Check-in [38e2e19036]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:merge with trunk
Timelines: family | ancestors | descendants | both | wtf-8-experiment
Files: files | file ages | folders
SHA1: 38e2e19036e282653c4a3c88e6ea8930c5f94589
User & Date: chw 2019-07-12 16:43:53
Context
2019-07-12
16:49
cleanup after merge check-in: 0acaefd7b1 user: chw tags: wtf-8-experiment
16:43
merge with trunk check-in: 38e2e19036 user: chw tags: wtf-8-experiment
16:21
update sqlite to version 3.29.0 check-in: 513d4da72a user: chw tags: trunk
2019-07-08
09:14
merge with trunk check-in: 104960adc4 user: chw tags: wtf-8-experiment
Changes

Changes to assets/sqlite3/pkgIndex.tcl.

     1      1   #
     2      2   # Tcl package index file
     3      3   #
     4      4   # Note sqlite*3* init specifically
     5      5   #
     6         -package ifneeded sqlite3 3.28.0 \
            6  +package ifneeded sqlite3 3.29.0 \
     7      7       [list load libtclsqlite3[info sharedlibextension] Sqlite3]

Changes to jni/sdl2tk/macosx/tkMacOSXBitmap.c.

    45     45       {"note",		kAlertNoteIcon},
    46     46       {"caution",		kAlertCautionIcon},
    47     47       {NULL}
    48     48   };
    49     49   
    50     50   #define builtInIconSize 32
    51     51   
           52  +#define OSTYPE_TO_UTI(x) (NSString *)UTTypeCreatePreferredIdentifierForTag( \
           53  +     kUTTagClassOSType, UTCreateStringForOSType(x), nil)
           54  +
    52     55   static Tcl_HashTable iconBitmapTable = {};
    53     56   typedef struct {
    54     57       int kind, width, height;
    55     58       char *value;
    56     59   } IconBitmap;
    57     60   
    58     61   static const char *const iconBitmapOptionStrings[] = {
................................................................................
   107    110   	}
   108    111       }
   109    112   }
   110    113   
   111    114   /*
   112    115    *----------------------------------------------------------------------
   113    116    *
   114         - * GetBitmapForIcon --
          117  + * PixmapFromImage --
   115    118    *
   116    119    * Results:
   117         - *	Bitmap for the given IconRef.
          120  + *	Returns a Pixmap with an NSImage drawn into it.
   118    121    *
   119    122    * Side effects:
   120    123    *	None.
   121    124    *
   122    125    *----------------------------------------------------------------------
   123    126    */
   124    127   
   125    128   static Pixmap
   126         -GetBitmapForIcon(
          129  +PixmapFromImage(
   127    130       Display *display,
   128         -    IconRef icon,
          131  +    NSImage* image,
   129    132       CGSize size)
   130    133   {
   131    134       TkMacOSXDrawingContext dc;
   132    135       Pixmap pixmap;
   133    136   
   134    137       pixmap = Tk_GetPixmap(display, None, size.width, size.height, 0);
   135    138       if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
   136    139   	if (dc.context) {
   137         -	    const CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
   138         -		    .tx = 0, .ty = size.height };
   139         -	    const CGRect r = { .origin = { .x = 0, .y = 0 }, .size = size };
   140         -
          140  +	    CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
          141  +				    .tx = 0, .ty = size.height};
   141    142   	    CGContextConcatCTM(dc.context, t);
   142         -	    PlotIconRefInContext(dc.context, &r, kAlignAbsoluteCenter,
   143         -		    kTransformNone, NULL, kPlotIconRefNormalFlags, icon);
          143  +	    [NSGraphicsContext saveGraphicsState];
          144  +	    [NSGraphicsContext setCurrentContext:[NSGraphicsContext
          145  +		graphicsContextWithGraphicsPort:dc.context
          146  +		flipped:NO]];
          147  +	    [image drawAtPoint:NSZeroPoint fromRect:NSZeroRect
          148  +		operation:NSCompositeCopy fraction:1.0];
          149  +	    [NSGraphicsContext restoreGraphicsState];
   144    150   	}
   145    151   	TkMacOSXRestoreDrawingContext(&dc);
   146    152       }
   147    153       return pixmap;
   148    154   }
   149    155   
   150    156   /*
................................................................................
   164    170    */
   165    171   
   166    172   Pixmap
   167    173   TkpCreateNativeBitmap(
   168    174       Display *display,
   169    175       const void *source)		/* Info about the icon to build. */
   170    176   {
   171         -    Pixmap pixmap;
   172         -    IconRef icon;
   173         -    OSErr err;
   174         -
   175         -    err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
   176         -	    PTR2UINT(source), &icon);
   177         -    if (err == noErr) {
   178         -	pixmap = GetBitmapForIcon(display, icon, CGSizeMake(builtInIconSize,
   179         -		builtInIconSize));
   180         -	ReleaseIconRef(icon);
   181         -    } else {
   182         -	pixmap = Tk_GetPixmap(display, None, builtInIconSize,
   183         -		builtInIconSize, 0);
   184         -    }
          177  +    NSString *iconUTI = OSTYPE_TO_UTI(PTR2UINT(source));
          178  +    NSImage *iconImage = [[NSWorkspace sharedWorkspace]
          179  +			     iconForFileType: iconUTI];
          180  +    CGSize size = CGSizeMake(builtInIconSize, builtInIconSize);
          181  +    Pixmap pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
   185    182       return pixmap;
   186    183   }
   187    184   
   188    185   /*
   189    186    *----------------------------------------------------------------------
   190    187    *
   191    188    * OSTypeFromString --
................................................................................
   320    317   	    }
   321    318   	}
   322    319   	if (image) {
   323    320   	    size = [image size];
   324    321   	}
   325    322       }
   326    323       if (image) {
   327         -	TkMacOSXDrawingContext dc;
   328         -	int depth = 0;
   329         -
   330         -#ifdef MAC_OSX_TK_TODO
   331         -	for (NSImageRep *r in [image representations]) {
   332         -	    NSInteger bitsPerSample = [r bitsPerSample];
   333         -	    if (bitsPerSample && bitsPerSample > depth) {
   334         -		depth = bitsPerSample;
   335         -	    };
   336         -	}
   337         -	if (depth == 1) {
   338         -	    /* TODO: convert BW NSImage to CGImageMask */
   339         -	}
   340         -#endif
   341         -	pixmap = Tk_GetPixmap(display, None, size.width, size.height, depth);
   342    324   	*width = size.width;
   343    325   	*height = size.height;
   344         -	if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
   345         -	    if (dc.context) {
   346         -		CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
   347         -			.tx = 0, .ty = size.height};
   348         -
   349         -		CGContextConcatCTM(dc.context, t);
   350         -		[NSGraphicsContext saveGraphicsState];
   351         -		[NSGraphicsContext setCurrentContext:[NSGraphicsContext
   352         -			graphicsContextWithGraphicsPort:dc.context flipped:NO]];
   353         -		[image drawAtPoint:NSZeroPoint fromRect:NSZeroRect
   354         -			operation:NSCompositeCopy fraction:1.0];
   355         -		[NSGraphicsContext restoreGraphicsState];
   356         -	    }
   357         -	    TkMacOSXRestoreDrawingContext(&dc);
   358         -	}
          326  +	pixmap = PixmapFromImage(display, image, NSSizeToCGSize(size));
   359    327       } else if (name) {
   360    328   	OSType iconType;
   361    329   	if (OSTypeFromString(name, &iconType) == TCL_OK) {
   362         -	    IconRef icon;
   363         -	    OSErr err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
   364         -		    iconType, &icon);
   365         -	    if (err == noErr) {
   366         -		pixmap = GetBitmapForIcon(display, icon, NSSizeToCGSize(size));
   367         -		*width = size.width;
   368         -		*height = size.height;
   369         -		ReleaseIconRef(icon);
   370         -	    }
          330  +	    NSString *iconUTI = OSTYPE_TO_UTI(iconType);
          331  +	    printf("Found image for UTI %s\n", iconUTI.UTF8String);
          332  +	    NSImage *iconImage = [[NSWorkspace sharedWorkspace]
          333  +				     iconForFileType: iconUTI];
          334  +	    pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
   371    335   	}
   372    336       }
   373    337       Tcl_DStringFree(&ds);
   374    338       Tcl_FreeEncoding(utf8);
   375    339       return pixmap;
   376    340   }
   377    341   

Changes to jni/sdl2tk/macosx/tkMacOSXWm.c.

  5601   5601   	if ([NSApp macMinorVersion] < 9) {
  5602   5602   	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
  5603   5603                   "Window appearances did not exist until OSX 10.9.", -1));
  5604   5604   	    Tcl_SetErrorCode(interp, "TK", "WINDOWSTYLE", "APPEARANCE", NULL);
  5605   5605   	    return TCL_ERROR;
  5606   5606   	}
  5607   5607   	if ((objc < 3) || (objc > 4)) {
  5608         -	    Tcl_WrongNumArgs(interp, 2, objv,
  5609         -		    "appearance window ?appearancename?");
         5608  +	    Tcl_WrongNumArgs(interp, 2, objv, "window ?appearancename?");
  5610   5609   	    return TCL_ERROR;
  5611   5610   	}
  5612   5611   	if (objc == 4 && [NSApp macMinorVersion] < 14) {
  5613   5612   	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
  5614   5613   		    "Window appearances cannot be changed before OSX 10.14.",
  5615   5614   		    -1));
  5616   5615   	    Tcl_SetErrorCode(interp, "TK", "WINDOWSTYLE", "APPEARANCE", NULL);

Changes to jni/sdl2tk/macosx/ttkMacOSXTheme.c.

  1232   1232       /*
  1233   1233        * See ButtonElementDraw for the explanation of why we always draw
  1234   1234        * PushButtons in the active state.
  1235   1235        */
  1236   1236   
  1237   1237       SInt32 HIThemeState;
  1238   1238   
         1239  +    HIThemeState = Ttk_StateTableLookup(ThemeStateTable, state);
  1239   1240       switch (params->kind) {
  1240   1241       case kThemePushButton:
  1241         -	HIThemeState = kThemeStateActive;
         1242  +	HIThemeState &= ~kThemeStateInactive;
         1243  +	HIThemeState |= kThemeStateActive;
  1242   1244   	break;
  1243   1245       default:
  1244         -	HIThemeState = Ttk_StateTableLookup(ThemeStateTable, state);
  1245   1246   	break;
  1246   1247       }
  1247   1248   
  1248   1249       const HIThemeButtonDrawInfo info = {
  1249   1250   	.version = 0,
  1250   1251   	.state = HIThemeState,
  1251   1252   	.kind = params ? params->kind : 0,

Changes to jni/tcl/generic/tclCmdAH.c.

  1388   1388                                "could not get access time for file \"%s\"",
  1389   1389                                TclGetString(objv[1])));
  1390   1390           return TCL_ERROR;
  1391   1391       }
  1392   1392   #endif
  1393   1393   
  1394   1394       if (objc == 3) {
  1395         -	/*
  1396         -	 * Need separate variable for reading longs from an object on 64-bit
  1397         -	 * platforms. [Bug 698146]
  1398         -	 */
         1395  +	Tcl_WideInt newTime;
  1399   1396   
  1400         -	long newTime;
  1401         -
  1402         -	if (TclGetLongFromObj(interp, objv[2], &newTime) != TCL_OK) {
         1397  +	if (Tcl_GetWideIntFromObj(interp, objv[2], &newTime) != TCL_OK) {
  1403   1398   	    return TCL_ERROR;
  1404   1399   	}
  1405   1400   
  1406   1401   	tval.actime = newTime;
  1407   1402   	tval.modtime = Tcl_GetModificationTimeFromStat(&buf);
  1408   1403   
  1409   1404   	if (Tcl_FSUtime(objv[1], &tval) != 0) {
................................................................................
  1474   1469   #endif
  1475   1470       if (objc == 3) {
  1476   1471   	/*
  1477   1472   	 * Need separate variable for reading longs from an object on 64-bit
  1478   1473   	 * platforms. [Bug 698146]
  1479   1474   	 */
  1480   1475   
  1481         -	long newTime;
         1476  +	Tcl_WideInt newTime;
  1482   1477   
  1483         -	if (TclGetLongFromObj(interp, objv[2], &newTime) != TCL_OK) {
         1478  +	if (Tcl_GetWideIntFromObj(interp, objv[2], &newTime) != TCL_OK) {
  1484   1479   	    return TCL_ERROR;
  1485   1480   	}
  1486   1481   
  1487   1482   	tval.actime = Tcl_GetAccessTimeFromStat(&buf);
  1488   1483   	tval.modtime = newTime;
  1489   1484   
  1490   1485   	if (Tcl_FSUtime(objv[1], &tval) != 0) {

Deleted jni/tcl/pkgs/sqlite3.28.0/Android.mk.

     1         -LOCAL_PATH := $(call my-dir)
     2         -
     3         -###########################
     4         -#
     5         -# tclsqlite3 shared library
     6         -#
     7         -###########################
     8         -
     9         -include $(CLEAR_VARS)
    10         -
    11         -tcl_path := $(LOCAL_PATH)/../../tcl
    12         -
    13         -include $(tcl_path)/tcl-config.mk
    14         -
    15         -LOCAL_ADDITIONAL_DEPENDENCIES += $(tcl_path)/tcl-config.mk
    16         -
    17         -LOCAL_MODULE := tclsqlite3
    18         -
    19         -LOCAL_ARM_MODE := arm
    20         -
    21         -LOCAL_C_INCLUDES := $(tcl_includes) \
    22         -	$(LOCAL_PATH)/icu4c \
    23         -	$(LOCAL_PATH)/compat/sqlite3
    24         -
    25         -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
    26         -
    27         -LOCAL_SRC_FILES := \
    28         -	generic/tclsqlite3.c \
    29         -	compat/sqlite3/shell.c \
    30         -	icu4c/dl_icu.c
    31         -
    32         -LOCAL_CFLAGS := $(tcl_cflags) \
    33         -	-DSQLITE_3_SUFFIX_ONLY=1 \
    34         -	-DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1 \
    35         -	-DSQLITE_UNTESTABLE=1 \
    36         -	-DSQLITE_OMIT_LOOKASIDE=1 \
    37         -	-DSQLITE_SECURE_DELETE=1 \
    38         -	-DSQLITE_SOUNDEX=1 \
    39         -	-DSQLITE_THREADSAFE=1 \
    40         -	-DSQLITE_USE_ALLOCA=1 \
    41         -	-DSQLITE_ENABLE_COLUMN_METADATA=1 \
    42         -	-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1 \
    43         -	-DSQLITE_ENABLE_DBPAGE_VTAB=1 \
    44         -	-DSQLITE_ENABLE_DBSTAT_VTAB=1 \
    45         -	-DSQLITE_ENABLE_FTS3_PARENTHESIS=1 \
    46         -	-DSQLITE_ENABLE_FTS3=1 \
    47         -	-DSQLITE_ENABLE_FTS4=1 \
    48         -	-DSQLITE_ENABLE_FTS5=1 \
    49         -	-DSQLITE_ENABLE_RTREE=1 \
    50         -	-DSQLITE_ENABLE_GEOPOLY=1 \
    51         -	-DSQLITE_ENABLE_RBU=1 \
    52         -	-DSQLITE_ENABLE_ICU=1 \
    53         -	-DSQLITE_ENABLE_JSON1=1 \
    54         -	-DSQLITE_ENABLE_UNLOCK_NOTIFY=1 \
    55         -	-DHAVE_USLEEP=1 \
    56         -	-DHAVE_MREMAP=1 \
    57         -	-DHAVE_ISNAN=1 \
    58         -	-DU_LIB_SUFFIX_C_NAME=_sqlite3 \
    59         -	-DPACKAGE_NAME="\"sqlite\"" \
    60         -	-DPACKAGE_VERSION="\"3.28.0\"" \
    61         -	-DBUILD_sqlite=1 \
    62         -	-Dmain=sqlite3_shell \
    63         -	-O2
    64         -
    65         -LOCAL_SHARED_LIBRARIES := libtcl
    66         -
    67         -LOCAL_LDLIBS :=	-llog
    68         -
    69         -include $(BUILD_SHARED_LIBRARY)

Deleted jni/tcl/pkgs/sqlite3.28.0/Makefile.in.

     1         -# Makefile.in --
     2         -#
     3         -#	This file is a Makefile for Sample TEA Extension.  If it has the name
     4         -#	"Makefile.in" then it is a template for a Makefile;  to generate the
     5         -#	actual Makefile, run "./configure", which is a configuration script
     6         -#	generated by the "autoconf" program (constructs like "@foo@" will get
     7         -#	replaced in the actual Makefile.
     8         -#
     9         -# Copyright (c) 1999 Scriptics Corporation.
    10         -# Copyright (c) 2002-2005 ActiveState Corporation.
    11         -#
    12         -# See the file "license.terms" for information on usage and redistribution
    13         -# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    14         -#
    15         -# RCS: @(#) $Id: Makefile.in,v 1.59 2005/07/26 19:17:02 mdejong Exp $
    16         -
    17         -#========================================================================
    18         -# Add additional lines to handle any additional AC_SUBST cases that
    19         -# have been added in a customized configure script.
    20         -#========================================================================
    21         -
    22         -#SAMPLE_NEW_VAR	= @SAMPLE_NEW_VAR@
    23         -
    24         -#========================================================================
    25         -# Nothing of the variables below this line should need to be changed.
    26         -# Please check the TARGETS section below to make sure the make targets
    27         -# are correct.
    28         -#========================================================================
    29         -
    30         -#========================================================================
    31         -# The names of the source files is defined in the configure script.
    32         -# The object files are used for linking into the final library.
    33         -# This will be used when a dist target is added to the Makefile.
    34         -# It is not important to specify the directory, as long as it is the
    35         -# $(srcdir) or in the generic, win or unix subdirectory.
    36         -#========================================================================
    37         -
    38         -PKG_SOURCES	= @PKG_SOURCES@
    39         -PKG_OBJECTS	= @PKG_OBJECTS@
    40         -
    41         -PKG_STUB_SOURCES = @PKG_STUB_SOURCES@
    42         -PKG_STUB_OBJECTS = @PKG_STUB_OBJECTS@
    43         -
    44         -#========================================================================
    45         -# PKG_TCL_SOURCES identifies Tcl runtime files that are associated with
    46         -# this package that need to be installed, if any.
    47         -#========================================================================
    48         -
    49         -PKG_TCL_SOURCES = @PKG_TCL_SOURCES@
    50         -
    51         -#========================================================================
    52         -# This is a list of public header files to be installed, if any.
    53         -#========================================================================
    54         -
    55         -PKG_HEADERS	= @PKG_HEADERS@
    56         -
    57         -#========================================================================
    58         -# "PKG_LIB_FILE" refers to the library (dynamic or static as per
    59         -# configuration options) composed of the named objects.
    60         -#========================================================================
    61         -
    62         -PKG_LIB_FILE	= @PKG_LIB_FILE@
    63         -PKG_STUB_LIB_FILE = @PKG_STUB_LIB_FILE@
    64         -
    65         -lib_BINARIES	= $(PKG_LIB_FILE)
    66         -BINARIES	= $(lib_BINARIES)
    67         -
    68         -SHELL		= @SHELL@
    69         -
    70         -srcdir		= @srcdir@
    71         -prefix		= @prefix@
    72         -exec_prefix	= @exec_prefix@
    73         -
    74         -bindir		= @bindir@
    75         -libdir		= @libdir@
    76         -datarootdir	= @datarootdir@
    77         -datadir		= @datadir@
    78         -mandir		= @mandir@
    79         -includedir	= @includedir@
    80         -
    81         -DESTDIR		=
    82         -
    83         -PKG_DIR		= $(PACKAGE_NAME)$(PACKAGE_VERSION)
    84         -pkgdatadir	= $(datadir)/$(PKG_DIR)
    85         -pkglibdir	= $(libdir)/$(PKG_DIR)
    86         -pkgincludedir	= $(includedir)/$(PKG_DIR)
    87         -
    88         -top_builddir	= .
    89         -
    90         -INSTALL		= @INSTALL@
    91         -INSTALL_PROGRAM	= @INSTALL_PROGRAM@
    92         -INSTALL_DATA	= @INSTALL_DATA@
    93         -INSTALL_SCRIPT	= @INSTALL_SCRIPT@
    94         -
    95         -PACKAGE_NAME	= @PACKAGE_NAME@
    96         -PACKAGE_VERSION	= @PACKAGE_VERSION@
    97         -CC		= @CC@
    98         -CFLAGS_DEFAULT	= @CFLAGS_DEFAULT@
    99         -CFLAGS_WARNING	= @CFLAGS_WARNING@
   100         -CLEANFILES	= @CLEANFILES@
   101         -EXEEXT		= @EXEEXT@
   102         -LDFLAGS_DEFAULT	= @LDFLAGS_DEFAULT@
   103         -MAKE_LIB	= @MAKE_LIB@
   104         -MAKE_SHARED_LIB	= @MAKE_SHARED_LIB@
   105         -MAKE_STATIC_LIB	= @MAKE_STATIC_LIB@
   106         -MAKE_STUB_LIB	= @MAKE_STUB_LIB@
   107         -OBJEXT		= @OBJEXT@
   108         -RANLIB		= @RANLIB@
   109         -RANLIB_STUB	= @RANLIB_STUB@
   110         -SHLIB_CFLAGS	= @SHLIB_CFLAGS@
   111         -SHLIB_LD	= @SHLIB_LD@
   112         -SHLIB_LD_LIBS	= @SHLIB_LD_LIBS@
   113         -STLIB_LD	= @STLIB_LD@
   114         -#TCL_DEFS	= @TCL_DEFS@
   115         -TCL_BIN_DIR	= @TCL_BIN_DIR@
   116         -TCL_SRC_DIR	= @TCL_SRC_DIR@
   117         -#TK_BIN_DIR	= @TK_BIN_DIR@
   118         -#TK_SRC_DIR	= @TK_SRC_DIR@
   119         -
   120         -# This is no longer necessary even for packages that use private Tcl headers
   121         -#TCL_TOP_DIR_NATIVE	= @TCL_TOP_DIR_NATIVE@
   122         -# Not used, but retained for reference of what libs Tcl required
   123         -#TCL_LIBS	= @TCL_LIBS@
   124         -
   125         -#========================================================================
   126         -# TCLLIBPATH seeds the auto_path in Tcl's init.tcl so we can test our
   127         -# package without installing.  The other environment variables allow us
   128         -# to test against an uninstalled Tcl.  Add special env vars that you
   129         -# require for testing here (like TCLX_LIBRARY).
   130         -#========================================================================
   131         -
   132         -EXTRA_PATH	= $(top_builddir):$(TCL_BIN_DIR)
   133         -#EXTRA_PATH	= $(top_builddir):$(TCL_BIN_DIR):$(TK_BIN_DIR)
   134         -TCLLIBPATH	= $(top_builddir)
   135         -TCLSH_ENV	= TCL_LIBRARY=`@CYGPATH@ $(TCL_SRC_DIR)/library` \
   136         -		  @LD_LIBRARY_PATH_VAR@="$(EXTRA_PATH):$(@LD_LIBRARY_PATH_VAR@)" \
   137         -		  PATH="$(EXTRA_PATH):$(PATH)" \
   138         -		  TCLLIBPATH="$(TCLLIBPATH)"
   139         -#		  TK_LIBRARY=`@CYGPATH@ $(TK_SRC_DIR)/library`
   140         -
   141         -TCLSH_PROG	= @TCLSH_PROG@
   142         -TCLSH	= $(TCLSH_ENV) $(TCLSH_PROG)
   143         -
   144         -#WISH_PROG	= @WISH_PROG@
   145         -#WISH	= $(TCLSH_ENV) $(WISH_PROG)
   146         -
   147         -
   148         -SHARED_BUILD	= @SHARED_BUILD@
   149         -
   150         -INCLUDES	= @PKG_INCLUDES@ @TCL_INCLUDES@ -I$(srcdir)/..
   151         -#INCLUDES	= @PKG_INCLUDES@ @TCL_INCLUDES@ @TK_INCLUDES@ @TK_XINCLUDES@
   152         -
   153         -PKG_CFLAGS	= @PKG_CFLAGS@ -DSQLITE_API=MODULE_SCOPE -DSQLITE_EXTERN=
   154         -
   155         -# TCL_DEFS is not strictly need here, but if you remove it, then you
   156         -# must make sure that configure.in checks for the necessary components
   157         -# that your library may use.  TCL_DEFS can actually be a problem if
   158         -# you do not compile with a similar machine setup as the Tcl core was
   159         -# compiled with.
   160         -#DEFS		= $(TCL_DEFS) @DEFS@ $(PKG_CFLAGS)
   161         -DEFS		= @DEFS@ $(PKG_CFLAGS)
   162         -
   163         -CONFIG_CLEAN_FILES = Makefile pkgIndex.tcl
   164         -
   165         -CPPFLAGS	= @CPPFLAGS@
   166         -LIBS		= @PKG_LIBS@ @LIBS@
   167         -AR		= @AR@
   168         -CFLAGS		= @CFLAGS@
   169         -COMPILE		= $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
   170         -
   171         -#========================================================================
   172         -# Start of user-definable TARGETS section
   173         -#========================================================================
   174         -
   175         -#========================================================================
   176         -# TEA TARGETS.  Please note that the "libraries:" target refers to platform
   177         -# independent files, and the "binaries:" target inclues executable programs and
   178         -# platform-dependent libraries.  Modify these targets so that they install
   179         -# the various pieces of your package.  The make and install rules
   180         -# for the BINARIES that you specified above have already been done.
   181         -#========================================================================
   182         -
   183         -all: binaries libraries doc
   184         -
   185         -#========================================================================
   186         -# The binaries target builds executable programs, Windows .dll's, unix
   187         -# shared/static libraries, and any other platform-dependent files.
   188         -# The list of targets to build for "binaries:" is specified at the top
   189         -# of the Makefile, in the "BINARIES" variable.
   190         -#========================================================================
   191         -
   192         -binaries: $(BINARIES)
   193         -
   194         -libraries:
   195         -
   196         -
   197         -#========================================================================
   198         -# Your doc target should differentiate from doc builds (by the developer)
   199         -# and doc installs (see install-doc), which just install the docs on the
   200         -# end user machine when building from source.
   201         -#========================================================================
   202         -
   203         -doc:
   204         -	@echo "If you have documentation to create, place the commands to"
   205         -	@echo "build the docs in the 'doc:' target.  For example:"
   206         -	@echo "        xml2nroff sample.xml > sample.n"
   207         -	@echo "        xml2html sample.xml > sample.html"
   208         -
   209         -install: all install-binaries install-libraries install-doc
   210         -
   211         -install-binaries: binaries install-lib-binaries install-bin-binaries
   212         -
   213         -#========================================================================
   214         -# This rule installs platform-independent files, such as header files.
   215         -# The list=...; for p in $$list handles the empty list case x-platform.
   216         -#========================================================================
   217         -
   218         -install-libraries: libraries
   219         -	@mkdir -p $(DESTDIR)$(includedir)
   220         -	@echo "Installing header files in $(DESTDIR)$(includedir)"
   221         -	@list='$(PKG_HEADERS)'; for i in $$list; do \
   222         -	    echo "Installing $(srcdir)/$$i" ; \
   223         -	    $(INSTALL_DATA) $(srcdir)/$$i $(DESTDIR)$(includedir) ; \
   224         -	done;
   225         -
   226         -#========================================================================
   227         -# Install documentation.  Unix manpages should go in the $(mandir)
   228         -# directory.
   229         -#========================================================================
   230         -
   231         -install-doc: doc
   232         -	@mkdir -p $(DESTDIR)$(mandir)/mann
   233         -	@echo "Installing documentation in $(DESTDIR)$(mandir)"
   234         -	@list='$(srcdir)/doc/*.n'; for i in $$list; do \
   235         -	    echo "Installing $$i"; \
   236         -	    rm -f $(DESTDIR)$(mandir)/mann/`basename $$i`; \
   237         -	    $(INSTALL_DATA) $$i $(DESTDIR)$(mandir)/mann ; \
   238         -	done
   239         -
   240         -test: binaries libraries
   241         -	$(TCLSH) `@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS) \
   242         -		-load "package ifneeded ${PACKAGE_NAME}3 ${PACKAGE_VERSION} \
   243         -			[list load `@CYGPATH@ $(PKG_LIB_FILE)` $(PACKAGE_NAME)3]"
   244         -
   245         -shell: binaries libraries
   246         -	@$(TCLSH) $(SCRIPT)
   247         -
   248         -gdb:
   249         -	$(TCLSH_ENV) gdb $(TCLSH_PROG) $(SCRIPT)
   250         -
   251         -depend:
   252         -
   253         -#========================================================================
   254         -# $(PKG_LIB_FILE) should be listed as part of the BINARIES variable
   255         -# mentioned above.  That will ensure that this target is built when you
   256         -# run "make binaries".
   257         -#
   258         -# The $(PKG_OBJECTS) objects are created and linked into the final
   259         -# library.  In most cases these object files will correspond to the
   260         -# source files above.
   261         -#========================================================================
   262         -
   263         -$(PKG_LIB_FILE): $(PKG_OBJECTS)
   264         -	-rm -f $(PKG_LIB_FILE)
   265         -	${MAKE_LIB}
   266         -	$(RANLIB) $(PKG_LIB_FILE)
   267         -
   268         -$(PKG_STUB_LIB_FILE): $(PKG_STUB_OBJECTS)
   269         -	-rm -f $(PKG_STUB_LIB_FILE)
   270         -	${MAKE_STUB_LIB}
   271         -	$(RANLIB_STUB) $(PKG_STUB_LIB_FILE)
   272         -
   273         -#========================================================================
   274         -# We need to enumerate the list of .c to .o lines here.
   275         -#
   276         -# In the following lines, $(srcdir) refers to the toplevel directory
   277         -# containing your extension.  If your sources are in a subdirectory,
   278         -# you will have to modify the paths to reflect this:
   279         -#
   280         -# sample.$(OBJEXT): $(srcdir)/generic/sample.c
   281         -# 	$(COMPILE) -c `@CYGPATH@ $(srcdir)/generic/sample.c` -o $@
   282         -#
   283         -# Setting the VPATH variable to a list of paths will cause the makefile
   284         -# to look into these paths when resolving .c to .obj dependencies.
   285         -# As necessary, add $(srcdir):$(srcdir)/compat:....
   286         -#========================================================================
   287         -
   288         -VPATH = $(srcdir):$(srcdir)/generic:$(srcdir)/unix:$(srcdir)/win
   289         -
   290         -.c.@OBJEXT@:
   291         -	$(COMPILE) -c `@CYGPATH@ $<` -o $@
   292         -
   293         -#========================================================================
   294         -# Distribution creation
   295         -# You may need to tweak this target to make it work correctly.
   296         -#========================================================================
   297         -
   298         -#COMPRESS	= tar cvf $(PKG_DIR).tar $(PKG_DIR); compress $(PKG_DIR).tar
   299         -COMPRESS	= gtar zcvf $(PKG_DIR).tar.gz $(PKG_DIR)
   300         -DIST_ROOT	= /tmp/dist
   301         -DIST_DIR	= $(DIST_ROOT)/$(PKG_DIR)
   302         -
   303         -dist-clean:
   304         -	rm -rf $(DIST_DIR) $(DIST_ROOT)/$(PKG_DIR).tar.*
   305         -
   306         -dist: dist-clean
   307         -	mkdir -p $(DIST_DIR)/compat/sqlite3
   308         -	cp -p $(srcdir)/README* $(srcdir)/license* \
   309         -		$(srcdir)/aclocal.m4 $(srcdir)/configure $(srcdir)/*.in \
   310         -		$(srcdir)/configure.ac $(DIST_DIR)/
   311         -	chmod 664 $(DIST_DIR)/Makefile.in $(DIST_DIR)/aclocal.m4
   312         -	chmod 775 $(DIST_DIR)/configure $(DIST_DIR)/configure.ac
   313         -
   314         -	for i in $(srcdir)/*.[ch]; do \
   315         -	    if [ -f $$i ]; then \
   316         -		cp -p $$i $(DIST_DIR)/ ; \
   317         -	    fi; \
   318         -	done;
   319         -
   320         -	mkdir -p $(DIST_DIR)/tclconfig
   321         -	cp $(srcdir)/tclconfig/install-sh $(srcdir)/tclconfig/tcl.m4 \
   322         -		$(DIST_DIR)/tclconfig/
   323         -	chmod 664 $(DIST_DIR)/tclconfig/tcl.m4
   324         -	chmod +x $(DIST_DIR)/tclconfig/install-sh
   325         -
   326         -	list='demos doc generic library mac tests unix win compat/sqlite3'; \
   327         -	for p in $$list; do \
   328         -	    if test -d $(srcdir)/$$p ; then \
   329         -		mkdir -p $(DIST_DIR)/$$p; \
   330         -		cp -p $(srcdir)/$$p/*.* $(DIST_DIR)/$$p/; \
   331         -	    fi; \
   332         -	done
   333         -
   334         -	(cd $(DIST_ROOT); $(COMPRESS);)
   335         -
   336         -#========================================================================
   337         -# End of user-definable section
   338         -#========================================================================
   339         -
   340         -#========================================================================
   341         -# Don't modify the file to clean here.  Instead, set the "CLEANFILES"
   342         -# variable in configure.in
   343         -#========================================================================
   344         -
   345         -clean:  
   346         -	-test -z "$(BINARIES)" || rm -f $(BINARIES)
   347         -	-rm -f *.$(OBJEXT) core *.core
   348         -	-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
   349         -
   350         -distclean: clean
   351         -	-rm -f *.tab.c
   352         -	-rm -f $(CONFIG_CLEAN_FILES)
   353         -	-rm -f config.h config.cache config.log config.status
   354         -
   355         -#========================================================================
   356         -# Install binary object libraries.  On Windows this includes both .dll and
   357         -# .lib files.  Because the .lib files are not explicitly listed anywhere,
   358         -# we need to deduce their existence from the .dll file of the same name.
   359         -# Library files go into the lib directory.
   360         -# In addition, this will generate the pkgIndex.tcl
   361         -# file in the install location (assuming it can find a usable tclsh shell)
   362         -#
   363         -# You should not have to modify this target.
   364         -#========================================================================
   365         -
   366         -install-lib-binaries: binaries
   367         -	@mkdir -p $(DESTDIR)$(pkglibdir)
   368         -	@list='$(lib_BINARIES)'; for p in $$list; do \
   369         -	  if test -f $$p; then \
   370         -	    echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(pkglibdir)/$$p"; \
   371         -	    $(INSTALL_PROGRAM) $$p $(DESTDIR)$(pkglibdir)/$$p; \
   372         -	    stub=`echo $$p|sed -e "s/.*\(stub\).*/\1/"`; \
   373         -	    if test "x$$stub" = "xstub"; then \
   374         -		echo " $(RANLIB_STUB) $(DESTDIR)$(pkglibdir)/$$p"; \
   375         -		$(RANLIB_STUB) $(DESTDIR)$(pkglibdir)/$$p; \
   376         -	    else \
   377         -		echo " $(RANLIB) $(DESTDIR)$(pkglibdir)/$$p"; \
   378         -		$(RANLIB) $(DESTDIR)$(pkglibdir)/$$p; \
   379         -	    fi; \
   380         -	    ext=`echo $$p|sed -e "s/.*\.//"`; \
   381         -	    if test "x$$ext" = "xdll"; then \
   382         -		lib=`basename $$p|sed -e 's/.[^.]*$$//'`.lib; \
   383         -		if test -f $$lib; then \
   384         -		    echo " $(INSTALL_DATA) $$lib $(DESTDIR)$(pkglibdir)/$$lib"; \
   385         -	            $(INSTALL_DATA) $$lib $(DESTDIR)$(pkglibdir)/$$lib; \
   386         -		fi; \
   387         -	    fi; \
   388         -	  fi; \
   389         -	done
   390         -	@list='$(PKG_TCL_SOURCES)'; for p in $$list; do \
   391         -	  if test -f $(srcdir)/$$p; then \
   392         -	    destp=`basename $$p`; \
   393         -	    echo " Install $$destp $(DESTDIR)$(pkglibdir)/$$destp"; \
   394         -	    $(INSTALL_DATA) $(srcdir)/$$p $(DESTDIR)$(pkglibdir)/$$destp; \
   395         -	  fi; \
   396         -	done
   397         -	@if test "x$(SHARED_BUILD)" = "x1"; then \
   398         -	    echo " Install pkgIndex.tcl $(DESTDIR)$(pkglibdir)"; \
   399         -	    $(INSTALL_DATA) pkgIndex.tcl $(DESTDIR)$(pkglibdir); \
   400         -	fi
   401         -
   402         -#========================================================================
   403         -# Install binary executables (e.g. .exe files and dependent .dll files)
   404         -# This is for files that must go in the bin directory (located next to
   405         -# wish and tclsh), like dependent .dll files on Windows.
   406         -#
   407         -# You should not have to modify this target, except to define bin_BINARIES
   408         -# above if necessary.
   409         -#========================================================================
   410         -
   411         -install-bin-binaries: binaries
   412         -	@mkdir -p $(DESTDIR)$(bindir)
   413         -	@list='$(bin_BINARIES)'; for p in $$list; do \
   414         -	  if test -f $$p; then \
   415         -	    echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$p"; \
   416         -	    $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$p; \
   417         -	  fi; \
   418         -	done
   419         -	$(INSTALL_PROGRAM) $(srcdir)/compat/sqlite3/spaceanal.tcl $(DESTDIR)$(bindir)/sqlite3_analyzer
   420         -
   421         -.SUFFIXES: .c .$(OBJEXT)
   422         -
   423         -Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
   424         -	cd $(top_builddir) \
   425         -	  && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status
   426         -
   427         -uninstall-binaries:
   428         -	list='$(lib_BINARIES)'; for p in $$list; do \
   429         -	  rm -f $(DESTDIR)$(pkglibdir)/$$p; \
   430         -	done
   431         -	list='$(PKG_TCL_SOURCES)'; for p in $$list; do \
   432         -	  p=`basename $$p`; \
   433         -	  rm -f $(DESTDIR)$(pkglibdir)/$$p; \
   434         -	done
   435         -	list='$(bin_BINARIES)'; for p in $$list; do \
   436         -	  rm -f $(DESTDIR)$(bindir)/$$p; \
   437         -	done
   438         -
   439         -.PHONY: all binaries clean depend distclean doc install libraries test
   440         -
   441         -# Tell versions [3.59,3.63) of GNU make to not export all variables.
   442         -# Otherwise a system limit (for SysV at least) may be exceeded.
   443         -.NOEXPORT:

Deleted jni/tcl/pkgs/sqlite3.28.0/README.

     1         -This is the SQLite extension for Tcl using the Tcl Extension
     2         -Architecture (TEA).  For additional information on SQLite see
     3         -
     4         -        http://www.sqlite.org/
     5         -
     6         -
     7         -UNIX BUILD
     8         -==========
     9         -
    10         -Building under most UNIX systems is easy, just run the configure script
    11         -and then run make. For more information about the build process, see
    12         -the tcl/unix/README file in the Tcl src dist. The following minimal
    13         -example will install the extension in the /opt/tcl directory.
    14         -
    15         -	$ cd sqlite-*-tea
    16         -	$ ./configure --prefix=/opt/tcl
    17         -	$ make
    18         -	$ make install
    19         -
    20         -WINDOWS BUILD
    21         -=============
    22         -
    23         -The recommended method to build extensions under windows is to use the
    24         -Msys + Mingw build process. This provides a Unix-style build while
    25         -generating native Windows binaries. Using the Msys + Mingw build tools
    26         -means that you can use the same configure script as per the Unix build
    27         -to create a Makefile. See the tcl/win/README file for the URL of
    28         -the Msys + Mingw download.
    29         -
    30         -If you have VC++ then you may wish to use the files in the win
    31         -subdirectory and build the extension using just VC++. These files have
    32         -been designed to be as generic as possible but will require some
    33         -additional maintenance by the project developer to synchronise with
    34         -the TEA configure.in and Makefile.in files. Instructions for using the
    35         -VC++ makefile are written in the first part of the Makefile.vc
    36         -file.

Deleted jni/tcl/pkgs/sqlite3.28.0/aclocal.m4.

     1         -#
     2         -# Include the TEA standard macro set
     3         -#
     4         -
     5         -builtin(include,tclconfig/tcl.m4)
     6         -
     7         -#
     8         -# Add here whatever m4 macros you want to define for your package
     9         -#

Deleted jni/tcl/pkgs/sqlite3.28.0/compat/sqlite3/shell.c.

more than 10,000 changes

Deleted jni/tcl/pkgs/sqlite3.28.0/compat/sqlite3/spaceanal.tcl.

     1         -#! /bin/sh
     2         -# restart with tclsh \
     3         -exec tclsh "$0" ${1+"$@"}
     4         -package require sqlite3
     5         -
     6         -# Run this TCL script using an SQLite-enabled TCL interpreter to get a report
     7         -# on how much disk space is used by a particular data to actually store data
     8         -# versus how much space is unused.
     9         -#
    10         -# The dbstat virtual table is required.
    11         -#
    12         -
    13         -if {[catch {
    14         -
    15         -# Argument $tname is the name of a table within the database opened by
    16         -# database handle [db]. Return true if it is a WITHOUT ROWID table, or
    17         -# false otherwise.
    18         -#
    19         -proc is_without_rowid {tname} {
    20         -  set t [string map {' ''} $tname]
    21         -  db eval "PRAGMA index_list = '$t'" o {
    22         -    if {$o(origin) == "pk"} {
    23         -      set n $o(name)
    24         -      if {0==[db one { SELECT count(*) FROM sqlite_master WHERE name=$n }]} {
    25         -        return 1
    26         -      }
    27         -    }
    28         -  }
    29         -  return 0
    30         -}
    31         -
    32         -# Read and run TCL commands from standard input.  Used to implement
    33         -# the --tclsh option.
    34         -#
    35         -proc tclsh {} {
    36         -  set line {}
    37         -  while {![eof stdin]} {
    38         -    if {$line!=""} {
    39         -      puts -nonewline "> "
    40         -    } else {
    41         -      puts -nonewline "% "
    42         -    }
    43         -    flush stdout
    44         -    append line [gets stdin]
    45         -    if {[info complete $line]} {
    46         -      if {[catch {uplevel #0 $line} result]} {
    47         -        puts stderr "Error: $result"
    48         -      } elseif {$result!=""} {
    49         -        puts $result
    50         -      }
    51         -      set line {}
    52         -    } else {
    53         -      append line \n
    54         -    }
    55         -  }
    56         -}
    57         -
    58         -
    59         -# Get the name of the database to analyze
    60         -#
    61         -proc usage {} {
    62         -  set argv0 [file rootname [file tail [info script]]]
    63         -  puts stderr "Usage: $argv0 ?--pageinfo? ?--stats? database-filename"
    64         -  puts stderr {
    65         -Analyze the SQLite3 database file specified by the "database-filename"
    66         -argument and output a report detailing size and storage efficiency
    67         -information for the database and its constituent tables and indexes.
    68         -
    69         -Options:
    70         -
    71         -   --pageinfo   Show how each page of the database-file is used
    72         -
    73         -   --stats      Output SQL text that creates a new database containing
    74         -                statistics about the database that was analyzed
    75         -
    76         -   --tclsh      Run the built-in TCL interpreter interactively (for debugging)
    77         -
    78         -   --version    Show the version number of SQLite
    79         -}
    80         -  exit 1
    81         -}
    82         -set file_to_analyze {}
    83         -set flags(-pageinfo) 0
    84         -set flags(-stats) 0
    85         -set flags(-debug) 0
    86         -append argv {}
    87         -foreach arg $argv {
    88         -  if {[regexp {^-+pageinfo$} $arg]} {
    89         -    set flags(-pageinfo) 1
    90         -  } elseif {[regexp {^-+stats$} $arg]} {
    91         -    set flags(-stats) 1
    92         -  } elseif {[regexp {^-+debug$} $arg]} {
    93         -    set flags(-debug) 1
    94         -  } elseif {[regexp {^-+tclsh$} $arg]} {
    95         -    tclsh
    96         -    exit 0
    97         -  } elseif {[regexp {^-+version$} $arg]} {
    98         -    sqlite3 mem :memory:
    99         -    puts [mem one {SELECT sqlite_version()||' '||sqlite_source_id()}]
   100         -    mem close
   101         -    exit 0
   102         -  } elseif {[regexp {^-} $arg]} {
   103         -    puts stderr "Unknown option: $arg"
   104         -    usage
   105         -  } elseif {$file_to_analyze!=""} {
   106         -    usage
   107         -  } else {
   108         -    set file_to_analyze $arg
   109         -  }
   110         -}
   111         -if {$file_to_analyze==""} usage
   112         -set root_filename $file_to_analyze
   113         -regexp {^file:(//)?([^?]*)} $file_to_analyze all x1 root_filename
   114         -if {![file exists $root_filename]} {
   115         -  puts stderr "No such file: $root_filename"
   116         -  exit 1
   117         -}
   118         -if {![file readable $root_filename]} {
   119         -  puts stderr "File is not readable: $root_filename"
   120         -  exit 1
   121         -}
   122         -set true_file_size [file size $root_filename]
   123         -if {$true_file_size<512} {
   124         -  puts stderr "Empty or malformed database: $root_filename"
   125         -  exit 1
   126         -}
   127         -
   128         -# Compute the total file size assuming test_multiplexor is being used.
   129         -# Assume that SQLITE_ENABLE_8_3_NAMES might be enabled
   130         -#
   131         -set extension [file extension $root_filename]
   132         -set pattern $root_filename
   133         -append pattern {[0-3][0-9][0-9]}
   134         -foreach f [glob -nocomplain $pattern] {
   135         -  incr true_file_size [file size $f]
   136         -  set extension {}
   137         -}
   138         -if {[string length $extension]>=2 && [string length $extension]<=4} {
   139         -  set pattern [file rootname $root_filename]
   140         -  append pattern {.[0-3][0-9][0-9]}
   141         -  foreach f [glob -nocomplain $pattern] {
   142         -    incr true_file_size [file size $f]
   143         -  }
   144         -}
   145         -
   146         -# Open the database
   147         -#
   148         -if {[catch {sqlite3 db $file_to_analyze -uri 1} msg]} {
   149         -  puts stderr "error trying to open $file_to_analyze: $msg"
   150         -  exit 1
   151         -}
   152         -if {$flags(-debug)} {
   153         -  proc dbtrace {txt} {puts $txt; flush stdout;}
   154         -  db trace ::dbtrace
   155         -}
   156         -
   157         -# Make sure all required compile-time options are available
   158         -#
   159         -if {![db exists {SELECT 1 FROM pragma_compile_options
   160         -                WHERE compile_options='ENABLE_DBSTAT_VTAB'}]} {
   161         -  puts "The SQLite database engine linked with this application\
   162         -        lacks required capabilities. Recompile using the\
   163         -        -DSQLITE_ENABLE_DBSTAT_VTAB compile-time option to fix\
   164         -        this problem."
   165         -  exit 1
   166         -}
   167         -
   168         -db eval {SELECT count(*) FROM sqlite_master}
   169         -set pageSize [expr {wide([db one {PRAGMA page_size}])}]
   170         -
   171         -if {$flags(-pageinfo)} {
   172         -  db eval {CREATE VIRTUAL TABLE temp.stat USING dbstat}
   173         -  db eval {SELECT name, path, pageno FROM temp.stat ORDER BY pageno} {
   174         -    puts "$pageno $name $path"
   175         -  }
   176         -  exit 0
   177         -}
   178         -if {$flags(-stats)} {
   179         -  db eval {CREATE VIRTUAL TABLE temp.stat USING dbstat}
   180         -  puts "BEGIN;"
   181         -  puts "CREATE TABLE stats("
   182         -  puts "  name       STRING,           /* Name of table or index */"
   183         -  puts "  path       INTEGER,          /* Path to page from root */"
   184         -  puts "  pageno     INTEGER,          /* Page number */"
   185         -  puts "  pagetype   STRING,           /* 'internal', 'leaf' or 'overflow' */"
   186         -  puts "  ncell      INTEGER,          /* Cells on page (0 for overflow) */"
   187         -  puts "  payload    INTEGER,          /* Bytes of payload on this page */"
   188         -  puts "  unused     INTEGER,          /* Bytes of unused space on this page */"
   189         -  puts "  mx_payload INTEGER,          /* Largest payload size of all cells */"
   190         -  puts "  pgoffset   INTEGER,          /* Offset of page in file */"
   191         -  puts "  pgsize     INTEGER           /* Size of the page */"
   192         -  puts ");"
   193         -  db eval {SELECT quote(name) || ',' ||
   194         -                  quote(path) || ',' ||
   195         -                  quote(pageno) || ',' ||
   196         -                  quote(pagetype) || ',' ||
   197         -                  quote(ncell) || ',' ||
   198         -                  quote(payload) || ',' ||
   199         -                  quote(unused) || ',' ||
   200         -                  quote(mx_payload) || ',' ||
   201         -                  quote(pgoffset) || ',' ||
   202         -                  quote(pgsize) AS x FROM stat} {
   203         -    puts "INSERT INTO stats VALUES($x);"
   204         -  }
   205         -  puts "COMMIT;"
   206         -  exit 0
   207         -}
   208         -
   209         -
   210         -# In-memory database for collecting statistics. This script loops through
   211         -# the tables and indices in the database being analyzed, adding a row for each
   212         -# to an in-memory database (for which the schema is shown below). It then
   213         -# queries the in-memory db to produce the space-analysis report.
   214         -#
   215         -sqlite3 mem :memory:
   216         -if {$flags(-debug)} {
   217         -  proc dbtrace {txt} {puts $txt; flush stdout;}
   218         -  mem trace ::dbtrace
   219         -}
   220         -set tabledef {CREATE TABLE space_used(
   221         -   name clob,        -- Name of a table or index in the database file
   222         -   tblname clob,     -- Name of associated table
   223         -   is_index boolean, -- TRUE if it is an index, false for a table
   224         -   is_without_rowid boolean, -- TRUE if WITHOUT ROWID table  
   225         -   nentry int,       -- Number of entries in the BTree
   226         -   leaf_entries int, -- Number of leaf entries
   227         -   depth int,        -- Depth of the b-tree
   228         -   payload int,      -- Total amount of data stored in this table or index
   229         -   ovfl_payload int, -- Total amount of data stored on overflow pages
   230         -   ovfl_cnt int,     -- Number of entries that use overflow
   231         -   mx_payload int,   -- Maximum payload size
   232         -   int_pages int,    -- Number of interior pages used
   233         -   leaf_pages int,   -- Number of leaf pages used
   234         -   ovfl_pages int,   -- Number of overflow pages used
   235         -   int_unused int,   -- Number of unused bytes on interior pages
   236         -   leaf_unused int,  -- Number of unused bytes on primary pages
   237         -   ovfl_unused int,  -- Number of unused bytes on overflow pages
   238         -   gap_cnt int,      -- Number of gaps in the page layout
   239         -   compressed_size int  -- Total bytes stored on disk
   240         -);}
   241         -mem eval $tabledef
   242         -
   243         -# Create a temporary "dbstat" virtual table.
   244         -#
   245         -db eval {CREATE VIRTUAL TABLE temp.stat USING dbstat}
   246         -db eval {CREATE TEMP TABLE dbstat AS SELECT * FROM temp.stat
   247         -         ORDER BY name, path}
   248         -db eval {DROP TABLE temp.stat}
   249         -
   250         -set isCompressed 0
   251         -set compressOverhead 0
   252         -set depth 0
   253         -set sql { SELECT name, tbl_name FROM sqlite_master WHERE rootpage>0 }
   254         -foreach {name tblname} [concat sqlite_master sqlite_master [db eval $sql]] {
   255         -
   256         -  set is_index [expr {$name!=$tblname}]
   257         -  set is_without_rowid [is_without_rowid $name]
   258         -  db eval {
   259         -    SELECT 
   260         -      sum(ncell) AS nentry,
   261         -      sum((pagetype=='leaf')*ncell) AS leaf_entries,
   262         -      sum(payload) AS payload,
   263         -      sum((pagetype=='overflow') * payload) AS ovfl_payload,
   264         -      sum(path LIKE '%+000000') AS ovfl_cnt,
   265         -      max(mx_payload) AS mx_payload,
   266         -      sum(pagetype=='internal') AS int_pages,
   267         -      sum(pagetype=='leaf') AS leaf_pages,
   268         -      sum(pagetype=='overflow') AS ovfl_pages,
   269         -      sum((pagetype=='internal') * unused) AS int_unused,
   270         -      sum((pagetype=='leaf') * unused) AS leaf_unused,
   271         -      sum((pagetype=='overflow') * unused) AS ovfl_unused,
   272         -      sum(pgsize) AS compressed_size,
   273         -      max((length(CASE WHEN path LIKE '%+%' THEN '' ELSE path END)+3)/4)
   274         -        AS depth
   275         -    FROM temp.dbstat WHERE name = $name
   276         -  } break
   277         -
   278         -  set total_pages [expr {$leaf_pages+$int_pages+$ovfl_pages}]
   279         -  set storage [expr {$total_pages*$pageSize}]
   280         -  if {!$isCompressed && $storage>$compressed_size} {
   281         -    set isCompressed 1
   282         -    set compressOverhead 14
   283         -  }
   284         -
   285         -  # Column 'gap_cnt' is set to the number of non-contiguous entries in the
   286         -  # list of pages visited if the b-tree structure is traversed in a top-down
   287         -  # fashion (each node visited before its child-tree is passed). Any overflow
   288         -  # chains present are traversed from start to finish before any child-tree
   289         -  # is.
   290         -  #
   291         -  set gap_cnt 0
   292         -  set prev 0
   293         -  db eval {
   294         -    SELECT pageno, pagetype FROM temp.dbstat
   295         -     WHERE name=$name
   296         -     ORDER BY pageno
   297         -  } {
   298         -    if {$prev>0 && $pagetype=="leaf" && $pageno!=$prev+1} {
   299         -      incr gap_cnt
   300         -    }
   301         -    set prev $pageno
   302         -  }
   303         -  mem eval {
   304         -    INSERT INTO space_used VALUES(
   305         -      $name,
   306         -      $tblname,
   307         -      $is_index,
   308         -      $is_without_rowid,
   309         -      $nentry,
   310         -      $leaf_entries,
   311         -      $depth,
   312         -      $payload,     
   313         -      $ovfl_payload,
   314         -      $ovfl_cnt,   
   315         -      $mx_payload,
   316         -      $int_pages,
   317         -      $leaf_pages,  
   318         -      $ovfl_pages, 
   319         -      $int_unused, 
   320         -      $leaf_unused,
   321         -      $ovfl_unused,
   322         -      $gap_cnt,
   323         -      $compressed_size
   324         -    );
   325         -  }
   326         -}
   327         -
   328         -proc integerify {real} {
   329         -  if {[string is double -strict $real]} {
   330         -    return [expr {wide($real)}]
   331         -  } else {
   332         -    return 0
   333         -  }
   334         -}
   335         -mem function int integerify
   336         -
   337         -# Quote a string for use in an SQL query. Examples:
   338         -#
   339         -# [quote {hello world}]   == {'hello world'}
   340         -# [quote {hello world's}] == {'hello world''s'}
   341         -#
   342         -proc quote {txt} {
   343         -  return [string map {' ''} $txt]
   344         -}
   345         -
   346         -# Output a title line
   347         -#
   348         -proc titleline {title} {
   349         -  if {$title==""} {
   350         -    puts [string repeat * 79]
   351         -  } else {
   352         -    set len [string length $title]
   353         -    set stars [string repeat * [expr 79-$len-5]]
   354         -    puts "*** $title $stars"
   355         -  }
   356         -}
   357         -
   358         -# Generate a single line of output in the statistics section of the
   359         -# report.
   360         -#
   361         -proc statline {title value {extra {}}} {
   362         -  set len [string length $title]
   363         -  set dots [string repeat . [expr 50-$len]]
   364         -  set len [string length $value]
   365         -  set sp2 [string range {          } $len end]
   366         -  if {$extra ne ""} {
   367         -    set extra " $extra"
   368         -  }
   369         -  puts "$title$dots $value$sp2$extra"
   370         -}
   371         -
   372         -# Generate a formatted percentage value for $num/$denom
   373         -#
   374         -proc percent {num denom {of {}}} {
   375         -  if {$denom==0.0} {return ""}
   376         -  set v [expr {$num*100.0/$denom}]
   377         -  set of {}
   378         -  if {$v==100.0 || $v<0.001 || ($v>1.0 && $v<99.0)} {
   379         -    return [format {%5.1f%% %s} $v $of]
   380         -  } elseif {$v<0.1 || $v>99.9} {
   381         -    return [format {%7.3f%% %s} $v $of]
   382         -  } else {
   383         -    return [format {%6.2f%% %s} $v $of]
   384         -  }
   385         -}
   386         -
   387         -proc divide {num denom} {
   388         -  if {$denom==0} {return 0.0}
   389         -  return [format %.2f [expr double($num)/double($denom)]]
   390         -}
   391         -
   392         -# Generate a subreport that covers some subset of the database.
   393         -# the $where clause determines which subset to analyze.
   394         -#
   395         -proc subreport {title where showFrag} {
   396         -  global pageSize file_pgcnt compressOverhead
   397         -
   398         -  # Query the in-memory database for the sum of various statistics 
   399         -  # for the subset of tables/indices identified by the WHERE clause in
   400         -  # $where. Note that even if the WHERE clause matches no rows, the
   401         -  # following query returns exactly one row (because it is an aggregate).
   402         -  #
   403         -  # The results of the query are stored directly by SQLite into local 
   404         -  # variables (i.e. $nentry, $payload etc.).
   405         -  #
   406         -  mem eval "
   407         -    SELECT
   408         -      int(sum(
   409         -        CASE WHEN (is_without_rowid OR is_index) THEN nentry 
   410         -             ELSE leaf_entries 
   411         -        END
   412         -      )) AS nentry,
   413         -      int(sum(payload)) AS payload,
   414         -      int(sum(ovfl_payload)) AS ovfl_payload,
   415         -      max(mx_payload) AS mx_payload,
   416         -      int(sum(ovfl_cnt)) as ovfl_cnt,
   417         -      int(sum(leaf_pages)) AS leaf_pages,
   418         -      int(sum(int_pages)) AS int_pages,
   419         -      int(sum(ovfl_pages)) AS ovfl_pages,
   420         -      int(sum(leaf_unused)) AS leaf_unused,
   421         -      int(sum(int_unused)) AS int_unused,
   422         -      int(sum(ovfl_unused)) AS ovfl_unused,
   423         -      int(sum(gap_cnt)) AS gap_cnt,
   424         -      int(sum(compressed_size)) AS compressed_size,
   425         -      int(max(depth)) AS depth,
   426         -      count(*) AS cnt
   427         -    FROM space_used WHERE $where" {} {}
   428         -
   429         -  # Output the sub-report title, nicely decorated with * characters.
   430         -  #
   431         -  puts ""
   432         -  titleline $title
   433         -  puts ""
   434         -
   435         -  # Calculate statistics and store the results in TCL variables, as follows:
   436         -  #
   437         -  # total_pages: Database pages consumed.
   438         -  # total_pages_percent: Pages consumed as a percentage of the file.
   439         -  # storage: Bytes consumed.
   440         -  # payload_percent: Payload bytes used as a percentage of $storage.
   441         -  # total_unused: Unused bytes on pages.
   442         -  # avg_payload: Average payload per btree entry.
   443         -  # avg_fanout: Average fanout for internal pages.
   444         -  # avg_unused: Average unused bytes per btree entry.
   445         -  # avg_meta: Average metadata overhead per entry.
   446         -  # ovfl_cnt_percent: Percentage of btree entries that use overflow pages.
   447         -  #
   448         -  set total_pages [expr {$leaf_pages+$int_pages+$ovfl_pages}]
   449         -  set total_pages_percent [percent $total_pages $file_pgcnt]
   450         -  set storage [expr {$total_pages*$pageSize}]
   451         -  set payload_percent [percent $payload $storage {of storage consumed}]
   452         -  set total_unused [expr {$ovfl_unused+$int_unused+$leaf_unused}]
   453         -  set avg_payload [divide $payload $nentry]
   454         -  set avg_unused [divide $total_unused $nentry]
   455         -  set total_meta [expr {$storage - $payload - $total_unused}]
   456         -  set total_meta [expr {$total_meta + 4*($ovfl_pages - $ovfl_cnt)}]
   457         -  set meta_percent [percent $total_meta $storage {of metadata}]
   458         -  set avg_meta [divide $total_meta $nentry]
   459         -  if {$int_pages>0} {
   460         -    # TODO: Is this formula correct?
   461         -    set nTab [mem eval "
   462         -      SELECT count(*) FROM (
   463         -          SELECT DISTINCT tblname FROM space_used WHERE $where AND is_index=0
   464         -      )
   465         -    "]
   466         -    set avg_fanout [mem eval "
   467         -      SELECT (sum(leaf_pages+int_pages)-$nTab)/sum(int_pages) FROM space_used
   468         -          WHERE $where
   469         -    "]
   470         -    set avg_fanout [format %.2f $avg_fanout]
   471         -  }
   472         -  set ovfl_cnt_percent [percent $ovfl_cnt $nentry {of all entries}]
   473         -
   474         -  # Print out the sub-report statistics.
   475         -  #
   476         -  statline {Percentage of total database} $total_pages_percent
   477         -  statline {Number of entries} $nentry
   478         -  statline {Bytes of storage consumed} $storage
   479         -  if {$compressed_size!=$storage} {
   480         -    set compressed_size [expr {$compressed_size+$compressOverhead*$total_pages}]
   481         -    set pct [expr {$compressed_size*100.0/$storage}]
   482         -    set pct [format {%5.1f%%} $pct]
   483         -    statline {Bytes used after compression} $compressed_size $pct
   484         -  }
   485         -  statline {Bytes of payload} $payload $payload_percent
   486         -  statline {Bytes of metadata} $total_meta $meta_percent
   487         -  if {$cnt==1} {statline {B-tree depth} $depth}
   488         -  statline {Average payload per entry} $avg_payload
   489         -  statline {Average unused bytes per entry} $avg_unused
   490         -  statline {Average metadata per entry} $avg_meta
   491         -  if {[info exists avg_fanout]} {
   492         -    statline {Average fanout} $avg_fanout
   493         -  }
   494         -  if {$showFrag && $total_pages>1} {
   495         -    set fragmentation [percent $gap_cnt [expr {$total_pages-1}]]
   496         -    statline {Non-sequential pages} $gap_cnt $fragmentation
   497         -  }
   498         -  statline {Maximum payload per entry} $mx_payload
   499         -  statline {Entries that use overflow} $ovfl_cnt $ovfl_cnt_percent
   500         -  if {$int_pages>0} {
   501         -    statline {Index pages used} $int_pages
   502         -  }
   503         -  statline {Primary pages used} $leaf_pages
   504         -  statline {Overflow pages used} $ovfl_pages
   505         -  statline {Total pages used} $total_pages
   506         -  if {$int_unused>0} {
   507         -    set int_unused_percent [
   508         -         percent $int_unused [expr {$int_pages*$pageSize}] {of index space}]
   509         -    statline "Unused bytes on index pages" $int_unused $int_unused_percent
   510         -  }
   511         -  statline "Unused bytes on primary pages" $leaf_unused [
   512         -     percent $leaf_unused [expr {$leaf_pages*$pageSize}] {of primary space}]
   513         -  statline "Unused bytes on overflow pages" $ovfl_unused [
   514         -     percent $ovfl_unused [expr {$ovfl_pages*$pageSize}] {of overflow space}]
   515         -  statline "Unused bytes on all pages" $total_unused [
   516         -               percent $total_unused $storage {of all space}]
   517         -  return 1
   518         -}
   519         -
   520         -# Calculate the overhead in pages caused by auto-vacuum. 
   521         -#
   522         -# This procedure calculates and returns the number of pages used by the 
   523         -# auto-vacuum 'pointer-map'. If the database does not support auto-vacuum,
   524         -# then 0 is returned. The two arguments are the size of the database file in
   525         -# pages and the page size used by the database (in bytes).
   526         -proc autovacuum_overhead {filePages pageSize} {
   527         -
   528         -  # Set $autovacuum to non-zero for databases that support auto-vacuum.
   529         -  set autovacuum [db one {PRAGMA auto_vacuum}]
   530         -
   531         -  # If the database is not an auto-vacuum database or the file consists
   532         -  # of one page only then there is no overhead for auto-vacuum. Return zero.
   533         -  if {0==$autovacuum || $filePages==1} {
   534         -    return 0
   535         -  }
   536         -
   537         -  # The number of entries on each pointer map page. The layout of the
   538         -  # database file is one pointer-map page, followed by $ptrsPerPage other
   539         -  # pages, followed by a pointer-map page etc. The first pointer-map page
   540         -  # is the second page of the file overall.
   541         -  set ptrsPerPage [expr double($pageSize/5)]
   542         -
   543         -  # Return the number of pointer map pages in the database.
   544         -  return [expr wide(ceil( ($filePages-1.0)/($ptrsPerPage+1.0) ))]
   545         -}
   546         -
   547         -
   548         -# Calculate the summary statistics for the database and store the results
   549         -# in TCL variables. They are output below. Variables are as follows:
   550         -#
   551         -# pageSize:      Size of each page in bytes.
   552         -# file_bytes:    File size in bytes.
   553         -# file_pgcnt:    Number of pages in the file.
   554         -# file_pgcnt2:   Number of pages in the file (calculated).
   555         -# av_pgcnt:      Pages consumed by the auto-vacuum pointer-map.
   556         -# av_percent:    Percentage of the file consumed by auto-vacuum pointer-map.
   557         -# inuse_pgcnt:   Data pages in the file.
   558         -# inuse_percent: Percentage of pages used to store data.
   559         -# free_pgcnt:    Free pages calculated as (<total pages> - <in-use pages>)
   560         -# free_pgcnt2:   Free pages in the file according to the file header.
   561         -# free_percent:  Percentage of file consumed by free pages (calculated).
   562         -# free_percent2: Percentage of file consumed by free pages (header).
   563         -# ntable:        Number of tables in the db.
   564         -# nindex:        Number of indices in the db.
   565         -# nautoindex:    Number of indices created automatically.
   566         -# nmanindex:     Number of indices created manually.
   567         -# user_payload:  Number of bytes of payload in table btrees 
   568         -#                (not including sqlite_master)
   569         -# user_percent:  $user_payload as a percentage of total file size.
   570         -
   571         -### The following, setting $file_bytes based on the actual size of the file
   572         -### on disk, causes this tool to choke on zipvfs databases. So set it based
   573         -### on the return of [PRAGMA page_count] instead.
   574         -if 0 {
   575         -  set file_bytes  [file size $file_to_analyze]
   576         -  set file_pgcnt  [expr {$file_bytes/$pageSize}]
   577         -}
   578         -set file_pgcnt  [db one {PRAGMA page_count}]
   579         -set file_bytes  [expr {$file_pgcnt * $pageSize}]
   580         -
   581         -set av_pgcnt    [autovacuum_overhead $file_pgcnt $pageSize]
   582         -set av_percent  [percent $av_pgcnt $file_pgcnt]
   583         -
   584         -set sql {SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM space_used}
   585         -set inuse_pgcnt   [expr wide([mem eval $sql])]
   586         -set inuse_percent [percent $inuse_pgcnt $file_pgcnt]
   587         -
   588         -set free_pgcnt    [expr {$file_pgcnt-$inuse_pgcnt-$av_pgcnt}]
   589         -set free_percent  [percent $free_pgcnt $file_pgcnt]
   590         -set free_pgcnt2   [db one {PRAGMA freelist_count}]
   591         -set free_percent2 [percent $free_pgcnt2 $file_pgcnt]
   592         -
   593         -set file_pgcnt2 [expr {$inuse_pgcnt+$free_pgcnt2+$av_pgcnt}]
   594         -
   595         -set ntable [db eval {SELECT count(*)+1 FROM sqlite_master WHERE type='table'}]
   596         -set nindex [db eval {SELECT count(*) FROM sqlite_master WHERE type='index'}]
   597         -set sql {SELECT count(*) FROM sqlite_master WHERE name LIKE 'sqlite_autoindex%'}
   598         -set nautoindex [db eval $sql]
   599         -set nmanindex [expr {$nindex-$nautoindex}]
   600         -
   601         -# set total_payload [mem eval "SELECT sum(payload) FROM space_used"]
   602         -set user_payload [mem one {SELECT int(sum(payload)) FROM space_used
   603         -     WHERE NOT is_index AND name NOT LIKE 'sqlite_master'}]
   604         -set user_percent [percent $user_payload $file_bytes]
   605         -
   606         -# Output the summary statistics calculated above.
   607         -#
   608         -puts "/** Disk-Space Utilization Report For $root_filename"
   609         -puts ""
   610         -statline {Page size in bytes} $pageSize
   611         -statline {Pages in the whole file (measured)} $file_pgcnt
   612         -statline {Pages in the whole file (calculated)} $file_pgcnt2
   613         -statline {Pages that store data} $inuse_pgcnt $inuse_percent
   614         -statline {Pages on the freelist (per header)} $free_pgcnt2 $free_percent2
   615         -statline {Pages on the freelist (calculated)} $free_pgcnt $free_percent
   616         -statline {Pages of auto-vacuum overhead} $av_pgcnt $av_percent
   617         -statline {Number of tables in the database} $ntable
   618         -statline {Number of indices} $nindex
   619         -statline {Number of defined indices} $nmanindex
   620         -statline {Number of implied indices} $nautoindex
   621         -if {$isCompressed} {
   622         -  statline {Size of uncompressed content in bytes} $file_bytes
   623         -  set efficiency [percent $true_file_size $file_bytes]
   624         -  statline {Size of compressed file on disk} $true_file_size $efficiency
   625         -} else {
   626         -  statline {Size of the file in bytes} $file_bytes
   627         -}
   628         -statline {Bytes of user payload stored} $user_payload $user_percent
   629         -
   630         -# Output table rankings
   631         -#
   632         -puts ""
   633         -titleline "Page counts for all tables with their indices"
   634         -puts ""
   635         -mem eval {SELECT tblname, count(*) AS cnt, 
   636         -              int(sum(int_pages+leaf_pages+ovfl_pages)) AS size
   637         -          FROM space_used GROUP BY tblname ORDER BY size+0 DESC, tblname} {} {
   638         -  statline [string toupper $tblname] $size [percent $size $file_pgcnt]
   639         -}
   640         -puts ""
   641         -titleline "Page counts for all tables and indices separately"
   642         -puts ""
   643         -mem eval {
   644         -  SELECT
   645         -       upper(name) AS nm,
   646         -       int(int_pages+leaf_pages+ovfl_pages) AS size
   647         -    FROM space_used
   648         -   ORDER BY size+0 DESC, name} {} {
   649         -  statline $nm $size [percent $size $file_pgcnt]
   650         -}
   651         -if {$isCompressed} {
   652         -  puts ""
   653         -  titleline "Bytes of disk space used after compression"
   654         -  puts ""
   655         -  set csum 0
   656         -  mem eval {SELECT tblname,
   657         -                  int(sum(compressed_size)) +
   658         -                         $compressOverhead*sum(int_pages+leaf_pages+ovfl_pages)
   659         -                        AS csize
   660         -          FROM space_used GROUP BY tblname ORDER BY csize+0 DESC, tblname} {} {
   661         -    incr csum $csize
   662         -    statline [string toupper $tblname] $csize [percent $csize $true_file_size]
   663         -  }
   664         -  set overhead [expr {$true_file_size - $csum}]
   665         -  if {$overhead>0} {
   666         -    statline {Header and free space} $overhead [percent $overhead $true_file_size]
   667         -  }
   668         -}
   669         -
   670         -# Output subreports
   671         -#
   672         -if {$nindex>0} {
   673         -  subreport {All tables and indices} 1 0
   674         -}
   675         -subreport {All tables} {NOT is_index} 0
   676         -if {$nindex>0} {
   677         -  subreport {All indices} {is_index} 0
   678         -}
   679         -foreach tbl [mem eval {SELECT DISTINCT tblname name FROM space_used
   680         -                       ORDER BY name}] {
   681         -  set qn [quote $tbl]
   682         -  set name [string toupper $tbl]
   683         -  set n [mem eval {SELECT count(*) FROM space_used WHERE tblname=$tbl}]
   684         -  if {$n>1} {
   685         -    set idxlist [mem eval "SELECT name FROM space_used
   686         -                            WHERE tblname='$qn' AND is_index
   687         -                            ORDER BY 1"]
   688         -    subreport "Table $name and all its indices" "tblname='$qn'" 0
   689         -    subreport "Table $name w/o any indices" "name='$qn'" 1
   690         -    if {[llength $idxlist]>1} {
   691         -      subreport "Indices of table $name" "tblname='$qn' AND is_index" 0
   692         -    }
   693         -    foreach idx $idxlist {
   694         -      set qidx [quote $idx]
   695         -      subreport "Index [string toupper $idx] of table $name" "name='$qidx'" 1
   696         -    }
   697         -  } else {
   698         -    subreport "Table $name" "name='$qn'" 1
   699         -  }
   700         -}
   701         -
   702         -# Output instructions on what the numbers above mean.
   703         -#
   704         -puts ""
   705         -titleline Definitions
   706         -puts {
   707         -Page size in bytes
   708         -
   709         -    The number of bytes in a single page of the database file.  
   710         -    Usually 1024.
   711         -
   712         -Number of pages in the whole file
   713         -}
   714         -puts "    The number of $pageSize-byte pages that go into forming the complete
   715         -    database"
   716         -puts {
   717         -Pages that store data
   718         -
   719         -    The number of pages that store data, either as primary B*Tree pages or
   720         -    as overflow pages.  The number at the right is the data pages divided by
   721         -    the total number of pages in the file.
   722         -
   723         -Pages on the freelist
   724         -
   725         -    The number of pages that are not currently in use but are reserved for
   726         -    future use.  The percentage at the right is the number of freelist pages
   727         -    divided by the total number of pages in the file.
   728         -
   729         -Pages of auto-vacuum overhead
   730         -
   731         -    The number of pages that store data used by the database to facilitate
   732         -    auto-vacuum. This is zero for databases that do not support auto-vacuum.
   733         -
   734         -Number of tables in the database
   735         -
   736         -    The number of tables in the database, including the SQLITE_MASTER table
   737         -    used to store schema information.
   738         -
   739         -Number of indices
   740         -
   741         -    The total number of indices in the database.
   742         -
   743         -Number of defined indices
   744         -
   745         -    The number of indices created using an explicit CREATE INDEX statement.
   746         -
   747         -Number of implied indices
   748         -
   749         -    The number of indices used to implement PRIMARY KEY or UNIQUE constraints
   750         -    on tables.
   751         -
   752         -Size of the file in bytes
   753         -
   754         -    The total amount of disk space used by the entire database files.
   755         -
   756         -Bytes of user payload stored
   757         -
   758         -    The total number of bytes of user payload stored in the database. The
   759         -    schema information in the SQLITE_MASTER table is not counted when
   760         -    computing this number.  The percentage at the right shows the payload
   761         -    divided by the total file size.
   762         -
   763         -Percentage of total database
   764         -
   765         -    The amount of the complete database file that is devoted to storing
   766         -    information described by this category.
   767         -
   768         -Number of entries
   769         -
   770         -    The total number of B-Tree key/value pairs stored under this category.
   771         -
   772         -Bytes of storage consumed
   773         -
   774         -    The total amount of disk space required to store all B-Tree entries
   775         -    under this category.  The is the total number of pages used times
   776         -    the pages size.
   777         -
   778         -Bytes of payload
   779         -
   780         -    The amount of payload stored under this category.  Payload is the data
   781         -    part of table entries and the key part of index entries.  The percentage
   782         -    at the right is the bytes of payload divided by the bytes of storage 
   783         -    consumed.
   784         -
   785         -Bytes of metadata
   786         -
   787         -    The amount of formatting and structural information stored in the
   788         -    table or index.  Metadata includes the btree page header, the cell pointer
   789         -    array, the size field for each cell, the left child pointer or non-leaf
   790         -    cells, the overflow pointers for overflow cells, and the rowid value for
   791         -    rowid table cells.  In other words, metadata is everything that is neither
   792         -    unused space nor content.  The record header in the payload is counted as
   793         -    content, not metadata.
   794         -
   795         -Average payload per entry
   796         -
   797         -    The average amount of payload on each entry.  This is just the bytes of
   798         -    payload divided by the number of entries.
   799         -
   800         -Average unused bytes per entry
   801         -
   802         -    The average amount of free space remaining on all pages under this
   803         -    category on a per-entry basis.  This is the number of unused bytes on
   804         -    all pages divided by the number of entries.
   805         -
   806         -Non-sequential pages
   807         -
   808         -    The number of pages in the table or index that are out of sequence.
   809         -    Many filesystems are optimized for sequential file access so a small
   810         -    number of non-sequential pages might result in faster queries,
   811         -    especially for larger database files that do not fit in the disk cache.
   812         -    Note that after running VACUUM, the root page of each table or index is
   813         -    at the beginning of the database file and all other pages are in a
   814         -    separate part of the database file, resulting in a single non-
   815         -    sequential page.
   816         -
   817         -Maximum payload per entry
   818         -
   819         -    The largest payload size of any entry.
   820         -
   821         -Entries that use overflow
   822         -
   823         -    The number of entries that user one or more overflow pages.
   824         -
   825         -Total pages used
   826         -
   827         -    This is the number of pages used to hold all information in the current
   828         -    category.  This is the sum of index, primary, and overflow pages.
   829         -
   830         -Index pages used
   831         -
   832         -    This is the number of pages in a table B-tree that hold only key (rowid)
   833         -    information and no data.
   834         -
   835         -Primary pages used
   836         -
   837         -    This is the number of B-tree pages that hold both key and data.
   838         -
   839         -Overflow pages used
   840         -
   841         -    The total number of overflow pages used for this category.
   842         -
   843         -Unused bytes on index pages
   844         -
   845         -    The total number of bytes of unused space on all index pages.  The
   846         -    percentage at the right is the number of unused bytes divided by the
   847         -    total number of bytes on index pages.
   848         -
   849         -Unused bytes on primary pages
   850         -
   851         -    The total number of bytes of unused space on all primary pages.  The
   852         -    percentage at the right is the number of unused bytes divided by the
   853         -    total number of bytes on primary pages.
   854         -
   855         -Unused bytes on overflow pages
   856         -
   857         -    The total number of bytes of unused space on all overflow pages.  The
   858         -    percentage at the right is the number of unused bytes divided by the
   859         -    total number of bytes on overflow pages.
   860         -
   861         -Unused bytes on all pages
   862         -
   863         -    The total number of bytes of unused space on all primary and overflow 
   864         -    pages.  The percentage at the right is the number of unused bytes 
   865         -    divided by the total number of bytes.
   866         -}
   867         -
   868         -# Output a dump of the in-memory database. This can be used for more
   869         -# complex offline analysis.
   870         -#
   871         -titleline {}
   872         -puts "The entire text of this report can be sourced into any SQL database"
   873         -puts "engine for further analysis.  All of the text above is an SQL comment."
   874         -puts "The data used to generate this report follows:"
   875         -puts "*/"
   876         -puts "BEGIN;"
   877         -puts $tabledef
   878         -unset -nocomplain x
   879         -mem eval {SELECT * FROM space_used} x {
   880         -  puts -nonewline "INSERT INTO space_used VALUES"
   881         -  set sep (
   882         -  foreach col $x(*) {
   883         -    set v $x($col)
   884         -    if {$v=="" || ![string is double $v]} {set v '[quote $v]'}
   885         -    puts -nonewline $sep$v
   886         -    set sep ,
   887         -  }
   888         -  puts ");"
   889         -}
   890         -puts "COMMIT;"
   891         -
   892         -} err]} {
   893         -  puts "ERROR: $err"
   894         -  puts $errorInfo
   895         -  exit 1
   896         -}

Deleted jni/tcl/pkgs/sqlite3.28.0/compat/sqlite3/sqlite3.c.

more than 10,000 changes

Deleted jni/tcl/pkgs/sqlite3.28.0/compat/sqlite3/sqlite3.h.

more than 10,000 changes

Deleted jni/tcl/pkgs/sqlite3.28.0/compat/sqlite3/sqlite3ext.h.

     1         -/*
     2         -** 2006 June 7
     3         -**
     4         -** The author disclaims copyright to this source code.  In place of
     5         -** a legal notice, here is a blessing:
     6         -**
     7         -**    May you do good and not evil.
     8         -**    May you find forgiveness for yourself and forgive others.
     9         -**    May you share freely, never taking more than you give.
    10         -**
    11         -*************************************************************************
    12         -** This header file defines the SQLite interface for use by
    13         -** shared libraries that want to be imported as extensions into
    14         -** an SQLite instance.  Shared libraries that intend to be loaded
    15         -** as extensions by SQLite should #include this file instead of 
    16         -** sqlite3.h.
    17         -*/
    18         -#ifndef SQLITE3EXT_H
    19         -#define SQLITE3EXT_H
    20         -#include "sqlite3.h"
    21         -
    22         -/*
    23         -** The following structure holds pointers to all of the SQLite API
    24         -** routines.
    25         -**
    26         -** WARNING:  In order to maintain backwards compatibility, add new
    27         -** interfaces to the end of this structure only.  If you insert new
    28         -** interfaces in the middle of this structure, then older different
    29         -** versions of SQLite will not be able to load each other's shared
    30         -** libraries!
    31         -*/
    32         -struct sqlite3_api_routines {
    33         -  void * (*aggregate_context)(sqlite3_context*,int nBytes);
    34         -  int  (*aggregate_count)(sqlite3_context*);
    35         -  int  (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*));
    36         -  int  (*bind_double)(sqlite3_stmt*,int,double);
    37         -  int  (*bind_int)(sqlite3_stmt*,int,int);
    38         -  int  (*bind_int64)(sqlite3_stmt*,int,sqlite_int64);
    39         -  int  (*bind_null)(sqlite3_stmt*,int);
    40         -  int  (*bind_parameter_count)(sqlite3_stmt*);
    41         -  int  (*bind_parameter_index)(sqlite3_stmt*,const char*zName);
    42         -  const char * (*bind_parameter_name)(sqlite3_stmt*,int);
    43         -  int  (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*));
    44         -  int  (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*));
    45         -  int  (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*);
    46         -  int  (*busy_handler)(sqlite3*,int(*)(void*,int),void*);
    47         -  int  (*busy_timeout)(sqlite3*,int ms);
    48         -  int  (*changes)(sqlite3*);
    49         -  int  (*close)(sqlite3*);
    50         -  int  (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,
    51         -                           int eTextRep,const char*));
    52         -  int  (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,
    53         -                             int eTextRep,const void*));
    54         -  const void * (*column_blob)(sqlite3_stmt*,int iCol);
    55         -  int  (*column_bytes)(sqlite3_stmt*,int iCol);
    56         -  int  (*column_bytes16)(sqlite3_stmt*,int iCol);
    57         -  int  (*column_count)(sqlite3_stmt*pStmt);
    58         -  const char * (*column_database_name)(sqlite3_stmt*,int);
    59         -  const void * (*column_database_name16)(sqlite3_stmt*,int);
    60         -  const char * (*column_decltype)(sqlite3_stmt*,int i);
    61         -  const void * (*column_decltype16)(sqlite3_stmt*,int);
    62         -  double  (*column_double)(sqlite3_stmt*,int iCol);
    63         -  int  (*column_int)(sqlite3_stmt*,int iCol);
    64         -  sqlite_int64  (*column_int64)(sqlite3_stmt*,int iCol);
    65         -  const char * (*column_name)(sqlite3_stmt*,int);
    66         -  const void * (*column_name16)(sqlite3_stmt*,int);
    67         -  const char * (*column_origin_name)(sqlite3_stmt*,int);
    68         -  const void * (*column_origin_name16)(sqlite3_stmt*,int);
    69         -  const char * (*column_table_name)(sqlite3_stmt*,int);
    70         -  const void * (*column_table_name16)(sqlite3_stmt*,int);
    71         -  const unsigned char * (*column_text)(sqlite3_stmt*,int iCol);
    72         -  const void * (*column_text16)(sqlite3_stmt*,int iCol);
    73         -  int  (*column_type)(sqlite3_stmt*,int iCol);
    74         -  sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol);
    75         -  void * (*commit_hook)(sqlite3*,int(*)(void*),void*);
    76         -  int  (*complete)(const char*sql);
    77         -  int  (*complete16)(const void*sql);
    78         -  int  (*create_collation)(sqlite3*,const char*,int,void*,
    79         -                           int(*)(void*,int,const void*,int,const void*));
    80         -  int  (*create_collation16)(sqlite3*,const void*,int,void*,
    81         -                             int(*)(void*,int,const void*,int,const void*));
    82         -  int  (*create_function)(sqlite3*,const char*,int,int,void*,
    83         -                          void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
    84         -                          void (*xStep)(sqlite3_context*,int,sqlite3_value**),
    85         -                          void (*xFinal)(sqlite3_context*));
    86         -  int  (*create_function16)(sqlite3*,const void*,int,int,void*,
    87         -                            void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
    88         -                            void (*xStep)(sqlite3_context*,int,sqlite3_value**),
    89         -                            void (*xFinal)(sqlite3_context*));
    90         -  int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*);
    91         -  int  (*data_count)(sqlite3_stmt*pStmt);
    92         -  sqlite3 * (*db_handle)(sqlite3_stmt*);
    93         -  int (*declare_vtab)(sqlite3*,const char*);
    94         -  int  (*enable_shared_cache)(int);
    95         -  int  (*errcode)(sqlite3*db);
    96         -  const char * (*errmsg)(sqlite3*);
    97         -  const void * (*errmsg16)(sqlite3*);
    98         -  int  (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**);
    99         -  int  (*expired)(sqlite3_stmt*);
   100         -  int  (*finalize)(sqlite3_stmt*pStmt);
   101         -  void  (*free)(void*);
   102         -  void  (*free_table)(char**result);
   103         -  int  (*get_autocommit)(sqlite3*);
   104         -  void * (*get_auxdata)(sqlite3_context*,int);
   105         -  int  (*get_table)(sqlite3*,const char*,char***,int*,int*,char**);
   106         -  int  (*global_recover)(void);
   107         -  void  (*interruptx)(sqlite3*);
   108         -  sqlite_int64  (*last_insert_rowid)(sqlite3*);
   109         -  const char * (*libversion)(void);
   110         -  int  (*libversion_number)(void);
   111         -  void *(*malloc)(int);
   112         -  char * (*mprintf)(const char*,...);
   113         -  int  (*open)(const char*,sqlite3**);
   114         -  int  (*open16)(const void*,sqlite3**);
   115         -  int  (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
   116         -  int  (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
   117         -  void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
   118         -  void  (*progress_handler)(sqlite3*,int,int(*)(void*),void*);
   119         -  void *(*realloc)(void*,int);
   120         -  int  (*reset)(sqlite3_stmt*pStmt);
   121         -  void  (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*));
   122         -  void  (*result_double)(sqlite3_context*,double);
   123         -  void  (*result_error)(sqlite3_context*,const char*,int);
   124         -  void  (*result_error16)(sqlite3_context*,const void*,int);
   125         -  void  (*result_int)(sqlite3_context*,int);
   126         -  void  (*result_int64)(sqlite3_context*,sqlite_int64);
   127         -  void  (*result_null)(sqlite3_context*);
   128         -  void  (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
   129         -  void  (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
   130         -  void  (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
   131         -  void  (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
   132         -  void  (*result_value)(sqlite3_context*,sqlite3_value*);
   133         -  void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
   134         -  int  (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
   135         -                         const char*,const char*),void*);
   136         -  void  (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
   137         -  char * (*xsnprintf)(int,char*,const char*,...);
   138         -  int  (*step)(sqlite3_stmt*);
   139         -  int  (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
   140         -                                char const**,char const**,int*,int*,int*);
   141         -  void  (*thread_cleanup)(void);
   142         -  int  (*total_changes)(sqlite3*);
   143         -  void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*);
   144         -  int  (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*);
   145         -  void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,
   146         -                                         sqlite_int64),void*);
   147         -  void * (*user_data)(sqlite3_context*);
   148         -  const void * (*value_blob)(sqlite3_value*);
   149         -  int  (*value_bytes)(sqlite3_value*);
   150         -  int  (*value_bytes16)(sqlite3_value*);
   151         -  double  (*value_double)(sqlite3_value*);
   152         -  int  (*value_int)(sqlite3_value*);
   153         -  sqlite_int64  (*value_int64)(sqlite3_value*);
   154         -  int  (*value_numeric_type)(sqlite3_value*);
   155         -  const unsigned char * (*value_text)(sqlite3_value*);
   156         -  const void * (*value_text16)(sqlite3_value*);
   157         -  const void * (*value_text16be)(sqlite3_value*);
   158         -  const void * (*value_text16le)(sqlite3_value*);
   159         -  int  (*value_type)(sqlite3_value*);
   160         -  char *(*vmprintf)(const char*,va_list);
   161         -  /* Added ??? */
   162         -  int (*overload_function)(sqlite3*, const char *zFuncName, int nArg);
   163         -  /* Added by 3.3.13 */
   164         -  int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
   165         -  int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
   166         -  int (*clear_bindings)(sqlite3_stmt*);
   167         -  /* Added by 3.4.1 */
   168         -  int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,
   169         -                          void (*xDestroy)(void *));
   170         -  /* Added by 3.5.0 */
   171         -  int (*bind_zeroblob)(sqlite3_stmt*,int,int);
   172         -  int (*blob_bytes)(sqlite3_blob*);
   173         -  int (*blob_close)(sqlite3_blob*);
   174         -  int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,
   175         -                   int,sqlite3_blob**);
   176         -  int (*blob_read)(sqlite3_blob*,void*,int,int);
   177         -  int (*blob_write)(sqlite3_blob*,const void*,int,int);
   178         -  int (*create_collation_v2)(sqlite3*,const char*,int,void*,
   179         -                             int(*)(void*,int,const void*,int,const void*),
   180         -                             void(*)(void*));
   181         -  int (*file_control)(sqlite3*,const char*,int,void*);
   182         -  sqlite3_int64 (*memory_highwater)(int);
   183         -  sqlite3_int64 (*memory_used)(void);
   184         -  sqlite3_mutex *(*mutex_alloc)(int);
   185         -  void (*mutex_enter)(sqlite3_mutex*);
   186         -  void (*mutex_free)(sqlite3_mutex*);
   187         -  void (*mutex_leave)(sqlite3_mutex*);
   188         -  int (*mutex_try)(sqlite3_mutex*);
   189         -  int (*open_v2)(const char*,sqlite3**,int,const char*);
   190         -  int (*release_memory)(int);
   191         -  void (*result_error_nomem)(sqlite3_context*);
   192         -  void (*result_error_toobig)(sqlite3_context*);
   193         -  int (*sleep)(int);
   194         -  void (*soft_heap_limit)(int);
   195         -  sqlite3_vfs *(*vfs_find)(const char*);
   196         -  int (*vfs_register)(sqlite3_vfs*,int);
   197         -  int (*vfs_unregister)(sqlite3_vfs*);
   198         -  int (*xthreadsafe)(void);
   199         -  void (*result_zeroblob)(sqlite3_context*,int);
   200         -  void (*result_error_code)(sqlite3_context*,int);
   201         -  int (*test_control)(int, ...);
   202         -  void (*randomness)(int,void*);
   203         -  sqlite3 *(*context_db_handle)(sqlite3_context*);
   204         -  int (*extended_result_codes)(sqlite3*,int);
   205         -  int (*limit)(sqlite3*,int,int);
   206         -  sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*);
   207         -  const char *(*sql)(sqlite3_stmt*);
   208         -  int (*status)(int,int*,int*,int);
   209         -  int (*backup_finish)(sqlite3_backup*);
   210         -  sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*);
   211         -  int (*backup_pagecount)(sqlite3_backup*);
   212         -  int (*backup_remaining)(sqlite3_backup*);
   213         -  int (*backup_step)(sqlite3_backup*,int);
   214         -  const char *(*compileoption_get)(int);
   215         -  int (*compileoption_used)(const char*);
   216         -  int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
   217         -                            void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
   218         -                            void (*xStep)(sqlite3_context*,int,sqlite3_value**),
   219         -                            void (*xFinal)(sqlite3_context*),
   220         -                            void(*xDestroy)(void*));
   221         -  int (*db_config)(sqlite3*,int,...);
   222         -  sqlite3_mutex *(*db_mutex)(sqlite3*);
   223         -  int (*db_status)(sqlite3*,int,int*,int*,int);
   224         -  int (*extended_errcode)(sqlite3*);
   225         -  void (*log)(int,const char*,...);
   226         -  sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64);
   227         -  const char *(*sourceid)(void);
   228         -  int (*stmt_status)(sqlite3_stmt*,int,int);
   229         -  int (*strnicmp)(const char*,const char*,int);
   230         -  int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*);
   231         -  int (*wal_autocheckpoint)(sqlite3*,int);
   232         -  int (*wal_checkpoint)(sqlite3*,const char*);
   233         -  void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*);
   234         -  int (*blob_reopen)(sqlite3_blob*,sqlite3_int64);
   235         -  int (*vtab_config)(sqlite3*,int op,...);
   236         -  int (*vtab_on_conflict)(sqlite3*);
   237         -  /* Version 3.7.16 and later */
   238         -  int (*close_v2)(sqlite3*);
   239         -  const char *(*db_filename)(sqlite3*,const char*);
   240         -  int (*db_readonly)(sqlite3*,const char*);
   241         -  int (*db_release_memory)(sqlite3*);
   242         -  const char *(*errstr)(int);
   243         -  int (*stmt_busy)(sqlite3_stmt*);
   244         -  int (*stmt_readonly)(sqlite3_stmt*);
   245         -  int (*stricmp)(const char*,const char*);
   246         -  int (*uri_boolean)(const char*,const char*,int);
   247         -  sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
   248         -  const char *(*uri_parameter)(const char*,const char*);
   249         -  char *(*xvsnprintf)(int,char*,const char*,va_list);
   250         -  int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
   251         -  /* Version 3.8.7 and later */
   252         -  int (*auto_extension)(void(*)(void));
   253         -  int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
   254         -                     void(*)(void*));
   255         -  int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64,
   256         -                      void(*)(void*),unsigned char);
   257         -  int (*cancel_auto_extension)(void(*)(void));
   258         -  int (*load_extension)(sqlite3*,const char*,const char*,char**);
   259         -  void *(*malloc64)(sqlite3_uint64);
   260         -  sqlite3_uint64 (*msize)(void*);
   261         -  void *(*realloc64)(void*,sqlite3_uint64);
   262         -  void (*reset_auto_extension)(void);
   263         -  void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64,
   264         -                        void(*)(void*));
   265         -  void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64,
   266         -                         void(*)(void*), unsigned char);
   267         -  int (*strglob)(const char*,const char*);
   268         -  /* Version 3.8.11 and later */
   269         -  sqlite3_value *(*value_dup)(const sqlite3_value*);
   270         -  void (*value_free)(sqlite3_value*);
   271         -  int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
   272         -  int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
   273         -  /* Version 3.9.0 and later */
   274         -  unsigned int (*value_subtype)(sqlite3_value*);
   275         -  void (*result_subtype)(sqlite3_context*,unsigned int);
   276         -  /* Version 3.10.0 and later */
   277         -  int (*status64)(int,sqlite3_int64*,sqlite3_int64*,int);
   278         -  int (*strlike)(const char*,const char*,unsigned int);
   279         -  int (*db_cacheflush)(sqlite3*);
   280         -  /* Version 3.12.0 and later */
   281         -  int (*system_errno)(sqlite3*);
   282         -  /* Version 3.14.0 and later */
   283         -  int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*);
   284         -  char *(*expanded_sql)(sqlite3_stmt*);
   285         -  /* Version 3.18.0 and later */
   286         -  void (*set_last_insert_rowid)(sqlite3*,sqlite3_int64);
   287         -  /* Version 3.20.0 and later */
   288         -  int (*prepare_v3)(sqlite3*,const char*,int,unsigned int,
   289         -                    sqlite3_stmt**,const char**);
   290         -  int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
   291         -                      sqlite3_stmt**,const void**);
   292         -  int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
   293         -  void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
   294         -  void *(*value_pointer)(sqlite3_value*,const char*);
   295         -  int (*vtab_nochange)(sqlite3_context*);
   296         -  int (*value_nochange)(sqlite3_value*);
   297         -  const char *(*vtab_collation)(sqlite3_index_info*,int);
   298         -  /* Version 3.24.0 and later */
   299         -  int (*keyword_count)(void);
   300         -  int (*keyword_name)(int,const char**,int*);
   301         -  int (*keyword_check)(const char*,int);
   302         -  sqlite3_str *(*str_new)(sqlite3*);
   303         -  char *(*str_finish)(sqlite3_str*);
   304         -  void (*str_appendf)(sqlite3_str*, const char *zFormat, ...);
   305         -  void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list);
   306         -  void (*str_append)(sqlite3_str*, const char *zIn, int N);
   307         -  void (*str_appendall)(sqlite3_str*, const char *zIn);
   308         -  void (*str_appendchar)(sqlite3_str*, int N, char C);
   309         -  void (*str_reset)(sqlite3_str*);
   310         -  int (*str_errcode)(sqlite3_str*);
   311         -  int (*str_length)(sqlite3_str*);
   312         -  char *(*str_value)(sqlite3_str*);
   313         -  /* Version 3.25.0 and later */
   314         -  int (*create_window_function)(sqlite3*,const char*,int,int,void*,
   315         -                            void (*xStep)(sqlite3_context*,int,sqlite3_value**),
   316         -                            void (*xFinal)(sqlite3_context*),
   317         -                            void (*xValue)(sqlite3_context*),
   318         -                            void (*xInv)(sqlite3_context*,int,sqlite3_value**),
   319         -                            void(*xDestroy)(void*));
   320         -  /* Version 3.26.0 and later */
   321         -  const char *(*normalized_sql)(sqlite3_stmt*);
   322         -  /* Version 3.28.0 and later */
   323         -  int (*stmt_isexplain)(sqlite3_stmt*);
   324         -  int (*value_frombind)(sqlite3_value*);
   325         -};
   326         -
   327         -/*
   328         -** This is the function signature used for all extension entry points.  It
   329         -** is also defined in the file "loadext.c".
   330         -*/
   331         -typedef int (*sqlite3_loadext_entry)(
   332         -  sqlite3 *db,                       /* Handle to the database. */
   333         -  char **pzErrMsg,                   /* Used to set error string on failure. */
   334         -  const sqlite3_api_routines *pThunk /* Extension API function pointers. */
   335         -);
   336         -
   337         -/*
   338         -** The following macros redefine the API routines so that they are
   339         -** redirected through the global sqlite3_api structure.
   340         -**
   341         -** This header file is also used by the loadext.c source file
   342         -** (part of the main SQLite library - not an extension) so that
   343         -** it can get access to the sqlite3_api_routines structure
   344         -** definition.  But the main library does not want to redefine
   345         -** the API.  So the redefinition macros are only valid if the
   346         -** SQLITE_CORE macros is undefined.
   347         -*/
   348         -#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
   349         -#define sqlite3_aggregate_context      sqlite3_api->aggregate_context
   350         -#ifndef SQLITE_OMIT_DEPRECATED
   351         -#define sqlite3_aggregate_count        sqlite3_api->aggregate_count
   352         -#endif
   353         -#define sqlite3_bind_blob              sqlite3_api->bind_blob
   354         -#define sqlite3_bind_double            sqlite3_api->bind_double
   355         -#define sqlite3_bind_int               sqlite3_api->bind_int
   356         -#define sqlite3_bind_int64             sqlite3_api->bind_int64
   357         -#define sqlite3_bind_null              sqlite3_api->bind_null
   358         -#define sqlite3_bind_parameter_count   sqlite3_api->bind_parameter_count
   359         -#define sqlite3_bind_parameter_index   sqlite3_api->bind_parameter_index
   360         -#define sqlite3_bind_parameter_name    sqlite3_api->bind_parameter_name
   361         -#define sqlite3_bind_text              sqlite3_api->bind_text
   362         -#define sqlite3_bind_text16            sqlite3_api->bind_text16
   363         -#define sqlite3_bind_value             sqlite3_api->bind_value
   364         -#define sqlite3_busy_handler           sqlite3_api->busy_handler
   365         -#define sqlite3_busy_timeout           sqlite3_api->busy_timeout
   366         -#define sqlite3_changes                sqlite3_api->changes
   367         -#define sqlite3_close                  sqlite3_api->close
   368         -#define sqlite3_collation_needed       sqlite3_api->collation_needed
   369         -#define sqlite3_collation_needed16     sqlite3_api->collation_needed16
   370         -#define sqlite3_column_blob            sqlite3_api->column_blob
   371         -#define sqlite3_column_bytes           sqlite3_api->column_bytes
   372         -#define sqlite3_column_bytes16         sqlite3_api->column_bytes16
   373         -#define sqlite3_column_count           sqlite3_api->column_count
   374         -#define sqlite3_column_database_name   sqlite3_api->column_database_name
   375         -#define sqlite3_column_database_name16 sqlite3_api->column_database_name16
   376         -#define sqlite3_column_decltype        sqlite3_api->column_decltype
   377         -#define sqlite3_column_decltype16      sqlite3_api->column_decltype16
   378         -#define sqlite3_column_double          sqlite3_api->column_double
   379         -#define sqlite3_column_int             sqlite3_api->column_int
   380         -#define sqlite3_column_int64           sqlite3_api->column_int64
   381         -#define sqlite3_column_name            sqlite3_api->column_name
   382         -#define sqlite3_column_name16          sqlite3_api->column_name16
   383         -#define sqlite3_column_origin_name     sqlite3_api->column_origin_name
   384         -#define sqlite3_column_origin_name16   sqlite3_api->column_origin_name16
   385         -#define sqlite3_column_table_name      sqlite3_api->column_table_name
   386         -#define sqlite3_column_table_name16    sqlite3_api->column_table_name16
   387         -#define sqlite3_column_text            sqlite3_api->column_text
   388         -#define sqlite3_column_text16          sqlite3_api->column_text16
   389         -#define sqlite3_column_type            sqlite3_api->column_type
   390         -#define sqlite3_column_value           sqlite3_api->column_value
   391         -#define sqlite3_commit_hook            sqlite3_api->commit_hook
   392         -#define sqlite3_complete               sqlite3_api->complete
   393         -#define sqlite3_complete16             sqlite3_api->complete16
   394         -#define sqlite3_create_collation       sqlite3_api->create_collation
   395         -#define sqlite3_create_collation16     sqlite3_api->create_collation16
   396         -#define sqlite3_create_function        sqlite3_api->create_function
   397         -#define sqlite3_create_function16      sqlite3_api->create_function16
   398         -#define sqlite3_create_module          sqlite3_api->create_module
   399         -#define sqlite3_create_module_v2       sqlite3_api->create_module_v2
   400         -#define sqlite3_data_count             sqlite3_api->data_count
   401         -#define sqlite3_db_handle              sqlite3_api->db_handle
   402         -#define sqlite3_declare_vtab           sqlite3_api->declare_vtab
   403         -#define sqlite3_enable_shared_cache    sqlite3_api->enable_shared_cache
   404         -#define sqlite3_errcode                sqlite3_api->errcode
   405         -#define sqlite3_errmsg                 sqlite3_api->errmsg
   406         -#define sqlite3_errmsg16               sqlite3_api->errmsg16
   407         -#define sqlite3_exec                   sqlite3_api->exec
   408         -#ifndef SQLITE_OMIT_DEPRECATED
   409         -#define sqlite3_expired                sqlite3_api->expired
   410         -#endif
   411         -#define sqlite3_finalize               sqlite3_api->finalize
   412         -#define sqlite3_free                   sqlite3_api->free
   413         -#define sqlite3_free_table             sqlite3_api->free_table
   414         -#define sqlite3_get_autocommit         sqlite3_api->get_autocommit
   415         -#define sqlite3_get_auxdata            sqlite3_api->get_auxdata
   416         -#define sqlite3_get_table              sqlite3_api->get_table
   417         -#ifndef SQLITE_OMIT_DEPRECATED
   418         -#define sqlite3_global_recover         sqlite3_api->global_recover
   419         -#endif
   420         -#define sqlite3_interrupt              sqlite3_api->interruptx
   421         -#define sqlite3_last_insert_rowid      sqlite3_api->last_insert_rowid
   422         -#define sqlite3_libversion             sqlite3_api->libversion
   423         -#define sqlite3_libversion_number      sqlite3_api->libversion_number
   424         -#define sqlite3_malloc                 sqlite3_api->malloc
   425         -#define sqlite3_mprintf                sqlite3_api->mprintf
   426         -#define sqlite3_open                   sqlite3_api->open
   427         -#define sqlite3_open16                 sqlite3_api->open16
   428         -#define sqlite3_prepare                sqlite3_api->prepare
   429         -#define sqlite3_prepare16              sqlite3_api->prepare16
   430         -#define sqlite3_prepare_v2             sqlite3_api->prepare_v2
   431         -#define sqlite3_prepare16_v2           sqlite3_api->prepare16_v2
   432         -#define sqlite3_profile                sqlite3_api->profile
   433         -#define sqlite3_progress_handler       sqlite3_api->progress_handler
   434         -#define sqlite3_realloc                sqlite3_api->realloc
   435         -#define sqlite3_reset                  sqlite3_api->reset
   436         -#define sqlite3_result_blob            sqlite3_api->result_blob
   437         -#define sqlite3_result_double          sqlite3_api->result_double
   438         -#define sqlite3_result_error           sqlite3_api->result_error
   439         -#define sqlite3_result_error16         sqlite3_api->result_error16
   440         -#define sqlite3_result_int             sqlite3_api->result_int
   441         -#define sqlite3_result_int64           sqlite3_api->result_int64
   442         -#define sqlite3_result_null            sqlite3_api->result_null
   443         -#define sqlite3_result_text            sqlite3_api->result_text
   444         -#define sqlite3_result_text16          sqlite3_api->result_text16
   445         -#define sqlite3_result_text16be        sqlite3_api->result_text16be
   446         -#define sqlite3_result_text16le        sqlite3_api->result_text16le
   447         -#define sqlite3_result_value           sqlite3_api->result_value
   448         -#define sqlite3_rollback_hook          sqlite3_api->rollback_hook
   449         -#define sqlite3_set_authorizer         sqlite3_api->set_authorizer
   450         -#define sqlite3_set_auxdata            sqlite3_api->set_auxdata
   451         -#define sqlite3_snprintf               sqlite3_api->xsnprintf
   452         -#define sqlite3_step                   sqlite3_api->step
   453         -#define sqlite3_table_column_metadata  sqlite3_api->table_column_metadata
   454         -#define sqlite3_thread_cleanup         sqlite3_api->thread_cleanup
   455         -#define sqlite3_total_changes          sqlite3_api->total_changes
   456         -#define sqlite3_trace                  sqlite3_api->trace
   457         -#ifndef SQLITE_OMIT_DEPRECATED
   458         -#define sqlite3_transfer_bindings      sqlite3_api->transfer_bindings
   459         -#endif
   460         -#define sqlite3_update_hook            sqlite3_api->update_hook
   461         -#define sqlite3_user_data              sqlite3_api->user_data
   462         -#define sqlite3_value_blob             sqlite3_api->value_blob
   463         -#define sqlite3_value_bytes            sqlite3_api->value_bytes
   464         -#define sqlite3_value_bytes16          sqlite3_api->value_bytes16
   465         -#define sqlite3_value_double           sqlite3_api->value_double
   466         -#define sqlite3_value_int              sqlite3_api->value_int
   467         -#define sqlite3_value_int64            sqlite3_api->value_int64
   468         -#define sqlite3_value_numeric_type     sqlite3_api->value_numeric_type
   469         -#define sqlite3_value_text             sqlite3_api->value_text
   470         -#define sqlite3_value_text16           sqlite3_api->value_text16
   471         -#define sqlite3_value_text16be         sqlite3_api->value_text16be
   472         -#define sqlite3_value_text16le         sqlite3_api->value_text16le
   473         -#define sqlite3_value_type             sqlite3_api->value_type
   474         -#define sqlite3_vmprintf               sqlite3_api->vmprintf
   475         -#define sqlite3_vsnprintf              sqlite3_api->xvsnprintf
   476         -#define sqlite3_overload_function      sqlite3_api->overload_function
   477         -#define sqlite3_prepare_v2             sqlite3_api->prepare_v2
   478         -#define sqlite3_prepare16_v2           sqlite3_api->prepare16_v2
   479         -#define sqlite3_clear_bindings         sqlite3_api->clear_bindings
   480         -#define sqlite3_bind_zeroblob          sqlite3_api->bind_zeroblob
   481         -#define sqlite3_blob_bytes             sqlite3_api->blob_bytes
   482         -#define sqlite3_blob_close             sqlite3_api->blob_close
   483         -#define sqlite3_blob_open              sqlite3_api->blob_open
   484         -#define sqlite3_blob_read              sqlite3_api->blob_read
   485         -#define sqlite3_blob_write             sqlite3_api->blob_write
   486         -#define sqlite3_create_collation_v2    sqlite3_api->create_collation_v2
   487         -#define sqlite3_file_control           sqlite3_api->file_control
   488         -#define sqlite3_memory_highwater       sqlite3_api->memory_highwater
   489         -#define sqlite3_memory_used            sqlite3_api->memory_used
   490         -#define sqlite3_mutex_alloc            sqlite3_api->mutex_alloc
   491         -#define sqlite3_mutex_enter            sqlite3_api->mutex_enter
   492         -#define sqlite3_mutex_free             sqlite3_api->mutex_free
   493         -#define sqlite3_mutex_leave            sqlite3_api->mutex_leave
   494         -#define sqlite3_mutex_try              sqlite3_api->mutex_try
   495         -#define sqlite3_open_v2                sqlite3_api->open_v2
   496         -#define sqlite3_release_memory         sqlite3_api->release_memory
   497         -#define sqlite3_result_error_nomem     sqlite3_api->result_error_nomem
   498         -#define sqlite3_result_error_toobig    sqlite3_api->result_error_toobig
   499         -#define sqlite3_sleep                  sqlite3_api->sleep
   500         -#define sqlite3_soft_heap_limit        sqlite3_api->soft_heap_limit
   501         -#define sqlite3_vfs_find               sqlite3_api->vfs_find
   502         -#define sqlite3_vfs_register           sqlite3_api->vfs_register
   503         -#define sqlite3_vfs_unregister         sqlite3_api->vfs_unregister
   504         -#define sqlite3_threadsafe             sqlite3_api->xthreadsafe
   505         -#define sqlite3_result_zeroblob        sqlite3_api->result_zeroblob
   506         -#define sqlite3_result_error_code      sqlite3_api->result_error_code
   507         -#define sqlite3_test_control           sqlite3_api->test_control
   508         -#define sqlite3_randomness             sqlite3_api->randomness
   509         -#define sqlite3_context_db_handle      sqlite3_api->context_db_handle
   510         -#define sqlite3_extended_result_codes  sqlite3_api->extended_result_codes
   511         -#define sqlite3_limit                  sqlite3_api->limit
   512         -#define sqlite3_next_stmt              sqlite3_api->next_stmt
   513         -#define sqlite3_sql                    sqlite3_api->sql
   514         -#define sqlite3_status                 sqlite3_api->status
   515         -#define sqlite3_backup_finish          sqlite3_api->backup_finish
   516         -#define sqlite3_backup_init            sqlite3_api->backup_init
   517         -#define sqlite3_backup_pagecount       sqlite3_api->backup_pagecount
   518         -#define sqlite3_backup_remaining       sqlite3_api->backup_remaining
   519         -#define sqlite3_backup_step            sqlite3_api->backup_step
   520         -#define sqlite3_compileoption_get      sqlite3_api->compileoption_get
   521         -#define sqlite3_compileoption_used     sqlite3_api->compileoption_used
   522         -#define sqlite3_create_function_v2     sqlite3_api->create_function_v2
   523         -#define sqlite3_db_config              sqlite3_api->db_config
   524         -#define sqlite3_db_mutex               sqlite3_api->db_mutex
   525         -#define sqlite3_db_status              sqlite3_api->db_status
   526         -#define sqlite3_extended_errcode       sqlite3_api->extended_errcode
   527         -#define sqlite3_log                    sqlite3_api->log
   528         -#define sqlite3_soft_heap_limit64      sqlite3_api->soft_heap_limit64
   529         -#define sqlite3_sourceid               sqlite3_api->sourceid
   530         -#define sqlite3_stmt_status            sqlite3_api->stmt_status
   531         -#define sqlite3_strnicmp               sqlite3_api->strnicmp
   532         -#define sqlite3_unlock_notify          sqlite3_api->unlock_notify
   533         -#define sqlite3_wal_autocheckpoint     sqlite3_api->wal_autocheckpoint
   534         -#define sqlite3_wal_checkpoint         sqlite3_api->wal_checkpoint
   535         -#define sqlite3_wal_hook               sqlite3_api->wal_hook
   536         -#define sqlite3_blob_reopen            sqlite3_api->blob_reopen
   537         -#define sqlite3_vtab_config            sqlite3_api->vtab_config
   538         -#define sqlite3_vtab_on_conflict       sqlite3_api->vtab_on_conflict
   539         -/* Version 3.7.16 and later */
   540         -#define sqlite3_close_v2               sqlite3_api->close_v2
   541         -#define sqlite3_db_filename            sqlite3_api->db_filename
   542         -#define sqlite3_db_readonly            sqlite3_api->db_readonly
   543         -#define sqlite3_db_release_memory      sqlite3_api->db_release_memory
   544         -#define sqlite3_errstr                 sqlite3_api->errstr
   545         -#define sqlite3_stmt_busy              sqlite3_api->stmt_busy
   546         -#define sqlite3_stmt_readonly          sqlite3_api->stmt_readonly
   547         -#define sqlite3_stricmp                sqlite3_api->stricmp
   548         -#define sqlite3_uri_boolean            sqlite3_api->uri_boolean
   549         -#define sqlite3_uri_int64              sqlite3_api->uri_int64
   550         -#define sqlite3_uri_parameter          sqlite3_api->uri_parameter
   551         -#define sqlite3_uri_vsnprintf          sqlite3_api->xvsnprintf
   552         -#define sqlite3_wal_checkpoint_v2      sqlite3_api->wal_checkpoint_v2
   553         -/* Version 3.8.7 and later */
   554         -#define sqlite3_auto_extension         sqlite3_api->auto_extension
   555         -#define sqlite3_bind_blob64            sqlite3_api->bind_blob64
   556         -#define sqlite3_bind_text64            sqlite3_api->bind_text64
   557         -#define sqlite3_cancel_auto_extension  sqlite3_api->cancel_auto_extension
   558         -#define sqlite3_load_extension         sqlite3_api->load_extension
   559         -#define sqlite3_malloc64               sqlite3_api->malloc64
   560         -#define sqlite3_msize                  sqlite3_api->msize
   561         -#define sqlite3_realloc64              sqlite3_api->realloc64
   562         -#define sqlite3_reset_auto_extension   sqlite3_api->reset_auto_extension
   563         -#define sqlite3_result_blob64          sqlite3_api->result_blob64
   564         -#define sqlite3_result_text64          sqlite3_api->result_text64
   565         -#define sqlite3_strglob                sqlite3_api->strglob
   566         -/* Version 3.8.11 and later */
   567         -#define sqlite3_value_dup              sqlite3_api->value_dup
   568         -#define sqlite3_value_free             sqlite3_api->value_free
   569         -#define sqlite3_result_zeroblob64      sqlite3_api->result_zeroblob64
   570         -#define sqlite3_bind_zeroblob64        sqlite3_api->bind_zeroblob64
   571         -/* Version 3.9.0 and later */
   572         -#define sqlite3_value_subtype          sqlite3_api->value_subtype
   573         -#define sqlite3_result_subtype         sqlite3_api->result_subtype
   574         -/* Version 3.10.0 and later */
   575         -#define sqlite3_status64               sqlite3_api->status64
   576         -#define sqlite3_strlike                sqlite3_api->strlike
   577         -#define sqlite3_db_cacheflush          sqlite3_api->db_cacheflush
   578         -/* Version 3.12.0 and later */
   579         -#define sqlite3_system_errno           sqlite3_api->system_errno
   580         -/* Version 3.14.0 and later */
   581         -#define sqlite3_trace_v2               sqlite3_api->trace_v2
   582         -#define sqlite3_expanded_sql           sqlite3_api->expanded_sql
   583         -/* Version 3.18.0 and later */
   584         -#define sqlite3_set_last_insert_rowid  sqlite3_api->set_last_insert_rowid
   585         -/* Version 3.20.0 and later */
   586         -#define sqlite3_prepare_v3             sqlite3_api->prepare_v3
   587         -#define sqlite3_prepare16_v3           sqlite3_api->prepare16_v3
   588         -#define sqlite3_bind_pointer           sqlite3_api->bind_pointer
   589         -#define sqlite3_result_pointer         sqlite3_api->result_pointer
   590         -#define sqlite3_value_pointer          sqlite3_api->value_pointer
   591         -/* Version 3.22.0 and later */
   592         -#define sqlite3_vtab_nochange          sqlite3_api->vtab_nochange
   593         -#define sqlite3_value_nochange         sqlite3_api->value_nochange
   594         -#define sqlite3_vtab_collation         sqlite3_api->vtab_collation
   595         -/* Version 3.24.0 and later */
   596         -#define sqlite3_keyword_count          sqlite3_api->keyword_count
   597         -#define sqlite3_keyword_name           sqlite3_api->keyword_name
   598         -#define sqlite3_keyword_check          sqlite3_api->keyword_check
   599         -#define sqlite3_str_new                sqlite3_api->str_new
   600         -#define sqlite3_str_finish             sqlite3_api->str_finish
   601         -#define sqlite3_str_appendf            sqlite3_api->str_appendf
   602         -#define sqlite3_str_vappendf           sqlite3_api->str_vappendf
   603         -#define sqlite3_str_append             sqlite3_api->str_append
   604         -#define sqlite3_str_appendall          sqlite3_api->str_appendall
   605         -#define sqlite3_str_appendchar         sqlite3_api->str_appendchar
   606         -#define sqlite3_str_reset              sqlite3_api->str_reset
   607         -#define sqlite3_str_errcode            sqlite3_api->str_errcode
   608         -#define sqlite3_str_length             sqlite3_api->str_length
   609         -#define sqlite3_str_value              sqlite3_api->str_value
   610         -/* Version 3.25.0 and later */
   611         -#define sqlite3_create_window_function sqlite3_api->create_window_function
   612         -/* Version 3.26.0 and later */
   613         -#define sqlite3_normalized_sql         sqlite3_api->normalized_sql
   614         -/* Version 3.28.0 and later */
   615         -#define sqlite3_stmt_isexplain         sqlite3_api->isexplain
   616         -#define sqlite3_value_frombind         sqlite3_api->frombind
   617         -#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
   618         -
   619         -#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
   620         -  /* This case when the file really is being compiled as a loadable 
   621         -  ** extension */
   622         -# define SQLITE_EXTENSION_INIT1     const sqlite3_api_routines *sqlite3_api=0;
   623         -# define SQLITE_EXTENSION_INIT2(v)  sqlite3_api=v;
   624         -# define SQLITE_EXTENSION_INIT3     \
   625         -    extern const sqlite3_api_routines *sqlite3_api;
   626         -#else
   627         -  /* This case when the file is being statically linked into the 
   628         -  ** application */
   629         -# define SQLITE_EXTENSION_INIT1     /*no-op*/
   630         -# define SQLITE_EXTENSION_INIT2(v)  (void)v; /* unused parameter */
   631         -# define SQLITE_EXTENSION_INIT3     /*no-op*/
   632         -#endif
   633         -
   634         -#endif /* SQLITE3EXT_H */

Deleted jni/tcl/pkgs/sqlite3.28.0/configure.

more than 10,000 changes

Deleted jni/tcl/pkgs/sqlite3.28.0/configure.ac.

     1         -#!/bin/bash -norc
     2         -dnl	This file is an input file used by the GNU "autoconf" program to
     3         -dnl	generate the file "configure", which is run during Tcl installation
     4         -dnl	to configure the system for the local environment.
     5         -#
     6         -# RCS: @(#) $Id: configure.in,v 1.43 2005/07/26 19:17:05 mdejong Exp $
     7         -
     8         -#-----------------------------------------------------------------------
     9         -# Sample configure.ac for Tcl Extensions.  The only places you should
    10         -# need to modify this file are marked by the string __CHANGE__
    11         -#-----------------------------------------------------------------------
    12         -
    13         -#-----------------------------------------------------------------------
    14         -# __CHANGE__
    15         -# Set your package name and version numbers here.
    16         -#
    17         -# This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION
    18         -# set as provided.  These will also be added as -D defs in your Makefile
    19         -# so you can encode the package version directly into the source files.
    20         -#-----------------------------------------------------------------------
    21         -
    22         -AC_INIT([sqlite], [3.28.0])
    23         -
    24         -#--------------------------------------------------------------------
    25         -# Call TEA_INIT as the first TEA_ macro to set up initial vars.
    26         -# This will define a ${TEA_PLATFORM} variable == "unix" or "windows"
    27         -# as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE.
    28         -#--------------------------------------------------------------------
    29         -
    30         -TEA_INIT([3.10])
    31         -
    32         -AC_CONFIG_AUX_DIR(tclconfig)
    33         -
    34         -#--------------------------------------------------------------------
    35         -# Load the tclConfig.sh file
    36         -#--------------------------------------------------------------------
    37         -
    38         -TEA_PATH_TCLCONFIG
    39         -TEA_LOAD_TCLCONFIG
    40         -
    41         -#--------------------------------------------------------------------
    42         -# Load the tkConfig.sh file if necessary (Tk extension)
    43         -#--------------------------------------------------------------------
    44         -
    45         -#TEA_PATH_TKCONFIG
    46         -#TEA_LOAD_TKCONFIG
    47         -
    48         -#-----------------------------------------------------------------------
    49         -# Handle the --prefix=... option by defaulting to what Tcl gave.
    50         -# Must be called after TEA_LOAD_TCLCONFIG and before TEA_SETUP_COMPILER.
    51         -#-----------------------------------------------------------------------
    52         -
    53         -TEA_PREFIX
    54         -
    55         -#-----------------------------------------------------------------------
    56         -# Standard compiler checks.
    57         -# This sets up CC by using the CC env var, or looks for gcc otherwise.
    58         -# This also calls AC_PROG_CC, AC_PROG_INSTALL and a few others to create
    59         -# the basic setup necessary to compile executables.
    60         -#-----------------------------------------------------------------------
    61         -
    62         -TEA_SETUP_COMPILER
    63         -
    64         -#-----------------------------------------------------------------------
    65         -# __CHANGE__
    66         -# Specify the C source files to compile in TEA_ADD_SOURCES,
    67         -# public headers that need to be installed in TEA_ADD_HEADERS,
    68         -# stub library C source files to compile in TEA_ADD_STUB_SOURCES,
    69         -# and runtime Tcl library files in TEA_ADD_TCL_SOURCES.
    70         -# This defines PKG(_STUB)_SOURCES, PKG(_STUB)_OBJECTS, PKG_HEADERS
    71         -# and PKG_TCL_SOURCES.
    72         -#-----------------------------------------------------------------------
    73         -
    74         -TEA_ADD_SOURCES([tclsqlite3.c])
    75         -TEA_ADD_HEADERS([])
    76         -TEA_ADD_INCLUDES([-I\"`\${CYGPATH} \${srcdir}/generic`\"])
    77         -TEA_ADD_LIBS([])
    78         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_DBPAGE_VTAB=1])
    79         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_DBSTAT_VTAB=1])
    80         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_FTS3_PARENTHESIS=1])
    81         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_FTS4=1])
    82         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_FTS5=1])
    83         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_COLUMN_METADATA=1])
    84         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_JSON1=1])
    85         -TEA_ADD_CFLAGS([-DSQLITE_3_SUFFIX_ONLY=1])
    86         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_RTREE=1])
    87         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_GEOPOLY=1])
    88         -TEA_ADD_CFLAGS([-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1])
    89         -TEA_ADD_CFLAGS([-DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1])
    90         -TEA_ADD_CFLAGS([-DSQLITE_UNTESTABLE=1])
    91         -TEA_ADD_CFLAGS([-DSQLITE_OMIT_DEPRECATED=1])
    92         -TEA_ADD_CFLAGS([-DSQLITE_OMIT_LOOKASIDE=1])
    93         -TEA_ADD_CFLAGS([-DSQLITE_SECURE_DELETE=1])
    94         -TEA_ADD_CFLAGS([-DSQLITE_SOUNDEX=1])
    95         -TEA_ADD_CFLAGS([-DSQLITE_USE_ALLOCA=1])
    96         -TEA_ADD_CFLAGS([-DSQLITE_WIN32_NO_ANSI=1])
    97         -TEA_ADD_CFLAGS([-DSQLITE_WIN32_GETVERSIONEX=0])
    98         -TEA_ADD_STUB_SOURCES([])
    99         -TEA_ADD_TCL_SOURCES([])
   100         -
   101         -#--------------------------------------------------------------------
   102         -# The --with-system-sqlite causes the TCL bindings to SQLite to use
   103         -# the system shared library for SQLite rather than statically linking
   104         -# against its own private copy.  This is dangerous and leads to
   105         -# undersirable dependences and is not recommended.
   106         -# Patchs from rmax.
   107         -#--------------------------------------------------------------------
   108         -AC_ARG_WITH([system-sqlite],
   109         - [AC_HELP_STRING([--with-system-sqlite],
   110         -   [use a system-supplied libsqlite3 instead of the bundled one])],
   111         - [], [with_system_sqlite=no])
   112         -if test x$with_system_sqlite != xno; then
   113         - AC_CHECK_HEADER([sqlite3.h],
   114         -   [AC_CHECK_LIB([sqlite3],[sqlite3_initialize],
   115         -     [AC_DEFINE(USE_SYSTEM_SQLITE)
   116         -      LIBS="$LIBS -lsqlite3"])])
   117         -fi
   118         -
   119         -#--------------------------------------------------------------------
   120         -# __CHANGE__
   121         -# Choose which headers you need.  Extension authors should try very
   122         -# hard to only rely on the Tcl public header files.  Internal headers
   123         -# contain private data structures and are subject to change without
   124         -# notice.
   125         -# This MUST be called after TEA_LOAD_TCLCONFIG / TEA_LOAD_TKCONFIG
   126         -#--------------------------------------------------------------------
   127         -
   128         -TEA_PUBLIC_TCL_HEADERS
   129         -#TEA_PRIVATE_TCL_HEADERS
   130         -
   131         -#TEA_PUBLIC_TK_HEADERS
   132         -#TEA_PRIVATE_TK_HEADERS
   133         -#TEA_PATH_X
   134         -
   135         -#--------------------------------------------------------------------
   136         -# Check whether --enable-threads or --disable-threads was given.
   137         -# This auto-enables if Tcl was compiled threaded.
   138         -#--------------------------------------------------------------------
   139         -
   140         -TEA_ENABLE_THREADS
   141         -if test "${TCL_THREADS}" = "1" ; then
   142         -    AC_DEFINE(SQLITE_THREADSAFE, 1, [Trigger sqlite threadsafe build])
   143         -    # Not automatically added by Tcl because its assumed Tcl links to them,
   144         -    # but it may not if it isn't really a threaded build.
   145         -    TEA_ADD_LIBS([$THREADS_LIBS])
   146         -else
   147         -    AC_DEFINE(SQLITE_THREADSAFE, 0, [Trigger sqlite non-threadsafe build])
   148         -fi
   149         -
   150         -#--------------------------------------------------------------------
   151         -# The statement below defines a collection of symbols related to
   152         -# building as a shared library instead of a static library.
   153         -#--------------------------------------------------------------------
   154         -
   155         -TEA_ENABLE_SHARED
   156         -
   157         -#--------------------------------------------------------------------
   158         -# This macro figures out what flags to use with the compiler/linker
   159         -# when building shared/static debug/optimized objects.  This information
   160         -# can be taken from the tclConfig.sh file, but this figures it all out.
   161         -#--------------------------------------------------------------------
   162         -
   163         -TEA_CONFIG_CFLAGS
   164         -
   165         -#--------------------------------------------------------------------
   166         -# Set the default compiler switches based on the --enable-symbols option.
   167         -#--------------------------------------------------------------------
   168         -
   169         -TEA_ENABLE_SYMBOLS
   170         -
   171         -#--------------------------------------------------------------------
   172         -# Everyone should be linking against the Tcl stub library.  If you
   173         -# can't for some reason, remove this definition.  If you aren't using
   174         -# stubs, you also need to modify the SHLIB_LD_LIBS setting below to
   175         -# link against the non-stubbed Tcl library.  Add Tk too if necessary.
   176         -#--------------------------------------------------------------------
   177         -
   178         -AC_DEFINE(USE_TCL_STUBS, 1, [Use Tcl stubs])
   179         -#AC_DEFINE(USE_TK_STUBS, 1, [Use Tk stubs])
   180         -
   181         -
   182         -#--------------------------------------------------------------------
   183         -# Redefine fdatasync as fsync on systems that lack fdatasync
   184         -#--------------------------------------------------------------------
   185         -#
   186         -#AC_CHECK_FUNC(fdatasync, , AC_DEFINE(fdatasync, fsync))
   187         -AC_CHECK_HEADERS([malloc.h])
   188         -# Check for library functions that SQLite can optionally use.
   189         -AC_CHECK_FUNCS([fdatasync usleep strchrnul localtime_r gmtime_r localtime_s malloc_usable_size utime flock readlink lstat pread pread64 pwrite pwrite64 rand_s])
   190         -
   191         -AC_FUNC_STRERROR_R
   192         -
   193         -
   194         -#--------------------------------------------------------------------
   195         -# This macro generates a line to use when building a library.  It
   196         -# depends on values set by the TEA_ENABLE_SHARED, TEA_ENABLE_SYMBOLS,
   197         -# and TEA_LOAD_TCLCONFIG macros above.
   198         -#--------------------------------------------------------------------
   199         -
   200         -TEA_MAKE_LIB
   201         -
   202         -#--------------------------------------------------------------------
   203         -# Determine the name of the tclsh and/or wish executables in the
   204         -# Tcl and Tk build directories or the location they were installed
   205         -# into. These paths are used to support running test cases only,
   206         -# the Makefile should not be making use of these paths to generate
   207         -# a pkgIndex.tcl file or anything else at extension build time.
   208         -#--------------------------------------------------------------------
   209         -
   210         -TEA_PROG_TCLSH
   211         -#TEA_PROG_WISH
   212         -
   213         -#--------------------------------------------------------------------
   214         -# Finally, substitute all of the various values into the Makefile.
   215         -# You may alternatively have a special pkgIndex.tcl.in or other files
   216         -# which require substituting th AC variables in.  Include these here.
   217         -#--------------------------------------------------------------------
   218         -
   219         -AC_OUTPUT([Makefile pkgIndex.tcl])

Deleted jni/tcl/pkgs/sqlite3.28.0/doc/sqlite3.n.

     1         -.TH sqlite3 n 4.1 "Tcl-Extensions"
     2         -.HS sqlite3 tcl
     3         -.BS
     4         -.SH NAME
     5         -sqlite3 \- an interface to the SQLite3 database engine
     6         -.SH SYNOPSIS
     7         -\fBsqlite3\fI command_name ?filename?\fR
     8         -.br
     9         -.SH DESCRIPTION
    10         -SQLite3 is a self-contains, zero-configuration, transactional SQL database
    11         -engine.  This extension provides an easy to use interface for accessing
    12         -SQLite database files from Tcl.
    13         -.PP
    14         -For full documentation see \fIhttp://www.sqlite.org/\fR and
    15         -in particular \fIhttp://www.sqlite.org/tclsqlite.html\fR.

Deleted jni/tcl/pkgs/sqlite3.28.0/generic/tclsqlite3.c.

     1         -#ifdef USE_SYSTEM_SQLITE
     2         -# include <sqlite3.h>
     3         -#else
     4         -#include "../compat/sqlite3/sqlite3.c"
     5         -#endif
     6         -/*
     7         -** 2001 September 15
     8         -**
     9         -** The author disclaims copyright to this source code.  In place of
    10         -** a legal notice, here is a blessing:
    11         -**
    12         -**    May you do good and not evil.
    13         -**    May you find forgiveness for yourself and forgive others.
    14         -**    May you share freely, never taking more than you give.
    15         -**
    16         -*************************************************************************
    17         -** A TCL Interface to SQLite.  Append this file to sqlite3.c and
    18         -** compile the whole thing to build a TCL-enabled version of SQLite.
    19         -**
    20         -** Compile-time options:
    21         -**
    22         -**  -DTCLSH         Add a "main()" routine that works as a tclsh.
    23         -**
    24         -**  -DTCLSH_INIT_PROC=name
    25         -**
    26         -**                  Invoke name(interp) to initialize the Tcl interpreter.
    27         -**                  If name(interp) returns a non-NULL string, then run
    28         -**                  that string as a Tcl script to launch the application.
    29         -**                  If name(interp) returns NULL, then run the regular
    30         -**                  tclsh-emulator code.
    31         -*/
    32         -#ifdef TCLSH_INIT_PROC
    33         -# define TCLSH 1
    34         -#endif
    35         -
    36         -/*
    37         -** If requested, include the SQLite compiler options file for MSVC.
    38         -*/
    39         -#if defined(INCLUDE_MSVC_H)
    40         -# include "msvc.h"
    41         -#endif
    42         -
    43         -#if defined(INCLUDE_SQLITE_TCL_H)
    44         -# include "sqlite_tcl.h"
    45         -#else
    46         -# include "tcl.h"
    47         -# ifndef SQLITE_TCLAPI
    48         -#  define SQLITE_TCLAPI
    49         -# endif
    50         -#endif
    51         -#include <errno.h>
    52         -
    53         -/*
    54         -** Some additional include files are needed if this file is not
    55         -** appended to the amalgamation.
    56         -*/
    57         -#ifndef SQLITE_AMALGAMATION
    58         -# include "sqlite3.h"
    59         -# include <stdlib.h>
    60         -# include <string.h>
    61         -# include <assert.h>
    62         -  typedef unsigned char u8;
    63         -#endif
    64         -#include <ctype.h>
    65         -
    66         -/* Used to get the current process ID */
    67         -#if !defined(_WIN32)
    68         -# include <signal.h>
    69         -# include <unistd.h>
    70         -# define GETPID getpid
    71         -#elif !defined(_WIN32_WCE)
    72         -# ifndef SQLITE_AMALGAMATION
    73         -#  ifndef WIN32_LEAN_AND_MEAN
    74         -#   define WIN32_LEAN_AND_MEAN
    75         -#  endif
    76         -#  include <windows.h>
    77         -# endif
    78         -# include <io.h>
    79         -# define isatty(h) _isatty(h)
    80         -# define GETPID (int)GetCurrentProcessId
    81         -#endif
    82         -
    83         -#ifdef USE_TCL_STUBS
    84         -# undef Tcl_BackgroundException
    85         -# define Tcl_BackgroundException(interp, result) (DbUseNre()? \
    86         -    ((void (*)(Tcl_Interp *, int))((&(tclStubsPtr->tcl_PkgProvideEx))[609]))((interp), (result)): \
    87         -    ((void (*)(Tcl_Interp *))((&(tclStubsPtr->tcl_PkgProvideEx))[76]))(interp))
    88         -#elif TCL_MAJOR_VERSION==8 && TCL_MINOR_VERSION<6
    89         -# define Tcl_BackgroundException(interp, result) Tcl_BackgroundError(interp)
    90         -#endif /* USE_TCL_STUBS */
    91         -
    92         -#if TCL_MAJOR_VERSION>8 || (TCL_MAJOR_VERSION==8 && TCL_MINOR_VERSION>=6)
    93         -static int DbUseNre(void);
    94         -#else
    95         -# define DbUseNre() 0
    96         -#endif
    97         -
    98         -/*
    99         - * If we are not sure the platform is 32-bit, always use sqlite3_????64()
   100         - * in stead of sqlite3_????() for certain functions, in order to prevent overflow.
   101         - */
   102         -#if !defined(i386)     && !defined(__i386__)   && !defined(_M_IX86) && \
   103         -    !defined(_M_ARM)   && !defined(__arm__)    && !defined(__x86) && \
   104         -    (!defined(__SIZEOF_POINTER__) || (__SIZEOF_POINTER__ != 4))
   105         -# undef sqlite3_bind_text
   106         -# undef sqlite3_result_text
   107         -# define sqlite3_bind_text(pStmt, i, zData, nData, xDel) sqlite3_bind_text64(pStmt, i, zData, nData, xDel, SQLITE_UTF8)
   108         -# define sqlite3_result_text(pCtx, z, n, xDel) sqlite3_result_text64(pCtx, z, n, xDel, SQLITE_UTF8)
   109         -#endif
   110         -
   111         -/*
   112         - * Windows needs to know which symbols to export.  Unix does not.
   113         - * BUILD_sqlite should be undefined for Unix.
   114         - */
   115         -#ifdef BUILD_sqlite
   116         -#undef TCL_STORAGE_CLASS
   117         -#define TCL_STORAGE_CLASS DLLEXPORT
   118         -#endif /* BUILD_sqlite */
   119         -
   120         -#define NUM_PREPARED_STMTS 10
   121         -#define MAX_PREPARED_STMTS 100
   122         -
   123         -/* Forward declaration */
   124         -typedef struct SqliteDb SqliteDb;
   125         -
   126         -/*
   127         -** New SQL functions can be created as TCL scripts.  Each such function
   128         -** is described by an instance of the following structure.
   129         -**
   130         -** Variable eType may be set to SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT,
   131         -** SQLITE_BLOB or SQLITE_NULL. If it is SQLITE_NULL, then the implementation
   132         -** attempts to determine the type of the result based on the Tcl object.
   133         -** If it is SQLITE_TEXT or SQLITE_BLOB, then a text (sqlite3_result_text())
   134         -** or blob (sqlite3_result_blob()) is returned. If it is SQLITE_INTEGER
   135         -** or SQLITE_FLOAT, then an attempt is made to return an integer or float
   136         -** value, falling back to float and then text if this is not possible.
   137         -*/
   138         -typedef struct SqlFunc SqlFunc;
   139         -struct SqlFunc {
   140         -  Tcl_Interp *interp;   /* The TCL interpret to execute the function */
   141         -  Tcl_Obj *pScript;     /* The Tcl_Obj representation of the script */
   142         -  SqliteDb *pDb;        /* Database connection that owns this function */
   143         -  int useEvalObjv;      /* True if it is safe to use Tcl_EvalObjv */
   144         -  int eType;            /* Type of value to return */
   145         -  char *zName;          /* Name of this function */
   146         -  SqlFunc *pNext;       /* Next function on the list of them all */
   147         -};
   148         -
   149         -/*
   150         -** New collation sequences function can be created as TCL scripts.  Each such
   151         -** function is described by an instance of the following structure.
   152         -*/
   153         -typedef struct SqlCollate SqlCollate;
   154         -struct SqlCollate {
   155         -  Tcl_Interp *interp;   /* The TCL interpret to execute the function */
   156         -  char *zScript;        /* The script to be run */
   157         -  SqlCollate *pNext;    /* Next function on the list of them all */
   158         -};
   159         -
   160         -/*
   161         -** Prepared statements are cached for faster execution.  Each prepared
   162         -** statement is described by an instance of the following structure.
   163         -*/
   164         -typedef struct SqlPreparedStmt SqlPreparedStmt;
   165         -struct SqlPreparedStmt {
   166         -  SqlPreparedStmt *pNext;  /* Next in linked list */
   167         -  SqlPreparedStmt *pPrev;  /* Previous on the list */
   168         -  sqlite3_stmt *pStmt;     /* The prepared statement */
   169         -  int nSql;                /* chars in zSql[] */
   170         -  const char *zSql;        /* Text of the SQL statement */
   171         -  int nParm;               /* Size of apParm array */
   172         -  Tcl_Obj **apParm;        /* Array of referenced object pointers */
   173         -};
   174         -
   175         -typedef struct IncrblobChannel IncrblobChannel;
   176         -
   177         -/*
   178         -** There is one instance of this structure for each SQLite database
   179         -** that has been opened by the SQLite TCL interface.
   180         -**
   181         -** If this module is built with SQLITE_TEST defined (to create the SQLite
   182         -** testfixture executable), then it may be configured to use either
   183         -** sqlite3_prepare_v2() or sqlite3_prepare() to prepare SQL statements.
   184         -** If SqliteDb.bLegacyPrepare is true, sqlite3_prepare() is used.
   185         -*/
   186         -struct SqliteDb {
   187         -  sqlite3 *db;               /* The "real" database structure. MUST BE FIRST */
   188         -  Tcl_Interp *interp;        /* The interpreter used for this database */
   189         -  char *zBusy;               /* The busy callback routine */
   190         -  char *zCommit;             /* The commit hook callback routine */
   191         -  char *zTrace;              /* The trace callback routine */
   192         -  char *zTraceV2;            /* The trace_v2 callback routine */
   193         -  char *zProfile;            /* The profile callback routine */
   194         -  char *zProgress;           /* The progress callback routine */
   195         -  char *zBindFallback;       /* Callback to invoke on a binding miss */
   196         -  char *zAuth;               /* The authorization callback routine */
   197         -  int disableAuth;           /* Disable the authorizer if it exists */
   198         -  char *zNull;               /* Text to substitute for an SQL NULL value */
   199         -  SqlFunc *pFunc;            /* List of SQL functions */
   200         -  Tcl_Obj *pUpdateHook;      /* Update hook script (if any) */
   201         -  Tcl_Obj *pPreUpdateHook;   /* Pre-update hook script (if any) */
   202         -  Tcl_Obj *pRollbackHook;    /* Rollback hook script (if any) */
   203         -  Tcl_Obj *pWalHook;         /* WAL hook script (if any) */
   204         -  Tcl_Obj *pUnlockNotify;    /* Unlock notify script (if any) */
   205         -  SqlCollate *pCollate;      /* List of SQL collation functions */
   206         -  int rc;                    /* Return code of most recent sqlite3_exec() */
   207         -  Tcl_Obj *pCollateNeeded;   /* Collation needed script */
   208         -  SqlPreparedStmt *stmtList; /* List of prepared statements*/
   209         -  SqlPreparedStmt *stmtLast; /* Last statement in the list */
   210         -  int maxStmt;               /* The next maximum number of stmtList */
   211         -  int nStmt;                 /* Number of statements in stmtList */
   212         -  IncrblobChannel *pIncrblob;/* Linked list of open incrblob channels */
   213         -  int nStep, nSort, nIndex;  /* Statistics for most recent operation */
   214         -  int nVMStep;               /* Another statistic for most recent operation */
   215         -  int nTransaction;          /* Number of nested [transaction] methods */
   216         -  int openFlags;             /* Flags used to open.  (SQLITE_OPEN_URI) */
   217         -#ifdef SQLITE_TEST
   218         -  int bLegacyPrepare;        /* True to use sqlite3_prepare() */
   219         -#endif
   220         -  Tcl_DString dsErr;         /* Used for error messages (utf8Encoding) */
   221         -};
   222         -
   223         -struct IncrblobChannel {
   224         -  sqlite3_blob *pBlob;      /* sqlite3 blob handle */
   225         -  SqliteDb *pDb;            /* Associated database connection */
   226         -  int iSeek;                /* Current seek offset */
   227         -  Tcl_Channel channel;      /* Channel identifier */
   228         -  IncrblobChannel *pNext;   /* Linked list of all open incrblob channels */
   229         -  IncrblobChannel *pPrev;   /* Linked list of all open incrblob channels */
   230         -};
   231         -
   232         -/*
   233         - ** Tcl UTF-8 encoding; loaded and tested on module init. Depending
   234         - ** on unicode support detected, it is reset to NULL or kept until
   235         - ** module gets unloaded.
   236         - */
   237         -static Tcl_Encoding utf8Encoding = NULL;
   238         -static int utf8EncInit = 0;
   239         -TCL_DECLARE_MUTEX(utf8EncMutex);
   240         -
   241         -/*
   242         -** Compute a string length that is limited to what can be stored in
   243         -** lower 30 bits of a 32-bit signed integer.
   244         -*/
   245         -static int strlen30(const char *z){
   246         -  const char *z2 = z;
   247         -  while( *z2 ){ z2++; }
   248         -  return 0x3fffffff & (int)(z2 - z);
   249         -}
   250         -
   251         -#ifdef USE_TCL_STUBS
   252         -# define tclStubsPtr staticTclStubsPtr
   253         -static const TclStubs *tclStubsPtr = 0;
   254         -#endif
   255         -
   256         -/*
   257         - ** Error message converter.
   258         - */
   259         -static const char *SQLITEDB_ERRMSG(SqliteDb *pDb){
   260         -  if( pDb!=NULL ){
   261         -    if( pDb->db!=NULL ){
   262         -      if( utf8Encoding!=NULL ){
   263         -        Tcl_DStringFree(&pDb->dsErr);
   264         -        Tcl_ExternalToUtfDString(utf8Encoding, sqlite3_errmsg(pDb->db),
   265         -            -1, &pDb->dsErr);
   266         -        return Tcl_DStringValue(&pDb->dsErr);
   267         -      }
   268         -      return sqlite3_errmsg(pDb->db);
   269         -    }
   270         -    return "not a valid database";
   271         -  }
   272         -  return "unknown error";
   273         -}
   274         -
   275         -#ifndef SQLITE_OMIT_INCRBLOB
   276         -/*
   277         -** Close all incrblob channels opened using database connection pDb.
   278         -** This is called when shutting down the database connection.
   279         -*/
   280         -static void closeIncrblobChannels(SqliteDb *pDb){
   281         -  IncrblobChannel *p;
   282         -  IncrblobChannel *pNext;
   283         -
   284         -  for(p=pDb->pIncrblob; p; p=pNext){
   285         -    pNext = p->pNext;
   286         -
   287         -    /* Note: Calling unregister here call Tcl_Close on the incrblob channel,
   288         -    ** which deletes the IncrblobChannel structure at *p. So do not
   289         -    ** call Tcl_Free() here.
   290         -    */
   291         -    Tcl_UnregisterChannel(pDb->interp, p->channel);
   292         -  }
   293         -}
   294         -
   295         -/*
   296         -** Close an incremental blob channel.
   297         -*/
   298         -static int SQLITE_TCLAPI incrblobClose(
   299         -  ClientData instanceData,
   300         -  Tcl_Interp *interp
   301         -){
   302         -  IncrblobChannel *p = (IncrblobChannel *)instanceData;
   303         -  int rc = sqlite3_blob_close(p->pBlob);
   304         -  SqliteDb *pDb = p->pDb;
   305         -
   306         -  /* Remove the channel from the SqliteDb.pIncrblob list. */
   307         -  if( p->pNext ){
   308         -    p->pNext->pPrev = p->pPrev;
   309         -  }
   310         -  if( p->pPrev ){
   311         -    p->pPrev->pNext = p->pNext;
   312         -  }
   313         -  if( p->pDb->pIncrblob==p ){
   314         -    p->pDb->pIncrblob = p->pNext;
   315         -  }
   316         -
   317         -  /* Free the IncrblobChannel structure */
   318         -  Tcl_Free((char *)p);
   319         -
   320         -  if( rc!=SQLITE_OK ){
   321         -    Tcl_AppendResult(interp, (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
   322         -    return TCL_ERROR;
   323         -  }
   324         -  return TCL_OK;
   325         -}
   326         -
   327         -/*
   328         -** Read data from an incremental blob channel.
   329         -*/
   330         -static int SQLITE_TCLAPI incrblobInput(
   331         -  ClientData instanceData,
   332         -  char *buf,
   333         -  int bufSize,
   334         -  int *errorCodePtr
   335         -){
   336         -  IncrblobChannel *p = (IncrblobChannel *)instanceData;
   337         -  int nRead = bufSize;         /* Number of bytes to read */
   338         -  int nBlob;                   /* Total size of the blob */
   339         -  int rc;                      /* sqlite error code */
   340         -
   341         -  nBlob = sqlite3_blob_bytes(p->pBlob);
   342         -  if( (p->iSeek+nRead)>nBlob ){
   343         -    nRead = nBlob-p->iSeek;
   344         -  }
   345         -  if( nRead<=0 ){
   346         -    return 0;
   347         -  }
   348         -
   349         -  rc = sqlite3_blob_read(p->pBlob, (void *)buf, nRead, p->iSeek);
   350         -  if( rc!=SQLITE_OK ){
   351         -    *errorCodePtr = rc;
   352         -    return -1;
   353         -  }
   354         -
   355         -  p->iSeek += nRead;
   356         -  return nRead;
   357         -}
   358         -
   359         -/*
   360         -** Write data to an incremental blob channel.
   361         -*/
   362         -static int SQLITE_TCLAPI incrblobOutput(
   363         -  ClientData instanceData,
   364         -  const char *buf,
   365         -  int toWrite,
   366         -  int *errorCodePtr
   367         -){
   368         -  IncrblobChannel *p = (IncrblobChannel *)instanceData;
   369         -  int nWrite = toWrite;        /* Number of bytes to write */
   370         -  int nBlob;                   /* Total size of the blob */
   371         -  int rc;                      /* sqlite error code */
   372         -
   373         -  nBlob = sqlite3_blob_bytes(p->pBlob);
   374         -  if( (p->iSeek+nWrite)>nBlob ){
   375         -    *errorCodePtr = EINVAL;
   376         -    return -1;
   377         -  }
   378         -  if( nWrite<=0 ){
   379         -    return 0;
   380         -  }
   381         -
   382         -  rc = sqlite3_blob_write(p->pBlob, (void *)buf, nWrite, p->iSeek);
   383         -  if( rc!=SQLITE_OK ){
   384         -    *errorCodePtr = EIO;
   385         -    return -1;
   386         -  }
   387         -
   388         -  p->iSeek += nWrite;
   389         -  return nWrite;
   390         -}
   391         -
   392         -/*
   393         -** Seek an incremental blob channel.
   394         -*/
   395         -static int SQLITE_TCLAPI incrblobSeek(
   396         -  ClientData instanceData,
   397         -  long offset,
   398         -  int seekMode,
   399         -  int *errorCodePtr
   400         -){
   401         -  IncrblobChannel *p = (IncrblobChannel *)instanceData;
   402         -
   403         -  switch( seekMode ){
   404         -    case SEEK_SET:
   405         -      p->iSeek = offset;
   406         -      break;
   407         -    case SEEK_CUR:
   408         -      p->iSeek += offset;
   409         -      break;
   410         -    case SEEK_END:
   411         -      p->iSeek = sqlite3_blob_bytes(p->pBlob) + offset;
   412         -      break;
   413         -
   414         -    default: assert(!"Bad seekMode");
   415         -  }
   416         -
   417         -  return p->iSeek;
   418         -}
   419         -
   420         -
   421         -static void SQLITE_TCLAPI incrblobWatch(
   422         -  ClientData instanceData,
   423         -  int mode
   424         -){
   425         -  /* NO-OP */
   426         -}
   427         -static int SQLITE_TCLAPI incrblobHandle(
   428         -  ClientData instanceData,
   429         -  int dir,
   430         -  ClientData *hPtr
   431         -){
   432         -  return TCL_ERROR;
   433         -}
   434         -
   435         -static Tcl_ChannelType IncrblobChannelType = {
   436         -  "incrblob",                        /* typeName                             */
   437         -  TCL_CHANNEL_VERSION_2,             /* version                              */
   438         -  incrblobClose,                     /* closeProc                            */
   439         -  incrblobInput,                     /* inputProc                            */
   440         -  incrblobOutput,                    /* outputProc                           */
   441         -  incrblobSeek,                      /* seekProc                             */
   442         -  0,                                 /* setOptionProc                        */
   443         -  0,                                 /* getOptionProc                        */
   444         -  incrblobWatch,                     /* watchProc (this is a no-op)          */
   445         -  incrblobHandle,                    /* getHandleProc (always returns error) */
   446         -  0,                                 /* close2Proc                           */
   447         -  0,                                 /* blockModeProc                        */
   448         -  0,                                 /* flushProc                            */
   449         -  0,                                 /* handlerProc                          */
   450         -  0,                                 /* wideSeekProc                         */
   451         -};
   452         -
   453         -/*
   454         -** Create a new incrblob channel.
   455         -*/
   456         -static int createIncrblobChannel(
   457         -  Tcl_Interp *interp,
   458         -  SqliteDb *pDb,
   459         -  const char *zDb,
   460         -  const char *zTable,
   461         -  const char *zColumn,
   462         -  sqlite_int64 iRow,
   463         -  int isReadonly
   464         -){
   465         -  IncrblobChannel *p;
   466         -  sqlite3 *db = pDb->db;
   467         -  sqlite3_blob *pBlob;
   468         -  int rc;
   469         -  int flags = TCL_READABLE|(isReadonly ? 0 : TCL_WRITABLE);
   470         -
   471         -  /* This variable is used to name the channels: "incrblob_[incr count]" */
   472         -  static int count = 0;
   473         -  char zChannel[64];
   474         -
   475         -  rc = sqlite3_blob_open(db, zDb, zTable, zColumn, iRow, !isReadonly, &pBlob);
   476         -  if( rc!=SQLITE_OK ){
   477         -    Tcl_AppendResult(interp, (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
   478         -    return TCL_ERROR;
   479         -  }
   480         -
   481         -  p = (IncrblobChannel *)Tcl_Alloc(sizeof(IncrblobChannel));
   482         -  p->iSeek = 0;
   483         -  p->pBlob = pBlob;
   484         -
   485         -  sqlite3_snprintf(sizeof(zChannel), zChannel, "incrblob_%d", ++count);
   486         -  p->channel = Tcl_CreateChannel(&IncrblobChannelType, zChannel, p, flags);
   487         -  Tcl_RegisterChannel(interp, p->channel);
   488         -
   489         -  /* Link the new channel into the SqliteDb.pIncrblob list. */
   490         -  p->pNext = pDb->pIncrblob;
   491         -  p->pPrev = 0;
   492         -  if( p->pNext ){
   493         -    p->pNext->pPrev = p;
   494         -  }
   495         -  pDb->pIncrblob = p;
   496         -  p->pDb = pDb;
   497         -
   498         -  Tcl_AppendResult(interp, Tcl_GetChannelName(p->channel), (char*)0);
   499         -  return TCL_OK;
   500         -}
   501         -#else  /* else clause for "#ifndef SQLITE_OMIT_INCRBLOB" */
   502         -  #define closeIncrblobChannels(pDb)
   503         -#endif
   504         -
   505         -/*
   506         -** Look at the script prefix in pCmd.  We will be executing this script
   507         -** after first appending one or more arguments.  This routine analyzes
   508         -** the script to see if it is safe to use Tcl_EvalObjv() on the script
   509         -** rather than the more general Tcl_EvalEx().  Tcl_EvalObjv() is much
   510         -** faster.
   511         -**
   512         -** Scripts that are safe to use with Tcl_EvalObjv() consists of a
   513         -** command name followed by zero or more arguments with no [...] or $
   514         -** or {...} or ; to be seen anywhere.  Most callback scripts consist
   515         -** of just a single procedure name and they meet this requirement.
   516         -*/
   517         -static int safeToUseEvalObjv(Tcl_Interp *interp, Tcl_Obj *pCmd){
   518         -  /* We could try to do something with Tcl_Parse().  But we will instead
   519         -  ** just do a search for forbidden characters.  If any of the forbidden
   520         -  ** characters appear in pCmd, we will report the string as unsafe.
   521         -  */
   522         -  const char *z;
   523         -  int n;
   524         -  z = Tcl_GetStringFromObj(pCmd, &n);
   525         -  while( n-- > 0 ){
   526         -    int c = *(z++);
   527         -    if( c=='$' || c=='[' || c==';' ) return 0;
   528         -  }
   529         -  return 1;
   530         -}
   531         -
   532         -/*
   533         -** Find an SqlFunc structure with the given name.  Or create a new
   534         -** one if an existing one cannot be found.  Return a pointer to the
   535         -** structure.
   536         -*/
   537         -static SqlFunc *findSqlFunc(SqliteDb *pDb, const char *zName){
   538         -  SqlFunc *p, *pNew;
   539         -  int nName = strlen30(zName);
   540         -  pNew = (SqlFunc*)Tcl_Alloc( sizeof(*pNew) + nName + 1 );
   541         -  pNew->zName = (char*)&pNew[1];
   542         -  memcpy(pNew->zName, zName, nName+1);
   543         -  for(p=pDb->pFunc; p; p=p->pNext){
   544         -    if( sqlite3_stricmp(p->zName, pNew->zName)==0 ){
   545         -      Tcl_Free((char*)pNew);
   546         -      return p;
   547         -    }
   548         -  }
   549         -  pNew->interp = pDb->interp;
   550         -  pNew->pDb = pDb;
   551         -  pNew->pScript = 0;
   552         -  pNew->pNext = pDb->pFunc;
   553         -  pDb->pFunc = pNew;
   554         -  return pNew;
   555         -}
   556         -
   557         -/*
   558         -** Free a single SqlPreparedStmt object.
   559         -*/
   560         -static void dbFreeStmt(SqlPreparedStmt *pStmt){
   561         -#ifdef SQLITE_TEST
   562         -  if( sqlite3_sql(pStmt->pStmt)==0 ){
   563         -    Tcl_Free((char *)pStmt->zSql);
   564         -  }
   565         -#endif
   566         -  sqlite3_finalize(pStmt->pStmt);
   567         -  Tcl_Free((char *)pStmt);
   568         -}
   569         -
   570         -/*
   571         -** Finalize and free a list of prepared statements
   572         -*/
   573         -static void flushStmtCache(SqliteDb *pDb){
   574         -  SqlPreparedStmt *pPreStmt;
   575         -  SqlPreparedStmt *pNext;
   576         -
   577         -  for(pPreStmt = pDb->stmtList; pPreStmt; pPreStmt=pNext){
   578         -    pNext = pPreStmt->pNext;
   579         -    dbFreeStmt(pPreStmt);
   580         -  }
   581         -  pDb->nStmt = 0;
   582         -  pDb->stmtLast = 0;
   583         -  pDb->stmtList = 0;
   584         -}
   585         -
   586         -/*
   587         -** TCL calls this procedure when an sqlite3 database command is
   588         -** deleted.
   589         -*/
   590         -static void SQLITE_TCLAPI DbDeleteCmd(void *db){
   591         -  SqliteDb *pDb = (SqliteDb*)db;
   592         -  flushStmtCache(pDb);
   593         -  closeIncrblobChannels(pDb);
   594         -  sqlite3_close(pDb->db);
   595         -  while( pDb->pFunc ){
   596         -    SqlFunc *pFunc = pDb->pFunc;
   597         -    pDb->pFunc = pFunc->pNext;
   598         -    assert( pFunc->pDb==pDb );
   599         -    Tcl_DecrRefCount(pFunc->pScript);
   600         -    Tcl_Free((char*)pFunc);
   601         -  }
   602         -  while( pDb->pCollate ){
   603         -    SqlCollate *pCollate = pDb->pCollate;
   604         -    pDb->pCollate = pCollate->pNext;
   605         -    Tcl_Free((char*)pCollate);
   606         -  }
   607         -  if( pDb->zBusy ){
   608         -    Tcl_Free(pDb->zBusy);
   609         -  }
   610         -  if( pDb->zTrace ){
   611         -    Tcl_Free(pDb->zTrace);
   612         -  }
   613         -  if( pDb->zTraceV2 ){
   614         -    Tcl_Free(pDb->zTraceV2);
   615         -  }
   616         -  if( pDb->zProfile ){
   617         -    Tcl_Free(pDb->zProfile);
   618         -  }
   619         -  if( pDb->zBindFallback ){
   620         -    Tcl_Free(pDb->zBindFallback);
   621         -  }
   622         -  if( pDb->zAuth ){
   623         -    Tcl_Free(pDb->zAuth);
   624         -  }
   625         -  if( pDb->zNull ){
   626         -    Tcl_Free(pDb->zNull);
   627         -  }
   628         -  if( pDb->pUpdateHook ){
   629         -    Tcl_DecrRefCount(pDb->pUpdateHook);
   630         -  }
   631         -  if( pDb->pPreUpdateHook ){
   632         -    Tcl_DecrRefCount(pDb->pPreUpdateHook);
   633         -  }
   634         -  if( pDb->pRollbackHook ){
   635         -    Tcl_DecrRefCount(pDb->pRollbackHook);
   636         -  }
   637         -  if( pDb->pWalHook ){
   638         -    Tcl_DecrRefCount(pDb->pWalHook);
   639         -  }
   640         -  if( pDb->pCollateNeeded ){
   641         -    Tcl_DecrRefCount(pDb->pCollateNeeded);
   642         -  }
   643         -  Tcl_DStringFree(&pDb->dsErr);
   644         -  Tcl_Free((char*)pDb);
   645         -}
   646         -
   647         -/*
   648         -** This routine is called when a database file is locked while trying
   649         -** to execute SQL.
   650         -*/
   651         -static int DbBusyHandler(void *cd, int nTries){
   652         -  SqliteDb *pDb = (SqliteDb*)cd;
   653         -  int rc;
   654         -  char zVal[32];
   655         -  Tcl_DString dstring;
   656         -
   657         -  sqlite3_snprintf(sizeof(zVal), zVal, " %d", nTries);
   658         -  Tcl_DStringInit(&dstring);
   659         -  Tcl_DStringAppend(&dstring, pDb->zBusy, -1);
   660         -  Tcl_DStringAppend(&dstring, zVal, -1);
   661         -  rc = Tcl_EvalEx(pDb->interp, Tcl_DStringValue(&dstring),
   662         -      Tcl_DStringLength(&dstring), TCL_EVAL_GLOBAL);
   663         -  Tcl_DStringFree(&dstring);
   664         -  if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){
   665         -    return 0;
   666         -  }
   667         -  return 1;
   668         -}
   669         -
   670         -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   671         -/*
   672         -** This routine is invoked as the 'progress callback' for the database.
   673         -*/
   674         -static int DbProgressHandler(void *cd){
   675         -  SqliteDb *pDb = (SqliteDb*)cd;
   676         -  int rc;
   677         -
   678         -  assert( pDb->zProgress );
   679         -  rc = Tcl_EvalEx(pDb->interp, pDb->zProgress, -1, 0);
   680         -  if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){
   681         -    return 1;
   682         -  }
   683         -  return 0;
   684         -}
   685         -#endif
   686         -
   687         -#ifndef SQLITE_OMIT_TRACE
   688         -/*
   689         -** This routine is called by the SQLite trace handler whenever a new
   690         -** block of SQL is executed.  The TCL script in pDb->zTrace is executed.
   691         -*/
   692         -static int DbTraceHandler(
   693         -  unsigned type, /* One of the SQLITE_TRACE_* event types. */
   694         -  void *cd,      /* The original context data pointer. */
   695         -  void *pd,      /* Primary event data, depends on event type. */
   696         -  void *xd       /* Extra event data, depends on event type. */
   697         -){
   698         -  SqliteDb *pDb = (SqliteDb*)cd;
   699         -  Tcl_DString str;
   700         -
   701         -  Tcl_DStringInit(&str);
   702         -  Tcl_DStringAppend(&str, pDb->zTrace, -1);
   703         -  Tcl_DStringAppendElement(&str, (char *)xd);
   704         -  Tcl_EvalEx(pDb->interp, Tcl_DStringValue(&str), -1, 0);
   705         -  Tcl_DStringFree(&str);
   706         -  Tcl_ResetResult(pDb->interp);
   707         -  return TCL_OK;
   708         -}
   709         -#endif
   710         -
   711         -#ifndef SQLITE_OMIT_TRACE
   712         -/*
   713         -** This routine is called by the SQLite trace_v2 handler whenever a new
   714         -** supported event is generated.  Unsupported event types are ignored.
   715         -** The TCL script in pDb->zTraceV2 is executed, with the arguments for
   716         -** the event appended to it (as list elements).
   717         -*/
   718         -static int DbTraceV2Handler(
   719         -  unsigned type, /* One of the SQLITE_TRACE_* event types. */
   720         -  void *cd,      /* The original context data pointer. */
   721         -  void *pd,      /* Primary event data, depends on event type. */
   722         -  void *xd       /* Extra event data, depends on event type. */
   723         -){
   724         -  SqliteDb *pDb = (SqliteDb*)cd;
   725         -  Tcl_Obj *pCmd;
   726         -
   727         -  switch( type ){
   728         -    case SQLITE_TRACE_STMT: {
   729         -      sqlite3_stmt *pStmt = (sqlite3_stmt *)pd;
   730         -      char *zSql = (char *)xd;
   731         -
   732         -      pCmd = Tcl_NewStringObj(pDb->zTraceV2, -1);
   733         -      Tcl_IncrRefCount(pCmd);
   734         -      Tcl_ListObjAppendElement(pDb->interp, pCmd,
   735         -                               Tcl_NewWideIntObj((size_t)pStmt));
   736         -      Tcl_ListObjAppendElement(pDb->interp, pCmd,
   737         -                               Tcl_NewStringObj(zSql, -1));
   738         -      Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT);
   739         -      Tcl_DecrRefCount(pCmd);
   740         -      Tcl_ResetResult(pDb->interp);
   741         -      break;
   742         -    }
   743         -    case SQLITE_TRACE_PROFILE: {
   744         -      sqlite3_stmt *pStmt = (sqlite3_stmt *)pd;
   745         -      sqlite3_int64 ns = *(sqlite3_int64*)xd;
   746         -
   747         -      pCmd = Tcl_NewStringObj(pDb->zTraceV2, -1);
   748         -      Tcl_IncrRefCount(pCmd);
   749         -      Tcl_ListObjAppendElement(pDb->interp, pCmd,
   750         -                               Tcl_NewWideIntObj((size_t)pStmt));
   751         -      Tcl_ListObjAppendElement(pDb->interp, pCmd,
   752         -                               Tcl_NewWideIntObj((Tcl_WideInt)ns));
   753         -      Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT);
   754         -      Tcl_DecrRefCount(pCmd);
   755         -      Tcl_ResetResult(pDb->interp);
   756         -      break;
   757         -    }
   758         -    case SQLITE_TRACE_ROW: {
   759         -      sqlite3_stmt *pStmt = (sqlite3_stmt *)pd;
   760         -
   761         -      pCmd = Tcl_NewStringObj(pDb->zTraceV2, -1);
   762         -      Tcl_IncrRefCount(pCmd);
   763         -      Tcl_ListObjAppendElement(pDb->interp, pCmd,
   764         -                               Tcl_NewWideIntObj((size_t)pStmt));
   765         -      Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT);
   766         -      Tcl_DecrRefCount(pCmd);
   767         -      Tcl_ResetResult(pDb->interp);
   768         -      break;
   769         -    }
   770         -    case SQLITE_TRACE_CLOSE: {
   771         -      sqlite3 *db = (sqlite3 *)pd;
   772         -
   773         -      pCmd = Tcl_NewStringObj(pDb->zTraceV2, -1);
   774         -      Tcl_IncrRefCount(pCmd);
   775         -      Tcl_ListObjAppendElement(pDb->interp, pCmd,
   776         -                               Tcl_NewWideIntObj((size_t)db));
   777         -      Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT);
   778         -      Tcl_DecrRefCount(pCmd);
   779         -      Tcl_ResetResult(pDb->interp);
   780         -      break;
   781         -    }
   782         -  }
   783         -  return SQLITE_OK;
   784         -}
   785         -#endif
   786         -
   787         -#ifndef SQLITE_OMIT_TRACE
   788         -/*
   789         -** This routine is called by the SQLite profile handler after a statement
   790         -** SQL has executed.  The TCL script in pDb->zProfile is evaluated.
   791         -*/
   792         -static int DbProfileHandler(
   793         -  unsigned type, /* One of the SQLITE_TRACE_* event types. */
   794         -  void *cd,      /* The original context data pointer. */
   795         -  void *pd,      /* Primary event data, depends on event type. */
   796         -  void *xd       /* Extra event data, depends on event type. */
   797         -){
   798         -  SqliteDb *pDb = (SqliteDb*)cd;
   799         -  Tcl_DString str;
   800         -  char zTm[100];
   801         -  sqlite3_stmt *pStmt = (sqlite3_stmt *)pd;
   802         -
   803         -  sqlite3_snprintf(sizeof(zTm)-1, zTm, "%lld", (Tcl_WideInt)(size_t)xd);
   804         -  Tcl_DStringInit(&str);
   805         -  Tcl_DStringAppend(&str, pDb->zProfile, -1);
   806         -  Tcl_DStringAppendElement(&str, sqlite3_sql(pStmt));
   807         -  Tcl_DStringAppendElement(&str, zTm);
   808         -  Tcl_EvalEx(pDb->interp, Tcl_DStringValue(&str), -1, 0);
   809         -  Tcl_DStringFree(&str);
   810         -  Tcl_ResetResult(pDb->interp);
   811         -  return SQLITE_OK;
   812         -}
   813         -#endif
   814         -
   815         -/*
   816         -** This routine is called when a transaction is committed.  The
   817         -** TCL script in pDb->zCommit is executed.  If it returns non-zero or
   818         -** if it throws an exception, the transaction is rolled back instead
   819         -** of being committed.
   820         -*/
   821         -static int DbCommitHandler(void *cd){
   822         -  SqliteDb *pDb = (SqliteDb*)cd;
   823         -  int rc;
   824         -
   825         -  rc = Tcl_EvalEx(pDb->interp, pDb->zCommit, -1, 0);
   826         -  if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){
   827         -    return 1;
   828         -  }
   829         -  return 0;
   830         -}
   831         -
   832         -static void DbRollbackHandler(void *clientData){
   833         -  int rc;
   834         -  SqliteDb *pDb = (SqliteDb*)clientData;
   835         -  assert(pDb->pRollbackHook);
   836         -  if( TCL_OK!=(rc=Tcl_EvalObjEx(pDb->interp, pDb->pRollbackHook, 0)) ){
   837         -    Tcl_BackgroundException(pDb->interp, rc);
   838         -  }
   839         -}
   840         -
   841         -/*
   842         -** This procedure handles wal_hook callbacks.
   843         -*/
   844         -static int DbWalHandler(
   845         -  void *clientData,
   846         -  sqlite3 *db,
   847         -  const char *zDb,
   848         -  int nEntry
   849         -){
   850         -  int ret = SQLITE_OK, rc;
   851         -  Tcl_Obj *p;
   852         -  SqliteDb *pDb = (SqliteDb*)clientData;
   853         -  Tcl_Interp *interp = pDb->interp;
   854         -  assert(pDb->pWalHook);
   855         -
   856         -  assert( db==pDb->db );
   857         -  p = Tcl_DuplicateObj(pDb->pWalHook);
   858         -  Tcl_IncrRefCount(p);
   859         -  Tcl_ListObjAppendElement(interp, p, Tcl_NewStringObj(zDb, -1));
   860         -  Tcl_ListObjAppendElement(interp, p, Tcl_NewWideIntObj(nEntry));
   861         -  if( TCL_OK!=(rc=Tcl_EvalObjEx(interp, p, 0))
   862         -   || TCL_OK!=(rc=Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &ret))
   863         -  ){
   864         -    Tcl_BackgroundException(interp, rc);
   865         -  }
   866         -  Tcl_DecrRefCount(p);
   867         -
   868         -  return ret;
   869         -}
   870         -
   871         -#if defined(SQLITE_TEST) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY)
   872         -static void setTestUnlockNotifyVars(Tcl_Interp *interp, int iArg, int nArg){
   873         -  char zBuf[64];
   874         -  sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", iArg);
   875         -  Tcl_SetVar2(interp, "sqlite_unlock_notify_arg", NULL, zBuf, TCL_GLOBAL_ONLY);
   876         -  sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", nArg);
   877         -  Tcl_SetVar2(interp, "sqlite_unlock_notify_argcount", NULL, zBuf, TCL_GLOBAL_ONLY);
   878         -}
   879         -#else
   880         -# define setTestUnlockNotifyVars(x,y,z)
   881         -#endif
   882         -
   883         -#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
   884         -static void DbUnlockNotify(void **apArg, int nArg){
   885         -  int i;
   886         -  for(i=0; i<nArg; i++){
   887         -    const int flags = (TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT);
   888         -    SqliteDb *pDb = (SqliteDb *)apArg[i];
   889         -    setTestUnlockNotifyVars(pDb->interp, i, nArg);
   890         -    assert( pDb->pUnlockNotify);
   891         -    Tcl_EvalObjEx(pDb->interp, pDb->pUnlockNotify, flags);
   892         -    Tcl_DecrRefCount(pDb->pUnlockNotify);
   893         -    pDb->pUnlockNotify = 0;
   894         -  }
   895         -}
   896         -#endif
   897         -
   898         -#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
   899         -/*
   900         -** Pre-update hook callback.
   901         -*/
   902         -static void DbPreUpdateHandler(
   903         -  void *p,
   904         -  sqlite3 *db,
   905         -  int op,
   906         -  const char *zDb,
   907         -  const char *zTbl,
   908         -  sqlite_int64 iKey1,
   909         -  sqlite_int64 iKey2
   910         -){
   911         -  SqliteDb *pDb = (SqliteDb *)p;
   912         -  Tcl_Obj *pCmd;
   913         -  static const char *azStr[] = {"DELETE", "INSERT", "UPDATE"};
   914         -
   915         -  assert( (SQLITE_DELETE-1)/9 == 0 );
   916         -  assert( (SQLITE_INSERT-1)/9 == 1 );
   917         -  assert( (SQLITE_UPDATE-1)/9 == 2 );
   918         -  assert( pDb->pPreUpdateHook );
   919         -  assert( db==pDb->db );
   920         -  assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE );
   921         -
   922         -  pCmd = Tcl_DuplicateObj(pDb->pPreUpdateHook);
   923         -  Tcl_IncrRefCount(pCmd);
   924         -  Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(azStr[(op-1)/9], -1));
   925         -  if( utf8Encoding!=NULL ){
   926         -    Tcl_DString ds;
   927         -    Tcl_ExternalToUtfDString(utf8Encoding, zDb, -1, &ds);
   928         -    Tcl_ListObjAppendElement(0, pCmd,
   929         -        Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)));
   930         -    Tcl_DStringFree(&ds);
   931         -    Tcl_ExternalToUtfDString(utf8Encoding, zTbl, -1, &ds);
   932         -    Tcl_ListObjAppendElement(0, pCmd,
   933         -        Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)));
   934         -    Tcl_DStringFree(&ds);
   935         -  }else{
   936         -    Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zDb, -1));
   937         -    Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zTbl, -1));
   938         -  }
   939         -  Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(iKey1));
   940         -  Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(iKey2));
   941         -  Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT);
   942         -  Tcl_DecrRefCount(pCmd);
   943         -}
   944         -#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
   945         -
   946         -static void DbUpdateHandler(
   947         -  void *p,
   948         -  int op,
   949         -  const char *zDb,
   950         -  const char *zTbl,
   951         -  sqlite_int64 rowid
   952         -){
   953         -  SqliteDb *pDb = (SqliteDb *)p;
   954         -  Tcl_Obj *pCmd;
   955         -  static const char *azStr[] = {"DELETE", "INSERT", "UPDATE"};
   956         -
   957         -  assert( (SQLITE_DELETE-1)/9 == 0 );
   958         -  assert( (SQLITE_INSERT-1)/9 == 1 );
   959         -  assert( (SQLITE_UPDATE-1)/9 == 2 );
   960         -
   961         -  assert( pDb->pUpdateHook );
   962         -  assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE );
   963         -
   964         -  pCmd = Tcl_DuplicateObj(pDb->pUpdateHook);
   965         -  Tcl_IncrRefCount(pCmd);
   966         -  Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(azStr[(op-1)/9], -1));
   967         -  if( utf8Encoding!=NULL ){
   968         -    Tcl_DString ds;
   969         -    Tcl_ExternalToUtfDString(utf8Encoding, zDb, -1, &ds);
   970         -    Tcl_ListObjAppendElement(0, pCmd,
   971         -        Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)));
   972         -    Tcl_DStringFree(&ds);
   973         -    Tcl_ExternalToUtfDString(utf8Encoding, zTbl, -1, &ds);
   974         -    Tcl_ListObjAppendElement(0, pCmd,
   975         -        Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)));
   976         -    Tcl_DStringFree(&ds);
   977         -  }else{
   978         -    Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zDb, -1));
   979         -    Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zTbl, -1));
   980         -  }
   981         -  Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(rowid));
   982         -  Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT);
   983         -  Tcl_DecrRefCount(pCmd);
   984         -}
   985         -
   986         -static void tclCollateNeeded(
   987         -  void *pCtx,
   988         -  sqlite3 *db,
   989         -  int enc,
   990         -  const char *zName
   991         -){
   992         -  SqliteDb *pDb = (SqliteDb *)pCtx;
   993         -  Tcl_Obj *pScript = Tcl_DuplicateObj(pDb->pCollateNeeded);
   994         -  Tcl_IncrRefCount(pScript);
   995         -  if( utf8Encoding!=NULL ){
   996         -    Tcl_DString ds;
   997         -    Tcl_ExternalToUtfDString(utf8Encoding, zName, -1, &ds);
   998         -    Tcl_ListObjAppendElement(0, pScript,
   999         -        Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)));
  1000         -    Tcl_DStringFree(&ds);
  1001         -  }else{
  1002         -    Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj(zName, -1));
  1003         -  }
  1004         -  Tcl_EvalObjEx(pDb->interp, pScript, 0);
  1005         -  Tcl_DecrRefCount(pScript);
  1006         -}
  1007         -
  1008         -/*
  1009         -** This routine is called to evaluate an SQL collation function implemented
  1010         -** using TCL script.
  1011         -*/
  1012         -static int tclSqlCollate(
  1013         -  void *pCtx,
  1014         -  int nA,
  1015         -  const void *zA,
  1016         -  int nB,
  1017         -  const void *zB
  1018         -){
  1019         -  SqlCollate *p = (SqlCollate *)pCtx;
  1020         -  Tcl_Obj *pCmd;
  1021         -
  1022         -  pCmd = Tcl_NewStringObj(p->zScript, -1);
  1023         -  Tcl_IncrRefCount(pCmd);
  1024         -  if( utf8Encoding!=NULL ){
  1025         -    Tcl_DString dsA, dsB;
  1026         -    Tcl_ExternalToUtfDString(utf8Encoding, (char*)zA, nA, &dsA);
  1027         -    Tcl_ExternalToUtfDString(utf8Encoding, (char*)zB, nB, &dsB);
  1028         -    Tcl_ListObjAppendElement(p->interp, pCmd,
  1029         -        Tcl_NewStringObj(Tcl_DStringValue(&dsA), Tcl_DStringLength(&dsA)));
  1030         -    Tcl_ListObjAppendElement(p->interp, pCmd,
  1031         -        Tcl_NewStringObj(Tcl_DStringValue(&dsB), Tcl_DStringLength(&dsB)));
  1032         -    Tcl_DStringFree(&dsA);
  1033         -    Tcl_DStringFree(&dsB);
  1034         -  }else{
  1035         -    Tcl_ListObjAppendElement(p->interp, pCmd, Tcl_NewStringObj(zA, nA));
  1036         -    Tcl_ListObjAppendElement(p->interp, pCmd, Tcl_NewStringObj(zB, nB));
  1037         -  }
  1038         -  Tcl_EvalObjEx(p->interp, pCmd, TCL_EVAL_DIRECT);
  1039         -  Tcl_DecrRefCount(pCmd);
  1040         -  return (atoi(Tcl_GetStringResult(p->interp)));
  1041         -}
  1042         -
  1043         -/*
  1044         -** This routine is called to evaluate an SQL function implemented
  1045         -** using TCL script.
  1046         -*/
  1047         -static void tclSqlFunc(sqlite3_context *context, int argc, sqlite3_value**argv){
  1048         -  SqlFunc *p = sqlite3_user_data(context);
  1049         -  Tcl_Obj *pCmd;
  1050         -  int i;
  1051         -  int rc;
  1052         -
  1053         -  if( argc==0 ){
  1054         -    /* If there are no arguments to the function, call Tcl_EvalObjEx on the
  1055         -    ** script object directly.  This allows the TCL compiler to generate
  1056         -    ** bytecode for the command on the first invocation and thus make
  1057         -    ** subsequent invocations much faster. */
  1058         -    pCmd = p->pScript;
  1059         -    Tcl_IncrRefCount(pCmd);
  1060         -    rc = Tcl_EvalObjEx(p->interp, pCmd, 0);
  1061         -    Tcl_DecrRefCount(pCmd);
  1062         -  }else{
  1063         -    /* If there are arguments to the function, make a shallow copy of the
  1064         -    ** script object, lappend the arguments, then evaluate the copy.
  1065         -    **
  1066         -    ** By "shallow" copy, we mean only the outer list Tcl_Obj is duplicated.
  1067         -    ** The new Tcl_Obj contains pointers to the original list elements.
  1068         -    ** That way, when Tcl_EvalObjv() is run and shimmers the first element
  1069         -    ** of the list to tclCmdNameType, that alternate representation will
  1070         -    ** be preserved and reused on the next invocation.
  1071         -    */
  1072         -    Tcl_Obj **aArg;
  1073         -    int nArg;
  1074         -    if( Tcl_ListObjGetElements(p->interp, p->pScript, &nArg, &aArg) ){
  1075         -resultError:
  1076         -      if( utf8Encoding!=NULL ){
  1077         -        Tcl_DString ds;
  1078         -        Tcl_UtfToExternalDString(utf8Encoding, Tcl_GetStringResult(p->interp),
  1079         -            -1, &ds);
  1080         -        sqlite3_result_error(context, Tcl_DStringValue(&ds),
  1081         -            Tcl_DStringLength(&ds));
  1082         -        Tcl_DStringFree(&ds);
  1083         -      }else{
  1084         -        sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1);
  1085         -      }
  1086         -      return;
  1087         -    }
  1088         -    pCmd = Tcl_NewListObj(nArg, aArg);
  1089         -    Tcl_IncrRefCount(pCmd);
  1090         -    for(i=0; i<argc; i++){
  1091         -      sqlite3_value *pIn = argv[i];
  1092         -      Tcl_Obj *pVal;
  1093         -
  1094         -      /* Set pVal to contain the i'th column of this row. */
  1095         -      switch( sqlite3_value_type(pIn) ){
  1096         -        case SQLITE_BLOB: {
  1097         -          int bytes = sqlite3_value_bytes(pIn);
  1098         -          pVal = Tcl_NewByteArrayObj(sqlite3_value_blob(pIn), bytes);
  1099         -          break;
  1100         -        }
  1101         -        case SQLITE_INTEGER: {
  1102         -          sqlite_int64 v = sqlite3_value_int64(pIn);
  1103         -          if( v>=-2147483647 && v<=2147483647 ){
  1104         -            pVal = Tcl_NewIntObj((int)v);
  1105         -          }else{
  1106         -            pVal = Tcl_NewWideIntObj(v);
  1107         -          }
  1108         -          break;
  1109         -        }
  1110         -        case SQLITE_FLOAT: {
  1111         -          double r = sqlite3_value_double(pIn);
  1112         -          pVal = Tcl_NewDoubleObj(r);
  1113         -          break;
  1114         -        }
  1115         -        case SQLITE_NULL: {
  1116         -          pVal = Tcl_NewStringObj(p->pDb->zNull, -1);
  1117         -          break;
  1118         -        }
  1119         -        default: {
  1120         -          int bytes = sqlite3_value_bytes(pIn);
  1121         -          if( utf8Encoding!=NULL ){
  1122         -            Tcl_DString ds;
  1123         -            Tcl_ExternalToUtfDString(utf8Encoding,
  1124         -                (char *)sqlite3_value_text(pIn), bytes, &ds);
  1125         -            pVal = Tcl_NewStringObj(Tcl_DStringValue(&ds),
  1126         -                       Tcl_DStringLength(&ds));
  1127         -            Tcl_DStringFree(&ds);
  1128         -          }else{
  1129         -            pVal = Tcl_NewStringObj((char *)sqlite3_value_text(pIn), bytes);
  1130         -          }
  1131         -          break;
  1132         -        }
  1133         -      }
  1134         -      rc = Tcl_ListObjAppendElement(p->interp, pCmd, pVal);
  1135         -      if( rc ){
  1136         -        Tcl_DecrRefCount(pCmd);
  1137         -        goto resultError;
  1138         -      }
  1139         -    }
  1140         -    if( !p->useEvalObjv ){
  1141         -      /* Tcl_EvalObjEx() will automatically call Tcl_EvalObjv() if pCmd
  1142         -      ** is a list without a string representation.  To prevent this from
  1143         -      ** happening, make sure pCmd has a valid string representation */
  1144         -      Tcl_GetString(pCmd);
  1145         -    }
  1146         -    rc = Tcl_EvalObjEx(p->interp, pCmd, TCL_EVAL_DIRECT);
  1147         -    Tcl_DecrRefCount(pCmd);
  1148         -  }
  1149         -
  1150         -  if( rc && rc!=TCL_RETURN ){
  1151         -    goto resultError;
  1152         -  }else{
  1153         -    Tcl_Obj *pVar = Tcl_GetObjResult(p->interp);
  1154         -    int n;
  1155         -    u8 *data;
  1156         -    const char *zType = (pVar->typePtr ? pVar->typePtr->name : "");
  1157         -    char c = zType[0];
  1158         -    int eType = p->eType;
  1159         -
  1160         -    if( eType==SQLITE_NULL ){
  1161         -      if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){
  1162         -        /* Only return a BLOB type if the Tcl variable is a bytearray and
  1163         -        ** has no string representation. */
  1164         -        eType = SQLITE_BLOB;
  1165         -      }else if( (c=='b' && ((strcmp(zType,"boolean")==0)
  1166         -             || (strcmp(zType,"booleanString")==0)))
  1167         -             || (c=='w' && strcmp(zType,"wideInt")==0)
  1168         -             || (c=='i' && strcmp(zType,"int")==0)
  1169         -      ){
  1170         -        eType = SQLITE_INTEGER;
  1171         -      }else if( c=='d' && strcmp(zType,"double")==0 ){
  1172         -        eType = SQLITE_FLOAT;
  1173         -      }else{
  1174         -        eType = SQLITE_TEXT;
  1175         -      }
  1176         -    }
  1177         -
  1178         -    switch( eType ){
  1179         -      case SQLITE_BLOB: {
  1180         -        data = Tcl_GetByteArrayFromObj(pVar, &n);
  1181         -        sqlite3_result_blob(context, data, n, SQLITE_TRANSIENT);
  1182         -        break;
  1183         -      }
  1184         -      case SQLITE_INTEGER: {
  1185         -        Tcl_WideInt v;
  1186         -        if( TCL_OK==Tcl_GetWideIntFromObj(0, pVar, &v) ){
  1187         -          sqlite3_result_int64(context, v);
  1188         -          break;
  1189         -        }
  1190         -        /* fall-through */
  1191         -      }
  1192         -      case SQLITE_FLOAT: {
  1193         -        double r;
  1194         -        if( TCL_OK==Tcl_GetDoubleFromObj(0, pVar, &r) ){
  1195         -          sqlite3_result_double(context, r);
  1196         -          break;
  1197         -        }
  1198         -        /* fall-through */
  1199         -      }
  1200         -      default: {
  1201         -        data = (unsigned char *)Tcl_GetStringFromObj(pVar, &n);
  1202         -        sqlite3_result_text(context, (char *)data, n, SQLITE_TRANSIENT);
  1203         -        break;
  1204         -      }
  1205         -    }
  1206         -
  1207         -  }
  1208         -}
  1209         -
  1210         -#ifndef SQLITE_OMIT_AUTHORIZATION
  1211         -/*
  1212         -** This is the authentication function.  It appends the authentication
  1213         -** type code and the two arguments to zCmd[] then invokes the result
  1214         -** on the interpreter.  The reply is examined to determine if the
  1215         -** authentication fails or succeeds.
  1216         -*/
  1217         -static int auth_callback(
  1218         -  void *pArg,
  1219         -  int code,
  1220         -  const char *zArg1,
  1221         -  const char *zArg2,
  1222         -  const char *zArg3,
  1223         -  const char *zArg4
  1224         -#ifdef SQLITE_USER_AUTHENTICATION
  1225         -  ,const char *zArg5
  1226         -#endif
  1227         -){
  1228         -  const char *zCode;
  1229         -  Tcl_DString str;
  1230         -  int rc;
  1231         -  const char *zReply;
  1232         -  /* EVIDENCE-OF: R-38590-62769 The first parameter to the authorizer
  1233         -  ** callback is a copy of the third parameter to the
  1234         -  ** sqlite3_set_authorizer() interface.
  1235         -  */
  1236         -  SqliteDb *pDb = (SqliteDb*)pArg;
  1237         -  if( pDb->disableAuth ) return SQLITE_OK;
  1238         -
  1239         -  /* EVIDENCE-OF: R-56518-44310 The second parameter to the callback is an
  1240         -  ** integer action code that specifies the particular action to be
  1241         -  ** authorized. */
  1242         -  switch( code ){
  1243         -    case SQLITE_COPY              : zCode="SQLITE_COPY"; break;
  1244         -    case SQLITE_CREATE_INDEX      : zCode="SQLITE_CREATE_INDEX"; break;
  1245         -    case SQLITE_CREATE_TABLE      : zCode="SQLITE_CREATE_TABLE"; break;
  1246         -    case SQLITE_CREATE_TEMP_INDEX : zCode="SQLITE_CREATE_TEMP_INDEX"; break;
  1247         -    case SQLITE_CREATE_TEMP_TABLE : zCode="SQLITE_CREATE_TEMP_TABLE"; break;
  1248         -    case SQLITE_CREATE_TEMP_TRIGGER: zCode="SQLITE_CREATE_TEMP_TRIGGER"; break;
  1249         -    case SQLITE_CREATE_TEMP_VIEW  : zCode="SQLITE_CREATE_TEMP_VIEW"; break;
  1250         -    case SQLITE_CREATE_TRIGGER    : zCode="SQLITE_CREATE_TRIGGER"; break;
  1251         -    case SQLITE_CREATE_VIEW       : zCode="SQLITE_CREATE_VIEW"; break;
  1252         -    case SQLITE_DELETE            : zCode="SQLITE_DELETE"; break;
  1253         -    case SQLITE_DROP_INDEX        : zCode="SQLITE_DROP_INDEX"; break;
  1254         -    case SQLITE_DROP_TABLE        : zCode="SQLITE_DROP_TABLE"; break;
  1255         -    case SQLITE_DROP_TEMP_INDEX   : zCode="SQLITE_DROP_TEMP_INDEX"; break;
  1256         -    case SQLITE_DROP_TEMP_TABLE   : zCode="SQLITE_DROP_TEMP_TABLE"; break;
  1257         -    case SQLITE_DROP_TEMP_TRIGGER : zCode="SQLITE_DROP_TEMP_TRIGGER"; break;
  1258         -    case SQLITE_DROP_TEMP_VIEW    : zCode="SQLITE_DROP_TEMP_VIEW"; break;
  1259         -    case SQLITE_DROP_TRIGGER      : zCode="SQLITE_DROP_TRIGGER"; break;
  1260         -    case SQLITE_DROP_VIEW         : zCode="SQLITE_DROP_VIEW"; break;
  1261         -    case SQLITE_INSERT            : zCode="SQLITE_INSERT"; break;
  1262         -    case SQLITE_PRAGMA            : zCode="SQLITE_PRAGMA"; break;
  1263         -    case SQLITE_READ              : zCode="SQLITE_READ"; break;
  1264         -    case SQLITE_SELECT            : zCode="SQLITE_SELECT"; break;
  1265         -    case SQLITE_TRANSACTION       : zCode="SQLITE_TRANSACTION"; break;
  1266         -    case SQLITE_UPDATE            : zCode="SQLITE_UPDATE"; break;
  1267         -    case SQLITE_ATTACH            : zCode="SQLITE_ATTACH"; break;
  1268         -    case SQLITE_DETACH            : zCode="SQLITE_DETACH"; break;
  1269         -    case SQLITE_ALTER_TABLE       : zCode="SQLITE_ALTER_TABLE"; break;
  1270         -    case SQLITE_REINDEX           : zCode="SQLITE_REINDEX"; break;
  1271         -    case SQLITE_ANALYZE           : zCode="SQLITE_ANALYZE"; break;
  1272         -    case SQLITE_CREATE_VTABLE     : zCode="SQLITE_CREATE_VTABLE"; break;
  1273         -    case SQLITE_DROP_VTABLE       : zCode="SQLITE_DROP_VTABLE"; break;
  1274         -    case SQLITE_FUNCTION          : zCode="SQLITE_FUNCTION"; break;
  1275         -    case SQLITE_SAVEPOINT         : zCode="SQLITE_SAVEPOINT"; break;
  1276         -    case SQLITE_RECURSIVE         : zCode="SQLITE_RECURSIVE"; break;
  1277         -    default                       : zCode="????"; break;
  1278         -  }
  1279         -  Tcl_DStringInit(&str);
  1280         -  Tcl_DStringAppend(&str, pDb->zAuth, -1);
  1281         -  Tcl_DStringAppendElement(&str, zCode);
  1282         -  Tcl_DStringAppendElement(&str, zArg1 ? zArg1 : "");
  1283         -  Tcl_DStringAppendElement(&str, zArg2 ? zArg2 : "");
  1284         -  Tcl_DStringAppendElement(&str, zArg3 ? zArg3 : "");
  1285         -  Tcl_DStringAppendElement(&str, zArg4 ? zArg4 : "");
  1286         -#ifdef SQLITE_USER_AUTHENTICATION
  1287         -  Tcl_DStringAppendElement(&str, zArg5 ? zArg5 : "");
  1288         -#endif
  1289         -  rc = Tcl_EvalEx(pDb->interp, Tcl_DStringValue(&str), -1, TCL_EVAL_GLOBAL);
  1290         -  Tcl_DStringFree(&str);
  1291         -  zReply = rc==TCL_OK ? Tcl_GetStringResult(pDb->interp) : "SQLITE_DENY";
  1292         -  if( strcmp(zReply,"SQLITE_OK")==0 ){
  1293         -    rc = SQLITE_OK;
  1294         -  }else if( strcmp(zReply,"SQLITE_DENY")==0 ){
  1295         -    rc = SQLITE_DENY;
  1296         -  }else if( strcmp(zReply,"SQLITE_IGNORE")==0 ){
  1297         -    rc = SQLITE_IGNORE;
  1298         -  }else{
  1299         -    rc = 999;
  1300         -  }
  1301         -  return rc;
  1302         -}
  1303         -#endif /* SQLITE_OMIT_AUTHORIZATION */
  1304         -
  1305         -#if 0
  1306         -/*
  1307         -** This routine reads a line of text from FILE in, stores
  1308         -** the text in memory obtained from malloc() and returns a pointer
  1309         -** to the text.  NULL is returned at end of file, or if malloc()
  1310         -** fails.
  1311         -**
  1312         -** The interface is like "readline" but no command-line editing
  1313         -** is done.
  1314         -**
  1315         -** copied from shell.c from '.import' command
  1316         -*/
  1317         -static char *local_getline(char *zPrompt, FILE *in){
  1318         -  char *zLine;
  1319         -  int nLine;
  1320         -  int n;
  1321         -
  1322         -  nLine = 100;
  1323         -  zLine = malloc( nLine );
  1324         -  if( zLine==0 ) return 0;
  1325         -  n = 0;
  1326         -  while( 1 ){
  1327         -    if( n+100>nLine ){
  1328         -      nLine = nLine*2 + 100;
  1329         -      zLine = realloc(zLine, nLine);
  1330         -      if( zLine==0 ) return 0;
  1331         -    }
  1332         -    if( fgets(&zLine[n], nLine - n, in)==0 ){
  1333         -      if( n==0 ){
  1334         -        free(zLine);
  1335         -        return 0;
  1336         -      }
  1337         -      zLine[n] = 0;
  1338         -      break;
  1339         -    }
  1340         -    while( zLine[n] ){ n++; }
  1341         -    if( n>0 && zLine[n-1]=='\n' ){
  1342         -      n--;
  1343         -      zLine[n] = 0;
  1344         -      break;
  1345         -    }
  1346         -  }
  1347         -  zLine = realloc( zLine, n+1 );
  1348         -  return zLine;
  1349         -}
  1350         -#endif
  1351         -
  1352         -
  1353         -/*
  1354         -** This function is part of the implementation of the command:
  1355         -**
  1356         -**   $db transaction [-deferred|-immediate|-exclusive] SCRIPT
  1357         -**
  1358         -** It is invoked after evaluating the script SCRIPT to commit or rollback
  1359         -** the transaction or savepoint opened by the [transaction] command.
  1360         -*/
  1361         -static int SQLITE_TCLAPI DbTransPostCmd(
  1362         -  ClientData data[],                   /* data[0] is the Sqlite3Db* for $db */
  1363         -  Tcl_Interp *interp,                  /* Tcl interpreter */
  1364         -  int result                           /* Result of evaluating SCRIPT */
  1365         -){
  1366         -  static const char *const azEnd[] = {
  1367         -    "RELEASE _tcl_transaction",        /* rc==TCL_ERROR, nTransaction!=0 */
  1368         -    "COMMIT",                          /* rc!=TCL_ERROR, nTransaction==0 */
  1369         -    "ROLLBACK TO _tcl_transaction ; RELEASE _tcl_transaction",
  1370         -    "ROLLBACK"                         /* rc==TCL_ERROR, nTransaction==0 */
  1371         -  };
  1372         -  SqliteDb *pDb = (SqliteDb*)data[0];
  1373         -  int rc = result;
  1374         -  const char *zEnd;
  1375         -
  1376         -  pDb->nTransaction--;
  1377         -  zEnd = azEnd[(rc==TCL_ERROR)*2 + (pDb->nTransaction==0)];
  1378         -
  1379         -  pDb->disableAuth++;
  1380         -  if( sqlite3_exec(pDb->db, zEnd, 0, 0, 0) ){
  1381         -      /* This is a tricky scenario to handle. The most likely cause of an
  1382         -      ** error is that the exec() above was an attempt to commit the
  1383         -      ** top-level transaction that returned SQLITE_BUSY. Or, less likely,
  1384         -      ** that an IO-error has occurred. In either case, throw a Tcl exception
  1385         -      ** and try to rollback the transaction.
  1386         -      **
  1387         -      ** But it could also be that the user executed one or more BEGIN,
  1388         -      ** COMMIT, SAVEPOINT, RELEASE or ROLLBACK commands that are confusing
  1389         -      ** this method's logic. Not clear how this would be best handled.
  1390         -      */
  1391         -    if( rc!=TCL_ERROR ){
  1392         -      Tcl_AppendResult(interp, (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
  1393         -      rc = TCL_ERROR;
  1394         -    }
  1395         -    sqlite3_exec(pDb->db, "ROLLBACK", 0, 0, 0);
  1396         -  }
  1397         -  pDb->disableAuth--;
  1398         -
  1399         -  return rc;
  1400         -}
  1401         -
  1402         -/*
  1403         -** Unless SQLITE_TEST is defined, this function is a simple wrapper around
  1404         -** sqlite3_prepare_v2(). If SQLITE_TEST is defined, then it uses either
  1405         -** sqlite3_prepare_v2() or legacy interface sqlite3_prepare(), depending
  1406         -** on whether or not the [db_use_legacy_prepare] command has been used to
  1407         -** configure the connection.
  1408         -*/
  1409         -static int dbPrepare(
  1410         -  SqliteDb *pDb,                  /* Database object */
  1411         -  const char *zSql,               /* SQL to compile */
  1412         -  sqlite3_stmt **ppStmt,          /* OUT: Prepared statement */
  1413         -  const char **pzOut              /* OUT: Pointer to next SQL statement */
  1414         -){
  1415         -  unsigned int prepFlags = 0;
  1416         -#ifdef SQLITE_TEST
  1417         -  if( pDb->bLegacyPrepare ){
  1418         -    return sqlite3_prepare(pDb->db, zSql, -1, ppStmt, pzOut);
  1419         -  }
  1420         -#endif
  1421         -  /* If the statement cache is large, use the SQLITE_PREPARE_PERSISTENT
  1422         -  ** flags, which uses less lookaside memory.  But if the cache is small,
  1423         -  ** omit that flag to make full use of lookaside */
  1424         -  if( pDb->maxStmt>5 ) prepFlags = SQLITE_PREPARE_PERSISTENT;
  1425         -
  1426         -  return sqlite3_prepare_v3(pDb->db, zSql, -1, prepFlags, ppStmt, pzOut);
  1427         -}
  1428         -
  1429         -/*
  1430         -** Search the cache for a prepared-statement object that implements the
  1431         -** first SQL statement in the buffer pointed to by parameter zIn. If
  1432         -** no such prepared-statement can be found, allocate and prepare a new
  1433         -** one. In either case, bind the current values of the relevant Tcl
  1434         -** variables to any $var, :var or @var variables in the statement. Before
  1435         -** returning, set *ppPreStmt to point to the prepared-statement object.
  1436         -**
  1437         -** Output parameter *pzOut is set to point to the next SQL statement in
  1438         -** buffer zIn, or to the '\0' byte at the end of zIn if there is no
  1439         -** next statement.
  1440         -**
  1441         -** If successful, TCL_OK is returned. Otherwise, TCL_ERROR is returned
  1442         -** and an error message loaded into interpreter pDb->interp.
  1443         -*/
  1444         -static int dbPrepareAndBind(
  1445         -  SqliteDb *pDb,                  /* Database object */
  1446         -  char const *zIn,                /* SQL to compile */
  1447         -  char const **pzOut,             /* OUT: Pointer to next SQL statement */
  1448         -  SqlPreparedStmt **ppPreStmt     /* OUT: Object used to cache statement */
  1449         -){
  1450         -  const char *zSql = zIn;         /* Pointer to first SQL statement in zIn */
  1451         -  sqlite3_stmt *pStmt = 0;        /* Prepared statement object */
  1452         -  SqlPreparedStmt *pPreStmt;      /* Pointer to cached statement */
  1453         -  int nSql;                       /* Length of zSql in bytes */
  1454         -  int nVar = 0;                   /* Number of variables in statement */
  1455         -  int iParm = 0;                  /* Next free entry in apParm */
  1456         -  char c;
  1457         -  int i;
  1458         -  int needResultReset = 0;        /* Need to invoke Tcl_ResetResult() */
  1459         -  int rc = SQLITE_OK;             /* Value to return */
  1460         -  Tcl_Interp *interp = pDb->interp;
  1461         -  Tcl_DString ds;
  1462         -
  1463         -  *ppPreStmt = 0;
  1464         -
  1465         -  /* Trim spaces from the start of zSql and calculate the remaining length. */
  1466         -  while( (c = zSql[0])==' ' || c=='\t' || c=='\r' || c=='\n' ){ zSql++; }
  1467         -  nSql = strlen30(zSql);
  1468         -
  1469         -  for(pPreStmt = pDb->stmtList; pPreStmt; pPreStmt=pPreStmt->pNext){
  1470         -    int n = pPreStmt->nSql;
  1471         -    if( nSql>=n
  1472         -        && memcmp(pPreStmt->zSql, zSql, n)==0
  1473         -        && (zSql[n]==0 || zSql[n-1]==';')
  1474         -    ){
  1475         -      pStmt = pPreStmt->pStmt;
  1476         -      *pzOut = &zSql[pPreStmt->nSql];
  1477         -
  1478         -      /* When a prepared statement is found, unlink it from the
  1479         -      ** cache list.  It will later be added back to the beginning
  1480         -      ** of the cache list in order to implement LRU replacement.
  1481         -      */
  1482         -      if( pPreStmt->pPrev ){
  1483         -        pPreStmt->pPrev->pNext = pPreStmt->pNext;
  1484         -      }else{
  1485         -        pDb->stmtList = pPreStmt->pNext;
  1486         -      }
  1487         -      if( pPreStmt->pNext ){
  1488         -        pPreStmt->pNext->pPrev = pPreStmt->pPrev;
  1489         -      }else{
  1490         -        pDb->stmtLast = pPreStmt->pPrev;
  1491         -      }
  1492         -      pDb->nStmt--;
  1493         -      nVar = sqlite3_bind_parameter_count(pStmt);
  1494         -      break;
  1495         -    }
  1496         -  }
  1497         -
  1498         -  /* If no prepared statement was found. Compile the SQL text. Also allocate
  1499         -  ** a new SqlPreparedStmt structure.  */
  1500         -  if( pPreStmt==0 ){
  1501         -    int nByte;
  1502         -
  1503         -    if( SQLITE_OK!=dbPrepare(pDb, zSql, &pStmt, pzOut) ){
  1504         -      Tcl_SetObjResult(interp, Tcl_NewStringObj(SQLITEDB_ERRMSG(pDb), -1));
  1505         -      return TCL_ERROR;
  1506         -    }
  1507         -    if( pStmt==0 ){
  1508         -      if( SQLITE_OK!=sqlite3_errcode(pDb->db) ){
  1509         -        /* A compile-time error in the statement. */
  1510         -        Tcl_SetObjResult(interp, Tcl_NewStringObj(SQLITEDB_ERRMSG(pDb), -1));
  1511         -        return TCL_ERROR;
  1512         -      }else{
  1513         -        /* The statement was a no-op.  Continue to the next statement
  1514         -        ** in the SQL string.
  1515         -        */
  1516         -        return TCL_OK;
  1517         -      }
  1518         -    }
  1519         -
  1520         -    assert( pPreStmt==0 );
  1521         -    nVar = sqlite3_bind_parameter_count(pStmt);
  1522         -    nByte = sizeof(SqlPreparedStmt) + nVar*sizeof(Tcl_Obj *);
  1523         -    pPreStmt = (SqlPreparedStmt*)Tcl_Alloc(nByte);
  1524         -    memset(pPreStmt, 0, nByte);
  1525         -
  1526         -    pPreStmt->pStmt = pStmt;
  1527         -    pPreStmt->nSql = (int)(*pzOut - zSql);
  1528         -    pPreStmt->zSql = sqlite3_sql(pStmt);
  1529         -    pPreStmt->apParm = (Tcl_Obj **)&pPreStmt[1];
  1530         -#ifdef SQLITE_TEST
  1531         -    if( pPreStmt->zSql==0 ){
  1532         -      char *zCopy = Tcl_Alloc(pPreStmt->nSql + 1);
  1533         -      memcpy(zCopy, zSql, pPreStmt->nSql);
  1534         -      zCopy[pPreStmt->nSql] = '\0';
  1535         -      pPreStmt->zSql = zCopy;
  1536         -    }
  1537         -#endif
  1538         -  }
  1539         -  assert( pPreStmt );
  1540         -  assert( strlen30(pPreStmt->zSql)==pPreStmt->nSql );
  1541         -  assert( 0==memcmp(pPreStmt->zSql, zSql, pPreStmt->nSql) );
  1542         -
  1543         -  /* Bind values to parameters that begin with $ or : */
  1544         -  Tcl_DStringInit(&ds);
  1545         -  for(i=1; i<=nVar; i++){
  1546         -    const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
  1547         -    if( utf8Encoding!= NULL ){
  1548         -      Tcl_DStringFree(&ds);
  1549         -      Tcl_ExternalToUtfDString(utf8Encoding, zVar, -1, &ds);
  1550         -      zVar = Tcl_DStringValue(&ds);
  1551         -    }
  1552         -    if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':' || zVar[0]=='@') ){
  1553         -      Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0);
  1554         -      if( pVar==0 && pDb->zBindFallback!=0 ){
  1555         -        Tcl_Obj *pCmd;
  1556         -        int rx;
  1557         -        pCmd = Tcl_NewStringObj(pDb->zBindFallback, -1);
  1558         -        Tcl_IncrRefCount(pCmd);
  1559         -        Tcl_ListObjAppendElement(interp, pCmd, Tcl_NewStringObj(zVar,-1));
  1560         -        if( needResultReset ) Tcl_ResetResult(interp);
  1561         -        needResultReset = 1;
  1562         -        rx = Tcl_EvalObjEx(interp, pCmd, TCL_EVAL_DIRECT);
  1563         -        Tcl_DecrRefCount(pCmd);
  1564         -        if( rx==TCL_OK ){
  1565         -          pVar = Tcl_GetObjResult(interp);
  1566         -        }else if( rx==TCL_ERROR ){
  1567         -          rc = TCL_ERROR;
  1568         -          break;
  1569         -        }else{
  1570         -          pVar = 0;
  1571         -        }
  1572         -      }
  1573         -      if( pVar ){
  1574         -        int n;
  1575         -        u8 *data;
  1576         -        const char *zType = (pVar->typePtr ? pVar->typePtr->name : "");
  1577         -        c = zType[0];
  1578         -        if( zVar[0]=='@' ||
  1579         -           (c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0) ){
  1580         -          /* Load a BLOB type if the Tcl variable is a bytearray and
  1581         -          ** it has no string representation or the host
  1582         -          ** parameter name begins with "@". */
  1583         -          data = Tcl_GetByteArrayFromObj(pVar, &n);
  1584         -          sqlite3_bind_blob(pStmt, i, data, n, SQLITE_STATIC);
  1585         -          Tcl_IncrRefCount(pVar);
  1586         -          pPreStmt->apParm[iParm++] = pVar;
  1587         -        }else if( c=='b' && strcmp(zType,"boolean")==0 ){
  1588         -          Tcl_GetIntFromObj(interp, pVar, &n);
  1589         -        }else if( c=='b' && strcmp(zType,"booleanString")==0 ){
  1590         -          Tcl_GetBooleanFromObj(interp, pVar, &n);
  1591         -          sqlite3_bind_int(pStmt, i, n);
  1592         -        }else if( c=='d' && strcmp(zType,"double")==0 ){
  1593         -          double r;
  1594         -          Tcl_GetDoubleFromObj(interp, pVar, &r);
  1595         -          sqlite3_bind_double(pStmt, i, r);
  1596         -        }else if( (c=='w' && strcmp(zType,"wideInt")==0) ||
  1597         -              (c=='i' && strcmp(zType,"int")==0) ){
  1598         -          Tcl_WideInt v;
  1599         -          Tcl_GetWideIntFromObj(interp, pVar, &v);
  1600         -          sqlite3_bind_int64(pStmt, i, v);
  1601         -        }else if( utf8Encoding!=NULL ){
  1602         -          Tcl_DStringFree(&ds);
  1603         -          Tcl_UtfToExternalDString(utf8Encoding, Tcl_GetString(pVar),
  1604         -              pVar->length, &ds);
  1605         -          sqlite3_bind_text(pStmt, i, Tcl_DStringValue(&ds),
  1606         -              Tcl_DStringLength(&ds), SQLITE_TRANSIENT);
  1607         -          Tcl_IncrRefCount(pVar);
  1608         -          pPreStmt->apParm[iParm++] = pVar;
  1609         -        }else{
  1610         -          data = (unsigned char *)Tcl_GetString(pVar);
  1611         -          sqlite3_bind_text(pStmt, i, (char *)data, pVar->length, SQLITE_STATIC);
  1612         -          Tcl_IncrRefCount(pVar);
  1613         -          pPreStmt->apParm[iParm++] = pVar;
  1614         -        }
  1615         -      }else{
  1616         -        sqlite3_bind_null(pStmt, i);
  1617         -      }
  1618         -      if( needResultReset ) Tcl_ResetResult(pDb->interp);
  1619         -    }
  1620         -  }
  1621         -  Tcl_DStringFree(&ds);
  1622         -  pPreStmt->nParm = iParm;
  1623         -  *ppPreStmt = pPreStmt;
  1624         -  if( needResultReset && rc==TCL_OK ) Tcl_ResetResult(pDb->interp);
  1625         -
  1626         -  return rc;
  1627         -}
  1628         -
  1629         -/*
  1630         -** Release a statement reference obtained by calling dbPrepareAndBind().
  1631         -** There should be exactly one call to this function for each call to
  1632         -** dbPrepareAndBind().
  1633         -**
  1634         -** If the discard parameter is non-zero, then the statement is deleted
  1635         -** immediately. Otherwise it is added to the LRU list and may be returned
  1636         -** by a subsequent call to dbPrepareAndBind().
  1637         -*/
  1638         -static void dbReleaseStmt(
  1639         -  SqliteDb *pDb,                  /* Database handle */
  1640         -  SqlPreparedStmt *pPreStmt,      /* Prepared statement handle to release */
  1641         -  int discard                     /* True to delete (not cache) the pPreStmt */
  1642         -){
  1643         -  int i;
  1644         -
  1645         -  /* Free the bound string and blob parameters */
  1646         -  for(i=0; i<pPreStmt->nParm; i++){
  1647         -    Tcl_DecrRefCount(pPreStmt->apParm[i]);
  1648         -  }
  1649         -  pPreStmt->nParm = 0;
  1650         -
  1651         -  if( pDb->maxStmt<=0 || discard ){
  1652         -    /* If the cache is turned off, deallocated the statement */
  1653         -    dbFreeStmt(pPreStmt);
  1654         -  }else{
  1655         -    /* Add the prepared statement to the beginning of the cache list. */
  1656         -    pPreStmt->pNext = pDb->stmtList;
  1657         -    pPreStmt->pPrev = 0;
  1658         -    if( pDb->stmtList ){
  1659         -     pDb->stmtList->pPrev = pPreStmt;
  1660         -    }
  1661         -    pDb->stmtList = pPreStmt;
  1662         -    if( pDb->stmtLast==0 ){
  1663         -      assert( pDb->nStmt==0 );
  1664         -      pDb->stmtLast = pPreStmt;
  1665         -    }else{
  1666         -      assert( pDb->nStmt>0 );
  1667         -    }
  1668         -    pDb->nStmt++;
  1669         -
  1670         -    /* If we have too many statement in cache, remove the surplus from
  1671         -    ** the end of the cache list.  */
  1672         -    while( pDb->nStmt>pDb->maxStmt ){
  1673         -      SqlPreparedStmt *pLast = pDb->stmtLast;
  1674         -      pDb->stmtLast = pLast->pPrev;
  1675         -      pDb->stmtLast->pNext = 0;
  1676         -      pDb->nStmt--;
  1677         -      dbFreeStmt(pLast);
  1678         -    }
  1679         -  }
  1680         -}
  1681         -
  1682         -/*
  1683         -** Structure used with dbEvalXXX() functions:
  1684         -**
  1685         -**   dbEvalInit()
  1686         -**   dbEvalStep()
  1687         -**   dbEvalFinalize()
  1688         -**   dbEvalRowInfo()
  1689         -**   dbEvalColumnValue()
  1690         -*/
  1691         -typedef struct DbEvalContext DbEvalContext;
  1692         -struct DbEvalContext {
  1693         -  SqliteDb *pDb;                  /* Database handle */
  1694         -  Tcl_Obj *pSql;                  /* Object holding string zSql */
  1695         -  Tcl_DString dsSql;              /* Encoded SQL text */
  1696         -  const char *zSql;               /* Remaining SQL to execute */
  1697         -  SqlPreparedStmt *pPreStmt;      /* Current statement */
  1698         -  int nCol;                       /* Number of columns returned by pStmt */
  1699         -  int evalFlags;                  /* Flags used */
  1700         -  Tcl_Obj *pArray;                /* Name of array variable */
  1701         -  Tcl_Obj **apColName;            /* Array of column names */
  1702         -};
  1703         -
  1704         -#define SQLITE_EVAL_WITHOUTNULLS  0x00001  /* Unset array(*) for NULL */
  1705         -
  1706         -/*
  1707         -** Release any cache of column names currently held as part of
  1708         -** the DbEvalContext structure passed as the first argument.
  1709         -*/
  1710         -static void dbReleaseColumnNames(DbEvalContext *p){
  1711         -  if( p->apColName ){
  1712         -    int i;
  1713         -    for(i=0; i<p->nCol; i++){
  1714         -      Tcl_DecrRefCount(p->apColName[i]);
  1715         -    }
  1716         -    Tcl_Free((char *)p->apColName);
  1717         -    p->apColName = 0;
  1718         -  }
  1719         -  p->nCol = 0;
  1720         -}
  1721         -
  1722         -/*
  1723         -** Initialize a DbEvalContext structure.
  1724         -**
  1725         -** If pArray is not NULL, then it contains the name of a Tcl array
  1726         -** variable. The "*" member of this array is set to a list containing
  1727         -** the names of the columns returned by the statement as part of each
  1728         -** call to dbEvalStep(), in order from left to right. e.g. if the names
  1729         -** of the returned columns are a, b and c, it does the equivalent of the
  1730         -** tcl command:
  1731         -**
  1732         -**     set ${pArray}(*) {a b c}
  1733         -*/
  1734         -static void dbEvalInit(
  1735         -  DbEvalContext *p,               /* Pointer to structure to initialize */
  1736         -  SqliteDb *pDb,                  /* Database handle */
  1737         -  Tcl_Obj *pSql,                  /* Object containing SQL script */
  1738         -  Tcl_Obj *pArray,                /* Name of Tcl array to set (*) element of */
  1739         -  int evalFlags                   /* Flags controlling evaluation */
  1740         -){
  1741         -  memset(p, 0, sizeof(DbEvalContext));
  1742         -  p->pDb = pDb;
  1743         -  if( utf8Encoding!=NULL ){
  1744         -    p->zSql = Tcl_UtfToExternalDString(utf8Encoding, Tcl_GetString(pSql),
  1745         -                  pSql->length, &p->dsSql);
  1746         -  }else{
  1747         -    Tcl_DStringInit(&p->dsSql);
  1748         -    p->zSql = Tcl_GetString(pSql);
  1749         -  }
  1750         -  p->pSql = pSql;
  1751         -  Tcl_IncrRefCount(pSql);
  1752         -  if( pArray ){
  1753         -    p->pArray = pArray;
  1754         -    Tcl_IncrRefCount(pArray);
  1755         -  }
  1756         -  p->evalFlags = evalFlags;
  1757         -}
  1758         -
  1759         -/*
  1760         -** Obtain information about the row that the DbEvalContext passed as the
  1761         -** first argument currently points to.
  1762         -*/
  1763         -static void dbEvalRowInfo(
  1764         -  DbEvalContext *p,               /* Evaluation context */
  1765         -  int *pnCol,                     /* OUT: Number of column names */
  1766         -  Tcl_Obj ***papColName           /* OUT: Array of column names */
  1767         -){
  1768         -  /* Compute column names */
  1769         -  if( 0==p->apColName ){
  1770         -    sqlite3_stmt *pStmt = p->pPreStmt->pStmt;
  1771         -    int i;                        /* Iterator variable */
  1772         -    int nCol;                     /* Number of columns returned by pStmt */
  1773         -    Tcl_Obj **apColName = 0;      /* Array of column names */
  1774         -
  1775         -    p->nCol = nCol = sqlite3_column_count(pStmt);
  1776         -    if( nCol>0 && (papColName || p->pArray) ){
  1777         -      apColName = (Tcl_Obj**)Tcl_Alloc( sizeof(Tcl_Obj*)*nCol );
  1778         -      for(i=0; i<nCol; i++){
  1779         -        if( utf8Encoding!=NULL ){
  1780         -          Tcl_DString ds;
  1781         -          Tcl_ExternalToUtfDString(utf8Encoding, sqlite3_column_name(pStmt,i),
  1782         -              -1, &ds);
  1783         -          apColName[i] = Tcl_NewStringObj(Tcl_DStringValue(&ds),
  1784         -                             Tcl_DStringLength(&ds));
  1785         -          Tcl_DStringFree(&ds);
  1786         -        }else{
  1787         -          apColName[i] = Tcl_NewStringObj(sqlite3_column_name(pStmt,i), -1);
  1788         -        }
  1789         -        Tcl_IncrRefCount(apColName[i]);
  1790         -      }
  1791         -      p->apColName = apColName;
  1792         -    }
  1793         -
  1794         -    /* If results are being stored in an array variable, then create
  1795         -    ** the array(*) entry for that array
  1796         -    */
  1797         -    if( p->pArray ){
  1798         -      Tcl_Interp *interp = p->pDb->interp;
  1799         -      Tcl_Obj *pColList = Tcl_NewObj();
  1800         -      Tcl_Obj *pStar = Tcl_NewStringObj("*", -1);
  1801         -
  1802         -      for(i=0; i<nCol; i++){
  1803         -        Tcl_ListObjAppendElement(interp, pColList, apColName[i]);
  1804         -      }
  1805         -      Tcl_IncrRefCount(pStar);
  1806         -      Tcl_ObjSetVar2(interp, p->pArray, pStar, pColList, 0);
  1807         -      Tcl_DecrRefCount(pStar);
  1808         -    }
  1809         -  }
  1810         -
  1811         -  if( papColName ){
  1812         -    *papColName = p->apColName;
  1813         -  }
  1814         -  if( pnCol ){
  1815         -    *pnCol = p->nCol;
  1816         -  }
  1817         -}
  1818         -
  1819         -/*
  1820         -** Return one of TCL_OK, TCL_BREAK or TCL_ERROR. If TCL_ERROR is
  1821         -** returned, then an error message is stored in the interpreter before
  1822         -** returning.
  1823         -**
  1824         -** A return value of TCL_OK means there is a row of data available. The
  1825         -** data may be accessed using dbEvalRowInfo() and dbEvalColumnValue(). This
  1826         -** is analogous to a return of SQLITE_ROW from sqlite3_step(). If TCL_BREAK
  1827         -** is returned, then the SQL script has finished executing and there are
  1828         -** no further rows available. This is similar to SQLITE_DONE.
  1829         -*/
  1830         -static int dbEvalStep(DbEvalContext *p){
  1831         -  const char *zPrevSql = 0;       /* Previous value of p->zSql */
  1832         -
  1833         -  while( p->zSql[0] || p->pPreStmt ){
  1834         -    int rc;
  1835         -    if( p->pPreStmt==0 ){
  1836         -      zPrevSql = (p->zSql==zPrevSql ? 0 : p->zSql);
  1837         -      rc = dbPrepareAndBind(p->pDb, p->zSql, &p->zSql, &p->pPreStmt);
  1838         -      if( rc!=TCL_OK ) return rc;
  1839         -    }else{
  1840         -      int rcs;
  1841         -      SqliteDb *pDb = p->pDb;
  1842         -      SqlPreparedStmt *pPreStmt = p->pPreStmt;
  1843         -      sqlite3_stmt *pStmt = pPreStmt->pStmt;
  1844         -
  1845         -      rcs = sqlite3_step(pStmt);
  1846         -      if( rcs==SQLITE_ROW ){
  1847         -        return TCL_OK;
  1848         -      }
  1849         -      if( p->pArray ){
  1850         -        dbEvalRowInfo(p, 0, 0);
  1851         -      }
  1852         -      rcs = sqlite3_reset(pStmt);
  1853         -
  1854         -      pDb->nStep = sqlite3_stmt_status(pStmt,SQLITE_STMTSTATUS_FULLSCAN_STEP,1);
  1855         -      pDb->nSort = sqlite3_stmt_status(pStmt,SQLITE_STMTSTATUS_SORT,1);
  1856         -      pDb->nIndex = sqlite3_stmt_status(pStmt,SQLITE_STMTSTATUS_AUTOINDEX,1);
  1857         -      pDb->nVMStep = sqlite3_stmt_status(pStmt,SQLITE_STMTSTATUS_VM_STEP,1);
  1858         -      dbReleaseColumnNames(p);
  1859         -      p->pPreStmt = 0;
  1860         -
  1861         -      if( rcs!=SQLITE_OK ){
  1862         -        /* If a run-time error occurs, report the error and stop reading
  1863         -        ** the SQL.  */
  1864         -        dbReleaseStmt(pDb, pPreStmt, 1);
  1865         -#if SQLITE_TEST
  1866         -        if( p->pDb->bLegacyPrepare && rcs==SQLITE_SCHEMA && zPrevSql ){
  1867         -          /* If the runtime error was an SQLITE_SCHEMA, and the database
  1868         -          ** handle is configured to use the legacy sqlite3_prepare()
  1869         -          ** interface, retry prepare()/step() on the same SQL statement.
  1870         -          ** This only happens once. If there is a second SQLITE_SCHEMA
  1871         -          ** error, the error will be returned to the caller. */
  1872         -          p->zSql = zPrevSql;
  1873         -          continue;
  1874         -        }
  1875         -#endif
  1876         -        Tcl_SetObjResult(pDb->interp,
  1877         -            Tcl_NewStringObj(SQLITEDB_ERRMSG(pDb), -1));
  1878         -        return TCL_ERROR;
  1879         -      }else{
  1880         -        dbReleaseStmt(pDb, pPreStmt, 0);
  1881         -      }
  1882         -    }
  1883         -  }
  1884         -
  1885         -  /* Finished */
  1886         -  return TCL_BREAK;
  1887         -}
  1888         -
  1889         -/*
  1890         -** Free all resources currently held by the DbEvalContext structure passed
  1891         -** as the first argument. There should be exactly one call to this function
  1892         -** for each call to dbEvalInit().
  1893         -*/
  1894         -static void dbEvalFinalize(DbEvalContext *p){
  1895         -  if( p->pPreStmt ){
  1896         -    sqlite3_reset(p->pPreStmt->pStmt);
  1897         -    dbReleaseStmt(p->pDb, p->pPreStmt, 0);
  1898         -    p->pPreStmt = 0;
  1899         -  }
  1900         -  if( p->pArray ){
  1901         -    Tcl_DecrRefCount(p->pArray);
  1902         -    p->pArray = 0;
  1903         -  }
  1904         -  Tcl_DStringFree(&p->dsSql);
  1905         -  Tcl_DecrRefCount(p->pSql);
  1906         -  dbReleaseColumnNames(p);
  1907         -}
  1908         -
  1909         -/*
  1910         -** Return a pointer to a Tcl_Obj structure with ref-count 0 that contains
  1911         -** the value for the iCol'th column of the row currently pointed to by
  1912         -** the DbEvalContext structure passed as the first argument.
  1913         -*/
  1914         -static Tcl_Obj *dbEvalColumnValue(DbEvalContext *p, int iCol){
  1915         -  sqlite3_stmt *pStmt = p->pPreStmt->pStmt;
  1916         -  switch( sqlite3_column_type(pStmt, iCol) ){
  1917         -    case SQLITE_BLOB: {
  1918         -      int bytes = sqlite3_column_bytes(pStmt, iCol);
  1919         -      const char *zBlob = sqlite3_column_blob(pStmt, iCol);
  1920         -      if( !zBlob ) bytes = 0;
  1921         -      return Tcl_NewByteArrayObj((u8*)zBlob, bytes);
  1922         -    }
  1923         -    case SQLITE_INTEGER: {
  1924         -      sqlite_int64 v = sqlite3_column_int64(pStmt, iCol);
  1925         -      if( v>=-2147483647 && v<=2147483647 ){
  1926         -        return Tcl_NewIntObj((int)v);
  1927         -      }else{
  1928         -        return Tcl_NewWideIntObj(v);
  1929         -      }
  1930         -    }
  1931         -    case SQLITE_FLOAT: {
  1932         -      return Tcl_NewDoubleObj(sqlite3_column_double(pStmt, iCol));
  1933         -    }
  1934         -    case SQLITE_NULL: {
  1935         -      return Tcl_NewStringObj(p->pDb->zNull, -1);
  1936         -    }
  1937         -  }
  1938         -  if( utf8Encoding!=NULL ){
  1939         -    Tcl_DString ds;
  1940         -    Tcl_Obj *obj;
  1941         -    Tcl_ExternalToUtfDString(utf8Encoding,
  1942         -        (char*)sqlite3_column_text(pStmt, iCol), -1, &ds);
  1943         -    obj = Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
  1944         -    Tcl_DStringFree(&ds);
  1945         -    return obj;
  1946         -  }
  1947         -  return Tcl_NewStringObj((char*)sqlite3_column_text(pStmt, iCol), -1);
  1948         -}
  1949         -
  1950         -/*
  1951         -** If using Tcl version 8.6 or greater, use the NR functions to avoid
  1952         -** recursive evalution of scripts by the [db eval] and [db trans]
  1953         -** commands. Even if the headers used while compiling the extension
  1954         -** are 8.6 or newer, the code still tests the Tcl version at runtime.
  1955         -** This allows stubs-enabled builds to be used with older Tcl libraries.
  1956         -*/
  1957         -#if TCL_MAJOR_VERSION>8 || (TCL_MAJOR_VERSION==8 && TCL_MINOR_VERSION>=6)
  1958         -# define SQLITE_TCL_NRE 1
  1959         -static int DbUseNre(void){
  1960         -  int major, minor;
  1961         -  Tcl_GetVersion(&major, &minor, 0, 0);
  1962         -  return( (major==8 && minor>=6) || major>8 );
  1963         -}
  1964         -#else
  1965         -/*
  1966         -** Compiling using headers earlier than 8.6. In this case NR cannot be
  1967         -** used, so DbUseNre() to always return zero. Add #defines for the other
  1968         -** Tcl_NRxxx() functions to prevent them from causing compilation errors,
  1969         -** even though the only invocations of them are within conditional blocks
  1970         -** of the form:
  1971         -**
  1972         -**   if( DbUseNre() ) { ... }
  1973         -*/
  1974         -# define SQLITE_TCL_NRE 0
  1975         -# define Tcl_NRAddCallback(a,b,c,d,e,f) (void)0
  1976         -# define Tcl_NREvalObj(a,b,c) 0
  1977         -# define Tcl_NRCreateCommand(a,b,c,d,e,f) (void)0
  1978         -#endif
  1979         -
  1980         -/*
  1981         -** This function is part of the implementation of the command:
  1982         -**
  1983         -**   $db eval SQL ?ARRAYNAME? SCRIPT
  1984         -*/
  1985         -static int SQLITE_TCLAPI DbEvalNextCmd(
  1986         -  ClientData data[],                   /* data[0] is the (DbEvalContext*) */
  1987         -  Tcl_Interp *interp,                  /* Tcl interpreter */
  1988         -  int result                           /* Result so far */
  1989         -){
  1990         -  int rc = result;                     /* Return code */
  1991         -
  1992         -  /* The first element of the data[] array is a pointer to a DbEvalContext
  1993         -  ** structure allocated using Tcl_Alloc(). The second element of data[]
  1994         -  ** is a pointer to a Tcl_Obj containing the script to run for each row
  1995         -  ** returned by the queries encapsulated in data[0]. */
  1996         -  DbEvalContext *p = (DbEvalContext *)data[0];
  1997         -  Tcl_Obj *pScript = (Tcl_Obj *)data[1];
  1998         -  Tcl_Obj *pArray = p->pArray;
  1999         -
  2000         -  while( (rc==TCL_OK || rc==TCL_CONTINUE) && TCL_OK==(rc = dbEvalStep(p)) ){
  2001         -    int i;
  2002         -    int nCol;
  2003         -    Tcl_Obj **apColName;
  2004         -    dbEvalRowInfo(p, &nCol, &apColName);
  2005         -    for(i=0; i<nCol; i++){
  2006         -      if( pArray==0 ){
  2007         -        Tcl_ObjSetVar2(interp, apColName[i], 0, dbEvalColumnValue(p,i), 0);
  2008         -      }else if( (p->evalFlags & SQLITE_EVAL_WITHOUTNULLS)!=0
  2009         -             && sqlite3_column_type(p->pPreStmt->pStmt, i)==SQLITE_NULL
  2010         -      ){
  2011         -        Tcl_UnsetVar2(interp, Tcl_GetString(pArray),
  2012         -                      Tcl_GetString(apColName[i]), 0);
  2013         -      }else{
  2014         -        Tcl_ObjSetVar2(interp, pArray, apColName[i], dbEvalColumnValue(p,i), 0);
  2015         -      }
  2016         -    }
  2017         -
  2018         -    /* The required interpreter variables are now populated with the data
  2019         -    ** from the current row. If using NRE, schedule callbacks to evaluate
  2020         -    ** script pScript, then to invoke this function again to fetch the next
  2021         -    ** row (or clean up if there is no next row or the script throws an
  2022         -    ** exception). After scheduling the callbacks, return control to the
  2023         -    ** caller.
  2024         -    **
  2025         -    ** If not using NRE, evaluate pScript directly and continue with the
  2026         -    ** next iteration of this while(...) loop.  */
  2027         -    if( DbUseNre() ){
  2028         -      Tcl_NRAddCallback(interp, DbEvalNextCmd, (void*)p, (void*)pScript, 0, 0);
  2029         -      return Tcl_NREvalObj(interp, pScript, 0);
  2030         -    }else{
  2031         -      rc = Tcl_EvalObjEx(interp, pScript, 0);
  2032         -    }
  2033         -  }
  2034         -
  2035         -  Tcl_DecrRefCount(pScript);
  2036         -  dbEvalFinalize(p);
  2037         -  Tcl_Free((char *)p);
  2038         -
  2039         -  if( rc==TCL_OK || rc==TCL_BREAK ){
  2040         -    Tcl_ResetResult(interp);
  2041         -    rc = TCL_OK;
  2042         -  }
  2043         -  return rc;
  2044         -}
  2045         -
  2046         -/*
  2047         -** This function is used by the implementations of the following database
  2048         -** handle sub-commands:
  2049         -**
  2050         -**   $db update_hook ?SCRIPT?
  2051         -**   $db wal_hook ?SCRIPT?
  2052         -**   $db commit_hook ?SCRIPT?
  2053         -**   $db preupdate hook ?SCRIPT?
  2054         -*/
  2055         -static void DbHookCmd(
  2056         -  Tcl_Interp *interp,             /* Tcl interpreter */
  2057         -  SqliteDb *pDb,                  /* Database handle */
  2058         -  Tcl_Obj *pArg,                  /* SCRIPT argument (or NULL) */
  2059         -  Tcl_Obj **ppHook                /* Pointer to member of SqliteDb */
  2060         -){
  2061         -  sqlite3 *db = pDb->db;
  2062         -
  2063         -  if( *ppHook ){
  2064         -    Tcl_SetObjResult(interp, *ppHook);
  2065         -    if( pArg ){
  2066         -      Tcl_DecrRefCount(*ppHook);
  2067         -      *ppHook = 0;
  2068         -    }
  2069         -  }
  2070         -  if( pArg ){
  2071         -    assert( !(*ppHook) );
  2072         -    if( Tcl_GetCharLength(pArg)>0 ){
  2073         -      *ppHook = pArg;
  2074         -      Tcl_IncrRefCount(*ppHook);
  2075         -    }
  2076         -  }
  2077         -
  2078         -#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
  2079         -  sqlite3_preupdate_hook(db, (pDb->pPreUpdateHook?DbPreUpdateHandler:0), pDb);
  2080         -#endif
  2081         -  sqlite3_update_hook(db, (pDb->pUpdateHook?DbUpdateHandler:0), pDb);
  2082         -  sqlite3_rollback_hook(db, (pDb->pRollbackHook?DbRollbackHandler:0), pDb);
  2083         -  sqlite3_wal_hook(db, (pDb->pWalHook?DbWalHandler:0), pDb);
  2084         -}
  2085         -
  2086         -/*
  2087         -** The "sqlite" command below creates a new Tcl command for each
  2088         -** connection it opens to an SQLite database.  This routine is invoked
  2089         -** whenever one of those connection-specific commands is executed
  2090         -** in Tcl.  For example, if you run Tcl code like this:
  2091         -**
  2092         -**       sqlite3 db1  "my_database"
  2093         -**       db1 close
  2094         -**
  2095         -** The first command opens a connection to the "my_database" database
  2096         -** and calls that connection "db1".  The second command causes this
  2097         -** subroutine to be invoked.
  2098         -*/
  2099         -static int SQLITE_TCLAPI DbObjCmd(
  2100         -  void *cd,
  2101         -  Tcl_Interp *interp,
  2102         -  int objc,
  2103         -  Tcl_Obj *const*objv
  2104         -){
  2105         -  SqliteDb *pDb = (SqliteDb*)cd;
  2106         -  int choice;
  2107         -  int rc = TCL_OK;
  2108         -  static const char *const DB_strs[] = {
  2109         -    "authorizer",             "backup",                "bind_fallback",
  2110         -    "busy",                   "cache",                 "changes",
  2111         -    "close",                  "collate",               "collation_needed",
  2112         -    "commit_hook",            "complete",              "copy",
  2113         -    "deserialize",            "enable_load_extension", "errorcode",
  2114         -    "eval",                   "exists",                "function",
  2115         -    "incrblob",               "interrupt",             "last_insert_rowid",
  2116         -    "nullvalue",              "onecolumn",             "preupdate",
  2117         -    "profile",                "progress",              "rekey",
  2118         -    "restore",                "rollback_hook",         "serialize",
  2119         -    "status",                 "timeout",               "total_changes",
  2120         -    "trace",                  "trace_v2",              "transaction",
  2121         -    "unlock_notify",          "update_hook",           "version",
  2122         -    "wal_hook",               0
  2123         -  };
  2124         -  enum DB_enum {
  2125         -    DB_AUTHORIZER,            DB_BACKUP,               DB_BIND_FALLBACK,
  2126         -    DB_BUSY,                  DB_CACHE,                DB_CHANGES,
  2127         -    DB_CLOSE,                 DB_COLLATE,              DB_COLLATION_NEEDED,
  2128         -    DB_COMMIT_HOOK,           DB_COMPLETE,             DB_COPY,
  2129         -    DB_DESERIALIZE,           DB_ENABLE_LOAD_EXTENSION,DB_ERRORCODE,
  2130         -    DB_EVAL,                  DB_EXISTS,               DB_FUNCTION,
  2131         -    DB_INCRBLOB,              DB_INTERRUPT,            DB_LAST_INSERT_ROWID,
  2132         -    DB_NULLVALUE,             DB_ONECOLUMN,            DB_PREUPDATE,
  2133         -    DB_PROFILE,               DB_PROGRESS,             DB_REKEY,
  2134         -    DB_RESTORE,               DB_ROLLBACK_HOOK,        DB_SERIALIZE,
  2135         -    DB_STATUS,                DB_TIMEOUT,              DB_TOTAL_CHANGES,
  2136         -    DB_TRACE,                 DB_TRACE_V2,             DB_TRANSACTION,
  2137         -    DB_UNLOCK_NOTIFY,         DB_UPDATE_HOOK,          DB_VERSION,
  2138         -    DB_WAL_HOOK
  2139         -  };
  2140         -  /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
  2141         -
  2142         -  if( objc<2 ){
  2143         -    Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ...");
  2144         -    return TCL_ERROR;
  2145         -  }
  2146         -  if( Tcl_GetIndexFromObjStruct(interp, objv[1], DB_strs, sizeof(char *), "option", 0, &choice) ){
  2147         -    return TCL_ERROR;
  2148         -  }
  2149         -
  2150         -  switch( (enum DB_enum)choice ){
  2151         -
  2152         -  /*    $db authorizer ?CALLBACK?
  2153         -  **
  2154         -  ** Invoke the given callback to authorize each SQL operation as it is
  2155         -  ** compiled.  5 arguments are appended to the callback before it is
  2156         -  ** invoked:
  2157         -  **
  2158         -  **   (1) The authorization type (ex: SQLITE_CREATE_TABLE, SQLITE_INSERT, ...)
  2159         -  **   (2) First descriptive name (depends on authorization type)
  2160         -  **   (3) Second descriptive name
  2161         -  **   (4) Name of the database (ex: "main", "temp")
  2162         -  **   (5) Name of trigger that is doing the access
  2163         -  **
  2164         -  ** The callback should return on of the following strings: SQLITE_OK,
  2165         -  ** SQLITE_IGNORE, or SQLITE_DENY.  Any other return value is an error.
  2166         -  **
  2167         -  ** If this method is invoked with no arguments, the current authorization
  2168         -  ** callback string is returned.
  2169         -  */
  2170         -  case DB_AUTHORIZER: {
  2171         -#ifdef SQLITE_OMIT_AUTHORIZATION
  2172         -    Tcl_AppendResult(interp, "authorization not available in this build",
  2173         -                     (char*)0);
  2174         -    return TCL_ERROR;
  2175         -#else
  2176         -    if( objc>3 ){
  2177         -      Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
  2178         -      return TCL_ERROR;
  2179         -    }else if( objc==2 ){
  2180         -      if( pDb->zAuth ){
  2181         -        Tcl_AppendResult(interp, pDb->zAuth, (char*)0);
  2182         -      }
  2183         -    }else{
  2184         -      char *zAuth;
  2185         -      int len;
  2186         -      if( pDb->zAuth ){
  2187         -        Tcl_Free(pDb->zAuth);
  2188         -      }
  2189         -      zAuth = Tcl_GetStringFromObj(objv[2], &len);
  2190         -      if( zAuth && len>0 ){
  2191         -        pDb->zAuth = Tcl_Alloc( len + 1 );
  2192         -        memcpy(pDb->zAuth, zAuth, len+1);
  2193         -      }else{
  2194         -        pDb->zAuth = 0;
  2195         -      }
  2196         -      if( pDb->zAuth ){
  2197         -        typedef int (*sqlite3_auth_cb)(
  2198         -           void*,int,const char*,const char*,
  2199         -           const char*,const char*);
  2200         -        pDb->interp = interp;
  2201         -        sqlite3_set_authorizer(pDb->db,(sqlite3_auth_cb)auth_callback,pDb);
  2202         -      }else{
  2203         -        sqlite3_set_authorizer(pDb->db, 0, 0);
  2204         -      }
  2205         -    }
  2206         -#endif
  2207         -    break;
  2208         -  }
  2209         -
  2210         -  /*    $db backup ?DATABASE? FILENAME
  2211         -  **
  2212         -  ** Open or create a database file named FILENAME.  Transfer the
  2213         -  ** content of local database DATABASE (default: "main") into the
  2214         -  ** FILENAME database.
  2215         -  */
  2216         -  case DB_BACKUP: {
  2217         -    const char *zDestFile;
  2218         -    const char *zSrcDb;
  2219         -    sqlite3 *pDest;
  2220         -    sqlite3_backup *pBackup;
  2221         -
  2222         -    if( objc==3 ){
  2223         -      zSrcDb = "main";
  2224         -      zDestFile = Tcl_GetString(objv[2]);
  2225         -    }else if( objc==4 ){
  2226         -      zSrcDb = Tcl_GetString(objv[2]);
  2227         -      zDestFile = Tcl_GetString(objv[3]);
  2228         -    }else{
  2229         -      Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? FILENAME");
  2230         -      return TCL_ERROR;
  2231         -    }
  2232         -    if( utf8Encoding!=NULL ){
  2233         -      Tcl_DString ds;
  2234         -      Tcl_UtfToExternalDString(utf8Encoding, zDestFile, -1, &ds);
  2235         -      rc = sqlite3_open_v2(Tcl_DStringValue(&ds), &pDest,
  2236         -               SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| pDb->openFlags, 0);
  2237         -      Tcl_DStringFree(&ds);
  2238         -    }else{
  2239         -      rc = sqlite3_open_v2(zDestFile, &pDest,
  2240         -               SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| pDb->openFlags, 0);
  2241         -    }
  2242         -    if( rc!=SQLITE_OK ){
  2243         -      if( utf8Encoding!=NULL ){
  2244         -        Tcl_DString ds;
  2245         -        Tcl_ExternalToUtfDString(utf8Encoding, sqlite3_errmsg(pDest), -1, &ds);
  2246         -        Tcl_AppendResult(interp, "cannot open target database: ",
  2247         -             Tcl_DStringValue(&ds), (char*)0);
  2248         -        Tcl_DStringFree(&ds);
  2249         -      }else{
  2250         -        Tcl_AppendResult(interp, "cannot open target database: ",
  2251         -             sqlite3_errmsg(pDest), (char*)0);
  2252         -      }
  2253         -      sqlite3_close(pDest);
  2254         -      return TCL_ERROR;
  2255         -    }
  2256         -    if( utf8Encoding!=NULL ){
  2257         -      Tcl_DString ds;
  2258         -      Tcl_UtfToExternalDString(utf8Encoding, zSrcDb, -1, &ds);
  2259         -      pBackup = sqlite3_backup_init(pDest, "main", pDb->db,
  2260         -                    Tcl_DStringValue(&ds));
  2261         -      Tcl_DStringFree(&ds);
  2262         -    }else{
  2263         -      pBackup = sqlite3_backup_init(pDest, "main", pDb->db, zSrcDb);
  2264         -    }
  2265         -    if( pBackup==0 ){
  2266         -      if( utf8Encoding!=NULL ){
  2267         -        Tcl_DString ds;
  2268         -        Tcl_ExternalToUtfDString(utf8Encoding, sqlite3_errmsg(pDest), -1, &ds);
  2269         -        Tcl_AppendResult(interp, "backup failed: ",
  2270         -             Tcl_DStringValue(&ds), (char*)0);
  2271         -        Tcl_DStringFree(&ds);
  2272         -      }else{
  2273         -        Tcl_AppendResult(interp, "backup failed: ",
  2274         -             sqlite3_errmsg(pDest), (char*)0);
  2275         -      }
  2276         -      sqlite3_close(pDest);
  2277         -      return TCL_ERROR;
  2278         -    }
  2279         -    while(  (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){}
  2280         -    sqlite3_backup_finish(pBackup);
  2281         -    if( rc==SQLITE_DONE ){
  2282         -      rc = TCL_OK;
  2283         -    }else{
  2284         -      if( utf8Encoding!=NULL ){
  2285         -        Tcl_DString ds;
  2286         -        Tcl_ExternalToUtfDString(utf8Encoding, sqlite3_errmsg(pDest), -1, &ds);
  2287         -        Tcl_AppendResult(interp, "backup failed: ",
  2288         -             Tcl_DStringValue(&ds), (char*)0);
  2289         -        Tcl_DStringFree(&ds);
  2290         -      }else{
  2291         -        Tcl_AppendResult(interp, "backup failed: ",
  2292         -             sqlite3_errmsg(pDest), (char*)0);
  2293         -      }
  2294         -      rc = TCL_ERROR;
  2295         -    }
  2296         -    sqlite3_close(pDest);
  2297         -    break;
  2298         -  }
  2299         -
  2300         -  /*    $db bind_fallback ?CALLBACK?
  2301         -  **
  2302         -  ** When resolving bind parameters in an SQL statement, if the parameter
  2303         -  ** cannot be associated with a TCL variable then invoke CALLBACK with a
  2304         -  ** single argument that is the name of the parameter and use the return
  2305         -  ** value of the CALLBACK as the binding.  If CALLBACK returns something
  2306         -  ** other than TCL_OK or TCL_ERROR then bind a NULL.
  2307         -  **
  2308         -  ** If CALLBACK is an empty string, then revert to the default behavior
  2309         -  ** which is to set the binding to NULL.
  2310         -  **
  2311         -  ** If CALLBACK returns an error, that causes the statement execution to
  2312         -  ** abort.  Hence, to configure a connection so that it throws an error
  2313         -  ** on an attempt to bind an unknown variable, do something like this:
  2314         -  **
  2315         -  **     proc bind_error {name} {error "no such variable: $name"}
  2316         -  **     db bind_fallback bind_error
  2317         -  */
  2318         -  case DB_BIND_FALLBACK: {
  2319         -    if( objc>3 ){
  2320         -      Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
  2321         -      return TCL_ERROR;
  2322         -    }else if( objc==2 ){
  2323         -      if( pDb->zBindFallback ){
  2324         -        Tcl_AppendResult(interp, pDb->zBindFallback, (char*)0);
  2325         -      }
  2326         -    }else{
  2327         -      char *zCallback;
  2328         -      int len;
  2329         -      if( pDb->zBindFallback ){
  2330         -        Tcl_Free(pDb->zBindFallback);
  2331         -      }
  2332         -      zCallback = Tcl_GetStringFromObj(objv[2], &len);
  2333         -      if( zCallback && len>0 ){
  2334         -        pDb->zBindFallback = Tcl_Alloc( len + 1 );
  2335         -        memcpy(pDb->zBindFallback, zCallback, len+1);
  2336         -      }else{
  2337         -        pDb->zBindFallback = 0;
  2338         -      }
  2339         -    }
  2340         -    break;
  2341         -  }
  2342         -
  2343         -  /*    $db busy ?CALLBACK?
  2344         -  **
  2345         -  ** Invoke the given callback if an SQL statement attempts to open
  2346         -  ** a locked database file.
  2347         -  */
  2348         -  case DB_BUSY: {
  2349         -    if( objc>3 ){
  2350         -      Tcl_WrongNumArgs(interp, 2, objv, "CALLBACK");
  2351         -      return TCL_ERROR;
  2352         -    }else if( objc==2 ){
  2353         -      if( pDb->zBusy ){
  2354         -        Tcl_AppendResult(interp, pDb->zBusy, (char*)0);
  2355         -      }
  2356         -    }else{
  2357         -      char *zBusy;
  2358         -      int len;
  2359         -      if( pDb->zBusy ){
  2360         -        Tcl_Free(pDb->zBusy);
  2361         -      }
  2362         -      zBusy = Tcl_GetStringFromObj(objv[2], &len);
  2363         -      if( zBusy && len>0 ){
  2364         -        pDb->zBusy = Tcl_Alloc( len + 1 );
  2365         -        memcpy(pDb->zBusy, zBusy, len+1);
  2366         -      }else{
  2367         -        pDb->zBusy = 0;
  2368         -      }
  2369         -      if( pDb->zBusy ){
  2370         -        pDb->interp = interp;
  2371         -        sqlite3_busy_handler(pDb->db, DbBusyHandler, pDb);
  2372         -      }else{
  2373         -        sqlite3_busy_handler(pDb->db, 0, 0);
  2374         -      }
  2375         -    }
  2376         -    break;
  2377         -  }
  2378         -
  2379         -  /*     $db cache flush
  2380         -  **     $db cache size n
  2381         -  **
  2382         -  ** Flush the prepared statement cache, or set the maximum number of
  2383         -  ** cached statements.
  2384         -  */
  2385         -  case DB_CACHE: {
  2386         -    char *subCmd;
  2387         -    int n;
  2388         -
  2389         -    if( objc<=2 ){
  2390         -      Tcl_WrongNumArgs(interp, 1, objv, "cache option ?arg?");
  2391         -      return TCL_ERROR;
  2392         -    }
  2393         -    subCmd = Tcl_GetString( objv[2] );
  2394         -    if( *subCmd=='f' && strcmp(subCmd,"flush")==0 ){
  2395         -      if( objc!=3 ){
  2396         -        Tcl_WrongNumArgs(interp, 2, objv, "flush");
  2397         -        return TCL_ERROR;
  2398         -      }else{
  2399         -        flushStmtCache( pDb );
  2400         -      }
  2401         -    }else if( *subCmd=='s' && strcmp(subCmd,"size")==0 ){
  2402         -      if( objc!=4 ){
  2403         -        Tcl_WrongNumArgs(interp, 2, objv, "size n");
  2404         -        return TCL_ERROR;
  2405         -      }else{
  2406         -        if( TCL_ERROR==Tcl_GetIntFromObj(interp, objv[3], &n) ){
  2407         -          Tcl_AppendResult( interp, "cannot convert \"",
  2408         -               Tcl_GetString(objv[3]), "\" to integer", (char*)0);
  2409         -          return TCL_ERROR;
  2410         -        }else{
  2411         -          if( n<0 ){
  2412         -            flushStmtCache( pDb );
  2413         -            n = 0;
  2414         -          }else if( n>MAX_PREPARED_STMTS ){
  2415         -            n = MAX_PREPARED_STMTS;
  2416         -          }
  2417         -          pDb->maxStmt = n;
  2418         -        }
  2419         -      }
  2420         -    }else{
  2421         -      Tcl_AppendResult( interp, "bad option \"",
  2422         -          Tcl_GetString(objv[2]), "\": must be flush or size",
  2423         -          (char*)0);
  2424         -      return TCL_ERROR;
  2425         -    }
  2426         -    break;
  2427         -  }
  2428         -
  2429         -  /*     $db changes
  2430         -  **
  2431         -  ** Return the number of rows that were modified, inserted, or deleted by
  2432         -  ** the most recent INSERT, UPDATE or DELETE statement, not including
  2433         -  ** any changes made by trigger programs.
  2434         -  */
  2435         -  case DB_CHANGES: {
  2436         -    Tcl_Obj *pResult;
  2437         -    if( objc!=2 ){
  2438         -      Tcl_WrongNumArgs(interp, 2, objv, "");
  2439         -      return TCL_ERROR;
  2440         -    }
  2441         -    pResult = Tcl_GetObjResult(interp);
  2442         -    Tcl_SetWideIntObj(pResult, sqlite3_changes(pDb->db));
  2443         -    break;
  2444         -  }
  2445         -
  2446         -  /*    $db close
  2447         -  **
  2448         -  ** Shutdown the database
  2449         -  */
  2450         -  case DB_CLOSE: {
  2451         -    Tcl_DeleteCommand(interp, Tcl_GetString(objv[0]));
  2452         -    break;
  2453         -  }
  2454         -
  2455         -  /*
  2456         -  **     $db collate NAME SCRIPT
  2457         -  **
  2458         -  ** Create a new SQL collation function called NAME.  Whenever
  2459         -  ** that function is called, invoke SCRIPT to evaluate the function.
  2460         -  */
  2461         -  case DB_COLLATE: {
  2462         -    SqlCollate *pCollate;
  2463         -    char *zName;
  2464         -    char *zScript;
  2465         -    int nScript;
  2466         -    Tcl_DString ds;
  2467         -    if( objc!=4 ){
  2468         -      Tcl_WrongNumArgs(interp, 2, objv, "NAME SCRIPT");
  2469         -      return TCL_ERROR;
  2470         -    }
  2471         -    zName = Tcl_GetString(objv[2]);
  2472         -    if( utf8Encoding!=NULL ){
  2473         -      Tcl_UtfToExternalDString(utf8Encoding, zName, -1, &ds);
  2474         -      zName = Tcl_DStringValue(&ds);
  2475         -    }else{
  2476         -      Tcl_DStringInit(&ds);
  2477         -    }
  2478         -    zScript = Tcl_GetStringFromObj(objv[3], &nScript);
  2479         -    pCollate = (SqlCollate*)Tcl_Alloc( sizeof(*pCollate) + nScript + 1 );
  2480         -    if( pCollate==0 ) return TCL_ERROR;
  2481         -    pCollate->interp = interp;
  2482         -    pCollate->pNext = pDb->pCollate;
  2483         -    pCollate->zScript = (char*)&pCollate[1];
  2484         -    pDb->pCollate = pCollate;
  2485         -    memcpy(pCollate->zScript, zScript, nScript+1);
  2486         -    if( sqlite3_create_collation_v2(pDb->db, zName, SQLITE_UTF8,
  2487         -        pCollate, tclSqlCollate, 0) ){
  2488         -      Tcl_DStringFree(&ds);
  2489         -      Tcl_AppendResult(interp, (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
  2490         -      return TCL_ERROR;
  2491         -    }
  2492         -    Tcl_DStringFree(&ds);
  2493         -    break;
  2494         -  }
  2495         -
  2496         -  /*
  2497         -  **     $db collation_needed SCRIPT
  2498         -  **
  2499         -  ** Create a new SQL collation function called NAME.  Whenever
  2500         -  ** that function is called, invoke SCRIPT to evaluate the function.
  2501         -  */
  2502         -  case DB_COLLATION_NEEDED: {
  2503         -    if( objc!=3 ){
  2504         -      Tcl_WrongNumArgs(interp, 2, objv, "SCRIPT");
  2505         -      return TCL_ERROR;
  2506         -    }
  2507         -    if( pDb->pCollateNeeded ){
  2508         -      Tcl_DecrRefCount(pDb->pCollateNeeded);
  2509         -    }
  2510         -    pDb->pCollateNeeded = Tcl_DuplicateObj(objv[2]);
  2511         -    Tcl_IncrRefCount(pDb->pCollateNeeded);
  2512         -    sqlite3_collation_needed(pDb->db, pDb, tclCollateNeeded);
  2513         -    break;
  2514         -  }
  2515         -
  2516         -  /*    $db commit_hook ?CALLBACK?
  2517         -  **
  2518         -  ** Invoke the given callback just before committing every SQL transaction.
  2519         -  ** If the callback throws an exception or returns non-zero, then the
  2520         -  ** transaction is aborted.  If CALLBACK is an empty string, the callback
  2521         -  ** is disabled.
  2522         -  */
  2523         -  case DB_COMMIT_HOOK: {
  2524         -    if( objc>3 ){
  2525         -      Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
  2526         -      return TCL_ERROR;
  2527         -    }else if( objc==2 ){
  2528         -      if( pDb->zCommit ){
  2529         -        Tcl_AppendResult(interp, pDb->zCommit, (char*)0);
  2530         -      }
  2531         -    }else{
  2532         -      const char *zCommit;
  2533         -      int len;
  2534         -      if( pDb->zCommit ){
  2535         -        Tcl_Free(pDb->zCommit);
  2536         -      }
  2537         -      zCommit = Tcl_GetStringFromObj(objv[2], &len);
  2538         -      if( zCommit && len>0 ){
  2539         -        pDb->zCommit = Tcl_Alloc( len + 1 );
  2540         -        memcpy(pDb->zCommit, zCommit, len+1);
  2541         -      }else{
  2542         -        pDb->zCommit = 0;
  2543         -      }
  2544         -      if( pDb->zCommit ){
  2545         -        pDb->interp = interp;
  2546         -        sqlite3_commit_hook(pDb->db, DbCommitHandler, pDb);
  2547         -      }else{
  2548         -        sqlite3_commit_hook(pDb->db, 0, 0);
  2549         -      }
  2550         -    }
  2551         -    break;
  2552         -  }
  2553         -
  2554         -  /*    $db complete SQL
  2555         -  **
  2556         -  ** Return TRUE if SQL is a complete SQL statement.  Return FALSE if
  2557         -  ** additional lines of input are needed.  This is similar to the
  2558         -  ** built-in "info complete" command of Tcl.
  2559         -  */
  2560         -  case DB_COMPLETE: {
  2561         -#ifndef SQLITE_OMIT_COMPLETE
  2562         -    Tcl_Obj *pResult;
  2563         -    int isComplete;
  2564         -    if( objc!=3 ){
  2565         -      Tcl_WrongNumArgs(interp, 2, objv, "SQL");
  2566         -      return TCL_ERROR;
  2567         -    }
  2568         -    isComplete = sqlite3_complete( Tcl_GetString(objv[2]) );
  2569         -    pResult = Tcl_GetObjResult(interp);
  2570         -    Tcl_SetBooleanObj(pResult, isComplete);
  2571         -#endif
  2572         -    break;
  2573         -  }
  2574         -
  2575         -  /*    $db copy conflict-algorithm table filename ?SEPARATOR? ?NULLINDICATOR?
  2576         -  **
  2577         -  ** Copy data into table from filename, optionally using SEPARATOR
  2578         -  ** as column separators.  If a column contains a null string, or the
  2579         -  ** value of NULLINDICATOR, a NULL is inserted for the column.
  2580         -  ** conflict-algorithm is one of the sqlite conflict algorithms:
  2581         -  **    rollback, abort, fail, ignore, replace
  2582         -  ** On success, return the number of lines processed, not necessarily same
  2583         -  ** as 'db changes' due to conflict-algorithm selected.
  2584         -  **
  2585         -  ** This code is basically an implementation/enhancement of
  2586         -  ** the sqlite3 shell.c ".import" command.
  2587         -  **
  2588         -  ** This command usage is equivalent to the sqlite2.x COPY statement,
  2589         -  ** which imports file data into a table using the PostgreSQL COPY file format:
  2590         -  **   $db copy $conflit_algo $table_name $filename \t \\N
  2591         -  */
  2592         -  case DB_COPY: {
  2593         -    char *zTable;               /* Insert data into this table */
  2594         -    char *zFile;                /* The file from which to extract data */
  2595         -    char *zConflict;            /* The conflict algorithm to use */
  2596         -    sqlite3_stmt *pStmt;        /* A statement */
  2597         -    int nCol;                   /* Number of columns in the table */
  2598         -    int nByte;                  /* Number of bytes in an SQL string */
  2599         -    int i, j;                   /* Loop counters */
  2600         -    int nSep;                   /* Number of bytes in zSep[] */
  2601         -    int nNull;                  /* Number of bytes in zNull[] */
  2602         -    char *zSql;                 /* An SQL statement */
  2603         -    char *zLine;                /* A single line of input from the file */
  2604         -    char **azCol;               /* zLine[] broken up into columns */
  2605         -    const char *zCommit;        /* How to commit changes */
  2606         -    Tcl_Channel in;             /* The input file */
  2607         -    int lineno = 0;             /* Line number of input file */
  2608         -    char zLineNum[80];          /* Line number print buffer */
  2609         -    Tcl_DString str;
  2610         -    Tcl_Obj *pResult;           /* interp result */
  2611         -
  2612         -    const char *zSep;
  2613         -    const char *zNull;
  2614         -    if( objc<5 || objc>7 ){
  2615         -      Tcl_WrongNumArgs(interp, 2, objv,
  2616         -         "CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?");
  2617         -      return TCL_ERROR;
  2618         -    }
  2619         -    if( objc>=6 ){
  2620         -      zSep = Tcl_GetString(objv[5]);
  2621         -    }else{
  2622         -      zSep = "\t";
  2623         -    }
  2624         -    if( objc>=7 ){
  2625         -      zNull = Tcl_GetString(objv[6]);
  2626         -    }else{
  2627         -      zNull = "";
  2628         -    }
  2629         -    zConflict = Tcl_GetString(objv[2]);
  2630         -    zTable = Tcl_GetString(objv[3]);
  2631         -    zFile = Tcl_GetString(objv[4]);
  2632         -    nSep = strlen30(zSep);
  2633         -    nNull = strlen30(zNull);
  2634         -    if( nSep==0 ){
  2635         -      Tcl_AppendResult(interp,"Error: non-null separator required for copy",
  2636         -                       (char*)0);
  2637         -      return TCL_ERROR;
  2638         -    }
  2639         -    if(strcmp(zConflict, "rollback") != 0 &&
  2640         -       strcmp(zConflict, "abort"   ) != 0 &&
  2641         -       strcmp(zConflict, "fail"    ) != 0 &&
  2642         -       strcmp(zConflict, "ignore"  ) != 0 &&
  2643         -       strcmp(zConflict, "replace" ) != 0 ) {
  2644         -      Tcl_AppendResult(interp, "Error: \"", zConflict,
  2645         -            "\", conflict-algorithm must be one of: rollback, "
  2646         -            "abort, fail, ignore, or replace", (char*)0);
  2647         -      return TCL_ERROR;
  2648         -    }
  2649         -    if( utf8Encoding!=NULL ){
  2650         -      Tcl_DString ds;
  2651         -      Tcl_UtfToExternalDString(utf8Encoding, zTable, -1, &ds);
  2652         -      zSql = sqlite3_mprintf("SELECT * FROM '%q'", Tcl_DStringValue(&ds));
  2653         -      Tcl_DStringFree(&ds);
  2654         -    }else{
  2655         -      zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable);
  2656         -    }
  2657         -    if( zSql==0 ){
  2658         -      Tcl_AppendResult(interp, "Error: no such table: ", zTable, (char*)0);
  2659         -      return TCL_ERROR;
  2660         -    }
  2661         -    nByte = strlen30(zSql);
  2662         -    rc = sqlite3_prepare(pDb->db, zSql, -1, &pStmt, 0);
  2663         -    sqlite3_free(zSql);
  2664         -    if( rc ){
  2665         -      Tcl_AppendResult(interp, "Error: ", (char*)SQLITEDB_ERRMSG(pDb),
  2666         -          (char*)0);
  2667         -      nCol = 0;
  2668         -    }else{
  2669         -      nCol = sqlite3_column_count(pStmt);
  2670         -    }
  2671         -    sqlite3_finalize(pStmt);
  2672         -    if( nCol==0 ) {
  2673         -      return TCL_ERROR;
  2674         -    }
  2675         -    zSql = sqlite3_malloc( nByte + 50 + nCol*2 );
  2676         -    if( zSql==0 ) {
  2677         -      Tcl_AppendResult(interp, "Error: can't malloc()", (char*)0);
  2678         -      return TCL_ERROR;
  2679         -    }
  2680         -    if( utf8Encoding!=NULL ){
  2681         -      Tcl_DString ds;
  2682         -      Tcl_UtfToExternalDString(utf8Encoding, zTable, -1, &ds);
  2683         -      sqlite3_snprintf(nByte+50, zSql, "INSERT OR %q INTO '%q' VALUES(?",
  2684         -                       zConflict, Tcl_DStringValue(&ds));
  2685         -      Tcl_DStringFree(&ds);
  2686         -    }else{
  2687         -      sqlite3_snprintf(nByte+50, zSql, "INSERT OR %q INTO '%q' VALUES(?",
  2688         -                       zConflict, zTable);
  2689         -    }
  2690         -    j = strlen30(zSql);
  2691         -    for(i=1; i<nCol; i++){
  2692         -      zSql[j++] = ',';
  2693         -      zSql[j++] = '?';
  2694         -    }
  2695         -    zSql[j++] = ')';
  2696         -    zSql[j] = 0;
  2697         -    rc = sqlite3_prepare(pDb->db, zSql, -1, &pStmt, 0);
  2698         -    sqlite3_free(zSql);
  2699         -    if( rc ){
  2700         -      Tcl_AppendResult(interp, "Error: ", (char*)SQLITEDB_ERRMSG(pDb),
  2701         -          (char*)0);
  2702         -      sqlite3_finalize(pStmt);
  2703         -      return TCL_ERROR;
  2704         -    }
  2705         -    in = Tcl_OpenFileChannel(interp, zFile, "r", 0666);
  2706         -    if( in==0 ){
  2707         -      sqlite3_finalize(pStmt);
  2708         -      return TCL_ERROR;
  2709         -    }
  2710         -    azCol = sqlite3_malloc( sizeof(azCol[0])*(nCol+1) );
  2711         -    if( azCol==0 ) {
  2712         -      Tcl_AppendResult(interp, "Error: can't malloc()", (char*)0);
  2713         -      Tcl_Close(interp, in);
  2714         -      return TCL_ERROR;
  2715         -    }
  2716         -    Tcl_DStringInit(&str);
  2717         -    (void)sqlite3_exec(pDb->db, "BEGIN", 0, 0, 0);
  2718         -    zCommit = "COMMIT";
  2719         -    while( (size_t)Tcl_Gets(in, &str)!=(size_t)-1 ) {
  2720         -      char *z;
  2721         -      lineno++;
  2722         -      zLine = Tcl_DStringValue(&str);
  2723         -      azCol[0] = zLine;
  2724         -      for(i=0, z=zLine; *z; z++){
  2725         -        if( *z==zSep[0] && strncmp(z, zSep, nSep)==0 ){
  2726         -          *z = 0;
  2727         -          i++;
  2728         -          if( i<nCol ){
  2729         -            azCol[i] = &z[nSep];
  2730         -            z += nSep-1;
  2731         -          }
  2732         -        }
  2733         -      }
  2734         -      if( i+1!=nCol ){
  2735         -        char *zErr;
  2736         -        int nErr = strlen30(zFile) + 200;
  2737         -        zErr = sqlite3_malloc(nErr);
  2738         -        if( zErr ){
  2739         -          sqlite3_snprintf(nErr, zErr,
  2740         -             "Error: %s line %d: expected %d columns of data but found %d",
  2741         -             zFile, lineno, nCol, i+1);
  2742         -          Tcl_AppendResult(interp, zErr, (char*)0);
  2743         -          sqlite3_free(zErr);
  2744         -        }
  2745         -        zCommit = "ROLLBACK";
  2746         -        break;
  2747         -      }
  2748         -      for(i=0; i<nCol; i++){
  2749         -        /* check for null data, if so, bind as null */
  2750         -        if( (azCol[i][0]==0) || (nNull>0 && strcmp(azCol[i], zNull)==0)
  2751         -        ){
  2752         -          sqlite3_bind_null(pStmt, i+1);
  2753         -        }else if( utf8Encoding!=NULL ){
  2754         -          Tcl_DString ds;
  2755         -          Tcl_UtfToExternalDString(utf8Encoding, azCol[i], -1, &ds);
  2756         -          sqlite3_bind_text(pStmt, i+1, Tcl_DStringValue(&ds),
  2757         -              Tcl_DStringLength(&ds), SQLITE_TRANSIENT);
  2758         -          Tcl_DStringFree(&ds);
  2759         -        }else{
  2760         -          sqlite3_bind_text(pStmt, i+1, azCol[i], strlen30(azCol[i]),
  2761         -              SQLITE_STATIC);
  2762         -        }
  2763         -      }
  2764         -      sqlite3_step(pStmt);
  2765         -      rc = sqlite3_reset(pStmt);
  2766         -      Tcl_DStringSetLength(&str, 0);
  2767         -      if( rc!=SQLITE_OK ){
  2768         -        Tcl_AppendResult(interp,"Error: ", (char*)SQLITEDB_ERRMSG(pDb),
  2769         -            (char*)0);
  2770         -        zCommit = "ROLLBACK";
  2771         -        break;
  2772         -      }
  2773         -    }
  2774         -    Tcl_DStringFree(&str);
  2775         -    sqlite3_free(azCol);
  2776         -    Tcl_Close(interp, in);
  2777         -    sqlite3_finalize(pStmt);
  2778         -    (void)sqlite3_exec(pDb->db, zCommit, 0, 0, 0);
  2779         -
  2780         -    if( zCommit[0] == 'C' ){
  2781         -      /* success, set result as number of lines processed */
  2782         -      pResult = Tcl_GetObjResult(interp);
  2783         -      Tcl_SetWideIntObj(pResult, lineno);
  2784         -      rc = TCL_OK;
  2785         -    }else{
  2786         -      /* failure, append lineno where failed */
  2787         -      sqlite3_snprintf(sizeof(zLineNum), zLineNum,"%d",lineno);
  2788         -      Tcl_AppendResult(interp,", failed while processing line: ",zLineNum,
  2789         -                       (char*)0);
  2790         -      rc = TCL_ERROR;
  2791         -    }
  2792         -    break;
  2793         -  }
  2794         -
  2795         -  /*
  2796         -  **     $db deserialize ?-maxsize N? ?-readonly BOOL? ?DATABASE? VALUE
  2797         -  **
  2798         -  ** Reopen DATABASE (default "main") using the content in $VALUE
  2799         -  */
  2800         -  case DB_DESERIALIZE: {
  2801         -#ifndef SQLITE_ENABLE_DESERIALIZE
  2802         -    Tcl_AppendResult(interp, "MEMDB not available in this build",
  2803         -                     (char*)0);
  2804         -    rc = TCL_ERROR;
  2805         -#else
  2806         -    const char *zSchema = 0;
  2807         -    Tcl_Obj *pValue = 0;
  2808         -    unsigned char *pBA;
  2809         -    unsigned char *pData;
  2810         -    int len, xrc;
  2811         -    sqlite3_int64 mxSize = 0;
  2812         -    int i;
  2813         -    int isReadonly = 0;
  2814         -
  2815         -
  2816         -    if( objc<3 ){
  2817         -      Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? VALUE");
  2818         -      rc = TCL_ERROR;
  2819         -      break;
  2820         -    }
  2821         -    for(i=2; i<objc-1; i++){
  2822         -      const char *z = Tcl_GetString(objv[i]);
  2823         -      if( strcmp(z,"-maxsize")==0 && i<objc-2 ){
  2824         -        rc = Tcl_GetWideIntFromObj(interp, objv[++i], &mxSize);
  2825         -        if( rc ) goto deserialize_error;
  2826         -        continue;
  2827         -      }
  2828         -      if( strcmp(z,"-readonly")==0 && i<objc-2 ){
  2829         -        rc = Tcl_GetBooleanFromObj(interp, objv[++i], &isReadonly);
  2830         -        if( rc ) goto deserialize_error;
  2831         -        continue;
  2832         -      }
  2833         -      if( zSchema==0 && i==objc-2 && z[0]!='-' ){
  2834         -        zSchema = z;
  2835         -        continue;
  2836         -      }
  2837         -      Tcl_AppendResult(interp, "unknown option: ", z, (char*)0);
  2838         -      rc = TCL_ERROR;
  2839         -      goto deserialize_error;
  2840         -    }
  2841         -    pValue = objv[objc-1];
  2842         -    pBA = Tcl_GetByteArrayFromObj(pValue, &len);
  2843         -    pData = sqlite3_malloc( len );
  2844         -    if( pData==0 && len>0 ){
  2845         -      Tcl_AppendResult(interp, "out of memory", (char*)0);
  2846         -      rc = TCL_ERROR;
  2847         -    }else{
  2848         -      int flags;
  2849         -      if( len>0 ) memcpy(pData, pBA, len);
  2850         -      if( isReadonly ){
  2851         -        flags = SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_READONLY;
  2852         -      }else{
  2853         -        flags = SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_RESIZEABLE;
  2854         -      }
  2855         -      if( utf8Encoding!=NULL ){
  2856         -        Tcl_DString ds;
  2857         -        Tcl_ExternalToUtfDString(utf8Encoding, (char*)zSchema, -1, &ds);
  2858         -        xrc = sqlite3_deserialize(pDb->db, Tcl_DStringValue(&ds),
  2859         -                  pData, len, len, flags);
  2860         -        Tcl_DStringFree(&ds);
  2861         -      } else {
  2862         -        xrc = sqlite3_deserialize(pDb->db, zSchema, pData, len, len, flags);
  2863         -      }
  2864         -      if( xrc ){
  2865         -        Tcl_AppendResult(interp, "unable to set MEMDB content", (char*)0);
  2866         -        rc = TCL_ERROR;
  2867         -      }
  2868         -      if( mxSize>0 ){
  2869         -        sqlite3_file_control(pDb->db, zSchema,SQLITE_FCNTL_SIZE_LIMIT,&mxSize);
  2870         -      }
  2871         -    }
  2872         -deserialize_error:
  2873         -#endif
  2874         -    break;
  2875         -  }
  2876         -
  2877         -  /*
  2878         -  **    $db enable_load_extension BOOLEAN
  2879         -  **
  2880         -  ** Turn the extension loading feature on or off.  It if off by
  2881         -  ** default.
  2882         -  */
  2883         -  case DB_ENABLE_LOAD_EXTENSION: {
  2884         -#ifndef SQLITE_OMIT_LOAD_EXTENSION
  2885         -    int onoff;
  2886         -    if( objc!=3 ){
  2887         -      Tcl_WrongNumArgs(interp, 2, objv, "BOOLEAN");
  2888         -      return TCL_ERROR;
  2889         -    }
  2890         -    if( Tcl_GetBooleanFromObj(interp, objv[2], &onoff) ){
  2891         -      return TCL_ERROR;
  2892         -    }
  2893         -    sqlite3_enable_load_extension(pDb->db, onoff);
  2894         -    break;
  2895         -#else
  2896         -    Tcl_AppendResult(interp, "extension loading is turned off at compile-time",
  2897         -                     (char*)0);
  2898         -    return TCL_ERROR;
  2899         -#endif
  2900         -  }
  2901         -
  2902         -  /*
  2903         -  **    $db errorcode
  2904         -  **
  2905         -  ** Return the numeric error code that was returned by the most recent
  2906         -  ** call to sqlite3_exec().
  2907         -  */
  2908         -  case DB_ERRORCODE: {
  2909         -    Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_errcode(pDb->db)));
  2910         -    break;
  2911         -  }
  2912         -
  2913         -  /*
  2914         -  **    $db exists $sql
  2915         -  **    $db onecolumn $sql
  2916         -  **
  2917         -  ** The onecolumn method is the equivalent of:
  2918         -  **     lindex [$db eval $sql] 0
  2919         -  */
  2920         -  case DB_EXISTS:
  2921         -  case DB_ONECOLUMN: {
  2922         -    Tcl_Obj *pResult = 0;
  2923         -    DbEvalContext sEval;
  2924         -    if( objc!=3 ){
  2925         -      Tcl_WrongNumArgs(interp, 2, objv, "SQL");
  2926         -      return TCL_ERROR;
  2927         -    }
  2928         -
  2929         -    dbEvalInit(&sEval, pDb, objv[2], 0, 0);
  2930         -    rc = dbEvalStep(&sEval);
  2931         -    if( choice==DB_ONECOLUMN ){
  2932         -      if( rc==TCL_OK ){
  2933         -        pResult = dbEvalColumnValue(&sEval, 0);
  2934         -      }else if( rc==TCL_BREAK ){
  2935         -        Tcl_ResetResult(interp);
  2936         -      }
  2937         -    }else if( rc==TCL_BREAK || rc==TCL_OK ){
  2938         -      pResult = Tcl_NewBooleanObj(rc==TCL_OK);
  2939         -    }
  2940         -    dbEvalFinalize(&sEval);
  2941         -    if( pResult ) Tcl_SetObjResult(interp, pResult);
  2942         -
  2943         -    if( rc==TCL_BREAK ){
  2944         -      rc = TCL_OK;
  2945         -    }
  2946         -    break;
  2947         -  }
  2948         -
  2949         -  /*
  2950         -  **    $db eval ?options? $sql ?array? ?{  ...code... }?
  2951         -  **
  2952         -  ** The SQL statement in $sql is evaluated.  For each row, the values are
  2953         -  ** placed in elements of the array named "array" and ...code... is executed.
  2954         -  ** If "array" and "code" are omitted, then no callback is every invoked.
  2955         -  ** If "array" is an empty string, then the values are placed in variables
  2956         -  ** that have the same name as the fields extracted by the query.
  2957         -  */
  2958         -  case DB_EVAL: {
  2959         -    int evalFlags = 0;
  2960         -    const char *zOpt;
  2961         -    while( objc>3 && (zOpt = Tcl_GetString(objv[2]))!=0 && zOpt[0]=='-' ){
  2962         -      if( strcmp(zOpt, "-withoutnulls")==0 ){
  2963         -        evalFlags |= SQLITE_EVAL_WITHOUTNULLS;
  2964         -      }
  2965         -      else{
  2966         -        Tcl_AppendResult(interp, "unknown option: \"", zOpt, "\"", (void*)0);
  2967         -        return TCL_ERROR;
  2968         -      }
  2969         -      objc--;
  2970         -      objv++;
  2971         -    }
  2972         -    if( objc<3 || objc>5 ){
  2973         -      Tcl_WrongNumArgs(interp, 2, objv,
  2974         -          "?OPTIONS? SQL ?ARRAY-NAME? ?SCRIPT?");
  2975         -      return TCL_ERROR;
  2976         -    }
  2977         -
  2978         -    if( objc==3 ){
  2979         -      DbEvalContext sEval;
  2980         -      Tcl_Obj *pRet = Tcl_NewObj();
  2981         -      Tcl_IncrRefCount(pRet);
  2982         -      dbEvalInit(&sEval, pDb, objv[2], 0, 0);
  2983         -      while( TCL_OK==(rc = dbEvalStep(&sEval)) ){
  2984         -        int i;
  2985         -        int nCol;
  2986         -        dbEvalRowInfo(&sEval, &nCol, 0);
  2987         -        for(i=0; i<nCol; i++){
  2988         -          Tcl_ListObjAppendElement(interp, pRet, dbEvalColumnValue(&sEval, i));
  2989         -        }
  2990         -      }
  2991         -      dbEvalFinalize(&sEval);
  2992         -      if( rc==TCL_BREAK ){
  2993         -        Tcl_SetObjResult(interp, pRet);
  2994         -        rc = TCL_OK;
  2995         -      }
  2996         -      Tcl_DecrRefCount(pRet);
  2997         -    }else{
  2998         -      ClientData cd2[2];
  2999         -      DbEvalContext *p;
  3000         -      Tcl_Obj *pArray = 0;
  3001         -      Tcl_Obj *pScript;
  3002         -
  3003         -      if( objc>=5 && *(char *)Tcl_GetString(objv[3]) ){
  3004         -        pArray = objv[3];
  3005         -      }
  3006         -      pScript = objv[objc-1];
  3007         -      Tcl_IncrRefCount(pScript);
  3008         -
  3009         -      p = (DbEvalContext *)Tcl_Alloc(sizeof(DbEvalContext));
  3010         -      dbEvalInit(p, pDb, objv[2], pArray, evalFlags);
  3011         -
  3012         -      cd2[0] = (void *)p;
  3013         -      cd2[1] = (void *)pScript;
  3014         -      rc = DbEvalNextCmd(cd2, interp, TCL_OK);
  3015         -    }
  3016         -    break;
  3017         -  }
  3018         -
  3019         -  /*
  3020         -  **     $db function NAME [-argcount N] [-deterministic] SCRIPT
  3021         -  **
  3022         -  ** Create a new SQL function called NAME.  Whenever that function is
  3023         -  ** called, invoke SCRIPT to evaluate the function.
  3024         -  */
  3025         -  case DB_FUNCTION: {
  3026         -    int flags = SQLITE_UTF8;
  3027         -    SqlFunc *pFunc;
  3028         -    Tcl_Obj *pScript;
  3029         -    char *zName;
  3030         -    int nArg = -1;
  3031         -    int i;
  3032         -    int eType = SQLITE_NULL;
  3033         -    Tcl_DString ds;
  3034         -    if( objc<4 ){
  3035         -      Tcl_WrongNumArgs(interp, 2, objv, "NAME ?SWITCHES? SCRIPT");
  3036         -      return TCL_ERROR;
  3037         -    }
  3038         -    for(i=3; i<(objc-1); i++){
  3039         -      const char *z = Tcl_GetString(objv[i]);
  3040         -      int n = strlen30(z);
  3041         -      if( n>1 && strncmp(z, "-argcount",n)==0 ){
  3042         -        if( i==(objc-2) ){
  3043         -          Tcl_AppendResult(interp, "option requires an argument: ", z,(char*)0);
  3044         -          return TCL_ERROR;
  3045         -        }
  3046         -        if( Tcl_GetIntFromObj(interp, objv[i+1], &nArg) ) return TCL_ERROR;
  3047         -        if( nArg<0 ){
  3048         -          Tcl_AppendResult(interp, "number of arguments must be non-negative",
  3049         -                           (char*)0);
  3050         -          return TCL_ERROR;
  3051         -        }
  3052         -        i++;
  3053         -      }else
  3054         -      if( n>1 && strncmp(z, "-deterministic",n)==0 ){
  3055         -        flags |= SQLITE_DETERMINISTIC;
  3056         -      }else
  3057         -      if( n>1 && strncmp(z, "-returntype", n)==0 ){
  3058         -        const char *const azType[] = {"integer", "real", "text", "blob", "any", 0};
  3059         -        assert( SQLITE_INTEGER==1 && SQLITE_FLOAT==2 && SQLITE_TEXT==3 );
  3060         -        assert( SQLITE_BLOB==4 && SQLITE_NULL==5 );
  3061         -        if( i==(objc-2) ){
  3062         -          Tcl_AppendResult(interp, "option requires an argument: ", z,(char*)0);
  3063         -          return TCL_ERROR;
  3064         -        }
  3065         -        i++;
  3066         -        if( Tcl_GetIndexFromObjStruct(interp, objv[i], azType, sizeof(char*), "type", 0, &eType) ){
  3067         -          return TCL_ERROR;
  3068         -        }
  3069         -        eType++;
  3070         -      }else{
  3071         -        Tcl_AppendResult(interp, "bad option \"", z,
  3072         -            "\": must be -argcount, -deterministic or -returntype", (char*)0
  3073         -        );
  3074         -        return TCL_ERROR;
  3075         -      }
  3076         -    }
  3077         -
  3078         -    pScript = objv[objc-1];
  3079         -    zName = Tcl_GetString(objv[2]);
  3080         -    if( utf8Encoding!=NULL ){
  3081         -      Tcl_UtfToExternalDString(utf8Encoding, zName, -1, &ds);
  3082         -      zName = Tcl_DStringValue(&ds);
  3083         -    }else{
  3084         -      Tcl_DStringInit(&ds);
  3085         -    }
  3086         -    pFunc = findSqlFunc(pDb, zName);
  3087         -    if( pFunc==0 ) return TCL_ERROR;
  3088         -    if( pFunc->pScript ){
  3089         -      Tcl_DecrRefCount(pFunc->pScript);
  3090         -    }
  3091         -    pFunc->pScript = pScript;
  3092         -    Tcl_IncrRefCount(pScript);
  3093         -    pFunc->useEvalObjv = safeToUseEvalObjv(interp, pScript);
  3094         -    pFunc->eType = eType;
  3095         -    rc = sqlite3_create_function_v2(pDb->db, zName, nArg, flags,
  3096         -        pFunc, tclSqlFunc, 0, 0, 0);
  3097         -    Tcl_DStringFree(&ds);
  3098         -    if( rc!=SQLITE_OK ){
  3099         -      rc = TCL_ERROR;
  3100         -      Tcl_AppendResult(interp, (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
  3101         -    }
  3102         -    break;
  3103         -  }
  3104         -
  3105         -  /*
  3106         -  **     $db incrblob ?-readonly? ?DB? TABLE COLUMN ROWID
  3107         -  */
  3108         -  case DB_INCRBLOB: {
  3109         -#ifdef SQLITE_OMIT_INCRBLOB
  3110         -    Tcl_AppendResult(interp, "incrblob not available in this build", (char*)0);
  3111         -    return TCL_ERROR;
  3112         -#else
  3113         -    int isReadonly = 0;
  3114         -    const char *zDb = "main";
  3115         -    const char *zTable;
  3116         -    const char *zColumn;
  3117         -    Tcl_WideInt iRow;
  3118         -
  3119         -    /* Check for the -readonly option */
  3120         -    if( objc>3 && strcmp(Tcl_GetString(objv[2]), "-readonly")==0 ){
  3121         -      isReadonly = 1;
  3122         -    }
  3123         -
  3124         -    if( objc!=(5+isReadonly) && objc!=(6+isReadonly) ){
  3125         -      Tcl_WrongNumArgs(interp, 2, objv, "?-readonly? ?DB? TABLE COLUMN ROWID");
  3126         -      return TCL_ERROR;
  3127         -    }
  3128         -
  3129         -    if( objc==(6+isReadonly) ){
  3130         -      zDb = Tcl_GetString(objv[2]);
  3131         -    }
  3132         -    zTable = Tcl_GetString(objv[objc-3]);
  3133         -    zColumn = Tcl_GetString(objv[objc-2]);
  3134         -    rc = Tcl_GetWideIntFromObj(interp, objv[objc-1], &iRow);
  3135         -
  3136         -    if( rc==TCL_OK ){
  3137         -      if( utf8Encoding!=NULL ){
  3138         -        Tcl_DString ds1, ds2, ds3;
  3139         -        Tcl_UtfToExternalDString(utf8Encoding, zDb, -1, &ds1);
  3140         -        Tcl_UtfToExternalDString(utf8Encoding, zTable, -1, &ds2);
  3141         -        Tcl_UtfToExternalDString(utf8Encoding, zColumn, -1, &ds3);
  3142         -        rc = createIncrblobChannel(
  3143         -            interp, pDb, Tcl_DStringValue(&ds1), Tcl_DStringValue(&ds2),
  3144         -            Tcl_DStringValue(&ds3), (sqlite3_int64)iRow, isReadonly
  3145         -        );
  3146         -        Tcl_DStringFree(&ds1);
  3147         -        Tcl_DStringFree(&ds2);
  3148         -        Tcl_DStringFree(&ds3);
  3149         -      }else{
  3150         -        rc = createIncrblobChannel(
  3151         -            interp, pDb, zDb, zTable, zColumn, (sqlite3_int64)iRow, isReadonly
  3152         -        );
  3153         -      }
  3154         -    }
  3155         -#endif
  3156         -    break;
  3157         -  }
  3158         -
  3159         -  /*
  3160         -  **     $db interrupt
  3161         -  **
  3162         -  ** Interrupt the execution of the inner-most SQL interpreter.  This
  3163         -  ** causes the SQL statement to return an error of SQLITE_INTERRUPT.
  3164         -  */
  3165         -  case DB_INTERRUPT: {
  3166         -    sqlite3_interrupt(pDb->db);
  3167         -    break;
  3168         -  }
  3169         -
  3170         -  /*
  3171         -  **     $db nullvalue ?STRING?
  3172         -  **
  3173         -  ** Change text used when a NULL comes back from the database. If ?STRING?
  3174         -  ** is not present, then the current string used for NULL is returned.
  3175         -  ** If STRING is present, then STRING is returned.
  3176         -  **
  3177         -  */
  3178         -  case DB_NULLVALUE: {
  3179         -    if( objc!=2 && objc!=3 ){
  3180         -      Tcl_WrongNumArgs(interp, 2, objv, "NULLVALUE");
  3181         -      return TCL_ERROR;
  3182         -    }
  3183         -    if( objc==3 ){
  3184         -      int len;
  3185         -      char *zNull = Tcl_GetStringFromObj(objv[2], &len);
  3186         -      if( pDb->zNull ){
  3187         -        Tcl_Free(pDb->zNull);
  3188         -      }
  3189         -      if( zNull && len>0 ){
  3190         -        pDb->zNull = Tcl_Alloc( len + 1 );
  3191         -        memcpy(pDb->zNull, zNull, len);
  3192         -        pDb->zNull[len] = '\0';
  3193         -      }else{
  3194         -        pDb->zNull = 0;
  3195         -      }
  3196         -    }
  3197         -    Tcl_SetObjResult(interp, Tcl_NewStringObj(pDb->zNull, -1));
  3198         -    break;
  3199         -  }
  3200         -
  3201         -  /*
  3202         -  **     $db last_insert_rowid
  3203         -  **
  3204         -  ** Return an integer which is the ROWID for the most recent insert.
  3205         -  */
  3206         -  case DB_LAST_INSERT_ROWID: {
  3207         -    Tcl_Obj *pResult;
  3208         -    Tcl_WideInt rowid;
  3209         -    if( objc!=2 ){
  3210         -      Tcl_WrongNumArgs(interp, 2, objv, "");
  3211         -      return TCL_ERROR;
  3212         -    }
  3213         -    rowid = sqlite3_last_insert_rowid(pDb->db);
  3214         -    pResult = Tcl_GetObjResult(interp);
  3215         -    Tcl_SetWideIntObj(pResult, rowid);
  3216         -    break;
  3217         -  }
  3218         -
  3219         -  /*
  3220         -  ** The DB_ONECOLUMN method is implemented together with DB_EXISTS.
  3221         -  */
  3222         -
  3223         -  /*    $db progress ?N CALLBACK?
  3224         -  **
  3225         -  ** Invoke the given callback every N virtual machine opcodes while executing
  3226         -  ** queries.
  3227         -  */
  3228         -  case DB_PROGRESS: {
  3229         -    if( objc==2 ){
  3230         -      if( pDb->zProgress ){
  3231         -        Tcl_AppendResult(interp, pDb->zProgress, (char*)0);
  3232         -      }
  3233         -    }else if( objc==4 ){
  3234         -      char *zProgress;
  3235         -      int len;
  3236         -      int N;
  3237         -      if( TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &N) ){
  3238         -        return TCL_ERROR;
  3239         -      };
  3240         -      if( pDb->zProgress ){
  3241         -        Tcl_Free(pDb->zProgress);
  3242         -      }
  3243         -      zProgress = Tcl_GetStringFromObj(objv[3], &len);
  3244         -      if( zProgress && len>0 ){
  3245         -        pDb->zProgress = Tcl_Alloc( len + 1 );
  3246         -        memcpy(pDb->zProgress, zProgress, len+1);
  3247         -      }else{
  3248         -        pDb->zProgress = 0;
  3249         -      }
  3250         -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  3251         -      if( pDb->zProgress ){
  3252         -        pDb->interp = interp;
  3253         -        sqlite3_progress_handler(pDb->db, N, DbProgressHandler, pDb);
  3254         -      }else{
  3255         -        sqlite3_progress_handler(pDb->db, 0, 0, 0);
  3256         -      }
  3257         -#endif
  3258         -    }else{
  3259         -      Tcl_WrongNumArgs(interp, 2, objv, "N CALLBACK");
  3260         -      return TCL_ERROR;
  3261         -    }
  3262         -    break;
  3263         -  }
  3264         -
  3265         -  /*    $db profile ?CALLBACK?
  3266         -  **
  3267         -  ** Make arrangements to invoke the CALLBACK routine after each SQL statement
  3268         -  ** that has run.  The text of the SQL and the amount of elapse time are
  3269         -  ** appended to CALLBACK before the script is run.
  3270         -  */
  3271         -  case DB_PROFILE: {
  3272         -    if( objc>3 ){
  3273         -      Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
  3274         -      return TCL_ERROR;
  3275         -    }else if( objc==2 ){
  3276         -      if( pDb->zProfile ){
  3277         -        Tcl_AppendResult(interp, pDb->zProfile, (char*)0);
  3278         -      }
  3279         -    }else{
  3280         -      char *zProfile;
  3281         -      int len;
  3282         -      if( pDb->zProfile ){
  3283         -        Tcl_Free(pDb->zProfile);
  3284         -      }
  3285         -      zProfile = Tcl_GetStringFromObj(objv[2], &len);
  3286         -      if( zProfile && len>0 ){
  3287         -        pDb->zProfile = Tcl_Alloc( len + 1 );
  3288         -        memcpy(pDb->zProfile, zProfile, len+1);
  3289         -      }else{
  3290         -        pDb->zProfile = 0;
  3291         -      }
  3292         -#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
  3293         -      if( pDb->zProfile ){
  3294         -        pDb->interp = interp;
  3295         -        sqlite3_trace_v2(pDb->db, SQLITE_TRACE_PROFILE, DbProfileHandler, pDb);
  3296         -      }else{
  3297         -        sqlite3_trace_v2(pDb->db, 0, 0, 0);
  3298         -      }
  3299         -#endif
  3300         -    }
  3301         -    break;
  3302         -  }
  3303         -
  3304         -  /*
  3305         -  **     $db rekey KEY
  3306         -  **
  3307         -  ** Change the encryption key on the currently open database.
  3308         -  */
  3309         -  case DB_REKEY: {
  3310         -#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  3311         -    int nKey;
  3312         -    void *pKey;
  3313         -#endif
  3314         -    if( objc!=3 ){
  3315         -      Tcl_WrongNumArgs(interp, 2, objv, "KEY");
  3316         -      return TCL_ERROR;
  3317         -    }
  3318         -#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  3319         -    pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey);
  3320         -    rc = sqlite3_rekey(pDb->db, pKey, nKey);
  3321         -    if( rc ){
  3322         -      if( utf8Encoding!=NULL){
  3323         -        Tcl_DString ds;
  3324         -        Tcl_ExternalToUtfDString(utf8Encoding, sqlite3_errstr(rc), -1, &ds);
  3325         -        Tcl_AppendResult(interp, Tcl_DStringValue(&ds), (char*)0);
  3326         -        Tcl_DStringFree(&ds);
  3327         -      }else{
  3328         -        Tcl_AppendResult(interp, sqlite3_errstr(rc), (char*)0);
  3329         -      }
  3330         -      rc = TCL_ERROR;
  3331         -    }
  3332         -#endif
  3333         -    break;
  3334         -  }
  3335         -
  3336         -  /*    $db restore ?DATABASE? FILENAME
  3337         -  **
  3338         -  ** Open a database file named FILENAME.  Transfer the content
  3339         -  ** of FILENAME into the local database DATABASE (default: "main").
  3340         -  */
  3341         -  case DB_RESTORE: {
  3342         -    const char *zSrcFile;
  3343         -    const char *zDestDb;
  3344         -    sqlite3 *pSrc;
  3345         -    sqlite3_backup *pBackup;
  3346         -    int nTimeout = 0;
  3347         -
  3348         -    if( objc==3 ){
  3349         -      zDestDb = "main";
  3350         -      zSrcFile = Tcl_GetString(objv[2]);
  3351         -    }else if( objc==4 ){
  3352         -      zDestDb = Tcl_GetString(objv[2]);
  3353         -      zSrcFile = Tcl_GetString(objv[3]);
  3354         -    }else{
  3355         -      Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? FILENAME");
  3356         -      return TCL_ERROR;
  3357         -    }
  3358         -    if( utf8Encoding!=NULL ){
  3359         -      Tcl_DString ds;
  3360         -      Tcl_UtfToExternalDString(utf8Encoding, zSrcFile, -1, &ds);
  3361         -      rc = sqlite3_open_v2(Tcl_DStringValue(&ds), &pSrc,
  3362         -               SQLITE_OPEN_READONLY | pDb->openFlags, 0);
  3363         -      Tcl_DStringFree(&ds);
  3364         -    }else{
  3365         -      rc = sqlite3_open_v2(zSrcFile, &pSrc,
  3366         -                           SQLITE_OPEN_READONLY | pDb->openFlags, 0);
  3367         -    }
  3368         -    if( rc!=SQLITE_OK ){
  3369         -      if( utf8Encoding!=NULL ){
  3370         -        Tcl_DString ds;
  3371         -        Tcl_ExternalToUtfDString(utf8Encoding, sqlite3_errmsg(pSrc), -1, &ds);
  3372         -        Tcl_AppendResult(interp, "cannot open source database: ",
  3373         -             Tcl_DStringValue(&ds), (char*)0);
  3374         -        Tcl_DStringFree(&ds);
  3375         -      }else{
  3376         -        Tcl_AppendResult(interp, "cannot open source database: ",
  3377         -             sqlite3_errmsg(pSrc), (char*)0);
  3378         -      }
  3379         -      sqlite3_close(pSrc);
  3380         -      return TCL_ERROR;
  3381         -    }
  3382         -    if( utf8Encoding!=NULL ){
  3383         -      Tcl_DString ds;
  3384         -      Tcl_UtfToExternalDString(utf8Encoding, zDestDb, -1, &ds);
  3385         -      pBackup = sqlite3_backup_init(pDb->db, Tcl_DStringValue(&ds), pSrc,
  3386         -                    "main");
  3387         -      Tcl_DStringFree(&ds);
  3388         -    }else{
  3389         -      pBackup = sqlite3_backup_init(pDb->db, zDestDb, pSrc, "main");
  3390         -    }
  3391         -    if( pBackup==0 ){
  3392         -      Tcl_AppendResult(interp, "restore failed: ",
  3393         -          (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
  3394         -      sqlite3_close(pSrc);
  3395         -      return TCL_ERROR;
  3396         -    }
  3397         -    while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK
  3398         -              || rc==SQLITE_BUSY ){
  3399         -      if( rc==SQLITE_BUSY ){
  3400         -        if( nTimeout++ >= 3 ) break;
  3401         -        sqlite3_sleep(100);
  3402         -      }
  3403         -    }
  3404         -    sqlite3_backup_finish(pBackup);
  3405         -    if( rc==SQLITE_DONE ){
  3406         -      rc = TCL_OK;
  3407         -    }else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){
  3408         -      Tcl_AppendResult(interp, "restore failed: source database busy",
  3409         -                       (char*)0);
  3410         -      rc = TCL_ERROR;
  3411         -    }else{
  3412         -      Tcl_AppendResult(interp, "restore failed: ",
  3413         -          (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
  3414         -      rc = TCL_ERROR;
  3415         -    }
  3416         -    sqlite3_close(pSrc);
  3417         -    break;
  3418         -  }
  3419         -
  3420         -  /*
  3421         -  **     $db serialize ?DATABASE?
  3422         -  **
  3423         -  ** Return a serialization of a database.
  3424         -  */
  3425         -  case DB_SERIALIZE: {
  3426         -#ifndef SQLITE_ENABLE_DESERIALIZE
  3427         -    Tcl_AppendResult(interp, "MEMDB not available in this build",
  3428         -                     (char*)0);
  3429         -    rc = TCL_ERROR;
  3430         -#else
  3431         -    const char *zSchema = objc>=3 ? Tcl_GetString(objv[2]) : "main";
  3432         -    sqlite3_int64 sz = 0;
  3433         -    unsigned char *pData;
  3434         -    if( objc!=2 && objc!=3 ){
  3435         -      Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE?");
  3436         -      rc = TCL_ERROR;
  3437         -    }else{
  3438         -      int needFree;
  3439         -      if( utf8Encoding!=NULL ){
  3440         -        Tcl_DString ds;
  3441         -        Tcl_ExternalToUtfDString(utf8Encoding, (char*)zSchema, -1, &ds);
  3442         -        pData = sqlite3_serialize(pDb->db, Tcl_DStringValue(&ds), &sz,
  3443         -                    SQLITE_SERIALIZE_NOCOPY);
  3444         -        Tcl_DStringFree(&ds);
  3445         -      } else {
  3446         -        pData = sqlite3_serialize(pDb->db, zSchema, &sz,
  3447         -                    SQLITE_SERIALIZE_NOCOPY);
  3448         -      }
  3449         -      if( pData ){
  3450         -        needFree = 0;
  3451         -      }else{
  3452         -        pData = sqlite3_serialize(pDb->db, zSchema, &sz, 0);
  3453         -        needFree = 1;
  3454         -      }
  3455         -      Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pData,sz));
  3456         -      if( needFree ) sqlite3_free(pData);
  3457         -    }
  3458         -#endif
  3459         -    break;
  3460         -  }
  3461         -
  3462         -  /*
  3463         -  **     $db status (step|sort|autoindex|vmstep)
  3464         -  **
  3465         -  ** Display SQLITE_STMTSTATUS_FULLSCAN_STEP or
  3466         -  ** SQLITE_STMTSTATUS_SORT for the most recent eval.
  3467         -  */
  3468         -  case DB_STATUS: {
  3469         -    int v;
  3470         -    const char *zOp;
  3471         -    if( objc!=3 ){
  3472         -      Tcl_WrongNumArgs(interp, 2, objv, "(step|sort|autoindex)");
  3473         -      return TCL_ERROR;
  3474         -    }
  3475         -    zOp = Tcl_GetString(objv[2]);
  3476         -    if( strcmp(zOp, "step")==0 ){
  3477         -      v = pDb->nStep;
  3478         -    }else if( strcmp(zOp, "sort")==0 ){
  3479         -      v = pDb->nSort;
  3480         -    }else if( strcmp(zOp, "autoindex")==0 ){
  3481         -      v = pDb->nIndex;
  3482         -    }else if( strcmp(zOp, "vmstep")==0 ){
  3483         -      v = pDb->nVMStep;
  3484         -    }else{
  3485         -      Tcl_AppendResult(interp,
  3486         -            "bad argument: should be autoindex, step, sort or vmstep",
  3487         -            (char*)0);
  3488         -      return TCL_ERROR;
  3489         -    }
  3490         -    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(v));
  3491         -    break;
  3492         -  }
  3493         -
  3494         -  /*
  3495         -  **     $db timeout MILLESECONDS
  3496         -  **
  3497         -  ** Delay for the number of milliseconds specified when a file is locked.
  3498         -  */
  3499         -  case DB_TIMEOUT: {
  3500         -    int ms;
  3501         -    if( objc!=3 ){
  3502         -      Tcl_WrongNumArgs(interp, 2, objv, "MILLISECONDS");
  3503         -      return TCL_ERROR;
  3504         -    }
  3505         -    if( Tcl_GetIntFromObj(interp, objv[2], &ms) ) return TCL_ERROR;
  3506         -    sqlite3_busy_timeout(pDb->db, ms);
  3507         -    break;
  3508         -  }
  3509         -
  3510         -  /*
  3511         -  **     $db total_changes
  3512         -  **
  3513         -  ** Return the number of rows that were modified, inserted, or deleted
  3514         -  ** since the database handle was created.
  3515         -  */
  3516         -  case DB_TOTAL_CHANGES: {
  3517         -    Tcl_Obj *pResult;
  3518         -    if( objc!=2 ){
  3519         -      Tcl_WrongNumArgs(interp, 2, objv, "");
  3520         -      return TCL_ERROR;
  3521         -    }
  3522         -    pResult = Tcl_GetObjResult(interp);
  3523         -    Tcl_SetWideIntObj(pResult, sqlite3_total_changes(pDb->db));
  3524         -    break;
  3525         -  }
  3526         -
  3527         -  /*    $db trace ?CALLBACK?
  3528         -  **
  3529         -  ** Make arrangements to invoke the CALLBACK routine for each SQL statement
  3530         -  ** that is executed.  The text of the SQL is appended to CALLBACK before
  3531         -  ** it is executed.
  3532         -  */
  3533         -  case DB_TRACE: {
  3534         -    if( objc>3 ){
  3535         -      Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
  3536         -      return TCL_ERROR;
  3537         -    }else if( objc==2 ){
  3538         -      if( pDb->zTrace ){
  3539         -        Tcl_AppendResult(interp, pDb->zTrace, (char*)0);
  3540         -      }
  3541         -    }else{
  3542         -      char *zTrace;
  3543         -      int len;
  3544         -      if( pDb->zTrace ){
  3545         -        Tcl_Free(pDb->zTrace);
  3546         -      }
  3547         -      zTrace = Tcl_GetStringFromObj(objv[2], &len);
  3548         -      if( zTrace && len>0 ){
  3549         -        pDb->zTrace = Tcl_Alloc( len + 1 );
  3550         -        memcpy(pDb->zTrace, zTrace, len+1);
  3551         -      }else{
  3552         -        pDb->zTrace = 0;
  3553         -      }
  3554         -#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
  3555         -      if( pDb->zTrace ){
  3556         -        pDb->interp = interp;
  3557         -        sqlite3_trace_v2(pDb->db, SQLITE_TRACE_STMT, DbTraceHandler, pDb);
  3558         -      }else{
  3559         -        sqlite3_trace_v2(pDb->db, 0, 0, 0);
  3560         -      }
  3561         -#endif
  3562         -    }
  3563         -    break;
  3564         -  }
  3565         -
  3566         -  /*    $db trace_v2 ?CALLBACK? ?MASK?
  3567         -  **
  3568         -  ** Make arrangements to invoke the CALLBACK routine for each trace event
  3569         -  ** matching the mask that is generated.  The parameters are appended to
  3570         -  ** CALLBACK before it is executed.
  3571         -  */
  3572         -  case DB_TRACE_V2: {
  3573         -    if( objc>4 ){
  3574         -      Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK? ?MASK?");
  3575         -      return TCL_ERROR;
  3576         -    }else if( objc==2 ){
  3577         -      if( pDb->zTraceV2 ){
  3578         -        Tcl_AppendResult(interp, pDb->zTraceV2, (char*)0);
  3579         -      }
  3580         -    }else{
  3581         -      char *zTraceV2;
  3582         -      int len;
  3583         -      Tcl_WideInt wMask = 0;
  3584         -      if( objc==4 ){
  3585         -        static const char *const TTYPE_strs[] = {
  3586         -          "statement", "profile", "row", "close", 0
  3587         -        };
  3588         -        enum TTYPE_enum {
  3589         -          TTYPE_STMT, TTYPE_PROFILE, TTYPE_ROW, TTYPE_CLOSE
  3590         -        };
  3591         -        int i;
  3592         -        if( TCL_OK!=Tcl_ListObjLength(interp, objv[3], &len) ){
  3593         -          return TCL_ERROR;
  3594         -        }
  3595         -        for(i=0; i<len; i++){
  3596         -          Tcl_Obj *pObj;
  3597         -          int ttype;
  3598         -          if( TCL_OK!=Tcl_ListObjIndex(interp, objv[3], i, &pObj) ){
  3599         -            return TCL_ERROR;
  3600         -          }
  3601         -          if( Tcl_GetIndexFromObjStruct(interp, pObj, TTYPE_strs, sizeof(char *), "trace type",
  3602         -                                  0, &ttype)!=TCL_OK ){
  3603         -            Tcl_WideInt wType;
  3604         -            Tcl_Obj *pError = Tcl_DuplicateObj(Tcl_GetObjResult(interp));
  3605         -            Tcl_IncrRefCount(pError);
  3606         -            if( TCL_OK==Tcl_GetWideIntFromObj(interp, pObj, &wType) ){
  3607         -              Tcl_DecrRefCount(pError);
  3608         -              wMask |= wType;
  3609         -            }else{
  3610         -              Tcl_SetObjResult(interp, pError);
  3611         -              Tcl_DecrRefCount(pError);
  3612         -              return TCL_ERROR;
  3613         -            }
  3614         -          }else{
  3615         -            switch( (enum TTYPE_enum)ttype ){
  3616         -              case TTYPE_STMT:    wMask |= SQLITE_TRACE_STMT;    break;
  3617         -              case TTYPE_PROFILE: wMask |= SQLITE_TRACE_PROFILE; break;
  3618         -              case TTYPE_ROW:     wMask |= SQLITE_TRACE_ROW;     break;
  3619         -              case TTYPE_CLOSE:   wMask |= SQLITE_TRACE_CLOSE;   break;
  3620         -            }
  3621         -          }
  3622         -        }
  3623         -      }else{
  3624         -        wMask = SQLITE_TRACE_STMT; /* use the "legacy" default */
  3625         -      }
  3626         -      if( pDb->zTraceV2 ){
  3627         -        Tcl_Free(pDb->zTraceV2);
  3628         -      }
  3629         -      zTraceV2 = Tcl_GetStringFromObj(objv[2], &len);
  3630         -      if( zTraceV2 && len>0 ){
  3631         -        pDb->zTraceV2 = Tcl_Alloc( len + 1 );
  3632         -        memcpy(pDb->zTraceV2, zTraceV2, len+1);
  3633         -      }else{
  3634         -        pDb->zTraceV2 = 0;
  3635         -      }
  3636         -#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
  3637         -      if( pDb->zTraceV2 ){
  3638         -        pDb->interp = interp;
  3639         -        sqlite3_trace_v2(pDb->db, (unsigned)wMask, DbTraceV2Handler, pDb);
  3640         -      }else{
  3641         -        sqlite3_trace_v2(pDb->db, 0, 0, 0);
  3642         -      }
  3643         -#endif
  3644         -    }
  3645         -    break;
  3646         -  }
  3647         -
  3648         -  /*    $db transaction [-deferred|-immediate|-exclusive] SCRIPT
  3649         -  **
  3650         -  ** Start a new transaction (if we are not already in the midst of a
  3651         -  ** transaction) and execute the TCL script SCRIPT.  After SCRIPT
  3652         -  ** completes, either commit the transaction or roll it back if SCRIPT
  3653         -  ** throws an exception.  Or if no new transation was started, do nothing.
  3654         -  ** pass the exception on up the stack.
  3655         -  **
  3656         -  ** This command was inspired by Dave Thomas's talk on Ruby at the
  3657         -  ** 2005 O'Reilly Open Source Convention (OSCON).
  3658         -  */
  3659         -  case DB_TRANSACTION: {
  3660         -    Tcl_Obj *pScript;
  3661         -    const char *zBegin = "SAVEPOINT _tcl_transaction";
  3662         -    if( objc!=3 && objc!=4 ){
  3663         -      Tcl_WrongNumArgs(interp, 2, objv, "[TYPE] SCRIPT");
  3664         -      return TCL_ERROR;
  3665         -    }
  3666         -
  3667         -    if( pDb->nTransaction==0 && objc==4 ){
  3668         -      static const char *const TTYPE_strs[] = {
  3669         -        "deferred",   "exclusive",  "immediate", 0
  3670         -      };
  3671         -      enum TTYPE_enum {
  3672         -        TTYPE_DEFERRED, TTYPE_EXCLUSIVE, TTYPE_IMMEDIATE
  3673         -      };
  3674         -      int ttype;
  3675         -      if( Tcl_GetIndexFromObjStruct(interp, objv[2], TTYPE_strs, sizeof(char *), "transaction type",
  3676         -                              0, &ttype) ){
  3677         -        return TCL_ERROR;
  3678         -      }
  3679         -      switch( (enum TTYPE_enum)ttype ){
  3680         -        case TTYPE_DEFERRED:    /* no-op */;                 break;
  3681         -        case TTYPE_EXCLUSIVE:   zBegin = "BEGIN EXCLUSIVE";  break;
  3682         -        case TTYPE_IMMEDIATE:   zBegin = "BEGIN IMMEDIATE";  break;
  3683         -      }
  3684         -    }
  3685         -    pScript = objv[objc-1];
  3686         -
  3687         -    /* Run the SQLite BEGIN command to open a transaction or savepoint. */
  3688         -    pDb->disableAuth++;
  3689         -    rc = sqlite3_exec(pDb->db, zBegin, 0, 0, 0);
  3690         -    pDb->disableAuth--;
  3691         -    if( rc!=SQLITE_OK ){
  3692         -      Tcl_AppendResult(interp, (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
  3693         -      return TCL_ERROR;
  3694         -    }
  3695         -    pDb->nTransaction++;
  3696         -
  3697         -    /* If using NRE, schedule a callback to invoke the script pScript, then
  3698         -    ** a second callback to commit (or rollback) the transaction or savepoint
  3699         -    ** opened above. If not using NRE, evaluate the script directly, then
  3700         -    ** call function DbTransPostCmd() to commit (or rollback) the transaction
  3701         -    ** or savepoint.  */
  3702         -    if( DbUseNre() ){
  3703         -      Tcl_NRAddCallback(interp, DbTransPostCmd, cd, 0, 0, 0);
  3704         -      (void)Tcl_NREvalObj(interp, pScript, 0);
  3705         -    }else{
  3706         -      rc = DbTransPostCmd(&cd, interp, Tcl_EvalObjEx(interp, pScript, 0));
  3707         -    }
  3708         -    break;
  3709         -  }
  3710         -
  3711         -  /*
  3712         -  **    $db unlock_notify ?script?
  3713         -  */
  3714         -  case DB_UNLOCK_NOTIFY: {
  3715         -#ifndef SQLITE_ENABLE_UNLOCK_NOTIFY
  3716         -    Tcl_AppendResult(interp, "unlock_notify not available in this build",
  3717         -                     (char*)0);
  3718         -    rc = TCL_ERROR;
  3719         -#else
  3720         -    if( objc!=2 && objc!=3 ){
  3721         -      Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?");
  3722         -      rc = TCL_ERROR;
  3723         -    }else{
  3724         -      void (*xNotify)(void **, int) = 0;
  3725         -      void *pNotifyArg = 0;
  3726         -
  3727         -      if( pDb->pUnlockNotify ){
  3728         -        Tcl_DecrRefCount(pDb->pUnlockNotify);
  3729         -        pDb->pUnlockNotify = 0;
  3730         -      }
  3731         -
  3732         -      if( objc==3 ){
  3733         -        xNotify = DbUnlockNotify;
  3734         -        pNotifyArg = (void *)pDb;
  3735         -        pDb->pUnlockNotify = objv[2];
  3736         -        Tcl_IncrRefCount(pDb->pUnlockNotify);
  3737         -      }
  3738         -
  3739         -      if( sqlite3_unlock_notify(pDb->db, xNotify, pNotifyArg) ){
  3740         -        Tcl_AppendResult(interp, (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
  3741         -        rc = TCL_ERROR;
  3742         -      }
  3743         -    }
  3744         -#endif
  3745         -    break;
  3746         -  }
  3747         -
  3748         -  /*
  3749         -  **    $db preupdate_hook count
  3750         -  **    $db preupdate_hook hook ?SCRIPT?
  3751         -  **    $db preupdate_hook new INDEX
  3752         -  **    $db preupdate_hook old INDEX
  3753         -  */
  3754         -  case DB_PREUPDATE: {
  3755         -#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
  3756         -    Tcl_AppendResult(interp, "preupdate_hook was omitted at compile-time",
  3757         -                     (char*)0);
  3758         -    rc = TCL_ERROR;
  3759         -#else
  3760         -    static const char *const azSub[] = {"count", "depth", "hook", "new", "old", 0};
  3761         -    enum DbPreupdateSubCmd {
  3762         -      PRE_COUNT, PRE_DEPTH, PRE_HOOK, PRE_NEW, PRE_OLD
  3763         -    };
  3764         -    int iSub;
  3765         -
  3766         -    if( objc<3 ){
  3767         -      Tcl_WrongNumArgs(interp, 2, objv, "SUB-COMMAND ?ARGS?");
  3768         -    }
  3769         -    if( Tcl_GetIndexFromObjStruct(interp, objv[2], azSub, sizeof(char *), "sub-command", 0, &iSub) ){
  3770         -      return TCL_ERROR;
  3771         -    }
  3772         -
  3773         -    switch( (enum DbPreupdateSubCmd)iSub ){
  3774         -      case PRE_COUNT: {
  3775         -        int nCol = sqlite3_preupdate_count(pDb->db);
  3776         -        Tcl_SetObjResult(interp, Tcl_NewWideIntObj(nCol));
  3777         -        break;
  3778         -      }
  3779         -
  3780         -      case PRE_HOOK: {
  3781         -        if( objc>4 ){
  3782         -          Tcl_WrongNumArgs(interp, 2, objv, "hook ?SCRIPT?");
  3783         -          return TCL_ERROR;
  3784         -        }
  3785         -        DbHookCmd(interp, pDb, (objc==4 ? objv[3] : 0), &pDb->pPreUpdateHook);
  3786         -        break;
  3787         -      }
  3788         -
  3789         -      case PRE_DEPTH: {
  3790         -        Tcl_Obj *pRet;
  3791         -        if( objc!=3 ){
  3792         -          Tcl_WrongNumArgs(interp, 3, objv, "");
  3793         -          return TCL_ERROR;
  3794         -        }
  3795         -        pRet = Tcl_NewWideIntObj(sqlite3_preupdate_depth(pDb->db));
  3796         -        Tcl_SetObjResult(interp, pRet);
  3797         -        break;
  3798         -      }
  3799         -
  3800         -      case PRE_NEW:
  3801         -      case PRE_OLD: {
  3802         -        int iIdx;
  3803         -        sqlite3_value *pValue;
  3804         -        if( objc!=4 ){
  3805         -          Tcl_WrongNumArgs(interp, 3, objv, "INDEX");
  3806         -          return TCL_ERROR;
  3807         -        }
  3808         -        if( Tcl_GetIntFromObj(interp, objv[3], &iIdx) ){
  3809         -          return TCL_ERROR;
  3810         -        }
  3811         -
  3812         -        if( iSub==PRE_OLD ){
  3813         -          rc = sqlite3_preupdate_old(pDb->db, iIdx, &pValue);
  3814         -        }else{
  3815         -          assert( iSub==PRE_NEW );
  3816         -          rc = sqlite3_preupdate_new(pDb->db, iIdx, &pValue);
  3817         -        }
  3818         -
  3819         -        if( rc==SQLITE_OK ){
  3820         -          Tcl_Obj *pObj;
  3821         -          pObj = Tcl_NewStringObj((char*)sqlite3_value_text(pValue), -1);
  3822         -          Tcl_SetObjResult(interp, pObj);
  3823         -        }else{
  3824         -          Tcl_AppendResult(interp, (char*)SQLITEDB_ERRMSG(pDb), (char*)0);
  3825         -          return TCL_ERROR;
  3826         -        }
  3827         -      }
  3828         -    }
  3829         -#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
  3830         -    break;
  3831         -  }
  3832         -
  3833         -  /*
  3834         -  **    $db wal_hook ?script?
  3835         -  **    $db update_hook ?script?
  3836         -  **    $db rollback_hook ?script?
  3837         -  */
  3838         -  case DB_WAL_HOOK:
  3839         -  case DB_UPDATE_HOOK:
  3840         -  case DB_ROLLBACK_HOOK: {
  3841         -    /* set ppHook to point at pUpdateHook or pRollbackHook, depending on
  3842         -    ** whether [$db update_hook] or [$db rollback_hook] was invoked.
  3843         -    */
  3844         -    Tcl_Obj **ppHook = 0;
  3845         -    if( choice==DB_WAL_HOOK ) ppHook = &pDb->pWalHook;
  3846         -    if( choice==DB_UPDATE_HOOK ) ppHook = &pDb->pUpdateHook;
  3847         -    if( choice==DB_ROLLBACK_HOOK ) ppHook = &pDb->pRollbackHook;
  3848         -    if( objc>3 ){
  3849         -       Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?");
  3850         -       return TCL_ERROR;
  3851         -    }
  3852         -
  3853         -    DbHookCmd(interp, pDb, (objc==3 ? objv[2] : 0), ppHook);
  3854         -    break;
  3855         -  }
  3856         -
  3857         -  /*    $db version
  3858         -  **
  3859         -  ** Return the version string for this database.
  3860         -  */
  3861         -  case DB_VERSION: {
  3862         -    int i;
  3863         -    for(i=2; i<objc; i++){
  3864         -      const char *zArg = Tcl_GetString(objv[i]);
  3865         -      /* Optional arguments to $db version are used for testing purpose */
  3866         -#ifdef SQLITE_TEST
  3867         -      /* $db version -use-legacy-prepare BOOLEAN
  3868         -      **
  3869         -      ** Turn the use of legacy sqlite3_prepare() on or off.
  3870         -      */
  3871         -      if( strcmp(zArg, "-use-legacy-prepare")==0 && i+1<objc ){
  3872         -        i++;
  3873         -        if( Tcl_GetBooleanFromObj(interp, objv[i], &pDb->bLegacyPrepare) ){
  3874         -          return TCL_ERROR;
  3875         -        }
  3876         -      }else
  3877         -
  3878         -      /* $db version -last-stmt-ptr
  3879         -      **
  3880         -      ** Return a string which is a hex encoding of the pointer to the
  3881         -      ** most recent sqlite3_stmt in the statement cache.
  3882         -      */
  3883         -      if( strcmp(zArg, "-last-stmt-ptr")==0 ){
  3884         -        char zBuf[100];
  3885         -        sqlite3_snprintf(sizeof(zBuf), zBuf, "%p",
  3886         -                         pDb->stmtList ? pDb->stmtList->pStmt: 0);
  3887         -        Tcl_AppendResult(interp, zBuf, (char*)0);
  3888         -      }else
  3889         -#endif /* SQLITE_TEST */
  3890         -      {
  3891         -        Tcl_AppendResult(interp, "unknown argument: ", zArg, (char*)0);
  3892         -        return TCL_ERROR;
  3893         -      }
  3894         -    }
  3895         -    if( i==2 ){
  3896         -      Tcl_AppendResult(interp, sqlite3_libversion(), (char*)0);
  3897         -    }
  3898         -    break;
  3899         -  }
  3900         -
  3901         -
  3902         -  } /* End of the SWITCH statement */
  3903         -  return rc;
  3904         -}
  3905         -
  3906         -#if SQLITE_TCL_NRE
  3907         -/*
  3908         -** Adaptor that provides an objCmd interface to the NRE-enabled
  3909         -** interface implementation.
  3910         -*/
  3911         -static int SQLITE_TCLAPI DbObjCmdAdaptor(
  3912         -  void *cd,
  3913         -  Tcl_Interp *interp,
  3914         -  int objc,
  3915         -  Tcl_Obj *const*objv
  3916         -){
  3917         -  return Tcl_NRCallObjProc(interp, DbObjCmd, cd, objc, objv);
  3918         -}
  3919         -#endif /* SQLITE_TCL_NRE */
  3920         -
  3921         -/*
  3922         -** Issue the usage message when the "sqlite3" command arguments are
  3923         -** incorrect.
  3924         -*/
  3925         -static int sqliteCmdUsage(
  3926         -  Tcl_Interp *interp,
  3927         -  Tcl_Obj *const*objv
  3928         -){
  3929         -  Tcl_WrongNumArgs(interp, 1, objv,
  3930         -    "HANDLE ?FILENAME? ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?"
  3931         -    " ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?"
  3932         -#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  3933         -    " ?-key CODECKEY?"
  3934         -#endif
  3935         -  );
  3936         -  return TCL_ERROR;
  3937         -}
  3938         -
  3939         -/*
  3940         -**   sqlite3 DBNAME FILENAME ?-vfs VFSNAME? ?-key KEY? ?-readonly BOOLEAN?
  3941         -**                           ?-create BOOLEAN? ?-nomutex BOOLEAN?
  3942         -**
  3943         -** This is the main Tcl command.  When the "sqlite" Tcl command is
  3944         -** invoked, this routine runs to process that command.
  3945         -**
  3946         -** The first argument, DBNAME, is an arbitrary name for a new
  3947         -** database connection.  This command creates a new command named
  3948         -** DBNAME that is used to control that connection.  The database
  3949         -** connection is deleted when the DBNAME command is deleted.
  3950         -**
  3951         -** The second argument is the name of the database file.
  3952         -**
  3953         -*/
  3954         -static int SQLITE_TCLAPI DbMain(
  3955         -  void *cd,
  3956         -  Tcl_Interp *interp,
  3957         -  int objc,
  3958         -  Tcl_Obj *const*objv
  3959         -){
  3960         -  SqliteDb *p;
  3961         -  const char *zArg;
  3962         -  char *zErrMsg;
  3963         -  int i;
  3964         -  const char *zFile = 0;
  3965         -  const char *zVfs = 0;
  3966         -  int flags;
  3967         -  Tcl_DString translatedFilename;
  3968         -#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  3969         -  void *pKey = 0;
  3970         -  int nKey = 0;
  3971         -#endif
  3972         -  int rc;
  3973         -
  3974         -  /* In normal use, each TCL interpreter runs in a single thread.  So
  3975         -  ** by default, we can turn off mutexing on SQLite database connections.
  3976         -  ** However, for testing purposes it is useful to have mutexes turned
  3977         -  ** on.  So, by default, mutexes default off.  But if compiled with
  3978         -  ** SQLITE_TCL_DEFAULT_FULLMUTEX then mutexes default on.
  3979         -  */
  3980         -#ifdef SQLITE_TCL_DEFAULT_FULLMUTEX
  3981         -  flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
  3982         -#else
  3983         -  flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX;
  3984         -#endif
  3985         -
  3986         -  if( objc==1 ) return sqliteCmdUsage(interp, objv);
  3987         -  if( objc==2 ){
  3988         -    zArg = Tcl_GetString(objv[1]);
  3989         -    if( strcmp(zArg,"-version")==0 ){
  3990         -      Tcl_AppendResult(interp,sqlite3_libversion(), (char*)0);
  3991         -      return TCL_OK;
  3992         -    }
  3993         -    if( strcmp(zArg,"-sourceid")==0 ){
  3994         -      Tcl_AppendResult(interp,sqlite3_sourceid(), (char*)0);
  3995         -      return TCL_OK;
  3996         -    }
  3997         -    if( strcmp(zArg,"-has-codec")==0 ){
  3998         -#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  3999         -      Tcl_AppendResult(interp,"1",(char*)0);
  4000         -#else
  4001         -      Tcl_AppendResult(interp,"0",(char*)0);
  4002         -#endif
  4003         -      return TCL_OK;
  4004         -    }
  4005         -    if( zArg[0]=='-' ) return sqliteCmdUsage(interp, objv);
  4006         -  }
  4007         -  for(i=2; i<objc; i++){
  4008         -    zArg = Tcl_GetString(objv[i]);
  4009         -    if( zArg[0]!='-' ){
  4010         -      if( zFile!=0 ) return sqliteCmdUsage(interp, objv);
  4011         -      zFile = zArg;
  4012         -      continue;
  4013         -    }
  4014         -    if( i==objc-1 ) return sqliteCmdUsage(interp, objv);
  4015         -    i++;
  4016         -    if( strcmp(zArg,"-key")==0 ){
  4017         -#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  4018         -      pKey = Tcl_GetByteArrayFromObj(objv[i], &nKey);
  4019         -#endif
  4020         -    }else if( strcmp(zArg, "-vfs")==0 ){
  4021         -      zVfs = Tcl_GetString(objv[i]);
  4022         -    }else if( strcmp(zArg, "-readonly")==0 ){
  4023         -      int b;
  4024         -      if( Tcl_GetBooleanFromObj(interp, objv[i], &b) ) return TCL_ERROR;
  4025         -      if( b ){
  4026         -        flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
  4027         -        flags |= SQLITE_OPEN_READONLY;
  4028         -      }else{
  4029         -        flags &= ~SQLITE_OPEN_READONLY;
  4030         -        flags |= SQLITE_OPEN_READWRITE;
  4031         -      }
  4032         -    }else if( strcmp(zArg, "-create")==0 ){
  4033         -      int b;
  4034         -      if( Tcl_GetBooleanFromObj(interp, objv[i], &b) ) return TCL_ERROR;
  4035         -      if( b && (flags & SQLITE_OPEN_READONLY)==0 ){
  4036         -        flags |= SQLITE_OPEN_CREATE;
  4037         -      }else{
  4038         -        flags &= ~SQLITE_OPEN_CREATE;
  4039         -      }
  4040         -    }else if( strcmp(zArg, "-nomutex")==0 ){
  4041         -      int b;
  4042         -      if( Tcl_GetBooleanFromObj(interp, objv[i], &b) ) return TCL_ERROR;
  4043         -      if( b ){
  4044         -        flags |= SQLITE_OPEN_NOMUTEX;
  4045         -        flags &= ~SQLITE_OPEN_FULLMUTEX;
  4046         -      }else{
  4047         -        flags &= ~SQLITE_OPEN_NOMUTEX;
  4048         -      }
  4049         -    }else if( strcmp(zArg, "-fullmutex")==0 ){
  4050         -      int b;
  4051         -      if( Tcl_GetBooleanFromObj(interp, objv[i], &b) ) return TCL_ERROR;
  4052         -      if( b ){
  4053         -        flags |= SQLITE_OPEN_FULLMUTEX;
  4054         -        flags &= ~SQLITE_OPEN_NOMUTEX;
  4055         -      }else{
  4056         -        flags &= ~SQLITE_OPEN_FULLMUTEX;
  4057         -      }
  4058         -    }else if( strcmp(zArg, "-uri")==0 ){
  4059         -      int b;
  4060         -      if( Tcl_GetBooleanFromObj(interp, objv[i], &b) ) return TCL_ERROR;
  4061         -      if( b ){
  4062         -        flags |= SQLITE_OPEN_URI;
  4063         -      }else{
  4064         -        flags &= ~SQLITE_OPEN_URI;
  4065         -      }
  4066         -    }else{
  4067         -      Tcl_AppendResult(interp, "unknown option: ", zArg, (char*)0);
  4068         -      return TCL_ERROR;
  4069         -    }
  4070         -  }
  4071         -  zErrMsg = 0;
  4072         -  p = (SqliteDb*)Tcl_Alloc( sizeof(*p) );
  4073         -  memset(p, 0, sizeof(*p));
  4074         -  Tcl_DStringInit(&p->dsErr);
  4075         -  if( zFile==0 ) zFile = "";
  4076         -  zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename);
  4077         -  if( utf8Encoding!=NULL ){
  4078         -    Tcl_DString ds1, ds2;
  4079         -    Tcl_UtfToExternalDString(utf8Encoding, zFile, -1, &ds1);
  4080         -    if ( zVfs!=NULL ){
  4081         -      Tcl_UtfToExternalDString(utf8Encoding, zVfs, -1, &ds2);
  4082         -      zVfs = Tcl_DStringValue(&ds2);
  4083         -    }
  4084         -    rc = sqlite3_open_v2(Tcl_DStringValue(&ds1), &p->db, flags, zVfs);
  4085         -    Tcl_DStringFree(&ds1);
  4086         -    if( zVfs!=NULL ){
  4087         -      Tcl_DStringFree(&ds2);
  4088         -    }
  4089         -  }else{
  4090         -    rc = sqlite3_open_v2(zFile, &p->db, flags, zVfs);
  4091         -  }
  4092         -  Tcl_DStringFree(&translatedFilename);
  4093         -  if( p->db ){
  4094         -    if( SQLITE_OK!=sqlite3_errcode(p->db) ){
  4095         -      zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db));
  4096         -      sqlite3_close(p->db);
  4097         -      p->db = 0;
  4098         -    }
  4099         -  }else{
  4100         -    zErrMsg = sqlite3_mprintf("%s", sqlite3_errstr(rc));
  4101         -  }
  4102         -#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  4103         -  if( p->db ){
  4104         -    sqlite3_key(p->db, pKey, nKey);
  4105         -  }
  4106         -#endif
  4107         -  if( p->db==0 ){
  4108         -    if( utf8Encoding!=NULL && zErrMsg ){
  4109         -      Tcl_DString ds;
  4110         -      Tcl_ExternalToUtfDString(utf8Encoding, zErrMsg, -1, &ds);
  4111         -      Tcl_AppendResult(interp, Tcl_DStringValue(&ds), (char*)0);
  4112         -      Tcl_DStringFree(&ds);
  4113         -    }else{
  4114         -      Tcl_AppendResult(interp, zErrMsg, (char*)0);
  4115         -    }
  4116         -    Tcl_Free((char*)p);
  4117         -    sqlite3_free(zErrMsg);
  4118         -    return TCL_ERROR;
  4119         -  }
  4120         -  p->maxStmt = NUM_PREPARED_STMTS;
  4121         -  p->openFlags = flags & SQLITE_OPEN_URI;
  4122         -  p->interp = interp;
  4123         -  zArg = Tcl_GetString(objv[1]);
  4124         -  if( DbUseNre() ){
  4125         -    Tcl_NRCreateCommand(interp, zArg, DbObjCmdAdaptor, DbObjCmd,
  4126         -                        (char*)p, DbDeleteCmd);
  4127         -  }else{
  4128         -    Tcl_CreateObjCommand(interp, zArg, DbObjCmd, (char*)p, DbDeleteCmd);
  4129         -  }
  4130         -  return TCL_OK;
  4131         -}
  4132         -
  4133         -/*
  4134         -** Provide a dummy Tcl_InitStubs if we are using this as a static
  4135         -** library.
  4136         -*/
  4137         -#undef  Tcl_InitStubs
  4138         -#ifndef USE_TCL_STUBS
  4139         -# define Tcl_InitStubs(a,b,c) TCL_VERSION
  4140         -#else
  4141         -# define Tcl_InitStubs staticTclInitStubs
  4142         -typedef struct {
  4143         -  char *result;
  4144         -  Tcl_FreeProc *freeProc;
  4145         -  int errorLine;
  4146         -  const struct TclStubs *stubTable;
  4147         -} PrivateTclInterp;
  4148         -static const char *Tcl_InitStubs(Tcl_Interp *interp, const char *version, int exact) {
  4149         -  tclStubsPtr = ((PrivateTclInterp *)interp)->stubTable;
  4150         -  if (tclStubsPtr->magic != TCL_STUB_MAGIC) {
  4151         -    ((PrivateTclInterp *)interp)->result = (char *)"interpreter uses an incompatible stubs mechanism";
  4152         -    ((PrivateTclInterp *)interp)->freeProc = 0; /* TCL_STATIC */
  4153         -    return NULL;
  4154         -  }
  4155         -  return Tcl_PkgRequireEx(interp, "Tcl", version, 0, (void *)&tclStubsPtr);
  4156         -}
  4157         -#endif
  4158         -
  4159         -/*
  4160         -** Make sure we have a PACKAGE_VERSION macro defined.  This will be
  4161         -** defined automatically by the TEA makefile.  But other makefiles
  4162         -** do not define it.
  4163         -*/
  4164         -#ifndef PACKAGE_VERSION
  4165         -# define PACKAGE_VERSION SQLITE_VERSION
  4166         -#endif
  4167         -
  4168         -/*
  4169         -** Initialize this module.
  4170         -**
  4171         -** This Tcl module contains only a single new Tcl command named "sqlite".
  4172         -** (Hence there is no namespace.  There is no point in using a namespace
  4173         -** if the extension only supplies one new name!)  The "sqlite" command is
  4174         -** used to open a new SQLite database.  See the DbMain() routine above
  4175         -** for additional information.
  4176         -**
  4177         -** The DLLEXPORT macros are required by TCL in order to work on windows.
  4178         -*/
  4179         -DLLEXPORT int Sqlite3_Init(Tcl_Interp *interp){
  4180         -  int rc = Tcl_InitStubs(interp, "8.5-", 0) ? TCL_OK : TCL_ERROR;
  4181         -  if( rc!=TCL_OK ){
  4182         -    rc = Tcl_InitStubs(interp, "8.4", 0) ? TCL_OK : TCL_ERROR;
  4183         -  }
  4184         -  if( rc==TCL_OK ){
  4185         -    Tcl_CreateObjCommand(interp, "sqlite3", (Tcl_ObjCmdProc*)DbMain, 0, 0);
  4186         -#ifndef SQLITE_3_SUFFIX_ONLY
  4187         -    /* The "sqlite" alias is undocumented.  It is here only to support
  4188         -    ** legacy scripts.  All new scripts should use only the "sqlite3"
  4189         -    ** command. */
  4190         -    Tcl_CreateObjCommand(interp, "sqlite", (Tcl_ObjCmdProc*)DbMain, 0, 0);
  4191         -#endif
  4192         -    rc = Tcl_PkgProvideEx(interp, "sqlite3", PACKAGE_VERSION, NULL);
  4193         -  }
  4194         -  if( !utf8EncInit ){
  4195         -    Tcl_Encoding enc;
  4196         -    Tcl_MutexLock(&utf8EncMutex);
  4197         -    if( ++utf8EncInit>1 ){
  4198         -      goto utf8EncInitDone;
  4199         -    }
  4200         -    enc = Tcl_GetEncoding(NULL, "utf-8");
  4201         -    /*
  4202         -     ** Try to detect the level of UTF-8 support in the Tcl core.
  4203         -     */
  4204         -    if( enc!=NULL ){
  4205         -      const char probe1[] = { 0xF0, 0x9F, 0x98, 0x82 };
  4206         -      const char probe1sp[] = { 0xED, 0xA0, 0xBD, 0xED, 0xB8, 0x82 };
  4207         -      Tcl_DString ds;
  4208         -      Tcl_ExternalToUtfDString(enc, probe1, sizeof(probe1), &ds);
  4209         -      if( Tcl_DStringLength(&ds)==sizeof(probe1) &&
  4210         -          memcmp(probe1, Tcl_DStringValue(&ds), sizeof(probe1))==0 ){
  4211         -        /*
  4212         -         ** Tcl core supports full Unicode.
  4213         -         */
  4214         -        Tcl_FreeEncoding(enc);
  4215         -      }else if( Tcl_DStringLength(&ds)==sizeof(probe1sp) &&
  4216         -          memcmp(probe1sp, Tcl_DStringValue(&ds), sizeof(probe1sp))==0 ){
  4217         -        /*
  4218         -         ** Tcl core supports full Unicode using surrogate pairs,
  4219         -         ** keep utf8Encoding for conversion to/from 4 byte UTF-8 sequences.
  4220         -         */
  4221         -        utf8Encoding = enc;
  4222         -      }else{
  4223         -        /*
  4224         -         ** Tcl core supports BMP only, let SQLite handle corner cases.
  4225         -         */
  4226         -        Tcl_FreeEncoding(enc);
  4227         -      }
  4228         -      Tcl_DStringFree(&ds);
  4229         -    }
  4230         -utf8EncInitDone:
  4231         -    Tcl_MutexUnlock(&utf8EncMutex);
  4232         -  }
  4233         -  return rc;
  4234         -}
  4235         -
  4236         -DLLEXPORT int Sqlite3_Unload(Tcl_Interp *interp, int flags){
  4237         -  Tcl_MutexLock(&utf8EncMutex);
  4238         -  if( --utf8EncInit<1 ){
  4239         -    if( utf8Encoding!=NULL ){
  4240         -      Tcl_FreeEncoding(utf8Encoding);
  4241         -      utf8Encoding = NULL;
  4242         -    }
  4243         -    utf8EncInit = 0;
  4244         -  }
  4245         -  Tcl_MutexUnlock(&utf8EncMutex);
  4246         -  return TCL_OK;
  4247         -}
  4248         -
  4249         -DLLEXPORT int Tclsqlite3_Init(Tcl_Interp *interp){
  4250         -  return Sqlite3_Init(interp);
  4251         -}
  4252         -
  4253         -DLLEXPORT int Tclsqlite3_Unload(Tcl_Interp *interp, int flags){
  4254         -  return Sqlite3_Unload(interp, flags);
  4255         -}
  4256         -
  4257         -/* Because it accesses the file-system and uses persistent state, SQLite
  4258         -** is not considered appropriate for safe interpreters.  Hence, we cause
  4259         -** the _SafeInit() interfaces return TCL_ERROR.
  4260         -*/
  4261         -DLLEXPORT int Sqlite3_SafeInit(Tcl_Interp *interp){ return TCL_ERROR; }
  4262         -DLLEXPORT int Sqlite3_SafeUnload(Tcl_Interp *interp, int flags){return TCL_ERROR;}
  4263         -
  4264         -
  4265         -
  4266         -#ifndef SQLITE_3_SUFFIX_ONLY
  4267         -int Sqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
  4268         -int Tclsqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); }
  4269         -int Sqlite_Unload(Tcl_Interp *interp, int flags){
  4270         -  return SqLite3_Unload(interp, flags);
  4271         -}
  4272         -int Tclsqlite_Unload(Tcl_Interp *interp, int flags){
  4273         -  return Sqlite3_Unload(interp, flags);
  4274         -}
  4275         -#endif
  4276         -
  4277         -/*
  4278         -** If the TCLSH macro is defined, add code to make a stand-alone program.
  4279         -*/
  4280         -#if defined(TCLSH)
  4281         -
  4282         -/* This is the main routine for an ordinary TCL shell.  If there are
  4283         -** are arguments, run the first argument as a script.  Otherwise,
  4284         -** read TCL commands from standard input
  4285         -*/
  4286         -static const char *tclsh_main_loop(void){
  4287         -  static const char zMainloop[] =
  4288         -    "if {[llength $argv]>=1} {\n"
  4289         -      "set argv0 [lindex $argv 0]\n"
  4290         -      "set argv [lrange $argv 1 end]\n"
  4291         -      "source $argv0\n"
  4292         -    "} else {\n"
  4293         -      "set line {}\n"
  4294         -      "while {![eof stdin]} {\n"
  4295         -        "if {$line!=\"\"} {\n"
  4296         -          "puts -nonewline \"> \"\n"
  4297         -        "} else {\n"
  4298         -          "puts -nonewline \"% \"\n"
  4299         -        "}\n"
  4300         -        "flush stdout\n"
  4301         -        "append line [gets stdin]\n"
  4302         -        "if {[info complete $line]} {\n"
  4303         -          "if {[catch {uplevel #0 $line} result]} {\n"
  4304         -            "puts stderr \"Error: $result\"\n"
  4305         -          "} elseif {$result!=\"\"} {\n"
  4306         -            "puts $result\n"
  4307         -          "}\n"
  4308         -          "set line {}\n"
  4309         -        "} else {\n"
  4310         -          "append line \\n\n"
  4311         -        "}\n"
  4312         -      "}\n"
  4313         -    "}\n"
  4314         -  ;
  4315         -  return zMainloop;
  4316         -}
  4317         -
  4318         -#define TCLSH_MAIN main   /* Needed to fake out mktclapp */
  4319         -int SQLITE_CDECL TCLSH_MAIN(int argc, char **argv){
  4320         -  Tcl_Interp *interp;
  4321         -  int i;
  4322         -  const char *zScript = 0;
  4323         -  char zArgc[32];
  4324         -#if defined(TCLSH_INIT_PROC)
  4325         -  extern const char *TCLSH_INIT_PROC(Tcl_Interp*);
  4326         -#endif
  4327         -
  4328         -#if !defined(_WIN32_WCE)
  4329         -  if( getenv("SQLITE_DEBUG_BREAK") ){
  4330         -    if( isatty(0) && isatty(2) ){
  4331         -      fprintf(stderr,
  4332         -          "attach debugger to process %d and press any key to continue.\n",
  4333         -          GETPID());
  4334         -      fgetc(stdin);
  4335         -    }else{
  4336         -#if defined(_WIN32) || defined(WIN32)
  4337         -      DebugBreak();
  4338         -#elif defined(SIGTRAP)
  4339         -      raise(SIGTRAP);
  4340         -#endif
  4341         -    }
  4342         -  }
  4343         -#endif
  4344         -
  4345         -  /* Call sqlite3_shutdown() once before doing anything else. This is to
  4346         -  ** test that sqlite3_shutdown() can be safely called by a process before
  4347         -  ** sqlite3_initialize() is. */
  4348         -  sqlite3_shutdown();
  4349         -
  4350         -  Tcl_FindExecutable(argv[0]);
  4351         -  Tcl_SetSystemEncoding(0, "utf-8");
  4352         -  interp = Tcl_CreateInterp();
  4353         -  Sqlite3_Init(interp);
  4354         -
  4355         -  sqlite3_snprintf(sizeof(zArgc), zArgc, "%d", argc-1);
  4356         -  Tcl_SetVar2(interp,"argc", NULL, zArgc, TCL_GLOBAL_ONLY);
  4357         -  Tcl_SetVar2(interp,"argv0", NULL, argv[0],TCL_GLOBAL_ONLY);
  4358         -  Tcl_SetVar2(interp,"argv", NULL, "", TCL_GLOBAL_ONLY);
  4359         -  for(i=1; i<argc; i++){
  4360         -    Tcl_SetVar2(interp, "argv", NULL, argv[i],
  4361         -        TCL_GLOBAL_ONLY | TCL_LIST_ELEMENT | TCL_APPEND_VALUE);
  4362         -  }
  4363         -#if defined(TCLSH_INIT_PROC)
  4364         -  zScript = TCLSH_INIT_PROC(interp);
  4365         -#endif
  4366         -  if( zScript==0 ){
  4367         -    zScript = tclsh_main_loop();
  4368         -  }
  4369         -  if( Tcl_EvalEx(interp, zScript, -1, TCL_EVAL_GLOBAL)!=TCL_OK ){
  4370         -    const char *zInfo = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
  4371         -    if( zInfo==0 ) zInfo = Tcl_GetStringResult(interp);
  4372         -    fprintf(stderr,"%s: %s\n", *argv, zInfo);
  4373         -    return 1;
  4374         -  }
  4375         -  return 0;
  4376         -}
  4377         -#endif /* TCLSH */

Deleted jni/tcl/pkgs/sqlite3.28.0/icu4c/dl_icu.c.

     1         -#include <dlfcn.h>
     2         -#include <stddef.h>
     3         -#include <string.h>
     4         -#include <stdio.h>
     5         -#include <sqlite3.h>
     6         -#ifdef ANDROID
     7         -#include <android/log.h>
     8         -#endif
     9         -
    10         -#define U_FILE_ACCESS_ERROR 4
    11         -#define U_MEMORY_ALLOCATION_ERROR 7
    12         -
    13         -static void *libicuuc_so = 0;
    14         -static int libver = 0;
    15         -static sqlite3_mutex *lock = 0;
    16         -static const char *LOG_TAG = "sqlite3_icu";
    17         -
    18         -static void *
    19         -libicuuc_link(const char *basefn)
    20         -{
    21         -    static const int ver[] = {
    22         -	55, 54, 53, 52, 51, 50, 49,
    23         -	4008, 4006, 4004, 4002, 4000,
    24         -	3008, 3006, 3004, 3002,
    25         -	-1
    26         -    };
    27         -    char fn[128];
    28         -    void *func = NULL;
    29         -
    30         -#if SQLITE_THREADSAFE
    31         -    lock = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
    32         -#endif
    33         -    if (libicuuc_so == NULL) {
    34         -	sqlite3_mutex_enter(lock);
    35         -	if (libicuuc_so != NULL) {
    36         -	    sqlite3_mutex_leave(lock);
    37         -	    goto dolink;
    38         -	}
    39         -#ifdef ANDROID
    40         -	dlerror();
    41         -	libicuuc_so = dlopen("libicuuc.so", RTLD_NOW | RTLD_GLOBAL);
    42         -#else
    43         -	for (i = 0; i < sizeof (ver) / sizeof (ver[0]); i++) {
    44         -	    int lver = ver[i];
    45         -
    46         -	    if (lver > 1000) {
    47         -		lver = lver / 100 + lver % 10;
    48         -	    }
    49         -	    if (lver > 0) {
    50         -		sprintf(fn, "%s.%d", "libicuuc.so", lver);
    51         -	    } else {
    52         -		strcpy(fn, "libicuuc.so");
    53         -	    }
    54         -	    libicuuc_so = dlopen(fn, RTLD_NOW | RTLD_GLOBAL);
    55         -	    if (libicuuc_so != NULL) {
    56         -		libver = ver[i];
    57         -		break;
    58         -	    }
    59         -	}
    60         -#endif
    61         -	sqlite3_mutex_leave(lock);
    62         -	if (libicuuc_so == NULL) {
    63         -#ifdef ANDROID
    64         -	    __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
    65         -				"dlopen(\"libicuuc.so\"): %s", dlerror());
    66         -#endif
    67         -	    return func;
    68         -	}
    69         -    }
    70         -dolink:
    71         -    if (libver == 0) {
    72         -	int i;
    73         -
    74         -	sqlite3_mutex_enter(lock);
    75         -	if (libver != 0) {
    76         -	    sqlite3_mutex_leave(lock);
    77         -	    goto dolink2;
    78         -	}
    79         -	for (i = 0; i < sizeof (ver) / sizeof (ver[0]); i++) {
    80         -#ifdef ANDROID
    81         -	    int ver2 = ver[i];
    82         -#endif
    83         -
    84         -	    if (ver[i] > 1000) {
    85         -		sprintf(fn, "%s_%d_%d", basefn, ver[i] / 1000, ver[i] % 1000);
    86         -#ifdef ANDROID
    87         -		ver2 = ver[i] / 100 + ver[i] % 10;
    88         -#endif
    89         -	    } else if (ver[i] > 0) {
    90         -		sprintf(fn, "%s_%d", basefn, ver[i]);
    91         -	    } else {
    92         -		strcpy(fn, basefn);
    93         -	    }
    94         -#ifdef ANDROID
    95         -	    dlerror();
    96         -#endif
    97         -	    func = dlsym(libicuuc_so, fn);
    98         -	    if (func != NULL) {
    99         -		libver = ver[i];
   100         -		break;
   101         -	    }
   102         -#ifdef ANDROID
   103         -	    if (ver2 != ver[i]) {
   104         -		if (ver2 > 0) {
   105         -		    sprintf(fn, "%s_%d", basefn, ver2);
   106         -		} else {
   107         -		    strcpy(fn, basefn);
   108         -		}
   109         -		dlerror();
   110         -		func = dlsym(libicuuc_so, fn);
   111         -		if (func != NULL) {
   112         -		    libver = ver2;
   113         -		    break;
   114         -		}
   115         -	    }
   116         -#endif
   117         -	}
   118         -	sqlite3_mutex_leave(lock);
   119         -#ifdef ANDROID
   120         -	if (func == NULL) {
   121         -	    __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
   122         -				"dlsym(\"%s\",\"%s\"): %s", basefn, fn,
   123         -				dlerror());
   124         -	} else {
   125         -	    __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG,
   126         -				"dlsym(\"%s\"): success", fn);
   127         -	}
   128         -#endif
   129         -    } else {
   130         -dolink2:
   131         -	if (libver > 1000) {
   132         -	    sprintf(fn, "%s_%d_%d", basefn, libver / 1000, libver % 1000);
   133         -	} else if (libver > 0) {
   134         -	    sprintf(fn, "%s_%d", basefn, libver);
   135         -	} else {
   136         -	    strcat(fn, basefn);
   137         -	}
   138         -#ifdef ANDROID
   139         -	dlerror();
   140         -#endif
   141         -	func = dlsym(libicuuc_so, fn);
   142         -#ifdef ANDROID
   143         -	if (func == NULL) {
   144         -	    __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
   145         -				"dlsym(\"%s\",\"%s\"): %s", basefn, fn,
   146         -				dlerror());
   147         -	} else {
   148         -	    __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG,
   149         -				"dlsym(\"%s\"): success", fn);
   150         -	}
   151         -#endif
   152         -    }
   153         -    return func;
   154         -}
   155         -
   156         -typedef void (ubrk_close)(void *);
   157         -typedef int (ubrk_current)(void *);
   158         -typedef int (ubrk_first)(void *);
   159         -typedef int (ubrk_next)(void *);
   160         -typedef void *(ubrk_open)(void *, int, void *, int, void *, int *);
   161         -typedef void (ucol_close)(void *);
   162         -typedef void *(ucol_open)(void *, int *);
   163         -typedef int (ucol_strcoll)(void *p1, void *p2, int, void *p3, int);
   164         -typedef const char *(u_errorName)(int);
   165         -typedef int (u_foldCase)(int, int);
   166         -typedef int (u_isspace)(int);
   167         -typedef void (uregex_close)(void *);
   168         -typedef int (uregex_matches)(void *, int, int *);
   169         -typedef void *(uregex_open)(void *, int, int, void *, int *);
   170         -typedef void (uregex_setText)(void *, void *, int, int *);
   171         -typedef int (u_strToLower)(void *, int, void *, int, void *, int *);
   172         -typedef int (u_strToUpper)(void *, int, void *, int, void *, int *);
   173         -typedef void *(u_strToUTF8)(void *, int, int *, void *, int, int *);
   174         -typedef int (utf8_nextCharSafeBody)(void *, int *, int, int, int);
   175         -
   176         -void
   177         -ubrk_close_53_sqlite3(void *ubrk)
   178         -{
   179         -    static ubrk_close *func = (ubrk_close *) -1;
   180         -
   181         -    if (func == (ubrk_close *) -1) {
   182         -	func = (ubrk_close *) libicuuc_link("ubrk_close");
   183         -    }
   184         -    if (func != NULL) {
   185         -	func(ubrk);
   186         -    }
   187         -}
   188         -
   189         -int
   190         -ubrk_current_53_sqlite3(void *ubrk)
   191         -{
   192         -    static ubrk_current *func = (ubrk_current *) -1;
   193         -    int ret = 0;
   194         -
   195         -    if (func == (ubrk_current *) -1) {
   196         -	func = (ubrk_current *) libicuuc_link("ubrk_current");
   197         -    }
   198         -    if (func != NULL) {
   199         -	ret = func(ubrk);
   200         -    }
   201         -    return ret;
   202         -}
   203         -
   204         -int
   205         -ubrk_first_53_sqlite3(void *ubrk)
   206         -{
   207         -    static ubrk_first *func = (ubrk_first *) -1;
   208         -    int ret = 0;
   209         -
   210         -    if (func == (ubrk_first *) -1) {
   211         -	func = (ubrk_first *) libicuuc_link("ubrk_first");
   212         -    }
   213         -    if (func != NULL) {
   214         -	ret = func(ubrk);
   215         -    }
   216         -    return ret;
   217         -}
   218         -
   219         -int
   220         -ubrk_next_53_sqlite3(void *ubrk)
   221         -{
   222         -    static ubrk_next *func = (ubrk_next *) -1;
   223         -    int ret = 0;
   224         -
   225         -    if (func == (ubrk_next *) -1) {
   226         -	func = (ubrk_next *) libicuuc_link("ubrk_next");
   227         -    }
   228         -    if (func != NULL) {
   229         -	ret = func(ubrk);
   230         -    }
   231         -    return ret;
   232         -}
   233         -
   234         -void *
   235         -ubrk_open_53_sqlite3(void *p1, int n1, void *p2, int n2, void *p3, int *err)
   236         -{
   237         -    static ubrk_open *func = (ubrk_open *) -1;
   238         -    int err0 = 0, *errp;
   239         -
   240         -    if (func == (ubrk_open *) -1) {
   241         -	func = (ubrk_open *) libicuuc_link("ubrk_open");
   242         -    }
   243         -    errp = (err == NULL) ? &err0 : err;
   244         -    if (func != NULL) {
   245         -	return func(p1, n1, p2, n2, p3, errp);
   246         -    }
   247         -    if (err != NULL) {
   248         -	*err = U_FILE_ACCESS_ERROR;
   249         -    }
   250         -    return NULL;
   251         -}
   252         -
   253         -void
   254         -ucol_close_53_sqlite3(void *ucol)
   255         -{
   256         -    static ucol_close *func = (ucol_close *) -1;
   257         -
   258         -    if (func == (ucol_close *) -1) {
   259         -	func = (ucol_close *) libicuuc_link("ucol_close");
   260         -    }
   261         -    if (func != NULL) {
   262         -	func(ucol);
   263         -    }
   264         -}
   265         -
   266         -void *
   267         -ucol_open_53_sqlite3(void *p1, int *err)
   268         -{
   269         -    static ucol_open *func = (ucol_open *) -1;
   270         -    int err0 = 0, *errp;
   271         -
   272         -    if (func == (ucol_open *) -1) {
   273         -	func = (ucol_open *) libicuuc_link("ucol_open");
   274         -    }
   275         -    errp = (err == NULL) ? &err0 : err;
   276         -    if (func != NULL) {
   277         -	return func(p1, errp);
   278         -    }
   279         -    if (err != NULL) {
   280         -	*err = U_FILE_ACCESS_ERROR;
   281         -    }
   282         -    return NULL;
   283         -}
   284         -
   285         -int
   286         -ucol_strcoll_53_sqlite3(void *p1, void *p2, int n1, void *p3, int n2)
   287         -{
   288         -    static ucol_strcoll *func = (ucol_strcoll *) -1;
   289         -    int ret = 0;
   290         -
   291         -    if (func == (ucol_strcoll *) -1) {
   292         -	func = (ucol_strcoll *) libicuuc_link("ucol_strcoll");
   293         -    }
   294         -    if (func != NULL) {
   295         -	ret = func(p1, p2, n1, p3, n2);
   296         -    }
   297         -    return ret;
   298         -}
   299         -
   300         -const char *
   301         -u_errorName_53_sqlite3(int err)
   302         -{
   303         -    static u_errorName *func = (u_errorName *) -1;
   304         -    int ret = 0;
   305         -
   306         -    if (func == (u_errorName *) -1) {
   307         -	func = (u_errorName *) libicuuc_link("u_errorName");
   308         -    }
   309         -    if (func != NULL) {
   310         -	return func(err);
   311         -    }
   312         -    return "link error";
   313         -}
   314         -
   315         -int
   316         -u_foldCase_53_sqlite3(int n1, int n2)
   317         -{
   318         -    static u_foldCase *func = (u_foldCase *) -1;
   319         -    int ret = n1;
   320         -
   321         -    if (func == (u_foldCase *) -1) {
   322         -	func = (u_foldCase *) libicuuc_link("u_foldCase");
   323         -    }
   324         -    if (func != NULL) {
   325         -	ret = func(n1, n2);
   326         -    }
   327         -    return ret;
   328         -}
   329         -
   330         -int
   331         -u_isspace_53_sqlite3(int n1)
   332         -{
   333         -    static u_isspace *func = (u_isspace *) -1;
   334         -
   335         -    if (func == (u_isspace *) -1) {
   336         -	func = (u_isspace *) libicuuc_link("u_isspace");
   337         -    }
   338         -    if (func != NULL) {
   339         -	return func(n1);
   340         -    }
   341         -    return (n1 == ' ') || (n1 == '\t') || (n1 == '\n') ||
   342         -	   (n1 == '\r') || (n1 == '\v');
   343         -}
   344         -
   345         -void
   346         -uregex_close_53_sqlite3(void *uregex)
   347         -{
   348         -    static uregex_close *func = (uregex_close *) -1;
   349         -
   350         -    if (func == (uregex_close *) -1) {
   351         -	func = (uregex_close *) libicuuc_link("uregex_close");
   352         -    }
   353         -    if (func != NULL) {
   354         -	func(uregex);
   355         -    }
   356         -}
   357         -
   358         -int
   359         -uregex_matches_53_sqlite3(void *uregex, int n1, int *err)
   360         -{
   361         -    static uregex_matches *func = (uregex_matches *) -1;
   362         -    int err0 = 0, *errp;
   363         -
   364         -    if (func == (uregex_matches *) -1) {
   365         -	func = (uregex_matches *) libicuuc_link("uregex_matches");
   366         -    }
   367         -    errp = (err == NULL) ? &err0 : err;
   368         -    if (func != NULL) {
   369         -	return func(uregex, n1, errp);
   370         -    }
   371         -    if (err != NULL) {
   372         -	*err = U_MEMORY_ALLOCATION_ERROR;
   373         -    }
   374         -    return 0;
   375         -}
   376         -
   377         -void *
   378         -uregex_open_53_sqlite3(void *p1, int n1, int n2, void *p2, int *err)
   379         -{
   380         -    static uregex_open *func = (uregex_open *) -1;
   381         -    int err0 = 0, *errp;
   382         -
   383         -    if (func == (uregex_open *) -1) {
   384         -	func = (uregex_open *) libicuuc_link("uregex_open");
   385         -    }
   386         -    errp = (err == NULL) ? &err0 : err;
   387         -    if (func != NULL) {
   388         -	return func(p1, n1, n2, p2, errp);
   389         -    }
   390         -    if (err != NULL) {
   391         -	*err = U_FILE_ACCESS_ERROR;
   392         -    }
   393         -    return NULL;
   394         -}
   395         -
   396         -void
   397         -uregex_setText_53_sqlite3(void *uregex, void *p1, int n1, int *err)
   398         -{
   399         -    static uregex_setText *func = (uregex_setText *) -1;
   400         -    int err0 = 0, *errp;
   401         -
   402         -    if (func == (uregex_setText *) -1) {
   403         -	func = (uregex_setText *) libicuuc_link("uregex_setText");
   404         -    }
   405         -    errp = (err == NULL) ? &err0 : err;
   406         -    if (func != NULL) {
   407         -	return func(uregex, p1, n1, errp);
   408         -    }
   409         -    if (err != NULL) {
   410         -	*err = U_MEMORY_ALLOCATION_ERROR;
   411         -    }
   412         -}
   413         -
   414         -int
   415         -u_strToLower_53_sqlite3(void *p1, int n1, void *p2, int n2, void *p3, int *err)
   416         -{
   417         -    static u_strToLower *func = (u_strToLower *) -1;
   418         -    int err0 = 0, *errp;
   419         -
   420         -    if (func == (u_strToLower *) -1) {
   421         -	func = (u_strToLower *) libicuuc_link("u_strToLower");
   422         -    }
   423         -    errp = (err == NULL) ? &err0 : err;
   424         -    if (func != NULL) {
   425         -	return func(p1, n1, p2, n2, p3, errp);
   426         -    }
   427         -    if (err != NULL) {
   428         -	*err = U_MEMORY_ALLOCATION_ERROR;
   429         -    }
   430         -    return 0;
   431         -}
   432         -
   433         -int
   434         -u_strToUpper_53_sqlite3(void *p1, int n1, void *p2, int n2, void *p3, int *err)
   435         -{
   436         -    static u_strToUpper *func = (u_strToUpper *) -1;
   437         -    int err0 = 0, *errp;
   438         -
   439         -    if (func == (u_strToUpper *) -1) {
   440         -	func = (u_strToUpper *) libicuuc_link("u_strToUpper");
   441         -    }
   442         -    errp = (err == NULL) ? &err0 : err;
   443         -    if (func != NULL) {
   444         -	return func(p1, n1, p2, n2, p3, errp);
   445         -    }
   446         -    if (err != NULL) {
   447         -	*err = U_MEMORY_ALLOCATION_ERROR;
   448         -    }
   449         -    return 0;
   450         -}
   451         -
   452         -void *
   453         -u_strToUTF8_53_sqlite3(void *p1, int n1, void *p2, int *p3, int n2, int *err)
   454         -{
   455         -    static u_strToUTF8 *func = (u_strToUTF8 *) -1;
   456         -    int err0 = 0, *errp;
   457         -
   458         -    if (func == (u_strToUTF8 *) -1) {
   459         -	func = (u_strToUTF8 *) libicuuc_link("u_strToUTF8");
   460         -    }
   461         -    errp = (err == NULL) ? &err0 : err;
   462         -    if (func != NULL) {
   463         -	return func(p1, n1, p2, p3, n2, errp);
   464         -    }
   465         -    if (err != NULL) {
   466         -	*err = U_MEMORY_ALLOCATION_ERROR;
   467         -    }
   468         -    return NULL;
   469         -}
   470         -
   471         -int
   472         -utf8_nextCharSafeBody_53_sqlite3(void *p1, int *p2, int n1, int n2, int n3)
   473         -{
   474         -    static utf8_nextCharSafeBody *func = (utf8_nextCharSafeBody *) -1;
   475         -
   476         -    if (func == (utf8_nextCharSafeBody *) -1) {
   477         -	func =
   478         -	    (utf8_nextCharSafeBody *) libicuuc_link("utf8_nextCharSafeBody");
   479         -    }
   480         -    if (func != NULL) {
   481         -	return func(p1, p2, n1, n2, n3);
   482         -    }
   483         -    return n2;
   484         -}

Deleted jni/tcl/pkgs/sqlite3.28.0/icu4c/unicode/localpointer.h.

     1         -/*
     2         -*******************************************************************************
     3         -*
     4         -*   Copyright (C) 2009-2012, International Business Machines
     5         -*   Corporation and others.  All Rights Reserved.
     6         -*
     7         -*******************************************************************************
     8         -*   file name:  localpointer.h
     9         -*   encoding:   US-ASCII
    10         -*   tab size:   8 (not used)
    11         -*   indentation:4
    12         -*
    13         -*   created on: 2009nov13
    14         -*   created by: Markus W. Scherer
    15         -*/
    16         -
    17         -#ifndef __LOCALPOINTER_H__
    18         -#define __LOCALPOINTER_H__
    19         -
    20         -/**
    21         - * \file 
    22         - * \brief C++ API: "Smart pointers" for use with and in ICU4C C++ code.
    23         - *
    24         - * These classes are inspired by
    25         - * - std::auto_ptr
    26         - * - boost::scoped_ptr & boost::scoped_array
    27         - * - Taligent Safe Pointers (TOnlyPointerTo)
    28         - *
    29         - * but none of those provide for all of the goals for ICU smart pointers:
    30         - * - Smart pointer owns the object and releases it when it goes out of scope.
    31         - * - No transfer of ownership via copy/assignment to reduce misuse. Simpler & more robust.
    32         - * - ICU-compatible: No exceptions.
    33         - * - Need to be able to orphan/release the pointer and its ownership.
    34         - * - Need variants for normal C++ object pointers, C++ arrays, and ICU C service objects.
    35         - *
    36         - * For details see http://site.icu-project.org/design/cpp/scoped_ptr
    37         - */
    38         -
    39         -#include "unicode/utypes.h"
    40         -
    41         -#if U_SHOW_CPLUSPLUS_API
    42         -
    43         -U_NAMESPACE_BEGIN
    44         -
    45         -/**
    46         - * "Smart pointer" base class; do not use directly: use LocalPointer etc.
    47         - *
    48         - * Base class for smart pointer classes that do not throw exceptions.
    49         - *
    50         - * Do not use this base class directly, since it does not delete its pointer.
    51         - * A subclass must implement methods that delete the pointer:
    52         - * Destructor and adoptInstead().
    53         - *
    54         - * There is no operator T *() provided because the programmer must decide
    55         - * whether to use getAlias() (without transfer of ownership) or orpan()
    56         - * (with transfer of ownership and NULLing of the pointer).
    57         - *
    58         - * @see LocalPointer
    59         - * @see LocalArray
    60         - * @see U_DEFINE_LOCAL_OPEN_POINTER
    61         - * @stable ICU 4.4
    62         - */
    63         -template<typename T>
    64         -class LocalPointerBase {
    65         -public:
    66         -    /**
    67         -     * Constructor takes ownership.
    68         -     * @param p simple pointer to an object that is adopted
    69         -     * @stable ICU 4.4
    70         -     */
    71         -    explicit LocalPointerBase(T *p=NULL) : ptr(p) {}
    72         -    /**
    73         -     * Destructor deletes the object it owns.
    74         -     * Subclass must override: Base class does nothing.
    75         -     * @stable ICU 4.4
    76         -     */
    77         -    ~LocalPointerBase() { /* delete ptr; */ }
    78         -    /**
    79         -     * NULL check.
    80         -     * @return TRUE if ==NULL
    81         -     * @stable ICU 4.4
    82         -     */
    83         -    UBool isNull() const { return ptr==NULL; }
    84         -    /**
    85         -     * NULL check.
    86         -     * @return TRUE if !=NULL
    87         -     * @stable ICU 4.4
    88         -     */
    89         -    UBool isValid() const { return ptr!=NULL; }
    90         -    /**
    91         -     * Comparison with a simple pointer, so that existing code
    92         -     * with ==NULL need not be changed.
    93         -     * @param other simple pointer for comparison
    94         -     * @return true if this pointer value equals other
    95         -     * @stable ICU 4.4
    96         -     */
    97         -    bool operator==(const T *other) const { return ptr==other; }
    98         -    /**
    99         -     * Comparison with a simple pointer, so that existing code
   100         -     * with !=NULL need not be changed.
   101         -     * @param other simple pointer for comparison
   102         -     * @return true if this pointer value differs from other
   103         -     * @stable ICU 4.4
   104         -     */
   105         -    bool operator!=(const T *other) const { return ptr!=other; }
   106         -    /**
   107         -     * Access without ownership change.
   108         -     * @return the pointer value
   109         -     * @stable ICU 4.4
   110         -     */
   111         -    T *getAlias() const { return ptr; }
   112         -    /**
   113         -     * Access without ownership change.
   114         -     * @return the pointer value as a reference
   115         -     * @stable ICU 4.4
   116         -     */
   117         -    T &operator*() const { return *ptr; }
   118         -    /**
   119         -     * Access without ownership change.
   120         -     * @return the pointer value
   121         -     * @stable ICU 4.4
   122         -     */
   123         -    T *operator->() const { return ptr; }
   124         -    /**
   125         -     * Gives up ownership; the internal pointer becomes NULL.
   126         -     * @return the pointer value;
   127         -     *         caller becomes responsible for deleting the object
   128         -     * @stable ICU 4.4
   129         -     */
   130         -    T *orphan() {
   131         -        T *p=ptr;
   132         -        ptr=NULL;
   133         -        return p;
   134         -    }
   135         -    /**
   136         -     * Deletes the object it owns,
   137         -     * and adopts (takes ownership of) the one passed in.
   138         -     * Subclass must override: Base class does not delete the object.
   139         -     * @param p simple pointer to an object that is adopted
   140         -     * @stable ICU 4.4
   141         -     */
   142         -    void adoptInstead(T *p) {
   143         -        // delete ptr;
   144         -        ptr=p;
   145         -    }
   146         -protected:
   147         -    /**
   148         -     * Actual pointer.
   149         -     * @internal
   150         -     */
   151         -    T *ptr;
   152         -private:
   153         -    // No comparison operators with other LocalPointerBases.
   154         -    bool operator==(const LocalPointerBase &other);
   155         -    bool operator!=(const LocalPointerBase &other);
   156         -    // No ownership transfer: No copy constructor, no assignment operator.
   157         -    LocalPointerBase(const LocalPointerBase &other);
   158         -    void operator=(const LocalPointerBase &other);
   159         -    // No heap allocation. Use only on the stack.
   160         -    static void * U_EXPORT2 operator new(size_t size);
   161         -    static void * U_EXPORT2 operator new[](size_t size);
   162         -#if U_HAVE_PLACEMENT_NEW
   163         -    static void * U_EXPORT2 operator new(size_t, void *ptr);
   164         -#endif
   165         -};
   166         -
   167         -/**
   168         - * "Smart pointer" class, deletes objects via the standard C++ delete operator.
   169         - * For most methods see the LocalPointerBase base class.
   170         - *
   171         - * Usage example:
   172         - * \code
   173         - * LocalPointer<UnicodeString> s(new UnicodeString((UChar32)0x50005));
   174         - * int32_t length=s->length();  // 2
   175         - * UChar lead=s->charAt(0);  // 0xd900
   176         - * if(some condition) { return; }  // no need to explicitly delete the pointer
   177         - * s.adoptInstead(new UnicodeString((UChar)0xfffc));
   178         - * length=s->length();  // 1
   179         - * // no need to explicitly delete the pointer
   180         - * \endcode
   181         - *
   182         - * @see LocalPointerBase
   183         - * @stable ICU 4.4
   184         - */
   185         -template<typename T>
   186         -class LocalPointer : public LocalPointerBase<T> {
   187         -public:
   188         -    /**
   189         -     * Constructor takes ownership.
   190         -     * @param p simple pointer to an object that is adopted
   191         -     * @stable ICU 4.4
   192         -     */
   193         -    explicit LocalPointer(T *p=NULL) : LocalPointerBase<T>(p) {}
   194         -    /**
   195         -     * Destructor deletes the object it owns.
   196         -     * @stable ICU 4.4
   197         -     */
   198         -    ~LocalPointer() {
   199         -        delete LocalPointerBase<T>::ptr;
   200         -    }
   201         -    /**
   202         -     * Deletes the object it owns,
   203         -     * and adopts (takes ownership of) the one passed in.
   204         -     * @param p simple pointer to an object that is adopted
   205         -     * @stable ICU 4.4
   206         -     */
   207         -    void adoptInstead(T *p) {
   208         -        delete LocalPointerBase<T>::ptr;
   209         -        LocalPointerBase<T>::ptr=p;
   210         -    }
   211         -};
   212         -
   213         -/**
   214         - * "Smart pointer" class, deletes objects via the C++ array delete[] operator.
   215         - * For most methods see the LocalPointerBase base class.
   216         - * Adds operator[] for array item access.
   217         - *
   218         - * Usage example:
   219         - * \code
   220         - * LocalArray<UnicodeString> a(new UnicodeString[2]);
   221         - * a[0].append((UChar)0x61);
   222         - * if(some condition) { return; }  // no need to explicitly delete the array
   223         - * a.adoptInstead(new UnicodeString[4]);
   224         - * a[3].append((UChar)0x62).append((UChar)0x63).reverse();
   225         - * // no need to explicitly delete the array
   226         - * \endcode
   227         - *
   228         - * @see LocalPointerBase
   229         - * @stable ICU 4.4
   230         - */
   231         -template<typename T>
   232         -class LocalArray : public LocalPointerBase<T> {
   233         -public:
   234         -    /**
   235         -     * Constructor takes ownership.
   236         -     * @param p simple pointer to an array of T objects that is adopted
   237         -     * @stable ICU 4.4
   238         -     */
   239         -    explicit LocalArray(T *p=NULL) : LocalPointerBase<T>(p) {}
   240         -    /**
   241         -     * Destructor deletes the array it owns.
   242         -     * @stable ICU 4.4
   243         -     */
   244         -    ~LocalArray() {
   245         -        delete[] LocalPointerBase<T>::ptr;
   246         -    }
   247         -    /**
   248         -     * Deletes the array it owns,
   249         -     * and adopts (takes ownership of) the one passed in.
   250         -     * @param p simple pointer to an array of T objects that is adopted
   251         -     * @stable ICU 4.4
   252         -     */
   253         -    void adoptInstead(T *p) {
   254         -        delete[] LocalPointerBase<T>::ptr;
   255         -        LocalPointerBase<T>::ptr=p;
   256         -    }
   257         -    /**
   258         -     * Array item access (writable).
   259         -     * No index bounds check.
   260         -     * @param i array index
   261         -     * @return reference to the array item
   262         -     * @stable ICU 4.4
   263         -     */
   264         -    T &operator[](ptrdiff_t i) const { return LocalPointerBase<T>::ptr[i]; }
   265         -};
   266         -
   267         -/**
   268         - * \def U_DEFINE_LOCAL_OPEN_POINTER
   269         - * "Smart pointer" definition macro, deletes objects via the closeFunction.
   270         - * Defines a subclass of LocalPointerBase which works just
   271         - * like LocalPointer<Type> except that this subclass will use the closeFunction
   272         - * rather than the C++ delete operator.
   273         - *
   274         - * Requirement: The closeFunction must tolerate a NULL pointer.
   275         - * (We could add a NULL check here but it is normally redundant.)
   276         - *
   277         - * Usage example:
   278         - * \code
   279         - * LocalUCaseMapPointer csm(ucasemap_open(localeID, options, &errorCode));
   280         - * utf8OutLength=ucasemap_utf8ToLower(csm.getAlias(),
   281         - *     utf8Out, (int32_t)sizeof(utf8Out),
   282         - *     utf8In, utf8InLength, &errorCode);
   283         - * if(U_FAILURE(errorCode)) { return; }  // no need to explicitly delete the UCaseMap
   284         - * \endcode
   285         - *
   286         - * @see LocalPointerBase
   287         - * @see LocalPointer
   288         - * @stable ICU 4.4
   289         - */
   290         -#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \
   291         -    class LocalPointerClassName : public LocalPointerBase<Type> { \
   292         -    public: \
   293         -        explicit LocalPointerClassName(Type *p=NULL) : LocalPointerBase<Type>(p) {} \
   294         -        ~LocalPointerClassName() { closeFunction(ptr); } \
   295         -        void adoptInstead(Type *p) { \
   296         -            closeFunction(ptr); \
   297         -            ptr=p; \
   298         -        } \
   299         -    }
   300         -
   301         -U_NAMESPACE_END
   302         -
   303         -#endif  /* U_SHOW_CPLUSPLUS_API */
   304         -#endif  /* __LOCALPOINTER_H__ */

Deleted jni/tcl/pkgs/sqlite3.28.0/icu4c/unicode/parseerr.h.

     1         -/*
     2         -**********************************************************************
     3         -*   Copyright (C) 1999-2005, International Business Machines
     4         -*   Corporation and others.  All Rights Reserved.
     5         -**********************************************************************
     6         -*   Date        Name        Description
     7         -*   03/14/00    aliu        Creation.
     8         -*   06/27/00    aliu        Change from C++ class to C struct
     9         -**********************************************************************
    10         -*/
    11         -#ifndef PARSEERR_H
    12         -#define PARSEERR_H
    13         -
    14         -#include "unicode/utypes.h"
    15         -
    16         -
    17         -/**
    18         - * \file
    19         - * \brief C API: Parse Error Information
    20         - */
    21         -/**
    22         - * The capacity of the context strings in UParseError.
    23         - * @stable ICU 2.0
    24         - */ 
    25         -enum { U_PARSE_CONTEXT_LEN = 16 };
    26         -
    27         -/**
    28         - * A UParseError struct is used to returned detailed information about
    29         - * parsing errors.  It is used by ICU parsing engines that parse long
    30         - * rules, patterns, or programs, where the text being parsed is long
    31         - * enough that more information than a UErrorCode is needed to
    32         - * localize the error.
    33         - *
    34         - * <p>The line, offset, and context fields are optional; parsing
    35         - * engines may choose not to use to use them.
    36         - *
    37         - * <p>The preContext and postContext strings include some part of the
    38         - * context surrounding the error.  If the source text is "let for=7"
    39         - * and "for" is the error (e.g., because it is a reserved word), then
    40         - * some examples of what a parser might produce are the following:
    41         - *
    42         - * <pre>
    43         - * preContext   postContext
    44         - * ""           ""            The parser does not support context
    45         - * "let "       "=7"          Pre- and post-context only
    46         - * "let "       "for=7"       Pre- and post-context and error text
    47         - * ""           "for"         Error text only
    48         - * </pre>
    49         - *
    50         - * <p>Examples of engines which use UParseError (or may use it in the
    51         - * future) are Transliterator, RuleBasedBreakIterator, and
    52         - * RegexPattern.
    53         - * 
    54         - * @stable ICU 2.0
    55         - */
    56         -typedef struct UParseError {
    57         -
    58         -    /**
    59         -     * The line on which the error occured.  If the parser uses this
    60         -     * field, it sets it to the line number of the source text line on
    61         -     * which the error appears, which will be be a value >= 1.  If the
    62         -     * parse does not support line numbers, the value will be <= 0.
    63         -     * @stable ICU 2.0
    64         -     */
    65         -    int32_t        line;
    66         -
    67         -    /**
    68         -     * The character offset to the error.  If the line field is >= 1,
    69         -     * then this is the offset from the start of the line.  Otherwise,
    70         -     * this is the offset from the start of the text.  If the parser
    71         -     * does not support this field, it will have a value < 0.
    72         -     * @stable ICU 2.0
    73         -     */
    74         -    int32_t        offset;
    75         -
    76         -    /**
    77         -     * Textual context before the error.  Null-terminated.  The empty
    78         -     * string if not supported by parser.
    79         -     * @stable ICU 2.0   
    80         -     */
    81         -    UChar          preContext[U_PARSE_CONTEXT_LEN];
    82         -
    83         -    /**
    84         -     * The error itself and/or textual context after the error.
    85         -     * Null-terminated.  The empty string if not supported by parser.
    86         -     * @stable ICU 2.0   
    87         -     */
    88         -    UChar          postContext[U_PARSE_CONTEXT_LEN];
    89         -
    90         -} UParseError;
    91         -
    92         -#endif

Deleted jni/tcl/pkgs/sqlite3.28.0/icu4c/unicode/platform.h.

     1         -/*
     2         -******************************************************************************
     3         -*
     4         -*   Copyright (C) 1997-2013, International Business Machines
     5         -*   Corporation and others.  All Rights Reserved.
     6         -*
     7         -******************************************************************************
     8         -*
     9         -*  FILE NAME : platform.h
    10         -*
    11         -*   Date        Name        Description
    12         -*   05/13/98    nos         Creation (content moved here from ptypes.h).
    13         -*   03/02/99    stephen     Added AS400 support.
    14         -*   03/30/99    stephen     Added Linux support.
    15         -*   04/13/99    stephen     Reworked for autoconf.
    16         -******************************************************************************
    17         -*/
    18         -
    19         -#ifndef _PLATFORM_H
    20         -#define _PLATFORM_H
    21         -
    22         -#include "unicode/uconfig.h"
    23         -#include "unicode/uvernum.h"
    24         -
    25         -/**
    26         - * \file
    27         - * \brief Basic types for the platform.
    28         - *
    29         - * This file used to be generated by autoconf/configure.
    30         - * Starting with ICU 49, platform.h is a normal source file,
    31         - * to simplify cross-compiling and working with non-autoconf/make build systems.
    32         - *
    33         - * When a value in this file does not work on a platform, then please
    34         - * try to derive it from the U_PLATFORM value
    35         - * (for which we might need a new value constant in rare cases)
    36         - * and/or from other macros that are predefined by the compiler
    37         - * or defined in standard (POSIX or platform or compiler) headers.
    38         - *
    39         - * As a temporary workaround, you can add an explicit <code>#define</code> for some macros
    40         - * before it is first tested, or add an equivalent -D macro definition
    41         - * to the compiler's command line.
    42         - *
    43         - * Note: Some compilers provide ways to show the predefined macros.
    44         - * For example, with gcc you can compile an empty .c file and have the compiler
    45         - * print the predefined macros with
    46         - * \code
    47         - * gcc -E -dM -x c /dev/null | sort
    48         - * \endcode
    49         - * (You can provide an actual empty .c file rather than /dev/null.
    50         - * <code>-x c++</code> is for C++.)
    51         - */
    52         -
    53         -/**
    54         - * Define some things so that they can be documented.
    55         - * @internal
    56         - */
    57         -#ifdef U_IN_DOXYGEN
    58         -/*
    59         - * Problem: "platform.h:335: warning: documentation for unknown define U_HAVE_STD_STRING found." means that U_HAVE_STD_STRING is not documented.
    60         - * Solution: #define any defines for non @internal API here, so that they are visible in the docs.  If you just set PREDEFINED in Doxyfile.in,  they won't be documented.
    61         - */
    62         -
    63         -/* None for now. */
    64         -#endif
    65         -
    66         -/**
    67         - * \def U_PLATFORM
    68         - * The U_PLATFORM macro defines the platform we're on.
    69         - *
    70         - * We used to define one different, value-less macro per platform.
    71         - * That made it hard to know the set of relevant platforms and macros,
    72         - * and hard to deal with variants of platforms.
    73         - *
    74         - * Starting with ICU 49, we define platforms as numeric macros,
    75         - * with ranges of values for related platforms and their variants.
    76         - * The U_PLATFORM macro is set to one of these values.
    77         - *
    78         - * Historical note from the Solaris Wikipedia article:
    79         - * AT&T and Sun collaborated on a project to merge the most popular Unix variants
    80         - * on the market at that time: BSD, System V, and Xenix.
    81         - * This became Unix System V Release 4 (SVR4).
    82         - *
    83         - * @internal
    84         - */
    85         -
    86         -/** Unknown platform. @internal */
    87         -#define U_PF_UNKNOWN 0
    88         -/** Windows @internal */
    89         -#define U_PF_WINDOWS 1000
    90         -/** MinGW. Windows, calls to Win32 API, but using GNU gcc and binutils. @internal */
    91         -#define U_PF_MINGW 1800
    92         -/**
    93         - * Cygwin. Windows, calls to cygwin1.dll for Posix functions,
    94         - * using MSVC or GNU gcc and binutils.
    95         - * @internal
    96         - */
    97         -#define U_PF_CYGWIN 1900
    98         -/* Reserve 2000 for U_PF_UNIX? */
    99         -/** HP-UX is based on UNIX System V. @internal */
   100         -#define U_PF_HPUX 2100
   101         -/** Solaris is a Unix operating system based on SVR4. @internal */
   102         -#define U_PF_SOLARIS 2600
   103         -/** BSD is a UNIX operating system derivative. @internal */
   104         -#define U_PF_BSD 3000
   105         -/** AIX is based on UNIX System V Releases and 4.3 BSD. @internal */
   106         -#define U_PF_AIX 3100
   107         -/** IRIX is based on UNIX System V with BSD extensions. @internal */
   108         -#define U_PF_IRIX 3200
   109         -/**
   110         - * Darwin is a POSIX-compliant operating system, composed of code developed by Apple,
   111         - * as well as code derived from NeXTSTEP, BSD, and other projects,
   112         - * built around the Mach kernel.
   113         - * Darwin forms the core set of components upon which Mac OS X, Apple TV, and iOS are based.
   114         - * (Original description modified from WikiPedia.)
   115         - * @internal
   116         - */
   117         -#define U_PF_DARWIN 3500
   118         -/** iPhone OS (iOS) is a derivative of Mac OS X. @internal */
   119         -#define U_PF_IPHONE 3550
   120         -/** QNX is a commercial Unix-like real-time operating system related to BSD. @internal */
   121         -#define U_PF_QNX 3700
   122         -/** Linux is a Unix-like operating system. @internal */
   123         -#define U_PF_LINUX 4000
   124         -/** Android is based on Linux. @internal */
   125         -#define U_PF_ANDROID 4050
   126         -/** "Classic" Mac OS (1984-2001) @internal */
   127         -#define U_PF_CLASSIC_MACOS 8000
   128         -/** z/OS is the successor to OS/390 which was the successor to MVS. @internal */
   129         -#define U_PF_OS390 9000
   130         -/** "IBM i" is the current name of what used to be i5/OS and earlier OS/400. @internal */
   131         -#define U_PF_OS400 9400
   132         -
   133         -#ifdef U_PLATFORM
   134         -    /* Use the predefined value. */
   135         -#elif defined(__MINGW32__)
   136         -#   define U_PLATFORM U_PF_MINGW
   137         -#elif defined(__CYGWIN__)
   138         -#   define U_PLATFORM U_PF_CYGWIN
   139         -#elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
   140         -#   define U_PLATFORM U_PF_WINDOWS
   141         -#elif defined(__ANDROID__)
   142         -#   define U_PLATFORM U_PF_ANDROID
   143         -    /* Android wchar_t support depends on the API level. */
   144         -#   include <android/api-level.h>
   145         -#elif defined(linux) || defined(__linux__) || defined(__linux)
   146         -#   define U_PLATFORM U_PF_LINUX
   147         -#elif defined(__APPLE__) && defined(__MACH__)
   148         -#   include <TargetConditionals.h>
   149         -#   if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE  /* variant of TARGET_OS_MAC */
   150         -#       define U_PLATFORM U_PF_IPHONE
   151         -#   else
   152         -#       define U_PLATFORM U_PF_DARWIN
   153         -#   endif
   154         -#elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
   155         -#   define U_PLATFORM U_PF_BSD
   156         -#elif defined(sun) || defined(__sun)
   157         -    /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
   158         -#   define U_PLATFORM U_PF_SOLARIS
   159         -#   if defined(__GNUC__)
   160         -        /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
   161         -         * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
   162         -         *  is included which does not include this header file.
   163         -         */
   164         -#       include <sys/isa_defs.h>
   165         -#   endif
   166         -#elif defined(_AIX) || defined(__TOS_AIX__)
   167         -#   define U_PLATFORM U_PF_AIX
   168         -#elif defined(_hpux) || defined(hpux) || defined(__hpux)
   169         -#   define U_PLATFORM U_PF_HPUX
   170         -#elif defined(sgi) || defined(__sgi)
   171         -#   define U_PLATFORM U_PF_IRIX
   172         -#elif defined(macintosh)
   173         -#   define U_PLATFORM U_PF_CLASSIC_MACOS
   174         -#elif defined(__QNX__) || defined(__QNXNTO__)
   175         -#   define U_PLATFORM U_PF_QNX
   176         -#elif defined(__TOS_MVS__)
   177         -#   define U_PLATFORM U_PF_OS390
   178         -#elif defined(__OS400__) || defined(__TOS_OS400__)
   179         -#   define U_PLATFORM U_PF_OS400
   180         -#else
   181         -#   define U_PLATFORM U_PF_UNKNOWN
   182         -#endif
   183         -
   184         -/**
   185         - * \def CYGWINMSVC
   186         - * Defined if this is Windows with Cygwin, but using MSVC rather than gcc.
   187         - * Otherwise undefined.
   188         - * @internal
   189         - */
   190         -/* Commented out because this is already set in mh-cygwin-msvc
   191         -#if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
   192         -#   define CYGWINMSVC
   193         -#endif
   194         -*/
   195         -
   196         -/**
   197         - * \def U_PLATFORM_USES_ONLY_WIN32_API
   198         - * Defines whether the platform uses only the Win32 API.
   199         - * Set to 1 for Windows/MSVC and MinGW but not Cygwin.
   200         - * @internal
   201         - */
   202         -#ifdef U_PLATFORM_USES_ONLY_WIN32_API
   203         -    /* Use the predefined value. */
   204         -#elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
   205         -#   define U_PLATFORM_USES_ONLY_WIN32_API 1
   206         -#else
   207         -    /* Cygwin implements POSIX. */
   208         -#   define U_PLATFORM_USES_ONLY_WIN32_API 0
   209         -#endif
   210         -
   211         -/**
   212         - * \def U_PLATFORM_HAS_WIN32_API
   213         - * Defines whether the Win32 API is available on the platform.
   214         - * Set to 1 for Windows/MSVC, MinGW and Cygwin.
   215         - * @internal
   216         - */
   217         -#ifdef U_PLATFORM_HAS_WIN32_API
   218         -    /* Use the predefined value. */
   219         -#elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
   220         -#   define U_PLATFORM_HAS_WIN32_API 1
   221         -#else
   222         -#   define U_PLATFORM_HAS_WIN32_API 0
   223         -#endif
   224         -
   225         -/**
   226         - * \def U_PLATFORM_IMPLEMENTS_POSIX
   227         - * Defines whether the platform implements (most of) the POSIX API.
   228         - * Set to 1 for Cygwin and most other platforms.
   229         - * @internal
   230         - */
   231         -#ifdef U_PLATFORM_IMPLEMENTS_POSIX
   232         -    /* Use the predefined value. */
   233         -#elif U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM == U_PF_CLASSIC_MACOS
   234         -#   define U_PLATFORM_IMPLEMENTS_POSIX 0
   235         -#else
   236         -#   define U_PLATFORM_IMPLEMENTS_POSIX 1
   237         -#endif
   238         -
   239         -/**
   240         - * \def U_PLATFORM_IS_LINUX_BASED
   241         - * Defines whether the platform is Linux or one of its derivatives.
   242         - * @internal
   243         - */
   244         -#ifdef U_PLATFORM_IS_LINUX_BASED
   245         -    /* Use the predefined value. */
   246         -#elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= U_PF_ANDROID
   247         -#   define U_PLATFORM_IS_LINUX_BASED 1
   248         -#else
   249         -#   define U_PLATFORM_IS_LINUX_BASED 0
   250         -#endif
   251         -
   252         -/**
   253         - * \def U_PLATFORM_IS_DARWIN_BASED
   254         - * Defines whether the platform is Darwin or one of its derivatives.
   255         - * @internal
   256         - */
   257         -#ifdef U_PLATFORM_IS_DARWIN_BASED
   258         -    /* Use the predefined value. */
   259         -#elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
   260         -#   define U_PLATFORM_IS_DARWIN_BASED 1
   261         -#else
   262         -#   define U_PLATFORM_IS_DARWIN_BASED 0
   263         -#endif
   264         -
   265         -/**
   266         - * \def U_HAVE_STDINT_H
   267         - * Defines whether stdint.h is available. It is a C99 standard header.
   268         - * We used to include inttypes.h which includes stdint.h but we usually do not need
   269         - * the additional definitions from inttypes.h.
   270         - * @internal
   271         - */
   272         -#ifdef U_HAVE_STDINT_H
   273         -    /* Use the predefined value. */
   274         -#elif U_PLATFORM_USES_ONLY_WIN32_API
   275         -#   if defined(__BORLANDC__) || U_PLATFORM == U_PF_MINGW || (defined(_MSC_VER) && _MSC_VER>=1600)
   276         -        /* Windows Visual Studio 9 and below do not have stdint.h & inttypes.h, but VS 2010 adds them. */
   277         -#       define U_HAVE_STDINT_H 1
   278         -#   else
   279         -#       define U_HAVE_STDINT_H 0
   280         -#   endif
   281         -#elif U_PLATFORM == U_PF_SOLARIS
   282         -    /* Solaris has inttypes.h but not stdint.h. */
   283         -#   define U_HAVE_STDINT_H 0
   284         -#elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
   285         -    /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
   286         -#   define U_HAVE_STDINT_H 0
   287         -#else
   288         -#   define U_HAVE_STDINT_H 1
   289         -#endif
   290         -
   291         -/**
   292         - * \def U_HAVE_INTTYPES_H
   293         - * Defines whether inttypes.h is available. It is a C99 standard header.
   294         - * We include inttypes.h where it is available but stdint.h is not.
   295         - * @internal
   296         - */
   297         -#ifdef U_HAVE_INTTYPES_H
   298         -    /* Use the predefined value. */
   299         -#elif U_PLATFORM == U_PF_SOLARIS
   300         -    /* Solaris has inttypes.h but not stdint.h. */
   301         -#   define U_HAVE_INTTYPES_H 1
   302         -#elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
   303         -    /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
   304         -#   define U_HAVE_INTTYPES_H 1
   305         -#else
   306         -    /* Most platforms have both inttypes.h and stdint.h, or neither. */
   307         -#   define U_HAVE_INTTYPES_H U_HAVE_STDINT_H
   308         -#endif
   309         -
   310         -/**
   311         - * \def U_IOSTREAM_SOURCE
   312         - * Defines what support for C++ streams is available.
   313         - *
   314         - * If U_IOSTREAM_SOURCE is set to 199711, then &lt;iostream&gt; is available
   315         - * (the ISO/IEC C++ FDIS was published in November 1997), and then
   316         - * one should qualify streams using the std namespace in ICU header
   317         - * files.
   318         - * Starting with ICU 49, this is the only supported version.
   319         - *
   320         - * If U_IOSTREAM_SOURCE is set to 198506, then &lt;iostream.h&gt; is
   321         - * available instead (in June 1985 Stroustrup published
   322         - * "An Extensible I/O Facility for C++" at the summer USENIX conference).
   323         - * Starting with ICU 49, this version is not supported any more.
   324         - *
   325         - * If U_IOSTREAM_SOURCE is 0 (or any value less than 199711),
   326         - * then C++ streams are not available and
   327         - * support for them will be silently suppressed in ICU.
   328         - *
   329         - * @internal
   330         - */
   331         -#ifndef U_IOSTREAM_SOURCE
   332         -#define U_IOSTREAM_SOURCE 199711
   333         -#endif
   334         -
   335         -/**
   336         - * \def U_HAVE_STD_STRING
   337         - * Defines whether the standard C++ (STL) &lt;string&gt; header is available.
   338         - * @internal
   339         - */
   340         -#ifdef U_HAVE_STD_STRING
   341         -    /* Use the predefined value. */
   342         -#elif U_PLATFORM == U_PF_ANDROID
   343         -#   define U_HAVE_STD_STRING 0
   344         -#else
   345         -#   define U_HAVE_STD_STRING 1
   346         -#endif
   347         -
   348         -/*===========================================================================*/
   349         -/** @{ Compiler and environment features                                     */
   350         -/*===========================================================================*/
   351         -
   352         -/**
   353         - * \def U_GCC_MAJOR_MINOR
   354         - * Indicates whether the compiler is gcc (test for != 0),
   355         - * and if so, contains its major (times 100) and minor version numbers.
   356         - * If the compiler is not gcc, then U_GCC_MAJOR_MINOR == 0.
   357         - *
   358         - * For example, for testing for whether we have gcc, and whether it's 4.6 or higher,
   359         - * use "#if U_GCC_MAJOR_MINOR >= 406".
   360         - * @internal
   361         - */
   362         -#ifdef __GNUC__
   363         -#   define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
   364         -#else
   365         -#   define U_GCC_MAJOR_MINOR 0
   366         -#endif
   367         -
   368         -/**
   369         - * \def U_IS_BIG_ENDIAN
   370         - * Determines the endianness of the platform.
   371         - * @internal
   372         - */
   373         -#ifdef U_IS_BIG_ENDIAN
   374         -    /* Use the predefined value. */
   375         -#elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
   376         -#   define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
   377         -#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
   378         -    /* gcc */
   379         -#   define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
   380         -#elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
   381         -#   define U_IS_BIG_ENDIAN 1
   382         -#elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
   383         -#   define U_IS_BIG_ENDIAN 0
   384         -#elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
   385         -    /* These platforms do not appear to predefine any endianness macros. */
   386         -#   define U_IS_BIG_ENDIAN 1
   387         -#elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
   388         -    /* HPPA do not appear to predefine any endianness macros. */
   389         -#   define U_IS_BIG_ENDIAN 1
   390         -#elif defined(sparc) || defined(__sparc) || defined(__sparc__)
   391         -    /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
   392         -#   define U_IS_BIG_ENDIAN 1
   393         -#else
   394         -#   define U_IS_BIG_ENDIAN 0
   395         -#endif
   396         -
   397         -/**
   398         - * \def U_HAVE_PLACEMENT_NEW
   399         - * Determines whether to override placement new and delete for STL.
   400         - * @stable ICU 2.6
   401         - */
   402         -#ifdef U_HAVE_PLACEMENT_NEW
   403         -    /* Use the predefined value. */
   404         -#elif defined(__BORLANDC__)
   405         -#   define U_HAVE_PLACEMENT_NEW 0
   406         -#else
   407         -#   define U_HAVE_PLACEMENT_NEW 1
   408         -#endif
   409         -
   410         -/**
   411         - * \def U_HAVE_DEBUG_LOCATION_NEW 
   412         - * Define this to define the MFC debug version of the operator new.
   413         - *
   414         - * @stable ICU 3.4
   415         - */
   416         -#ifdef U_HAVE_DEBUG_LOCATION_NEW
   417         -    /* Use the predefined value. */
   418         -#elif defined(_MSC_VER)
   419         -#   define U_HAVE_DEBUG_LOCATION_NEW 1
   420         -#else
   421         -#   define U_HAVE_DEBUG_LOCATION_NEW 0
   422         -#endif
   423         -
   424         -/* Compatibility with non clang compilers */
   425         -#ifndef __has_attribute
   426         -#    define __has_attribute(x) 0
   427         -#endif
   428         -
   429         -/**
   430         - * \def U_MALLOC_ATTR
   431         - * Attribute to mark functions as malloc-like
   432         - * @internal
   433         - */
   434         -#if defined(__GNUC__) && __GNUC__>=3
   435         -#    define U_MALLOC_ATTR __attribute__ ((__malloc__))
   436         -#else
   437         -#    define U_MALLOC_ATTR
   438         -#endif
   439         -
   440         -/**
   441         - * \def U_ALLOC_SIZE_ATTR
   442         - * Attribute to specify the size of the allocated buffer for malloc-like functions
   443         - * @internal
   444         - */
   445         -#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || __has_attribute(alloc_size)
   446         -#   define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
   447         -#   define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
   448         -#else
   449         -#   define U_ALLOC_SIZE_ATTR(X)
   450         -#   define U_ALLOC_SIZE_ATTR2(X,Y)
   451         -#endif
   452         -
   453         -/** @} */
   454         -
   455         -/*===========================================================================*/
   456         -/** @{ Character data types                                                  */
   457         -/*===========================================================================*/
   458         -
   459         -/**
   460         - * U_CHARSET_FAMILY is equal to this value when the platform is an ASCII based platform.
   461         - * @stable ICU 2.0
   462         - */
   463         -#define U_ASCII_FAMILY 0
   464         -
   465         -/**
   466         - * U_CHARSET_FAMILY is equal to this value when the platform is an EBCDIC based platform.
   467         - * @stable ICU 2.0
   468         - */
   469         -#define U_EBCDIC_FAMILY 1
   470         -
   471         -/**
   472         - * \def U_CHARSET_FAMILY
   473         - *
   474         - * <p>These definitions allow to specify the encoding of text
   475         - * in the char data type as defined by the platform and the compiler.
   476         - * It is enough to determine the code point values of "invariant characters",
   477         - * which are the ones shared by all encodings that are in use
   478         - * on a given platform.</p>
   479         - *
   480         - * <p>Those "invariant characters" should be all the uppercase and lowercase
   481         - * latin letters, the digits, the space, and "basic punctuation".
   482         - * Also, '\\n', '\\r', '\\t' should be available.</p>
   483         - *
   484         - * <p>The list of "invariant characters" is:<br>
   485         - * \code
   486         - *    A-Z  a-z  0-9  SPACE  "  %  &amp;  '  (  )  *  +  ,  -  .  /  :  ;  <  =  >  ?  _
   487         - * \endcode
   488         - * <br>
   489         - * (52 letters + 10 numbers + 20 punc/sym/space = 82 total)</p>
   490         - *
   491         - * <p>This matches the IBM Syntactic Character Set (CS 640).</p>
   492         - *
   493         - * <p>In other words, all the graphic characters in 7-bit ASCII should
   494         - * be safely accessible except the following:</p>
   495         - *
   496         - * \code
   497         - *    '\' <backslash>
   498         - *    '[' <left bracket>
   499         - *    ']' <right bracket>
   500         - *    '{' <left brace>
   501         - *    '}' <right brace>
   502         - *    '^' <circumflex>
   503         - *    '~' <tilde>
   504         - *    '!' <exclamation mark>
   505         - *    '#' <number sign>
   506         - *    '|' <vertical line>
   507         - *    '$' <dollar sign>
   508         - *    '@' <commercial at>
   509         - *    '`' <grave accent>
   510         - * \endcode
   511         - * @stable ICU 2.0
   512         - */
   513         -#ifdef U_CHARSET_FAMILY
   514         -    /* Use the predefined value. */
   515         -#elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
   516         -#   define U_CHARSET_FAMILY U_EBCDIC_FAMILY
   517         -#elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
   518         -#   define U_CHARSET_FAMILY U_EBCDIC_FAMILY
   519         -#else
   520         -#   define U_CHARSET_FAMILY U_ASCII_FAMILY
   521         -#endif
   522         -
   523         -/**
   524         - * \def U_CHARSET_IS_UTF8
   525         - *
   526         - * Hardcode the default charset to UTF-8.
   527         - *
   528         - * If this is set to 1, then
   529         - * - ICU will assume that all non-invariant char*, StringPiece, std::string etc.
   530         - *   contain UTF-8 text, regardless of what the system API uses
   531         - * - some ICU code will use fast functions like u_strFromUTF8()
   532         - *   rather than the more general and more heavy-weight conversion API (ucnv.h)
   533         - * - ucnv_getDefaultName() always returns "UTF-8"
   534         - * - ucnv_setDefaultName() is disabled and will not change the default charset
   535         - * - static builds of ICU are smaller
   536         - * - more functionality is available with the UCONFIG_NO_CONVERSION build-time
   537         - *   configuration option (see unicode/uconfig.h)
   538         - * - the UCONFIG_NO_CONVERSION build option in uconfig.h is more usable
   539         - *
   540         - * @stable ICU 4.2
   541         - * @see UCONFIG_NO_CONVERSION
   542         - */
   543         -#ifdef U_CHARSET_IS_UTF8
   544         -    /* Use the predefined value. */
   545         -#elif U_PLATFORM == U_PF_ANDROID || U_PLATFORM_IS_DARWIN_BASED
   546         -#   define U_CHARSET_IS_UTF8 1
   547         -#elif U_PLATFORM_IS_LINUX_BASED
   548         -   /*
   549         -    * Google-specific: Set to 1 to match the google3 execution environment's
   550         -    * use of UTF-8, on both Linux server and workstation machines.
   551         -    */
   552         -#   define U_CHARSET_IS_UTF8 1
   553         -#else
   554         -#   define U_CHARSET_IS_UTF8 0
   555         -#endif
   556         -
   557         -/** @} */
   558         -
   559         -/*===========================================================================*/
   560         -/** @{ Information about wchar support                                       */
   561         -/*===========================================================================*/
   562         -
   563         -/**
   564         - * \def U_HAVE_WCHAR_H
   565         - * Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default.
   566         - *
   567         - * @stable ICU 2.0
   568         - */
   569         -#ifdef U_HAVE_WCHAR_H
   570         -    /* Use the predefined value. */
   571         -#elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
   572         -    /*
   573         -     * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
   574         -     * The type and header existed, but the library functions did not work as expected.
   575         -     * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
   576         -     */
   577         -#   define U_HAVE_WCHAR_H 0
   578         -#else
   579         -#   define U_HAVE_WCHAR_H 1
   580         -#endif
   581         -
   582         -/**
   583         - * \def U_SIZEOF_WCHAR_T
   584         - * U_SIZEOF_WCHAR_T==sizeof(wchar_t)
   585         - *
   586         - * @stable ICU 2.0
   587         - */
   588         -#ifdef U_SIZEOF_WCHAR_T
   589         -    /* Use the predefined value. */
   590         -#elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9) || U_PLATFORM == U_PF_CLASSIC_MACOS
   591         -    /*
   592         -     * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
   593         -     * Newer Mac OS X has size 4.
   594         -     */
   595         -#   define U_SIZEOF_WCHAR_T 1
   596         -#elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
   597         -#   define U_SIZEOF_WCHAR_T 2
   598         -#elif U_PLATFORM == U_PF_AIX
   599         -    /*
   600         -     * AIX 6.1 information, section "Wide character data representation":
   601         -     * "... the wchar_t datatype is 32-bit in the 64-bit environment and
   602         -     * 16-bit in the 32-bit environment."
   603         -     * and
   604         -     * "All locales use Unicode for their wide character code values (process code),
   605         -     * except the IBM-eucTW codeset."
   606         -     */
   607         -#   ifdef __64BIT__
   608         -#       define U_SIZEOF_WCHAR_T 4
   609         -#   else
   610         -#       define U_SIZEOF_WCHAR_T 2
   611         -#   endif
   612         -#elif U_PLATFORM == U_PF_OS390
   613         -    /*
   614         -     * z/OS V1R11 information center, section "LP64 | ILP32":
   615         -     * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
   616         -     * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
   617         -     */
   618         -#   ifdef _LP64
   619         -#       define U_SIZEOF_WCHAR_T 4
   620         -#   else
   621         -#       define U_SIZEOF_WCHAR_T 2
   622         -#   endif
   623         -#elif U_PLATFORM == U_PF_OS400
   624         -#   if defined(__UTF32__)
   625         -        /*
   626         -         * LOCALETYPE(*LOCALEUTF) is specified.
   627         -         * Wide-character strings are in UTF-32,
   628         -         * narrow-character strings are in UTF-8.
   629         -         */
   630         -#       define U_SIZEOF_WCHAR_T 4
   631         -#   elif defined(__UCS2__)
   632         -        /*
   633         -         * LOCALETYPE(*LOCALEUCS2) is specified.
   634         -         * Wide-character strings are in UCS-2,
   635         -         * narrow-character strings are in EBCDIC.
   636         -         */
   637         -#       define U_SIZEOF_WCHAR_T 2
   638         -#else
   639         -        /*
   640         -         * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
   641         -         * Wide-character strings are in 16-bit EBCDIC,
   642         -         * narrow-character strings are in EBCDIC.
   643         -         */
   644         -#       define U_SIZEOF_WCHAR_T 2
   645         -#   endif
   646         -#else
   647         -#   define U_SIZEOF_WCHAR_T 4
   648         -#endif
   649         -
   650         -#ifndef U_HAVE_WCSCPY
   651         -#define U_HAVE_WCSCPY U_HAVE_WCHAR_H
   652         -#endif
   653         -
   654         -/** @} */
   655         -
   656         -/**
   657         - * \def U_HAVE_CHAR16_T
   658         - * Defines whether the char16_t type is available for UTF-16
   659         - * and u"abc" UTF-16 string literals are supported.
   660         - * This is a new standard type and standard string literal syntax in C++0x
   661         - * but has been available in some compilers before.
   662         - * @internal
   663         - */
   664         -#ifdef U_HAVE_CHAR16_T
   665         -    /* Use the predefined value. */
   666         -#else
   667         -    /*
   668         -     * Notes:
   669         -     * Visual Studio 10 (_MSC_VER>=1600) defines char16_t but
   670         -     * does not support u"abc" string literals.
   671         -     * gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but
   672         -     * does not support u"abc" string literals.
   673         -     * C++11 and C11 require support for UTF-16 literals
   674         -     */
   675         -#   if (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
   676         -#       define U_HAVE_CHAR16_T 1
   677         -#   else
   678         -#       define U_HAVE_CHAR16_T 0
   679         -#   endif
   680         -#endif
   681         -
   682         -/**
   683         - * @{
   684         - * \def U_DECLARE_UTF16
   685         - * Do not use this macro because it is not defined on all platforms.
   686         - * Use the UNICODE_STRING or U_STRING_DECL macros instead.
   687         - * @internal
   688         - */
   689         -#ifdef U_DECLARE_UTF16
   690         -    /* Use the predefined value. */
   691         -#elif U_HAVE_CHAR16_T \
   692         -    || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
   693         -    || (defined(__HP_aCC) && __HP_aCC >= 035000) \
   694         -    || (defined(__HP_cc) && __HP_cc >= 111106)
   695         -#   define U_DECLARE_UTF16(string) u ## string
   696         -#elif U_SIZEOF_WCHAR_T == 2 \
   697         -    && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
   698         -#   define U_DECLARE_UTF16(string) L ## string
   699         -#else
   700         -    /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
   701         -#endif
   702         -
   703         -/** @} */
   704         -
   705         -/*===========================================================================*/
   706         -/** @{ Symbol import-export control                                          */
   707         -/*===========================================================================*/
   708         -
   709         -#ifdef U_EXPORT
   710         -    /* Use the predefined value. */
   711         -#elif defined(U_STATIC_IMPLEMENTATION)
   712         -#   define U_EXPORT
   713         -#elif defined(__GNUC__)
   714         -#   define U_EXPORT __attribute__((visibility("default")))
   715         -#elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
   716         -   || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550) 
   717         -#   define U_EXPORT __global
   718         -/*#elif defined(__HP_aCC) || defined(__HP_cc)
   719         -#   define U_EXPORT __declspec(dllexport)*/
   720         -#elif defined(_MSC_VER)
   721         -#   define U_EXPORT __declspec(dllexport)
   722         -#else
   723         -#   define U_EXPORT
   724         -#endif
   725         -
   726         -/* U_CALLCONV is releated to U_EXPORT2 */
   727         -#ifdef U_EXPORT2
   728         -    /* Use the predefined value. */
   729         -#elif defined(_MSC_VER)
   730         -#   define U_EXPORT2 __cdecl
   731         -#else
   732         -#   define U_EXPORT2
   733         -#endif
   734         -
   735         -#ifdef U_IMPORT
   736         -    /* Use the predefined value. */
   737         -#elif defined(_MSC_VER)
   738         -    /* Windows needs to export/import data. */
   739         -#   define U_IMPORT __declspec(dllimport)
   740         -#else
   741         -#   define U_IMPORT 
   742         -#endif
   743         -
   744         -/**
   745         - * \def U_CALLCONV
   746         - * Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary
   747         - * in callback function typedefs to make sure that the calling convention
   748         - * is compatible.
   749         - *
   750         - * This is only used for non-ICU-API functions.
   751         - * When a function is a public ICU API,
   752         - * you must use the U_CAPI and U_EXPORT2 qualifiers.
   753         - * @stable ICU 2.0
   754         - */
   755         -#if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
   756         -#    define U_CALLCONV __cdecl
   757         -#else
   758         -#    define U_CALLCONV U_EXPORT2
   759         -#endif
   760         -
   761         -/* @} */
   762         -
   763         -#endif

Deleted jni/tcl/pkgs/sqlite3.28.0/icu4c/unicode/ptypes.h.

     1         -/*
     2         -******************************************************************************
     3         -*
     4         -*   Copyright (C) 1997-2012, International Business Machines
     5         -*   Corporation and others.  All Rights Reserved.
     6         -*
     7         -******************************************************************************
     8         -*
     9         -*  FILE NAME : ptypes.h
    10         -*
    11         -*   Date        Name        Description
    12         -*   05/13/98    nos         Creation (content moved here from ptypes.h).
    13         -*   03/02/99    stephen     Added AS400 support.
    14         -*   03/30/99    stephen     Added Linux support.
    15         -*   04/13/99    stephen     Reworked for autoconf.
    16         -*   09/18/08    srl         Moved basic types back to ptypes.h from platform.h
    17         -******************************************************************************
    18         -*/
    19         -
    20         -/**
    21         - * \file
    22         - * \brief C API: Definitions of integer types of various widths
    23         - */
    24         -
    25         -#ifndef _PTYPES_H
    26         -#define _PTYPES_H
    27         -
    28         -/**
    29         - * \def __STDC_LIMIT_MACROS
    30         - * According to the Linux stdint.h, the ISO C99 standard specifies that in C++ implementations
    31         - * macros like INT32_MIN and UINTPTR_MAX should only be defined if explicitly requested.
    32         - * We need to define __STDC_LIMIT_MACROS before including stdint.h in C++ code
    33         - * that uses such limit macros.
    34         - * @internal
    35         - */
    36         -#ifndef __STDC_LIMIT_MACROS
    37         -#define __STDC_LIMIT_MACROS
    38         -#endif
    39         -
    40         -/* NULL, size_t, wchar_t */
    41         -#include <stddef.h>
    42         -
    43         -/*
    44         - * If all compilers provided all of the C99 headers and types,
    45         - * we would just unconditionally #include <stdint.h> here
    46         - * and not need any of the stuff after including platform.h.
    47         - */
    48         -
    49         -/* Find out if we have stdint.h etc. */
    50         -#include "unicode/platform.h"
    51         -
    52         -/*===========================================================================*/
    53         -/* Generic data types                                                        */
    54         -/*===========================================================================*/
    55         -
    56         -/* If your platform does not have the <stdint.h> header, you may
    57         -   need to edit the typedefs in the #else section below.
    58         -   Use #if...#else...#endif with predefined compiler macros if possible. */
    59         -#if U_HAVE_STDINT_H
    60         -
    61         -/*
    62         - * We mostly need <stdint.h> (which defines the standard integer types) but not <inttypes.h>.
    63         - * <inttypes.h> includes <stdint.h> and adds the printf/scanf helpers PRId32, SCNx16 etc.
    64         - * which we almost never use, plus stuff like imaxabs() which we never use.
    65         - */
    66         -#include <stdint.h>
    67         -
    68         -#if U_PLATFORM == U_PF_OS390
    69         -/* The features header is needed to get (u)int64_t sometimes. */
    70         -#include <features.h>
    71         -/* z/OS has <stdint.h>, but some versions are missing uint8_t (APAR PK62248). */
    72         -#if !defined(__uint8_t)
    73         -#define __uint8_t 1
    74         -typedef unsigned char uint8_t;
    75         -#endif
    76         -#endif /* U_PLATFORM == U_PF_OS390 */
    77         -
    78         -#elif U_HAVE_INTTYPES_H
    79         -
    80         -#   include <inttypes.h>
    81         -
    82         -#else /* neither U_HAVE_STDINT_H nor U_HAVE_INTTYPES_H */
    83         -
    84         -#if ! U_HAVE_INT8_T
    85         -typedef signed char int8_t;
    86         -#endif
    87         -
    88         -#if ! U_HAVE_UINT8_T
    89         -typedef unsigned char uint8_t;
    90         -#endif
    91         -
    92         -#if ! U_HAVE_INT16_T
    93         -typedef signed short int16_t;
    94         -#endif
    95         -
    96         -#if ! U_HAVE_UINT16_T
    97         -typedef unsigned short uint16_t;
    98         -#endif
    99         -
   100         -#if ! U_HAVE_INT32_T
   101         -typedef signed int int32_t;
   102         -#endif
   103         -
   104         -#if ! U_HAVE_UINT32_T
   105         -typedef unsigned int uint32_t;
   106         -#endif
   107         -
   108         -#if ! U_HAVE_INT64_T
   109         -#ifdef _MSC_VER
   110         -    typedef signed __int64 int64_t;
   111         -#else
   112         -    typedef signed long long int64_t;
   113         -#endif
   114         -#endif
   115         -
   116         -#if ! U_HAVE_UINT64_T
   117         -#ifdef _MSC_VER
   118         -    typedef unsigned __int64 uint64_t;
   119         -#else
   120         -    typedef unsigned long long uint64_t;
   121         -#endif
   122         -#endif
   123         -
   124         -#endif /* U_HAVE_STDINT_H / U_HAVE_INTTYPES_H */
   125         -
   126         -#endif /* _PTYPES_H */

Deleted jni/tcl/pkgs/sqlite3.28.0/icu4c/unicode/putil.h.

     1         -/*
     2         -******************************************************************************
     3         -*
     4         -*   Copyright (C) 1997-2011, International Business Machines
     5         -*   Corporation and others.  All Rights Reserved.
     6         -*
     7         -******************************************************************************
     8         -*
     9         -*  FILE NAME : putil.h
    10         -*
    11         -*   Date        Name        Description
    12         -*   05/14/98    nos         Creation (content moved here from utypes.h).
    13         -*   06/17/99    erm         Added IEEE_754
    14         -*   07/22/98    stephen     Added IEEEremainder, max, min, trunc
    15         -*   08/13/98    stephen     Added isNegativeInfinity, isPositiveInfinity
    16         -*   08/24/98    stephen     Added longBitsFromDouble
    17         -*   03/02/99    stephen     Removed openFile().  Added AS400 support.
    18         -*   04/15/99    stephen     Converted to C
    19         -*   11/15/99    helena      Integrated S/390 changes for IEEE support.
    20         -*   01/11/00    helena      Added u_getVersion.
    21         -******************************************************************************
    22         -*/
    23         -
    24         -#ifndef PUTIL_H
    25         -#define PUTIL_H
    26         -
    27         -#include "unicode/utypes.h"
    28         - /**
    29         -  * \file
    30         -  * \brief C API: Platform Utilities
    31         -  */
    32         -
    33         -/*==========================================================================*/
    34         -/* Platform utilities                                                       */
    35         -/*==========================================================================*/
    36         -
    37         -/**
    38         - * Platform utilities isolates the platform dependencies of the
    39         - * libarary.  For each platform which this code is ported to, these
    40         - * functions may have to be re-implemented.
    41         - */
    42         -
    43         -/**
    44         - * Return the ICU data directory. 
    45         - * The data directory is where common format ICU data files (.dat files)
    46         - *   are loaded from.  Note that normal use of the built-in ICU
    47         - *   facilities does not require loading of an external data file;
    48         - *   unless you are adding custom data to ICU, the data directory
    49         - *   does not need to be set.
    50         - *
    51         - * The data directory is determined as follows:
    52         - *    If u_setDataDirectory() has been called, that is it, otherwise
    53         - *    if the ICU_DATA environment variable is set, use that, otherwise
    54         - *    If a data directory was specifed at ICU build time
    55         - *      <code>
    56         - * \code
    57         - *        #define ICU_DATA_DIR "path" 
    58         - * \endcode
    59         - * </code> use that,
    60         - *    otherwise no data directory is available.
    61         - *
    62         - * @return the data directory, or an empty string ("") if no data directory has
    63         - *         been specified.
    64         - *   
    65         - * @stable ICU 2.0
    66         - */
    67         -U_STABLE const char* U_EXPORT2 u_getDataDirectory(void);
    68         -
    69         -/** 
    70         - * Set the ICU data directory. 
    71         - * The data directory is where common format ICU data files (.dat files)
    72         - *   are loaded from.  Note that normal use of the built-in ICU
    73         - *   facilities does not require loading of an external data file;
    74         - *   unless you are adding custom data to ICU, the data directory
    75         - *   does not need to be set.
    76         - *
    77         - * This function should be called at most once in a process, before the
    78         - * first ICU operation (e.g., u_init()) that will require the loading of an
    79         - * ICU data file.
    80         - * This function is not thread-safe. Use it before calling ICU APIs from
    81         - * multiple threads.
    82         - *
    83         - * @param directory The directory to be set.
    84         - *
    85         - * @see u_init
    86         - * @stable ICU 2.0
    87         - */
    88         -U_STABLE void U_EXPORT2 u_setDataDirectory(const char *directory);
    89         -
    90         -/**
    91         - * @{
    92         - * Filesystem file and path separator characters.
    93         - * Example: '/' and ':' on Unix, '\\' and ';' on Windows.
    94         - * @stable ICU 2.0
    95         - */
    96         -#if U_PLATFORM == U_PF_CLASSIC_MACOS
    97         -#   define U_FILE_SEP_CHAR ':'
    98         -#   define U_FILE_ALT_SEP_CHAR ':'
    99         -#   define U_PATH_SEP_CHAR ';'
   100         -#   define U_FILE_SEP_STRING ":"
   101         -#   define U_FILE_ALT_SEP_STRING ":"
   102         -#   define U_PATH_SEP_STRING ";"
   103         -#elif U_PLATFORM_USES_ONLY_WIN32_API
   104         -#   define U_FILE_SEP_CHAR '\\'
   105         -#   define U_FILE_ALT_SEP_CHAR '/'
   106         -#   define U_PATH_SEP_CHAR ';'
   107         -#   define U_FILE_SEP_STRING "\\"
   108         -#   define U_FILE_ALT_SEP_STRING "/"
   109         -#   define U_PATH_SEP_STRING ";"
   110         -#else
   111         -#   define U_FILE_SEP_CHAR '/'
   112         -#   define U_FILE_ALT_SEP_CHAR '/'
   113         -#   define U_PATH_SEP_CHAR ':'
   114         -#   define U_FILE_SEP_STRING "/"
   115         -#   define U_FILE_ALT_SEP_STRING "/"
   116         -#   define U_PATH_SEP_STRING ":"
   117         -#endif
   118         -
   119         -/** @} */
   120         -
   121         -/**
   122         - * Convert char characters to UChar characters.
   123         - * This utility function is useful only for "invariant characters"
   124         - * that are encoded in the platform default encoding.
   125         - * They are a small, constant subset of the encoding and include
   126         - * just the latin letters, digits, and some punctuation.
   127         - * For details, see U_CHARSET_FAMILY.
   128         - *
   129         - * @param cs Input string, points to <code>length</code>
   130         - *           character bytes from a subset of the platform encoding.
   131         - * @param us Output string, points to memory for <code>length</code>
   132         - *           Unicode characters.
   133         - * @param length The number of characters to convert; this may
   134         - *               include the terminating <code>NUL</code>.
   135         - *
   136         - * @see U_CHARSET_FAMILY
   137         - * @stable ICU 2.0
   138         - */
   139         -U_STABLE void U_EXPORT2
   140         -u_charsToUChars(const char *cs, UChar *us, int32_t length);
   141         -
   142         -/**
   143         - * Convert UChar characters to char characters.
   144         - * This utility function is useful only for "invariant characters"
   145         - * that can be encoded in the platform default encoding.
   146         - * They are a small, constant subset of the encoding and include
   147         - * just the latin letters, digits, and some punctuation.
   148         - * For details, see U_CHARSET_FAMILY.
   149         - *
   150         - * @param us Input string, points to <code>length</code>
   151         - *           Unicode characters that can be encoded with the
   152         - *           codepage-invariant subset of the platform encoding.
   153         - * @param cs Output string, points to memory for <code>length</code>
   154         - *           character bytes.
   155         - * @param length The number of characters to convert; this may
   156         - *               include the terminating <code>NUL</code>.
   157         - *
   158         - * @see U_CHARSET_FAMILY
   159         - * @stable ICU 2.0
   160         - */
   161         -U_STABLE void U_EXPORT2
   162         -u_UCharsToChars(const UChar *us, char *cs, int32_t length);
   163         -
   164         -#endif

Deleted jni/tcl/pkgs/sqlite3.28.0/icu4c/unicode/ubrk.h.

     1         -/*
     2         -******************************************************************************
     3         -* Copyright (C) 1996-2013, International Business Machines Corporation and others.
     4         -* All Rights Reserved.
     5         -******************************************************************************
     6         -*/
     7         -
     8         -#ifndef UBRK_H
     9         -#define UBRK_H
    10         -
    11         -#include "unicode/utypes.h"
    12         -#include "unicode/uloc.h"
    13         -#include "unicode/utext.h"
    14         -#include "unicode/localpointer.h"
    15         -
    16         -/**
    17         - * A text-break iterator.
    18         - *  For usage in C programs.
    19         - */
    20         -#ifndef UBRK_TYPEDEF_UBREAK_ITERATOR
    21         -#   define UBRK_TYPEDEF_UBREAK_ITERATOR
    22         -    /**
    23         -     *  Opaque type representing an ICU Break iterator object.
    24         -     *  @stable ICU 2.0
    25         -     */
    26         -    typedef struct UBreakIterator UBreakIterator;
    27         -#endif
    28         -
    29         -#if !UCONFIG_NO_BREAK_ITERATION
    30         -
    31         -#include "unicode/parseerr.h"
    32         -
    33         -/**
    34         - * \file
    35         - * \brief C API: BreakIterator
    36         - *
    37         - * <h2> BreakIterator C API </h2>
    38         - *
    39         - * The BreakIterator C API defines  methods for finding the location
    40         - * of boundaries in text. Pointer to a UBreakIterator maintain a
    41         - * current position and scan over text returning the index of characters
    42         - * where boundaries occur.
    43         - * <p>
    44         - * Line boundary analysis determines where a text string can be broken
    45         - * when line-wrapping. The mechanism correctly handles punctuation and
    46         - * hyphenated words.
    47         - * <p>
    48         - * Sentence boundary analysis allows selection with correct
    49         - * interpretation of periods within numbers and abbreviations, and
    50         - * trailing punctuation marks such as quotation marks and parentheses.
    51         - * <p>
    52         - * Word boundary analysis is used by search and replace functions, as
    53         - * well as within text editing applications that allow the user to
    54         - * select words with a double click. Word selection provides correct
    55         - * interpretation of punctuation marks within and following
    56         - * words. Characters that are not part of a word, such as symbols or
    57         - * punctuation marks, have word-breaks on both sides.
    58         - * <p>
    59         - * Character boundary analysis identifies the boundaries of
    60         - * "Extended Grapheme Clusters", which are groupings of codepoints
    61         - * that should be treated as character-like units for many text operations.
    62         - * Please see Unicode Standard Annex #29, Unicode Text Segmentation,
    63         - * http://www.unicode.org/reports/tr29/ for additional information 
    64         - * on grapheme clusters and guidelines on their use.
    65         - * <p>
    66         - * Title boundary analysis locates all positions,
    67         - * typically starts of words, that should be set to Title Case
    68         - * when title casing the text.
    69         - * <p>
    70         - * The text boundary positions are found according to the rules
    71         - * described in Unicode Standard Annex #29, Text Boundaries, and
    72         - * Unicode Standard Annex #14, Line Breaking Properties.  These
    73         - * are available at http://www.unicode.org/reports/tr14/ and
    74         - * http://www.unicode.org/reports/tr29/.
    75         - * <p>
    76         - * In addition to the plain C API defined in this header file, an
    77         - * object oriented C++ API with equivalent functionality is defined in the
    78         - * file brkiter.h.
    79         - * <p>
    80         - * Code snippets illustrating the use of the Break Iterator APIs
    81         - * are available in the ICU User Guide,
    82         - * http://icu-project.org/userguide/boundaryAnalysis.html
    83         - * and in the sample program icu/source/samples/break/break.cpp
    84         - */
    85         -
    86         -/** The possible types of text boundaries.  @stable ICU 2.0 */
    87         -typedef enum UBreakIteratorType {
    88         -  /** Character breaks  @stable ICU 2.0 */
    89         -  UBRK_CHARACTER = 0,
    90         -  /** Word breaks @stable ICU 2.0 */
    91         -  UBRK_WORD = 1,
    92         -  /** Line breaks @stable ICU 2.0 */
    93         -  UBRK_LINE = 2,
    94         -  /** Sentence breaks @stable ICU 2.0 */
    95         -  UBRK_SENTENCE = 3,
    96         -
    97         -#ifndef U_HIDE_DEPRECATED_API
    98         -  /**
    99         -   * Title Case breaks
   100         -   * The iterator created using this type locates title boundaries as described for
   101         -   * Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration,
   102         -   * please use Word Boundary iterator.
   103         -   *
   104         -   * @deprecated ICU 2.8 Use the word break iterator for titlecasing for Unicode 4 and later.
   105         -   */
   106         -  UBRK_TITLE = 4,
   107         -#endif /* U_HIDE_DEPRECATED_API */
   108         -  UBRK_COUNT = 5
   109         -} UBreakIteratorType;
   110         -
   111         -/** Value indicating all text boundaries have been returned.
   112         - *  @stable ICU 2.0
   113         - */
   114         -#define UBRK_DONE ((int32_t) -1)
   115         -
   116         -
   117         -/**
   118         - *  Enum constants for the word break tags returned by
   119         - *  getRuleStatus().  A range of values is defined for each category of
   120         - *  word, to allow for further subdivisions of a category in future releases.
   121         - *  Applications should check for tag values falling within the range, rather
   122         - *  than for single individual values.
   123         - *  @stable ICU 2.2
   124         -*/
   125         -typedef enum UWordBreak {
   126         -    /** Tag value for "words" that do not fit into any of other categories.
   127         -     *  Includes spaces and most punctuation. */
   128         -    UBRK_WORD_NONE           = 0,
   129         -    /** Upper bound for tags for uncategorized words. */
   130         -    UBRK_WORD_NONE_LIMIT     = 100,
   131         -    /** Tag value for words that appear to be numbers, lower limit.    */
   132         -    UBRK_WORD_NUMBER         = 100,
   133         -    /** Tag value for words that appear to be numbers, upper limit.    */
   134         -    UBRK_WORD_NUMBER_LIMIT   = 200,
   135         -    /** Tag value for words that contain letters, excluding
   136         -     *  hiragana, katakana or ideographic characters, lower limit.    */
   137         -    UBRK_WORD_LETTER         = 200,
   138         -    /** Tag value for words containing letters, upper limit  */
   139         -    UBRK_WORD_LETTER_LIMIT   = 300,
   140         -    /** Tag value for words containing kana characters, lower limit */
   141         -    UBRK_WORD_KANA           = 300,
   142         -    /** Tag value for words containing kana characters, upper limit */
   143         -    UBRK_WORD_KANA_LIMIT     = 400,
   144         -    /** Tag value for words containing ideographic characters, lower limit */
   145         -    UBRK_WORD_IDEO           = 400,
   146         -    /** Tag value for words containing ideographic characters, upper limit */
   147         -    UBRK_WORD_IDEO_LIMIT     = 500
   148         -} UWordBreak;
   149         -
   150         -/**
   151         - *  Enum constants for the line break tags returned by getRuleStatus().
   152         - *  A range of values is defined for each category of
   153         - *  word, to allow for further subdivisions of a category in future releases.
   154         - *  Applications should check for tag values falling within the range, rather
   155         - *  than for single individual values.
   156         - *  @stable ICU 2.8
   157         -*/
   158         -typedef enum ULineBreakTag {
   159         -    /** Tag value for soft line breaks, positions at which a line break
   160         -      *  is acceptable but not required                */
   161         -    UBRK_LINE_SOFT            = 0,
   162         -    /** Upper bound for soft line breaks.              */
   163         -    UBRK_LINE_SOFT_LIMIT      = 100,
   164         -    /** Tag value for a hard, or mandatory line break  */
   165         -    UBRK_LINE_HARD            = 100,
   166         -    /** Upper bound for hard line breaks.              */
   167         -    UBRK_LINE_HARD_LIMIT      = 200
   168         -} ULineBreakTag;
   169         -
   170         -
   171         -
   172         -/**
   173         - *  Enum constants for the sentence break tags returned by getRuleStatus().
   174         - *  A range of values is defined for each category of
   175         - *  sentence, to allow for further subdivisions of a category in future releases.
   176         - *  Applications should check for tag values falling within the range, rather
   177         - *  than for single individual values.
   178         - *  @stable ICU 2.8
   179         -*/
   180         -typedef enum USentenceBreakTag {
   181         -    /** Tag value for for sentences  ending with a sentence terminator
   182         -      * ('.', '?', '!', etc.) character, possibly followed by a
   183         -      * hard separator (CR, LF, PS, etc.)
   184         -      */
   185         -    UBRK_SENTENCE_TERM       = 0,
   186         -    /** Upper bound for tags for sentences ended by sentence terminators.    */
   187         -    UBRK_SENTENCE_TERM_LIMIT = 100,
   188         -    /** Tag value for for sentences that do not contain an ending
   189         -      * sentence terminator ('.', '?', '!', etc.) character, but
   190         -      * are ended only by a hard separator (CR, LF, PS, etc.) or end of input.
   191         -      */
   192         -    UBRK_SENTENCE_SEP        = 100,
   193         -    /** Upper bound for tags for sentences ended by a separator.              */
   194         -    UBRK_SENTENCE_SEP_LIMIT  = 200
   195         -    /** Tag value for a hard, or mandatory line break  */
   196         -} USentenceBreakTag;
   197         -
   198         -
   199         -/**
   200         - * Open a new UBreakIterator for locating text boundaries for a specified locale.
   201         - * A UBreakIterator may be used for detecting character, line, word,
   202         - * and sentence breaks in text.
   203         - * @param type The type of UBreakIterator to open: one of UBRK_CHARACTER, UBRK_WORD,
   204         - * UBRK_LINE, UBRK_SENTENCE
   205         - * @param locale The locale specifying the text-breaking conventions.
   206         - * @param text The text to be iterated over.
   207         - * @param textLength The number of characters in text, or -1 if null-terminated.
   208         - * @param status A UErrorCode to receive any errors.
   209         - * @return A UBreakIterator for the specified locale.
   210         - * @see ubrk_openRules
   211         - * @stable ICU 2.0
   212         - */
   213         -U_STABLE UBreakIterator* U_EXPORT2
   214         -ubrk_open(UBreakIteratorType type,
   215         -      const char *locale,
   216         -      const UChar *text,
   217         -      int32_t textLength,
   218         -      UErrorCode *status);
   219         -
   220         -/**
   221         - * Open a new UBreakIterator for locating text boundaries using specified breaking rules.
   222         - * The rule syntax is ... (TBD)
   223         - * @param rules A set of rules specifying the text breaking conventions.
   224         - * @param rulesLength The number of characters in rules, or -1 if null-terminated.
   225         - * @param text The text to be iterated over.  May be null, in which case ubrk_setText() is
   226         - *        used to specify the text to be iterated.
   227         - * @param textLength The number of characters in text, or -1 if null-terminated.
   228         - * @param parseErr   Receives position and context information for any syntax errors
   229         - *                   detected while parsing the rules.
   230         - * @param status A UErrorCode to receive any errors.
   231         - * @return A UBreakIterator for the specified rules.
   232         - * @see ubrk_open
   233         - * @stable ICU 2.2
   234         - */
   235         -U_STABLE UBreakIterator* U_EXPORT2
   236         -ubrk_openRules(const UChar     *rules,
   237         -               int32_t         rulesLength,
   238         -               const UChar     *text,
   239         -               int32_t          textLength,
   240         -               UParseError     *parseErr,
   241         -               UErrorCode      *status);
   242         -
   243         -/**
   244         - * Thread safe cloning operation
   245         - * @param bi iterator to be cloned
   246         - * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br>
   247         - *  user allocated space for the new clone. If NULL new memory will be allocated.
   248         - *  If buffer is not large enough, new memory will be allocated.
   249         - *  Clients can use the U_BRK_SAFECLONE_BUFFERSIZE.
   250         - * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br>
   251         - *  pointer to size of allocated space.
   252         - *  If *pBufferSize == 0, a sufficient size for use in cloning will
   253         - *  be returned ('pre-flighting')
   254         - *  If *pBufferSize is not enough for a stack-based safe clone,
   255         - *  new memory will be allocated.
   256         - * @param status to indicate whether the operation went on smoothly or there were errors
   257         - *  An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any allocations were necessary.
   258         - * @return pointer to the new clone
   259         - * @stable ICU 2.0
   260         - */
   261         -U_STABLE UBreakIterator * U_EXPORT2
   262         -ubrk_safeClone(
   263         -          const UBreakIterator *bi,
   264         -          void *stackBuffer,
   265         -          int32_t *pBufferSize,
   266         -          UErrorCode *status);
   267         -
   268         -#ifndef U_HIDE_DEPRECATED_API
   269         -
   270         -/**
   271         -  * A recommended size (in bytes) for the memory buffer to be passed to ubrk_saveClone().
   272         -  * @deprecated ICU 52. Do not rely on ubrk_safeClone() cloning into any provided buffer.
   273         -  */
   274         -#define U_BRK_SAFECLONE_BUFFERSIZE 1
   275         -
   276         -#endif /* U_HIDE_DEPRECATED_API */
   277         -
   278         -/**
   279         -* Close a UBreakIterator.
   280         -* Once closed, a UBreakIterator may no longer be used.
   281         -* @param bi The break iterator to close.
   282         - * @stable ICU 2.0
   283         -*/
   284         -U_STABLE void U_EXPORT2
   285         -ubrk_close(UBreakIterator *bi);
   286         -
   287         -#if U_SHOW_CPLUSPLUS_API
   288         -
   289         -U_NAMESPACE_BEGIN
   290         -
   291         -/**
   292         - * \class LocalUBreakIteratorPointer
   293         - * "Smart pointer" class, closes a UBreakIterator via ubrk_close().
   294         - * For most methods see the LocalPointerBase base class.
   295         - *
   296         - * @see LocalPointerBase
   297         - * @see LocalPointer
   298         - * @stable ICU 4.4
   299         - */
   300         -U_DEFINE_LOCAL_OPEN_POINTER(LocalUBreakIteratorPointer, UBreakIterator, ubrk_close);
   301         -
   302         -U_NAMESPACE_END
   303         -
   304         -#endif
   305         -
   306         -/**
   307         - * Sets an existing iterator to point to a new piece of text
   308         - * @param bi The iterator to use
   309         - * @param text The text to be set
   310         - * @param textLength The length of the text
   311         - * @param status The error code
   312         - * @stable ICU 2.0
   313         - */
   314         -U_STABLE void U_EXPORT2
   315         -ubrk_setText(UBreakIterator* bi,
   316         -             const UChar*    text,
   317         -             int32_t         textLength,
   318         -             UErrorCode*     status);
   319         -
   320         -
   321         -/**
   322         - * Sets an existing iterator to point to a new piece of text.
   323         - *
   324         - * All index positions returned by break iterator functions are
   325         - * native indices from the UText. For example, when breaking UTF-8
   326         - * encoded text, the break positions returned by \ref ubrk_next, \ref ubrk_previous, etc.
   327         - * will be UTF-8 string indices, not UTF-16 positions.
   328         - *
   329         - * @param bi The iterator to use
   330         - * @param text The text to be set.
   331         - *             This function makes a shallow clone of the supplied UText.  This means
   332         - *             that the caller is free to immediately close or otherwise reuse the
   333         - *             UText that was passed as a parameter, but that the underlying text itself
   334         - *             must not be altered while being referenced by the break iterator.
   335         - * @param status The error code
   336         - * @stable ICU 3.4
   337         - */
   338         -U_STABLE void U_EXPORT2
   339         -ubrk_setUText(UBreakIterator* bi,
   340         -             UText*          text,
   341         -             UErrorCode*     status);
   342         -
   343         -
   344         -
   345         -/**
   346         - * Determine the most recently-returned text boundary.
   347         - *
   348         - * @param bi The break iterator to use.
   349         - * @return The character index most recently returned by \ref ubrk_next, \ref ubrk_previous,
   350         - * \ref ubrk_first, or \ref ubrk_last.
   351         - * @stable ICU 2.0
   352         - */
   353         -U_STABLE int32_t U_EXPORT2
   354         -ubrk_current(const UBreakIterator *bi);
   355         -
   356         -/**
   357         - * Advance the iterator to the boundary following the current boundary.
   358         - *
   359         - * @param bi The break iterator to use.
   360         - * @return The character index of the next text boundary, or UBRK_DONE
   361         - * if all text boundaries have been returned.
   362         - * @see ubrk_previous
   363         - * @stable ICU 2.0
   364         - */
   365         -U_STABLE int32_t U_EXPORT2
   366         -ubrk_next(UBreakIterator *bi);
   367         -
   368         -/**
   369         - * Set the iterator position to the boundary preceding the current boundary.
   370         - *
   371         - * @param bi The break iterator to use.
   372         - * @return The character index of the preceding text boundary, or UBRK_DONE
   373         - * if all text boundaries have been returned.
   374         - * @see ubrk_next
   375         - * @stable ICU 2.0
   376         - */
   377         -U_STABLE int32_t U_EXPORT2
   378         -ubrk_previous(UBreakIterator *bi);
   379         -
   380         -/**
   381         - * Set the iterator position to the index of the first character in the text being scanned.
   382         - * This is not always the same as index 0 of the text.
   383         - * @param bi The break iterator to use.
   384         - * @return The character index of the first character in the text being scanned.
   385         - * @see ubrk_last
   386         - * @stable ICU 2.0
   387         - */
   388         -U_STABLE int32_t U_EXPORT2
   389         -ubrk_first(UBreakIterator *bi);
   390         -
   391         -/**
   392         - * Set the iterator position to the index immediately <EM>beyond</EM> the last character in the text being scanned.
   393         - * This is not the same as the last character.
   394         - * @param bi The break iterator to use.
   395         - * @return The character offset immediately <EM>beyond</EM> the last character in the
   396         - * text being scanned.
   397         - * @see ubrk_first
   398         - * @stable ICU 2.0
   399         - */
   400         -U_STABLE int32_t U_EXPORT2
   401         -ubrk_last(UBreakIterator *bi);
   402         -
   403         -/**
   404         - * Set the iterator position to the first boundary preceding the specified offset.
   405         - * The new position is always smaller than offset, or UBRK_DONE.
   406         - * @param bi The break iterator to use.
   407         - * @param offset The offset to begin scanning.
   408         - * @return The text boundary preceding offset, or UBRK_DONE.
   409         - * @see ubrk_following
   410         - * @stable ICU 2.0
   411         - */
   412         -U_STABLE int32_t U_EXPORT2
   413         -ubrk_preceding(UBreakIterator *bi,
   414         -           int32_t offset);
   415         -
   416         -/**
   417         - * Advance the iterator to the first boundary following the specified offset.
   418         - * The value returned is always greater than offset, or UBRK_DONE.
   419         - * @param bi The break iterator to use.
   420         - * @param offset The offset to begin scanning.
   421         - * @return The text boundary following offset, or UBRK_DONE.
   422         - * @see ubrk_preceding
   423         - * @stable ICU 2.0
   424         - */
   425         -U_STABLE int32_t U_EXPORT2
   426         -ubrk_following(UBreakIterator *bi,
   427         -           int32_t offset);
   428         -
   429         -/**
   430         -* Get a locale for which text breaking information is available.
   431         -* A UBreakIterator in a locale returned by this function will perform the correct
   432         -* text breaking for the locale.
   433         -* @param index The index of the desired locale.
   434         -* @return A locale for which number text breaking information is available, or 0 if none.
   435         -* @see ubrk_countAvailable
   436         -* @stable ICU 2.0
   437         -*/
   438         -U_STABLE const char* U_EXPORT2
   439         -ubrk_getAvailable(int32_t index);
   440         -
   441         -/**
   442         -* Determine how many locales have text breaking information available.
   443         -* This function is most useful as determining the loop ending condition for
   444         -* calls to \ref ubrk_getAvailable.
   445         -* @return The number of locales for which text breaking information is available.
   446         -* @see ubrk_getAvailable
   447         -* @stable ICU 2.0
   448         -*/
   449         -U_STABLE int32_t U_EXPORT2
   450         -ubrk_countAvailable(void);
   451         -
   452         -
   453         -/**
   454         -* Returns true if the specfied position is a boundary position.  As a side
   455         -* effect, leaves the iterator pointing to the first boundary position at
   456         -* or after "offset".
   457         -* @param bi The break iterator to use.
   458         -* @param offset the offset to check.
   459         -* @return True if "offset" is a boundary position.
   460         -* @stable ICU 2.0
   461         -*/
   462         -U_STABLE  UBool U_EXPORT2
   463         -ubrk_isBoundary(UBreakIterator *bi, int32_t offset);
   464         -
   465         -/**
   466         - * Return the status from the break rule that determined the most recently
   467         - * returned break position.  The values appear in the rule source
   468         - * within brackets, {123}, for example.  For rules that do not specify a
   469         - * status, a default value of 0 is returned.
   470         - * <p>
   471         - * For word break iterators, the possible values are defined in enum UWordBreak.
   472         - * @stable ICU 2.2
   473         - */
   474         -U_STABLE  int32_t U_EXPORT2
   475         -ubrk_getRuleStatus(UBreakIterator *bi);
   476         -
   477         -/**
   478         - * Get the statuses from the break rules that determined the most recently
   479         - * returned break position.  The values appear in the rule source
   480         - * within brackets, {123}, for example.  The default status value for rules
   481         - * that do not explicitly provide one is zero.
   482         - * <p>
   483         - * For word break iterators, the possible values are defined in enum UWordBreak.
   484         - * @param bi        The break iterator to use
   485         - * @param fillInVec an array to be filled in with the status values.
   486         - * @param capacity  the length of the supplied vector.  A length of zero causes
   487         - *                  the function to return the number of status values, in the
   488         - *                  normal way, without attemtping to store any values.
   489         - * @param status    receives error codes.
   490         - * @return          The number of rule status values from rules that determined
   491         - *                  the most recent boundary returned by the break iterator.
   492         - * @stable ICU 3.0
   493         - */
   494         -U_STABLE  int32_t U_EXPORT2
   495         -ubrk_getRuleStatusVec(UBreakIterator *bi, int32_t *fillInVec, int32_t capacity, UErrorCode *status);
   496         -
   497         -/**
   498         - * Return the locale of the break iterator. You can choose between the valid and
   499         - * the actual locale.
   500         - * @param bi break iterator
   501         - * @param type locale type (valid or actual)
   502         - * @param status error code
   503         - * @return locale string
   504         - * @stable ICU 2.8
   505         - */
   506         -U_STABLE const char* U_EXPORT2
   507         -ubrk_getLocaleByType(const UBreakIterator *bi, ULocDataLocaleType type, UErrorCode* status);
   508         -
   509         -/**
   510         -  *  Set the subject text string upon which the break iterator is operating
   511         -  *  without changing any other aspect of the state.
   512         -  *  The new and previous text strings must have the same content.
   513         -  *
   514         -  *  This function is intended for use in environments where ICU is operating on
   515         -  *  strings that may move around in memory.  It provides a mechanism for notifying
   516         -  *  ICU that the string has been relocated, and providing a new UText to access the
   517         -  *  string in its new position.
   518         -  *
   519         -  *  Note that the break iterator never copies the underlying text
   520         -  *  of a string being processed, but always operates directly on the original text
   521         -  *  provided by the user. Refreshing simply drops the references to the old text
   522         -  *  and replaces them with references to the new.
   523         -  *
   524         -  *  Caution:  this function is normally used only by very specialized
   525         -  *            system-level code.   One example use case is with garbage collection
   526         -  *            that moves the text in memory.
   527         -  *
   528         -  * @param bi         The break iterator.
   529         -  * @param text       The new (moved) text string.
   530         -  * @param status     Receives errors detected by this function.
   531         -  *
   532         -  * @stable ICU 49
   533         -  */
   534         -U_STABLE void U_EXPORT2
   535         -ubrk_refreshUText(UBreakIterator *bi,
   536         -                       UText          *text,
   537         -                       UErrorCode     *status);
   538         -
   539         -#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
   540         -
   541         -#endif

Deleted jni/tcl/pkgs/sqlite3.28.0/icu4c/unicode/uchar.h.

     1         -/*
     2         -**********************************************************************
     3         -*   Copyright (C) 1997-2014, International Business Machines
     4         -*   Corporation and others.  All Rights Reserved.
     5         -**********************************************************************
     6         -*
     7         -* File UCHAR.H
     8         -*
     9         -* Modification History:
    10         -*
    11         -*   Date        Name        Description
    12         -*   04/02/97    aliu        Creation.
    13         -*   03/29/99    helena      Updated for C APIs.
    14         -*   4/15/99     Madhu       Updated for C Implementation and Javadoc
    15         -*   5/20/99     Madhu       Added the function u_getVersion()
    16         -*   8/19/1999   srl         Upgraded scripts to Unicode 3.0
    17         -*   8/27/1999   schererm    UCharDirection constants: U_...
    18         -*   11/11/1999  weiv        added u_isalnum(), cleaned comments
    19         -*   01/11/2000  helena      Renamed u_getVersion to u_getUnicodeVersion().
    20         -******************************************************************************
    21         -*/
    22         -
    23         -#ifndef UCHAR_H
    24         -#define UCHAR_H
    25         -
    26         -#include "unicode/utypes.h"
    27         -
    28         -U_CDECL_BEGIN
    29         -
    30         -/*==========================================================================*/
    31         -/* Unicode version number                                                   */
    32         -/*==========================================================================*/
    33         -/**
    34         - * Unicode version number, default for the current ICU version.
    35         - * The actual Unicode Character Database (UCD) data is stored in uprops.dat
    36         - * and may be generated from UCD files from a different Unicode version.
    37         - * Call u_getUnicodeVersion to get the actual Unicode version of the data.
    38         - *
    39         - * @see u_getUnicodeVersion
    40         - * @stable ICU 2.0
    41         - */
    42         -#define U_UNICODE_VERSION "6.3"
    43         -
    44         -/**
    45         - * \file
    46         - * \brief C API: Unicode Properties
    47         - *
    48         - * This C API provides low-level access to the Unicode Character Database.
    49         - * In addition to raw property values, some convenience functions calculate
    50         - * derived properties, for example for Java-style programming.
    51         - *
    52         - * Unicode assigns each code point (not just assigned character) values for
    53         - * many properties.
    54         - * Most of them are simple boolean flags, or constants from a small enumerated list.
    55         - * For some properties, values are strings or other relatively more complex types.
    56         - *
    57         - * For more information see
    58         - * "About the Unicode Character Database" (http://www.unicode.org/ucd/)
    59         - * and the ICU User Guide chapter on Properties (http://icu-project.org/userguide/properties.html).
    60         - *
    61         - * Many functions are designed to match java.lang.Character functions.
    62         - * See the individual function documentation,
    63         - * and see the JDK 1.4 java.lang.Character documentation
    64         - * at http://java.sun.com/j2se/1.4/docs/api/java/lang/Character.html
    65         - *
    66         - * There are also functions that provide easy migration from C/POSIX functions
    67         - * like isblank(). Their use is generally discouraged because the C/POSIX
    68         - * standards do not define their semantics beyond the ASCII range, which means
    69         - * that different implementations exhibit very different behavior.
    70         - * Instead, Unicode properties should be used directly.
    71         - *
    72         - * There are also only a few, broad C/POSIX character classes, and they tend
    73         - * to be used for conflicting purposes. For example, the "isalpha()" class
    74         - * is sometimes used to determine word boundaries, while a more sophisticated
    75         - * approach would at least distinguish initial letters from continuation
    76         - * characters (the latter including combining marks).
    77         - * (In ICU, BreakIterator is the most sophisticated API for word boundaries.)
    78         - * Another example: There is no "istitle()" class for titlecase characters.
    79         - *
    80         - * ICU 3.4 and later provides API access for all twelve C/POSIX character classes.
    81         - * ICU implements them according to the Standard Recommendations in
    82         - * Annex C: Compatibility Properties of UTS #18 Unicode Regular Expressions
    83         - * (http://www.unicode.org/reports/tr18/#Compatibility_Properties).
    84         - *
    85         - * API access for C/POSIX character classes is as follows:
    86         - * - alpha:     u_isUAlphabetic(c) or u_hasBinaryProperty(c, UCHAR_ALPHABETIC)
    87         - * - lower:     u_isULowercase(c) or u_hasBinaryProperty(c, UCHAR_LOWERCASE)
    88         - * - upper:     u_isUUppercase(c) or u_hasBinaryProperty(c, UCHAR_UPPERCASE)
    89         - * - punct:     u_ispunct(c)
    90         - * - digit:     u_isdigit(c) or u_charType(c)==U_DECIMAL_DIGIT_NUMBER
    91         - * - xdigit:    u_isxdigit(c) or u_hasBinaryProperty(c, UCHAR_POSIX_XDIGIT)
    92         - * - alnum:     u_hasBinaryProperty(c, UCHAR_POSIX_ALNUM)
    93         - * - space:     u_isUWhiteSpace(c) or u_hasBinaryProperty(c, UCHAR_WHITE_SPACE)
    94         - * - blank:     u_isblank(c) or u_hasBinaryProperty(c, UCHAR_POSIX_BLANK)
    95         - * - cntrl:     u_charType(c)==U_CONTROL_CHAR
    96         - * - graph:     u_hasBinaryProperty(c, UCHAR_POSIX_GRAPH)
    97         - * - print:     u_hasBinaryProperty(c, UCHAR_POSIX_PRINT)
    98         - *
    99         - * Note: Some of the u_isxyz() functions in uchar.h predate, and do not match,
   100         - * the Standard Recommendations in UTS #18. Instead, they match Java
   101         - * functions according to their API documentation.
   102         - *
   103         - * \htmlonly
   104         - * The C/POSIX character classes are also available in UnicodeSet patterns,
   105         - * using patterns like [:graph:] or \p{graph}.
   106         - * \endhtmlonly
   107         - *
   108         - * Note: There are several ICU whitespace functions.
   109         - * Comparison:
   110         - * - u_isUWhiteSpace=UCHAR_WHITE_SPACE: Unicode White_Space property;
   111         - *       most of general categories "Z" (separators) + most whitespace ISO controls
   112         - *       (including no-break spaces, but excluding IS1..IS4 and ZWSP)
   113         - * - u_isWhitespace: Java isWhitespace; Z + whitespace ISO controls but excluding no-break spaces
   114         - * - u_isJavaSpaceChar: Java isSpaceChar; just Z (including no-break spaces)
   115         - * - u_isspace: Z + whitespace ISO controls (including no-break spaces)
   116         - * - u_isblank: "horizontal spaces" = TAB + Zs - ZWSP
   117         - */
   118         -
   119         -/**
   120         - * Constants.
   121         - */
   122         -
   123         -/** The lowest Unicode code point value. Code points are non-negative. @stable ICU 2.0 */
   124         -#define UCHAR_MIN_VALUE 0
   125         -
   126         -/**
   127         - * The highest Unicode code point value (scalar value) according to
   128         - * The Unicode Standard. This is a 21-bit value (20.1 bits, rounded up).
   129         - * For a single character, UChar32 is a simple type that can hold any code point value.
   130         - *
   131         - * @see UChar32
   132         - * @stable ICU 2.0
   133         - */
   134         -#define UCHAR_MAX_VALUE 0x10ffff
   135         -
   136         -/**
   137         - * Get a single-bit bit set (a flag) from a bit number 0..31.
   138         - * @stable ICU 2.1
   139         - */
   140         -#define U_MASK(x) ((uint32_t)1<<(x))
   141         -
   142         -/**
   143         - * Selection constants for Unicode properties.
   144         - * These constants are used in functions like u_hasBinaryProperty to select
   145         - * one of the Unicode properties.
   146         - *
   147         - * The properties APIs are intended to reflect Unicode properties as defined
   148         - * in the Unicode Character Database (UCD) and Unicode Technical Reports (UTR).
   149         - * For details about the properties see http://www.unicode.org/ucd/ .
   150         - * For names of Unicode properties see the UCD file PropertyAliases.txt.
   151         - *
   152         - * Important: If ICU is built with UCD files from Unicode versions below, e.g., 3.2,
   153         - * then properties marked with "new in Unicode 3.2" are not or not fully available.
   154         - * Check u_getUnicodeVersion to be sure.
   155         - *
   156         - * @see u_hasBinaryProperty
   157         - * @see u_getIntPropertyValue
   158         - * @see u_getUnicodeVersion
   159         - * @stable ICU 2.1
   160         - */
   161         -typedef enum UProperty {
   162         -    /*
   163         -     * Note: UProperty constants are parsed by preparseucd.py.
   164         -     * It matches lines like
   165         -     *     UCHAR_<Unicode property name>=<integer>,
   166         -     */
   167         -
   168         -    /*  Note: Place UCHAR_ALPHABETIC before UCHAR_BINARY_START so that
   169         -    debuggers display UCHAR_ALPHABETIC as the symbolic name for 0,
   170         -    rather than UCHAR_BINARY_START.  Likewise for other *_START
   171         -    identifiers. */
   172         -
   173         -    /** Binary property Alphabetic. Same as u_isUAlphabetic, different from u_isalpha.
   174         -        Lu+Ll+Lt+Lm+Lo+Nl+Other_Alphabetic @stable ICU 2.1 */
   175         -    UCHAR_ALPHABETIC=0,
   176         -    /** First constant for binary Unicode properties. @stable ICU 2.1 */
   177         -    UCHAR_BINARY_START=UCHAR_ALPHABETIC,
   178         -    /** Binary property ASCII_Hex_Digit. 0-9 A-F a-f @stable ICU 2.1 */
   179         -    UCHAR_ASCII_HEX_DIGIT=1,
   180         -    /** Binary property Bidi_Control.
   181         -        Format controls which have specific functions
   182         -        in the Bidi Algorithm. @stable ICU 2.1 */
   183         -    UCHAR_BIDI_CONTROL=2,
   184         -    /** Binary property Bidi_Mirrored.
   185         -        Characters that may change display in RTL text.
   186         -        Same as u_isMirrored.
   187         -        See Bidi Algorithm, UTR 9. @stable ICU 2.1 */
   188         -    UCHAR_BIDI_MIRRORED=3,
   189         -    /** Binary property Dash. Variations of dashes. @stable ICU 2.1 */
   190         -    UCHAR_DASH=4,
   191         -    /** Binary property Default_Ignorable_Code_Point (new in Unicode 3.2).
   192         -        Ignorable in most processing.
   193         -        <2060..206F, FFF0..FFFB, E0000..E0FFF>+Other_Default_Ignorable_Code_Point+(Cf+Cc+Cs-White_Space) @stable ICU 2.1 */
   194         -    UCHAR_DEFAULT_IGNORABLE_CODE_POINT=5,
   195         -    /** Binary property Deprecated (new in Unicode 3.2).
   196         -        The usage of deprecated characters is strongly discouraged. @stable ICU 2.1 */
   197         -    UCHAR_DEPRECATED=6,
   198         -    /** Binary property Diacritic. Characters that linguistically modify
   199         -        the meaning of another character to which they apply. @stable ICU 2.1 */
   200         -    UCHAR_DIACRITIC=7,
   201         -    /** Binary property Extender.
   202         -        Extend the value or shape of a preceding alphabetic character,
   203         -        e.g., length and iteration marks. @stable ICU 2.1 */
   204         -    UCHAR_EXTENDER=8,
   205         -    /** Binary property Full_Composition_Exclusion.
   206         -        CompositionExclusions.txt+Singleton Decompositions+
   207         -        Non-Starter Decompositions. @stable ICU 2.1 */
   208         -    UCHAR_FULL_COMPOSITION_EXCLUSION=9,
   209         -    /** Binary property Grapheme_Base (new in Unicode 3.2).
   210         -        For programmatic determination of grapheme cluster boundaries.
   211         -        [0..10FFFF]-Cc-Cf-Cs-Co-Cn-Zl-Zp-Grapheme_Link-Grapheme_Extend-CGJ @stable ICU 2.1 */
   212         -    UCHAR_GRAPHEME_BASE=10,
   213         -    /** Binary property Grapheme_Extend (new in Unicode 3.2).
   214         -        For programmatic determination of grapheme cluster boundaries.
   215         -        Me+Mn+Mc+Other_Grapheme_Extend-Grapheme_Link-CGJ @stable ICU 2.1 */
   216         -    UCHAR_GRAPHEME_EXTEND=11,
   217         -    /** Binary property Grapheme_Link (new in Unicode 3.2).
   218         -        For programmatic determination of grapheme cluster boundaries. @stable ICU 2.1 */
   219         -    UCHAR_GRAPHEME_LINK=12,
   220         -    /** Binary property Hex_Digit.
   221         -        Characters commonly used for hexadecimal numbers. @stable ICU 2.1 */
   222         -    UCHAR_HEX_DIGIT=13,
   223         -    /** Binary property Hyphen. Dashes used to mark connections
   224         -        between pieces of words, plus the Katakana middle dot. @stable ICU 2.1 */
   225         -    UCHAR_HYPHEN=14,
   226         -    /** Binary property ID_Continue.
   227         -        Characters that can continue an identifier.
   228         -        DerivedCoreProperties.txt also says "NOTE: Cf characters should be filtered out."
   229         -        ID_Start+Mn+Mc+Nd+Pc @stable ICU 2.1 */
   230         -    UCHAR_ID_CONTINUE=15,
   231         -    /** Binary property ID_Start.
   232         -        Characters that can start an identifier.
   233         -        Lu+Ll+Lt+Lm+Lo+Nl @stable ICU 2.1 */
   234         -    UCHAR_ID_START=16,
   235         -    /** Binary property Ideographic.
   236         -        CJKV ideographs. @stable ICU 2.1 */
   237         -    UCHAR_IDEOGRAPHIC=17,
   238         -    /** Binary property IDS_Binary_Operator (new in Unicode 3.2).
   239         -        For programmatic determination of
   240         -        Ideographic Description Sequences. @stable ICU 2.1 */
   241         -    UCHAR_IDS_BINARY_OPERATOR=18,
   242         -    /** Binary property IDS_Trinary_Operator (new in Unicode 3.2).
   243         -        For programmatic determination of
   244         -        Ideographic Description Sequences. @stable ICU 2.1 */
   245         -    UCHAR_IDS_TRINARY_OPERATOR=19,
   246         -    /** Binary property Join_Control.
   247         -        Format controls for cursive joining and ligation. @stable ICU 2.1 */
   248         -    UCHAR_JOIN_CONTROL=20,
   249         -    /** Binary property Logical_Order_Exception (new in Unicode 3.2).
   250         -        Characters that do not use logical order and
   251         -        require special handling in most processing. @stable ICU 2.1 */
   252         -    UCHAR_LOGICAL_ORDER_EXCEPTION=21,
   253         -    /** Binary property Lowercase. Same as u_isULowercase, different from u_islower.
   254         -        Ll+Other_Lowercase @stable ICU 2.1 */
   255         -    UCHAR_LOWERCASE=22,
   256         -    /** Binary property Math. Sm+Other_Math @stable ICU 2.1 */
   257         -    UCHAR_MATH=23,
   258         -    /** Binary property Noncharacter_Code_Point.
   259         -        Code points that are explicitly defined as illegal
   260         -        for the encoding of characters. @stable ICU 2.1 */
   261         -    UCHAR_NONCHARACTER_CODE_POINT=24,
   262         -    /** Binary property Quotation_Mark. @stable ICU 2.1 */
   263         -    UCHAR_QUOTATION_MARK=25,
   264         -    /** Binary property Radical (new in Unicode 3.2).
   265         -        For programmatic determination of
   266         -        Ideographic Description Sequences. @stable ICU 2.1 */
   267         -    UCHAR_RADICAL=26,
   268         -    /** Binary property Soft_Dotted (new in Unicode 3.2).
   269         -        Characters with a "soft dot", like i or j.
   270         -        An accent placed on these characters causes
   271         -        the dot to disappear. @stable ICU 2.1 */
   272         -    UCHAR_SOFT_DOTTED=27,
   273         -    /** Binary property Terminal_Punctuation.
   274         -        Punctuation characters that generally mark
   275         -        the end of textual units. @stable ICU 2.1 */
   276         -    UCHAR_TERMINAL_PUNCTUATION=28,
   277         -    /** Binary property Unified_Ideograph (new in Unicode 3.2).
   278         -        For programmatic determination of
   279         -        Ideographic Description Sequences. @stable ICU 2.1 */