System.Data.SQLite
Check-in [5e670230f4]
Not logged in

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

Overview
Comment:1.0.45.0 code merge with SQLite 3.4.2
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1:5e670230f42637dc0a8667baf081e0098c146064
User & Date: rmsimpson 2007-09-25 22:50:39
Context
2007-10-01
03:25
1.0.46.0 check-in: 67f18e8aaa user: rmsimpson tags: sourceforge
2007-09-25
22:50
1.0.45.0 code merge with SQLite 3.4.2 check-in: 5e670230f4 user: rmsimpson tags: sourceforge
22:46
Fixed section size calculations check-in: 685c65f2d6 user: rmsimpson tags: sourceforge
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to SQLite.Interop/src/sqlite3.c.

     1      1   /******************************************************************************
     2      2   ** This file is an amalgamation of many separate C source files from SQLite
     3         -** version 3.4.1.  By combining all the individual C code files into this 
            3  +** version 3.4.2.  By combining all the individual C code files into this 
     4      4   ** single large file, the entire code can be compiled as a one translation
     5      5   ** unit.  This allows many compilers to do optimizations that would not be
     6      6   ** possible if the files were compiled separately.  Performance improvements
     7      7   ** of 5% are more are commonly seen when SQLite is compiled as a single
     8      8   ** translation unit.
     9      9   **
    10     10   ** This file is all you need to compile SQLite.  To use SQLite in other
    11     11   ** programs, you need this file and the "sqlite3.h" header file that defines
    12     12   ** the programming interface to the SQLite library.  (If you do not have 
    13     13   ** the "sqlite3.h" header file at hand, you will find a copy in the first
    14         -** 2702 lines past this header comment.)  Additional code files may be
           14  +** 2709 lines past this header comment.)  Additional code files may be
    15     15   ** needed if you want a wrapper to interface SQLite with your choice of
    16     16   ** programming language.  The code for the "sqlite3" command-line shell
    17     17   ** is also in a separate file.  This file contains only code for the core
    18     18   ** SQLite library.
    19     19   **
    20         -** This amalgamation was generated on 2007-07-20 11:05:39 UTC.
           20  +** This amalgamation was generated on 2007-08-14 00:24:36 UTC.
    21     21   */
    22     22   #define SQLITE_AMALGAMATION 1
    23     23   #ifndef SQLITE_PRIVATE
    24     24   # define SQLITE_PRIVATE static
    25     25   #endif
    26     26   #ifndef SQLITE_API
    27     27   # define SQLITE_API
