Changes On Branch sqlite4
Not logged in

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

Changes In Branch sqlite4 Excluding Merge-Ins

This is equivalent to a diff from 01e4de6b8a to 0328d68181

2012-06-29
19:35
Remove redundant include argument from the compilation steps of several source files. check-in: 8a18e7fb7f user: mistachkin tags: trunk
15:59
Update to the latest SQLite4 that requires converting preprocessor macro prefixes from "SQLITE_" to "SQLITE4_". Leaf check-in: 0328d68181 user: drh tags: sqlite4
15:47
Merge in the trunk changes. check-in: 0315f3f03b user: drh tags: sqlite4
12:48
Fix the manifest generator for check-ins so that when a partial commit is done and some of the uncommitted files have been renamed, the rows of the check-in manifest are ordered by the original, unchanged names of the uncommitted renamed files. check-in: 01e4de6b8a user: drh tags: trunk
11:05
Update the test-parse-manifest test command so that it reports parse failures on standard output. check-in: 4113f5881b user: drh tags: trunk

Changes to src/Makefile.

     1      1   all clean:
     2      2   	$(MAKE) -C .. $(MAKECMDGOALS)
     3         -

Changes to src/add.c.

   163    163       xCmp = fossil_stricmp;
   164    164       db_multi_exec(
   165    165         "CREATE INDEX IF NOT EXISTS vfile_nocase"
   166    166         "    ON vfile(pathname COLLATE nocase)"
   167    167       );
   168    168     }
   169    169     db_prepare(&loop, "SELECT x FROM sfile ORDER BY x");
   170         -  while( db_step(&loop)==SQLITE_ROW ){
          170  +  while( db_step(&loop)==SQLITE4_ROW ){
   171    171       const char *zToAdd = db_column_text(&loop, 0);
   172    172       if( fossil_strcmp(zToAdd, zRepo)==0 ) continue;
   173    173       for(i=0; (zReserved = fossil_reserved_name(i))!=0; i++){
   174    174         if( xCmp(zToAdd, zReserved)==0 ) break;
   175    175       }
   176    176       if( zReserved ) continue;
   177    177       nAdd += add_one_file(zToAdd, vid, caseSensitive);
................................................................................
   313    313          "    AND NOT deleted",
   314    314          zTreeName, zTreeName, zTreeName
   315    315       );
   316    316       blob_reset(&treeName);
   317    317     }
   318    318     
   319    319     db_prepare(&loop, "SELECT x FROM sfile");
   320         -  while( db_step(&loop)==SQLITE_ROW ){
          320  +  while( db_step(&loop)==SQLITE4_ROW ){
   321    321       fossil_print("DELETED %s\n", db_column_text(&loop, 0));
   322    322     }
   323    323     db_finalize(&loop);
   324    324     db_multi_exec(
   325    325       "UPDATE vfile SET deleted=1 WHERE pathname IN sfile;"
   326    326       "DELETE FROM vfile WHERE rid=0 AND deleted;"
   327    327     );
................................................................................
   475    475     /* step 2: search for missing files */
   476    476     db_prepare(&q,
   477    477         "SELECT pathname, %Q || pathname, deleted FROM vfile"
   478    478         " WHERE NOT deleted"
   479    479         " ORDER BY 1",
   480    480         g.zLocalRoot
   481    481     );
   482         -  while( db_step(&q)==SQLITE_ROW ){
          482  +  while( db_step(&q)==SQLITE4_ROW ){
   483    483       const char * zFile;
   484    484       const char * zPath;
   485    485   
   486    486       zFile = db_column_text(&q, 0);
   487    487       zPath = db_column_text(&q, 1);
   488    488       if( !file_wd_isfile_or_link(zPath) ){
   489    489         if( !isTest ){
................................................................................
   579    579         db_prepare(&q,
   580    580            "SELECT pathname FROM vfile"
   581    581            " WHERE vid=%d"
   582    582            "   AND (pathname='%q' OR (pathname>'%q/' AND pathname<'%q0'))"
   583    583            " ORDER BY 1",
   584    584            vid, zOrig, zOrig, zOrig
   585    585         );
   586         -      while( db_step(&q)==SQLITE_ROW ){
          586  +      while( db_step(&q)==SQLITE4_ROW ){
   587    587           const char *zPath = db_column_text(&q, 0);
   588    588           int nPath = db_column_bytes(&q, 0);
   589    589           const char *zTail;
   590    590           if( nPath==nOrig ){
   591    591             zTail = file_tail(zPath);
   592    592           }else{
   593    593             zTail = &zPath[nOrig+1];
................................................................................
   597    597             zPath, blob_str(&dest), zTail
   598    598           );
   599    599         }
   600    600         db_finalize(&q);
   601    601       }
   602    602     }
   603    603     db_prepare(&q, "SELECT f, t FROM mv ORDER BY f");
   604         -  while( db_step(&q)==SQLITE_ROW ){
          604  +  while( db_step(&q)==SQLITE4_ROW ){
   605    605       const char *zFrom = db_column_text(&q, 0);
   606    606       const char *zTo = db_column_text(&q, 1);
   607    607       mv_one_file(vid, zFrom, zTo);
   608    608     }
   609    609     db_finalize(&q);
   610    610     db_end_transaction(0);
   611    611   }

Changes to src/allrepo.c.

   162    162          "SELECT substr(name, 6) COLLATE nocase, max(rowid)"
   163    163          "  FROM global_config"
   164    164          " WHERE substr(name, 1, 5)=='repo:'"
   165    165          " GROUP BY 1 ORDER BY 1"
   166    166       );
   167    167     }
   168    168     bag_init(&outOfDate);
   169         -  while( db_step(&q)==SQLITE_ROW ){
          169  +  while( db_step(&q)==SQLITE4_ROW ){
   170    170       const char *zFilename = db_column_text(&q, 0);
   171    171       int rowid = db_column_int(&q, 1);
   172    172       if( file_access(zFilename, 0) || !file_is_canonical(zFilename) ){
   173    173         bag_insert(&outOfDate, rowid);
   174    174         continue;
   175    175       }
   176    176       if( useCheckouts && file_isdir(zFilename)!=1 ){

Changes to src/attach.c.

    57     57       blob_appendf(&sql, " WHERE target GLOB '%q*'", zTkt);
    58     58     }else{
    59     59       if( g.perm.RdTkt==0 && g.perm.RdWiki==0 ) login_needed();
    60     60       style_header("All Attachments");
    61     61     }
    62     62     blob_appendf(&sql, " ORDER BY mtime DESC");
    63     63     db_prepare(&q, "%s", blob_str(&sql));
    64         -  while( db_step(&q)==SQLITE_ROW ){
           64  +  while( db_step(&q)==SQLITE4_ROW ){
    65     65       const char *zDate = db_column_text(&q, 0);
    66     66       const char *zSrc = db_column_text(&q, 1);
    67     67       const char *zTarget = db_column_text(&q, 2);
    68     68       const char *zFilename = db_column_text(&q, 3);
    69     69       const char *zComment = db_column_text(&q, 4);
    70     70       const char *zUser = db_column_text(&q, 5);
    71     71       int i;

Changes to src/bisect.c.

   226    226                      "       datetime(event.mtime) FROM blob, event"
   227    227                      " WHERE blob.rid=:rid AND event.objid=:rid"
   228    228                      "   AND event.type='ci'");
   229    229       nStep = path_length();
   230    230       for(p=path_last(), n=0; p; p=p->pFrom, n++){
   231    231         const char *z;
   232    232         db_bind_int(&s, ":rid", p->rid);
   233         -      if( db_step(&s)==SQLITE_ROW ){
          233  +      if( db_step(&s)==SQLITE4_ROW ){
   234    234           z = db_column_text(&s, 0);
   235    235           fossil_print("%s", z);
   236    236           if( p->rid==bisect.good ) fossil_print(" GOOD");
   237    237           if( p->rid==bisect.bad ) fossil_print(" BAD");
   238    238           if( p->rid==vid ) fossil_print(" CURRENT");
   239    239           if( nStep>1 && n==nStep/2 ) fossil_print(" NEXT");
   240    240           fossil_print("\n");

Changes to src/branch.c.

   125    125     /* Cancel all other symbolic tags */
   126    126     db_prepare(&q,
   127    127         "SELECT tagname FROM tagxref, tag"
   128    128         " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
   129    129         "   AND tagtype>0 AND tagname GLOB 'sym-*'"
   130    130         " ORDER BY tagname",
   131    131         rootid);
   132         -  while( db_step(&q)==SQLITE_ROW ){
          132  +  while( db_step(&q)==SQLITE4_ROW ){
   133    133       const char *zTag = db_column_text(&q, 0);
   134    134       blob_appendf(&branch, "T -%F *\n", zTag);
   135    135     }
   136    136     db_finalize(&q);
   137    137     
   138    138     blob_appendf(&branch, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
   139    139     md5sum_blob(&branch, &mcksum);
................................................................................
   267    267   
   268    268       if( g.localOpen ){
   269    269         vid = db_lget_int("checkout", 0);
   270    270         zCurrent = db_text(0, "SELECT value FROM tagxref"
   271    271                               " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
   272    272       }
   273    273       branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0));
   274         -    while( db_step(&q)==SQLITE_ROW ){
          274  +    while( db_step(&q)==SQLITE4_ROW ){
   275    275         const char *zBr = db_column_text(&q, 0);
   276    276         int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
   277    277         fossil_print("%s%s\n", (isCur ? "* " : "  "), zBr);
   278    278       }
   279    279       db_finalize(&q);
   280    280     }else{
   281    281       fossil_panic("branch subcommand should be one of: "
................................................................................
   335    335     @ Closed branches are fixed and do not change (unless they are first
   336    336     @ reopened)</li>
   337    337     @ </ol>
   338    338     style_sidebox_end();
   339    339   
   340    340     branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0));
   341    341     cnt = 0;
   342         -  while( db_step(&q)==SQLITE_ROW ){
          342  +  while( db_step(&q)==SQLITE4_ROW ){
   343    343       const char *zBr = db_column_text(&q, 0);
   344    344       if( cnt==0 ){
   345    345         if( colorTest ){
   346    346           @ <h2>Default background colors for all branches:</h2>
   347    347         }else if( showAll ){
   348    348           @ <h2>All Branches:</h2>
   349    349         }else if( showClosed ){
................................................................................
   387    387       "SELECT substr(tagname,5) FROM tagxref, tag"
   388    388       " WHERE tagxref.rid=%d"
   389    389       "   AND tagxref.tagid=tag.tagid"
   390    390       "   AND tagxref.tagtype>0"
   391    391       "   AND tag.tagname GLOB 'sym-*'",
   392    392       rid
   393    393     );
   394         -  while( db_step(&q)==SQLITE_ROW ){
          394  +  while( db_step(&q)==SQLITE4_ROW ){
   395    395       const char *zTagName = db_column_text(&q, 0);
   396    396       @ %z(href("%R/timeline?r=%T",zTagName))[timeline]</a>
   397    397     }
   398    398     db_finalize(&q);
   399    399   }
   400    400   
   401    401   /*

Changes to src/browse.c.

    33     33   ** Examples:
    34     34   **
    35     35   **      pathelement('abc/pqr/xyz', 4)  ->  '/pqr'
    36     36   **      pathelement('abc/pqr', 4)      ->  'pqr'
    37     37   **      pathelement('abc/pqr/xyz', 0)  ->  '/abc'
    38     38   */
    39     39   void pathelementFunc(
    40         -  sqlite3_context *context,
           40  +  sqlite4_context *context,
    41     41     int argc,
    42         -  sqlite3_value **argv
           42  +  sqlite4_value **argv
    43     43   ){
    44     44     const unsigned char *z;
    45     45     int len, n, i;
    46     46     char *zOut;
    47     47   
    48     48     assert( argc==2 );
    49         -  z = sqlite3_value_text(argv[0]);
           49  +  z = sqlite4_value_text(argv[0]);
    50     50     if( z==0 ) return;
    51         -  len = sqlite3_value_bytes(argv[0]);
    52         -  n = sqlite3_value_int(argv[1]);
           51  +  len = sqlite4_value_bytes(argv[0]);
           52  +  n = sqlite4_value_int(argv[1]);
    53     53     if( len<=n ) return;
    54     54     if( n>0 && z[n-1]!='/' ) return;
    55     55     for(i=n; i<len && z[i]!='/'; i++){}
    56     56     if( i==len ){
    57         -    sqlite3_result_text(context, (char*)&z[n], len-n, SQLITE_TRANSIENT);
           57  +    sqlite4_result_text(context, (char*)&z[n], len-n, SQLITE4_TRANSIENT);
    58     58     }else{
    59         -    zOut = sqlite3_mprintf("/%.*s", i-n, &z[n]);
    60         -    sqlite3_result_text(context, zOut, i-n+1, sqlite3_free);
           59  +    zOut = sqlite4_mprintf(0, "/%.*s", i-n, &z[n]);
           60  +    sqlite4_result_text(context, zOut, i-n+1, SQLITE4_DYNAMIC);
    61     61     }
    62     62   }
    63     63   
    64     64   /*
    65     65   ** Given a pathname which is a relative path from the root of
    66     66   ** the repository to a file or directory, compute a string which
    67     67   ** is an HTML rendering of that path with hyperlinks on each
................................................................................
   121    121     Manifest *pM = 0;
   122    122     const char *zSubdirLink;
   123    123   
   124    124     login_check_credentials();
   125    125     if( !g.perm.Hyperlink ){ login_needed(); return; }
   126    126     while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; }
   127    127     style_header("File List");
   128         -  sqlite3_create_function(g.db, "pathelement", 2, SQLITE_UTF8, 0,
          128  +  sqlite4_create_function(g.db, "pathelement", 2, SQLITE4_UTF8, 0,
   129    129                             pathelementFunc, 0, 0);
   130    130   
   131    131     /* If the name= parameter is an empty string, make it a NULL pointer */
   132    132     if( zD && strlen(zD)==0 ){ zD = 0; }
   133    133   
   134    134     /* If a specific check-in is requested, fetch and parse it.  If the
   135    135     ** specific check-in does not exist, clear zCI.  zCI==0 will cause all
................................................................................
   267    267     nCol = 100/mxLen;
   268    268     if( nCol<1 ) nCol = 1;
   269    269     if( nCol>5 ) nCol = 5;
   270    270     nRow = (cnt+nCol-1)/nCol;
   271    271     db_prepare(&q, "SELECT x, u FROM localfiles ORDER BY x /*scan*/");
   272    272     @ <table class="browser"><tr><td class="browser"><ul class="browser">
   273    273     i = 0;
   274         -  while( db_step(&q)==SQLITE_ROW ){
          274  +  while( db_step(&q)==SQLITE4_ROW ){
   275    275       const char *zFN;
   276    276       if( i==nRow ){
   277    277         @ </ul></td><td class="browser"><ul class="browser">
   278    278         i = 0;
   279    279       }
   280    280       i++;
   281    281       zFN = db_column_text(&q, 0);

Changes to src/captcha.c.

   388    388     int i;
   389    389     unsigned int v;
   390    390     char *z;
   391    391   
   392    392     for(i=2; i<g.argc; i++){
   393    393       char zHex[30];
   394    394       v = (unsigned int)atoi(g.argv[i]);
   395         -    sqlite3_snprintf(sizeof(zHex), zHex, "%x", v);
          395  +    sqlite4_snprintf(zHex, sizeof(zHex), "%x", v);
   396    396       z = captcha_render(zHex);
   397    397       fossil_print("%s:\n%s", zHex, z);
   398    398       free(z);
   399    399     }
   400    400   }
   401    401   
   402    402   /*
................................................................................
   403    403   ** Compute a seed value for a captcha.  The seed is public and is sent
   404    404   ** as a hidden parameter with the page that contains the captcha.  Knowledge
   405    405   ** of the seed is insufficient for determining the captcha without additional
   406    406   ** information held only on the server and never revealed.
   407    407   */
   408    408   unsigned int captcha_seed(void){
   409    409     unsigned int x;
   410         -  sqlite3_randomness(sizeof(x), &x);
          410  +  sqlite4_randomness(0, sizeof(x), &x);
   411    411     x &= 0x7fffffff;
   412    412     return x;
   413    413   }
   414    414   
   415    415   /*
   416    416   ** Translate a captcha seed value into the captcha password string.
   417    417   ** The returned string is static and overwritten on each call to

Changes to src/cgi.c.

   662    662         zName = 0;
   663    663         showBytes = 0;
   664    664       }else{
   665    665         nArg = tokenize_line(zLine, sizeof(azArg)/sizeof(azArg[0]), azArg);
   666    666         for(i=0; i<nArg; i++){
   667    667           int c = fossil_tolower(azArg[i][0]);
   668    668           int n = strlen(azArg[i]);
   669         -        if( c=='c' && sqlite3_strnicmp(azArg[i],"content-disposition:",n)==0 ){
          669  +        if( c=='c' && sqlite4_strnicmp(azArg[i],"content-disposition:",n)==0 ){
   670    670             i++;
   671         -        }else if( c=='n' && sqlite3_strnicmp(azArg[i],"name=",n)==0 ){
          671  +        }else if( c=='n' && sqlite4_strnicmp(azArg[i],"name=",n)==0 ){
   672    672             zName = azArg[++i];
   673         -        }else if( c=='f' && sqlite3_strnicmp(azArg[i],"filename=",n)==0 ){
          673  +        }else if( c=='f' && sqlite4_strnicmp(azArg[i],"filename=",n)==0 ){
   674    674             char *z = azArg[++i];
   675    675             if( zName && z && fossil_islower(zName[0]) ){
   676    676               cgi_set_parameter_nocopy(mprintf("%s:filename",zName), z);
   677    677             }
   678    678             showBytes = 1;
   679         -        }else if( c=='c' && sqlite3_strnicmp(azArg[i],"content-type:",n)==0 ){
          679  +        }else if( c=='c' && sqlite4_strnicmp(azArg[i],"content-type:",n)==0 ){
   680    680             char *z = azArg[++i];
   681    681             if( zName && z && fossil_islower(zName[0]) ){
   682    682               cgi_set_parameter_nocopy(mprintf("%s:mimetype",zName), z);
   683    683             }
   684    684           }
   685    685         }
   686    686       }

Changes to src/checkin.c.

    44     44     db_prepare(&q, 
    45     45       "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
    46     46       "  FROM vfile "
    47     47       " WHERE is_selected(id)"
    48     48       "   AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1"
    49     49     );
    50     50     blob_zero(&rewrittenPathname);
    51         -  while( db_step(&q)==SQLITE_ROW ){
           51  +  while( db_step(&q)==SQLITE4_ROW ){
    52     52       const char *zPathname = db_column_text(&q,0);
    53     53       const char *zDisplayName = zPathname;
    54     54       int isDeleted = db_column_int(&q, 1);
    55     55       int isChnged = db_column_int(&q,2);
    56     56       int isNew = db_column_int(&q,3)==0;
    57     57       int isRenamed = db_column_int(&q,4);
    58     58       char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
................................................................................
    95     95       }
    96     96       free(zFullName);
    97     97     }
    98     98     blob_reset(&rewrittenPathname);
    99     99     db_finalize(&q);
   100    100     db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
   101    101                    " WHERE id<=0");
   102         -  while( db_step(&q)==SQLITE_ROW ){
          102  +  while( db_step(&q)==SQLITE4_ROW ){
   103    103       const char *zLabel = "MERGED_WITH";
   104    104       switch( db_column_int(&q, 1) ){
   105    105         case -1:  zLabel = "CHERRYPICK ";  break;
   106    106         case -2:  zLabel = "BACKOUT    ";  break;
   107    107       }
   108    108       blob_append(report, zPrefix, nPrefix);
   109    109       blob_appendf(report, "%s %s\n", zLabel, db_column_text(&q, 0));
................................................................................
   231    231     vid = db_lget_int("checkout", 0);
   232    232     vfile_check_signature(vid, 0, 0);
   233    233     db_prepare(&q,
   234    234        "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
   235    235        "  FROM vfile"
   236    236        " ORDER BY 1"
   237    237     );
   238         -  while( db_step(&q)==SQLITE_ROW ){
          238  +  while( db_step(&q)==SQLITE4_ROW ){
   239    239       const char *zPathname = db_column_text(&q,0);
   240    240       int isDeleted = db_column_int(&q, 1);
   241    241       int isNew = db_column_int(&q,2)==0;
   242    242       int chnged = db_column_int(&q,3);
   243    243       int renamed = db_column_int(&q,4);
   244    244       char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
   245    245       if( isBrief ){
................................................................................
   323    323         fossil_all_reserved_names()
   324    324     );
   325    325     if( file_tree_name(g.zRepositoryName, &repo, 0) ){
   326    326       db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
   327    327     }
   328    328     db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)");
   329    329     blob_zero(&rewrittenPathname);
   330         -  while( db_step(&q)==SQLITE_ROW ){
          330  +  while( db_step(&q)==SQLITE4_ROW ){
   331    331       zDisplayName = zPathname = db_column_text(&q, 0);
   332    332       if( cwdRelative ) {
   333    333         char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
   334    334         file_relative_name(zFullName, &rewrittenPathname, 0);
   335    335         free(zFullName);
   336    336         zDisplayName = blob_str(&rewrittenPathname);
   337    337         if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
................................................................................
   399    399         " WHERE x NOT IN (%s)"
   400    400         " ORDER BY 1",
   401    401         g.zLocalRoot, fossil_all_reserved_names()
   402    402     );
   403    403     if( file_tree_name(g.zRepositoryName, &repo, 0) ){
   404    404       db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
   405    405     }
   406         -  while( db_step(&q)==SQLITE_ROW ){
          406  +  while( db_step(&q)==SQLITE4_ROW ){
   407    407       if( allFlag ){
   408    408         file_delete(db_column_text(&q, 0));
   409    409       }else{
   410    410         Blob ans;
   411    411         char *prompt = mprintf("remove unmanaged file \"%s\" (y/N)? ",
   412    412                                 db_column_text(&q, 0));
   413    413         blob_zero(&ans);
................................................................................
   689    689       " WHERE (NOT deleted OR NOT is_selected(vfile.id))"
   690    690       "   AND vfile.vid=%d"
   691    691       " ORDER BY if_selected(vfile.id, pathname, origname)",
   692    692       vid);
   693    693     blob_zero(&filename);
   694    694     blob_appendf(&filename, "%s", g.zLocalRoot);
   695    695     nBasename = blob_size(&filename);
   696         -  while( db_step(&q)==SQLITE_ROW ){
          696  +  while( db_step(&q)==SQLITE4_ROW ){
   697    697       const char *zName = db_column_text(&q, 0);
   698    698       const char *zUuid = db_column_text(&q, 1);
   699    699       const char *zOrig = db_column_text(&q, 2);
   700    700       int frid = db_column_int(&q, 3);
   701    701       int isExe = db_column_int(&q, 4);
   702    702       int isLink = db_column_int(&q, 5);
   703    703       int isSelected = db_column_int(&q, 6);
................................................................................
   754    754       pFile = manifest_file_next(pBaseline, 0);
   755    755       nFBcard++;
   756    756     }
   757    757     blob_appendf(pOut, "P %s", zParentUuid);
   758    758     if( verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate);
   759    759     free(zParentUuid);
   760    760     db_prepare(&q2, "SELECT merge FROM vmerge WHERE id=0");
   761         -  while( db_step(&q2)==SQLITE_ROW ){
          761  +  while( db_step(&q2)==SQLITE4_ROW ){
   762    762       char *zMergeUuid;
   763    763       int mid = db_column_int(&q2, 0);
   764    764       if( !g.markPrivate && content_is_private(mid) ) continue;
   765    765       zMergeUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid);
   766    766       if( zMergeUuid ){
   767    767         blob_appendf(pOut, " %s", zMergeUuid);
   768    768         if( verifyDate ) checkin_verify_younger(mid, zMergeUuid, zDate);
................................................................................
   804    804       db_prepare(&q,
   805    805           "SELECT tagname FROM tagxref, tag"
   806    806           " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
   807    807           "   AND tagtype==2 AND tagname GLOB 'sym-*'"
   808    808           "   AND tagname!='sym-'||%Q"
   809    809           " ORDER BY tagname",
   810    810           vid, zBranch);
   811         -    while( db_step(&q)==SQLITE_ROW ){
          811  +    while( db_step(&q)==SQLITE4_ROW ){
   812    812         const char *zBrTag = db_column_text(&q, 0);
   813    813         blob_appendf(pOut, "T -%F *\n", zBrTag);
   814    814       }
   815    815       db_finalize(&q);
   816    816     }  
   817    817     blob_appendf(pOut, "U %F\n", zUserOvrd ? zUserOvrd : g.zLogin);
   818    818     md5sum_blob(pOut, &mcksum);
................................................................................
  1153   1153     ** the identified fils are inserted (if they have been modified).
  1154   1154     */
  1155   1155     db_prepare(&q,
  1156   1156       "SELECT id, %Q || pathname, mrid, %s FROM vfile "
  1157   1157       "WHERE chnged==1 AND NOT deleted AND is_selected(id)",
  1158   1158       g.zLocalRoot, glob_expr("pathname", db_get("crnl-glob",""))
  1159   1159     );
  1160         -  while( db_step(&q)==SQLITE_ROW ){
         1160  +  while( db_step(&q)==SQLITE4_ROW ){
  1161   1161       int id, rid;
  1162   1162       const char *zFullname;
  1163   1163       Blob content;
  1164   1164       int crnlOk;
  1165   1165   
  1166   1166       id = db_column_int(&q, 0);
  1167   1167       zFullname = db_column_text(&q, 1);

Changes to src/clone.c.

    40     40       "SELECT "
    41     41       "   rid, (SELECT uuid FROM blob WHERE rid=delta.rid),"
    42     42       "   srcid, (SELECT uuid FROM blob WHERE rid=delta.srcid)"
    43     43       "  FROM delta"
    44     44       " WHERE srcid in private AND rid NOT IN private"
    45     45     );
    46     46     bag_init(&toUndelta);
    47         -  while( db_step(&q)==SQLITE_ROW ){
           47  +  while( db_step(&q)==SQLITE4_ROW ){
    48     48       int rid = db_column_int(&q, 0);
    49     49       const char *zId = db_column_text(&q, 1);
    50     50       int srcid = db_column_int(&q, 2);
    51     51       const char *zSrc = db_column_text(&q, 3);
    52     52       if( showWarning ){
    53     53         fossil_warning(
    54     54           "public artifact %S (%d) is a delta from private artifact %S (%d)",

Changes to src/config.h.

    82     82   #  else
    83     83   #    define COMPILER_NAME "unknown"
    84     84   #  endif
    85     85   #endif
    86     86   
    87     87   #ifndef _RC_COMPILE_
    88     88   
    89         -#include "sqlite3.h"
           89  +#include "sqlite4.h"
    90     90   
    91     91   /*
    92     92   ** On Solaris, getpass() will only return up to 8 characters. getpassphrase() returns up to 257.
    93     93   */
    94     94   #if HAVE_GETPASSPHRASE
    95     95     #define getpass getpassphrase
    96     96   #endif
    97     97   
    98     98   /*
    99     99   ** Typedef for a 64-bit integer
   100    100   */
   101         -typedef sqlite3_int64 i64;
   102         -typedef sqlite3_uint64 u64;
          101  +typedef sqlite4_int64 i64;
          102  +typedef sqlite4_uint64 u64;
   103    103   
   104    104   /*
   105    105   ** 8-bit types
   106    106   */
   107    107   typedef unsigned char u8;
   108    108   typedef signed char i8;
   109    109   

Changes to src/configure.c.

   194    194   ** and "@shun" and "@user".  This routine writes SQL text into pOut that when
   195    195   ** evaluated will populate the corresponding table with data.
   196    196   */
   197    197   void configure_render_special_name(const char *zName, Blob *pOut){
   198    198     Stmt q;
   199    199     if( fossil_strcmp(zName, "@shun")==0 ){
   200    200       db_prepare(&q, "SELECT uuid FROM shun");
   201         -    while( db_step(&q)==SQLITE_ROW ){
          201  +    while( db_step(&q)==SQLITE4_ROW ){
   202    202         blob_appendf(pOut, "INSERT OR IGNORE INTO shun VALUES('%s');\n", 
   203    203           db_column_text(&q, 0)
   204    204         );
   205    205       }
   206    206       db_finalize(&q);
   207    207     }else if( fossil_strcmp(zName, "@reportfmt")==0 ){
   208    208       db_prepare(&q, "SELECT title, cols, sqlcode FROM reportfmt");
   209         -    while( db_step(&q)==SQLITE_ROW ){
          209  +    while( db_step(&q)==SQLITE4_ROW ){
   210    210         blob_appendf(pOut, "INSERT INTO _xfer_reportfmt(title,cols,sqlcode)"
   211    211                            " VALUES(%Q,%Q,%Q);\n", 
   212    212           db_column_text(&q, 0),
   213    213           db_column_text(&q, 1),
   214    214           db_column_text(&q, 2)
   215    215         );
   216    216       }
   217    217       db_finalize(&q);
   218    218     }else if( fossil_strcmp(zName, "@user")==0 ){
   219    219       db_prepare(&q, 
   220    220           "SELECT login, CASE WHEN length(pw)==40 THEN pw END,"
   221    221           "       cap, info, quote(photo) FROM user");
   222         -    while( db_step(&q)==SQLITE_ROW ){
          222  +    while( db_step(&q)==SQLITE4_ROW ){
   223    223         blob_appendf(pOut, "INSERT INTO _xfer_user(login,pw,cap,info,photo)"
   224    224                            " VALUES(%Q,%Q,%Q,%Q,%s);\n",
   225    225           db_column_text(&q, 0),
   226    226           db_column_text(&q, 1),
   227    227           db_column_text(&q, 2),
   228    228           db_column_text(&q, 3),
   229    229           db_column_text(&q, 4)
   230    230         );
   231    231       }
   232    232       db_finalize(&q);
   233    233     }else if( fossil_strcmp(zName, "@concealed")==0 ){
   234    234       db_prepare(&q, "SELECT hash, content FROM concealed");
   235         -    while( db_step(&q)==SQLITE_ROW ){
          235  +    while( db_step(&q)==SQLITE4_ROW ){
   236    236         blob_appendf(pOut, "INSERT OR IGNORE INTO concealed(hash,content)"
   237    237                            " VALUES(%Q,%Q);\n",
   238    238           db_column_text(&q, 0),
   239    239           db_column_text(&q, 1)
   240    240         );
   241    241       }
   242    242       db_finalize(&q);
................................................................................
   257    257   ** are given in the argument.
   258    258   **
   259    259   ** These functions are used below in the WHEN clause of a trigger to
   260    260   ** get the trigger to fire exactly once.
   261    261   */
   262    262   static int configHasBeenReset = 0;
   263    263   static void config_is_reset_function(
   264         -  sqlite3_context *context,
          264  +  sqlite4_context *context,
   265    265     int argc,
   266         -  sqlite3_value **argv
          266  +  sqlite4_value **argv
   267    267   ){
   268         -  int m = sqlite3_value_int(argv[0]);
   269         -  sqlite3_result_int(context, (configHasBeenReset&m)!=0 );
          268  +  int m = sqlite4_value_int(argv[0]);
          269  +  sqlite4_result_int(context, (configHasBeenReset&m)!=0 );
   270    270   }
   271    271   static void config_reset_function(
   272         -  sqlite3_context *context,
          272  +  sqlite4_context *context,
   273    273     int argc,
   274         -  sqlite3_value **argv
          274  +  sqlite4_value **argv
   275    275   ){
   276         -  int m = sqlite3_value_int(argv[0]);
          276  +  int m = sqlite4_value_int(argv[0]);
   277    277     configHasBeenReset |= m;
   278    278   }
   279    279   
   280    280   /*
   281    281   ** Create the temporary _xfer_reportfmt and _xfer_user tables that are
   282    282   ** necessary in order to evalute the SQL text generated by the
   283    283   ** configure_render_special_name() routine.
................................................................................
   333    333         @ END;
   334    334         @ CREATE TEMP TRIGGER _xfer_r3 BEFORE INSERT ON shun
   335    335         @ WHEN NOT config_is_reset(8) BEGIN
   336    336         @   DELETE FROM shun;
   337    337         @   SELECT config_reset(8);
   338    338         @ END;
   339    339       ;
   340         -    sqlite3_create_function(g.db, "config_is_reset", 1, SQLITE_UTF8, 0,
          340  +    sqlite4_create_function(g.db, "config_is_reset", 1, SQLITE4_UTF8, 0,
   341    341            config_is_reset_function, 0, 0);
   342         -    sqlite3_create_function(g.db, "config_reset", 1, SQLITE_UTF8, 0,
          342  +    sqlite4_create_function(g.db, "config_reset", 1, SQLITE4_UTF8, 0,
   343    343            config_reset_function, 0, 0);
   344    344       configHasBeenReset = 0;
   345    345       db_multi_exec(zSQL2);
   346    346     }
   347    347   }
   348    348   
   349    349   /*
................................................................................
   593    593   ** Send only entries whose timestamp is later than or equal to iStart.
   594    594   **
   595    595   ** Return the number of cards sent.
   596    596   */
   597    597   int configure_send_group(
   598    598     Blob *pOut,              /* Write output here */
   599    599     int groupMask,           /* Mask of groups to be send */
   600         -  sqlite3_int64 iStart     /* Only write values changed since this time */
          600  +  sqlite4_int64 iStart     /* Only write values changed since this time */
   601    601   ){
   602    602     Stmt q;
   603    603     Blob rec;
   604    604     int ii;
   605    605     int nCard = 0;
   606    606   
   607    607     blob_zero(&rec);
   608    608     if( groupMask & CONFIGSET_SHUN ){
   609    609       db_prepare(&q, "SELECT mtime, quote(uuid), quote(scom) FROM shun"
   610    610                      " WHERE mtime>=%lld", iStart);
   611         -    while( db_step(&q)==SQLITE_ROW ){
          611  +    while( db_step(&q)==SQLITE4_ROW ){
   612    612         blob_appendf(&rec,"%s %s scom %s",
   613    613           db_column_text(&q, 0),
   614    614           db_column_text(&q, 1),
   615    615           db_column_text(&q, 2)
   616    616         );
   617    617         blob_appendf(pOut, "config /shun %d\n%s\n",
   618    618                      blob_size(&rec), blob_str(&rec));
................................................................................
   621    621       }
   622    622       db_finalize(&q);
   623    623     }
   624    624     if( groupMask & CONFIGSET_USER ){
   625    625       db_prepare(&q, "SELECT mtime, quote(login), quote(pw), quote(cap),"
   626    626                      "       quote(info), quote(photo) FROM user"
   627    627                      " WHERE mtime>=%lld", iStart);
   628         -    while( db_step(&q)==SQLITE_ROW ){
          628  +    while( db_step(&q)==SQLITE4_ROW ){
   629    629         blob_appendf(&rec,"%s %s pw %s cap %s info %s photo %s",
   630    630           db_column_text(&q, 0),
   631    631           db_column_text(&q, 1),
   632    632           db_column_text(&q, 2),
   633    633           db_column_text(&q, 3),
   634    634           db_column_text(&q, 4),
   635    635           db_column_text(&q, 5)
................................................................................
   641    641       }
   642    642       db_finalize(&q);
   643    643     }
   644    644     if( groupMask & CONFIGSET_TKT ){
   645    645       db_prepare(&q, "SELECT mtime, quote(title), quote(owner), quote(cols),"
   646    646                      "       quote(sqlcode) FROM reportfmt"
   647    647                      " WHERE mtime>=%lld", iStart);
   648         -    while( db_step(&q)==SQLITE_ROW ){
          648  +    while( db_step(&q)==SQLITE4_ROW ){
   649    649         blob_appendf(&rec,"%s %s owner %s cols %s sqlcode %s",
   650    650           db_column_text(&q, 0),
   651    651           db_column_text(&q, 1),
   652    652           db_column_text(&q, 2),
   653    653           db_column_text(&q, 3),
   654    654           db_column_text(&q, 4)
   655    655         );
................................................................................
   659    659         blob_reset(&rec);
   660    660       }
   661    661       db_finalize(&q);
   662    662     }
   663    663     if( groupMask & CONFIGSET_ADDR ){
   664    664       db_prepare(&q, "SELECT mtime, quote(hash), quote(content) FROM concealed"
   665    665                      " WHERE mtime>=%lld", iStart);
   666         -    while( db_step(&q)==SQLITE_ROW ){
          666  +    while( db_step(&q)==SQLITE4_ROW ){
   667    667         blob_appendf(&rec,"%s %s content %s",
   668    668           db_column_text(&q, 0),
   669    669           db_column_text(&q, 1),
   670    670           db_column_text(&q, 2)
   671    671         );
   672    672         blob_appendf(pOut, "config /concealed %d\n%s\n",
   673    673                      blob_size(&rec), blob_str(&rec));
................................................................................
   677    677       db_finalize(&q);
   678    678     }
   679    679     db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config"
   680    680                    " WHERE name=:name AND mtime>=%lld", iStart);
   681    681     for(ii=0; ii<count(aConfig); ii++){
   682    682       if( (aConfig[ii].groupMask & groupMask)!=0 && aConfig[ii].zName[0]!='@' ){
   683    683         db_bind_text(&q, ":name", aConfig[ii].zName);
   684         -      while( db_step(&q)==SQLITE_ROW ){
          684  +      while( db_step(&q)==SQLITE4_ROW ){
   685    685           blob_appendf(&rec,"%s %s value %s",
   686    686             db_column_text(&q, 0),
   687    687             db_column_text(&q, 1),
   688    688             db_column_text(&q, 2)
   689    689           );
   690    690           blob_appendf(pOut, "config /config %d\n%s\n",
   691    691                        blob_size(&rec), blob_str(&rec));
................................................................................
   724    724   /*
   725    725   ** Write SQL text into file zFilename that will restore the configuration
   726    726   ** area identified by mask to its current state from any other state.
   727    727   */
   728    728   static void export_config(
   729    729     int groupMask,            /* Mask indicating which configuration to export */
   730    730     const char *zMask,        /* Name of the configuration */
   731         -  sqlite3_int64 iStart,     /* Start date */
          731  +  sqlite4_int64 iStart,     /* Start date */
   732    732     const char *zFilename     /* Write into this file */
   733    733   ){
   734    734     Blob out;
   735    735     blob_zero(&out);
   736    736     blob_appendf(&out, 
   737    737       "# The \"%s\" configuration exported from\n"
   738    738       "# repository \"%s\"\n"
................................................................................
   810    810     db_find_and_open_repository(0, 0);
   811    811     db_open_config(0);
   812    812     zMethod = g.argv[2];
   813    813     n = strlen(zMethod);
   814    814     if( strncmp(zMethod, "export", n)==0 ){
   815    815       int mask;
   816    816       const char *zSince = find_option("since",0,1);
   817         -    sqlite3_int64 iStart;
          817  +    sqlite4_int64 iStart;
   818    818       if( g.argc!=5 ){
   819    819         usage("export AREA FILENAME");
   820    820       }
   821    821       mask = configure_name_to_mask(g.argv[3], 1);
   822    822       if( zSince ){
   823    823         iStart = db_multi_exec(
   824    824            "SELECT coalesce(strftime('%%s',%Q),strftime('%%s','now',%Q))+0",

Changes to src/content.c.

   121    121   ** original content and not a delta.
   122    122   */
   123    123   static int findSrcid(int rid){
   124    124     static Stmt q;
   125    125     int srcid;
   126    126     db_static_prepare(&q, "SELECT srcid FROM delta WHERE rid=:rid");
   127    127     db_bind_int(&q, ":rid", rid);
   128         -  if( db_step(&q)==SQLITE_ROW ){
          128  +  if( db_step(&q)==SQLITE4_ROW ){
   129    129       srcid = db_column_int(&q, 0);
   130    130     }else{
   131    131       srcid = 0;
   132    132     }
   133    133     db_reset(&q);
   134    134     return srcid;
   135    135   }
................................................................................
   138    138   ** Return the blob.size field given blob.rid
   139    139   */
   140    140   int content_size(int rid, int dflt){
   141    141     static Stmt q;
   142    142     int sz = dflt;
   143    143     db_static_prepare(&q, "SELECT size FROM blob WHERE rid=:r");
   144    144     db_bind_int(&q, ":r", rid);
   145         -  if( db_step(&q)==SQLITE_ROW ){
          145  +  if( db_step(&q)==SQLITE4_ROW ){
   146    146       sz = db_column_int(&q, 0);
   147    147     }
   148    148     db_reset(&q);
   149    149     return sz;
   150    150   }
   151    151   
   152    152   /*
................................................................................
   192    192     bag_insert(&pending, rid);
   193    193     while( (rid = bag_first(&pending))!=0 ){
   194    194       bag_remove(&pending, rid);
   195    195       bag_remove(&contentCache.missing, rid);
   196    196       bag_insert(&contentCache.available, rid);
   197    197       db_static_prepare(&q, "SELECT rid FROM delta WHERE srcid=:rid");
   198    198       db_bind_int(&q, ":rid", rid);
   199         -    while( db_step(&q)==SQLITE_ROW ){
          199  +    while( db_step(&q)==SQLITE4_ROW ){
   200    200         int nx = db_column_int(&q, 0);
   201    201         bag_insert(&pending, nx);
   202    202       }
   203    203       db_reset(&q);
   204    204     }
   205    205     bag_clear(&pending);
   206    206   }
................................................................................
   210    210   ** 0 on failure.
   211    211   */
   212    212   static int content_of_blob(int rid, Blob *pBlob){
   213    213     static Stmt q;
   214    214     int rc = 0;
   215    215     db_static_prepare(&q, "SELECT content FROM blob WHERE rid=:rid AND size>=0");
   216    216     db_bind_int(&q, ":rid", rid);
   217         -  if( db_step(&q)==SQLITE_ROW ){
          217  +  if( db_step(&q)==SQLITE4_ROW ){
   218    218       db_ephemeral_blob(&q, 0, pBlob);
   219    219       blob_uncompress(pBlob, pBlob);
   220    220       rc = 1;
   221    221     }
   222    222     db_reset(&q);
   223    223     return rc;
   224    224   }
................................................................................
   390    390         content_get(rid, &content);
   391    391         manifest_crosslink(rid, &content);
   392    392         assert( blob_is_reset(&content) );
   393    393       }
   394    394   
   395    395       /* Parse all delta-manifests that depend on baseline-manifest rid */
   396    396       db_prepare(&q, "SELECT rid FROM orphan WHERE baseline=%d", rid);
   397         -    while( db_step(&q)==SQLITE_ROW ){
          397  +    while( db_step(&q)==SQLITE4_ROW ){
   398    398         int child = db_column_int(&q, 0);
   399    399         if( nChildUsed>=nChildAlloc ){
   400    400           nChildAlloc = nChildAlloc*2 + 10;
   401    401           aChild = fossil_realloc(aChild, nChildAlloc*sizeof(aChild));
   402    402         }
   403    403         aChild[nChildUsed++] = child;
   404    404       }
................................................................................
   418    418       nChildUsed = 0;
   419    419       db_prepare(&q, 
   420    420          "SELECT rid FROM delta"
   421    421          " WHERE srcid=%d"
   422    422          "   AND NOT EXISTS(SELECT 1 FROM mlink WHERE mid=delta.rid)",
   423    423          rid
   424    424       );
   425         -    while( db_step(&q)==SQLITE_ROW ){
          425  +    while( db_step(&q)==SQLITE4_ROW ){
   426    426         int child = db_column_int(&q, 0);
   427    427         if( nChildUsed>=nChildAlloc ){
   428    428           nChildAlloc = nChildAlloc*2 + 10;
   429    429           aChild = fossil_realloc(aChild, nChildAlloc*sizeof(aChild));
   430    430         }
   431    431         aChild[nChildUsed++] = child;
   432    432       }
................................................................................
   507    507     }
   508    508     db_begin_transaction();
   509    509   
   510    510     /* Check to see if the entry already exists and if it does whether
   511    511     ** or not the entry is a phantom
   512    512     */
   513    513     db_prepare(&s1, "SELECT rid, size FROM blob WHERE uuid=%B", &hash);
   514         -  if( db_step(&s1)==SQLITE_ROW ){
          514  +  if( db_step(&s1)==SQLITE4_ROW ){
   515    515       rid = db_column_int(&s1, 0);
   516    516       if( db_column_int(&s1, 1)>=0 || pBlob==0 ){
   517    517         /* Either the entry is not a phantom or it is a phantom but we
   518    518         ** have no data with which to dephantomize it.  In either case,
   519    519         ** there is nothing for us to do other than return the RID. */
   520    520         db_finalize(&s1);
   521    521         db_end_transaction(0);
................................................................................
   721    721     int rc;
   722    722     db_static_prepare(&s1,
   723    723       "SELECT 1 FROM private WHERE rid=:rid"
   724    724     );
   725    725     db_bind_int(&s1, ":rid", rid);
   726    726     rc = db_step(&s1);
   727    727     db_reset(&s1);
   728         -  return rc==SQLITE_ROW;  
          728  +  return rc==SQLITE4_ROW;  
   729    729   }
   730    730   
   731    731   /*
   732    732   ** Make sure an artifact is public.  
   733    733   */
   734    734   void content_make_public(int rid){
   735    735     static Stmt s1;
................................................................................
   843    843     db_prepare(&q,
   844    844       "SELECT "
   845    845       "   rid, (SELECT uuid FROM blob WHERE rid=delta.rid),"
   846    846       "   srcid, (SELECT uuid FROM blob WHERE rid=delta.srcid)"
   847    847       "  FROM delta"
   848    848       " WHERE srcid in private AND rid NOT IN private"
   849    849     );
   850         -  while( db_step(&q)==SQLITE_ROW ){
          850  +  while( db_step(&q)==SQLITE4_ROW ){
   851    851       int rid = db_column_int(&q, 0);
   852    852       const char *zId = db_column_text(&q, 1);
   853    853       int srcid = db_column_int(&q, 2);
   854    854       const char *zSrc = db_column_text(&q, 3);
   855    855       fossil_print(
   856    856         "public artifact %S (%d) is a delta from private artifact %S (%d)\n",
   857    857         zId, rid, zSrc, srcid
................................................................................
   858    858       );
   859    859       nErr++;
   860    860     }
   861    861     db_finalize(&q);
   862    862       
   863    863     db_prepare(&q, "SELECT rid, uuid, size FROM blob ORDER BY rid");
   864    864     total = db_int(0, "SELECT max(rid) FROM blob");
   865         -  while( db_step(&q)==SQLITE_ROW ){
          865  +  while( db_step(&q)==SQLITE4_ROW ){
   866    866       int rid = db_column_int(&q, 0);
   867    867       const char *zUuid = db_column_text(&q, 1);
   868    868       int size = db_column_int(&q, 2);
   869    869       n1++;
   870    870       fossil_print("  %d/%d\r", n1, total);
   871    871       fflush(stdout);
   872    872       if( size<0 ){

Changes to src/cson_amalgamation.c.

  1402   1402   
  1403   1403   #ifdef _MSC_VER
  1404   1404   #   if _MSC_VER >= 1400 /* Visual Studio 2005 and up */
  1405   1405   #     pragma warning( push )
  1406   1406   #     pragma warning(disable:4996) /* unsecure sscanf (but snscanf() isn't in c89) */
  1407   1407   #     pragma warning(disable:4244) /* complaining about data loss due
  1408   1408                                         to integer precision in the
  1409         -                                      sqlite3 utf decoding routines */
         1409  +                                      sqlite4 utf decoding routines */
  1410   1410   #   endif
  1411   1411   #endif
  1412   1412   
  1413   1413   #if 1
  1414   1414   #include <stdio.h>
  1415   1415   #define MARKER if(1) printf("MARKER: %s:%d:%s():\t",__FILE__,__LINE__,__func__); if(1) printf
  1416   1416   #else
................................................................................
  3680   3680               rc = cson_rc.UnknownError;
  3681   3681           }
  3682   3682       }
  3683   3683       return rc;
  3684   3684   }
  3685   3685   
  3686   3686   /**
  3687         -   The UTF code was originally taken from sqlite3's public-domain
         3687  +   The UTF code was originally taken from sqlite4's public-domain
  3688   3688      source code (http://sqlite.org), modified only slightly for use
  3689   3689      here. This code generates some "possible data loss" warnings on
  3690         -   MSVC, but if this code is good enough for sqlite3 then it's damned
         3690  +   MSVC, but if this code is good enough for sqlite4 then it's damned
  3691   3691      well good enough for me, so we disable that warning for Windows
  3692   3692      builds.
  3693   3693   */
  3694   3694   
  3695   3695   /*
  3696   3696   ** This lookup table is used to help decode the first byte of
  3697   3697   ** a multi-byte UTF8 character.
................................................................................
  5272   5272   
  5273   5273               if(obj) cleaner(obj);
  5274   5274           }
  5275   5275       }
  5276   5276       cson_kvp_list_reserve(self,0);
  5277   5277   }
  5278   5278   /* end file ./cson_lists.h */
  5279         -/* begin file ./cson_sqlite3.c */
  5280         -/** @file cson_sqlite3.c
         5279  +/* begin file ./cson_sqlite4.c */
         5280  +/** @file cson_sqlite4.c
  5281   5281   
  5282   5282   This file contains the implementation code for the cson
  5283         -sqlite3-to-JSON API.
         5283  +sqlite4-to-JSON API.
  5284   5284   
  5285   5285   License: the same as the cson core library.
  5286   5286   
  5287   5287   Author: Stephan Beal (http://wanderinghorse.net/home/stephan)
  5288   5288   */
  5289   5289   #if CSON_ENABLE_SQLITE3 /* we do this here for the sake of the amalgamation build */
  5290   5290   #include <assert.h>
................................................................................
  5297   5297   #define MARKER if(0) printf
  5298   5298   #endif
  5299   5299   
  5300   5300   #if defined(__cplusplus)
  5301   5301   extern "C" {
  5302   5302   #endif
  5303   5303   
  5304         -cson_value * cson_sqlite3_column_to_value( sqlite3_stmt * st, int col )
         5304  +cson_value * cson_sqlite4_column_to_value( sqlite4_stmt * st, int col )
  5305   5305   {
  5306   5306       if( ! st ) return NULL;
  5307   5307       else
  5308   5308       {
  5309   5309   #if 0
  5310         -        sqlite3_value * val = sqlite3_column_type(st,col);
  5311         -        int const vtype = val ? sqlite3_value_type(val) : -1;
         5310  +        sqlite4_value * val = sqlite4_column_type(st,col);
         5311  +        int const vtype = val ? sqlite4_value_type(val) : -1;
  5312   5312           if( ! val ) return cson_value_null();
  5313   5313   #else
  5314         -        int const vtype = sqlite3_column_type(st,col);
         5314  +        int const vtype = sqlite4_column_type(st,col);
  5315   5315   #endif
  5316   5316           switch( vtype )
  5317   5317           {
  5318         -          case SQLITE_NULL:
         5318  +          case SQLITE4_NULL:
  5319   5319                 return cson_value_null();
  5320         -          case SQLITE_INTEGER:
         5320  +          case SQLITE4_INTEGER:
  5321   5321                 /* FIXME: for large integers fall back to Double instead. */
  5322         -              return cson_value_new_integer( (cson_int_t) sqlite3_column_int64(st, col)  );
  5323         -          case SQLITE_FLOAT:
  5324         -              return cson_value_new_double( sqlite3_column_double(st, col) );
  5325         -          case SQLITE_BLOB: /* arguably fall through... */
  5326         -          case SQLITE_TEXT: {
  5327         -              char const * str = (char const *)sqlite3_column_text(st,col);
         5322  +              return cson_value_new_integer( (cson_int_t) sqlite4_column_int64(st, col)  );
         5323  +          case SQLITE4_FLOAT:
         5324  +              return cson_value_new_double( sqlite4_column_double(st, col) );
         5325  +          case SQLITE4_BLOB: /* arguably fall through... */
         5326  +          case SQLITE4_TEXT: {
         5327  +              char const * str = (char const *)sqlite4_column_text(st,col);
  5328   5328                 return cson_value_new_string(str, str ? strlen(str) : 0);
  5329   5329             }
  5330   5330             default:
  5331   5331                 return NULL;
  5332   5332           }
  5333   5333       }
  5334   5334   }
  5335   5335   
  5336         -cson_value * cson_sqlite3_column_names( sqlite3_stmt * st )
         5336  +cson_value * cson_sqlite4_column_names( sqlite4_stmt * st )
  5337   5337   {
  5338   5338       cson_value * aryV = NULL;
  5339   5339       cson_array * ary = NULL;
  5340   5340       char const * colName = NULL;
  5341   5341       int i = 0;
  5342   5342       int rc = 0;
  5343   5343       int colCount = 0;
  5344   5344       assert(st);
  5345         -    colCount = sqlite3_column_count(st);
         5345  +    colCount = sqlite4_column_count(st);
  5346   5346       if( colCount <= 0 ) return NULL;
  5347   5347       
  5348   5348       aryV = cson_value_new_array();
  5349   5349       if( ! aryV ) return NULL;
  5350   5350       ary = cson_value_get_array(aryV);
  5351   5351       assert(ary);
  5352   5352       for( i = 0; (0 ==rc) && (i < colCount); ++i )
  5353   5353       {
  5354         -        colName = sqlite3_column_name( st, i );
         5354  +        colName = sqlite4_column_name( st, i );
  5355   5355           if( ! colName ) rc = cson_rc.AllocError;
  5356   5356           else
  5357   5357           {
  5358   5358               rc = cson_array_set( ary, (unsigned int)i,
  5359   5359                       cson_value_new_string(colName, strlen(colName)) );
  5360   5360           }
  5361   5361       }
................................................................................
  5364   5364       {
  5365   5365           cson_value_free(aryV);
  5366   5366           return NULL;
  5367   5367       }
  5368   5368   }
  5369   5369   
  5370   5370   
  5371         -cson_value * cson_sqlite3_row_to_object2( sqlite3_stmt * st,
         5371  +cson_value * cson_sqlite4_row_to_object2( sqlite4_stmt * st,
  5372   5372                                             cson_array * colNames )
  5373   5373   {
  5374   5374       cson_value * rootV = NULL;
  5375   5375       cson_object * root = NULL;
  5376   5376       cson_string * colName = NULL;
  5377   5377       int i = 0;
  5378   5378       int rc = 0;
  5379   5379       cson_value * currentValue = NULL;
  5380         -    int const colCount = sqlite3_column_count(st);
         5380  +    int const colCount = sqlite4_column_count(st);
  5381   5381       if( !colCount || (colCount>cson_array_length_get(colNames)) ) {
  5382   5382           return NULL;
  5383   5383       }
  5384   5384       rootV = cson_value_new_object();
  5385   5385       if(!rootV) return NULL;
  5386   5386       root = cson_value_get_object(rootV);
  5387   5387       for( i = 0; i < colCount; ++i )
  5388   5388       {
  5389   5389           colName = cson_value_get_string( cson_array_get( colNames, i ) );
  5390   5390           if( ! colName ) goto error;
  5391         -        currentValue = cson_sqlite3_column_to_value(st,i);
         5391  +        currentValue = cson_sqlite4_column_to_value(st,i);
  5392   5392           if( ! currentValue ) currentValue = cson_value_null();
  5393   5393           rc = cson_object_set_s( root, colName, currentValue );
  5394   5394           if( 0 != rc )
  5395   5395           {
  5396   5396               cson_value_free( currentValue );
  5397   5397               goto error;
  5398   5398           }
................................................................................
  5402   5402       cson_value_free( rootV );
  5403   5403       rootV = NULL;
  5404   5404       end:
  5405   5405       return rootV;
  5406   5406   }
  5407   5407   
  5408   5408   
  5409         -cson_value * cson_sqlite3_row_to_object( sqlite3_stmt * st )
         5409  +cson_value * cson_sqlite4_row_to_object( sqlite4_stmt * st )
  5410   5410   {
  5411   5411   #if 0
  5412         -    cson_value * arV = cson_sqlite3_column_names(st);
         5412  +    cson_value * arV = cson_sqlite4_column_names(st);
  5413   5413       cson_array * ar = NULL;
  5414   5414       cson_value * rc = NULL;
  5415   5415       if(!arV) return NULL;
  5416   5416       ar = cson_value_get_array(arV);
  5417   5417       assert( NULL != ar );
  5418         -    rc = cson_sqlite3_row_to_object2(st, ar);
         5418  +    rc = cson_sqlite4_row_to_object2(st, ar);
  5419   5419       cson_value_free(arV);
  5420   5420       return rc;
  5421   5421   #else
  5422   5422       cson_value * rootV = NULL;
  5423   5423       cson_object * root = NULL;
  5424   5424       char const * colName = NULL;
  5425   5425       int i = 0;
  5426   5426       int rc = 0;
  5427   5427       cson_value * currentValue = NULL;
  5428         -    int const colCount = sqlite3_column_count(st);
         5428  +    int const colCount = sqlite4_column_count(st);
  5429   5429       if( !colCount ) return NULL;
  5430   5430       rootV = cson_value_new_object();
  5431   5431       if(!rootV) return NULL;
  5432   5432       root = cson_value_get_object(rootV);
  5433   5433       for( i = 0; i < colCount; ++i )
  5434   5434       {
  5435         -        colName = sqlite3_column_name( st, i );
         5435  +        colName = sqlite4_column_name( st, i );
  5436   5436           if( ! colName ) goto error;
  5437         -        currentValue = cson_sqlite3_column_to_value(st,i);
         5437  +        currentValue = cson_sqlite4_column_to_value(st,i);
  5438   5438           if( ! currentValue ) currentValue = cson_value_null();
  5439   5439           rc = cson_object_set( root, colName, currentValue );
  5440   5440           if( 0 != rc )
  5441   5441           {
  5442   5442               cson_value_free( currentValue );
  5443   5443               goto error;
  5444   5444           }
................................................................................
  5448   5448       cson_value_free( rootV );
  5449   5449       rootV = NULL;
  5450   5450       end:
  5451   5451       return rootV;
  5452   5452   #endif
  5453   5453   }
  5454   5454   
  5455         -cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st )
         5455  +cson_value * cson_sqlite4_row_to_array( sqlite4_stmt * st )
  5456   5456   {
  5457   5457       cson_value * aryV = NULL;
  5458   5458       cson_array * ary = NULL;
  5459   5459       int i = 0;
  5460   5460       int rc = 0;
  5461         -    int const colCount = sqlite3_column_count(st);
         5461  +    int const colCount = sqlite4_column_count(st);
  5462   5462       if( ! colCount ) return NULL;
  5463   5463       aryV = cson_value_new_array();
  5464   5464       if( ! aryV ) return NULL;
  5465   5465       ary = cson_value_get_array(aryV);
  5466   5466       rc = cson_array_reserve(ary, (unsigned int) colCount );
  5467   5467       if( 0 != rc ) goto error;
  5468   5468   
  5469   5469       for( i = 0; i < colCount; ++i ){
  5470         -        cson_value * elem = cson_sqlite3_column_to_value(st,i);
         5470  +        cson_value * elem = cson_sqlite4_column_to_value(st,i);
  5471   5471           if( ! elem ) goto error;
  5472   5472           rc = cson_array_append(ary,elem);
  5473   5473           if(0!=rc)
  5474   5474           {
  5475   5475               cson_value_free( elem );
  5476   5476               goto end;
  5477   5477           }
................................................................................
  5482   5482       aryV = NULL;
  5483   5483       end:
  5484   5484       return aryV;
  5485   5485   }
  5486   5486   
  5487   5487       
  5488   5488   /**
  5489         -    Internal impl of cson_sqlite3_stmt_to_json() when the 'fat'
         5489  +    Internal impl of cson_sqlite4_stmt_to_json() when the 'fat'
  5490   5490       parameter is non-0.
  5491   5491   */
  5492         -static int cson_sqlite3_stmt_to_json_fat( sqlite3_stmt * st, cson_value ** tgt )
         5492  +static int cson_sqlite4_stmt_to_json_fat( sqlite4_stmt * st, cson_value ** tgt )
  5493   5493   {
  5494   5494   #define RETURN(RC) { if(rootV) cson_value_free(rootV); return RC; }
  5495   5495       if( ! tgt || !st ) return cson_rc.ArgError;
  5496   5496       else
  5497   5497       {
  5498   5498           cson_value * rootV = NULL;
  5499   5499           cson_object * root = NULL;
  5500   5500           cson_value * colsV = NULL;
  5501   5501           cson_array * cols = NULL;
  5502   5502           cson_value * rowsV = NULL;
  5503   5503           cson_array * rows = NULL;
  5504   5504           cson_value * objV = NULL;
  5505   5505           int rc = 0;
  5506         -        int const colCount = sqlite3_column_count(st);
         5506  +        int const colCount = sqlite4_column_count(st);
  5507   5507           if( colCount <= 0 ) return cson_rc.ArgError;
  5508   5508           rootV = cson_value_new_object();
  5509   5509           if( ! rootV ) return cson_rc.AllocError;
  5510         -        colsV = cson_sqlite3_column_names(st);
         5510  +        colsV = cson_sqlite4_column_names(st);
  5511   5511           if( ! colsV )
  5512   5512           {
  5513   5513               cson_value_free( rootV );
  5514   5514               RETURN(cson_rc.AllocError);
  5515   5515           }
  5516   5516           cols = cson_value_get_array(colsV);
  5517   5517           assert(NULL != cols);
................................................................................
  5528   5528           if( rc )
  5529   5529           {
  5530   5530               cson_value_free( rowsV );
  5531   5531               RETURN(rc);
  5532   5532           }
  5533   5533           rows = cson_value_get_array(rowsV);
  5534   5534           assert(rows);
  5535         -        while( SQLITE_ROW == sqlite3_step(st) )
         5535  +        while( SQLITE4_ROW == sqlite4_step(st) )
  5536   5536           {
  5537         -            objV = cson_sqlite3_row_to_object2(st, cols);
         5537  +            objV = cson_sqlite4_row_to_object2(st, cols);
  5538   5538               if( ! objV ) RETURN(cson_rc.UnknownError);
  5539   5539               rc = cson_array_append( rows, objV );
  5540   5540               if( rc )
  5541   5541               {
  5542   5542                   cson_value_free( objV );
  5543   5543                   RETURN(rc);
  5544   5544               }
................................................................................
  5546   5546           *tgt = rootV;
  5547   5547           return 0;
  5548   5548       }
  5549   5549   #undef RETURN
  5550   5550   }
  5551   5551   
  5552   5552   /**
  5553         -    Internal impl of cson_sqlite3_stmt_to_json() when the 'fat'
         5553  +    Internal impl of cson_sqlite4_stmt_to_json() when the 'fat'
  5554   5554       parameter is 0.
  5555   5555   */
  5556         -static int cson_sqlite3_stmt_to_json_slim( sqlite3_stmt * st, cson_value ** tgt )
         5556  +static int cson_sqlite4_stmt_to_json_slim( sqlite4_stmt * st, cson_value ** tgt )
  5557   5557   {
  5558   5558   #define RETURN(RC) { if(rootV) cson_value_free(rootV); return RC; }
  5559   5559       if( ! tgt || !st ) return cson_rc.ArgError;
  5560   5560       else
  5561   5561       {
  5562   5562           cson_value * rootV = NULL;
  5563   5563           cson_object * root = NULL;
  5564   5564           cson_value * aryV = NULL;
  5565   5565           cson_value * rowsV = NULL;
  5566   5566           cson_array * rows = NULL;
  5567   5567           int rc = 0;
  5568         -        int const colCount = sqlite3_column_count(st);
         5568  +        int const colCount = sqlite4_column_count(st);
  5569   5569           if( colCount <= 0 ) return cson_rc.ArgError;
  5570   5570           rootV = cson_value_new_object();
  5571   5571           if( ! rootV ) return cson_rc.AllocError;
  5572         -        aryV = cson_sqlite3_column_names(st);
         5572  +        aryV = cson_sqlite4_column_names(st);
  5573   5573           if( ! aryV )
  5574   5574           {
  5575   5575               cson_value_free( rootV );
  5576   5576               RETURN(cson_rc.AllocError);
  5577   5577           }
  5578   5578           root = cson_value_get_object(rootV);
  5579   5579           rc = cson_object_set( root, "columns", aryV );
................................................................................
  5589   5589           if( 0 != rc )
  5590   5590           {
  5591   5591               cson_value_free( rowsV );
  5592   5592               RETURN(rc);
  5593   5593           }
  5594   5594           rows = cson_value_get_array(rowsV);
  5595   5595           assert(rows);
  5596         -        while( SQLITE_ROW == sqlite3_step(st) )
         5596  +        while( SQLITE4_ROW == sqlite4_step(st) )
  5597   5597           {
  5598         -            aryV = cson_sqlite3_row_to_array(st);
         5598  +            aryV = cson_sqlite4_row_to_array(st);
  5599   5599               if( ! aryV ) RETURN(cson_rc.UnknownError);
  5600   5600               rc = cson_array_append( rows, aryV );
  5601   5601               if( 0 != rc )
  5602   5602               {
  5603   5603                   cson_value_free( aryV );
  5604   5604                   RETURN(rc);
  5605   5605               }
................................................................................
  5606   5606           }
  5607   5607           *tgt = rootV;
  5608   5608           return 0;
  5609   5609       }
  5610   5610   #undef RETURN
  5611   5611   }
  5612   5612   
  5613         -int cson_sqlite3_stmt_to_json( sqlite3_stmt * st, cson_value ** tgt, char fat )
         5613  +int cson_sqlite4_stmt_to_json( sqlite4_stmt * st, cson_value ** tgt, char fat )
  5614   5614   {
  5615   5615       return fat
  5616         -        ? cson_sqlite3_stmt_to_json_fat(st,tgt)
  5617         -        : cson_sqlite3_stmt_to_json_slim(st,tgt)
         5616  +        ? cson_sqlite4_stmt_to_json_fat(st,tgt)
         5617  +        : cson_sqlite4_stmt_to_json_slim(st,tgt)
  5618   5618           ;
  5619   5619   }
  5620   5620   
  5621         -int cson_sqlite3_sql_to_json( sqlite3 * db, cson_value ** tgt, char const * sql, char fat )
         5621  +int cson_sqlite4_sql_to_json( sqlite4 * db, cson_value ** tgt, char const * sql, char fat )
  5622   5622   {
  5623   5623       if( !db || !tgt || !sql || !*sql ) return cson_rc.ArgError;
  5624   5624       else
  5625   5625       {
  5626         -        sqlite3_stmt * st = NULL;
  5627         -        int rc = sqlite3_prepare_v2( db, sql, -1, &st, NULL );
         5626  +        sqlite4_stmt * st = NULL;
         5627  +        int rc = sqlite4_prepare( db, sql, -1, &st, NULL );
  5628   5628           if( 0 != rc ) return cson_rc.IOError /* FIXME: Better error code? */;
  5629         -        rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
  5630         -        sqlite3_finalize( st );
         5629  +        rc = cson_sqlite4_stmt_to_json( st, tgt, fat );
         5630  +        sqlite4_finalize( st );
  5631   5631           return rc;
  5632   5632       }        
  5633   5633   }
  5634   5634   
  5635         -int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v )
         5635  +int cson_sqlite4_bind_value( sqlite4_stmt * st, int ndx, cson_value const * v )
  5636   5636   {
  5637   5637       int rc = 0;
  5638   5638       char convertErr = 0;
  5639   5639       if(!st) return cson_rc.ArgError;
  5640   5640       else if( ndx < 1 ) {
  5641   5641           rc = cson_rc.RangeError;
  5642   5642       }
  5643   5643       else if( cson_value_is_array(v) ){
  5644   5644           cson_array * ar = cson_value_get_array(v);
  5645   5645           unsigned int len = cson_array_length_get(ar);
  5646   5646           unsigned int i;
  5647   5647           assert(NULL != ar);
  5648   5648           for( i = 0; !rc && (i < len); ++i ){
  5649         -            rc = cson_sqlite3_bind_value( st, (int)i+ndx,
         5649  +            rc = cson_sqlite4_bind_value( st, (int)i+ndx,
  5650   5650                                             cson_array_get(ar, i));
  5651   5651           }
  5652   5652       }
  5653   5653       else if(!v || cson_value_is_null(v)){
  5654         -        rc = sqlite3_bind_null(st,ndx);
         5654  +        rc = sqlite4_bind_null(st,ndx);
  5655   5655           convertErr = 1;
  5656   5656       }
  5657   5657       else if( cson_value_is_double(v) ){
  5658         -        rc = sqlite3_bind_double( st, ndx, cson_value_get_double(v) );
         5658  +        rc = sqlite4_bind_double( st, ndx, cson_value_get_double(v) );
  5659   5659           convertErr = 1;
  5660   5660       }
  5661   5661       else if( cson_value_is_bool(v) ){
  5662         -        rc = sqlite3_bind_int( st, ndx, cson_value_get_bool(v) ? 1 : 0 );
         5662  +        rc = sqlite4_bind_int( st, ndx, cson_value_get_bool(v) ? 1 : 0 );
  5663   5663           convertErr = 1;
  5664   5664       }
  5665   5665       else if( cson_value_is_integer(v) ){
  5666         -        rc = sqlite3_bind_int64( st, ndx, cson_value_get_integer(v) );
         5666  +        rc = sqlite4_bind_int64( st, ndx, cson_value_get_integer(v) );
  5667   5667           convertErr = 1;
  5668   5668       }
  5669   5669       else if( cson_value_is_string(v) ){
  5670   5670           cson_string const * s = cson_value_get_string(v);
  5671         -        rc = sqlite3_bind_text( st, ndx,
         5671  +        rc = sqlite4_bind_text( st, ndx,
  5672   5672                                   cson_string_cstr(s),
  5673   5673                                   cson_string_length_bytes(s),
  5674         -                                SQLITE_TRANSIENT);
         5674  +                                SQLITE4_TRANSIENT);
  5675   5675           convertErr = 1;
  5676   5676       }
  5677   5677       else {
  5678   5678           rc = cson_rc.TypeError;
  5679   5679       }
  5680   5680       if(convertErr && rc) switch(rc){
  5681         -      case SQLITE_TOOBIG:
  5682         -      case SQLITE_RANGE: rc = cson_rc.RangeError; break;
  5683         -      case SQLITE_NOMEM: rc = cson_rc.AllocError; break;
  5684         -      case SQLITE_IOERR: rc = cson_rc.IOError; break;
         5681  +      case SQLITE4_TOOBIG:
         5682  +      case SQLITE4_RANGE: rc = cson_rc.RangeError; break;
         5683  +      case SQLITE4_NOMEM: rc = cson_rc.AllocError; break;
         5684  +      case SQLITE4_IOERR: rc = cson_rc.IOError; break;
  5685   5685         default: rc = cson_rc.UnknownError; break;
  5686   5686       };
  5687   5687       return rc;
  5688   5688   }
  5689   5689   
  5690   5690   
  5691   5691   #if defined(__cplusplus)
  5692   5692   } /*extern "C"*/
  5693   5693   #endif
  5694   5694   #undef MARKER
  5695   5695   #endif /* CSON_ENABLE_SQLITE3 */
  5696         -/* end file ./cson_sqlite3.c */
         5696  +/* end file ./cson_sqlite4.c */
  5697   5697   #endif /* FOSSIL_ENABLE_JSON */

Changes to src/cson_amalgamation.h.

  2299   2299   
  2300   2300   #if defined(__cplusplus)
  2301   2301   } /*extern "C"*/
  2302   2302   #endif
  2303   2303   
  2304   2304   #endif /* WANDERINGHORSE_NET_CSON_H_INCLUDED */
  2305   2305   /* end file include/wh/cson/cson.h */
  2306         -/* begin file include/wh/cson/cson_sqlite3.h */
  2307         -/** @file cson_sqlite3.h
         2306  +/* begin file include/wh/cson/cson_sqlite4.h */
         2307  +/** @file cson_sqlite4.h
  2308   2308   
  2309         -This file contains cson's public sqlite3-to-JSON API declarations
         2309  +This file contains cson's public sqlite4-to-JSON API declarations
  2310   2310   and API documentation. If CSON_ENABLE_SQLITE3 is not defined,
  2311   2311   or is defined to 0, then including this file will have no side-effects
  2312   2312   other than defining CSON_ENABLE_SQLITE3 (if it was not defined) to 0
  2313   2313   and defining a few include guard macros. i.e. if CSON_ENABLE_SQLITE3
  2314   2314   is not set to a true value then the API is not visible.
  2315   2315   
  2316         -This API requires that <sqlite3.h> be in the INCLUDES path and that
  2317         -the client eventually link to (or directly embed) the sqlite3 library.
         2316  +This API requires that <sqlite4.h> be in the INCLUDES path and that
         2317  +the client eventually link to (or directly embed) the sqlite4 library.
  2318   2318   */
  2319   2319   #if !defined(WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED)
  2320   2320   #define WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED 1
  2321   2321   #if !defined(CSON_ENABLE_SQLITE3)
  2322   2322   #  if defined(DOXYGEN)
  2323   2323   #define CSON_ENABLE_SQLITE3 1
  2324   2324   #  else
  2325   2325   #define CSON_ENABLE_SQLITE3 1
  2326   2326   #  endif
  2327   2327   #endif
  2328   2328   
  2329   2329   #if CSON_ENABLE_SQLITE3 /* we do this here for the sake of the amalgamation build */
  2330         -#include <sqlite3.h>
         2330  +#include <sqlite4.h>
  2331   2331   
  2332   2332   #if defined(__cplusplus)
  2333   2333   extern "C" {
  2334   2334   #endif
  2335   2335   
  2336   2336   /**
  2337   2337      Converts a single value from a single 0-based column index to its JSON
  2338   2338      equivalent.
  2339   2339   
  2340   2340      On success it returns a new JSON value, which will have a different concrete
  2341         -   type depending on the field type reported by sqlite3_column_type(st,col):
         2341  +   type depending on the field type reported by sqlite4_column_type(st,col):
  2342   2342   
  2343   2343      Integer, double, null, or string (TEXT and BLOB data, though not
  2344   2344      all blob data is legal for a JSON string).
  2345   2345   
  2346         -   st must be a sqlite3_step()'d row and col must be a 0-based column
         2346  +   st must be a sqlite4_step()'d row and col must be a 0-based column
  2347   2347      index within that result row.
  2348   2348    */       
  2349         -cson_value * cson_sqlite3_column_to_value( sqlite3_stmt * st, int col );
         2349  +cson_value * cson_sqlite4_column_to_value( sqlite4_stmt * st, int col );
  2350   2350   
  2351   2351   /**
  2352   2352      Creates a JSON Array object containing the names of all columns
  2353   2353      of the given prepared statement handle. 
  2354   2354       
  2355   2355      Returns a new array value on success, which the caller owns. Its elements
  2356   2356      are in the same order as in the underlying query.
  2357   2357   
  2358   2358      On error NULL is returned.
  2359   2359       
  2360   2360      st is not traversed or freed by this function - only the column
  2361   2361      count and names are read.
  2362   2362   */
  2363         -cson_value * cson_sqlite3_column_names( sqlite3_stmt * st );
         2363  +cson_value * cson_sqlite4_column_names( sqlite4_stmt * st );
  2364   2364   
  2365   2365   /**
  2366   2366      Creates a JSON Object containing key/value pairs corresponding
  2367   2367      to the result columns in the current row of the given statement
  2368         -   handle. st must be a sqlite3_step()'d row result.
         2368  +   handle. st must be a sqlite4_step()'d row result.
  2369   2369   
  2370   2370      On success a new Object is returned which is owned by the
  2371   2371      caller. On error NULL is returned.
  2372   2372   
  2373         -   cson_sqlite3_column_to_value() is used to convert each column to a
         2373  +   cson_sqlite4_column_to_value() is used to convert each column to a
  2374   2374      JSON value, and the column names are taken from
  2375         -   sqlite3_column_name().
         2375  +   sqlite4_column_name().
  2376   2376   */
  2377         -cson_value * cson_sqlite3_row_to_object( sqlite3_stmt * st );
         2377  +cson_value * cson_sqlite4_row_to_object( sqlite4_stmt * st );
  2378   2378   /**
  2379         -   Functionally almost identical to cson_sqlite3_row_to_object(), the
         2379  +   Functionally almost identical to cson_sqlite4_row_to_object(), the
  2380   2380      only difference being how the result objects gets its column names.
  2381   2381      st must be a freshly-step()'d handle holding a result row.
  2382   2382      colNames must be an Array with at least the same number of columns
  2383   2383      as st. If it has fewer, NULL is returned and this function has
  2384   2384      no side-effects.
  2385   2385   
  2386   2386      For each column in the result set, the colNames entry at the same
  2387   2387      index is used for the column key. If a given entry is-not-a String
  2388   2388      then conversion will fail and NULL will be returned.
  2389   2389   
  2390         -   The one reason to prefer this over cson_sqlite3_row_to_object() is
         2390  +   The one reason to prefer this over cson_sqlite4_row_to_object() is
  2391   2391      that this one can share the keys across multiple rows (or even
  2392   2392      other JSON containers), whereas the former makes fresh copies of
  2393   2393      the column names for each row.
  2394   2394   
  2395   2395   */
  2396         -cson_value * cson_sqlite3_row_to_object2( sqlite3_stmt * st,
         2396  +cson_value * cson_sqlite4_row_to_object2( sqlite4_stmt * st,
  2397   2397                                             cson_array * colNames );
  2398   2398   
  2399   2399   /**
  2400         -   Similar to cson_sqlite3_row_to_object(), but creates an Array
         2400  +   Similar to cson_sqlite4_row_to_object(), but creates an Array
  2401   2401      value which contains the JSON-form values of the given result
  2402   2402      set row.
  2403   2403   */
  2404         -cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st );
         2404  +cson_value * cson_sqlite4_row_to_array( sqlite4_stmt * st );
  2405   2405   /**
  2406         -    Converts the results of an sqlite3 SELECT statement to JSON,
         2406  +    Converts the results of an sqlite4 SELECT statement to JSON,
  2407   2407       in the form of a cson_value object tree.
  2408   2408       
  2409   2409       st must be a prepared, but not yet traversed, SELECT query.
  2410   2410       tgt must be a pointer to NULL (see the example below). If
  2411   2411       either of those arguments are NULL, cson_rc.ArgError is returned.
  2412   2412       
  2413   2413       This walks the query results and returns a JSON object which
................................................................................
  2454   2454       JSON object tree (using the above structure), which the caller owns.
  2455   2455       If the query returns no rows, the "rows" value will be an empty
  2456   2456       array, as opposed to null.
  2457   2457       
  2458   2458       On error non-0 is returned and *tgt is not modified.
  2459   2459       
  2460   2460       The error code cson_rc.IOError is used to indicate a db-level
  2461         -    error, and cson_rc.TypeError is returned if sqlite3_column_count(st)
         2461  +    error, and cson_rc.TypeError is returned if sqlite4_column_count(st)
  2462   2462       returns 0 or less (indicating an invalid or non-SELECT statement).
  2463   2463       
  2464   2464       The JSON data types are determined by the column type as reported
  2465         -    by sqlite3_column_type():
         2465  +    by sqlite4_column_type():
  2466   2466       
  2467   2467       SQLITE_INTEGER: integer
  2468   2468       
  2469   2469       SQLITE_FLOAT: double
  2470   2470       
  2471   2471       SQLITE_TEXT or SQLITE_BLOB: string, and this will only work if
  2472   2472       the data is UTF8 compatible.
................................................................................
  2475   2475       to a JSON null. If it somehow finds a column type it cannot handle,
  2476   2476       the value is also converted to a NULL in the output.
  2477   2477   
  2478   2478       Example
  2479   2479       
  2480   2480       @code
  2481   2481       cson_value * json = NULL;
  2482         -    int rc = cson_sqlite3_stmt_to_json( myStatement, &json, 1 );
         2482  +    int rc = cson_sqlite4_stmt_to_json( myStatement, &json, 1 );
  2483   2483       if( 0 != rc ) { ... error ... }
  2484   2484       else {
  2485   2485           cson_output_FILE( json, stdout, NULL );
  2486   2486           cson_value_free( json );
  2487   2487       }
  2488   2488       @endcode
  2489   2489   */
  2490         -int cson_sqlite3_stmt_to_json( sqlite3_stmt * st, cson_value ** tgt, char fat );
         2490  +int cson_sqlite4_stmt_to_json( sqlite4_stmt * st, cson_value ** tgt, char fat );
  2491   2491   
  2492   2492   /**
  2493         -    A convenience wrapper around cson_sqlite3_stmt_to_json(), which
  2494         -    takes SQL instead of a sqlite3_stmt object. It has the same
         2493  +    A convenience wrapper around cson_sqlite4_stmt_to_json(), which
         2494  +    takes SQL instead of a sqlite4_stmt object. It has the same
  2495   2495       return value and argument semantics as that function.
  2496   2496   */
  2497         -int cson_sqlite3_sql_to_json( sqlite3 * db, cson_value ** tgt, char const * sql, char fat );
         2497  +int cson_sqlite4_sql_to_json( sqlite4 * db, cson_value ** tgt, char const * sql, char fat );
  2498   2498   
  2499   2499   /**
  2500   2500      Binds a JSON value to a 1-based parameter index in a prepared SQL
  2501   2501      statement. v must be NULL or one of one of the types (null, string,
  2502   2502      integer, double, boolean, array). Booleans are bound as integer 0
  2503   2503      or 1. NULL or null are bound as SQL NULL. Integers are bound as
  2504         -   64-bit ints. Strings are bound using sqlite3_bind_text() (as
         2504  +   64-bit ints. Strings are bound using sqlite4_bind_text() (as
  2505   2505      opposed to text16), but we could/should arguably bind them as
  2506   2506      blobs.
  2507   2507   
  2508   2508      If v is an Array then ndx is is used as a starting position
  2509   2509      (1-based) and each item in the array is bound to the next parameter
  2510   2510      position (starting and ndx, though the array uses 0-based offsets).
  2511   2511   
  2512   2512      TODO: add Object support for named parameters.
  2513   2513   
  2514   2514      Returns 0 on success, non-0 on error.
  2515   2515    */
  2516         -int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v );
         2516  +int cson_sqlite4_bind_value( sqlite4_stmt * st, int ndx, cson_value const * v );
  2517   2517       
  2518   2518   #if defined(__cplusplus)
  2519   2519   } /*extern "C"*/
  2520   2520   #endif
  2521   2521       
  2522   2522   #endif /* CSON_ENABLE_SQLITE3 */
  2523   2523   #endif /* WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED */
  2524         -/* end file include/wh/cson/cson_sqlite3.h */
         2524  +/* end file include/wh/cson/cson_sqlite4.h */
  2525   2525   #endif /* FOSSIL_ENABLE_JSON */

Changes to src/db.c.

    28     28   **         and located at the root of the local copy of the source tree.
    29     29   **
    30     30   */
    31     31   #include "config.h"
    32     32   #if ! defined(_WIN32)
    33     33   #  include <pwd.h>
    34     34   #endif
    35         -#include <sqlite3.h>
           35  +#include <sqlite4.h>
    36     36   #include <sys/types.h>
    37     37   #include <sys/stat.h>
    38     38   #include <unistd.h>
    39     39   #include <time.h>
    40     40   #include "db.h"
    41     41   
    42     42   #if INTERFACE
    43     43   /*
    44     44   ** An single SQL statement is represented as an instance of the following
    45     45   ** structure.
    46     46   */
    47     47   struct Stmt {
    48     48     Blob sql;               /* The SQL for this statement */
    49         -  sqlite3_stmt *pStmt;    /* The results of sqlite3_prepare() */
           49  +  sqlite4_stmt *pStmt;    /* The results of sqlite4_prepare() */
    50     50     Stmt *pNext, *pPrev;    /* List of all unfinalized statements */
    51         -  int nStep;              /* Number of sqlite3_step() calls */
           51  +  int nStep;              /* Number of sqlite4_step() calls */
    52     52   };
    53     53   
    54     54   /*
    55     55   ** Copy this to initialize a Stmt object to a clean/empty state. This
    56     56   ** is useful to help avoid assertions when performing cleanup in some
    57     57   ** error handling cases.
    58     58   */
................................................................................
   106    106   ** the following structure.
   107    107   */
   108    108   static struct DbLocalData {
   109    109     int nBegin;               /* Nesting depth of BEGIN */
   110    110     int doRollback;           /* True to force a rollback */
   111    111     int nCommitHook;          /* Number of commit hooks */
   112    112     Stmt *pAllStmt;           /* List of all unfinalized statements */
   113         -  int nPrepare;             /* Number of calls to sqlite3_prepare() */
          113  +  int nPrepare;             /* Number of calls to sqlite4_prepare() */
   114    114     int nDeleteOnFail;        /* Number of entries in azDeleteOnFail[] */
   115    115     struct sCommitHook {
   116    116       int (*xHook)(void);         /* Functions to call at db_end_transaction() */
   117    117       int sequence;               /* Call functions in sequence order */
   118    118     } aHook[5];
   119    119     char *azDeleteOnFail[3];  /* Files to delete on a failure */
   120    120     char *azBeforeCommit[5];  /* Commands to run prior to COMMIT */
   121    121     int nBeforeCommit;        /* Number of entries in azBeforeCommit */
   122         -  int nPriorChanges;        /* sqlite3_total_changes() at transaction start */
          122  +  int nPriorChanges;        /* sqlite4_total_changes() at transaction start */
   123    123   } db = {0, 0, 0, 0, 0, 0, };
   124    124   
   125    125   /*
   126    126   ** Arrange for the given file to be deleted on a failure.
   127    127   */
   128    128   void db_delete_on_failure(const char *zFilename){
   129    129     assert( db.nDeleteOnFail<count(db.azDeleteOnFail) );
................................................................................
   149    149   
   150    150   /*
   151    151   ** Begin and end a nested transaction
   152    152   */
   153    153   void db_begin_transaction(void){
   154    154     if( db.nBegin==0 ){
   155    155       db_multi_exec("BEGIN");
   156         -    sqlite3_commit_hook(g.db, db_verify_at_commit, 0);
   157         -    db.nPriorChanges = sqlite3_total_changes(g.db);
          156  +    /* sqlite3_commit_hook(g.db, db_verify_at_commit, 0); */
          157  +    db.nPriorChanges = sqlite4_total_changes(g.db);
   158    158     }
   159    159     db.nBegin++;
   160    160   }
   161    161   void db_end_transaction(int rollbackFlag){
   162    162     if( g.db==0 ) return;
   163    163     if( db.nBegin<=0 ) return;
   164    164     if( rollbackFlag ) db.doRollback = 1;
   165    165     db.nBegin--;
   166    166     if( db.nBegin==0 ){
   167    167       int i;
   168         -    if( db.doRollback==0 && db.nPriorChanges<sqlite3_total_changes(g.db) ){
          168  +    if( db.doRollback==0 && db.nPriorChanges<sqlite4_total_changes(g.db) ){
   169    169         while( db.nBeforeCommit ){
   170    170           db.nBeforeCommit--;
   171         -        sqlite3_exec(g.db, db.azBeforeCommit[db.nBeforeCommit], 0, 0, 0);
   172         -        sqlite3_free(db.azBeforeCommit[db.nBeforeCommit]);
          171  +        sqlite4_exec(g.db, db.azBeforeCommit[db.nBeforeCommit], 0, 0, 0);
          172  +        sqlite4_free(0, db.azBeforeCommit[db.nBeforeCommit]);
   173    173         }
   174    174         leaf_do_pending_checks();
   175    175       }
   176    176       for(i=0; db.doRollback==0 && i<db.nCommitHook; i++){
   177    177         db.doRollback |= db.aHook[i].xHook();
   178    178       }
   179    179       while( db.pAllStmt ){
................................................................................
   186    186   
   187    187   /*
   188    188   ** Force a rollback and shutdown the database
   189    189   */
   190    190   void db_force_rollback(void){
   191    191     int i;
   192    192     static int busy = 0;
   193         -  sqlite3_stmt *pStmt = 0;
          193  +  sqlite4_stmt *pStmt = 0;
   194    194     if( busy || g.db==0 ) return;
   195    195     busy = 1;
   196    196     undo_rollback();
   197         -  while( (pStmt = sqlite3_next_stmt(g.db,pStmt))!=0 ){
   198         -    sqlite3_reset(pStmt);
          197  +  while( (pStmt = sqlite4_next_stmt(g.db,pStmt))!=0 ){
          198  +    sqlite4_reset(pStmt);
   199    199     }
   200    200     while( db.pAllStmt ){
   201    201       db_finalize(db.pAllStmt);
   202    202     }
   203    203     if( db.nBegin ){
   204         -    sqlite3_exec(g.db, "ROLLBACK", 0, 0, 0);
          204  +    sqlite4_exec(g.db, "ROLLBACK", 0, 0, 0);
   205    205       db.nBegin = 0;
   206    206     }
   207    207     busy = 0;
   208    208     db_close(0);
   209    209     for(i=0; i<db.nDeleteOnFail; i++){
   210    210       file_delete(db.azDeleteOnFail[i]);
   211    211     }
................................................................................
   249    249     int rc;
   250    250     char *zSql;
   251    251     blob_zero(&pStmt->sql);
   252    252     blob_vappendf(&pStmt->sql, zFormat, ap);
   253    253     va_end(ap);
   254    254     zSql = blob_str(&pStmt->sql);
   255    255     db.nPrepare++;
   256         -  rc = sqlite3_prepare_v2(g.db, zSql, -1, &pStmt->pStmt, 0);
          256  +  rc = sqlite4_prepare(g.db, zSql, -1, &pStmt->pStmt, 0);
   257    257     if( rc!=0 && !errOk ){
   258         -    db_err("%s\n%s", sqlite3_errmsg(g.db), zSql);
          258  +    db_err("%s\n%s", sqlite4_errmsg(g.db), zSql);
   259    259     }
   260    260     pStmt->pNext = pStmt->pPrev = 0;
   261    261     pStmt->nStep = 0;
   262    262     return rc;
   263    263   }
   264    264   int db_prepare(Stmt *pStmt, const char *zFormat, ...){
   265    265     int rc;
................................................................................
   274    274     va_list ap;
   275    275     va_start(ap, zFormat);
   276    276     rc = db_vprepare(pStmt, 1, zFormat, ap);
   277    277     va_end(ap);
   278    278     return rc;
   279    279   }
   280    280   int db_static_prepare(Stmt *pStmt, const char *zFormat, ...){
   281         -  int rc = SQLITE_OK;
          281  +  int rc = SQLITE4_OK;
   282    282     if( blob_size(&pStmt->sql)==0 ){
   283    283       va_list ap;
   284    284       va_start(ap, zFormat);
   285    285       rc = db_vprepare(pStmt, 0, zFormat, ap);
   286    286       pStmt->pNext = db.pAllStmt;
   287    287       pStmt->pPrev = 0;
   288    288       if( db.pAllStmt ) db.pAllStmt->pPrev = pStmt;
................................................................................
   292    292     return rc;
   293    293   }
   294    294   
   295    295   /*
   296    296   ** Return the index of a bind parameter
   297    297   */
   298    298   static int paramIdx(Stmt *pStmt, const char *zParamName){
   299         -  int i = sqlite3_bind_parameter_index(pStmt->pStmt, zParamName);
          299  +  int i = sqlite4_bind_parameter_index(pStmt->pStmt, zParamName);
   300    300     if( i==0 ){
   301    301       db_err("no such bind parameter: %s\nSQL: %b", zParamName, &pStmt->sql);
   302    302     }
   303    303     return i;
   304    304   }
   305    305   /*
   306    306   ** Bind an integer, string, or Blob value to a named parameter.
   307    307   */
   308    308   int db_bind_int(Stmt *pStmt, const char *zParamName, int iValue){
   309         -  return sqlite3_bind_int(pStmt->pStmt, paramIdx(pStmt, zParamName), iValue);
          309  +  return sqlite4_bind_int(pStmt->pStmt, paramIdx(pStmt, zParamName), iValue);
   310    310   }
   311    311   int db_bind_int64(Stmt *pStmt, const char *zParamName, i64 iValue){
   312         -  return sqlite3_bind_int64(pStmt->pStmt, paramIdx(pStmt, zParamName), iValue);
          312  +  return sqlite4_bind_int64(pStmt->pStmt, paramIdx(pStmt, zParamName), iValue);
   313    313   }
   314    314   int db_bind_double(Stmt *pStmt, const char *zParamName, double rValue){
   315         -  return sqlite3_bind_double(pStmt->pStmt, paramIdx(pStmt, zParamName), rValue);
          315  +  return sqlite4_bind_double(pStmt->pStmt, paramIdx(pStmt, zParamName), rValue);
   316    316   }
   317    317   int db_bind_text(Stmt *pStmt, const char *zParamName, const char *zValue){
   318         -  return sqlite3_bind_text(pStmt->pStmt, paramIdx(pStmt, zParamName), zValue,
   319         -                           -1, SQLITE_STATIC);
          318  +  return sqlite4_bind_text(pStmt->pStmt, paramIdx(pStmt, zParamName), zValue,
          319  +                           -1, SQLITE4_STATIC);
   320    320   }
   321    321   int db_bind_null(Stmt *pStmt, const char *zParamName){
   322         -  return sqlite3_bind_null(pStmt->pStmt, paramIdx(pStmt, zParamName));
          322  +  return sqlite4_bind_null(pStmt->pStmt, paramIdx(pStmt, zParamName));
   323    323   }
   324    324   int db_bind_blob(Stmt *pStmt, const char *zParamName, Blob *pBlob){
   325         -  return sqlite3_bind_blob(pStmt->pStmt, paramIdx(pStmt, zParamName),
   326         -                          blob_buffer(pBlob), blob_size(pBlob), SQLITE_STATIC);
          325  +  return sqlite4_bind_blob(pStmt->pStmt, paramIdx(pStmt, zParamName),
          326  +                          blob_buffer(pBlob), blob_size(pBlob), SQLITE4_STATIC);
   327    327   }
   328    328   
   329    329   /* bind_str() treats a Blob object like a TEXT string and binds it
   330    330   ** to the SQL variable.  Constrast this to bind_blob() which treats
   331    331   ** the Blob object like an SQL BLOB.
   332    332   */
   333    333   int db_bind_str(Stmt *pStmt, const char *zParamName, Blob *pBlob){
   334         -  return sqlite3_bind_text(pStmt->pStmt, paramIdx(pStmt, zParamName),
   335         -                          blob_buffer(pBlob), blob_size(pBlob), SQLITE_STATIC);
          334  +  return sqlite4_bind_text(pStmt->pStmt, paramIdx(pStmt, zParamName),
          335  +                          blob_buffer(pBlob), blob_size(pBlob), SQLITE4_STATIC);
   336    336   }
   337    337   
   338    338   /*
   339         -** Step the SQL statement.  Return either SQLITE_ROW or an error code
   340         -** or SQLITE_OK if the statement finishes successfully.
          339  +** Step the SQL statement.  Return either SQLITE4_ROW or an error code
          340  +** or SQLITE4_OK if the statement finishes successfully.
   341    341   */
   342    342   int db_step(Stmt *pStmt){
   343    343     int rc;
   344         -  rc = sqlite3_step(pStmt->pStmt);
          344  +  rc = sqlite4_step(pStmt->pStmt);
   345    345     pStmt->nStep++;
   346    346     return rc;
   347    347   }
   348    348   
   349    349   /*
   350    350   ** Print warnings if a query is inefficient.
   351    351   */
   352    352   static void db_stats(Stmt *pStmt){
   353    353   #ifdef FOSSIL_DEBUG
   354    354     int c1, c2, c3;
   355         -  const char *zSql = sqlite3_sql(pStmt->pStmt);
          355  +  const char *zSql = sqlite4_sql(pStmt->pStmt);
   356    356     if( zSql==0 ) return;
   357         -  c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
   358         -  c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, 1);
   359         -  c3 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
          357  +  c1 = sqlite4_stmt_status(pStmt->pStmt, SQLITE4_STMTSTATUS_FULLSCAN_STEP, 1);
          358  +  c2 = sqlite4_stmt_status(pStmt->pStmt, SQLITE4_STMTSTATUS_AUTOINDEX, 1);
          359  +  c3 = sqlite4_stmt_status(pStmt->pStmt, SQLITE4_STMTSTATUS_SORT, 1);
   360    360     if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
   361    361       fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
   362    362     }else if( c2 ){
   363    363       fossil_warning("%d automatic index rows in [%s]", c2, zSql);
   364    364     }else if( c3 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
   365    365       fossil_warning("sort w/o index in [%s]", zSql);
   366    366     }
................................................................................
   370    370   
   371    371   /*
   372    372   ** Reset or finalize a statement.
   373    373   */
   374    374   int db_reset(Stmt *pStmt){
   375    375     int rc;
   376    376     db_stats(pStmt);
   377         -  rc = sqlite3_reset(pStmt->pStmt);
          377  +  rc = sqlite4_reset(pStmt->pStmt);
   378    378     db_check_result(rc);
   379    379     return rc;
   380    380   }
   381    381   int db_finalize(Stmt *pStmt){
   382    382     int rc;
   383    383     db_stats(pStmt);
   384    384     blob_reset(&pStmt->sql);
   385         -  rc = sqlite3_finalize(pStmt->pStmt);
          385  +  rc = sqlite4_finalize(pStmt->pStmt);
   386    386     db_check_result(rc);
   387    387     pStmt->pStmt = 0;
   388    388     if( pStmt->pNext ){
   389    389       pStmt->pNext->pPrev = pStmt->pPrev;
   390    390     }
   391    391     if( pStmt->pPrev ){
   392    392       pStmt->pPrev->pNext = pStmt->pNext;
................................................................................
   398    398     return rc;
   399    399   }
   400    400   
   401    401   /*
   402    402   ** Return the rowid of the most recent insert
   403    403   */
   404    404   i64 db_last_insert_rowid(void){
   405         -  return sqlite3_last_insert_rowid(g.db);
          405  +  return sqlite4_last_insert_rowid(g.db);
   406    406   }
   407    407   
   408    408   /*
   409    409   ** Return the number of rows that were changed by the most recent
   410    410   ** INSERT, UPDATE, or DELETE.  Auxiliary changes caused by triggers
   411    411   ** or other side effects are not counted.
   412    412   */
   413    413   int db_changes(void){
   414         -  return sqlite3_changes(g.db);
          414  +  return sqlite4_changes(g.db);
   415    415   }
   416    416   
   417    417   /*
   418    418   ** Extract text, integer, or blob values from the N-th column of the
   419    419   ** current row.
   420    420   */
   421    421   int db_column_bytes(Stmt *pStmt, int N){
   422         -  return sqlite3_column_bytes(pStmt->pStmt, N);
          422  +  return sqlite4_column_bytes(pStmt->pStmt, N);
   423    423   }
   424    424   int db_column_int(Stmt *pStmt, int N){
   425         -  return sqlite3_column_int(pStmt->pStmt, N);
          425  +  return sqlite4_column_int(pStmt->pStmt, N);
   426    426   }
   427    427   i64 db_column_int64(Stmt *pStmt, int N){
   428         -  return sqlite3_column_int64(pStmt->pStmt, N);
          428  +  return sqlite4_column_int64(pStmt->pStmt, N);
   429    429   }
   430    430   double db_column_double(Stmt *pStmt, int N){
   431         -  return sqlite3_column_double(pStmt->pStmt, N);
          431  +  return sqlite4_column_double(pStmt->pStmt, N);
   432    432   }
   433    433   const char *db_column_text(Stmt *pStmt, int N){
   434         -  return (char*)sqlite3_column_text(pStmt->pStmt, N);
          434  +  return (char*)sqlite4_column_text(pStmt->pStmt, N);
   435    435   }
   436    436   const char *db_column_raw(Stmt *pStmt, int N){
   437         -  return (const char*)sqlite3_column_blob(pStmt->pStmt, N);
          437  +  return (const char*)sqlite4_column_blob(pStmt->pStmt, N);
   438    438   }
   439    439   const char *db_column_name(Stmt *pStmt, int N){
   440         -  return (char*)sqlite3_column_name(pStmt->pStmt, N);
          440  +  return (char*)sqlite4_column_name(pStmt->pStmt, N);
   441    441   }
   442    442   int db_column_count(Stmt *pStmt){
   443         -  return sqlite3_column_count(pStmt->pStmt);
          443  +  return sqlite4_column_count(pStmt->pStmt);
   444    444   }
   445    445   char *db_column_malloc(Stmt *pStmt, int N){
   446    446     return mprintf("%s", db_column_text(pStmt, N));
   447    447   }
   448    448   void db_column_blob(Stmt *pStmt, int N, Blob *pBlob){
   449         -  blob_append(pBlob, sqlite3_column_blob(pStmt->pStmt, N),
   450         -              sqlite3_column_bytes(pStmt->pStmt, N));
          449  +  blob_append(pBlob, sqlite4_column_blob(pStmt->pStmt, N),
          450  +              sqlite4_column_bytes(pStmt->pStmt, N));
   451    451   }
   452    452   
   453    453   /*
   454    454   ** Initialize a blob to an ephermeral copy of the content of a
   455    455   ** column in the current row.  The data in the blob will become
   456    456   ** invalid when the statement is stepped or reset.
   457    457   */
   458    458   void db_ephemeral_blob(Stmt *pStmt, int N, Blob *pBlob){
   459         -  blob_init(pBlob, sqlite3_column_blob(pStmt->pStmt, N),
   460         -              sqlite3_column_bytes(pStmt->pStmt, N));
          459  +  blob_init(pBlob, sqlite4_column_blob(pStmt->pStmt, N),
          460  +              sqlite4_column_bytes(pStmt->pStmt, N));
   461    461   }
   462    462   
   463    463   /*
   464         -** Check a result code.  If it is not SQLITE_OK, print the
          464  +** Check a result code.  If it is not SQLITE4_OK, print the
   465    465   ** corresponding error message and exit.
   466    466   */
   467    467   void db_check_result(int rc){
   468         -  if( rc!=SQLITE_OK ){
   469         -    db_err("SQL error: %s", sqlite3_errmsg(g.db));
          468  +  if( rc!=SQLITE4_OK ){
          469  +    db_err("SQL error: %s", sqlite4_errmsg(g.db));
   470    470     }
   471    471   }
   472    472   
   473    473   /*
   474    474   ** Execute a single prepared statement until it finishes.
   475    475   */
   476    476   int db_exec(Stmt *pStmt){
   477    477     int rc;
   478         -  while( (rc = db_step(pStmt))==SQLITE_ROW ){}
          478  +  while( (rc = db_step(pStmt))==SQLITE4_ROW ){}
   479    479     rc = db_reset(pStmt);
   480    480     db_check_result(rc);
   481    481     return rc;
   482    482   }
   483    483   
   484    484   /*
   485    485   ** Execute multiple SQL statements.
................................................................................
   489    489     int rc;
   490    490     va_list ap;
   491    491     char *zErr = 0;
   492    492     blob_init(&sql, 0, 0);
   493    493     va_start(ap, zSql);
   494    494     blob_vappendf(&sql, zSql, ap);
   495    495     va_end(ap);
   496         -  rc = sqlite3_exec(g.db, blob_buffer(&sql), 0, 0, &zErr);
   497         -  if( rc!=SQLITE_OK ){
          496  +  rc = sqlite4_exec(g.db, blob_buffer(&sql), 0, 0, &zErr);
          497  +  if( rc!=SQLITE4_OK ){
   498    498       db_err("%s\n%s", zErr, blob_buffer(&sql));
   499    499     }
   500    500     blob_reset(&sql);
   501    501     return rc;
   502    502   }
   503    503   
   504    504   /*
................................................................................
   506    506   ** convenient.  Do not start a transaction for these changes, but only
   507    507   ** make these changes if other changes are also being made.
   508    508   */
   509    509   void db_optional_sql(const char *zDb, const char *zSql, ...){
   510    510     if( db_is_writeable(zDb) && db.nBeforeCommit < count(db.azBeforeCommit) ){
   511    511       va_list ap;
   512    512       va_start(ap, zSql);
   513         -    db.azBeforeCommit[db.nBeforeCommit++] = sqlite3_vmprintf(zSql, ap);
          513  +    db.azBeforeCommit[db.nBeforeCommit++] = sqlite4_vmprintf(0, zSql, ap);
   514    514       va_end(ap);
   515    515     }
   516    516   }
   517    517   
   518    518   /*
   519    519   ** Execute a query and return a single integer value.
   520    520   */
................................................................................
   521    521   i64 db_int64(i64 iDflt, const char *zSql, ...){
   522    522     va_list ap;
   523    523     Stmt s;
   524    524     i64 rc;
   525    525     va_start(ap, zSql);
   526    526     db_vprepare(&s, 0, zSql, ap);
   527    527     va_end(ap);
   528         -  if( db_step(&s)!=SQLITE_ROW ){
          528  +  if( db_step(&s)!=SQLITE4_ROW ){
   529    529       rc = iDflt;
   530    530     }else{
   531    531       rc = db_column_int64(&s, 0);
   532    532     }
   533    533     db_finalize(&s);
   534    534     return rc;
   535    535   }
................................................................................
   536    536   int db_int(int iDflt, const char *zSql, ...){
   537    537     va_list ap;
   538    538     Stmt s;
   539    539     int rc;
   540    540     va_start(ap, zSql);
   541    541     db_vprepare(&s, 0, zSql, ap);
   542    542     va_end(ap);
   543         -  if( db_step(&s)!=SQLITE_ROW ){
          543  +  if( db_step(&s)!=SQLITE4_ROW ){
   544    544       rc = iDflt;
   545    545     }else{
   546    546       rc = db_column_int(&s, 0);
   547    547     }
   548    548     db_finalize(&s);
   549    549     return rc;
   550    550   }
................................................................................
   556    556   int db_exists(const char *zSql, ...){
   557    557     va_list ap;
   558    558     Stmt s;
   559    559     int rc;
   560    560     va_start(ap, zSql);
   561    561     db_vprepare(&s, 0, zSql, ap);
   562    562     va_end(ap);
   563         -  if( db_step(&s)!=SQLITE_ROW ){
          563  +  if( db_step(&s)!=SQLITE4_ROW ){
   564    564       rc = 0;
   565    565     }else{
   566    566       rc = 1;
   567    567     }
   568    568     db_finalize(&s);
   569    569     return rc;
   570    570   }
................................................................................
   576    576   double db_double(double rDflt, const char *zSql, ...){
   577    577     va_list ap;
   578    578     Stmt s;
   579    579     double r;
   580    580     va_start(ap, zSql);
   581    581     db_vprepare(&s, 0, zSql, ap);
   582    582     va_end(ap);
   583         -  if( db_step(&s)!=SQLITE_ROW ){
          583  +  if( db_step(&s)!=SQLITE4_ROW ){
   584    584       r = rDflt;
   585    585     }else{
   586    586       r = db_column_double(&s, 0);
   587    587     }
   588    588     db_finalize(&s);
   589    589     return r;
   590    590   }
................................................................................
   595    595   */
   596    596   void db_blob(Blob *pResult, const char *zSql, ...){
   597    597     va_list ap;
   598    598     Stmt s;
   599    599     va_start(ap, zSql);
   600    600     db_vprepare(&s, 0, zSql, ap);
   601    601     va_end(ap);
   602         -  if( db_step(&s)==SQLITE_ROW ){
   603         -    blob_append(pResult, sqlite3_column_blob(s.pStmt, 0),
   604         -                         sqlite3_column_bytes(s.pStmt, 0));
          602  +  if( db_step(&s)==SQLITE4_ROW ){
          603  +    blob_append(pResult, sqlite4_column_blob(s.pStmt, 0),
          604  +                         sqlite4_column_bytes(s.pStmt, 0));
   605    605     }
   606    606     db_finalize(&s);
   607    607   }
   608    608   
   609    609   /*
   610    610   ** Execute a query.  Return the first column of the first row
   611    611   ** of the result set as a string.  Space to hold the string is
................................................................................
   615    615   char *db_text(char const *zDefault, const char *zSql, ...){
   616    616     va_list ap;
   617    617     Stmt s;
   618    618     char *z;
   619    619     va_start(ap, zSql);
   620    620     db_vprepare(&s, 0, zSql, ap);
   621    621     va_end(ap);
   622         -  if( db_step(&s)==SQLITE_ROW ){
   623         -    z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
          622  +  if( db_step(&s)==SQLITE4_ROW ){
          623  +    z = mprintf("%s", sqlite4_column_text(s.pStmt, 0));
   624    624     }else if( zDefault ){
   625    625       z = mprintf("%s", zDefault);
   626    626     }else{
   627    627       z = 0;
   628    628     }
   629    629     db_finalize(&s);
   630    630     return z;
................................................................................
   635    635   ** goes wrong, call db_err() to exit.
   636    636   */
   637    637   void db_init_database(
   638    638     const char *zFileName,   /* Name of database file to create */
   639    639     const char *zSchema,     /* First part of schema */
   640    640     ...                      /* Additional SQL to run.  Terminate with NULL. */
   641    641   ){
   642         -  sqlite3 *db;
          642  +  sqlite4 *db;
   643    643     int rc;
   644    644     const char *zSql;
   645    645     va_list ap;
   646    646   
   647         -  rc = sqlite3_open(zFileName, &db);
   648         -  if( rc!=SQLITE_OK ){
   649         -    db_err(sqlite3_errmsg(db));
          647  +  rc = sqlite4_open(0, zFileName, &db,
          648  +                    SQLITE4_OPEN_READWRITE|SQLITE4_OPEN_CREATE);
          649  +  if( rc!=SQLITE4_OK ){
          650  +    db_err(sqlite4_errmsg(db));
   650    651     }
   651         -  sqlite3_busy_timeout(db, 5000);
   652         -  sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
   653         -  rc = sqlite3_exec(db, zSchema, 0, 0, 0);
   654         -  if( rc!=SQLITE_OK ){
   655         -    db_err(sqlite3_errmsg(db));
          652  +  sqlite4_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
          653  +  rc = sqlite4_exec(db, zSchema, 0, 0, 0);
          654  +  if( rc!=SQLITE4_OK ){
          655  +    db_err(sqlite4_errmsg(db));
   656    656     }
   657    657     va_start(ap, zSchema);
   658    658     while( (zSql = va_arg(ap, const char*))!=0 ){
   659         -    rc = sqlite3_exec(db, zSql, 0, 0, 0);
   660         -    if( rc!=SQLITE_OK ){
   661         -      db_err(sqlite3_errmsg(db));
          659  +    rc = sqlite4_exec(db, zSql, 0, 0, 0);
          660  +    if( rc!=SQLITE4_OK ){
          661  +      db_err(sqlite4_errmsg(db));
   662    662       }
   663    663     }
   664    664     va_end(ap);
   665         -  sqlite3_exec(db, "COMMIT", 0, 0, 0);
   666         -  sqlite3_close(db);
          665  +  sqlite4_exec(db, "COMMIT", 0, 0, 0);
          666  +  sqlite4_close(db);
   667    667   }
   668    668   
   669    669   /*
   670    670   ** Function to return the number of seconds since 1970.  This is
   671    671   ** the same as strftime('%s','now') but is more compact.
   672    672   */
   673    673   void db_now_function(
   674         -  sqlite3_context *context,
          674  +  sqlite4_context *context,
   675    675     int argc,
   676         -  sqlite3_value **argv
          676  +  sqlite4_value **argv
   677    677   ){
   678         -  sqlite3_result_int64(context, time(0));
          678  +  sqlite4_result_int64(context, time(0));
   679    679   }
   680    680   
   681    681   
   682    682   /*
   683    683   ** Open a database file.  Return a pointer to the new database
   684    684   ** connection.  An error results in process abort.
   685    685   */
   686         -static sqlite3 *openDatabase(const char *zDbName){
          686  +static sqlite4 *openDatabase(const char *zDbName){
   687    687     int rc;
   688    688     const char *zVfs;
   689         -  sqlite3 *db;
          689  +  sqlite4 *db;
   690    690   
   691    691     zVfs = fossil_getenv("FOSSIL_VFS");
   692         -  rc = sqlite3_open_v2(
          692  +  rc = sqlite4_open(0,
   693    693          zDbName, &db,
   694         -       SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
   695         -       zVfs
          694  +       SQLITE4_OPEN_READWRITE | SQLITE4_OPEN_CREATE
   696    695     );
   697         -  if( rc!=SQLITE_OK ){
   698         -    db_err(sqlite3_errmsg(db));
          696  +  if( rc!=SQLITE4_OK ){
          697  +    db_err(sqlite4_errmsg(db));
   699    698     }
   700         -  sqlite3_busy_timeout(db, 5000); 
   701         -  sqlite3_wal_autocheckpoint(db, 1);  /* Set to checkpoint frequently */
   702         -  sqlite3_create_function(db, "now", 0, SQLITE_ANY, 0, db_now_function, 0, 0);
          699  +  sqlite4_create_function(db, "now", 0, SQLITE4_ANY, 0, db_now_function, 0, 0);
   703    700     return db;
   704    701   }
   705    702   
   706    703   
   707    704   /*
   708    705   ** zDbName is the name of a database file.  If no other database
   709    706   ** file is open, then open this one.  If another database file is
................................................................................
   764    761     if( access(zHome, W_OK) ){
   765    762       fossil_fatal("home directory %s must be writeable", zHome);
   766    763     }
   767    764   #endif
   768    765     g.zHome = mprintf("%/", zHome);
   769    766   #if defined(_WIN32)
   770    767     /* . filenames give some window systems problems and many apps problems */
   771         -  zDbName = mprintf("%//_fossil", zHome);
          768  +  zDbName = mprintf("%//_fossil4", zHome);
   772    769   #else
   773         -  zDbName = mprintf("%s/.fossil", zHome);
          770  +  zDbName = mprintf("%s/.fossil4", zHome);
   774    771   #endif
   775    772     if( file_size(zDbName)<1024*3 ){
   776    773       db_init_database(zDbName, zConfigSchema, (char*)0);
   777    774     }
   778    775     g.useAttach = useAttach;
   779    776     if( useAttach ){
   780    777       db_open_or_attach(zDbName, "configdb");
................................................................................
   875    872     if( g.localOpen) return 1;
   876    873     file_getcwd(zPwd, sizeof(zPwd)-20);
   877    874     n = strlen(zPwd);
   878    875     if( n==1 && zPwd[0]=='/' ) zPwd[0] = '.';
   879    876     while( n>0 ){
   880    877       if( file_access(zPwd, W_OK) ) break;
   881    878       for(i=0; i<sizeof(aDbName)/sizeof(aDbName[0]); i++){
   882         -      sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "%s", aDbName[i]);
          879  +      sqlite4_snprintf(zPwd+n, sizeof(zPwd)-n, "%s", aDbName[i]);
   883    880         if( isValidLocalDb(zPwd) ){
   884    881           /* Found a valid checkout database file */
   885    882           zPwd[n] = 0;
   886    883           while( n>1 && zPwd[n-1]=='/' ){
   887    884             n--;
   888    885             zPwd[n] = 0;
   889    886           }
................................................................................
  1025   1022                      "   AND value<>'%s'", AUX_SCHEMA);
  1026   1023   }
  1027   1024   
  1028   1025   /*
  1029   1026   ** Return true if the database is writeable
  1030   1027   */
  1031   1028   int db_is_writeable(const char *zName){
  1032         -  return !sqlite3_db_readonly(g.db, db_name(zName));
         1029  +  return 1; /* !sqlite4_db_readonly(g.db, db_name(zName)); */
  1033   1030   }
  1034   1031   
  1035   1032   /*
  1036   1033   ** Verify that the repository schema is correct.  If it is not correct,
  1037   1034   ** issue a fatal error and die.
  1038   1035   */
  1039   1036   void db_verify_schema(void){
................................................................................
  1094   1091   /*
  1095   1092   ** Close the database connection.
  1096   1093   **
  1097   1094   ** Check for unfinalized statements and report errors if the reportErrors
  1098   1095   ** argument is true.  Ignore unfinalized statements when false.
  1099   1096   */
  1100   1097   void db_close(int reportErrors){
  1101         -  sqlite3_stmt *pStmt;
         1098  +  sqlite4_stmt *pStmt;
  1102   1099     if( g.db==0 ) return;
  1103   1100     if( g.fSqlStats ){
  1104   1101       int cur, hiwtr;
  1105         -    sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_USED, &cur, &hiwtr, 0);
         1102  +    sqlite4_db_status(g.db, SQLITE4_DBSTATUS_LOOKASIDE_USED, &cur, &hiwtr, 0);
  1106   1103       fprintf(stderr, "-- LOOKASIDE_USED         %10d %10d\n", cur, hiwtr);
  1107         -    sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &cur, &hiwtr, 0);
         1104  +    sqlite4_db_status(g.db, SQLITE4_DBSTATUS_LOOKASIDE_HIT, &cur, &hiwtr, 0);
  1108   1105       fprintf(stderr, "-- LOOKASIDE_HIT                     %10d\n", hiwtr);
  1109         -    sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &cur,&hiwtr,0);
         1106  +    sqlite4_db_status(g.db, SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE, &cur,&hiwtr,0);
  1110   1107       fprintf(stderr, "-- LOOKASIDE_MISS_SIZE               %10d\n", hiwtr);
  1111         -    sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &cur,&hiwtr,0);
         1108  +    sqlite4_db_status(g.db, SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL, &cur,&hiwtr,0);
  1112   1109       fprintf(stderr, "-- LOOKASIDE_MISS_FULL               %10d\n", hiwtr);
  1113         -    sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_USED, &cur, &hiwtr, 0);
         1110  +    sqlite4_db_status(g.db, SQLITE4_DBSTATUS_CACHE_USED, &cur, &hiwtr, 0);
  1114   1111       fprintf(stderr, "-- CACHE_USED             %10d\n", cur);
  1115         -    sqlite3_db_status(g.db, SQLITE_DBSTATUS_SCHEMA_USED, &cur, &hiwtr, 0);
         1112  +    sqlite4_db_status(g.db, SQLITE4_DBSTATUS_SCHEMA_USED, &cur, &hiwtr, 0);
  1116   1113       fprintf(stderr, "-- SCHEMA_USED            %10d\n", cur);
  1117         -    sqlite3_db_status(g.db, SQLITE_DBSTATUS_STMT_USED, &cur, &hiwtr, 0);
         1114  +    sqlite4_db_status(g.db, SQLITE4_DBSTATUS_STMT_USED, &cur, &hiwtr, 0);
  1118   1115       fprintf(stderr, "-- STMT_USED              %10d\n", cur);
  1119         -    sqlite3_status(SQLITE_STATUS_MEMORY_USED, &cur, &hiwtr, 0);
         1116  +    sqlite4_env_status(0, SQLITE4_ENVSTATUS_MEMORY_USED, &cur, &hiwtr, 0);
  1120   1117       fprintf(stderr, "-- MEMORY_USED            %10d %10d\n", cur, hiwtr);
  1121         -    sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &cur, &hiwtr, 0);
         1118  +    sqlite4_env_status(0, SQLITE4_ENVSTATUS_MALLOC_SIZE, &cur, &hiwtr, 0);
  1122   1119       fprintf(stderr, "-- MALLOC_SIZE                       %10d\n", hiwtr);
  1123         -    sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &cur, &hiwtr, 0);
         1120  +    sqlite4_env_status(0, SQLITE4_ENVSTATUS_MALLOC_COUNT, &cur, &hiwtr, 0);
  1124   1121       fprintf(stderr, "-- MALLOC_COUNT           %10d %10d\n", cur, hiwtr);
  1125         -    sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &cur, &hiwtr, 0);
  1126         -    fprintf(stderr, "-- PCACHE_OVFLOW          %10d %10d\n", cur, hiwtr);
  1127   1122       fprintf(stderr, "-- prepared statements    %10d\n", db.nPrepare);
  1128   1123     }
  1129   1124     while( db.pAllStmt ){
  1130   1125       db_finalize(db.pAllStmt);
  1131   1126     }
  1132   1127     db_end_transaction(1);
  1133   1128     pStmt = 0;
  1134   1129     if( reportErrors ){
  1135         -    while( (pStmt = sqlite3_next_stmt(g.db, pStmt))!=0 ){
  1136         -      fossil_warning("unfinalized SQL statement: [%s]", sqlite3_sql(pStmt));
         1130  +    while( (pStmt = sqlite4_next_stmt(g.db, pStmt))!=0 ){
         1131  +      fossil_warning("unfinalized SQL statement: [%s]", sqlite4_sql(pStmt));
  1137   1132       }
  1138   1133     }
  1139   1134     g.repositoryOpen = 0;
  1140   1135     g.localOpen = 0;
  1141   1136     g.configOpen = 0;
  1142         -  sqlite3_wal_checkpoint(g.db, 0);
  1143         -  sqlite3_close(g.db);
         1137  +  sqlite4_close(g.db);
  1144   1138     g.db = 0;
  1145   1139     if( g.dbConfig ){
  1146         -    sqlite3_close(g.dbConfig);
         1140  +    sqlite4_close(g.dbConfig);
  1147   1141       g.dbConfig = 0;
  1148   1142     }
  1149   1143   }
  1150   1144   
  1151   1145   
  1152   1146   /*
  1153   1147   ** Create a new empty repository database with the given name.
................................................................................
  1308   1302   /*
  1309   1303   ** SQL functions for debugging.
  1310   1304   **
  1311   1305   ** The print() function writes its arguments on stdout, but only
  1312   1306   ** if the -sqlprint command-line option is turned on.
  1313   1307   */
  1314   1308   static void db_sql_print(
  1315         -  sqlite3_context *context,
         1309  +  sqlite4_context *context,
  1316   1310     int argc,
  1317         -  sqlite3_value **argv
         1311  +  sqlite4_value **argv
  1318   1312   ){
  1319   1313     int i;
  1320   1314     if( g.fSqlPrint ){
  1321   1315       for(i=0; i<argc; i++){
  1322   1316         char c = i==argc-1 ? '\n' : ' ';
  1323         -      fossil_print("%s%c", sqlite3_value_text(argv[i]), c);
         1317  +      fossil_print("%s%c", sqlite4_value_text(argv[i]), c);
  1324   1318       }
  1325   1319     }
  1326   1320   }
  1327   1321   static void db_sql_trace(void *notUsed, const char *zSql){
  1328   1322     int n = strlen(zSql);
  1329   1323     char *zMsg = mprintf("%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";");
  1330   1324     fossil_puts(zMsg, 1);
................................................................................
  1332   1326   }
  1333   1327   
  1334   1328   /*
  1335   1329   ** Implement the user() SQL function.  user() takes no arguments and
  1336   1330   ** returns the user ID of the current user.
  1337   1331   */
  1338   1332   static void db_sql_user(
  1339         -  sqlite3_context *context,
         1333  +  sqlite4_context *context,
  1340   1334     int argc,
  1341         -  sqlite3_value **argv
         1335  +  sqlite4_value **argv
  1342   1336   ){
  1343   1337     if( g.zLogin!=0 ){
  1344         -    sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC);
         1338  +    sqlite4_result_text(context, g.zLogin, -1, SQLITE4_STATIC);
  1345   1339     }
  1346   1340   }
  1347   1341   
  1348   1342   /*
  1349   1343   ** Implement the cgi() SQL function.  cgi() takes a an argument which is
  1350   1344   ** a name of CGI query parameter. The value of that parameter is returned, 
  1351   1345   ** if available. optional second argument will be returned if the first
  1352   1346   ** doesn't exist as a CGI parameter.
  1353   1347   */
  1354         -static void db_sql_cgi(sqlite3_context *context, int argc, sqlite3_value **argv){
         1348  +static void db_sql_cgi(sqlite4_context *context, int argc, sqlite4_value **argv){
  1355   1349     const char* zP;
  1356   1350     if( argc!=1 && argc!=2 ) return;
  1357         -  zP = P((const char*)sqlite3_value_text(argv[0]));
         1351  +  zP = P((const char*)sqlite4_value_text(argv[0]));
  1358   1352     if( zP ){
  1359         -    sqlite3_result_text(context, zP, -1, SQLITE_STATIC);
         1353  +    sqlite4_result_text(context, zP, -1, SQLITE4_STATIC);
  1360   1354     }else if( argc==2 ){
  1361         -    zP = (const char*)sqlite3_value_text(argv[1]);
  1362         -    if( zP ) sqlite3_result_text(context, zP, -1, SQLITE_TRANSIENT);
         1355  +    zP = (const char*)sqlite4_value_text(argv[1]);
         1356  +    if( zP ) sqlite4_result_text(context, zP, -1, SQLITE4_TRANSIENT);
  1363   1357     }
  1364   1358   }
  1365   1359   
  1366   1360   /*
  1367   1361   ** SQL function:
  1368   1362   **
  1369   1363   **       is_selected(id)
................................................................................
  1379   1373   ** changes are to be committed) or if id is found in g.aCommitFile[]
  1380   1374   ** (meaning that id was named on the command-line).
  1381   1375   **
  1382   1376   ** In the second form (3 arguments) return argument X if true and Y
  1383   1377   ** if false.
  1384   1378   */
  1385   1379   static void file_is_selected(
  1386         -  sqlite3_context *context,
         1380  +  sqlite4_context *context,
  1387   1381     int argc,
  1388         -  sqlite3_value **argv
         1382  +  sqlite4_value **argv
  1389   1383   ){
  1390   1384     int rc = 0;
  1391   1385   
  1392   1386     assert(argc==1 || argc==3);
  1393   1387     if( g.aCommitFile ){
  1394         -    int iId = sqlite3_value_int(argv[0]);
         1388  +    int iId = sqlite4_value_int(argv[0]);
  1395   1389       int ii;
  1396   1390       for(ii=0; g.aCommitFile[ii]; ii++){
  1397   1391         if( iId==g.aCommitFile[ii] ){
  1398   1392           rc = 1;
  1399   1393           break;
  1400   1394         }
  1401   1395       }
  1402   1396     }else{
  1403   1397       rc = 1;
  1404   1398     }
  1405   1399     if( argc==1 ){
  1406         -    sqlite3_result_int(context, rc);
         1400  +    sqlite4_result_int(context, rc);
  1407   1401     }else{
  1408   1402       assert( argc==3 );
  1409   1403       assert( rc==0 || rc==1 );
  1410         -    sqlite3_result_value(context, argv[2-rc]);
         1404  +    sqlite4_result_value(context, argv[2-rc]);
  1411   1405     }
  1412   1406   }
  1413   1407   
  1414   1408   /*
  1415   1409   ** Convert the input string into an SHA1.  Make a notation in the
  1416   1410   ** CONCEALED table so that the hash can be undo using the db_reveal()
  1417   1411   ** function at some later time.
................................................................................
  1432   1426     Blob out;
  1433   1427     if( n==40 && validate16(zContent, n) ){
  1434   1428       memcpy(zHash, zContent, n);
  1435   1429       zHash[n] = 0;
  1436   1430     }else{
  1437   1431       sha1sum_step_text(zContent, n);
  1438   1432       sha1sum_finish(&out);
  1439         -    sqlite3_snprintf(sizeof(zHash), zHash, "%s", blob_str(&out));
         1433  +    sqlite4_snprintf(zHash, sizeof(zHash), "%s", blob_str(&out));
  1440   1434       blob_reset(&out);
  1441   1435       db_multi_exec(
  1442   1436          "INSERT OR IGNORE INTO concealed(hash,content,mtime)"
  1443   1437          " VALUES(%Q,%#Q,now())",
  1444   1438          zHash, n, zContent
  1445   1439       );
  1446   1440     }
................................................................................
  1470   1464   }
  1471   1465   
  1472   1466   /*
  1473   1467   ** This function registers auxiliary functions when the SQLite
  1474   1468   ** database connection is first established.
  1475   1469   */
  1476   1470   LOCAL void db_connection_init(void){
  1477         -  sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
  1478         -  sqlite3_create_function(g.db, "user", 0, SQLITE_ANY, 0, db_sql_user, 0, 0);
  1479         -  sqlite3_create_function(g.db, "cgi", 1, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
  1480         -  sqlite3_create_function(g.db, "cgi", 2, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
  1481         -  sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
  1482         -  sqlite3_create_function(
  1483         -    g.db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
         1471  +  sqlite4_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
         1472  +  sqlite4_create_function(g.db, "user", 0, SQLITE4_ANY, 0, db_sql_user, 0, 0);
         1473  +  sqlite4_create_function(g.db, "cgi", 1, SQLITE4_ANY, 0, db_sql_cgi, 0, 0);
         1474  +  sqlite4_create_function(g.db, "cgi", 2, SQLITE4_ANY, 0, db_sql_cgi, 0, 0);
         1475  +  sqlite4_create_function(g.db, "print", -1, SQLITE4_UTF8, 0,db_sql_print,0,0);
         1476  +  sqlite4_create_function(
         1477  +    g.db, "is_selected", 1, SQLITE4_UTF8, 0, file_is_selected,0,0
  1484   1478     );
  1485         -  sqlite3_create_function(
  1486         -    g.db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
         1479  +  sqlite4_create_function(
         1480  +    g.db, "if_selected", 3, SQLITE4_UTF8, 0, file_is_selected,0,0
  1487   1481     );
  1488   1482     if( g.fSqlTrace ){
  1489         -    sqlite3_trace(g.db, db_sql_trace, 0);
         1483  +    sqlite4_trace(g.db, db_sql_trace, 0);
  1490   1484     }
  1491   1485   }
  1492   1486   
  1493   1487   /*
  1494   1488   ** Return true if the string zVal represents "true" (or "false").
  1495   1489   */
  1496   1490   int is_truth(const char *zVal){
................................................................................
  1517   1511   **
  1518   1512   ** If g.useAttach that means the ~/.fossil database was opened with
  1519   1513   ** the useAttach flag set to 1.  In that case no connection swap is required
  1520   1514   ** so this routine is a no-op.
  1521   1515   */
  1522   1516   void db_swap_connections(void){
  1523   1517     if( !g.useAttach ){
  1524         -    sqlite3 *dbTemp = g.db;
         1518  +    sqlite4 *dbTemp = g.db;
  1525   1519       g.db = g.dbConfig;
  1526   1520       g.dbConfig = dbTemp;
  1527   1521     }
  1528   1522   }
  1529   1523   
  1530   1524   /*
  1531   1525   ** Logic for reading potentially versioned settings from
................................................................................
  1678   1672   int db_get_int(const char *zName, int dflt){
  1679   1673     int v = dflt;
  1680   1674     int rc;
  1681   1675     if( g.repositoryOpen ){
  1682   1676       Stmt q;
  1683   1677       db_prepare(&q, "SELECT value FROM config WHERE name=%Q", zName);
  1684   1678       rc = db_step(&q);
  1685         -    if( rc==SQLITE_ROW ){
         1679  +    if( rc==SQLITE4_ROW ){
  1686   1680         v = db_column_int(&q, 0);
  1687   1681       }
  1688   1682       db_finalize(&q);
  1689   1683     }else{
  1690         -    rc = SQLITE_DONE;
         1684  +    rc = SQLITE4_DONE;
  1691   1685     }
  1692         -  if( rc==SQLITE_DONE && g.configOpen ){
         1686  +  if( rc==SQLITE4_DONE && g.configOpen ){
  1693   1687       db_swap_connections();
  1694   1688       v = db_int(dflt, "SELECT value FROM global_config WHERE name=%Q", zName);
  1695   1689       db_swap_connections();
  1696   1690     }
  1697   1691     return v;
  1698   1692   }
  1699   1693   void db_set_int(const char *zName, int value, int globalFlag){
................................................................................
  1864   1858       );
  1865   1859     }else{
  1866   1860       db_prepare(&q,
  1867   1861         "SELECT '(global)', value FROM global_config WHERE name=%Q",
  1868   1862         ctrlSetting->name
  1869   1863       );
  1870   1864     }
  1871         -  if( db_step(&q)==SQLITE_ROW ){
         1865  +  if( db_step(&q)==SQLITE4_ROW ){
  1872   1866       fossil_print("%-20s %-8s %s\n", ctrlSetting->name, db_column_text(&q, 0),
  1873   1867           db_column_text(&q, 1));
  1874   1868     }else{
  1875   1869       fossil_print("%-20s\n", ctrlSetting->name);
  1876   1870     }
  1877   1871     if( ctrlSetting->versionable && localOpen ){
  1878   1872       /* Check to see if this is overridden by a versionable settings file */
................................................................................
  2172   2166   ** describes that timespan in units of seconds, minutes, hours, days,
  2173   2167   ** or years, depending on its duration.
  2174   2168   */
  2175   2169   char *db_timespan_name(double rSpan){
  2176   2170     if( rSpan<0 ) rSpan = -rSpan;
  2177   2171     rSpan *= 24.0*3600.0;  /* Convert units to seconds */
  2178   2172     if( rSpan<120.0 ){
  2179         -    return sqlite3_mprintf("%.1f seconds", rSpan);
         2173  +    return sqlite4_mprintf(0, "%.1f seconds", rSpan);
  2180   2174     }
  2181   2175     rSpan /= 60.0;         /* Convert units to minutes */
  2182   2176     if( rSpan<90.0 ){
  2183         -    return sqlite3_mprintf("%.1f minutes", rSpan);
         2177  +    return sqlite4_mprintf(0, "%.1f minutes", rSpan);
  2184   2178     }
  2185   2179     rSpan /= 60.0;         /* Convert units to hours */
  2186   2180     if( rSpan<=48.0 ){
  2187         -    return sqlite3_mprintf("%.1f hours", rSpan);
         2181  +    return sqlite4_mprintf(0, "%.1f hours", rSpan);
  2188   2182     }
  2189   2183     rSpan /= 24.0;         /* Convert units to days */
  2190   2184     if( rSpan<=365.0 ){
  2191         -    return sqlite3_mprintf("%.1f days", rSpan);
         2185  +    return sqlite4_mprintf(0, "%.1f days", rSpan);
  2192   2186     }
  2193   2187     rSpan /= 356.24;         /* Convert units to years */
  2194         -  return sqlite3_mprintf("%.1f years", rSpan);
         2188  +  return sqlite4_mprintf(0, "%.1f years", rSpan);
  2195   2189   }
  2196   2190   
  2197   2191   /*
  2198   2192   ** COMMAND: test-timespan
  2199   2193   ** %fossil test-timespan TIMESTAMP
  2200   2194   **
  2201   2195   ** Print the approximate span of time from now to TIMESTAMP.
  2202   2196   */
  2203   2197   void test_timespan_cmd(void){
  2204   2198     double rDiff;
  2205   2199     if( g.argc!=3 ) usage("TIMESTAMP");
  2206         -  sqlite3_open(":memory:", &g.db);  
         2200  +  sqlite4_open(0, ":memory:", &g.db, SQLITE4_OPEN_READWRITE);  
  2207   2201     rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]);
  2208   2202     fossil_print("Time differences: %s\n", db_timespan_name(rDiff));
  2209         -  sqlite3_close(g.db);
         2203  +  sqlite4_close(g.db);
  2210   2204     g.db = 0;
  2211   2205   }

Changes to src/descendants.c.

   102    102       db_prepare(&ins, "INSERT OR IGNORE INTO leaves VALUES(:rid)");
   103    103     
   104    104       while( bag_count(&pending) ){
   105    105         int rid = bag_first(&pending);
   106    106         int cnt = 0;
   107    107         bag_remove(&pending, rid);
   108    108         db_bind_int(&q1, ":rid", rid);
   109         -      while( db_step(&q1)==SQLITE_ROW ){
          109  +      while( db_step(&q1)==SQLITE4_ROW ){
   110    110           int cid = db_column_int(&q1, 0);
   111    111           if( bag_insert(&seen, cid) ){
   112    112             bag_insert(&pending, cid);
   113    113           }
   114    114           db_bind_int(&isBr, ":rid", cid);
   115         -        if( db_step(&isBr)==SQLITE_DONE ){
          115  +        if( db_step(&isBr)==SQLITE4_DONE ){
   116    116             cnt++;
   117    117           }
   118    118           db_reset(&isBr);
   119    119         }
   120    120         db_reset(&q1);
   121    121         if( cnt==0 && !is_a_leaf(rid) ){
   122    122           cnt++;
................................................................................
   173    173       " WHERE a.cid=:rid"
   174    174     );
   175    175     while( (N--)>0 && (rid = pqueuex_extract(&queue, 0))!=0 ){
   176    176       db_bind_int(&ins, ":rid", rid);
   177    177       db_step(&ins);
   178    178       db_reset(&ins);
   179    179       db_bind_int(&q, ":rid", rid);
   180         -    while( db_step(&q)==SQLITE_ROW ){
          180  +    while( db_step(&q)==SQLITE4_ROW ){
   181    181         int pid = db_column_int(&q, 0);
   182    182         double mtime = db_column_double(&q, 1);
   183    183         if( bag_insert(&seen, pid) ){
   184    184           pqueuex_insert(&queue, pid, -mtime, 0);
   185    185         }
   186    186       }
   187    187       db_reset(&q);
................................................................................
   211    211     db_prepare(&ins, "INSERT INTO ancestor VALUES(:rid, :gen)");
   212    212     db_prepare(&q, 
   213    213       "SELECT pid FROM plink"
   214    214       " WHERE cid=:rid AND isprim"
   215    215     );
   216    216     while( (N--)>0 ){
   217    217       db_bind_int(&q, ":rid", rid);
   218         -    if( db_step(&q)!=SQLITE_ROW ) break;
          218  +    if( db_step(&q)!=SQLITE4_ROW ) break;
   219    219       rid = db_column_int(&q, 0);
   220    220       db_reset(&q);
   221    221       gen++;
   222    222       db_bind_int(&ins, ":rid", rid);
   223    223       db_bind_int(&ins, ":gen", gen);
   224    224       db_step(&ins);
   225    225       db_reset(&ins);
................................................................................
   245    245     db_prepare(&ins, "INSERT OR IGNORE INTO ok VALUES(:rid)");
   246    246     db_prepare(&q, "SELECT cid, mtime FROM plink WHERE pid=:rid");
   247    247     while( (N--)>0 && (rid = pqueuex_extract(&queue, 0))!=0 ){
   248    248       db_bind_int(&ins, ":rid", rid);
   249    249       db_step(&ins);
   250    250       db_reset(&ins);
   251    251       db_bind_int(&q, ":rid", rid);
   252         -    while( db_step(&q)==SQLITE_ROW ){
          252  +    while( db_step(&q)==SQLITE4_ROW ){
   253    253         int pid = db_column_int(&q, 0);
   254    254         double mtime = db_column_double(&q, 1);
   255    255         if( bag_insert(&seen, pid) ){
   256    256           pqueuex_insert(&queue, pid, mtime, 0);
   257    257         }
   258    258       }
   259    259       db_reset(&q);

Changes to src/diff.c.

   471    471   }
   472    472   
   473    473   /*
   474    474   ** Write a 6-digit line number followed by a single space onto the line.
   475    475   */
   476    476   static void sbsWriteLineno(SbsLine *p, int ln){
   477    477     sbsWriteHtml(p, "<span class=\"diffln\">");
   478         -  sqlite3_snprintf(7, &p->zLine[p->n], "%5d ", ln+1);
          478  +  sqlite4_snprintf(&p->zLine[p->n], 7, "%5d ", ln+1);
   479    479     p->n += 6;
   480    480     sbsWriteHtml(p, "</span>");
   481    481     p->zLine[p->n++] = ' ';
   482    482   }
   483    483   
   484    484   /*
   485    485   ** The two text segments zLeft and zRight are known to be different on 
................................................................................
  1773   1773       "   AND event.objid=ancestor.rid"
  1774   1774       " ORDER BY ancestor.generation ASC"
  1775   1775       " LIMIT %d",
  1776   1776       (annFlags & ANN_FILE_VERS)!=0 ? "fid" : "mid",
  1777   1777       fnid,
  1778   1778       iLimit>0 ? iLimit : 10000000
  1779   1779     );
  1780         -  while( db_step(&q)==SQLITE_ROW ){
         1780  +  while( db_step(&q)==SQLITE4_ROW ){
  1781   1781       int pid = db_column_int(&q, 0);
  1782   1782       const char *zUuid = db_column_text(&q, 1);
  1783   1783       const char *zDate = db_column_text(&q, 2);
  1784   1784       const char *zUser = db_column_text(&q, 3);
  1785   1785       if( webLabel ){
  1786   1786         zLabel = mprintf(
  1787   1787             "<a href='%R/info/%s' target='infowindow'>%.10s</a> %s %13.13s", 

Changes to src/diffcmd.c.

   278    278         " WHERE vid=%d"
   279    279         "   AND (deleted OR chnged OR rid==0)"
   280    280         " ORDER BY pathname",
   281    281         vid
   282    282       );
   283    283     }
   284    284     db_prepare(&q, blob_str(&sql));
   285         -  while( db_step(&q)==SQLITE_ROW ){
          285  +  while( db_step(&q)==SQLITE4_ROW ){
   286    286       const char *zPathname = db_column_text(&q,0);
   287    287       int isDeleted = db_column_int(&q, 1);
   288    288       int isChnged = db_column_int(&q,2);
   289    289       int isNew = db_column_int(&q,3);
   290    290       int srcid = db_column_int(&q, 4);
   291    291       int isLink = db_column_int(&q, 5);
   292    292       char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);

Changes to src/doc.c.

   300    300   
   301    301     z = zName;
   302    302     for(i=0; zName[i]; i++){
   303    303       if( zName[i]=='.' ) z = &zName[i+1];
   304    304     }
   305    305     len = strlen(z);
   306    306     if( len<sizeof(zSuffix)-1 ){
   307         -    sqlite3_snprintf(sizeof(zSuffix), zSuffix, "%s", z);
          307  +    sqlite4_snprintf(zSuffix, sizeof(zSuffix), "%s", z);
   308    308       for(i=0; zSuffix[i]; i++) zSuffix[i] = fossil_tolower(zSuffix[i]);
   309    309       first = 0;
   310    310       last = sizeof(aMime)/sizeof(aMime[0]);
   311    311       while( first<=last ){
   312    312         int c;
   313    313         i = (first+last)/2;
   314    314         c = fossil_strcmp(zSuffix, aMime[i].zSuffix);
................................................................................
   384    384           goto doc_not_found;
   385    385         }
   386    386       }else{
   387    387         goto doc_not_found;
   388    388       }
   389    389     }
   390    390     if( fossil_strcmp(zBaseline,"ckout")==0 && db_open_local()==0 ){
   391         -    sqlite3_snprintf(sizeof(zBaseline), zBaseline, "tip");
          391  +    sqlite4_snprintf(zBaseline, sizeof(zBaseline), "tip");
   392    392     }
   393    393     if( fossil_strcmp(zBaseline,"ckout")==0 ){
   394    394       /* Read from the local checkout */
   395    395       char *zFullpath;
   396    396       db_must_be_within_tree();
   397    397       zFullpath = mprintf("%s/%s", g.zLocalRoot, zName);
   398    398       if( !file_isfile(zFullpath) ){

Changes to src/encode.c.

   530    530     int n, i;
   531    531     unsigned char salt;
   532    532     char *zOut;
   533    533     
   534    534     if( zIn==0 ) return 0;
   535    535     n = strlen(zIn);
   536    536     zOut = fossil_malloc( n*2+3 );
   537         -  sqlite3_randomness(1, &salt);
          537  +  sqlite4_randomness(0, 1, &salt);
   538    538     zOut[n+1] = (char)salt;
   539    539     for(i=0; i<n; i++) zOut[i+n+2] = zIn[i]^aObscurer[i&0x0f]^salt;
   540    540     encode16((unsigned char*)&zOut[n+1], (unsigned char*)zOut, n+1);
   541    541     return zOut;
   542    542   }
   543    543   
   544    544   /*

Changes to src/event.c.

    81     81     rid = nextRid = prevRid = 0;
    82     82     db_prepare(&q1,
    83     83        "SELECT rid FROM tagxref"
    84     84        " WHERE tagid=(SELECT tagid FROM tag WHERE tagname GLOB 'event-%q*')"
    85     85        " ORDER BY mtime DESC",
    86     86        zEventId
    87     87     );
    88         -  while( db_step(&q1)==SQLITE_ROW ){
           88  +  while( db_step(&q1)==SQLITE4_ROW ){
    89     89       nextRid = rid;
    90     90       rid = db_column_int(&q1, 0);
    91     91       if( specRid==0 || specRid==rid ){
    92         -      if( db_step(&q1)==SQLITE_ROW ){
           92  +      if( db_step(&q1)==SQLITE4_ROW ){
    93     93           prevRid = db_column_int(&q1, 0);
    94     94         }
    95     95         break;
    96     96       }
    97     97     }
    98     98     db_finalize(&q1);
    99     99     if( rid==0 || (specRid!=0 && specRid!=rid) ){
................................................................................
   322    322           db_multi_exec("INSERT INTO newtags VALUES(%B)", &one);
   323    323         }
   324    324         blob_reset(&tags);
   325    325   
   326    326         /* Extract the tags in sorted order and make an entry in the
   327    327         ** artifact for each. */
   328    328         db_prepare(&q, "SELECT x FROM newtags ORDER BY x");
   329         -      while( db_step(&q)==SQLITE_ROW ){
          329  +      while( db_step(&q)==SQLITE4_ROW ){
   330    330           blob_appendf(&event, "T +sym-%F *\n", db_column_text(&q, 0));
   331    331         }
   332    332         db_finalize(&q);
   333    333       }        
   334    334       if( g.zLogin ){
   335    335         blob_appendf(&event, "U %F\n", g.zLogin);
   336    336       }

Changes to src/export.c.

    33     33   
    34     34     if( zUser==0 ){
    35     35       printf(" <unknown>");
    36     36       return;
    37     37     }
    38     38     db_static_prepare(&q, "SELECT info FROM user WHERE login=:user");
    39     39     db_bind_text(&q, ":user", zUser);
    40         -  if( db_step(&q)!=SQLITE_ROW ){
           40  +  if( db_step(&q)!=SQLITE4_ROW ){
    41     41       db_reset(&q);
    42     42       for(i=0; zUser[i] && zUser[i]!='>' && zUser[i]!='<'; i++){}
    43     43       if( zUser[i]==0 ){
    44     44         printf(" %s <%s>", zUser, zUser);
    45     45         return;
    46     46       }
    47     47       zName = mprintf("%s", zUser);
................................................................................
   180    180       " FROM mlink"
   181    181       " WHERE fid>0 AND NOT EXISTS(SELECT 1 FROM oldblob WHERE rid=fid)");
   182    182     db_prepare(&q,
   183    183       "SELECT DISTINCT fid FROM mlink"
   184    184       " WHERE fid>0 AND NOT EXISTS(SELECT 1 FROM oldblob WHERE rid=fid)");
   185    185     db_prepare(&q2, "INSERT INTO oldblob VALUES (:rid)");
   186    186     db_prepare(&q3, "SELECT rid FROM newblob WHERE srcid= (:srcid)");
   187         -  while( db_step(&q)==SQLITE_ROW ){
          187  +  while( db_step(&q)==SQLITE4_ROW ){
   188    188       int rid = db_column_int(&q, 0);
   189    189       Blob content;
   190    190   
   191    191       while( !bag_find(&blobs, rid) ){
   192    192         content_get(rid, &content);
   193    193         db_bind_int(&q2, ":rid", rid);
   194    194         db_step(&q2);
................................................................................
   196    196         printf("blob\nmark :%d\ndata %d\n", BLOBMARK(rid), blob_size(&content));
   197    197         bag_insert(&blobs, rid);
   198    198         fwrite(blob_buffer(&content), 1, blob_size(&content), stdout);
   199    199         printf("\n");
   200    200         blob_reset(&content);
   201    201   
   202    202         db_bind_int(&q3, ":srcid", rid);
   203         -      if( db_step(&q3) != SQLITE_ROW ){
          203  +      if( db_step(&q3) != SQLITE4_ROW ){
   204    204           db_reset(&q3);
   205    205           break;
   206    206         }
   207    207         rid = db_column_int(&q3, 0);
   208    208         db_reset(&q3);
   209    209       }
   210    210     }
................................................................................
   220    220       "       (SELECT value FROM tagxref WHERE rid=objid AND tagid=%d)"
   221    221       "  FROM event"
   222    222       " WHERE type='ci' AND NOT EXISTS (SELECT 1 FROM oldcommit WHERE objid=rid)"
   223    223       " ORDER BY mtime ASC",
   224    224       TAG_BRANCH
   225    225     );
   226    226     db_prepare(&q2, "INSERT INTO oldcommit VALUES (:rid)");
   227         -  while( db_step(&q)==SQLITE_ROW ){
          227  +  while( db_step(&q)==SQLITE4_ROW ){
   228    228       Stmt q4;
   229    229       const char *zSecondsSince1970 = db_column_text(&q, 0);
   230    230       int ckinId = db_column_int(&q, 1);
   231    231       const char *zComment = db_column_text(&q, 2);
   232    232       const char *zUser = db_column_text(&q, 3);
   233    233       const char *zBranch = db_column_text(&q, 4);
   234    234       char *zBr;
................................................................................
   246    246       free(zBr);
   247    247       printf("committer");
   248    248       print_person(zUser);
   249    249       printf(" %s +0000\n", zSecondsSince1970);
   250    250       if( zComment==0 ) zComment = "null comment";
   251    251       printf("data %d\n%s\n", (int)strlen(zComment), zComment);
   252    252       db_prepare(&q3, "SELECT pid FROM plink WHERE cid=%d AND isprim", ckinId);
   253         -    if( db_step(&q3) == SQLITE_ROW ){
          253  +    if( db_step(&q3) == SQLITE4_ROW ){
   254    254         printf("from :%d\n", COMMITMARK(db_column_int(&q3, 0)));
   255    255         db_prepare(&q4,
   256    256           "SELECT pid FROM plink"
   257    257           " WHERE cid=%d AND NOT isprim"
   258    258           "   AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=pid)"
   259    259           " ORDER BY pid",
   260    260           ckinId);
   261         -      while( db_step(&q4)==SQLITE_ROW ){
          261  +      while( db_step(&q4)==SQLITE4_ROW ){
   262    262           printf("merge :%d\n", COMMITMARK(db_column_int(&q4,0)));
   263    263         }
   264    264         db_finalize(&q4);
   265    265       }else{
   266    266         printf("deleteall\n");
   267    267       }
   268    268   
   269    269       db_prepare(&q4,
   270    270         "SELECT filename.name, mlink.fid, mlink.mperm FROM mlink"
   271    271         " JOIN filename ON filename.fnid=mlink.fnid"
   272    272         " WHERE mlink.mid=%d",
   273    273         ckinId
   274    274       );
   275         -    while( db_step(&q4)==SQLITE_ROW ){
          275  +    while( db_step(&q4)==SQLITE4_ROW ){
   276    276         const char *zName = db_column_text(&q4,0);
   277    277         int zNew = db_column_int(&q4,1);
   278    278         int mPerm = db_column_int(&q4,2);
   279    279         if( zNew==0)
   280    280           printf("D %s\n", zName);
   281    281         else if( bag_find(&blobs, zNew) ) {
   282    282           const char *zPerm;
................................................................................
   300    300   
   301    301     /* Output tags */
   302    302     db_prepare(&q,
   303    303        "SELECT tagname, rid, strftime('%%s',mtime)"
   304    304        "  FROM tagxref JOIN tag USING(tagid)"
   305    305        " WHERE tagtype=1 AND tagname GLOB 'sym-*'"
   306    306     );
   307         -  while( db_step(&q)==SQLITE_ROW ){
          307  +  while( db_step(&q)==SQLITE4_ROW ){
   308    308       const char *zTagname = db_column_text(&q, 0);
   309    309       char *zEncoded = 0;
   310    310       int rid = db_column_int(&q, 1);
   311    311       const char *zSecSince1970 = db_column_text(&q, 2);
   312    312       int i;
   313    313       if( rid==0 || !bag_find(&vers, rid) ) continue;
   314    314       zTagname += 4;
................................................................................
   328    328     if( markfile_out!=0 ){
   329    329       FILE *f;
   330    330       f = fopen(markfile_out, "w");
   331    331       if( f == 0 ){
   332    332         fossil_panic("cannot open %s for writing", markfile_out);
   333    333       }
   334    334       db_prepare(&q, "SELECT rid FROM oldblob");
   335         -    while( db_step(&q)==SQLITE_ROW ){
          335  +    while( db_step(&q)==SQLITE4_ROW ){
   336    336         fprintf(f, "b%d\n", db_column_int(&q, 0));
   337    337       }
   338    338       db_finalize(&q);
   339    339       db_prepare(&q, "SELECT rid FROM oldcommit");
   340         -    while( db_step(&q)==SQLITE_ROW ){
          340  +    while( db_step(&q)==SQLITE4_ROW ){
   341    341         fprintf(f, "c%d\n", db_column_int(&q, 0));
   342    342       }
   343    343       db_finalize(&q);
   344    344       if( ferror(f)!=0 || fclose(f)!=0 ) {
   345    345         fossil_panic("error while writing %s", markfile_out);
   346    346       }
   347    347     }
   348    348   }

Changes to src/file.c.

   669    669     blob_zero(&x);
   670    670     for(i=2; i<g.argc; i++){
   671    671       char zBuf[100];
   672    672       const char *zName = g.argv[i];
   673    673       file_canonical_name(zName, &x, 0);
   674    674       fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x));
   675    675       blob_reset(&x);
   676         -    sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zName));
          676  +    sqlite4_snprintf(zBuf, sizeof(zBuf), "%lld", file_wd_size(zName));
   677    677       fossil_print("  file_size   = %s\n", zBuf);
   678         -    sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zName));
          678  +    sqlite4_snprintf(zBuf, sizeof(zBuf), "%lld", file_wd_mtime(zName));
   679    679       fossil_print("  file_mtime  = %s\n", zBuf);
   680    680       fossil_print("  file_isfile = %d\n", file_wd_isfile(zName));
   681    681       fossil_print("  file_isfile_or_link = %d\n",file_wd_isfile_or_link(zName));
   682    682       fossil_print("  file_islink = %d\n", file_wd_islink(zName));
   683    683       fossil_print("  file_isexe  = %d\n", file_wd_isexe(zName));
   684    684       fossil_print("  file_isdir  = %d\n", file_wd_isdir(zName));
   685    685     }
................................................................................
   944    944       if( azDirs[i]==0 ) continue;
   945    945       if( !file_isdir(azDirs[i]) ) continue;
   946    946       zDir = azDirs[i];
   947    947       break;
   948    948     }
   949    949   
   950    950     /* Check that the output buffer is large enough for the temporary file 
   951         -  ** name. If it is not, return SQLITE_ERROR.
          951  +  ** name. If it is not, return SQLITE4_ERROR.
   952    952     */
   953    953     if( (strlen(zDir) + 17) >= (size_t)nBuf ){
   954    954       fossil_fatal("insufficient space for temporary filename");
   955    955     }
   956    956   
   957    957     do{
   958    958       if( cnt++>20 ) fossil_panic("cannot generate a temporary filename");
   959         -    sqlite3_snprintf(nBuf-17, zBuf, "%s/", zDir);
          959  +    sqlite4_snprintf(zBuf, nBuf-17, "%s/", zDir);
   960    960       j = (int)strlen(zBuf);
   961         -    sqlite3_randomness(15, &zBuf[j]);
          961  +    sqlite4_randomness(0, 15, &zBuf[j]);
   962    962       for(i=0; i<15; i++, j++){
   963    963         zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
   964    964       }
   965    965       zBuf[j] = 0;
   966    966     }while( file_size(zBuf)>=0 );
   967    967   
   968    968   #if defined(_WIN32)
................................................................................
  1005   1005   /*
  1006   1006   ** Translate MBCS to UTF8.  Return a pointer to the translated text.  
  1007   1007   ** Call fossil_mbcs_free() to deallocate any memory used to store the
  1008   1008   ** returned pointer when done.
  1009   1009   */
  1010   1010   char *fossil_mbcs_to_utf8(const char *zMbcs){
  1011   1011   #ifdef _WIN32
  1012         -  extern char *sqlite3_win32_mbcs_to_utf8(const char*);
  1013         -  return sqlite3_win32_mbcs_to_utf8(zMbcs);
         1012  +  extern char *sqlite4_win32_mbcs_to_utf8(const char*);
         1013  +  return sqlite4_win32_mbcs_to_utf8(zMbcs);
  1014   1014   #else
  1015   1015     return (char*)zMbcs;  /* No-op on unix */
  1016   1016   #endif  
  1017   1017   }
  1018   1018   
  1019   1019   /*
  1020   1020   ** Translate UTF8 to MBCS for use in system calls.  Return a pointer to the
  1021   1021   ** translated text..  Call fossil_mbcs_free() to deallocate any memory
  1022   1022   ** used to store the returned pointer when done.
  1023   1023   */
  1024   1024   char *fossil_utf8_to_mbcs(const char *zUtf8){
  1025   1025   #ifdef _WIN32
  1026         -  extern char *sqlite3_win32_utf8_to_mbcs(const char*);
  1027         -  return sqlite3_win32_utf8_to_mbcs(zUtf8);
         1026  +  extern char *sqlite4_win32_utf8_to_mbcs(const char*);
         1027  +  return sqlite4_win32_utf8_to_mbcs(zUtf8);
  1028   1028   #else
  1029   1029     return (char*)zUtf8;  /* No-op on unix */
  1030   1030   #endif  
  1031   1031   }
  1032   1032   
  1033   1033   /*
  1034   1034   ** Return the value of an environment variable as UTF8.
................................................................................
  1084   1084   
  1085   1085   /*
  1086   1086   ** Translate MBCS to UTF8.  Return a pointer.  Call fossil_mbcs_free()
  1087   1087   ** to deallocate any memory used to store the returned pointer when done.
  1088   1088   */
  1089   1089   void fossil_mbcs_free(char *zOld){
  1090   1090   #ifdef _WIN32
  1091         -  extern void sqlite3_free(void*);
  1092         -  sqlite3_free(zOld);
         1091  +  extern void sqlite4_free(void*);
         1092  +  sqlite4_free(0, zOld);
  1093   1093   #else
  1094   1094     /* No-op on unix */
  1095   1095   #endif  
  1096   1096   }
  1097   1097   
  1098   1098   /*
  1099   1099   ** Like fopen() but always takes a UTF8 argument.

Changes to src/finfo.c.

    71     71       vfile_check_signature(vid, 1, 0);
    72     72       file_tree_name(g.argv[2], &fname, 1);
    73     73       db_prepare(&q,
    74     74           "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
    75     75           "  FROM vfile WHERE vfile.pathname=%B %s",
    76     76           &fname, filename_collation());
    77     77       blob_zero(&line);
    78         -    if ( db_step(&q)==SQLITE_ROW ) {
           78  +    if ( db_step(&q)==SQLITE4_ROW ) {
    79     79         Blob uuid;
    80     80         int isDeleted = db_column_int(&q, 1);
    81     81         int isNew = db_column_int(&q,2) == 0;
    82     82         int chnged = db_column_int(&q,3);
    83     83         int renamed = db_column_int(&q,4);
    84     84   
    85     85         blob_zero(&uuid);
................................................................................
   170    170           " ORDER BY event.mtime DESC LIMIT %d OFFSET %d",
   171    171           zFilename, filename_collation(), iLimit, iOffset
   172    172       );
   173    173       blob_zero(&line);
   174    174       if( iBrief ){
   175    175         fossil_print("History of %s\n", blob_str(&fname));
   176    176       }
   177         -    while( db_step(&q)==SQLITE_ROW ){
          177  +    while( db_step(&q)==SQLITE4_ROW ){
   178    178         const char *zFileUuid = db_column_text(&q, 0);
   179    179         const char *zCiUuid = db_column_text(&q,1);
   180    180         const char *zDate = db_column_text(&q, 2);
   181    181         const char *zCom = db_column_text(&q, 3);
   182    182         const char *zUser = db_column_text(&q, 4);
   183    183         char *zOut;
   184    184         if( iBrief ){
   185    185           fossil_print("%s ", zDate);
   186         -        zOut = sqlite3_mprintf("[%.10s] %s (user: %s, artifact: [%.10s])",
          186  +        zOut = sqlite4_mprintf(0, "[%.10s] %s (user: %s, artifact: [%.10s])",
   187    187                                  zCiUuid, zCom, zUser, zFileUuid);
   188    188           comment_print(zOut, 11, 79);
   189         -        sqlite3_free(zOut);
          189  +        sqlite4_free(0, zOut);
   190    190         }else{
   191    191           blob_reset(&line);
   192    192           blob_appendf(&line, "%.10s ", zCiUuid);
   193    193           blob_appendf(&line, "%.10s ", zDate);
   194    194           blob_appendf(&line, "%8.8s ", zUser);
   195    195           blob_appendf(&line,"%-40.40s\n", zCom );
   196    196           comment_print(blob_str(&line), 0, 79);
................................................................................
   272    272     blob_appendf(&title, "History of ");
   273    273     hyperlinked_path(zFilename, &title, 0);
   274    274     @ <h2>%b(&title)</h2>
   275    275     blob_reset(&title);
   276    276     pGraph = graph_init();
   277    277     @ <div id="canvas" style="position:relative;width:1px;height:1px;"></div>
   278    278     @ <table id="timelineTable" class="timelineTable">
   279         -  while( db_step(&q)==SQLITE_ROW ){
          279  +  while( db_step(&q)==SQLITE4_ROW ){
   280    280       const char *zDate = db_column_text(&q, 0);
   281    281       const char *zCom = db_column_text(&q, 1);
   282    282       const char *zUser = db_column_text(&q, 2);
   283    283       int fpid = db_column_int(&q, 3);
   284    284       int frid = db_column_int(&q, 4);
   285    285       const char *zPUuid = db_column_text(&q, 5);
   286    286       const char *zUuid = db_column_text(&q, 6);
................................................................................
   295    295       if( uBg ){
   296    296         zBgClr = hash_color(zUser);
   297    297       }else if( brBg || zBgClr==0 || zBgClr[0]==0 ){
   298    298         zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr);
   299    299       }
   300    300       gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr, zBgClr, 0);
   301    301       if( memcmp(zDate, zPrevDate, 10) ){
   302         -      sqlite3_snprintf(sizeof(zPrevDate), zPrevDate, "%.10s", zDate);
          302  +      sqlite4_snprintf(zPrevDate, sizeof(zPrevDate), "%.10s", zDate);
   303    303         @ <tr><td>
   304    304         @   <div class="divider">%s(zPrevDate)</div>
   305    305         @ </td></tr>
   306    306       }
   307    307       memcpy(zTime, &zDate[11], 5);
   308    308       zTime[5] = 0;
   309    309       @ <tr><td class="timelineTime">
................................................................................
   310    310       @ %z(href("%R/timeline?c=%t",zDate))%s(zTime)</a></td>
   311    311       @ <td class="timelineGraph"><div id="m%d(gidx)"></div></td>
   312    312       if( zBgClr && zBgClr[0] ){
   313    313         @ <td class="timelineTableCell" style="background-color: %h(zBgClr);">
   314    314       }else{
   315    315         @ <td class="timelineTableCell">
   316    316       }
   317         -    sqlite3_snprintf(sizeof(zShort), zShort, "%.10s", zUuid);
   318         -    sqlite3_snprintf(sizeof(zShortCkin), zShortCkin, "%.10s", zCkin);
          317  +    sqlite4_snprintf(zShort, sizeof(zShort), "%.10s", zUuid);
          318  +    sqlite4_snprintf(zShortCkin, sizeof(zShortCkin), "%.10s", zCkin);
   319    319       if( zUuid ){
   320    320         @ %z(href("%R/artifact/%s",zUuid))[%S(zUuid)]</a> part of check-in
   321    321       }else{
   322    322         @ <b>Deleted</b> by check-in
   323    323       }
   324    324       hyperlink_to_uuid(zShortCkin);
   325    325       @ %h(zCom) (user: 

Changes to src/gzip.c.

    45     45     z[2] = (v>>16) & 0xff;
    46     46     z[3] = (v>>24) & 0xff;
    47     47   }
    48     48   
    49     49   /*
    50     50   ** Begin constructing a gzip file.
    51     51   */
    52         -void gzip_begin(sqlite3_int64 now){
           52  +void gzip_begin(sqlite4_int64 now){
    53     53     char aHdr[10];
    54     54     assert( gzip.eState==0 );
    55     55     blob_zero(&gzip.out);
    56     56     aHdr[0] = 0x1f;
    57     57     aHdr[1] = 0x8b;
    58     58     aHdr[2] = 8;
    59     59     aHdr[3] = 0;
................................................................................
   123    123   **
   124    124   ** Compress a file using gzip.
   125    125   */
   126    126   void test_gzip_cmd(void){
   127    127     Blob b;
   128    128     char *zOut;
   129    129     if( g.argc!=3 ) usage("FILENAME");
   130         -  sqlite3_open(":memory:", &g.db);
          130  +  sqlite4_open(0, ":memory:", &g.db, SQLITE4_OPEN_READWRITE);
   131    131     gzip_begin(0);
   132    132     blob_read_from_file(&b, g.argv[2]);
   133    133     zOut = mprintf("%s.gz", g.argv[2]);
   134    134     gzip_step(blob_buffer(&b), blob_size(&b));
   135    135     blob_reset(&b);
   136    136     gzip_finish(&b);
   137    137     blob_write_to_file(&b, zOut);
   138    138     blob_reset(&b);
   139    139     fossil_free(zOut);
   140    140   }

Changes to src/http_transport.c.

   200    200         rc = ssl_open();
   201    201         if( rc==0 ) transport.isOpen = 1;
   202    202         #else
   203    203         socket_set_errmsg("HTTPS: Fossil has been compiled without SSL support");
   204    204         rc = 1;
   205    205         #endif
   206    206       }else if( g.urlIsFile ){
   207         -      sqlite3_uint64 iRandId;
   208         -      sqlite3_randomness(sizeof(iRandId), &iRandId);
          207  +      sqlite4_uint64 iRandId;
          208  +      sqlite4_randomness(0, sizeof(iRandId), &iRandId);
   209    209         transport.zOutFile = mprintf("%s-%llu-out.http", 
   210    210                                          g.zRepositoryName, iRandId);
   211    211         transport.zInFile = mprintf("%s-%llu-in.http", 
   212    212                                          g.zRepositoryName, iRandId);
   213    213         transport.pFile = fopen(transport.zOutFile, "wb");
   214    214         if( transport.pFile==0 ){
   215    215           fossil_fatal("cannot output temporary file: %s", transport.zOutFile);

Changes to src/import.c.

   555    555       }else
   556    556       if( memcmp(zLine, "mark ", 5)==0 ){
   557    557         trim_newline(&zLine[5]);
   558    558         fossil_free(gg.zMark);
   559    559         gg.zMark = fossil_strdup(&zLine[5]);
   560    560       }else
   561    561       if( memcmp(zLine, "tagger ", 7)==0 || memcmp(zLine, "committer ",10)==0 ){
   562         -      sqlite3_int64 secSince1970;
          562  +      sqlite4_int64 secSince1970;
   563    563         for(i=0; zLine[i] && zLine[i]!='<'; i++){}
   564    564         if( zLine[i]==0 ) goto malformed_line;
   565    565         z = &zLine[i+1];
   566    566         for(i=i+1; zLine[i] && zLine[i]!='>'; i++){}
   567    567         if( zLine[i]==0 ) goto malformed_line;
   568    568         zLine[i] = 0;
   569    569         fossil_free(gg.zUser);
................................................................................
   772    772     );
   773    773   
   774    774   
   775    775     db_begin_transaction();
   776    776     if( !incrFlag ) db_initial_setup(0, 0, 1);
   777    777     git_fast_import(pIn);
   778    778     db_prepare(&q, "SELECT tcontent FROM xtag");
   779         -  while( db_step(&q)==SQLITE_ROW ){
          779  +  while( db_step(&q)==SQLITE4_ROW ){
   780    780       Blob record;
   781    781       db_ephemeral_blob(&q, 0, &record);
   782    782       fast_insert_content(&record, 0, 0);
   783    783       import_reset(0);
   784    784     }
   785    785     db_finalize(&q);
   786    786     db_end_transaction(0);

Changes to src/info.c.

    81     81         rid
    82     82       );
    83     83     }
    84     84     if( showFamily ){
    85     85       db_prepare(&q, "SELECT uuid, pid, isprim FROM plink JOIN blob ON pid=rid "
    86     86                      " WHERE cid=%d"
    87     87                      " ORDER BY isprim DESC, mtime DESC /*sort*/", rid);
    88         -    while( db_step(&q)==SQLITE_ROW ){
           88  +    while( db_step(&q)==SQLITE4_ROW ){
    89     89         const char *zUuid = db_column_text(&q, 0);
    90     90         const char *zType = db_column_int(&q, 2) ? "parent:" : "merged-from:";
    91     91         zDate = db_text("", 
    92     92           "SELECT datetime(mtime) || ' UTC' FROM event WHERE objid=%d",
    93     93           db_column_int(&q, 1)
    94     94         );
    95     95         fossil_print("%-13s %s %s\n", zType, zUuid, zDate);
    96     96         free(zDate);
    97     97       }
    98     98       db_finalize(&q);
    99     99       db_prepare(&q, "SELECT uuid, cid, isprim FROM plink JOIN blob ON cid=rid "
   100    100                      " WHERE pid=%d"
   101    101                      " ORDER BY isprim DESC, mtime DESC /*sort*/", rid);
   102         -    while( db_step(&q)==SQLITE_ROW ){
          102  +    while( db_step(&q)==SQLITE4_ROW ){
   103    103         const char *zUuid = db_column_text(&q, 0);
   104    104         const char *zType = db_column_int(&q, 2) ? "child:" : "merged-into:";
   105    105         zDate = db_text("", 
   106    106           "SELECT datetime(mtime) || ' UTC' FROM event WHERE objid=%d",
   107    107           db_column_int(&q, 1)
   108    108         );
   109    109         fossil_print("%-13s %s %s\n", zType, zUuid, zDate);
................................................................................
   128    128   ** checkouts in a repository.
   129    129   */
   130    130   static void extraRepoInfo(void){
   131    131     Stmt s;
   132    132     db_prepare(&s, "SELECT substr(name,7), date(mtime,'unixepoch')"
   133    133                    "  FROM config"
   134    134                    " WHERE name GLOB 'ckout:*' ORDER BY name");
   135         -  while( db_step(&s)==SQLITE_ROW ){
          135  +  while( db_step(&s)==SQLITE4_ROW ){
   136    136       const char *zName;
   137    137       const char *zCkout = db_column_text(&s, 0);
   138    138       if( g.localOpen ){
   139    139         if( fossil_strcmp(zCkout, g.zLocalRoot)==0 ) continue;
   140    140         zName = "alt-root:";
   141    141       }else{
   142    142         zName = "check-out:";
................................................................................
   144    144       fossil_print("%-11s   %-54s %s\n", zName, zCkout,
   145    145                    db_column_text(&s, 1));
   146    146     }
   147    147     db_finalize(&s);
   148    148     db_prepare(&s, "SELECT substr(name,9), date(mtime,'unixepoch')"
   149    149                    "  FROM config"
   150    150                    " WHERE name GLOB 'baseurl:*' ORDER BY name");
   151         -  while( db_step(&s)==SQLITE_ROW ){
          151  +  while( db_step(&s)==SQLITE4_ROW ){
   152    152       fossil_print("access-url:   %-54s %s\n", db_column_text(&s, 0),
   153    153                    db_column_text(&s, 1));
   154    154     }
   155    155     db_finalize(&s);
   156    156   }
   157    157   
   158    158   
................................................................................
   231    231       "       (SELECT uuid FROM blob WHERE rid=tagxref.srcid AND rid!=%d),"
   232    232       "       value, datetime(tagxref.mtime,'localtime'), tagtype,"
   233    233       "       (SELECT uuid FROM blob WHERE rid=tagxref.origid AND rid!=%d)"
   234    234       "  FROM tagxref JOIN tag ON tagxref.tagid=tag.tagid"
   235    235       " WHERE tagxref.rid=%d AND tagname NOT GLOB '%s'"
   236    236       " ORDER BY tagname /*sort*/", rid, rid, rid, zNotGlob
   237    237     );
   238         -  while( db_step(&q)==SQLITE_ROW ){
          238  +  while( db_step(&q)==SQLITE4_ROW ){
   239    239       const char *zTagname = db_column_text(&q, 1);
   240    240       const char *zSrcUuid = db_column_text(&q, 2);
   241    241       const char *zValue = db_column_text(&q, 3);
   242    242       const char *zDate = db_column_text(&q, 4);
   243    243       int tagtype = db_column_int(&q, 5);
   244    244       const char *zOrigUuid = db_column_text(&q, 6);
   245    245       cnt++;
................................................................................
   469    469        "       datetime(omtime, 'localtime')"
   470    470        "  FROM blob, event"
   471    471        " WHERE blob.rid=%d"
   472    472        "   AND event.objid=%d",
   473    473        rid, rid
   474    474     );
   475    475     sideBySide = atoi(PD("sbs","1"));
   476         -  if( db_step(&q)==SQLITE_ROW ){
          476  +  if( db_step(&q)==SQLITE4_ROW ){
   477    477       const char *zUuid = db_column_text(&q, 0);
   478    478       char *zTitle = mprintf("Check-in [%.10s]", zUuid);
   479    479       char *zEUser, *zEComment;
   480    480       const char *zUser;
   481    481       const char *zComment;
   482    482       const char *zDate;
   483    483       const char *zOrigDate;
................................................................................
   525    525       if( g.perm.Admin ){
   526    526         db_prepare(&q, 
   527    527            "SELECT rcvfrom.ipaddr, user.login, datetime(rcvfrom.mtime)"
   528    528            "  FROM blob JOIN rcvfrom USING(rcvid) LEFT JOIN user USING(uid)"
   529    529            " WHERE blob.rid=%d",
   530    530            rid
   531    531         );
   532         -      if( db_step(&q)==SQLITE_ROW ){
          532  +      if( db_step(&q)==SQLITE4_ROW ){
   533    533           const char *zIpAddr = db_column_text(&q, 0);
   534    534           const char *zUser = db_column_text(&q, 1);
   535    535           const char *zDate = db_column_text(&q, 2);
   536    536           if( zUser==0 || zUser[0]==0 ) zUser = "unknown";
   537    537           @ <tr><th>Received&nbsp;From:</th>
   538    538           @ <td>%h(zUser) @ %h(zIpAddr) on %s(zDate)</td></tr>
   539    539         }
................................................................................
   552    552         if( zParent && !isLeaf ){
   553    553           @ | %z(href("%R/timeline?dp=%S",zUuid))both</a>
   554    554         }
   555    555         db_prepare(&q, "SELECT substr(tag.tagname,5) FROM tagxref, tag "
   556    556                        " WHERE rid=%d AND tagtype>0 "
   557    557                        "   AND tag.tagid=tagxref.tagid "
   558    558                        "   AND +tag.tagname GLOB 'sym-*'", rid);
   559         -      while( db_step(&q)==SQLITE_ROW ){
          559  +      while( db_step(&q)==SQLITE4_ROW ){
   560    560           const char *zTagName = db_column_text(&q, 0);
   561    561           @  | %z(href("%R/timeline?r=%T",zTagName))%h(zTagName)</a>
   562    562         }
   563    563         db_finalize(&q);
   564    564         @ </td></tr>
   565    565         @ <tr><th>Other&nbsp;Links:</th>
   566    566         @   <td>
................................................................................
   636    636          "       (SELECT name FROM filename WHERE filename.fnid=mlink.pfnid)"
   637    637          "  FROM mlink JOIN filename ON filename.fnid=mlink.fnid"
   638    638          " WHERE mlink.mid=%d"
   639    639          " ORDER BY name /*sort*/",
   640    640          rid
   641    641       );
   642    642       diffFlags = construct_diff_flags(showDiff, sideBySide);
   643         -    while( db_step(&q)==SQLITE_ROW ){
          643  +    while( db_step(&q)==SQLITE4_ROW ){
   644    644         const char *zName = db_column_text(&q,0);
   645    645         int mperm = db_column_int(&q, 1);
   646    646         const char *zOld = db_column_text(&q,2);
   647    647         const char *zNew = db_column_text(&q,3);
   648    648         const char *zOldName = db_column_text(&q, 4);
   649    649         append_file_change_line(zName, zOld, zNew, zOldName, diffFlags, mperm);
   650    650       }
................................................................................
   679    679        " WHERE tagxref.rid=%d"
   680    680        "   AND tag.tagid=tagxref.tagid"
   681    681        "   AND tag.tagname LIKE 'wiki-%%'"
   682    682        "   AND blob.rid=%d"
   683    683        "   AND event.objid=%d",
   684    684        rid, rid, rid
   685    685     );
   686         -  if( db_step(&q)==SQLITE_ROW ){
          686  +  if( db_step(&q)==SQLITE4_ROW ){
   687    687       const char *zName = db_column_text(&q, 0);
   688    688       const char *zUuid = db_column_text(&q, 1);
   689    689       char *zTitle = mprintf("Wiki Page %s", zName);
   690    690       const char *zDate = db_column_text(&q,2);
   691    691       const char *zUser = db_column_text(&q,3);
   692    692       style_header(zTitle);
   693    693       free(zTitle);
................................................................................
   775    775       "SELECT datetime(mtime), coalesce(euser,user),"
   776    776       "       coalesce(ecomment,comment), uuid"
   777    777       "  FROM event, blob"
   778    778       " WHERE event.objid=%d AND type='ci'"
   779    779       "   AND blob.rid=%d",
   780    780       rid, rid
   781    781     );
   782         -  while( db_step(&q)==SQLITE_ROW ){
          782  +  while( db_step(&q)==SQLITE4_ROW ){
   783    783       const char *zDate = db_column_text(&q, 0);
   784    784       const char *zUser = db_column_text(&q, 1);
   785    785       const char *zCom = db_column_text(&q, 2);
   786    786       const char *zUuid = db_column_text(&q, 3);
   787    787       @ Check-in
   788    788       hyperlink_to_uuid(zUuid);
   789    789       @ - %w(zCom) by
................................................................................
   917    917       "   AND a.rid=mlink.fid"
   918    918       "   AND b.rid=mlink.mid"
   919    919       "   AND mlink.fid=%d"
   920    920       "   ORDER BY filename.name, event.mtime /*sort*/",
   921    921       TAG_BRANCH, rid
   922    922     );
   923    923     @ <ul>
   924         -  while( db_step(&q)==SQLITE_ROW ){
          924  +  while( db_step(&q)==SQLITE4_ROW ){
   925    925       const char *zName = db_column_text(&q, 0);
   926    926       const char *zDate = db_column_text(&q, 1);
   927    927       const char *zCom = db_column_text(&q, 2);
   928    928       const char *zUser = db_column_text(&q, 3);
   929    929       const char *zVers = db_column_text(&q, 4);
   930    930       int mPerm = db_column_int(&q, 5);
   931    931       const char *zBr = db_column_text(&q, 6);
................................................................................
   971    971       "  FROM tagxref, tag, event"
   972    972       " WHERE tagxref.rid=%d"
   973    973       "   AND tag.tagid=tagxref.tagid" 
   974    974       "   AND tag.tagname LIKE 'wiki-%%'"
   975    975       "   AND event.objid=tagxref.rid",
   976    976       rid
   977    977     );
   978         -  while( db_step(&q)==SQLITE_ROW ){
          978  +  while( db_step(&q)==SQLITE4_ROW ){
   979    979       const char *zPagename = db_column_text(&q, 0);
   980    980       const char *zDate = db_column_text(&q, 1);
   981    981       const char *zUser = db_column_text(&q, 2);
   982    982       if( cnt>0 ){
   983    983         @ Also wiki page
   984    984       }else{
   985    985         @ Wiki page
................................................................................
   998    998       db_prepare(&q,
   999    999         "SELECT datetime(mtime), user, comment, type, uuid, tagid"
  1000   1000         "  FROM event, blob"
  1001   1001         " WHERE event.objid=%d"
  1002   1002         "   AND blob.rid=%d",
  1003   1003         rid, rid
  1004   1004       );
  1005         -    while( db_step(&q)==SQLITE_ROW ){
         1005  +    while( db_step(&q)==SQLITE4_ROW ){
  1006   1006         const char *zDate = db_column_text(&q, 0);
  1007   1007         const char *zUser = db_column_text(&q, 1);
  1008   1008         const char *zCom = db_column_text(&q, 2);
  1009   1009         const char *zType = db_column_text(&q, 3);
  1010   1010         const char *zUuid = db_column_text(&q, 4);
  1011   1011         if( cnt>0 ){
  1012   1012           @ Also
................................................................................
  1039   1039     db_prepare(&q, 
  1040   1040       "SELECT target, filename, datetime(mtime), user, src"
  1041   1041       "  FROM attachment"
  1042   1042       " WHERE src=(SELECT uuid FROM blob WHERE rid=%d)"
  1043   1043       " ORDER BY mtime DESC /*sort*/",
  1044   1044       rid
  1045   1045     );
  1046         -  while( db_step(&q)==SQLITE_ROW ){
         1046  +  while( db_step(&q)==SQLITE4_ROW ){
  1047   1047       const char *zTarget = db_column_text(&q, 0);
  1048   1048       const char *zFilename = db_column_text(&q, 1);
  1049   1049       const char *zDate = db_column_text(&q, 2);
  1050   1050       const char *zUser = db_column_text(&q, 3);
  1051   1051       /* const char *zSrc = db_column_text(&q, 4); */
  1052   1052       if( cnt>0 ){
  1053   1053         @ Also attachment "%h(zFilename)" to
................................................................................
  1204   1204     for(i=0; i<n; i+=16){
  1205   1205       j = 0;
  1206   1206       zLine[0] = zHex[(i>>24)&0xf];
  1207   1207       zLine[1] = zHex[(i>>16)&0xf];
  1208   1208       zLine[2] = zHex[(i>>8)&0xf];
  1209   1209       zLine[3] = zHex[i&0xf];
  1210   1210       zLine[4] = ':';
  1211         -    sqlite3_snprintf(sizeof(zLine), zLine, "%04x: ", i);
         1211  +    sqlite4_snprintf(zLine, sizeof(zLine), "%04x: ", i);
  1212   1212       for(j=0; j<16; j++){
  1213   1213         k = 5+j*3;
  1214   1214         zLine[k] = ' ';
  1215   1215         if( i+j<n ){
  1216   1216           unsigned char c = x[i+j];
  1217   1217           zLine[k+1] = zHex[c>>4];
  1218   1218           zLine[k+2] = zHex[c&0xf];
................................................................................
  1851   1851         db_multi_exec("REPLACE INTO newtags VALUES('user','+',%Q)", zNewUser);
  1852   1852       }
  1853   1853       db_prepare(&q,
  1854   1854          "SELECT tag.tagid, tagname FROM tagxref, tag"
  1855   1855          " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid",
  1856   1856          rid
  1857   1857       );
  1858         -    while( db_step(&q)==SQLITE_ROW ){
         1858  +    while( db_step(&q)==SQLITE4_ROW ){
  1859   1859         int tagid = db_column_int(&q, 0);
  1860   1860         const char *zTag = db_column_text(&q, 1);
  1861   1861         char zLabel[30];
  1862         -      sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
         1862  +      sqlite4_snprintf(zLabel, sizeof(zLabel), "c%d", tagid);
  1863   1863         if( P(zLabel) ){
  1864   1864           db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
  1865   1865         }
  1866   1866       }
  1867   1867       db_finalize(&q);
  1868   1868       if( zCloseFlag[0] ){
  1869   1869         db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)");
................................................................................
  1882   1882         );
  1883   1883         db_multi_exec("REPLACE INTO newtags VALUES('branch','*',%Q)", zNewBranch);
  1884   1884         db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','*',NULL)",
  1885   1885                       zNewBranch);
  1886   1886       }
  1887   1887       db_prepare(&q, "SELECT tag, prefix, value FROM newtags"
  1888   1888                      " ORDER BY prefix || tag");
  1889         -    while( db_step(&q)==SQLITE_ROW ){
         1889  +    while( db_step(&q)==SQLITE4_ROW ){
  1890   1890         const char *zTag = db_column_text(&q, 0);
  1891   1891         const char *zPrefix = db_column_text(&q, 1);
  1892   1892         const char *zValue = db_column_text(&q, 2);
  1893   1893         nChng++;
  1894   1894         if( zValue ){
  1895   1895           blob_appendf(&ctrl, "T %s%F %s %F\n", zPrefix, zTag, zUuid, zValue);
  1896   1896         }else{
................................................................................
  1931   1931       wiki_convert(&comment, 0, WIKI_INLINE);
  1932   1932       blob_zero(&suffix);
  1933   1933       blob_appendf(&suffix, "(user: %h", zNewUser);
  1934   1934       db_prepare(&q, "SELECT substr(tagname,5) FROM tagxref, tag"
  1935   1935                      " WHERE tagname GLOB 'sym-*' AND tagxref.rid=%d"
  1936   1936                      "   AND tagtype>1 AND tag.tagid=tagxref.tagid",
  1937   1937                      rid);
  1938         -    while( db_step(&q)==SQLITE_ROW ){
         1938  +    while( db_step(&q)==SQLITE4_ROW ){
  1939   1939         const char *zTag = db_column_text(&q, 0);
  1940   1940         if( nTag==0 ){
  1941   1941           blob_appendf(&suffix, ", tags: %h", zTag);
  1942   1942         }else{
  1943   1943           blob_appendf(&suffix, ", %h", zTag);
  1944   1944         }
  1945   1945         nTag++;
................................................................................
  1987   1987     db_prepare(&q,
  1988   1988        "SELECT tag.tagid, tagname FROM tagxref, tag"
  1989   1989        " WHERE tagxref.rid=%d AND tagtype>0 AND tagxref.tagid=tag.tagid"
  1990   1990        " ORDER BY CASE WHEN tagname GLOB 'sym-*' THEN substr(tagname,5)"
  1991   1991        "               ELSE tagname END /*sort*/",
  1992   1992        rid
  1993   1993     );
  1994         -  while( db_step(&q)==SQLITE_ROW ){
         1994  +  while( db_step(&q)==SQLITE4_ROW ){
  1995   1995       int tagid = db_column_int(&q, 0);
  1996   1996       const char *zTagName = db_column_text(&q, 1);
  1997   1997       char zLabel[30];
  1998         -    sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
         1998  +    sqlite4_snprintf(zLabel, sizeof(zLabel), "c%d", tagid);
  1999   1999       if( P(zLabel) ){
  2000   2000         @ <br /><input type="checkbox" name="c%d(tagid)" checked="checked" />
  2001   2001       }else{
  2002   2002         @ <br /><input type="checkbox" name="c%d(tagid)" />
  2003   2003       }
  2004   2004       if( strncmp(zTagName, "sym-", 4)==0 ){
  2005   2005         @ Cancel tag <b>%h(&zTagName[4])</b>

Changes to src/json.c.

    51     51     "requestId" /*requestId*/,
    52     52     "resultCode" /*resultCode*/,
    53     53     "resultText" /*resultText*/,
    54     54     "timestamp" /*timestamp*/
    55     55   };
    56     56   
    57     57   
    58         -/* Timer code taken from sqlite3's shell.c, modified slightly.
           58  +/* Timer code taken from sqlite4's shell.c, modified slightly.
    59     59      FIXME: move the timer into the fossil core API so that we can
    60     60      start the timer early on in the app init phase. Right now we're
    61     61      just timing the json ops themselves.
    62     62   */
    63     63   #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL)
    64     64   #include <sys/time.h>
    65     65   #include <sys/resource.h>
................................................................................
  1043   1043     }
  1044   1044   
  1045   1045     if(g.isHTTP){
  1046   1046       cgi_set_content_type(json_guess_content_type())
  1047   1047         /* reminder: must be done after g.json.jsonp is initialized */
  1048   1048         ;
  1049   1049   #if 0
  1050         -    /* Calling this seems to trigger an SQLITE_MISUSE warning???
         1050  +    /* Calling this seems to trigger an SQLITE4_MISUSE warning???
  1051   1051          Maybe it's not legal to set the logger more than once?
  1052   1052       */
  1053         -    sqlite3_config(SQLITE_CONFIG_LOG, NULL, 0)
         1053  +    sqlite4_env_config(0, SQLITE4_CONFIG_LOG, NULL, 0)
  1054   1054           /* avoids debug messages on stderr in JSON mode */
  1055   1055           ;
  1056   1056   #endif
  1057   1057     }
  1058   1058   
  1059   1059     g.json.cmd.v = cson_value_new_array();
  1060   1060     g.json.cmd.a = cson_value_get_array(g.json.cmd.v);
................................................................................
  1687   1687   */
  1688   1688   cson_value * json_stmt_to_array_of_obj(Stmt *pStmt,
  1689   1689                                          cson_array * pTgt){
  1690   1690     cson_array * a = pTgt;
  1691   1691     char const * warnMsg = NULL;
  1692   1692     cson_value * colNamesV = NULL;
  1693   1693     cson_array * colNames = NULL;
  1694         -  while( (SQLITE_ROW==db_step(pStmt)) ){
         1694  +  while( (SQLITE4_ROW==db_step(pStmt)) ){
  1695   1695       cson_value * row = NULL;
  1696   1696       if(!a){
  1697   1697         a = cson_new_array();
  1698   1698         assert(NULL!=a);
  1699   1699       }
  1700   1700       if(!colNames){
  1701         -      colNamesV = cson_sqlite3_column_names(pStmt->pStmt);
         1701  +      colNamesV = cson_sqlite4_column_names(pStmt->pStmt);
  1702   1702         assert(NULL != colNamesV);
  1703   1703         cson_value_add_reference(colNamesV)/*avoids an ownership problem*/;
  1704   1704         colNames = cson_value_get_array(colNamesV);
  1705   1705         assert(NULL != colNames);
  1706   1706       }      
  1707         -    row = cson_sqlite3_row_to_object2(pStmt->pStmt, colNames);
         1707  +    row = cson_sqlite4_row_to_object2(pStmt->pStmt, colNames);
  1708   1708       if(!row && !warnMsg){
  1709   1709         warnMsg = "Could not convert at least one result row to JSON.";
  1710   1710         continue;
  1711   1711       }
  1712   1712       if( 0 != cson_array_append(a, row) ){
  1713   1713         cson_value_free(row);
  1714   1714         assert( 0 && "Alloc error.");
................................................................................
  1730   1730   ** result set is represented as an Array of values instead of an
  1731   1731   ** Object (key/value pairs). If pTgt is NULL and the statement
  1732   1732   ** has no results then NULL is returned, not an empty array.
  1733   1733   */
  1734   1734   cson_value * json_stmt_to_array_of_array(Stmt *pStmt,
  1735   1735                                            cson_array * pTgt){
  1736   1736     cson_array * a = pTgt;
  1737         -  while( (SQLITE_ROW==db_step(pStmt)) ){
         1737  +  while( (SQLITE4_ROW==db_step(pStmt)) ){
  1738   1738       cson_value * row = NULL;
  1739   1739       if(!a){
  1740   1740         a = cson_new_array();
  1741   1741         assert(NULL!=a);
  1742   1742       }
  1743         -    row = cson_sqlite3_row_to_array(pStmt->pStmt);
         1743  +    row = cson_sqlite4_row_to_array(pStmt->pStmt);
  1744   1744       cson_array_append(a, row);
  1745   1745     }
  1746   1746     return cson_array_value(a);
  1747   1747   }
  1748   1748   
  1749   1749   cson_value * json_stmt_to_array_of_values(Stmt *pStmt,
  1750   1750                                             int resultColumn,
  1751   1751                                             cson_array * pTgt){
  1752   1752     cson_array * a = pTgt;
  1753         -  while( (SQLITE_ROW==db_step(pStmt)) ){
  1754         -    cson_value * row = cson_sqlite3_column_to_value(pStmt->pStmt,
         1753  +  while( (SQLITE4_ROW==db_step(pStmt)) ){
         1754  +    cson_value * row = cson_sqlite4_column_to_value(pStmt->pStmt,
  1755   1755                                                       resultColumn);
  1756   1756       if(row){
  1757   1757         if(!a){
  1758   1758           a = cson_new_array();
  1759   1759           assert(NULL!=a);
  1760   1760         }
  1761   1761         cson_array_append(a, row);
................................................................................
  1930   1930   cson_value * json_cap_value(){
  1931   1931     if(g.userUid<=0){
  1932   1932       return NULL;
  1933   1933     }else{
  1934   1934       Stmt q = empty_Stmt;
  1935   1935       cson_value * val = NULL;
  1936   1936       db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid);
  1937         -    if( db_step(&q)==SQLITE_ROW ){
  1938         -      char const * str = (char const *)sqlite3_column_text(q.pStmt,0);
         1937  +    if( db_step(&q)==SQLITE4_ROW ){
         1938  +      char const * str = (char const *)sqlite4_column_text(q.pStmt,0);
  1939   1939         if( str ){
  1940   1940           val = json_new_string(str);
  1941   1941         }
  1942   1942       }
  1943   1943       db_finalize(&q);
  1944   1944       return val;
  1945   1945     }
................................................................................
  1956   1956   */
  1957   1957   cson_value * json_page_cap(){
  1958   1958     cson_value * payload = cson_value_new_object();
  1959   1959     cson_value * sub = cson_value_new_object();
  1960   1960     Stmt q;
  1961   1961     cson_object * obj = cson_value_get_object(payload);
  1962   1962     db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid);
  1963         -  if( db_step(&q)==SQLITE_ROW ){
         1963  +  if( db_step(&q)==SQLITE4_ROW ){
  1964   1964       /* reminder: we don't use g.zLogin because it's 0 for the guest
  1965   1965          user and the HTML UI appears to currently allow the name to be
  1966   1966          changed (but doing so would break other code). */
  1967         -    char const * str = (char const *)sqlite3_column_text(q.pStmt,0);
         1967  +    char const * str = (char const *)sqlite4_column_text(q.pStmt,0);
  1968   1968       if( str ){
  1969   1969         cson_object_set( obj, "name",
  1970   1970                          cson_value_new_string(str,strlen(str)) );
  1971   1971       }
  1972         -    str = (char const *)sqlite3_column_text(q.pStmt,1);
         1972  +    str = (char const *)sqlite4_column_text(q.pStmt,1);
  1973   1973       if( str ){
  1974   1974         cson_object_set( obj, "capabilities",
  1975   1975                          cson_value_new_string(str,strlen(str)) );
  1976   1976       }
  1977   1977     }
  1978   1978     db_finalize(&q);
  1979   1979     cson_object_set( obj, "permissionFlags", sub );
................................................................................
  2065   2065         if( t/fsize < 5 ){
  2066   2066           b = 10;
  2067   2067           fsize /= 10;
  2068   2068         }else{
  2069   2069           b = 1;
  2070   2070         }
  2071   2071         a = t/fsize;
  2072         -      sqlite3_snprintf(BufLen,zBuf, "%d:%d", a, b);
         2072  +      sqlite4_snprintf(zBuf,BufLen, "%d:%d", a, b);
  2073   2073         SETBUF(jo, "compressionRatio");
  2074   2074       }
  2075   2075       n = db_int(0, "SELECT count(distinct mid) FROM mlink /*scan*/");
  2076   2076       cson_object_set(jo, "checkinCount", cson_value_new_integer((cson_int_t)n));
  2077   2077       n = db_int(0, "SELECT count(*) FROM filename /*scan*/");
  2078   2078       cson_object_set(jo, "fileCount", cson_value_new_integer((cson_int_t)n));
  2079   2079       n = db_int(0, "SELECT count(*) FROM tag  /*scan*/"
................................................................................
  2083   2083                  " WHERE +tagname GLOB 'tkt-*'");
  2084   2084       cson_object_set(jo, "ticketCount", cson_value_new_integer((cson_int_t)n));
  2085   2085     }/*full*/
  2086   2086     n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)"
  2087   2087                   " + 0.99");
  2088   2088     cson_object_set(jo, "ageDays", cson_value_new_integer((cson_int_t)n));
  2089   2089     cson_object_set(jo, "ageYears", cson_value_new_double(n/365.24));
  2090         -  sqlite3_snprintf(BufLen, zBuf, db_get("project-code",""));
         2090  +  sqlite4_snprintf(zBuf,BufLen, db_get("project-code",""));
  2091   2091     SETBUF(jo, "projectCode");
  2092         -  sqlite3_snprintf(BufLen, zBuf, db_get("server-code",""));
         2092  +  sqlite4_snprintf(zBuf,BufLen, db_get("server-code",""));
  2093   2093     SETBUF(jo, "serverCode");
  2094   2094     cson_object_set(jo, "compiler", cson_value_new_string(COMPILER_NAME, strlen(COMPILER_NAME)));
  2095   2095   
  2096   2096     jv2 = cson_value_new_object();
  2097   2097     jo2 = cson_value_get_object(jv2);
  2098   2098     cson_object_set(jo, "sqlite", jv2);
  2099         -  sqlite3_snprintf(BufLen, zBuf, "%.19s [%.10s] (%s)",
  2100         -                   SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], SQLITE_VERSION);
         2099  +  sqlite4_snprintf(zBuf, BufLen, "%.19s [%.10s] (%s)",
         2100  +                   SQLITE4_SOURCE_ID, &SQLITE4_SOURCE_ID[20], SQLITE4_VERSION);
  2101   2101     SETBUF(jo2, "version");
  2102   2102     zDb = db_name("repository");
  2103   2103     cson_object_set(jo2, "pageCount", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_count", zDb)));
  2104   2104     cson_object_set(jo2, "pageSize", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.page_size", zDb)));
  2105   2105     cson_object_set(jo2, "freeList", cson_value_new_integer((cson_int_t)db_int(0, "PRAGMA %s.freelist_count", zDb)));
  2106         -  sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA %s.encoding", zDb));
         2106  +  sqlite4_snprintf(zBuf, BufLen, "%s", db_text(0, "PRAGMA %s.encoding", zDb));
  2107   2107     SETBUF(jo2, "encoding");
  2108         -  sqlite3_snprintf(BufLen, zBuf, "%s", db_text(0, "PRAGMA %s.journal_mode", zDb));
         2108  +  sqlite4_snprintf(zBuf, BufLen, "%s", db_text(0, "PRAGMA %s.journal_mode", zDb));
  2109   2109     cson_object_set(jo2, "journalMode", *zBuf ? cson_value_new_string(zBuf, strlen(zBuf)) : cson_value_null());
  2110   2110     return jv;
  2111   2111   #undef SETBUF
  2112   2112   }
  2113   2113   
  2114   2114   
  2115   2115   
................................................................................
  2196   2196     /* Reminder: the db_xxx() ops "should" fail via the fossil core
  2197   2197        error handlers, which will cause a JSON error and exit(). i.e. we
  2198   2198        don't handle the errors here. TODO: confirm that all these db
  2199   2199        routine fail gracefully in JSON mode.
  2200   2200   
  2201   2201        On large repos (e.g. fossil's) this operation is likely to take
  2202   2202        longer than the client timeout, which will cause it to fail (but
  2203         -     it's sqlite3, so it'll fail gracefully).
         2203  +     it's sqlite4, so it'll fail gracefully).
  2204   2204     */
  2205   2205       db_close(1);
  2206   2206       db_open_repository(g.zRepositoryName);
  2207   2207       db_begin_transaction();
  2208   2208       rebuild_db(0, 0, 0);
  2209   2209       db_end_transaction(0);
  2210   2210       return NULL;

Changes to src/json_artifact.c.

    61     61     Stmt q = empty_Stmt;
    62     62     cson_array * pParents = NULL;
    63     63     db_prepare( &q,
    64     64                 "SELECT uuid FROM plink, blob"
    65     65                 " WHERE plink.cid=%d AND blob.rid=plink.pid"
    66     66                 " ORDER BY plink.isprim DESC",
    67     67                 rid );
    68         -  while( SQLITE_ROW==db_step(&q) ){
           68  +  while( SQLITE4_ROW==db_step(&q) ){
    69     69       if(!pParents) {
    70     70         pParents = cson_new_array();
    71     71       }
    72         -    cson_array_append( pParents, cson_sqlite3_column_to_value( q.pStmt, 0 ) );
           72  +    cson_array_append( pParents, cson_sqlite4_column_to_value( q.pStmt, 0 ) );
    73     73     }
    74     74     db_finalize(&q);
    75     75     return cson_array_value(pParents);
    76     76   }
    77     77   
    78     78   /*
    79     79   ** Generates an artifact Object for the given rid,
................................................................................
    97     97                " e.user, "
    98     98                " e.comment"
    99     99                " FROM blob b, event e"
   100    100                " WHERE b.rid=%d"
   101    101                "   AND e.objid=%d",
   102    102                rid, rid
   103    103                );
   104         -  if( db_step(&q)==SQLITE_ROW ){
          104  +  if( db_step(&q)==SQLITE4_ROW ){
   105    105       cson_object * o;
   106    106       cson_value * tmpV = NULL;
   107    107       const char *zUuid = db_column_text(&q, 0);
   108    108       const char *zUser;
   109    109       const char *zComment;
   110    110       char * zEUser, * zEComment;
   111    111       int mtime, omtime;
................................................................................
   322    322         TAG_BRANCH, rid
   323    323       );
   324    324     /* TODO: add a "state" flag for the file in each checkin,
   325    325        e.g. "modified", "new", "deleted".
   326    326      */
   327    327     checkin_arr = cson_new_array(); 
   328    328     cson_object_set(pay, "checkins", cson_array_value(checkin_arr));
   329         -  while( (SQLITE_ROW==db_step(&q) ) ){
   330         -    cson_object * row = cson_value_get_object(cson_sqlite3_row_to_object(q.pStmt));
          329  +  while( (SQLITE4_ROW==db_step(&q) ) ){
          330  +    cson_object * row = cson_value_get_object(cson_sqlite4_row_to_object(q.pStmt));
   331    331       char const isNew = cson_value_get_bool(cson_object_get(row,"isNew"));
   332    332       char const isDel = cson_value_get_bool(cson_object_get(row,"isDel"));
   333    333       cson_object_set(row, "isNew", NULL);
   334    334       cson_object_set(row, "isDel", NULL);
   335    335       cson_object_set(row, "state",
   336    336                       json_new_string(json_artifact_status_to_string(isNew, isDel)));
   337    337       cson_array_append( checkin_arr, cson_object_value(row) );

Changes to src/json_branch.c.

   128    128         cson_object_set(pay,"current",json_new_string(zCurrent));
   129    129       }
   130    130     }
   131    131   
   132    132     
   133    133     branch_prepare_list_query(&q, which);
   134    134     cson_object_set(pay,"branches",listV);
   135         -  while((SQLITE_ROW==db_step(&q))){
   136         -    cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
          135  +  while((SQLITE4_ROW==db_step(&q))){
          136  +    cson_value * v = cson_sqlite4_column_to_value(q.pStmt,0);
   137    137       if(v){
   138    138         cson_array_append(list,v);
   139    139       }else if(!sawConversionError){
   140    140         sawConversionError = mprintf("Column-to-json failed @ %s:%d",
   141    141                                      __FILE__,__LINE__);
   142    142       }
   143    143     }
................................................................................
   274    274     /* Cancel all other symbolic tags */
   275    275     db_prepare(&q,
   276    276         "SELECT tagname FROM tagxref, tag"
   277    277         " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
   278    278         "   AND tagtype>0 AND tagname GLOB 'sym-*'"
   279    279         " ORDER BY tagname",
   280    280         rootid);
   281         -  while( db_step(&q)==SQLITE_ROW ){
          281  +  while( db_step(&q)==SQLITE4_ROW ){
   282    282       const char *zTag = db_column_text(&q, 0);
   283    283       blob_appendf(&branch, "T -%F *\n", zTag);
   284    284     }
   285    285     db_finalize(&q);
   286    286     
   287    287     blob_appendf(&branch, "U %F\n", g.zLogin);
   288    288     md5sum_blob(&branch, &mcksum);

Changes to src/json_config.c.

   148    148     if( optSkinBackups ){
   149    149       blob_append(&sql, " OR name GLOB 'skin:*'", -1);
   150    150     }
   151    151     blob_append(&sql," ORDER BY name", -1);
   152    152     db_prepare(&q, blob_str(&sql));
   153    153     blob_reset(&sql);
   154    154     pay = cson_new_object();
   155         -  while( (SQLITE_ROW==db_step(&q)) ){
          155  +  while( (SQLITE4_ROW==db_step(&q)) ){
   156    156       cson_object_set(pay,
   157    157                       db_column_text(&q,0),
   158    158                       json_new_string(db_column_text(&q,1)));
   159    159     }
   160    160     db_finalize(&q);
   161    161     return cson_object_value(pay);
   162    162   }

Changes to src/json_dir.c.

    98     98     if(zDX && (!*zDX || (0==strcmp(zDX,"/")))){
    99     99       zDX = NULL;
   100    100     }
   101    101     zD = zDX ? fossil_strdup(zDX) : NULL;
   102    102     nD = zD ? strlen(zD)+1 : 0;
   103    103     while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; }
   104    104   
   105         -  sqlite3_create_function(g.db, "pathelement", 2, SQLITE_UTF8, 0,
          105  +  sqlite4_create_function(g.db, "pathelement", 2, SQLITE4_UTF8, 0,
   106    106                             pathelementFunc, 0, 0);
   107    107   
   108    108     /* Compute the temporary table "localfiles" containing the names
   109    109     ** of all files and subdirectories in the zD[] directory.  
   110    110     **
   111    111     ** Subdirectory names begin with "/".  This causes them to sort
   112    112     ** first and it also gives us an easy way to distinguish files
................................................................................
   238    238     zPayload = cson_new_object();
   239    239     cson_object_set_s( zPayload, zKeyName,
   240    240                        json_new_string((zD&&*zD) ? zD : "/") );
   241    241     if( zUuid ){
   242    242       cson_object_set( zPayload, "checkin", json_new_string(zUuid) );
   243    243     }
   244    244   
   245         -  while( (SQLITE_ROW==db_step(&q)) ){
          245  +  while( (SQLITE4_ROW==db_step(&q)) ){
   246    246       cson_value * name = NULL;
   247    247       char const * n = db_column_text(&q,0);
   248    248       char const isDir = ('/'==*n);
   249    249       zEntry = cson_new_object();
   250    250       if(!zEntries){
   251    251         zEntries = cson_new_array();
   252    252         cson_object_set( zPayload, "entries", cson_array_value(zEntries) );

Changes to src/json_finfo.c.

   115    115     pay = cson_new_object();
   116    116     cson_object_set(pay, "name", json_new_string(zFilename));
   117    117     if( limit > 0 ){
   118    118       cson_object_set(pay, "limit", json_new_int(limit));
   119    119     }
   120    120     checkins = cson_new_array();
   121    121     cson_object_set(pay, "checkins", cson_array_value(checkins));
   122         -  while( db_step(&q)==SQLITE_ROW ){
          122  +  while( db_step(&q)==SQLITE4_ROW ){
   123    123       cson_object * row = cson_new_object();
   124    124       int const isNew = db_column_int(&q,9);
   125    125       int const isDel = db_column_int(&q,10);
   126    126       cson_array_append( checkins, cson_object_value(row) );
   127    127       cson_object_set(row, "checkin", json_new_string( db_column_text(&q,1) ));
   128    128       cson_object_set(row, "uuid", json_new_string( db_column_text(&q,2) ));
   129    129       /*cson_object_set(row, "parentArtifact", json_new_string( db_column_text(&q,6) ));*/

Changes to src/json_login.c.

   237    237         /* assume we just logged out. */
   238    238         db_prepare(&q, "SELECT login, cap FROM user WHERE login='nobody'");
   239    239     }
   240    240     else{
   241    241         db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d",
   242    242                    g.userUid);
   243    243     }
   244         -  if( db_step(&q)==SQLITE_ROW ){
          244  +  if( db_step(&q)==SQLITE4_ROW ){
   245    245   
   246    246       /* reminder: we don't use g.zLogin because it's 0 for the guest
   247    247          user and the HTML UI appears to currently allow the name to be
   248    248          changed (but doing so would break other code). */
   249    249       char const * str;
   250    250       payload = cson_value_new_object();
   251    251       obj = cson_value_get_object(payload);
   252         -    str = (char const *)sqlite3_column_text(q.pStmt,0);
          252  +    str = (char const *)sqlite4_column_text(q.pStmt,0);
   253    253       if( str ){
   254    254         cson_object_set( obj, "name",
   255    255                          cson_value_new_string(str,strlen(str)) );
   256    256       }
   257         -    str = (char const *)sqlite3_column_text(q.pStmt,1);
          257  +    str = (char const *)sqlite4_column_text(q.pStmt,1);
   258    258       if( str ){
   259    259         cson_object_set( obj, "capabilities",
   260    260                          cson_value_new_string(str,strlen(str)) );
   261    261       }
   262    262       if( g.json.authToken ){
   263    263         cson_object_set( obj, "authToken", g.json.authToken );
   264    264       }

Changes to src/json_query.c.

    65     65     }
    66     66   
    67     67     zFmt = json_find_option_cstr2("format",NULL,"f",3);
    68     68     if(!zFmt) zFmt = "o";
    69     69     db_prepare(&q,"%s", zSql);
    70     70     switch(*zFmt){
    71     71       case 'a':
    72         -      check = cson_sqlite3_stmt_to_json(q.pStmt, &payV, 0);
           72  +      check = cson_sqlite4_stmt_to_json(q.pStmt, &payV, 0);
    73     73         break;
    74     74       case 'o':
    75     75       default:
    76         -      check = cson_sqlite3_stmt_to_json(q.pStmt, &payV, 1);
           76  +      check = cson_sqlite4_stmt_to_json(q.pStmt, &payV, 1);
    77     77     };
    78     78     db_finalize(&q);
    79     79     if(0 != check){
    80     80       json_set_err(FSL_JSON_E_UNKNOWN,
    81     81                    "Conversion to JSON failed with cson code #%d (%s).",
    82     82                    check, cson_rc_string(check));
    83     83       assert(NULL==payV);
    84     84     }
    85     85     return payV;
    86     86   
    87     87   }
    88     88   
    89     89   #endif /* FOSSIL_ENABLE_JSON */

Changes to src/json_report.c.

   106    106                " title AS title,"
   107    107                " cast(strftime('%%s',mtime) as int) as timestamp,"
   108    108                " cols as columns,"
   109    109                " sqlcode as sqlCode"
   110    110                " FROM reportfmt"
   111    111                " WHERE rn=%d",
   112    112                nReport);
   113         -  if( SQLITE_ROW != db_step(&q) ){
          113  +  if( SQLITE4_ROW != db_step(&q) ){
   114    114       db_finalize(&q);
   115    115       json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND,
   116    116                    "Report #%d not found.", nReport);
   117    117       return NULL;
   118    118     }
   119         -  pay = cson_sqlite3_row_to_object(q.pStmt);
          119  +  pay = cson_sqlite4_row_to_object(q.pStmt);
   120    120     db_finalize(&q);
   121    121     return pay;
   122    122   }
   123    123   
   124    124   /*
   125    125   ** Impl of /json/report/list.
   126    126   */
................................................................................
   187    187     if(!zFmt) zFmt = "o";
   188    188     db_prepare(&q,
   189    189                "SELECT sqlcode, "
   190    190                " title"
   191    191                " FROM reportfmt"
   192    192                " WHERE rn=%d",
   193    193                nReport);
   194         -  if(SQLITE_ROW != db_step(&q)){
          194  +  if(SQLITE4_ROW != db_step(&q)){
   195    195       json_set_err(FSL_JSON_E_INVALID_ARGS,
   196    196                    "Report number %d not found.",
   197    197                    nReport);
   198    198       db_finalize(&q);
   199    199       goto error;
   200    200     }
   201    201   
................................................................................
   222    222     if(g.perm.TktFmt){
   223    223       cson_object_set(pay, "sqlcode",
   224    224                       cson_value_new_string(blob_str(&sql),
   225    225                                             (unsigned int)blob_size(&sql)));
   226    226     }
   227    227     blob_reset(&sql);
   228    228   
   229         -  colNames = cson_sqlite3_column_names(q.pStmt);
          229  +  colNames = cson_sqlite4_column_names(q.pStmt);
   230    230     cson_object_set( pay, "columnNames", colNames);
   231    231     for( i = 0 ; ((limit>0) ?(i < limit) : 1)
   232         -         && (SQLITE_ROW == db_step(&q));
          232  +         && (SQLITE4_ROW == db_step(&q));
   233    233          ++i){
   234    234       cson_value * row = ('a'==*zFmt)
   235         -      ? cson_sqlite3_row_to_array(q.pStmt)
   236         -      : cson_sqlite3_row_to_object2(q.pStmt,
          235  +      ? cson_sqlite4_row_to_array(q.pStmt)
          236  +      : cson_sqlite4_row_to_object2(q.pStmt,
   237    237                                       cson_value_get_array(colNames));
   238    238       ;
   239    239       if(row && !tktList){
   240    240         tktList = cson_new_array();
   241    241       }
   242    242       cson_array_append(tktList, row);
   243    243     }

Changes to src/json_tag.c.

   260    260                  " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
   261    261                  "   AND tagxref.tagtype>0"
   262    262                  "   AND blob.rid=tagxref.rid"
   263    263                  "%s LIMIT %d",
   264    264                  zName,
   265    265                  (limit>0)?"":"--", limit
   266    266                  );
   267         -    while( db_step(&q)==SQLITE_ROW ){
          267  +    while( db_step(&q)==SQLITE4_ROW ){
   268    268         if(!listV){
   269    269           listV = cson_value_new_array();
   270    270           list = cson_value_get_array(listV);
   271    271         }
   272         -      cson_array_append(list, cson_sqlite3_column_to_value(q.pStmt,0));
          272  +      cson_array_append(list, cson_sqlite4_column_to_value(q.pStmt,0));
   273    273       }
   274    274       db_finalize(&q);
   275    275     }else{
   276    276       char const * zSqlBase = /*modified from timeline_query_for_tty()*/
   277    277         " SELECT"
   278    278   #if 0
   279    279         "   blob.rid AS rid,"
................................................................................
   385    385                  "SELECT tagname, value FROM tagxref, tag"
   386    386                  " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
   387    387                  "   AND tagtype>%d"
   388    388                  " ORDER BY tagname",
   389    389                  rid,
   390    390                  fRaw ? -1 : 0
   391    391                  );
   392         -    while( SQLITE_ROW == db_step(&q) ){
          392  +    while( SQLITE4_ROW == db_step(&q) ){
   393    393         const char *zName = db_column_text(&q, 0);
   394    394         const char *zValue = db_column_text(&q, 1);
   395    395         if( fRaw==0 ){
   396    396           if( 0!=strncmp(zName, "sym-", 4) ) continue;
   397    397           zName += 4;
   398    398           assert( *zName );
   399    399         }
................................................................................
   443    443         blob_append(&sql, " AND tagname NOT GLOB('tkt-*') ", -1);
   444    444       }
   445    445       blob_append(&sql,
   446    446                   " ORDER BY tagname", -1);
   447    447       db_prepare(&q, blob_buffer(&sql));
   448    448       blob_reset(&sql);
   449    449       cson_object_set(pay, "includeTickets", cson_value_new_bool(fTicket) );
   450         -    while( SQLITE_ROW == db_step(&q) ){
          450  +    while( SQLITE4_ROW == db_step(&q) ){
   451    451         const char *zName = db_column_text(&q, 0);
   452    452         if(NULL==arV){
   453    453           arV = cson_value_new_array();
   454    454           ar = cson_value_get_array(arV);
   455    455           cson_object_set(pay, "tags", arV);
   456    456           tagsVal = arV;
   457    457         }

Changes to src/json_timeline.c.

   301    301              "       blob.size as size"
   302    302              "  FROM mlink, blob"
   303    303              " WHERE mid=%d AND pid!=fid"
   304    304              " AND blob.rid=fid "
   305    305              " ORDER BY name /*sort*/",
   306    306                rid
   307    307                );
   308         -  while( (SQLITE_ROW == db_step(&q)) ){
          308  +  while( (SQLITE4_ROW == db_step(&q)) ){
   309    309       cson_value * rowV = cson_value_new_object();
   310    310       cson_object * row = cson_value_get_object(rowV);
   311    311       int const isNew = db_column_int(&q,0);
   312    312       int const isDel = db_column_int(&q,1);
   313    313       char * zDownload = NULL;
   314    314       if(!rowsV){
   315    315         rowsV = cson_value_new_array();
................................................................................
   461    461                " rid AS rid"
   462    462                " FROM json_timeline"
   463    463                " ORDER BY rowid");
   464    464     listV = cson_value_new_array();
   465    465     list = cson_value_get_array(listV);
   466    466     tmp = listV;
   467    467     SET("timeline");
   468         -  while( (SQLITE_ROW == db_step(&q) )){
          468  +  while( (SQLITE4_ROW == db_step(&q) )){
   469    469       /* convert each row into a JSON object...*/
   470    470       int const rid = db_column_int(&q,0);
   471    471       cson_value * rowV = json_artifact_for_ci(rid, showFiles);
   472    472       cson_object * row = cson_value_get_object(rowV);
   473    473       if(!row){
   474    474         if( !warnRowToJsonFailed ){
   475    475           warnRowToJsonFailed = 1;
................................................................................
   613    613                " FROM json_timeline"
   614    614                " ORDER BY rowid",
   615    615                -1);
   616    616     listV = cson_value_new_array();
   617    617     list = cson_value_get_array(listV);
   618    618     tmp = listV;
   619    619     SET("timeline");
   620         -  while( (SQLITE_ROW == db_step(&q) )){
          620  +  while( (SQLITE4_ROW == db_step(&q) )){
   621    621       /* convert each row into a JSON object...*/
   622    622       int rc;
   623    623       int const rid = db_column_int(&q,0);
   624    624       Manifest * pMan = NULL;
   625    625       cson_value * rowV;
   626    626       cson_object * row;
   627    627       /*printf("rid=%d\n",rid);*/
................................................................................
   633    633            /json/artifact/1292fef05f2472108 returns not-found,
   634    634            probably because we haven't added artifact/ticket
   635    635            yet(?).
   636    636         */
   637    637         continue;
   638    638       }
   639    639   
   640         -    rowV = cson_sqlite3_row_to_object(q.pStmt);
          640  +    rowV = cson_sqlite4_row_to_object(q.pStmt);
   641    641       row = cson_value_get_object(rowV);
   642    642       if(!row){
   643    643         manifest_destroy(pMan);
   644    644         json_warn( FSL_JSON_W_ROW_TO_JSON_FAILED,
   645    645                    "Could not convert at least one timeline result row to JSON." );
   646    646         continue;
   647    647       }

Changes to src/json_user.c.

    87     87                " login AS name,"
    88     88                " cap AS capabilities,"
    89     89                " info AS info,"
    90     90                " mtime AS timestamp"
    91     91                " FROM user"
    92     92                " WHERE login=%Q",
    93     93                zName);
    94         -  if( (SQLITE_ROW == db_step(&q)) ){
    95         -    u = cson_sqlite3_row_to_object(q.pStmt);
           94  +  if( (SQLITE4_ROW == db_step(&q)) ){
           95  +    u = cson_sqlite4_row_to_object(q.pStmt);
    96     96     }
    97     97     db_finalize(&q);
    98     98     return u;  
    99     99   }
   100    100   
   101    101   /*
   102    102   ** Identical to json_load_user_by_name(), but expects a user ID.  Returns
................................................................................
   109    109                " login AS name,"
   110    110                " cap AS capabilities,"
   111    111                " info AS info,"
   112    112                " mtime AS timestamp"
   113    113                " FROM user"
   114    114                " WHERE uid=%d",
   115    115                uid);
   116         -  if( (SQLITE_ROW == db_step(&q)) ){
   117         -    u = cson_sqlite3_row_to_object(q.pStmt);
          116  +  if( (SQLITE4_ROW == db_step(&q)) ){
          117  +    u = cson_sqlite4_row_to_object(q.pStmt);
   118    118     }
   119    119     db_finalize(&q);
   120    120     return u;  
   121    121   }
   122    122   
   123    123   
   124    124   /*

Changes to src/json_wiki.c.

   449    449       }
   450    450     }
   451    451     blob_append(&sql," ORDER BY lower(name)", -1);
   452    452     db_prepare(&q,"%s", blob_str(&sql));
   453    453     blob_reset(&sql);
   454    454     listV = cson_value_new_array();
   455    455     list = cson_value_get_array(listV);
   456         -  while( SQLITE_ROW == db_step(&q) ){
          456  +  while( SQLITE4_ROW == db_step(&q) ){
   457    457       cson_value * v;
   458    458       if( verbose ){
   459    459         char const * name = db_column_text(&q,0);
   460    460         v = json_get_wiki_page_by_name(name,0);
   461    461       }else{
   462         -      v = cson_sqlite3_column_to_value(q.pStmt,0);
          462  +      v = cson_sqlite4_column_to_value(q.pStmt,0);
   463    463       }
   464    464       if(!v){
   465    465         json_set_err(FSL_JSON_E_UNKNOWN,
   466    466                      "Could not convert wiki name column to JSON.");
   467    467         goto error;
   468    468       }else if( 0 != cson_array_append( list, v ) ){
   469    469         cson_value_free(v);

Changes to src/leaf.c.

    63     63       @    AND coalesce((SELECT value FROM tagxref
    64     64       @                   WHERE tagid=%d AND rid=plink.pid), 'trunk')
    65     65       @       =coalesce((SELECT value FROM tagxref
    66     66       @                   WHERE tagid=%d AND rid=plink.cid), 'trunk')
    67     67     ;
    68     68     db_static_prepare(&q, zSql, TAG_BRANCH, TAG_BRANCH);
    69     69     db_bind_int(&q, ":pid", pid);
    70         -  if( db_step(&q)==SQLITE_ROW ){
           70  +  if( db_step(&q)==SQLITE4_ROW ){
    71     71       nNonBranch = db_column_int(&q, 0);
    72     72     }
    73     73     db_reset(&q);
    74     74     return nNonBranch;
    75     75   }
    76     76   
    77     77   
................................................................................
   119    119          " == coalesce((SELECT value FROM tagxref"
   120    120                       " WHERE tagid=%d AND rid=plink.cid),'trunk');",
   121    121       TAG_BRANCH, TAG_BRANCH
   122    122     );
   123    123     db_bind_int(&checkIfLeaf, ":rid", rid);
   124    124     rc = db_step(&checkIfLeaf);
   125    125     db_reset(&checkIfLeaf);
   126         -  if( rc==SQLITE_ROW ){
          126  +  if( rc==SQLITE4_ROW ){
   127    127       db_static_prepare(&removeLeaf, "DELETE FROM leaf WHERE rid=:rid");
   128    128       db_bind_int(&removeLeaf, ":rid", rid);
   129    129       db_step(&removeLeaf);
   130    130       db_reset(&removeLeaf);
   131    131     }else{
   132    132       db_static_prepare(&addLeaf, "INSERT OR IGNORE INTO leaf VALUES(:rid)");
   133    133       db_bind_int(&addLeaf, ":rid", rid);
................................................................................
   161    161     static Stmt parentsOf;
   162    162   
   163    163     db_static_prepare(&parentsOf, 
   164    164        "SELECT pid FROM plink WHERE cid=:rid AND pid>0"
   165    165     );
   166    166     db_bind_int(&parentsOf, ":rid", rid);
   167    167     bag_insert(&needToCheck, rid);
   168         -  while( db_step(&parentsOf)==SQLITE_ROW ){
          168  +  while( db_step(&parentsOf)==SQLITE4_ROW ){
   169    169       bag_insert(&needToCheck, db_column_int(&parentsOf, 0));
   170    170     }
   171    171     db_reset(&parentsOf);
   172    172   }
   173    173   
   174    174   /*
   175    175   ** Do all pending leaf checks.

Changes to src/login.c.

   424    424   }
   425    425   
   426    426   /*
   427    427   ** SQL function for constant time comparison of two values.
   428    428   ** Sets result to 0 if two values are equal.
   429    429   */
   430    430   static void constant_time_cmp_function(
   431         - sqlite3_context *context,
          431  + sqlite4_context *context,
   432    432    int argc,
   433         - sqlite3_value **argv
          433  + sqlite4_value **argv
   434    434   ){
   435    435     const unsigned char *buf1, *buf2;
   436    436     int len, i;
   437    437     unsigned char rc = 0;
   438    438   
   439    439     assert( argc==2 );
   440         -  len = sqlite3_value_bytes(argv[0]);
   441         -  if( len==0 || len!=sqlite3_value_bytes(argv[1]) ){
          440  +  len = sqlite4_value_bytes(argv[0]);
          441  +  if( len==0 || len!=sqlite4_value_bytes(argv[1]) ){
   442    442       rc = 1;
   443    443     }else{
   444         -    buf1 = sqlite3_value_text(argv[0]);
   445         -    buf2 = sqlite3_value_text(argv[1]);
          444  +    buf1 = sqlite4_value_text(argv[0]);
          445  +    buf2 = sqlite4_value_text(argv[1]);
   446    446       for( i=0; i<len; i++ ){
   447    447         rc = rc | (buf1[i] ^ buf2[i]);
   448    448       }
   449    449     }
   450         -  sqlite3_result_int(context, rc);
          450  +  sqlite4_result_int(context, rc);
   451    451   }
   452    452   
   453    453   /*
   454    454   ** WEBPAGE: login
   455    455   ** WEBPAGE: logout
   456    456   ** WEBPAGE: my
   457    457   **
................................................................................
   470    470     int anonFlag;
   471    471     char *zErrMsg = "";
   472    472     int uid;                     /* User id loged in user */
   473    473     char *zSha1Pw;
   474    474     const char *zIpAddr;         /* IP address of requestor */
   475    475   
   476    476     login_check_credentials();
   477         -  sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
          477  +  sqlite4_create_function(g.db, "constant_time_cmp", 2, SQLITE4_UTF8, 0,
   478    478   		  constant_time_cmp_function, 0, 0);
   479    479     zUsername = P("u");
   480    480     zPasswd = P("p");
   481    481     anonFlag = P("anon")!=0;
   482    482     if( P("out")!=0 ){
   483    483       login_clear_login_data();
   484    484       redirect_to_g();
................................................................................
   680    680   */
   681    681   static int login_transfer_credentials(
   682    682     const char *zLogin,          /* Login we are looking for */
   683    683     const char *zCode,           /* Project code of peer repository */
   684    684     const char *zHash,           /* HASH from login cookie HASH/CODE/LOGIN */
   685    685     const char *zRemoteAddr      /* Request comes from here */
   686    686   ){
   687         -  sqlite3 *pOther = 0;         /* The other repository */
   688         -  sqlite3_stmt *pStmt;         /* Query against the other repository */
          687  +  sqlite4 *pOther = 0;         /* The other repository */
          688  +  sqlite4_stmt *pStmt;         /* Query against the other repository */
   689    689     char *zSQL;                  /* SQL of the query against other repo */
   690    690     char *zOtherRepo;            /* Filename of the other repository */
   691    691     int rc;                      /* Result code from SQLite library functions */
   692    692     int nXfer = 0;               /* Number of credentials transferred */
   693    693   
   694    694     zOtherRepo = db_text(0, 
   695    695          "SELECT value FROM config WHERE name='peer-repo-%q'",
   696    696          zCode
   697    697     );
   698    698     if( zOtherRepo==0 ) return 0;  /* No such peer repository */
   699    699   
   700         -  rc = sqlite3_open(zOtherRepo, &pOther);
   701         -  if( rc==SQLITE_OK ){
   702         -    sqlite3_create_function(pOther,"now",0,SQLITE_ANY,0,db_now_function,0,0);
   703         -    sqlite3_create_function(pOther, "constant_time_cmp", 2, SQLITE_UTF8, 0,
          700  +  rc = sqlite4_open(0, zOtherRepo, &pOther, SQLITE4_OPEN_READWRITE);
          701  +  if( rc==SQLITE4_OK ){
          702  +    sqlite4_create_function(pOther,"now",0,SQLITE4_ANY,0,db_now_function,0,0);
          703  +    sqlite4_create_function(pOther, "constant_time_cmp", 2, SQLITE4_UTF8, 0,
   704    704   		  constant_time_cmp_function, 0, 0);
   705         -    sqlite3_busy_timeout(pOther, 5000);
   706    705       zSQL = mprintf(
   707    706         "SELECT cexpire FROM user"
   708    707         " WHERE login=%Q"
   709    708         "   AND ipaddr=%Q"
   710    709         "   AND length(cap)>0"
   711    710         "   AND length(pw)>0"
   712    711         "   AND cexpire>julianday('now')"
   713    712         "   AND constant_time_cmp(cookie,%Q)=0",
   714    713         zLogin, zRemoteAddr, zHash
   715    714       );
   716    715       pStmt = 0;
   717         -    rc = sqlite3_prepare_v2(pOther, zSQL, -1, &pStmt, 0);
   718         -    if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
          716  +    rc = sqlite4_prepare(pOther, zSQL, -1, &pStmt, 0);
          717  +    if( rc==SQLITE4_OK && sqlite4_step(pStmt)==SQLITE4_ROW ){
   719    718         db_multi_exec(
   720    719           "UPDATE user SET cookie=%Q, ipaddr=%Q, cexpire=%.17g"
   721    720           " WHERE login=%Q",
   722    721           zHash, zRemoteAddr,
   723         -        sqlite3_column_double(pStmt, 0), zLogin
          722  +        sqlite4_column_double(pStmt, 0), zLogin
   724    723         );
   725    724         nXfer++;
   726    725       }
   727         -    sqlite3_finalize(pStmt);
          726  +    sqlite4_finalize(pStmt);
   728    727     }
   729         -  sqlite3_close(pOther);
          728  +  sqlite4_close(pOther);
   730    729     fossil_free(zOtherRepo);
   731    730     return nXfer;
   732    731   }
   733    732   
   734    733   /*
   735    734   ** Lookup the uid for a non-built-in user with zLogin and zCookie and
   736    735   ** zRemoteAddr.  Return 0 if not found.
................................................................................
   777    776     char *zRemoteAddr;            /* Abbreviated IP address of the requestor */
   778    777     const char *zCap = 0;         /* Capability string */
   779    778     const char *zPublicPages = 0; /* GLOB patterns of public pages */
   780    779   
   781    780     /* Only run this check once.  */
   782    781     if( g.userUid!=0 ) return;
   783    782   
   784         -  sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
          783  +  sqlite4_create_function(g.db, "constant_time_cmp", 2, SQLITE4_UTF8, 0,
   785    784   		  constant_time_cmp_function, 0, 0);
   786    785   
   787    786     /* If the HTTP connection is coming over 127.0.0.1 and if
   788    787     ** local login is disabled and if we are using HTTP and not HTTPS, 
   789    788     ** then there is no need to check user credentials.
   790    789     **
   791    790     ** This feature allows the "fossil ui" command to give the user
................................................................................
   797    796      && db_get_int("localauth",0)==0
   798    797      && P("HTTPS")==0
   799    798     ){
   800    799       uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'");
   801    800       g.zLogin = db_text("?", "SELECT login FROM user WHERE uid=%d", uid);
   802    801       zCap = "sx";
   803    802       g.noPswd = 1;
   804         -    sqlite3_snprintf(sizeof(g.zCsrfToken), g.zCsrfToken, "localhost");
          803  +    sqlite4_snprintf(g.zCsrfToken, sizeof(g.zCsrfToken), "localhost");
   805    804     }
   806    805   
   807    806     /* Check the login cookie to see if it matches a known valid user.
   808    807     */
   809    808     if( uid==0 && (zCookie = P(login_cookie_name()))!=0 ){
   810    809       /* Parse the cookie value up into HASH/ARG/USER */
   811    810       char *zHash = fossil_strdup(zCookie);
................................................................................
   853    852         */
   854    853         uid = login_find_user(zUser, zHash, zRemoteAddr);
   855    854         if( uid==0 && login_transfer_credentials(zUser,zArg,zHash,zRemoteAddr) ){
   856    855           uid = login_find_user(zUser, zHash, zRemoteAddr);
   857    856           if( uid ) record_login_attempt(zUser, zIpAddr, 1);
   858    857         }
   859    858       }
   860         -    sqlite3_snprintf(sizeof(g.zCsrfToken), g.zCsrfToken, "%.10s", zHash);
          859  +    sqlite4_snprintf(g.zCsrfToken, sizeof(g.zCsrfToken), "%.10s", zHash);
   861    860     }
   862    861   
   863    862     /* If no user found and the REMOTE_USER environment variable is set,
   864    863     ** then accept the value of REMOTE_USER as the user.
   865    864     */
   866    865     if( uid==0 ){
   867    866       const char *zRemoteUser = P("REMOTE_USER");
................................................................................
   875    874     if( uid==0 ){
   876    875       uid = db_int(0, "SELECT uid FROM user WHERE login='nobody'");
   877    876       if( uid==0 ){
   878    877         /* If there is no user "nobody", then make one up - with no privileges */
   879    878         uid = -1;
   880    879         zCap = "";
   881    880       }
   882         -    sqlite3_snprintf(sizeof(g.zCsrfToken), g.zCsrfToken, "none");
          881  +    sqlite4_snprintf(g.zCsrfToken, sizeof(g.zCsrfToken), "none");
   883    882     }
   884    883   
   885    884     /* At this point, we know that uid!=0.  Find the privileges associated
   886    885     ** with user uid.
   887    886     */
   888    887     assert( uid!=0 );
   889    888     if( zCap==0 ){
   890    889       Stmt s;
   891    890       db_prepare(&s, "SELECT login, cap FROM user WHERE uid=%d", uid);
   892         -    if( db_step(&s)==SQLITE_ROW ){
          891  +    if( db_step(&s)==SQLITE4_ROW ){
   893    892         g.zLogin = db_column_malloc(&s, 0);
   894    893         zCap = db_column_malloc(&s, 1);
   895    894       }
   896    895       db_finalize(&s);
   897    896       if( zCap==0 ){
   898    897         zCap = "";
   899    898       }
................................................................................
  1313   1312   */
  1314   1313   int login_group_sql(
  1315   1314     const char *zSql,        /* The SQL to run */
  1316   1315     const char *zPrefix,     /* Prefix to each error message */
  1317   1316     const char *zSuffix,     /* Suffix to each error message */
  1318   1317     char **pzErrorMsg        /* Write error message here, if not NULL */
  1319   1318   ){
  1320         -  sqlite3 *pPeer;          /* Connection to another database */
         1319  +  sqlite4 *pPeer;          /* Connection to another database */
  1321   1320     int nErr = 0;            /* Number of errors seen so far */
  1322   1321     int rc;                  /* Result code from subroutine calls */
  1323   1322     char *zErr;              /* SQLite error text */
  1324   1323     char *zSelfCode;         /* Project code for ourself */
  1325   1324     Blob err;                /* Accumulate errors here */
  1326   1325     Stmt q;                  /* Query of all peer-* entries in CONFIG */
  1327   1326   
................................................................................
  1333   1332     db_prepare(&q, 
  1334   1333       "SELECT name, value FROM config"
  1335   1334       " WHERE name GLOB 'peer-repo-*'"
  1336   1335       "   AND name <> 'peer-repo-%q'"
  1337   1336       " ORDER BY +value",
  1338   1337       zSelfCode
  1339   1338     );
  1340         -  while( db_step(&q)==SQLITE_ROW ){
         1339  +  while( db_step(&q)==SQLITE4_ROW ){
  1341   1340       const char *zRepoName = db_column_text(&q, 1);
  1342   1341       if( file_size(zRepoName)<0 ){
  1343   1342         /* Silently remove non-existant repositories from the login group. */
  1344   1343         const char *zLabel = db_column_text(&q, 0);
  1345   1344         db_multi_exec(
  1346   1345            "DELETE FROM config WHERE name GLOB 'peer-*-%q'",
  1347   1346            &zLabel[10]
  1348   1347         );
  1349   1348         continue;
  1350   1349       }
  1351         -    rc = sqlite3_open_v2(zRepoName, &pPeer, SQLITE_OPEN_READWRITE, 0);
  1352         -    if( rc!=SQLITE_OK ){
         1350  +    rc = sqlite4_open(0, zRepoName, &pPeer, SQLITE4_OPEN_READWRITE);
         1351  +    if( rc!=SQLITE4_OK ){
  1353   1352         blob_appendf(&err, "%s%s: %s%s", zPrefix, zRepoName,
  1354         -                   sqlite3_errmsg(pPeer), zSuffix);
         1353  +                   sqlite4_errmsg(pPeer), zSuffix);
  1355   1354         nErr++;
  1356         -      sqlite3_close(pPeer);
         1355  +      sqlite4_close(pPeer);
  1357   1356         continue;
  1358   1357       }
  1359         -    sqlite3_create_function(pPeer, "shared_secret", 3, SQLITE_UTF8,
         1358  +    sqlite4_create_function(pPeer, "shared_secret", 3, SQLITE4_UTF8,
  1360   1359                               0, sha1_shared_secret_sql_function, 0, 0);
  1361         -    sqlite3_create_function(pPeer, "now", 0,SQLITE_ANY,0,db_now_function,0,0);
  1362         -    sqlite3_busy_timeout(pPeer, 5000);
         1360  +    sqlite4_create_function(pPeer, "now", 0,SQLITE4_ANY,0,db_now_function,0,0);
  1363   1361       zErr = 0;
  1364         -    rc = sqlite3_exec(pPeer, zSql, 0, 0, &zErr);
         1362  +    rc = sqlite4_exec(pPeer, zSql, 0, 0, &zErr);
  1365   1363       if( zErr ){
  1366   1364         blob_appendf(&err, "%s%s: %s%s", zPrefix, zRepoName, zErr, zSuffix);
  1367         -      sqlite3_free(zErr);
         1365  +      sqlite4_free(0, zErr);
  1368   1366         nErr++;
  1369         -    }else if( rc!=SQLITE_OK ){
         1367  +    }else if( rc!=SQLITE4_OK ){
  1370   1368         blob_appendf(&err, "%s%s: %s%s", zPrefix, zRepoName,
  1371         -                   sqlite3_errmsg(pPeer), zSuffix);
         1369  +                   sqlite4_errmsg(pPeer), zSuffix);
  1372   1370         nErr++;
  1373   1371       }
  1374         -    sqlite3_close(pPeer);
         1372  +    sqlite4_close(pPeer);
  1375   1373     }
  1376   1374     db_finalize(&q);
  1377   1375     if( pzErrorMsg && blob_size(&err)>0 ){
  1378   1376       *pzErrorMsg = fossil_strdup(blob_str(&err));
  1379   1377     }
  1380   1378     blob_reset(&err);
  1381   1379     fossil_free(zSelfCode);
................................................................................
  1391   1389     const char *zRepo,         /* Repository file in the login group */
  1392   1390     const char *zLogin,        /* Login name for the other repo */
  1393   1391     const char *zPassword,     /* Password to prove we are authorized to join */
  1394   1392     const char *zNewName,      /* Name of new login group if making a new one */
  1395   1393     char **pzErrMsg            /* Leave an error message here */
  1396   1394   ){
  1397   1395     Blob fullName;             /* Blob for finding full pathnames */
  1398         -  sqlite3 *pOther;           /* The other repository */
  1399         -  int rc;                    /* Return code from sqlite3 functions */
         1396  +  sqlite4 *pOther;           /* The other repository */
         1397  +  int rc;                    /* Return code from sqlite4 functions */
  1400   1398     char *zOtherProjCode;      /* Project code for pOther */
  1401   1399     char *zPwHash;             /* Password hash on pOther */
  1402   1400     char *zSelfRepo;           /* Name of our repository */
  1403   1401     char *zSelfLabel;          /* Project-name for our repository */
  1404   1402     char *zSelfProjCode;       /* Our project-code */
  1405   1403     char *zSql;                /* SQL to run on all peers */
  1406   1404     const char *zSelf;         /* The ATTACH name of our repository */
................................................................................
  1431   1429     }
  1432   1430   
  1433   1431     /* Make sure the other repository is a valid Fossil database */
  1434   1432     if( file_size(zRepo)<0 ){
  1435   1433       *pzErrMsg = mprintf("repository file \"%s\" does not exist", zRepo);
  1436   1434       return;
  1437   1435     }
  1438         -  rc = sqlite3_open(zRepo, &pOther);
  1439         -  if( rc!=SQLITE_OK ){
  1440         -    *pzErrMsg = mprintf(sqlite3_errmsg(pOther));
         1436  +  rc = sqlite4_open(0, zRepo, &pOther, SQLITE4_OPEN_READWRITE);
         1437  +  if( rc!=SQLITE4_OK ){
         1438  +    *pzErrMsg = mprintf(sqlite4_errmsg(pOther));
  1441   1439     }else{
  1442         -    rc = sqlite3_exec(pOther, "SELECT count(*) FROM user", 0, 0, pzErrMsg);
         1440  +    rc = sqlite4_exec(pOther, "SELECT count(*) FROM user", 0, 0, pzErrMsg);
  1443   1441     }
  1444         -  sqlite3_close(pOther);
         1442  +  sqlite4_close(pOther);
  1445   1443     if( rc ) return;
  1446   1444   
  1447   1445     /* Attach the other respository.  Make sure the username/password is
  1448   1446     ** valid and has Setup permission.
  1449   1447     */
  1450   1448     db_multi_exec("ATTACH %Q AS other", zRepo);
  1451   1449     zOtherProjCode = db_text("x", "SELECT value FROM other.config"

Changes to src/main.c.

    94     94   
    95     95   /*
    96     96   ** All global variables are in this structure.
    97     97   */
    98     98   struct Global {
    99     99     int argc; char **argv;  /* Command-line arguments to the program */
   100    100     int isConst;            /* True if the output is unchanging */
   101         -  sqlite3 *db;            /* The connection to the databases */
   102         -  sqlite3 *dbConfig;      /* Separate connection for global_config table */
          101  +  sqlite4 *db;            /* The connection to the databases */
          102  +  sqlite4 *dbConfig;      /* Separate connection for global_config table */
   103    103     int useAttach;          /* True if global_config is attached to repository */
   104    104     int configOpen;         /* True if the config database is open */
   105         -  sqlite3_int64 now;      /* Seconds since 1970 */
          105  +  sqlite4_int64 now;      /* Seconds since 1970 */
   106    106     int repositoryOpen;     /* True if the main repository database is open */
   107    107     char *zRepositoryName;  /* Name of the repository database */
   108    108     const char *zMainDbType;/* "configdb", "localdb", or "repository" */
   109    109     const char *zHome;      /* Name of user home directory */
   110    110     int localOpen;          /* True if the local database is open */
   111    111     char *zLocalRoot;       /* The directory holding the  local database */
   112    112     int minPrefix;          /* Number of digits needed for a distinct UUID */
................................................................................
   416    416   
   417    417   #ifdef FOSSIL_ENABLE_TCL
   418    418     g.tcl.argc = argc;
   419    419     g.tcl.argv = argv;
   420    420     g.tcl.interp = 0;
   421    421   #endif
   422    422   
   423         -  sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
          423  +  sqlite4_env_config(0, SQLITE4_ENVCONFIG_LOG, fossil_sqlite_log, 0);
   424    424     memset(&g, 0, sizeof(g));
   425    425     g.now = time(0);
   426    426     g.argc = argc;
   427    427     g.argv = argv;
   428    428   #ifdef FOSSIL_ENABLE_JSON
   429    429   #if defined(NDEBUG)
   430    430     g.json.errorDetailParanoia = 2 /* FIXME: make configurable
................................................................................
   728    728   
   729    729   /*
   730    730   ** Return a name for an SQLite error code
   731    731   */
   732    732   static const char *sqlite_error_code_name(int iCode){
   733    733     static char zCode[30];
   734    734     switch( iCode & 0xff ){
   735         -    case SQLITE_OK:         return "SQLITE_OK";
   736         -    case SQLITE_ERROR:      return "SQLITE_ERROR";
   737         -    case SQLITE_PERM:       return "SQLITE_PERM";
   738         -    case SQLITE_ABORT:      return "SQLITE_ABORT";
   739         -    case SQLITE_BUSY:       return "SQLITE_BUSY";
   740         -    case SQLITE_NOMEM:      return "SQLITE_NOMEM";
   741         -    case SQLITE_READONLY:   return "SQLITE_READONLY";
   742         -    case SQLITE_INTERRUPT:  return "SQLITE_INTERRUPT";
   743         -    case SQLITE_IOERR:      return "SQLITE_IOERR";
   744         -    case SQLITE_CORRUPT:    return "SQLITE_CORRUPT";
   745         -    case SQLITE_FULL:       return "SQLITE_FULL";
   746         -    case SQLITE_CANTOPEN:   return "SQLITE_CANTOPEN";
   747         -    case SQLITE_PROTOCOL:   return "SQLITE_PROTOCOL";
   748         -    case SQLITE_EMPTY:      return "SQLITE_EMPTY";
   749         -    case SQLITE_SCHEMA:     return "SQLITE_SCHEMA";
   750         -    case SQLITE_CONSTRAINT: return "SQLITE_CONSTRAINT";
   751         -    case SQLITE_MISMATCH:   return "SQLITE_MISMATCH";
   752         -    case SQLITE_MISUSE:     return "SQLITE_MISUSE";
   753         -    case SQLITE_NOLFS:      return "SQLITE_NOLFS";
   754         -    case SQLITE_FORMAT:     return "SQLITE_FORMAT";
   755         -    case SQLITE_RANGE:      return "SQLITE_RANGE";
   756         -    case SQLITE_NOTADB:     return "SQLITE_NOTADB";
          735  +    case SQLITE4_OK:         return "SQLITE4_OK";
          736  +    case SQLITE4_ERROR:      return "SQLITE4_ERROR";
          737  +    case SQLITE4_PERM:       return "SQLITE4_PERM";
          738  +    case SQLITE4_ABORT:      return "SQLITE4_ABORT";
          739  +    case SQLITE4_BUSY:       return "SQLITE4_BUSY";
          740  +    case SQLITE4_NOMEM:      return "SQLITE4_NOMEM";
          741  +    case SQLITE4_READONLY:   return "SQLITE4_READONLY";
          742  +    case SQLITE4_INTERRUPT:  return "SQLITE4_INTERRUPT";
          743  +    case SQLITE4_IOERR:      return "SQLITE4_IOERR";
          744  +    case SQLITE4_CORRUPT:    return "SQLITE4_CORRUPT";
          745  +    case SQLITE4_FULL:       return "SQLITE4_FULL";
          746  +    case SQLITE4_CANTOPEN:   return "SQLITE4_CANTOPEN";
          747  +    case SQLITE4_PROTOCOL:   return "SQLITE4_PROTOCOL";
          748  +    case SQLITE4_EMPTY:      return "SQLITE4_EMPTY";
          749  +    case SQLITE4_SCHEMA:     return "SQLITE4_SCHEMA";
          750  +    case SQLITE4_CONSTRAINT: return "SQLITE4_CONSTRAINT";
          751  +    case SQLITE4_MISMATCH:   return "SQLITE4_MISMATCH";
          752  +    case SQLITE4_MISUSE:     return "SQLITE4_MISUSE";
          753  +    case SQLITE4_NOLFS:      return "SQLITE4_NOLFS";
          754  +    case SQLITE4_FORMAT:     return "SQLITE4_FORMAT";
          755  +    case SQLITE4_RANGE:      return "SQLITE4_RANGE";
          756  +    case SQLITE4_NOTADB:     return "SQLITE4_NOTADB";
   757    757       default: {
   758         -      sqlite3_snprintf(sizeof(zCode),zCode,"error code %d",iCode);
          758  +      sqlite4_snprintf(zCode, sizeof(zCode), "error code %d",iCode);
   759    759       }
   760    760     }
   761    761     return zCode;
   762    762   }
   763    763   
   764    764   /* Error logs from SQLite */
   765    765   void fossil_sqlite_log(void *notUsed, int iCode, const char *zErrmsg){

Changes to src/main.mk.

   306    306    $(OBJDIR)/wiki.o \
   307    307    $(OBJDIR)/wikiformat.o \
   308    308    $(OBJDIR)/winhttp.o \
   309    309    $(OBJDIR)/xfer.o \
   310    310    $(OBJDIR)/xfersetup.o \
   311    311    $(OBJDIR)/zip.o
   312    312   
   313         -APPNAME = fossil$(E)
          313  +APPNAME = fossil4$(E)
   314    314   
   315    315   
   316    316   
   317    317   all:	$(OBJDIR) $(APPNAME)
   318    318   
   319    319   install:	$(APPNAME)
   320    320   	mv $(APPNAME) $(INSTALLDIR)
................................................................................
   341    341   	$(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME)
   342    342   
   343    343   $(OBJDIR)/VERSION.h:	$(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
   344    344   	$(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid  $(SRCDIR)/../manifest  $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
   345    345   
   346    346   # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
   347    347   # to 1. If it is set to 1, then there is no need to build or link
   348         -# the sqlite3.o object. Instead, the system sqlite will be linked
   349         -# using -lsqlite3.
          348  +# the sqlite4.o object. Instead, the system sqlite will be linked
          349  +# using -lsqlite4.
   350    350   SQLITE3_OBJ.1 = 
   351         -SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
          351  +SQLITE3_OBJ.0 = $(OBJDIR)/sqlite4.o
   352    352   SQLITE3_OBJ.  = $(SQLITE3_OBJ.0)
   353    353   
   354    354   # The FOSSIL_ENABLE_TCL variable may be undefined, set to 0, or set to 1.
   355    355   # If it is set to 1, then we need to build the Tcl integration code and
   356    356   # link to the Tcl library.
   357    357   TCL_OBJ.0 = 
   358    358   TCL_OBJ.1 = $(OBJDIR)/th_tcl.o
................................................................................
   372    372   clean:	
   373    373   	rm -rf $(OBJDIR)/* $(APPNAME)
   374    374   
   375    375   
   376    376   $(OBJDIR)/page_index.h: $(TRANS_SRC) $(OBJDIR)/mkindex
   377    377   	$(OBJDIR)/mkindex $(TRANS_SRC) >$@
   378    378   $(OBJDIR)/headers:	$(OBJDIR)/page_index.h $(OBJDIR)/makeheaders $(OBJDIR)/VERSION.h
   379         -	$(OBJDIR)/makeheaders  $(OBJDIR)/add_.c:$(OBJDIR)/add.h $(OBJDIR)/allrepo_.c:$(OBJDIR)/allrepo.h $(OBJDIR)/attach_.c:$(OBJDIR)/attach.h $(OBJDIR)/bag_.c:$(OBJDIR)/bag.h $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h $(OBJDIR)/clearsign_.c:$(OBJDIR)/clearsign.h $(OBJDIR)/clone_.c:$(OBJDIR)/clone.h $(OBJDIR)/comformat_.c:$(OBJDIR)/comformat.h $(OBJDIR)/configure_.c:$(OBJDIR)/configure.h $(OBJDIR)/content_.c:$(OBJDIR)/content.h $(OBJDIR)/db_.c:$(OBJDIR)/db.h $(OBJDIR)/delta_.c:$(OBJDIR)/delta.h $(OBJDIR)/deltacmd_.c:$(OBJDIR)/deltacmd.h $(OBJDIR)/descendants_.c:$(OBJDIR)/descendants.h $(OBJDIR)/diff_.c:$(OBJDIR)/diff.h $(OBJDIR)/diffcmd_.c:$(OBJDIR)/diffcmd.h $(OBJDIR)/doc_.c:$(OBJDIR)/doc.h $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h $(OBJDIR)/event_.c:$(OBJDIR)/event.h $(OBJDIR)/export_.c:$(OBJDIR)/export.h $(OBJDIR)/file_.c:$(OBJDIR)/file.h $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h $(OBJDIR)/http_.c:$(OBJDIR)/http.h $(OBJDIR)/http_socket_.c:$(OBJDIR)/http_socket.h $(OBJDIR)/http_ssl_.c:$(OBJDIR)/http_ssl.h $(OBJDIR)/http_transport_.c:$(OBJDIR)/http_transport.h $(OBJDIR)/import_.c:$(OBJDIR)/import.h $(OBJDIR)/info_.c:$(OBJDIR)/info.h $(OBJDIR)/json_.c:$(OBJDIR)/json.h $(OBJDIR)/json_artifact_.c:$(OBJDIR)/json_artifact.h $(OBJDIR)/json_branch_.c:$(OBJDIR)/json_branch.h $(OBJDIR)/json_config_.c:$(OBJDIR)/json_config.h $(OBJDIR)/json_diff_.c:$(OBJDIR)/json_diff.h $(OBJDIR)/json_dir_.c:$(OBJDIR)/json_dir.h $(OBJDIR)/json_finfo_.c:$(OBJDIR)/json_finfo.h $(OBJDIR)/json_login_.c:$(OBJDIR)/json_login.h $(OBJDIR)/json_query_.c:$(OBJDIR)/json_query.h $(OBJDIR)/json_report_.c:$(OBJDIR)/json_report.h $(OBJDIR)/json_tag_.c:$(OBJDIR)/json_tag.h $(OBJDIR)/json_timeline_.c:$(OBJDIR)/json_timeline.h $(OBJDIR)/json_user_.c:$(OBJDIR)/json_user.h $(OBJDIR)/json_wiki_.c:$(OBJDIR)/json_wiki.h $(OBJDIR)/leaf_.c:$(OBJDIR)/leaf.h $(OBJDIR)/login_.c:$(OBJDIR)/login.h $(OBJDIR)/main_.c:$(OBJDIR)/main.h $(OBJDIR)/manifest_.c:$(OBJDIR)/manifest.h $(OBJDIR)/md5_.c:$(OBJDIR)/md5.h $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h $(OBJDIR)/name_.c:$(OBJDIR)/name.h $(OBJDIR)/path_.c:$(OBJDIR)/path.h $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h $(OBJDIR)/report_.c:$(OBJDIR)/report.h $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h $(OBJDIR)/search_.c:$(OBJDIR)/search.h $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h $(OBJDIR)/style_.c:$(OBJDIR)/style.h $(OBJDIR)/sync_.c:$(OBJDIR)/sync.h $(OBJDIR)/tag_.c:$(OBJDIR)/tag.h $(OBJDIR)/tar_.c:$(OBJDIR)/tar.h $(OBJDIR)/th_main_.c:$(OBJDIR)/th_main.h $(OBJDIR)/timeline_.c:$(OBJDIR)/timeline.h $(OBJDIR)/tkt_.c:$(OBJDIR)/tkt.h $(OBJDIR)/tktsetup_.c:$(OBJDIR)/tktsetup.h $(OBJDIR)/undo_.c:$(OBJDIR)/undo.h $(OBJDIR)/update_.c:$(OBJDIR)/update.h $(OBJDIR)/url_.c:$(OBJDIR)/url.h $(OBJDIR)/user_.c:$(OBJDIR)/user.h $(OBJDIR)/verify_.c:$(OBJDIR)/verify.h $(OBJDIR)/vfile_.c:$(OBJDIR)/vfile.h $(OBJDIR)/wiki_.c:$(OBJDIR)/wiki.h $(OBJDIR)/wikiformat_.c:$(OBJDIR)/wikiformat.h $(OBJDIR)/winhttp_.c:$(OBJDIR)/winhttp.h $(OBJDIR)/xfer_.c:$(OBJDIR)/xfer.h $(OBJDIR)/xfersetup_.c:$(OBJDIR)/xfersetup.h $(OBJDIR)/zip_.c:$(OBJDIR)/zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h $(OBJDIR)/VERSION.h
          379  +	$(OBJDIR)/makeheaders  $(OBJDIR)/add_.c:$(OBJDIR)/add.h $(OBJDIR)/allrepo_.c:$(OBJDIR)/allrepo.h $(OBJDIR)/attach_.c:$(OBJDIR)/attach.h $(OBJDIR)/bag_.c:$(OBJDIR)/bag.h $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h $(OBJDIR)/clearsign_.c:$(OBJDIR)/clearsign.h $(OBJDIR)/clone_.c:$(OBJDIR)/clone.h $(OBJDIR)/comformat_.c:$(OBJDIR)/comformat.h $(OBJDIR)/configure_.c:$(OBJDIR)/configure.h $(OBJDIR)/content_.c:$(OBJDIR)/content.h $(OBJDIR)/db_.c:$(OBJDIR)/db.h $(OBJDIR)/delta_.c:$(OBJDIR)/delta.h $(OBJDIR)/deltacmd_.c:$(OBJDIR)/deltacmd.h $(OBJDIR)/descendants_.c:$(OBJDIR)/descendants.h $(OBJDIR)/diff_.c:$(OBJDIR)/diff.h $(OBJDIR)/diffcmd_.c:$(OBJDIR)/diffcmd.h $(OBJDIR)/doc_.c:$(OBJDIR)/doc.h $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h $(OBJDIR)/event_.c:$(OBJDIR)/event.h $(OBJDIR)/export_.c:$(OBJDIR)/export.h $(OBJDIR)/file_.c:$(OBJDIR)/file.h $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h $(OBJDIR)/http_.c:$(OBJDIR)/http.h $(OBJDIR)/http_socket_.c:$(OBJDIR)/http_socket.h $(OBJDIR)/http_ssl_.c:$(OBJDIR)/http_ssl.h $(OBJDIR)/http_transport_.c:$(OBJDIR)/http_transport.h $(OBJDIR)/import_.c:$(OBJDIR)/import.h $(OBJDIR)/info_.c:$(OBJDIR)/info.h $(OBJDIR)/json_.c:$(OBJDIR)/json.h $(OBJDIR)/json_artifact_.c:$(OBJDIR)/json_artifact.h $(OBJDIR)/json_branch_.c:$(OBJDIR)/json_branch.h $(OBJDIR)/json_config_.c:$(OBJDIR)/json_config.h $(OBJDIR)/json_diff_.c:$(OBJDIR)/json_diff.h $(OBJDIR)/json_dir_.c:$(OBJDIR)/json_dir.h $(OBJDIR)/json_finfo_.c:$(OBJDIR)/json_finfo.h $(OBJDIR)/json_login_.c:$(OBJDIR)/json_login.h $(OBJDIR)/json_query_.c:$(OBJDIR)/json_query.h $(OBJDIR)/json_report_.c:$(OBJDIR)/json_report.h $(OBJDIR)/json_tag_.c:$(OBJDIR)/json_tag.h $(OBJDIR)/json_timeline_.c:$(OBJDIR)/json_timeline.h $(OBJDIR)/json_user_.c:$(OBJDIR)/json_user.h $(OBJDIR)/json_wiki_.c:$(OBJDIR)/json_wiki.h $(OBJDIR)/leaf_.c:$(OBJDIR)/leaf.h $(OBJDIR)/login_.c:$(OBJDIR)/login.h $(OBJDIR)/main_.c:$(OBJDIR)/main.h $(OBJDIR)/manifest_.c:$(OBJDIR)/manifest.h $(OBJDIR)/md5_.c:$(OBJDIR)/md5.h $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h $(OBJDIR)/name_.c:$(OBJDIR)/name.h $(OBJDIR)/path_.c:$(OBJDIR)/path.h $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h $(OBJDIR)/report_.c:$(OBJDIR)/report.h $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h $(OBJDIR)/search_.c:$(OBJDIR)/search.h $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h $(OBJDIR)/style_.c:$(OBJDIR)/style.h $(OBJDIR)/sync_.c:$(OBJDIR)/sync.h $(OBJDIR)/tag_.c:$(OBJDIR)/tag.h $(OBJDIR)/tar_.c:$(OBJDIR)/tar.h $(OBJDIR)/th_main_.c:$(OBJDIR)/th_main.h $(OBJDIR)/timeline_.c:$(OBJDIR)/timeline.h $(OBJDIR)/tkt_.c:$(OBJDIR)/tkt.h $(OBJDIR)/tktsetup_.c:$(OBJDIR)/tktsetup.h $(OBJDIR)/undo_.c:$(OBJDIR)/undo.h $(OBJDIR)/update_.c:$(OBJDIR)/update.h $(OBJDIR)/url_.c:$(OBJDIR)/url.h $(OBJDIR)/user_.c:$(OBJDIR)/user.h $(OBJDIR)/verify_.c:$(OBJDIR)/verify.h $(OBJDIR)/vfile_.c:$(OBJDIR)/vfile.h $(OBJDIR)/wiki_.c:$(OBJDIR)/wiki.h $(OBJDIR)/wikiformat_.c:$(OBJDIR)/wikiformat.h $(OBJDIR)/winhttp_.c:$(OBJDIR)/winhttp.h $(OBJDIR)/xfer_.c:$(OBJDIR)/xfer.h $(OBJDIR)/xfersetup_.c:$(OBJDIR)/xfersetup.h $(OBJDIR)/zip_.c:$(OBJDIR)/zip.h $(SRCDIR)/sqlite4.h $(SRCDIR)/th.h $(OBJDIR)/VERSION.h
   380    380   	touch $(OBJDIR)/headers
   381    381   $(OBJDIR)/headers: Makefile
   382    382   $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/json_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
   383    383   Makefile:
   384    384   $(OBJDIR)/add_.c:	$(SRCDIR)/add.c $(OBJDIR)/translate
   385    385   	$(OBJDIR)/translate $(SRCDIR)/add.c >$(OBJDIR)/add_.c
   386    386   
................................................................................
  1056   1056   $(OBJDIR)/zip_.c:	$(SRCDIR)/zip.c $(OBJDIR)/translate
  1057   1057   	$(OBJDIR)/translate $(SRCDIR)/zip.c >$(OBJDIR)/zip_.c
  1058   1058   
  1059   1059   $(OBJDIR)/zip.o:	$(OBJDIR)/zip_.c $(OBJDIR)/zip.h  $(SRCDIR)/config.h
  1060   1060   	$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
  1061   1061   
  1062   1062   $(OBJDIR)/zip.h:	$(OBJDIR)/headers
  1063         -$(OBJDIR)/sqlite3.o:	$(SRCDIR)/sqlite3.c
  1064         -	$(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
         1063  +$(OBJDIR)/sqlite4.o:	$(SRCDIR)/sqlite4.c
         1064  +	$(XTCC) -DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -DSQLITE4_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0 -c $(SRCDIR)/sqlite4.c -o $(OBJDIR)/sqlite4.o
  1065   1065   
  1066         -$(OBJDIR)/shell.o:	$(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
  1067         -	$(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
         1066  +$(OBJDIR)/shell.o:	$(SRCDIR)/shell.c $(SRCDIR)/sqlite4.h
         1067  +	$(XTCC) -Dmain=sqlite4_shell -DSQLITE4_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
  1068   1068   
  1069   1069   $(OBJDIR)/th.o:	$(SRCDIR)/th.c
  1070   1070   	$(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
  1071   1071   
  1072   1072   $(OBJDIR)/th_lang.o:	$(SRCDIR)/th_lang.c
  1073   1073   	$(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th_lang.c -o $(OBJDIR)/th_lang.o
  1074   1074   

Changes to src/makemake.tcl.

   115    115     xfersetup
   116    116     zip
   117    117     http_ssl
   118    118   }
   119    119   
   120    120   # Name of the final application
   121    121   #
   122         -set name fossil
          122  +set name fossil4
   123    123   
   124    124   # The "writeln" command sends output to the target makefile.
   125    125   #
   126    126   proc writeln {args} {
   127    127     global output_file
   128    128     if {[lindex $args 0]=="-nonewline"} {
   129    129       puts -nonewline $output_file [lindex $args 1]
................................................................................
   208    208   $(OBJDIR)/VERSION.h:	$(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
   209    209   	$(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \
   210    210   		$(SRCDIR)/../manifest \
   211    211   		$(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
   212    212   
   213    213   # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
   214    214   # to 1. If it is set to 1, then there is no need to build or link
   215         -# the sqlite3.o object. Instead, the system sqlite will be linked
   216         -# using -lsqlite3.
          215  +# the sqlite4.o object. Instead, the system sqlite will be linked
          216  +# using -lsqlite4.
   217    217   SQLITE3_OBJ.1 = 
   218         -SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
          218  +SQLITE3_OBJ.0 = $(OBJDIR)/sqlite4.o
   219    219   SQLITE3_OBJ.  = $(SQLITE3_OBJ.0)
   220    220   
   221    221   # The FOSSIL_ENABLE_TCL variable may be undefined, set to 0, or set to 1.
   222    222   # If it is set to 1, then we need to build the Tcl integration code and
   223    223   # link to the Tcl library.
   224    224   TCL_OBJ.0 = 
   225    225   TCL_OBJ.1 = $(OBJDIR)/th_tcl.o
................................................................................
   248    248   }
   249    249   
   250    250   set mhargs {}
   251    251   foreach s [lsort $src] {
   252    252     append mhargs " \$(OBJDIR)/${s}_.c:\$(OBJDIR)/$s.h"
   253    253     set extra_h($s) {}
   254    254   }
   255         -append mhargs " \$(SRCDIR)/sqlite3.h"
          255  +append mhargs " \$(SRCDIR)/sqlite4.h"
   256    256   append mhargs " \$(SRCDIR)/th.h"
   257    257   #append mhargs " \$(SRCDIR)/cson_amalgamation.h"
   258    258   append mhargs " \$(OBJDIR)/VERSION.h"
   259    259   writeln "\$(OBJDIR)/page_index.h: \$(TRANS_SRC) \$(OBJDIR)/mkindex"
   260    260   writeln "\t\$(OBJDIR)/mkindex \$(TRANS_SRC) >$@"
   261    261   writeln "\$(OBJDIR)/headers:\t\$(OBJDIR)/page_index.h \$(OBJDIR)/makeheaders \$(OBJDIR)/VERSION.h"
   262    262   writeln "\t\$(OBJDIR)/makeheaders $mhargs"
................................................................................
   271    271     writeln "\t\$(OBJDIR)/translate \$(SRCDIR)/$s.c >\$(OBJDIR)/${s}_.c\n"
   272    272     writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h"
   273    273     writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
   274    274     writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers"
   275    275   }
   276    276   
   277    277   
   278         -writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
   279         -set opt {-DSQLITE_OMIT_LOAD_EXTENSION=1}
   280         -append opt " -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4"
   281         -#append opt " -DSQLITE_ENABLE_FTS3=1"
   282         -append opt " -DSQLITE_ENABLE_STAT3"
          278  +writeln "\$(OBJDIR)/sqlite4.o:\t\$(SRCDIR)/sqlite4.c"
          279  +set opt {-DSQLITE4_OMIT_LOAD_EXTENSION=1}
          280  +append opt " -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4"
          281  +#append opt " -DSQLITE4_ENABLE_FTS3=1"
          282  +append opt " -DSQLITE4_ENABLE_STAT3"
   283    283   append opt " -Dlocaltime=fossil_localtime"
   284         -append opt " -DSQLITE_ENABLE_LOCKING_STYLE=0"
   285         -set SQLITE_OPTIONS $opt
   286         -writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
          284  +append opt " -DSQLITE4_ENABLE_LOCKING_STYLE=0"
          285  +set SQLITE4_OPTIONS $opt
          286  +writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite4.c -o \$(OBJDIR)/sqlite4.o\n"
   287    287   
   288         -writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
   289         -set opt {-Dmain=sqlite3_shell}
   290         -append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
          288  +writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite4.h"
          289  +set opt {-Dmain=sqlite4_shell}
          290  +append opt " -DSQLITE4_OMIT_LOAD_EXTENSION=1"
   291    291   writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
   292    292   
   293    293   writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
   294    294   writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
   295    295   
   296    296   writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
   297    297   writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th_lang.c -o \$(OBJDIR)/th_lang.o\n"
................................................................................
   544    544   test:	$(OBJDIR) $(APPNAME)
   545    545   	$(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME)
   546    546   
   547    547   $(OBJDIR)/VERSION.h:	$(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
   548    548   	$(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
   549    549   
   550    550   EXTRAOBJ = \
   551         -  $(OBJDIR)/sqlite3.o \
          551  +  $(OBJDIR)/sqlite4.o \
   552    552     $(OBJDIR)/shell.o \
   553    553     $(OBJDIR)/th.o \
   554    554     $(OBJDIR)/th_lang.o \
   555    555     $(OBJDIR)/cson_amalgamation.o
   556    556   
   557    557   ifdef FOSSIL_ENABLE_TCL
   558    558   EXTRAOBJ +=  $(OBJDIR)/th_tcl.o
................................................................................
   580    580   }
   581    581   
   582    582   set mhargs {}
   583    583   foreach s [lsort $src] {
   584    584     append mhargs " \$(OBJDIR)/${s}_.c:\$(OBJDIR)/$s.h"
   585    585     set extra_h($s) {}
   586    586   }
   587         -append mhargs " \$(SRCDIR)/sqlite3.h"
          587  +append mhargs " \$(SRCDIR)/sqlite4.h"
   588    588   append mhargs " \$(SRCDIR)/th.h"
   589    589   append mhargs " \$(OBJDIR)/VERSION.h"
   590    590   writeln "\$(OBJDIR)/page_index.h: \$(TRANS_SRC) \$(OBJDIR)/mkindex"
   591    591   writeln "\t\$(MKINDEX) \$(TRANS_SRC) >$@"
   592    592   writeln "\$(OBJDIR)/headers:\t\$(OBJDIR)/page_index.h \$(OBJDIR)/makeheaders \$(OBJDIR)/VERSION.h"
   593    593   writeln "\t\$(MAKEHEADERS) $mhargs"
   594    594   writeln "\techo Done >\$(OBJDIR)/headers"
................................................................................
   602    602     writeln "\t\$(TRANSLATE) \$(SRCDIR)/$s.c >\$(OBJDIR)/${s}_.c\n"
   603    603     writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h $extra_h($s) \$(SRCDIR)/config.h"
   604    604     writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
   605    605     writeln "$s.h:\t\$(OBJDIR)/headers"
   606    606   }
   607    607   
   608    608   
   609         -writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
   610         -set opt $SQLITE_OPTIONS
   611         -writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
          609  +writeln "\$(OBJDIR)/sqlite4.o:\t\$(SRCDIR)/sqlite4.c"
          610  +set opt $SQLITE4_OPTIONS
          611  +writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite4.c -o \$(OBJDIR)/sqlite4.o\n"
   612    612   
   613    613   set opt {}
   614    614   writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
   615    615   writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/cson_amalgamation.c -o \$(OBJDIR)/cson_amalgamation.o -DCSON_FOSSIL_MODE\n"
   616    616   writeln "\$(OBJDIR)/json.o \$(OBJDIR)/json_artifact.o \$(OBJDIR)/json_branch.o \$(OBJDIR)/json_config.o \$(OBJDIR)/json_diff.o \$(OBJDIR)/json_dir.o \$(OBJDIR)/jsos_finfo.o \$(OBJDIR)/json_login.o \$(OBJDIR)/json_query.o \$(OBJDIR)/json_report.o \$(OBJDIR)/json_tag.o \$(OBJDIR)/json_timeline.o \$(OBJDIR)/json_user.o \$(OBJDIR)/json_wiki.o : \$(SRCDIR)/json_detail.h\n"
   617    617   
   618         -writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
   619         -set opt {-Dmain=sqlite3_shell}
   620         -append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
          618  +writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite4.h"
          619  +set opt {-Dmain=sqlite4_shell}
          620  +append opt " -DSQLITE4_OMIT_LOAD_EXTENSION=1"
   621    621   writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
   622    622   
   623    623   writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
   624    624   writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
   625    625   
   626    626   writeln "\$(OBJDIR)/th_lang.o:\t\$(SRCDIR)/th_lang.c"
   627    627   writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th_lang.c -o \$(OBJDIR)/th_lang.o\n"
................................................................................
   668    668   SSL    =
   669    669   
   670    670   CFLAGS = -o
   671    671   BCC    = $(DMDIR)\bin\dmc $(CFLAGS)
   672    672   TCC    = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
   673    673   LIBS   = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
   674    674   }
   675         -writeln "SQLITE_OPTIONS = $SQLITE_OPTIONS\n"
          675  +writeln "SQLITE4_OPTIONS = $SQLITE4_OPTIONS\n"
   676    676   writeln -nonewline "SRC   = "
   677    677   foreach s [lsort $src] {
   678    678     writeln -nonewline "${s}_.c "
   679    679   }
   680    680   writeln "\n"
   681    681   writeln -nonewline "OBJ   = "
   682    682   foreach s [lsort $src] {
   683    683     writeln -nonewline "\$(OBJDIR)\\$s\$O "
   684    684   }
   685         -writeln "\$(OBJDIR)\\shell\$O \$(OBJDIR)\\sqlite3\$O \$(OBJDIR)\\th\$O \$(OBJDIR)\\th_lang\$O "
          685  +writeln "\$(OBJDIR)\\shell\$O \$(OBJDIR)\\sqlite4\$O \$(OBJDIR)\\th\$O \$(OBJDIR)\\th_lang\$O "
   686    686   writeln {
   687    687   
   688    688   RC=$(DMDIR)\bin\rcc
   689    689   RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__
   690    690   
   691    691   APPNAME = $(OBJDIR)\fossil$(E)
   692    692   
................................................................................
   700    700   	$(RC) $(RCFLAGS) -o$@ $**
   701    701   
   702    702   $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res}
   703    703   writeln -nonewline "\t+echo "
   704    704   foreach s [lsort $src] {
   705    705     writeln -nonewline "$s "
   706    706   }
   707         -writeln "shell sqlite3 th th_lang > \$@"
          707  +writeln "shell sqlite4 th th_lang > \$@"
   708    708   writeln "\t+echo fossil >> \$@"
   709    709   writeln "\t+echo fossil >> \$@"
   710    710   writeln "\t+echo \$(LIBS) >> \$@"
   711    711   writeln "\t+echo. >> \$@"
   712    712   writeln "\t+echo fossil >> \$@"
   713    713   
   714    714   writeln {
................................................................................
   721    721   mkindex$E: $(SRCDIR)\mkindex.c
   722    722   	$(BCC) -o$@ $**
   723    723   
   724    724   version$E: $B\src\mkversion.c
   725    725   	$(BCC) -o$@ $**
   726    726   
   727    727   $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
   728         -	$(TCC) -o$@ -c -Dmain=sqlite3_shell $(SQLITE_OPTIONS) $**
          728  +	$(TCC) -o$@ -c -Dmain=sqlite4_shell $(SQLITE4_OPTIONS) $**
   729    729   
   730         -$(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
   731         -	$(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
          730  +$(OBJDIR)\sqlite4$O : $(SRCDIR)\sqlite4.c
          731  +	$(TCC) -o$@ -c $(SQLITE4_OPTIONS) $**
   732    732   
   733    733   $(OBJDIR)\th$O : $(SRCDIR)\th.c
   734    734   	$(TCC) -o$@ -c $**
   735    735   
   736    736   $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
   737    737   	$(TCC) -o$@ -c $**
   738    738   
................................................................................
   776    776     writeln "\t+translate\$E \$** > \$@\n"
   777    777   }
   778    778   
   779    779   writeln -nonewline "headers: makeheaders\$E page_index.h VERSION.h\n\t +makeheaders\$E "
   780    780   foreach s [lsort $src] {
   781    781     writeln -nonewline "${s}_.c:$s.h "
   782    782   }
   783         -writeln "\$(SRCDIR)\\sqlite3.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR)\\cson_amalgamation.h"
          783  +writeln "\$(SRCDIR)\\sqlite4.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR)\\cson_amalgamation.h"
   784    784   writeln "\t@copy /Y nul: headers"
   785    785   
   786    786   close $output_file
   787    787   #
   788    788   # End of the win/Makefile.dmc output
   789    789   ##############################################################################
   790    790   ##############################################################################
................................................................................
   833    833   
   834    834   CFLAGS = -nologo -MT -O2
   835    835   BCC    = $(CC) $(CFLAGS)
   836    836   TCC    = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL)
   837    837   LIBS   = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB)
   838    838   LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR)
   839    839   }
   840         -regsub -all {[-]D} $SQLITE_OPTIONS {/D} MSC_SQLITE_OPTIONS
   841         -writeln "SQLITE_OPTIONS = $MSC_SQLITE_OPTIONS\n"
          840  +regsub -all {[-]D} $SQLITE4_OPTIONS {/D} MSC_SQLITE4_OPTIONS
          841  +writeln "SQLITE4_OPTIONS = $MSC_SQLITE4_OPTIONS\n"
   842    842   writeln -nonewline "SRC   = "
   843    843   foreach s [lsort $src] {
   844    844     writeln -nonewline "${s}_.c "
   845    845   }
   846    846   writeln "\n"
   847    847   writeln -nonewline "OBJ   = "
   848    848   foreach s [lsort $src] {
   849    849     writeln -nonewline "\$(OX)\\$s\$O "
   850    850   }
   851         -writeln "\$(OX)\\shell\$O \$(OX)\\sqlite3\$O \$(OX)\\th\$O \$(OX)\\th_lang\$O "
          851  +writeln "\$(OX)\\shell\$O \$(OX)\\sqlite4\$O \$(OX)\\th\$O \$(OX)\\th_lang\$O "
   852    852   writeln {
   853    853   
   854    854   APPNAME = $(OX)\fossil$(E)
   855    855   
   856    856   all: $(OX) $(APPNAME)
   857    857   
   858    858   $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts
   859    859   	cd $(OX) 
   860    860   	link /NODEFAULTLIB:msvcrt -OUT:$@ $(LIBDIR) @linkopts
   861    861   
   862    862   $(OX)\linkopts: $B\win\Makefile.msc}
   863    863   set redir {>}
   864         -foreach s [lsort [concat $src {shell sqlite3 th th_lang}]] {
          864  +foreach s [lsort [concat $src {shell sqlite4 th th_lang}]] {
   865    865     writeln "\techo \$(OX)\\$s.obj $redir \$@"
   866    866     set redir {>>}
   867    867   }
   868    868   writeln "\techo \$(LIBS) >> \$@\n\n"
   869    869   
   870    870   writeln {
   871    871   
................................................................................
   881    881   mkindex$E: $(SRCDIR)\mkindex.c
   882    882   	$(BCC) $**
   883    883   
   884    884   mkversion$E: $B\src\mkversion.c
   885    885   	$(BCC) $**
   886    886   
   887    887   $(OX)\shell$O : $(SRCDIR)\shell.c
   888         -	$(TCC) /Fo$@ /Dmain=sqlite3_shell $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
          888  +	$(TCC) /Fo$@ /Dmain=sqlite4_shell $(SQLITE4_OPTIONS) -c $(SRCDIR)\shell.c
   889    889   
   890         -$(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
   891         -	$(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
          890  +$(OX)\sqlite4$O : $(SRCDIR)\sqlite4.c
          891  +	$(TCC) /Fo$@ -c $(SQLITE4_OPTIONS) $**
   892    892   
   893    893   $(OX)\th$O : $(SRCDIR)\th.c
   894    894   	$(TCC) /Fo$@ -c $**
   895    895   
   896    896   $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
   897    897   	$(TCC) /Fo$@ -c $**
   898    898   
................................................................................
   935    935     writeln "\ttranslate\$E \$** > \$@\n"
   936    936   }
   937    937   
   938    938   writeln -nonewline "headers: makeheaders\$E page_index.h VERSION.h\n\tmakeheaders\$E "
   939    939   foreach s [lsort $src] {
   940    940     writeln -nonewline "${s}_.c:$s.h "
   941    941   }
   942         -writeln "\$(SRCDIR)\\sqlite3.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR)\\cson_amalgamation.h"
          942  +writeln "\$(SRCDIR)\\sqlite4.h \$(SRCDIR)\\th.h VERSION.h \$(SRCDIR)\\cson_amalgamation.h"
   943    943   writeln "\t@copy /Y nul: headers"
   944    944   
   945    945   
   946    946   close $output_file
   947    947   #
   948    948   # End of the win/Makefile.msc output
   949    949   ##############################################################################
................................................................................
  1035   1035   # define the special utilities files, needed to generate
  1036   1036   # the automatically generated source files
  1037   1037   UTILS=translate.exe mkindex.exe makeheaders.exe
  1038   1038   UTILS_OBJ=$(UTILS:.exe=.obj)
  1039   1039   UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c))
  1040   1040   
  1041   1041   # define the sqlite files, which need special flags on compile
  1042         -SQLITESRC=sqlite3.c
         1042  +SQLITESRC=sqlite4.c
  1043   1043   ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
  1044   1044   SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
  1045         -SQLITEDEFINES=-DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0
         1045  +SQLITEDEFINES=-DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0
  1046   1046   
  1047   1047   # define the sqlite shell files, which need special flags on compile
  1048   1048   SQLITESHELLSRC=shell.c
  1049   1049   ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
  1050   1050   SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
  1051         -SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1
         1051  +SQLITESHELLDEFINES=-Dmain=sqlite4_shell -DSQLITE4_OMIT_LOAD_EXTENSION=1
  1052   1052   
  1053   1053   # define the th scripting files, which need special flags on compile
  1054   1054   THSRC=th.c th_lang.c
  1055   1055   ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
  1056   1056   THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
  1057   1057   
  1058   1058   # define the zlib files, needed by this compile
................................................................................
  1100   1100   	mkindex.exe $(TRANSLATEDSRC) >$@
  1101   1101   
  1102   1102   # extracting version info from manifest
  1103   1103   VERSION.h:	version.exe ..\manifest.uuid ..\manifest ..\VERSION
  1104   1104   	version.exe ..\manifest.uuid ..\manifest ..\VERSION  > $@
  1105   1105   
  1106   1106   # generate the simplified headers
  1107         -headers: makeheaders.exe page_index.h VERSION.h ../src/sqlite3.h ../src/th.h VERSION.h
  1108         -	makeheaders.exe $(foreach ts,$(TRANSLATEDSRC),$(ts):$(ts:_.c=.h)) ../src/sqlite3.h ../src/th.h VERSION.h
         1107  +headers: makeheaders.exe page_index.h VERSION.h ../src/sqlite4.h ../src/th.h VERSION.h
         1108  +	makeheaders.exe $(foreach ts,$(TRANSLATEDSRC),$(ts):$(ts:_.c=.h)) ../src/sqlite4.h ../src/th.h VERSION.h
  1109   1109   	echo Done >$@
  1110   1110   
  1111   1111   # compile C sources with relevant options
  1112   1112   
  1113   1113   $(TRANSLATEDOBJ):	%_.obj:	%_.c %.h
  1114   1114   	$(CC) $(CCFLAGS) $(INCLUDE) "$<" -Fo"$@"
  1115   1115   

Changes to src/manifest.c.

   962    962   ** Parse the manifest and discarded.  Use for testing only.
   963    963   */
   964    964   void manifest_test_parse_cmd(void){
   965    965     Manifest *p;
   966    966     Blob b;
   967    967     int i;
   968    968     int n = 1;
   969         -  sqlite3_open(":memory:", &g.db);
          969  +  sqlite4_open(0, ":memory:", &g.db, SQLITE4_OPEN_READWRITE);
   970    970     if( g.argc!=3 && g.argc!=4 ){
   971    971       usage("FILENAME");
   972    972     }
   973    973     blob_read_from_file(&b, g.argv[2]);
   974    974     if( g.argc>3 ) n = atoi(g.argv[3]);
   975    975     for(i=0; i<n; i++){
   976    976       Blob b2;
................................................................................
  1086   1086   */
  1087   1087   static int filename_to_fnid(const char *zFilename){
  1088   1088     static Stmt q1, s1;
  1089   1089     int fnid;
  1090   1090     db_static_prepare(&q1, "SELECT fnid FROM filename WHERE name=:fn");
  1091   1091     db_bind_text(&q1, ":fn", zFilename);
  1092   1092     fnid = 0;
  1093         -  if( db_step(&q1)==SQLITE_ROW ){
         1093  +  if( db_step(&q1)==SQLITE4_ROW ){
  1094   1094       fnid = db_column_int(&q1, 0);
  1095   1095     }
  1096   1096     db_reset(&q1);
  1097   1097     if( fnid==0 ){
  1098   1098       db_static_prepare(&s1, "INSERT INTO filename(name) VALUES(:fn)");
  1099   1099       db_bind_text(&s1, ":fn", zFilename);
  1100   1100       db_exec(&s1);
................................................................................
  1281   1281     /* If mlink table entires are already set for cid, then abort early
  1282   1282     ** doing no work.
  1283   1283     */
  1284   1284     db_static_prepare(&eq, "SELECT 1 FROM mlink WHERE mid=:mid");
  1285   1285     db_bind_int(&eq, ":mid", cid);
  1286   1286     rc = db_step(&eq);
  1287   1287     db_reset(&eq);
  1288         -  if( rc==SQLITE_ROW ) return;
         1288  +  if( rc==SQLITE4_ROW ) return;
  1289   1289   
  1290   1290     /* Compute the value of the missing pParent or pChild parameter.
  1291   1291     ** Fetch the baseline checkins for both.
  1292   1292     */
  1293   1293     assert( pParent==0 || pChild==0 );
  1294   1294     if( pParent==0 ){
  1295   1295       ppOther = &pParent;
................................................................................
  1444   1444   ** Finish up a sequence of manifest_crosslink calls.
  1445   1445   */
  1446   1446   void manifest_crosslink_end(void){
  1447   1447     Stmt q, u;
  1448   1448     int i;
  1449   1449     assert( manifest_crosslink_busy==1 );
  1450   1450     db_prepare(&q, "SELECT uuid FROM pending_tkt");
  1451         -  while( db_step(&q)==SQLITE_ROW ){
         1451  +  while( db_step(&q)==SQLITE4_ROW ){
  1452   1452       const char *zUuid = db_column_text(&q, 0);
  1453   1453       ticket_rebuild_entry(zUuid);
  1454   1454     }
  1455   1455     db_finalize(&q);
  1456   1456     db_multi_exec("DROP TABLE pending_tkt");
  1457   1457   
  1458   1458     /* If multiple check-ins happen close together in time, adjust their
................................................................................
  1467   1467     db_prepare(&u,
  1468   1468         "UPDATE time_fudge SET m2="
  1469   1469            "(SELECT x.m1 FROM time_fudge AS x WHERE x.mid=time_fudge.cid)"
  1470   1470     );
  1471   1471     for(i=0; i<30; i++){
  1472   1472       db_step(&q);
  1473   1473       db_reset(&q);
  1474         -    if( sqlite3_changes(g.db)==0 ) break;
         1474  +    if( sqlite4_changes(g.db)==0 ) break;
  1475   1475       db_step(&u);
  1476   1476       db_reset(&u);
  1477   1477     }
  1478   1478     db_finalize(&q);
  1479   1479     db_finalize(&u);
  1480   1480     db_multi_exec(
  1481   1481       "UPDATE event SET mtime=(SELECT m1 FROM time_fudge WHERE mid=objid)"
................................................................................
  1623   1623                         "VALUES(%d, %d, %d, %.17g)", pid, rid, i==0, p->rDate);
  1624   1624           if( i==0 ){
  1625   1625             add_mlink(pid, 0, rid, p);
  1626   1626             parentid = pid;
  1627   1627           }
  1628   1628         }
  1629   1629         db_prepare(&q, "SELECT cid FROM plink WHERE pid=%d AND isprim", rid);
  1630         -      while( db_step(&q)==SQLITE_ROW ){
         1630  +      while( db_step(&q)==SQLITE4_ROW ){
  1631   1631           int cid = db_column_int(&q, 0);
  1632   1632           add_mlink(rid, p, cid, 0);
  1633   1633         }
  1634   1634         db_finalize(&q);
  1635   1635         if( p->nParent==0 ){
  1636   1636           /* For root files (files without parents) add mlink entries
  1637   1637           ** showing all content as new. */
................................................................................
  1725   1725       int tagid = tag_findid(zTag, 1);
  1726   1726       int prior;
  1727   1727       char *zComment;
  1728   1728       int nWiki;
  1729   1729       char zLength[40];
  1730   1730       while( fossil_isspace(p->zWiki[0]) ) p->zWiki++;
  1731   1731       nWiki = strlen(p->zWiki);
  1732         -    sqlite3_snprintf(sizeof(zLength), zLength, "%d", nWiki);
         1732  +    sqlite4_snprintf(zLength, sizeof(zLength), "%d", nWiki);
  1733   1733       tag_insert(zTag, 1, zLength, rid, p->rDate, rid);
  1734   1734       free(zTag);
  1735   1735       prior = db_int(0,
  1736   1736         "SELECT rid FROM tagxref"
  1737   1737         " WHERE tagid=%d AND mtime<%.17g"
  1738   1738         " ORDER BY mtime DESC",
  1739   1739         tagid, p->rDate
................................................................................
  1765   1765       char *zTag = mprintf("event-%s", p->zEventId);
  1766   1766       int tagid = tag_findid(zTag, 1);
  1767   1767       int prior, subsequent;
  1768   1768       int nWiki;
  1769   1769       char zLength[40];
  1770   1770       while( fossil_isspace(p->zWiki[0]) ) p->zWiki++;
  1771   1771       nWiki = strlen(p->zWiki);
  1772         -    sqlite3_snprintf(sizeof(zLength), zLength, "%d", nWiki);
         1772  +    sqlite4_snprintf(zLength, sizeof(zLength), "%d", nWiki);
  1773   1773       tag_insert(zTag, 1, zLength, rid, p->rDate, rid);
  1774   1774       free(zTag);
  1775   1775       prior = db_int(0,
  1776   1776         "SELECT rid FROM tagxref"
  1777   1777         " WHERE tagid=%d AND mtime<%.17g AND rid!=%d"
  1778   1778         " ORDER BY mtime DESC",
  1779   1779         tagid, p->rDate, rid

Changes to src/md5.c.

    16     16    * To compute the message digest of a chunk of bytes, declare an
    17     17    * MD5Context structure, pass it to MD5Init, call MD5Update as
    18     18    * needed on buffers full of bytes, and then call MD5Final, which
    19     19    * will fill a supplied 16-byte array with the digest.
    20     20    */
    21     21   #include <string.h>
    22     22   #include <stdio.h>
    23         -#include <sqlite3.h>
           23  +#include <sqlite4.h>
    24     24   #include "md5.h"
    25     25   
    26     26   /*
    27     27    * If compiled on a machine that doesn't have a 32-bit integer,
    28     28    * you just set "uint32" to the appropriate datatype for an
    29     29    * unsigned 32-bit integer.  For example:
    30     30    *
................................................................................
   335    335   
   336    336     pFirst = (unsigned int*)&incrCtx;
   337    337     pLast = (unsigned int*)((&incrCtx)+1);
   338    338     while( pFirst<pLast ){
   339    339       cksum += *pFirst;
   340    340       pFirst++;
   341    341     }
   342         -  sqlite3_snprintf(sizeof(zResult), zResult, "%08x", cksum);
          342  +  sqlite4_snprintf(zResult, sizeof(zResult), "%08x", cksum);
   343    343     return zResult;
   344    344   }
   345    345   
   346    346   /*
   347    347   ** Finish the incremental MD5 checksum.  Store the result in blob pOut
   348    348   ** if pOut!=0.  Also return a pointer to the result.  
   349    349   **

Changes to src/merge.c.

    31     31        "SELECT datetime(mtime,'localtime'),"
    32     32        "       coalesce(euser,user), coalesce(ecomment,comment),"
    33     33        "       (SELECT uuid FROM blob WHERE rid=%d),"
    34     34        "       (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref"
    35     35        "         WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid"
    36     36        "           AND tagxref.rid=%d AND tagxref.tagtype>0)"
    37     37        "  FROM event WHERE objid=%d", rid, rid, rid);
    38         -  if( db_step(&q)==SQLITE_ROW ){
           38  +  if( db_step(&q)==SQLITE4_ROW ){
    39     39       const char *zTagList = db_column_text(&q, 4);
    40     40       char *zCom;
    41     41       if( zTagList && zTagList[0] ){
    42     42         zCom = mprintf("%s (%s)", db_column_text(&q, 2), zTagList);
    43     43       }else{
    44     44         zCom = mprintf("%s", db_column_text(&q,2));
    45     45       }
................................................................................
   156    156       if( pid<=0 ){
   157    157         fossil_fatal("cannot find an ancestor for %s", g.argv[2]);
   158    158       }
   159    159     }else{
   160    160       pivot_set_primary(mid);
   161    161       pivot_set_secondary(vid);
   162    162       db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0");
   163         -    while( db_step(&q)==SQLITE_ROW ){
          163  +    while( db_step(&q)==SQLITE4_ROW ){
   164    164         pivot_set_secondary(db_column_int(&q,0));
   165    165       }
   166    166       db_finalize(&q);
   167    167       pid = pivot_find();
   168    168       if( pid<=0 ){
   169    169         fossil_fatal("cannot find a common ancestor between the current "
   170    170                      "checkout and %s", g.argv[2]);
................................................................................
   307    307     );
   308    308   
   309    309     if( debugFlag ){
   310    310       db_prepare(&q,
   311    311          "SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, "
   312    312          "       isexe, islinkv, islinkm FROM fv"
   313    313       );
   314         -    while( db_step(&q)==SQLITE_ROW ){
          314  +    while( db_step(&q)==SQLITE4_ROW ){
   315    315          fossil_print("%3d: ridv=%-4d ridp=%-4d ridm=%-4d chnged=%d isexe=%d "
   316    316                       " islinkv=%d islinkm=%d\n",
   317    317             db_column_int(&q, 0),
   318    318             db_column_int(&q, 5),
   319    319             db_column_int(&q, 6),
   320    320             db_column_int(&q, 7),
   321    321             db_column_int(&q, 4),
................................................................................
   333    333     ** Find files in M and V but not in P and report conflicts.
   334    334     ** The file in M will be ignored.  It will be treated as if it
   335    335     ** does not exist.
   336    336     */
   337    337     db_prepare(&q,
   338    338       "SELECT idm FROM fv WHERE idp=0 AND idv>0 AND idm>0"
   339    339     );
   340         -  while( db_step(&q)==SQLITE_ROW ){
          340  +  while( db_step(&q)==SQLITE4_ROW ){
   341    341       int idm = db_column_int(&q, 0);
   342    342       char *zName = db_text(0, "SELECT pathname FROM vfile WHERE id=%d", idm);
   343    343       fossil_warning("WARNING - no common ancestor: %s\n", zName);
   344    344       free(zName);
   345    345       db_multi_exec("UPDATE fv SET idm=0 WHERE idm=%d", idm);
   346    346     }
   347    347     db_finalize(&q);
................................................................................
   349    349     /*
   350    350     ** Add to V files that are not in V or P but are in M
   351    351     */
   352    352     db_prepare(&q,
   353    353       "SELECT idm, rowid, fnm FROM fv AS x"
   354    354       " WHERE idp=0 AND idv=0 AND idm>0"
   355    355     );
   356         -  while( db_step(&q)==SQLITE_ROW ){
          356  +  while( db_step(&q)==SQLITE4_ROW ){
   357    357       int idm = db_column_int(&q, 0);
   358    358       int rowid = db_column_int(&q, 1);
   359    359       int idv;
   360    360       const char *zName;
   361    361       char *zFullName;
   362    362       db_multi_exec(
   363    363         "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,islink,pathname)"
................................................................................
   387    387     ** Copy the M content over into V.
   388    388     */
   389    389     db_prepare(&q,
   390    390       "SELECT idv, ridm, fn, islinkm FROM fv"
   391    391       " WHERE idp>0 AND idv>0 AND idm>0"
   392    392       "   AND ridm!=ridp AND ridv=ridp AND NOT chnged"
   393    393     );
   394         -  while( db_step(&q)==SQLITE_ROW ){
          394  +  while( db_step(&q)==SQLITE4_ROW ){
   395    395       int idv = db_column_int(&q, 0);
   396    396       int ridm = db_column_int(&q, 1);
   397    397       const char *zName = db_column_text(&q, 2);
   398    398       int islinkm = db_column_int(&q, 3);
   399    399       /* Copy content from idm over into idv.  Overwrite idv. */
   400    400       fossil_print("UPDATE %s\n", zName);
   401    401       if( !nochangeFlag ){
................................................................................
   414    414     */
   415    415     db_prepare(&q,
   416    416       "SELECT ridm, idv, ridp, ridv, %s, fn, isexe, islinkv, islinkm FROM fv"
   417    417       " WHERE idp>0 AND idv>0 AND idm>0"
   418    418       "   AND ridm!=ridp AND (ridv!=ridp OR chnged)",
   419    419       glob_expr("fv.fn", zBinGlob)
   420    420     );
   421         -  while( db_step(&q)==SQLITE_ROW ){
          421  +  while( db_step(&q)==SQLITE4_ROW ){
   422    422       int ridm = db_column_int(&q, 0);
   423    423       int idv = db_column_int(&q, 1);
   424    424       int ridp = db_column_int(&q, 2);
   425    425       int ridv = db_column_int(&q, 3);
   426    426       int isBinary = db_column_int(&q, 4);
   427    427       const char *zName = db_column_text(&q, 5);
   428    428       int isExe = db_column_int(&q, 6);
................................................................................
   478    478     /*
   479    479     ** Drop files that are in P and V but not in M
   480    480     */
   481    481     db_prepare(&q,
   482    482       "SELECT idv, fn, chnged FROM fv"
   483    483       " WHERE idp>0 AND idv>0 AND idm=0"
   484    484     );
   485         -  while( db_step(&q)==SQLITE_ROW ){
          485  +  while( db_step(&q)==SQLITE4_ROW ){
   486    486       int idv = db_column_int(&q, 0);
   487    487       const char *zName = db_column_text(&q, 1);
   488    488       int chnged = db_column_int(&q, 2);
   489    489       /* Delete the file idv */
   490    490       fossil_print("DELETE %s\n", zName);
   491    491       if( chnged ){
   492    492         fossil_warning("WARNING: local edits lost for %s\n", zName);
................................................................................
   509    509     ** name o P->V.   If a file is renamed on P->V only or on both P->V and
   510    510     ** P->M then we retain the V name of the file.
   511    511     */
   512    512     db_prepare(&q,
   513    513       "SELECT idv, fnp, fnm FROM fv"
   514    514       " WHERE idv>0 AND idp>0 AND idm>0 AND fnp=fn AND fnm!=fnp"
   515    515     );
   516         -  while( db_step(&q)==SQLITE_ROW ){
          516  +  while( db_step(&q)==SQLITE4_ROW ){
   517    517       int idv = db_column_int(&q, 0);
   518    518       const char *zOldName = db_column_text(&q, 1);
   519    519       const char *zNewName = db_column_text(&q, 2);
   520    520       fossil_print("RENAME %s -> %s\n", zOldName, zNewName);
   521    521       undo_save(zOldName);
   522    522       undo_save(zNewName);
   523    523       db_multi_exec(

Changes to src/name.c.

   160    160     /* symbolic-name ":" date-time */
   161    161     nTag = strlen(zTag);
   162    162     for(i=0; i<nTag-10 && zTag[i]!=':'; i++){}
   163    163     if( zTag[i]==':' && is_date(&zTag[i+1]) ){
   164    164       char *zDate = mprintf("%s", &zTag[i+1]);
   165    165       char *zTagBase = mprintf("%.*s", i, zTag);
   166    166       int nDate = strlen(zDate);
   167         -    if( sqlite3_strnicmp(&zDate[nDate-3],"utc",3)==0 ){
          167  +    if( sqlite4_strnicmp(&zDate[nDate-3],"utc",3)==0 ){
   168    168         zDate[nDate-3] = 'z';
   169    169         zDate[nDate-2] = 0;
   170    170       }
   171    171       rid = db_int(0,
   172    172         "SELECT event.objid"
   173    173         "  FROM tag, tagxref, event"
   174    174         " WHERE tag.tagname='sym-%q' "
................................................................................
   197    197           "  FROM blob, event"
   198    198           " WHERE blob.uuid GLOB '%s*'"
   199    199           "   AND event.objid=blob.rid"
   200    200           "   AND event.type GLOB '%q'",
   201    201           zUuid, zType
   202    202         );
   203    203       }
   204         -    if( db_step(&q)==SQLITE_ROW ){
          204  +    if( db_step(&q)==SQLITE4_ROW ){
   205    205         rid = db_column_int(&q, 0);
   206         -      if( db_step(&q)==SQLITE_ROW ) rid = -1;
          206  +      if( db_step(&q)==SQLITE4_ROW ) rid = -1;
   207    207       }
   208    208       db_finalize(&q);
   209    209       if( rid ) return rid;
   210    210     }
   211    211   
   212    212     /* Symbolic name */
   213    213     rid = db_int(0,
................................................................................
   363    363     style_header("Ambiguous Artifact ID");
   364    364     @ <p>The artifact id <b>%h(zName)</b> is ambiguous and might
   365    365     @ mean any of the following:
   366    366     @ <ol>
   367    367     z = mprintf("%s", zName);
   368    368     canonical16(z, strlen(z));
   369    369     db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z);
   370         -  while( db_step(&q)==SQLITE_ROW ){
          370  +  while( db_step(&q)==SQLITE4_ROW ){
   371    371       const char *zUuid = db_column_text(&q, 0);
   372    372       int rid = db_column_int(&q, 1);
   373    373       @ <li><p><a href="%s(g.zTop)/%T(zSrc)/%S(zUuid)">
   374    374       @ %S(zUuid)</a> -
   375    375       object_description(rid, 0, 0);
   376    376       @ </p></li>
   377    377     }
................................................................................
   430    430          "       (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref"
   431    431          "         WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid"
   432    432          "           AND tagxref.rid=blob.rid AND tagxref.tagtype>0)"
   433    433          "  FROM blob, rcvfrom"
   434    434          " WHERE rid=%d"
   435    435          "   AND rcvfrom.rcvid=blob.rcvid",
   436    436          rid);
   437         -    if( db_step(&q)==SQLITE_ROW ){
          437  +    if( db_step(&q)==SQLITE4_ROW ){
   438    438         const char *zTagList = db_column_text(&q, 4);
   439    439         if( fExtra ){
   440    440           fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid);
   441    441           fossil_print("size:     %d bytes\n", db_column_int(&q,1));
   442    442           fossil_print("received: %s from %s\n",
   443    443              db_column_text(&q, 2),
   444    444              db_column_text(&q, 3));
................................................................................
   451    451         }
   452    452       }
   453    453       db_finalize(&q);
   454    454       db_prepare(&q,
   455    455          "SELECT type, datetime(mtime,'localtime'),"
   456    456          "       coalesce(euser,user), coalesce(ecomment,comment)"
   457    457          "  FROM event WHERE objid=%d", rid);
   458         -    if( db_step(&q)==SQLITE_ROW ){
          458  +    if( db_step(&q)==SQLITE4_ROW ){
   459    459         const char *zType;
   460    460         switch( db_column_text(&q,0)[0] ){
   461    461           case 'c':  zType = "Check-in";       break;
   462    462           case 'w':  zType = "Wiki-edit";      break;
   463    463           case 'e':  zType = "Event";          break;
   464    464           case 't':  zType = "Ticket-change";  break;
   465    465           case 'g':  zType = "Tag-change";     break;
................................................................................
   477    477         "  FROM mlink, filename, blob, event"
   478    478         " WHERE mlink.fid=%d"
   479    479         "   AND filename.fnid=mlink.fnid"
   480    480         "   AND event.objid=mlink.mid"
   481    481         "   AND blob.rid=mlink.mid"
   482    482         " ORDER BY event.mtime DESC /*sort*/",
   483    483         rid);
   484         -    while( db_step(&q)==SQLITE_ROW ){
          484  +    while( db_step(&q)==SQLITE4_ROW ){
   485    485         fossil_print("file:     %s\n", db_column_text(&q,0));
   486    486         fossil_print("          part of [%.10s] by %s on %s\n",
   487    487           db_column_text(&q, 1),
   488    488           db_column_text(&q, 3),
   489    489           db_column_text(&q, 2));
   490    490         fossil_print("          ");
   491    491         comment_print(db_column_text(&q,4), 10, 78);
   492    492       }
   493    493       db_finalize(&q);
   494    494     }
   495    495   }

Changes to src/path.c.

   158    158     }
   159    159     while( path.pCurrent ){
   160    160       path.nStep++;
   161    161       pPrev = path.pCurrent;
   162    162       path.pCurrent = 0;
   163    163       while( pPrev ){
   164    164         db_bind_int(&s, ":pid", pPrev->rid);
   165         -      while( db_step(&s)==SQLITE_ROW ){
          165  +      while( db_step(&s)==SQLITE4_ROW ){
   166    166           int cid = db_column_int(&s, 0);
   167    167           int isParent = db_column_int(&s, 1);
   168    168           if( bag_find(&path.seen, cid) ) continue;
   169    169           p = path_new_node(cid, pPrev, isParent);
   170    170           if( cid==iTo ){
   171    171             db_finalize(&s);
   172    172             path.pEnd = p;
................................................................................
   261    261     bag_init(&you);
   262    262     bag_insert(&you, iYou);
   263    263     while( path.pCurrent ){
   264    264       pPrev = path.pCurrent;
   265    265       path.pCurrent = 0;
   266    266       while( pPrev ){
   267    267         db_bind_int(&s, ":cid", pPrev->rid);
   268         -      while( db_step(&s)==SQLITE_ROW ){
          268  +      while( db_step(&s)==SQLITE4_ROW ){
   269    269           int pid = db_column_int(&s, 0);
   270    270           if( bag_find(pPrev->isPrim ? &you : &me, pid) ){
   271    271             /* pid is the common ancestor */
   272    272             PathNode *pNext;
   273    273             for(p=path.pAll; p && p->rid!=pid; p=p->pAll){}
   274    274             assert( p!=0 );
   275    275             pNext = p;
................................................................................
   396    396     for(p=path.pStart; p; p=p->u.pTo){
   397    397       int fnid, pfnid;
   398    398       if( !p->fromIsParent && (p->u.pTo==0 || p->u.pTo->fromIsParent) ){
   399    399         /* Skip nodes where the parent is not on the path */
   400    400         continue;
   401    401       }
   402    402       db_bind_int(&q1, ":mid", p->rid);
   403         -    while( db_step(&q1)==SQLITE_ROW ){
          403  +    while( db_step(&q1)==SQLITE4_ROW ){
   404    404         fnid = db_column_int(&q1, 1);
   405    405         pfnid = db_column_int(&q1, 0);
   406    406         if( pfnid==0 ){
   407    407           pfnid = fnid;
   408    408           fnid = 0;
   409    409         }
   410    410         if( !p->fromIsParent ){

Changes to src/pivot.c.

   123    123       "       1,"
   124    124       "       aqueue.src "
   125    125       "  FROM plink, aqueue"
   126    126       " WHERE plink.cid=:rid"
   127    127       "   AND aqueue.rid=:rid"
   128    128     );
   129    129   
   130         -  while( db_step(&q1)==SQLITE_ROW ){
          130  +  while( db_step(&q1)==SQLITE4_ROW ){
   131    131       rid = db_column_int(&q1, 0);
   132    132       db_reset(&q1);
   133    133       db_bind_int(&q2, ":rid", rid);
   134         -    if( db_step(&q2)==SQLITE_ROW ){
          134  +    if( db_step(&q2)==SQLITE4_ROW ){
   135    135          break;
   136    136       }
   137    137       db_reset(&q2);
   138    138       db_bind_int(&i1, ":rid", rid);
   139    139       db_exec(&i1);
   140    140       db_bind_int(&u1, ":rid", rid);
   141    141       db_exec(&u1);

Changes to src/printf.c.

   897    897     if( zA==0 ){
   898    898       if( zB==0 ) return 0;
   899    899       return -1;
   900    900     }else if( zB==0 ){
   901    901       return +1;
   902    902     }
   903    903     if( nByte<0 ) nByte = strlen(zB);
   904         -  return sqlite3_strnicmp(zA, zB, nByte);
          904  +  return sqlite4_strnicmp(zA, zB, nByte);
   905    905   }
   906    906   int fossil_stricmp(const char *zA, const char *zB){
   907    907     int nByte;
   908    908     int rc;
   909    909     if( zA==0 ){
   910    910       if( zB==0 ) return 0;
   911    911       return -1;
   912    912     }else if( zB==0 ){
   913    913       return +1;
   914    914     }
   915    915     nByte = strlen(zB);
   916         -  rc = sqlite3_strnicmp(zA, zB, nByte);
          916  +  rc = sqlite4_strnicmp(zA, zB, nByte);
   917    917     if( rc==0 && zA[nByte] ) rc = 1;
   918    918     return rc;
   919    919   }

Changes to src/rebuild.c.

   231    231         );
   232    232       }
   233    233     
   234    234       /* Find all children of artifact rid */
   235    235       db_static_prepare(&q1, "SELECT rid FROM delta WHERE srcid=:rid");
   236    236       db_bind_int(&q1, ":rid", rid);
   237    237       bag_init(&children);
   238         -    while( db_step(&q1)==SQLITE_ROW ){
          238  +    while( db_step(&q1)==SQLITE4_ROW ){
   239    239         int cid = db_column_int(&q1, 0);
   240    240         if( !bag_find(&bagDone, cid) ){
   241    241           bag_insert(&children, cid);
   242    242         }
   243    243       }
   244    244       nChild = bag_count(&children);
   245    245       db_reset(&q1);
................................................................................
   269    269       /* Call all children recursively */
   270    270       rid = 0;
   271    271       for(cid=bag_first(&children), i=1; cid; cid=bag_next(&children, cid), i++){
   272    272         static Stmt q2;
   273    273         int sz;
   274    274         db_static_prepare(&q2, "SELECT content, size FROM blob WHERE rid=:rid");
   275    275         db_bind_int(&q2, ":rid", cid);
   276         -      if( db_step(&q2)==SQLITE_ROW && (sz = db_column_int(&q2,1))>=0 ){
          276  +      if( db_step(&q2)==SQLITE4_ROW && (sz = db_column_int(&q2,1))>=0 ){
   277    277           Blob delta, next;
   278    278           db_ephemeral_blob(&q2, 0, &delta);
   279    279           blob_uncompress(&delta, &delta);
   280    280           blob_delta_apply(pBase, &delta, &next);
   281    281           blob_reset(&delta);
   282    282           db_reset(&q2);
   283    283           if( i<nChild ){
................................................................................
   381    381     totalSize += incrSize*2;
   382    382     db_prepare(&s,
   383    383        "SELECT rid, size FROM blob /*scan*/"
   384    384        " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
   385    385        "   AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)"
   386    386     );
   387    387     manifest_crosslink_begin();
   388         -  while( db_step(&s)==SQLITE_ROW ){
          388  +  while( db_step(&s)==SQLITE4_ROW ){
   389    389       int rid = db_column_int(&s, 0);
   390    390       int size = db_column_int(&s, 1);
   391    391       if( size>=0 ){
   392    392         Blob content;
   393    393         content_get(rid, &content);
   394    394         rebuild_step(rid, size, &content);
   395    395       }
   396    396     }
   397    397     db_finalize(&s);
   398    398     db_prepare(&s,
   399    399        "SELECT rid, size FROM blob"
   400    400        " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
   401    401     );
   402         -  while( db_step(&s)==SQLITE_ROW ){
          402  +  while( db_step(&s)==SQLITE4_ROW ){
   403    403       int rid = db_column_int(&s, 0);
   404    404       int size = db_column_int(&s, 1);
   405    405       if( size>=0 ){
   406    406         if( !bag_find(&bagDone, rid) ){
   407    407           Blob content;
   408    408           content_get(rid, &content);
   409    409           rebuild_step(rid, size, &content);
................................................................................
   445    445        "SELECT rid FROM event, blob"
   446    446        " WHERE blob.rid=event.objid"
   447    447        "   AND event.type='ci'"
   448    448        "   AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)"
   449    449        " ORDER BY event.mtime DESC"
   450    450     );
   451    451     topid = previd = 0;
   452         -  while( db_step(&q)==SQLITE_ROW ){
          452  +  while( db_step(&q)==SQLITE4_ROW ){
   453    453       rid = db_column_int(&q, 0);
   454    454       if( topid==0 ){
   455    455         topid = previd = rid;
   456    456       }else{
   457    457         if( content_deltify(rid, previd, 0)==0 && previd!=topid ){
   458    458           content_deltify(rid, topid, 0);
   459    459         }
................................................................................
   467    467        " WHERE NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)"
   468    468        "   AND mlink.fid=blob.rid"
   469    469        "   AND mlink.mid=plink.cid"
   470    470        "   AND plink.cid=mlink.mid"
   471    471        " ORDER BY mlink.fnid, plink.mtime DESC"
   472    472     );
   473    473     prevfnid = 0;
   474         -  while( db_step(&q)==SQLITE_ROW ){
          474  +  while( db_step(&q)==SQLITE4_ROW ){
   475    475       rid = db_column_int(&q, 0);
   476    476       fnid = db_column_int(&q, 1);
   477    477       if( prevfnid!=fnid ){
   478    478         prevfnid = fnid;
   479    479         topid = previd = rid;
   480    480       }else{
   481    481         if( content_deltify(rid, previd, 0)==0 && previd!=topid ){
................................................................................
   695    695       "INSERT OR IGNORE INTO xdone"
   696    696            " SELECT blob.rid FROM shun JOIN blob USING(uuid);"
   697    697     );
   698    698     db_prepare(&q,
   699    699       "SELECT rid FROM unclustered WHERE rid IN"
   700    700       " (SELECT rid FROM tagxref WHERE tagid=%d)", TAG_CLUSTER
   701    701     );
   702         -  while( db_step(&q)==SQLITE_ROW ){
          702  +  while( db_step(&q)==SQLITE4_ROW ){
   703    703       bag_insert(&pending, db_column_int(&q, 0));
   704    704     }
   705    705     db_finalize(&q);
   706    706     while( bag_count(&pending)>0 ){
   707    707       Manifest *p;
   708    708       int rid = bag_first(&pending);
   709    709       int i;
................................................................................
   732    732     n = db_int(0, "SELECT count(*) FROM /*scan*/"
   733    733                   "  (SELECT rid FROM blob EXCEPT SELECT x FROM xdone)");
   734    734     if( n==0 ){
   735    735       fossil_print("all artifacts reachable through clusters\n");
   736    736     }else{
   737    737       fossil_print("%d unreachable artifacts:\n", n);
   738    738       db_prepare(&q, "SELECT rid, uuid FROM blob WHERE rid NOT IN xdone");
   739         -    while( db_step(&q)==SQLITE_ROW ){
          739  +    while( db_step(&q)==SQLITE4_ROW ){
   740    740         fossil_print("  %3d %s\n", db_column_int(&q,0), db_column_text(&q,1));
   741    741       }
   742    742       db_finalize(&q);
   743    743     }
   744    744   }
   745    745   
   746    746   /*
................................................................................
   990    990     }
   991    991     totalSize = db_int(0, "SELECT count(*) FROM blob");
   992    992     db_prepare(&s,
   993    993        "SELECT rid, size FROM blob /*scan*/"
   994    994        " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
   995    995        "   AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)"
   996    996     );
   997         -  while( db_step(&s)==SQLITE_ROW ){
          997  +  while( db_step(&s)==SQLITE4_ROW ){
   998    998       int rid = db_column_int(&s, 0);
   999    999       int size = db_column_int(&s, 1);
  1000   1000       if( size>=0 ){
  1001   1001         Blob content;
  1002   1002         content_get(rid, &content);
  1003   1003         rebuild_step(rid, size, &content);
  1004   1004       }
  1005   1005     }
  1006   1006     db_finalize(&s);
  1007   1007     db_prepare(&s,
  1008   1008        "SELECT rid, size FROM blob"
  1009   1009        " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
  1010   1010     );
  1011         -  while( db_step(&s)==SQLITE_ROW ){
         1011  +  while( db_step(&s)==SQLITE4_ROW ){
  1012   1012       int rid = db_column_int(&s, 0);
  1013   1013       int size = db_column_int(&s, 1);
  1014   1014       if( size>=0 ){
  1015   1015         if( !bag_find(&bagDone, rid) ){
  1016   1016           Blob content;
  1017   1017           content_get(rid, &content);
  1018   1018           rebuild_step(rid, size, &content);

Changes to src/report.c.

    42     42     zScript = ticket_reportlist_code();
    43     43     if( g.thTrace ) Th_Trace("BEGIN_REPORTLIST_SCRIPT<br />\n", -1);
    44     44     
    45     45     blob_zero(&ril);
    46     46     ticket_init();
    47     47   
    48     48     db_prepare(&q, "SELECT rn, title, owner FROM reportfmt ORDER BY title");
    49         -  while( db_step(&q)==SQLITE_ROW ){
           49  +  while( db_step(&q)==SQLITE4_ROW ){
    50     50       const char *zTitle = db_column_text(&q, 1);
    51     51       const char *zOwner = db_column_text(&q, 2);
    52     52       if( zTitle[0] =='_' && !g.perm.TktFmt ){
    53     53         continue;
    54     54       }
    55     55       rn = db_column_int(&q, 0);
    56     56       cnt++;
................................................................................
   157    157     void *pError,
   158    158     int code,
   159    159     const char *zArg1,
   160    160     const char *zArg2,
   161    161     const char *zArg3,
   162    162     const char *zArg4
   163    163   ){
   164         -  int rc = SQLITE_OK;
          164  +  int rc = SQLITE4_OK;
   165    165     if( *(char**)pError ){
   166    166       /* We've already seen an error.  No need to continue. */
   167         -    return SQLITE_OK;
          167  +    return SQLITE4_OK;
   168    168     }
   169    169     switch( code ){
   170         -    case SQLITE_SELECT:
   171         -    case SQLITE_FUNCTION: {
          170  +    case SQLITE4_SELECT:
          171  +    case SQLITE4_FUNCTION: {
   172    172         break;
   173    173       }
   174         -    case SQLITE_READ: {
          174  +    case SQLITE4_READ: {
   175    175         static const char *azAllowed[] = {
   176    176            "ticket",
   177    177            "blob",
   178    178            "filename",
   179    179            "mlink",
   180    180            "plink",
   181    181            "event",
................................................................................
   184    184         };
   185    185         int i;
   186    186         for(i=0; i<sizeof(azAllowed)/sizeof(azAllowed[0]); i++){
   187    187           if( fossil_stricmp(zArg1, azAllowed[i])==0 ) break;
   188    188         }
   189    189         if( i>=sizeof(azAllowed)/sizeof(azAllowed[0]) ){
   190    190           *(char**)pError = mprintf("access to table \"%s\" is restricted",zArg1);
   191         -        rc = SQLITE_DENY;
          191  +        rc = SQLITE4_DENY;
   192    192         }else if( !g.perm.RdAddr && strncmp(zArg2, "private_", 8)==0 ){
   193         -        rc = SQLITE_IGNORE;
          193  +        rc = SQLITE4_IGNORE;
   194    194         }
   195    195         break;
   196    196       }
   197    197       default: {
   198    198         *(char**)pError = mprintf("only SELECT statements are allowed");
   199         -      rc = SQLITE_DENY;
          199  +      rc = SQLITE4_DENY;
   200    200         break;
   201    201       }
   202    202     }
   203    203     return rc;
   204    204   }
   205    205   
   206    206   /*
   207    207   ** Activate the query authorizer
   208    208   */
   209    209   static void report_restrict_sql(char **pzErr){
   210    210     (void)fossil_localtime(0);
   211         -  sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)pzErr);
          211  +  sqlite4_set_authorizer(g.db, report_query_authorizer, (void*)pzErr);
   212    212   }
   213    213   static void report_unrestrict_sql(void){
   214         -  sqlite3_set_authorizer(g.db, 0, 0);
          214  +  sqlite4_set_authorizer(g.db, 0, 0);
   215    215   }
   216    216   
   217    217   
   218    218   /*
   219    219   ** Check the given SQL to see if is a valid query that does not
   220    220   ** attempt to do anything dangerous.  Return 0 on success and a
   221    221   ** pointer to an error message string (obtained from malloc) if
   222    222   ** there is a problem.
   223    223   */
   224    224   char *verify_sql_statement(char *zSql){
   225    225     int i;
   226    226     char *zErr = 0;
   227    227     const char *zTail;
   228         -  sqlite3_stmt *pStmt;
          228  +  sqlite4_stmt *pStmt;
   229    229     int rc;
   230    230   
   231    231     /* First make sure the SQL is a single query command by verifying that
   232    232     ** the first token is "SELECT" and that there are no unquoted semicolons.
   233    233     */
   234    234     for(i=0; fossil_isspace(zSql[i]); i++){}
   235    235     if( fossil_strnicmp(&zSql[i],"select",6)!=0 ){
................................................................................
   236    236       return mprintf("The SQL must be a SELECT statement");
   237    237     }
   238    238     for(i=0; zSql[i]; i++){
   239    239       if( zSql[i]==';' ){
   240    240         int bad;
   241    241         int c = zSql[i+1];
   242    242         zSql[i+1] = 0;
   243         -      bad = sqlite3_complete(zSql);
          243  +      bad = sqlite4_complete(zSql);
   244    244         zSql[i+1] = c;
   245    245         if( bad ){
   246    246           /* A complete statement basically means that an unquoted semi-colon
   247    247           ** was found. We don't actually check what's after that.
   248    248           */
   249    249           return mprintf("Semi-colon detected! "
   250    250                          "Only a single SQL statement is allowed");
   251    251         }
   252    252       }
   253    253     }
   254    254     
   255    255     /* Compile the statement and check for illegal accesses or syntax errors. */
   256    256     report_restrict_sql(&zErr);
   257         -  rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, &zTail);
   258         -  if( rc!=SQLITE_OK ){
   259         -    zErr = mprintf("Syntax error: %s", sqlite3_errmsg(g.db));
          257  +  rc = sqlite4_prepare(g.db, zSql, -1, &pStmt, &zTail);
          258  +  if( rc!=SQLITE4_OK ){
          259  +    zErr = mprintf("Syntax error: %s", sqlite4_errmsg(g.db));
   260    260     }
   261         -  if( !sqlite3_stmt_readonly(pStmt) ){
          261  +  if( !sqlite4_stmt_readonly(pStmt) ){
   262    262       zErr = mprintf("SQL must not modify the database");
   263    263     }
   264    264     if( pStmt ){
   265         -    sqlite3_finalize(pStmt);
          265  +    sqlite4_finalize(pStmt);
   266    266     }
   267    267     report_unrestrict_sql();
   268    268     return zErr;
   269    269   }
   270    270   
   271    271   /*
   272    272   ** WEBPAGE: /rptsql
................................................................................
   284    284       login_needed();
   285    285       return;
   286    286     }
   287    287     rn = atoi(PD("rn","0"));
   288    288     db_prepare(&q, "SELECT title, sqlcode, owner, cols "
   289    289                      "FROM reportfmt WHERE rn=%d",rn);
   290    290     style_header("SQL For Report Format Number %d", rn);
   291         -  if( db_step(&q)!=SQLITE_ROW ){
          291  +  if( db_step(&q)!=SQLITE4_ROW ){
   292    292       @ <p>Unknown report number: %d(rn)</p>
   293    293       style_footer();
   294    294       return;
   295    295     }
   296    296     zTitle = db_column_text(&q, 0);
   297    297     zSQL = db_column_text(&q, 1);
   298    298     zOwner = db_column_text(&q, 2);
................................................................................
   401    401       zTitle = "";
   402    402       zSQL = ticket_report_template();
   403    403       zClrKey = ticket_key_template();
   404    404     }else{
   405    405       Stmt q;
   406    406       db_prepare(&q, "SELECT title, sqlcode, owner, cols "
   407    407                        "FROM reportfmt WHERE rn=%d",rn);
   408         -    if( db_step(&q)==SQLITE_ROW ){
          408  +    if( db_step(&q)==SQLITE4_ROW ){
   409    409         zTitle = db_column_malloc(&q, 0);
   410    410         zSQL = db_column_malloc(&q, 1);
   411    411         zOwner = db_column_malloc(&q, 2);
   412    412         zClrKey = db_column_malloc(&q, 3);
   413    413       }
   414    414       db_finalize(&q);
   415    415       if( P("copy") ){
................................................................................
   639    639   
   640    640     /* Do initialization
   641    641     */
   642    642     if( pState->nCount==0 ){
   643    643       /* Turn off the authorizer.  It is no longer doing anything since the
   644    644       ** query has already been prepared.
   645    645       */
   646         -    sqlite3_set_authorizer(g.db, 0, 0);
          646  +    sqlite4_set_authorizer(g.db, 0, 0);
   647    647   
   648    648       /* Figure out the number of columns, the column that determines background
   649    649       ** color, and whether or not this row of data is represented by multiple
   650    650       ** rows in the table.
   651    651       */
   652    652       pState->nCol = 0;
   653    653       pState->isMultirow = 0;
................................................................................
   832    832     @ </table>
   833    833   }
   834    834   
   835    835   /*
   836    836   ** Execute a single read-only SQL statement.  Invoke xCallback() on each
   837    837   ** row.
   838    838   */
   839         -int sqlite3_exec_readonly(
   840         -  sqlite3 *db,                /* The database on which the SQL executes */
          839  +int sqlite4_exec_readonly(
          840  +  sqlite4 *db,                /* The database on which the SQL executes */
   841    841     const char *zSql,           /* The SQL to be executed */
   842         -  sqlite3_callback xCallback, /* Invoke this callback routine */
          842  +  sqlite4_callback xCallback, /* Invoke this callback routine */
   843    843     void *pArg,                 /* First argument to xCallback() */
   844    844     char **pzErrMsg             /* Write error messages here */
   845    845   ){
   846         -  int rc = SQLITE_OK;         /* Return code */
          846  +  int rc = SQLITE4_OK;         /* Return code */
   847    847     const char *zLeftover;      /* Tail of unprocessed SQL */
   848         -  sqlite3_stmt *pStmt = 0;    /* The current SQL statement */
          848  +  sqlite4_stmt *pStmt = 0;    /* The current SQL statement */
   849    849     char **azCols = 0;          /* Names of result columns */
   850    850     int nCol;                   /* Number of columns of output */
   851    851     char **azVals = 0;          /* Text of all output columns */
   852    852     int i;                      /* Loop counter */
   853    853   
   854    854     pStmt = 0;
   855         -  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
   856         -  assert( rc==SQLITE_OK || pStmt==0 );
   857         -  if( rc!=SQLITE_OK ){
          855  +  rc = sqlite4_prepare(db, zSql, -1, &pStmt, &zLeftover);
          856  +  assert( rc==SQLITE4_OK || pStmt==0 );
          857  +  if( rc!=SQLITE4_OK ){
   858    858       return rc;
   859    859     }
   860    860     if( !pStmt ){
   861    861       /* this happens for a comment or white-space */
   862         -    return SQLITE_OK;
          862  +    return SQLITE4_OK;
   863    863     }
   864         -  if( !sqlite3_stmt_readonly(pStmt) ){
   865         -    sqlite3_finalize(pStmt);
   866         -    return SQLITE_ERROR;
          864  +  if( !sqlite4_stmt_readonly(pStmt) ){
          865  +    sqlite4_finalize(pStmt);
          866  +    return SQLITE4_ERROR;
   867    867     }
   868    868   
   869         -  nCol = sqlite3_column_count(pStmt);
          869  +  nCol = sqlite4_column_count(pStmt);
   870    870     azVals = fossil_malloc(2*nCol*sizeof(const char*) + 1);
   871         -  while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
          871  +  while( (rc = sqlite4_step(pStmt))==SQLITE4_ROW ){
   872    872       if( azCols==0 ){
   873    873         azCols = &azVals[nCol];
   874    874         for(i=0; i<nCol; i++){
   875         -        azCols[i] = (char *)sqlite3_column_name(pStmt, i);
          875  +        azCols[i] = (char *)sqlite4_column_name(pStmt, i);
   876    876         }
   877    877       }
   878    878       for(i=0; i<nCol; i++){
   879         -      azVals[i] = (char *)sqlite3_column_text(pStmt, i);
          879  +      azVals[i] = (char *)sqlite4_column_text(pStmt, i);
   880    880       }
   881    881       if( xCallback(pArg, nCol, azVals, azCols) ){
   882    882         break;
   883    883       }
   884    884     }
   885         -  rc = sqlite3_finalize(pStmt);
          885  +  rc = sqlite4_finalize(pStmt);
   886    886     fossil_free(azVals);
   887    887     return rc;
   888    888   }
   889    889   
   890    890   
   891    891   /*
   892    892   ** WEBPAGE: /rptview
................................................................................
   915    915       cgi_redirect("reportlist");
   916    916       return;
   917    917     }
   918    918     tabs = P("tablist")!=0;
   919    919     /* view_add_functions(tabs); */
   920    920     db_prepare(&q,
   921    921       "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
   922         -  if( db_step(&q)!=SQLITE_ROW ){
          922  +  if( db_step(&q)!=SQLITE4_ROW ){
   923    923       cgi_redirect("reportlist");
   924    924       return;
   925    925     }
   926    926     zTitle = db_column_malloc(&q, 0);
   927    927     zSql = db_column_malloc(&q, 1);
   928    928     zOwner = db_column_malloc(&q, 2);
   929    929     zClrKey = db_column_malloc(&q, 3);
................................................................................
   965    965       style_header(zTitle);
   966    966       output_color_key(zClrKey, 1, 
   967    967           "border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"report\"");
   968    968       @ <table border="1" cellpadding="2" cellspacing="0" class="report">
   969    969       sState.rn = rn;
   970    970       sState.nCount = 0;
   971    971       report_restrict_sql(&zErr1);
   972         -    sqlite3_exec_readonly(g.db, zSql, generate_html, &sState, &zErr2);
          972  +    sqlite4_exec_readonly(g.db, zSql, generate_html, &sState, &zErr2);
   973    973       report_unrestrict_sql();
   974    974       @ </table>
   975    975       if( zErr1 ){
   976    976         @ <p class="reportError">Error: %h(zErr1)</p>
   977    977       }else if( zErr2 ){
   978    978         @ <p class="reportError">Error: %h(zErr2)</p>
   979    979       }
   980    980       style_footer();
   981    981     }else{
   982    982       report_restrict_sql(&zErr1);
   983         -    sqlite3_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
          983  +    sqlite4_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
   984    984       report_unrestrict_sql();
   985    985       cgi_set_content_type("text/plain");
   986    986     }
   987    987   }
   988    988   
   989    989   /*
   990    990   ** report number for full table ticket export
................................................................................
  1004   1004     Stmt q;
  1005   1005     char const aRptOutFrmt[] = "%s\t%s\n";
  1006   1006   
  1007   1007     fossil_print("Available reports:\n");
  1008   1008     fossil_print(aRptOutFrmt,"report number","report title");
  1009   1009     fossil_print(aRptOutFrmt,zFullTicketRptRn,zFullTicketRptTitle);
  1010   1010     db_prepare(&q,"SELECT rn,title FROM reportfmt ORDER BY rn");
  1011         -  while( db_step(&q)==SQLITE_ROW ){
         1011  +  while( db_step(&q)==SQLITE4_ROW ){
  1012   1012       const char *zRn = db_column_text(&q, 0);
  1013   1013       const char *zTitle = db_column_text(&q, 1);
  1014   1014   
  1015   1015       fossil_print(aRptOutFrmt,zRn,zTitle);
  1016   1016     }
  1017   1017     db_finalize(&q);
  1018   1018   }
................................................................................
  1114   1114       if( rn ){
  1115   1115         db_prepare(&q,
  1116   1116          "SELECT sqlcode FROM reportfmt WHERE rn=%d", rn);
  1117   1117       }else{
  1118   1118         db_prepare(&q,
  1119   1119          "SELECT sqlcode FROM reportfmt WHERE title=%Q", zRep);
  1120   1120       }
  1121         -    if( db_step(&q)!=SQLITE_ROW ){
         1121  +    if( db_step(&q)!=SQLITE4_ROW ){
  1122   1122         db_finalize(&q);
  1123   1123         rpt_list_reports();
  1124   1124         fossil_fatal("unknown report format(%s)!",zRep);
  1125   1125       }
  1126   1126       zSql = db_column_malloc(&q, 0);
  1127   1127       db_finalize(&q);
  1128   1128     }
................................................................................
  1129   1129     if( zFilter ){
  1130   1130       zSql = mprintf("SELECT * FROM (%s) WHERE %s",zSql,zFilter);
  1131   1131     }
  1132   1132     count = 0;
  1133   1133     tktEncode = enc;
  1134   1134     zSep = zSepIn;
  1135   1135     report_restrict_sql(&zErr1);
  1136         -  sqlite3_exec_readonly(g.db, zSql, output_separated_file, &count, &zErr2);
         1136  +  sqlite4_exec_readonly(g.db, zSql, output_separated_file, &count, &zErr2);
  1137   1137     report_unrestrict_sql();
  1138   1138     if( zFilter ){
  1139   1139       free(zSql);
  1140   1140     }
  1141   1141   }

Changes to src/rss.c.

   102    102     @     <link>%s(g.zBaseURL)</link>
   103    103     @     <description>%h(zProjectDescr)</description>
   104    104     @     <pubDate>%s(zPubDate)</pubDate>
   105    105     @     <generator>Fossil version %s(MANIFEST_VERSION) %s(MANIFEST_DATE)</generator>
   106    106     free(zPubDate);
   107    107     db_prepare(&q, blob_str(&bSQL));
   108    108     blob_reset( &bSQL );
   109         -  while( db_step(&q)==SQLITE_ROW && nLine<=nLimit ){
          109  +  while( db_step(&q)==SQLITE4_ROW && nLine<=nLimit ){
   110    110       const char *zId = db_column_text(&q, 1);
   111    111       const char *zCom = db_column_text(&q, 3);
   112    112       const char *zAuthor = db_column_text(&q, 4);
   113    113       char *zPrefix = "";
   114    114       char *zDate;
   115    115       int nChild = db_column_int(&q, 5);
   116    116       int nParent = db_column_int(&q, 6);

Changes to src/search.c.

   109    109   
   110    110     memset(seen, 0, sizeof(seen));
   111    111     for(i=0; zDoc[i]; i++){
   112    112       char c = zDoc[i];
   113    113       if( isBoundary[c&0xff] ) continue;
   114    114       for(j=0; j<p->nTerm; j++){
   115    115         int n = p->a[j].n;
   116         -      if( sqlite3_strnicmp(p->a[j].z, &zDoc[i], n)==0 ){
          116  +      if( sqlite4_strnicmp(p->a[j].z, &zDoc[i], n)==0 ){
   117    117           score += 1;
   118    118           if( !seen[j] ){
   119    119             if( isBoundary[zDoc[i+n]&0xff] ) score += 10;
   120    120             seen[j] = 1;
   121    121           }
   122    122           if( j==iPrev+1 ){
   123    123             score += iBonus;
................................................................................
   141    141   }
   142    142   
   143    143   /*
   144    144   ** This is an SQLite function that scores its input using
   145    145   ** a pre-computed pattern.
   146    146   */
   147    147   static void search_score_sqlfunc(
   148         -  sqlite3_context *context,
          148  +  sqlite4_context *context,
   149    149     int argc,
   150         -  sqlite3_value **argv
          150  +  sqlite4_value **argv
   151    151   ){
   152         -  Search *p = (Search*)sqlite3_user_data(context);
   153         -  int score = search_score(p, (const char*)sqlite3_value_text(argv[0]));
   154         -  sqlite3_result_int(context, score);
          152  +  Search *p = (Search*)sqlite4_user_data(context);
          153  +  int score = search_score(p, (const char*)sqlite4_value_text(argv[0]));
          154  +  sqlite4_result_int(context, score);
   155    155   }
   156    156   
   157    157   /*
   158    158   ** Register the "score()" SQL function to score its input text
   159    159   ** using the given Search object.  Once this function is registered,
   160    160   ** do not delete the Search object.
   161    161   */
   162    162   void search_sql_setup(Search *p){
   163         -  sqlite3_create_function(g.db, "score", 1, SQLITE_UTF8, p,
          163  +  sqlite4_create_function(g.db, "score", 1, SQLITE4_UTF8, p,
   164    164        search_score_sqlfunc, 0, 0);
   165    165   }
   166    166   
   167    167   /*
   168    168   ** Testing the search function.
   169    169   **
   170    170   ** COMMAND: search*

Changes to src/setup.c.

   131    131        "SELECT uid, login, cap, info, 1 FROM user"
   132    132        " WHERE login IN ('anonymous','nobody','developer','reader') "
   133    133        " UNION ALL "
   134    134        "SELECT uid, login, cap, info, 2 FROM user"
   135    135        " WHERE login NOT IN ('anonymous','nobody','developer','reader') "
   136    136        "ORDER BY 5, 2"
   137    137     );
   138         -  while( db_step(&s)==SQLITE_ROW ){
          138  +  while( db_step(&s)==SQLITE4_ROW ){
   139    139       int iLevel = db_column_int(&s, 4);
   140    140       const char *zCap = db_column_text(&s, 2);
   141    141       const char *zLogin = db_column_text(&s, 1);
   142    142       if( iLevel>prevLevel ){
   143    143         if( prevLevel>0 ){
   144    144           @ <tr><td colspan="3"><hr></td></tr>
   145    145         }
................................................................................
  1066   1066          "SELECT value,"
  1067   1067          "       (SELECT value FROM config"
  1068   1068          "         WHERE name=('peer-name-' || substr(x.name,11)))"
  1069   1069          "  FROM config AS x"
  1070   1070          " WHERE name GLOB 'peer-repo-*'"
  1071   1071          " ORDER BY value"
  1072   1072       );
  1073         -    while( db_step(&q)==SQLITE_ROW ){
         1073  +    while( db_step(&q)==SQLITE4_ROW ){
  1074   1074         const char *zRepo = db_column_text(&q, 0);
  1075   1075         const char *zTitle = db_column_text(&q, 1);
  1076   1076         n++;
  1077   1077         @ <tr><td align="right">%d(n).</td><td width="4">
  1078   1078         @ <td>%h(zTitle)<td width="10"><td>%h(zRepo)</tr>
  1079   1079       }
  1080   1080       db_finalize(&q);
................................................................................
  1567   1567     @ SQL:<br />
  1568   1568     @ <textarea name="q" rows="5" cols="80">%h(zQ)</textarea><br />
  1569   1569     @ <input type="submit" name="go" value="Run SQL">
  1570   1570     @ <input type="submit" name="schema" value="Show Schema">
  1571   1571     @ <input type="submit" name="tablelist" value="List Tables">
  1572   1572     @ </form>
  1573   1573     if( P("schema") ){
  1574         -    zQ = sqlite3_mprintf(
         1574  +    zQ = sqlite4_mprintf(0, 
  1575   1575               "SELECT sql FROM %s.sqlite_master WHERE sql IS NOT NULL",
  1576   1576               db_name("repository"));
  1577   1577       go = 1;
  1578   1578     }else if( P("tablelist") ){
  1579         -    zQ = sqlite3_mprintf(
         1579  +    zQ = sqlite4_mprintf(0, 
  1580   1580               "SELECT name FROM %s.sqlite_master WHERE type='table'"
  1581   1581               " ORDER BY name",
  1582   1582               db_name("repository"));
  1583   1583       go = 1;
  1584   1584     }
  1585   1585     if( go ){
  1586         -    sqlite3_stmt *pStmt;
         1586  +    sqlite4_stmt *pStmt;
  1587   1587       int rc;
  1588   1588       const char *zTail;
  1589   1589       int nCol;
  1590   1590       int nRow = 0;
  1591   1591       int i;
  1592   1592       @ <hr />
  1593   1593       login_verify_csrf_secret();
  1594         -    rc = sqlite3_prepare_v2(g.db, zQ, -1, &pStmt, &zTail);
  1595         -    if( rc!=SQLITE_OK ){
  1596         -      @ <div class="generalError">%h(sqlite3_errmsg(g.db))</div>
  1597         -      sqlite3_finalize(pStmt);
         1594  +    rc = sqlite4_prepare(g.db, zQ, -1, &pStmt, &zTail);
         1595  +    if( rc!=SQLITE4_OK ){
         1596  +      @ <div class="generalError">%h(sqlite4_errmsg(g.db))</div>
         1597  +      sqlite4_finalize(pStmt);
  1598   1598       }else if( pStmt==0 ){
  1599   1599         /* No-op */
  1600         -    }else if( (nCol = sqlite3_column_count(pStmt))==0 ){
  1601         -      sqlite3_step(pStmt);
  1602         -      rc = sqlite3_finalize(pStmt);
         1600  +    }else if( (nCol = sqlite4_column_count(pStmt))==0 ){
         1601  +      sqlite4_step(pStmt);
         1602  +      rc = sqlite4_finalize(pStmt);
  1603   1603         if( rc ){
  1604         -        @ <div class="generalError">%h(sqlite3_errmsg(g.db))</div>
         1604  +        @ <div class="generalError">%h(sqlite4_errmsg(g.db))</div>
  1605   1605         }
  1606   1606       }else{
  1607   1607         @ <table border=1>
  1608         -      while( sqlite3_step(pStmt)==SQLITE_ROW ){
         1608  +      while( sqlite4_step(pStmt)==SQLITE4_ROW ){
  1609   1609           if( nRow==0 ){
  1610   1610             @ <tr>
  1611   1611             for(i=0; i<nCol; i++){
  1612         -            @ <th>%h(sqlite3_column_name(pStmt, i))</th>
         1612  +            @ <th>%h(sqlite4_column_name(pStmt, i))</th>
  1613   1613             }
  1614   1614             @ </tr>
  1615   1615           }
  1616   1616           nRow++;
  1617   1617           @ <tr>
  1618   1618           for(i=0; i<nCol; i++){
  1619         -          switch( sqlite3_column_type(pStmt, i) ){
  1620         -            case SQLITE_INTEGER:
  1621         -            case SQLITE_FLOAT: {
         1619  +          switch( sqlite4_column_type(pStmt, i) ){
         1620  +            case SQLITE4_INTEGER:
         1621  +            case SQLITE4_FLOAT: {
  1622   1622                  @ <td align="right" valign="top">
  1623         -               @ %s(sqlite3_column_text(pStmt, i))</td>
         1623  +               @ %s(sqlite4_column_text(pStmt, i))</td>
  1624   1624                  break;
  1625   1625               }
  1626         -            case SQLITE_NULL: {
         1626  +            case SQLITE4_NULL: {
  1627   1627                  @ <td valign="top" align="center"><i>NULL</i></td>
  1628   1628                  break;
  1629   1629               }
  1630         -            case SQLITE_TEXT: {
  1631         -               const char *zText = (const char*)sqlite3_column_text(pStmt, i);
         1630  +            case SQLITE4_TEXT: {
         1631  +               const char *zText = (const char*)sqlite4_column_text(pStmt, i);
  1632   1632                  @ <td align="left" valign="top"
  1633   1633                  @ style="white-space:pre;">%h(zText)</td>
  1634   1634                  break;
  1635   1635               }
  1636         -            case SQLITE_BLOB: {
         1636  +            case SQLITE4_BLOB: {
  1637   1637                  @ <td valign="top" align="center">
  1638         -               @ <i>%d(sqlite3_column_bytes(pStmt, i))-byte BLOB</i></td>
         1638  +               @ <i>%d(sqlite4_column_bytes(pStmt, i))-byte BLOB</i></td>
  1639   1639                  break;
  1640   1640               }
  1641   1641             }
  1642   1642           }
  1643   1643           @ </tr>
  1644   1644         }
  1645         -      sqlite3_finalize(pStmt);
         1645  +      sqlite4_finalize(pStmt);
  1646   1646         @ </table>
  1647   1647       }
  1648   1648     }
  1649   1649     style_footer();
  1650   1650   }

Changes to src/sha1.c.

   411    411   ** (1) The cleartext password
   412    412   ** (2) The login name
   413    413   ** (3) The project code
   414    414   **
   415    415   ** Returns sha1($password/$login/$projcode).
   416    416   */
   417    417   void sha1_shared_secret_sql_function(
   418         -  sqlite3_context *context,
          418  +  sqlite4_context *context,
   419    419     int argc,
   420         -  sqlite3_value **argv
          420  +  sqlite4_value **argv
   421    421   ){
   422    422     const char *zPw;
   423    423     const char *zLogin;
   424    424     const char *zProjid;
   425    425   
   426    426     assert( argc==2 || argc==3 );
   427         -  zPw = (const char*)sqlite3_value_text(argv[0]);
          427  +  zPw = (const char*)sqlite4_value_text(argv[0]);
   428    428     if( zPw==0 || zPw[0]==0 ) return;
   429         -  zLogin = (const char*)sqlite3_value_text(argv[1]);
          429  +  zLogin = (const char*)sqlite4_value_text(argv[1]);
   430    430     if( zLogin==0 ) return;
   431    431     if( argc==3 ){
   432         -    zProjid = (const char*)sqlite3_value_text(argv[2]);
          432  +    zProjid = (const char*)sqlite4_value_text(argv[2]);
   433    433       if( zProjid && zProjid[0]==0 ) zProjid = 0;
   434    434     }else{
   435    435       zProjid = 0;
   436    436     }
   437         -  sqlite3_result_text(context, sha1_shared_secret(zPw, zLogin, zProjid), -1,
          437  +  sqlite4_result_text(context, sha1_shared_secret(zPw, zLogin, zProjid), -1,
   438    438                         fossil_free);
   439    439   }
   440    440   
   441    441   /*
   442    442   ** COMMAND: sha1sum*
   443    443   ** %fossil sha1sum FILE...
   444    444   **

Changes to src/shell.c.

    16     16   /* This needs to come before any includes for MSVC compiler */
    17     17   #define _CRT_SECURE_NO_WARNINGS
    18     18   #endif
    19     19   
    20     20   /*
    21     21   ** Enable large-file support for fopen() and friends on unix.
    22     22   */
    23         -#ifndef SQLITE_DISABLE_LFS
           23  +#ifndef SQLITE4_DISABLE_LFS
    24     24   # define _LARGE_FILE       1
    25     25   # ifndef _FILE_OFFSET_BITS
    26     26   #   define _FILE_OFFSET_BITS 64
    27     27   # endif
    28     28   # define _LARGEFILE_SOURCE 1
    29     29   #endif
    30     30   
    31     31   #include <stdlib.h>
    32     32   #include <string.h>
    33     33   #include <stdio.h>
    34     34   #include <assert.h>
    35         -#include "sqlite3.h"
           35  +#include "sqlite4.h"
    36     36   #include <ctype.h>
    37     37   #include <stdarg.h>
    38     38   
    39         -#if !defined(_WIN32) && !defined(WIN32)
           39  +#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__)
    40     40   # include <signal.h>
    41     41   # if !defined(__RTP__) && !defined(_WRS_KERNEL)
    42     42   #  include <pwd.h>
    43     43   # endif
    44     44   # include <unistd.h>
    45     45   # include <sys/types.h>
    46     46   #endif
           47  +
           48  +#ifdef __OS2__
           49  +# include <unistd.h>
           50  +#endif
    47     51   
    48     52   #ifdef HAVE_EDITLINE
    49     53   # include <editline/editline.h>
    50     54   #endif
    51     55   #if defined(HAVE_READLINE) && HAVE_READLINE==1
    52     56   # include <readline/readline.h>
    53     57   # include <readline/history.h>
................................................................................
    60     64   # define stifle_history(X)
    61     65   #endif
    62     66   
    63     67   #if defined(_WIN32) || defined(WIN32)
    64     68   # include <io.h>
    65     69   #define isatty(h) _isatty(h)
    66     70   #define access(f,m) _access((f),(m))
    67         -#define popen(a,b) _popen((a),(b))
    68         -#define pclose(x) _pclose(x)
    69     71   #else
    70     72   /* Make sure isatty() has a prototype.
    71     73   */
    72     74   extern int isatty(int);
    73     75   #endif
    74     76   
    75     77   #if defined(_WIN32_WCE)
................................................................................
    84     86   static int enableTimer = 0;
    85     87   
    86     88   /* ctype macros that work with signed characters */
    87     89   #define IsSpace(X)  isspace((unsigned char)X)
    88     90   #define IsDigit(X)  isdigit((unsigned char)X)
    89     91   #define ToLower(X)  (char)tolower((unsigned char)X)
    90     92   
    91         -#if !defined(_WIN32) && !defined(WIN32) && !defined(_WRS_KERNEL)
           93  +#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL)
    92     94   #include <sys/time.h>
    93     95   #include <sys/resource.h>
    94     96   
    95     97   /* Saved resource information for the beginning of an operation */
    96     98   static struct rusage sBegin;
    97     99   
    98    100   /*
................................................................................
   223    225   static int stdin_is_interactive = 1;
   224    226   
   225    227   /*
   226    228   ** The following is the open SQLite database.  We make a pointer
   227    229   ** to this database a static variable so that it can be accessed
   228    230   ** by the SIGINT handler to interrupt database processing.
   229    231   */
   230         -static sqlite3 *db = 0;
          232  +static sqlite4 *db = 0;
   231    233   
   232    234   /*
   233    235   ** True if an interrupt (Control-C) has been received.
   234    236   */
   235    237   static volatile int seenInterrupt = 0;
   236    238   
   237    239   /*
................................................................................
   246    248   */
   247    249   static char mainPrompt[20];     /* First line prompt. default: "sqlite> "*/
   248    250   static char continuePrompt[20]; /* Continuation prompt. default: "   ...> " */
   249    251   
   250    252   /*
   251    253   ** Write I/O traces to the following stream.
   252    254   */
   253         -#ifdef SQLITE_ENABLE_IOTRACE
          255  +#ifdef SQLITE4_ENABLE_IOTRACE
   254    256   static FILE *iotrace = 0;
   255    257   #endif
   256    258   
   257    259   /*
   258    260   ** This routine works like printf in that its first argument is a
   259    261   ** format string and subsequent arguments are values to be substituted
   260    262   ** in place of % fields.  The result of formatting this string
   261    263   ** is written to iotrace.
   262    264   */
   263         -#ifdef SQLITE_ENABLE_IOTRACE
          265  +#ifdef SQLITE4_ENABLE_IOTRACE
   264    266   static void iotracePrintf(const char *zFormat, ...){
   265    267     va_list ap;
   266    268     char *z;
   267    269     if( iotrace==0 ) return;
   268    270     va_start(ap, zFormat);
   269         -  z = sqlite3_vmprintf(zFormat, ap);
          271  +  z = sqlite4_vmprintf(0, zFormat, ap);
   270    272     va_end(ap);
   271    273     fprintf(iotrace, "%s", z);
   272         -  sqlite3_free(z);
          274  +  sqlite4_free(0, z);
   273    275   }
   274    276   #endif
   275    277   
   276    278   
   277    279   /*
   278    280   ** Determines if a string is a number of not.
   279    281   */
................................................................................
   301    303     return *z==0;
   302    304   }
   303    305   
   304    306   /*
   305    307   ** A global char* and an SQL function to access its current value 
   306    308   ** from within an SQL statement. This program used to use the 
   307    309   ** sqlite_exec_printf() API to substitue a string into an SQL statement.
   308         -** The correct way to do this with sqlite3 is to use the bind API, but
          310  +** The correct way to do this with sqlite4 is to use the bind API, but
   309    311   ** since the shell is built around the callback paradigm it would be a lot
   310    312   ** of work. Instead just use this hack, which is quite harmless.
   311    313   */
   312    314   static const char *zShellStatic = 0;
   313    315   static void shellstaticFunc(
   314         -  sqlite3_context *context,
          316  +  sqlite4_context *context,
   315    317     int argc,
   316         -  sqlite3_value **argv
          318  +  sqlite4_value **argv
   317    319   ){
   318    320     assert( 0==argc );
   319    321     assert( zShellStatic );
   320    322     UNUSED_PARAMETER(argc);
   321    323     UNUSED_PARAMETER(argv);
   322         -  sqlite3_result_text(context, zShellStatic, -1, SQLITE_STATIC);
          324  +  sqlite4_result_text(context, zShellStatic, -1, SQLITE4_STATIC);
   323    325   }
   324    326   
   325    327   
   326    328   /*
   327    329   ** This routine reads a line of text from FILE in, stores
   328    330   ** the text in memory obtained from malloc() and returns a pointer
   329    331   ** to the text.  NULL is returned at end of file, or if malloc()
................................................................................
   408    410   
   409    411   /*
   410    412   ** An pointer to an instance of this structure is passed from
   411    413   ** the main program to the callback.  This is used to communicate
   412    414   ** state and mode information.
   413    415   */
   414    416   struct callback_data {
   415         -  sqlite3 *db;           /* The database */
          417  +  sqlite4 *db;           /* The database */
   416    418     int echoOn;            /* True to echo input commands */
   417    419     int statsOn;           /* True to display memory stats before each finalize */
   418    420     int cnt;               /* Number of records displayed so far */
   419    421     FILE *out;             /* Write results here */
   420         -  FILE *traceOut;        /* Output for sqlite3_trace() */
   421    422     int nErr;              /* Number of errors seen */
   422    423     int mode;              /* An output mode setting */
   423    424     int writableSchema;    /* True if PRAGMA writable_schema=ON */
   424    425     int showHeader;        /* True to show column names in List or Column mode */
   425    426     char *zDestTable;      /* Name of destination table when MODE_Insert */
   426    427     char separator[20];    /* Separator character for MODE_List */
   427    428     int colWidth[100];     /* Requested width of each column when in column mode*/
................................................................................
   430    431                            ** the database */
   431    432     struct previous_mode_data explainPrev;
   432    433                            /* Holds the mode information just before
   433    434                            ** .explain ON */
   434    435     char outfile[FILENAME_MAX]; /* Filename for *out */
   435    436     const char *zDbFilename;    /* name of the database file */
   436    437     const char *zVfs;           /* Name of VFS to use */
   437         -  sqlite3_stmt *pStmt;   /* Current statement if any. */
          438  +  sqlite4_stmt *pStmt;   /* Current statement if any. */
   438    439     FILE *pLog;            /* Write log output here */
   439    440   };
   440    441   
   441    442   /*
   442    443   ** These are the allowed modes.
   443    444   */
   444    445   #define MODE_Line     0  /* One column per line.  Blank line between records */
................................................................................
   475    476   static int strlen30(const char *z){
   476    477     const char *z2 = z;
   477    478     while( *z2 ){ z2++; }
   478    479     return 0x3fffffff & (int)(z2 - z);
   479    480   }
   480    481   
   481    482   /*
   482         -** A callback for the sqlite3_log() interface.
          483  +** A callback for the sqlite4_log() interface.
   483    484   */
   484    485   static void shellLog(void *pArg, int iErrCode, const char *zMsg){
   485    486     struct callback_data *p = (struct callback_data*)pArg;
   486    487     if( p->pLog==0 ) return;
   487    488     fprintf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
   488    489     fflush(p->pLog);
   489    490   }
................................................................................
   491    492   /*
   492    493   ** Output the given string as a hex-encoded blob (eg. X'1234' )
   493    494   */
   494    495   static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
   495    496     int i;
   496    497     char *zBlob = (char *)pBlob;
   497    498     fprintf(out,"X'");
   498         -  for(i=0; i<nBlob; i++){ fprintf(out,"%02x",zBlob[i]&0xff); }
          499  +  for(i=0; i<nBlob; i++){ fprintf(out,"%02x",zBlob[i]); }
   499    500     fprintf(out,"'");
   500    501   }
   501    502   
   502    503   /*
   503    504   ** Output the given string as a quoted string using SQL quoting conventions.
   504    505   */
   505    506   static void output_quoted_string(FILE *out, const char *z){
................................................................................
   653    654   #ifdef SIGINT
   654    655   /*
   655    656   ** This routine runs when the user presses Ctrl-C
   656    657   */
   657    658   static void interrupt_handler(int NotUsed){
   658    659     UNUSED_PARAMETER(NotUsed);
   659    660     seenInterrupt = 1;
   660         -  if( db ) sqlite3_interrupt(db);
          661  +  if( db ) sqlite4_interrupt(db);
   661    662   }
   662    663   #endif
   663    664   
   664    665   /*
   665    666   ** This is the callback routine that the shell
   666    667   ** invokes for each row of a query result.
   667    668   */
................................................................................
   812    813       }
   813    814       case MODE_Insert: {
   814    815         p->cnt++;
   815    816         if( azArg==0 ) break;
   816    817         fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
   817    818         for(i=0; i<nArg; i++){
   818    819           char *zSep = i>0 ? ",": "";
   819         -        if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
          820  +        if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE4_NULL) ){
   820    821             fprintf(p->out,"%sNULL",zSep);
   821         -        }else if( aiType && aiType[i]==SQLITE_TEXT ){
          822  +        }else if( aiType && aiType[i]==SQLITE4_TEXT ){
   822    823             if( zSep[0] ) fprintf(p->out,"%s",zSep);
   823    824             output_quoted_string(p->out, azArg[i]);
   824         -        }else if( aiType && (aiType[i]==SQLITE_INTEGER || aiType[i]==SQLITE_FLOAT) ){
          825  +        }else if( aiType && (aiType[i]==SQLITE4_INTEGER || aiType[i]==SQLITE4_FLOAT) ){
   825    826             fprintf(p->out,"%s%s",zSep, azArg[i]);
   826         -        }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
   827         -          const void *pBlob = sqlite3_column_blob(p->pStmt, i);
   828         -          int nBlob = sqlite3_column_bytes(p->pStmt, i);
          827  +        }else if( aiType && aiType[i]==SQLITE4_BLOB && p->pStmt ){
          828  +          const void *pBlob = sqlite4_column_blob(p->pStmt, i);
          829  +          int nBlob = sqlite4_column_bytes(p->pStmt, i);
   829    830             if( zSep[0] ) fprintf(p->out,"%s",zSep);
   830    831             output_hex_blob(p->out, pBlob, nBlob);
   831    832           }else if( isNumber(azArg[i], 0) ){
   832    833             fprintf(p->out,"%s%s",zSep, azArg[i]);
   833    834           }else{
   834    835             if( zSep[0] ) fprintf(p->out,"%s",zSep);
   835    836             output_quoted_string(p->out, azArg[i]);
................................................................................
   932    933     }
   933    934   
   934    935     return zIn;
   935    936   }
   936    937   
   937    938   
   938    939   /*
   939         -** Execute a query statement that will generate SQL output.  Print
   940         -** the result columns, comma-separated, on a line and then add a
   941         -** semicolon terminator to the end of that line.
          940  +** Execute a query statement that has a single result column.  Print
          941  +** that result column on a line by itself with a semicolon terminator.
   942    942   **
   943         -** If the number of columns is 1 and that column contains text "--"
   944         -** then write the semicolon on a separate line.  That way, if a 
   945         -** "--" comment occurs at the end of the statement, the comment
   946         -** won't consume the semicolon terminator.
          943  +** This is used, for example, to show the schema of the database by
          944  +** querying the SQLITE4_MASTER table.
   947    945   */
   948    946   static int run_table_dump_query(
   949    947     struct callback_data *p, /* Query context */
   950    948     const char *zSelect,     /* SELECT statement to extract content */
   951    949     const char *zFirstRow    /* Print before first row, if not NULL */
   952    950   ){
   953         -  sqlite3_stmt *pSelect;
          951  +  sqlite4_stmt *pSelect;
   954    952     int rc;
   955         -  int nResult;
   956         -  int i;
   957         -  const char *z;
   958         -  rc = sqlite3_prepare(p->db, zSelect, -1, &pSelect, 0);
   959         -  if( rc!=SQLITE_OK || !pSelect ){
   960         -    fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
          953  +  rc = sqlite4_prepare(p->db, zSelect, -1, &pSelect, 0);
          954  +  if( rc!=SQLITE4_OK || !pSelect ){
          955  +    fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite4_errmsg(p->db));
   961    956       p->nErr++;
   962    957       return rc;
   963    958     }
   964         -  rc = sqlite3_step(pSelect);
   965         -  nResult = sqlite3_column_count(pSelect);
   966         -  while( rc==SQLITE_ROW ){
          959  +  rc = sqlite4_step(pSelect);
          960  +  while( rc==SQLITE4_ROW ){
   967    961       if( zFirstRow ){
   968    962         fprintf(p->out, "%s", zFirstRow);
   969    963         zFirstRow = 0;
   970    964       }
   971         -    z = (const char*)sqlite3_column_text(pSelect, 0);
   972         -    fprintf(p->out, "%s", z);
   973         -    for(i=1; i<nResult; i++){ 
   974         -      fprintf(p->out, ",%s", sqlite3_column_text(pSelect, i));
   975         -    }
   976         -    if( z==0 ) z = "";
   977         -    while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
   978         -    if( z[0] ){
   979         -      fprintf(p->out, "\n;\n");
   980         -    }else{
   981         -      fprintf(p->out, ";\n");
   982         -    }    
   983         -    rc = sqlite3_step(pSelect);
          965  +    fprintf(p->out, "%s;\n", sqlite4_column_text(pSelect, 0));
          966  +    rc = sqlite4_step(pSelect);
   984    967     }
   985         -  rc = sqlite3_finalize(pSelect);
   986         -  if( rc!=SQLITE_OK ){
   987         -    fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
          968  +  rc = sqlite4_finalize(pSelect);
          969  +  if( rc!=SQLITE4_OK ){
          970  +    fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite4_errmsg(p->db));
   988    971       p->nErr++;
   989    972     }
   990    973     return rc;
   991    974   }
   992    975   
   993    976   /*
   994    977   ** Allocate space and save off current error string.
   995    978   */
   996    979   static char *save_err_msg(
   997         -  sqlite3 *db            /* Database to query */
          980  +  sqlite4 *db            /* Database to query */
   998    981   ){
   999         -  int nErrMsg = 1+strlen30(sqlite3_errmsg(db));
  1000         -  char *zErrMsg = sqlite3_malloc(nErrMsg);
          982  +  int nErrMsg = 1+strlen30(sqlite4_errmsg(db));
          983  +  char *zErrMsg = sqlite4_malloc(0, nErrMsg);
  1001    984     if( zErrMsg ){
  1002         -    memcpy(zErrMsg, sqlite3_errmsg(db), nErrMsg);
          985  +    memcpy(zErrMsg, sqlite4_errmsg(db), nErrMsg);
  1003    986     }
  1004    987     return zErrMsg;
  1005    988   }
  1006    989   
  1007    990   /*
  1008    991   ** Display memory stats.
  1009    992   */
  1010    993   static int display_stats(
  1011         -  sqlite3 *db,                /* Database to query */
          994  +  sqlite4 *db,                /* Database to query */
  1012    995     struct callback_data *pArg, /* Pointer to struct callback_data */
  1013    996     int bReset                  /* True to reset the stats */
  1014    997   ){
  1015    998     int iCur;
  1016    999     int iHiwtr;
  1017   1000   
  1018         -  if( pArg && pArg->out ){
  1019         -    
  1020         -    iHiwtr = iCur = -1;
  1021         -    sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
  1022         -    fprintf(pArg->out, "Memory Used:                         %d (max %d) bytes\n", iCur, iHiwtr);
  1023         -    iHiwtr = iCur = -1;
  1024         -    sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
  1025         -    fprintf(pArg->out, "Number of Outstanding Allocations:   %d (max %d)\n", iCur, iHiwtr);
  1026         -/*
  1027         -** Not currently used by the CLI.
  1028         -**    iHiwtr = iCur = -1;
  1029         -**    sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
  1030         -**    fprintf(pArg->out, "Number of Pcache Pages Used:         %d (max %d) pages\n", iCur, iHiwtr);
  1031         -*/
  1032         -    iHiwtr = iCur = -1;
  1033         -    sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
  1034         -    fprintf(pArg->out, "Number of Pcache Overflow Bytes:     %d (max %d) bytes\n", iCur, iHiwtr);
  1035         -/*
  1036         -** Not currently used by the CLI.
  1037         -**    iHiwtr = iCur = -1;
  1038         -**    sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
  1039         -**    fprintf(pArg->out, "Number of Scratch Allocations Used:  %d (max %d)\n", iCur, iHiwtr);
  1040         -*/
  1041         -    iHiwtr = iCur = -1;
  1042         -    sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
  1043         -    fprintf(pArg->out, "Number of Scratch Overflow Bytes:    %d (max %d) bytes\n", iCur, iHiwtr);
  1044         -    iHiwtr = iCur = -1;
  1045         -    sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
  1046         -    fprintf(pArg->out, "Largest Allocation:                  %d bytes\n", iHiwtr);
  1047         -    iHiwtr = iCur = -1;
  1048         -    sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
  1049         -    fprintf(pArg->out, "Largest Pcache Allocation:           %d bytes\n", iHiwtr);
  1050         -    iHiwtr = iCur = -1;
  1051         -    sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
  1052         -    fprintf(pArg->out, "Largest Scratch Allocation:          %d bytes\n", iHiwtr);
  1053         -#ifdef YYTRACKMAXSTACKDEPTH
  1054         -    iHiwtr = iCur = -1;
  1055         -    sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
  1056         -    fprintf(pArg->out, "Deepest Parser Stack:                %d (max %d)\n", iCur, iHiwtr);
  1057         -#endif
  1058         -  }
  1059         -
  1060   1001     if( pArg && pArg->out && db ){
  1061   1002       iHiwtr = iCur = -1;
  1062         -    sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, bReset);
         1003  +    sqlite4_db_status(db, SQLITE4_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, bReset);
  1063   1004       fprintf(pArg->out, "Lookaside Slots Used:                %d (max %d)\n", iCur, iHiwtr);
  1064         -    sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, bReset);
         1005  +    sqlite4_db_status(db, SQLITE4_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, bReset);
  1065   1006       fprintf(pArg->out, "Successful lookaside attempts:       %d\n", iHiwtr);
  1066         -    sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur, &iHiwtr, bReset);
         1007  +    sqlite4_db_status(db, SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur, &iHiwtr, bReset);
  1067   1008       fprintf(pArg->out, "Lookaside failures due to size:      %d\n", iHiwtr);
  1068         -    sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur, &iHiwtr, bReset);
         1009  +    sqlite4_db_status(db, SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur, &iHiwtr, bReset);
  1069   1010       fprintf(pArg->out, "Lookaside failures due to OOM:       %d\n", iHiwtr);
  1070   1011       iHiwtr = iCur = -1;
  1071         -    sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
  1072         -    fprintf(pArg->out, "Pager Heap Usage:                    %d bytes\n", iCur);    iHiwtr = iCur = -1;
  1073         -    sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
  1074         -    fprintf(pArg->out, "Page cache hits:                     %d\n", iCur);
  1075         -    iHiwtr = iCur = -1;
  1076         -    sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
  1077         -    fprintf(pArg->out, "Page cache misses:                   %d\n", iCur); 
  1078         -    iHiwtr = iCur = -1;
  1079         -    sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
  1080         -    fprintf(pArg->out, "Page cache writes:                   %d\n", iCur); 
  1081         -    iHiwtr = iCur = -1;
  1082         -    sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
         1012  +    sqlite4_db_status(db, SQLITE4_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
  1083   1013       fprintf(pArg->out, "Schema Heap Usage:                   %d bytes\n", iCur); 
  1084   1014       iHiwtr = iCur = -1;
  1085         -    sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
         1015  +    sqlite4_db_status(db, SQLITE4_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
  1086   1016       fprintf(pArg->out, "Statement Heap/Lookaside Usage:      %d bytes\n", iCur); 
  1087   1017     }
  1088   1018   
  1089   1019     if( pArg && pArg->out && db && pArg->pStmt ){
  1090         -    iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset);
         1020  +    iCur = sqlite4_stmt_status(pArg->pStmt, SQLITE4_STMTSTATUS_FULLSCAN_STEP, bReset);
  1091   1021       fprintf(pArg->out, "Fullscan Steps:                      %d\n", iCur);
  1092         -    iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
         1022  +    iCur = sqlite4_stmt_status(pArg->pStmt, SQLITE4_STMTSTATUS_SORT, bReset);
  1093   1023       fprintf(pArg->out, "Sort Operations:                     %d\n", iCur);
  1094         -    iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
         1024  +    iCur = sqlite4_stmt_status(pArg->pStmt, SQLITE4_STMTSTATUS_AUTOINDEX, bReset);
  1095   1025       fprintf(pArg->out, "Autoindex Inserts:                   %d\n", iCur);
  1096   1026     }
  1097   1027   
  1098   1028     return 0;
  1099   1029   }
  1100   1030   
  1101   1031   /*
  1102   1032   ** Execute a statement or set of statements.  Print 
  1103   1033   ** any result rows/columns depending on the current mode 
  1104   1034   ** set via the supplied callback.
  1105   1035   **
  1106         -** This is very similar to SQLite's built-in sqlite3_exec() 
         1036  +** This is very similar to SQLite's built-in sqlite4_exec() 
  1107   1037   ** function except it takes a slightly different callback 
  1108   1038   ** and callback data argument.
  1109   1039   */
  1110   1040   static int shell_exec(
  1111         -  sqlite3 *db,                                /* An open database */
         1041  +  sqlite4 *db,                                /* An open database */
  1112   1042     const char *zSql,                           /* SQL to be evaluated */
  1113   1043     int (*xCallback)(void*,int,char**,char**,int*),   /* Callback function */
  1114         -                                              /* (not the same as sqlite3_exec) */
         1044  +                                              /* (not the same as sqlite4_exec) */
  1115   1045     struct callback_data *pArg,                 /* Pointer to struct callback_data */
  1116   1046     char **pzErrMsg                             /* Error msg written here */
  1117   1047   ){
  1118         -  sqlite3_stmt *pStmt = NULL;     /* Statement to execute. */
  1119         -  int rc = SQLITE_OK;             /* Return Code */
         1048  +  sqlite4_stmt *pStmt = NULL;     /* Statement to execute. */
         1049  +  int rc = SQLITE4_OK;             /* Return Code */
  1120   1050     int rc2;
  1121   1051     const char *zLeftover;          /* Tail of unprocessed SQL */
  1122   1052   
  1123   1053     if( pzErrMsg ){
  1124   1054       *pzErrMsg = NULL;
  1125   1055     }
  1126   1056   
  1127         -  while( zSql[0] && (SQLITE_OK == rc) ){
  1128         -    rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
  1129         -    if( SQLITE_OK != rc ){
         1057  +  while( zSql[0] && (SQLITE4_OK == rc) ){
         1058  +    rc = sqlite4_prepare(db, zSql, -1, &pStmt, &zLeftover);
         1059  +    if( SQLITE4_OK != rc ){
  1130   1060         if( pzErrMsg ){
  1131   1061           *pzErrMsg = save_err_msg(db);
  1132   1062         }
  1133   1063       }else{
  1134   1064         if( !pStmt ){
  1135   1065           /* this happens for a comment or white-space */
  1136   1066           zSql = zLeftover;
................................................................................
  1142   1072         if( pArg ){
  1143   1073           pArg->pStmt = pStmt;
  1144   1074           pArg->cnt = 0;
  1145   1075         }
  1146   1076   
  1147   1077         /* echo the sql statement if echo on */
  1148   1078         if( pArg && pArg->echoOn ){
  1149         -        const char *zStmtSql = sqlite3_sql(pStmt);
         1079  +        const char *zStmtSql = sqlite4_sql(pStmt);
  1150   1080           fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
  1151   1081         }
  1152   1082   
  1153   1083         /* Output TESTCTRL_EXPLAIN text of requested */
  1154   1084         if( pArg && pArg->mode==MODE_Explain ){
  1155   1085           const char *zExplain = 0;
  1156         -        sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
         1086  +        sqlite4_test_control(SQLITE4_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
  1157   1087           if( zExplain && zExplain[0] ){
  1158   1088             fprintf(pArg->out, "%s", zExplain);
  1159   1089           }
  1160   1090         }
  1161   1091   
  1162   1092         /* perform the first step.  this will tell us if we
  1163   1093         ** have a result set or not and how wide it is.
  1164   1094         */
  1165         -      rc = sqlite3_step(pStmt);
         1095  +      rc = sqlite4_step(pStmt);
  1166   1096         /* if we have a result set... */
  1167         -      if( SQLITE_ROW == rc ){
         1097  +      if( SQLITE4_ROW == rc ){
  1168   1098           /* if we have a callback... */
  1169   1099           if( xCallback ){
  1170   1100             /* allocate space for col name ptr, value ptr, and type */
  1171         -          int nCol = sqlite3_column_count(pStmt);
  1172         -          void *pData = sqlite3_malloc(3*nCol*sizeof(const char*) + 1);
         1101  +          int nCol = sqlite4_column_count(pStmt);
         1102  +          void *pData = sqlite4_malloc(0, 3*nCol*sizeof(const char*) + 1);
  1173   1103             if( !pData ){
  1174         -            rc = SQLITE_NOMEM;
         1104  +            rc = SQLITE4_NOMEM;
  1175   1105             }else{
  1176   1106               char **azCols = (char **)pData;      /* Names of result columns */
  1177   1107               char **azVals = &azCols[nCol];       /* Results */
  1178   1108               int *aiTypes = (int *)&azVals[nCol]; /* Result types */
  1179   1109               int i;
  1180   1110               assert(sizeof(int) <= sizeof(char *)); 
  1181   1111               /* save off ptrs to column names */
  1182   1112               for(i=0; i<nCol; i++){
  1183         -              azCols[i] = (char *)sqlite3_column_name(pStmt, i);
         1113  +              azCols[i] = (char *)sqlite4_column_name(pStmt, i);
  1184   1114               }
  1185   1115               do{
  1186   1116                 /* extract the data and data types */
  1187   1117                 for(i=0; i<nCol; i++){
  1188         -                azVals[i] = (char *)sqlite3_column_text(pStmt, i);
  1189         -                aiTypes[i] = sqlite3_column_type(pStmt, i);
  1190         -                if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
  1191         -                  rc = SQLITE_NOMEM;
         1118  +                azVals[i] = (char *)sqlite4_column_text(pStmt, i);
         1119  +                aiTypes[i] = sqlite4_column_type(pStmt, i);
         1120  +                if( !azVals[i] && (aiTypes[i]!=SQLITE4_NULL) ){
         1121  +                  rc = SQLITE4_NOMEM;
  1192   1122                     break; /* from for */
  1193   1123                   }
  1194   1124                 } /* end for */
  1195   1125   
  1196   1126                 /* if data and types extracted successfully... */
  1197         -              if( SQLITE_ROW == rc ){ 
         1127  +              if( SQLITE4_ROW == rc ){ 
  1198   1128                   /* call the supplied callback with the result row data */
  1199   1129                   if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
  1200         -                  rc = SQLITE_ABORT;
         1130  +                  rc = SQLITE4_ABORT;
  1201   1131                   }else{
  1202         -                  rc = sqlite3_step(pStmt);
         1132  +                  rc = sqlite4_step(pStmt);
  1203   1133                   }
  1204   1134                 }
  1205         -            } while( SQLITE_ROW == rc );
  1206         -            sqlite3_free(pData);
         1135  +            } while( SQLITE4_ROW == rc );
         1136  +            sqlite4_free(0, pData);
  1207   1137             }
  1208   1138           }else{
  1209   1139             do{
  1210         -            rc = sqlite3_step(pStmt);
  1211         -          } while( rc == SQLITE_ROW );
         1140  +            rc = sqlite4_step(pStmt);
         1141  +          } while( rc == SQLITE4_ROW );
  1212   1142           }
  1213   1143         }
  1214   1144   
  1215   1145         /* print usage stats if stats on */
  1216   1146         if( pArg && pArg->statsOn ){
  1217   1147           display_stats(db, pArg, 0);
  1218   1148         }
  1219   1149   
  1220   1150         /* Finalize the statement just executed. If this fails, save a 
  1221   1151         ** copy of the error message. Otherwise, set zSql to point to the
  1222   1152         ** next statement to execute. */
  1223         -      rc2 = sqlite3_finalize(pStmt);
  1224         -      if( rc!=SQLITE_NOMEM ) rc = rc2;
  1225         -      if( rc==SQLITE_OK ){
         1153  +      rc2 = sqlite4_finalize(pStmt);
         1154  +      if( rc!=SQLITE4_NOMEM ) rc = rc2;
         1155  +      if( rc==SQLITE4_OK ){
  1226   1156           zSql = zLeftover;
  1227   1157           while( IsSpace(zSql[0]) ) zSql++;
  1228   1158         }else if( pzErrMsg ){
  1229   1159           *pzErrMsg = save_err_msg(db);
  1230   1160         }
  1231   1161   
  1232   1162         /* clear saved stmt handle */
................................................................................
  1268   1198       return 0;
  1269   1199     }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
  1270   1200       char *zIns;
  1271   1201       if( !p->writableSchema ){
  1272   1202         fprintf(p->out, "PRAGMA writable_schema=ON;\n");
  1273   1203         p->writableSchema = 1;
  1274   1204       }
  1275         -    zIns = sqlite3_mprintf(
         1205  +    zIns = sqlite4_mprintf(0, 
  1276   1206          "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
  1277   1207          "VALUES('table','%q','%q',0,'%q');",
  1278   1208          zTable, zTable, zSql);
  1279   1209       fprintf(p->out, "%s\n", zIns);
  1280         -    sqlite3_free(zIns);
         1210  +    sqlite4_free(0, zIns);
  1281   1211       return 0;
  1282   1212     }else{
  1283   1213       fprintf(p->out, "%s;\n", zSql);
  1284   1214     }
  1285   1215   
  1286   1216     if( strcmp(zType, "table")==0 ){
  1287         -    sqlite3_stmt *pTableInfo = 0;
         1217  +    sqlite4_stmt *pTableInfo = 0;
  1288   1218       char *zSelect = 0;
  1289   1219       char *zTableInfo = 0;
  1290   1220       char *zTmp = 0;
  1291   1221       int nRow = 0;
  1292   1222      
  1293   1223       zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0);
  1294   1224       zTableInfo = appendText(zTableInfo, zTable, '"');
  1295   1225       zTableInfo = appendText(zTableInfo, ");", 0);
  1296   1226   
  1297         -    rc = sqlite3_prepare(p->db, zTableInfo, -1, &pTableInfo, 0);
         1227  +    rc = sqlite4_prepare(p->db, zTableInfo, -1, &pTableInfo, 0);
  1298   1228       free(zTableInfo);
  1299         -    if( rc!=SQLITE_OK || !pTableInfo ){
         1229  +    if( rc!=SQLITE4_OK || !pTableInfo ){
  1300   1230         return 1;
  1301   1231       }
  1302   1232   
  1303   1233       zSelect = appendText(zSelect, "SELECT 'INSERT INTO ' || ", 0);
  1304         -    /* Always quote the table name, even if it appears to be pure ascii,
  1305         -    ** in case it is a keyword. Ex:  INSERT INTO "table" ... */
  1306   1234       zTmp = appendText(zTmp, zTable, '"');
  1307   1235       if( zTmp ){
  1308   1236         zSelect = appendText(zSelect, zTmp, '\'');
  1309         -      free(zTmp);
  1310   1237       }
  1311   1238       zSelect = appendText(zSelect, " || ' VALUES(' || ", 0);
  1312         -    rc = sqlite3_step(pTableInfo);
  1313         -    while( rc==SQLITE_ROW ){
  1314         -      const char *zText = (const char *)sqlite3_column_text(pTableInfo, 1);
         1239  +    rc = sqlite4_step(pTableInfo);
         1240  +    while( rc==SQLITE4_ROW ){
         1241  +      const char *zText = (const char *)sqlite4_column_text(pTableInfo, 1);
  1315   1242         zSelect = appendText(zSelect, "quote(", 0);
  1316   1243         zSelect = appendText(zSelect, zText, '"');
  1317         -      rc = sqlite3_step(pTableInfo);
  1318         -      if( rc==SQLITE_ROW ){
  1319         -        zSelect = appendText(zSelect, "), ", 0);
         1244  +      rc = sqlite4_step(pTableInfo);
         1245  +      if( rc==SQLITE4_ROW ){
         1246  +        zSelect = appendText(zSelect, ") || ',' || ", 0);
  1320   1247         }else{
  1321   1248           zSelect = appendText(zSelect, ") ", 0);
  1322   1249         }
  1323   1250         nRow++;
  1324   1251       }
  1325         -    rc = sqlite3_finalize(pTableInfo);
  1326         -    if( rc!=SQLITE_OK || nRow==0 ){
         1252  +    rc = sqlite4_finalize(pTableInfo);
         1253  +    if( rc!=SQLITE4_OK || nRow==0 ){
  1327   1254         free(zSelect);
  1328   1255         return 1;
  1329   1256       }
  1330   1257       zSelect = appendText(zSelect, "|| ')' FROM  ", 0);
  1331   1258       zSelect = appendText(zSelect, zTable, '"');
  1332   1259   
  1333   1260       rc = run_table_dump_query(p, zSelect, zPrepStmt);
  1334         -    if( rc==SQLITE_CORRUPT ){
         1261  +    if( rc==SQLITE4_CORRUPT ){
  1335   1262         zSelect = appendText(zSelect, " ORDER BY rowid DESC", 0);
  1336   1263         run_table_dump_query(p, zSelect, 0);
  1337   1264       }
  1338         -    free(zSelect);
         1265  +    if( zSelect ) free(zSelect);
  1339   1266     }
  1340   1267     return 0;
  1341   1268   }
  1342   1269   
  1343   1270   /*
  1344   1271   ** Run zQuery.  Use dump_callback() as the callback routine so that
  1345   1272   ** the contents of the query are output as SQL statements.
  1346   1273   **
  1347         -** If we get a SQLITE_CORRUPT error, rerun the query after appending
         1274  +** If we get a SQLITE4_CORRUPT error, rerun the query after appending
  1348   1275   ** "ORDER BY rowid DESC" to the end.
  1349   1276   */
  1350   1277   static int run_schema_dump_query(
  1351   1278     struct callback_data *p, 
  1352   1279     const char *zQuery
  1353   1280   ){
  1354   1281     int rc;
  1355   1282     char *zErr = 0;
  1356         -  rc = sqlite3_exec(p->db, zQuery, dump_callback, p, &zErr);
  1357         -  if( rc==SQLITE_CORRUPT ){
         1283  +  rc = sqlite4_exec(p->db, zQuery, dump_callback, p, &zErr);
         1284  +  if( rc==SQLITE4_CORRUPT ){
  1358   1285       char *zQ2;
  1359   1286       int len = strlen30(zQuery);
  1360   1287       fprintf(p->out, "/****** CORRUPTION ERROR *******/\n");
  1361   1288       if( zErr ){
  1362   1289         fprintf(p->out, "/****** %s ******/\n", zErr);
  1363         -      sqlite3_free(zErr);
         1290  +      sqlite4_free(0, zErr);
  1364   1291         zErr = 0;
  1365   1292       }
  1366   1293       zQ2 = malloc( len+100 );
  1367   1294       if( zQ2==0 ) return rc;
  1368         -    sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery);
  1369         -    rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr);
         1295  +    sqlite4_snprintf(zQ2,sizeof(zQ2), "%s ORDER BY rowid DESC", zQuery);
         1296  +    rc = sqlite4_exec(p->db, zQ2, dump_callback, p, &zErr);
  1370   1297       if( rc ){
  1371   1298         fprintf(p->out, "/****** ERROR: %s ******/\n", zErr);
  1372   1299       }else{
  1373         -      rc = SQLITE_CORRUPT;
         1300  +      rc = SQLITE4_CORRUPT;
  1374   1301       }
  1375         -    sqlite3_free(zErr);
         1302  +    sqlite4_free(0, zErr);
  1376   1303       free(zQ2);
  1377   1304     }
  1378   1305     return rc;
  1379   1306   }
  1380   1307   
  1381   1308   /*
  1382   1309   ** Text of a help message
  1383   1310   */
  1384   1311   static char zHelp[] =
  1385         -  ".backup ?DB? FILE      Backup DB (default \"main\") to FILE\n"
  1386   1312     ".bail ON|OFF           Stop after hitting an error.  Default OFF\n"
  1387   1313     ".databases             List names and files of attached databases\n"
  1388   1314     ".dump ?TABLE? ...      Dump the database in an SQL text format\n"
  1389   1315     "                         If TABLE specified, only dump tables matching\n"
  1390   1316     "                         LIKE pattern TABLE.\n"
  1391   1317     ".echo ON|OFF           Turn command echo on or off\n"
  1392   1318     ".exit                  Exit this program\n"
................................................................................
  1394   1320     "                         With no args, it turns EXPLAIN on.\n"
  1395   1321     ".header(s) ON|OFF      Turn display of headers on or off\n"
  1396   1322     ".help                  Show this message\n"
  1397   1323     ".import FILE TABLE     Import data from FILE into TABLE\n"
  1398   1324     ".indices ?TABLE?       Show names of all indices\n"
  1399   1325     "                         If TABLE specified, only show indices for tables\n"
  1400   1326     "                         matching LIKE pattern TABLE.\n"
  1401         -#ifdef SQLITE_ENABLE_IOTRACE
         1327  +#ifdef SQLITE4_ENABLE_IOTRACE
  1402   1328     ".iotrace FILE          Enable I/O diagnostic logging to FILE\n"
  1403   1329   #endif
  1404         -#ifndef SQLITE_OMIT_LOAD_EXTENSION
         1330  +#ifndef SQLITE4_OMIT_LOAD_EXTENSION
  1405   1331     ".load FILE ?ENTRY?     Load an extension library\n"
  1406   1332   #endif
  1407   1333     ".log FILE|off          Turn logging on or off.  FILE can be stderr/stdout\n"
  1408   1334     ".mode MODE ?TABLE?     Set output mode where MODE is one of:\n"
  1409   1335     "                         csv      Comma-separated values\n"
  1410   1336     "                         column   Left-aligned columns.  (See .width)\n"
  1411   1337     "                         html     HTML <table> code\n"
................................................................................
  1416   1342     "                         tcl      TCL list elements\n"
  1417   1343     ".nullvalue STRING      Print STRING in place of NULL values\n"
  1418   1344     ".output FILENAME       Send output to FILENAME\n"
  1419   1345     ".output stdout         Send output to the screen\n"
  1420   1346     ".prompt MAIN CONTINUE  Replace the standard prompts\n"
  1421   1347     ".quit                  Exit this program\n"
  1422   1348     ".read FILENAME         Execute SQL in FILENAME\n"
  1423         -  ".restore ?DB? FILE     Restore content of DB (default \"main\") from FILE\n"
  1424   1349     ".schema ?TABLE?        Show the CREATE statements\n"
  1425   1350     "                         If TABLE specified, only show tables matching\n"
  1426   1351     "                         LIKE pattern TABLE.\n"
  1427   1352     ".separator STRING      Change separator used by output mode and .import\n"
  1428   1353     ".show                  Show the current values for various settings\n"
  1429   1354     ".stats ON|OFF          Turn stats on or off\n"
  1430   1355     ".tables ?TABLE?        List names of tables\n"
  1431   1356     "                         If TABLE specified, only list tables matching\n"
  1432   1357     "                         LIKE pattern TABLE.\n"
  1433         -  ".timeout MS            Try opening locked tables for MS milliseconds\n"
  1434         -  ".trace FILE|off        Output each SQL statement as it is run\n"
  1435         -  ".vfsname ?AUX?         Print the name of the VFS stack\n"
  1436   1358     ".width NUM1 NUM2 ...   Set column widths for \"column\" mode\n"
  1437   1359   ;
  1438   1360   
  1439   1361   static char zTimerHelp[] =
  1440   1362     ".timer ON|OFF          Turn the CPU timer measurement on or off\n"
  1441   1363   ;
  1442   1364   
................................................................................
  1445   1367   
  1446   1368   /*
  1447   1369   ** Make sure the database is open.  If it is not, then open it.  If
  1448   1370   ** the database fails to open, print an error message and exit.
  1449   1371   */
  1450   1372   static void open_db(struct callback_data *p){
  1451   1373     if( p->db==0 ){
  1452         -    sqlite3_open(p->zDbFilename, &p->db);
         1374  +    sqlite4_open(0, p->zDbFilename, &p->db, 0);
  1453   1375       db = p->db;
  1454         -    if( db && sqlite3_errcode(db)==SQLITE_OK ){
  1455         -      sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
         1376  +    if( db && sqlite4_errcode(db)==SQLITE4_OK ){
         1377  +      sqlite4_create_function(db, "shellstatic", 0, SQLITE4_UTF8, 0,
  1456   1378             shellstaticFunc, 0, 0);
  1457   1379       }
  1458         -    if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
         1380  +    if( db==0 || SQLITE4_OK!=sqlite4_errcode(db) ){
  1459   1381         fprintf(stderr,"Error: unable to open database \"%s\": %s\n", 
  1460         -          p->zDbFilename, sqlite3_errmsg(db));
         1382  +          p->zDbFilename, sqlite4_errmsg(db));
  1461   1383         exit(1);
  1462   1384       }
  1463         -#ifndef SQLITE_OMIT_LOAD_EXTENSION
  1464         -    sqlite3_enable_load_extension(p->db, 1);
         1385  +#if 0 /*ndef SQLITE4_OMIT_LOAD_EXTENSION*/
         1386  +    sqlite4_enable_load_extension(p->db, 1);
  1465   1387   #endif
  1466   1388     }
  1467   1389   }
  1468   1390   
  1469   1391   /*
  1470   1392   ** Do C-language style dequoting.
  1471   1393   **
................................................................................
  1517   1439       val = 1;
  1518   1440     }else if( strcmp(zArg,"yes")==0 ){
  1519   1441       val = 1;
  1520   1442     }
  1521   1443     return val;
  1522   1444   }
  1523   1445   
  1524         -/*
  1525         -** Close an output file, assuming it is not stderr or stdout
  1526         -*/
  1527         -static void output_file_close(FILE *f){
  1528         -  if( f && f!=stdout && f!=stderr ) fclose(f);
  1529         -}
  1530         -
  1531         -/*
  1532         -** Try to open an output file.   The names "stdout" and "stderr" are
  1533         -** recognized and do the right thing.  NULL is returned if the output 
  1534         -** filename is "off".
  1535         -*/
  1536         -static FILE *output_file_open(const char *zFile){
  1537         -  FILE *f;
  1538         -  if( strcmp(zFile,"stdout")==0 ){
  1539         -    f = stdout;
  1540         -  }else if( strcmp(zFile, "stderr")==0 ){
  1541         -    f = stderr;
  1542         -  }else if( strcmp(zFile, "off")==0 ){
  1543         -    f = 0;
  1544         -  }else{
  1545         -    f = fopen(zFile, "wb");
  1546         -    if( f==0 ){
  1547         -      fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
  1548         -    }
  1549         -  }
  1550         -  return f;
  1551         -}
  1552         -
  1553         -/*
  1554         -** A routine for handling output from sqlite3_trace().
  1555         -*/
  1556         -static void sql_trace_callback(void *pArg, const char *z){
  1557         -  FILE *f = (FILE*)pArg;
  1558         -  if( f ) fprintf(f, "%s\n", z);
  1559         -}
  1560         -
  1561         -/*
  1562         -** A no-op routine that runs with the ".breakpoint" doc-command.  This is
  1563         -** a useful spot to set a debugger breakpoint.
  1564         -*/
  1565         -static void test_breakpoint(void){
  1566         -  static int nCall = 0;
  1567         -  nCall++;
  1568         -}
  1569         -
  1570   1446   /*
  1571   1447   ** If an input line begins with "." then invoke this routine to
  1572   1448   ** process that line.
  1573   1449   **
  1574   1450   ** Return 1 on error, 2 to exit, and 0 otherwise.
  1575   1451   */
  1576   1452   static int do_meta_command(char *zLine, struct callback_data *p){
  1577   1453     int i = 1;
  1578   1454     int nArg = 0;
  1579         -  int n, c;
  1580   1455     int rc = 0;
         1456  +  int c, n;
  1581   1457     char *azArg[50];
  1582   1458   
  1583   1459     /* Parse the input line into tokens.
  1584   1460     */
  1585   1461     while( zLine[i] && nArg<ArraySize(azArg) ){
  1586   1462       while( IsSpace(zLine[i]) ){ i++; }
  1587   1463       if( zLine[i]==0 ) break;
................................................................................
  1597   1473         azArg[nArg++] = &zLine[i];
  1598   1474         while( zLine[i] && !IsSpace(zLine[i]) ){ i++; }
  1599   1475         if( zLine[i] ) zLine[i++] = 0;
  1600   1476         resolve_backslashes(azArg[nArg-1]);
  1601   1477       }
  1602   1478     }
  1603   1479   
  1604         -  /* Process the input line.
  1605         -  */
         1480  +
  1606   1481     if( nArg==0 ) return 0; /* no tokens, no error */
  1607   1482     n = strlen30(azArg[0]);
  1608   1483     c = azArg[0][0];
  1609         -  if( c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0 && nArg>1 && nArg<4){
  1610         -    const char *zDestFile;
  1611         -    const char *zDb;
  1612         -    sqlite3 *pDest;
  1613         -    sqlite3_backup *pBackup;
  1614         -    if( nArg==2 ){
  1615         -      zDestFile = azArg[1];
  1616         -      zDb = "main";
  1617         -    }else{
  1618         -      zDestFile = azArg[2];
  1619         -      zDb = azArg[1];
  1620         -    }
  1621         -    rc = sqlite3_open(zDestFile, &pDest);
  1622         -    if( rc!=SQLITE_OK ){
  1623         -      fprintf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
  1624         -      sqlite3_close(pDest);
  1625         -      return 1;
  1626         -    }
  1627         -    open_db(p);
  1628         -    pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
  1629         -    if( pBackup==0 ){
  1630         -      fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
  1631         -      sqlite3_close(pDest);
  1632         -      return 1;
  1633         -    }
  1634         -    while(  (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){}
  1635         -    sqlite3_backup_finish(pBackup);
  1636         -    if( rc==SQLITE_DONE ){
  1637         -      rc = 0;
  1638         -    }else{
  1639         -      fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
  1640         -      rc = 1;
  1641         -    }
  1642         -    sqlite3_close(pDest);
  1643         -  }else
  1644   1484   
  1645   1485     if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 && nArg>1 && nArg<3 ){
  1646   1486       bail_on_error = booleanValue(azArg[1]);
  1647   1487     }else
  1648         -
  1649         -  /* The undocumented ".breakpoint" command causes a call to the no-op
  1650         -  ** routine named test_breakpoint().
  1651         -  */
  1652         -  if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
  1653         -    test_breakpoint();
  1654         -  }else
  1655         -
  1656   1488     if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
  1657   1489       struct callback_data data;
  1658   1490       char *zErrMsg = 0;
  1659   1491       open_db(p);
  1660   1492       memcpy(&data, p, sizeof(data));
  1661   1493       data.showHeader = 1;
  1662   1494       data.mode = MODE_Column;
  1663   1495       data.colWidth[0] = 3;
  1664   1496       data.colWidth[1] = 15;
  1665   1497       data.colWidth[2] = 58;
  1666   1498       data.cnt = 0;
  1667         -    sqlite3_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
         1499  +    sqlite4_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
  1668   1500       if( zErrMsg ){
  1669   1501         fprintf(stderr,"Error: %s\n", zErrMsg);
  1670         -      sqlite3_free(zErrMsg);
         1502  +      sqlite4_free(0, zErrMsg);
  1671   1503         rc = 1;
  1672   1504       }
  1673   1505     }else
  1674   1506   
  1675   1507     if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
  1676   1508       open_db(p);
  1677   1509       /* When playing back a "dump", the content might appear in an order
  1678   1510       ** which causes immediate foreign key constraints to be violated.
  1679   1511       ** So disable foreign-key constraint enforcement to prevent problems. */
  1680   1512       fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
  1681   1513       fprintf(p->out, "BEGIN TRANSACTION;\n");
  1682   1514       p->writableSchema = 0;
  1683         -    sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
         1515  +    sqlite4_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
  1684   1516       p->nErr = 0;
  1685   1517       if( nArg==1 ){
  1686   1518         run_schema_dump_query(p, 
  1687   1519           "SELECT name, type, sql FROM sqlite_master "
  1688   1520           "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'"
  1689   1521         );
  1690   1522         run_schema_dump_query(p, 
................................................................................
  1712   1544           zShellStatic = 0;
  1713   1545         }
  1714   1546       }
  1715   1547       if( p->writableSchema ){
  1716   1548         fprintf(p->out, "PRAGMA writable_schema=OFF;\n");
  1717   1549         p->writableSchema = 0;
  1718   1550       }
  1719         -    sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
  1720         -    sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
         1551  +    sqlite4_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
         1552  +    sqlite4_exec(p->db, "RELEASE dump;", 0, 0, 0);
  1721   1553       fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
  1722   1554     }else
  1723   1555   
  1724   1556     if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
  1725   1557       p->echoOn = booleanValue(azArg[1]);
  1726   1558     }else
  1727   1559   
................................................................................
  1775   1607         fprintf(stderr,"%s",zTimerHelp);
  1776   1608       }
  1777   1609     }else
  1778   1610   
  1779   1611     if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
  1780   1612       char *zTable = azArg[2];    /* Insert data into this table */
  1781   1613       char *zFile = azArg[1];     /* The file from which to extract data */
  1782         -    sqlite3_stmt *pStmt = NULL; /* A statement */
         1614  +    sqlite4_stmt *pStmt = NULL; /* A statement */
  1783   1615       int nCol;                   /* Number of columns in the table */
  1784   1616       int nByte;                  /* Number of bytes in an SQL string */
  1785   1617       int i, j;                   /* Loop counters */
  1786   1618       int nSep;                   /* Number of bytes in p->separator[] */
  1787   1619       char *zSql;                 /* An SQL statement */
  1788   1620       char *zLine;                /* A single line of input from the file */
  1789   1621       char **azCol;               /* zLine[] broken up into columns */
................................................................................
  1793   1625   
  1794   1626       open_db(p);
  1795   1627       nSep = strlen30(p->separator);
  1796   1628       if( nSep==0 ){
  1797   1629         fprintf(stderr, "Error: non-null separator required for import\n");
  1798   1630         return 1;
  1799   1631       }
  1800         -    zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
         1632  +    zSql = sqlite4_mprintf(0, "SELECT * FROM %s", zTable);
  1801   1633       if( zSql==0 ){
  1802   1634         fprintf(stderr, "Error: out of memory\n");
  1803   1635         return 1;
  1804   1636       }
  1805   1637       nByte = strlen30(zSql);
  1806         -    rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
  1807         -    sqlite3_free(zSql);
         1638  +    rc = sqlite4_prepare(p->db, zSql, -1, &pStmt, 0);
         1639  +    sqlite4_free(0, zSql);
  1808   1640       if( rc ){
  1809         -      if (pStmt) sqlite3_finalize(pStmt);
  1810         -      fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
         1641  +      if (pStmt) sqlite4_finalize(pStmt);
         1642  +      fprintf(stderr,"Error: %s\n", sqlite4_errmsg(db));
  1811   1643         return 1;
  1812   1644       }
  1813         -    nCol = sqlite3_column_count(pStmt);
  1814         -    sqlite3_finalize(pStmt);
         1645  +    nCol = sqlite4_column_count(pStmt);
         1646  +    sqlite4_finalize(pStmt);
  1815   1647       pStmt = 0;
  1816   1648       if( nCol==0 ) return 0; /* no columns, no error */
  1817   1649       zSql = malloc( nByte + 20 + nCol*2 );
  1818   1650       if( zSql==0 ){
  1819   1651         fprintf(stderr, "Error: out of memory\n");
  1820   1652         return 1;
  1821   1653       }
  1822         -    sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s VALUES(?", zTable);
         1654  +    sqlite4_snprintf(zSql, nByte+20, "INSERT INTO %s VALUES(?", zTable);
  1823   1655       j = strlen30(zSql);
  1824   1656       for(i=1; i<nCol; i++){
  1825   1657         zSql[j++] = ',';
  1826   1658         zSql[j++] = '?';
  1827   1659       }
  1828   1660       zSql[j++] = ')';
  1829   1661       zSql[j] = 0;
  1830         -    rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
         1662  +    rc = sqlite4_prepare(p->db, zSql, -1, &pStmt, 0);
  1831   1663       free(zSql);
  1832   1664       if( rc ){
  1833         -      fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
  1834         -      if (pStmt) sqlite3_finalize(pStmt);
         1665  +      fprintf(stderr, "Error: %s\n", sqlite4_errmsg(db));
         1666  +      if (pStmt) sqlite4_finalize(pStmt);
  1835   1667         return 1;
  1836   1668       }
  1837   1669       in = fopen(zFile, "rb");
  1838   1670       if( in==0 ){
  1839   1671         fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
  1840         -      sqlite3_finalize(pStmt);
         1672  +      sqlite4_finalize(pStmt);
  1841   1673         return 1;
  1842   1674       }
  1843   1675       azCol = malloc( sizeof(azCol[0])*(nCol+1) );
  1844   1676       if( azCol==0 ){
  1845   1677         fprintf(stderr, "Error: out of memory\n");
  1846   1678         fclose(in);
  1847         -      sqlite3_finalize(pStmt);
         1679  +      sqlite4_finalize(pStmt);
  1848   1680         return 1;
  1849   1681       }
  1850         -    sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
         1682  +    sqlite4_exec(p->db, "BEGIN", 0, 0, 0);
  1851   1683       zCommit = "COMMIT";
  1852   1684       while( (zLine = local_getline(0, in, 1))!=0 ){
  1853   1685         char *z, c;
  1854   1686         int inQuote = 0;
  1855   1687         lineno++;
  1856   1688         azCol[0] = zLine;
  1857   1689         for(i=0, z=zLine; (c = *z)!=0; z++){
................................................................................
  1881   1713             int k;
  1882   1714             for(z=azCol[i], j=1, k=0; z[j]; j++){
  1883   1715               if( z[j]=='"' ){ j++; if( z[j]==0 ) break; }
  1884   1716               z[k++] = z[j];
  1885   1717             }
  1886   1718             z[k] = 0;
  1887   1719           }
  1888         -        sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
         1720  +        sqlite4_bind_text(pStmt, i+1, azCol[i], -1, SQLITE4_STATIC);
  1889   1721         }
  1890         -      sqlite3_step(pStmt);
  1891         -      rc = sqlite3_reset(pStmt);
         1722  +      sqlite4_step(pStmt);
         1723  +      rc = sqlite4_reset(pStmt);
  1892   1724         free(zLine);
  1893         -      if( rc!=SQLITE_OK ){
  1894         -        fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
         1725  +      if( rc!=SQLITE4_OK ){
         1726  +        fprintf(stderr,"Error: %s\n", sqlite4_errmsg(db));
  1895   1727           zCommit = "ROLLBACK";
  1896   1728           rc = 1;
  1897   1729           break; /* from while */
  1898   1730         }
  1899   1731       } /* end while */
  1900   1732       free(azCol);
  1901   1733       fclose(in);
  1902         -    sqlite3_finalize(pStmt);
  1903         -    sqlite3_exec(p->db, zCommit, 0, 0, 0);
         1734  +    sqlite4_finalize(pStmt);
         1735  +    sqlite4_exec(p->db, zCommit, 0, 0, 0);
  1904   1736     }else
  1905   1737   
  1906   1738     if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
  1907   1739       struct callback_data data;
  1908   1740       char *zErrMsg = 0;
  1909   1741       open_db(p);
  1910   1742       memcpy(&data, p, sizeof(data));
  1911   1743       data.showHeader = 0;
  1912   1744       data.mode = MODE_List;
  1913   1745       if( nArg==1 ){
  1914         -      rc = sqlite3_exec(p->db,
         1746  +      rc = sqlite4_exec(p->db,
  1915   1747           "SELECT name FROM sqlite_master "
  1916   1748           "WHERE type='index' AND name NOT LIKE 'sqlite_%' "
  1917   1749           "UNION ALL "
  1918   1750           "SELECT name FROM sqlite_temp_master "
  1919   1751           "WHERE type='index' "
  1920   1752           "ORDER BY 1",
  1921   1753           callback, &data, &zErrMsg
  1922   1754         );
  1923   1755       }else{
  1924   1756         zShellStatic = azArg[1];
  1925         -      rc = sqlite3_exec(p->db,
         1757  +      rc = sqlite4_exec(p->db,
  1926   1758           "SELECT name FROM sqlite_master "
  1927   1759           "WHERE type='index' AND tbl_name LIKE shellstatic() "
  1928   1760           "UNION ALL "
  1929   1761           "SELECT name FROM sqlite_temp_master "
  1930   1762           "WHERE type='index' AND tbl_name LIKE shellstatic() "
  1931   1763           "ORDER BY 1",
  1932   1764           callback, &data, &zErrMsg
  1933   1765         );
  1934   1766         zShellStatic = 0;
  1935   1767       }
  1936   1768       if( zErrMsg ){
  1937   1769         fprintf(stderr,"Error: %s\n", zErrMsg);
  1938         -      sqlite3_free(zErrMsg);
         1770  +      sqlite4_free(0, zErrMsg);
  1939   1771         rc = 1;
  1940         -    }else if( rc != SQLITE_OK ){
         1772  +    }else if( rc != SQLITE4_OK ){
  1941   1773         fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n");
  1942   1774         rc = 1;
  1943   1775       }
  1944   1776     }else
  1945   1777   
  1946         -#ifdef SQLITE_ENABLE_IOTRACE
         1778  +#ifdef SQLITE4_ENABLE_IOTRACE
  1947   1779     if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){
  1948         -    extern void (*sqlite3IoTrace)(const char*, ...);
         1780  +    extern void (*sqlite4IoTrace)(const char*, ...);
  1949   1781       if( iotrace && iotrace!=stdout ) fclose(iotrace);
  1950   1782       iotrace = 0;
  1951   1783       if( nArg<2 ){
  1952         -      sqlite3IoTrace = 0;
         1784  +      sqlite4IoTrace = 0;
  1953   1785       }else if( strcmp(azArg[1], "-")==0 ){
  1954         -      sqlite3IoTrace = iotracePrintf;
         1786  +      sqlite4IoTrace = iotracePrintf;
  1955   1787         iotrace = stdout;
  1956   1788       }else{
  1957   1789         iotrace = fopen(azArg[1], "w");
  1958   1790         if( iotrace==0 ){
  1959   1791           fprintf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
  1960         -        sqlite3IoTrace = 0;
         1792  +        sqlite4IoTrace = 0;
  1961   1793           rc = 1;
  1962   1794         }else{
  1963         -        sqlite3IoTrace = iotracePrintf;
         1795  +        sqlite4IoTrace = iotracePrintf;
  1964   1796         }
  1965   1797       }
  1966   1798     }else
  1967   1799   #endif
  1968   1800   
  1969         -#ifndef SQLITE_OMIT_LOAD_EXTENSION
         1801  +#if 0 /*ndef SQLITE4_OMIT_LOAD_EXTENSION*/
  1970   1802     if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){
  1971   1803       const char *zFile, *zProc;
  1972   1804       char *zErrMsg = 0;
  1973   1805       zFile = azArg[1];
  1974   1806       zProc = nArg>=3 ? azArg[2] : 0;
  1975   1807       open_db(p);
  1976         -    rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
  1977         -    if( rc!=SQLITE_OK ){
         1808  +    rc = sqlite4_load_extension(p->db, zFile, zProc, &zErrMsg);
         1809  +    if( rc!=SQLITE4_OK ){
  1978   1810         fprintf(stderr, "Error: %s\n", zErrMsg);
  1979         -      sqlite3_free(zErrMsg);
         1811  +      sqlite4_free(0, zErrMsg);
  1980   1812         rc = 1;
  1981   1813       }
  1982   1814     }else
  1983   1815   #endif
  1984   1816   
  1985   1817     if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){
  1986   1818       const char *zFile = azArg[1];
  1987         -    output_file_close(p->pLog);
  1988         -    p->pLog = output_file_open(zFile);
         1819  +    if( p->pLog && p->pLog!=stdout && p->pLog!=stderr ){
         1820  +      fclose(p->pLog);
         1821  +      p->pLog = 0;
         1822  +    }
         1823  +    if( strcmp(zFile,"stdout")==0 ){
         1824  +      p->pLog = stdout;
         1825  +    }else if( strcmp(zFile, "stderr")==0 ){
         1826  +      p->pLog = stderr;
         1827  +    }else if( strcmp(zFile, "off")==0 ){
         1828  +      p->pLog = 0;
         1829  +    }else{
         1830  +      p->pLog = fopen(zFile, "w");
         1831  +      if( p->pLog==0 ){
         1832  +        fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
         1833  +      }
         1834  +    }
  1989   1835     }else
  1990   1836   
  1991   1837     if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==2 ){
  1992   1838       int n2 = strlen30(azArg[1]);
  1993   1839       if( (n2==4 && strncmp(azArg[1],"line",n2)==0)
  1994   1840           ||
  1995   1841           (n2==5 && strncmp(azArg[1],"lines",n2)==0) ){
................................................................................
  2002   1848         p->mode = MODE_List;
  2003   1849       }else if( n2==4 && strncmp(azArg[1],"html",n2)==0 ){
  2004   1850         p->mode = MODE_Html;
  2005   1851       }else if( n2==3 && strncmp(azArg[1],"tcl",n2)==0 ){
  2006   1852         p->mode = MODE_Tcl;
  2007   1853       }else if( n2==3 && strncmp(azArg[1],"csv",n2)==0 ){
  2008   1854         p->mode = MODE_Csv;
  2009         -      sqlite3_snprintf(sizeof(p->separator), p->separator, ",");
         1855  +      sqlite4_snprintf(p->separator, sizeof(p->separator), ",");
  2010   1856       }else if( n2==4 && strncmp(azArg[1],"tabs",n2)==0 ){
  2011   1857         p->mode = MODE_List;
  2012         -      sqlite3_snprintf(sizeof(p->separator), p->separator, "\t");
         1858  +      sqlite4_snprintf(p->separator, sizeof(p->separator), "\t");
  2013   1859       }else if( n2==6 && strncmp(azArg[1],"insert",n2)==0 ){
  2014   1860         p->mode = MODE_Insert;
  2015   1861         set_table_name(p, "table");
  2016   1862       }else {
  2017   1863         fprintf(stderr,"Error: mode should be one of: "
  2018   1864            "column csv html insert line list tabs tcl\n");
  2019   1865         rc = 1;
................................................................................
  2029   1875         fprintf(stderr, "Error: invalid arguments: "
  2030   1876           " \"%s\". Enter \".help\" for help\n", azArg[2]);
  2031   1877         rc = 1;
  2032   1878       }
  2033   1879     }else
  2034   1880   
  2035   1881     if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) {
  2036         -    sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
         1882  +    sqlite4_snprintf(p->nullvalue, sizeof(p->nullvalue),
  2037   1883                        "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
  2038   1884     }else
  2039   1885   
  2040   1886     if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
  2041         -    if( p->outfile[0]=='|' ){
  2042         -      pclose(p->out);
         1887  +    if( p->out!=stdout ){
         1888  +      fclose(p->out);
         1889  +    }
         1890  +    if( strcmp(azArg[1],"stdout")==0 ){
         1891  +      p->out = stdout;
         1892  +      sqlite4_snprintf(p->outfile, sizeof(p->outfile), "stdout");
  2043   1893       }else{
  2044         -      output_file_close(p->out);
  2045         -    }
  2046         -    p->outfile[0] = 0;
  2047         -    if( azArg[1][0]=='|' ){
  2048         -      p->out = popen(&azArg[1][1], "w");
         1894  +      p->out = fopen(azArg[1], "wb");
  2049   1895         if( p->out==0 ){
  2050         -        fprintf(stderr,"Error: cannot open pipe \"%s\"\n", &azArg[1][1]);
  2051         -        p->out = stdout;
  2052         -        rc = 1;
  2053         -      }else{
  2054         -        sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
  2055         -      }
  2056         -    }else{
  2057         -      p->out = output_file_open(azArg[1]);
  2058         -      if( p->out==0 ){
  2059         -        if( strcmp(azArg[1],"off")!=0 ){
  2060         -          fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]);
  2061         -        }
         1896  +        fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]);
  2062   1897           p->out = stdout;
  2063   1898           rc = 1;
  2064   1899         } else {
  2065         -        sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
         1900  +         sqlite4_snprintf(p->outfile, sizeof(p->outfile), "%s", azArg[1]);
  2066   1901         }
  2067   1902       }
  2068   1903     }else
  2069   1904   
  2070   1905     if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && (nArg==2 || nArg==3)){
  2071   1906       if( nArg >= 2) {
  2072   1907         strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
................................................................................
  2087   1922         rc = 1;
  2088   1923       }else{
  2089   1924         rc = process_input(p, alt);
  2090   1925         fclose(alt);
  2091   1926       }
  2092   1927     }else
  2093   1928   
  2094         -  if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 && nArg>1 && nArg<4){
  2095         -    const char *zSrcFile;
  2096         -    const char *zDb;
  2097         -    sqlite3 *pSrc;
  2098         -    sqlite3_backup *pBackup;
  2099         -    int nTimeout = 0;
  2100         -
  2101         -    if( nArg==2 ){
  2102         -      zSrcFile = azArg[1];
  2103         -      zDb = "main";
  2104         -    }else{
  2105         -      zSrcFile = azArg[2];
  2106         -      zDb = azArg[1];
  2107         -    }
  2108         -    rc = sqlite3_open(zSrcFile, &pSrc);
  2109         -    if( rc!=SQLITE_OK ){
  2110         -      fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
  2111         -      sqlite3_close(pSrc);
  2112         -      return 1;
  2113         -    }
  2114         -    open_db(p);
  2115         -    pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
  2116         -    if( pBackup==0 ){
  2117         -      fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
  2118         -      sqlite3_close(pSrc);
  2119         -      return 1;
  2120         -    }
  2121         -    while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK
  2122         -          || rc==SQLITE_BUSY  ){
  2123         -      if( rc==SQLITE_BUSY ){
  2124         -        if( nTimeout++ >= 3 ) break;
  2125         -        sqlite3_sleep(100);
  2126         -      }
  2127         -    }
  2128         -    sqlite3_backup_finish(pBackup);
  2129         -    if( rc==SQLITE_DONE ){
  2130         -      rc = 0;
  2131         -    }else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){
  2132         -      fprintf(stderr, "Error: source database is busy\n");
  2133         -      rc = 1;
  2134         -    }else{
  2135         -      fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
  2136         -      rc = 1;
  2137         -    }
  2138         -    sqlite3_close(pSrc);
  2139         -  }else
  2140   1929   
  2141   1930     if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){
  2142   1931       struct callback_data data;
  2143   1932       char *zErrMsg = 0;
  2144   1933       open_db(p);
  2145   1934       memcpy(&data, p, sizeof(data));
  2146   1935       data.showHeader = 0;
................................................................................
  2157   1946                         "  rootpage integer,\n"
  2158   1947                         "  sql text\n"
  2159   1948                         ")";
  2160   1949           new_argv[1] = 0;
  2161   1950           new_colv[0] = "sql";
  2162   1951           new_colv[1] = 0;
  2163   1952           callback(&data, 1, new_argv, new_colv);
  2164         -        rc = SQLITE_OK;
         1953  +        rc = SQLITE4_OK;
  2165   1954         }else if( strcmp(azArg[1],"sqlite_temp_master")==0 ){
  2166   1955           char *new_argv[2], *new_colv[2];
  2167   1956           new_argv[0] = "CREATE TEMP TABLE sqlite_temp_master (\n"
  2168   1957                         "  type text,\n"
  2169   1958                         "  name text,\n"
  2170   1959                         "  tbl_name text,\n"
  2171   1960                         "  rootpage integer,\n"
  2172   1961                         "  sql text\n"
  2173   1962                         ")";
  2174   1963           new_argv[1] = 0;
  2175   1964           new_colv[0] = "sql";
  2176   1965           new_colv[1] = 0;
  2177   1966           callback(&data, 1, new_argv, new_colv);
  2178         -        rc = SQLITE_OK;
         1967  +        rc = SQLITE4_OK;
  2179   1968         }else{
  2180   1969           zShellStatic = azArg[1];
  2181         -        rc = sqlite3_exec(p->db,
         1970  +        rc = sqlite4_exec(p->db,
  2182   1971             "SELECT sql FROM "
  2183         -          "  (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
         1972  +          "  (SELECT sql sql, type type, tbl_name tbl_name, name name"
  2184   1973             "     FROM sqlite_master UNION ALL"
  2185         -          "   SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
         1974  +          "   SELECT sql, type, tbl_name, name FROM sqlite_temp_master) "
  2186   1975             "WHERE lower(tbl_name) LIKE shellstatic()"
  2187   1976             "  AND type!='meta' AND sql NOTNULL "
  2188         -          "ORDER BY substr(type,2,1), "
  2189         -                  " CASE type WHEN 'view' THEN rowid ELSE name END",
         1977  +          "ORDER BY substr(type,2,1), name",
  2190   1978             callback, &data, &zErrMsg);
  2191   1979           zShellStatic = 0;
  2192   1980         }
  2193   1981       }else{
  2194         -      rc = sqlite3_exec(p->db,
         1982  +      rc = sqlite4_exec(p->db,
  2195   1983            "SELECT sql FROM "
  2196         -         "  (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
         1984  +         "  (SELECT sql sql, type type, tbl_name tbl_name, name name"
  2197   1985            "     FROM sqlite_master UNION ALL"
  2198         -         "   SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
         1986  +         "   SELECT sql, type, tbl_name, name FROM sqlite_temp_master) "
  2199   1987            "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
  2200         -         "ORDER BY substr(type,2,1),"
  2201         -                  " CASE type WHEN 'view' THEN rowid ELSE name END",
         1988  +         "ORDER BY substr(type,2,1), name",
  2202   1989            callback, &data, &zErrMsg
  2203   1990         );
  2204   1991       }
  2205   1992       if( zErrMsg ){
  2206   1993         fprintf(stderr,"Error: %s\n", zErrMsg);
  2207         -      sqlite3_free(zErrMsg);
         1994  +      sqlite4_free(0, zErrMsg);
  2208   1995         rc = 1;
  2209         -    }else if( rc != SQLITE_OK ){
         1996  +    }else if( rc != SQLITE4_OK ){
  2210   1997         fprintf(stderr,"Error: querying schema information\n");
  2211   1998         rc = 1;
  2212   1999       }else{
  2213   2000         rc = 0;
  2214   2001       }
  2215   2002     }else
  2216   2003   
  2217   2004     if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
  2218         -    sqlite3_snprintf(sizeof(p->separator), p->separator,
         2005  +    sqlite4_snprintf(p->separator, sizeof(p->separator),
  2219   2006                        "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
  2220   2007     }else
  2221   2008   
  2222   2009     if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
  2223   2010       int i;
  2224   2011       fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
  2225   2012       fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
................................................................................
  2242   2029     }else
  2243   2030   
  2244   2031     if( c=='s' && strncmp(azArg[0], "stats", n)==0 && nArg>1 && nArg<3 ){
  2245   2032       p->statsOn = booleanValue(azArg[1]);
  2246   2033     }else
  2247   2034   
  2248   2035     if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){
  2249         -    sqlite3_stmt *pStmt;
         2036  +    sqlite4_stmt *pStmt;
  2250   2037       char **azResult;
  2251   2038       int nRow, nAlloc;
  2252   2039       char *zSql = 0;
  2253   2040       int ii;
  2254   2041       open_db(p);
  2255         -    rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
         2042  +    rc = sqlite4_prepare(p->db, "PRAGMA database_list", -1, &pStmt, 0);
  2256   2043       if( rc ) return rc;
  2257         -    zSql = sqlite3_mprintf(
         2044  +    zSql = sqlite4_mprintf(0, 
  2258   2045           "SELECT name FROM sqlite_master"
  2259   2046           " WHERE type IN ('table','view')"
  2260   2047           "   AND name NOT LIKE 'sqlite_%%'"
  2261   2048           "   AND name LIKE ?1");
  2262         -    while( sqlite3_step(pStmt)==SQLITE_ROW ){
  2263         -      const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
         2049  +    while( sqlite4_step(pStmt)==SQLITE4_ROW ){
         2050  +      const char *zDbName = (const char*)sqlite4_column_text(pStmt, 1);
  2264   2051         if( zDbName==0 || strcmp(zDbName,"main")==0 ) continue;
  2265   2052         if( strcmp(zDbName,"temp")==0 ){
  2266         -        zSql = sqlite3_mprintf(
         2053  +        zSql = sqlite4_mprintf(0, 
  2267   2054                    "%z UNION ALL "
  2268   2055                    "SELECT 'temp.' || name FROM sqlite_temp_master"
  2269   2056                    " WHERE type IN ('table','view')"
  2270   2057                    "   AND name NOT LIKE 'sqlite_%%'"
  2271   2058                    "   AND name LIKE ?1", zSql);
  2272   2059         }else{
  2273         -        zSql = sqlite3_mprintf(
         2060  +        zSql = sqlite4_mprintf(0, 
  2274   2061                    "%z UNION ALL "
  2275   2062                    "SELECT '%q.' || name FROM \"%w\".sqlite_master"
  2276   2063                    " WHERE type IN ('table','view')"
  2277   2064                    "   AND name NOT LIKE 'sqlite_%%'"
  2278   2065                    "   AND name LIKE ?1", zSql, zDbName, zDbName);
  2279   2066         }
  2280   2067       }
  2281         -    sqlite3_finalize(pStmt);
  2282         -    zSql = sqlite3_mprintf("%z ORDER BY 1", zSql);
  2283         -    rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
  2284         -    sqlite3_free(zSql);
         2068  +    sqlite4_finalize(pStmt);
         2069  +    zSql = sqlite4_mprintf(0, "%z ORDER BY 1", zSql);
         2070  +    rc = sqlite4_prepare(p->db, zSql, -1, &pStmt, 0);
         2071  +    sqlite4_free(0, zSql);
  2285   2072       if( rc ) return rc;
  2286   2073       nRow = nAlloc = 0;
  2287   2074       azResult = 0;
  2288   2075       if( nArg>1 ){
  2289         -      sqlite3_bind_text(pStmt, 1, azArg[1], -1, SQLITE_TRANSIENT);
         2076  +      sqlite4_bind_text(pStmt, 1, azArg[1], -1, SQLITE4_TRANSIENT);
  2290   2077       }else{
  2291         -      sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC);
         2078  +      sqlite4_bind_text(pStmt, 1, "%", -1, SQLITE4_STATIC);
  2292   2079       }
  2293         -    while( sqlite3_step(pStmt)==SQLITE_ROW ){
         2080  +    while( sqlite4_step(pStmt)==SQLITE4_ROW ){
  2294   2081         if( nRow>=nAlloc ){
  2295   2082           char **azNew;
  2296   2083           int n = nAlloc*2 + 10;
  2297         -        azNew = sqlite3_realloc(azResult, sizeof(azResult[0])*n);
         2084  +        azNew = sqlite4_realloc(0, azResult, sizeof(azResult[0])*n);
  2298   2085           if( azNew==0 ){
  2299   2086             fprintf(stderr, "Error: out of memory\n");
  2300   2087             break;
  2301   2088           }
  2302   2089           nAlloc = n;
  2303   2090           azResult = azNew;
  2304   2091         }
  2305         -      azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
         2092  +      azResult[nRow] = sqlite4_mprintf(0, "%s", sqlite4_column_text(pStmt, 0));
  2306   2093         if( azResult[nRow] ) nRow++;
  2307   2094       }
  2308         -    sqlite3_finalize(pStmt);        
         2095  +    sqlite4_finalize(pStmt);        
  2309   2096       if( nRow>0 ){
  2310   2097         int len, maxlen = 0;
  2311   2098         int i, j;
  2312   2099         int nPrintCol, nPrintRow;
  2313   2100         for(i=0; i<nRow; i++){
  2314   2101           len = strlen30(azResult[i]);
  2315   2102           if( len>maxlen ) maxlen = len;
................................................................................
  2321   2108           for(j=i; j<nRow; j+=nPrintRow){
  2322   2109             char *zSp = j<nPrintRow ? "" : "  ";
  2323   2110             printf("%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : "");
  2324   2111           }
  2325   2112           printf("\n");
  2326   2113         }
  2327   2114       }
  2328         -    for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
  2329         -    sqlite3_free(azResult);
         2115  +    for(ii=0; ii<nRow; ii++) sqlite4_free(0, azResult[ii]);
         2116  +    sqlite4_free(0, azResult);
  2330   2117     }else
  2331   2118   
  2332   2119     if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
  2333   2120       static const struct {
  2334   2121          const char *zCtrlName;   /* Name of a test-control option */
  2335   2122          int ctrlCode;            /* Integer code for that option */
  2336   2123       } aCtrl[] = {
  2337         -      { "prng_save",             SQLITE_TESTCTRL_PRNG_SAVE              },
  2338         -      { "prng_restore",          SQLITE_TESTCTRL_PRNG_RESTORE           },
  2339         -      { "prng_reset",            SQLITE_TESTCTRL_PRNG_RESET             },
  2340         -      { "bitvec_test",           SQLITE_TESTCTRL_BITVEC_TEST            },
  2341         -      { "fault_install",         SQLITE_TESTCTRL_FAULT_INSTALL          },
  2342         -      { "benign_malloc_hooks",   SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS    },
  2343         -      { "pending_byte",          SQLITE_TESTCTRL_PENDING_BYTE           },
  2344         -      { "assert",                SQLITE_TESTCTRL_ASSERT                 },
  2345         -      { "always",                SQLITE_TESTCTRL_ALWAYS                 },
  2346         -      { "reserve",               SQLITE_TESTCTRL_RESERVE                },
  2347         -      { "optimizations",         SQLITE_TESTCTRL_OPTIMIZATIONS          },
  2348         -      { "iskeyword",             SQLITE_TESTCTRL_ISKEYWORD              },
  2349         -      { "scratchmalloc",         SQLITE_TESTCTRL_SCRATCHMALLOC          },
         2124  +      { "fault_install",         SQLITE4_TESTCTRL_FAULT_INSTALL          },
         2125  +      { "assert",                SQLITE4_TESTCTRL_ASSERT                 },
         2126  +      { "always",                SQLITE4_TESTCTRL_ALWAYS                 },
         2127  +      { "optimizations",         SQLITE4_TESTCTRL_OPTIMIZATIONS          },
         2128  +      { "iskeyword",             SQLITE4_TESTCTRL_ISKEYWORD              },
  2350   2129       };
  2351   2130       int testctrl = -1;
  2352   2131       int rc = 0;
  2353   2132       int i, n;
  2354   2133       open_db(p);
  2355   2134   
  2356   2135       /* convert testctrl text option to value. allow any unique prefix
................................................................................
  2364   2143             fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
  2365   2144             testctrl = -1;
  2366   2145             break;
  2367   2146           }
  2368   2147         }
  2369   2148       }
  2370   2149       if( testctrl<0 ) testctrl = atoi(azArg[1]);
  2371         -    if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
         2150  +    if( (testctrl<SQLITE4_TESTCTRL_FIRST) || (testctrl>SQLITE4_TESTCTRL_LAST) ){
  2372   2151         fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
  2373   2152       }else{
  2374   2153         switch(testctrl){
  2375   2154   
  2376         -        /* sqlite3_test_control(int, db, int) */
  2377         -        case SQLITE_TESTCTRL_OPTIMIZATIONS:
  2378         -        case SQLITE_TESTCTRL_RESERVE:             
         2155  +        /* sqlite4_test_control(int, db, int) */
         2156  +        case SQLITE4_TESTCTRL_OPTIMIZATIONS:
         2157  +        case SQLITE4_TESTCTRL_RESERVE:             
  2379   2158             if( nArg==3 ){
  2380   2159               int opt = (int)strtol(azArg[2], 0, 0);        
  2381         -            rc = sqlite3_test_control(testctrl, p->db, opt);
         2160  +            rc = sqlite4_test_control(testctrl, p->db, opt);
  2382   2161               printf("%d (0x%08x)\n", rc, rc);
  2383   2162             } else {
  2384   2163               fprintf(stderr,"Error: testctrl %s takes a single int option\n",
  2385   2164                       azArg[1]);
  2386   2165             }
  2387   2166             break;
  2388   2167   
  2389         -        /* sqlite3_test_control(int) */
  2390         -        case SQLITE_TESTCTRL_PRNG_SAVE:           
  2391         -        case SQLITE_TESTCTRL_PRNG_RESTORE:        
  2392         -        case SQLITE_TESTCTRL_PRNG_RESET:
  2393         -          if( nArg==2 ){
  2394         -            rc = sqlite3_test_control(testctrl);
  2395         -            printf("%d (0x%08x)\n", rc, rc);
  2396         -          } else {
  2397         -            fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
  2398         -          }
  2399         -          break;
  2400         -
  2401         -        /* sqlite3_test_control(int, uint) */
  2402         -        case SQLITE_TESTCTRL_PENDING_BYTE:        
  2403         -          if( nArg==3 ){
  2404         -            unsigned int opt = (unsigned int)atoi(azArg[2]);        
  2405         -            rc = sqlite3_test_control(testctrl, opt);
  2406         -            printf("%d (0x%08x)\n", rc, rc);
  2407         -          } else {
  2408         -            fprintf(stderr,"Error: testctrl %s takes a single unsigned"
  2409         -                           " int option\n", azArg[1]);
  2410         -          }
  2411         -          break;
  2412         -          
  2413         -        /* sqlite3_test_control(int, int) */
  2414         -        case SQLITE_TESTCTRL_ASSERT:              
  2415         -        case SQLITE_TESTCTRL_ALWAYS:              
         2168  +        /* sqlite4_test_control(int, int) */
         2169  +        case SQLITE4_TESTCTRL_ASSERT:              
         2170  +        case SQLITE4_TESTCTRL_ALWAYS:              
  2416   2171             if( nArg==3 ){
  2417   2172               int opt = atoi(azArg[2]);        
  2418         -            rc = sqlite3_test_control(testctrl, opt);
         2173  +            rc = sqlite4_test_control(testctrl, opt);
  2419   2174               printf("%d (0x%08x)\n", rc, rc);
  2420   2175             } else {
  2421   2176               fprintf(stderr,"Error: testctrl %s takes a single int option\n",
  2422   2177                               azArg[1]);
  2423   2178             }
  2424   2179             break;
  2425   2180   
  2426         -        /* sqlite3_test_control(int, char *) */
  2427         -#ifdef SQLITE_N_KEYWORD
  2428         -        case SQLITE_TESTCTRL_ISKEYWORD:           
         2181  +        /* sqlite4_test_control(int, char *) */
         2182  +#ifdef SQLITE4_N_KEYWORD
         2183  +        case SQLITE4_TESTCTRL_ISKEYWORD:           
  2429   2184             if( nArg==3 ){
  2430   2185               const char *opt = azArg[2];        
  2431         -            rc = sqlite3_test_control(testctrl, opt);
         2186  +            rc = sqlite4_test_control(testctrl, opt);
  2432   2187               printf("%d (0x%08x)\n", rc, rc);
  2433   2188             } else {
  2434   2189               fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
  2435   2190                               azArg[1]);
  2436   2191             }
  2437   2192             break;
  2438   2193   #endif
  2439   2194   
  2440         -        case SQLITE_TESTCTRL_BITVEC_TEST:         
  2441         -        case SQLITE_TESTCTRL_FAULT_INSTALL:       
  2442         -        case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: 
  2443         -        case SQLITE_TESTCTRL_SCRATCHMALLOC:       
         2195  +        case SQLITE4_TESTCTRL_FAULT_INSTALL:       
  2444   2196           default:
  2445   2197             fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n",
  2446   2198                     azArg[1]);
  2447   2199             break;
  2448   2200         }
  2449   2201       }
  2450   2202     }else
  2451         -
  2452         -  if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
  2453         -    open_db(p);
  2454         -    sqlite3_busy_timeout(p->db, atoi(azArg[1]));
  2455         -  }else
  2456   2203       
  2457   2204     if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
  2458   2205      && nArg==2
  2459   2206     ){
  2460   2207       enableTimer = booleanValue(azArg[1]);
  2461   2208     }else
  2462   2209     
  2463         -  if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
  2464         -    open_db(p);
  2465         -    output_file_close(p->traceOut);
  2466         -    p->traceOut = output_file_open(azArg[1]);
  2467         -#ifndef SQLITE_OMIT_TRACE
  2468         -    if( p->traceOut==0 ){
  2469         -      sqlite3_trace(p->db, 0, 0);
  2470         -    }else{
  2471         -      sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
  2472         -    }
  2473         -#endif
  2474         -  }else
  2475         -
  2476   2210     if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
  2477   2211       printf("SQLite %s %s\n" /*extra-version-info*/,
  2478         -        sqlite3_libversion(), sqlite3_sourceid());
  2479         -  }else
  2480         -
  2481         -  if( c=='v' && strncmp(azArg[0], "vfsname", n)==0 ){
  2482         -    const char *zDbName = nArg==2 ? azArg[1] : "main";
  2483         -    char *zVfsName = 0;
  2484         -    if( p->db ){
  2485         -      sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName);
  2486         -      if( zVfsName ){
  2487         -        printf("%s\n", zVfsName);
  2488         -        sqlite3_free(zVfsName);
  2489         -      }
  2490         -    }
         2212  +        sqlite4_libversion(), sqlite4_sourceid());
  2491   2213     }else
  2492   2214   
  2493   2215     if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){
  2494   2216       int j;
  2495   2217       assert( nArg<=ArraySize(azArg) );
  2496   2218       for(j=1; j<nArg && j<ArraySize(p->colWidth); j++){
  2497   2219         p->colWidth[j-1] = atoi(azArg[j]);
................................................................................
  2563   2285   ** ends in the middle of a string literal or C-style comment.
  2564   2286   */
  2565   2287   static int _is_complete(char *zSql, int nSql){
  2566   2288     int rc;
  2567   2289     if( zSql==0 ) return 1;
  2568   2290     zSql[nSql] = ';';
  2569   2291     zSql[nSql+1] = 0;
  2570         -  rc = sqlite3_complete(zSql);
         2292  +  rc = sqlite4_complete(zSql);
  2571   2293     zSql[nSql] = 0;
  2572   2294     return rc;
  2573   2295   }
  2574   2296   
  2575   2297   /*
  2576   2298   ** Read input from *in and process it.  If *in==0 then input
  2577   2299   ** is interactive - the user is typing it it.  Otherwise, input
................................................................................
  2593   2315     int startline = 0;
  2594   2316   
  2595   2317     while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){
  2596   2318       fflush(p->out);
  2597   2319       free(zLine);
  2598   2320       zLine = one_input_line(zSql, in);
  2599   2321       if( zLine==0 ){
  2600         -      /* End of input */
  2601         -      if( stdin_is_interactive ) printf("\n");
  2602         -      break;
         2322  +      break;  /* We have reached EOF */
  2603   2323       }
  2604   2324       if( seenInterrupt ){
  2605   2325         if( in!=0 ) break;
  2606   2326         seenInterrupt = 0;
  2607   2327       }
  2608   2328       lineno++;
  2609   2329       if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
................................................................................
  2642   2362           exit(1);
  2643   2363         }
  2644   2364         zSql[nSql++] = '\n';
  2645   2365         memcpy(&zSql[nSql], zLine, len+1);
  2646   2366         nSql += len;
  2647   2367       }
  2648   2368       if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
  2649         -                && sqlite3_complete(zSql) ){
         2369  +                && sqlite4_complete(zSql) ){
  2650   2370         p->cnt = 0;
  2651   2371         open_db(p);
  2652   2372         BEGIN_TIMER;
  2653   2373         rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
  2654   2374         END_TIMER;
  2655   2375         if( rc || zErrMsg ){
  2656   2376           char zPrefix[100];
  2657   2377           if( in!=0 || !stdin_is_interactive ){
  2658         -          sqlite3_snprintf(sizeof(zPrefix), zPrefix, 
         2378  +          sqlite4_snprintf(zPrefix, sizeof(zPrefix),
  2659   2379                              "Error: near line %d:", startline);
  2660   2380           }else{
  2661         -          sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
         2381  +          sqlite4_snprintf(zPrefix, sizeof(zPrefix), "Error:");
  2662   2382           }
  2663   2383           if( zErrMsg!=0 ){
  2664   2384             fprintf(stderr, "%s %s\n", zPrefix, zErrMsg);
  2665         -          sqlite3_free(zErrMsg);
         2385  +          sqlite4_free(0, zErrMsg);
  2666   2386             zErrMsg = 0;
  2667   2387           }else{
  2668         -          fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
         2388  +          fprintf(stderr, "%s %s\n", zPrefix, sqlite4_errmsg(p->db));
  2669   2389           }
  2670   2390           errCnt++;
  2671   2391         }
  2672   2392         free(zSql);
  2673   2393         zSql = 0;
  2674   2394         nSql = 0;
  2675   2395       }
................................................................................
  2682   2402     }
  2683   2403     free(zLine);
  2684   2404     return errCnt;
  2685   2405   }
  2686   2406   
  2687   2407   /*
  2688   2408   ** Return a pathname which is the user's home directory.  A
  2689         -** 0 return indicates an error of some kind.
         2409  +** 0 return indicates an error of some kind.  Space to hold the
         2410  +** resulting string is obtained from malloc().  The calling
         2411  +** function should free the result.
  2690   2412   */
  2691   2413   static char *find_home_dir(void){
  2692         -  static char *home_dir = NULL;
  2693         -  if( home_dir ) return home_dir;
         2414  +  char *home_dir = NULL;
  2694   2415   
  2695         -#if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
  2696         -  {
  2697         -    struct passwd *pwent;
  2698         -    uid_t uid = getuid();
  2699         -    if( (pwent=getpwuid(uid)) != NULL) {
  2700         -      home_dir = pwent->pw_dir;
  2701         -    }
         2416  +#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
         2417  +  struct passwd *pwent;
         2418  +  uid_t uid = getuid();
         2419  +  if( (pwent=getpwuid(uid)) != NULL) {
         2420  +    home_dir = pwent->pw_dir;
  2702   2421     }
  2703   2422   #endif
  2704   2423   
  2705   2424   #if defined(_WIN32_WCE)
  2706   2425     /* Windows CE (arm-wince-mingw32ce-gcc) does not provide getenv()
  2707   2426      */
  2708         -  home_dir = "/";
         2427  +  home_dir = strdup("/");
  2709   2428   #else
  2710   2429   
  2711         -#if defined(_WIN32) || defined(WIN32)
         2430  +#if defined(_WIN32) || defined(WIN32) || defined(__OS2__)
  2712   2431     if (!home_dir) {
  2713   2432       home_dir = getenv("USERPROFILE");
  2714   2433     }
  2715   2434   #endif
  2716   2435   
  2717   2436     if (!home_dir) {
  2718   2437       home_dir = getenv("HOME");
  2719   2438     }
  2720   2439   
  2721         -#if defined(_WIN32) || defined(WIN32)
         2440  +#if defined(_WIN32) || defined(WIN32) || defined(__OS2__)
  2722   2441     if (!home_dir) {
  2723   2442       char *zDrive, *zPath;
  2724   2443       int n;
  2725   2444       zDrive = getenv("HOMEDRIVE");
  2726   2445       zPath = getenv("HOMEPATH");
  2727   2446       if( zDrive && zPath ){
  2728   2447         n = strlen30(zDrive) + strlen30(zPath) + 1;
  2729   2448         home_dir = malloc( n );
  2730   2449         if( home_dir==0 ) return 0;
  2731         -      sqlite3_snprintf(n, home_dir, "%s%s", zDrive, zPath);
         2450  +      sqlite4_snprintf(home_dir, n, "%s%s", zDrive, zPath);
  2732   2451         return home_dir;
  2733   2452       }
  2734   2453       home_dir = "c:\\";
  2735   2454     }
  2736   2455   #endif
  2737   2456   
  2738   2457   #endif /* !_WIN32_WCE */
................................................................................
  2757   2476     struct callback_data *p,        /* Configuration data */
  2758   2477     const char *sqliterc_override   /* Name of config file. NULL to use default */
  2759   2478   ){
  2760   2479     char *home_dir = NULL;
  2761   2480     const char *sqliterc = sqliterc_override;
  2762   2481     char *zBuf = 0;
  2763   2482     FILE *in = NULL;
         2483  +  int nBuf;
  2764   2484     int rc = 0;
  2765   2485   
  2766   2486     if (sqliterc == NULL) {
  2767   2487       home_dir = find_home_dir();
  2768   2488       if( home_dir==0 ){
  2769   2489   #if !defined(__RTP__) && !defined(_WRS_KERNEL)
  2770   2490         fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0);
  2771   2491   #endif
  2772   2492         return 1;
  2773   2493       }
  2774         -    zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
  2775         -    sqliterc = zBuf;
         2494  +    nBuf = strlen30(home_dir) + 16;
         2495  +    zBuf = malloc( nBuf );
         2496  +    if( zBuf==0 ){
         2497  +      fprintf(stderr,"%s: Error: out of memory\n",Argv0);
         2498  +      return 1;
         2499  +    }
         2500  +    sqlite4_snprintf(zBuf,nBuf,"%s/.sqliterc",home_dir);
         2501  +    free(home_dir);
         2502  +    sqliterc = (const char*)zBuf;
  2776   2503     }
  2777   2504     in = fopen(sqliterc,"rb");
  2778   2505     if( in ){
  2779   2506       if( stdin_is_interactive ){
  2780   2507         fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
  2781   2508       }
  2782   2509       rc = process_input(p,in);
  2783   2510       fclose(in);
  2784   2511     }
  2785         -  sqlite3_free(zBuf);
         2512  +  free(zBuf);
  2786   2513     return rc;
  2787   2514   }
  2788   2515   
  2789   2516   /*
  2790   2517   ** Show available command line options
  2791   2518   */
  2792   2519   static const char zOptions[] = 
         2520  +  "   -help                show this message\n"
         2521  +  "   -init filename       read/process named file\n"
         2522  +  "   -echo                print commands before execution\n"
         2523  +  "   -[no]header          turn headers on or off\n"
  2793   2524     "   -bail                stop after hitting an error\n"
         2525  +  "   -interactive         force interactive I/O\n"
  2794   2526     "   -batch               force batch I/O\n"
  2795   2527     "   -column              set output mode to 'column'\n"
  2796         -  "   -cmd command         run \"command\" before reading stdin\n"
  2797   2528     "   -csv                 set output mode to 'csv'\n"
  2798         -  "   -echo                print commands before execution\n"
  2799         -  "   -init filename       read/process named file\n"
  2800         -  "   -[no]header          turn headers on or off\n"
  2801         -  "   -help                show this message\n"
  2802   2529     "   -html                set output mode to HTML\n"
  2803         -  "   -interactive         force interactive I/O\n"
  2804   2530     "   -line                set output mode to 'line'\n"
  2805   2531     "   -list                set output mode to 'list'\n"
  2806         -#ifdef SQLITE_ENABLE_MULTIPLEX
  2807         -  "   -multiplex           enable the multiplexor VFS\n"
  2808         -#endif
  2809         -  "   -nullvalue 'text'    set text string for NULL values\n"
  2810   2532     "   -separator 'x'       set output field separator (|)\n"
  2811   2533     "   -stats               print memory stats before each finalize\n"
         2534  +  "   -nullvalue 'text'    set text string for NULL values\n"
  2812   2535     "   -version             show SQLite version\n"
  2813         -  "   -vfs NAME            use NAME as the default VFS\n"
  2814         -#ifdef SQLITE_ENABLE_VFSTRACE
  2815         -  "   -vfstrace            enable tracing of all VFS calls\n"
         2536  +#ifdef SQLITE4_ENABLE_MULTIPLEX
         2537  +  "   -multiplex           enable the multiplexor VFS\n"
  2816   2538   #endif
  2817   2539   ;
  2818   2540   static void usage(int showDetail){
  2819   2541     fprintf(stderr,
  2820   2542         "Usage: %s [OPTIONS] FILENAME [SQL]\n"  
  2821   2543         "FILENAME is the name of an SQLite database. A new database is created\n"
  2822   2544         "if the file does not previously exist.\n", Argv0);
................................................................................
  2832   2554   ** Initialize the state information in data
  2833   2555   */
  2834   2556   static void main_init(struct callback_data *data) {
  2835   2557     memset(data, 0, sizeof(*data));
  2836   2558     data->mode = MODE_List;
  2837   2559     memcpy(data->separator,"|", 2);
  2838   2560     data->showHeader = 0;
  2839         -  sqlite3_config(SQLITE_CONFIG_URI, 1);
  2840         -  sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
  2841         -  sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
  2842         -  sqlite3_snprintf(sizeof(continuePrompt), continuePrompt,"   ...> ");
  2843         -  sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
         2561  +  sqlite4_env_config(0, SQLITE4_ENVCONFIG_LOG, shellLog, data);
         2562  +  sqlite4_snprintf(mainPrompt,sizeof(mainPrompt),        "sqlite> ");
         2563  +  sqlite4_snprintf(continuePrompt,sizeof(continuePrompt),"   ...> ");
         2564  +  sqlite4_env_config(0, SQLITE4_ENVCONFIG_SINGLETHREAD);
  2844   2565   }
  2845   2566   
  2846   2567   int main(int argc, char **argv){
  2847   2568     char *zErrMsg = 0;
  2848   2569     struct callback_data data;
  2849   2570     const char *zInitFile = 0;
  2850   2571     char *zFirstCmd = 0;
  2851   2572     int i;
  2852   2573     int rc = 0;
  2853   2574   
  2854         -  if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
         2575  +  if( strcmp(sqlite4_sourceid(),SQLITE4_SOURCE_ID)!=0 ){
  2855   2576       fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
  2856         -            sqlite3_sourceid(), SQLITE_SOURCE_ID);
         2577  +            sqlite4_sourceid(), SQLITE4_SOURCE_ID);
  2857   2578       exit(1);
  2858   2579     }
  2859   2580     Argv0 = argv[0];
  2860   2581     main_init(&data);
  2861   2582     stdin_is_interactive = isatty(0);
  2862   2583   
  2863   2584     /* Make sure we have a valid signal handler early, before anything
................................................................................
  2872   2593     ** the size of the alternative malloc heap,
  2873   2594     ** and the first command to execute.
  2874   2595     */
  2875   2596     for(i=1; i<argc-1; i++){
  2876   2597       char *z;
  2877   2598       if( argv[i][0]!='-' ) break;
  2878   2599       z = argv[i];
  2879         -    if( z[1]=='-' ) z++;
  2880         -    if( strcmp(z,"-separator")==0
  2881         -     || strcmp(z,"-nullvalue")==0
  2882         -     || strcmp(z,"-cmd")==0
  2883         -    ){
         2600  +    if( z[0]=='-' && z[1]=='-' ) z++;
         2601  +    if( strcmp(argv[i],"-separator")==0 || strcmp(argv[i],"-nullvalue")==0 ){
  2884   2602         i++;
  2885         -    }else if( strcmp(z,"-init")==0 ){
         2603  +    }else if( strcmp(argv[i],"-init")==0 ){
  2886   2604         i++;
  2887   2605         zInitFile = argv[i];
  2888   2606       /* Need to check for batch mode here to so we can avoid printing
  2889   2607       ** informational messages (like from process_sqliterc) before 
  2890   2608       ** we do the actual processing of arguments later in a second pass.
  2891   2609       */
  2892         -    }else if( strcmp(z,"-batch")==0 ){
         2610  +    }else if( strcmp(argv[i],"-batch")==0 ){
  2893   2611         stdin_is_interactive = 0;
  2894         -    }else if( strcmp(z,"-heap")==0 ){
  2895         -#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
         2612  +    }else if( strcmp(argv[i],"-heap")==0 ){
         2613  +#if defined(SQLITE4_ENABLE_MEMSYS3) || defined(SQLITE4_ENABLE_MEMSYS5)
  2896   2614         int j, c;
  2897   2615         const char *zSize;
  2898         -      sqlite3_int64 szHeap;
         2616  +      sqlite4_int64 szHeap;
  2899   2617   
  2900   2618         zSize = argv[++i];
  2901   2619         szHeap = atoi(zSize);
  2902   2620         for(j=0; (c = zSize[j])!=0; j++){
  2903   2621           if( c=='M' ){ szHeap *= 1000000; break; }
  2904   2622           if( c=='K' ){ szHeap *= 1000; break; }
  2905   2623           if( c=='G' ){ szHeap *= 1000000000; break; }
  2906   2624         }
  2907   2625         if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
  2908         -      sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
         2626  +      sqlite4_config(0,SQLITE4_CONFIG_HEAP, malloc((int)szHeap),(int)szHeap,64);
  2909   2627   #endif
  2910         -#ifdef SQLITE_ENABLE_VFSTRACE
  2911         -    }else if( strcmp(z,"-vfstrace")==0 ){
  2912         -      extern int vfstrace_register(
  2913         -         const char *zTraceName,
  2914         -         const char *zOldVfsName,
  2915         -         int (*xOut)(const char*,void*),
  2916         -         void *pOutArg,
  2917         -         int makeDefault
  2918         -      );
  2919         -      vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1);
         2628  +#ifdef SQLITE4_ENABLE_MULTIPLEX
         2629  +    }else if( strcmp(argv[i],"-multiplex")==0 ){
         2630  +      extern int sqlite4_multiple_initialize(const char*,int);
         2631  +      sqlite4_multiplex_initialize(0, 1);
  2920   2632   #endif
  2921         -#ifdef SQLITE_ENABLE_MULTIPLEX
  2922         -    }else if( strcmp(z,"-multiplex")==0 ){
  2923         -      extern int sqlite3_multiple_initialize(const char*,int);
  2924         -      sqlite3_multiplex_initialize(0, 1);
  2925         -#endif
  2926         -    }else if( strcmp(z,"-vfs")==0 ){
  2927         -      sqlite3_vfs *pVfs = sqlite3_vfs_find(argv[++i]);
  2928         -      if( pVfs ){
  2929         -        sqlite3_vfs_register(pVfs, 1);
  2930         -      }else{
  2931         -        fprintf(stderr, "no such VFS: \"%s\"\n", argv[i]);
  2932         -        exit(1);
  2933         -      }
  2934   2633       }
  2935   2634     }
  2936   2635     if( i<argc ){
         2636  +#if defined(SQLITE4_OS_OS2) && SQLITE4_OS_OS2
         2637  +    data.zDbFilename = (const char *)convertCpPathToUtf8( argv[i++] );
         2638  +#else
  2937   2639       data.zDbFilename = argv[i++];
         2640  +#endif
  2938   2641     }else{
  2939         -#ifndef SQLITE_OMIT_MEMORYDB
         2642  +#ifndef SQLITE4_OMIT_MEMORYDB
  2940   2643       data.zDbFilename = ":memory:";
  2941   2644   #else
  2942   2645       data.zDbFilename = 0;
  2943   2646   #endif
  2944   2647       /***** Begin Fossil Patch *****/
  2945   2648       {
  2946   2649         extern void fossil_open(const char **);
................................................................................
  2954   2657     if( i<argc ){
  2955   2658       fprintf(stderr,"%s: Error: too many options: \"%s\"\n", Argv0, argv[i]);
  2956   2659       fprintf(stderr,"Use -help for a list of options.\n");
  2957   2660       return 1;
  2958   2661     }
  2959   2662     data.out = stdout;
  2960   2663   
  2961         -#ifdef SQLITE_OMIT_MEMORYDB
         2664  +#ifdef SQLITE4_OMIT_MEMORYDB
  2962   2665     if( data.zDbFilename==0 ){
  2963   2666       fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
  2964   2667       return 1;
  2965   2668     }
  2966   2669   #endif
  2967   2670   
  2968   2671     /* Go ahead and open the database file if it already exists.  If the
................................................................................
  3003   2706         data.mode = MODE_Column;
  3004   2707       }else if( strcmp(z,"-csv")==0 ){
  3005   2708         data.mode = MODE_Csv;
  3006   2709         memcpy(data.separator,",",2);
  3007   2710       }else if( strcmp(z,"-separator")==0 ){
  3008   2711         i++;
  3009   2712         if(i>=argc){
  3010         -        fprintf(stderr,"%s: Error: missing argument for option: %s\n",
  3011         -                        Argv0, z);
         2713  +        fprintf(stderr,"%s: Error: missing argument for option: %s\n", Argv0, z);
  3012   2714           fprintf(stderr,"Use -help for a list of options.\n");
  3013   2715           return 1;
  3014   2716         }
  3015         -      sqlite3_snprintf(sizeof(data.separator), data.separator,
         2717  +      sqlite4_snprintf(data.separator, sizeof(data.separator),
  3016   2718                          "%.*s",(int)sizeof(data.separator)-1,argv[i]);
  3017   2719       }else if( strcmp(z,"-nullvalue")==0 ){
  3018   2720         i++;
  3019   2721         if(i>=argc){
  3020         -        fprintf(stderr,"%s: Error: missing argument for option: %s\n",
  3021         -                        Argv0, z);
         2722  +        fprintf(stderr,"%s: Error: missing argument for option: %s\n", Argv0, z);
  3022   2723           fprintf(stderr,"Use -help for a list of options.\n");
  3023   2724           return 1;
  3024   2725         }
  3025         -      sqlite3_snprintf(sizeof(data.nullvalue), data.nullvalue,
         2726  +      sqlite4_snprintf(data.nullvalue, sizeof(data.nullvalue),
  3026   2727                          "%.*s",(int)sizeof(data.nullvalue)-1,argv[i]);
  3027   2728       }else if( strcmp(z,"-header")==0 ){
  3028   2729         data.showHeader = 1;
  3029   2730       }else if( strcmp(z,"-noheader")==0 ){
  3030   2731         data.showHeader = 0;
  3031   2732       }else if( strcmp(z,"-echo")==0 ){
  3032   2733         data.echoOn = 1;
  3033   2734       }else if( strcmp(z,"-stats")==0 ){
  3034   2735         data.statsOn = 1;
  3035   2736       }else if( strcmp(z,"-bail")==0 ){
  3036   2737         bail_on_error = 1;
  3037   2738       }else if( strcmp(z,"-version")==0 ){
  3038         -      printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
         2739  +      printf("%s %s\n", sqlite4_libversion(), sqlite4_sourceid());
  3039   2740         return 0;
  3040   2741       }else if( strcmp(z,"-interactive")==0 ){
  3041   2742         stdin_is_interactive = 1;
  3042   2743       }else if( strcmp(z,"-batch")==0 ){
  3043   2744         stdin_is_interactive = 0;
  3044   2745       }else if( strcmp(z,"-heap")==0 ){
  3045   2746         i++;
  3046         -    }else if( strcmp(z,"-vfs")==0 ){
  3047         -      i++;
  3048         -#ifdef SQLITE_ENABLE_VFSTRACE
  3049         -    }else if( strcmp(z,"-vfstrace")==0 ){
  3050         -      i++;
  3051         -#endif
  3052         -#ifdef SQLITE_ENABLE_MULTIPLEX
         2747  +#ifdef SQLITE4_ENABLE_MULTIPLEX
  3053   2748       }else if( strcmp(z,"-multiplex")==0 ){
  3054   2749         i++;
  3055   2750   #endif
  3056         -    }else if( strcmp(z,"-help")==0 ){
         2751  +    }else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){
  3057   2752         usage(1);
  3058         -    }else if( strcmp(z,"-cmd")==0 ){
  3059         -      if( i==argc-1 ) break;
  3060         -      i++;
  3061         -      z = argv[i];
  3062         -      if( z[0]=='.' ){
  3063         -        rc = do_meta_command(z, &data);
  3064         -        if( rc && bail_on_error ) return rc;
  3065         -      }else{
  3066         -        open_db(&data);
  3067         -        rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
  3068         -        if( zErrMsg!=0 ){
  3069         -          fprintf(stderr,"Error: %s\n", zErrMsg);
  3070         -          if( bail_on_error ) return rc!=0 ? rc : 1;
  3071         -        }else if( rc!=0 ){
  3072         -          fprintf(stderr,"Error: unable to process SQL \"%s\"\n", z);
  3073         -          if( bail_on_error ) return rc;
  3074         -        }
  3075         -      }
  3076   2753       }else{
  3077   2754         fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
  3078   2755         fprintf(stderr,"Use -help for a list of options.\n");
  3079   2756         return 1;
  3080   2757       }
  3081   2758     }
  3082   2759   
................................................................................
  3103   2780         char *zHome;
  3104   2781         char *zHistory = 0;
  3105   2782         int nHistory;
  3106   2783         printf(
  3107   2784           "SQLite version %s %.19s\n" /*extra-version-info*/
  3108   2785           "Enter \".help\" for instructions\n"
  3109   2786           "Enter SQL statements terminated with a \";\"\n",
  3110         -        sqlite3_libversion(), sqlite3_sourceid()
         2787  +        sqlite4_libversion(), sqlite4_sourceid()
  3111   2788         );
  3112   2789         zHome = find_home_dir();
  3113   2790         if( zHome ){
  3114   2791           nHistory = strlen30(zHome) + 20;
  3115   2792           if( (zHistory = malloc(nHistory))!=0 ){
  3116         -          sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
         2793  +          sqlite4_snprintf(zHistory, nHistory, "%s/.sqlite_history", zHome);
  3117   2794           }
  3118   2795         }
  3119   2796   #if defined(HAVE_READLINE) && HAVE_READLINE==1
  3120   2797         if( zHistory ) read_history(zHistory);
  3121   2798   #endif
  3122   2799         rc = process_input(&data, 0);
  3123   2800         if( zHistory ){
  3124   2801           stifle_history(100);
  3125   2802           write_history(zHistory);
  3126   2803           free(zHistory);
  3127   2804         }
         2805  +      free(zHome);
  3128   2806       }else{
  3129   2807         rc = process_input(&data, stdin);
  3130   2808       }
  3131   2809     }
  3132   2810     set_table_name(&data, 0);
  3133   2811     if( data.db ){
  3134         -    sqlite3_close(data.db);
         2812  +    sqlite4_close(data.db);
  3135   2813     }
  3136   2814     return rc;
  3137   2815   }

Changes to src/shun.c.

    28     28     static Stmt q;
    29     29     int rc;
    30     30     if( zUuid==0 || zUuid[0]==0 ) return 0;
    31     31     db_static_prepare(&q, "SELECT 1 FROM shun WHERE uuid=:uuid");
    32     32     db_bind_text(&q, ":uuid", zUuid);
    33     33     rc = db_step(&q);
    34     34     db_reset(&q);
    35         -  return rc==SQLITE_ROW;
           35  +  return rc==SQLITE4_ROW;
    36     36   }
    37     37   
    38     38   /*
    39     39   ** WEBPAGE: shun
    40     40   */
    41     41   void shun_page(void){
    42     42     Stmt q;
................................................................................
   162    162     @ </blockquote>
   163    163     @ 
   164    164     @ <hr /><p>Shunned Artifacts:</p>
   165    165     @ <blockquote><p>
   166    166     db_prepare(&q, 
   167    167        "SELECT uuid, EXISTS(SELECT 1 FROM blob WHERE blob.uuid=shun.uuid)"
   168    168        "  FROM shun ORDER BY uuid");
   169         -  while( db_step(&q)==SQLITE_ROW ){
          169  +  while( db_step(&q)==SQLITE4_ROW ){
   170    170       const char *zUuid = db_column_text(&q, 0);
   171    171       int stillExists = db_column_int(&q, 1);
   172    172       cnt++;
   173    173       if( stillExists ){
   174    174         @ <b><a href="%s(g.zTop)/artifact/%s(zUuid)">%s(zUuid)</a></b><br />
   175    175       }else{
   176    176         @ <b>%s(zUuid)</b><br />
................................................................................
   192    192     db_multi_exec(
   193    193        "CREATE TEMP TABLE toshun(rid INTEGER PRIMARY KEY);"
   194    194        "INSERT INTO toshun SELECT rid FROM blob, shun WHERE blob.uuid=shun.uuid;"
   195    195     );
   196    196     db_prepare(&q,
   197    197        "SELECT rid FROM delta WHERE srcid IN toshun"
   198    198     );
   199         -  while( db_step(&q)==SQLITE_ROW ){
          199  +  while( db_step(&q)==SQLITE4_ROW ){
   200    200       int srcid = db_column_int(&q, 0);
   201    201       content_undelta(srcid);
   202    202     }
   203    203     db_finalize(&q);
   204    204     db_multi_exec(
   205    205        "DELETE FROM delta WHERE rid IN toshun;"
   206    206        "DELETE FROM blob WHERE rid IN toshun;"
................................................................................
   247    247     @
   248    248     @ <table cellpadding="0" cellspacing="0" border="0">
   249    249     @ <tr><th style="padding-right: 15px;text-align: right;">rcvid</th>
   250    250     @     <th style="padding-right: 15px;text-align: left;">Date</th>
   251    251     @     <th style="padding-right: 15px;text-align: left;">User</th>
   252    252     @     <th style="text-align: left;">IP&nbsp;Address</th></tr>
   253    253     cnt = 0;
   254         -  while( db_step(&q)==SQLITE_ROW ){
          254  +  while( db_step(&q)==SQLITE4_ROW ){
   255    255       int rcvid = db_column_int(&q, 0);
   256    256       const char *zUser = db_column_text(&q, 1);
   257    257       const char *zDate = db_column_text(&q, 2);
   258    258       const char *zIpAddr = db_column_text(&q, 3);
   259    259       if( cnt==30 ){
   260    260         style_submenu_element("Older", "Older",
   261    261            "rcvfromlist?ofst=%d", ofst+30);
................................................................................
   293    293       "  FROM rcvfrom LEFT JOIN user USING(uid)"
   294    294       " WHERE rcvid=%d",
   295    295       rcvid
   296    296     );
   297    297     @ <table cellspacing="15" cellpadding="0" border="0">
   298    298     @ <tr><td valign="top" align="right"><b>rcvid:</b></td>
   299    299     @ <td valign="top">%d(rcvid)</td></tr>
   300         -  if( db_step(&q)==SQLITE_ROW ){
          300  +  if( db_step(&q)==SQLITE4_ROW ){
   301    301       const char *zUser = db_column_text(&q, 0);
   302    302       const char *zDate = db_column_text(&q, 1);
   303    303       const char *zIpAddr = db_column_text(&q, 2);
   304    304       @ <tr><td valign="top" align="right"><b>User:</b></td>
   305    305       @ <td valign="top">%s(zUser)</td></tr>
   306    306       @ <tr><td valign="top" align="right"><b>Date:</b></td>
   307    307       @ <td valign="top">%s(zDate)</td></tr>
................................................................................
   310    310     }
   311    311     db_finalize(&q);
   312    312     db_prepare(&q,
   313    313       "SELECT rid, uuid, size FROM blob WHERE rcvid=%d", rcvid
   314    314     );
   315    315     @ <tr><td valign="top" align="right"><b>Artifacts:</b></td>
   316    316     @ <td valign="top">
   317         -  while( db_step(&q)==SQLITE_ROW ){
          317  +  while( db_step(&q)==SQLITE4_ROW ){
   318    318       int rid = db_column_int(&q, 0);
   319    319       const char *zUuid = db_column_text(&q, 1);
   320    320       int size = db_column_int(&q, 2);
   321    321       @ <a href="%s(g.zTop)/info/%s(zUuid)">%s(zUuid)</a>
   322    322       @ (rid: %d(rid), size: %d(size))<br />
   323    323     }
   324    324     @ </td></tr>
   325    325     @ </table>
   326    326     db_finalize(&q);
   327    327     style_footer();
   328    328   }

Changes to src/skins.c.

  1132   1132       }
  1133   1133     }
  1134   1134     db_prepare(&q,
  1135   1135        "SELECT substr(name, 6), value FROM config"
  1136   1136        " WHERE name GLOB 'skin:*'"
  1137   1137        " ORDER BY name"
  1138   1138     );
  1139         -  while( db_step(&q)==SQLITE_ROW ){
         1139  +  while( db_step(&q)==SQLITE4_ROW ){
  1140   1140       const char *zN = db_column_text(&q, 0);
  1141   1141       const char *zV = db_column_text(&q, 1);
  1142   1142       if( fossil_strcmp(zV, zCurrent)==0 ){
  1143   1143         @ <li><p>%h(zN).&nbsp;&nbsp;  <b>Currently In Use</b></p>
  1144   1144       }else{
  1145   1145         @ <li><form action="%s(g.zTop)/setup_skin" method="post">
  1146   1146         @ %h(zN).&nbsp;&nbsp; 

Changes to src/sqlcmd.c.

    11     11   **
    12     12   ** Author contact information:
    13     13   **   drh@hwaci.com
    14     14   **   http://www.hwaci.com/drh/
    15     15   **
    16     16   *******************************************************************************
    17     17   **
    18         -** This module contains the code that initializes the "sqlite3" command-line
           18  +** This module contains the code that initializes the "sqlite4" command-line
    19     19   ** shell against the repository database.  The command-line shell itself
    20     20   ** is a copy of the "shell.c" code from SQLite.  This file contains logic
    21     21   ** to initialize the code in shell.c.
    22     22   */
    23     23   #include "config.h"
    24     24   #include "sqlcmd.h"
    25     25   #include <zlib.h>
    26     26   
    27     27   /*
    28     28   ** Implementation of the "content(X)" SQL function.  Return the complete
    29     29   ** content of artifact identified by X as a blob.
    30     30   */
    31     31   static void sqlcmd_content(
    32         -  sqlite3_context *context,
           32  +  sqlite4_context *context,
    33     33     int argc,
    34         -  sqlite3_value **argv
           34  +  sqlite4_value **argv
    35     35   ){
    36     36     int rid;
    37     37     Blob cx;
    38     38     const char *zName;
    39     39     assert( argc==1 );
    40         -  zName = (const char*)sqlite3_value_text(argv[0]);
           40  +  zName = (const char*)sqlite4_value_text(argv[0]);
    41     41     if( zName==0 ) return;
    42         -  g.db = sqlite3_context_db_handle(context);
           42  +  g.db = sqlite4_context_db_handle(context);
    43     43     g.repositoryOpen = 1;
    44     44     rid = name_to_rid(zName);
    45     45     if( rid==0 ) return;
    46     46     if( content_get(rid, &cx) ){
    47         -    sqlite3_result_blob(context, blob_buffer(&cx), blob_size(&cx), 
    48         -                                 SQLITE_TRANSIENT);
           47  +    sqlite4_result_blob(context, blob_buffer(&cx), blob_size(&cx), 
           48  +                                 SQLITE4_TRANSIENT);
    49     49       blob_reset(&cx);
    50     50     }
    51     51   }
    52     52   
    53     53   /*
    54     54   ** Implementation of the "compress(X)" SQL function.  The input X is
    55     55   ** compressed using zLib and the output is returned.
    56     56   */
    57     57   static void sqlcmd_compress(
    58         -  sqlite3_context *context,
           58  +  sqlite4_context *context,
    59     59     int argc,
    60         -  sqlite3_value **argv
           60  +  sqlite4_value **argv
    61     61   ){
    62     62     const unsigned char *pIn;
    63     63     unsigned char *pOut;
    64     64     unsigned int nIn;
    65     65     unsigned long int nOut;
    66     66   
    67         -  pIn = sqlite3_value_blob(argv[0]);
    68         -  nIn = sqlite3_value_bytes(argv[0]);
           67  +  pIn = sqlite4_value_blob(argv[0]);
           68  +  nIn = sqlite4_value_bytes(argv[0]);
    69     69     nOut = 13 + nIn + (nIn+999)/1000;
    70         -  pOut = sqlite3_malloc( nOut+4 );
           70  +  pOut = sqlite4_malloc(0, nOut+4);
    71     71     pOut[0] = nIn>>24 & 0xff;
    72     72     pOut[1] = nIn>>16 & 0xff;
    73     73     pOut[2] = nIn>>8 & 0xff;
    74     74     pOut[3] = nIn & 0xff;
    75     75     compress(&pOut[4], &nOut, pIn, nIn);
    76         -  sqlite3_result_blob(context, pOut, nOut+4, sqlite3_free);
           76  +  sqlite4_result_blob(context, pOut, nOut+4, SQLITE4_DYNAMIC);
    77     77   }
    78     78   
    79     79   /*
    80     80   ** Implementation of the "decompress(X)" SQL function.  The argument X
    81     81   ** is a blob which was obtained from compress(Y).  The output will be
    82     82   ** the value Y.
    83     83   */
    84     84   static void sqlcmd_decompress(
    85         -  sqlite3_context *context,
           85  +  sqlite4_context *context,
    86     86     int argc,
    87         -  sqlite3_value **argv
           87  +  sqlite4_value **argv
    88     88   ){
    89     89     const unsigned char *pIn;
    90     90     unsigned char *pOut;
    91     91     unsigned int nIn;
    92     92     unsigned long int nOut;
    93     93     int rc;
    94     94   
    95         -  pIn = sqlite3_value_blob(argv[0]);
    96         -  nIn = sqlite3_value_bytes(argv[0]);
           95  +  pIn = sqlite4_value_blob(argv[0]);
           96  +  nIn = sqlite4_value_bytes(argv[0]);
    97     97     nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3];
    98         -  pOut = sqlite3_malloc( nOut+1 );
           98  +  pOut = sqlite4_malloc(0, nOut+1);
    99     99     rc = uncompress(pOut, &nOut, &pIn[4], nIn-4);
   100    100     if( rc==Z_OK ){
   101         -    sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
          101  +    sqlite4_result_blob(context, pOut, nOut, SQLITE4_DYNAMIC);
   102    102     }else{
   103         -    sqlite3_result_error(context, "input is not zlib compressed", -1);
          103  +    sqlite4_result_error(context, "input is not zlib compressed", -1);
   104    104     }
   105    105   }
   106    106   
   107    107   /*
   108    108   ** This is the "automatic extensionn" initializer that runs right after
   109    109   ** the connection to the repository database is opened.  Set up the
   110    110   ** database connection to be more useful to the human operator.
   111    111   */
   112    112   static int sqlcmd_autoinit(
   113         -  sqlite3 *db,
          113  +  sqlite4 *db,
   114    114     const char **pzErrMsg,
   115    115     const void *notUsed
   116    116   ){
   117         -  sqlite3_create_function(db, "content", 1, SQLITE_ANY, 0,
          117  +  sqlite4_create_function(db, "content", 1, SQLITE4_ANY, 0,
   118    118                             sqlcmd_content, 0, 0);
   119         -  sqlite3_create_function(db, "compress", 1, SQLITE_ANY, 0,
          119  +  sqlite4_create_function(db, "compress", 1, SQLITE4_ANY, 0,
   120    120                             sqlcmd_compress, 0, 0);
   121         -  sqlite3_create_function(db, "decompress", 1, SQLITE_ANY, 0,
          121  +  sqlite4_create_function(db, "decompress", 1, SQLITE4_ANY, 0,
   122    122                             sqlcmd_decompress, 0, 0);
   123         -  return SQLITE_OK;
          123  +  return SQLITE4_OK;
   124    124   }
   125    125   
   126    126   
   127    127   /*
   128         -** COMMAND: sqlite3
          128  +** COMMAND: sqlite4
   129    129   **
   130         -** Usage: %fossil sqlite3 ?DATABASE? ?OPTIONS?
          130  +** Usage: %fossil sqlite4 ?DATABASE? ?OPTIONS?
   131    131   **
   132         -** Run the standalone sqlite3 command-line shell on DATABASE with OPTIONS.
          132  +** Run the standalone sqlite4 command-line shell on DATABASE with OPTIONS.
   133    133   ** If DATABASE is omitted, then the repository that serves the working
   134    134   ** directory is opened.
   135    135   **
   136    136   ** WARNING:  Careless use of this command can corrupt a Fossil repository
   137    137   ** in ways that are unrecoverable.  Be sure you know what you are doing before
   138    138   ** running any SQL commands that modifies the repository database.
   139    139   */
   140         -void sqlite3_cmd(void){
   141         -  extern int sqlite3_shell(int, char**);
          140  +void sqlite4_cmd(void){
          141  +  extern int sqlite4_shell(int, char**);
   142    142     db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
   143    143     db_close(1);
   144         -  sqlite3_shutdown();
   145         -  sqlite3_shell(g.argc-1, g.argv+1);
          144  +  sqlite4_shutdown(0);
          145  +  sqlite4_shell(g.argc-1, g.argv+1);
   146    146   }
   147    147   
   148    148   /*
   149         -** This routine is called by the patched sqlite3 command-line shell in order
          149  +** This routine is called by the patched sqlite4 command-line shell in order
   150    150   ** to load the name and database connection for the open Fossil database.
   151    151   */
   152    152   void fossil_open(const char **pzRepoName){
   153         -  sqlite3_auto_extension((void(*)(void))sqlcmd_autoinit);
          153  +  /*sqlite4_auto_extension((void(*)(void))sqlcmd_autoinit);*/
   154    154     *pzRepoName = g.zRepositoryName;
   155    155   }

Deleted src/sqlite3.c.

more than 10,000 changes

Deleted src/sqlite3.h.

     1         -/*
     2         -** 2001 September 15
     3         -**
     4         -** The author disclaims copyright to this source code.  In place of
     5         -** a legal notice, here is a blessing:
     6         -**
     7         -**    May you do good and not evil.
     8         -**    May you find forgiveness for yourself and forgive others.
     9         -**    May you share freely, never taking more than you give.
    10         -**
    11         -*************************************************************************
    12         -** This header file defines the interface that the SQLite library
    13         -** presents to client programs.  If a C-function, structure, datatype,
    14         -** or constant definition does not appear in this file, then it is
    15         -** not a published API of SQLite, is subject to change without
    16         -** notice, and should not be referenced by programs that use SQLite.
    17         -**
    18         -** Some of the definitions that are in this file are marked as
    19         -** "experimental".  Experimental interfaces are normally new
    20         -** features recently added to SQLite.  We do not anticipate changes
    21         -** to experimental interfaces but reserve the right to make minor changes
    22         -** if experience from use "in the wild" suggest such changes are prudent.
    23         -**
    24         -** The official C-language API documentation for SQLite is derived
    25         -** from comments in this file.  This file is the authoritative source
    26         -** on how SQLite interfaces are suppose to operate.
    27         -**
    28         -** The name of this file under configuration management is "sqlite.h.in".
    29         -** The makefile makes some minor changes to this file (such as inserting
    30         -** the version number) and changes its name to "sqlite3.h" as
    31         -** part of the build process.
    32         -*/
    33         -#ifndef _SQLITE3_H_
    34         -#define _SQLITE3_H_
    35         -#include <stdarg.h>     /* Needed for the definition of va_list */
    36         -
    37         -/*
    38         -** Make sure we can call this stuff from C++.
    39         -*/
    40         -#ifdef __cplusplus
    41         -extern "C" {
    42         -#endif
    43         -
    44         -
    45         -/*
    46         -** Add the ability to override 'extern'
    47         -*/
    48         -#ifndef SQLITE_EXTERN
    49         -# define SQLITE_EXTERN extern
    50         -#endif
    51         -
    52         -#ifndef SQLITE_API
    53         -# define SQLITE_API
    54         -#endif
    55         -
    56         -
    57         -/*
    58         -** These no-op macros are used in front of interfaces to mark those
    59         -** interfaces as either deprecated or experimental.  New applications
    60         -** should not use deprecated interfaces - they are support for backwards
    61         -** compatibility only.  Application writers should be aware that
    62         -** experimental interfaces are subject to change in point releases.
    63         -**
    64         -** These macros used to resolve to various kinds of compiler magic that
    65         -** would generate warning messages when they were used.  But that
    66         -** compiler magic ended up generating such a flurry of bug reports
    67         -** that we have taken it all out and gone back to using simple
    68         -** noop macros.
    69         -*/
    70         -#define SQLITE_DEPRECATED
    71         -#define SQLITE_EXPERIMENTAL
    72         -
    73         -/*
    74         -** Ensure these symbols were not defined by some previous header file.
    75         -*/
    76         -#ifdef SQLITE_VERSION
    77         -# undef SQLITE_VERSION
    78         -#endif
    79         -#ifdef SQLITE_VERSION_NUMBER
    80         -# undef SQLITE_VERSION_NUMBER
    81         -#endif
    82         -
    83         -/*
    84         -** CAPI3REF: Compile-Time Library Version Numbers
    85         -**
    86         -** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
    87         -** evaluates to a string literal that is the SQLite version in the
    88         -** format "X.Y.Z" where X is the major version number (always 3 for
    89         -** SQLite3) and Y is the minor version number and Z is the release number.)^
    90         -** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
    91         -** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
    92         -** numbers used in [SQLITE_VERSION].)^
    93         -** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
    94         -** be larger than the release from which it is derived.  Either Y will
    95         -** be held constant and Z will be incremented or else Y will be incremented
    96         -** and Z will be reset to zero.
    97         -**
    98         -** Since version 3.6.18, SQLite source code has been stored in the
    99         -** <a href="http://www.fossil-scm.org/">Fossil configuration management
   100         -** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
   101         -** a string which identifies a particular check-in of SQLite
   102         -** within its configuration management system.  ^The SQLITE_SOURCE_ID
   103         -** string contains the date and time of the check-in (UTC) and an SHA1
   104         -** hash of the entire source tree.
   105         -**
   106         -** See also: [sqlite3_libversion()],
   107         -** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   108         -** [sqlite_version()] and [sqlite_source_id()].
   109         -*/
   110         -#define SQLITE_VERSION        "3.7.14"
   111         -#define SQLITE_VERSION_NUMBER 3007014
   112         -#define SQLITE_SOURCE_ID      "2012-06-21 17:21:52 d5e6880279210ca63e2d5e7f6d009f30566f1242"
   113         -
   114         -/*
   115         -** CAPI3REF: Run-Time Library Version Numbers
   116         -** KEYWORDS: sqlite3_version, sqlite3_sourceid
   117         -**
   118         -** These interfaces provide the same information as the [SQLITE_VERSION],
   119         -** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
   120         -** but are associated with the library instead of the header file.  ^(Cautious
   121         -** programmers might include assert() statements in their application to
   122         -** verify that values returned by these interfaces match the macros in
   123         -** the header, and thus insure that the application is
   124         -** compiled with matching library and header files.
   125         -**
   126         -** <blockquote><pre>
   127         -** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
   128         -** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
   129         -** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
   130         -** </pre></blockquote>)^
   131         -**
   132         -** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
   133         -** macro.  ^The sqlite3_libversion() function returns a pointer to the
   134         -** to the sqlite3_version[] string constant.  The sqlite3_libversion()
   135         -** function is provided for use in DLLs since DLL users usually do not have
   136         -** direct access to string constants within the DLL.  ^The
   137         -** sqlite3_libversion_number() function returns an integer equal to
   138         -** [SQLITE_VERSION_NUMBER].  ^The sqlite3_sourceid() function returns 
   139         -** a pointer to a string constant whose value is the same as the 
   140         -** [SQLITE_SOURCE_ID] C preprocessor macro.
   141         -**
   142         -** See also: [sqlite_version()] and [sqlite_source_id()].
   143         -*/
   144         -SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
   145         -SQLITE_API const char *sqlite3_libversion(void);
   146         -SQLITE_API const char *sqlite3_sourceid(void);
   147         -SQLITE_API int sqlite3_libversion_number(void);
   148         -
   149         -/*
   150         -** CAPI3REF: Run-Time Library Compilation Options Diagnostics
   151         -**
   152         -** ^The sqlite3_compileoption_used() function returns 0 or 1 
   153         -** indicating whether the specified option was defined at 
   154         -** compile time.  ^The SQLITE_ prefix may be omitted from the 
   155         -** option name passed to sqlite3_compileoption_used().  
   156         -**
   157         -** ^The sqlite3_compileoption_get() function allows iterating
   158         -** over the list of options that were defined at compile time by
   159         -** returning the N-th compile time option string.  ^If N is out of range,
   160         -** sqlite3_compileoption_get() returns a NULL pointer.  ^The SQLITE_ 
   161         -** prefix is omitted from any strings returned by 
   162         -** sqlite3_compileoption_get().
   163         -**
   164         -** ^Support for the diagnostic functions sqlite3_compileoption_used()
   165         -** and sqlite3_compileoption_get() may be omitted by specifying the 
   166         -** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
   167         -**
   168         -** See also: SQL functions [sqlite_compileoption_used()] and
   169         -** [sqlite_compileoption_get()] and the [compile_options pragma].
   170         -*/
   171         -#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
   172         -SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
   173         -SQLITE_API const char *sqlite3_compileoption_get(int N);
   174         -#endif
   175         -
   176         -/*
   177         -** CAPI3REF: Test To See If The Library Is Threadsafe
   178         -**
   179         -** ^The sqlite3_threadsafe() function returns zero if and only if
   180         -** SQLite was compiled with mutexing code omitted due to the
   181         -** [SQLITE_THREADSAFE] compile-time option being set to 0.
   182         -**
   183         -** SQLite can be compiled with or without mutexes.  When
   184         -** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
   185         -** are enabled and SQLite is threadsafe.  When the
   186         -** [SQLITE_THREADSAFE] macro is 0, 
   187         -** the mutexes are omitted.  Without the mutexes, it is not safe
   188         -** to use SQLite concurrently from more than one thread.
   189         -**
   190         -** Enabling mutexes incurs a measurable performance penalty.
   191         -** So if speed is of utmost importance, it makes sense to disable
   192         -** the mutexes.  But for maximum safety, mutexes should be enabled.
   193         -** ^The default behavior is for mutexes to be enabled.
   194         -**
   195         -** This interface can be used by an application to make sure that the
   196         -** version of SQLite that it is linking against was compiled with
   197         -** the desired setting of the [SQLITE_THREADSAFE] macro.
   198         -**
   199         -** This interface only reports on the compile-time mutex setting
   200         -** of the [SQLITE_THREADSAFE] flag.  If SQLite is compiled with
   201         -** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
   202         -** can be fully or partially disabled using a call to [sqlite3_config()]
   203         -** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
   204         -** or [SQLITE_CONFIG_MUTEX].  ^(The return value of the
   205         -** sqlite3_threadsafe() function shows only the compile-time setting of
   206         -** thread safety, not any run-time changes to that setting made by
   207         -** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
   208         -** is unchanged by calls to sqlite3_config().)^
   209         -**
   210         -** See the [threading mode] documentation for additional information.
   211         -*/
   212         -SQLITE_API int sqlite3_threadsafe(void);
   213         -
   214         -/*
   215         -** CAPI3REF: Database Connection Handle
   216         -** KEYWORDS: {database connection} {database connections}
   217         -**
   218         -** Each open SQLite database is represented by a pointer to an instance of
   219         -** the opaque structure named "sqlite3".  It is useful to think of an sqlite3
   220         -** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and
   221         -** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
   222         -** and [sqlite3_close_v2()] are its destructors.  There are many other
   223         -** interfaces (such as
   224         -** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
   225         -** [sqlite3_busy_timeout()] to name but three) that are methods on an
   226         -** sqlite3 object.
   227         -*/
   228         -typedef struct sqlite3 sqlite3;
   229         -
   230         -/*
   231         -** CAPI3REF: 64-Bit Integer Types
   232         -** KEYWORDS: sqlite_int64 sqlite_uint64
   233         -**
   234         -** Because there is no cross-platform way to specify 64-bit integer types
   235         -** SQLite includes typedefs for 64-bit signed and unsigned integers.
   236         -**
   237         -** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
   238         -** The sqlite_int64 and sqlite_uint64 types are supported for backwards
   239         -** compatibility only.
   240         -**
   241         -** ^The sqlite3_int64 and sqlite_int64 types can store integer values
   242         -** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
   243         -** sqlite3_uint64 and sqlite_uint64 types can store integer values 
   244         -** between 0 and +18446744073709551615 inclusive.
   245         -*/
   246         -#ifdef SQLITE_INT64_TYPE
   247         -  typedef SQLITE_INT64_TYPE sqlite_int64;
   248         -  typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
   249         -#elif defined(_MSC_VER) || defined(__BORLANDC__)
   250         -  typedef __int64 sqlite_int64;
   251         -  typedef unsigned __int64 sqlite_uint64;
   252         -#else
   253         -  typedef long long int sqlite_int64;
   254         -  typedef unsigned long long int sqlite_uint64;
   255         -#endif
   256         -typedef sqlite_int64 sqlite3_int64;
   257         -typedef sqlite_uint64 sqlite3_uint64;
   258         -
   259         -/*
   260         -** If compiling for a processor that lacks floating point support,
   261         -** substitute integer for floating-point.
   262         -*/
   263         -#ifdef SQLITE_OMIT_FLOATING_POINT
   264         -# define double sqlite3_int64
   265         -#endif
   266         -
   267         -/*
   268         -** CAPI3REF: Closing A Database Connection
   269         -**
   270         -** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
   271         -** for the [sqlite3] object.
   272         -** ^Calls to sqlite3_close() and sqlite3_close_v2() return SQLITE_OK if
   273         -** the [sqlite3] object is successfully destroyed and all associated
   274         -** resources are deallocated.
   275         -**
   276         -** ^If the database connection is associated with unfinalized prepared
   277         -** statements or unfinished sqlite3_backup objects then sqlite3_close()
   278         -** will leave the database connection open and return [SQLITE_BUSY].
   279         -** ^If sqlite3_close_v2() is called with unfinalized prepared statements
   280         -** and unfinished sqlite3_backups, then the database connection becomes
   281         -** an unusable "zombie" which will automatically be deallocated when the
   282         -** last prepared statement is finalized or the last sqlite3_backup is
   283         -** finished.  The sqlite3_close_v2() interface is intended for use with
   284         -** host languages that are garbage collected, and where the order in which
   285         -** destructors are called is arbitrary.
   286         -**
   287         -** Applications should [sqlite3_finalize | finalize] all [prepared statements],
   288         -** [sqlite3_blob_close | close] all [BLOB handles], and 
   289         -** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
   290         -** with the [sqlite3] object prior to attempting to close the object.  ^If
   291         -** sqlite3_close() is called on a [database connection] that still has
   292         -** outstanding [prepared statements], [BLOB handles], and/or
   293         -** [sqlite3_backup] objects then it returns SQLITE_OK but the deallocation
   294         -** of resources is deferred until all [prepared statements], [BLOB handles],
   295         -** and [sqlite3_backup] objects are also destroyed.
   296         -**
   297         -** ^If an [sqlite3] object is destroyed while a transaction is open,
   298         -** the transaction is automatically rolled back.
   299         -**
   300         -** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
   301         -** must be either a NULL
   302         -** pointer or an [sqlite3] object pointer obtained
   303         -** from [sqlite3_open()], [sqlite3_open16()], or
   304         -** [sqlite3_open_v2()], and not previously closed.
   305         -** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
   306         -** argument is a harmless no-op.
   307         -*/
   308         -SQLITE_API int sqlite3_close(sqlite3*);
   309         -SQLITE_API int sqlite3_close_v2(sqlite3*);
   310         -
   311         -/*
   312         -** The type for a callback function.
   313         -** This is legacy and deprecated.  It is included for historical
   314         -** compatibility and is not documented.
   315         -*/
   316         -typedef int (*sqlite3_callback)(void*,int,char**, char**);
   317         -
   318         -/*
   319         -** CAPI3REF: One-Step Query Execution Interface
   320         -**
   321         -** The sqlite3_exec() interface is a convenience wrapper around
   322         -** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
   323         -** that allows an application to run multiple statements of SQL
   324         -** without having to use a lot of C code. 
   325         -**
   326         -** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
   327         -** semicolon-separate SQL statements passed into its 2nd argument,
   328         -** in the context of the [database connection] passed in as its 1st
   329         -** argument.  ^If the callback function of the 3rd argument to
   330         -** sqlite3_exec() is not NULL, then it is invoked for each result row
   331         -** coming out of the evaluated SQL statements.  ^The 4th argument to
   332         -** sqlite3_exec() is relayed through to the 1st argument of each
   333         -** callback invocation.  ^If the callback pointer to sqlite3_exec()
   334         -** is NULL, then no callback is ever invoked and result rows are
   335         -** ignored.
   336         -**
   337         -** ^If an error occurs while evaluating the SQL statements passed into
   338         -** sqlite3_exec(), then execution of the current statement stops and
   339         -** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
   340         -** is not NULL then any error message is written into memory obtained
   341         -** from [sqlite3_malloc()] and passed back through the 5th parameter.
   342         -** To avoid memory leaks, the application should invoke [sqlite3_free()]
   343         -** on error message strings returned through the 5th parameter of
   344         -** of sqlite3_exec() after the error message string is no longer needed.
   345         -** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
   346         -** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
   347         -** NULL before returning.
   348         -**
   349         -** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
   350         -** routine returns SQLITE_ABORT without invoking the callback again and
   351         -** without running any subsequent SQL statements.
   352         -**
   353         -** ^The 2nd argument to the sqlite3_exec() callback function is the
   354         -** number of columns in the result.  ^The 3rd argument to the sqlite3_exec()
   355         -** callback is an array of pointers to strings obtained as if from
   356         -** [sqlite3_column_text()], one for each column.  ^If an element of a
   357         -** result row is NULL then the corresponding string pointer for the
   358         -** sqlite3_exec() callback is a NULL pointer.  ^The 4th argument to the
   359         -** sqlite3_exec() callback is an array of pointers to strings where each
   360         -** entry represents the name of corresponding result column as obtained
   361         -** from [sqlite3_column_name()].
   362         -**
   363         -** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
   364         -** to an empty string, or a pointer that contains only whitespace and/or 
   365         -** SQL comments, then no SQL statements are evaluated and the database
   366         -** is not changed.
   367         -**
   368         -** Restrictions:
   369         -**
   370         -** <ul>
   371         -** <li> The application must insure that the 1st parameter to sqlite3_exec()
   372         -**      is a valid and open [database connection].
   373         -** <li> The application must not close [database connection] specified by
   374         -**      the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
   375         -** <li> The application must not modify the SQL statement text passed into
   376         -**      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
   377         -** </ul>
   378         -*/
   379         -SQLITE_API int sqlite3_exec(
   380         -  sqlite3*,                                  /* An open database */
   381         -  const char *sql,                           /* SQL to be evaluated */
   382         -  int (*callback)(void*,int,char**,char**),  /* Callback function */
   383         -  void *,                                    /* 1st argument to callback */
   384         -  char **errmsg                              /* Error msg written here */
   385         -);
   386         -
   387         -/*
   388         -** CAPI3REF: Result Codes
   389         -** KEYWORDS: SQLITE_OK {error code} {error codes}
   390         -** KEYWORDS: {result code} {result codes}
   391         -**
   392         -** Many SQLite functions return an integer result code from the set shown
   393         -** here in order to indicate success or failure.
   394         -**
   395         -** New error codes may be added in future versions of SQLite.
   396         -**
   397         -** See also: [SQLITE_IOERR_READ | extended result codes],
   398         -** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes].
   399         -*/
   400         -#define SQLITE_OK           0   /* Successful result */
   401         -/* beginning-of-error-codes */
   402         -#define SQLITE_ERROR        1   /* SQL error or missing database */
   403         -#define SQLITE_INTERNAL     2   /* Internal logic error in SQLite */
   404         -#define SQLITE_PERM         3   /* Access permission denied */
   405         -#define SQLITE_ABORT        4   /* Callback routine requested an abort */
   406         -#define SQLITE_BUSY         5   /* The database file is locked */
   407         -#define SQLITE_LOCKED       6   /* A table in the database is locked */
   408         -#define SQLITE_NOMEM        7   /* A malloc() failed */
   409         -#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
   410         -#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
   411         -#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
   412         -#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
   413         -#define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */
   414         -#define SQLITE_FULL        13   /* Insertion failed because database is full */
   415         -#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
   416         -#define SQLITE_PROTOCOL    15   /* Database lock protocol error */
   417         -#define SQLITE_EMPTY       16   /* Database is empty */
   418         -#define SQLITE_SCHEMA      17   /* The database schema changed */
   419         -#define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
   420         -#define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
   421         -#define SQLITE_MISMATCH    20   /* Data type mismatch */
   422         -#define SQLITE_MISUSE      21   /* Library used incorrectly */
   423         -#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
   424         -#define SQLITE_AUTH        23   /* Authorization denied */
   425         -#define SQLITE_FORMAT      24   /* Auxiliary database format error */
   426         -#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
   427         -#define SQLITE_NOTADB      26   /* File opened that is not a database file */
   428         -#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
   429         -#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
   430         -/* end-of-error-codes */
   431         -
   432         -/*
   433         -** CAPI3REF: Extended Result Codes
   434         -** KEYWORDS: {extended error code} {extended error codes}
   435         -** KEYWORDS: {extended result code} {extended result codes}
   436         -**
   437         -** In its default configuration, SQLite API routines return one of 26 integer
   438         -** [SQLITE_OK | result codes].  However, experience has shown that many of
   439         -** these result codes are too coarse-grained.  They do not provide as
   440         -** much information about problems as programmers might like.  In an effort to
   441         -** address this, newer versions of SQLite (version 3.3.8 and later) include
   442         -** support for additional result codes that provide more detailed information
   443         -** about errors. The extended result codes are enabled or disabled
   444         -** on a per database connection basis using the
   445         -** [sqlite3_extended_result_codes()] API.
   446         -**
   447         -** Some of the available extended result codes are listed here.
   448         -** One may expect the number of extended result codes will be expand
   449         -** over time.  Software that uses extended result codes should expect
   450         -** to see new result codes in future releases of SQLite.
   451         -**
   452         -** The SQLITE_OK result code will never be extended.  It will always
   453         -** be exactly zero.
   454         -*/
   455         -#define SQLITE_IOERR_READ              (SQLITE_IOERR | (1<<8))
   456         -#define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
   457         -#define SQLITE_IOERR_WRITE             (SQLITE_IOERR | (3<<8))
   458         -#define SQLITE_IOERR_FSYNC             (SQLITE_IOERR | (4<<8))
   459         -#define SQLITE_IOERR_DIR_FSYNC         (SQLITE_IOERR | (5<<8))
   460         -#define SQLITE_IOERR_TRUNCATE          (SQLITE_IOERR | (6<<8))
   461         -#define SQLITE_IOERR_FSTAT             (SQLITE_IOERR | (7<<8))
   462         -#define SQLITE_IOERR_UNLOCK            (SQLITE_IOERR | (8<<8))
   463         -#define SQLITE_IOERR_RDLOCK            (SQLITE_IOERR | (9<<8))
   464         -#define SQLITE_IOERR_DELETE            (SQLITE_IOERR | (10<<8))
   465         -#define SQLITE_IOERR_BLOCKED           (SQLITE_IOERR | (11<<8))
   466         -#define SQLITE_IOERR_NOMEM             (SQLITE_IOERR | (12<<8))
   467         -#define SQLITE_IOERR_ACCESS            (SQLITE_IOERR | (13<<8))
   468         -#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
   469         -#define SQLITE_IOERR_LOCK              (SQLITE_IOERR | (15<<8))
   470         -#define SQLITE_IOERR_CLOSE             (SQLITE_IOERR | (16<<8))
   471         -#define SQLITE_IOERR_DIR_CLOSE         (SQLITE_IOERR | (17<<8))
   472         -#define SQLITE_IOERR_SHMOPEN           (SQLITE_IOERR | (18<<8))
   473         -#define SQLITE_IOERR_SHMSIZE           (SQLITE_IOERR | (19<<8))
   474         -#define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
   475         -#define SQLITE_IOERR_SHMMAP            (SQLITE_IOERR | (21<<8))
   476         -#define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
   477         -#define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
   478         -#define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
   479         -#define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
   480         -#define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
   481         -#define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
   482         -#define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
   483         -#define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
   484         -#define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
   485         -
   486         -/*
   487         -** CAPI3REF: Flags For File Open Operations
   488         -**
   489         -** These bit values are intended for use in the
   490         -** 3rd parameter to the [sqlite3_open_v2()] interface and
   491         -** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
   492         -*/
   493         -#define SQLITE_OPEN_READONLY         0x00000001  /* Ok for sqlite3_open_v2() */
   494         -#define SQLITE_OPEN_READWRITE        0x00000002  /* Ok for sqlite3_open_v2() */
   495         -#define SQLITE_OPEN_CREATE           0x00000004  /* Ok for sqlite3_open_v2() */
   496         -#define SQLITE_OPEN_DELETEONCLOSE    0x00000008  /* VFS only */
   497         -#define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
   498         -#define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
   499         -#define SQLITE_OPEN_URI              0x00000040  /* Ok for sqlite3_open_v2() */
   500         -#define SQLITE_OPEN_MEMORY           0x00000080  /* Ok for sqlite3_open_v2() */
   501         -#define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
   502         -#define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
   503         -#define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
   504         -#define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  /* VFS only */
   505         -#define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  /* VFS only */
   506         -#define SQLITE_OPEN_SUBJOURNAL       0x00002000  /* VFS only */
   507         -#define SQLITE_OPEN_MASTER_JOURNAL   0x00004000  /* VFS only */
   508         -#define SQLITE_OPEN_NOMUTEX          0x00008000  /* Ok for sqlite3_open_v2() */
   509         -#define SQLITE_OPEN_FULLMUTEX        0x00010000  /* Ok for sqlite3_open_v2() */
   510         -#define SQLITE_OPEN_SHAREDCACHE      0x00020000  /* Ok for sqlite3_open_v2() */
   511         -#define SQLITE_OPEN_PRIVATECACHE     0x00040000  /* Ok for sqlite3_open_v2() */
   512         -#define SQLITE_OPEN_WAL              0x00080000  /* VFS only */
   513         -
   514         -/* Reserved:                         0x00F00000 */
   515         -
   516         -/*
   517         -** CAPI3REF: Device Characteristics
   518         -**
   519         -** The xDeviceCharacteristics method of the [sqlite3_io_methods]
   520         -** object returns an integer which is a vector of the these
   521         -** bit values expressing I/O characteristics of the mass storage
   522         -** device that holds the file that the [sqlite3_io_methods]
   523         -** refers to.
   524         -**
   525         -** The SQLITE_IOCAP_ATOMIC property means that all writes of
   526         -** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
   527         -** mean that writes of blocks that are nnn bytes in size and
   528         -** are aligned to an address which is an integer multiple of
   529         -** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
   530         -** that when data is appended to a file, the data is appended
   531         -** first then the size of the file is extended, never the other
   532         -** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
   533         -** information is written to disk in the same order as calls
   534         -** to xWrite().  The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
   535         -** after reboot following a crash or power loss, the only bytes in a
   536         -** file that were written at the application level might have changed
   537         -** and that adjacent bytes, even bytes within the same sector are
   538         -** guaranteed to be unchanged.
   539         -*/
   540         -#define SQLITE_IOCAP_ATOMIC                 0x00000001
   541         -#define SQLITE_IOCAP_ATOMIC512              0x00000002
   542         -#define SQLITE_IOCAP_ATOMIC1K               0x00000004
   543         -#define SQLITE_IOCAP_ATOMIC2K               0x00000008
   544         -#define SQLITE_IOCAP_ATOMIC4K               0x00000010
   545         -#define SQLITE_IOCAP_ATOMIC8K               0x00000020
   546         -#define SQLITE_IOCAP_ATOMIC16K              0x00000040
   547         -#define SQLITE_IOCAP_ATOMIC32K              0x00000080
   548         -#define SQLITE_IOCAP_ATOMIC64K              0x00000100
   549         -#define SQLITE_IOCAP_SAFE_APPEND            0x00000200
   550         -#define SQLITE_IOCAP_SEQUENTIAL             0x00000400
   551         -#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
   552         -#define SQLITE_IOCAP_POWERSAFE_OVERWRITE    0x00001000
   553         -
   554         -/*
   555         -** CAPI3REF: File Locking Levels
   556         -**
   557         -** SQLite uses one of these integer values as the second
   558         -** argument to calls it makes to the xLock() and xUnlock() methods
   559         -** of an [sqlite3_io_methods] object.
   560         -*/
   561         -#define SQLITE_LOCK_NONE          0
   562         -#define SQLITE_LOCK_SHARED        1
   563         -#define SQLITE_LOCK_RESERVED      2
   564         -#define SQLITE_LOCK_PENDING       3
   565         -#define SQLITE_LOCK_EXCLUSIVE     4
   566         -
   567         -/*
   568         -** CAPI3REF: Synchronization Type Flags
   569         -**
   570         -** When SQLite invokes the xSync() method of an
   571         -** [sqlite3_io_methods] object it uses a combination of
   572         -** these integer values as the second argument.
   573         -**
   574         -** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
   575         -** sync operation only needs to flush data to mass storage.  Inode
   576         -** information need not be flushed. If the lower four bits of the flag
   577         -** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
   578         -** If the lower four bits equal SQLITE_SYNC_FULL, that means
   579         -** to use Mac OS X style fullsync instead of fsync().
   580         -**
   581         -** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
   582         -** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
   583         -** settings.  The [synchronous pragma] determines when calls to the
   584         -** xSync VFS method occur and applies uniformly across all platforms.
   585         -** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
   586         -** energetic or rigorous or forceful the sync operations are and
   587         -** only make a difference on Mac OSX for the default SQLite code.
   588         -** (Third-party VFS implementations might also make the distinction
   589         -** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
   590         -** operating systems natively supported by SQLite, only Mac OSX
   591         -** cares about the difference.)
   592         -*/
   593         -#define SQLITE_SYNC_NORMAL        0x00002
   594         -#define SQLITE_SYNC_FULL          0x00003
   595         -#define SQLITE_SYNC_DATAONLY      0x00010
   596         -
   597         -/*
   598         -** CAPI3REF: OS Interface Open File Handle
   599         -**
   600         -** An [sqlite3_file] object represents an open file in the 
   601         -** [sqlite3_vfs | OS interface layer].  Individual OS interface
   602         -** implementations will
   603         -** want to subclass this object by appending additional fields
   604         -** for their own use.  The pMethods entry is a pointer to an
   605         -** [sqlite3_io_methods] object that defines methods for performing
   606         -** I/O operations on the open file.
   607         -*/
   608         -typedef struct sqlite3_file sqlite3_file;
   609         -struct sqlite3_file {
   610         -  const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
   611         -};
   612         -
   613         -/*
   614         -** CAPI3REF: OS Interface File Virtual Methods Object
   615         -**
   616         -** Every file opened by the [sqlite3_vfs.xOpen] method populates an
   617         -** [sqlite3_file] object (or, more commonly, a subclass of the
   618         -** [sqlite3_file] object) with a pointer to an instance of this object.
   619         -** This object defines the methods used to perform various operations
   620         -** against the open file represented by the [sqlite3_file] object.
   621         -**
   622         -** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element 
   623         -** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
   624         -** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed.  The
   625         -** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
   626         -** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
   627         -** to NULL.
   628         -**
   629         -** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
   630         -** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
   631         -** The second choice is a Mac OS X style fullsync.  The [SQLITE_SYNC_DATAONLY]
   632         -** flag may be ORed in to indicate that only the data of the file
   633         -** and not its inode needs to be synced.
   634         -**
   635         -** The integer values to xLock() and xUnlock() are one of
   636         -** <ul>
   637         -** <li> [SQLITE_LOCK_NONE],
   638         -** <li> [SQLITE_LOCK_SHARED],
   639         -** <li> [SQLITE_LOCK_RESERVED],
   640         -** <li> [SQLITE_LOCK_PENDING], or
   641         -** <li> [SQLITE_LOCK_EXCLUSIVE].
   642         -** </ul>
   643         -** xLock() increases the lock. xUnlock() decreases the lock.
   644         -** The xCheckReservedLock() method checks whether any database connection,
   645         -** either in this process or in some other process, is holding a RESERVED,
   646         -** PENDING, or EXCLUSIVE lock on the file.  It returns true
   647         -** if such a lock exists and false otherwise.
   648         -**
   649         -** The xFileControl() method is a generic interface that allows custom
   650         -** VFS implementations to directly control an open file using the
   651         -** [sqlite3_file_control()] interface.  The second "op" argument is an
   652         -** integer opcode.  The third argument is a generic pointer intended to
   653         -** point to a structure that may contain arguments or space in which to
   654         -** write return values.  Potential uses for xFileControl() might be
   655         -** functions to enable blocking locks with timeouts, to change the
   656         -** locking strategy (for example to use dot-file locks), to inquire
   657         -** about the status of a lock, or to break stale locks.  The SQLite
   658         -** core reserves all opcodes less than 100 for its own use.
   659         -** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
   660         -** Applications that define a custom xFileControl method should use opcodes
   661         -** greater than 100 to avoid conflicts.  VFS implementations should
   662         -** return [SQLITE_NOTFOUND] for file control opcodes that they do not
   663         -** recognize.
   664         -**
   665         -** The xSectorSize() method returns the sector size of the
   666         -** device that underlies the file.  The sector size is the
   667         -** minimum write that can be performed without disturbing
   668         -** other bytes in the file.  The xDeviceCharacteristics()
   669         -** method returns a bit vector describing behaviors of the
   670         -** underlying device:
   671         -**
   672         -** <ul>
   673         -** <li> [SQLITE_IOCAP_ATOMIC]
   674         -** <li> [SQLITE_IOCAP_ATOMIC512]
   675         -** <li> [SQLITE_IOCAP_ATOMIC1K]
   676         -** <li> [SQLITE_IOCAP_ATOMIC2K]
   677         -** <li> [SQLITE_IOCAP_ATOMIC4K]
   678         -** <li> [SQLITE_IOCAP_ATOMIC8K]
   679         -** <li> [SQLITE_IOCAP_ATOMIC16K]
   680         -** <li> [SQLITE_IOCAP_ATOMIC32K]
   681         -** <li> [SQLITE_IOCAP_ATOMIC64K]
   682         -** <li> [SQLITE_IOCAP_SAFE_APPEND]
   683         -** <li> [SQLITE_IOCAP_SEQUENTIAL]
   684         -** </ul>
   685         -**
   686         -** The SQLITE_IOCAP_ATOMIC property means that all writes of
   687         -** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
   688         -** mean that writes of blocks that are nnn bytes in size and
   689         -** are aligned to an address which is an integer multiple of
   690         -** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
   691         -** that when data is appended to a file, the data is appended
   692         -** first then the size of the file is extended, never the other
   693         -** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
   694         -** information is written to disk in the same order as calls
   695         -** to xWrite().
   696         -**
   697         -** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
   698         -** in the unread portions of the buffer with zeros.  A VFS that
   699         -** fails to zero-fill short reads might seem to work.  However,
   700         -** failure to zero-fill short reads will eventually lead to
   701         -** database corruption.
   702         -*/
   703         -typedef struct sqlite3_io_methods sqlite3_io_methods;
   704         -struct sqlite3_io_methods {
   705         -  int iVersion;
   706         -  int (*xClose)(sqlite3_file*);
   707         -  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
   708         -  int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
   709         -  int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
   710         -  int (*xSync)(sqlite3_file*, int flags);
   711         -  int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
   712         -  int (*xLock)(sqlite3_file*, int);
   713         -  int (*xUnlock)(sqlite3_file*, int);
   714         -  int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
   715         -  int (*xFileControl)(sqlite3_file*, int op, void *pArg);
   716         -  int (*xSectorSize)(sqlite3_file*);
   717         -  int (*xDeviceCharacteristics)(sqlite3_file*);
   718         -  /* Methods above are valid for version 1 */
   719         -  int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
   720         -  int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
   721         -  void (*xShmBarrier)(sqlite3_file*);
   722         -  int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
   723         -  /* Methods above are valid for version 2 */
   724         -  /* Additional methods may be added in future releases */
   725         -};
   726         -
   727         -/*
   728         -** CAPI3REF: Standard File Control Opcodes
   729         -**
   730         -** These integer constants are opcodes for the xFileControl method
   731         -** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
   732         -** interface.
   733         -**
   734         -** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
   735         -** opcode causes the xFileControl method to write the current state of
   736         -** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
   737         -** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
   738         -** into an integer that the pArg argument points to. This capability
   739         -** is used during testing and only needs to be supported when SQLITE_TEST
   740         -** is defined.
   741         -** <ul>
   742         -** <li>[[SQLITE_FCNTL_SIZE_HINT]]
   743         -** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
   744         -** layer a hint of how large the database file will grow to be during the
   745         -** current transaction.  This hint is not guaranteed to be accurate but it
   746         -** is often close.  The underlying VFS might choose to preallocate database
   747         -** file space based on this hint in order to help writes to the database
   748         -** file run faster.
   749         -**
   750         -** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
   751         -** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
   752         -** extends and truncates the database file in chunks of a size specified
   753         -** by the user. The fourth argument to [sqlite3_file_control()] should 
   754         -** point to an integer (type int) containing the new chunk-size to use
   755         -** for the nominated database. Allocating database file space in large
   756         -** chunks (say 1MB at a time), may reduce file-system fragmentation and
   757         -** improve performance on some systems.
   758         -**
   759         -** <li>[[SQLITE_FCNTL_FILE_POINTER]]
   760         -** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
   761         -** to the [sqlite3_file] object associated with a particular database
   762         -** connection.  See the [sqlite3_file_control()] documentation for
   763         -** additional information.
   764         -**
   765         -** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
   766         -** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
   767         -** SQLite and sent to all VFSes in place of a call to the xSync method
   768         -** when the database connection has [PRAGMA synchronous] set to OFF.)^
   769         -** Some specialized VFSes need this signal in order to operate correctly
   770         -** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most 
   771         -** VFSes do not need this signal and should silently ignore this opcode.
   772         -** Applications should not call [sqlite3_file_control()] with this
   773         -** opcode as doing so may disrupt the operation of the specialized VFSes
   774         -** that do require it.  
   775         -**
   776         -** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
   777         -** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
   778         -** retry counts and intervals for certain disk I/O operations for the
   779         -** windows [VFS] in order to provide robustness in the presence of
   780         -** anti-virus programs.  By default, the windows VFS will retry file read,
   781         -** file write, and file delete operations up to 10 times, with a delay
   782         -** of 25 milliseconds before the first retry and with the delay increasing
   783         -** by an additional 25 milliseconds with each subsequent retry.  This
   784         -** opcode allows these two values (10 retries and 25 milliseconds of delay)
   785         -** to be adjusted.  The values are changed for all database connections
   786         -** within the same process.  The argument is a pointer to an array of two
   787         -** integers where the first integer i the new retry count and the second
   788         -** integer is the delay.  If either integer is negative, then the setting
   789         -** is not changed but instead the prior value of that setting is written
   790         -** into the array entry, allowing the current retry settings to be
   791         -** interrogated.  The zDbName parameter is ignored.
   792         -**
   793         -** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
   794         -** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
   795         -** persistent [WAL | Write Ahead Log] setting.  By default, the auxiliary
   796         -** write ahead log and shared memory files used for transaction control
   797         -** are automatically deleted when the latest connection to the database
   798         -** closes.  Setting persistent WAL mode causes those files to persist after
   799         -** close.  Persisting the files is useful when other processes that do not
   800         -** have write permission on the directory containing the database file want
   801         -** to read the database file, as the WAL and shared memory files must exist
   802         -** in order for the database to be readable.  The fourth parameter to
   803         -** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
   804         -** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
   805         -** WAL mode.  If the integer is -1, then it is overwritten with the current
   806         -** WAL persistence setting.
   807         -**
   808         -** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
   809         -** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
   810         -** persistent "powersafe-overwrite" or "PSOW" setting.  The PSOW setting
   811         -** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
   812         -** xDeviceCharacteristics methods. The fourth parameter to
   813         -** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
   814         -** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
   815         -** mode.  If the integer is -1, then it is overwritten with the current
   816         -** zero-damage mode setting.
   817         -**
   818         -** <li>[[SQLITE_FCNTL_OVERWRITE]]
   819         -** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
   820         -** a write transaction to indicate that, unless it is rolled back for some
   821         -** reason, the entire database file will be overwritten by the current 
   822         -** transaction. This is used by VACUUM operations.
   823         -**
   824         -** <li>[[SQLITE_FCNTL_VFSNAME]]
   825         -** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
   826         -** all [VFSes] in the VFS stack.  The names are of all VFS shims and the
   827         -** final bottom-level VFS are written into memory obtained from 
   828         -** [sqlite3_malloc()] and the result is stored in the char* variable
   829         -** that the fourth parameter of [sqlite3_file_control()] points to.
   830         -** The caller is responsible for freeing the memory when done.  As with
   831         -** all file-control actions, there is no guarantee that this will actually
   832         -** do anything.  Callers should initialize the char* variable to a NULL
   833         -** pointer in case this file-control is not implemented.  This file-control
   834         -** is intended for diagnostic use only.
   835         -**
   836         -** <li>[[SQLITE_FCNTL_PRAGMA]]
   837         -** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] 
   838         -** file control is sent to the open [sqlite3_file] object corresponding
   839         -** to the database file to which the pragma statement refers. ^The argument
   840         -** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
   841         -** pointers to strings (char**) in which the second element of the array
   842         -** is the name of the pragma and the third element is the argument to the
   843         -** pragma or NULL if the pragma has no argument.  ^The handler for an
   844         -** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
   845         -** of the char** argument point to a string obtained from [sqlite3_mprintf()]
   846         -** or the equivalent and that string will become the result of the pragma or
   847         -** the error message if the pragma fails. ^If the
   848         -** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal 
   849         -** [PRAGMA] processing continues.  ^If the [SQLITE_FCNTL_PRAGMA]
   850         -** file control returns [SQLITE_OK], then the parser assumes that the
   851         -** VFS has handled the PRAGMA itself and the parser generates a no-op
   852         -** prepared statement.  ^If the [SQLITE_FCNTL_PRAGMA] file control returns
   853         -** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
   854         -** that the VFS encountered an error while handling the [PRAGMA] and the
   855         -** compilation of the PRAGMA fails with an error.  ^The [SQLITE_FCNTL_PRAGMA]
   856         -** file control occurs at the beginning of pragma statement analysis and so
   857         -** it is able to override built-in [PRAGMA] statements.
   858         -** </ul>
   859         -*/
   860         -#define SQLITE_FCNTL_LOCKSTATE               1
   861         -#define SQLITE_GET_LOCKPROXYFILE             2
   862         -#define SQLITE_SET_LOCKPROXYFILE             3
   863         -#define SQLITE_LAST_ERRNO                    4
   864         -#define SQLITE_FCNTL_SIZE_HINT               5
   865         -#define SQLITE_FCNTL_CHUNK_SIZE              6
   866         -#define SQLITE_FCNTL_FILE_POINTER            7
   867         -#define SQLITE_FCNTL_SYNC_OMITTED            8
   868         -#define SQLITE_FCNTL_WIN32_AV_RETRY          9
   869         -#define SQLITE_FCNTL_PERSIST_WAL            10
   870         -#define SQLITE_FCNTL_OVERWRITE              11
   871         -#define SQLITE_FCNTL_VFSNAME                12
   872         -#define SQLITE_FCNTL_POWERSAFE_OVERWRITE    13
   873         -#define SQLITE_FCNTL_PRAGMA                 14
   874         -
   875         -/*
   876         -** CAPI3REF: Mutex Handle
   877         -**
   878         -** The mutex module within SQLite defines [sqlite3_mutex] to be an
   879         -** abstract type for a mutex object.  The SQLite core never looks
   880         -** at the internal representation of an [sqlite3_mutex].  It only
   881         -** deals with pointers to the [sqlite3_mutex] object.
   882         -**
   883         -** Mutexes are created using [sqlite3_mutex_alloc()].
   884         -*/
   885         -typedef struct sqlite3_mutex sqlite3_mutex;
   886         -
   887         -/*
   888         -** CAPI3REF: OS Interface Object
   889         -**
   890         -** An instance of the sqlite3_vfs object defines the interface between
   891         -** the SQLite core and the underlying operating system.  The "vfs"
   892         -** in the name of the object stands for "virtual file system".  See
   893         -** the [VFS | VFS documentation] for further information.
   894         -**
   895         -** The value of the iVersion field is initially 1 but may be larger in
   896         -** future versions of SQLite.  Additional fields may be appended to this
   897         -** object when the iVersion value is increased.  Note that the structure
   898         -** of the sqlite3_vfs object changes in the transaction between
   899         -** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
   900         -** modified.
   901         -**
   902         -** The szOsFile field is the size of the subclassed [sqlite3_file]
   903         -** structure used by this VFS.  mxPathname is the maximum length of
   904         -** a pathname in this VFS.
   905         -**
   906         -** Registered sqlite3_vfs objects are kept on a linked list formed by
   907         -** the pNext pointer.  The [sqlite3_vfs_register()]
   908         -** and [sqlite3_vfs_unregister()] interfaces manage this list
   909         -** in a thread-safe way.  The [sqlite3_vfs_find()] interface
   910         -** searches the list.  Neither the application code nor the VFS
   911         -** implementation should use the pNext pointer.
   912         -**
   913         -** The pNext field is the only field in the sqlite3_vfs
   914         -** structure that SQLite will ever modify.  SQLite will only access
   915         -** or modify this field while holding a particular static mutex.
   916         -** The application should never modify anything within the sqlite3_vfs
   917         -** object once the object has been registered.
   918         -**
   919         -** The zName field holds the name of the VFS module.  The name must
   920         -** be unique across all VFS modules.
   921         -**
   922         -** [[sqlite3_vfs.xOpen]]
   923         -** ^SQLite guarantees that the zFilename parameter to xOpen
   924         -** is either a NULL pointer or string obtained
   925         -** from xFullPathname() with an optional suffix added.
   926         -** ^If a suffix is added to the zFilename parameter, it will
   927         -** consist of a single "-" character followed by no more than
   928         -** 11 alphanumeric and/or "-" characters.
   929         -** ^SQLite further guarantees that
   930         -** the string will be valid and unchanged until xClose() is
   931         -** called. Because of the previous sentence,
   932         -** the [sqlite3_file] can safely store a pointer to the
   933         -** filename if it needs to remember the filename for some reason.
   934         -** If the zFilename parameter to xOpen is a NULL pointer then xOpen
   935         -** must invent its own temporary name for the file.  ^Whenever the 
   936         -** xFilename parameter is NULL it will also be the case that the
   937         -** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
   938         -**
   939         -** The flags argument to xOpen() includes all bits set in
   940         -** the flags argument to [sqlite3_open_v2()].  Or if [sqlite3_open()]
   941         -** or [sqlite3_open16()] is used, then flags includes at least
   942         -** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 
   943         -** If xOpen() opens a file read-only then it sets *pOutFlags to
   944         -** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be set.
   945         -**
   946         -** ^(SQLite will also add one of the following flags to the xOpen()
   947         -** call, depending on the object being opened:
   948         -**
   949         -** <ul>
   950         -** <li>  [SQLITE_OPEN_MAIN_DB]
   951         -** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
   952         -** <li>  [SQLITE_OPEN_TEMP_DB]
   953         -** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
   954         -** <li>  [SQLITE_OPEN_TRANSIENT_DB]
   955         -** <li>  [SQLITE_OPEN_SUBJOURNAL]
   956         -** <li>  [SQLITE_OPEN_MASTER_JOURNAL]
   957         -** <li>  [SQLITE_OPEN_WAL]
   958         -** </ul>)^
   959         -**
   960         -** The file I/O implementation can use the object type flags to
   961         -** change the way it deals with files.  For example, an application
   962         -** that does not care about crash recovery or rollback might make
   963         -** the open of a journal file a no-op.  Writes to this journal would
   964         -** also be no-ops, and any attempt to read the journal would return
   965         -** SQLITE_IOERR.  Or the implementation might recognize that a database
   966         -** file will be doing page-aligned sector reads and writes in a random
   967         -** order and set up its I/O subsystem accordingly.
   968         -**
   969         -** SQLite might also add one of the following flags to the xOpen method:
   970         -**
   971         -** <ul>
   972         -** <li> [SQLITE_OPEN_DELETEONCLOSE]
   973         -** <li> [SQLITE_OPEN_EXCLUSIVE]
   974         -** </ul>
   975         -**
   976         -** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
   977         -** deleted when it is closed.  ^The [SQLITE_OPEN_DELETEONCLOSE]
   978         -** will be set for TEMP databases and their journals, transient
   979         -** databases, and subjournals.
   980         -**
   981         -** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
   982         -** with the [SQLITE_OPEN_CREATE] flag, which are both directly
   983         -** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
   984         -** API.  The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 
   985         -** SQLITE_OPEN_CREATE, is used to indicate that file should always
   986         -** be created, and that it is an error if it already exists.
   987         -** It is <i>not</i> used to indicate the file should be opened 
   988         -** for exclusive access.
   989         -**
   990         -** ^At least szOsFile bytes of memory are allocated by SQLite
   991         -** to hold the  [sqlite3_file] structure passed as the third
   992         -** argument to xOpen.  The xOpen method does not have to
   993         -** allocate the structure; it should just fill it in.  Note that
   994         -** the xOpen method must set the sqlite3_file.pMethods to either
   995         -** a valid [sqlite3_io_methods] object or to NULL.  xOpen must do
   996         -** this even if the open fails.  SQLite expects that the sqlite3_file.pMethods
   997         -** element will be valid after xOpen returns regardless of the success
   998         -** or failure of the xOpen call.
   999         -**
  1000         -** [[sqlite3_vfs.xAccess]]
  1001         -** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
  1002         -** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
  1003         -** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
  1004         -** to test whether a file is at least readable.   The file can be a
  1005         -** directory.
  1006         -**
  1007         -** ^SQLite will always allocate at least mxPathname+1 bytes for the
  1008         -** output buffer xFullPathname.  The exact size of the output buffer
  1009         -** is also passed as a parameter to both  methods. If the output buffer
  1010         -** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
  1011         -** handled as a fatal error by SQLite, vfs implementations should endeavor
  1012         -** to prevent this by setting mxPathname to a sufficiently large value.
  1013         -**
  1014         -** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
  1015         -** interfaces are not strictly a part of the filesystem, but they are
  1016         -** included in the VFS structure for completeness.
  1017         -** The xRandomness() function attempts to return nBytes bytes
  1018         -** of good-quality randomness into zOut.  The return value is
  1019         -** the actual number of bytes of randomness obtained.
  1020         -** The xSleep() method causes the calling thread to sleep for at
  1021         -** least the number of microseconds given.  ^The xCurrentTime()
  1022         -** method returns a Julian Day Number for the current date and time as
  1023         -** a floating point value.
  1024         -** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
  1025         -** Day Number multiplied by 86400000 (the number of milliseconds in 
  1026         -** a 24-hour day).  
  1027         -** ^SQLite will use the xCurrentTimeInt64() method to get the current
  1028         -** date and time if that method is available (if iVersion is 2 or 
  1029         -** greater and the function pointer is not NULL) and will fall back
  1030         -** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
  1031         -**
  1032         -** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
  1033         -** are not used by the SQLite core.  These optional interfaces are provided
  1034         -** by some VFSes to facilitate testing of the VFS code. By overriding 
  1035         -** system calls with functions under its control, a test program can
  1036         -** simulate faults and error conditions that would otherwise be difficult
  1037         -** or impossible to induce.  The set of system calls that can be overridden
  1038         -** varies from one VFS to another, and from one version of the same VFS to the
  1039         -** next.  Applications that use these interfaces must be prepared for any
  1040         -** or all of these interfaces to be NULL or for their behavior to change
  1041         -** from one release to the next.  Applications must not attempt to access
  1042         -** any of these methods if the iVersion of the VFS is less than 3.
  1043         -*/
  1044         -typedef struct sqlite3_vfs sqlite3_vfs;
  1045         -typedef void (*sqlite3_syscall_ptr)(void);
  1046         -struct sqlite3_vfs {
  1047         -  int iVersion;            /* Structure version number (currently 3) */
  1048         -  int szOsFile;            /* Size of subclassed sqlite3_file */
  1049         -  int mxPathname;          /* Maximum file pathname length */
  1050         -  sqlite3_vfs *pNext;      /* Next registered VFS */
  1051         -  const char *zName;       /* Name of this virtual file system */
  1052         -  void *pAppData;          /* Pointer to application-specific data */
  1053         -  int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
  1054         -               int flags, int *pOutFlags);
  1055         -  int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
  1056         -  int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
  1057         -  int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
  1058         -  void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
  1059         -  void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
  1060         -  void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
  1061         -  void (*xDlClose)(sqlite3_vfs*, void*);
  1062         -  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
  1063         -  int (*xSleep)(sqlite3_vfs*, int microseconds);
  1064         -  int (*xCurrentTime)(sqlite3_vfs*, double*);
  1065         -  int (*xGetLastError)(sqlite3_vfs*, int, char *);
  1066         -  /*
  1067         -  ** The methods above are in version 1 of the sqlite_vfs object
  1068         -  ** definition.  Those that follow are added in version 2 or later
  1069         -  */
  1070         -  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
  1071         -  /*
  1072         -  ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
  1073         -  ** Those below are for version 3 and greater.
  1074         -  */
  1075         -  int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
  1076         -  sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
  1077         -  const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
  1078         -  /*
  1079         -  ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
  1080         -  ** New fields may be appended in figure versions.  The iVersion
  1081         -  ** value will increment whenever this happens. 
  1082         -  */
  1083         -};
  1084         -
  1085         -/*
  1086         -** CAPI3REF: Flags for the xAccess VFS method
  1087         -**
  1088         -** These integer constants can be used as the third parameter to
  1089         -** the xAccess method of an [sqlite3_vfs] object.  They determine
  1090         -** what kind of permissions the xAccess method is looking for.
  1091         -** With SQLITE_ACCESS_EXISTS, the xAccess method
  1092         -** simply checks whether the file exists.
  1093         -** With SQLITE_ACCESS_READWRITE, the xAccess method
  1094         -** checks whether the named directory is both readable and writable
  1095         -** (in other words, if files can be added, removed, and renamed within
  1096         -** the directory).
  1097         -** The SQLITE_ACCESS_READWRITE constant is currently used only by the
  1098         -** [temp_store_directory pragma], though this could change in a future
  1099         -** release of SQLite.
  1100         -** With SQLITE_ACCESS_READ, the xAccess method
  1101         -** checks whether the file is readable.  The SQLITE_ACCESS_READ constant is
  1102         -** currently unused, though it might be used in a future release of
  1103         -** SQLite.
  1104         -*/
  1105         -#define SQLITE_ACCESS_EXISTS    0
  1106         -#define SQLITE_ACCESS_READWRITE 1   /* Used by PRAGMA temp_store_directory */
  1107         -#define SQLITE_ACCESS_READ      2   /* Unused */
  1108         -
  1109         -/*
  1110         -** CAPI3REF: Flags for the xShmLock VFS method
  1111         -**
  1112         -** These integer constants define the various locking operations
  1113         -** allowed by the xShmLock method of [sqlite3_io_methods].  The
  1114         -** following are the only legal combinations of flags to the
  1115         -** xShmLock method:
  1116         -**
  1117         -** <ul>
  1118         -** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
  1119         -** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
  1120         -** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
  1121         -** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
  1122         -** </ul>
  1123         -**
  1124         -** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
  1125         -** was given no the corresponding lock.  
  1126         -**
  1127         -** The xShmLock method can transition between unlocked and SHARED or
  1128         -** between unlocked and EXCLUSIVE.  It cannot transition between SHARED
  1129         -** and EXCLUSIVE.
  1130         -*/
  1131         -#define SQLITE_SHM_UNLOCK       1
  1132         -#define SQLITE_SHM_LOCK         2
  1133         -#define SQLITE_SHM_SHARED       4
  1134         -#define SQLITE_SHM_EXCLUSIVE    8
  1135         -
  1136         -/*
  1137         -** CAPI3REF: Maximum xShmLock index
  1138         -**
  1139         -** The xShmLock method on [sqlite3_io_methods] may use values
  1140         -** between 0 and this upper bound as its "offset" argument.
  1141         -** The SQLite core will never attempt to acquire or release a
  1142         -** lock outside of this range
  1143         -*/
  1144         -#define SQLITE_SHM_NLOCK        8
  1145         -
  1146         -
  1147         -/*
  1148         -** CAPI3REF: Initialize The SQLite Library
  1149         -**
  1150         -** ^The sqlite3_initialize() routine initializes the
  1151         -** SQLite library.  ^The sqlite3_shutdown() routine
  1152         -** deallocates any resources that were allocated by sqlite3_initialize().
  1153         -** These routines are designed to aid in process initialization and
  1154         -** shutdown on embedded systems.  Workstation applications using
  1155         -** SQLite normally do not need to invoke either of these routines.
  1156         -**
  1157         -** A call to sqlite3_initialize() is an "effective" call if it is
  1158         -** the first time sqlite3_initialize() is invoked during the lifetime of
  1159         -** the process, or if it is the first time sqlite3_initialize() is invoked
  1160         -** following a call to sqlite3_shutdown().  ^(Only an effective call
  1161         -** of sqlite3_initialize() does any initialization.  All other calls
  1162         -** are harmless no-ops.)^
  1163         -**
  1164         -** A call to sqlite3_shutdown() is an "effective" call if it is the first
  1165         -** call to sqlite3_shutdown() since the last sqlite3_initialize().  ^(Only
  1166         -** an effective call to sqlite3_shutdown() does any deinitialization.
  1167         -** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
  1168         -**
  1169         -** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
  1170         -** is not.  The sqlite3_shutdown() interface must only be called from a
  1171         -** single thread.  All open [database connections] must be closed and all
  1172         -** other SQLite resources must be deallocated prior to invoking
  1173         -** sqlite3_shutdown().
  1174         -**
  1175         -** Among other things, ^sqlite3_initialize() will invoke
  1176         -** sqlite3_os_init().  Similarly, ^sqlite3_shutdown()
  1177         -** will invoke sqlite3_os_end().
  1178         -**
  1179         -** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
  1180         -** ^If for some reason, sqlite3_initialize() is unable to initialize
  1181         -** the library (perhaps it is unable to allocate a needed resource such
  1182         -** as a mutex) it returns an [error code] other than [SQLITE_OK].
  1183         -**
  1184         -** ^The sqlite3_initialize() routine is called internally by many other
  1185         -** SQLite interfaces so that an application usually does not need to
  1186         -** invoke sqlite3_initialize() directly.  For example, [sqlite3_open()]
  1187         -** calls sqlite3_initialize() so the SQLite library will be automatically
  1188         -** initialized when [sqlite3_open()] is called if it has not be initialized
  1189         -** already.  ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
  1190         -** compile-time option, then the automatic calls to sqlite3_initialize()
  1191         -** are omitted and the application must call sqlite3_initialize() directly
  1192         -** prior to using any other SQLite interface.  For maximum portability,
  1193         -** it is recommended that applications always invoke sqlite3_initialize()
  1194         -** directly prior to using any other SQLite interface.  Future releases
  1195         -** of SQLite may require this.  In other words, the behavior exhibited
  1196         -** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
  1197         -** default behavior in some future release of SQLite.
  1198         -**
  1199         -** The sqlite3_os_init() routine does operating-system specific
  1200         -** initialization of the SQLite library.  The sqlite3_os_end()
  1201         -** routine undoes the effect of sqlite3_os_init().  Typical tasks
  1202         -** performed by these routines include allocation or deallocation
  1203         -** of static resources, initialization of global variables,
  1204         -** setting up a default [sqlite3_vfs] module, or setting up
  1205         -** a default configuration using [sqlite3_config()].
  1206         -**
  1207         -** The application should never invoke either sqlite3_os_init()
  1208         -** or sqlite3_os_end() directly.  The application should only invoke
  1209         -** sqlite3_initialize() and sqlite3_shutdown().  The sqlite3_os_init()
  1210         -** interface is called automatically by sqlite3_initialize() and
  1211         -** sqlite3_os_end() is called by sqlite3_shutdown().  Appropriate
  1212         -** implementations for sqlite3_os_init() and sqlite3_os_end()
  1213         -** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
  1214         -** When [custom builds | built for other platforms]
  1215         -** (using the [SQLITE_OS_OTHER=1] compile-time
  1216         -** option) the application must supply a suitable implementation for
  1217         -** sqlite3_os_init() and sqlite3_os_end().  An application-supplied
  1218         -** implementation of sqlite3_os_init() or sqlite3_os_end()
  1219         -** must return [SQLITE_OK] on success and some other [error code] upon
  1220         -** failure.
  1221         -*/
  1222         -SQLITE_API int sqlite3_initialize(void);
  1223         -SQLITE_API int sqlite3_shutdown(void);
  1224         -SQLITE_API int sqlite3_os_init(void);
  1225         -SQLITE_API int sqlite3_os_end(void);
  1226         -
  1227         -/*
  1228         -** CAPI3REF: Configuring The SQLite Library
  1229         -**
  1230         -** The sqlite3_config() interface is used to make global configuration
  1231         -** changes to SQLite in order to tune SQLite to the specific needs of
  1232         -** the application.  The default configuration is recommended for most
  1233         -** applications and so this routine is usually not necessary.  It is
  1234         -** provided to support rare applications with unusual needs.
  1235         -**
  1236         -** The sqlite3_config() interface is not threadsafe.  The application
  1237         -** must insure that no other SQLite interfaces are invoked by other
  1238         -** threads while sqlite3_config() is running.  Furthermore, sqlite3_config()
  1239         -** may only be invoked prior to library initialization using
  1240         -** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
  1241         -** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
  1242         -** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
  1243         -** Note, however, that ^sqlite3_config() can be called as part of the
  1244         -** implementation of an application-defined [sqlite3_os_init()].
  1245         -**
  1246         -** The first argument to sqlite3_config() is an integer
  1247         -** [configuration option] that determines
  1248         -** what property of SQLite is to be configured.  Subsequent arguments
  1249         -** vary depending on the [configuration option]
  1250         -** in the first argument.
  1251         -**
  1252         -** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
  1253         -** ^If the option is unknown or SQLite is unable to set the option
  1254         -** then this routine returns a non-zero [error code].
  1255         -*/
  1256         -SQLITE_API int sqlite3_config(int, ...);
  1257         -
  1258         -/*
  1259         -** CAPI3REF: Configure database connections
  1260         -**
  1261         -** The sqlite3_db_config() interface is used to make configuration
  1262         -** changes to a [database connection].  The interface is similar to
  1263         -** [sqlite3_config()] except that the changes apply to a single
  1264         -** [database connection] (specified in the first argument).
  1265         -**
  1266         -** The second argument to sqlite3_db_config(D,V,...)  is the
  1267         -** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code 
  1268         -** that indicates what aspect of the [database connection] is being configured.
  1269         -** Subsequent arguments vary depending on the configuration verb.
  1270         -**
  1271         -** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
  1272         -** the call is considered successful.
  1273         -*/
  1274         -SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
  1275         -
  1276         -/*
  1277         -** CAPI3REF: Memory Allocation Routines
  1278         -**
  1279         -** An instance of this object defines the interface between SQLite
  1280         -** and low-level memory allocation routines.
  1281         -**
  1282         -** This object is used in only one place in the SQLite interface.
  1283         -** A pointer to an instance of this object is the argument to
  1284         -** [sqlite3_config()] when the configuration option is
  1285         -** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].  
  1286         -** By creating an instance of this object
  1287         -** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
  1288         -** during configuration, an application can specify an alternative
  1289         -** memory allocation subsystem for SQLite to use for all of its
  1290         -** dynamic memory needs.
  1291         -**
  1292         -** Note that SQLite comes with several [built-in memory allocators]
  1293         -** that are perfectly adequate for the overwhelming majority of applications
  1294         -** and that this object is only useful to a tiny minority of applications
  1295         -** with specialized memory allocation requirements.  This object is
  1296         -** also used during testing of SQLite in order to specify an alternative
  1297         -** memory allocator that simulates memory out-of-memory conditions in
  1298         -** order to verify that SQLite recovers gracefully from such
  1299         -** conditions.
  1300         -**
  1301         -** The xMalloc, xRealloc, and xFree methods must work like the
  1302         -** malloc(), realloc() and free() functions from the standard C library.
  1303         -** ^SQLite guarantees that the second argument to
  1304         -** xRealloc is always a value returned by a prior call to xRoundup.
  1305         -**
  1306         -** xSize should return the allocated size of a memory allocation
  1307         -** previously obtained from xMalloc or xRealloc.  The allocated size
  1308         -** is always at least as big as the requested size but may be larger.
  1309         -**
  1310         -** The xRoundup method returns what would be the allocated size of
  1311         -** a memory allocation given a particular requested size.  Most memory
  1312         -** allocators round up memory allocations at least to the next multiple
  1313         -** of 8.  Some allocators round up to a larger multiple or to a power of 2.
  1314         -** Every memory allocation request coming in through [sqlite3_malloc()]
  1315         -** or [sqlite3_realloc()] first calls xRoundup.  If xRoundup returns 0, 
  1316         -** that causes the corresponding memory allocation to fail.
  1317         -**
  1318         -** The xInit method initializes the memory allocator.  (For example,
  1319         -** it might allocate any require mutexes or initialize internal data
  1320         -** structures.  The xShutdown method is invoked (indirectly) by
  1321         -** [sqlite3_shutdown()] and should deallocate any resources acquired
  1322         -** by xInit.  The pAppData pointer is used as the only parameter to
  1323         -** xInit and xShutdown.
  1324         -**
  1325         -** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
  1326         -** the xInit method, so the xInit method need not be threadsafe.  The
  1327         -** xShutdown method is only called from [sqlite3_shutdown()] so it does
  1328         -** not need to be threadsafe either.  For all other methods, SQLite
  1329         -** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
  1330         -** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
  1331         -** it is by default) and so the methods are automatically serialized.
  1332         -** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
  1333         -** methods must be threadsafe or else make their own arrangements for
  1334         -** serialization.
  1335         -**
  1336         -** SQLite will never invoke xInit() more than once without an intervening
  1337         -** call to xShutdown().
  1338         -*/
  1339         -typedef struct sqlite3_mem_methods sqlite3_mem_methods;
  1340         -struct sqlite3_mem_methods {
  1341         -  void *(*xMalloc)(int);         /* Memory allocation function */
  1342         -  void (*xFree)(void*);          /* Free a prior allocation */
  1343         -  void *(*xRealloc)(void*,int);  /* Resize an allocation */
  1344         -  int (*xSize)(void*);           /* Return the size of an allocation */
  1345         -  int (*xRoundup)(int);          /* Round up request size to allocation size */
  1346         -  int (*xInit)(void*);           /* Initialize the memory allocator */
  1347         -  void (*xShutdown)(void*);      /* Deinitialize the memory allocator */
  1348         -  void *pAppData;                /* Argument to xInit() and xShutdown() */
  1349         -};
  1350         -
  1351         -/*
  1352         -** CAPI3REF: Configuration Options
  1353         -** KEYWORDS: {configuration option}
  1354         -**
  1355         -** These constants are the available integer configuration options that
  1356         -** can be passed as the first argument to the [sqlite3_config()] interface.
  1357         -**
  1358         -** New configuration options may be added in future releases of SQLite.
  1359         -** Existing configuration options might be discontinued.  Applications
  1360         -** should check the return code from [sqlite3_config()] to make sure that
  1361         -** the call worked.  The [sqlite3_config()] interface will return a
  1362         -** non-zero [error code] if a discontinued or unsupported configuration option
  1363         -** is invoked.
  1364         -**
  1365         -** <dl>
  1366         -** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
  1367         -** <dd>There are no arguments to this option.  ^This option sets the
  1368         -** [threading mode] to Single-thread.  In other words, it disables
  1369         -** all mutexing and puts SQLite into a mode where it can only be used
  1370         -** by a single thread.   ^If SQLite is compiled with
  1371         -** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1372         -** it is not possible to change the [threading mode] from its default
  1373         -** value of Single-thread and so [sqlite3_config()] will return 
  1374         -** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
  1375         -** configuration option.</dd>
  1376         -**
  1377         -** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
  1378         -** <dd>There are no arguments to this option.  ^This option sets the
  1379         -** [threading mode] to Multi-thread.  In other words, it disables
  1380         -** mutexing on [database connection] and [prepared statement] objects.
  1381         -** The application is responsible for serializing access to
  1382         -** [database connections] and [prepared statements].  But other mutexes
  1383         -** are enabled so that SQLite will be safe to use in a multi-threaded
  1384         -** environment as long as no two threads attempt to use the same
  1385         -** [database connection] at the same time.  ^If SQLite is compiled with
  1386         -** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1387         -** it is not possible to set the Multi-thread [threading mode] and
  1388         -** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1389         -** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
  1390         -**
  1391         -** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
  1392         -** <dd>There are no arguments to this option.  ^This option sets the
  1393         -** [threading mode] to Serialized. In other words, this option enables
  1394         -** all mutexes including the recursive
  1395         -** mutexes on [database connection] and [prepared statement] objects.
  1396         -** In this mode (which is the default when SQLite is compiled with
  1397         -** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
  1398         -** to [database connections] and [prepared statements] so that the
  1399         -** application is free to use the same [database connection] or the
  1400         -** same [prepared statement] in different threads at the same time.
  1401         -** ^If SQLite is compiled with
  1402         -** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1403         -** it is not possible to set the Serialized [threading mode] and
  1404         -** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
  1405         -** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
  1406         -**
  1407         -** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
  1408         -** <dd> ^(This option takes a single argument which is a pointer to an
  1409         -** instance of the [sqlite3_mem_methods] structure.  The argument specifies
  1410         -** alternative low-level memory allocation routines to be used in place of
  1411         -** the memory allocation routines built into SQLite.)^ ^SQLite makes
  1412         -** its own private copy of the content of the [sqlite3_mem_methods] structure
  1413         -** before the [sqlite3_config()] call returns.</dd>
  1414         -**
  1415         -** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
  1416         -** <dd> ^(This option takes a single argument which is a pointer to an
  1417         -** instance of the [sqlite3_mem_methods] structure.  The [sqlite3_mem_methods]
  1418         -** structure is filled with the currently defined memory allocation routines.)^
  1419         -** This option can be used to overload the default memory allocation
  1420         -** routines with a wrapper that simulations memory allocation failure or
  1421         -** tracks memory usage, for example. </dd>
  1422         -**
  1423         -** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  1424         -** <dd> ^This option takes single argument of type int, interpreted as a 
  1425         -** boolean, which enables or disables the collection of memory allocation 
  1426         -** statistics. ^(When memory allocation statistics are disabled, the 
  1427         -** following SQLite interfaces become non-operational:
  1428         -**   <ul>
  1429         -**   <li> [sqlite3_memory_used()]
  1430         -**   <li> [sqlite3_memory_highwater()]
  1431         -**   <li> [sqlite3_soft_heap_limit64()]
  1432         -**   <li> [sqlite3_status()]
  1433         -**   </ul>)^
  1434         -** ^Memory allocation statistics are enabled by default unless SQLite is
  1435         -** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
  1436         -** allocation statistics are disabled by default.
  1437         -** </dd>
  1438         -**
  1439         -** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
  1440         -** <dd> ^This option specifies a static memory buffer that SQLite can use for
  1441         -** scratch memory.  There are three arguments:  A pointer an 8-byte
  1442         -** aligned memory buffer from which the scratch allocations will be
  1443         -** drawn, the size of each scratch allocation (sz),
  1444         -** and the maximum number of scratch allocations (N).  The sz
  1445         -** argument must be a multiple of 16.
  1446         -** The first argument must be a pointer to an 8-byte aligned buffer
  1447         -** of at least sz*N bytes of memory.
  1448         -** ^SQLite will use no more than two scratch buffers per thread.  So
  1449         -** N should be set to twice the expected maximum number of threads.
  1450         -** ^SQLite will never require a scratch buffer that is more than 6
  1451         -** times the database page size. ^If SQLite needs needs additional
  1452         -** scratch memory beyond what is provided by this configuration option, then 
  1453         -** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
  1454         -**
  1455         -** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1456         -** <dd> ^This option specifies a static memory buffer that SQLite can use for
  1457         -** the database page cache with the default page cache implementation.  
  1458         -** This configuration should not be used if an application-define page
  1459         -** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
  1460         -** There are three arguments to this option: A pointer to 8-byte aligned
  1461         -** memory, the size of each page buffer (sz), and the number of pages (N).
  1462         -** The sz argument should be the size of the largest database page
  1463         -** (a power of two between 512 and 32768) plus a little extra for each
  1464         -** page header.  ^The page header size is 20 to 40 bytes depending on
  1465         -** the host architecture.  ^It is harmless, apart from the wasted memory,
  1466         -** to make sz a little too large.  The first
  1467         -** argument should point to an allocation of at least sz*N bytes of memory.
  1468         -** ^SQLite will use the memory provided by the first argument to satisfy its
  1469         -** memory needs for the first N pages that it adds to cache.  ^If additional
  1470         -** page cache memory is needed beyond what is provided by this option, then
  1471         -** SQLite goes to [sqlite3_malloc()] for the additional storage space.
  1472         -** The pointer in the first argument must
  1473         -** be aligned to an 8-byte boundary or subsequent behavior of SQLite
  1474         -** will be undefined.</dd>
  1475         -**
  1476         -** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
  1477         -** <dd> ^This option specifies a static memory buffer that SQLite will use
  1478         -** for all of its dynamic memory allocation needs beyond those provided
  1479         -** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
  1480         -** There are three arguments: An 8-byte aligned pointer to the memory,
  1481         -** the number of bytes in the memory buffer, and the minimum allocation size.
  1482         -** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
  1483         -** to using its default memory allocator (the system malloc() implementation),
  1484         -** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  ^If the
  1485         -** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
  1486         -** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
  1487         -** allocator is engaged to handle all of SQLites memory allocation needs.
  1488         -** The first pointer (the memory pointer) must be aligned to an 8-byte
  1489         -** boundary or subsequent behavior of SQLite will be undefined.
  1490         -** The minimum allocation size is capped at 2**12. Reasonable values
  1491         -** for the minimum allocation size are 2**5 through 2**8.</dd>
  1492         -**
  1493         -** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
  1494         -** <dd> ^(This option takes a single argument which is a pointer to an
  1495         -** instance of the [sqlite3_mutex_methods] structure.  The argument specifies
  1496         -** alternative low-level mutex routines to be used in place
  1497         -** the mutex routines built into SQLite.)^  ^SQLite makes a copy of the
  1498         -** content of the [sqlite3_mutex_methods] structure before the call to
  1499         -** [sqlite3_config()] returns. ^If SQLite is compiled with
  1500         -** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1501         -** the entire mutexing subsystem is omitted from the build and hence calls to
  1502         -** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
  1503         -** return [SQLITE_ERROR].</dd>
  1504         -**
  1505         -** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
  1506         -** <dd> ^(This option takes a single argument which is a pointer to an
  1507         -** instance of the [sqlite3_mutex_methods] structure.  The
  1508         -** [sqlite3_mutex_methods]
  1509         -** structure is filled with the currently defined mutex routines.)^
  1510         -** This option can be used to overload the default mutex allocation
  1511         -** routines with a wrapper used to track mutex usage for performance
  1512         -** profiling or testing, for example.   ^If SQLite is compiled with
  1513         -** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
  1514         -** the entire mutexing subsystem is omitted from the build and hence calls to
  1515         -** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
  1516         -** return [SQLITE_ERROR].</dd>
  1517         -**
  1518         -** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
  1519         -** <dd> ^(This option takes two arguments that determine the default
  1520         -** memory allocation for the lookaside memory allocator on each
  1521         -** [database connection].  The first argument is the
  1522         -** size of each lookaside buffer slot and the second is the number of
  1523         -** slots allocated to each database connection.)^  ^(This option sets the
  1524         -** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
  1525         -** verb to [sqlite3_db_config()] can be used to change the lookaside
  1526         -** configuration on individual connections.)^ </dd>
  1527         -**
  1528         -** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
  1529         -** <dd> ^(This option takes a single argument which is a pointer to
  1530         -** an [sqlite3_pcache_methods2] object.  This object specifies the interface
  1531         -** to a custom page cache implementation.)^  ^SQLite makes a copy of the
  1532         -** object and uses it for page cache memory allocations.</dd>
  1533         -**
  1534         -** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
  1535         -** <dd> ^(This option takes a single argument which is a pointer to an
  1536         -** [sqlite3_pcache_methods2] object.  SQLite copies of the current
  1537         -** page cache implementation into that object.)^ </dd>
  1538         -**
  1539         -** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
  1540         -** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
  1541         -** function with a call signature of void(*)(void*,int,const char*), 
  1542         -** and a pointer to void. ^If the function pointer is not NULL, it is
  1543         -** invoked by [sqlite3_log()] to process each logging event.  ^If the
  1544         -** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
  1545         -** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
  1546         -** passed through as the first parameter to the application-defined logger
  1547         -** function whenever that function is invoked.  ^The second parameter to
  1548         -** the logger function is a copy of the first parameter to the corresponding
  1549         -** [sqlite3_log()] call and is intended to be a [result code] or an
  1550         -** [extended result code].  ^The third parameter passed to the logger is
  1551         -** log message after formatting via [sqlite3_snprintf()].
  1552         -** The SQLite logging interface is not reentrant; the logger function
  1553         -** supplied by the application must not invoke any SQLite interface.
  1554         -** In a multi-threaded application, the application-defined logger
  1555         -** function must be threadsafe. </dd>
  1556         -**
  1557         -** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
  1558         -** <dd> This option takes a single argument of type int. If non-zero, then
  1559         -** URI handling is globally enabled. If the parameter is zero, then URI handling
  1560         -** is globally disabled. If URI handling is globally enabled, all filenames
  1561         -** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
  1562         -** specified as part of [ATTACH] commands are interpreted as URIs, regardless
  1563         -** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
  1564         -** connection is opened. If it is globally disabled, filenames are
  1565         -** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
  1566         -** database connection is opened. By default, URI handling is globally
  1567         -** disabled. The default value may be changed by compiling with the
  1568         -** [SQLITE_USE_URI] symbol defined.
  1569         -**
  1570         -** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
  1571         -** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
  1572         -** <dd> These options are obsolete and should not be used by new code.
  1573         -** They are retained for backwards compatibility but are now no-ops.
  1574         -** </dl>
  1575         -*/
  1576         -#define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
  1577         -#define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
  1578         -#define SQLITE_CONFIG_SERIALIZED    3  /* nil */
  1579         -#define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
  1580         -#define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
  1581         -#define SQLITE_CONFIG_SCRATCH       6  /* void*, int sz, int N */
  1582         -#define SQLITE_CONFIG_PAGECACHE     7  /* void*, int sz, int N */
  1583         -#define SQLITE_CONFIG_HEAP          8  /* void*, int nByte, int min */
  1584         -#define SQLITE_CONFIG_MEMSTATUS     9  /* boolean */
  1585         -#define SQLITE_CONFIG_MUTEX        10  /* sqlite3_mutex_methods* */
  1586         -#define SQLITE_CONFIG_GETMUTEX     11  /* sqlite3_mutex_methods* */
  1587         -/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 
  1588         -#define SQLITE_CONFIG_LOOKASIDE    13  /* int int */
  1589         -#define SQLITE_CONFIG_PCACHE       14  /* no-op */
  1590         -#define SQLITE_CONFIG_GETPCACHE    15  /* no-op */
  1591         -#define SQLITE_CONFIG_LOG          16  /* xFunc, void* */
  1592         -#define SQLITE_CONFIG_URI          17  /* int */
  1593         -#define SQLITE_CONFIG_PCACHE2      18  /* sqlite3_pcache_methods2* */
  1594         -#define SQLITE_CONFIG_GETPCACHE2   19  /* sqlite3_pcache_methods2* */
  1595         -
  1596         -/*
  1597         -** CAPI3REF: Database Connection Configuration Options
  1598         -**
  1599         -** These constants are the available integer configuration options that
  1600         -** can be passed as the second argument to the [sqlite3_db_config()] interface.
  1601         -**
  1602         -** New configuration options may be added in future releases of SQLite.
  1603         -** Existing configuration options might be discontinued.  Applications
  1604         -** should check the return code from [sqlite3_db_config()] to make sure that
  1605         -** the call worked.  ^The [sqlite3_db_config()] interface will return a
  1606         -** non-zero [error code] if a discontinued or unsupported configuration option
  1607         -** is invoked.
  1608         -**
  1609         -** <dl>
  1610         -** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
  1611         -** <dd> ^This option takes three additional arguments that determine the 
  1612         -** [lookaside memory allocator] configuration for the [database connection].
  1613         -** ^The first argument (the third parameter to [sqlite3_db_config()] is a
  1614         -** pointer to a memory buffer to use for lookaside memory.
  1615         -** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
  1616         -** may be NULL in which case SQLite will allocate the
  1617         -** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
  1618         -** size of each lookaside buffer slot.  ^The third argument is the number of
  1619         -** slots.  The size of the buffer in the first argument must be greater than
  1620         -** or equal to the product of the second and third arguments.  The buffer
  1621         -** must be aligned to an 8-byte boundary.  ^If the second argument to
  1622         -** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
  1623         -** rounded down to the next smaller multiple of 8.  ^(The lookaside memory
  1624         -** configuration for a database connection can only be changed when that
  1625         -** connection is not currently using lookaside memory, or in other words
  1626         -** when the "current value" returned by
  1627         -** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
  1628         -** Any attempt to change the lookaside memory configuration when lookaside
  1629         -** memory is in use leaves the configuration unchanged and returns 
  1630         -** [SQLITE_BUSY].)^</dd>
  1631         -**
  1632         -** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
  1633         -** <dd> ^This option is used to enable or disable the enforcement of
  1634         -** [foreign key constraints].  There should be two additional arguments.
  1635         -** The first argument is an integer which is 0 to disable FK enforcement,
  1636         -** positive to enable FK enforcement or negative to leave FK enforcement
  1637         -** unchanged.  The second parameter is a pointer to an integer into which
  1638         -** is written 0 or 1 to indicate whether FK enforcement is off or on
  1639         -** following this call.  The second parameter may be a NULL pointer, in
  1640         -** which case the FK enforcement setting is not reported back. </dd>
  1641         -**
  1642         -** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
  1643         -** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
  1644         -** There should be two additional arguments.
  1645         -** The first argument is an integer which is 0 to disable triggers,
  1646         -** positive to enable triggers or negative to leave the setting unchanged.
  1647         -** The second parameter is a pointer to an integer into which
  1648         -** is written 0 or 1 to indicate whether triggers are disabled or enabled
  1649         -** following this call.  The second parameter may be a NULL pointer, in
  1650         -** which case the trigger setting is not reported back. </dd>
  1651         -**
  1652         -** </dl>
  1653         -*/
  1654         -#define SQLITE_DBCONFIG_LOOKASIDE       1001  /* void* int int */
  1655         -#define SQLITE_DBCONFIG_ENABLE_FKEY     1002  /* int int* */
  1656         -#define SQLITE_DBCONFIG_ENABLE_TRIGGER  1003  /* int int* */
  1657         -
  1658         -
  1659         -/*
  1660         -** CAPI3REF: Enable Or Disable Extended Result Codes
  1661         -**
  1662         -** ^The sqlite3_extended_result_codes() routine enables or disables the
  1663         -** [extended result codes] feature of SQLite. ^The extended result
  1664         -** codes are disabled by default for historical compatibility.
  1665         -*/
  1666         -SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
  1667         -
  1668         -/*
  1669         -** CAPI3REF: Last Insert Rowid
  1670         -**
  1671         -** ^Each entry in an SQLite table has a unique 64-bit signed
  1672         -** integer key called the [ROWID | "rowid"]. ^The rowid is always available
  1673         -** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
  1674         -** names are not also used by explicitly declared columns. ^If
  1675         -** the table has a column of type [INTEGER PRIMARY KEY] then that column
  1676         -** is another alias for the rowid.
  1677         -**
  1678         -** ^This routine returns the [rowid] of the most recent
  1679         -** successful [INSERT] into the database from the [database connection]
  1680         -** in the first argument.  ^As of SQLite version 3.7.7, this routines
  1681         -** records the last insert rowid of both ordinary tables and [virtual tables].
  1682         -** ^If no successful [INSERT]s
  1683         -** have ever occurred on that database connection, zero is returned.
  1684         -**
  1685         -** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
  1686         -** method, then this routine will return the [rowid] of the inserted
  1687         -** row as long as the trigger or virtual table method is running.
  1688         -** But once the trigger or virtual table method ends, the value returned 
  1689         -** by this routine reverts to what it was before the trigger or virtual
  1690         -** table method began.)^
  1691         -**
  1692         -** ^An [INSERT] that fails due to a constraint violation is not a
  1693         -** successful [INSERT] and does not change the value returned by this
  1694         -** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
  1695         -** and INSERT OR ABORT make no changes to the return value of this
  1696         -** routine when their insertion fails.  ^(When INSERT OR REPLACE
  1697         -** encounters a constraint violation, it does not fail.  The
  1698         -** INSERT continues to completion after deleting rows that caused
  1699         -** the constraint problem so INSERT OR REPLACE will always change
  1700         -** the return value of this interface.)^
  1701         -**
  1702         -** ^For the purposes of this routine, an [INSERT] is considered to
  1703         -** be successful even if it is subsequently rolled back.
  1704         -**
  1705         -** This function is accessible to SQL statements via the
  1706         -** [last_insert_rowid() SQL function].
  1707         -**
  1708         -** If a separate thread performs a new [INSERT] on the same
  1709         -** database connection while the [sqlite3_last_insert_rowid()]
  1710         -** function is running and thus changes the last insert [rowid],
  1711         -** then the value returned by [sqlite3_last_insert_rowid()] is
  1712         -** unpredictable and might not equal either the old or the new
  1713         -** last insert [rowid].
  1714         -*/
  1715         -SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
  1716         -
  1717         -/*
  1718         -** CAPI3REF: Count The Number Of Rows Modified
  1719         -**
  1720         -** ^This function returns the number of database rows that were changed
  1721         -** or inserted or deleted by the most recently completed SQL statement
  1722         -** on the [database connection] specified by the first parameter.
  1723         -** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
  1724         -** or [DELETE] statement are counted.  Auxiliary changes caused by
  1725         -** triggers or [foreign key actions] are not counted.)^ Use the
  1726         -** [sqlite3_total_changes()] function to find the total number of changes
  1727         -** including changes caused by triggers and foreign key actions.
  1728         -**
  1729         -** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
  1730         -** are not counted.  Only real table changes are counted.
  1731         -**
  1732         -** ^(A "row change" is a change to a single row of a single table
  1733         -** caused by an INSERT, DELETE, or UPDATE statement.  Rows that
  1734         -** are changed as side effects of [REPLACE] constraint resolution,
  1735         -** rollback, ABORT processing, [DROP TABLE], or by any other
  1736         -** mechanisms do not count as direct row changes.)^
  1737         -**
  1738         -** A "trigger context" is a scope of execution that begins and
  1739         -** ends with the script of a [CREATE TRIGGER | trigger]. 
  1740         -** Most SQL statements are
  1741         -** evaluated outside of any trigger.  This is the "top level"
  1742         -** trigger context.  If a trigger fires from the top level, a
  1743         -** new trigger context is entered for the duration of that one
  1744         -** trigger.  Subtriggers create subcontexts for their duration.
  1745         -**
  1746         -** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
  1747         -** not create a new trigger context.
  1748         -**
  1749         -** ^This function returns the number of direct row changes in the
  1750         -** most recent INSERT, UPDATE, or DELETE statement within the same
  1751         -** trigger context.
  1752         -**
  1753         -** ^Thus, when called from the top level, this function returns the
  1754         -** number of changes in the most recent INSERT, UPDATE, or DELETE
  1755         -** that also occurred at the top level.  ^(Within the body of a trigger,
  1756         -** the sqlite3_changes() interface can be called to find the number of
  1757         -** changes in the most recently completed INSERT, UPDATE, or DELETE
  1758         -** statement within the body of the same trigger.
  1759         -** However, the number returned does not include changes
  1760         -** caused by subtriggers since those have their own context.)^
  1761         -**
  1762         -** See also the [sqlite3_total_changes()] interface, the
  1763         -** [count_changes pragma], and the [changes() SQL function].
  1764         -**
  1765         -** If a separate thread makes changes on the same database connection
  1766         -** while [sqlite3_changes()] is running then the value returned
  1767         -** is unpredictable and not meaningful.
  1768         -*/
  1769         -SQLITE_API int sqlite3_changes(sqlite3*);
  1770         -
  1771         -/*
  1772         -** CAPI3REF: Total Number Of Rows Modified
  1773         -**
  1774         -** ^This function returns the number of row changes caused by [INSERT],
  1775         -** [UPDATE] or [DELETE] statements since the [database connection] was opened.
  1776         -** ^(The count returned by sqlite3_total_changes() includes all changes
  1777         -** from all [CREATE TRIGGER | trigger] contexts and changes made by
  1778         -** [foreign key actions]. However,
  1779         -** the count does not include changes used to implement [REPLACE] constraints,
  1780         -** do rollbacks or ABORT processing, or [DROP TABLE] processing.  The
  1781         -** count does not include rows of views that fire an [INSTEAD OF trigger],
  1782         -** though if the INSTEAD OF trigger makes changes of its own, those changes 
  1783         -** are counted.)^
  1784         -** ^The sqlite3_total_changes() function counts the changes as soon as
  1785         -** the statement that makes them is completed (when the statement handle
  1786         -** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
  1787         -**
  1788         -** See also the [sqlite3_changes()] interface, the
  1789         -** [count_changes pragma], and the [total_changes() SQL function].
  1790         -**
  1791         -** If a separate thread makes changes on the same database connection
  1792         -** while [sqlite3_total_changes()] is running then the value
  1793         -** returned is unpredictable and not meaningful.
  1794         -*/
  1795         -SQLITE_API int sqlite3_total_changes(sqlite3*);
  1796         -
  1797         -/*
  1798         -** CAPI3REF: Interrupt A Long-Running Query
  1799         -**
  1800         -** ^This function causes any pending database operation to abort and
  1801         -** return at its earliest opportunity. This routine is typically
  1802         -** called in response to a user action such as pressing "Cancel"
  1803         -** or Ctrl-C where the user wants a long query operation to halt
  1804         -** immediately.
  1805         -**
  1806         -** ^It is safe to call this routine from a thread different from the
  1807         -** thread that is currently running the database operation.  But it
  1808         -** is not safe to call this routine with a [database connection] that
  1809         -** is closed or might close before sqlite3_interrupt() returns.
  1810         -**
  1811         -** ^If an SQL operation is very nearly finished at the time when
  1812         -** sqlite3_interrupt() is called, then it might not have an opportunity
  1813         -** to be interrupted and might continue to completion.
  1814         -**
  1815         -** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
  1816         -** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
  1817         -** that is inside an explicit transaction, then the entire transaction
  1818         -** will be rolled back automatically.
  1819         -**
  1820         -** ^The sqlite3_interrupt(D) call is in effect until all currently running
  1821         -** SQL statements on [database connection] D complete.  ^Any new SQL statements
  1822         -** that are started after the sqlite3_interrupt() call and before the 
  1823         -** running statements reaches zero are interrupted as if they had been
  1824         -** running prior to the sqlite3_interrupt() call.  ^New SQL statements
  1825         -** that are started after the running statement count reaches zero are
  1826         -** not effected by the sqlite3_interrupt().
  1827         -** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  1828         -** SQL statements is a no-op and has no effect on SQL statements
  1829         -** that are started after the sqlite3_interrupt() call returns.
  1830         -**
  1831         -** If the database connection closes while [sqlite3_interrupt()]
  1832         -** is running then bad things will likely happen.
  1833         -*/
  1834         -SQLITE_API void sqlite3_interrupt(sqlite3*);
  1835         -
  1836         -/*
  1837         -** CAPI3REF: Determine If An SQL Statement Is Complete
  1838         -**
  1839         -** These routines are useful during command-line input to determine if the
  1840         -** currently entered text seems to form a complete SQL statement or
  1841         -** if additional input is needed before sending the text into
  1842         -** SQLite for parsing.  ^These routines return 1 if the input string
  1843         -** appears to be a complete SQL statement.  ^A statement is judged to be
  1844         -** complete if it ends with a semicolon token and is not a prefix of a
  1845         -** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
  1846         -** string literals or quoted identifier names or comments are not
  1847         -** independent tokens (they are part of the token in which they are
  1848         -** embedded) and thus do not count as a statement terminator.  ^Whitespace
  1849         -** and comments that follow the final semicolon are ignored.
  1850         -**
  1851         -** ^These routines return 0 if the statement is incomplete.  ^If a
  1852         -** memory allocation fails, then SQLITE_NOMEM is returned.
  1853         -**
  1854         -** ^These routines do not parse the SQL statements thus
  1855         -** will not detect syntactically incorrect SQL.
  1856         -**
  1857         -** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 
  1858         -** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
  1859         -** automatically by sqlite3_complete16().  If that initialization fails,
  1860         -** then the return value from sqlite3_complete16() will be non-zero
  1861         -** regardless of whether or not the input SQL is complete.)^
  1862         -**
  1863         -** The input to [sqlite3_complete()] must be a zero-terminated
  1864         -** UTF-8 string.
  1865         -**
  1866         -** The input to [sqlite3_complete16()] must be a zero-terminated
  1867         -** UTF-16 string in native byte order.
  1868         -*/
  1869         -SQLITE_API int sqlite3_complete(const char *sql);
  1870         -SQLITE_API int sqlite3_complete16(const void *sql);
  1871         -
  1872         -/*
  1873         -** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
  1874         -**
  1875         -** ^This routine sets a callback function that might be invoked whenever
  1876         -** an attempt is made to open a database table that another thread
  1877         -** or process has locked.
  1878         -**
  1879         -** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
  1880         -** is returned immediately upon encountering the lock.  ^If the busy callback
  1881         -** is not NULL, then the callback might be invoked with two arguments.
  1882         -**
  1883         -** ^The first argument to the busy handler is a copy of the void* pointer which
  1884         -** is the third argument to sqlite3_busy_handler().  ^The second argument to
  1885         -** the busy handler callback is the number of times that the busy handler has
  1886         -** been invoked for this locking event.  ^If the
  1887         -** busy callback returns 0, then no additional attempts are made to
  1888         -** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
  1889         -** ^If the callback returns non-zero, then another attempt
  1890         -** is made to open the database for reading and the cycle repeats.
  1891         -**
  1892         -** The presence of a busy handler does not guarantee that it will be invoked
  1893         -** when there is lock contention. ^If SQLite determines that invoking the busy
  1894         -** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
  1895         -** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
  1896         -** Consider a scenario where one process is holding a read lock that
  1897         -** it is trying to promote to a reserved lock and
  1898         -** a second process is holding a reserved lock that it is trying
  1899         -** to promote to an exclusive lock.  The first process cannot proceed
  1900         -** because it is blocked by the second and the second process cannot
  1901         -** proceed because it is blocked by the first.  If both processes
  1902         -** invoke the busy handlers, neither will make any progress.  Therefore,
  1903         -** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
  1904         -** will induce the first process to release its read lock and allow
  1905         -** the second process to proceed.
  1906         -**
  1907         -** ^The default busy callback is NULL.
  1908         -**
  1909         -** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
  1910         -** when SQLite is in the middle of a large transaction where all the
  1911         -** changes will not fit into the in-memory cache.  SQLite will
  1912         -** already hold a RESERVED lock on the database file, but it needs
  1913         -** to promote this lock to EXCLUSIVE so that it can spill cache
  1914         -** pages into the database file without harm to concurrent
  1915         -** readers.  ^If it is unable to promote the lock, then the in-memory
  1916         -** cache will be left in an inconsistent state and so the error
  1917         -** code is promoted from the relatively benign [SQLITE_BUSY] to
  1918         -** the more severe [SQLITE_IOERR_BLOCKED].  ^This error code promotion
  1919         -** forces an automatic rollback of the changes.  See the
  1920         -** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
  1921         -** CorruptionFollowingBusyError</a> wiki page for a discussion of why
  1922         -** this is important.
  1923         -**
  1924         -** ^(There can only be a single busy handler defined for each
  1925         -** [database connection].  Setting a new busy handler clears any
  1926         -** previously set handler.)^  ^Note that calling [sqlite3_busy_timeout()]
  1927         -** will also set or clear the busy handler.
  1928         -**
  1929         -** The busy callback should not take any actions which modify the
  1930         -** database connection that invoked the busy handler.  Any such actions
  1931         -** result in undefined behavior.
  1932         -** 
  1933         -** A busy handler must not close the database connection
  1934         -** or [prepared statement] that invoked the busy handler.
  1935         -*/
  1936         -SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
  1937         -
  1938         -/*
  1939         -** CAPI3REF: Set A Busy Timeout
  1940         -**
  1941         -** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
  1942         -** for a specified amount of time when a table is locked.  ^The handler
  1943         -** will sleep multiple times until at least "ms" milliseconds of sleeping
  1944         -** have accumulated.  ^After at least "ms" milliseconds of sleeping,
  1945         -** the handler returns 0 which causes [sqlite3_step()] to return
  1946         -** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
  1947         -**
  1948         -** ^Calling this routine with an argument less than or equal to zero
  1949         -** turns off all busy handlers.
  1950         -**
  1951         -** ^(There can only be a single busy handler for a particular
  1952         -** [database connection] any any given moment.  If another busy handler
  1953         -** was defined  (using [sqlite3_busy_handler()]) prior to calling
  1954         -** this routine, that other busy handler is cleared.)^
  1955         -*/
  1956         -SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
  1957         -
  1958         -/*
  1959         -** CAPI3REF: Convenience Routines For Running Queries
  1960         -**
  1961         -** This is a legacy interface that is preserved for backwards compatibility.
  1962         -** Use of this interface is not recommended.
  1963         -**
  1964         -** Definition: A <b>result table</b> is memory data structure created by the
  1965         -** [sqlite3_get_table()] interface.  A result table records the
  1966         -** complete query results from one or more queries.
  1967         -**
  1968         -** The table conceptually has a number of rows and columns.  But
  1969         -** these numbers are not part of the result table itself.  These
  1970         -** numbers are obtained separately.  Let N be the number of rows
  1971         -** and M be the number of columns.
  1972         -**
  1973         -** A result table is an array of pointers to zero-terminated UTF-8 strings.
  1974         -** There are (N+1)*M elements in the array.  The first M pointers point
  1975         -** to zero-terminated strings that  contain the names of the columns.
  1976         -** The remaining entries all point to query results.  NULL values result
  1977         -** in NULL pointers.  All other values are in their UTF-8 zero-terminated
  1978         -** string representation as returned by [sqlite3_column_text()].
  1979         -**
  1980         -** A result table might consist of one or more memory allocations.
  1981         -** It is not safe to pass a result table directly to [sqlite3_free()].
  1982         -** A result table should be deallocated using [sqlite3_free_table()].
  1983         -**
  1984         -** ^(As an example of the result table format, suppose a query result
  1985         -** is as follows:
  1986         -**
  1987         -** <blockquote><pre>
  1988         -**        Name        | Age
  1989         -**        -----------------------
  1990         -**        Alice       | 43
  1991         -**        Bob         | 28
  1992         -**        Cindy       | 21
  1993         -** </pre></blockquote>
  1994         -**
  1995         -** There are two column (M==2) and three rows (N==3).  Thus the
  1996         -** result table has 8 entries.  Suppose the result table is stored
  1997         -** in an array names azResult.  Then azResult holds this content:
  1998         -**
  1999         -** <blockquote><pre>
  2000         -**        azResult&#91;0] = "Name";
  2001         -**        azResult&#91;1] = "Age";
  2002         -**        azResult&#91;2] = "Alice";
  2003         -**        azResult&#91;3] = "43";
  2004         -**        azResult&#91;4] = "Bob";
  2005         -**        azResult&#91;5] = "28";
  2006         -**        azResult&#91;6] = "Cindy";
  2007         -**        azResult&#91;7] = "21";
  2008         -** </pre></blockquote>)^
  2009         -**
  2010         -** ^The sqlite3_get_table() function evaluates one or more
  2011         -** semicolon-separated SQL statements in the zero-terminated UTF-8
  2012         -** string of its 2nd parameter and returns a result table to the
  2013         -** pointer given in its 3rd parameter.
  2014         -**
  2015         -** After the application has finished with the result from sqlite3_get_table(),
  2016         -** it must pass the result table pointer to sqlite3_free_table() in order to
  2017         -** release the memory that was malloced.  Because of the way the
  2018         -** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
  2019         -** function must not try to call [sqlite3_free()] directly.  Only
  2020         -** [sqlite3_free_table()] is able to release the memory properly and safely.
  2021         -**
  2022         -** The sqlite3_get_table() interface is implemented as a wrapper around
  2023         -** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
  2024         -** to any internal data structures of SQLite.  It uses only the public
  2025         -** interface defined here.  As a consequence, errors that occur in the
  2026         -** wrapper layer outside of the internal [sqlite3_exec()] call are not
  2027         -** reflected in subsequent calls to [sqlite3_errcode()] or
  2028         -** [sqlite3_errmsg()].
  2029         -*/
  2030         -SQLITE_API int sqlite3_get_table(
  2031         -  sqlite3 *db,          /* An open database */
  2032         -  const char *zSql,     /* SQL to be evaluated */
  2033         -  char ***pazResult,    /* Results of the query */
  2034         -  int *pnRow,           /* Number of result rows written here */
  2035         -  int *pnColumn,        /* Number of result columns written here */
  2036         -  char **pzErrmsg       /* Error msg written here */
  2037         -);
  2038         -SQLITE_API void sqlite3_free_table(char **result);
  2039         -
  2040         -/*
  2041         -** CAPI3REF: Formatted String Printing Functions
  2042         -**
  2043         -** These routines are work-alikes of the "printf()" family of functions
  2044         -** from the standard C library.
  2045         -**
  2046         -** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  2047         -** results into memory obtained from [sqlite3_malloc()].
  2048         -** The strings returned by these two routines should be
  2049         -** released by [sqlite3_free()].  ^Both routines return a
  2050         -** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  2051         -** memory to hold the resulting string.
  2052         -**
  2053         -** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
  2054         -** the standard C library.  The result is written into the
  2055         -** buffer supplied as the second parameter whose size is given by
  2056         -** the first parameter. Note that the order of the
  2057         -** first two parameters is reversed from snprintf().)^  This is an
  2058         -** historical accident that cannot be fixed without breaking
  2059         -** backwards compatibility.  ^(Note also that sqlite3_snprintf()
  2060         -** returns a pointer to its buffer instead of the number of
  2061         -** characters actually written into the buffer.)^  We admit that
  2062         -** the number of characters written would be a more useful return
  2063         -** value but we cannot change the implementation of sqlite3_snprintf()
  2064         -** now without breaking compatibility.
  2065         -**
  2066         -** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
  2067         -** guarantees that the buffer is always zero-terminated.  ^The first
  2068         -** parameter "n" is the total size of the buffer, including space for
  2069         -** the zero terminator.  So the longest string that can be completely
  2070         -** written will be n-1 characters.
  2071         -**
  2072         -** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
  2073         -**
  2074         -** These routines all implement some additional formatting
  2075         -** options that are useful for constructing SQL statements.
  2076         -** All of the usual printf() formatting options apply.  In addition, there
  2077         -** is are "%q", "%Q", and "%z" options.
  2078         -**
  2079         -** ^(The %q option works like %s in that it substitutes a nul-terminated
  2080         -** string from the argument list.  But %q also doubles every '\'' character.
  2081         -** %q is designed for use inside a string literal.)^  By doubling each '\''
  2082         -** character it escapes that character and allows it to be inserted into
  2083         -** the string.
  2084         -**
  2085         -** For example, assume the string variable zText contains text as follows:
  2086         -**
  2087         -** <blockquote><pre>
  2088         -**  char *zText = "It's a happy day!";
  2089         -** </pre></blockquote>
  2090         -**
  2091         -** One can use this text in an SQL statement as follows:
  2092         -**
  2093         -** <blockquote><pre>
  2094         -**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
  2095         -**  sqlite3_exec(db, zSQL, 0, 0, 0);
  2096         -**  sqlite3_free(zSQL);
  2097         -** </pre></blockquote>
  2098         -**
  2099         -** Because the %q format string is used, the '\'' character in zText
  2100         -** is escaped and the SQL generated is as follows:
  2101         -**
  2102         -** <blockquote><pre>
  2103         -**  INSERT INTO table1 VALUES('It''s a happy day!')
  2104         -** </pre></blockquote>
  2105         -**
  2106         -** This is correct.  Had we used %s instead of %q, the generated SQL
  2107         -** would have looked like this:
  2108         -**
  2109         -** <blockquote><pre>
  2110         -**  INSERT INTO table1 VALUES('It's a happy day!');
  2111         -** </pre></blockquote>
  2112         -**
  2113         -** This second example is an SQL syntax error.  As a general rule you should
  2114         -** always use %q instead of %s when inserting text into a string literal.
  2115         -**
  2116         -** ^(The %Q option works like %q except it also adds single quotes around
  2117         -** the outside of the total string.  Additionally, if the parameter in the
  2118         -** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
  2119         -** single quotes).)^  So, for example, one could say:
  2120         -**
  2121         -** <blockquote><pre>
  2122         -**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
  2123         -**  sqlite3_exec(db, zSQL, 0, 0, 0);
  2124         -**  sqlite3_free(zSQL);
  2125         -** </pre></blockquote>
  2126         -**
  2127         -** The code above will render a correct SQL statement in the zSQL
  2128         -** variable even if the zText variable is a NULL pointer.
  2129         -**
  2130         -** ^(The "%z" formatting option works like "%s" but with the
  2131         -** addition that after the string has been read and copied into
  2132         -** the result, [sqlite3_free()] is called on the input string.)^
  2133         -*/
  2134         -SQLITE_API char *sqlite3_mprintf(const char*,...);
  2135         -SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  2136         -SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
  2137         -SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
  2138         -
  2139         -/*
  2140         -** CAPI3REF: Memory Allocation Subsystem
  2141         -**
  2142         -** The SQLite core uses these three routines for all of its own
  2143         -** internal memory allocation needs. "Core" in the previous sentence
  2144         -** does not include operating-system specific VFS implementation.  The
  2145         -** Windows VFS uses native malloc() and free() for some operations.
  2146         -**
  2147         -** ^The sqlite3_malloc() routine returns a pointer to a block
  2148         -** of memory at least N bytes in length, where N is the parameter.
  2149         -** ^If sqlite3_malloc() is unable to obtain sufficient free
  2150         -** memory, it returns a NULL pointer.  ^If the parameter N to
  2151         -** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
  2152         -** a NULL pointer.
  2153         -**
  2154         -** ^Calling sqlite3_free() with a pointer previously returned
  2155         -** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
  2156         -** that it might be reused.  ^The sqlite3_free() routine is
  2157         -** a no-op if is called with a NULL pointer.  Passing a NULL pointer
  2158         -** to sqlite3_free() is harmless.  After being freed, memory
  2159         -** should neither be read nor written.  Even reading previously freed
  2160         -** memory might result in a segmentation fault or other severe error.
  2161         -** Memory corruption, a segmentation fault, or other severe error
  2162         -** might result if sqlite3_free() is called with a non-NULL pointer that
  2163         -** was not obtained from sqlite3_malloc() or sqlite3_realloc().
  2164         -**
  2165         -** ^(The sqlite3_realloc() interface attempts to resize a
  2166         -** prior memory allocation to be at least N bytes, where N is the
  2167         -** second parameter.  The memory allocation to be resized is the first
  2168         -** parameter.)^ ^ If the first parameter to sqlite3_realloc()
  2169         -** is a NULL pointer then its behavior is identical to calling
  2170         -** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
  2171         -** ^If the second parameter to sqlite3_realloc() is zero or
  2172         -** negative then the behavior is exactly the same as calling
  2173         -** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
  2174         -** ^sqlite3_realloc() returns a pointer to a memory allocation
  2175         -** of at least N bytes in size or NULL if sufficient memory is unavailable.
  2176         -** ^If M is the size of the prior allocation, then min(N,M) bytes
  2177         -** of the prior allocation are copied into the beginning of buffer returned
  2178         -** by sqlite3_realloc() and the prior allocation is freed.
  2179         -** ^If sqlite3_realloc() returns NULL, then the prior allocation
  2180         -** is not freed.
  2181         -**
  2182         -** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
  2183         -** is always aligned to at least an 8 byte boundary, or to a
  2184         -** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
  2185         -** option is used.
  2186         -**
  2187         -** In SQLite version 3.5.0 and 3.5.1, it was possible to define
  2188         -** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
  2189         -** implementation of these routines to be omitted.  That capability
  2190         -** is no longer provided.  Only built-in memory allocators can be used.
  2191         -**
  2192         -** Prior to SQLite version 3.7.10, the Windows OS interface layer called
  2193         -** the system malloc() and free() directly when converting
  2194         -** filenames between the UTF-8 encoding used by SQLite
  2195         -** and whatever filename encoding is used by the particular Windows
  2196         -** installation.  Memory allocation errors were detected, but
  2197         -** they were reported back as [SQLITE_CANTOPEN] or
  2198         -** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
  2199         -**
  2200         -** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
  2201         -** must be either NULL or else pointers obtained from a prior
  2202         -** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
  2203         -** not yet been released.
  2204         -**
  2205         -** The application must not read or write any part of
  2206         -** a block of memory after it has been released using
  2207         -** [sqlite3_free()] or [sqlite3_realloc()].
  2208         -*/
  2209         -SQLITE_API void *sqlite3_malloc(int);
  2210         -SQLITE_API void *sqlite3_realloc(void*, int);
  2211         -SQLITE_API void sqlite3_free(void*);
  2212         -
  2213         -/*
  2214         -** CAPI3REF: Memory Allocator Statistics
  2215         -**
  2216         -** SQLite provides these two interfaces for reporting on the status
  2217         -** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
  2218         -** routines, which form the built-in memory allocation subsystem.
  2219         -**
  2220         -** ^The [sqlite3_memory_used()] routine returns the number of bytes
  2221         -** of memory currently outstanding (malloced but not freed).
  2222         -** ^The [sqlite3_memory_highwater()] routine returns the maximum
  2223         -** value of [sqlite3_memory_used()] since the high-water mark
  2224         -** was last reset.  ^The values returned by [sqlite3_memory_used()] and
  2225         -** [sqlite3_memory_highwater()] include any overhead
  2226         -** added by SQLite in its implementation of [sqlite3_malloc()],
  2227         -** but not overhead added by the any underlying system library
  2228         -** routines that [sqlite3_malloc()] may call.
  2229         -**
  2230         -** ^The memory high-water mark is reset to the current value of
  2231         -** [sqlite3_memory_used()] if and only if the parameter to
  2232         -** [sqlite3_memory_highwater()] is true.  ^The value returned
  2233         -** by [sqlite3_memory_highwater(1)] is the high-water mark
  2234         -** prior to the reset.
  2235         -*/
  2236         -SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
  2237         -SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
  2238         -
  2239         -/*
  2240         -** CAPI3REF: Pseudo-Random Number Generator
  2241         -**
  2242         -** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
  2243         -** select random [ROWID | ROWIDs] when inserting new records into a table that
  2244         -** already uses the largest possible [ROWID].  The PRNG is also used for
  2245         -** the build-in random() and randomblob() SQL functions.  This interface allows
  2246         -** applications to access the same PRNG for other purposes.
  2247         -**
  2248         -** ^A call to this routine stores N bytes of randomness into buffer P.
  2249         -**
  2250         -** ^The first time this routine is invoked (either internally or by
  2251         -** the application) the PRNG is seeded using randomness obtained
  2252         -** from the xRandomness method of the default [sqlite3_vfs] object.
  2253         -** ^On all subsequent invocations, the pseudo-randomness is generated
  2254         -** internally and without recourse to the [sqlite3_vfs] xRandomness
  2255         -** method.
  2256         -*/
  2257         -SQLITE_API void sqlite3_randomness(int N, void *P);
  2258         -
  2259         -/*
  2260         -** CAPI3REF: Compile-Time Authorization Callbacks
  2261         -**
  2262         -** ^This routine registers an authorizer callback with a particular
  2263         -** [database connection], supplied in the first argument.
  2264         -** ^The authorizer callback is invoked as SQL statements are being compiled
  2265         -** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  2266         -** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  ^At various
  2267         -** points during the compilation process, as logic is being created
  2268         -** to perform various actions, the authorizer callback is invoked to
  2269         -** see if those actions are allowed.  ^The authorizer callback should
  2270         -** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
  2271         -** specific action but allow the SQL statement to continue to be
  2272         -** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
  2273         -** rejected with an error.  ^If the authorizer callback returns
  2274         -** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
  2275         -** then the [sqlite3_prepare_v2()] or equivalent call that triggered
  2276         -** the authorizer will fail with an error message.
  2277         -**
  2278         -** When the callback returns [SQLITE_OK], that means the operation
  2279         -** requested is ok.  ^When the callback returns [SQLITE_DENY], the
  2280         -** [sqlite3_prepare_v2()] or equivalent call that triggered the
  2281         -** authorizer will fail with an error message explaining that
  2282         -** access is denied. 
  2283         -**
  2284         -** ^The first parameter to the authorizer callback is a copy of the third
  2285         -** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  2286         -** to the callback is an integer [SQLITE_COPY | action code] that specifies
  2287         -** the particular action to be authorized. ^The third through sixth parameters
  2288         -** to the callback are zero-terminated strings that contain additional
  2289         -** details about the action to be authorized.
  2290         -**
  2291         -** ^If the action code is [SQLITE_READ]
  2292         -** and the callback returns [SQLITE_IGNORE] then the
  2293         -** [prepared statement] statement is constructed to substitute
  2294         -** a NULL value in place of the table column that would have
  2295         -** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
  2296         -** return can be used to deny an untrusted user access to individual
  2297         -** columns of a table.
  2298         -** ^If the action code is [SQLITE_DELETE] and the callback returns
  2299         -** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  2300         -** [truncate optimization] is disabled and all rows are deleted individually.
  2301         -**
  2302         -** An authorizer is used when [sqlite3_prepare | preparing]
  2303         -** SQL statements from an untrusted source, to ensure that the SQL statements
  2304         -** do not try to access data they are not allowed to see, or that they do not
  2305         -** try to execute malicious statements that damage the database.  For
  2306         -** example, an application may allow a user to enter arbitrary
  2307         -** SQL queries for evaluation by a database.  But the application does
  2308         -** not want the user to be able to make arbitrary changes to the
  2309         -** database.  An authorizer could then be put in place while the
  2310         -** user-entered SQL is being [sqlite3_prepare | prepared] that
  2311         -** disallows everything except [SELECT] statements.
  2312         -**
  2313         -** Applications that need to process SQL from untrusted sources
  2314         -** might also consider lowering resource limits using [sqlite3_limit()]
  2315         -** and limiting database size using the [max_page_count] [PRAGMA]
  2316         -** in addition to using an authorizer.
  2317         -**
  2318         -** ^(Only a single authorizer can be in place on a database connection
  2319         -** at a time.  Each call to sqlite3_set_authorizer overrides the
  2320         -** previous call.)^  ^Disable the authorizer by installing a NULL callback.
  2321         -** The authorizer is disabled by default.
  2322         -**
  2323         -** The authorizer callback must not do anything that will modify
  2324         -** the database connection that invoked the authorizer callback.
  2325         -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  2326         -** database connections for the meaning of "modify" in this paragraph.
  2327         -**
  2328         -** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
  2329         -** statement might be re-prepared during [sqlite3_step()] due to a 
  2330         -** schema change.  Hence, the application should ensure that the
  2331         -** correct authorizer callback remains in place during the [sqlite3_step()].
  2332         -**
  2333         -** ^Note that the authorizer callback is invoked only during
  2334         -** [sqlite3_prepare()] or its variants.  Authorization is not
  2335         -** performed during statement evaluation in [sqlite3_step()], unless
  2336         -** as stated in the previous paragraph, sqlite3_step() invokes
  2337         -** sqlite3_prepare_v2() to reprepare a statement after a schema change.
  2338         -*/
  2339         -SQLITE_API int sqlite3_set_authorizer(
  2340         -  sqlite3*,
  2341         -  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  2342         -  void *pUserData
  2343         -);
  2344         -
  2345         -/*
  2346         -** CAPI3REF: Authorizer Return Codes
  2347         -**
  2348         -** The [sqlite3_set_authorizer | authorizer callback function] must
  2349         -** return either [SQLITE_OK] or one of these two constants in order
  2350         -** to signal SQLite whether or not the action is permitted.  See the
  2351         -** [sqlite3_set_authorizer | authorizer documentation] for additional
  2352         -** information.
  2353         -**
  2354         -** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code]
  2355         -** from the [sqlite3_vtab_on_conflict()] interface.
  2356         -*/
  2357         -#define SQLITE_DENY   1   /* Abort the SQL statement with an error */
  2358         -#define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
  2359         -
  2360         -/*
  2361         -** CAPI3REF: Authorizer Action Codes
  2362         -**
  2363         -** The [sqlite3_set_authorizer()] interface registers a callback function
  2364         -** that is invoked to authorize certain SQL statement actions.  The
  2365         -** second parameter to the callback is an integer code that specifies
  2366         -** what action is being authorized.  These are the integer action codes that
  2367         -** the authorizer callback may be passed.
  2368         -**
  2369         -** These action code values signify what kind of operation is to be
  2370         -** authorized.  The 3rd and 4th parameters to the authorization
  2371         -** callback function will be parameters or NULL depending on which of these
  2372         -** codes is used as the second parameter.  ^(The 5th parameter to the
  2373         -** authorizer callback is the name of the database ("main", "temp",
  2374         -** etc.) if applicable.)^  ^The 6th parameter to the authorizer callback
  2375         -** is the name of the inner-most trigger or view that is responsible for
  2376         -** the access attempt or NULL if this access attempt is directly from
  2377         -** top-level SQL code.
  2378         -*/
  2379         -/******************************************* 3rd ************ 4th ***********/
  2380         -#define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */
  2381         -#define SQLITE_CREATE_TABLE          2   /* Table Name      NULL            */
  2382         -#define SQLITE_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */
  2383         -#define SQLITE_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */
  2384         -#define SQLITE_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */
  2385         -#define SQLITE_CREATE_TEMP_VIEW      6   /* View Name       NULL            */
  2386         -#define SQLITE_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */
  2387         -#define SQLITE_CREATE_VIEW           8   /* View Name       NULL            */
  2388         -#define SQLITE_DELETE                9   /* Table Name      NULL            */
  2389         -#define SQLITE_DROP_INDEX           10   /* Index Name      Table Name      */
  2390         -#define SQLITE_DROP_TABLE           11   /* Table Name      NULL            */
  2391         -#define SQLITE_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */
  2392         -#define SQLITE_DROP_TEMP_TABLE      13   /* Table Name      NULL            */
  2393         -#define SQLITE_DROP_TEMP_TRIGGER    14   /* Trigger Name    Table Name      */
  2394         -#define SQLITE_DROP_TEMP_VIEW       15   /* View Name       NULL            */
  2395         -#define SQLITE_DROP_TRIGGER         16   /* Trigger Name    Table Name      */
  2396         -#define SQLITE_DROP_VIEW            17   /* View Name       NULL            */
  2397         -#define SQLITE_INSERT               18   /* Table Name      NULL            */
  2398         -#define SQLITE_PRAGMA               19   /* Pragma Name     1st arg or NULL */
  2399         -#define SQLITE_READ                 20   /* Table Name      Column Name     */
  2400         -#define SQLITE_SELECT               21   /* NULL            NULL            */
  2401         -#define SQLITE_TRANSACTION          22   /* Operation       NULL            */
  2402         -#define SQLITE_UPDATE               23   /* Table Name      Column Name     */
  2403         -#define SQLITE_ATTACH               24   /* Filename        NULL            */
  2404         -#define SQLITE_DETACH               25   /* Database Name   NULL            */
  2405         -#define SQLITE_ALTER_TABLE          26   /* Database Name   Table Name      */
  2406         -#define SQLITE_REINDEX              27   /* Index Name      NULL            */
  2407         -#define SQLITE_ANALYZE              28   /* Table Name      NULL            */
  2408         -#define SQLITE_CREATE_VTABLE        29   /* Table Name      Module Name     */
  2409         -#define SQLITE_DROP_VTABLE          30   /* Table Name      Module Name     */
  2410         -#define SQLITE_FUNCTION             31   /* NULL            Function Name   */
  2411         -#define SQLITE_SAVEPOINT            32   /* Operation       Savepoint Name  */
  2412         -#define SQLITE_COPY                  0   /* No longer used */
  2413         -
  2414         -/*
  2415         -** CAPI3REF: Tracing And Profiling Functions
  2416         -**
  2417         -** These routines register callback functions that can be used for
  2418         -** tracing and profiling the execution of SQL statements.
  2419         -**
  2420         -** ^The callback function registered by sqlite3_trace() is invoked at
  2421         -** various times when an SQL statement is being run by [sqlite3_step()].
  2422         -** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
  2423         -** SQL statement text as the statement first begins executing.
  2424         -** ^(Additional sqlite3_trace() callbacks might occur
  2425         -** as each triggered subprogram is entered.  The callbacks for triggers
  2426         -** contain a UTF-8 SQL comment that identifies the trigger.)^
  2427         -**
  2428         -** ^The callback function registered by sqlite3_profile() is invoked
  2429         -** as each SQL statement finishes.  ^The profile callback contains
  2430         -** the original statement text and an estimate of wall-clock time
  2431         -** of how long that statement took to run.  ^The profile callback
  2432         -** time is in units of nanoseconds, however the current implementation
  2433         -** is only capable of millisecond resolution so the six least significant
  2434         -** digits in the time are meaningless.  Future versions of SQLite
  2435         -** might provide greater resolution on the profiler callback.  The
  2436         -** sqlite3_profile() function is considered experimental and is
  2437         -** subject to change in future versions of SQLite.
  2438         -*/
  2439         -SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  2440         -SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
  2441         -   void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
  2442         -
  2443         -/*
  2444         -** CAPI3REF: Query Progress Callbacks
  2445         -**
  2446         -** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
  2447         -** function X to be invoked periodically during long running calls to
  2448         -** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
  2449         -** database connection D.  An example use for this
  2450         -** interface is to keep a GUI updated during a large query.
  2451         -**
  2452         -** ^The parameter P is passed through as the only parameter to the 
  2453         -** callback function X.  ^The parameter N is the number of 
  2454         -** [virtual machine instructions] that are evaluated between successive
  2455         -** invocations of the callback X.
  2456         -**
  2457         -** ^Only a single progress handler may be defined at one time per
  2458         -** [database connection]; setting a new progress handler cancels the
  2459         -** old one.  ^Setting parameter X to NULL disables the progress handler.
  2460         -** ^The progress handler is also disabled by setting N to a value less
  2461         -** than 1.
  2462         -**
  2463         -** ^If the progress callback returns non-zero, the operation is
  2464         -** interrupted.  This feature can be used to implement a
  2465         -** "Cancel" button on a GUI progress dialog box.
  2466         -**
  2467         -** The progress handler callback must not do anything that will modify
  2468         -** the database connection that invoked the progress handler.
  2469         -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  2470         -** database connections for the meaning of "modify" in this paragraph.
  2471         -**
  2472         -*/
  2473         -SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  2474         -
  2475         -/*
  2476         -** CAPI3REF: Opening A New Database Connection
  2477         -**
  2478         -** ^These routines open an SQLite database file as specified by the 
  2479         -** filename argument. ^The filename argument is interpreted as UTF-8 for
  2480         -** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
  2481         -** order for sqlite3_open16(). ^(A [database connection] handle is usually
  2482         -** returned in *ppDb, even if an error occurs.  The only exception is that
  2483         -** if SQLite is unable to allocate memory to hold the [sqlite3] object,
  2484         -** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
  2485         -** object.)^ ^(If the database is opened (and/or created) successfully, then
  2486         -** [SQLITE_OK] is returned.  Otherwise an [error code] is returned.)^ ^The
  2487         -** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
  2488         -** an English language description of the error following a failure of any
  2489         -** of the sqlite3_open() routines.
  2490         -**
  2491         -** ^The default encoding for the database will be UTF-8 if
  2492         -** sqlite3_open() or sqlite3_open_v2() is called and
  2493         -** UTF-16 in the native byte order if sqlite3_open16() is used.
  2494         -**
  2495         -** Whether or not an error occurs when it is opened, resources
  2496         -** associated with the [database connection] handle should be released by
  2497         -** passing it to [sqlite3_close()] when it is no longer required.
  2498         -**
  2499         -** The sqlite3_open_v2() interface works like sqlite3_open()
  2500         -** except that it accepts two additional parameters for additional control
  2501         -** over the new database connection.  ^(The flags parameter to
  2502         -** sqlite3_open_v2() can take one of
  2503         -** the following three values, optionally combined with the 
  2504         -** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
  2505         -** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
  2506         -**
  2507         -** <dl>
  2508         -** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
  2509         -** <dd>The database is opened in read-only mode.  If the database does not
  2510         -** already exist, an error is returned.</dd>)^
  2511         -**
  2512         -** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
  2513         -** <dd>The database is opened for reading and writing if possible, or reading
  2514         -** only if the file is write protected by the operating system.  In either
  2515         -** case the database must already exist, otherwise an error is returned.</dd>)^
  2516         -**
  2517         -** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  2518         -** <dd>The database is opened for reading and writing, and is created if
  2519         -** it does not already exist. This is the behavior that is always used for
  2520         -** sqlite3_open() and sqlite3_open16().</dd>)^
  2521         -** </dl>
  2522         -**
  2523         -** If the 3rd parameter to sqlite3_open_v2() is not one of the
  2524         -** combinations shown above optionally combined with other
  2525         -** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
  2526         -** then the behavior is undefined.
  2527         -**
  2528         -** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
  2529         -** opens in the multi-thread [threading mode] as long as the single-thread
  2530         -** mode has not been set at compile-time or start-time.  ^If the
  2531         -** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
  2532         -** in the serialized [threading mode] unless single-thread was
  2533         -** previously selected at compile-time or start-time.
  2534         -** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
  2535         -** eligible to use [shared cache mode], regardless of whether or not shared
  2536         -** cache is enabled using [sqlite3_enable_shared_cache()].  ^The
  2537         -** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
  2538         -** participate in [shared cache mode] even if it is enabled.
  2539         -**
  2540         -** ^The fourth parameter to sqlite3_open_v2() is the name of the
  2541         -** [sqlite3_vfs] object that defines the operating system interface that
  2542         -** the new database connection should use.  ^If the fourth parameter is
  2543         -** a NULL pointer then the default [sqlite3_vfs] object is used.
  2544         -**
  2545         -** ^If the filename is ":memory:", then a private, temporary in-memory database
  2546         -** is created for the connection.  ^This in-memory database will vanish when
  2547         -** the database connection is closed.  Future versions of SQLite might
  2548         -** make use of additional special filenames that begin with the ":" character.
  2549         -** It is recommended that when a database filename actually does begin with
  2550         -** a ":" character you should prefix the filename with a pathname such as
  2551         -** "./" to avoid ambiguity.
  2552         -**
  2553         -** ^If the filename is an empty string, then a private, temporary
  2554         -** on-disk database will be created.  ^This private database will be
  2555         -** automatically deleted as soon as the database connection is closed.
  2556         -**
  2557         -** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
  2558         -**
  2559         -** ^If [URI filename] interpretation is enabled, and the filename argument
  2560         -** begins with "file:", then the filename is interpreted as a URI. ^URI
  2561         -** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
  2562         -** set in the fourth argument to sqlite3_open_v2(), or if it has
  2563         -** been enabled globally using the [SQLITE_CONFIG_URI] option with the
  2564         -** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
  2565         -** As of SQLite version 3.7.7, URI filename interpretation is turned off
  2566         -** by default, but future releases of SQLite might enable URI filename
  2567         -** interpretation by default.  See "[URI filenames]" for additional
  2568         -** information.
  2569         -**
  2570         -** URI filenames are parsed according to RFC 3986. ^If the URI contains an
  2571         -** authority, then it must be either an empty string or the string 
  2572         -** "localhost". ^If the authority is not an empty string or "localhost", an 
  2573         -** error is returned to the caller. ^The fragment component of a URI, if 
  2574         -** present, is ignored.
  2575         -**
  2576         -** ^SQLite uses the path component of the URI as the name of the disk file
  2577         -** which contains the database. ^If the path begins with a '/' character, 
  2578         -** then it is interpreted as an absolute path. ^If the path does not begin 
  2579         -** with a '/' (meaning that the authority section is omitted from the URI)
  2580         -** then the path is interpreted as a relative path. 
  2581         -** ^On windows, the first component of an absolute path 
  2582         -** is a drive specification (e.g. "C:").
  2583         -**
  2584         -** [[core URI query parameters]]
  2585         -** The query component of a URI may contain parameters that are interpreted
  2586         -** either by SQLite itself, or by a [VFS | custom VFS implementation].
  2587         -** SQLite interprets the following three query parameters:
  2588         -**
  2589         -** <ul>
  2590         -**   <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
  2591         -**     a VFS object that provides the operating system interface that should
  2592         -**     be used to access the database file on disk. ^If this option is set to
  2593         -**     an empty string the default VFS object is used. ^Specifying an unknown
  2594         -**     VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
  2595         -**     present, then the VFS specified by the option takes precedence over
  2596         -**     the value passed as the fourth parameter to sqlite3_open_v2().
  2597         -**
  2598         -**   <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
  2599         -**     "rwc", or "memory". Attempting to set it to any other value is
  2600         -**     an error)^. 
  2601         -**     ^If "ro" is specified, then the database is opened for read-only 
  2602         -**     access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 
  2603         -**     third argument to sqlite3_prepare_v2(). ^If the mode option is set to 
  2604         -**     "rw", then the database is opened for read-write (but not create) 
  2605         -**     access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 
  2606         -**     been set. ^Value "rwc" is equivalent to setting both 
  2607         -**     SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE.  ^If the mode option is
  2608         -**     set to "memory" then a pure [in-memory database] that never reads
  2609         -**     or writes from disk is used. ^It is an error to specify a value for
  2610         -**     the mode parameter that is less restrictive than that specified by
  2611         -**     the flags passed in the third parameter to sqlite3_open_v2().
  2612         -**
  2613         -**   <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
  2614         -**     "private". ^Setting it to "shared" is equivalent to setting the
  2615         -**     SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
  2616         -**     sqlite3_open_v2(). ^Setting the cache parameter to "private" is 
  2617         -**     equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
  2618         -**     ^If sqlite3_open_v2() is used and the "cache" parameter is present in
  2619         -**     a URI filename, its value overrides any behaviour requested by setting
  2620         -**     SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
  2621         -** </ul>
  2622         -**
  2623         -** ^Specifying an unknown parameter in the query component of a URI is not an
  2624         -** error.  Future versions of SQLite might understand additional query
  2625         -** parameters.  See "[query parameters with special meaning to SQLite]" for
  2626         -** additional information.
  2627         -**
  2628         -** [[URI filename examples]] <h3>URI filename examples</h3>
  2629         -**
  2630         -** <table border="1" align=center cellpadding=5>
  2631         -** <tr><th> URI filenames <th> Results
  2632         -** <tr><td> file:data.db <td> 
  2633         -**          Open the file "data.db" in the current directory.
  2634         -** <tr><td> file:/home/fred/data.db<br>
  2635         -**          file:///home/fred/data.db <br> 
  2636         -**          file://localhost/home/fred/data.db <br> <td> 
  2637         -**          Open the database file "/home/fred/data.db".
  2638         -** <tr><td> file://darkstar/home/fred/data.db <td> 
  2639         -**          An error. "darkstar" is not a recognized authority.
  2640         -** <tr><td style="white-space:nowrap"> 
  2641         -**          file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
  2642         -**     <td> Windows only: Open the file "data.db" on fred's desktop on drive
  2643         -**          C:. Note that the %20 escaping in this example is not strictly 
  2644         -**          necessary - space characters can be used literally
  2645         -**          in URI filenames.
  2646         -** <tr><td> file:data.db?mode=ro&cache=private <td> 
  2647         -**          Open file "data.db" in the current directory for read-only access.
  2648         -**          Regardless of whether or not shared-cache mode is enabled by
  2649         -**          default, use a private cache.
  2650         -** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td>
  2651         -**          Open file "/home/fred/data.db". Use the special VFS "unix-nolock".
  2652         -** <tr><td> file:data.db?mode=readonly <td> 
  2653         -**          An error. "readonly" is not a valid option for the "mode" parameter.
  2654         -** </table>
  2655         -**
  2656         -** ^URI hexadecimal escape sequences (%HH) are supported within the path and
  2657         -** query components of a URI. A hexadecimal escape sequence consists of a
  2658         -** percent sign - "%" - followed by exactly two hexadecimal digits 
  2659         -** specifying an octet value. ^Before the path or query components of a
  2660         -** URI filename are interpreted, they are encoded using UTF-8 and all 
  2661         -** hexadecimal escape sequences replaced by a single byte containing the
  2662         -** corresponding octet. If this process generates an invalid UTF-8 encoding,
  2663         -** the results are undefined.
  2664         -**
  2665         -** <b>Note to Windows users:</b>  The encoding used for the filename argument
  2666         -** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
  2667         -** codepage is currently defined.  Filenames containing international
  2668         -** characters must be converted to UTF-8 prior to passing them into
  2669         -** sqlite3_open() or sqlite3_open_v2().
  2670         -*/
  2671         -SQLITE_API int sqlite3_open(
  2672         -  const char *filename,   /* Database filename (UTF-8) */
  2673         -  sqlite3 **ppDb          /* OUT: SQLite db handle */
  2674         -);
  2675         -SQLITE_API int sqlite3_open16(
  2676         -  const void *filename,   /* Database filename (UTF-16) */
  2677         -  sqlite3 **ppDb          /* OUT: SQLite db handle */
  2678         -);
  2679         -SQLITE_API int sqlite3_open_v2(
  2680         -  const char *filename,   /* Database filename (UTF-8) */
  2681         -  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  2682         -  int flags,              /* Flags */
  2683         -  const char *zVfs        /* Name of VFS module to use */
  2684         -);
  2685         -
  2686         -/*
  2687         -** CAPI3REF: Obtain Values For URI Parameters
  2688         -**
  2689         -** These are utility routines, useful to VFS implementations, that check
  2690         -** to see if a database file was a URI that contained a specific query 
  2691         -** parameter, and if so obtains the value of that query parameter.
  2692         -**
  2693         -** If F is the database filename pointer passed into the xOpen() method of 
  2694         -** a VFS implementation when the flags parameter to xOpen() has one or 
  2695         -** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
  2696         -** P is the name of the query parameter, then
  2697         -** sqlite3_uri_parameter(F,P) returns the value of the P
  2698         -** parameter if it exists or a NULL pointer if P does not appear as a 
  2699         -** query parameter on F.  If P is a query parameter of F
  2700         -** has no explicit value, then sqlite3_uri_parameter(F,P) returns
  2701         -** a pointer to an empty string.
  2702         -**
  2703         -** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
  2704         -** parameter and returns true (1) or false (0) according to the value
  2705         -** of P.  The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
  2706         -** value of query parameter P is one of "yes", "true", or "on" in any
  2707         -** case or if the value begins with a non-zero number.  The 
  2708         -** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
  2709         -** query parameter P is one of "no", "false", or "off" in any case or
  2710         -** if the value begins with a numeric zero.  If P is not a query
  2711         -** parameter on F or if the value of P is does not match any of the
  2712         -** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
  2713         -**
  2714         -** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
  2715         -** 64-bit signed integer and returns that integer, or D if P does not
  2716         -** exist.  If the value of P is something other than an integer, then
  2717         -** zero is returned.
  2718         -** 
  2719         -** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
  2720         -** sqlite3_uri_boolean(F,P,B) returns B.  If F is not a NULL pointer and
  2721         -** is not a database file pathname pointer that SQLite passed into the xOpen
  2722         -** VFS method, then the behavior of this routine is undefined and probably
  2723         -** undesirable.
  2724         -*/
  2725         -SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  2726         -SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  2727         -SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  2728         -
  2729         -
  2730         -/*
  2731         -** CAPI3REF: Error Codes And Messages
  2732         -**
  2733         -** ^The sqlite3_errcode() interface returns the numeric [result code] or
  2734         -** [extended result code] for the most recent failed sqlite3_* API call
  2735         -** associated with a [database connection]. If a prior API call failed
  2736         -** but the most recent API call succeeded, the return value from
  2737         -** sqlite3_errcode() is undefined.  ^The sqlite3_extended_errcode()
  2738         -** interface is the same except that it always returns the 
  2739         -** [extended result code] even when extended result codes are
  2740         -** disabled.
  2741         -**
  2742         -** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  2743         -** text that describes the error, as either UTF-8 or UTF-16 respectively.
  2744         -** ^(Memory to hold the error message string is managed internally.
  2745         -** The application does not need to worry about freeing the result.
  2746         -** However, the error string might be overwritten or deallocated by
  2747         -** subsequent calls to other SQLite interface functions.)^
  2748         -**
  2749         -** When the serialized [threading mode] is in use, it might be the
  2750         -** case that a second error occurs on a separate thread in between
  2751         -** the time of the first error and the call to these interfaces.
  2752         -** When that happens, the second error will be reported since these
  2753         -** interfaces always report the most recent result.  To avoid
  2754         -** this, each thread can obtain exclusive use of the [database connection] D
  2755         -** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
  2756         -** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
  2757         -** all calls to the interfaces listed here are completed.
  2758         -**
  2759         -** If an interface fails with SQLITE_MISUSE, that means the interface
  2760         -** was invoked incorrectly by the application.  In that case, the
  2761         -** error code and message may or may not be set.
  2762         -*/
  2763         -SQLITE_API int sqlite3_errcode(sqlite3 *db);
  2764         -SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
  2765         -SQLITE_API const char *sqlite3_errmsg(sqlite3*);
  2766         -SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
  2767         -
  2768         -/*
  2769         -** CAPI3REF: SQL Statement Object
  2770         -** KEYWORDS: {prepared statement} {prepared statements}
  2771         -**
  2772         -** An instance of this object represents a single SQL statement.
  2773         -** This object is variously known as a "prepared statement" or a
  2774         -** "compiled SQL statement" or simply as a "statement".
  2775         -**
  2776         -** The life of a statement object goes something like this:
  2777         -**
  2778         -** <ol>
  2779         -** <li> Create the object using [sqlite3_prepare_v2()] or a related
  2780         -**      function.
  2781         -** <li> Bind values to [host parameters] using the sqlite3_bind_*()
  2782         -**      interfaces.
  2783         -** <li> Run the SQL by calling [sqlite3_step()] one or more times.
  2784         -** <li> Reset the statement using [sqlite3_reset()] then go back
  2785         -**      to step 2.  Do this zero or more times.
  2786         -** <li> Destroy the object using [sqlite3_finalize()].
  2787         -** </ol>
  2788         -**
  2789         -** Refer to documentation on individual methods above for additional
  2790         -** information.
  2791         -*/
  2792         -typedef struct sqlite3_stmt sqlite3_stmt;
  2793         -
  2794         -/*
  2795         -** CAPI3REF: Run-time Limits
  2796         -**
  2797         -** ^(This interface allows the size of various constructs to be limited
  2798         -** on a connection by connection basis.  The first parameter is the
  2799         -** [database connection] whose limit is to be set or queried.  The
  2800         -** second parameter is one of the [limit categories] that define a
  2801         -** class of constructs to be size limited.  The third parameter is the
  2802         -** new limit for that construct.)^
  2803         -**
  2804         -** ^If the new limit is a negative number, the limit is unchanged.
  2805         -** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a 
  2806         -** [limits | hard upper bound]
  2807         -** set at compile-time by a C preprocessor macro called
  2808         -** [limits | SQLITE_MAX_<i>NAME</i>].
  2809         -** (The "_LIMIT_" in the name is changed to "_MAX_".))^
  2810         -** ^Attempts to increase a limit above its hard upper bound are
  2811         -** silently truncated to the hard upper bound.
  2812         -**
  2813         -** ^Regardless of whether or not the limit was changed, the 
  2814         -** [sqlite3_limit()] interface returns the prior value of the limit.
  2815         -** ^Hence, to find the current value of a limit without changing it,
  2816         -** simply invoke this interface with the third parameter set to -1.
  2817         -**
  2818         -** Run-time limits are intended for use in applications that manage
  2819         -** both their own internal database and also databases that are controlled
  2820         -** by untrusted external sources.  An example application might be a
  2821         -** web browser that has its own databases for storing history and
  2822         -** separate databases controlled by JavaScript applications downloaded
  2823         -** off the Internet.  The internal databases can be given the
  2824         -** large, default limits.  Databases managed by external sources can
  2825         -** be given much smaller limits designed to prevent a denial of service
  2826         -** attack.  Developers might also want to use the [sqlite3_set_authorizer()]
  2827         -** interface to further control untrusted SQL.  The size of the database
  2828         -** created by an untrusted script can be contained using the
  2829         -** [max_page_count] [PRAGMA].
  2830         -**
  2831         -** New run-time limit categories may be added in future releases.
  2832         -*/
  2833         -SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
  2834         -
  2835         -/*
  2836         -** CAPI3REF: Run-Time Limit Categories
  2837         -** KEYWORDS: {limit category} {*limit categories}
  2838         -**
  2839         -** These constants define various performance limits
  2840         -** that can be lowered at run-time using [sqlite3_limit()].
  2841         -** The synopsis of the meanings of the various limits is shown below.
  2842         -** Additional information is available at [limits | Limits in SQLite].
  2843         -**
  2844         -** <dl>
  2845         -** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
  2846         -** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
  2847         -**
  2848         -** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
  2849         -** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
  2850         -**
  2851         -** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
  2852         -** <dd>The maximum number of columns in a table definition or in the
  2853         -** result set of a [SELECT] or the maximum number of columns in an index
  2854         -** or in an ORDER BY or GROUP BY clause.</dd>)^
  2855         -**
  2856         -** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
  2857         -** <dd>The maximum depth of the parse tree on any expression.</dd>)^
  2858         -**
  2859         -** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
  2860         -** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
  2861         -**
  2862         -** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
  2863         -** <dd>The maximum number of instructions in a virtual machine program
  2864         -** used to implement an SQL statement.  This limit is not currently
  2865         -** enforced, though that might be added in some future release of
  2866         -** SQLite.</dd>)^
  2867         -**
  2868         -** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  2869         -** <dd>The maximum number of arguments on a function.</dd>)^
  2870         -**
  2871         -** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
  2872         -** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
  2873         -**
  2874         -** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
  2875         -** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
  2876         -** <dd>The maximum length of the pattern argument to the [LIKE] or
  2877         -** [GLOB] operators.</dd>)^
  2878         -**
  2879         -** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
  2880         -** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
  2881         -** <dd>The maximum index number of any [parameter] in an SQL statement.)^
  2882         -**
  2883         -** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
  2884         -** <dd>The maximum depth of recursion for triggers.</dd>)^
  2885         -** </dl>
  2886         -*/
  2887         -#define SQLITE_LIMIT_LENGTH                    0
  2888         -#define SQLITE_LIMIT_SQL_LENGTH                1
  2889         -#define SQLITE_LIMIT_COLUMN                    2
  2890         -#define SQLITE_LIMIT_EXPR_DEPTH                3
  2891         -#define SQLITE_LIMIT_COMPOUND_SELECT           4
  2892         -#define SQLITE_LIMIT_VDBE_OP                   5
  2893         -#define SQLITE_LIMIT_FUNCTION_ARG              6
  2894         -#define SQLITE_LIMIT_ATTACHED                  7
  2895         -#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH       8
  2896         -#define SQLITE_LIMIT_VARIABLE_NUMBER           9
  2897         -#define SQLITE_LIMIT_TRIGGER_DEPTH            10
  2898         -
  2899         -/*
  2900         -** CAPI3REF: Compiling An SQL Statement
  2901         -** KEYWORDS: {SQL statement compiler}
  2902         -**
  2903         -** To execute an SQL query, it must first be compiled into a byte-code
  2904         -** program using one of these routines.
  2905         -**
  2906         -** The first argument, "db", is a [database connection] obtained from a
  2907         -** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
  2908         -** [sqlite3_open16()].  The database connection must not have been closed.
  2909         -**
  2910         -** The second argument, "zSql", is the statement to be compiled, encoded
  2911         -** as either UTF-8 or UTF-16.  The sqlite3_prepare() and sqlite3_prepare_v2()
  2912         -** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
  2913         -** use UTF-16.
  2914         -**
  2915         -** ^If the nByte argument is less than zero, then zSql is read up to the
  2916         -** first zero terminator. ^If nByte is non-negative, then it is the maximum
  2917         -** number of  bytes read from zSql.  ^When nByte is non-negative, the
  2918         -** zSql string ends at either the first '\000' or '\u0000' character or
  2919         -** the nByte-th byte, whichever comes first. If the caller knows
  2920         -** that the supplied string is nul-terminated, then there is a small
  2921         -** performance advantage to be gained by passing an nByte parameter that
  2922         -** is equal to the number of bytes in the input string <i>including</i>
  2923         -** the nul-terminator bytes as this saves SQLite from having to
  2924         -** make a copy of the input string.
  2925         -**
  2926         -** ^If pzTail is not NULL then *pzTail is made to point to the first byte
  2927         -** past the end of the first SQL statement in zSql.  These routines only
  2928         -** compile the first statement in zSql, so *pzTail is left pointing to
  2929         -** what remains uncompiled.
  2930         -**
  2931         -** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
  2932         -** executed using [sqlite3_step()].  ^If there is an error, *ppStmt is set
  2933         -** to NULL.  ^If the input text contains no SQL (if the input is an empty
  2934         -** string or a comment) then *ppStmt is set to NULL.
  2935         -** The calling procedure is responsible for deleting the compiled
  2936         -** SQL statement using [sqlite3_finalize()] after it has finished with it.
  2937         -** ppStmt may not be NULL.
  2938         -**
  2939         -** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
  2940         -** otherwise an [error code] is returned.
  2941         -**
  2942         -** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
  2943         -** recommended for all new programs. The two older interfaces are retained
  2944         -** for backwards compatibility, but their use is discouraged.
  2945         -** ^In the "v2" interfaces, the prepared statement
  2946         -** that is returned (the [sqlite3_stmt] object) contains a copy of the
  2947         -** original SQL text. This causes the [sqlite3_step()] interface to
  2948         -** behave differently in three ways:
  2949         -**
  2950         -** <ol>
  2951         -** <li>
  2952         -** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
  2953         -** always used to do, [sqlite3_step()] will automatically recompile the SQL
  2954         -** statement and try to run it again.
  2955         -** </li>
  2956         -**
  2957         -** <li>
  2958         -** ^When an error occurs, [sqlite3_step()] will return one of the detailed
  2959         -** [error codes] or [extended error codes].  ^The legacy behavior was that
  2960         -** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
  2961         -** and the application would have to make a second call to [sqlite3_reset()]
  2962         -** in order to find the underlying cause of the problem. With the "v2" prepare
  2963         -** interfaces, the underlying reason for the error is returned immediately.
  2964         -** </li>
  2965         -**
  2966         -** <li>
  2967         -** ^If the specific value bound to [parameter | host parameter] in the 
  2968         -** WHERE clause might influence the choice of query plan for a statement,
  2969         -** then the statement will be automatically recompiled, as if there had been 
  2970         -** a schema change, on the first  [sqlite3_step()] call following any change
  2971         -** to the [sqlite3_bind_text | bindings] of that [parameter]. 
  2972         -** ^The specific value of WHERE-clause [parameter] might influence the 
  2973         -** choice of query plan if the parameter is the left-hand side of a [LIKE]
  2974         -** or [GLOB] operator or if the parameter is compared to an indexed column
  2975         -** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
  2976         -** the 
  2977         -** </li>
  2978         -** </ol>
  2979         -*/
  2980         -SQLITE_API int sqlite3_prepare(
  2981         -  sqlite3 *db,            /* Database handle */
  2982         -  const char *zSql,       /* SQL statement, UTF-8 encoded */
  2983         -  int nByte,              /* Maximum length of zSql in bytes. */
  2984         -  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  2985         -  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  2986         -);
  2987         -SQLITE_API int sqlite3_prepare_v2(
  2988         -  sqlite3 *db,            /* Database handle */
  2989         -  const char *zSql,       /* SQL statement, UTF-8 encoded */
  2990         -  int nByte,              /* Maximum length of zSql in bytes. */
  2991         -  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  2992         -  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  2993         -);
  2994         -SQLITE_API int sqlite3_prepare16(
  2995         -  sqlite3 *db,            /* Database handle */
  2996         -  const void *zSql,       /* SQL statement, UTF-16 encoded */
  2997         -  int nByte,              /* Maximum length of zSql in bytes. */
  2998         -  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  2999         -  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  3000         -);
  3001         -SQLITE_API int sqlite3_prepare16_v2(
  3002         -  sqlite3 *db,            /* Database handle */
  3003         -  const void *zSql,       /* SQL statement, UTF-16 encoded */
  3004         -  int nByte,              /* Maximum length of zSql in bytes. */
  3005         -  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  3006         -  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  3007         -);
  3008         -
  3009         -/*
  3010         -** CAPI3REF: Retrieving Statement SQL
  3011         -**
  3012         -** ^This interface can be used to retrieve a saved copy of the original
  3013         -** SQL text used to create a [prepared statement] if that statement was
  3014         -** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  3015         -*/
  3016         -SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  3017         -
  3018         -/*
  3019         -** CAPI3REF: Determine If An SQL Statement Writes The Database
  3020         -**
  3021         -** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
  3022         -** and only if the [prepared statement] X makes no direct changes to
  3023         -** the content of the database file.
  3024         -**
  3025         -** Note that [application-defined SQL functions] or
  3026         -** [virtual tables] might change the database indirectly as a side effect.  
  3027         -** ^(For example, if an application defines a function "eval()" that 
  3028         -** calls [sqlite3_exec()], then the following SQL statement would
  3029         -** change the database file through side-effects:
  3030         -**
  3031         -** <blockquote><pre>
  3032         -**    SELECT eval('DELETE FROM t1') FROM t2;
  3033         -** </pre></blockquote>
  3034         -**
  3035         -** But because the [SELECT] statement does not change the database file
  3036         -** directly, sqlite3_stmt_readonly() would still return true.)^
  3037         -**
  3038         -** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
  3039         -** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
  3040         -** since the statements themselves do not actually modify the database but
  3041         -** rather they control the timing of when other statements modify the 
  3042         -** database.  ^The [ATTACH] and [DETACH] statements also cause
  3043         -** sqlite3_stmt_readonly() to return true since, while those statements
  3044         -** change the configuration of a database connection, they do not make 
  3045         -** changes to the content of the database files on disk.
  3046         -*/
  3047         -SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  3048         -
  3049         -/*
  3050         -** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  3051         -**
  3052         -** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  3053         -** [prepared statement] S has been stepped at least once using 
  3054         -** [sqlite3_step(S)] but has not run to completion and/or has not 
  3055         -** been reset using [sqlite3_reset(S)].  ^The sqlite3_stmt_busy(S)
  3056         -** interface returns false if S is a NULL pointer.  If S is not a 
  3057         -** NULL pointer and is not a pointer to a valid [prepared statement]
  3058         -** object, then the behavior is undefined and probably undesirable.
  3059         -**
  3060         -** This interface can be used in combination [sqlite3_next_stmt()]
  3061         -** to locate all prepared statements associated with a database 
  3062         -** connection that are in need of being reset.  This can be used,
  3063         -** for example, in diagnostic routines to search for prepared 
  3064         -** statements that are holding a transaction open.
  3065         -*/
  3066         -SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
  3067         -
  3068         -/*
  3069         -** CAPI3REF: Dynamically Typed Value Object
  3070         -** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  3071         -**
  3072         -** SQLite uses the sqlite3_value object to represent all values
  3073         -** that can be stored in a database table. SQLite uses dynamic typing
  3074         -** for the values it stores.  ^Values stored in sqlite3_value objects
  3075         -** can be integers, floating point values, strings, BLOBs, or NULL.
  3076         -**
  3077         -** An sqlite3_value object may be either "protected" or "unprotected".
  3078         -** Some interfaces require a protected sqlite3_value.  Other interfaces
  3079         -** will accept either a protected or an unprotected sqlite3_value.
  3080         -** Every interface that accepts sqlite3_value arguments specifies
  3081         -** whether or not it requires a protected sqlite3_value.
  3082         -**
  3083         -** The terms "protected" and "unprotected" refer to whether or not
  3084         -** a mutex is held.  An internal mutex is held for a protected
  3085         -** sqlite3_value object but no mutex is held for an unprotected
  3086         -** sqlite3_value object.  If SQLite is compiled to be single-threaded
  3087         -** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
  3088         -** or if SQLite is run in one of reduced mutex modes 
  3089         -** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
  3090         -** then there is no distinction between protected and unprotected
  3091         -** sqlite3_value objects and they can be used interchangeably.  However,
  3092         -** for maximum code portability it is recommended that applications
  3093         -** still make the distinction between protected and unprotected
  3094         -** sqlite3_value objects even when not strictly required.
  3095         -**
  3096         -** ^The sqlite3_value objects that are passed as parameters into the
  3097         -** implementation of [application-defined SQL functions] are protected.
  3098         -** ^The sqlite3_value object returned by
  3099         -** [sqlite3_column_value()] is unprotected.
  3100         -** Unprotected sqlite3_value objects may only be used with
  3101         -** [sqlite3_result_value()] and [sqlite3_bind_value()].
  3102         -** The [sqlite3_value_blob | sqlite3_value_type()] family of
  3103         -** interfaces require protected sqlite3_value objects.
  3104         -*/
  3105         -typedef struct Mem sqlite3_value;
  3106         -
  3107         -/*
  3108         -** CAPI3REF: SQL Function Context Object
  3109         -**
  3110         -** The context in which an SQL function executes is stored in an
  3111         -** sqlite3_context object.  ^A pointer to an sqlite3_context object
  3112         -** is always first parameter to [application-defined SQL functions].
  3113         -** The application-defined SQL function implementation will pass this
  3114         -** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
  3115         -** [sqlite3_aggregate_context()], [sqlite3_user_data()],
  3116         -** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
  3117         -** and/or [sqlite3_set_auxdata()].
  3118         -*/
  3119         -typedef struct sqlite3_context sqlite3_context;
  3120         -
  3121         -/*
  3122         -** CAPI3REF: Binding Values To Prepared Statements
  3123         -** KEYWORDS: {host parameter} {host parameters} {host parameter name}
  3124         -** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
  3125         -**
  3126         -** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
  3127         -** literals may be replaced by a [parameter] that matches one of following
  3128         -** templates:
  3129         -**
  3130         -** <ul>
  3131         -** <li>  ?
  3132         -** <li>  ?NNN
  3133         -** <li>  :VVV
  3134         -** <li>  @VVV
  3135         -** <li>  $VVV
  3136         -** </ul>
  3137         -**
  3138         -** In the templates above, NNN represents an integer literal,
  3139         -** and VVV represents an alphanumeric identifier.)^  ^The values of these
  3140         -** parameters (also called "host parameter names" or "SQL parameters")
  3141         -** can be set using the sqlite3_bind_*() routines defined here.
  3142         -**
  3143         -** ^The first argument to the sqlite3_bind_*() routines is always
  3144         -** a pointer to the [sqlite3_stmt] object returned from
  3145         -** [sqlite3_prepare_v2()] or its variants.
  3146         -**
  3147         -** ^The second argument is the index of the SQL parameter to be set.
  3148         -** ^The leftmost SQL parameter has an index of 1.  ^When the same named
  3149         -** SQL parameter is used more than once, second and subsequent
  3150         -** occurrences have the same index as the first occurrence.
  3151         -** ^The index for named parameters can be looked up using the
  3152         -** [sqlite3_bind_parameter_index()] API if desired.  ^The index
  3153         -** for "?NNN" parameters is the value of NNN.
  3154         -** ^The NNN value must be between 1 and the [sqlite3_limit()]
  3155         -** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
  3156         -**
  3157         -** ^The third argument is the value to bind to the parameter.
  3158         -**
  3159         -** ^(In those routines that have a fourth argument, its value is the
  3160         -** number of bytes in the parameter.  To be clear: the value is the
  3161         -** number of <u>bytes</u> in the value, not the number of characters.)^
  3162         -** ^If the fourth parameter is negative, the length of the string is
  3163         -** the number of bytes up to the first zero terminator.
  3164         -** If a non-negative fourth parameter is provided to sqlite3_bind_text()
  3165         -** or sqlite3_bind_text16() then that parameter must be the byte offset
  3166         -** where the NUL terminator would occur assuming the string were NUL
  3167         -** terminated.  If any NUL characters occur at byte offsets less than 
  3168         -** the value of the fourth parameter then the resulting string value will
  3169         -** contain embedded NULs.  The result of expressions involving strings
  3170         -** with embedded NULs is undefined.
  3171         -**
  3172         -** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
  3173         -** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
  3174         -** string after SQLite has finished with it.  ^The destructor is called
  3175         -** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
  3176         -** sqlite3_bind_text(), or sqlite3_bind_text16() fails.  
  3177         -** ^If the fifth argument is
  3178         -** the special value [SQLITE_STATIC], then SQLite assumes that the
  3179         -** information is in static, unmanaged space and does not need to be freed.
  3180         -** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
  3181         -** SQLite makes its own private copy of the data immediately, before
  3182         -** the sqlite3_bind_*() routine returns.
  3183         -**
  3184         -** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
  3185         -** is filled with zeroes.  ^A zeroblob uses a fixed amount of memory
  3186         -** (just an integer to hold its size) while it is being processed.
  3187         -** Zeroblobs are intended to serve as placeholders for BLOBs whose
  3188         -** content is later written using
  3189         -** [sqlite3_blob_open | incremental BLOB I/O] routines.
  3190         -** ^A negative value for the zeroblob results in a zero-length BLOB.
  3191         -**
  3192         -** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
  3193         -** for the [prepared statement] or with a prepared statement for which
  3194         -** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
  3195         -** then the call will return [SQLITE_MISUSE].  If any sqlite3_bind_()
  3196         -** routine is passed a [prepared statement] that has been finalized, the
  3197         -** result is undefined and probably harmful.
  3198         -**
  3199         -** ^Bindings are not cleared by the [sqlite3_reset()] routine.
  3200         -** ^Unbound parameters are interpreted as NULL.
  3201         -**
  3202         -** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
  3203         -** [error code] if anything goes wrong.
  3204         -** ^[SQLITE_RANGE] is returned if the parameter
  3205         -** index is out of range.  ^[SQLITE_NOMEM] is returned if malloc() fails.
  3206         -**
  3207         -** See also: [sqlite3_bind_parameter_count()],
  3208         -** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  3209         -*/
  3210         -SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  3211         -SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
  3212         -SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
  3213         -SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  3214         -SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
  3215         -SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
  3216         -SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  3217         -SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  3218         -SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  3219         -
  3220         -/*
  3221         -** CAPI3REF: Number Of SQL Parameters
  3222         -**
  3223         -** ^This routine can be used to find the number of [SQL parameters]
  3224         -** in a [prepared statement].  SQL parameters are tokens of the
  3225         -** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
  3226         -** placeholders for values that are [sqlite3_bind_blob | bound]
  3227         -** to the parameters at a later time.
  3228         -**
  3229         -** ^(This routine actually returns the index of the largest (rightmost)
  3230         -** parameter. For all forms except ?NNN, this will correspond to the
  3231         -** number of unique parameters.  If parameters of the ?NNN form are used,
  3232         -** there may be gaps in the list.)^
  3233         -**
  3234         -** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3235         -** [sqlite3_bind_parameter_name()], and
  3236         -** [sqlite3_bind_parameter_index()].
  3237         -*/
  3238         -SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
  3239         -
  3240         -/*
  3241         -** CAPI3REF: Name Of A Host Parameter
  3242         -**
  3243         -** ^The sqlite3_bind_parameter_name(P,N) interface returns
  3244         -** the name of the N-th [SQL parameter] in the [prepared statement] P.
  3245         -** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
  3246         -** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
  3247         -** respectively.
  3248         -** In other words, the initial ":" or "$" or "@" or "?"
  3249         -** is included as part of the name.)^
  3250         -** ^Parameters of the form "?" without a following integer have no name
  3251         -** and are referred to as "nameless" or "anonymous parameters".
  3252         -**
  3253         -** ^The first host parameter has an index of 1, not 0.
  3254         -**
  3255         -** ^If the value N is out of range or if the N-th parameter is
  3256         -** nameless, then NULL is returned.  ^The returned string is
  3257         -** always in UTF-8 encoding even if the named parameter was
  3258         -** originally specified as UTF-16 in [sqlite3_prepare16()] or
  3259         -** [sqlite3_prepare16_v2()].
  3260         -**
  3261         -** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3262         -** [sqlite3_bind_parameter_count()], and
  3263         -** [sqlite3_bind_parameter_index()].
  3264         -*/
  3265         -SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  3266         -
  3267         -/*
  3268         -** CAPI3REF: Index Of A Parameter With A Given Name
  3269         -**
  3270         -** ^Return the index of an SQL parameter given its name.  ^The
  3271         -** index value returned is suitable for use as the second
  3272         -** parameter to [sqlite3_bind_blob|sqlite3_bind()].  ^A zero
  3273         -** is returned if no matching parameter is found.  ^The parameter
  3274         -** name must be given in UTF-8 even if the original statement
  3275         -** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
  3276         -**
  3277         -** See also: [sqlite3_bind_blob|sqlite3_bind()],
  3278         -** [sqlite3_bind_parameter_count()], and
  3279         -** [sqlite3_bind_parameter_index()].
  3280         -*/
  3281         -SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  3282         -
  3283         -/*
  3284         -** CAPI3REF: Reset All Bindings On A Prepared Statement
  3285         -**
  3286         -** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
  3287         -** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  3288         -** ^Use this routine to reset all host parameters to NULL.
  3289         -*/
  3290         -SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
  3291         -
  3292         -/*
  3293         -** CAPI3REF: Number Of Columns In A Result Set
  3294         -**
  3295         -** ^Return the number of columns in the result set returned by the
  3296         -** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
  3297         -** statement that does not return data (for example an [UPDATE]).
  3298         -**
  3299         -** See also: [sqlite3_data_count()]
  3300         -*/
  3301         -SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
  3302         -
  3303         -/*
  3304         -** CAPI3REF: Column Names In A Result Set
  3305         -**
  3306         -** ^These routines return the name assigned to a particular column
  3307         -** in the result set of a [SELECT] statement.  ^The sqlite3_column_name()
  3308         -** interface returns a pointer to a zero-terminated UTF-8 string
  3309         -** and sqlite3_column_name16() returns a pointer to a zero-terminated
  3310         -** UTF-16 string.  ^The first parameter is the [prepared statement]
  3311         -** that implements the [SELECT] statement. ^The second parameter is the
  3312         -** column number.  ^The leftmost column is number 0.
  3313         -**
  3314         -** ^The returned string pointer is valid until either the [prepared statement]
  3315         -** is destroyed by [sqlite3_finalize()] or until the statement is automatically
  3316         -** reprepared by the first call to [sqlite3_step()] for a particular run
  3317         -** or until the next call to
  3318         -** sqlite3_column_name() or sqlite3_column_name16() on the same column.
  3319         -**
  3320         -** ^If sqlite3_malloc() fails during the processing of either routine
  3321         -** (for example during a conversion from UTF-8 to UTF-16) then a
  3322         -** NULL pointer is returned.
  3323         -**
  3324         -** ^The name of a result column is the value of the "AS" clause for
  3325         -** that column, if there is an AS clause.  If there is no AS clause
  3326         -** then the name of the column is unspecified and may change from
  3327         -** one release of SQLite to the next.
  3328         -*/
  3329         -SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
  3330         -SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
  3331         -
  3332         -/*
  3333         -** CAPI3REF: Source Of Data In A Query Result
  3334         -**
  3335         -** ^These routines provide a means to determine the database, table, and
  3336         -** table column that is the origin of a particular result column in
  3337         -** [SELECT] statement.
  3338         -** ^The name of the database or table or column can be returned as
  3339         -** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
  3340         -** the database name, the _table_ routines return the table name, and
  3341         -** the origin_ routines return the column name.
  3342         -** ^The returned string is valid until the [prepared statement] is destroyed
  3343         -** using [sqlite3_finalize()] or until the statement is automatically
  3344         -** reprepared by the first call to [sqlite3_step()] for a particular run
  3345         -** or until the same information is requested
  3346         -** again in a different encoding.
  3347         -**
  3348         -** ^The names returned are the original un-aliased names of the
  3349         -** database, table, and column.
  3350         -**
  3351         -** ^The first argument to these interfaces is a [prepared statement].
  3352         -** ^These functions return information about the Nth result column returned by
  3353         -** the statement, where N is the second function argument.
  3354         -** ^The left-most column is column 0 for these routines.
  3355         -**
  3356         -** ^If the Nth column returned by the statement is an expression or
  3357         -** subquery and is not a column value, then all of these functions return
  3358         -** NULL.  ^These routine might also return NULL if a memory allocation error
  3359         -** occurs.  ^Otherwise, they return the name of the attached database, table,
  3360         -** or column that query result column was extracted from.
  3361         -**
  3362         -** ^As with all other SQLite APIs, those whose names end with "16" return
  3363         -** UTF-16 encoded strings and the other functions return UTF-8.
  3364         -**
  3365         -** ^These APIs are only available if the library was compiled with the
  3366         -** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
  3367         -**
  3368         -** If two or more threads call one or more of these routines against the same
  3369         -** prepared statement and column at the same time then the results are
  3370         -** undefined.
  3371         -**
  3372         -** If two or more threads call one or more
  3373         -** [sqlite3_column_database_name | column metadata interfaces]
  3374         -** for the same [prepared statement] and result column
  3375         -** at the same time then the results are undefined.
  3376         -*/
  3377         -SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  3378         -SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  3379         -SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  3380         -SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  3381         -SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  3382         -SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  3383         -
  3384         -/*
  3385         -** CAPI3REF: Declared Datatype Of A Query Result
  3386         -**
  3387         -** ^(The first parameter is a [prepared statement].
  3388         -** If this statement is a [SELECT] statement and the Nth column of the
  3389         -** returned result set of that [SELECT] is a table column (not an
  3390         -** expression or subquery) then the declared type of the table
  3391         -** column is returned.)^  ^If the Nth column of the result set is an
  3392         -** expression or subquery, then a NULL pointer is returned.
  3393         -** ^The returned string is always UTF-8 encoded.
  3394         -**
  3395         -** ^(For example, given the database schema:
  3396         -**
  3397         -** CREATE TABLE t1(c1 VARIANT);
  3398         -**
  3399         -** and the following statement to be compiled:
  3400         -**
  3401         -** SELECT c1 + 1, c1 FROM t1;
  3402         -**
  3403         -** this routine would return the string "VARIANT" for the second result
  3404         -** column (i==1), and a NULL pointer for the first result column (i==0).)^
  3405         -**
  3406         -** ^SQLite uses dynamic run-time typing.  ^So just because a column
  3407         -** is declared to contain a particular type does not mean that the
  3408         -** data stored in that column is of the declared type.  SQLite is
  3409         -** strongly typed, but the typing is dynamic not static.  ^Type
  3410         -** is associated with individual values, not with the containers
  3411         -** used to hold those values.
  3412         -*/
  3413         -SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
  3414         -SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  3415         -
  3416         -/*
  3417         -** CAPI3REF: Evaluate An SQL Statement
  3418         -**
  3419         -** After a [prepared statement] has been prepared using either
  3420         -** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
  3421         -** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
  3422         -** must be called one or more times to evaluate the statement.
  3423         -**
  3424         -** The details of the behavior of the sqlite3_step() interface depend
  3425         -** on whether the statement was prepared using the newer "v2" interface
  3426         -** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
  3427         -** interface [sqlite3_prepare()] and [sqlite3_prepare16()].  The use of the
  3428         -** new "v2" interface is recommended for new applications but the legacy
  3429         -** interface will continue to be supported.
  3430         -**
  3431         -** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
  3432         -** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  3433         -** ^With the "v2" interface, any of the other [result codes] or
  3434         -** [extended result codes] might be returned as well.
  3435         -**
  3436         -** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
  3437         -** database locks it needs to do its job.  ^If the statement is a [COMMIT]
  3438         -** or occurs outside of an explicit transaction, then you can retry the
  3439         -** statement.  If the statement is not a [COMMIT] and occurs within an
  3440         -** explicit transaction then you should rollback the transaction before
  3441         -** continuing.
  3442         -**
  3443         -** ^[SQLITE_DONE] means that the statement has finished executing
  3444         -** successfully.  sqlite3_step() should not be called again on this virtual
  3445         -** machine without first calling [sqlite3_reset()] to reset the virtual
  3446         -** machine back to its initial state.
  3447         -**
  3448         -** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
  3449         -** is returned each time a new row of data is ready for processing by the
  3450         -** caller. The values may be accessed using the [column access functions].
  3451         -** sqlite3_step() is called again to retrieve the next row of data.
  3452         -**
  3453         -** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
  3454         -** violation) has occurred.  sqlite3_step() should not be called again on
  3455         -** the VM. More information may be found by calling [sqlite3_errmsg()].
  3456         -** ^With the legacy interface, a more specific error code (for example,
  3457         -** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
  3458         -** can be obtained by calling [sqlite3_reset()] on the
  3459         -** [prepared statement].  ^In the "v2" interface,
  3460         -** the more specific error code is returned directly by sqlite3_step().
  3461         -**
  3462         -** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  3463         -** Perhaps it was called on a [prepared statement] that has
  3464         -** already been [sqlite3_finalize | finalized] or on one that had
  3465         -** previously returned [SQLITE_ERROR] or [SQLITE_DONE].  Or it could
  3466         -** be the case that the same database connection is being used by two or
  3467         -** more threads at the same moment in time.
  3468         -**
  3469         -** For all versions of SQLite up to and including 3.6.23.1, a call to
  3470         -** [sqlite3_reset()] was required after sqlite3_step() returned anything
  3471         -** other than [SQLITE_ROW] before any subsequent invocation of
  3472         -** sqlite3_step().  Failure to reset the prepared statement using 
  3473         -** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
  3474         -** sqlite3_step().  But after version 3.6.23.1, sqlite3_step() began
  3475         -** calling [sqlite3_reset()] automatically in this circumstance rather
  3476         -** than returning [SQLITE_MISUSE].  This is not considered a compatibility
  3477         -** break because any application that ever receives an SQLITE_MISUSE error
  3478         -** is broken by definition.  The [SQLITE_OMIT_AUTORESET] compile-time option
  3479         -** can be used to restore the legacy behavior.
  3480         -**
  3481         -** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  3482         -** API always returns a generic error code, [SQLITE_ERROR], following any
  3483         -** error other than [SQLITE_BUSY] and [SQLITE_MISUSE].  You must call
  3484         -** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  3485         -** specific [error codes] that better describes the error.
  3486         -** We admit that this is a goofy design.  The problem has been fixed
  3487         -** with the "v2" interface.  If you prepare all of your SQL statements
  3488         -** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  3489         -** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  3490         -** then the more specific [error codes] are returned directly
  3491         -** by sqlite3_step().  The use of the "v2" interface is recommended.
  3492         -*/
  3493         -SQLITE_API int sqlite3_step(sqlite3_stmt*);
  3494         -
  3495         -/*
  3496         -** CAPI3REF: Number of columns in a result set
  3497         -**
  3498         -** ^The sqlite3_data_count(P) interface returns the number of columns in the
  3499         -** current row of the result set of [prepared statement] P.
  3500         -** ^If prepared statement P does not have results ready to return
  3501         -** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
  3502         -** interfaces) then sqlite3_data_count(P) returns 0.
  3503         -** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
  3504         -** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
  3505         -** [sqlite3_step](P) returned [SQLITE_DONE].  ^The sqlite3_data_count(P)
  3506         -** will return non-zero if previous call to [sqlite3_step](P) returned
  3507         -** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
  3508         -** where it always returns zero since each step of that multi-step
  3509         -** pragma returns 0 columns of data.
  3510         -**
  3511         -** See also: [sqlite3_column_count()]
  3512         -*/
  3513         -SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
  3514         -
  3515         -/*
  3516         -** CAPI3REF: Fundamental Datatypes
  3517         -** KEYWORDS: SQLITE_TEXT
  3518         -**
  3519         -** ^(Every value in SQLite has one of five fundamental datatypes:
  3520         -**
  3521         -** <ul>
  3522         -** <li> 64-bit signed integer
  3523         -** <li> 64-bit IEEE floating point number
  3524         -** <li> string
  3525         -** <li> BLOB
  3526         -** <li> NULL
  3527         -** </ul>)^
  3528         -**
  3529         -** These constants are codes for each of those types.
  3530         -**
  3531         -** Note that the SQLITE_TEXT constant was also used in SQLite version 2
  3532         -** for a completely different meaning.  Software that links against both
  3533         -** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
  3534         -** SQLITE_TEXT.
  3535         -*/
  3536         -#define SQLITE_INTEGER  1
  3537         -#define SQLITE_FLOAT    2
  3538         -#define SQLITE_BLOB     4
  3539         -#define SQLITE_NULL     5
  3540         -#ifdef SQLITE_TEXT
  3541         -# undef SQLITE_TEXT
  3542         -#else
  3543         -# define SQLITE_TEXT     3
  3544         -#endif
  3545         -#define SQLITE3_TEXT     3
  3546         -
  3547         -/*
  3548         -** CAPI3REF: Result Values From A Query
  3549         -** KEYWORDS: {column access functions}
  3550         -**
  3551         -** These routines form the "result set" interface.
  3552         -**
  3553         -** ^These routines return information about a single column of the current
  3554         -** result row of a query.  ^In every case the first argument is a pointer
  3555         -** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  3556         -** that was returned from [sqlite3_prepare_v2()] or one of its variants)
  3557         -** and the second argument is the index of the column for which information
  3558         -** should be returned. ^The leftmost column of the result set has the index 0.
  3559         -** ^The number of columns in the result can be determined using
  3560         -** [sqlite3_column_count()].
  3561         -**
  3562         -** If the SQL statement does not currently point to a valid row, or if the
  3563         -** column index is out of range, the result is undefined.
  3564         -** These routines may only be called when the most recent call to
  3565         -** [sqlite3_step()] has returned [SQLITE_ROW] and neither
  3566         -** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
  3567         -** If any of these routines are called after [sqlite3_reset()] or
  3568         -** [sqlite3_finalize()] or after [sqlite3_step()] has returned
  3569         -** something other than [SQLITE_ROW], the results are undefined.
  3570         -** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
  3571         -** are called from a different thread while any of these routines
  3572         -** are pending, then the results are undefined.
  3573         -**
  3574         -** ^The sqlite3_column_type() routine returns the
  3575         -** [SQLITE_INTEGER | datatype code] for the initial data type
  3576         -** of the result column.  ^The returned value is one of [SQLITE_INTEGER],
  3577         -** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].  The value
  3578         -** returned by sqlite3_column_type() is only meaningful if no type
  3579         -** conversions have occurred as described below.  After a type conversion,
  3580         -** the value returned by sqlite3_column_type() is undefined.  Future
  3581         -** versions of SQLite may change the behavior of sqlite3_column_type()
  3582         -** following a type conversion.
  3583         -**
  3584         -** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  3585         -** routine returns the number of bytes in that BLOB or string.
  3586         -** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  3587         -** the string to UTF-8 and then returns the number of bytes.
  3588         -** ^If the result is a numeric value then sqlite3_column_bytes() uses
  3589         -** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
  3590         -** the number of bytes in that string.
  3591         -** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
  3592         -**
  3593         -** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
  3594         -** routine returns the number of bytes in that BLOB or string.
  3595         -** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
  3596         -** the string to UTF-16 and then returns the number of bytes.
  3597         -** ^If the result is a numeric value then sqlite3_column_bytes16() uses
  3598         -** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
  3599         -** the number of bytes in that string.
  3600         -** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
  3601         -**
  3602         -** ^The values returned by [sqlite3_column_bytes()] and 
  3603         -** [sqlite3_column_bytes16()] do not include the zero terminators at the end
  3604         -** of the string.  ^For clarity: the values returned by
  3605         -** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
  3606         -** bytes in the string, not the number of characters.
  3607         -**
  3608         -** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  3609         -** even empty strings, are always zero-terminated.  ^The return
  3610         -** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
  3611         -**
  3612         -** ^The object returned by [sqlite3_column_value()] is an
  3613         -** [unprotected sqlite3_value] object.  An unprotected sqlite3_value object
  3614         -** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
  3615         -** If the [unprotected sqlite3_value] object returned by
  3616         -** [sqlite3_column_value()] is used in any other way, including calls
  3617         -** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  3618         -** or [sqlite3_value_bytes()], then the behavior is undefined.
  3619         -**
  3620         -** These routines attempt to convert the value where appropriate.  ^For
  3621         -** example, if the internal representation is FLOAT and a text result
  3622         -** is requested, [sqlite3_snprintf()] is used internally to perform the
  3623         -** conversion automatically.  ^(The following table details the conversions
  3624         -** that are applied:
  3625         -**
  3626         -** <blockquote>
  3627         -** <table border="1">
  3628         -** <tr><th> Internal<br>Type <th> Requested<br>Type <th>  Conversion
  3629         -**
  3630         -** <tr><td>  NULL    <td> INTEGER   <td> Result is 0
  3631         -** <tr><td>  NULL    <td>  FLOAT    <td> Result is 0.0
  3632         -** <tr><td>  NULL    <td>   TEXT    <td> Result is NULL pointer
  3633         -** <tr><td>  NULL    <td>   BLOB    <td> Result is NULL pointer
  3634         -** <tr><td> INTEGER  <td>  FLOAT    <td> Convert from integer to float
  3635         -** <tr><td> INTEGER  <td>   TEXT    <td> ASCII rendering of the integer
  3636         -** <tr><td> INTEGER  <td>   BLOB    <td> Same as INTEGER->TEXT
  3637         -** <tr><td>  FLOAT   <td> INTEGER   <td> Convert from float to integer
  3638         -** <tr><td>  FLOAT   <td>   TEXT    <td> ASCII rendering of the float
  3639         -** <tr><td>  FLOAT   <td>   BLOB    <td> Same as FLOAT->TEXT
  3640         -** <tr><td>  TEXT    <td> INTEGER   <td> Use atoi()
  3641         -** <tr><td>  TEXT    <td>  FLOAT    <td> Use atof()
  3642         -** <tr><td>  TEXT    <td>   BLOB    <td> No change
  3643         -** <tr><td>  BLOB    <td> INTEGER   <td> Convert to TEXT then use atoi()
  3644         -** <tr><td>  BLOB    <td>  FLOAT    <td> Convert to TEXT then use atof()
  3645         -** <tr><td>  BLOB    <td>   TEXT    <td> Add a zero terminator if needed
  3646         -** </table>
  3647         -** </blockquote>)^
  3648         -**
  3649         -** The table above makes reference to standard C library functions atoi()
  3650         -** and atof().  SQLite does not really use these functions.  It has its
  3651         -** own equivalent internal routines.  The atoi() and atof() names are
  3652         -** used in the table for brevity and because they are familiar to most
  3653         -** C programmers.
  3654         -**
  3655         -** Note that when type conversions occur, pointers returned by prior
  3656         -** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  3657         -** sqlite3_column_text16() may be invalidated.
  3658         -** Type conversions and pointer invalidations might occur
  3659         -** in the following cases:
  3660         -**
  3661         -** <ul>
  3662         -** <li> The initial content is a BLOB and sqlite3_column_text() or
  3663         -**      sqlite3_column_text16() is called.  A zero-terminator might
  3664         -**      need to be added to the string.</li>
  3665         -** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
  3666         -**      sqlite3_column_text16() is called.  The content must be converted
  3667         -**      to UTF-16.</li>
  3668         -** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
  3669         -**      sqlite3_column_text() is called.  The content must be converted
  3670         -**      to UTF-8.</li>
  3671         -** </ul>
  3672         -**
  3673         -** ^Conversions between UTF-16be and UTF-16le are always done in place and do
  3674         -** not invalidate a prior pointer, though of course the content of the buffer
  3675         -** that the prior pointer references will have been modified.  Other kinds
  3676         -** of conversion are done in place when it is possible, but sometimes they
  3677         -** are not possible and in those cases prior pointers are invalidated.
  3678         -**
  3679         -** The safest and easiest to remember policy is to invoke these routines
  3680         -** in one of the following ways:
  3681         -**
  3682         -** <ul>
  3683         -**  <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  3684         -**  <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  3685         -**  <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  3686         -** </ul>
  3687         -**
  3688         -** In other words, you should call sqlite3_column_text(),
  3689         -** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
  3690         -** into the desired format, then invoke sqlite3_column_bytes() or
  3691         -** sqlite3_column_bytes16() to find the size of the result.  Do not mix calls
  3692         -** to sqlite3_column_text() or sqlite3_column_blob() with calls to
  3693         -** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
  3694         -** with calls to sqlite3_column_bytes().
  3695         -**
  3696         -** ^The pointers returned are valid until a type conversion occurs as
  3697         -** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  3698         -** [sqlite3_finalize()] is called.  ^The memory space used to hold strings
  3699         -** and BLOBs is freed automatically.  Do <b>not</b> pass the pointers returned
  3700         -** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  3701         -** [sqlite3_free()].
  3702         -**
  3703         -** ^(If a memory allocation error occurs during the evaluation of any
  3704         -** of these routines, a default value is returned.  The default value
  3705         -** is either the integer 0, the floating point number 0.0, or a NULL
  3706         -** pointer.  Subsequent calls to [sqlite3_errcode()] will return
  3707         -** [SQLITE_NOMEM].)^
  3708         -*/
  3709         -SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  3710         -SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  3711         -SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  3712         -SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
  3713         -SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
  3714         -SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  3715         -SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  3716         -SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  3717         -SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
  3718         -SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  3719         -
  3720         -/*
  3721         -** CAPI3REF: Destroy A Prepared Statement Object
  3722         -**
  3723         -** ^The sqlite3_finalize() function is called to delete a [prepared statement].
  3724         -** ^If the most recent evaluation of the statement encountered no errors
  3725         -** or if the statement is never been evaluated, then sqlite3_finalize() returns
  3726         -** SQLITE_OK.  ^If the most recent evaluation of statement S failed, then
  3727         -** sqlite3_finalize(S) returns the appropriate [error code] or
  3728         -** [extended error code].
  3729         -**
  3730         -** ^The sqlite3_finalize(S) routine can be called at any point during
  3731         -** the life cycle of [prepared statement] S:
  3732         -** before statement S is ever evaluated, after
  3733         -** one or more calls to [sqlite3_reset()], or after any call
  3734         -** to [sqlite3_step()] regardless of whether or not the statement has
  3735         -** completed execution.
  3736         -**
  3737         -** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
  3738         -**
  3739         -** The application must finalize every [prepared statement] in order to avoid
  3740         -** resource leaks.  It is a grievous error for the application to try to use
  3741         -** a prepared statement after it has been finalized.  Any use of a prepared
  3742         -** statement after it has been finalized can result in undefined and
  3743         -** undesirable behavior such as segfaults and heap corruption.
  3744         -*/
  3745         -SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
  3746         -
  3747         -/*
  3748         -** CAPI3REF: Reset A Prepared Statement Object
  3749         -**
  3750         -** The sqlite3_reset() function is called to reset a [prepared statement]
  3751         -** object back to its initial state, ready to be re-executed.
  3752         -** ^Any SQL statement variables that had values bound to them using
  3753         -** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  3754         -** Use [sqlite3_clear_bindings()] to reset the bindings.
  3755         -**
  3756         -** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
  3757         -** back to the beginning of its program.
  3758         -**
  3759         -** ^If the most recent call to [sqlite3_step(S)] for the
  3760         -** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
  3761         -** or if [sqlite3_step(S)] has never before been called on S,
  3762         -** then [sqlite3_reset(S)] returns [SQLITE_OK].
  3763         -**
  3764         -** ^If the most recent call to [sqlite3_step(S)] for the
  3765         -** [prepared statement] S indicated an error, then
  3766         -** [sqlite3_reset(S)] returns an appropriate [error code].
  3767         -**
  3768         -** ^The [sqlite3_reset(S)] interface does not change the values
  3769         -** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  3770         -*/
  3771         -SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
  3772         -
  3773         -/*
  3774         -** CAPI3REF: Create Or Redefine SQL Functions
  3775         -** KEYWORDS: {function creation routines}
  3776         -** KEYWORDS: {application-defined SQL function}
  3777         -** KEYWORDS: {application-defined SQL functions}
  3778         -**
  3779         -** ^These functions (collectively known as "function creation routines")
  3780         -** are used to add SQL functions or aggregates or to redefine the behavior
  3781         -** of existing SQL functions or aggregates.  The only differences between
  3782         -** these routines are the text encoding expected for
  3783         -** the second parameter (the name of the function being created)
  3784         -** and the presence or absence of a destructor callback for
  3785         -** the application data pointer.
  3786         -**
  3787         -** ^The first parameter is the [database connection] to which the SQL
  3788         -** function is to be added.  ^If an application uses more than one database
  3789         -** connection then application-defined SQL functions must be added
  3790         -** to each database connection separately.
  3791         -**
  3792         -** ^The second parameter is the name of the SQL function to be created or
  3793         -** redefined.  ^The length of the name is limited to 255 bytes in a UTF-8
  3794         -** representation, exclusive of the zero-terminator.  ^Note that the name
  3795         -** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.  
  3796         -** ^Any attempt to create a function with a longer name
  3797         -** will result in [SQLITE_MISUSE] being returned.
  3798         -**
  3799         -** ^The third parameter (nArg)
  3800         -** is the number of arguments that the SQL function or
  3801         -** aggregate takes. ^If this parameter is -1, then the SQL function or
  3802         -** aggregate may take any number of arguments between 0 and the limit
  3803         -** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]).  If the third
  3804         -** parameter is less than -1 or greater than 127 then the behavior is
  3805         -** undefined.
  3806         -**
  3807         -** ^The fourth parameter, eTextRep, specifies what
  3808         -** [SQLITE_UTF8 | text encoding] this SQL function prefers for
  3809         -** its parameters.  Every SQL function implementation must be able to work
  3810         -** with UTF-8, UTF-16le, or UTF-16be.  But some implementations may be
  3811         -** more efficient with one encoding than another.  ^An application may
  3812         -** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
  3813         -** times with the same function but with different values of eTextRep.
  3814         -** ^When multiple implementations of the same function are available, SQLite
  3815         -** will pick the one that involves the least amount of data conversion.
  3816         -** If there is only a single implementation which does not care what text
  3817         -** encoding is used, then the fourth argument should be [SQLITE_ANY].
  3818         -**
  3819         -** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
  3820         -** function can gain access to this pointer using [sqlite3_user_data()].)^
  3821         -**
  3822         -** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
  3823         -** pointers to C-language functions that implement the SQL function or
  3824         -** aggregate. ^A scalar SQL function requires an implementation of the xFunc
  3825         -** callback only; NULL pointers must be passed as the xStep and xFinal
  3826         -** parameters. ^An aggregate SQL function requires an implementation of xStep
  3827         -** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
  3828         -** SQL function or aggregate, pass NULL pointers for all three function
  3829         -** callbacks.
  3830         -**
  3831         -** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
  3832         -** then it is destructor for the application data pointer. 
  3833         -** The destructor is invoked when the function is deleted, either by being
  3834         -** overloaded or when the database connection closes.)^
  3835         -** ^The destructor is also invoked if the call to
  3836         -** sqlite3_create_function_v2() fails.
  3837         -** ^When the destructor callback of the tenth parameter is invoked, it
  3838         -** is passed a single argument which is a copy of the application data 
  3839         -** pointer which was the fifth parameter to sqlite3_create_function_v2().
  3840         -**
  3841         -** ^It is permitted to register multiple implementations of the same
  3842         -** functions with the same name but with either differing numbers of
  3843         -** arguments or differing preferred text encodings.  ^SQLite will use
  3844         -** the implementation that most closely matches the way in which the
  3845         -** SQL function is used.  ^A function implementation with a non-negative
  3846         -** nArg parameter is a better match than a function implementation with
  3847         -** a negative nArg.  ^A function where the preferred text encoding
  3848         -** matches the database encoding is a better
  3849         -** match than a function where the encoding is different.  
  3850         -** ^A function where the encoding difference is between UTF16le and UTF16be
  3851         -** is a closer match than a function where the encoding difference is
  3852         -** between UTF8 and UTF16.
  3853         -**
  3854         -** ^Built-in functions may be overloaded by new application-defined functions.
  3855         -**
  3856         -** ^An application-defined function is permitted to call other
  3857         -** SQLite interfaces.  However, such calls must not
  3858         -** close the database connection nor finalize or reset the prepared
  3859         -** statement in which the function is running.
  3860         -*/
  3861         -SQLITE_API int sqlite3_create_function(
  3862         -  sqlite3 *db,
  3863         -  const char *zFunctionName,
  3864         -  int nArg,
  3865         -  int eTextRep,
  3866         -  void *pApp,
  3867         -  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  3868         -  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  3869         -  void (*xFinal)(sqlite3_context*)
  3870         -);
  3871         -SQLITE_API int sqlite3_create_function16(
  3872         -  sqlite3 *db,
  3873         -  const void *zFunctionName,
  3874         -  int nArg,
  3875         -  int eTextRep,
  3876         -  void *pApp,
  3877         -  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  3878         -  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  3879         -  void (*xFinal)(sqlite3_context*)
  3880         -);
  3881         -SQLITE_API int sqlite3_create_function_v2(
  3882         -  sqlite3 *db,
  3883         -  const char *zFunctionName,
  3884         -  int nArg,
  3885         -  int eTextRep,
  3886         -  void *pApp,
  3887         -  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  3888         -  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  3889         -  void (*xFinal)(sqlite3_context*),
  3890         -  void(*xDestroy)(void*)
  3891         -);
  3892         -
  3893         -/*
  3894         -** CAPI3REF: Text Encodings
  3895         -**
  3896         -** These constant define integer codes that represent the various
  3897         -** text encodings supported by SQLite.
  3898         -*/
  3899         -#define SQLITE_UTF8           1
  3900         -#define SQLITE_UTF16LE        2
  3901         -#define SQLITE_UTF16BE        3
  3902         -#define SQLITE_UTF16          4    /* Use native byte order */
  3903         -#define SQLITE_ANY            5    /* sqlite3_create_function only */
  3904         -#define SQLITE_UTF16_ALIGNED  8    /* sqlite3_create_collation only */
  3905         -
  3906         -/*
  3907         -** CAPI3REF: Deprecated Functions
  3908         -** DEPRECATED
  3909         -**
  3910         -** These functions are [deprecated].  In order to maintain
  3911         -** backwards compatibility with older code, these functions continue 
  3912         -** to be supported.  However, new applications should avoid
  3913         -** the use of these functions.  To help encourage people to avoid
  3914         -** using these functions, we are not going to tell you what they do.
  3915         -*/
  3916         -#ifndef SQLITE_OMIT_DEPRECATED
  3917         -SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
  3918         -SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
  3919         -SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  3920         -SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
  3921         -SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
  3922         -SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
  3923         -#endif
  3924         -
  3925         -/*
  3926         -** CAPI3REF: Obtaining SQL Function Parameter Values
  3927         -**
  3928         -** The C-language implementation of SQL functions and aggregates uses
  3929         -** this set of interface routines to access the parameter values on
  3930         -** the function or aggregate.
  3931         -**
  3932         -** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  3933         -** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  3934         -** define callbacks that implement the SQL functions and aggregates.
  3935         -** The 3rd parameter to these callbacks is an array of pointers to
  3936         -** [protected sqlite3_value] objects.  There is one [sqlite3_value] object for
  3937         -** each parameter to the SQL function.  These routines are used to
  3938         -** extract values from the [sqlite3_value] objects.
  3939         -**
  3940         -** These routines work only with [protected sqlite3_value] objects.
  3941         -** Any attempt to use these routines on an [unprotected sqlite3_value]
  3942         -** object results in undefined behavior.
  3943         -**
  3944         -** ^These routines work just like the corresponding [column access functions]
  3945         -** except that  these routines take a single [protected sqlite3_value] object
  3946         -** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
  3947         -**
  3948         -** ^The sqlite3_value_text16() interface extracts a UTF-16 string
  3949         -** in the native byte-order of the host machine.  ^The
  3950         -** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  3951         -** extract UTF-16 strings as big-endian and little-endian respectively.
  3952         -**
  3953         -** ^(The sqlite3_value_numeric_type() interface attempts to apply
  3954         -** numeric affinity to the value.  This means that an attempt is
  3955         -** made to convert the value to an integer or floating point.  If
  3956         -** such a conversion is possible without loss of information (in other
  3957         -** words, if the value is a string that looks like a number)
  3958         -** then the conversion is performed.  Otherwise no conversion occurs.
  3959         -** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
  3960         -**
  3961         -** Please pay particular attention to the fact that the pointer returned
  3962         -** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  3963         -** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  3964         -** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  3965         -** or [sqlite3_value_text16()].
  3966         -**
  3967         -** These routines must be called from the same thread as
  3968         -** the SQL function that supplied the [sqlite3_value*] parameters.
  3969         -*/
  3970         -SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
  3971         -SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
  3972         -SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
  3973         -SQLITE_API double sqlite3_value_double(sqlite3_value*);
  3974         -SQLITE_API int sqlite3_value_int(sqlite3_value*);
  3975         -SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  3976         -SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
  3977         -SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
  3978         -SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
  3979         -SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
  3980         -SQLITE_API int sqlite3_value_type(sqlite3_value*);
  3981         -SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
  3982         -
  3983         -/*
  3984         -** CAPI3REF: Obtain Aggregate Function Context
  3985         -**
  3986         -** Implementations of aggregate SQL functions use this
  3987         -** routine to allocate memory for storing their state.
  3988         -**
  3989         -** ^The first time the sqlite3_aggregate_context(C,N) routine is called 
  3990         -** for a particular aggregate function, SQLite
  3991         -** allocates N of memory, zeroes out that memory, and returns a pointer
  3992         -** to the new memory. ^On second and subsequent calls to
  3993         -** sqlite3_aggregate_context() for the same aggregate function instance,
  3994         -** the same buffer is returned.  Sqlite3_aggregate_context() is normally
  3995         -** called once for each invocation of the xStep callback and then one
  3996         -** last time when the xFinal callback is invoked.  ^(When no rows match
  3997         -** an aggregate query, the xStep() callback of the aggregate function
  3998         -** implementation is never called and xFinal() is called exactly once.
  3999         -** In those cases, sqlite3_aggregate_context() might be called for the
  4000         -** first time from within xFinal().)^
  4001         -**
  4002         -** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
  4003         -** less than or equal to zero or if a memory allocate error occurs.
  4004         -**
  4005         -** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
  4006         -** determined by the N parameter on first successful call.  Changing the
  4007         -** value of N in subsequent call to sqlite3_aggregate_context() within
  4008         -** the same aggregate function instance will not resize the memory
  4009         -** allocation.)^
  4010         -**
  4011         -** ^SQLite automatically frees the memory allocated by 
  4012         -** sqlite3_aggregate_context() when the aggregate query concludes.
  4013         -**
  4014         -** The first parameter must be a copy of the
  4015         -** [sqlite3_context | SQL function context] that is the first parameter
  4016         -** to the xStep or xFinal callback routine that implements the aggregate
  4017         -** function.
  4018         -**
  4019         -** This routine must be called from the same thread in which
  4020         -** the aggregate SQL function is running.
  4021         -*/
  4022         -SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  4023         -
  4024         -/*
  4025         -** CAPI3REF: User Data For Functions
  4026         -**
  4027         -** ^The sqlite3_user_data() interface returns a copy of
  4028         -** the pointer that was the pUserData parameter (the 5th parameter)
  4029         -** of the [sqlite3_create_function()]
  4030         -** and [sqlite3_create_function16()] routines that originally
  4031         -** registered the application defined function.
  4032         -**
  4033         -** This routine must be called from the same thread in which
  4034         -** the application-defined function is running.
  4035         -*/
  4036         -SQLITE_API void *sqlite3_user_data(sqlite3_context*);
  4037         -
  4038         -/*
  4039         -** CAPI3REF: Database Connection For Functions
  4040         -**
  4041         -** ^The sqlite3_context_db_handle() interface returns a copy of
  4042         -** the pointer to the [database connection] (the 1st parameter)
  4043         -** of the [sqlite3_create_function()]
  4044         -** and [sqlite3_create_function16()] routines that originally
  4045         -** registered the application defined function.
  4046         -*/
  4047         -SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
  4048         -
  4049         -/*
  4050         -** CAPI3REF: Function Auxiliary Data
  4051         -**
  4052         -** The following two functions may be used by scalar SQL functions to
  4053         -** associate metadata with argument values. If the same value is passed to
  4054         -** multiple invocations of the same SQL function during query execution, under
  4055         -** some circumstances the associated metadata may be preserved. This may
  4056         -** be used, for example, to add a regular-expression matching scalar
  4057         -** function. The compiled version of the regular expression is stored as
  4058         -** metadata associated with the SQL value passed as the regular expression
  4059         -** pattern.  The compiled regular expression can be reused on multiple
  4060         -** invocations of the same function so that the original pattern string
  4061         -** does not need to be recompiled on each invocation.
  4062         -**
  4063         -** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
  4064         -** associated by the sqlite3_set_auxdata() function with the Nth argument
  4065         -** value to the application-defined function. ^If no metadata has been ever
  4066         -** been set for the Nth argument of the function, or if the corresponding
  4067         -** function parameter has changed since the meta-data was set,
  4068         -** then sqlite3_get_auxdata() returns a NULL pointer.
  4069         -**
  4070         -** ^The sqlite3_set_auxdata() interface saves the metadata
  4071         -** pointed to by its 3rd parameter as the metadata for the N-th
  4072         -** argument of the application-defined function.  Subsequent
  4073         -** calls to sqlite3_get_auxdata() might return this data, if it has
  4074         -** not been destroyed.
  4075         -** ^If it is not NULL, SQLite will invoke the destructor
  4076         -** function given by the 4th parameter to sqlite3_set_auxdata() on
  4077         -** the metadata when the corresponding function parameter changes
  4078         -** or when the SQL statement completes, whichever comes first.
  4079         -**
  4080         -** SQLite is free to call the destructor and drop metadata on any
  4081         -** parameter of any function at any time.  ^The only guarantee is that
  4082         -** the destructor will be called before the metadata is dropped.
  4083         -**
  4084         -** ^(In practice, metadata is preserved between function calls for
  4085         -** expressions that are constant at compile time. This includes literal
  4086         -** values and [parameters].)^
  4087         -**
  4088         -** These routines must be called from the same thread in which
  4089         -** the SQL function is running.
  4090         -*/
  4091         -SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
  4092         -SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  4093         -
  4094         -
  4095         -/*
  4096         -** CAPI3REF: Constants Defining Special Destructor Behavior
  4097         -**
  4098         -** These are special values for the destructor that is passed in as the
  4099         -** final argument to routines like [sqlite3_result_blob()].  ^If the destructor
  4100         -** argument is SQLITE_STATIC, it means that the content pointer is constant
  4101         -** and will never change.  It does not need to be destroyed.  ^The
  4102         -** SQLITE_TRANSIENT value means that the content will likely change in
  4103         -** the near future and that SQLite should make its own private copy of
  4104         -** the content before returning.
  4105         -**
  4106         -** The typedef is necessary to work around problems in certain
  4107         -** C++ compilers.  See ticket #2191.
  4108         -*/
  4109         -typedef void (*sqlite3_destructor_type)(void*);
  4110         -#define SQLITE_STATIC      ((sqlite3_destructor_type)0)
  4111         -#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
  4112         -
  4113         -/*
  4114         -** CAPI3REF: Setting The Result Of An SQL Function
  4115         -**
  4116         -** These routines are used by the xFunc or xFinal callbacks that
  4117         -** implement SQL functions and aggregates.  See
  4118         -** [sqlite3_create_function()] and [sqlite3_create_function16()]
  4119         -** for additional information.
  4120         -**
  4121         -** These functions work very much like the [parameter binding] family of
  4122         -** functions used to bind values to host parameters in prepared statements.
  4123         -** Refer to the [SQL parameter] documentation for additional information.
  4124         -**
  4125         -** ^The sqlite3_result_blob() interface sets the result from
  4126         -** an application-defined function to be the BLOB whose content is pointed
  4127         -** to by the second parameter and which is N bytes long where N is the
  4128         -** third parameter.
  4129         -**
  4130         -** ^The sqlite3_result_zeroblob() interfaces set the result of
  4131         -** the application-defined function to be a BLOB containing all zero
  4132         -** bytes and N bytes in size, where N is the value of the 2nd parameter.
  4133         -**
  4134         -** ^The sqlite3_result_double() interface sets the result from
  4135         -** an application-defined function to be a floating point value specified
  4136         -** by its 2nd argument.
  4137         -**
  4138         -** ^The sqlite3_result_error() and sqlite3_result_error16() functions
  4139         -** cause the implemented SQL function to throw an exception.
  4140         -** ^SQLite uses the string pointed to by the
  4141         -** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
  4142         -** as the text of an error message.  ^SQLite interprets the error
  4143         -** message string from sqlite3_result_error() as UTF-8. ^SQLite
  4144         -** interprets the string from sqlite3_result_error16() as UTF-16 in native
  4145         -** byte order.  ^If the third parameter to sqlite3_result_error()
  4146         -** or sqlite3_result_error16() is negative then SQLite takes as the error
  4147         -** message all text up through the first zero character.
  4148         -** ^If the third parameter to sqlite3_result_error() or
  4149         -** sqlite3_result_error16() is non-negative then SQLite takes that many
  4150         -** bytes (not characters) from the 2nd parameter as the error message.
  4151         -** ^The sqlite3_result_error() and sqlite3_result_error16()
  4152         -** routines make a private copy of the error message text before
  4153         -** they return.  Hence, the calling function can deallocate or
  4154         -** modify the text after they return without harm.
  4155         -** ^The sqlite3_result_error_code() function changes the error code
  4156         -** returned by SQLite as a result of an error in a function.  ^By default,
  4157         -** the error code is SQLITE_ERROR.  ^A subsequent call to sqlite3_result_error()
  4158         -** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  4159         -**
  4160         -** ^The sqlite3_result_toobig() interface causes SQLite to throw an error
  4161         -** indicating that a string or BLOB is too long to represent.
  4162         -**
  4163         -** ^The sqlite3_result_nomem() interface causes SQLite to throw an error
  4164         -** indicating that a memory allocation failed.
  4165         -**
  4166         -** ^The sqlite3_result_int() interface sets the return value
  4167         -** of the application-defined function to be the 32-bit signed integer
  4168         -** value given in the 2nd argument.
  4169         -** ^The sqlite3_result_int64() interface sets the return value
  4170         -** of the application-defined function to be the 64-bit signed integer
  4171         -** value given in the 2nd argument.
  4172         -**
  4173         -** ^The sqlite3_result_null() interface sets the return value
  4174         -** of the application-defined function to be NULL.
  4175         -**
  4176         -** ^The sqlite3_result_text(), sqlite3_result_text16(),
  4177         -** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
  4178         -** set the return value of the application-defined function to be
  4179         -** a text string which is represented as UTF-8, UTF-16 native byte order,
  4180         -** UTF-16 little endian, or UTF-16 big endian, respectively.
  4181         -** ^SQLite takes the text result from the application from
  4182         -** the 2nd parameter of the sqlite3_result_text* interfaces.
  4183         -** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  4184         -** is negative, then SQLite takes result text from the 2nd parameter
  4185         -** through the first zero character.
  4186         -** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  4187         -** is non-negative, then as many bytes (not characters) of the text
  4188         -** pointed to by the 2nd parameter are taken as the application-defined
  4189         -** function result.  If the 3rd parameter is non-negative, then it
  4190         -** must be the byte offset into the string where the NUL terminator would
  4191         -** appear if the string where NUL terminated.  If any NUL characters occur
  4192         -** in the string at a byte offset that is less than the value of the 3rd
  4193         -** parameter, then the resulting string will contain embedded NULs and the
  4194         -** result of expressions operating on strings with embedded NULs is undefined.
  4195         -** ^If the 4th parameter to the sqlite3_result_text* interfaces
  4196         -** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
  4197         -** function as the destructor on the text or BLOB result when it has
  4198         -** finished using that result.
  4199         -** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
  4200         -** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
  4201         -** assumes that the text or BLOB result is in constant space and does not
  4202         -** copy the content of the parameter nor call a destructor on the content
  4203         -** when it has finished using that result.
  4204         -** ^If the 4th parameter to the sqlite3_result_text* interfaces
  4205         -** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  4206         -** then SQLite makes a copy of the result into space obtained from
  4207         -** from [sqlite3_malloc()] before it returns.
  4208         -**
  4209         -** ^The sqlite3_result_value() interface sets the result of
  4210         -** the application-defined function to be a copy the
  4211         -** [unprotected sqlite3_value] object specified by the 2nd parameter.  ^The
  4212         -** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
  4213         -** so that the [sqlite3_value] specified in the parameter may change or
  4214         -** be deallocated after sqlite3_result_value() returns without harm.
  4215         -** ^A [protected sqlite3_value] object may always be used where an
  4216         -** [unprotected sqlite3_value] object is required, so either
  4217         -** kind of [sqlite3_value] object can be used with this interface.
  4218         -**
  4219         -** If these routines are called from within the different thread
  4220         -** than the one containing the application-defined function that received
  4221         -** the [sqlite3_context] pointer, the results are undefined.
  4222         -*/
  4223         -SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  4224         -SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
  4225         -SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
  4226         -SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
  4227         -SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
  4228         -SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
  4229         -SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
  4230         -SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
  4231         -SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  4232         -SQLITE_API void sqlite3_result_null(sqlite3_context*);
  4233         -SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  4234         -SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  4235         -SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  4236         -SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  4237         -SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  4238         -SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
  4239         -
  4240         -/*
  4241         -** CAPI3REF: Define New Collating Sequences
  4242         -**
  4243         -** ^These functions add, remove, or modify a [collation] associated
  4244         -** with the [database connection] specified as the first argument.
  4245         -**
  4246         -** ^The name of the collation is a UTF-8 string
  4247         -** for sqlite3_create_collation() and sqlite3_create_collation_v2()
  4248         -** and a UTF-16 string in native byte order for sqlite3_create_collation16().
  4249         -** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
  4250         -** considered to be the same name.
  4251         -**
  4252         -** ^(The third argument (eTextRep) must be one of the constants:
  4253         -** <ul>
  4254         -** <li> [SQLITE_UTF8],
  4255         -** <li> [SQLITE_UTF16LE],
  4256         -** <li> [SQLITE_UTF16BE],
  4257         -** <li> [SQLITE_UTF16], or
  4258         -** <li> [SQLITE_UTF16_ALIGNED].
  4259         -** </ul>)^
  4260         -** ^The eTextRep argument determines the encoding of strings passed
  4261         -** to the collating function callback, xCallback.
  4262         -** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
  4263         -** force strings to be UTF16 with native byte order.
  4264         -** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
  4265         -** on an even byte address.
  4266         -**
  4267         -** ^The fourth argument, pArg, is an application data pointer that is passed
  4268         -** through as the first argument to the collating function callback.
  4269         -**
  4270         -** ^The fifth argument, xCallback, is a pointer to the collating function.
  4271         -** ^Multiple collating functions can be registered using the same name but
  4272         -** with different eTextRep parameters and SQLite will use whichever
  4273         -** function requires the least amount of data transformation.
  4274         -** ^If the xCallback argument is NULL then the collating function is
  4275         -** deleted.  ^When all collating functions having the same name are deleted,
  4276         -** that collation is no longer usable.
  4277         -**
  4278         -** ^The collating function callback is invoked with a copy of the pArg 
  4279         -** application data pointer and with two strings in the encoding specified
  4280         -** by the eTextRep argument.  The collating function must return an
  4281         -** integer that is negative, zero, or positive
  4282         -** if the first string is less than, equal to, or greater than the second,
  4283         -** respectively.  A collating function must always return the same answer
  4284         -** given the same inputs.  If two or more collating functions are registered
  4285         -** to the same collation name (using different eTextRep values) then all
  4286         -** must give an equivalent answer when invoked with equivalent strings.
  4287         -** The collating function must obey the following properties for all
  4288         -** strings A, B, and C:
  4289         -**
  4290         -** <ol>
  4291         -** <li> If A==B then B==A.
  4292         -** <li> If A==B and B==C then A==C.
  4293         -** <li> If A&lt;B THEN B&gt;A.
  4294         -** <li> If A&lt;B and B&lt;C then A&lt;C.
  4295         -** </ol>
  4296         -**
  4297         -** If a collating function fails any of the above constraints and that
  4298         -** collating function is  registered and used, then the behavior of SQLite
  4299         -** is undefined.
  4300         -**
  4301         -** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
  4302         -** with the addition that the xDestroy callback is invoked on pArg when
  4303         -** the collating function is deleted.
  4304         -** ^Collating functions are deleted when they are overridden by later
  4305         -** calls to the collation creation functions or when the
  4306         -** [database connection] is closed using [sqlite3_close()].
  4307         -**
  4308         -** ^The xDestroy callback is <u>not</u> called if the 
  4309         -** sqlite3_create_collation_v2() function fails.  Applications that invoke
  4310         -** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should 
  4311         -** check the return code and dispose of the application data pointer
  4312         -** themselves rather than expecting SQLite to deal with it for them.
  4313         -** This is different from every other SQLite interface.  The inconsistency 
  4314         -** is unfortunate but cannot be changed without breaking backwards 
  4315         -** compatibility.
  4316         -**
  4317         -** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
  4318         -*/
  4319         -SQLITE_API int sqlite3_create_collation(
  4320         -  sqlite3*, 
  4321         -  const char *zName, 
  4322         -  int eTextRep, 
  4323         -  void *pArg,
  4324         -  int(*xCompare)(void*,int,const void*,int,const void*)
  4325         -);
  4326         -SQLITE_API int sqlite3_create_collation_v2(
  4327         -  sqlite3*, 
  4328         -  const char *zName, 
  4329         -  int eTextRep, 
  4330         -  void *pArg,
  4331         -  int(*xCompare)(void*,int,const void*,int,const void*),
  4332         -  void(*xDestroy)(void*)
  4333         -);
  4334         -SQLITE_API int sqlite3_create_collation16(
  4335         -  sqlite3*, 
  4336         -  const void *zName,
  4337         -  int eTextRep, 
  4338         -  void *pArg,
  4339         -  int(*xCompare)(void*,int,const void*,int,const void*)
  4340         -);
  4341         -
  4342         -/*
  4343         -** CAPI3REF: Collation Needed Callbacks
  4344         -**
  4345         -** ^To avoid having to register all collation sequences before a database
  4346         -** can be used, a single callback function may be registered with the
  4347         -** [database connection] to be invoked whenever an undefined collation
  4348         -** sequence is required.
  4349         -**
  4350         -** ^If the function is registered using the sqlite3_collation_needed() API,
  4351         -** then it is passed the names of undefined collation sequences as strings
  4352         -** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
  4353         -** the names are passed as UTF-16 in machine native byte order.
  4354         -** ^A call to either function replaces the existing collation-needed callback.
  4355         -**
  4356         -** ^(When the callback is invoked, the first argument passed is a copy
  4357         -** of the second argument to sqlite3_collation_needed() or
  4358         -** sqlite3_collation_needed16().  The second argument is the database
  4359         -** connection.  The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
  4360         -** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
  4361         -** sequence function required.  The fourth parameter is the name of the
  4362         -** required collation sequence.)^
  4363         -**
  4364         -** The callback function should register the desired collation using
  4365         -** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  4366         -** [sqlite3_create_collation_v2()].
  4367         -*/
  4368         -SQLITE_API int sqlite3_collation_needed(
  4369         -  sqlite3*, 
  4370         -  void*, 
  4371         -  void(*)(void*,sqlite3*,int eTextRep,const char*)
  4372         -);
  4373         -SQLITE_API int sqlite3_collation_needed16(
  4374         -  sqlite3*, 
  4375         -  void*,
  4376         -  void(*)(void*,sqlite3*,int eTextRep,const void*)
  4377         -);
  4378         -
  4379         -#ifdef SQLITE_HAS_CODEC
  4380         -/*
  4381         -** Specify the key for an encrypted database.  This routine should be
  4382         -** called right after sqlite3_open().
  4383         -**
  4384         -** The code to implement this API is not available in the public release
  4385         -** of SQLite.
  4386         -*/
  4387         -SQLITE_API int sqlite3_key(
  4388         -  sqlite3 *db,                   /* Database to be rekeyed */
  4389         -  const void *pKey, int nKey     /* The key */
  4390         -);
  4391         -
  4392         -/*
  4393         -** Change the key on an open database.  If the current database is not
  4394         -** encrypted, this routine will encrypt it.  If pNew==0 or nNew==0, the
  4395         -** database is decrypted.
  4396         -**
  4397         -** The code to implement this API is not available in the public release
  4398         -** of SQLite.
  4399         -*/
  4400         -SQLITE_API int sqlite3_rekey(
  4401         -  sqlite3 *db,                   /* Database to be rekeyed */
  4402         -  const void *pKey, int nKey     /* The new key */
  4403         -);
  4404         -
  4405         -/*
  4406         -** Specify the activation key for a SEE database.  Unless 
  4407         -** activated, none of the SEE routines will work.
  4408         -*/
  4409         -SQLITE_API void sqlite3_activate_see(
  4410         -  const char *zPassPhrase        /* Activation phrase */
  4411         -);
  4412         -#endif
  4413         -
  4414         -#ifdef SQLITE_ENABLE_CEROD
  4415         -/*
  4416         -** Specify the activation key for a CEROD database.  Unless 
  4417         -** activated, none of the CEROD routines will work.
  4418         -*/
  4419         -SQLITE_API void sqlite3_activate_cerod(
  4420         -  const char *zPassPhrase        /* Activation phrase */
  4421         -);
  4422         -#endif
  4423         -
  4424         -/*
  4425         -** CAPI3REF: Suspend Execution For A Short Time
  4426         -**
  4427         -** The sqlite3_sleep() function causes the current thread to suspend execution
  4428         -** for at least a number of milliseconds specified in its parameter.
  4429         -**
  4430         -** If the operating system does not support sleep requests with
  4431         -** millisecond time resolution, then the time will be rounded up to
  4432         -** the nearest second. The number of milliseconds of sleep actually
  4433         -** requested from the operating system is returned.
  4434         -**
  4435         -** ^SQLite implements this interface by calling the xSleep()
  4436         -** method of the default [sqlite3_vfs] object.  If the xSleep() method
  4437         -** of the default VFS is not implemented correctly, or not implemented at
  4438         -** all, then the behavior of sqlite3_sleep() may deviate from the description
  4439         -** in the previous paragraphs.
  4440         -*/
  4441         -SQLITE_API int sqlite3_sleep(int);
  4442         -
  4443         -/*
  4444         -** CAPI3REF: Name Of The Folder Holding Temporary Files
  4445         -**
  4446         -** ^(If this global variable is made to point to a string which is
  4447         -** the name of a folder (a.k.a. directory), then all temporary files
  4448         -** created by SQLite when using a built-in [sqlite3_vfs | VFS]
  4449         -** will be placed in that directory.)^  ^If this variable
  4450         -** is a NULL pointer, then SQLite performs a search for an appropriate
  4451         -** temporary file directory.
  4452         -**
  4453         -** It is not safe to read or modify this variable in more than one
  4454         -** thread at a time.  It is not safe to read or modify this variable
  4455         -** if a [database connection] is being used at the same time in a separate
  4456         -** thread.
  4457         -** It is intended that this variable be set once
  4458         -** as part of process initialization and before any SQLite interface
  4459         -** routines have been called and that this variable remain unchanged
  4460         -** thereafter.
  4461         -**
  4462         -** ^The [temp_store_directory pragma] may modify this variable and cause
  4463         -** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
  4464         -** the [temp_store_directory pragma] always assumes that any string
  4465         -** that this variable points to is held in memory obtained from 
  4466         -** [sqlite3_malloc] and the pragma may attempt to free that memory
  4467         -** using [sqlite3_free].
  4468         -** Hence, if this variable is modified directly, either it should be
  4469         -** made NULL or made to point to memory obtained from [sqlite3_malloc]
  4470         -** or else the use of the [temp_store_directory pragma] should be avoided.
  4471         -*/
  4472         -SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
  4473         -
  4474         -/*
  4475         -** CAPI3REF: Name Of The Folder Holding Database Files
  4476         -**
  4477         -** ^(If this global variable is made to point to a string which is
  4478         -** the name of a folder (a.k.a. directory), then all database files
  4479         -** specified with a relative pathname and created or accessed by
  4480         -** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
  4481         -** to be relative to that directory.)^ ^If this variable is a NULL
  4482         -** pointer, then SQLite assumes that all database files specified
  4483         -** with a relative pathname are relative to the current directory
  4484         -** for the process.  Only the windows VFS makes use of this global
  4485         -** variable; it is ignored by the unix VFS.
  4486         -**
  4487         -** Changing the value of this variable while a database connection is
  4488         -** open can result in a corrupt database.
  4489         -**
  4490         -** It is not safe to read or modify this variable in more than one
  4491         -** thread at a time.  It is not safe to read or modify this variable
  4492         -** if a [database connection] is being used at the same time in a separate
  4493         -** thread.
  4494         -** It is intended that this variable be set once
  4495         -** as part of process initialization and before any SQLite interface
  4496         -** routines have been called and that this variable remain unchanged
  4497         -** thereafter.
  4498         -**
  4499         -** ^The [data_store_directory pragma] may modify this variable and cause
  4500         -** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
  4501         -** the [data_store_directory pragma] always assumes that any string
  4502         -** that this variable points to is held in memory obtained from 
  4503         -** [sqlite3_malloc] and the pragma may attempt to free that memory
  4504         -** using [sqlite3_free].
  4505         -** Hence, if this variable is modified directly, either it should be
  4506         -** made NULL or made to point to memory obtained from [sqlite3_malloc]
  4507         -** or else the use of the [data_store_directory pragma] should be avoided.
  4508         -*/
  4509         -SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
  4510         -
  4511         -/*
  4512         -** CAPI3REF: Test For Auto-Commit Mode
  4513         -** KEYWORDS: {autocommit mode}
  4514         -**
  4515         -** ^The sqlite3_get_autocommit() interface returns non-zero or
  4516         -** zero if the given database connection is or is not in autocommit mode,
  4517         -** respectively.  ^Autocommit mode is on by default.
  4518         -** ^Autocommit mode is disabled by a [BEGIN] statement.
  4519         -** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
  4520         -**
  4521         -** If certain kinds of errors occur on a statement within a multi-statement
  4522         -** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
  4523         -** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
  4524         -** transaction might be rolled back automatically.  The only way to
  4525         -** find out whether SQLite automatically rolled back the transaction after
  4526         -** an error is to use this function.
  4527         -**
  4528         -** If another thread changes the autocommit status of the database
  4529         -** connection while this routine is running, then the return value
  4530         -** is undefined.
  4531         -*/
  4532         -SQLITE_API int sqlite3_get_autocommit(sqlite3*);
  4533         -
  4534         -/*
  4535         -** CAPI3REF: Find The Database Handle Of A Prepared Statement
  4536         -**
  4537         -** ^The sqlite3_db_handle interface returns the [database connection] handle
  4538         -** to which a [prepared statement] belongs.  ^The [database connection]
  4539         -** returned by sqlite3_db_handle is the same [database connection]
  4540         -** that was the first argument
  4541         -** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  4542         -** create the statement in the first place.
  4543         -*/
  4544         -SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  4545         -
  4546         -/*
  4547         -** CAPI3REF: Return The Filename For A Database Connection
  4548         -**
  4549         -** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
  4550         -** associated with database N of connection D.  ^The main database file
  4551         -** has the name "main".  If there is no attached database N on the database
  4552         -** connection D, or if database N is a temporary or in-memory database, then
  4553         -** a NULL pointer is returned.
  4554         -**
  4555         -** ^The filename returned by this function is the output of the
  4556         -** xFullPathname method of the [VFS].  ^In other words, the filename
  4557         -** will be an absolute pathname, even if the filename used
  4558         -** to open the database originally was a URI or relative pathname.
  4559         -*/
  4560         -SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
  4561         -
  4562         -/*
  4563         -** CAPI3REF: Determine if a database is read-only
  4564         -**
  4565         -** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
  4566         -** of connection D is read-only, 0 if it is read/write, or -1 if N is not
  4567         -** the name of a database on connection D.
  4568         -*/
  4569         -SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
  4570         -
  4571         -/*
  4572         -** CAPI3REF: Find the next prepared statement
  4573         -**
  4574         -** ^This interface returns a pointer to the next [prepared statement] after
  4575         -** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
  4576         -** then this interface returns a pointer to the first prepared statement
  4577         -** associated with the database connection pDb.  ^If no prepared statement
  4578         -** satisfies the conditions of this routine, it returns NULL.
  4579         -**
  4580         -** The [database connection] pointer D in a call to
  4581         -** [sqlite3_next_stmt(D,S)] must refer to an open database
  4582         -** connection and in particular must not be a NULL pointer.
  4583         -*/
  4584         -SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  4585         -
  4586         -/*
  4587         -** CAPI3REF: Commit And Rollback Notification Callbacks
  4588         -**
  4589         -** ^The sqlite3_commit_hook() interface registers a callback
  4590         -** function to be invoked whenever a transaction is [COMMIT | committed].
  4591         -** ^Any callback set by a previous call to sqlite3_commit_hook()
  4592         -** for the same database connection is overridden.
  4593         -** ^The sqlite3_rollback_hook() interface registers a callback
  4594         -** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
  4595         -** ^Any callback set by a previous call to sqlite3_rollback_hook()
  4596         -** for the same database connection is overridden.
  4597         -** ^The pArg argument is passed through to the callback.
  4598         -** ^If the callback on a commit hook function returns non-zero,
  4599         -** then the commit is converted into a rollback.
  4600         -**
  4601         -** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
  4602         -** return the P argument from the previous call of the same function
  4603         -** on the same [database connection] D, or NULL for
  4604         -** the first call for each function on D.
  4605         -**
  4606         -** The commit and rollback hook callbacks are not reentrant.
  4607         -** The callback implementation must not do anything that will modify
  4608         -** the database connection that invoked the callback.  Any actions
  4609         -** to modify the database connection must be deferred until after the
  4610         -** completion of the [sqlite3_step()] call that triggered the commit
  4611         -** or rollback hook in the first place.
  4612         -** Note that running any other SQL statements, including SELECT statements,
  4613         -** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
  4614         -** the database connections for the meaning of "modify" in this paragraph.
  4615         -**
  4616         -** ^Registering a NULL function disables the callback.
  4617         -**
  4618         -** ^When the commit hook callback routine returns zero, the [COMMIT]
  4619         -** operation is allowed to continue normally.  ^If the commit hook
  4620         -** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
  4621         -** ^The rollback hook is invoked on a rollback that results from a commit
  4622         -** hook returning non-zero, just as it would be with any other rollback.
  4623         -**
  4624         -** ^For the purposes of this API, a transaction is said to have been
  4625         -** rolled back if an explicit "ROLLBACK" statement is executed, or
  4626         -** an error or constraint causes an implicit rollback to occur.
  4627         -** ^The rollback callback is not invoked if a transaction is
  4628         -** automatically rolled back because the database connection is closed.
  4629         -**
  4630         -** See also the [sqlite3_update_hook()] interface.
  4631         -*/
  4632         -SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  4633         -SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  4634         -
  4635         -/*
  4636         -** CAPI3REF: Data Change Notification Callbacks
  4637         -**
  4638         -** ^The sqlite3_update_hook() interface registers a callback function
  4639         -** with the [database connection] identified by the first argument
  4640         -** to be invoked whenever a row is updated, inserted or deleted.
  4641         -** ^Any callback set by a previous call to this function
  4642         -** for the same database connection is overridden.
  4643         -**
  4644         -** ^The second argument is a pointer to the function to invoke when a
  4645         -** row is updated, inserted or deleted.
  4646         -** ^The first argument to the callback is a copy of the third argument
  4647         -** to sqlite3_update_hook().
  4648         -** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
  4649         -** or [SQLITE_UPDATE], depending on the operation that caused the callback
  4650         -** to be invoked.
  4651         -** ^The third and fourth arguments to the callback contain pointers to the
  4652         -** database and table name containing the affected row.
  4653         -** ^The final callback parameter is the [rowid] of the row.
  4654         -** ^In the case of an update, this is the [rowid] after the update takes place.
  4655         -**
  4656         -** ^(The update hook is not invoked when internal system tables are
  4657         -** modified (i.e. sqlite_master and sqlite_sequence).)^
  4658         -**
  4659         -** ^In the current implementation, the update hook
  4660         -** is not invoked when duplication rows are deleted because of an
  4661         -** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
  4662         -** invoked when rows are deleted using the [truncate optimization].
  4663         -** The exceptions defined in this paragraph might change in a future
  4664         -** release of SQLite.
  4665         -**
  4666         -** The update hook implementation must not do anything that will modify
  4667         -** the database connection that invoked the update hook.  Any actions
  4668         -** to modify the database connection must be deferred until after the
  4669         -** completion of the [sqlite3_step()] call that triggered the update hook.
  4670         -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  4671         -** database connections for the meaning of "modify" in this paragraph.
  4672         -**
  4673         -** ^The sqlite3_update_hook(D,C,P) function
  4674         -** returns the P argument from the previous call
  4675         -** on the same [database connection] D, or NULL for
  4676         -** the first call on D.
  4677         -**
  4678         -** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()]
  4679         -** interfaces.
  4680         -*/
  4681         -SQLITE_API void *sqlite3_update_hook(
  4682         -  sqlite3*, 
  4683         -  void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  4684         -  void*
  4685         -);
  4686         -
  4687         -/*
  4688         -** CAPI3REF: Enable Or Disable Shared Pager Cache
  4689         -**
  4690         -** ^(This routine enables or disables the sharing of the database cache
  4691         -** and schema data structures between [database connection | connections]
  4692         -** to the same database. Sharing is enabled if the argument is true
  4693         -** and disabled if the argument is false.)^
  4694         -**
  4695         -** ^Cache sharing is enabled and disabled for an entire process.
  4696         -** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
  4697         -** sharing was enabled or disabled for each thread separately.
  4698         -**
  4699         -** ^(The cache sharing mode set by this interface effects all subsequent
  4700         -** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
  4701         -** Existing database connections continue use the sharing mode
  4702         -** that was in effect at the time they were opened.)^
  4703         -**
  4704         -** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
  4705         -** successfully.  An [error code] is returned otherwise.)^
  4706         -**
  4707         -** ^Shared cache is disabled by default. But this might change in
  4708         -** future releases of SQLite.  Applications that care about shared
  4709         -** cache setting should set it explicitly.
  4710         -**
  4711         -** See Also:  [SQLite Shared-Cache Mode]
  4712         -*/
  4713         -SQLITE_API int sqlite3_enable_shared_cache(int);
  4714         -
  4715         -/*
  4716         -** CAPI3REF: Attempt To Free Heap Memory
  4717         -**
  4718         -** ^The sqlite3_release_memory() interface attempts to free N bytes
  4719         -** of heap memory by deallocating non-essential memory allocations
  4720         -** held by the database library.   Memory used to cache database
  4721         -** pages to improve performance is an example of non-essential memory.
  4722         -** ^sqlite3_release_memory() returns the number of bytes actually freed,
  4723         -** which might be more or less than the amount requested.
  4724         -** ^The sqlite3_release_memory() routine is a no-op returning zero
  4725         -** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  4726         -**
  4727         -** See also: [sqlite3_db_release_memory()]
  4728         -*/
  4729         -SQLITE_API int sqlite3_release_memory(int);
  4730         -
  4731         -/*
  4732         -** CAPI3REF: Free Memory Used By A Database Connection
  4733         -**
  4734         -** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
  4735         -** memory as possible from database connection D. Unlike the
  4736         -** [sqlite3_release_memory()] interface, this interface is effect even
  4737         -** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
  4738         -** omitted.
  4739         -**
  4740         -** See also: [sqlite3_release_memory()]
  4741         -*/
  4742         -SQLITE_API int sqlite3_db_release_memory(sqlite3*);
  4743         -
  4744         -/*
  4745         -** CAPI3REF: Impose A Limit On Heap Size
  4746         -**
  4747         -** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
  4748         -** soft limit on the amount of heap memory that may be allocated by SQLite.
  4749         -** ^SQLite strives to keep heap memory utilization below the soft heap
  4750         -** limit by reducing the number of pages held in the page cache
  4751         -** as heap memory usages approaches the limit.
  4752         -** ^The soft heap limit is "soft" because even though SQLite strives to stay
  4753         -** below the limit, it will exceed the limit rather than generate
  4754         -** an [SQLITE_NOMEM] error.  In other words, the soft heap limit 
  4755         -** is advisory only.
  4756         -**
  4757         -** ^The return value from sqlite3_soft_heap_limit64() is the size of
  4758         -** the soft heap limit prior to the call, or negative in the case of an
  4759         -** error.  ^If the argument N is negative
  4760         -** then no change is made to the soft heap limit.  Hence, the current
  4761         -** size of the soft heap limit can be determined by invoking
  4762         -** sqlite3_soft_heap_limit64() with a negative argument.
  4763         -**
  4764         -** ^If the argument N is zero then the soft heap limit is disabled.
  4765         -**
  4766         -** ^(The soft heap limit is not enforced in the current implementation
  4767         -** if one or more of following conditions are true:
  4768         -**
  4769         -** <ul>
  4770         -** <li> The soft heap limit is set to zero.
  4771         -** <li> Memory accounting is disabled using a combination of the
  4772         -**      [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
  4773         -**      the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
  4774         -** <li> An alternative page cache implementation is specified using
  4775         -**      [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
  4776         -** <li> The page cache allocates from its own memory pool supplied
  4777         -**      by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
  4778         -**      from the heap.
  4779         -** </ul>)^
  4780         -**
  4781         -** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
  4782         -** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
  4783         -** compile-time option is invoked.  With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
  4784         -** the soft heap limit is enforced on every memory allocation.  Without
  4785         -** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
  4786         -** when memory is allocated by the page cache.  Testing suggests that because
  4787         -** the page cache is the predominate memory user in SQLite, most
  4788         -** applications will achieve adequate soft heap limit enforcement without
  4789         -** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  4790         -**
  4791         -** The circumstances under which SQLite will enforce the soft heap limit may
  4792         -** changes in future releases of SQLite.
  4793         -*/
  4794         -SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
  4795         -
  4796         -/*
  4797         -** CAPI3REF: Deprecated Soft Heap Limit Interface
  4798         -** DEPRECATED
  4799         -**
  4800         -** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
  4801         -** interface.  This routine is provided for historical compatibility
  4802         -** only.  All new applications should use the
  4803         -** [sqlite3_soft_heap_limit64()] interface rather than this one.
  4804         -*/
  4805         -SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
  4806         -
  4807         -
  4808         -/*
  4809         -** CAPI3REF: Extract Metadata About A Column Of A Table
  4810         -**
  4811         -** ^This routine returns metadata about a specific column of a specific
  4812         -** database table accessible using the [database connection] handle
  4813         -** passed as the first function argument.
  4814         -**
  4815         -** ^The column is identified by the second, third and fourth parameters to
  4816         -** this function. ^The second parameter is either the name of the database
  4817         -** (i.e. "main", "temp", or an attached database) containing the specified
  4818         -** table or NULL. ^If it is NULL, then all attached databases are searched
  4819         -** for the table using the same algorithm used by the database engine to
  4820         -** resolve unqualified table references.
  4821         -**
  4822         -** ^The third and fourth parameters to this function are the table and column
  4823         -** name of the desired column, respectively. Neither of these parameters
  4824         -** may be NULL.
  4825         -**
  4826         -** ^Metadata is returned by writing to the memory locations passed as the 5th
  4827         -** and subsequent parameters to this function. ^Any of these arguments may be
  4828         -** NULL, in which case the corresponding element of metadata is omitted.
  4829         -**
  4830         -** ^(<blockquote>
  4831         -** <table border="1">
  4832         -** <tr><th> Parameter <th> Output<br>Type <th>  Description
  4833         -**
  4834         -** <tr><td> 5th <td> const char* <td> Data type
  4835         -** <tr><td> 6th <td> const char* <td> Name of default collation sequence
  4836         -** <tr><td> 7th <td> int         <td> True if column has a NOT NULL constraint
  4837         -** <tr><td> 8th <td> int         <td> True if column is part of the PRIMARY KEY
  4838         -** <tr><td> 9th <td> int         <td> True if column is [AUTOINCREMENT]
  4839         -** </table>
  4840         -** </blockquote>)^
  4841         -**
  4842         -** ^The memory pointed to by the character pointers returned for the
  4843         -** declaration type and collation sequence is valid only until the next
  4844         -** call to any SQLite API function.
  4845         -**
  4846         -** ^If the specified table is actually a view, an [error code] is returned.
  4847         -**
  4848         -** ^If the specified column is "rowid", "oid" or "_rowid_" and an
  4849         -** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
  4850         -** parameters are set for the explicitly declared column. ^(If there is no
  4851         -** explicitly declared [INTEGER PRIMARY KEY] column, then the output
  4852         -** parameters are set as follows:
  4853         -**
  4854         -** <pre>
  4855         -**     data type: "INTEGER"
  4856         -**     collation sequence: "BINARY"
  4857         -**     not null: 0
  4858         -**     primary key: 1
  4859         -**     auto increment: 0
  4860         -** </pre>)^
  4861         -**
  4862         -** ^(This function may load one or more schemas from database files. If an
  4863         -** error occurs during this process, or if the requested table or column
  4864         -** cannot be found, an [error code] is returned and an error message left
  4865         -** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
  4866         -**
  4867         -** ^This API is only available if the library was compiled with the
  4868         -** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
  4869         -*/
  4870         -SQLITE_API int sqlite3_table_column_metadata(
  4871         -  sqlite3 *db,                /* Connection handle */
  4872         -  const char *zDbName,        /* Database name or NULL */
  4873         -  const char *zTableName,     /* Table name */
  4874         -  const char *zColumnName,    /* Column name */
  4875         -  char const **pzDataType,    /* OUTPUT: Declared data type */
  4876         -  char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
  4877         -  int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
  4878         -  int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
  4879         -  int *pAutoinc               /* OUTPUT: True if column is auto-increment */
  4880         -);
  4881         -
  4882         -/*
  4883         -** CAPI3REF: Load An Extension
  4884         -**
  4885         -** ^This interface loads an SQLite extension library from the named file.
  4886         -**
  4887         -** ^The sqlite3_load_extension() interface attempts to load an
  4888         -** SQLite extension library contained in the file zFile.
  4889         -**
  4890         -** ^The entry point is zProc.
  4891         -** ^zProc may be 0, in which case the name of the entry point
  4892         -** defaults to "sqlite3_extension_init".
  4893         -** ^The sqlite3_load_extension() interface returns
  4894         -** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
  4895         -** ^If an error occurs and pzErrMsg is not 0, then the
  4896         -** [sqlite3_load_extension()] interface shall attempt to
  4897         -** fill *pzErrMsg with error message text stored in memory
  4898         -** obtained from [sqlite3_malloc()]. The calling function
  4899         -** should free this memory by calling [sqlite3_free()].
  4900         -**
  4901         -** ^Extension loading must be enabled using
  4902         -** [sqlite3_enable_load_extension()] prior to calling this API,
  4903         -** otherwise an error will be returned.
  4904         -**
  4905         -** See also the [load_extension() SQL function].
  4906         -*/
  4907         -SQLITE_API int sqlite3_load_extension(
  4908         -  sqlite3 *db,          /* Load the extension into this database connection */
  4909         -  const char *zFile,    /* Name of the shared library containing extension */
  4910         -  const char *zProc,    /* Entry point.  Derived from zFile if 0 */
  4911         -  char **pzErrMsg       /* Put error message here if not 0 */
  4912         -);
  4913         -
  4914         -/*
  4915         -** CAPI3REF: Enable Or Disable Extension Loading
  4916         -**
  4917         -** ^So as not to open security holes in older applications that are
  4918         -** unprepared to deal with extension loading, and as a means of disabling
  4919         -** extension loading while evaluating user-entered SQL, the following API
  4920         -** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
  4921         -**
  4922         -** ^Extension loading is off by default. See ticket #1863.
  4923         -** ^Call the sqlite3_enable_load_extension() routine with onoff==1
  4924         -** to turn extension loading on and call it with onoff==0 to turn
  4925         -** it back off again.
  4926         -*/
  4927         -SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  4928         -
  4929         -/*
  4930         -** CAPI3REF: Automatically Load Statically Linked Extensions
  4931         -**
  4932         -** ^This interface causes the xEntryPoint() function to be invoked for
  4933         -** each new [database connection] that is created.  The idea here is that
  4934         -** xEntryPoint() is the entry point for a statically linked SQLite extension
  4935         -** that is to be automatically loaded into all new database connections.
  4936         -**
  4937         -** ^(Even though the function prototype shows that xEntryPoint() takes
  4938         -** no arguments and returns void, SQLite invokes xEntryPoint() with three
  4939         -** arguments and expects and integer result as if the signature of the
  4940         -** entry point where as follows:
  4941         -**
  4942         -** <blockquote><pre>
  4943         -** &nbsp;  int xEntryPoint(
  4944         -** &nbsp;    sqlite3 *db,
  4945         -** &nbsp;    const char **pzErrMsg,
  4946         -** &nbsp;    const struct sqlite3_api_routines *pThunk
  4947         -** &nbsp;  );
  4948         -** </pre></blockquote>)^
  4949         -**
  4950         -** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
  4951         -** point to an appropriate error message (obtained from [sqlite3_mprintf()])
  4952         -** and return an appropriate [error code].  ^SQLite ensures that *pzErrMsg
  4953         -** is NULL before calling the xEntryPoint().  ^SQLite will invoke
  4954         -** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns.  ^If any
  4955         -** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
  4956         -** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
  4957         -**
  4958         -** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
  4959         -** on the list of automatic extensions is a harmless no-op. ^No entry point
  4960         -** will be called more than once for each database connection that is opened.
  4961         -**
  4962         -** See also: [sqlite3_reset_auto_extension()].
  4963         -*/
  4964         -SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
  4965         -
  4966         -/*
  4967         -** CAPI3REF: Reset Automatic Extension Loading
  4968         -**
  4969         -** ^This interface disables all automatic extensions previously
  4970         -** registered using [sqlite3_auto_extension()].
  4971         -*/
  4972         -SQLITE_API void sqlite3_reset_auto_extension(void);
  4973         -
  4974         -/*
  4975         -** The interface to the virtual-table mechanism is currently considered
  4976         -** to be experimental.  The interface might change in incompatible ways.
  4977         -** If this is a problem for you, do not use the interface at this time.
  4978         -**
  4979         -** When the virtual-table mechanism stabilizes, we will declare the
  4980         -** interface fixed, support it indefinitely, and remove this comment.
  4981         -*/
  4982         -
  4983         -/*
  4984         -** Structures used by the virtual table interface
  4985         -*/
  4986         -typedef struct sqlite3_vtab sqlite3_vtab;
  4987         -typedef struct sqlite3_index_info sqlite3_index_info;
  4988         -typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
  4989         -typedef struct sqlite3_module sqlite3_module;
  4990         -
  4991         -/*
  4992         -** CAPI3REF: Virtual Table Object
  4993         -** KEYWORDS: sqlite3_module {virtual table module}
  4994         -**
  4995         -** This structure, sometimes called a "virtual table module", 
  4996         -** defines the implementation of a [virtual tables].  
  4997         -** This structure consists mostly of methods for the module.
  4998         -**
  4999         -** ^A virtual table module is created by filling in a persistent
  5000         -** instance of this structure and passing a pointer to that instance
  5001         -** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
  5002         -** ^The registration remains valid until it is replaced by a different
  5003         -** module or until the [database connection] closes.  The content
  5004         -** of this structure must not change while it is registered with
  5005         -** any database connection.
  5006         -*/
  5007         -struct sqlite3_module {
  5008         -  int iVersion;
  5009         -  int (*xCreate)(sqlite3*, void *pAux,
  5010         -               int argc, const char *const*argv,
  5011         -               sqlite3_vtab **ppVTab, char**);
  5012         -  int (*xConnect)(sqlite3*, void *pAux,
  5013         -               int argc, const char *const*argv,
  5014         -               sqlite3_vtab **ppVTab, char**);
  5015         -  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
  5016         -  int (*xDisconnect)(sqlite3_vtab *pVTab);
  5017         -  int (*xDestroy)(sqlite3_vtab *pVTab);
  5018         -  int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
  5019         -  int (*xClose)(sqlite3_vtab_cursor*);
  5020         -  int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
  5021         -                int argc, sqlite3_value **argv);
  5022         -  int (*xNext)(sqlite3_vtab_cursor*);
  5023         -  int (*xEof)(sqlite3_vtab_cursor*);
  5024         -  int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
  5025         -  int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
  5026         -  int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
  5027         -  int (*xBegin)(sqlite3_vtab *pVTab);
  5028         -  int (*xSync)(sqlite3_vtab *pVTab);
  5029         -  int (*xCommit)(sqlite3_vtab *pVTab);
  5030         -  int (*xRollback)(sqlite3_vtab *pVTab);
  5031         -  int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  5032         -                       void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  5033         -                       void **ppArg);
  5034         -  int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  5035         -  /* The methods above are in version 1 of the sqlite_module object. Those 
  5036         -  ** below are for version 2 and greater. */
  5037         -  int (*xSavepoint)(sqlite3_vtab *pVTab, int);
  5038         -  int (*xRelease)(sqlite3_vtab *pVTab, int);
  5039         -  int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
  5040         -};
  5041         -
  5042         -/*
  5043         -** CAPI3REF: Virtual Table Indexing Information
  5044         -** KEYWORDS: sqlite3_index_info
  5045         -**
  5046         -** The sqlite3_index_info structure and its substructures is used as part
  5047         -** of the [virtual table] interface to
  5048         -** pass information into and receive the reply from the [xBestIndex]
  5049         -** method of a [virtual table module].  The fields under **Inputs** are the
  5050         -** inputs to xBestIndex and are read-only.  xBestIndex inserts its
  5051         -** results into the **Outputs** fields.
  5052         -**
  5053         -** ^(The aConstraint[] array records WHERE clause constraints of the form:
  5054         -**
  5055         -** <blockquote>column OP expr</blockquote>
  5056         -**
  5057         -** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^  ^(The particular operator is
  5058         -** stored in aConstraint[].op using one of the
  5059         -** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
  5060         -** ^(The index of the column is stored in
  5061         -** aConstraint[].iColumn.)^  ^(aConstraint[].usable is TRUE if the
  5062         -** expr on the right-hand side can be evaluated (and thus the constraint
  5063         -** is usable) and false if it cannot.)^
  5064         -**
  5065         -** ^The optimizer automatically inverts terms of the form "expr OP column"
  5066         -** and makes other simplifications to the WHERE clause in an attempt to
  5067         -** get as many WHERE clause terms into the form shown above as possible.
  5068         -** ^The aConstraint[] array only reports WHERE clause terms that are
  5069         -** relevant to the particular virtual table being queried.
  5070         -**
  5071         -** ^Information about the ORDER BY clause is stored in aOrderBy[].
  5072         -** ^Each term of aOrderBy records a column of the ORDER BY clause.
  5073         -**
  5074         -** The [xBestIndex] method must fill aConstraintUsage[] with information
  5075         -** about what parameters to pass to xFilter.  ^If argvIndex>0 then
  5076         -** the right-hand side of the corresponding aConstraint[] is evaluated
  5077         -** and becomes the argvIndex-th entry in argv.  ^(If aConstraintUsage[].omit
  5078         -** is true, then the constraint is assumed to be fully handled by the
  5079         -** virtual table and is not checked again by SQLite.)^
  5080         -**
  5081         -** ^The idxNum and idxPtr values are recorded and passed into the
  5082         -** [xFilter] method.
  5083         -** ^[sqlite3_free()] is used to free idxPtr if and only if
  5084         -** needToFreeIdxPtr is true.
  5085         -**
  5086         -** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
  5087         -** the correct order to satisfy the ORDER BY clause so that no separate
  5088         -** sorting step is required.
  5089         -**
  5090         -** ^The estimatedCost value is an estimate of the cost of doing the
  5091         -** particular lookup.  A full scan of a table with N entries should have
  5092         -** a cost of N.  A binary search of a table of N entries should have a
  5093         -** cost of approximately log(N).
  5094         -*/
  5095         -struct sqlite3_index_info {
  5096         -  /* Inputs */
  5097         -  int nConstraint;           /* Number of entries in aConstraint */
  5098         -  struct sqlite3_index_constraint {
  5099         -     int iColumn;              /* Column on left-hand side of constraint */
  5100         -     unsigned char op;         /* Constraint operator */
  5101         -     unsigned char usable;     /* True if this constraint is usable */
  5102         -     int iTermOffset;          /* Used internally - xBestIndex should ignore */
  5103         -  } *aConstraint;            /* Table of WHERE clause constraints */
  5104         -  int nOrderBy;              /* Number of terms in the ORDER BY clause */
  5105         -  struct sqlite3_index_orderby {
  5106         -     int iColumn;              /* Column number */
  5107         -     unsigned char desc;       /* True for DESC.  False for ASC. */
  5108         -  } *aOrderBy;               /* The ORDER BY clause */
  5109         -  /* Outputs */
  5110         -  struct sqlite3_index_constraint_usage {
  5111         -    int argvIndex;           /* if >0, constraint is part of argv to xFilter */
  5112         -    unsigned char omit;      /* Do not code a test for this constraint */
  5113         -  } *aConstraintUsage;
  5114         -  int idxNum;                /* Number used to identify the index */
  5115         -  char *idxStr;              /* String, possibly obtained from sqlite3_malloc */
  5116         -  int needToFreeIdxStr;      /* Free idxStr using sqlite3_free() if true */
  5117         -  int orderByConsumed;       /* True if output is already ordered */
  5118         -  double estimatedCost;      /* Estimated cost of using this index */
  5119         -};
  5120         -
  5121         -/*
  5122         -** CAPI3REF: Virtual Table Constraint Operator Codes
  5123         -**
  5124         -** These macros defined the allowed values for the
  5125         -** [sqlite3_index_info].aConstraint[].op field.  Each value represents
  5126         -** an operator that is part of a constraint term in the wHERE clause of
  5127         -** a query that uses a [virtual table].
  5128         -*/
  5129         -#define SQLITE_INDEX_CONSTRAINT_EQ    2
  5130         -#define SQLITE_INDEX_CONSTRAINT_GT    4
  5131         -#define SQLITE_INDEX_CONSTRAINT_LE    8
  5132         -#define SQLITE_INDEX_CONSTRAINT_LT    16
  5133         -#define SQLITE_INDEX_CONSTRAINT_GE    32
  5134         -#define SQLITE_INDEX_CONSTRAINT_MATCH 64
  5135         -
  5136         -/*
  5137         -** CAPI3REF: Register A Virtual Table Implementation
  5138         -**
  5139         -** ^These routines are used to register a new [virtual table module] name.
  5140         -** ^Module names must be registered before
  5141         -** creating a new [virtual table] using the module and before using a
  5142         -** preexisting [virtual table] for the module.
  5143         -**
  5144         -** ^The module name is registered on the [database connection] specified
  5145         -** by the first parameter.  ^The name of the module is given by the 
  5146         -** second parameter.  ^The third parameter is a pointer to
  5147         -** the implementation of the [virtual table module].   ^The fourth
  5148         -** parameter is an arbitrary client data pointer that is passed through
  5149         -** into the [xCreate] and [xConnect] methods of the virtual table module
  5150         -** when a new virtual table is be being created or reinitialized.
  5151         -**
  5152         -** ^The sqlite3_create_module_v2() interface has a fifth parameter which
  5153         -** is a pointer to a destructor for the pClientData.  ^SQLite will
  5154         -** invoke the destructor function (if it is not NULL) when SQLite
  5155         -** no longer needs the pClientData pointer.  ^The destructor will also
  5156         -** be invoked if the call to sqlite3_create_module_v2() fails.
  5157         -** ^The sqlite3_create_module()
  5158         -** interface is equivalent to sqlite3_create_module_v2() with a NULL
  5159         -** destructor.
  5160         -*/
  5161         -SQLITE_API int sqlite3_create_module(
  5162         -  sqlite3 *db,               /* SQLite connection to register module with */
  5163         -  const char *zName,         /* Name of the module */
  5164         -  const sqlite3_module *p,   /* Methods for the module */
  5165         -  void *pClientData          /* Client data for xCreate/xConnect */
  5166         -);
  5167         -SQLITE_API int sqlite3_create_module_v2(
  5168         -  sqlite3 *db,               /* SQLite connection to register module with */
  5169         -  const char *zName,         /* Name of the module */
  5170         -  const sqlite3_module *p,   /* Methods for the module */
  5171         -  void *pClientData,         /* Client data for xCreate/xConnect */
  5172         -  void(*xDestroy)(void*)     /* Module destructor function */
  5173         -);
  5174         -
  5175         -/*
  5176         -** CAPI3REF: Virtual Table Instance Object
  5177         -** KEYWORDS: sqlite3_vtab
  5178         -**
  5179         -** Every [virtual table module] implementation uses a subclass
  5180         -** of this object to describe a particular instance
  5181         -** of the [virtual table].  Each subclass will
  5182         -** be tailored to the specific needs of the module implementation.
  5183         -** The purpose of this superclass is to define certain fields that are
  5184         -** common to all module implementations.
  5185         -**
  5186         -** ^Virtual tables methods can set an error message by assigning a
  5187         -** string obtained from [sqlite3_mprintf()] to zErrMsg.  The method should
  5188         -** take care that any prior string is freed by a call to [sqlite3_free()]
  5189         -** prior to assigning a new string to zErrMsg.  ^After the error message
  5190         -** is delivered up to the client application, the string will be automatically
  5191         -** freed by sqlite3_free() and the zErrMsg field will be zeroed.
  5192         -*/
  5193         -struct sqlite3_vtab {
  5194         -  const sqlite3_module *pModule;  /* The module for this virtual table */
  5195         -  int nRef;                       /* NO LONGER USED */
  5196         -  char *zErrMsg;                  /* Error message from sqlite3_mprintf() */
  5197         -  /* Virtual table implementations will typically add additional fields */
  5198         -};
  5199         -
  5200         -/*
  5201         -** CAPI3REF: Virtual Table Cursor Object
  5202         -** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
  5203         -**
  5204         -** Every [virtual table module] implementation uses a subclass of the
  5205         -** following structure to describe cursors that point into the
  5206         -** [virtual table] and are used
  5207         -** to loop through the virtual table.  Cursors are created using the
  5208         -** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
  5209         -** by the [sqlite3_module.xClose | xClose] method.  Cursors are used
  5210         -** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
  5211         -** of the module.  Each module implementation will define
  5212         -** the content of a cursor structure to suit its own needs.
  5213         -**
  5214         -** This superclass exists in order to define fields of the cursor that
  5215         -** are common to all implementations.
  5216         -*/
  5217         -struct sqlite3_vtab_cursor {
  5218         -  sqlite3_vtab *pVtab;      /* Virtual table of this cursor */
  5219         -  /* Virtual table implementations will typically add additional fields */
  5220         -};
  5221         -
  5222         -/*
  5223         -** CAPI3REF: Declare The Schema Of A Virtual Table
  5224         -**
  5225         -** ^The [xCreate] and [xConnect] methods of a
  5226         -** [virtual table module] call this interface
  5227         -** to declare the format (the names and datatypes of the columns) of
  5228         -** the virtual tables they implement.
  5229         -*/
  5230         -SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
  5231         -
  5232         -/*
  5233         -** CAPI3REF: Overload A Function For A Virtual Table
  5234         -**
  5235         -** ^(Virtual tables can provide alternative implementations of functions
  5236         -** using the [xFindFunction] method of the [virtual table module].  
  5237         -** But global versions of those functions
  5238         -** must exist in order to be overloaded.)^
  5239         -**
  5240         -** ^(This API makes sure a global version of a function with a particular
  5241         -** name and number of parameters exists.  If no such function exists
  5242         -** before this API is called, a new function is created.)^  ^The implementation
  5243         -** of the new function always causes an exception to be thrown.  So
  5244         -** the new function is not good for anything by itself.  Its only
  5245         -** purpose is to be a placeholder function that can be overloaded
  5246         -** by a [virtual table].
  5247         -*/
  5248         -SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  5249         -
  5250         -/*
  5251         -** The interface to the virtual-table mechanism defined above (back up
  5252         -** to a comment remarkably similar to this one) is currently considered
  5253         -** to be experimental.  The interface might change in incompatible ways.
  5254         -** If this is a problem for you, do not use the interface at this time.
  5255         -**
  5256         -** When the virtual-table mechanism stabilizes, we will declare the
  5257         -** interface fixed, support it indefinitely, and remove this comment.
  5258         -*/
  5259         -
  5260         -/*
  5261         -** CAPI3REF: A Handle To An Open BLOB
  5262         -** KEYWORDS: {BLOB handle} {BLOB handles}
  5263         -**
  5264         -** An instance of this object represents an open BLOB on which
  5265         -** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
  5266         -** ^Objects of this type are created by [sqlite3_blob_open()]
  5267         -** and destroyed by [sqlite3_blob_close()].
  5268         -** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
  5269         -** can be used to read or write small subsections of the BLOB.
  5270         -** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
  5271         -*/
  5272         -typedef struct sqlite3_blob sqlite3_blob;
  5273         -
  5274         -/*
  5275         -** CAPI3REF: Open A BLOB For Incremental I/O
  5276         -**
  5277         -** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
  5278         -** in row iRow, column zColumn, table zTable in database zDb;
  5279         -** in other words, the same BLOB that would be selected by:
  5280         -**
  5281         -** <pre>
  5282         -**     SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
  5283         -** </pre>)^
  5284         -**
  5285         -** ^If the flags parameter is non-zero, then the BLOB is opened for read
  5286         -** and write access. ^If it is zero, the BLOB is opened for read access.
  5287         -** ^It is not possible to open a column that is part of an index or primary 
  5288         -** key for writing. ^If [foreign key constraints] are enabled, it is 
  5289         -** not possible to open a column that is part of a [child key] for writing.
  5290         -**
  5291         -** ^Note that the database name is not the filename that contains
  5292         -** the database but rather the symbolic name of the database that
  5293         -** appears after the AS keyword when the database is connected using [ATTACH].
  5294         -** ^For the main database file, the database name is "main".
  5295         -** ^For TEMP tables, the database name is "temp".
  5296         -**
  5297         -** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
  5298         -** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
  5299         -** to be a null pointer.)^
  5300         -** ^This function sets the [database connection] error code and message
  5301         -** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
  5302         -** functions. ^Note that the *ppBlob variable is always initialized in a
  5303         -** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
  5304         -** regardless of the success or failure of this routine.
  5305         -**
  5306         -** ^(If the row that a BLOB handle points to is modified by an
  5307         -** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
  5308         -** then the BLOB handle is marked as "expired".
  5309         -** This is true if any column of the row is changed, even a column
  5310         -** other than the one the BLOB handle is open on.)^
  5311         -** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
  5312         -** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
  5313         -** ^(Changes written into a BLOB prior to the BLOB expiring are not
  5314         -** rolled back by the expiration of the BLOB.  Such changes will eventually
  5315         -** commit if the transaction continues to completion.)^
  5316         -**
  5317         -** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
  5318         -** the opened blob.  ^The size of a blob may not be changed by this
  5319         -** interface.  Use the [UPDATE] SQL command to change the size of a
  5320         -** blob.
  5321         -**
  5322         -** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
  5323         -** and the built-in [zeroblob] SQL function can be used, if desired,
  5324         -** to create an empty, zero-filled blob in which to read or write using
  5325         -** this interface.
  5326         -**
  5327         -** To avoid a resource leak, every open [BLOB handle] should eventually
  5328         -** be released by a call to [sqlite3_blob_close()].
  5329         -*/
  5330         -SQLITE_API int sqlite3_blob_open(
  5331         -  sqlite3*,
  5332         -  const char *zDb,
  5333         -  const char *zTable,
  5334         -  const char *zColumn,
  5335         -  sqlite3_int64 iRow,
  5336         -  int flags,
  5337         -  sqlite3_blob **ppBlob
  5338         -);
  5339         -
  5340         -/*
  5341         -** CAPI3REF: Move a BLOB Handle to a New Row
  5342         -**
  5343         -** ^This function is used to move an existing blob handle so that it points
  5344         -** to a different row of the same database table. ^The new row is identified
  5345         -** by the rowid value passed as the second argument. Only the row can be
  5346         -** changed. ^The database, table and column on which the blob handle is open
  5347         -** remain the same. Moving an existing blob handle to a new row can be
  5348         -** faster than closing the existing handle and opening a new one.
  5349         -**
  5350         -** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
  5351         -** it must exist and there must be either a blob or text value stored in
  5352         -** the nominated column.)^ ^If the new row is not present in the table, or if
  5353         -** it does not contain a blob or text value, or if another error occurs, an
  5354         -** SQLite error code is returned and the blob handle is considered aborted.
  5355         -** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
  5356         -** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
  5357         -** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
  5358         -** always returns zero.
  5359         -**
  5360         -** ^This function sets the database handle error code and message.
  5361         -*/
  5362         -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
  5363         -
  5364         -/*
  5365         -** CAPI3REF: Close A BLOB Handle
  5366         -**
  5367         -** ^Closes an open [BLOB handle].
  5368         -**
  5369         -** ^Closing a BLOB shall cause the current transaction to commit
  5370         -** if there are no other BLOBs, no pending prepared statements, and the
  5371         -** database connection is in [autocommit mode].
  5372         -** ^If any writes were made to the BLOB, they might be held in cache
  5373         -** until the close operation if they will fit.
  5374         -**
  5375         -** ^(Closing the BLOB often forces the changes
  5376         -** out to disk and so if any I/O errors occur, they will likely occur
  5377         -** at the time when the BLOB is closed.  Any errors that occur during
  5378         -** closing are reported as a non-zero return value.)^
  5379         -**
  5380         -** ^(The BLOB is closed unconditionally.  Even if this routine returns
  5381         -** an error code, the BLOB is still closed.)^
  5382         -**
  5383         -** ^Calling this routine with a null pointer (such as would be returned
  5384         -** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
  5385         -*/
  5386         -SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
  5387         -
  5388         -/*
  5389         -** CAPI3REF: Return The Size Of An Open BLOB
  5390         -**
  5391         -** ^Returns the size in bytes of the BLOB accessible via the 
  5392         -** successfully opened [BLOB handle] in its only argument.  ^The
  5393         -** incremental blob I/O routines can only read or overwriting existing
  5394         -** blob content; they cannot change the size of a blob.
  5395         -**
  5396         -** This routine only works on a [BLOB handle] which has been created
  5397         -** by a prior successful call to [sqlite3_blob_open()] and which has not
  5398         -** been closed by [sqlite3_blob_close()].  Passing any other pointer in
  5399         -** to this routine results in undefined and probably undesirable behavior.
  5400         -*/
  5401         -SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
  5402         -
  5403         -/*
  5404         -** CAPI3REF: Read Data From A BLOB Incrementally
  5405         -**
  5406         -** ^(This function is used to read data from an open [BLOB handle] into a
  5407         -** caller-supplied buffer. N bytes of data are copied into buffer Z
  5408         -** from the open BLOB, starting at offset iOffset.)^
  5409         -**
  5410         -** ^If offset iOffset is less than N bytes from the end of the BLOB,
  5411         -** [SQLITE_ERROR] is returned and no data is read.  ^If N or iOffset is
  5412         -** less than zero, [SQLITE_ERROR] is returned and no data is read.
  5413         -** ^The size of the blob (and hence the maximum value of N+iOffset)
  5414         -** can be determined using the [sqlite3_blob_bytes()] interface.
  5415         -**
  5416         -** ^An attempt to read from an expired [BLOB handle] fails with an
  5417         -** error code of [SQLITE_ABORT].
  5418         -**
  5419         -** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
  5420         -** Otherwise, an [error code] or an [extended error code] is returned.)^
  5421         -**
  5422         -** This routine only works on a [BLOB handle] which has been created
  5423         -** by a prior successful call to [sqlite3_blob_open()] and which has not
  5424         -** been closed by [sqlite3_blob_close()].  Passing any other pointer in
  5425         -** to this routine results in undefined and probably undesirable behavior.
  5426         -**
  5427         -** See also: [sqlite3_blob_write()].
  5428         -*/
  5429         -SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  5430         -
  5431         -/*
  5432         -** CAPI3REF: Write Data Into A BLOB Incrementally
  5433         -**
  5434         -** ^This function is used to write data into an open [BLOB handle] from a
  5435         -** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
  5436         -** into the open BLOB, starting at offset iOffset.
  5437         -**
  5438         -** ^If the [BLOB handle] passed as the first argument was not opened for
  5439         -** writing (the flags parameter to [sqlite3_blob_open()] was zero),
  5440         -** this function returns [SQLITE_READONLY].
  5441         -**
  5442         -** ^This function may only modify the contents of the BLOB; it is
  5443         -** not possible to increase the size of a BLOB using this API.
  5444         -** ^If offset iOffset is less than N bytes from the end of the BLOB,
  5445         -** [SQLITE_ERROR] is returned and no data is written.  ^If N is
  5446         -** less than zero [SQLITE_ERROR] is returned and no data is written.
  5447         -** The size of the BLOB (and hence the maximum value of N+iOffset)
  5448         -** can be determined using the [sqlite3_blob_bytes()] interface.
  5449         -**
  5450         -** ^An attempt to write to an expired [BLOB handle] fails with an
  5451         -** error code of [SQLITE_ABORT].  ^Writes to the BLOB that occurred
  5452         -** before the [BLOB handle] expired are not rolled back by the
  5453         -** expiration of the handle, though of course those changes might
  5454         -** have been overwritten by the statement that expired the BLOB handle
  5455         -** or by other independent statements.
  5456         -**
  5457         -** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
  5458         -** Otherwise, an  [error code] or an [extended error code] is returned.)^
  5459         -**
  5460         -** This routine only works on a [BLOB handle] which has been created
  5461         -** by a prior successful call to [sqlite3_blob_open()] and which has not
  5462         -** been closed by [sqlite3_blob_close()].  Passing any other pointer in
  5463         -** to this routine results in undefined and probably undesirable behavior.
  5464         -**
  5465         -** See also: [sqlite3_blob_read()].
  5466         -*/
  5467         -SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  5468         -
  5469         -/*
  5470         -** CAPI3REF: Virtual File System Objects
  5471         -**
  5472         -** A virtual filesystem (VFS) is an [sqlite3_vfs] object
  5473         -** that SQLite uses to interact
  5474         -** with the underlying operating system.  Most SQLite builds come with a
  5475         -** single default VFS that is appropriate for the host computer.
  5476         -** New VFSes can be registered and existing VFSes can be unregistered.
  5477         -** The following interfaces are provided.
  5478         -**
  5479         -** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
  5480         -** ^Names are case sensitive.
  5481         -** ^Names are zero-terminated UTF-8 strings.
  5482         -** ^If there is no match, a NULL pointer is returned.
  5483         -** ^If zVfsName is NULL then the default VFS is returned.
  5484         -**
  5485         -** ^New VFSes are registered with sqlite3_vfs_register().
  5486         -** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
  5487         -** ^The same VFS can be registered multiple times without injury.
  5488         -** ^To make an existing VFS into the default VFS, register it again
  5489         -** with the makeDflt flag set.  If two different VFSes with the
  5490         -** same name are registered, the behavior is undefined.  If a
  5491         -** VFS is registered with a name that is NULL or an empty string,
  5492         -** then the behavior is undefined.
  5493         -**
  5494         -** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
  5495         -** ^(If the default VFS is unregistered, another VFS is chosen as
  5496         -** the default.  The choice for the new VFS is arbitrary.)^
  5497         -*/
  5498         -SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
  5499         -SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  5500         -SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
  5501         -
  5502         -/*
  5503         -** CAPI3REF: Mutexes
  5504         -**
  5505         -** The SQLite core uses these routines for thread
  5506         -** synchronization. Though they are intended for internal
  5507         -** use by SQLite, code that links against SQLite is
  5508         -** permitted to use any of these routines.
  5509         -**
  5510         -** The SQLite source code contains multiple implementations
  5511         -** of these mutex routines.  An appropriate implementation
  5512         -** is selected automatically at compile-time.  ^(The following
  5513         -** implementations are available in the SQLite core:
  5514         -**
  5515         -** <ul>
  5516         -** <li>   SQLITE_MUTEX_PTHREADS
  5517         -** <li>   SQLITE_MUTEX_W32
  5518         -** <li>   SQLITE_MUTEX_NOOP
  5519         -** </ul>)^
  5520         -**
  5521         -** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
  5522         -** that does no real locking and is appropriate for use in
  5523         -** a single-threaded application.  ^The SQLITE_MUTEX_PTHREADS and
  5524         -** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
  5525         -** and Windows.
  5526         -**
  5527         -** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
  5528         -** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
  5529         -** implementation is included with the library. In this case the
  5530         -** application must supply a custom mutex implementation using the
  5531         -** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
  5532         -** before calling sqlite3_initialize() or any other public sqlite3_
  5533         -** function that calls sqlite3_initialize().)^
  5534         -**
  5535         -** ^The sqlite3_mutex_alloc() routine allocates a new
  5536         -** mutex and returns a pointer to it. ^If it returns NULL
  5537         -** that means that a mutex could not be allocated.  ^SQLite
  5538         -** will unwind its stack and return an error.  ^(The argument
  5539         -** to sqlite3_mutex_alloc() is one of these integer constants:
  5540         -**
  5541         -** <ul>
  5542         -** <li>  SQLITE_MUTEX_FAST
  5543         -** <li>  SQLITE_MUTEX_RECURSIVE
  5544         -** <li>  SQLITE_MUTEX_STATIC_MASTER
  5545         -** <li>  SQLITE_MUTEX_STATIC_MEM
  5546         -** <li>  SQLITE_MUTEX_STATIC_MEM2
  5547         -** <li>  SQLITE_MUTEX_STATIC_PRNG
  5548         -** <li>  SQLITE_MUTEX_STATIC_LRU
  5549         -** <li>  SQLITE_MUTEX_STATIC_LRU2
  5550         -** </ul>)^
  5551         -**
  5552         -** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
  5553         -** cause sqlite3_mutex_alloc() to create
  5554         -** a new mutex.  ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
  5555         -** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
  5556         -** The mutex implementation does not need to make a distinction
  5557         -** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
  5558         -** not want to.  ^SQLite will only request a recursive mutex in
  5559         -** cases where it really needs one.  ^If a faster non-recursive mutex
  5560         -** implementation is available on the host platform, the mutex subsystem
  5561         -** might return such a mutex in response to SQLITE_MUTEX_FAST.
  5562         -**
  5563         -** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
  5564         -** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
  5565         -** a pointer to a static preexisting mutex.  ^Six static mutexes are
  5566         -** used by the current version of SQLite.  Future versions of SQLite
  5567         -** may add additional static mutexes.  Static mutexes are for internal
  5568         -** use by SQLite only.  Applications that use SQLite mutexes should
  5569         -** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
  5570         -** SQLITE_MUTEX_RECURSIVE.
  5571         -**
  5572         -** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
  5573         -** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
  5574         -** returns a different mutex on every call.  ^But for the static
  5575         -** mutex types, the same mutex is returned on every call that has
  5576         -** the same type number.
  5577         -**
  5578         -** ^The sqlite3_mutex_free() routine deallocates a previously
  5579         -** allocated dynamic mutex.  ^SQLite is careful to deallocate every
  5580         -** dynamic mutex that it allocates.  The dynamic mutexes must not be in
  5581         -** use when they are deallocated.  Attempting to deallocate a static
  5582         -** mutex results in undefined behavior.  ^SQLite never deallocates
  5583         -** a static mutex.
  5584         -**
  5585         -** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
  5586         -** to enter a mutex.  ^If another thread is already within the mutex,
  5587         -** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
  5588         -** SQLITE_BUSY.  ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
  5589         -** upon successful entry.  ^(Mutexes created using
  5590         -** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
  5591         -** In such cases the,
  5592         -** mutex must be exited an equal number of times before another thread
  5593         -** can enter.)^  ^(If the same thread tries to enter any other
  5594         -** kind of mutex more than once, the behavior is undefined.
  5595         -** SQLite will never exhibit
  5596         -** such behavior in its own use of mutexes.)^
  5597         -**
  5598         -** ^(Some systems (for example, Windows 95) do not support the operation
  5599         -** implemented by sqlite3_mutex_try().  On those systems, sqlite3_mutex_try()
  5600         -** will always return SQLITE_BUSY.  The SQLite core only ever uses
  5601         -** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^
  5602         -**
  5603         -** ^The sqlite3_mutex_leave() routine exits a mutex that was
  5604         -** previously entered by the same thread.   ^(The behavior
  5605         -** is undefined if the mutex is not currently entered by the
  5606         -** calling thread or is not currently allocated.  SQLite will
  5607         -** never do either.)^
  5608         -**
  5609         -** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
  5610         -** sqlite3_mutex_leave() is a NULL pointer, then all three routines
  5611         -** behave as no-ops.
  5612         -**
  5613         -** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  5614         -*/
  5615         -SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
  5616         -SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
  5617         -SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
  5618         -SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
  5619         -SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
  5620         -
  5621         -/*
  5622         -** CAPI3REF: Mutex Methods Object
  5623         -**
  5624         -** An instance of this structure defines the low-level routines
  5625         -** used to allocate and use mutexes.
  5626         -**
  5627         -** Usually, the default mutex implementations provided by SQLite are
  5628         -** sufficient, however the user has the option of substituting a custom
  5629         -** implementation for specialized deployments or systems for which SQLite
  5630         -** does not provide a suitable implementation. In this case, the user
  5631         -** creates and populates an instance of this structure to pass
  5632         -** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
  5633         -** Additionally, an instance of this structure can be used as an
  5634         -** output variable when querying the system for the current mutex
  5635         -** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
  5636         -**
  5637         -** ^The xMutexInit method defined by this structure is invoked as
  5638         -** part of system initialization by the sqlite3_initialize() function.
  5639         -** ^The xMutexInit routine is called by SQLite exactly once for each
  5640         -** effective call to [sqlite3_initialize()].
  5641         -**
  5642         -** ^The xMutexEnd method defined by this structure is invoked as
  5643         -** part of system shutdown by the sqlite3_shutdown() function. The
  5644         -** implementation of this method is expected to release all outstanding
  5645         -** resources obtained by the mutex methods implementation, especially
  5646         -** those obtained by the xMutexInit method.  ^The xMutexEnd()
  5647         -** interface is invoked exactly once for each call to [sqlite3_shutdown()].
  5648         -**
  5649         -** ^(The remaining seven methods defined by this structure (xMutexAlloc,
  5650         -** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
  5651         -** xMutexNotheld) implement the following interfaces (respectively):
  5652         -**
  5653         -** <ul>
  5654         -**   <li>  [sqlite3_mutex_alloc()] </li>
  5655         -**   <li>  [sqlite3_mutex_free()] </li>
  5656         -**   <li>  [sqlite3_mutex_enter()] </li>
  5657         -**   <li>  [sqlite3_mutex_try()] </li>
  5658         -**   <li>  [sqlite3_mutex_leave()] </li>
  5659         -**   <li>  [sqlite3_mutex_held()] </li>
  5660         -**   <li>  [sqlite3_mutex_notheld()] </li>
  5661         -** </ul>)^
  5662         -**
  5663         -** The only difference is that the public sqlite3_XXX functions enumerated
  5664         -** above silently ignore any invocations that pass a NULL pointer instead
  5665         -** of a valid mutex handle. The implementations of the methods defined
  5666         -** by this structure are not required to handle this case, the results
  5667         -** of passing a NULL pointer instead of a valid mutex handle are undefined
  5668         -** (i.e. it is acceptable to provide an implementation that segfaults if
  5669         -** it is passed a NULL pointer).
  5670         -**
  5671         -** The xMutexInit() method must be threadsafe.  ^It must be harmless to
  5672         -** invoke xMutexInit() multiple times within the same process and without
  5673         -** intervening calls to xMutexEnd().  Second and subsequent calls to
  5674         -** xMutexInit() must be no-ops.
  5675         -**
  5676         -** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
  5677         -** and its associates).  ^Similarly, xMutexAlloc() must not use SQLite memory
  5678         -** allocation for a static mutex.  ^However xMutexAlloc() may use SQLite
  5679         -** memory allocation for a fast or recursive mutex.
  5680         -**
  5681         -** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
  5682         -** called, but only if the prior call to xMutexInit returned SQLITE_OK.
  5683         -** If xMutexInit fails in any way, it is expected to clean up after itself
  5684         -** prior to returning.
  5685         -*/
  5686         -typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
  5687         -struct sqlite3_mutex_methods {
  5688         -  int (*xMutexInit)(void);
  5689         -  int (*xMutexEnd)(void);
  5690         -  sqlite3_mutex *(*xMutexAlloc)(int);
  5691         -  void (*xMutexFree)(sqlite3_mutex *);
  5692         -  void (*xMutexEnter)(sqlite3_mutex *);
  5693         -  int (*xMutexTry)(sqlite3_mutex *);
  5694         -  void (*xMutexLeave)(sqlite3_mutex *);
  5695         -  int (*xMutexHeld)(sqlite3_mutex *);
  5696         -  int (*xMutexNotheld)(sqlite3_mutex *);
  5697         -};
  5698         -
  5699         -/*
  5700         -** CAPI3REF: Mutex Verification Routines
  5701         -**
  5702         -** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
  5703         -** are intended for use inside assert() statements.  ^The SQLite core
  5704         -** never uses these routines except inside an assert() and applications
  5705         -** are advised to follow the lead of the core.  ^The SQLite core only
  5706         -** provides implementations for these routines when it is compiled
  5707         -** with the SQLITE_DEBUG flag.  ^External mutex implementations
  5708         -** are only required to provide these routines if SQLITE_DEBUG is
  5709         -** defined and if NDEBUG is not defined.
  5710         -**
  5711         -** ^These routines should return true if the mutex in their argument
  5712         -** is held or not held, respectively, by the calling thread.
  5713         -**
  5714         -** ^The implementation is not required to provide versions of these
  5715         -** routines that actually work. If the implementation does not provide working
  5716         -** versions of these routines, it should at least provide stubs that always
  5717         -** return true so that one does not get spurious assertion failures.
  5718         -**
  5719         -** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
  5720         -** the routine should return 1.   This seems counter-intuitive since
  5721         -** clearly the mutex cannot be held if it does not exist.  But
  5722         -** the reason the mutex does not exist is because the build is not
  5723         -** using mutexes.  And we do not want the assert() containing the
  5724         -** call to sqlite3_mutex_held() to fail, so a non-zero return is
  5725         -** the appropriate thing to do.  ^The sqlite3_mutex_notheld()
  5726         -** interface should also return 1 when given a NULL pointer.
  5727         -*/
  5728         -#ifndef NDEBUG
  5729         -SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
  5730         -SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
  5731         -#endif
  5732         -
  5733         -/*
  5734         -** CAPI3REF: Mutex Types
  5735         -**
  5736         -** The [sqlite3_mutex_alloc()] interface takes a single argument
  5737         -** which is one of these integer constants.
  5738         -**
  5739         -** The set of static mutexes may change from one SQLite release to the
  5740         -** next.  Applications that override the built-in mutex logic must be
  5741         -** prepared to accommodate additional static mutexes.
  5742         -*/
  5743         -#define SQLITE_MUTEX_FAST             0
  5744         -#define SQLITE_MUTEX_RECURSIVE        1
  5745         -#define SQLITE_MUTEX_STATIC_MASTER    2
  5746         -#define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
  5747         -#define SQLITE_MUTEX_STATIC_MEM2      4  /* NOT USED */
  5748         -#define SQLITE_MUTEX_STATIC_OPEN      4  /* sqlite3BtreeOpen() */
  5749         -#define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_random() */
  5750         -#define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
  5751         -#define SQLITE_MUTEX_STATIC_LRU2      7  /* NOT USED */
  5752         -#define SQLITE_MUTEX_STATIC_PMEM      7  /* sqlite3PageMalloc() */
  5753         -
  5754         -/*
  5755         -** CAPI3REF: Retrieve the mutex for a database connection
  5756         -**
  5757         -** ^This interface returns a pointer the [sqlite3_mutex] object that 
  5758         -** serializes access to the [database connection] given in the argument
  5759         -** when the [threading mode] is Serialized.
  5760         -** ^If the [threading mode] is Single-thread or Multi-thread then this
  5761         -** routine returns a NULL pointer.
  5762         -*/
  5763         -SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
  5764         -
  5765         -/*
  5766         -** CAPI3REF: Low-Level Control Of Database Files
  5767         -**
  5768         -** ^The [sqlite3_file_control()] interface makes a direct call to the
  5769         -** xFileControl method for the [sqlite3_io_methods] object associated
  5770         -** with a particular database identified by the second argument. ^The
  5771         -** name of the database is "main" for the main database or "temp" for the
  5772         -** TEMP database, or the name that appears after the AS keyword for
  5773         -** databases that are added using the [ATTACH] SQL command.
  5774         -** ^A NULL pointer can be used in place of "main" to refer to the
  5775         -** main database file.
  5776         -** ^The third and fourth parameters to this routine
  5777         -** are passed directly through to the second and third parameters of
  5778         -** the xFileControl method.  ^The return value of the xFileControl
  5779         -** method becomes the return value of this routine.
  5780         -**
  5781         -** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
  5782         -** a pointer to the underlying [sqlite3_file] object to be written into
  5783         -** the space pointed to by the 4th parameter.  ^The SQLITE_FCNTL_FILE_POINTER
  5784         -** case is a short-circuit path which does not actually invoke the
  5785         -** underlying sqlite3_io_methods.xFileControl method.
  5786         -**
  5787         -** ^If the second parameter (zDbName) does not match the name of any
  5788         -** open database file, then SQLITE_ERROR is returned.  ^This error
  5789         -** code is not remembered and will not be recalled by [sqlite3_errcode()]
  5790         -** or [sqlite3_errmsg()].  The underlying xFileControl method might
  5791         -** also return SQLITE_ERROR.  There is no way to distinguish between
  5792         -** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  5793         -** xFileControl method.
  5794         -**
  5795         -** See also: [SQLITE_FCNTL_LOCKSTATE]
  5796         -*/
  5797         -SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  5798         -
  5799         -/*
  5800         -** CAPI3REF: Testing Interface
  5801         -**
  5802         -** ^The sqlite3_test_control() interface is used to read out internal
  5803         -** state of SQLite and to inject faults into SQLite for testing
  5804         -** purposes.  ^The first parameter is an operation code that determines
  5805         -** the number, meaning, and operation of all subsequent parameters.
  5806         -**
  5807         -** This interface is not for use by applications.  It exists solely
  5808         -** for verifying the correct operation of the SQLite library.  Depending
  5809         -** on how the SQLite library is compiled, this interface might not exist.
  5810         -**
  5811         -** The details of the operation codes, their meanings, the parameters
  5812         -** they take, and what they do are all subject to change without notice.
  5813         -** Unlike most of the SQLite API, this function is not guaranteed to
  5814         -** operate consistently from one release to the next.
  5815         -*/
  5816         -SQLITE_API int sqlite3_test_control(int op, ...);
  5817         -
  5818         -/*
  5819         -** CAPI3REF: Testing Interface Operation Codes
  5820         -**
  5821         -** These constants are the valid operation code parameters used
  5822         -** as the first argument to [sqlite3_test_control()].
  5823         -**
  5824         -** These parameters and their meanings are subject to change
  5825         -** without notice.  These values are for testing purposes only.
  5826         -** Applications should not use any of these parameters or the
  5827         -** [sqlite3_test_control()] interface.
  5828         -*/
  5829         -#define SQLITE_TESTCTRL_FIRST                    5
  5830         -#define SQLITE_TESTCTRL_PRNG_SAVE                5
  5831         -#define SQLITE_TESTCTRL_PRNG_RESTORE             6
  5832         -#define SQLITE_TESTCTRL_PRNG_RESET               7
  5833         -#define SQLITE_TESTCTRL_BITVEC_TEST              8
  5834         -#define SQLITE_TESTCTRL_FAULT_INSTALL            9
  5835         -#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
  5836         -#define SQLITE_TESTCTRL_PENDING_BYTE            11
  5837         -#define SQLITE_TESTCTRL_ASSERT                  12
  5838         -#define SQLITE_TESTCTRL_ALWAYS                  13
  5839         -#define SQLITE_TESTCTRL_RESERVE                 14
  5840         -#define SQLITE_TESTCTRL_OPTIMIZATIONS           15
  5841         -#define SQLITE_TESTCTRL_ISKEYWORD               16
  5842         -#define SQLITE_TESTCTRL_SCRATCHMALLOC           17
  5843         -#define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
  5844         -#define SQLITE_TESTCTRL_EXPLAIN_STMT            19
  5845         -#define SQLITE_TESTCTRL_LAST                    19
  5846         -
  5847         -/*
  5848         -** CAPI3REF: SQLite Runtime Status
  5849         -**
  5850         -** ^This interface is used to retrieve runtime status information
  5851         -** about the performance of SQLite, and optionally to reset various
  5852         -** highwater marks.  ^The first argument is an integer code for
  5853         -** the specific parameter to measure.  ^(Recognized integer codes
  5854         -** are of the form [status parameters | SQLITE_STATUS_...].)^
  5855         -** ^The current value of the parameter is returned into *pCurrent.
  5856         -** ^The highest recorded value is returned in *pHighwater.  ^If the
  5857         -** resetFlag is true, then the highest record value is reset after
  5858         -** *pHighwater is written.  ^(Some parameters do not record the highest
  5859         -** value.  For those parameters
  5860         -** nothing is written into *pHighwater and the resetFlag is ignored.)^
  5861         -** ^(Other parameters record only the highwater mark and not the current
  5862         -** value.  For these latter parameters nothing is written into *pCurrent.)^
  5863         -**
  5864         -** ^The sqlite3_status() routine returns SQLITE_OK on success and a
  5865         -** non-zero [error code] on failure.
  5866         -**
  5867         -** This routine is threadsafe but is not atomic.  This routine can be
  5868         -** called while other threads are running the same or different SQLite
  5869         -** interfaces.  However the values returned in *pCurrent and
  5870         -** *pHighwater reflect the status of SQLite at different points in time
  5871         -** and it is possible that another thread might change the parameter
  5872         -** in between the times when *pCurrent and *pHighwater are written.
  5873         -**
  5874         -** See also: [sqlite3_db_status()]
  5875         -*/
  5876         -SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  5877         -
  5878         -
  5879         -/*
  5880         -** CAPI3REF: Status Parameters
  5881         -** KEYWORDS: {status parameters}
  5882         -**
  5883         -** These integer constants designate various run-time status parameters
  5884         -** that can be returned by [sqlite3_status()].
  5885         -**
  5886         -** <dl>
  5887         -** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
  5888         -** <dd>This parameter is the current amount of memory checked out
  5889         -** using [sqlite3_malloc()], either directly or indirectly.  The
  5890         -** figure includes calls made to [sqlite3_malloc()] by the application
  5891         -** and internal memory usage by the SQLite library.  Scratch memory
  5892         -** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
  5893         -** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  5894         -** this parameter.  The amount returned is the sum of the allocation
  5895         -** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
  5896         -**
  5897         -** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
  5898         -** <dd>This parameter records the largest memory allocation request
  5899         -** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  5900         -** internal equivalents).  Only the value returned in the
  5901         -** *pHighwater parameter to [sqlite3_status()] is of interest.  
  5902         -** The value written into the *pCurrent parameter is undefined.</dd>)^
  5903         -**
  5904         -** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
  5905         -** <dd>This parameter records the number of separate memory allocations
  5906         -** currently checked out.</dd>)^
  5907         -**
  5908         -** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  5909         -** <dd>This parameter returns the number of pages used out of the
  5910         -** [pagecache memory allocator] that was configured using 
  5911         -** [SQLITE_CONFIG_PAGECACHE].  The
  5912         -** value returned is in pages, not in bytes.</dd>)^
  5913         -**
  5914         -** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] 
  5915         -** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
  5916         -** <dd>This parameter returns the number of bytes of page cache
  5917         -** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
  5918         -** buffer and where forced to overflow to [sqlite3_malloc()].  The
  5919         -** returned value includes allocations that overflowed because they
  5920         -** where too large (they were larger than the "sz" parameter to
  5921         -** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
  5922         -** no space was left in the page cache.</dd>)^
  5923         -**
  5924         -** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
  5925         -** <dd>This parameter records the largest memory allocation request
  5926         -** handed to [pagecache memory allocator].  Only the value returned in the
  5927         -** *pHighwater parameter to [sqlite3_status()] is of interest.  
  5928         -** The value written into the *pCurrent parameter is undefined.</dd>)^
  5929         -**
  5930         -** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
  5931         -** <dd>This parameter returns the number of allocations used out of the
  5932         -** [scratch memory allocator] configured using
  5933         -** [SQLITE_CONFIG_SCRATCH].  The value returned is in allocations, not
  5934         -** in bytes.  Since a single thread may only have one scratch allocation
  5935         -** outstanding at time, this parameter also reports the number of threads
  5936         -** using scratch memory at the same time.</dd>)^
  5937         -**
  5938         -** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  5939         -** <dd>This parameter returns the number of bytes of scratch memory
  5940         -** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
  5941         -** buffer and where forced to overflow to [sqlite3_malloc()].  The values
  5942         -** returned include overflows because the requested allocation was too
  5943         -** larger (that is, because the requested allocation was larger than the
  5944         -** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
  5945         -** slots were available.
  5946         -** </dd>)^
  5947         -**
  5948         -** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  5949         -** <dd>This parameter records the largest memory allocation request
  5950         -** handed to [scratch memory allocator].  Only the value returned in the
  5951         -** *pHighwater parameter to [sqlite3_status()] is of interest.  
  5952         -** The value written into the *pCurrent parameter is undefined.</dd>)^
  5953         -**
  5954         -** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
  5955         -** <dd>This parameter records the deepest parser stack.  It is only
  5956         -** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
  5957         -** </dl>
  5958         -**
  5959         -** New status parameters may be added from time to time.
  5960         -*/
  5961         -#define SQLITE_STATUS_MEMORY_USED          0
  5962         -#define SQLITE_STATUS_PAGECACHE_USED       1
  5963         -#define SQLITE_STATUS_PAGECACHE_OVERFLOW   2
  5964         -#define SQLITE_STATUS_SCRATCH_USED         3
  5965         -#define SQLITE_STATUS_SCRATCH_OVERFLOW     4
  5966         -#define SQLITE_STATUS_MALLOC_SIZE          5
  5967         -#define SQLITE_STATUS_PARSER_STACK         6
  5968         -#define SQLITE_STATUS_PAGECACHE_SIZE       7
  5969         -#define SQLITE_STATUS_SCRATCH_SIZE         8
  5970         -#define SQLITE_STATUS_MALLOC_COUNT         9
  5971         -
  5972         -/*
  5973         -** CAPI3REF: Database Connection Status
  5974         -**
  5975         -** ^This interface is used to retrieve runtime status information 
  5976         -** about a single [database connection].  ^The first argument is the
  5977         -** database connection object to be interrogated.  ^The second argument
  5978         -** is an integer constant, taken from the set of
  5979         -** [SQLITE_DBSTATUS options], that
  5980         -** determines the parameter to interrogate.  The set of 
  5981         -** [SQLITE_DBSTATUS options] is likely
  5982         -** to grow in future releases of SQLite.
  5983         -**
  5984         -** ^The current value of the requested parameter is written into *pCur
  5985         -** and the highest instantaneous value is written into *pHiwtr.  ^If
  5986         -** the resetFlg is true, then the highest instantaneous value is
  5987         -** reset back down to the current value.
  5988         -**
  5989         -** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
  5990         -** non-zero [error code] on failure.
  5991         -**
  5992         -** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  5993         -*/
  5994         -SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  5995         -
  5996         -/*
  5997         -** CAPI3REF: Status Parameters for database connections
  5998         -** KEYWORDS: {SQLITE_DBSTATUS options}
  5999         -**
  6000         -** These constants are the available integer "verbs" that can be passed as
  6001         -** the second argument to the [sqlite3_db_status()] interface.
  6002         -**
  6003         -** New verbs may be added in future releases of SQLite. Existing verbs
  6004         -** might be discontinued. Applications should check the return code from
  6005         -** [sqlite3_db_status()] to make sure that the call worked.
  6006         -** The [sqlite3_db_status()] interface will return a non-zero error code
  6007         -** if a discontinued or unsupported verb is invoked.
  6008         -**
  6009         -** <dl>
  6010         -** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  6011         -** <dd>This parameter returns the number of lookaside memory slots currently
  6012         -** checked out.</dd>)^
  6013         -**
  6014         -** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
  6015         -** <dd>This parameter returns the number malloc attempts that were 
  6016         -** satisfied using lookaside memory. Only the high-water value is meaningful;
  6017         -** the current value is always zero.)^
  6018         -**
  6019         -** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
  6020         -** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
  6021         -** <dd>This parameter returns the number malloc attempts that might have
  6022         -** been satisfied using lookaside memory but failed due to the amount of
  6023         -** memory requested being larger than the lookaside slot size.
  6024         -** Only the high-water value is meaningful;
  6025         -** the current value is always zero.)^
  6026         -**
  6027         -** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
  6028         -** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
  6029         -** <dd>This parameter returns the number malloc attempts that might have
  6030         -** been satisfied using lookaside memory but failed due to all lookaside
  6031         -** memory already being in use.
  6032         -** Only the high-water value is meaningful;
  6033         -** the current value is always zero.)^
  6034         -**
  6035         -** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  6036         -** <dd>This parameter returns the approximate number of of bytes of heap
  6037         -** memory used by all pager caches associated with the database connection.)^
  6038         -** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  6039         -**
  6040         -** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
  6041         -** <dd>This parameter returns the approximate number of of bytes of heap
  6042         -** memory used to store the schema for all databases associated
  6043         -** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 
  6044         -** ^The full amount of memory used by the schemas is reported, even if the
  6045         -** schema memory is shared with other database connections due to
  6046         -** [shared cache mode] being enabled.
  6047         -** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
  6048         -**
  6049         -** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
  6050         -** <dd>This parameter returns the approximate number of of bytes of heap
  6051         -** and lookaside memory used by all prepared statements associated with
  6052         -** the database connection.)^
  6053         -** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
  6054         -** </dd>
  6055         -**
  6056         -** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
  6057         -** <dd>This parameter returns the number of pager cache hits that have
  6058         -** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT 
  6059         -** is always 0.
  6060         -** </dd>
  6061         -**
  6062         -** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
  6063         -** <dd>This parameter returns the number of pager cache misses that have
  6064         -** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS 
  6065         -** is always 0.
  6066         -** </dd>
  6067         -**
  6068         -** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
  6069         -** <dd>This parameter returns the number of dirty cache entries that have
  6070         -** been written to disk. Specifically, the number of pages written to the
  6071         -** wal file in wal mode databases, or the number of pages written to the
  6072         -** database file in rollback mode databases. Any pages written as part of
  6073         -** transaction rollback or database recovery operations are not included.
  6074         -** If an IO or other error occurs while writing a page to disk, the effect
  6075         -** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
  6076         -** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
  6077         -** </dd>
  6078         -** </dl>
  6079         -*/
  6080         -#define SQLITE_DBSTATUS_LOOKASIDE_USED       0
  6081         -#define SQLITE_DBSTATUS_CACHE_USED           1
  6082         -#define SQLITE_DBSTATUS_SCHEMA_USED          2
  6083         -#define SQLITE_DBSTATUS_STMT_USED            3
  6084         -#define SQLITE_DBSTATUS_LOOKASIDE_HIT        4
  6085         -#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE  5
  6086         -#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL  6
  6087         -#define SQLITE_DBSTATUS_CACHE_HIT            7
  6088         -#define SQLITE_DBSTATUS_CACHE_MISS           8
  6089         -#define SQLITE_DBSTATUS_CACHE_WRITE          9
  6090         -#define SQLITE_DBSTATUS_MAX                  9   /* Largest defined DBSTATUS */
  6091         -
  6092         -
  6093         -/*
  6094         -** CAPI3REF: Prepared Statement Status
  6095         -**
  6096         -** ^(Each prepared statement maintains various
  6097         -** [SQLITE_STMTSTATUS counters] that measure the number
  6098         -** of times it has performed specific operations.)^  These counters can
  6099         -** be used to monitor the performance characteristics of the prepared
  6100         -** statements.  For example, if the number of table steps greatly exceeds
  6101         -** the number of table searches or result rows, that would tend to indicate
  6102         -** that the prepared statement is using a full table scan rather than
  6103         -** an index.  
  6104         -**
  6105         -** ^(This interface is used to retrieve and reset counter values from
  6106         -** a [prepared statement].  The first argument is the prepared statement
  6107         -** object to be interrogated.  The second argument
  6108         -** is an integer code for a specific [SQLITE_STMTSTATUS counter]
  6109         -** to be interrogated.)^
  6110         -** ^The current value of the requested counter is returned.
  6111         -** ^If the resetFlg is true, then the counter is reset to zero after this
  6112         -** interface call returns.
  6113         -**
  6114         -** See also: [sqlite3_status()] and [sqlite3_db_status()].
  6115         -*/
  6116         -SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  6117         -
  6118         -/*
  6119         -** CAPI3REF: Status Parameters for prepared statements
  6120         -** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
  6121         -**
  6122         -** These preprocessor macros define integer codes that name counter
  6123         -** values associated with the [sqlite3_stmt_status()] interface.
  6124         -** The meanings of the various counters are as follows:
  6125         -**
  6126         -** <dl>
  6127         -** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
  6128         -** <dd>^This is the number of times that SQLite has stepped forward in
  6129         -** a table as part of a full table scan.  Large numbers for this counter
  6130         -** may indicate opportunities for performance improvement through 
  6131         -** careful use of indices.</dd>
  6132         -**
  6133         -** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
  6134         -** <dd>^This is the number of sort operations that have occurred.
  6135         -** A non-zero value in this counter may indicate an opportunity to
  6136         -** improvement performance through careful use of indices.</dd>
  6137         -**
  6138         -** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
  6139         -** <dd>^This is the number of rows inserted into transient indices that
  6140         -** were created automatically in order to help joins run faster.
  6141         -** A non-zero value in this counter may indicate an opportunity to
  6142         -** improvement performance by adding permanent indices that do not
  6143         -** need to be reinitialized each time the statement is run.</dd>
  6144         -** </dl>
  6145         -*/
  6146         -#define SQLITE_STMTSTATUS_FULLSCAN_STEP     1
  6147         -#define SQLITE_STMTSTATUS_SORT              2
  6148         -#define SQLITE_STMTSTATUS_AUTOINDEX         3
  6149         -
  6150         -/*
  6151         -** CAPI3REF: Custom Page Cache Object
  6152         -**
  6153         -** The sqlite3_pcache type is opaque.  It is implemented by
  6154         -** the pluggable module.  The SQLite core has no knowledge of
  6155         -** its size or internal structure and never deals with the
  6156         -** sqlite3_pcache object except by holding and passing pointers
  6157         -** to the object.
  6158         -**
  6159         -** See [sqlite3_pcache_methods2] for additional information.
  6160         -*/
  6161         -typedef struct sqlite3_pcache sqlite3_pcache;
  6162         -
  6163         -/*
  6164         -** CAPI3REF: Custom Page Cache Object
  6165         -**
  6166         -** The sqlite3_pcache_page object represents a single page in the
  6167         -** page cache.  The page cache will allocate instances of this
  6168         -** object.  Various methods of the page cache use pointers to instances
  6169         -** of this object as parameters or as their return value.
  6170         -**
  6171         -** See [sqlite3_pcache_methods2] for additional information.
  6172         -*/
  6173         -typedef struct sqlite3_pcache_page sqlite3_pcache_page;
  6174         -struct sqlite3_pcache_page {
  6175         -  void *pBuf;        /* The content of the page */
  6176         -  void *pExtra;      /* Extra information associated with the page */
  6177         -};
  6178         -
  6179         -/*
  6180         -** CAPI3REF: Application Defined Page Cache.
  6181         -** KEYWORDS: {page cache}
  6182         -**
  6183         -** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
  6184         -** register an alternative page cache implementation by passing in an 
  6185         -** instance of the sqlite3_pcache_methods2 structure.)^
  6186         -** In many applications, most of the heap memory allocated by 
  6187         -** SQLite is used for the page cache.
  6188         -** By implementing a 
  6189         -** custom page cache using this API, an application can better control
  6190         -** the amount of memory consumed by SQLite, the way in which 
  6191         -** that memory is allocated and released, and the policies used to 
  6192         -** determine exactly which parts of a database file are cached and for 
  6193         -** how long.
  6194         -**
  6195         -** The alternative page cache mechanism is an
  6196         -** extreme measure that is only needed by the most demanding applications.
  6197         -** The built-in page cache is recommended for most uses.
  6198         -**
  6199         -** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
  6200         -** internal buffer by SQLite within the call to [sqlite3_config].  Hence
  6201         -** the application may discard the parameter after the call to
  6202         -** [sqlite3_config()] returns.)^
  6203         -**
  6204         -** [[the xInit() page cache method]]
  6205         -** ^(The xInit() method is called once for each effective 
  6206         -** call to [sqlite3_initialize()])^
  6207         -** (usually only once during the lifetime of the process). ^(The xInit()
  6208         -** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
  6209         -** The intent of the xInit() method is to set up global data structures 
  6210         -** required by the custom page cache implementation. 
  6211         -** ^(If the xInit() method is NULL, then the 
  6212         -** built-in default page cache is used instead of the application defined
  6213         -** page cache.)^
  6214         -**
  6215         -** [[the xShutdown() page cache method]]
  6216         -** ^The xShutdown() method is called by [sqlite3_shutdown()].
  6217         -** It can be used to clean up 
  6218         -** any outstanding resources before process shutdown, if required.
  6219         -** ^The xShutdown() method may be NULL.
  6220         -**
  6221         -** ^SQLite automatically serializes calls to the xInit method,
  6222         -** so the xInit method need not be threadsafe.  ^The
  6223         -** xShutdown method is only called from [sqlite3_shutdown()] so it does
  6224         -** not need to be threadsafe either.  All other methods must be threadsafe
  6225         -** in multithreaded applications.
  6226         -**
  6227         -** ^SQLite will never invoke xInit() more than once without an intervening
  6228         -** call to xShutdown().
  6229         -**
  6230         -** [[the xCreate() page cache methods]]
  6231         -** ^SQLite invokes the xCreate() method to construct a new cache instance.
  6232         -** SQLite will typically create one cache instance for each open database file,
  6233         -** though this is not guaranteed. ^The
  6234         -** first parameter, szPage, is the size in bytes of the pages that must
  6235         -** be allocated by the cache.  ^szPage will always a power of two.  ^The
  6236         -** second parameter szExtra is a number of bytes of extra storage 
  6237         -** associated with each page cache entry.  ^The szExtra parameter will
  6238         -** a number less than 250.  SQLite will use the
  6239         -** extra szExtra bytes on each page to store metadata about the underlying
  6240         -** database page on disk.  The value passed into szExtra depends
  6241         -** on the SQLite version, the target platform, and how SQLite was compiled.
  6242         -** ^The third argument to xCreate(), bPurgeable, is true if the cache being
  6243         -** created will be used to cache database pages of a file stored on disk, or
  6244         -** false if it is used for an in-memory database. The cache implementation
  6245         -** does not have to do anything special based with the value of bPurgeable;
  6246         -** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
  6247         -** never invoke xUnpin() except to deliberately delete a page.
  6248         -** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
  6249         -** false will always have the "discard" flag set to true.  
  6250         -** ^Hence, a cache created with bPurgeable false will
  6251         -** never contain any unpinned pages.
  6252         -**
  6253         -** [[the xCachesize() page cache method]]
  6254         -** ^(The xCachesize() method may be called at any time by SQLite to set the
  6255         -** suggested maximum cache-size (number of pages stored by) the cache
  6256         -** instance passed as the first argument. This is the value configured using
  6257         -** the SQLite "[PRAGMA cache_size]" command.)^  As with the bPurgeable
  6258         -** parameter, the implementation is not required to do anything with this
  6259         -** value; it is advisory only.
  6260         -**
  6261         -** [[the xPagecount() page cache methods]]
  6262         -** The xPagecount() method must return the number of pages currently
  6263         -** stored in the cache, both pinned and unpinned.
  6264         -** 
  6265         -** [[the xFetch() page cache methods]]
  6266         -** The xFetch() method locates a page in the cache and returns a pointer to 
  6267         -** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
  6268         -** The pBuf element of the returned sqlite3_pcache_page object will be a
  6269         -** pointer to a buffer of szPage bytes used to store the content of a 
  6270         -** single database page.  The pExtra element of sqlite3_pcache_page will be
  6271         -** a pointer to the szExtra bytes of extra storage that SQLite has requested
  6272         -** for each entry in the page cache.
  6273         -**
  6274         -** The page to be fetched is determined by the key. ^The minimum key value
  6275         -** is 1.  After it has been retrieved using xFetch, the page is considered
  6276         -** to be "pinned".
  6277         -**
  6278         -** If the requested page is already in the page cache, then the page cache
  6279         -** implementation must return a pointer to the page buffer with its content
  6280         -** intact.  If the requested page is not already in the cache, then the
  6281         -** cache implementation should use the value of the createFlag
  6282         -** parameter to help it determined what action to take:
  6283         -**
  6284         -** <table border=1 width=85% align=center>
  6285         -** <tr><th> createFlag <th> Behaviour when page is not already in cache
  6286         -** <tr><td> 0 <td> Do not allocate a new page.  Return NULL.
  6287         -** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
  6288         -**                 Otherwise return NULL.
  6289         -** <tr><td> 2 <td> Make every effort to allocate a new page.  Only return
  6290         -**                 NULL if allocating a new page is effectively impossible.
  6291         -** </table>
  6292         -**
  6293         -** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1.  SQLite
  6294         -** will only use a createFlag of 2 after a prior call with a createFlag of 1
  6295         -** failed.)^  In between the to xFetch() calls, SQLite may
  6296         -** attempt to unpin one or more cache pages by spilling the content of
  6297         -** pinned pages to disk and synching the operating system disk cache.
  6298         -**
  6299         -** [[the xUnpin() page cache method]]
  6300         -** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
  6301         -** as its second argument.  If the third parameter, discard, is non-zero,
  6302         -** then the page must be evicted from the cache.
  6303         -** ^If the discard parameter is
  6304         -** zero, then the page may be discarded or retained at the discretion of
  6305         -** page cache implementation. ^The page cache implementation
  6306         -** may choose to evict unpinned pages at any time.
  6307         -**
  6308         -** The cache must not perform any reference counting. A single 
  6309         -** call to xUnpin() unpins the page regardless of the number of prior calls 
  6310         -** to xFetch().
  6311         -**
  6312         -** [[the xRekey() page cache methods]]
  6313         -** The xRekey() method is used to change the key value associated with the
  6314         -** page passed as the second argument. If the cache
  6315         -** previously contains an entry associated with newKey, it must be
  6316         -** discarded. ^Any prior cache entry associated with newKey is guaranteed not
  6317         -** to be pinned.
  6318         -**
  6319         -** When SQLite calls the xTruncate() method, the cache must discard all
  6320         -** existing cache entries with page numbers (keys) greater than or equal
  6321         -** to the value of the iLimit parameter passed to xTruncate(). If any
  6322         -** of these pages are pinned, they are implicitly unpinned, meaning that
  6323         -** they can be safely discarded.
  6324         -**
  6325         -** [[the xDestroy() page cache method]]
  6326         -** ^The xDestroy() method is used to delete a cache allocated by xCreate().
  6327         -** All resources associated with the specified cache should be freed. ^After
  6328         -** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  6329         -** handle invalid, and will not use it with any other sqlite3_pcache_methods2
  6330         -** functions.
  6331         -**
  6332         -** [[the xShrink() page cache method]]
  6333         -** ^SQLite invokes the xShrink() method when it wants the page cache to
  6334         -** free up as much of heap memory as possible.  The page cache implementation
  6335         -** is not obligated to free any memory, but well-behaved implementations should
  6336         -** do their best.
  6337         -*/
  6338         -typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
  6339         -struct sqlite3_pcache_methods2 {
  6340         -  int iVersion;
  6341         -  void *pArg;
  6342         -  int (*xInit)(void*);
  6343         -  void (*xShutdown)(void*);
  6344         -  sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
  6345         -  void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  6346         -  int (*xPagecount)(sqlite3_pcache*);
  6347         -  sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  6348         -  void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
  6349         -  void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, 
  6350         -      unsigned oldKey, unsigned newKey);
  6351         -  void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  6352         -  void (*xDestroy)(sqlite3_pcache*);
  6353         -  void (*xShrink)(sqlite3_pcache*);
  6354         -};
  6355         -
  6356         -/*
  6357         -** This is the obsolete pcache_methods object that has now been replaced
  6358         -** by sqlite3_pcache_methods2.  This object is not used by SQLite.  It is
  6359         -** retained in the header file for backwards compatibility only.
  6360         -*/
  6361         -typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  6362         -struct sqlite3_pcache_methods {
  6363         -  void *pArg;
  6364         -  int (*xInit)(void*);
  6365         -  void (*xShutdown)(void*);
  6366         -  sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
  6367         -  void (*xCachesize)(sqlite3_pcache*, int nCachesize);
  6368         -  int (*xPagecount)(sqlite3_pcache*);
  6369         -  void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  6370         -  void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  6371         -  void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  6372         -  void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  6373         -  void (*xDestroy)(sqlite3_pcache*);
  6374         -};
  6375         -
  6376         -
  6377         -/*
  6378         -** CAPI3REF: Online Backup Object
  6379         -**
  6380         -** The sqlite3_backup object records state information about an ongoing
  6381         -** online backup operation.  ^The sqlite3_backup object is created by
  6382         -** a call to [sqlite3_backup_init()] and is destroyed by a call to
  6383         -** [sqlite3_backup_finish()].
  6384         -**
  6385         -** See Also: [Using the SQLite Online Backup API]
  6386         -*/
  6387         -typedef struct sqlite3_backup sqlite3_backup;
  6388         -
  6389         -/*
  6390         -** CAPI3REF: Online Backup API.
  6391         -**
  6392         -** The backup API copies the content of one database into another.
  6393         -** It is useful either for creating backups of databases or
  6394         -** for copying in-memory databases to or from persistent files. 
  6395         -**
  6396         -** See Also: [Using the SQLite Online Backup API]
  6397         -**
  6398         -** ^SQLite holds a write transaction open on the destination database file
  6399         -** for the duration of the backup operation.
  6400         -** ^The source database is read-locked only while it is being read;
  6401         -** it is not locked continuously for the entire backup operation.
  6402         -** ^Thus, the backup may be performed on a live source database without
  6403         -** preventing other database connections from
  6404         -** reading or writing to the source database while the backup is underway.
  6405         -** 
  6406         -** ^(To perform a backup operation: 
  6407         -**   <ol>
  6408         -**     <li><b>sqlite3_backup_init()</b> is called once to initialize the
  6409         -**         backup, 
  6410         -**     <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 
  6411         -**         the data between the two databases, and finally
  6412         -**     <li><b>sqlite3_backup_finish()</b> is called to release all resources 
  6413         -**         associated with the backup operation. 
  6414         -**   </ol>)^
  6415         -** There should be exactly one call to sqlite3_backup_finish() for each
  6416         -** successful call to sqlite3_backup_init().
  6417         -**
  6418         -** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
  6419         -**
  6420         -** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 
  6421         -** [database connection] associated with the destination database 
  6422         -** and the database name, respectively.
  6423         -** ^The database name is "main" for the main database, "temp" for the
  6424         -** temporary database, or the name specified after the AS keyword in
  6425         -** an [ATTACH] statement for an attached database.
  6426         -** ^The S and M arguments passed to 
  6427         -** sqlite3_backup_init(D,N,S,M) identify the [database connection]
  6428         -** and database name of the source database, respectively.
  6429         -** ^The source and destination [database connections] (parameters S and D)
  6430         -** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
  6431         -** an error.
  6432         -**
  6433         -** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
  6434         -** returned and an error code and error message are stored in the
  6435         -** destination [database connection] D.
  6436         -** ^The error code and message for the failed call to sqlite3_backup_init()
  6437         -** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
  6438         -** [sqlite3_errmsg16()] functions.
  6439         -** ^A successful call to sqlite3_backup_init() returns a pointer to an
  6440         -** [sqlite3_backup] object.
  6441         -** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
  6442         -** sqlite3_backup_finish() functions to perform the specified backup 
  6443         -** operation.
  6444         -**
  6445         -** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
  6446         -**
  6447         -** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 
  6448         -** the source and destination databases specified by [sqlite3_backup] object B.
  6449         -** ^If N is negative, all remaining source pages are copied. 
  6450         -** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
  6451         -** are still more pages to be copied, then the function returns [SQLITE_OK].
  6452         -** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
  6453         -** from source to destination, then it returns [SQLITE_DONE].
  6454         -** ^If an error occurs while running sqlite3_backup_step(B,N),
  6455         -** then an [error code] is returned. ^As well as [SQLITE_OK] and
  6456         -** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
  6457         -** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
  6458         -** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
  6459         -**
  6460         -** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
  6461         -** <ol>
  6462         -** <li> the destination database was opened read-only, or
  6463         -** <li> the destination database is using write-ahead-log journaling
  6464         -** and the destination and source page sizes differ, or
  6465         -** <li> the destination database is an in-memory database and the
  6466         -** destination and source page sizes differ.
  6467         -** </ol>)^
  6468         -**
  6469         -** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
  6470         -** the [sqlite3_busy_handler | busy-handler function]
  6471         -** is invoked (if one is specified). ^If the 
  6472         -** busy-handler returns non-zero before the lock is available, then 
  6473         -** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
  6474         -** sqlite3_backup_step() can be retried later. ^If the source
  6475         -** [database connection]
  6476         -** is being used to write to the source database when sqlite3_backup_step()
  6477         -** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
  6478         -** case the call to sqlite3_backup_step() can be retried later on. ^(If
  6479         -** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
  6480         -** [SQLITE_READONLY] is returned, then 
  6481         -** there is no point in retrying the call to sqlite3_backup_step(). These 
  6482         -** errors are considered fatal.)^  The application must accept 
  6483         -** that the backup operation has failed and pass the backup operation handle 
  6484         -** to the sqlite3_backup_finish() to release associated resources.
  6485         -**
  6486         -** ^The first call to sqlite3_backup_step() obtains an exclusive lock
  6487         -** on the destination file. ^The exclusive lock is not released until either 
  6488         -** sqlite3_backup_finish() is called or the backup operation is complete 
  6489         -** and sqlite3_backup_step() returns [SQLITE_DONE].  ^Every call to
  6490         -** sqlite3_backup_step() obtains a [shared lock] on the source database that
  6491         -** lasts for the duration of the sqlite3_backup_step() call.
  6492         -** ^Because the source database is not locked between calls to
  6493         -** sqlite3_backup_step(), the source database may be modified mid-way
  6494         -** through the backup process.  ^If the source database is modified by an
  6495         -** external process or via a database connection other than the one being
  6496         -** used by the backup operation, then the backup will be automatically
  6497         -** restarted by the next call to sqlite3_backup_step(). ^If the source 
  6498         -** database is modified by the using the same database connection as is used
  6499         -** by the backup operation, then the backup database is automatically
  6500         -** updated at the same time.
  6501         -**
  6502         -** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
  6503         -**
  6504         -** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 
  6505         -** application wishes to abandon the backup operation, the application
  6506         -** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
  6507         -** ^The sqlite3_backup_finish() interfaces releases all
  6508         -** resources associated with the [sqlite3_backup] object. 
  6509         -** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
  6510         -** active write-transaction on the destination database is rolled back.
  6511         -** The [sqlite3_backup] object is invalid
  6512         -** and may not be used following a call to sqlite3_backup_finish().
  6513         -**
  6514         -** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
  6515         -** sqlite3_backup_step() errors occurred, regardless or whether or not
  6516         -** sqlite3_backup_step() completed.
  6517         -** ^If an out-of-memory condition or IO error occurred during any prior
  6518         -** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
  6519         -** sqlite3_backup_finish() returns the corresponding [error code].
  6520         -**
  6521         -** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
  6522         -** is not a permanent error and does not affect the return value of
  6523         -** sqlite3_backup_finish().
  6524         -**
  6525         -** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
  6526         -** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
  6527         -**
  6528         -** ^Each call to sqlite3_backup_step() sets two values inside
  6529         -** the [sqlite3_backup] object: the number of pages still to be backed
  6530         -** up and the total number of pages in the source database file.
  6531         -** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
  6532         -** retrieve these two values, respectively.
  6533         -**
  6534         -** ^The values returned by these functions are only updated by
  6535         -** sqlite3_backup_step(). ^If the source database is modified during a backup
  6536         -** operation, then the values are not updated to account for any extra
  6537         -** pages that need to be updated or the size of the source database file
  6538         -** changing.
  6539         -**
  6540         -** <b>Concurrent Usage of Database Handles</b>
  6541         -**
  6542         -** ^The source [database connection] may be used by the application for other
  6543         -** purposes while a backup operation is underway or being initialized.
  6544         -** ^If SQLite is compiled and configured to support threadsafe database
  6545         -** connections, then the source database connection may be used concurrently
  6546         -** from within other threads.
  6547         -**
  6548         -** However, the application must guarantee that the destination 
  6549         -** [database connection] is not passed to any other API (by any thread) after 
  6550         -** sqlite3_backup_init() is called and before the corresponding call to
  6551         -** sqlite3_backup_finish().  SQLite does not currently check to see
  6552         -** if the application incorrectly accesses the destination [database connection]
  6553         -** and so no error code is reported, but the operations may malfunction
  6554         -** nevertheless.  Use of the destination database connection while a
  6555         -** backup is in progress might also also cause a mutex deadlock.
  6556         -**
  6557         -** If running in [shared cache mode], the application must
  6558         -** guarantee that the shared cache used by the destination database
  6559         -** is not accessed while the backup is running. In practice this means
  6560         -** that the application must guarantee that the disk file being 
  6561         -** backed up to is not accessed by any connection within the process,
  6562         -** not just the specific connection that was passed to sqlite3_backup_init().
  6563         -**
  6564         -** The [sqlite3_backup] object itself is partially threadsafe. Multiple 
  6565         -** threads may safely make multiple concurrent calls to sqlite3_backup_step().
  6566         -** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
  6567         -** APIs are not strictly speaking threadsafe. If they are invoked at the
  6568         -** same time as another thread is invoking sqlite3_backup_step() it is
  6569         -** possible that they return invalid values.
  6570         -*/
  6571         -SQLITE_API sqlite3_backup *sqlite3_backup_init(
  6572         -  sqlite3 *pDest,                        /* Destination database handle */
  6573         -  const char *zDestName,                 /* Destination database name */
  6574         -  sqlite3 *pSource,                      /* Source database handle */
  6575         -  const char *zSourceName                /* Source database name */
  6576         -);
  6577         -SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
  6578         -SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
  6579         -SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
  6580         -SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
  6581         -
  6582         -/*
  6583         -** CAPI3REF: Unlock Notification
  6584         -**
  6585         -** ^When running in shared-cache mode, a database operation may fail with
  6586         -** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
  6587         -** individual tables within the shared-cache cannot be obtained. See
  6588         -** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 
  6589         -** ^This API may be used to register a callback that SQLite will invoke 
  6590         -** when the connection currently holding the required lock relinquishes it.
  6591         -** ^This API is only available if the library was compiled with the
  6592         -** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
  6593         -**
  6594         -** See Also: [Using the SQLite Unlock Notification Feature].
  6595         -**
  6596         -** ^Shared-cache locks are released when a database connection concludes
  6597         -** its current transaction, either by committing it or rolling it back. 
  6598         -**
  6599         -** ^When a connection (known as the blocked connection) fails to obtain a
  6600         -** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
  6601         -** identity of the database connection (the blocking connection) that
  6602         -** has locked the required resource is stored internally. ^After an 
  6603         -** application receives an SQLITE_LOCKED error, it may call the
  6604         -** sqlite3_unlock_notify() method with the blocked connection handle as 
  6605         -** the first argument to register for a callback that will be invoked
  6606         -** when the blocking connections current transaction is concluded. ^The
  6607         -** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
  6608         -** call that concludes the blocking connections transaction.
  6609         -**
  6610         -** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
  6611         -** there is a chance that the blocking connection will have already
  6612         -** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
  6613         -** If this happens, then the specified callback is invoked immediately,
  6614         -** from within the call to sqlite3_unlock_notify().)^
  6615         -**
  6616         -** ^If the blocked connection is attempting to obtain a write-lock on a
  6617         -** shared-cache table, and more than one other connection currently holds
  6618         -** a read-lock on the same table, then SQLite arbitrarily selects one of 
  6619         -** the other connections to use as the blocking connection.
  6620         -**
  6621         -** ^(There may be at most one unlock-notify callback registered by a 
  6622         -** blocked connection. If sqlite3_unlock_notify() is called when the
  6623         -** blocked connection already has a registered unlock-notify callback,
  6624         -** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
  6625         -** called with a NULL pointer as its second argument, then any existing
  6626         -** unlock-notify callback is canceled. ^The blocked connections 
  6627         -** unlock-notify callback may also be canceled by closing the blocked
  6628         -** connection using [sqlite3_close()].
  6629         -**
  6630         -** The unlock-notify callback is not reentrant. If an application invokes
  6631         -** any sqlite3_xxx API functions from within an unlock-notify callback, a
  6632         -** crash or deadlock may be the result.
  6633         -**
  6634         -** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
  6635         -** returns SQLITE_OK.
  6636         -**
  6637         -** <b>Callback Invocation Details</b>
  6638         -**
  6639         -** When an unlock-notify callback is registered, the application provides a 
  6640         -** single void* pointer that is passed to the callback when it is invoked.
  6641         -** However, the signature of the callback function allows SQLite to pass
  6642         -** it an array of void* context pointers. The first argument passed to
  6643         -** an unlock-notify callback is a pointer to an array of void* pointers,
  6644         -** and the second is the number of entries in the array.
  6645         -**
  6646         -** When a blocking connections transaction is concluded, there may be
  6647         -** more than one blocked connection that has registered for an unlock-notify
  6648         -** callback. ^If two or more such blocked connections have specified the
  6649         -** same callback function, then instead of invoking the callback function
  6650         -** multiple times, it is invoked once with the set of void* context pointers
  6651         -** specified by the blocked connections bundled together into an array.
  6652         -** This gives the application an opportunity to prioritize any actions 
  6653         -** related to the set of unblocked database connections.
  6654         -**
  6655         -** <b>Deadlock Detection</b>
  6656         -**
  6657         -** Assuming that after registering for an unlock-notify callback a 
  6658         -** database waits for the callback to be issued before taking any further
  6659         -** action (a reasonable assumption), then using this API may cause the
  6660         -** application to deadlock. For example, if connection X is waiting for
  6661         -** connection Y's transaction to be concluded, and similarly connection
  6662         -** Y is waiting on connection X's transaction, then neither connection
  6663         -** will proceed and the system may remain deadlocked indefinitely.
  6664         -**
  6665         -** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
  6666         -** detection. ^If a given call to sqlite3_unlock_notify() would put the
  6667         -** system in a deadlocked state, then SQLITE_LOCKED is returned and no
  6668         -** unlock-notify callback is registered. The system is said to be in
  6669         -** a deadlocked state if connection A has registered for an unlock-notify
  6670         -** callback on the conclusion of connection B's transaction, and connection
  6671         -** B has itself registered for an unlock-notify callback when connection
  6672         -** A's transaction is concluded. ^Indirect deadlock is also detected, so
  6673         -** the system is also considered to be deadlocked if connection B has
  6674         -** registered for an unlock-notify callback on the conclusion of connection
  6675         -** C's transaction, where connection C is waiting on connection A. ^Any
  6676         -** number of levels of indirection are allowed.
  6677         -**
  6678         -** <b>The "DROP TABLE" Exception</b>
  6679         -**
  6680         -** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost 
  6681         -** always appropriate to call sqlite3_unlock_notify(). There is however,
  6682         -** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
  6683         -** SQLite checks if there are any currently executing SELECT statements
  6684         -** that belong to the same connection. If there are, SQLITE_LOCKED is
  6685         -** returned. In this case there is no "blocking connection", so invoking
  6686         -** sqlite3_unlock_notify() results in the unlock-notify callback being
  6687         -** invoked immediately. If the application then re-attempts the "DROP TABLE"
  6688         -** or "DROP INDEX" query, an infinite loop might be the result.
  6689         -**
  6690         -** One way around this problem is to check the extended error code returned
  6691         -** by an sqlite3_step() call. ^(If there is a blocking connection, then the
  6692         -** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
  6693         -** the special "DROP TABLE/INDEX" case, the extended error code is just 
  6694         -** SQLITE_LOCKED.)^
  6695         -*/
  6696         -SQLITE_API int sqlite3_unlock_notify(
  6697         -  sqlite3 *pBlocked,                          /* Waiting connection */
  6698         -  void (*xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
  6699         -  void *pNotifyArg                            /* Argument to pass to xNotify */
  6700         -);
  6701         -
  6702         -
  6703         -/*
  6704         -** CAPI3REF: String Comparison
  6705         -**
  6706         -** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
  6707         -** and extensions to compare the contents of two buffers containing UTF-8
  6708         -** strings in a case-independent fashion, using the same definition of "case
  6709         -** independence" that SQLite uses internally when comparing identifiers.
  6710         -*/
  6711         -SQLITE_API int sqlite3_stricmp(const char *, const char *);
  6712         -SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
  6713         -
  6714         -/*
  6715         -** CAPI3REF: Error Logging Interface
  6716         -**
  6717         -** ^The [sqlite3_log()] interface writes a message into the error log
  6718         -** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
  6719         -** ^If logging is enabled, the zFormat string and subsequent arguments are
  6720         -** used with [sqlite3_snprintf()] to generate the final output string.
  6721         -**
  6722         -** The sqlite3_log() interface is intended for use by extensions such as
  6723         -** virtual tables, collating functions, and SQL functions.  While there is
  6724         -** nothing to prevent an application from calling sqlite3_log(), doing so
  6725         -** is considered bad form.
  6726         -**
  6727         -** The zFormat string must not be NULL.
  6728         -**
  6729         -** To avoid deadlocks and other threading problems, the sqlite3_log() routine
  6730         -** will not use dynamically allocated memory.  The log message is stored in
  6731         -** a fixed-length buffer on the stack.  If the log message is longer than
  6732         -** a few hundred characters, it will be truncated to the length of the
  6733         -** buffer.
  6734         -*/
  6735         -SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
  6736         -
  6737         -/*
  6738         -** CAPI3REF: Write-Ahead Log Commit Hook
  6739         -**
  6740         -** ^The [sqlite3_wal_hook()] function is used to register a callback that
  6741         -** will be invoked each time a database connection commits data to a
  6742         -** [write-ahead log] (i.e. whenever a transaction is committed in
  6743         -** [journal_mode | journal_mode=WAL mode]). 
  6744         -**
  6745         -** ^The callback is invoked by SQLite after the commit has taken place and 
  6746         -** the associated write-lock on the database released, so the implementation 
  6747         -** may read, write or [checkpoint] the database as required.
  6748         -**
  6749         -** ^The first parameter passed to the callback function when it is invoked
  6750         -** is a copy of the third parameter passed to sqlite3_wal_hook() when
  6751         -** registering the callback. ^The second is a copy of the database handle.
  6752         -** ^The third parameter is the name of the database that was written to -
  6753         -** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
  6754         -** is the number of pages currently in the write-ahead log file,
  6755         -** including those that were just committed.
  6756         -**
  6757         -** The callback function should normally return [SQLITE_OK].  ^If an error
  6758         -** code is returned, that error will propagate back up through the
  6759         -** SQLite code base to cause the statement that provoked the callback
  6760         -** to report an error, though the commit will have still occurred. If the
  6761         -** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
  6762         -** that does not correspond to any valid SQLite error code, the results
  6763         -** are undefined.
  6764         -**
  6765         -** A single database handle may have at most a single write-ahead log callback 
  6766         -** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
  6767         -** previously registered write-ahead log callback. ^Note that the
  6768         -** [sqlite3_wal_autocheckpoint()] interface and the
  6769         -** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
  6770         -** those overwrite any prior [sqlite3_wal_hook()] settings.
  6771         -*/
  6772         -SQLITE_API void *sqlite3_wal_hook(
  6773         -  sqlite3*, 
  6774         -  int(*)(void *,sqlite3*,const char*,int),
  6775         -  void*
  6776         -);
  6777         -
  6778         -/*
  6779         -** CAPI3REF: Configure an auto-checkpoint
  6780         -**
  6781         -** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
  6782         -** [sqlite3_wal_hook()] that causes any database on [database connection] D
  6783         -** to automatically [checkpoint]
  6784         -** after committing a transaction if there are N or
  6785         -** more frames in the [write-ahead log] file.  ^Passing zero or 
  6786         -** a negative value as the nFrame parameter disables automatic
  6787         -** checkpoints entirely.
  6788         -**
  6789         -** ^The callback registered by this function replaces any existing callback
  6790         -** registered using [sqlite3_wal_hook()].  ^Likewise, registering a callback
  6791         -** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
  6792         -** configured by this function.
  6793         -**
  6794         -** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
  6795         -** from SQL.
  6796         -**
  6797         -** ^Every new [database connection] defaults to having the auto-checkpoint
  6798         -** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
  6799         -** pages.  The use of this interface
  6800         -** is only necessary if the default setting is found to be suboptimal
  6801         -** for a particular application.
  6802         -*/
  6803         -SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  6804         -
  6805         -/*
  6806         -** CAPI3REF: Checkpoint a database
  6807         -**
  6808         -** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
  6809         -** on [database connection] D to be [checkpointed].  ^If X is NULL or an
  6810         -** empty string, then a checkpoint is run on all databases of
  6811         -** connection D.  ^If the database connection D is not in
  6812         -** [WAL | write-ahead log mode] then this interface is a harmless no-op.
  6813         -**
  6814         -** ^The [wal_checkpoint pragma] can be used to invoke this interface
  6815         -** from SQL.  ^The [sqlite3_wal_autocheckpoint()] interface and the
  6816         -** [wal_autocheckpoint pragma] can be used to cause this interface to be
  6817         -** run whenever the WAL reaches a certain size threshold.
  6818         -**
  6819         -** See also: [sqlite3_wal_checkpoint_v2()]
  6820         -*/
  6821         -SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
  6822         -
  6823         -/*
  6824         -** CAPI3REF: Checkpoint a database
  6825         -**
  6826         -** Run a checkpoint operation on WAL database zDb attached to database 
  6827         -** handle db. The specific operation is determined by the value of the 
  6828         -** eMode parameter:
  6829         -**
  6830         -** <dl>
  6831         -** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
  6832         -**   Checkpoint as many frames as possible without waiting for any database 
  6833         -**   readers or writers to finish. Sync the db file if all frames in the log
  6834         -**   are checkpointed. This mode is the same as calling 
  6835         -**   sqlite3_wal_checkpoint(). The busy-handler callback is never invoked.
  6836         -**
  6837         -** <dt>SQLITE_CHECKPOINT_FULL<dd>
  6838         -**   This mode blocks (calls the busy-handler callback) until there is no
  6839         -**   database writer and all readers are reading from the most recent database
  6840         -**   snapshot. It then checkpoints all frames in the log file and syncs the
  6841         -**   database file. This call blocks database writers while it is running,
  6842         -**   but not database readers.
  6843         -**
  6844         -** <dt>SQLITE_CHECKPOINT_RESTART<dd>
  6845         -**   This mode works the same way as SQLITE_CHECKPOINT_FULL, except after 
  6846         -**   checkpointing the log file it blocks (calls the busy-handler callback)
  6847         -**   until all readers are reading from the database file only. This ensures 
  6848         -**   that the next client to write to the database file restarts the log file 
  6849         -**   from the beginning. This call blocks database writers while it is running,
  6850         -**   but not database readers.
  6851         -** </dl>
  6852         -**
  6853         -** If pnLog is not NULL, then *pnLog is set to the total number of frames in
  6854         -** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
  6855         -** the total number of checkpointed frames (including any that were already
  6856         -** checkpointed when this function is called). *pnLog and *pnCkpt may be
  6857         -** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK.
  6858         -** If no values are available because of an error, they are both set to -1
  6859         -** before returning to communicate this to the caller.
  6860         -**
  6861         -** All calls obtain an exclusive "checkpoint" lock on the database file. If
  6862         -** any other process is running a checkpoint operation at the same time, the 
  6863         -** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a 
  6864         -** busy-handler configured, it will not be invoked in this case.
  6865         -**
  6866         -** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive 
  6867         -** "writer" lock on the database file. If the writer lock cannot be obtained
  6868         -** immediately, and a busy-handler is configured, it is invoked and the writer
  6869         -** lock retried until either the busy-handler returns 0 or the lock is
  6870         -** successfully obtained. The busy-handler is also invoked while waiting for
  6871         -** database readers as described above. If the busy-handler returns 0 before
  6872         -** the writer lock is obtained or while waiting for database readers, the
  6873         -** checkpoint operation proceeds from that point in the same way as 
  6874         -** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible 
  6875         -** without blocking any further. SQLITE_BUSY is returned in this case.
  6876         -**
  6877         -** If parameter zDb is NULL or points to a zero length string, then the
  6878         -** specified operation is attempted on all WAL databases. In this case the
  6879         -** values written to output parameters *pnLog and *pnCkpt are undefined. If 
  6880         -** an SQLITE_BUSY error is encountered when processing one or more of the 
  6881         -** attached WAL databases, the operation is still attempted on any remaining 
  6882         -** attached databases and SQLITE_BUSY is returned to the caller. If any other 
  6883         -** error occurs while processing an attached database, processing is abandoned 
  6884         -** and the error code returned to the caller immediately. If no error 
  6885         -** (SQLITE_BUSY or otherwise) is encountered while processing the attached 
  6886         -** databases, SQLITE_OK is returned.
  6887         -**
  6888         -** If database zDb is the name of an attached database that is not in WAL
  6889         -** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If
  6890         -** zDb is not NULL (or a zero length string) and is not the name of any
  6891         -** attached database, SQLITE_ERROR is returned to the caller.
  6892         -*/
  6893         -SQLITE_API int sqlite3_wal_checkpoint_v2(
  6894         -  sqlite3 *db,                    /* Database handle */
  6895         -  const char *zDb,                /* Name of attached database (or NULL) */
  6896         -  int eMode,                      /* SQLITE_CHECKPOINT_* value */
  6897         -  int *pnLog,                     /* OUT: Size of WAL log in frames */
  6898         -  int *pnCkpt                     /* OUT: Total number of frames checkpointed */
  6899         -);
  6900         -
  6901         -/*
  6902         -** CAPI3REF: Checkpoint operation parameters
  6903         -**
  6904         -** These constants can be used as the 3rd parameter to
  6905         -** [sqlite3_wal_checkpoint_v2()].  See the [sqlite3_wal_checkpoint_v2()]
  6906         -** documentation for additional information about the meaning and use of
  6907         -** each of these values.
  6908         -*/
  6909         -#define SQLITE_CHECKPOINT_PASSIVE 0
  6910         -#define SQLITE_CHECKPOINT_FULL    1
  6911         -#define SQLITE_CHECKPOINT_RESTART 2
  6912         -
  6913         -/*
  6914         -** CAPI3REF: Virtual Table Interface Configuration
  6915         -**
  6916         -** This function may be called by either the [xConnect] or [xCreate] method
  6917         -** of a [virtual table] implementation to configure
  6918         -** various facets of the virtual table interface.
  6919         -**
  6920         -** If this interface is invoked outside the context of an xConnect or
  6921         -** xCreate virtual table method then the behavior is undefined.
  6922         -**
  6923         -** At present, there is only one option that may be configured using
  6924         -** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].)  Further options
  6925         -** may be added in the future.
  6926         -*/
  6927         -SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
  6928         -
  6929         -/*
  6930         -** CAPI3REF: Virtual Table Configuration Options
  6931         -**
  6932         -** These macros define the various options to the
  6933         -** [sqlite3_vtab_config()] interface that [virtual table] implementations
  6934         -** can use to customize and optimize their behavior.
  6935         -**
  6936         -** <dl>
  6937         -** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
  6938         -** <dd>Calls of the form
  6939         -** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
  6940         -** where X is an integer.  If X is zero, then the [virtual table] whose
  6941         -** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
  6942         -** support constraints.  In this configuration (which is the default) if
  6943         -** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
  6944         -** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
  6945         -** specified as part of the users SQL statement, regardless of the actual
  6946         -** ON CONFLICT mode specified.
  6947         -**
  6948         -** If X is non-zero, then the virtual table implementation guarantees
  6949         -** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
  6950         -** any modifications to internal or persistent data structures have been made.
  6951         -** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite 
  6952         -** is able to roll back a statement or database transaction, and abandon
  6953         -** or continue processing the current SQL statement as appropriate. 
  6954         -** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
  6955         -** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
  6956         -** had been ABORT.
  6957         -**
  6958         -** Virtual table implementations that are required to handle OR REPLACE
  6959         -** must do so within the [xUpdate] method. If a call to the 
  6960         -** [sqlite3_vtab_on_conflict()] function indicates that the current ON 
  6961         -** CONFLICT policy is REPLACE, the virtual table implementation should 
  6962         -** silently replace the appropriate rows within the xUpdate callback and
  6963         -** return SQLITE_OK. Or, if this is not possible, it may return
  6964         -** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT 
  6965         -** constraint handling.
  6966         -** </dl>
  6967         -*/
  6968         -#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
  6969         -
  6970         -/*
  6971         -** CAPI3REF: Determine The Virtual Table Conflict Policy
  6972         -**
  6973         -** This function may only be called from within a call to the [xUpdate] method
  6974         -** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
  6975         -** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
  6976         -** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
  6977         -** of the SQL statement that triggered the call to the [xUpdate] method of the
  6978         -** [virtual table].
  6979         -*/
  6980         -SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
  6981         -
  6982         -/*
  6983         -** CAPI3REF: Conflict resolution modes
  6984         -**
  6985         -** These constants are returned by [sqlite3_vtab_on_conflict()] to
  6986         -** inform a [virtual table] implementation what the [ON CONFLICT] mode
  6987         -** is for the SQL statement being evaluated.
  6988         -**
  6989         -** Note that the [SQLITE_IGNORE] constant is also used as a potential
  6990         -** return value from the [sqlite3_set_authorizer()] callback and that
  6991         -** [SQLITE_ABORT] is also a [result code].
  6992         -*/
  6993         -#define SQLITE_ROLLBACK 1
  6994         -/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
  6995         -#define SQLITE_FAIL     3
  6996         -/* #define SQLITE_ABORT 4  // Also an error code */
  6997         -#define SQLITE_REPLACE  5
  6998         -
  6999         -
  7000         -
  7001         -/*
  7002         -** Undo the hack that converts floating point types to integer for
  7003         -** builds on processors without floating point support.
  7004         -*/
  7005         -#ifdef SQLITE_OMIT_FLOATING_POINT
  7006         -# undef double
  7007         -#endif
  7008         -
  7009         -#ifdef __cplusplus
  7010         -}  /* End of the 'extern "C"' block */
  7011         -#endif
  7012         -#endif
  7013         -
  7014         -/*
  7015         -** 2010 August 30
  7016         -**
  7017         -** The author disclaims copyright to this source code.  In place of
  7018         -** a legal notice, here is a blessing:
  7019         -**
  7020         -**    May you do good and not evil.
  7021         -**    May you find forgiveness for yourself and forgive others.
  7022         -**    May you share freely, never taking more than you give.
  7023         -**
  7024         -*************************************************************************
  7025         -*/
  7026         -
  7027         -#ifndef _SQLITE3RTREE_H_
  7028         -#define _SQLITE3RTREE_H_
  7029         -
  7030         -
  7031         -#ifdef __cplusplus
  7032         -extern "C" {
  7033         -#endif
  7034         -
  7035         -typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
  7036         -
  7037         -/*
  7038         -** Register a geometry callback named zGeom that can be used as part of an
  7039         -** R-Tree geometry query as follows:
  7040         -**
  7041         -**   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
  7042         -*/
  7043         -SQLITE_API int sqlite3_rtree_geometry_callback(
  7044         -  sqlite3 *db,
  7045         -  const char *zGeom,
  7046         -#ifdef SQLITE_RTREE_INT_ONLY
  7047         -  int (*xGeom)(sqlite3_rtree_geometry*, int n, sqlite3_int64 *a, int *pRes),
  7048         -#else
  7049         -  int (*xGeom)(sqlite3_rtree_geometry*, int n, double *a, int *pRes),
  7050         -#endif
  7051         -  void *pContext
  7052         -);
  7053         -
  7054         -
  7055         -/*
  7056         -** A pointer to a structure of the following type is passed as the first
  7057         -** argument to callbacks registered using rtree_geometry_callback().
  7058         -*/
  7059         -struct sqlite3_rtree_geometry {
  7060         -  void *pContext;                 /* Copy of pContext passed to s_r_g_c() */
  7061         -  int nParam;                     /* Size of array aParam[] */
  7062         -  double *aParam;                 /* Parameters passed to SQL geom function */
  7063         -  void *pUser;                    /* Callback implementation user data */
  7064         -  void (*xDelUser)(void *);       /* Called by SQLite to clean up pUser */
  7065         -};
  7066         -
  7067         -
  7068         -#ifdef __cplusplus
  7069         -}  /* end of the 'extern "C"' block */
  7070         -#endif
  7071         -
  7072         -#endif  /* ifndef _SQLITE3RTREE_H_ */
  7073         -

Added src/sqlite4.c.

more than 10,000 changes

Added src/sqlite4.h.

            1  +/*
            2  +** 2001 September 15
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +*************************************************************************
           12  +** This header file defines the interface that the SQLite library
           13  +** presents to client programs.  If a C-function, structure, datatype,
           14  +** or constant definition does not appear in this file, then it is
           15  +** not a published API of SQLite, is subject to change without
           16  +** notice, and should not be referenced by programs that use SQLite.
           17  +**
           18  +** Some of the definitions that are in this file are marked as
           19  +** "experimental".  Experimental interfaces are normally new
           20  +** features recently added to SQLite.  We do not anticipate changes
           21  +** to experimental interfaces but reserve the right to make minor changes
           22  +** if experience from use "in the wild" suggest such changes are prudent.
           23  +**
           24  +** The official C-language API documentation for SQLite is derived
           25  +** from comments in this file.  This file is the authoritative source
           26  +** on how SQLite interfaces are suppose to operate.
           27  +**
           28  +** The name of this file under configuration management is "sqlite.h.in".
           29  +** The makefile makes some minor changes to this file (such as inserting
           30  +** the version number) and changes its name to "sqlite4.h" as
           31  +** part of the build process.
           32  +*/
           33  +#ifndef _SQLITE4_H_
           34  +#define _SQLITE4_H_
           35  +#include <stdarg.h>     /* Needed for the definition of va_list */
           36  +
           37  +/*
           38  +** Make sure we can call this stuff from C++.
           39  +*/
           40  +#ifdef __cplusplus
           41  +extern "C" {
           42  +#endif
           43  +
           44  +
           45  +/*
           46  +** Add the ability to override 'extern'
           47  +*/
           48  +#ifndef SQLITE4_EXTERN
           49  +# define SQLITE4_EXTERN extern
           50  +#endif
           51  +
           52  +#ifndef SQLITE4_API
           53  +# define SQLITE4_API
           54  +#endif
           55  +
           56  +
           57  +/*
           58  +** These no-op macros are used in front of interfaces to mark those
           59  +** interfaces as either deprecated or experimental.  New applications
           60  +** should not use deprecated interfaces - they are support for backwards
           61  +** compatibility only.  Application writers should be aware that
           62  +** experimental interfaces are subject to change in point releases.
           63  +**
           64  +** These macros used to resolve to various kinds of compiler magic that
           65  +** would generate warning messages when they were used.  But that
           66  +** compiler magic ended up generating such a flurry of bug reports
           67  +** that we have taken it all out and gone back to using simple
           68  +** noop macros.
           69  +*/
           70  +#define SQLITE4_DEPRECATED
           71  +#define SQLITE4_EXPERIMENTAL
           72  +
           73  +/*
           74  +** Ensure these symbols were not defined by some previous header file.
           75  +*/
           76  +#ifdef SQLITE4_VERSION
           77  +# undef SQLITE4_VERSION
           78  +#endif
           79  +#ifdef SQLITE4_VERSION_NUMBER
           80  +# undef SQLITE4_VERSION_NUMBER
           81  +#endif
           82  +
           83  +/*
           84  +** CAPIREF: Run-time Environment Object
           85  +**
           86  +** An instance of the following object defines the run-time environment 
           87  +** for an SQLite4 database connection.  This object defines the interface
           88  +** to appropriate mutex routines, memory allocation routines, a
           89  +** pseudo-random number generator, real-time clock, and the key-value
           90  +** backend stores.
           91  +*/
           92  +typedef struct sqlite4_env sqlite4_env;
           93  +
           94  +/*
           95  +** CAPIREF: Find the default run-time environment
           96  +**
           97  +** Return a pointer to the default run-time environment.
           98  +*/
           99  +SQLITE4_API sqlite4_env *sqlite4_env_default(void);
          100  +
          101  +/*
          102  +** CAPIREF: Size of an sqlite4_env object
          103  +**
          104  +** Return the number of bytes of memory needed to hold an sqlite4_env
          105  +** object.  This number varies from one machine to another, and from
          106  +** one release of SQLite to another.
          107  +*/
          108  +SQLITE4_API int sqlite4_env_size(void);
          109  +
          110  +/*
          111  +** CAPIREF: Configure a run-time environment
          112  +*/
          113  +SQLITE4_API int sqlite4_env_config(sqlite4_env*, int op, ...);
          114  +
          115  +/*
          116  +** CAPIREF: Configuration options for sqlite4_env_config().
          117  +*/
          118  +#define SQLITE4_ENVCONFIG_INIT          1   /* size, template */
          119  +#define SQLITE4_ENVCONFIG_SINGLETHREAD  2   /* */
          120  +#define SQLITE4_ENVCONFIG_MULTITHREAD   3   /* */
          121  +#define SQLITE4_ENVCONFIG_SERIALIZED    4   /* */
          122  +#define SQLITE4_ENVCONFIG_MUTEX         5   /* sqlite4_mutex_methods* */
          123  +#define SQLITE4_ENVCONFIG_GETMUTEX      6   /* sqlite4_mutex_methods* */
          124  +#define SQLITE4_ENVCONFIG_MALLOC        7   /* sqlite4_mem_methods* */
          125  +#define SQLITE4_ENVCONFIG_GETMALLOC     8   /* sqlite4_mem_methods* */
          126  +#define SQLITE4_ENVCONFIG_MEMSTATUS     9   /* boolean */
          127  +#define SQLITE4_ENVCONFIG_LOOKASIDE    10   /* size, count */
          128  +#define SQLITE4_ENVCONFIG_LOG          11   /* xLog, pArg */
          129  +#define SQLITE4_ENVCONFIG_KVSTORE_PUSH 12   /* name, factory */
          130  +#define SQLITE4_ENVCONFIG_KVSTORE_POP  13   /* name */
          131  +#define SQLITE4_ENVCONFIG_KVSTORE_GET  14   /* name, *factor */
          132  +
          133  +
          134  +/*
          135  +** CAPIREF: Compile-Time Library Version Numbers
          136  +**
          137  +** ^(The [SQLITE4_VERSION] C preprocessor macro in the sqlite4.h header
          138  +** evaluates to a string literal that is the SQLite version in the
          139  +** format "X.Y.Z" where X is the major version number (always 3 for
          140  +** SQLite3) and Y is the minor version number and Z is the release number.)^
          141  +** ^(The [SQLITE4_VERSION_NUMBER] C preprocessor macro resolves to an integer
          142  +** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
          143  +** numbers used in [SQLITE4_VERSION].)^
          144  +** The SQLITE4_VERSION_NUMBER for any given release of SQLite will also
          145  +** be larger than the release from which it is derived.  Either Y will
          146  +** be held constant and Z will be incremented or else Y will be incremented
          147  +** and Z will be reset to zero.
          148  +**
          149  +** Since version 3.6.18, SQLite source code has been stored in the
          150  +** <a href="http://www.fossil-scm.org/">Fossil configuration management
          151  +** system</a>.  ^The SQLITE4_SOURCE_ID macro evaluates to
          152  +** a string which identifies a particular check-in of SQLite
          153  +** within its configuration management system.  ^The SQLITE4_SOURCE_ID
          154  +** string contains the date and time of the check-in (UTC) and an SHA1
          155  +** hash of the entire source tree.
          156  +**
          157  +** See also: [sqlite4_libversion()],
          158  +** [sqlite4_libversion_number()], [sqlite4_sourceid()],
          159  +** [sqlite_version()] and [sqlite_source_id()].
          160  +*/
          161  +#define SQLITE4_VERSION        "4.0.0"
          162  +#define SQLITE4_VERSION_NUMBER 4000000
          163  +#define SQLITE4_SOURCE_ID      "2012-06-29 15:58:49 2aa05e9008ff9e3630161995cdb256351cc45f9b"
          164  +
          165  +/*
          166  +** CAPIREF: Run-Time Library Version Numbers
          167  +** KEYWORDS: sqlite4_version, sqlite4_sourceid
          168  +**
          169  +** These interfaces provide the same information as the [SQLITE4_VERSION],
          170  +** [SQLITE4_VERSION_NUMBER], and [SQLITE4_SOURCE_ID] C preprocessor macros
          171  +** but are associated with the library instead of the header file.  ^(Cautious
          172  +** programmers might include assert() statements in their application to
          173  +** verify that values returned by these interfaces match the macros in
          174  +** the header, and thus insure that the application is
          175  +** compiled with matching library and header files.
          176  +**
          177  +** <blockquote><pre>
          178  +** assert( sqlite4_libversion_number()==SQLITE4_VERSION_NUMBER );
          179  +** assert( strcmp(sqlite4_sourceid(),SQLITE4_SOURCE_ID)==0 );
          180  +** assert( strcmp(sqlite4_libversion(),SQLITE4_VERSION)==0 );
          181  +** </pre></blockquote>)^
          182  +**
          183  +** ^The sqlite4_libversion() function returns a pointer to a string
          184  +** constant that contains the text of [SQLITE4_VERSION].  ^The
          185  +** sqlite4_libversion_number() function returns an integer equal to
          186  +** [SQLITE4_VERSION_NUMBER].  ^The sqlite4_sourceid() function returns 
          187  +** a pointer to a string constant whose value is the same as the 
          188  +** [SQLITE4_SOURCE_ID] C preprocessor macro.
          189  +**
          190  +** See also: [sqlite_version()] and [sqlite_source_id()].
          191  +*/
          192  +SQLITE4_API const char *sqlite4_libversion(void);
          193  +SQLITE4_API const char *sqlite4_sourceid(void);
          194  +SQLITE4_API int sqlite4_libversion_number(void);
          195  +
          196  +/*
          197  +** CAPIREF: Run-Time Library Compilation Options Diagnostics
          198  +**
          199  +** ^The sqlite4_compileoption_used() function returns 0 or 1 
          200  +** indicating whether the specified option was defined at 
          201  +** compile time.  ^The SQLITE4_ prefix may be omitted from the 
          202  +** option name passed to sqlite4_compileoption_used().  
          203  +**
          204  +** ^The sqlite4_compileoption_get() function allows iterating
          205  +** over the list of options that were defined at compile time by
          206  +** returning the N-th compile time option string.  ^If N is out of range,
          207  +** sqlite4_compileoption_get() returns a NULL pointer.  ^The SQLITE4_ 
          208  +** prefix is omitted from any strings returned by 
          209  +** sqlite4_compileoption_get().
          210  +**
          211  +** ^Support for the diagnostic functions sqlite4_compileoption_used()
          212  +** and sqlite4_compileoption_get() may be omitted by specifying the 
          213  +** [SQLITE4_OMIT_COMPILEOPTION_DIAGS] option at compile time.
          214  +**
          215  +** See also: SQL functions [sqlite_compileoption_used()] and
          216  +** [sqlite_compileoption_get()] and the [compile_options pragma].
          217  +*/
          218  +#ifndef SQLITE4_OMIT_COMPILEOPTION_DIAGS
          219  +SQLITE4_API int sqlite4_compileoption_used(const char *zOptName);
          220  +SQLITE4_API const char *sqlite4_compileoption_get(int N);
          221  +#endif
          222  +
          223  +/*
          224  +** CAPIREF: Test To See If The Library Is Threadsafe
          225  +**
          226  +** ^The sqlite4_threadsafe(E) function returns zero if the [sqlite4_env]
          227  +** object is configured in such a way that it should only be used by a
          228  +** single thread at a time.  In other words, this routine returns zero
          229  +** if the environment is configured as [SQLITE4_ENVCONFIG_SINGLETHREAD].
          230  +**
          231  +** ^The sqlite4_threadsafe(E) function returns one if multiple
          232  +** [database connection] objects associated with E can be used at the
          233  +** same time in different threads, so long as no single [database connection]
          234  +** object is used by two or more threads at the same time.  This
          235  +** corresponds to [SQLITE4_ENVCONFIG_MULTITHREAD].
          236  +**
          237  +** ^The sqlite4_threadsafe(E) function returns two if the same
          238  +** [database connection] can be used at the same time from two or more
          239  +** separate threads.  This setting corresponds to [SQLITE4_ENVCONFIG_SERIALIZED].
          240  +**
          241  +** Note that SQLite4 is always threadsafe in this sense: Two or more
          242  +** objects each associated with different [sqlite4_env] objects can
          243  +** always be used at the same time in separate threads.
          244  +*/
          245  +SQLITE4_API int sqlite4_threadsafe(sqlite4_env*);
          246  +
          247  +/*
          248  +** CAPIREF: Database Connection Handle
          249  +** KEYWORDS: {database connection} {database connections}
          250  +**
          251  +** Each open SQLite database is represented by a pointer to an instance of
          252  +** the opaque structure named "sqlite4".  It is useful to think of an sqlite4
          253  +** pointer as an object.  The [sqlite4_open()]
          254  +** interface is its constructors, and [sqlite4_close()]
          255  +** is its destructor.  There are many other interfaces (such as
          256  +** [sqlite4_prepare], [sqlite4_create_function()], and
          257  +** [sqlite4_busy_timeout()] to name but three) that are methods on an
          258  +** sqlite4 object.
          259  +*/
          260  +typedef struct sqlite4 sqlite4;
          261  +
          262  +/*
          263  +** CAPIREF: 64-Bit Integer Types
          264  +** KEYWORDS: sqlite_int64 sqlite_uint64
          265  +**
          266  +** Because there is no cross-platform way to specify 64-bit integer types
          267  +** SQLite includes typedefs for 64-bit signed and unsigned integers.
          268  +**
          269  +** The sqlite4_int64 and sqlite4_uint64 are the preferred type definitions.
          270  +** The sqlite_int64 and sqlite_uint64 types are supported for backwards
          271  +** compatibility only.
          272  +**
          273  +** ^The sqlite4_int64 and sqlite_int64 types can store integer values
          274  +** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
          275  +** sqlite4_uint64 and sqlite_uint64 types can store integer values 
          276  +** between 0 and +18446744073709551615 inclusive.
          277  +*/
          278  +#ifdef SQLITE4_INT64_TYPE
          279  +  typedef SQLITE4_INT64_TYPE sqlite_int64;
          280  +  typedef unsigned SQLITE4_INT64_TYPE sqlite_uint64;
          281  +#elif defined(_MSC_VER) || defined(__BORLANDC__)
          282  +  typedef __int64 sqlite_int64;
          283  +  typedef unsigned __int64 sqlite_uint64;
          284  +#else
          285  +  typedef long long int sqlite_int64;
          286  +  typedef unsigned long long int sqlite_uint64;
          287  +#endif
          288  +typedef sqlite_int64 sqlite4_int64;
          289  +typedef sqlite_uint64 sqlite4_uint64;
          290  +
          291  +/*
          292  +** CAPIREF: String length type
          293  +**
          294  +** A type for measuring the length of the string.  Like size_t but
          295  +** does not require &lt;stddef.h&gt;
          296  +*/
          297  +typedef int sqlite4_size_t;
          298  +
          299  +/*
          300  +** If compiling for a processor that lacks floating point support,
          301  +** substitute integer for floating-point.
          302  +*/
          303  +#ifdef SQLITE4_OMIT_FLOATING_POINT
          304  +# define double sqlite4_int64
          305  +#endif
          306  +
          307  +/*
          308  +** CAPIREF: Closing A Database Connection
          309  +**
          310  +** ^The sqlite4_close() routine is the destructor for the [sqlite4] object.
          311  +** ^Calls to sqlite4_close() return SQLITE4_OK if the [sqlite4] object is
          312  +** successfully destroyed and all associated resources are deallocated.
          313  +**
          314  +** Applications must [sqlite4_finalize | finalize] all [prepared statements]
          315  +** and [sqlite4_blob_close | close] all [BLOB handles] associated with
          316  +** the [sqlite4] object prior to attempting to close the object.  ^If
          317  +** sqlite4_close() is called on a [database connection] that still has
          318  +** outstanding [prepared statements] or [BLOB handles], then it returns
          319  +** SQLITE4_BUSY.
          320  +**
          321  +** ^If [sqlite4_close()] is invoked while a transaction is open,
          322  +** the transaction is automatically rolled back.
          323  +**
          324  +** The C parameter to [sqlite4_close(C)] must be either a NULL
          325  +** pointer or an [sqlite4] object pointer obtained
          326  +** from [sqlite4_open()] and not previously closed.
          327  +** ^Calling sqlite4_close() with a NULL pointer argument is a 
          328  +** harmless no-op.
          329  +*/
          330  +SQLITE4_API int sqlite4_close(sqlite4 *);
          331  +
          332  +/*
          333  +** The type for a callback function.
          334  +** This is legacy and deprecated.  It is included for historical
          335  +** compatibility and is not documented.
          336  +*/
          337  +typedef int (*sqlite4_callback)(void*,int,char**, char**);
          338  +
          339  +/*
          340  +** CAPIREF: One-Step Query Execution Interface
          341  +**
          342  +** The sqlite4_exec() interface is a convenience wrapper around
          343  +** [sqlite4_prepare()], [sqlite4_step()], and [sqlite4_finalize()],
          344  +** that allows an application to run multiple statements of SQL
          345  +** without having to use a lot of C code. 
          346  +**
          347  +** ^The sqlite4_exec() interface runs zero or more UTF-8 encoded,
          348  +** semicolon-separate SQL statements passed into its 2nd argument,
          349  +** in the context of the [database connection] passed in as its 1st
          350  +** argument.  ^If the callback function of the 3rd argument to
          351  +** sqlite4_exec() is not NULL, then it is invoked for each result row
          352  +** coming out of the evaluated SQL statements.  ^The 4th argument to
          353  +** sqlite4_exec() is relayed through to the 1st argument of each
          354  +** callback invocation.  ^If the callback pointer to sqlite4_exec()
          355  +** is NULL, then no callback is ever invoked and result rows are
          356  +** ignored.
          357  +**
          358  +** ^If an error occurs while evaluating the SQL statements passed into
          359  +** sqlite4_exec(), then execution of the current statement stops and
          360  +** subsequent statements are skipped.  ^If the 5th parameter to sqlite4_exec()
          361  +** is not NULL then any error message is written into memory obtained
          362  +** from [sqlite4_malloc()] and passed back through the 5th parameter.
          363  +** To avoid memory leaks, the application should invoke [sqlite4_free()]
          364  +** on error message strings returned through the 5th parameter of
          365  +** of sqlite4_exec() after the error message string is no longer needed.
          366  +** ^If the 5th parameter to sqlite4_exec() is not NULL and no errors
          367  +** occur, then sqlite4_exec() sets the pointer in its 5th parameter to
          368  +** NULL before returning.
          369  +**
          370  +** ^If an sqlite4_exec() callback returns non-zero, the sqlite4_exec()
          371  +** routine returns SQLITE4_ABORT without invoking the callback again and
          372  +** without running any subsequent SQL statements.
          373  +**
          374  +** ^The 2nd argument to the sqlite4_exec() callback function is the
          375  +** number of columns in the result.  ^The 3rd argument to the sqlite4_exec()
          376  +** callback is an array of pointers to strings obtained as if from
          377  +** [sqlite4_column_text()], one for each column.  ^If an element of a
          378  +** result row is NULL then the corresponding string pointer for the
          379  +** sqlite4_exec() callback is a NULL pointer.  ^The 4th argument to the
          380  +** sqlite4_exec() callback is an array of pointers to strings where each
          381  +** entry represents the name of corresponding result column as obtained
          382  +** from [sqlite4_column_name()].
          383  +**
          384  +** ^If the 2nd parameter to sqlite4_exec() is a NULL pointer, a pointer
          385  +** to an empty string, or a pointer that contains only whitespace and/or 
          386  +** SQL comments, then no SQL statements are evaluated and the database
          387  +** is not changed.
          388  +**
          389  +** Restrictions:
          390  +**
          391  +** <ul>
          392  +** <li> The application must insure that the 1st parameter to sqlite4_exec()
          393  +**      is a valid and open [database connection].
          394  +** <li> The application must not close [database connection] specified by
          395  +**      the 1st parameter to sqlite4_exec() while sqlite4_exec() is running.
          396  +** <li> The application must not modify the SQL statement text passed into
          397  +**      the 2nd parameter of sqlite4_exec() while sqlite4_exec() is running.
          398  +** </ul>
          399  +*/
          400  +SQLITE4_API int sqlite4_exec(
          401  +  sqlite4*,                                  /* An open database */
          402  +  const char *sql,                           /* SQL to be evaluated */
          403  +  int (*callback)(void*,int,char**,char**),  /* Callback function */
          404  +  void *,                                    /* 1st argument to callback */
          405  +  char **errmsg                              /* Error msg written here */
          406  +);
          407  +
          408  +/*
          409  +** CAPIREF: Result Codes
          410  +** KEYWORDS: SQLITE4_OK {error code} {error codes}
          411  +** KEYWORDS: {result code} {result codes}
          412  +**
          413  +** Many SQLite functions return an integer result code from the set shown
          414  +** here in order to indicate success or failure.
          415  +**
          416  +** New error codes may be added in future versions of SQLite.
          417  +**
          418  +** See also: [SQLITE4_IOERR_READ | extended result codes],
          419  +** [sqlite4_vtab_on_conflict()] [SQLITE4_ROLLBACK | result codes].
          420  +*/
          421  +#define SQLITE4_OK           0   /* Successful result */
          422  +/* beginning-of-error-codes */
          423  +#define SQLITE4_ERROR        1   /* SQL error or missing database */
          424  +#define SQLITE4_INTERNAL     2   /* Internal logic error in SQLite */
          425  +#define SQLITE4_PERM         3   /* Access permission denied */
          426  +#define SQLITE4_ABORT        4   /* Callback routine requested an abort */
          427  +#define SQLITE4_BUSY         5   /* The database file is locked */
          428  +#define SQLITE4_LOCKED       6   /* A table in the database is locked */
          429  +#define SQLITE4_NOMEM        7   /* A malloc() failed */
          430  +#define SQLITE4_READONLY     8   /* Attempt to write a readonly database */
          431  +#define SQLITE4_INTERRUPT    9   /* Operation terminated by sqlite4_interrupt()*/
          432  +#define SQLITE4_IOERR       10   /* Some kind of disk I/O error occurred */
          433  +#define SQLITE4_CORRUPT     11   /* The database disk image is malformed */
          434  +#define SQLITE4_NOTFOUND    12   /* Unknown opcode in sqlite4_file_control() */
          435  +#define SQLITE4_FULL        13   /* Insertion failed because database is full */
          436  +#define SQLITE4_CANTOPEN    14   /* Unable to open the database file */
          437  +#define SQLITE4_PROTOCOL    15   /* Database lock protocol error */
          438  +#define SQLITE4_EMPTY       16   /* Database is empty */
          439  +#define SQLITE4_SCHEMA      17   /* The database schema changed */
          440  +#define SQLITE4_TOOBIG      18   /* String or BLOB exceeds size limit */
          441  +#define SQLITE4_CONSTRAINT  19   /* Abort due to constraint violation */
          442  +#define SQLITE4_MISMATCH    20   /* Data type mismatch */
          443  +#define SQLITE4_MISUSE      21   /* Library used incorrectly */
          444  +#define SQLITE4_NOLFS       22   /* Uses OS features not supported on host */
          445  +#define SQLITE4_AUTH        23   /* Authorization denied */
          446  +#define SQLITE4_FORMAT      24   /* Auxiliary database format error */
          447  +#define SQLITE4_RANGE       25   /* 2nd parameter to sqlite4_bind out of range */
          448  +#define SQLITE4_NOTADB      26   /* File opened that is not a database file */
          449  +#define SQLITE4_ROW         100  /* sqlite4_step() has another row ready */
          450  +#define SQLITE4_DONE        101  /* sqlite4_step() has finished executing */
          451  +#define SQLITE4_INEXACT     102  /* xSeek method of storage finds nearby ans */
          452  +/* end-of-error-codes */
          453  +
          454  +/*
          455  +** CAPIREF: Extended Result Codes
          456  +** KEYWORDS: {extended error code} {extended error codes}
          457  +** KEYWORDS: {extended result code} {extended result codes}
          458  +**
          459  +** In its default configuration, SQLite API routines return one of 26 integer
          460  +** [SQLITE4_OK | result codes].  However, experience has shown that many of
          461  +** these result codes are too coarse-grained.  They do not provide as
          462  +** much information about problems as programmers might like.  In an effort to
          463  +** address this, newer versions of SQLite (version 3.3.8 and later) include
          464  +** support for additional result codes that provide more detailed information
          465  +** about errors. The extended result codes are enabled or disabled
          466  +** on a per database connection basis using the
          467  +** [sqlite4_extended_result_codes()] API.
          468  +**
          469  +** Some of the available extended result codes are listed here.
          470  +** One may expect the number of extended result codes will be expand
          471  +** over time.  Software that uses extended result codes should expect
          472  +** to see new result codes in future releases of SQLite.
          473  +**
          474  +** The SQLITE4_OK result code will never be extended.  It will always
          475  +** be exactly zero.
          476  +*/
          477  +#define SQLITE4_IOERR_READ              (SQLITE4_IOERR | (1<<8))
          478  +#define SQLITE4_IOERR_SHORT_READ        (SQLITE4_IOERR | (2<<8))
          479  +#define SQLITE4_IOERR_WRITE             (SQLITE4_IOERR | (3<<8))
          480  +#define SQLITE4_IOERR_FSYNC             (SQLITE4_IOERR | (4<<8))
          481  +#define SQLITE4_IOERR_DIR_FSYNC         (SQLITE4_IOERR | (5<<8))
          482  +#define SQLITE4_IOERR_TRUNCATE          (SQLITE4_IOERR | (6<<8))
          483  +#define SQLITE4_IOERR_FSTAT             (SQLITE4_IOERR | (7<<8))
          484  +#define SQLITE4_IOERR_UNLOCK            (SQLITE4_IOERR | (8<<8))
          485  +#define SQLITE4_IOERR_RDLOCK            (SQLITE4_IOERR | (9<<8))
          486  +#define SQLITE4_IOERR_DELETE            (SQLITE4_IOERR | (10<<8))
          487  +#define SQLITE4_IOERR_BLOCKED           (SQLITE4_IOERR | (11<<8))
          488  +#define SQLITE4_IOERR_NOMEM             (SQLITE4_IOERR | (12<<8))
          489  +#define SQLITE4_IOERR_ACCESS            (SQLITE4_IOERR | (13<<8))
          490  +#define SQLITE4_IOERR_CHECKRESERVEDLOCK (SQLITE4_IOERR | (14<<8))
          491  +#define SQLITE4_IOERR_LOCK              (SQLITE4_IOERR | (15<<8))
          492  +#define SQLITE4_IOERR_CLOSE             (SQLITE4_IOERR | (16<<8))
          493  +#define SQLITE4_IOERR_DIR_CLOSE         (SQLITE4_IOERR | (17<<8))
          494  +#define SQLITE4_IOERR_SHMOPEN           (SQLITE4_IOERR | (18<<8))
          495  +#define SQLITE4_IOERR_SHMSIZE           (SQLITE4_IOERR | (19<<8))
          496  +#define SQLITE4_IOERR_SHMLOCK           (SQLITE4_IOERR | (20<<8))
          497  +#define SQLITE4_IOERR_SHMMAP            (SQLITE4_IOERR | (21<<8))
          498  +#define SQLITE4_IOERR_SEEK              (SQLITE4_IOERR | (22<<8))
          499  +#define SQLITE4_LOCKED_SHAREDCACHE      (SQLITE4_LOCKED |  (1<<8))
          500  +#define SQLITE4_BUSY_RECOVERY           (SQLITE4_BUSY   |  (1<<8))
          501  +#define SQLITE4_CANTOPEN_NOTEMPDIR      (SQLITE4_CANTOPEN | (1<<8))
          502  +#define SQLITE4_CORRUPT_VTAB            (SQLITE4_CORRUPT | (1<<8))
          503  +#define SQLITE4_READONLY_RECOVERY       (SQLITE4_READONLY | (1<<8))
          504  +#define SQLITE4_READONLY_CANTLOCK       (SQLITE4_READONLY | (2<<8))
          505  +
          506  +/*
          507  +** CAPIREF: Flags For File Open Operations
          508  +**
          509  +** These bit values are intended for use as options in the
          510  +** [sqlite4_open()] interface
          511  +*/
          512  +#define SQLITE4_OPEN_READONLY         0x00000001  /* Ok for sqlite4_open() */
          513  +#define SQLITE4_OPEN_READWRITE        0x00000002  /* Ok for sqlite4_open() */
          514  +#define SQLITE4_OPEN_CREATE           0x00000004  /* Ok for sqlite4_open() */
          515  +
          516  +/* NB:  The above must not overlap with the SQLITE4_KVOPEN_xxxxx flags
          517  +** defined below */
          518  +
          519  +
          520  +/*
          521  +** CAPIREF: Mutex Handle
          522  +**
          523  +** The mutex module within SQLite defines [sqlite4_mutex] to be an
          524  +** abstract type for a mutex object.  The SQLite core never looks
          525  +** at the internal representation of an [sqlite4_mutex].  It only
          526  +** deals with pointers to the [sqlite4_mutex] object.
          527  +**
          528  +** Mutexes are created using [sqlite4_mutex_alloc()].
          529  +*/
          530  +typedef struct sqlite4_mutex sqlite4_mutex;
          531  +struct sqlite4_mutex {
          532  +  struct sqlite4_mutex_methods *pMutexMethods;
          533  +  /* Subclasses will typically add additional fields */
          534  +};
          535  +
          536  +/*
          537  +** CAPIREF: Initialize The SQLite Library
          538  +**
          539  +** ^The sqlite4_initialize(A) routine initializes an sqlite4_env object A.
          540  +** ^The sqlite4_shutdown(A) routine
          541  +** deallocates any resources that were allocated by sqlite4_initialize(A).
          542  +**
          543  +** A call to sqlite4_initialize(A) is an "effective" call if it is
          544  +** the first time sqlite4_initialize(A) is invoked during the lifetime of
          545  +** A, or if it is the first time sqlite4_initialize(A) is invoked
          546  +** following a call to sqlite4_shutdown(A).  ^(Only an effective call
          547  +** of sqlite4_initialize(A) does any initialization or A.  All other calls
          548  +** are harmless no-ops.)^
          549  +**
          550  +** A call to sqlite4_shutdown(A) is an "effective" call if it is the first
          551  +** call to sqlite4_shutdown(A) since the last sqlite4_initialize(A).  ^(Only
          552  +** an effective call to sqlite4_shutdown(A) does any deinitialization.
          553  +** All other valid calls to sqlite4_shutdown(A) are harmless no-ops.)^
          554  +**
          555  +** The sqlite4_initialize(A) interface is threadsafe, but sqlite4_shutdown(A)
          556  +** is not.  The sqlite4_shutdown(A) interface must only be called from a
          557  +** single thread.  All open [database connections] must be closed and all
          558  +** other SQLite resources must be deallocated prior to invoking
          559  +** sqlite4_shutdown(A).
          560  +**
          561  +** ^The sqlite4_initialize(A) routine returns [SQLITE4_OK] on success.
          562  +** ^If for some reason, sqlite4_initialize(A) is unable to initialize
          563  +** the sqlite4_env object A (perhaps it is unable to allocate a needed
          564  +** resource such as a mutex) it returns an [error code] other than [SQLITE4_OK].
          565  +**
          566  +** ^The sqlite4_initialize() routine is called internally by many other
          567  +** SQLite interfaces so that an application usually does not need to
          568  +** invoke sqlite4_initialize() directly.  For example, [sqlite4_open()]
          569  +** calls sqlite4_initialize() so the SQLite library will be automatically
          570  +** initialized when [sqlite4_open()] is called if it has not be initialized
          571  +** already.  ^However, if SQLite is compiled with the [SQLITE4_OMIT_AUTOINIT]
          572  +** compile-time option, then the automatic calls to sqlite4_initialize()
          573  +** are omitted and the application must call sqlite4_initialize() directly
          574  +** prior to using any other SQLite interface.  For maximum portability,
          575  +** it is recommended that applications always invoke sqlite4_initialize()
          576  +** directly prior to using any other SQLite interface.  Future releases
          577  +** of SQLite may require this.  In other words, the behavior exhibited
          578  +** when SQLite is compiled with [SQLITE4_OMIT_AUTOINIT] might become the
          579  +** default behavior in some future release of SQLite.
          580  +*/
          581  +SQLITE4_API int sqlite4_initialize(sqlite4_env*);
          582  +SQLITE4_API int sqlite4_shutdown(sqlite4_env*);
          583  +
          584  +/*
          585  +** CAPIREF: Configure database connections
          586  +**
          587  +** The sqlite4_db_config() interface is used to make configuration
          588  +** changes to a [database connection].  The interface is similar to
          589  +** [sqlite4_env_config()] except that the changes apply to a single
          590  +** [database connection] (specified in the first argument).
          591  +**
          592  +** The second argument to sqlite4_db_config(D,V,...)  is the
          593  +** [SQLITE4_DBCONFIG_LOOKASIDE | configuration verb] - an integer code 
          594  +** that indicates what aspect of the [database connection] is being configured.
          595  +** Subsequent arguments vary depending on the configuration verb.
          596  +**
          597  +** ^Calls to sqlite4_db_config() return SQLITE4_OK if and only if
          598  +** the call is considered successful.
          599  +*/
          600  +SQLITE4_API int sqlite4_db_config(sqlite4*, int op, ...);
          601  +
          602  +/*
          603  +** CAPIREF: Run-time environment of a database connection
          604  +**
          605  +** Return the sqlite4_env object to which the database connection
          606  +** belongs.
          607  +*/
          608  +SQLITE4_API sqlite4_env *sqlite4_db_env(sqlite4*);
          609  +
          610  +/*
          611  +** CAPIREF: Memory Allocation Routines
          612  +**
          613  +** An instance of this object defines the interface between SQLite
          614  +** and low-level memory allocation routines.
          615  +**
          616  +** This object is used in only one place in the SQLite interface.
          617  +** A pointer to an instance of this object is the argument to
          618  +** [sqlite4_env_config()] when the configuration option is
          619  +** [SQLITE4_ENVCONFIG_MALLOC] or [SQLITE4_ENVCONFIG_GETMALLOC].  
          620  +** By creating an instance of this object
          621  +** and passing it to [sqlite4_env_config]([SQLITE4_ENVCONFIG_MALLOC])
          622  +** during configuration, an application can specify an alternative
          623  +** memory allocation subsystem for SQLite to use for all of its
          624  +** dynamic memory needs.
          625  +**
          626  +** Note that SQLite comes with several [built-in memory allocators]
          627  +** that are perfectly adequate for the overwhelming majority of applications
          628  +** and that this object is only useful to a tiny minority of applications
          629  +** with specialized memory allocation requirements.  This object is
          630  +** also used during testing of SQLite in order to specify an alternative
          631  +** memory allocator that simulates memory out-of-memory conditions in
          632  +** order to verify that SQLite recovers gracefully from such
          633  +** conditions.
          634  +**
          635  +** The xMalloc, xRealloc, and xFree methods must work like the
          636  +** malloc(), realloc() and free() functions from the standard C library.
          637  +** ^SQLite guarantees that the second argument to
          638  +** xRealloc is always a value returned by a prior call to xRoundup.
          639  +**
          640  +** xSize should return the allocated size of a memory allocation
          641  +** previously obtained from xMalloc or xRealloc.  The allocated size
          642  +** is always at least as big as the requested size but may be larger.
          643  +**
          644  +** The xRoundup method returns what would be the allocated size of
          645  +** a memory allocation given a particular requested size.  Most memory
          646  +** allocators round up memory allocations at least to the next multiple
          647  +** of 8.  Some allocators round up to a larger multiple or to a power of 2.
          648  +** Every memory allocation request coming in through [sqlite4_malloc()]
          649  +** or [sqlite4_realloc()] first calls xRoundup.  If xRoundup returns 0, 
          650  +** that causes the corresponding memory allocation to fail.
          651  +**
          652  +** The xInit method initializes the memory allocator.  (For example,
          653  +** it might allocate any require mutexes or initialize internal data
          654  +** structures.  The xShutdown method is invoked (indirectly) by
          655  +** [sqlite4_shutdown()] and should deallocate any resources acquired
          656  +** by xInit.  The pMemEnv pointer is used as the only parameter to
          657  +** xInit and xShutdown.
          658  +**
          659  +** SQLite holds the [SQLITE4_MUTEX_STATIC_MASTER] mutex when it invokes
          660  +** the xInit method, so the xInit method need not be threadsafe.  The
          661  +** xShutdown method is only called from [sqlite4_shutdown()] so it does
          662  +** not need to be threadsafe either.  For all other methods, SQLite
          663  +** holds the [SQLITE4_MUTEX_STATIC_MEM] mutex as long as the
          664  +** [SQLITE4_CONFIG_MEMSTATUS] configuration option is turned on (which
          665  +** it is by default) and so the methods are automatically serialized.
          666  +** However, if [SQLITE4_CONFIG_MEMSTATUS] is disabled, then the other
          667  +** methods must be threadsafe or else make their own arrangements for
          668  +** serialization.
          669  +**
          670  +** SQLite will never invoke xInit() more than once without an intervening
          671  +** call to xShutdown().
          672  +*/
          673  +typedef struct sqlite4_mem_methods sqlite4_mem_methods;
          674  +struct sqlite4_mem_methods {
          675  +  void *(*xMalloc)(void*,sqlite4_size_t); /* Memory allocation function */
          676  +  void (*xFree)(void*,void*);             /* Free a prior allocation */
          677  +  void *(*xRealloc)(void*,void*,int);     /* Resize an allocation */
          678  +  sqlite4_size_t (*xSize)(void*,void*);   /* Return the size of an allocation */
          679  +  int (*xInit)(void*);                    /* Initialize the memory allocator */
          680  +  void (*xShutdown)(void*);               /* Deinitialize the allocator */
          681  +  void (*xBeginBenign)(void*);            /* Enter a benign malloc region */
          682  +  void (*xEndBenign)(void*);              /* Leave a benign malloc region */
          683  +  void *pMemEnv;                         /* 1st argument to all routines */
          684  +};
          685  +
          686  +
          687  +/*
          688  +** CAPIREF: Database Connection Configuration Options
          689  +**
          690  +** These constants are the available integer configuration options that
          691  +** can be passed as the second argument to the [sqlite4_db_config()] interface.
          692  +**
          693  +** New configuration options may be added in future releases of SQLite.
          694  +** Existing configuration options might be discontinued.  Applications
          695  +** should check the return code from [sqlite4_db_config()] to make sure that
          696  +** the call worked.  ^The [sqlite4_db_config()] interface will return a
          697  +** non-zero [error code] if a discontinued or unsupported configuration option
          698  +** is invoked.
          699  +**
          700  +** <dl>
          701  +** <dt>SQLITE4_DBCONFIG_LOOKASIDE</dt>
          702  +** <dd> ^This option takes three additional arguments that determine the 
          703  +** [lookaside memory allocator] configuration for the [database connection].
          704  +** ^The first argument (the third parameter to [sqlite4_db_config()] is a
          705  +** pointer to a memory buffer to use for lookaside memory.
          706  +** ^The first argument after the SQLITE4_DBCONFIG_LOOKASIDE verb
          707  +** may be NULL in which case SQLite will allocate the
          708  +** lookaside buffer itself using [sqlite4_malloc()]. ^The second argument is the
          709  +** size of each lookaside buffer slot.  ^The third argument is the number of
          710  +** slots.  The size of the buffer in the first argument must be greater than
          711  +** or equal to the product of the second and third arguments.  The buffer
          712  +** must be aligned to an 8-byte boundary.  ^If the second argument to
          713  +** SQLITE4_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
          714  +** rounded down to the next smaller multiple of 8.  ^(The lookaside memory
          715  +** configuration for a database connection can only be changed when that
          716  +** connection is not currently using lookaside memory, or in other words
          717  +** when the "current value" returned by
          718  +** [sqlite4_db_status](D,[SQLITE4_CONFIG_LOOKASIDE],...) is zero.
          719  +** Any attempt to change the lookaside memory configuration when lookaside
          720  +** memory is in use leaves the configuration unchanged and returns 
          721  +** [SQLITE4_BUSY].)^</dd>
          722  +**
          723  +** <dt>SQLITE4_DBCONFIG_ENABLE_FKEY</dt>
          724  +** <dd> ^This option is used to enable or disable the enforcement of
          725  +** [foreign key constraints].  There should be two additional arguments.
          726  +** The first argument is an integer which is 0 to disable FK enforcement,
          727  +** positive to enable FK enforcement or negative to leave FK enforcement
          728  +** unchanged.  The second parameter is a pointer to an integer into which
          729  +** is written 0 or 1 to indicate whether FK enforcement is off or on
          730  +** following this call.  The second parameter may be a NULL pointer, in
          731  +** which case the FK enforcement setting is not reported back. </dd>
          732  +**
          733  +** <dt>SQLITE4_DBCONFIG_ENABLE_TRIGGER</dt>
          734  +** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
          735  +** There should be two additional arguments.
          736  +** The first argument is an integer which is 0 to disable triggers,
          737  +** positive to enable triggers or negative to leave the setting unchanged.
          738  +** The second parameter is a pointer to an integer into which
          739  +** is written 0 or 1 to indicate whether triggers are disabled or enabled
          740  +** following this call.  The second parameter may be a NULL pointer, in
          741  +** which case the trigger setting is not reported back. </dd>
          742  +**
          743  +** </dl>
          744  +*/
          745  +#define SQLITE4_DBCONFIG_LOOKASIDE       1001  /* void* int int */
          746  +#define SQLITE4_DBCONFIG_ENABLE_FKEY     1002  /* int int* */
          747  +#define SQLITE4_DBCONFIG_ENABLE_TRIGGER  1003  /* int int* */
          748  +
          749  +
          750  +/*
          751  +** CAPIREF: Last Insert Rowid
          752  +**
          753  +** ^Each entry in an SQLite table has a unique 64-bit signed
          754  +** integer key called the [ROWID | "rowid"]. ^The rowid is always available
          755  +** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
          756  +** names are not also used by explicitly declared columns. ^If
          757  +** the table has a column of type [INTEGER PRIMARY KEY] then that column
          758  +** is another alias for the rowid.
          759  +**
          760  +** ^This routine returns the [rowid] of the most recent
          761  +** successful [INSERT] into the database from the [database connection]
          762  +** in the first argument.  ^As of SQLite version 3.7.7, this routines
          763  +** records the last insert rowid of both ordinary tables and [virtual tables].
          764  +** ^If no successful [INSERT]s
          765  +** have ever occurred on that database connection, zero is returned.
          766  +**
          767  +** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
          768  +** method, then this routine will return the [rowid] of the inserted
          769  +** row as long as the trigger or virtual table method is running.
          770  +** But once the trigger or virtual table method ends, the value returned 
          771  +** by this routine reverts to what it was before the trigger or virtual
          772  +** table method began.)^
          773  +**
          774  +** ^An [INSERT] that fails due to a constraint violation is not a
          775  +** successful [INSERT] and does not change the value returned by this
          776  +** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
          777  +** and INSERT OR ABORT make no changes to the return value of this
          778  +** routine when their insertion fails.  ^(When INSERT OR REPLACE
          779  +** encounters a constraint violation, it does not fail.  The
          780  +** INSERT continues to completion after deleting rows that caused
          781  +** the constraint problem so INSERT OR REPLACE will always change
          782  +** the return value of this interface.)^
          783  +**
          784  +** ^For the purposes of this routine, an [INSERT] is considered to
          785  +** be successful even if it is subsequently rolled back.
          786  +**
          787  +** This function is accessible to SQL statements via the
          788  +** [last_insert_rowid() SQL function].
          789  +**
          790  +** If a separate thread performs a new [INSERT] on the same
          791  +** database connection while the [sqlite4_last_insert_rowid()]
          792  +** function is running and thus changes the last insert [rowid],
          793  +** then the value returned by [sqlite4_last_insert_rowid()] is
          794  +** unpredictable and might not equal either the old or the new
          795  +** last insert [rowid].
          796  +*/
          797  +SQLITE4_API sqlite4_int64 sqlite4_last_insert_rowid(sqlite4*);
          798  +
          799  +/*
          800  +** CAPIREF: Count The Number Of Rows Modified
          801  +**
          802  +** ^This function returns the number of database rows that were changed
          803  +** or inserted or deleted by the most recently completed SQL statement
          804  +** on the [database connection] specified by the first parameter.
          805  +** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
          806  +** or [DELETE] statement are counted.  Auxiliary changes caused by
          807  +** triggers or [foreign key actions] are not counted.)^ Use the
          808  +** [sqlite4_total_changes()] function to find the total number of changes
          809  +** including changes caused by triggers and foreign key actions.
          810  +**
          811  +** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
          812  +** are not counted.  Only real table changes are counted.
          813  +**
          814  +** ^(A "row change" is a change to a single row of a single table
          815  +** caused by an INSERT, DELETE, or UPDATE statement.  Rows that
          816  +** are changed as side effects of [REPLACE] constraint resolution,
          817  +** rollback, ABORT processing, [DROP TABLE], or by any other
          818  +** mechanisms do not count as direct row changes.)^
          819  +**
          820  +** A "trigger context" is a scope of execution that begins and
          821  +** ends with the script of a [CREATE TRIGGER | trigger]. 
          822  +** Most SQL statements are
          823  +** evaluated outside of any trigger.  This is the "top level"
          824  +** trigger context.  If a trigger fires from the top level, a
          825  +** new trigger context is entered for the duration of that one
          826  +** trigger.  Subtriggers create subcontexts for their duration.
          827  +**
          828  +** ^Calling [sqlite4_exec()] or [sqlite4_step()] recursively does
          829  +** not create a new trigger context.
          830  +**
          831  +** ^This function returns the number of direct row changes in the
          832  +** most recent INSERT, UPDATE, or DELETE statement within the same
          833  +** trigger context.
          834  +**
          835  +** ^Thus, when called from the top level, this function returns the
          836  +** number of changes in the most recent INSERT, UPDATE, or DELETE
          837  +** that also occurred at the top level.  ^(Within the body of a trigger,
          838  +** the sqlite4_changes() interface can be called to find the number of
          839  +** changes in the most recently completed INSERT, UPDATE, or DELETE
          840  +** statement within the body of the same trigger.
          841  +** However, the number returned does not include changes
          842  +** caused by subtriggers since those have their own context.)^
          843  +**
          844  +** See also the [sqlite4_total_changes()] interface, the
          845  +** [count_changes pragma], and the [changes() SQL function].
          846  +**
          847  +** If a separate thread makes changes on the same database connection
          848  +** while [sqlite4_changes()] is running then the value returned
          849  +** is unpredictable and not meaningful.
          850  +*/
          851  +SQLITE4_API int sqlite4_changes(sqlite4*);
          852  +
          853  +/*
          854  +** CAPIREF: Total Number Of Rows Modified
          855  +**
          856  +** ^This function returns the number of row changes caused by [INSERT],
          857  +** [UPDATE] or [DELETE] statements since the [database connection] was opened.
          858  +** ^(The count returned by sqlite4_total_changes() includes all changes
          859  +** from all [CREATE TRIGGER | trigger] contexts and changes made by
          860  +** [foreign key actions]. However,
          861  +** the count does not include changes used to implement [REPLACE] constraints,
          862  +** do rollbacks or ABORT processing, or [DROP TABLE] processing.  The
          863  +** count does not include rows of views that fire an [INSTEAD OF trigger],
          864  +** though if the INSTEAD OF trigger makes changes of its own, those changes 
          865  +** are counted.)^
          866  +** ^The sqlite4_total_changes() function counts the changes as soon as
          867  +** the statement that makes them is completed (when the statement handle
          868  +** is passed to [sqlite4_reset()] or [sqlite4_finalize()]).
          869  +**
          870  +** See also the [sqlite4_changes()] interface, the
          871  +** [count_changes pragma], and the [total_changes() SQL function].
          872  +**
          873  +** If a separate thread makes changes on the same database connection
          874  +** while [sqlite4_total_changes()] is running then the value
          875  +** returned is unpredictable and not meaningful.
          876  +*/
          877  +SQLITE4_API int sqlite4_total_changes(sqlite4*);
          878  +
          879  +/*
          880  +** CAPIREF: Interrupt A Long-Running Query
          881  +**
          882  +** ^This function causes any pending database operation to abort and
          883  +** return at its earliest opportunity. This routine is typically
          884  +** called in response to a user action such as pressing "Cancel"
          885  +** or Ctrl-C where the user wants a long query operation to halt
          886  +** immediately.
          887  +**
          888  +** ^It is safe to call this routine from a thread different from the
          889  +** thread that is currently running the database operation.  But it
          890  +** is not safe to call this routine with a [database connection] that
          891  +** is closed or might close before sqlite4_interrupt() returns.
          892  +**
          893  +** ^If an SQL operation is very nearly finished at the time when
          894  +** sqlite4_interrupt() is called, then it might not have an opportunity
          895  +** to be interrupted and might continue to completion.
          896  +**
          897  +** ^An SQL operation that is interrupted will return [SQLITE4_INTERRUPT].
          898  +** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
          899  +** that is inside an explicit transaction, then the entire transaction
          900  +** will be rolled back automatically.
          901  +**
          902  +** ^The sqlite4_interrupt(D) call is in effect until all currently running
          903  +** SQL statements on [database connection] D complete.  ^Any new SQL statements
          904  +** that are started after the sqlite4_interrupt() call and before the 
          905  +** running statements reaches zero are interrupted as if they had been
          906  +** running prior to the sqlite4_interrupt() call.  ^New SQL statements
          907  +** that are started after the running statement count reaches zero are
          908  +** not effected by the sqlite4_interrupt().
          909  +** ^A call to sqlite4_interrupt(D) that occurs when there are no running
          910  +** SQL statements is a no-op and has no effect on SQL statements
          911  +** that are started after the sqlite4_interrupt() call returns.
          912  +**
          913  +** If the database connection closes while [sqlite4_interrupt()]
          914  +** is running then bad things will likely happen.
          915  +*/
          916  +SQLITE4_API void sqlite4_interrupt(sqlite4*);
          917  +
          918  +/*
          919  +** CAPIREF: Determine If An SQL Statement Is Complete
          920  +**
          921  +** These routines are useful during command-line input to determine if the
          922  +** currently entered text seems to form a complete SQL statement or
          923  +** if additional input is needed before sending the text into
          924  +** SQLite for parsing.  ^These routines return 1 if the input string
          925  +** appears to be a complete SQL statement.  ^A statement is judged to be
          926  +** complete if it ends with a semicolon token and is not a prefix of a
          927  +** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
          928  +** string literals or quoted identifier names or comments are not
          929  +** independent tokens (they are part of the token in which they are
          930  +** embedded) and thus do not count as a statement terminator.  ^Whitespace
          931  +** and comments that follow the final semicolon are ignored.
          932  +**
          933  +** ^These routines return 0 if the statement is incomplete.  ^If a
          934  +** memory allocation fails, then SQLITE4_NOMEM is returned.
          935  +**
          936  +** ^These routines do not parse the SQL statements thus
          937  +** will not detect syntactically incorrect SQL.
          938  +**
          939  +** ^(If SQLite has not been initialized using [sqlite4_initialize()] prior 
          940  +** to invoking sqlite4_complete16() then sqlite4_initialize() is invoked
          941  +** automatically by sqlite4_complete16().  If that initialization fails,
          942  +** then the return value from sqlite4_complete16() will be non-zero
          943  +** regardless of whether or not the input SQL is complete.)^
          944  +**
          945  +** The input to [sqlite4_complete()] must be a zero-terminated
          946  +** UTF-8 string.
          947  +**
          948  +** The input to [sqlite4_complete16()] must be a zero-terminated
          949  +** UTF-16 string in native byte order.
          950  +*/
          951  +SQLITE4_API int sqlite4_complete(const char *sql);
          952  +SQLITE4_API int sqlite4_complete16(const void *sql);
          953  +
          954  +
          955  +/*
          956  +** CAPIREF: Formatted String Printing Functions
          957  +**
          958  +** These routines are work-alikes of the "printf()" family of functions
          959  +** from the standard C library.
          960  +**
          961  +** ^The sqlite4_mprintf() and sqlite4_vmprintf() routines write their
          962  +** results into memory obtained from [sqlite4_malloc()].
          963  +** The strings returned by these two routines should be
          964  +** released by [sqlite4_free()].  ^Both routines return a
          965  +** NULL pointer if [sqlite4_malloc()] is unable to allocate enough
          966  +** memory to hold the resulting string.
          967  +**
          968  +** ^(The sqlite4_snprintf() routine is similar to "snprintf()" from
          969  +** the standard C library.  The result is written into the
          970  +** buffer supplied as the first parameter whose size is given by
          971  +** the second parameter.)^  The return value from sqltie4_snprintf()
          972  +** is the number of bytes actually written into the buffer, not
          973  +** counting the zero terminator.  The buffer is always zero-terminated
          974  +** as long as it it at least one byte in length.
          975  +**
          976  +** The sqlite4_snprintf() differs from the standard library snprintf()
          977  +** routine in two ways:  (1) sqlite4_snprintf() returns the number of
          978  +** bytes actually written, not the number of bytes that would have been
          979  +** written if the buffer had been infinitely long.  (2) If the buffer is
          980  +** at least one byte long, sqlite4_snprintf() always zero-terminates its
          981  +** result.
          982  +**
          983  +** ^As long as the buffer size is greater than zero, sqlite4_snprintf()
          984  +** guarantees that the buffer is always zero-terminated.  ^The second
          985  +** parameter "n" is the total size of the buffer, including space for
          986  +** the zero terminator.  So the longest string that can be completely
          987  +** written will be n-1 characters.
          988  +**
          989  +** ^The sqlite4_vsnprintf() routine is a varargs version of sqlite4_snprintf().
          990  +**
          991  +** These routines all implement some additional formatting
          992  +** options that are useful for constructing SQL statements.
          993  +** All of the usual printf() formatting options apply.  In addition, there
          994  +** is are "%q", "%Q", and "%z" options.
          995  +**
          996  +** ^(The %q option works like %s in that it substitutes a nul-terminated
          997  +** string from the argument list.  But %q also doubles every '\'' character.
          998  +** %q is designed for use inside a string literal.)^  By doubling each '\''
          999  +** character it escapes that character and allows it to be inserted into
         1000  +** the string.
         1001  +**
         1002  +** For example, assume the string variable zText contains text as follows:
         1003  +**
         1004  +** <blockquote><pre>
         1005  +**  char *zText = "It's a happy day!";
         1006  +** </pre></blockquote>
         1007  +**
         1008  +** One can use this text in an SQL statement as follows:
         1009  +**
         1010  +** <blockquote><pre>
         1011  +**  char *zSQL = sqlite4_mprintf("INSERT INTO table VALUES('%q')", zText);
         1012  +**  sqlite4_exec(db, zSQL, 0, 0, 0);
         1013  +**  sqlite4_free(zSQL);
         1014  +** </pre></blockquote>
         1015  +**
         1016  +** Because the %q format string is used, the '\'' character in zText
         1017  +** is escaped and the SQL generated is as follows:
         1018  +**
         1019  +** <blockquote><pre>
         1020  +**  INSERT INTO table1 VALUES('It''s a happy day!')
         1021  +** </pre></blockquote>
         1022  +**
         1023  +** This is correct.  Had we used %s instead of %q, the generated SQL
         1024  +** would have looked like this:
         1025  +**
         1026  +** <blockquote><pre>
         1027  +**  INSERT INTO table1 VALUES('It's a happy day!');
         1028  +** </pre></blockquote>
         1029  +**
         1030  +** This second example is an SQL syntax error.  As a general rule you should
         1031  +** always use %q instead of %s when inserting text into a string literal.
         1032  +**
         1033  +** ^(The %Q option works like %q except it also adds single quotes around
         1034  +** the outside of the total string.  Additionally, if the parameter in the
         1035  +** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
         1036  +** single quotes).)^  So, for example, one could say:
         1037  +**
         1038  +** <blockquote><pre>
         1039  +**  char *zSQL = sqlite4_mprintf("INSERT INTO table VALUES(%Q)", zText);
         1040  +**  sqlite4_exec(db, zSQL, 0, 0, 0);
         1041  +**  sqlite4_free(zSQL);
         1042  +** </pre></blockquote>
         1043  +**
         1044  +** The code above will render a correct SQL statement in the zSQL
         1045  +** variable even if the zText variable is a NULL pointer.
         1046  +**
         1047  +** ^(The "%z" formatting option works like "%s" but with the
         1048  +** addition that after the string has been read and copied into
         1049  +** the result, [sqlite4_free()] is called on the input string.)^
         1050  +*/
         1051  +SQLITE4_API char *sqlite4_mprintf(sqlite4_env*, const char*,...);
         1052  +SQLITE4_API char *sqlite4_vmprintf(sqlite4_env*, const char*, va_list);
         1053  +SQLITE4_API sqlite4_size_t sqlite4_snprintf(char*,sqlite4_size_t,const char*, ...);
         1054  +SQLITE4_API sqlite4_size_t sqlite4_vsnprintf(char*,sqlite4_size_t,const char*, va_list);
         1055  +
         1056  +/*
         1057  +** CAPIREF: Memory Allocation Subsystem
         1058  +**
         1059  +** The SQLite core uses these three routines for all of its own
         1060  +** internal memory allocation needs.
         1061  +**
         1062  +** ^The sqlite4_malloc() routine returns a pointer to a block
         1063  +** of memory at least N bytes in length, where N is the parameter.
         1064  +** ^If sqlite4_malloc() is unable to obtain sufficient free
         1065  +** memory, it returns a NULL pointer.  ^If the parameter N to
         1066  +** sqlite4_malloc() is zero or negative then sqlite4_malloc() returns
         1067  +** a NULL pointer.
         1068  +**
         1069  +** ^Calling sqlite4_free() with a pointer previously returned
         1070  +** by sqlite4_malloc() or sqlite4_realloc() releases that memory so
         1071  +** that it might be reused.  ^The sqlite4_free() routine is
         1072  +** a no-op if is called with a NULL pointer.  Passing a NULL pointer
         1073  +** to sqlite4_free() is harmless.  After being freed, memory
         1074  +** should neither be read nor written.  Even reading previously freed
         1075  +** memory might result in a segmentation fault or other severe error.
         1076  +** Memory corruption, a segmentation fault, or other severe error
         1077  +** might result if sqlite4_free() is called with a non-NULL pointer that
         1078  +** was not obtained from sqlite4_malloc() or sqlite4_realloc().
         1079  +**
         1080  +** ^(The sqlite4_realloc() interface attempts to resize a
         1081  +** prior memory allocation to be at least N bytes, where N is the
         1082  +** second parameter.  The memory allocation to be resized is the first
         1083  +** parameter.)^ ^ If the first parameter to sqlite4_realloc()
         1084  +** is a NULL pointer then its behavior is identical to calling
         1085  +** sqlite4_malloc(N) where N is the second parameter to sqlite4_realloc().
         1086  +** ^If the second parameter to sqlite4_realloc() is zero or
         1087  +** negative then the behavior is exactly the same as calling
         1088  +** sqlite4_free(P) where P is the first parameter to sqlite4_realloc().
         1089  +** ^sqlite4_realloc() returns a pointer to a memory allocation
         1090  +** of at least N bytes in size or NULL if sufficient memory is unavailable.
         1091  +** ^If M is the size of the prior allocation, then min(N,M) bytes
         1092  +** of the prior allocation are copied into the beginning of buffer returned
         1093  +** by sqlite4_realloc() and the prior allocation is freed.
         1094  +** ^If sqlite4_realloc() returns NULL, then the prior allocation
         1095  +** is not freed.
         1096  +**
         1097  +** ^The memory returned by sqlite4_malloc() and sqlite4_realloc()
         1098  +** is always aligned to at least an 8 byte boundary, or to a
         1099  +** 4 byte boundary if the [SQLITE4_4_BYTE_ALIGNED_MALLOC] compile-time
         1100  +** option is used.
         1101  +**
         1102  +** The pointer arguments to [sqlite4_free()] and [sqlite4_realloc()]
         1103  +** must be either NULL or else pointers obtained from a prior
         1104  +** invocation of [sqlite4_malloc()] or [sqlite4_realloc()] that have
         1105  +** not yet been released.
         1106  +**
         1107  +** The application must not read or write any part of
         1108  +** a block of memory after it has been released using
         1109  +** [sqlite4_free()] or [sqlite4_realloc()].
         1110  +*/
         1111  +SQLITE4_API void *sqlite4_malloc(sqlite4_env*, sqlite4_size_t);
         1112  +SQLITE4_API void *sqlite4_realloc(sqlite4_env*, void*, sqlite4_size_t);
         1113  +SQLITE4_API void sqlite4_free(sqlite4_env*, void*);
         1114  +
         1115  +/*
         1116  +** CAPIREF: Memory Allocator Statistics
         1117  +**
         1118  +** SQLite provides these two interfaces for reporting on the status
         1119  +** of the [sqlite4_malloc()], [sqlite4_free()], and [sqlite4_realloc()]
         1120  +** routines, which form the built-in memory allocation subsystem.
         1121  +**
         1122  +** ^The [sqlite4_memory_used(E)] routine returns the number of bytes
         1123  +** of memory currently outstanding (malloced but not freed) for 
         1124  +** sqlite4_env environment E.
         1125  +** ^The [sqlite4_memory_highwater(E)] routine returns the maximum
         1126  +** value of [sqlite4_memory_used(E)] since the high-water mark
         1127  +** was last reset.  ^The values returned by [sqlite4_memory_used()] and
         1128  +** [sqlite4_memory_highwater()] include any overhead
         1129  +** added by SQLite in its implementation of [sqlite4_malloc()],
         1130  +** but not overhead added by the any underlying system library
         1131  +** routines that [sqlite4_malloc()] may call.
         1132  +**
         1133  +** ^The memory high-water mark is reset to the current value of
         1134  +** [sqlite4_memory_used(E)] if and only if the R parameter to
         1135  +** [sqlite4_memory_highwater(E,R)] is true.  ^The value returned
         1136  +** by [sqlite4_memory_highwater(E,1)] is the high-water mark
         1137  +** prior to the reset.
         1138  +*/
         1139  +SQLITE4_API sqlite4_uint64 sqlite4_memory_used(sqlite4_env*);
         1140  +SQLITE4_API sqlite4_uint64 sqlite4_memory_highwater(sqlite4_env*, int resetFlag);
         1141  +
         1142  +/*
         1143  +** CAPIREF: Pseudo-Random Number Generator
         1144  +**
         1145  +** ^A call to this routine stores N bytes of pseudo-randomness into buffer P.
         1146  +*/
         1147  +SQLITE4_API void sqlite4_randomness(sqlite4_env*, int N, void *P);
         1148  +
         1149  +/*
         1150  +** CAPIREF: Compile-Time Authorization Callbacks
         1151  +**
         1152  +** ^This routine registers an authorizer callback with a particular
         1153  +** [database connection], supplied in the first argument.
         1154  +** ^The authorizer callback is invoked as SQL statements are being compiled
         1155  +** by [sqlite4_prepare()] or its variants [sqlite4_prepare()],
         1156  +** [sqlite4_prepare16()] and [sqlite4_prepare16_v2()].  ^At various
         1157  +** points during the compilation process, as logic is being created
         1158  +** to perform various actions, the authorizer callback is invoked to
         1159  +** see if those actions are allowed.  ^The authorizer callback should
         1160  +** return [SQLITE4_OK] to allow the action, [SQLITE4_IGNORE] to disallow the
         1161  +** specific action but allow the SQL statement to continue to be
         1162  +** compiled, or [SQLITE4_DENY] to cause the entire SQL statement to be
         1163  +** rejected with an error.  ^If the authorizer callback returns
         1164  +** any value other than [SQLITE4_IGNORE], [SQLITE4_OK], or [SQLITE4_DENY]
         1165  +** then the [sqlite4_prepare()] or equivalent call that triggered
         1166  +** the authorizer will fail with an error message.
         1167  +**
         1168  +** When the callback returns [SQLITE4_OK], that means the operation
         1169  +** requested is ok.  ^When the callback returns [SQLITE4_DENY], the
         1170  +** [sqlite4_prepare()] or equivalent call that triggered the
         1171  +** authorizer will fail with an error message explaining that
         1172  +** access is denied. 
         1173  +**
         1174  +** ^The first parameter to the authorizer callback is a copy of the third
         1175  +** parameter to the sqlite4_set_authorizer() interface. ^The second parameter
         1176  +** to the callback is an integer [SQLITE4_COPY | action code] that specifies
         1177  +** the particular action to be authorized. ^The third through sixth parameters
         1178  +** to the callback are zero-terminated strings that contain additional
         1179  +** details about the action to be authorized.
         1180  +**
         1181  +** ^If the action code is [SQLITE4_READ]
         1182  +** and the callback returns [SQLITE4_IGNORE] then the
         1183  +** [prepared statement] statement is constructed to substitute
         1184  +** a NULL value in place of the table column that would have
         1185  +** been read if [SQLITE4_OK] had been returned.  The [SQLITE4_IGNORE]
         1186  +** return can be used to deny an untrusted user access to individual
         1187  +** columns of a table.
         1188  +** ^If the action code is [SQLITE4_DELETE] and the callback returns
         1189  +** [SQLITE4_IGNORE] then the [DELETE] operation proceeds but the
         1190  +** [truncate optimization] is disabled and all rows are deleted individually.
         1191  +**
         1192  +** An authorizer is used when [sqlite4_prepare | preparing]
         1193  +** SQL statements from an untrusted source, to ensure that the SQL statements
         1194  +** do not try to access data they are not allowed to see, or that they do not
         1195  +** try to execute malicious statements that damage the database.  For
         1196  +** example, an application may allow a user to enter arbitrary
         1197  +** SQL queries for evaluation by a database.  But the application does
         1198  +** not want the user to be able to make arbitrary changes to the
         1199  +** database.  An authorizer could then be put in place while the
         1200  +** user-entered SQL is being [sqlite4_prepare | prepared] that
         1201  +** disallows everything except [SELECT] statements.
         1202  +**
         1203  +** Applications that need to process SQL from untrusted sources
         1204  +** might also consider lowering resource limits using [sqlite4_limit()]
         1205  +** and limiting database size using the [max_page_count] [PRAGMA]
         1206  +** in addition to using an authorizer.
         1207  +**
         1208  +** ^(Only a single authorizer can be in place on a database connection
         1209  +** at a time.  Each call to sqlite4_set_authorizer overrides the
         1210  +** previous call.)^  ^Disable the authorizer by installing a NULL callback.
         1211  +** The authorizer is disabled by default.
         1212  +**
         1213  +** The authorizer callback must not do anything that will modify
         1214  +** the database connection that invoked the authorizer callback.
         1215  +** Note that [sqlite4_prepare()] and [sqlite4_step()] both modify their
         1216  +** database connections for the meaning of "modify" in this paragraph.
         1217  +**
         1218  +** ^When [sqlite4_prepare()] is used to prepare a statement, the
         1219  +** statement might be re-prepared during [sqlite4_step()] due to a 
         1220  +** schema change.  Hence, the application should ensure that the
         1221  +** correct authorizer callback remains in place during the [sqlite4_step()].
         1222  +**
         1223  +** ^Note that the authorizer callback is invoked only during
         1224  +** [sqlite4_prepare()] or its variants.  Authorization is not
         1225  +** performed during statement evaluation in [sqlite4_step()], unless
         1226  +** as stated in the previous paragraph, sqlite4_step() invokes
         1227  +** sqlite4_prepare() to reprepare a statement after a schema change.
         1228  +*/
         1229  +SQLITE4_API int sqlite4_set_authorizer(
         1230  +  sqlite4*,
         1231  +  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
         1232  +  void *pUserData
         1233  +);
         1234  +
         1235  +/*
         1236  +** CAPIREF: Authorizer Return Codes
         1237  +**
         1238  +** The [sqlite4_set_authorizer | authorizer callback function] must
         1239  +** return either [SQLITE4_OK] or one of these two constants in order
         1240  +** to signal SQLite whether or not the action is permitted.  See the
         1241  +** [sqlite4_set_authorizer | authorizer documentation] for additional
         1242  +** information.
         1243  +**
         1244  +** Note that SQLITE4_IGNORE is also used as a [SQLITE4_ROLLBACK | return code]
         1245  +** from the [sqlite4_vtab_on_conflict()] interface.
         1246  +*/
         1247  +#define SQLITE4_DENY   1   /* Abort the SQL statement with an error */
         1248  +#define SQLITE4_IGNORE 2   /* Don't allow access, but don't generate an error */
         1249  +
         1250  +/*
         1251  +** CAPIREF: Authorizer Action Codes
         1252  +**
         1253  +** The [sqlite4_set_authorizer()] interface registers a callback function
         1254  +** that is invoked to authorize certain SQL statement actions.  The
         1255  +** second parameter to the callback is an integer code that specifies
         1256  +** what action is being authorized.  These are the integer action codes that
         1257  +** the authorizer callback may be passed.
         1258  +**
         1259  +** These action code values signify what kind of operation is to be
         1260  +** authorized.  The 3rd and 4th parameters to the authorization
         1261  +** callback function will be parameters or NULL depending on which of these
         1262  +** codes is used as the second parameter.  ^(The 5th parameter to the
         1263  +** authorizer callback is the name of the database ("main", "temp",
         1264  +** etc.) if applicable.)^  ^The 6th parameter to the authorizer callback
         1265  +** is the name of the inner-most trigger or view that is responsible for
         1266  +** the access attempt or NULL if this access attempt is directly from
         1267  +** top-level SQL code.
         1268  +*/
         1269  +/******************************************* 3rd ************ 4th ***********/
         1270  +#define SQLITE4_CREATE_INDEX          1   /* Index Name      Table Name      */
         1271  +#define SQLITE4_CREATE_TABLE          2   /* Table Name      NULL            */
         1272  +#define SQLITE4_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */
         1273  +#define SQLITE4_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */
         1274  +#define SQLITE4_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */
         1275  +#define SQLITE4_CREATE_TEMP_VIEW      6   /* View Name       NULL            */
         1276  +#define SQLITE4_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */
         1277  +#define SQLITE4_CREATE_VIEW           8   /* View Name       NULL            */
         1278  +#define SQLITE4_DELETE                9   /* Table Name      NULL            */
         1279  +#define SQLITE4_DROP_INDEX           10   /* Index Name      Table Name      */
         1280  +#define SQLITE4_DROP_TABLE           11   /* Table Name      NULL            */
         1281  +#define SQLITE4_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */
         1282  +#define SQLITE4_DROP_TEMP_TABLE      13   /* Table Name      NULL            */
         1283  +#define SQLITE4_DROP_TEMP_TRIGGER    14   /* Trigger Name    Table Name      */
         1284  +#define SQLITE4_DROP_TEMP_VIEW       15   /* View Name       NULL            */
         1285  +#define SQLITE4_DROP_TRIGGER         16   /* Trigger Name    Table Name      */
         1286  +#define SQLITE4_DROP_VIEW            17   /* View Name       NULL            */
         1287  +#define SQLITE4_INSERT               18   /* Table Name      NULL            */
         1288  +#define SQLITE4_PRAGMA               19   /* Pragma Name     1st arg or NULL */
         1289  +#define SQLITE4_READ                 20   /* Table Name      Column Name     */
         1290  +#define SQLITE4_SELECT               21   /* NULL            NULL            */
         1291  +#define SQLITE4_TRANSACTION          22   /* Operation       NULL            */
         1292  +#define SQLITE4_UPDATE               23   /* Table Name      Column Name     */
         1293  +#define SQLITE4_ATTACH               24   /* Filename        NULL            */
         1294  +#define SQLITE4_DETACH               25   /* Database Name   NULL            */
         1295  +#define SQLITE4_ALTER_TABLE          26   /* Database Name   Table Name      */
         1296  +#define SQLITE4_REINDEX              27   /* Index Name      NULL            */
         1297  +#define SQLITE4_ANALYZE              28   /* Table Name      NULL            */
         1298  +#define SQLITE4_CREATE_VTABLE        29   /* Table Name      Module Name     */
         1299  +#define SQLITE4_DROP_VTABLE          30   /* Table Name      Module Name     */
         1300  +#define SQLITE4_FUNCTION             31   /* NULL            Function Name   */
         1301  +#define SQLITE4_SAVEPOINT            32   /* Operation       Savepoint Name  */
         1302  +#define SQLITE4_COPY                  0   /* No longer used */
         1303  +
         1304  +/*
         1305  +** CAPIREF: Tracing And Profiling Functions
         1306  +**
         1307  +** These routines register callback functions that can be used for
         1308  +** tracing and profiling the execution of SQL statements.
         1309  +**
         1310  +** ^The callback function registered by sqlite4_trace() is invoked at
         1311  +** various times when an SQL statement is being run by [sqlite4_step()].
         1312  +** ^The sqlite4_trace() callback is invoked with a UTF-8 rendering of the
         1313  +** SQL statement text as the statement first begins executing.
         1314  +** ^(Additional sqlite4_trace() callbacks might occur
         1315  +** as each triggered subprogram is entered.  The callbacks for triggers
         1316  +** contain a UTF-8 SQL comment that identifies the trigger.)^
         1317  +**
         1318  +** ^The callback function registered by sqlite4_profile() is invoked
         1319  +** as each SQL statement finishes.  ^The profile callback contains
         1320  +** the original statement text and an estimate of wall-clock time
         1321  +** of how long that statement took to run.  ^The profile callback
         1322  +** time is in units of nanoseconds, however the current implementation
         1323  +** is only capable of millisecond resolution so the six least significant
         1324  +** digits in the time are meaningless.  Future versions of SQLite
         1325  +** might provide greater resolution on the profiler callback.  The
         1326  +** sqlite4_profile() function is considered experimental and is
         1327  +** subject to change in future versions of SQLite.
         1328  +*/
         1329  +SQLITE4_API void *sqlite4_trace(sqlite4*, void(*xTrace)(void*,const char*), void*);
         1330  +SQLITE4_API SQLITE4_EXPERIMENTAL void *sqlite4_profile(sqlite4*,
         1331  +   void(*xProfile)(void*,const char*,sqlite4_uint64), void*);
         1332  +
         1333  +/*
         1334  +** CAPIREF: Query Progress Callbacks
         1335  +**
         1336  +** ^The sqlite4_progress_handler(D,N,X,P) interface causes the callback
         1337  +** function X to be invoked periodically during long running calls to
         1338  +** [sqlite4_exec()] and [sqlite4_step()] for
         1339  +** database connection D.  An example use for this
         1340  +** interface is to keep a GUI updated during a large query.
         1341  +**
         1342  +** ^The parameter P is passed through as the only parameter to the 
         1343  +** callback function X.  ^The parameter N is the number of 
         1344  +** [virtual machine instructions] that are evaluated between successive
         1345  +** invocations of the callback X.
         1346  +**
         1347  +** ^Only a single progress handler may be defined at one time per
         1348  +** [database connection]; setting a new progress handler cancels the
         1349  +** old one.  ^Setting parameter X to NULL disables the progress handler.
         1350  +** ^The progress handler is also disabled by setting N to a value less
         1351  +** than 1.
         1352  +**
         1353  +** ^If the progress callback returns non-zero, the operation is
         1354  +** interrupted.  This feature can be used to implement a
         1355  +** "Cancel" button on a GUI progress dialog box.
         1356  +**
         1357  +** The progress handler callback must not do anything that will modify
         1358  +** the database connection that invoked the progress handler.
         1359  +** Note that [sqlite4_prepare()] and [sqlite4_step()] both modify their
         1360  +** database connections for the meaning of "modify" in this paragraph.
         1361  +**
         1362  +*/
         1363  +SQLITE4_API void sqlite4_progress_handler(sqlite4*, int, int(*)(void*), void*);
         1364  +
         1365  +/*
         1366  +** CAPIREF: Opening A New Database Connection
         1367  +**
         1368  +** ^These routines open an SQLite4 database file as specified by the 
         1369  +** URI argument.
         1370  +** ^(A [database connection] handle is usually
         1371  +** returned in *ppDb, even if an error occurs.  The only exception is that
         1372  +** if SQLite is unable to allocate memory to hold the [sqlite4] object,
         1373  +** a NULL will be written into *ppDb instead of a pointer to the [sqlite4]
         1374  +** object.)^ ^(If the database is opened (and/or created) successfully, then
         1375  +** [SQLITE4_OK] is returned.  Otherwise an [error code] is returned.)^ ^The
         1376  +** [sqlite4_errmsg()] routine can be used to obtain
         1377  +** an English language description of the error following a failure of any
         1378  +** of the sqlite4_open() routines.
         1379  +**
         1380  +** Whether or not an error occurs when it is opened, resources
         1381  +** associated with the [database connection] handle should be released by
         1382  +** passing it to [sqlite4_close()] when it is no longer required.
         1383  +**
         1384  +*/
         1385  +SQLITE4_API int sqlite4_open(
         1386  +  sqlite4_env *pEnv,     /* Run-time environment. NULL means use the default */
         1387  +  const char *filename,  /* Database filename (UTF-8) */
         1388  +  sqlite4 **ppDb,        /* OUT: SQLite db handle */
         1389  +  ...                    /* Optional parameters.  Zero terminates options */
         1390  +);
         1391  +
         1392  +/*
         1393  +** CAPIREF: Obtain Values For URI Parameters
         1394  +**
         1395  +** These are utility routines, useful to VFS implementations, that check
         1396  +** to see if a database file was a URI that contained a specific query 
         1397  +** parameter, and if so obtains the value of that query parameter.
         1398  +**
         1399  +** If F is the database filename pointer passed into the xOpen() method of 
         1400  +** a VFS implementation when the flags parameter to xOpen() has one or 
         1401  +** more of the [SQLITE4_OPEN_URI] or [SQLITE4_OPEN_MAIN_DB] bits set and
         1402  +** P is the name of the query parameter, then
         1403  +** sqlite4_uri_parameter(F,P) returns the value of the P
         1404  +** parameter if it exists or a NULL pointer if P does not appear as a 
         1405  +** query parameter on F.  If P is a query parameter of F
         1406  +** has no explicit value, then sqlite4_uri_parameter(F,P) returns
         1407  +** a pointer to an empty string.
         1408  +**
         1409  +** The sqlite4_uri_boolean(F,P,B) routine assumes that P is a boolean
         1410  +** parameter and returns true (1) or false (0) according to the value
         1411  +** of P.  The value of P is true if it is "yes" or "true" or "on" or 
         1412  +** a non-zero number and is false otherwise.  If P is not a query parameter
         1413  +** on F then sqlite4_uri_boolean(F,P,B) returns (B!=0).
         1414  +**
         1415  +** The sqlite4_uri_int64(F,P,D) routine converts the value of P into a
         1416  +** 64-bit signed integer and returns that integer, or D if P does not
         1417  +** exist.  If the value of P is something other than an integer, then
         1418  +** zero is returned.
         1419  +** 
         1420  +** If F is a NULL pointer, then sqlite4_uri_parameter(F,P) returns NULL and
         1421  +** sqlite4_uri_boolean(F,P,B) returns B.  If F is not a NULL pointer and
         1422  +** is not a database file pathname pointer that SQLite passed into the xOpen
         1423  +** VFS method, then the behavior of this routine is undefined and probably
         1424  +** undesirable.
         1425  +*/
         1426  +SQLITE4_API const char *sqlite4_uri_parameter(const char *zFilename, const char *zParam);
         1427  +SQLITE4_API int sqlite4_uri_boolean(const char *zFile, const char *zParam, int bDefault);
         1428  +SQLITE4_API sqlite4_int64 sqlite4_uri_int64(const char*, const char*, sqlite4_int64);
         1429  +
         1430  +
         1431  +/*
         1432  +** CAPIREF: Error Codes And Messages
         1433  +**
         1434  +** ^The sqlite4_errcode() interface returns the numeric 
         1435  +** [extended result code] for the most recent failed sqlite4_* API call
         1436  +** associated with a [database connection]. If a prior API call failed
         1437  +** but the most recent API call succeeded, the return value from
         1438  +** sqlite4_errcode() is undefined.
         1439  +**
         1440  +** ^The sqlite4_errmsg() and sqlite4_errmsg16() return English-language
         1441  +** text that describes the error, as either UTF-8 or UTF-16 respectively.
         1442  +** ^(Memory to hold the error message string is managed internally.
         1443  +** The application does not need to worry about freeing the result.
         1444  +** However, the error string might be overwritten or deallocated by
         1445  +** subsequent calls to other SQLite interface functions.)^
         1446  +**
         1447  +** When the serialized [threading mode] is in use, it might be the
         1448  +** case that a second error occurs on a separate thread in between
         1449  +** the time of the first error and the call to these interfaces.
         1450  +** When that happens, the second error will be reported since these
         1451  +** interfaces always report the most recent result.  To avoid
         1452  +** this, each thread can obtain exclusive use of the [database connection] D
         1453  +** by invoking [sqlite4_mutex_enter]([sqlite4_db_mutex](D)) before beginning
         1454  +** to use D and invoking [sqlite4_mutex_leave]([sqlite4_db_mutex](D)) after
         1455  +** all calls to the interfaces listed here are completed.
         1456  +**
         1457  +** If an interface fails with SQLITE4_MISUSE, that means the interface
         1458  +** was invoked incorrectly by the application.  In that case, the
         1459  +** error code and message may or may not be set.
         1460  +*/
         1461  +SQLITE4_API int sqlite4_errcode(sqlite4 *db);
         1462  +SQLITE4_API const char *sqlite4_errmsg(sqlite4*);
         1463  +SQLITE4_API const void *sqlite4_errmsg16(sqlite4*);
         1464  +
         1465  +/*
         1466  +** CAPIREF: SQL Statement Object
         1467  +** KEYWORDS: {prepared statement} {prepared statements}
         1468  +**
         1469  +** An instance of this object represents a single SQL statement.
         1470  +** This object is variously known as a "prepared statement" or a
         1471  +** "compiled SQL statement" or simply as a "statement".
         1472  +**
         1473  +** The life of a statement object goes something like this:
         1474  +**
         1475  +** <ol>
         1476  +** <li> Create the object using [sqlite4_prepare()] or a related
         1477  +**      function.
         1478  +** <li> Bind values to [host parameters] using the sqlite4_bind_*()
         1479  +**      interfaces.
         1480  +** <li> Run the SQL by calling [sqlite4_step()] one or more times.
         1481  +** <li> Reset the statement using [sqlite4_reset()] then go back
         1482  +**      to step 2.  Do this zero or more times.
         1483  +** <li> Destroy the object using [sqlite4_finalize()].
         1484  +** </ol>
         1485  +**
         1486  +** Refer to documentation on individual methods above for additional
         1487  +** information.
         1488  +*/
         1489  +typedef struct sqlite4_stmt sqlite4_stmt;
         1490  +
         1491  +/*
         1492  +** CAPIREF: Run-time Limits
         1493  +**
         1494  +** ^(This interface allows the size of various constructs to be limited
         1495  +** on a connection by connection basis.  The first parameter is the
         1496  +** [database connection] whose limit is to be set or queried.  The
         1497  +** second parameter is one of the [limit categories] that define a
         1498  +** class of constructs to be size limited.  The third parameter is the
         1499  +** new limit for that construct.)^
         1500  +**
         1501  +** ^If the new limit is a negative number, the limit is unchanged.
         1502  +** ^(For each limit category SQLITE4_LIMIT_<i>NAME</i> there is a 
         1503  +** [limits | hard upper bound]
         1504  +** set at compile-time by a C preprocessor macro called
         1505  +** [limits | SQLITE4_MAX_<i>NAME</i>].
         1506  +** (The "_LIMIT_" in the name is changed to "_MAX_".))^
         1507  +** ^Attempts to increase a limit above its hard upper bound are
         1508  +** silently truncated to the hard upper bound.
         1509  +**
         1510  +** ^Regardless of whether or not the limit was changed, the 
         1511  +** [sqlite4_limit()] interface returns the prior value of the limit.
         1512  +** ^Hence, to find the current value of a limit without changing it,
         1513  +** simply invoke this interface with the third parameter set to -1.
         1514  +**
         1515  +** Run-time limits are intended for use in applications that manage
         1516  +** both their own internal database and also databases that are controlled
         1517  +** by untrusted external sources.  An example application might be a
         1518  +** web browser that has its own databases for storing history and
         1519  +** separate databases controlled by JavaScript applications downloaded
         1520  +** off the Internet.  The internal databases can be given the
         1521  +** large, default limits.  Databases managed by external sources can
         1522  +** be given much smaller limits designed to prevent a denial of service
         1523  +** attack.  Developers might also want to use the [sqlite4_set_authorizer()]
         1524  +** interface to further control untrusted SQL.  The size of the database
         1525  +** created by an untrusted script can be contained using the
         1526  +** [max_page_count] [PRAGMA].
         1527  +**
         1528  +** New run-time limit categories may be added in future releases.
         1529  +*/
         1530  +SQLITE4_API int sqlite4_limit(sqlite4*, int id, int newVal);
         1531  +
         1532  +/*
         1533  +** CAPIREF: Run-Time Limit Categories
         1534  +** KEYWORDS: {limit category} {*limit categories}
         1535  +**
         1536  +** These constants define various performance limits
         1537  +** that can be lowered at run-time using [sqlite4_limit()].
         1538  +** The synopsis of the meanings of the various limits is shown below.
         1539  +** Additional information is available at [limits | Limits in SQLite].
         1540  +**
         1541  +** <dl>
         1542  +** [[SQLITE4_LIMIT_LENGTH]] ^(<dt>SQLITE4_LIMIT_LENGTH</dt>
         1543  +** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
         1544  +**
         1545  +** [[SQLITE4_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE4_LIMIT_SQL_LENGTH</dt>
         1546  +** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
         1547  +**
         1548  +** [[SQLITE4_LIMIT_COLUMN]] ^(<dt>SQLITE4_LIMIT_COLUMN</dt>
         1549  +** <dd>The maximum number of columns in a table definition or in the
         1550  +** result set of a [SELECT] or the maximum number of columns in an index
         1551  +** or in an ORDER BY or GROUP BY clause.</dd>)^
         1552  +**
         1553  +** [[SQLITE4_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE4_LIMIT_EXPR_DEPTH</dt>
         1554  +** <dd>The maximum depth of the parse tree on any expression.</dd>)^
         1555  +**
         1556  +** [[SQLITE4_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE4_LIMIT_COMPOUND_SELECT</dt>
         1557  +** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
         1558  +**
         1559  +** [[SQLITE4_LIMIT_VDBE_OP]] ^(<dt>SQLITE4_LIMIT_VDBE_OP</dt>
         1560  +** <dd>The maximum number of instructions in a virtual machine program
         1561  +** used to implement an SQL statement.  This limit is not currently
         1562  +** enforced, though that might be added in some future release of
         1563  +** SQLite.</dd>)^
         1564  +**
         1565  +** [[SQLITE4_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE4_LIMIT_FUNCTION_ARG</dt>
         1566  +** <dd>The maximum number of arguments on a function.</dd>)^
         1567  +**
         1568  +** [[SQLITE4_LIMIT_ATTACHED]] ^(<dt>SQLITE4_LIMIT_ATTACHED</dt>
         1569  +** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
         1570  +**
         1571  +** [[SQLITE4_LIMIT_LIKE_PATTERN_LENGTH]]
         1572  +** ^(<dt>SQLITE4_LIMIT_LIKE_PATTERN_LENGTH</dt>
         1573  +** <dd>The maximum length of the pattern argument to the [LIKE] or
         1574  +** [GLOB] operators.</dd>)^
         1575  +**
         1576  +** [[SQLITE4_LIMIT_VARIABLE_NUMBER]]
         1577  +** ^(<dt>SQLITE4_LIMIT_VARIABLE_NUMBER</dt>
         1578  +** <dd>The maximum index number of any [parameter] in an SQL statement.)^
         1579  +**
         1580  +** [[SQLITE4_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE4_LIMIT_TRIGGER_DEPTH</dt>
         1581  +** <dd>The maximum depth of recursion for triggers.</dd>)^
         1582  +** </dl>
         1583  +*/
         1584  +#define SQLITE4_LIMIT_LENGTH                    0
         1585  +#define SQLITE4_LIMIT_SQL_LENGTH                1
         1586  +#define SQLITE4_LIMIT_COLUMN                    2
         1587  +#define SQLITE4_LIMIT_EXPR_DEPTH                3
         1588  +#define SQLITE4_LIMIT_COMPOUND_SELECT           4
         1589  +#define SQLITE4_LIMIT_VDBE_OP                   5
         1590  +#define SQLITE4_LIMIT_FUNCTION_ARG              6
         1591  +#define SQLITE4_LIMIT_ATTACHED                  7
         1592  +#define SQLITE4_LIMIT_LIKE_PATTERN_LENGTH       8
         1593  +#define SQLITE4_LIMIT_VARIABLE_NUMBER           9
         1594  +#define SQLITE4_LIMIT_TRIGGER_DEPTH            10
         1595  +
         1596  +/*
         1597  +** CAPIREF: Compiling An SQL Statement
         1598  +** KEYWORDS: {SQL statement compiler}
         1599  +**
         1600  +** To execute an SQL query, it must first be compiled into a byte-code
         1601  +** program using one of these routines.
         1602  +**
         1603  +** The first argument, "db", is a [database connection] obtained from a
         1604  +** prior successful call to [sqlite4_open()].
         1605  +** The database connection must not have been closed.
         1606  +**
         1607  +** The second argument, "zSql", is the statement to be compiled, encoded
         1608  +** as either UTF-8 or UTF-16.  The sqlite4_prepare()
         1609  +** interface uses UTF-8, and sqlite4_prepare16()
         1610  +** uses UTF-16.
         1611  +**
         1612  +** ^If the nByte argument is less than zero, then zSql is read up to the
         1613  +** first zero terminator. ^If nByte is non-negative, then it is the maximum
         1614  +** number of  bytes read from zSql.  ^When nByte is non-negative, the
         1615  +** zSql string ends at either the first '\000' or '\u0000' character or
         1616  +** the nByte-th byte, whichever comes first. If the caller knows
         1617  +** that the supplied string is nul-terminated, then there is a small
         1618  +** performance advantage to be gained by passing an nByte parameter that
         1619  +** is equal to the number of bytes in the input string <i>including</i>
         1620  +** the nul-terminator bytes as this saves SQLite from having to
         1621  +** make a copy of the input string.
         1622  +**
         1623  +** ^If pzTail is not NULL then *pzTail is made to point to the first byte
         1624  +** past the end of the first SQL statement in zSql.  These routines only
         1625  +** compile the first statement in zSql, so *pzTail is left pointing to
         1626  +** what remains uncompiled.
         1627  +**
         1628  +** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
         1629  +** executed using [sqlite4_step()].  ^If there is an error, *ppStmt is set
         1630  +** to NULL.  ^If the input text contains no SQL (if the input is an empty
         1631  +** string or a comment) then *ppStmt is set to NULL.
         1632  +** The calling procedure is responsible for deleting the compiled
         1633  +** SQL statement using [sqlite4_finalize()] after it has finished with it.
         1634  +** ppStmt may not be NULL.
         1635  +**
         1636  +** ^On success, the sqlite4_prepare() family of routines return [SQLITE4_OK];
         1637  +** otherwise an [error code] is returned.
         1638  +*/
         1639  +SQLITE4_API int sqlite4_prepare(
         1640  +  sqlite4 *db,            /* Database handle */
         1641  +  const char *zSql,       /* SQL statement, UTF-8 encoded */
         1642  +  int nByte,              /* Maximum length of zSql in bytes. */
         1643  +  sqlite4_stmt **ppStmt,  /* OUT: Statement handle */
         1644  +  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
         1645  +);
         1646  +
         1647  +/*
         1648  +** CAPIREF: Retrieving Statement SQL
         1649  +**
         1650  +** ^This interface can be used to retrieve a saved copy of the original
         1651  +** SQL text used to create a [prepared statement] if that statement was
         1652  +** compiled using either [sqlite4_prepare()] or [sqlite4_prepare16_v2()].
         1653  +*/
         1654  +SQLITE4_API const char *sqlite4_sql(sqlite4_stmt *pStmt);
         1655  +
         1656  +/*
         1657  +** CAPIREF: Determine If An SQL Statement Writes The Database
         1658  +**
         1659  +** ^The sqlite4_stmt_readonly(X) interface returns true (non-zero) if
         1660  +** and only if the [prepared statement] X makes no direct changes to
         1661  +** the content of the database file.
         1662  +**
         1663  +** Note that [application-defined SQL functions] or
         1664  +** [virtual tables] might change the database indirectly as a side effect.  
         1665  +** ^(For example, if an application defines a function "eval()" that 
         1666  +** calls [sqlite4_exec()], then the following SQL statement would
         1667  +** change the database file through side-effects:
         1668  +**
         1669  +** <blockquote><pre>
         1670  +**    SELECT eval('DELETE FROM t1') FROM t2;
         1671  +** </pre></blockquote>
         1672  +**
         1673  +** But because the [SELECT] statement does not change the database file
         1674  +** directly, sqlite4_stmt_readonly() would still return true.)^
         1675  +**
         1676  +** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
         1677  +** [SAVEPOINT], and [RELEASE] cause sqlite4_stmt_readonly() to return true,
         1678  +** since the statements themselves do not actually modify the database but
         1679  +** rather they control the timing of when other statements modify the 
         1680  +** database.  ^The [ATTACH] and [DETACH] statements also cause
         1681  +** sqlite4_stmt_readonly() to return true since, while those statements
         1682  +** change the configuration of a database connection, they do not make 
         1683  +** changes to the content of the database files on disk.
         1684  +*/
         1685  +SQLITE4_API int sqlite4_stmt_readonly(sqlite4_stmt *pStmt);
         1686  +
         1687  +/*
         1688  +** CAPIREF: Determine If A Prepared Statement Has Been Reset
         1689  +**
         1690  +** ^The sqlite4_stmt_busy(S) interface returns true (non-zero) if the
         1691  +** [prepared statement] S has been stepped at least once using 
         1692  +** [sqlite4_step(S)] but has not run to completion and/or has not 
         1693  +** been reset using [sqlite4_reset(S)].  ^The sqlite4_stmt_busy(S)
         1694  +** interface returns false if S is a NULL pointer.  If S is not a 
         1695  +** NULL pointer and is not a pointer to a valid [prepared statement]
         1696  +** object, then the behavior is undefined and probably undesirable.
         1697  +**
         1698  +** This interface can be used in combination [sqlite4_next_stmt()]
         1699  +** to locate all prepared statements associated with a database 
         1700  +** connection that are in need of being reset.  This can be used,
         1701  +** for example, in diagnostic routines to search for prepared 
         1702  +** statements that are holding a transaction open.
         1703  +*/
         1704  +SQLITE4_API int sqlite4_stmt_busy(sqlite4_stmt*);
         1705  +
         1706  +/*
         1707  +** CAPIREF: Dynamically Typed Value Object
         1708  +** KEYWORDS: {protected sqlite4_value} {unprotected sqlite4_value}
         1709  +**
         1710  +** SQLite uses the sqlite4_value object to represent all values
         1711  +** that can be stored in a database table. SQLite uses dynamic typing
         1712  +** for the values it stores.  ^Values stored in sqlite4_value objects
         1713  +** can be integers, floating point values, strings, BLOBs, or NULL.
         1714  +**
         1715  +** An sqlite4_value object may be either "protected" or "unprotected".
         1716  +** Some interfaces require a protected sqlite4_value.  Other interfaces
         1717  +** will accept either a protected or an unprotected sqlite4_value.
         1718  +** Every interface that accepts sqlite4_value arguments specifies
         1719  +** whether or not it requires a protected sqlite4_value.
         1720  +**
         1721  +** The terms "protected" and "unprotected" refer to whether or not
         1722  +** a mutex is held.  An internal mutex is held for a protected
         1723  +** sqlite4_value object but no mutex is held for an unprotected
         1724  +** sqlite4_value object.  If SQLite is compiled to be single-threaded
         1725  +** (with [SQLITE4_THREADSAFE=0] and with [sqlite4_threadsafe()] returning 0)
         1726  +** or if SQLite is run in one of reduced mutex modes 
         1727  +** [SQLITE4_CONFIG_SINGLETHREAD] or [SQLITE4_CONFIG_MULTITHREAD]
         1728  +** then there is no distinction between protected and unprotected
         1729  +** sqlite4_value objects and they can be used interchangeably.  However,
         1730  +** for maximum code portability it is recommended that applications
         1731  +** still make the distinction between protected and unprotected
         1732  +** sqlite4_value objects even when not strictly required.
         1733  +**
         1734  +** ^The sqlite4_value objects that are passed as parameters into the
         1735  +** implementation of [application-defined SQL functions] are protected.
         1736  +** ^The sqlite4_value object returned by
         1737  +** [sqlite4_column_value()] is unprotected.
         1738  +** Unprotected sqlite4_value objects may only be used with
         1739  +** [sqlite4_result_value()] and [sqlite4_bind_value()].
         1740  +** The [sqlite4_value_blob | sqlite4_value_type()] family of
         1741  +** interfaces require protected sqlite4_value objects.
         1742  +*/
         1743  +typedef struct Mem sqlite4_value;
         1744  +
         1745  +/*
         1746  +** CAPIREF: SQL Function Context Object
         1747  +**
         1748  +** The context in which an SQL function executes is stored in an
         1749  +** sqlite4_context object.  ^A pointer to an sqlite4_context object
         1750  +** is always first parameter to [application-defined SQL functions].
         1751  +** The application-defined SQL function implementation will pass this
         1752  +** pointer through into calls to [sqlite4_result_int | sqlite4_result()],
         1753  +** [sqlite4_aggregate_context()], [sqlite4_user_data()],
         1754  +** [sqlite4_context_db_handle()], [sqlite4_get_auxdata()],
         1755  +** and/or [sqlite4_set_auxdata()].
         1756  +*/
         1757  +typedef struct sqlite4_context sqlite4_context;
         1758  +
         1759  +/*
         1760  +** CAPIREF: Binding Values To Prepared Statements
         1761  +** KEYWORDS: {host parameter} {host parameters} {host parameter name}
         1762  +** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
         1763  +**
         1764  +** ^(In the SQL statement text input to [sqlite4_prepare()] and its variants,
         1765  +** literals may be replaced by a [parameter] that matches one of following
         1766  +** templates:
         1767  +**
         1768  +** <ul>
         1769  +** <li>  ?
         1770  +** <li>  ?NNN
         1771  +** <li>  :VVV
         1772  +** <li>  @VVV
         1773  +** <li>  $VVV
         1774  +** </ul>
         1775  +**
         1776  +** In the templates above, NNN represents an integer literal,
         1777  +** and VVV represents an alphanumeric identifier.)^  ^The values of these
         1778  +** parameters (also called "host parameter names" or "SQL parameters")
         1779  +** can be set using the sqlite4_bind_*() routines defined here.
         1780  +**
         1781  +** ^The first argument to the sqlite4_bind_*() routines is always
         1782  +** a pointer to the [sqlite4_stmt] object returned from
         1783  +** [sqlite4_prepare()] or its variants.
         1784  +**
         1785  +** ^The second argument is the index of the SQL parameter to be set.
         1786  +** ^The leftmost SQL parameter has an index of 1.  ^When the same named
         1787  +** SQL parameter is used more than once, second and subsequent
         1788  +** occurrences have the same index as the first occurrence.
         1789  +** ^The index for named parameters can be looked up using the
         1790  +** [sqlite4_bind_parameter_index()] API if desired.  ^The index
         1791  +** for "?NNN" parameters is the value of NNN.
         1792  +** ^The NNN value must be between 1 and the [sqlite4_limit()]
         1793  +** parameter [SQLITE4_LIMIT_VARIABLE_NUMBER] (default value: 999).
         1794  +**
         1795  +** ^The third argument is the value to bind to the parameter.
         1796  +**
         1797  +** ^(In those routines that have a fourth argument, its value is the
         1798  +** number of bytes in the parameter.  To be clear: the value is the
         1799  +** number of <u>bytes</u> in the value, not the number of characters.)^
         1800  +** ^If the fourth parameter is negative, the length of the string is
         1801  +** the number of bytes up to the first zero terminator.
         1802  +** If a non-negative fourth parameter is provided to sqlite4_bind_text()
         1803  +** or sqlite4_bind_text16() then that parameter must be the byte offset
         1804  +** where the NUL terminator would occur assuming the string were NUL
         1805  +** terminated.  If any NUL characters occur at byte offsets less than 
         1806  +** the value of the fourth parameter then the resulting string value will
         1807  +** contain embedded NULs.  The result of expressions involving strings
         1808  +** with embedded NULs is undefined.
         1809  +**
         1810  +** ^The fifth argument to sqlite4_bind_blob(), sqlite4_bind_text(), and
         1811  +** sqlite4_bind_text16() is a destructor used to dispose of the BLOB or
         1812  +** string after SQLite has finished with it.  ^The destructor is called
         1813  +** to dispose of the BLOB or string even if the call to sqlite4_bind_blob(),
         1814  +** sqlite4_bind_text(), or sqlite4_bind_text16() fails.  
         1815  +** ^If the fifth argument is
         1816  +** the special value [SQLITE4_STATIC], then SQLite assumes that the
         1817  +** information is in static, unmanaged space and does not need to be freed.
         1818  +** ^If the fifth argument has the value [SQLITE4_TRANSIENT], then
         1819  +** SQLite makes its own private copy of the data immediately, before
         1820  +** the sqlite4_bind_*() routine returns.
         1821  +**
         1822  +** ^The sqlite4_bind_zeroblob() routine binds a BLOB of length N that
         1823  +** is filled with zeroes.  ^A zeroblob uses a fixed amount of memory
         1824  +** (just an integer to hold its size) while it is being processed.
         1825  +** Zeroblobs are intended to serve as placeholders for BLOBs whose
         1826  +** content is later written using
         1827  +** [sqlite4_blob_open | incremental BLOB I/O] routines.
         1828  +** ^A negative value for the zeroblob results in a zero-length BLOB.
         1829  +**
         1830  +** ^If any of the sqlite4_bind_*() routines are called with a NULL pointer
         1831  +** for the [prepared statement] or with a prepared statement for which
         1832  +** [sqlite4_step()] has been called more recently than [sqlite4_reset()],
         1833  +** then the call will return [SQLITE4_MISUSE].  If any sqlite4_bind_()
         1834  +** routine is passed a [prepared statement] that has been finalized, the
         1835  +** result is undefined and probably harmful.
         1836  +**
         1837  +** ^Bindings are not cleared by the [sqlite4_reset()] routine.
         1838  +** ^Unbound parameters are interpreted as NULL.
         1839  +**
         1840  +** ^The sqlite4_bind_* routines return [SQLITE4_OK] on success or an
         1841  +** [error code] if anything goes wrong.
         1842  +** ^[SQLITE4_RANGE] is returned if the parameter
         1843  +** index is out of range.  ^[SQLITE4_NOMEM] is returned if malloc() fails.
         1844  +**
         1845  +** See also: [sqlite4_bind_parameter_count()],
         1846  +** [sqlite4_bind_parameter_name()], and [sqlite4_bind_parameter_index()].
         1847  +*/
         1848  +SQLITE4_API int sqlite4_bind_blob(sqlite4_stmt*, int, const void*, int n, void(*)(void*));
         1849  +SQLITE4_API int sqlite4_bind_double(sqlite4_stmt*, int, double);
         1850  +SQLITE4_API int sqlite4_bind_int(sqlite4_stmt*, int, int);
         1851  +SQLITE4_API int sqlite4_bind_int64(sqlite4_stmt*, int, sqlite4_int64);
         1852  +SQLITE4_API int sqlite4_bind_null(sqlite4_stmt*, int);
         1853  +SQLITE4_API int sqlite4_bind_text(sqlite4_stmt*, int, const char*, int n, void(*)(void*));
         1854  +SQLITE4_API int sqlite4_bind_text16(sqlite4_stmt*, int, const void*, int, void(*)(void*));
         1855  +SQLITE4_API int sqlite4_bind_value(sqlite4_stmt*, int, const sqlite4_value*);
         1856  +SQLITE4_API int sqlite4_bind_zeroblob(sqlite4_stmt*, int, int n);
         1857  +
         1858  +/*
         1859  +** CAPIREF: Number Of SQL Parameters
         1860  +**
         1861  +** ^This routine can be used to find the number of [SQL parameters]
         1862  +** in a [prepared statement].  SQL parameters are tokens of the
         1863  +** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
         1864  +** placeholders for values that are [sqlite4_bind_blob | bound]
         1865  +** to the parameters at a later time.
         1866  +**
         1867  +** ^(This routine actually returns the index of the largest (rightmost)
         1868  +** parameter. For all forms except ?NNN, this will correspond to the
         1869  +** number of unique parameters.  If parameters of the ?NNN form are used,
         1870  +** there may be gaps in the list.)^
         1871  +**
         1872  +** See also: [sqlite4_bind_blob|sqlite4_bind()],
         1873  +** [sqlite4_bind_parameter_name()], and
         1874  +** [sqlite4_bind_parameter_index()].
         1875  +*/
         1876  +SQLITE4_API int sqlite4_bind_parameter_count(sqlite4_stmt*);
         1877  +
         1878  +/*
         1879  +** CAPIREF: Name Of A Host Parameter
         1880  +**
         1881  +** ^The sqlite4_bind_parameter_name(P,N) interface returns
         1882  +** the name of the N-th [SQL parameter] in the [prepared statement] P.
         1883  +** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
         1884  +** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
         1885  +** respectively.
         1886  +** In other words, the initial ":" or "$" or "@" or "?"
         1887  +** is included as part of the name.)^
         1888  +** ^Parameters of the form "?" without a following integer have no name
         1889  +** and are referred to as "nameless" or "anonymous parameters".
         1890  +**
         1891  +** ^The first host parameter has an index of 1, not 0.
         1892  +**
         1893  +** ^If the value N is out of range or if the N-th parameter is
         1894  +** nameless, then NULL is returned.  ^The returned string is
         1895  +** always in UTF-8 encoding even if the named parameter was
         1896  +** originally specified as UTF-16 in [sqlite4_prepare16()] or
         1897  +** [sqlite4_prepare16_v2()].
         1898  +**
         1899  +** See also: [sqlite4_bind_blob|sqlite4_bind()],
         1900  +** [sqlite4_bind_parameter_count()], and
         1901  +** [sqlite4_bind_parameter_index()].
         1902  +*/
         1903  +SQLITE4_API const char *sqlite4_bind_parameter_name(sqlite4_stmt*, int);
         1904  +
         1905  +/*
         1906  +** CAPIREF: Index Of A Parameter With A Given Name
         1907  +**
         1908  +** ^Return the index of an SQL parameter given its name.  ^The
         1909  +** index value returned is suitable for use as the second
         1910  +** parameter to [sqlite4_bind_blob|sqlite4_bind()].  ^A zero
         1911  +** is returned if no matching parameter is found.  ^The parameter
         1912  +** name must be given in UTF-8 even if the original statement
         1913  +** was prepared from UTF-16 text using [sqlite4_prepare16_v2()].
         1914  +**
         1915  +** See also: [sqlite4_bind_blob|sqlite4_bind()],
         1916  +** [sqlite4_bind_parameter_count()], and
         1917  +** [sqlite4_bind_parameter_index()].
         1918  +*/
         1919  +SQLITE4_API int sqlite4_bind_parameter_index(sqlite4_stmt*, const char *zName);
         1920  +
         1921  +/*
         1922  +** CAPIREF: Reset All Bindings On A Prepared Statement
         1923  +**
         1924  +** ^Contrary to the intuition of many, [sqlite4_reset()] does not reset
         1925  +** the [sqlite4_bind_blob | bindings] on a [prepared statement].
         1926  +** ^Use this routine to reset all host parameters to NULL.
         1927  +*/
         1928  +SQLITE4_API int sqlite4_clear_bindings(sqlite4_stmt*);
         1929  +
         1930  +/*
         1931  +** CAPIREF: Number Of Columns In A Result Set
         1932  +**
         1933  +** ^Return the number of columns in the result set returned by the
         1934  +** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
         1935  +** statement that does not return data (for example an [UPDATE]).
         1936  +**
         1937  +** See also: [sqlite4_data_count()]
         1938  +*/
         1939  +SQLITE4_API int sqlite4_column_count(sqlite4_stmt *pStmt);
         1940  +
         1941  +/*
         1942  +** CAPIREF: Column Names In A Result Set
         1943  +**
         1944  +** ^These routines return the name assigned to a particular column
         1945  +** in the result set of a [SELECT] statement.  ^The sqlite4_column_name()
         1946  +** interface returns a pointer to a zero-terminated UTF-8 string
         1947  +** and sqlite4_column_name16() returns a pointer to a zero-terminated
         1948  +** UTF-16 string.  ^The first parameter is the [prepared statement]
         1949  +** that implements the [SELECT] statement. ^The second parameter is the
         1950  +** column number.  ^The leftmost column is number 0.
         1951  +**
         1952  +** ^The returned string pointer is valid until either the [prepared statement]
         1953  +** is destroyed by [sqlite4_finalize()] or until the statement is automatically
         1954  +** reprepared by the first call to [sqlite4_step()] for a particular run
         1955  +** or until the next call to
         1956  +** sqlite4_column_name() or sqlite4_column_name16() on the same column.
         1957  +**
         1958  +** ^If sqlite4_malloc() fails during the processing of either routine
         1959  +** (for example during a conversion from UTF-8 to UTF-16) then a
         1960  +** NULL pointer is returned.
         1961  +**
         1962  +** ^The name of a result column is the value of the "AS" clause for
         1963  +** that column, if there is an AS clause.  If there is no AS clause
         1964  +** then the name of the column is unspecified and may change from
         1965  +** one release of SQLite to the next.
         1966  +*/
         1967  +SQLITE4_API const char *sqlite4_column_name(sqlite4_stmt*, int N);
         1968  +SQLITE4_API const void *sqlite4_column_name16(sqlite4_stmt*, int N);
         1969  +
         1970  +/*
         1971  +** CAPIREF: Source Of Data In A Query Result
         1972  +**
         1973  +** ^These routines provide a means to determine the database, table, and
         1974  +** table column that is the origin of a particular result column in
         1975  +** [SELECT] statement.
         1976  +** ^The name of the database or table or column can be returned as
         1977  +** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
         1978  +** the database name, the _table_ routines return the table name, and
         1979  +** the origin_ routines return the column name.
         1980  +** ^The returned string is valid until the [prepared statement] is destroyed
         1981  +** using [sqlite4_finalize()] or until the statement is automatically
         1982  +** reprepared by the first call to [sqlite4_step()] for a particular run
         1983  +** or until the same information is requested
         1984  +** again in a different encoding.
         1985  +**
         1986  +** ^The names returned are the original un-aliased names of the
         1987  +** database, table, and column.
         1988  +**
         1989  +** ^The first argument to these interfaces is a [prepared statement].
         1990  +** ^These functions return information about the Nth result column returned by
         1991  +** the statement, where N is the second function argument.
         1992  +** ^The left-most column is column 0 for these routines.
         1993  +**
         1994  +** ^If the Nth column returned by the statement is an expression or
         1995  +** subquery and is not a column value, then all of these functions return
         1996  +** NULL.  ^These routine might also return NULL if a memory allocation error
         1997  +** occurs.  ^Otherwise, they return the name of the attached database, table,
         1998  +** or column that query result column was extracted from.
         1999  +**
         2000  +** ^As with all other SQLite APIs, those whose names end with "16" return
         2001  +** UTF-16 encoded strings and the other functions return UTF-8.
         2002  +**
         2003  +** ^These APIs are only available if the library was compiled with the
         2004  +** [SQLITE4_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
         2005  +**
         2006  +** If two or more threads call one or more of these routines against the same
         2007  +** prepared statement and column at the same time then the results are
         2008  +** undefined.
         2009  +**
         2010  +** If two or more threads call one or more
         2011  +** [sqlite4_column_database_name | column metadata interfaces]
         2012  +** for the same [prepared statement] and result column
         2013  +** at the same time then the results are undefined.
         2014  +*/
         2015  +SQLITE4_API const char *sqlite4_column_database_name(sqlite4_stmt*,int);
         2016  +SQLITE4_API const void *sqlite4_column_database_name16(sqlite4_stmt*,int);
         2017  +SQLITE4_API const char *sqlite4_column_table_name(sqlite4_stmt*,int);
         2018  +SQLITE4_API const void *sqlite4_column_table_name16(sqlite4_stmt*,int);
         2019  +SQLITE4_API const char *sqlite4_column_origin_name(sqlite4_stmt*,int);
         2020  +SQLITE4_API const void *sqlite4_column_origin_name16(sqlite4_stmt*,int);
         2021  +
         2022  +/*
         2023  +** CAPIREF: Declared Datatype Of A Query Result
         2024  +**
         2025  +** ^(The first parameter is a [prepared statement].
         2026  +** If this statement is a [SELECT] statement and the Nth column of the
         2027  +** returned result set of that [SELECT] is a table column (not an
         2028  +** expression or subquery) then the declared type of the table
         2029  +** column is returned.)^  ^If the Nth column of the result set is an
         2030  +** expression or subquery, then a NULL pointer is returned.
         2031  +** ^The returned string is always UTF-8 encoded.
         2032  +**
         2033  +** ^(For example, given the database schema:
         2034  +**
         2035  +** CREATE TABLE t1(c1 VARIANT);
         2036  +**
         2037  +** and the following statement to be compiled:
         2038  +**
         2039  +** SELECT c1 + 1, c1 FROM t1;
         2040  +**
         2041  +** this routine would return the string "VARIANT" for the second result
         2042  +** column (i==1), and a NULL pointer for the first result column (i==0).)^
         2043  +**
         2044  +** ^SQLite uses dynamic run-time typing.  ^So just because a column
         2045  +** is declared to contain a particular type does not mean that the
         2046  +** data stored in that column is of the declared type.  SQLite is
         2047  +** strongly typed, but the typing is dynamic not static.  ^Type
         2048  +** is associated with individual values, not with the containers
         2049  +** used to hold those values.
         2050  +*/
         2051  +SQLITE4_API const char *sqlite4_column_decltype(sqlite4_stmt*,int);
         2052  +SQLITE4_API const void *sqlite4_column_decltype16(sqlite4_stmt*,int);
         2053  +
         2054  +/*
         2055  +** CAPIREF: Evaluate An SQL Statement
         2056  +**
         2057  +** After a [prepared statement] has been prepared using [sqlite4_prepare()],
         2058  +** this function must be called one or more times to evaluate the statement.
         2059  +**
         2060  +** ^This routine can return any of the other [result codes] or
         2061  +** [extended result codes].
         2062  +**
         2063  +** ^[SQLITE4_BUSY] means that the database engine was unable to acquire the
         2064  +** database locks it needs to do its job.  ^If the statement is a [COMMIT]
         2065  +** or occurs outside of an explicit transaction, then you can retry the
         2066  +** statement.  If the statement is not a [COMMIT] and occurs within an
         2067  +** explicit transaction then you should rollback the transaction before
         2068  +** continuing.
         2069  +**
         2070  +** ^[SQLITE4_DONE] means that the statement has finished executing
         2071  +** successfully.  sqlite4_step() should not be called again on this virtual
         2072  +** machine without first calling [sqlite4_reset()] to reset the virtual
         2073  +** machine back to its initial state.
         2074  +**
         2075  +** ^If the SQL statement being executed returns any data, then [SQLITE4_ROW]
         2076  +** is returned each time a new row of data is ready for processing by the
         2077  +** caller. The values may be accessed using the [column access functions].
         2078  +** sqlite4_step() is called again to retrieve the next row of data.
         2079  +**
         2080  +** ^[SQLITE4_ERROR] means that a run-time error (such as a constraint
         2081  +** violation) has occurred.  sqlite4_step() should not be called again on
         2082  +** the VM. More information may be found by calling [sqlite4_errmsg()].
         2083  +**
         2084  +** [SQLITE4_MISUSE] means that the this routine was called inappropriately.
         2085  +** Perhaps it was called on a [prepared statement] that has
         2086  +** already been [sqlite4_finalize | finalized] or on one that had
         2087  +** previously returned [SQLITE4_ERROR] or [SQLITE4_DONE].  Or it could
         2088  +** be the case that the same database connection is being used by two or
         2089  +** more threads at the same moment in time.
         2090  +*/
         2091  +SQLITE4_API int sqlite4_step(sqlite4_stmt*);
         2092  +
         2093  +/*
         2094  +** CAPIREF: Number of columns in a result set
         2095  +**
         2096  +** ^The sqlite4_data_count(P) interface returns the number of columns in the
         2097  +** current row of the result set of [prepared statement] P.
         2098  +** ^If prepared statement P does not have results ready to return
         2099  +** (via calls to the [sqlite4_column_int | sqlite4_column_*()] of
         2100  +** interfaces) then sqlite4_data_count(P) returns 0.
         2101  +** ^The sqlite4_data_count(P) routine also returns 0 if P is a NULL pointer.
         2102  +** ^The sqlite4_data_count(P) routine returns 0 if the previous call to
         2103  +** [sqlite4_step](P) returned [SQLITE4_DONE].  ^The sqlite4_data_count(P)
         2104  +** will return non-zero if previous call to [sqlite4_step](P) returned
         2105  +** [SQLITE4_ROW], except in the case of the [PRAGMA incremental_vacuum]
         2106  +** where it always returns zero since each step of that multi-step
         2107  +** pragma returns 0 columns of data.
         2108  +**
         2109  +** See also: [sqlite4_column_count()]
         2110  +*/
         2111  +SQLITE4_API int sqlite4_data_count(sqlite4_stmt *pStmt);
         2112  +
         2113  +/*
         2114  +** CAPIREF: Fundamental Datatypes
         2115  +** KEYWORDS: SQLITE4_TEXT
         2116  +**
         2117  +** ^(Every value in SQLite has one of five fundamental datatypes:
         2118  +**
         2119  +** <ul>
         2120  +** <li> 64-bit signed integer
         2121  +** <li> 64-bit IEEE floating point number
         2122  +** <li> string
         2123  +** <li> BLOB
         2124  +** <li> NULL
         2125  +** </ul>)^
         2126  +**
         2127  +** These constants are codes for each of those types.
         2128  +*/
         2129  +#define SQLITE4_INTEGER  1
         2130  +#define SQLITE4_FLOAT    2
         2131  +#define SQLITE4_TEXT     3
         2132  +#define SQLITE4_BLOB     4
         2133  +#define SQLITE4_NULL     5
         2134  +
         2135  +/*
         2136  +** CAPIREF: Result Values From A Query
         2137  +** KEYWORDS: {column access functions}
         2138  +**
         2139  +** These routines form the "result set" interface.
         2140  +**
         2141  +** ^These routines return information about a single column of the current
         2142  +** result row of a query.  ^In every case the first argument is a pointer
         2143  +** to the [prepared statement] that is being evaluated (the [sqlite4_stmt*]
         2144  +** that was returned from [sqlite4_prepare()].
         2145  +** and the second argument is the index of the column for which information
         2146  +** should be returned. ^The leftmost column of the result set has the index 0.
         2147  +** ^The number of columns in the result can be determined using
         2148  +** [sqlite4_column_count()].
         2149  +**
         2150  +** If the SQL statement does not currently point to a valid row, or if the
         2151  +** column index is out of range, the result is undefined.
         2152  +** These routines may only be called when the most recent call to
         2153  +** [sqlite4_step()] has returned [SQLITE4_ROW] and neither
         2154  +** [sqlite4_reset()] nor [sqlite4_finalize()] have been called subsequently.
         2155  +** If any of these routines are called after [sqlite4_reset()] or
         2156  +** [sqlite4_finalize()] or after [sqlite4_step()] has returned
         2157  +** something other than [SQLITE4_ROW], the results are undefined.
         2158  +** If [sqlite4_step()] or [sqlite4_reset()] or [sqlite4_finalize()]
         2159  +** are called from a different thread while any of these routines
         2160  +** are pending, then the results are undefined.
         2161  +**
         2162  +** ^The sqlite4_column_type() routine returns the
         2163  +** [SQLITE4_INTEGER | datatype code] for the initial data type
         2164  +** of the result column.  ^The returned value is one of [SQLITE4_INTEGER],
         2165  +** [SQLITE4_FLOAT], [SQLITE4_TEXT], [SQLITE4_BLOB], or [SQLITE4_NULL].  The value
         2166  +** returned by sqlite4_column_type() is only meaningful if no type
         2167  +** conversions have occurred as described below.  After a type conversion,
         2168  +** the value returned by sqlite4_column_type() is undefined.  Future
         2169  +** versions of SQLite may change the behavior of sqlite4_column_type()
         2170  +** following a type conversion.
         2171  +**
         2172  +** ^If the result is a BLOB or UTF-8 string then the sqlite4_column_bytes()
         2173  +** routine returns the number of bytes in that BLOB or string.
         2174  +** ^If the result is a UTF-16 string, then sqlite4_column_bytes() converts
         2175  +** the string to UTF-8 and then returns the number of bytes.
         2176  +** ^If the result is a numeric value then sqlite4_column_bytes() uses
         2177  +** [sqlite4_snprintf()] to convert that value to a UTF-8 string and returns
         2178  +** the number of bytes in that string.
         2179  +** ^If the result is NULL, then sqlite4_column_bytes() returns zero.
         2180  +**
         2181  +** ^If the result is a BLOB or UTF-16 string then the sqlite4_column_bytes16()
         2182  +** routine returns the number of bytes in that BLOB or string.
         2183  +** ^If the result is a UTF-8 string, then sqlite4_column_bytes16() converts
         2184  +** the string to UTF-16 and then returns the number of bytes.
         2185  +** ^If the result is a numeric value then sqlite4_column_bytes16() uses
         2186  +** [sqlite4_snprintf()] to convert that value to a UTF-16 string and returns
         2187  +** the number of bytes in that string.
         2188  +** ^If the result is NULL, then sqlite4_column_bytes16() returns zero.
         2189  +**
         2190  +** ^The values returned by [sqlite4_column_bytes()] and 
         2191  +** [sqlite4_column_bytes16()] do not include the zero terminators at the end
         2192  +** of the string.  ^For clarity: the values returned by
         2193  +** [sqlite4_column_bytes()] and [sqlite4_column_bytes16()] are the number of
         2194  +** bytes in the string, not the number of characters.
         2195  +**
         2196  +** ^Strings returned by sqlite4_column_text() and sqlite4_column_text16(),
         2197  +** even empty strings, are always zero-terminated.  ^The return
         2198  +** value from sqlite4_column_blob() for a zero-length BLOB is a NULL pointer.
         2199  +**
         2200  +** ^The object returned by [sqlite4_column_value()] is an
         2201  +** [unprotected sqlite4_value] object.  An unprotected sqlite4_value object
         2202  +** may only be used with [sqlite4_bind_value()] and [sqlite4_result_value()].
         2203  +** If the [unprotected sqlite4_value] object returned by
         2204  +** [sqlite4_column_value()] is used in any other way, including calls
         2205  +** to routines like [sqlite4_value_int()], [sqlite4_value_text()],
         2206  +** or [sqlite4_value_bytes()], then the behavior is undefined.
         2207  +**
         2208  +** These routines attempt to convert the value where appropriate.  ^For
         2209  +** example, if the internal representation is FLOAT and a text result
         2210  +** is requested, [sqlite4_snprintf()] is used internally to perform the
         2211  +** conversion automatically.  ^(The following table details the conversions
         2212  +** that are applied:
         2213  +**
         2214  +** <blockquote>
         2215  +** <table border="1">
         2216  +** <tr><th> Internal<br>Type <th> Requested<br>Type <th>  Conversion
         2217  +**
         2218  +** <tr><td>  NULL    <td> INTEGER   <td> Result is 0
         2219  +** <tr><td>  NULL    <td>  FLOAT    <td> Result is 0.0
         2220  +** <tr><td>  NULL    <td>   TEXT    <td> Result is NULL pointer
         2221  +** <tr><td>  NULL    <td>   BLOB    <td> Result is NULL pointer
         2222  +** <tr><td> INTEGER  <td>  FLOAT    <td> Convert from integer to float
         2223  +** <tr><td> INTEGER  <td>   TEXT    <td> ASCII rendering of the integer
         2224  +** <tr><td> INTEGER  <td>   BLOB    <td> Same as INTEGER->TEXT
         2225  +** <tr><td>  FLOAT   <td> INTEGER   <td> Convert from float to integer
         2226  +** <tr><td>  FLOAT   <td>   TEXT    <td> ASCII rendering of the float
         2227  +** <tr><td>  FLOAT   <td>   BLOB    <td> Same as FLOAT->TEXT
         2228  +** <tr><td>  TEXT    <td> INTEGER   <td> Use atoi()
         2229  +** <tr><td>  TEXT    <td>  FLOAT    <td> Use atof()
         2230  +** <tr><td>  TEXT    <td>   BLOB    <td> No change
         2231  +** <tr><td>  BLOB    <td> INTEGER   <td> Convert to TEXT then use atoi()
         2232  +** <tr><td>  BLOB    <td>  FLOAT    <td> Convert to TEXT then use atof()
         2233  +** <tr><td>  BLOB    <td>   TEXT    <td> Add a zero terminator if needed
         2234  +** </table>
         2235  +** </blockquote>)^
         2236  +**
         2237  +** The table above makes reference to standard C library functions atoi()
         2238  +** and atof().  SQLite does not really use these functions.  It has its
         2239  +** own equivalent internal routines.  The atoi() and atof() names are
         2240  +** used in the table for brevity and because they are familiar to most
         2241  +** C programmers.
         2242  +**
         2243  +** Note that when type conversions occur, pointers returned by prior
         2244  +** calls to sqlite4_column_blob(), sqlite4_column_text(), and/or
         2245  +** sqlite4_column_text16() may be invalidated.
         2246  +** Type conversions and pointer invalidations might occur
         2247  +** in the following cases:
         2248  +**
         2249  +** <ul>
         2250  +** <li> The initial content is a BLOB and sqlite4_column_text() or
         2251  +**      sqlite4_column_text16() is called.  A zero-terminator might
         2252  +**      need to be added to the string.</li>
         2253  +** <li> The initial content is UTF-8 text and sqlite4_column_bytes16() or
         2254  +**      sqlite4_column_text16() is called.  The content must be converted
         2255  +**      to UTF-16.</li>
         2256  +** <li> The initial content is UTF-16 text and sqlite4_column_bytes() or
         2257  +**      sqlite4_column_text() is called.  The content must be converted
         2258  +**      to UTF-8.</li>
         2259  +** </ul>
         2260  +**
         2261  +** ^Conversions between UTF-16be and UTF-16le are always done in place and do
         2262  +** not invalidate a prior pointer, though of course the content of the buffer
         2263  +** that the prior pointer references will have been modified.  Other kinds
         2264  +** of conversion are done in place when it is possible, but sometimes they
         2265  +** are not possible and in those cases prior pointers are invalidated.
         2266  +**
         2267  +** The safest and easiest to remember policy is to invoke these routines
         2268  +** in one of the following ways:
         2269  +**
         2270  +** <ul>
         2271  +**  <li>sqlite4_column_text() followed by sqlite4_column_bytes()</li>
         2272  +**  <li>sqlite4_column_blob() followed by sqlite4_column_bytes()</li>
         2273  +**  <li>sqlite4_column_text16() followed by sqlite4_column_bytes16()</li>
         2274  +** </ul>
         2275  +**
         2276  +** In other words, you should call sqlite4_column_text(),
         2277  +** sqlite4_column_blob(), or sqlite4_column_text16() first to force the result
         2278  +** into the desired format, then invoke sqlite4_column_bytes() or
         2279  +** sqlite4_column_bytes16() to find the size of the result.  Do not mix calls
         2280  +** to sqlite4_column_text() or sqlite4_column_blob() with calls to
         2281  +** sqlite4_column_bytes16(), and do not mix calls to sqlite4_column_text16()
         2282  +** with calls to sqlite4_column_bytes().
         2283  +**
         2284  +** ^The pointers returned are valid until a type conversion occurs as
         2285  +** described above, or until [sqlite4_step()] or [sqlite4_reset()] or
         2286  +** [sqlite4_finalize()] is called.  ^The memory space used to hold strings
         2287  +** and BLOBs is freed automatically.  Do <b>not</b> pass the pointers returned
         2288  +** [sqlite4_column_blob()], [sqlite4_column_text()], etc. into
         2289  +** [sqlite4_free()].
         2290  +**
         2291  +** ^(If a memory allocation error occurs during the evaluation of any
         2292  +** of these routines, a default value is returned.  The default value
         2293  +** is either the integer 0, the floating point number 0.0, or a NULL
         2294  +** pointer.  Subsequent calls to [sqlite4_errcode()] will return
         2295  +** [SQLITE4_NOMEM].)^
         2296  +*/
         2297  +SQLITE4_API const void *sqlite4_column_blob(sqlite4_stmt*, int iCol);
         2298  +SQLITE4_API int sqlite4_column_bytes(sqlite4_stmt*, int iCol);
         2299  +SQLITE4_API int sqlite4_column_bytes16(sqlite4_stmt*, int iCol);
         2300  +SQLITE4_API double sqlite4_column_double(sqlite4_stmt*, int iCol);
         2301  +SQLITE4_API int sqlite4_column_int(sqlite4_stmt*, int iCol);
         2302  +SQLITE4_API sqlite4_int64 sqlite4_column_int64(sqlite4_stmt*, int iCol);
         2303  +SQLITE4_API const unsigned char *sqlite4_column_text(sqlite4_stmt*, int iCol);
         2304  +SQLITE4_API const void *sqlite4_column_text16(sqlite4_stmt*, int iCol);
         2305  +SQLITE4_API int sqlite4_column_type(sqlite4_stmt*, int iCol);
         2306  +SQLITE4_API sqlite4_value *sqlite4_column_value(sqlite4_stmt*, int iCol);
         2307  +
         2308  +/*
         2309  +** CAPIREF: Destroy A Prepared Statement Object
         2310  +**
         2311  +** ^The sqlite4_finalize() function is called to delete a [prepared statement].
         2312  +** ^If the most recent evaluation of the statement encountered no errors
         2313  +** or if the statement is never been evaluated, then sqlite4_finalize() returns
         2314  +** SQLITE4_OK.  ^If the most recent evaluation of statement S failed, then
         2315  +** sqlite4_finalize(S) returns the appropriate [error code] or
         2316  +** [extended error code].
         2317  +**
         2318  +** ^The sqlite4_finalize(S) routine can be called at any point during
         2319  +** the life cycle of [prepared statement] S:
         2320  +** before statement S is ever evaluated, after
         2321  +** one or more calls to [sqlite4_reset()], or after any call
         2322  +** to [sqlite4_step()] regardless of whether or not the statement has
         2323  +** completed execution.
         2324  +**
         2325  +** ^Invoking sqlite4_finalize() on a NULL pointer is a harmless no-op.
         2326  +**
         2327  +** The application must finalize every [prepared statement] in order to avoid
         2328  +** resource leaks.  It is a grievous error for the application to try to use
         2329  +** a prepared statement after it has been finalized.  Any use of a prepared
         2330  +** statement after it has been finalized can result in undefined and
         2331  +** undesirable behavior such as segfaults and heap corruption.
         2332  +*/
         2333  +SQLITE4_API int sqlite4_finalize(sqlite4_stmt *pStmt);
         2334  +
         2335  +/*
         2336  +** CAPIREF: Reset A Prepared Statement Object
         2337  +**
         2338  +** The sqlite4_reset() function is called to reset a [prepared statement]
         2339  +** object back to its initial state, ready to be re-executed.
         2340  +** ^Any SQL statement variables that had values bound to them using
         2341  +** the [sqlite4_bind_blob | sqlite4_bind_*() API] retain their values.
         2342  +** Use [sqlite4_clear_bindings()] to reset the bindings.
         2343  +**
         2344  +** ^The [sqlite4_reset(S)] interface resets the [prepared statement] S
         2345  +** back to the beginning of its program.
         2346  +**
         2347  +** ^If the most recent call to [sqlite4_step(S)] for the
         2348  +** [prepared statement] S returned [SQLITE4_ROW] or [SQLITE4_DONE],
         2349  +** or if [sqlite4_step(S)] has never before been called on S,
         2350  +** then [sqlite4_reset(S)] returns [SQLITE4_OK].
         2351  +**
         2352  +** ^If the most recent call to [sqlite4_step(S)] for the
         2353  +** [prepared statement] S indicated an error, then
         2354  +** [sqlite4_reset(S)] returns an appropriate [error code].
         2355  +**
         2356  +** ^The [sqlite4_reset(S)] interface does not change the values
         2357  +** of any [sqlite4_bind_blob|bindings] on the [prepared statement] S.
         2358  +*/
         2359  +SQLITE4_API int sqlite4_reset(sqlite4_stmt *pStmt);
         2360  +
         2361  +/*
         2362  +** CAPIREF: Create Or Redefine SQL Functions
         2363  +** KEYWORDS: {function creation routines}
         2364  +** KEYWORDS: {application-defined SQL function}
         2365  +** KEYWORDS: {application-defined SQL functions}
         2366  +**
         2367  +** ^These functions (collectively known as "function creation routines")
         2368  +** are used to add SQL functions or aggregates or to redefine the behavior
         2369  +** of existing SQL functions or aggregates.  The only differences between
         2370  +** these routines are the text encoding expected for
         2371  +** the second parameter (the name of the function being created)
         2372  +** and the presence or absence of a destructor callback for
         2373  +** the application data pointer.
         2374  +**
         2375  +** ^The first parameter is the [database connection] to which the SQL
         2376  +** function is to be added.  ^If an application uses more than one database
         2377  +** connection then application-defined SQL functions must be added
         2378  +** to each database connection separately.
         2379  +**
         2380  +** ^The second parameter is the name of the SQL function to be created or
         2381  +** redefined.  ^The length of the name is limited to 255 bytes in a UTF-8
         2382  +** representation, exclusive of the zero-terminator.  ^Note that the name
         2383  +** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.  
         2384  +** ^Any attempt to create a function with a longer name
         2385  +** will result in [SQLITE4_MISUSE] being returned.
         2386  +**
         2387  +** ^The third parameter (nArg)
         2388  +** is the number of arguments that the SQL function or
         2389  +** aggregate takes. ^If this parameter is -1, then the SQL function or
         2390  +** aggregate may take any number of arguments between 0 and the limit
         2391  +** set by [sqlite4_limit]([SQLITE4_LIMIT_FUNCTION_ARG]).  If the third
         2392  +** parameter is less than -1 or greater than 127 then the behavior is
         2393  +** undefined.
         2394  +**
         2395  +** ^The fourth parameter, eTextRep, specifies what
         2396  +** [SQLITE4_UTF8 | text encoding] this SQL function prefers for
         2397  +** its parameters.  Every SQL function implementation must be able to work
         2398  +** with UTF-8, UTF-16le, or UTF-16be.  But some implementations may be
         2399  +** more efficient with one encoding than another.  ^An application may
         2400  +** invoke sqlite4_create_function() or sqlite4_create_function16() multiple
         2401  +** times with the same function but with different values of eTextRep.
         2402  +** ^When multiple implementations of the same function are available, SQLite
         2403  +** will pick the one that involves the least amount of data conversion.
         2404  +** If there is only a single implementation which does not care what text
         2405  +** encoding is used, then the fourth argument should be [SQLITE4_ANY].
         2406  +**
         2407  +** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
         2408  +** function can gain access to this pointer using [sqlite4_user_data()].)^
         2409  +**
         2410  +** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
         2411  +** pointers to C-language functions that implement the SQL function or
         2412  +** aggregate. ^A scalar SQL function requires an implementation of the xFunc
         2413  +** callback only; NULL pointers must be passed as the xStep and xFinal
         2414  +** parameters. ^An aggregate SQL function requires an implementation of xStep
         2415  +** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
         2416  +** SQL function or aggregate, pass NULL pointers for all three function
         2417  +** callbacks.
         2418  +**
         2419  +** ^(If the ninth parameter to sqlite4_create_function_v2() is not NULL,
         2420  +** then it is destructor for the application data pointer. 
         2421  +** The destructor is invoked when the function is deleted, either by being
         2422  +** overloaded or when the database connection closes.)^
         2423  +** ^The destructor is also invoked if the call to
         2424  +** sqlite4_create_function_v2() fails.
         2425  +** ^When the destructor callback of the tenth parameter is invoked, it
         2426  +** is passed a single argument which is a copy of the application data 
         2427  +** pointer which was the fifth parameter to sqlite4_create_function_v2().
         2428  +**
         2429  +** ^It is permitted to register multiple implementations of the same
         2430  +** functions with the same name but with either differing numbers of
         2431  +** arguments or differing preferred text encodings.  ^SQLite will use
         2432  +** the implementation that most closely matches the way in which the
         2433  +** SQL function is used.  ^A function implementation with a non-negative
         2434  +** nArg parameter is a better match than a function implementation with
         2435  +** a negative nArg.  ^A function where the preferred text encoding
         2436  +** matches the database encoding is a better
         2437  +** match than a function where the encoding is different.  
         2438  +** ^A function where the encoding difference is between UTF16le and UTF16be
         2439  +** is a closer match than a function where the encoding difference is
         2440  +** between UTF8 and UTF16.
         2441  +**
         2442  +** ^Built-in functions may be overloaded by new application-defined functions.
         2443  +**
         2444  +** ^An application-defined function is permitted to call other
         2445  +** SQLite interfaces.  However, such calls must not
         2446  +** close the database connection nor finalize or reset the prepared
         2447  +** statement in which the function is running.
         2448  +*/
         2449  +SQLITE4_API int sqlite4_create_function(
         2450  +  sqlite4 *db,
         2451  +  const char *zFunctionName,
         2452  +  int nArg,
         2453  +  int eTextRep,
         2454  +  void *pApp,
         2455  +  void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
         2456  +  void (*xStep)(sqlite4_context*,int,sqlite4_value**),
         2457  +  void (*xFinal)(sqlite4_context*)
         2458  +);
         2459  +SQLITE4_API int sqlite4_create_function16(
         2460  +  sqlite4 *db,
         2461  +  const void *zFunctionName,
         2462  +  int nArg,
         2463  +  int eTextRep,
         2464  +  void *pApp,
         2465  +  void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
         2466  +  void (*xStep)(sqlite4_context*,int,sqlite4_value**),
         2467  +  void (*xFinal)(sqlite4_context*)
         2468  +);
         2469  +SQLITE4_API int sqlite4_create_function_v2(
         2470  +  sqlite4 *db,
         2471  +  const char *zFunctionName,
         2472  +  int nArg,
         2473  +  int eTextRep,
         2474  +  void *pApp,
         2475  +  void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
         2476  +  void (*xStep)(sqlite4_context*,int,sqlite4_value**),
         2477  +  void (*xFinal)(sqlite4_context*),
         2478  +  void(*xDestroy)(void*)
         2479  +);
         2480  +
         2481  +/*
         2482  +** CAPIREF: Text Encodings
         2483  +**
         2484  +** These constant define integer codes that represent the various
         2485  +** text encodings supported by SQLite.
         2486  +*/
         2487  +#define SQLITE4_UTF8           1
         2488  +#define SQLITE4_UTF16LE        2
         2489  +#define SQLITE4_UTF16BE        3
         2490  +#define SQLITE4_UTF16          4    /* Use native byte order */
         2491  +#define SQLITE4_ANY            5    /* sqlite4_create_function only */
         2492  +#define SQLITE4_UTF16_ALIGNED  8    /* sqlite4_create_collation only */
         2493  +
         2494  +/*
         2495  +** CAPIREF: Deprecated Functions
         2496  +** DEPRECATED
         2497  +**
         2498  +** These functions are [deprecated].  In order to maintain
         2499  +** backwards compatibility with older code, these functions continue 
         2500  +** to be supported.  However, new applications should avoid
         2501  +** the use of these functions.  To help encourage people to avoid
         2502  +** using these functions, we are not going to tell you what they do.
         2503  +*/
         2504  +#ifndef SQLITE4_OMIT_DEPRECATED
         2505  +SQLITE4_API SQLITE4_DEPRECATED int sqlite4_aggregate_count(sqlite4_context*);
         2506  +SQLITE4_API SQLITE4_DEPRECATED int sqlite4_expired(sqlite4_stmt*);
         2507  +SQLITE4_API SQLITE4_DEPRECATED int sqlite4_transfer_bindings(sqlite4_stmt*, sqlite4_stmt*);
         2508  +SQLITE4_API SQLITE4_DEPRECATED int sqlite4_global_recover(void);
         2509  +#endif
         2510  +
         2511  +/*
         2512  +** CAPIREF: Obtaining SQL Function Parameter Values
         2513  +**
         2514  +** The C-language implementation of SQL functions and aggregates uses
         2515  +** this set of interface routines to access the parameter values on
         2516  +** the function or aggregate.
         2517  +**
         2518  +** The xFunc (for scalar functions) or xStep (for aggregates) parameters
         2519  +** to [sqlite4_create_function()] and [sqlite4_create_function16()]
         2520  +** define callbacks that implement the SQL functions and aggregates.
         2521  +** The 3rd parameter to these callbacks is an array of pointers to
         2522  +** [protected sqlite4_value] objects.  There is one [sqlite4_value] object for
         2523  +** each parameter to the SQL function.  These routines are used to
         2524  +** extract values from the [sqlite4_value] objects.
         2525  +**
         2526  +** These routines work only with [protected sqlite4_value] objects.
         2527  +** Any attempt to use these routines on an [unprotected sqlite4_value]
         2528  +** object results in undefined behavior.
         2529  +**
         2530  +** ^These routines work just like the corresponding [column access functions]
         2531  +** except that  these routines take a single [protected sqlite4_value] object
         2532  +** pointer instead of a [sqlite4_stmt*] pointer and an integer column number.
         2533  +**
         2534  +** ^The sqlite4_value_text16() interface extracts a UTF-16 string
         2535  +** in the native byte-order of the host machine.  ^The
         2536  +** sqlite4_value_text16be() and sqlite4_value_text16le() interfaces
         2537  +** extract UTF-16 strings as big-endian and little-endian respectively.
         2538  +**
         2539  +** ^(The sqlite4_value_numeric_type() interface attempts to apply
         2540  +** numeric affinity to the value.  This means that an attempt is
         2541  +** made to convert the value to an integer or floating point.  If
         2542  +** such a conversion is possible without loss of information (in other
         2543  +** words, if the value is a string that looks like a number)
         2544  +** then the conversion is performed.  Otherwise no conversion occurs.
         2545  +** The [SQLITE4_INTEGER | datatype] after conversion is returned.)^
         2546  +**
         2547  +** Please pay particular attention to the fact that the pointer returned
         2548  +** from [sqlite4_value_blob()], [sqlite4_value_text()], or
         2549  +** [sqlite4_value_text16()] can be invalidated by a subsequent call to
         2550  +** [sqlite4_value_bytes()], [sqlite4_value_bytes16()], [sqlite4_value_text()],
         2551  +** or [sqlite4_value_text16()].
         2552  +**
         2553  +** These routines must be called from the same thread as
         2554  +** the SQL function that supplied the [sqlite4_value*] parameters.
         2555  +*/
         2556  +SQLITE4_API const void *sqlite4_value_blob(sqlite4_value*);
         2557  +SQLITE4_API int sqlite4_value_bytes(sqlite4_value*);
         2558  +SQLITE4_API int sqlite4_value_bytes16(sqlite4_value*);
         2559  +SQLITE4_API double sqlite4_value_double(sqlite4_value*);
         2560  +SQLITE4_API int sqlite4_value_int(sqlite4_value*);
         2561  +SQLITE4_API sqlite4_int64 sqlite4_value_int64(sqlite4_value*);
         2562  +SQLITE4_API const unsigned char *sqlite4_value_text(sqlite4_value*);
         2563  +SQLITE4_API const void *sqlite4_value_text16(sqlite4_value*);
         2564  +SQLITE4_API const void *sqlite4_value_text16le(sqlite4_value*);
         2565  +SQLITE4_API const void *sqlite4_value_text16be(sqlite4_value*);
         2566  +SQLITE4_API int sqlite4_value_type(sqlite4_value*);
         2567  +SQLITE4_API int sqlite4_value_numeric_type(sqlite4_value*);
         2568  +
         2569  +/*
         2570  +** CAPIREF: Obtain Aggregate Function Context
         2571  +**
         2572  +** Implementations of aggregate SQL functions use this
         2573  +** routine to allocate memory for storing their state.
         2574  +**
         2575  +** ^The first time the sqlite4_aggregate_context(C,N) routine is called 
         2576  +** for a particular aggregate function, SQLite
         2577  +** allocates N of memory, zeroes out that memory, and returns a pointer
         2578  +** to the new memory. ^On second and subsequent calls to
         2579  +** sqlite4_aggregate_context() for the same aggregate function instance,
         2580  +** the same buffer is returned.  Sqlite3_aggregate_context() is normally
         2581  +** called once for each invocation of the xStep callback and then one
         2582  +** last time when the xFinal callback is invoked.  ^(When no rows match
         2583  +** an aggregate query, the xStep() callback of the aggregate function
         2584  +** implementation is never called and xFinal() is called exactly once.
         2585  +** In those cases, sqlite4_aggregate_context() might be called for the
         2586  +** first time from within xFinal().)^
         2587  +**
         2588  +** ^The sqlite4_aggregate_context(C,N) routine returns a NULL pointer if N is
         2589  +** less than or equal to zero or if a memory allocate error occurs.
         2590  +**
         2591  +** ^(The amount of space allocated by sqlite4_aggregate_context(C,N) is
         2592  +** determined by the N parameter on first successful call.  Changing the
         2593  +** value of N in subsequent call to sqlite4_aggregate_context() within
         2594  +** the same aggregate function instance will not resize the memory
         2595  +** allocation.)^
         2596  +**
         2597  +** ^SQLite automatically frees the memory allocated by 
         2598  +** sqlite4_aggregate_context() when the aggregate query concludes.
         2599  +**
         2600  +** The first parameter must be a copy of the
         2601  +** [sqlite4_context | SQL function context] that is the first parameter
         2602  +** to the xStep or xFinal callback routine that implements the aggregate
         2603  +** function.
         2604  +**
         2605  +** This routine must be called from the same thread in which
         2606  +** the aggregate SQL function is running.
         2607  +*/
         2608  +SQLITE4_API void *sqlite4_aggregate_context(sqlite4_context*, int nBytes);
         2609  +
         2610  +/*
         2611  +** CAPIREF: User Data For Functions
         2612  +**
         2613  +** ^The sqlite4_user_data() interface returns a copy of
         2614  +** the pointer that was the pUserData parameter (the 5th parameter)
         2615  +** of the [sqlite4_create_function()]
         2616  +** and [sqlite4_create_function16()] routines that originally
         2617  +** registered the application defined function.
         2618  +**
         2619  +** This routine must be called from the same thread in which
         2620  +** the application-defined function is running.
         2621  +*/
         2622  +SQLITE4_API void *sqlite4_user_data(sqlite4_context*);
         2623  +
         2624  +/*
         2625  +** CAPIREF: Database Connection For Functions
         2626  +**
         2627  +** ^The sqlite4_context_db_handle() interface returns a copy of
         2628  +** the pointer to the [database connection] (the 1st parameter)
         2629  +** of the [sqlite4_create_function()]
         2630  +** and [sqlite4_create_function16()] routines that originally
         2631  +** registered the application defined function.
         2632  +*/
         2633  +SQLITE4_API sqlite4 *sqlite4_context_db_handle(sqlite4_context*);
         2634  +SQLITE4_API sqlite4_env *sqlite4_context_env(sqlite4_context*);
         2635  +
         2636  +/*
         2637  +** CAPIREF: Function Auxiliary Data
         2638  +**
         2639  +** The following two functions may be used by scalar SQL functions to
         2640  +** associate metadata with argument values. If the same value is passed to
         2641  +** multiple invocations of the same SQL function during query execution, under
         2642  +** some circumstances the associated metadata may be preserved. This may
         2643  +** be used, for example, to add a regular-expression matching scalar
         2644  +** function. The compiled version of the regular expression is stored as
         2645  +** metadata associated with the SQL value passed as the regular expression
         2646  +** pattern.  The compiled regular expression can be reused on multiple
         2647  +** invocations of the same function so that the original pattern string
         2648  +** does not need to be recompiled on each invocation.
         2649  +**
         2650  +** ^The sqlite4_get_auxdata() interface returns a pointer to the metadata
         2651  +** associated by the sqlite4_set_auxdata() function with the Nth argument
         2652  +** value to the application-defined function. ^If no metadata has been ever
         2653  +** been set for the Nth argument of the function, or if the corresponding
         2654  +** function parameter has changed since the meta-data was set,
         2655  +** then sqlite4_get_auxdata() returns a NULL pointer.
         2656  +**
         2657  +** ^The sqlite4_set_auxdata() interface saves the metadata
         2658  +** pointed to by its 3rd parameter as the metadata for the N-th
         2659  +** argument of the application-defined function.  Subsequent
         2660  +** calls to sqlite4_get_auxdata() might return this data, if it has
         2661  +** not been destroyed.
         2662  +** ^If it is not NULL, SQLite will invoke the destructor
         2663  +** function given by the 4th parameter to sqlite4_set_auxdata() on
         2664  +** the metadata when the corresponding function parameter changes
         2665  +** or when the SQL statement completes, whichever comes first.
         2666  +**
         2667  +** SQLite is free to call the destructor and drop metadata on any
         2668  +** parameter of any function at any time.  ^The only guarantee is that
         2669  +** the destructor will be called before the metadata is dropped.
         2670  +**
         2671  +** ^(In practice, metadata is preserved between function calls for
         2672  +** expressions that are constant at compile time. This includes literal
         2673  +** values and [parameters].)^
         2674  +**
         2675  +** These routines must be called from the same thread in which
         2676  +** the SQL function is running.
         2677  +*/
         2678  +SQLITE4_API void *sqlite4_get_auxdata(sqlite4_context*, int N);
         2679  +SQLITE4_API void sqlite4_set_auxdata(sqlite4_context*, int N, void*, void (*)(void*));
         2680  +
         2681  +
         2682  +/*
         2683  +** CAPIREF: Constants Defining Special Destructor Behavior
         2684  +**
         2685  +** These are special values for the destructor that is passed in as the
         2686  +** final argument to routines like [sqlite4_result_blob()].  ^If the destructor
         2687  +** argument is SQLITE4_STATIC, it means that the content pointer is constant
         2688  +** and will never change.  It does not need to be destroyed.  ^The
         2689  +** SQLITE4_TRANSIENT value means that the content will likely change in
         2690  +** the near future and that SQLite should make its own private copy of
         2691  +** the content before returning.
         2692  +**
         2693  +** The typedef is necessary to work around problems in certain
         2694  +** C++ compilers.  See ticket #2191.
         2695  +*/
         2696  +typedef void (*sqlite4_destructor_type)(void*);
         2697  +SQLITE4_API void sqlite4_dynamic(void*);
         2698  +#define SQLITE4_STATIC      ((sqlite4_destructor_type)0)
         2699  +#define SQLITE4_TRANSIENT   ((sqlite4_destructor_type)-1)
         2700  +#define SQLITE4_DYNAMIC     (sqlite4_dynamic)
         2701  +
         2702  +
         2703  +/*
         2704  +** CAPIREF: Setting The Result Of An SQL Function
         2705  +**
         2706  +** These routines are used by the xFunc or xFinal callbacks that
         2707  +** implement SQL functions and aggregates.  See
         2708  +** [sqlite4_create_function()] and [sqlite4_create_function16()]
         2709  +** for additional information.
         2710  +**
         2711  +** These functions work very much like the [parameter binding] family of
         2712  +** functions used to bind values to host parameters in prepared statements.
         2713  +** Refer to the [SQL parameter] documentation for additional information.
         2714  +**
         2715  +** ^The sqlite4_result_blob() interface sets the result from
         2716  +** an application-defined function to be the BLOB whose content is pointed
         2717  +** to by the second parameter and which is N bytes long where N is the
         2718  +** third parameter.
         2719  +**
         2720  +** ^The sqlite4_result_zeroblob() interfaces set the result of
         2721  +** the application-defined function to be a BLOB containing all zero
         2722  +** bytes and N bytes in size, where N is the value of the 2nd parameter.
         2723  +**
         2724  +** ^The sqlite4_result_double() interface sets the result from
         2725  +** an application-defined function to be a floating point value specified
         2726  +** by its 2nd argument.
         2727  +**
         2728  +** ^The sqlite4_result_error() and sqlite4_result_error16() functions
         2729  +** cause the implemented SQL function to throw an exception.
         2730  +** ^SQLite uses the string pointed to by the
         2731  +** 2nd parameter of sqlite4_result_error() or sqlite4_result_error16()
         2732  +** as the text of an error message.  ^SQLite interprets the error
         2733  +** message string from sqlite4_result_error() as UTF-8. ^SQLite
         2734  +** interprets the string from sqlite4_result_error16() as UTF-16 in native
         2735  +** byte order.  ^If the third parameter to sqlite4_result_error()
         2736  +** or sqlite4_result_error16() is negative then SQLite takes as the error
         2737  +** message all text up through the first zero character.
         2738  +** ^If the third parameter to sqlite4_result_error() or
         2739  +** sqlite4_result_error16() is non-negative then SQLite takes that many
         2740  +** bytes (not characters) from the 2nd parameter as the error message.
         2741  +** ^The sqlite4_result_error() and sqlite4_result_error16()
         2742  +** routines make a private copy of the error message text before
         2743  +** they return.  Hence, the calling function can deallocate or
         2744  +** modify the text after they return without harm.
         2745  +** ^The sqlite4_result_error_code() function changes the error code
         2746  +** returned by SQLite as a result of an error in a function.  ^By default,
         2747  +** the error code is SQLITE4_ERROR.  ^A subsequent call to sqlite4_result_error()
         2748  +** or sqlite4_result_error16() resets the error code to SQLITE4_ERROR.
         2749  +**
         2750  +** ^The sqlite4_result_toobig() interface causes SQLite to throw an error
         2751  +** indicating that a string or BLOB is too long to represent.
         2752  +**
         2753  +** ^The sqlite4_result_nomem() interface causes SQLite to throw an error
         2754  +** indicating that a memory allocation failed.
         2755  +**
         2756  +** ^The sqlite4_result_int() interface sets the return value
         2757  +** of the application-defined function to be the 32-bit signed integer
         2758  +** value given in the 2nd argument.
         2759  +** ^The sqlite4_result_int64() interface sets the return value
         2760  +** of the application-defined function to be the 64-bit signed integer
         2761  +** value given in the 2nd argument.
         2762  +**
         2763  +** ^The sqlite4_result_null() interface sets the return value
         2764  +** of the application-defined function to be NULL.
         2765  +**
         2766  +** ^The sqlite4_result_text(), sqlite4_result_text16(),
         2767  +** sqlite4_result_text16le(), and sqlite4_result_text16be() interfaces
         2768  +** set the return value of the application-defined function to be
         2769  +** a text string which is represented as UTF-8, UTF-16 native byte order,
         2770  +** UTF-16 little endian, or UTF-16 big endian, respectively.
         2771  +** ^SQLite takes the text result from the application from
         2772  +** the 2nd parameter of the sqlite4_result_text* interfaces.
         2773  +** ^If the 3rd parameter to the sqlite4_result_text* interfaces
         2774  +** is negative, then SQLite takes result text from the 2nd parameter
         2775  +** through the first zero character.
         2776  +** ^If the 3rd parameter to the sqlite4_result_text* interfaces
         2777  +** is non-negative, then as many bytes (not characters) of the text
         2778  +** pointed to by the 2nd parameter are taken as the application-defined
         2779  +** function result.  If the 3rd parameter is non-negative, then it
         2780  +** must be the byte offset into the string where the NUL terminator would
         2781  +** appear if the string where NUL terminated.  If any NUL characters occur
         2782  +** in the string at a byte offset that is less than the value of the 3rd
         2783  +** parameter, then the resulting string will contain embedded NULs and the
         2784  +** result of expressions operating on strings with embedded NULs is undefined.
         2785  +** ^If the 4th parameter to the sqlite4_result_text* interfaces
         2786  +** or sqlite4_result_blob is a non-NULL pointer, then SQLite calls that
         2787  +** function as the destructor on the text or BLOB result when it has
         2788  +** finished using that result.
         2789  +** ^If the 4th parameter to the sqlite4_result_text* interfaces or to
         2790  +** sqlite4_result_blob is the special constant SQLITE4_STATIC, then SQLite
         2791  +** assumes that the text or BLOB result is in constant space and does not
         2792  +** copy the content of the parameter nor call a destructor on the content
         2793  +** when it has finished using that result.
         2794  +** ^If the 4th parameter to the sqlite4_result_text* interfaces
         2795  +** or sqlite4_result_blob is the special constant SQLITE4_TRANSIENT
         2796  +** then SQLite makes a copy of the result into space obtained from
         2797  +** from [sqlite4_malloc()] before it returns.
         2798  +**
         2799  +** ^The sqlite4_result_value() interface sets the result of
         2800  +** the application-defined function to be a copy the
         2801  +** [unprotected sqlite4_value] object specified by the 2nd parameter.  ^The
         2802  +** sqlite4_result_value() interface makes a copy of the [sqlite4_value]
         2803  +** so that the [sqlite4_value] specified in the parameter may change or
         2804  +** be deallocated after sqlite4_result_value() returns without harm.
         2805  +** ^A [protected sqlite4_value] object may always be used where an
         2806  +** [unprotected sqlite4_value] object is required, so either
         2807  +** kind of [sqlite4_value] object can be used with this interface.
         2808  +**
         2809  +** If these routines are called from within the different thread
         2810  +** than the one containing the application-defined function that received
         2811  +** the [sqlite4_context] pointer, the results are undefined.
         2812  +*/
         2813  +SQLITE4_API void sqlite4_result_blob(sqlite4_context*, const void*, int, void(*)(void*));
         2814  +SQLITE4_API void sqlite4_result_double(sqlite4_context*, double);
         2815  +SQLITE4_API void sqlite4_result_error(sqlite4_context*, const char*, int);
         2816  +SQLITE4_API void sqlite4_result_error16(sqlite4_context*, const void*, int);
         2817  +SQLITE4_API void sqlite4_result_error_toobig(sqlite4_context*);
         2818  +SQLITE4_API void sqlite4_result_error_nomem(sqlite4_context*);
         2819  +SQLITE4_API void sqlite4_result_error_code(sqlite4_context*, int);
         2820  +SQLITE4_API void sqlite4_result_int(sqlite4_context*, int);
         2821  +SQLITE4_API void sqlite4_result_int64(sqlite4_context*, sqlite4_int64);
         2822  +SQLITE4_API void sqlite4_result_null(sqlite4_context*);
         2823  +SQLITE4_API void sqlite4_result_text(sqlite4_context*, const char*, int, void(*)(void*));
         2824  +SQLITE4_API void sqlite4_result_text16(sqlite4_context*, const void*, int, void(*)(void*));
         2825  +SQLITE4_API void sqlite4_result_text16le(sqlite4_context*, const void*, int,void(*)(void*));
         2826  +SQLITE4_API void sqlite4_result_text16be(sqlite4_context*, const void*, int,void(*)(void*));
         2827  +SQLITE4_API void sqlite4_result_value(sqlite4_context*, sqlite4_value*);
         2828  +SQLITE4_API void sqlite4_result_zeroblob(sqlite4_context*, int n);
         2829  +
         2830  +/*
         2831  +** CAPIREF: Define New Collating Sequences
         2832  +**
         2833  +** ^This function adds, removes, or modifies a [collation] associated
         2834  +** with the [database connection] specified as the first argument.
         2835  +**
         2836  +** ^The name of the collation is a UTF-8 string.
         2837  +** ^Collation names that compare equal according to [sqlite4_strnicmp()] are
         2838  +** considered to be the same name.
         2839  +**
         2840  +** ^(The third argument (eTextRep) must be one of the constants:
         2841  +** <ul>
         2842  +** <li> [SQLITE4_UTF8],
         2843  +** <li> [SQLITE4_UTF16LE],
         2844  +** <li> [SQLITE4_UTF16BE],
         2845  +** <li> [SQLITE4_UTF16], or
         2846  +** <li> [SQLITE4_UTF16_ALIGNED].
         2847  +** </ul>)^
         2848  +** ^The eTextRep argument determines the encoding of strings passed
         2849  +** to the collating function callback, xCallback.
         2850  +** ^The [SQLITE4_UTF16] and [SQLITE4_UTF16_ALIGNED] values for eTextRep
         2851  +** force strings to be UTF16 with native byte order.
         2852  +** ^The [SQLITE4_UTF16_ALIGNED] value for eTextRep forces strings to begin
         2853  +** on an even byte address.
         2854  +**
         2855  +** ^The fourth argument, pArg, is an application data pointer that is passed
         2856  +** through as the first argument to the collating function callback.
         2857  +**
         2858  +** ^The fifth argument, xCallback, is a pointer to the comparision function.
         2859  +** ^The sixth argument, xMakeKey, is a pointer to a function that generates
         2860  +** a sort key.
         2861  +** ^Multiple functions can be registered using the same name but
         2862  +** with different eTextRep parameters and SQLite will use whichever
         2863  +** function requires the least amount of data transformation.
         2864  +** ^If the xCallback argument is NULL then the collating function is
         2865  +** deleted.  ^When all collating functions having the same name are deleted,
         2866  +** that collation is no longer usable.
         2867  +**
         2868  +** ^The collating function callback is invoked with a copy of the pArg 
         2869  +** application data pointer and with two strings in the encoding specified
         2870  +** by the eTextRep argument.  The collating function must return an
         2871  +** integer that is negative, zero, or positive
         2872  +** if the first string is less than, equal to, or greater than the second,
         2873  +** respectively.  A collating function must always return the same answer
         2874  +** given the same inputs.  If two or more collating functions are registered
         2875  +** to the same collation name (using different eTextRep values) then all
         2876  +** must give an equivalent answer when invoked with equivalent strings.
         2877  +** The collating function must obey the following properties for all
         2878  +** strings A, B, and C:
         2879  +**
         2880  +** <ol>
         2881  +** <li> If A==B then B==A.
         2882  +** <li> If A==B and B==C then A==C.
         2883  +** <li> If A&lt;B THEN B&gt;A.
         2884  +** <li> If A&lt;B and B&lt;C then A&lt;C.
         2885  +** </ol>
         2886  +**
         2887  +** If a collating function fails any of the above constraints and that
         2888  +** collating function is  registered and used, then the behavior of SQLite
         2889  +** is undefined.
         2890  +**
         2891  +** ^Collating functions are deleted when they are overridden by later
         2892  +** calls to the collation creation functions or when the
         2893  +** [database connection] is closed using [sqlite4_close()].
         2894  +**
         2895  +** ^The xDestroy callback is <u>not</u> called if the 
         2896  +** sqlite4_create_collation() function fails.  Applications that invoke
         2897  +** sqlite4_create_collation() with a non-NULL xDestroy argument should 
         2898  +** check the return code and dispose of the application data pointer
         2899  +** themselves rather than expecting SQLite to deal with it for them.
         2900  +** This is different from every other SQLite interface.  The inconsistency 
         2901  +** is unfortunate but cannot be changed without breaking backwards 
         2902  +** compatibility.
         2903  +**
         2904  +** See also:  [sqlite4_collation_needed()] and [sqlite4_collation_needed16()].
         2905  +*/
         2906  +SQLITE4_API int sqlite4_create_collation(
         2907  +  sqlite4*, 
         2908  +  const char *zName, 
         2909  +  int eTextRep, 
         2910  +  void *pArg,
         2911  +  int(*xCompare)(void*,int,const void*,int,const void*),
         2912  +  int(*xMakeKey)(void*,int,const void*,int,void*),
         2913  +  void(*xDestroy)(void*)
         2914  +);
         2915  +
         2916  +/*
         2917  +** CAPIREF: Collation Needed Callbacks
         2918  +**
         2919  +** ^To avoid having to register all collation sequences before a database
         2920  +** can be used, a single callback function may be registered with the
         2921  +** [database connection] to be invoked whenever an undefined collation
         2922  +** sequence is required.
         2923  +**
         2924  +** ^If the function is registered using the sqlite4_collation_needed() API,
         2925  +** then it is passed the names of undefined collation sequences as strings
         2926  +** encoded in UTF-8. ^If sqlite4_collation_needed16() is used,
         2927  +** the names are passed as UTF-16 in machine native byte order.
         2928  +** ^A call to either function replaces the existing collation-needed callback.
         2929  +**
         2930  +** ^(When the callback is invoked, the first argument passed is a copy
         2931  +** of the second argument to sqlite4_collation_needed() or
         2932  +** sqlite4_collation_needed16().  The second argument is the database
         2933  +** connection.  The third argument is one of [SQLITE4_UTF8], [SQLITE4_UTF16BE],
         2934  +** or [SQLITE4_UTF16LE], indicating the most desirable form of the collation
         2935  +** sequence function required.  The fourth parameter is the name of the
         2936  +** required collation sequence.)^
         2937  +**
         2938  +** The callback function should register the desired collation using
         2939  +** [sqlite4_create_collation()], [sqlite4_create_collation16()], or
         2940  +** [sqlite4_create_collation_v2()].
         2941  +*/
         2942  +SQLITE4_API int sqlite4_collation_needed(
         2943  +  sqlite4*, 
         2944  +  void*, 
         2945  +  void(*)(void*,sqlite4*,int eTextRep,const char*)
         2946  +);
         2947  +SQLITE4_API int sqlite4_collation_needed16(
         2948  +  sqlite4*, 
         2949  +  void*,
         2950  +  void(*)(void*,sqlite4*,int eTextRep,const void*)
         2951  +);
         2952  +
         2953  +/*
         2954  +** CAPIREF: Suspend Execution For A Short Time
         2955  +**
         2956  +** The sqlite4_sleep() function causes the current thread to suspend execution
         2957  +** for at least a number of milliseconds specified in its parameter.
         2958  +**
         2959  +** If the operating system does not support sleep requests with
         2960  +** millisecond time resolution, then the time will be rounded up to
         2961  +** the nearest second. The number of milliseconds of sleep actually
         2962  +** requested from the operating system is returned.
         2963  +**
         2964  +** ^SQLite implements this interface by calling the xSleep()
         2965  +** method of the default [sqlite4_vfs] object.  If the xSleep() method
         2966  +** of the default VFS is not implemented correctly, or not implemented at
         2967  +** all, then the behavior of sqlite4_sleep() may deviate from the description
         2968  +** in the previous paragraphs.
         2969  +*/
         2970  +SQLITE4_API int sqlite4_sleep(int);
         2971  +
         2972  +/*
         2973  +** CAPIREF: Test For Auto-Commit Mode
         2974  +** KEYWORDS: {autocommit mode}
         2975  +**
         2976  +** ^The sqlite4_get_autocommit() interface returns non-zero or
         2977  +** zero if the given database connection is or is not in autocommit mode,
         2978  +** respectively.  ^Autocommit mode is on by default.
         2979  +** ^Autocommit mode is disabled by a [BEGIN] statement.
         2980  +** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
         2981  +**
         2982  +** If certain kinds of errors occur on a statement within a multi-statement
         2983  +** transaction (errors including [SQLITE4_FULL], [SQLITE4_IOERR],
         2984  +** [SQLITE4_NOMEM], [SQLITE4_BUSY], and [SQLITE4_INTERRUPT]) then the
         2985  +** transaction might be rolled back automatically.  The only way to
         2986  +** find out whether SQLite automatically rolled back the transaction after
         2987  +** an error is to use this function.
         2988  +**
         2989  +** If another thread changes the autocommit status of the database
         2990  +** connection while this routine is running, then the return value
         2991  +** is undefined.
         2992  +*/
         2993  +SQLITE4_API int sqlite4_get_autocommit(sqlite4*);
         2994  +
         2995  +/*
         2996  +** CAPIREF: Find The Database Handle Of A Prepared Statement
         2997  +**
         2998  +** ^The sqlite4_db_handle interface returns the [database connection] handle
         2999  +** to which a [prepared statement] belongs.  ^The [database connection]
         3000  +** returned by sqlite4_db_handle is the same [database connection]
         3001  +** that was the first argument
         3002  +** to the [sqlite4_prepare()] call (or its variants) that was used to
         3003  +** create the statement in the first place.
         3004  +*/
         3005  +SQLITE4_API sqlite4 *sqlite4_db_handle(sqlite4_stmt*);
         3006  +
         3007  +/*
         3008  +** CAPIREF: Return The Filename For A Database Connection
         3009  +**
         3010  +** ^The sqlite4_db_filename(D,N) interface returns a pointer to a filename
         3011  +** associated with database N of connection D.  ^The main database file
         3012  +** has the name "main".  If there is no attached database N on the database
         3013  +** connection D, or if database N is a temporary or in-memory database, then
         3014  +** a NULL pointer is returned.
         3015  +**
         3016  +** ^The filename returned by this function is the output of the
         3017  +** xFullPathname method of the [VFS].  ^In other words, the filename
         3018  +** will be an absolute pathname, even if the filename used
         3019  +** to open the database originally was a URI or relative pathname.
         3020  +*/
         3021  +SQLITE4_API const char *sqlite4_db_filename(sqlite4 *db, const char *zDbName);
         3022  +
         3023  +/*
         3024  +** CAPIREF: Find the next prepared statement
         3025  +**
         3026  +** ^This interface returns a pointer to the next [prepared statement] after
         3027  +** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
         3028  +** then this interface returns a pointer to the first prepared statement
         3029  +** associated with the database connection pDb.  ^If no prepared statement
         3030  +** satisfies the conditions of this routine, it returns NULL.
         3031  +**
         3032  +** The [database connection] pointer D in a call to
         3033  +** [sqlite4_next_stmt(D,S)] must refer to an open database
         3034  +** connection and in particular must not be a NULL pointer.
         3035  +*/
         3036  +SQLITE4_API sqlite4_stmt *sqlite4_next_stmt(sqlite4 *pDb, sqlite4_stmt *pStmt);
         3037  +
         3038  +/*
         3039  +** CAPIREF: Free Memory Used By A Database Connection
         3040  +**
         3041  +** ^The sqlite4_db_release_memory(D) interface attempts to free as much heap
         3042  +** memory as possible from database connection D.
         3043  +*/
         3044  +SQLITE4_API int sqlite4_db_release_memory(sqlite4*);
         3045  +
         3046  +/*
         3047  +** CAPIREF: Extract Metadata About A Column Of A Table
         3048  +**
         3049  +** ^This routine returns metadata about a specific column of a specific
         3050  +** database table accessible using the [database connection] handle
         3051  +** passed as the first function argument.
         3052  +**
         3053  +** ^The column is identified by the second, third and fourth parameters to
         3054  +** this function. ^The second parameter is either the name of the database
         3055  +** (i.e. "main", "temp", or an attached database) containing the specified
         3056  +** table or NULL. ^If it is NULL, then all attached databases are searched
         3057  +** for the table using the same algorithm used by the database engine to
         3058  +** resolve unqualified table references.
         3059  +**
         3060  +** ^The third and fourth parameters to this function are the table and column
         3061  +** name of the desired column, respectively. Neither of these parameters
         3062  +** may be NULL.
         3063  +**
         3064  +** ^Metadata is returned by writing to the memory locations passed as the 5th
         3065  +** and subsequent parameters to this function. ^Any of these arguments may be
         3066  +** NULL, in which case the corresponding element of metadata is omitted.
         3067  +**
         3068  +** ^(<blockquote>
         3069  +** <table border="1">
         3070  +** <tr><th> Parameter <th> Output<br>Type <th>  Description
         3071  +**
         3072  +** <tr><td> 5th <td> const char* <td> Data type
         3073  +** <tr><td> 6th <td> const char* <td> Name of default collation sequence
         3074  +** <tr><td> 7th <td> int         <td> True if column has a NOT NULL constraint
         3075  +** <tr><td> 8th <td> int         <td> True if column is part of the PRIMARY KEY
         3076  +** <tr><td> 9th <td> int         <td> True if column is [AUTOINCREMENT]
         3077  +** </table>
         3078  +** </blockquote>)^
         3079  +**
         3080  +** ^The memory pointed to by the character pointers returned for the
         3081  +** declaration type and collation sequence is valid only until the next
         3082  +** call to any SQLite API function.
         3083  +**
         3084  +** ^If the specified table is actually a view, an [error code] is returned.
         3085  +**
         3086  +** ^If the specified column is "rowid", "oid" or "_rowid_" and an
         3087  +** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
         3088  +** parameters are set for the explicitly declared column. ^(If there is no
         3089  +** explicitly declared [INTEGER PRIMARY KEY] column, then the output
         3090  +** parameters are set as follows:
         3091  +**
         3092  +** <pre>
         3093  +**     data type: "INTEGER"
         3094  +**     collation sequence: "BINARY"
         3095  +**     not null: 0
         3096  +**     primary key: 1
         3097  +**     auto increment: 0
         3098  +** </pre>)^
         3099  +**
         3100  +** ^(This function may load one or more schemas from database files. If an
         3101  +** error occurs during this process, or if the requested table or column
         3102  +** cannot be found, an [error code] is returned and an error message left
         3103  +** in the [database connection] (to be retrieved using sqlite4_errmsg()).)^
         3104  +**
         3105  +** ^This API is only available if the library was compiled with the
         3106  +** [SQLITE4_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
         3107  +*/
         3108  +SQLITE4_API int sqlite4_table_column_metadata(
         3109  +  sqlite4 *db,                /* Connection handle */
         3110  +  const char *zDbName,        /* Database name or NULL */
         3111  +  const char *zTableName,     /* Table name */
         3112  +  const char *zColumnName,    /* Column name */
         3113  +  char const **pzDataType,    /* OUTPUT: Declared data type */
         3114  +  char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
         3115  +  int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
         3116  +  int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
         3117  +  int *pAutoinc               /* OUTPUT: True if column is auto-increment */
         3118  +);
         3119  +
         3120  +/*
         3121  +** CAPIREF: Load An Extension
         3122  +**
         3123  +** ^This interface loads an SQLite extension library from the named file.
         3124  +**
         3125  +** ^The sqlite4_load_extension() interface attempts to load an
         3126  +** SQLite extension library contained in the file zFile.
         3127  +**
         3128  +** ^The entry point is zProc.
         3129  +** ^zProc may be 0, in which case the name of the entry point
         3130  +** defaults to "sqlite4_extension_init".
         3131  +** ^The sqlite4_load_extension() interface returns
         3132  +** [SQLITE4_OK] on success and [SQLITE4_ERROR] if something goes wrong.
         3133  +** ^If an error occurs and pzErrMsg is not 0, then the
         3134  +** [sqlite4_load_extension()] interface shall attempt to
         3135  +** fill *pzErrMsg with error message text stored in memory
         3136  +** obtained from [sqlite4_malloc()]. The calling function
         3137  +** should free this memory by calling [sqlite4_free()].
         3138  +**
         3139  +** ^Extension loading must be enabled using
         3140  +** [sqlite4_enable_load_extension()] prior to calling this API,
         3141  +** otherwise an error will be returned.
         3142  +**
         3143  +** See also the [load_extension() SQL function].
         3144  +*/
         3145  +SQLITE4_API int sqlite4_load_extension(
         3146  +  sqlite4 *db,          /* Load the extension into this database connection */
         3147  +  const char *zFile,    /* Name of the shared library containing extension */
         3148  +  const char *zProc,    /* Entry point.  Derived from zFile if 0 */
         3149  +  char **pzErrMsg       /* Put error message here if not 0 */
         3150  +);
         3151  +
         3152  +/*
         3153  +** CAPIREF: Enable Or Disable Extension Loading
         3154  +**
         3155  +** ^So as not to open security holes in older applications that are
         3156  +** unprepared to deal with extension loading, and as a means of disabling
         3157  +** extension loading while evaluating user-entered SQL, the following API
         3158  +** is provided to turn the [sqlite4_load_extension()] mechanism on and off.
         3159  +**
         3160  +** ^Extension loading is off by default. See ticket #1863.
         3161  +** ^Call the sqlite4_enable_load_extension() routine with onoff==1
         3162  +** to turn extension loading on and call it with onoff==0 to turn
         3163  +** it back off again.
         3164  +*/
         3165  +SQLITE4_API int sqlite4_enable_load_extension(sqlite4 *db, int onoff);
         3166  +
         3167  +/*
         3168  +** The interface to the virtual-table mechanism is currently considered
         3169  +** to be experimental.  The interface might change in incompatible ways.
         3170  +** If this is a problem for you, do not use the interface at this time.
         3171  +**
         3172  +** When the virtual-table mechanism stabilizes, we will declare the
         3173  +** interface fixed, support it indefinitely, and remove this comment.
         3174  +*/
         3175  +
         3176  +/*
         3177  +** Structures used by the virtual table interface
         3178  +*/
         3179  +typedef struct sqlite4_vtab sqlite4_vtab;
         3180  +typedef struct sqlite4_index_info sqlite4_index_info;
         3181  +typedef struct sqlite4_vtab_cursor sqlite4_vtab_cursor;
         3182  +typedef struct sqlite4_module sqlite4_module;
         3183  +
         3184  +/*
         3185  +** CAPIREF: Virtual Table Object
         3186  +** KEYWORDS: sqlite4_module {virtual table module}
         3187  +**
         3188  +** This structure, sometimes called a "virtual table module", 
         3189  +** defines the implementation of a [virtual tables].  
         3190  +** This structure consists mostly of methods for the module.
         3191  +**
         3192  +** ^A virtual table module is created by filling in a persistent
         3193  +** instance of this structure and passing a pointer to that instance
         3194  +** to [sqlite4_create_module()] or [sqlite4_create_module_v2()].
         3195  +** ^The registration remains valid until it is replaced by a different
         3196  +** module or until the [database connection] closes.  The content
         3197  +** of this structure must not change while it is registered with
         3198  +** any database connection.
         3199  +*/
         3200  +struct sqlite4_module {
         3201  +  int iVersion;
         3202  +  int (*xCreate)(sqlite4*, void *pAux,
         3203  +               int argc, const char *const*argv,
         3204  +               sqlite4_vtab **ppVTab, char**);
         3205  +  int (*xConnect)(sqlite4*, void *pAux,
         3206  +               int argc, const char *const*argv,
         3207  +               sqlite4_vtab **ppVTab, char**);
         3208  +  int (*xBestIndex)(sqlite4_vtab *pVTab, sqlite4_index_info*);
         3209  +  int (*xDisconnect)(sqlite4_vtab *pVTab);
         3210  +  int (*xDestroy)(sqlite4_vtab *pVTab);
         3211  +  int (*xOpen)(sqlite4_vtab *pVTab, sqlite4_vtab_cursor **ppCursor);
         3212  +  int (*xClose)(sqlite4_vtab_cursor*);
         3213  +  int (*xFilter)(sqlite4_vtab_cursor*, int idxNum, const char *idxStr,
         3214  +                int argc, sqlite4_value **argv);
         3215  +  int (*xNext)(sqlite4_vtab_cursor*);
         3216  +  int (*xEof)(sqlite4_vtab_cursor*);
         3217  +  int (*xColumn)(sqlite4_vtab_cursor*, sqlite4_context*, int);
         3218  +  int (*xRowid)(sqlite4_vtab_cursor*, sqlite4_int64 *pRowid);
         3219  +  int (*xUpdate)(sqlite4_vtab *, int, sqlite4_value **, sqlite4_int64 *);
         3220  +  int (*xBegin)(sqlite4_vtab *pVTab);
         3221  +  int (*xSync)(sqlite4_vtab *pVTab);
         3222  +  int (*xCommit)(sqlite4_vtab *pVTab);
         3223  +  int (*xRollback)(sqlite4_vtab *pVTab);
         3224  +  int (*xFindFunction)(sqlite4_vtab *pVtab, int nArg, const char *zName,
         3225  +                       void (**pxFunc)(sqlite4_context*,int,sqlite4_value**),
         3226  +                       void **ppArg);
         3227  +  int (*xRename)(sqlite4_vtab *pVtab, const char *zNew);
         3228  +  /* The methods above are in version 1 of the sqlite_module object. Those 
         3229  +  ** below are for version 2 and greater. */
         3230  +  int (*xSavepoint)(sqlite4_vtab *pVTab, int);
         3231  +  int (*xRelease)(sqlite4_vtab *pVTab, int);
         3232  +  int (*xRollbackTo)(sqlite4_vtab *pVTab, int);
         3233  +};
         3234  +
         3235  +/*
         3236  +** CAPIREF: Virtual Table Indexing Information
         3237  +** KEYWORDS: sqlite4_index_info
         3238  +**
         3239  +** The sqlite4_index_info structure and its substructures is used as part
         3240  +** of the [virtual table] interface to
         3241  +** pass information into and receive the reply from the [xBestIndex]
         3242  +** method of a [virtual table module].  The fields under **Inputs** are the
         3243  +** inputs to xBestIndex and are read-only.  xBestIndex inserts its
         3244  +** results into the **Outputs** fields.
         3245  +**
         3246  +** ^(The aConstraint[] array records WHERE clause constraints of the form:
         3247  +**
         3248  +** <blockquote>column OP expr</blockquote>
         3249  +**
         3250  +** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^  ^(The particular operator is
         3251  +** stored in aConstraint[].op using one of the
         3252  +** [SQLITE4_INDEX_CONSTRAINT_EQ | SQLITE4_INDEX_CONSTRAINT_ values].)^
         3253  +** ^(The index of the column is stored in
         3254  +** aConstraint[].iColumn.)^  ^(aConstraint[].usable is TRUE if the
         3255  +** expr on the right-hand side can be evaluated (and thus the constraint
         3256  +** is usable) and false if it cannot.)^
         3257  +**
         3258  +** ^The optimizer automatically inverts terms of the form "expr OP column"
         3259  +** and makes other simplifications to the WHERE clause in an attempt to
         3260  +** get as many WHERE clause terms into the form shown above as possible.
         3261  +** ^The aConstraint[] array only reports WHERE clause terms that are
         3262  +** relevant to the particular virtual table being queried.
         3263  +**
         3264  +** ^Information about the ORDER BY clause is stored in aOrderBy[].
         3265  +** ^Each term of aOrderBy records a column of the ORDER BY clause.
         3266  +**
         3267  +** The [xBestIndex] method must fill aConstraintUsage[] with information
         3268  +** about what parameters to pass to xFilter.  ^If argvIndex>0 then
         3269  +** the right-hand side of the corresponding aConstraint[] is evaluated
         3270  +** and becomes the argvIndex-th entry in argv.  ^(If aConstraintUsage[].omit
         3271  +** is true, then the constraint is assumed to be fully handled by the
         3272  +** virtual table and is not checked again by SQLite.)^
         3273  +**
         3274  +** ^The idxNum and idxPtr values are recorded and passed into the
         3275  +** [xFilter] method.
         3276  +** ^[sqlite4_free()] is used to free idxPtr if and only if
         3277  +** needToFreeIdxPtr is true.
         3278  +**
         3279  +** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
         3280  +** the correct order to satisfy the ORDER BY clause so that no separate
         3281  +** sorting step is required.
         3282  +**
         3283  +** ^The estimatedCost value is an estimate of the cost of doing the
         3284  +** particular lookup.  A full scan of a table with N entries should have
         3285  +** a cost of N.  A binary search of a table of N entries should have a
         3286  +** cost of approximately log(N).
         3287  +*/
         3288  +struct sqlite4_index_info {
         3289  +  /* Inputs */
         3290  +  int nConstraint;           /* Number of entries in aConstraint */
         3291  +  struct sqlite4_index_constraint {
         3292  +     int iColumn;              /* Column on left-hand side of constraint */
         3293  +     unsigned char op;         /* Constraint operator */
         3294  +     unsigned char usable;     /* True if this constraint is usable */
         3295  +     int iTermOffset;          /* Used internally - xBestIndex should ignore */
         3296  +  } *aConstraint;            /* Table of WHERE clause constraints */
         3297  +  int nOrderBy;              /* Number of terms in the ORDER BY clause */
         3298  +  struct sqlite4_index_orderby {
         3299  +     int iColumn;              /* Column number */
         3300  +     unsigned char desc;       /* True for DESC.  False for ASC. */
         3301  +  } *aOrderBy;               /* The ORDER BY clause */
         3302  +  /* Outputs */
         3303  +  struct sqlite4_index_constraint_usage {
         3304  +    int argvIndex;           /* if >0, constraint is part of argv to xFilter */
         3305  +    unsigned char omit;      /* Do not code a test for this constraint */
         3306  +  } *aConstraintUsage;
         3307  +  int idxNum;                /* Number used to identify the index */
         3308  +  char *idxStr;              /* String, possibly obtained from sqlite4_malloc */
         3309  +  int needToFreeIdxStr;      /* Free idxStr using sqlite4_free() if true */
         3310  +  int orderByConsumed;       /* True if output is already ordered */
         3311  +  double estimatedCost;      /* Estimated cost of using this index */
         3312  +};
         3313  +
         3314  +/*
         3315  +** CAPIREF: Virtual Table Constraint Operator Codes
         3316  +**
         3317  +** These macros defined the allowed values for the
         3318  +** [sqlite4_index_info].aConstraint[].op field.  Each value represents
         3319  +** an operator that is part of a constraint term in the wHERE clause of
         3320  +** a query that uses a [virtual table].
         3321  +*/
         3322  +#define SQLITE4_INDEX_CONSTRAINT_EQ    2
         3323  +#define SQLITE4_INDEX_CONSTRAINT_GT    4
         3324  +#define SQLITE4_INDEX_CONSTRAINT_LE    8
         3325  +#define SQLITE4_INDEX_CONSTRAINT_LT    16
         3326  +#define SQLITE4_INDEX_CONSTRAINT_GE    32
         3327  +#define SQLITE4_INDEX_CONSTRAINT_MATCH 64
         3328  +
         3329  +/*
         3330  +** CAPIREF: Register A Virtual Table Implementation
         3331  +**
         3332  +** ^These routines are used to register a new [virtual table module] name.
         3333  +** ^Module names must be registered before
         3334  +** creating a new [virtual table] using the module and before using a
         3335  +** preexisting [virtual table] for the module.
         3336  +**
         3337  +** ^The module name is registered on the [database connection] specified
         3338  +** by the first parameter.  ^The name of the module is given by the 
         3339  +** second parameter.  ^The third parameter is a pointer to
         3340  +** the implementation of the [virtual table module].   ^The fourth
         3341  +** parameter is an arbitrary client data pointer that is passed through
         3342  +** into the [xCreate] and [xConnect] methods of the virtual table module
         3343  +** when a new virtual table is be being created or reinitialized.
         3344  +**
         3345  +** ^The sqlite4_create_module_v2() interface has a fifth parameter which
         3346  +** is a pointer to a destructor for the pClientData.  ^SQLite will
         3347  +** invoke the destructor function (if it is not NULL) when SQLite
         3348  +** no longer needs the pClientData pointer.  ^The destructor will also
         3349  +** be invoked if the call to sqlite4_create_module_v2() fails.
         3350  +** ^The sqlite4_create_module()
         3351  +** interface is equivalent to sqlite4_create_module_v2() with a NULL
         3352  +** destructor.
         3353  +*/
         3354  +SQLITE4_API int sqlite4_create_module(
         3355  +  sqlite4 *db,               /* SQLite connection to register module with */
         3356  +  const char *zName,         /* Name of the module */
         3357  +  const sqlite4_module *p,   /* Methods for the module */
         3358  +  void *pClientData          /* Client data for xCreate/xConnect */
         3359  +);
         3360  +SQLITE4_API int sqlite4_create_module_v2(
         3361  +  sqlite4 *db,               /* SQLite connection to register module with */
         3362  +  const char *zName,         /* Name of the module */
         3363  +  const sqlite4_module *p,   /* Methods for the module */
         3364  +  void *pClientData,         /* Client data for xCreate/xConnect */
         3365  +  void(*xDestroy)(void*)     /* Module destructor function */
         3366  +);
         3367  +
         3368  +/*
         3369  +** CAPIREF: Virtual Table Instance Object
         3370  +** KEYWORDS: sqlite4_vtab
         3371  +**
         3372  +** Every [virtual table module] implementation uses a subclass
         3373  +** of this object to describe a particular instance
         3374  +** of the [virtual table].  Each subclass will
         3375  +** be tailored to the specific needs of the module implementation.
         3376  +** The purpose of this superclass is to define certain fields that are
         3377  +** common to all module implementations.
         3378  +**
         3379  +** ^Virtual tables methods can set an error message by assigning a
         3380  +** string obtained from [sqlite4_mprintf()] to zErrMsg.  The method should
         3381  +** take care that any prior string is freed by a call to [sqlite4_free()]
         3382  +** prior to assigning a new string to zErrMsg.  ^After the error message
         3383  +** is delivered up to the client application, the string will be automatically
         3384  +** freed by sqlite4_free() and the zErrMsg field will be zeroed.
         3385  +*/
         3386  +struct sqlite4_vtab {
         3387  +  const sqlite4_module *pModule;  /* The module for this virtual table */
         3388  +  int nRef;                       /* NO LONGER USED */
         3389  +  char *zErrMsg;                  /* Error message from sqlite4_mprintf() */
         3390  +  /* Virtual table implementations will typically add additional fields */
         3391  +};
         3392  +
         3393  +/*
         3394  +** CAPIREF: Virtual Table Cursor Object
         3395  +** KEYWORDS: sqlite4_vtab_cursor {virtual table cursor}
         3396  +**
         3397  +** Every [virtual table module] implementation uses a subclass of the
         3398  +** following structure to describe cursors that point into the
         3399  +** [virtual table] and are used
         3400  +** to loop through the virtual table.  Cursors are created using the
         3401  +** [sqlite4_module.xOpen | xOpen] method of the module and are destroyed
         3402  +** by the [sqlite4_module.xClose | xClose] method.  Cursors are used
         3403  +** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
         3404  +** of the module.  Each module implementation will define
         3405  +** the content of a cursor structure to suit its own needs.
         3406  +**
         3407  +** This superclass exists in order to define fields of the cursor that
         3408  +** are common to all implementations.
         3409  +*/
         3410  +struct sqlite4_vtab_cursor {
         3411  +  sqlite4_vtab *pVtab;      /* Virtual table of this cursor */
         3412  +  /* Virtual table implementations will typically add additional fields */
         3413  +};
         3414  +
         3415  +/*
         3416  +** CAPIREF: Declare The Schema Of A Virtual Table
         3417  +**
         3418  +** ^The [xCreate] and [xConnect] methods of a
         3419  +** [virtual table module] call this interface
         3420  +** to declare the format (the names and datatypes of the columns) of
         3421  +** the virtual tables they implement.
         3422  +*/
         3423  +SQLITE4_API int sqlite4_declare_vtab(sqlite4*, const char *zSQL);
         3424  +
         3425  +/*
         3426  +** CAPIREF: Overload A Function For A Virtual Table
         3427  +**
         3428  +** ^(Virtual tables can provide alternative implementations of functions
         3429  +** using the [xFindFunction] method of the [virtual table module].  
         3430  +** But global versions of those functions
         3431  +** must exist in order to be overloaded.)^
         3432  +**
         3433  +** ^(This API makes sure a global version of a function with a particular
         3434  +** name and number of parameters exists.  If no such function exists
         3435  +** before this API is called, a new function is created.)^  ^The implementation
         3436  +** of the new function always causes an exception to be thrown.  So
         3437  +** the new function is not good for anything by itself.  Its only
         3438  +** purpose is to be a placeholder function that can be overloaded
         3439  +** by a [virtual table].
         3440  +*/
         3441  +SQLITE4_API int sqlite4_overload_function(sqlite4*, const char *zFuncName, int nArg);
         3442  +
         3443  +/*
         3444  +** CAPIREF: Mutexes
         3445  +**
         3446  +** The SQLite core uses these routines for thread
         3447  +** synchronization. Though they are intended for internal
         3448  +** use by SQLite, code that links against SQLite is
         3449  +** permitted to use any of these routines.
         3450  +**
         3451  +** The SQLite source code contains multiple implementations
         3452  +** of these mutex routines.  An appropriate implementation
         3453  +** is selected automatically at compile-time.  ^(The following
         3454  +** implementations are available in the SQLite core:
         3455  +**
         3456  +** <ul>
         3457  +** <li>   SQLITE4_MUTEX_PTHREADS
         3458  +** <li>   SQLITE4_MUTEX_W32
         3459  +** <li>   SQLITE4_MUTEX_NOOP
         3460  +** </ul>)^
         3461  +**
         3462  +** ^The SQLITE4_MUTEX_NOOP implementation is a set of routines
         3463  +** that does no real locking and is appropriate for use in
         3464  +** a single-threaded application.  ^The SQLITE4_MUTEX_PTHREADS
         3465  +** and SQLITE4_MUTEX_W32 implementations
         3466  +** are appropriate for use on Unix and Windows.
         3467  +**
         3468  +** ^(If SQLite is compiled with the SQLITE4_MUTEX_APPDEF preprocessor
         3469  +** macro defined (with "-DSQLITE4_MUTEX_APPDEF=1"), then no mutex
         3470  +** implementation is included with the library. In this case the
         3471  +** application must supply a custom mutex implementation using the
         3472  +** [SQLITE4_CONFIG_MUTEX] option of the sqlite4_env_config() function
         3473  +** before calling sqlite4_initialize() or any other public sqlite4_
         3474  +** function that calls sqlite4_initialize().)^
         3475  +**
         3476  +** ^The sqlite4_mutex_alloc() routine allocates a new
         3477  +** mutex and returns a pointer to it. ^If it returns NULL
         3478  +** that means that a mutex could not be allocated.  ^SQLite
         3479  +** will unwind its stack and return an error.  ^(The argument
         3480  +** to sqlite4_mutex_alloc() is one of these integer constants:
         3481  +**
         3482  +** <ul>
         3483  +** <li>  SQLITE4_MUTEX_FAST
         3484  +** <li>  SQLITE4_MUTEX_RECURSIVE
         3485  +** </ul>)^
         3486  +**
         3487  +** ^The new mutex is recursive when SQLITE4_MUTEX_RECURSIVE
         3488  +** is used but not necessarily so when SQLITE4_MUTEX_FAST is used.
         3489  +** The mutex implementation does not need to make a distinction
         3490  +** between SQLITE4_MUTEX_RECURSIVE and SQLITE4_MUTEX_FAST if it does
         3491  +** not want to.  ^SQLite will only request a recursive mutex in
         3492  +** cases where it really needs one.  ^If a faster non-recursive mutex
         3493  +** implementation is available on the host platform, the mutex subsystem
         3494  +** might return such a mutex in response to SQLITE4_MUTEX_FAST.
         3495  +**
         3496  +** ^The sqlite4_mutex_free() routine deallocates a previously
         3497  +** allocated mutex. 
         3498  +**
         3499  +** ^The sqlite4_mutex_enter() and sqlite4_mutex_try() routines attempt
         3500  +** to enter a mutex.  ^If another thread is already within the mutex,
         3501  +** sqlite4_mutex_enter() will block and sqlite4_mutex_try() will return
         3502  +** SQLITE4_BUSY.  ^The sqlite4_mutex_try() interface returns [SQLITE4_OK]
         3503  +** upon successful entry.  ^(Mutexes created using
         3504  +** SQLITE4_MUTEX_RECURSIVE can be entered multiple times by the same thread.
         3505  +** In such cases the,
         3506  +** mutex must be exited an equal number of times before another thread
         3507  +** can enter.)^  ^(If the same thread tries to enter any other
         3508  +** kind of mutex more than once, the behavior is undefined.
         3509  +** SQLite will never exhibit
         3510  +** such behavior in its own use of mutexes.)^
         3511  +**
         3512  +** ^(Some systems (for example, Windows 95) do not support the operation
         3513  +** implemented by sqlite4_mutex_try().  On those systems, sqlite4_mutex_try()
         3514  +** will always return SQLITE4_BUSY.  The SQLite core only ever uses
         3515  +** sqlite4_mutex_try() as an optimization so this is acceptable behavior.)^
         3516  +**
         3517  +** ^The sqlite4_mutex_leave() routine exits a mutex that was
         3518  +** previously entered by the same thread.   ^(The behavior
         3519  +** is undefined if the mutex is not currently entered by the
         3520  +** calling thread or is not currently allocated.  SQLite will
         3521  +** never do either.)^
         3522  +**
         3523  +** ^If the argument to sqlite4_mutex_enter(), sqlite4_mutex_try(), or
         3524  +** sqlite4_mutex_leave() is a NULL pointer, then all three routines
         3525  +** behave as no-ops.
         3526  +**
         3527  +** See also: [sqlite4_mutex_held()] and [sqlite4_mutex_notheld()].
         3528  +*/
         3529  +SQLITE4_API sqlite4_mutex *sqlite4_mutex_alloc(sqlite4_env*, int);
         3530  +SQLITE4_API void sqlite4_mutex_free(sqlite4_mutex*);
         3531  +SQLITE4_API void sqlite4_mutex_enter(sqlite4_mutex*);
         3532  +SQLITE4_API int sqlite4_mutex_try(sqlite4_mutex*);
         3533  +SQLITE4_API void sqlite4_mutex_leave(sqlite4_mutex*);
         3534  +
         3535  +/*
         3536  +** CAPIREF: Mutex Methods Object
         3537  +**
         3538  +** An instance of this structure defines the low-level routines
         3539  +** used to allocate and use mutexes.
         3540  +**
         3541  +** Usually, the default mutex implementations provided by SQLite are
         3542  +** sufficient, however the user has the option of substituting a custom
         3543  +** implementation for specialized deployments or systems for which SQLite
         3544  +** does not provide a suitable implementation. In this case, the user
         3545  +** creates and populates an instance of this structure to pass
         3546  +** to sqlite4_env_config() along with the [SQLITE4_CONFIG_MUTEX] option.
         3547  +** Additionally, an instance of this structure can be used as an
         3548  +** output variable when querying the system for the current mutex
         3549  +** implementation, using the [SQLITE4_CONFIG_GETMUTEX] option.
         3550  +**
         3551  +** ^The xMutexInit method defined by this structure is invoked as
         3552  +** part of system initialization by the sqlite4_initialize() function.
         3553  +** ^The xMutexInit routine is called by SQLite exactly once for each
         3554  +** effective call to [sqlite4_initialize()].
         3555  +**
         3556  +** ^The xMutexEnd method defined by this structure is invoked as
         3557  +** part of system shutdown by the sqlite4_shutdown() function. The
         3558  +** implementation of this method is expected to release all outstanding
         3559  +** resources obtained by the mutex methods implementation, especially
         3560  +** those obtained by the xMutexInit method.  ^The xMutexEnd()
         3561  +** interface is invoked exactly once for each call to [sqlite4_shutdown()].
         3562  +**
         3563  +** ^(The remaining seven methods defined by this structure (xMutexAlloc,
         3564  +** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
         3565  +** xMutexNotheld) implement the following interfaces (respectively):
         3566  +**
         3567  +** <ul>
         3568  +**   <li>  [sqlite4_mutex_alloc()] </li>
         3569  +**   <li>  [sqlite4_mutex_free()] </li>
         3570  +**   <li>  [sqlite4_mutex_enter()] </li>
         3571  +**   <li>  [sqlite4_mutex_try()] </li>
         3572  +**   <li>  [sqlite4_mutex_leave()] </li>
         3573  +**   <li>  [sqlite4_mutex_held()] </li>
         3574  +**   <li>  [sqlite4_mutex_notheld()] </li>
         3575  +** </ul>)^
         3576  +**
         3577  +** The only difference is that the public sqlite4_XXX functions enumerated
         3578  +** above silently ignore any invocations that pass a NULL pointer instead
         3579  +** of a valid mutex handle. The implementations of the methods defined
         3580  +** by this structure are not required to handle this case, the results
         3581  +** of passing a NULL pointer instead of a valid mutex handle are undefined
         3582  +** (i.e. it is acceptable to provide an implementation that segfaults if
         3583  +** it is passed a NULL pointer).
         3584  +**
         3585  +** The xMutexInit() method must be threadsafe.  ^It must be harmless to
         3586  +** invoke xMutexInit() multiple times within the same process and without
         3587  +** intervening calls to xMutexEnd().  Second and subsequent calls to
         3588  +** xMutexInit() must be no-ops.
         3589  +**
         3590  +** ^xMutexInit() must not use SQLite memory allocation ([sqlite4_malloc()]
         3591  +** and its associates).  ^Similarly, xMutexAlloc() must not use SQLite memory
         3592  +** allocation for a static mutex.  ^However xMutexAlloc() may use SQLite
         3593  +** memory allocation for a fast or recursive mutex.
         3594  +**
         3595  +** ^SQLite will invoke the xMutexEnd() method when [sqlite4_shutdown()] is
         3596  +** called, but only if the prior call to xMutexInit returned SQLITE4_OK.
         3597  +** If xMutexInit fails in any way, it is expected to clean up after itself
         3598  +** prior to returning.
         3599  +*/
         3600  +typedef struct sqlite4_mutex_methods sqlite4_mutex_methods;
         3601  +struct sqlite4_mutex_methods {
         3602  +  int (*xMutexInit)(void*);
         3603  +  int (*xMutexEnd)(void*);
         3604  +  sqlite4_mutex *(*xMutexAlloc)(void*,int);
         3605  +  void (*xMutexFree)(sqlite4_mutex *);
         3606  +  void (*xMutexEnter)(sqlite4_mutex *);
         3607  +  int (*xMutexTry)(sqlite4_mutex *);
         3608  +  void (*xMutexLeave)(sqlite4_mutex *);
         3609  +  int (*xMutexHeld)(sqlite4_mutex *);
         3610  +  int (*xMutexNotheld)(sqlite4_mutex *);
         3611  +  void *pMutexEnv;
         3612  +};
         3613  +
         3614  +/*
         3615  +** CAPIREF: Mutex Verification Routines
         3616  +**
         3617  +** The sqlite4_mutex_held() and sqlite4_mutex_notheld() routines
         3618  +** are intended for use inside assert() statements.  ^The SQLite core
         3619  +** never uses these routines except inside an assert() and applications
         3620  +** are advised to follow the lead of the core.  ^The SQLite core only
         3621  +** provides implementations for these routines when it is compiled
         3622  +** with the SQLITE4_DEBUG flag.  ^External mutex implementations
         3623  +** are only required to provide these routines if SQLITE4_DEBUG is
         3624  +** defined and if NDEBUG is not defined.
         3625  +**
         3626  +** ^These routines should return true if the mutex in their argument
         3627  +** is held or not held, respectively, by the calling thread.
         3628  +**
         3629  +** ^The implementation is not required to provide versions of these
         3630  +** routines that actually work. If the implementation does not provide working
         3631  +** versions of these routines, it should at least provide stubs that always
         3632  +** return true so that one does not get spurious assertion failures.
         3633  +**
         3634  +** ^If the argument to sqlite4_mutex_held() is a NULL pointer then
         3635  +** the routine should return 1.   This seems counter-intuitive since
         3636  +** clearly the mutex cannot be held if it does not exist.  But
         3637  +** the reason the mutex does not exist is because the build is not
         3638  +** using mutexes.  And we do not want the assert() containing the
         3639  +** call to sqlite4_mutex_held() to fail, so a non-zero return is
         3640  +** the appropriate thing to do.  ^The sqlite4_mutex_notheld()
         3641  +** interface should also return 1 when given a NULL pointer.
         3642  +*/
         3643  +#ifndef NDEBUG
         3644  +SQLITE4_API int sqlite4_mutex_held(sqlite4_mutex*);
         3645  +SQLITE4_API int sqlite4_mutex_notheld(sqlite4_mutex*);
         3646  +#endif
         3647  +
         3648  +/*
         3649  +** CAPIREF: Mutex Types
         3650  +**
         3651  +** The [sqlite4_mutex_alloc()] interface takes a single argument
         3652  +** which is one of these integer constants.
         3653  +**
         3654  +** The set of static mutexes may change from one SQLite release to the
         3655  +** next.  Applications that override the built-in mutex logic must be
         3656  +** prepared to accommodate additional static mutexes.
         3657  +*/
         3658  +#define SQLITE4_MUTEX_FAST             0
         3659  +#define SQLITE4_MUTEX_RECURSIVE        1
         3660  +
         3661  +/*
         3662  +** CAPIREF: Retrieve the mutex for a database connection
         3663  +**
         3664  +** ^This interface returns a pointer the [sqlite4_mutex] object that 
         3665  +** serializes access to the [database connection] given in the argument
         3666  +** when the [threading mode] is Serialized.
         3667  +** ^If the [threading mode] is Single-thread or Multi-thread then this
         3668  +** routine returns a NULL pointer.
         3669  +*/
         3670  +SQLITE4_API sqlite4_mutex *sqlite4_db_mutex(sqlite4*);
         3671  +
         3672  +/*
         3673  +** CAPIREF: Low-Level Control Of Database Backends
         3674  +**
         3675  +** ^The [sqlite4_kvstore_control()] interface makes a direct call to the
         3676  +** xControl method of the key-value store associated with the particular 
         3677  +** database identified by the second argument. ^The name of the database 
         3678  +** is "main" for the main database or "temp" for the TEMP database, or the 
         3679  +** name that appears after the AS keyword for databases that were added 
         3680  +** using the [ATTACH] SQL command. ^A NULL pointer can be used in place 
         3681  +** of "main" to refer to the main database file.
         3682  +**
         3683  +** ^The third and fourth parameters to this routine are passed directly 
         3684  +** through to the second and third parameters of the
         3685  +** sqlite4_kv_methods.xControl method. ^The return value of the xControl
         3686  +** call becomes the return value of this routine.
         3687  +**
         3688  +** ^If the second parameter (zDbName) does not match the name of any
         3689  +** open database file, then SQLITE4_ERROR is returned.  ^This error
         3690  +** code is not remembered and will not be recalled by [sqlite4_errcode()]
         3691  +** or [sqlite4_errmsg()]. The underlying xControl method might also return 
         3692  +** SQLITE4_ERROR. There is no way to distinguish between an incorrect zDbName 
         3693  +** and an SQLITE4_ERROR return from the underlying xControl method.
         3694  +*/
         3695  +SQLITE4_API int sqlite4_kvstore_control(sqlite4*, const char *zDbName, int op, void*);
         3696  +
         3697  +/*
         3698  +** <dl>
         3699  +** <dt>SQLITE4_KVCTRL_LSM_HANDLE</dt><dd>
         3700  +**
         3701  +** <dt>SQLITE4_KVCTRL_SYNCHRONOUS</dt><dd>
         3702  +** This op is used to configure or query the synchronous level of the 
         3703  +** database backend (either OFF, NORMAL or FULL). The fourth parameter passed 
         3704  +** to kvstore_control should be of type (int *). Call the value that the
         3705  +** parameter points to N. If N is initially 0, 1 or 2, then the database 
         3706  +** backend should attempt to change the synchronous level to OFF, NORMAL 
         3707  +** or FULL, respectively. Regardless of its initial value, N is set to 
         3708  +** the current (possibly updated) synchronous level before returning (
         3709  +** 0, 1 or 2).
         3710  +*/
         3711  +#define SQLITE4_KVCTRL_LSM_HANDLE       1
         3712  +#define SQLITE4_KVCTRL_SYNCHRONOUS      2
         3713  +#define SQLITE4_KVCTRL_LSM_FLUSH        3
         3714  +#define SQLITE4_KVCTRL_LSM_MERGE        4
         3715  +#define SQLITE4_KVCTRL_LSM_CHECKPOINT   5
         3716  +
         3717  +/*
         3718  +** CAPIREF: Testing Interface
         3719  +**
         3720  +** ^The sqlite4_test_control() interface is used to read out internal
         3721  +** state of SQLite and to inject faults into SQLite for testing
         3722  +** purposes.  ^The first parameter is an operation code that determines
         3723  +** the number, meaning, and operation of all subsequent parameters.
         3724  +**
         3725  +** This interface is not for use by applications.  It exists solely
         3726  +** for verifying the correct operation of the SQLite library.  Depending
         3727  +** on how the SQLite library is compiled, this interface might not exist.
         3728  +**
         3729  +** The details of the operation codes, their meanings, the parameters
         3730  +** they take, and what they do are all subject to change without notice.
         3731  +** Unlike most of the SQLite API, this function is not guaranteed to
         3732  +** operate consistently from one release to the next.
         3733  +*/
         3734  +SQLITE4_API int sqlite4_test_control(int op, ...);
         3735  +
         3736  +/*
         3737  +** CAPIREF: Testing Interface Operation Codes
         3738  +**
         3739  +** These constants are the valid operation code parameters used
         3740  +** as the first argument to [sqlite4_test_control()].
         3741  +**
         3742  +** These parameters and their meanings are subject to change
         3743  +** without notice.  These values are for testing purposes only.
         3744  +** Applications should not use any of these parameters or the
         3745  +** [sqlite4_test_control()] interface.
         3746  +*/
         3747  +#define SQLITE4_TESTCTRL_FIRST                    1
         3748  +#define SQLITE4_TESTCTRL_FAULT_INSTALL            2
         3749  +#define SQLITE4_TESTCTRL_ASSERT                   3
         3750  +#define SQLITE4_TESTCTRL_ALWAYS                   4
         3751  +#define SQLITE4_TESTCTRL_RESERVE                  5
         3752  +#define SQLITE4_TESTCTRL_OPTIMIZATIONS            6
         3753  +#define SQLITE4_TESTCTRL_ISKEYWORD                7
         3754  +#define SQLITE4_TESTCTRL_LOCALTIME_FAULT          8
         3755  +#define SQLITE4_TESTCTRL_EXPLAIN_STMT             9
         3756  +#define SQLITE4_TESTCTRL_LAST                     9
         3757  +
         3758  +/*
         3759  +** CAPIREF: SQLite Runtime Status
         3760  +**
         3761  +** ^This interface is used to retrieve runtime status information
         3762  +** about the performance of SQLite, and optionally to reset various
         3763  +** highwater marks.  ^The first argument is an integer code for
         3764  +** the specific parameter to measure.  ^(Recognized integer codes
         3765  +** are of the form [status parameters | SQLITE4_STATUS_...].)^
         3766  +** ^The current value of the parameter is returned into *pCurrent.
         3767  +** ^The highest recorded value is returned in *pHighwater.  ^If the
         3768  +** resetFlag is true, then the highest record value is reset after
         3769  +** *pHighwater is written.  ^(Some parameters do not record the highest
         3770  +** value.  For those parameters
         3771  +** nothing is written into *pHighwater and the resetFlag is ignored.)^
         3772  +** ^(Other parameters record only the highwater mark and not the current
         3773  +** value.  For these latter parameters nothing is written into *pCurrent.)^
         3774  +**
         3775  +** ^The sqlite4_status() routine returns SQLITE4_OK on success and a
         3776  +** non-zero [error code] on failure.
         3777  +**
         3778  +** This routine is threadsafe but is not atomic.  This routine can be
         3779  +** called while other threads are running the same or different SQLite
         3780  +** interfaces.  However the values returned in *pCurrent and
         3781  +** *pHighwater reflect the status of SQLite at different points in time
         3782  +** and it is possible that another thread might change the parameter
         3783  +** in between the times when *pCurrent and *pHighwater are written.
         3784  +**
         3785  +** See also: [sqlite4_db_status()]
         3786  +*/
         3787  +SQLITE4_API int sqlite4_env_status(
         3788  +  sqlite4_env *pEnv,
         3789  +  int op,
         3790  +  sqlite4_uint64 *pCurrent,
         3791  +  sqlite4_uint64 *pHighwater,
         3792  +  int resetFlag
         3793  +);
         3794  +
         3795  +
         3796  +/*
         3797  +** CAPIREF: Status Parameters
         3798  +** KEYWORDS: {status parameters}
         3799  +**
         3800  +** These integer constants designate various run-time status parameters
         3801  +** that can be returned by [sqlite4_status()].
         3802  +**
         3803  +** <dl>
         3804  +** [[SQLITE4_STATUS_MEMORY_USED]] ^(<dt>SQLITE4_STATUS_MEMORY_USED</dt>
         3805  +** <dd>This parameter is the current amount of memory checked out
         3806  +** using [sqlite4_malloc()], either directly or indirectly.  The
         3807  +** figure includes calls made to [sqlite4_malloc()] by the application
         3808  +** and internal memory usage by the SQLite library.  Scratch memory
         3809  +** controlled by [SQLITE4_CONFIG_SCRATCH] and auxiliary page-cache
         3810  +** memory controlled by [SQLITE4_CONFIG_PAGECACHE] is not included in
         3811  +** this parameter.  The amount returned is the sum of the allocation
         3812  +** sizes as reported by the xSize method in [sqlite4_mem_methods].</dd>)^
         3813  +**
         3814  +** [[SQLITE4_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE4_STATUS_MALLOC_SIZE</dt>
         3815  +** <dd>This parameter records the largest memory allocation request
         3816  +** handed to [sqlite4_malloc()] or [sqlite4_realloc()] (or their
         3817  +** internal equivalents).  Only the value returned in the
         3818  +** *pHighwater parameter to [sqlite4_status()] is of interest.  
         3819  +** The value written into the *pCurrent parameter is undefined.</dd>)^
         3820  +**
         3821  +** [[SQLITE4_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE4_STATUS_MALLOC_COUNT</dt>
         3822  +** <dd>This parameter records the number of separate memory allocations
         3823  +** currently checked out.</dd>)^
         3824  +**
         3825  +** [[SQLITE4_STATUS_PARSER_STACK]] ^(<dt>SQLITE4_STATUS_PARSER_STACK</dt>
         3826  +** <dd>This parameter records the deepest parser stack.  It is only
         3827  +** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
         3828  +** </dl>
         3829  +**
         3830  +** New status parameters may be added from time to time.
         3831  +*/
         3832  +#define SQLITE4_ENVSTATUS_MEMORY_USED          0
         3833  +#define SQLITE4_ENVSTATUS_MALLOC_SIZE          1
         3834  +#define SQLITE4_ENVSTATUS_MALLOC_COUNT         2
         3835  +#define SQLITE4_ENVSTATUS_PARSER_STACK         3
         3836  +
         3837  +/*
         3838  +** CAPIREF: Database Connection Status
         3839  +**
         3840  +** ^This interface is used to retrieve runtime status information 
         3841  +** about a single [database connection].  ^The first argument is the
         3842  +** database connection object to be interrogated.  ^The second argument
         3843  +** is an integer constant, taken from the set of
         3844  +** [SQLITE4_DBSTATUS options], that
         3845  +** determines the parameter to interrogate.  The set of 
         3846  +** [SQLITE4_DBSTATUS options] is likely
         3847  +** to grow in future releases of SQLite.
         3848  +**
         3849  +** ^The current value of the requested parameter is written into *pCur
         3850  +** and the highest instantaneous value is written into *pHiwtr.  ^If
         3851  +** the resetFlg is true, then the highest instantaneous value is
         3852  +** reset back down to the current value.
         3853  +**
         3854  +** ^The sqlite4_db_status() routine returns SQLITE4_OK on success and a
         3855  +** non-zero [error code] on failure.
         3856  +**
         3857  +** See also: [sqlite4_status()] and [sqlite4_stmt_status()].
         3858  +*/
         3859  +SQLITE4_API int sqlite4_db_status(sqlite4*, int op, int *pCur, int *pHiwtr, int resetFlg);
         3860  +
         3861  +/*
         3862  +** CAPIREF: Status Parameters for database connections
         3863  +** KEYWORDS: {SQLITE4_DBSTATUS options}
         3864  +**
         3865  +** These constants are the available integer "verbs" that can be passed as
         3866  +** the second argument to the [sqlite4_db_status()] interface.
         3867  +**
         3868  +** New verbs may be added in future releases of SQLite. Existing verbs
         3869  +** might be discontinued. Applications should check the return code from
         3870  +** [sqlite4_db_status()] to make sure that the call worked.
         3871  +** The [sqlite4_db_status()] interface will return a non-zero error code
         3872  +** if a discontinued or unsupported verb is invoked.
         3873  +**
         3874  +** <dl>
         3875  +** [[SQLITE4_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_USED</dt>
         3876  +** <dd>This parameter returns the number of lookaside memory slots currently
         3877  +** checked out.</dd>)^
         3878  +**
         3879  +** [[SQLITE4_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_HIT</dt>
         3880  +** <dd>This parameter returns the number malloc attempts that were 
         3881  +** satisfied using lookaside memory. Only the high-water value is meaningful;
         3882  +** the current value is always zero.)^
         3883  +**
         3884  +** [[SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE]]
         3885  +** ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
         3886  +** <dd>This parameter returns the number malloc attempts that might have
         3887  +** been satisfied using lookaside memory but failed due to the amount of
         3888  +** memory requested being larger than the lookaside slot size.
         3889  +** Only the high-water value is meaningful;
         3890  +** the current value is always zero.)^
         3891  +**
         3892  +** [[SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL]]
         3893  +** ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
         3894  +** <dd>This parameter returns the number malloc attempts that might have
         3895  +** been satisfied using lookaside memory but failed due to all lookaside
         3896  +** memory already being in use.
         3897  +** Only the high-water value is meaningful;
         3898  +** the current value is always zero.)^
         3899  +**
         3900  +** [[SQLITE4_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE4_DBSTATUS_CACHE_USED</dt>
         3901  +** <dd>This parameter returns the approximate number of of bytes of heap
         3902  +** memory used by all pager caches associated with the database connection.)^
         3903  +** ^The highwater mark associated with SQLITE4_DBSTATUS_CACHE_USED is always 0.
         3904  +**
         3905  +** [[SQLITE4_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE4_DBSTATUS_SCHEMA_USED</dt>
         3906  +** <dd>This parameter returns the approximate number of of bytes of heap
         3907  +** memory used to store the schema for all databases associated
         3908  +** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 
         3909  +** ^The full amount of memory used by the schemas is reported, even if the
         3910  +** schema memory is shared with other database connections due to
         3911  +** [shared cache mode] being enabled.
         3912  +** ^The highwater mark associated with SQLITE4_DBSTATUS_SCHEMA_USED is always 0.
         3913  +**
         3914  +** [[SQLITE4_DBSTATUS_STMT_USED]] ^(<dt>SQLITE4_DBSTATUS_STMT_USED</dt>
         3915  +** <dd>This parameter returns the approximate number of of bytes of heap
         3916  +** and lookaside memory used by all prepared statements associated with
         3917  +** the database connection.)^
         3918  +** ^The highwater mark associated with SQLITE4_DBSTATUS_STMT_USED is always 0.
         3919  +** </dd>
         3920  +**
         3921  +** [[SQLITE4_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE4_DBSTATUS_CACHE_HIT</dt>
         3922  +** <dd>This parameter returns the number of pager cache hits that have
         3923  +** occurred.)^ ^The highwater mark associated with SQLITE4_DBSTATUS_CACHE_HIT 
         3924  +** is always 0.
         3925  +** </dd>
         3926  +**
         3927  +** [[SQLITE4_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE4_DBSTATUS_CACHE_MISS</dt>
         3928  +** <dd>This parameter returns the number of pager cache misses that have
         3929  +** occurred.)^ ^The highwater mark associated with SQLITE4_DBSTATUS_CACHE_MISS 
         3930  +** is always 0.
         3931  +** </dd>
         3932  +** </dl>
         3933  +*/
         3934  +#define SQLITE4_DBSTATUS_LOOKASIDE_USED       0
         3935  +#define SQLITE4_DBSTATUS_CACHE_USED           1
         3936  +#define SQLITE4_DBSTATUS_SCHEMA_USED          2
         3937  +#define SQLITE4_DBSTATUS_STMT_USED            3
         3938  +#define SQLITE4_DBSTATUS_LOOKASIDE_HIT        4
         3939  +#define SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE  5
         3940  +#define SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL  6
         3941  +#define SQLITE4_DBSTATUS_CACHE_HIT            7
         3942  +#define SQLITE4_DBSTATUS_CACHE_MISS           8
         3943  +#define SQLITE4_DBSTATUS_MAX                  8   /* Largest defined DBSTATUS */
         3944  +
         3945  +
         3946  +/*
         3947  +** CAPIREF: Prepared Statement Status
         3948  +**
         3949  +** ^(Each prepared statement maintains various
         3950  +** [SQLITE4_STMTSTATUS counters] that measure the number
         3951  +** of times it has performed specific operations.)^  These counters can
         3952  +** be used to monitor the performance characteristics of the prepared
         3953  +** statements.  For example, if the number of table steps greatly exceeds
         3954  +** the number of table searches or result rows, that would tend to indicate
         3955  +** that the prepared statement is using a full table scan rather than
         3956  +** an index.  
         3957  +**
         3958  +** ^(This interface is used to retrieve and reset counter values from
         3959  +** a [prepared statement].  The first argument is the prepared statement
         3960  +** object to be interrogated.  The second argument
         3961  +** is an integer code for a specific [SQLITE4_STMTSTATUS counter]
         3962  +** to be interrogated.)^
         3963  +** ^The current value of the requested counter is returned.
         3964  +** ^If the resetFlg is true, then the counter is reset to zero after this
         3965  +** interface call returns.
         3966  +**
         3967  +** See also: [sqlite4_status()] and [sqlite4_db_status()].
         3968  +*/
         3969  +SQLITE4_API int sqlite4_stmt_status(sqlite4_stmt*, int op,int resetFlg);
         3970  +
         3971  +/*
         3972  +** CAPIREF: Status Parameters for prepared statements
         3973  +** KEYWORDS: {SQLITE4_STMTSTATUS counter} {SQLITE4_STMTSTATUS counters}
         3974  +**
         3975  +** These preprocessor macros define integer codes that name counter
         3976  +** values associated with the [sqlite4_stmt_status()] interface.
         3977  +** The meanings of the various counters are as follows:
         3978  +**
         3979  +** <dl>
         3980  +** [[SQLITE4_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE4_STMTSTATUS_FULLSCAN_STEP</dt>
         3981  +** <dd>^This is the number of times that SQLite has stepped forward in
         3982  +** a table as part of a full table scan.  Large numbers for this counter
         3983  +** may indicate opportunities for performance improvement through 
         3984  +** careful use of indices.</dd>
         3985  +**
         3986  +** [[SQLITE4_STMTSTATUS_SORT]] <dt>SQLITE4_STMTSTATUS_SORT</dt>
         3987  +** <dd>^This is the number of sort operations that have occurred.
         3988  +** A non-zero value in this counter may indicate an opportunity to
         3989  +** improvement performance through careful use of indices.</dd>
         3990  +**
         3991  +** [[SQLITE4_STMTSTATUS_AUTOINDEX]] <dt>SQLITE4_STMTSTATUS_AUTOINDEX</dt>
         3992  +** <dd>^This is the number of rows inserted into transient indices that
         3993  +** were created automatically in order to help joins run faster.
         3994  +** A non-zero value in this counter may indicate an opportunity to
         3995  +** improvement performance by adding permanent indices that do not
         3996  +** need to be reinitialized each time the statement is run.</dd>
         3997  +** </dl>
         3998  +*/
         3999  +#define SQLITE4_STMTSTATUS_FULLSCAN_STEP     1
         4000  +#define SQLITE4_STMTSTATUS_SORT              2
         4001  +#define SQLITE4_STMTSTATUS_AUTOINDEX         3
         4002  +
         4003  +
         4004  +/*
         4005  +** CAPIREF: Unlock Notification
         4006  +**
         4007  +** ^When running in shared-cache mode, a database operation may fail with
         4008  +** an [SQLITE4_LOCKED] error if the required locks on the shared-cache or
         4009  +** individual tables within the shared-cache cannot be obtained. See
         4010  +** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 
         4011  +** ^This API may be used to register a callback that SQLite will invoke 
         4012  +** when the connection currently holding the required lock relinquishes it.
         4013  +** ^This API is only available if the library was compiled with the
         4014  +** [SQLITE4_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
         4015  +**
         4016  +** See Also: [Using the SQLite Unlock Notification Feature].
         4017  +**
         4018  +** ^Shared-cache locks are released when a database connection concludes
         4019  +** its current transaction, either by committing it or rolling it back. 
         4020  +**
         4021  +** ^When a connection (known as the blocked connection) fails to obtain a
         4022  +** shared-cache lock and SQLITE4_LOCKED is returned to the caller, the
         4023  +** identity of the database connection (the blocking connection) that
         4024  +** has locked the required resource is stored internally. ^After an 
         4025  +** application receives an SQLITE4_LOCKED error, it may call the
         4026  +** sqlite4_unlock_notify() method with the blocked connection handle as 
         4027  +** the first argument to register for a callback that will be invoked
         4028  +** when the blocking connections current transaction is concluded. ^The
         4029  +** callback is invoked from within the [sqlite4_step] or [sqlite4_close]
         4030  +** call that concludes the blocking connections transaction.
         4031  +**
         4032  +** ^(If sqlite4_unlock_notify() is called in a multi-threaded application,
         4033  +** there is a chance that the blocking connection will have already
         4034  +** concluded its transaction by the time sqlite4_unlock_notify() is invoked.
         4035  +** If this happens, then the specified callback is invoked immediately,
         4036  +** from within the call to sqlite4_unlock_notify().)^
         4037  +**
         4038  +** ^If the blocked connection is attempting to obtain a write-lock on a
         4039  +** shared-cache table, and more than one other connection currently holds
         4040  +** a read-lock on the same table, then SQLite arbitrarily selects one of 
         4041  +** the other connections to use as the blocking connection.
         4042  +**
         4043  +** ^(There may be at most one unlock-notify callback registered by a 
         4044  +** blocked connection. If sqlite4_unlock_notify() is called when the
         4045  +** blocked connection already has a registered unlock-notify callback,
         4046  +** then the new callback replaces the old.)^ ^If sqlite4_unlock_notify() is
         4047  +** called with a NULL pointer as its second argument, then any existing
         4048  +** unlock-notify callback is canceled. ^The blocked connections 
         4049  +** unlock-notify callback may also be canceled by closing the blocked
         4050  +** connection using [sqlite4_close()].
         4051  +**
         4052  +** The unlock-notify callback is not reentrant. If an application invokes
         4053  +** any sqlite4_xxx API functions from within an unlock-notify callback, a
         4054  +** crash or deadlock may be the result.
         4055  +**
         4056  +** ^Unless deadlock is detected (see below), sqlite4_unlock_notify() always
         4057  +** returns SQLITE4_OK.
         4058  +**
         4059  +** <b>Callback Invocation Details</b>
         4060  +**
         4061  +** When an unlock-notify callback is registered, the application provides a 
         4062  +** single void* pointer that is passed to the callback when it is invoked.
         4063  +** However, the signature of the callback function allows SQLite to pass
         4064  +** it an array of void* context pointers. The first argument passed to
         4065  +** an unlock-notify callback is a pointer to an array of void* pointers,
         4066  +** and the second is the number of entries in the array.
         4067  +**
         4068  +** When a blocking connections transaction is concluded, there may be
         4069  +** more than one blocked connection that has registered for an unlock-notify
         4070  +** callback. ^If two or more such blocked connections have specified the
         4071  +** same callback function, then instead of invoking the callback function
         4072  +** multiple times, it is invoked once with the set of void* context pointers
         4073  +** specified by the blocked connections bundled together into an array.
         4074  +** This gives the application an opportunity to prioritize any actions 
         4075  +** related to the set of unblocked database connections.
         4076  +**
         4077  +** <b>Deadlock Detection</b>
         4078  +**
         4079  +** Assuming that after registering for an unlock-notify callback a 
         4080  +** database waits for the callback to be issued before taking any further
         4081  +** action (a reasonable assumption), then using this API may cause the
         4082  +** application to deadlock. For example, if connection X is waiting for
         4083  +** connection Y's transaction to be concluded, and similarly connection
         4084  +** Y is waiting on connection X's transaction, then neither connection
         4085  +** will proceed and the system may remain deadlocked indefinitely.
         4086  +**
         4087  +** To avoid this scenario, the sqlite4_unlock_notify() performs deadlock
         4088  +** detection. ^If a given call to sqlite4_unlock_notify() would put the
         4089  +** system in a deadlocked state, then SQLITE4_LOCKED is returned and no
         4090  +** unlock-notify callback is registered. The system is said to be in
         4091  +** a deadlocked state if connection A has registered for an unlock-notify
         4092  +** callback on the conclusion of connection B's transaction, and connection
         4093  +** B has itself registered for an unlock-notify callback when connection
         4094  +** A's transaction is concluded. ^Indirect deadlock is also detected, so
         4095  +** the system is also considered to be deadlocked if connection B has
         4096  +** registered for an unlock-notify callback on the conclusion of connection
         4097  +** C's transaction, where connection C is waiting on connection A. ^Any
         4098  +** number of levels of indirection are allowed.
         4099  +**
         4100  +** <b>The "DROP TABLE" Exception</b>
         4101  +**
         4102  +** When a call to [sqlite4_step()] returns SQLITE4_LOCKED, it is almost 
         4103  +** always appropriate to call sqlite4_unlock_notify(). There is however,
         4104  +** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
         4105  +** SQLite checks if there are any currently executing SELECT statements
         4106  +** that belong to the same connection. If there are, SQLITE4_LOCKED is
         4107  +** returned. In this case there is no "blocking connection", so invoking
         4108  +** sqlite4_unlock_notify() results in the unlock-notify callback being
         4109  +** invoked immediately. If the application then re-attempts the "DROP TABLE"
         4110  +** or "DROP INDEX" query, an infinite loop might be the result.
         4111  +**
         4112  +** One way around this problem is to check the extended error code returned
         4113  +** by an sqlite4_step() call. ^(If there is a blocking connection, then the
         4114  +** extended error code is set to SQLITE4_LOCKED_SHAREDCACHE. Otherwise, in
         4115  +** the special "DROP TABLE/INDEX" case, the extended error code is just 
         4116  +** SQLITE4_LOCKED.)^
         4117  +*/
         4118  +SQLITE4_API int sqlite4_unlock_notify(
         4119  +  sqlite4 *pBlocked,                          /* Waiting connection */
         4120  +  void (*xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
         4121  +  void *pNotifyArg                            /* Argument to pass to xNotify */
         4122  +);
         4123  +
         4124  +
         4125  +/*
         4126  +** CAPIREF: String Comparison
         4127  +**
         4128  +** ^The [sqlite4_strnicmp()] API allows applications and extensions to
         4129  +** compare the contents of two buffers containing UTF-8 strings in a
         4130  +** case-independent fashion, using the same definition of case independence 
         4131  +** that SQLite uses internally when comparing identifiers.
         4132  +*/
         4133  +SQLITE4_API int sqlite4_strnicmp(const char *, const char *, int);
         4134  +
         4135  +/*
         4136  +** CAPIREF: Error Logging Interface
         4137  +**
         4138  +** ^The [sqlite4_log()] interface writes a message into the error log
         4139  +** established by the [SQLITE4_CONFIG_LOG] option to [sqlite4_env_config()].
         4140  +** ^If logging is enabled, the zFormat string and subsequent arguments are
         4141  +** used with [sqlite4_snprintf()] to generate the final output string.
         4142  +**
         4143  +** The sqlite4_log() interface is intended for use by extensions such as
         4144  +** virtual tables, collating functions, and SQL functions.  While there is
         4145  +** nothing to prevent an application from calling sqlite4_log(), doing so
         4146  +** is considered bad form.
         4147  +**
         4148  +** The zFormat string must not be NULL.
         4149  +**
         4150  +** To avoid deadlocks and other threading problems, the sqlite4_log() routine
         4151  +** will not use dynamically allocated memory.  The log message is stored in
         4152  +** a fixed-length buffer on the stack.  If the log message is longer than
         4153  +** a few hundred characters, it will be truncated to the length of the
         4154  +** buffer.
         4155  +*/
         4156  +SQLITE4_API void sqlite4_log(sqlite4_env*, int iErrCode, const char *zFormat, ...);
         4157  +
         4158  +/*
         4159  +** CAPIREF: Virtual Table Interface Configuration
         4160  +**
         4161  +** This function may be called by either the [xConnect] or [xCreate] method
         4162  +** of a [virtual table] implementation to configure
         4163  +** various facets of the virtual table interface.
         4164  +**
         4165  +** If this interface is invoked outside the context of an xConnect or
         4166  +** xCreate virtual table method then the behavior is undefined.
         4167  +**
         4168  +** At present, there is only one option that may be configured using
         4169  +** this function. (See [SQLITE4_VTAB_CONSTRAINT_SUPPORT].)  Further options
         4170  +** may be added in the future.
         4171  +*/
         4172  +SQLITE4_API int sqlite4_vtab_config(sqlite4*, int op, ...);
         4173  +
         4174  +/*
         4175  +** CAPIREF: Virtual Table Configuration Options
         4176  +**
         4177  +** These macros define the various options to the
         4178  +** [sqlite4_vtab_config()] interface that [virtual table] implementations
         4179  +** can use to customize and optimize their behavior.
         4180  +**
         4181  +** <dl>
         4182  +** <dt>SQLITE4_VTAB_CONSTRAINT_SUPPORT
         4183  +** <dd>Calls of the form
         4184  +** [sqlite4_vtab_config](db,SQLITE4_VTAB_CONSTRAINT_SUPPORT,X) are supported,
         4185  +** where X is an integer.  If X is zero, then the [virtual table] whose
         4186  +** [xCreate] or [xConnect] method invoked [sqlite4_vtab_config()] does not
         4187  +** support constraints.  In this configuration (which is the default) if
         4188  +** a call to the [xUpdate] method returns [SQLITE4_CONSTRAINT], then the entire
         4189  +** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
         4190  +** specified as part of the users SQL statement, regardless of the actual
         4191  +** ON CONFLICT mode specified.
         4192  +**
         4193  +** If X is non-zero, then the virtual table implementation guarantees
         4194  +** that if [xUpdate] returns [SQLITE4_CONSTRAINT], it will do so before
         4195  +** any modifications to internal or persistent data structures have been made.
         4196  +** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite 
         4197  +** is able to roll back a statement or database transaction, and abandon
         4198  +** or continue processing the current SQL statement as appropriate. 
         4199  +** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
         4200  +** [SQLITE4_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
         4201  +** had been ABORT.
         4202  +**
         4203  +** Virtual table implementations that are required to handle OR REPLACE
         4204  +** must do so within the [xUpdate] method. If a call to the 
         4205  +** [sqlite4_vtab_on_conflict()] function indicates that the current ON 
         4206  +** CONFLICT policy is REPLACE, the virtual table implementation should 
         4207  +** silently replace the appropriate rows within the xUpdate callback and
         4208  +** return SQLITE4_OK. Or, if this is not possible, it may return
         4209  +** SQLITE4_CONSTRAINT, in which case SQLite falls back to OR ABORT 
         4210  +** constraint handling.
         4211  +** </dl>
         4212  +*/
         4213  +#define SQLITE4_VTAB_CONSTRAINT_SUPPORT 1
         4214  +
         4215  +/*
         4216  +** CAPIREF: Determine The Virtual Table Conflict Policy
         4217  +**
         4218  +** This function may only be called from within a call to the [xUpdate] method
         4219  +** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
         4220  +** value returned is one of [SQLITE4_ROLLBACK], [SQLITE4_IGNORE], [SQLITE4_FAIL],
         4221  +** [SQLITE4_ABORT], or [SQLITE4_REPLACE], according to the [ON CONFLICT] mode
         4222  +** of the SQL statement that triggered the call to the [xUpdate] method of the
         4223  +** [virtual table].
         4224  +*/
         4225  +SQLITE4_API int sqlite4_vtab_on_conflict(sqlite4 *);
         4226  +
         4227  +/*
         4228  +** CAPIREF: Conflict resolution modes
         4229  +**
         4230  +** These constants are returned by [sqlite4_vtab_on_conflict()] to
         4231  +** inform a [virtual table] implementation what the [ON CONFLICT] mode
         4232  +** is for the SQL statement being evaluated.
         4233  +**
         4234  +** Note that the [SQLITE4_IGNORE] constant is also used as a potential
         4235  +** return value from the [sqlite4_set_authorizer()] callback and that
         4236  +** [SQLITE4_ABORT] is also a [result code].
         4237  +*/
         4238  +#define SQLITE4_ROLLBACK 1
         4239  +/* #define SQLITE4_IGNORE 2 // Also used by sqlite4_authorizer() callback */
         4240  +#define SQLITE4_FAIL     3
         4241  +/* #define SQLITE4_ABORT 4  // Also an error code */
         4242  +#define SQLITE4_REPLACE  5
         4243  +
         4244  +
         4245  +/*
         4246  +** CAPI4REF:  Length of a key-value storage key or data field
         4247  +**
         4248  +** The length of the key or data for a key-value storage entry is
         4249  +** stored in a variable of this type.
         4250  +*/
         4251  +typedef int sqlite4_kvsize;
         4252  +
         4253  +/*
         4254  +** CAPI4REF: Key-Value Storage Engine Object
         4255  +**
         4256  +** An instance of a subclass of the following object defines a
         4257  +** connection to a storage engine.
         4258  +*/
         4259  +typedef struct sqlite4_kvstore sqlite4_kvstore;
         4260  +struct sqlite4_kvstore {
         4261  +  const struct sqlite4_kv_methods *pStoreVfunc;  /* Methods */
         4262  +  sqlite4_env *pEnv;                      /* Runtime environment for kvstore */
         4263  +  int iTransLevel;                        /* Current transaction level */
         4264  +  unsigned kvId;                          /* Unique ID used for tracing */
         4265  +  unsigned fTrace;                        /* True to enable tracing */
         4266  +  char zKVName[12];                       /* Used for debugging */
         4267  +  /* Subclasses will typically append additional fields */
         4268  +};
         4269  +
         4270  +/*
         4271  +** CAPI4REF:  Key-Value Storage Engine Cursor Object
         4272  +**
         4273  +** An instance of a subclass of the following object defines a cursor
         4274  +** used to scan through a key-value storage engine.
         4275  +*/
         4276  +typedef struct sqlite4_kvcursor sqlite4_kvcursor;
         4277  +struct sqlite4_kvcursor {
         4278  +  sqlite4_kvstore *pStore;                /* The owner of this cursor */
         4279  +  const struct sqlite4_kv_methods *pStoreVfunc;  /* Methods */
         4280  +  sqlite4_env *pEnv;                      /* Runtime environment  */
         4281  +  int iTransLevel;                        /* Current transaction level */
         4282  +  unsigned curId;                         /* Unique ID for tracing */
         4283  +  unsigned fTrace;                        /* True to enable tracing */
         4284  +  /* Subclasses will typically add additional fields */
         4285  +};
         4286  +
         4287  +/*
         4288  +** CAPI4REF: Key-value storage engine virtual method table
         4289  +**
         4290  +** A Key-Value storage engine is defined by an instance of the following
         4291  +** object.
         4292  +*/
         4293  +struct sqlite4_kv_methods {
         4294  +  int iVersion;
         4295  +  int szSelf;
         4296  +  int (*xReplace)(
         4297  +         sqlite4_kvstore*,
         4298  +         const unsigned char *pKey, sqlite4_kvsize nKey,
         4299  +         const unsigned char *pData, sqlite4_kvsize nData);
         4300  +  int (*xOpenCursor)(sqlite4_kvstore*, sqlite4_kvcursor**);
         4301  +  int (*xSeek)(sqlite4_kvcursor*,
         4302  +               const unsigned char *pKey, sqlite4_kvsize nKey, int dir);
         4303  +  int (*xNext)(sqlite4_kvcursor*);
         4304  +  int (*xPrev)(sqlite4_kvcursor*);
         4305  +  int (*xDelete)(sqlite4_kvcursor*);
         4306  +  int (*xKey)(sqlite4_kvcursor*,
         4307  +              const unsigned char **ppKey, sqlite4_kvsize *pnKey);
         4308  +  int (*xData)(sqlite4_kvcursor*, sqlite4_kvsize ofst, sqlite4_kvsize n,
         4309  +               const unsigned char **ppData, sqlite4_kvsize *pnData);
         4310  +  int (*xReset)(sqlite4_kvcursor*);
         4311  +  int (*xCloseCursor)(sqlite4_kvcursor*);
         4312  +  int (*xBegin)(sqlite4_kvstore*, int);
         4313  +  int (*xCommitPhaseOne)(sqlite4_kvstore*, int);
         4314  +  int (*xCommitPhaseTwo)(sqlite4_kvstore*, int);
         4315  +  int (*xRollback)(sqlite4_kvstore*, int);
         4316  +  int (*xRevert)(sqlite4_kvstore*, int);
         4317  +  int (*xClose)(sqlite4_kvstore*);
         4318  +  int (*xControl)(sqlite4_kvstore*, int, void*);
         4319  +};
         4320  +typedef struct sqlite4_kv_methods sqlite4_kv_methods;
         4321  +
         4322  +/*
         4323  +** CAPI4REF: Key-value storage engine open flags
         4324  +**
         4325  +** Allowed values to the flags parameter of an sqlite4_kvstore object
         4326  +** factory.
         4327  +**
         4328  +** The flags parameter to the sqlite4_kvstore factory (the fourth parameter)
         4329  +** is an OR-ed combination of these values and the
         4330  +** [SQLITE4_OPEN_READONLY | SQLITE4_OPEN_xxxxx] flags that appear as 
         4331  +** arguments to [sqlite4_open()].
         4332  +*/
         4333  +#define SQLITE4_KVOPEN_TEMPORARY       0x00010000  /* A temporary database */
         4334  +#define SQLITE4_KVOPEN_NO_TRANSACTIONS 0x00020000  /* No transactions needed */
         4335  +
         4336  +
         4337  +/*
         4338  +** CAPI4REF: Representation Of Numbers
         4339  +**
         4340  +** Every number in SQLite is represented in memory by an instance of
         4341  +** the following object.
         4342  +*/
         4343  +typedef struct sqlite4_num sqlite4_num;
         4344  +struct sqlite4_num {
         4345  +  unsigned char sign;     /* Sign of the overall value */
         4346  +  unsigned char approx;   /* True if the value is approximate */
         4347  +  unsigned short e;       /* The exponent. */
         4348  +  sqlite4_uint64 m;       /* The significant */
         4349  +};
         4350  +
         4351  +/*
         4352  +** CAPI4REF: Operations On SQLite Number Objects
         4353  +*/
         4354  +SQLITE4_API sqlite4_num sqlite4_num_add(sqlite4_num, sqlite4_num);
         4355  +SQLITE4_API sqlite4_num sqlite4_num_sub(sqlite4_num, sqlite4_num);
         4356  +SQLITE4_API sqlite4_num sqlite4_num_mul(sqlite4_num, sqlite4_num);
         4357  +SQLITE4_API sqlite4_num sqlite4_num_div(sqlite4_num, sqlite4_num);
         4358  +SQLITE4_API int sqlite4_num_isinf(sqlite4_num);
         4359  +SQLITE4_API int sqlite4_num_isnan(sqlite4_num);
         4360  +SQLITE4_API sqlite4_num sqlite4_num_round(sqlite4_num, int iDigit);
         4361  +SQLITE4_API int sqlite4_num_compare(sqlite4_num, sqlite4_num);
         4362  +SQLITE4_API sqlite4_num sqlite4_num_from_text(const char*, int n, unsigned flags);
         4363  +SQLITE4_API sqlite4_num sqlite4_num_from_int64(sqlite4_int64);
         4364  +SQLITE4_API sqlite4_num sqlite4_num_from_double(double);
         4365  +SQLITE4_API int sqlite4_num_to_int32(sqlite4_num, int*);
         4366  +SQLITE4_API int sqlite4_num_to_int64(sqlite4_num, sqlite4_int64*);
         4367  +SQLITE4_API double sqlite4_num_to_double(sqlite4_num);
         4368  +SQLITE4_API int sqlite4_num_to_text(sqlite4_num, char*);
         4369  +
         4370  +/*
         4371  +** CAPI4REF: Flags For Text-To-Numeric Conversion
         4372  +*/
         4373  +#define SQLITE4_PREFIX_ONLY         0x10
         4374  +#define SQLITE4_IGNORE_WHITESPACE   0x20
         4375  +
         4376  +/*
         4377  +** Undo the hack that converts floating point types to integer for
         4378  +** builds on processors without floating point support.
         4379  +*/
         4380  +#ifdef SQLITE4_OMIT_FLOATING_POINT
         4381  +# undef double
         4382  +#endif
         4383  +
         4384  +#ifdef __cplusplus
         4385  +}  /* End of the 'extern "C"' block */
         4386  +#endif
         4387  +#endif
         4388  +
         4389  +/*
         4390  +** 2010 August 30
         4391  +**
         4392  +** The author disclaims copyright to this source code.  In place of
         4393  +** a legal notice, here is a blessing:
         4394  +**
         4395  +**    May you do good and not evil.
         4396  +**    May you find forgiveness for yourself and forgive others.
         4397  +**    May you share freely, never taking more than you give.
         4398  +**
         4399  +*************************************************************************
         4400  +*/
         4401  +
         4402  +#ifndef _SQLITE3RTREE_H_
         4403  +#define _SQLITE3RTREE_H_
         4404  +
         4405  +
         4406  +#ifdef __cplusplus
         4407  +extern "C" {
         4408  +#endif
         4409  +
         4410  +typedef struct sqlite4_rtree_geometry sqlite4_rtree_geometry;
         4411  +
         4412  +/*
         4413  +** Register a geometry callback named zGeom that can be used as part of an
         4414  +** R-Tree geometry query as follows:
         4415  +**
         4416  +**   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
         4417  +*/
         4418  +SQLITE4_API int sqlite4_rtree_geometry_callback(
         4419  +  sqlite4 *db,
         4420  +  const char *zGeom,
         4421  +  int (*xGeom)(sqlite4_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
         4422  +  void *pContext
         4423  +);
         4424  +
         4425  +
         4426  +/*
         4427  +** A pointer to a structure of the following type is passed as the first
         4428  +** argument to callbacks registered using rtree_geometry_callback().
         4429  +*/
         4430  +struct sqlite4_rtree_geometry {
         4431  +  void *pContext;                 /* Copy of pContext passed to s_r_g_c() */
         4432  +  int nParam;                     /* Size of array aParam[] */
         4433  +  double *aParam;                 /* Parameters passed to SQL geom function */
         4434  +  void *pUser;                    /* Callback implementation user data */
         4435  +  void (*xDelUser)(void *);       /* Called by SQLite to clean up pUser */
         4436  +};
         4437  +
         4438  +
         4439  +#ifdef __cplusplus
         4440  +}  /* end of the 'extern "C"' block */
         4441  +#endif
         4442  +
         4443  +#endif  /* ifndef _SQLITE3RTREE_H_ */
         4444  +

Changes to src/stash.c.

    80     80     blob_reset(&sql);
    81     81     db_prepare(&ins,
    82     82        "INSERT INTO stashfile(stashid, rid, isAdded, isRemoved, isExec, isLink,"
    83     83                              "origname, newname, delta)"
    84     84        "VALUES(%d,:rid,:isadd,:isrm,:isexe,:islink,:orig,:new,:content)",
    85     85        stashid
    86     86     );
    87         -  while( db_step(&q)==SQLITE_ROW ){
           87  +  while( db_step(&q)==SQLITE4_ROW ){
    88     88       int deleted = db_column_int(&q, 0);
    89     89       int rid = db_column_int(&q, 3);
    90     90       const char *zName = db_column_text(&q, 4);
    91     91       const char *zOrig = db_column_text(&q, 5);
    92     92       char *zPath = mprintf("%s%s", g.zLocalRoot, zName);
    93     93       Blob content;
    94     94       int isNewLink = file_wd_islink(zPath);
................................................................................
   183    183   static void stash_apply(int stashid, int nConflict){
   184    184     Stmt q;
   185    185     db_prepare(&q,
   186    186        "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta"
   187    187        "  FROM stashfile WHERE stashid=%d",
   188    188        stashid
   189    189     );
   190         -  while( db_step(&q)==SQLITE_ROW ){
          190  +  while( db_step(&q)==SQLITE4_ROW ){
   191    191       int rid = db_column_int(&q, 0);
   192    192       int isRemoved = db_column_int(&q, 1);
   193    193       int isExec = db_column_int(&q, 2);
   194    194       int isLink = db_column_int(&q, 3);
   195    195       const char *zOrig = db_column_text(&q, 4);
   196    196       const char *zNew = db_column_text(&q, 5);
   197    197       char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
................................................................................
   274    274     Blob empty;
   275    275     blob_zero(&empty);
   276    276     db_prepare(&q,
   277    277        "SELECT rid, isRemoved, isExec, isLink, origname, newname, delta"
   278    278        "  FROM stashfile WHERE stashid=%d",
   279    279        stashid
   280    280     );
   281         -  while( db_step(&q)==SQLITE_ROW ){
          281  +  while( db_step(&q)==SQLITE4_ROW ){
   282    282       int rid = db_column_int(&q, 0);
   283    283       int isRemoved = db_column_int(&q, 1);
   284    284       int isLink = db_column_int(&q, 3);
   285    285       const char *zOrig = db_column_text(&q, 4);
   286    286       const char *zNew = db_column_text(&q, 5);
   287    287       char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
   288    288       Blob delta;
................................................................................
   430    430       if( g.argc>=2 ){
   431    431         int nFile = db_int(0, "SELECT count(*) FROM stashfile WHERE stashid=%d",
   432    432                            stashid);
   433    433         char **newArgv = fossil_malloc( sizeof(char*)*(nFile+2) );
   434    434         int i = 2;
   435    435         Stmt q;
   436    436         db_prepare(&q,"SELECT origname FROM stashfile WHERE stashid=%d", stashid);
   437         -      while( db_step(&q)==SQLITE_ROW ){
          437  +      while( db_step(&q)==SQLITE4_ROW ){
   438    438           newArgv[i++] = mprintf("%s%s", g.zLocalRoot, db_column_text(&q, 0));
   439    439         }
   440    440         db_finalize(&q);
   441    441         newArgv[0] = g.argv[0];
   442    442         g.argv = newArgv;
   443    443         g.argc = nFile+2;
   444    444         if( nFile==0 ) return;
................................................................................
   459    459          "       comment, datetime(ctime) FROM stash"
   460    460          " ORDER BY ctime DESC"
   461    461       );
   462    462       if( fDetail ){
   463    463         db_prepare(&q2, "SELECT isAdded, isRemoved, origname, newname"
   464    464                         "  FROM stashfile WHERE stashid=$id");
   465    465       }
   466         -    while( db_step(&q)==SQLITE_ROW ){
          466  +    while( db_step(&q)==SQLITE4_ROW ){
   467    467         int stashid = db_column_int(&q, 0);
   468    468         const char *zCom;
   469    469         n++;
   470    470         fossil_print("%5d: [%.14s] on %s\n",
   471    471           stashid,
   472    472           db_column_text(&q, 1),
   473    473           db_column_text(&q, 3)
................................................................................
   475    475         zCom = db_column_text(&q, 2);
   476    476         if( zCom && zCom[0] ){
   477    477           fossil_print("       ");
   478    478           comment_print(zCom, 7, 79);
   479    479         }
   480    480         if( fDetail ){
   481    481           db_bind_int(&q2, "$id", stashid);
   482         -        while( db_step(&q2)==SQLITE_ROW ){
          482  +        while( db_step(&q2)==SQLITE4_ROW ){
   483    483             int isAdded = db_column_int(&q2, 0);
   484    484             int isRemoved = db_column_int(&q2, 1);
   485    485             const char *zOrig = db_column_text(&q2, 2);
   486    486             const char *zNew = db_column_text(&q2, 3);
   487    487             if( isAdded ){
   488    488                fossil_print("          ADD %s\n", zNew);
   489    489             }else if( isRemoved ){

Changes to src/stat.c.

    22     22   #include "config.h"
    23     23   #include "stat.h"
    24     24   
    25     25   /*
    26     26   ** For a sufficiently large integer, provide an alternative
    27     27   ** representation as MB or GB or TB.
    28     28   */
    29         -static void bigSizeName(int nOut, char *zOut, sqlite3_int64 v){
           29  +static void bigSizeName(int nOut, char *zOut, sqlite4_int64 v){
    30     30     if( v<100000 ){
    31         -    sqlite3_snprintf(nOut, zOut, "%lld bytes", v);
           31  +    sqlite4_snprintf(zOut, nOut, "%lld bytes", v);
    32     32     }else if( v<1000000000 ){
    33         -    sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fMB)",
           33  +    sqlite4_snprintf(zOut, nOut, "%lld bytes (%.1fMB)",
    34     34                       v, (double)v/1000000.0);
    35     35     }else{
    36         -    sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fGB)",
           36  +    sqlite4_snprintf(zOut, nOut, "%lld bytes (%.1fGB)",
    37     37                       v, (double)v/1000000000.0);
    38     38     }
    39     39   }
    40     40   
    41     41   /*
    42     42   ** WEBPAGE: stat
    43     43   **
................................................................................
   118    118     @ </td></tr>
   119    119     @ <tr><th>Project&nbsp;ID:</th><td>%h(db_get("project-code",""))</td></tr>
   120    120     @ <tr><th>Server&nbsp;ID:</th><td>%h(db_get("server-code",""))</td></tr>
   121    121     @ <tr><th>Fossil&nbsp;Version:</th><td>
   122    122     @ %h(RELEASE_VERSION) %h(MANIFEST_DATE) %h(MANIFEST_VERSION)
   123    123     @ (%h(COMPILER_NAME))
   124    124     @ </td></tr>
   125         -  @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(SQLITE_SOURCE_ID)
   126         -  @ [%.10s(&SQLITE_SOURCE_ID[20])] (%s(SQLITE_VERSION))</td></tr>
          125  +  @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(SQLITE4_SOURCE_ID)
          126  +  @ [%.10s(&SQLITE4_SOURCE_ID[20])] (%s(SQLITE4_VERSION))</td></tr>
   127    127     @ <tr><th>Database&nbsp;Stats:</th><td>
   128    128     zDb = db_name("repository");
   129    129     @ %d(db_int(0, "PRAGMA %s.page_count", zDb)) pages,
   130    130     @ %d(db_int(0, "PRAGMA %s.page_size", zDb)) bytes/page,
   131    131     @ %d(db_int(0, "PRAGMA %s.freelist_count", zDb)) free pages,
   132    132     @ %s(db_text(0, "PRAGMA %s.encoding", zDb)),
   133    133     @ %s(db_text(0, "PRAGMA %s.journal_mode", zDb)) mode
   134    134     @ </td></tr>
   135    135   
   136    136     @ </table>
   137    137     style_footer();
   138    138   }

Changes to src/tag.c.

    79     79     if( tagid==TAG_BGCOLOR ){
    80     80       db_prepare(&eventupdate,
    81     81         "UPDATE event SET bgcolor=%Q WHERE objid=:rid", zValue
    82     82       );
    83     83     }
    84     84     while( (pid = pqueuex_extract(&queue, 0))!=0 ){
    85     85       db_bind_int(&s, ":pid", pid);
    86         -    while( db_step(&s)==SQLITE_ROW ){
           86  +    while( db_step(&s)==SQLITE4_ROW ){
    87     87         int doit = db_column_int(&s, 2);
    88     88         if( doit ){
    89     89           int cid = db_column_int(&s, 0);
    90     90           double mtime = db_column_double(&s, 1);
    91     91           pqueuex_insert(&queue, cid, mtime, 0);
    92     92           db_bind_int(&ins, ":rid", cid);
    93     93           db_step(&ins);
................................................................................
   118    118   void tag_propagate_all(int pid){
   119    119     Stmt q;
   120    120     db_prepare(&q,
   121    121        "SELECT tagid, tagtype, mtime, value, origid FROM tagxref"
   122    122        " WHERE rid=%d",
   123    123        pid
   124    124     );
   125         -  while( db_step(&q)==SQLITE_ROW ){
          125  +  while( db_step(&q)==SQLITE4_ROW ){
   126    126       int tagid = db_column_int(&q, 0);
   127    127       int tagtype = db_column_int(&q, 1);
   128    128       double mtime = db_column_double(&q, 2);
   129    129       const char *zValue = db_column_text(&q, 3);
   130    130       int origid = db_column_int(&q, 4);
   131    131       if( tagtype==1 ) tagtype = 0;
   132    132       tag_propagate(pid, tagid, tagtype, origid, zValue, mtime);
................................................................................
   173    173       "   AND rid=%d"
   174    174       "   AND mtime>=:mtime",
   175    175       tagid, rid
   176    176     );
   177    177     db_bind_double(&s, ":mtime", mtime);
   178    178     rc = db_step(&s);
   179    179     db_finalize(&s);
   180         -  if( rc==SQLITE_ROW ){
          180  +  if( rc==SQLITE4_ROW ){
   181    181       /* Another entry that is more recent already exists.  Do nothing */
   182    182       return tagid;
   183    183     }
   184    184     db_prepare(&s, 
   185    185       "REPLACE INTO tagxref(tagid,tagtype,srcId,origid,value,mtime,rid)"
   186    186       " VALUES(%d,%d,%d,%d,%Q,:mtime,%d)",
   187    187       tagid, tagtype, srcId, rid, zValue, rid
................................................................................
   438    438         db_prepare(&q,
   439    439           "SELECT blob.uuid FROM tagxref, blob"
   440    440           " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
   441    441           "   AND tagxref.tagtype>0"
   442    442           "   AND blob.rid=tagxref.rid",
   443    443           g.argv[3]
   444    444         );
   445         -      while( db_step(&q)==SQLITE_ROW ){
          445  +      while( db_step(&q)==SQLITE4_ROW ){
   446    446           fossil_print("%s\n", db_column_text(&q, 0));
   447    447         }
   448    448         db_finalize(&q);
   449    449       }else{
   450    450         int tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",
   451    451                            g.argv[3]);
   452    452         if( tagid>0 ){
................................................................................
   472    472         db_prepare(&q, 
   473    473           "SELECT tagname FROM tag"
   474    474           " WHERE EXISTS(SELECT 1 FROM tagxref"
   475    475           "               WHERE tagid=tag.tagid"
   476    476           "                 AND tagtype>0)"
   477    477           " ORDER BY tagname"
   478    478         );
   479         -      while( db_step(&q)==SQLITE_ROW ){
          479  +      while( db_step(&q)==SQLITE4_ROW ){
   480    480           const char *zName = db_column_text(&q, 0);
   481    481           if( fRaw ){
   482    482             fossil_print("%s\n", zName);
   483    483           }else if( strncmp(zName, "sym-", 4)==0 ){
   484    484             fossil_print("%s\n", &zName[4]);
   485    485           }
   486    486         }
................................................................................
   491    491           "SELECT tagname, value FROM tagxref, tag"
   492    492           " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
   493    493           "   AND tagtype>%d"
   494    494           " ORDER BY tagname",
   495    495           rid,
   496    496           fRaw ? -1 : 0
   497    497         );
   498         -      while( db_step(&q)==SQLITE_ROW ){
          498  +      while( db_step(&q)==SQLITE4_ROW ){
   499    499           const char *zName = db_column_text(&q, 0);
   500    500           const char *zValue = db_column_text(&q, 1);
   501    501           if( fRaw==0 ){
   502    502             if( strncmp(zName, "sym-", 4)!=0 ) continue;
   503    503             zName += 4;
   504    504           }
   505    505           if( zValue && zValue[0] ){
................................................................................
   544    544       " WHERE EXISTS(SELECT 1 FROM tagxref"
   545    545       "               WHERE tagid=tag.tagid"
   546    546       "                 AND tagtype=1)"
   547    547       " AND tagname GLOB 'sym-*'"
   548    548       " ORDER BY tagname"
   549    549     );
   550    550     @ <ul>
   551         -  while( db_step(&q)==SQLITE_ROW ){
          551  +  while( db_step(&q)==SQLITE4_ROW ){
   552    552       const char *zName = db_column_text(&q, 0);
   553    553       if( g.perm.Hyperlink ){
   554    554         @ <li>%z(xhref("class='taglink'","%R/timeline?t=%T",zName))
   555    555         @ %h(zName)</a></li>
   556    556       }else{
   557    557         @ <li><span class="tagDsp">%h(zName)</span></li>
   558    558       }

Changes to src/tar.c.

    42     42   
    43     43   
    44     44   /*
    45     45   ** Begin the process of generating a tarball.
    46     46   **
    47     47   ** Initialize the GZIP compressor and the table of directory names.
    48     48   */
    49         -static void tar_begin(sqlite3_int64 mTime){
           49  +static void tar_begin(sqlite4_int64 mTime){
    50     50     assert( tball.aHdr==0 );
    51     51     tball.aHdr = fossil_malloc(512+512);
    52     52     memset(tball.aHdr, 0, 512+512);
    53     53     tball.zSpaces = (char*)&tball.aHdr[512];
    54     54     /* zPrevDir init */
    55     55     tball.zPrevDir = NULL;
    56     56     tball.nPrevDirAlloc = 0;
................................................................................
   262    262     char cType
   263    263   ){
   264    264     unsigned int cksum = 0;
   265    265     int i;
   266    266     memset(&tball.aHdr[148], ' ', 8);
   267    267     tball.aHdr[156] = cType;
   268    268     for(i=0; i<512; i++) cksum += tball.aHdr[i];
   269         -  sqlite3_snprintf(8, (char*)&tball.aHdr[148], "%07o", cksum);
          269  +  sqlite4_snprintf((char*)&tball.aHdr[148], 8, "%07o", cksum);
   270    270     tball.aHdr[155] = 0;
   271    271     gzip_step((char*)tball.aHdr, 512);
   272    272   }
   273    273   
   274    274   
   275    275   /*
   276    276   ** Build a header for a file or directory and write that header
................................................................................
   282    282     int iMode,             /* Mode.  0644 or 0755 */
   283    283     unsigned int mTime,    /* File modification time */
   284    284     int iSize,             /* Size of the object in bytes */
   285    285     char cType             /* Type of object:  
   286    286                               '0'==file. '2'==symlink. '5'==directory */
   287    287   ){
   288    288     /* set mode and modification time */
   289         -  sqlite3_snprintf(8, (char*)&tball.aHdr[100], "%07o", iMode);
   290         -  sqlite3_snprintf(12, (char*)&tball.aHdr[136], "%011o", mTime);
          289  +  sqlite4_snprintf((char*)&tball.aHdr[100], 8, "%07o", iMode);
          290  +  sqlite4_snprintf((char*)&tball.aHdr[136], 12, "%011o", mTime);
   291    291   
   292    292     /* see if we need to output a Pax Interchange Header */
   293    293     if( !is_iso646_name(zName, nName)
   294    294      || !tar_split_path(zName, nName, (char*)tball.aHdr, (char*)&tball.aHdr[345])
   295    295     ){
   296    296       int lastPage;
   297    297       /* add a file name for interoperability with older programs */
................................................................................
   299    299                              (char*)&tball.aHdr[345], 1);
   300    300   
   301    301       /* generate the Pax Interchange path header */
   302    302       blob_reset(&tball.pax);
   303    303       add_pax_header("path", zName, nName);
   304    304   
   305    305       /* set the header length, and write the header */
   306         -    sqlite3_snprintf(12, (char*)&tball.aHdr[124], "%011o",
          306  +    sqlite4_snprintf((char*)&tball.aHdr[124], 8, "%011o",
   307    307                        blob_size(&tball.pax));
   308    308       cksum_and_write_header('x');
   309    309   
   310    310       /* write the Pax Interchange data */
   311    311       gzip_step(blob_buffer(&tball.pax), blob_size(&tball.pax));
   312    312       lastPage = blob_size(&tball.pax) % 512;
   313    313       if( lastPage!=0 ){
................................................................................
   315    315       }
   316    316   
   317    317       /* generate an approximate path for the regular header */
   318    318       approximate_split_path(zName, nName, (char*)tball.aHdr,
   319    319                              (char*)&tball.aHdr[345], 0);
   320    320     }
   321    321     /* set the size */
   322         -  sqlite3_snprintf(12, (char*)&tball.aHdr[124], "%011o", iSize);
          322  +  sqlite4_snprintf((char*)&tball.aHdr[124], 12, "%011o", iSize);
   323    323   
   324    324     /* write the regular header */
   325    325     cksum_and_write_header(cType);
   326    326   }
   327    327   
   328    328   
   329    329   /*
................................................................................
   337    337   ){
   338    338     int i;
   339    339     for(i=nName-1; i>0 && zName[i]!='/'; i--){}
   340    340     if( i<=0 ) return;
   341    341     if( i < tball.nPrevDirAlloc && tball.zPrevDir[i]==0 &&
   342    342           memcmp(tball.zPrevDir, zName, i)==0 ) return;
   343    343     db_multi_exec("INSERT OR IGNORE INTO dir VALUES('%#q')", i, zName);
   344         -  if( sqlite3_changes(g.db)==0 ) return;
          344  +  if( sqlite4_changes(g.db)==0 ) return;
   345    345     tar_add_directory_of(zName, i-1, mTime);
   346    346     tar_add_header(zName, i, 0755, mTime, 0, '5');
   347    347     if( i >= tball.nPrevDirAlloc ){
   348    348       int nsize = tball.nPrevDirAlloc * 2;
   349    349       if(i+1 > nsize)
   350    350         nsize = i+1;
   351    351       tball.zPrevDir = fossil_realloc(tball.zPrevDir, nsize);
................................................................................
   377    377      * If we have a symlink, write its destination path (which is stored in
   378    378      * pContent) into header, and set content length to 0 to avoid storing path
   379    379      * as file content in the next step.  Since 'linkname' header is limited to
   380    380      * 100 bytes (-1 byte for terminating zero), if path is greater than that,
   381    381      * store symlink as a plain-text file. (Not sure how TAR handles long links.)
   382    382      */
   383    383     if( mPerm == PERM_LNK && n <= 100 ){
   384         -    sqlite3_snprintf(100, (char*)&tball.aHdr[157], "%s", blob_str(pContent));
          384  +    sqlite4_snprintf((char*)&tball.aHdr[157], 100, "%s", blob_str(pContent));
   385    385       cType = '2';
   386    386       n = 0;
   387    387     }
   388    388   
   389    389     tar_add_header(zName, nName, ( mPerm==PERM_EXE ) ? 0755 : 0644, 
   390    390                    mTime, n, cType);
   391    391     if( n ){
................................................................................
   424    424   void test_tarball_cmd(void){
   425    425     int i;
   426    426     Blob zip;
   427    427     Blob file;
   428    428     if( g.argc<3 ){
   429    429       usage("ARCHIVE FILE....");
   430    430     }
   431         -  sqlite3_open(":memory:", &g.db);
          431  +  sqlite4_open(0, ":memory:", &g.db, SQLITE4_OPEN_READWRITE);
   432    432     tar_begin(0);
   433    433     for(i=3; i<g.argc; i++){
   434    434       blob_zero(&file);
   435    435       blob_read_from_file(&file, g.argv[i]);
   436    436       tar_add_file(g.argv[i], &file,
   437    437                    file_wd_perm(g.argv[i]), file_wd_mtime(g.argv[i]));
   438    438       blob_reset(&file);

Changes to src/th.c.

  2344   2344   ** Return TRUE if z is a pure numeric string.  Return FALSE if the
  2345   2345   ** string contains any character which is not part of a number. If
  2346   2346   ** the string is numeric and contains the '.' character, set *realnum
  2347   2347   ** to TRUE (otherwise FALSE).
  2348   2348   **
  2349   2349   ** An empty string is considered non-numeric.
  2350   2350   */
  2351         -static int sqlite3IsNumber(const char *z, int *realnum){
         2351  +static int sqlite4IsNumber(const char *z, int *realnum){
  2352   2352     int incr = 1;
  2353   2353     if( *z=='-' || *z=='+' ) z += incr;
  2354   2354     if( !th_isdigit(*(u8*)z) ){
  2355   2355       return 0;
  2356   2356     }
  2357   2357     z += incr;
  2358   2358     if( realnum ) *realnum = 0;
................................................................................
  2381   2381   ** is not, the result is undefined.
  2382   2382   **
  2383   2383   ** This routine is used instead of the library atof() function because
  2384   2384   ** the library atof() might want to use "," as the decimal point instead
  2385   2385   ** of "." depending on how locale is set.  But that would cause problems
  2386   2386   ** for SQL.  So this routine always uses "." regardless of locale.
  2387   2387   */
  2388         -static int sqlite3AtoF(const char *z, double *pResult){
         2388  +static int sqlite4AtoF(const char *z, double *pResult){
  2389   2389     int sign = 1;
  2390   2390     const char *zBegin = z;
  2391   2391     LONGDOUBLE_TYPE v1 = 0.0;
  2392   2392     while( th_isspace(*(u8*)z) ) z++;
  2393   2393     if( *z=='-' ){
  2394   2394       sign = -1;
  2395   2395       z++;
................................................................................
  2484   2484   */
  2485   2485   int Th_ToDouble(
  2486   2486     Th_Interp *interp, 
  2487   2487     const char *z, 
  2488   2488     int n, 
  2489   2489     double *pfOut
  2490   2490   ){
  2491         -  if( !sqlite3IsNumber((const char *)z, 0) ){
         2491  +  if( !sqlite4IsNumber((const char *)z, 0) ){
  2492   2492       Th_ErrorMessage(interp, "expected number, got: \"", z, n);
  2493   2493       return TH_ERROR;
  2494   2494     }
  2495   2495   
  2496         -  sqlite3AtoF((const char *)z, pfOut);
         2496  +  sqlite4AtoF((const char *)z, pfOut);
  2497   2497     return TH_OK;
  2498   2498   }
  2499   2499   
  2500   2500   /*
  2501   2501   ** Set the result of the interpreter to the th1 representation of
  2502   2502   ** the integer iVal and return TH_OK.
  2503   2503   */

Changes to src/timeline.c.

   147    147       case 0:  r = mx; g = h2, b = mn;  break;
   148    148       case 1:  r = h2; g = mx, b = mn;  break;
   149    149       case 2:  r = mn; g = mx, b = h2;  break;
   150    150       case 3:  r = mn; g = h2, b = mx;  break;
   151    151       case 4:  r = h2; g = mn, b = mx;  break;
   152    152       default: r = mx; g = mn, b = h2;  break;
   153    153     }
   154         -  sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
          154  +  sqlite4_snprintf(zColor, 8, "#%02x%02x%02x", r,g,b);
   155    155     return zColor;
   156    156   }
   157    157   
   158    158   /*
   159    159   ** COMMAND:  test-hash-color
   160    160   **
   161    161   ** Usage: %fossil test-hash-color TAG ...
................................................................................
   222    222     db_static_prepare(&qbranch,
   223    223       "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=:rid",
   224    224       TAG_BRANCH
   225    225     );
   226    226   
   227    227     @ <table id="timelineTable" class="timelineTable">
   228    228     blob_zero(&comment);
   229         -  while( db_step(pQuery)==SQLITE_ROW ){
          229  +  while( db_step(pQuery)==SQLITE4_ROW ){
   230    230       int rid = db_column_int(pQuery, 0);
   231    231       const char *zUuid = db_column_text(pQuery, 1);
   232    232       int isLeaf = db_column_int(pQuery, 5);
   233    233       const char *zBgClr = db_column_text(pQuery, 6);
   234    234       const char *zDate = db_column_text(pQuery, 2);
   235    235       const char *zType = db_column_text(pQuery, 7);
   236    236       const char *zUser = db_column_text(pQuery, 4);
................................................................................
   261    261           @ <tr><td colspan="3"><hr /></td></tr>
   262    262         }
   263    263         prevWasDivider = 1;
   264    264         continue;
   265    265       }
   266    266       prevWasDivider = 0;
   267    267       if( memcmp(zDate, zPrevDate, 10) ){
   268         -      sqlite3_snprintf(sizeof(zPrevDate), zPrevDate, "%.10s", zDate);
          268  +      sqlite4_snprintf(zPrevDate, sizeof(zPrevDate), "%.10s", zDate);
   269    269         @ <tr><td>
   270    270         @   <div class="divider">%s(zPrevDate)</div>
   271    271         @ </td></tr>
   272    272       }
   273    273       memcpy(zTime, &zDate[11], 5);
   274    274       zTime[5] = 0;
   275    275       @ <tr>
................................................................................
   277    277       @ <td class="timelineGraph">
   278    278       if( tmFlags & TIMELINE_UCOLOR )  zBgClr = zUser ? hash_color(zUser) : 0;
   279    279       if( zType[0]=='c'
   280    280       && (pGraph || zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0)
   281    281       ){
   282    282         db_reset(&qbranch);   
   283    283         db_bind_int(&qbranch, ":rid", rid);
   284         -      if( db_step(&qbranch)==SQLITE_ROW ){
          284  +      if( db_step(&qbranch)==SQLITE4_ROW ){
   285    285           zBr = db_column_text(&qbranch, 0);
   286    286         }else{
   287    287           zBr = "trunk";
   288    288         }
   289    289         if( zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0 ){
   290    290           if( zBr==0 || strcmp(zBr,"trunk")==0 ){
   291    291             zBgClr = 0;
................................................................................
   301    301         static Stmt qparent;
   302    302         db_static_prepare(&qparent,
   303    303           "SELECT pid FROM plink"
   304    304           " WHERE cid=:rid AND pid NOT IN phantom"
   305    305           " ORDER BY isprim DESC /*sort*/"
   306    306         );
   307    307         db_bind_int(&qparent, ":rid", rid);
   308         -      while( db_step(&qparent)==SQLITE_ROW && nParent<32 ){
          308  +      while( db_step(&qparent)==SQLITE4_ROW && nParent<32 ){
   309    309           aParent[nParent++] = db_column_int(&qparent, 0);
   310    310         }
   311    311         db_reset(&qparent);
   312    312         gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr, isLeaf);
   313    313         db_reset(&qbranch);
   314    314         @ <div id="m%d(gidx)"></div>
   315    315       }
................................................................................
   416    416             "  FROM mlink"
   417    417             " WHERE mid=:mid AND (pid!=fid OR pfnid>0)"
   418    418             " ORDER BY 3 /*sort*/"
   419    419           );
   420    420           fchngQueryInit = 1;
   421    421         }
   422    422         db_bind_int(&fchngQuery, ":mid", rid);
   423         -      while( db_step(&fchngQuery)==SQLITE_ROW ){
          423  +      while( db_step(&fchngQuery)==SQLITE4_ROW ){
   424    424           const char *zFilename = db_column_text(&fchngQuery, 2);
   425    425           int isNew = db_column_int(&fchngQuery, 0);
   426    426           int isDel = db_column_int(&fchngQuery, 1);
   427    427           const char *zOldName = db_column_text(&fchngQuery, 5);
   428    428           const char *zOld = db_column_text(&fchngQuery, 4);
   429    429           const char *zNew = db_column_text(&fchngQuery, 3);
   430    430           if( !inUl ){
................................................................................
  1283   1283     zPrevDate[0] = 0;
  1284   1284   
  1285   1285     if( g.localOpen ){
  1286   1286       int rid = db_lget_int("checkout", 0);
  1287   1287       zCurrentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
  1288   1288     }
  1289   1289   
  1290         -  while( db_step(q)==SQLITE_ROW && nLine<=mxLine ){
         1290  +  while( db_step(q)==SQLITE4_ROW && nLine<=mxLine ){
  1291   1291       int rid = db_column_int(q, 0);
  1292   1292       const char *zId = db_column_text(q, 1);
  1293   1293       const char *zDate = db_column_text(q, 2);
  1294   1294       const char *zCom = db_column_text(q, 3);
  1295   1295       int nChild = db_column_int(q, 4);
  1296   1296       int nParent = db_column_int(q, 5);
  1297   1297       char *zFree = 0;
  1298   1298       int n = 0;
  1299   1299       char zPrefix[80];
  1300   1300       char zUuid[UUID_SIZE+1];
  1301   1301       
  1302         -    sqlite3_snprintf(sizeof(zUuid), zUuid, "%.10s", zId);
         1302  +    sqlite4_snprintf(zUuid, sizeof(zUuid), "%.10s", zId);
  1303   1303       if( memcmp(zDate, zPrevDate, 10) ){
  1304   1304         fossil_print("=== %.10s ===\n", zDate);
  1305   1305         memcpy(zPrevDate, zDate, 10);
  1306   1306         nLine++;
  1307   1307       }
  1308   1308       if( zCom==0 ) zCom = "";
  1309   1309       fossil_print("%.8s ", &zDate[11]);
  1310   1310       zPrefix[0] = 0;
  1311   1311       if( nParent>1 ){
  1312         -      sqlite3_snprintf(sizeof(zPrefix), zPrefix, "*MERGE* ");
         1312  +      sqlite4_snprintf(zPrefix, sizeof(zPrefix), "*MERGE* ");
  1313   1313         n = strlen(zPrefix);
  1314   1314       }
  1315   1315       if( nChild>1 ){
  1316   1316         const char *zBrType;
  1317   1317         if( count_nonbranch_children(rid)>1 ){
  1318   1318           zBrType = "*FORK* ";
  1319   1319         }else{
  1320   1320           zBrType = "*BRANCH* ";
  1321   1321         }
  1322         -      sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], zBrType);
         1322  +      sqlite4_snprintf(zPrefix+n, sizeof(zPrefix)-n, zBrType);
  1323   1323         n = strlen(zPrefix);
  1324   1324       }
  1325   1325       if( fossil_strcmp(zCurrentUuid,zId)==0 ){
  1326         -      sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
         1326  +      sqlite4_snprintf(zPrefix+n, sizeof(zPrefix)-n, "*CURRENT* ");
  1327   1327         n += strlen(zPrefix);
  1328   1328       }
  1329         -    zFree = sqlite3_mprintf("[%.10s] %s%s", zUuid, zPrefix, zCom);
         1329  +    zFree = sqlite4_mprintf(0, "[%.10s] %s%s", zUuid, zPrefix, zCom);
  1330   1330       nLine += comment_print(zFree, 9, 79);
  1331         -    sqlite3_free(zFree);
         1331  +    sqlite4_free(0, zFree);
  1332   1332   
  1333   1333       if(showfiles){
  1334   1334         if( !fchngQueryInit ){
  1335   1335           db_prepare(&fchngQuery, 
  1336   1336              "SELECT (pid==0) AS isnew,"
  1337   1337              "       (fid==0) AS isdel,"
  1338   1338              "       (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
................................................................................
  1341   1341              "  FROM mlink"
  1342   1342              " WHERE mid=:mid AND pid!=fid"
  1343   1343              " ORDER BY 3 /*sort*/"
  1344   1344           );
  1345   1345           fchngQueryInit = 1;
  1346   1346         }
  1347   1347         db_bind_int(&fchngQuery, ":mid", rid);
  1348         -      while( db_step(&fchngQuery)==SQLITE_ROW ){
         1348  +      while( db_step(&fchngQuery)==SQLITE4_ROW ){
  1349   1349           const char *zFilename = db_column_text(&fchngQuery, 2);
  1350   1350           int isNew = db_column_int(&fchngQuery, 0);
  1351   1351           int isDel = db_column_int(&fchngQuery, 1);
  1352   1352           if( isNew ){    
  1353   1353             fossil_print("   ADDED %s\n",zFilename);
  1354   1354           }else if( isDel ){
  1355   1355             fossil_print("   DELETED %s\n",zFilename);
................................................................................
  1581   1581     db_prepare(&q,
  1582   1582        "SELECT (SELECT uuid FROM blob WHERE rid=p.cid),"
  1583   1583        "       (SELECT uuid FROM blob WHERE rid=c.cid),"
  1584   1584        "       datetime(p.mtime), datetime(c.mtime)"
  1585   1585        "  FROM plink p, plink c"
  1586   1586        " WHERE p.cid=c.pid  AND p.mtime>c.mtime"
  1587   1587     );
  1588         -  while( db_step(&q)==SQLITE_ROW ){
         1588  +  while( db_step(&q)==SQLITE4_ROW ){
  1589   1589       if( !showDetail ){
  1590   1590         fossil_print("%s\n", db_column_text(&q, 1));
  1591   1591       }else{
  1592   1592         fossil_print("%.14s -> %.14s   %s -> %s\n",
  1593   1593            db_column_text(&q, 0),
  1594   1594            db_column_text(&q, 1),
  1595   1595            db_column_text(&q, 2),
................................................................................
  1611   1611     @ <ul>
  1612   1612     db_prepare(&q,
  1613   1613        "SELECT blob.uuid "
  1614   1614        "  FROM plink p, plink c, blob"
  1615   1615        " WHERE p.cid=c.pid  AND p.mtime>c.mtime"
  1616   1616        "   AND blob.rid=c.cid"
  1617   1617     );
  1618         -  while( db_step(&q)==SQLITE_ROW ){
         1618  +  while( db_step(&q)==SQLITE4_ROW ){
  1619   1619       const char *zUuid = db_column_text(&q, 0);
  1620   1620       @ <li>
  1621   1621       @ <a href="%s(g.zTop)/timeline?p=%S(zUuid)&d=%S(zUuid)">%S(zUuid)</a>
  1622   1622     }
  1623   1623     db_finalize(&q);
  1624   1624     style_footer();
  1625   1625   }

Changes to src/tkt.c.

    47     47   ** all the values there to zero.
    48     48   */
    49     49   static void getAllTicketFields(void){
    50     50     Stmt q;
    51     51     int i;
    52     52     if( nField>0 ) return;
    53     53     db_prepare(&q, "PRAGMA table_info(ticket)");
    54         -  while( db_step(&q)==SQLITE_ROW ){
           54  +  while( db_step(&q)==SQLITE4_ROW ){
    55     55       const char *zField = db_column_text(&q, 1);
    56     56       if( strncmp(zField,"tkt_",4)==0 ) continue;
    57     57       if( nField%10==0 ){
    58     58         azField = fossil_realloc(azField, sizeof(azField)*3*(nField+10) );
    59     59       }
    60     60       azField[nField] = mprintf("%s", zField);
    61     61       nField++;
................................................................................
   101    101     const char *zName;
   102    102     Stmt q;
   103    103     int i, n, size, j;
   104    104   
   105    105     zName = PD("name","-none-");
   106    106     db_prepare(&q, "SELECT datetime(tkt_mtime,'localtime') AS tkt_datetime, *"
   107    107                    "  FROM ticket WHERE tkt_uuid GLOB '%q*'", zName);
   108         -  if( db_step(&q)==SQLITE_ROW ){
          108  +  if( db_step(&q)==SQLITE4_ROW ){
   109    109       n = db_column_count(&q);
   110    110       for(i=0; i<n; i++){
   111    111         const char *zVal = db_column_text(&q, i);
   112    112         const char *zName = db_column_name(&q, i);
   113    113         char *zRevealed = 0;
   114    114         if( zVal==0 ){
   115    115           zVal = "";
................................................................................
   129    129       }
   130    130     }else{
   131    131       db_finalize(&q);
   132    132       db_prepare(&q, "PRAGMA table_info(ticket)");
   133    133       if( Th_Fetch("tkt_uuid",&size)==0 ){
   134    134         Th_Store("tkt_uuid",zName);
   135    135       }
   136         -    while( db_step(&q)==SQLITE_ROW ){
          136  +    while( db_step(&q)==SQLITE4_ROW ){
   137    137         const char *zField = db_column_text(&q, 1);
   138    138         if( Th_Fetch(zField, &size)==0 ){
   139    139           Th_Store(zField, "");
   140    140         }
   141    141       }
   142    142       if( Th_Fetch("tkt_datetime",&size)==0 ){
   143    143         Th_Store("tkt_datetime","");
................................................................................
   218    218     int createFlag = 1;
   219    219   
   220    220     fossil_free(zTag);  
   221    221     db_multi_exec(
   222    222        "DELETE FROM ticket WHERE tkt_uuid=%Q", zTktUuid
   223    223     );
   224    224     db_prepare(&q, "SELECT rid FROM tagxref WHERE tagid=%d ORDER BY mtime",tagid);
   225         -  while( db_step(&q)==SQLITE_ROW ){
          225  +  while( db_step(&q)==SQLITE4_ROW ){
   226    226       int rid = db_column_int(&q, 0);
   227    227       pTicket = manifest_get(rid, CFTYPE_TICKET);
   228    228       if( pTicket ){
   229    229         ticket_insert(pTicket, createFlag, rid);
   230    230         manifest_ticket_event(rid, pTicket, createFlag, tagid);
   231    231         manifest_destroy(pTicket);
   232    232       }
................................................................................
   274    274   ** Repopulate the ticket table
   275    275   */
   276    276   void ticket_rebuild(void){
   277    277     Stmt q;
   278    278     ticket_create_table(1);
   279    279     db_begin_transaction();
   280    280     db_prepare(&q,"SELECT tagname FROM tag WHERE tagname GLOB 'tkt-*'");
   281         -  while( db_step(&q)==SQLITE_ROW ){
          281  +  while( db_step(&q)==SQLITE4_ROW ){
   282    282       const char *zName = db_column_text(&q, 0);
   283    283       int len;
   284    284       zName += 4;
   285    285       len = strlen(zName);
   286    286       if( len<20 || !validate16(zName, len) ) continue;
   287    287       ticket_rebuild_entry(zName);
   288    288     }
................................................................................
   341    341       Stmt q;
   342    342       db_prepare(&q,
   343    343          "SELECT datetime(mtime,'localtime'), filename, user"
   344    344          "  FROM attachment"
   345    345          " WHERE isLatest AND src!='' AND target=%Q"
   346    346          " ORDER BY mtime DESC",
   347    347          zFullName);
   348         -    while( db_step(&q)==SQLITE_ROW ){
          348  +    while( db_step(&q)==SQLITE4_ROW ){
   349    349         const char *zDate = db_column_text(&q, 0);
   350    350         const char *zFile = db_column_text(&q, 1);
   351    351         const char *zUser = db_column_text(&q, 2);
   352    352         if( cnt==0 ){
   353    353           @ <hr /><h2>Attachments:</h2>
   354    354           @ <ul>
   355    355         }
................................................................................
   623    623   ** be well-formed.  If everything is OK, return NULL.  If something is
   624    624   ** amiss, then return a pointer to a string (obtained from malloc) that
   625    625   ** describes the problem.
   626    626   */
   627    627   char *ticket_schema_check(const char *zSchema){
   628    628     char *zErr = 0;
   629    629     int rc;
   630         -  sqlite3 *db;
   631         -  rc = sqlite3_open(":memory:", &db);
   632         -  if( rc==SQLITE_OK ){
   633         -    rc = sqlite3_exec(db, zSchema, 0, 0, &zErr);
   634         -    if( rc!=SQLITE_OK ){
   635         -      sqlite3_close(db);
          630  +  sqlite4 *db;
          631  +  rc = sqlite4_open(0, ":memory:", &db, SQLITE4_OPEN_READWRITE);
          632  +  if( rc==SQLITE4_OK ){
          633  +    rc = sqlite4_exec(db, zSchema, 0, 0, &zErr);
          634  +    if( rc!=SQLITE4_OK ){
          635  +      sqlite4_close(db);
   636    636         return zErr;
   637    637       }
   638         -    rc = sqlite3_exec(db, "SELECT tkt_id, tkt_uuid, tkt_mtime FROM ticket",
          638  +    rc = sqlite4_exec(db, "SELECT tkt_id, tkt_uuid, tkt_mtime FROM ticket",
   639    639                         0, 0, 0);
   640         -    sqlite3_close(db);
   641         -    if( rc!=SQLITE_OK ){
          640  +    sqlite4_close(db);
          641  +    if( rc!=SQLITE4_OK ){
   642    642         zErr = mprintf("schema fails to define a valid ticket table "
   643    643                        "containing all required fields");
   644    644         return zErr;
   645    645       }
   646    646     }
   647    647     return 0;
   648    648   }
................................................................................
   682    682       zTitle = mprintf("Check-Ins Associated With Ticket %h", zUuid);
   683    683     }else{
   684    684       zTitle = mprintf("Timeline Of Ticket %h", zUuid);
   685    685     }
   686    686     style_header(zTitle);
   687    687     free(zTitle);
   688    688   
   689         -  sqlite3_snprintf(6, zGlobPattern, "%s", zUuid);
          689  +  sqlite4_snprintf(zGlobPattern, 6, "%s", zUuid);
   690    690     canonical16(zGlobPattern, strlen(zGlobPattern));
   691    691     tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname GLOB 'tkt-%q*'",zUuid);
   692    692     if( tagid==0 ){
   693    693       @ No such ticket: %h(zUuid)
   694    694       style_footer();
   695    695       return;
   696    696     }
................................................................................
   765    765       "SELECT datetime(mtime,'localtime'), attachid, uuid, src, filename, user"
   766    766       "  FROM attachment, blob"
   767    767       " WHERE target=(SELECT substr(tagname,5) FROM tag WHERE tagid=%d)"
   768    768       "   AND blob.rid=attachid"
   769    769       " ORDER BY 1 DESC",
   770    770       tagid, tagid
   771    771     );
   772         -  while( db_step(&q)==SQLITE_ROW ){
          772  +  while( db_step(&q)==SQLITE4_ROW ){
   773    773       Manifest *pTicket;
   774    774       char zShort[12];
   775    775       const char *zDate = db_column_text(&q, 0);
   776    776       int rid = db_column_int(&q, 1);
   777    777       const char *zChngUuid = db_column_text(&q, 2);
   778    778       const char *zFile = db_column_text(&q, 4);
   779    779       memcpy(zShort, zChngUuid, 10);
................................................................................
  1040   1040               "SELECT datetime(mtime,'localtime'), attachid, uuid, src, filename, user"
  1041   1041               "  FROM attachment, blob"
  1042   1042               " WHERE target=(SELECT substr(tagname,5) FROM tag WHERE tagid=%d)"
  1043   1043               "   AND blob.rid=attachid"
  1044   1044               " ORDER BY 1 DESC",
  1045   1045               tagid, tagid
  1046   1046             );
  1047         -          while( db_step(&q)==SQLITE_ROW ){
         1047  +          while( db_step(&q)==SQLITE4_ROW ){
  1048   1048               Manifest *pTicket;
  1049   1049               char zShort[12];
  1050   1050               const char *zDate = db_column_text(&q, 0);
  1051   1051               int rid = db_column_int(&q, 1);
  1052   1052               const char *zChngUuid = db_column_text(&q, 2);
  1053   1053               const char *zFile = db_column_text(&q, 4);
  1054   1054               memcpy(zShort, zChngUuid, 10);

Changes to src/undo.c.

    32     32     Stmt q;
    33     33     char *zFullname;
    34     34     db_prepare(&q,
    35     35       "SELECT content, existsflag, isExe, isLink FROM undo"
    36     36       " WHERE pathname=%Q AND redoflag=%d",
    37     37        zPathname, redoFlag
    38     38     );
    39         -  if( db_step(&q)==SQLITE_ROW ){
           39  +  if( db_step(&q)==SQLITE4_ROW ){
    40     40       int old_exists;
    41     41       int new_exists;
    42     42       int old_exe;
    43     43       int new_exe;
    44     44       int new_link;
    45     45       int old_link;
    46     46       Blob current;
................................................................................
   112    112     Stmt q;
   113    113     db_prepare(&q,
   114    114        "SELECT pathname FROM undo"
   115    115        " WHERE redoflag=%d"
   116    116        " ORDER BY rowid",
   117    117        redoFlag
   118    118     );
   119         -  while( db_step(&q)==SQLITE_ROW ){
          119  +  while( db_step(&q)==SQLITE4_ROW ){
   120    120       const char *zPathname = db_column_text(&q, 0);
   121    121       undo_one(zPathname, redoFlag);
   122    122     }
   123    123     db_finalize(&q);
   124    124   }
   125    125   
   126    126   /*
................................................................................
   397    397         zCmd = undo_available==1 ? "undo" : "redo";
   398    398         fossil_print("A %s is available for the following command:\n\n"
   399    399                      "   %s %s\n\n",
   400    400                      zCmd, g.argv[0], db_lget("undo_cmdline", "???"));
   401    401         db_prepare(&q,
   402    402           "SELECT existsflag, pathname FROM undo ORDER BY pathname"
   403    403         );
   404         -      while( db_step(&q)==SQLITE_ROW ){
          404  +      while( db_step(&q)==SQLITE4_ROW ){
   405    405           if( nChng==0 ){
   406    406             fossil_print("The following file changes would occur if the "
   407    407                          "command above is %sne:\n\n", zCmd);
   408    408           }
   409    409           nChng++;
   410    410           fossil_print("%s %s\n", 
   411    411              db_column_int(&q,0) ? "UPDATE" : "DELETE",

Changes to src/update.c.

   280    280   
   281    281   
   282    282     if( debugFlag ){
   283    283       db_prepare(&q,
   284    284          "SELECT rowid, fn, fnt, chnged, ridv, ridt, isexe,"
   285    285          "       islinkv, islinkt FROM fv"
   286    286       );
   287         -    while( db_step(&q)==SQLITE_ROW ){
          287  +    while( db_step(&q)==SQLITE4_ROW ){
   288    288          fossil_print("%3d: ridv=%-4d ridt=%-4d chnged=%d isexe=%d"
   289    289                       " islinkv=%d  islinkt=%d\n",
   290    290             db_column_int(&q, 0),
   291    291             db_column_int(&q, 4),
   292    292             db_column_int(&q, 5),
   293    293             db_column_int(&q, 3),
   294    294             db_column_int(&q, 6),
................................................................................
   343    343     db_prepare(&mtimeXfer,
   344    344       "UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)"
   345    345       " WHERE id=:idt"
   346    346     );
   347    347     assert( g.zLocalRoot!=0 );
   348    348     assert( strlen(g.zLocalRoot)>1 );
   349    349     assert( g.zLocalRoot[strlen(g.zLocalRoot)-1]=='/' );
   350         -  while( db_step(&q)==SQLITE_ROW ){
          350  +  while( db_step(&q)==SQLITE4_ROW ){
   351    351       const char *zName = db_column_text(&q, 0);  /* The filename from root */
   352    352       int idv = db_column_int(&q, 1);             /* VFILE entry for current */
   353    353       int ridv = db_column_int(&q, 2);            /* RecordID for current */
   354    354       int idt = db_column_int(&q, 3);             /* VFILE entry for target */
   355    355       int ridt = db_column_int(&q, 4);            /* RecordID for target */
   356    356       int chnged = db_column_int(&q, 5);          /* Current is edited */
   357    357       const char *zNewName = db_column_text(&q,6);/* New filename */
................................................................................
   469    469     /* Report on conflicts
   470    470     */
   471    471     if( !nochangeFlag ){
   472    472       Stmt q;
   473    473       int nMerge = 0;
   474    474       db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
   475    475                      " WHERE id<=0");
   476         -    while( db_step(&q)==SQLITE_ROW ){
          476  +    while( db_step(&q)==SQLITE4_ROW ){
   477    477         const char *zLabel = "merge";
   478    478         switch( db_column_int(&q, 1) ){
   479    479           case -1:  zLabel = "cherrypick merge"; break;
   480    480           case -2:  zLabel = "backout merge";    break;
   481    481         }
   482    482         fossil_warning("uncommitted %s against %S.",
   483    483                        zLabel, db_column_text(&q, 0));
................................................................................
   693    693     }
   694    694     blob_zero(&record);
   695    695     db_prepare(&q, "SELECT name FROM torevert");
   696    696     if( zRevision==0 ){
   697    697       int vid = db_lget_int("checkout", 0);
   698    698       zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
   699    699     }
   700         -  while( db_step(&q)==SQLITE_ROW ){
          700  +  while( db_step(&q)==SQLITE4_ROW ){
   701    701       int isExe = 0;
   702    702       int isLink = 0;
   703    703       char *zFull;
   704    704       zFile = db_column_text(&q, 0);
   705    705       zFull = mprintf("%/%/", g.zLocalRoot, zFile);
   706    706       errCode = historical_version_of_file(zRevision, zFile, &record,
   707    707                                            &isLink, &isExe,2);
................................................................................
   711    711         }else{
   712    712           undo_save(zFile);
   713    713           file_delete(zFull);
   714    714           fossil_print("DELETE: %s\n", zFile);
   715    715         }
   716    716         db_multi_exec("DELETE FROM vfile WHERE pathname=%Q", zFile);
   717    717       }else{
   718         -      sqlite3_int64 mtime;
          718  +      sqlite4_int64 mtime;
   719    719         undo_save(zFile);
   720    720         if( file_wd_size(zFull)>=0 && (isLink || file_wd_islink(zFull)) ){
   721    721           file_delete(zFull);
   722    722         }
   723    723         if( isLink ){
   724    724           symlink_create(blob_str(&record), zFull);
   725    725         }else{

Changes to src/user.c.

   224    224         }else{
   225    225           db_set("default-user", g.argv[3], 0);
   226    226         }
   227    227       }
   228    228     }else if( n>=2 && strncmp(g.argv[2],"list",n)==0 ){
   229    229       Stmt q;
   230    230       db_prepare(&q, "SELECT login, info FROM user ORDER BY login");
   231         -    while( db_step(&q)==SQLITE_ROW ){
          231  +    while( db_step(&q)==SQLITE4_ROW ){
   232    232         fossil_print("%-12s %s\n", db_column_text(&q, 0), db_column_text(&q, 1));
   233    233       }
   234    234       db_finalize(&q);
   235    235     }else if( n>=2 && strncmp(g.argv[2],"password",2)==0 ){
   236    236       char *zPrompt;
   237    237       int uid;
   238    238       Blob pw;
................................................................................
   328    328   
   329    329     if( attempt_user(fossil_getenv("USER")) ) return;
   330    330   
   331    331     db_prepare(&s,
   332    332       "SELECT uid, login FROM user"
   333    333       " WHERE login NOT IN ('anonymous','nobody','reader','developer')"
   334    334     );
   335         -  if( db_step(&s)==SQLITE_ROW ){
          335  +  if( db_step(&s)==SQLITE4_ROW ){
   336    336       g.userUid = db_column_int(&s, 0);
   337    337       g.zLogin = mprintf("%s", db_column_text(&s, 1));
   338    338     }
   339    339     db_finalize(&s);
   340    340   
   341    341     if( g.userUid==0 ){
   342    342       db_prepare(&s, "SELECT uid, login FROM user");
   343         -    if( db_step(&s)==SQLITE_ROW ){
          343  +    if( db_step(&s)==SQLITE4_ROW ){
   344    344         g.userUid = db_column_int(&s, 0);
   345    345         g.zLogin = mprintf("%s", db_column_text(&s, 1));
   346    346       }
   347    347       db_finalize(&s);
   348    348     }
   349    349   
   350    350     if( g.userUid==0 ){
................................................................................
   366    366   ** Convert all local password storage to use a SHA1 hash of the password
   367    367   ** rather than cleartext.  Passwords that are already stored as the SHA1
   368    368   ** has are unchanged.
   369    369   */
   370    370   void user_hash_passwords_cmd(void){
   371    371     if( g.argc!=3 ) usage("REPOSITORY");
   372    372     db_open_repository(g.argv[2]);
   373         -  sqlite3_create_function(g.db, "shared_secret", 2, SQLITE_UTF8, 0,
          373  +  sqlite4_create_function(g.db, "shared_secret", 2, SQLITE4_UTF8, 0,
   374    374                             sha1_shared_secret_sql_function, 0, 0);
   375    375     db_multi_exec(
   376    376       "UPDATE user SET pw=shared_secret(pw,login), mtime=now()"
   377    377       " WHERE length(pw)>0 AND length(pw)!=40"
   378    378     );
   379    379   }
   380    380   
................................................................................
   437    437                 "%s/access_log?o=%d&n=%d&y=%d", g.zTop, skip>=n ? skip-n : 0,
   438    438                 n, y);
   439    439     }
   440    440     rc = db_prepare_ignore_error(&q, blob_str(&sql));
   441    441     @ <center><table border="1" cellpadding="5">
   442    442     @ <tr><th width="33%%">Date</th><th width="34%%">User</th>
   443    443     @ <th width="33%%">IP Address</th></tr>
   444         -  while( rc==SQLITE_OK && db_step(&q)==SQLITE_ROW ){
          444  +  while( rc==SQLITE4_OK && db_step(&q)==SQLITE4_ROW ){
   445    445       const char *zName = db_column_text(&q, 0);
   446    446       const char *zIP = db_column_text(&q, 1);
   447    447       const char *zDate = db_column_text(&q, 2);
   448    448       int bSuccess = db_column_int(&q, 3);
   449    449       cnt++;
   450    450       if( cnt>n ){
   451    451         style_submenu_element("Older", "Older entries",

Changes to src/verify.c.

   116    116   ** Verify all records in the repository.
   117    117   */
   118    118   void verify_all_cmd(void){
   119    119     Stmt q;
   120    120     int cnt = 0;
   121    121     db_must_be_within_tree();
   122    122     db_prepare(&q, "SELECT rid FROM blob");
   123         -  while( db_step(&q)==SQLITE_ROW ){
          123  +  while( db_step(&q)==SQLITE4_ROW ){
   124    124       int rid = db_column_int(&q, 0);
   125    125       verify_before_commit(rid);
   126    126       cnt++;
   127    127       assert( bag_count(&toVerify)==cnt );
   128    128     }
   129    129     db_finalize(&q);
   130    130     verify_at_commit();
   131    131     assert( bag_count(&toVerify)==0 );
   132    132   }

Changes to src/vfile.c.

    32     32   ** Find its rid.
    33     33   */
    34     34   int fast_uuid_to_rid(const char *zUuid){
    35     35     static Stmt q;
    36     36     int rid;
    37     37     db_static_prepare(&q, "SELECT rid FROM blob WHERE uuid=:uuid");
    38     38     db_bind_text(&q, ":uuid", zUuid);
    39         -  if( db_step(&q)==SQLITE_ROW ){
           39  +  if( db_step(&q)==SQLITE4_ROW ){
    40     40       rid = db_column_int(&q, 0);
    41     41     }else{
    42     42       rid = 0;
    43     43     }
    44     44     db_reset(&q);
    45     45     return rid;
    46     46   }
................................................................................
    88     88     }
    89     89   
    90     90     db_begin_transaction();
    91     91     p = manifest_get(vid, CFTYPE_MANIFEST);
    92     92     if( p==0 ) return;
    93     93     db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid);
    94     94     db_prepare(&ins,
    95         -    "INSERT INTO vfile(vid,isexe,islink,rid,mrid,pathname) "
    96         -    " VALUES(:vid,:isexe,:islink,:id,:id,:name)");
           95  +    "INSERT INTO vfile(id,vid,isexe,islink,rid,mrid,pathname) "
           96  +    " VALUES(1+(SELECT coalesce(max(id),0) FROM vfile),"
           97  +            ":vid,:isexe,:islink,:id,:id,:name)");
    97     98     db_prepare(&ridq, "SELECT rid,size FROM blob WHERE uuid=:uuid");
    98     99     db_bind_int(&ins, ":vid", vid);
    99    100     manifest_file_rewind(p);
   100    101     while( (pFile = manifest_file_next(p,0))!=0 ){
   101    102       if( pFile->zUuid==0 || uuid_is_shunned(pFile->zUuid) ) continue;
   102    103       db_bind_text(&ridq, ":uuid", pFile->zUuid);
   103         -    if( db_step(&ridq)==SQLITE_ROW ){
          104  +    if( db_step(&ridq)==SQLITE4_ROW ){
   104    105         rid = db_column_int(&ridq, 0);
   105    106         size = db_column_int(&ridq, 0);
   106    107       }else{
   107    108         rid = 0;
   108    109         size = 0;
   109    110       }
   110    111       db_reset(&ridq);
................................................................................
   158    159     int useMtime = useSha1sum==0 && db_get_boolean("mtime-changes", 1);
   159    160   
   160    161     db_begin_transaction();
   161    162     db_prepare(&q, "SELECT id, %Q || pathname,"
   162    163                    "       vfile.mrid, deleted, chnged, uuid, size, mtime"
   163    164                    "  FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
   164    165                    " WHERE vid=%d ", g.zLocalRoot, vid);
   165         -  while( db_step(&q)==SQLITE_ROW ){
          166  +  while( db_step(&q)==SQLITE4_ROW ){
   166    167       int id, rid, isDeleted;
   167    168       const char *zName;
   168    169       int chnged = 0;
   169    170       int oldChnged;
   170    171       i64 oldMtime;
   171    172       i64 currentMtime;
   172    173       i64 origSize;
................................................................................
   257    258     }else{
   258    259       assert( vid==0 && id>0 );
   259    260       db_prepare(&q, "SELECT id, %Q || pathname, mrid, isexe, islink"
   260    261                      "  FROM vfile"
   261    262                      " WHERE id=%d AND mrid>0",
   262    263                      g.zLocalRoot, id);
   263    264     }
   264         -  while( db_step(&q)==SQLITE_ROW ){
          265  +  while( db_step(&q)==SQLITE4_ROW ){
   265    266       int id, rid, isExe, isLink;
   266    267       const char *zName;
   267    268   
   268    269       id = db_column_int(&q, 0);
   269    270       zName = db_column_text(&q, 1);
   270    271       rid = db_column_int(&q, 2);
   271    272       isExe = db_column_int(&q, 3);
................................................................................
   322    323   /*
   323    324   ** Delete from the disk every file in VFILE vid.
   324    325   */
   325    326   void vfile_unlink(int vid){
   326    327     Stmt q;
   327    328     db_prepare(&q, "SELECT %Q || pathname FROM vfile"
   328    329                    " WHERE vid=%d AND mrid>0", g.zLocalRoot, vid);
   329         -  while( db_step(&q)==SQLITE_ROW ){
          330  +  while( db_step(&q)==SQLITE4_ROW ){
   330    331       const char *zName;
   331    332   
   332    333       zName = db_column_text(&q, 0);
   333    334       file_delete(zName);
   334    335     }
   335    336     db_finalize(&q);
   336    337     db_multi_exec("UPDATE vfile SET mtime=NULL WHERE vid=%d AND mrid>0", vid);
................................................................................
   478    479         "SELECT %Q || pathname, pathname, origname, is_selected(id), rid"
   479    480         "  FROM vfile"
   480    481         " WHERE (NOT deleted OR NOT is_selected(id)) AND vid=%d"
   481    482         " ORDER BY if_selected(id, pathname, origname) /*scan*/",
   482    483         g.zLocalRoot, vid
   483    484     );
   484    485     md5sum_init();
   485         -  while( db_step(&q)==SQLITE_ROW ){
          486  +  while( db_step(&q)==SQLITE4_ROW ){
   486    487       const char *zFullpath = db_column_text(&q, 0);
   487    488       const char *zName = db_column_text(&q, 1);
   488    489       int isSelected = db_column_int(&q, 3);
   489    490   
   490    491       if( isSelected ){
   491    492         md5sum_step_text(zName, -1);
   492    493         if( file_wd_islink(zFullpath) ){
   493    494           /* Instead of file content, use link destination path */
   494    495           Blob pathBuf;
   495    496   
   496         -        sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n", 
          497  +        sqlite4_snprintf(zBuf, sizeof(zBuf), " %ld\n", 
   497    498                            blob_read_link(&pathBuf, zFullpath));
   498    499           md5sum_step_text(zBuf, -1);
   499    500           md5sum_step_text(blob_str(&pathBuf), -1);
   500    501           blob_reset(&pathBuf);
   501    502         }else{
   502    503           in = fossil_fopen(zFullpath,"rb");
   503    504           if( in==0 ){
   504    505             md5sum_step_text(" 0\n", -1);
   505    506             continue;
   506    507           }
   507    508           fseek(in, 0L, SEEK_END);
   508         -        sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n", ftell(in));
          509  +        sqlite4_snprintf(zBuf, sizeof(zBuf), " %ld\n", ftell(in));
   509    510           fseek(in, 0L, SEEK_SET);
   510    511           md5sum_step_text(zBuf, -1);
   511    512           /*printf("%s %s %s",md5sum_current_state(),zName,zBuf); fflush(stdout);*/
   512    513           for(;;){
   513    514             int n;
   514    515             n = fread(zBuf, 1, sizeof(zBuf), in);
   515    516             if( n<=0 ) break;
................................................................................
   524    525         Blob file;
   525    526   
   526    527         if( zOrigName ) zName = zOrigName;
   527    528         if( rid>0 ){
   528    529           md5sum_step_text(zName, -1);
   529    530           blob_zero(&file);
   530    531           content_get(rid, &file);
   531         -        sqlite3_snprintf(sizeof(zBuf), zBuf, " %d\n", blob_size(&file));
          532  +        sqlite4_snprintf(zBuf, sizeof(zBuf), " %d\n", blob_size(&file));
   532    533           md5sum_step_text(zBuf, -1);
   533    534           md5sum_step_blob(&file);
   534    535           blob_reset(&file);
   535    536         }
   536    537       }
   537    538     }
   538    539     db_finalize(&q);
................................................................................
   539    540     md5sum_finish(pOut);
   540    541   }
   541    542   
   542    543   /*
   543    544   ** Write a BLOB into a random filename.  Return the name of the file.
   544    545   */
   545    546   static char *write_blob_to_temp_file(Blob *pBlob){
   546         -  sqlite3_uint64 r;
          547  +  sqlite4_uint64 r;
   547    548     char *zOut = 0;
   548    549     do{
   549         -    sqlite3_free(zOut);
   550         -    sqlite3_randomness(8, &r);
   551         -    zOut = sqlite3_mprintf("file-%08llx", r);
          550  +    sqlite4_free(0, zOut);
          551  +    sqlite4_randomness(0, 8, &r);
          552  +    zOut = sqlite4_mprintf(0, "file-%08llx", r);
   552    553     }while( file_size(zOut)>=0 );
   553    554     blob_write_to_file(pBlob, zOut);
   554    555     return zOut;
   555    556   }
   556    557   
   557    558   /*
   558    559   ** Do a file-by-file comparison of the content of the repository and
................................................................................
   568    569     db_prepare(&q, 
   569    570         "SELECT %Q || pathname, pathname, rid FROM vfile"
   570    571         " WHERE NOT deleted AND vid=%d AND is_selected(id)"
   571    572         " ORDER BY if_selected(id, pathname, origname) /*scan*/",
   572    573         g.zLocalRoot, vid
   573    574     );
   574    575     md5sum_init();
   575         -  while( db_step(&q)==SQLITE_ROW ){
          576  +  while( db_step(&q)==SQLITE4_ROW ){
   576    577       const char *zFullpath = db_column_text(&q, 0);
   577    578       const char *zName = db_column_text(&q, 1);
   578    579       int rid = db_column_int(&q, 2);
   579    580   
   580    581       blob_zero(&disk);
   581    582       if( file_wd_islink(zFullpath) ){
   582    583         rc = blob_read_link(&disk, zFullpath);
................................................................................
   592    593       content_get(rid, &repo);
   593    594       if( blob_size(&repo)!=blob_size(&disk) ){
   594    595         fossil_print("ERROR: [%s] is %d bytes on disk but %d in the repository\n",
   595    596                zName, blob_size(&disk), blob_size(&repo));
   596    597         zOut = write_blob_to_temp_file(&repo);
   597    598         fossil_print("NOTICE: Repository version of [%s] stored in [%s]\n",
   598    599                      zName, zOut);
   599         -      sqlite3_free(zOut);
          600  +      sqlite4_free(0, zOut);
   600    601         blob_reset(&disk);
   601    602         blob_reset(&repo);
   602    603         continue;
   603    604       }
   604    605       if( blob_compare(&repo, &disk) ){
   605    606         fossil_print(
   606    607             "ERROR: [%s] is different on disk compared to the repository\n",
   607    608             zName);
   608    609         zOut = write_blob_to_temp_file(&repo);
   609    610         fossil_print("NOTICE: Repository version of [%s] stored in [%s]\n",
   610    611             zName, zOut);
   611         -      sqlite3_free(zOut);
          612  +      sqlite4_free(0, zOut);
   612    613       }
   613    614       blob_reset(&disk);
   614    615       blob_reset(&repo);
   615    616     }
   616    617     db_finalize(&q);
   617    618   }
   618    619   
................................................................................
   634    635                    " FROM vfile"
   635    636                    " WHERE (NOT deleted OR NOT is_selected(id))"
   636    637                    "   AND rid>0 AND vid=%d"
   637    638                    " ORDER BY if_selected(id,pathname,origname) /*scan*/",
   638    639                    vid);
   639    640     blob_zero(&file);
   640    641     md5sum_init();
   641         -  while( db_step(&q)==SQLITE_ROW ){
          642  +  while( db_step(&q)==SQLITE4_ROW ){
   642    643       const char *zName = db_column_text(&q, 0);
   643    644       const char *zOrigName = db_column_text(&q, 1);
   644    645       int rid = db_column_int(&q, 2);
   645    646       int isSelected = db_column_int(&q, 3);
   646    647       if( zOrigName && !isSelected ) zName = zOrigName;
   647    648       md5sum_step_text(zName, -1);
   648    649       content_get(rid, &file);
   649         -    sqlite3_snprintf(sizeof(zBuf), zBuf, " %d\n", blob_size(&file));
          650  +    sqlite4_snprintf(zBuf, sizeof(zBuf), " %d\n", blob_size(&file));
   650    651       md5sum_step_text(zBuf, -1);
   651    652       /*printf("%s %s %s",md5sum_current_state(),zName,zBuf); fflush(stdout);*/
   652    653       md5sum_step_blob(&file);
   653    654       blob_reset(&file);
   654    655     }
   655    656     db_finalize(&q);
   656    657     md5sum_finish(pOut);
................................................................................
   687    688     }
   688    689     manifest_file_rewind(pManifest);
   689    690     while( (pFile = manifest_file_next(pManifest,0))!=0 ){
   690    691       if( pFile->zUuid==0 ) continue;
   691    692       fid = uuid_to_rid(pFile->zUuid, 0);
   692    693       md5sum_step_text(pFile->zName, -1);
   693    694       content_get(fid, &file);
   694         -    sqlite3_snprintf(sizeof(zBuf), zBuf, " %d\n", blob_size(&file));
          695  +    sqlite4_snprintf(zBuf, sizeof(zBuf), " %d\n", blob_size(&file));
   695    696       md5sum_step_text(zBuf, -1);
   696    697       md5sum_step_blob(&file);
   697    698       blob_reset(&file);
   698    699     }
   699    700     if( pManOut ){
   700    701       if( pManifest->zRepoCksum ){
   701    702         blob_append(pManOut, pManifest->zRepoCksum, -1);

Changes to src/wiki.c.

   211    211   
   212    212     db_prepare(&q,
   213    213        "SELECT datetime(mtime,'localtime'), filename, user"
   214    214        "  FROM attachment"
   215    215        " WHERE isLatest AND src!='' AND target=%Q"
   216    216        " ORDER BY mtime DESC",
   217    217        zPageName);
   218         -  while( db_step(&q)==SQLITE_ROW ){
          218  +  while( db_step(&q)==SQLITE4_ROW ){
   219    219       const char *zDate = db_column_text(&q, 0);
   220    220       const char *zFile = db_column_text(&q, 1);
   221    221       const char *zUser = db_column_text(&q, 2);
   222    222       if( cnt==0 ){
   223    223         @ <hr /><h2>Attachments:</h2>
   224    224         @ <ul>
   225    225       }
................................................................................
   666    666     if( showAll ){
   667    667       style_submenu_element("Active", "Only Active Pages", "%s/wcontent", g.zTop);
   668    668     }else{
   669    669       style_submenu_element("All", "All", "%s/wcontent?all=1", g.zTop);
   670    670     }
   671    671     @ <ul>
   672    672     wiki_prepare_page_list(&q);
   673         -  while( db_step(&q)==SQLITE_ROW ){
          673  +  while( db_step(&q)==SQLITE4_ROW ){
   674    674       const char *zName = db_column_text(&q, 0);
   675    675       int size = db_column_int(&q, 1);
   676    676       if( size>0 ){
   677    677         @ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li>
   678    678       }else if( showAll ){
   679    679         @ <li>%z(href("%R/wiki?name=%T",zName))<s>%h(zName)</s></a></li>
   680    680       }
................................................................................
   698    698     zTitle = PD("title","*");
   699    699     style_header("Wiki Pages Found");
   700    700     @ <ul>
   701    701     db_prepare(&q, 
   702    702       "SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname like 'wiki-%%%q%%'"
   703    703       " ORDER BY lower(tagname) /*sort*/" ,
   704    704   	zTitle);
   705         -  while( db_step(&q)==SQLITE_ROW ){
          705  +  while( db_step(&q)==SQLITE4_ROW ){
   706    706       const char *zName = db_column_text(&q, 0);
   707    707       @ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li>
   708    708     }
   709    709     db_finalize(&q);
   710    710     @ </ul>
   711    711     style_footer();
   712    712   }
................................................................................
   967    967     }else
   968    968     if( strncmp(g.argv[2],"list",n)==0 ){
   969    969       Stmt q;
   970    970       db_prepare(&q, 
   971    971         "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
   972    972         " ORDER BY lower(tagname) /*sort*/"
   973    973       );
   974         -    while( db_step(&q)==SQLITE_ROW ){
          974  +    while( db_step(&q)==SQLITE4_ROW ){
   975    975         const char *zName = db_column_text(&q, 0);
   976    976         fossil_print( "%s\n",zName);
   977    977       }
   978    978       db_finalize(&q);
   979    979     }else
   980    980     {
   981    981       goto wiki_cmd_usage;
   982    982     }
   983    983     return;
   984    984   
   985    985   wiki_cmd_usage:
   986    986     usage("export|create|commit|list ...");
   987    987   }

Changes to src/wikiformat.c.

   951    951     int rc;
   952    952     db_static_prepare(&q, 
   953    953        "SELECT 1 FROM blob WHERE uuid>=:u AND +uuid GLOB (:u || '*')"
   954    954     );
   955    955     db_bind_text(&q, ":u", zUuid);
   956    956     rc = db_step(&q);
   957    957     db_reset(&q);
   958         -  return rc==SQLITE_ROW;
          958  +  return rc==SQLITE4_ROW;
   959    959   }
   960    960   
   961    961   /*
   962    962   ** zTarget is guaranteed to be a UUID.  It might be the UUID of a ticket.
   963    963   ** If it is, store in *pClosed a true or false depending on whether or not
   964    964   ** the ticket is closed and return true. If zTarget
   965    965   ** is not the UUID of a ticket, return false.
................................................................................
   986    986         " WHERE tkt_uuid>=:lwr AND tkt_uuid<:upr",
   987    987         zClosedExpr
   988    988       );
   989    989       once = 0;
   990    990     }
   991    991     db_bind_text(&q, ":lwr", zLower);
   992    992     db_bind_text(&q, ":upr", zUpper);
   993         -  if( db_step(&q)==SQLITE_ROW ){
          993  +  if( db_step(&q)==SQLITE4_ROW ){
   994    994       rc = 1;
   995    995       *pClosed = db_column_int(&q, 0);
   996    996     }else{
   997    997       rc = 0;
   998    998     }
   999    999     db_reset(&q);
  1000   1000     return rc;
................................................................................
  1095   1095     }else if( wiki_name_is_wellformed((const unsigned char *)zTarget) ){
  1096   1096       blob_appendf(p->pOut, "<a href=\"%s/wiki?name=%T\">", g.zTop, zTarget);
  1097   1097     }else{
  1098   1098       blob_appendf(p->pOut, "<span class=\"brokenlink\">[%h]</span>", zTarget);
  1099   1099       zTerm = "";
  1100   1100     }
  1101   1101     assert( strlen(zTerm)<nClose );
  1102         -  sqlite3_snprintf(nClose, zClose, "%s", zTerm);
         1102  +  sqlite4_snprintf(zClose, nClose, "%s", zTerm);
  1103   1103   }
  1104   1104   
  1105   1105   /*
  1106   1106   ** Check to see if the given parsed markup is the correct
  1107   1107   ** </verbatim> tag.
  1108   1108   */
  1109   1109   static int endVerbatim(Renderer *p, ParsedMarkup *pMarkup){

Changes to src/winhttp.c.

    70     70     int wanted = 0;
    71     71     char *z;
    72     72     char zRequestFName[100];
    73     73     char zReplyFName[100];
    74     74     char zCmd[2000];          /* Command-line to process the request */
    75     75     char zHdr[2000];          /* The HTTP request header */
    76     76   
    77         -  sqlite3_snprintf(sizeof(zRequestFName), zRequestFName,
           77  +  sqlite4_snprintf(zRequestFName, sizeof(zRequestFName),
    78     78                      "%s_in%d.txt", zTempPrefix, p->id);
    79         -  sqlite3_snprintf(sizeof(zReplyFName), zReplyFName,
           79  +  sqlite4_snprintf(zReplayFName, sizeof(zReplyFName),
    80     80                      "%s_out%d.txt", zTempPrefix, p->id);
    81     81     amt = 0;
    82     82     while( amt<sizeof(zHdr) ){
    83     83       got = recv(p->s, &zHdr[amt], sizeof(zHdr)-1-amt, 0);
    84     84       if( got==SOCKET_ERROR ) goto end_request;
    85     85       if( got==0 ){
    86     86         wanted = 0;
................................................................................
   106    106       }else{
   107    107         break;
   108    108       }
   109    109       wanted -= got;
   110    110     }
   111    111     fclose(out);
   112    112     out = 0;
   113         -  sqlite3_snprintf(sizeof(zCmd), zCmd, "\"%s\" http \"%s\" %s %s %s --nossl%s",
          113  +  sqlite4_snprintf(zCmd, sizeof(zCmd), "\"%s\" http \"%s\" %s %s %s --nossl%s",
   114    114       fossil_nameofexe(), g.zRepositoryName, zRequestFName, zReplyFName, 
   115    115       inet_ntoa(p->addr.sin_addr), p->zOptions
   116    116     );
   117    117     fossil_system(zCmd);
   118    118     in = fossil_fopen(zReplyFName, "rb");
   119    119     if( in ){
   120    120       while( (got = fread(zHdr, 1, sizeof(zHdr), in))>0 ){

Changes to src/xfer.c.

    55     55   */
    56     56   static int rid_from_uuid(Blob *pUuid, int phantomize, int isPrivate){
    57     57     static Stmt q;
    58     58     int rid;
    59     59   
    60     60     db_static_prepare(&q, "SELECT rid FROM blob WHERE uuid=:uuid");
    61     61     db_bind_str(&q, ":uuid", pUuid);
    62         -  if( db_step(&q)==SQLITE_ROW ){
           62  +  if( db_step(&q)==SQLITE4_ROW ){
    63     63       rid = db_column_int(&q, 0);
    64     64     }else{
    65     65       rid = 0;
    66     66     }
    67     67     db_reset(&q);
    68     68     if( rid==0 && phantomize ){
    69     69       rid = content_new(blob_str(pUuid), isPrivate);
................................................................................
   463    463       " FROM blob LEFT JOIN delta ON (blob.rid=delta.rid)"
   464    464       " WHERE blob.rid=:rid"
   465    465       "   AND blob.size>=0"
   466    466       "   AND NOT EXISTS(SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)"
   467    467     );
   468    468     db_bind_int(&q1, ":rid", rid);
   469    469     rc = db_step(&q1);
   470         -  if( rc==SQLITE_ROW ){
          470  +  if( rc==SQLITE4_ROW ){
   471    471       zUuid = db_column_text(&q1, 0);
   472    472       szU = db_column_int(&q1, 1);
   473    473       szC = db_column_bytes(&q1, 2);
   474    474       zContent = db_column_raw(&q1, 2);
   475    475       srcIsPrivate = db_column_int(&q1, 3);
   476    476       zDelta = db_column_text(&q1, 4);
   477    477       if( isPrivate ) blob_append(pXfer->pOut, "private\n", -1);
................................................................................
   512    512     Stmt q;
   513    513     db_prepare(&q, 
   514    514       "SELECT uuid FROM phantom JOIN blob USING(rid)"
   515    515       " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid) %s",
   516    516       (pXfer->syncPrivate ? "" :
   517    517            "   AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)")
   518    518     );
   519         -  while( db_step(&q)==SQLITE_ROW && maxReq-- > 0 ){
          519  +  while( db_step(&q)==SQLITE4_ROW && maxReq-- > 0 ){
   520    520       const char *zUuid = db_column_text(&q, 0);
   521    521       blob_appendf(pXfer->pOut, "gimme %s\n", zUuid);
   522    522       pXfer->nGimmeSent++;
   523    523     }
   524    524     db_finalize(&q);
   525    525   }
   526    526   
................................................................................
   579    579     db_prepare(&q,
   580    580        "SELECT pw, cap, uid FROM user"
   581    581        " WHERE login=%Q"
   582    582        "   AND login NOT IN ('anonymous','nobody','developer','reader')"
   583    583        "   AND length(pw)>0",
   584    584        zLogin
   585    585     );
   586         -  if( db_step(&q)==SQLITE_ROW ){
          586  +  if( db_step(&q)==SQLITE4_ROW ){
   587    587       int szPw;
   588    588       Blob pw, combined, hash;
   589    589       blob_zero(&pw);
   590    590       db_ephemeral_blob(&q, 0, &pw);
   591    591       szPw = blob_size(&pw);
   592    592       blob_zero(&combined);
   593    593       blob_copy(&combined, pNonce);
................................................................................
   632    632   ** This is really just an optimization.  If you clear the
   633    633   ** unsent table, all the right files will still get transferred.
   634    634   ** It just might require an extra round trip or two.
   635    635   */
   636    636   static void send_unsent(Xfer *pXfer){
   637    637     Stmt q;
   638    638     db_prepare(&q, "SELECT rid FROM unsent EXCEPT SELECT rid FROM private");
   639         -  while( db_step(&q)==SQLITE_ROW ){
          639  +  while( db_step(&q)==SQLITE4_ROW ){
   640    640       int rid = db_column_int(&q, 0);
   641    641       send_file(pXfer, rid, 0, 0);
   642    642     }
   643    643     db_finalize(&q);
   644    644     db_multi_exec("DELETE FROM unsent");
   645    645   }
   646    646   
................................................................................
   674    674       blob_zero(&deleteWhere);
   675    675       db_prepare(&q, "SELECT uuid FROM unclustered, blob"
   676    676                      " WHERE NOT EXISTS(SELECT 1 FROM phantom"
   677    677                      "                   WHERE rid=unclustered.rid)"
   678    678                      "   AND unclustered.rid=blob.rid"
   679    679                      "   AND NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
   680    680                      " ORDER BY 1");
   681         -    while( db_step(&q)==SQLITE_ROW ){
          681  +    while( db_step(&q)==SQLITE4_ROW ){
   682    682         blob_appendf(&cluster, "M %s\n", db_column_text(&q, 0));
   683    683         nRow++;
   684    684         if( nRow>=800 && nUncl>nRow+100 ){
   685    685           md5sum_blob(&cluster, &cksum);
   686    686           blob_appendf(&cluster, "Z %b\n", &cksum);
   687    687           blob_reset(&cksum);
   688    688           rid = content_put(&cluster);
................................................................................
   712    712   ** Send igot messages for every private artifact
   713    713   */
   714    714   static int send_private(Xfer *pXfer){
   715    715     int cnt = 0;
   716    716     Stmt q;
   717    717     if( pXfer->syncPrivate ){
   718    718       db_prepare(&q, "SELECT uuid FROM private JOIN blob USING(rid)");
   719         -    while( db_step(&q)==SQLITE_ROW ){
          719  +    while( db_step(&q)==SQLITE4_ROW ){
   720    720         blob_appendf(pXfer->pOut, "igot %s 1\n", db_column_text(&q,0));
   721    721         cnt++;
   722    722       }
   723    723       db_finalize(&q);
   724    724     }
   725    725     return cnt;
   726    726   }
................................................................................
   734    734     int cnt = 0;
   735    735     db_prepare(&q, 
   736    736       "SELECT uuid FROM unclustered JOIN blob USING(rid)"
   737    737       " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
   738    738       "   AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=blob.rid)"
   739    739       "   AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)"
   740    740     );
   741         -  while( db_step(&q)==SQLITE_ROW ){
          741  +  while( db_step(&q)==SQLITE4_ROW ){
   742    742       blob_appendf(pXfer->pOut, "igot %s\n", db_column_text(&q, 0));
   743    743       cnt++;
   744    744     }
   745    745     db_finalize(&q);
   746    746     return cnt;
   747    747   }
   748    748   
................................................................................
   753    753     Stmt q;
   754    754     db_prepare(&q, 
   755    755       "SELECT uuid FROM blob "
   756    756       " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
   757    757       "   AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)"
   758    758       "   AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=blob.rid)"
   759    759     );
   760         -  while( db_step(&q)==SQLITE_ROW ){
          760  +  while( db_step(&q)==SQLITE4_ROW ){
   761    761       blob_appendf(pXfer->pOut, "igot %s\n", db_column_text(&q, 0));
   762    762     }
   763    763     db_finalize(&q);
   764    764   }
   765    765   
   766    766   /*
   767    767   ** Send a single old-style config card for configuration item zName.
................................................................................
  1476   1476       /* Process the reply that came back from the server */
  1477   1477       while( blob_line(&recv, &xfer.line) ){
  1478   1478         if( blob_buffer(&xfer.line)[0]=='#' ){
  1479   1479           const char *zLine = blob_buffer(&xfer.line);
  1480   1480           if( memcmp(zLine, "# timestamp ", 12)==0 ){
  1481   1481             char zTime[20];
  1482   1482             double rDiff;
  1483         -          sqlite3_snprintf(sizeof(zTime), zTime, "%.19s", &zLine[12]);
         1483  +          sqlite4_snprintf(zTime, sizeof(zTime), "%.19s", &zLine[12]);
  1484   1484             rDiff = db_double(9e99, "SELECT julianday('%q') - %.17g",
  1485   1485                               zTime, rArrivalTime);
  1486   1486             if( rDiff>9e98 || rDiff<-9e98 ) rDiff = 0.0;
  1487   1487             if( (rDiff*24.0*3600.0) > 10.0 ){
  1488   1488                fossil_warning("*** time skew *** server is fast by %s",
  1489   1489                               db_timespan_name(rDiff));
  1490   1490                g.clockSkewSeen = 1;

Changes to win/Makefile.PellesCGMake.

    78     78   # define the special utilities files, needed to generate
    79     79   # the automatically generated source files
    80     80   UTILS=translate.exe mkindex.exe makeheaders.exe
    81     81   UTILS_OBJ=$(UTILS:.exe=.obj)
    82     82   UTILS_SRC=$(foreach uf,$(UTILS),$(SRCDIR)$(uf:.exe=.c))
    83     83   
    84     84   # define the sqlite files, which need special flags on compile
    85         -SQLITESRC=sqlite3.c
           85  +SQLITESRC=sqlite4.c
    86     86   ORIGSQLITESRC=$(foreach sf,$(SQLITESRC),$(SRCDIR)$(sf))
    87     87   SQLITEOBJ=$(foreach sf,$(SQLITESRC),$(sf:.c=.obj))
    88         -SQLITEDEFINES=-DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0
           88  +SQLITEDEFINES=-DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0
    89     89   
    90     90   # define the sqlite shell files, which need special flags on compile
    91     91   SQLITESHELLSRC=shell.c
    92     92   ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
    93     93   SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
    94         -SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1
           94  +SQLITESHELLDEFINES=-Dmain=sqlite4_shell -DSQLITE4_OMIT_LOAD_EXTENSION=1
    95     95   
    96     96   # define the th scripting files, which need special flags on compile
    97     97   THSRC=th.c th_lang.c
    98     98   ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
    99     99   THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
   100    100   
   101    101   # define the zlib files, needed by this compile
................................................................................
   143    143   	mkindex.exe $(TRANSLATEDSRC) >$@
   144    144   
   145    145   # extracting version info from manifest
   146    146   VERSION.h:	version.exe ..\manifest.uuid ..\manifest ..\VERSION
   147    147   	version.exe ..\manifest.uuid ..\manifest ..\VERSION  > $@
   148    148   
   149    149   # generate the simplified headers
   150         -headers: makeheaders.exe page_index.h VERSION.h ../src/sqlite3.h ../src/th.h VERSION.h
   151         -	makeheaders.exe $(foreach ts,$(TRANSLATEDSRC),$(ts):$(ts:_.c=.h)) ../src/sqlite3.h ../src/th.h VERSION.h
          150  +headers: makeheaders.exe page_index.h VERSION.h ../src/sqlite4.h ../src/th.h VERSION.h
          151  +	makeheaders.exe $(foreach ts,$(TRANSLATEDSRC),$(ts):$(ts:_.c=.h)) ../src/sqlite4.h ../src/th.h VERSION.h
   152    152   	echo Done >$@
   153    153   
   154    154   # compile C sources with relevant options
   155    155   
   156    156   $(TRANSLATEDOBJ):	%_.obj:	%_.c %.h
   157    157   	$(CC) $(CCFLAGS) $(INCLUDE) "$<" -Fo"$@"
   158    158   

Changes to win/Makefile.dmc.

    22     22   SSL    =
    23     23   
    24     24   CFLAGS = -o
    25     25   BCC    = $(DMDIR)\bin\dmc $(CFLAGS)
    26     26   TCC    = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
    27     27   LIBS   = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
    28     28   
    29         -SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0
           29  +SQLITE4_OPTIONS = -DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -DSQLITE4_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0
    30     30   
    31     31   SRC   = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c main_.c manifest_.c md5_.c merge_.c merge3_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c update_.c url_.c user_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c xfer_.c xfersetup_.c zip_.c 
    32     32   
    33         -OBJ   = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winhttp$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O 
           33  +OBJ   = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winhttp$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite4$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O 
    34     34   
    35     35   
    36     36   RC=$(DMDIR)\bin\rcc
    37     37   RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__
    38     38   
    39     39   APPNAME = $(OBJDIR)\fossil$(E)
    40     40   
................................................................................
    44     44   	cd $(OBJDIR) 
    45     45   	$(DMDIR)\bin\link @link
    46     46   
    47     47   $(OBJDIR)\fossil.res:	$B\win\fossil.rc
    48     48   	$(RC) $(RCFLAGS) -o$@ $**
    49     49   
    50     50   $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res
    51         -	+echo add allrepo attach bag bisect blob branch browse captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_tag json_timeline json_user json_wiki leaf login main manifest md5 merge merge3 name path pivot popen pqueue printf rebuild report rss schema search setup sha1 shun skins sqlcmd stash stat style sync tag tar th_main timeline tkt tktsetup undo update url user verify vfile wiki wikiformat winhttp xfer xfersetup zip shell sqlite3 th th_lang > $@
           51  +	+echo add allrepo attach bag bisect blob branch browse captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_tag json_timeline json_user json_wiki leaf login main manifest md5 merge merge3 name path pivot popen pqueue printf rebuild report rss schema search setup sha1 shun skins sqlcmd stash stat style sync tag tar th_main timeline tkt tktsetup undo update url user verify vfile wiki wikiformat winhttp xfer xfersetup zip shell sqlite4 th th_lang > $@
    52     52   	+echo fossil >> $@
    53     53   	+echo fossil >> $@
    54     54   	+echo $(LIBS) >> $@
    55     55   	+echo. >> $@
    56     56   	+echo fossil >> $@
    57     57   
    58     58   translate$E: $(SRCDIR)\translate.c
................................................................................
    64     64   mkindex$E: $(SRCDIR)\mkindex.c
    65     65   	$(BCC) -o$@ $**
    66     66   
    67     67   version$E: $B\src\mkversion.c
    68     68   	$(BCC) -o$@ $**
    69     69   
    70     70   $(OBJDIR)\shell$O : $(SRCDIR)\shell.c
    71         -	$(TCC) -o$@ -c -Dmain=sqlite3_shell $(SQLITE_OPTIONS) $**
           71  +	$(TCC) -o$@ -c -Dmain=sqlite4_shell $(SQLITE4_OPTIONS) $**
    72     72   
    73         -$(OBJDIR)\sqlite3$O : $(SRCDIR)\sqlite3.c
    74         -	$(TCC) -o$@ -c $(SQLITE_OPTIONS) $**
           73  +$(OBJDIR)\sqlite4$O : $(SRCDIR)\sqlite4.c
           74  +	$(TCC) -o$@ -c $(SQLITE4_OPTIONS) $**
    75     75   
    76     76   $(OBJDIR)\th$O : $(SRCDIR)\th.c
    77     77   	$(TCC) -o$@ -c $**
    78     78   
    79     79   $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
    80     80   	$(TCC) -o$@ -c $**
    81     81   
................................................................................
   691    691   $(OBJDIR)\zip$O : zip_.c zip.h
   692    692   	$(TCC) -o$@ -c zip_.c
   693    693   
   694    694   zip_.c : $(SRCDIR)\zip.c
   695    695   	+translate$E $** > $@
   696    696   
   697    697   headers: makeheaders$E page_index.h VERSION.h
   698         -	 +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
          698  +	 +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite4.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
   699    699   	@copy /Y nul: headers

Changes to win/Makefile.mingw.

   465    465    $(OBJDIR)/wiki.o \
   466    466    $(OBJDIR)/wikiformat.o \
   467    467    $(OBJDIR)/winhttp.o \
   468    468    $(OBJDIR)/xfer.o \
   469    469    $(OBJDIR)/xfersetup.o \
   470    470    $(OBJDIR)/zip.o
   471    471   
   472         -APPNAME = fossil.exe
          472  +APPNAME = fossil4.exe
   473    473   TRANSLATE   = $(subst /,\\,$(OBJDIR)/translate.exe)
   474    474   MAKEHEADERS = $(subst /,\\,$(OBJDIR)/makeheaders.exe)
   475    475   MKINDEX     = $(subst /,\\,$(OBJDIR)/mkindex.exe)
   476    476   VERSION     = $(subst /,\\,$(OBJDIR)/version.exe)
   477    477   
   478    478   
   479    479   all:	$(OBJDIR) $(APPNAME)
................................................................................
   505    505   # the repository after running the tests.
   506    506   test:	$(OBJDIR) $(APPNAME)
   507    507   	$(TCLSH) $(SRCDIR)/../test/tester.tcl $(APPNAME)
   508    508   
   509    509   $(OBJDIR)/VERSION.h:	$(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
   510    510   	$(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
   511    511   
   512         -EXTRAOBJ =  $(OBJDIR)/sqlite3.o  $(OBJDIR)/shell.o  $(OBJDIR)/th.o  $(OBJDIR)/th_lang.o  $(OBJDIR)/cson_amalgamation.o
          512  +EXTRAOBJ =  $(OBJDIR)/sqlite4.o  $(OBJDIR)/shell.o  $(OBJDIR)/th.o  $(OBJDIR)/th_lang.o  $(OBJDIR)/cson_amalgamation.o
   513    513   
   514    514   ifdef FOSSIL_ENABLE_TCL
   515    515   EXTRAOBJ +=  $(OBJDIR)/th_tcl.o
   516    516   endif
   517    517   
   518    518   $(APPNAME):	$(OBJDIR)/headers $(OBJ) $(EXTRAOBJ) $(OBJDIR)/icon.o
   519    519   	$(TCC) -o $(APPNAME) $(OBJ) $(EXTRAOBJ) $(LIB) $(OBJDIR)/icon.o
................................................................................
   534    534   setup: $(OBJDIR) $(APPNAME)
   535    535   	$(MAKENSIS) ./fossil.nsi
   536    536   
   537    537   
   538    538   $(OBJDIR)/page_index.h: $(TRANS_SRC) $(OBJDIR)/mkindex
   539    539   	$(MKINDEX) $(TRANS_SRC) >$@
   540    540   $(OBJDIR)/headers:	$(OBJDIR)/page_index.h $(OBJDIR)/makeheaders $(OBJDIR)/VERSION.h
   541         -	$(MAKEHEADERS)  $(OBJDIR)/add_.c:$(OBJDIR)/add.h $(OBJDIR)/allrepo_.c:$(OBJDIR)/allrepo.h $(OBJDIR)/attach_.c:$(OBJDIR)/attach.h $(OBJDIR)/bag_.c:$(OBJDIR)/bag.h $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h $(OBJDIR)/clearsign_.c:$(OBJDIR)/clearsign.h $(OBJDIR)/clone_.c:$(OBJDIR)/clone.h $(OBJDIR)/comformat_.c:$(OBJDIR)/comformat.h $(OBJDIR)/configure_.c:$(OBJDIR)/configure.h $(OBJDIR)/content_.c:$(OBJDIR)/content.h $(OBJDIR)/db_.c:$(OBJDIR)/db.h $(OBJDIR)/delta_.c:$(OBJDIR)/delta.h $(OBJDIR)/deltacmd_.c:$(OBJDIR)/deltacmd.h $(OBJDIR)/descendants_.c:$(OBJDIR)/descendants.h $(OBJDIR)/diff_.c:$(OBJDIR)/diff.h $(OBJDIR)/diffcmd_.c:$(OBJDIR)/diffcmd.h $(OBJDIR)/doc_.c:$(OBJDIR)/doc.h $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h $(OBJDIR)/event_.c:$(OBJDIR)/event.h $(OBJDIR)/export_.c:$(OBJDIR)/export.h $(OBJDIR)/file_.c:$(OBJDIR)/file.h $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h $(OBJDIR)/http_.c:$(OBJDIR)/http.h $(OBJDIR)/http_socket_.c:$(OBJDIR)/http_socket.h $(OBJDIR)/http_ssl_.c:$(OBJDIR)/http_ssl.h $(OBJDIR)/http_transport_.c:$(OBJDIR)/http_transport.h $(OBJDIR)/import_.c:$(OBJDIR)/import.h $(OBJDIR)/info_.c:$(OBJDIR)/info.h $(OBJDIR)/json_.c:$(OBJDIR)/json.h $(OBJDIR)/json_artifact_.c:$(OBJDIR)/json_artifact.h $(OBJDIR)/json_branch_.c:$(OBJDIR)/json_branch.h $(OBJDIR)/json_config_.c:$(OBJDIR)/json_config.h $(OBJDIR)/json_diff_.c:$(OBJDIR)/json_diff.h $(OBJDIR)/json_dir_.c:$(OBJDIR)/json_dir.h $(OBJDIR)/json_finfo_.c:$(OBJDIR)/json_finfo.h $(OBJDIR)/json_login_.c:$(OBJDIR)/json_login.h $(OBJDIR)/json_query_.c:$(OBJDIR)/json_query.h $(OBJDIR)/json_report_.c:$(OBJDIR)/json_report.h $(OBJDIR)/json_tag_.c:$(OBJDIR)/json_tag.h $(OBJDIR)/json_timeline_.c:$(OBJDIR)/json_timeline.h $(OBJDIR)/json_user_.c:$(OBJDIR)/json_user.h $(OBJDIR)/json_wiki_.c:$(OBJDIR)/json_wiki.h $(OBJDIR)/leaf_.c:$(OBJDIR)/leaf.h $(OBJDIR)/login_.c:$(OBJDIR)/login.h $(OBJDIR)/main_.c:$(OBJDIR)/main.h $(OBJDIR)/manifest_.c:$(OBJDIR)/manifest.h $(OBJDIR)/md5_.c:$(OBJDIR)/md5.h $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h $(OBJDIR)/name_.c:$(OBJDIR)/name.h $(OBJDIR)/path_.c:$(OBJDIR)/path.h $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h $(OBJDIR)/report_.c:$(OBJDIR)/report.h $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h $(OBJDIR)/search_.c:$(OBJDIR)/search.h $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h $(OBJDIR)/style_.c:$(OBJDIR)/style.h $(OBJDIR)/sync_.c:$(OBJDIR)/sync.h $(OBJDIR)/tag_.c:$(OBJDIR)/tag.h $(OBJDIR)/tar_.c:$(OBJDIR)/tar.h $(OBJDIR)/th_main_.c:$(OBJDIR)/th_main.h $(OBJDIR)/timeline_.c:$(OBJDIR)/timeline.h $(OBJDIR)/tkt_.c:$(OBJDIR)/tkt.h $(OBJDIR)/tktsetup_.c:$(OBJDIR)/tktsetup.h $(OBJDIR)/undo_.c:$(OBJDIR)/undo.h $(OBJDIR)/update_.c:$(OBJDIR)/update.h $(OBJDIR)/url_.c:$(OBJDIR)/url.h $(OBJDIR)/user_.c:$(OBJDIR)/user.h $(OBJDIR)/verify_.c:$(OBJDIR)/verify.h $(OBJDIR)/vfile_.c:$(OBJDIR)/vfile.h $(OBJDIR)/wiki_.c:$(OBJDIR)/wiki.h $(OBJDIR)/wikiformat_.c:$(OBJDIR)/wikiformat.h $(OBJDIR)/winhttp_.c:$(OBJDIR)/winhttp.h $(OBJDIR)/xfer_.c:$(OBJDIR)/xfer.h $(OBJDIR)/xfersetup_.c:$(OBJDIR)/xfersetup.h $(OBJDIR)/zip_.c:$(OBJDIR)/zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h $(OBJDIR)/VERSION.h
          541  +	$(MAKEHEADERS)  $(OBJDIR)/add_.c:$(OBJDIR)/add.h $(OBJDIR)/allrepo_.c:$(OBJDIR)/allrepo.h $(OBJDIR)/attach_.c:$(OBJDIR)/attach.h $(OBJDIR)/bag_.c:$(OBJDIR)/bag.h $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h $(OBJDIR)/clearsign_.c:$(OBJDIR)/clearsign.h $(OBJDIR)/clone_.c:$(OBJDIR)/clone.h $(OBJDIR)/comformat_.c:$(OBJDIR)/comformat.h $(OBJDIR)/configure_.c:$(OBJDIR)/configure.h $(OBJDIR)/content_.c:$(OBJDIR)/content.h $(OBJDIR)/db_.c:$(OBJDIR)/db.h $(OBJDIR)/delta_.c:$(OBJDIR)/delta.h $(OBJDIR)/deltacmd_.c:$(OBJDIR)/deltacmd.h $(OBJDIR)/descendants_.c:$(OBJDIR)/descendants.h $(OBJDIR)/diff_.c:$(OBJDIR)/diff.h $(OBJDIR)/diffcmd_.c:$(OBJDIR)/diffcmd.h $(OBJDIR)/doc_.c:$(OBJDIR)/doc.h $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h $(OBJDIR)/event_.c:$(OBJDIR)/event.h $(OBJDIR)/export_.c:$(OBJDIR)/export.h $(OBJDIR)/file_.c:$(OBJDIR)/file.h $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h $(OBJDIR)/http_.c:$(OBJDIR)/http.h $(OBJDIR)/http_socket_.c:$(OBJDIR)/http_socket.h $(OBJDIR)/http_ssl_.c:$(OBJDIR)/http_ssl.h $(OBJDIR)/http_transport_.c:$(OBJDIR)/http_transport.h $(OBJDIR)/import_.c:$(OBJDIR)/import.h $(OBJDIR)/info_.c:$(OBJDIR)/info.h $(OBJDIR)/json_.c:$(OBJDIR)/json.h $(OBJDIR)/json_artifact_.c:$(OBJDIR)/json_artifact.h $(OBJDIR)/json_branch_.c:$(OBJDIR)/json_branch.h $(OBJDIR)/json_config_.c:$(OBJDIR)/json_config.h $(OBJDIR)/json_diff_.c:$(OBJDIR)/json_diff.h $(OBJDIR)/json_dir_.c:$(OBJDIR)/json_dir.h $(OBJDIR)/json_finfo_.c:$(OBJDIR)/json_finfo.h $(OBJDIR)/json_login_.c:$(OBJDIR)/json_login.h $(OBJDIR)/json_query_.c:$(OBJDIR)/json_query.h $(OBJDIR)/json_report_.c:$(OBJDIR)/json_report.h $(OBJDIR)/json_tag_.c:$(OBJDIR)/json_tag.h $(OBJDIR)/json_timeline_.c:$(OBJDIR)/json_timeline.h $(OBJDIR)/json_user_.c:$(OBJDIR)/json_user.h $(OBJDIR)/json_wiki_.c:$(OBJDIR)/json_wiki.h $(OBJDIR)/leaf_.c:$(OBJDIR)/leaf.h $(OBJDIR)/login_.c:$(OBJDIR)/login.h $(OBJDIR)/main_.c:$(OBJDIR)/main.h $(OBJDIR)/manifest_.c:$(OBJDIR)/manifest.h $(OBJDIR)/md5_.c:$(OBJDIR)/md5.h $(OBJDIR)/merge_.c:$(OBJDIR)/merge.h $(OBJDIR)/merge3_.c:$(OBJDIR)/merge3.h $(OBJDIR)/name_.c:$(OBJDIR)/name.h $(OBJDIR)/path_.c:$(OBJDIR)/path.h $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h $(OBJDIR)/report_.c:$(OBJDIR)/report.h $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h $(OBJDIR)/search_.c:$(OBJDIR)/search.h $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h $(OBJDIR)/style_.c:$(OBJDIR)/style.h $(OBJDIR)/sync_.c:$(OBJDIR)/sync.h $(OBJDIR)/tag_.c:$(OBJDIR)/tag.h $(OBJDIR)/tar_.c:$(OBJDIR)/tar.h $(OBJDIR)/th_main_.c:$(OBJDIR)/th_main.h $(OBJDIR)/timeline_.c:$(OBJDIR)/timeline.h $(OBJDIR)/tkt_.c:$(OBJDIR)/tkt.h $(OBJDIR)/tktsetup_.c:$(OBJDIR)/tktsetup.h $(OBJDIR)/undo_.c:$(OBJDIR)/undo.h $(OBJDIR)/update_.c:$(OBJDIR)/update.h $(OBJDIR)/url_.c:$(OBJDIR)/url.h $(OBJDIR)/user_.c:$(OBJDIR)/user.h $(OBJDIR)/verify_.c:$(OBJDIR)/verify.h $(OBJDIR)/vfile_.c:$(OBJDIR)/vfile.h $(OBJDIR)/wiki_.c:$(OBJDIR)/wiki.h $(OBJDIR)/wikiformat_.c:$(OBJDIR)/wikiformat.h $(OBJDIR)/winhttp_.c:$(OBJDIR)/winhttp.h $(OBJDIR)/xfer_.c:$(OBJDIR)/xfer.h $(OBJDIR)/xfersetup_.c:$(OBJDIR)/xfersetup.h $(OBJDIR)/zip_.c:$(OBJDIR)/zip.h $(SRCDIR)/sqlite4.h $(SRCDIR)/th.h $(OBJDIR)/VERSION.h
   542    542   	echo Done >$(OBJDIR)/headers
   543    543   
   544    544   $(OBJDIR)/headers: Makefile
   545    545   Makefile:
   546    546   $(OBJDIR)/add_.c:	$(SRCDIR)/add.c $(OBJDIR)/translate
   547    547   	$(TRANSLATE) $(SRCDIR)/add.c >$(OBJDIR)/add_.c
   548    548   
................................................................................
  1218   1218   $(OBJDIR)/zip_.c:	$(SRCDIR)/zip.c $(OBJDIR)/translate
  1219   1219   	$(TRANSLATE) $(SRCDIR)/zip.c >$(OBJDIR)/zip_.c
  1220   1220   
  1221   1221   $(OBJDIR)/zip.o:	$(OBJDIR)/zip_.c $(OBJDIR)/zip.h  $(SRCDIR)/config.h
  1222   1222   	$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
  1223   1223   
  1224   1224   zip.h:	$(OBJDIR)/headers
  1225         -$(OBJDIR)/sqlite3.o:	$(SRCDIR)/sqlite3.c
  1226         -	$(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
         1225  +$(OBJDIR)/sqlite4.o:	$(SRCDIR)/sqlite4.c
         1226  +	$(XTCC) -DSQLITE4_OMIT_LOAD_EXTENSION=1 -DSQLITE4_THREADSAFE=0 -DSQLITE4_DEFAULT_FILE_FORMAT=4 -DSQLITE4_ENABLE_STAT3 -Dlocaltime=fossil_localtime -DSQLITE4_ENABLE_LOCKING_STYLE=0 -c $(SRCDIR)/sqlite4.c -o $(OBJDIR)/sqlite4.o
  1227   1227   
  1228   1228   $(OBJDIR)/cson_amalgamation.o:	$(SRCDIR)/cson_amalgamation.c
  1229   1229   	$(XTCC)  -c $(SRCDIR)/cson_amalgamation.c -o $(OBJDIR)/cson_amalgamation.o -DCSON_FOSSIL_MODE
  1230   1230   
  1231   1231   $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_finfo.o $(OBJDIR)/json_login.o $(OBJDIR)/json_query.o $(OBJDIR)/json_report.o $(OBJDIR)/json_tag.o $(OBJDIR)/json_timeline.o $(OBJDIR)/json_user.o $(OBJDIR)/json_wiki.o : $(SRCDIR)/json_detail.h
  1232   1232   
  1233         -$(OBJDIR)/shell.o:	$(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
  1234         -	$(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
         1233  +$(OBJDIR)/shell.o:	$(SRCDIR)/shell.c $(SRCDIR)/sqlite4.h
         1234  +	$(XTCC) -Dmain=sqlite4_shell -DSQLITE4_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
  1235   1235   
  1236   1236   $(OBJDIR)/th.o:	$(SRCDIR)/th.c
  1237   1237   	$(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
  1238   1238   
  1239   1239   $(OBJDIR)/th_lang.o:	$(SRCDIR)/th_lang.c
  1240   1240   	$(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th_lang.c -o $(OBJDIR)/th_lang.o
  1241   1241   
  1242   1242   ifdef FOSSIL_ENABLE_TCL
  1243   1243   $(OBJDIR)/th_tcl.o:	$(SRCDIR)/th_tcl.c
  1244   1244   	$(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th_tcl.c -o $(OBJDIR)/th_tcl.o
  1245   1245   endif
  1246   1246   

Changes to win/Makefile.msc.

    36     36   
    37     37   CFLAGS = -nologo -MT -O2
    38     38   BCC    = $(CC) $(CFLAGS)
    39     39   TCC    = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL)
    40     40   LIBS   = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB)
    41     41   LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR)
    42     42   
    43         -SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 /DSQLITE_THREADSAFE=0 /DSQLITE_DEFAULT_FILE_FORMAT=4 /DSQLITE_ENABLE_STAT3 /Dlocaltime=fossil_localtime /DSQLITE_ENABLE_LOCKING_STYLE=0
           43  +SQLITE4_OPTIONS = /DSQLITE4_OMIT_LOAD_EXTENSION=1 /DSQLITE4_THREADSAFE=0 /DSQLITE4_DEFAULT_FILE_FORMAT=4 /DSQLITE4_ENABLE_STAT3 /Dlocaltime=fossil_localtime /DSQLITE4_ENABLE_LOCKING_STYLE=0
    44     44   
    45     45   SRC   = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c main_.c manifest_.c md5_.c merge_.c merge3_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c update_.c url_.c user_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c xfer_.c xfersetup_.c zip_.c 
    46     46   
    47         -OBJ   = $(OX)\add$O $(OX)\allrepo$O $(OX)\attach$O $(OX)\bag$O $(OX)\bisect$O $(OX)\blob$O $(OX)\branch$O $(OX)\browse$O $(OX)\captcha$O $(OX)\cgi$O $(OX)\checkin$O $(OX)\checkout$O $(OX)\clearsign$O $(OX)\clone$O $(OX)\comformat$O $(OX)\configure$O $(OX)\content$O $(OX)\db$O $(OX)\delta$O $(OX)\deltacmd$O $(OX)\descendants$O $(OX)\diff$O $(OX)\diffcmd$O $(OX)\doc$O $(OX)\encode$O $(OX)\event$O $(OX)\export$O $(OX)\file$O $(OX)\finfo$O $(OX)\glob$O $(OX)\graph$O $(OX)\gzip$O $(OX)\http$O $(OX)\http_socket$O $(OX)\http_ssl$O $(OX)\http_transport$O $(OX)\import$O $(OX)\info$O $(OX)\json$O $(OX)\json_artifact$O $(OX)\json_branch$O $(OX)\json_config$O $(OX)\json_diff$O $(OX)\json_dir$O $(OX)\json_finfo$O $(OX)\json_login$O $(OX)\json_query$O $(OX)\json_report$O $(OX)\json_tag$O $(OX)\json_timeline$O $(OX)\json_user$O $(OX)\json_wiki$O $(OX)\leaf$O $(OX)\login$O $(OX)\main$O $(OX)\manifest$O $(OX)\md5$O $(OX)\merge$O $(OX)\merge3$O $(OX)\name$O $(OX)\path$O $(OX)\pivot$O $(OX)\popen$O $(OX)\pqueue$O $(OX)\printf$O $(OX)\rebuild$O $(OX)\report$O $(OX)\rss$O $(OX)\schema$O $(OX)\search$O $(OX)\setup$O $(OX)\sha1$O $(OX)\shun$O $(OX)\skins$O $(OX)\sqlcmd$O $(OX)\stash$O $(OX)\stat$O $(OX)\style$O $(OX)\sync$O $(OX)\tag$O $(OX)\tar$O $(OX)\th_main$O $(OX)\timeline$O $(OX)\tkt$O $(OX)\tktsetup$O $(OX)\undo$O $(OX)\update$O $(OX)\url$O $(OX)\user$O $(OX)\verify$O $(OX)\vfile$O $(OX)\wiki$O $(OX)\wikiformat$O $(OX)\winhttp$O $(OX)\xfer$O $(OX)\xfersetup$O $(OX)\zip$O $(OX)\shell$O $(OX)\sqlite3$O $(OX)\th$O $(OX)\th_lang$O 
           47  +OBJ   = $(OX)\add$O $(OX)\allrepo$O $(OX)\attach$O $(OX)\bag$O $(OX)\bisect$O $(OX)\blob$O $(OX)\branch$O $(OX)\browse$O $(OX)\captcha$O $(OX)\cgi$O $(OX)\checkin$O $(OX)\checkout$O $(OX)\clearsign$O $(OX)\clone$O $(OX)\comformat$O $(OX)\configure$O $(OX)\content$O $(OX)\db$O $(OX)\delta$O $(OX)\deltacmd$O $(OX)\descendants$O $(OX)\diff$O $(OX)\diffcmd$O $(OX)\doc$O $(OX)\encode$O $(OX)\event$O $(OX)\export$O $(OX)\file$O $(OX)\finfo$O $(OX)\glob$O $(OX)\graph$O $(OX)\gzip$O $(OX)\http$O $(OX)\http_socket$O $(OX)\http_ssl$O $(OX)\http_transport$O $(OX)\import$O $(OX)\info$O $(OX)\json$O $(OX)\json_artifact$O $(OX)\json_branch$O $(OX)\json_config$O $(OX)\json_diff$O $(OX)\json_dir$O $(OX)\json_finfo$O $(OX)\json_login$O $(OX)\json_query$O $(OX)\json_report$O $(OX)\json_tag$O $(OX)\json_timeline$O $(OX)\json_user$O $(OX)\json_wiki$O $(OX)\leaf$O $(OX)\login$O $(OX)\main$O $(OX)\manifest$O $(OX)\md5$O $(OX)\merge$O $(OX)\merge3$O $(OX)\name$O $(OX)\path$O $(OX)\pivot$O $(OX)\popen$O $(OX)\pqueue$O $(OX)\printf$O $(OX)\rebuild$O $(OX)\report$O $(OX)\rss$O $(OX)\schema$O $(OX)\search$O $(OX)\setup$O $(OX)\sha1$O $(OX)\shun$O $(OX)\skins$O $(OX)\sqlcmd$O $(OX)\stash$O $(OX)\stat$O $(OX)\style$O $(OX)\sync$O $(OX)\tag$O $(OX)\tar$O $(OX)\th_main$O $(OX)\timeline$O $(OX)\tkt$O $(OX)\tktsetup$O $(OX)\undo$O $(OX)\update$O $(OX)\url$O $(OX)\user$O $(OX)\verify$O $(OX)\vfile$O $(OX)\wiki$O $(OX)\wikiformat$O $(OX)\winhttp$O $(OX)\xfer$O $(OX)\xfersetup$O $(OX)\zip$O $(OX)\shell$O $(OX)\sqlite4$O $(OX)\th$O $(OX)\th_lang$O 
    48     48   
    49     49   
    50     50   APPNAME = $(OX)\fossil$(E)
    51     51   
    52     52   all: $(OX) $(APPNAME)
    53     53   
    54     54   $(APPNAME) : translate$E mkindex$E headers $(OBJ) $(OX)\linkopts
................................................................................
   128    128   	echo $(OX)\search.obj >> $@
   129    129   	echo $(OX)\setup.obj >> $@
   130    130   	echo $(OX)\sha1.obj >> $@
   131    131   	echo $(OX)\shell.obj >> $@
   132    132   	echo $(OX)\shun.obj >> $@
   133    133   	echo $(OX)\skins.obj >> $@
   134    134   	echo $(OX)\sqlcmd.obj >> $@
   135         -	echo $(OX)\sqlite3.obj >> $@
          135  +	echo $(OX)\sqlite4.obj >> $@
   136    136   	echo $(OX)\stash.obj >> $@
   137    137   	echo $(OX)\stat.obj >> $@
   138    138   	echo $(OX)\style.obj >> $@
   139    139   	echo $(OX)\sync.obj >> $@
   140    140   	echo $(OX)\tag.obj >> $@
   141    141   	echo $(OX)\tar.obj >> $@
   142    142   	echo $(OX)\th.obj >> $@
................................................................................
   174    174   mkindex$E: $(SRCDIR)\mkindex.c
   175    175   	$(BCC) $**
   176    176   
   177    177   mkversion$E: $B\src\mkversion.c
   178    178   	$(BCC) $**
   179    179   
   180    180   $(OX)\shell$O : $(SRCDIR)\shell.c
   181         -	$(TCC) /Fo$@ /Dmain=sqlite3_shell $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
          181  +	$(TCC) /Fo$@ /Dmain=sqlite4_shell $(SQLITE4_OPTIONS) -c $(SRCDIR)\shell.c
   182    182   
   183         -$(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
   184         -	$(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
          183  +$(OX)\sqlite4$O : $(SRCDIR)\sqlite4.c
          184  +	$(TCC) /Fo$@ -c $(SQLITE4_OPTIONS) $**
   185    185   
   186    186   $(OX)\th$O : $(SRCDIR)\th.c
   187    187   	$(TCC) /Fo$@ -c $**
   188    188   
   189    189   $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
   190    190   	$(TCC) /Fo$@ -c $**
   191    191   
................................................................................
   800    800   $(OX)\zip$O : zip_.c zip.h
   801    801   	$(TCC) /Fo$@ -c zip_.c
   802    802   
   803    803   zip_.c : $(SRCDIR)\zip.c
   804    804   	translate$E $** > $@
   805    805   
   806    806   headers: makeheaders$E page_index.h VERSION.h
   807         -	makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
          807  +	makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite4.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
   808    808   	@copy /Y nul: headers