sqlmath 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.gitconfig +2 -2
  2. package/.github/workflows/ci.yml +73 -15
  3. package/.github/workflows/publish.yml +66 -0
  4. package/.gitignore +1 -5
  5. package/CHANGELOG.md +53 -2
  6. package/LICENSE +16 -22
  7. package/README.md +18 -219
  8. package/asset_image_folder_open_solid.svg +1 -0
  9. package/jslint.mjs +10998 -0
  10. package/jslint_ci.sh +1542 -728
  11. package/package.json +23 -8
  12. package/{sqlite-autoconf-3360000/sqlite3.c → sqlite3.c} +13116 -85
  13. package/sqlite3_ext.c +8372 -0
  14. package/{sqlite-autoconf-3360000/shell.c → sqlite3_shell.c} +330 -275
  15. package/sqlmath.mjs +1713 -0
  16. package/sqlmath_base.c +1832 -0
  17. package/sqlmath_custom.c +78 -0
  18. package/sqlmath_custom.cpp +0 -0
  19. package/sqlmath_custom.mjs +4 -0
  20. package/sqlmath_old.js +31038 -0
  21. package/extension-functions.c +0 -2047
  22. package/node_sqlite3.cc +0 -11877
  23. package/sqlite-autoconf-3360000/INSTALL +0 -370
  24. package/sqlite-autoconf-3360000/Makefile.am +0 -20
  25. package/sqlite-autoconf-3360000/Makefile.fallback +0 -19
  26. package/sqlite-autoconf-3360000/Makefile.in +0 -1028
  27. package/sqlite-autoconf-3360000/Makefile.msc +0 -1037
  28. package/sqlite-autoconf-3360000/README.txt +0 -113
  29. package/sqlite-autoconf-3360000/Replace.cs +0 -223
  30. package/sqlite-autoconf-3360000/aclocal.m4 +0 -10199
  31. package/sqlite-autoconf-3360000/compile +0 -347
  32. package/sqlite-autoconf-3360000/config.guess +0 -1480
  33. package/sqlite-autoconf-3360000/config.sub +0 -1801
  34. package/sqlite-autoconf-3360000/configure +0 -16135
  35. package/sqlite-autoconf-3360000/configure.ac +0 -285
  36. package/sqlite-autoconf-3360000/depcomp +0 -791
  37. package/sqlite-autoconf-3360000/install-sh +0 -508
  38. package/sqlite-autoconf-3360000/ltmain.sh +0 -11156
  39. package/sqlite-autoconf-3360000/missing +0 -215
  40. package/sqlite-autoconf-3360000/sqlite3.1 +0 -286
  41. package/sqlite-autoconf-3360000/sqlite3.h +0 -12353
  42. package/sqlite-autoconf-3360000/sqlite3.pc.in +0 -13
  43. package/sqlite-autoconf-3360000/sqlite3.rc +0 -83
  44. package/sqlite-autoconf-3360000/sqlite3ext.h +0 -663
  45. package/sqlite-autoconf-3360000/sqlite3rc.h +0 -3
  46. package/sqlite-autoconf-3360000/tea/Makefile.in +0 -440
  47. package/sqlite-autoconf-3360000/tea/README +0 -36
  48. package/sqlite-autoconf-3360000/tea/aclocal.m4 +0 -9
  49. package/sqlite-autoconf-3360000/tea/configure +0 -9989
  50. package/sqlite-autoconf-3360000/tea/configure.ac +0 -201
  51. package/sqlite-autoconf-3360000/tea/doc/sqlite3.n +0 -15
  52. package/sqlite-autoconf-3360000/tea/generic/tclsqlite3.c +0 -4016
  53. package/sqlite-autoconf-3360000/tea/license.terms +0 -6
  54. package/sqlite-autoconf-3360000/tea/pkgIndex.tcl.in +0 -7
  55. package/sqlite-autoconf-3360000/tea/tclconfig/install-sh +0 -528
  56. package/sqlite-autoconf-3360000/tea/tclconfig/tcl.m4 +0 -4168
  57. package/sqlite-autoconf-3360000/tea/win/makefile.vc +0 -419
  58. package/sqlite-autoconf-3360000/tea/win/nmakehlp.c +0 -815
  59. package/sqlite-autoconf-3360000/tea/win/rules.vc +0 -711
  60. package/sqlmath.js +0 -238
  61. package/test/backup.test.js +0 -279
  62. package/test/blob.test.js +0 -54
  63. package/test/cache.test.js +0 -42
  64. package/test/constants.test.js +0 -44
  65. package/test/database_fail.test.js +0 -153
  66. package/test/each.test.js +0 -39
  67. package/test/exec.test.js +0 -39
  68. package/test/extension.test.js +0 -26
  69. package/test/extension_functions.test.js +0 -29
  70. package/test/fts-content.test.js +0 -13
  71. package/test/interrupt.test.js +0 -80
  72. package/test/issue-108.test.js +0 -28
  73. package/test/json.test.js +0 -22
  74. package/test/map.test.js +0 -63
  75. package/test/named_columns.test.js +0 -38
  76. package/test/named_params.test.js +0 -69
  77. package/test/null_error.test.js +0 -41
  78. package/test/nw/.gitignore +0 -3
  79. package/test/nw/Makefile +0 -39
  80. package/test/nw/index.html +0 -14
  81. package/test/nw/package.json +0 -9
  82. package/test/open_close.test.js +0 -187
  83. package/test/other_objects.test.js +0 -98
  84. package/test/parallel_insert.test.js +0 -44
  85. package/test/prepare.test.js +0 -427
  86. package/test/profile.test.js +0 -57
  87. package/test/rerun.test.js +0 -50
  88. package/test/scheduling.test.js +0 -44
  89. package/test/serialization.test.js +0 -104
  90. package/test/support/createdb-electron.js +0 -10
  91. package/test/support/createdb.js +0 -47
  92. package/test/support/elmo.png +0 -0
  93. package/test/support/helper.js +0 -37
  94. package/test/support/script.sql +0 -70
  95. package/test/trace.test.js +0 -67
  96. package/test/unicode.test.js +0 -114
  97. package/test/upsert.test.js +0 -27
  98. package/test/verbose.test.js +0 -60
  99. package/test.js +0 -141
  100. package/test.slr.mjs +0 -212
@@ -1,3 +1,54 @@
1
+ /*
2
+ curl -L https://www.sqlite.org/2021/sqlite-autoconf-3360000.tar.gz | tar -xz
3
+ */
4
+ /*jslint-disable*/
5
+ /*
6
+ shRawLibFetch
7
+ {
8
+ "fetchList": [
9
+ {
10
+ "comment": true,
11
+ "url": "https://github.com/sqlite/sqlite/blob/version-3.36.0/LICENSE.md"
12
+ },
13
+ {
14
+ "footer": "\n#endif // SQLITE3_SHELL_C2\n",
15
+ "header": "\n#ifdef SQLITE3_SHELL_C2\n",
16
+ "sh": "cat sqlite-autoconf-3360000/shell.c",
17
+ "url": "https://github.com/sqlite/sqlite/blob/version-3.36.0/autoconf/shell.c"
18
+ }
19
+ ]
20
+ }
21
+ -int sqlite3_regexp_init(
22
+ +// hack-sqlite - disable redundant sqlite3_regexp_init
23
+ +// int sqlite3_regexp_init2(sqlite3 *, char **, const sqlite3_api_routines *);
24
+ +int sqlite3_regexp_init(
25
+ */
26
+
27
+
28
+ /*
29
+ repo https://github.com/sqlite/sqlite/tree/version-3.36.0
30
+ committed 2021-06-18T18:36:39Z
31
+ */
32
+
33
+
34
+ /*
35
+ file https://github.com/sqlite/sqlite/blob/version-3.36.0/LICENSE.md
36
+ */
37
+ /*
38
+ The author disclaims copyright to this source code. In place of
39
+ a legal notice, here is a blessing:
40
+
41
+ * May you do good and not evil.
42
+ * May you find forgiveness for yourself and forgive others.
43
+ * May you share freely, never taking more than you give.
44
+ */
45
+
46
+
47
+ /*
48
+ file https://github.com/sqlite/sqlite/blob/version-3.36.0/autoconf/shell.c
49
+ */
50
+
51
+ #ifdef SQLITE3_SHELL_C2
1
52
  /* DO NOT EDIT!
2
53
  ** This file is automatically generated by the script in the canonical
3
54
  ** SQLite source tree at tool/mkshellc.tcl. That script combines source
@@ -1887,7 +1938,7 @@ static unsigned char *SHA3Final(SHA3Context *p){
1887
1938
  ** Implementation of the sha3(X,SIZE) function.
1888
1939
  **
1889
1940
  ** Return a BLOB which is the SIZE-bit SHA3 hash of X. The default
1890
- ** size is 256. If X is a BLOB, it is hashed as is.
1941
+ ** size is 256. If X is a BLOB, it is hashed as is.
1891
1942
  ** For all other non-NULL types of input, X is converted into a UTF-8 string
1892
1943
  ** and the string is hashed without the trailing 0x00 terminator. The hash
1893
1944
  ** of a NULL value is NULL.
@@ -2189,8 +2240,8 @@ int sqlite3_shathree_init(
2189
2240
  ** directory, NULL.
2190
2241
  **
2191
2242
  ** If a non-NULL value is specified for the optional $dir parameter and
2192
- ** $path is a relative path, then $path is interpreted relative to $dir.
2193
- ** And the paths returned in the "name" column of the table are also
2243
+ ** $path is a relative path, then $path is interpreted relative to $dir.
2244
+ ** And the paths returned in the "name" column of the table are also
2194
2245
  ** relative to directory $dir.
2195
2246
  */
2196
2247
  /* #include "sqlite3ext.h" */
@@ -2240,7 +2291,7 @@ SQLITE_EXTENSION_INIT1
2240
2291
 
2241
2292
 
2242
2293
  /*
2243
- ** Set the result stored by context ctx to a blob containing the
2294
+ ** Set the result stored by context ctx to a blob containing the
2244
2295
  ** contents of file zName. Or, leave the result unchanged (NULL)
2245
2296
  ** if the file does not exist or is unreadable.
2246
2297
  **
@@ -2457,7 +2508,7 @@ static int makeDirectory(
2457
2508
  }
2458
2509
 
2459
2510
  /*
2460
- ** This function does the work for the writefile() UDF. Refer to
2511
+ ** This function does the work for the writefile() UDF. Refer to
2461
2512
  ** header comments at the top of this file for details.
2462
2513
  */