................................................................................
    55     55   ** on how SQLite interfaces are suppose to operate.
    56     56   **
    57     57   ** The name of this file under configuration management is "sqlite.h.in".
    58     58   ** The makefile makes some minor changes to this file (such as inserting
    59     59   ** the version number) and changes its name to "sqlite3.h" as
    60     60   ** part of the build process.
    61     61   **
    62         -** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
           62  +** @(#) $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
    63     63   */
    64     64   #ifndef _SQLITE3_H_
    65     65   #define _SQLITE3_H_
    66     66   #include <stdarg.h>     /* Needed for the definition of va_list */
    67     67   
    68     68   /*
    69     69   ** Make sure we can call this stuff from C++.
    70     70   */
    71     71   #if 0
    72     72   extern "C" {
    73     73   #endif
    74     74   
           75  +/*
           76  +** Add the ability to override 'extern'
           77  +*/
           78  +#ifndef SQLITE_EXTERN
           79  +# define SQLITE_EXTERN extern
           80  +#endif
           81  +
    75     82   /*
    76     83   ** Make sure these symbols where not defined by some previous header
    77     84   ** file.
    78     85   */
    79     86   #ifdef SQLITE_VERSION
    80     87   # undef SQLITE_VERSION
    81     88   #endif
................................................................................
   106    113   ** (X*1000000 + Y*1000 + Z). For example, for version "3.1.1beta", 
   107    114   ** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using 
   108    115   ** version 3.1.1 or greater at compile time, programs may use the test 
   109    116   ** (SQLITE_VERSION_NUMBER>=3001001).
   110    117   **
   111    118   ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
   112    119   */
   113         -#define SQLITE_VERSION         "3.4.1"
   114         -#define SQLITE_VERSION_NUMBER 3004001
          120  +#define SQLITE_VERSION         "3.4.2"
          121  +#define SQLITE_VERSION_NUMBER 3004002
   115    122   
   116    123   /*
   117    124   ** CAPI3REF: Run-Time Library Version Numbers
   118    125   **
   119    126   ** These routines return values equivalent to the header constants
   120    127   ** [SQLITE_VERSION] and [SQLITE_VERSION_NUMBER].  The values returned
   121    128   ** by this routines should only be different from the header values
................................................................................
   125    132   **
   126    133   ** The sqlite3_version[] string constant contains the text of the
   127    134   ** [SQLITE_VERSION] string.  The sqlite3_libversion() function returns
   128    135   ** a poiner to the sqlite3_version[] string constant.  The function
   129    136   ** is provided for DLL users who can only access functions and not
   130    137   ** constants within the DLL.
   131    138   */
   132         -extern const char sqlite3_version[];
          139  +SQLITE_EXTERN const char sqlite3_version[];
   133    140   SQLITE_API const char *sqlite3_libversion(void);
   134         -int sqlite3_libversion_number(void);
          141  +SQLITE_API int sqlite3_libversion_number(void);
   135    142   
   136    143   /*
   137    144   ** CAPI3REF: Database Connection Handle
   138    145   **
   139    146   ** Each open SQLite database is represented by pointer to an instance of the
   140    147   ** opaque structure named "sqlite3".  It is useful to think of an sqlite3
   141    148   ** pointer as an object.  The [sqlite3_open] interface is its constructor
................................................................................
   345    352   ** much larger and can (hopefully) provide more detailed information
   346    353   ** about the cause of an error.
   347    354   **
   348    355   ** The second argument is a boolean value that turns extended result
   349    356   ** codes on and off.  Extended result codes are off by default for
   350    357   ** backwards compatibility with older versions of SQLite.
   351    358   */
   352         -int sqlite3_extended_result_codes(sqlite3*, int onoff);
          359  +SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
   353    360   
   354    361   /*
   355    362   ** CAPI3REF: Last Insert Rowid
   356    363   **
   357    364   ** Each entry in an SQLite table has a unique 64-bit signed integer key
   358    365   ** called the "rowid". The rowid is always available as an undeclared
   359    366   ** column named ROWID, OID, or _ROWID_.  If the table has a column of
................................................................................
   367    374   **
   368    375   ** If an INSERT occurs within a trigger, then the rowid of the
   369    376   ** inserted row is returned by this routine as long as the trigger
   370    377   ** is running.  But once the trigger terminates, the value returned
   371    378   ** by this routine reverts to the last value inserted before the
   372    379   ** trigger fired.
   373    380   */
   374         -sqlite_int64 sqlite3_last_insert_rowid(sqlite3*);
          381  +SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3*);
   375    382   
   376    383   /*
   377    384   ** CAPI3REF: Count The Number Of Rows Modified
   378    385   **
   379    386   ** This function returns the number of database rows that were changed
   380    387   ** (or inserted or deleted) by the most recent SQL statement.  Only
   381    388   ** changes that are directly specified by the INSERT, UPDATE, or
................................................................................
   422    429   ** by dropping and recreating the table.  (This is much faster than going
   423    430   ** through and deleting individual elements form the table.)  Because of
   424    431   ** this optimization, the change count for "DELETE FROM table" will be
   425    432   ** zero regardless of the number of elements that were originally in the
   426    433   ** table. To get an accurate count of the number of rows deleted, use
   427    434   ** "DELETE FROM table WHERE 1" instead.
   428    435   */
   429         -int sqlite3_total_changes(sqlite3*);
          436  +SQLITE_API int sqlite3_total_changes(sqlite3*);
   430    437   
   431    438   /*
   432    439   ** CAPI3REF: Interrupt A Long-Running Query
   433    440   **
   434    441   ** This function causes any pending database operation to abort and
   435    442   ** return at its earliest opportunity.  This routine is typically
   436    443   ** called in response to a user action such as pressing "Cancel"
................................................................................
   528    535   ** probably result in a segmentation fault or other runtime error.
   529    536   **
   530    537   ** There can only be a single busy handler defined for each database
   531    538   ** connection.  Setting a new busy handler clears any previous one.
   532    539   ** Note that calling [sqlite3_busy_timeout()] will also set or clear
   533    540   ** the busy handler.
   534    541   */
   535         -int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
          542  +SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
   536    543   
   537    544   /*
   538    545   ** CAPI3REF: Set A Busy Timeout
   539    546   **
   540    547   ** This routine sets a busy handler that sleeps for a while when a
   541    548   ** table is locked.  The handler will sleep multiple times until 
   542    549   ** at least "ms" milliseconds of sleeping have been done.  After
................................................................................
   547    554   ** turns off all busy handlers.
   548    555   **
   549    556   ** There can only be a single busy handler for a particular database
   550    557   ** connection.  If another busy handler was defined  
   551    558   ** (using [sqlite3_busy_handler()]) prior to calling
   552    559   ** this routine, that other busy handler is cleared.
   553    560   */
   554         -int sqlite3_busy_timeout(sqlite3*, int ms);
          561  +SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
   555    562   
   556    563   /*
   557    564   ** CAPI3REF: Convenience Routines For Running Queries
   558    565   **
   559    566   ** This next routine is a convenience wrapper around [sqlite3_exec()].
   560    567   ** Instead of invoking a user-supplied callback for each row of the
   561    568   ** result, this routine remembers each row of the result in memory
................................................................................
   596    603   ** release the memory that was malloc-ed.  Because of the way the 
   597    604   ** [sqlite3_malloc()] happens, the calling function must not try to call 
   598    605   ** [sqlite3_free()] directly.  Only [sqlite3_free_table()] is able to release 
   599    606   ** the memory properly and safely.
   600    607   **
   601    608   ** The return value of this routine is the same as from [sqlite3_exec()].
   602    609   */
   603         -int sqlite3_get_table(
          610  +SQLITE_API int sqlite3_get_table(
   604    611     sqlite3*,              /* An open database */
   605    612     const char *sql,       /* SQL to be executed */
   606    613     char ***resultp,       /* Result written to a char *[]  that this points to */
   607    614     int *nrow,             /* Number of result rows written here */
   608    615     int *ncolumn,          /* Number of result columns written here */
   609    616     char **errmsg          /* Error msg written here */
   610    617   );
   611         -void sqlite3_free_table(char **result);
          618  +SQLITE_API void sqlite3_free_table(char **result);
   612    619   
   613    620   /*
   614    621   ** CAPI3REF: Formatted String Printing Functions
   615    622   **
   616    623   ** These routines are workalikes of the "printf()" family of functions
   617    624   ** from the standard C library.
   618    625   **
................................................................................
   765    772   ** previous call.  A NULL authorizer means that no authorization
   766    773   ** callback is invoked.  The default authorizer is NULL.
   767    774   **
   768    775   ** Note that the authorizer callback is invoked only during 
   769    776   ** [sqlite3_prepare()] or its variants.  Authorization is not
   770    777   ** performed during statement evaluation in [sqlite3_step()].
   771    778   */
   772         -int sqlite3_set_authorizer(
          779  +SQLITE_API int sqlite3_set_authorizer(
   773    780     sqlite3*,
   774    781     int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
   775    782     void *pUserData
   776    783   );
   777    784   
   778    785   /*
   779    786   ** CAPI3REF: Authorizer Return Codes
................................................................................
   885    892   ** If the progress callback returns a result other than 0, then the current 
   886    893   ** query is immediately terminated and any database changes rolled back.
   887    894   ** The containing [sqlite3_exec()], [sqlite3_step()], or
   888    895   ** [sqlite3_get_table()] call returns SQLITE_INTERRUPT.   This feature
   889    896   ** can be used, for example, to implement the "Cancel" button on a
   890    897   ** progress dialog box in a GUI.
   891    898   */
   892         -void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
          899  +SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
   893    900   
   894    901   /*
   895    902   ** CAPI3REF: Opening A New Database Connection
   896    903   **
   897    904   ** Open the sqlite database file "filename".  The "filename" is UTF-8
   898    905   ** encoded for sqlite3_open() and UTF-16 encoded in the native byte order
   899    906   ** for sqlite3_open16().  An [sqlite3*] handle is returned in *ppDb, even
................................................................................
  1052   1059   SQLITE_API int sqlite3_prepare(
  1053   1060     sqlite3 *db,            /* Database handle */
  1054   1061     const char *zSql,       /* SQL statement, UTF-8 encoded */
  1055   1062     int nByte,              /* Maximum length of zSql in bytes. */
  1056   1063     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1057   1064     const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  1058   1065   );
  1059         -int sqlite3_prepare_v2(
         1066  +SQLITE_API int sqlite3_prepare_v2(
  1060   1067     sqlite3 *db,            /* Database handle */
  1061   1068     const char *zSql,       /* SQL statement, UTF-8 encoded */
  1062   1069     int nByte,              /* Maximum length of zSql in bytes. */
  1063   1070     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1064   1071     const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  1065   1072   );
  1066   1073   SQLITE_API int sqlite3_prepare16(
  1067   1074     sqlite3 *db,            /* Database handle */
  1068   1075     const void *zSql,       /* SQL statement, UTF-16 encoded */
  1069   1076     int nByte,              /* Maximum length of zSql in bytes. */
  1070   1077     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1071   1078     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  1072   1079   );
  1073         -int sqlite3_prepare16_v2(
         1080  +SQLITE_API int sqlite3_prepare16_v2(
  1074   1081     sqlite3 *db,            /* Database handle */
  1075   1082     const void *zSql,       /* SQL statement, UTF-16 encoded */
  1076   1083     int nByte,              /* Maximum length of zSql in bytes. */
  1077   1084     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1078   1085     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  1079   1086   );
  1080   1087   
................................................................................
  1166   1173   **
  1167   1174   ** These routines return [SQLITE_OK] on success or an error code if
  1168   1175   ** anything goes wrong.  [SQLITE_RANGE] is returned if the parameter
  1169   1176   ** index is out of range.  [SQLITE_NOMEM] is returned if malloc fails.
  1170   1177   ** [SQLITE_MISUSE] is returned if these routines are called on a virtual
  1171   1178   ** machine that is the wrong state or which has already been finalized.
  1172   1179   */
  1173         -int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  1174         -int sqlite3_bind_double(sqlite3_stmt*, int, double);
  1175         -int sqlite3_bind_int(sqlite3_stmt*, int, int);
  1176         -int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite_int64);
  1177         -int sqlite3_bind_null(sqlite3_stmt*, int);
  1178         -int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
  1179         -int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  1180         -int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  1181         -int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
         1180  +SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
         1181  +SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
         1182  +SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
         1183  +SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite_int64);
         1184  +SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
         1185  +SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
         1186  +SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
         1187  +SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
         1188  +SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  1182   1189   
  1183   1190   /*
  1184   1191   ** CAPI3REF: Number Of Host Parameters
  1185   1192   **
  1186   1193   ** Return the largest host parameter index in the precompiled statement given
  1187   1194   ** as the argument.  When the host parameters are of the forms like ":AAA"
  1188   1195   ** or "?", then they are assigned sequential increasing numbers beginning
................................................................................
  1190   1197   ** if the same host parameter name is used multiple times, each occurrance
  1191   1198   ** is given the same number, so the value returned in that case is the number
  1192   1199   ** of unique host parameter names.  If host parameters of the form "?NNN"
  1193   1200   ** are used (where NNN is an integer) then there might be gaps in the
  1194   1201   ** numbering and the value returned by this interface is the index of the
  1195   1202   ** host parameter with the largest index value.
  1196   1203   */
  1197         -int sqlite3_bind_parameter_count(sqlite3_stmt*);
         1204  +SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
  1198   1205   
  1199   1206   /*
  1200   1207   ** CAPI3REF: Name Of A Host Parameter
  1201   1208   **
  1202   1209   ** This routine returns a pointer to the name of the n-th parameter in a 
  1203   1210   ** [sqlite3_stmt | prepared statement].
  1204   1211   ** Host parameters of the form ":AAA" or "@AAA" or "$VVV" have a name
................................................................................
  1210   1217   ** The first bound parameter has an index of 1, not 0.
  1211   1218   **
  1212   1219   ** If the value n is out of range or if the n-th parameter is nameless,
  1213   1220   ** then NULL is returned.  The returned string is always in the
  1214   1221   ** UTF-8 encoding even if the named parameter was originally specified
  1215   1222   ** as UTF-16 in [sqlite3_prepare16()] or [sqlite3_prepare16_v2()].
  1216   1223   */
  1217         -const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
         1224  +SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  1218   1225   
  1219   1226   /*
  1220   1227   ** CAPI3REF: Index Of A Parameter With A Given Name
  1221   1228   **
  1222   1229   ** This routine returns the index of a host parameter with the given name.
  1223   1230   ** The name must match exactly.  If no parameter with the given name is 
  1224   1231   ** found, return 0.  Parameter names must be UTF8.
  1225   1232   */
  1226         -int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
         1233  +SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  1227   1234   
  1228   1235   /*
  1229   1236   ** CAPI3REF: Reset All Bindings On A Prepared Statement
  1230   1237   **
  1231   1238   ** Contrary to the intuition of many, [sqlite3_reset()] does not
  1232   1239   ** reset the [sqlite3_bind_blob | bindings] on a 
  1233   1240   ** [sqlite3_stmt | prepared statement].  Use this routine to
  1234   1241   ** reset all host parameters to NULL.
  1235   1242   */
  1236         -int sqlite3_clear_bindings(sqlite3_stmt*);
         1243  +SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
  1237   1244   
  1238   1245   /*
  1239   1246   ** CAPI3REF: Number Of Columns In A Result Set
  1240   1247   **
  1241   1248   ** Return the number of columns in the result set returned by the 
  1242   1249   ** [sqlite3_stmt | compiled SQL statement]. This routine returns 0
  1243   1250   ** if pStmt is an SQL statement that does not return data (for 
  1244   1251   ** example an UPDATE).
  1245   1252   */
  1246         -int sqlite3_column_count(sqlite3_stmt *pStmt);
         1253  +SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
  1247   1254   
  1248   1255   /*
  1249   1256   ** CAPI3REF: Column Names In A Result Set
  1250   1257   **
  1251   1258   ** These routines return the name assigned to a particular column
  1252   1259   ** in the result set of a SELECT statement.  The sqlite3_column_name()
  1253   1260   ** interface returns a pointer to a UTF8 string and sqlite3_column_name16()
................................................................................
  1257   1264   ** number 0.
  1258   1265   **
  1259   1266   ** The returned string pointer is valid until either the 
  1260   1267   ** [sqlite_stmt | prepared statement] is destroyed by [sqlite3_finalize()]
  1261   1268   ** or until the next call sqlite3_column_name() or sqlite3_column_name16()
  1262   1269   ** on the same column.
  1263   1270   */
  1264         -const char *sqlite3_column_name(sqlite3_stmt*, int N);
  1265         -const void *sqlite3_column_name16(sqlite3_stmt*, int N);
         1271  +SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
         1272  +SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
  1266   1273   
  1267   1274   /*
  1268   1275   ** CAPI3REF: Source Of Data In A Query Result
  1269   1276   **
  1270   1277   ** These routines provide a means to determine what column of what
  1271   1278   ** table in which database a result of a SELECT statement comes from.
  1272   1279   ** The name of the database or table or column can be returned as
................................................................................
  1294   1301   **
  1295   1302   ** As with all other SQLite APIs, those postfixed with "16" return UTF-16
  1296   1303   ** encoded strings, the other functions return UTF-8.
  1297   1304   **
  1298   1305   ** These APIs are only available if the library was compiled with the 
  1299   1306   ** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
  1300   1307   */
  1301         -const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  1302         -const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  1303         -const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  1304         -const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  1305         -const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  1306         -const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
         1308  +SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
         1309  +SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
         1310  +SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
         1311  +SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
         1312  +SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
         1313  +SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  1307   1314   
  1308   1315   /*
  1309   1316   ** CAPI3REF: Declared Datatype Of A Query Result
  1310   1317   **
  1311   1318   ** The first parameter is a [sqlite3_stmt | compiled SQL statement]. 
  1312   1319   ** If this statement is a SELECT statement and the Nth column of the 
  1313   1320   ** returned result set  of that SELECT is a table column (not an
................................................................................
  1330   1337   ** SQLite uses dynamic run-time typing.  So just because a column
  1331   1338   ** is declared to contain a particular type does not mean that the
  1332   1339   ** data stored in that column is of the declared type.  SQLite is
  1333   1340   ** strongly typed, but the typing is dynamic not static.  Type
  1334   1341   ** is associated with individual values, not with the containers
  1335   1342   ** used to hold those values.
  1336   1343   */
  1337         -const char *sqlite3_column_decltype(sqlite3_stmt *, int i);
  1338         -const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
         1344  +SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt *, int i);
         1345  +SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  1339   1346   
  1340   1347   /* 
  1341   1348   ** CAPI3REF:  Evaluate An SQL Statement
  1342   1349   **
  1343   1350   ** After an [sqlite3_stmt | SQL statement] has been prepared with a call
  1344   1351   ** to either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or to one of
  1345   1352   ** the legacy interfaces [sqlite3_prepare()] or [sqlite3_prepare16()],
................................................................................
  1417   1424   ** After a call to [sqlite3_step()] that returns [SQLITE_ROW], this routine
  1418   1425   ** will return the same value as the [sqlite3_column_count()] function.
  1419   1426   ** After [sqlite3_step()] has returned an [SQLITE_DONE], [SQLITE_BUSY], or
  1420   1427   ** a [SQLITE_ERROR | error code], or before [sqlite3_step()] has been 
  1421   1428   ** called on the [sqlite_stmt | prepared statement] for the first time,
  1422   1429   ** this routine returns zero.
  1423   1430   */
  1424         -int sqlite3_data_count(sqlite3_stmt *pStmt);
         1431  +SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
  1425   1432   
  1426   1433   /*
  1427   1434   ** CAPI3REF: Fundamental Datatypes
  1428   1435   **
  1429   1436   ** Every value in SQLite has one of five fundamental datatypes:
  1430   1437   **
  1431   1438   ** <ul>
................................................................................
  1568   1575   ** In other words, you should call sqlite3_column_text(), sqlite3_column_blob(),
  1569   1576   ** or sqlite3_column_text16() first to force the result into the desired
  1570   1577   ** format, then invoke sqlite3_column_bytes() or sqlite3_column_bytes16() to
  1571   1578   ** find the size of the result.  Do not mix call to sqlite3_column_text() or
  1572   1579   ** sqlite3_column_blob() with calls to sqlite3_column_bytes16().  And do not
  1573   1580   ** mix calls to sqlite3_column_text16() with calls to sqlite3_column_bytes().
  1574   1581   */
  1575         -const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  1576         -int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  1577         -int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  1578         -double sqlite3_column_double(sqlite3_stmt*, int iCol);
  1579         -int sqlite3_column_int(sqlite3_stmt*, int iCol);
  1580         -sqlite_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  1581         -const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  1582         -const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  1583         -int sqlite3_column_type(sqlite3_stmt*, int iCol);
  1584         -sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
         1582  +SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
         1583  +SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
         1584  +SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
         1585  +SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
         1586  +SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
         1587  +SQLITE_API sqlite_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
         1588  +SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
         1589  +SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
         1590  +SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
         1591  +SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  1585   1592   
  1586   1593   /*
  1587   1594   ** CAPI3REF: Destroy A Prepared Statement Object
  1588   1595   **
  1589   1596   ** The sqlite3_finalize() function is called to delete a 
  1590   1597   ** [sqlite3_stmt | compiled SQL statement]. If the statement was
  1591   1598   ** executed successfully, or not executed at all, then SQLITE_OK is returned.
................................................................................
  1669   1676   **
  1670   1677   ** It is permitted to register multiple implementations of the same
  1671   1678   ** functions with the same name but with either differing numbers of
  1672   1679   ** arguments or differing perferred text encodings.  SQLite will use
  1673   1680   ** the implementation most closely matches the way in which the
  1674   1681   ** SQL function is used.
  1675   1682   */
  1676         -int sqlite3_create_function(
         1683  +SQLITE_API int sqlite3_create_function(
  1677   1684     sqlite3 *,
  1678   1685     const char *zFunctionName,
  1679   1686     int nArg,
  1680   1687     int eTextRep,
  1681   1688     void*,
  1682   1689     void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  1683   1690     void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  1684   1691     void (*xFinal)(sqlite3_context*)
  1685   1692   );
  1686         -int sqlite3_create_function16(
         1693  +SQLITE_API int sqlite3_create_function16(
  1687   1694     sqlite3*,
  1688   1695     const void *zFunctionName,
  1689   1696     int nArg,
  1690   1697     int eTextRep,
  1691   1698     void*,
  1692   1699     void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  1693   1700     void (*xStep)(sqlite3_context*,int,sqlite3_value**),
................................................................................
  1712   1719   **
  1713   1720   ** These functions are all now obsolete.  In order to maintain
  1714   1721   ** backwards compatibility with older code, we continue to support
  1715   1722   ** these functions.  However, new development projects should avoid
  1716   1723   ** the use of these functions.  To help encourage people to avoid
  1717   1724   ** using these functions, we are not going to tell you want they do.
  1718   1725   */
  1719         -int sqlite3_aggregate_count(sqlite3_context*);
         1726  +SQLITE_API int sqlite3_aggregate_count(sqlite3_context*);
  1720   1727   SQLITE_API int sqlite3_expired(sqlite3_stmt*);
  1721         -int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  1722         -int sqlite3_global_recover(void);
         1728  +SQLITE_API int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
         1729  +SQLITE_API int sqlite3_global_recover(void);
  1723   1730   
  1724   1731   
  1725   1732   /*
  1726   1733   ** CAPI3REF: Obtaining SQL Function Parameter Values
  1727   1734   **
  1728   1735   ** The C-language implementation of SQL functions and aggregates uses
  1729   1736   ** this set of interface routines to access the parameter values on
................................................................................
  1757   1764   **
  1758   1765   ** Please pay particular attention to the fact that the pointer that
  1759   1766   ** is returned from [sqlite3_value_blob()], [sqlite3_value_text()], or
  1760   1767   ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  1761   1768   ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite_value_text()],
  1762   1769   ** or [sqlite3_value_text16()].  
  1763   1770   */
  1764         -const void *sqlite3_value_blob(sqlite3_value*);
  1765         -int sqlite3_value_bytes(sqlite3_value*);
  1766         -int sqlite3_value_bytes16(sqlite3_value*);
  1767         -double sqlite3_value_double(sqlite3_value*);
  1768         -int sqlite3_value_int(sqlite3_value*);
  1769         -sqlite_int64 sqlite3_value_int64(sqlite3_value*);
  1770         -const unsigned char *sqlite3_value_text(sqlite3_value*);
  1771         -const void *sqlite3_value_text16(sqlite3_value*);
  1772         -const void *sqlite3_value_text16le(sqlite3_value*);
  1773         -const void *sqlite3_value_text16be(sqlite3_value*);
  1774         -int sqlite3_value_type(sqlite3_value*);
  1775         -int sqlite3_value_numeric_type(sqlite3_value*);
         1771  +SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
         1772  +SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
         1773  +SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
         1774  +SQLITE_API double sqlite3_value_double(sqlite3_value*);
         1775  +SQLITE_API int sqlite3_value_int(sqlite3_value*);
         1776  +SQLITE_API sqlite_int64 sqlite3_value_int64(sqlite3_value*);
         1777  +SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
         1778  +SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
         1779  +SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
         1780  +SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
         1781  +SQLITE_API int sqlite3_value_type(sqlite3_value*);
         1782  +SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
  1776   1783   
  1777   1784   /*
  1778   1785   ** CAPI3REF: Obtain Aggregate Function Context
  1779   1786   **
  1780   1787   ** The implementation of aggregate SQL functions use this routine to allocate
  1781   1788   ** a structure for storing their state.  The first time this routine
  1782   1789   ** is called for a particular aggregate, a new structure of size nBytes
................................................................................
  1788   1795   ** query concludes.
  1789   1796   **
  1790   1797   ** The first parameter should be a copy of the 
  1791   1798   ** [sqlite3_context | SQL function context] that is the first
  1792   1799   ** parameter to the callback routine that implements the aggregate
  1793   1800   ** function.
  1794   1801   */
  1795         -void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
         1802  +SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  1796   1803   
  1797   1804   /*
  1798   1805   ** CAPI3REF: User Data For Functions
  1799   1806   **
  1800   1807   ** The pUserData parameter to the [sqlite3_create_function()]
  1801   1808   ** and [sqlite3_create_function16()] routines
  1802   1809   ** used to register user functions is available to
  1803   1810   ** the implementation of the function using this call.
  1804   1811   */
  1805         -void *sqlite3_user_data(sqlite3_context*);
         1812  +SQLITE_API void *sqlite3_user_data(sqlite3_context*);
  1806   1813   
  1807   1814   /*
  1808   1815   ** CAPI3REF: Function Auxiliary Data
  1809   1816   **
  1810   1817   ** The following two functions may be used by scalar SQL functions to
  1811   1818   ** associate meta-data with argument values. If the same value is passed to
  1812   1819   ** multiple invocations of the same SQL function during query execution, under
................................................................................
  1830   1837   ** data pointer to release it when it is no longer required. If the 
  1831   1838   ** destructor is NULL, it is not invoked.
  1832   1839   **
  1833   1840   ** In practice, meta-data is preserved between function calls for
  1834   1841   ** expressions that are constant at compile time. This includes literal
  1835   1842   ** values and SQL variables.
  1836   1843   */
  1837         -void *sqlite3_get_auxdata(sqlite3_context*, int);
  1838         -void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*));
         1844  +SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int);
         1845  +SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*));
  1839   1846   
  1840   1847   
  1841   1848   /*
  1842   1849   ** CAPI3REF: Constants Defining Special Destructor Behavior
  1843   1850   **
  1844   1851   ** These are special value for the destructor that is passed in as the
  1845   1852   ** final argument to routines like [sqlite3_result_blob()].  If the destructor
................................................................................
  1876   1883   ** parameter to sqlite3_result_error() or sqlite3_result_error16()
  1877   1884   ** is the text of an error message.
  1878   1885   **
  1879   1886   ** The sqlite3_result_toobig() cause the function implementation
  1880   1887   ** to throw and error indicating that a string or BLOB is to long
  1881   1888   ** to represent.
  1882   1889   */
  1883         -void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  1884         -void sqlite3_result_double(sqlite3_context*, double);
  1885         -void sqlite3_result_error(sqlite3_context*, const char*, int);
  1886         -void sqlite3_result_error16(sqlite3_context*, const void*, int);
  1887         -void sqlite3_result_error_toobig(sqlite3_context*);
  1888         -void sqlite3_result_int(sqlite3_context*, int);
  1889         -void sqlite3_result_int64(sqlite3_context*, sqlite_int64);
  1890         -void sqlite3_result_null(sqlite3_context*);
  1891         -void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  1892         -void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  1893         -void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  1894         -void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  1895         -void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  1896         -void sqlite3_result_zeroblob(sqlite3_context*, int n);
         1890  +SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
         1891  +SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
         1892  +SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
         1893  +SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
         1894  +SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
         1895  +SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
         1896  +SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite_int64);
         1897  +SQLITE_API void sqlite3_result_null(sqlite3_context*);
         1898  +SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
         1899  +SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
         1900  +SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
         1901  +SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
         1902  +SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
         1903  +SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
  1897   1904   
  1898   1905   /*
  1899   1906   ** CAPI3REF: Define New Collating Sequences
  1900   1907   **
  1901   1908   ** These functions are used to add new collation sequences to the
  1902   1909   ** [sqlite3*] handle specified as the first argument. 
  1903   1910   **
................................................................................
  1933   1940   ** they are overridden by later calls to the collation creation functions
  1934   1941   ** or when the [sqlite3*] database handle is closed using [sqlite3_close()].
  1935   1942   **
  1936   1943   ** The sqlite3_create_collation_v2() interface is experimental and
  1937   1944   ** subject to change in future releases.  The other collation creation
  1938   1945   ** functions are stable.
  1939   1946   */
  1940         -int sqlite3_create_collation(
         1947  +SQLITE_API int sqlite3_create_collation(
  1941   1948     sqlite3*, 
  1942   1949     const char *zName, 
  1943   1950     int eTextRep, 
  1944   1951     void*,
  1945   1952     int(*xCompare)(void*,int,const void*,int,const void*)
  1946   1953   );
  1947         -int sqlite3_create_collation_v2(
         1954  +SQLITE_API int sqlite3_create_collation_v2(
  1948   1955     sqlite3*, 
  1949   1956     const char *zName, 
  1950   1957     int eTextRep, 
  1951   1958     void*,
  1952   1959     int(*xCompare)(void*,int,const void*,int,const void*),
  1953   1960     void(*xDestroy)(void*)
  1954   1961   );
  1955         -int sqlite3_create_collation16(
         1962  +SQLITE_API int sqlite3_create_collation16(
  1956   1963     sqlite3*, 
  1957   1964     const char *zName, 
  1958   1965     int eTextRep, 
  1959   1966     void*,
  1960   1967     int(*xCompare)(void*,int,const void*,int,const void*)
  1961   1968   );
  1962   1969   
................................................................................
  1982   1989   ** sequence function required. The fourth parameter is the name of the
  1983   1990   ** required collation sequence.
  1984   1991   **
  1985   1992   ** The callback function should register the desired collation using
  1986   1993   ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  1987   1994   ** [sqlite3_create_collation_v2()].
  1988   1995   */
  1989         -int sqlite3_collation_needed(
         1996  +SQLITE_API int sqlite3_collation_needed(
  1990   1997     sqlite3*, 
  1991   1998     void*, 
  1992   1999     void(*)(void*,sqlite3*,int eTextRep,const char*)
  1993   2000   );
  1994         -int sqlite3_collation_needed16(
         2001  +SQLITE_API int sqlite3_collation_needed16(
  1995   2002     sqlite3*, 
  1996   2003     void*,
  1997   2004     void(*)(void*,sqlite3*,int eTextRep,const void*)
  1998   2005   );
  1999   2006   
  2000   2007   /*
  2001   2008   ** Specify the key for an encrypted database.  This routine should be
................................................................................
  2045   2052   ** file directory.
  2046   2053   **
  2047   2054   ** Once [sqlite3_open()] has been called, changing this variable will
  2048   2055   ** invalidate the current temporary database, if any.  Generally speaking,
  2049   2056   ** it is not safe to invoke this routine after [sqlite3_open()] has
  2050   2057   ** been called.
  2051   2058   */
  2052         -extern char *sqlite3_temp_directory;
         2059  +SQLITE_EXTERN char *sqlite3_temp_directory;
  2053   2060   
  2054   2061   /*
  2055   2062   ** CAPI3REF:  Test To See If The Databse Is In Auto-Commit Mode
  2056   2063   **
  2057   2064   ** Test to see whether or not the database connection is in autocommit
  2058   2065   ** mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
  2059   2066   ** by default.  Autocommit is disabled by a BEGIN statement and reenabled
  2060   2067   ** by the next COMMIT or ROLLBACK.
  2061   2068   */
  2062         -int sqlite3_get_autocommit(sqlite3*);
         2069  +SQLITE_API int sqlite3_get_autocommit(sqlite3*);
  2063   2070   
  2064   2071   /*
  2065   2072   ** CAPI3REF:  Find The Database Handle Associated With A Prepared Statement
  2066   2073   **
  2067   2074   ** Return the [sqlite3*] database handle to which a
  2068   2075   ** [sqlite3_stmt | prepared statement] belongs.
  2069   2076   ** This is the same database handle that was
  2070   2077   ** the first argument to the [sqlite3_prepare_v2()] or its variants
  2071   2078   ** that was used to create the statement in the first place.
  2072   2079   */
  2073         -sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
         2080  +SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  2074   2081   
  2075   2082   
  2076   2083   /*
  2077   2084   ** CAPI3REF: Commit And Rollback Notification Callbacks
  2078   2085   **
  2079   2086   ** These routines
  2080   2087   ** register callback functions to be invoked whenever a transaction
................................................................................
  2091   2098   ** rolled back if an explicit "ROLLBACK" statement is executed, or
  2092   2099   ** an error or constraint causes an implicit rollback to occur. The 
  2093   2100   ** callback is not invoked if a transaction is automatically rolled
  2094   2101   ** back because the database connection is closed.
  2095   2102   **
  2096   2103   ** These are experimental interfaces and are subject to change.
  2097   2104   */
  2098         -void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  2099         -void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
         2105  +SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
         2106  +SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  2100   2107   
  2101   2108   /*
  2102   2109   ** CAPI3REF: Data Change Notification Callbacks
  2103   2110   **
  2104   2111   ** Register a callback function with the database connection identified by the 
  2105   2112   ** first argument to be invoked whenever a row is updated, inserted or deleted.
  2106   2113   ** Any callback set by a previous call to this function for the same 
................................................................................
  2118   2125   **
  2119   2126   ** The update hook is not invoked when internal system tables are
  2120   2127   ** modified (i.e. sqlite_master and sqlite_sequence).
  2121   2128   **
  2122   2129   ** If another function was previously registered, its pArg value is returned.
  2123   2130   ** Otherwise NULL is returned.
  2124   2131   */
  2125         -void *sqlite3_update_hook(
         2132  +SQLITE_API void *sqlite3_update_hook(
  2126   2133     sqlite3*, 
  2127   2134     void(*)(void *,int ,char const *,char const *,sqlite_int64),
  2128   2135     void*
  2129   2136   );
  2130   2137   
  2131   2138   /*
  2132   2139   ** CAPI3REF:  Enable Or Disable Shared Pager Cache
................................................................................
  2165   2172   **
  2166   2173   ** This routine returns [SQLITE_OK] if shared cache was
  2167   2174   ** enabled or disabled successfully.  An [SQLITE_ERROR | error code]
  2168   2175   ** is returned otherwise.
  2169   2176   **
  2170   2177   ** Shared cache is disabled by default for backward compatibility.
  2171   2178   */
  2172         -int sqlite3_enable_shared_cache(int);
         2179  +SQLITE_API int sqlite3_enable_shared_cache(int);
  2173   2180   
  2174   2181   /*
  2175   2182   ** CAPI3REF:  Attempt To Free Heap Memory
  2176   2183   **
  2177   2184   ** Attempt to free N bytes of heap memory by deallocating non-essential
  2178   2185   ** memory allocations held by the database library (example: memory 
  2179   2186   ** used to cache database pages to improve performance).
  2180   2187   **
  2181   2188   ** This function is not a part of standard builds.  It is only created
  2182   2189   ** if SQLite is compiled with the SQLITE_ENABLE_MEMORY_MANAGEMENT macro.
  2183   2190   */
  2184         -int sqlite3_release_memory(int);
         2191  +SQLITE_API int sqlite3_release_memory(int);
  2185   2192   
  2186   2193   /*
  2187   2194   ** CAPI3REF:  Impose A Limit On Heap Size
  2188   2195   **
  2189   2196   ** Place a "soft" limit on the amount of heap memory that may be allocated by
  2190   2197   ** SQLite within the current thread. If an internal allocation is requested 
  2191   2198   ** that would exceed the specified limit, [sqlite3_release_memory()] is invoked
................................................................................
  2208   2215   ** continue without error or notification.  This is why the limit is 
  2209   2216   ** called a "soft" limit.  It is advisory only.
  2210   2217   **
  2211   2218   ** This function is only available if the library was compiled with the 
  2212   2219   ** SQLITE_ENABLE_MEMORY_MANAGEMENT option set.
  2213   2220   ** memory-management has been enabled.
  2214   2221   */
  2215         -void sqlite3_soft_heap_limit(int);
         2222  +SQLITE_API void sqlite3_soft_heap_limit(int);
  2216   2223   
  2217   2224   /*
  2218   2225   ** CAPI3REF:  Clean Up Thread Local Storage
  2219   2226   **
  2220   2227   ** This routine makes sure that all thread-local storage has been
  2221   2228   ** deallocated for the current thread.
  2222   2229   **
................................................................................
  2223   2230   ** This routine is not technically necessary.  All thread-local storage
  2224   2231   ** will be automatically deallocated once memory-management and
  2225   2232   ** shared-cache are disabled and the soft heap limit has been set
  2226   2233   ** to zero.  This routine is provided as a convenience for users who
  2227   2234   ** want to make absolutely sure they have not forgotten something
  2228   2235   ** prior to killing off a thread.
  2229   2236   */
  2230         -void sqlite3_thread_cleanup(void);
         2237  +SQLITE_API void sqlite3_thread_cleanup(void);
  2231   2238   
  2232   2239   /*
  2233   2240   ** CAPI3REF:  Extract Metadata About A Column Of A Table
  2234   2241   **
  2235   2242   ** This routine
  2236   2243   ** returns meta-data about a specific column of a specific database
  2237   2244   ** table accessible using the connection handle passed as the first function 
................................................................................
  2289   2296   ** error occurs during this process, or if the requested table or column
  2290   2297   ** cannot be found, an SQLITE error code is returned and an error message
  2291   2298   ** left in the database handle (to be retrieved using sqlite3_errmsg()).
  2292   2299   **
  2293   2300   ** This API is only available if the library was compiled with the
  2294   2301   ** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
  2295   2302   */
  2296         -int sqlite3_table_column_metadata(
         2303  +SQLITE_API int sqlite3_table_column_metadata(
  2297   2304     sqlite3 *db,                /* Connection handle */
  2298   2305     const char *zDbName,        /* Database name or NULL */
  2299   2306     const char *zTableName,     /* Table name */
  2300   2307     const char *zColumnName,    /* Column name */
  2301   2308     char const **pzDataType,    /* OUTPUT: Declared data type */
  2302   2309     char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
  2303   2310     int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
................................................................................
  2317   2324   ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with 
  2318   2325   ** error message text.  The calling function should free this memory
  2319   2326   ** by calling [sqlite3_free()].
  2320   2327   **
  2321   2328   ** Extension loading must be enabled using [sqlite3_enable_load_extension()]
  2322   2329   ** prior to calling this API or an error will be returned.
  2323   2330   */
  2324         -int sqlite3_load_extension(
         2331  +SQLITE_API int sqlite3_load_extension(
  2325   2332     sqlite3 *db,          /* Load the extension into this database connection */
  2326   2333     const char *zFile,    /* Name of the shared library containing extension */
  2327   2334     const char *zProc,    /* Entry point.  Derived from zFile if 0 */
  2328   2335     char **pzErrMsg       /* Put error message here if not 0 */
  2329   2336   );
  2330   2337   
  2331   2338   /*
................................................................................
  2336   2343   ** extension loading while evaluating user-entered SQL, the following
  2337   2344   ** API is provided to turn the [sqlite3_load_extension()] mechanism on and
  2338   2345   ** off.  It is off by default.  See ticket #1863.
  2339   2346   **
  2340   2347   ** Call this routine with onoff==1 to turn extension loading on
  2341   2348   ** and call it with onoff==0 to turn it back off again.
  2342   2349   */
  2343         -int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
         2350  +SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  2344   2351   
  2345   2352   /*
  2346   2353   ** CAPI3REF: Make Arrangements To Automatically Load An Extension
  2347   2354   **
  2348   2355   ** Register an extension entry point that is automatically invoked
  2349   2356   ** whenever a new database connection is opened using
  2350   2357   ** [sqlite3_open()] or [sqlite3_open16()].
................................................................................
  2363   2370   ** to shutdown to free the memory.
  2364   2371   **
  2365   2372   ** Automatic extensions apply across all threads.
  2366   2373   **
  2367   2374   ** This interface is experimental and is subject to change or
  2368   2375   ** removal in future releases of SQLite.
  2369   2376   */
  2370         -int sqlite3_auto_extension(void *xEntryPoint);
         2377  +SQLITE_API int sqlite3_auto_extension(void *xEntryPoint);
  2371   2378   
  2372   2379   
  2373   2380   /*
  2374   2381   ** CAPI3REF: Reset Automatic Extension Loading
  2375   2382   **
  2376   2383   ** Disable all previously registered automatic extensions.  This
  2377   2384   ** routine undoes the effect of all prior [sqlite3_automatic_extension()]
................................................................................
  2378   2385   ** calls.
  2379   2386   **
  2380   2387   ** This call disabled automatic extensions in all threads.
  2381   2388   **
  2382   2389   ** This interface is experimental and is subject to change or
  2383   2390   ** removal in future releases of SQLite.
  2384   2391   */
  2385         -void sqlite3_reset_auto_extension(void);
         2392  +SQLITE_API void sqlite3_reset_auto_extension(void);
  2386   2393   
  2387   2394   
  2388   2395   /*
  2389   2396   ****** EXPERIMENTAL - subject to change without notice **************
  2390   2397   **
  2391   2398   ** The interface to the virtual-table mechanism is currently considered
  2392   2399   ** to be experimental.  The interface might change in incompatible ways.
................................................................................
  2521   2528   
  2522   2529   /*
  2523   2530   ** This routine is used to register a new module name with an SQLite
  2524   2531   ** connection.  Module names must be registered before creating new
  2525   2532   ** virtual tables on the module, or before using preexisting virtual
  2526   2533   ** tables of the module.
  2527   2534   */
  2528         -int sqlite3_create_module(
         2535  +SQLITE_API int sqlite3_create_module(
  2529   2536     sqlite3 *db,               /* SQLite connection to register module with */
  2530   2537     const char *zName,         /* Name of the module */
  2531   2538     const sqlite3_module *,    /* Methods for the module */
  2532   2539     void *                     /* Client data for xCreate/xConnect */
  2533   2540   );
  2534   2541   
  2535   2542   /*
  2536   2543   ** This routine is identical to the sqlite3_create_module() method above,
  2537   2544   ** except that it allows a destructor function to be specified. It is
  2538   2545   ** even more experimental than the rest of the virtual tables API.
  2539   2546   */
  2540         -int sqlite3_create_module_v2(
         2547  +SQLITE_API int sqlite3_create_module_v2(
  2541   2548     sqlite3 *db,               /* SQLite connection to register module with */
  2542   2549     const char *zName,         /* Name of the module */
  2543   2550     const sqlite3_module *,    /* Methods for the module */
  2544   2551     void *,                    /* Client data for xCreate/xConnect */
  2545   2552     void(*xDestroy)(void*)     /* Module destructor function */
  2546   2553   );
  2547   2554   
................................................................................
  2584   2591   };
  2585   2592   
  2586   2593   /*
  2587   2594   ** The xCreate and xConnect methods of a module use the following API
  2588   2595   ** to declare the format (the names and datatypes of the columns) of
  2589   2596   ** the virtual tables they implement.
  2590   2597   */
  2591         -int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
         2598  +SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
  2592   2599   
  2593   2600   /*
  2594   2601   ** Virtual tables can provide alternative implementations of functions
  2595   2602   ** using the xFindFunction method.  But global versions of those functions
  2596   2603   ** must exist in order to be overloaded.
  2597   2604   **
  2598   2605   ** This API makes sure a global version of a function with a particular
................................................................................
  2602   2609   ** the new function is not good for anything by itself.  Its only
  2603   2610   ** purpose is to be a place-holder function that can be overloaded
  2604   2611   ** by virtual tables.
  2605   2612   **
  2606   2613   ** This API should be considered part of the virtual table interface,
  2607   2614   ** which is experimental and subject to change.
  2608   2615   */
  2609         -int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
         2616  +SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  2610   2617   
  2611   2618   /*
  2612   2619   ** The interface to the virtual-table mechanism defined above (back up
  2613   2620   ** to a comment remarkably similar to this one) is currently considered
  2614   2621   ** to be experimental.  The interface might change in incompatible ways.
  2615   2622   ** If this is a problem for you, do not use the interface at this time.
  2616   2623   **
................................................................................
  2651   2658   ** On success, [SQLITE_OK] is returned and the new 
  2652   2659   ** [sqlite3_blob | blob handle] is written to *ppBlob.
  2653   2660   ** Otherwise an error code is returned and 
  2654   2661   ** any value written to *ppBlob should not be used by the caller.
  2655   2662   ** This function sets the database-handle error code and message
  2656   2663   ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()].
  2657   2664   */
  2658         -int sqlite3_blob_open(
         2665  +SQLITE_API int sqlite3_blob_open(
  2659   2666     sqlite3*,
  2660   2667     const char *zDb,
  2661   2668     const char *zTable,
  2662   2669     const char *zColumn,
  2663   2670     sqlite_int64 iRow,
  2664   2671     int flags,
  2665   2672     sqlite3_blob **ppBlob
................................................................................
  2666   2673   );
  2667   2674   
  2668   2675   /*
  2669   2676   ** CAPI3REF:  Close A BLOB Handle
  2670   2677   **
  2671   2678   ** Close an open [sqlite3_blob | blob handle].
  2672   2679   */
  2673         -int sqlite3_blob_close(sqlite3_blob *);
         2680  +SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
  2674   2681   
  2675   2682   /*
  2676   2683   ** CAPI3REF:  Return The Size Of An Open BLOB
  2677   2684   **
  2678   2685   ** Return the size in bytes of the blob accessible via the open 
  2679   2686   ** [sqlite3_blob | blob-handle] passed as an argument.
  2680   2687   */
  2681         -int sqlite3_blob_bytes(sqlite3_blob *);
         2688  +SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
  2682   2689   
  2683   2690   /*
  2684   2691   ** CAPI3REF:  Read Data From A BLOB Incrementally
  2685   2692   **
  2686   2693   ** This function is used to read data from an open 
  2687   2694   ** [sqlite3_blob | blob-handle] into a caller supplied buffer.
  2688   2695   ** n bytes of data are copied into buffer
  2689   2696   ** z from the open blob, starting at offset iOffset.
  2690   2697   **
  2691   2698   ** On success, SQLITE_OK is returned. Otherwise, an 
  2692   2699   ** [SQLITE_ERROR | SQLite error code] or an
  2693   2700   ** [SQLITE_IOERR_READ | extended error code] is returned.
  2694   2701   */
  2695         -int sqlite3_blob_read(sqlite3_blob *, void *z, int n, int iOffset);
         2702  +SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *z, int n, int iOffset);
  2696   2703   
  2697   2704   /*
  2698   2705   ** CAPI3REF:  Write Data Into A BLOB Incrementally
  2699   2706   **
  2700   2707   ** This function is used to write data into an open 
  2701   2708   ** [sqlite3_blob | blob-handle] from a user supplied buffer.
  2702   2709   ** n bytes of data are copied from the buffer
................................................................................
  2711   2718   ** offset iOffset is less than n bytes from the end of the blob, 
  2712   2719   ** [SQLITE_ERROR] is returned and no data is written.
  2713   2720   **
  2714   2721   ** On success, SQLITE_OK is returned. Otherwise, an 
  2715   2722   ** [SQLITE_ERROR | SQLite error code] or an
  2716   2723   ** [SQLITE_IOERR_READ | extended error code] is returned.
  2717   2724   */
  2718         -int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
         2725  +SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  2719   2726   
  2720   2727   /*
  2721   2728   ** Undo the hack that converts floating point types to integer for
  2722   2729   ** builds on processors without floating point support.
  2723   2730   */
  2724   2731   #ifdef SQLITE_OMIT_FLOATING_POINT
  2725   2732   # undef double
................................................................................
  2746   2753   ** This file contains the C functions that implement date and time
  2747   2754   ** functions for SQLite.  
  2748   2755   **
  2749   2756   ** There is only one exported symbol in this file - the function
  2750   2757   ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
  2751   2758   ** All other code has file scope.
  2752   2759   **
  2753         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         2760  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  2754   2761   **
  2755   2762   ** SQLite processes all times and dates as Julian Day numbers.  The
  2756   2763   ** dates and times are stored as the number of days since noon
  2757   2764   ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
  2758   2765   ** calendar system. 
  2759   2766   **
  2760   2767   ** 1970-01-01 00:00:00 is JD 2440587.5
................................................................................
  2790   2797   **    May you do good and not evil.
  2791   2798   **    May you find forgiveness for yourself and forgive others.
  2792   2799   **    May you share freely, never taking more than you give.
  2793   2800   **
  2794   2801   *************************************************************************
  2795   2802   ** Internal interface definitions for SQLite.
  2796   2803   **
  2797         -** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         2804  +** @(#) $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  2798   2805   */
  2799   2806   #ifndef _SQLITEINT_H_
  2800   2807   #define _SQLITEINT_H_
  2801   2808   /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
  2802   2809   /************** Begin file sqliteLimit.h *************************************/
  2803   2810   /*
  2804   2811   ** 2007 May 7
................................................................................
  2810   2817   **    May you find forgiveness for yourself and forgive others.
  2811   2818   **    May you share freely, never taking more than you give.
  2812   2819   **
  2813   2820   *************************************************************************
  2814   2821   ** 
  2815   2822   ** This file defines various limits of what SQLite can process.
  2816   2823   **
  2817         -** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         2824  +** @(#) $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  2818   2825   */
  2819   2826   
  2820   2827   /*
  2821   2828   ** The maximum length of a TEXT or BLOB in bytes.   This also
  2822   2829   ** limits the size of a row in a table or index.
  2823   2830   **
  2824   2831   ** The hard limit is the ability of a 32-bit signed integer
................................................................................
  3013   3020   **    May you find forgiveness for yourself and forgive others.
  3014   3021   **    May you share freely, never taking more than you give.
  3015   3022   **
  3016   3023   *************************************************************************
  3017   3024   ** This is the header file for the generic hash-table implemenation
  3018   3025   ** used in SQLite.
  3019   3026   **
  3020         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         3027  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  3021   3028   */
  3022   3029   #ifndef _SQLITE_HASH_H_
  3023   3030   #define _SQLITE_HASH_H_
  3024   3031   
  3025   3032   /* Forward declarations of structures. */
  3026   3033   typedef struct Hash Hash;
  3027   3034   typedef struct HashElem HashElem;
................................................................................
  3395   3402   typedef UINT8_TYPE u8;             /* 1-byte unsigned integer */
  3396   3403   typedef UINT8_TYPE i8;             /* 1-byte signed integer */
  3397   3404   
  3398   3405   /*
  3399   3406   ** Macros to determine whether the machine is big or little endian,
  3400   3407   ** evaluated at runtime.
  3401   3408   */
  3402         -extern const int sqlite3one;
         3409  +SQLITE_PRIVATE const int sqlite3one;
  3403   3410   #if defined(i386) || defined(__i386__) || defined(_M_IX86)
  3404   3411   # define SQLITE_BIGENDIAN    0
  3405   3412   # define SQLITE_LITTLEENDIAN 1
  3406   3413   # define SQLITE_UTF16NATIVE  SQLITE_UTF16LE
  3407   3414   #else
  3408   3415   # define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
  3409   3416   # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
................................................................................
  3445   3452   *************************************************************************
  3446   3453   ** Header file for the Virtual DataBase Engine (VDBE)
  3447   3454   **
  3448   3455   ** This header defines the interface to the virtual database engine
  3449   3456   ** or VDBE.  The VDBE implements an abstract machine that runs a
  3450   3457   ** simple program to access and modify the underlying database.
  3451   3458   **
  3452         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         3459  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  3453   3460   */
  3454   3461   #ifndef _SQLITE_VDBE_H_
  3455   3462   #define _SQLITE_VDBE_H_
  3456   3463   
  3457   3464   /*
  3458   3465   ** A single VDBE is an opaque structure named "Vdbe".  Only routines
  3459   3466   ** in the source file sqliteVdbe.c are allowed to see the insides
................................................................................
  3761   3768   **    May you share freely, never taking more than you give.
  3762   3769   **
  3763   3770   *************************************************************************
  3764   3771   ** This header file defines the interface that the sqlite B-Tree file
  3765   3772   ** subsystem.  See comments in the source code for a detailed description
  3766   3773   ** of what each interface routine does.
  3767   3774   **
  3768         -** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         3775  +** @(#) $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  3769   3776   */
  3770   3777   #ifndef _BTREE_H_
  3771   3778   #define _BTREE_H_
  3772   3779   
  3773   3780   /* TODO: This definition is just included so other modules compile. It
  3774   3781   ** needs to be revisited.
  3775   3782   */
................................................................................
  3915   3922   **    May you share freely, never taking more than you give.
  3916   3923   **
  3917   3924   *************************************************************************
  3918   3925   ** This header file defines the interface that the sqlite page cache
  3919   3926   ** subsystem.  The page cache subsystem reads and writes a file a page
  3920   3927   ** at a time and provides a journal for rollback.
  3921   3928   **
  3922         -** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         3929  +** @(#) $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  3923   3930   */
  3924   3931   
  3925   3932   #ifndef _PAGER_H_
  3926   3933   #define _PAGER_H_
  3927   3934   
  3928   3935   /*
  3929   3936   ** The type used to represent a page number.  The first page in a file
................................................................................
  4037   4044   /************** Continuing where we left off in sqliteInt.h ******************/
  4038   4045   
  4039   4046   #ifdef SQLITE_MEMDEBUG
  4040   4047   /*
  4041   4048   ** The following global variables are used for testing and debugging
  4042   4049   ** only.  They only work if SQLITE_MEMDEBUG is defined.
  4043   4050   */
  4044         -extern int sqlite3_nMalloc;      /* Number of sqliteMalloc() calls */
  4045         -extern int sqlite3_nFree;        /* Number of sqliteFree() calls */
  4046         -extern int sqlite3_iMallocFail;  /* Fail sqliteMalloc() after this many calls */
  4047         -extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
         4051  +SQLITE_API extern int sqlite3_nMalloc;      /* Number of sqliteMalloc() calls */
         4052  +SQLITE_API extern int sqlite3_nFree;        /* Number of sqliteFree() calls */
         4053  +SQLITE_API extern int sqlite3_iMallocFail;  /* Fail sqliteMalloc() after this many calls */
         4054  +SQLITE_API extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
  4048   4055   
  4049         -extern void *sqlite3_pFirst;         /* Pointer to linked list of allocations */
  4050         -extern int sqlite3_nMaxAlloc;        /* High water mark of ThreadData.nAlloc */
  4051         -extern int sqlite3_mallocDisallowed; /* assert() in sqlite3Malloc() if set */
  4052         -extern int sqlite3_isFail;           /* True if all malloc calls should fail */
  4053         -extern const char *sqlite3_zFile;    /* Filename to associate debug info with */
  4054         -extern int sqlite3_iLine;            /* Line number for debug info */
         4056  +SQLITE_API extern void *sqlite3_pFirst;         /* Pointer to linked list of allocations */
         4057  +SQLITE_API extern int sqlite3_nMaxAlloc;        /* High water mark of ThreadData.nAlloc */
         4058  +SQLITE_API extern int sqlite3_mallocDisallowed; /* assert() in sqlite3Malloc() if set */
         4059  +SQLITE_API extern int sqlite3_isFail;           /* True if all malloc calls should fail */
         4060  +SQLITE_API extern const char *sqlite3_zFile;    /* Filename to associate debug info with */
         4061  +SQLITE_API extern int sqlite3_iLine;            /* Line number for debug info */
  4055   4062   
  4056   4063   #define ENTER_MALLOC (sqlite3_zFile = __FILE__, sqlite3_iLine = __LINE__)
  4057   4064   #define sqliteMalloc(x)          (ENTER_MALLOC, sqlite3Malloc(x,1))
  4058   4065   #define sqliteMallocRaw(x)       (ENTER_MALLOC, sqlite3MallocRaw(x,1))
  4059   4066   #define sqliteRealloc(x,y)       (ENTER_MALLOC, sqlite3Realloc(x,y))
  4060   4067   #define sqliteStrDup(x)          (ENTER_MALLOC, sqlite3StrDup(x))
  4061   4068   #define sqliteStrNDup(x,y)       (ENTER_MALLOC, sqlite3StrNDup(x,y))
................................................................................
  4069   4076   #define sqliteRealloc(x,y)       sqlite3Realloc(x,y)
  4070   4077   #define sqliteStrDup(x)          sqlite3StrDup(x)
  4071   4078   #define sqliteStrNDup(x,y)       sqlite3StrNDup(x,y)
  4072   4079   #define sqliteReallocOrFree(x,y) sqlite3ReallocOrFree(x,y)
  4073   4080   
  4074   4081   #endif
  4075   4082   
  4076         -/* Variable sqlite3_mallocHasFailed is set to true after a malloc() 
         4083  +/* Variable sqlite3MallocHasFailed is set to true after a malloc() 
  4077   4084   ** failure occurs. 
  4078   4085   **
  4079   4086   ** The sqlite3MallocFailed() macro returns true if a malloc has failed
  4080   4087   ** in this thread since the last call to sqlite3ApiExit(), or false 
  4081   4088   ** otherwise.
  4082   4089   */
  4083         -extern int sqlite3_mallocHasFailed;
  4084         -#define sqlite3MallocFailed() (sqlite3_mallocHasFailed && sqlite3OsInMutex(1))
         4090  +SQLITE_PRIVATE int sqlite3MallocHasFailed;
         4091  +#define sqlite3MallocFailed() (sqlite3MallocHasFailed && sqlite3OsInMutex(1))
  4085   4092   
  4086   4093   #define sqliteFree(x)          sqlite3FreeX(x)
  4087   4094   #define sqliteAllocSize(x)     sqlite3AllocSize(x)
  4088   4095   
  4089   4096   /*
  4090   4097   ** An instance of this structure might be allocated to store information
  4091   4098   ** specific to a single thread.
................................................................................
  4498   4505   ** The default location of PENDING_BYTE is the first byte past the
  4499   4506   ** 1GB boundary.
  4500   4507   **
  4501   4508   */
  4502   4509   #ifndef SQLITE_TEST
  4503   4510   #define PENDING_BYTE      0x40000000  /* First byte past the 1GB boundary */
  4504   4511   #else
  4505         -extern unsigned int sqlite3_pending_byte;
         4512  +SQLITE_API extern unsigned int sqlite3_pending_byte;
  4506   4513   #define PENDING_BYTE sqlite3_pending_byte
  4507   4514   #endif
  4508   4515   
  4509   4516   #define RESERVED_BYTE     (PENDING_BYTE+1)
  4510   4517   #define SHARED_FIRST      (PENDING_BYTE+2)
  4511   4518   #define SHARED_SIZE       510
  4512   4519   
................................................................................
  4656   4663     ** Files other than os.c just reference the global virtual function table. 
  4657   4664     */
  4658   4665     extern struct sqlite3OsVtbl sqlite3Os;
  4659   4666   #endif /* _SQLITE_OS_C_ */
  4660   4667   
  4661   4668   
  4662   4669   /* This additional API routine is available with redefinable I/O */
  4663         -struct sqlite3OsVtbl *sqlite3_os_switch(void);
         4670  +SQLITE_API struct sqlite3OsVtbl *sqlite3_os_switch(void);
  4664   4671   
  4665   4672   
  4666   4673   /*
  4667   4674   ** Redefine the OS interface to go through the virtual function table
  4668   4675   ** rather than calling routines directly.
  4669   4676   */
  4670   4677   #undef sqlite3OsOpenReadWrite
................................................................................
  5842   5849    */
  5843   5850   struct TriggerStep {
  5844   5851     int op;              /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
  5845   5852     int orconf;          /* OE_Rollback etc. */
  5846   5853     Trigger *pTrig;      /* The trigger that this step is a part of */
  5847   5854   
  5848   5855     Select *pSelect;     /* Valid for SELECT and sometimes 
  5849         -			  INSERT steps (when pExprList == 0) */
         5856  +                          INSERT steps (when pExprList == 0) */
  5850   5857     Token target;        /* Valid for DELETE, UPDATE, INSERT steps */
  5851   5858     Expr *pWhere;        /* Valid for DELETE, UPDATE steps */
  5852   5859     ExprList *pExprList; /* Valid for UPDATE statements and sometimes 
  5853         -			   INSERT steps (when pSelect == 0)         */
         5860  +                           INSERT steps (when pSelect == 0)         */
  5854   5861     IdList *pIdList;     /* Valid for INSERT statements only */
  5855   5862     TriggerStep *pNext;  /* Next in the link-list */
  5856   5863     TriggerStep *pLast;  /* Last element in link-list. Valid for 1st elem only */
  5857   5864   };
  5858   5865   
  5859   5866   /*
  5860   5867    * An instance of struct TriggerStack stores information required during code
................................................................................
  5914   5921     sqlite3 *db;        /* The database being initialized */
  5915   5922     int iDb;            /* 0 for main database.  1 for TEMP, 2.. for ATTACHed */
  5916   5923     char **pzErrMsg;    /* Error message stored here */
  5917   5924     int rc;             /* Result code stored here */
  5918   5925   } InitData;
  5919   5926   
  5920   5927   /*
  5921         - * This global flag is set for performance testing of triggers. When it is set
  5922         - * SQLite will perform the overhead of building new and old trigger references 
  5923         - * even when no triggers exist
  5924         - */
  5925         -extern int sqlite3_always_code_trigger_setup;
  5926         -
  5927         -/*
  5928         -** A lookup table used by the SQLITE_READ_UTF8 macro.  The definition
  5929         -** is in utf.c.
         5928  +** Assuming zIn points to the first byte of a UTF-8 character,
         5929  +** advance zIn to point to the first byte of the next UTF-8 character.
  5930   5930   */
  5931         -extern const unsigned char sqlite3UtfTrans1[];
  5932         -
  5933         -/*
  5934         -** Macros for reading UTF8 characters.
  5935         -**
  5936         -** SQLITE_READ_UTF8(x,c) reads a single UTF8 value out of x and writes
  5937         -** that value into c.  The type of x must be unsigned char*.  The type
  5938         -** of c must be unsigned int.
  5939         -**
  5940         -** SQLITE_SKIP_UTF8(x) advances x forward by one character.  The type of
  5941         -** x must be unsigned char*.
  5942         -**
  5943         -** Notes On Invalid UTF-8:
  5944         -**
  5945         -**  *  These macros never allow a 7-bit character (0x00 through 0x7f) to
  5946         -**     be encoded as a multi-byte character.  Any multi-byte character that
  5947         -**     attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd.
  5948         -**
  5949         -**  *  These macros never allow a UTF16 surrogate value to be encoded.
  5950         -**     If a multi-byte character attempts to encode a value between
  5951         -**     0xd800 and 0xe000 then it is rendered as 0xfffd.
  5952         -**
  5953         -**  *  Bytes in the range of 0x80 through 0xbf which occur as the first
  5954         -**     byte of a character are interpreted as single-byte characters
  5955         -**     and rendered as themselves even though they are technically
  5956         -**     invalid characters.
  5957         -**
  5958         -**  *  These routines accept an infinite number of different UTF8 encodings
  5959         -**     for unicode values 0x80 and greater.  They do not change over-length
  5960         -**     encodings to 0xfffd as some systems recommend.
  5961         -** 
  5962         -*/
  5963         -#define SQLITE_READ_UTF8(zIn, c) {                     \
  5964         -  c = *(zIn++);                                        \
  5965         -  if( c>=0xc0 ){                                       \
  5966         -    c = sqlite3UtfTrans1[c-0xc0];                      \
  5967         -    while( (*zIn & 0xc0)==0x80 ){                      \
  5968         -      c = (c<<6) + (0x3f & *(zIn++));                  \
  5969         -    }                                                  \
  5970         -    if( c<0x80                                         \
  5971         -        || (c&0xFFFFF800)==0xD800                      \
  5972         -        || (c&0xFFFFFFFE)==0xFFFE ){  c = 0xFFFD; }    \
  5973         -  }                                                    \
  5974         -}
  5975   5931   #define SQLITE_SKIP_UTF8(zIn) {                        \
  5976   5932     if( (*(zIn++))>=0xc0 ){                              \
  5977   5933       while( (*zIn & 0xc0)==0x80 ){ zIn++; }             \
  5978   5934     }                                                    \
  5979   5935   }
  5980         -
  5981         -
  5982         -
  5983   5936   
  5984   5937   /*
  5985   5938   ** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production
  5986   5939   ** builds) or a function call (for debugging).  If it is a function call,
  5987   5940   ** it allows the operator to set a breakpoint at the spot where database
  5988   5941   ** corruption is first detected.
  5989   5942   */
................................................................................
  6195   6148   SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
  6196   6149   SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*);
  6197   6150   SQLITE_API char *sqlite3_snprintf(int,char*,const char*,...);
  6198   6151   SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
  6199   6152   SQLITE_PRIVATE int sqlite3FitsIn64Bits(const char *);
  6200   6153   SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
  6201   6154   SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
  6202         -SQLITE_PRIVATE u32 sqlite3ReadUtf8(const unsigned char *);
         6155  +SQLITE_PRIVATE int sqlite3Utf8Read(const u8*, const u8*, const u8**);
  6203   6156   SQLITE_PRIVATE int sqlite3PutVarint(unsigned char *, u64);
  6204   6157   SQLITE_PRIVATE int sqlite3GetVarint(const unsigned char *, u64 *);
  6205   6158   SQLITE_PRIVATE int sqlite3GetVarint32(const unsigned char *, u32 *);
  6206   6159   SQLITE_PRIVATE int sqlite3VarintLen(u64 v);
  6207   6160   SQLITE_PRIVATE void sqlite3IndexAffinityStr(Vdbe *, Index *);
  6208   6161   SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *);
  6209   6162   SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
................................................................................
  6218   6171   SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char *,int,int);
  6219   6172   SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName);
  6220   6173   SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
  6221   6174   SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *);
  6222   6175   SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
  6223   6176   SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
  6224   6177   SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
  6225         -SQLITE_PRIVATE void sqlite3Utf16Substr(sqlite3_context *,int,sqlite3_value **);
  6226   6178   
  6227   6179   SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
  6228   6180   SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
  6229   6181   SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
  6230   6182   SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
  6231   6183   SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(void);
  6232   6184   SQLITE_PRIVATE char *sqlite3Utf16to8(const void*, int);
  6233   6185   SQLITE_PRIVATE int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
  6234   6186   SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
  6235         -extern const unsigned char sqlite3UpperToLower[];
         6187  +/*SQLITE_PRIVATE*/ const unsigned char sqlite3UpperToLower[];
  6236   6188   SQLITE_PRIVATE void sqlite3RootPageMoved(Db*, int, int);
  6237   6189   SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
  6238   6190   SQLITE_PRIVATE void sqlite3AlterFunctions(sqlite3*);
  6239   6191   SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
  6240   6192   SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
  6241   6193   SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
  6242   6194   SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
................................................................................
  6267   6219     void (*)(sqlite3_context*,int,sqlite3_value **),
  6268   6220     void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*));
  6269   6221   SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
  6270   6222   SQLITE_PRIVATE void sqlite3FailedMalloc(void);
  6271   6223   SQLITE_PRIVATE void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *);
  6272   6224   SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
  6273   6225   
         6226  +/*
         6227  +** The interface to the LEMON-generated parser
         6228  +*/
         6229  +SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(size_t));
         6230  +SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
         6231  +SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
         6232  +
  6274   6233   #ifndef SQLITE_OMIT_LOAD_EXTENSION
  6275   6234   SQLITE_PRIVATE   void sqlite3CloseExtensions(sqlite3*);
  6276   6235   SQLITE_PRIVATE   int sqlite3AutoLoadExtensions(sqlite3*);
  6277   6236   #else
  6278   6237   # define sqlite3CloseExtensions(X)
  6279   6238   # define sqlite3AutoLoadExtensions(X)  SQLITE_OK
  6280   6239   #endif
