System.Data.SQLite
Check-in [b10b90ef08]
Not logged in

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

Overview
Comment:Update SQLite core library to the latest trunk code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b10b90ef08d6252d3f3835d542f11a59a03d63d1
User & Date: mistachkin 2016-07-30 18:40:03
Context
2016-07-30
18:43
The Mono batch build tool should honor the BUILD_DEBUG environment variable. check-in: 068edf42f2 user: mistachkin tags: trunk
18:40
Update SQLite core library to the latest trunk code. check-in: b10b90ef08 user: mistachkin tags: trunk
2016-07-22
22:21
Update version history docs. check-in: eb23ed0cb0 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Doc/Extra/Provider/version.html.

    41     41         </table>
    42     42       </div>
    43     43       <div id="mainSection">
    44     44       <div id="mainBody">
    45     45       <h1 class="heading">Version History</h1>
    46     46       <p><b>1.0.103.0 - August XX, 2016 <font color="red">(release scheduled)</font></b></p>
    47     47       <ul>
           48  +      <li>Updated to <a href="https://www.sqlite.org/draft/releaselog/3_14_0.html">SQLite 3.14.0</a>.</li>
    48     49         <li>Change the SQLiteReadValueCallback delegate &quot;eventArgs&quot; parameter to be of type SQLiteReadEventArgs.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    49     50         <li>Make SQLiteReadValueEventArgs and SQLiteReadArrayEventArgs derive from SQLiteReadEventArgs.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    50     51         <li>Rename SQLiteReadValueEventArgs.ArrayEventArgs property to ExtraEventArgs.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    51     52         <li>Add No_SQLiteGetSettingValue and No_SQLiteXmlConfigFile environment variables.</li>
    52     53         <li>Reduce the number of calls to GetSettingValue from SQLiteConnection. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/25d53b48f6">[25d53b48f6]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    53     54         <li>Add NoVerifyTypeAffinity connection flag to disable all type affinity checking.</li>
    54     55         <li>Add support for <a href="https://www.sqlite.org/c3ref/blob_open.html">incremental blob I/O</a>.</li>

Changes to SQLite.Interop/props/sqlite3.props.

     5      5    *
     6      6    * Written by Joe Mistachkin.
     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    11     11     <PropertyGroup Label="UserMacros">
    12         -    <SQLITE_MANIFEST_VERSION>3.13.0.0</SQLITE_MANIFEST_VERSION>
    13         -    <SQLITE_RC_VERSION>3,13,0,0</SQLITE_RC_VERSION>
           12  +    <SQLITE_MANIFEST_VERSION>3.14.0.0</SQLITE_MANIFEST_VERSION>
           13  +    <SQLITE_RC_VERSION>3,14,0,0</SQLITE_RC_VERSION>
    14     14       <SQLITE_COMMON_DEFINES>_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT4=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1;SQLITE_ENABLE_API_ARMOR=1;SQLITE_ENABLE_DBSTAT_VTAB=1</SQLITE_COMMON_DEFINES>
    15     15       <SQLITE_EXTRA_DEFINES>SQLITE_PLACEHOLDER=1;SQLITE_HAS_CODEC=1</SQLITE_EXTRA_DEFINES>
    16     16       <SQLITE_WINCE_200X_DEFINES>SQLITE_OMIT_WAL=1</SQLITE_WINCE_200X_DEFINES>
    17     17       <SQLITE_WINCE_2013_DEFINES>HAVE_ERRNO_H=1;SQLITE_MSVC_LOCALTIME_API=1</SQLITE_WINCE_2013_DEFINES>
    18     18       <SQLITE_DEBUG_DEFINES>SQLITE_DEBUG=1;SQLITE_MEMDEBUG=1;SQLITE_ENABLE_EXPENSIVE_ASSERT=1</SQLITE_DEBUG_DEFINES>
    19     19       <SQLITE_RELEASE_DEFINES>SQLITE_WIN32_MALLOC=1</SQLITE_RELEASE_DEFINES>
    20     20       <SQLITE_DISABLE_WARNINGS>4055;4100;4127;4146;4210;4232;4244;4245;4267;4306;4389;4701;4703;4706</SQLITE_DISABLE_WARNINGS>

Changes to SQLite.Interop/props/sqlite3.vsprops.

    10     10   <VisualStudioPropertySheet
    11     11   	ProjectType="Visual C++"
    12     12   	Version="8.00"
    13     13   	Name="sqlite3"
    14     14   	>
    15     15   	<UserMacro
    16     16   		Name="SQLITE_MANIFEST_VERSION"
    17         -		Value="3.13.0.0"
           17  +		Value="3.14.0.0"
    18     18   		PerformEnvironmentSet="true"
    19     19   	/>
    20     20   	<UserMacro
    21     21   		Name="SQLITE_RC_VERSION"
    22         -		Value="3,13,0,0"
           22  +		Value="3,14,0,0"
    23     23   		PerformEnvironmentSet="true"
    24     24   	/>
    25     25   	<UserMacro
    26     26   		Name="SQLITE_COMMON_DEFINES"
    27     27   		Value="_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT4=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1;SQLITE_ENABLE_API_ARMOR=1;SQLITE_ENABLE_DBSTAT_VTAB=1"
    28     28   		PerformEnvironmentSet="true"
    29     29   	/>

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

     1      1   /******************************************************************************
     2      2   ** This file is an amalgamation of many separate C source files from SQLite
     3         -** version 3.13.0.  By combining all the individual C code files into this 
            3  +** version 3.14.0.  By combining all the individual C code files into this 
     4      4   ** single large file, the entire code can be compiled as a single 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% or 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
................................................................................
    33     33   **    May you find forgiveness for yourself and forgive others.
    34     34   **    May you share freely, never taking more than you give.
    35     35   **
    36     36   *************************************************************************
    37     37   ** Internal interface definitions for SQLite.
    38     38   **
    39     39   */
    40         -#ifndef _SQLITEINT_H_
    41         -#define _SQLITEINT_H_
           40  +#ifndef SQLITEINT_H
           41  +#define SQLITEINT_H
    42     42   
    43     43   /* Special Comments:
    44     44   **
    45     45   ** Some comments have special meaning to the tools that measure test
    46     46   ** coverage:
    47     47   **
    48     48   **    NO_TEST                     - The branches on this line are not
................................................................................
    63     63   **                                  if it did occur.  
    64     64   **
    65     65   ** In all cases, the special comment must be enclosed in the usual
    66     66   ** slash-asterisk...asterisk-slash comment marks, with no spaces between the 
    67     67   ** asterisks and the comment text.
    68     68   */
    69     69   
           70  +/*
           71  +** Make sure the Tcl calling convention macro is defined.  This macro is
           72  +** only used by test code and Tcl integration code.
           73  +*/
           74  +#ifndef SQLITE_TCLAPI
           75  +#  define SQLITE_TCLAPI
           76  +#endif
           77  +
    70     78   /*
    71     79   ** Make sure that rand_s() is available on Windows systems with MSVC 2005
    72     80   ** or higher.
    73     81   */
    74     82   #if defined(_MSC_VER) && _MSC_VER>=1400
    75     83   #  define _CRT_RAND_S
    76     84   #endif
................................................................................
    93    101   **    May you find forgiveness for yourself and forgive others.
    94    102   **    May you share freely, never taking more than you give.
    95    103   **
    96    104   ******************************************************************************
    97    105   **
    98    106   ** This file contains code that is specific to MSVC.
    99    107   */
   100         -#ifndef _MSVC_H_
   101         -#define _MSVC_H_
          108  +#ifndef SQLITE_MSVC_H
          109  +#define SQLITE_MSVC_H
   102    110   
   103    111   #if defined(_MSC_VER)
   104    112   #pragma warning(disable : 4054)
   105    113   #pragma warning(disable : 4055)
   106    114   #pragma warning(disable : 4100)
   107    115   #pragma warning(disable : 4127)
   108    116   #pragma warning(disable : 4130)
................................................................................
   114    122   #pragma warning(disable : 4244)
   115    123   #pragma warning(disable : 4305)
   116    124   #pragma warning(disable : 4306)
   117    125   #pragma warning(disable : 4702)
   118    126   #pragma warning(disable : 4706)
   119    127   #endif /* defined(_MSC_VER) */
   120    128   
   121         -#endif /* _MSVC_H_ */
          129  +#endif /* SQLITE_MSVC_H */
   122    130   
   123    131   /************** End of msvc.h ************************************************/
   124    132   /************** Continuing where we left off in sqliteInt.h ******************/
   125    133   
   126    134   /*
   127    135   ** Special setup for VxWorks
   128    136   */
................................................................................
   278    286   ** on how SQLite interfaces are supposed to operate.
   279    287   **
   280    288   ** The name of this file under configuration management is "sqlite.h.in".
   281    289   ** The makefile makes some minor changes to this file (such as inserting
   282    290   ** the version number) and changes its name to "sqlite3.h" as
   283    291   ** part of the build process.
   284    292   */
   285         -#ifndef _SQLITE3_H_
   286         -#define _SQLITE3_H_
          293  +#ifndef SQLITE3_H
          294  +#define SQLITE3_H
   287    295   #include <stdarg.h>     /* Needed for the definition of va_list */
   288    296   
   289    297   /*
   290    298   ** Make sure we can call this stuff from C++.
   291    299   */
   292    300   #if 0
   293    301   extern "C" {
................................................................................
   302    310   #endif
   303    311   #ifndef SQLITE_API
   304    312   # define SQLITE_API
   305    313   #endif
   306    314   #ifndef SQLITE_CDECL
   307    315   # define SQLITE_CDECL
   308    316   #endif
          317  +#ifndef SQLITE_APICALL
          318  +# define SQLITE_APICALL
          319  +#endif
   309    320   #ifndef SQLITE_STDCALL
   310         -# define SQLITE_STDCALL
          321  +# define SQLITE_STDCALL SQLITE_APICALL
          322  +#endif
          323  +#ifndef SQLITE_CALLBACK
          324  +# define SQLITE_CALLBACK
          325  +#endif
          326  +#ifndef SQLITE_SYSAPI
          327  +# define SQLITE_SYSAPI
   311    328   #endif
   312    329   
   313    330   /*
   314    331   ** These no-op macros are used in front of interfaces to mark those
   315    332   ** interfaces as either deprecated or experimental.  New applications
   316    333   ** should not use deprecated interfaces - they are supported for backwards
   317    334   ** compatibility only.  Application writers should be aware that
................................................................................
   359    376   ** string contains the date and time of the check-in (UTC) and an SHA1
   360    377   ** hash of the entire source tree.
   361    378   **
   362    379   ** See also: [sqlite3_libversion()],
   363    380   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   364    381   ** [sqlite_version()] and [sqlite_source_id()].
   365    382   */
   366         -#define SQLITE_VERSION        "3.13.0"
   367         -#define SQLITE_VERSION_NUMBER 3013000
   368         -#define SQLITE_SOURCE_ID      "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
          383  +#define SQLITE_VERSION        "3.14.0"
          384  +#define SQLITE_VERSION_NUMBER 3014000
          385  +#define SQLITE_SOURCE_ID      "2016-07-29 17:36:27 9fae75c08b7d3b3e13734193ad8398ef6971cbac"
   369    386   
   370    387   /*
   371    388   ** CAPI3REF: Run-Time Library Version Numbers
   372    389   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   373    390   **
   374    391   ** These interfaces provide the same information as the [SQLITE_VERSION],
   375    392   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   394    411   ** [SQLITE_VERSION_NUMBER].  ^The sqlite3_sourceid() function returns 
   395    412   ** a pointer to a string constant whose value is the same as the 
   396    413   ** [SQLITE_SOURCE_ID] C preprocessor macro.
   397    414   **
   398    415   ** See also: [sqlite_version()] and [sqlite_source_id()].
   399    416   */
   400    417   SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
   401         -SQLITE_API const char *SQLITE_STDCALL sqlite3_libversion(void);
   402         -SQLITE_API const char *SQLITE_STDCALL sqlite3_sourceid(void);
   403         -SQLITE_API int SQLITE_STDCALL sqlite3_libversion_number(void);
          418  +SQLITE_API const char *SQLITE_APICALL sqlite3_libversion(void);
          419  +SQLITE_API const char *SQLITE_APICALL sqlite3_sourceid(void);
          420  +SQLITE_API int SQLITE_APICALL sqlite3_libversion_number(void);
   404    421   
   405    422   /*
   406    423   ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
   407    424   **
   408    425   ** ^The sqlite3_compileoption_used() function returns 0 or 1 
   409    426   ** indicating whether the specified option was defined at 
   410    427   ** compile time.  ^The SQLITE_ prefix may be omitted from the 
................................................................................
   421    438   ** and sqlite3_compileoption_get() may be omitted by specifying the 
   422    439   ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
   423    440   **
   424    441   ** See also: SQL functions [sqlite_compileoption_used()] and
   425    442   ** [sqlite_compileoption_get()] and the [compile_options pragma].
   426    443   */
   427    444   #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
   428         -SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName);
   429         -SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N);
          445  +SQLITE_API int SQLITE_APICALL sqlite3_compileoption_used(const char *zOptName);
          446  +SQLITE_API const char *SQLITE_APICALL sqlite3_compileoption_get(int N);
   430    447   #endif
   431    448   
   432    449   /*
   433    450   ** CAPI3REF: Test To See If The Library Is Threadsafe
   434    451   **
   435    452   ** ^The sqlite3_threadsafe() function returns zero if and only if
   436    453   ** SQLite was compiled with mutexing code omitted due to the
................................................................................
   461    478   ** sqlite3_threadsafe() function shows only the compile-time setting of
   462    479   ** thread safety, not any run-time changes to that setting made by
   463    480   ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
   464    481   ** is unchanged by calls to sqlite3_config().)^
   465    482   **
   466    483   ** See the [threading mode] documentation for additional information.
   467    484   */
   468         -SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void);
          485  +SQLITE_API int SQLITE_APICALL sqlite3_threadsafe(void);
   469    486   
   470    487   /*
   471    488   ** CAPI3REF: Database Connection Handle
   472    489   ** KEYWORDS: {database connection} {database connections}
   473    490   **
   474    491   ** Each open SQLite database is represented by a pointer to an instance of
   475    492   ** the opaque structure named "sqlite3".  It is useful to think of an sqlite3
................................................................................
   558    575   ** must be either a NULL
   559    576   ** pointer or an [sqlite3] object pointer obtained
   560    577   ** from [sqlite3_open()], [sqlite3_open16()], or
   561    578   ** [sqlite3_open_v2()], and not previously closed.
   562    579   ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
   563    580   ** argument is a harmless no-op.
   564    581   */
   565         -SQLITE_API int SQLITE_STDCALL sqlite3_close(sqlite3*);
   566         -SQLITE_API int SQLITE_STDCALL sqlite3_close_v2(sqlite3*);
          582  +SQLITE_API int SQLITE_APICALL sqlite3_close(sqlite3*);
          583  +SQLITE_API int SQLITE_APICALL sqlite3_close_v2(sqlite3*);
   567    584   
   568    585   /*
   569    586   ** The type for a callback function.
   570    587   ** This is legacy and deprecated.  It is included for historical
   571    588   ** compatibility and is not documented.
   572    589   */
   573         -typedef int (*sqlite3_callback)(void*,int,char**, char**);
          590  +typedef int (SQLITE_CALLBACK *sqlite3_callback)(void*,int,char**, char**);
   574    591   
   575    592   /*
   576    593   ** CAPI3REF: One-Step Query Execution Interface
   577    594   ** METHOD: sqlite3
   578    595   **
   579    596   ** The sqlite3_exec() interface is a convenience wrapper around
   580    597   ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
................................................................................
   630    647   **      is a valid and open [database connection].
   631    648   ** <li> The application must not close the [database connection] specified by
   632    649   **      the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
   633    650   ** <li> The application must not modify the SQL statement text passed into
   634    651   **      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
   635    652   ** </ul>
   636    653   */
   637         -SQLITE_API int SQLITE_STDCALL sqlite3_exec(
          654  +SQLITE_API int SQLITE_APICALL sqlite3_exec(
   638    655     sqlite3*,                                  /* An open database */
   639    656     const char *sql,                           /* SQL to be evaluated */
   640         -  int (*callback)(void*,int,char**,char**),  /* Callback function */
          657  +  int (SQLITE_CALLBACK *callback)(void*,int,char**,char**),  /* Callback function */
   641    658     void *,                                    /* 1st argument to callback */
   642    659     char **errmsg                              /* Error msg written here */
   643    660   );
   644    661   
   645    662   /*
   646    663   ** CAPI3REF: Result Codes
   647    664   ** KEYWORDS: {result code definitions}
................................................................................
   754    771   #define SQLITE_CONSTRAINT_UNIQUE       (SQLITE_CONSTRAINT | (8<<8))
   755    772   #define SQLITE_CONSTRAINT_VTAB         (SQLITE_CONSTRAINT | (9<<8))
   756    773   #define SQLITE_CONSTRAINT_ROWID        (SQLITE_CONSTRAINT |(10<<8))
   757    774   #define SQLITE_NOTICE_RECOVER_WAL      (SQLITE_NOTICE | (1<<8))
   758    775   #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
   759    776   #define SQLITE_WARNING_AUTOINDEX       (SQLITE_WARNING | (1<<8))
   760    777   #define SQLITE_AUTH_USER               (SQLITE_AUTH | (1<<8))
          778  +#define SQLITE_OK_LOAD_PERMANENTLY     (SQLITE_OK | (1<<8))
   761    779   
   762    780   /*
   763    781   ** CAPI3REF: Flags For File Open Operations
   764    782   **
   765    783   ** These bit values are intended for use in the
   766    784   ** 3rd parameter to the [sqlite3_open_v2()] interface and
   767    785   ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
................................................................................
   980    998   ** fails to zero-fill short reads might seem to work.  However,
   981    999   ** failure to zero-fill short reads will eventually lead to
   982   1000   ** database corruption.
   983   1001   */
   984   1002   typedef struct sqlite3_io_methods sqlite3_io_methods;
   985   1003   struct sqlite3_io_methods {
   986   1004     int iVersion;
   987         -  int (*xClose)(sqlite3_file*);
   988         -  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
   989         -  int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
   990         -  int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
   991         -  int (*xSync)(sqlite3_file*, int flags);
   992         -  int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
   993         -  int (*xLock)(sqlite3_file*, int);
   994         -  int (*xUnlock)(sqlite3_file*, int);
   995         -  int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
   996         -  int (*xFileControl)(sqlite3_file*, int op, void *pArg);
   997         -  int (*xSectorSize)(sqlite3_file*);
   998         -  int (*xDeviceCharacteristics)(sqlite3_file*);
         1005  +  int (SQLITE_CALLBACK *xClose)(sqlite3_file*);
         1006  +  int (SQLITE_CALLBACK *xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
         1007  +  int (SQLITE_CALLBACK *xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
         1008  +  int (SQLITE_CALLBACK *xTruncate)(sqlite3_file*, sqlite3_int64 size);
         1009  +  int (SQLITE_CALLBACK *xSync)(sqlite3_file*, int flags);
         1010  +  int (SQLITE_CALLBACK *xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
         1011  +  int (SQLITE_CALLBACK *xLock)(sqlite3_file*, int);
         1012  +  int (SQLITE_CALLBACK *xUnlock)(sqlite3_file*, int);
         1013  +  int (SQLITE_CALLBACK *xCheckReservedLock)(sqlite3_file*, int *pResOut);
         1014  +  int (SQLITE_CALLBACK *xFileControl)(sqlite3_file*, int op, void *pArg);
         1015  +  int (SQLITE_CALLBACK *xSectorSize)(sqlite3_file*);
         1016  +  int (SQLITE_CALLBACK *xDeviceCharacteristics)(sqlite3_file*);
   999   1017     /* Methods above are valid for version 1 */
  1000         -  int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
  1001         -  int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
  1002         -  void (*xShmBarrier)(sqlite3_file*);
  1003         -  int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
         1018  +  int (SQLITE_CALLBACK *xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
         1019  +  int (SQLITE_CALLBACK *xShmLock)(sqlite3_file*, int offset, int n, int flags);
         1020  +  void (SQLITE_CALLBACK *xShmBarrier)(sqlite3_file*);
         1021  +  int (SQLITE_CALLBACK *xShmUnmap)(sqlite3_file*, int deleteFlag);
  1004   1022     /* Methods above are valid for version 2 */
  1005         -  int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
  1006         -  int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
         1023  +  int (SQLITE_CALLBACK *xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
         1024  +  int (SQLITE_CALLBACK *xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
  1007   1025     /* Methods above are valid for version 3 */
  1008   1026     /* Additional methods may be added in future releases */
  1009   1027   };
  1010   1028   
  1011   1029   /*
  1012   1030   ** CAPI3REF: Standard File Control Opcodes
  1013   1031   ** KEYWORDS: {file control opcodes} {file control opcode}
................................................................................
  1175   1193   **
  1176   1194   ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
  1177   1195   ** ^The [SQLITE_FCNTL_BUSYHANDLER]
  1178   1196   ** file-control may be invoked by SQLite on the database file handle
  1179   1197   ** shortly after it is opened in order to provide a custom VFS with access
  1180   1198   ** to the connections busy-handler callback. The argument is of type (void **)
  1181   1199   ** - an array of two (void *) values. The first (void *) actually points
  1182         -** to a function of type (int (*)(void *)). In order to invoke the connections
         1200  +** to a function of type (int (SQLITE_CALLBACK *)(void *)). In order to invoke the connections
  1183   1201   ** busy-handler, this function should be invoked with the second (void *) in
  1184   1202   ** the array as the only argument. If it returns non-zero, then the operation
  1185   1203   ** should be retried. If it returns zero, the custom VFS should abandon the
  1186   1204   ** current operation.
  1187   1205   **
  1188   1206   ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
  1189   1207   ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
................................................................................
  1441   1459   ** varies from one VFS to another, and from one version of the same VFS to the
  1442   1460   ** next.  Applications that use these interfaces must be prepared for any
  1443   1461   ** or all of these interfaces to be NULL or for their behavior to change
  1444   1462   ** from one release to the next.  Applications must not attempt to access
  1445   1463   ** any of these methods if the iVersion of the VFS is less than 3.
  1446   1464   */
  1447   1465   typedef struct sqlite3_vfs sqlite3_vfs;
  1448         -typedef void (*sqlite3_syscall_ptr)(void);
         1466  +typedef void (SQLITE_SYSAPI *sqlite3_syscall_ptr)(void);
  1449   1467   struct sqlite3_vfs {
  1450   1468     int iVersion;            /* Structure version number (currently 3) */
  1451   1469     int szOsFile;            /* Size of subclassed sqlite3_file */
  1452   1470     int mxPathname;          /* Maximum file pathname length */
  1453   1471     sqlite3_vfs *pNext;      /* Next registered VFS */
  1454   1472     const char *zName;       /* Name of this virtual file system */
  1455   1473     void *pAppData;          /* Pointer to application-specific data */
  1456         -  int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
         1474  +  int (SQLITE_CALLBACK *xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
  1457   1475                  int flags, int *pOutFlags);
  1458         -  int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  1459         -  int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  1460         -  int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  1461         -  void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  1462         -  void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  1463         -  void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  1464         -  void (*xDlClose)(sqlite3_vfs*, void*);
  1465         -  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  1466         -  int (*xSleep)(sqlite3_vfs*, int microseconds);
  1467         -  int (*xCurrentTime)(sqlite3_vfs*, double*);
  1468         -  int (*xGetLastError)(sqlite3_vfs*, int, char *);
         1476  +  int (SQLITE_CALLBACK *xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
         1477  +  int (SQLITE_CALLBACK *xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
         1478  +  int (SQLITE_CALLBACK *xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
         1479  +  void *(SQLITE_CALLBACK *xDlOpen)(sqlite3_vfs*, const char *zFilename);
         1480  +  void (SQLITE_CALLBACK *xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
         1481  +  void (SQLITE_CALLBACK *(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
         1482  +  void (SQLITE_CALLBACK *xDlClose)(sqlite3_vfs*, void*);
         1483  +  int (SQLITE_CALLBACK *xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
         1484  +  int (SQLITE_CALLBACK *xSleep)(sqlite3_vfs*, int microseconds);
         1485  +  int (SQLITE_CALLBACK *xCurrentTime)(sqlite3_vfs*, double*);
         1486  +  int (SQLITE_CALLBACK *xGetLastError)(sqlite3_vfs*, int, char *);
  1469   1487     /*
  1470   1488     ** The methods above are in version 1 of the sqlite_vfs object
  1471   1489     ** definition.  Those that follow are added in version 2 or later
  1472   1490     */
  1473         -  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
         1491  +  int (SQLITE_CALLBACK *xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
  1474   1492     /*
  1475   1493     ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
  1476   1494     ** Those below are for version 3 and greater.
  1477   1495     */
  1478         -  int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
  1479         -  sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
  1480         -  const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
         1496  +  int (SQLITE_CALLBACK *xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
         1497  +  sqlite3_syscall_ptr (SQLITE_CALLBACK *xGetSystemCall)(sqlite3_vfs*, const char *zName);
         1498  +  const char *(SQLITE_CALLBACK *xNextSystemCall)(sqlite3_vfs*, const char *zName);
  1481   1499     /*
  1482   1500     ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
  1483   1501     ** New fields may be appended in future versions.  The iVersion
  1484   1502     ** value will increment whenever this happens. 
  1485   1503     */
  1486   1504   };
  1487   1505   
................................................................................
  1618   1636   ** (using the [SQLITE_OS_OTHER=1] compile-time
  1619   1637   ** option) the application must supply a suitable implementation for
  1620   1638   ** sqlite3_os_init() and sqlite3_os_end().  An application-supplied
  1621   1639   ** implementation of sqlite3_os_init() or sqlite3_os_end()
  1622   1640   ** must return [SQLITE_OK] on success and some other [error code] upon
  1623   1641   ** failure.
  1624   1642   */
  1625         -SQLITE_API int SQLITE_STDCALL sqlite3_initialize(void);
  1626         -SQLITE_API int SQLITE_STDCALL sqlite3_shutdown(void);
  1627         -SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void);
  1628         -SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void);
         1643  +SQLITE_API int SQLITE_APICALL sqlite3_initialize(void);
         1644  +SQLITE_API int SQLITE_APICALL sqlite3_shutdown(void);
         1645  +SQLITE_API int SQLITE_APICALL sqlite3_os_init(void);
         1646  +SQLITE_API int SQLITE_APICALL sqlite3_os_end(void);
  1629   1647   
  1630   1648   /*
  1631   1649   ** CAPI3REF: Configuring The SQLite Library
  1632   1650   **
  1633   1651   ** The sqlite3_config() interface is used to make global configuration
  1634   1652   ** changes to SQLite in order to tune SQLite to the specific needs of
  1635   1653   ** the application.  The default configuration is recommended for most
................................................................................
  1740   1758   ** serialization.
  1741   1759   **
  1742   1760   ** SQLite will never invoke xInit() more than once without an intervening
  1743   1761   ** call to xShutdown().
  1744   1762   */
  1745   1763   typedef struct sqlite3_mem_methods sqlite3_mem_methods;
  1746   1764   struct sqlite3_mem_methods {
  1747         -  void *(*xMalloc)(int);         /* Memory allocation function */
  1748         -  void (*xFree)(void*);          /* Free a prior allocation */
  1749         -  void *(*xRealloc)(void*,int);  /* Resize an allocation */
  1750         -  int (*xSize)(void*);           /* Return the size of an allocation */
  1751         -  int (*xRoundup)(int);          /* Round up request size to allocation size */
  1752         -  int (*xInit)(void*);           /* Initialize the memory allocator */
  1753         -  void (*xShutdown)(void*);      /* Deinitialize the memory allocator */
         1765  +  void *(SQLITE_CALLBACK *xMalloc)(int);         /* Memory allocation function */
         1766  +  void (SQLITE_CALLBACK *xFree)(void*);          /* Free a prior allocation */
         1767  +  void *(SQLITE_CALLBACK *xRealloc)(void*,int);  /* Resize an allocation */
         1768  +  int (SQLITE_CALLBACK *xSize)(void*);           /* Return the size of an allocation */
         1769  +  int (SQLITE_CALLBACK *xRoundup)(int);          /* Round up request size to allocation size */
         1770  +  int (SQLITE_CALLBACK *xInit)(void*);           /* Initialize the memory allocator */
         1771  +  void (SQLITE_CALLBACK *xShutdown)(void*);      /* Deinitialize the memory allocator */
  1754   1772     void *pAppData;                /* Argument to xInit() and xShutdown() */
  1755   1773   };
  1756   1774   
  1757   1775   /*
  1758   1776   ** CAPI3REF: Configuration Options
  1759   1777   ** KEYWORDS: {configuration option}
  1760   1778   **
................................................................................
  1963   1981   ** is a pointer to an [sqlite3_pcache_methods2] object.  SQLite copies of
  1964   1982   ** the current page cache implementation into that object.)^ </dd>
  1965   1983   **
  1966   1984   ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
  1967   1985   ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
  1968   1986   ** global [error log].
  1969   1987   ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
  1970         -** function with a call signature of void(*)(void*,int,const char*), 
         1988  +** function with a call signature of void(SQLITE_CALLBACK *)(void*,int,const char*), 
  1971   1989   ** and a pointer to void. ^If the function pointer is not NULL, it is
  1972   1990   ** invoked by [sqlite3_log()] to process each logging event.  ^If the
  1973   1991   ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
  1974   1992   ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
  1975   1993   ** passed through as the first parameter to the application-defined logger
  1976   1994   ** function whenever that function is invoked.  ^The second parameter to
  1977   1995   ** the logger function is a copy of the first parameter to the corresponding
................................................................................
  2016   2034   ** They are retained for backwards compatibility but are now no-ops.
  2017   2035   ** </dd>
  2018   2036   **
  2019   2037   ** [[SQLITE_CONFIG_SQLLOG]]
  2020   2038   ** <dt>SQLITE_CONFIG_SQLLOG
  2021   2039   ** <dd>This option is only available if sqlite is compiled with the
  2022   2040   ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
  2023         -** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
         2041  +** be a pointer to a function of type void(SQLITE_CALLBACK *)(void*,sqlite3*,const char*, int).
  2024   2042   ** The second should be of type (void*). The callback is invoked by the library
  2025   2043   ** in three separate circumstances, identified by the value passed as the
  2026   2044   ** fourth parameter. If the fourth parameter is 0, then the database connection
  2027   2045   ** passed as the second argument has just been opened. The third argument
  2028   2046   ** points to a buffer containing the name of the main database file. If the
  2029   2047   ** fourth parameter is 1, then the SQL statement that the third parameter
  2030   2048   ** points to has just been executed. Or, if the fourth parameter is 2, then
................................................................................
  2214   2232   ** CAPI3REF: Enable Or Disable Extended Result Codes
  2215   2233   ** METHOD: sqlite3
  2216   2234   **
  2217   2235   ** ^The sqlite3_extended_result_codes() routine enables or disables the
  2218   2236   ** [extended result codes] feature of SQLite. ^The extended result
  2219   2237   ** codes are disabled by default for historical compatibility.
  2220   2238   */
  2221         -SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
         2239  +SQLITE_API int SQLITE_APICALL sqlite3_extended_result_codes(sqlite3*, int onoff);
  2222   2240   
  2223   2241   /*
  2224   2242   ** CAPI3REF: Last Insert Rowid
  2225   2243   ** METHOD: sqlite3
  2226   2244   **
  2227   2245   ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
  2228   2246   ** has a unique 64-bit signed
................................................................................
  2266   2284   ** If a separate thread performs a new [INSERT] on the same
  2267   2285   ** database connection while the [sqlite3_last_insert_rowid()]
  2268   2286   ** function is running and thus changes the last insert [rowid],
  2269   2287   ** then the value returned by [sqlite3_last_insert_rowid()] is
  2270   2288   ** unpredictable and might not equal either the old or the new
  2271   2289   ** last insert [rowid].
  2272   2290   */
  2273         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
         2291  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_last_insert_rowid(sqlite3*);
  2274   2292   
  2275   2293   /*
  2276   2294   ** CAPI3REF: Count The Number Of Rows Modified
  2277   2295   ** METHOD: sqlite3
  2278   2296   **
  2279   2297   ** ^This function returns the number of rows modified, inserted or
  2280   2298   ** deleted by the most recently completed INSERT, UPDATE or DELETE
................................................................................
  2319   2337   ** See also the [sqlite3_total_changes()] interface, the
  2320   2338   ** [count_changes pragma], and the [changes() SQL function].
  2321   2339   **
  2322   2340   ** If a separate thread makes changes on the same database connection
  2323   2341   ** while [sqlite3_changes()] is running then the value returned
  2324   2342   ** is unpredictable and not meaningful.
  2325   2343   */
  2326         -SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
         2344  +SQLITE_API int SQLITE_APICALL sqlite3_changes(sqlite3*);
  2327   2345   
  2328   2346   /*
  2329   2347   ** CAPI3REF: Total Number Of Rows Modified
  2330   2348   ** METHOD: sqlite3
  2331   2349   **
  2332   2350   ** ^This function returns the total number of rows inserted, modified or
  2333   2351   ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
................................................................................
  2343   2361   ** See also the [sqlite3_changes()] interface, the
  2344   2362   ** [count_changes pragma], and the [total_changes() SQL function].
  2345   2363   **
  2346   2364   ** If a separate thread makes changes on the same database connection
  2347   2365   ** while [sqlite3_total_changes()] is running then the value
  2348   2366   ** returned is unpredictable and not meaningful.
  2349   2367   */
  2350         -SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
         2368  +SQLITE_API int SQLITE_APICALL sqlite3_total_changes(sqlite3*);
  2351   2369   
  2352   2370   /*
  2353   2371   ** CAPI3REF: Interrupt A Long-Running Query
  2354   2372   ** METHOD: sqlite3
  2355   2373   **
  2356   2374   ** ^This function causes any pending database operation to abort and
  2357   2375   ** return at its earliest opportunity. This routine is typically
................................................................................
  2383   2401   ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  2384   2402   ** SQL statements is a no-op and has no effect on SQL statements
  2385   2403   ** that are started after the sqlite3_interrupt() call returns.
  2386   2404   **
  2387   2405   ** If the database connection closes while [sqlite3_interrupt()]
  2388   2406   ** is running then bad things will likely happen.
  2389   2407   */
  2390         -SQLITE_API void SQLITE_STDCALL sqlite3_interrupt(sqlite3*);
         2408  +SQLITE_API void SQLITE_APICALL sqlite3_interrupt(sqlite3*);
  2391   2409   
  2392   2410   /*
  2393   2411   ** CAPI3REF: Determine If An SQL Statement Is Complete
  2394   2412   **
  2395   2413   ** These routines are useful during command-line input to determine if the
  2396   2414   ** currently entered text seems to form a complete SQL statement or
  2397   2415   ** if additional input is needed before sending the text into
................................................................................
  2418   2436   **
  2419   2437   ** The input to [sqlite3_complete()] must be a zero-terminated
  2420   2438   ** UTF-8 string.
  2421   2439   **
  2422   2440   ** The input to [sqlite3_complete16()] must be a zero-terminated
  2423   2441   ** UTF-16 string in native byte order.
  2424   2442   */
  2425         -SQLITE_API int SQLITE_STDCALL sqlite3_complete(const char *sql);
  2426         -SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
         2443  +SQLITE_API int SQLITE_APICALL sqlite3_complete(const char *sql);
         2444  +SQLITE_API int SQLITE_APICALL sqlite3_complete16(const void *sql);
  2427   2445   
  2428   2446   /*
  2429   2447   ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
  2430   2448   ** KEYWORDS: {busy-handler callback} {busy handler}
  2431   2449   ** METHOD: sqlite3
  2432   2450   **
  2433   2451   ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
................................................................................
  2480   2498   ** database connection that invoked the busy handler.  In other words,
  2481   2499   ** the busy handler is not reentrant.  Any such actions
  2482   2500   ** result in undefined behavior.
  2483   2501   ** 
  2484   2502   ** A busy handler must not close the database connection
  2485   2503   ** or [prepared statement] that invoked the busy handler.
  2486   2504   */
  2487         -SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
         2505  +SQLITE_API int SQLITE_APICALL sqlite3_busy_handler(sqlite3*, int(SQLITE_CALLBACK *)(void*,int), void*);
  2488   2506   
  2489   2507   /*
  2490   2508   ** CAPI3REF: Set A Busy Timeout
  2491   2509   ** METHOD: sqlite3
  2492   2510   **
  2493   2511   ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
  2494   2512   ** for a specified amount of time when a table is locked.  ^The handler
................................................................................
  2503   2521   ** ^(There can only be a single busy handler for a particular
  2504   2522   ** [database connection] at any given moment.  If another busy handler
  2505   2523   ** was defined  (using [sqlite3_busy_handler()]) prior to calling
  2506   2524   ** this routine, that other busy handler is cleared.)^
  2507   2525   **
  2508   2526   ** See also:  [PRAGMA busy_timeout]
  2509   2527   */
  2510         -SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
         2528  +SQLITE_API int SQLITE_APICALL sqlite3_busy_timeout(sqlite3*, int ms);
  2511   2529   
  2512   2530   /*
  2513   2531   ** CAPI3REF: Convenience Routines For Running Queries
  2514   2532   ** METHOD: sqlite3
  2515   2533   **
  2516   2534   ** This is a legacy interface that is preserved for backwards compatibility.
  2517   2535   ** Use of this interface is not recommended.
................................................................................
  2578   2596   ** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
  2579   2597   ** to any internal data structures of SQLite.  It uses only the public
  2580   2598   ** interface defined here.  As a consequence, errors that occur in the
  2581   2599   ** wrapper layer outside of the internal [sqlite3_exec()] call are not
  2582   2600   ** reflected in subsequent calls to [sqlite3_errcode()] or
  2583   2601   ** [sqlite3_errmsg()].
  2584   2602   */
  2585         -SQLITE_API int SQLITE_STDCALL sqlite3_get_table(
         2603  +SQLITE_API int SQLITE_APICALL sqlite3_get_table(
  2586   2604     sqlite3 *db,          /* An open database */
  2587   2605     const char *zSql,     /* SQL to be evaluated */
  2588   2606     char ***pazResult,    /* Results of the query */
  2589   2607     int *pnRow,           /* Number of result rows written here */
  2590   2608     int *pnColumn,        /* Number of result columns written here */
  2591   2609     char **pzErrmsg       /* Error msg written here */
  2592   2610   );
  2593         -SQLITE_API void SQLITE_STDCALL sqlite3_free_table(char **result);
         2611  +SQLITE_API void SQLITE_APICALL sqlite3_free_table(char **result);
  2594   2612   
  2595   2613   /*
  2596   2614   ** CAPI3REF: Formatted String Printing Functions
  2597   2615   **
  2598   2616   ** These routines are work-alikes of the "printf()" family of functions
  2599   2617   ** from the standard C library.
  2600   2618   ** These routines understand most of the common K&R formatting options,
................................................................................
  2693   2711   ** table and column names into a constructed SQL statement.
  2694   2712   **
  2695   2713   ** ^(The "%z" formatting option works like "%s" but with the
  2696   2714   ** addition that after the string has been read and copied into
  2697   2715   ** the result, [sqlite3_free()] is called on the input string.)^
  2698   2716   */
  2699   2717   SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char*,...);
  2700         -SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char*, va_list);
         2718  +SQLITE_API char *SQLITE_APICALL sqlite3_vmprintf(const char*, va_list);
  2701   2719   SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int,char*,const char*, ...);
  2702         -SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int,char*,const char*, va_list);
         2720  +SQLITE_API char *SQLITE_APICALL sqlite3_vsnprintf(int,char*,const char*, va_list);
  2703   2721   
  2704   2722   /*
  2705   2723   ** CAPI3REF: Memory Allocation Subsystem
  2706   2724   **
  2707   2725   ** The SQLite core uses these three routines for all of its own
  2708   2726   ** internal memory allocation needs. "Core" in the previous sentence
  2709   2727   ** does not include operating-system specific VFS implementation.  The
................................................................................
  2785   2803   ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
  2786   2804   ** not yet been released.
  2787   2805   **
  2788   2806   ** The application must not read or write any part of
  2789   2807   ** a block of memory after it has been released using
  2790   2808   ** [sqlite3_free()] or [sqlite3_realloc()].
  2791   2809   */
  2792         -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int);
  2793         -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64);
  2794         -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void*, int);
  2795         -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void*, sqlite3_uint64);
  2796         -SQLITE_API void SQLITE_STDCALL sqlite3_free(void*);
  2797         -SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void*);
         2810  +SQLITE_API void *SQLITE_APICALL sqlite3_malloc(int);
         2811  +SQLITE_API void *SQLITE_APICALL sqlite3_malloc64(sqlite3_uint64);
         2812  +SQLITE_API void *SQLITE_APICALL sqlite3_realloc(void*, int);
         2813  +SQLITE_API void *SQLITE_APICALL sqlite3_realloc64(void*, sqlite3_uint64);
         2814  +SQLITE_API void SQLITE_APICALL sqlite3_free(void*);
         2815  +SQLITE_API sqlite3_uint64 SQLITE_APICALL sqlite3_msize(void*);
  2798   2816   
  2799   2817   /*
  2800   2818   ** CAPI3REF: Memory Allocator Statistics
  2801   2819   **
  2802   2820   ** SQLite provides these two interfaces for reporting on the status
  2803   2821   ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
  2804   2822   ** routines, which form the built-in memory allocation subsystem.
................................................................................
  2815   2833   **
  2816   2834   ** ^The memory high-water mark is reset to the current value of
  2817   2835   ** [sqlite3_memory_used()] if and only if the parameter to
  2818   2836   ** [sqlite3_memory_highwater()] is true.  ^The value returned
  2819   2837   ** by [sqlite3_memory_highwater(1)] is the high-water mark
  2820   2838   ** prior to the reset.
  2821   2839   */
  2822         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void);
  2823         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag);
         2840  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_memory_used(void);
         2841  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_memory_highwater(int resetFlag);
  2824   2842   
  2825   2843   /*
  2826   2844   ** CAPI3REF: Pseudo-Random Number Generator
  2827   2845   **
  2828   2846   ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
  2829   2847   ** select random [ROWID | ROWIDs] when inserting new records into a table that
  2830   2848   ** already uses the largest possible [ROWID].  The PRNG is also used for
................................................................................
  2839   2857   ** seeded using randomness obtained from the xRandomness method of
  2840   2858   ** the default [sqlite3_vfs] object.
  2841   2859   ** ^If the previous call to this routine had an N of 1 or more and a
  2842   2860   ** non-NULL P then the pseudo-randomness is generated
  2843   2861   ** internally and without recourse to the [sqlite3_vfs] xRandomness
  2844   2862   ** method.
  2845   2863   */
  2846         -SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
         2864  +SQLITE_API void SQLITE_APICALL sqlite3_randomness(int N, void *P);
  2847   2865   
  2848   2866   /*
  2849   2867   ** CAPI3REF: Compile-Time Authorization Callbacks
  2850   2868   ** METHOD: sqlite3
  2851   2869   **
  2852   2870   ** ^This routine registers an authorizer callback with a particular
  2853   2871   ** [database connection], supplied in the first argument.
................................................................................
  2922   2940   **
  2923   2941   ** ^Note that the authorizer callback is invoked only during
  2924   2942   ** [sqlite3_prepare()] or its variants.  Authorization is not
  2925   2943   ** performed during statement evaluation in [sqlite3_step()], unless
  2926   2944   ** as stated in the previous paragraph, sqlite3_step() invokes
  2927   2945   ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
  2928   2946   */
  2929         -SQLITE_API int SQLITE_STDCALL sqlite3_set_authorizer(
         2947  +SQLITE_API int SQLITE_APICALL sqlite3_set_authorizer(
  2930   2948     sqlite3*,
  2931         -  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
         2949  +  int (SQLITE_CALLBACK *xAuth)(void*,int,const char*,const char*,const char*,const char*),
  2932   2950     void *pUserData
  2933   2951   );
  2934   2952   
  2935   2953   /*
  2936   2954   ** CAPI3REF: Authorizer Return Codes
  2937   2955   **
  2938   2956   ** The [sqlite3_set_authorizer | authorizer callback function] must
................................................................................
  3001   3019   #define SQLITE_SAVEPOINT            32   /* Operation       Savepoint Name  */
  3002   3020   #define SQLITE_COPY                  0   /* No longer used */
  3003   3021   #define SQLITE_RECURSIVE            33   /* NULL            NULL            */
  3004   3022   
  3005   3023   /*
  3006   3024   ** CAPI3REF: Tracing And Profiling Functions
  3007   3025   ** METHOD: sqlite3
         3026  +**
         3027  +** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
         3028  +** instead of the routines described here.
  3008   3029   **
  3009   3030   ** These routines register callback functions that can be used for
  3010   3031   ** tracing and profiling the execution of SQL statements.
  3011   3032   **
  3012   3033   ** ^The callback function registered by sqlite3_trace() is invoked at
  3013   3034   ** various times when an SQL statement is being run by [sqlite3_step()].
  3014   3035   ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
................................................................................
  3027   3048   ** time is in units of nanoseconds, however the current implementation
  3028   3049   ** is only capable of millisecond resolution so the six least significant
  3029   3050   ** digits in the time are meaningless.  Future versions of SQLite
  3030   3051   ** might provide greater resolution on the profiler callback.  The
  3031   3052   ** sqlite3_profile() function is considered experimental and is
  3032   3053   ** subject to change in future versions of SQLite.
  3033   3054   */
  3034         -SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  3035         -SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
  3036         -   void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
         3055  +SQLITE_API SQLITE_DEPRECATED void *SQLITE_APICALL sqlite3_trace(sqlite3*,
         3056  +   void(SQLITE_CALLBACK *xTrace)(void*,const char*), void*);
         3057  +SQLITE_API SQLITE_DEPRECATED void *SQLITE_APICALL sqlite3_profile(sqlite3*,
         3058  +   void(SQLITE_CALLBACK *xProfile)(void*,const char*,sqlite3_uint64), void*);
         3059  +
         3060  +/*
         3061  +** CAPI3REF: SQL Trace Event Codes
         3062  +** KEYWORDS: SQLITE_TRACE
         3063  +**
         3064  +** These constants identify classes of events that can be monitored
         3065  +** using the [sqlite3_trace_v2()] tracing logic.  The third argument
         3066  +** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
         3067  +** the following constants.  ^The first argument to the trace callback
         3068  +** is one of the following constants.
         3069  +**
         3070  +** New tracing constants may be added in future releases.
         3071  +**
         3072  +** ^A trace callback has four arguments: xCallback(T,C,P,X).
         3073  +** ^The T argument is one of the integer type codes above.
         3074  +** ^The C argument is a copy of the context pointer passed in as the
         3075  +** fourth argument to [sqlite3_trace_v2()].
         3076  +** The P and X arguments are pointers whose meanings depend on T.
         3077  +**
         3078  +** <dl>
         3079  +** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
         3080  +** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
         3081  +** first begins running and possibly at other times during the
         3082  +** execution of the prepared statement, such as at the start of each
         3083  +** trigger subprogram. ^The P argument is a pointer to the
         3084  +** [prepared statement]. ^The X argument is a pointer to a string which
         3085  +** is the unexpanded SQL text of the prepared statement or an SQL comment 
         3086  +** that indicates the invocation of a trigger.  ^The callback can compute
         3087  +** the same text that would have been returned by the legacy [sqlite3_trace()]
         3088  +** interface by using the X argument when X begins with "--" and invoking
         3089  +** [sqlite3_expanded_sql(P)] otherwise.
         3090  +**
         3091  +** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
         3092  +** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
         3093  +** information as is provided by the [sqlite3_profile()] callback.
         3094  +** ^The P argument is a pointer to the [prepared statement] and the
         3095  +** X argument points to a 64-bit integer which is the estimated of
         3096  +** the number of nanosecond that the prepared statement took to run.
         3097  +** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
         3098  +**
         3099  +** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
         3100  +** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
         3101  +** statement generates a single row of result.  
         3102  +** ^The P argument is a pointer to the [prepared statement] and the
         3103  +** X argument is unused.
         3104  +**
         3105  +** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
         3106  +** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
         3107  +** connection closes.
         3108  +** ^The P argument is a pointer to the [database connection] object
         3109  +** and the X argument is unused.
         3110  +** </dl>
         3111  +*/
         3112  +#define SQLITE_TRACE_STMT       0x01
         3113  +#define SQLITE_TRACE_PROFILE    0x02
         3114  +#define SQLITE_TRACE_ROW        0x04
         3115  +#define SQLITE_TRACE_CLOSE      0x08
         3116  +
         3117  +/*
         3118  +** CAPI3REF: SQL Trace Hook
         3119  +** METHOD: sqlite3
         3120  +**
         3121  +** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
         3122  +** function X against [database connection] D, using property mask M
         3123  +** and context pointer P.  ^If the X callback is
         3124  +** NULL or if the M mask is zero, then tracing is disabled.  The
         3125  +** M argument should be the bitwise OR-ed combination of
         3126  +** zero or more [SQLITE_TRACE] constants.
         3127  +**
         3128  +** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides 
         3129  +** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
         3130  +**
         3131  +** ^The X callback is invoked whenever any of the events identified by 
         3132  +** mask M occur.  ^The integer return value from the callback is currently
         3133  +** ignored, though this may change in future releases.  Callback
         3134  +** implementations should return zero to ensure future compatibility.
         3135  +**
         3136  +** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
         3137  +** ^The T argument is one of the [SQLITE_TRACE]
         3138  +** constants to indicate why the callback was invoked.
         3139  +** ^The C argument is a copy of the context pointer.
         3140  +** The P and X arguments are pointers whose meanings depend on T.
         3141  +**
         3142  +** The sqlite3_trace_v2() interface is intended to replace the legacy
         3143  +** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
         3144  +** are deprecated.
         3145  +*/
         3146  +SQLITE_API int SQLITE_APICALL sqlite3_trace_v2(
         3147  +  sqlite3*,
         3148  +  unsigned uMask,
         3149  +  int(SQLITE_CALLBACK *xCallback)(unsigned,void*,void*,void*),
         3150  +  void *pCtx
         3151  +);
  3037   3152   
  3038   3153   /*
  3039   3154   ** CAPI3REF: Query Progress Callbacks
  3040   3155   ** METHOD: sqlite3
  3041   3156   **
  3042   3157   ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
  3043   3158   ** function X to be invoked periodically during long running calls to
................................................................................
  3063   3178   **
  3064   3179   ** The progress handler callback must not do anything that will modify
  3065   3180   ** the database connection that invoked the progress handler.
  3066   3181   ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  3067   3182   ** database connections for the meaning of "modify" in this paragraph.
  3068   3183   **
  3069   3184   */
  3070         -SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
         3185  +SQLITE_API void SQLITE_APICALL sqlite3_progress_handler(sqlite3*, int, int(SQLITE_CALLBACK *)(void*), void*);
  3071   3186   
  3072   3187   /*
  3073   3188   ** CAPI3REF: Opening A New Database Connection
  3074   3189   ** CONSTRUCTOR: sqlite3
  3075   3190   **
  3076   3191   ** ^These routines open an SQLite database file as specified by the 
  3077   3192   ** filename argument. ^The filename argument is interpreted as UTF-8 for
................................................................................
  3292   3407   **
  3293   3408   ** <b>Note to Windows Runtime users:</b>  The temporary directory must be set
  3294   3409   ** prior to calling sqlite3_open() or sqlite3_open_v2().  Otherwise, various
  3295   3410   ** features that require the use of temporary files may fail.
  3296   3411   **
  3297   3412   ** See also: [sqlite3_temp_directory]
  3298   3413   */
  3299         -SQLITE_API int SQLITE_STDCALL sqlite3_open(
         3414  +SQLITE_API int SQLITE_APICALL sqlite3_open(
  3300   3415     const char *filename,   /* Database filename (UTF-8) */
  3301   3416     sqlite3 **ppDb          /* OUT: SQLite db handle */
  3302   3417   );
  3303         -SQLITE_API int SQLITE_STDCALL sqlite3_open16(
         3418  +SQLITE_API int SQLITE_APICALL sqlite3_open16(
  3304   3419     const void *filename,   /* Database filename (UTF-16) */
  3305   3420     sqlite3 **ppDb          /* OUT: SQLite db handle */
  3306   3421   );
  3307         -SQLITE_API int SQLITE_STDCALL sqlite3_open_v2(
         3422  +SQLITE_API int SQLITE_APICALL sqlite3_open_v2(
  3308   3423     const char *filename,   /* Database filename (UTF-8) */
  3309   3424     sqlite3 **ppDb,         /* OUT: SQLite db handle */
  3310   3425     int flags,              /* Flags */
  3311   3426     const char *zVfs        /* Name of VFS module to use */
  3312   3427   );
  3313   3428   
  3314   3429   /*
................................................................................
  3346   3461   ** 
  3347   3462   ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
  3348   3463   ** sqlite3_uri_boolean(F,P,B) returns B.  If F is not a NULL pointer and
  3349   3464   ** is not a database file pathname pointer that SQLite passed into the xOpen
  3350   3465   ** VFS method, then the behavior of this routine is undefined and probably
  3351   3466   ** undesirable.
  3352   3467   */
  3353         -SQLITE_API const char *SQLITE_STDCALL sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  3354         -SQLITE_API int SQLITE_STDCALL sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  3355         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
         3468  +SQLITE_API const char *SQLITE_APICALL sqlite3_uri_parameter(const char *zFilename, const char *zParam);
         3469  +SQLITE_API int SQLITE_APICALL sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
         3470  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  3356   3471   
  3357   3472   
  3358   3473   /*
  3359   3474   ** CAPI3REF: Error Codes And Messages
  3360   3475   ** METHOD: sqlite3
  3361   3476   **
  3362   3477   ** ^If the most recent sqlite3_* API call associated with 
................................................................................
  3392   3507   ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
  3393   3508   ** all calls to the interfaces listed here are completed.
  3394   3509   **
  3395   3510   ** If an interface fails with SQLITE_MISUSE, that means the interface
  3396   3511   ** was invoked incorrectly by the application.  In that case, the
  3397   3512   ** error code and message may or may not be set.
  3398   3513   */
  3399         -SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db);
  3400         -SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db);
  3401         -SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
  3402         -SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
  3403         -SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
         3514  +SQLITE_API int SQLITE_APICALL sqlite3_errcode(sqlite3 *db);
         3515  +SQLITE_API int SQLITE_APICALL sqlite3_extended_errcode(sqlite3 *db);
         3516  +SQLITE_API const char *SQLITE_APICALL sqlite3_errmsg(sqlite3*);
         3517  +SQLITE_API const void *SQLITE_APICALL sqlite3_errmsg16(sqlite3*);
         3518  +SQLITE_API const char *SQLITE_APICALL sqlite3_errstr(int);
  3404   3519   
  3405   3520   /*
  3406   3521   ** CAPI3REF: Prepared Statement Object
  3407   3522   ** KEYWORDS: {prepared statement} {prepared statements}
  3408   3523   **
  3409   3524   ** An instance of this object represents a single SQL statement that
  3410   3525   ** has been compiled into binary form and is ready to be evaluated.
................................................................................
  3464   3579   ** attack.  Developers might also want to use the [sqlite3_set_authorizer()]
  3465   3580   ** interface to further control untrusted SQL.  The size of the database
  3466   3581   ** created by an untrusted script can be contained using the
  3467   3582   ** [max_page_count] [PRAGMA].
  3468   3583   **
  3469   3584   ** New run-time limit categories may be added in future releases.
  3470   3585   */
  3471         -SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3*, int id, int newVal);
         3586  +SQLITE_API int SQLITE_APICALL sqlite3_limit(sqlite3*, int id, int newVal);
  3472   3587   
  3473   3588   /*
  3474   3589   ** CAPI3REF: Run-Time Limit Categories
  3475   3590   ** KEYWORDS: {limit category} {*limit categories}
  3476   3591   **
  3477   3592   ** These constants define various performance limits
  3478   3593   ** that can be lowered at run-time using [sqlite3_limit()].
................................................................................
  3616   3731   ** ^The specific value of WHERE-clause [parameter] might influence the 
  3617   3732   ** choice of query plan if the parameter is the left-hand side of a [LIKE]
  3618   3733   ** or [GLOB] operator or if the parameter is compared to an indexed column
  3619   3734   ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
  3620   3735   ** </li>
  3621   3736   ** </ol>
  3622   3737   */
  3623         -SQLITE_API int SQLITE_STDCALL sqlite3_prepare(
         3738  +SQLITE_API int SQLITE_APICALL sqlite3_prepare(
  3624   3739     sqlite3 *db,            /* Database handle */
  3625   3740     const char *zSql,       /* SQL statement, UTF-8 encoded */
  3626   3741     int nByte,              /* Maximum length of zSql in bytes. */
  3627   3742     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  3628   3743     const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  3629   3744   );
  3630         -SQLITE_API int SQLITE_STDCALL sqlite3_prepare_v2(
         3745  +SQLITE_API int SQLITE_APICALL sqlite3_prepare_v2(
  3631   3746     sqlite3 *db,            /* Database handle */
  3632   3747     const char *zSql,       /* SQL statement, UTF-8 encoded */
  3633   3748     int nByte,              /* Maximum length of zSql in bytes. */
  3634   3749     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  3635   3750     const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  3636   3751   );
  3637         -SQLITE_API int SQLITE_STDCALL sqlite3_prepare16(
         3752  +SQLITE_API int SQLITE_APICALL sqlite3_prepare16(
  3638   3753     sqlite3 *db,            /* Database handle */
  3639   3754     const void *zSql,       /* SQL statement, UTF-16 encoded */
  3640   3755     int nByte,              /* Maximum length of zSql in bytes. */
  3641   3756     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  3642   3757     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  3643   3758   );
  3644         -SQLITE_API int SQLITE_STDCALL sqlite3_prepare16_v2(
         3759  +SQLITE_API int SQLITE_APICALL sqlite3_prepare16_v2(
  3645   3760     sqlite3 *db,            /* Database handle */
  3646   3761     const void *zSql,       /* SQL statement, UTF-16 encoded */
  3647   3762     int nByte,              /* Maximum length of zSql in bytes. */
  3648   3763     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  3649   3764     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  3650   3765   );
  3651   3766   
  3652   3767   /*
  3653   3768   ** CAPI3REF: Retrieving Statement SQL
  3654   3769   ** METHOD: sqlite3_stmt
  3655   3770   **
  3656         -** ^This interface can be used to retrieve a saved copy of the original
  3657         -** SQL text used to create a [prepared statement] if that statement was
  3658         -** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
         3771  +** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
         3772  +** SQL text used to create [prepared statement] P if P was
         3773  +** created by either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
         3774  +** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
         3775  +** string containing the SQL text of prepared statement P with
         3776  +** [bound parameters] expanded.
         3777  +**
         3778  +** ^(For example, if a prepared statement is created using the SQL
         3779  +** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
         3780  +** and parameter :xyz is unbound, then sqlite3_sql() will return
         3781  +** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
         3782  +** will return "SELECT 2345,NULL".)^
         3783  +**
         3784  +** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
         3785  +** is available to hold the result, or if the result would exceed the
         3786  +** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
         3787  +**
         3788  +** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
         3789  +** bound parameter expansions.  ^The [SQLITE_OMIT_TRACE] compile-time
         3790  +** option causes sqlite3_expanded_sql() to always return NULL.
         3791  +**
         3792  +** ^The string returned by sqlite3_sql(P) is managed by SQLite and is
         3793  +** automatically freed when the prepared statement is finalized.
         3794  +** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
         3795  +** is obtained from [sqlite3_malloc()] and must be free by the application
         3796  +** by passing it to [sqlite3_free()].
  3659   3797   */
  3660         -SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
         3798  +SQLITE_API const char *SQLITE_APICALL sqlite3_sql(sqlite3_stmt *pStmt);
         3799  +SQLITE_API char *SQLITE_APICALL sqlite3_expanded_sql(sqlite3_stmt *pStmt);
  3661   3800   
  3662   3801   /*
  3663   3802   ** CAPI3REF: Determine If An SQL Statement Writes The Database
  3664   3803   ** METHOD: sqlite3_stmt
  3665   3804   **
  3666   3805   ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
  3667   3806   ** and only if the [prepared statement] X makes no direct changes to
................................................................................
  3685   3824   ** since the statements themselves do not actually modify the database but
  3686   3825   ** rather they control the timing of when other statements modify the 
  3687   3826   ** database.  ^The [ATTACH] and [DETACH] statements also cause
  3688   3827   ** sqlite3_stmt_readonly() to return true since, while those statements
  3689   3828   ** change the configuration of a database connection, they do not make 
  3690   3829   ** changes to the content of the database files on disk.
  3691   3830   */
  3692         -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
         3831  +SQLITE_API int SQLITE_APICALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  3693   3832   
  3694   3833   /*
  3695   3834   ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  3696   3835   ** METHOD: sqlite3_stmt
  3697   3836   **
  3698   3837   ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  3699   3838   ** [prepared statement] S has been stepped at least once using 
................................................................................
  3706   3845   **
  3707   3846   ** This interface can be used in combination [sqlite3_next_stmt()]
  3708   3847   ** to locate all prepared statements associated with a database 
  3709   3848   ** connection that are in need of being reset.  This can be used,
  3710   3849   ** for example, in diagnostic routines to search for prepared 
  3711   3850   ** statements that are holding a transaction open.
  3712   3851   */
  3713         -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_busy(sqlite3_stmt*);
         3852  +SQLITE_API int SQLITE_APICALL sqlite3_stmt_busy(sqlite3_stmt*);
  3714   3853   
  3715   3854   /*
  3716   3855   ** CAPI3REF: Dynamically Typed Value Object
  3717   3856   ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  3718   3857   **
  3719   3858   ** SQLite uses the sqlite3_value object to represent all values
  3720   3859   ** that can be stored in a database table. SQLite uses dynamic typing
................................................................................
  3870   4009   ** [SQLITE_MAX_LENGTH].
  3871   4010   ** ^[SQLITE_RANGE] is returned if the parameter
  3872   4011   ** index is out of range.  ^[SQLITE_NOMEM] is returned if malloc() fails.
  3873   4012   **
  3874   4013   ** See also: [sqlite3_bind_parameter_count()],
  3875   4014   ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  3876   4015   */
  3877         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  3878         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
  3879         -                        void(*)(void*));
  3880         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_double(sqlite3_stmt*, int, double);
  3881         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int(sqlite3_stmt*, int, int);
  3882         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  3883         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_null(sqlite3_stmt*, int);
  3884         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
  3885         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  3886         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
  3887         -                         void(*)(void*), unsigned char encoding);
  3888         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  3889         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  3890         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
         4016  +SQLITE_API int SQLITE_APICALL sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(SQLITE_CALLBACK *)(void*));
         4017  +SQLITE_API int SQLITE_APICALL sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
         4018  +                        void(SQLITE_CALLBACK *)(void*));
         4019  +SQLITE_API int SQLITE_APICALL sqlite3_bind_double(sqlite3_stmt*, int, double);
         4020  +SQLITE_API int SQLITE_APICALL sqlite3_bind_int(sqlite3_stmt*, int, int);
         4021  +SQLITE_API int SQLITE_APICALL sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
         4022  +SQLITE_API int SQLITE_APICALL sqlite3_bind_null(sqlite3_stmt*, int);
         4023  +SQLITE_API int SQLITE_APICALL sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(SQLITE_CALLBACK *)(void*));
         4024  +SQLITE_API int SQLITE_APICALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(SQLITE_CALLBACK *)(void*));
         4025  +SQLITE_API int SQLITE_APICALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
         4026  +                         void(SQLITE_CALLBACK *)(void*), unsigned char encoding);
         4027  +SQLITE_API int SQLITE_APICALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
         4028  +SQLITE_API int SQLITE_APICALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
         4029  +SQLITE_API int SQLITE_APICALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
  3891   4030   
  3892   4031   /*
  3893   4032   ** CAPI3REF: Number Of SQL Parameters
  3894   4033   ** METHOD: sqlite3_stmt
  3895   4034   **
  3896   4035   ** ^This routine can be used to find the number of [SQL parameters]
  3897   4036   ** in a [prepared statement].  SQL parameters are tokens of the
................................................................................
  3904   4043   ** number of unique parameters.  If parameters of the ?NNN form are used,
  3905   4044   ** there may be gaps in the list.)^
  3906   4045   **
  3907   4046   ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3908   4047   ** [sqlite3_bind_parameter_name()], and
  3909   4048   ** [sqlite3_bind_parameter_index()].
  3910   4049   */
  3911         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
         4050  +SQLITE_API int SQLITE_APICALL sqlite3_bind_parameter_count(sqlite3_stmt*);
  3912   4051   
  3913   4052   /*
  3914   4053   ** CAPI3REF: Name Of A Host Parameter
  3915   4054   ** METHOD: sqlite3_stmt
  3916   4055   **
  3917   4056   ** ^The sqlite3_bind_parameter_name(P,N) interface returns
  3918   4057   ** the name of the N-th [SQL parameter] in the [prepared statement] P.
................................................................................
  3932   4071   ** originally specified as UTF-16 in [sqlite3_prepare16()] or
  3933   4072   ** [sqlite3_prepare16_v2()].
  3934   4073   **
  3935   4074   ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3936   4075   ** [sqlite3_bind_parameter_count()], and
  3937   4076   ** [sqlite3_bind_parameter_index()].
  3938   4077   */
  3939         -SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
         4078  +SQLITE_API const char *SQLITE_APICALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  3940   4079   
  3941   4080   /*
  3942   4081   ** CAPI3REF: Index Of A Parameter With A Given Name
  3943   4082   ** METHOD: sqlite3_stmt
  3944   4083   **
  3945   4084   ** ^Return the index of an SQL parameter given its name.  ^The
  3946   4085   ** index value returned is suitable for use as the second
................................................................................
  3949   4088   ** name must be given in UTF-8 even if the original statement
  3950   4089   ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
  3951   4090   **
  3952   4091   ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3953   4092   ** [sqlite3_bind_parameter_count()], and
  3954   4093   ** [sqlite3_bind_parameter_name()].
  3955   4094   */
  3956         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
         4095  +SQLITE_API int SQLITE_APICALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  3957   4096   
  3958   4097   /*
  3959   4098   ** CAPI3REF: Reset All Bindings On A Prepared Statement
  3960   4099   ** METHOD: sqlite3_stmt
  3961   4100   **
  3962   4101   ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
  3963   4102   ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  3964   4103   ** ^Use this routine to reset all host parameters to NULL.
  3965   4104   */
  3966         -SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
         4105  +SQLITE_API int SQLITE_APICALL sqlite3_clear_bindings(sqlite3_stmt*);
  3967   4106   
  3968   4107   /*
  3969   4108   ** CAPI3REF: Number Of Columns In A Result Set
  3970   4109   ** METHOD: sqlite3_stmt
  3971   4110   **
  3972   4111   ** ^Return the number of columns in the result set returned by the
  3973   4112   ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
  3974   4113   ** statement that does not return data (for example an [UPDATE]).
  3975   4114   **
  3976   4115   ** See also: [sqlite3_data_count()]
  3977   4116   */
  3978         -SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
         4117  +SQLITE_API int SQLITE_APICALL sqlite3_column_count(sqlite3_stmt *pStmt);
  3979   4118   
  3980   4119   /*
  3981   4120   ** CAPI3REF: Column Names In A Result Set
  3982   4121   ** METHOD: sqlite3_stmt
  3983   4122   **
  3984   4123   ** ^These routines return the name assigned to a particular column
  3985   4124   ** in the result set of a [SELECT] statement.  ^The sqlite3_column_name()
................................................................................
  4000   4139   ** NULL pointer is returned.
  4001   4140   **
  4002   4141   ** ^The name of a result column is the value of the "AS" clause for
  4003   4142   ** that column, if there is an AS clause.  If there is no AS clause
  4004   4143   ** then the name of the column is unspecified and may change from
  4005   4144   ** one release of SQLite to the next.
  4006   4145   */
  4007         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
  4008         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
         4146  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_name(sqlite3_stmt*, int N);
         4147  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_name16(sqlite3_stmt*, int N);
  4009   4148   
  4010   4149   /*
  4011   4150   ** CAPI3REF: Source Of Data In A Query Result
  4012   4151   ** METHOD: sqlite3_stmt
  4013   4152   **
  4014   4153   ** ^These routines provide a means to determine the database, table, and
  4015   4154   ** table column that is the origin of a particular result column in
................................................................................
  4049   4188   ** undefined.
  4050   4189   **
  4051   4190   ** If two or more threads call one or more
  4052   4191   ** [sqlite3_column_database_name | column metadata interfaces]
  4053   4192   ** for the same [prepared statement] and result column
  4054   4193   ** at the same time then the results are undefined.
  4055   4194   */
  4056         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_database_name(sqlite3_stmt*,int);
  4057         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_database_name16(sqlite3_stmt*,int);
  4058         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_table_name(sqlite3_stmt*,int);
  4059         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_table_name16(sqlite3_stmt*,int);
  4060         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
  4061         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
         4195  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_database_name(sqlite3_stmt*,int);
         4196  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_database_name16(sqlite3_stmt*,int);
         4197  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_table_name(sqlite3_stmt*,int);
         4198  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_table_name16(sqlite3_stmt*,int);
         4199  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_origin_name(sqlite3_stmt*,int);
         4200  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
  4062   4201   
  4063   4202   /*
  4064   4203   ** CAPI3REF: Declared Datatype Of A Query Result
  4065   4204   ** METHOD: sqlite3_stmt
  4066   4205   **
  4067   4206   ** ^(The first parameter is a [prepared statement].
  4068   4207   ** If this statement is a [SELECT] statement and the Nth column of the
................................................................................
  4086   4225   ** ^SQLite uses dynamic run-time typing.  ^So just because a column
  4087   4226   ** is declared to contain a particular type does not mean that the
  4088   4227   ** data stored in that column is of the declared type.  SQLite is
  4089   4228   ** strongly typed, but the typing is dynamic not static.  ^Type
  4090   4229   ** is associated with individual values, not with the containers
  4091   4230   ** used to hold those values.
  4092   4231   */
  4093         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
  4094         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
         4232  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_decltype(sqlite3_stmt*,int);
         4233  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_decltype16(sqlite3_stmt*,int);
  4095   4234   
  4096   4235   /*
  4097   4236   ** CAPI3REF: Evaluate An SQL Statement
  4098   4237   ** METHOD: sqlite3_stmt
  4099   4238   **
  4100   4239   ** After a [prepared statement] has been prepared using either
  4101   4240   ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
................................................................................
  4167   4306   ** We admit that this is a goofy design.  The problem has been fixed
  4168   4307   ** with the "v2" interface.  If you prepare all of your SQL statements
  4169   4308   ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  4170   4309   ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  4171   4310   ** then the more specific [error codes] are returned directly
  4172   4311   ** by sqlite3_step().  The use of the "v2" interface is recommended.
  4173   4312   */
  4174         -SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
         4313  +SQLITE_API int SQLITE_APICALL sqlite3_step(sqlite3_stmt*);
  4175   4314   
  4176   4315   /*
  4177   4316   ** CAPI3REF: Number of columns in a result set
  4178   4317   ** METHOD: sqlite3_stmt
  4179   4318   **
  4180   4319   ** ^The sqlite3_data_count(P) interface returns the number of columns in the
  4181   4320   ** current row of the result set of [prepared statement] P.
................................................................................
  4188   4327   ** will return non-zero if previous call to [sqlite3_step](P) returned
  4189   4328   ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
  4190   4329   ** where it always returns zero since each step of that multi-step
  4191   4330   ** pragma returns 0 columns of data.
  4192   4331   **
  4193   4332   ** See also: [sqlite3_column_count()]
  4194   4333   */
  4195         -SQLITE_API int SQLITE_STDCALL sqlite3_data_count(sqlite3_stmt *pStmt);
         4334  +SQLITE_API int SQLITE_APICALL sqlite3_data_count(sqlite3_stmt *pStmt);
  4196   4335   
  4197   4336   /*
  4198   4337   ** CAPI3REF: Fundamental Datatypes
  4199   4338   ** KEYWORDS: SQLITE_TEXT
  4200   4339   **
  4201   4340   ** ^(Every value in SQLite has one of five fundamental datatypes:
  4202   4341   **
................................................................................
  4378   4517   **
  4379   4518   ** ^(If a memory allocation error occurs during the evaluation of any
  4380   4519   ** of these routines, a default value is returned.  The default value
  4381   4520   ** is either the integer 0, the floating point number 0.0, or a NULL
  4382   4521   ** pointer.  Subsequent calls to [sqlite3_errcode()] will return
  4383   4522   ** [SQLITE_NOMEM].)^
  4384   4523   */
  4385         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_blob(sqlite3_stmt*, int iCol);
  4386         -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  4387         -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  4388         -SQLITE_API double SQLITE_STDCALL sqlite3_column_double(sqlite3_stmt*, int iCol);
  4389         -SQLITE_API int SQLITE_STDCALL sqlite3_column_int(sqlite3_stmt*, int iCol);
  4390         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_column_int64(sqlite3_stmt*, int iCol);
  4391         -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_column_text(sqlite3_stmt*, int iCol);
  4392         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_text16(sqlite3_stmt*, int iCol);
  4393         -SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
  4394         -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
         4524  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_blob(sqlite3_stmt*, int iCol);
         4525  +SQLITE_API int SQLITE_APICALL sqlite3_column_bytes(sqlite3_stmt*, int iCol);
         4526  +SQLITE_API int SQLITE_APICALL sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
         4527  +SQLITE_API double SQLITE_APICALL sqlite3_column_double(sqlite3_stmt*, int iCol);
         4528  +SQLITE_API int SQLITE_APICALL sqlite3_column_int(sqlite3_stmt*, int iCol);
         4529  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_column_int64(sqlite3_stmt*, int iCol);
         4530  +SQLITE_API const unsigned char *SQLITE_APICALL sqlite3_column_text(sqlite3_stmt*, int iCol);
         4531  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_text16(sqlite3_stmt*, int iCol);
         4532  +SQLITE_API int SQLITE_APICALL sqlite3_column_type(sqlite3_stmt*, int iCol);
         4533  +SQLITE_API sqlite3_value *SQLITE_APICALL sqlite3_column_value(sqlite3_stmt*, int iCol);
  4395   4534   
  4396   4535   /*
  4397   4536   ** CAPI3REF: Destroy A Prepared Statement Object
  4398   4537   ** DESTRUCTOR: sqlite3_stmt
  4399   4538   **
  4400   4539   ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
  4401   4540   ** ^If the most recent evaluation of the statement encountered no errors
................................................................................
  4415   4554   **
  4416   4555   ** The application must finalize every [prepared statement] in order to avoid
  4417   4556   ** resource leaks.  It is a grievous error for the application to try to use
  4418   4557   ** a prepared statement after it has been finalized.  Any use of a prepared
  4419   4558   ** statement after it has been finalized can result in undefined and
  4420   4559   ** undesirable behavior such as segfaults and heap corruption.
  4421   4560   */
  4422         -SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
         4561  +SQLITE_API int SQLITE_APICALL sqlite3_finalize(sqlite3_stmt *pStmt);
  4423   4562   
  4424   4563   /*
  4425   4564   ** CAPI3REF: Reset A Prepared Statement Object
  4426   4565   ** METHOD: sqlite3_stmt
  4427   4566   **
  4428   4567   ** The sqlite3_reset() function is called to reset a [prepared statement]
  4429   4568   ** object back to its initial state, ready to be re-executed.
................................................................................
  4442   4581   ** ^If the most recent call to [sqlite3_step(S)] for the
  4443   4582   ** [prepared statement] S indicated an error, then
  4444   4583   ** [sqlite3_reset(S)] returns an appropriate [error code].
  4445   4584   **
  4446   4585   ** ^The [sqlite3_reset(S)] interface does not change the values
  4447   4586   ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  4448   4587   */
  4449         -SQLITE_API int SQLITE_STDCALL sqlite3_reset(sqlite3_stmt *pStmt);
         4588  +SQLITE_API int SQLITE_APICALL sqlite3_reset(sqlite3_stmt *pStmt);
  4450   4589   
  4451   4590   /*
  4452   4591   ** CAPI3REF: Create Or Redefine SQL Functions
  4453   4592   ** KEYWORDS: {function creation routines}
  4454   4593   ** KEYWORDS: {application-defined SQL function}
  4455   4594   ** KEYWORDS: {application-defined SQL functions}
  4456   4595   ** METHOD: sqlite3
................................................................................
  4542   4681   ** ^Built-in functions may be overloaded by new application-defined functions.
  4543   4682   **
  4544   4683   ** ^An application-defined function is permitted to call other
  4545   4684   ** SQLite interfaces.  However, such calls must not
  4546   4685   ** close the database connection nor finalize or reset the prepared
  4547   4686   ** statement in which the function is running.
  4548   4687   */
  4549         -SQLITE_API int SQLITE_STDCALL sqlite3_create_function(
         4688  +SQLITE_API int SQLITE_APICALL sqlite3_create_function(
  4550   4689     sqlite3 *db,
  4551   4690     const char *zFunctionName,
  4552   4691     int nArg,
  4553   4692     int eTextRep,
  4554   4693     void *pApp,
  4555         -  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4556         -  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4557         -  void (*xFinal)(sqlite3_context*)
         4694  +  void (SQLITE_CALLBACK *xFunc)(sqlite3_context*,int,sqlite3_value**),
         4695  +  void (SQLITE_CALLBACK *xStep)(sqlite3_context*,int,sqlite3_value**),
         4696  +  void (SQLITE_CALLBACK *xFinal)(sqlite3_context*)
  4558   4697   );
  4559         -SQLITE_API int SQLITE_STDCALL sqlite3_create_function16(
         4698  +SQLITE_API int SQLITE_APICALL sqlite3_create_function16(
  4560   4699     sqlite3 *db,
  4561   4700     const void *zFunctionName,
  4562   4701     int nArg,
  4563   4702     int eTextRep,
  4564   4703     void *pApp,
  4565         -  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4566         -  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4567         -  void (*xFinal)(sqlite3_context*)
         4704  +  void (SQLITE_CALLBACK *xFunc)(sqlite3_context*,int,sqlite3_value**),
         4705  +  void (SQLITE_CALLBACK *xStep)(sqlite3_context*,int,sqlite3_value**),
         4706  +  void (SQLITE_CALLBACK *xFinal)(sqlite3_context*)
  4568   4707   );
  4569         -SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2(
         4708  +SQLITE_API int SQLITE_APICALL sqlite3_create_function_v2(
  4570   4709     sqlite3 *db,
  4571   4710     const char *zFunctionName,
  4572   4711     int nArg,
  4573   4712     int eTextRep,
  4574   4713     void *pApp,
  4575         -  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  4576         -  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  4577         -  void (*xFinal)(sqlite3_context*),
  4578         -  void(*xDestroy)(void*)
         4714  +  void (SQLITE_CALLBACK *xFunc)(sqlite3_context*,int,sqlite3_value**),
         4715  +  void (SQLITE_CALLBACK *xStep)(sqlite3_context*,int,sqlite3_value**),
         4716  +  void (SQLITE_CALLBACK *xFinal)(sqlite3_context*),
         4717  +  void(SQLITE_CALLBACK *xDestroy)(void*)
  4579   4718   );
  4580   4719   
  4581   4720   /*
  4582   4721   ** CAPI3REF: Text Encodings
  4583   4722   **
  4584   4723   ** These constant define integer codes that represent the various
  4585   4724   ** text encodings supported by SQLite.
................................................................................
  4608   4747   ** These functions are [deprecated].  In order to maintain
  4609   4748   ** backwards compatibility with older code, these functions continue 
  4610   4749   ** to be supported.  However, new applications should avoid
  4611   4750   ** the use of these functions.  To encourage programmers to avoid
  4612   4751   ** these functions, we will not explain what they do.
  4613   4752   */
  4614   4753   #ifndef SQLITE_OMIT_DEPRECATED
  4615         -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context*);
  4616         -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_expired(sqlite3_stmt*);
  4617         -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  4618         -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_global_recover(void);
  4619         -SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_thread_cleanup(void);
  4620         -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
         4754  +SQLITE_API SQLITE_DEPRECATED int SQLITE_APICALL sqlite3_aggregate_count(sqlite3_context*);
         4755  +SQLITE_API SQLITE_DEPRECATED int SQLITE_APICALL sqlite3_expired(sqlite3_stmt*);
         4756  +SQLITE_API SQLITE_DEPRECATED int SQLITE_APICALL sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
         4757  +SQLITE_API SQLITE_DEPRECATED int SQLITE_APICALL sqlite3_global_recover(void);
         4758  +SQLITE_API SQLITE_DEPRECATED void SQLITE_APICALL sqlite3_thread_cleanup(void);
         4759  +SQLITE_API SQLITE_DEPRECATED int SQLITE_APICALL sqlite3_memory_alarm(void(SQLITE_CALLBACK *)(void*,sqlite3_int64,int),
  4621   4760                         void*,sqlite3_int64);
  4622   4761   #endif
  4623   4762   
  4624   4763   /*
  4625   4764   ** CAPI3REF: Obtaining SQL Values
  4626   4765   ** METHOD: sqlite3_value
  4627   4766   **
................................................................................
  4663   4802   ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  4664   4803   ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  4665   4804   ** or [sqlite3_value_text16()].
  4666   4805   **
  4667   4806   ** These routines must be called from the same thread as
  4668   4807   ** the SQL function that supplied the [sqlite3_value*] parameters.
  4669   4808   */
  4670         -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value*);
  4671         -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes(sqlite3_value*);
  4672         -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes16(sqlite3_value*);
  4673         -SQLITE_API double SQLITE_STDCALL sqlite3_value_double(sqlite3_value*);
  4674         -SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value*);
  4675         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value*);
  4676         -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value*);
  4677         -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16(sqlite3_value*);
  4678         -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
  4679         -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
  4680         -SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
  4681         -SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
         4809  +SQLITE_API const void *SQLITE_APICALL sqlite3_value_blob(sqlite3_value*);
         4810  +SQLITE_API int SQLITE_APICALL sqlite3_value_bytes(sqlite3_value*);
         4811  +SQLITE_API int SQLITE_APICALL sqlite3_value_bytes16(sqlite3_value*);
         4812  +SQLITE_API double SQLITE_APICALL sqlite3_value_double(sqlite3_value*);
         4813  +SQLITE_API int SQLITE_APICALL sqlite3_value_int(sqlite3_value*);
         4814  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_value_int64(sqlite3_value*);
         4815  +SQLITE_API const unsigned char *SQLITE_APICALL sqlite3_value_text(sqlite3_value*);
         4816  +SQLITE_API const void *SQLITE_APICALL sqlite3_value_text16(sqlite3_value*);
         4817  +SQLITE_API const void *SQLITE_APICALL sqlite3_value_text16le(sqlite3_value*);
         4818  +SQLITE_API const void *SQLITE_APICALL sqlite3_value_text16be(sqlite3_value*);
         4819  +SQLITE_API int SQLITE_APICALL sqlite3_value_type(sqlite3_value*);
         4820  +SQLITE_API int SQLITE_APICALL sqlite3_value_numeric_type(sqlite3_value*);
  4682   4821   
  4683   4822   /*
  4684   4823   ** CAPI3REF: Finding The Subtype Of SQL Values
  4685   4824   ** METHOD: sqlite3_value
  4686   4825   **
  4687   4826   ** The sqlite3_value_subtype(V) function returns the subtype for
  4688   4827   ** an [application-defined SQL function] argument V.  The subtype
................................................................................
  4690   4829   ** one SQL function to another.  Use the [sqlite3_result_subtype()]
  4691   4830   ** routine to set the subtype for the return value of an SQL function.
  4692   4831   **
  4693   4832   ** SQLite makes no use of subtype itself.  It merely passes the subtype
  4694   4833   ** from the result of one [application-defined SQL function] into the
  4695   4834   ** input of another.
  4696   4835   */
  4697         -SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value*);
         4836  +SQLITE_API unsigned int SQLITE_APICALL sqlite3_value_subtype(sqlite3_value*);
  4698   4837   
  4699   4838   /*
  4700   4839   ** CAPI3REF: Copy And Free SQL Values
  4701   4840   ** METHOD: sqlite3_value
  4702   4841   **
  4703   4842   ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
  4704   4843   ** object D and returns a pointer to that copy.  ^The [sqlite3_value] returned
................................................................................
  4706   4845   ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
  4707   4846   ** memory allocation fails.
  4708   4847   **
  4709   4848   ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
  4710   4849   ** previously obtained from [sqlite3_value_dup()].  ^If V is a NULL pointer
  4711   4850   ** then sqlite3_value_free(V) is a harmless no-op.
  4712   4851   */
  4713         -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_value_dup(const sqlite3_value*);
  4714         -SQLITE_API void SQLITE_STDCALL sqlite3_value_free(sqlite3_value*);
         4852  +SQLITE_API sqlite3_value *SQLITE_APICALL sqlite3_value_dup(const sqlite3_value*);
         4853  +SQLITE_API void SQLITE_APICALL sqlite3_value_free(sqlite3_value*);
  4715   4854   
  4716   4855   /*
  4717   4856   ** CAPI3REF: Obtain Aggregate Function Context
  4718   4857   ** METHOD: sqlite3_context
  4719   4858   **
  4720   4859   ** Implementations of aggregate SQL functions use this
  4721   4860   ** routine to allocate memory for storing their state.
................................................................................
  4752   4891   ** [sqlite3_context | SQL function context] that is the first parameter
  4753   4892   ** to the xStep or xFinal callback routine that implements the aggregate
  4754   4893   ** function.
  4755   4894   **
  4756   4895   ** This routine must be called from the same thread in which
  4757   4896   ** the aggregate SQL function is running.
  4758   4897   */
  4759         -SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
         4898  +SQLITE_API void *SQLITE_APICALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  4760   4899   
  4761   4900   /*
  4762   4901   ** CAPI3REF: User Data For Functions
  4763   4902   ** METHOD: sqlite3_context
  4764   4903   **
  4765   4904   ** ^The sqlite3_user_data() interface returns a copy of
  4766   4905   ** the pointer that was the pUserData parameter (the 5th parameter)
................................................................................
  4767   4906   ** of the [sqlite3_create_function()]
  4768   4907   ** and [sqlite3_create_function16()] routines that originally
  4769   4908   ** registered the application defined function.
  4770   4909   **
  4771   4910   ** This routine must be called from the same thread in which
  4772   4911   ** the application-defined function is running.
  4773   4912   */
  4774         -SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
         4913  +SQLITE_API void *SQLITE_APICALL sqlite3_user_data(sqlite3_context*);
  4775   4914   
  4776   4915   /*
  4777   4916   ** CAPI3REF: Database Connection For Functions
  4778   4917   ** METHOD: sqlite3_context
  4779   4918   **
  4780   4919   ** ^The sqlite3_context_db_handle() interface returns a copy of
  4781   4920   ** the pointer to the [database connection] (the 1st parameter)
  4782   4921   ** of the [sqlite3_create_function()]
  4783   4922   ** and [sqlite3_create_function16()] routines that originally
  4784   4923   ** registered the application defined function.
  4785   4924   */
  4786         -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
         4925  +SQLITE_API sqlite3 *SQLITE_APICALL sqlite3_context_db_handle(sqlite3_context*);
  4787   4926   
  4788   4927   /*
  4789   4928   ** CAPI3REF: Function Auxiliary Data
  4790   4929   ** METHOD: sqlite3_context
  4791   4930   **
  4792   4931   ** These functions may be used by (non-aggregate) SQL functions to
  4793   4932   ** associate metadata with argument values. If the same value is passed to
................................................................................
  4832   4971   ** ^(In practice, metadata is preserved between function calls for
  4833   4972   ** function parameters that are compile-time constants, including literal
  4834   4973   ** values and [parameters] and expressions composed from the same.)^
  4835   4974   **
  4836   4975   ** These routines must be called from the same thread in which
  4837   4976   ** the SQL function is running.
  4838   4977   */
  4839         -SQLITE_API void *SQLITE_STDCALL sqlite3_get_auxdata(sqlite3_context*, int N);
  4840         -SQLITE_API void SQLITE_STDCALL sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
         4978  +SQLITE_API void *SQLITE_APICALL sqlite3_get_auxdata(sqlite3_context*, int N);
         4979  +SQLITE_API void SQLITE_APICALL sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (SQLITE_CALLBACK *)(void*));
  4841   4980   
  4842   4981   
  4843   4982   /*
  4844   4983   ** CAPI3REF: Constants Defining Special Destructor Behavior
  4845   4984   **
  4846   4985   ** These are special values for the destructor that is passed in as the
  4847   4986   ** final argument to routines like [sqlite3_result_blob()].  ^If the destructor
................................................................................
  4850   4989   ** SQLITE_TRANSIENT value means that the content will likely change in
  4851   4990   ** the near future and that SQLite should make its own private copy of
  4852   4991   ** the content before returning.
  4853   4992   **
  4854   4993   ** The typedef is necessary to work around problems in certain
  4855   4994   ** C++ compilers.
  4856   4995   */
  4857         -typedef void (*sqlite3_destructor_type)(void*);
         4996  +typedef void (SQLITE_CALLBACK *sqlite3_destructor_type)(void*);
  4858   4997   #define SQLITE_STATIC      ((sqlite3_destructor_type)0)
  4859   4998   #define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
  4860   4999   
  4861   5000   /*
  4862   5001   ** CAPI3REF: Setting The Result Of An SQL Function
  4863   5002   ** METHOD: sqlite3_context
  4864   5003   **
................................................................................
  4969   5108   ** [unprotected sqlite3_value] object is required, so either
  4970   5109   ** kind of [sqlite3_value] object can be used with this interface.
  4971   5110   **
  4972   5111   ** If these routines are called from within the different thread
  4973   5112   ** than the one containing the application-defined function that received
  4974   5113   ** the [sqlite3_context] pointer, the results are undefined.
  4975   5114   */
  4976         -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  4977         -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob64(sqlite3_context*,const void*,
  4978         -                           sqlite3_uint64,void(*)(void*));
  4979         -SQLITE_API void SQLITE_STDCALL sqlite3_result_double(sqlite3_context*, double);
  4980         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error(sqlite3_context*, const char*, int);
  4981         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error16(sqlite3_context*, const void*, int);
  4982         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_toobig(sqlite3_context*);
  4983         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_nomem(sqlite3_context*);
  4984         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context*, int);
  4985         -SQLITE_API void SQLITE_STDCALL sqlite3_result_int(sqlite3_context*, int);
  4986         -SQLITE_API void SQLITE_STDCALL sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  4987         -SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context*);
  4988         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  4989         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
  4990         -                           void(*)(void*), unsigned char encoding);
  4991         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  4992         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  4993         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  4994         -SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  4995         -SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
  4996         -SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
         5115  +SQLITE_API void SQLITE_APICALL sqlite3_result_blob(sqlite3_context*, const void*, int, void(SQLITE_CALLBACK *)(void*));
         5116  +SQLITE_API void SQLITE_APICALL sqlite3_result_blob64(sqlite3_context*,const void*,
         5117  +                           sqlite3_uint64,void(SQLITE_CALLBACK *)(void*));
         5118  +SQLITE_API void SQLITE_APICALL sqlite3_result_double(sqlite3_context*, double);
         5119  +SQLITE_API void SQLITE_APICALL sqlite3_result_error(sqlite3_context*, const char*, int);
         5120  +SQLITE_API void SQLITE_APICALL sqlite3_result_error16(sqlite3_context*, const void*, int);
         5121  +SQLITE_API void SQLITE_APICALL sqlite3_result_error_toobig(sqlite3_context*);
         5122  +SQLITE_API void SQLITE_APICALL sqlite3_result_error_nomem(sqlite3_context*);
         5123  +SQLITE_API void SQLITE_APICALL sqlite3_result_error_code(sqlite3_context*, int);
         5124  +SQLITE_API void SQLITE_APICALL sqlite3_result_int(sqlite3_context*, int);
         5125  +SQLITE_API void SQLITE_APICALL sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
         5126  +SQLITE_API void SQLITE_APICALL sqlite3_result_null(sqlite3_context*);
         5127  +SQLITE_API void SQLITE_APICALL sqlite3_result_text(sqlite3_context*, const char*, int, void(SQLITE_CALLBACK *)(void*));
         5128  +SQLITE_API void SQLITE_APICALL sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
         5129  +                           void(SQLITE_CALLBACK *)(void*), unsigned char encoding);
         5130  +SQLITE_API void SQLITE_APICALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(SQLITE_CALLBACK *)(void*));
         5131  +SQLITE_API void SQLITE_APICALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(SQLITE_CALLBACK *)(void*));
         5132  +SQLITE_API void SQLITE_APICALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(SQLITE_CALLBACK *)(void*));
         5133  +SQLITE_API void SQLITE_APICALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
         5134  +SQLITE_API void SQLITE_APICALL sqlite3_result_zeroblob(sqlite3_context*, int n);
         5135  +SQLITE_API int SQLITE_APICALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
  4997   5136   
  4998   5137   
  4999   5138   /*
  5000   5139   ** CAPI3REF: Setting The Subtype Of An SQL Function
  5001   5140   ** METHOD: sqlite3_context
  5002   5141   **
  5003   5142   ** The sqlite3_result_subtype(C,T) function causes the subtype of
................................................................................
  5004   5143   ** the result from the [application-defined SQL function] with 
  5005   5144   ** [sqlite3_context] C to be the value T.  Only the lower 8 bits 
  5006   5145   ** of the subtype T are preserved in current versions of SQLite;
  5007   5146   ** higher order bits are discarded.
  5008   5147   ** The number of subtype bytes preserved by SQLite might increase
  5009   5148   ** in future releases of SQLite.
  5010   5149   */
  5011         -SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context*,unsigned int);
         5150  +SQLITE_API void SQLITE_APICALL sqlite3_result_subtype(sqlite3_context*,unsigned int);
  5012   5151   
  5013   5152   /*
  5014   5153   ** CAPI3REF: Define New Collating Sequences
  5015   5154   ** METHOD: sqlite3
  5016   5155   **
  5017   5156   ** ^These functions add, remove, or modify a [collation] associated
  5018   5157   ** with the [database connection] specified as the first argument.
................................................................................
  5086   5225   ** themselves rather than expecting SQLite to deal with it for them.
  5087   5226   ** This is different from every other SQLite interface.  The inconsistency 
  5088   5227   ** is unfortunate but cannot be changed without breaking backwards 
  5089   5228   ** compatibility.
  5090   5229   **
  5091   5230   ** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
  5092   5231   */
  5093         -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation(
         5232  +SQLITE_API int SQLITE_APICALL sqlite3_create_collation(
  5094   5233     sqlite3*, 
  5095   5234     const char *zName, 
  5096   5235     int eTextRep, 
  5097   5236     void *pArg,
  5098         -  int(*xCompare)(void*,int,const void*,int,const void*)
         5237  +  int(SQLITE_CALLBACK *xCompare)(void*,int,const void*,int,const void*)
  5099   5238   );
  5100         -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation_v2(
         5239  +SQLITE_API int SQLITE_APICALL sqlite3_create_collation_v2(
  5101   5240     sqlite3*, 
  5102   5241     const char *zName, 
  5103   5242     int eTextRep, 
  5104   5243     void *pArg,
  5105         -  int(*xCompare)(void*,int,const void*,int,const void*),
  5106         -  void(*xDestroy)(void*)
         5244  +  int(SQLITE_CALLBACK *xCompare)(void*,int,const void*,int,const void*),
         5245  +  void(SQLITE_CALLBACK *xDestroy)(void*)
  5107   5246   );
  5108         -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation16(
         5247  +SQLITE_API int SQLITE_APICALL sqlite3_create_collation16(
  5109   5248     sqlite3*, 
  5110   5249     const void *zName,
  5111   5250     int eTextRep, 
  5112   5251     void *pArg,
  5113         -  int(*xCompare)(void*,int,const void*,int,const void*)
         5252  +  int(SQLITE_CALLBACK *xCompare)(void*,int,const void*,int,const void*)
  5114   5253   );
  5115   5254   
  5116   5255   /*
  5117   5256   ** CAPI3REF: Collation Needed Callbacks
  5118   5257   ** METHOD: sqlite3
  5119   5258   **
  5120   5259   ** ^To avoid having to register all collation sequences before a database
................................................................................
  5136   5275   ** sequence function required.  The fourth parameter is the name of the
  5137   5276   ** required collation sequence.)^
  5138   5277   **
  5139   5278   ** The callback function should register the desired collation using
  5140   5279   ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  5141   5280   ** [sqlite3_create_collation_v2()].
  5142   5281   */
  5143         -SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed(
         5282  +SQLITE_API int SQLITE_APICALL sqlite3_collation_needed(
  5144   5283     sqlite3*, 
  5145   5284     void*, 
  5146         -  void(*)(void*,sqlite3*,int eTextRep,const char*)
         5285  +  void(SQLITE_CALLBACK *)(void*,sqlite3*,int eTextRep,const char*)
  5147   5286   );
  5148         -SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed16(
         5287  +SQLITE_API int SQLITE_APICALL sqlite3_collation_needed16(
  5149   5288     sqlite3*, 
  5150   5289     void*,
  5151         -  void(*)(void*,sqlite3*,int eTextRep,const void*)
         5290  +  void(SQLITE_CALLBACK *)(void*,sqlite3*,int eTextRep,const void*)
  5152   5291   );
  5153   5292   
  5154   5293   #ifdef SQLITE_HAS_CODEC
  5155   5294   /*
  5156   5295   ** Specify the key for an encrypted database.  This routine should be
  5157   5296   ** called right after sqlite3_open().
  5158   5297   **
  5159   5298   ** The code to implement this API is not available in the public release
  5160   5299   ** of SQLite.
  5161   5300   */
  5162         -SQLITE_API int SQLITE_STDCALL sqlite3_key(
         5301  +SQLITE_API int SQLITE_APICALL sqlite3_key(
  5163   5302     sqlite3 *db,                   /* Database to be rekeyed */
  5164   5303     const void *pKey, int nKey     /* The key */
  5165   5304   );
  5166         -SQLITE_API int SQLITE_STDCALL sqlite3_key_v2(
         5305  +SQLITE_API int SQLITE_APICALL sqlite3_key_v2(
  5167   5306     sqlite3 *db,                   /* Database to be rekeyed */
  5168   5307     const char *zDbName,           /* Name of the database */
  5169   5308     const void *pKey, int nKey     /* The key */
  5170   5309   );
  5171   5310   
  5172   5311   /*
  5173   5312   ** Change the key on an open database.  If the current database is not
  5174   5313   ** encrypted, this routine will encrypt it.  If pNew==0 or nNew==0, the
  5175   5314   ** database is decrypted.
  5176   5315   **
  5177   5316   ** The code to implement this API is not available in the public release
  5178   5317   ** of SQLite.
  5179   5318   */
  5180         -SQLITE_API int SQLITE_STDCALL sqlite3_rekey(
         5319  +SQLITE_API int SQLITE_APICALL sqlite3_rekey(
  5181   5320     sqlite3 *db,                   /* Database to be rekeyed */
  5182   5321     const void *pKey, int nKey     /* The new key */
  5183   5322   );
  5184         -SQLITE_API int SQLITE_STDCALL sqlite3_rekey_v2(
         5323  +SQLITE_API int SQLITE_APICALL sqlite3_rekey_v2(
  5185   5324     sqlite3 *db,                   /* Database to be rekeyed */
  5186   5325     const char *zDbName,           /* Name of the database */
  5187   5326     const void *pKey, int nKey     /* The new key */
  5188   5327   );
  5189   5328   
  5190   5329   /*
  5191   5330   ** Specify the activation key for a SEE database.  Unless 
  5192   5331   ** activated, none of the SEE routines will work.
  5193   5332   */
  5194         -SQLITE_API void SQLITE_STDCALL sqlite3_activate_see(
         5333  +SQLITE_API void SQLITE_APICALL sqlite3_activate_see(
  5195   5334     const char *zPassPhrase        /* Activation phrase */
  5196   5335   );
  5197   5336   #endif
  5198   5337   
  5199   5338   #ifdef SQLITE_ENABLE_CEROD
  5200   5339   /*
  5201   5340   ** Specify the activation key for a CEROD database.  Unless 
  5202   5341   ** activated, none of the CEROD routines will work.
  5203   5342   */
  5204         -SQLITE_API void SQLITE_STDCALL sqlite3_activate_cerod(
         5343  +SQLITE_API void SQLITE_APICALL sqlite3_activate_cerod(
  5205   5344     const char *zPassPhrase        /* Activation phrase */
  5206   5345   );
  5207   5346   #endif
  5208   5347   
  5209   5348   /*
  5210   5349   ** CAPI3REF: Suspend Execution For A Short Time
  5211   5350   **
................................................................................
  5219   5358   **
  5220   5359   ** ^SQLite implements this interface by calling the xSleep()
  5221   5360   ** method of the default [sqlite3_vfs] object.  If the xSleep() method
  5222   5361   ** of the default VFS is not implemented correctly, or not implemented at
  5223   5362   ** all, then the behavior of sqlite3_sleep() may deviate from the description
  5224   5363   ** in the previous paragraphs.
  5225   5364   */
  5226         -SQLITE_API int SQLITE_STDCALL sqlite3_sleep(int);
         5365  +SQLITE_API int SQLITE_APICALL sqlite3_sleep(int);
  5227   5366   
  5228   5367   /*
  5229   5368   ** CAPI3REF: Name Of The Folder Holding Temporary Files
  5230   5369   **
  5231   5370   ** ^(If this global variable is made to point to a string which is
  5232   5371   ** the name of a folder (a.k.a. directory), then all temporary files
  5233   5372   ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
................................................................................
  5338   5477   ** find out whether SQLite automatically rolled back the transaction after
  5339   5478   ** an error is to use this function.
  5340   5479   **
  5341   5480   ** If another thread changes the autocommit status of the database
  5342   5481   ** connection while this routine is running, then the return value
  5343   5482   ** is undefined.
  5344   5483   */
  5345         -SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
         5484  +SQLITE_API int SQLITE_APICALL sqlite3_get_autocommit(sqlite3*);
  5346   5485   
  5347   5486   /*
  5348   5487   ** CAPI3REF: Find The Database Handle Of A Prepared Statement
  5349   5488   ** METHOD: sqlite3_stmt
  5350   5489   **
  5351   5490   ** ^The sqlite3_db_handle interface returns the [database connection] handle
  5352   5491   ** to which a [prepared statement] belongs.  ^The [database connection]
  5353   5492   ** returned by sqlite3_db_handle is the same [database connection]
  5354   5493   ** that was the first argument
  5355   5494   ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  5356   5495   ** create the statement in the first place.
  5357   5496   */
  5358         -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
         5497  +SQLITE_API sqlite3 *SQLITE_APICALL sqlite3_db_handle(sqlite3_stmt*);
  5359   5498   
  5360   5499   /*
  5361   5500   ** CAPI3REF: Return The Filename For A Database Connection
  5362   5501   ** METHOD: sqlite3
  5363   5502   **
  5364   5503   ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
  5365   5504   ** associated with database N of connection D.  ^The main database file
................................................................................
  5368   5507   ** a NULL pointer is returned.
  5369   5508   **
  5370   5509   ** ^The filename returned by this function is the output of the
  5371   5510   ** xFullPathname method of the [VFS].  ^In other words, the filename
  5372   5511   ** will be an absolute pathname, even if the filename used
  5373   5512   ** to open the database originally was a URI or relative pathname.
  5374   5513   */
  5375         -SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
         5514  +SQLITE_API const char *SQLITE_APICALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
  5376   5515   
  5377   5516   /*
  5378   5517   ** CAPI3REF: Determine if a database is read-only
  5379   5518   ** METHOD: sqlite3
  5380   5519   **
  5381   5520   ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
  5382   5521   ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
  5383   5522   ** the name of a database on connection D.
  5384   5523   */
  5385         -SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
         5524  +SQLITE_API int SQLITE_APICALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
  5386   5525   
  5387   5526   /*
  5388   5527   ** CAPI3REF: Find the next prepared statement
  5389   5528   ** METHOD: sqlite3
  5390   5529   **
  5391   5530   ** ^This interface returns a pointer to the next [prepared statement] after
  5392   5531   ** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
................................................................................
  5394   5533   ** associated with the database connection pDb.  ^If no prepared statement
  5395   5534   ** satisfies the conditions of this routine, it returns NULL.
  5396   5535   **
  5397   5536   ** The [database connection] pointer D in a call to
  5398   5537   ** [sqlite3_next_stmt(D,S)] must refer to an open database
  5399   5538   ** connection and in particular must not be a NULL pointer.
  5400   5539   */
  5401         -SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
         5540  +SQLITE_API sqlite3_stmt *SQLITE_APICALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  5402   5541   
  5403   5542   /*
  5404   5543   ** CAPI3REF: Commit And Rollback Notification Callbacks
  5405   5544   ** METHOD: sqlite3
  5406   5545   **
  5407   5546   ** ^The sqlite3_commit_hook() interface registers a callback
  5408   5547   ** function to be invoked whenever a transaction is [COMMIT | committed].
................................................................................
  5443   5582   ** rolled back if an explicit "ROLLBACK" statement is executed, or
  5444   5583   ** an error or constraint causes an implicit rollback to occur.
  5445   5584   ** ^The rollback callback is not invoked if a transaction is
  5446   5585   ** automatically rolled back because the database connection is closed.
  5447   5586   **
  5448   5587   ** See also the [sqlite3_update_hook()] interface.
  5449   5588   */
  5450         -SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  5451         -SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
         5589  +SQLITE_API void *SQLITE_APICALL sqlite3_commit_hook(sqlite3*, int(SQLITE_CALLBACK *)(void*), void*);
         5590  +SQLITE_API void *SQLITE_APICALL sqlite3_rollback_hook(sqlite3*, void(SQLITE_CALLBACK *)(void *), void*);
  5452   5591   
  5453   5592   /*
  5454   5593   ** CAPI3REF: Data Change Notification Callbacks
  5455   5594   ** METHOD: sqlite3
  5456   5595   **
  5457   5596   ** ^The sqlite3_update_hook() interface registers a callback function
  5458   5597   ** with the [database connection] identified by the first argument
................................................................................
  5495   5634   ** returns the P argument from the previous call
  5496   5635   ** on the same [database connection] D, or NULL for
  5497   5636   ** the first call on D.
  5498   5637   **
  5499   5638   ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
  5500   5639   ** and [sqlite3_preupdate_hook()] interfaces.
  5501   5640   */
  5502         -SQLITE_API void *SQLITE_STDCALL sqlite3_update_hook(
         5641  +SQLITE_API void *SQLITE_APICALL sqlite3_update_hook(
  5503   5642     sqlite3*, 
  5504         -  void(*)(void *,int ,char const *,char const *,sqlite3_int64),
         5643  +  void(SQLITE_CALLBACK *)(void *,int ,char const *,char const *,sqlite3_int64),
  5505   5644     void*
  5506   5645   );
  5507   5646   
  5508   5647   /*
  5509   5648   ** CAPI3REF: Enable Or Disable Shared Pager Cache
  5510   5649   **
  5511   5650   ** ^(This routine enables or disables the sharing of the database cache
................................................................................
  5535   5674   ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
  5536   5675   **
  5537   5676   ** This interface is threadsafe on processors where writing a
  5538   5677   ** 32-bit integer is atomic.
  5539   5678   **
  5540   5679   ** See Also:  [SQLite Shared-Cache Mode]
  5541   5680   */
  5542         -SQLITE_API int SQLITE_STDCALL sqlite3_enable_shared_cache(int);
         5681  +SQLITE_API int SQLITE_APICALL sqlite3_enable_shared_cache(int);
  5543   5682   
  5544   5683   /*
  5545   5684   ** CAPI3REF: Attempt To Free Heap Memory
  5546   5685   **
  5547   5686   ** ^The sqlite3_release_memory() interface attempts to free N bytes
  5548   5687   ** of heap memory by deallocating non-essential memory allocations
  5549   5688   ** held by the database library.   Memory used to cache database
................................................................................
  5551   5690   ** ^sqlite3_release_memory() returns the number of bytes actually freed,
  5552   5691   ** which might be more or less than the amount requested.
  5553   5692   ** ^The sqlite3_release_memory() routine is a no-op returning zero
  5554   5693   ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  5555   5694   **
  5556   5695   ** See also: [sqlite3_db_release_memory()]
  5557   5696   */
  5558         -SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
         5697  +SQLITE_API int SQLITE_APICALL sqlite3_release_memory(int);
  5559   5698   
  5560   5699   /*
  5561   5700   ** CAPI3REF: Free Memory Used By A Database Connection
  5562   5701   ** METHOD: sqlite3
  5563   5702   **
  5564   5703   ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
  5565   5704   ** memory as possible from database connection D. Unlike the
  5566   5705   ** [sqlite3_release_memory()] interface, this interface is in effect even
  5567   5706   ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
  5568   5707   ** omitted.
  5569   5708   **
  5570   5709   ** See also: [sqlite3_release_memory()]
  5571   5710   */
  5572         -SQLITE_API int SQLITE_STDCALL sqlite3_db_release_memory(sqlite3*);
         5711  +SQLITE_API int SQLITE_APICALL sqlite3_db_release_memory(sqlite3*);
  5573   5712   
  5574   5713   /*
  5575   5714   ** CAPI3REF: Impose A Limit On Heap Size
  5576   5715   **
  5577   5716   ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
  5578   5717   ** soft limit on the amount of heap memory that may be allocated by SQLite.
  5579   5718   ** ^SQLite strives to keep heap memory utilization below the soft heap
................................................................................
  5617   5756   ** the page cache is the predominate memory user in SQLite, most
  5618   5757   ** applications will achieve adequate soft heap limit enforcement without
  5619   5758   ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  5620   5759   **
  5621   5760   ** The circumstances under which SQLite will enforce the soft heap limit may
  5622   5761   ** changes in future releases of SQLite.
  5623   5762   */
  5624         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 N);
         5763  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_soft_heap_limit64(sqlite3_int64 N);
  5625   5764   
  5626   5765   /*
  5627   5766   ** CAPI3REF: Deprecated Soft Heap Limit Interface
  5628   5767   ** DEPRECATED
  5629   5768   **
  5630   5769   ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
  5631   5770   ** interface.  This routine is provided for historical compatibility
  5632   5771   ** only.  All new applications should use the
  5633   5772   ** [sqlite3_soft_heap_limit64()] interface rather than this one.
  5634   5773   */
  5635         -SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
         5774  +SQLITE_API SQLITE_DEPRECATED void SQLITE_APICALL sqlite3_soft_heap_limit(int N);
  5636   5775   
  5637   5776   
  5638   5777   /*
  5639   5778   ** CAPI3REF: Extract Metadata About A Column Of A Table
  5640   5779   ** METHOD: sqlite3
  5641   5780   **
  5642   5781   ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
................................................................................
  5698   5837   **     auto increment: 0
  5699   5838   ** </pre>)^
  5700   5839   **
  5701   5840   ** ^This function causes all database schemas to be read from disk and
  5702   5841   ** parsed, if that has not already been done, and returns an error if
  5703   5842   ** any errors are encountered while loading the schema.
  5704   5843   */
  5705         -SQLITE_API int SQLITE_STDCALL sqlite3_table_column_metadata(
         5844  +SQLITE_API int SQLITE_APICALL sqlite3_table_column_metadata(
  5706   5845     sqlite3 *db,                /* Connection handle */
  5707   5846     const char *zDbName,        /* Database name or NULL */
  5708   5847     const char *zTableName,     /* Table name */
  5709   5848     const char *zColumnName,    /* Column name */
  5710   5849     char const **pzDataType,    /* OUTPUT: Declared data type */
  5711   5850     char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
  5712   5851     int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
................................................................................
  5754   5893   ** interface.  The use of the [sqlite3_enable_load_extension()] interface
  5755   5894   ** should be avoided.  This will keep the SQL function [load_extension()]
  5756   5895   ** disabled and prevent SQL injections from giving attackers
  5757   5896   ** access to extension loading capabilities.
  5758   5897   **
  5759   5898   ** See also the [load_extension() SQL function].
  5760   5899   */
  5761         -SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
         5900  +SQLITE_API int SQLITE_APICALL sqlite3_load_extension(
  5762   5901     sqlite3 *db,          /* Load the extension into this database connection */
  5763   5902     const char *zFile,    /* Name of the shared library containing extension */
  5764   5903     const char *zProc,    /* Entry point.  Derived from zFile if 0 */
  5765   5904     char **pzErrMsg       /* Put error message here if not 0 */
  5766   5905   );
  5767   5906   
  5768   5907   /*
................................................................................
  5786   5925   **
  5787   5926   ** <b>Security warning:</b> It is recommended that extension loading
  5788   5927   ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
  5789   5928   ** rather than this interface, so the [load_extension()] SQL function
  5790   5929   ** remains disabled. This will prevent SQL injections from giving attackers
  5791   5930   ** access to extension loading capabilities.
  5792   5931   */
  5793         -SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
         5932  +SQLITE_API int SQLITE_APICALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  5794   5933   
  5795   5934   /*
  5796   5935   ** CAPI3REF: Automatically Load Statically Linked Extensions
  5797   5936   **
  5798   5937   ** ^This interface causes the xEntryPoint() function to be invoked for
  5799   5938   ** each new [database connection] that is created.  The idea here is that
  5800   5939   ** xEntryPoint() is the entry point for a statically linked [SQLite extension]
................................................................................
  5824   5963   ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
  5825   5964   ** on the list of automatic extensions is a harmless no-op. ^No entry point
  5826   5965   ** will be called more than once for each database connection that is opened.
  5827   5966   **
  5828   5967   ** See also: [sqlite3_reset_auto_extension()]
  5829   5968   ** and [sqlite3_cancel_auto_extension()]
  5830   5969   */
  5831         -SQLITE_API int SQLITE_STDCALL sqlite3_auto_extension(void (*xEntryPoint)(void));
         5970  +typedef struct sqlite3_api_routines sqlite3_api_routines;
         5971  +SQLITE_API int SQLITE_APICALL sqlite3_auto_extension(
         5972  +  int (SQLITE_CALLBACK *xEntryPoint)(sqlite3 *, char **, const sqlite3_api_routines *)
         5973  +);
  5832   5974   
  5833   5975   /*
  5834   5976   ** CAPI3REF: Cancel Automatic Extension Loading
  5835   5977   **
  5836   5978   ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
  5837   5979   ** initialization routine X that was registered using a prior call to
  5838   5980   ** [sqlite3_auto_extension(X)].  ^The [sqlite3_cancel_auto_extension(X)]
  5839   5981   ** routine returns 1 if initialization routine X was successfully 
  5840   5982   ** unregistered and it returns 0 if X was not on the list of initialization
  5841   5983   ** routines.
  5842   5984   */
  5843         -SQLITE_API int SQLITE_STDCALL sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
         5985  +SQLITE_API int SQLITE_APICALL sqlite3_cancel_auto_extension(
         5986  +  int (SQLITE_CALLBACK *xEntryPoint)(sqlite3 *, char **, const sqlite3_api_routines *)
         5987  +);
  5844   5988   
  5845   5989   /*
  5846   5990   ** CAPI3REF: Reset Automatic Extension Loading
  5847   5991   **
  5848   5992   ** ^This interface disables all automatic extensions previously
  5849   5993   ** registered using [sqlite3_auto_extension()].
  5850   5994   */
  5851         -SQLITE_API void SQLITE_STDCALL sqlite3_reset_auto_extension(void);
         5995  +SQLITE_API void SQLITE_APICALL sqlite3_reset_auto_extension(void);
  5852   5996   
  5853   5997   /*
  5854   5998   ** The interface to the virtual-table mechanism is currently considered
  5855   5999   ** to be experimental.  The interface might change in incompatible ways.
  5856   6000   ** If this is a problem for you, do not use the interface at this time.
  5857   6001   **
  5858   6002   ** When the virtual-table mechanism stabilizes, we will declare the
................................................................................
  5881   6025   ** ^The registration remains valid until it is replaced by a different
  5882   6026   ** module or until the [database connection] closes.  The content
  5883   6027   ** of this structure must not change while it is registered with
  5884   6028   ** any database connection.
  5885   6029   */
  5886   6030   struct sqlite3_module {
  5887   6031     int iVersion;
  5888         -  int (*xCreate)(sqlite3*, void *pAux,
         6032  +  int (SQLITE_CALLBACK *xCreate)(sqlite3*, void *pAux,
  5889   6033                  int argc, const char *const*argv,
  5890   6034                  sqlite3_vtab **ppVTab, char**);
  5891         -  int (*xConnect)(sqlite3*, void *pAux,
         6035  +  int (SQLITE_CALLBACK *xConnect)(sqlite3*, void *pAux,
  5892   6036                  int argc, const char *const*argv,
  5893   6037                  sqlite3_vtab **ppVTab, char**);
  5894         -  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  5895         -  int (*xDisconnect)(sqlite3_vtab *pVTab);
  5896         -  int (*xDestroy)(sqlite3_vtab *pVTab);
  5897         -  int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  5898         -  int (*xClose)(sqlite3_vtab_cursor*);
  5899         -  int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
         6038  +  int (SQLITE_CALLBACK *xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
         6039  +  int (SQLITE_CALLBACK *xDisconnect)(sqlite3_vtab *pVTab);
         6040  +  int (SQLITE_CALLBACK *xDestroy)(sqlite3_vtab *pVTab);
         6041  +  int (SQLITE_CALLBACK *xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
         6042  +  int (SQLITE_CALLBACK *xClose)(sqlite3_vtab_cursor*);
         6043  +  int (SQLITE_CALLBACK *xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  5900   6044                   int argc, sqlite3_value **argv);
  5901         -  int (*xNext)(sqlite3_vtab_cursor*);
  5902         -  int (*xEof)(sqlite3_vtab_cursor*);
  5903         -  int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  5904         -  int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  5905         -  int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  5906         -  int (*xBegin)(sqlite3_vtab *pVTab);
  5907         -  int (*xSync)(sqlite3_vtab *pVTab);
  5908         -  int (*xCommit)(sqlite3_vtab *pVTab);
  5909         -  int (*xRollback)(sqlite3_vtab *pVTab);
  5910         -  int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  5911         -                       void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
         6045  +  int (SQLITE_CALLBACK *xNext)(sqlite3_vtab_cursor*);
         6046  +  int (SQLITE_CALLBACK *xEof)(sqlite3_vtab_cursor*);
         6047  +  int (SQLITE_CALLBACK *xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
         6048  +  int (SQLITE_CALLBACK *xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
         6049  +  int (SQLITE_CALLBACK *xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
         6050  +  int (SQLITE_CALLBACK *xBegin)(sqlite3_vtab *pVTab);
         6051  +  int (SQLITE_CALLBACK *xSync)(sqlite3_vtab *pVTab);
         6052  +  int (SQLITE_CALLBACK *xCommit)(sqlite3_vtab *pVTab);
         6053  +  int (SQLITE_CALLBACK *xRollback)(sqlite3_vtab *pVTab);
         6054  +  int (SQLITE_CALLBACK *xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
         6055  +                       void (SQLITE_CALLBACK **pxFunc)(sqlite3_context*,int,sqlite3_value**),
  5912   6056                          void **ppArg);
  5913         -  int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
         6057  +  int (SQLITE_CALLBACK *xRename)(sqlite3_vtab *pVtab, const char *zNew);
  5914   6058     /* The methods above are in version 1 of the sqlite_module object. Those 
  5915   6059     ** below are for version 2 and greater. */
  5916         -  int (*xSavepoint)(sqlite3_vtab *pVTab, int);
  5917         -  int (*xRelease)(sqlite3_vtab *pVTab, int);
  5918         -  int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
         6060  +  int (SQLITE_CALLBACK *xSavepoint)(sqlite3_vtab *pVTab, int);
         6061  +  int (SQLITE_CALLBACK *xRelease)(sqlite3_vtab *pVTab, int);
         6062  +  int (SQLITE_CALLBACK *xRollbackTo)(sqlite3_vtab *pVTab, int);
  5919   6063   };
  5920   6064   
  5921   6065   /*
  5922   6066   ** CAPI3REF: Virtual Table Indexing Information
  5923   6067   ** KEYWORDS: sqlite3_index_info
  5924   6068   **
  5925   6069   ** The sqlite3_index_info structure and its substructures is used as part
................................................................................
  6089   6233   ** invoke the destructor function (if it is not NULL) when SQLite
  6090   6234   ** no longer needs the pClientData pointer.  ^The destructor will also
  6091   6235   ** be invoked if the call to sqlite3_create_module_v2() fails.
  6092   6236   ** ^The sqlite3_create_module()
  6093   6237   ** interface is equivalent to sqlite3_create_module_v2() with a NULL
  6094   6238   ** destructor.
  6095   6239   */
  6096         -SQLITE_API int SQLITE_STDCALL sqlite3_create_module(
         6240  +SQLITE_API int SQLITE_APICALL sqlite3_create_module(
  6097   6241     sqlite3 *db,               /* SQLite connection to register module with */
  6098   6242     const char *zName,         /* Name of the module */
  6099   6243     const sqlite3_module *p,   /* Methods for the module */
  6100   6244     void *pClientData          /* Client data for xCreate/xConnect */
  6101   6245   );
  6102         -SQLITE_API int SQLITE_STDCALL sqlite3_create_module_v2(
         6246  +SQLITE_API int SQLITE_APICALL sqlite3_create_module_v2(
  6103   6247     sqlite3 *db,               /* SQLite connection to register module with */
  6104   6248     const char *zName,         /* Name of the module */
  6105   6249     const sqlite3_module *p,   /* Methods for the module */
  6106   6250     void *pClientData,         /* Client data for xCreate/xConnect */
  6107         -  void(*xDestroy)(void*)     /* Module destructor function */
         6251  +  void(SQLITE_CALLBACK *xDestroy)(void*)     /* Module destructor function */
  6108   6252   );
  6109   6253   
  6110   6254   /*
  6111   6255   ** CAPI3REF: Virtual Table Instance Object
  6112   6256   ** KEYWORDS: sqlite3_vtab
  6113   6257   **
  6114   6258   ** Every [virtual table module] implementation uses a subclass
................................................................................
  6158   6302   ** CAPI3REF: Declare The Schema Of A Virtual Table
  6159   6303   **
  6160   6304   ** ^The [xCreate] and [xConnect] methods of a
  6161   6305   ** [virtual table module] call this interface
  6162   6306   ** to declare the format (the names and datatypes of the columns) of
  6163   6307   ** the virtual tables they implement.
  6164   6308   */
  6165         -SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
         6309  +SQLITE_API int SQLITE_APICALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
  6166   6310   
  6167   6311   /*
  6168   6312   ** CAPI3REF: Overload A Function For A Virtual Table
  6169   6313   ** METHOD: sqlite3
  6170   6314   **
  6171   6315   ** ^(Virtual tables can provide alternative implementations of functions
  6172   6316   ** using the [xFindFunction] method of the [virtual table module].  
................................................................................
  6177   6321   ** name and number of parameters exists.  If no such function exists
  6178   6322   ** before this API is called, a new function is created.)^  ^The implementation
  6179   6323   ** of the new function always causes an exception to be thrown.  So
  6180   6324   ** the new function is not good for anything by itself.  Its only
  6181   6325   ** purpose is to be a placeholder function that can be overloaded
  6182   6326   ** by a [virtual table].
  6183   6327   */
  6184         -SQLITE_API int SQLITE_STDCALL sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
         6328  +SQLITE_API int SQLITE_APICALL sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  6185   6329   
  6186   6330   /*
  6187   6331   ** The interface to the virtual-table mechanism defined above (back up
  6188   6332   ** to a comment remarkably similar to this one) is currently considered
  6189   6333   ** to be experimental.  The interface might change in incompatible ways.
  6190   6334   ** If this is a problem for you, do not use the interface at this time.
  6191   6335   **
................................................................................
  6276   6420   ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
  6277   6421   ** and the built-in [zeroblob] SQL function may be used to create a 
  6278   6422   ** zero-filled blob to read or write using the incremental-blob interface.
  6279   6423   **
  6280   6424   ** To avoid a resource leak, every open [BLOB handle] should eventually
  6281   6425   ** be released by a call to [sqlite3_blob_close()].
  6282   6426   */
  6283         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_open(
         6427  +SQLITE_API int SQLITE_APICALL sqlite3_blob_open(
  6284   6428     sqlite3*,
  6285   6429     const char *zDb,
  6286   6430     const char *zTable,
  6287   6431     const char *zColumn,
  6288   6432     sqlite3_int64 iRow,
  6289   6433     int flags,
  6290   6434     sqlite3_blob **ppBlob
................................................................................
  6309   6453   ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
  6310   6454   ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
  6311   6455   ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
  6312   6456   ** always returns zero.
  6313   6457   **
  6314   6458   ** ^This function sets the database handle error code and message.
  6315   6459   */
  6316         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
         6460  +SQLITE_API int SQLITE_APICALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
  6317   6461   
  6318   6462   /*
  6319   6463   ** CAPI3REF: Close A BLOB Handle
  6320   6464   ** DESTRUCTOR: sqlite3_blob
  6321   6465   **
  6322   6466   ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
  6323   6467   ** unconditionally.  Even if this routine returns an error code, the 
................................................................................
  6332   6476   ** Calling this function with an argument that is not a NULL pointer or an
  6333   6477   ** open blob handle results in undefined behaviour. ^Calling this routine 
  6334   6478   ** with a null pointer (such as would be returned by a failed call to 
  6335   6479   ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
  6336   6480   ** is passed a valid open blob handle, the values returned by the 
  6337   6481   ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
  6338   6482   */
  6339         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
         6483  +SQLITE_API int SQLITE_APICALL sqlite3_blob_close(sqlite3_blob *);
  6340   6484   
  6341   6485   /*
  6342   6486   ** CAPI3REF: Return The Size Of An Open BLOB
  6343   6487   ** METHOD: sqlite3_blob
  6344   6488   **
  6345   6489   ** ^Returns the size in bytes of the BLOB accessible via the 
  6346   6490   ** successfully opened [BLOB handle] in its only argument.  ^The
................................................................................
  6348   6492   ** blob content; they cannot change the size of a blob.
  6349   6493   **
  6350   6494   ** This routine only works on a [BLOB handle] which has been created
  6351   6495   ** by a prior successful call to [sqlite3_blob_open()] and which has not
  6352   6496   ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
  6353   6497   ** to this routine results in undefined and probably undesirable behavior.
  6354   6498   */
  6355         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
         6499  +SQLITE_API int SQLITE_APICALL sqlite3_blob_bytes(sqlite3_blob *);
  6356   6500   
  6357   6501   /*
  6358   6502   ** CAPI3REF: Read Data From A BLOB Incrementally
  6359   6503   ** METHOD: sqlite3_blob
  6360   6504   **
  6361   6505   ** ^(This function is used to read data from an open [BLOB handle] into a
  6362   6506   ** caller-supplied buffer. N bytes of data are copied into buffer Z
................................................................................
  6377   6521   ** This routine only works on a [BLOB handle] which has been created
  6378   6522   ** by a prior successful call to [sqlite3_blob_open()] and which has not
  6379   6523   ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
  6380   6524   ** to this routine results in undefined and probably undesirable behavior.
  6381   6525   **
  6382   6526   ** See also: [sqlite3_blob_write()].
  6383   6527   */
  6384         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
         6528  +SQLITE_API int SQLITE_APICALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  6385   6529   
  6386   6530   /*
  6387   6531   ** CAPI3REF: Write Data Into A BLOB Incrementally
  6388   6532   ** METHOD: sqlite3_blob
  6389   6533   **
  6390   6534   ** ^(This function is used to write data into an open [BLOB handle] from a
  6391   6535   ** caller-supplied buffer. N bytes of data are copied from the buffer Z
................................................................................
  6419   6563   ** This routine only works on a [BLOB handle] which has been created
  6420   6564   ** by a prior successful call to [sqlite3_blob_open()] and which has not
  6421   6565   ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
  6422   6566   ** to this routine results in undefined and probably undesirable behavior.
  6423   6567   **
  6424   6568   ** See also: [sqlite3_blob_read()].
  6425   6569   */
  6426         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
         6570  +SQLITE_API int SQLITE_APICALL sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  6427   6571   
  6428   6572   /*
  6429   6573   ** CAPI3REF: Virtual File System Objects
  6430   6574   **
  6431   6575   ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  6432   6576   ** that SQLite uses to interact
  6433   6577   ** with the underlying operating system.  Most SQLite builds come with a
................................................................................
  6450   6594   ** VFS is registered with a name that is NULL or an empty string,
  6451   6595   ** then the behavior is undefined.
  6452   6596   **
  6453   6597   ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
  6454   6598   ** ^(If the default VFS is unregistered, another VFS is chosen as
  6455   6599   ** the default.  The choice for the new VFS is arbitrary.)^
  6456   6600   */
  6457         -SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfsName);
  6458         -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  6459         -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs*);
         6601  +SQLITE_API sqlite3_vfs *SQLITE_APICALL sqlite3_vfs_find(const char *zVfsName);
         6602  +SQLITE_API int SQLITE_APICALL sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
         6603  +SQLITE_API int SQLITE_APICALL sqlite3_vfs_unregister(sqlite3_vfs*);
  6460   6604   
  6461   6605   /*
  6462   6606   ** CAPI3REF: Mutexes
  6463   6607   **
  6464   6608   ** The SQLite core uses these routines for thread
  6465   6609   ** synchronization. Though they are intended for internal
  6466   6610   ** use by SQLite, code that links against SQLite is
................................................................................
  6568   6712   **
  6569   6713   ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
  6570   6714   ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
  6571   6715   ** behave as no-ops.
  6572   6716   **
  6573   6717   ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  6574   6718   */
  6575         -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int);
  6576         -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex*);
  6577         -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex*);
  6578         -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex*);
  6579         -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex*);
         6719  +SQLITE_API sqlite3_mutex *SQLITE_APICALL sqlite3_mutex_alloc(int);
         6720  +SQLITE_API void SQLITE_APICALL sqlite3_mutex_free(sqlite3_mutex*);
         6721  +SQLITE_API void SQLITE_APICALL sqlite3_mutex_enter(sqlite3_mutex*);
         6722  +SQLITE_API int SQLITE_APICALL sqlite3_mutex_try(sqlite3_mutex*);
         6723  +SQLITE_API void SQLITE_APICALL sqlite3_mutex_leave(sqlite3_mutex*);
  6580   6724   
  6581   6725   /*
  6582   6726   ** CAPI3REF: Mutex Methods Object
  6583   6727   **
  6584   6728   ** An instance of this structure defines the low-level routines
  6585   6729   ** used to allocate and use mutexes.
  6586   6730   **
................................................................................
  6641   6785   ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
  6642   6786   ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
  6643   6787   ** If xMutexInit fails in any way, it is expected to clean up after itself
  6644   6788   ** prior to returning.
  6645   6789   */
  6646   6790   typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
  6647   6791   struct sqlite3_mutex_methods {
  6648         -  int (*xMutexInit)(void);
  6649         -  int (*xMutexEnd)(void);
  6650         -  sqlite3_mutex *(*xMutexAlloc)(int);
  6651         -  void (*xMutexFree)(sqlite3_mutex *);
  6652         -  void (*xMutexEnter)(sqlite3_mutex *);
  6653         -  int (*xMutexTry)(sqlite3_mutex *);
  6654         -  void (*xMutexLeave)(sqlite3_mutex *);
  6655         -  int (*xMutexHeld)(sqlite3_mutex *);
  6656         -  int (*xMutexNotheld)(sqlite3_mutex *);
         6792  +  int (SQLITE_CALLBACK *xMutexInit)(void);
         6793  +  int (SQLITE_CALLBACK *xMutexEnd)(void);
         6794  +  sqlite3_mutex *(SQLITE_CALLBACK *xMutexAlloc)(int);
         6795  +  void (SQLITE_CALLBACK *xMutexFree)(sqlite3_mutex *);
         6796  +  void (SQLITE_CALLBACK *xMutexEnter)(sqlite3_mutex *);
         6797  +  int (SQLITE_CALLBACK *xMutexTry)(sqlite3_mutex *);
         6798  +  void (SQLITE_CALLBACK *xMutexLeave)(sqlite3_mutex *);
         6799  +  int (SQLITE_CALLBACK *xMutexHeld)(sqlite3_mutex *);
         6800  +  int (SQLITE_CALLBACK *xMutexNotheld)(sqlite3_mutex *);
  6657   6801   };
  6658   6802   
  6659   6803   /*
  6660   6804   ** CAPI3REF: Mutex Verification Routines
  6661   6805   **
  6662   6806   ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  6663   6807   ** are intended for use inside assert() statements.  The SQLite core
................................................................................
  6682   6826   ** the reason the mutex does not exist is because the build is not
  6683   6827   ** using mutexes.  And we do not want the assert() containing the
  6684   6828   ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  6685   6829   ** the appropriate thing to do.  The sqlite3_mutex_notheld()
  6686   6830   ** interface should also return 1 when given a NULL pointer.
  6687   6831   */
  6688   6832   #ifndef NDEBUG
  6689         -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex*);
  6690         -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex*);
         6833  +SQLITE_API int SQLITE_APICALL sqlite3_mutex_held(sqlite3_mutex*);
         6834  +SQLITE_API int SQLITE_APICALL sqlite3_mutex_notheld(sqlite3_mutex*);
  6691   6835   #endif
  6692   6836   
  6693   6837   /*
  6694   6838   ** CAPI3REF: Mutex Types
  6695   6839   **
  6696   6840   ** The [sqlite3_mutex_alloc()] interface takes a single argument
  6697   6841   ** which is one of these integer constants.
................................................................................
  6723   6867   **
  6724   6868   ** ^This interface returns a pointer the [sqlite3_mutex] object that 
  6725   6869   ** serializes access to the [database connection] given in the argument
  6726   6870   ** when the [threading mode] is Serialized.
  6727   6871   ** ^If the [threading mode] is Single-thread or Multi-thread then this
  6728   6872   ** routine returns a NULL pointer.
  6729   6873   */
  6730         -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
         6874  +SQLITE_API sqlite3_mutex *SQLITE_APICALL sqlite3_db_mutex(sqlite3*);
  6731   6875   
  6732   6876   /*
  6733   6877   ** CAPI3REF: Low-Level Control Of Database Files
  6734   6878   ** METHOD: sqlite3
  6735   6879   **
  6736   6880   ** ^The [sqlite3_file_control()] interface makes a direct call to the
  6737   6881   ** xFileControl method for the [sqlite3_io_methods] object associated
................................................................................
  6758   6902   ** or [sqlite3_errmsg()].  The underlying xFileControl method might
  6759   6903   ** also return SQLITE_ERROR.  There is no way to distinguish between
  6760   6904   ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  6761   6905   ** xFileControl method.
  6762   6906   **
  6763   6907   ** See also: [SQLITE_FCNTL_LOCKSTATE]
  6764   6908   */
  6765         -SQLITE_API int SQLITE_STDCALL sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
         6909  +SQLITE_API int SQLITE_APICALL sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  6766   6910   
  6767   6911   /*
  6768   6912   ** CAPI3REF: Testing Interface
  6769   6913   **
  6770   6914   ** ^The sqlite3_test_control() interface is used to read out internal
  6771   6915   ** state of SQLite and to inject faults into SQLite for testing
  6772   6916   ** purposes.  ^The first parameter is an operation code that determines
................................................................................
  6840   6984   **
  6841   6985   ** If either the current value or the highwater mark is too large to
  6842   6986   ** be represented by a 32-bit integer, then the values returned by
  6843   6987   ** sqlite3_status() are undefined.
  6844   6988   **
  6845   6989   ** See also: [sqlite3_db_status()]
  6846   6990   */
  6847         -SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  6848         -SQLITE_API int SQLITE_STDCALL sqlite3_status64(
         6991  +SQLITE_API int SQLITE_APICALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
         6992  +SQLITE_API int SQLITE_APICALL sqlite3_status64(
  6849   6993     int op,
  6850   6994     sqlite3_int64 *pCurrent,
  6851   6995     sqlite3_int64 *pHighwater,
  6852   6996     int resetFlag
  6853   6997   );
  6854   6998   
  6855   6999   
................................................................................
  6966   7110   ** reset back down to the current value.
  6967   7111   **
  6968   7112   ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
  6969   7113   ** non-zero [error code] on failure.
  6970   7114   **
  6971   7115   ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  6972   7116   */
  6973         -SQLITE_API int SQLITE_STDCALL sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
         7117  +SQLITE_API int SQLITE_APICALL sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  6974   7118   
  6975   7119   /*
  6976   7120   ** CAPI3REF: Status Parameters for database connections
  6977   7121   ** KEYWORDS: {SQLITE_DBSTATUS options}
  6978   7122   **
  6979   7123   ** These constants are the available integer "verbs" that can be passed as
  6980   7124   ** the second argument to the [sqlite3_db_status()] interface.
................................................................................
  7012   7156   ** the current value is always zero.)^
  7013   7157   **
  7014   7158   ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  7015   7159   ** <dd>This parameter returns the approximate number of bytes of heap
  7016   7160   ** memory used by all pager caches associated with the database connection.)^
  7017   7161   ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  7018   7162   **
         7163  +** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]] 
         7164  +** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
         7165  +** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
         7166  +** pager cache is shared between two or more connections the bytes of heap
         7167  +** memory used by that pager cache is divided evenly between the attached
         7168  +** connections.)^  In other words, if none of the pager caches associated
         7169  +** with the database connection are shared, this request returns the same
         7170  +** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
         7171  +** shared, the value returned by this call will be smaller than that returned
         7172  +** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
         7173  +** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
         7174  +**
  7019   7175   ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
  7020   7176   ** <dd>This parameter returns the approximate number of bytes of heap
  7021   7177   ** memory used to store the schema for all databases associated
  7022   7178   ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 
  7023   7179   ** ^The full amount of memory used by the schemas is reported, even if the
  7024   7180   ** schema memory is shared with other database connections due to
  7025   7181   ** [shared cache mode] being enabled.
................................................................................
  7069   7225   #define SQLITE_DBSTATUS_LOOKASIDE_HIT        4
  7070   7226   #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE  5
  7071   7227   #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL  6
  7072   7228   #define SQLITE_DBSTATUS_CACHE_HIT            7
  7073   7229   #define SQLITE_DBSTATUS_CACHE_MISS           8
  7074   7230   #define SQLITE_DBSTATUS_CACHE_WRITE          9
  7075   7231   #define SQLITE_DBSTATUS_DEFERRED_FKS        10
  7076         -#define SQLITE_DBSTATUS_MAX                 10   /* Largest defined DBSTATUS */
         7232  +#define SQLITE_DBSTATUS_CACHE_USED_SHARED   11
         7233  +#define SQLITE_DBSTATUS_MAX                 11   /* Largest defined DBSTATUS */
  7077   7234   
  7078   7235   
  7079   7236   /*
  7080   7237   ** CAPI3REF: Prepared Statement Status
  7081   7238   ** METHOD: sqlite3_stmt
  7082   7239   **
  7083   7240   ** ^(Each prepared statement maintains various
................................................................................
  7096   7253   ** to be interrogated.)^
  7097   7254   ** ^The current value of the requested counter is returned.
  7098   7255   ** ^If the resetFlg is true, then the counter is reset to zero after this
  7099   7256   ** interface call returns.
  7100   7257   **
  7101   7258   ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  7102   7259   */
  7103         -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
         7260  +SQLITE_API int SQLITE_APICALL sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  7104   7261   
  7105   7262   /*
  7106   7263   ** CAPI3REF: Status Parameters for prepared statements
  7107   7264   ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
  7108   7265   **
  7109   7266   ** These preprocessor macros define integer codes that name counter
  7110   7267   ** values associated with the [sqlite3_stmt_status()] interface.
................................................................................
  7332   7489   ** is not obligated to free any memory, but well-behaved implementations should
  7333   7490   ** do their best.
  7334   7491   */
  7335   7492   typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
  7336   7493   struct sqlite3_pcache_methods2 {
  7337   7494     int iVersion;
  7338   7495     void *pArg;
  7339         -  int (*xInit)(void*);
  7340         -  void (*xShutdown)(void*);
  7341         -  sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
  7342         -  void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  7343         -  int (*xPagecount)(sqlite3_pcache*);
  7344         -  sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  7345         -  void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
  7346         -  void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, 
         7496  +  int (SQLITE_CALLBACK *xInit)(void*);
         7497  +  void (SQLITE_CALLBACK *xShutdown)(void*);
         7498  +  sqlite3_pcache *(SQLITE_CALLBACK *xCreate)(int szPage, int szExtra, int bPurgeable);
         7499  +  void (SQLITE_CALLBACK *xCachesize)(sqlite3_pcache*, int nCachesize);
         7500  +  int (SQLITE_CALLBACK *xPagecount)(sqlite3_pcache*);
         7501  +  sqlite3_pcache_page *(SQLITE_CALLBACK *xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
         7502  +  void (SQLITE_CALLBACK *xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
         7503  +  void (SQLITE_CALLBACK *xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, 
  7347   7504         unsigned oldKey, unsigned newKey);
  7348         -  void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  7349         -  void (*xDestroy)(sqlite3_pcache*);
  7350         -  void (*xShrink)(sqlite3_pcache*);
         7505  +  void (SQLITE_CALLBACK *xTruncate)(sqlite3_pcache*, unsigned iLimit);
         7506  +  void (SQLITE_CALLBACK *xDestroy)(sqlite3_pcache*);
         7507  +  void (SQLITE_CALLBACK *xShrink)(sqlite3_pcache*);
  7351   7508   };
  7352   7509   
  7353   7510   /*
  7354   7511   ** This is the obsolete pcache_methods object that has now been replaced
  7355   7512   ** by sqlite3_pcache_methods2.  This object is not used by SQLite.  It is
  7356   7513   ** retained in the header file for backwards compatibility only.
  7357   7514   */
  7358   7515   typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  7359   7516   struct sqlite3_pcache_methods {
  7360   7517     void *pArg;
  7361         -  int (*xInit)(void*);
  7362         -  void (*xShutdown)(void*);
  7363         -  sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  7364         -  void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  7365         -  int (*xPagecount)(sqlite3_pcache*);
  7366         -  void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  7367         -  void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  7368         -  void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  7369         -  void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  7370         -  void (*xDestroy)(sqlite3_pcache*);
         7518  +  int (SQLITE_CALLBACK *xInit)(void*);
         7519  +  void (SQLITE_CALLBACK *xShutdown)(void*);
         7520  +  sqlite3_pcache *(SQLITE_CALLBACK *xCreate)(int szPage, int bPurgeable);
         7521  +  void (SQLITE_CALLBACK *xCachesize)(sqlite3_pcache*, int nCachesize);
         7522  +  int (SQLITE_CALLBACK *xPagecount)(sqlite3_pcache*);
         7523  +  void *(SQLITE_CALLBACK *xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
         7524  +  void (SQLITE_CALLBACK *xUnpin)(sqlite3_pcache*, void*, int discard);
         7525  +  void (SQLITE_CALLBACK *xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
         7526  +  void (SQLITE_CALLBACK *xTruncate)(sqlite3_pcache*, unsigned iLimit);
         7527  +  void (SQLITE_CALLBACK *xDestroy)(sqlite3_pcache*);
  7371   7528   };
  7372   7529   
  7373   7530   
  7374   7531   /*
  7375   7532   ** CAPI3REF: Online Backup Object
  7376   7533   **
  7377   7534   ** The sqlite3_backup object records state information about an ongoing
................................................................................
  7565   7722   ** The [sqlite3_backup] object itself is partially threadsafe. Multiple 
  7566   7723   ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
  7567   7724   ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
  7568   7725   ** APIs are not strictly speaking threadsafe. If they are invoked at the
  7569   7726   ** same time as another thread is invoking sqlite3_backup_step() it is
  7570   7727   ** possible that they return invalid values.
  7571   7728   */
  7572         -SQLITE_API sqlite3_backup *SQLITE_STDCALL sqlite3_backup_init(
         7729  +SQLITE_API sqlite3_backup *SQLITE_APICALL sqlite3_backup_init(
  7573   7730     sqlite3 *pDest,                        /* Destination database handle */
  7574   7731     const char *zDestName,                 /* Destination database name */
  7575   7732     sqlite3 *pSource,                      /* Source database handle */
  7576   7733     const char *zSourceName                /* Source database name */
  7577   7734   );
  7578         -SQLITE_API int SQLITE_STDCALL sqlite3_backup_step(sqlite3_backup *p, int nPage);
  7579         -SQLITE_API int SQLITE_STDCALL sqlite3_backup_finish(sqlite3_backup *p);
  7580         -SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
  7581         -SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
         7735  +SQLITE_API int SQLITE_APICALL sqlite3_backup_step(sqlite3_backup *p, int nPage);
         7736  +SQLITE_API int SQLITE_APICALL sqlite3_backup_finish(sqlite3_backup *p);
         7737  +SQLITE_API int SQLITE_APICALL sqlite3_backup_remaining(sqlite3_backup *p);
         7738  +SQLITE_API int SQLITE_APICALL sqlite3_backup_pagecount(sqlite3_backup *p);
  7582   7739   
  7583   7740   /*
  7584   7741   ** CAPI3REF: Unlock Notification
  7585   7742   ** METHOD: sqlite3
  7586   7743   **
  7587   7744   ** ^When running in shared-cache mode, a database operation may fail with
  7588   7745   ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
................................................................................
  7691   7848   **
  7692   7849   ** One way around this problem is to check the extended error code returned
  7693   7850   ** by an sqlite3_step() call. ^(If there is a blocking connection, then the
  7694   7851   ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
  7695   7852   ** the special "DROP TABLE/INDEX" case, the extended error code is just 
  7696   7853   ** SQLITE_LOCKED.)^
  7697   7854   */
  7698         -SQLITE_API int SQLITE_STDCALL sqlite3_unlock_notify(
         7855  +SQLITE_API int SQLITE_APICALL sqlite3_unlock_notify(
  7699   7856     sqlite3 *pBlocked,                          /* Waiting connection */
  7700         -  void (*xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
         7857  +  void (SQLITE_CALLBACK *xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
  7701   7858     void *pNotifyArg                            /* Argument to pass to xNotify */
  7702   7859   );
  7703   7860   
  7704   7861   
  7705   7862   /*
  7706   7863   ** CAPI3REF: String Comparison
  7707   7864   **
  7708   7865   ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
  7709   7866   ** and extensions to compare the contents of two buffers containing UTF-8
  7710   7867   ** strings in a case-independent fashion, using the same definition of "case
  7711   7868   ** independence" that SQLite uses internally when comparing identifiers.
  7712   7869   */
  7713         -SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *, const char *);
  7714         -SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *, const char *, int);
         7870  +SQLITE_API int SQLITE_APICALL sqlite3_stricmp(const char *, const char *);
         7871  +SQLITE_API int SQLITE_APICALL sqlite3_strnicmp(const char *, const char *, int);
  7715   7872   
  7716   7873   /*
  7717   7874   ** CAPI3REF: String Globbing
  7718   7875   *
  7719   7876   ** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if
  7720   7877   ** string X matches the [GLOB] pattern P.
  7721   7878   ** ^The definition of [GLOB] pattern matching used in
................................................................................
  7724   7881   ** is case sensitive.
  7725   7882   **
  7726   7883   ** Note that this routine returns zero on a match and non-zero if the strings
  7727   7884   ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
  7728   7885   **
  7729   7886   ** See also: [sqlite3_strlike()].
  7730   7887   */
  7731         -SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlob, const char *zStr);
         7888  +SQLITE_API int SQLITE_APICALL sqlite3_strglob(const char *zGlob, const char *zStr);
  7732   7889   
  7733   7890   /*
  7734   7891   ** CAPI3REF: String LIKE Matching
  7735   7892   *
  7736   7893   ** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if
  7737   7894   ** string X matches the [LIKE] pattern P with escape character E.
  7738   7895   ** ^The definition of [LIKE] pattern matching used in
................................................................................
  7747   7904   ** only ASCII characters are case folded.
  7748   7905   **
  7749   7906   ** Note that this routine returns zero on a match and non-zero if the strings
  7750   7907   ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
  7751   7908   **
  7752   7909   ** See also: [sqlite3_strglob()].
  7753   7910   */
  7754         -SQLITE_API int SQLITE_STDCALL sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
         7911  +SQLITE_API int SQLITE_APICALL sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
  7755   7912   
  7756   7913   /*
  7757   7914   ** CAPI3REF: Error Logging Interface
  7758   7915   **
  7759   7916   ** ^The [sqlite3_log()] interface writes a message into the [error log]
  7760   7917   ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
  7761   7918   ** ^If logging is enabled, the zFormat string and subsequent arguments are
................................................................................
  7806   7963   ** A single database handle may have at most a single write-ahead log callback 
  7807   7964   ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
  7808   7965   ** previously registered write-ahead log callback. ^Note that the
  7809   7966   ** [sqlite3_wal_autocheckpoint()] interface and the
  7810   7967   ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
  7811   7968   ** overwrite any prior [sqlite3_wal_hook()] settings.
  7812   7969   */
  7813         -SQLITE_API void *SQLITE_STDCALL sqlite3_wal_hook(
         7970  +SQLITE_API void *SQLITE_APICALL sqlite3_wal_hook(
  7814   7971     sqlite3*, 
  7815         -  int(*)(void *,sqlite3*,const char*,int),
         7972  +  int(SQLITE_CALLBACK *)(void *,sqlite3*,const char*,int),
  7816   7973     void*
  7817   7974   );
  7818   7975   
  7819   7976   /*
  7820   7977   ** CAPI3REF: Configure an auto-checkpoint
  7821   7978   ** METHOD: sqlite3
  7822   7979   **
................................................................................
  7841   7998   **
  7842   7999   ** ^Every new [database connection] defaults to having the auto-checkpoint
  7843   8000   ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
  7844   8001   ** pages.  The use of this interface
  7845   8002   ** is only necessary if the default setting is found to be suboptimal
  7846   8003   ** for a particular application.
  7847   8004   */
  7848         -SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
         8005  +SQLITE_API int SQLITE_APICALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  7849   8006   
  7850   8007   /*
  7851   8008   ** CAPI3REF: Checkpoint a database
  7852   8009   ** METHOD: sqlite3
  7853   8010   **
  7854   8011   ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
  7855   8012   ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
................................................................................
  7863   8020   ** This interface used to be the only way to cause a checkpoint to
  7864   8021   ** occur.  But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
  7865   8022   ** interface was added.  This interface is retained for backwards
  7866   8023   ** compatibility and as a convenience for applications that need to manually
  7867   8024   ** start a callback but which do not need the full power (and corresponding
  7868   8025   ** complication) of [sqlite3_wal_checkpoint_v2()].
  7869   8026   */
  7870         -SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
         8027  +SQLITE_API int SQLITE_APICALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
  7871   8028   
  7872   8029   /*
  7873   8030   ** CAPI3REF: Checkpoint a database
  7874   8031   ** METHOD: sqlite3
  7875   8032   **
  7876   8033   ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
  7877   8034   ** operation on database X of [database connection] D in mode M.  Status
................................................................................
  7957   8114   ** the sqlite3_wal_checkpoint_v2() interface
  7958   8115   ** sets the error information that is queried by
  7959   8116   ** [sqlite3_errcode()] and [sqlite3_errmsg()].
  7960   8117   **
  7961   8118   ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
  7962   8119   ** from SQL.
  7963   8120   */
  7964         -SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint_v2(
         8121  +SQLITE_API int SQLITE_APICALL sqlite3_wal_checkpoint_v2(
  7965   8122     sqlite3 *db,                    /* Database handle */
  7966   8123     const char *zDb,                /* Name of attached database (or NULL) */
  7967   8124     int eMode,                      /* SQLITE_CHECKPOINT_* value */
  7968   8125     int *pnLog,                     /* OUT: Size of WAL log in frames */
  7969   8126     int *pnCkpt                     /* OUT: Total number of frames checkpointed */
  7970   8127   );
  7971   8128   
................................................................................
  8046   8203   ** This function may only be called from within a call to the [xUpdate] method
  8047   8204   ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
  8048   8205   ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
  8049   8206   ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
  8050   8207   ** of the SQL statement that triggered the call to the [xUpdate] method of the
  8051   8208   ** [virtual table].
  8052   8209   */
  8053         -SQLITE_API int SQLITE_STDCALL sqlite3_vtab_on_conflict(sqlite3 *);
         8210  +SQLITE_API int SQLITE_APICALL sqlite3_vtab_on_conflict(sqlite3 *);
  8054   8211   
  8055   8212   /*
  8056   8213   ** CAPI3REF: Conflict resolution modes
  8057   8214   ** KEYWORDS: {conflict resolution mode}
  8058   8215   **
  8059   8216   ** These constants are returned by [sqlite3_vtab_on_conflict()] to
  8060   8217   ** inform a [virtual table] implementation what the [ON CONFLICT] mode
................................................................................
  8151   8308   ** ^Statistics might not be available for all loops in all statements. ^In cases
  8152   8309   ** where there exist loops with no available statistics, this function behaves
  8153   8310   ** as if the loop did not exist - it returns non-zero and leave the variable
  8154   8311   ** that pOut points to unchanged.
  8155   8312   **
  8156   8313   ** See also: [sqlite3_stmt_scanstatus_reset()]
  8157   8314   */
  8158         -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_scanstatus(
         8315  +SQLITE_API int SQLITE_APICALL sqlite3_stmt_scanstatus(
  8159   8316     sqlite3_stmt *pStmt,      /* Prepared statement for which info desired */
  8160   8317     int idx,                  /* Index of loop to report on */
  8161   8318     int iScanStatusOp,        /* Information desired.  SQLITE_SCANSTAT_* */
  8162   8319     void *pOut                /* Result written here */
  8163   8320   );     
  8164   8321   
  8165   8322   /*
................................................................................
  8167   8324   ** METHOD: sqlite3_stmt
  8168   8325   **
  8169   8326   ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
  8170   8327   **
  8171   8328   ** This API is only available if the library is built with pre-processor
  8172   8329   ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
  8173   8330   */
  8174         -SQLITE_API void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
         8331  +SQLITE_API void SQLITE_APICALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
  8175   8332   
  8176   8333   /*
  8177   8334   ** CAPI3REF: Flush caches to disk mid-transaction
  8178   8335   **
  8179   8336   ** ^If a write-transaction is open on [database connection] D when the
  8180   8337   ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
  8181   8338   ** pages in the pager-cache that are not currently in use are written out 
................................................................................
  8199   8356   ** abandoned and an SQLite [error code] is returned to the caller immediately.
  8200   8357   **
  8201   8358   ** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK.
  8202   8359   **
  8203   8360   ** ^This function does not set the database handle error code or message
  8204   8361   ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
  8205   8362   */
  8206         -SQLITE_API int SQLITE_STDCALL sqlite3_db_cacheflush(sqlite3*);
         8363  +SQLITE_API int SQLITE_APICALL sqlite3_db_cacheflush(sqlite3*);
  8207   8364   
  8208   8365   /*
  8209   8366   ** CAPI3REF: The pre-update hook.
  8210   8367   **
  8211   8368   ** ^These interfaces are only available if SQLite is compiled using the
  8212   8369   ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
  8213   8370   **
................................................................................
  8279   8436   ** callback was invoked as a result of a direct insert, update, or delete
  8280   8437   ** operation; or 1 for inserts, updates, or deletes invoked by top-level 
  8281   8438   ** triggers; or 2 for changes resulting from triggers called by top-level
  8282   8439   ** triggers; and so forth.
  8283   8440   **
  8284   8441   ** See also:  [sqlite3_update_hook()]
  8285   8442   */
  8286         -SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_preupdate_hook(
         8443  +SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_APICALL sqlite3_preupdate_hook(
  8287   8444     sqlite3 *db,
  8288         -  void(*xPreUpdate)(
         8445  +  void(SQLITE_CALLBACK *xPreUpdate)(
  8289   8446       void *pCtx,                   /* Copy of third arg to preupdate_hook() */
  8290   8447       sqlite3 *db,                  /* Database handle */
  8291   8448       int op,                       /* SQLITE_UPDATE, DELETE or INSERT */
  8292   8449       char const *zDb,              /* Database name */
  8293   8450       char const *zName,            /* Table name */
  8294   8451       sqlite3_int64 iKey1,          /* Rowid of row about to be deleted/updated */
  8295   8452       sqlite3_int64 iKey2           /* New rowid value (for a rowid UPDATE) */
  8296   8453     ),
  8297   8454     void*
  8298   8455   );
  8299         -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
  8300         -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_count(sqlite3 *);
  8301         -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_depth(sqlite3 *);
  8302         -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
         8456  +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_APICALL sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
         8457  +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_APICALL sqlite3_preupdate_count(sqlite3 *);
         8458  +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_APICALL sqlite3_preupdate_depth(sqlite3 *);
         8459  +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_APICALL sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
  8303   8460   
  8304   8461   /*
  8305   8462   ** CAPI3REF: Low-level system error code
  8306   8463   **
  8307   8464   ** ^Attempt to return the underlying operating system error code or error
  8308   8465   ** number that caused the most recent I/O error or failure to open a file.
  8309   8466   ** The return value is OS-dependent.  For example, on unix systems, after
  8310   8467   ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
  8311   8468   ** called to get back the underlying "errno" that caused the problem, such
  8312   8469   ** as ENOSPC, EAUTH, EISDIR, and so forth.  
  8313   8470   */
  8314         -SQLITE_API int SQLITE_STDCALL sqlite3_system_errno(sqlite3*);
         8471  +SQLITE_API int SQLITE_APICALL sqlite3_system_errno(sqlite3*);
  8315   8472   
  8316   8473   /*
  8317   8474   ** CAPI3REF: Database Snapshot
  8318   8475   ** KEYWORDS: {snapshot}
  8319   8476   ** EXPERIMENTAL
  8320   8477   **
  8321   8478   ** An instance of the snapshot object records the state of a [WAL mode]
................................................................................
  8357   8514   ** The [sqlite3_snapshot] object returned from a successful call to
  8358   8515   ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
  8359   8516   ** to avoid a memory leak.
  8360   8517   **
  8361   8518   ** The [sqlite3_snapshot_get()] interface is only available when the
  8362   8519   ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
  8363   8520   */
  8364         -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_get(
         8521  +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_APICALL sqlite3_snapshot_get(
  8365   8522     sqlite3 *db,
  8366   8523     const char *zSchema,
  8367   8524     sqlite3_snapshot **ppSnapshot
  8368   8525   );
  8369   8526   
  8370   8527   /*
  8371   8528   ** CAPI3REF: Start a read transaction on an historical snapshot
................................................................................
  8395   8552   ** after the most recent I/O on the database connection.)^
  8396   8553   ** (Hint: Run "[PRAGMA application_id]" against a newly opened
  8397   8554   ** database connection in order to make it ready to use snapshots.)
  8398   8555   **
  8399   8556   ** The [sqlite3_snapshot_open()] interface is only available when the
  8400   8557   ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
  8401   8558   */
  8402         -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_open(
         8559  +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_APICALL sqlite3_snapshot_open(
  8403   8560     sqlite3 *db,
  8404   8561     const char *zSchema,
  8405   8562     sqlite3_snapshot *pSnapshot
  8406   8563   );
  8407   8564   
  8408   8565   /*
  8409   8566   ** CAPI3REF: Destroy a snapshot
................................................................................
  8412   8569   ** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.
  8413   8570   ** The application must eventually free every [sqlite3_snapshot] object
  8414   8571   ** using this routine to avoid a memory leak.
  8415   8572   **
  8416   8573   ** The [sqlite3_snapshot_free()] interface is only available when the
  8417   8574   ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
  8418   8575   */
  8419         -SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
         8576  +SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_APICALL sqlite3_snapshot_free(sqlite3_snapshot*);
  8420   8577   
  8421   8578   /*
  8422   8579   ** CAPI3REF: Compare the ages of two snapshot handles.
  8423   8580   ** EXPERIMENTAL
  8424   8581   **
  8425   8582   ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
  8426   8583   ** of two valid snapshot handles. 
................................................................................
  8436   8593   ** wal file was last deleted, the value returned by this function 
  8437   8594   ** is undefined.
  8438   8595   **
  8439   8596   ** Otherwise, this API returns a negative value if P1 refers to an older
  8440   8597   ** snapshot than P2, zero if the two handles refer to the same database
  8441   8598   ** snapshot, and a positive value if P1 is a newer snapshot than P2.
  8442   8599   */
  8443         -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
         8600  +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_APICALL sqlite3_snapshot_cmp(
  8444   8601     sqlite3_snapshot *p1,
  8445   8602     sqlite3_snapshot *p2
  8446   8603   );
  8447   8604   
  8448   8605   /*
  8449   8606   ** Undo the hack that converts floating point types to integer for
  8450   8607   ** builds on processors without floating point support.
................................................................................
  8452   8609   #ifdef SQLITE_OMIT_FLOATING_POINT
  8453   8610   # undef double
  8454   8611   #endif
  8455   8612   
  8456   8613   #if 0
  8457   8614   }  /* End of the 'extern "C"' block */
  8458   8615   #endif
  8459         -#endif /* _SQLITE3_H_ */
         8616  +#endif /* SQLITE3_H */
  8460   8617   
  8461   8618   /******** Begin file sqlite3rtree.h *********/
  8462   8619   /*
  8463   8620   ** 2010 August 30
  8464   8621   **
  8465   8622   ** The author disclaims copyright to this source code.  In place of
  8466   8623   ** a legal notice, here is a blessing:
................................................................................
  8494   8651   
  8495   8652   /*
  8496   8653   ** Register a geometry callback named zGeom that can be used as part of an
  8497   8654   ** R-Tree geometry query as follows:
  8498   8655   **
  8499   8656   **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
  8500   8657   */
  8501         -SQLITE_API int SQLITE_STDCALL sqlite3_rtree_geometry_callback(
         8658  +SQLITE_API int SQLITE_APICALL sqlite3_rtree_geometry_callback(
  8502   8659     sqlite3 *db,
  8503   8660     const char *zGeom,
  8504         -  int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
         8661  +  int (SQLITE_CALLBACK *xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
  8505   8662     void *pContext
  8506   8663   );
  8507   8664   
  8508   8665   
  8509   8666   /*
  8510   8667   ** A pointer to a structure of the following type is passed as the first
  8511   8668   ** argument to callbacks registered using rtree_geometry_callback().
  8512   8669   */
  8513   8670   struct sqlite3_rtree_geometry {
  8514   8671     void *pContext;                 /* Copy of pContext passed to s_r_g_c() */
  8515   8672     int nParam;                     /* Size of array aParam[] */
  8516   8673     sqlite3_rtree_dbl *aParam;      /* Parameters passed to SQL geom function */
  8517   8674     void *pUser;                    /* Callback implementation user data */
  8518         -  void (*xDelUser)(void *);       /* Called by SQLite to clean up pUser */
         8675  +  void (SQLITE_CALLBACK *xDelUser)(void *);       /* Called by SQLite to clean up pUser */
  8519   8676   };
  8520   8677   
  8521   8678   /*
  8522   8679   ** Register a 2nd-generation geometry callback named zScore that can be 
  8523   8680   ** used as part of an R-Tree geometry query as follows:
  8524   8681   **
  8525   8682   **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
  8526   8683   */
  8527         -SQLITE_API int SQLITE_STDCALL sqlite3_rtree_query_callback(
         8684  +SQLITE_API int SQLITE_APICALL sqlite3_rtree_query_callback(
  8528   8685     sqlite3 *db,
  8529   8686     const char *zQueryFunc,
  8530         -  int (*xQueryFunc)(sqlite3_rtree_query_info*),
         8687  +  int (SQLITE_CALLBACK *xQueryFunc)(sqlite3_rtree_query_info*),
  8531   8688     void *pContext,
  8532         -  void (*xDestructor)(void*)
         8689  +  void (SQLITE_CALLBACK *xDestructor)(void*)
  8533   8690   );
  8534   8691   
  8535   8692   
  8536   8693   /*
  8537   8694   ** A pointer to a structure of the following type is passed as the 
  8538   8695   ** argument to scored geometry callback registered using
  8539   8696   ** sqlite3_rtree_query_callback().
................................................................................
  8543   8700   ** sqlite3_rtree_geometry.
  8544   8701   */
  8545   8702   struct sqlite3_rtree_query_info {
  8546   8703     void *pContext;                   /* pContext from when function registered */
  8547   8704     int nParam;                       /* Number of function parameters */
  8548   8705     sqlite3_rtree_dbl *aParam;        /* value of function parameters */
  8549   8706     void *pUser;                      /* callback can use this, if desired */
  8550         -  void (*xDelUser)(void*);          /* function to free pUser */
         8707  +  void (SQLITE_CALLBACK *xDelUser)(void*);          /* function to free pUser */
  8551   8708     sqlite3_rtree_dbl *aCoord;        /* Coordinates of node or entry to check */
  8552   8709     unsigned int *anQueue;            /* Number of pending entries in the queue */
  8553   8710     int nCoord;                       /* Number of coordinates */
  8554   8711     int iLevel;                       /* Level of current node or entry */
  8555   8712     int mxLevel;                      /* The largest iLevel value in the tree */
  8556   8713     sqlite3_int64 iRowid;             /* Rowid for current entry */
  8557   8714     sqlite3_rtree_dbl rParentScore;   /* Score of parent node */
................................................................................
  8739   8896   ** in tables that are not attached to the Session oject, the filter is called
  8740   8897   ** to determine whether changes to the table's rows should be tracked or not. 
  8741   8898   ** If xFilter returns 0, changes is not tracked. Note that once a table is 
  8742   8899   ** attached, xFilter will not be called again.
  8743   8900   */
  8744   8901   void sqlite3session_table_filter(
  8745   8902     sqlite3_session *pSession,      /* Session object */
  8746         -  int(*xFilter)(
         8903  +  int(SQLITE_CALLBACK *xFilter)(
  8747   8904       void *pCtx,                   /* Copy of third arg to _filter_table() */
  8748   8905       const char *zTab              /* Table name */
  8749   8906     ),
  8750   8907     void *pCtx                      /* First argument passed to xFilter */
  8751   8908   );
  8752   8909   
  8753   8910   /*
................................................................................
  9314   9471   ** CAPI3REF: Combine two or more changesets into a single changeset.
  9315   9472   **
  9316   9473   ** An sqlite3_changegroup object is used to combine two or more changesets
  9317   9474   ** (or patchsets) into a single changeset (or patchset). A single changegroup
  9318   9475   ** object may combine changesets or patchsets, but not both. The output is
  9319   9476   ** always in the same format as the input.
  9320   9477   **
  9321         -** If successful, this function returns SQLITE_OK and populates (*pp) with
         9478  +** If successful, this function returns SQLITE_OK and populates (SQLITE_CALLBACK *pp) with
  9322   9479   ** a pointer to a new sqlite3_changegroup object before returning. The caller
  9323   9480   ** should eventually free the returned object using a call to 
  9324   9481   ** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
  9325   9482   ** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
  9326   9483   **
  9327   9484   ** The usual usage pattern for an sqlite3_changegroup object is as follows:
  9328   9485   **
................................................................................
  9434   9591   ** in the same order as for the very first changeset added to the changegroup.
  9435   9592   ** If the second or subsequent changesets added to the changegroup contain
  9436   9593   ** changes for tables that do not appear in the first changeset, they are
  9437   9594   ** appended onto the end of the output changeset, again in the order in
  9438   9595   ** which they are first encountered.
  9439   9596   **
  9440   9597   ** If an error occurs, an SQLite error code is returned and the output
  9441         -** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
         9598  +** variables (SQLITE_CALLBACK *pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
  9442   9599   ** is returned and the output variables are set to the size of and a 
  9443   9600   ** pointer to the output buffer, respectively. In this case it is the
  9444   9601   ** responsibility of the caller to eventually free the buffer using a
  9445   9602   ** call to sqlite3_free().
  9446   9603   */
  9447   9604   int sqlite3changegroup_output(
  9448   9605     sqlite3_changegroup*,
................................................................................
  9591   9748   ** rolled back, restoring the target database to its original state, and an 
  9592   9749   ** SQLite error code returned.
  9593   9750   */
  9594   9751   int sqlite3changeset_apply(
  9595   9752     sqlite3 *db,                    /* Apply change to "main" db of this handle */
  9596   9753     int nChangeset,                 /* Size of changeset in bytes */
  9597   9754     void *pChangeset,               /* Changeset blob */
  9598         -  int(*xFilter)(
         9755  +  int(SQLITE_CALLBACK *xFilter)(
  9599   9756       void *pCtx,                   /* Copy of sixth arg to _apply() */
  9600   9757       const char *zTab              /* Table name */
  9601   9758     ),
  9602         -  int(*xConflict)(
         9759  +  int(SQLITE_CALLBACK *xConflict)(
  9603   9760       void *pCtx,                   /* Copy of sixth arg to _apply() */
  9604   9761       int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  9605   9762       sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  9606   9763     ),
  9607   9764     void *pCtx                      /* First argument passed to xConflict */
  9608   9765   );
  9609   9766   
................................................................................
  9736   9893   **  &nbsp;     int nChangeset,
  9737   9894   **  &nbsp;     void *pChangeset,
  9738   9895   **  </pre>
  9739   9896   **
  9740   9897   ** Is replaced by:
  9741   9898   **
  9742   9899   **  <pre>
  9743         -**  &nbsp;     int (*xInput)(void *pIn, void *pData, int *pnData),
         9900  +**  &nbsp;     int (SQLITE_CALLBACK *xInput)(void *pIn, void *pData, int *pnData),
  9744   9901   **  &nbsp;     void *pIn,
  9745   9902   **  </pre>
  9746   9903   **
  9747   9904   ** Each time the xInput callback is invoked by the sessions module, the first
  9748   9905   ** argument passed is a copy of the supplied pIn context pointer. The second 
  9749         -** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no 
  9750         -** error occurs the xInput method should copy up to (*pnData) bytes of data 
  9751         -** into the buffer and set (*pnData) to the actual number of bytes copied 
  9752         -** before returning SQLITE_OK. If the input is completely exhausted, (*pnData) 
         9906  +** argument, pData, points to a buffer (SQLITE_CALLBACK *pnData) bytes in size. Assuming no 
         9907  +** error occurs the xInput method should copy up to (SQLITE_CALLBACK *pnData) bytes of data 
         9908  +** into the buffer and set (SQLITE_CALLBACK *pnData) to the actual number of bytes copied 
         9909  +** before returning SQLITE_OK. If the input is completely exhausted, (SQLITE_CALLBACK *pnData) 
  9753   9910   ** should be set to zero to indicate this. Or, if an error occurs, an SQLite 
  9754   9911   ** error code should be returned. In all cases, if an xInput callback returns
  9755   9912   ** an error, all processing is abandoned and the streaming API function
  9756   9913   ** returns a copy of the error code to the caller.
  9757   9914   **
  9758   9915   ** In the case of sqlite3changeset_start_strm(), the xInput callback may be
  9759   9916   ** invoked by the sessions module at any point during the lifetime of the
................................................................................
  9770   9927   **  &nbsp;     int *pnChangeset,
  9771   9928   **  &nbsp;     void **ppChangeset,
  9772   9929   **  </pre>
  9773   9930   **
  9774   9931   ** Is replaced by:
  9775   9932   **
  9776   9933   **  <pre>
  9777         -**  &nbsp;     int (*xOutput)(void *pOut, const void *pData, int nData),
         9934  +**  &nbsp;     int (SQLITE_CALLBACK *xOutput)(void *pOut, const void *pData, int nData),
  9778   9935   **  &nbsp;     void *pOut
  9779   9936   **  </pre>
  9780   9937   **
  9781   9938   ** The xOutput callback is invoked zero or more times to return data to
  9782   9939   ** the application. The first parameter passed to each call is a copy of the
  9783   9940   ** pOut pointer supplied by the application. The second parameter, pData,
  9784   9941   ** points to a buffer nData bytes in size containing the chunk of output
................................................................................
  9790   9947   **
  9791   9948   ** The sessions module never invokes an xOutput callback with the third 
  9792   9949   ** parameter set to a value less than or equal to zero. Other than this,
  9793   9950   ** no guarantees are made as to the size of the chunks of data returned.
  9794   9951   */
  9795   9952   int sqlite3changeset_apply_strm(
  9796   9953     sqlite3 *db,                    /* Apply change to "main" db of this handle */
  9797         -  int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
         9954  +  int (SQLITE_CALLBACK *xInput)(void *pIn, void *pData, int *pnData), /* Input function */
  9798   9955     void *pIn,                                          /* First arg for xInput */
  9799         -  int(*xFilter)(
         9956  +  int(SQLITE_CALLBACK *xFilter)(
  9800   9957       void *pCtx,                   /* Copy of sixth arg to _apply() */
  9801   9958       const char *zTab              /* Table name */
  9802   9959     ),
  9803         -  int(*xConflict)(
         9960  +  int(SQLITE_CALLBACK *xConflict)(
  9804   9961       void *pCtx,                   /* Copy of sixth arg to _apply() */
  9805   9962       int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  9806   9963       sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  9807   9964     ),
  9808   9965     void *pCtx                      /* First argument passed to xConflict */
  9809   9966   );
  9810   9967   int sqlite3changeset_concat_strm(
  9811         -  int (*xInputA)(void *pIn, void *pData, int *pnData),
         9968  +  int (SQLITE_CALLBACK *xInputA)(void *pIn, void *pData, int *pnData),
  9812   9969     void *pInA,
  9813         -  int (*xInputB)(void *pIn, void *pData, int *pnData),
         9970  +  int (SQLITE_CALLBACK *xInputB)(void *pIn, void *pData, int *pnData),
  9814   9971     void *pInB,
  9815         -  int (*xOutput)(void *pOut, const void *pData, int nData),
         9972  +  int (SQLITE_CALLBACK *xOutput)(void *pOut, const void *pData, int nData),
  9816   9973     void *pOut
  9817   9974   );
  9818   9975   int sqlite3changeset_invert_strm(
  9819         -  int (*xInput)(void *pIn, void *pData, int *pnData),
         9976  +  int (SQLITE_CALLBACK *xInput)(void *pIn, void *pData, int *pnData),
  9820   9977     void *pIn,
  9821         -  int (*xOutput)(void *pOut, const void *pData, int nData),
         9978  +  int (SQLITE_CALLBACK *xOutput)(void *pOut, const void *pData, int nData),
  9822   9979     void *pOut
  9823   9980   );
  9824   9981   int sqlite3changeset_start_strm(
  9825   9982     sqlite3_changeset_iter **pp,
  9826         -  int (*xInput)(void *pIn, void *pData, int *pnData),
         9983  +  int (SQLITE_CALLBACK *xInput)(void *pIn, void *pData, int *pnData),
  9827   9984     void *pIn
  9828   9985   );
  9829   9986   int sqlite3session_changeset_strm(
  9830   9987     sqlite3_session *pSession,
  9831         -  int (*xOutput)(void *pOut, const void *pData, int nData),
         9988  +  int (SQLITE_CALLBACK *xOutput)(void *pOut, const void *pData, int nData),
  9832   9989     void *pOut
  9833   9990   );
  9834   9991   int sqlite3session_patchset_strm(
  9835   9992     sqlite3_session *pSession,
  9836         -  int (*xOutput)(void *pOut, const void *pData, int nData),
         9993  +  int (SQLITE_CALLBACK *xOutput)(void *pOut, const void *pData, int nData),
  9837   9994     void *pOut
  9838   9995   );
  9839   9996   int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
  9840         -    int (*xInput)(void *pIn, void *pData, int *pnData),
         9997  +    int (SQLITE_CALLBACK *xInput)(void *pIn, void *pData, int *pnData),
  9841   9998       void *pIn
  9842   9999   );
  9843  10000   int sqlite3changegroup_output_strm(sqlite3_changegroup*,
  9844         -    int (*xOutput)(void *pOut, const void *pData, int nData), 
        10001  +    int (SQLITE_CALLBACK *xOutput)(void *pOut, const void *pData, int nData), 
  9845  10002       void *pOut
  9846  10003   );
  9847  10004   
  9848  10005   
  9849  10006   /*
  9850  10007   ** Make sure we can call this stuff from C++.
  9851  10008   */
................................................................................
  9892  10049   ** the sqlite3_module.xFindFunction() method.
  9893  10050   */
  9894  10051   
  9895  10052   typedef struct Fts5ExtensionApi Fts5ExtensionApi;
  9896  10053   typedef struct Fts5Context Fts5Context;
  9897  10054   typedef struct Fts5PhraseIter Fts5PhraseIter;
  9898  10055   
  9899         -typedef void (*fts5_extension_function)(
        10056  +typedef void (SQLITE_CALLBACK *fts5_extension_function)(
  9900  10057     const Fts5ExtensionApi *pApi,   /* API offered by current FTS version */
  9901  10058     Fts5Context *pFts,              /* First arg to pass to pApi functions */
  9902  10059     sqlite3_context *pCtx,          /* Context for returning result/error */
  9903  10060     int nVal,                       /* Number of values in apVal[] array */
  9904  10061     sqlite3_value **apVal           /* Array of trailing arguments */
  9905  10062   );
  9906  10063   
................................................................................
  9943  10100   **   returned.
  9944  10101   **
  9945  10102   **   This function may be quite inefficient if used with an FTS5 table
  9946  10103   **   created with the "columnsize=0" option.
  9947  10104   **
  9948  10105   ** xColumnText:
  9949  10106   **   This function attempts to retrieve the text of column iCol of the
  9950         -**   current document. If successful, (*pz) is set to point to a buffer
  9951         -**   containing the text in utf-8 encoding, (*pn) is set to the size in bytes
        10107  +**   current document. If successful, (SQLITE_CALLBACK *pz) is set to point to a buffer
        10108  +**   containing the text in utf-8 encoding, (SQLITE_CALLBACK *pn) is set to the size in bytes
  9952  10109   **   (not characters) of the buffer and SQLITE_OK is returned. Otherwise,
  9953  10110   **   if an error occurs, an SQLite error code is returned and the final values
  9954         -**   of (*pz) and (*pn) are undefined.
        10111  +**   of (SQLITE_CALLBACK *pz) and (*pn) are undefined.
  9955  10112   **
  9956  10113   ** xPhraseCount:
  9957  10114   **   Returns the number of phrases in the current query expression.
  9958  10115   **
  9959  10116   ** xPhraseSize:
  9960  10117   **   Returns the number of tokens in phrase iPhrase of the query. Phrases
  9961  10118   **   are numbered starting from zero.
................................................................................
 10056  10213   **
 10057  10214   **
 10058  10215   ** xRowCount(pFts5, pnRow)
 10059  10216   **
 10060  10217   **   This function is used to retrieve the total number of rows in the table.
 10061  10218   **   In other words, the same value that would be returned by:
 10062  10219   **
 10063         -**        SELECT count(*) FROM ftstable;
        10220  +**        SELECT count(SQLITE_CALLBACK *) FROM ftstable;
 10064  10221   **
 10065  10222   ** xPhraseFirst()
 10066  10223   **   This function is used, along with type Fts5PhraseIter and the xPhraseNext
 10067  10224   **   method, to iterate through all instances of a single query phrase within
 10068  10225   **   the current row. This is the same information as is accessible via the
 10069  10226   **   xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
 10070  10227   **   to use, this API may be faster under some circumstances. To iterate 
................................................................................
 10123  10280   **
 10124  10281   ** xPhraseNextColumn()
 10125  10282   **   See xPhraseFirstColumn above.
 10126  10283   */
 10127  10284   struct Fts5ExtensionApi {
 10128  10285     int iVersion;                   /* Currently always set to 3 */
 10129  10286   
 10130         -  void *(*xUserData)(Fts5Context*);
        10287  +  void *(SQLITE_CALLBACK *xUserData)(Fts5Context*);
 10131  10288   
 10132         -  int (*xColumnCount)(Fts5Context*);
 10133         -  int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);
 10134         -  int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);
        10289  +  int (SQLITE_CALLBACK *xColumnCount)(Fts5Context*);
        10290  +  int (SQLITE_CALLBACK *xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);
        10291  +  int (SQLITE_CALLBACK *xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);
 10135  10292   
 10136         -  int (*xTokenize)(Fts5Context*, 
        10293  +  int (SQLITE_CALLBACK *xTokenize)(Fts5Context*, 
 10137  10294       const char *pText, int nText, /* Text to tokenize */
 10138  10295       void *pCtx,                   /* Context passed to xToken() */
 10139         -    int (*xToken)(void*, int, const char*, int, int, int)       /* Callback */
 10140         -  );
 10141         -
 10142         -  int (*xPhraseCount)(Fts5Context*);
 10143         -  int (*xPhraseSize)(Fts5Context*, int iPhrase);
 10144         -
 10145         -  int (*xInstCount)(Fts5Context*, int *pnInst);
 10146         -  int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);
 10147         -
 10148         -  sqlite3_int64 (*xRowid)(Fts5Context*);
 10149         -  int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn);
 10150         -  int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken);
 10151         -
 10152         -  int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData,
 10153         -    int(*)(const Fts5ExtensionApi*,Fts5Context*,void*)
 10154         -  );
 10155         -  int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*));
 10156         -  void *(*xGetAuxdata)(Fts5Context*, int bClear);
 10157         -
 10158         -  int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*);
 10159         -  void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff);
 10160         -
 10161         -  int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*);
 10162         -  void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);
        10296  +    int (SQLITE_CALLBACK *xToken)(void*, int, const char*, int, int, int)       /* Callback */
        10297  +  );
        10298  +
        10299  +  int (SQLITE_CALLBACK *xPhraseCount)(Fts5Context*);
        10300  +  int (SQLITE_CALLBACK *xPhraseSize)(Fts5Context*, int iPhrase);
        10301  +
        10302  +  int (SQLITE_CALLBACK *xInstCount)(Fts5Context*, int *pnInst);
        10303  +  int (SQLITE_CALLBACK *xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);
        10304  +
        10305  +  sqlite3_int64 (SQLITE_CALLBACK *xRowid)(Fts5Context*);
        10306  +  int (SQLITE_CALLBACK *xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn);
        10307  +  int (SQLITE_CALLBACK *xColumnSize)(Fts5Context*, int iCol, int *pnToken);
        10308  +
        10309  +  int (SQLITE_CALLBACK *xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData,
        10310  +    int(SQLITE_CALLBACK *)(const Fts5ExtensionApi*,Fts5Context*,void*)
        10311  +  );
        10312  +  int (SQLITE_CALLBACK *xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*));
        10313  +  void *(SQLITE_CALLBACK *xGetAuxdata)(Fts5Context*, int bClear);
        10314  +
        10315  +  int (SQLITE_CALLBACK *xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*);
        10316  +  void (SQLITE_CALLBACK *xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff);
        10317  +
        10318  +  int (SQLITE_CALLBACK *xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*);
        10319  +  void (SQLITE_CALLBACK *xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);
 10163  10320   };
 10164  10321   
 10165  10322   /* 
 10166  10323   ** CUSTOM AUXILIARY FUNCTIONS
 10167  10324   *************************************************************************/
 10168  10325   
 10169  10326   /*************************************************************************
................................................................................
 10183  10340   **   pointer provided by the application when the fts5_tokenizer object
 10184  10341   **   was registered with FTS5 (the third argument to xCreateTokenizer()). 
 10185  10342   **   The second and third arguments are an array of nul-terminated strings
 10186  10343   **   containing the tokenizer arguments, if any, specified following the
 10187  10344   **   tokenizer name as part of the CREATE VIRTUAL TABLE statement used
 10188  10345   **   to create the FTS5 table.
 10189  10346   **
 10190         -**   The final argument is an output variable. If successful, (*ppOut) 
        10347  +**   The final argument is an output variable. If successful, (SQLITE_CALLBACK *ppOut) 
 10191  10348   **   should be set to point to the new tokenizer handle and SQLITE_OK
 10192  10349   **   returned. If an error occurs, some value other than SQLITE_OK should
 10193  10350   **   be returned. In this case, fts5 assumes that the final value of *ppOut 
 10194  10351   **   is undefined.
 10195  10352   **
 10196  10353   ** xDelete:
 10197  10354   **   This function is invoked to delete a tokenizer handle previously
................................................................................
 10357  10514   **   provide synonyms when tokenizing document text (method (2)) or query
 10358  10515   **   text (method (3)), not both. Doing so will not cause any errors, but is
 10359  10516   **   inefficient.
 10360  10517   */
 10361  10518   typedef struct Fts5Tokenizer Fts5Tokenizer;
 10362  10519   typedef struct fts5_tokenizer fts5_tokenizer;
 10363  10520   struct fts5_tokenizer {
 10364         -  int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
 10365         -  void (*xDelete)(Fts5Tokenizer*);
 10366         -  int (*xTokenize)(Fts5Tokenizer*, 
        10521  +  int (SQLITE_CALLBACK *xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
        10522  +  void (SQLITE_CALLBACK *xDelete)(Fts5Tokenizer*);
        10523  +  int (SQLITE_CALLBACK *xTokenize)(Fts5Tokenizer*, 
 10367  10524         void *pCtx,
 10368  10525         int flags,            /* Mask of FTS5_TOKENIZE_* flags */
 10369  10526         const char *pText, int nText, 
 10370         -      int (*xToken)(
        10527  +      int (SQLITE_CALLBACK *xToken)(
 10371  10528           void *pCtx,         /* Copy of 2nd argument to xTokenize() */
 10372  10529           int tflags,         /* Mask of FTS5_TOKEN_* flags */
 10373  10530           const char *pToken, /* Pointer to buffer containing token */
 10374  10531           int nToken,         /* Size of token in bytes */
 10375  10532           int iStart,         /* Byte offset of token within input text */
 10376  10533           int iEnd            /* Byte offset of end of token within input text */
 10377  10534         )
................................................................................
 10396  10553   ** FTS5 EXTENSION REGISTRATION API
 10397  10554   */
 10398  10555   typedef struct fts5_api fts5_api;
 10399  10556   struct fts5_api {
 10400  10557     int iVersion;                   /* Currently always set to 2 */
 10401  10558   
 10402  10559     /* Create a new tokenizer */
 10403         -  int (*xCreateTokenizer)(
        10560  +  int (SQLITE_CALLBACK *xCreateTokenizer)(
 10404  10561       fts5_api *pApi,
 10405  10562       const char *zName,
 10406  10563       void *pContext,
 10407  10564       fts5_tokenizer *pTokenizer,
 10408         -    void (*xDestroy)(void*)
        10565  +    void (SQLITE_CALLBACK *xDestroy)(void*)
 10409  10566     );
 10410  10567   
 10411  10568     /* Find an existing tokenizer */
 10412         -  int (*xFindTokenizer)(
        10569  +  int (SQLITE_CALLBACK *xFindTokenizer)(
 10413  10570       fts5_api *pApi,
 10414  10571       const char *zName,
 10415  10572       void **ppContext,
 10416  10573       fts5_tokenizer *pTokenizer
 10417  10574     );
 10418  10575   
 10419  10576     /* Create a new auxiliary function */
 10420         -  int (*xCreateFunction)(
        10577  +  int (SQLITE_CALLBACK *xCreateFunction)(
 10421  10578       fts5_api *pApi,
 10422  10579       const char *zName,
 10423  10580       void *pContext,
 10424  10581       fts5_extension_function xFunction,
 10425         -    void (*xDestroy)(void*)
        10582  +    void (SQLITE_CALLBACK *xDestroy)(void*)
 10426  10583     );
 10427  10584   };
 10428  10585   
 10429  10586   /*
 10430  10587   ** END OF REGISTRATION API
 10431  10588   *************************************************************************/
 10432  10589   
................................................................................
 10730  10887   
 10731  10888   /*
 10732  10889   ** Make sure that the compiler intrinsics we desire are enabled when
 10733  10890   ** compiling with an appropriate version of MSVC unless prevented by
 10734  10891   ** the SQLITE_DISABLE_INTRINSIC define.
 10735  10892   */
 10736  10893   #if !defined(SQLITE_DISABLE_INTRINSIC)
 10737         -#  if defined(_MSC_VER) && _MSC_VER>=1300
        10894  +#  if defined(_MSC_VER) && _MSC_VER>=1400
 10738  10895   #    if !defined(_WIN32_WCE)
 10739  10896   #      include <intrin.h>
 10740  10897   #      pragma intrinsic(_byteswap_ushort)
 10741  10898   #      pragma intrinsic(_byteswap_ulong)
 10742  10899   #      pragma intrinsic(_ReadWriteBarrier)
 10743  10900   #    else
 10744  10901   #      include <cmnintrin.h>
................................................................................
 11007  11164   **    May you find forgiveness for yourself and forgive others.
 11008  11165   **    May you share freely, never taking more than you give.
 11009  11166   **
 11010  11167   *************************************************************************
 11011  11168   ** This is the header file for the generic hash-table implementation
 11012  11169   ** used in SQLite.
 11013  11170   */
 11014         -#ifndef _SQLITE_HASH_H_
 11015         -#define _SQLITE_HASH_H_
        11171  +#ifndef SQLITE_HASH_H
        11172  +#define SQLITE_HASH_H
 11016  11173   
 11017  11174   /* Forward declarations of structures. */
 11018  11175   typedef struct Hash Hash;
 11019  11176   typedef struct HashElem HashElem;
 11020  11177   
 11021  11178   /* A complete hash table is an instance of the following structure.
 11022  11179   ** The internals of this structure are intended to be opaque -- client
................................................................................
 11088  11245   /* #define sqliteHashKeysize(E) ((E)->nKey)  // NOT USED */
 11089  11246   
 11090  11247   /*
 11091  11248   ** Number of entries in a hash table
 11092  11249   */
 11093  11250   /* #define sqliteHashCount(H)  ((H)->count) // NOT USED */
 11094  11251   
 11095         -#endif /* _SQLITE_HASH_H_ */
        11252  +#endif /* SQLITE_HASH_H */
 11096  11253   
 11097  11254   /************** End of hash.h ************************************************/
 11098  11255   /************** Continuing where we left off in sqliteInt.h ******************/
 11099  11256   /************** Include parse.h in the middle of sqliteInt.h *****************/
 11100  11257   /************** Begin file parse.h *******************************************/
 11101  11258   #define TK_SEMI                             1
 11102  11259   #define TK_EXPLAIN                          2
................................................................................
 11736  11893   ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
 11737  11894   ** macros become no-ops and have zero performance impact.
 11738  11895   */
 11739  11896   #ifdef SQLITE_OMIT_WSD
 11740  11897     #define SQLITE_WSD const
 11741  11898     #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
 11742  11899     #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
 11743         -SQLITE_API int SQLITE_STDCALL sqlite3_wsd_init(int N, int J);
 11744         -SQLITE_API void *SQLITE_STDCALL sqlite3_wsd_find(void *K, int L);
        11900  +SQLITE_API int SQLITE_APICALL sqlite3_wsd_init(int N, int J);
        11901  +SQLITE_API void *SQLITE_APICALL sqlite3_wsd_find(void *K, int L);
 11745  11902   #else
 11746  11903     #define SQLITE_WSD
 11747  11904     #define GLOBAL(t,v) v
 11748  11905     #define sqlite3GlobalConfig sqlite3Config
 11749  11906   #endif
 11750  11907   
 11751  11908   /*
................................................................................
 11836  11993   **    May you share freely, never taking more than you give.
 11837  11994   **
 11838  11995   *************************************************************************
 11839  11996   ** This header file defines the interface that the sqlite B-Tree file
 11840  11997   ** subsystem.  See comments in the source code for a detailed description
 11841  11998   ** of what each interface routine does.
 11842  11999   */
 11843         -#ifndef _BTREE_H_
 11844         -#define _BTREE_H_
        12000  +#ifndef SQLITE_BTREE_H
        12001  +#define SQLITE_BTREE_H
 11845  12002   
 11846  12003   /* TODO: This definition is just included so other modules compile. It
 11847  12004   ** needs to be revisited.
 11848  12005   */
 11849  12006   #define SQLITE_N_BTREE_META 16
 11850  12007   
 11851  12008   /*
................................................................................
 11862  12019   
 11863  12020   /*
 11864  12021   ** Forward declarations of structure
 11865  12022   */
 11866  12023   typedef struct Btree Btree;
 11867  12024   typedef struct BtCursor BtCursor;
 11868  12025   typedef struct BtShared BtShared;
        12026  +typedef struct BtreePayload BtreePayload;
 11869  12027   
 11870  12028   
 11871  12029   SQLITE_PRIVATE int sqlite3BtreeOpen(
 11872  12030     sqlite3_vfs *pVfs,       /* VFS to use with this b-tree */
 11873  12031     const char *zFilename,   /* Name of database file to open */
 11874  12032     sqlite3 *db,             /* Associated database connection */
 11875  12033     Btree **ppBtree,         /* Return open Btree* here */
................................................................................
 12073  12231   SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*);
 12074  12232   SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags);
 12075  12233   
 12076  12234   /* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */
 12077  12235   #define BTREE_SAVEPOSITION 0x02  /* Leave cursor pointing at NEXT or PREV */
 12078  12236   #define BTREE_AUXDELETE    0x04  /* not the primary delete operation */
 12079  12237   
 12080         -SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
 12081         -                                  const void *pData, int nData,
 12082         -                                  int nZero, int bias, int seekResult);
        12238  +/* An instance of the BtreePayload object describes the content of a single
        12239  +** entry in either an index or table btree.
        12240  +**
        12241  +** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
        12242  +** an arbitrary key and no data.  These btrees have pKey,nKey set to their
        12243  +** key and pData,nData,nZero set to zero.
        12244  +**
        12245  +** Table btrees (used for rowid tables) contain an integer rowid used as
        12246  +** the key and passed in the nKey field.  The pKey field is zero.  
        12247  +** pData,nData hold the content of the new entry.  nZero extra zero bytes
        12248  +** are appended to the end of the content when constructing the entry.
        12249  +**
        12250  +** This object is used to pass information into sqlite3BtreeInsert().  The
        12251  +** same information used to be passed as five separate parameters.  But placing
        12252  +** the information into this object helps to keep the interface more 
        12253  +** organized and understandable, and it also helps the resulting code to
        12254  +** run a little faster by using fewer registers for parameter passing.
        12255  +*/
        12256  +struct BtreePayload {
        12257  +  const void *pKey;       /* Key content for indexes.  NULL for tables */
        12258  +  sqlite3_int64 nKey;     /* Size of pKey for indexes.  PRIMARY KEY for tabs */
        12259  +  const void *pData;      /* Data for tables.  NULL for indexes */
        12260  +  int nData;              /* Size of pData.  0 if none. */
        12261  +  int nZero;              /* Extra zero data appended after pData,nData */
        12262  +};
        12263  +
        12264  +SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
        12265  +                       int bias, int seekResult);
 12083  12266   SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
 12084  12267   SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
 12085  12268   SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
 12086  12269   SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
 12087  12270   SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
 12088         -SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
        12271  +SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
 12089  12272   SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
 12090         -SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
 12091         -SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
 12092         -SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
        12273  +SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
        12274  +SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
 12093  12275   SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
 12094  12276   
 12095  12277   SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
 12096  12278   SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
 12097  12279   
 12098  12280   SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
 12099  12281   SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
................................................................................
 12126  12308   ** Enter and Leave procedures no-ops.
 12127  12309   */
 12128  12310   #ifndef SQLITE_OMIT_SHARED_CACHE
 12129  12311   SQLITE_PRIVATE   void sqlite3BtreeEnter(Btree*);
 12130  12312   SQLITE_PRIVATE   void sqlite3BtreeEnterAll(sqlite3*);
 12131  12313   SQLITE_PRIVATE   int sqlite3BtreeSharable(Btree*);
 12132  12314   SQLITE_PRIVATE   void sqlite3BtreeEnterCursor(BtCursor*);
        12315  +SQLITE_PRIVATE   int sqlite3BtreeConnectionCount(Btree*);
 12133  12316   #else
 12134  12317   # define sqlite3BtreeEnter(X) 
 12135  12318   # define sqlite3BtreeEnterAll(X)
 12136  12319   # define sqlite3BtreeSharable(X) 0
 12137  12320   # define sqlite3BtreeEnterCursor(X)
        12321  +# define sqlite3BtreeConnectionCount(X) 1
 12138  12322   #endif
 12139  12323   
 12140  12324   #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
 12141  12325   SQLITE_PRIVATE   void sqlite3BtreeLeave(Btree*);
 12142  12326   SQLITE_PRIVATE   void sqlite3BtreeLeaveCursor(BtCursor*);
 12143  12327   SQLITE_PRIVATE   void sqlite3BtreeLeaveAll(sqlite3*);
 12144  12328   #ifndef NDEBUG
................................................................................
 12155  12339   
 12156  12340   # define sqlite3BtreeHoldsMutex(X) 1
 12157  12341   # define sqlite3BtreeHoldsAllMutexes(X) 1
 12158  12342   # define sqlite3SchemaMutexHeld(X,Y,Z) 1
 12159  12343   #endif
 12160  12344   
 12161  12345   
 12162         -#endif /* _BTREE_H_ */
        12346  +#endif /* SQLITE_BTREE_H */
 12163  12347   
 12164  12348   /************** End of btree.h ***********************************************/
 12165  12349   /************** Continuing where we left off in sqliteInt.h ******************/
 12166  12350   /************** Include vdbe.h in the middle of sqliteInt.h ******************/
 12167  12351   /************** Begin file vdbe.h ********************************************/
 12168  12352   /*
 12169  12353   ** 2001 September 15
................................................................................
 12178  12362   *************************************************************************
 12179  12363   ** Header file for the Virtual DataBase Engine (VDBE)
 12180  12364   **
 12181  12365   ** This header defines the interface to the virtual database engine
 12182  12366   ** or VDBE.  The VDBE implements an abstract machine that runs a
 12183  12367   ** simple program to access and modify the underlying database.
 12184  12368   */
 12185         -#ifndef _SQLITE_VDBE_H_
 12186         -#define _SQLITE_VDBE_H_
        12369  +#ifndef SQLITE_VDBE_H
        12370  +#define SQLITE_VDBE_H
 12187  12371   /* #include <stdio.h> */
 12188  12372   
 12189  12373   /*
 12190  12374   ** A single VDBE is an opaque structure named "Vdbe".  Only routines
 12191  12375   ** in the source file sqliteVdbe.c are allowed to see the insides
 12192  12376   ** of this structure.
 12193  12377   */
................................................................................
 12364  12548   #define OP_SeekGE         25 /* synopsis: key=r[P3@P4]                     */
 12365  12549   #define OP_SeekGT         26 /* synopsis: key=r[P3@P4]                     */
 12366  12550   #define OP_Or             27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
 12367  12551   #define OP_And            28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
 12368  12552   #define OP_NoConflict     29 /* synopsis: key=r[P3@P4]                     */
 12369  12553   #define OP_NotFound       30 /* synopsis: key=r[P3@P4]                     */
 12370  12554   #define OP_Found          31 /* synopsis: key=r[P3@P4]                     */
 12371         -#define OP_NotExists      32 /* synopsis: intkey=r[P3]                     */
 12372         -#define OP_Last           33
        12555  +#define OP_SeekRowid      32 /* synopsis: intkey=r[P3]                     */
        12556  +#define OP_NotExists      33 /* synopsis: intkey=r[P3]                     */
 12373  12557   #define OP_IsNull         34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
 12374  12558   #define OP_NotNull        35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
 12375  12559   #define OP_Ne             36 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
 12376  12560   #define OP_Eq             37 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
 12377  12561   #define OP_Gt             38 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
 12378  12562   #define OP_Le             39 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
 12379  12563   #define OP_Lt             40 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
 12380  12564   #define OP_Ge             41 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
 12381         -#define OP_SorterSort     42
        12565  +#define OP_Last           42
 12382  12566   #define OP_BitAnd         43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
 12383  12567   #define OP_BitOr          44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
 12384  12568   #define OP_ShiftLeft      45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
 12385  12569   #define OP_ShiftRight     46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
 12386  12570   #define OP_Add            47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
 12387  12571   #define OP_Subtract       48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
 12388  12572   #define OP_Multiply       49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
 12389  12573   #define OP_Divide         50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
 12390  12574   #define OP_Remainder      51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
 12391  12575   #define OP_Concat         52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 12392         -#define OP_Sort           53
        12576  +#define OP_SorterSort     53
 12393  12577   #define OP_BitNot         54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
 12394         -#define OP_Rewind         55
 12395         -#define OP_IdxLE          56 /* synopsis: key=r[P3@P4]                     */
 12396         -#define OP_IdxGT          57 /* synopsis: key=r[P3@P4]                     */
 12397         -#define OP_IdxLT          58 /* synopsis: key=r[P3@P4]                     */
 12398         -#define OP_IdxGE          59 /* synopsis: key=r[P3@P4]                     */
 12399         -#define OP_RowSetRead     60 /* synopsis: r[P3]=rowset(P1)                 */
 12400         -#define OP_RowSetTest     61 /* synopsis: if r[P3] in rowset(P1) goto P2   */
 12401         -#define OP_Program        62
 12402         -#define OP_FkIfZero       63 /* synopsis: if fkctr[P1]==0 goto P2          */
 12403         -#define OP_IfPos          64 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
 12404         -#define OP_IfNotZero      65 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
 12405         -#define OP_DecrJumpZero   66 /* synopsis: if (--r[P1])==0 goto P2          */
 12406         -#define OP_IncrVacuum     67
 12407         -#define OP_VNext          68
 12408         -#define OP_Init           69 /* synopsis: Start at P2                      */
 12409         -#define OP_Return         70
 12410         -#define OP_EndCoroutine   71
 12411         -#define OP_HaltIfNull     72 /* synopsis: if r[P3]=null halt               */
 12412         -#define OP_Halt           73
 12413         -#define OP_Integer        74 /* synopsis: r[P2]=P1                         */
 12414         -#define OP_Int64          75 /* synopsis: r[P2]=P4                         */
 12415         -#define OP_String         76 /* synopsis: r[P2]='P4' (len=P1)              */
 12416         -#define OP_Null           77 /* synopsis: r[P2..P3]=NULL                   */
 12417         -#define OP_SoftNull       78 /* synopsis: r[P1]=NULL                       */
 12418         -#define OP_Blob           79 /* synopsis: r[P2]=P4 (len=P1)                */
 12419         -#define OP_Variable       80 /* synopsis: r[P2]=parameter(P1,P4)           */
 12420         -#define OP_Move           81 /* synopsis: r[P2@P3]=r[P1@P3]                */
 12421         -#define OP_Copy           82 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
 12422         -#define OP_SCopy          83 /* synopsis: r[P2]=r[P1]                      */
 12423         -#define OP_IntCopy        84 /* synopsis: r[P2]=r[P1]                      */
 12424         -#define OP_ResultRow      85 /* synopsis: output=r[P1@P2]                  */
 12425         -#define OP_CollSeq        86
 12426         -#define OP_Function0      87 /* synopsis: r[P3]=func(r[P2@P5])             */
 12427         -#define OP_Function       88 /* synopsis: r[P3]=func(r[P2@P5])             */
 12428         -#define OP_AddImm         89 /* synopsis: r[P1]=r[P1]+P2                   */
 12429         -#define OP_RealAffinity   90
 12430         -#define OP_Cast           91 /* synopsis: affinity(r[P1])                  */
 12431         -#define OP_Permutation    92
 12432         -#define OP_Compare        93 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
 12433         -#define OP_Column         94 /* synopsis: r[P3]=PX                         */
 12434         -#define OP_Affinity       95 /* synopsis: affinity(r[P1@P2])               */
 12435         -#define OP_MakeRecord     96 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
        12578  +#define OP_Sort           55
        12579  +#define OP_Rewind         56
        12580  +#define OP_IdxLE          57 /* synopsis: key=r[P3@P4]                     */
        12581  +#define OP_IdxGT          58 /* synopsis: key=r[P3@P4]                     */
        12582  +#define OP_IdxLT          59 /* synopsis: key=r[P3@P4]                     */
        12583  +#define OP_IdxGE          60 /* synopsis: key=r[P3@P4]                     */
        12584  +#define OP_RowSetRead     61 /* synopsis: r[P3]=rowset(P1)                 */
        12585  +#define OP_RowSetTest     62 /* synopsis: if r[P3] in rowset(P1) goto P2   */
        12586  +#define OP_Program        63
        12587  +#define OP_FkIfZero       64 /* synopsis: if fkctr[P1]==0 goto P2          */
        12588  +#define OP_IfPos          65 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
        12589  +#define OP_IfNotZero      66 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
        12590  +#define OP_DecrJumpZero   67 /* synopsis: if (--r[P1])==0 goto P2          */
        12591  +#define OP_IncrVacuum     68
        12592  +#define OP_VNext          69
        12593  +#define OP_Init           70 /* synopsis: Start at P2                      */
        12594  +#define OP_Return         71
        12595  +#define OP_EndCoroutine   72
        12596  +#define OP_HaltIfNull     73 /* synopsis: if r[P3]=null halt               */
        12597  +#define OP_Halt           74
        12598  +#define OP_Integer        75 /* synopsis: r[P2]=P1                         */
        12599  +#define OP_Int64          76 /* synopsis: r[P2]=P4                         */
        12600  +#define OP_String         77 /* synopsis: r[P2]='P4' (len=P1)              */
        12601  +#define OP_Null           78 /* synopsis: r[P2..P3]=NULL                   */
        12602  +#define OP_SoftNull       79 /* synopsis: r[P1]=NULL                       */
        12603  +#define OP_Blob           80 /* synopsis: r[P2]=P4 (len=P1)                */
        12604  +#define OP_Variable       81 /* synopsis: r[P2]=parameter(P1,P4)           */
        12605  +#define OP_Move           82 /* synopsis: r[P2@P3]=r[P1@P3]                */
        12606  +#define OP_Copy           83 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
        12607  +#define OP_SCopy          84 /* synopsis: r[P2]=r[P1]                      */
        12608  +#define OP_IntCopy        85 /* synopsis: r[P2]=r[P1]                      */
        12609  +#define OP_ResultRow      86 /* synopsis: output=r[P1@P2]                  */
        12610  +#define OP_CollSeq        87
        12611  +#define OP_Function0      88 /* synopsis: r[P3]=func(r[P2@P5])             */
        12612  +#define OP_Function       89 /* synopsis: r[P3]=func(r[P2@P5])             */
        12613  +#define OP_AddImm         90 /* synopsis: r[P1]=r[P1]+P2                   */
        12614  +#define OP_RealAffinity   91
        12615  +#define OP_Cast           92 /* synopsis: affinity(r[P1])                  */
        12616  +#define OP_Permutation    93
        12617  +#define OP_Compare        94 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
        12618  +#define OP_Column         95 /* synopsis: r[P3]=PX                         */
        12619  +#define OP_Affinity       96 /* synopsis: affinity(r[P1@P2])               */
 12436  12620   #define OP_String8        97 /* same as TK_STRING, synopsis: r[P2]='P4'    */
 12437         -#define OP_Count          98 /* synopsis: r[P2]=count()                    */
 12438         -#define OP_ReadCookie     99
 12439         -#define OP_SetCookie     100
 12440         -#define OP_ReopenIdx     101 /* synopsis: root=P2 iDb=P3                   */
 12441         -#define OP_OpenRead      102 /* synopsis: root=P2 iDb=P3                   */
 12442         -#define OP_OpenWrite     103 /* synopsis: root=P2 iDb=P3                   */
 12443         -#define OP_OpenAutoindex 104 /* synopsis: nColumn=P2                       */
 12444         -#define OP_OpenEphemeral 105 /* synopsis: nColumn=P2                       */
 12445         -#define OP_SorterOpen    106
 12446         -#define OP_SequenceTest  107 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
 12447         -#define OP_OpenPseudo    108 /* synopsis: P3 columns in r[P2]              */
 12448         -#define OP_Close         109
 12449         -#define OP_ColumnsUsed   110
 12450         -#define OP_Sequence      111 /* synopsis: r[P2]=cursor[P1].ctr++           */
 12451         -#define OP_NewRowid      112 /* synopsis: r[P2]=rowid                      */
 12452         -#define OP_Insert        113 /* synopsis: intkey=r[P3] data=r[P2]          */
 12453         -#define OP_InsertInt     114 /* synopsis: intkey=P3 data=r[P2]             */
 12454         -#define OP_Delete        115
 12455         -#define OP_ResetCount    116
 12456         -#define OP_SorterCompare 117 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
 12457         -#define OP_SorterData    118 /* synopsis: r[P2]=data                       */
 12458         -#define OP_RowKey        119 /* synopsis: r[P2]=key                        */
 12459         -#define OP_RowData       120 /* synopsis: r[P2]=data                       */
 12460         -#define OP_Rowid         121 /* synopsis: r[P2]=rowid                      */
 12461         -#define OP_NullRow       122
 12462         -#define OP_SorterInsert  123
 12463         -#define OP_IdxInsert     124 /* synopsis: key=r[P2]                        */
 12464         -#define OP_IdxDelete     125 /* synopsis: key=r[P2@P3]                     */
 12465         -#define OP_Seek          126 /* synopsis: Move P3 to P1.rowid              */
 12466         -#define OP_IdxRowid      127 /* synopsis: r[P2]=rowid                      */
 12467         -#define OP_Destroy       128
 12468         -#define OP_Clear         129
 12469         -#define OP_ResetSorter   130
 12470         -#define OP_CreateIndex   131 /* synopsis: r[P2]=root iDb=P1                */
 12471         -#define OP_CreateTable   132 /* synopsis: r[P2]=root iDb=P1                */
        12621  +#define OP_MakeRecord     98 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
        12622  +#define OP_Count          99 /* synopsis: r[P2]=count()                    */
        12623  +#define OP_ReadCookie    100
        12624  +#define OP_SetCookie     101
        12625  +#define OP_ReopenIdx     102 /* synopsis: root=P2 iDb=P3                   */
        12626  +#define OP_OpenRead      103 /* synopsis: root=P2 iDb=P3                   */
        12627  +#define OP_OpenWrite     104 /* synopsis: root=P2 iDb=P3                   */
        12628  +#define OP_OpenAutoindex 105 /* synopsis: nColumn=P2                       */
        12629  +#define OP_OpenEphemeral 106 /* synopsis: nColumn=P2                       */
        12630  +#define OP_SorterOpen    107
        12631  +#define OP_SequenceTest  108 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
        12632  +#define OP_OpenPseudo    109 /* synopsis: P3 columns in r[P2]              */
        12633  +#define OP_Close         110
        12634  +#define OP_ColumnsUsed   111
        12635  +#define OP_Sequence      112 /* synopsis: r[P2]=cursor[P1].ctr++           */
        12636  +#define OP_NewRowid      113 /* synopsis: r[P2]=rowid                      */
        12637  +#define OP_Insert        114 /* synopsis: intkey=r[P3] data=r[P2]          */
        12638  +#define OP_InsertInt     115 /* synopsis: intkey=P3 data=r[P2]             */
        12639  +#define OP_Delete        116
        12640  +#define OP_ResetCount    117
        12641  +#define OP_SorterCompare 118 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
        12642  +#define OP_SorterData    119 /* synopsis: r[P2]=data                       */
        12643  +#define OP_RowKey        120 /* synopsis: r[P2]=key                        */
        12644  +#define OP_RowData       121 /* synopsis: r[P2]=data                       */
        12645  +#define OP_Rowid         122 /* synopsis: r[P2]=rowid                      */
        12646  +#define OP_NullRow       123
        12647  +#define OP_SorterInsert  124
        12648  +#define OP_IdxInsert     125 /* synopsis: key=r[P2]                        */
        12649  +#define OP_IdxDelete     126 /* synopsis: key=r[P2@P3]                     */
        12650  +#define OP_Seek          127 /* synopsis: Move P3 to P1.rowid              */
        12651  +#define OP_IdxRowid      128 /* synopsis: r[P2]=rowid                      */
        12652  +#define OP_Destroy       129
        12653  +#define OP_Clear         130
        12654  +#define OP_ResetSorter   131
        12655  +#define OP_CreateIndex   132 /* synopsis: r[P2]=root iDb=P1                */
 12472  12656   #define OP_Real          133 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
 12473         -#define OP_ParseSchema   134
 12474         -#define OP_LoadAnalysis  135
 12475         -#define OP_DropTable     136
 12476         -#define OP_DropIndex     137
 12477         -#define OP_DropTrigger   138
 12478         -#define OP_IntegrityCk   139
 12479         -#define OP_RowSetAdd     140 /* synopsis: rowset(P1)=r[P2]                 */
 12480         -#define OP_Param         141
 12481         -#define OP_FkCounter     142 /* synopsis: fkctr[P1]+=P2                    */
 12482         -#define OP_MemMax        143 /* synopsis: r[P1]=max(r[P1],r[P2])           */
 12483         -#define OP_OffsetLimit   144 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
 12484         -#define OP_AggStep0      145 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12485         -#define OP_AggStep       146 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12486         -#define OP_AggFinal      147 /* synopsis: accum=r[P1] N=P2                 */
 12487         -#define OP_Expire        148
 12488         -#define OP_TableLock     149 /* synopsis: iDb=P1 root=P2 write=P3          */
 12489         -#define OP_VBegin        150
 12490         -#define OP_VCreate       151
 12491         -#define OP_VDestroy      152
 12492         -#define OP_VOpen         153
 12493         -#define OP_VColumn       154 /* synopsis: r[P3]=vcolumn(P2)                */
 12494         -#define OP_VRename       155
 12495         -#define OP_Pagecount     156
 12496         -#define OP_MaxPgcnt      157
 12497         -#define OP_CursorHint    158
 12498         -#define OP_Noop          159
 12499         -#define OP_Explain       160
        12657  +#define OP_CreateTable   134 /* synopsis: r[P2]=root iDb=P1                */
        12658  +#define OP_ParseSchema   135
        12659  +#define OP_LoadAnalysis  136
        12660  +#define OP_DropTable     137
        12661  +#define OP_DropIndex     138
        12662  +#define OP_DropTrigger   139
        12663  +#define OP_IntegrityCk   140
        12664  +#define OP_RowSetAdd     141 /* synopsis: rowset(P1)=r[P2]                 */
        12665  +#define OP_Param         142
        12666  +#define OP_FkCounter     143 /* synopsis: fkctr[P1]+=P2                    */
        12667  +#define OP_MemMax        144 /* synopsis: r[P1]=max(r[P1],r[P2])           */
        12668  +#define OP_OffsetLimit   145 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
        12669  +#define OP_AggStep0      146 /* synopsis: accum=r[P3] step(r[P2@P5])       */
        12670  +#define OP_AggStep       147 /* synopsis: accum=r[P3] step(r[P2@P5])       */
        12671  +#define OP_AggFinal      148 /* synopsis: accum=r[P1] N=P2                 */
        12672  +#define OP_Expire        149
        12673  +#define OP_TableLock     150 /* synopsis: iDb=P1 root=P2 write=P3          */
        12674  +#define OP_VBegin        151
        12675  +#define OP_VCreate       152
        12676  +#define OP_VDestroy      153
        12677  +#define OP_VOpen         154
        12678  +#define OP_VColumn       155 /* synopsis: r[P3]=vcolumn(P2)                */
        12679  +#define OP_VRename       156
        12680  +#define OP_Pagecount     157
        12681  +#define OP_MaxPgcnt      158
        12682  +#define OP_CursorHint    159
        12683  +#define OP_Noop          160
        12684  +#define OP_Explain       161
 12500  12685   
 12501  12686   /* Properties such as "out2" or "jump" that are specified in
 12502  12687   ** comments following the "case" for each opcode in the vdbe.c
 12503  12688   ** are encoded into bitvectors as follows:
 12504  12689   */
 12505  12690   #define OPFLG_JUMP        0x01  /* jump:  P2 holds jmp target */
 12506  12691   #define OPFLG_IN1         0x02  /* in1:   P1 is an input */
................................................................................
 12509  12694   #define OPFLG_OUT2        0x10  /* out2:  P2 is an output */
 12510  12695   #define OPFLG_OUT3        0x20  /* out3:  P3 is an output */
 12511  12696   #define OPFLG_INITIALIZER {\
 12512  12697   /*   0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
 12513  12698   /*   8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
 12514  12699   /*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
 12515  12700   /*  24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
 12516         -/*  32 */ 0x09, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
        12701  +/*  32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
 12517  12702   /*  40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
 12518  12703   /*  48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
 12519         -/*  56 */ 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01,\
 12520         -/*  64 */ 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02, 0x02,\
 12521         -/*  72 */ 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10,\
 12522         -/*  80 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
 12523         -/*  88 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
 12524         -/*  96 */ 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
 12525         -/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
 12526         -/* 112 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 12527         -/* 120 */ 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
 12528         -/* 128 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
 12529         -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
 12530         -/* 144 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 12531         -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
 12532         -/* 160 */ 0x00,}
        12704  +/*  56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01,\
        12705  +/*  64 */ 0x01, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02,\
        12706  +/*  72 */ 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,\
        12707  +/*  80 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
        12708  +/*  88 */ 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00,\
        12709  +/*  96 */ 0x00, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
        12710  +/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
        12711  +/* 112 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
        12712  +/* 120 */ 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00,\
        12713  +/* 128 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\
        12714  +/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\
        12715  +/* 144 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
        12716  +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
        12717  +/* 160 */ 0x00, 0x00,}
 12533  12718   
 12534  12719   /* The sqlite3P2Values() routine is able to run faster if it knows
 12535  12720   ** the value of the largest JUMP opcode.  The smaller the maximum
 12536  12721   ** JUMP opcode the better, so the mkopcodeh.tcl script that
 12537  12722   ** generated this include file strives to group all JUMP opcodes
 12538  12723   ** together near the beginning of the list.
 12539  12724   */
 12540         -#define SQLITE_MX_JUMP_OPCODE  69  /* Maximum JUMP opcode */
        12725  +#define SQLITE_MX_JUMP_OPCODE  70  /* Maximum JUMP opcode */
 12541  12726   
 12542  12727   /************** End of opcodes.h *********************************************/
 12543  12728   /************** Continuing where we left off in vdbe.h ***********************/
 12544  12729   
 12545  12730   /*
 12546  12731   ** Prototypes for the VDBE interface.  See comments on the implementation
 12547  12732   ** for a description of what each of these routines does.
................................................................................
 12680  12865   
 12681  12866   #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
 12682  12867   SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
 12683  12868   #else
 12684  12869   # define sqlite3VdbeScanStatus(a,b,c,d,e)
 12685  12870   #endif
 12686  12871   
 12687         -#endif
        12872  +#endif /* SQLITE_VDBE_H */
 12688  12873   
 12689  12874   /************** End of vdbe.h ************************************************/
 12690  12875   /************** Continuing where we left off in sqliteInt.h ******************/
 12691  12876   /************** Include pager.h in the middle of sqliteInt.h *****************/
 12692  12877   /************** Begin file pager.h *******************************************/
 12693  12878   /*
 12694  12879   ** 2001 September 15
................................................................................
 12702  12887   **
 12703  12888   *************************************************************************
 12704  12889   ** This header file defines the interface that the sqlite page cache
 12705  12890   ** subsystem.  The page cache subsystem reads and writes a file a page
 12706  12891   ** at a time and provides a journal for rollback.
 12707  12892   */
 12708  12893   
 12709         -#ifndef _PAGER_H_
 12710         -#define _PAGER_H_
        12894  +#ifndef SQLITE_PAGER_H
        12895  +#define SQLITE_PAGER_H
 12711  12896   
 12712  12897   /*
 12713  12898   ** Default maximum size for persistent journal files. A negative 
 12714  12899   ** value means no limit. This value may be overridden using the 
 12715  12900   ** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
 12716  12901   */
 12717  12902   #ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
................................................................................
 12891  13076   SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*);
 12892  13077   SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
 12893  13078   SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*);
 12894  13079   SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
 12895  13080   SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
 12896  13081   SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
 12897  13082   SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
 12898         -SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *);
 12899  13083   SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
 12900  13084   
 12901  13085   /* Functions used to truncate the database file. */
 12902  13086   SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
 12903  13087   
 12904  13088   SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
 12905  13089   
................................................................................
 12918  13102     void disable_simulated_io_errors(void);
 12919  13103     void enable_simulated_io_errors(void);
 12920  13104   #else
 12921  13105   # define disable_simulated_io_errors()
 12922  13106   # define enable_simulated_io_errors()
 12923  13107   #endif
 12924  13108   
 12925         -#endif /* _PAGER_H_ */
        13109  +#endif /* SQLITE_PAGER_H */
 12926  13110   
 12927  13111   /************** End of pager.h ***********************************************/
 12928  13112   /************** Continuing where we left off in sqliteInt.h ******************/
 12929  13113   /************** Include pcache.h in the middle of sqliteInt.h ****************/
 12930  13114   /************** Begin file pcache.h ******************************************/
 12931  13115   /*
 12932  13116   ** 2008 August 05
................................................................................
 13156  13340   **    May you share freely, never taking more than you give.
 13157  13341   **
 13158  13342   ******************************************************************************
 13159  13343   **
 13160  13344   ** This file contains pre-processor directives related to operating system
 13161  13345   ** detection and/or setup.
 13162  13346   */
 13163         -#ifndef _OS_SETUP_H_
 13164         -#define _OS_SETUP_H_
        13347  +#ifndef SQLITE_OS_SETUP_H
        13348  +#define SQLITE_OS_SETUP_H
 13165  13349   
 13166  13350   /*
 13167  13351   ** Figure out if we are dealing with Unix, Windows, or some other operating
 13168  13352   ** system.
 13169  13353   **
 13170  13354   ** After the following block of preprocess macros, all of SQLITE_OS_UNIX,
 13171  13355   ** SQLITE_OS_WIN, and SQLITE_OS_OTHER will defined to either 1 or 0.  One of
................................................................................
 13197  13381   #  endif
 13198  13382   #else
 13199  13383   #  ifndef SQLITE_OS_WIN
 13200  13384   #    define SQLITE_OS_WIN 0
 13201  13385   #  endif
 13202  13386   #endif
 13203  13387   
 13204         -#endif /* _OS_SETUP_H_ */
        13388  +#endif /* SQLITE_OS_SETUP_H */
 13205  13389   
 13206  13390   /************** End of os_setup.h ********************************************/
 13207  13391   /************** Continuing where we left off in os.h *************************/
 13208  13392   
 13209  13393   /* If the SET_FULLSYNC macro is not defined above, then make it
 13210  13394   ** a no-op
 13211  13395   */
................................................................................
 13654  13838     typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
 13655  13839                                  const char*, const char*);
 13656  13840   #else
 13657  13841     typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*,
 13658  13842                                  const char*);
 13659  13843   #endif
 13660  13844   
        13845  +#ifndef SQLITE_OMIT_DEPRECATED
        13846  +/* This is an extra SQLITE_TRACE macro that indicates "legacy" tracing
        13847  +** in the style of sqlite3_trace()
        13848  +*/
        13849  +#define SQLITE_TRACE_LEGACY  0x80
        13850  +#else
        13851  +#define SQLITE_TRACE_LEGACY  0
        13852  +#endif /* SQLITE_OMIT_DEPRECATED */
        13853  +
 13661  13854   
 13662  13855   /*
 13663  13856   ** Each database connection is an instance of the following structure.
 13664  13857   */
 13665  13858   struct sqlite3 {
 13666  13859     sqlite3_vfs *pVfs;            /* OS Interface */
 13667  13860     struct Vdbe *pVdbe;           /* List of active virtual machines */
................................................................................
 13683  13876     u8 mallocFailed;              /* True if we have seen a malloc failure */
 13684  13877     u8 bBenignMalloc;             /* Do not require OOMs if true */
 13685  13878     u8 dfltLockMode;              /* Default locking-mode for attached dbs */
 13686  13879     signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */
 13687  13880     u8 suppressErr;               /* Do not issue error messages if true */
 13688  13881     u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
 13689  13882     u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
        13883  +  u8 mTrace;                    /* zero or more SQLITE_TRACE flags */
 13690  13884     int nextPagesize;             /* Pagesize after VACUUM if >0 */
 13691  13885     u32 magic;                    /* Magic number for detect library misuse */
 13692  13886     int nChange;                  /* Value returned by sqlite3_changes() */
 13693  13887     int nTotalChange;             /* Value returned by sqlite3_total_changes() */
 13694  13888     int aLimit[SQLITE_N_LIMIT];   /* Limits */
 13695  13889     int nMaxSorterMmap;           /* Maximum size of regions mapped by sorter */
 13696  13890     struct sqlite3InitInfo {      /* Information used during initialization */
................................................................................
 13703  13897     int nVdbeActive;              /* Number of VDBEs currently running */
 13704  13898     int nVdbeRead;                /* Number of active VDBEs that read or write */
 13705  13899     int nVdbeWrite;               /* Number of active VDBEs that read and write */
 13706  13900     int nVdbeExec;                /* Number of nested calls to VdbeExec() */
 13707  13901     int nVDestroy;                /* Number of active OP_VDestroy operations */
 13708  13902     int nExtension;               /* Number of loaded extensions */
 13709  13903     void **aExtension;            /* Array of shared library handles */
 13710         -  void (*xTrace)(void*,const char*);        /* Trace function */
        13904  +  int (*xTrace)(u32,void*,void*,void*);     /* Trace function */
 13711  13905     void *pTraceArg;                          /* Argument to the trace function */
 13712  13906     void (*xProfile)(void*,const char*,u64);  /* Profiling function */
 13713  13907     void *pProfileArg;                        /* Argument to profile function */
 13714  13908     void *pCommitArg;                 /* Argument to xCommitCallback() */
 13715  13909     int (*xCommitCallback)(void*);    /* Invoked at every commit. */
 13716  13910     void *pRollbackArg;               /* Argument to xRollbackCallback() */
 13717  13911     void (*xRollbackCallback)(void*); /* Invoked at every commit. */
................................................................................
 14898  15092       char *zAlias;     /* The "B" part of a "A AS B" phrase.  zName is the "A" */
 14899  15093       Table *pTab;      /* An SQL table corresponding to zName */
 14900  15094       Select *pSelect;  /* A SELECT statement used in place of a table name */
 14901  15095       int addrFillSub;  /* Address of subroutine to manifest a subquery */
 14902  15096       int regReturn;    /* Register holding return address of addrFillSub */
 14903  15097       int regResult;    /* Registers holding results of a co-routine */
 14904  15098       struct {
 14905         -      u8 jointype;      /* Type of join between this able and the previous */
        15099  +      u8 jointype;      /* Type of join between this table and the previous */
 14906  15100         unsigned notIndexed :1;    /* True if there is a NOT INDEXED clause */
 14907  15101         unsigned isIndexedBy :1;   /* True if there is an INDEXED BY clause */
 14908  15102         unsigned isTabFunc :1;     /* True if table-valued-function syntax */
 14909  15103         unsigned isCorrelated :1;  /* True if sub-query is correlated */
 14910  15104         unsigned viaCoroutine :1;  /* Implemented as a co-routine */
 14911  15105         unsigned isRecursive :1;   /* True for recursive reference in WITH */
 14912  15106       } fg;
................................................................................
 14944  15138   ** Value constraints (enforced via assert()):
 14945  15139   **     WHERE_USE_LIMIT  == SF_FixedLimit
 14946  15140   */
 14947  15141   #define WHERE_ORDERBY_NORMAL   0x0000 /* No-op */
 14948  15142   #define WHERE_ORDERBY_MIN      0x0001 /* ORDER BY processing for min() func */
 14949  15143   #define WHERE_ORDERBY_MAX      0x0002 /* ORDER BY processing for max() func */
 14950  15144   #define WHERE_ONEPASS_DESIRED  0x0004 /* Want to do one-pass UPDATE/DELETE */
 14951         -#define WHERE_DUPLICATES_OK    0x0008 /* Ok to return a row more than once */
 14952         -#define WHERE_OMIT_OPEN_CLOSE  0x0010 /* Table cursors are already open */
 14953         -#define WHERE_FORCE_TABLE      0x0020 /* Do not use an index-only search */
 14954         -#define WHERE_ONETABLE_ONLY    0x0040 /* Only code the 1st table in pTabList */
 14955         -#define WHERE_NO_AUTOINDEX     0x0080 /* Disallow automatic indexes */
 14956         -#define WHERE_GROUPBY          0x0100 /* pOrderBy is really a GROUP BY */
 14957         -#define WHERE_DISTINCTBY       0x0200 /* pOrderby is really a DISTINCT clause */
 14958         -#define WHERE_WANT_DISTINCT    0x0400 /* All output needs to be distinct */
 14959         -#define WHERE_SORTBYGROUP      0x0800 /* Support sqlite3WhereIsSorted() */
 14960         -#define WHERE_REOPEN_IDX       0x1000 /* Try to use OP_ReopenIdx */
 14961         -#define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */
 14962         -#define WHERE_USE_LIMIT        0x4000 /* There is a constant LIMIT clause */
 14963         -#define WHERE_SEEK_TABLE       0x8000 /* Do not defer seeks on main table */
        15145  +#define WHERE_ONEPASS_MULTIROW 0x0008 /* ONEPASS is ok with multiple rows */
        15146  +#define WHERE_DUPLICATES_OK    0x0010 /* Ok to return a row more than once */
        15147  +#define WHERE_OR_SUBCLAUSE     0x0020 /* Processing a sub-WHERE as part of
        15148  +                                      ** the OR optimization  */
        15149  +#define WHERE_GROUPBY          0x0040 /* pOrderBy is really a GROUP BY */
        15150  +#define WHERE_DISTINCTBY       0x0080 /* pOrderby is really a DISTINCT clause */
        15151  +#define WHERE_WANT_DISTINCT    0x0100 /* All output needs to be distinct */
        15152  +#define WHERE_SORTBYGROUP      0x0200 /* Support sqlite3WhereIsSorted() */
        15153  +#define WHERE_SEEK_TABLE       0x0400 /* Do not defer seeks on main table */
        15154  +#define WHERE_ORDERBY_LIMIT    0x0800 /* ORDERBY+LIMIT on the inner loop */
        15155  +                        /*     0x1000    not currently used */
        15156  +                        /*     0x2000    not currently used */
        15157  +#define WHERE_USE_LIMIT        0x4000 /* Use the LIMIT in cost estimates */
        15158  +                        /*     0x8000    not currently used */
 14964  15159   
 14965  15160   /* Allowed return values from sqlite3WhereIsDistinct()
 14966  15161   */
 14967  15162   #define WHERE_DISTINCT_NOOP      0  /* DISTINCT keyword not used */
 14968  15163   #define WHERE_DISTINCT_UNIQUE    1  /* No duplicates */
 14969  15164   #define WHERE_DISTINCT_ORDERED   2  /* All duplicates are adjacent */
 14970  15165   #define WHERE_DISTINCT_UNORDERED 3  /* Duplicates are scattered */
................................................................................
 15659  15854       NameContext *pNC;                          /* Naming context */
 15660  15855       int n;                                     /* A counter */
 15661  15856       int iCur;                                  /* A cursor number */
 15662  15857       SrcList *pSrcList;                         /* FROM clause */
 15663  15858       struct SrcCount *pSrcCount;                /* Counting column references */
 15664  15859       struct CCurHint *pCCurHint;                /* Used by codeCursorHint() */
 15665  15860       int *aiCol;                                /* array of column indexes */
        15861  +    struct IdxCover *pIdxCover;                /* Check for index coverage */
 15666  15862     } u;
 15667  15863   };
 15668  15864   
 15669  15865   /* Forward declarations */
 15670  15866   SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
 15671  15867   SQLITE_PRIVATE int sqlite3WalkExprList(Walker*, ExprList*);
 15672  15868   SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*);
................................................................................
 15842  16038   # define sqlite3StackFree(D,P)
 15843  16039   #else
 15844  16040   # define sqlite3StackAllocRaw(D,N)   sqlite3DbMallocRaw(D,N)
 15845  16041   # define sqlite3StackAllocZero(D,N)  sqlite3DbMallocZero(D,N)
 15846  16042   # define sqlite3StackFree(D,P)       sqlite3DbFree(D,P)
 15847  16043   #endif
 15848  16044   
 15849         -#ifdef SQLITE_ENABLE_MEMSYS3
 15850         -SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
 15851         -#endif
        16045  +/* Do not allow both MEMSYS5 and MEMSYS3 to be defined together.  If they
        16046  +** are, disable MEMSYS3
        16047  +*/
 15852  16048   #ifdef SQLITE_ENABLE_MEMSYS5
 15853  16049   SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
        16050  +#undef SQLITE_ENABLE_MEMSYS3
        16051  +#endif
        16052  +#ifdef SQLITE_ENABLE_MEMSYS3
        16053  +SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
 15854  16054   #endif
 15855  16055   
 15856  16056   
 15857  16057   #ifndef SQLITE_MUTEX_OMIT
 15858  16058   SQLITE_PRIVATE   sqlite3_mutex_methods const *sqlite3DefaultMutex(void);
 15859  16059   SQLITE_PRIVATE   sqlite3_mutex_methods const *sqlite3NoopMutex(void);
 15860  16060   SQLITE_PRIVATE   sqlite3_mutex *sqlite3MutexAlloc(int);
................................................................................
 16029  16229   SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*);
 16030  16230   SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
 16031  16231   SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
 16032  16232   SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
 16033  16233   SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
 16034  16234   SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
 16035  16235   SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
 16036         -SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
 16037         -                          Expr*, int, int);
        16236  +SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
        16237  +                          Expr*, int, int, u8);
 16038  16238   SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
 16039  16239   SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
 16040  16240   SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
 16041  16241                            Expr*,ExprList*,u32,Expr*,Expr*);
 16042  16242   SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
 16043  16243   SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
 16044  16244   SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
................................................................................
 16049  16249   SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
 16050  16250   SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
 16051  16251   SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
 16052  16252   SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
 16053  16253   SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
 16054  16254   SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
 16055  16255   SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
        16256  +SQLITE_PRIVATE int sqlite3WhereOrderedInnerLoop(WhereInfo*);
 16056  16257   SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
 16057  16258   SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
 16058  16259   SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
 16059  16260   SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
 16060  16261   #define ONEPASS_OFF      0        /* Use of ONEPASS not allowed */
 16061  16262   #define ONEPASS_SINGLE   1        /* ONEPASS valid for a single row update */
 16062  16263   #define ONEPASS_MULTI    2        /* ONEPASS is valid for multiple rows */
................................................................................
 16082  16283   #define SQLITE_ECEL_DUP      0x01  /* Deep, not shallow copies */
 16083  16284   #define SQLITE_ECEL_FACTOR   0x02  /* Factor out constant terms */
 16084  16285   #define SQLITE_ECEL_REF      0x04  /* Use ExprList.u.x.iOrderByCol */
 16085  16286   SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
 16086  16287   SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
 16087  16288   SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
 16088  16289   SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
 16089         -SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
 16090         -SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
        16290  +#define LOCATE_VIEW    0x01
        16291  +#define LOCATE_NOERR   0x02
        16292  +SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
        16293  +SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
 16091  16294   SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
 16092  16295   SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
 16093  16296   SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
 16094  16297   SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
 16095  16298   SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
 16096  16299   SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
 16097  16300   SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
 16098  16301   SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
 16099  16302   SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
 16100  16303   SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
 16101  16304   SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
        16305  +SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
 16102  16306   SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
 16103  16307   SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
 16104  16308   #ifndef SQLITE_OMIT_BUILTIN_TEST
 16105  16309   SQLITE_PRIVATE void sqlite3PrngSaveState(void);
 16106  16310   SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
 16107  16311   #endif
 16108  16312   SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
................................................................................
 16646  16850   SQLITE_PRIVATE int sqlite3ThreadJoin(SQLiteThread*, void**);
 16647  16851   #endif
 16648  16852   
 16649  16853   #if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)
 16650  16854   SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*);
 16651  16855   #endif
 16652  16856   
 16653         -#endif /* _SQLITEINT_H_ */
        16857  +#endif /* SQLITEINT_H */
 16654  16858   
 16655  16859   /************** End of sqliteInt.h *******************************************/
 16656  16860   /************** Begin file global.c ******************************************/
 16657  16861   /*
 16658  16862   ** 2008 June 13
 16659  16863   **
 16660  16864   ** The author disclaims copyright to this source code.  In place of
................................................................................
 16981  17185   #endif
 16982  17186   #if SQLITE_CASE_SENSITIVE_LIKE
 16983  17187     "CASE_SENSITIVE_LIKE",
 16984  17188   #endif
 16985  17189   #if SQLITE_CHECK_PAGES
 16986  17190     "CHECK_PAGES",
 16987  17191   #endif
        17192  +#if defined(__clang__) && defined(__clang_major__)
        17193  +  "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "."
        17194  +                    CTIMEOPT_VAL(__clang_minor__) "."
        17195  +                    CTIMEOPT_VAL(__clang_patchlevel__),
        17196  +#elif defined(_MSC_VER)
        17197  +  "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER),
        17198  +#elif defined(__GNUC__) && defined(__VERSION__)
        17199  +  "COMPILER=gcc-" __VERSION__,
        17200  +#endif
 16988  17201   #if SQLITE_COVERAGE_TEST
 16989  17202     "COVERAGE_TEST",
 16990  17203   #endif
 16991  17204   #if SQLITE_DEBUG
 16992  17205     "DEBUG",
 16993  17206   #endif
 16994  17207   #if SQLITE_DEFAULT_LOCKING_MODE
................................................................................
 17000  17213   #if SQLITE_DISABLE_DIRSYNC
 17001  17214     "DISABLE_DIRSYNC",
 17002  17215   #endif
 17003  17216   #if SQLITE_DISABLE_LFS
 17004  17217     "DISABLE_LFS",
 17005  17218   #endif
 17006  17219   #if SQLITE_ENABLE_8_3_NAMES
 17007         -  "ENABLE_8_3_NAMES",
        17220  +  "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
 17008  17221   #endif
 17009  17222   #if SQLITE_ENABLE_API_ARMOR
 17010  17223     "ENABLE_API_ARMOR",
 17011  17224   #endif
 17012  17225   #if SQLITE_ENABLE_ATOMIC_WRITE
 17013  17226     "ENABLE_ATOMIC_WRITE",
 17014  17227   #endif
................................................................................
 17340  17553   /*
 17341  17554   ** Given the name of a compile-time option, return true if that option
 17342  17555   ** was used and false if not.
 17343  17556   **
 17344  17557   ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
 17345  17558   ** is not required for a match.
 17346  17559   */
 17347         -SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName){
        17560  +SQLITE_API int SQLITE_APICALL sqlite3_compileoption_used(const char *zOptName){
 17348  17561     int i, n;
 17349  17562   
 17350  17563   #if SQLITE_ENABLE_API_ARMOR
 17351  17564     if( zOptName==0 ){
 17352  17565       (void)SQLITE_MISUSE_BKPT;
 17353  17566       return 0;
 17354  17567     }
................................................................................
 17368  17581     return 0;
 17369  17582   }
 17370  17583   
 17371  17584   /*
 17372  17585   ** Return the N-th compile-time option string.  If N is out of range,
 17373  17586   ** return a NULL pointer.
 17374  17587   */
 17375         -SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N){
        17588  +SQLITE_API const char *SQLITE_APICALL sqlite3_compileoption_get(int N){
 17376  17589     if( N>=0 && N<ArraySize(azCompileOpt) ){
 17377  17590       return azCompileOpt[N];
 17378  17591     }
 17379  17592     return 0;
 17380  17593   }
 17381  17594   
 17382  17595   #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
................................................................................
 17414  17627   *************************************************************************
 17415  17628   ** This is the header file for information that is private to the
 17416  17629   ** VDBE.  This information used to all be at the top of the single
 17417  17630   ** source code file "vdbe.c".  When that file became too big (over
 17418  17631   ** 6000 lines long) it was split up into several smaller files and
 17419  17632   ** this header information was factored out.
 17420  17633   */
 17421         -#ifndef _VDBEINT_H_
 17422         -#define _VDBEINT_H_
        17634  +#ifndef SQLITE_VDBEINT_H
        17635  +#define SQLITE_VDBEINT_H
 17423  17636   
 17424  17637   /*
 17425  17638   ** The maximum number of times that a statement will try to reparse
 17426  17639   ** itself before giving up and returning SQLITE_SCHEMA.
 17427  17640   */
 17428  17641   #ifndef SQLITE_MAX_SCHEMA_RETRY
 17429  17642   # define SQLITE_MAX_SCHEMA_RETRY 50
................................................................................
 17957  18170   SQLITE_PRIVATE   int sqlite3VdbeMemExpandBlob(Mem *);
 17958  18171     #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
 17959  18172   #else
 17960  18173     #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
 17961  18174     #define ExpandBlob(P) SQLITE_OK
 17962  18175   #endif
 17963  18176   
 17964         -#endif /* !defined(_VDBEINT_H_) */
        18177  +#endif /* !defined(SQLITE_VDBEINT_H) */
 17965  18178   
 17966  18179   /************** End of vdbeInt.h *********************************************/
 17967  18180   /************** Continuing where we left off in status.c *********************/
 17968  18181   
 17969  18182   /*
 17970  18183   ** Variables in which to record status information.
 17971  18184   */
................................................................................
 18078  18291       wsdStat.mxValue[op] = newValue;
 18079  18292     }
 18080  18293   }
 18081  18294   
 18082  18295   /*
 18083  18296   ** Query status information.
 18084  18297   */
 18085         -SQLITE_API int SQLITE_STDCALL sqlite3_status64(
        18298  +SQLITE_API int SQLITE_APICALL sqlite3_status64(
 18086  18299     int op,
 18087  18300     sqlite3_int64 *pCurrent,
 18088  18301     sqlite3_int64 *pHighwater,
 18089  18302     int resetFlag
 18090  18303   ){
 18091  18304     sqlite3_mutex *pMutex;
 18092  18305     wsdStatInit;
................................................................................
 18103  18316     if( resetFlag ){
 18104  18317       wsdStat.mxValue[op] = wsdStat.nowValue[op];
 18105  18318     }
 18106  18319     sqlite3_mutex_leave(pMutex);
 18107  18320     (void)pMutex;  /* Prevent warning when SQLITE_THREADSAFE=0 */
 18108  18321     return SQLITE_OK;
 18109  18322   }
 18110         -SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
        18323  +SQLITE_API int SQLITE_APICALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
 18111  18324     sqlite3_int64 iCur, iHwtr;
 18112  18325     int rc;
 18113  18326   #ifdef SQLITE_ENABLE_API_ARMOR
 18114  18327     if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
 18115  18328   #endif
 18116  18329     rc = sqlite3_status64(op, &iCur, &iHwtr, resetFlag);
 18117  18330     if( rc==0 ){
................................................................................
 18120  18333     }
 18121  18334     return rc;
 18122  18335   }
 18123  18336   
 18124  18337   /*
 18125  18338   ** Query status information for a single database connection
 18126  18339   */
 18127         -SQLITE_API int SQLITE_STDCALL sqlite3_db_status(
        18340  +SQLITE_API int SQLITE_APICALL sqlite3_db_status(
 18128  18341     sqlite3 *db,          /* The database connection whose status is desired */
 18129  18342     int op,               /* Status verb */
 18130  18343     int *pCurrent,        /* Write current value here */
 18131  18344     int *pHighwater,      /* Write high-water mark here */
 18132  18345     int resetFlag         /* Reset high-water mark if true */
 18133  18346   ){
 18134  18347     int rc = SQLITE_OK;   /* Return code */
................................................................................
 18165  18378       }
 18166  18379   
 18167  18380       /* 
 18168  18381       ** Return an approximation for the amount of memory currently used
 18169  18382       ** by all pagers associated with the given database connection.  The
 18170  18383       ** highwater mark is meaningless and is returned as zero.
 18171  18384       */
        18385  +    case SQLITE_DBSTATUS_CACHE_USED_SHARED:
 18172  18386       case SQLITE_DBSTATUS_CACHE_USED: {
 18173  18387         int totalUsed = 0;
 18174  18388         int i;
 18175  18389         sqlite3BtreeEnterAll(db);
 18176  18390         for(i=0; i<db->nDb; i++){
 18177  18391           Btree *pBt = db->aDb[i].pBt;
 18178  18392           if( pBt ){
 18179  18393             Pager *pPager = sqlite3BtreePager(pBt);
 18180         -          totalUsed += sqlite3PagerMemUsed(pPager);
        18394  +          int nByte = sqlite3PagerMemUsed(pPager);
        18395  +          if( op==SQLITE_DBSTATUS_CACHE_USED_SHARED ){
        18396  +            nByte = nByte / sqlite3BtreeConnectionCount(pBt);
        18397  +          }
        18398  +          totalUsed += nByte;
 18181  18399           }
 18182  18400         }
 18183  18401         sqlite3BtreeLeaveAll(db);
 18184  18402         *pCurrent = totalUsed;
 18185  18403         *pHighwater = 0;
 18186  18404         break;
 18187  18405       }
................................................................................
 19476  19694   **    May you share freely, never taking more than you give.
 19477  19695   **
 19478  19696   ******************************************************************************
 19479  19697   **
 19480  19698   ** This file contains OS interface code that is common to all
 19481  19699   ** architectures.
 19482  19700   */
 19483         -#define _SQLITE_OS_C_ 1
 19484  19701   /* #include "sqliteInt.h" */
 19485         -#undef _SQLITE_OS_C_
 19486  19702   
 19487  19703   /*
 19488  19704   ** If we compile with the SQLITE_TEST macro set, then the following block
 19489  19705   ** of code will give us the ability to simulate a disk I/O error.  This
 19490  19706   ** is used for testing the I/O recovery logic.
 19491  19707   */
 19492  19708   #if defined(SQLITE_TEST)
................................................................................
 19795  20011   static sqlite3_vfs * SQLITE_WSD vfsList = 0;
 19796  20012   #define vfsList GLOBAL(sqlite3_vfs *, vfsList)
 19797  20013   
 19798  20014   /*
 19799  20015   ** Locate a VFS by name.  If no name is given, simply return the
 19800  20016   ** first VFS on the list.
 19801  20017   */
 19802         -SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfs){
        20018  +SQLITE_API sqlite3_vfs *SQLITE_APICALL sqlite3_vfs_find(const char *zVfs){
 19803  20019     sqlite3_vfs *pVfs = 0;
 19804  20020   #if SQLITE_THREADSAFE
 19805  20021     sqlite3_mutex *mutex;
 19806  20022   #endif
 19807  20023   #ifndef SQLITE_OMIT_AUTOINIT
 19808  20024     int rc = sqlite3_initialize();
 19809  20025     if( rc ) return 0;
................................................................................
 19841  20057   }
 19842  20058   
 19843  20059   /*
 19844  20060   ** Register a VFS with the system.  It is harmless to register the same
 19845  20061   ** VFS multiple times.  The new VFS becomes the default if makeDflt is
 19846  20062   ** true.
 19847  20063   */
 19848         -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
        20064  +SQLITE_API int SQLITE_APICALL sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
 19849  20065     MUTEX_LOGIC(sqlite3_mutex *mutex;)
 19850  20066   #ifndef SQLITE_OMIT_AUTOINIT
 19851  20067     int rc = sqlite3_initialize();
 19852  20068     if( rc ) return rc;
 19853  20069   #endif
 19854  20070   #ifdef SQLITE_ENABLE_API_ARMOR
 19855  20071     if( pVfs==0 ) return SQLITE_MISUSE_BKPT;
................................................................................
 19869  20085     sqlite3_mutex_leave(mutex);
 19870  20086     return SQLITE_OK;
 19871  20087   }
 19872  20088   
 19873  20089   /*
 19874  20090   ** Unregister a VFS so that it is no longer accessible.
 19875  20091   */
 19876         -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
        20092  +SQLITE_API int SQLITE_APICALL sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
 19877  20093   #if SQLITE_THREADSAFE
 19878  20094     sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 19879  20095   #endif
 19880  20096     sqlite3_mutex_enter(mutex);
 19881  20097     vfsUnlink(pVfs);
 19882  20098     sqlite3_mutex_leave(mutex);
 19883  20099     return SQLITE_OK;
................................................................................
 22220  22436   
 22221  22437     return rc;
 22222  22438   }
 22223  22439   
 22224  22440   /*
 22225  22441   ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
 22226  22442   */
 22227         -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int id){
        22443  +SQLITE_API sqlite3_mutex *SQLITE_APICALL sqlite3_mutex_alloc(int id){
 22228  22444   #ifndef SQLITE_OMIT_AUTOINIT
 22229  22445     if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
 22230  22446     if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
 22231  22447   #endif
 22232  22448     assert( sqlite3GlobalConfig.mutex.xMutexAlloc );
 22233  22449     return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
 22234  22450   }
................................................................................
 22241  22457     assert( sqlite3GlobalConfig.mutex.xMutexAlloc );
 22242  22458     return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
 22243  22459   }
 22244  22460   
 22245  22461   /*
 22246  22462   ** Free a dynamic mutex.
 22247  22463   */
 22248         -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex *p){
        22464  +SQLITE_API void SQLITE_APICALL sqlite3_mutex_free(sqlite3_mutex *p){
 22249  22465     if( p ){
 22250  22466       assert( sqlite3GlobalConfig.mutex.xMutexFree );
 22251  22467       sqlite3GlobalConfig.mutex.xMutexFree(p);
 22252  22468     }
 22253  22469   }
 22254  22470   
 22255  22471   /*
 22256  22472   ** Obtain the mutex p. If some other thread already has the mutex, block
 22257  22473   ** until it can be obtained.
 22258  22474   */
 22259         -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex *p){
        22475  +SQLITE_API void SQLITE_APICALL sqlite3_mutex_enter(sqlite3_mutex *p){
 22260  22476     if( p ){
 22261  22477       assert( sqlite3GlobalConfig.mutex.xMutexEnter );
 22262  22478       sqlite3GlobalConfig.mutex.xMutexEnter(p);
 22263  22479     }
 22264  22480   }
 22265  22481   
 22266  22482   /*
 22267  22483   ** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another
 22268  22484   ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY.
 22269  22485   */
 22270         -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex *p){
        22486  +SQLITE_API int SQLITE_APICALL sqlite3_mutex_try(sqlite3_mutex *p){
 22271  22487     int rc = SQLITE_OK;
 22272  22488     if( p ){
 22273  22489       assert( sqlite3GlobalConfig.mutex.xMutexTry );
 22274  22490       return sqlite3GlobalConfig.mutex.xMutexTry(p);
 22275  22491     }
 22276  22492     return rc;
 22277  22493   }
................................................................................
 22278  22494   
 22279  22495   /*
 22280  22496   ** The sqlite3_mutex_leave() routine exits a mutex that was previously
 22281  22497   ** entered by the same thread.  The behavior is undefined if the mutex 
 22282  22498   ** is not currently entered. If a NULL pointer is passed as an argument
 22283  22499   ** this function is a no-op.
 22284  22500   */
 22285         -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex *p){
        22501  +SQLITE_API void SQLITE_APICALL sqlite3_mutex_leave(sqlite3_mutex *p){
 22286  22502     if( p ){
 22287  22503       assert( sqlite3GlobalConfig.mutex.xMutexLeave );
 22288  22504       sqlite3GlobalConfig.mutex.xMutexLeave(p);
 22289  22505     }
 22290  22506   }
 22291  22507   
 22292  22508   #ifndef NDEBUG
 22293  22509   /*
 22294  22510   ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
 22295  22511   ** intended for use inside assert() statements.
 22296  22512   */
 22297         -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex *p){
        22513  +SQLITE_API int SQLITE_APICALL sqlite3_mutex_held(sqlite3_mutex *p){
 22298  22514     assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld );
 22299  22515     return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p);
 22300  22516   }
 22301         -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex *p){
        22517  +SQLITE_API int SQLITE_APICALL sqlite3_mutex_notheld(sqlite3_mutex *p){
 22302  22518     assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld );
 22303  22519     return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
 22304  22520   }
 22305  22521   #endif
 22306  22522   
 22307  22523   #endif /* !defined(SQLITE_MUTEX_OMIT) */
 22308  22524   
................................................................................
 22991  23207   **    May you share freely, never taking more than you give.
 22992  23208   **
 22993  23209   ******************************************************************************
 22994  23210   **
 22995  23211   ** This file contains inline asm code for retrieving "high-performance"
 22996  23212   ** counters for x86 class CPUs.
 22997  23213   */
 22998         -#ifndef _HWTIME_H_
 22999         -#define _HWTIME_H_
        23214  +#ifndef SQLITE_HWTIME_H
        23215  +#define SQLITE_HWTIME_H
 23000  23216   
 23001  23217   /*
 23002  23218   ** The following routine only works on pentium-class (or newer) processors.
 23003  23219   ** It uses the RDTSC opcode to read the cycle count value out of the
 23004  23220   ** processor and returns that value.  This can be used for high-res
 23005  23221   ** profiling.
 23006  23222   */
................................................................................
 23060  23276     ** of the debugging and testing utilities, but it should at
 23061  23277     ** least compile and run.
 23062  23278     */
 23063  23279   SQLITE_PRIVATE   sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
 23064  23280   
 23065  23281   #endif
 23066  23282   
 23067         -#endif /* !defined(_HWTIME_H_) */
        23283  +#endif /* !defined(SQLITE_HWTIME_H) */
 23068  23284   
 23069  23285   /************** End of hwtime.h **********************************************/
 23070  23286   /************** Continuing where we left off in os_common.h ******************/
 23071  23287   
 23072  23288   static sqlite_uint64 g_start;
 23073  23289   static sqlite_uint64 g_elapsed;
 23074  23290   #define TIMER_START       g_start=sqlite3Hwtime()
................................................................................
 23150  23366   **    May you find forgiveness for yourself and forgive others.
 23151  23367   **    May you share freely, never taking more than you give.
 23152  23368   **
 23153  23369   ******************************************************************************
 23154  23370   **
 23155  23371   ** This file contains code that is specific to Windows.
 23156  23372   */
 23157         -#ifndef _OS_WIN_H_
 23158         -#define _OS_WIN_H_
        23373  +#ifndef SQLITE_OS_WIN_H
        23374  +#define SQLITE_OS_WIN_H
 23159  23375   
 23160  23376   /*
 23161  23377   ** Include the primary Windows SDK header file.
 23162  23378   */
 23163  23379   #include "windows.h"
 23164  23380   
 23165  23381   #ifdef __CYGWIN__
................................................................................
 23223  23439   #if SQLITE_OS_WIN && !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
 23224  23440       SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
 23225  23441   # define SQLITE_OS_WIN_THREADS 1
 23226  23442   #else
 23227  23443   # define SQLITE_OS_WIN_THREADS 0
 23228  23444   #endif
 23229  23445   
 23230         -#endif /* _OS_WIN_H_ */
        23446  +#endif /* SQLITE_OS_WIN_H */
 23231  23447   
 23232  23448   /************** End of os_win.h **********************************************/
 23233  23449   /************** Continuing where we left off in mutex_w32.c ******************/
 23234  23450   #endif
 23235  23451   
 23236  23452   /*
 23237  23453   ** The code in this file is only used if we are compiling multithreaded
................................................................................
 23326  23542   
 23327  23543   /* As the winMutexInit() and winMutexEnd() functions are called as part
 23328  23544   ** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
 23329  23545   ** "interlocked" magic used here is probably not strictly necessary.
 23330  23546   */
 23331  23547   static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
 23332  23548   
 23333         -SQLITE_API int SQLITE_STDCALL sqlite3_win32_is_nt(void); /* os_win.c */
 23334         -SQLITE_API void SQLITE_STDCALL sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
        23549  +SQLITE_API int SQLITE_APICALL sqlite3_win32_is_nt(void); /* os_win.c */
        23550  +SQLITE_API void SQLITE_APICALL sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
 23335  23551   
 23336  23552   static int winMutexInit(void){
 23337  23553     /* The first to increment to 1 does actual initialization */
 23338  23554     if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
 23339  23555       int i;
 23340  23556       for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
 23341  23557   #if SQLITE_OS_WINRT
................................................................................
 23627  23843   /* #include <stdarg.h> */
 23628  23844   
 23629  23845   /*
 23630  23846   ** Attempt to release up to n bytes of non-essential memory currently
 23631  23847   ** held by SQLite. An example of non-essential memory is memory used to
 23632  23848   ** cache database pages that are not currently in use.
 23633  23849   */
 23634         -SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int n){
        23850  +SQLITE_API int SQLITE_APICALL sqlite3_release_memory(int n){
 23635  23851   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
 23636  23852     return sqlite3PcacheReleaseMemory(n);
 23637  23853   #else
 23638  23854     /* IMPLEMENTATION-OF: R-34391-24921 The sqlite3_release_memory() routine
 23639  23855     ** is a no-op returning zero if SQLite is not compiled with
 23640  23856     ** SQLITE_ENABLE_MEMORY_MANAGEMENT. */
 23641  23857     UNUSED_PARAMETER(n);
................................................................................
 23686  23902   
 23687  23903   #ifndef SQLITE_OMIT_DEPRECATED
 23688  23904   /*
 23689  23905   ** Deprecated external interface.  It used to set an alarm callback
 23690  23906   ** that was invoked when memory usage grew too large.  Now it is a
 23691  23907   ** no-op.
 23692  23908   */
 23693         -SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm(
        23909  +SQLITE_API int SQLITE_APICALL sqlite3_memory_alarm(
 23694  23910     void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
 23695  23911     void *pArg,
 23696  23912     sqlite3_int64 iThreshold
 23697  23913   ){
 23698  23914     (void)xCallback;
 23699  23915     (void)pArg;
 23700  23916     (void)iThreshold;
................................................................................
 23702  23918   }
 23703  23919   #endif
 23704  23920   
 23705  23921   /*
 23706  23922   ** Set the soft heap-size limit for the library. Passing a zero or 
 23707  23923   ** negative value indicates no limit.
 23708  23924   */
 23709         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
        23925  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
 23710  23926     sqlite3_int64 priorLimit;
 23711  23927     sqlite3_int64 excess;
 23712  23928     sqlite3_int64 nUsed;
 23713  23929   #ifndef SQLITE_OMIT_AUTOINIT
 23714  23930     int rc = sqlite3_initialize();
 23715  23931     if( rc ) return -1;
 23716  23932   #endif
................................................................................
 23724  23940     nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
 23725  23941     mem0.nearlyFull = (n>0 && n<=nUsed);
 23726  23942     sqlite3_mutex_leave(mem0.mutex);
 23727  23943     excess = sqlite3_memory_used() - n;
 23728  23944     if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
 23729  23945     return priorLimit;
 23730  23946   }
 23731         -SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){
        23947  +SQLITE_API void SQLITE_APICALL sqlite3_soft_heap_limit(int n){
 23732  23948     if( n<0 ) n = 0;
 23733  23949     sqlite3_soft_heap_limit64(n);
 23734  23950   }
 23735  23951   
 23736  23952   /*
 23737  23953   ** Initialize the memory allocation subsystem.
 23738  23954   */
................................................................................
 23793  24009     }
 23794  24010     memset(&mem0, 0, sizeof(mem0));
 23795  24011   }
 23796  24012   
 23797  24013   /*
 23798  24014   ** Return the amount of memory currently checked out.
 23799  24015   */
 23800         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void){
        24016  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_memory_used(void){
 23801  24017     sqlite3_int64 res, mx;
 23802  24018     sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, 0);
 23803  24019     return res;
 23804  24020   }
 23805  24021   
 23806  24022   /*
 23807  24023   ** Return the maximum amount of memory that has ever been
 23808  24024   ** checked out since either the beginning of this process
 23809  24025   ** or since the most recent reset.
 23810  24026   */
 23811         -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag){
        24027  +SQLITE_API sqlite3_int64 SQLITE_APICALL sqlite3_memory_highwater(int resetFlag){
 23812  24028     sqlite3_int64 res, mx;
 23813  24029     sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, resetFlag);
 23814  24030     return mx;
 23815  24031   }
 23816  24032   
 23817  24033   /*
 23818  24034   ** Trigger the alarm 
................................................................................
 23884  24100   }
 23885  24101   
 23886  24102   /*
 23887  24103   ** This version of the memory allocation is for use by the application.
 23888  24104   ** First make sure the memory subsystem is initialized, then do the
 23889  24105   ** allocation.
 23890  24106   */
 23891         -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int n){
        24107  +SQLITE_API void *SQLITE_APICALL sqlite3_malloc(int n){
 23892  24108   #ifndef SQLITE_OMIT_AUTOINIT
 23893  24109     if( sqlite3_initialize() ) return 0;
 23894  24110   #endif
 23895  24111     return n<=0 ? 0 : sqlite3Malloc(n);
 23896  24112   }
 23897         -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64 n){
        24113  +SQLITE_API void *SQLITE_APICALL sqlite3_malloc64(sqlite3_uint64 n){
 23898  24114   #ifndef SQLITE_OMIT_AUTOINIT
 23899  24115     if( sqlite3_initialize() ) return 0;
 23900  24116   #endif
 23901  24117     return sqlite3Malloc(n);
 23902  24118   }
 23903  24119   
 23904  24120   /*
................................................................................
 24033  24249   #endif
 24034  24250       return sqlite3GlobalConfig.m.xSize(p);
 24035  24251     }else{
 24036  24252       assert( sqlite3_mutex_held(db->mutex) );
 24037  24253       return db->lookaside.sz;
 24038  24254     }
 24039  24255   }
 24040         -SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){
        24256  +SQLITE_API sqlite3_uint64 SQLITE_APICALL sqlite3_msize(void *p){
 24041  24257     assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 24042  24258     assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 24043  24259     return p ? sqlite3GlobalConfig.m.xSize(p) : 0;
 24044  24260   }
 24045  24261   
 24046  24262   /*
 24047  24263   ** Free memory previously obtained from sqlite3Malloc().
 24048  24264   */
 24049         -SQLITE_API void SQLITE_STDCALL sqlite3_free(void *p){
        24265  +SQLITE_API void SQLITE_APICALL sqlite3_free(void *p){
 24050  24266     if( p==0 ) return;  /* IMP: R-49053-54554 */
 24051  24267     assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 24052  24268     assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 24053  24269     if( sqlite3GlobalConfig.bMemstat ){
 24054  24270       sqlite3_mutex_enter(mem0.mutex);
 24055  24271       sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, sqlite3MallocSize(p));
 24056  24272       sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1);
................................................................................
 24151  24367     return pNew;
 24152  24368   }
 24153  24369   
 24154  24370   /*
 24155  24371   ** The public interface to sqlite3Realloc.  Make sure that the memory
 24156  24372   ** subsystem is initialized prior to invoking sqliteRealloc.
 24157  24373   */
 24158         -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void *pOld, int n){
        24374  +SQLITE_API void *SQLITE_APICALL sqlite3_realloc(void *pOld, int n){
 24159  24375   #ifndef SQLITE_OMIT_AUTOINIT
 24160  24376     if( sqlite3_initialize() ) return 0;
 24161  24377   #endif
 24162  24378     if( n<0 ) n = 0;  /* IMP: R-26507-47431 */
 24163  24379     return sqlite3Realloc(pOld, n);
 24164  24380   }
 24165         -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
        24381  +SQLITE_API void *SQLITE_APICALL sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
 24166  24382   #ifndef SQLITE_OMIT_AUTOINIT
 24167  24383     if( sqlite3_initialize() ) return 0;
 24168  24384   #endif
 24169  24385     return sqlite3Realloc(pOld, n);
 24170  24386   }
 24171  24387   
 24172  24388   
................................................................................
 25385  25601     return z;
 25386  25602   }
 25387  25603   
 25388  25604   /*
 25389  25605   ** Print into memory obtained from sqlite3_malloc().  Omit the internal
 25390  25606   ** %-conversion extensions.
 25391  25607   */
 25392         -SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char *zFormat, va_list ap){
        25608  +SQLITE_API char *SQLITE_APICALL sqlite3_vmprintf(const char *zFormat, va_list ap){
 25393  25609     char *z;
 25394  25610     char zBase[SQLITE_PRINT_BUF_SIZE];
 25395  25611     StrAccum acc;
 25396  25612   
 25397  25613   #ifdef SQLITE_ENABLE_API_ARMOR  
 25398  25614     if( zFormat==0 ){
 25399  25615       (void)SQLITE_MISUSE_BKPT;
................................................................................
 25434  25650   ** Oops:  The first two arguments of sqlite3_snprintf() are backwards
 25435  25651   ** from the snprintf() standard.  Unfortunately, it is too late to change
 25436  25652   ** this without breaking compatibility, so we just have to live with the
 25437  25653   ** mistake.
 25438  25654   **
 25439  25655   ** sqlite3_vsnprintf() is the varargs version.
 25440  25656   */
 25441         -SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
        25657  +SQLITE_API char *SQLITE_APICALL sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
 25442  25658     StrAccum acc;
 25443  25659     if( n<=0 ) return zBuf;
 25444  25660   #ifdef SQLITE_ENABLE_API_ARMOR
 25445  25661     if( zBuf==0 || zFormat==0 ) {
 25446  25662       (void)SQLITE_MISUSE_BKPT;
 25447  25663       if( zBuf ) zBuf[0] = 0;
 25448  25664       return zBuf;
................................................................................
 25974  26190           case OE_Fail:       zType = "fail";      break;
 25975  26191           case OE_Ignore:     zType = "ignore";    break;
 25976  26192         }
 25977  26193         sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
 25978  26194         break;
 25979  26195       }
 25980  26196   #endif
        26197  +    case TK_MATCH: {
        26198  +      sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s",
        26199  +                          pExpr->iTable, pExpr->iColumn, zFlgs);
        26200  +      sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
        26201  +      break;
        26202  +    }
 25981  26203       default: {
 25982  26204         sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
 25983  26205         break;
 25984  26206       }
 25985  26207     }
 25986  26208     if( zBinOp ){
 25987  26209       sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs);
................................................................................
 26055  26277     unsigned char i, j;            /* State variables */
 26056  26278     unsigned char s[256];          /* State variables */
 26057  26279   } sqlite3Prng;
 26058  26280   
 26059  26281   /*
 26060  26282   ** Return N random bytes.
 26061  26283   */
 26062         -SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *pBuf){
        26284  +SQLITE_API void SQLITE_APICALL sqlite3_randomness(int N, void *pBuf){
 26063  26285     unsigned char t;
 26064  26286     unsigned char *zBuf = pBuf;
 26065  26287   
 26066  26288     /* The "wsdPrng" macro will resolve to the pseudo-random number generator
 26067  26289     ** state vector.  If writable static data is unsupported on the target,
 26068  26290     ** we have to locate the state vector at run-time.  In the more common
 26069  26291     ** case where writable static data is supported, wsdPrng can refer directly
................................................................................
 27258  27480   **
 27259  27481   ** IMPLEMENTATION-OF: R-30243-02494 The sqlite3_stricmp() and
 27260  27482   ** sqlite3_strnicmp() APIs allow applications and extensions to compare
 27261  27483   ** the contents of two buffers containing UTF-8 strings in a
 27262  27484   ** case-independent fashion, using the same definition of "case
 27263  27485   ** independence" that SQLite uses internally when comparing identifiers.
 27264  27486   */
 27265         -SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *zLeft, const char *zRight){
        27487  +SQLITE_API int SQLITE_APICALL sqlite3_stricmp(const char *zLeft, const char *zRight){
 27266  27488     if( zLeft==0 ){
 27267  27489       return zRight ? -1 : 0;
 27268  27490     }else if( zRight==0 ){
 27269  27491       return 1;
 27270  27492     }
 27271  27493     return sqlite3StrICmp(zLeft, zRight);
 27272  27494   }
................................................................................
 27279  27501       c = (int)UpperToLower[*a] - (int)UpperToLower[*b];
 27280  27502       if( c || *a==0 ) break;
 27281  27503       a++;
 27282  27504       b++;
 27283  27505     }
 27284  27506     return c;
 27285  27507   }
 27286         -SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
        27508  +SQLITE_API int SQLITE_APICALL sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
 27287  27509     register unsigned char *a, *b;
 27288  27510     if( zLeft==0 ){
 27289  27511       return zRight ? -1 : 0;
 27290  27512     }else if( zRight==0 ){
 27291  27513       return 1;
 27292  27514     }
 27293  27515     a = (unsigned char *)zLeft;
................................................................................
 28757  28979       /*  25 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
 28758  28980       /*  26 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
 28759  28981       /*  27 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
 28760  28982       /*  28 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
 28761  28983       /*  29 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
 28762  28984       /*  30 */ "NotFound"         OpHelp("key=r[P3@P4]"),
 28763  28985       /*  31 */ "Found"            OpHelp("key=r[P3@P4]"),
 28764         -    /*  32 */ "NotExists"        OpHelp("intkey=r[P3]"),
 28765         -    /*  33 */ "Last"             OpHelp(""),
        28986  +    /*  32 */ "SeekRowid"        OpHelp("intkey=r[P3]"),
        28987  +    /*  33 */ "NotExists"        OpHelp("intkey=r[P3]"),
 28766  28988       /*  34 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
 28767  28989       /*  35 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
 28768  28990       /*  36 */ "Ne"               OpHelp("if r[P1]!=r[P3] goto P2"),
 28769  28991       /*  37 */ "Eq"               OpHelp("if r[P1]==r[P3] goto P2"),
 28770  28992       /*  38 */ "Gt"               OpHelp("if r[P1]>r[P3] goto P2"),
 28771  28993       /*  39 */ "Le"               OpHelp("if r[P1]<=r[P3] goto P2"),
 28772  28994       /*  40 */ "Lt"               OpHelp("if r[P1]<r[P3] goto P2"),
 28773  28995       /*  41 */ "Ge"               OpHelp("if r[P1]>=r[P3] goto P2"),
 28774         -    /*  42 */ "SorterSort"       OpHelp(""),
        28996  +    /*  42 */ "Last"             OpHelp(""),
 28775  28997       /*  43 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
 28776  28998       /*  44 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
 28777  28999       /*  45 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
 28778  29000       /*  46 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
 28779  29001       /*  47 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
 28780  29002       /*  48 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
 28781  29003       /*  49 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
 28782  29004       /*  50 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
 28783  29005       /*  51 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
 28784  29006       /*  52 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
 28785         -    /*  53 */ "Sort"             OpHelp(""),
        29007  +    /*  53 */ "SorterSort"       OpHelp(""),
 28786  29008       /*  54 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
 28787         -    /*  55 */ "Rewind"           OpHelp(""),
 28788         -    /*  56 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
 28789         -    /*  57 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
 28790         -    /*  58 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
 28791         -    /*  59 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
 28792         -    /*  60 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
 28793         -    /*  61 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
 28794         -    /*  62 */ "Program"          OpHelp(""),
 28795         -    /*  63 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
 28796         -    /*  64 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
 28797         -    /*  65 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
 28798         -    /*  66 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
 28799         -    /*  67 */ "IncrVacuum"       OpHelp(""),
 28800         -    /*  68 */ "VNext"            OpHelp(""),
 28801         -    /*  69 */ "Init"             OpHelp("Start at P2"),
 28802         -    /*  70 */ "Return"           OpHelp(""),
 28803         -    /*  71 */ "EndCoroutine"     OpHelp(""),
 28804         -    /*  72 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
 28805         -    /*  73 */ "Halt"             OpHelp(""),
 28806         -    /*  74 */ "Integer"          OpHelp("r[P2]=P1"),
 28807         -    /*  75 */ "Int64"            OpHelp("r[P2]=P4"),
 28808         -    /*  76 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
 28809         -    /*  77 */ "Null"             OpHelp("r[P2..P3]=NULL"),
 28810         -    /*  78 */ "SoftNull"         OpHelp("r[P1]=NULL"),
 28811         -    /*  79 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
 28812         -    /*  80 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
 28813         -    /*  81 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
 28814         -    /*  82 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
 28815         -    /*  83 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
 28816         -    /*  84 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
 28817         -    /*  85 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
 28818         -    /*  86 */ "CollSeq"          OpHelp(""),
 28819         -    /*  87 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
 28820         -    /*  88 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
 28821         -    /*  89 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
 28822         -    /*  90 */ "RealAffinity"     OpHelp(""),
 28823         -    /*  91 */ "Cast"             OpHelp("affinity(r[P1])"),
 28824         -    /*  92 */ "Permutation"      OpHelp(""),
 28825         -    /*  93 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
 28826         -    /*  94 */ "Column"           OpHelp("r[P3]=PX"),
 28827         -    /*  95 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
 28828         -    /*  96 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
        29009  +    /*  55 */ "Sort"             OpHelp(""),
        29010  +    /*  56 */ "Rewind"           OpHelp(""),
        29011  +    /*  57 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
        29012  +    /*  58 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
        29013  +    /*  59 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
        29014  +    /*  60 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
        29015  +    /*  61 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
        29016  +    /*  62 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
        29017  +    /*  63 */ "Program"          OpHelp(""),
        29018  +    /*  64 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
        29019  +    /*  65 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
        29020  +    /*  66 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
        29021  +    /*  67 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
        29022  +    /*  68 */ "IncrVacuum"       OpHelp(""),
        29023  +    /*  69 */ "VNext"            OpHelp(""),
        29024  +    /*  70 */ "Init"             OpHelp("Start at P2"),
        29025  +    /*  71 */ "Return"           OpHelp(""),
        29026  +    /*  72 */ "EndCoroutine"     OpHelp(""),
        29027  +    /*  73 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
        29028  +    /*  74 */ "Halt"             OpHelp(""),
        29029  +    /*  75 */ "Integer"          OpHelp("r[P2]=P1"),
        29030  +    /*  76 */ "Int64"            OpHelp("r[P2]=P4"),
        29031  +    /*  77 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
        29032  +    /*  78 */ "Null"             OpHelp("r[P2..P3]=NULL"),
        29033  +    /*  79 */ "SoftNull"         OpHelp("r[P1]=NULL"),
        29034  +    /*  80 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
        29035  +    /*  81 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
        29036  +    /*  82 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
        29037  +    /*  83 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
        29038  +    /*  84 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
        29039  +    /*  85 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
        29040  +    /*  86 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
        29041  +    /*  87 */ "CollSeq"          OpHelp(""),
        29042  +    /*  88 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
        29043  +    /*  89 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
        29044  +    /*  90 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
        29045  +    /*  91 */ "RealAffinity"     OpHelp(""),
        29046  +    /*  92 */ "Cast"             OpHelp("affinity(r[P1])"),
        29047  +    /*  93 */ "Permutation"      OpHelp(""),
        29048  +    /*  94 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
        29049  +    /*  95 */ "Column"           OpHelp("r[P3]=PX"),
        29050  +    /*  96 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
 28829  29051       /*  97 */ "String8"          OpHelp("r[P2]='P4'"),
 28830         -    /*  98 */ "Count"            OpHelp("r[P2]=count()"),
 28831         -    /*  99 */ "ReadCookie"       OpHelp(""),
 28832         -    /* 100 */ "SetCookie"        OpHelp(""),
 28833         -    /* 101 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
 28834         -    /* 102 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
 28835         -    /* 103 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
 28836         -    /* 104 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
 28837         -    /* 105 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
 28838         -    /* 106 */ "SorterOpen"       OpHelp(""),
 28839         -    /* 107 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
 28840         -    /* 108 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
 28841         -    /* 109 */ "Close"            OpHelp(""),
 28842         -    /* 110 */ "ColumnsUsed"      OpHelp(""),
 28843         -    /* 111 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
 28844         -    /* 112 */ "NewRowid"         OpHelp("r[P2]=rowid"),
 28845         -    /* 113 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
 28846         -    /* 114 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
 28847         -    /* 115 */ "Delete"           OpHelp(""),
 28848         -    /* 116 */ "ResetCount"       OpHelp(""),
 28849         -    /* 117 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
 28850         -    /* 118 */ "SorterData"       OpHelp("r[P2]=data"),
 28851         -    /* 119 */ "RowKey"           OpHelp("r[P2]=key"),
 28852         -    /* 120 */ "RowData"          OpHelp("r[P2]=data"),
 28853         -    /* 121 */ "Rowid"            OpHelp("r[P2]=rowid"),
 28854         -    /* 122 */ "NullRow"          OpHelp(""),
 28855         -    /* 123 */ "SorterInsert"     OpHelp(""),
 28856         -    /* 124 */ "IdxInsert"        OpHelp("key=r[P2]"),
 28857         -    /* 125 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
 28858         -    /* 126 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
 28859         -    /* 127 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 28860         -    /* 128 */ "Destroy"          OpHelp(""),
 28861         -    /* 129 */ "Clear"            OpHelp(""),
 28862         -    /* 130 */ "ResetSorter"      OpHelp(""),
 28863         -    /* 131 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
 28864         -    /* 132 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
        29052  +    /*  98 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
        29053  +    /*  99 */ "Count"            OpHelp("r[P2]=count()"),
        29054  +    /* 100 */ "ReadCookie"       OpHelp(""),
        29055  +    /* 101 */ "SetCookie"        OpHelp(""),
        29056  +    /* 102 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
        29057  +    /* 103 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
        29058  +    /* 104 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
        29059  +    /* 105 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
        29060  +    /* 106 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
        29061  +    /* 107 */ "SorterOpen"       OpHelp(""),
        29062  +    /* 108 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
        29063  +    /* 109 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
        29064  +    /* 110 */ "Close"            OpHelp(""),
        29065  +    /* 111 */ "ColumnsUsed"      OpHelp(""),
        29066  +    /* 112 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
        29067  +    /* 113 */ "NewRowid"         OpHelp("r[P2]=rowid"),
        29068  +    /* 114 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
        29069  +    /* 115 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
        29070  +    /* 116 */ "Delete"           OpHelp(""),
        29071  +    /* 117 */ "ResetCount"       OpHelp(""),
        29072  +    /* 118 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
        29073  +    /* 119 */ "SorterData"       OpHelp("r[P2]=data"),
        29074  +    /* 120 */ "RowKey"           OpHelp("r[P2]=key"),
        29075  +    /* 121 */ "RowData"          OpHelp("r[P2]=data"),
        29076  +    /* 122 */ "Rowid"            OpHelp("r[P2]=rowid"),
        29077  +    /* 123 */ "NullRow"          OpHelp(""),
        29078  +    /* 124 */ "SorterInsert"     OpHelp(""),
        29079  +    /* 125 */ "IdxInsert"        OpHelp("key=r[P2]"),
        29080  +    /* 126 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
        29081  +    /* 127 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
        29082  +    /* 128 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
        29083  +    /* 129 */ "Destroy"          OpHelp(""),
        29084  +    /* 130 */ "Clear"            OpHelp(""),
        29085  +    /* 131 */ "ResetSorter"      OpHelp(""),
        29086  +    /* 132 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
 28865  29087       /* 133 */ "Real"             OpHelp("r[P2]=P4"),
 28866         -    /* 134 */ "ParseSchema"      OpHelp(""),
 28867         -    /* 135 */ "LoadAnalysis"     OpHelp(""),
 28868         -    /* 136 */ "DropTable"        OpHelp(""),
 28869         -    /* 137 */ "DropIndex"        OpHelp(""),
 28870         -    /* 138 */ "DropTrigger"      OpHelp(""),
 28871         -    /* 139 */ "IntegrityCk"      OpHelp(""),
 28872         -    /* 140 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
 28873         -    /* 141 */ "Param"            OpHelp(""),
 28874         -    /* 142 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
 28875         -    /* 143 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
 28876         -    /* 144 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
 28877         -    /* 145 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
 28878         -    /* 146 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
 28879         -    /* 147 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
 28880         -    /* 148 */ "Expire"           OpHelp(""),
 28881         -    /* 149 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
 28882         -    /* 150 */ "VBegin"           OpHelp(""),
 28883         -    /* 151 */ "VCreate"          OpHelp(""),
 28884         -    /* 152 */ "VDestroy"         OpHelp(""),
 28885         -    /* 153 */ "VOpen"            OpHelp(""),
 28886         -    /* 154 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
 28887         -    /* 155 */ "VRename"          OpHelp(""),
 28888         -    /* 156 */ "Pagecount"        OpHelp(""),
 28889         -    /* 157 */ "MaxPgcnt"         OpHelp(""),
 28890         -    /* 158 */ "CursorHint"       OpHelp(""),
 28891         -    /* 159 */ "Noop"             OpHelp(""),
 28892         -    /* 160 */ "Explain"          OpHelp(""),
        29088  +    /* 134 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
        29089  +    /* 135 */ "ParseSchema"      OpHelp(""),
        29090  +    /* 136 */ "LoadAnalysis"     OpHelp(""),
        29091  +    /* 137 */ "DropTable"        OpHelp(""),
        29092  +    /* 138 */ "DropIndex"        OpHelp(""),
        29093  +    /* 139 */ "DropTrigger"      OpHelp(""),
        29094  +    /* 140 */ "IntegrityCk"      OpHelp(""),
        29095  +    /* 141 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
        29096  +    /* 142 */ "Param"            OpHelp(""),
        29097  +    /* 143 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
        29098  +    /* 144 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
        29099  +    /* 145 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
        29100  +    /* 146 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
        29101  +    /* 147 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
        29102  +    /* 148 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
        29103  +    /* 149 */ "Expire"           OpHelp(""),
        29104  +    /* 150 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
        29105  +    /* 151 */ "VBegin"           OpHelp(""),
        29106  +    /* 152 */ "VCreate"          OpHelp(""),
        29107  +    /* 153 */ "VDestroy"         OpHelp(""),
        29108  +    /* 154 */ "VOpen"            OpHelp(""),
        29109  +    /* 155 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
        29110  +    /* 156 */ "VRename"          OpHelp(""),
        29111  +    /* 157 */ "Pagecount"        OpHelp(""),
        29112  +    /* 158 */ "MaxPgcnt"         OpHelp(""),
        29113  +    /* 159 */ "CursorHint"       OpHelp(""),
        29114  +    /* 160 */ "Noop"             OpHelp(""),
        29115  +    /* 161 */ "Explain"          OpHelp(""),
 28893  29116     };
 28894  29117     return azName[i];
 28895  29118   }
 28896  29119   #endif
 28897  29120   
 28898  29121   /************** End of opcodes.c *********************************************/
 28899  29122   /************** Begin file os_unix.c *****************************************/
................................................................................
 29235  29458   **    May you share freely, never taking more than you give.
 29236  29459   **
 29237  29460   ******************************************************************************
 29238  29461   **
 29239  29462   ** This file contains inline asm code for retrieving "high-performance"
 29240  29463   ** counters for x86 class CPUs.
 29241  29464   */
 29242         -#ifndef _HWTIME_H_
 29243         -#define _HWTIME_H_
        29465  +#ifndef SQLITE_HWTIME_H
        29466  +#define SQLITE_HWTIME_H
 29244  29467   
 29245  29468   /*
 29246  29469   ** The following routine only works on pentium-class (or newer) processors.
 29247  29470   ** It uses the RDTSC opcode to read the cycle count value out of the
 29248  29471   ** processor and returns that value.  This can be used for high-res
 29249  29472   ** profiling.
 29250  29473   */
................................................................................
 29304  29527     ** of the debugging and testing utilities, but it should at
 29305  29528     ** least compile and run.
 29306  29529     */
 29307  29530   SQLITE_PRIVATE   sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
 29308  29531   
 29309  29532   #endif
 29310  29533   
 29311         -#endif /* !defined(_HWTIME_H_) */
        29534  +#endif /* !defined(SQLITE_HWTIME_H) */
 29312  29535   
 29313  29536   /************** End of hwtime.h **********************************************/
 29314  29537   /************** Continuing where we left off in os_common.h ******************/
 29315  29538   
 29316  29539   static sqlite_uint64 g_start;
 29317  29540   static sqlite_uint64 g_elapsed;
 29318  29541   #define TIMER_START       g_start=sqlite3Hwtime()
................................................................................
 36577  36800   ** files.
 36578  36801   **
 36579  36802   ** This routine is called once during SQLite initialization and by a
 36580  36803   ** single thread.  The memory allocation and mutex subsystems have not
 36581  36804   ** necessarily been initialized when this routine is called, and so they
 36582  36805   ** should not be used.
 36583  36806   */
 36584         -SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void){ 
        36807  +SQLITE_API int SQLITE_APICALL sqlite3_os_init(void){ 
 36585  36808     /* 
 36586  36809     ** The following macro defines an initializer for an sqlite3_vfs object.
 36587  36810     ** The name of the VFS is NAME.  The pAppData is a pointer to a pointer
 36588  36811     ** to the "finder" function.  (pAppData is a pointer to a pointer because
 36589  36812     ** silly C90 rules prohibit a void* from being cast to a function pointer
 36590  36813     ** and so we have to go through the intermediate pointer to avoid problems
 36591  36814     ** when compiling with -pedantic-errors on GCC.)
................................................................................
 36676  36899   /*
 36677  36900   ** Shutdown the operating system interface.
 36678  36901   **
 36679  36902   ** Some operating systems might need to do some cleanup in this routine,
 36680  36903   ** to release dynamically allocated objects.  But not on unix.
 36681  36904   ** This routine is a no-op for unix.
 36682  36905   */
 36683         -SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void){ 
        36906  +SQLITE_API int SQLITE_APICALL sqlite3_os_end(void){ 
 36684  36907     return SQLITE_OK; 
 36685  36908   }
 36686  36909    
 36687  36910   #endif /* SQLITE_OS_UNIX */
 36688  36911   
 36689  36912   /************** End of os_unix.c *********************************************/
 36690  36913   /************** Begin file os_win.c ******************************************/
................................................................................
 36764  36987   **    May you share freely, never taking more than you give.
 36765  36988   **
 36766  36989   ******************************************************************************
 36767  36990   **
 36768  36991   ** This file contains inline asm code for retrieving "high-performance"
 36769  36992   ** counters for x86 class CPUs.
 36770  36993   */
 36771         -#ifndef _HWTIME_H_
 36772         -#define _HWTIME_H_
        36994  +#ifndef SQLITE_HWTIME_H
        36995  +#define SQLITE_HWTIME_H
 36773  36996   
 36774  36997   /*
 36775  36998   ** The following routine only works on pentium-class (or newer) processors.
 36776  36999   ** It uses the RDTSC opcode to read the cycle count value out of the
 36777  37000   ** processor and returns that value.  This can be used for high-res
 36778  37001   ** profiling.
 36779  37002   */
................................................................................
 36833  37056     ** of the debugging and testing utilities, but it should at
 36834  37057     ** least compile and run.
 36835  37058     */
 36836  37059   SQLITE_PRIVATE   sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
 36837  37060   
 36838  37061   #endif
 36839  37062   
 36840         -#endif /* !defined(_HWTIME_H_) */
        37063  +#endif /* !defined(SQLITE_HWTIME_H) */
 36841  37064   
 36842  37065   /************** End of hwtime.h **********************************************/
 36843  37066   /************** Continuing where we left off in os_common.h ******************/
 36844  37067   
 36845  37068   static sqlite_uint64 g_start;
 36846  37069   static sqlite_uint64 g_elapsed;
 36847  37070   #define TIMER_START       g_start=sqlite3Hwtime()
................................................................................
 37173  37396     HANDLE hMap;                  /* Handle for accessing memory mapping */
 37174  37397     void *pMapRegion;             /* Area memory mapped */
 37175  37398     sqlite3_int64 mmapSize;       /* Usable size of mapped region */
 37176  37399     sqlite3_int64 mmapSizeActual; /* Actual size of mapped region */
 37177  37400     sqlite3_int64 mmapSizeMax;    /* Configured FCNTL_MMAP_SIZE value */
 37178  37401   #endif
 37179  37402   };
        37403  +
        37404  +/*
        37405  +** The winVfsAppData structure is used for the pAppData member for all of the
        37406  +** Win32 VFS variants.
        37407  +*/
        37408  +typedef struct winVfsAppData winVfsAppData;
        37409  +struct winVfsAppData {
        37410  +  const sqlite3_io_methods *pMethod; /* The file I/O methods to use. */
        37411  +  void *pAppData;                    /* The extra pAppData, if any. */
        37412  +  BOOL bNoLock;                      /* Non-zero if locking is disabled. */
        37413  +};
 37180  37414   
 37181  37415   /*
 37182  37416   ** Allowed values for winFile.ctrlFlags
 37183  37417   */
 37184  37418   #define WINFILE_RDONLY          0x02   /* Connection is read only */
 37185  37419   #define WINFILE_PERSIST_WAL     0x04   /* Persistent WAL mode */
 37186  37420   #define WINFILE_PSOW            0x10   /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
................................................................................
 38100  38334   /*
 38101  38335   ** If a Win32 native heap has been configured, this function will attempt to
 38102  38336   ** compact it.  Upon success, SQLITE_OK will be returned.  Upon failure, one
 38103  38337   ** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned.  The
 38104  38338   ** "pnLargest" argument, if non-zero, will be used to return the size of the
 38105  38339   ** largest committed free block in the heap, in bytes.
 38106  38340   */
 38107         -SQLITE_API int SQLITE_STDCALL sqlite3_win32_compact_heap(LPUINT pnLargest){
        38341  +SQLITE_API int SQLITE_APICALL sqlite3_win32_compact_heap(LPUINT pnLargest){
 38108  38342     int rc = SQLITE_OK;
 38109  38343     UINT nLargest = 0;
 38110  38344     HANDLE hHeap;
 38111  38345   
 38112  38346     winMemAssertMagic();
 38113  38347     hHeap = winMemGetHeap();
 38114  38348     assert( hHeap!=0 );
................................................................................
 38140  38374   
 38141  38375   /*
 38142  38376   ** If a Win32 native heap has been configured, this function will attempt to
 38143  38377   ** destroy and recreate it.  If the Win32 native heap is not isolated and/or
 38144  38378   ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will
 38145  38379   ** be returned and no changes will be made to the Win32 native heap.
 38146  38380   */
 38147         -SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){
        38381  +SQLITE_API int SQLITE_APICALL sqlite3_win32_reset_heap(){
 38148  38382     int rc;
 38149  38383     MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
 38150  38384     MUTEX_LOGIC( sqlite3_mutex *pMem; )    /* The memsys static mutex */
 38151  38385     MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
 38152  38386     MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
 38153  38387     sqlite3_mutex_enter(pMaster);
 38154  38388     sqlite3_mutex_enter(pMem);
................................................................................
 38185  38419   #endif /* SQLITE_WIN32_MALLOC */
 38186  38420   
 38187  38421   /*
 38188  38422   ** This function outputs the specified (ANSI) string to the Win32 debugger
 38189  38423   ** (if available).
 38190  38424   */
 38191  38425   
 38192         -SQLITE_API void SQLITE_STDCALL sqlite3_win32_write_debug(const char *zBuf, int nBuf){
        38426  +SQLITE_API void SQLITE_APICALL sqlite3_win32_write_debug(const char *zBuf, int nBuf){
 38193  38427     char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE];
 38194  38428     int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */
 38195  38429     if( nMin<-1 ) nMin = -1; /* all negative values become -1. */
 38196  38430     assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE );
 38197  38431   #ifdef SQLITE_ENABLE_API_ARMOR
 38198  38432     if( !zBuf ){
 38199  38433       (void)SQLITE_MISUSE_BKPT;
................................................................................
 38231  38465   ** The following routine suspends the current thread for at least ms
 38232  38466   ** milliseconds.  This is equivalent to the Win32 Sleep() interface.
 38233  38467   */
 38234  38468   #if SQLITE_OS_WINRT
 38235  38469   static HANDLE sleepObj = NULL;
 38236  38470   #endif
 38237  38471   
 38238         -SQLITE_API void SQLITE_STDCALL sqlite3_win32_sleep(DWORD milliseconds){
        38472  +SQLITE_API void SQLITE_APICALL sqlite3_win32_sleep(DWORD milliseconds){
 38239  38473   #if SQLITE_OS_WINRT
 38240  38474     if ( sleepObj==NULL ){
 38241  38475       sleepObj = osCreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET,
 38242  38476                                   SYNCHRONIZE);
 38243  38477     }
 38244  38478     assert( sleepObj!=NULL );
 38245  38479     osWaitForSingleObjectEx(sleepObj, milliseconds, FALSE);
................................................................................
 38280  38514   # define osIsNT()  ((sqlite3_os_type==2) || sqlite3_win32_is_nt())
 38281  38515   #endif
 38282  38516   
 38283  38517   /*
 38284  38518   ** This function determines if the machine is running a version of Windows
 38285  38519   ** based on the NT kernel.
 38286  38520   */
 38287         -SQLITE_API int SQLITE_STDCALL sqlite3_win32_is_nt(void){
        38521  +SQLITE_API int SQLITE_APICALL sqlite3_win32_is_nt(void){
 38288  38522   #if SQLITE_OS_WINRT
 38289  38523     /*
 38290  38524     ** NOTE: The WinRT sub-platform is always assumed to be based on the NT
 38291  38525     **       kernel.
 38292  38526     */
 38293  38527     return 1;
 38294  38528   #elif SQLITE_WIN32_GETVERSIONEX
................................................................................
 38668  38902     sqlite3_free(zTmpWide);
 38669  38903     return zTextMbcs;
 38670  38904   }
 38671  38905   
 38672  38906   /*
 38673  38907   ** This is a public wrapper for the winUtf8ToUnicode() function.
 38674  38908   */
 38675         -SQLITE_API LPWSTR SQLITE_STDCALL sqlite3_win32_utf8_to_unicode(const char *zText){
        38909  +SQLITE_API LPWSTR SQLITE_APICALL sqlite3_win32_utf8_to_unicode(const char *zText){
 38676  38910   #ifdef SQLITE_ENABLE_API_ARMOR
 38677  38911     if( !zText ){
 38678  38912       (void)SQLITE_MISUSE_BKPT;
 38679  38913       return 0;
 38680  38914     }
 38681  38915   #endif
 38682  38916   #ifndef SQLITE_OMIT_AUTOINIT
................................................................................
 38684  38918   #endif
 38685  38919     return winUtf8ToUnicode(zText);
 38686  38920   }
 38687  38921   
 38688  38922   /*
 38689  38923   ** This is a public wrapper for the winUnicodeToUtf8() function.
 38690  38924   */
 38691         -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_unicode_to_utf8(LPCWSTR zWideText){
        38925  +SQLITE_API char *SQLITE_APICALL sqlite3_win32_unicode_to_utf8(LPCWSTR zWideText){
 38692  38926   #ifdef SQLITE_ENABLE_API_ARMOR
 38693  38927     if( !zWideText ){
 38694  38928       (void)SQLITE_MISUSE_BKPT;
 38695  38929       return 0;
 38696  38930     }
 38697  38931   #endif
 38698  38932   #ifndef SQLITE_OMIT_AUTOINIT
................................................................................
 38700  38934   #endif
 38701  38935     return winUnicodeToUtf8(zWideText);
 38702  38936   }
 38703  38937   
 38704  38938   /*
 38705  38939   ** This is a public wrapper for the winMbcsToUtf8() function.
 38706  38940   */
 38707         -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_mbcs_to_utf8(const char *zText){
        38941  +SQLITE_API char *SQLITE_APICALL sqlite3_win32_mbcs_to_utf8(const char *zText){
 38708  38942   #ifdef SQLITE_ENABLE_API_ARMOR
 38709  38943     if( !zText ){
 38710  38944       (void)SQLITE_MISUSE_BKPT;
 38711  38945       return 0;
 38712  38946     }
 38713  38947   #endif
 38714  38948   #ifndef SQLITE_OMIT_AUTOINIT
................................................................................
 38716  38950   #endif
 38717  38951     return winMbcsToUtf8(zText, osAreFileApisANSI());
 38718  38952   }
 38719  38953   
 38720  38954   /*
 38721  38955   ** This is a public wrapper for the winMbcsToUtf8() function.
 38722  38956   */
 38723         -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
        38957  +SQLITE_API char *SQLITE_APICALL sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
 38724  38958   #ifdef SQLITE_ENABLE_API_ARMOR
 38725  38959     if( !zText ){
 38726  38960       (void)SQLITE_MISUSE_BKPT;
 38727  38961       return 0;
 38728  38962     }
 38729  38963   #endif
 38730  38964   #ifndef SQLITE_OMIT_AUTOINIT
................................................................................
 38732  38966   #endif
 38733  38967     return winMbcsToUtf8(zText, useAnsi);
 38734  38968   }
 38735  38969   
 38736  38970   /*
 38737  38971   ** This is a public wrapper for the winUtf8ToMbcs() function.
 38738  38972   */
 38739         -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_utf8_to_mbcs(const char *zText){
        38973  +SQLITE_API char *SQLITE_APICALL sqlite3_win32_utf8_to_mbcs(const char *zText){
 38740  38974   #ifdef SQLITE_ENABLE_API_ARMOR
 38741  38975     if( !zText ){
 38742  38976       (void)SQLITE_MISUSE_BKPT;
 38743  38977       return 0;
 38744  38978     }
 38745  38979   #endif
 38746  38980   #ifndef SQLITE_OMIT_AUTOINIT
................................................................................
 38748  38982   #endif
 38749  38983     return winUtf8ToMbcs(zText, osAreFileApisANSI());
 38750  38984   }
 38751  38985   
 38752  38986   /*
 38753  38987   ** This is a public wrapper for the winUtf8ToMbcs() function.
 38754  38988   */
 38755         -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_utf8_to_mbcs_v2(const char *zText, int useAnsi){
        38989  +SQLITE_API char *SQLITE_APICALL sqlite3_win32_utf8_to_mbcs_v2(const char *zText, int useAnsi){
 38756  38990   #ifdef SQLITE_ENABLE_API_ARMOR
 38757  38991     if( !zText ){
 38758  38992       (void)SQLITE_MISUSE_BKPT;
 38759  38993       return 0;
 38760  38994     }
 38761  38995   #endif
 38762  38996   #ifndef SQLITE_OMIT_AUTOINIT
................................................................................
 38768  39002   /*
 38769  39003   ** This function sets the data directory or the temporary directory based on
 38770  39004   ** the provided arguments.  The type argument must be 1 in order to set the
 38771  39005   ** data directory or 2 in order to set the temporary directory.  The zValue
 38772  39006   ** argument is the name of the directory to use.  The return value will be
 38773  39007   ** SQLITE_OK if successful.
 38774  39008   */
 38775         -SQLITE_API int SQLITE_STDCALL sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){
        39009  +SQLITE_API int SQLITE_APICALL sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){
 38776  39010     char **ppDirectory = 0;
 38777  39011   #ifndef SQLITE_OMIT_AUTOINIT
 38778  39012     int rc = sqlite3_initialize();
 38779  39013     if( rc ) return rc;
 38780  39014   #endif
 38781  39015     if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){
 38782  39016       ppDirectory = &sqlite3_data_directory;
................................................................................
 39495  39729   
 39496  39730     do{
 39497  39731       rc = osCloseHandle(pFile->h);
 39498  39732       /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
 39499  39733     }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
 39500  39734   #if SQLITE_OS_WINCE
 39501  39735   #define WINCE_DELETION_ATTEMPTS 3
 39502         -  winceDestroyLock(pFile);
        39736  +  {
        39737  +    winVfsAppData *pAppData = (winVfsAppData*)pFile->pVfs->pAppData;
        39738  +    if( pAppData==NULL || !pAppData->bNoLock ){
        39739  +      winceDestroyLock(pFile);
        39740  +    }
        39741  +  }
 39503  39742     if( pFile->zDeleteOnClose ){
 39504  39743       int cnt = 0;
 39505  39744       while(
 39506  39745              osDeleteFileW(pFile->zDeleteOnClose)==0
 39507  39746           && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
 39508  39747           && cnt++ < WINCE_DELETION_ATTEMPTS
 39509  39748       ){
................................................................................
 40227  40466     }
 40228  40467     pFile->locktype = (u8)locktype;
 40229  40468     OSTRACE(("UNLOCK file=%p, lock=%d, rc=%s\n",
 40230  40469              pFile->h, pFile->locktype, sqlite3ErrName(rc)));
 40231  40470     return rc;
 40232  40471   }
 40233  40472   
        40473  +/******************************************************************************
        40474  +****************************** No-op Locking **********************************
        40475  +**
        40476  +** Of the various locking implementations available, this is by far the
        40477  +** simplest:  locking is ignored.  No attempt is made to lock the database
        40478  +** file for reading or writing.
        40479  +**
        40480  +** This locking mode is appropriate for use on read-only databases
        40481  +** (ex: databases that are burned into CD-ROM, for example.)  It can
        40482  +** also be used if the application employs some external mechanism to
        40483  +** prevent simultaneous access of the same database by two or more
        40484  +** database connections.  But there is a serious risk of database
        40485  +** corruption if this locking mode is used in situations where multiple
        40486  +** database connections are accessing the same database file at the same
        40487  +** time and one or more of those connections are writing.
        40488  +*/
        40489  +
        40490  +static int winNolockLock(sqlite3_file *id, int locktype){
        40491  +  UNUSED_PARAMETER(id);
        40492  +  UNUSED_PARAMETER(locktype);
        40493  +  return SQLITE_OK;
        40494  +}
        40495  +
        40496  +static int winNolockCheckReservedLock(sqlite3_file *id, int *pResOut){
        40497  +  UNUSED_PARAMETER(id);
        40498  +  UNUSED_PARAMETER(pResOut);
        40499  +  return SQLITE_OK;
        40500  +}
        40501  +
        40502  +static int winNolockUnlock(sqlite3_file *id, int locktype){
        40503  +  UNUSED_PARAMETER(id);
        40504  +  UNUSED_PARAMETER(locktype);
        40505  +  return SQLITE_OK;
        40506  +}
        40507  +
        40508  +/******************* End of the no-op lock implementation *********************
        40509  +******************************************************************************/
        40510  +
 40234  40511   /*
 40235  40512   ** If *pArg is initially negative then this is a query.  Set *pArg to
 40236  40513   ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
 40237  40514   **
 40238  40515   ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
 40239  40516   */
 40240  40517   static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){
................................................................................
 40505  40782   */
 40506  40783   #define WIN_SHM_BASE   ((22+SQLITE_SHM_NLOCK)*4)        /* first lock byte */
 40507  40784   #define WIN_SHM_DMS    (WIN_SHM_BASE+SQLITE_SHM_NLOCK)  /* deadman switch */
 40508  40785   
 40509  40786   /*
 40510  40787   ** Apply advisory locks for all n bytes beginning at ofst.
 40511  40788   */
 40512         -#define _SHM_UNLCK  1
 40513         -#define _SHM_RDLCK  2
 40514         -#define _SHM_WRLCK  3
        40789  +#define WINSHM_UNLCK  1
        40790  +#define WINSHM_RDLCK  2
        40791  +#define WINSHM_WRLCK  3
 40515  40792   static int winShmSystemLock(
 40516  40793     winShmNode *pFile,    /* Apply locks to this open shared-memory segment */
 40517         -  int lockType,         /* _SHM_UNLCK, _SHM_RDLCK, or _SHM_WRLCK */
        40794  +  int lockType,         /* WINSHM_UNLCK, WINSHM_RDLCK, or WINSHM_WRLCK */
 40518  40795     int ofst,             /* Offset to first byte to be locked/unlocked */
 40519  40796     int nByte             /* Number of bytes to lock or unlock */
 40520  40797   ){
 40521  40798     int rc = 0;           /* Result code form Lock/UnlockFileEx() */
 40522  40799   
 40523  40800     /* Access to the winShmNode object is serialized by the caller */
 40524  40801     assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 );
 40525  40802   
 40526  40803     OSTRACE(("SHM-LOCK file=%p, lock=%d, offset=%d, size=%d\n",
 40527  40804              pFile->hFile.h, lockType, ofst, nByte));
 40528  40805   
 40529  40806     /* Release/Acquire the system-level lock */
 40530         -  if( lockType==_SHM_UNLCK ){
        40807  +  if( lockType==WINSHM_UNLCK ){
 40531  40808       rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
 40532  40809     }else{
 40533  40810       /* Initialize the locking parameters */
 40534  40811       DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
 40535         -    if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
        40812  +    if( lockType == WINSHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
 40536  40813       rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
 40537  40814     }
 40538  40815   
 40539  40816     if( rc!= 0 ){
 40540  40817       rc = SQLITE_OK;
 40541  40818     }else{
 40542  40819       pFile->lastErrno =  osGetLastError();
 40543  40820       rc = SQLITE_BUSY;
 40544  40821     }
 40545  40822   
 40546  40823     OSTRACE(("SHM-LOCK file=%p, func=%s, errno=%lu, rc=%s\n",
 40547         -           pFile->hFile.h, (lockType == _SHM_UNLCK) ? "winUnlockFile" :
        40824  +           pFile->hFile.h, (lockType == WINSHM_UNLCK) ? "winUnlockFile" :
 40548  40825              "winLockFile", pFile->lastErrno, sqlite3ErrName(rc)));
 40549  40826   
 40550  40827     return rc;
 40551  40828   }
 40552  40829   
 40553  40830   /* Forward references to VFS methods */
 40554  40831   static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*);
................................................................................
 40668  40945       if( SQLITE_OK!=rc ){
 40669  40946         goto shm_open_err;
 40670  40947       }
 40671  40948   
 40672  40949       /* Check to see if another process is holding the dead-man switch.
 40673  40950       ** If not, truncate the file to zero length.
 40674  40951       */
 40675         -    if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){
        40952  +    if( winShmSystemLock(pShmNode, WINSHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){
 40676  40953         rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0);
 40677  40954         if( rc!=SQLITE_OK ){
 40678  40955           rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(),
 40679  40956                            "winOpenShm", pDbFd->zPath);
 40680  40957         }
 40681  40958       }
 40682  40959       if( rc==SQLITE_OK ){
 40683         -      winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1);
 40684         -      rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1);
        40960  +      winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
        40961  +      rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, WIN_SHM_DMS, 1);
 40685  40962       }
 40686  40963       if( rc ) goto shm_open_err;
 40687  40964     }
 40688  40965   
 40689  40966     /* Make the new connection a child of the winShmNode */
 40690  40967     p->pShmNode = pShmNode;
 40691  40968   #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
................................................................................
 40706  40983     p->pNext = pShmNode->pFirst;
 40707  40984     pShmNode->pFirst = p;
 40708  40985     sqlite3_mutex_leave(pShmNode->mutex);
 40709  40986     return SQLITE_OK;
 40710  40987   
 40711  40988     /* Jump here on any error */
 40712  40989   shm_open_err:
 40713         -  winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1);
        40990  +  winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
 40714  40991     winShmPurge(pDbFd->pVfs, 0);      /* This call frees pShmNode if required */
 40715  40992     sqlite3_free(p);
 40716  40993     sqlite3_free(pNew);
 40717  40994     winShmLeaveMutex();
 40718  40995     return rc;
 40719  40996   }
 40720  40997   
................................................................................
 40795  41072         if( pX==p ) continue;
 40796  41073         assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 );
 40797  41074         allMask |= pX->sharedMask;
 40798  41075       }
 40799  41076   
 40800  41077       /* Unlock the system-level locks */
 40801  41078       if( (mask & allMask)==0 ){
 40802         -      rc = winShmSystemLock(pShmNode, _SHM_UNLCK, ofst+WIN_SHM_BASE, n);
        41079  +      rc = winShmSystemLock(pShmNode, WINSHM_UNLCK, ofst+WIN_SHM_BASE, n);
 40803  41080       }else{
 40804  41081         rc = SQLITE_OK;
 40805  41082       }
 40806  41083   
 40807  41084       /* Undo the local locks */
 40808  41085       if( rc==SQLITE_OK ){
 40809  41086         p->exclMask &= ~mask;
................................................................................
 40823  41100         }
 40824  41101         allShared |= pX->sharedMask;
 40825  41102       }
 40826  41103   
 40827  41104       /* Get shared locks at the system level, if necessary */
 40828  41105       if( rc==SQLITE_OK ){
 40829  41106         if( (allShared & mask)==0 ){
 40830         -        rc = winShmSystemLock(pShmNode, _SHM_RDLCK, ofst+WIN_SHM_BASE, n);
        41107  +        rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, ofst+WIN_SHM_BASE, n);
 40831  41108         }else{
 40832  41109           rc = SQLITE_OK;
 40833  41110         }
 40834  41111       }
 40835  41112   
 40836  41113       /* Get the local shared locks */
 40837  41114       if( rc==SQLITE_OK ){
................................................................................
 40848  41125         }
 40849  41126       }
 40850  41127   
 40851  41128       /* Get the exclusive locks at the system level.  Then if successful
 40852  41129       ** also mark the local connection as being locked.
 40853  41130       */
 40854  41131       if( rc==SQLITE_OK ){
 40855         -      rc = winShmSystemLock(pShmNode, _SHM_WRLCK, ofst+WIN_SHM_BASE, n);
        41132  +      rc = winShmSystemLock(pShmNode, WINSHM_WRLCK, ofst+WIN_SHM_BASE, n);
 40856  41133         if( rc==SQLITE_OK ){
 40857  41134           assert( (p->sharedMask & mask)==0 );
 40858  41135           p->exclMask |= mask;
 40859  41136         }
 40860  41137       }
 40861  41138     }
 40862  41139     sqlite3_mutex_leave(pShmNode->mutex);
................................................................................
 41290  41567     winShmMap,                      /* xShmMap */
 41291  41568     winShmLock,                     /* xShmLock */
 41292  41569     winShmBarrier,                  /* xShmBarrier */
 41293  41570     winShmUnmap,                    /* xShmUnmap */
 41294  41571     winFetch,                       /* xFetch */
 41295  41572     winUnfetch                      /* xUnfetch */
 41296  41573   };
        41574  +
        41575  +/*
        41576  +** This vector defines all the methods that can operate on an
        41577  +** sqlite3_file for win32 without performing any locking.
        41578  +*/
        41579  +static const sqlite3_io_methods winIoNolockMethod = {
        41580  +  3,                              /* iVersion */
        41581  +  winClose,                       /* xClose */
        41582  +  winRead,                        /* xRead */
        41583  +  winWrite,                       /* xWrite */
        41584  +  winTruncate,                    /* xTruncate */
        41585  +  winSync,                        /* xSync */
        41586  +  winFileSize,                    /* xFileSize */
        41587  +  winNolockLock,                  /* xLock */
        41588  +  winNolockUnlock,                /* xUnlock */
        41589  +  winNolockCheckReservedLock,     /* xCheckReservedLock */
        41590  +  winFileControl,                 /* xFileControl */
        41591  +  winSectorSize,                  /* xSectorSize */
        41592  +  winDeviceCharacteristics,       /* xDeviceCharacteristics */
        41593  +  winShmMap,                      /* xShmMap */
        41594  +  winShmLock,                     /* xShmLock */
        41595  +  winShmBarrier,                  /* xShmBarrier */
        41596  +  winShmUnmap,                    /* xShmUnmap */
        41597  +  winFetch,                       /* xFetch */
        41598  +  winUnfetch                      /* xUnfetch */
        41599  +};
        41600  +
        41601  +static winVfsAppData winAppData = {
        41602  +  &winIoMethod,       /* pMethod */
        41603  +  0,                  /* pAppData */
        41604  +  0                   /* bNoLock */
        41605  +};
        41606  +
        41607  +static winVfsAppData winNolockAppData = {
        41608  +  &winIoNolockMethod, /* pMethod */
        41609  +  0,                  /* pAppData */
        41610  +  1                   /* bNoLock */
        41611  +};
 41297  41612   
 41298  41613   /****************************************************************************
 41299  41614   **************************** sqlite3_vfs methods ****************************
 41300  41615   **
 41301  41616   ** This division contains the implementation of methods on the
 41302  41617   ** sqlite3_vfs object.
 41303  41618   */
................................................................................
 41623  41938     return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY);
 41624  41939   }
 41625  41940   
 41626  41941   /*
 41627  41942   ** Open a file.
 41628  41943   */
 41629  41944   static int winOpen(
 41630         -  sqlite3_vfs *pVfs,        /* Used to get maximum path name length */
        41945  +  sqlite3_vfs *pVfs,        /* Used to get maximum path length and AppData */
 41631  41946     const char *zName,        /* Name of the file (UTF-8) */
 41632  41947     sqlite3_file *id,         /* Write the SQLite file handle here */
 41633  41948     int flags,                /* Open mode flags */
 41634  41949     int *pOutFlags            /* Status return flags */
 41635  41950   ){
 41636  41951     HANDLE h;
 41637  41952     DWORD lastErrno = 0;
................................................................................
 41638  41953     DWORD dwDesiredAccess;
 41639  41954     DWORD dwShareMode;
 41640  41955     DWORD dwCreationDisposition;
 41641  41956     DWORD dwFlagsAndAttributes = 0;
 41642  41957   #if SQLITE_OS_WINCE
 41643  41958     int isTemp = 0;
 41644  41959   #endif
        41960  +  winVfsAppData *pAppData;
 41645  41961     winFile *pFile = (winFile*)id;
 41646  41962     void *zConverted;              /* Filename in OS encoding */
 41647  41963     const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
 41648  41964     int cnt = 0;
 41649  41965   
 41650  41966     /* If argument zPath is a NULL pointer, this function is required to open
 41651  41967     ** a temporary file. Use this buffer to store the file name in.
................................................................................
 41859  42175       }
 41860  42176     }
 41861  42177   
 41862  42178     OSTRACE(("OPEN file=%p, name=%s, access=%lx, pOutFlags=%p, *pOutFlags=%d, "
 41863  42179              "rc=%s\n", h, zUtf8Name, dwDesiredAccess, pOutFlags, pOutFlags ?
 41864  42180              *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
 41865  42181   
        42182  +  pAppData = (winVfsAppData*)pVfs->pAppData;
        42183  +
 41866  42184   #if SQLITE_OS_WINCE
 41867         -  if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
 41868         -       && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
 41869         -  ){
 41870         -    osCloseHandle(h);
 41871         -    sqlite3_free(zConverted);
 41872         -    sqlite3_free(zTmpname);
 41873         -    OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc)));
 41874         -    return rc;
        42185  +  {
        42186  +    if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
        42187  +         && ((pAppData==NULL) || !pAppData->bNoLock)
        42188  +         && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
        42189  +    ){
        42190  +      osCloseHandle(h);
        42191  +      sqlite3_free(zConverted);
        42192  +      sqlite3_free(zTmpname);
        42193  +      OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc)));
        42194  +      return rc;
        42195  +    }
 41875  42196     }
 41876  42197     if( isTemp ){
 41877  42198       pFile->zDeleteOnClose = zConverted;
 41878  42199     }else
 41879  42200   #endif
 41880  42201     {
 41881  42202       sqlite3_free(zConverted);
 41882  42203     }
 41883  42204   
 41884  42205     sqlite3_free(zTmpname);
 41885         -  pFile->pMethod = &winIoMethod;
        42206  +  pFile->pMethod = pAppData ? pAppData->pMethod : &winIoMethod;
 41886  42207     pFile->pVfs = pVfs;
 41887  42208     pFile->h = h;
 41888  42209     if( isReadonly ){
 41889  42210       pFile->ctrlFlags |= WINFILE_RDONLY;
 41890  42211     }
 41891  42212     if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
 41892  42213       pFile->ctrlFlags |= WINFILE_PSOW;
................................................................................
 42153  42474   */
 42154  42475   static int winFullPathname(
 42155  42476     sqlite3_vfs *pVfs,            /* Pointer to vfs object */
 42156  42477     const char *zRelative,        /* Possibly relative input path */
 42157  42478     int nFull,                    /* Size of output buffer in bytes */
 42158  42479     char *zFull                   /* Output buffer */
 42159  42480   ){
        42481  +#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
        42482  +  DWORD nByte;
        42483  +  void *zConverted;
        42484  +  char *zOut;
        42485  +#endif
        42486  +
        42487  +  /* If this path name begins with "/X:", where "X" is any alphabetic
        42488  +  ** character, discard the initial "/" from the pathname.
        42489  +  */
        42490  +  if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){
        42491  +    zRelative++;
        42492  +  }
 42160  42493   
 42161  42494   #if defined(__CYGWIN__)
 42162  42495     SimulateIOError( return SQLITE_ERROR );
 42163  42496     UNUSED_PARAMETER(nFull);
 42164  42497     assert( nFull>=pVfs->mxPathname );
 42165  42498     if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
 42166  42499       /*
................................................................................
 42231  42564     }else{
 42232  42565       sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
 42233  42566     }
 42234  42567     return SQLITE_OK;
 42235  42568   #endif
 42236  42569   
 42237  42570   #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
 42238         -  DWORD nByte;
 42239         -  void *zConverted;
 42240         -  char *zOut;
 42241         -
 42242         -  /* If this path name begins with "/X:", where "X" is any alphabetic
 42243         -  ** character, discard the initial "/" from the pathname.
 42244         -  */
 42245         -  if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){
 42246         -    zRelative++;
 42247         -  }
 42248         -
 42249  42571     /* It's odd to simulate an io-error here, but really this is just
 42250  42572     ** using the io-error infrastructure to test that SQLite handles this
 42251  42573     ** function failing. This function could fail if, for example, the
 42252  42574     ** current working directory has been unlinked.
 42253  42575     */
 42254  42576     SimulateIOError( return SQLITE_ERROR );
 42255  42577     if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
................................................................................
 42598  42920     if( nBuf>0 ) winGetLastErrorMsg(e, nBuf, zBuf);
 42599  42921     return e;
 42600  42922   }
 42601  42923   
 42602  42924   /*
 42603  42925   ** Initialize and deinitialize the operating system interface.
 42604  42926   */
 42605         -SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void){
        42927  +SQLITE_API int SQLITE_APICALL sqlite3_os_init(void){
 42606  42928     static sqlite3_vfs winVfs = {
 42607         -    3,                   /* iVersion */
 42608         -    sizeof(winFile),     /* szOsFile */
        42929  +    3,                     /* iVersion */
        42930  +    sizeof(winFile),       /* szOsFile */
 42609  42931       SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */
 42610         -    0,                   /* pNext */
 42611         -    "win32",             /* zName */
 42612         -    0,                   /* pAppData */
 42613         -    winOpen,             /* xOpen */
 42614         -    winDelete,           /* xDelete */
 42615         -    winAccess,           /* xAccess */
 42616         -    winFullPathname,     /* xFullPathname */
 42617         -    winDlOpen,           /* xDlOpen */
 42618         -    winDlError,          /* xDlError */
 42619         -    winDlSym,            /* xDlSym */
 42620         -    winDlClose,          /* xDlClose */
 42621         -    winRandomness,       /* xRandomness */
 42622         -    winSleep,            /* xSleep */
 42623         -    winCurrentTime,      /* xCurrentTime */
 42624         -    winGetLastError,     /* xGetLastError */
 42625         -    winCurrentTimeInt64, /* xCurrentTimeInt64 */
 42626         -    winSetSystemCall,    /* xSetSystemCall */
 42627         -    winGetSystemCall,    /* xGetSystemCall */
 42628         -    winNextSystemCall,   /* xNextSystemCall */
        42932  +    0,                     /* pNext */
        42933  +    "win32",               /* zName */
        42934  +    &winAppData,           /* pAppData */
        42935  +    winOpen,               /* xOpen */
        42936  +    winDelete,             /* xDelete */
        42937  +    winAccess,             /* xAccess */
        42938  +    winFullPathname,       /* xFullPathname */
        42939  +    winDlOpen,             /* xDlOpen */
        42940  +    winDlError,            /* xDlError */
        42941  +    winDlSym,              /* xDlSym */
        42942  +    winDlClose,            /* xDlClose */
        42943  +    winRandomness,         /* xRandomness */
        42944  +    winSleep,              /* xSleep */
        42945  +    winCurrentTime,        /* xCurrentTime */
        42946  +    winGetLastError,       /* xGetLastError */
        42947  +    winCurrentTimeInt64,   /* xCurrentTimeInt64 */
        42948  +    winSetSystemCall,      /* xSetSystemCall */
        42949  +    winGetSystemCall,      /* xGetSystemCall */
        42950  +    winNextSystemCall,     /* xNextSystemCall */
 42629  42951     };
 42630  42952   #if defined(SQLITE_WIN32_HAS_WIDE)
 42631  42953     static sqlite3_vfs winLongPathVfs = {
 42632         -    3,                   /* iVersion */
 42633         -    sizeof(winFile),     /* szOsFile */
        42954  +    3,                     /* iVersion */
        42955  +    sizeof(winFile),       /* szOsFile */
        42956  +    SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
        42957  +    0,                     /* pNext */
        42958  +    "win32-longpath",      /* zName */
        42959  +    &winAppData,           /* pAppData */
        42960  +    winOpen,               /* xOpen */
        42961  +    winDelete,             /* xDelete */
        42962  +    winAccess,             /* xAccess */
        42963  +    winFullPathname,       /* xFullPathname */
        42964  +    winDlOpen,             /* xDlOpen */
        42965  +    winDlError,            /* xDlError */
        42966  +    winDlSym,              /* xDlSym */
        42967  +    winDlClose,            /* xDlClose */
        42968  +    winRandomness,         /* xRandomness */
        42969  +    winSleep,              /* xSleep */
        42970  +    winCurrentTime,        /* xCurrentTime */
        42971  +    winGetLastError,       /* xGetLastError */
        42972  +    winCurrentTimeInt64,   /* xCurrentTimeInt64 */
        42973  +    winSetSystemCall,      /* xSetSystemCall */
        42974  +    winGetSystemCall,      /* xGetSystemCall */
        42975  +    winNextSystemCall,     /* xNextSystemCall */
        42976  +  };
        42977  +#endif
        42978  +  static sqlite3_vfs winNolockVfs = {
        42979  +    3,                     /* iVersion */
        42980  +    sizeof(winFile),       /* szOsFile */
        42981  +    SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */
        42982  +    0,                     /* pNext */
        42983  +    "win32-none",          /* zName */
        42984  +    &winNolockAppData,     /* pAppData */
        42985  +    winOpen,               /* xOpen */
        42986  +    winDelete,             /* xDelete */
        42987  +    winAccess,             /* xAccess */
        42988  +    winFullPathname,       /* xFullPathname */
        42989  +    winDlOpen,             /* xDlOpen */
        42990  +    winDlError,            /* xDlError */
        42991  +    winDlSym,              /* xDlSym */
        42992  +    winDlClose,            /* xDlClose */
        42993  +    winRandomness,         /* xRandomness */
        42994  +    winSleep,              /* xSleep */
        42995  +    winCurrentTime,        /* xCurrentTime */
        42996  +    winGetLastError,       /* xGetLastError */
        42997  +    winCurrentTimeInt64,   /* xCurrentTimeInt64 */
        42998  +    winSetSystemCall,      /* xSetSystemCall */
        42999  +    winGetSystemCall,      /* xGetSystemCall */
        43000  +    winNextSystemCall,     /* xNextSystemCall */
        43001  +  };
        43002  +#if defined(SQLITE_WIN32_HAS_WIDE)
        43003  +  static sqlite3_vfs winLongPathNolockVfs = {
        43004  +    3,                     /* iVersion */
        43005  +    sizeof(winFile),       /* szOsFile */
 42634  43006       SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
 42635         -    0,                   /* pNext */
 42636         -    "win32-longpath",    /* zName */
 42637         -    0,                   /* pAppData */
 42638         -    winOpen,             /* xOpen */
 42639         -    winDelete,           /* xDelete */
 42640         -    winAccess,           /* xAccess */
 42641         -    winFullPathname,     /* xFullPathname */
 42642         -    winDlOpen,           /* xDlOpen */
 42643         -    winDlError,          /* xDlError */
 42644         -    winDlSym,            /* xDlSym */
 42645         -    winDlClose,          /* xDlClose */
 42646         -    winRandomness,       /* xRandomness */
 42647         -    winSleep,            /* xSleep */
 42648         -    winCurrentTime,      /* xCurrentTime */
 42649         -    winGetLastError,     /* xGetLastError */
 42650         -    winCurrentTimeInt64, /* xCurrentTimeInt64 */
 42651         -    winSetSystemCall,    /* xSetSystemCall */
 42652         -    winGetSystemCall,    /* xGetSystemCall */
 42653         -    winNextSystemCall,   /* xNextSystemCall */
        43007  +    0,                     /* pNext */
        43008  +    "win32-longpath-none", /* zName */
        43009  +    &winNolockAppData,     /* pAppData */
        43010  +    winOpen,               /* xOpen */
        43011  +    winDelete,             /* xDelete */
        43012  +    winAccess,             /* xAccess */
        43013  +    winFullPathname,       /* xFullPathname */
        43014  +    winDlOpen,             /* xDlOpen */
        43015  +    winDlError,            /* xDlError */
        43016  +    winDlSym,              /* xDlSym */
        43017  +    winDlClose,            /* xDlClose */
        43018  +    winRandomness,         /* xRandomness */
        43019  +    winSleep,              /* xSleep */
        43020  +    winCurrentTime,        /* xCurrentTime */
        43021  +    winGetLastError,       /* xGetLastError */
        43022  +    winCurrentTimeInt64,   /* xCurrentTimeInt64 */
        43023  +    winSetSystemCall,      /* xSetSystemCall */
        43024  +    winGetSystemCall,      /* xGetSystemCall */
        43025  +    winNextSystemCall,     /* xNextSystemCall */
 42654  43026     };
 42655  43027   #endif
 42656  43028   
 42657  43029     /* Double-check that the aSyscall[] array has been constructed
 42658  43030     ** correctly.  See ticket [bb3a86e890c8e96ab] */
 42659  43031     assert( ArraySize(aSyscall)==80 );
 42660  43032   
................................................................................
 42669  43041     assert( winSysInfo.dwPageSize>0 );
 42670  43042   
 42671  43043     sqlite3_vfs_register(&winVfs, 1);
 42672  43044   
 42673  43045   #if defined(SQLITE_WIN32_HAS_WIDE)
 42674  43046     sqlite3_vfs_register(&winLongPathVfs, 0);
 42675  43047   #endif
        43048  +
        43049  +  sqlite3_vfs_register(&winNolockVfs, 0);
        43050  +
        43051  +#if defined(SQLITE_WIN32_HAS_WIDE)
        43052  +  sqlite3_vfs_register(&winLongPathNolockVfs, 0);
        43053  +#endif
 42676  43054   
 42677  43055     return SQLITE_OK;
 42678  43056   }
 42679  43057   
 42680         -SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void){
        43058  +SQLITE_API int SQLITE_APICALL sqlite3_os_end(void){
 42681  43059   #if SQLITE_OS_WINRT
 42682  43060     if( sleepObj!=NULL ){
 42683  43061       osCloseHandle(sleepObj);
 42684  43062       sleepObj = NULL;
 42685  43063     }
 42686  43064   #endif
 42687  43065     return SQLITE_OK;
................................................................................
 43790  44168   */
 43791  44169   SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
 43792  44170     sqlite3PcacheTruncate(pCache, 0);
 43793  44171   }
 43794  44172   
 43795  44173   /*
 43796  44174   ** Merge two lists of pages connected by pDirty and in pgno order.
 43797         -** Do not both fixing the pDirtyPrev pointers.
        44175  +** Do not bother fixing the pDirtyPrev pointers.
 43798  44176   */
 43799  44177   static PgHdr *pcacheMergeDirtyList(PgHdr *pA, PgHdr *pB){
 43800  44178     PgHdr result, *pTail;
 43801  44179     pTail = &result;
 43802         -  while( pA && pB ){
        44180  +  assert( pA!=0 && pB!=0 );
        44181  +  for(;;){
 43803  44182       if( pA->pgno<pB->pgno ){
 43804  44183         pTail->pDirty = pA;
 43805  44184         pTail = pA;
 43806  44185         pA = pA->pDirty;
        44186  +      if( pA==0 ){
        44187  +        pTail->pDirty = pB;
        44188  +        break;
        44189  +      }
 43807  44190       }else{
 43808  44191         pTail->pDirty = pB;
 43809  44192         pTail = pB;
 43810  44193         pB = pB->pDirty;
        44194  +      if( pB==0 ){
        44195  +        pTail->pDirty = pA;
        44196  +        break;
        44197  +      }
 43811  44198       }
 43812  44199     }
 43813         -  if( pA ){
 43814         -    pTail->pDirty = pA;
 43815         -  }else if( pB ){
 43816         -    pTail->pDirty = pB;
 43817         -  }else{
 43818         -    pTail->pDirty = 0;
 43819         -  }
 43820  44200     return result.pDirty;
 43821  44201   }
 43822  44202   
 43823  44203   /*
 43824  44204   ** Sort the list of pages in accending order by pgno.  Pages are
 43825  44205   ** connected by pDirty pointers.  The pDirtyPrev pointers are
 43826  44206   ** corrupted by this sort.
................................................................................
 43853  44233         ** the input list.  But that is impossible.
 43854  44234         */
 43855  44235         a[i] = pcacheMergeDirtyList(a[i], p);
 43856  44236       }
 43857  44237     }
 43858  44238     p = a[0];
 43859  44239     for(i=1; i<N_SORT_BUCKET; i++){
 43860         -    p = pcacheMergeDirtyList(p, a[i]);
        44240  +    if( a[i]==0 ) continue;
        44241  +    p = p ? pcacheMergeDirtyList(p, a[i]) : a[i];
 43861  44242     }
 43862  44243     return p;
 43863  44244   }
 43864  44245   
 43865  44246   /*
 43866  44247   ** Return a list of all dirty pages in the cache, sorted by page number.
 43867  44248   */
................................................................................
 45458  45839     struct RowSetEntry *pA,    /* First sorted list to be merged */
 45459  45840     struct RowSetEntry *pB     /* Second sorted list to be merged */
 45460  45841   ){
 45461  45842     struct RowSetEntry head;
 45462  45843     struct RowSetEntry *pTail;
 45463  45844   
 45464  45845     pTail = &head;
 45465         -  while( pA && pB ){
        45846  +  assert( pA!=0 && pB!=0 );
        45847  +  for(;;){
 45466  45848       assert( pA->pRight==0 || pA->v<=pA->pRight->v );
 45467  45849       assert( pB->pRight==0 || pB->v<=pB->pRight->v );
 45468         -    if( pA->v<pB->v ){
 45469         -      pTail->pRight = pA;
        45850  +    if( pA->v<=pB->v ){
        45851  +      if( pA->v<pB->v ) pTail = pTail->pRight = pA;
 45470  45852         pA = pA->pRight;
 45471         -      pTail = pTail->pRight;
 45472         -    }else if( pB->v<pA->v ){
 45473         -      pTail->pRight = pB;
        45853  +      if( pA==0 ){
        45854  +        pTail->pRight = pB;
        45855  +        break;
        45856  +      }
        45857  +    }else{
        45858  +      pTail = pTail->pRight = pB;
 45474  45859         pB = pB->pRight;
 45475         -      pTail = pTail->pRight;
 45476         -    }else{
 45477         -      pA = pA->pRight;
        45860  +      if( pB==0 ){
        45861  +        pTail->pRight = pA;
        45862  +        break;
        45863  +      }
 45478  45864       }
 45479  45865     }
 45480         -  if( pA ){
 45481         -    assert( pA->pRight==0 || pA->v<=pA->pRight->v );
 45482         -    pTail->pRight = pA;
 45483         -  }else{
 45484         -    assert( pB==0 || pB->pRight==0 || pB->v<=pB->pRight->v );
 45485         -    pTail->pRight = pB;
 45486         -  }
 45487  45866     return head.pRight;
 45488  45867   }
 45489  45868   
 45490  45869   /*
 45491  45870   ** Sort all elements on the list of RowSetEntry objects into order of
 45492  45871   ** increasing v.
 45493  45872   */ 
................................................................................
 45502  45881       for(i=0; aBucket[i]; i++){
 45503  45882         pIn = rowSetEntryMerge(aBucket[i], pIn);
 45504  45883         aBucket[i] = 0;
 45505  45884       }
 45506  45885       aBucket[i] = pIn;
 45507  45886       pIn = pNext;
 45508  45887     }
 45509         -  pIn = 0;
 45510         -  for(i=0; i<sizeof(aBucket)/sizeof(aBucket[0]); i++){
 45511         -    pIn = rowSetEntryMerge(pIn, aBucket[i]);
        45888  +  pIn = aBucket[0];
        45889  +  for(i=1; i<sizeof(aBucket)/sizeof(aBucket[0]); i++){
        45890  +    if( aBucket[i]==0 ) continue;
        45891  +    pIn = pIn ? rowSetEntryMerge(pIn, aBucket[i]) : aBucket[i];
 45512  45892     }
 45513  45893     return pIn;
 45514  45894   }
 45515  45895   
 45516  45896   
 45517  45897   /*
 45518  45898   ** The input, pIn, is a binary tree (or subtree) of RowSetEntry objects.
................................................................................
 45756  46136   **
 45757  46137   *************************************************************************
 45758  46138   ** This header file defines the interface to the write-ahead logging 
 45759  46139   ** system. Refer to the comments below and the header comment attached to 
 45760  46140   ** the implementation of each function in log.c for further details.
 45761  46141   */
 45762  46142   
 45763         -#ifndef _WAL_H_
 45764         -#define _WAL_H_
        46143  +#ifndef SQLITE_WAL_H
        46144  +#define SQLITE_WAL_H
 45765  46145   
 45766  46146   /* #include "sqliteInt.h" */
 45767  46147   
 45768  46148   /* Additional values that can be added to the sync_flags argument of
 45769  46149   ** sqlite3WalFrames():
 45770  46150   */
 45771  46151   #define WAL_SYNC_TRANSACTIONS  0x20   /* Sync at the end of each transaction */
................................................................................
 45885  46265   SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal);
 45886  46266   #endif
 45887  46267   
 45888  46268   /* Return the sqlite3_file object for the WAL file */
 45889  46269   SQLITE_PRIVATE sqlite3_file *sqlite3WalFile(Wal *pWal);
 45890  46270   
 45891  46271   #endif /* ifndef SQLITE_OMIT_WAL */
 45892         -#endif /* _WAL_H_ */
        46272  +#endif /* SQLITE_WAL_H */
 45893  46273   
 45894  46274   /************** End of wal.h *************************************************/
 45895  46275   /************** Continuing where we left off in pager.c **********************/
 45896  46276   
 45897  46277   
 45898  46278   /******************* NOTES ON THE DESIGN OF THE PAGER ************************
 45899  46279   **
................................................................................
 53025  53405   ** uses it opaquely as an argument to sqlite3BackupRestart() and
 53026  53406   ** sqlite3BackupUpdate() only.
 53027  53407   */
 53028  53408   SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager *pPager){
 53029  53409     return &pPager->pBackup;
 53030  53410   }
 53031  53411   
 53032         -#ifndef SQLITE_OMIT_VACUUM
 53033         -/*
 53034         -** Unless this is an in-memory or temporary database, clear the pager cache.
 53035         -*/
 53036         -SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *pPager){
 53037         -  assert( MEMDB==0 || pPager->tempFile );
 53038         -  if( pPager->tempFile==0 ) pager_reset(pPager);
 53039         -}
 53040         -#endif
 53041         -
 53042  53412   #ifndef SQLITE_OMIT_WAL
 53043  53413   /*
 53044  53414   ** This function is called when the user invokes "PRAGMA wal_checkpoint",
 53045  53415   ** "PRAGMA wal_blocking_checkpoint" or calls the sqlite3_wal_checkpoint()
 53046  53416   ** or wal_blocking_checkpoint() API functions.
 53047  53417   **
 53048  53418   ** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
................................................................................
 56376  56746     ** needed and only the sync is done.  If padding is needed, then the
 56377  56747     ** final frame is repeated (with its commit mark) until the next sector
 56378  56748     ** boundary is crossed.  Only the part of the WAL prior to the last
 56379  56749     ** sector boundary is synced; the part of the last frame that extends
 56380  56750     ** past the sector boundary is written after the sync.
 56381  56751     */
 56382  56752     if( isCommit && (sync_flags & WAL_SYNC_TRANSACTIONS)!=0 ){
        56753  +    int bSync = 1;
 56383  56754       if( pWal->padToSectorBoundary ){
 56384  56755         int sectorSize = sqlite3SectorSize(pWal->pWalFd);
 56385  56756         w.iSyncPoint = ((iOffset+sectorSize-1)/sectorSize)*sectorSize;
        56757  +      bSync = (w.iSyncPoint==iOffset);
        56758  +      testcase( bSync );
 56386  56759         while( iOffset<w.iSyncPoint ){
 56387  56760           rc = walWriteOneFrame(&w, pLast, nTruncate, iOffset);
 56388  56761           if( rc ) return rc;
 56389  56762           iOffset += szFrame;
 56390  56763           nExtra++;
 56391  56764         }
 56392         -    }else{
        56765  +    }
        56766  +    if( bSync ){
        56767  +      assert( rc==SQLITE_OK );
 56393  56768         rc = sqlite3OsSync(w.pFd, sync_flags & SQLITE_SYNC_MASK);
 56394  56769       }
 56395  56770     }
 56396  56771   
 56397  56772     /* If this frame set completes the first transaction in the WAL and
 56398  56773     ** if PRAGMA journal_size_limit is set, then truncate the WAL to the
 56399  56774     ** journal size limit, if possible.
................................................................................
 56671  57046     pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
 56672  57047   }
 56673  57048   
 56674  57049   /* 
 56675  57050   ** Return a +ve value if snapshot p1 is newer than p2. A -ve value if
 56676  57051   ** p1 is older than p2 and zero if p1 and p2 are the same snapshot.
 56677  57052   */
 56678         -SQLITE_API int SQLITE_STDCALL sqlite3_snapshot_cmp(sqlite3_snapshot *p1, sqlite3_snapshot *p2){
        57053  +SQLITE_API int SQLITE_APICALL sqlite3_snapshot_cmp(sqlite3_snapshot *p1, sqlite3_snapshot *p2){
 56679  57054     WalIndexHdr *pHdr1 = (WalIndexHdr*)p1;
 56680  57055     WalIndexHdr *pHdr2 = (WalIndexHdr*)p2;
 56681  57056   
 56682  57057     /* aSalt[0] is a copy of the value stored in the wal file header. It
 56683  57058     ** is incremented each time the wal file is restarted.  */
 56684  57059     if( pHdr1->aSalt[0]<pHdr2->aSalt[0] ) return -1;
 56685  57060     if( pHdr1->aSalt[0]>pHdr2->aSalt[0] ) return +1;
................................................................................
 57808  58183   /*
 57809  58184   ** Enable or disable the shared pager and schema features.
 57810  58185   **
 57811  58186   ** This routine has no effect on existing database connections.
 57812  58187   ** The shared cache setting effects only future calls to
 57813  58188   ** sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2().
 57814  58189   */
 57815         -SQLITE_API int SQLITE_STDCALL sqlite3_enable_shared_cache(int enable){
        58190  +SQLITE_API int SQLITE_APICALL sqlite3_enable_shared_cache(int enable){
 57816  58191     sqlite3GlobalConfig.sharedCacheEnabled = enable;
 57817  58192     return SQLITE_OK;
 57818  58193   }
 57819  58194   #endif
 57820  58195   
 57821  58196   
 57822  58197   
................................................................................
 58172  58547   **
 58173  58548   ** Verify that the cursor holds the mutex on its BtShared
 58174  58549   */
 58175  58550   #ifdef SQLITE_DEBUG
 58176  58551   static int cursorHoldsMutex(BtCursor *p){
 58177  58552     return sqlite3_mutex_held(p->pBt->mutex);
 58178  58553   }
        58554  +
        58555  +/* Verify that the cursor and the BtShared agree about what is the current
        58556  +** database connetion. This is important in shared-cache mode. If the database 
        58557  +** connection pointers get out-of-sync, it is possible for routines like
        58558  +** btreeInitPage() to reference an stale connection pointer that references a
        58559  +** a connection that has already closed.  This routine is used inside assert()
        58560  +** statements only and for the purpose of double-checking that the btree code
        58561  +** does keep the database connection pointers up-to-date.
        58562  +*/
 58179  58563   static int cursorOwnsBtShared(BtCursor *p){
 58180  58564     assert( cursorHoldsMutex(p) );
 58181  58565     return (p->pBtree->db==p->pBt->db);
 58182  58566   }
 58183  58567   #endif
 58184  58568   
 58185  58569   /*
................................................................................
 58331  58715   ** If the cursor is open on an intkey table, then the integer key
 58332  58716   ** (the rowid) is stored in pCur->nKey and pCur->pKey is left set to
 58333  58717   ** NULL. If the cursor is open on a non-intkey table, then pCur->pKey is 
 58334  58718   ** set to point to a malloced buffer pCur->nKey bytes in size containing 
 58335  58719   ** the key.
 58336  58720   */
 58337  58721   static int saveCursorKey(BtCursor *pCur){
 58338         -  int rc;
        58722  +  int rc = SQLITE_OK;
 58339  58723     assert( CURSOR_VALID==pCur->eState );
 58340  58724     assert( 0==pCur->pKey );
 58341  58725     assert( cursorHoldsMutex(pCur) );
 58342  58726   
 58343         -  rc = sqlite3BtreeKeySize(pCur, &pCur->nKey);
 58344         -  assert( rc==SQLITE_OK );  /* KeySize() cannot fail */
 58345         -
 58346         -  /* If this is an intKey table, then the above call to BtreeKeySize()
 58347         -  ** stores the integer key in pCur->nKey. In this case this value is
 58348         -  ** all that is required. Otherwise, if pCur is not open on an intKey
 58349         -  ** table, then malloc space for and store the pCur->nKey bytes of key 
 58350         -  ** data.  */
 58351         -  if( 0==pCur->curIntKey ){
 58352         -    void *pKey = sqlite3Malloc( pCur->nKey );
        58727  +  if( pCur->curIntKey ){
        58728  +    /* Only the rowid is required for a table btree */
        58729  +    pCur->nKey = sqlite3BtreeIntegerKey(pCur);
        58730  +  }else{
        58731  +    /* For an index btree, save the complete key content */
        58732  +    void *pKey;
        58733  +    pCur->nKey = sqlite3BtreePayloadSize(pCur);
        58734  +    pKey = sqlite3Malloc( pCur->nKey );
 58353  58735       if( pKey ){
 58354  58736         rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
 58355  58737         if( rc==SQLITE_OK ){
 58356  58738           pCur->pKey = pKey;
 58357  58739         }else{
 58358  58740           sqlite3_free(pKey);
 58359  58741         }
................................................................................
 60052  60434       if( rc ) goto btree_open_out;
 60053  60435       pBt->usableSize = pBt->pageSize - nReserve;
 60054  60436       assert( (pBt->pageSize & 7)==0 );  /* 8-byte alignment of pageSize */
 60055  60437      
 60056  60438   #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
 60057  60439       /* Add the new BtShared object to the linked list sharable BtShareds.
 60058  60440       */
        60441  +    pBt->nRef = 1;
 60059  60442       if( p->sharable ){
 60060  60443         MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
 60061         -      pBt->nRef = 1;
 60062  60444         MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);)
 60063  60445         if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
 60064  60446           pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
 60065  60447           if( pBt->mutex==0 ){
 60066  60448             rc = SQLITE_NOMEM_BKPT;
 60067  60449             goto btree_open_out;
 60068  60450           }
................................................................................
 60125  60507         sqlite3PagerSetCachesize(p->pBt->pPager, SQLITE_DEFAULT_CACHE_SIZE);
 60126  60508       }
 60127  60509     }
 60128  60510     if( mutexOpen ){
 60129  60511       assert( sqlite3_mutex_held(mutexOpen) );
 60130  60512       sqlite3_mutex_leave(mutexOpen);
 60131  60513     }
        60514  +  assert( rc!=SQLITE_OK || sqlite3BtreeConnectionCount(*ppBtree)>0 );
 60132  60515     return rc;
 60133  60516   }
 60134  60517   
 60135  60518   /*
 60136  60519   ** Decrement the BtShared.nRef counter.  When it reaches zero,
 60137  60520   ** remove the BtShared structure from the sharing list.  Return
 60138  60521   ** true if the BtShared.nRef counter reaches zero and return
................................................................................
 61984  62367   */
 61985  62368   SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor *pCur){
 61986  62369     return pCur && pCur->eState==CURSOR_VALID;
 61987  62370   }
 61988  62371   #endif /* NDEBUG */
 61989  62372   
 61990  62373   /*
 61991         -** Set *pSize to the size of the buffer needed to hold the value of
 61992         -** the key for the current entry.  If the cursor is not pointing
 61993         -** to a valid entry, *pSize is set to 0. 
 61994         -**
 61995         -** For a table with the INTKEY flag set, this routine returns the key
 61996         -** itself, not the number of bytes in the key.
 61997         -**
 61998         -** The caller must position the cursor prior to invoking this routine.
 61999         -** 
 62000         -** This routine cannot fail.  It always returns SQLITE_OK.  
        62374  +** Return the value of the integer key or "rowid" for a table btree.
        62375  +** This routine is only valid for a cursor that is pointing into a
        62376  +** ordinary table btree.  If the cursor points to an index btree or
        62377  +** is invalid, the result of this routine is undefined.
 62001  62378   */
 62002         -SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
        62379  +SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor *pCur){
 62003  62380     assert( cursorHoldsMutex(pCur) );
 62004  62381     assert( pCur->eState==CURSOR_VALID );
        62382  +  assert( pCur->curIntKey );
 62005  62383     getCellInfo(pCur);
 62006         -  *pSize = pCur->info.nKey;
 62007         -  return SQLITE_OK;
        62384  +  return pCur->info.nKey;
 62008  62385   }
 62009  62386   
 62010  62387   /*
 62011         -** Set *pSize to the number of bytes of data in the entry the
 62012         -** cursor currently points to.
        62388  +** Return the number of bytes of payload for the entry that pCur is
        62389  +** currently pointing to.  For table btrees, this will be the amount
        62390  +** of data.  For index btrees, this will be the size of the key.
 62013  62391   **
 62014  62392   ** The caller must guarantee that the cursor is pointing to a non-NULL
 62015  62393   ** valid entry.  In other words, the calling procedure must guarantee
 62016  62394   ** that the cursor has Cursor.eState==CURSOR_VALID.
 62017         -**
 62018         -** Failure is not possible.  This function always returns SQLITE_OK.
 62019         -** It might just as well be a procedure (returning void) but we continue
 62020         -** to return an integer result code for historical reasons.
 62021  62395   */
 62022         -SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
 62023         -  assert( cursorOwnsBtShared(pCur) );
        62396  +SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor *pCur){
        62397  +  assert( cursorHoldsMutex(pCur) );
 62024  62398     assert( pCur->eState==CURSOR_VALID );
 62025         -  assert( pCur->iPage>=0 );
 62026         -  assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
 62027         -  assert( pCur->apPage[pCur->iPage]->intKeyLeaf==1 );
 62028  62399     getCellInfo(pCur);
 62029         -  *pSize = pCur->info.nPayload;
 62030         -  return SQLITE_OK;
        62400  +  return pCur->info.nPayload;
 62031  62401   }
 62032  62402   
 62033  62403   /*
 62034  62404   ** Given the page number of an overflow page in the database (parameter
 62035  62405   ** ovfl), this function finds the page number of the next page in the 
 62036  62406   ** linked list of overflow pages. If possible, it uses the auto-vacuum
 62037  62407   ** pointer-map data instead of reading the content of page ovfl to do so. 
................................................................................
 62465  62835   ** including calls from other threads against the same cache.
 62466  62836   ** Hence, a mutex on the BtShared should be held prior to calling
 62467  62837   ** this routine.
 62468  62838   **
 62469  62839   ** These routines is used to get quick access to key and data
 62470  62840   ** in the common case where no overflow pages are used.
 62471  62841   */
 62472         -SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
 62473         -  return fetchPayload(pCur, pAmt);
 62474         -}
 62475         -SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
        62842  +SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor *pCur, u32 *pAmt){
 62476  62843     return fetchPayload(pCur, pAmt);
 62477  62844   }
 62478  62845   
 62479  62846   
 62480  62847   /*
 62481  62848   ** Move the cursor down to a new child page.  The newPgno argument is the
 62482  62849   ** page number of the child page to move to.
................................................................................
 62801  63168     int rc;
 62802  63169     RecordCompare xRecordCompare;
 62803  63170   
 62804  63171     assert( cursorOwnsBtShared(pCur) );
 62805  63172     assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
 62806  63173     assert( pRes );
 62807  63174     assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
        63175  +  assert( pCur->eState!=CURSOR_VALID || (pIdxKey==0)==(pCur->curIntKey!=0) );
 62808  63176   
 62809  63177     /* If the cursor is already positioned at the point we are trying
 62810  63178     ** to move to, then just return without doing any work */
 62811         -  if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0
 62812         -   && pCur->curIntKey 
        63179  +  if( pIdxKey==0
        63180  +   && pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0
 62813  63181     ){
 62814  63182       if( pCur->info.nKey==intKey ){
 62815  63183         *pRes = 0;
 62816  63184         return SQLITE_OK;
 62817  63185       }
 62818  63186       if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKey<intKey ){
 62819  63187         *pRes = -1;
................................................................................
 63794  64162   ** area.  pCell might point to some temporary storage.  The cell will
 63795  64163   ** be constructed in this temporary area then copied into pPage->aData
 63796  64164   ** later.
 63797  64165   */
 63798  64166   static int fillInCell(
 63799  64167     MemPage *pPage,                /* The page that contains the cell */
 63800  64168     unsigned char *pCell,          /* Complete text of the cell */
 63801         -  const void *pKey, i64 nKey,    /* The key */
 63802         -  const void *pData,int nData,   /* The data */
 63803         -  int nZero,                     /* Extra zero bytes to append to pData */
        64169  +  const BtreePayload *pX,        /* Payload with which to construct the cell */
 63804  64170     int *pnSize                    /* Write cell size here */
 63805  64171   ){
 63806  64172     int nPayload;
 63807  64173     const u8 *pSrc;
 63808  64174     int nSrc, n, rc;
 63809  64175     int spaceLeft;
 63810  64176     MemPage *pOvfl = 0;
................................................................................
 63820  64186     /* pPage is not necessarily writeable since pCell might be auxiliary
 63821  64187     ** buffer space that is separate from the pPage buffer area */
 63822  64188     assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
 63823  64189               || sqlite3PagerIswriteable(pPage->pDbPage) );
 63824  64190   
 63825  64191     /* Fill in the header. */
 63826  64192     nHeader = pPage->childPtrSize;
 63827         -  nPayload = nData + nZero;
 63828         -  if( pPage->intKeyLeaf ){
 63829         -    nHeader += putVarint32(&pCell[nHeader], nPayload);
 63830         -  }else{
 63831         -    assert( nData==0 );
 63832         -    assert( nZero==0 );
 63833         -  }
 63834         -  nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
 63835         -  
 63836         -  /* Fill in the payload size */
 63837  64193     if( pPage->intKey ){
 63838         -    pSrc = pData;
 63839         -    nSrc = nData;
 63840         -    nData = 0;
 63841         -  }else{ 
 63842         -    assert( nKey<=0x7fffffff && pKey!=0 );
 63843         -    nPayload = (int)nKey;
 63844         -    pSrc = pKey;
 63845         -    nSrc = (int)nKey;
        64194  +    nPayload = pX->nData + pX->nZero;
        64195  +    pSrc = pX->pData;
        64196  +    nSrc = pX->nData;
        64197  +    assert( pPage->intKeyLeaf ); /* fillInCell() only called for leaves */
        64198  +    nHeader += putVarint32(&pCell[nHeader], nPayload);
        64199  +    nHeader += putVarint(&pCell[nHeader], *(u64*)&pX->nKey);
        64200  +  }else{
        64201  +    assert( pX->nData==0 );
        64202  +    assert( pX->nZero==0 );
        64203  +    assert( pX->nKey<=0x7fffffff && pX->pKey!=0 );
        64204  +    nSrc = nPayload = (int)pX->nKey;
        64205  +    pSrc = pX->pKey;
        64206  +    nHeader += putVarint32(&pCell[nHeader], nPayload);
 63846  64207     }
        64208  +  
        64209  +  /* Fill in the payload */
 63847  64210     if( nPayload<=pPage->maxLocal ){
 63848  64211       n = nHeader + nPayload;
 63849  64212       testcase( n==3 );
 63850  64213       testcase( n==4 );
 63851  64214       if( n<4 ) n = 4;
 63852  64215       *pnSize = n;
 63853  64216       spaceLeft = nPayload;
................................................................................
 63877  64240     ** were computed correctly.
 63878  64241     */
 63879  64242   #if SQLITE_DEBUG
 63880  64243     {
 63881  64244       CellInfo info;
 63882  64245       pPage->xParseCell(pPage, pCell, &info);
 63883  64246       assert( nHeader==(int)(info.pPayload - pCell) );
 63884         -    assert( info.nKey==nKey );
        64247  +    assert( info.nKey==pX->nKey );
 63885  64248       assert( *pnSize == info.nSize );
 63886  64249       assert( spaceLeft == info.nLocal );
 63887  64250     }
 63888  64251   #endif
 63889  64252   
 63890  64253     /* Write the payload into the local Cell and any extra into overflow pages */
 63891  64254     while( nPayload>0 ){
................................................................................
 63962  64325         memset(pPayload, 0, n);
 63963  64326       }
 63964  64327       nPayload -= n;
 63965  64328       pPayload += n;
 63966  64329       pSrc += n;
 63967  64330       nSrc -= n;
 63968  64331       spaceLeft -= n;
 63969         -    if( nSrc==0 ){
 63970         -      nSrc = nData;
 63971         -      pSrc = pData;
 63972         -    }
 63973  64332     }
 63974  64333     releasePage(pToRelease);
 63975  64334     return SQLITE_OK;
 63976  64335   }
 63977  64336   
 63978  64337   /*
 63979  64338   ** Remove the i-th cell from pPage.  This routine effects pPage only.
................................................................................
 64032  64391   ** If the cell content will fit on the page, then put it there.  If it
 64033  64392   ** will not fit, then make a copy of the cell content into pTemp if
 64034  64393   ** pTemp is not null.  Regardless of pTemp, allocate a new entry
 64035  64394   ** in pPage->apOvfl[] and make it point to the cell content (either
 64036  64395   ** in pTemp or the original pCell) and also record its index. 
 64037  64396   ** Allocating a new entry in pPage->aCell[] implies that 
 64038  64397   ** pPage->nOverflow is incremented.
        64398  +**
        64399  +** *pRC must be SQLITE_OK when this routine is called.
 64039  64400   */
 64040  64401   static void insertCell(
 64041  64402     MemPage *pPage,   /* Page into which we are copying */
 64042  64403     int i,            /* New cell becomes the i-th cell of the page */
 64043  64404     u8 *pCell,        /* Content of the new cell */
 64044  64405     int sz,           /* Bytes of content in pCell */
 64045  64406     u8 *pTemp,        /* Temp storage space for pCell, if needed */
................................................................................
 64047  64408     int *pRC          /* Read and write return code from here */
 64048  64409   ){
 64049  64410     int idx = 0;      /* Where to write new cell content in data[] */
 64050  64411     int j;            /* Loop counter */
 64051  64412     u8 *data;         /* The content of the whole page */
 64052  64413     u8 *pIns;         /* The point in pPage->aCellIdx[] where no cell inserted */
 64053  64414   
 64054         -  if( *pRC ) return;
 64055         -
        64415  +  assert( *pRC==SQLITE_OK );
 64056  64416     assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
 64057  64417     assert( MX_CELL(pPage->pBt)<=10921 );
 64058  64418     assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB );
 64059  64419     assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) );
 64060  64420     assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) );
 64061  64421     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 64062  64422     /* The cell should normally be sized correctly.  However, when moving a
................................................................................
 64554  64914       pCell = findCell(pPage, pPage->nCell-1);
 64555  64915       pStop = &pCell[9];
 64556  64916       while( (*(pCell++)&0x80) && pCell<pStop );
 64557  64917       pStop = &pCell[9];
 64558  64918       while( ((*(pOut++) = *(pCell++))&0x80) && pCell<pStop );
 64559  64919   
 64560  64920       /* Insert the new divider cell into pParent. */
 64561         -    insertCell(pParent, pParent->nCell, pSpace, (int)(pOut-pSpace),
 64562         -               0, pPage->pgno, &rc);
        64921  +    if( rc==SQLITE_OK ){
        64922  +      insertCell(pParent, pParent->nCell, pSpace, (int)(pOut-pSpace),
        64923  +                   0, pPage->pgno, &rc);
        64924  +    }
 64563  64925   
 64564  64926       /* Set the right-child pointer of pParent to point to the new page. */
 64565  64927       put4byte(&pParent->aData[pParent->hdrOffset+8], pgnoNew);
 64566  64928     
 64567  64929       /* Release the reference to the new page. */
 64568  64930       releasePage(pNew);
 64569  64931     }
................................................................................
 65075  65437       d = r + 1 - leafData;
 65076  65438       (void)cachedCellSize(&b, d);
 65077  65439       do{
 65078  65440         assert( d<nMaxCells );
 65079  65441         assert( r<nMaxCells );
 65080  65442         (void)cachedCellSize(&b, r);
 65081  65443         if( szRight!=0
 65082         -       && (bBulk || szRight+b.szCell[d]+2 > szLeft-(b.szCell[r]+2)) ){
        65444  +       && (bBulk || szRight+b.szCell[d]+2 > szLeft-(b.szCell[r]+(i==k-1?0:2)))){
 65083  65445           break;
 65084  65446         }
 65085  65447         szRight += b.szCell[d] + 2;
 65086  65448         szLeft -= b.szCell[r] + 2;
 65087  65449         cntNew[i-1] = r;
 65088  65450         r--;
 65089  65451         d--;
................................................................................
 65647  66009       sqlite3PageFree(pFree);
 65648  66010     }
 65649  66011     return rc;
 65650  66012   }
 65651  66013   
 65652  66014   
 65653  66015   /*
 65654         -** Insert a new record into the BTree.  The key is given by (pKey,nKey)
 65655         -** and the data is given by (pData,nData).  The cursor is used only to
 65656         -** define what table the record should be inserted into.  The cursor
 65657         -** is left pointing at a random location.
        66016  +** Insert a new record into the BTree.  The content of the new record
        66017  +** is described by the pX object.  The pCur cursor is used only to
        66018  +** define what table the record should be inserted into, and is left
        66019  +** pointing at a random location.
 65658  66020   **
 65659         -** For an INTKEY table, only the nKey value of the key is used.  pKey is
 65660         -** ignored.  For a ZERODATA table, the pData and nData are both ignored.
        66021  +** For a table btree (used for rowid tables), only the pX.nKey value of
        66022  +** the key is used. The pX.pKey value must be NULL.  The pX.nKey is the
        66023  +** rowid or INTEGER PRIMARY KEY of the row.  The pX.nData,pData,nZero fields
        66024  +** hold the content of the row.
        66025  +**
        66026  +** For an index btree (used for indexes and WITHOUT ROWID tables), the
        66027  +** key is an arbitrary byte sequence stored in pX.pKey,nKey.  The 
        66028  +** pX.pData,nData,nZero fields must be zero.
 65661  66029   **
 65662  66030   ** If the seekResult parameter is non-zero, then a successful call to
 65663  66031   ** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
 65664  66032   ** been performed. seekResult is the search result returned (a negative
 65665  66033   ** number if pCur points at an entry that is smaller than (pKey, nKey), or
 65666  66034   ** a positive value if pCur points at an entry that is larger than 
 65667  66035   ** (pKey, nKey)). 
................................................................................
 65670  66038   ** cursor pCur is pointing at the existing copy of a row that is to be
 65671  66039   ** overwritten.  If the seekResult parameter is 0, then cursor pCur may
 65672  66040   ** point to any entry or to no entry at all and so this function has to seek
 65673  66041   ** the cursor before the new key can be inserted.
 65674  66042   */
 65675  66043   SQLITE_PRIVATE int sqlite3BtreeInsert(
 65676  66044     BtCursor *pCur,                /* Insert data into the table of this cursor */
 65677         -  const void *pKey, i64 nKey,    /* The key of the new record */
 65678         -  const void *pData, int nData,  /* The data of the new record */
 65679         -  int nZero,                     /* Number of extra 0 bytes to append to data */
        66045  +  const BtreePayload *pX,        /* Content of the row to be inserted */
 65680  66046     int appendBias,                /* True if this is likely an append */
 65681  66047     int seekResult                 /* Result of prior MovetoUnpacked() call */
 65682  66048   ){
 65683  66049     int rc;
 65684  66050     int loc = seekResult;          /* -1: before desired location  +1: after */
 65685  66051     int szNew = 0;
 65686  66052     int idx;
................................................................................
 65702  66068     assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
 65703  66069   
 65704  66070     /* Assert that the caller has been consistent. If this cursor was opened
 65705  66071     ** expecting an index b-tree, then the caller should be inserting blob
 65706  66072     ** keys with no associated data. If the cursor was opened expecting an
 65707  66073     ** intkey table, the caller should be inserting integer keys with a
 65708  66074     ** blob of associated data.  */
 65709         -  assert( (pKey==0)==(pCur->pKeyInfo==0) );
        66075  +  assert( (pX->pKey==0)==(pCur->pKeyInfo==0) );
 65710  66076   
 65711  66077     /* Save the positions of any other cursors open on this table.
 65712  66078     **
 65713  66079     ** In some cases, the call to btreeMoveto() below is a no-op. For
 65714  66080     ** example, when inserting data into a table with auto-generated integer
 65715  66081     ** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the 
 65716  66082     ** integer key to use. It then calls this function to actually insert the 
................................................................................
 65721  66087     */
 65722  66088     if( pCur->curFlags & BTCF_Multiple ){
 65723  66089       rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
 65724  66090       if( rc ) return rc;
 65725  66091     }
 65726  66092   
 65727  66093     if( pCur->pKeyInfo==0 ){
 65728         -    assert( pKey==0 );
        66094  +    assert( pX->pKey==0 );
 65729  66095       /* If this is an insert into a table b-tree, invalidate any incrblob 
 65730  66096       ** cursors open on the row being replaced */
 65731         -    invalidateIncrblobCursors(p, nKey, 0);
        66097  +    invalidateIncrblobCursors(p, pX->nKey, 0);
 65732  66098   
 65733  66099       /* If the cursor is currently on the last row and we are appending a
 65734  66100       ** new row onto the end, set the "loc" to avoid an unnecessary
 65735  66101       ** btreeMoveto() call */
 65736         -    if( (pCur->curFlags&BTCF_ValidNKey)!=0 && nKey>0
 65737         -      && pCur->info.nKey==nKey-1 ){
        66102  +    if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
        66103  +      && pCur->info.nKey==pX->nKey-1 ){
 65738  66104          loc = -1;
 65739  66105       }else if( loc==0 ){
 65740         -      rc = sqlite3BtreeMovetoUnpacked(pCur, 0, nKey, appendBias, &loc);
        66106  +      rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, appendBias, &loc);
 65741  66107         if( rc ) return rc;
 65742  66108       }
 65743  66109     }else if( loc==0 ){
 65744         -    rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
        66110  +    rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
 65745  66111       if( rc ) return rc;
 65746  66112     }
 65747  66113     assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
 65748  66114   
 65749  66115     pPage = pCur->apPage[pCur->iPage];
 65750         -  assert( pPage->intKey || nKey>=0 );
        66116  +  assert( pPage->intKey || pX->nKey>=0 );
 65751  66117     assert( pPage->leaf || !pPage->intKey );
 65752  66118   
 65753  66119     TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
 65754         -          pCur->pgnoRoot, nKey, nData, pPage->pgno,
        66120  +          pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
 65755  66121             loc==0 ? "overwrite" : "new entry"));
 65756  66122     assert( pPage->isInit );
 65757  66123     newCell = pBt->pTmpSpace;
 65758  66124     assert( newCell!=0 );
 65759         -  rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
        66125  +  rc = fillInCell(pPage, newCell, pX, &szNew);
 65760  66126     if( rc ) goto end_insert;
 65761  66127     assert( szNew==pPage->xCellSize(pPage, newCell) );
 65762  66128     assert( szNew <= MX_CELL_SIZE(pBt) );
 65763  66129     idx = pCur->aiIdx[pCur->iPage];
 65764  66130     if( loc==0 ){
 65765  66131       u16 szOld;
 65766  66132       assert( idx<pPage->nCell );
................................................................................
 65778  66144     }else if( loc<0 && pPage->nCell>0 ){
 65779  66145       assert( pPage->leaf );
 65780  66146       idx = ++pCur->aiIdx[pCur->iPage];
 65781  66147     }else{
 65782  66148       assert( pPage->leaf );
 65783  66149     }
 65784  66150     insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
        66151  +  assert( pPage->nOverflow==0 || rc==SQLITE_OK );
 65785  66152     assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
 65786  66153   
 65787  66154     /* If no error has occurred and pPage has an overflow cell, call balance() 
 65788  66155     ** to redistribute the cells within the tree. Since balance() may move
 65789  66156     ** the cursor, zero the BtCursor.info.nSize and BTCF_ValidNKey
 65790  66157     ** variables.
 65791  66158     **
................................................................................
 65801  66168     ** is advantageous to leave the cursor pointing to the last entry in
 65802  66169     ** the b-tree if possible. If the cursor is left pointing to the last
 65803  66170     ** entry in the table, and the next row inserted has an integer key
 65804  66171     ** larger than the largest existing key, it is possible to insert the
 65805  66172     ** row without seeking the cursor. This can be a big performance boost.
 65806  66173     */
 65807  66174     pCur->info.nSize = 0;
 65808         -  if( rc==SQLITE_OK && pPage->nOverflow ){
        66175  +  if( pPage->nOverflow ){
        66176  +    assert( rc==SQLITE_OK );
 65809  66177       pCur->curFlags &= ~(BTCF_ValidNKey);
 65810  66178       rc = balance(pCur);
 65811  66179   
 65812  66180       /* Must make sure nOverflow is reset to zero even if the balance()
 65813  66181       ** fails. Internal data structure corruption will result otherwise. 
 65814  66182       ** Also, set the cursor state to invalid. This stops saveCursorPosition()
 65815  66183       ** from trying to save the current position of the cursor.  */
................................................................................
 65937  66305       pCell = findCell(pLeaf, pLeaf->nCell-1);
 65938  66306       if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT;
 65939  66307       nCell = pLeaf->xCellSize(pLeaf, pCell);
 65940  66308       assert( MX_CELL_SIZE(pBt) >= nCell );
 65941  66309       pTmp = pBt->pTmpSpace;
 65942  66310       assert( pTmp!=0 );
 65943  66311       rc = sqlite3PagerWrite(pLeaf->pDbPage);
 65944         -    insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n, &rc);
        66312  +    if( rc==SQLITE_OK ){
        66313  +      insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n, &rc);
        66314  +    }
 65945  66315       dropCell(pLeaf, pLeaf->nCell-1, nCell, &rc);
 65946  66316       if( rc ) return rc;
 65947  66317     }
 65948  66318   
 65949  66319     /* Balance the tree. If the entry deleted was located on a leaf page,
 65950  66320     ** then the cursor still points to that page. In this case the first
 65951  66321     ** call to balance() repairs the tree, and the if(...) condition is
................................................................................
 67426  67796   #if !defined(SQLITE_OMIT_SHARED_CACHE)
 67427  67797   /*
 67428  67798   ** Return true if the Btree passed as the only argument is sharable.
 67429  67799   */
 67430  67800   SQLITE_PRIVATE int sqlite3BtreeSharable(Btree *p){
 67431  67801     return p->sharable;
 67432  67802   }
        67803  +
        67804  +/*
        67805  +** Return the number of connections to the BtShared object accessed by
        67806  +** the Btree handle passed as the only argument. For private caches 
        67807  +** this is always 1. For shared caches it may be 1 or greater.
        67808  +*/
        67809  +SQLITE_PRIVATE int sqlite3BtreeConnectionCount(Btree *p){
        67810  +  testcase( p->sharable );
        67811  +  return p->pBt->nRef;
        67812  +}
 67433  67813   #endif
 67434  67814   
 67435  67815   /************** End of btree.c ***********************************************/
 67436  67816   /************** Begin file backup.c ******************************************/
 67437  67817   /*
 67438  67818   ** 2009 January 28
 67439  67819   **
................................................................................
 67576  67956   ** Create an sqlite3_backup process to copy the contents of zSrcDb from
 67577  67957   ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
 67578  67958   ** a pointer to the new sqlite3_backup object.
 67579  67959   **
 67580  67960   ** If an error occurs, NULL is returned and an error code and error message
 67581  67961   ** stored in database handle pDestDb.
 67582  67962   */
 67583         -SQLITE_API sqlite3_backup *SQLITE_STDCALL sqlite3_backup_init(
        67963  +SQLITE_API sqlite3_backup *SQLITE_APICALL sqlite3_backup_init(
 67584  67964     sqlite3* pDestDb,                     /* Database to write to */
 67585  67965     const char *zDestDb,                  /* Name of database within pDestDb */
 67586  67966     sqlite3* pSrcDb,                      /* Database connection to read from */
 67587  67967     const char *zSrcDb                    /* Name of database within pSrcDb */
 67588  67968   ){
 67589  67969     sqlite3_backup *p;                    /* Value to return */
 67590  67970   
................................................................................
 67784  68164     *pp = p;
 67785  68165     p->isAttached = 1;
 67786  68166   }
 67787  68167   
 67788  68168   /*
 67789  68169   ** Copy nPage pages from the source b-tree to the destination.
 67790  68170   */
 67791         -SQLITE_API int SQLITE_STDCALL sqlite3_backup_step(sqlite3_backup *p, int nPage){
        68171  +SQLITE_API int SQLITE_APICALL sqlite3_backup_step(sqlite3_backup *p, int nPage){
 67792  68172     int rc;
 67793  68173     int destMode;       /* Destination journal mode */
 67794  68174     int pgszSrc = 0;    /* Source page size */
 67795  68175     int pgszDest = 0;   /* Destination page size */
 67796  68176   
 67797  68177   #ifdef SQLITE_ENABLE_API_ARMOR
 67798  68178     if( p==0 ) return SQLITE_MISUSE_BKPT;
................................................................................
 68028  68408     sqlite3_mutex_leave(p->pSrcDb->mutex);
 68029  68409     return rc;
 68030  68410   }
 68031  68411   
 68032  68412   /*
 68033  68413   ** Release all resources associated with an sqlite3_backup* handle.
 68034  68414   */
 68035         -SQLITE_API int SQLITE_STDCALL sqlite3_backup_finish(sqlite3_backup *p){
        68415  +SQLITE_API int SQLITE_APICALL sqlite3_backup_finish(sqlite3_backup *p){
 68036  68416     sqlite3_backup **pp;                 /* Ptr to head of pagers backup list */
 68037  68417     sqlite3 *pSrcDb;                     /* Source database connection */
 68038  68418     int rc;                              /* Value to return */
 68039  68419   
 68040  68420     /* Enter the mutexes */
 68041  68421     if( p==0 ) return SQLITE_OK;
 68042  68422     pSrcDb = p->pSrcDb;
................................................................................
 68080  68460     return rc;
 68081  68461   }
 68082  68462   
 68083  68463   /*
 68084  68464   ** Return the number of pages still to be backed up as of the most recent
 68085  68465   ** call to sqlite3_backup_step().
 68086  68466   */
 68087         -SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p){
        68467  +SQLITE_API int SQLITE_APICALL sqlite3_backup_remaining(sqlite3_backup *p){
 68088  68468   #ifdef SQLITE_ENABLE_API_ARMOR
 68089  68469     if( p==0 ){
 68090  68470       (void)SQLITE_MISUSE_BKPT;
 68091  68471       return 0;
 68092  68472     }
 68093  68473   #endif
 68094  68474     return p->nRemaining;
 68095  68475   }
 68096  68476   
 68097  68477   /*
 68098  68478   ** Return the total number of pages in the source database as of the most 
 68099  68479   ** recent call to sqlite3_backup_step().
 68100  68480   */
 68101         -SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p){
        68481  +SQLITE_API int SQLITE_APICALL sqlite3_backup_pagecount(sqlite3_backup *p){
 68102  68482   #ifdef SQLITE_ENABLE_API_ARMOR
 68103  68483     if( p==0 ){
 68104  68484       (void)SQLITE_MISUSE_BKPT;
 68105  68485       return 0;
 68106  68486     }
 68107  68487   #endif
 68108  68488     return p->nPagecount;
................................................................................
 68216  68596     ** or an error code.
 68217  68597     */
 68218  68598     sqlite3_backup_step(&b, 0x7FFFFFFF);
 68219  68599     assert( b.rc!=SQLITE_OK );
 68220  68600     rc = sqlite3_backup_finish(&b);
 68221  68601     if( rc==SQLITE_OK ){
 68222  68602       pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
 68223         -  }else{
 68224         -    sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
 68225  68603     }
 68226  68604   
 68227  68605     assert( sqlite3BtreeIsInTrans(pTo)==0 );
 68228  68606   copy_finished:
 68229  68607     sqlite3BtreeLeave(pFrom);
 68230  68608     sqlite3BtreeLeave(pTo);
 68231  68609     return rc;
................................................................................
 69223  69601   
 69224  69602     assert( sqlite3BtreeCursorIsValid(pCur) );
 69225  69603     assert( !VdbeMemDynamic(pMem) );
 69226  69604   
 69227  69605     /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert() 
 69228  69606     ** that both the BtShared and database handle mutexes are held. */
 69229  69607     assert( (pMem->flags & MEM_RowSet)==0 );
 69230         -  if( key ){
 69231         -    zData = (char *)sqlite3BtreeKeyFetch(pCur, &available);
 69232         -  }else{
 69233         -    zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
 69234         -  }
        69608  +  zData = (char *)sqlite3BtreePayloadFetch(pCur, &available);
 69235  69609     assert( zData!=0 );
 69236  69610   
 69237  69611     if( offset+amt<=available ){
 69238  69612       pMem->z = &zData[offset];
 69239  69613       pMem->flags = MEM_Blob|MEM_Ephem;
 69240  69614       pMem->n = (int)amt;
 69241  69615     }else{
................................................................................
 70007  70381     if( !isPrepareV2 ) return;
 70008  70382   #endif
 70009  70383     assert( p->zSql==0 );
 70010  70384     p->zSql = sqlite3DbStrNDup(p->db, z, n);
 70011  70385     p->isPrepareV2 = (u8)isPrepareV2;
 70012  70386   }
 70013  70387   
 70014         -/*
 70015         -** Return the SQL associated with a prepared statement
 70016         -*/
 70017         -SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt){
 70018         -  Vdbe *p = (Vdbe *)pStmt;
 70019         -  return p ? p->zSql : 0;
 70020         -}
 70021         -
 70022  70388   /*
 70023  70389   ** Swap all content between two VDBE structures.
 70024  70390   */
 70025  70391   SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
 70026  70392     Vdbe tmp, *pTmp;
 70027  70393     char *zTmp;
 70028  70394     assert( pA->db==pB->db );
................................................................................
 70734  71100   
 70735  71101   
 70736  71102   /*
 70737  71103   ** If the input FuncDef structure is ephemeral, then free it.  If
 70738  71104   ** the FuncDef is not ephermal, then do nothing.
 70739  71105   */
 70740  71106   static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
 70741         -  if( ALWAYS(pDef) && (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
        71107  +  if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
 70742  71108       sqlite3DbFree(db, pDef);
 70743  71109     }
 70744  71110   }
 70745  71111   
 70746  71112   static void vdbeFreeOpArray(sqlite3 *, Op *, int);
 70747  71113   
 70748  71114   /*
 70749  71115   ** Delete a P4 value if necessary.
 70750  71116   */
        71117  +static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
        71118  +  if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
        71119  +  sqlite3DbFree(db, p);
        71120  +}
        71121  +static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
        71122  +  freeEphemeralFunction(db, p->pFunc);
        71123  +  sqlite3DbFree(db, p);
        71124  +}
 70751  71125   static void freeP4(sqlite3 *db, int p4type, void *p4){
 70752  71126     assert( db );
 70753  71127     switch( p4type ){
 70754  71128       case P4_FUNCCTX: {
 70755         -      freeEphemeralFunction(db, ((sqlite3_context*)p4)->pFunc);
 70756         -      /* Fall through into the next case */
        71129  +      freeP4FuncCtx(db, (sqlite3_context*)p4);
        71130  +      break;
 70757  71131       }
 70758  71132       case P4_REAL:
 70759  71133       case P4_INT64:
 70760  71134       case P4_DYNAMIC:
 70761  71135       case P4_INTARRAY: {
 70762  71136         sqlite3DbFree(db, p4);
 70763  71137         break;
................................................................................
 70780  71154         freeEphemeralFunction(db, (FuncDef*)p4);
 70781  71155         break;
 70782  71156       }
 70783  71157       case P4_MEM: {
 70784  71158         if( db->pnBytesFreed==0 ){
 70785  71159           sqlite3ValueFree((sqlite3_value*)p4);
 70786  71160         }else{
 70787         -        Mem *p = (Mem*)p4;
 70788         -        if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
 70789         -        sqlite3DbFree(db, p);
        71161  +        freeP4Mem(db, (Mem*)p4);
 70790  71162         }
 70791  71163         break;
 70792  71164       }
 70793  71165       case P4_VTAB : {
 70794  71166         if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
 70795  71167         break;
 70796  71168       }
................................................................................
 74252  74624   
 74253  74625     /* Get the size of the index entry.  Only indices entries of less
 74254  74626     ** than 2GiB are support - anything large must be database corruption.
 74255  74627     ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
 74256  74628     ** this code can safely assume that nCellKey is 32-bits  
 74257  74629     */
 74258  74630     assert( sqlite3BtreeCursorIsValid(pCur) );
 74259         -  VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
 74260         -  assert( rc==SQLITE_OK );     /* pCur is always valid so KeySize cannot fail */
        74631  +  nCellKey = sqlite3BtreePayloadSize(pCur);
 74261  74632     assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
 74262  74633   
 74263  74634     /* Read in the complete content of the index entry */
 74264  74635     sqlite3VdbeMemInit(&m, db, 0);
 74265  74636     rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
 74266  74637     if( rc ){
 74267  74638       return rc;
................................................................................
 74330  74701     int rc;
 74331  74702     BtCursor *pCur;
 74332  74703     Mem m;
 74333  74704   
 74334  74705     assert( pC->eCurType==CURTYPE_BTREE );
 74335  74706     pCur = pC->uc.pCursor;
 74336  74707     assert( sqlite3BtreeCursorIsValid(pCur) );
 74337         -  VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
 74338         -  assert( rc==SQLITE_OK );    /* pCur is always valid so KeySize cannot fail */
        74708  +  nCellKey = sqlite3BtreePayloadSize(pCur);
 74339  74709     /* nCellKey will always be between 0 and 0xffffffff because of the way
 74340  74710     ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
 74341  74711     if( nCellKey<=0 || nCellKey>0x7fffffff ){
 74342  74712       *res = 0;
 74343  74713       return SQLITE_CORRUPT_BKPT;
 74344  74714     }
 74345  74715     sqlite3VdbeMemInit(&m, db, 0);
................................................................................
 74558  74928   ** Return TRUE (non-zero) of the statement supplied as an argument needs
 74559  74929   ** to be recompiled.  A statement needs to be recompiled whenever the
 74560  74930   ** execution environment changes in a way that would alter the program
 74561  74931   ** that sqlite3_prepare() generates.  For example, if new functions or
 74562  74932   ** collating sequences are registered or if an authorizer function is
 74563  74933   ** added or changed.
 74564  74934   */
 74565         -SQLITE_API int SQLITE_STDCALL sqlite3_expired(sqlite3_stmt *pStmt){
        74935  +SQLITE_API int SQLITE_APICALL sqlite3_expired(sqlite3_stmt *pStmt){
 74566  74936     Vdbe *p = (Vdbe*)pStmt;
 74567  74937     return p==0 || p->expired;
 74568  74938   }
 74569  74939   #endif
 74570  74940   
 74571  74941   /*
 74572  74942   ** Check on a Vdbe to make sure it has not been finalized.  Log
................................................................................
 74593  74963   #ifndef SQLITE_OMIT_TRACE
 74594  74964   /*
 74595  74965   ** Invoke the profile callback.  This routine is only called if we already
 74596  74966   ** know that the profile callback is defined and needs to be invoked.
 74597  74967   */
 74598  74968   static SQLITE_NOINLINE void invokeProfileCallback(sqlite3 *db, Vdbe *p){
 74599  74969     sqlite3_int64 iNow;
        74970  +  sqlite3_int64 iElapse;
 74600  74971     assert( p->startTime>0 );
 74601         -  assert( db->xProfile!=0 );
        74972  +  assert( db->xProfile!=0 || (db->mTrace & SQLITE_TRACE_PROFILE)!=0 );
 74602  74973     assert( db->init.busy==0 );
 74603  74974     assert( p->zSql!=0 );
 74604  74975     sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
 74605         -  db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
        74976  +  iElapse = (iNow - p->startTime)*1000000;
        74977  +  if( db->xProfile ){
        74978  +    db->xProfile(db->pProfileArg, p->zSql, iElapse);
        74979  +  }
        74980  +  if( db->mTrace & SQLITE_TRACE_PROFILE ){
        74981  +    db->xTrace(SQLITE_TRACE_PROFILE, db->pTraceArg, p, (void*)&iElapse);
        74982  +  }
 74606  74983     p->startTime = 0;
 74607  74984   }
 74608  74985   /*
 74609  74986   ** The checkProfileCallback(DB,P) macro checks to see if a profile callback
 74610  74987   ** is needed, and it invokes the callback if it is needed.
 74611  74988   */
 74612  74989   # define checkProfileCallback(DB,P) \
................................................................................
 74620  74997   ** the sqlite3_compile() routine. The integer returned is an SQLITE_
 74621  74998   ** success/failure code that describes the result of executing the virtual
 74622  74999   ** machine.
 74623  75000   **
 74624  75001   ** This routine sets the error code and string returned by
 74625  75002   ** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
 74626  75003   */
 74627         -SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt){
        75004  +SQLITE_API int SQLITE_APICALL sqlite3_finalize(sqlite3_stmt *pStmt){
 74628  75005     int rc;
 74629  75006     if( pStmt==0 ){
 74630  75007       /* IMPLEMENTATION-OF: R-57228-12904 Invoking sqlite3_finalize() on a NULL
 74631  75008       ** pointer is a harmless no-op. */
 74632  75009       rc = SQLITE_OK;
 74633  75010     }else{
 74634  75011       Vdbe *v = (Vdbe*)pStmt;
................................................................................
 74647  75024   ** Terminate the current execution of an SQL statement and reset it
 74648  75025   ** back to its starting state so that it can be reused. A success code from
 74649  75026   ** the prior execution is returned.
 74650  75027   **
 74651  75028   ** This routine sets the error code and string returned by
 74652  75029   ** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
 74653  75030   */
 74654         -SQLITE_API int SQLITE_STDCALL sqlite3_reset(sqlite3_stmt *pStmt){
        75031  +SQLITE_API int SQLITE_APICALL sqlite3_reset(sqlite3_stmt *pStmt){
 74655  75032     int rc;
 74656  75033     if( pStmt==0 ){
 74657  75034       rc = SQLITE_OK;
 74658  75035     }else{
 74659  75036       Vdbe *v = (Vdbe*)pStmt;
 74660  75037       sqlite3 *db = v->db;
 74661  75038       sqlite3_mutex_enter(db->mutex);
................................................................................
 74668  75045     }
 74669  75046     return rc;
 74670  75047   }
 74671  75048   
 74672  75049   /*
 74673  75050   ** Set all the parameters in the compiled SQL statement to NULL.
 74674  75051   */
 74675         -SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt *pStmt){
        75052  +SQLITE_API int SQLITE_APICALL sqlite3_clear_bindings(sqlite3_stmt *pStmt){
 74676  75053     int i;
 74677  75054     int rc = SQLITE_OK;
 74678  75055     Vdbe *p = (Vdbe*)pStmt;
 74679  75056   #if SQLITE_THREADSAFE
 74680  75057     sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
 74681  75058   #endif
 74682  75059     sqlite3_mutex_enter(mutex);
................................................................................
 74692  75069   }
 74693  75070   
 74694  75071   
 74695  75072   /**************************** sqlite3_value_  *******************************
 74696  75073   ** The following routines extract information from a Mem or sqlite3_value
 74697  75074   ** structure.
 74698  75075   */
 74699         -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value *pVal){
        75076  +SQLITE_API const void *SQLITE_APICALL sqlite3_value_blob(sqlite3_value *pVal){
 74700  75077     Mem *p = (Mem*)pVal;
 74701  75078     if( p->flags & (MEM_Blob|MEM_Str) ){
 74702  75079       if( sqlite3VdbeMemExpandBlob(p)!=SQLITE_OK ){
 74703  75080         assert( p->flags==MEM_Null && p->z==0 );
 74704  75081         return 0;
 74705  75082       }
 74706  75083       p->flags |= MEM_Blob;
 74707  75084       return p->n ? p->z : 0;
 74708  75085     }else{
 74709  75086       return sqlite3_value_text(pVal);
 74710  75087     }
 74711  75088   }
 74712         -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes(sqlite3_value *pVal){
        75089  +SQLITE_API int SQLITE_APICALL sqlite3_value_bytes(sqlite3_value *pVal){
 74713  75090     return sqlite3ValueBytes(pVal, SQLITE_UTF8);
 74714  75091   }
 74715         -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes16(sqlite3_value *pVal){
        75092  +SQLITE_API int SQLITE_APICALL sqlite3_value_bytes16(sqlite3_value *pVal){
 74716  75093     return sqlite3ValueBytes(pVal, SQLITE_UTF16NATIVE);
 74717  75094   }
 74718         -SQLITE_API double SQLITE_STDCALL sqlite3_value_double(sqlite3_value *pVal){
        75095  +SQLITE_API double SQLITE_APICALL sqlite3_value_double(sqlite3_value *pVal){
 74719  75096     return sqlite3VdbeRealValue((Mem*)pVal);
 74720  75097   }
 74721         -SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value *pVal){
        75098  +SQLITE_API int SQLITE_APICALL sqlite3_value_int(sqlite3_value *pVal){
 74722  75099     return (int)sqlite3VdbeIntValue((Mem*)pVal);
 74723  75100   }
 74724         -SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value *pVal){
        75101  +SQLITE_API sqlite_int64 SQLITE_APICALL sqlite3_value_int64(sqlite3_value *pVal){
 74725  75102     return sqlite3VdbeIntValue((Mem*)pVal);
 74726  75103   }
 74727         -SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value *pVal){
        75104  +SQLITE_API unsigned int SQLITE_APICALL sqlite3_value_subtype(sqlite3_value *pVal){
 74728  75105     Mem *pMem = (Mem*)pVal;
 74729  75106     return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
 74730  75107   }
 74731         -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value *pVal){
        75108  +SQLITE_API const unsigned char *SQLITE_APICALL sqlite3_value_text(sqlite3_value *pVal){
 74732  75109     return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
 74733  75110   }
 74734  75111   #ifndef SQLITE_OMIT_UTF16
 74735         -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16(sqlite3_value* pVal){
        75112  +SQLITE_API const void *SQLITE_APICALL sqlite3_value_text16(sqlite3_value* pVal){
 74736  75113     return sqlite3ValueText(pVal, SQLITE_UTF16NATIVE);
 74737  75114   }
 74738         -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value *pVal){
        75115  +SQLITE_API const void *SQLITE_APICALL sqlite3_value_text16be(sqlite3_value *pVal){
 74739  75116     return sqlite3ValueText(pVal, SQLITE_UTF16BE);
 74740  75117   }
 74741         -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value *pVal){
        75118  +SQLITE_API const void *SQLITE_APICALL sqlite3_value_text16le(sqlite3_value *pVal){
 74742  75119     return sqlite3ValueText(pVal, SQLITE_UTF16LE);
 74743  75120   }
 74744  75121   #endif /* SQLITE_OMIT_UTF16 */
 74745  75122   /* EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five
 74746  75123   ** fundamental datatypes: 64-bit signed integer 64-bit IEEE floating
 74747  75124   ** point number string BLOB NULL
 74748  75125   */
 74749         -SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value* pVal){
        75126  +SQLITE_API int SQLITE_APICALL sqlite3_value_type(sqlite3_value* pVal){
 74750  75127     static const u8 aType[] = {
 74751  75128        SQLITE_BLOB,     /* 0x00 */
 74752  75129        SQLITE_NULL,     /* 0x01 */
 74753  75130        SQLITE_TEXT,     /* 0x02 */
 74754  75131        SQLITE_NULL,     /* 0x03 */
 74755  75132        SQLITE_INTEGER,  /* 0x04 */
 74756  75133        SQLITE_NULL,     /* 0x05 */
................................................................................
 74782  75159        SQLITE_NULL,     /* 0x1f */
 74783  75160     };
 74784  75161     return aType[pVal->flags&MEM_AffMask];
 74785  75162   }
 74786  75163   
 74787  75164   /* Make a copy of an sqlite3_value object
 74788  75165   */
 74789         -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_value_dup(const sqlite3_value *pOrig){
        75166  +SQLITE_API sqlite3_value *SQLITE_APICALL sqlite3_value_dup(const sqlite3_value *pOrig){
 74790  75167     sqlite3_value *pNew;
 74791  75168     if( pOrig==0 ) return 0;
 74792  75169     pNew = sqlite3_malloc( sizeof(*pNew) );
 74793  75170     if( pNew==0 ) return 0;
 74794  75171     memset(pNew, 0, sizeof(*pNew));
 74795  75172     memcpy(pNew, pOrig, MEMCELLSIZE);
 74796  75173     pNew->flags &= ~MEM_Dyn;
................................................................................
 74805  75182     }
 74806  75183     return pNew;
 74807  75184   }
 74808  75185   
 74809  75186   /* Destroy an sqlite3_value object previously obtained from
 74810  75187   ** sqlite3_value_dup().
 74811  75188   */
 74812         -SQLITE_API void SQLITE_STDCALL sqlite3_value_free(sqlite3_value *pOld){
        75189  +SQLITE_API void SQLITE_APICALL sqlite3_value_free(sqlite3_value *pOld){
 74813  75190     sqlite3ValueFree(pOld);
 74814  75191   }
 74815  75192     
 74816  75193   
 74817  75194   /**************************** sqlite3_result_  *******************************
 74818  75195   ** The following routines are used by user-defined functions to specify
 74819  75196   ** the function result.
................................................................................
 74848  75225       /* noop */
 74849  75226     }else{
 74850  75227       xDel((void*)p);
 74851  75228     }
 74852  75229     if( pCtx ) sqlite3_result_error_toobig(pCtx);
 74853  75230     return SQLITE_TOOBIG;
 74854  75231   }
 74855         -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob(
        75232  +SQLITE_API void SQLITE_APICALL sqlite3_result_blob(
 74856  75233     sqlite3_context *pCtx, 
 74857  75234     const void *z, 
 74858  75235     int n, 
 74859  75236     void (*xDel)(void *)
 74860  75237   ){
 74861  75238     assert( n>=0 );
 74862  75239     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74863  75240     setResultStrOrError(pCtx, z, n, 0, xDel);
 74864  75241   }
 74865         -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob64(
        75242  +SQLITE_API void SQLITE_APICALL sqlite3_result_blob64(
 74866  75243     sqlite3_context *pCtx, 
 74867  75244     const void *z, 
 74868  75245     sqlite3_uint64 n,
 74869  75246     void (*xDel)(void *)
 74870  75247   ){
 74871  75248     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74872  75249     assert( xDel!=SQLITE_DYNAMIC );
 74873  75250     if( n>0x7fffffff ){
 74874  75251       (void)invokeValueDestructor(z, xDel, pCtx);
 74875  75252     }else{
 74876  75253       setResultStrOrError(pCtx, z, (int)n, 0, xDel);
 74877  75254     }
 74878  75255   }
 74879         -SQLITE_API void SQLITE_STDCALL sqlite3_result_double(sqlite3_context *pCtx, double rVal){
        75256  +SQLITE_API void SQLITE_APICALL sqlite3_result_double(sqlite3_context *pCtx, double rVal){
 74880  75257     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74881  75258     sqlite3VdbeMemSetDouble(pCtx->pOut, rVal);
 74882  75259   }
 74883         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
        75260  +SQLITE_API void SQLITE_APICALL sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
 74884  75261     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74885  75262     pCtx->isError = SQLITE_ERROR;
 74886  75263     pCtx->fErrorOrAux = 1;
 74887  75264     sqlite3VdbeMemSetStr(pCtx->pOut, z, n, SQLITE_UTF8, SQLITE_TRANSIENT);
 74888  75265   }
 74889  75266   #ifndef SQLITE_OMIT_UTF16
 74890         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
        75267  +SQLITE_API void SQLITE_APICALL sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
 74891  75268     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74892  75269     pCtx->isError = SQLITE_ERROR;
 74893  75270     pCtx->fErrorOrAux = 1;
 74894  75271     sqlite3VdbeMemSetStr(pCtx->pOut, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT);
 74895  75272   }
 74896  75273   #endif
 74897         -SQLITE_API void SQLITE_STDCALL sqlite3_result_int(sqlite3_context *pCtx, int iVal){
        75274  +SQLITE_API void SQLITE_APICALL sqlite3_result_int(sqlite3_context *pCtx, int iVal){
 74898  75275     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74899  75276     sqlite3VdbeMemSetInt64(pCtx->pOut, (i64)iVal);
 74900  75277   }
 74901         -SQLITE_API void SQLITE_STDCALL sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){
        75278  +SQLITE_API void SQLITE_APICALL sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){
 74902  75279     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74903  75280     sqlite3VdbeMemSetInt64(pCtx->pOut, iVal);
 74904  75281   }
 74905         -SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context *pCtx){
        75282  +SQLITE_API void SQLITE_APICALL sqlite3_result_null(sqlite3_context *pCtx){
 74906  75283     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74907  75284     sqlite3VdbeMemSetNull(pCtx->pOut);
 74908  75285   }
 74909         -SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context *pCtx, unsigned int eSubtype){
        75286  +SQLITE_API void SQLITE_APICALL sqlite3_result_subtype(sqlite3_context *pCtx, unsigned int eSubtype){
 74910  75287     Mem *pOut = pCtx->pOut;
 74911  75288     assert( sqlite3_mutex_held(pOut->db->mutex) );
 74912  75289     pOut->eSubtype = eSubtype & 0xff;
 74913  75290     pOut->flags |= MEM_Subtype;
 74914  75291   }
 74915         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text(
        75292  +SQLITE_API void SQLITE_APICALL sqlite3_result_text(
 74916  75293     sqlite3_context *pCtx, 
 74917  75294     const char *z, 
 74918  75295     int n,
 74919  75296     void (*xDel)(void *)
 74920  75297   ){
 74921  75298     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74922  75299     setResultStrOrError(pCtx, z, n, SQLITE_UTF8, xDel);
 74923  75300   }
 74924         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text64(
        75301  +SQLITE_API void SQLITE_APICALL sqlite3_result_text64(
 74925  75302     sqlite3_context *pCtx, 
 74926  75303     const char *z, 
 74927  75304     sqlite3_uint64 n,
 74928  75305     void (*xDel)(void *),
 74929  75306     unsigned char enc
 74930  75307   ){
 74931  75308     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
................................................................................
 74934  75311     if( n>0x7fffffff ){
 74935  75312       (void)invokeValueDestructor(z, xDel, pCtx);
 74936  75313     }else{
 74937  75314       setResultStrOrError(pCtx, z, (int)n, enc, xDel);
 74938  75315     }
 74939  75316   }
 74940  75317   #ifndef SQLITE_OMIT_UTF16
 74941         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(
        75318  +SQLITE_API void SQLITE_APICALL sqlite3_result_text16(
 74942  75319     sqlite3_context *pCtx, 
 74943  75320     const void *z, 
 74944  75321     int n, 
 74945  75322     void (*xDel)(void *)
 74946  75323   ){
 74947  75324     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74948  75325     setResultStrOrError(pCtx, z, n, SQLITE_UTF16NATIVE, xDel);
 74949  75326   }
 74950         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(
        75327  +SQLITE_API void SQLITE_APICALL sqlite3_result_text16be(
 74951  75328     sqlite3_context *pCtx, 
 74952  75329     const void *z, 
 74953  75330     int n, 
 74954  75331     void (*xDel)(void *)
 74955  75332   ){
 74956  75333     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74957  75334     setResultStrOrError(pCtx, z, n, SQLITE_UTF16BE, xDel);
 74958  75335   }
 74959         -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(
        75336  +SQLITE_API void SQLITE_APICALL sqlite3_result_text16le(
 74960  75337     sqlite3_context *pCtx, 
 74961  75338     const void *z, 
 74962  75339     int n, 
 74963  75340     void (*xDel)(void *)
 74964  75341   ){
 74965  75342     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74966  75343     setResultStrOrError(pCtx, z, n, SQLITE_UTF16LE, xDel);
 74967  75344   }
 74968  75345   #endif /* SQLITE_OMIT_UTF16 */
 74969         -SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
        75346  +SQLITE_API void SQLITE_APICALL sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
 74970  75347     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74971  75348     sqlite3VdbeMemCopy(pCtx->pOut, pValue);
 74972  75349   }
 74973         -SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
        75350  +SQLITE_API void SQLITE_APICALL sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
 74974  75351     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 74975  75352     sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
 74976  75353   }
 74977         -SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){
        75354  +SQLITE_API int SQLITE_APICALL sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){
 74978  75355     Mem *pOut = pCtx->pOut;
 74979  75356     assert( sqlite3_mutex_held(pOut->db->mutex) );
 74980  75357     if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
 74981  75358       return SQLITE_TOOBIG;
 74982  75359     }
 74983  75360     sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n);
 74984  75361     return SQLITE_OK;
 74985  75362   }
 74986         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
        75363  +SQLITE_API void SQLITE_APICALL sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
 74987  75364     pCtx->isError = errCode;
 74988  75365     pCtx->fErrorOrAux = 1;
 74989  75366   #ifdef SQLITE_DEBUG
 74990  75367     if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;
 74991  75368   #endif
 74992  75369     if( pCtx->pOut->flags & MEM_Null ){
 74993  75370       sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1, 
 74994  75371                            SQLITE_UTF8, SQLITE_STATIC);
 74995  75372     }
 74996  75373   }
 74997  75374   
 74998  75375   /* Force an SQLITE_TOOBIG error. */
 74999         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_toobig(sqlite3_context *pCtx){
        75376  +SQLITE_API void SQLITE_APICALL sqlite3_result_error_toobig(sqlite3_context *pCtx){
 75000  75377     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 75001  75378     pCtx->isError = SQLITE_TOOBIG;
 75002  75379     pCtx->fErrorOrAux = 1;
 75003  75380     sqlite3VdbeMemSetStr(pCtx->pOut, "string or blob too big", -1, 
 75004  75381                          SQLITE_UTF8, SQLITE_STATIC);
 75005  75382   }
 75006  75383   
 75007  75384   /* An SQLITE_NOMEM error. */
 75008         -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_nomem(sqlite3_context *pCtx){
        75385  +SQLITE_API void SQLITE_APICALL sqlite3_result_error_nomem(sqlite3_context *pCtx){
 75009  75386     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 75010  75387     sqlite3VdbeMemSetNull(pCtx->pOut);
 75011  75388     pCtx->isError = SQLITE_NOMEM_BKPT;
 75012  75389     pCtx->fErrorOrAux = 1;
 75013  75390     sqlite3OomFault(pCtx->pOut->db);
 75014  75391   }
 75015  75392   
................................................................................
 75102  75479       }
 75103  75480   
 75104  75481       assert( db->nVdbeWrite>0 || db->autoCommit==0 
 75105  75482           || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
 75106  75483       );
 75107  75484   
 75108  75485   #ifndef SQLITE_OMIT_TRACE
 75109         -    if( db->xProfile && !db->init.busy && p->zSql ){
        75486  +    if( (db->xProfile || (db->mTrace & SQLITE_TRACE_PROFILE)!=0)
        75487  +        && !db->init.busy && p->zSql ){
 75110  75488         sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
 75111  75489       }else{
 75112  75490         assert( p->startTime==0 );
 75113  75491       }
 75114  75492   #endif
 75115  75493   
 75116  75494       db->nVdbeActive++;
................................................................................
 75172  75550   }
 75173  75551   
 75174  75552   /*
 75175  75553   ** This is the top-level implementation of sqlite3_step().  Call
 75176  75554   ** sqlite3Step() to do most of the work.  If a schema error occurs,
 75177  75555   ** call sqlite3Reprepare() and try again.
 75178  75556   */
 75179         -SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt *pStmt){
        75557  +SQLITE_API int SQLITE_APICALL sqlite3_step(sqlite3_stmt *pStmt){
 75180  75558     int rc = SQLITE_OK;      /* Result from sqlite3Step() */
 75181  75559     int rc2 = SQLITE_OK;     /* Result from sqlite3Reprepare() */
 75182  75560     Vdbe *v = (Vdbe*)pStmt;  /* the prepared statement */
 75183  75561     int cnt = 0;             /* Counter to prevent infinite loop of reprepares */
 75184  75562     sqlite3 *db;             /* The database connection */
 75185  75563   
 75186  75564     if( vdbeSafetyNotNull(v) ){
................................................................................
 75223  75601   }
 75224  75602   
 75225  75603   
 75226  75604   /*
 75227  75605   ** Extract the user data from a sqlite3_context structure and return a
 75228  75606   ** pointer to it.
 75229  75607   */
 75230         -SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context *p){
        75608  +SQLITE_API void *SQLITE_APICALL sqlite3_user_data(sqlite3_context *p){
 75231  75609     assert( p && p->pFunc );
 75232  75610     return p->pFunc->pUserData;
 75233  75611   }
 75234  75612   
 75235  75613   /*
 75236  75614   ** Extract the user data from a sqlite3_context structure and return a
 75237  75615   ** pointer to it.
................................................................................
 75238  75616   **
 75239  75617   ** IMPLEMENTATION-OF: R-46798-50301 The sqlite3_context_db_handle() interface
 75240  75618   ** returns a copy of the pointer to the database connection (the 1st
 75241  75619   ** parameter) of the sqlite3_create_function() and
 75242  75620   ** sqlite3_create_function16() routines that originally registered the
 75243  75621   ** application defined function.
 75244  75622   */
 75245         -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context *p){
        75623  +SQLITE_API sqlite3 *SQLITE_APICALL sqlite3_context_db_handle(sqlite3_context *p){
 75246  75624     assert( p && p->pOut );
 75247  75625     return p->pOut->db;
 75248  75626   }
 75249  75627   
 75250  75628   /*
 75251  75629   ** Return the current time for a statement.  If the current time
 75252  75630   ** is requested more than once within the same run of a single prepared
................................................................................
 75314  75692   }
 75315  75693   
 75316  75694   /*
 75317  75695   ** Allocate or return the aggregate context for a user function.  A new
 75318  75696   ** context is allocated on the first call.  Subsequent calls return the
 75319  75697   ** same context that was returned on prior calls.
 75320  75698   */
 75321         -SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context *p, int nByte){
        75699  +SQLITE_API void *SQLITE_APICALL sqlite3_aggregate_context(sqlite3_context *p, int nByte){
 75322  75700     assert( p && p->pFunc && p->pFunc->xFinalize );
 75323  75701     assert( sqlite3_mutex_held(p->pOut->db->mutex) );
 75324  75702     testcase( nByte<0 );
 75325  75703     if( (p->pMem->flags & MEM_Agg)==0 ){
 75326  75704       return createAggContext(p, nByte);
 75327  75705     }else{
 75328  75706       return (void*)p->pMem->z;
................................................................................
 75329  75707     }
 75330  75708   }
 75331  75709   
 75332  75710   /*
 75333  75711   ** Return the auxiliary data pointer, if any, for the iArg'th argument to
 75334  75712   ** the user-function defined by pCtx.
 75335  75713   */
 75336         -SQLITE_API void *SQLITE_STDCALL sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
        75714  +SQLITE_API void *SQLITE_APICALL sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
 75337  75715     AuxData *pAuxData;
 75338  75716   
 75339  75717     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 75340  75718   #if SQLITE_ENABLE_STAT3_OR_STAT4
 75341  75719     if( pCtx->pVdbe==0 ) return 0;
 75342  75720   #else
 75343  75721     assert( pCtx->pVdbe!=0 );
................................................................................
 75350  75728   }
 75351  75729   
 75352  75730   /*
 75353  75731   ** Set the auxiliary data pointer and delete function, for the iArg'th
 75354  75732   ** argument to the user-function defined by pCtx. Any previous value is
 75355  75733   ** deleted by calling the delete function specified when it was set.
 75356  75734   */
 75357         -SQLITE_API void SQLITE_STDCALL sqlite3_set_auxdata(
        75735  +SQLITE_API void SQLITE_APICALL sqlite3_set_auxdata(
 75358  75736     sqlite3_context *pCtx, 
 75359  75737     int iArg, 
 75360  75738     void *pAux, 
 75361  75739     void (*xDelete)(void*)
 75362  75740   ){
 75363  75741     AuxData *pAuxData;
 75364  75742     Vdbe *pVdbe = pCtx->pVdbe;
................................................................................
 75405  75783   ** called.
 75406  75784   **
 75407  75785   ** This function is deprecated.  Do not use it for new code.  It is
 75408  75786   ** provide only to avoid breaking legacy code.  New aggregate function
 75409  75787   ** implementations should keep their own counts within their aggregate
 75410  75788   ** context.
 75411  75789   */
 75412         -SQLITE_API int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context *p){
        75790  +SQLITE_API int SQLITE_APICALL sqlite3_aggregate_count(sqlite3_context *p){
 75413  75791     assert( p && p->pMem && p->pFunc && p->pFunc->xFinalize );
 75414  75792     return p->pMem->n;
 75415  75793   }
 75416  75794   #endif
 75417  75795   
 75418  75796   /*
 75419  75797   ** Return the number of columns in the result set for the statement pStmt.
 75420  75798   */
 75421         -SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt){
        75799  +SQLITE_API int SQLITE_APICALL sqlite3_column_count(sqlite3_stmt *pStmt){
 75422  75800     Vdbe *pVm = (Vdbe *)pStmt;
 75423  75801     return pVm ? pVm->nResColumn : 0;
 75424  75802   }
 75425  75803   
 75426  75804   /*
 75427  75805   ** Return the number of values available from the current row of the
 75428  75806   ** currently executing statement pStmt.
 75429  75807   */
 75430         -SQLITE_API int SQLITE_STDCALL sqlite3_data_count(sqlite3_stmt *pStmt){
        75808  +SQLITE_API int SQLITE_APICALL sqlite3_data_count(sqlite3_stmt *pStmt){
 75431  75809     Vdbe *pVm = (Vdbe *)pStmt;
 75432  75810     if( pVm==0 || pVm->pResultSet==0 ) return 0;
 75433  75811     return pVm->nResColumn;
 75434  75812   }
 75435  75813   
 75436  75814   /*
 75437  75815   ** Return a pointer to static memory containing an SQL NULL value.
................................................................................
 75526  75904     }
 75527  75905   }
 75528  75906   
 75529  75907   /**************************** sqlite3_column_  *******************************
 75530  75908   ** The following routines are used to access elements of the current row
 75531  75909   ** in the result set.
 75532  75910   */
 75533         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
        75911  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
 75534  75912     const void *val;
 75535  75913     val = sqlite3_value_blob( columnMem(pStmt,i) );
 75536  75914     /* Even though there is no encoding conversion, value_blob() might
 75537  75915     ** need to call malloc() to expand the result of a zeroblob() 
 75538  75916     ** expression. 
 75539  75917     */
 75540  75918     columnMallocFailure(pStmt);
 75541  75919     return val;
 75542  75920   }
 75543         -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
        75921  +SQLITE_API int SQLITE_APICALL sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
 75544  75922     int val = sqlite3_value_bytes( columnMem(pStmt,i) );
 75545  75923     columnMallocFailure(pStmt);
 75546  75924     return val;
 75547  75925   }
 75548         -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
        75926  +SQLITE_API int SQLITE_APICALL sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
 75549  75927     int val = sqlite3_value_bytes16( columnMem(pStmt,i) );
 75550  75928     columnMallocFailure(pStmt);
 75551  75929     return val;
 75552  75930   }
 75553         -SQLITE_API double SQLITE_STDCALL sqlite3_column_double(sqlite3_stmt *pStmt, int i){
        75931  +SQLITE_API double SQLITE_APICALL sqlite3_column_double(sqlite3_stmt *pStmt, int i){
 75554  75932     double val = sqlite3_value_double( columnMem(pStmt,i) );
 75555  75933     columnMallocFailure(pStmt);
 75556  75934     return val;
 75557  75935   }
 75558         -SQLITE_API int SQLITE_STDCALL sqlite3_column_int(sqlite3_stmt *pStmt, int i){
        75936  +SQLITE_API int SQLITE_APICALL sqlite3_column_int(sqlite3_stmt *pStmt, int i){
 75559  75937     int val = sqlite3_value_int( columnMem(pStmt,i) );
 75560  75938     columnMallocFailure(pStmt);
 75561  75939     return val;
 75562  75940   }
 75563         -SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
        75941  +SQLITE_API sqlite_int64 SQLITE_APICALL sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
 75564  75942     sqlite_int64 val = sqlite3_value_int64( columnMem(pStmt,i) );
 75565  75943     columnMallocFailure(pStmt);
 75566  75944     return val;
 75567  75945   }
 75568         -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_column_text(sqlite3_stmt *pStmt, int i){
        75946  +SQLITE_API const unsigned char *SQLITE_APICALL sqlite3_column_text(sqlite3_stmt *pStmt, int i){
 75569  75947     const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
 75570  75948     columnMallocFailure(pStmt);
 75571  75949     return val;
 75572  75950   }
 75573         -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt *pStmt, int i){
        75951  +SQLITE_API sqlite3_value *SQLITE_APICALL sqlite3_column_value(sqlite3_stmt *pStmt, int i){
 75574  75952     Mem *pOut = columnMem(pStmt, i);
 75575  75953     if( pOut->flags&MEM_Static ){
 75576  75954       pOut->flags &= ~MEM_Static;
 75577  75955       pOut->flags |= MEM_Ephem;
 75578  75956     }
 75579  75957     columnMallocFailure(pStmt);
 75580  75958     return (sqlite3_value *)pOut;
 75581  75959   }
 75582  75960   #ifndef SQLITE_OMIT_UTF16
 75583         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
        75961  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
 75584  75962     const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
 75585  75963     columnMallocFailure(pStmt);
 75586  75964     return val;
 75587  75965   }
 75588  75966   #endif /* SQLITE_OMIT_UTF16 */
 75589         -SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt *pStmt, int i){
        75967  +SQLITE_API int SQLITE_APICALL sqlite3_column_type(sqlite3_stmt *pStmt, int i){
 75590  75968     int iType = sqlite3_value_type( columnMem(pStmt,i) );
 75591  75969     columnMallocFailure(pStmt);
 75592  75970     return iType;
 75593  75971   }
 75594  75972   
 75595  75973   /*
 75596  75974   ** Convert the N-th element of pStmt->pColName[] into a string using
................................................................................
 75646  76024     return ret;
 75647  76025   }
 75648  76026   
 75649  76027   /*
 75650  76028   ** Return the name of the Nth column of the result set returned by SQL
 75651  76029   ** statement pStmt.
 75652  76030   */
 75653         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt *pStmt, int N){
        76031  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_name(sqlite3_stmt *pStmt, int N){
 75654  76032     return columnName(
 75655  76033         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
 75656  76034   }
 75657  76035   #ifndef SQLITE_OMIT_UTF16
 75658         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
        76036  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
 75659  76037     return columnName(
 75660  76038         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
 75661  76039   }
 75662  76040   #endif
 75663  76041   
 75664  76042   /*
 75665  76043   ** Constraint:  If you have ENABLE_COLUMN_METADATA then you must
................................................................................
 75671  76049   #endif
 75672  76050   
 75673  76051   #ifndef SQLITE_OMIT_DECLTYPE
 75674  76052   /*
 75675  76053   ** Return the column declaration type (if applicable) of the 'i'th column
 75676  76054   ** of the result set of SQL statement pStmt.
 75677  76055   */
 75678         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
        76056  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
 75679  76057     return columnName(
 75680  76058         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
 75681  76059   }
 75682  76060   #ifndef SQLITE_OMIT_UTF16
 75683         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
        76061  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
 75684  76062     return columnName(
 75685  76063         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
 75686  76064   }
 75687  76065   #endif /* SQLITE_OMIT_UTF16 */
 75688  76066   #endif /* SQLITE_OMIT_DECLTYPE */
 75689  76067   
 75690  76068   #ifdef SQLITE_ENABLE_COLUMN_METADATA
 75691  76069   /*
 75692  76070   ** Return the name of the database from which a result column derives.
 75693  76071   ** NULL is returned if the result column is an expression or constant or
 75694  76072   ** anything else which is not an unambiguous reference to a database column.
 75695  76073   */
 75696         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
        76074  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
 75697  76075     return columnName(
 75698  76076         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
 75699  76077   }
 75700  76078   #ifndef SQLITE_OMIT_UTF16
 75701         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
        76079  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
 75702  76080     return columnName(
 75703  76081         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
 75704  76082   }
 75705  76083   #endif /* SQLITE_OMIT_UTF16 */
 75706  76084   
 75707  76085   /*
 75708  76086   ** Return the name of the table from which a result column derives.
 75709  76087   ** NULL is returned if the result column is an expression or constant or
 75710  76088   ** anything else which is not an unambiguous reference to a database column.
 75711  76089   */
 75712         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
        76090  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
 75713  76091     return columnName(
 75714  76092         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
 75715  76093   }
 75716  76094   #ifndef SQLITE_OMIT_UTF16
 75717         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
        76095  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
 75718  76096     return columnName(
 75719  76097         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
 75720  76098   }
 75721  76099   #endif /* SQLITE_OMIT_UTF16 */
 75722  76100   
 75723  76101   /*
 75724  76102   ** Return the name of the table column from which a result column derives.
 75725  76103   ** NULL is returned if the result column is an expression or constant or
 75726  76104   ** anything else which is not an unambiguous reference to a database column.
 75727  76105   */
 75728         -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
        76106  +SQLITE_API const char *SQLITE_APICALL sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
 75729  76107     return columnName(
 75730  76108         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
 75731  76109   }
 75732  76110   #ifndef SQLITE_OMIT_UTF16
 75733         -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
        76111  +SQLITE_API const void *SQLITE_APICALL sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
 75734  76112     return columnName(
 75735  76113         pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
 75736  76114   }
 75737  76115   #endif /* SQLITE_OMIT_UTF16 */
 75738  76116   #endif /* SQLITE_ENABLE_COLUMN_METADATA */
 75739  76117   
 75740  76118   
................................................................................
 75827  76205     return rc;
 75828  76206   }
 75829  76207   
 75830  76208   
 75831  76209   /*
 75832  76210   ** Bind a blob value to an SQL statement variable.
 75833  76211   */
 75834         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob(
        76212  +SQLITE_API int SQLITE_APICALL sqlite3_bind_blob(
 75835  76213     sqlite3_stmt *pStmt, 
 75836  76214     int i, 
 75837  76215     const void *zData, 
 75838  76216     int nData, 
 75839  76217     void (*xDel)(void*)
 75840  76218   ){
 75841  76219   #ifdef SQLITE_ENABLE_API_ARMOR
 75842  76220     if( nData<0 ) return SQLITE_MISUSE_BKPT;
 75843  76221   #endif
 75844  76222     return bindText(pStmt, i, zData, nData, xDel, 0);
 75845  76223   }
 75846         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob64(
        76224  +SQLITE_API int SQLITE_APICALL sqlite3_bind_blob64(
 75847  76225     sqlite3_stmt *pStmt, 
 75848  76226     int i, 
 75849  76227     const void *zData, 
 75850  76228     sqlite3_uint64 nData, 
 75851  76229     void (*xDel)(void*)
 75852  76230   ){
 75853  76231     assert( xDel!=SQLITE_DYNAMIC );
 75854  76232     if( nData>0x7fffffff ){
 75855  76233       return invokeValueDestructor(zData, xDel, 0);
 75856  76234     }else{
 75857  76235       return bindText(pStmt, i, zData, (int)nData, xDel, 0);
 75858  76236     }
 75859  76237   }
 75860         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
        76238  +SQLITE_API int SQLITE_APICALL sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
 75861  76239     int rc;
 75862  76240     Vdbe *p = (Vdbe *)pStmt;
 75863  76241     rc = vdbeUnbind(p, i);
 75864  76242     if( rc==SQLITE_OK ){
 75865  76243       sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
 75866  76244       sqlite3_mutex_leave(p->db->mutex);
 75867  76245     }
 75868  76246     return rc;
 75869  76247   }
 75870         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
        76248  +SQLITE_API int SQLITE_APICALL sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
 75871  76249     return sqlite3_bind_int64(p, i, (i64)iValue);
 75872  76250   }
 75873         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
        76251  +SQLITE_API int SQLITE_APICALL sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
 75874  76252     int rc;
 75875  76253     Vdbe *p = (Vdbe *)pStmt;
 75876  76254     rc = vdbeUnbind(p, i);
 75877  76255     if( rc==SQLITE_OK ){
 75878  76256       sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
 75879  76257       sqlite3_mutex_leave(p->db->mutex);
 75880  76258     }
 75881  76259     return rc;
 75882  76260   }
 75883         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
        76261  +SQLITE_API int SQLITE_APICALL sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
 75884  76262     int rc;
 75885  76263     Vdbe *p = (Vdbe*)pStmt;
 75886  76264     rc = vdbeUnbind(p, i);
 75887  76265     if( rc==SQLITE_OK ){
 75888  76266       sqlite3_mutex_leave(p->db->mutex);
 75889  76267     }
 75890  76268     return rc;
 75891  76269   }
 75892         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text( 
        76270  +SQLITE_API int SQLITE_APICALL sqlite3_bind_text( 
 75893  76271     sqlite3_stmt *pStmt, 
 75894  76272     int i, 
 75895  76273     const char *zData, 
 75896  76274     int nData, 
 75897  76275     void (*xDel)(void*)
 75898  76276   ){
 75899  76277     return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
 75900  76278   }
 75901         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64( 
        76279  +SQLITE_API int SQLITE_APICALL sqlite3_bind_text64( 
 75902  76280     sqlite3_stmt *pStmt, 
 75903  76281     int i, 
 75904  76282     const char *zData, 
 75905  76283     sqlite3_uint64 nData, 
 75906  76284     void (*xDel)(void*),
 75907  76285     unsigned char enc
 75908  76286   ){
................................................................................
 75911  76289       return invokeValueDestructor(zData, xDel, 0);
 75912  76290     }else{
 75913  76291       if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
 75914  76292       return bindText(pStmt, i, zData, (int)nData, xDel, enc);
 75915  76293     }
 75916  76294   }
 75917  76295   #ifndef SQLITE_OMIT_UTF16
 75918         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(
        76296  +SQLITE_API int SQLITE_APICALL sqlite3_bind_text16(
 75919  76297     sqlite3_stmt *pStmt, 
 75920  76298     int i, 
 75921  76299     const void *zData, 
 75922  76300     int nData, 
 75923  76301     void (*xDel)(void*)
 75924  76302   ){
 75925  76303     return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
 75926  76304   }
 75927  76305   #endif /* SQLITE_OMIT_UTF16 */
 75928         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
        76306  +SQLITE_API int SQLITE_APICALL sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
 75929  76307     int rc;
 75930  76308     switch( sqlite3_value_type((sqlite3_value*)pValue) ){
 75931  76309       case SQLITE_INTEGER: {
 75932  76310         rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
 75933  76311         break;
 75934  76312       }
 75935  76313       case SQLITE_FLOAT: {
................................................................................
 75952  76330       default: {
 75953  76331         rc = sqlite3_bind_null(pStmt, i);
 75954  76332         break;
 75955  76333       }
 75956  76334     }
 75957  76335     return rc;
 75958  76336   }
 75959         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
        76337  +SQLITE_API int SQLITE_APICALL sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
 75960  76338     int rc;
 75961  76339     Vdbe *p = (Vdbe *)pStmt;
 75962  76340     rc = vdbeUnbind(p, i);
 75963  76341     if( rc==SQLITE_OK ){
 75964  76342       sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
 75965  76343       sqlite3_mutex_leave(p->db->mutex);
 75966  76344     }
 75967  76345     return rc;
 75968  76346   }
 75969         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt *pStmt, int i, sqlite3_uint64 n){
        76347  +SQLITE_API int SQLITE_APICALL sqlite3_bind_zeroblob64(sqlite3_stmt *pStmt, int i, sqlite3_uint64 n){
 75970  76348     int rc;
 75971  76349     Vdbe *p = (Vdbe *)pStmt;
 75972  76350     sqlite3_mutex_enter(p->db->mutex);
 75973  76351     if( n>(u64)p->db->aLimit[SQLITE_LIMIT_LENGTH] ){
 75974  76352       rc = SQLITE_TOOBIG;
 75975  76353     }else{
 75976  76354       assert( (n & 0x7FFFFFFF)==n );
................................................................................
 75981  76359     return rc;
 75982  76360   }
 75983  76361   
 75984  76362   /*
 75985  76363   ** Return the number of wildcards that can be potentially bound to.
 75986  76364   ** This routine is added to support DBD::SQLite.  
 75987  76365   */
 75988         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
        76366  +SQLITE_API int SQLITE_APICALL sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
 75989  76367     Vdbe *p = (Vdbe*)pStmt;
 75990  76368     return p ? p->nVar : 0;
 75991  76369   }
 75992  76370   
 75993  76371   /*
 75994  76372   ** Return the name of a wildcard parameter.  Return NULL if the index
 75995  76373   ** is out of range or if the wildcard is unnamed.
 75996  76374   **
 75997  76375   ** The result is always UTF-8.
 75998  76376   */
 75999         -SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
        76377  +SQLITE_API const char *SQLITE_APICALL sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
 76000  76378     Vdbe *p = (Vdbe*)pStmt;
 76001  76379     if( p==0 || i<1 || i>p->nzVar ){
 76002  76380       return 0;
 76003  76381     }
 76004  76382     return p->azVar[i-1];
 76005  76383   }
 76006  76384   
................................................................................
 76020  76398         if( z && strncmp(z,zName,nName)==0 && z[nName]==0 ){
 76021  76399           return i+1;
 76022  76400         }
 76023  76401       }
 76024  76402     }
 76025  76403     return 0;
 76026  76404   }
 76027         -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
        76405  +SQLITE_API int SQLITE_APICALL sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
 76028  76406     return sqlite3VdbeParameterIndex((Vdbe*)pStmt, zName, sqlite3Strlen30(zName));
 76029  76407   }
 76030  76408   
 76031  76409   /*
 76032  76410   ** Transfer all bindings from the first statement over to the second.
 76033  76411   */
 76034  76412   SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
................................................................................
 76054  76432   ** database connections.  But as this is a deprecated interface, we
 76055  76433   ** will not bother to check for that condition.
 76056  76434   **
 76057  76435   ** If the two statements contain a different number of bindings, then
 76058  76436   ** an SQLITE_ERROR is returned.  Nothing else can go wrong, so otherwise
 76059  76437   ** SQLITE_OK is returned.
 76060  76438   */
 76061         -SQLITE_API int SQLITE_STDCALL sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
        76439  +SQLITE_API int SQLITE_APICALL sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
 76062  76440     Vdbe *pFrom = (Vdbe*)pFromStmt;
 76063  76441     Vdbe *pTo = (Vdbe*)pToStmt;
 76064  76442     if( pFrom->nVar!=pTo->nVar ){
 76065  76443       return SQLITE_ERROR;
 76066  76444     }
 76067  76445     if( pTo->isPrepareV2 && pTo->expmask ){
 76068  76446       pTo->expired = 1;
................................................................................
 76076  76454   
 76077  76455   /*
 76078  76456   ** Return the sqlite3* database handle to which the prepared statement given
 76079  76457   ** in the argument belongs.  This is the same database handle that was
 76080  76458   ** the first argument to the sqlite3_prepare() that was used to create
 76081  76459   ** the statement in the first place.
 76082  76460   */
 76083         -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt *pStmt){
        76461  +SQLITE_API sqlite3 *SQLITE_APICALL sqlite3_db_handle(sqlite3_stmt *pStmt){
 76084  76462     return pStmt ? ((Vdbe*)pStmt)->db : 0;
 76085  76463   }
 76086  76464   
 76087  76465   /*
 76088  76466   ** Return true if the prepared statement is guaranteed to not modify the
 76089  76467   ** database.
 76090  76468   */
 76091         -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
        76469  +SQLITE_API int SQLITE_APICALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
 76092  76470     return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
 76093  76471   }
 76094  76472   
 76095  76473   /*
 76096  76474   ** Return true if the prepared statement is in need of being reset.
 76097  76475   */
 76098         -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_busy(sqlite3_stmt *pStmt){
        76476  +SQLITE_API int SQLITE_APICALL sqlite3_stmt_busy(sqlite3_stmt *pStmt){
 76099  76477     Vdbe *v = (Vdbe*)pStmt;
 76100  76478     return v!=0 && v->pc>=0 && v->magic==VDBE_MAGIC_RUN;
 76101  76479   }
 76102  76480   
 76103  76481   /*
 76104  76482   ** Return a pointer to the next prepared statement after pStmt associated
 76105  76483   ** with database connection pDb.  If pStmt is NULL, return the first
 76106  76484   ** prepared statement for the database connection.  Return NULL if there
 76107  76485   ** are no more.
 76108  76486   */
 76109         -SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){
        76487  +SQLITE_API sqlite3_stmt *SQLITE_APICALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){
 76110  76488     sqlite3_stmt *pNext;
 76111  76489   #ifdef SQLITE_ENABLE_API_ARMOR
 76112  76490     if( !sqlite3SafetyCheckOk(pDb) ){
 76113  76491       (void)SQLITE_MISUSE_BKPT;
 76114  76492       return 0;
 76115  76493     }
 76116  76494   #endif
................................................................................
 76123  76501     sqlite3_mutex_leave(pDb->mutex);
 76124  76502     return pNext;
 76125  76503   }
 76126  76504   
 76127  76505   /*
 76128  76506   ** Return the value of a status counter for a prepared statement
 76129  76507   */
 76130         -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
        76508  +SQLITE_API int SQLITE_APICALL sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
 76131  76509     Vdbe *pVdbe = (Vdbe*)pStmt;
 76132  76510     u32 v;
 76133  76511   #ifdef SQLITE_ENABLE_API_ARMOR
 76134  76512     if( !pStmt ){
 76135  76513       (void)SQLITE_MISUSE_BKPT;
 76136  76514       return 0;
 76137  76515     }
 76138  76516   #endif
 76139  76517     v = pVdbe->aCounter[op];
 76140  76518     if( resetFlag ) pVdbe->aCounter[op] = 0;
 76141  76519     return (int)v;
 76142  76520   }
        76521  +
        76522  +/*
        76523  +** Return the SQL associated with a prepared statement
        76524  +*/
        76525  +SQLITE_API const char *SQLITE_APICALL sqlite3_sql(sqlite3_stmt *pStmt){
        76526  +  Vdbe *p = (Vdbe *)pStmt;
        76527  +  return p ? p->zSql : 0;
        76528  +}
        76529  +
        76530  +/*
        76531  +** Return the SQL associated with a prepared statement with
        76532  +** bound parameters expanded.  Space to hold the returned string is
        76533  +** obtained from sqlite3_malloc().  The caller is responsible for
        76534  +** freeing the returned string by passing it to sqlite3_free().
        76535  +**
        76536  +** The SQLITE_TRACE_SIZE_LIMIT puts an upper bound on the size of
        76537  +** expanded bound parameters.
        76538  +*/
        76539  +SQLITE_API char *SQLITE_APICALL sqlite3_expanded_sql(sqlite3_stmt *pStmt){
        76540  +#ifdef SQLITE_OMIT_TRACE
        76541  +  return 0;
        76542  +#else
        76543  +  char *z = 0;
        76544  +  const char *zSql = sqlite3_sql(pStmt);
        76545  +  if( zSql ){
        76546  +    Vdbe *p = (Vdbe *)pStmt;
        76547  +    sqlite3_mutex_enter(p->db->mutex);
        76548  +    z = sqlite3VdbeExpandSql(p, zSql);
        76549  +    sqlite3_mutex_leave(p->db->mutex);
        76550  +  }
        76551  +  return z;
        76552  +#endif
        76553  +}
 76143  76554   
 76144  76555   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 76145  76556   /*
 76146  76557   ** Allocate and populate an UnpackedRecord structure based on the serialized
 76147  76558   ** record in nKey/pKey. Return a pointer to the new UnpackedRecord structure
 76148  76559   ** if successful, or a NULL pointer if an OOM error is encountered.
 76149  76560   */
................................................................................
 76163  76574     return pRet;
 76164  76575   }
 76165  76576   
 76166  76577   /*
 76167  76578   ** This function is called from within a pre-update callback to retrieve
 76168  76579   ** a field of the row currently being updated or deleted.
 76169  76580   */
 76170         -SQLITE_API int SQLITE_STDCALL sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
        76581  +SQLITE_API int SQLITE_APICALL sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
 76171  76582     PreUpdate *p = db->pPreUpdate;
 76172  76583     int rc = SQLITE_OK;
 76173  76584   
 76174  76585     /* Test that this call is being made from within an SQLITE_DELETE or
 76175  76586     ** SQLITE_UPDATE pre-update callback, and that iIdx is within range. */
 76176  76587     if( !p || p->op==SQLITE_INSERT ){
 76177  76588       rc = SQLITE_MISUSE_BKPT;
................................................................................
 76183  76594     }
 76184  76595   
 76185  76596     /* If the old.* record has not yet been loaded into memory, do so now. */
 76186  76597     if( p->pUnpacked==0 ){
 76187  76598       u32 nRec;
 76188  76599       u8 *aRec;
 76189  76600   
 76190         -    rc = sqlite3BtreeDataSize(p->pCsr->uc.pCursor, &nRec);
 76191         -    if( rc!=SQLITE_OK ) goto preupdate_old_out;
        76601  +    nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor);
 76192  76602       aRec = sqlite3DbMallocRaw(db, nRec);
 76193  76603       if( !aRec ) goto preupdate_old_out;
 76194  76604       rc = sqlite3BtreeData(p->pCsr->uc.pCursor, 0, nRec, aRec);
 76195  76605       if( rc==SQLITE_OK ){
 76196  76606         p->pUnpacked = vdbeUnpackRecord(&p->keyinfo, nRec, aRec);
 76197  76607         if( !p->pUnpacked ) rc = SQLITE_NOMEM;
 76198  76608       }
................................................................................
 76219  76629   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 76220  76630   
 76221  76631   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 76222  76632   /*
 76223  76633   ** This function is called from within a pre-update callback to retrieve
 76224  76634   ** the number of columns in the row being updated, deleted or inserted.
 76225  76635   */
 76226         -SQLITE_API int SQLITE_STDCALL sqlite3_preupdate_count(sqlite3 *db){
        76636  +SQLITE_API int SQLITE_APICALL sqlite3_preupdate_count(sqlite3 *db){
 76227  76637     PreUpdate *p = db->pPreUpdate;
 76228  76638     return (p ? p->keyinfo.nField : 0);
 76229  76639   }
 76230  76640   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 76231  76641   
 76232  76642   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 76233  76643   /*
................................................................................
 76237  76647   ** trigger program, it returns the number of trigger programs currently
 76238  76648   ** on the stack (1 for a top-level trigger, 2 for a trigger fired by a 
 76239  76649   ** top-level trigger etc.).
 76240  76650   **
 76241  76651   ** For the purposes of the previous paragraph, a foreign key CASCADE, SET NULL
 76242  76652   ** or SET DEFAULT action is considered a trigger.
 76243  76653   */
 76244         -SQLITE_API int SQLITE_STDCALL sqlite3_preupdate_depth(sqlite3 *db){
        76654  +SQLITE_API int SQLITE_APICALL sqlite3_preupdate_depth(sqlite3 *db){
 76245  76655     PreUpdate *p = db->pPreUpdate;
 76246  76656     return (p ? p->v->nFrame : 0);
 76247  76657   }
 76248  76658   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 76249  76659   
 76250  76660   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 76251  76661   /*
 76252  76662   ** This function is called from within a pre-update callback to retrieve
 76253  76663   ** a field of the row currently being updated or inserted.
 76254  76664   */
 76255         -SQLITE_API int SQLITE_STDCALL sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
        76665  +SQLITE_API int SQLITE_APICALL sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
 76256  76666     PreUpdate *p = db->pPreUpdate;
 76257  76667     int rc = SQLITE_OK;
 76258  76668     Mem *pMem;
 76259  76669   
 76260  76670     if( !p || p->op==SQLITE_DELETE ){
 76261  76671       rc = SQLITE_MISUSE_BKPT;
 76262  76672       goto preupdate_new_out;
................................................................................
 76322  76732   }
 76323  76733   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 76324  76734   
 76325  76735   #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
 76326  76736   /*
 76327  76737   ** Return status data for a single loop within query pStmt.
 76328  76738   */
 76329         -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_scanstatus(
        76739  +SQLITE_API int SQLITE_APICALL sqlite3_stmt_scanstatus(
 76330  76740     sqlite3_stmt *pStmt,            /* Prepared statement being queried */
 76331  76741     int idx,                        /* Index of loop to report on */
 76332  76742     int iScanStatusOp,              /* Which metric to return */
 76333  76743     void *pOut                      /* OUT: Write the answer here */
 76334  76744   ){
 76335  76745     Vdbe *p = (Vdbe*)pStmt;
 76336  76746     ScanStatus *pScan;
................................................................................
 76381  76791     }
 76382  76792     return 0;
 76383  76793   }
 76384  76794   
 76385  76795   /*
 76386  76796   ** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
 76387  76797   */
 76388         -SQLITE_API void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
        76798  +SQLITE_API void SQLITE_APICALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
 76389  76799     Vdbe *p = (Vdbe*)pStmt;
 76390  76800     memset(p->anExec, 0, p->nOp * sizeof(i64));
 76391  76801   }
 76392  76802   #endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
 76393  76803   
 76394  76804   /************** End of vdbeapi.c *********************************************/
 76395  76805   /************** Begin file vdbetrace.c ***************************************/
................................................................................
 76472  76882     int idx = 0;             /* Index of a host parameter */
 76473  76883     int nextIndex = 1;       /* Index of next ? host parameter */
 76474  76884     int n;                   /* Length of a token prefix */
 76475  76885     int nToken;              /* Length of the parameter token */
 76476  76886     int i;                   /* Loop counter */
 76477  76887     Mem *pVar;               /* Value of a host parameter */
 76478  76888     StrAccum out;            /* Accumulate the output here */
        76889  +#ifndef SQLITE_OMIT_UTF16
        76890  +  Mem utf8;                /* Used to convert UTF16 parameters into UTF8 for display */
        76891  +#endif
 76479  76892     char zBase[100];         /* Initial working space */
 76480  76893   
 76481  76894     db = p->db;
 76482         -  sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase), 
        76895  +  sqlite3StrAccumInit(&out, 0, zBase, sizeof(zBase), 
 76483  76896                         db->aLimit[SQLITE_LIMIT_LENGTH]);
 76484  76897     if( db->nVdbeExec>1 ){
 76485  76898       while( *zRawSql ){
 76486  76899         const char *zStart = zRawSql;
 76487  76900         while( *(zRawSql++)!='\n' && *zRawSql );
 76488  76901         sqlite3StrAccumAppend(&out, "-- ", 3);
 76489  76902         assert( (zRawSql - zStart) > 0 );
................................................................................
 76526  76939           sqlite3XPrintf(&out, "%lld", pVar->u.i);
 76527  76940         }else if( pVar->flags & MEM_Real ){
 76528  76941           sqlite3XPrintf(&out, "%!.15g", pVar->u.r);
 76529  76942         }else if( pVar->flags & MEM_Str ){
 76530  76943           int nOut;  /* Number of bytes of the string text to include in output */
 76531  76944   #ifndef SQLITE_OMIT_UTF16
 76532  76945           u8 enc = ENC(db);
 76533         -        Mem utf8;
 76534  76946           if( enc!=SQLITE_UTF8 ){
 76535  76947             memset(&utf8, 0, sizeof(utf8));
 76536  76948             utf8.db = db;
 76537  76949             sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE_STATIC);
 76538         -          sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8);
        76950  +          if( SQLITE_NOMEM==sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8) ){
        76951  +            out.accError = STRACCUM_NOMEM;
        76952  +            out.nAlloc = 0;
        76953  +          }
 76539  76954             pVar = &utf8;
 76540  76955           }
 76541  76956   #endif
 76542  76957           nOut = pVar->n;
 76543  76958   #ifdef SQLITE_TRACE_SIZE_LIMIT
 76544  76959           if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
 76545  76960             nOut = SQLITE_TRACE_SIZE_LIMIT;
................................................................................
 76573  76988           if( nOut<pVar->n ){
 76574  76989             sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
 76575  76990           }
 76576  76991   #endif
 76577  76992         }
 76578  76993       }
 76579  76994     }
        76995  +  if( out.accError ) sqlite3StrAccumReset(&out);
 76580  76996     return sqlite3StrAccumFinish(&out);
 76581  76997   }
 76582  76998   
 76583  76999   #endif /* #ifndef SQLITE_OMIT_TRACE */
 76584  77000   
 76585  77001   /************** End of vdbetrace.c *******************************************/
 76586  77002   /************** Begin file vdbe.c ********************************************/
................................................................................
 76902  77318   
 76903  77319   /*
 76904  77320   ** Try to convert the type of a function argument or a result column
 76905  77321   ** into a numeric representation.  Use either INTEGER or REAL whichever
 76906  77322   ** is appropriate.  But only do the conversion if it is possible without
 76907  77323   ** loss of information and return the revised type of the argument.
 76908  77324   */
 76909         -SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value *pVal){
        77325  +SQLITE_API int SQLITE_APICALL sqlite3_value_numeric_type(sqlite3_value *pVal){
 76910  77326     int eType = sqlite3_value_type(pVal);
 76911  77327     if( eType==SQLITE_TEXT ){
 76912  77328       Mem *pMem = (Mem*)pVal;
 76913  77329       applyNumericAffinity(pMem, 0);
 76914  77330       eType = sqlite3_value_type(pVal);
 76915  77331     }
 76916  77332     return eType;
................................................................................
 77105  77521   **    May you share freely, never taking more than you give.
 77106  77522   **
 77107  77523   ******************************************************************************
 77108  77524   **
 77109  77525   ** This file contains inline asm code for retrieving "high-performance"
 77110  77526   ** counters for x86 class CPUs.
 77111  77527   */
 77112         -#ifndef _HWTIME_H_
 77113         -#define _HWTIME_H_
        77528  +#ifndef SQLITE_HWTIME_H
        77529  +#define SQLITE_HWTIME_H
 77114  77530   
 77115  77531   /*
 77116  77532   ** The following routine only works on pentium-class (or newer) processors.
 77117  77533   ** It uses the RDTSC opcode to read the cycle count value out of the
 77118  77534   ** processor and returns that value.  This can be used for high-res
 77119  77535   ** profiling.
 77120  77536   */
................................................................................
 77174  77590     ** of the debugging and testing utilities, but it should at
 77175  77591     ** least compile and run.
 77176  77592     */
 77177  77593   SQLITE_PRIVATE   sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
 77178  77594   
 77179  77595   #endif
 77180  77596   
 77181         -#endif /* !defined(_HWTIME_H_) */
        77597  +#endif /* !defined(SQLITE_HWTIME_H) */
 77182  77598   
 77183  77599   /************** End of hwtime.h **********************************************/
 77184  77600   /************** Continuing where we left off in vdbe.c ***********************/
 77185  77601   
 77186  77602   #endif
 77187  77603   
 77188  77604   #ifndef NDEBUG
................................................................................
 78053  78469       Deephemeralize(&pMem[i]);
 78054  78470       assert( (pMem[i].flags & MEM_Ephem)==0
 78055  78471               || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
 78056  78472       sqlite3VdbeMemNulTerminate(&pMem[i]);
 78057  78473       REGISTER_TRACE(pOp->p1+i, &pMem[i]);
 78058  78474     }
 78059  78475     if( db->mallocFailed ) goto no_mem;
        78476  +
        78477  +  if( db->mTrace & SQLITE_TRACE_ROW ){
        78478  +    db->xTrace(SQLITE_TRACE_ROW, db->pTraceArg, p, 0);
        78479  +  }
 78060  78480   
 78061  78481     /* Return SQLITE_ROW
 78062  78482     */
 78063  78483     p->pc = (int)(pOp - aOp) + 1;
 78064  78484     rc = SQLITE_ROW;
 78065  78485     goto vdbe_return;
 78066  78486   }
................................................................................
 78687  79107     }else{
 78688  79108       /* Neither operand is NULL.  Do a comparison. */
 78689  79109       affinity = pOp->p5 & SQLITE_AFF_MASK;
 78690  79110       if( affinity>=SQLITE_AFF_NUMERIC ){
 78691  79111         if( (flags1 | flags3)&MEM_Str ){
 78692  79112           if( (flags1 & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
 78693  79113             applyNumericAffinity(pIn1,0);
        79114  +          flags3 = pIn3->flags;
 78694  79115           }
 78695  79116           if( (flags3 & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
 78696  79117             applyNumericAffinity(pIn3,0);
 78697  79118           }
 78698  79119         }
 78699  79120       }else if( affinity==SQLITE_AFF_TEXT ){
 78700  79121         if( (flags1 & MEM_Str)==0 && (flags1 & (MEM_Int|MEM_Real))!=0 ){
 78701  79122           testcase( pIn1->flags & MEM_Int );
 78702  79123           testcase( pIn1->flags & MEM_Real );
 78703  79124           sqlite3VdbeMemStringify(pIn1, encoding, 1);
 78704  79125           testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
 78705  79126           flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
        79127  +        flags3 = pIn3->flags;
 78706  79128         }
 78707  79129         if( (flags3 & MEM_Str)==0 && (flags3 & (MEM_Int|MEM_Real))!=0 ){
 78708  79130           testcase( pIn3->flags & MEM_Int );
 78709  79131           testcase( pIn3->flags & MEM_Real );
 78710  79132           sqlite3VdbeMemStringify(pIn3, encoding, 1);
 78711  79133           testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) );
 78712  79134           flags3 = (pIn3->flags & ~MEM_TypeMask) | (flags3 & MEM_TypeMask);
................................................................................
 79051  79473   **
 79052  79474   ** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when
 79053  79475   ** the result is guaranteed to only be used as the argument of a length()
 79054  79476   ** or typeof() function, respectively.  The loading of large blobs can be
 79055  79477   ** skipped for length() and all content loading can be skipped for typeof().
 79056  79478   */
 79057  79479   case OP_Column: {
 79058         -  i64 payloadSize64; /* Number of bytes in the record */
 79059  79480     int p2;            /* column number to retrieve */
 79060  79481     VdbeCursor *pC;    /* The VDBE cursor */
 79061  79482     BtCursor *pCrsr;   /* The BTree cursor */
 79062  79483     u32 *aOffset;      /* aOffset[i] is offset to start of data for i-th column */
 79063  79484     int len;           /* The length of the serialized data for the column */
 79064  79485     int i;             /* Loop counter */
 79065  79486     Mem *pDest;        /* Where to write the extracted value */
................................................................................
 79074  79495     Mem *pReg;         /* PseudoTable input register */
 79075  79496   
 79076  79497     pC = p->apCsr[pOp->p1];
 79077  79498     p2 = pOp->p2;
 79078  79499   
 79079  79500     /* If the cursor cache is stale, bring it up-to-date */
 79080  79501     rc = sqlite3VdbeCursorMoveto(&pC, &p2);
        79502  +  if( rc ) goto abort_due_to_error;
 79081  79503   
 79082  79504     assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
 79083  79505     pDest = &aMem[pOp->p3];
 79084  79506     memAboutToChange(p, pDest);
 79085  79507     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 79086  79508     assert( pC!=0 );
 79087  79509     assert( p2<pC->nField );
 79088  79510     aOffset = pC->aOffset;
 79089  79511     assert( pC->eCurType!=CURTYPE_VTAB );
 79090  79512     assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
 79091  79513     assert( pC->eCurType!=CURTYPE_SORTER );
 79092  79514     pCrsr = pC->uc.pCursor;
 79093  79515   
 79094         -  if( rc ) goto abort_due_to_error;
 79095         -  if( pC->cacheStatus!=p->cacheCtr ){
        79516  +  if( pC->cacheStatus!=p->cacheCtr ){                /*OPTIMIZATION-IF-FALSE*/
 79096  79517       if( pC->nullRow ){
 79097  79518         if( pC->eCurType==CURTYPE_PSEUDO ){
 79098  79519           assert( pC->uc.pseudoTableReg>0 );
 79099  79520           pReg = &aMem[pC->uc.pseudoTableReg];
 79100  79521           assert( pReg->flags & MEM_Blob );
 79101  79522           assert( memIsValid(pReg) );
 79102  79523           pC->payloadSize = pC->szRow = avail = pReg->n;
................................................................................
 79104  79525         }else{
 79105  79526           sqlite3VdbeMemSetNull(pDest);
 79106  79527           goto op_column_out;
 79107  79528         }
 79108  79529       }else{
 79109  79530         assert( pC->eCurType==CURTYPE_BTREE );
 79110  79531         assert( pCrsr );
 79111         -      if( pC->isTable==0 ){
 79112         -        assert( sqlite3BtreeCursorIsValid(pCrsr) );
 79113         -        VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64);
 79114         -        assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
 79115         -        /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
 79116         -        ** payload size, so it is impossible for payloadSize64 to be
 79117         -        ** larger than 32 bits. */
 79118         -        assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 );
 79119         -        pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail);
 79120         -        pC->payloadSize = (u32)payloadSize64;
 79121         -      }else{
 79122         -        assert( sqlite3BtreeCursorIsValid(pCrsr) );
 79123         -        VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize);
 79124         -        assert( rc==SQLITE_OK );   /* DataSize() cannot fail */
 79125         -        pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail);
 79126         -      }
        79532  +      assert( sqlite3BtreeCursorIsValid(pCrsr) );
        79533  +      pC->payloadSize = sqlite3BtreePayloadSize(pCrsr);
        79534  +      pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &avail);
 79127  79535         assert( avail<=65536 );  /* Maximum page size is 64KiB */
 79128  79536         if( pC->payloadSize <= (u32)avail ){
 79129  79537           pC->szRow = pC->payloadSize;
 79130  79538         }else if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
 79131  79539           goto too_big;
 79132  79540         }else{
 79133  79541           pC->szRow = avail;
................................................................................
 79135  79543       }
 79136  79544       pC->cacheStatus = p->cacheCtr;
 79137  79545       pC->iHdrOffset = getVarint32(pC->aRow, offset);
 79138  79546       pC->nHdrParsed = 0;
 79139  79547       aOffset[0] = offset;
 79140  79548   
 79141  79549   
 79142         -    if( avail<offset ){
        79550  +    if( avail<offset ){      /*OPTIMIZATION-IF-FALSE*/
 79143  79551         /* pC->aRow does not have to hold the entire row, but it does at least
 79144  79552         ** need to cover the header of the record.  If pC->aRow does not contain
 79145  79553         ** the complete header, then set it to zero, forcing the header to be
 79146  79554         ** dynamically allocated. */
 79147  79555         pC->aRow = 0;
 79148  79556         pC->szRow = 0;
 79149  79557   
................................................................................
 79156  79564         ** 3-byte type for each of the maximum of 32768 columns plus three
 79157  79565         ** extra bytes for the header length itself.  32768*3 + 3 = 98307.
 79158  79566         */
 79159  79567         if( offset > 98307 || offset > pC->payloadSize ){
 79160  79568           rc = SQLITE_CORRUPT_BKPT;
 79161  79569           goto abort_due_to_error;
 79162  79570         }
        79571  +    }else if( offset>0 ){ /*OPTIMIZATION-IF-TRUE*/
        79572  +      /* The following goto is an optimization.  It can be omitted and
        79573  +      ** everything will still work.  But OP_Column is measurably faster
        79574  +      ** by skipping the subsequent conditional, which is always true.
        79575  +      */
        79576  +      zData = pC->aRow;
        79577  +      assert( pC->nHdrParsed<=p2 );         /* Conditional skipped */
        79578  +      goto op_column_read_header;
 79163  79579       }
 79164         -
 79165         -    /* The following goto is an optimization.  It can be omitted and
 79166         -    ** everything will still work.  But OP_Column is measurably faster
 79167         -    ** by skipping the subsequent conditional, which is always true.
 79168         -    */
 79169         -    assert( pC->nHdrParsed<=p2 );         /* Conditional skipped */
 79170         -    goto op_column_read_header;
 79171  79580     }
 79172  79581   
 79173  79582     /* Make sure at least the first p2+1 entries of the header have been
 79174  79583     ** parsed and valid information is in aOffset[] and pC->aType[].
 79175  79584     */
 79176  79585     if( pC->nHdrParsed<=p2 ){
 79177  79586       /* If there is more header available for parsing in the record, try
 79178  79587       ** to extract additional fields up through the p2+1-th field 
 79179  79588       */
 79180         -    op_column_read_header:
 79181  79589       if( pC->iHdrOffset<aOffset[0] ){
 79182  79590         /* Make sure zData points to enough of the record to cover the header. */
 79183  79591         if( pC->aRow==0 ){
 79184  79592           memset(&sMem, 0, sizeof(sMem));
 79185  79593           rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], !pC->isTable, &sMem);
 79186  79594           if( rc!=SQLITE_OK ) goto abort_due_to_error;
 79187  79595           zData = (u8*)sMem.z;
 79188  79596         }else{
 79189  79597           zData = pC->aRow;
 79190  79598         }
 79191  79599     
 79192  79600         /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */
        79601  +    op_column_read_header:
 79193  79602         i = pC->nHdrParsed;
 79194  79603         offset64 = aOffset[i];
 79195  79604         zHdr = zData + pC->iHdrOffset;
 79196  79605         zEndHdr = zData + aOffset[0];
 79197         -      assert( i<=p2 && zHdr<zEndHdr );
 79198  79606         do{
 79199  79607           if( (t = zHdr[0])<0x80 ){
 79200  79608             zHdr++;
 79201  79609             offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
 79202  79610           }else{
 79203  79611             zHdr += sqlite3GetVarint32(zHdr, &t);
 79204  79612             offset64 += sqlite3VdbeSerialTypeLen(t);
 79205  79613           }
 79206  79614           pC->aType[i++] = t;
 79207  79615           aOffset[i] = (u32)(offset64 & 0xffffffff);
 79208  79616         }while( i<=p2 && zHdr<zEndHdr );
 79209         -      pC->nHdrParsed = i;
 79210         -      pC->iHdrOffset = (u32)(zHdr - zData);
 79211         -  
        79617  +
 79212  79618         /* The record is corrupt if any of the following are true:
 79213  79619         ** (1) the bytes of the header extend past the declared header size
 79214  79620         ** (2) the entire header was used but not all data was used
 79215  79621         ** (3) the end of the data extends beyond the end of the record.
 79216  79622         */
 79217  79623         if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
 79218  79624          || (offset64 > pC->payloadSize)
 79219  79625         ){
 79220  79626           if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
 79221  79627           rc = SQLITE_CORRUPT_BKPT;
 79222  79628           goto abort_due_to_error;
 79223  79629         }
        79630  +
        79631  +      pC->nHdrParsed = i;
        79632  +      pC->iHdrOffset = (u32)(zHdr - zData);
 79224  79633         if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
 79225         -
 79226  79634       }else{
 79227  79635         t = 0;
 79228  79636       }
 79229  79637   
 79230  79638       /* If after trying to extract new entries from the header, nHdrParsed is
 79231  79639       ** still not up to p2, that means that the record has fewer than p2
 79232  79640       ** columns.  So the result will be either the default value or a NULL.
................................................................................
 79246  79654     /* Extract the content for the p2+1-th column.  Control can only
 79247  79655     ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are
 79248  79656     ** all valid.
 79249  79657     */
 79250  79658     assert( p2<pC->nHdrParsed );
 79251  79659     assert( rc==SQLITE_OK );
 79252  79660     assert( sqlite3VdbeCheckMemInvariants(pDest) );
 79253         -  if( VdbeMemDynamic(pDest) ) sqlite3VdbeMemSetNull(pDest);
        79661  +  if( VdbeMemDynamic(pDest) ){
        79662  +    sqlite3VdbeMemSetNull(pDest);
        79663  +  }
 79254  79664     assert( t==pC->aType[p2] );
 79255         -  pDest->enc = encoding;
 79256  79665     if( pC->szRow>=aOffset[p2+1] ){
 79257  79666       /* This is the common case where the desired content fits on the original
 79258  79667       ** page - where the content is not on an overflow page */
 79259  79668       zData = pC->aRow + aOffset[p2];
 79260  79669       if( t<12 ){
 79261  79670         sqlite3VdbeSerialGet(zData, t, pDest);
 79262  79671       }else{
 79263  79672         /* If the column value is a string, we need a persistent value, not
 79264  79673         ** a MEM_Ephem value.  This branch is a fast short-cut that is equivalent
 79265  79674         ** to calling sqlite3VdbeSerialGet() and sqlite3VdbeDeephemeralize().
 79266  79675         */
 79267  79676         static const u16 aFlag[] = { MEM_Blob, MEM_Str|MEM_Term };
 79268  79677         pDest->n = len = (t-12)/2;
        79678  +      pDest->enc = encoding;
 79269  79679         if( pDest->szMalloc < len+2 ){
 79270  79680           pDest->flags = MEM_Null;
 79271  79681           if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem;
 79272  79682         }else{
 79273  79683           pDest->z = pDest->zMalloc;
 79274  79684         }
 79275  79685         memcpy(pDest->z, zData, len);
 79276  79686         pDest->z[len] = 0;
 79277  79687         pDest->z[len+1] = 0;
 79278  79688         pDest->flags = aFlag[t&1];
 79279  79689       }
 79280  79690     }else{
        79691  +    pDest->enc = encoding;
 79281  79692       /* This branch happens only when content is on overflow pages */
 79282  79693       if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
 79283  79694             && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
 79284  79695        || (len = sqlite3VdbeSerialTypeLen(t))==0
 79285  79696       ){
 79286  79697         /* Content is irrelevant for
 79287  79698         **    1. the typeof() function,
................................................................................
 80691  81102     }else{
 80692  81103       VdbeBranchTaken(takeJump||alreadyExists==0,2);
 80693  81104       if( takeJump || !alreadyExists ) goto jump_to_p2;
 80694  81105     }
 80695  81106     break;
 80696  81107   }
 80697  81108   
        81109  +/* Opcode: SeekRowid P1 P2 P3 * *
        81110  +** Synopsis: intkey=r[P3]
        81111  +**
        81112  +** P1 is the index of a cursor open on an SQL table btree (with integer
        81113  +** keys).  If register P3 does not contain an integer or if P1 does not
        81114  +** contain a record with rowid P3 then jump immediately to P2.  
        81115  +** Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain
        81116  +** a record with rowid P3 then 
        81117  +** leave the cursor pointing at that record and fall through to the next
        81118  +** instruction.
        81119  +**
        81120  +** The OP_NotExists opcode performs the same operation, but with OP_NotExists
        81121  +** the P3 register must be guaranteed to contain an integer value.  With this
        81122  +** opcode, register P3 might not contain an integer.
        81123  +**
        81124  +** The OP_NotFound opcode performs the same operation on index btrees
        81125  +** (with arbitrary multi-value keys).
        81126  +**
        81127  +** This opcode leaves the cursor in a state where it cannot be advanced
        81128  +** in either direction.  In other words, the Next and Prev opcodes will
        81129  +** not work following this opcode.
        81130  +**
        81131  +** See also: Found, NotFound, NoConflict, SeekRowid
        81132  +*/
 80698  81133   /* Opcode: NotExists P1 P2 P3 * *
 80699  81134   ** Synopsis: intkey=r[P3]
 80700  81135   **
 80701  81136   ** P1 is the index of a cursor open on an SQL table btree (with integer
 80702  81137   ** keys).  P3 is an integer rowid.  If P1 does not contain a record with
 80703  81138   ** rowid P3 then jump immediately to P2.  Or, if P2 is 0, raise an
 80704  81139   ** SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then 
 80705  81140   ** leave the cursor pointing at that record and fall through to the next
 80706  81141   ** instruction.
 80707  81142   **
        81143  +** The OP_SeekRowid opcode performs the same operation but also allows the
        81144  +** P3 register to contain a non-integer value, in which case the jump is
        81145  +** always taken.  This opcode requires that P3 always contain an integer.
        81146  +**
 80708  81147   ** The OP_NotFound opcode performs the same operation on index btrees
 80709  81148   ** (with arbitrary multi-value keys).
 80710  81149   **
 80711  81150   ** This opcode leaves the cursor in a state where it cannot be advanced
 80712  81151   ** in either direction.  In other words, the Next and Prev opcodes will
 80713  81152   ** not work following this opcode.
 80714  81153   **
 80715         -** See also: Found, NotFound, NoConflict
        81154  +** See also: Found, NotFound, NoConflict, SeekRowid
 80716  81155   */
 80717         -case OP_NotExists: {        /* jump, in3 */
        81156  +case OP_SeekRowid: {        /* jump, in3 */
 80718  81157     VdbeCursor *pC;
 80719  81158     BtCursor *pCrsr;
 80720  81159     int res;
 80721  81160     u64 iKey;
 80722  81161   
 80723  81162     pIn3 = &aMem[pOp->p3];
        81163  +  if( (pIn3->flags & MEM_Int)==0 ){
        81164  +    applyAffinity(pIn3, SQLITE_AFF_NUMERIC, encoding);
        81165  +    if( (pIn3->flags & MEM_Int)==0 ) goto jump_to_p2;
        81166  +  }
        81167  +  /* Fall through into OP_NotExists */
        81168  +case OP_NotExists:          /* jump, in3 */
        81169  +  pIn3 = &aMem[pOp->p3];
 80724  81170     assert( pIn3->flags & MEM_Int );
 80725  81171     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 80726  81172     pC = p->apCsr[pOp->p1];
 80727  81173     assert( pC!=0 );
 80728  81174   #ifdef SQLITE_DEBUG
 80729  81175     pC->seekOp = 0;
 80730  81176   #endif
................................................................................
 80834  81280         if( rc!=SQLITE_OK ){
 80835  81281           goto abort_due_to_error;
 80836  81282         }
 80837  81283         if( res ){
 80838  81284           v = 1;   /* IMP: R-61914-48074 */
 80839  81285         }else{
 80840  81286           assert( sqlite3BtreeCursorIsValid(pC->uc.pCursor) );
 80841         -        rc = sqlite3BtreeKeySize(pC->uc.pCursor, &v);
 80842         -        assert( rc==SQLITE_OK );   /* Cannot fail following BtreeLast() */
        81287  +        v = sqlite3BtreeIntegerKey(pC->uc.pCursor);
 80843  81288           if( v>=MAX_ROWID ){
 80844  81289             pC->useRandomRowid = 1;
 80845  81290           }else{
 80846  81291             v++;   /* IMP: R-29538-34987 */
 80847  81292           }
 80848  81293         }
 80849  81294       }
................................................................................
 80918  81363   **
 80919  81364   ** If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
 80920  81365   ** incremented (otherwise not).  If the OPFLAG_LASTROWID flag of P5 is set,
 80921  81366   ** then rowid is stored for subsequent return by the
 80922  81367   ** sqlite3_last_insert_rowid() function (otherwise it is unmodified).
 80923  81368   **
 80924  81369   ** If the OPFLAG_USESEEKRESULT flag of P5 is set and if the result of
 80925         -** the last seek operation (OP_NotExists) was a success, then this
        81370  +** the last seek operation (OP_NotExists or OP_SeekRowid) was a success,
        81371  +** then this
 80926  81372   ** operation will not attempt to find the appropriate row before doing
 80927  81373   ** the insert but will instead overwrite the row that the cursor is
 80928         -** currently pointing to.  Presumably, the prior OP_NotExists opcode
        81374  +** currently pointing to.  Presumably, the prior OP_NotExists or
        81375  +** OP_SeekRowid opcode
 80929  81376   ** has already positioned the cursor correctly.  This is an optimization
 80930  81377   ** that boosts performance by avoiding redundant seeks.
 80931  81378   **
 80932  81379   ** If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an
 80933  81380   ** UPDATE operation.  Otherwise (if the flag is clear) then this opcode
 80934  81381   ** is part of an INSERT operation.  The difference is only important to
 80935  81382   ** the update hook.
................................................................................
 80953  81400   ** This works exactly like OP_Insert except that the key is the
 80954  81401   ** integer value P3, not the value of the integer stored in register P3.
 80955  81402   */
 80956  81403   case OP_Insert: 
 80957  81404   case OP_InsertInt: {
 80958  81405     Mem *pData;       /* MEM cell holding data for the record to be inserted */
 80959  81406     Mem *pKey;        /* MEM cell holding key  for the record */
 80960         -  i64 iKey;         /* The integer ROWID or key for the record to be inserted */
 80961  81407     VdbeCursor *pC;   /* Cursor to table into which insert is written */
 80962         -  int nZero;        /* Number of zero-bytes to append */
 80963  81408     int seekResult;   /* Result of prior seek or 0 if no USESEEKRESULT flag */
 80964  81409     const char *zDb;  /* database name - used by the update hook */
 80965  81410     Table *pTab;      /* Table structure - used by update and pre-update hooks */
 80966  81411     int op;           /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
        81412  +  BtreePayload x;   /* Payload to be inserted */
 80967  81413   
 80968  81414     op = 0;
 80969  81415     pData = &aMem[pOp->p2];
 80970  81416     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 80971  81417     assert( memIsValid(pData) );
 80972  81418     pC = p->apCsr[pOp->p1];
 80973  81419     assert( pC!=0 );
................................................................................
 80978  81424     REGISTER_TRACE(pOp->p2, pData);
 80979  81425   
 80980  81426     if( pOp->opcode==OP_Insert ){
 80981  81427       pKey = &aMem[pOp->p3];
 80982  81428       assert( pKey->flags & MEM_Int );
 80983  81429       assert( memIsValid(pKey) );
 80984  81430       REGISTER_TRACE(pOp->p3, pKey);
 80985         -    iKey = pKey->u.i;
        81431  +    x.nKey = pKey->u.i;
 80986  81432     }else{
 80987  81433       assert( pOp->opcode==OP_InsertInt );
 80988         -    iKey = pOp->p3;
        81434  +    x.nKey = pOp->p3;
 80989  81435     }
 80990  81436   
 80991  81437     if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
 80992  81438       assert( pC->isTable );
 80993  81439       assert( pC->iDb>=0 );
 80994  81440       zDb = db->aDb[pC->iDb].zName;
 80995  81441       pTab = pOp->p4.pTab;
................................................................................
 81002  81448   
 81003  81449   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 81004  81450     /* Invoke the pre-update hook, if any */
 81005  81451     if( db->xPreUpdateCallback 
 81006  81452      && pOp->p4type==P4_TABLE
 81007  81453      && !(pOp->p5 & OPFLAG_ISUPDATE)
 81008  81454     ){
 81009         -    sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, iKey, pOp->p2);
        81455  +    sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2);
 81010  81456     }
 81011  81457   #endif
 81012  81458   
 81013  81459     if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
 81014         -  if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
        81460  +  if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = x.nKey;
 81015  81461     if( pData->flags & MEM_Null ){
 81016         -    pData->z = 0;
 81017         -    pData->n = 0;
        81462  +    x.pData = 0;
        81463  +    x.nData = 0;
 81018  81464     }else{
 81019  81465       assert( pData->flags & (MEM_Blob|MEM_Str) );
        81466  +    x.pData = pData->z;
        81467  +    x.nData = pData->n;
 81020  81468     }
 81021  81469     seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
 81022  81470     if( pData->flags & MEM_Zero ){
 81023         -    nZero = pData->u.nZero;
        81471  +    x.nZero = pData->u.nZero;
 81024  81472     }else{
 81025         -    nZero = 0;
        81473  +    x.nZero = 0;
 81026  81474     }
 81027         -  rc = sqlite3BtreeInsert(pC->uc.pCursor, 0, iKey,
 81028         -                          pData->z, pData->n, nZero,
        81475  +  x.pKey = 0;
        81476  +  rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
 81029  81477                             (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
 81030  81478     );
 81031  81479     pC->deferredMoveto = 0;
 81032  81480     pC->cacheStatus = CACHE_STALE;
 81033  81481   
 81034  81482     /* Invoke the update-hook if required. */
 81035  81483     if( rc ) goto abort_due_to_error;
 81036  81484     if( db->xUpdateCallback && op ){
 81037         -    db->xUpdateCallback(db->pUpdateArg, op, zDb, pTab->zName, iKey);
        81485  +    db->xUpdateCallback(db->pUpdateArg, op, zDb, pTab->zName, x.nKey);
 81038  81486     }
 81039  81487     break;
 81040  81488   }
 81041  81489   
 81042  81490   /* Opcode: Delete P1 P2 P3 P4 P5
 81043  81491   **
 81044  81492   ** Delete the record at which the P1 cursor is currently pointing.
................................................................................
 81089  81537     assert( pC->deferredMoveto==0 );
 81090  81538   
 81091  81539   #ifdef SQLITE_DEBUG
 81092  81540     if( pOp->p4type==P4_TABLE && HasRowid(pOp->p4.pTab) && pOp->p5==0 ){
 81093  81541       /* If p5 is zero, the seek operation that positioned the cursor prior to
 81094  81542       ** OP_Delete will have also set the pC->movetoTarget field to the rowid of
 81095  81543       ** the row that is being deleted */
 81096         -    i64 iKey = 0;
 81097         -    sqlite3BtreeKeySize(pC->uc.pCursor, &iKey);
        81544  +    i64 iKey = sqlite3BtreeIntegerKey(pC->uc.pCursor);
 81098  81545       assert( pC->movetoTarget==iKey );
 81099  81546     }
 81100  81547   #endif
 81101  81548   
 81102  81549     /* If the update-hook or pre-update-hook will be invoked, set zDb to
 81103  81550     ** the name of the db to pass as to it. Also set local pTab to a copy
 81104  81551     ** of p4.pTab. Finally, if p5 is true, indicating that this cursor was
................................................................................
 81106  81553     ** VdbeCursor.movetoTarget to the current rowid.  */
 81107  81554     if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
 81108  81555       assert( pC->iDb>=0 );
 81109  81556       assert( pOp->p4.pTab!=0 );
 81110  81557       zDb = db->aDb[pC->iDb].zName;
 81111  81558       pTab = pOp->p4.pTab;
 81112  81559       if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){
 81113         -      sqlite3BtreeKeySize(pC->uc.pCursor, &pC->movetoTarget);
        81560  +      pC->movetoTarget = sqlite3BtreeIntegerKey(pC->uc.pCursor);
 81114  81561       }
 81115  81562     }else{
 81116  81563       zDb = 0;   /* Not needed.  Silence a compiler warning. */
 81117  81564       pTab = 0;  /* Not needed.  Silence a compiler warning. */
 81118  81565     }
 81119  81566   
 81120  81567   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
................................................................................
 81260  81707   ** of a real table, not a pseudo-table.
 81261  81708   */
 81262  81709   case OP_RowKey:
 81263  81710   case OP_RowData: {
 81264  81711     VdbeCursor *pC;
 81265  81712     BtCursor *pCrsr;
 81266  81713     u32 n;
 81267         -  i64 n64;
 81268  81714   
 81269  81715     pOut = &aMem[pOp->p2];
 81270  81716     memAboutToChange(p, pOut);
 81271  81717   
 81272  81718     /* Note that RowKey and RowData are really exactly the same instruction */
 81273  81719     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 81274  81720     pC = p->apCsr[pOp->p1];
................................................................................
 81278  81724     assert( pC->isTable || pOp->opcode!=OP_RowData );
 81279  81725     assert( pC->isTable==0 || pOp->opcode==OP_RowData );
 81280  81726     assert( pC->nullRow==0 );
 81281  81727     assert( pC->uc.pCursor!=0 );
 81282  81728     pCrsr = pC->uc.pCursor;
 81283  81729   
 81284  81730     /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
 81285         -  ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
 81286         -  ** the cursor.  If this where not the case, on of the following assert()s
        81731  +  ** OP_SeekRowid or OP_Rewind/Op_Next with no intervening instructions
        81732  +  ** that might invalidate the cursor.
        81733  +  ** If this where not the case, on of the following assert()s
 81287  81734     ** would fail.  Should this ever change (because of changes in the code
 81288  81735     ** generator) then the fix would be to insert a call to
 81289  81736     ** sqlite3VdbeCursorMoveto().
 81290  81737     */
 81291  81738     assert( pC->deferredMoveto==0 );
 81292  81739     assert( sqlite3BtreeCursorIsValid(pCrsr) );
 81293  81740   #if 0  /* Not required due to the previous to assert() statements */
 81294  81741     rc = sqlite3VdbeCursorMoveto(pC);
 81295  81742     if( rc!=SQLITE_OK ) goto abort_due_to_error;
 81296  81743   #endif
 81297  81744   
 81298         -  if( pC->isTable==0 ){
 81299         -    assert( !pC->isTable );
 81300         -    VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
 81301         -    assert( rc==SQLITE_OK );    /* True because of CursorMoveto() call above */
 81302         -    if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
 81303         -      goto too_big;
 81304         -    }
 81305         -    n = (u32)n64;
 81306         -  }else{
 81307         -    VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &n);
 81308         -    assert( rc==SQLITE_OK );    /* DataSize() cannot fail */
 81309         -    if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
 81310         -      goto too_big;
 81311         -    }
        81745  +  n = sqlite3BtreePayloadSize(pCrsr);
        81746  +  if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
        81747  +    goto too_big;
 81312  81748     }
 81313  81749     testcase( n==0 );
 81314  81750     if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
 81315  81751       goto no_mem;
 81316  81752     }
 81317  81753     pOut->n = n;
 81318  81754     MemSetTypeFlag(pOut, MEM_Blob);
................................................................................
 81369  81805       assert( pC->uc.pCursor!=0 );
 81370  81806       rc = sqlite3VdbeCursorRestore(pC);
 81371  81807       if( rc ) goto abort_due_to_error;
 81372  81808       if( pC->nullRow ){
 81373  81809         pOut->flags = MEM_Null;
 81374  81810         break;
 81375  81811       }
 81376         -    rc = sqlite3BtreeKeySize(pC->uc.pCursor, &v);
 81377         -    assert( rc==SQLITE_OK );  /* Always so because of CursorRestore() above */
        81812  +    v = sqlite3BtreeIntegerKey(pC->uc.pCursor);
 81378  81813     }
 81379  81814     pOut->u.i = v;
 81380  81815     break;
 81381  81816   }
 81382  81817   
 81383  81818   /* Opcode: NullRow P1 * * * *
 81384  81819   **
................................................................................
 81645  82080   **
 81646  82081   ** This instruction only works for indices.  The equivalent instruction
 81647  82082   ** for tables is OP_Insert.
 81648  82083   */
 81649  82084   case OP_SorterInsert:       /* in2 */
 81650  82085   case OP_IdxInsert: {        /* in2 */
 81651  82086     VdbeCursor *pC;
 81652         -  int nKey;
 81653         -  const char *zKey;
        82087  +  BtreePayload x;
 81654  82088   
 81655  82089     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 81656  82090     pC = p->apCsr[pOp->p1];
 81657  82091     assert( pC!=0 );
 81658  82092     assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) );
 81659  82093     pIn2 = &aMem[pOp->p2];
 81660  82094     assert( pIn2->flags & MEM_Blob );
................................................................................
 81662  82096     assert( pC->eCurType==CURTYPE_BTREE || pOp->opcode==OP_SorterInsert );
 81663  82097     assert( pC->isTable==0 );
 81664  82098     rc = ExpandBlob(pIn2);
 81665  82099     if( rc ) goto abort_due_to_error;
 81666  82100     if( pOp->opcode==OP_SorterInsert ){
 81667  82101       rc = sqlite3VdbeSorterWrite(pC, pIn2);
 81668  82102     }else{
 81669         -    nKey = pIn2->n;
 81670         -    zKey = pIn2->z;
 81671         -    rc = sqlite3BtreeInsert(pC->uc.pCursor, zKey, nKey, "", 0, 0, pOp->p3, 
        82103  +    x.nKey = pIn2->n;
        82104  +    x.pKey = pIn2->z;
        82105  +    x.nData = 0;
        82106  +    x.nZero = 0;
        82107  +    x.pData = 0;
        82108  +    rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, pOp->p3, 
 81672  82109           ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
 81673  82110           );
 81674  82111       assert( pC->deferredMoveto==0 );
 81675  82112       pC->cacheStatus = CACHE_STALE;
 81676  82113     }
 81677  82114     if( rc) goto abort_due_to_error;
 81678  82115     break;
................................................................................
 83432  83869   ** the UTF-8 string contained in P4 is emitted on the trace callback.
 83433  83870   ** Or if P4 is blank, use the string returned by sqlite3_sql().
 83434  83871   **
 83435  83872   ** If P2 is not zero, jump to instruction P2.
 83436  83873   */
 83437  83874   case OP_Init: {          /* jump */
 83438  83875     char *zTrace;
 83439         -  char *z;
        83876  +
        83877  +  /* If the P4 argument is not NULL, then it must be an SQL comment string.
        83878  +  ** The "--" string is broken up to prevent false-positives with srcck1.c.
        83879  +  **
        83880  +  ** This assert() provides evidence for:
        83881  +  ** EVIDENCE-OF: R-50676-09860 The callback can compute the same text that
        83882  +  ** would have been returned by the legacy sqlite3_trace() interface by
        83883  +  ** using the X argument when X begins with "--" and invoking
        83884  +  ** sqlite3_expanded_sql(P) otherwise.
        83885  +  */
        83886  +  assert( pOp->p4.z==0 || strncmp(pOp->p4.z, "-" "- ", 3)==0 );
 83440  83887   
 83441  83888   #ifndef SQLITE_OMIT_TRACE
 83442         -  if( db->xTrace
        83889  +  if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0
 83443  83890      && !p->doingRerun
 83444  83891      && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
 83445  83892     ){
 83446         -    z = sqlite3VdbeExpandSql(p, zTrace);
 83447         -    db->xTrace(db->pTraceArg, z);
 83448         -    sqlite3DbFree(db, z);
        83893  +#ifndef SQLITE_OMIT_DEPRECATED
        83894  +    if( db->mTrace & SQLITE_TRACE_LEGACY ){
        83895  +      void (*x)(void*,const char*) = (void(*)(void*,const char*))db->xTrace;
        83896  +      char *z = sqlite3VdbeExpandSql(p, zTrace);
        83897  +      x(db->pTraceArg, z);
        83898  +      sqlite3_free(z);
        83899  +    }else
        83900  +#endif
        83901  +    {
        83902  +      (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, zTrace);
        83903  +    }
 83449  83904     }
 83450  83905   #ifdef SQLITE_USE_FCNTL_TRACE
 83451  83906     zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
 83452  83907     if( zTrace ){
 83453  83908       int i;
 83454  83909       for(i=0; i<db->nDb; i++){
 83455  83910         if( DbMaskTest(p->btreeMask, i)==0 ) continue;
................................................................................
 83715  84170     *pzErr = zErr;
 83716  84171     return rc;
 83717  84172   }
 83718  84173   
 83719  84174   /*
 83720  84175   ** Open a blob handle.
 83721  84176   */
 83722         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_open(
        84177  +SQLITE_API int SQLITE_APICALL sqlite3_blob_open(
 83723  84178     sqlite3* db,            /* The database connection */
 83724  84179     const char *zDb,        /* The attached database containing the blob */
 83725  84180     const char *zTable,     /* The table containing the blob */
 83726  84181     const char *zColumn,    /* The column containing the blob */
 83727  84182     sqlite_int64 iRow,      /* The row containing the glob */
 83728  84183     int flags,              /* True -> read/write access, false -> read-only */
 83729  84184     sqlite3_blob **ppBlob   /* Handle for accessing the blob returned here */
................................................................................
 83956  84411     return rc;
 83957  84412   }
 83958  84413   
 83959  84414   /*
 83960  84415   ** Close a blob handle that was previously created using
 83961  84416   ** sqlite3_blob_open().
 83962  84417   */
 83963         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *pBlob){
        84418  +SQLITE_API int SQLITE_APICALL sqlite3_blob_close(sqlite3_blob *pBlob){
 83964  84419     Incrblob *p = (Incrblob *)pBlob;
 83965  84420     int rc;
 83966  84421     sqlite3 *db;
 83967  84422   
 83968  84423     if( p ){
 83969  84424       db = p->db;
 83970  84425       sqlite3_mutex_enter(db->mutex);
................................................................................
 84024  84479         ** SQLITE_UPDATE where the PK columns do not change is handled in the 
 84025  84480         ** same way as an SQLITE_DELETE (the SQLITE_DELETE code is actually
 84026  84481         ** slightly more efficient). Since you cannot write to a PK column
 84027  84482         ** using the incremental-blob API, this works. For the sessions module
 84028  84483         ** anyhow.
 84029  84484         */
 84030  84485         sqlite3_int64 iKey;
 84031         -      sqlite3BtreeKeySize(p->pCsr, &iKey);
        84486  +      iKey = sqlite3BtreeIntegerKey(p->pCsr);
 84032  84487         sqlite3VdbePreUpdateHook(
 84033  84488             v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1
 84034  84489         );
 84035  84490       }
 84036  84491   #endif
 84037  84492   
 84038  84493       rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
................................................................................
 84049  84504     sqlite3_mutex_leave(db->mutex);
 84050  84505     return rc;
 84051  84506   }
 84052  84507   
 84053  84508   /*
 84054  84509   ** Read data from a blob handle.
 84055  84510   */
 84056         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){
        84511  +SQLITE_API int SQLITE_APICALL sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){
 84057  84512     return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreeData);
 84058  84513   }
 84059  84514   
 84060  84515   /*
 84061  84516   ** Write data to a blob handle.
 84062  84517   */
 84063         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_write(sqlite3_blob *pBlob, const void *z, int n, int iOffset){
        84518  +SQLITE_API int SQLITE_APICALL sqlite3_blob_write(sqlite3_blob *pBlob, const void *z, int n, int iOffset){
 84064  84519     return blobReadWrite(pBlob, (void *)z, n, iOffset, sqlite3BtreePutData);
 84065  84520   }
 84066  84521   
 84067  84522   /*
 84068  84523   ** Query a blob handle for the size of the data.
 84069  84524   **
 84070  84525   ** The Incrblob.nByte field is fixed for the lifetime of the Incrblob
 84071  84526   ** so no mutex is required for access.
 84072  84527   */
 84073         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *pBlob){
        84528  +SQLITE_API int SQLITE_APICALL sqlite3_blob_bytes(sqlite3_blob *pBlob){
 84074  84529     Incrblob *p = (Incrblob *)pBlob;
 84075  84530     return (p && p->pStmt) ? p->nByte : 0;
 84076  84531   }
 84077  84532   
 84078  84533   /*
 84079  84534   ** Move an existing blob handle to point to a different row of the same
 84080  84535   ** database table.
................................................................................
 84081  84536   **
 84082  84537   ** If an error occurs, or if the specified row does not exist or does not
 84083  84538   ** contain a blob or text value, then an error code is returned and the
 84084  84539   ** database handle error code and message set. If this happens, then all 
 84085  84540   ** subsequent calls to sqlite3_blob_xxx() functions (except blob_close()) 
 84086  84541   ** immediately return SQLITE_ABORT.
 84087  84542   */
 84088         -SQLITE_API int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *pBlob, sqlite3_int64 iRow){
        84543  +SQLITE_API int SQLITE_APICALL sqlite3_blob_reopen(sqlite3_blob *pBlob, sqlite3_int64 iRow){
 84089  84544     int rc;
 84090  84545     Incrblob *p = (Incrblob *)pBlob;
 84091  84546     sqlite3 *db;
 84092  84547   
 84093  84548     if( p==0 ) return SQLITE_MISUSE_BKPT;
 84094  84549     db = p->db;
 84095  84550     sqlite3_mutex_enter(db->mutex);
................................................................................
 85459  85914     }
 85460  85915     return SQLITE_OK;
 85461  85916   }
 85462  85917   
 85463  85918   
 85464  85919   /*
 85465  85920   ** Merge the two sorted lists p1 and p2 into a single list.
 85466         -** Set *ppOut to the head of the new list.
 85467  85921   */
 85468         -static void vdbeSorterMerge(
        85922  +static SorterRecord *vdbeSorterMerge(
 85469  85923     SortSubtask *pTask,             /* Calling thread context */
 85470  85924     SorterRecord *p1,               /* First list to merge */
 85471         -  SorterRecord *p2,               /* Second list to merge */
 85472         -  SorterRecord **ppOut            /* OUT: Head of merged list */
        85925  +  SorterRecord *p2                /* Second list to merge */
 85473  85926   ){
 85474  85927     SorterRecord *pFinal = 0;
 85475  85928     SorterRecord **pp = &pFinal;
 85476  85929     int bCached = 0;
 85477  85930   
 85478         -  while( p1 && p2 ){
        85931  +  assert( p1!=0 && p2!=0 );
        85932  +  for(;;){
 85479  85933       int res;
 85480  85934       res = pTask->xCompare(
 85481  85935           pTask, &bCached, SRVAL(p1), p1->nVal, SRVAL(p2), p2->nVal
 85482  85936       );
 85483  85937   
 85484  85938       if( res<=0 ){
 85485  85939         *pp = p1;
 85486  85940         pp = &p1->u.pNext;
 85487  85941         p1 = p1->u.pNext;
        85942  +      if( p1==0 ){
        85943  +        *pp = p2;
        85944  +        break;
        85945  +      }
 85488  85946       }else{
 85489  85947         *pp = p2;
 85490  85948         pp = &p2->u.pNext;
 85491  85949         p2 = p2->u.pNext;
 85492  85950         bCached = 0;
        85951  +      if( p2==0 ){
        85952  +        *pp = p1;
        85953  +        break;
        85954  +      }
 85493  85955       }
 85494  85956     }
 85495         -  *pp = p1 ? p1 : p2;
 85496         -  *ppOut = pFinal;
        85957  +  return pFinal;
 85497  85958   }
 85498  85959   
 85499  85960   /*
 85500  85961   ** Return the SorterCompare function to compare values collected by the
 85501  85962   ** sorter object passed as the only argument.
 85502  85963   */
 85503  85964   static SorterCompare vdbeSorterGetCompare(VdbeSorter *p){
................................................................................
 85542  86003         }
 85543  86004       }else{
 85544  86005         pNext = p->u.pNext;
 85545  86006       }
 85546  86007   
 85547  86008       p->u.pNext = 0;
 85548  86009       for(i=0; aSlot[i]; i++){
 85549         -      vdbeSorterMerge(pTask, p, aSlot[i], &p);
        86010  +      p = vdbeSorterMerge(pTask, p, aSlot[i]);
 85550  86011         aSlot[i] = 0;
 85551  86012       }
 85552  86013       aSlot[i] = p;
 85553  86014       p = pNext;
 85554  86015     }
 85555  86016   
 85556  86017     p = 0;
 85557  86018     for(i=0; i<64; i++){
 85558         -    vdbeSorterMerge(pTask, p, aSlot[i], &p);
        86019  +    if( aSlot[i]==0 ) continue;
        86020  +    p = p ? vdbeSorterMerge(pTask, p, aSlot[i]) : aSlot[i];
 85559  86021     }
 85560  86022     pList->pList = p;
 85561  86023   
 85562  86024     sqlite3_free(aSlot);
 85563  86025     assert( pTask->pUnpacked->errCode==SQLITE_OK 
 85564  86026          || pTask->pUnpacked->errCode==SQLITE_NOMEM 
 85565  86027     );
................................................................................
 90771  91233             sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
 90772  91234             sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
 90773  91235             VdbeComment((v, "%s", pIdx->zName));
 90774  91236             assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
 90775  91237             eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
 90776  91238   
 90777  91239             if( prRhsHasNull && !pTab->aCol[iCol].notNull ){
        91240  +#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
        91241  +            const i64 sOne = 1;
        91242  +            sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, 
        91243  +                iTab, 0, 0, (u8*)&sOne, P4_INT64);
        91244  +#endif
 90778  91245               *prRhsHasNull = ++pParse->nMem;
 90779  91246               sqlite3SetHasNullFlag(v, iTab, *prRhsHasNull);
 90780  91247             }
 90781  91248             sqlite3VdbeJumpHere(v, iAddr);
 90782  91249           }
 90783  91250         }
 90784  91251       }
 90785  91252     }
 90786  91253   
 90787  91254     /* If no preexisting index is available for the IN clause
 90788  91255     ** and IN_INDEX_NOOP is an allowed reply
 90789  91256     ** and the RHS of the IN operator is a list, not a subquery
 90790         -  ** and the RHS is not contant or has two or fewer terms,
        91257  +  ** and the RHS is not constant or has two or fewer terms,
 90791  91258     ** then it is not worth creating an ephemeral table to evaluate
 90792  91259     ** the IN operator so return IN_INDEX_NOOP.
 90793  91260     */
 90794  91261     if( eType==0
 90795  91262      && (inFlags & IN_INDEX_NOOP_OK)
 90796  91263      && !ExprHasProperty(pX, EP_xIsSelect)
 90797  91264      && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
................................................................................
 91175  91642           sqlite3VdbeJumpHere(v, addr1);
 91176  91643         }
 91177  91644       }
 91178  91645     
 91179  91646       if( eType==IN_INDEX_ROWID ){
 91180  91647         /* In this case, the RHS is the ROWID of table b-tree
 91181  91648         */
 91182         -      sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse); VdbeCoverage(v);
 91183         -      sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, destIfFalse, r1);
        91649  +      sqlite3VdbeAddOp3(v, OP_SeekRowid, pExpr->iTable, destIfFalse, r1);
 91184  91650         VdbeCoverage(v);
 91185  91651       }else{
 91186  91652         /* In this case, the RHS is an index b-tree.
 91187  91653         */
 91188  91654         sqlite3VdbeAddOp4(v, OP_Affinity, r1, 1, 0, &affinity, 1);
 91189  91655     
 91190  91656         /* If the set membership test fails, then the result of the 
................................................................................
 91489  91955     int regOut      /* Extract the value into this register */
 91490  91956   ){
 91491  91957     if( iCol<0 || iCol==pTab->iPKey ){
 91492  91958       sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
 91493  91959     }else{
 91494  91960       int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
 91495  91961       int x = iCol;
 91496         -    if( !HasRowid(pTab) ){
        91962  +    if( !HasRowid(pTab) && !IsVirtual(pTab) ){
 91497  91963         x = sqlite3ColumnOfIndex(sqlite3PrimaryKeyIndex(pTab), iCol);
 91498  91964       }
 91499  91965       sqlite3VdbeAddOp3(v, op, iTabCur, x, regOut);
 91500  91966     }
 91501  91967     if( iCol>=0 ){
 91502  91968       sqlite3ColumnDefault(v, pTab, iCol, regOut);
 91503  91969     }
................................................................................
 92913  93379      && sqlite3ExprCompare(pE1->pLeft, pE2->pLeft, iTab)==0
 92914  93380      && (pE1->op!=TK_ISNULL && pE1->op!=TK_IS)
 92915  93381     ){
 92916  93382       return 1;
 92917  93383     }
 92918  93384     return 0;
 92919  93385   }
        93386  +
        93387  +/*
        93388  +** An instance of the following structure is used by the tree walker
        93389  +** to determine if an expression can be evaluated by reference to the
        93390  +** index only, without having to do a search for the corresponding
        93391  +** table entry.  The IdxCover.pIdx field is the index.  IdxCover.iCur
        93392  +** is the cursor for the table.
        93393  +*/
        93394  +struct IdxCover {
        93395  +  Index *pIdx;     /* The index to be tested for coverage */
        93396  +  int iCur;        /* Cursor number for the table corresponding to the index */
        93397  +};
        93398  +
        93399  +/*
        93400  +** Check to see if there are references to columns in table 
        93401  +** pWalker->u.pIdxCover->iCur can be satisfied using the index
        93402  +** pWalker->u.pIdxCover->pIdx.
        93403  +*/
        93404  +static int exprIdxCover(Walker *pWalker, Expr *pExpr){
        93405  +  if( pExpr->op==TK_COLUMN
        93406  +   && pExpr->iTable==pWalker->u.pIdxCover->iCur
        93407  +   && sqlite3ColumnOfIndex(pWalker->u.pIdxCover->pIdx, pExpr->iColumn)<0
        93408  +  ){
        93409  +    pWalker->eCode = 1;
        93410  +    return WRC_Abort;
        93411  +  }
        93412  +  return WRC_Continue;
        93413  +}
        93414  +
        93415  +/*
        93416  +** Determine if an index pIdx on table with cursor iCur contains will
        93417  +** the expression pExpr.  Return true if the index does cover the
        93418  +** expression and false if the pExpr expression references table columns
        93419  +** that are not found in the index pIdx.
        93420  +**
        93421  +** An index covering an expression means that the expression can be
        93422  +** evaluated using only the index and without having to lookup the
        93423  +** corresponding table entry.
        93424  +*/
        93425  +SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(
        93426  +  Expr *pExpr,        /* The index to be tested */
        93427  +  int iCur,           /* The cursor number for the corresponding table */
        93428  +  Index *pIdx         /* The index that might be used for coverage */
        93429  +){
        93430  +  Walker w;
        93431  +  struct IdxCover xcov;
        93432  +  memset(&w, 0, sizeof(w));
        93433  +  xcov.iCur = iCur;
        93434  +  xcov.pIdx = pIdx;
        93435  +  w.xExprCallback = exprIdxCover;
        93436  +  w.u.pIdxCover = &xcov;
        93437  +  sqlite3WalkExpr(&w, pExpr);
        93438  +  return !w.eCode;
        93439  +}
        93440  +
 92920  93441   
 92921  93442   /*
 92922  93443   ** An instance of the following structure is used by the tree walker
 92923  93444   ** to count references to table columns in the arguments of an 
 92924  93445   ** aggregate function, in order to implement the
 92925  93446   ** sqlite3FunctionThisSrc() routine.
 92926  93447   */
................................................................................
 93868  94389     const char *zDb;          /* Database name */
 93869  94390     const char *zTab;         /* Table name */
 93870  94391     char *zCol;               /* Null-terminated column definition */
 93871  94392     Column *pCol;             /* The new column */
 93872  94393     Expr *pDflt;              /* Default value for the new column */
 93873  94394     sqlite3 *db;              /* The database connection; */
 93874  94395     Vdbe *v = pParse->pVdbe;  /* The prepared statement under construction */
        94396  +  int r1;                   /* Temporary registers */
 93875  94397   
 93876  94398     db = pParse->db;
 93877  94399     if( pParse->nErr || db->mallocFailed ) return;
 93878  94400     assert( v!=0 );
 93879  94401     pNew = pParse->pNewTable;
 93880  94402     assert( pNew );
 93881  94403   
................................................................................
 93962  94484         zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1,
 93963  94485         zTab
 93964  94486       );
 93965  94487       sqlite3DbFree(db, zCol);
 93966  94488       db->flags = savedDbFlags;
 93967  94489     }
 93968  94490   
 93969         -  /* If the default value of the new column is NULL, then the file
 93970         -  ** format to 2. If the default value of the new column is not NULL,
 93971         -  ** the file format be 3.  Back when this feature was first added
 93972         -  ** in 2006, we went to the trouble to upgrade the file format to the
 93973         -  ** minimum support values.  But 10-years on, we can assume that all
 93974         -  ** extent versions of SQLite support file-format 4, so we always and
 93975         -  ** unconditionally upgrade to 4.
        94491  +  /* Make sure the schema version is at least 3.  But do not upgrade
        94492  +  ** from less than 3 to 4, as that will corrupt any preexisting DESC
        94493  +  ** index.
 93976  94494     */
 93977         -  sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 
 93978         -                    SQLITE_MAX_FILE_FORMAT);
        94495  +  r1 = sqlite3GetTempReg(pParse);
        94496  +  sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
        94497  +  sqlite3VdbeUsesBtree(v, iDb);
        94498  +  sqlite3VdbeAddOp2(v, OP_AddImm, r1, -2);
        94499  +  sqlite3VdbeAddOp2(v, OP_IfPos, r1, sqlite3VdbeCurrentAddr(v)+2);
        94500  +  VdbeCoverage(v);
        94501  +  sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3);
        94502  +  sqlite3ReleaseTempReg(pParse, r1);
 93979  94503   
 93980  94504     /* Reload the schema of the modified table. */
 93981  94505     reloadTableSchema(pParse, pTab, pTab->zName);
 93982  94506   }
 93983  94507   
 93984  94508   /*
 93985  94509   ** This function is called by the parser after the table-name in
................................................................................
 96616  97140   ** will return with an error.  SQLITE_IGNORE means that the SQL statement
 96617  97141   ** should run but attempts to read the specified column will return NULL
 96618  97142   ** and attempts to write the column will be ignored.
 96619  97143   **
 96620  97144   ** Setting the auth function to NULL disables this hook.  The default
 96621  97145   ** setting of the auth function is NULL.
 96622  97146   */
 96623         -SQLITE_API int SQLITE_STDCALL sqlite3_set_authorizer(
        97147  +SQLITE_API int SQLITE_APICALL sqlite3_set_authorizer(
 96624  97148     sqlite3 *db,
 96625  97149     int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
 96626  97150     void *pArg
 96627  97151   ){
 96628  97152   #ifdef SQLITE_ENABLE_API_ARMOR
 96629  97153     if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
 96630  97154   #endif
................................................................................
 96660  97184     const char *zCol,               /* Column name */
 96661  97185     int iDb                         /* Index of containing database. */
 96662  97186   ){
 96663  97187     sqlite3 *db = pParse->db;       /* Database handle */
 96664  97188     char *zDb = db->aDb[iDb].zName; /* Name of attached database */
 96665  97189     int rc;                         /* Auth callback return code */
 96666  97190   
        97191  +  if( db->init.busy ) return SQLITE_OK;
 96667  97192     rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
 96668  97193   #ifdef SQLITE_USER_AUTHENTICATION
 96669  97194                    ,db->auth.zAuthUser
 96670  97195   #endif
 96671  97196                   );
 96672  97197     if( rc==SQLITE_DENY ){
 96673  97198       if( db->nDb>2 || iDb!=0 ){
................................................................................
 97150  97675   **
 97151  97676   ** The difference between this routine and sqlite3FindTable() is that this
 97152  97677   ** routine leaves an error message in pParse->zErrMsg where
 97153  97678   ** sqlite3FindTable() does not.
 97154  97679   */
 97155  97680   SQLITE_PRIVATE Table *sqlite3LocateTable(
 97156  97681     Parse *pParse,         /* context in which to report errors */
 97157         -  int isView,            /* True if looking for a VIEW rather than a TABLE */
        97682  +  u32 flags,             /* LOCATE_VIEW or LOCATE_NOERR */
 97158  97683     const char *zName,     /* Name of the table we are looking for */
 97159  97684     const char *zDbase     /* Name of the database.  Might be NULL */
 97160  97685   ){
 97161  97686     Table *p;
 97162  97687   
 97163  97688     /* Read the database schema. If an error occurs, leave an error message
 97164  97689     ** and code in pParse and return NULL. */
 97165  97690     if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
 97166  97691       return 0;
 97167  97692     }
 97168  97693   
 97169  97694     p = sqlite3FindTable(pParse->db, zName, zDbase);
 97170  97695     if( p==0 ){
 97171         -    const char *zMsg = isView ? "no such view" : "no such table";
        97696  +    const char *zMsg = flags & LOCATE_VIEW ? "no such view" : "no such table";
 97172  97697   #ifndef SQLITE_OMIT_VIRTUALTABLE
 97173  97698       if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
 97174  97699         /* If zName is the not the name of a table in the schema created using
 97175  97700         ** CREATE, then check to see if it is the name of an virtual table that
 97176  97701         ** can be an eponymous virtual table. */
 97177  97702         Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
 97178  97703         if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
 97179  97704           return pMod->pEpoTab;
 97180  97705         }
 97181  97706       }
 97182  97707   #endif
 97183         -    if( zDbase ){
 97184         -      sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
 97185         -    }else{
 97186         -      sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
        97708  +    if( (flags & LOCATE_NOERR)==0 ){
        97709  +      if( zDbase ){
        97710  +        sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
        97711  +      }else{
        97712  +        sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
        97713  +      }
        97714  +      pParse->checkSchema = 1;
 97187  97715       }
 97188         -    pParse->checkSchema = 1;
 97189  97716     }
 97190  97717   
 97191  97718     return p;
 97192  97719   }
 97193  97720   
 97194  97721   /*
 97195  97722   ** Locate the table identified by *p.
................................................................................
 97198  97725   ** sqlite3LocateTable() and this function is that this function restricts
 97199  97726   ** the search to schema (p->pSchema) if it is not NULL. p->pSchema may be
 97200  97727   ** non-NULL if it is part of a view or trigger program definition. See
 97201  97728   ** sqlite3FixSrcList() for details.
 97202  97729   */
 97203  97730   SQLITE_PRIVATE Table *sqlite3LocateTableItem(
 97204  97731     Parse *pParse, 
 97205         -  int isView, 
        97732  +  u32 flags,
 97206  97733     struct SrcList_item *p
 97207  97734   ){
 97208  97735     const char *zDb;
 97209  97736     assert( p->pSchema==0 || p->zDatabase==0 );
 97210  97737     if( p->pSchema ){
 97211  97738       int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
 97212  97739       zDb = pParse->db->aDb[iDb].zName;
 97213  97740     }else{
 97214  97741       zDb = p->zDatabase;
 97215  97742     }
 97216         -  return sqlite3LocateTable(pParse, isView, p->zName, zDb);
        97743  +  return sqlite3LocateTable(pParse, flags, p->zName, zDb);
 97217  97744   }
 97218  97745   
 97219  97746   /*
 97220  97747   ** Locate the in-memory structure that describes 
 97221  97748   ** a particular index given the name of that index
 97222  97749   ** and the name of the database that contains the index.
 97223  97750   ** Return NULL if not found.
................................................................................
 97417  97944     ** lookaside, this number should not change. */
 97418  97945     TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
 97419  97946                            db->lookaside.nOut : 0 );
 97420  97947   
 97421  97948     /* Delete all indices associated with this table. */
 97422  97949     for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
 97423  97950       pNext = pIndex->pNext;
 97424         -    assert( pIndex->pSchema==pTable->pSchema );
 97425         -    if( !db || db->pnBytesFreed==0 ){
        97951  +    assert( pIndex->pSchema==pTable->pSchema
        97952  +         || (IsVirtual(pTable) && pIndex->idxType!=SQLITE_IDXTYPE_APPDEF) );
        97953  +    if( (db==0 || db->pnBytesFreed==0) && !IsVirtual(pTable) ){
 97426  97954         char *zName = pIndex->zName; 
 97427  97955         TESTONLY ( Index *pOld = ) sqlite3HashInsert(
 97428  97956            &pIndex->pSchema->idxHash, zName, 0
 97429  97957         );
 97430  97958         assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
 97431  97959         assert( pOld==pIndex || pOld==0 );
 97432  97960       }
................................................................................
 98100  98628     int autoInc,      /* True if the AUTOINCREMENT keyword is present */
 98101  98629     int sortOrder     /* SQLITE_SO_ASC or SQLITE_SO_DESC */
 98102  98630   ){
 98103  98631     Table *pTab = pParse->pNewTable;
 98104  98632     Column *pCol = 0;
 98105  98633     int iCol = -1, i;
 98106  98634     int nTerm;
 98107         -  if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
        98635  +  if( pTab==0 ) goto primary_key_exit;
 98108  98636     if( pTab->tabFlags & TF_HasPrimaryKey ){
 98109  98637       sqlite3ErrorMsg(pParse, 
 98110  98638         "table \"%s\" has more than one primary key", pTab->zName);
 98111  98639       goto primary_key_exit;
 98112  98640     }
 98113  98641     pTab->tabFlags |= TF_HasPrimaryKey;
 98114  98642     if( pList==0 ){
................................................................................
 98146  98674       if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;
 98147  98675     }else if( autoInc ){
 98148  98676   #ifndef SQLITE_OMIT_AUTOINCREMENT
 98149  98677       sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
 98150  98678          "INTEGER PRIMARY KEY");
 98151  98679   #endif
 98152  98680     }else{
 98153         -    Index *p;
 98154         -    p = sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
 98155         -                           0, sortOrder, 0);
 98156         -    if( p ){
 98157         -      p->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
 98158         -    }
        98681  +    sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
        98682  +                           0, sortOrder, 0, SQLITE_IDXTYPE_PRIMARYKEY);
 98159  98683       pList = 0;
 98160  98684     }
 98161  98685   
 98162  98686   primary_key_exit:
 98163  98687     sqlite3ExprListDelete(pParse->db, pList);
 98164  98688     return;
 98165  98689   }
................................................................................
 98468  98992   /*
 98469  98993   ** This routine runs at the end of parsing a CREATE TABLE statement that
 98470  98994   ** has a WITHOUT ROWID clause.  The job of this routine is to convert both
 98471  98995   ** internal schema data structures and the generated VDBE code so that they
 98472  98996   ** are appropriate for a WITHOUT ROWID table instead of a rowid table.
 98473  98997   ** Changes include:
 98474  98998   **
 98475         -**     (1)  Convert the OP_CreateTable into an OP_CreateIndex.  There is
        98999  +**     (1)  Set all columns of the PRIMARY KEY schema object to be NOT NULL.
        99000  +**     (2)  Convert the OP_CreateTable into an OP_CreateIndex.  There is
 98476  99001   **          no rowid btree for a WITHOUT ROWID.  Instead, the canonical
 98477  99002   **          data storage is a covering index btree.
 98478         -**     (2)  Bypass the creation of the sqlite_master table entry
        99003  +**     (3)  Bypass the creation of the sqlite_master table entry
 98479  99004   **          for the PRIMARY KEY as the primary key index is now
 98480  99005   **          identified by the sqlite_master table entry of the table itself.
 98481         -**     (3)  Set the Index.tnum of the PRIMARY KEY Index object in the
        99006  +**     (4)  Set the Index.tnum of the PRIMARY KEY Index object in the
 98482  99007   **          schema to the rootpage from the main table.
 98483         -**     (4)  Set all columns of the PRIMARY KEY schema object to be NOT NULL.
 98484  99008   **     (5)  Add all table columns to the PRIMARY KEY Index object
 98485  99009   **          so that the PRIMARY KEY is a covering index.  The surplus
 98486  99010   **          columns are part of KeyInfo.nXField and are not used for
 98487  99011   **          sorting or lookup or uniqueness checks.
 98488  99012   **     (6)  Replace the rowid tail on all automatically generated UNIQUE
 98489  99013   **          indices with the PRIMARY KEY columns.
        99014  +**
        99015  +** For virtual tables, only (1) is performed.
 98490  99016   */
 98491  99017   static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
 98492  99018     Index *pIdx;
 98493  99019     Index *pPk;
 98494  99020     int nPk;
 98495  99021     int i, j;
 98496  99022     sqlite3 *db = pParse->db;
 98497  99023     Vdbe *v = pParse->pVdbe;
        99024  +
        99025  +  /* Mark every PRIMARY KEY column as NOT NULL (except for imposter tables)
        99026  +  */
        99027  +  if( !db->init.imposterTable ){
        99028  +    for(i=0; i<pTab->nCol; i++){
        99029  +      if( (pTab->aCol[i].colFlags & COLFLAG_PRIMKEY)!=0 ){
        99030  +        pTab->aCol[i].notNull = OE_Abort;
        99031  +      }
        99032  +    }
        99033  +  }
        99034  +
        99035  +  /* The remaining transformations only apply to b-tree tables, not to
        99036  +  ** virtual tables */
        99037  +  if( IN_DECLARE_VTAB ) return;
 98498  99038   
 98499  99039     /* Convert the OP_CreateTable opcode that would normally create the
 98500  99040     ** root-page for the table into an OP_CreateIndex opcode.  The index
 98501  99041     ** created will become the PRIMARY KEY index.
 98502  99042     */
 98503  99043     if( pParse->addrCrTab ){
 98504  99044       assert( v );
................................................................................
 98513  99053       Token ipkToken;
 98514  99054       sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
 98515  99055       pList = sqlite3ExprListAppend(pParse, 0, 
 98516  99056                     sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
 98517  99057       if( pList==0 ) return;
 98518  99058       pList->a[0].sortOrder = pParse->iPkSortOrder;
 98519  99059       assert( pParse->pNewTable==pTab );
 98520         -    pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
 98521         -    if( pPk==0 ) return;
 98522         -    pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
        99060  +    sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
        99061  +                       SQLITE_IDXTYPE_PRIMARYKEY);
        99062  +    if( db->mallocFailed ) return;
        99063  +    pPk = sqlite3PrimaryKeyIndex(pTab);
 98523  99064       pTab->iPKey = -1;
 98524  99065     }else{
 98525  99066       pPk = sqlite3PrimaryKeyIndex(pTab);
 98526  99067   
 98527  99068       /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
 98528  99069       ** table entry. This is only required if currently generating VDBE
 98529  99070       ** code for a CREATE TABLE (not when parsing one as part of reading
................................................................................
 98543  99084           pPk->nColumn--;
 98544  99085         }else{
 98545  99086           pPk->aiColumn[j++] = pPk->aiColumn[i];
 98546  99087         }
 98547  99088       }
 98548  99089       pPk->nKeyCol = j;
 98549  99090     }
 98550         -  pPk->isCovering = 1;
 98551  99091     assert( pPk!=0 );
        99092  +  pPk->isCovering = 1;
        99093  +  if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
 98552  99094     nPk = pPk->nKeyCol;
 98553  99095   
 98554         -  /* Make sure every column of the PRIMARY KEY is NOT NULL.  (Except,
 98555         -  ** do not enforce this for imposter tables.) */
 98556         -  if( !db->init.imposterTable ){
 98557         -    for(i=0; i<nPk; i++){
 98558         -      pTab->aCol[pPk->aiColumn[i]].notNull = OE_Abort;
 98559         -    }
 98560         -    pPk->uniqNotNull = 1;
 98561         -  }
 98562         -
 98563  99096     /* The root page of the PRIMARY KEY is the table root page */
 98564  99097     pPk->tnum = pTab->tnum;
 98565  99098   
 98566  99099     /* Update the in-memory representation of all UNIQUE indices by converting
 98567  99100     ** the final rowid column into one or more columns of the PRIMARY KEY.
 98568  99101     */
 98569  99102     for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
................................................................................
 99310  99843     if( db->mallocFailed ){
 99311  99844       goto exit_drop_table;
 99312  99845     }
 99313  99846     assert( pParse->nErr==0 );
 99314  99847     assert( pName->nSrc==1 );
 99315  99848     if( sqlite3ReadSchema(pParse) ) goto exit_drop_table;
 99316  99849     if( noErr ) db->suppressErr++;
        99850  +  assert( isView==0 || isView==LOCATE_VIEW );
 99317  99851     pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
 99318  99852     if( noErr ) db->suppressErr--;
 99319  99853   
 99320  99854     if( pTab==0 ){
 99321  99855       if( noErr ) sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
 99322  99856       goto exit_drop_table;
 99323  99857     }
................................................................................
 99680 100214   ** UNIQUE constraint.  If pTable and pIndex are NULL, use pParse->pNewTable
 99681 100215   ** as the table to be indexed.  pParse->pNewTable is a table that is
 99682 100216   ** currently being constructed by a CREATE TABLE statement.
 99683 100217   **
 99684 100218   ** pList is a list of columns to be indexed.  pList will be NULL if this
 99685 100219   ** is a primary key or unique-constraint on the most recent column added
 99686 100220   ** to the table currently under construction.  
 99687         -**
 99688         -** If the index is created successfully, return a pointer to the new Index
 99689         -** structure. This is used by sqlite3AddPrimaryKey() to mark the index
 99690         -** as the tables primary key (Index.idxType==SQLITE_IDXTYPE_PRIMARYKEY)
 99691 100221   */
 99692         -SQLITE_PRIVATE Index *sqlite3CreateIndex(
       100222  +SQLITE_PRIVATE void sqlite3CreateIndex(
 99693 100223     Parse *pParse,     /* All information about this parse */
 99694 100224     Token *pName1,     /* First part of index name. May be NULL */
 99695 100225     Token *pName2,     /* Second part of index name. May be NULL */
 99696 100226     SrcList *pTblName, /* Table to index. Use pParse->pNewTable if 0 */
 99697 100227     ExprList *pList,   /* A list of columns to be indexed */
 99698 100228     int onError,       /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
 99699 100229     Token *pStart,     /* The CREATE token that begins this statement */
 99700 100230     Expr *pPIWhere,    /* WHERE clause for partial indices */
 99701 100231     int sortOrder,     /* Sort order of primary key when pList==NULL */
 99702         -  int ifNotExist     /* Omit error if index already exists */
       100232  +  int ifNotExist,    /* Omit error if index already exists */
       100233  +  u8 idxType         /* The index type */
 99703 100234   ){
 99704         -  Index *pRet = 0;     /* Pointer to return */
 99705 100235     Table *pTab = 0;     /* Table to be indexed */
 99706 100236     Index *pIndex = 0;   /* The index to be created */
 99707 100237     char *zName = 0;     /* Name of the index */
 99708 100238     int nName;           /* Number of characters in zName */
 99709 100239     int i, j;
 99710 100240     DbFixer sFix;        /* For assigning database names to pTable */
 99711 100241     int sortOrderMask;   /* 1 to honor DESC in index.  0 to ignore. */
................................................................................
 99715 100245     Token *pName = 0;    /* Unqualified name of the index to create */
 99716 100246     struct ExprList_item *pListItem; /* For looping over pList */
 99717 100247     int nExtra = 0;                  /* Space allocated for zExtra[] */
 99718 100248     int nExtraCol;                   /* Number of extra columns needed */
 99719 100249     char *zExtra = 0;                /* Extra space after the Index object */
 99720 100250     Index *pPk = 0;      /* PRIMARY KEY index for WITHOUT ROWID tables */
 99721 100251   
 99722         -  if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
       100252  +  if( db->mallocFailed || pParse->nErr>0 ){
       100253  +    goto exit_create_index;
       100254  +  }
       100255  +  if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
 99723 100256       goto exit_create_index;
 99724 100257     }
 99725 100258     if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
 99726 100259       goto exit_create_index;
 99727 100260     }
 99728 100261   
 99729 100262     /*
................................................................................
 99904 100437     assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) );
 99905 100438     pIndex->zName = zExtra;
 99906 100439     zExtra += nName + 1;
 99907 100440     memcpy(pIndex->zName, zName, nName+1);
 99908 100441     pIndex->pTable = pTab;
 99909 100442     pIndex->onError = (u8)onError;
 99910 100443     pIndex->uniqNotNull = onError!=OE_None;
 99911         -  pIndex->idxType = pName ? SQLITE_IDXTYPE_APPDEF : SQLITE_IDXTYPE_UNIQUE;
       100444  +  pIndex->idxType = idxType;
 99912 100445     pIndex->pSchema = db->aDb[iDb].pSchema;
 99913 100446     pIndex->nKeyCol = pList->nExpr;
 99914 100447     if( pPIWhere ){
 99915 100448       sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
 99916 100449       pIndex->pPartIdxWhere = pPIWhere;
 99917 100450       pPIWhere = 0;
 99918 100451     }
................................................................................
100084 100617               sqlite3ErrorMsg(pParse, 
100085 100618                   "conflicting ON CONFLICT clauses specified", 0);
100086 100619             }
100087 100620             if( pIdx->onError==OE_Default ){
100088 100621               pIdx->onError = pIndex->onError;
100089 100622             }
100090 100623           }
100091         -        pRet = pIdx;
       100624  +        if( idxType==SQLITE_IDXTYPE_PRIMARYKEY ) pIdx->idxType = idxType;
100092 100625           goto exit_create_index;
100093 100626         }
100094 100627       }
100095 100628     }
100096 100629   
100097 100630     /* Link the new Index structure to its table and to the other
100098 100631     ** in-memory database structures. 
100099 100632     */
100100 100633     assert( pParse->nErr==0 );
100101 100634     if( db->init.busy ){
100102 100635       Index *p;
       100636  +    assert( !IN_DECLARE_VTAB );
100103 100637       assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
100104 100638       p = sqlite3HashInsert(&pIndex->pSchema->idxHash, 
100105 100639                             pIndex->zName, pIndex);
100106 100640       if( p ){
100107 100641         assert( p==pIndex );  /* Malloc must have failed */
100108 100642         sqlite3OomFault(db);
100109 100643         goto exit_create_index;
................................................................................
100177 100711       ** to invalidate all pre-compiled statements.
100178 100712       */
100179 100713       if( pTblName ){
100180 100714         sqlite3RefillIndex(pParse, pIndex, iMem);
100181 100715         sqlite3ChangeCookie(pParse, iDb);
100182 100716         sqlite3VdbeAddParseSchemaOp(v, iDb,
100183 100717            sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
100184         -      sqlite3VdbeAddOp1(v, OP_Expire, 0);
       100718  +      sqlite3VdbeAddOp0(v, OP_Expire);
100185 100719       }
100186 100720   
100187 100721       sqlite3VdbeJumpHere(v, pIndex->tnum);
100188 100722     }
100189 100723   
100190 100724     /* When adding an index to the list of indices for a table, make
100191 100725     ** sure all indices labeled OE_Replace come after all those labeled
................................................................................
100202 100736         Index *pOther = pTab->pIndex;
100203 100737         while( pOther->pNext && pOther->pNext->onError!=OE_Replace ){
100204 100738           pOther = pOther->pNext;
100205 100739         }
100206 100740         pIndex->pNext = pOther->pNext;
100207 100741         pOther->pNext = pIndex;
100208 100742       }
100209         -    pRet = pIndex;
100210 100743       pIndex = 0;
100211 100744     }
100212 100745   
100213 100746     /* Clean up before exiting */
100214 100747   exit_create_index:
100215 100748     if( pIndex ) freeIndex(db, pIndex);
100216 100749     sqlite3ExprDelete(db, pPIWhere);
100217 100750     sqlite3ExprListDelete(db, pList);
100218 100751     sqlite3SrcListDelete(db, pTblName);
100219 100752     sqlite3DbFree(db, zName);
100220         -  return pRet;
100221 100753   }
100222 100754   
100223 100755   /*
100224 100756   ** Fill the Index.aiRowEst[] array with default information - information
100225 100757   ** to be used when we have not run the ANALYZE command.
100226 100758   **
100227 100759   ** aiRowEst[0] is supposed to contain the number of elements in the index.
................................................................................
100242 100774     /*                10,  9,  8,  7,  6 */
100243 100775     LogEst aVal[] = { 33, 32, 30, 28, 26 };
100244 100776     LogEst *a = pIdx->aiRowLogEst;
100245 100777     int nCopy = MIN(ArraySize(aVal), pIdx->nKeyCol);
100246 100778     int i;
100247 100779   
100248 100780     /* Set the first entry (number of rows in the index) to the estimated 
100249         -  ** number of rows in the table. Or 10, if the estimated number of rows 
100250         -  ** in the table is less than that.  */
       100781  +  ** number of rows in the table, or half the number of rows in the table
       100782  +  ** for a partial index.   But do not let the estimate drop below 10. */
100251 100783     a[0] = pIdx->pTable->nRowLogEst;
100252         -  if( a[0]<33 ) a[0] = 33;        assert( 33==sqlite3LogEst(10) );
       100784  +  if( pIdx->pPartIdxWhere!=0 ) a[0] -= 10;  assert( 10==sqlite3LogEst(2) );
       100785  +  if( a[0]<33 ) a[0] = 33;                  assert( 33==sqlite3LogEst(10) );
100253 100786   
100254 100787     /* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
100255 100788     ** 6 and each subsequent value (if any) is 5.  */
100256 100789     memcpy(&a[1], aVal, nCopy*sizeof(LogEst));
100257 100790     for(i=nCopy+1; i<=pIdx->nKeyCol; i++){
100258 100791       a[i] = 23;                    assert( 23==sqlite3LogEst(5) );
100259 100792     }
................................................................................
101127 101660     sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed");
101128 101661   }
101129 101662   #endif
101130 101663   
101131 101664   /*
101132 101665   ** Return a KeyInfo structure that is appropriate for the given Index.
101133 101666   **
101134         -** The KeyInfo structure for an index is cached in the Index object.
101135         -** So there might be multiple references to the returned pointer.  The
101136         -** caller should not try to modify the KeyInfo object.
101137         -**
101138 101667   ** The caller should invoke sqlite3KeyInfoUnref() on the returned object
101139 101668   ** when it has finished using it.
101140 101669   */
101141 101670   SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
101142 101671     int i;
101143 101672     int nCol = pIdx->nColumn;
101144 101673     int nKey = pIdx->nKeyCol;
................................................................................
103362 103891             return 0;
103363 103892           }
103364 103893           continue;
103365 103894         }
103366 103895       }
103367 103896       c2 = Utf8Read(zString);
103368 103897       if( c==c2 ) continue;
103369         -    if( noCase && c<0x80 && c2<0x80 && sqlite3Tolower(c)==sqlite3Tolower(c2) ){
       103898  +    if( noCase  && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){
103370 103899         continue;
103371 103900       }
103372 103901       if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue;
103373 103902       return 0;
103374 103903     }
103375 103904     return *zString==0;
103376 103905   }
103377 103906   
103378 103907   /*
103379 103908   ** The sqlite3_strglob() interface.
103380 103909   */
103381         -SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlobPattern, const char *zString){
       103910  +SQLITE_API int SQLITE_APICALL sqlite3_strglob(const char *zGlobPattern, const char *zString){
103382 103911     return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '[')==0;
103383 103912   }
103384 103913   
103385 103914   /*
103386 103915   ** The sqlite3_strlike() interface.
103387 103916   */
103388         -SQLITE_API int SQLITE_STDCALL sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){
       103917  +SQLITE_API int SQLITE_APICALL sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){
103389 103918     return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc)==0;
103390 103919   }
103391 103920   
103392 103921   /*
103393 103922   ** Count the number of times that the LIKE operator (or GLOB which is
103394 103923   ** just a variation of LIKE) gets called.  This is used for testing
103395 103924   ** only.
................................................................................
105821 106350   ** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
105822 106351   ** hash table.
105823 106352   */
105824 106353   SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
105825 106354     FKey *pFKey;                    /* Iterator variable */
105826 106355     FKey *pNext;                    /* Copy of pFKey->pNextFrom */
105827 106356   
105828         -  assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
       106357  +  assert( db==0 || IsVirtual(pTab)
       106358  +         || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
105829 106359     for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
105830 106360   
105831 106361       /* Remove the FK from the fkeyHash hash table. */
105832 106362       if( !db || db->pnBytesFreed==0 ){
105833 106363         if( pFKey->pPrevTo ){
105834 106364           pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
105835 106365         }else{
................................................................................
108076 108606   ** malloc() and make *pzErrMsg point to that message.
108077 108607   **
108078 108608   ** If the SQL is a query, then for each row in the query result
108079 108609   ** the xCallback() function is called.  pArg becomes the first
108080 108610   ** argument to xCallback().  If xCallback=NULL then no callback
108081 108611   ** is invoked, even for queries.
108082 108612   */
108083         -SQLITE_API int SQLITE_STDCALL sqlite3_exec(
       108613  +SQLITE_API int SQLITE_APICALL sqlite3_exec(
108084 108614     sqlite3 *db,                /* The database on which the SQL executes */
108085 108615     const char *zSql,           /* The SQL to be executed */
108086 108616     sqlite3_callback xCallback, /* Invoke this callback routine */
108087 108617     void *pArg,                 /* First argument to xCallback() */
108088 108618     char **pzErrMsg             /* Write error messages here */
108089 108619   ){
108090 108620     int rc = SQLITE_OK;         /* Return code */
................................................................................
108231 108761   *************************************************************************
108232 108762   ** This header file defines the SQLite interface for use by
108233 108763   ** shared libraries that want to be imported as extensions into
108234 108764   ** an SQLite instance.  Shared libraries that intend to be loaded
108235 108765   ** as extensions by SQLite should #include this file instead of 
108236 108766   ** sqlite3.h.
108237 108767   */
108238         -#ifndef _SQLITE3EXT_H_
108239         -#define _SQLITE3EXT_H_
       108768  +#ifndef SQLITE3EXT_H
       108769  +#define SQLITE3EXT_H
108240 108770   /* #include "sqlite3.h" */
108241 108771   
108242 108772   typedef struct sqlite3_api_routines sqlite3_api_routines;
108243 108773   
108244 108774   /*
108245 108775   ** The following structure holds pointers to all of the SQLite API
108246 108776   ** routines.
................................................................................
108248 108778   ** WARNING:  In order to maintain backwards compatibility, add new
108249 108779   ** interfaces to the end of this structure only.  If you insert new
108250 108780   ** interfaces in the middle of this structure, then older different
108251 108781   ** versions of SQLite will not be able to load each other's shared
108252 108782   ** libraries!
108253 108783   */
108254 108784   struct sqlite3_api_routines {
108255         -  void * (*aggregate_context)(sqlite3_context*,int nBytes);
108256         -  int  (*aggregate_count)(sqlite3_context*);
108257         -  int  (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*));
108258         -  int  (*bind_double)(sqlite3_stmt*,int,double);
108259         -  int  (*bind_int)(sqlite3_stmt*,int,int);
108260         -  int  (*bind_int64)(sqlite3_stmt*,int,sqlite_int64);
108261         -  int  (*bind_null)(sqlite3_stmt*,int);
108262         -  int  (*bind_parameter_count)(sqlite3_stmt*);
108263         -  int  (*bind_parameter_index)(sqlite3_stmt*,const char*zName);
108264         -  const char * (*bind_parameter_name)(sqlite3_stmt*,int);
108265         -  int  (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*));
108266         -  int  (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*));
108267         -  int  (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*);
108268         -  int  (*busy_handler)(sqlite3*,int(*)(void*,int),void*);
108269         -  int  (*busy_timeout)(sqlite3*,int ms);
108270         -  int  (*changes)(sqlite3*);
108271         -  int  (*close)(sqlite3*);
108272         -  int  (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,
       108785  +  void * (SQLITE_APICALL *aggregate_context)(sqlite3_context*,int nBytes);
       108786  +  int  (SQLITE_APICALL *aggregate_count)(sqlite3_context*);
       108787  +  int  (SQLITE_APICALL *bind_blob)(sqlite3_stmt*,int,const void*,int n,void(SQLITE_CALLBACK *)(void*));
       108788  +  int  (SQLITE_APICALL *bind_double)(sqlite3_stmt*,int,double);
       108789  +  int  (SQLITE_APICALL *bind_int)(sqlite3_stmt*,int,int);
       108790  +  int  (SQLITE_APICALL *bind_int64)(sqlite3_stmt*,int,sqlite_int64);
       108791  +  int  (SQLITE_APICALL *bind_null)(sqlite3_stmt*,int);
       108792  +  int  (SQLITE_APICALL *bind_parameter_count)(sqlite3_stmt*);
       108793  +  int  (SQLITE_APICALL *bind_parameter_index)(sqlite3_stmt*,const char*zName);
       108794  +  const char * (SQLITE_APICALL *bind_parameter_name)(sqlite3_stmt*,int);
       108795  +  int  (SQLITE_APICALL *bind_text)(sqlite3_stmt*,int,const char*,int n,void(SQLITE_CALLBACK *)(void*));
       108796  +  int  (SQLITE_APICALL *bind_text16)(sqlite3_stmt*,int,const void*,int,void(SQLITE_CALLBACK *)(void*));
       108797  +  int  (SQLITE_APICALL *bind_value)(sqlite3_stmt*,int,const sqlite3_value*);
       108798  +  int  (SQLITE_APICALL *busy_handler)(sqlite3*,int(SQLITE_CALLBACK *)(void*,int),void*);
       108799  +  int  (SQLITE_APICALL *busy_timeout)(sqlite3*,int ms);
       108800  +  int  (SQLITE_APICALL *changes)(sqlite3*);
       108801  +  int  (SQLITE_APICALL *close)(sqlite3*);
       108802  +  int  (SQLITE_APICALL *collation_needed)(sqlite3*,void*,void(SQLITE_CALLBACK *)(void*,sqlite3*,
108273 108803                              int eTextRep,const char*));
108274         -  int  (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,
       108804  +  int  (SQLITE_APICALL *collation_needed16)(sqlite3*,void*,void(SQLITE_CALLBACK *)(void*,sqlite3*,
108275 108805                                int eTextRep,const void*));
108276         -  const void * (*column_blob)(sqlite3_stmt*,int iCol);
108277         -  int  (*column_bytes)(sqlite3_stmt*,int iCol);
108278         -  int  (*column_bytes16)(sqlite3_stmt*,int iCol);
108279         -  int  (*column_count)(sqlite3_stmt*pStmt);
108280         -  const char * (*column_database_name)(sqlite3_stmt*,int);
108281         -  const void * (*column_database_name16)(sqlite3_stmt*,int);
108282         -  const char * (*column_decltype)(sqlite3_stmt*,int i);
108283         -  const void * (*column_decltype16)(sqlite3_stmt*,int);
108284         -  double  (*column_double)(sqlite3_stmt*,int iCol);
108285         -  int  (*column_int)(sqlite3_stmt*,int iCol);
108286         -  sqlite_int64  (*column_int64)(sqlite3_stmt*,int iCol);
108287         -  const char * (*column_name)(sqlite3_stmt*,int);
108288         -  const void * (*column_name16)(sqlite3_stmt*,int);
108289         -  const char * (*column_origin_name)(sqlite3_stmt*,int);
108290         -  const void * (*column_origin_name16)(sqlite3_stmt*,int);
108291         -  const char * (*column_table_name)(sqlite3_stmt*,int);
108292         -  const void * (*column_table_name16)(sqlite3_stmt*,int);
108293         -  const unsigned char * (*column_text)(sqlite3_stmt*,int iCol);
108294         -  const void * (*column_text16)(sqlite3_stmt*,int iCol);
108295         -  int  (*column_type)(sqlite3_stmt*,int iCol);
108296         -  sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol);
108297         -  void * (*commit_hook)(sqlite3*,int(*)(void*),void*);
108298         -  int  (*complete)(const char*sql);
108299         -  int  (*complete16)(const void*sql);
108300         -  int  (*create_collation)(sqlite3*,const char*,int,void*,
108301         -                           int(*)(void*,int,const void*,int,const void*));
108302         -  int  (*create_collation16)(sqlite3*,const void*,int,void*,
108303         -                             int(*)(void*,int,const void*,int,const void*));
108304         -  int  (*create_function)(sqlite3*,const char*,int,int,void*,
108305         -                          void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
108306         -                          void (*xStep)(sqlite3_context*,int,sqlite3_value**),
108307         -                          void (*xFinal)(sqlite3_context*));
108308         -  int  (*create_function16)(sqlite3*,const void*,int,int,void*,
108309         -                            void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
108310         -                            void (*xStep)(sqlite3_context*,int,sqlite3_value**),
108311         -                            void (*xFinal)(sqlite3_context*));
108312         -  int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*);
108313         -  int  (*data_count)(sqlite3_stmt*pStmt);
108314         -  sqlite3 * (*db_handle)(sqlite3_stmt*);
108315         -  int (*declare_vtab)(sqlite3*,const char*);
108316         -  int  (*enable_shared_cache)(int);
108317         -  int  (*errcode)(sqlite3*db);
108318         -  const char * (*errmsg)(sqlite3*);
108319         -  const void * (*errmsg16)(sqlite3*);
108320         -  int  (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**);
108321         -  int  (*expired)(sqlite3_stmt*);
108322         -  int  (*finalize)(sqlite3_stmt*pStmt);
108323         -  void  (*free)(void*);
108324         -  void  (*free_table)(char**result);
108325         -  int  (*get_autocommit)(sqlite3*);
108326         -  void * (*get_auxdata)(sqlite3_context*,int);
108327         -  int  (*get_table)(sqlite3*,const char*,char***,int*,int*,char**);
108328         -  int  (*global_recover)(void);
108329         -  void  (*interruptx)(sqlite3*);
108330         -  sqlite_int64  (*last_insert_rowid)(sqlite3*);
108331         -  const char * (*libversion)(void);
108332         -  int  (*libversion_number)(void);
108333         -  void *(*malloc)(int);
108334         -  char * (*mprintf)(const char*,...);
108335         -  int  (*open)(const char*,sqlite3**);
108336         -  int  (*open16)(const void*,sqlite3**);
108337         -  int  (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
108338         -  int  (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
108339         -  void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
108340         -  void  (*progress_handler)(sqlite3*,int,int(*)(void*),void*);
108341         -  void *(*realloc)(void*,int);
108342         -  int  (*reset)(sqlite3_stmt*pStmt);
108343         -  void  (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*));
108344         -  void  (*result_double)(sqlite3_context*,double);
108345         -  void  (*result_error)(sqlite3_context*,const char*,int);
108346         -  void  (*result_error16)(sqlite3_context*,const void*,int);
108347         -  void  (*result_int)(sqlite3_context*,int);
108348         -  void  (*result_int64)(sqlite3_context*,sqlite_int64);
108349         -  void  (*result_null)(sqlite3_context*);
108350         -  void  (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
108351         -  void  (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
108352         -  void  (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
108353         -  void  (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
108354         -  void  (*result_value)(sqlite3_context*,sqlite3_value*);
108355         -  void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
108356         -  int  (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
       108806  +  const void * (SQLITE_APICALL *column_blob)(sqlite3_stmt*,int iCol);
       108807  +  int  (SQLITE_APICALL *column_bytes)(sqlite3_stmt*,int iCol);
       108808  +  int  (SQLITE_APICALL *column_bytes16)(sqlite3_stmt*,int iCol);
       108809  +  int  (SQLITE_APICALL *column_count)(sqlite3_stmt*pStmt);
       108810  +  const char * (SQLITE_APICALL *column_database_name)(sqlite3_stmt*,int);
       108811  +  const void * (SQLITE_APICALL *column_database_name16)(sqlite3_stmt*,int);
       108812  +  const char * (SQLITE_APICALL *column_decltype)(sqlite3_stmt*,int i);
       108813  +  const void * (SQLITE_APICALL *column_decltype16)(sqlite3_stmt*,int);
       108814  +  double  (SQLITE_APICALL *column_double)(sqlite3_stmt*,int iCol);
       108815  +  int  (SQLITE_APICALL *column_int)(sqlite3_stmt*,int iCol);
       108816  +  sqlite_int64  (SQLITE_APICALL *column_int64)(sqlite3_stmt*,int iCol);
       108817  +  const char * (SQLITE_APICALL *column_name)(sqlite3_stmt*,int);
       108818  +  const void * (SQLITE_APICALL *column_name16)(sqlite3_stmt*,int);
       108819  +  const char * (SQLITE_APICALL *column_origin_name)(sqlite3_stmt*,int);
       108820  +  const void * (SQLITE_APICALL *column_origin_name16)(sqlite3_stmt*,int);
       108821  +  const char * (SQLITE_APICALL *column_table_name)(sqlite3_stmt*,int);
       108822  +  const void * (SQLITE_APICALL *column_table_name16)(sqlite3_stmt*,int);
       108823  +  const unsigned char * (SQLITE_APICALL *column_text)(sqlite3_stmt*,int iCol);
       108824  +  const void * (SQLITE_APICALL *column_text16)(sqlite3_stmt*,int iCol);
       108825  +  int  (SQLITE_APICALL *column_type)(sqlite3_stmt*,int iCol);
       108826  +  sqlite3_value* (SQLITE_APICALL *column_value)(sqlite3_stmt*,int iCol);
       108827  +  void * (SQLITE_APICALL *commit_hook)(sqlite3*,int(SQLITE_CALLBACK *)(void*),void*);
       108828  +  int  (SQLITE_APICALL *complete)(const char*sql);
       108829  +  int  (SQLITE_APICALL *complete16)(const void*sql);
       108830  +  int  (SQLITE_APICALL *create_collation)(sqlite3*,const char*,int,void*,
       108831  +                           int(SQLITE_CALLBACK *)(void*,int,const void*,int,const void*));
       108832  +  int  (SQLITE_APICALL *create_collation16)(sqlite3*,const void*,int,void*,
       108833  +                             int(SQLITE_CALLBACK *)(void*,int,const void*,int,const void*));
       108834  +  int  (SQLITE_APICALL *create_function)(sqlite3*,const char*,int,int,void*,
       108835  +                          void (SQLITE_APICALL *xFunc)(sqlite3_context*,int,sqlite3_value**),
       108836  +                          void (SQLITE_APICALL *xStep)(sqlite3_context*,int,sqlite3_value**),
       108837  +                          void (SQLITE_APICALL *xFinal)(sqlite3_context*));
       108838  +  int  (SQLITE_APICALL *create_function16)(sqlite3*,const void*,int,int,void*,
       108839  +                            void (SQLITE_APICALL *xFunc)(sqlite3_context*,int,sqlite3_value**),
       108840  +                            void (SQLITE_APICALL *xStep)(sqlite3_context*,int,sqlite3_value**),
       108841  +                            void (SQLITE_APICALL *xFinal)(sqlite3_context*));
       108842  +  int (SQLITE_APICALL *create_module)(sqlite3*,const char*,const sqlite3_module*,void*);
       108843  +  int  (SQLITE_APICALL *data_count)(sqlite3_stmt*pStmt);
       108844  +  sqlite3 * (SQLITE_APICALL *db_handle)(sqlite3_stmt*);
       108845  +  int (SQLITE_APICALL *declare_vtab)(sqlite3*,const char*);
       108846  +  int  (SQLITE_APICALL *enable_shared_cache)(int);
       108847  +  int  (SQLITE_APICALL *errcode)(sqlite3*db);
       108848  +  const char * (SQLITE_APICALL *errmsg)(sqlite3*);
       108849  +  const void * (SQLITE_APICALL *errmsg16)(sqlite3*);
       108850  +  int  (SQLITE_APICALL *exec)(sqlite3*,const char*,sqlite3_callback,void*,char**);
       108851  +  int  (SQLITE_APICALL *expired)(sqlite3_stmt*);
       108852  +  int  (SQLITE_APICALL *finalize)(sqlite3_stmt*pStmt);
       108853  +  void  (SQLITE_APICALL *free)(void*);
       108854  +  void  (SQLITE_APICALL *free_table)(char**result);
       108855  +  int  (SQLITE_APICALL *get_autocommit)(sqlite3*);
       108856  +  void * (SQLITE_APICALL *get_auxdata)(sqlite3_context*,int);
       108857  +  int  (SQLITE_APICALL *get_table)(sqlite3*,const char*,char***,int*,int*,char**);
       108858  +  int  (SQLITE_APICALL *global_recover)(void);
       108859  +  void  (SQLITE_APICALL *interruptx)(sqlite3*);
       108860  +  sqlite_int64  (SQLITE_APICALL *last_insert_rowid)(sqlite3*);
       108861  +  const char * (SQLITE_APICALL *libversion)(void);
       108862  +  int  (SQLITE_APICALL *libversion_number)(void);
       108863  +  void *(SQLITE_APICALL *malloc)(int);
       108864  +  char * (SQLITE_APICALL *mprintf)(const char*,...);
       108865  +  int  (SQLITE_APICALL *open)(const char*,sqlite3**);
       108866  +  int  (SQLITE_APICALL *open16)(const void*,sqlite3**);
       108867  +  int  (SQLITE_APICALL *prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
       108868  +  int  (SQLITE_APICALL *prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
       108869  +  void * (SQLITE_APICALL *profile)(sqlite3*,void(SQLITE_CALLBACK *)(void*,const char*,sqlite_uint64),void*);
       108870  +  void  (SQLITE_APICALL *progress_handler)(sqlite3*,int,int(SQLITE_CALLBACK *)(void*),void*);
       108871  +  void *(SQLITE_APICALL *realloc)(void*,int);
       108872  +  int  (SQLITE_APICALL *reset)(sqlite3_stmt*pStmt);
       108873  +  void  (SQLITE_APICALL *result_blob)(sqlite3_context*,const void*,int,void(SQLITE_CALLBACK *)(void*));
       108874  +  void  (SQLITE_APICALL *result_double)(sqlite3_context*,double);
       108875  +  void  (SQLITE_APICALL *result_error)(sqlite3_context*,const char*,int);
       108876  +  void  (SQLITE_APICALL *result_error16)(sqlite3_context*,const void*,int);
       108877  +  void  (SQLITE_APICALL *result_int)(sqlite3_context*,int);
       108878  +  void  (SQLITE_APICALL *result_int64)(sqlite3_context*,sqlite_int64);
       108879  +  void  (SQLITE_APICALL *result_null)(sqlite3_context*);
       108880  +  void  (SQLITE_APICALL *result_text)(sqlite3_context*,const char*,int,void(SQLITE_CALLBACK *)(void*));
       108881  +  void  (SQLITE_APICALL *result_text16)(sqlite3_context*,const void*,int,void(SQLITE_CALLBACK *)(void*));
       108882  +  void  (SQLITE_APICALL *result_text16be)(sqlite3_context*,const void*,int,void(SQLITE_CALLBACK *)(void*));
       108883  +  void  (SQLITE_APICALL *result_text16le)(sqlite3_context*,const void*,int,void(SQLITE_CALLBACK *)(void*));
       108884  +  void  (SQLITE_APICALL *result_value)(sqlite3_context*,sqlite3_value*);
       108885  +  void * (SQLITE_APICALL *rollback_hook)(sqlite3*,void(SQLITE_CALLBACK *)(void*),void*);
       108886  +  int  (SQLITE_APICALL *set_authorizer)(sqlite3*,int(SQLITE_CALLBACK *)(void*,int,const char*,const char*,
108357 108887                            const char*,const char*),void*);
108358         -  void  (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
108359         -  char * (*snprintf)(int,char*,const char*,...);
108360         -  int  (*step)(sqlite3_stmt*);
108361         -  int  (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
       108888  +  void  (SQLITE_APICALL *set_auxdata)(sqlite3_context*,int,void*,void (SQLITE_CALLBACK *)(void*));
       108889  +  char * (SQLITE_APICALL *snprintf)(int,char*,const char*,...);
       108890  +  int  (SQLITE_APICALL *step)(sqlite3_stmt*);
       108891  +  int  (SQLITE_APICALL *table_column_metadata)(sqlite3*,const char*,const char*,const char*,
108362 108892                                   char const**,char const**,int*,int*,int*);
108363         -  void  (*thread_cleanup)(void);
108364         -  int  (*total_changes)(sqlite3*);
108365         -  void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*);
108366         -  int  (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*);
108367         -  void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,
       108893  +  void  (SQLITE_APICALL *thread_cleanup)(void);
       108894  +  int  (SQLITE_APICALL *total_changes)(sqlite3*);
       108895  +  void * (SQLITE_APICALL *trace)(sqlite3*,void(SQLITE_APICALL *xTrace)(void*,const char*),void*);
       108896  +  int  (SQLITE_APICALL *transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*);
       108897  +  void * (SQLITE_APICALL *update_hook)(sqlite3*,void(SQLITE_CALLBACK *)(void*,int ,char const*,char const*,
108368 108898                                            sqlite_int64),void*);
108369         -  void * (*user_data)(sqlite3_context*);
108370         -  const void * (*value_blob)(sqlite3_value*);
108371         -  int  (*value_bytes)(sqlite3_value*);
108372         -  int  (*value_bytes16)(sqlite3_value*);
108373         -  double  (*value_double)(sqlite3_value*);
108374         -  int  (*value_int)(sqlite3_value*);
108375         -  sqlite_int64  (*value_int64)(sqlite3_value*);
108376         -  int  (*value_numeric_type)(sqlite3_value*);
108377         -  const unsigned char * (*value_text)(sqlite3_value*);
108378         -  const void * (*value_text16)(sqlite3_value*);
108379         -  const void * (*value_text16be)(sqlite3_value*);
108380         -  const void * (*value_text16le)(sqlite3_value*);
108381         -  int  (*value_type)(sqlite3_value*);
108382         -  char *(*vmprintf)(const char*,va_list);
       108899  +  void * (SQLITE_APICALL *user_data)(sqlite3_context*);
       108900  +  const void * (SQLITE_APICALL *value_blob)(sqlite3_value*);
       108901  +  int  (SQLITE_APICALL *value_bytes)(sqlite3_value*);
       108902  +  int  (SQLITE_APICALL *value_bytes16)(sqlite3_value*);
       108903  +  double  (SQLITE_APICALL *value_double)(sqlite3_value*);
       108904  +  int  (SQL