2463
2514
  static int writeFile(
@@ -2571,7 +2622,7 @@ static int writeFile(
2571
2622
  }
2572
2623
 
2573
2624
  /*
2574
- ** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
2625
+ ** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
2575
2626
  ** Refer to header comments at the top of this file for details.
2576
2627
  */
2577
2628
  static void writefileFunc(
@@ -2585,7 +2636,7 @@ static void writefileFunc(
2585
2636
  sqlite3_int64 mtime = -1;
2586
2637
 
2587
2638
  if( argc<2 || argc>4 ){
2588
- sqlite3_result_error(context,
2639
+ sqlite3_result_error(context,
2589
2640
  "wrong number of arguments to function writefile()", -1
2590
2641
  );
2591
2642
  return;
@@ -2655,7 +2706,7 @@ static void lsModeFunc(
2655
2706
 
2656
2707
  #ifndef SQLITE_OMIT_VIRTUALTABLE
2657
2708
 
2658
- /*
2709
+ /*
2659
2710
  ** Cursor type for recursively iterating through a directory structure.
2660
2711
  */
2661
2712
  typedef struct fsdir_cursor fsdir_cursor;
@@ -2803,7 +2854,7 @@ static int fsdirNext(sqlite3_vtab_cursor *cur){
2803
2854
  }
2804
2855
  pCur->iLvl = iNew;
2805
2856
  pLvl = &pCur->aLvl[iNew];
2806
-
2857
+
2807
2858
  pLvl->zDir = pCur->zPath;
2808
2859
  pCur->zPath = 0;
2809
2860
  pLvl->pDir = opendir(pLvl->zDir);
@@ -2934,7 +2985,7 @@ static int fsdirEof(sqlite3_vtab_cursor *cur){
2934
2985
  ** idxNum==2 Both PATH and DIR supplied
2935
2986
  */
2936
2987
  static int fsdirFilter(
2937
- sqlite3_vtab_cursor *cur,
2988
+ sqlite3_vtab_cursor *cur,
2938
2989
  int idxNum, const char *idxStr,
2939
2990
  int argc, sqlite3_value **argv
2940
2991
  ){
@@ -3023,7 +3074,7 @@ static int fsdirBestIndex(
3023
3074
  }
3024
3075
  break;
3025
3076
  }
3026
- }
3077
+ }
3027
3078
  }
3028
3079
  if( seenPath || seenDir ){
3029
3080
  /* If input parameters are unusable, disallow this plan */
@@ -3094,14 +3145,14 @@ static int fsdirRegister(sqlite3 *db){
3094
3145
 
3095
3146
  #endif
3096
3147
  int sqlite3_fileio_init(
3097
- sqlite3 *db,
3098
- char **pzErrMsg,
3148
+ sqlite3 *db,
3149
+ char **pzErrMsg,
3099
3150
  const sqlite3_api_routines *pApi
3100
3151
  ){
3101
3152
  int rc = SQLITE_OK;
3102
3153
  SQLITE_EXTENSION_INIT2(pApi);
3103
3154
  (void)pzErrMsg; /* Unused parameter */
3104
- rc = sqlite3_create_function(db, "readfile", 1,
3155
+ rc = sqlite3_create_function(db, "readfile", 1,
3105
3156
  SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
3106
3157
  readfileFunc, 0, 0);
3107
3158
  if( rc==SQLITE_OK ){
@@ -3470,11 +3521,11 @@ static int completionEof(sqlite3_vtab_cursor *cur){
3470
3521
  /*
3471
3522
  ** This method is called to "rewind" the completion_cursor object back
3472
3523
  ** to the first row of output. This method is always called at least
3473
- ** once prior to any call to completionColumn() or completionRowid() or
3524
+ ** once prior to any call to completionColumn() or completionRowid() or
3474
3525
  ** completionEof().
3475
3526
  */
3476
3527
  static int completionFilter(
3477
- sqlite3_vtab_cursor *pVtabCursor,
3528
+ sqlite3_vtab_cursor *pVtabCursor,
3478
3529
  int idxNum, const char *idxStr,
3479
3530
  int argc, sqlite3_value **argv
3480
3531
  ){
@@ -3566,7 +3617,7 @@ static int completionBestIndex(
3566
3617
  }
3567
3618
 
3568
3619
  /*
3569
- ** This following structure defines all the methods for the
3620
+ ** This following structure defines all the methods for the
3570
3621
  ** completion virtual table.
3571
3622
  */
3572
3623
  static sqlite3_module completionModule = {
@@ -3610,8 +3661,8 @@ int sqlite3CompletionVtabInit(sqlite3 *db){
3610
3661
 
3611
3662
  #endif
3612
3663
  int sqlite3_completion_init(
3613
- sqlite3 *db,
3614
- char **pzErrMsg,
3664
+ sqlite3 *db,
3665
+ char **pzErrMsg,
3615
3666
  const sqlite3_api_routines *pApi
3616
3667
  ){
3617
3668
  int rc = SQLITE_OK;
@@ -3807,7 +3858,7 @@ static sqlite3_vfs apnd_vfs = {
3807
3858
  1024, /* mxPathname */
3808
3859
  0, /* pNext */
3809
3860
  "apndvfs", /* zName */
3810
- 0, /* pAppData (set when registered) */
3861
+ 0, /* pAppData (set when registered) */
3811
3862
  apndOpen, /* xOpen */
3812
3863
  apndDelete, /* xDelete */
3813
3864
  apndAccess, /* xAccess */
@@ -3860,9 +3911,9 @@ static int apndClose(sqlite3_file *pFile){
3860
3911
  ** Read data from an apnd-file.
3861
3912
  */
3862
3913
  static int apndRead(
3863
- sqlite3_file *pFile,
3864
- void *zBuf,
3865
- int iAmt,
3914
+ sqlite3_file *pFile,
3915
+ void *zBuf,
3916
+ int iAmt,
3866
3917
  sqlite_int64 iOfst
3867
3918
  ){
3868
3919
  ApndFile *paf = (ApndFile *)pFile;
@@ -4167,7 +4218,7 @@ static int apndOpen(
4167
4218
  }
4168
4219
  if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
4169
4220
  /* The file being opened appears to be just an ordinary DB. Copy
4170
- ** the base dispatch-table so this instance mimics the base VFS.
4221
+ ** the base dispatch-table so this instance mimics the base VFS.
4171
4222
  */
4172
4223
  memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
4173
4224
  return SQLITE_OK;
@@ -4182,7 +4233,7 @@ static int apndOpen(
4182
4233
  rc = SQLITE_CANTOPEN;
4183
4234
  pFile->pMethods = 0;
4184
4235
  }else{
4185
- /* Round newly added appendvfs location to #define'd page boundary.
4236
+ /* Round newly added appendvfs location to #define'd page boundary.
4186
4237
  ** Note that nothing has yet been written to the underlying file.
4187
4238
  ** The append mark will be written along with first content write.
4188
4239
  ** Until then, paf->iMark value indicates it is not yet written.
@@ -4206,17 +4257,17 @@ static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
4206
4257
  ** All other VFS methods are pass-thrus.
4207
4258
  */
4208
4259
  static int apndAccess(
4209
- sqlite3_vfs *pVfs,
4210
- const char *zPath,
4211
- int flags,
4260
+ sqlite3_vfs *pVfs,
4261
+ const char *zPath,
4262
+ int flags,
4212
4263
  int *pResOut
4213
4264
  ){
4214
4265
  return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
4215
4266
  }
4216
4267
  static int apndFullPathname(
4217
- sqlite3_vfs *pVfs,
4218
- const char *zPath,
4219
- int nOut,
4268
+ sqlite3_vfs *pVfs,
4269
+ const char *zPath,
4270
+ int nOut,
4220
4271
  char *zOut
4221
4272
  ){
4222
4273
  return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
@@ -4265,17 +4316,17 @@ static const char *apndNextSystemCall(sqlite3_vfs *pVfs, const char *zName){
4265
4316
  return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
4266
4317
  }
4267
4318
 
4268
-
4319
+
4269
4320
  #ifdef _WIN32
4270
4321
 
4271
4322
  #endif
4272
- /*
4323
+ /*
4273
4324
  ** This routine is called when the extension is loaded.
4274
4325
  ** Register the new VFS.
4275
4326
  */
4276
4327
  int sqlite3_appendvfs_init(
4277
- sqlite3 *db,
4278
- char **pzErrMsg,
4328
+ sqlite3 *db,
4329
+ char **pzErrMsg,
4279
4330
  const sqlite3_api_routines *pApi
4280
4331
  ){
4281
4332
  int rc = SQLITE_OK;
@@ -4334,7 +4385,7 @@ static FILE *memtraceOut;
4334
4385
  /* Methods that trace memory allocations */
4335
4386
  static void *memtraceMalloc(int n){
4336
4387
  if( memtraceOut ){
4337
- fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
4388
+ fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
4338
4389
  memtraceBase.xRoundup(n));
4339
4390
  }
4340
4391
  return memtraceBase.xMalloc(n);
@@ -4495,8 +4546,8 @@ static int uintCollFunc(
4495
4546
 
4496
4547
  #endif
4497
4548
  int sqlite3_uint_init(
4498
- sqlite3 *db,
4499
- char **pzErrMsg,
4549
+ sqlite3 *db,
4550
+ char **pzErrMsg,
4500
4551
  const sqlite3_api_routines *pApi
4501
4552
  ){
4502
4553
  SQLITE_EXTENSION_INIT2(pApi);
@@ -4649,7 +4700,7 @@ static Decimal *decimal_new(
4649
4700
  p->nFrac = 0;
4650
4701
  }
4651
4702
  }
4652
- if( iExp>0 ){
4703
+ if( iExp>0 ){
4653
4704
  p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
4654
4705
  if( p->a==0 ) goto new_no_mem;
4655
4706
  memset(p->a+p->nDigit, 0, iExp);
@@ -5057,7 +5108,7 @@ static void decimalMulFunc(
5057
5108
  int minFrac;
5058
5109
  UNUSED_PARAMETER(argc);
5059
5110
  if( pA==0 || pA->oom || pA->isNull
5060
- || pB==0 || pB->oom || pB->isNull
5111
+ || pB==0 || pB->oom || pB->isNull
5061
5112
  ){
5062
5113
  goto mul_end;
5063
5114
  }
@@ -5103,8 +5154,8 @@ mul_end:
5103
5154
 
5104
5155
  #endif
5105
5156
  int sqlite3_decimal_init(
5106
- sqlite3 *db,
5107
- char **pzErrMsg,
5157
+ sqlite3 *db,
5158
+ char **pzErrMsg,
5108
5159
  const sqlite3_api_routines *pApi
5109
5160
  ){
5110
5161
  int rc = SQLITE_OK;
@@ -5403,8 +5454,8 @@ static void ieee754func_to_blob(
5403
5454
 
5404
5455
  #endif
5405
5456
  int sqlite3_ieee_init(
5406
- sqlite3 *db,
5407
- char **pzErrMsg,
5457
+ sqlite3 *db,
5458
+ char **pzErrMsg,
5408
5459
  const sqlite3_api_routines *pApi
5409
5460
  ){
5410
5461
  static const struct {
@@ -5419,14 +5470,13 @@ int sqlite3_ieee_init(
5419
5470
  { "ieee754_exponent", 1, 2, ieee754func },
5420
5471
  { "ieee754_to_blob", 1, 0, ieee754func_to_blob },
5421
5472
  { "ieee754_from_blob", 1, 0, ieee754func_from_blob },
5422
-
5423
5473
  };
5424
5474
  unsigned int i;
5425
5475
  int rc = SQLITE_OK;
5426
5476
  SQLITE_EXTENSION_INIT2(pApi);
5427
5477
  (void)pzErrMsg; /* Unused parameter */
5428
5478
  for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){
5429
- rc = sqlite3_create_function(db, aFunc[i].zFName, aFunc[i].nArg,
5479
+ rc = sqlite3_create_function(db, aFunc[i].zFName, aFunc[i].nArg,
5430
5480
  SQLITE_UTF8|SQLITE_INNOCUOUS,
5431
5481
  (void*)&aFunc[i].iAux,
5432
5482
  aFunc[i].xFunc, 0, 0);
@@ -5662,7 +5712,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
5662
5712
  }
5663
5713
  }
5664
5714
 
5665
- /* True to cause run-time checking of the start=, stop=, and/or step=
5715
+ /* True to cause run-time checking of the start=, stop=, and/or step=
5666
5716
  ** parameters. The only reason to do this is for testing the
5667
5717
  ** constraint checking logic for virtual tables in the SQLite core.
5668
5718
  */
@@ -5673,7 +5723,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
5673
5723
  /*
5674
5724
  ** This method is called to "rewind" the series_cursor object back
5675
5725
  ** to the first row of output. This method is always called at least
5676
- ** once prior to any call to seriesColumn() or seriesRowid() or
5726
+ ** once prior to any call to seriesColumn() or seriesRowid() or
5677
5727
  ** seriesEof().
5678
5728
  **
5679
5729
  ** The query plan selected by seriesBestIndex is passed in the idxNum
@@ -5693,7 +5743,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
5693
5743
  ** (so that seriesEof() will return true) if the table is empty.
5694
5744
  */
5695
5745
  static int seriesFilter(
5696
- sqlite3_vtab_cursor *pVtabCursor,
5746
+ sqlite3_vtab_cursor *pVtabCursor,
5697
5747
  int idxNum, const char *idxStrUnused,
5698
5748
  int argc, sqlite3_value **argv
5699
5749
  ){
@@ -5806,7 +5856,7 @@ static int seriesBestIndex(
5806
5856
  return SQLITE_CONSTRAINT;
5807
5857
  }
5808
5858
  if( (idxNum & 3)==3 ){
5809
- /* Both start= and stop= boundaries are available. This is the
5859
+ /* Both start= and stop= boundaries are available. This is the
5810
5860
  ** the preferred case */
5811
5861
  pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0));
5812
5862
  pIdxInfo->estimatedRows = 1000;
@@ -5829,7 +5879,7 @@ static int seriesBestIndex(
5829
5879
  }
5830
5880
 
5831
5881
  /*
5832
- ** This following structure defines all the methods for the
5882
+ ** This following structure defines all the methods for the
5833
5883
  ** generate_series virtual table.
5834
5884
  */
5835
5885
  static sqlite3_module seriesModule = {
@@ -5865,8 +5915,8 @@ static sqlite3_module seriesModule = {
5865
5915
 
5866
5916
  #endif
5867
5917
  int sqlite3_series_init(
5868
- sqlite3 *db,
5869
- char **pzErrMsg,
5918
+ sqlite3 *db,
5919
+ char **pzErrMsg,
5870
5920
  const sqlite3_api_routines *pApi
5871
5921
  ){
5872
5922
  int rc = SQLITE_OK;
@@ -6027,7 +6077,7 @@ static void re_add_state(ReStateSet *pSet, int newState){
6027
6077
 
6028
6078
  /* Extract the next unicode character from *pzIn and return it. Advance
6029
6079
  ** *pzIn to the first byte past the end of the character returned. To
6030
- ** be clear: this routine converts utf8 to unicode. This routine is
6080
+ ** be clear: this routine converts utf8 to unicode. This routine is
6031
6081
  ** optimized for the common case where the next character is a single byte.
6032
6082
  */
6033
6083
  static unsigned re_next_char(ReInput *p){
@@ -6098,7 +6148,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
6098
6148
  /* Look for the initial prefix match, if there is one. */
6099
6149
  if( pRe->nInit ){
6100
6150
  unsigned char x = pRe->zInit[0];
6101
- while( in.i+pRe->nInit<=in.mx
6151
+ while( in.i+pRe->nInit<=in.mx
6102
6152
  && (zIn[in.i]!=x ||
6103
6153
  strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
6104
6154
  ){
@@ -6557,7 +6607,7 @@ static const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){
6557
6607
  /* The following is a performance optimization. If the regex begins with
6558
6608
  ** ".*" (if the input regex lacks an initial "^") and afterwards there are
6559
6609
  ** one or more matching characters, enter those matching characters into
6560
- ** zInit[]. The re_match() routine can then search ahead in the input
6610
+ ** zInit[]. The re_match() routine can then search ahead in the input
6561
6611
  ** string looking for the initial match without having to run the whole
6562
6612
  ** regex engine over the string. Do not worry able trying to match
6563
6613
  ** unicode characters beyond plane 0 - those are very rare and this is
@@ -6637,9 +6687,11 @@ static void re_sql_func(
6637
6687
  #ifdef _WIN32
6638
6688
 
6639
6689
  #endif
6690
+ // hack-sqlite - disable redundant sqlite3_regexp_init
6691
+ // int sqlite3_regexp_init2(sqlite3 *, char **, const sqlite3_api_routines *);
6640
6692
  int sqlite3_regexp_init(
6641
- sqlite3 *db,
6642
- char **pzErrMsg,
6693
+ sqlite3 *db,
6694
+ char **pzErrMsg,
6643
6695
  const sqlite3_api_routines *pApi
6644
6696
  ){
6645
6697
  int rc = SQLITE_OK;
@@ -6733,10 +6785,10 @@ typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
6733
6785
  /*
6734
6786
  ** Definitions for mode bitmasks S_IFDIR, S_IFREG and S_IFLNK.
6735
6787
  **
6736
- ** In some ways it would be better to obtain these values from system
6788
+ ** In some ways it would be better to obtain these values from system
6737
6789
  ** header files. But, the dependency is undesirable and (a) these
6738
6790
  ** have been stable for decades, (b) the values are part of POSIX and
6739
- ** are also made explicit in [man stat], and (c) are part of the
6791
+ ** are also made explicit in [man stat], and (c) are part of the
6740
6792
  ** file format for zip archives.
6741
6793
  */
6742
6794
  #ifndef S_IFDIR
@@ -6749,7 +6801,7 @@ typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
6749
6801
  # define S_IFLNK 0120000
6750
6802
  #endif
6751
6803
 
6752
- static const char ZIPFILE_SCHEMA[] =
6804
+ static const char ZIPFILE_SCHEMA[] =
6753
6805
  "CREATE TABLE y("
6754
6806
  "name PRIMARY KEY," /* 0: Name of file in zip archive */
6755
6807
  "mode," /* 1: POSIX mode for file */
@@ -6770,8 +6822,8 @@ static const char ZIPFILE_SCHEMA[] =
6770
6822
  **
6771
6823
  ** ZIPFILE_NEWENTRY_MADEBY:
6772
6824
  ** Use this value for the "version-made-by" field in new zip file
6773
- ** entries. The upper byte indicates "unix", and the lower byte
6774
- ** indicates that the zip file matches pkzip specification 3.0.
6825
+ ** entries. The upper byte indicates "unix", and the lower byte
6826
+ ** indicates that the zip file matches pkzip specification 3.0.
6775
6827
  ** This is what info-zip seems to do.
6776
6828
  **
6777
6829
  ** ZIPFILE_NEWENTRY_REQUIRED:
@@ -6800,7 +6852,7 @@ static const char ZIPFILE_SCHEMA[] =
6800
6852
  #define ZIPFILE_SIGNATURE_EOCD 0x06054b50
6801
6853
 
6802
6854
  /*
6803
- ** The sizes of the fixed-size part of each of the three main data
6855
+ ** The sizes of the fixed-size part of each of the three main data
6804
6856
  ** structures in a zip archive.
6805
6857
  */
6806
6858
  #define ZIPFILE_LFH_FIXED_SZ 30
@@ -6893,7 +6945,7 @@ struct ZipfileCDS {
6893
6945
  *** uncompressed size 4 bytes
6894
6946
  *** file name length 2 bytes
6895
6947
  *** extra field length 2 bytes
6896
- ***
6948
+ ***
6897
6949
  */
6898
6950
  typedef struct ZipfileLFH ZipfileLFH;
6899
6951
  struct ZipfileLFH {
@@ -6919,7 +6971,7 @@ struct ZipfileEntry {
6919
6971
  ZipfileEntry *pNext; /* Next element in in-memory CDS */
6920
6972
  };
6921
6973
 
6922
- /*
6974
+ /*
6923
6975
  ** Cursor type for zipfile tables.
6924
6976
  */
6925
6977
  typedef struct ZipfileCsr ZipfileCsr;
@@ -6992,7 +7044,7 @@ static void zipfileDequote(char *zIn){
6992
7044
 
6993
7045
  /*
6994
7046
  ** Construct a new ZipfileTab virtual table object.
6995
- **
7047
+ **
6996
7048
  ** argv[0] -> module name ("zipfile")
6997
7049
  ** argv[1] -> database name
6998
7050
  ** argv[2] -> table name
@@ -7060,7 +7112,7 @@ static void zipfileEntryFree(ZipfileEntry *p){
7060
7112
  }
7061
7113
 
7062
7114
  /*
7063
- ** Release resources that should be freed at the end of a write
7115
+ ** Release resources that should be freed at the end of a write
7064
7116
  ** transaction.
7065
7117
  */
7066
7118
  static void zipfileCleanupTransaction(ZipfileTab *pTab){
@@ -7169,7 +7221,7 @@ static void zipfileCursorErr(ZipfileCsr *pCsr, const char *zFmt, ...){
7169
7221
  /*
7170
7222
  ** Read nRead bytes of data from offset iOff of file pFile into buffer
7171
7223
  ** aRead[]. Return SQLITE_OK if successful, or an SQLite error code
7172
- ** otherwise.
7224
+ ** otherwise.
7173
7225
  **
7174
7226
  ** If an error does occur, output variable (*pzErrmsg) may be set to point
7175
7227
  ** to an English language error message. It is the responsibility of the
@@ -7376,7 +7428,7 @@ static int zipfileScanExtra(u8 *aExtra, int nExtra, u32 *pmTime){
7376
7428
  ** File modification date:
7377
7429
  ** Bits 00-04: day
7378
7430
  ** Bits 05-08: month (1-12)
7379
- ** Bits 09-15: years from 1980
7431
+ ** Bits 09-15: years from 1980
7380
7432
  **
7381
7433
  ** https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx
7382
7434
  */
@@ -7436,9 +7488,9 @@ static void zipfileMtimeToDos(ZipfileCDS *pCds, u32 mUnixTime){
7436
7488
  pCds->mDate = pCds->mTime = 0;
7437
7489
  }
7438
7490
 
7439
- assert( mUnixTime<315507600
7440
- || mUnixTime==zipfileMtime(pCds)
7441
- || ((mUnixTime % 2) && mUnixTime-1==zipfileMtime(pCds))
7491
+ assert( mUnixTime<315507600
7492
+ || mUnixTime==zipfileMtime(pCds)
7493
+ || ((mUnixTime % 2) && mUnixTime-1==zipfileMtime(pCds))
7442
7494
  /* || (mUnixTime % 2) */
7443
7495
  );
7444
7496
  }
@@ -7505,7 +7557,7 @@ static int zipfileGetEntry(
7505
7557
 
7506
7558
  if( rc==SQLITE_OK ){
7507
7559
  u32 *pt = &pNew->mUnixTime;
7508
- pNew->cds.zFile = sqlite3_mprintf("%.*s", nFile, aRead);
7560
+ pNew->cds.zFile = sqlite3_mprintf("%.*s", nFile, aRead);
7509
7561
  pNew->aExtra = (u8*)&pNew[1];
7510
7562
  memcpy(pNew->aExtra, &aRead[nFile], nExtra);
7511
7563
  if( pNew->cds.zFile==0 ){
@@ -7533,7 +7585,7 @@ static int zipfileGetEntry(
7533
7585
  memcpy(pNew->aData, &aBlob[pNew->iDataOff], pNew->cds.szCompressed);
7534
7586
  }
7535
7587
  }else{
7536
- *pzErr = sqlite3_mprintf("failed to read LFH at offset %d",
7588
+ *pzErr = sqlite3_mprintf("failed to read LFH at offset %d",
7537
7589
  (int)pNew->cds.iOffset
7538
7590
  );
7539
7591
  }
@@ -7585,8 +7637,8 @@ static int zipfileNext(sqlite3_vtab_cursor *cur){
7585
7637
  return rc;
7586
7638
  }
7587
7639
 
7588
- static void zipfileFree(void *p) {
7589
- sqlite3_free(p);
7640
+ static void zipfileFree(void *p) {
7641
+ sqlite3_free(p);
7590
7642
  }
7591
7643
 
7592
7644
  /*
@@ -7636,7 +7688,7 @@ static void zipfileInflate(
7636
7688
  ** Buffer aIn (size nIn bytes) contains uncompressed data. This function
7637
7689
  ** compresses it and sets (*ppOut) to point to a buffer containing the
7638
7690
  ** compressed data. The caller is responsible for eventually calling
7639
- ** sqlite3_free() to release buffer (*ppOut). Before returning, (*pnOut)
7691
+ ** sqlite3_free() to release buffer (*ppOut). Before returning, (*pnOut)
7640
7692
  ** is set to the size of buffer (*ppOut) in bytes.
7641
7693
  **
7642
7694
  ** If no error occurs, SQLITE_OK is returned. Otherwise, an SQLite error
@@ -7822,8 +7874,8 @@ static int zipfileReadEOCD(
7822
7874
 
7823
7875
  /* Scan backwards looking for the signature bytes */
7824
7876
  for(i=nRead-20; i>=0; i--){
7825
- if( aRead[i]==0x50 && aRead[i+1]==0x4b
7826
- && aRead[i+2]==0x05 && aRead[i+3]==0x06
7877
+ if( aRead[i]==0x50 && aRead[i+1]==0x4b
7878
+ && aRead[i+2]==0x05 && aRead[i+3]==0x06
7827
7879
  ){
7828
7880
  break;
7829
7881
  }
@@ -7848,14 +7900,14 @@ static int zipfileReadEOCD(
7848
7900
  }
7849
7901
 
7850
7902
  /*
7851
- ** Add object pNew to the linked list that begins at ZipfileTab.pFirstEntry
7903
+ ** Add object pNew to the linked list that begins at ZipfileTab.pFirstEntry
7852
7904
  ** and ends with pLastEntry. If argument pBefore is NULL, then pNew is added
7853
7905
  ** to the end of the list. Otherwise, it is added to the list immediately
7854
7906
  ** before pBefore (which is guaranteed to be a part of said list).
7855
7907
  */
7856
7908
  static void zipfileAddEntry(
7857
- ZipfileTab *pTab,
7858
- ZipfileEntry *pBefore,
7909
+ ZipfileTab *pTab,
7910
+ ZipfileEntry *pBefore,
7859
7911
  ZipfileEntry *pNew
7860
7912
  ){
7861
7913
  assert( (pTab->pFirstEntry==0)==(pTab->pLastEntry==0) );
@@ -7901,7 +7953,7 @@ static int zipfileLoadDirectory(ZipfileTab *pTab, const u8 *aBlob, int nBlob){
7901
7953
  ** xFilter callback.
7902
7954
  */
7903
7955
  static int zipfileFilter(
7904
- sqlite3_vtab_cursor *cur,
7956
+ sqlite3_vtab_cursor *cur,
7905
7957
  int idxNum, const char *idxStr,
7906
7958
  int argc, sqlite3_value **argv
7907
7959
  ){
@@ -8055,7 +8107,7 @@ static int zipfileAppendEntry(
8055
8107
  }
8056
8108
 
8057
8109
  static int zipfileGetMode(
8058
- sqlite3_value *pVal,
8110
+ sqlite3_value *pVal,
8059
8111
  int bIsDir, /* If true, default to directory */
8060
8112
  u32 *pMode, /* OUT: Mode value */
8061
8113
  char **pzErr /* OUT: Error message */
@@ -8118,7 +8170,7 @@ static int zipfileBegin(sqlite3_vtab *pVtab){
8118
8170
  }
8119
8171
 
8120
8172
  /* Open a write fd on the file. Also load the entire central directory
8121
- ** structure into memory. During the transaction any new file data is
8173
+ ** structure into memory. During the transaction any new file data is
8122
8174
  ** appended to the archive file, but the central directory is accumulated
8123
8175
  ** in main-memory until the transaction is committed. */
8124
8176
  pTab->pWriteFd = fopen(pTab->zFile, "ab+");
@@ -8191,9 +8243,9 @@ static void zipfileRemoveEntryFromList(ZipfileTab *pTab, ZipfileEntry *pOld){
8191
8243
  ** xUpdate method.
8192
8244
  */
8193
8245
  static int zipfileUpdate(
8194
- sqlite3_vtab *pVtab,
8195
- int nVal,
8196
- sqlite3_value **apVal,
8246
+ sqlite3_vtab *pVtab,
8247
+ int nVal,
8248
+ sqlite3_value **apVal,
8197
8249
  sqlite_int64 *pRowid
8198
8250
  ){
8199
8251
  ZipfileTab *pTab = (ZipfileTab*)pVtab;
@@ -8246,7 +8298,7 @@ static int zipfileUpdate(
8246
8298
  rc = SQLITE_CONSTRAINT;
8247
8299
  }
8248
8300
  if( sqlite3_value_type(apVal[6])!=SQLITE_NULL ){
8249
- zipfileTableErr(pTab, "rawdata must be NULL");
8301
+ zipfileTableErr(pTab, "rawdata must be NULL");
8250
8302
  rc = SQLITE_CONSTRAINT;
8251
8303
  }
8252
8304
 
@@ -8832,7 +8884,7 @@ static int zipfileRegister(sqlite3 *db){
8832
8884
  int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0);
8833
8885
  if( rc==SQLITE_OK ) rc = sqlite3_overload_function(db, "zipfile_cds", -1);
8834
8886
  if( rc==SQLITE_OK ){
8835
- rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0,
8887
+ rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0,
8836
8888
  zipfileStep, zipfileFinal
8837
8889
  );
8838
8890
  }
@@ -8850,8 +8902,8 @@ static int zipfileRegister(sqlite3 *db){
8850
8902
 
8851
8903
  #endif
8852
8904
  int sqlite3_zipfile_init(
8853
- sqlite3 *db,
8854
- char **pzErrMsg,
8905
+ sqlite3 *db,
8906
+ char **pzErrMsg,
8855
8907
  const sqlite3_api_routines *pApi
8856
8908
  ){
8857
8909
  SQLITE_EXTENSION_INIT2(pApi);
@@ -8968,14 +9020,14 @@ static void sqlarUncompressFunc(
8968
9020
 
8969
9021
  #endif
8970
9022
  int sqlite3_sqlar_init(
8971
- sqlite3 *db,
8972
- char **pzErrMsg,
9023
+ sqlite3 *db,
9024
+ char **pzErrMsg,
8973
9025
  const sqlite3_api_routines *pApi
8974
9026
  ){
8975
9027
  int rc = SQLITE_OK;
8976
9028
  SQLITE_EXTENSION_INIT2(pApi);
8977
9029
  (void)pzErrMsg; /* Unused parameter */
8978
- rc = sqlite3_create_function(db, "sqlar_compress", 1,
9030
+ rc = sqlite3_create_function(db, "sqlar_compress", 1,
8979
9031
  SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
8980
9032
  sqlarCompressFunc, 0, 0);
8981
9033
  if( rc==SQLITE_OK ){
@@ -9025,7 +9077,7 @@ sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErr);
9025
9077
  ** By default, sqlite3_expert_analyze() generates sqlite_stat1 data for
9026
9078
  ** each candidate index. This involves scanning and sorting the entire
9027
9079
  ** contents of each user database table once for each candidate index
9028
- ** associated with the table. For large databases, this can be
9080
+ ** associated with the table. For large databases, this can be
9029
9081
  ** prohibitively slow. This option allows the sqlite3expert object to
9030
9082
  ** be configured so that sqlite_stat1 data is instead generated based on a
9031
9083
  ** subset of each table, or so that no sqlite_stat1 data is used at all.
@@ -9085,7 +9137,7 @@ int sqlite3_expert_sql(
9085
9137
  ** add further SQL statements to the analysis.
9086
9138
  **
9087
9139
  ** If successful, SQLITE_OK is returned and (*pzErr) is set to NULL. Or, if
9088
- ** an error occurs, an SQLite error code is returned and (*pzErr) set to
9140
+ ** an error occurs, an SQLite error code is returned and (*pzErr) set to
9089
9141
  ** point to a buffer containing an English language error message. In this
9090
9142
  ** case it is the responsibility of the caller to eventually free the buffer
9091
9143
  ** using sqlite3_free().
@@ -9114,7 +9166,7 @@ int sqlite3_expert_count(sqlite3expert*);
9114
9166
  ** The value passed as the third argument must be one of the EXPERT_REPORT_*
9115
9167
  ** #define constants defined below.
9116
9168
  **
9117
- ** For some EXPERT_REPORT_* parameters, the buffer returned contains
9169
+ ** For some EXPERT_REPORT_* parameters, the buffer returned contains
9118
9170
  ** information relating to a specific SQL statement. In these cases that
9119
9171
  ** SQL statement is identified by the value passed as the second argument.
9120
9172
  ** SQL statements are numbered from 0 in the order in which they are parsed.
@@ -9127,7 +9179,7 @@ int sqlite3_expert_count(sqlite3expert*);
9127
9179
  **
9128
9180
  ** EXPERT_REPORT_INDEXES:
9129
9181
  ** Return a buffer containing the CREATE INDEX statements for all recommended
9130
- ** indexes for statement iStmt. If there are no new recommeded indexes, NULL
9182
+ ** indexes for statement iStmt. If there are no new recommeded indexes, NULL
9131
9183
  ** is returned.
9132
9184
  **
9133
9185
  ** EXPERT_REPORT_PLAN:
@@ -9135,7 +9187,7 @@ int sqlite3_expert_count(sqlite3expert*);
9135
9187
  ** iStmt after the proposed indexes have been added to the database schema.
9136
9188
  **
9137
9189
  ** EXPERT_REPORT_CANDIDATES:
9138
- ** Return a pointer to a buffer containing the CREATE INDEX statements
9190
+ ** Return a pointer to a buffer containing the CREATE INDEX statements
9139
9191
  ** for all indexes that were tested (for all SQL statements). The iStmt
9140
9192
  ** parameter is ignored for EXPERT_REPORT_CANDIDATES calls.
9141
9193
  */
@@ -9150,8 +9202,8 @@ const char *sqlite3_expert_report(sqlite3expert*, int iStmt, int eReport);
9150
9202
  #define EXPERT_REPORT_CANDIDATES 4
9151
9203
 
9152
9204
  /*
9153
- ** Free an (sqlite3expert*) handle and all associated resources. There
9154
- ** should be one call to this function for each successful call to
9205
+ ** Free an (sqlite3expert*) handle and all associated resources. There
9206
+ ** should be one call to this function for each successful call to
9155
9207
  ** sqlite3-expert_new().
9156
9208
  */
9157
9209
  void sqlite3_expert_destroy(sqlite3expert*);
@@ -9177,7 +9229,7 @@ void sqlite3_expert_destroy(sqlite3expert*);
9177
9229
  #include <string.h>
9178
9230
  #include <stdio.h>
9179
9231
 
9180
- #ifndef SQLITE_OMIT_VIRTUALTABLE
9232
+ #ifndef SQLITE_OMIT_VIRTUALTABLE
9181
9233
 
9182
9234
  /* typedef sqlite3_int64 i64; */
9183
9235
  /* typedef sqlite3_uint64 u64; */
@@ -9230,7 +9282,7 @@ struct IdxScan {
9230
9282
  };
9231
9283
 
9232
9284
  /*
9233
- ** Information regarding a single database table. Extracted from
9285
+ ** Information regarding a single database table. Extracted from
9234
9286
  ** "PRAGMA table_info" by function idxGetTableInfo().
9235
9287
  */
9236
9288
  struct IdxColumn {
@@ -9314,7 +9366,7 @@ struct sqlite3expert {
9314
9366
 
9315
9367
 
9316
9368
  /*
9317
- ** Allocate and return nByte bytes of zeroed memory using sqlite3_malloc().
9369
+ ** Allocate and return nByte bytes of zeroed memory using sqlite3_malloc().
9318
9370
  ** If the allocation fails, set *pRc to SQLITE_NOMEM and return NULL.
9319
9371
  */
9320
9372
  static void *idxMalloc(int *pRc, int nByte){
@@ -9370,11 +9422,11 @@ static int idxHashString(const char *z, int n){
9370
9422
  /*
9371
9423
  ** If zKey is already present in the hash table, return non-zero and do
9372
9424
  ** nothing. Otherwise, add an entry with key zKey and payload string zVal to
9373
- ** the hash table passed as the second argument.
9425
+ ** the hash table passed as the second argument.
9374
9426
  */
9375
9427
  static int idxHashAdd(
9376
- int *pRc,
9377
- IdxHash *pHash,
9428
+ int *pRc,
9429
+ IdxHash *pHash,
9378
9430
  const char *zKey,
9379
9431
  const char *zVal
9380
9432
  ){
@@ -9406,7 +9458,7 @@ static int idxHashAdd(
9406
9458
  }
9407
9459
 
9408
9460
  /*
9409
- ** If zKey/nKey is present in the hash table, return a pointer to the
9461
+ ** If zKey/nKey is present in the hash table, return a pointer to the
9410
9462
  ** hash-entry object.
9411
9463
  */
9412
9464
  static IdxHashEntry *idxHashFind(IdxHash *pHash, const char *zKey, int nKey){
@@ -9545,7 +9597,7 @@ static char *expertDequote(const char *zIn){
9545
9597
  return zRet;
9546
9598
  }
9547
9599
 
9548
- /*
9600
+ /*
9549
9601
  ** This function is the implementation of both the xConnect and xCreate
9550
9602
  ** methods of the r-tree virtual table.
9551
9603
  **
@@ -9601,7 +9653,7 @@ static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
9601
9653
  int rc = SQLITE_OK;
9602
9654
  int n = 0;
9603
9655
  IdxScan *pScan;
9604
- const int opmask =
9656
+ const int opmask =
9605
9657
  SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_GT |
9606
9658
  SQLITE_INDEX_CONSTRAINT_LT | SQLITE_INDEX_CONSTRAINT_GE |
9607
9659
  SQLITE_INDEX_CONSTRAINT_LE;
@@ -9618,10 +9670,10 @@ static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
9618
9670
  /* Add the constraints to the IdxScan object */
9619
9671
  for(i=0; i<pIdxInfo->nConstraint; i++){
9620
9672
  struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
9621
- if( pCons->usable
9622
- && pCons->iColumn>=0
9673
+ if( pCons->usable
9674
+ && pCons->iColumn>=0
9623
9675
  && p->pTab->aCol[pCons->iColumn].iPk==0
9624
- && (pCons->op & opmask)
9676
+ && (pCons->op & opmask)
9625
9677
  ){
9626
9678
  IdxConstraint *pNew;
9627
9679
  const char *zColl = sqlite3_vtab_collation(pIdxInfo, i);
@@ -9664,9 +9716,9 @@ static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
9664
9716
  }
9665
9717
 
9666
9718
  static int expertUpdate(
9667
- sqlite3_vtab *pVtab,
9668
- int nData,
9669
- sqlite3_value **azData,
9719
+ sqlite3_vtab *pVtab,
9720
+ int nData,
9721
+ sqlite3_value **azData,
9670
9722
  sqlite_int64 *pRowid
9671
9723
  ){
9672
9724
  (void)pVtab;
@@ -9676,7 +9728,7 @@ static int expertUpdate(
9676
9728
  return SQLITE_OK;
9677
9729
  }
9678
9730
 
9679
- /*
9731
+ /*
9680
9732
  ** Virtual table module xOpen method.
9681
9733
  */
9682
9734
  static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
@@ -9688,7 +9740,7 @@ static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
9688
9740
  return rc;
9689
9741
  }
9690
9742
 
9691
- /*
9743
+ /*
9692
9744
  ** Virtual table module xClose method.
9693
9745
  */
9694
9746
  static int expertClose(sqlite3_vtab_cursor *cur){
@@ -9701,7 +9753,7 @@ static int expertClose(sqlite3_vtab_cursor *cur){
9701
9753
  /*
9702
9754
  ** Virtual table module xEof method.
9703
9755
  **
9704
- ** Return non-zero if the cursor does not currently point to a valid
9756
+ ** Return non-zero if the cursor does not currently point to a valid
9705
9757
  ** record (i.e if the scan has finished), or zero otherwise.
9706
9758
  */
9707
9759
  static int expertEof(sqlite3_vtab_cursor *cur){
@@ -9709,7 +9761,7 @@ static int expertEof(sqlite3_vtab_cursor *cur){
9709
9761
  return pCsr->pData==0;
9710
9762
  }
9711
9763
 
9712
- /*
9764
+ /*
9713
9765
  ** Virtual table module xNext method.
9714
9766
  */
9715
9767
  static int expertNext(sqlite3_vtab_cursor *cur){
@@ -9728,7 +9780,7 @@ static int expertNext(sqlite3_vtab_cursor *cur){
9728
9780
  return rc;
9729
9781
  }
9730
9782
 
9731
- /*
9783
+ /*
9732
9784
  ** Virtual table module xRowid method.
9733
9785
  */
9734
9786
  static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
@@ -9737,7 +9789,7 @@ static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
9737
9789
  return SQLITE_OK;
9738
9790
  }
9739
9791
 
9740
- /*
9792
+ /*
9741
9793
  ** Virtual table module xColumn method.
9742
9794
  */
9743
9795
  static int expertColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
@@ -9750,11 +9802,11 @@ static int expertColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
9750
9802
  return SQLITE_OK;
9751
9803
  }
9752
9804
 
9753
- /*
9805
+ /*
9754
9806
  ** Virtual table module xFilter method.
9755
9807
  */
9756
9808
  static int expertFilter(
9757
- sqlite3_vtab_cursor *cur,
9809
+ sqlite3_vtab_cursor *cur,
9758
9810
  int idxNum, const char *idxStr,
9759
9811
  int argc, sqlite3_value **argv
9760
9812
  ){
@@ -9909,7 +9961,7 @@ static int idxGetTableInfo(
9909
9961
  }
9910
9962
 
9911
9963
  /*
9912
- ** This function is a no-op if *pRc is set to anything other than
9964
+ ** This function is a no-op if *pRc is set to anything other than
9913
9965
  ** SQLITE_OK when it is called.
9914
9966
  **
9915
9967
  ** If *pRc is initially set to SQLITE_OK, then the text specified by
@@ -9999,7 +10051,7 @@ static char *idxAppendColDefn(
9999
10051
 
10000
10052
  /*
10001
10053
  ** Search database dbm for an index compatible with the one idxCreateFromCons()
10002
- ** would create from arguments pScan, pEq and pTail. If no error occurs and
10054
+ ** would create from arguments pScan, pEq and pTail. If no error occurs and
10003
10055
  ** such an index is found, return non-zero. Or, if no such index is found,
10004
10056
  ** return zero.
10005
10057
  **
@@ -10075,7 +10127,7 @@ static int idxFindCompatible(
10075
10127
  static int idxCreateFromCons(
10076
10128
  sqlite3expert *p,
10077
10129
  IdxScan *pScan,
10078
- IdxConstraint *pEq,
10130
+ IdxConstraint *pEq,
10079
10131
  IdxConstraint *pTail
10080
10132
  ){
10081
10133
  sqlite3 *dbm = p->dbm;
@@ -10104,7 +10156,7 @@ static int idxCreateFromCons(
10104
10156
  h += ((h<<3) + zCols[i]);
10105
10157
  }
10106
10158
  zName = sqlite3_mprintf("%s_idx_%08x", zTable, h);
10107
- if( zName==0 ){
10159
+ if( zName==0 ){
10108
10160
  rc = SQLITE_NOMEM;
10109
10161
  }else{
10110
10162
  if( idxIdentifierRequiresQuotes(zTable) ){
@@ -10142,7 +10194,7 @@ static int idxFindConstraint(IdxConstraint *pList, IdxConstraint *p){
10142
10194
  }
10143
10195
 
10144
10196
  static int idxCreateFromWhere(
10145
- sqlite3expert *p,
10197
+ sqlite3expert *p,
10146
10198
  IdxScan *pScan, /* Create indexes for this scan */
10147
10199
  IdxConstraint *pTail /* range/ORDER BY constraints for inclusion */
10148
10200
  ){
@@ -10177,7 +10229,7 @@ static int idxCreateFromWhere(
10177
10229
  }
10178
10230
 
10179
10231
  /*
10180
- ** Create candidate indexes in database [dbm] based on the data in
10232
+ ** Create candidate indexes in database [dbm] based on the data in
10181
10233
  ** linked-list pScan.
10182
10234
  */
10183
10235
  static int idxCreateCandidates(sqlite3expert *p){
@@ -10224,7 +10276,7 @@ static void idxScanFree(IdxScan *pScan, IdxScan *pLast){
10224
10276
  }
10225
10277
 
10226
10278
  /*
10227
- ** Free all elements of the linked list starting from pStatement up
10279
+ ** Free all elements of the linked list starting from pStatement up
10228
10280
  ** until pLast (pLast is not freed).
10229
10281
  */
10230
10282
  static void idxStatementFree(IdxStatement *pStatement, IdxStatement *pLast){
@@ -10263,7 +10315,6 @@ static void idxWriteFree(IdxWrite *pTab){
10263
10315
  }
10264
10316
 
10265
10317
 
10266
-
10267
10318
  /*
10268
10319
  ** This function is called after candidate indexes have been created. It
10269
10320
  ** runs all the queries to see which indexes they prefer, and populates
@@ -10302,8 +10353,8 @@ int idxFindIndexes(
10302
10353
  const char *zIdx = 0;
10303
10354
  if( i+13<nDetail && memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){
10304
10355
  zIdx = &zDetail[i+13];
10305
- }else if( i+22<nDetail
10306
- && memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0
10356
+ }else if( i+22<nDetail
10357
+ && memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0
10307
10358
  ){
10308
10359
  zIdx = &zDetail[i+22];
10309
10360
  }
@@ -10378,15 +10429,15 @@ static int idxAuthCallback(
10378
10429
  }
10379
10430
 
10380
10431
  static int idxProcessOneTrigger(
10381
- sqlite3expert *p,
10382
- IdxWrite *pWrite,
10432
+ sqlite3expert *p,
10433
+ IdxWrite *pWrite,
10383
10434
  char **pzErr
10384
10435
  ){
10385
10436
  static const char *zInt = UNIQUE_TABLE_NAME;
10386
10437
  static const char *zDrop = "DROP TABLE " UNIQUE_TABLE_NAME;
10387
10438
  IdxTable *pTab = pWrite->pTab;
10388
10439
  const char *zTab = pTab->zName;
10389
- const char *zSql =
10440
+ const char *zSql =
10390
10441
  "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_schema "
10391
10442
  "WHERE tbl_name = %Q AND type IN ('table', 'trigger') "
10392
10443
  "ORDER BY type;";
@@ -10427,7 +10478,7 @@ static int idxProcessOneTrigger(
10427
10478
  int i;
10428
10479
  zWrite = idxAppendText(&rc, zWrite, "UPDATE %Q SET ", zInt);
10429
10480
  for(i=0; i<pTab->nCol; i++){
10430
- zWrite = idxAppendText(&rc, zWrite, "%s%Q=?", i==0 ? "" : ", ",
10481
+ zWrite = idxAppendText(&rc, zWrite, "%s%Q=?", i==0 ? "" : ", ",
10431
10482
  pTab->aCol[i].zName
10432
10483
  );
10433
10484
  }
@@ -10515,14 +10566,14 @@ static int idxCreateVtabSchema(sqlite3expert *p, char **pzErrmsg){
10515
10566
  /* The statement the vtab will pass to sqlite3_declare_vtab() */
10516
10567
  zInner = idxAppendText(&rc, 0, "CREATE TABLE x(");
10517
10568
  for(i=0; i<pTab->nCol; i++){
10518
- zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s",
10569
+ zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s",
10519
10570
  (i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl
10520
10571
  );
10521
10572
  }
10522
10573
  zInner = idxAppendText(&rc, zInner, ")");
10523
10574
 
10524
10575
  /* The CVT statement to create the vtab */
10525
- zOuter = idxAppendText(&rc, 0,
10576
+ zOuter = idxAppendText(&rc, 0,
10526
10577
  "CREATE VIRTUAL TABLE %Q USING expert(%Q)", zName, zInner
10527
10578
  );
10528
10579
  if( rc==SQLITE_OK ){
@@ -10660,7 +10711,7 @@ static void idxRemFunc(
10660
10711
 
10661
10712
  static int idxLargestIndex(sqlite3 *db, int *pnMax, char **pzErr){
10662
10713
  int rc = SQLITE_OK;
10663
- const char *zMax =
10714
+ const char *zMax =
10664
10715
  "SELECT max(i.seqno) FROM "
10665
10716
  " sqlite_schema AS s, "
10666
10717
  " pragma_index_list(s.name) AS l, "
@@ -10703,7 +10754,7 @@ static int idxPopulateOneStat1(
10703
10754
  const char *zComma = zCols==0 ? "" : ", ";
10704
10755
  const char *zName = (const char*)sqlite3_column_text(pIndexXInfo, 0);
10705
10756
  const char *zColl = (const char*)sqlite3_column_text(pIndexXInfo, 1);
10706
- zCols = idxAppendText(&rc, zCols,
10757
+ zCols = idxAppendText(&rc, zCols,
10707
10758
  "%sx.%Q IS rem(%d, x.%Q) COLLATE %s", zComma, zName, nCol, zName, zColl
10708
10759
  );
10709
10760
  zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol);
@@ -10800,13 +10851,13 @@ static int idxBuildSampleTable(sqlite3expert *p, const char *zTab){
10800
10851
  ** indexes have already been created in database sqlite3expert.dbm, this
10801
10852
  ** function populates sqlite_stat1 table in the same database.
10802
10853
  **
10803
- ** The stat1 data is generated by querying the
10854
+ ** The stat1 data is generated by querying the
10804
10855
  */
10805
10856
  static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
10806
10857
  int rc = SQLITE_OK;
10807
10858
  int nMax =0;
10808
10859
  struct IdxRemCtx *pCtx = 0;
10809
- struct IdxSampleCtx samplectx;
10860
+ struct IdxSampleCtx samplectx;
10810
10861
  int i;
10811
10862
  i64 iPrev = -100000;
10812
10863
  sqlite3_stmt *pAllIndex = 0;
@@ -10818,7 +10869,7 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
10818
10869
  " sqlite_schema AS s, "
10819
10870
  " pragma_index_list(s.name) AS l "
10820
10871
  "WHERE s.type = 'table'";
10821
- const char *zIndexXInfo =
10872
+ const char *zIndexXInfo =
10822
10873
  "SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
10823
10874
  const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
10824
10875
 
@@ -10874,7 +10925,7 @@ static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
10874
10925
  iPrev = iRowid;
10875
10926
  }
10876
10927
  if( rc==SQLITE_OK && p->iSample<100 ){
10877
- rc = sqlite3_exec(p->dbv,
10928
+ rc = sqlite3_exec(p->dbv,
10878
10929
  "DROP TABLE IF EXISTS temp." UNIQUE_TABLE_NAME, 0,0,0
10879
10930
  );
10880
10931
  }
@@ -10924,12 +10975,12 @@ sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErrmsg){
10924
10975
  sqlite3_db_config(pNew->dbm, SQLITE_DBCONFIG_TRIGGER_EQP, 1, (int*)0);
10925
10976
  }
10926
10977
  }
10927
-
10978
+
10928
10979
 
10929
10980
  /* Copy the entire schema of database [db] into [dbm]. */
10930
10981
  if( rc==SQLITE_OK ){
10931
10982
  sqlite3_stmt *pSql;
10932
- rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
10983
+ rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
10933
10984
  "SELECT sql FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'"
10934
10985
  " AND sql NOT LIKE 'CREATE VIRTUAL %%'"
10935
10986
  );
@@ -11050,8 +11101,8 @@ int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr){
11050
11101
 
11051
11102
  /* Formulate the EXPERT_REPORT_CANDIDATES text */
11052
11103
  for(pEntry=p->hIdx.pFirst; pEntry; pEntry=pEntry->pNext){
11053
- p->zCandidates = idxAppendText(&rc, p->zCandidates,
11054
- "%s;%s%s\n", pEntry->zVal,
11104
+ p->zCandidates = idxAppendText(&rc, p->zCandidates,
11105
+ "%s;%s%s\n", pEntry->zVal,
11055
11106
  pEntry->zVal2 ? " -- stat1: " : "", pEntry->zVal2
11056
11107
  );
11057
11108
  }
@@ -11173,7 +11224,7 @@ void sqlite3_expert_destroy(sqlite3expert *p){
11173
11224
  ** INSERT INTO t1(rowid, a, b) VALUES(5, 'v', 'five');
11174
11225
  ** INSERT INTO t1(rowid, a, b) VALUES(10, 'x', 'ten');
11175
11226
  **
11176
- ** the sqlite_dbdata table contains, as well as from entries related to
11227
+ ** the sqlite_dbdata table contains, as well as from entries related to
11177
11228
  ** page 1, content equivalent to:
11178
11229
  **
11179
11230
  ** INSERT INTO sqlite_dbdata(pgno, cell, field, value) VALUES
@@ -11200,7 +11251,7 @@ void sqlite3_expert_destroy(sqlite3expert *p){
11200
11251
  ** It contains one entry for each b-tree pointer between a parent and
11201
11252
  ** child page in the database.
11202
11253
  */
11203
- #if !defined(SQLITEINT_H)
11254
+ #if !defined(SQLITEINT_H)
11204
11255
  /* #include "sqlite3ext.h" */
11205
11256
 
11206
11257
  /* typedef unsigned char u8; */
@@ -11210,7 +11261,7 @@ SQLITE_EXTENSION_INIT1
11210
11261
  #include <string.h>
11211
11262
  #include <assert.h>
11212
11263
 
11213
- #define DBDATA_PADDING_BYTES 100
11264
+ #define DBDATA_PADDING_BYTES 100
11214
11265
 
11215
11266
  typedef struct DbdataTable DbdataTable;
11216
11267
  typedef struct DbdataCursor DbdataCursor;
@@ -11236,7 +11287,7 @@ struct DbdataCursor {
11236
11287
  int iField; /* Current field number */
11237
11288
  u8 *pHdrPtr;
11238
11289
  u8 *pPtr;
11239
-
11290
+
11240
11291
  sqlite3_int64 iIntkey; /* Integer key value */
11241
11292
  };
11242
11293
 
@@ -11275,7 +11326,7 @@ struct DbdataTable {
11275
11326
  ")"
11276
11327
 
11277
11328
  /*
11278
- ** Connect to an sqlite_dbdata (pAux==0) or sqlite_dbptr (pAux!=0) virtual
11329
+ ** Connect to an sqlite_dbdata (pAux==0) or sqlite_dbptr (pAux!=0) virtual
11279
11330
  ** table.
11280
11331
  */
11281
11332
  static int dbdataConnect(
@@ -11366,7 +11417,6 @@ static int dbdataBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdx){
11366
11417
  pIdx->orderByConsumed = (pIdx->aOrderBy[1].iColumn==1);
11367
11418
  }
11368
11419
  }
11369
-
11370
11420
  }else{
11371
11421
  pIdx->estimatedCost = 100000000;
11372
11422
  pIdx->estimatedRows = 1000000000;
@@ -11394,7 +11444,7 @@ static int dbdataOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
11394
11444
  }
11395
11445
 
11396
11446
  /*
11397
- ** Restore a cursor object to the state it was in when first allocated
11447
+ ** Restore a cursor object to the state it was in when first allocated
11398
11448
  ** by dbdataOpen().
11399
11449
  */
11400
11450
  static void dbdataResetCursor(DbdataCursor *pCsr){
@@ -11425,8 +11475,8 @@ static int dbdataClose(sqlite3_vtab_cursor *pCursor){
11425
11475
  return SQLITE_OK;
11426
11476
  }
11427
11477
 
11428
- /*
11429
- ** Utility methods to decode 16 and 32-bit big-endian unsigned integers.
11478
+ /*
11479
+ ** Utility methods to decode 16 and 32-bit big-endian unsigned integers.
11430
11480
  */
11431
11481
  static unsigned int get_uint16(unsigned char *a){
11432
11482
  return (a[0]<<8)|a[1];
@@ -11533,26 +11583,26 @@ static int dbdataValueBytes(int eType){
11533
11583
  ** result of context object pCtx.
11534
11584
  */
11535
11585
  static void dbdataValue(
11536
- sqlite3_context *pCtx,
11537
- int eType,
11586
+ sqlite3_context *pCtx,
11587
+ int eType,
11538
11588
  u8 *pData,
11539
11589
  int nData
11540
11590
  ){
11541
11591
  if( eType>=0 && dbdataValueBytes(eType)<=nData ){
11542
11592
  switch( eType ){
11543
- case 0:
11544
- case 10:
11545
- case 11:
11593
+ case 0:
11594
+ case 10:
11595
+ case 11:
11546
11596
  sqlite3_result_null(pCtx);
11547
11597
  break;
11548
-
11549
- case 8:
11598
+
11599
+ case 8:
11550
11600
  sqlite3_result_int(pCtx, 0);
11551
11601
  break;
11552
11602
  case 9:
11553
11603
  sqlite3_result_int(pCtx, 1);
11554
11604
  break;
11555
-
11605
+
11556
11606
  case 1: case 2: case 3: case 4: case 5: case 6: case 7: {
11557
11607
  sqlite3_uint64 v = (signed char)pData[0];
11558
11608
  pData++;
@@ -11564,7 +11614,7 @@ static void dbdataValue(
11564
11614
  case 3: v = (v<<8) + pData[0]; pData++;
11565
11615
  case 2: v = (v<<8) + pData[0]; pData++;
11566
11616
  }
11567
-
11617
+
11568
11618
  if( eType==7 ){
11569
11619
  double r;
11570
11620
  memcpy(&r, &v, sizeof(r));
@@ -11574,7 +11624,7 @@ static void dbdataValue(
11574
11624
  }
11575
11625
  break;
11576
11626
  }
11577
-
11627
+
11578
11628
  default: {
11579
11629
  int n = ((eType-12) / 2);
11580
11630
  if( eType % 2 ){
@@ -11635,7 +11685,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
11635
11685
  int iHdr;
11636
11686
  int U, X;
11637
11687
  int nLocal;
11638
-
11688
+
11639
11689
  switch( pCsr->aPage[iOff] ){
11640
11690
  case 0x02:
11641
11691
  nPointer = 4;
@@ -11654,29 +11704,29 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
11654
11704
  if( pCsr->iCell>=pCsr->nCell ){
11655
11705
  bNextPage = 1;
11656
11706
  }else{
11657
-
11707
+
11658
11708
  iOff += 8 + nPointer + pCsr->iCell*2;
11659
11709
  if( iOff>pCsr->nPage ){
11660
11710
  bNextPage = 1;
11661
11711
  }else{
11662
11712
  iOff = get_uint16(&pCsr->aPage[iOff]);
11663
11713
  }
11664
-
11714
+
11665
11715
  /* For an interior node cell, skip past the child-page number */
11666
11716
  iOff += nPointer;
11667
-
11717
+
11668
11718
  /* Load the "byte of payload including overflow" field */
11669
11719
  if( bNextPage || iOff>pCsr->nPage ){
11670
11720
  bNextPage = 1;
11671
11721
  }else{
11672
11722
  iOff += dbdataGetVarint(&pCsr->aPage[iOff], &nPayload);
11673
11723
  }
11674
-
11724
+
11675
11725
  /* If this is a leaf intkey cell, load the rowid */
11676
11726
  if( bHasRowid && !bNextPage && iOff<pCsr->nPage ){
11677
11727
  iOff += dbdataGetVarint(&pCsr->aPage[iOff], &pCsr->iIntkey);
11678
11728
  }
11679
-
11729
+
11680
11730
  /* Figure out how much data to read from the local page */
11681
11731
  U = pCsr->nPage;
11682
11732
  if( bHasRowid ){
@@ -11702,7 +11752,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
11702
11752
  }else{
11703
11753
 
11704
11754
  /* Allocate space for payload. And a bit more to catch small buffer
11705
- ** overruns caused by attempting to read a varint or similar from
11755
+ ** overruns caused by attempting to read a varint or similar from
11706
11756
  ** near the end of a corrupt record. */
11707
11757
  pCsr->pRec = (u8*)sqlite3_malloc64(nPayload+DBDATA_PADDING_BYTES);
11708
11758
  if( pCsr->pRec==0 ) return SQLITE_NOMEM;
@@ -11735,7 +11785,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
11735
11785
  sqlite3_free(aOvfl);
11736
11786
  }
11737
11787
  }
11738
-
11788
+
11739
11789
  iHdr = dbdataGetVarint(pCsr->pRec, &nHdr);
11740
11790
  pCsr->nHdr = nHdr;
11741
11791
  pCsr->pHdrPtr = &pCsr->pRec[iHdr];
@@ -11781,7 +11831,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
11781
11831
  return SQLITE_OK;
11782
11832
  }
11783
11833
 
11784
- /*
11834
+ /*
11785
11835
  ** Return true if the cursor is at EOF.
11786
11836
  */
11787
11837
  static int dbdataEof(sqlite3_vtab_cursor *pCursor){
@@ -11789,9 +11839,9 @@ static int dbdataEof(sqlite3_vtab_cursor *pCursor){
11789
11839
  return pCsr->aPage==0;
11790
11840
  }
11791
11841
 
11792
- /*
11842
+ /*
11793
11843
  ** Determine the size in pages of database zSchema (where zSchema is
11794
- ** "main", "temp" or the name of an attached database) and set
11844
+ ** "main", "temp" or the name of an attached database) and set
11795
11845
  ** pCsr->szDb accordingly. If successful, return SQLITE_OK. Otherwise,
11796
11846
  ** an SQLite error code.
11797
11847
  */
@@ -11813,11 +11863,11 @@ static int dbdataDbsize(DbdataCursor *pCsr, const char *zSchema){
11813
11863
  return rc;
11814
11864
  }
11815
11865
 
11816
- /*
11866
+ /*
11817
11867
  ** xFilter method for sqlite_dbdata and sqlite_dbptr.
11818
11868
  */
11819
11869
  static int dbdataFilter(
11820
- sqlite3_vtab_cursor *pCursor,
11870
+ sqlite3_vtab_cursor *pCursor,
11821
11871
  int idxNum, const char *idxStr,
11822
11872
  int argc, sqlite3_value **argv
11823
11873
  ){
@@ -11844,7 +11894,7 @@ static int dbdataFilter(
11844
11894
  pCsr->pStmt = pTab->pStmt;
11845
11895
  pTab->pStmt = 0;
11846
11896
  }else{
11847
- rc = sqlite3_prepare_v2(pTab->db,
11897
+ rc = sqlite3_prepare_v2(pTab->db,
11848
11898
  "SELECT data FROM sqlite_dbpage(?) WHERE pgno=?", -1,
11849
11899
  &pCsr->pStmt, 0
11850
11900
  );
@@ -11861,12 +11911,12 @@ static int dbdataFilter(
11861
11911
  return rc;
11862
11912
  }
11863
11913
 
11864
- /*
11914
+ /*
11865
11915
  ** Return a column for the sqlite_dbdata or sqlite_dbptr table.
11866
11916
  */
11867
11917
  static int dbdataColumn(
11868
- sqlite3_vtab_cursor *pCursor,
11869
- sqlite3_context *ctx,
11918
+ sqlite3_vtab_cursor *pCursor,
11919
+ sqlite3_context *ctx,
11870
11920
  int i
11871
11921
  ){
11872
11922
  DbdataCursor *pCsr = (DbdataCursor*)pCursor;
@@ -11919,7 +11969,7 @@ static int dbdataColumn(
11919
11969
  return SQLITE_OK;
11920
11970
  }
11921
11971
 
11922
- /*
11972
+ /*
11923
11973
  ** Return the rowid for an sqlite_dbdata or sqlite_dptr table.
11924
11974
  */
11925
11975
  static int dbdataRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
@@ -11971,8 +12021,8 @@ static int sqlite3DbdataRegister(sqlite3 *db){
11971
12021
 
11972
12022
  #endif
11973
12023
  int sqlite3_dbdata_init(
11974
- sqlite3 *db,
11975
- char **pzErrMsg,
12024
+ sqlite3 *db,
12025
+ char **pzErrMsg,
11976
12026
  const sqlite3_api_routines *pApi
11977
12027
  ){
11978
12028
  SQLITE_EXTENSION_INIT2(pApi);
@@ -12349,7 +12399,7 @@ static void editFunc(
12349
12399
  }
12350
12400
  sz = j;
12351
12401
  p[sz] = 0;
12352
- }
12402
+ }
12353
12403
  sqlite3_result_text64(context, (const char*)p, sz,
12354
12404
  sqlite3_free, SQLITE_UTF8);
12355
12405
  }
@@ -13941,7 +13991,7 @@ static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
13941
13991
  ** characters
13942
13992
  */
13943
13993
  static void print_box_line(FILE *out, int N){
13944
- const char zDash[] =
13994
+ const char zDash[] =
13945
13995
  BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24
13946
13996
  BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24;
13947
13997
  const int nDash = sizeof(zDash) - 1;
@@ -13977,7 +14027,6 @@ static void print_box_row_separator(
13977
14027
  }
13978
14028
 
13979
14029
 
13980
-
13981
14030
  /*
13982
14031
  ** Run a prepared statement and output the result in one of the
13983
14032
  ** table-oriented formats: MODE_Column, MODE_Markdown, MODE_Table,
@@ -14224,8 +14273,8 @@ static void exec_prepared_stmt(
14224
14273
  ** caller to eventually free this buffer using sqlite3_free().
14225
14274
  */
14226
14275
  static int expertHandleSQL(
14227
- ShellState *pState,
14228
- const char *zSql,
14276
+ ShellState *pState,
14277
+ const char *zSql,
14229
14278
  char **pzErr
14230
14279
  ){
14231
14280
  assert( pState->expert.pExpert );
@@ -14235,7 +14284,7 @@ static int expertHandleSQL(
14235
14284
 
14236
14285
  /*
14237
14286
  ** This function is called either to silently clean up the object
14238
- ** created by the ".expert" command (if bCancel==1), or to generate a
14287
+ ** created by the ".expert" command (if bCancel==1), or to generate a
14239
14288
  ** report from it and then clean it up (if bCancel==0).
14240
14289
  **
14241
14290
  ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
@@ -14918,7 +14967,7 @@ static const char *(azHelp[]) = {
14918
14967
  " -x Send output as CSV to a spreadsheet (same as \".excel\")",
14919
14968
  #ifdef SQLITE_DEBUG
14920
14969
  ".oom ?--repeat M? ?N? Simulate an OOM error on the N-th allocation",
14921
- #endif
14970
+ #endif
14922
14971
  ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
14923
14972
  " Options:",
14924
14973
  " --append Use appendvfs to append database to the end of FILE",
@@ -15241,7 +15290,7 @@ int deduceDatabaseType(const char *zName, int dfltZip){
15241
15290
  }
15242
15291
  }
15243
15292
  fclose(f);
15244
- return rc;
15293
+ return rc;
15245
15294
  }
15246
15295
 
15247
15296
  #ifndef SQLITE_OMIT_DESERIALIZE
@@ -15342,8 +15391,8 @@ readHexDb_error:
15342
15391
  ** offset (4*<arg2>) of the blob.
15343
15392
  */
15344
15393
  static void shellInt32(
15345
- sqlite3_context *context,
15346
- int argc,
15394
+ sqlite3_context *context,
15395
+ int argc,
15347
15396
  sqlite3_value **argv
15348
15397
  ){
15349
15398
  const unsigned char *pBlob;
@@ -15370,8 +15419,8 @@ static void shellInt32(
15370
15419
  ** using "..." with internal double-quote characters doubled.
15371
15420
  */
15372
15421
  static void shellIdQuote(
15373
- sqlite3_context *context,
15374
- int argc,
15422
+ sqlite3_context *context,
15423
+ int argc,
15375
15424
  sqlite3_value **argv
15376
15425
  ){
15377
15426
  const char *zName = (const char*)sqlite3_value_text(argv[0]);
@@ -15386,8 +15435,8 @@ static void shellIdQuote(
15386
15435
  ** Scalar function "usleep(X)" invokes sqlite3_sleep(X) and returns X.
15387
15436
  */
15388
15437
  static void shellUSleepFunc(
15389
- sqlite3_context *context,
15390
- int argcUnused,
15438
+ sqlite3_context *context,
15439
+ int argcUnused,
15391
15440
  sqlite3_value **argv
15392
15441
  ){
15393
15442
  int sleep = sqlite3_value_int(argv[0]);
@@ -15399,7 +15448,7 @@ static void shellUSleepFunc(
15399
15448
  /*
15400
15449
  ** Scalar function "shell_escape_crnl" used by the .recover command.
15401
15450
  ** The argument passed to this function is the output of built-in
15402
- ** function quote(). If the first character of the input is "'",
15451
+ ** function quote(). If the first character of the input is "'",
15403
15452
  ** indicating that the value passed to quote() was a text value,
15404
15453
  ** then this function searches the input for "\n" and "\r" characters
15405
15454
  ** and adds a wrapper similar to the following:
@@ -15410,8 +15459,8 @@ static void shellUSleepFunc(
15410
15459
  ** of the input is returned.
15411
15460
  */
15412
15461
  static void shellEscapeCrnl(
15413
- sqlite3_context *context,
15414
- int argc,
15462
+ sqlite3_context *context,
15463
+ int argc,
15415
15464
  sqlite3_value **argv
15416
15465
  ){
15417
15466
  const char *zText = (const char*)sqlite3_value_text(argv[0]);
@@ -15510,13 +15559,13 @@ static void open_db(ShellState *p, int openFlags){
15510
15559
  if( p->zDbFilename==0 || p->zDbFilename[0]==0 ){
15511
15560
  p->openMode = SHELL_OPEN_NORMAL;
15512
15561
  }else{
15513
- p->openMode = (u8)deduceDatabaseType(p->zDbFilename,
15562
+ p->openMode = (u8)deduceDatabaseType(p->zDbFilename,
15514
15563
  (openFlags & OPEN_DB_ZIPFILE)!=0);
15515
15564
  }
15516
15565
  }
15517
15566
  switch( p->openMode ){
15518
15567
  case SHELL_OPEN_APPENDVFS: {
15519
- sqlite3_open_v2(p->zDbFilename, &p->db,
15568
+ sqlite3_open_v2(p->zDbFilename, &p->db,
15520
15569
  SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|p->openFlags, "apndvfs");
15521
15570
  break;
15522
15571
  }
@@ -15631,7 +15680,7 @@ void close_db(sqlite3 *db){
15631
15680
  if( rc ){
15632
15681
  utf8_printf(stderr, "Error: sqlite3_close() returns %d: %s\n",
15633
15682
  rc, sqlite3_errmsg(db));
15634
- }
15683
+ }
15635
15684
  }
15636
15685
 
15637
15686
  #if HAVE_READLINE || HAVE_EDITLINE
@@ -16863,16 +16912,16 @@ static int lintDotCommand(
16863
16912
 
16864
16913
  #if !defined SQLITE_OMIT_VIRTUALTABLE
16865
16914
  static void shellPrepare(
16866
- sqlite3 *db,
16867
- int *pRc,
16868
- const char *zSql,
16915
+ sqlite3 *db,
16916
+ int *pRc,
16917
+ const char *zSql,
16869
16918
  sqlite3_stmt **ppStmt
16870
16919
  ){
16871
16920
  *ppStmt = 0;
16872
16921
  if( *pRc==SQLITE_OK ){
16873
16922
  int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
16874
16923
  if( rc!=SQLITE_OK ){
16875
- raw_printf(stderr, "sql error: %s (%d)\n",
16924
+ raw_printf(stderr, "sql error: %s (%d)\n",
16876
16925
  sqlite3_errmsg(db), sqlite3_errcode(db)
16877
16926
  );
16878
16927
  *pRc = rc;
@@ -16888,10 +16937,10 @@ static void shellPrepare(
16888
16937
  ** nuisance compiler warnings about "defined but not used".
16889
16938
  */
16890
16939
  void shellPreparePrintf(
16891
- sqlite3 *db,
16892
- int *pRc,
16940
+ sqlite3 *db,
16941
+ int *pRc,
16893
16942
  sqlite3_stmt **ppStmt,
16894
- const char *zFmt,
16943
+ const char *zFmt,
16895
16944
  ...
16896
16945
  ){
16897
16946
  *ppStmt = 0;
@@ -16917,7 +16966,7 @@ void shellPreparePrintf(
16917
16966
  ** nuisance compiler warnings about "defined but not used".
16918
16967
  */
16919
16968
  void shellFinalize(
16920
- int *pRc,
16969
+ int *pRc,
16921
16970
  sqlite3_stmt *pStmt
16922
16971
  ){
16923
16972
  if( pStmt ){
@@ -16939,7 +16988,7 @@ void shellFinalize(
16939
16988
  ** nuisance compiler warnings about "defined but not used".
16940
16989
  */
16941
16990
  void shellReset(
16942
- int *pRc,
16991
+ int *pRc,
16943
16992
  sqlite3_stmt *pStmt
16944
16993
  ){
16945
16994
  int rc = sqlite3_reset(pStmt);
@@ -16986,7 +17035,7 @@ static int arUsage(FILE *f){
16986
17035
  }
16987
17036
 
16988
17037
  /*
16989
- ** Print an error message for the .ar command to stderr and return
17038
+ ** Print an error message for the .ar command to stderr and return
16990
17039
  ** SQLITE_ERROR.
16991
17040
  */
16992
17041
  static int arErrorMsg(ArCommand *pAr, const char *zFmt, ...){
@@ -17061,7 +17110,7 @@ static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
17061
17110
  /*
17062
17111
  ** Parse the command line for an ".ar" command. The results are written into
17063
17112
  ** structure (*pAr). SQLITE_OK is returned if the command line is parsed
17064
- ** successfully, otherwise an error message is written to stderr and
17113
+ ** successfully, otherwise an error message is written to stderr and
17065
17114
  ** SQLITE_ERROR returned.
17066
17115
  */
17067
17116
  static int arParseCommand(
@@ -17202,7 +17251,7 @@ static int arParseCommand(
17202
17251
 
17203
17252
  /*
17204
17253
  ** This function assumes that all arguments within the ArCommand.azArg[]
17205
- ** array refer to archive members, as for the --extract or --list commands.
17254
+ ** array refer to archive members, as for the --extract or --list commands.
17206
17255
  ** It checks that each of them are present. If any specified file is not
17207
17256
  ** present in the archive, an error is printed to stderr and an error
17208
17257
  ** code returned. Otherwise, if all specified arguments are present in
@@ -17219,7 +17268,7 @@ static int arCheckEntries(ArCommand *pAr){
17219
17268
  sqlite3_stmt *pTest = 0;
17220
17269
 
17221
17270
  shellPreparePrintf(pAr->db, &rc, &pTest,
17222
- "SELECT name FROM %s WHERE name=$name",
17271
+ "SELECT name FROM %s WHERE name=$name",
17223
17272
  pAr->zSrcTable
17224
17273
  );
17225
17274
  j = sqlite3_bind_parameter_index(pTest, "$name");
@@ -17252,8 +17301,8 @@ static int arCheckEntries(ArCommand *pAr){
17252
17301
  ** any non-NULL (*pzWhere) value.
17253
17302
  */
17254
17303
  static void arWhereClause(
17255
- int *pRc,
17256
- ArCommand *pAr,
17304
+ int *pRc,
17305
+ ArCommand *pAr,
17257
17306
  char **pzWhere /* OUT: New WHERE clause */
17258
17307
  ){
17259
17308
  char *zWhere = 0;
@@ -17266,7 +17315,7 @@ static void arWhereClause(
17266
17315
  for(i=0; i<pAr->nArg; i++){
17267
17316
  const char *z = pAr->azArg[i];
17268
17317
  zWhere = sqlite3_mprintf(
17269
- "%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
17318
+ "%z%s name = '%q' OR substr(name,1,%d) = '%q/'",
17270
17319
  zWhere, zSep, z, strlen30(z)+1, z
17271
17320
  );
17272
17321
  if( zWhere==0 ){
@@ -17281,10 +17330,10 @@ static void arWhereClause(
17281
17330
  }
17282
17331
 
17283
17332
  /*
17284
- ** Implementation of .ar "lisT" command.
17333
+ ** Implementation of .ar "lisT" command.
17285
17334
  */
17286
17335
  static int arListCommand(ArCommand *pAr){
17287
- const char *zSql = "SELECT %s FROM %s WHERE %s";
17336
+ const char *zSql = "SELECT %s FROM %s WHERE %s";
17288
17337
  const char *azCols[] = {
17289
17338
  "name",
17290
17339
  "lsmode(mode), sz, datetime(mtime, 'unixepoch'), name"
@@ -17306,7 +17355,7 @@ static int arListCommand(ArCommand *pAr){
17306
17355
  if( pAr->bVerbose ){
17307
17356
  utf8_printf(pAr->p->out, "%s % 10d %s %s\n",
17308
17357
  sqlite3_column_text(pSql, 0),
17309
- sqlite3_column_int(pSql, 1),
17358
+ sqlite3_column_int(pSql, 1),
17310
17359
  sqlite3_column_text(pSql, 2),
17311
17360
  sqlite3_column_text(pSql, 3)
17312
17361
  );
@@ -17322,17 +17371,17 @@ static int arListCommand(ArCommand *pAr){
17322
17371
 
17323
17372
 
17324
17373
  /*
17325
- ** Implementation of .ar "eXtract" command.
17374
+ ** Implementation of .ar "eXtract" command.
17326
17375
  */
17327
17376
  static int arExtractCommand(ArCommand *pAr){
17328
- const char *zSql1 =
17377
+ const char *zSql1 =
17329
17378
  "SELECT "
17330
17379
  " ($dir || name),"
17331
17380
  " writefile(($dir || name), %s, mode, mtime) "
17332
17381
  "FROM %s WHERE (%s) AND (data IS NULL OR $dirOnly = 0)"
17333
17382
  " AND name NOT GLOB '*..[/\\]*'";
17334
17383
 
17335
- const char *azExtraArg[] = {
17384
+ const char *azExtraArg[] = {
17336
17385
  "sqlar_uncompress(data, sz)",
17337
17386
  "data"
17338
17387
  };
@@ -17358,7 +17407,7 @@ static int arExtractCommand(ArCommand *pAr){
17358
17407
  if( zDir==0 ) rc = SQLITE_NOMEM;
17359
17408
  }
17360
17409
 
17361
- shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
17410
+ shellPreparePrintf(pAr->db, &rc, &pSql, zSql1,
17362
17411
  azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere
17363
17412
  );
17364
17413
 
@@ -17436,7 +17485,7 @@ static int arCreateOrUpdateCommand(
17436
17485
  int bUpdate, /* true for a --create. */
17437
17486
  int bOnlyIfChanged /* Only update if file has changed */
17438
17487
  ){
17439
- const char *zCreate =
17488
+ const char *zCreate =
17440
17489
  "CREATE TABLE IF NOT EXISTS sqlar(\n"
17441
17490
  " name TEXT PRIMARY KEY, -- name of the file\n"
17442
17491
  " mode INT, -- access permissions\n"
@@ -17478,7 +17527,7 @@ static int arCreateOrUpdateCommand(
17478
17527
  arExecSql(pAr, "PRAGMA page_size=512");
17479
17528
  rc = arExecSql(pAr, "SAVEPOINT ar;");
17480
17529
  if( rc!=SQLITE_OK ) return rc;
17481
- zTemp[0] = 0;
17530
+ zTemp[0] = 0;
17482
17531
  if( pAr->bZip ){
17483
17532
  /* Initialize the zipfile virtual table, if necessary */
17484
17533
  if( pAr->zFile ){
@@ -17572,7 +17621,7 @@ static int arDotCommand(
17572
17621
  }else if( cmd.zFile ){
17573
17622
  int flags;
17574
17623
  if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
17575
- if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
17624
+ if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
17576
17625
  || cmd.eCmd==AR_CMD_UPDATE ){
17577
17626
  flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
17578
17627
  }else{
@@ -17583,10 +17632,10 @@ static int arDotCommand(
17583
17632
  utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile,
17584
17633
  eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : "");
17585
17634
  }
17586
- rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
17635
+ rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags,
17587
17636
  eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0);
17588
17637
  if( rc!=SQLITE_OK ){
17589
- utf8_printf(stderr, "cannot open file: %s (%s)\n",
17638
+ utf8_printf(stderr, "cannot open file: %s (%s)\n",
17590
17639
  cmd.zFile, sqlite3_errmsg(cmd.db)
17591
17640
  );
17592
17641
  goto end_ar_command;
@@ -17595,7 +17644,6 @@ static int arDotCommand(
17595
17644
  sqlite3_sqlar_init(cmd.db, 0, 0);
17596
17645
  sqlite3_create_function(cmd.db, "shell_putsnl", 1, SQLITE_UTF8, cmd.p,
17597
17646
  shellPutsFunc, 0, 0);
17598
-
17599
17647
  }
17600
17648
  if( cmd.zSrcTable==0 && cmd.bZip==0 && cmd.eCmd!=AR_CMD_HELP ){
17601
17649
  if( cmd.eCmd!=AR_CMD_CREATE
@@ -17708,12 +17756,12 @@ static void *shellMalloc(int *pRc, sqlite3_int64 nByte){
17708
17756
  /*
17709
17757
  ** If *pRc is not SQLITE_OK when this function is called, it is a no-op.
17710
17758
  ** Otherwise, zFmt is treated as a printf() style string. The result of
17711
- ** formatting it along with any trailing arguments is written into a
17759
+ ** formatting it along with any trailing arguments is written into a
17712
17760
  ** buffer obtained from sqlite3_malloc(), and pointer to which is returned.
17713
17761
  ** It is the responsibility of the caller to eventually free this buffer
17714
17762
  ** using a call to sqlite3_free().
17715
- **
17716
- ** If an OOM error occurs, (*pRc) is set to SQLITE_NOMEM and a NULL
17763
+ **
17764
+ ** If an OOM error occurs, (*pRc) is set to SQLITE_NOMEM and a NULL
17717
17765
  ** pointer returned.
17718
17766
  */
17719
17767
  static char *shellMPrintf(int *pRc, const char *zFmt, ...){
@@ -17772,7 +17820,7 @@ static RecoverTable *recoverNewTable(
17772
17820
  int *pRc, /* IN/OUT: Error code */
17773
17821
  const char *zName, /* Name of table */
17774
17822
  const char *zSql, /* CREATE TABLE statement */
17775
- int bIntkey,
17823
+ int bIntkey,
17776
17824
  int nCol
17777
17825
  ){
17778
17826
  sqlite3 *dbtmp = 0; /* sqlite3 handle for testing CREATE TABLE */
@@ -17784,7 +17832,7 @@ static RecoverTable *recoverNewTable(
17784
17832
  int nSqlCol = 0;
17785
17833
  int bSqlIntkey = 0;
17786
17834
  sqlite3_stmt *pStmt = 0;
17787
-
17835
+
17788
17836
  rc = sqlite3_open("", &dbtmp);
17789
17837
  if( rc==SQLITE_OK ){
17790
17838
  sqlite3_create_function(dbtmp, "shell_idquote", 1, SQLITE_UTF8, 0,
@@ -17800,7 +17848,7 @@ static RecoverTable *recoverNewTable(
17800
17848
  goto finished;
17801
17849
  }
17802
17850
  }
17803
- shellPreparePrintf(dbtmp, &rc, &pStmt,
17851
+ shellPreparePrintf(dbtmp, &rc, &pStmt,
17804
17852
  "SELECT count(*) FROM pragma_table_info(%Q)", zName
17805
17853
  );
17806
17854
  if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
@@ -17812,7 +17860,7 @@ static RecoverTable *recoverNewTable(
17812
17860
  goto finished;
17813
17861
  }
17814
17862
 
17815
- shellPreparePrintf(dbtmp, &rc, &pStmt,
17863
+ shellPreparePrintf(dbtmp, &rc, &pStmt,
17816
17864
  "SELECT ("
17817
17865
  " SELECT substr(data,1,1)==X'0D' FROM sqlite_dbpage WHERE pgno=rootpage"
17818
17866
  ") FROM sqlite_schema WHERE name = %Q", zName
@@ -17834,7 +17882,7 @@ static RecoverTable *recoverNewTable(
17834
17882
  ** leave zPk as "_rowid_" and pTab->iPk at -2. */
17835
17883
  pTab->iPk = -2;
17836
17884
  if( bIntkey ){
17837
- shellPreparePrintf(dbtmp, &rc, &pPkFinder,
17885
+ shellPreparePrintf(dbtmp, &rc, &pPkFinder,
17838
17886
  "SELECT cid, name FROM pragma_table_info(%Q) "
17839
17887
  " WHERE pk=1 AND type='integer' COLLATE nocase"
17840
17888
  " AND NOT EXISTS (SELECT cid FROM pragma_table_info(%Q) WHERE pk=2)"
@@ -17856,11 +17904,11 @@ static RecoverTable *recoverNewTable(
17856
17904
  pTab->azlCol[0] = shellMPrintf(&rc, "");
17857
17905
  }
17858
17906
  i = 1;
17859
- shellPreparePrintf(dbtmp, &rc, &pStmt,
17907
+ shellPreparePrintf(dbtmp, &rc, &pStmt,
17860
17908
  "SELECT %Q || group_concat(shell_idquote(name), ', ') "
17861
17909
  " FILTER (WHERE cid!=%d) OVER (ORDER BY %s cid) "
17862
- "FROM pragma_table_info(%Q)",
17863
- bIntkey ? ", " : "", pTab->iPk,
17910
+ "FROM pragma_table_info(%Q)",
17911
+ bIntkey ? ", " : "", pTab->iPk,
17864
17912
  bIntkey ? "" : "(CASE WHEN pk=0 THEN 1000000 ELSE pk END), ",
17865
17913
  zName
17866
17914
  );
@@ -17894,7 +17942,7 @@ static RecoverTable *recoverNewTable(
17894
17942
  ** those.
17895
17943
  **
17896
17944
  ** If a table is found, a (RecoverTable*) object is returned. Or, if
17897
- ** no such table is found, but bIntkey is false and iRoot is the
17945
+ ** no such table is found, but bIntkey is false and iRoot is the
17898
17946
  ** root page of an index in the recovered schema, then (*pbNoop) is
17899
17947
  ** set to true and NULL returned. Or, if there is no such table or
17900
17948
  ** index, NULL is returned and (*pbNoop) set to 0, indicating that
@@ -17988,7 +18036,7 @@ static RecoverTable *recoverOrphanTable(
17988
18036
  recoverFreeTable(pTab);
17989
18037
  pTab = 0;
17990
18038
  }else{
17991
- raw_printf(pState->out,
18039
+ raw_printf(pState->out,
17992
18040
  "CREATE TABLE %s(rootpgno INTEGER, "
17993
18041
  "pgno INTEGER, nfield INTEGER, id INTEGER", pTab->zQuoted
17994
18042
  );
@@ -18041,14 +18089,14 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18041
18089
  bRowids = 0;
18042
18090
  }
18043
18091
  else{
18044
- utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
18092
+ utf8_printf(stderr, "unexpected option: %s\n", azArg[i]);
18045
18093
  showHelp(pState->out, azArg[0]);
18046
18094
  return 1;
18047
18095
  }
18048
18096
  }
18049
18097
 
18050
18098
  shellExecPrintf(pState->db, &rc,
18051
- /* Attach an in-memory database named 'recovery'. Create an indexed
18099
+ /* Attach an in-memory database named 'recovery'. Create an indexed
18052
18100
  ** cache of the sqlite_dbptr virtual table. */
18053
18101
  "PRAGMA writable_schema = on;"
18054
18102
  "ATTACH %Q AS recovery;"
@@ -18082,9 +18130,9 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18082
18130
  }
18083
18131
 
18084
18132
  /* If this is an auto-vacuum database, add all pointer-map pages to
18085
- ** the freelist table. Do this regardless of whether or not
18133
+ ** the freelist table. Do this regardless of whether or not
18086
18134
  ** --freelist-corrupt was specified. */
18087
- shellExec(pState->db, &rc,
18135
+ shellExec(pState->db, &rc,
18088
18136
  "WITH ptrmap(pgno) AS ("
18089
18137
  " SELECT 2 WHERE shell_int32("
18090
18138
  " (SELECT data FROM sqlite_dbpage WHERE pgno=1), 13"
@@ -18096,7 +18144,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18096
18144
  "REPLACE INTO recovery.freelist SELECT pgno FROM ptrmap"
18097
18145
  );
18098
18146
 
18099
- shellExec(pState->db, &rc,
18147
+ shellExec(pState->db, &rc,
18100
18148
  "CREATE TABLE recovery.dbptr("
18101
18149
  " pgno, child, PRIMARY KEY(child, pgno)"
18102
18150
  ") WITHOUT ROWID;"
@@ -18116,7 +18164,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18116
18164
  ");"
18117
18165
 
18118
18166
  /* Create the "map" table that will (eventually) contain instructions
18119
- ** for dealing with each page in the db that contains one or more
18167
+ ** for dealing with each page in the db that contains one or more
18120
18168
  ** records. */
18121
18169
  "CREATE TABLE recovery.map("
18122
18170
  "pgno INTEGER PRIMARY KEY, maxlen INT, intkey, root INT"
@@ -18165,7 +18213,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18165
18213
  "CREATE INDEX recovery.schema_rootpage ON schema(rootpage);"
18166
18214
  );
18167
18215
 
18168
- /* Open a transaction, then print out all non-virtual, non-"sqlite_%"
18216
+ /* Open a transaction, then print out all non-virtual, non-"sqlite_%"
18169
18217
  ** CREATE TABLE statements that extracted from the existing schema. */
18170
18218
  if( rc==SQLITE_OK ){
18171
18219
  sqlite3_stmt *pStmt = 0;
@@ -18182,7 +18230,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18182
18230
  );
18183
18231
  while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
18184
18232
  const char *zCreateTable = (const char*)sqlite3_column_text(pStmt, 0);
18185
- raw_printf(pState->out, "CREATE TABLE IF NOT EXISTS %s;\n",
18233
+ raw_printf(pState->out, "CREATE TABLE IF NOT EXISTS %s;\n",
18186
18234
  &zCreateTable[12]
18187
18235
  );
18188
18236
  }
@@ -18191,7 +18239,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18191
18239
 
18192
18240
  /* Figure out if an orphan table will be required. And if so, how many
18193
18241
  ** user columns it should contain */
18194
- shellPrepare(pState->db, &rc,
18242
+ shellPrepare(pState->db, &rc,
18195
18243
  "SELECT coalesce(max(maxlen), -2) FROM recovery.map WHERE root>1"
18196
18244
  , &pLoop
18197
18245
  );
@@ -18215,8 +18263,8 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18215
18263
  );
18216
18264
 
18217
18265
  /* Loop through each root page. */
18218
- shellPrepare(pState->db, &rc,
18219
- "SELECT root, intkey, max(maxlen) FROM recovery.map"
18266
+ shellPrepare(pState->db, &rc,
18267
+ "SELECT root, intkey, max(maxlen) FROM recovery.map"
18220
18268
  " WHERE root>1 GROUP BY root, intkey ORDER BY root=("
18221
18269
  " SELECT rootpage FROM recovery.schema WHERE name='sqlite_sequence'"
18222
18270
  ")", &pLoop
@@ -18269,13 +18317,13 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18269
18317
 
18270
18318
  nField = nField+1;
18271
18319
  if( pTab2==pOrphan ){
18272
- raw_printf(pState->out,
18320
+ raw_printf(pState->out,
18273
18321
  "INSERT INTO %s VALUES(%d, %d, %d, %s%s%s);\n",
18274
18322
  pTab2->zQuoted, iRoot, iPgno, nField,
18275
18323
  iMin<0 ? "" : "NULL, ", zVal, pTab2->azlCol[nField]
18276
18324
  );
18277
18325
  }else{
18278
- raw_printf(pState->out, "INSERT INTO %s(%s) VALUES( %s );\n",
18326
+ raw_printf(pState->out, "INSERT INTO %s(%s) VALUES( %s );\n",
18279
18327
  pTab2->zQuoted, pTab2->azlCol[nField], zVal
18280
18328
  );
18281
18329
  }
@@ -18293,7 +18341,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18293
18341
  /* The rest of the schema */
18294
18342
  if( rc==SQLITE_OK ){
18295
18343
  sqlite3_stmt *pStmt = 0;
18296
- shellPrepare(pState->db, &rc,
18344
+ shellPrepare(pState->db, &rc,
18297
18345
  "SELECT sql, name FROM recovery.schema "
18298
18346
  "WHERE sql NOT LIKE 'create table%'", &pStmt
18299
18347
  );
@@ -18301,7 +18349,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
18301
18349
  const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
18302
18350
  if( sqlite3_strnicmp(zSql, "create virt", 11)==0 ){
18303
18351
  const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
18304
- char *zPrint = shellMPrintf(&rc,
18352
+ char *zPrint = shellMPrintf(&rc,
18305
18353
  "INSERT INTO sqlite_schema VALUES('table', %Q, %Q, 0, %Q)",
18306
18354
  zName, zName, zSql
18307
18355
  );
@@ -18437,7 +18485,7 @@ static int do_meta_command(char *zLine, ShellState *p){
18437
18485
  return 1;
18438
18486
  }
18439
18487
  if( zDb==0 ) zDb = "main";
18440
- rc = sqlite3_open_v2(zDestFile, &pDest,
18488
+ rc = sqlite3_open_v2(zDestFile, &pDest,
18441
18489
  SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
18442
18490
  if( rc!=SQLITE_OK ){
18443
18491
  utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
@@ -18631,7 +18679,7 @@ static int do_meta_command(char *zLine, ShellState *p){
18631
18679
  if( nArg>1 && ii==ArraySize(aDbConfig) ){
18632
18680
  utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
18633
18681
  utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
18634
- }
18682
+ }
18635
18683
  }else
18636
18684
 
18637
18685
  if( c=='d' && n>=3 && strncmp(azArg[0], "dbinfo", n)==0 ){
@@ -18651,7 +18699,7 @@ static int do_meta_command(char *zLine, ShellState *p){
18651
18699
  int i;
18652
18700
  int savedShowHeader = p->showHeader;
18653
18701
  int savedShellFlags = p->shellFlgs;
18654
- ShellClearFlag(p,
18702
+ ShellClearFlag(p,
18655
18703
  SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo
18656
18704
  |SHFLG_DumpDataOnly|SHFLG_DumpNoSys);
18657
18705
  for(i=1; i<nArg; i++){
@@ -18698,7 +18746,7 @@ static int do_meta_command(char *zLine, ShellState *p){
18698
18746
  " substr(o.name, 1, length(name)+1) == (name||'_')"
18699
18747
  ")", azArg[i], azArg[i]
18700
18748
  );
18701
-
18749
+
18702
18750
  if( zLike ){
18703
18751
  zLike = sqlite3_mprintf("%z OR %z", zLike, zExpr);
18704
18752
  }else{
@@ -18841,7 +18889,7 @@ static int do_meta_command(char *zLine, ShellState *p){
18841
18889
  } aCtrl[] = {
18842
18890
  { "chunk_size", SQLITE_FCNTL_CHUNK_SIZE, "SIZE" },
18843
18891
  { "data_version", SQLITE_FCNTL_DATA_VERSION, "" },
18844
- { "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
18892
+ { "has_moved", SQLITE_FCNTL_HAS_MOVED, "" },
18845
18893
  { "lock_timeout", SQLITE_FCNTL_LOCK_TIMEOUT, "MILLISEC" },
18846
18894
  { "persist_wal", SQLITE_FCNTL_PERSIST_WAL, "[BOOLEAN]" },
18847
18895
  /* { "pragma", SQLITE_FCNTL_PRAGMA, "NAME ARG" },*/
@@ -18862,7 +18910,7 @@ static int do_meta_command(char *zLine, ShellState *p){
18862
18910
  open_db(p, 0);
18863
18911
  zCmd = nArg>=2 ? azArg[1] : "help";
18864
18912
 
18865
- if( zCmd[0]=='-'
18913
+ if( zCmd[0]=='-'
18866
18914
  && (strcmp(zCmd,"--schema")==0 || strcmp(zCmd,"-schema")==0)
18867
18915
  && nArg>=4
18868
18916
  ){
@@ -19127,7 +19175,7 @@ static int do_meta_command(char *zLine, ShellState *p){
19127
19175
  goto meta_command_exit;
19128
19176
  }
19129
19177
  if( nSep>1 ){
19130
- raw_printf(stderr,
19178
+ raw_printf(stderr,
19131
19179
  "Error: multi-character column separators not allowed"
19132
19180
  " for import\n");
19133
19181
  rc = 1;
@@ -22379,3 +22427,10 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
22379
22427
  memset(&data, 0, sizeof(data));
22380
22428
  return rc;
22381
22429
  }
22430
+ #endif // SQLITE3_SHELL_C2
22431
+
22432
+
22433
+ /*
22434
+ file none
22435
+ */
22436
+ /*jslint-enable*/