................................................................................
  6328   6287   SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
  6329   6288   SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
  6330   6289   SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *);
  6331   6290   SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(FuncDef*, int nArg, Expr*);
  6332   6291   SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
  6333   6292   SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
  6334   6293   SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*);
  6335         -CollSeq* sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
         6294  +SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
  6336   6295   
  6337   6296   #if SQLITE_MAX_EXPR_DEPTH>0
  6338   6297   SQLITE_PRIVATE   void sqlite3ExprSetHeight(Expr *);
  6339   6298   SQLITE_PRIVATE   int sqlite3SelectExprHeight(Select *);
  6340   6299   #else
  6341   6300     #define sqlite3ExprSetHeight(x)
  6342   6301   #endif
  6343   6302   
  6344         -SQLITE_PRIVATE u32 sqlite3Get2byte(const u8*);
  6345   6303   SQLITE_PRIVATE u32 sqlite3Get4byte(const u8*);
  6346         -SQLITE_PRIVATE void sqlite3Put2byte(u8*, u32);
  6347   6304   SQLITE_PRIVATE void sqlite3Put4byte(u8*, u32);
  6348   6305   
  6349   6306   #ifdef SQLITE_SSE
  6350   6307   #include "sseInt.h"
  6351   6308   #endif
  6352   6309   
  6353   6310   #ifdef SQLITE_DEBUG
................................................................................
  6362   6319   #ifdef SQLITE_ENABLE_IOTRACE
  6363   6320   # define IOTRACE(A)  if( sqlite3_io_trace ){ sqlite3_io_trace A; }
  6364   6321   SQLITE_PRIVATE   void sqlite3VdbeIOTraceSql(Vdbe*);
  6365   6322   #else
  6366   6323   # define IOTRACE(A)
  6367   6324   # define sqlite3VdbeIOTraceSql(X)
  6368   6325   #endif
  6369         -extern void (*sqlite3_io_trace)(const char*,...);
         6326  +SQLITE_EXTERN void (*sqlite3_io_trace)(const char*,...);
  6370   6327   
  6371   6328   #endif
  6372   6329   
  6373   6330   /************** End of sqliteInt.h *******************************************/
  6374   6331   /************** Continuing where we left off in date.c ***********************/
  6375   6332   #include <ctype.h>
  6376   6333   #include <time.h>
................................................................................
  7446   7403   ** This routine really does not accomplish very much since the
  7447   7404   ** virtual function table is a global variable and anybody who
  7448   7405   ** can call this function can just as easily access the variable
  7449   7406   ** for themselves.  Nevertheless, we include this routine for
  7450   7407   ** backwards compatibility with an earlier redefinable I/O
  7451   7408   ** interface design.
  7452   7409   */
  7453         -struct sqlite3OsVtbl *sqlite3_os_switch(void){
         7410  +SQLITE_API struct sqlite3OsVtbl *sqlite3_os_switch(void){
  7454   7411     return &sqlite3Os;
  7455   7412   }
  7456   7413   #endif
  7457   7414   
  7458   7415   /************** End of os.c **************************************************/
  7459   7416   /************** Begin file malloc.c ******************************************/
  7460   7417   /*
................................................................................
  7467   7424   **    May you find forgiveness for yourself and forgive others.
  7468   7425   **    May you share freely, never taking more than you give.
  7469   7426   **
  7470   7427   *************************************************************************
  7471   7428   ** Memory allocation functions used throughout sqlite.
  7472   7429   **
  7473   7430   **
  7474         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         7431  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  7475   7432   */
  7476   7433   
  7477   7434   /*
  7478   7435   ** MALLOC WRAPPER ARCHITECTURE
  7479   7436   **
  7480   7437   ** The sqlite code accesses dynamic memory allocation/deallocation by invoking
  7481   7438   ** the following six APIs (which may be implemented as macros).
................................................................................
  7520   7477   #define MAX(x,y) ((x)>(y)?(x):(y))
  7521   7478   
  7522   7479   #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
  7523   7480   /*
  7524   7481   ** Set the soft heap-size limit for the current thread. Passing a negative
  7525   7482   ** value indicates no limit.
  7526   7483   */
  7527         -void sqlite3_soft_heap_limit(int n){
         7484  +SQLITE_API void sqlite3_soft_heap_limit(int n){
  7528   7485     ThreadData *pTd = sqlite3ThreadData();
  7529   7486     if( pTd ){
  7530   7487       pTd->nSoftHeapLimit = n;
  7531   7488     }
  7532   7489     sqlite3ReleaseThreadData();
  7533   7490   }
  7534   7491   
  7535   7492   /*
  7536   7493   ** Release memory held by SQLite instances created by the current thread.
  7537   7494   */
  7538         -int sqlite3_release_memory(int n){
         7495  +SQLITE_API int sqlite3_release_memory(int n){
  7539   7496     return sqlite3PagerReleaseMemory(n);
  7540   7497   }
  7541   7498   #else
  7542   7499   /* If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, then define a version
  7543   7500   ** of sqlite3_release_memory() to be used by other code in this file.
  7544   7501   ** This is done for no better reason than to reduce the number of 
  7545   7502   ** pre-processor #ifndef statements.
................................................................................
  7589   7546   
  7590   7547   /*
  7591   7548   ** Size reserved for storing the user string. Each time a Malloc() or Realloc()
  7592   7549   ** call succeeds, up to TESTALLOC_USERSIZE bytes of the string pointed to by
  7593   7550   ** sqlite3_malloc_id are stored along with the other test system metadata.
  7594   7551   */
  7595   7552   #define TESTALLOC_USERSIZE 64
  7596         -const char *sqlite3_malloc_id = 0;
         7553  +SQLITE_API const char *sqlite3_malloc_id = 0;
  7597   7554   
  7598   7555   /*
  7599   7556   ** Blocks used by the test layer have the following format:
  7600   7557   **
  7601   7558   **        <sizeof(void *) pNext pointer>
  7602   7559   **        <sizeof(void *) pPrev pointer>
  7603   7560   **        <TESTALLOC_NGUARD 32-bit guard words>
................................................................................
  7641   7598   /*
  7642   7599   ** For keeping track of the number of mallocs and frees.   This
  7643   7600   ** is used to check for memory leaks.  The iMallocFail and iMallocReset
  7644   7601   ** values are used to simulate malloc() failures during testing in 
  7645   7602   ** order to verify that the library correctly handles an out-of-memory
  7646   7603   ** condition.
  7647   7604   */
  7648         -int sqlite3_nMalloc;         /* Number of sqliteMalloc() calls */
  7649         -int sqlite3_nFree;           /* Number of sqliteFree() calls */
  7650         -int sqlite3_memUsed;         /* TODO Total memory obtained from malloc */
  7651         -int sqlite3_memMax;          /* TODO Mem usage high-water mark */
  7652         -int sqlite3_iMallocFail;     /* Fail sqliteMalloc() after this many calls */
  7653         -int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */
         7605  +SQLITE_API int sqlite3_nMalloc;         /* Number of sqliteMalloc() calls */
         7606  +SQLITE_API int sqlite3_nFree;           /* Number of sqliteFree() calls */
         7607  +SQLITE_API int sqlite3_memUsed;         /* TODO Total memory obtained from malloc */
         7608  +SQLITE_API int sqlite3_memMax;          /* TODO Mem usage high-water mark */
         7609  +SQLITE_API int sqlite3_iMallocFail;     /* Fail sqliteMalloc() after this many calls */
         7610  +SQLITE_API int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */
  7654   7611   
  7655         -void *sqlite3_pFirst = 0;         /* Pointer to linked list of allocations */
  7656         -int sqlite3_nMaxAlloc = 0;        /* High water mark of ThreadData.nAlloc */
  7657         -int sqlite3_mallocDisallowed = 0; /* assert() in sqlite3Malloc() if set */
  7658         -int sqlite3_isFail = 0;           /* True if all malloc calls should fail */
  7659         -const char *sqlite3_zFile = 0;    /* Filename to associate debug info with */
  7660         -int sqlite3_iLine = 0;            /* Line number for debug info */
  7661         -int sqlite3_mallocfail_trace = 0; /* Print a msg on malloc fail if true */
         7612  +SQLITE_API void *sqlite3_pFirst = 0;         /* Pointer to linked list of allocations */
         7613  +SQLITE_API int sqlite3_nMaxAlloc = 0;        /* High water mark of ThreadData.nAlloc */
         7614  +SQLITE_API int sqlite3_mallocDisallowed = 0; /* assert() in sqlite3Malloc() if set */
         7615  +SQLITE_API int sqlite3_isFail = 0;           /* True if all malloc calls should fail */
         7616  +SQLITE_API const char *sqlite3_zFile = 0;    /* Filename to associate debug info with */
         7617  +SQLITE_API int sqlite3_iLine = 0;            /* Line number for debug info */
         7618  +SQLITE_API int sqlite3_mallocfail_trace = 0; /* Print a msg on malloc fail if true */
  7662   7619   
  7663   7620   /*
  7664   7621   ** Check for a simulated memory allocation failure.  Return true if
  7665   7622   ** the failure should be simulated.  Return false to proceed as normal.
  7666   7623   */
  7667   7624   SQLITE_PRIVATE int sqlite3TestMallocFail(){
  7668   7625     if( sqlite3_isFail ){
................................................................................
  8242   8199   ** function. However, if a malloc() failure has occured since the previous
  8243   8200   ** invocation SQLITE_NOMEM is returned instead. 
  8244   8201   **
  8245   8202   ** If the first argument, db, is not NULL and a malloc() error has occured,
  8246   8203   ** then the connection error-code (the value returned by sqlite3_errcode())
  8247   8204   ** is set to SQLITE_NOMEM.
  8248   8205   */
  8249         -int sqlite3_mallocHasFailed = 0;
         8206  +SQLITE_PRIVATE int sqlite3MallocHasFailed = 0;
  8250   8207   SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
  8251   8208     if( sqlite3MallocFailed() ){
  8252         -    sqlite3_mallocHasFailed = 0;
         8209  +    sqlite3MallocHasFailed = 0;
  8253   8210       sqlite3OsLeaveMutex();
  8254   8211       sqlite3Error(db, SQLITE_NOMEM, 0);
  8255   8212       rc = SQLITE_NOMEM;
  8256   8213     }
  8257   8214     return rc & (db ? db->errMask : 0xff);
  8258   8215   }
  8259   8216   
  8260   8217   /* 
  8261   8218   ** Set the "malloc has failed" condition to true for this thread.
  8262   8219   */
  8263   8220   SQLITE_PRIVATE void sqlite3FailedMalloc(){
  8264   8221     if( !sqlite3MallocFailed() ){
  8265   8222       sqlite3OsEnterMutex();
  8266         -    assert( sqlite3_mallocHasFailed==0 );
  8267         -    sqlite3_mallocHasFailed = 1;
         8223  +    assert( sqlite3MallocHasFailed==0 );
         8224  +    sqlite3MallocHasFailed = 1;
  8268   8225     }
  8269   8226   }
  8270   8227   
  8271   8228   #ifdef SQLITE_MEMDEBUG
  8272   8229   /*
  8273   8230   ** This function sets a flag in the thread-specific-data structure that will
  8274   8231   ** cause an assert to fail if sqliteMalloc() or sqliteRealloc() is called.
................................................................................
  9190   9147   *************************************************************************
  9191   9148   ** This file contains code to implement a pseudo-random number
  9192   9149   ** generator (PRNG) for SQLite.
  9193   9150   **
  9194   9151   ** Random numbers are used by some of the database backends in order
  9195   9152   ** to generate random integer keys for tables or random filenames.
  9196   9153   **
  9197         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         9154  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  9198   9155   */
  9199   9156   
  9200   9157   
  9201   9158   /*
  9202   9159   ** Get a single 8-bit random value from the RC4 PRNG.  The Mutex
  9203   9160   ** must be held while executing this routine.
  9204   9161   **
................................................................................
  9288   9245   **    May you find forgiveness for yourself and forgive others.
  9289   9246   **    May you share freely, never taking more than you give.
  9290   9247   **
  9291   9248   *************************************************************************
  9292   9249   ** This file contains routines used to translate between UTF-8, 
  9293   9250   ** UTF-16, UTF-16BE, and UTF-16LE.
  9294   9251   **
  9295         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
         9252  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
  9296   9253   **
  9297   9254   ** Notes on UTF-8:
  9298   9255   **
  9299   9256   **   Byte-0    Byte-1    Byte-2    Byte-3    Value
  9300   9257   **  0xxxxxxx                                 00000000 00000000 0xxxxxxx
  9301   9258   **  110yyyyy  10xxxxxx                       00000000 00000yyy yyxxxxxx
  9302   9259   **  1110zzzz  10yyyyyy  10xxxxxx             00000000 zzzzyyyy yyxxxxxx
................................................................................
  9346   9303   
  9347   9304   /*
  9348   9305   ** The makefile scans the vdbe.c source file and creates the following
  9349   9306   ** array of string constants which are the names of all VDBE opcodes.  This
  9350   9307   ** array is defined in a separate source code file named opcode.c which is
  9351   9308   ** automatically generated by the makefile.
  9352   9309   */
  9353         -extern const char *const sqlite3OpcodeNames[];
         9310  +/*SQLITE_PRIVATE*/ const char *const sqlite3OpcodeNames[];
  9354   9311   
  9355   9312   /*
  9356   9313   ** SQL is translated into a sequence of instructions to be
  9357   9314   ** executed by a virtual machine.  Each instruction is an instance
  9358   9315   ** of the following structure.
  9359   9316   */
  9360   9317   typedef struct VdbeOp Op;
................................................................................
  9750   9707   /************** End of vdbeInt.h *********************************************/
  9751   9708   /************** Continuing where we left off in utf.c ************************/
  9752   9709   
  9753   9710   /*
  9754   9711   ** The following constant value is used by the SQLITE_BIGENDIAN and
  9755   9712   ** SQLITE_LITTLEENDIAN macros.
  9756   9713   */
  9757         -const int sqlite3one = 1;
         9714  +SQLITE_PRIVATE const int sqlite3one = 1;
  9758   9715   
  9759   9716   /*
  9760   9717   ** This lookup table is used to help decode the first byte of
  9761   9718   ** a multi-byte UTF8 character.
  9762   9719   */
  9763         -const unsigned char sqlite3UtfTrans1[] = {
         9720  +static const unsigned char sqlite3UtfTrans1[] = {
  9764   9721     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  9765   9722     0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  9766   9723     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  9767   9724     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  9768   9725     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  9769   9726     0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  9770   9727     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  9771   9728     0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
  9772   9729   };
         9730  +
  9773   9731   
  9774   9732   #define WRITE_UTF8(zOut, c) {                          \
  9775   9733     if( c<0x00080 ){                                     \
  9776   9734       *zOut++ = (c&0xFF);                                \
  9777   9735     }                                                    \
  9778   9736     else if( c<0x00800 ){                                \
  9779   9737       *zOut++ = 0xC0 + ((c>>6)&0x1F);                    \
................................................................................
  9832   9790     if( c>=0xD800 && c<0xE000 ){                                       \
  9833   9791       int c2 = ((*zIn++)<<8);                                           \
  9834   9792       c2 += (*zIn++);                                                   \
  9835   9793       c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10);   \
  9836   9794       if( (c & 0xFFFF0000)==0 ) c = 0xFFFD;                             \
  9837   9795     }                                                                   \
  9838   9796   }
         9797  +
         9798  +/*
         9799  +** Translate a single UTF-8 character.  Return the unicode value.
         9800  +**
         9801  +** During translation, assume that the byte that zTerm points
         9802  +** is a 0x00.
         9803  +**
         9804  +** Write a pointer to the next unread byte back into *pzNext.
         9805  +**
         9806  +** Notes On Invalid UTF-8:
         9807  +**
         9808  +**  *  This routine never allows a 7-bit character (0x00 through 0x7f) to
         9809  +**     be encoded as a multi-byte character.  Any multi-byte character that
         9810  +**     attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd.
         9811  +**
         9812  +**  *  This routine never allows a UTF16 surrogate value to be encoded.
         9813  +**     If a multi-byte character attempts to encode a value between
         9814  +**     0xd800 and 0xe000 then it is rendered as 0xfffd.
         9815  +**
         9816  +**  *  Bytes in the range of 0x80 through 0xbf which occur as the first
         9817  +**     byte of a character are interpreted as single-byte characters
         9818  +**     and rendered as themselves even though they are technically
         9819  +**     invalid characters.
         9820  +**
         9821  +**  *  This routine accepts an infinite number of different UTF8 encodings
         9822  +**     for unicode values 0x80 and greater.  It do not change over-length
         9823  +**     encodings to 0xfffd as some systems recommend.
         9824  +*/
         9825  +SQLITE_PRIVATE int sqlite3Utf8Read(
         9826  +  const unsigned char *z,         /* First byte of UTF-8 character */
         9827  +  const unsigned char *zTerm,     /* Pretend this byte is 0x00 */
         9828  +  const unsigned char **pzNext    /* Write first byte past UTF-8 char here */
         9829  +){
         9830  +  int c = *(z++);
         9831  +  if( c>=0xc0 ){
         9832  +    c = sqlite3UtfTrans1[c-0xc0];
         9833  +    while( z!=zTerm && (*z & 0xc0)==0x80 ){
         9834  +      c = (c<<6) + (0x3f & *(z++));
         9835  +    }
         9836  +    if( c<0x80
         9837  +        || (c&0xFFFFF800)==0xD800
         9838  +        || (c&0xFFFFFFFE)==0xFFFE ){  c = 0xFFFD; }
         9839  +  }
         9840  +  *pzNext = z;
         9841  +  return c;
         9842  +}
         9843  +
         9844  +
  9839   9845   
  9840   9846   /*
  9841   9847   ** If the TRANSLATE_TRACE macro is defined, the value of each Mem is
  9842   9848   ** printed on stderr on the way into and out of sqlite3VdbeMemTranslate().
  9843   9849   */ 
  9844   9850   /* #define TRANSLATE_TRACE 1 */
  9845   9851   
................................................................................
  9926   9932       if( !zOut ) return SQLITE_NOMEM;
  9927   9933     }else{
  9928   9934       zOut = zShort;
  9929   9935     }
  9930   9936     z = zOut;
  9931   9937   
  9932   9938     if( pMem->enc==SQLITE_UTF8 ){
  9933         -    unsigned int iExtra = 0xD800;
  9934         -
  9935         -    if( 0==(pMem->flags&MEM_Term) && zTerm>zIn && (zTerm[-1]&0x80) ){
  9936         -      /* This UTF8 string is not nul-terminated, and the last byte is
  9937         -      ** not a character in the ascii range (codpoints 0..127). This
  9938         -      ** means the SQLITE_READ_UTF8() macro might read past the end
  9939         -      ** of the allocated buffer.
  9940         -      **
  9941         -      ** There are four possibilities:
  9942         -      **
  9943         -      **   1. The last byte is the first byte of a non-ASCII character,
  9944         -      **
  9945         -      **   2. The final N bytes of the input string are continuation bytes
  9946         -      **      and immediately preceding them is the first byte of a 
  9947         -      **      non-ASCII character.
  9948         -      **
  9949         -      **   3. The final N bytes of the input string are continuation bytes
  9950         -      **      and immediately preceding them is a byte that encodes a 
  9951         -      **      character in the ASCII range.
  9952         -      **
  9953         -      **   4. The entire string consists of continuation characters.
  9954         -      **
  9955         -      ** Cases (3) and (4) require no special handling. The SQLITE_READ_UTF8()
  9956         -      ** macro will not overread the buffer in these cases.
  9957         -      */
  9958         -      unsigned char *zExtra = &zTerm[-1];
  9959         -      while( zExtra>zIn && (zExtra[0]&0xC0)==0x80 ){
  9960         -        zExtra--;
  9961         -      }
  9962         -
  9963         -      if( (zExtra[0]&0xC0)==0xC0 ){
  9964         -        /* Make a copy of the last character encoding in the input string.
  9965         -        ** Then make sure it is nul-terminated and use SQLITE_READ_UTF8()
  9966         -        ** to decode the codepoint. Store the codepoint in variable iExtra,
  9967         -        ** it will be appended to the output string later.
  9968         -        */
  9969         -        unsigned char *zFree = 0;
  9970         -        unsigned char zBuf[16];
  9971         -        int nExtra = (pMem->n+zIn-zExtra);
  9972         -        zTerm = zExtra;
  9973         -        if( nExtra>15 ){
  9974         -          zExtra = sqliteMallocRaw(nExtra+1);
  9975         -          if( !zExtra ){
  9976         -            return SQLITE_NOMEM;
  9977         -          }
  9978         -          zFree = zExtra;
  9979         -        }else{
  9980         -          zExtra = zBuf;
  9981         -        }
  9982         -        memcpy(zExtra, zTerm, nExtra);
  9983         -        zExtra[nExtra] = '\0';
  9984         -        SQLITE_READ_UTF8(zExtra, iExtra);
  9985         -        sqliteFree(zFree);
  9986         -      }
  9987         -    }
  9988         -
  9989   9939       if( desiredEnc==SQLITE_UTF16LE ){
  9990   9940         /* UTF-8 -> UTF-16 Little-endian */
  9991   9941         while( zIn<zTerm ){
  9992         -        SQLITE_READ_UTF8(zIn, c); 
         9942  +        c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn);
  9993   9943           WRITE_UTF16LE(z, c);
  9994   9944         }
  9995         -      if( iExtra!=0xD800 ){
  9996         -        WRITE_UTF16LE(z, iExtra);
  9997         -      }
  9998   9945       }else{
  9999   9946         assert( desiredEnc==SQLITE_UTF16BE );
 10000   9947         /* UTF-8 -> UTF-16 Big-endian */
 10001   9948         while( zIn<zTerm ){
 10002         -        SQLITE_READ_UTF8(zIn, c); 
         9949  +        c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn);
 10003   9950           WRITE_UTF16BE(z, c);
 10004   9951         }
 10005         -      if( iExtra!=0xD800 ){
 10006         -        WRITE_UTF16BE(z, iExtra);
 10007         -      }
 10008   9952       }
 10009   9953       pMem->n = z - zOut;
 10010   9954       *z++ = 0;
 10011   9955     }else{
 10012   9956       assert( desiredEnc==SQLITE_UTF8 );
 10013   9957       if( pMem->enc==SQLITE_UTF16LE ){
 10014   9958         /* UTF-16 Little-endian -> UTF-8 */
................................................................................
 10184  10128   **
 10185  10129   ** The translation is done in-place (since it is impossible for the
 10186  10130   ** correct UTF-8 encoding to be longer than a malformed encoding).
 10187  10131   */
 10188  10132   SQLITE_PRIVATE int sqlite3Utf8To8(unsigned char *zIn){
 10189  10133     unsigned char *zOut = zIn;
 10190  10134     unsigned char *zStart = zIn;
 10191         -  int c;
        10135  +  unsigned char *zTerm;
        10136  +  u32 c;
 10192  10137   
 10193         -  while(1){
 10194         -    SQLITE_READ_UTF8(zIn, c);
 10195         -    if( c==0 ) break;
        10138  +  while( zIn[0] ){
        10139  +    c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn);
 10196  10140       if( c!=0xfffd ){
 10197  10141         WRITE_UTF8(zOut, c);
 10198  10142       }
 10199  10143     }
 10200  10144     *zOut = 0;
 10201  10145     return zOut - zStart;
 10202  10146   }
................................................................................
 10208  10152   ** It checks that the primitives for serializing and deserializing
 10209  10153   ** characters in each encoding are inverses of each other.
 10210  10154   */
 10211  10155   SQLITE_PRIVATE void sqlite3UtfSelfTest(){
 10212  10156     unsigned int i, t;
 10213  10157     unsigned char zBuf[20];
 10214  10158     unsigned char *z;
        10159  +  unsigned char *zTerm;
 10215  10160     int n;
 10216  10161     unsigned int c;
 10217  10162   
 10218  10163     for(i=0; i<0x00110000; i++){
 10219  10164       z = zBuf;
 10220  10165       WRITE_UTF8(z, i);
 10221  10166       n = z-zBuf;
 10222  10167       z[0] = 0;
        10168  +    zTerm = z;
 10223  10169       z = zBuf;
 10224         -    SQLITE_READ_UTF8(z, c);
        10170  +    c = sqlite3Utf8Read(z, zTerm, (const u8**)&z);
 10225  10171       t = i;
 10226  10172       if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
 10227  10173       if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD;
 10228  10174       assert( c==t );
 10229  10175       assert( (z-zBuf)==n );
 10230  10176     }
 10231  10177     for(i=0; i<0x00110000; i++){
................................................................................
 10268  10214   **
 10269  10215   *************************************************************************
 10270  10216   ** Utility functions used throughout sqlite.
 10271  10217   **
 10272  10218   ** This file contains functions for allocating memory, comparing
 10273  10219   ** strings, and stuff like that.
 10274  10220   **
 10275         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        10221  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 10276  10222   */
 10277  10223   
 10278  10224   
 10279  10225   /*
 10280  10226   ** Set the most recent error code and error string for the sqlite
 10281  10227   ** handle "db". The error code is set to "err_code".
 10282  10228   **
................................................................................
 10387  10333       }
 10388  10334     }
 10389  10335   }
 10390  10336   
 10391  10337   /* An array to map all upper-case characters into their corresponding
 10392  10338   ** lower-case character. 
 10393  10339   */
 10394         -const unsigned char sqlite3UpperToLower[] = {
        10340  +SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[] = {
 10395  10341   #ifdef SQLITE_ASCII
 10396  10342         0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
 10397  10343        18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
 10398  10344        36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
 10399  10345        54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103,
 10400  10346       104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,
 10401  10347       122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,
................................................................................
 10997  10943   **    May you find forgiveness for yourself and forgive others.
 10998  10944   **    May you share freely, never taking more than you give.
 10999  10945   **
 11000  10946   *************************************************************************
 11001  10947   ** This is the implementation of generic hash-tables
 11002  10948   ** used in SQLite.
 11003  10949   **
 11004         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        10950  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 11005  10951   */
 11006  10952   
 11007  10953   /* Turn bulk memory into a hash table object by initializing the
 11008  10954   ** fields of the Hash structure.
 11009  10955   **
 11010  10956   ** "pNew" is a pointer to the hash table that is to be initialized.
 11011  10957   ** keyClass is one of the constants SQLITE_HASH_INT, SQLITE_HASH_POINTER,
................................................................................
 11384  11330   }
 11385  11331   
 11386  11332   /************** End of hash.c ************************************************/
 11387  11333   /************** Begin file opcodes.c *****************************************/
 11388  11334   /* Automatically generated.  Do not edit */
 11389  11335   /* See the mkopcodec.awk script for details. */
 11390  11336   #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
 11391         -const char *const sqlite3OpcodeNames[] = { "?",
        11337  +SQLITE_PRIVATE const char *const sqlite3OpcodeNames[] = { "?",
 11392  11338    /*   1 */ "MemLoad",
 11393  11339    /*   2 */ "VNext",
 11394  11340    /*   3 */ "Column",
 11395  11341    /*   4 */ "SetCookie",
 11396  11342    /*   5 */ "IfMemPos",
 11397  11343    /*   6 */ "Sequence",
 11398  11344    /*   7 */ "MoveGt",
................................................................................
 11597  11543   
 11598  11544   
 11599  11545   /*
 11600  11546    * When testing, this global variable stores the location of the
 11601  11547    * pending-byte in the database file.
 11602  11548    */
 11603  11549   #ifdef SQLITE_TEST
 11604         -unsigned int sqlite3_pending_byte = 0x40000000;
        11550  +SQLITE_API unsigned int sqlite3_pending_byte = 0x40000000;
 11605  11551   #endif
 11606  11552   
 11607         -int sqlite3_os_trace = 0;
 11608  11553   #ifdef SQLITE_DEBUG
        11554  +SQLITE_API int sqlite3_os_trace = 0;
 11609  11555   #define OSTRACE1(X)         if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
 11610  11556   #define OSTRACE2(X,Y)       if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
 11611  11557   #define OSTRACE3(X,Y,Z)     if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
 11612  11558   #define OSTRACE4(X,Y,Z,A)   if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A)
 11613  11559   #define OSTRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B)
 11614  11560   #define OSTRACE6(X,Y,Z,A,B,C) \
 11615  11561       if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C)
................................................................................
 11650  11596   
 11651  11597   /*
 11652  11598   ** If we compile with the SQLITE_TEST macro set, then the following block
 11653  11599   ** of code will give us the ability to simulate a disk I/O error.  This
 11654  11600   ** is used for testing the I/O recovery logic.
 11655  11601   */
 11656  11602   #ifdef SQLITE_TEST
 11657         -int sqlite3_io_error_hit = 0;
 11658         -int sqlite3_io_error_pending = 0;
 11659         -int sqlite3_io_error_persist = 0;
 11660         -int sqlite3_diskfull_pending = 0;
 11661         -int sqlite3_diskfull = 0;
        11603  +SQLITE_API int sqlite3_io_error_hit = 0;
        11604  +SQLITE_API int sqlite3_io_error_pending = 0;
        11605  +SQLITE_API int sqlite3_io_error_persist = 0;
        11606  +SQLITE_API int sqlite3_diskfull_pending = 0;
        11607  +SQLITE_API int sqlite3_diskfull = 0;
 11662  11608   #define SimulateIOError(CODE)  \
 11663  11609     if( sqlite3_io_error_pending || sqlite3_io_error_hit ) \
 11664  11610        if( sqlite3_io_error_pending-- == 1 \
 11665  11611            || (sqlite3_io_error_persist && sqlite3_io_error_hit) ) \
 11666  11612                   { local_ioerr(); CODE; }
 11667  11613   static void local_ioerr(){
 11668  11614     IOTRACE(("IOERR\n"));
................................................................................
 11684  11630   #define SimulateDiskfullError(A)
 11685  11631   #endif
 11686  11632   
 11687  11633   /*
 11688  11634   ** When testing, keep a count of the number of open files.
 11689  11635   */
 11690  11636   #ifdef SQLITE_TEST
 11691         -int sqlite3_open_file_count = 0;
        11637  +SQLITE_API int sqlite3_open_file_count = 0;
 11692  11638   #define OpenCounter(X)  sqlite3_open_file_count+=(X)
 11693  11639   #else
 11694  11640   #define OpenCounter(X)
 11695  11641   #endif
 11696  11642   
 11697  11643   /*
 11698  11644   ** sqlite3GenericMalloc
................................................................................
 12650  12596   }
 12651  12597   
 12652  12598   /*
 12653  12599   ** The following variable, if set to a non-zero value, becomes the result
 12654  12600   ** returned from sqlite3OsCurrentTime().  This is used for testing.
 12655  12601   */
 12656  12602   #ifdef SQLITE_TEST
 12657         -int sqlite3_current_time = 0;
        12603  +SQLITE_API int sqlite3_current_time = 0;
 12658  12604   #endif
 12659  12605   
 12660  12606   /*
 12661  12607   ** Find the current time (in Universal Coordinated Time).  Write the
 12662  12608   ** current time and date as a Julian Day number into *prNow and
 12663  12609   ** return 0.  Return 1 if the time and date cannot be found.
 12664  12610   */
................................................................................
 12698  12644   
 12699  12645   /*
 12700  12646   ** Remember the number of thread-specific-data blocks allocated.
 12701  12647   ** Use this to verify that we are not leaking thread-specific-data.
 12702  12648   ** Ticket #1601
 12703  12649   */
 12704  12650   #ifdef SQLITE_TEST
 12705         -int sqlite3_tsd_count = 0;
        12651  +SQLITE_API int sqlite3_tsd_count = 0;
 12706  12652   # define TSD_COUNTER_INCR InterlockedIncrement( &sqlite3_tsd_count )
 12707  12653   # define TSD_COUNTER_DECR InterlockedDecrement( &sqlite3_tsd_count )
 12708  12654   #else
 12709  12655   # define TSD_COUNTER_INCR  /* no-op */
 12710  12656   # define TSD_COUNTER_DECR  /* no-op */
 12711  12657   #endif
 12712  12658   
................................................................................
 12916  12862   
 12917  12863   
 12918  12864   /*
 12919  12865    * When testing, this global variable stores the location of the
 12920  12866    * pending-byte in the database file.
 12921  12867    */
 12922  12868   #ifdef SQLITE_TEST
 12923         -unsigned int sqlite3_pending_byte = 0x40000000;
        12869  +SQLITE_API unsigned int sqlite3_pending_byte = 0x40000000;
 12924  12870   #endif
 12925  12871   
 12926         -int sqlite3_os_trace = 0;
 12927  12872   #ifdef SQLITE_DEBUG
        12873  +SQLITE_API int sqlite3_os_trace = 0;
 12928  12874   #define OSTRACE1(X)         if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
 12929  12875   #define OSTRACE2(X,Y)       if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
 12930  12876   #define OSTRACE3(X,Y,Z)     if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
 12931  12877   #define OSTRACE4(X,Y,Z,A)   if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A)
 12932  12878   #define OSTRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B)
 12933  12879   #define OSTRACE6(X,Y,Z,A,B,C) \
 12934  12880       if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C)
................................................................................
 12969  12915   
 12970  12916   /*
 12971  12917   ** If we compile with the SQLITE_TEST macro set, then the following block
 12972  12918   ** of code will give us the ability to simulate a disk I/O error.  This
 12973  12919   ** is used for testing the I/O recovery logic.
 12974  12920   */
 12975  12921   #ifdef SQLITE_TEST
 12976         -int sqlite3_io_error_hit = 0;
 12977         -int sqlite3_io_error_pending = 0;
 12978         -int sqlite3_io_error_persist = 0;
 12979         -int sqlite3_diskfull_pending = 0;
 12980         -int sqlite3_diskfull = 0;
        12922  +SQLITE_API int sqlite3_io_error_hit = 0;
        12923  +SQLITE_API int sqlite3_io_error_pending = 0;
        12924  +SQLITE_API int sqlite3_io_error_persist = 0;
        12925  +SQLITE_API int sqlite3_diskfull_pending = 0;
        12926  +SQLITE_API int sqlite3_diskfull = 0;
 12981  12927   #define SimulateIOError(CODE)  \
 12982  12928     if( sqlite3_io_error_pending || sqlite3_io_error_hit ) \
 12983  12929        if( sqlite3_io_error_pending-- == 1 \
 12984  12930            || (sqlite3_io_error_persist && sqlite3_io_error_hit) ) \
 12985  12931                   { local_ioerr(); CODE; }
 12986  12932   static void local_ioerr(){
 12987  12933     IOTRACE(("IOERR\n"));
................................................................................
 13003  12949   #define SimulateDiskfullError(A)
 13004  12950   #endif
 13005  12951   
 13006  12952   /*
 13007  12953   ** When testing, keep a count of the number of open files.
 13008  12954   */
 13009  12955   #ifdef SQLITE_TEST
 13010         -int sqlite3_open_file_count = 0;
        12956  +SQLITE_API int sqlite3_open_file_count = 0;
 13011  12957   #define OpenCounter(X)  sqlite3_open_file_count+=(X)
 13012  12958   #else
 13013  12959   #define OpenCounter(X)
 13014  12960   #endif
 13015  12961   
 13016  12962   /*
 13017  12963   ** sqlite3GenericMalloc
................................................................................
 13338  13284   **   can be used on file systems that do not offer any reliable file locking
 13339  13285   ** NO locking means that no locking will be attempted, this is only used for
 13340  13286   **   read-only file systems currently
 13341  13287   ** UNSUPPORTED means that no locking will be attempted, this is only used for
 13342  13288   **   file systems that are known to be unsupported
 13343  13289   */
 13344  13290   typedef enum {
 13345         -	posixLockingStyle = 0,       /* standard posix-advisory locks */
 13346         -	afpLockingStyle,             /* use afp locks */
 13347         -	flockLockingStyle,           /* use flock() */
 13348         -	dotlockLockingStyle,         /* use <file>.lock files */
 13349         -	noLockingStyle,              /* useful for read-only file system */
 13350         -	unsupportedLockingStyle      /* indicates unsupported file system */
        13291  +        posixLockingStyle = 0,       /* standard posix-advisory locks */
        13292  +        afpLockingStyle,             /* use afp locks */
        13293  +        flockLockingStyle,           /* use flock() */
        13294  +        dotlockLockingStyle,         /* use <file>.lock files */
        13295  +        noLockingStyle,              /* useful for read-only file system */
        13296  +        unsupportedLockingStyle      /* indicates unsupported file system */
 13351  13297   } sqlite3LockingStyle;
 13352  13298   #endif /* SQLITE_ENABLE_LOCKING_STYLE */
 13353  13299   
 13354  13300   #ifdef SQLITE_UNIX_THREADS
 13355  13301   /*
 13356  13302   ** This variable records whether or not threads can override each others
 13357  13303   ** locks.
................................................................................
 13563  13509       return sqlite3TestLockingStyle(filePath, fd);
 13564  13510     
 13565  13511     if (fsInfo.f_flags & MNT_RDONLY)
 13566  13512       return noLockingStyle;
 13567  13513     
 13568  13514     if( (!strcmp(fsInfo.f_fstypename, "hfs")) ||
 13569  13515       (!strcmp(fsInfo.f_fstypename, "ufs")) )
 13570         -		return posixLockingStyle;
        13516  +                return posixLockingStyle;
 13571  13517     
 13572  13518     if(!strcmp(fsInfo.f_fstypename, "afpfs"))
 13573  13519       return afpLockingStyle;
 13574  13520     
 13575  13521     if(!strcmp(fsInfo.f_fstypename, "nfs")) 
 13576  13522       return sqlite3TestLockingStyle(filePath, fd);
 13577  13523     
................................................................................
 14070  14016   }
 14071  14017   
 14072  14018   #ifdef SQLITE_TEST
 14073  14019   /*
 14074  14020   ** Count the number of fullsyncs and normal syncs.  This is used to test
 14075  14021   ** that syncs and fullsyncs are occuring at the right times.
 14076  14022   */
 14077         -int sqlite3_sync_count = 0;
 14078         -int sqlite3_fullsync_count = 0;
        14023  +SQLITE_API int sqlite3_sync_count = 0;
        14024  +SQLITE_API int sqlite3_fullsync_count = 0;
 14079  14025   #endif
 14080  14026   
 14081  14027   /*
 14082  14028   ** Use the fdatasync() API only if the HAVE_FDATASYNC macro is defined.
 14083  14029   ** Otherwise use fsync() in its place.
 14084  14030   */
 14085  14031   #ifndef HAVE_FDATASYNC
................................................................................
 14676  14622     unsigned long long length;        /* nbr of bytes to lock */
 14677  14623     unsigned long long retRangeStart; /* nbr of 1st byte locked if successful */
 14678  14624     unsigned char unLockFlag;         /* 1 = unlock, 0 = lock */
 14679  14625     unsigned char startEndFlag;       /* 1=rel to end of fork, 0=rel to start */
 14680  14626     int fd;                           /* file desc to assoc this lock with */
 14681  14627   };
 14682  14628   
 14683         -#define afpfsByteRangeLock2FSCTL	_IOWR('z', 23, struct ByteRangeLockPB2)
        14629  +#define afpfsByteRangeLock2FSCTL        _IOWR('z', 23, struct ByteRangeLockPB2)
 14684  14630   
 14685  14631   /* return 0 on success, 1 on failure.  To match the behavior of the 
 14686  14632     normal posix file locking (used in unixLock for example), we should 
 14687  14633     provide 'richer' return codes - specifically to differentiate between
 14688  14634     'file busy' and 'file system error' results */
 14689  14635   static int _AFPFSSetLock(const char *path, int fd, unsigned long long offset, 
 14690  14636                            unsigned long long length, int setLockFlag)
 14691  14637   {
 14692         -  struct ByteRangeLockPB2	pb;
        14638  +  struct ByteRangeLockPB2       pb;
 14693  14639     int                     err;
 14694  14640     
 14695  14641     pb.unLockFlag = setLockFlag ? 0 : 1;
 14696  14642     pb.startEndFlag = 0;
 14697  14643     pb.offset = offset;
 14698  14644     pb.length = length; 
 14699  14645     pb.fd = fd;
................................................................................
 15765  15711   
 15766  15712   /*
 15767  15713   ** Remember the number of thread-specific-data blocks allocated.
 15768  15714   ** Use this to verify that we are not leaking thread-specific-data.
 15769  15715   ** Ticket #1601
 15770  15716   */
 15771  15717   #ifdef SQLITE_TEST
 15772         -int sqlite3_tsd_count = 0;
        15718  +SQLITE_API int sqlite3_tsd_count = 0;
 15773  15719   # ifdef SQLITE_UNIX_THREADS
 15774  15720       static pthread_mutex_t tsd_counter_mutex = PTHREAD_MUTEX_INITIALIZER;
 15775  15721   #   define TSD_COUNTER(N) \
 15776  15722                pthread_mutex_lock(&tsd_counter_mutex); \
 15777  15723                sqlite3_tsd_count += N; \
 15778  15724                pthread_mutex_unlock(&tsd_counter_mutex);
 15779  15725   # else
................................................................................
 15868  15814   }
 15869  15815   
 15870  15816   /*
 15871  15817   ** The following variable, if set to a non-zero value, becomes the result
 15872  15818   ** returned from sqlite3OsCurrentTime().  This is used for testing.
 15873  15819   */
 15874  15820   #ifdef SQLITE_TEST
 15875         -int sqlite3_current_time = 0;
        15821  +SQLITE_API int sqlite3_current_time = 0;
 15876  15822   #endif
 15877  15823   
 15878  15824   /*
 15879  15825   ** Find the current time (in Universal Coordinated Time).  Write the
 15880  15826   ** current time and date as a Julian Day number into *prNow and
 15881  15827   ** return 0.  Return 1 if the time and date cannot be found.
 15882  15828   */
................................................................................
 15967  15913   
 15968  15914   
 15969  15915   /*
 15970  15916    * When testing, this global variable stores the location of the
 15971  15917    * pending-byte in the database file.
 15972  15918    */
 15973  15919   #ifdef SQLITE_TEST
 15974         -unsigned int sqlite3_pending_byte = 0x40000000;
        15920  +SQLITE_API unsigned int sqlite3_pending_byte = 0x40000000;
 15975  15921   #endif
 15976  15922   
 15977         -int sqlite3_os_trace = 0;
 15978  15923   #ifdef SQLITE_DEBUG
        15924  +SQLITE_API int sqlite3_os_trace = 0;
 15979  15925   #define OSTRACE1(X)         if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
 15980  15926   #define OSTRACE2(X,Y)       if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
 15981  15927   #define OSTRACE3(X,Y,Z)     if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
 15982  15928   #define OSTRACE4(X,Y,Z,A)   if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A)
 15983  15929   #define OSTRACE5(X,Y,Z,A,B) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z,A,B)
 15984  15930   #define OSTRACE6(X,Y,Z,A,B,C) \
 15985  15931       if(sqlite3_os_trace) sqlite3DebugPrintf(X,Y,Z,A,B,C)
................................................................................
 16020  15966   
 16021  15967   /*
 16022  15968   ** If we compile with the SQLITE_TEST macro set, then the following block
 16023  15969   ** of code will give us the ability to simulate a disk I/O error.  This
 16024  15970   ** is used for testing the I/O recovery logic.
 16025  15971   */
 16026  15972   #ifdef SQLITE_TEST
 16027         -int sqlite3_io_error_hit = 0;
 16028         -int sqlite3_io_error_pending = 0;
 16029         -int sqlite3_io_error_persist = 0;
 16030         -int sqlite3_diskfull_pending = 0;
 16031         -int sqlite3_diskfull = 0;
        15973  +SQLITE_API int sqlite3_io_error_hit = 0;
        15974  +SQLITE_API int sqlite3_io_error_pending = 0;
        15975  +SQLITE_API int sqlite3_io_error_persist = 0;
        15976  +SQLITE_API int sqlite3_diskfull_pending = 0;
        15977  +SQLITE_API int sqlite3_diskfull = 0;
 16032  15978   #define SimulateIOError(CODE)  \
 16033  15979     if( sqlite3_io_error_pending || sqlite3_io_error_hit ) \
 16034  15980        if( sqlite3_io_error_pending-- == 1 \
 16035  15981            || (sqlite3_io_error_persist && sqlite3_io_error_hit) ) \
 16036  15982                   { local_ioerr(); CODE; }
 16037  15983   static void local_ioerr(){
 16038  15984     IOTRACE(("IOERR\n"));
................................................................................
 16054  16000   #define SimulateDiskfullError(A)
 16055  16001   #endif
 16056  16002   
 16057  16003   /*
 16058  16004   ** When testing, keep a count of the number of open files.
 16059  16005   */
 16060  16006   #ifdef SQLITE_TEST
 16061         -int sqlite3_open_file_count = 0;
        16007  +SQLITE_API int sqlite3_open_file_count = 0;
 16062  16008   #define OpenCounter(X)  sqlite3_open_file_count+=(X)
 16063  16009   #else
 16064  16010   #define OpenCounter(X)
 16065  16011   #endif
 16066  16012   
 16067  16013   /*
 16068  16014   ** sqlite3GenericMalloc
................................................................................
 16197  16143   ** 0:   Operating system unknown.
 16198  16144   ** 1:   Operating system is Win95.
 16199  16145   ** 2:   Operating system is WinNT.
 16200  16146   **
 16201  16147   ** In order to facilitate testing on a WinNT system, the test fixture
 16202  16148   ** can manually set this value to 1 to emulate Win98 behavior.
 16203  16149   */
 16204         -int sqlite3_os_type = 0;
        16150  +SQLITE_API int sqlite3_os_type = 0;
 16205  16151   
 16206  16152   /*
 16207  16153   ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
 16208  16154   ** or WinCE.  Return false (zero) for Win95, Win98, or WinME.
 16209  16155   **
 16210  16156   ** Here is an interesting observation:  Win95, Win98, and WinME lack
 16211  16157   ** the LockFileEx() API.  But we can still statically link against that
................................................................................
 16507  16453         pFile->shared->bExclusive = FALSE;
 16508  16454       }
 16509  16455   
 16510  16456       /* De-reference and close our copy of the shared memory handle */
 16511  16457       UnmapViewOfFile(pFile->shared);
 16512  16458       CloseHandle(pFile->hShared);
 16513  16459   
 16514         -    if( pFile->zDeleteOnClose ){
 16515         -      DeleteFileW(pFile->zDeleteOnClose);
 16516         -      sqliteFree(pFile->zDeleteOnClose);
 16517         -      pFile->zDeleteOnClose = 0;
 16518         -    }
 16519         -
 16520  16460       /* Done with the mutex */
 16521  16461       winceMutexRelease(pFile->hMutex);    
 16522  16462       CloseHandle(pFile->hMutex);
 16523  16463       pFile->hMutex = NULL;
 16524  16464     }
 16525  16465   }
 16526  16466   
................................................................................
 17081  17021       int rc, cnt = 0;
 17082  17022       OSTRACE2("CLOSE %d\n", pFile->h);
 17083  17023       do{
 17084  17024         rc = CloseHandle(pFile->h);
 17085  17025       }while( rc==0 && cnt++ < MX_CLOSE_ATTEMPT && (Sleep(100), 1) );
 17086  17026   #if OS_WINCE
 17087  17027       winceDestroyLock(pFile);
        17028  +    if( pFile->zDeleteOnClose ){
        17029  +      DeleteFileW(pFile->zDeleteOnClose);
        17030  +      sqliteFree(pFile->zDeleteOnClose);
        17031  +    }
 17088  17032   #endif
 17089  17033       OpenCounter(-1);
 17090  17034       sqliteFree(pFile);
 17091  17035       *pId = 0;
 17092  17036     }
 17093  17037     return rc ? SQLITE_OK : SQLITE_IOERR;
 17094  17038   }
................................................................................
 17756  17700   
 17757  17701   
 17758  17702   /*
 17759  17703   ** The following variable, if set to a non-zero value, becomes the result
 17760  17704   ** returned from sqlite3OsCurrentTime().  This is used for testing.
 17761  17705   */
 17762  17706   #ifdef SQLITE_TEST
 17763         -int sqlite3_current_time = 0;
        17707  +SQLITE_API int sqlite3_current_time = 0;
 17764  17708   #endif
 17765  17709   
 17766  17710   /*
 17767  17711   ** Find the current time (in Universal Coordinated Time).  Write the
 17768  17712   ** current time and date as a Julian Day number into *prNow and
 17769  17713   ** return 0.  Return 1 if the time and date cannot be found.
 17770  17714   */
................................................................................
 17793  17737   
 17794  17738   /*
 17795  17739   ** Remember the number of thread-specific-data blocks allocated.
 17796  17740   ** Use this to verify that we are not leaking thread-specific-data.
 17797  17741   ** Ticket #1601
 17798  17742   */
 17799  17743   #ifdef SQLITE_TEST
 17800         -int sqlite3_tsd_count = 0;
        17744  +SQLITE_API int sqlite3_tsd_count = 0;
 17801  17745   # define TSD_COUNTER_INCR InterlockedIncrement(&sqlite3_tsd_count)
 17802  17746   # define TSD_COUNTER_DECR InterlockedDecrement(&sqlite3_tsd_count)
 17803  17747   #else
 17804  17748   # define TSD_COUNTER_INCR  /* no-op */
 17805  17749   # define TSD_COUNTER_DECR  /* no-op */
 17806  17750   #endif
 17807  17751   
................................................................................
 17878  17822   ** The pager is used to access a database disk file.  It implements
 17879  17823   ** atomic commit and rollback through the use of a journal file that
 17880  17824   ** is separate from the database file.  The pager also implements file
 17881  17825   ** locking to prevent two processes from writing the same database
 17882  17826   ** file simultaneously, or one process from reading the database while
 17883  17827   ** another is writing.
 17884  17828   **
 17885         -** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        17829  +** @(#) $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 17886  17830   */
 17887  17831   #ifndef SQLITE_OMIT_DISKIO
 17888  17832   
 17889  17833   /*
 17890  17834   ** Macros for troubleshooting.  Normally turned off
 17891  17835   */
 17892  17836   #if 0
................................................................................
 18230  18174   
 18231  18175   /*
 18232  18176   ** The following global variables hold counters used for
 18233  18177   ** testing purposes only.  These variables do not exist in
 18234  18178   ** a non-testing build.  These variables are not thread-safe.
 18235  18179   */
 18236  18180   #ifdef SQLITE_TEST
 18237         -int sqlite3_pager_readdb_count = 0;    /* Number of full pages read from DB */
 18238         -int sqlite3_pager_writedb_count = 0;   /* Number of full pages written to DB */
 18239         -int sqlite3_pager_writej_count = 0;    /* Number of pages written to journal */
 18240         -int sqlite3_pager_pgfree_count = 0;    /* Number of cache pages freed */
        18181  +SQLITE_API int sqlite3_pager_readdb_count = 0;    /* Number of full pages read from DB */
        18182  +SQLITE_API int sqlite3_pager_writedb_count = 0;   /* Number of full pages written to DB */
        18183  +SQLITE_API int sqlite3_pager_writej_count = 0;    /* Number of pages written to journal */
        18184  +SQLITE_API int sqlite3_pager_pgfree_count = 0;    /* Number of cache pages freed */
 18241  18185   # define PAGER_INCR(v)  v++
 18242  18186   #else
 18243  18187   # define PAGER_INCR(v)
 18244  18188   #endif
 18245  18189   
 18246  18190   
 18247  18191   
................................................................................
 18417  18361   **
 18418  18362   ** If the second argument is SQLITE_IOERR, SQLITE_CORRUPT, or SQLITE_FULL
 18419  18363   ** the error becomes persistent. All subsequent API calls on this Pager
 18420  18364   ** will immediately return the same error code.
 18421  18365   */
 18422  18366   static int pager_error(Pager *pPager, int rc){
 18423  18367     int rc2 = rc & 0xff;
 18424         -  assert( pPager->errCode==SQLITE_FULL || pPager->errCode==SQLITE_OK );
        18368  +  assert(
        18369  +       pPager->errCode==SQLITE_FULL ||
        18370  +       pPager->errCode==SQLITE_OK ||
        18371  +       (pPager->errCode & 0xff)==SQLITE_IOERR
        18372  +  );
 18425  18373     if(
 18426  18374       rc2==SQLITE_FULL ||
 18427  18375       rc2==SQLITE_IOERR ||
 18428  18376       rc2==SQLITE_CORRUPT
 18429  18377     ){
 18430  18378       pPager->errCode = rc;
 18431  18379     }
................................................................................
 19306  19254       */
 19307  19255       if( nRec==0xffffffff ){
 19308  19256         assert( pPager->journalOff==JOURNAL_HDR_SZ(pPager) );
 19309  19257         nRec = (szJ - JOURNAL_HDR_SZ(pPager))/JOURNAL_PG_SZ(pPager);
 19310  19258       }
 19311  19259   
 19312  19260       /* If nRec is 0 and this rollback is of a transaction created by this
 19313         -    ** process. In this case the rest of the journal file consists of
 19314         -    ** journalled copies of pages that need to be read back into the cache.
        19261  +    ** process and if this is the final header in the journal, then it means
        19262  +    ** that this part of the journal was being filled but has not yet been
        19263  +    ** synced to disk.  Compute the number of pages based on the remaining
        19264  +    ** size of the file.
        19265  +    **
        19266  +    ** The third term of the test was added to fix ticket #2565.
 19315  19267       */
 19316         -    if( nRec==0 && !isHot ){
        19268  +    if( nRec==0 && !isHot &&
        19269  +        pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){
 19317  19270         nRec = (szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager);
 19318  19271       }
 19319  19272   
 19320  19273       /* If this is the first header read from the journal, truncate the
 19321  19274       ** database file back to it's original size.
 19322  19275       */
 19323  19276       if( pPager->journalOff==JOURNAL_HDR_SZ(pPager) ){
................................................................................
 19527  19480   
 19528  19481   /*
 19529  19482   ** The following global variable is incremented whenever the library
 19530  19483   ** attempts to open a temporary file.  This information is used for
 19531  19484   ** testing and analysis only.  
 19532  19485   */
 19533  19486   #ifdef SQLITE_TEST
 19534         -int sqlite3_opentemp_count = 0;
        19487  +SQLITE_API int sqlite3_opentemp_count = 0;
 19535  19488   #endif
 19536  19489   
 19537  19490   /*
 19538  19491   ** Open a temporary file. 
 19539  19492   **
 19540  19493   ** Write the file descriptor into *fd.  Return SQLITE_OK on success or some
 19541  19494   ** other error code if we fail.
................................................................................
 19787  19740   ** I/O error mechanism.  These routines are used to avoid simulated
 19788  19741   ** errors in places where we do not care about errors.
 19789  19742   **
 19790  19743   ** Unless -DSQLITE_TEST=1 is used, these routines are all no-ops
 19791  19744   ** and generate no code.
 19792  19745   */
 19793  19746   #ifdef SQLITE_TEST
 19794         -extern int sqlite3_io_error_pending;
 19795         -extern int sqlite3_io_error_hit;
        19747  +SQLITE_API extern int sqlite3_io_error_pending;
        19748  +SQLITE_API extern int sqlite3_io_error_hit;
 19796  19749   static int saved_cnt;
 19797  19750   void disable_simulated_io_errors(void){
 19798  19751     saved_cnt = sqlite3_io_error_pending;
 19799  19752     sqlite3_io_error_pending = -1;
 19800  19753   }
 19801  19754   void enable_simulated_io_errors(void){
 19802  19755     sqlite3_io_error_pending = saved_cnt;
................................................................................
 20610  20563           if( pPg==pPager->pAll ){
 20611  20564              pPager->pAll = pPg->pNextAll;
 20612  20565           }else{
 20613  20566             for( pTmp=pPager->pAll; pTmp->pNextAll!=pPg; pTmp=pTmp->pNextAll ){}
 20614  20567             pTmp->pNextAll = pPg->pNextAll;
 20615  20568           }
 20616  20569           nReleased += sqliteAllocSize(pPg);
 20617         -        IOTRACE(("PGFREE %p %d\n", pPager, pPg->pgno));
        20570  +        IOTRACE(("PGFREE %p %d *\n", pPager, pPg->pgno));
 20618  20571           PAGER_INCR(sqlite3_pager_pgfree_count);
 20619  20572           sqliteFree(pPg);
 20620  20573         }
 20621  20574   
 20622  20575         if( rc!=SQLITE_OK ){
 20623  20576           /* An error occured whilst writing to the database file or 
 20624  20577           ** journal in pager_recycle(). The error is not returned to the 
 20625  20578           ** caller of this function. Instead, set the Pager.errCode variable.
 20626  20579           ** The error will be returned to the user (or users, in the case 
 20627  20580           ** of a shared pager cache) of the pager for which the error occured.
 20628  20581           */
 20629         -        assert( (rc&0xff)==SQLITE_IOERR || rc==SQLITE_FULL );
        20582  +        assert(
        20583  +            (rc&0xff)==SQLITE_IOERR ||
        20584  +            rc==SQLITE_FULL ||
        20585  +            rc==SQLITE_BUSY
        20586  +        );
 20630  20587           assert( pPager->state>=PAGER_RESERVED );
 20631  20588           pager_error(pPager, rc);
 20632  20589         }
 20633  20590       }
 20634  20591     }
 20635  20592   
 20636  20593     return nReleased;
................................................................................
 20711  20668           ** we are unable to open the journal file. 
 20712  20669           **
 20713  20670           ** The journal file does not need to be locked itself.  The
 20714  20671           ** journal file is never open unless the main database file holds
 20715  20672           ** a write lock, so there is never any chance of two or more
 20716  20673           ** processes opening the journal at the same time.
 20717  20674           **
 20718         -	** Open the journal for read/write access. This is because in 
 20719         -	** exclusive-access mode the file descriptor will be kept open and
        20675  +        ** Open the journal for read/write access. This is because in 
        20676  +        ** exclusive-access mode the file descriptor will be kept open and
 20720  20677           ** possibly used for a transaction later on. On some systems, the
 20721  20678           ** OsTruncate() call used in exclusive-access mode also requires
 20722  20679           ** a read/write file handle.
 20723  20680           */
 20724  20681           rc = SQLITE_BUSY;
 20725  20682           if( sqlite3OsFileExists(pPager->zJournal) ){
 20726  20683             int ro;
................................................................................
 21434  21391                      pPager->journalOff, szPg));
 21435  21392             PAGER_INCR(sqlite3_pager_writej_count);
 21436  21393             pPager->journalOff += szPg;
 21437  21394             PAGERTRACE5("JOURNAL %d page %d needSync=%d hash(%08x)\n",
 21438  21395                  PAGERID(pPager), pPg->pgno, pPg->needSync, pager_pagehash(pPg));
 21439  21396             *(u32*)pEnd = saved;
 21440  21397   
 21441         -	  /* An error has occured writing to the journal file. The 
        21398  +          /* An error has occured writing to the journal file. The 
 21442  21399             ** transaction will be rolled back by the layer above.
 21443  21400             */
 21444  21401             if( rc!=SQLITE_OK ){
 21445  21402               return rc;
 21446  21403             }
 21447  21404   
 21448  21405             pPager->nRec++;
................................................................................
 22336  22293   ** a legal notice, here is a blessing:
 22337  22294   **
 22338  22295   **    May you do good and not evil.
 22339  22296   **    May you find forgiveness for yourself and forgive others.
 22340  22297   **    May you share freely, never taking more than you give.
 22341  22298   **
 22342  22299   *************************************************************************
 22343         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        22300  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 22344  22301   **
 22345  22302   ** This file implements a external (disk-based) database using BTrees.
 22346  22303   ** See the header comment on "btreeInt.h" for additional information.
 22347  22304   ** Including a description of file format and an overview of operation.
 22348  22305   */
 22349  22306   /************** Include btreeInt.h in the middle of btree.c ******************/
 22350  22307   /************** Begin file btreeInt.h ****************************************/
................................................................................
 22355  22312   ** a legal notice, here is a blessing:
 22356  22313   **
 22357  22314   **    May you do good and not evil.
 22358  22315   **    May you find forgiveness for yourself and forgive others.
 22359  22316   **    May you share freely, never taking more than you give.
 22360  22317   **
 22361  22318   *************************************************************************
 22362         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        22319  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 22363  22320   **
 22364  22321   ** This file implements a external (disk-based) database using BTrees.
 22365  22322   ** For a detailed discussion of BTrees, refer to
 22366  22323   **
 22367  22324   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
 22368  22325   **     "Sorting And Searching", pages 473-480. Addison-Wesley
 22369  22326   **     Publishing Company, Reading, Massachusetts.
................................................................................
 23335  23292   ** the page, 1 means the second cell, and so forth) return a pointer
 23336  23293   ** to the cell content.
 23337  23294   **
 23338  23295   ** This routine works only for pages that do not contain overflow cells.
 23339  23296   */
 23340  23297   #define findCell(pPage, iCell) \
 23341  23298     ((pPage)->aData + get2byte(&(pPage)->aData[(pPage)->cellOffset+2*(iCell)]))
        23299  +#ifdef SQLITE_TEST
 23342  23300   SQLITE_PRIVATE u8 *sqlite3BtreeFindCell(MemPage *pPage, int iCell){
 23343  23301     assert( iCell>=0 );
 23344  23302     assert( iCell<get2byte(&pPage->aData[pPage->hdrOffset+3]) );
 23345  23303     return findCell(pPage, iCell);
 23346  23304   }
        23305  +#endif
 23347  23306   
 23348  23307   /*
 23349  23308   ** This a more complex version of sqlite3BtreeFindCell() that works for
 23350  23309   ** pages that do contain overflow cells.  See insert
 23351  23310   */
 23352  23311   static u8 *findOverflowCell(MemPage *pPage, int iCell){
 23353  23312     int i;
................................................................................
 24923  24882       while( rc==SQLITE_OK ){
 24924  24883         rc = incrVacuumStep(pBt, nFin);
 24925  24884       }
 24926  24885       if( rc==SQLITE_DONE ){
 24927  24886         assert(nFin==0 || pBt->nTrunc==0 || nFin<=pBt->nTrunc);
 24928  24887         rc = SQLITE_OK;
 24929  24888         if( pBt->nTrunc ){
 24930         -        sqlite3PagerWrite(pBt->pPage1->pDbPage);
        24889  +        rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
 24931  24890           put4byte(&pBt->pPage1->aData[32], 0);
 24932  24891           put4byte(&pBt->pPage1->aData[36], 0);
 24933  24892           pBt->nTrunc = nFin;
 24934  24893         }
 24935  24894       }
 24936  24895       if( rc!=SQLITE_OK ){
 24937  24896         sqlite3PagerRollback(pPager);
................................................................................
 25705  25664           pCur->aOverflow[iIdx] = nextPage;
 25706  25665         }
 25707  25666   #endif
 25708  25667   
 25709  25668         if( offset>=ovflSize ){
 25710  25669           /* The only reason to read this page is to obtain the page
 25711  25670           ** number for the next page in the overflow chain. The page
 25712         -	** data is not required. So first try to lookup the overflow
 25713         -	** page-list cache, if any, then fall back to the getOverflowPage()
        25671  +        ** data is not required. So first try to lookup the overflow
        25672  +        ** page-list cache, if any, then fall back to the getOverflowPage()
 25714  25673           ** function.
 25715  25674           */
 25716  25675   #ifndef SQLITE_OMIT_INCRBLOB
 25717  25676           if( pCur->aOverflow && pCur->aOverflow[iIdx+1] ){
 25718  25677             nextPage = pCur->aOverflow[iIdx+1];
 25719  25678           } else 
 25720  25679   #endif
................................................................................
 27685  27644         assert( j<nMaxCells );
 27686  27645         pCell = apCell[j];
 27687  27646         sz = szCell[j] + leafCorrection;
 27688  27647         if( !pNew->leaf ){
 27689  27648           memcpy(&pNew->aData[8], pCell, 4);
 27690  27649           pTemp = 0;
 27691  27650         }else if( leafData ){
 27692         -	/* If the tree is a leaf-data tree, and the siblings are leaves, 
        27651  +        /* If the tree is a leaf-data tree, and the siblings are leaves, 
 27693  27652           ** then there is no divider cell in apCell[]. Instead, the divider 
 27694  27653           ** cell consists of the integer key for the right-most cell of 
 27695  27654           ** the sibling-page assembled above only.
 27696  27655           */
 27697  27656           CellInfo info;
 27698  27657           j--;
 27699  27658           sqlite3BtreeParseCellPtr(pNew, apCell[j], &info);
................................................................................
 27877  27836           rc = ptrmapPutOvfl(pPage, i);
 27878  27837           if( rc!=SQLITE_OK ){
 27879  27838             goto end_shallow_balance;
 27880  27839           }
 27881  27840         }
 27882  27841       }
 27883  27842   #endif
 27884         -    if( rc!=SQLITE_OK ) goto end_shallow_balance;
 27885  27843       releasePage(pChild);
 27886  27844     }
 27887  27845   end_shallow_balance:
 27888  27846     sqliteFree(apCell);
 27889  27847     return rc;
 27890  27848   }
 27891  27849   
................................................................................
 30413  30371   
 30414  30372   /*
 30415  30373   ** When debugging the code generator in a symbolic debugger, one can
 30416  30374   ** set the sqlite3_vdbe_addop_trace to 1 and all opcodes will be printed
 30417  30375   ** as they are added to the instruction stream.
 30418  30376   */
 30419  30377   #ifdef SQLITE_DEBUG
 30420         -int sqlite3_vdbe_addop_trace = 0;
        30378  +SQLITE_API int sqlite3_vdbe_addop_trace = 0;
 30421  30379   #endif
 30422  30380   
 30423  30381   
 30424  30382   /*
 30425  30383   ** Create a new virtual database engine.
 30426  30384   */
 30427  30385   SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){
................................................................................
 31180  31138   SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe *p){
 31181  31139     int nOp = p->nOp;
 31182  31140     VdbeOp *pOp;
 31183  31141     if( sqlite3_io_trace==0 ) return;
 31184  31142     if( nOp<1 ) return;
 31185  31143     pOp = &p->aOp[nOp-1];
 31186  31144     if( pOp->opcode==OP_Noop && pOp->p3!=0 ){
 31187         -    char *z = sqlite3StrDup(pOp->p3);
 31188  31145       int i, j;
        31146  +    char z[1000];
        31147  +    sqlite3_snprintf(sizeof(z), z, "%s", pOp->p3);
 31189  31148       for(i=0; isspace((unsigned char)z[i]); i++){}
 31190  31149       for(j=0; z[i]; i++){
 31191  31150         if( isspace((unsigned char)z[i]) ){
 31192  31151           if( z[i-1]!=' ' ){
 31193  31152             z[j++] = ' ';
 31194  31153           }
 31195  31154         }else{
 31196  31155           z[j++] = z[i];
 31197  31156         }
 31198  31157       }
 31199  31158       z[j] = 0;
 31200  31159       sqlite3_io_trace("SQL %s\n", z);
 31201         -    sqliteFree(z);
 31202  31160     }
 31203  31161   }
 31204  31162   #endif /* !SQLITE_OMIT_TRACE && SQLITE_ENABLE_IOTRACE */
 31205  31163   
 31206  31164   
 31207  31165   /*
 31208  31166   ** Prepare a virtual machine for execution.  This involves things such
................................................................................
 31822  31780       ** we do either a commit or rollback of the current transaction. 
 31823  31781       **
 31824  31782       ** Note: This block also runs if one of the special errors handled 
 31825  31783       ** above has occured. 
 31826  31784       */
 31827  31785       if( db->autoCommit && db->activeVdbeCnt==1 ){
 31828  31786         if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
 31829         -	/* The auto-commit flag is true, and the vdbe program was 
        31787  +        /* The auto-commit flag is true, and the vdbe program was 
 31830  31788           ** successful or hit an 'OR FAIL' constraint. This means a commit 
 31831  31789           ** is required.
 31832  31790           */
 31833  31791           int rc = vdbeCommit(db);
 31834  31792           if( rc==SQLITE_BUSY ){
 31835  31793             return SQLITE_BUSY;
 31836  31794           }else if( rc!=SQLITE_OK ){
................................................................................
 31987  31945         }
 31988  31946         fclose(out);
 31989  31947       }
 31990  31948     }
 31991  31949   #endif
 31992  31950     p->magic = VDBE_MAGIC_INIT;
 31993  31951     p->aborted = 0;
 31994         -  if( p->rc==SQLITE_SCHEMA ){
 31995         -    sqlite3ResetInternalSchema(db, 0);
 31996         -  }
 31997  31952     return p->rc & db->errMask;
 31998  31953   }
 31999  31954    
 32000  31955   /*
 32001  31956   ** Clean up and delete a VDBE after execution.  Return an integer which is
 32002  31957   ** the result code.  Write any error message text into *pzErrMsg.
 32003  31958   */
................................................................................
 32636  32591     return p==0 || p->expired;
 32637  32592   }
 32638  32593   
 32639  32594   /**************************** sqlite3_value_  *******************************
 32640  32595   ** The following routines extract information from a Mem or sqlite3_value
 32641  32596   ** structure.
 32642  32597   */
 32643         -const void *sqlite3_value_blob(sqlite3_value *pVal){
        32598  +SQLITE_API const void *sqlite3_value_blob(sqlite3_value *pVal){
 32644  32599     Mem *p = (Mem*)pVal;
 32645  32600     if( p->flags & (MEM_Blob|MEM_Str) ){
 32646  32601       sqlite3VdbeMemExpandBlob(p);
 32647  32602       p->flags &= ~MEM_Str;
 32648  32603       p->flags |= MEM_Blob;
 32649  32604       return p->z;
 32650  32605     }else{
 32651  32606       return sqlite3_value_text(pVal);
 32652  32607     }
 32653  32608   }
 32654         -int sqlite3_value_bytes(sqlite3_value *pVal){
        32609  +SQLITE_API int sqlite3_value_bytes(sqlite3_value *pVal){
 32655  32610     return sqlite3ValueBytes(pVal, SQLITE_UTF8);
 32656  32611   }
 32657         -int sqlite3_value_bytes16(sqlite3_value *pVal){
        32612  +SQLITE_API int sqlite3_value_bytes16(sqlite3_value *pVal){
 32658  32613     return sqlite3ValueBytes(pVal, SQLITE_UTF16NATIVE);
 32659  32614   }
 32660         -double sqlite3_value_double(sqlite3_value *pVal){
        32615  +SQLITE_API double sqlite3_value_double(sqlite3_value *pVal){
 32661  32616     return sqlite3VdbeRealValue((Mem*)pVal);
 32662  32617   }
 32663         -int sqlite3_value_int(sqlite3_value *pVal){
        32618  +SQLITE_API int sqlite3_value_int(sqlite3_value *pVal){
 32664  32619     return sqlite3VdbeIntValue((Mem*)pVal);
 32665  32620   }
 32666         -sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
        32621  +SQLITE_API sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
 32667  32622     return sqlite3VdbeIntValue((Mem*)pVal);
 32668  32623   }
 32669         -const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
        32624  +SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
 32670  32625     return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
 32671  32626   }
 32672  32627   #ifndef SQLITE_OMIT_UTF16
 32673         -const void *sqlite3_value_text16(sqlite3_value* pVal){
        32628  +SQLITE_API const void *sqlite3_value_text16(sqlite3_value* pVal){
 32674  32629     return sqlite3ValueText(pVal, SQLITE_UTF16NATIVE);
 32675  32630   }
 32676         -const void *sqlite3_value_text16be(sqlite3_value *pVal){
        32631  +SQLITE_API const void *sqlite3_value_text16be(sqlite3_value *pVal){
 32677  32632     return sqlite3ValueText(pVal, SQLITE_UTF16BE);
 32678  32633   }
 32679         -const void *sqlite3_value_text16le(sqlite3_value *pVal){
        32634  +SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
 32680  32635     return sqlite3ValueText(pVal, SQLITE_UTF16LE);
 32681  32636   }
 32682  32637   #endif /* SQLITE_OMIT_UTF16 */
 32683         -int sqlite3_value_type(sqlite3_value* pVal){
        32638  +SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
 32684  32639     return pVal->type;
 32685  32640   }
 32686  32641   /* sqlite3_value_numeric_type() defined in vdbe.c */
 32687  32642   
 32688  32643   /**************************** sqlite3_result_  *******************************
 32689  32644   ** The following routines are used by user-defined functions to specify
 32690  32645   ** the function result.
 32691  32646   */
 32692         -void sqlite3_result_blob(
        32647  +SQLITE_API void sqlite3_result_blob(
 32693  32648     sqlite3_context *pCtx, 
 32694  32649     const void *z, 
 32695  32650     int n, 
 32696  32651     void (*xDel)(void *)
 32697  32652   ){
 32698  32653     assert( n>=0 );
 32699  32654     sqlite3VdbeMemSetStr(&pCtx->s, z, n, 0, xDel);
 32700  32655   }
 32701         -void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
        32656  +SQLITE_API void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
 32702  32657     sqlite3VdbeMemSetDouble(&pCtx->s, rVal);
 32703  32658   }
 32704         -void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
        32659  +SQLITE_API void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
 32705  32660     pCtx->isError = 1;
 32706  32661     sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT);
 32707  32662   }
 32708  32663   #ifndef SQLITE_OMIT_UTF16
 32709         -void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
        32664  +SQLITE_API void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
 32710  32665     pCtx->isError = 1;
 32711  32666     sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT);
 32712  32667   }
 32713  32668   #endif
 32714         -void sqlite3_result_int(sqlite3_context *pCtx, int iVal){
        32669  +SQLITE_API void sqlite3_result_int(sqlite3_context *pCtx, int iVal){
 32715  32670     sqlite3VdbeMemSetInt64(&pCtx->s, (i64)iVal);
 32716  32671   }
 32717         -void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){
        32672  +SQLITE_API void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){
 32718  32673     sqlite3VdbeMemSetInt64(&pCtx->s, iVal);
 32719  32674   }
 32720         -void sqlite3_result_null(sqlite3_context *pCtx){
        32675  +SQLITE_API void sqlite3_result_null(sqlite3_context *pCtx){
 32721  32676     sqlite3VdbeMemSetNull(&pCtx->s);
 32722  32677   }
 32723         -void sqlite3_result_text(
        32678  +SQLITE_API void sqlite3_result_text(
 32724  32679     sqlite3_context *pCtx, 
 32725  32680     const char *z, 
 32726  32681     int n,
 32727  32682     void (*xDel)(void *)
 32728  32683   ){
 32729  32684     sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, xDel);
 32730  32685   }
 32731  32686   #ifndef SQLITE_OMIT_UTF16
 32732         -void sqlite3_result_text16(
        32687  +SQLITE_API void sqlite3_result_text16(
 32733  32688     sqlite3_context *pCtx, 
 32734  32689     const void *z, 
 32735  32690     int n, 
 32736  32691     void (*xDel)(void *)
 32737  32692   ){
 32738  32693     sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, xDel);
 32739  32694   }
 32740         -void sqlite3_result_text16be(
        32695  +SQLITE_API void sqlite3_result_text16be(
 32741  32696     sqlite3_context *pCtx, 
 32742  32697     const void *z, 
 32743  32698     int n, 
 32744  32699     void (*xDel)(void *)
 32745  32700   ){
 32746  32701     sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16BE, xDel);
 32747  32702   }
 32748         -void sqlite3_result_text16le(
        32703  +SQLITE_API void sqlite3_result_text16le(
 32749  32704     sqlite3_context *pCtx, 
 32750  32705     const void *z, 
 32751  32706     int n, 
 32752  32707     void (*xDel)(void *)
 32753  32708   ){
 32754  32709     sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16LE, xDel);
 32755  32710   }
 32756  32711   #endif /* SQLITE_OMIT_UTF16 */
 32757         -void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
        32712  +SQLITE_API void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
 32758  32713     sqlite3VdbeMemCopy(&pCtx->s, pValue);
 32759  32714   }
 32760         -void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
        32715  +SQLITE_API void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
 32761  32716     sqlite3VdbeMemSetZeroBlob(&pCtx->s, n);
 32762  32717   }
 32763  32718   
 32764  32719   /* Force an SQLITE_TOOBIG error. */
 32765         -void sqlite3_result_error_toobig(sqlite3_context *pCtx){
        32720  +SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){
 32766  32721     sqlite3VdbeMemSetZeroBlob(&pCtx->s, SQLITE_MAX_LENGTH+1);
 32767  32722   }
 32768  32723   
 32769  32724   
 32770  32725   /*
 32771  32726   ** Execute the statement pStmt, either until a row of data is ready, the
 32772  32727   ** statement is completely executed or an error occurs.
................................................................................
 32914  32869   }
 32915  32870   #endif
 32916  32871   
 32917  32872   /*
 32918  32873   ** Extract the user data from a sqlite3_context structure and return a
 32919  32874   ** pointer to it.
 32920  32875   */
 32921         -void *sqlite3_user_data(sqlite3_context *p){
        32876  +SQLITE_API void *sqlite3_user_data(sqlite3_context *p){
 32922  32877     assert( p && p->pFunc );
 32923  32878     return p->pFunc->pUserData;
 32924  32879   }
 32925  32880   
 32926  32881   /*
 32927  32882   ** The following is the implementation of an SQL function that always
 32928  32883   ** fails with an error message stating that the function is used in the
................................................................................
 32945  32900   }
 32946  32901   
 32947  32902   /*
 32948  32903   ** Allocate or return the aggregate context for a user function.  A new
 32949  32904   ** context is allocated on the first call.  Subsequent calls return the
 32950  32905   ** same context that was returned on prior calls.
 32951  32906   */
 32952         -void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
        32907  +SQLITE_API void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
 32953  32908     Mem *pMem = p->pMem;
 32954  32909     assert( p && p->pFunc && p->pFunc->xStep );
 32955  32910     if( (pMem->flags & MEM_Agg)==0 ){
 32956  32911       if( nByte==0 ){
 32957  32912         assert( pMem->flags==MEM_Null );
 32958  32913         pMem->z = 0;
 32959  32914       }else{
................................................................................
 32971  32926     return (void*)pMem->z;
 32972  32927   }
 32973  32928   
 32974  32929   /*
 32975  32930   ** Return the auxilary data pointer, if any, for the iArg'th argument to
 32976  32931   ** the user-function defined by pCtx.
 32977  32932   */
 32978         -void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
        32933  +SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
 32979  32934     VdbeFunc *pVdbeFunc = pCtx->pVdbeFunc;
 32980  32935     if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){
 32981  32936       return 0;
 32982  32937     }
 32983  32938     return pVdbeFunc->apAux[iArg].pAux;
 32984  32939   }
 32985  32940   
 32986  32941   /*
 32987  32942   ** Set the auxilary data pointer and delete function, for the iArg'th
 32988  32943   ** argument to the user-function defined by pCtx. Any previous value is
 32989  32944   ** deleted by calling the delete function specified when it was set.
 32990  32945   */
 32991         -void sqlite3_set_auxdata(
        32946  +SQLITE_API void sqlite3_set_auxdata(
 32992  32947     sqlite3_context *pCtx, 
 32993  32948     int iArg, 
 32994  32949     void *pAux, 
 32995  32950     void (*xDelete)(void*)
 32996  32951   ){
 32997  32952     struct AuxData *pAuxData;
 32998  32953     VdbeFunc *pVdbeFunc;
 32999         -  if( iArg<0 ) return;
        32954  +  if( iArg<0 ) goto failed;
 33000  32955   
 33001  32956     pVdbeFunc = pCtx->pVdbeFunc;
 33002  32957     if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
 33003  32958       int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
 33004  32959       pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc);
 33005         -    if( !pVdbeFunc ) return;
        32960  +    if( !pVdbeFunc ) goto failed;
 33006  32961       pCtx->pVdbeFunc = pVdbeFunc;
 33007  32962       memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0, 
 33008  32963                sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux));
 33009  32964       pVdbeFunc->nAux = iArg+1;
 33010  32965       pVdbeFunc->pFunc = pCtx->pFunc;
 33011  32966     }
 33012  32967   
 33013  32968     pAuxData = &pVdbeFunc->apAux[iArg];
 33014  32969     if( pAuxData->pAux && pAuxData->xDelete ){
 33015  32970       pAuxData->xDelete(pAuxData->pAux);
 33016  32971     }
 33017  32972     pAuxData->pAux = pAux;
 33018  32973     pAuxData->xDelete = xDelete;
        32974  +  return;
        32975  +
        32976  +failed:
        32977  +  if( xDelete ){
        32978  +    xDelete(pAux);
        32979  +  }
 33019  32980   }
 33020  32981   
 33021  32982   /*
 33022  32983   ** Return the number of times the Step function of a aggregate has been 
 33023  32984   ** called.
 33024  32985   **
 33025  32986   ** This function is deprecated.  Do not use it for new code.  It is
 33026  32987   ** provide only to avoid breaking legacy code.  New aggregate function
 33027  32988   ** implementations should keep their own counts within their aggregate
 33028  32989   ** context.
 33029  32990   */
 33030         -int sqlite3_aggregate_count(sqlite3_context *p){
        32991  +SQLITE_API int sqlite3_aggregate_count(sqlite3_context *p){
 33031  32992     assert( p && p->pFunc && p->pFunc->xStep );
 33032  32993     return p->pMem->n;
 33033  32994   }
 33034  32995   
 33035  32996   /*
 33036  32997   ** Return the number of columns in the result set for the statement pStmt.
 33037  32998   */
 33038         -int sqlite3_column_count(sqlite3_stmt *pStmt){
        32999  +SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt){
 33039  33000     Vdbe *pVm = (Vdbe *)pStmt;
 33040  33001     return pVm ? pVm->nResColumn : 0;
 33041  33002   }
 33042  33003   
 33043  33004   /*
 33044  33005   ** Return the number of values available from the current row of the
 33045  33006   ** currently executing statement pStmt.
 33046  33007   */
 33047         -int sqlite3_data_count(sqlite3_stmt *pStmt){
        33008  +SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt){
 33048  33009     Vdbe *pVm = (Vdbe *)pStmt;
 33049  33010     if( pVm==0 || !pVm->resOnStack ) return 0;
 33050  33011     return pVm->nResColumn;
 33051  33012   }
 33052  33013   
 33053  33014   
 33054  33015   /*
................................................................................
 33098  33059     p->rc = sqlite3ApiExit(0, p->rc);
 33099  33060   }
 33100  33061   
 33101  33062   /**************************** sqlite3_column_  *******************************
 33102  33063   ** The following routines are used to access elements of the current row
 33103  33064   ** in the result set.
 33104  33065   */
 33105         -const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
        33066  +SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
 33106  33067     const void *val;
 33107  33068     val = sqlite3_value_blob( columnMem(pStmt,i) );
 33108  33069     /* Even though there is no encoding conversion, value_blob() might
 33109  33070     ** need to call malloc() to expand the result of a zeroblob() 
 33110  33071     ** expression. 
 33111  33072     */
 33112  33073     columnMallocFailure(pStmt);
 33113  33074     return val;
 33114  33075   }
 33115         -int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
        33076  +SQLITE_API int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
 33116  33077     int val = sqlite3_value_bytes( columnMem(pStmt,i) );
 33117  33078     columnMallocFailure(pStmt);
 33118  33079     return val;
 33119  33080   }
 33120         -int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
        33081  +SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
 33121  33082     int val = sqlite3_value_bytes16( columnMem(pStmt,i) );
 33122  33083     columnMallocFailure(pStmt);
 33123  33084     return val;
 33124  33085   }
 33125         -double sqlite3_column_double(sqlite3_stmt *pStmt, int i){
        33086  +SQLITE_API double sqlite3_column_double(sqlite3_stmt *pStmt, int i){
 33126  33087     double val = sqlite3_value_double( columnMem(pStmt,i) );
 33127  33088     columnMallocFailure(pStmt);
 33128  33089     return val;
 33129  33090   }
 33130         -int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
        33091  +SQLITE_API int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
 33131  33092     int val = sqlite3_value_int( columnMem(pStmt,i) );
 33132  33093     columnMallocFailure(pStmt);
 33133  33094     return val;
 33134  33095   }
 33135         -sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
        33096  +SQLITE_API sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
 33136  33097     sqlite_int64 val = sqlite3_value_int64( columnMem(pStmt,i) );
 33137  33098     columnMallocFailure(pStmt);
 33138  33099     return val;
 33139  33100   }
 33140         -const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
        33101  +SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
 33141  33102     const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
 33142  33103     columnMallocFailure(pStmt);
 33143  33104     return val;
 33144  33105   }
 33145         -sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
        33106  +SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
 33146  33107     return columnMem(pStmt, i);
 33147  33108   }
 33148  33109   #ifndef SQLITE_OMIT_UTF16
 33149         -const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
        33110  +SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
 33150  33111     const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
 33151  33112     columnMallocFailure(pStmt);
 33152  33113     return val;
 33153  33114   }
 33154  33115   #endif /* SQLITE_OMIT_UTF16 */
 33155         -int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
        33116  +SQLITE_API int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
 33156  33117     return sqlite3_value_type( columnMem(pStmt,i) );
 33157  33118   }
 33158  33119   
 33159  33120   /* The following function is experimental and subject to change or
 33160  33121   ** removal */
 33161  33122   /*int sqlite3_column_numeric_type(sqlite3_stmt *pStmt, int i){
 33162  33123   **  return sqlite3_value_numeric_type( columnMem(pStmt,i) );
................................................................................
 33202  33163     return ret;
 33203  33164   }
 33204  33165   
 33205  33166   /*
 33206  33167   ** Return the name of the Nth column of the result set returned by SQL
 33207  33168   ** statement pStmt.
 33208  33169   */
 33209         -const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
        33170  +SQLITE_API const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
 33210  33171     return columnName(
 33211  33172         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
 33212  33173   }
 33213  33174   #ifndef SQLITE_OMIT_UTF16
 33214         -const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
        33175  +SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
 33215  33176     return columnName(
 33216  33177         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
 33217  33178   }
 33218  33179   #endif
 33219  33180   
 33220  33181   /*
 33221  33182   ** Return the column declaration type (if applicable) of the 'i'th column
 33222  33183   ** of the result set of SQL statement pStmt.
 33223  33184   */
 33224         -const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
        33185  +SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
 33225  33186     return columnName(
 33226  33187         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
 33227  33188   }
 33228  33189   #ifndef SQLITE_OMIT_UTF16
 33229         -const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
        33190  +SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
 33230  33191     return columnName(
 33231  33192         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
 33232  33193   }
 33233  33194   #endif /* SQLITE_OMIT_UTF16 */
 33234  33195   
 33235  33196   #ifdef SQLITE_ENABLE_COLUMN_METADATA
 33236  33197   /*
 33237  33198   ** Return the name of the database from which a result column derives.
 33238  33199   ** NULL is returned if the result column is an expression or constant or
 33239  33200   ** anything else which is not an unabiguous reference to a database column.
 33240  33201   */
 33241         -const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
        33202  +SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
 33242  33203     return columnName(
 33243  33204         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
 33244  33205   }
 33245  33206   #ifndef SQLITE_OMIT_UTF16
 33246         -const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
        33207  +SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
 33247  33208     return columnName(
 33248  33209         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
 33249  33210   }
 33250  33211   #endif /* SQLITE_OMIT_UTF16 */
 33251  33212   
 33252  33213   /*
 33253  33214   ** Return the name of the table from which a result column derives.
 33254  33215   ** NULL is returned if the result column is an expression or constant or
 33255  33216   ** anything else which is not an unabiguous reference to a database column.
 33256  33217   */
 33257         -const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
        33218  +SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
 33258  33219     return columnName(
 33259  33220         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
 33260  33221   }
 33261  33222   #ifndef SQLITE_OMIT_UTF16
 33262         -const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
        33223  +SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
 33263  33224     return columnName(
 33264  33225         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
 33265  33226   }
 33266  33227   #endif /* SQLITE_OMIT_UTF16 */
 33267  33228   
 33268  33229   /*
 33269  33230   ** Return the name of the table column from which a result column derives.
 33270  33231   ** NULL is returned if the result column is an expression or constant or
 33271  33232   ** anything else which is not an unabiguous reference to a database column.
 33272  33233   */
 33273         -const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
        33234  +SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
 33274  33235     return columnName(
 33275  33236         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
 33276  33237   }
 33277  33238   #ifndef SQLITE_OMIT_UTF16
 33278         -const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
        33239  +SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
 33279  33240     return columnName(
 33280  33241         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
 33281  33242   }
 33282  33243   #endif /* SQLITE_OMIT_UTF16 */
 33283  33244   #endif /* SQLITE_ENABLE_COLUMN_METADATA */
 33284  33245   
 33285  33246   
................................................................................
 33342  33303     return sqlite3ApiExit(((Vdbe *)pStmt)->db, rc);
 33343  33304   }
 33344  33305   
 33345  33306   
 33346  33307   /*
 33347  33308   ** Bind a blob value to an SQL statement variable.
 33348  33309   */
 33349         -int sqlite3_bind_blob(
        33310  +SQLITE_API int sqlite3_bind_blob(
 33350  33311     sqlite3_stmt *pStmt, 
 33351  33312     int i, 
 33352  33313     const void *zData, 
 33353  33314     int nData, 
 33354  33315     void (*xDel)(void*)
 33355  33316   ){
 33356  33317     return bindText(pStmt, i, zData, nData, xDel, 0);
 33357  33318   }
 33358         -int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
        33319  +SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
 33359  33320     int rc;
 33360  33321     Vdbe *p = (Vdbe *)pStmt;
 33361  33322     rc = vdbeUnbind(p, i);
 33362  33323     if( rc==SQLITE_OK ){
 33363  33324       sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
 33364  33325     }
 33365  33326     return rc;
 33366  33327   }
 33367         -int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
        33328  +SQLITE_API int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
 33368  33329     return sqlite3_bind_int64(p, i, (i64)iValue);
 33369  33330   }
 33370         -int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
        33331  +SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
 33371  33332     int rc;
 33372  33333     Vdbe *p = (Vdbe *)pStmt;
 33373  33334     rc = vdbeUnbind(p, i);
 33374  33335     if( rc==SQLITE_OK ){
 33375  33336       sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
 33376  33337     }
 33377  33338     return rc;
 33378  33339   }
 33379         -int sqlite3_bind_null(sqlite3_stmt* p, int i){
        33340  +SQLITE_API int sqlite3_bind_null(sqlite3_stmt* p, int i){
 33380  33341     return vdbeUnbind((Vdbe *)p, i);
 33381  33342   }
 33382         -int sqlite3_bind_text( 
        33343  +SQLITE_API int sqlite3_bind_text( 
 33383  33344     sqlite3_stmt *pStmt, 
 33384  33345     int i, 
 33385  33346     const char *zData, 
 33386  33347     int nData, 
 33387  33348     void (*xDel)(void*)
 33388  33349   ){
 33389  33350     return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
 33390  33351   }
 33391  33352   #ifndef SQLITE_OMIT_UTF16
 33392         -int sqlite3_bind_text16(
        33353  +SQLITE_API int sqlite3_bind_text16(
 33393  33354     sqlite3_stmt *pStmt, 
 33394  33355     int i, 
 33395  33356     const void *zData, 
 33396  33357     int nData, 
 33397  33358     void (*xDel)(void*)
 33398  33359   ){
 33399  33360     return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
 33400  33361   }
 33401  33362   #endif /* SQLITE_OMIT_UTF16 */
 33402         -int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
        33363  +SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
 33403  33364     int rc;
 33404  33365     Vdbe *p = (Vdbe *)pStmt;
 33405  33366     rc = vdbeUnbind(p, i);
 33406  33367     if( rc==SQLITE_OK ){
 33407  33368       sqlite3VdbeMemCopy(&p->aVar[i-1], pValue);
 33408  33369     }
 33409  33370     return rc;
 33410  33371   }
 33411         -int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
        33372  +SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
 33412  33373     int rc;
 33413  33374     Vdbe *p = (Vdbe *)pStmt;
 33414  33375     rc = vdbeUnbind(p, i);
 33415  33376     if( rc==SQLITE_OK ){
 33416  33377       sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
 33417  33378     }
 33418  33379     return rc;
 33419  33380   }
 33420  33381   
 33421  33382   /*
 33422  33383   ** Return the number of wildcards that can be potentially bound to.
 33423  33384   ** This routine is added to support DBD::SQLite.  
 33424  33385   */
 33425         -int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
        33386  +SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
 33426  33387     Vdbe *p = (Vdbe*)pStmt;
 33427  33388     return p ? p->nVar : 0;
 33428  33389   }
 33429  33390   
 33430  33391   /*
 33431  33392   ** Create a mapping from variable numbers to variable names
 33432  33393   ** in the Vdbe.azVar[] array, if such a mapping does not already
................................................................................
 33448  33409   
 33449  33410   /*
 33450  33411   ** Return the name of a wildcard parameter.  Return NULL if the index
 33451  33412   ** is out of range or if the wildcard is unnamed.
 33452  33413   **
 33453  33414   ** The result is always UTF-8.
 33454  33415   */
 33455         -const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
        33416  +SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
 33456  33417     Vdbe *p = (Vdbe*)pStmt;
 33457  33418     if( p==0 || i<1 || i>p->nVar ){
 33458  33419       return 0;
 33459  33420     }
 33460  33421     createVarMap(p);
 33461  33422     return p->azVar[i-1];
 33462  33423   }
 33463  33424   
 33464  33425   /*
 33465  33426   ** Given a wildcard parameter name, return the index of the variable
 33466  33427   ** with that name.  If there is no variable with the given name,
 33467  33428   ** return 0.
 33468  33429   */
 33469         -int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
        33430  +SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
 33470  33431     Vdbe *p = (Vdbe*)pStmt;
 33471  33432     int i;
 33472  33433     if( p==0 ){
 33473  33434       return 0;
 33474  33435     }
 33475  33436     createVarMap(p); 
 33476  33437     if( zName ){
................................................................................
 33485  33446   }
 33486  33447   
 33487  33448   /*
 33488  33449   ** Transfer all bindings from the first statement over to the second.
 33489  33450   ** If the two statements contain a different number of bindings, then
 33490  33451   ** an SQLITE_ERROR is returned.
 33491  33452   */
 33492         -int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
        33453  +SQLITE_API int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
 33493  33454     Vdbe *pFrom = (Vdbe*)pFromStmt;
 33494  33455     Vdbe *pTo = (Vdbe*)pToStmt;
 33495  33456     int i, rc = SQLITE_OK;
 33496  33457     if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT)
 33497  33458       || (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT) ){
 33498  33459       return SQLITE_MISUSE;
 33499  33460     }
................................................................................
 33511  33472   
 33512  33473   /*
 33513  33474   ** Return the sqlite3* database handle to which the prepared statement given
 33514  33475   ** in the argument belongs.  This is the same database handle that was
 33515  33476   ** the first argument to the sqlite3_prepare() that was used to create
 33516  33477   ** the statement in the first place.
 33517  33478   */
 33518         -sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){
        33479  +SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){
 33519  33480     return pStmt ? ((Vdbe*)pStmt)->db : 0;
 33520  33481   }
 33521  33482   
 33522  33483   /************** End of vdbeapi.c *********************************************/
 33523  33484   /************** Begin file vdbe.c ********************************************/
 33524  33485   /*
 33525  33486   ** 2001 September 15
................................................................................
 33562  33523   **
 33563  33524   ** Various scripts scan this source file in order to generate HTML
 33564  33525   ** documentation, headers files, or other derived files.  The formatting
 33565  33526   ** of the code in this file is, therefore, important.  See other comments
 33566  33527   ** in this file for details.  If in doubt, do not deviate from existing
 33567  33528   ** commenting and indentation practices when changing or adding code.
 33568  33529   **
 33569         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        33530  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 33570  33531   */
 33571  33532   
 33572  33533   /*
 33573  33534   ** The following global variable is incremented every time a cursor
 33574  33535   ** moves, either by the OP_MoveXX, OP_Next, or OP_Prev opcodes.  The test
 33575  33536   ** procedures use this information to make sure that indices are
 33576  33537   ** working correctly.  This variable has no function other than to
 33577  33538   ** help verify the correct operation of the library.
 33578  33539   */
 33579  33540   #ifdef SQLITE_TEST
 33580         -int sqlite3_search_count = 0;
        33541  +SQLITE_API int sqlite3_search_count = 0;
 33581  33542   #endif
 33582  33543   
 33583  33544   /*
 33584  33545   ** When this global variable is positive, it gets decremented once before
 33585  33546   ** each instruction in the VDBE.  When reaches zero, the u1.isInterrupted
 33586  33547   ** field of the sqlite3 structure is set in order to simulate and interrupt.
 33587  33548   **
 33588  33549   ** This facility is used for testing purposes only.  It does not function
 33589  33550   ** in an ordinary build.
 33590  33551   */
 33591  33552   #ifdef SQLITE_TEST
 33592         -int sqlite3_interrupt_count = 0;
        33553  +SQLITE_API int sqlite3_interrupt_count = 0;
 33593  33554   #endif
 33594  33555   
 33595  33556   /*
 33596  33557   ** The next global variable is incremented each type the OP_Sort opcode
 33597  33558   ** is executed.  The test procedures use this information to make sure that
 33598  33559   ** sorting is occurring or not occuring at appropriate times.   This variable
 33599  33560   ** has no function other than to help verify the correct operation of the
 33600  33561   ** library.
 33601  33562   */
 33602  33563   #ifdef SQLITE_TEST
 33603         -int sqlite3_sort_count = 0;
        33564  +SQLITE_API int sqlite3_sort_count = 0;
 33604  33565   #endif
 33605  33566   
 33606  33567   /*
 33607  33568   ** The next global variable records the size of the largest MEM_Blob
 33608  33569   ** or MEM_Str that has appeared on the VDBE stack.  The test procedures
 33609  33570   ** use this information to make sure that the zero-blob functionality
 33610  33571   ** is working correctly.   This variable has no function other than to
 33611  33572   ** help verify the correct operation of the library.
 33612  33573   */
 33613  33574   #ifdef SQLITE_TEST
 33614         -int sqlite3_max_blobsize = 0;
        33575  +SQLITE_API int sqlite3_max_blobsize = 0;
 33615  33576   #endif
 33616  33577   
 33617  33578   /*
 33618  33579   ** Release the memory associated with the given stack level.  This
 33619  33580   ** leaves the Mem.flags field in an inconsistent state.
 33620  33581   */
 33621  33582   #define Release(P) if((P)->flags&MEM_Dyn){ sqlite3VdbeMemRelease(P); }
................................................................................
 33798  33759   ** Try to convert the type of a function argument or a result column
 33799  33760   ** into a numeric representation.  Use either INTEGER or REAL whichever
 33800  33761   ** is appropriate.  But only do the conversion if it is possible without
 33801  33762   ** loss of information and return the revised type of the argument.
 33802  33763   **
 33803  33764   ** This is an EXPERIMENTAL api and is subject to change or removal.
 33804  33765   */
 33805         -int sqlite3_value_numeric_type(sqlite3_value *pVal){
        33766  +SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
 33806  33767     Mem *pMem = (Mem*)pVal;
 33807  33768     applyNumericAffinity(pMem);
 33808  33769     storeTypeInfo(pMem, 0);
 33809  33770     return pMem->type;
 33810  33771   }
 33811  33772   
 33812  33773   /*
................................................................................
 34803  34764       assert( pOp[-1].p3type==P3_COLLSEQ );
 34804  34765       assert( pOp[-1].opcode==OP_CollSeq );
 34805  34766       ctx.pColl = (CollSeq *)pOp[-1].p3;
 34806  34767     }
 34807  34768     if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
 34808  34769     (*ctx.pFunc->xFunc)(&ctx, n, apVal);
 34809  34770     if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
 34810         -  if( sqlite3MallocFailed() ) goto no_mem;
        34771  +  if( sqlite3MallocFailed() ){
        34772  +    /* Even though a malloc() has failed, the implementation of the
        34773  +    ** user function may have called an sqlite3_result_XXX() function
        34774  +    ** to return a value. The following call releases any resources
        34775  +    ** associated with such a value.
        34776  +    **
        34777  +    ** Note: Maybe MemRelease() should be called if sqlite3SafetyOn()
        34778  +    ** fails also (the if(...) statement above). But if people are
        34779  +    ** misusing sqlite, they have bigger problems than a leaked value.
        34780  +    */
        34781  +    sqlite3VdbeMemRelease(&ctx.s);
        34782  +    goto no_mem;
        34783  +  }
 34811  34784     popStack(&pTos, n);
 34812  34785   
 34813  34786     /* If any auxilary data functions have been called by this user function,
 34814  34787     ** immediately call the destructor for any non-static values.
 34815  34788     */
 34816  34789     if( ctx.pVdbeFunc ){
 34817  34790       sqlite3VdbeDeleteAuxData(ctx.pVdbeFunc, pOp->p1);
................................................................................
 37813  37786     char *z;
 37814  37787     Mem *pnErr;
 37815  37788   
 37816  37789     for(nRoot=0; &pTos[-nRoot]>=p->aStack; nRoot++){
 37817  37790       if( (pTos[-nRoot].flags & MEM_Int)==0 ) break;
 37818  37791     }
 37819  37792     assert( nRoot>0 );
 37820         -  aRoot = sqliteMallocRaw( sizeof(int*)*(nRoot+1) );
        37793  +  aRoot = sqliteMallocRaw( sizeof(int)*(nRoot+1) );
 37821  37794     if( aRoot==0 ) goto no_mem;
 37822  37795     j = pOp->p1;
 37823  37796     assert( j>=0 && j<p->nMem );
 37824  37797     pnErr = &p->aMem[j];
 37825  37798     assert( (pnErr->flags & MEM_Int)!=0 );
 37826  37799     for(j=0; j<nRoot; j++){
 37827         -    aRoot[j] = pTos[-j].u.i;
        37800  +    aRoot[j] = (pTos-j)->u.i;
 37828  37801     }
 37829  37802     aRoot[j] = 0;
 37830  37803     popStack(&pTos, nRoot);
 37831  37804     pTos++;
 37832  37805     z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p2].pBt, aRoot, nRoot,
 37833  37806                                    pnErr->u.i, &nErr);
 37834  37807     pnErr->u.i -= nErr;
................................................................................
 38754  38727   **    May you find forgiveness for yourself and forgive others.
 38755  38728   **    May you share freely, never taking more than you give.
 38756  38729   **
 38757  38730   *************************************************************************
 38758  38731   **
 38759  38732   ** This file contains code used to implement incremental BLOB I/O.
 38760  38733   **
 38761         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        38734  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 38762  38735   */
 38763  38736   
 38764  38737   
 38765  38738   #ifndef SQLITE_OMIT_INCRBLOB
 38766  38739   
 38767  38740   /*
 38768  38741   ** Valid sqlite3_blob* handles point to Incrblob structures.
................................................................................
 38775  38748     BtCursor *pCsr;         /* Cursor pointing at blob row */
 38776  38749     sqlite3_stmt *pStmt;    /* Statement holding cursor open */
 38777  38750   };
 38778  38751   
 38779  38752   /*
 38780  38753   ** Open a blob handle.
 38781  38754   */
 38782         -int sqlite3_blob_open(
        38755  +SQLITE_API int sqlite3_blob_open(
 38783  38756     sqlite3* db,            /* The database connection */
 38784  38757     const char *zDb,        /* The attached database containing the blob */
 38785  38758     const char *zTable,     /* The table containing the blob */
 38786  38759     const char *zColumn,    /* The column containing the blob */
 38787  38760     sqlite_int64 iRow,      /* The row containing the glob */
 38788  38761     int flags,              /* True -> read/write access, false -> read-only */
 38789  38762     sqlite3_blob **ppBlob   /* Handle for accessing the blob returned here */
................................................................................
 38979  38952     return sqlite3ApiExit(db, rc);
 38980  38953   }
 38981  38954   
 38982  38955   /*
 38983  38956   ** Close a blob handle that was previously created using
 38984  38957   ** sqlite3_blob_open().
 38985  38958   */
 38986         -int sqlite3_blob_close(sqlite3_blob *pBlob){
        38959  +SQLITE_API int sqlite3_blob_close(sqlite3_blob *pBlob){
 38987  38960     Incrblob *p = (Incrblob *)pBlob;
 38988  38961     sqlite3_stmt *pStmt = p->pStmt;
 38989  38962     sqliteFree(p);
 38990  38963     return sqlite3_finalize(pStmt);
 38991  38964   }
 38992  38965   
 38993  38966   
................................................................................
 39028  39001   
 39029  39002     return sqlite3ApiExit(db, rc);
 39030  39003   }
 39031  39004   
 39032  39005   /*
 39033  39006   ** Read data from a blob handle.
 39034  39007   */
 39035         -int sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){
        39008  +SQLITE_API int sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){
 39036  39009     return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreeData);
 39037  39010   }
 39038  39011   
 39039  39012   /*
 39040  39013   ** Write data to a blob handle.
 39041  39014   */
 39042         -int sqlite3_blob_write(sqlite3_blob *pBlob, const void *z, int n, int iOffset){
        39015  +SQLITE_API int sqlite3_blob_write(sqlite3_blob *pBlob, const void *z, int n, int iOffset){
 39043  39016     return blobReadWrite(pBlob, (void *)z, n, iOffset, sqlite3BtreePutData);
 39044  39017   }
 39045  39018   
 39046  39019   /*
 39047  39020   ** Query a blob handle for the size of the data.
 39048  39021   */
 39049         -int sqlite3_blob_bytes(sqlite3_blob *pBlob){
        39022  +SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *pBlob){
 39050  39023     Incrblob *p = (Incrblob *)pBlob;
 39051  39024     return p->nByte;
 39052  39025   }
 39053  39026   
 39054  39027   #endif /* #ifndef SQLITE_OMIT_INCRBLOB */
 39055  39028   
 39056  39029   /************** End of vdbeblob.c ********************************************/
................................................................................
 39065  39038   **    May you find forgiveness for yourself and forgive others.
 39066  39039   **    May you share freely, never taking more than you give.
 39067  39040   **
 39068  39041   *************************************************************************
 39069  39042   ** This file contains routines used for analyzing expressions and
 39070  39043   ** for generating VDBE code that evaluates expressions in SQLite.
 39071  39044   **
 39072         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        39045  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 39073  39046   */
 39074  39047   
 39075  39048   /*
 39076  39049   ** Return the 'affinity' of the expression pExpr if any.
 39077  39050   **
 39078  39051   ** If pExpr is a column, a reference to a column via an 'AS' alias,
 39079  39052   ** or a sub-select with a column as the return value, then the 
................................................................................
 39228  39201   ** used. Otherwise the collation sequence for the right hand expression
 39229  39202   ** is used, or the default (BINARY) if neither expression has a collating
 39230  39203   ** type.
 39231  39204   **
 39232  39205   ** Argument pRight (but not pLeft) may be a null pointer. In this case,
 39233  39206   ** it is not considered.
 39234  39207   */
 39235         -CollSeq* sqlite3BinaryCompareCollSeq(
        39208  +SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(
 39236  39209     Parse *pParse, 
 39237  39210     Expr *pLeft, 
 39238  39211     Expr *pRight
 39239  39212   ){
 39240  39213     CollSeq *pColl;
 39241  39214     assert( pLeft );
 39242  39215     if( pLeft->flags & EP_ExpCollate ){
................................................................................
 40191  40164       ** Note that the expression in the result set should have already been
 40192  40165       ** resolved by the time the WHERE clause is resolved.
 40193  40166       */
 40194  40167       if( cnt==0 && (pEList = pNC->pEList)!=0 && zTab==0 ){
 40195  40168         for(j=0; j<pEList->nExpr; j++){
 40196  40169           char *zAs = pEList->a[j].zName;
 40197  40170           if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
 40198         -          Expr *pDup;
        40171  +          Expr *pDup, *pOrig;
 40199  40172             assert( pExpr->pLeft==0 && pExpr->pRight==0 );
 40200  40173             assert( pExpr->pList==0 );
 40201  40174             assert( pExpr->pSelect==0 );
 40202         -          pDup = sqlite3ExprDup(pEList->a[j].pExpr);
        40175  +          pOrig = pEList->a[j].pExpr;
        40176  +          if( !pNC->allowAgg && ExprHasProperty(pOrig, EP_Agg) ){
        40177  +            sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
        40178  +            sqliteFree(zCol);
        40179  +            return 2;
        40180  +          }
        40181  +          pDup = sqlite3ExprDup(pOrig);
 40203  40182             if( pExpr->flags & EP_ExpCollate ){
 40204  40183               pDup->pColl = pExpr->pColl;
 40205  40184               pDup->flags |= EP_ExpCollate;
 40206  40185             }
 40207  40186             if( pExpr->span.dyn ) sqliteFree((char*)pExpr->span.z);
 40208  40187             if( pExpr->token.dyn ) sqliteFree((char*)pExpr->token.z);
 40209  40188             memcpy(pExpr, pDup, sizeof(*pExpr));
................................................................................
 40623  40602           if( pEList && pEList->nExpr>0 ){ 
 40624  40603             keyInfo.aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
 40625  40604                 pEList->a[0].pExpr);
 40626  40605           }
 40627  40606         }else if( pExpr->pList ){
 40628  40607           /* Case 2:     expr IN (exprlist)
 40629  40608           **
 40630         -	** For each expression, build an index key from the evaluation and
        40609  +        ** For each expression, build an index key from the evaluation and
 40631  40610           ** store it in the temporary table. If <expr> is a column, then use
 40632  40611           ** that columns affinity when building index keys. If <expr> is not
 40633  40612           ** a column, use numeric affinity.
 40634  40613           */
 40635  40614           int i;
 40636  40615           ExprList *pList = pExpr->pList;
 40637  40616           struct ExprList_item *pItem;
................................................................................
 41103  41082         break;
 41104  41083       }
 41105  41084   #ifndef SQLITE_OMIT_TRIGGER
 41106  41085       case TK_RAISE: {
 41107  41086         if( !pParse->trigStack ){
 41108  41087           sqlite3ErrorMsg(pParse,
 41109  41088                          "RAISE() may only be used within a trigger-program");
 41110         -	return;
        41089  +        return;
 41111  41090         }
 41112  41091         if( pExpr->iColumn!=OE_Ignore ){
 41113  41092            assert( pExpr->iColumn==OE_Rollback ||
 41114  41093                    pExpr->iColumn == OE_Abort ||
 41115  41094                    pExpr->iColumn == OE_Fail );
 41116  41095            sqlite3DequoteExpr(pExpr);
 41117  41096            sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn,
................................................................................
 41647  41626   **    May you find forgiveness for yourself and forgive others.
 41648  41627   **    May you share freely, never taking more than you give.
 41649  41628   **
 41650  41629   *************************************************************************
 41651  41630   ** This file contains C code routines that used to generate VDBE code
 41652  41631   ** that implements the ALTER TABLE command.
 41653  41632   **
 41654         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        41633  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 41655  41634   */
 41656  41635   
 41657  41636   /*
 41658  41637   ** The code in this file only exists if we are not omitting the
 41659  41638   ** ALTER TABLE logic from the build.
 41660  41639   */
 41661  41640   #ifndef SQLITE_OMIT_ALTERTABLE
................................................................................
 42256  42235   **    May you do good and not evil.
 42257  42236   **    May you find forgiveness for yourself and forgive others.
 42258  42237   **    May you share freely, never taking more than you give.
 42259  42238   **
 42260  42239   *************************************************************************
 42261  42240   ** This file contains code associated with the ANALYZE command.
 42262  42241   **
 42263         -** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        42242  +** @(#) $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 42264  42243   */
 42265  42244   #ifndef SQLITE_OMIT_ANALYZE
 42266  42245   
 42267  42246   /*
 42268  42247   ** This routine generates code that opens the sqlite_stat1 table on cursor
 42269  42248   ** iStatCur.
 42270  42249   **
................................................................................
 42668  42647   **    May you do good and not evil.
 42669  42648   **    May you find forgiveness for yourself and forgive others.
 42670  42649   **    May you share freely, never taking more than you give.
 42671  42650   **
 42672  42651   *************************************************************************
 42673  42652   ** This file contains code used to implement the ATTACH and DETACH commands.
 42674  42653   **
 42675         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        42654  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 42676  42655   */
 42677  42656   
 42678  42657   #ifndef SQLITE_OMIT_ATTACH
 42679  42658   /*
 42680  42659   ** Resolve an expression that was part of an ATTACH or DETACH statement. This
 42681  42660   ** is slightly different from resolving a normal SQL expression, because simple
 42682  42661   ** identifiers are treated as strings, not possible column names or aliases.
................................................................................
 43189  43168   **
 43190  43169   *************************************************************************
 43191  43170   ** This file contains code used to implement the sqlite3_set_authorizer()
 43192  43171   ** API.  This facility is an optional feature of the library.  Embedded
 43193  43172   ** systems that do not need this facility may omit it by recompiling
 43194  43173   ** the library with -DSQLITE_OMIT_AUTHORIZATION=1
 43195  43174   **
 43196         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        43175  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 43197  43176   */
 43198  43177   
 43199  43178   /*
 43200  43179   ** All of the code in this file may be omitted by defining a single
 43201  43180   ** macro.
 43202  43181   */
 43203  43182   #ifndef SQLITE_OMIT_AUTHORIZATION
................................................................................
 43243  43222   ** will return with an error.  SQLITE_IGNORE means that the SQL statement
 43244  43223   ** should run but attempts to read the specified column will return NULL
 43245  43224   ** and attempts to write the column will be ignored.
 43246  43225   **
 43247  43226   ** Setting the auth function to NULL disables this hook.  The default
 43248  43227   ** setting of the auth function is NULL.
 43249  43228   */
 43250         -int sqlite3_set_authorizer(
        43229  +SQLITE_API int sqlite3_set_authorizer(
 43251  43230     sqlite3 *db,
 43252  43231     int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
 43253  43232     void *pArg
 43254  43233   ){
 43255  43234     db->xAuth = xAuth;
 43256  43235     db->pAuthArg = pArg;
 43257  43236     sqlite3ExpirePreparedStatements(db);
................................................................................
 43432  43411   **     CREATE INDEX
 43433  43412   **     DROP INDEX
 43434  43413   **     creating ID lists
 43435  43414   **     BEGIN TRANSACTION
 43436  43415   **     COMMIT
 43437  43416   **     ROLLBACK
 43438  43417   **
 43439         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        43418  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 43440  43419   */
 43441  43420   
 43442  43421   /*
 43443  43422   ** This routine is called when a new SQL statement is beginning to
 43444  43423   ** be parsed.  Initialize the pParse structure as needed.
 43445  43424   */
 43446  43425   SQLITE_PRIVATE void sqlite3BeginParse(Parse *pParse, int explainFlag){
................................................................................
 46785  46764   **    May you share freely, never taking more than you give.
 46786  46765   **
 46787  46766   *************************************************************************
 46788  46767   **
 46789  46768   ** This file contains functions used to access the internal hash tables
 46790  46769   ** of user defined functions and collation sequences.
 46791  46770   **
 46792         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        46771  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 46793  46772   */
 46794  46773   
 46795  46774   
 46796  46775   /*
 46797  46776   ** Invoke the 'collation needed' callback to request a collation sequence
 46798  46777   ** in the database text encoding of name zName, length nName.
 46799  46778   ** If the collation sequence
................................................................................
 47164  47143   ** An tokenizer for SQL
 47165  47144   **
 47166  47145   ** This file contains C code that implements the sqlite3_complete() API.
 47167  47146   ** This code used to be part of the tokenizer.c source file.  But by
 47168  47147   ** separating it out, the code will be automatically omitted from
 47169  47148   ** static links that do not use it.
 47170  47149   **
 47171         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        47150  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 47172  47151   */
 47173  47152   #ifndef SQLITE_OMIT_COMPLETE
 47174  47153   
 47175  47154   /*
 47176  47155   ** This is defined in tokenize.c.  We just have to import the definition.
 47177  47156   */
 47178         -extern const char sqlite3IsIdChar[];
        47157  +/*SQLITE_PRIVATE*/ const char sqlite3IsIdChar[];
 47179  47158   #define IdChar(C)  (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
 47180  47159   
 47181  47160   
 47182  47161   /*
 47183  47162   ** Token types used by the sqlite3_complete() routine.  See the header
 47184  47163   ** comments on that procedure for additional information.
 47185  47164   */
................................................................................
 47425  47404   **    May you find forgiveness for yourself and forgive others.
 47426  47405   **    May you share freely, never taking more than you give.
 47427  47406   **
 47428  47407   *************************************************************************
 47429  47408   ** This file contains C code routines that are called by the parser
 47430  47409   ** in order to generate code for DELETE FROM statements.
 47431  47410   **
 47432         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        47411  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 47433  47412   */
 47434  47413   
 47435  47414   /*
 47436  47415   ** Look up every table that is named in pSrc.  If any table is not found,
 47437  47416   ** add an error message to pParse->zErrMsg and return NULL.  If all tables
 47438  47417   ** are found, return a pointer to the last table.
 47439  47418   */
................................................................................
 47898  47877   ** This file contains the C functions that implement various SQL
 47899  47878   ** functions of SQLite.  
 47900  47879   **
 47901  47880   ** There is only one exported symbol in this file - the function
 47902  47881   ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
 47903  47882   ** All other code has file scope.
 47904  47883   **
 47905         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        47884  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 47906  47885   */
 47907  47886   /* #include <math.h> */
        47887  +
 47908  47888   
 47909  47889   /*
 47910  47890   ** Return the collating function associated with a function.
 47911  47891   */
 47912  47892   static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
 47913  47893     return context->pColl;
 47914  47894   }
................................................................................
 48273  48253   /* The correct SQL-92 behavior is for the LIKE operator to ignore
 48274  48254   ** case.  Thus  'a' LIKE 'A' would be true. */
 48275  48255   static const struct compareInfo likeInfoNorm = { '%', '_',   0, 1 };
 48276  48256   /* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
 48277  48257   ** is case sensitive causing 'a' LIKE 'A' to be false */
 48278  48258   static const struct compareInfo likeInfoAlt = { '%', '_',   0, 0 };
 48279  48259   
 48280         -/*
 48281         -** Read a single UTF-8 character and return its value.
 48282         -*/
 48283         -SQLITE_PRIVATE u32 sqlite3ReadUtf8(const unsigned char *z){
 48284         -  u32 c;
 48285         -  SQLITE_READ_UTF8(z, c);
 48286         -  return c;
 48287         -}
 48288         -
 48289  48260   /*
 48290  48261   ** Compare two UTF-8 strings for equality where the first string can
 48291  48262   ** potentially be a "glob" expression.  Return true (1) if they
 48292  48263   ** are the same and false (0) if they are different.
 48293  48264   **
 48294  48265   ** Globbing rules:
 48295  48266   **
................................................................................
 48316  48287   */
 48317  48288   static int patternCompare(
 48318  48289     const u8 *zPattern,              /* The glob pattern */
 48319  48290     const u8 *zString,               /* The string to compare against the glob */
 48320  48291     const struct compareInfo *pInfo, /* Information about how to do the compare */
 48321  48292     const int esc                    /* The escape character */
 48322  48293   ){
 48323         -  register int c;
        48294  +  int c, c2;
 48324  48295     int invert;
 48325  48296     int seen;
 48326         -  int c2;
 48327  48297     u8 matchOne = pInfo->matchOne;
 48328  48298     u8 matchAll = pInfo->matchAll;
 48329  48299     u8 matchSet = pInfo->matchSet;
 48330  48300     u8 noCase = pInfo->noCase; 
 48331  48301     int prevEscape = 0;     /* True if the previous character was 'escape' */
 48332  48302   
 48333         -  while( (c = *zPattern)!=0 ){
        48303  +  while( (c = sqlite3Utf8Read(zPattern,0,&zPattern))!=0 ){
 48334  48304       if( !prevEscape && c==matchAll ){
 48335         -      while( (c=zPattern[1]) == matchAll || c == matchOne ){
 48336         -        if( c==matchOne ){
 48337         -          if( *zString==0 ) return 0;
 48338         -          SQLITE_SKIP_UTF8(zString);
        48305  +      while( (c=sqlite3Utf8Read(zPattern,0,&zPattern)) == matchAll
        48306  +               || c == matchOne ){
        48307  +        if( c==matchOne && sqlite3Utf8Read(zString, 0, &zString)==0 ){
        48308  +          return 0;
 48339  48309           }
 48340         -        zPattern++;
 48341  48310         }
 48342         -      if( c && esc && sqlite3ReadUtf8(&zPattern[1])==esc ){
 48343         -        u8 const *zTemp = &zPattern[1];
 48344         -        SQLITE_SKIP_UTF8(zTemp);
 48345         -        c = *zTemp;
 48346         -      }
 48347         -      if( c==0 ) return 1;
 48348         -      if( c==matchSet ){
 48349         -        assert( esc==0 );   /* This is GLOB, not LIKE */
 48350         -        while( *zString && patternCompare(&zPattern[1],zString,pInfo,esc)==0 ){
        48311  +      if( c==0 ){
        48312  +        return 1;
        48313  +      }else if( c==esc ){
        48314  +        c = sqlite3Utf8Read(zPattern, 0, &zPattern);
        48315  +        if( c==0 ){
        48316  +          return 0;
        48317  +        }
        48318  +      }else if( c==matchSet ){
        48319  +        assert( esc==0 );         /* This is GLOB, not LIKE */
        48320  +        assert( matchSet<0x80 );  /* '[' is a single-byte character */
        48321  +        while( *zString && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
 48351  48322             SQLITE_SKIP_UTF8(zString);
 48352  48323           }
 48353  48324           return *zString!=0;
 48354         -      }else{
 48355         -        while( (c2 = *zString)!=0 ){
 48356         -          if( noCase ){
 48357         -            c2 = sqlite3UpperToLower[c2];
 48358         -            c = sqlite3UpperToLower[c];
 48359         -            while( c2 != 0 && c2 != c ){ c2 = sqlite3UpperToLower[*++zString]; }
 48360         -          }else{
 48361         -            while( c2 != 0 && c2 != c ){ c2 = *++zString; }
        48325  +      }
        48326  +      while( (c2 = sqlite3Utf8Read(zString,0,&zString))!=0 ){
        48327  +        if( noCase ){
        48328  +          c2 = c2<0x80 ? sqlite3UpperToLower[c2] : c2;
        48329  +          c = c<0x80 ? sqlite3UpperToLower[c] : c;
        48330  +          while( c2 != 0 && c2 != c ){
        48331  +            c2 = sqlite3Utf8Read(zString, 0, &zString);
        48332  +            if( c2<0x80 ) c2 = sqlite3UpperToLower[c2];
 48362  48333             }
 48363         -          if( c2==0 ) return 0;
 48364         -          if( patternCompare(&zPattern[1],zString,pInfo,esc) ) return 1;
 48365         -          SQLITE_SKIP_UTF8(zString);
        48334  +        }else{
        48335  +          while( c2 != 0 && c2 != c ){
        48336  +            c2 = sqlite3Utf8Read(zString, 0, &zString);
        48337  +          }
 48366  48338           }
        48339  +        if( c2==0 ) return 0;
        48340  +        if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
        48341  +      }
        48342  +      return 0;
        48343  +    }else if( !prevEscape && c==matchOne ){
        48344  +      if( sqlite3Utf8Read(zString, 0, &zString)==0 ){
 48367  48345           return 0;
 48368  48346         }
 48369         -    }else if( !prevEscape && c==matchOne ){
 48370         -      if( *zString==0 ) return 0;
 48371         -      SQLITE_SKIP_UTF8(zString);
 48372         -      zPattern++;
 48373  48347       }else if( c==matchSet ){
 48374  48348         int prior_c = 0;
 48375  48349         assert( esc==0 );    /* This only occurs for GLOB, not LIKE */
 48376  48350         seen = 0;
 48377  48351         invert = 0;
 48378         -      c = sqlite3ReadUtf8(zString);
        48352  +      c = sqlite3Utf8Read(zString, 0, &zString);
 48379  48353         if( c==0 ) return 0;
 48380         -      c2 = *++zPattern;
 48381         -      if( c2=='^' ){ invert = 1; c2 = *++zPattern; }
        48354  +      c2 = sqlite3Utf8Read(zPattern, 0, &zPattern);
        48355  +      if( c2=='^' ){
        48356  +        invert = 1;
        48357  +        c2 = sqlite3Utf8Read(zPattern, 0, &zPattern);
        48358  +      }
 48382  48359         if( c2==']' ){
 48383  48360           if( c==']' ) seen = 1;
 48384         -        c2 = *++zPattern;
        48361  +        c2 = sqlite3Utf8Read(zPattern, 0, &zPattern);
 48385  48362         }
 48386         -      while( (c2 = sqlite3ReadUtf8(zPattern))!=0 && c2!=']' ){
 48387         -        if( c2=='-' && zPattern[1]!=']' && zPattern[1]!=0 && prior_c>0 ){
 48388         -          zPattern++;
 48389         -          c2 = sqlite3ReadUtf8(zPattern);
        48363  +      while( c2 && c2!=']' ){
        48364  +        if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
        48365  +          c2 = sqlite3Utf8Read(zPattern, 0, &zPattern);
 48390  48366             if( c>=prior_c && c<=c2 ) seen = 1;
 48391  48367             prior_c = 0;
 48392         -        }else if( c==c2 ){
 48393         -          seen = 1;
 48394         -          prior_c = c2;
 48395  48368           }else{
        48369  +          if( c==c2 ){
        48370  +            seen = 1;
        48371  +          }
 48396  48372             prior_c = c2;
 48397  48373           }
 48398         -        SQLITE_SKIP_UTF8(zPattern);
        48374  +        c2 = sqlite3Utf8Read(zPattern, 0, &zPattern);
 48399  48375         }
 48400         -      if( c2==0 || (seen ^ invert)==0 ) return 0;
 48401         -      SQLITE_SKIP_UTF8(zString);
 48402         -      zPattern++;
 48403         -    }else if( esc && !prevEscape && sqlite3ReadUtf8(zPattern)==esc){
        48376  +      if( c2==0 || (seen ^ invert)==0 ){
        48377  +        return 0;
        48378  +      }
        48379  +    }else if( esc==c && !prevEscape ){
 48404  48380         prevEscape = 1;
 48405         -      SQLITE_SKIP_UTF8(zPattern);
 48406  48381       }else{
        48382  +      c2 = sqlite3Utf8Read(zString, 0, &zString);
 48407  48383         if( noCase ){
 48408         -        if( sqlite3UpperToLower[c] != sqlite3UpperToLower[*zString] ) return 0;
 48409         -      }else{
 48410         -        if( c != *zString ) return 0;
        48384  +        c = c<0x80 ? sqlite3UpperToLower[c] : c;
        48385  +        c2 = c2<0x80 ? sqlite3UpperToLower[c2] : c2;
 48411  48386         }
 48412         -      zPattern++;
 48413         -      zString++;
        48387  +      if( c!=c2 ){
        48388  +        return 0;
        48389  +      }
 48414  48390         prevEscape = 0;
 48415  48391       }
 48416  48392     }
 48417  48393     return *zString==0;
 48418  48394   }
 48419  48395   
 48420  48396   /*
 48421  48397   ** Count the number of times that the LIKE operator (or GLOB which is
 48422  48398   ** just a variation of LIKE) gets called.  This is used for testing
 48423  48399   ** only.
 48424  48400   */
 48425  48401   #ifdef SQLITE_TEST
 48426         -int sqlite3_like_count = 0;
        48402  +SQLITE_API int sqlite3_like_count = 0;
 48427  48403   #endif
 48428  48404   
 48429  48405   
 48430  48406   /*
 48431  48407   ** Implementation of the like() SQL function.  This function implements
 48432  48408   ** the build-in LIKE operator.  The first argument to the function is the
 48433  48409   ** pattern and the second argument is the string.  So, the SQL statements:
................................................................................
 48466  48442       const unsigned char *zEsc = sqlite3_value_text(argv[2]);
 48467  48443       if( zEsc==0 ) return;
 48468  48444       if( sqlite3Utf8CharLen((char*)zEsc, -1)!=1 ){
 48469  48445         sqlite3_result_error(context, 
 48470  48446             "ESCAPE expression must be a single character", -1);
 48471  48447         return;
 48472  48448       }
 48473         -    escape = sqlite3ReadUtf8(zEsc);
        48449  +    escape = sqlite3Utf8Read(zEsc, 0, &zEsc);
 48474  48450     }
 48475  48451     if( zA && zB ){
 48476  48452       struct compareInfo *pInfo = sqlite3_user_data(context);
 48477  48453   #ifdef SQLITE_TEST
 48478  48454       sqlite3_like_count++;
 48479  48455   #endif
 48480  48456       
................................................................................
 48997  48973     for(i=0; i<nArg; i++){
 48998  48974       char const *z = (char*)sqlite3_value_text(argv[i]);
 48999  48975       if( z ){
 49000  48976         char *zAux = sqlite3_get_auxdata(pCtx, i);
 49001  48977         if( zAux ){
 49002  48978           zRet[i*2] = '1';
 49003  48979           if( strcmp(zAux, z) ){
        48980  +          free_test_auxdata((void *)zRet);
 49004  48981             sqlite3_result_error(pCtx, "Auxilary data corruption", -1);
 49005  48982             return;
 49006  48983           }
 49007  48984         }else{
 49008  48985           zRet[i*2] = '0';
 49009  48986           zAux = sqliteStrDup(z);
 49010  48987           sqlite3_set_auxdata(pCtx, i, zAux, free_test_auxdata);
................................................................................
 49384  49361   **    May you find forgiveness for yourself and forgive others.
 49385  49362   **    May you share freely, never taking more than you give.
 49386  49363   **
 49387  49364   *************************************************************************
 49388  49365   ** This file contains C code routines that are called by the parser
 49389  49366   ** to handle INSERT statements in SQLite.
 49390  49367   **
 49391         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        49368  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 49392  49369   */
 49393  49370   
 49394  49371   /*
 49395  49372   ** Set P3 of the most recently inserted opcode to a column affinity
 49396  49373   ** string for index pIdx. A column affinity string has one character
 49397  49374   ** for each column in the table, according to the affinity of the column:
 49398  49375   **
................................................................................
 50398  50375       int allOk = sqlite3VdbeMakeLabel(v);
 50399  50376       assert( pParse->ckOffset==0 );
 50400  50377       pParse->ckOffset = nCol;
 50401  50378       sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, 1);
 50402  50379       assert( pParse->ckOffset==nCol );
 50403  50380       pParse->ckOffset = 0;
 50404  50381       onError = overrideError!=OE_Default ? overrideError : OE_Abort;
 50405         -    if( onError==OE_Ignore || onError==OE_Replace ){
        50382  +    if( onError==OE_Ignore ){
 50406  50383         sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
 50407  50384         sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
 50408  50385       }else{
 50409  50386         sqlite3VdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, onError);
 50410  50387       }
 50411  50388       sqlite3VdbeResolveLabel(v, allOk);
 50412  50389     }
................................................................................
 50662  50639   #ifdef SQLITE_TEST
 50663  50640   /*
 50664  50641   ** The following global variable is incremented whenever the
 50665  50642   ** transfer optimization is used.  This is used for testing
 50666  50643   ** purposes only - to make sure the transfer optimization really
 50667  50644   ** is happening when it is suppose to.
 50668  50645   */
 50669         -int sqlite3_xferopt_count;
        50646  +SQLITE_API int sqlite3_xferopt_count;
 50670  50647   #endif /* SQLITE_TEST */
 50671  50648   
 50672  50649   
 50673  50650   #ifndef SQLITE_OMIT_XFER_OPT
 50674  50651   /*
 50675  50652   ** Check to collation names to see if they are compatible.
 50676  50653   */
................................................................................
 50992  50969   **
 50993  50970   *************************************************************************
 50994  50971   ** Main file for the SQLite library.  The routines in this file
 50995  50972   ** implement the programmer interface to the library.  Routines in
 50996  50973   ** other files are for internal use by SQLite and should not be
 50997  50974   ** accessed by users of the library.
 50998  50975   **
 50999         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        50976  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 51000  50977   */
 51001  50978   
 51002  50979   
 51003  50980   /*
 51004  50981   ** Execute SQL code.  Return one of the SQLITE_ success/failure
 51005  50982   ** codes.  Also write an error message into memory obtained from
 51006  50983   ** malloc() and make *pzErrMsg point to that message.
................................................................................
 51144  51121   *************************************************************************
 51145  51122   ** This header file defines the SQLite interface for use by
 51146  51123   ** shared libraries that want to be imported as extensions into
 51147  51124   ** an SQLite instance.  Shared libraries that intend to be loaded
 51148  51125   ** as extensions by SQLite should #include this file instead of 
 51149  51126   ** sqlite3.h.
 51150  51127   **
 51151         -** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        51128  +** @(#) $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 51152  51129   */
 51153  51130   #ifndef _SQLITE3EXT_H_
 51154  51131   #define _SQLITE3EXT_H_
 51155  51132   
 51156  51133   typedef struct sqlite3_api_routines sqlite3_api_routines;
 51157  51134   
 51158  51135   /*
................................................................................
 51516  51493   **
 51517  51494   ** Extensions that use newer APIs should first call the
 51518  51495   ** sqlite3_libversion_number() to make sure that the API they
 51519  51496   ** intend to use is supported by the library.  Extensions should
 51520  51497   ** also check to make sure that the pointer to the function is
 51521  51498   ** not NULL before calling it.
 51522  51499   */
 51523         -const sqlite3_api_routines sqlite3_apis = {
        51500  +SQLITE_API const sqlite3_api_routines sqlite3_apis = {
 51524  51501     sqlite3_aggregate_context,
 51525  51502     sqlite3_aggregate_count,
 51526  51503     sqlite3_bind_blob,
 51527  51504     sqlite3_bind_double,
 51528  51505     sqlite3_bind_int,
 51529  51506     sqlite3_bind_int64,
 51530  51507     sqlite3_bind_null,
................................................................................
 51668  51645   **
 51669  51646   ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
 51670  51647   **
 51671  51648   ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with 
 51672  51649   ** error message text.  The calling function should free this memory
 51673  51650   ** by calling sqlite3_free().
 51674  51651   */
 51675         -int sqlite3_load_extension(
        51652  +SQLITE_API int sqlite3_load_extension(
 51676  51653     sqlite3 *db,          /* Load the extension into this database connection */
 51677  51654     const char *zFile,    /* Name of the shared library containing extension */
 51678  51655     const char *zProc,    /* Entry point.  Use "sqlite3_extension_init" if 0 */
 51679  51656     char **pzErrMsg       /* Put error message here if not 0 */
 51680  51657   ){
 51681  51658     void *handle;
 51682  51659     int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
................................................................................
 51753  51730     sqliteFree(db->aExtension);
 51754  51731   }
 51755  51732   
 51756  51733   /*
 51757  51734   ** Enable or disable extension loading.  Extension loading is disabled by
 51758  51735   ** default so as not to open security holes in older applications.
 51759  51736   */
 51760         -int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
        51737  +SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
 51761  51738     if( onoff ){
 51762  51739       db->flags |= SQLITE_LoadExtension;
 51763  51740     }else{
 51764  51741       db->flags &= ~SQLITE_LoadExtension;
 51765  51742     }
 51766  51743     return SQLITE_OK;
 51767  51744   }
................................................................................
 51776  51753   static void **aAutoExtension = 0;
 51777  51754   
 51778  51755   
 51779  51756   /*
 51780  51757   ** Register a statically linked extension that is automatically
 51781  51758   ** loaded by every new database connection.
 51782  51759   */
 51783         -int sqlite3_auto_extension(void *xInit){
        51760  +SQLITE_API int sqlite3_auto_extension(void *xInit){
 51784  51761     int i;
 51785  51762     int rc = SQLITE_OK;
 51786  51763     sqlite3OsEnterMutex();
 51787  51764     for(i=0; i<nAutoExtension; i++){
 51788  51765       if( aAutoExtension[i]==xInit ) break;
 51789  51766     }
 51790  51767     if( i==nAutoExtension ){
................................................................................
 51802  51779     assert( (rc&0xff)==rc );
 51803  51780     return rc;
 51804  51781   }
 51805  51782   
 51806  51783   /*
 51807  51784   ** Reset the automatic extension loading mechanism.
 51808  51785   */
 51809         -void sqlite3_reset_auto_extension(void){
        51786  +SQLITE_API void sqlite3_reset_auto_extension(void){
 51810  51787     sqlite3OsEnterMutex();
 51811  51788     sqliteFree(aAutoExtension);
 51812  51789     aAutoExtension = 0;
 51813  51790     nAutoExtension = 0;
 51814  51791     sqlite3OsLeaveMutex();
 51815  51792   }
 51816  51793   
................................................................................
 51861  51838   **    May you do good and not evil.
 51862  51839   **    May you find forgiveness for yourself and forgive others.
 51863  51840   **    May you share freely, never taking more than you give.
 51864  51841   **
 51865  51842   *************************************************************************
 51866  51843   ** This file contains code used to implement the PRAGMA command.
 51867  51844   **
 51868         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        51845  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 51869  51846   */
 51870  51847   
 51871  51848   /* Ignore this whole file if pragmas are disabled
 51872  51849   */
 51873  51850   #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
 51874  51851   
 51875  51852   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
................................................................................
 53041  53018   **    May you share freely, never taking more than you give.
 53042  53019   **
 53043  53020   *************************************************************************
 53044  53021   ** This file contains the implementation of the sqlite3_prepare()
 53045  53022   ** interface, and routines that contribute to loading the database schema
 53046  53023   ** from disk.
 53047  53024   **
 53048         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        53025  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 53049  53026   */
 53050  53027   
 53051  53028   /*
 53052  53029   ** Fill the InitData structure with an error message that indicates
 53053  53030   ** that the database is corrupt.
 53054  53031   */
 53055  53032   static void corruptSchema(InitData *pData, const char *zExtra){
................................................................................
 53362  53339   **
 53363  53340   ** After a database is initialized, the DB_SchemaLoaded bit is set
 53364  53341   ** bit is set in the flags field of the Db structure. If the database
 53365  53342   ** file was of zero-length, then the DB_Empty flag is also set.
 53366  53343   */
 53367  53344   SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
 53368  53345     int i, rc;
 53369         -  int called_initone = 0;
        53346  +  int commit_internal = !(db->flags&SQLITE_InternChanges);
 53370  53347     
 53371  53348     if( db->init.busy ) return SQLITE_OK;
 53372  53349     rc = SQLITE_OK;
 53373  53350     db->init.busy = 1;
 53374  53351     for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
 53375  53352       if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
 53376  53353       rc = sqlite3InitOne(db, i, pzErrMsg);
 53377  53354       if( rc ){
 53378  53355         sqlite3ResetInternalSchema(db, i);
 53379  53356       }
 53380         -    called_initone = 1;
 53381  53357     }
 53382  53358   
 53383  53359     /* Once all the other databases have been initialised, load the schema
 53384  53360     ** for the TEMP database. This is loaded last, as the TEMP database
 53385  53361     ** schema may contain references to objects in other databases.
 53386  53362     */
 53387  53363   #ifndef SQLITE_OMIT_TEMPDB
 53388  53364     if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
 53389  53365       rc = sqlite3InitOne(db, 1, pzErrMsg);
 53390  53366       if( rc ){
 53391  53367         sqlite3ResetInternalSchema(db, 1);
 53392  53368       }
 53393         -    called_initone = 1;
 53394  53369     }
 53395  53370   #endif
 53396  53371   
 53397  53372     db->init.busy = 0;
 53398         -  if( rc==SQLITE_OK && called_initone ){
        53373  +  if( rc==SQLITE_OK && commit_internal ){
 53399  53374       sqlite3CommitInternalChanges(db);
 53400  53375     }
 53401  53376   
 53402  53377     return rc; 
 53403  53378   }
 53404  53379   
 53405  53380   /*
................................................................................
 53640  53615     const char *zSql,         /* UTF-8 encoded SQL statement. */
 53641  53616     int nBytes,               /* Length of zSql in bytes. */
 53642  53617     sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
 53643  53618     const char **pzTail       /* OUT: End of parsed string */
 53644  53619   ){
 53645  53620     return sqlite3Prepare(db,zSql,nBytes,0,ppStmt,pzTail);
 53646  53621   }
 53647         -int sqlite3_prepare_v2(
        53622  +SQLITE_API int sqlite3_prepare_v2(
 53648  53623     sqlite3 *db,              /* Database handle. */
 53649  53624     const char *zSql,         /* UTF-8 encoded SQL statement. */
 53650  53625     int nBytes,               /* Length of zSql in bytes. */
 53651  53626     sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
 53652  53627     const char **pzTail       /* OUT: End of parsed string */
 53653  53628   ){
 53654  53629     return sqlite3Prepare(db,zSql,nBytes,1,ppStmt,pzTail);
................................................................................
 53709  53684     const void *zSql,         /* UTF-8 encoded SQL statement. */
 53710  53685     int nBytes,               /* Length of zSql in bytes. */
 53711  53686     sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
 53712  53687     const void **pzTail       /* OUT: End of parsed string */
 53713  53688   ){
 53714  53689     return sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
 53715  53690   }
 53716         -int sqlite3_prepare16_v2(
        53691  +SQLITE_API int sqlite3_prepare16_v2(
 53717  53692     sqlite3 *db,              /* Database handle. */ 
 53718  53693     const void *zSql,         /* UTF-8 encoded SQL statement. */
 53719  53694     int nBytes,               /* Length of zSql in bytes. */
 53720  53695     sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
 53721  53696     const void **pzTail       /* OUT: End of parsed string */
 53722  53697   ){
 53723  53698     return sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail);
................................................................................
 53737  53712   **    May you find forgiveness for yourself and forgive others.
 53738  53713   **    May you share freely, never taking more than you give.
 53739  53714   **
 53740  53715   *************************************************************************
 53741  53716   ** This file contains C code routines that are called by the parser
 53742  53717   ** to handle SELECT statements in SQLite.
 53743  53718   **
 53744         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        53719  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 53745  53720   */
 53746  53721   
 53747  53722   
 53748  53723   /*
 53749  53724   ** Delete all the content of a Select structure but do not deallocate
 53750  53725   ** the select structure itself.
 53751  53726   */
................................................................................
 57347  57322   ** at the conclusion of the call.
 57348  57323   **
 57349  57324   ** The result that is written to ***pazResult is held in memory obtained
 57350  57325   ** from malloc().  But the caller cannot free this memory directly.  
 57351  57326   ** Instead, the entire table should be passed to sqlite3_free_table() when
 57352  57327   ** the calling procedure is finished using it.
 57353  57328   */
 57354         -int sqlite3_get_table(
        57329  +SQLITE_API int sqlite3_get_table(
 57355  57330     sqlite3 *db,                /* The database on which the SQL executes */
 57356  57331     const char *zSql,           /* The SQL to be executed */
 57357  57332     char ***pazResult,          /* Write the result table here */
 57358  57333     int *pnRow,                 /* Write the number of rows in the result here */
 57359  57334     int *pnColumn,              /* Write the number of columns of result here */
 57360  57335     char **pzErrMsg             /* Write error messages here */
 57361  57336   ){
................................................................................
 57412  57387     if( pnRow ) *pnRow = res.nRow;
 57413  57388     return rc & db->errMask;
 57414  57389   }
 57415  57390   
 57416  57391   /*
 57417  57392   ** This routine frees the space the sqlite3_get_table() malloced.
 57418  57393   */
 57419         -void sqlite3_free_table(
        57394  +SQLITE_API void sqlite3_free_table(
 57420  57395     char **azResult            /* Result returned from from sqlite3_get_table() */
 57421  57396   ){
 57422  57397     if( azResult ){
 57423  57398       int i, n;
 57424  57399       azResult--;
 57425  57400       if( azResult==0 ) return;
 57426  57401       n = (int)azResult[0];
................................................................................
 58103  58078     sqlite3VdbeAddOp(v, OP_ContextPush, 0, 0);
 58104  58079     VdbeComment((v, "# begin trigger %s", pStepList->pTrig->name));
 58105  58080     while( pTriggerStep ){
 58106  58081       orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
 58107  58082       pParse->trigStack->orconf = orconf;
 58108  58083       switch( pTriggerStep->op ){
 58109  58084         case TK_SELECT: {
 58110         -	Select *ss = sqlite3SelectDup(pTriggerStep->pSelect);
        58085  +        Select *ss = sqlite3SelectDup(pTriggerStep->pSelect);
 58111  58086           if( ss ){
 58112  58087             sqlite3SelectResolve(pParse, ss, 0);
 58113  58088             sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
 58114  58089             sqlite3SelectDelete(ss);
 58115  58090           }
 58116         -	break;
        58091  +        break;
 58117  58092         }
 58118  58093         case TK_UPDATE: {
 58119  58094           SrcList *pSrc;
 58120  58095           pSrc = targetSrcList(pParse, pTriggerStep);
 58121  58096           sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
 58122  58097           sqlite3Update(pParse, pSrc,
 58123         -		sqlite3ExprListDup(pTriggerStep->pExprList), 
 58124         -		sqlite3ExprDup(pTriggerStep->pWhere), orconf);
        58098  +                sqlite3ExprListDup(pTriggerStep->pExprList), 
        58099  +                sqlite3ExprDup(pTriggerStep->pWhere), orconf);
 58125  58100           sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0);
 58126  58101           break;
 58127  58102         }
 58128  58103         case TK_INSERT: {
 58129  58104           SrcList *pSrc;
 58130  58105           pSrc = targetSrcList(pParse, pTriggerStep);
 58131  58106           sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
................................................................................
 58273  58248   **    May you find forgiveness for yourself and forgive others.
 58274  58249   **    May you share freely, never taking more than you give.
 58275  58250   **
 58276  58251   *************************************************************************
 58277  58252   ** This file contains C code routines that are called by the parser
 58278  58253   ** to handle UPDATE statements.
 58279  58254   **
 58280         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        58255  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 58281  58256   */
 58282  58257   
 58283  58258   #ifndef SQLITE_OMIT_VIRTUALTABLE
 58284  58259   /* Forward declaration */
 58285  58260   static void updateVirtualTable(
 58286  58261     Parse *pParse,       /* The parsing context */
 58287  58262     SrcList *pSrc,       /* The virtual table to be modified */
................................................................................
 58904  58879   **
 58905  58880   *************************************************************************
 58906  58881   ** This file contains code used to implement the VACUUM command.
 58907  58882   **
 58908  58883   ** Most of the code in this file may be omitted by defining the
 58909  58884   ** SQLITE_OMIT_VACUUM macro.
 58910  58885   **
 58911         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        58886  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 58912  58887   */
 58913  58888   
 58914  58889   #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
 58915  58890   /*
 58916  58891   ** Execute zSql on database db. Return an error code.
 58917  58892   */
 58918  58893   static int execSql(sqlite3 *db, const char *zSql){
................................................................................
 59163  59138   **    May you do good and not evil.
 59164  59139   **    May you find forgiveness for yourself and forgive others.
 59165  59140   **    May you share freely, never taking more than you give.
 59166  59141   **
 59167  59142   *************************************************************************
 59168  59143   ** This file contains code used to help implement virtual tables.
 59169  59144   **
 59170         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        59145  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 59171  59146   */
 59172  59147   #ifndef SQLITE_OMIT_VIRTUALTABLE
 59173  59148   
 59174  59149   static int createModule(
 59175  59150     sqlite3 *db,                    /* Database in which module is registered */
 59176  59151     const char *zName,              /* Name assigned to this module */
 59177  59152     const sqlite3_module *pModule,  /* The definition of the module */
................................................................................
 59197  59172     return sqlite3ApiExit(db, SQLITE_OK);
 59198  59173   }
 59199  59174   
 59200  59175   
 59201  59176   /*
 59202  59177   ** External API function used to create a new virtual-table module.
 59203  59178   */
 59204         -int sqlite3_create_module(
        59179  +SQLITE_API int sqlite3_create_module(
 59205  59180     sqlite3 *db,                    /* Database in which module is registered */
 59206  59181     const char *zName,              /* Name assigned to this module */
 59207  59182     const sqlite3_module *pModule,  /* The definition of the module */
 59208  59183     void *pAux                      /* Context pointer for xCreate/xConnect */
 59209  59184   ){
 59210  59185     return createModule(db, zName, pModule, pAux, 0);
 59211  59186   }
 59212  59187   
 59213  59188   /*
 59214  59189   ** External API function used to create a new virtual-table module.
 59215  59190   */
 59216         -int sqlite3_create_module_v2(
        59191  +SQLITE_API int sqlite3_create_module_v2(
 59217  59192     sqlite3 *db,                    /* Database in which module is registered */
 59218  59193     const char *zName,              /* Name assigned to this module */
 59219  59194     const sqlite3_module *pModule,  /* The definition of the module */
 59220  59195     void *pAux,                     /* Context pointer for xCreate/xConnect */
 59221  59196     void (*xDestroy)(void *)        /* Module destructor function */
 59222  59197   ){
 59223  59198     return createModule(db, zName, pModule, pAux, xDestroy);
................................................................................
 59667  59642   }
 59668  59643   
 59669  59644   /*
 59670  59645   ** This function is used to set the schema of a virtual table.  It is only
 59671  59646   ** valid to call this function from within the xCreate() or xConnect() of a
 59672  59647   ** virtual table module.
 59673  59648   */
 59674         -int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
        59649  +SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
 59675  59650     Parse sParse;
 59676  59651   
 59677  59652     int rc = SQLITE_OK;
 59678  59653     Table *pTab = db->pVTab;
 59679  59654     char *zErr = 0;
 59680  59655   
 59681  59656     if( !pTab ){
................................................................................
 59951  59926   ** This module contains C code that generates VDBE code used to process
 59952  59927   ** the WHERE clause of SQL statements.  This module is reponsible for
 59953  59928   ** generating the code that loops through a table looking for applicable
 59954  59929   ** rows.  Indices are selected and used to speed the search when doing
 59955  59930   ** so is applicable.  Because this module is responsible for selecting
 59956  59931   ** indices, you might also think of this module as the "query optimizer".
 59957  59932   **
 59958         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        59933  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 59959  59934   */
 59960  59935   
 59961  59936   /*
 59962  59937   ** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
 59963  59938   */
 59964  59939   #define BMS  (sizeof(Bitmask)*8)
 59965  59940   
 59966  59941   /*
 59967  59942   ** Trace output macros
 59968  59943   */
 59969  59944   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
 59970         -int sqlite3_where_trace = 0;
        59945  +SQLITE_API int sqlite3_where_trace = 0;
 59971  59946   # define WHERETRACE(X)  if(sqlite3_where_trace) sqlite3DebugPrintf X
 59972  59947   #else
 59973  59948   # define WHERETRACE(X)
 59974  59949   #endif
 59975  59950   
 59976  59951   /* Forward reference
 59977  59952   */
................................................................................
 60317  60292   ** Swap two objects of type T.
 60318  60293   */
 60319  60294   #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
 60320  60295   
 60321  60296   /*
 60322  60297   ** Commute a comparision operator.  Expressions of the form "X op Y"
 60323  60298   ** are converted into "Y op X".
        60299  +**
        60300  +** If a collation sequence is associated with either the left or right
        60301  +** side of the comparison, it remains associated with the same side after
        60302  +** the commutation. So "Y collate NOCASE op X" becomes 
        60303  +** "X collate NOCASE op Y". This is because any collation sequence on
        60304  +** the left hand side of a comparison overrides any collation sequence 
        60305  +** attached to the right. For the same reason the EP_ExpCollate flag
        60306  +** is not commuted.
 60324  60307   */
 60325  60308   static void exprCommute(Expr *pExpr){
        60309  +  u16 expRight = (pExpr->pRight->flags & EP_ExpCollate);
        60310  +  u16 expLeft = (pExpr->pLeft->flags & EP_ExpCollate);
 60326  60311     assert( allowedOp(pExpr->op) && pExpr->op!=TK_IN );
 60327  60312     SWAP(CollSeq*,pExpr->pRight->pColl,pExpr->pLeft->pColl);
        60313  +  pExpr->pRight->flags = (pExpr->pRight->flags & ~EP_ExpCollate) | expLeft;
        60314  +  pExpr->pLeft->flags = (pExpr->pLeft->flags & ~EP_ExpCollate) | expRight;
 60328  60315     SWAP(Expr*,pExpr->pRight,pExpr->pLeft);
 60329  60316     if( pExpr->op>=TK_GT ){
 60330  60317       assert( TK_LT==TK_GT+2 );
 60331  60318       assert( TK_GE==TK_LE+2 );
 60332  60319       assert( TK_GT>TK_EQ );
 60333  60320       assert( TK_GT<TK_LE );
 60334  60321       assert( pExpr->op>=TK_GT && pExpr->op<=TK_GE );
................................................................................
 61755  61742   #if defined(SQLITE_TEST)
 61756  61743   /*
 61757  61744   ** The following variable holds a text description of query plan generated
 61758  61745   ** by the most recent call to sqlite3WhereBegin().  Each call to WhereBegin
 61759  61746   ** overwrites the previous.  This information is used for testing and
 61760  61747   ** analysis only.
 61761  61748   */
 61762         -char sqlite3_query_plan[BMS*2*40];  /* Text of the join */
        61749  +SQLITE_API char sqlite3_query_plan[BMS*2*40];  /* Text of the join */
 61763  61750   static int nQPlan = 0;              /* Next free slow in _query_plan[] */
 61764  61751   
 61765  61752   #endif /* SQLITE_TEST */
 61766  61753   
 61767  61754   
 61768  61755   /*
 61769  61756   ** Free a WhereInfo structure
................................................................................
 65815  65802   *************************************************************************
 65816  65803   ** An tokenizer for SQL
 65817  65804   **
 65818  65805   ** This file contains C code that splits an SQL input string up into
 65819  65806   ** individual tokens and sends those tokens one-by-one over to the
 65820  65807   ** parser for analysis.
 65821  65808   **
 65822         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        65809  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 65823  65810   */
 65824  65811   
 65825  65812   /*
 65826  65813   ** The charMap() macro maps alphabetic characters into their
 65827  65814   ** lower-case ASCII equivalent.  On ASCII machines, this is just
 65828  65815   ** an upper-to-lower case map.  On EBCDIC machines we also need
 65829  65816   ** to adjust the encoding.  Only alphabetic characters and underscores
................................................................................
 65868  65855   */
 65869  65856   /************** Include keywordhash.h in the middle of tokenize.c ************/
 65870  65857   /************** Begin file keywordhash.h *************************************/
 65871  65858   /***** This file contains automatically generated code ******
 65872  65859   **
 65873  65860   ** The code in this file has been automatically generated by
 65874  65861   **
 65875         -**     $Header: /cvsroot/sqlite-dotnet2/SQLite.NET/SQLite.Interop/src/sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        65862  +**     $Header: /cvsroot/sqlite-dotnet2/SQLite.NET/SQLite.Interop/src/sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 65876  65863   **
 65877  65864   ** The code in this file implements a function that determines whether
 65878  65865   ** or not a given identifier is really an SQL keyword.  The same thing
 65879  65866   ** might be implemented more directly using a hand-written hash table.
 65880  65867   ** But by using this automatically generated code, the size of the code
 65881  65868   ** is substantially reduced.  This is important for embedded applications
 65882  65869   ** on platforms with limited memory.
................................................................................
 65998  65985   **
 65999  65986   ** Ticket #1066.  the SQL standard does not allow '$' in the
 66000  65987   ** middle of identfiers.  But many SQL implementations do. 
 66001  65988   ** SQLite will allow '$' in identifiers for compatibility.
 66002  65989   ** But the feature is undocumented.
 66003  65990   */
 66004  65991   #ifdef SQLITE_ASCII
 66005         -const char sqlite3IsIdChar[] = {
        65992  +SQLITE_PRIVATE const char sqlite3IsIdChar[] = {
 66006  65993   /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
 66007  65994       0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 2x */
 66008  65995       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,  /* 3x */
 66009  65996       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 4x */
 66010  65997       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,  /* 5x */
 66011  65998       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 6x */
 66012  65999       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,  /* 7x */
 66013  66000   };
 66014  66001   #define IdChar(C)  (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
 66015  66002   #endif
 66016  66003   #ifdef SQLITE_EBCDIC
 66017         -const char sqlite3IsIdChar[] = {
        66004  +SQLITE_PRIVATE const char sqlite3IsIdChar[] = {
 66018  66005   /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
 66019  66006       0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,  /* 4x */
 66020  66007       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0,  /* 5x */
 66021  66008       0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0,  /* 6x */
 66022  66009       0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,  /* 7x */
 66023  66010       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0,  /* 8x */
 66024  66011       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0,  /* 9x */
................................................................................
 66292  66279     *tokenType = TK_ILLEGAL;
 66293  66280     return 1;
 66294  66281   }
 66295  66282   SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){
 66296  66283     return getToken(z, tokenType);
 66297  66284   }
 66298  66285   
 66299         -/*
 66300         -** The interface to the LEMON-generated parser
 66301         -*/
 66302         -SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(size_t));
 66303         -SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
 66304         -SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
 66305         -
 66306  66286   /*
 66307  66287   ** Run the parser on the given SQL string.  The parser structure is
 66308  66288   ** passed in.  An SQLITE_ status code is returned.  If an error occurs
 66309  66289   ** and pzErrMsg!=NULL then an error message might be written into 
 66310  66290   ** memory obtained from malloc() and *pzErrMsg made to point to that
 66311  66291   ** error message.  Or maybe not.
 66312  66292   */
................................................................................
 66444  66424   **
 66445  66425   *************************************************************************
 66446  66426   ** Main file for the SQLite library.  The routines in this file
 66447  66427   ** implement the programmer interface to the library.  Routines in
 66448  66428   ** other files are for internal use by SQLite and should not be
 66449  66429   ** accessed by users of the library.
 66450  66430   **
 66451         -** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
        66431  +** $Id: sqlite3.c,v 1.5 2007/09/25 22:50:39 rmsimpson Exp $
 66452  66432   */
 66453  66433   
 66454  66434   /*
 66455  66435   ** The version of the library
 66456  66436   */
 66457         -const char sqlite3_version[] = SQLITE_VERSION;
        66437  +SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
 66458  66438   SQLITE_API const char *sqlite3_libversion(void){ return sqlite3_version; }
 66459         -int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
        66439  +SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
 66460  66440   
 66461  66441   /*
 66462  66442   ** If the following function pointer is not NULL and if
 66463  66443   ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
 66464  66444   ** I/O active are written using this function.  These messages
 66465  66445   ** are intended for debugging activity only.
 66466  66446   */
 66467         -void (*sqlite3_io_trace)(const char*, ...) = 0;
        66447  +SQLITE_API void (*sqlite3_io_trace)(const char*, ...) = 0;
 66468  66448   
 66469  66449   /*
 66470  66450   ** If the following global variable points to a string which is the
 66471  66451   ** name of a directory, then that directory will be used to store
 66472  66452   ** temporary files.
 66473  66453   **
 66474  66454   ** See also the "PRAGMA temp_store_directory" SQL command.
 66475  66455   */
 66476         -char *sqlite3_temp_directory = 0;
        66456  +SQLITE_API char *sqlite3_temp_directory = 0;
 66477  66457   
 66478  66458   
 66479  66459   /*
 66480  66460   ** This is the default collating function named "BINARY" which is always
 66481  66461   ** available.
 66482  66462   */
 66483  66463   static int binCollFunc(
................................................................................
 66515  66495     }
 66516  66496     return r;
 66517  66497   }
 66518  66498   
 66519  66499   /*
 66520  66500   ** Return the ROWID of the most recent insert
 66521  66501   */
 66522         -sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
        66502  +SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
 66523  66503     return db->lastRowid;
 66524  66504   }
 66525  66505   
 66526  66506   /*
 66527  66507   ** Return the number of changes in the most recent call to sqlite3_exec().
 66528  66508   */
 66529  66509   SQLITE_API int sqlite3_changes(sqlite3 *db){
 66530  66510     return db->nChange;
 66531  66511   }
 66532  66512   
 66533  66513   /*
 66534  66514   ** Return the number of changes since the database handle was opened.
 66535  66515   */
 66536         -int sqlite3_total_changes(sqlite3 *db){
        66516  +SQLITE_API int sqlite3_total_changes(sqlite3 *db){
 66537  66517     return db->nTotalChange;
 66538  66518   }
 66539  66519   
 66540  66520   /*
 66541  66521   ** Close an existing SQLite database
 66542  66522   */
 66543  66523   SQLITE_API int sqlite3_close(sqlite3 *db){
................................................................................
 66667  66647         }
 66668  66648         sqlite3BtreeRollback(db->aDb[i].pBt);
 66669  66649         db->aDb[i].inTrans = 0;
 66670  66650       }
 66671  66651     }
 66672  66652     sqlite3VtabRollback(db);
 66673  66653     if( db->flags&SQLITE_InternChanges ){
        66654  +    sqlite3ExpirePreparedStatements(db);
 66674  66655       sqlite3ResetInternalSchema(db, 0);
 66675  66656     }
 66676  66657   
 66677  66658     /* If one has been configured, invoke the rollback-hook callback */
 66678  66659     if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
 66679  66660       db->xRollbackCallback(db->pRollbackArg);
 66680  66661     }
................................................................................
 66780  66761     return rc; 
 66781  66762   }
 66782  66763   
 66783  66764   /*
 66784  66765   ** This routine sets the busy callback for an Sqlite database to the
 66785  66766   ** given callback function with the given argument.
 66786  66767   */
 66787         -int sqlite3_busy_handler(
        66768  +SQLITE_API int sqlite3_busy_handler(
 66788  66769     sqlite3 *db,
 66789  66770     int (*xBusy)(void*,int),
 66790  66771     void *pArg
 66791  66772   ){
 66792  66773     if( sqlite3SafetyCheck(db) ){
 66793  66774       return SQLITE_MISUSE;
 66794  66775     }
................................................................................
 66800  66781   
 66801  66782   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
 66802  66783   /*
 66803  66784   ** This routine sets the progress callback for an Sqlite database to the
 66804  66785   ** given callback function with the given argument. The progress callback will
 66805  66786   ** be invoked every nOps opcodes.
 66806  66787   */
 66807         -void sqlite3_progress_handler(
        66788  +SQLITE_API void sqlite3_progress_handler(
 66808  66789     sqlite3 *db, 
 66809  66790     int nOps,
 66810  66791     int (*xProgress)(void*), 
 66811  66792     void *pArg
 66812  66793   ){
 66813  66794     if( !sqlite3SafetyCheck(db) ){
 66814  66795       if( nOps>0 ){
................................................................................
 66825  66806   #endif
 66826  66807   
 66827  66808   
 66828  66809   /*
 66829  66810   ** This routine installs a default busy handler that waits for the
 66830  66811   ** specified number of milliseconds before returning 0.
 66831  66812   */
 66832         -int sqlite3_busy_timeout(sqlite3 *db, int ms){
        66813  +SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
 66833  66814     if( sqlite3SafetyCheck(db) ){
 66834  66815       return SQLITE_MISUSE;
 66835  66816     }
 66836  66817     if( ms>0 ){
 66837  66818       db->busyTimeout = ms;
 66838  66819       sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
 66839  66820     }else{
................................................................................
 66960  66941     }
 66961  66942     return SQLITE_OK;
 66962  66943   }
 66963  66944   
 66964  66945   /*
 66965  66946   ** Create new user functions.
 66966  66947   */
 66967         -int sqlite3_create_function(
        66948  +SQLITE_API int sqlite3_create_function(
 66968  66949     sqlite3 *db,
 66969  66950     const char *zFunctionName,
 66970  66951     int nArg,
 66971  66952     int enc,
 66972  66953     void *p,
 66973  66954     void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
 66974  66955     void (*xStep)(sqlite3_context*,int,sqlite3_value **),
................................................................................
 66978  66959     assert( !sqlite3MallocFailed() );
 66979  66960     rc = sqlite3CreateFunc(db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal);
 66980  66961   
 66981  66962     return sqlite3ApiExit(db, rc);
 66982  66963   }
 66983  66964   
 66984  66965   #ifndef SQLITE_OMIT_UTF16
 66985         -int sqlite3_create_function16(
        66966  +SQLITE_API int sqlite3_create_function16(
 66986  66967     sqlite3 *db,
 66987  66968     const void *zFunctionName,
 66988  66969     int nArg,
 66989  66970     int eTextRep,
 66990  66971     void *p,
 66991  66972     void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
 66992  66973     void (*xStep)(sqlite3_context*,int,sqlite3_value**),
................................................................................
 67013  66994   ** a new one that always throws a run-time error.  
 67014  66995   **
 67015  66996   ** When virtual tables intend to provide an overloaded function, they
 67016  66997   ** should call this routine to make sure the global function exists.
 67017  66998   ** A global function must exist in order for name resolution to work
 67018  66999   ** properly.
 67019  67000   */
 67020         -int sqlite3_overload_function(
        67001  +SQLITE_API int sqlite3_overload_function(
 67021  67002     sqlite3 *db,
 67022  67003     const char *zName,
 67023  67004     int nArg
 67024  67005   ){
 67025  67006     int nName = strlen(zName);
 67026  67007     if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
 67027  67008       sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
................................................................................
 67067  67048   
 67068  67049   /*** EXPERIMENTAL ***
 67069  67050   **
 67070  67051   ** Register a function to be invoked when a transaction comments.
 67071  67052   ** If the invoked function returns non-zero, then the commit becomes a
 67072  67053   ** rollback.
 67073  67054   */
 67074         -void *sqlite3_commit_hook(
        67055  +SQLITE_API void *sqlite3_commit_hook(
 67075  67056     sqlite3 *db,              /* Attach the hook to this database */
 67076  67057     int (*xCallback)(void*),  /* Function to invoke on each commit */
 67077  67058     void *pArg                /* Argument to the function */
 67078  67059   ){
 67079  67060     void *pOld = db->pCommitArg;
 67080  67061     db->xCommitCallback = xCallback;
 67081  67062     db->pCommitArg = pArg;
................................................................................
 67082  67063     return pOld;
 67083  67064   }
 67084  67065   
 67085  67066   /*
 67086  67067   ** Register a callback to be invoked each time a row is updated,
 67087  67068   ** inserted or deleted using this database connection.
 67088  67069   */
 67089         -void *sqlite3_update_hook(
        67070  +SQLITE_API void *sqlite3_update_hook(
 67090  67071     sqlite3 *db,              /* Attach the hook to this database */
 67091  67072     void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
 67092  67073     void *pArg                /* Argument to the function */
 67093  67074   ){
 67094  67075     void *pRet = db->pUpdateArg;
 67095  67076     db->xUpdateCallback = xCallback;
 67096  67077     db->pUpdateArg = pArg;
................................................................................
 67097  67078     return pRet;
 67098  67079   }
 67099  67080   
 67100  67081   /*
 67101  67082   ** Register a callback to be invoked each time a transaction is rolled
 67102  67083   ** back by this database connection.
 67103  67084   */
 67104         -void *sqlite3_rollback_hook(
        67085  +SQLITE_API void *sqlite3_rollback_hook(
 67105  67086     sqlite3 *db,              /* Attach the hook to this database */
 67106  67087     void (*xCallback)(void*), /* Callback function */
 67107  67088     void *pArg                /* Argument to the function */
 67108  67089   ){
 67109  67090     void *pRet = db->pRollbackArg;
 67110  67091     db->xRollbackCallback = xCallback;
 67111  67092     db->pRollbackArg = pArg;
................................................................................
 67563  67544     }
 67564  67545     return rc;
 67565  67546   }
 67566  67547   
 67567  67548   /*
 67568  67549   ** Register a new collation sequence with the database handle db.
 67569  67550   */
 67570         -int sqlite3_create_collation(
        67551  +SQLITE_API int sqlite3_create_collation(
 67571  67552     sqlite3* db, 
 67572  67553     const char *zName, 
 67573  67554     int enc, 
 67574  67555     void* pCtx,
 67575  67556     int(*xCompare)(void*,int,const void*,int,const void*)
 67576  67557   ){
 67577  67558     int rc;
................................................................................
 67579  67560     rc = createCollation(db, zName, enc, pCtx, xCompare, 0);
 67580  67561     return sqlite3ApiExit(db, rc);
 67581  67562   }
 67582  67563   
 67583  67564   /*
 67584  67565   ** Register a new collation sequence with the database handle db.
 67585  67566   */
 67586         -int sqlite3_create_collation_v2(
        67567  +SQLITE_API int sqlite3_create_collation_v2(
 67587  67568     sqlite3* db, 
 67588  67569     const char *zName, 
 67589  67570     int enc, 
 67590  67571     void* pCtx,
 67591  67572     int(*xCompare)(void*,int,const void*,int,const void*),
 67592  67573     void(*xDel)(void*)
 67593  67574   ){
................................................................................
 67597  67578     return sqlite3ApiExit(db, rc);
 67598  67579   }
 67599  67580   
 67600  67581   #ifndef SQLITE_OMIT_UTF16
 67601  67582   /*
 67602  67583   ** Register a new collation sequence with the database handle db.
 67603  67584   */
 67604         -int sqlite3_create_collation16(
        67585  +SQLITE_API int sqlite3_create_collation16(
 67605  67586     sqlite3* db, 
 67606  67587     const char *zName, 
 67607  67588     int enc, 
 67608  67589     void* pCtx,
 67609  67590     int(*xCompare)(void*,int,const void*,int,const void*)
 67610  67591   ){
 67611  67592     int rc = SQLITE_OK;
................................................................................
 67620  67601   }
 67621  67602   #endif /* SQLITE_OMIT_UTF16 */
 67622  67603   
 67623  67604   /*
 67624  67605   ** Register a collation sequence factory callback with the database handle
 67625  67606   ** db. Replace any previously installed collation sequence factory.
 67626  67607   */
 67627         -int sqlite3_collation_needed(
        67608  +SQLITE_API int sqlite3_collation_needed(
 67628  67609     sqlite3 *db, 
 67629  67610     void *pCollNeededArg, 
 67630  67611     void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
 67631  67612   ){
 67632  67613     if( sqlite3SafetyCheck(db) ){
 67633  67614       return SQLITE_MISUSE;
 67634  67615     }
................................................................................
 67639  67620   }
 67640  67621   
 67641  67622   #ifndef SQLITE_OMIT_UTF16
 67642  67623   /*
 67643  67624   ** Register a collation sequence factory callback with the database handle
 67644  67625   ** db. Replace any previously installed collation sequence factory.
 67645  67626   */
 67646         -int sqlite3_collation_needed16(
        67627  +SQLITE_API int sqlite3_collation_needed16(
 67647  67628     sqlite3 *db, 
 67648  67629     void *pCollNeededArg, 
 67649  67630     void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
 67650  67631   ){
 67651  67632     if( sqlite3SafetyCheck(db) ){
 67652  67633       return SQLITE_MISUSE;
 67653  67634     }
................................................................................
 67659  67640   #endif /* SQLITE_OMIT_UTF16 */
 67660  67641   
 67661  67642   #ifndef SQLITE_OMIT_GLOBALRECOVER
 67662  67643   /*
 67663  67644   ** This function is now an anachronism. It used to be used to recover from a
 67664  67645   ** malloc() failure, but SQLite now does this automatically.
 67665  67646   */
 67666         -int sqlite3_global_recover(){
        67647  +SQLITE_API int sqlite3_global_recover(){
 67667  67648     return SQLITE_OK;
 67668  67649   }
 67669  67650   #endif
 67670  67651   
 67671  67652   /*
 67672  67653   ** Test to see whether or not the database connection is in autocommit
 67673  67654   ** mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
 67674  67655   ** by default.  Autocommit is disabled by a BEGIN statement and reenabled
 67675  67656   ** by the next COMMIT or ROLLBACK.
 67676  67657   **
 67677  67658   ******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
 67678  67659   */
 67679         -int sqlite3_get_autocommit(sqlite3 *db){
        67660  +SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
 67680  67661     return db->autoCommit;
 67681  67662   }
 67682  67663   
 67683  67664   #ifdef SQLITE_DEBUG
 67684  67665   /*
 67685  67666   ** The following routine is subtituted for constant SQLITE_CORRUPT in
 67686  67667   ** debugging builds.  This provides a way to set a breakpoint for when
................................................................................
 67696  67677   /*
 67697  67678   ** Enable or disable the shared pager and schema features for the
 67698  67679   ** current thread.
 67699  67680   **
 67700  67681   ** This routine should only be called when there are no open
 67701  67682   ** database connections.
 67702  67683   */
 67703         -int sqlite3_enable_shared_cache(int enable){
        67684  +SQLITE_API int sqlite3_enable_shared_cache(int enable){
 67704  67685     ThreadData *pTd = sqlite3ThreadData();
 67705  67686     if( pTd ){
 67706  67687       /* It is only legal to call sqlite3_enable_shared_cache() when there
 67707  67688       ** are no currently open b-trees that were opened by the calling thread.
 67708  67689       ** This condition is only easy to detect if the shared-cache were 
 67709  67690       ** previously enabled (and is being disabled). 
 67710  67691       */
................................................................................
 67720  67701   }
 67721  67702   #endif
 67722  67703   
 67723  67704   /*
 67724  67705   ** This is a convenience routine that makes sure that all thread-specific
 67725  67706   ** data for this thread has been deallocated.
 67726  67707   */
 67727         -void sqlite3_thread_cleanup(void){
        67708  +SQLITE_API void sqlite3_thread_cleanup(void){
 67728  67709     ThreadData *pTd = sqlite3OsThreadSpecificData(0);
 67729  67710     if( pTd ){
 67730  67711       memset(pTd, 0, sizeof(*pTd));
 67731  67712       sqlite3OsThreadSpecificData(-1);
 67732  67713     }
 67733  67714   }
 67734  67715   
 67735  67716   /*
 67736  67717   ** Return meta information about a specific column of a database table.
 67737  67718   ** See comment in sqlite3.h (sqlite.h.in) for details.
 67738  67719   */
 67739  67720   #ifdef SQLITE_ENABLE_COLUMN_METADATA
 67740         -int sqlite3_table_column_metadata(
        67721  +SQLITE_API int sqlite3_table_column_metadata(
 67741  67722     sqlite3 *db,                /* Connection handle */
 67742  67723     const char *zDbName,        /* Database name or NULL */
 67743  67724     const char *zTableName,     /* Table name */
 67744  67725     const char *zColumnName,    /* Column name */
 67745  67726     char const **pzDataType,    /* OUTPUT: Declared data type */
 67746  67727     char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
 67747  67728     int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
................................................................................
 67844  67825     return sqlite3ApiExit(db, rc);
 67845  67826   }
 67846  67827   #endif
 67847  67828   
 67848  67829   /*
 67849  67830   ** Set all the parameters in the compiled SQL statement to NULL.
 67850  67831   */
 67851         -int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
        67832  +SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
 67852  67833     int i;
 67853  67834     int rc = SQLITE_OK;
 67854  67835     for(i=1; rc==SQLITE_OK && i<=sqlite3_bind_parameter_count(pStmt); i++){
 67855  67836       rc = sqlite3_bind_null(pStmt, i);
 67856  67837     }
 67857  67838     return rc;
 67858  67839   }
................................................................................
 67863  67844   SQLITE_API int sqlite3_sleep(int ms){
 67864  67845     return sqlite3OsSleep(ms);
 67865  67846   }
 67866  67847   
 67867  67848   /*
 67868  67849   ** Enable or disable the extended result codes.
 67869  67850   */
 67870         -int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
        67851  +SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
 67871  67852     db->errMask = onoff ? 0xffffffff : 0xff;
 67872  67853     return SQLITE_OK;
 67873  67854   }
 67874  67855   
 67875  67856   /************** End of main.c ************************************************/

Changes to SQLite.Interop/src/sqlite3.h.

    26     26   ** on how SQLite interfaces are suppose to operate.
    27     27   **
    28     28   ** The name of this file under configuration management is "sqlite.h.in".
    29     29   ** The makefile makes some minor changes to this file (such as inserting
    30     30   ** the version number) and changes its name to "sqlite3.h" as
    31     31   ** part of the build process.
    32     32   **
    33         -** @(#) $Id: sqlite3.h,v 1.31 2007/07/21 08:51:43 rmsimpson Exp $
           33  +** @(#) $Id: sqlite3.h,v 1.32 2007/09/25 22:50:40 rmsimpson Exp $
    34     34   */
    35     35   #ifndef _SQLITE3_H_
    36     36   #define _SQLITE3_H_
    37     37   #include <stdarg.h>     /* Needed for the definition of va_list */
    38     38   
    39     39   /*
    40     40   ** Make sure we can call this stuff from C++.
    41     41   */
    42     42   #ifdef __cplusplus
    43     43   extern "C" {
    44     44   #endif
    45     45   
           46  +/*
           47  +** Add the ability to override 'extern'
           48  +*/
           49  +#ifndef SQLITE_EXTERN
           50  +# define SQLITE_EXTERN extern
           51  +#endif
           52  +
    46     53   /*
    47     54   ** Make sure these symbols where not defined by some previous header
    48     55   ** file.
    49     56   */
    50     57   #ifdef SQLITE_VERSION
    51     58   # undef SQLITE_VERSION
    52     59   #endif
................................................................................
    77     84   ** (X*1000000 + Y*1000 + Z). For example, for version "3.1.1beta", 
    78     85   ** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using 
    79     86   ** version 3.1.1 or greater at compile time, programs may use the test 
    80     87   ** (SQLITE_VERSION_NUMBER>=3001001).
    81     88   **
    82     89   ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
    83     90   */
    84         -#define SQLITE_VERSION         "3.4.1"
    85         -#define SQLITE_VERSION_NUMBER 3004001
           91  +#define SQLITE_VERSION         "3.4.2"
           92  +#define SQLITE_VERSION_NUMBER 3004002
    86     93   
    87     94   /*
    88     95   ** CAPI3REF: Run-Time Library Version Numbers
    89     96   **
    90     97   ** These routines return values equivalent to the header constants
    91     98   ** [SQLITE_VERSION] and [SQLITE_VERSION_NUMBER].  The values returned
    92     99   ** by this routines should only be different from the header values
................................................................................
    96    103   **
    97    104   ** The sqlite3_version[] string constant contains the text of the
    98    105   ** [SQLITE_VERSION] string.  The sqlite3_libversion() function returns
    99    106   ** a poiner to the sqlite3_version[] string constant.  The function
   100    107   ** is provided for DLL users who can only access functions and not
   101    108   ** constants within the DLL.
   102    109   */
   103         -extern const char sqlite3_version[];
          110  +SQLITE_EXTERN const char sqlite3_version[];
   104    111   const char *sqlite3_libversion(void);
   105    112   int sqlite3_libversion_number(void);
   106    113   
   107    114   /*
   108    115   ** CAPI3REF: Database Connection Handle
   109    116   **
   110    117   ** Each open SQLite database is represented by pointer to an instance of the
................................................................................
  2016   2023   ** file directory.
  2017   2024   **
  2018   2025   ** Once [sqlite3_open()] has been called, changing this variable will
  2019   2026   ** invalidate the current temporary database, if any.  Generally speaking,
  2020   2027   ** it is not safe to invoke this routine after [sqlite3_open()] has
  2021   2028   ** been called.
  2022   2029   */
  2023         -extern char *sqlite3_temp_directory;
         2030  +SQLITE_EXTERN char *sqlite3_temp_directory;
  2024   2031   
  2025   2032   /*
  2026   2033   ** CAPI3REF:  Test To See If The Databse Is In Auto-Commit Mode
  2027   2034   **
  2028   2035   ** Test to see whether or not the database connection is in autocommit
  2029   2036   ** mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
  2030   2037   ** by default.  Autocommit is disabled by a BEGIN statement and reenabled