Fossil SCM

Update the built-in SQLite to the latest version from the SQLite trunk.

drh 2011-03-24 01:51 trunk
Commit 3d2e8b2ddf9938267e3fd41f52dbbbdb24d1b229
3 files changed +80 -27 +835 -403 +52 -13
+80 -27
--- src/shell.c
+++ src/shell.c
@@ -417,10 +417,11 @@
417417
struct previous_mode_data explainPrev;
418418
/* Holds the mode information just before
419419
** .explain ON */
420420
char outfile[FILENAME_MAX]; /* Filename for *out */
421421
const char *zDbFilename; /* name of the database file */
422
+ const char *zVfs; /* Name of VFS to use */
422423
sqlite3_stmt *pStmt; /* Current statement if any. */
423424
FILE *pLog; /* Write log output here */
424425
};
425426
426427
/*
@@ -1848,11 +1849,11 @@
18481849
rc = 1;
18491850
}
18501851
}else
18511852
#endif
18521853
1853
- if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=1 ){
1854
+ if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){
18541855
const char *zFile = azArg[1];
18551856
if( p->pLog && p->pLog!=stdout && p->pLog!=stderr ){
18561857
fclose(p->pLog);
18571858
p->pLog = 0;
18581859
}
@@ -2170,33 +2171,49 @@
21702171
}
21712172
sqlite3_free_table(azResult);
21722173
}else
21732174
21742175
if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
2176
+ static const struct {
2177
+ const char *zCtrlName; /* Name of a test-control option */
2178
+ int ctrlCode; /* Integer code for that option */
2179
+ } aCtrl[] = {
2180
+ { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE },
2181
+ { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE },
2182
+ { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET },
2183
+ { "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST },
2184
+ { "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL },
2185
+ { "benign_malloc_hooks", SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS },
2186
+ { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE },
2187
+ { "assert", SQLITE_TESTCTRL_ASSERT },
2188
+ { "always", SQLITE_TESTCTRL_ALWAYS },
2189
+ { "reserve", SQLITE_TESTCTRL_RESERVE },
2190
+ { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
2191
+ { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
2192
+ { "pghdrsz", SQLITE_TESTCTRL_PGHDRSZ },
2193
+ { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
2194
+ };
21752195
int testctrl = -1;
21762196
int rc = 0;
2197
+ int i, n;
21772198
open_db(p);
21782199
2179
- /* convert testctrl text option to value. allow only the first
2180
- ** three characters of the option to be used or the numerical
2181
- ** value. */
2182
- if( strncmp( azArg[1], "prng_save", 6 )==0 ) testctrl = SQLITE_TESTCTRL_PRNG_SAVE;
2183
- else if( strncmp( azArg[1], "prng_restore", 10 )==0 ) testctrl = SQLITE_TESTCTRL_PRNG_RESTORE;
2184
- else if( strncmp( azArg[1], "prng_reset", 10 )==0 ) testctrl = SQLITE_TESTCTRL_PRNG_RESET;
2185
- else if( strncmp( azArg[1], "bitvec_test", 6 )==3 ) testctrl = SQLITE_TESTCTRL_BITVEC_TEST;
2186
- else if( strncmp( azArg[1], "fault_install", 6 )==3 ) testctrl = SQLITE_TESTCTRL_FAULT_INSTALL;
2187
- else if( strncmp( azArg[1], "benign_malloc_hooks", 3 )==0 ) testctrl = SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS;
2188
- else if( strncmp( azArg[1], "pending_byte", 3 )==0 ) testctrl = SQLITE_TESTCTRL_PENDING_BYTE;
2189
- else if( strncmp( azArg[1], "assert", 3 )==0 ) testctrl = SQLITE_TESTCTRL_ASSERT;
2190
- else if( strncmp( azArg[1], "always", 3 )==0 ) testctrl = SQLITE_TESTCTRL_ALWAYS;
2191
- else if( strncmp( azArg[1], "reserve", 3 )==0 ) testctrl = SQLITE_TESTCTRL_RESERVE;
2192
- else if( strncmp( azArg[1], "optimizations", 3 )==0 ) testctrl = SQLITE_TESTCTRL_OPTIMIZATIONS;
2193
- else if( strncmp( azArg[1], "iskeyword", 3 )==0 ) testctrl = SQLITE_TESTCTRL_ISKEYWORD;
2194
- else if( strncmp( azArg[1], "pghdrsz", 3 )==0 ) testctrl = SQLITE_TESTCTRL_PGHDRSZ;
2195
- else if( strncmp( azArg[1], "scratchmalloc", 3 )==0 ) testctrl = SQLITE_TESTCTRL_SCRATCHMALLOC;
2196
- else testctrl = atoi(azArg[1]);
2197
-
2200
+ /* convert testctrl text option to value. allow any unique prefix
2201
+ ** of the option name, or a numerical value. */
2202
+ n = strlen(azArg[1]);
2203
+ for(i=0; i<sizeof(aCtrl)/sizeof(aCtrl[0]); i++){
2204
+ if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
2205
+ if( testctrl<0 ){
2206
+ testctrl = aCtrl[i].ctrlCode;
2207
+ }else{
2208
+ fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[i]);
2209
+ testctrl = -1;
2210
+ break;
2211
+ }
2212
+ }
2213
+ }
2214
+ if( testctrl<0 ) testctrl = atoi(azArg[1]);
21982215
if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
21992216
fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
22002217
}else{
22012218
switch(testctrl){
22022219
@@ -2206,11 +2223,12 @@
22062223
if( nArg==3 ){
22072224
int opt = (int)strtol(azArg[2], 0, 0);
22082225
rc = sqlite3_test_control(testctrl, p->db, opt);
22092226
printf("%d (0x%08x)\n", rc, rc);
22102227
} else {
2211
- fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]);
2228
+ fprintf(stderr,"Error: testctrl %s takes a single int option\n",
2229
+ azArg[1]);
22122230
}
22132231
break;
22142232
22152233
/* sqlite3_test_control(int) */
22162234
case SQLITE_TESTCTRL_PRNG_SAVE:
@@ -2230,11 +2248,12 @@
22302248
if( nArg==3 ){
22312249
unsigned int opt = (unsigned int)atoi(azArg[2]);
22322250
rc = sqlite3_test_control(testctrl, opt);
22332251
printf("%d (0x%08x)\n", rc, rc);
22342252
} else {
2235
- fprintf(stderr,"Error: testctrl %s takes a single unsigned int option\n", azArg[1]);
2253
+ fprintf(stderr,"Error: testctrl %s takes a single unsigned"
2254
+ " int option\n", azArg[1]);
22362255
}
22372256
break;
22382257
22392258
/* sqlite3_test_control(int, int) */
22402259
case SQLITE_TESTCTRL_ASSERT:
@@ -2242,11 +2261,12 @@
22422261
if( nArg==3 ){
22432262
int opt = atoi(azArg[2]);
22442263
rc = sqlite3_test_control(testctrl, opt);
22452264
printf("%d (0x%08x)\n", rc, rc);
22462265
} else {
2247
- fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]);
2266
+ fprintf(stderr,"Error: testctrl %s takes a single int option\n",
2267
+ azArg[1]);
22482268
}
22492269
break;
22502270
22512271
/* sqlite3_test_control(int, char *) */
22522272
#ifdef SQLITE_N_KEYWORD
@@ -2254,21 +2274,23 @@
22542274
if( nArg==3 ){
22552275
const char *opt = azArg[2];
22562276
rc = sqlite3_test_control(testctrl, opt);
22572277
printf("%d (0x%08x)\n", rc, rc);
22582278
} else {
2259
- fprintf(stderr,"Error: testctrl %s takes a single char * option\n", azArg[1]);
2279
+ fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
2280
+ azArg[1]);
22602281
}
22612282
break;
22622283
#endif
22632284
22642285
case SQLITE_TESTCTRL_BITVEC_TEST:
22652286
case SQLITE_TESTCTRL_FAULT_INSTALL:
22662287
case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
22672288
case SQLITE_TESTCTRL_SCRATCHMALLOC:
22682289
default:
2269
- fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n", azArg[1]);
2290
+ fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n",
2291
+ azArg[1]);
22702292
break;
22712293
}
22722294
}
22732295
}else
22742296
@@ -2275,11 +2297,13 @@
22752297
if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
22762298
open_db(p);
22772299
sqlite3_busy_timeout(p->db, atoi(azArg[1]));
22782300
}else
22792301
2280
- if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 && nArg==2 ){
2302
+ if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
2303
+ && nArg==2
2304
+ ){
22812305
enableTimer = booleanValue(azArg[1]);
22822306
}else
22832307
22842308
if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){
22852309
int j;
@@ -2462,11 +2486,13 @@
24622486
zSql = 0;
24632487
nSql = 0;
24642488
}
24652489
}
24662490
if( zSql ){
2467
- if( !_all_whitespace(zSql) ) fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
2491
+ if( !_all_whitespace(zSql) ){
2492
+ fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
2493
+ }
24682494
free(zSql);
24692495
}
24702496
free(zLine);
24712497
return errCnt;
24722498
}
@@ -2598,10 +2624,14 @@
25982624
" -list set output mode to 'list'\n"
25992625
" -separator 'x' set output field separator (|)\n"
26002626
" -stats print memory stats before each finalize\n"
26012627
" -nullvalue 'text' set text string for NULL values\n"
26022628
" -version show SQLite version\n"
2629
+ " -vfs NAME use NAME as the default VFS\n"
2630
+#ifdef SQLITE_ENABLE_VFSTRACE
2631
+ " -vfstrace enable tracing of all VFS calls\n"
2632
+#endif
26032633
;
26042634
static void usage(int showDetail){
26052635
fprintf(stderr,
26062636
"Usage: %s [OPTIONS] FILENAME [SQL]\n"
26072637
"FILENAME is the name of an SQLite database. A new database is created\n"
@@ -2682,10 +2712,29 @@
26822712
}
26832713
if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
26842714
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
26852715
sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
26862716
#endif
2717
+#ifdef SQLITE_ENABLE_VFSTRACE
2718
+ }else if( strcmp(argv[i],"-vfstrace")==0 ){
2719
+ extern int vfstrace_register(
2720
+ const char *zTraceName,
2721
+ const char *zOldVfsName,
2722
+ int (*xOut)(const char*,void*),
2723
+ void *pOutArg,
2724
+ int makeDefault
2725
+ );
2726
+ vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1);
2727
+#endif
2728
+ }else if( strcmp(argv[i],"-vfs")==0 ){
2729
+ sqlite3_vfs *pVfs = sqlite3_vfs_find(argv[++i]);
2730
+ if( pVfs ){
2731
+ sqlite3_vfs_register(pVfs, 1);
2732
+ }else{
2733
+ fprintf(stderr, "no such VFS: \"%s\"\n", argv[i]);
2734
+ exit(1);
2735
+ }
26872736
}
26882737
}
26892738
if( i<argc ){
26902739
#if defined(SQLITE_OS_OS2) && SQLITE_OS_OS2
26912740
data.zDbFilename = (const char *)convertCpPathToUtf8( argv[i++] );
@@ -2796,10 +2845,14 @@
27962845
stdin_is_interactive = 1;
27972846
}else if( strcmp(z,"-batch")==0 ){
27982847
stdin_is_interactive = 0;
27992848
}else if( strcmp(z,"-heap")==0 ){
28002849
i++;
2850
+ }else if( strcmp(z,"-vfs")==0 ){
2851
+ i++;
2852
+ }else if( strcmp(z,"-vfstrace")==0 ){
2853
+ i++;
28012854
}else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){
28022855
usage(1);
28032856
}else{
28042857
fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
28052858
fprintf(stderr,"Use -help for a list of options.\n");
28062859
--- src/shell.c
+++ src/shell.c
@@ -417,10 +417,11 @@
417 struct previous_mode_data explainPrev;
418 /* Holds the mode information just before
419 ** .explain ON */
420 char outfile[FILENAME_MAX]; /* Filename for *out */
421 const char *zDbFilename; /* name of the database file */
 
422 sqlite3_stmt *pStmt; /* Current statement if any. */
423 FILE *pLog; /* Write log output here */
424 };
425
426 /*
@@ -1848,11 +1849,11 @@
1848 rc = 1;
1849 }
1850 }else
1851 #endif
1852
1853 if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=1 ){
1854 const char *zFile = azArg[1];
1855 if( p->pLog && p->pLog!=stdout && p->pLog!=stderr ){
1856 fclose(p->pLog);
1857 p->pLog = 0;
1858 }
@@ -2170,33 +2171,49 @@
2170 }
2171 sqlite3_free_table(azResult);
2172 }else
2173
2174 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2175 int testctrl = -1;
2176 int rc = 0;
 
2177 open_db(p);
2178
2179 /* convert testctrl text option to value. allow only the first
2180 ** three characters of the option to be used or the numerical
2181 ** value. */
2182 if( strncmp( azArg[1], "prng_save", 6 )==0 ) testctrl = SQLITE_TESTCTRL_PRNG_SAVE;
2183 else if( strncmp( azArg[1], "prng_restore", 10 )==0 ) testctrl = SQLITE_TESTCTRL_PRNG_RESTORE;
2184 else if( strncmp( azArg[1], "prng_reset", 10 )==0 ) testctrl = SQLITE_TESTCTRL_PRNG_RESET;
2185 else if( strncmp( azArg[1], "bitvec_test", 6 )==3 ) testctrl = SQLITE_TESTCTRL_BITVEC_TEST;
2186 else if( strncmp( azArg[1], "fault_install", 6 )==3 ) testctrl = SQLITE_TESTCTRL_FAULT_INSTALL;
2187 else if( strncmp( azArg[1], "benign_malloc_hooks", 3 )==0 ) testctrl = SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS;
2188 else if( strncmp( azArg[1], "pending_byte", 3 )==0 ) testctrl = SQLITE_TESTCTRL_PENDING_BYTE;
2189 else if( strncmp( azArg[1], "assert", 3 )==0 ) testctrl = SQLITE_TESTCTRL_ASSERT;
2190 else if( strncmp( azArg[1], "always", 3 )==0 ) testctrl = SQLITE_TESTCTRL_ALWAYS;
2191 else if( strncmp( azArg[1], "reserve", 3 )==0 ) testctrl = SQLITE_TESTCTRL_RESERVE;
2192 else if( strncmp( azArg[1], "optimizations", 3 )==0 ) testctrl = SQLITE_TESTCTRL_OPTIMIZATIONS;
2193 else if( strncmp( azArg[1], "iskeyword", 3 )==0 ) testctrl = SQLITE_TESTCTRL_ISKEYWORD;
2194 else if( strncmp( azArg[1], "pghdrsz", 3 )==0 ) testctrl = SQLITE_TESTCTRL_PGHDRSZ;
2195 else if( strncmp( azArg[1], "scratchmalloc", 3 )==0 ) testctrl = SQLITE_TESTCTRL_SCRATCHMALLOC;
2196 else testctrl = atoi(azArg[1]);
2197
2198 if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
2199 fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
2200 }else{
2201 switch(testctrl){
2202
@@ -2206,11 +2223,12 @@
2206 if( nArg==3 ){
2207 int opt = (int)strtol(azArg[2], 0, 0);
2208 rc = sqlite3_test_control(testctrl, p->db, opt);
2209 printf("%d (0x%08x)\n", rc, rc);
2210 } else {
2211 fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]);
 
2212 }
2213 break;
2214
2215 /* sqlite3_test_control(int) */
2216 case SQLITE_TESTCTRL_PRNG_SAVE:
@@ -2230,11 +2248,12 @@
2230 if( nArg==3 ){
2231 unsigned int opt = (unsigned int)atoi(azArg[2]);
2232 rc = sqlite3_test_control(testctrl, opt);
2233 printf("%d (0x%08x)\n", rc, rc);
2234 } else {
2235 fprintf(stderr,"Error: testctrl %s takes a single unsigned int option\n", azArg[1]);
 
2236 }
2237 break;
2238
2239 /* sqlite3_test_control(int, int) */
2240 case SQLITE_TESTCTRL_ASSERT:
@@ -2242,11 +2261,12 @@
2242 if( nArg==3 ){
2243 int opt = atoi(azArg[2]);
2244 rc = sqlite3_test_control(testctrl, opt);
2245 printf("%d (0x%08x)\n", rc, rc);
2246 } else {
2247 fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]);
 
2248 }
2249 break;
2250
2251 /* sqlite3_test_control(int, char *) */
2252 #ifdef SQLITE_N_KEYWORD
@@ -2254,21 +2274,23 @@
2254 if( nArg==3 ){
2255 const char *opt = azArg[2];
2256 rc = sqlite3_test_control(testctrl, opt);
2257 printf("%d (0x%08x)\n", rc, rc);
2258 } else {
2259 fprintf(stderr,"Error: testctrl %s takes a single char * option\n", azArg[1]);
 
2260 }
2261 break;
2262 #endif
2263
2264 case SQLITE_TESTCTRL_BITVEC_TEST:
2265 case SQLITE_TESTCTRL_FAULT_INSTALL:
2266 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
2267 case SQLITE_TESTCTRL_SCRATCHMALLOC:
2268 default:
2269 fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n", azArg[1]);
 
2270 break;
2271 }
2272 }
2273 }else
2274
@@ -2275,11 +2297,13 @@
2275 if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
2276 open_db(p);
2277 sqlite3_busy_timeout(p->db, atoi(azArg[1]));
2278 }else
2279
2280 if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 && nArg==2 ){
 
 
2281 enableTimer = booleanValue(azArg[1]);
2282 }else
2283
2284 if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){
2285 int j;
@@ -2462,11 +2486,13 @@
2462 zSql = 0;
2463 nSql = 0;
2464 }
2465 }
2466 if( zSql ){
2467 if( !_all_whitespace(zSql) ) fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
 
 
2468 free(zSql);
2469 }
2470 free(zLine);
2471 return errCnt;
2472 }
@@ -2598,10 +2624,14 @@
2598 " -list set output mode to 'list'\n"
2599 " -separator 'x' set output field separator (|)\n"
2600 " -stats print memory stats before each finalize\n"
2601 " -nullvalue 'text' set text string for NULL values\n"
2602 " -version show SQLite version\n"
 
 
 
 
2603 ;
2604 static void usage(int showDetail){
2605 fprintf(stderr,
2606 "Usage: %s [OPTIONS] FILENAME [SQL]\n"
2607 "FILENAME is the name of an SQLite database. A new database is created\n"
@@ -2682,10 +2712,29 @@
2682 }
2683 if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
2684 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
2685 sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
2686 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2687 }
2688 }
2689 if( i<argc ){
2690 #if defined(SQLITE_OS_OS2) && SQLITE_OS_OS2
2691 data.zDbFilename = (const char *)convertCpPathToUtf8( argv[i++] );
@@ -2796,10 +2845,14 @@
2796 stdin_is_interactive = 1;
2797 }else if( strcmp(z,"-batch")==0 ){
2798 stdin_is_interactive = 0;
2799 }else if( strcmp(z,"-heap")==0 ){
2800 i++;
 
 
 
 
2801 }else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){
2802 usage(1);
2803 }else{
2804 fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
2805 fprintf(stderr,"Use -help for a list of options.\n");
2806
--- src/shell.c
+++ src/shell.c
@@ -417,10 +417,11 @@
417 struct previous_mode_data explainPrev;
418 /* Holds the mode information just before
419 ** .explain ON */
420 char outfile[FILENAME_MAX]; /* Filename for *out */
421 const char *zDbFilename; /* name of the database file */
422 const char *zVfs; /* Name of VFS to use */
423 sqlite3_stmt *pStmt; /* Current statement if any. */
424 FILE *pLog; /* Write log output here */
425 };
426
427 /*
@@ -1848,11 +1849,11 @@
1849 rc = 1;
1850 }
1851 }else
1852 #endif
1853
1854 if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){
1855 const char *zFile = azArg[1];
1856 if( p->pLog && p->pLog!=stdout && p->pLog!=stderr ){
1857 fclose(p->pLog);
1858 p->pLog = 0;
1859 }
@@ -2170,33 +2171,49 @@
2171 }
2172 sqlite3_free_table(azResult);
2173 }else
2174
2175 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
2176 static const struct {
2177 const char *zCtrlName; /* Name of a test-control option */
2178 int ctrlCode; /* Integer code for that option */
2179 } aCtrl[] = {
2180 { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE },
2181 { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE },
2182 { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET },
2183 { "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST },
2184 { "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL },
2185 { "benign_malloc_hooks", SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS },
2186 { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE },
2187 { "assert", SQLITE_TESTCTRL_ASSERT },
2188 { "always", SQLITE_TESTCTRL_ALWAYS },
2189 { "reserve", SQLITE_TESTCTRL_RESERVE },
2190 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
2191 { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
2192 { "pghdrsz", SQLITE_TESTCTRL_PGHDRSZ },
2193 { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
2194 };
2195 int testctrl = -1;
2196 int rc = 0;
2197 int i, n;
2198 open_db(p);
2199
2200 /* convert testctrl text option to value. allow any unique prefix
2201 ** of the option name, or a numerical value. */
2202 n = strlen(azArg[1]);
2203 for(i=0; i<sizeof(aCtrl)/sizeof(aCtrl[0]); i++){
2204 if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
2205 if( testctrl<0 ){
2206 testctrl = aCtrl[i].ctrlCode;
2207 }else{
2208 fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[i]);
2209 testctrl = -1;
2210 break;
2211 }
2212 }
2213 }
2214 if( testctrl<0 ) testctrl = atoi(azArg[1]);
 
 
 
 
2215 if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
2216 fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
2217 }else{
2218 switch(testctrl){
2219
@@ -2206,11 +2223,12 @@
2223 if( nArg==3 ){
2224 int opt = (int)strtol(azArg[2], 0, 0);
2225 rc = sqlite3_test_control(testctrl, p->db, opt);
2226 printf("%d (0x%08x)\n", rc, rc);
2227 } else {
2228 fprintf(stderr,"Error: testctrl %s takes a single int option\n",
2229 azArg[1]);
2230 }
2231 break;
2232
2233 /* sqlite3_test_control(int) */
2234 case SQLITE_TESTCTRL_PRNG_SAVE:
@@ -2230,11 +2248,12 @@
2248 if( nArg==3 ){
2249 unsigned int opt = (unsigned int)atoi(azArg[2]);
2250 rc = sqlite3_test_control(testctrl, opt);
2251 printf("%d (0x%08x)\n", rc, rc);
2252 } else {
2253 fprintf(stderr,"Error: testctrl %s takes a single unsigned"
2254 " int option\n", azArg[1]);
2255 }
2256 break;
2257
2258 /* sqlite3_test_control(int, int) */
2259 case SQLITE_TESTCTRL_ASSERT:
@@ -2242,11 +2261,12 @@
2261 if( nArg==3 ){
2262 int opt = atoi(azArg[2]);
2263 rc = sqlite3_test_control(testctrl, opt);
2264 printf("%d (0x%08x)\n", rc, rc);
2265 } else {
2266 fprintf(stderr,"Error: testctrl %s takes a single int option\n",
2267 azArg[1]);
2268 }
2269 break;
2270
2271 /* sqlite3_test_control(int, char *) */
2272 #ifdef SQLITE_N_KEYWORD
@@ -2254,21 +2274,23 @@
2274 if( nArg==3 ){
2275 const char *opt = azArg[2];
2276 rc = sqlite3_test_control(testctrl, opt);
2277 printf("%d (0x%08x)\n", rc, rc);
2278 } else {
2279 fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
2280 azArg[1]);
2281 }
2282 break;
2283 #endif
2284
2285 case SQLITE_TESTCTRL_BITVEC_TEST:
2286 case SQLITE_TESTCTRL_FAULT_INSTALL:
2287 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
2288 case SQLITE_TESTCTRL_SCRATCHMALLOC:
2289 default:
2290 fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n",
2291 azArg[1]);
2292 break;
2293 }
2294 }
2295 }else
2296
@@ -2275,11 +2297,13 @@
2297 if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
2298 open_db(p);
2299 sqlite3_busy_timeout(p->db, atoi(azArg[1]));
2300 }else
2301
2302 if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
2303 && nArg==2
2304 ){
2305 enableTimer = booleanValue(azArg[1]);
2306 }else
2307
2308 if( c=='w' && strncmp(azArg[0], "width", n)==0 && nArg>1 ){
2309 int j;
@@ -2462,11 +2486,13 @@
2486 zSql = 0;
2487 nSql = 0;
2488 }
2489 }
2490 if( zSql ){
2491 if( !_all_whitespace(zSql) ){
2492 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
2493 }
2494 free(zSql);
2495 }
2496 free(zLine);
2497 return errCnt;
2498 }
@@ -2598,10 +2624,14 @@
2624 " -list set output mode to 'list'\n"
2625 " -separator 'x' set output field separator (|)\n"
2626 " -stats print memory stats before each finalize\n"
2627 " -nullvalue 'text' set text string for NULL values\n"
2628 " -version show SQLite version\n"
2629 " -vfs NAME use NAME as the default VFS\n"
2630 #ifdef SQLITE_ENABLE_VFSTRACE
2631 " -vfstrace enable tracing of all VFS calls\n"
2632 #endif
2633 ;
2634 static void usage(int showDetail){
2635 fprintf(stderr,
2636 "Usage: %s [OPTIONS] FILENAME [SQL]\n"
2637 "FILENAME is the name of an SQLite database. A new database is created\n"
@@ -2682,10 +2712,29 @@
2712 }
2713 if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
2714 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
2715 sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
2716 #endif
2717 #ifdef SQLITE_ENABLE_VFSTRACE
2718 }else if( strcmp(argv[i],"-vfstrace")==0 ){
2719 extern int vfstrace_register(
2720 const char *zTraceName,
2721 const char *zOldVfsName,
2722 int (*xOut)(const char*,void*),
2723 void *pOutArg,
2724 int makeDefault
2725 );
2726 vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1);
2727 #endif
2728 }else if( strcmp(argv[i],"-vfs")==0 ){
2729 sqlite3_vfs *pVfs = sqlite3_vfs_find(argv[++i]);
2730 if( pVfs ){
2731 sqlite3_vfs_register(pVfs, 1);
2732 }else{
2733 fprintf(stderr, "no such VFS: \"%s\"\n", argv[i]);
2734 exit(1);
2735 }
2736 }
2737 }
2738 if( i<argc ){
2739 #if defined(SQLITE_OS_OS2) && SQLITE_OS_OS2
2740 data.zDbFilename = (const char *)convertCpPathToUtf8( argv[i++] );
@@ -2796,10 +2845,14 @@
2845 stdin_is_interactive = 1;
2846 }else if( strcmp(z,"-batch")==0 ){
2847 stdin_is_interactive = 0;
2848 }else if( strcmp(z,"-heap")==0 ){
2849 i++;
2850 }else if( strcmp(z,"-vfs")==0 ){
2851 i++;
2852 }else if( strcmp(z,"-vfstrace")==0 ){
2853 i++;
2854 }else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){
2855 usage(1);
2856 }else{
2857 fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
2858 fprintf(stderr,"Use -help for a list of options.\n");
2859
+835 -403
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651651
** [sqlite_version()] and [sqlite_source_id()].
652652
*/
653653
#define SQLITE_VERSION "3.7.6"
654654
#define SQLITE_VERSION_NUMBER 3007006
655
-#define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61"
655
+#define SQLITE_SOURCE_ID "2011-03-24 01:34:03 b6e268fce12829f058f1dfa223731ec8479493f8"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -1439,14 +1439,27 @@
14391439
** a 24-hour day).
14401440
** ^SQLite will use the xCurrentTimeInt64() method to get the current
14411441
** date and time if that method is available (if iVersion is 2 or
14421442
** greater and the function pointer is not NULL) and will fall back
14431443
** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1444
+**
1445
+** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
1446
+** are not used by the SQLite core. These optional interfaces are provided
1447
+** by some VFSes to facilitate testing of the VFS code. By overriding
1448
+** system calls with functions under its control, a test program can
1449
+** simulate faults and error conditions that would otherwise be difficult
1450
+** or impossible to induce. The set of system calls that can be overridden
1451
+** varies from one VFS to another, and from one version of the same VFS to the
1452
+** next. Applications that use these interfaces must be prepared for any
1453
+** or all of these interfaces to be NULL or for their behavior to change
1454
+** from one release to the next. Applications must not attempt to access
1455
+** any of these methods if the iVersion of the VFS is less than 3.
14441456
*/
14451457
typedef struct sqlite3_vfs sqlite3_vfs;
1458
+typedef void (*sqlite3_syscall_ptr)(void);
14461459
struct sqlite3_vfs {
1447
- int iVersion; /* Structure version number (currently 2) */
1460
+ int iVersion; /* Structure version number (currently 3) */
14481461
int szOsFile; /* Size of subclassed sqlite3_file */
14491462
int mxPathname; /* Maximum file pathname length */
14501463
sqlite3_vfs *pNext; /* Next registered VFS */
14511464
const char *zName; /* Name of this virtual file system */
14521465
void *pAppData; /* Pointer to application-specific data */
@@ -1468,10 +1481,17 @@
14681481
** definition. Those that follow are added in version 2 or later
14691482
*/
14701483
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
14711484
/*
14721485
** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1486
+ ** Those below are for version 3 and greater.
1487
+ */
1488
+ int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
1489
+ sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
1490
+ const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
1491
+ /*
1492
+ ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
14731493
** New fields may be appended in figure versions. The iVersion
14741494
** value will increment whenever this happens.
14751495
*/
14761496
};
14771497
@@ -1652,21 +1672,16 @@
16521672
** CAPI3REF: Configure database connections
16531673
**
16541674
** The sqlite3_db_config() interface is used to make configuration
16551675
** changes to a [database connection]. The interface is similar to
16561676
** [sqlite3_config()] except that the changes apply to a single
1657
-** [database connection] (specified in the first argument). The
1658
-** sqlite3_db_config() interface should only be used immediately after
1659
-** the database connection is created using [sqlite3_open()],
1660
-** [sqlite3_open16()], or [sqlite3_open_v2()].
1677
+** [database connection] (specified in the first argument).
16611678
**
16621679
** The second argument to sqlite3_db_config(D,V,...) is the
1663
-** configuration verb - an integer code that indicates what
1664
-** aspect of the [database connection] is being configured.
1665
-** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
1666
-** New verbs are likely to be added in future releases of SQLite.
1667
-** Additional arguments depend on the verb.
1680
+** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code
1681
+** that indicates what aspect of the [database connection] is being configured.
1682
+** Subsequent arguments vary depending on the configuration verb.
16681683
**
16691684
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
16701685
** the call is considered successful.
16711686
*/
16721687
SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
@@ -1887,11 +1902,13 @@
18871902
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
18881903
** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
18891904
** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
18901905
** allocator is engaged to handle all of SQLites memory allocation needs.
18911906
** The first pointer (the memory pointer) must be aligned to an 8-byte
1892
-** boundary or subsequent behavior of SQLite will be undefined.</dd>
1907
+** boundary or subsequent behavior of SQLite will be undefined.
1908
+** The minimum allocation size is capped at 2^12. Reasonable values
1909
+** for the minimum allocation size are 2^5 through 2^8.</dd>
18931910
**
18941911
** <dt>SQLITE_CONFIG_MUTEX</dt>
18951912
** <dd> ^(This option takes a single argument which is a pointer to an
18961913
** instance of the [sqlite3_mutex_methods] structure. The argument specifies
18971914
** alternative low-level mutex routines to be used in place
@@ -2008,13 +2025,35 @@
20082025
** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
20092026
** Any attempt to change the lookaside memory configuration when lookaside
20102027
** memory is in use leaves the configuration unchanged and returns
20112028
** [SQLITE_BUSY].)^</dd>
20122029
**
2030
+** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2031
+** <dd> ^This option is used to enable or disable the enforcement of
2032
+** [foreign key constraints]. There should be two additional arguments.
2033
+** The first argument is an integer which is 0 to disable FK enforcement,
2034
+** positive to enable FK enforcement or negative to leave FK enforcement
2035
+** unchanged. The second parameter is a pointer to an integer into which
2036
+** is written 0 or 1 to indicate whether FK enforcement is off or on
2037
+** following this call. The second parameter may be a NULL pointer, in
2038
+** which case the FK enforcement setting is not reported back. </dd>
2039
+**
2040
+** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
2041
+** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2042
+** There should be two additional arguments.
2043
+** The first argument is an integer which is 0 to disable triggers,
2044
+** positive to enable trigers or negative to leave the setting unchanged.
2045
+** The second parameter is a pointer to an integer into which
2046
+** is written 0 or 1 to indicate whether triggers are disabled or enabled
2047
+** following this call. The second parameter may be a NULL pointer, in
2048
+** which case the trigger setting is not reported back. </dd>
2049
+**
20132050
** </dl>
20142051
*/
2015
-#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2052
+#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2053
+#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2054
+#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
20162055
20172056
20182057
/*
20192058
** CAPI3REF: Enable Or Disable Extended Result Codes
20202059
**
@@ -8974,10 +9013,11 @@
89749013
/*
89759014
** An instance of the following structure stores a database schema.
89769015
*/
89779016
struct Schema {
89789017
int schema_cookie; /* Database schema version number for this file */
9018
+ int iGeneration; /* Generation counter. Incremented with each change */
89799019
Hash tblHash; /* All tables indexed by name */
89809020
Hash idxHash; /* All (named) indices indexed by name */
89819021
Hash trigHash; /* All triggers indexed by name */
89829022
Hash fkeyHash; /* All foreign keys by referenced table name */
89839023
Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
@@ -9227,10 +9267,11 @@
92279267
#define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
92289268
#define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
92299269
#define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
92309270
#define SQLITE_PreferBuiltin 0x10000000 /* Preference to built-in funcs */
92319271
#define SQLITE_LoadExtension 0x20000000 /* Enable load_extension */
9272
+#define SQLITE_EnableTrigger 0x40000000 /* True to enable triggers */
92329273
92339274
/*
92349275
** Bits of the sqlite3.flags field that are used by the
92359276
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
92369277
** These must be the low-order bits of the flags field.
@@ -9926,11 +9967,11 @@
99269967
u8 op; /* Operation performed by this node */
99279968
char affinity; /* The affinity of the column or 0 if not a column */
99289969
u16 flags; /* Various flags. EP_* See below */
99299970
union {
99309971
char *zToken; /* Token value. Zero terminated and dequoted */
9931
- int iValue; /* Integer value if EP_IntValue */
9972
+ int iValue; /* Non-negative integer value if EP_IntValue */
99329973
} u;
99339974
99349975
/* If the EP_TokenOnly flag is set in the Expr.flags mask, then no
99359976
** space is allocated for the fields below this point. An attempt to
99369977
** access them will result in a segfault or malfunction.
@@ -10426,10 +10467,17 @@
1042610467
SubProgram *pProgram; /* Program implementing pTrigger/orconf */
1042710468
u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */
1042810469
TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */
1042910470
};
1043010471
10472
+/* Datatype for the bitmask of all attached databases */
10473
+#if SQLITE_MAX_ATTACHED>30
10474
+ typedef sqlite3_uint64 tAttachMask;
10475
+#else
10476
+ typedef unsigned int tAttachMask;
10477
+#endif
10478
+
1043110479
/*
1043210480
** An SQL parser context. A copy of this structure is passed through
1043310481
** the parser and down into all the parser action routine in order to
1043410482
** carry around information that is global to the entire parse.
1043510483
**
@@ -10474,12 +10522,12 @@
1047410522
u8 tempReg; /* iReg is a temp register that needs to be freed */
1047510523
int iLevel; /* Nesting level */
1047610524
int iReg; /* Reg with value of this column. 0 means none. */
1047710525
int lru; /* Least recently used entry has the smallest value */
1047810526
} aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
10479
- u32 writeMask; /* Start a write transaction on these databases */
10480
- u32 cookieMask; /* Bitmask of schema verified databases */
10527
+ tAttachMask writeMask; /* Start a write transaction on these databases */
10528
+ tAttachMask cookieMask; /* Bitmask of schema verified databases */
1048110529
u8 isMultiWrite; /* True if statement may affect/insert multiple rows */
1048210530
u8 mayAbort; /* True if statement may throw an ABORT exception */
1048310531
int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
1048410532
int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
1048510533
#ifndef SQLITE_OMIT_SHARED_CACHE
@@ -11209,10 +11257,11 @@
1120911257
SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
1121011258
SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
1121111259
SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64);
1121211260
SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64);
1121311261
SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64);
11262
+SQLITE_PRIVATE int sqlite3AbsInt32(int);
1121411263
1121511264
SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
1121611265
SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
1121711266
SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
1121811267
void(*)(void*));
@@ -12023,10 +12072,13 @@
1202312072
"OMIT_TRIGGER",
1202412073
#endif
1202512074
#ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
1202612075
"OMIT_TRUNCATE_OPTIMIZATION",
1202712076
#endif
12077
+#ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT
12078
+ "OMIT_UNIQUE_ENFORCEMENT",
12079
+#endif
1202812080
#ifdef SQLITE_OMIT_UTF16
1202912081
"OMIT_UTF16",
1203012082
#endif
1203112083
#ifdef SQLITE_OMIT_VACUUM
1203212084
"OMIT_VACUUM",
@@ -12436,11 +12488,11 @@
1243612488
u8 inVtabMethod; /* See comments above */
1243712489
u8 usesStmtJournal; /* True if uses a statement journal */
1243812490
u8 readOnly; /* True for read-only statements */
1243912491
u8 isPrepareV2; /* True if prepared with prepare_v2() */
1244012492
int nChange; /* Number of db changes made since last reset */
12441
- int btreeMask; /* Bitmask of db->aDb[] entries referenced */
12493
+ tAttachMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
1244212494
int iStatement; /* Statement number (or 0 if has not opened stmt) */
1244312495
int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
1244412496
BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
1244512497
#ifndef SQLITE_OMIT_TRACE
1244612498
i64 startTime; /* Time when query started - used for profiling */
@@ -16155,11 +16207,11 @@
1615516207
** memsys5Log(8) -> 3
1615616208
** memsys5Log(9) -> 4
1615716209
*/
1615816210
static int memsys5Log(int iValue){
1615916211
int iLog;
16160
- for(iLog=0; (1<<iLog)<iValue; iLog++);
16212
+ for(iLog=0; (iLog<((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++);
1616116213
return iLog;
1616216214
}
1616316215
1616416216
/*
1616516217
** Initialize the memory allocator.
@@ -16186,10 +16238,11 @@
1618616238
1618716239
nByte = sqlite3GlobalConfig.nHeap;
1618816240
zByte = (u8*)sqlite3GlobalConfig.pHeap;
1618916241
assert( zByte!=0 ); /* sqlite3_config() does not allow otherwise */
1619016242
16243
+ /* boundaries on sqlite3GlobalConfig.mnReq are enforced in sqlite3_config() */
1619116244
nMinLog = memsys5Log(sqlite3GlobalConfig.mnReq);
1619216245
mem5.szAtom = (1<<nMinLog);
1619316246
while( (int)sizeof(Mem5Link)>mem5.szAtom ){
1619416247
mem5.szAtom = mem5.szAtom << 1;
1619516248
}
@@ -16689,15 +16742,20 @@
1668916742
** Each recursive mutex is an instance of the following structure.
1669016743
*/
1669116744
struct sqlite3_mutex {
1669216745
HMTX mutex; /* Mutex controlling the lock */
1669316746
int id; /* Mutex type */
16694
- int nRef; /* Number of references */
16695
- TID owner; /* Thread holding this mutex */
16747
+#ifdef SQLITE_DEBUG
16748
+ int trace; /* True to trace changes */
16749
+#endif
1669616750
};
1669716751
16698
-#define OS2_MUTEX_INITIALIZER 0,0,0,0
16752
+#ifdef SQLITE_DEBUG
16753
+#define SQLITE3_MUTEX_INITIALIZER { 0, 0, 0 }
16754
+#else
16755
+#define SQLITE3_MUTEX_INITIALIZER { 0, 0 }
16756
+#endif
1669916757
1670016758
/*
1670116759
** Initialize and deinitialize the mutex subsystem.
1670216760
*/
1670316761
static int os2MutexInit(void){ return SQLITE_OK; }
@@ -16709,15 +16767,18 @@
1670916767
** that means that a mutex could not be allocated.
1671016768
** SQLite will unwind its stack and return an error. The argument
1671116769
** to sqlite3_mutex_alloc() is one of these integer constants:
1671216770
**
1671316771
** <ul>
16714
-** <li> SQLITE_MUTEX_FAST 0
16715
-** <li> SQLITE_MUTEX_RECURSIVE 1
16716
-** <li> SQLITE_MUTEX_STATIC_MASTER 2
16717
-** <li> SQLITE_MUTEX_STATIC_MEM 3
16718
-** <li> SQLITE_MUTEX_STATIC_PRNG 4
16772
+** <li> SQLITE_MUTEX_FAST
16773
+** <li> SQLITE_MUTEX_RECURSIVE
16774
+** <li> SQLITE_MUTEX_STATIC_MASTER
16775
+** <li> SQLITE_MUTEX_STATIC_MEM
16776
+** <li> SQLITE_MUTEX_STATIC_MEM2
16777
+** <li> SQLITE_MUTEX_STATIC_PRNG
16778
+** <li> SQLITE_MUTEX_STATIC_LRU
16779
+** <li> SQLITE_MUTEX_STATIC_LRU2
1671916780
** </ul>
1672016781
**
1672116782
** The first two constants cause sqlite3_mutex_alloc() to create
1672216783
** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
1672316784
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -16727,11 +16788,11 @@
1672716788
** cases where it really needs one. If a faster non-recursive mutex
1672816789
** implementation is available on the host platform, the mutex subsystem
1672916790
** might return such a mutex in response to SQLITE_MUTEX_FAST.
1673016791
**
1673116792
** The other allowed parameters to sqlite3_mutex_alloc() each return
16732
-** a pointer to a static preexisting mutex. Three static mutexes are
16793
+** a pointer to a static preexisting mutex. Six static mutexes are
1673316794
** used by the current version of SQLite. Future versions of SQLite
1673416795
** may add additional static mutexes. Static mutexes are for internal
1673516796
** use by SQLite only. Applications that use SQLite mutexes should
1673616797
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
1673716798
** SQLITE_MUTEX_RECURSIVE.
@@ -16757,17 +16818,17 @@
1675716818
}
1675816819
break;
1675916820
}
1676016821
default: {
1676116822
static volatile int isInit = 0;
16762
- static sqlite3_mutex staticMutexes[] = {
16763
- { OS2_MUTEX_INITIALIZER, },
16764
- { OS2_MUTEX_INITIALIZER, },
16765
- { OS2_MUTEX_INITIALIZER, },
16766
- { OS2_MUTEX_INITIALIZER, },
16767
- { OS2_MUTEX_INITIALIZER, },
16768
- { OS2_MUTEX_INITIALIZER, },
16823
+ static sqlite3_mutex staticMutexes[6] = {
16824
+ SQLITE3_MUTEX_INITIALIZER,
16825
+ SQLITE3_MUTEX_INITIALIZER,
16826
+ SQLITE3_MUTEX_INITIALIZER,
16827
+ SQLITE3_MUTEX_INITIALIZER,
16828
+ SQLITE3_MUTEX_INITIALIZER,
16829
+ SQLITE3_MUTEX_INITIALIZER,
1676916830
};
1677016831
if ( !isInit ){
1677116832
APIRET rc;
1677216833
PTIB ptib;
1677316834
PPIB ppib;
@@ -16809,13 +16870,18 @@
1680916870
/*
1681016871
** This routine deallocates a previously allocated mutex.
1681116872
** SQLite is careful to deallocate every mutex that it allocates.
1681216873
*/
1681316874
static void os2MutexFree(sqlite3_mutex *p){
16814
- if( p==0 ) return;
16815
- assert( p->nRef==0 );
16875
+#ifdef SQLITE_DEBUG
16876
+ TID tid;
16877
+ PID pid;
16878
+ ULONG ulCount;
16879
+ DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16880
+ assert( ulCount==0 );
1681616881
assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
16882
+#endif
1681716883
DosCloseMutexSem( p->mutex );
1681816884
sqlite3_free( p );
1681916885
}
1682016886
1682116887
#ifdef SQLITE_DEBUG
@@ -16826,30 +16892,33 @@
1682616892
static int os2MutexHeld(sqlite3_mutex *p){
1682716893
TID tid;
1682816894
PID pid;
1682916895
ULONG ulCount;
1683016896
PTIB ptib;
16831
- if( p!=0 ) {
16832
- DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16833
- } else {
16834
- DosGetInfoBlocks(&ptib, NULL);
16835
- tid = ptib->tib_ptib2->tib2_ultid;
16836
- }
16837
- return p==0 || (p->nRef!=0 && p->owner==tid);
16897
+ DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16898
+ if( ulCount==0 || ( ulCount>1 && p->id!=SQLITE_MUTEX_RECURSIVE ) )
16899
+ return 0;
16900
+ DosGetInfoBlocks(&ptib, NULL);
16901
+ return tid==ptib->tib_ptib2->tib2_ultid;
1683816902
}
1683916903
static int os2MutexNotheld(sqlite3_mutex *p){
1684016904
TID tid;
1684116905
PID pid;
1684216906
ULONG ulCount;
1684316907
PTIB ptib;
16844
- if( p!= 0 ) {
16845
- DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16846
- } else {
16847
- DosGetInfoBlocks(&ptib, NULL);
16848
- tid = ptib->tib_ptib2->tib2_ultid;
16849
- }
16850
- return p==0 || p->nRef==0 || p->owner!=tid;
16908
+ DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16909
+ if( ulCount==0 )
16910
+ return 1;
16911
+ DosGetInfoBlocks(&ptib, NULL);
16912
+ return tid!=ptib->tib_ptib2->tib2_ultid;
16913
+}
16914
+static void os2MutexTrace(sqlite3_mutex *p, char *pAction){
16915
+ TID tid;
16916
+ PID pid;
16917
+ ULONG ulCount;
16918
+ DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16919
+ printf("%s mutex %p (%d) with nRef=%ld\n", pAction, (void*)p, p->trace, ulCount);
1685116920
}
1685216921
#endif
1685316922
1685416923
/*
1685516924
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
@@ -16861,36 +16930,25 @@
1686116930
** mutex must be exited an equal number of times before another thread
1686216931
** can enter. If the same thread tries to enter any other kind of mutex
1686316932
** more than once, the behavior is undefined.
1686416933
*/
1686516934
static void os2MutexEnter(sqlite3_mutex *p){
16866
- TID tid;
16867
- PID holder1;
16868
- ULONG holder2;
16869
- if( p==0 ) return;
1687016935
assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) );
1687116936
DosRequestMutexSem(p->mutex, SEM_INDEFINITE_WAIT);
16872
- DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2);
16873
- p->owner = tid;
16874
- p->nRef++;
16937
+#ifdef SQLITE_DEBUG
16938
+ if( p->trace ) os2MutexTrace(p, "enter");
16939
+#endif
1687516940
}
1687616941
static int os2MutexTry(sqlite3_mutex *p){
16877
- int rc;
16878
- TID tid;
16879
- PID holder1;
16880
- ULONG holder2;
16881
- if( p==0 ) return SQLITE_OK;
16942
+ int rc = SQLITE_BUSY;
1688216943
assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) );
16883
- if( DosRequestMutexSem(p->mutex, SEM_IMMEDIATE_RETURN) == NO_ERROR) {
16884
- DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2);
16885
- p->owner = tid;
16886
- p->nRef++;
16944
+ if( DosRequestMutexSem(p->mutex, SEM_IMMEDIATE_RETURN) == NO_ERROR ) {
1688716945
rc = SQLITE_OK;
16888
- } else {
16889
- rc = SQLITE_BUSY;
16946
+#ifdef SQLITE_DEBUG
16947
+ if( p->trace ) os2MutexTrace(p, "try");
16948
+#endif
1689016949
}
16891
-
1689216950
return rc;
1689316951
}
1689416952
1689516953
/*
1689616954
** The sqlite3_mutex_leave() routine exits a mutex that was
@@ -16897,23 +16955,18 @@
1689716955
** previously entered by the same thread. The behavior
1689816956
** is undefined if the mutex is not currently entered or
1689916957
** is not currently allocated. SQLite will never do either.
1690016958
*/
1690116959
static void os2MutexLeave(sqlite3_mutex *p){
16902
- TID tid;
16903
- PID holder1;
16904
- ULONG holder2;
16905
- if( p==0 ) return;
16906
- assert( p->nRef>0 );
16907
- DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2);
16908
- assert( p->owner==tid );
16909
- p->nRef--;
16910
- assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
16960
+ assert( os2MutexHeld(p) );
1691116961
DosReleaseMutexSem(p->mutex);
16962
+#ifdef SQLITE_DEBUG
16963
+ if( p->trace ) os2MutexTrace(p, "leave");
16964
+#endif
1691216965
}
1691316966
16914
-SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
16967
+SQLITE_PRIVATE SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
1691516968
static const sqlite3_mutex_methods sMutex = {
1691616969
os2MutexInit,
1691716970
os2MutexEnd,
1691816971
os2MutexAlloc,
1691916972
os2MutexFree,
@@ -16921,10 +16974,13 @@
1692116974
os2MutexTry,
1692216975
os2MutexLeave,
1692316976
#ifdef SQLITE_DEBUG
1692416977
os2MutexHeld,
1692516978
os2MutexNotheld
16979
+#else
16980
+ 0,
16981
+ 0
1692616982
#endif
1692716983
};
1692816984
1692916985
return &sMutex;
1693016986
}
@@ -17564,11 +17620,11 @@
1756417620
#else
1756517621
UNUSED_PARAMETER(p);
1756617622
#endif
1756717623
#ifdef SQLITE_DEBUG
1756817624
if( rc==SQLITE_OK && p->trace ){
17569
- printf("enter mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
17625
+ printf("try mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
1757017626
}
1757117627
#endif
1757217628
return rc;
1757317629
}
1757417630
@@ -21270,10 +21326,20 @@
2127021326
r *= TWOPOWER32;
2127121327
if( sqlite3AddInt64(&r, iA0*iB0) ) return 1;
2127221328
*pA = r;
2127321329
return 0;
2127421330
}
21331
+
21332
+/*
21333
+** Compute the absolute value of a 32-bit signed integer, of possible. Or
21334
+** if the integer has a value of -2147483648, return +2147483647
21335
+*/
21336
+SQLITE_PRIVATE int sqlite3AbsInt32(int x){
21337
+ if( x>=0 ) return x;
21338
+ if( x==(int)0x80000000 ) return 0x7fffffff;
21339
+ return -x;
21340
+}
2127521341
2127621342
/************** End of util.c ************************************************/
2127721343
/************** Begin file hash.c ********************************************/
2127821344
/*
2127921345
** 2001 September 22
@@ -22560,23 +22626,27 @@
2256022626
/*
2256122627
** This vector defines all the methods that can operate on an
2256222628
** sqlite3_file for os2.
2256322629
*/
2256422630
static const sqlite3_io_methods os2IoMethod = {
22565
- 1, /* iVersion */
22566
- os2Close,
22567
- os2Read,
22568
- os2Write,
22569
- os2Truncate,
22570
- os2Sync,
22571
- os2FileSize,
22572
- os2Lock,
22573
- os2Unlock,
22574
- os2CheckReservedLock,
22575
- os2FileControl,
22576
- os2SectorSize,
22577
- os2DeviceCharacteristics
22631
+ 1, /* iVersion */
22632
+ os2Close, /* xClose */
22633
+ os2Read, /* xRead */
22634
+ os2Write, /* xWrite */
22635
+ os2Truncate, /* xTruncate */
22636
+ os2Sync, /* xSync */
22637
+ os2FileSize, /* xFileSize */
22638
+ os2Lock, /* xLock */
22639
+ os2Unlock, /* xUnlock */
22640
+ os2CheckReservedLock, /* xCheckReservedLock */
22641
+ os2FileControl, /* xFileControl */
22642
+ os2SectorSize, /* xSectorSize */
22643
+ os2DeviceCharacteristics, /* xDeviceCharacteristics */
22644
+ 0, /* xShmMap */
22645
+ 0, /* xShmLock */
22646
+ 0, /* xShmBarrier */
22647
+ 0 /* xShmUnmap */
2257822648
};
2257922649
2258022650
/***************************************************************************
2258122651
** Here ends the I/O methods that form the sqlite3_io_methods object.
2258222652
**
@@ -22664,115 +22734,151 @@
2266422734
/*
2266522735
** Open a file.
2266622736
*/
2266722737
static int os2Open(
2266822738
sqlite3_vfs *pVfs, /* Not used */
22669
- const char *zName, /* Name of the file */
22739
+ const char *zName, /* Name of the file (UTF-8) */
2267022740
sqlite3_file *id, /* Write the SQLite file handle here */
2267122741
int flags, /* Open mode flags */
2267222742
int *pOutFlags /* Status return flags */
2267322743
){
2267422744
HFILE h;
22675
- ULONG ulFileAttribute = FILE_NORMAL;
2267622745
ULONG ulOpenFlags = 0;
2267722746
ULONG ulOpenMode = 0;
22747
+ ULONG ulAction = 0;
22748
+ ULONG rc;
2267822749
os2File *pFile = (os2File*)id;
22679
- APIRET rc = NO_ERROR;
22680
- ULONG ulAction;
22750
+ const char *zUtf8Name = zName;
2268122751
char *zNameCp;
22682
- char zTmpname[CCHMAXPATH+1]; /* Buffer to hold name of temp file */
22752
+ char zTmpname[CCHMAXPATH];
22753
+
22754
+ int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
22755
+ int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
22756
+ int isCreate = (flags & SQLITE_OPEN_CREATE);
22757
+ int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
22758
+#ifndef NDEBUG
22759
+ int isReadonly = (flags & SQLITE_OPEN_READONLY);
22760
+ int eType = (flags & 0xFFFFFF00);
22761
+ int isOpenJournal = (isCreate && (
22762
+ eType==SQLITE_OPEN_MASTER_JOURNAL
22763
+ || eType==SQLITE_OPEN_MAIN_JOURNAL
22764
+ || eType==SQLITE_OPEN_WAL
22765
+ ));
22766
+#endif
22767
+
22768
+ UNUSED_PARAMETER(pVfs);
22769
+ assert( id!=0 );
22770
+
22771
+ /* Check the following statements are true:
22772
+ **
22773
+ ** (a) Exactly one of the READWRITE and READONLY flags must be set, and
22774
+ ** (b) if CREATE is set, then READWRITE must also be set, and
22775
+ ** (c) if EXCLUSIVE is set, then CREATE must also be set.
22776
+ ** (d) if DELETEONCLOSE is set, then CREATE must also be set.
22777
+ */
22778
+ assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
22779
+ assert(isCreate==0 || isReadWrite);
22780
+ assert(isExclusive==0 || isCreate);
22781
+ assert(isDelete==0 || isCreate);
22782
+
22783
+ /* The main DB, main journal, WAL file and master journal are never
22784
+ ** automatically deleted. Nor are they ever temporary files. */
22785
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
22786
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
22787
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
22788
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
22789
+
22790
+ /* Assert that the upper layer has set one of the "file-type" flags. */
22791
+ assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
22792
+ || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
22793
+ || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
22794
+ || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
22795
+ );
22796
+
22797
+ memset( pFile, 0, sizeof(*pFile) );
22798
+ pFile->pMethod = &os2IoMethod;
2268322799
2268422800
/* If the second argument to this function is NULL, generate a
2268522801
** temporary file name to use
2268622802
*/
22687
- if( !zName ){
22688
- int rc = getTempname(CCHMAXPATH+1, zTmpname);
22803
+ if( !zUtf8Name ){
22804
+ assert(isDelete && !isOpenJournal);
22805
+ rc = getTempname(CCHMAXPATH, zTmpname);
2268922806
if( rc!=SQLITE_OK ){
2269022807
return rc;
2269122808
}
22692
- zName = zTmpname;
22809
+ zUtf8Name = zTmpname;
2269322810
}
2269422811
22695
-
22696
- memset( pFile, 0, sizeof(*pFile) );
22697
-
22698
- OSTRACE(( "OPEN want %d\n", flags ));
22699
-
22700
- if( flags & SQLITE_OPEN_READWRITE ){
22812
+ if( isReadWrite ){
2270122813
ulOpenMode |= OPEN_ACCESS_READWRITE;
22702
- OSTRACE(( "OPEN read/write\n" ));
2270322814
}else{
2270422815
ulOpenMode |= OPEN_ACCESS_READONLY;
22705
- OSTRACE(( "OPEN read only\n" ));
22706
- }
22707
-
22708
- if( flags & SQLITE_OPEN_CREATE ){
22709
- ulOpenFlags |= OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
22710
- OSTRACE(( "OPEN open new/create\n" ));
22711
- }else{
22712
- ulOpenFlags |= OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
22713
- OSTRACE(( "OPEN open existing\n" ));
22714
- }
22715
-
22716
- if( flags & SQLITE_OPEN_MAIN_DB ){
22717
- ulOpenMode |= OPEN_SHARE_DENYNONE;
22718
- OSTRACE(( "OPEN share read/write\n" ));
22719
- }else{
22720
- ulOpenMode |= OPEN_SHARE_DENYWRITE;
22721
- OSTRACE(( "OPEN share read only\n" ));
22722
- }
22723
-
22724
- if( flags & SQLITE_OPEN_DELETEONCLOSE ){
22725
- char pathUtf8[CCHMAXPATH];
22726
-#ifdef NDEBUG /* when debugging we want to make sure it is deleted */
22727
- ulFileAttribute = FILE_HIDDEN;
22728
-#endif
22729
- os2FullPathname( pVfs, zName, CCHMAXPATH, pathUtf8 );
22730
- pFile->pathToDel = convertUtf8PathToCp( pathUtf8 );
22731
- OSTRACE(( "OPEN hidden/delete on close file attributes\n" ));
22732
- }else{
22733
- pFile->pathToDel = NULL;
22734
- OSTRACE(( "OPEN normal file attribute\n" ));
22735
- }
22736
-
22737
- /* always open in random access mode for possibly better speed */
22816
+ }
22817
+
22818
+ /* Open in random access mode for possibly better speed. Allow full
22819
+ ** sharing because file locks will provide exclusive access when needed.
22820
+ */
2273822821
ulOpenMode |= OPEN_FLAGS_RANDOM;
2273922822
ulOpenMode |= OPEN_FLAGS_FAIL_ON_ERROR;
2274022823
ulOpenMode |= OPEN_FLAGS_NOINHERIT;
22824
+ ulOpenMode |= OPEN_SHARE_DENYNONE;
2274122825
22742
- zNameCp = convertUtf8PathToCp( zName );
22826
+ /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
22827
+ ** created. SQLite doesn't use it to indicate "exclusive access"
22828
+ ** as it is usually understood.
22829
+ */
22830
+ if( isExclusive ){
22831
+ /* Creates a new file, only if it does not already exist. */
22832
+ /* If the file exists, it fails. */
22833
+ ulOpenFlags |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_FAIL_IF_EXISTS;
22834
+ }else if( isCreate ){
22835
+ /* Open existing file, or create if it doesn't exist */
22836
+ ulOpenFlags |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
22837
+ }else{
22838
+ /* Opens a file, only if it exists. */
22839
+ ulOpenFlags |= OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
22840
+ }
22841
+
22842
+ /* For DELETEONCLOSE, save a pointer to the converted filename */
22843
+ if( isDelete ){
22844
+ char pathUtf8[CCHMAXPATH];
22845
+ os2FullPathname( pVfs, zUtf8Name, CCHMAXPATH, pathUtf8 );
22846
+ pFile->pathToDel = convertUtf8PathToCp( pathUtf8 );
22847
+ }
22848
+
22849
+ zNameCp = convertUtf8PathToCp( zUtf8Name );
2274322850
rc = DosOpen( (PSZ)zNameCp,
2274422851
&h,
2274522852
&ulAction,
2274622853
0L,
22747
- ulFileAttribute,
22854
+ FILE_NORMAL,
2274822855
ulOpenFlags,
2274922856
ulOpenMode,
2275022857
(PEAOP2)NULL );
2275122858
free( zNameCp );
22859
+
2275222860
if( rc != NO_ERROR ){
22753
- OSTRACE(( "OPEN Invalid handle rc=%d: zName=%s, ulAction=%#lx, ulAttr=%#lx, ulFlags=%#lx, ulMode=%#lx\n",
22754
- rc, zName, ulAction, ulFileAttribute, ulOpenFlags, ulOpenMode ));
22861
+ OSTRACE(( "OPEN Invalid handle rc=%d: zName=%s, ulAction=%#lx, ulFlags=%#lx, ulMode=%#lx\n",
22862
+ rc, zUtf8Name, ulAction, ulOpenFlags, ulOpenMode ));
2275522863
if( pFile->pathToDel )
2275622864
free( pFile->pathToDel );
2275722865
pFile->pathToDel = NULL;
22758
- if( flags & SQLITE_OPEN_READWRITE ){
22759
- OSTRACE(( "OPEN %d Invalid handle\n",
22760
- ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE) ));
22866
+
22867
+ if( isReadWrite ){
2276122868
return os2Open( pVfs, zName, id,
22762
- ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE),
22869
+ ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)),
2276322870
pOutFlags );
2276422871
}else{
2276522872
return SQLITE_CANTOPEN;
2276622873
}
2276722874
}
2276822875
2276922876
if( pOutFlags ){
22770
- *pOutFlags = flags & SQLITE_OPEN_READWRITE ? SQLITE_OPEN_READWRITE : SQLITE_OPEN_READONLY;
22877
+ *pOutFlags = isReadWrite ? SQLITE_OPEN_READWRITE : SQLITE_OPEN_READONLY;
2277122878
}
2277222879
22773
- pFile->pMethod = &os2IoMethod;
2277422880
pFile->h = h;
2277522881
OpenCounter(+1);
2277622882
OSTRACE(( "OPEN %d pOutFlags=%d\n", pFile->h, pOutFlags ));
2277722883
return SQLITE_OK;
2277822884
}
@@ -22783,17 +22889,20 @@
2278322889
static int os2Delete(
2278422890
sqlite3_vfs *pVfs, /* Not used on os2 */
2278522891
const char *zFilename, /* Name of file to delete */
2278622892
int syncDir /* Not used on os2 */
2278722893
){
22788
- APIRET rc = NO_ERROR;
22789
- char *zFilenameCp = convertUtf8PathToCp( zFilename );
22894
+ APIRET rc;
22895
+ char *zFilenameCp;
2279022896
SimulateIOError( return SQLITE_IOERR_DELETE );
22897
+ zFilenameCp = convertUtf8PathToCp( zFilename );
2279122898
rc = DosDelete( (PSZ)zFilenameCp );
2279222899
free( zFilenameCp );
2279322900
OSTRACE(( "DELETE \"%s\"\n", zFilename ));
22794
- return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR_DELETE;
22901
+ return (rc == NO_ERROR ||
22902
+ rc == ERROR_FILE_NOT_FOUND ||
22903
+ rc == ERROR_PATH_NOT_FOUND ) ? SQLITE_OK : SQLITE_IOERR_DELETE;
2279522904
}
2279622905
2279722906
/*
2279822907
** Check the existance and status of a file.
2279922908
*/
@@ -22854,11 +22963,11 @@
2285422963
** os2Dlopen returns zero if DosLoadModule is not successful.
2285522964
*/
2285622965
static void os2DlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
2285722966
/* no-op */
2285822967
}
22859
-static void *os2DlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol){
22968
+static void (*os2DlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
2286022969
PFN pfn;
2286122970
APIRET rc;
2286222971
rc = DosQueryProcAddr((HMODULE)pHandle, 0L, zSymbol, &pfn);
2286322972
if( rc != NO_ERROR ){
2286422973
/* if the symbol itself was not found, search again for the same
@@ -22866,11 +22975,11 @@
2286622975
* on the calling convention */
2286722976
char _zSymbol[256] = "_";
2286822977
strncat(_zSymbol, zSymbol, 255);
2286922978
rc = DosQueryProcAddr((HMODULE)pHandle, 0L, _zSymbol, &pfn);
2287022979
}
22871
- return rc != NO_ERROR ? 0 : (void*)pfn;
22980
+ return rc != NO_ERROR ? 0 : (void(*)(void))pfn;
2287222981
}
2287322982
static void os2DlClose(sqlite3_vfs *pVfs, void *pHandle){
2287422983
DosFreeModule((HMODULE)pHandle);
2287522984
}
2287622985
#else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
@@ -22970,14 +23079,15 @@
2297023079
** return 0. Return 1 if the time and date cannot be found.
2297123080
*/
2297223081
int os2CurrentTime( sqlite3_vfs *pVfs, double *prNow ){
2297323082
double now;
2297423083
SHORT minute; /* needs to be able to cope with negative timezone offset */
22975
- USHORT second, hour,
23084
+ USHORT hundredths, second, hour,
2297623085
day, month, year;
2297723086
DATETIME dt;
2297823087
DosGetDateTime( &dt );
23088
+ hundredths = (USHORT)dt.hundredths;
2297923089
second = (USHORT)dt.seconds;
2298023090
minute = (SHORT)dt.minutes + dt.timezone;
2298123091
hour = (USHORT)dt.hours;
2298223092
day = (USHORT)dt.day;
2298323093
month = (USHORT)dt.month;
@@ -22993,18 +23103,35 @@
2299323103
2299423104
/* Add the fractional hours, mins and seconds */
2299523105
now += (hour + 12.0)/24.0;
2299623106
now += minute/1440.0;
2299723107
now += second/86400.0;
23108
+ now += hundredths/8640000.0;
2299823109
*prNow = now;
2299923110
#ifdef SQLITE_TEST
2300023111
if( sqlite3_current_time ){
2300123112
*prNow = sqlite3_current_time/86400.0 + 2440587.5;
2300223113
}
2300323114
#endif
2300423115
return 0;
2300523116
}
23117
+
23118
+/*
23119
+** Find the current time (in Universal Coordinated Time). Write into *piNow
23120
+** the current time and date as a Julian Day number times 86_400_000. In
23121
+** other words, write into *piNow the number of milliseconds since the Julian
23122
+** epoch of noon in Greenwich on November 24, 4714 B.C according to the
23123
+** proleptic Gregorian calendar.
23124
+**
23125
+** On success, return 0. Return 1 if the time and date cannot be found.
23126
+*/
23127
+static int os2CurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){
23128
+ double now;
23129
+ os2CurrentTime(pVfs, &now);
23130
+ *piNow = now * 86400000;
23131
+ return 0;
23132
+}
2300623133
2300723134
static int os2GetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
2300823135
return 0;
2300923136
}
2301023137
@@ -23011,11 +23138,11 @@
2301123138
/*
2301223139
** Initialize and deinitialize the operating system interface.
2301323140
*/
2301423141
SQLITE_API int sqlite3_os_init(void){
2301523142
static sqlite3_vfs os2Vfs = {
23016
- 1, /* iVersion */
23143
+ 3, /* iVersion */
2301723144
sizeof(os2File), /* szOsFile */
2301823145
CCHMAXPATH, /* mxPathname */
2301923146
0, /* pNext */
2302023147
"os2", /* zName */
2302123148
0, /* pAppData */
@@ -23030,10 +23157,14 @@
2303023157
os2DlClose, /* xDlClose */
2303123158
os2Randomness, /* xRandomness */
2303223159
os2Sleep, /* xSleep */
2303323160
os2CurrentTime, /* xCurrentTime */
2303423161
os2GetLastError, /* xGetLastError */
23162
+ os2CurrentTimeInt64 /* xCurrentTimeInt64 */
23163
+ 0, /* xSetSystemCall */
23164
+ 0, /* xGetSystemCall */
23165
+ 0, /* xNextSystemCall */
2303523166
};
2303623167
sqlite3_vfs_register(&os2Vfs, 1);
2303723168
initUconvObjects();
2303823169
return SQLITE_OK;
2303923170
}
@@ -23249,14 +23380,14 @@
2324923380
sqlite3_io_methods const *pMethod; /* Always the first entry */
2325023381
unixInodeInfo *pInode; /* Info about locks on this inode */
2325123382
int h; /* The file descriptor */
2325223383
int dirfd; /* File descriptor for the directory */
2325323384
unsigned char eFileLock; /* The type of lock held on this fd */
23385
+ unsigned char ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */
2325423386
int lastErrno; /* The unix errno from last I/O error */
2325523387
void *lockingContext; /* Locking style specific state */
2325623388
UnixUnusedFd *pUnused; /* Pre-allocated UnixUnusedFd */
23257
- int fileFlags; /* Miscellanous flags */
2325823389
const char *zPath; /* Name of the file */
2325923390
unixShm *pShm; /* Shared memory segment information */
2326023391
int szChunk; /* Configured by FCNTL_CHUNK_SIZE */
2326123392
#if SQLITE_ENABLE_LOCKING_STYLE
2326223393
int openFlags; /* The flags specified at open() */
@@ -23287,13 +23418,14 @@
2328723418
char aPadding[32];
2328823419
#endif
2328923420
};
2329023421
2329123422
/*
23292
-** The following macros define bits in unixFile.fileFlags
23423
+** Allowed values for the unixFile.ctrlFlags bitmask:
2329323424
*/
23294
-#define SQLITE_WHOLE_FILE_LOCKING 0x0001 /* Use whole-file locking */
23425
+#define UNIXFILE_EXCL 0x01 /* Connections from one process only */
23426
+#define UNIXFILE_RDONLY 0x02 /* Connection is read only */
2329523427
2329623428
/*
2329723429
** Include code that is common to all os_*.c files
2329823430
*/
2329923431
/************** Include os_common.h in the middle of os_unix.c ***************/
@@ -23518,20 +23650,10 @@
2351823650
#endif
2351923651
#ifndef O_BINARY
2352023652
# define O_BINARY 0
2352123653
#endif
2352223654
23523
-/*
23524
-** The DJGPP compiler environment looks mostly like Unix, but it
23525
-** lacks the fcntl() system call. So redefine fcntl() to be something
23526
-** that always succeeds. This means that locking does not occur under
23527
-** DJGPP. But it is DOS - what did you expect?
23528
-*/
23529
-#ifdef __DJGPP__
23530
-# define fcntl(A,B,C) 0
23531
-#endif
23532
-
2353323655
/*
2353423656
** The threadid macro resolves to the thread-id or to 0. Used for
2353523657
** testing and debugging only.
2353623658
*/
2353723659
#if SQLITE_THREADSAFE
@@ -23538,10 +23660,197 @@
2353823660
#define threadid pthread_self()
2353923661
#else
2354023662
#define threadid 0
2354123663
#endif
2354223664
23665
+/*
23666
+** Many system calls are accessed through pointer-to-functions so that
23667
+** they may be overridden at runtime to facilitate fault injection during
23668
+** testing and sandboxing. The following array holds the names and pointers
23669
+** to all overrideable system calls.
23670
+*/
23671
+static struct unix_syscall {
23672
+ const char *zName; /* Name of the sytem call */
23673
+ sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
23674
+ sqlite3_syscall_ptr pDefault; /* Default value */
23675
+} aSyscall[] = {
23676
+ { "open", (sqlite3_syscall_ptr)open, 0 },
23677
+#define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
23678
+
23679
+ { "close", (sqlite3_syscall_ptr)close, 0 },
23680
+#define osClose ((int(*)(int))aSyscall[1].pCurrent)
23681
+
23682
+ { "access", (sqlite3_syscall_ptr)access, 0 },
23683
+#define osAccess ((int(*)(const char*,int))aSyscall[2].pCurrent)
23684
+
23685
+ { "getcwd", (sqlite3_syscall_ptr)getcwd, 0 },
23686
+#define osGetcwd ((char*(*)(char*,size_t))aSyscall[3].pCurrent)
23687
+
23688
+ { "stat", (sqlite3_syscall_ptr)stat, 0 },
23689
+#define osStat ((int(*)(const char*,struct stat*))aSyscall[4].pCurrent)
23690
+
23691
+/*
23692
+** The DJGPP compiler environment looks mostly like Unix, but it
23693
+** lacks the fcntl() system call. So redefine fcntl() to be something
23694
+** that always succeeds. This means that locking does not occur under
23695
+** DJGPP. But it is DOS - what did you expect?
23696
+*/
23697
+#ifdef __DJGPP__
23698
+ { "fstat", 0, 0 },
23699
+#define osFstat(a,b,c) 0
23700
+#else
23701
+ { "fstat", (sqlite3_syscall_ptr)fstat, 0 },
23702
+#define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
23703
+#endif
23704
+
23705
+ { "ftruncate", (sqlite3_syscall_ptr)ftruncate, 0 },
23706
+#define osFtruncate ((int(*)(int,off_t))aSyscall[6].pCurrent)
23707
+
23708
+ { "fcntl", (sqlite3_syscall_ptr)fcntl, 0 },
23709
+#define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent)
23710
+
23711
+ { "read", (sqlite3_syscall_ptr)read, 0 },
23712
+#define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
23713
+
23714
+#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
23715
+ { "pread", (sqlite3_syscall_ptr)pread, 0 },
23716
+#else
23717
+ { "pread", (sqlite3_syscall_ptr)0, 0 },
23718
+#endif
23719
+#define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
23720
+
23721
+#if defined(USE_PREAD64)
23722
+ { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
23723
+#else
23724
+ { "pread64", (sqlite3_syscall_ptr)0, 0 },
23725
+#endif
23726
+#define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
23727
+
23728
+ { "write", (sqlite3_syscall_ptr)write, 0 },
23729
+#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
23730
+
23731
+#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
23732
+ { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
23733
+#else
23734
+ { "pwrite", (sqlite3_syscall_ptr)0, 0 },
23735
+#endif
23736
+#define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\
23737
+ aSyscall[12].pCurrent)
23738
+
23739
+#if defined(USE_PREAD64)
23740
+ { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
23741
+#else
23742
+ { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
23743
+#endif
23744
+#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
23745
+ aSyscall[13].pCurrent)
23746
+
23747
+ { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
23748
+#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
23749
+
23750
+#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
23751
+ { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
23752
+#else
23753
+ { "fallocate", (sqlite3_syscall_ptr)0, 0 },
23754
+#endif
23755
+#define osFallocate ((int(*)(int,off_t,off_t)aSyscall[15].pCurrent)
23756
+
23757
+}; /* End of the overrideable system calls */
23758
+
23759
+/*
23760
+** This is the xSetSystemCall() method of sqlite3_vfs for all of the
23761
+** "unix" VFSes. Return SQLITE_OK opon successfully updating the
23762
+** system call pointer, or SQLITE_NOTFOUND if there is no configurable
23763
+** system call named zName.
23764
+*/
23765
+static int unixSetSystemCall(
23766
+ sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */
23767
+ const char *zName, /* Name of system call to override */
23768
+ sqlite3_syscall_ptr pNewFunc /* Pointer to new system call value */
23769
+){
23770
+ unsigned int i;
23771
+ int rc = SQLITE_NOTFOUND;
23772
+
23773
+ UNUSED_PARAMETER(pNotUsed);
23774
+ if( zName==0 ){
23775
+ /* If no zName is given, restore all system calls to their default
23776
+ ** settings and return NULL
23777
+ */
23778
+ for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
23779
+ if( aSyscall[i].pDefault ){
23780
+ aSyscall[i].pCurrent = aSyscall[i].pDefault;
23781
+ rc = SQLITE_OK;
23782
+ }
23783
+ }
23784
+ }else{
23785
+ /* If zName is specified, operate on only the one system call
23786
+ ** specified.
23787
+ */
23788
+ for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
23789
+ if( strcmp(zName, aSyscall[i].zName)==0 ){
23790
+ if( aSyscall[i].pDefault==0 ){
23791
+ aSyscall[i].pDefault = aSyscall[i].pCurrent;
23792
+ }
23793
+ rc = SQLITE_OK;
23794
+ if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault;
23795
+ aSyscall[i].pCurrent = pNewFunc;
23796
+ break;
23797
+ }
23798
+ }
23799
+ }
23800
+ return rc;
23801
+}
23802
+
23803
+/*
23804
+** Return the value of a system call. Return NULL if zName is not a
23805
+** recognized system call name. NULL is also returned if the system call
23806
+** is currently undefined.
23807
+*/
23808
+static sqlite3_syscall_ptr unixGetSystemCall(
23809
+ sqlite3_vfs *pNotUsed,
23810
+ const char *zName
23811
+){
23812
+ unsigned int i;
23813
+
23814
+ UNUSED_PARAMETER(pNotUsed);
23815
+ for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
23816
+ if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent;
23817
+ }
23818
+ return 0;
23819
+}
23820
+
23821
+/*
23822
+** Return the name of the first system call after zName. If zName==NULL
23823
+** then return the name of the first system call. Return NULL if zName
23824
+** is the last system call or if zName is not the name of a valid
23825
+** system call.
23826
+*/
23827
+static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){
23828
+ unsigned int i;
23829
+
23830
+ UNUSED_PARAMETER(p);
23831
+ if( zName==0 ){
23832
+ i = -1;
23833
+ }else{
23834
+ for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0])-1; i++){
23835
+ if( strcmp(zName, aSyscall[0].zName)==0 ) break;
23836
+ }
23837
+ }
23838
+ for(i++; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
23839
+ if( aSyscall[0].pCurrent!=0 ) return aSyscall[0].zName;
23840
+ }
23841
+ return 0;
23842
+}
23843
+
23844
+/*
23845
+** Retry open() calls that fail due to EINTR
23846
+*/
23847
+static int robust_open(const char *z, int f, int m){
23848
+ int rc;
23849
+ do{ rc = osOpen(z,f,m); }while( rc<0 && errno==EINTR );
23850
+ return rc;
23851
+}
2354323852
2354423853
/*
2354523854
** Helper functions to obtain and relinquish the global mutex. The
2354623855
** global mutex is used to protect the unixInodeInfo and
2354723856
** vxworksFileId objects used by this file, all of which may be
@@ -23602,11 +23911,11 @@
2360223911
if( op==F_GETLK ){
2360323912
zOpName = "GETLK";
2360423913
}else if( op==F_SETLK ){
2360523914
zOpName = "SETLK";
2360623915
}else{
23607
- s = fcntl(fd, op, p);
23916
+ s = osFcntl(fd, op, p);
2360823917
sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s);
2360923918
return s;
2361023919
}
2361123920
if( p->l_type==F_RDLCK ){
2361223921
zType = "RDLCK";
@@ -23616,19 +23925,19 @@
2361623925
zType = "UNLCK";
2361723926
}else{
2361823927
assert( 0 );
2361923928
}
2362023929
assert( p->l_whence==SEEK_SET );
23621
- s = fcntl(fd, op, p);
23930
+ s = osFcntl(fd, op, p);
2362223931
savedErrno = errno;
2362323932
sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n",
2362423933
threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len,
2362523934
(int)p->l_pid, s);
2362623935
if( s==(-1) && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){
2362723936
struct flock l2;
2362823937
l2 = *p;
23629
- fcntl(fd, F_GETLK, &l2);
23938
+ osFcntl(fd, F_GETLK, &l2);
2363023939
if( l2.l_type==F_RDLCK ){
2363123940
zType = "RDLCK";
2363223941
}else if( l2.l_type==F_WRLCK ){
2363323942
zType = "WRLCK";
2363423943
}else if( l2.l_type==F_UNLCK ){
@@ -23640,27 +23949,22 @@
2364023949
zType, (int)l2.l_start, (int)l2.l_len, (int)l2.l_pid);
2364123950
}
2364223951
errno = savedErrno;
2364323952
return s;
2364423953
}
23645
-#define fcntl lockTrace
23954
+#undef osFcntl
23955
+#define osFcntl lockTrace
2364623956
#endif /* SQLITE_LOCK_TRACE */
23647
-
2364823957
2364923958
/*
2365023959
** Retry ftruncate() calls that fail due to EINTR
2365123960
*/
23652
-#ifdef EINTR
2365323961
static int robust_ftruncate(int h, sqlite3_int64 sz){
2365423962
int rc;
23655
- do{ rc = ftruncate(h,sz); }while( rc<0 && errno==EINTR );
23963
+ do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR );
2365623964
return rc;
2365723965
}
23658
-#else
23659
-# define robust_ftruncate(a,b) ftruncate(a,b)
23660
-#endif
23661
-
2366223966
2366323967
/*
2366423968
** This routine translates a standard POSIX errno code into something
2366523969
** useful to the clients of the sqlite3 functions. Specifically, it is
2366623970
** intended to translate a variety of "try again" errors into SQLITE_BUSY
@@ -23978,11 +24282,12 @@
2397824282
** object keeps a count of the number of unixFile pointing to it.
2397924283
*/
2398024284
struct unixInodeInfo {
2398124285
struct unixFileId fileId; /* The lookup key */
2398224286
int nShared; /* Number of SHARED locks held */
23983
- int eFileLock; /* One of SHARED_LOCK, RESERVED_LOCK etc. */
24287
+ unsigned char eFileLock; /* One of SHARED_LOCK, RESERVED_LOCK etc. */
24288
+ unsigned char bProcessLock; /* An exclusive process lock is held */
2398424289
int nRef; /* Number of pointers to this structure */
2398524290
unixShmNode *pShmNode; /* Shared memory associated with this inode */
2398624291
int nLock; /* Number of outstanding file locks */
2398724292
UnixUnusedFd *pUnused; /* Unused file descriptors to close */
2398824293
unixInodeInfo *pNext; /* List of all unixInodeInfo objects */
@@ -24083,11 +24388,11 @@
2408324388
** file descriptor might have already been reused by another thread.
2408424389
** So we don't even try to recover from an EINTR. Just log the error
2408524390
** and move on.
2408624391
*/
2408724392
static void robust_close(unixFile *pFile, int h, int lineno){
24088
- if( close(h) ){
24393
+ if( osClose(h) ){
2408924394
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
2409024395
pFile ? pFile->zPath : 0, lineno);
2409124396
}
2409224397
}
2409324398
@@ -24160,11 +24465,11 @@
2416024465
2416124466
/* Get low-level information about the file that we can used to
2416224467
** create a unique name for the file.
2416324468
*/
2416424469
fd = pFile->h;
24165
- rc = fstat(fd, &statbuf);
24470
+ rc = osFstat(fd, &statbuf);
2416624471
if( rc!=0 ){
2416724472
pFile->lastErrno = errno;
2416824473
#ifdef EOVERFLOW
2416924474
if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
2417024475
#endif
@@ -24181,16 +24486,16 @@
2418124486
** in the header of every SQLite database. In this way, if there
2418224487
** is a race condition such that another thread has already populated
2418324488
** the first page of the database, no damage is done.
2418424489
*/
2418524490
if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
24186
- do{ rc = write(fd, "S", 1); }while( rc<0 && errno==EINTR );
24491
+ do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
2418724492
if( rc!=1 ){
2418824493
pFile->lastErrno = errno;
2418924494
return SQLITE_IOERR;
2419024495
}
24191
- rc = fstat(fd, &statbuf);
24496
+ rc = osFstat(fd, &statbuf);
2419224497
if( rc!=0 ){
2419324498
pFile->lastErrno = errno;
2419424499
return SQLITE_IOERR;
2419524500
}
2419624501
}
@@ -24249,17 +24554,17 @@
2424924554
}
2425024555
2425124556
/* Otherwise see if some other process holds it.
2425224557
*/
2425324558
#ifndef __DJGPP__
24254
- if( !reserved ){
24559
+ if( !reserved && !pFile->pInode->bProcessLock ){
2425524560
struct flock lock;
2425624561
lock.l_whence = SEEK_SET;
2425724562
lock.l_start = RESERVED_BYTE;
2425824563
lock.l_len = 1;
2425924564
lock.l_type = F_WRLCK;
24260
- if (-1 == fcntl(pFile->h, F_GETLK, &lock)) {
24565
+ if (-1 == osFcntl(pFile->h, F_GETLK, &lock)) {
2426124566
int tErrno = errno;
2426224567
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK);
2426324568
pFile->lastErrno = tErrno;
2426424569
} else if( lock.l_type!=F_UNLCK ){
2426524570
reserved = 1;
@@ -24271,10 +24576,54 @@
2427124576
OSTRACE(("TEST WR-LOCK %d %d %d (unix)\n", pFile->h, rc, reserved));
2427224577
2427324578
*pResOut = reserved;
2427424579
return rc;
2427524580
}
24581
+
24582
+/*
24583
+** Attempt to set a system-lock on the file pFile. The lock is
24584
+** described by pLock.
24585
+**
24586
+** If the pFile was opened read/write from unix-excl, then the only lock
24587
+** ever obtained is an exclusive lock, and it is obtained exactly once
24588
+** the first time any lock is attempted. All subsequent system locking
24589
+** operations become no-ops. Locking operations still happen internally,
24590
+** in order to coordinate access between separate database connections
24591
+** within this process, but all of that is handled in memory and the
24592
+** operating system does not participate.
24593
+**
24594
+** This function is a pass-through to fcntl(F_SETLK) if pFile is using
24595
+** any VFS other than "unix-excl" or if pFile is opened on "unix-excl"
24596
+** and is read-only.
24597
+*/
24598
+static int unixFileLock(unixFile *pFile, struct flock *pLock){
24599
+ int rc;
24600
+ unixInodeInfo *pInode = pFile->pInode;
24601
+ assert( unixMutexHeld() );
24602
+ assert( pInode!=0 );
24603
+ if( ((pFile->ctrlFlags & UNIXFILE_EXCL)!=0 || pInode->bProcessLock)
24604
+ && ((pFile->ctrlFlags & UNIXFILE_RDONLY)==0)
24605
+ ){
24606
+ if( pInode->bProcessLock==0 ){
24607
+ struct flock lock;
24608
+ assert( pInode->nLock==0 );
24609
+ lock.l_whence = SEEK_SET;
24610
+ lock.l_start = SHARED_FIRST;
24611
+ lock.l_len = SHARED_SIZE;
24612
+ lock.l_type = F_WRLCK;
24613
+ rc = osFcntl(pFile->h, F_SETLK, &lock);
24614
+ if( rc<0 ) return rc;
24615
+ pInode->bProcessLock = 1;
24616
+ pInode->nLock++;
24617
+ }else{
24618
+ rc = 0;
24619
+ }
24620
+ }else{
24621
+ rc = osFcntl(pFile->h, F_SETLK, pLock);
24622
+ }
24623
+ return rc;
24624
+}
2427624625
2427724626
/*
2427824627
** Lock the file with the lock specified by parameter eFileLock - one
2427924628
** of the following:
2428024629
**
@@ -24408,11 +24757,11 @@
2440824757
if( eFileLock==SHARED_LOCK
2440924758
|| (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
2441024759
){
2441124760
lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK);
2441224761
lock.l_start = PENDING_BYTE;
24413
- s = fcntl(pFile->h, F_SETLK, &lock);
24762
+ s = unixFileLock(pFile, &lock);
2441424763
if( s==(-1) ){
2441524764
tErrno = errno;
2441624765
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
2441724766
if( IS_LOCK_ERROR(rc) ){
2441824767
pFile->lastErrno = tErrno;
@@ -24430,18 +24779,18 @@
2443024779
assert( pInode->eFileLock==0 );
2443124780
2443224781
/* Now get the read-lock */
2443324782
lock.l_start = SHARED_FIRST;
2443424783
lock.l_len = SHARED_SIZE;
24435
- if( (s = fcntl(pFile->h, F_SETLK, &lock))==(-1) ){
24784
+ if( (s = unixFileLock(pFile, &lock))==(-1) ){
2443624785
tErrno = errno;
2443724786
}
2443824787
/* Drop the temporary PENDING lock */
2443924788
lock.l_start = PENDING_BYTE;
2444024789
lock.l_len = 1L;
2444124790
lock.l_type = F_UNLCK;
24442
- if( fcntl(pFile->h, F_SETLK, &lock)!=0 ){
24791
+ if( unixFileLock(pFile, &lock)!=0 ){
2444324792
if( s != -1 ){
2444424793
/* This could happen with a network mount */
2444524794
tErrno = errno;
2444624795
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
2444724796
if( IS_LOCK_ERROR(rc) ){
@@ -24480,11 +24829,11 @@
2448024829
lock.l_len = SHARED_SIZE;
2448124830
break;
2448224831
default:
2448324832
assert(0);
2448424833
}
24485
- s = fcntl(pFile->h, F_SETLK, &lock);
24834
+ s = unixFileLock(pFile, &lock);
2448624835
if( s==(-1) ){
2448724836
tErrno = errno;
2448824837
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
2448924838
if( IS_LOCK_ERROR(rc) ){
2449024839
pFile->lastErrno = tErrno;
@@ -24549,11 +24898,11 @@
2454924898
** the byte range is divided into 2 parts and the first part is unlocked then
2455024899
** set to a read lock, then the other part is simply unlocked. This works
2455124900
** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to
2455224901
** remove the write lock on a region when a read lock is set.
2455324902
*/
24554
-static int _posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
24903
+static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
2455524904
unixFile *pFile = (unixFile*)id;
2455624905
unixInodeInfo *pInode;
2455724906
struct flock lock;
2455824907
int rc = SQLITE_OK;
2455924908
int h;
@@ -24605,10 +24954,11 @@
2460524954
** 4: [RRRR.]
2460624955
*/
2460724956
if( eFileLock==SHARED_LOCK ){
2460824957
2460924958
#if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE
24959
+ (void)handleNFSUnlock;
2461024960
assert( handleNFSUnlock==0 );
2461124961
#endif
2461224962
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
2461324963
if( handleNFSUnlock ){
2461424964
off_t divSize = SHARED_SIZE - 1;
@@ -24615,11 +24965,11 @@
2461524965
2461624966
lock.l_type = F_UNLCK;
2461724967
lock.l_whence = SEEK_SET;
2461824968
lock.l_start = SHARED_FIRST;
2461924969
lock.l_len = divSize;
24620
- if( fcntl(h, F_SETLK, &lock)==(-1) ){
24970
+ if( unixFileLock(pFile,, &lock)==(-1) ){
2462124971
tErrno = errno;
2462224972
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
2462324973
if( IS_LOCK_ERROR(rc) ){
2462424974
pFile->lastErrno = tErrno;
2462524975
}
@@ -24627,11 +24977,11 @@
2462724977
}
2462824978
lock.l_type = F_RDLCK;
2462924979
lock.l_whence = SEEK_SET;
2463024980
lock.l_start = SHARED_FIRST;
2463124981
lock.l_len = divSize;
24632
- if( fcntl(h, F_SETLK, &lock)==(-1) ){
24982
+ if( unixFileLock(pFile, &lock)==(-1) ){
2463324983
tErrno = errno;
2463424984
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
2463524985
if( IS_LOCK_ERROR(rc) ){
2463624986
pFile->lastErrno = tErrno;
2463724987
}
@@ -24639,11 +24989,11 @@
2463924989
}
2464024990
lock.l_type = F_UNLCK;
2464124991
lock.l_whence = SEEK_SET;
2464224992
lock.l_start = SHARED_FIRST+divSize;
2464324993
lock.l_len = SHARED_SIZE-divSize;
24644
- if( fcntl(h, F_SETLK, &lock)==(-1) ){
24994
+ if( unixFileLock(pFile, &lock)==(-1) ){
2464524995
tErrno = errno;
2464624996
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
2464724997
if( IS_LOCK_ERROR(rc) ){
2464824998
pFile->lastErrno = tErrno;
2464924999
}
@@ -24654,11 +25004,11 @@
2465425004
{
2465525005
lock.l_type = F_RDLCK;
2465625006
lock.l_whence = SEEK_SET;
2465725007
lock.l_start = SHARED_FIRST;
2465825008
lock.l_len = SHARED_SIZE;
24659
- if( fcntl(h, F_SETLK, &lock)==(-1) ){
25009
+ if( unixFileLock(pFile, &lock)==(-1) ){
2466025010
tErrno = errno;
2466125011
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
2466225012
if( IS_LOCK_ERROR(rc) ){
2466325013
pFile->lastErrno = tErrno;
2466425014
}
@@ -24668,11 +25018,11 @@
2466825018
}
2466925019
lock.l_type = F_UNLCK;
2467025020
lock.l_whence = SEEK_SET;
2467125021
lock.l_start = PENDING_BYTE;
2467225022
lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
24673
- if( fcntl(h, F_SETLK, &lock)!=(-1) ){
25023
+ if( unixFileLock(pFile, &lock)!=(-1) ){
2467425024
pInode->eFileLock = SHARED_LOCK;
2467525025
}else{
2467625026
tErrno = errno;
2467725027
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
2467825028
if( IS_LOCK_ERROR(rc) ){
@@ -24692,11 +25042,11 @@
2469225042
lock.l_whence = SEEK_SET;
2469325043
lock.l_start = lock.l_len = 0L;
2469425044
SimulateIOErrorBenign(1);
2469525045
SimulateIOError( h=(-1) )
2469625046
SimulateIOErrorBenign(0);
24697
- if( fcntl(h, F_SETLK, &lock)!=(-1) ){
25047
+ if( unixFileLock(pFile, &lock)!=(-1) ){
2469825048
pInode->eFileLock = NO_LOCK;
2469925049
}else{
2470025050
tErrno = errno;
2470125051
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
2470225052
if( IS_LOCK_ERROR(rc) ){
@@ -24730,11 +25080,11 @@
2473025080
**
2473125081
** If the locking level of the file descriptor is already at or below
2473225082
** the requested locking level, this routine is a no-op.
2473325083
*/
2473425084
static int unixUnlock(sqlite3_file *id, int eFileLock){
24735
- return _posixUnlock(id, eFileLock, 0);
25085
+ return posixUnlock(id, eFileLock, 0);
2473625086
}
2473725087
2473825088
/*
2473925089
** This function performs the parts of the "close file" operation
2474025090
** common to all locking schemes. It closes the directory and file
@@ -24780,10 +25130,12 @@
2478025130
int rc = SQLITE_OK;
2478125131
if( id ){
2478225132
unixFile *pFile = (unixFile *)id;
2478325133
unixUnlock(id, NO_LOCK);
2478425134
unixEnterMutex();
25135
+ assert( pFile->pInode==0 || pFile->pInode->nLock>0
25136
+ || pFile->pInode->bProcessLock==0 );
2478525137
if( pFile->pInode && pFile->pInode->nLock ){
2478625138
/* If there are outstanding locks, do not actually close the file just
2478725139
** yet because that would clear those locks. Instead, add the file
2478825140
** descriptor to pInode->pUnused list. It will be automatically closed
2478925141
** when the last lock is cleared.
@@ -24894,11 +25246,11 @@
2489425246
** holds a lock on the file. No need to check further. */
2489525247
reserved = 1;
2489625248
}else{
2489725249
/* The lock is held if and only if the lockfile exists */
2489825250
const char *zLockFile = (const char*)pFile->lockingContext;
24899
- reserved = access(zLockFile, 0)==0;
25251
+ reserved = osAccess(zLockFile, 0)==0;
2490025252
}
2490125253
OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
2490225254
*pResOut = reserved;
2490325255
return rc;
2490425256
}
@@ -24948,11 +25300,11 @@
2494825300
#endif
2494925301
return SQLITE_OK;
2495025302
}
2495125303
2495225304
/* grab an exclusive lock */
24953
- fd = open(zLockFile,O_RDONLY|O_CREAT|O_EXCL,0600);
25305
+ fd = robust_open(zLockFile,O_RDONLY|O_CREAT|O_EXCL,0600);
2495425306
if( fd<0 ){
2495525307
/* failed to open/create the file, someone else may have stolen the lock */
2495625308
int tErrno = errno;
2495725309
if( EEXIST == tErrno ){
2495825310
rc = SQLITE_BUSY;
@@ -25911,11 +26263,11 @@
2591126263
**
2591226264
** If the locking level of the file descriptor is already at or below
2591326265
** the requested locking level, this routine is a no-op.
2591426266
*/
2591526267
static int nfsUnlock(sqlite3_file *id, int eFileLock){
25916
- return _posixUnlock(id, eFileLock, 1);
26268
+ return posixUnlock(id, eFileLock, 1);
2591726269
}
2591826270
2591926271
#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
2592026272
/*
2592126273
** The code above is the NFS lock implementation. The code is specific
@@ -25953,14 +26305,14 @@
2595326305
#if (!defined(USE_PREAD) && !defined(USE_PREAD64))
2595426306
i64 newOffset;
2595526307
#endif
2595626308
TIMER_START;
2595726309
#if defined(USE_PREAD)
25958
- do{ got = pread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26310
+ do{ got = osPread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
2595926311
SimulateIOError( got = -1 );
2596026312
#elif defined(USE_PREAD64)
25961
- do{ got = pread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26313
+ do{ got = osPread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR);
2596226314
SimulateIOError( got = -1 );
2596326315
#else
2596426316
newOffset = lseek(id->h, offset, SEEK_SET);
2596526317
SimulateIOError( newOffset-- );
2596626318
if( newOffset!=offset ){
@@ -25969,11 +26321,11 @@
2596926321
}else{
2597026322
((unixFile*)id)->lastErrno = 0;
2597126323
}
2597226324
return -1;
2597326325
}
25974
- do{ got = read(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
26326
+ do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
2597526327
#endif
2597626328
TIMER_END;
2597726329
if( got<0 ){
2597826330
((unixFile*)id)->lastErrno = errno;
2597926331
}
@@ -26031,13 +26383,13 @@
2603126383
#if (!defined(USE_PREAD) && !defined(USE_PREAD64))
2603226384
i64 newOffset;
2603326385
#endif
2603426386
TIMER_START;
2603526387
#if defined(USE_PREAD)
26036
- do{ got = pwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26388
+ do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
2603726389
#elif defined(USE_PREAD64)
26038
- do{ got = pwrite64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26390
+ do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR);
2603926391
#else
2604026392
newOffset = lseek(id->h, offset, SEEK_SET);
2604126393
if( newOffset!=offset ){
2604226394
if( newOffset == -1 ){
2604326395
((unixFile*)id)->lastErrno = errno;
@@ -26044,11 +26396,11 @@
2604426396
}else{
2604526397
((unixFile*)id)->lastErrno = 0;
2604626398
}
2604726399
return -1;
2604826400
}
26049
- do{ got = write(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
26401
+ do{ got = osWrite(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
2605026402
#endif
2605126403
TIMER_END;
2605226404
if( got<0 ){
2605326405
((unixFile*)id)->lastErrno = errno;
2605426406
}
@@ -26212,11 +26564,11 @@
2621226564
*/
2621326565
#ifdef SQLITE_NO_SYNC
2621426566
rc = SQLITE_OK;
2621526567
#elif HAVE_FULLFSYNC
2621626568
if( fullSync ){
26217
- rc = fcntl(fd, F_FULLFSYNC, 0);
26569
+ rc = osFcntl(fd, F_FULLFSYNC, 0);
2621826570
}else{
2621926571
rc = 1;
2622026572
}
2622126573
/* If the FULLFSYNC failed, fall back to attempting an fsync().
2622226574
** It shouldn't be possible for fullfsync to fail on the local
@@ -26359,11 +26711,11 @@
2635926711
*/
2636026712
static int unixFileSize(sqlite3_file *id, i64 *pSize){
2636126713
int rc;
2636226714
struct stat buf;
2636326715
assert( id );
26364
- rc = fstat(((unixFile*)id)->h, &buf);
26716
+ rc = osFstat(((unixFile*)id)->h, &buf);
2636526717
SimulateIOError( rc=1 );
2636626718
if( rc!=0 ){
2636726719
((unixFile*)id)->lastErrno = errno;
2636826720
return SQLITE_IOERR_FSTAT;
2636926721
}
@@ -26400,18 +26752,18 @@
2640026752
static int fcntlSizeHint(unixFile *pFile, i64 nByte){
2640126753
if( pFile->szChunk ){
2640226754
i64 nSize; /* Required file size */
2640326755
struct stat buf; /* Used to hold return values of fstat() */
2640426756
26405
- if( fstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
26757
+ if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
2640626758
2640726759
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
2640826760
if( nSize>(i64)buf.st_size ){
2640926761
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
2641026762
int rc;
2641126763
do{
26412
- rc = posix_fallocate(pFile-.h, buf.st_size, nSize-buf.st_size;
26764
+ rc = osFallocate(pFile->.h, buf.st_size, nSize-buf.st_size;
2641326765
}while( rc<0 && errno=EINTR );
2641426766
if( rc ) return SQLITE_IOERR_WRITE;
2641526767
#else
2641626768
/* If the OS does not have posix_fallocate(), fake it. First use
2641726769
** ftruncate() to set the file size, then write a single byte to
@@ -26608,19 +26960,21 @@
2660826960
assert( n==1 || lockType!=F_RDLCK );
2660926961
2661026962
/* Locks are within range */
2661126963
assert( n>=1 && n<SQLITE_SHM_NLOCK );
2661226964
26613
- /* Initialize the locking parameters */
26614
- memset(&f, 0, sizeof(f));
26615
- f.l_type = lockType;
26616
- f.l_whence = SEEK_SET;
26617
- f.l_start = ofst;
26618
- f.l_len = n;
26619
-
26620
- rc = fcntl(pShmNode->h, F_SETLK, &f);
26621
- rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
26965
+ if( pShmNode->h>=0 ){
26966
+ /* Initialize the locking parameters */
26967
+ memset(&f, 0, sizeof(f));
26968
+ f.l_type = lockType;
26969
+ f.l_whence = SEEK_SET;
26970
+ f.l_start = ofst;
26971
+ f.l_len = n;
26972
+
26973
+ rc = osFcntl(pShmNode->h, F_SETLK, &f);
26974
+ rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
26975
+ }
2662226976
2662326977
/* Update the global lock state and do debug tracing */
2662426978
#ifdef SQLITE_DEBUG
2662526979
{ u16 mask;
2662626980
OSTRACE(("SHM-LOCK "));
@@ -26671,11 +27025,15 @@
2667127025
if( p && p->nRef==0 ){
2667227026
int i;
2667327027
assert( p->pInode==pFd->pInode );
2667427028
if( p->mutex ) sqlite3_mutex_free(p->mutex);
2667527029
for(i=0; i<p->nRegion; i++){
26676
- munmap(p->apRegion[i], p->szRegion);
27030
+ if( p->h>=0 ){
27031
+ munmap(p->apRegion[i], p->szRegion);
27032
+ }else{
27033
+ sqlite3_free(p->apRegion[i]);
27034
+ }
2667727035
}
2667827036
sqlite3_free(p->apRegion);
2667927037
if( p->h>=0 ){
2668027038
robust_close(pFd, p->h, __LINE__);
2668127039
p->h = -1;
@@ -26711,10 +27069,16 @@
2671127069
** "unsupported" and may go away in a future SQLite release.
2671227070
**
2671327071
** When opening a new shared-memory file, if no other instances of that
2671427072
** file are currently open, in this process or in other processes, then
2671527073
** the file must be truncated to zero length or have its header cleared.
27074
+**
27075
+** If the original database file (pDbFd) is using the "unix-excl" VFS
27076
+** that means that an exclusive lock is held on the database file and
27077
+** that no other processes are able to read or write the database. In
27078
+** that case, we do not really need shared memory. No shared memory
27079
+** file is created. The shared memory will be simulated with heap memory.
2671627080
*/
2671727081
static int unixOpenSharedMemory(unixFile *pDbFd){
2671827082
struct unixShm *p = 0; /* The connection to be opened */
2671927083
struct unixShmNode *pShmNode; /* The underlying mmapped file */
2672027084
int rc; /* Result code */
@@ -26740,11 +27104,11 @@
2674027104
/* Call fstat() to figure out the permissions on the database file. If
2674127105
** a new *-shm file is created, an attempt will be made to create it
2674227106
** with the same permissions. The actual permissions the file is created
2674327107
** with are subject to the current umask setting.
2674427108
*/
26745
- if( fstat(pDbFd->h, &sStat) ){
27109
+ if( osFstat(pDbFd->h, &sStat) && pInode->bProcessLock==0 ){
2674627110
rc = SQLITE_IOERR_FSTAT;
2674727111
goto shm_open_err;
2674827112
}
2674927113
2675027114
#ifdef SQLITE_SHM_DIRECTORY
@@ -26773,29 +27137,32 @@
2677327137
if( pShmNode->mutex==0 ){
2677427138
rc = SQLITE_NOMEM;
2677527139
goto shm_open_err;
2677627140
}
2677727141
26778
- pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, (sStat.st_mode & 0777));
26779
- if( pShmNode->h<0 ){
26780
- rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
26781
- goto shm_open_err;
26782
- }
26783
-
26784
- /* Check to see if another process is holding the dead-man switch.
26785
- ** If not, truncate the file to zero length.
26786
- */
26787
- rc = SQLITE_OK;
26788
- if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
26789
- if( robust_ftruncate(pShmNode->h, 0) ){
26790
- rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
26791
- }
26792
- }
26793
- if( rc==SQLITE_OK ){
26794
- rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1);
26795
- }
26796
- if( rc ) goto shm_open_err;
27142
+ if( pInode->bProcessLock==0 ){
27143
+ pShmNode->h = robust_open(zShmFilename, O_RDWR|O_CREAT,
27144
+ (sStat.st_mode & 0777));
27145
+ if( pShmNode->h<0 ){
27146
+ rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
27147
+ goto shm_open_err;
27148
+ }
27149
+
27150
+ /* Check to see if another process is holding the dead-man switch.
27151
+ ** If not, truncate the file to zero length.
27152
+ */
27153
+ rc = SQLITE_OK;
27154
+ if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
27155
+ if( robust_ftruncate(pShmNode->h, 0) ){
27156
+ rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
27157
+ }
27158
+ }
27159
+ if( rc==SQLITE_OK ){
27160
+ rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1);
27161
+ }
27162
+ if( rc ) goto shm_open_err;
27163
+ }
2679727164
}
2679827165
2679927166
/* Make the new connection a child of the unixShmNode */
2680027167
p->pShmNode = pShmNode;
2680127168
#ifdef SQLITE_DEBUG
@@ -26865,38 +27232,44 @@
2686527232
2686627233
p = pDbFd->pShm;
2686727234
pShmNode = p->pShmNode;
2686827235
sqlite3_mutex_enter(pShmNode->mutex);
2686927236
assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
27237
+ assert( pShmNode->pInode==pDbFd->pInode );
27238
+ assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 );
27239
+ assert( pShmNode->h<0 || pDbFd->pInode->bProcessLock==0 );
2687027240
2687127241
if( pShmNode->nRegion<=iRegion ){
2687227242
char **apNew; /* New apRegion[] array */
2687327243
int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
2687427244
struct stat sStat; /* Used by fstat() */
2687527245
2687627246
pShmNode->szRegion = szRegion;
2687727247
26878
- /* The requested region is not mapped into this processes address space.
26879
- ** Check to see if it has been allocated (i.e. if the wal-index file is
26880
- ** large enough to contain the requested region).
26881
- */
26882
- if( fstat(pShmNode->h, &sStat) ){
26883
- rc = SQLITE_IOERR_SHMSIZE;
26884
- goto shmpage_out;
26885
- }
26886
-
26887
- if( sStat.st_size<nByte ){
26888
- /* The requested memory region does not exist. If bExtend is set to
26889
- ** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
26890
- **
26891
- ** Alternatively, if bExtend is true, use ftruncate() to allocate
26892
- ** the requested memory region.
26893
- */
26894
- if( !bExtend ) goto shmpage_out;
26895
- if( robust_ftruncate(pShmNode->h, nByte) ){
26896
- rc = unixLogError(SQLITE_IOERR_SHMSIZE,"ftruncate",pShmNode->zFilename);
26897
- goto shmpage_out;
27248
+ if( pShmNode->h>=0 ){
27249
+ /* The requested region is not mapped into this processes address space.
27250
+ ** Check to see if it has been allocated (i.e. if the wal-index file is
27251
+ ** large enough to contain the requested region).
27252
+ */
27253
+ if( osFstat(pShmNode->h, &sStat) ){
27254
+ rc = SQLITE_IOERR_SHMSIZE;
27255
+ goto shmpage_out;
27256
+ }
27257
+
27258
+ if( sStat.st_size<nByte ){
27259
+ /* The requested memory region does not exist. If bExtend is set to
27260
+ ** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
27261
+ **
27262
+ ** Alternatively, if bExtend is true, use ftruncate() to allocate
27263
+ ** the requested memory region.
27264
+ */
27265
+ if( !bExtend ) goto shmpage_out;
27266
+ if( robust_ftruncate(pShmNode->h, nByte) ){
27267
+ rc = unixLogError(SQLITE_IOERR_SHMSIZE, "ftruncate",
27268
+ pShmNode->zFilename);
27269
+ goto shmpage_out;
27270
+ }
2689827271
}
2689927272
}
2690027273
2690127274
/* Map the requested memory region into this processes address space. */
2690227275
apNew = (char **)sqlite3_realloc(
@@ -26906,16 +27279,26 @@
2690627279
rc = SQLITE_IOERR_NOMEM;
2690727280
goto shmpage_out;
2690827281
}
2690927282
pShmNode->apRegion = apNew;
2691027283
while(pShmNode->nRegion<=iRegion){
26911
- void *pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
26912
- MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
26913
- );
26914
- if( pMem==MAP_FAILED ){
26915
- rc = SQLITE_IOERR;
26916
- goto shmpage_out;
27284
+ void *pMem;
27285
+ if( pShmNode->h>=0 ){
27286
+ pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
27287
+ MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
27288
+ );
27289
+ if( pMem==MAP_FAILED ){
27290
+ rc = SQLITE_IOERR;
27291
+ goto shmpage_out;
27292
+ }
27293
+ }else{
27294
+ pMem = sqlite3_malloc(szRegion);
27295
+ if( pMem==0 ){
27296
+ rc = SQLITE_NOMEM;
27297
+ goto shmpage_out;
27298
+ }
27299
+ memset(pMem, 0, szRegion);
2691727300
}
2691827301
pShmNode->apRegion[pShmNode->nRegion] = pMem;
2691927302
pShmNode->nRegion++;
2692027303
}
2692127304
}
@@ -26958,10 +27341,12 @@
2695827341
assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
2695927342
|| flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
2696027343
|| flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
2696127344
|| flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
2696227345
assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
27346
+ assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 );
27347
+ assert( pShmNode->h<0 || pDbFd->pInode->bProcessLock==0 );
2696327348
2696427349
mask = (1<<(ofst+n)) - (1<<ofst);
2696527350
assert( n>1 || mask==(1<<ofst) );
2696627351
sqlite3_mutex_enter(pShmNode->mutex);
2696727352
if( flags & SQLITE_SHM_UNLOCK ){
@@ -27095,11 +27480,11 @@
2709527480
** shared-memory file, too */
2709627481
unixEnterMutex();
2709727482
assert( pShmNode->nRef>0 );
2709827483
pShmNode->nRef--;
2709927484
if( pShmNode->nRef==0 ){
27100
- if( deleteFlag ) unlink(pShmNode->zFilename);
27485
+ if( deleteFlag && pShmNode->h>=0 ) unlink(pShmNode->zFilename);
2710127486
unixShmPurge(pDbFd);
2710227487
}
2710327488
unixLeaveMutex();
2710427489
2710527490
return SQLITE_OK;
@@ -27336,11 +27721,11 @@
2733627721
*/
2733727722
lockInfo.l_len = 1;
2733827723
lockInfo.l_start = 0;
2733927724
lockInfo.l_whence = SEEK_SET;
2734027725
lockInfo.l_type = F_RDLCK;
27341
- if( fcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
27726
+ if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
2734227727
if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){
2734327728
return &nfsIoMethods;
2734427729
} else {
2734527730
return &posixIoMethods;
2734627731
}
@@ -27378,11 +27763,11 @@
2737827763
*/
2737927764
lockInfo.l_len = 1;
2738027765
lockInfo.l_start = 0;
2738127766
lockInfo.l_whence = SEEK_SET;
2738227767
lockInfo.l_type = F_RDLCK;
27383
- if( fcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
27768
+ if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
2738427769
return &posixIoMethods;
2738527770
}else{
2738627771
return &semIoMethods;
2738727772
}
2738827773
}
@@ -27412,11 +27797,12 @@
2741227797
int h, /* Open file descriptor of file being opened */
2741327798
int dirfd, /* Directory file descriptor */
2741427799
sqlite3_file *pId, /* Write to the unixFile structure here */
2741527800
const char *zFilename, /* Name of the file being opened */
2741627801
int noLock, /* Omit locking if true */
27417
- int isDelete /* Delete on close if true */
27802
+ int isDelete, /* Delete on close if true */
27803
+ int isReadOnly /* True if the file is opened read-only */
2741827804
){
2741927805
const sqlite3_io_methods *pLockingStyle;
2742027806
unixFile *pNew = (unixFile *)pId;
2742127807
int rc = SQLITE_OK;
2742227808
@@ -27439,12 +27825,19 @@
2743927825
#endif
2744027826
2744127827
OSTRACE(("OPEN %-3d %s\n", h, zFilename));
2744227828
pNew->h = h;
2744327829
pNew->dirfd = dirfd;
27444
- pNew->fileFlags = 0;
2744527830
pNew->zPath = zFilename;
27831
+ if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
27832
+ pNew->ctrlFlags = UNIXFILE_EXCL;
27833
+ }else{
27834
+ pNew->ctrlFlags = 0;
27835
+ }
27836
+ if( isReadOnly ){
27837
+ pNew->ctrlFlags |= UNIXFILE_RDONLY;
27838
+ }
2744627839
2744727840
#if OS_VXWORKS
2744827841
pNew->pId = vxworksFindFileId(zFilename);
2744927842
if( pNew->pId==0 ){
2745027843
noLock = 1;
@@ -27601,14 +27994,14 @@
2760127994
2760227995
sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename);
2760327996
for(ii=(int)strlen(zDirname); ii>1 && zDirname[ii]!='/'; ii--);
2760427997
if( ii>0 ){
2760527998
zDirname[ii] = '\0';
27606
- fd = open(zDirname, O_RDONLY|O_BINARY, 0);
27999
+ fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0);
2760728000
if( fd>=0 ){
2760828001
#ifdef FD_CLOEXEC
27609
- fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
28002
+ osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
2761028003
#endif
2761128004
OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
2761228005
}
2761328006
}
2761428007
*pFd = fd;
@@ -27634,13 +28027,13 @@
2763428027
2763528028
azDirs[0] = sqlite3_temp_directory;
2763628029
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
2763728030
for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
2763828031
if( zDir==0 ) continue;
27639
- if( stat(zDir, &buf) ) continue;
28032
+ if( osStat(zDir, &buf) ) continue;
2764028033
if( !S_ISDIR(buf.st_mode) ) continue;
27641
- if( access(zDir, 07) ) continue;
28034
+ if( osAccess(zDir, 07) ) continue;
2764228035
break;
2764328036
}
2764428037
return zDir;
2764528038
}
2764628039
@@ -27679,11 +28072,11 @@
2767928072
sqlite3_randomness(15, &zBuf[j]);
2768028073
for(i=0; i<15; i++, j++){
2768128074
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
2768228075
}
2768328076
zBuf[j] = 0;
27684
- }while( access(zBuf,0)==0 );
28077
+ }while( osAccess(zBuf,0)==0 );
2768528078
return SQLITE_OK;
2768628079
}
2768728080
2768828081
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
2768928082
/*
@@ -27940,19 +28333,20 @@
2794028333
if( rc!=SQLITE_OK ){
2794128334
assert( !p->pUnused );
2794228335
assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
2794328336
return rc;
2794428337
}
27945
- fd = open(zName, openFlags, openMode);
28338
+ fd = robust_open(zName, openFlags, openMode);
2794628339
OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
2794728340
if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){
2794828341
/* Failed to open the file for read/write access. Try read-only. */
2794928342
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
2795028343
openFlags &= ~(O_RDWR|O_CREAT);
2795128344
flags |= SQLITE_OPEN_READONLY;
2795228345
openFlags |= O_RDONLY;
27953
- fd = open(zName, openFlags, openMode);
28346
+ isReadonly = 1;
28347
+ fd = robust_open(zName, openFlags, openMode);
2795428348
}
2795528349
if( fd<0 ){
2795628350
rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
2795728351
goto open_finished;
2795828352
}
@@ -27992,11 +28386,11 @@
2799228386
goto open_finished;
2799328387
}
2799428388
}
2799528389
2799628390
#ifdef FD_CLOEXEC
27997
- fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
28391
+ osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
2799828392
#endif
2799928393
2800028394
noLock = eType!=SQLITE_OPEN_MAIN_DB;
2800128395
2800228396
@@ -28044,11 +28438,12 @@
2804428438
goto open_finished;
2804528439
}
2804628440
useProxy = !(fsInfo.f_flags&MNT_LOCAL);
2804728441
}
2804828442
if( useProxy ){
28049
- rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock, isDelete);
28443
+ rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock,
28444
+ isDelete, isReadonly);
2805028445
if( rc==SQLITE_OK ){
2805128446
rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
2805228447
if( rc!=SQLITE_OK ){
2805328448
/* Use unixClose to clean up the resources added in fillInUnixFile
2805428449
** and clear all the structure's references. Specifically,
@@ -28061,11 +28456,12 @@
2806128456
goto open_finished;
2806228457
}
2806328458
}
2806428459
#endif
2806528460
28066
- rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock, isDelete);
28461
+ rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock,
28462
+ isDelete, isReadonly);
2806728463
open_finished:
2806828464
if( rc!=SQLITE_OK ){
2806928465
sqlite3_free(p->pUnused);
2807028466
}
2807128467
return rc;
@@ -28138,11 +28534,11 @@
2813828534
break;
2813928535
2814028536
default:
2814128537
assert(!"Invalid flags argument");
2814228538
}
28143
- *pResOut = (access(zPath, amode)==0);
28539
+ *pResOut = (osAccess(zPath, amode)==0);
2814428540
if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){
2814528541
struct stat buf;
2814628542
if( 0==stat(zPath, &buf) && buf.st_size==0 ){
2814728543
*pResOut = 0;
2814828544
}
@@ -28180,11 +28576,11 @@
2818028576
zOut[nOut-1] = '\0';
2818128577
if( zPath[0]=='/' ){
2818228578
sqlite3_snprintf(nOut, zOut, "%s", zPath);
2818328579
}else{
2818428580
int nCwd;
28185
- if( getcwd(zOut, nOut-1)==0 ){
28581
+ if( osGetcwd(zOut, nOut-1)==0 ){
2818628582
return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
2818728583
}
2818828584
nCwd = (int)strlen(zOut);
2818928585
sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath);
2819028586
}
@@ -28275,21 +28671,21 @@
2827528671
*/
2827628672
memset(zBuf, 0, nBuf);
2827728673
#if !defined(SQLITE_TEST)
2827828674
{
2827928675
int pid, fd;
28280
- fd = open("/dev/urandom", O_RDONLY);
28676
+ fd = robust_open("/dev/urandom", O_RDONLY, 0);
2828128677
if( fd<0 ){
2828228678
time_t t;
2828328679
time(&t);
2828428680
memcpy(zBuf, &t, sizeof(t));
2828528681
pid = getpid();
2828628682
memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
2828728683
assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
2828828684
nBuf = sizeof(t) + sizeof(pid);
2828928685
}else{
28290
- do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
28686
+ do{ nBuf = osRead(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
2829128687
robust_close(0, fd, __LINE__);
2829228688
}
2829328689
}
2829428690
#endif
2829528691
return nBuf;
@@ -28684,21 +29080,21 @@
2868429080
if( !pUnused ){
2868529081
return SQLITE_NOMEM;
2868629082
}
2868729083
}
2868829084
if( fd<0 ){
28689
- fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
29085
+ fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
2869029086
terrno = errno;
2869129087
if( fd<0 && errno==ENOENT && islockfile ){
2869229088
if( proxyCreateLockPath(path) == SQLITE_OK ){
28693
- fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
29089
+ fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
2869429090
}
2869529091
}
2869629092
}
2869729093
if( fd<0 ){
2869829094
openFlags = O_RDONLY;
28699
- fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
29095
+ fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
2870029096
terrno = errno;
2870129097
}
2870229098
if( fd<0 ){
2870329099
if( islockfile ){
2870429100
return SQLITE_BUSY;
@@ -28723,11 +29119,11 @@
2872329119
dummyVfs.pAppData = (void*)&autolockIoFinder;
2872429120
pUnused->fd = fd;
2872529121
pUnused->flags = openFlags;
2872629122
pNew->pUnused = pUnused;
2872729123
28728
- rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0);
29124
+ rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0, 0);
2872929125
if( rc==SQLITE_OK ){
2873029126
*ppFile = pNew;
2873129127
return SQLITE_OK;
2873229128
}
2873329129
end_create_proxy:
@@ -28808,22 +29204,23 @@
2880829204
(strlcpy(&tPath[pathLen-5], "break", 6) != 5) ){
2880929205
sqlite3_snprintf(sizeof(errmsg),errmsg,"path error (len %d)",(int)pathLen);
2881029206
goto end_breaklock;
2881129207
}
2881229208
/* read the conch content */
28813
- readLen = pread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
29209
+ readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
2881429210
if( readLen<PROXY_PATHINDEX ){
2881529211
sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
2881629212
goto end_breaklock;
2881729213
}
2881829214
/* write it out to the temporary break file */
28819
- fd = open(tPath, (O_RDWR|O_CREAT|O_EXCL), SQLITE_DEFAULT_FILE_PERMISSIONS);
29215
+ fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL),
29216
+ SQLITE_DEFAULT_FILE_PERMISSIONS);
2882029217
if( fd<0 ){
2882129218
sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
2882229219
goto end_breaklock;
2882329220
}
28824
- if( pwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
29221
+ if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
2882529222
sqlite3_snprintf(sizeof(errmsg), errmsg, "write failed (%d)", errno);
2882629223
goto end_breaklock;
2882729224
}
2882829225
if( rename(tPath, cPath) ){
2882929226
sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno);
@@ -28865,11 +29262,11 @@
2886529262
* 2nd try: fail if the mod time changed or host id is different, wait
2886629263
* 10 sec and try again
2886729264
* 3rd try: break the lock unless the mod time has changed.
2886829265
*/
2886929266
struct stat buf;
28870
- if( fstat(conchFile->h, &buf) ){
29267
+ if( osFstat(conchFile->h, &buf) ){
2887129268
pFile->lastErrno = errno;
2887229269
return SQLITE_IOERR_LOCK;
2887329270
}
2887429271
2887529272
if( nTries==1 ){
@@ -28884,11 +29281,11 @@
2888429281
return SQLITE_BUSY;
2888529282
}
2888629283
2888729284
if( nTries==2 ){
2888829285
char tBuf[PROXY_MAXCONCHLEN];
28889
- int len = pread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
29286
+ int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
2889029287
if( len<0 ){
2889129288
pFile->lastErrno = errno;
2889229289
return SQLITE_IOERR_LOCK;
2889329290
}
2889429291
if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){
@@ -29054,20 +29451,20 @@
2905429451
/* If we created a new conch file (not just updated the contents of a
2905529452
** valid conch file), try to match the permissions of the database
2905629453
*/
2905729454
if( rc==SQLITE_OK && createConch ){
2905829455
struct stat buf;
29059
- int err = fstat(pFile->h, &buf);
29456
+ int err = osFstat(pFile->h, &buf);
2906029457
if( err==0 ){
2906129458
mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
2906229459
S_IROTH|S_IWOTH);
2906329460
/* try to match the database file R/W permissions, ignore failure */
2906429461
#ifndef SQLITE_PROXY_DEBUG
29065
- fchmod(conchFile->h, cmode);
29462
+ osFchmod(conchFile->h, cmode);
2906629463
#else
2906729464
do{
29068
- rc = fchmod(conchFile->h, cmode);
29465
+ rc = osFchmod(conchFile->h, cmode);
2906929466
}while( rc==(-1) && errno==EINTR );
2907029467
if( rc!=0 ){
2907129468
int code = errno;
2907229469
fprintf(stderr, "fchmod %o FAILED with %d %s\n",
2907329470
cmode, code, strerror(code));
@@ -29089,11 +29486,11 @@
2908929486
if( rc==SQLITE_OK && pFile->openFlags ){
2909029487
if( pFile->h>=0 ){
2909129488
robust_close(pFile, pFile->h, __LINE__);
2909229489
}
2909329490
pFile->h = -1;
29094
- int fd = open(pCtx->dbPath, pFile->openFlags,
29491
+ int fd = robust_open(pCtx->dbPath, pFile->openFlags,
2909529492
SQLITE_DEFAULT_FILE_PERMISSIONS);
2909629493
OSTRACE(("TRANSPROXY: OPEN %d\n", fd));
2909729494
if( fd>=0 ){
2909829495
pFile->h = fd;
2909929496
}else{
@@ -29315,11 +29712,11 @@
2931529712
*/
2931629713
struct statfs fsInfo;
2931729714
struct stat conchInfo;
2931829715
int goLockless = 0;
2931929716
29320
- if( stat(pCtx->conchFilePath, &conchInfo) == -1 ) {
29717
+ if( osStat(pCtx->conchFilePath, &conchInfo) == -1 ) {
2932129718
int err = errno;
2932229719
if( (err==ENOENT) && (statfs(dbPath, &fsInfo) != -1) ){
2932329720
goLockless = (fsInfo.f_flags&MNT_RDONLY) == MNT_RDONLY;
2932429721
}
2932529722
}
@@ -29600,11 +29997,11 @@
2960029997
** more than that; it looks at the filesystem type that hosts the
2960129998
** database file and tries to choose an locking method appropriate for
2960229999
** that filesystem time.
2960330000
*/
2960430001
#define UNIXVFS(VFSNAME, FINDER) { \
29605
- 2, /* iVersion */ \
30002
+ 3, /* iVersion */ \
2960630003
sizeof(unixFile), /* szOsFile */ \
2960730004
MAX_PATHNAME, /* mxPathname */ \
2960830005
0, /* pNext */ \
2960930006
VFSNAME, /* zName */ \
2961030007
(void*)&FINDER, /* pAppData */ \
@@ -29619,10 +30016,13 @@
2961930016
unixRandomness, /* xRandomness */ \
2962030017
unixSleep, /* xSleep */ \
2962130018
unixCurrentTime, /* xCurrentTime */ \
2962230019
unixGetLastError, /* xGetLastError */ \
2962330020
unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
30021
+ unixSetSystemCall, /* xSetSystemCall */ \
30022
+ unixGetSystemCall, /* xGetSystemCall */ \
30023
+ unixNextSystemCall, /* xNextSystemCall */ \
2962430024
}
2962530025
2962630026
/*
2962730027
** All default VFSes for unix are contained in the following array.
2962830028
**
@@ -29636,10 +30036,11 @@
2963630036
#else
2963730037
UNIXVFS("unix", posixIoFinder ),
2963830038
#endif
2963930039
UNIXVFS("unix-none", nolockIoFinder ),
2964030040
UNIXVFS("unix-dotfile", dotlockIoFinder ),
30041
+ UNIXVFS("unix-excl", posixIoFinder ),
2964130042
#if OS_VXWORKS
2964230043
UNIXVFS("unix-namedsem", semIoFinder ),
2964330044
#endif
2964430045
#if SQLITE_ENABLE_LOCKING_STYLE
2964530046
UNIXVFS("unix-posix", posixIoFinder ),
@@ -32626,11 +33027,11 @@
3262633027
/*
3262733028
** Initialize and deinitialize the operating system interface.
3262833029
*/
3262933030
SQLITE_API int sqlite3_os_init(void){
3263033031
static sqlite3_vfs winVfs = {
32631
- 2, /* iVersion */
33032
+ 3, /* iVersion */
3263233033
sizeof(winFile), /* szOsFile */
3263333034
MAX_PATH, /* mxPathname */
3263433035
0, /* pNext */
3263533036
"win32", /* zName */
3263633037
0, /* pAppData */
@@ -32645,10 +33046,13 @@
3264533046
winRandomness, /* xRandomness */
3264633047
winSleep, /* xSleep */
3264733048
winCurrentTime, /* xCurrentTime */
3264833049
winGetLastError, /* xGetLastError */
3264933050
winCurrentTimeInt64, /* xCurrentTimeInt64 */
33051
+ 0, /* xSetSystemCall */
33052
+ 0, /* xGetSystemCall */
33053
+ 0, /* xNextSystemCall */
3265033054
};
3265133055
3265233056
#ifndef SQLITE_OMIT_WAL
3265333057
/* get memory map allocation granularity */
3265433058
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
@@ -50782,15 +51186,13 @@
5078251186
}
5078351187
if( nearby>0 ){
5078451188
u32 i;
5078551189
int dist;
5078651190
closest = 0;
50787
- dist = get4byte(&aData[8]) - nearby;
50788
- if( dist<0 ) dist = -dist;
51191
+ dist = sqlite3AbsInt32(get4byte(&aData[8]) - nearby);
5078951192
for(i=1; i<k; i++){
50790
- int d2 = get4byte(&aData[8+i*4]) - nearby;
50791
- if( d2<0 ) d2 = -d2;
51193
+ int d2 = sqlite3AbsInt32(get4byte(&aData[8+i*4]) - nearby);
5079251194
if( d2<dist ){
5079351195
closest = i;
5079451196
dist = d2;
5079551197
}
5079651198
}
@@ -55777,13 +56179,18 @@
5577756179
}
5577856180
}else if( op==TK_UMINUS ) {
5577956181
/* This branch happens for multiple negative signs. Ex: -(-5) */
5578056182
if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
5578156183
sqlite3VdbeMemNumerify(pVal);
55782
- pVal->u.i = -1 * pVal->u.i;
55783
- /* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */
55784
- pVal->r = (double)-1 * pVal->r;
56184
+ if( pVal->u.i==SMALLEST_INT64 ){
56185
+ pVal->flags &= MEM_Int;
56186
+ pVal->flags |= MEM_Real;
56187
+ pVal->r = (double)LARGEST_INT64;
56188
+ }else{
56189
+ pVal->u.i = -pVal->u.i;
56190
+ }
56191
+ pVal->r = -pVal->r;
5578556192
sqlite3ValueApplyAffinity(pVal, affinity, enc);
5578656193
}
5578756194
}else if( op==TK_NULL ){
5578856195
pVal = sqlite3ValueNew(db);
5578956196
if( pVal==0 ) goto no_mem;
@@ -56805,12 +57212,12 @@
5680557212
** will be used so that it can acquire mutexes on them all in sorted
5680657213
** order (via sqlite3VdbeMutexArrayEnter(). Mutexes are acquired
5680757214
** in order (and released in reverse order) to avoid deadlocks.
5680857215
*/
5680957216
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){
56810
- int mask;
56811
- assert( i>=0 && i<p->db->nDb && i<sizeof(u32)*8 );
57217
+ tAttachMask mask;
57218
+ assert( i>=0 && i<p->db->nDb && i<sizeof(tAttachMask)*8 );
5681257219
assert( i<(int)sizeof(p->btreeMask)*8 );
5681357220
mask = ((u32)1)<<i;
5681457221
if( (p->btreeMask & mask)==0 ){
5681557222
p->btreeMask |= mask;
5681657223
sqlite3BtreeMutexArrayInsert(&p->aMutex, p->db->aDb[i].pBt);
@@ -61309,10 +61716,11 @@
6130961716
struct OP_SetCookie_stack_vars {
6131061717
Db *pDb;
6131161718
} au;
6131261719
struct OP_VerifyCookie_stack_vars {
6131361720
int iMeta;
61721
+ int iGen;
6131461722
Btree *pBt;
6131561723
} av;
6131661724
struct OP_OpenWrite_stack_vars {
6131761725
int nField;
6131861726
KeyInfo *pKeyInfo;
@@ -63931,14 +64339,16 @@
6393164339
p->expired = 0;
6393264340
}
6393364341
break;
6393464342
}
6393564343
63936
-/* Opcode: VerifyCookie P1 P2 *
64344
+/* Opcode: VerifyCookie P1 P2 P3 * *
6393764345
**
6393864346
** Check the value of global database parameter number 0 (the
63939
-** schema version) and make sure it is equal to P2.
64347
+** schema version) and make sure it is equal to P2 and that the
64348
+** generation counter on the local schema parse equals P3.
64349
+**
6394064350
** P1 is the database number which is 0 for the main database file
6394164351
** and 1 for the file holding temporary tables and some higher number
6394264352
** for auxiliary databases.
6394364353
**
6394464354
** The cookie changes its value whenever the database schema changes.
@@ -63950,21 +64360,24 @@
6395064360
** invoked.
6395164361
*/
6395264362
case OP_VerifyCookie: {
6395364363
#if 0 /* local variables moved into u.av */
6395464364
int iMeta;
64365
+ int iGen;
6395564366
Btree *pBt;
6395664367
#endif /* local variables moved into u.av */
64368
+
6395764369
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6395864370
assert( (p->btreeMask & (1<<pOp->p1))!=0 );
6395964371
u.av.pBt = db->aDb[pOp->p1].pBt;
6396064372
if( u.av.pBt ){
6396164373
sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta);
64374
+ u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
6396264375
}else{
6396364376
u.av.iMeta = 0;
6396464377
}
63965
- if( u.av.iMeta!=pOp->p2 ){
64378
+ if( u.av.iMeta!=pOp->p2 || u.av.iGen!=pOp->p3 ){
6396664379
sqlite3DbFree(db, p->zErrMsg);
6396764380
p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
6396864381
/* If the schema-cookie from the database file matches the cookie
6396964382
** stored with the in-memory representation of the schema, do
6397064383
** not reload the schema from the database file.
@@ -65694,18 +66107,14 @@
6569466107
rc = sqlite3BtreeCreateTable(u.bt.pDb->pBt, &u.bt.pgno, u.bt.flags);
6569566108
pOut->u.i = u.bt.pgno;
6569666109
break;
6569766110
}
6569866111
65699
-/* Opcode: ParseSchema P1 P2 * P4 *
66112
+/* Opcode: ParseSchema P1 * * P4 *
6570066113
**
6570166114
** Read and parse all entries from the SQLITE_MASTER table of database P1
65702
-** that match the WHERE clause P4. P2 is the "force" flag. Always do
65703
-** the parsing if P2 is true. If P2 is false, then this routine is a
65704
-** no-op if the schema is not currently loaded. In other words, if P2
65705
-** is false, the SQLITE_MASTER table is only parsed if the rest of the
65706
-** schema is already loaded into the symbol table.
66115
+** that match the WHERE clause P4.
6570766116
**
6570866117
** This opcode invokes the parser to create a new virtual machine,
6570966118
** then runs the new virtual machine. It is thus a re-entrant opcode.
6571066119
*/
6571166120
case OP_ParseSchema: {
@@ -65717,18 +66126,11 @@
6571766126
#endif /* local variables moved into u.bu */
6571866127
6571966128
u.bu.iDb = pOp->p1;
6572066129
assert( u.bu.iDb>=0 && u.bu.iDb<db->nDb );
6572166130
65722
- /* If pOp->p2 is 0, then this opcode is being executed to read a
65723
- ** single row, for example the row corresponding to a new index
65724
- ** created by this VDBE, from the sqlite_master table. It only
65725
- ** does this if the corresponding in-memory schema is currently
65726
- ** loaded. Otherwise, the new index definition can be loaded along
65727
- ** with the rest of the schema when it is required.
65728
- **
65729
- ** Although the mutex on the BtShared object that corresponds to
66131
+ /* Although the mutex on the BtShared object that corresponds to
6573066132
** database u.bu.iDb (the database containing the sqlite_master table
6573166133
** read by this instruction) is currently held, it is necessary to
6573266134
** obtain the mutexes on all attached databases before checking if
6573366135
** the schema of u.bu.iDb is loaded. This is because, at the start of
6573466136
** the sqlite3_exec() call below, SQLite will invoke
@@ -65740,11 +66142,11 @@
6574066142
** can result in a "no such table: sqlite_master" or "malformed
6574166143
** database schema" error being returned to the user.
6574266144
*/
6574366145
assert( sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) );
6574466146
sqlite3BtreeEnterAll(db);
65745
- if( pOp->p2 || DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded) ){
66147
+ if( ALWAYS(DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded)) ){
6574666148
u.bu.zMaster = SCHEMA_TABLE(u.bu.iDb);
6574766149
u.bu.initData.db = db;
6574866150
u.bu.initData.iDb = pOp->p1;
6574966151
u.bu.initData.pzErrMsg = &p->zErrMsg;
6575066152
u.bu.zSql = sqlite3MPrintf(db,
@@ -67395,10 +67797,11 @@
6739567797
sqlite3VdbeChangeP2(v, 0, flags);
6739667798
6739767799
/* Configure the OP_VerifyCookie */
6739867800
sqlite3VdbeChangeP1(v, 1, iDb);
6739967801
sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie);
67802
+ sqlite3VdbeChangeP3(v, 1, pTab->pSchema->iGeneration);
6740067803
6740167804
/* Make sure a mutex is held on the table to be accessed */
6740267805
sqlite3VdbeUsesBtree(v, iDb);
6740367806
6740467807
/* Configure the OP_TableLock instruction */
@@ -69826,10 +70229,11 @@
6982670229
6982770230
if( pToken ){
6982870231
if( op!=TK_INTEGER || pToken->z==0
6982970232
|| sqlite3GetInt32(pToken->z, &iValue)==0 ){
6983070233
nExtra = pToken->n+1;
70234
+ assert( iValue>=0 );
6983170235
}
6983270236
}
6983370237
pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
6983470238
if( pNew ){
6983570239
pNew->op = (u8)op;
@@ -70051,10 +70455,12 @@
7005170455
/*
7005270456
** Recursively delete an expression tree.
7005370457
*/
7005470458
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
7005570459
if( p==0 ) return;
70460
+ /* Sanity check: Assert that the IntValue is non-negative if it exists */
70461
+ assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
7005670462
if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
7005770463
sqlite3ExprDelete(db, p->pLeft);
7005870464
sqlite3ExprDelete(db, p->pRight);
7005970465
if( !ExprHasProperty(p, EP_Reduced) && (p->flags2 & EP2_MallocedToken)!=0 ){
7006070466
sqlite3DbFree(db, p->u.zToken);
@@ -70660,17 +71066,10 @@
7066071066
}
7066171067
break;
7066271068
}
7066371069
default: break;
7066471070
}
70665
- if( rc ){
70666
- assert( ExprHasAnyProperty(p, EP_Reduced|EP_TokenOnly)
70667
- || (p->flags2 & EP2_MallocedToken)==0 );
70668
- p->op = TK_INTEGER;
70669
- p->flags |= EP_IntValue;
70670
- p->u.iValue = *pValue;
70671
- }
7067271071
return rc;
7067371072
}
7067471073
7067571074
/*
7067671075
** Return FALSE if there is no chance that the expression can be NULL.
@@ -71391,10 +71790,11 @@
7139171790
*/
7139271791
static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
7139371792
Vdbe *v = pParse->pVdbe;
7139471793
if( pExpr->flags & EP_IntValue ){
7139571794
int i = pExpr->u.iValue;
71795
+ assert( i>=0 );
7139671796
if( negFlag ) i = -i;
7139771797
sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
7139871798
}else{
7139971799
int c;
7140071800
i64 value;
@@ -75655,19 +76055,21 @@
7565576055
** set for each database that is used. Generate code to start a
7565676056
** transaction on each used database and to verify the schema cookie
7565776057
** on each used database.
7565876058
*/
7565976059
if( pParse->cookieGoto>0 ){
75660
- u32 mask;
76060
+ tAttachMask mask;
7566176061
int iDb;
7566276062
sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
7566376063
for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
7566476064
if( (mask & pParse->cookieMask)==0 ) continue;
7566576065
sqlite3VdbeUsesBtree(v, iDb);
7566676066
sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
7566776067
if( db->init.busy==0 ){
75668
- sqlite3VdbeAddOp2(v,OP_VerifyCookie, iDb, pParse->cookieValue[iDb]);
76068
+ sqlite3VdbeAddOp3(v, OP_VerifyCookie,
76069
+ iDb, pParse->cookieValue[iDb],
76070
+ db->aDb[iDb].pSchema->iGeneration);
7566976071
}
7567076072
}
7567176073
#ifndef SQLITE_OMIT_VIRTUALTABLE
7567276074
{
7567376075
int i;
@@ -75873,11 +76275,11 @@
7587376275
int len;
7587476276
Hash *pHash = &db->aDb[iDb].pSchema->idxHash;
7587576277
7587676278
len = sqlite3Strlen30(zIdxName);
7587776279
pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0);
75878
- if( pIndex ){
76280
+ if( ALWAYS(pIndex) ){
7587976281
if( pIndex->pTable->pIndex==pIndex ){
7588076282
pIndex->pTable->pIndex = pIndex->pNext;
7588176283
}else{
7588276284
Index *p;
7588376285
/* Justification of ALWAYS(); The index must be on the list of
@@ -78949,16 +79351,16 @@
7894979351
if( v==0 ) return; /* This only happens if there was a prior error */
7895079352
pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1;
7895179353
}
7895279354
if( iDb>=0 ){
7895379355
sqlite3 *db = pToplevel->db;
78954
- int mask;
79356
+ tAttachMask mask;
7895579357
7895679358
assert( iDb<db->nDb );
7895779359
assert( db->aDb[iDb].pBt!=0 || iDb==1 );
7895879360
assert( iDb<SQLITE_MAX_ATTACHED+2 );
78959
- mask = 1<<iDb;
79361
+ mask = ((tAttachMask)1)<<iDb;
7896079362
if( (pToplevel->cookieMask & mask)==0 ){
7896179363
pToplevel->cookieMask |= mask;
7896279364
pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
7896379365
if( !OMIT_TEMPDB && iDb==1 ){
7896479366
sqlite3OpenTempDatabase(pToplevel);
@@ -78981,11 +79383,11 @@
7898179383
** necessary to undo a write and the checkpoint should not be set.
7898279384
*/
7898379385
SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
7898479386
Parse *pToplevel = sqlite3ParseToplevel(pParse);
7898579387
sqlite3CodeVerifySchema(pParse, iDb);
78986
- pToplevel->writeMask |= 1<<iDb;
79388
+ pToplevel->writeMask |= ((tAttachMask)1)<<iDb;
7898779389
pToplevel->isMultiWrite |= setStatement;
7898879390
}
7898979391
7899079392
/*
7899179393
** Indicate that the statement currently under construction might write
@@ -79626,11 +80028,14 @@
7962680028
sqlite3DeleteTable(0, pTab);
7962780029
}
7962880030
sqlite3HashClear(&temp1);
7962980031
sqlite3HashClear(&pSchema->fkeyHash);
7963080032
pSchema->pSeqTab = 0;
79631
- pSchema->flags &= ~DB_SchemaLoaded;
80033
+ if( pSchema->flags & DB_SchemaLoaded ){
80034
+ pSchema->iGeneration++;
80035
+ pSchema->flags &= ~DB_SchemaLoaded;
80036
+ }
7963280037
}
7963380038
7963480039
/*
7963580040
** Find and return the schema associated with a BTree. Create
7963680041
** a new one if necessary.
@@ -84381,12 +84786,13 @@
8438184786
** index and making sure that duplicate entries do not already exist.
8438284787
** Add the new records to the indices as we go.
8438384788
*/
8438484789
for(iCur=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, iCur++){
8438584790
int regIdx;
84791
+#ifndef SQLITE_OMIT_UNIQUE_ENFORCEMENT
8438684792
int regR;
84387
-
84793
+#endif
8438884794
if( aRegIdx[iCur]==0 ) continue; /* Skip unused indices */
8438984795
8439084796
/* Create a key for accessing the index entry */
8439184797
regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn+1);
8439284798
for(i=0; i<pIdx->nColumn; i++){
@@ -84399,10 +84805,15 @@
8439984805
}
8440084806
sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
8440184807
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]);
8440284808
sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);
8440384809
sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1);
84810
+
84811
+#ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT
84812
+ sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
84813
+ continue; /* Treat pIdx as if it is not a UNIQUE index */
84814
+#else
8440484815
8440584816
/* Find out what action to take in case there is an indexing conflict */
8440684817
onError = pIdx->onError;
8440784818
if( onError==OE_None ){
8440884819
sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
@@ -84473,10 +84884,11 @@
8447384884
break;
8447484885
}
8447584886
}
8447684887
sqlite3VdbeJumpHere(v, j3);
8447784888
sqlite3ReleaseTempReg(pParse, regR);
84889
+#endif
8447884890
}
8447984891
8448084892
if( pbMayReplace ){
8448184893
*pbMayReplace = seenReplace;
8448284894
}
@@ -86501,12 +86913,11 @@
8650186913
addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
8650286914
sqlite3VdbeChangeP1(v, addr, iDb);
8650386915
sqlite3VdbeChangeP1(v, addr+1, iDb);
8650486916
sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
8650586917
}else{
86506
- int size = sqlite3Atoi(zRight);
86507
- if( size<0 ) size = -size;
86918
+ int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
8650886919
sqlite3BeginWriteOperation(pParse, 0, iDb);
8650986920
sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
8651086921
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
8651186922
pDb->pSchema->cache_size = size;
8651286923
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
@@ -86811,12 +87222,11 @@
8681187222
if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
8681287223
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
8681387224
if( !zRight ){
8681487225
returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
8681587226
}else{
86816
- int size = sqlite3Atoi(zRight);
86817
- if( size<0 ) size = -size;
87227
+ int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
8681887228
pDb->pSchema->cache_size = size;
8681987229
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
8682087230
}
8682187231
}else
8682287232
@@ -87920,13 +88330,12 @@
8792088330
DbSetProperty(db, iDb, DB_Empty);
8792188331
}
8792288332
pDb->pSchema->enc = ENC(db);
8792388333
8792488334
if( pDb->pSchema->cache_size==0 ){
87925
- size = meta[BTREE_DEFAULT_CACHE_SIZE-1];
88335
+ size = sqlite3AbsInt32(meta[BTREE_DEFAULT_CACHE_SIZE-1]);
8792688336
if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
87927
- if( size<0 ) size = -size;
8792888337
pDb->pSchema->cache_size = size;
8792988338
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
8793088339
}
8793188340
8793288341
/*
@@ -93787,12 +94196,16 @@
9378794196
int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
9378894197
ExprList *pChanges, /* Columns that change in an UPDATE statement */
9378994198
int *pMask /* OUT: Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
9379094199
){
9379194200
int mask = 0;
93792
- Trigger *pList = sqlite3TriggerList(pParse, pTab);
94201
+ Trigger *pList = 0;
9379394202
Trigger *p;
94203
+
94204
+ if( (pParse->db->flags & SQLITE_EnableTrigger)!=0 ){
94205
+ pList = sqlite3TriggerList(pParse, pTab);
94206
+ }
9379494207
assert( pList==0 || IsVirtual(pTab)==0 );
9379594208
for(p=pList; p; p=p->pNext){
9379694209
if( p->op==op && checkColumnOverlap(p->pColumns, pChanges) ){
9379794210
mask |= p->tr_tm;
9379894211
}
@@ -95642,11 +96055,11 @@
9564296055
v = sqlite3GetVdbe(pParse);
9564396056
sqlite3ChangeCookie(pParse, iDb);
9564496057
9564596058
sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
9564696059
zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
95647
- sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 1, 0, zWhere, P4_DYNAMIC);
96060
+ sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
9564896061
sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0,
9564996062
pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
9565096063
}
9565196064
9565296065
/* If we are rereading the sqlite_master table create the in-memory
@@ -98732,11 +99145,12 @@
9873299145
/*
9873399146
** Estimate the number of rows that will be returned based on
9873499147
** an equality constraint x=VALUE and where that VALUE occurs in
9873599148
** the histogram data. This only works when x is the left-most
9873699149
** column of an index and sqlite_stat2 histogram data is available
98737
-** for that index.
99150
+** for that index. When pExpr==NULL that means the constraint is
99151
+** "x IS NULL" instead of "x=VALUE".
9873899152
**
9873999153
** Write the estimated row count into *pnRow and return SQLITE_OK.
9874099154
** If unable to make an estimate, leave *pnRow unchanged and return
9874199155
** non-zero.
9874299156
**
@@ -98757,12 +99171,16 @@
9875799171
int rc; /* Subfunction return code */
9875899172
double nRowEst; /* New estimate of the number of rows */
9875999173
9876099174
assert( p->aSample!=0 );
9876199175
aff = p->pTable->aCol[p->aiColumn[0]].affinity;
98762
- rc = valueFromExpr(pParse, pExpr, aff, &pRhs);
98763
- if( rc ) goto whereEqualScanEst_cancel;
99176
+ if( pExpr ){
99177
+ rc = valueFromExpr(pParse, pExpr, aff, &pRhs);
99178
+ if( rc ) goto whereEqualScanEst_cancel;
99179
+ }else{
99180
+ pRhs = sqlite3ValueNew(pParse->db);
99181
+ }
9876499182
if( pRhs==0 ) return SQLITE_NOTFOUND;
9876599183
rc = whereRangeRegion(pParse, p, pRhs, 0, &iLower);
9876699184
if( rc ) goto whereEqualScanEst_cancel;
9876799185
rc = whereRangeRegion(pParse, p, pRhs, 1, &iUpper);
9876899186
if( rc ) goto whereEqualScanEst_cancel;
@@ -99147,11 +99565,13 @@
9914799565
** data is available for column x, then it might be possible
9914899566
** to get a better estimate on the number of rows based on
9914999567
** VALUE and how common that value is according to the histogram.
9915099568
*/
9915199569
if( nRow>(double)1 && nEq==1 && pFirstTerm!=0 ){
99152
- if( pFirstTerm->eOperator==WO_EQ ){
99570
+ if( pFirstTerm->eOperator & (WO_EQ|WO_ISNULL) ){
99571
+ testcase( pFirstTerm->eOperator==WO_EQ );
99572
+ testcase( pFirstTerm->pOperator==WO_ISNULL );
9915399573
whereEqualScanEst(pParse, pProbe, pFirstTerm->pExpr->pRight, &nRow);
9915499574
}else if( pFirstTerm->eOperator==WO_IN && bInEst==0 ){
9915599575
whereInScanEst(pParse, pProbe, pFirstTerm->pExpr->x.pList, &nRow);
9915699576
}
9915799577
}
@@ -100213,11 +100633,17 @@
100213100633
}
100214100634
100215100635
/* Record the instruction used to terminate the loop. Disable
100216100636
** WHERE clause terms made redundant by the index range scan.
100217100637
*/
100218
- pLevel->op = bRev ? OP_Prev : OP_Next;
100638
+ if( pLevel->plan.wsFlags & WHERE_UNIQUE ){
100639
+ pLevel->op = OP_Noop;
100640
+ }else if( bRev ){
100641
+ pLevel->op = OP_Prev;
100642
+ }else{
100643
+ pLevel->op = OP_Next;
100644
+ }
100219100645
pLevel->p1 = iIdxCur;
100220100646
}else
100221100647
100222100648
#ifndef SQLITE_OMIT_OR_OPTIMIZATION
100223100649
if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
@@ -106160,10 +106586,17 @@
106160106586
case SQLITE_CONFIG_HEAP: {
106161106587
/* Designate a buffer for heap memory space */
106162106588
sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
106163106589
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
106164106590
sqlite3GlobalConfig.mnReq = va_arg(ap, int);
106591
+
106592
+ if( sqlite3GlobalConfig.mnReq<1 ){
106593
+ sqlite3GlobalConfig.mnReq = 1;
106594
+ }else if( sqlite3GlobalConfig.mnReq>(1<<12) ){
106595
+ /* cap min request size at 2^12 */
106596
+ sqlite3GlobalConfig.mnReq = (1<<12);
106597
+ }
106165106598
106166106599
if( sqlite3GlobalConfig.pHeap==0 ){
106167106600
/* If the heap pointer is NULL, then restore the malloc implementation
106168106601
** back to NULL pointers too. This will cause the malloc to go
106169106602
** back to its default implementation when sqlite3_initialize() is
@@ -106301,11 +106734,39 @@
106301106734
int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
106302106735
rc = setupLookaside(db, pBuf, sz, cnt);
106303106736
break;
106304106737
}
106305106738
default: {
106739
+ static const struct {
106740
+ int op; /* The opcode */
106741
+ u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
106742
+ } aFlagOp[] = {
106743
+ { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
106744
+ { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
106745
+ };
106746
+ unsigned int i;
106306106747
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
106748
+ for(i=0; i<ArraySize(aFlagOp); i++){
106749
+ if( aFlagOp[i].op==op ){
106750
+ int onoff = va_arg(ap, int);
106751
+ int *pRes = va_arg(ap, int*);
106752
+ int oldFlags = db->flags;
106753
+ if( onoff>0 ){
106754
+ db->flags |= aFlagOp[i].mask;
106755
+ }else if( onoff==0 ){
106756
+ db->flags &= ~aFlagOp[i].mask;
106757
+ }
106758
+ if( oldFlags!=db->flags ){
106759
+ sqlite3ExpirePreparedStatements(db);
106760
+ }
106761
+ if( pRes ){
106762
+ *pRes = (db->flags & aFlagOp[i].mask)!=0;
106763
+ }
106764
+ rc = SQLITE_OK;
106765
+ break;
106766
+ }
106767
+ }
106307106768
break;
106308106769
}
106309106770
}
106310106771
va_end(ap);
106311106772
return rc;
@@ -107474,12 +107935,12 @@
107474107935
# error SQLITE_MAX_VDBE_OP must be at least 40
107475107936
#endif
107476107937
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
107477107938
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
107478107939
#endif
107479
-#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>30
107480
-# error SQLITE_MAX_ATTACHED must be between 0 and 30
107940
+#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>62
107941
+# error SQLITE_MAX_ATTACHED must be between 0 and 62
107481107942
#endif
107482107943
#if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
107483107944
# error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
107484107945
#endif
107485107946
#if SQLITE_MAX_COLUMN>32767
@@ -107634,11 +108095,11 @@
107634108095
assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
107635108096
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
107636108097
db->autoCommit = 1;
107637108098
db->nextAutovac = -1;
107638108099
db->nextPagesize = 0;
107639
- db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex
108100
+ db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger
107640108101
#if SQLITE_DEFAULT_FILE_FORMAT<4
107641108102
| SQLITE_LegacyFileFmt
107642108103
#endif
107643108104
#ifdef SQLITE_ENABLE_LOAD_EXTENSION
107644108105
| SQLITE_LoadExtension
@@ -119847,17 +120308,17 @@
119847120308
Fts3Expr *pExpr, /* Phrase expression node */
119848120309
int iPhrase, /* Phrase number */
119849120310
void *pCtx /* Pointer to MatchInfo structure */
119850120311
){
119851120312
MatchInfo *p = (MatchInfo *)pCtx;
120313
+ int iStart = iPhrase * p->nCol * 3;
120314
+ int i;
120315
+
120316
+ for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0;
119852120317
119853120318
if( pExpr->aDoclist ){
119854120319
char *pCsr;
119855
- int iStart = iPhrase * p->nCol * 3;
119856
- int i;
119857
-
119858
- for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0;
119859120320
119860120321
pCsr = sqlite3Fts3FindPositions(pExpr, p->pCursor->iPrevId, -1);
119861120322
if( pCsr ){
119862120323
fts3LoadColumnlistCounts(&pCsr, &p->aMatchinfo[iStart], 0);
119863120324
}
@@ -121944,19 +122405,19 @@
121944122405
** to which the constraint applies. The leftmost coordinate column
121945122406
** is 'a', the second from the left 'b' etc.
121946122407
*/
121947122408
static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
121948122409
int rc = SQLITE_OK;
121949
- int ii, cCol;
122410
+ int ii;
121950122411
121951122412
int iIdx = 0;
121952122413
char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
121953122414
memset(zIdxStr, 0, sizeof(zIdxStr));
121954122415
UNUSED_PARAMETER(tab);
121955122416
121956122417
assert( pIdxInfo->idxStr==0 );
121957
- for(ii=0; ii<pIdxInfo->nConstraint; ii++){
122418
+ for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(sizeof(zIdxStr)-1); ii++){
121958122419
struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
121959122420
121960122421
if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
121961122422
/* We have an equality constraint on the rowid. Use strategy 1. */
121962122423
int jj;
@@ -121976,13 +122437,11 @@
121976122437
pIdxInfo->estimatedCost = 10.0;
121977122438
return SQLITE_OK;
121978122439
}
121979122440
121980122441
if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
121981
- int j, opmsk;
121982
- static const unsigned char compatible[] = { 0, 0, 1, 1, 2, 2 };
121983
- u8 op = 0;
122442
+ u8 op;
121984122443
switch( p->op ){
121985122444
case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
121986122445
case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
121987122446
case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
121988122447
case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
@@ -121990,41 +122449,14 @@
121990122449
default:
121991122450
assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH );
121992122451
op = RTREE_MATCH;
121993122452
break;
121994122453
}
121995
- assert( op!=0 );
121996
-
121997
- /* Make sure this particular constraint has not been used before.
121998
- ** If it has been used before, ignore it.
121999
- **
122000
- ** A <= or < can be used if there is a prior >= or >.
122001
- ** A >= or > can be used if there is a prior < or <=.
122002
- ** A <= or < is disqualified if there is a prior <=, <, or ==.
122003
- ** A >= or > is disqualified if there is a prior >=, >, or ==.
122004
- ** A == is disqualifed if there is any prior constraint.
122005
- */
122006
- assert( compatible[RTREE_EQ & 7]==0 );
122007
- assert( compatible[RTREE_LT & 7]==1 );
122008
- assert( compatible[RTREE_LE & 7]==1 );
122009
- assert( compatible[RTREE_GT & 7]==2 );
122010
- assert( compatible[RTREE_GE & 7]==2 );
122011
- cCol = p->iColumn - 1 + 'a';
122012
- opmsk = compatible[op & 7];
122013
- for(j=0; j<iIdx; j+=2){
122014
- if( zIdxStr[j+1]==cCol && (compatible[zIdxStr[j] & 7] & opmsk)!=0 ){
122015
- op = 0;
122016
- break;
122017
- }
122018
- }
122019
- if( op ){
122020
- assert( iIdx<sizeof(zIdxStr)-1 );
122021
- zIdxStr[iIdx++] = op;
122022
- zIdxStr[iIdx++] = cCol;
122023
- pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
122024
- pIdxInfo->aConstraintUsage[ii].omit = 1;
122025
- }
122454
+ zIdxStr[iIdx++] = op;
122455
+ zIdxStr[iIdx++] = p->iColumn - 1 + 'a';
122456
+ pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
122457
+ pIdxInfo->aConstraintUsage[ii].omit = 1;
122026122458
}
122027122459
}
122028122460
122029122461
pIdxInfo->idxNum = 2;
122030122462
pIdxInfo->needToFreeIdxStr = 1;
122031122463
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.6"
654 #define SQLITE_VERSION_NUMBER 3007006
655 #define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1439,14 +1439,27 @@
1439 ** a 24-hour day).
1440 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
1441 ** date and time if that method is available (if iVersion is 2 or
1442 ** greater and the function pointer is not NULL) and will fall back
1443 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
 
 
 
 
 
 
 
 
 
 
 
 
1444 */
1445 typedef struct sqlite3_vfs sqlite3_vfs;
 
1446 struct sqlite3_vfs {
1447 int iVersion; /* Structure version number (currently 2) */
1448 int szOsFile; /* Size of subclassed sqlite3_file */
1449 int mxPathname; /* Maximum file pathname length */
1450 sqlite3_vfs *pNext; /* Next registered VFS */
1451 const char *zName; /* Name of this virtual file system */
1452 void *pAppData; /* Pointer to application-specific data */
@@ -1468,10 +1481,17 @@
1468 ** definition. Those that follow are added in version 2 or later
1469 */
1470 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1471 /*
1472 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
 
 
 
 
 
 
 
1473 ** New fields may be appended in figure versions. The iVersion
1474 ** value will increment whenever this happens.
1475 */
1476 };
1477
@@ -1652,21 +1672,16 @@
1652 ** CAPI3REF: Configure database connections
1653 **
1654 ** The sqlite3_db_config() interface is used to make configuration
1655 ** changes to a [database connection]. The interface is similar to
1656 ** [sqlite3_config()] except that the changes apply to a single
1657 ** [database connection] (specified in the first argument). The
1658 ** sqlite3_db_config() interface should only be used immediately after
1659 ** the database connection is created using [sqlite3_open()],
1660 ** [sqlite3_open16()], or [sqlite3_open_v2()].
1661 **
1662 ** The second argument to sqlite3_db_config(D,V,...) is the
1663 ** configuration verb - an integer code that indicates what
1664 ** aspect of the [database connection] is being configured.
1665 ** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
1666 ** New verbs are likely to be added in future releases of SQLite.
1667 ** Additional arguments depend on the verb.
1668 **
1669 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1670 ** the call is considered successful.
1671 */
1672 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
@@ -1887,11 +1902,13 @@
1887 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1888 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1889 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1890 ** allocator is engaged to handle all of SQLites memory allocation needs.
1891 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1892 ** boundary or subsequent behavior of SQLite will be undefined.</dd>
 
 
1893 **
1894 ** <dt>SQLITE_CONFIG_MUTEX</dt>
1895 ** <dd> ^(This option takes a single argument which is a pointer to an
1896 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1897 ** alternative low-level mutex routines to be used in place
@@ -2008,13 +2025,35 @@
2008 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2009 ** Any attempt to change the lookaside memory configuration when lookaside
2010 ** memory is in use leaves the configuration unchanged and returns
2011 ** [SQLITE_BUSY].)^</dd>
2012 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2013 ** </dl>
2014 */
2015 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
 
 
2016
2017
2018 /*
2019 ** CAPI3REF: Enable Or Disable Extended Result Codes
2020 **
@@ -8974,10 +9013,11 @@
8974 /*
8975 ** An instance of the following structure stores a database schema.
8976 */
8977 struct Schema {
8978 int schema_cookie; /* Database schema version number for this file */
 
8979 Hash tblHash; /* All tables indexed by name */
8980 Hash idxHash; /* All (named) indices indexed by name */
8981 Hash trigHash; /* All triggers indexed by name */
8982 Hash fkeyHash; /* All foreign keys by referenced table name */
8983 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
@@ -9227,10 +9267,11 @@
9227 #define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
9228 #define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
9229 #define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
9230 #define SQLITE_PreferBuiltin 0x10000000 /* Preference to built-in funcs */
9231 #define SQLITE_LoadExtension 0x20000000 /* Enable load_extension */
 
9232
9233 /*
9234 ** Bits of the sqlite3.flags field that are used by the
9235 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
9236 ** These must be the low-order bits of the flags field.
@@ -9926,11 +9967,11 @@
9926 u8 op; /* Operation performed by this node */
9927 char affinity; /* The affinity of the column or 0 if not a column */
9928 u16 flags; /* Various flags. EP_* See below */
9929 union {
9930 char *zToken; /* Token value. Zero terminated and dequoted */
9931 int iValue; /* Integer value if EP_IntValue */
9932 } u;
9933
9934 /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no
9935 ** space is allocated for the fields below this point. An attempt to
9936 ** access them will result in a segfault or malfunction.
@@ -10426,10 +10467,17 @@
10426 SubProgram *pProgram; /* Program implementing pTrigger/orconf */
10427 u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */
10428 TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */
10429 };
10430
 
 
 
 
 
 
 
10431 /*
10432 ** An SQL parser context. A copy of this structure is passed through
10433 ** the parser and down into all the parser action routine in order to
10434 ** carry around information that is global to the entire parse.
10435 **
@@ -10474,12 +10522,12 @@
10474 u8 tempReg; /* iReg is a temp register that needs to be freed */
10475 int iLevel; /* Nesting level */
10476 int iReg; /* Reg with value of this column. 0 means none. */
10477 int lru; /* Least recently used entry has the smallest value */
10478 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
10479 u32 writeMask; /* Start a write transaction on these databases */
10480 u32 cookieMask; /* Bitmask of schema verified databases */
10481 u8 isMultiWrite; /* True if statement may affect/insert multiple rows */
10482 u8 mayAbort; /* True if statement may throw an ABORT exception */
10483 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
10484 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
10485 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -11209,10 +11257,11 @@
11209 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
11210 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
11211 SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64);
11212 SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64);
11213 SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64);
 
11214
11215 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
11216 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
11217 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
11218 void(*)(void*));
@@ -12023,10 +12072,13 @@
12023 "OMIT_TRIGGER",
12024 #endif
12025 #ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
12026 "OMIT_TRUNCATE_OPTIMIZATION",
12027 #endif
 
 
 
12028 #ifdef SQLITE_OMIT_UTF16
12029 "OMIT_UTF16",
12030 #endif
12031 #ifdef SQLITE_OMIT_VACUUM
12032 "OMIT_VACUUM",
@@ -12436,11 +12488,11 @@
12436 u8 inVtabMethod; /* See comments above */
12437 u8 usesStmtJournal; /* True if uses a statement journal */
12438 u8 readOnly; /* True for read-only statements */
12439 u8 isPrepareV2; /* True if prepared with prepare_v2() */
12440 int nChange; /* Number of db changes made since last reset */
12441 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
12442 int iStatement; /* Statement number (or 0 if has not opened stmt) */
12443 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
12444 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
12445 #ifndef SQLITE_OMIT_TRACE
12446 i64 startTime; /* Time when query started - used for profiling */
@@ -16155,11 +16207,11 @@
16155 ** memsys5Log(8) -> 3
16156 ** memsys5Log(9) -> 4
16157 */
16158 static int memsys5Log(int iValue){
16159 int iLog;
16160 for(iLog=0; (1<<iLog)<iValue; iLog++);
16161 return iLog;
16162 }
16163
16164 /*
16165 ** Initialize the memory allocator.
@@ -16186,10 +16238,11 @@
16186
16187 nByte = sqlite3GlobalConfig.nHeap;
16188 zByte = (u8*)sqlite3GlobalConfig.pHeap;
16189 assert( zByte!=0 ); /* sqlite3_config() does not allow otherwise */
16190
 
16191 nMinLog = memsys5Log(sqlite3GlobalConfig.mnReq);
16192 mem5.szAtom = (1<<nMinLog);
16193 while( (int)sizeof(Mem5Link)>mem5.szAtom ){
16194 mem5.szAtom = mem5.szAtom << 1;
16195 }
@@ -16689,15 +16742,20 @@
16689 ** Each recursive mutex is an instance of the following structure.
16690 */
16691 struct sqlite3_mutex {
16692 HMTX mutex; /* Mutex controlling the lock */
16693 int id; /* Mutex type */
16694 int nRef; /* Number of references */
16695 TID owner; /* Thread holding this mutex */
 
16696 };
16697
16698 #define OS2_MUTEX_INITIALIZER 0,0,0,0
 
 
 
 
16699
16700 /*
16701 ** Initialize and deinitialize the mutex subsystem.
16702 */
16703 static int os2MutexInit(void){ return SQLITE_OK; }
@@ -16709,15 +16767,18 @@
16709 ** that means that a mutex could not be allocated.
16710 ** SQLite will unwind its stack and return an error. The argument
16711 ** to sqlite3_mutex_alloc() is one of these integer constants:
16712 **
16713 ** <ul>
16714 ** <li> SQLITE_MUTEX_FAST 0
16715 ** <li> SQLITE_MUTEX_RECURSIVE 1
16716 ** <li> SQLITE_MUTEX_STATIC_MASTER 2
16717 ** <li> SQLITE_MUTEX_STATIC_MEM 3
16718 ** <li> SQLITE_MUTEX_STATIC_PRNG 4
 
 
 
16719 ** </ul>
16720 **
16721 ** The first two constants cause sqlite3_mutex_alloc() to create
16722 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
16723 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -16727,11 +16788,11 @@
16727 ** cases where it really needs one. If a faster non-recursive mutex
16728 ** implementation is available on the host platform, the mutex subsystem
16729 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
16730 **
16731 ** The other allowed parameters to sqlite3_mutex_alloc() each return
16732 ** a pointer to a static preexisting mutex. Three static mutexes are
16733 ** used by the current version of SQLite. Future versions of SQLite
16734 ** may add additional static mutexes. Static mutexes are for internal
16735 ** use by SQLite only. Applications that use SQLite mutexes should
16736 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
16737 ** SQLITE_MUTEX_RECURSIVE.
@@ -16757,17 +16818,17 @@
16757 }
16758 break;
16759 }
16760 default: {
16761 static volatile int isInit = 0;
16762 static sqlite3_mutex staticMutexes[] = {
16763 { OS2_MUTEX_INITIALIZER, },
16764 { OS2_MUTEX_INITIALIZER, },
16765 { OS2_MUTEX_INITIALIZER, },
16766 { OS2_MUTEX_INITIALIZER, },
16767 { OS2_MUTEX_INITIALIZER, },
16768 { OS2_MUTEX_INITIALIZER, },
16769 };
16770 if ( !isInit ){
16771 APIRET rc;
16772 PTIB ptib;
16773 PPIB ppib;
@@ -16809,13 +16870,18 @@
16809 /*
16810 ** This routine deallocates a previously allocated mutex.
16811 ** SQLite is careful to deallocate every mutex that it allocates.
16812 */
16813 static void os2MutexFree(sqlite3_mutex *p){
16814 if( p==0 ) return;
16815 assert( p->nRef==0 );
 
 
 
 
16816 assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
 
16817 DosCloseMutexSem( p->mutex );
16818 sqlite3_free( p );
16819 }
16820
16821 #ifdef SQLITE_DEBUG
@@ -16826,30 +16892,33 @@
16826 static int os2MutexHeld(sqlite3_mutex *p){
16827 TID tid;
16828 PID pid;
16829 ULONG ulCount;
16830 PTIB ptib;
16831 if( p!=0 ) {
16832 DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16833 } else {
16834 DosGetInfoBlocks(&ptib, NULL);
16835 tid = ptib->tib_ptib2->tib2_ultid;
16836 }
16837 return p==0 || (p->nRef!=0 && p->owner==tid);
16838 }
16839 static int os2MutexNotheld(sqlite3_mutex *p){
16840 TID tid;
16841 PID pid;
16842 ULONG ulCount;
16843 PTIB ptib;
16844 if( p!= 0 ) {
16845 DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16846 } else {
16847 DosGetInfoBlocks(&ptib, NULL);
16848 tid = ptib->tib_ptib2->tib2_ultid;
16849 }
16850 return p==0 || p->nRef==0 || p->owner!=tid;
 
 
 
 
 
16851 }
16852 #endif
16853
16854 /*
16855 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
@@ -16861,36 +16930,25 @@
16861 ** mutex must be exited an equal number of times before another thread
16862 ** can enter. If the same thread tries to enter any other kind of mutex
16863 ** more than once, the behavior is undefined.
16864 */
16865 static void os2MutexEnter(sqlite3_mutex *p){
16866 TID tid;
16867 PID holder1;
16868 ULONG holder2;
16869 if( p==0 ) return;
16870 assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) );
16871 DosRequestMutexSem(p->mutex, SEM_INDEFINITE_WAIT);
16872 DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2);
16873 p->owner = tid;
16874 p->nRef++;
16875 }
16876 static int os2MutexTry(sqlite3_mutex *p){
16877 int rc;
16878 TID tid;
16879 PID holder1;
16880 ULONG holder2;
16881 if( p==0 ) return SQLITE_OK;
16882 assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) );
16883 if( DosRequestMutexSem(p->mutex, SEM_IMMEDIATE_RETURN) == NO_ERROR) {
16884 DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2);
16885 p->owner = tid;
16886 p->nRef++;
16887 rc = SQLITE_OK;
16888 } else {
16889 rc = SQLITE_BUSY;
 
16890 }
16891
16892 return rc;
16893 }
16894
16895 /*
16896 ** The sqlite3_mutex_leave() routine exits a mutex that was
@@ -16897,23 +16955,18 @@
16897 ** previously entered by the same thread. The behavior
16898 ** is undefined if the mutex is not currently entered or
16899 ** is not currently allocated. SQLite will never do either.
16900 */
16901 static void os2MutexLeave(sqlite3_mutex *p){
16902 TID tid;
16903 PID holder1;
16904 ULONG holder2;
16905 if( p==0 ) return;
16906 assert( p->nRef>0 );
16907 DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2);
16908 assert( p->owner==tid );
16909 p->nRef--;
16910 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
16911 DosReleaseMutexSem(p->mutex);
 
 
 
16912 }
16913
16914 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
16915 static const sqlite3_mutex_methods sMutex = {
16916 os2MutexInit,
16917 os2MutexEnd,
16918 os2MutexAlloc,
16919 os2MutexFree,
@@ -16921,10 +16974,13 @@
16921 os2MutexTry,
16922 os2MutexLeave,
16923 #ifdef SQLITE_DEBUG
16924 os2MutexHeld,
16925 os2MutexNotheld
 
 
 
16926 #endif
16927 };
16928
16929 return &sMutex;
16930 }
@@ -17564,11 +17620,11 @@
17564 #else
17565 UNUSED_PARAMETER(p);
17566 #endif
17567 #ifdef SQLITE_DEBUG
17568 if( rc==SQLITE_OK && p->trace ){
17569 printf("enter mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
17570 }
17571 #endif
17572 return rc;
17573 }
17574
@@ -21270,10 +21326,20 @@
21270 r *= TWOPOWER32;
21271 if( sqlite3AddInt64(&r, iA0*iB0) ) return 1;
21272 *pA = r;
21273 return 0;
21274 }
 
 
 
 
 
 
 
 
 
 
21275
21276 /************** End of util.c ************************************************/
21277 /************** Begin file hash.c ********************************************/
21278 /*
21279 ** 2001 September 22
@@ -22560,23 +22626,27 @@
22560 /*
22561 ** This vector defines all the methods that can operate on an
22562 ** sqlite3_file for os2.
22563 */
22564 static const sqlite3_io_methods os2IoMethod = {
22565 1, /* iVersion */
22566 os2Close,
22567 os2Read,
22568 os2Write,
22569 os2Truncate,
22570 os2Sync,
22571 os2FileSize,
22572 os2Lock,
22573 os2Unlock,
22574 os2CheckReservedLock,
22575 os2FileControl,
22576 os2SectorSize,
22577 os2DeviceCharacteristics
 
 
 
 
22578 };
22579
22580 /***************************************************************************
22581 ** Here ends the I/O methods that form the sqlite3_io_methods object.
22582 **
@@ -22664,115 +22734,151 @@
22664 /*
22665 ** Open a file.
22666 */
22667 static int os2Open(
22668 sqlite3_vfs *pVfs, /* Not used */
22669 const char *zName, /* Name of the file */
22670 sqlite3_file *id, /* Write the SQLite file handle here */
22671 int flags, /* Open mode flags */
22672 int *pOutFlags /* Status return flags */
22673 ){
22674 HFILE h;
22675 ULONG ulFileAttribute = FILE_NORMAL;
22676 ULONG ulOpenFlags = 0;
22677 ULONG ulOpenMode = 0;
 
 
22678 os2File *pFile = (os2File*)id;
22679 APIRET rc = NO_ERROR;
22680 ULONG ulAction;
22681 char *zNameCp;
22682 char zTmpname[CCHMAXPATH+1]; /* Buffer to hold name of temp file */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22683
22684 /* If the second argument to this function is NULL, generate a
22685 ** temporary file name to use
22686 */
22687 if( !zName ){
22688 int rc = getTempname(CCHMAXPATH+1, zTmpname);
 
22689 if( rc!=SQLITE_OK ){
22690 return rc;
22691 }
22692 zName = zTmpname;
22693 }
22694
22695
22696 memset( pFile, 0, sizeof(*pFile) );
22697
22698 OSTRACE(( "OPEN want %d\n", flags ));
22699
22700 if( flags & SQLITE_OPEN_READWRITE ){
22701 ulOpenMode |= OPEN_ACCESS_READWRITE;
22702 OSTRACE(( "OPEN read/write\n" ));
22703 }else{
22704 ulOpenMode |= OPEN_ACCESS_READONLY;
22705 OSTRACE(( "OPEN read only\n" ));
22706 }
22707
22708 if( flags & SQLITE_OPEN_CREATE ){
22709 ulOpenFlags |= OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
22710 OSTRACE(( "OPEN open new/create\n" ));
22711 }else{
22712 ulOpenFlags |= OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
22713 OSTRACE(( "OPEN open existing\n" ));
22714 }
22715
22716 if( flags & SQLITE_OPEN_MAIN_DB ){
22717 ulOpenMode |= OPEN_SHARE_DENYNONE;
22718 OSTRACE(( "OPEN share read/write\n" ));
22719 }else{
22720 ulOpenMode |= OPEN_SHARE_DENYWRITE;
22721 OSTRACE(( "OPEN share read only\n" ));
22722 }
22723
22724 if( flags & SQLITE_OPEN_DELETEONCLOSE ){
22725 char pathUtf8[CCHMAXPATH];
22726 #ifdef NDEBUG /* when debugging we want to make sure it is deleted */
22727 ulFileAttribute = FILE_HIDDEN;
22728 #endif
22729 os2FullPathname( pVfs, zName, CCHMAXPATH, pathUtf8 );
22730 pFile->pathToDel = convertUtf8PathToCp( pathUtf8 );
22731 OSTRACE(( "OPEN hidden/delete on close file attributes\n" ));
22732 }else{
22733 pFile->pathToDel = NULL;
22734 OSTRACE(( "OPEN normal file attribute\n" ));
22735 }
22736
22737 /* always open in random access mode for possibly better speed */
22738 ulOpenMode |= OPEN_FLAGS_RANDOM;
22739 ulOpenMode |= OPEN_FLAGS_FAIL_ON_ERROR;
22740 ulOpenMode |= OPEN_FLAGS_NOINHERIT;
 
22741
22742 zNameCp = convertUtf8PathToCp( zName );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22743 rc = DosOpen( (PSZ)zNameCp,
22744 &h,
22745 &ulAction,
22746 0L,
22747 ulFileAttribute,
22748 ulOpenFlags,
22749 ulOpenMode,
22750 (PEAOP2)NULL );
22751 free( zNameCp );
 
22752 if( rc != NO_ERROR ){
22753 OSTRACE(( "OPEN Invalid handle rc=%d: zName=%s, ulAction=%#lx, ulAttr=%#lx, ulFlags=%#lx, ulMode=%#lx\n",
22754 rc, zName, ulAction, ulFileAttribute, ulOpenFlags, ulOpenMode ));
22755 if( pFile->pathToDel )
22756 free( pFile->pathToDel );
22757 pFile->pathToDel = NULL;
22758 if( flags & SQLITE_OPEN_READWRITE ){
22759 OSTRACE(( "OPEN %d Invalid handle\n",
22760 ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE) ));
22761 return os2Open( pVfs, zName, id,
22762 ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE),
22763 pOutFlags );
22764 }else{
22765 return SQLITE_CANTOPEN;
22766 }
22767 }
22768
22769 if( pOutFlags ){
22770 *pOutFlags = flags & SQLITE_OPEN_READWRITE ? SQLITE_OPEN_READWRITE : SQLITE_OPEN_READONLY;
22771 }
22772
22773 pFile->pMethod = &os2IoMethod;
22774 pFile->h = h;
22775 OpenCounter(+1);
22776 OSTRACE(( "OPEN %d pOutFlags=%d\n", pFile->h, pOutFlags ));
22777 return SQLITE_OK;
22778 }
@@ -22783,17 +22889,20 @@
22783 static int os2Delete(
22784 sqlite3_vfs *pVfs, /* Not used on os2 */
22785 const char *zFilename, /* Name of file to delete */
22786 int syncDir /* Not used on os2 */
22787 ){
22788 APIRET rc = NO_ERROR;
22789 char *zFilenameCp = convertUtf8PathToCp( zFilename );
22790 SimulateIOError( return SQLITE_IOERR_DELETE );
 
22791 rc = DosDelete( (PSZ)zFilenameCp );
22792 free( zFilenameCp );
22793 OSTRACE(( "DELETE \"%s\"\n", zFilename ));
22794 return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR_DELETE;
 
 
22795 }
22796
22797 /*
22798 ** Check the existance and status of a file.
22799 */
@@ -22854,11 +22963,11 @@
22854 ** os2Dlopen returns zero if DosLoadModule is not successful.
22855 */
22856 static void os2DlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
22857 /* no-op */
22858 }
22859 static void *os2DlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol){
22860 PFN pfn;
22861 APIRET rc;
22862 rc = DosQueryProcAddr((HMODULE)pHandle, 0L, zSymbol, &pfn);
22863 if( rc != NO_ERROR ){
22864 /* if the symbol itself was not found, search again for the same
@@ -22866,11 +22975,11 @@
22866 * on the calling convention */
22867 char _zSymbol[256] = "_";
22868 strncat(_zSymbol, zSymbol, 255);
22869 rc = DosQueryProcAddr((HMODULE)pHandle, 0L, _zSymbol, &pfn);
22870 }
22871 return rc != NO_ERROR ? 0 : (void*)pfn;
22872 }
22873 static void os2DlClose(sqlite3_vfs *pVfs, void *pHandle){
22874 DosFreeModule((HMODULE)pHandle);
22875 }
22876 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
@@ -22970,14 +23079,15 @@
22970 ** return 0. Return 1 if the time and date cannot be found.
22971 */
22972 int os2CurrentTime( sqlite3_vfs *pVfs, double *prNow ){
22973 double now;
22974 SHORT minute; /* needs to be able to cope with negative timezone offset */
22975 USHORT second, hour,
22976 day, month, year;
22977 DATETIME dt;
22978 DosGetDateTime( &dt );
 
22979 second = (USHORT)dt.seconds;
22980 minute = (SHORT)dt.minutes + dt.timezone;
22981 hour = (USHORT)dt.hours;
22982 day = (USHORT)dt.day;
22983 month = (USHORT)dt.month;
@@ -22993,18 +23103,35 @@
22993
22994 /* Add the fractional hours, mins and seconds */
22995 now += (hour + 12.0)/24.0;
22996 now += minute/1440.0;
22997 now += second/86400.0;
 
22998 *prNow = now;
22999 #ifdef SQLITE_TEST
23000 if( sqlite3_current_time ){
23001 *prNow = sqlite3_current_time/86400.0 + 2440587.5;
23002 }
23003 #endif
23004 return 0;
23005 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23006
23007 static int os2GetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
23008 return 0;
23009 }
23010
@@ -23011,11 +23138,11 @@
23011 /*
23012 ** Initialize and deinitialize the operating system interface.
23013 */
23014 SQLITE_API int sqlite3_os_init(void){
23015 static sqlite3_vfs os2Vfs = {
23016 1, /* iVersion */
23017 sizeof(os2File), /* szOsFile */
23018 CCHMAXPATH, /* mxPathname */
23019 0, /* pNext */
23020 "os2", /* zName */
23021 0, /* pAppData */
@@ -23030,10 +23157,14 @@
23030 os2DlClose, /* xDlClose */
23031 os2Randomness, /* xRandomness */
23032 os2Sleep, /* xSleep */
23033 os2CurrentTime, /* xCurrentTime */
23034 os2GetLastError, /* xGetLastError */
 
 
 
 
23035 };
23036 sqlite3_vfs_register(&os2Vfs, 1);
23037 initUconvObjects();
23038 return SQLITE_OK;
23039 }
@@ -23249,14 +23380,14 @@
23249 sqlite3_io_methods const *pMethod; /* Always the first entry */
23250 unixInodeInfo *pInode; /* Info about locks on this inode */
23251 int h; /* The file descriptor */
23252 int dirfd; /* File descriptor for the directory */
23253 unsigned char eFileLock; /* The type of lock held on this fd */
 
23254 int lastErrno; /* The unix errno from last I/O error */
23255 void *lockingContext; /* Locking style specific state */
23256 UnixUnusedFd *pUnused; /* Pre-allocated UnixUnusedFd */
23257 int fileFlags; /* Miscellanous flags */
23258 const char *zPath; /* Name of the file */
23259 unixShm *pShm; /* Shared memory segment information */
23260 int szChunk; /* Configured by FCNTL_CHUNK_SIZE */
23261 #if SQLITE_ENABLE_LOCKING_STYLE
23262 int openFlags; /* The flags specified at open() */
@@ -23287,13 +23418,14 @@
23287 char aPadding[32];
23288 #endif
23289 };
23290
23291 /*
23292 ** The following macros define bits in unixFile.fileFlags
23293 */
23294 #define SQLITE_WHOLE_FILE_LOCKING 0x0001 /* Use whole-file locking */
 
23295
23296 /*
23297 ** Include code that is common to all os_*.c files
23298 */
23299 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -23518,20 +23650,10 @@
23518 #endif
23519 #ifndef O_BINARY
23520 # define O_BINARY 0
23521 #endif
23522
23523 /*
23524 ** The DJGPP compiler environment looks mostly like Unix, but it
23525 ** lacks the fcntl() system call. So redefine fcntl() to be something
23526 ** that always succeeds. This means that locking does not occur under
23527 ** DJGPP. But it is DOS - what did you expect?
23528 */
23529 #ifdef __DJGPP__
23530 # define fcntl(A,B,C) 0
23531 #endif
23532
23533 /*
23534 ** The threadid macro resolves to the thread-id or to 0. Used for
23535 ** testing and debugging only.
23536 */
23537 #if SQLITE_THREADSAFE
@@ -23538,10 +23660,197 @@
23538 #define threadid pthread_self()
23539 #else
23540 #define threadid 0
23541 #endif
23542
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23543
23544 /*
23545 ** Helper functions to obtain and relinquish the global mutex. The
23546 ** global mutex is used to protect the unixInodeInfo and
23547 ** vxworksFileId objects used by this file, all of which may be
@@ -23602,11 +23911,11 @@
23602 if( op==F_GETLK ){
23603 zOpName = "GETLK";
23604 }else if( op==F_SETLK ){
23605 zOpName = "SETLK";
23606 }else{
23607 s = fcntl(fd, op, p);
23608 sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s);
23609 return s;
23610 }
23611 if( p->l_type==F_RDLCK ){
23612 zType = "RDLCK";
@@ -23616,19 +23925,19 @@
23616 zType = "UNLCK";
23617 }else{
23618 assert( 0 );
23619 }
23620 assert( p->l_whence==SEEK_SET );
23621 s = fcntl(fd, op, p);
23622 savedErrno = errno;
23623 sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n",
23624 threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len,
23625 (int)p->l_pid, s);
23626 if( s==(-1) && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){
23627 struct flock l2;
23628 l2 = *p;
23629 fcntl(fd, F_GETLK, &l2);
23630 if( l2.l_type==F_RDLCK ){
23631 zType = "RDLCK";
23632 }else if( l2.l_type==F_WRLCK ){
23633 zType = "WRLCK";
23634 }else if( l2.l_type==F_UNLCK ){
@@ -23640,27 +23949,22 @@
23640 zType, (int)l2.l_start, (int)l2.l_len, (int)l2.l_pid);
23641 }
23642 errno = savedErrno;
23643 return s;
23644 }
23645 #define fcntl lockTrace
 
23646 #endif /* SQLITE_LOCK_TRACE */
23647
23648
23649 /*
23650 ** Retry ftruncate() calls that fail due to EINTR
23651 */
23652 #ifdef EINTR
23653 static int robust_ftruncate(int h, sqlite3_int64 sz){
23654 int rc;
23655 do{ rc = ftruncate(h,sz); }while( rc<0 && errno==EINTR );
23656 return rc;
23657 }
23658 #else
23659 # define robust_ftruncate(a,b) ftruncate(a,b)
23660 #endif
23661
23662
23663 /*
23664 ** This routine translates a standard POSIX errno code into something
23665 ** useful to the clients of the sqlite3 functions. Specifically, it is
23666 ** intended to translate a variety of "try again" errors into SQLITE_BUSY
@@ -23978,11 +24282,12 @@
23978 ** object keeps a count of the number of unixFile pointing to it.
23979 */
23980 struct unixInodeInfo {
23981 struct unixFileId fileId; /* The lookup key */
23982 int nShared; /* Number of SHARED locks held */
23983 int eFileLock; /* One of SHARED_LOCK, RESERVED_LOCK etc. */
 
23984 int nRef; /* Number of pointers to this structure */
23985 unixShmNode *pShmNode; /* Shared memory associated with this inode */
23986 int nLock; /* Number of outstanding file locks */
23987 UnixUnusedFd *pUnused; /* Unused file descriptors to close */
23988 unixInodeInfo *pNext; /* List of all unixInodeInfo objects */
@@ -24083,11 +24388,11 @@
24083 ** file descriptor might have already been reused by another thread.
24084 ** So we don't even try to recover from an EINTR. Just log the error
24085 ** and move on.
24086 */
24087 static void robust_close(unixFile *pFile, int h, int lineno){
24088 if( close(h) ){
24089 unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
24090 pFile ? pFile->zPath : 0, lineno);
24091 }
24092 }
24093
@@ -24160,11 +24465,11 @@
24160
24161 /* Get low-level information about the file that we can used to
24162 ** create a unique name for the file.
24163 */
24164 fd = pFile->h;
24165 rc = fstat(fd, &statbuf);
24166 if( rc!=0 ){
24167 pFile->lastErrno = errno;
24168 #ifdef EOVERFLOW
24169 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
24170 #endif
@@ -24181,16 +24486,16 @@
24181 ** in the header of every SQLite database. In this way, if there
24182 ** is a race condition such that another thread has already populated
24183 ** the first page of the database, no damage is done.
24184 */
24185 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
24186 do{ rc = write(fd, "S", 1); }while( rc<0 && errno==EINTR );
24187 if( rc!=1 ){
24188 pFile->lastErrno = errno;
24189 return SQLITE_IOERR;
24190 }
24191 rc = fstat(fd, &statbuf);
24192 if( rc!=0 ){
24193 pFile->lastErrno = errno;
24194 return SQLITE_IOERR;
24195 }
24196 }
@@ -24249,17 +24554,17 @@
24249 }
24250
24251 /* Otherwise see if some other process holds it.
24252 */
24253 #ifndef __DJGPP__
24254 if( !reserved ){
24255 struct flock lock;
24256 lock.l_whence = SEEK_SET;
24257 lock.l_start = RESERVED_BYTE;
24258 lock.l_len = 1;
24259 lock.l_type = F_WRLCK;
24260 if (-1 == fcntl(pFile->h, F_GETLK, &lock)) {
24261 int tErrno = errno;
24262 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK);
24263 pFile->lastErrno = tErrno;
24264 } else if( lock.l_type!=F_UNLCK ){
24265 reserved = 1;
@@ -24271,10 +24576,54 @@
24271 OSTRACE(("TEST WR-LOCK %d %d %d (unix)\n", pFile->h, rc, reserved));
24272
24273 *pResOut = reserved;
24274 return rc;
24275 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24276
24277 /*
24278 ** Lock the file with the lock specified by parameter eFileLock - one
24279 ** of the following:
24280 **
@@ -24408,11 +24757,11 @@
24408 if( eFileLock==SHARED_LOCK
24409 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
24410 ){
24411 lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK);
24412 lock.l_start = PENDING_BYTE;
24413 s = fcntl(pFile->h, F_SETLK, &lock);
24414 if( s==(-1) ){
24415 tErrno = errno;
24416 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
24417 if( IS_LOCK_ERROR(rc) ){
24418 pFile->lastErrno = tErrno;
@@ -24430,18 +24779,18 @@
24430 assert( pInode->eFileLock==0 );
24431
24432 /* Now get the read-lock */
24433 lock.l_start = SHARED_FIRST;
24434 lock.l_len = SHARED_SIZE;
24435 if( (s = fcntl(pFile->h, F_SETLK, &lock))==(-1) ){
24436 tErrno = errno;
24437 }
24438 /* Drop the temporary PENDING lock */
24439 lock.l_start = PENDING_BYTE;
24440 lock.l_len = 1L;
24441 lock.l_type = F_UNLCK;
24442 if( fcntl(pFile->h, F_SETLK, &lock)!=0 ){
24443 if( s != -1 ){
24444 /* This could happen with a network mount */
24445 tErrno = errno;
24446 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
24447 if( IS_LOCK_ERROR(rc) ){
@@ -24480,11 +24829,11 @@
24480 lock.l_len = SHARED_SIZE;
24481 break;
24482 default:
24483 assert(0);
24484 }
24485 s = fcntl(pFile->h, F_SETLK, &lock);
24486 if( s==(-1) ){
24487 tErrno = errno;
24488 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
24489 if( IS_LOCK_ERROR(rc) ){
24490 pFile->lastErrno = tErrno;
@@ -24549,11 +24898,11 @@
24549 ** the byte range is divided into 2 parts and the first part is unlocked then
24550 ** set to a read lock, then the other part is simply unlocked. This works
24551 ** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to
24552 ** remove the write lock on a region when a read lock is set.
24553 */
24554 static int _posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
24555 unixFile *pFile = (unixFile*)id;
24556 unixInodeInfo *pInode;
24557 struct flock lock;
24558 int rc = SQLITE_OK;
24559 int h;
@@ -24605,10 +24954,11 @@
24605 ** 4: [RRRR.]
24606 */
24607 if( eFileLock==SHARED_LOCK ){
24608
24609 #if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE
 
24610 assert( handleNFSUnlock==0 );
24611 #endif
24612 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
24613 if( handleNFSUnlock ){
24614 off_t divSize = SHARED_SIZE - 1;
@@ -24615,11 +24965,11 @@
24615
24616 lock.l_type = F_UNLCK;
24617 lock.l_whence = SEEK_SET;
24618 lock.l_start = SHARED_FIRST;
24619 lock.l_len = divSize;
24620 if( fcntl(h, F_SETLK, &lock)==(-1) ){
24621 tErrno = errno;
24622 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
24623 if( IS_LOCK_ERROR(rc) ){
24624 pFile->lastErrno = tErrno;
24625 }
@@ -24627,11 +24977,11 @@
24627 }
24628 lock.l_type = F_RDLCK;
24629 lock.l_whence = SEEK_SET;
24630 lock.l_start = SHARED_FIRST;
24631 lock.l_len = divSize;
24632 if( fcntl(h, F_SETLK, &lock)==(-1) ){
24633 tErrno = errno;
24634 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
24635 if( IS_LOCK_ERROR(rc) ){
24636 pFile->lastErrno = tErrno;
24637 }
@@ -24639,11 +24989,11 @@
24639 }
24640 lock.l_type = F_UNLCK;
24641 lock.l_whence = SEEK_SET;
24642 lock.l_start = SHARED_FIRST+divSize;
24643 lock.l_len = SHARED_SIZE-divSize;
24644 if( fcntl(h, F_SETLK, &lock)==(-1) ){
24645 tErrno = errno;
24646 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
24647 if( IS_LOCK_ERROR(rc) ){
24648 pFile->lastErrno = tErrno;
24649 }
@@ -24654,11 +25004,11 @@
24654 {
24655 lock.l_type = F_RDLCK;
24656 lock.l_whence = SEEK_SET;
24657 lock.l_start = SHARED_FIRST;
24658 lock.l_len = SHARED_SIZE;
24659 if( fcntl(h, F_SETLK, &lock)==(-1) ){
24660 tErrno = errno;
24661 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
24662 if( IS_LOCK_ERROR(rc) ){
24663 pFile->lastErrno = tErrno;
24664 }
@@ -24668,11 +25018,11 @@
24668 }
24669 lock.l_type = F_UNLCK;
24670 lock.l_whence = SEEK_SET;
24671 lock.l_start = PENDING_BYTE;
24672 lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
24673 if( fcntl(h, F_SETLK, &lock)!=(-1) ){
24674 pInode->eFileLock = SHARED_LOCK;
24675 }else{
24676 tErrno = errno;
24677 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
24678 if( IS_LOCK_ERROR(rc) ){
@@ -24692,11 +25042,11 @@
24692 lock.l_whence = SEEK_SET;
24693 lock.l_start = lock.l_len = 0L;
24694 SimulateIOErrorBenign(1);
24695 SimulateIOError( h=(-1) )
24696 SimulateIOErrorBenign(0);
24697 if( fcntl(h, F_SETLK, &lock)!=(-1) ){
24698 pInode->eFileLock = NO_LOCK;
24699 }else{
24700 tErrno = errno;
24701 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
24702 if( IS_LOCK_ERROR(rc) ){
@@ -24730,11 +25080,11 @@
24730 **
24731 ** If the locking level of the file descriptor is already at or below
24732 ** the requested locking level, this routine is a no-op.
24733 */
24734 static int unixUnlock(sqlite3_file *id, int eFileLock){
24735 return _posixUnlock(id, eFileLock, 0);
24736 }
24737
24738 /*
24739 ** This function performs the parts of the "close file" operation
24740 ** common to all locking schemes. It closes the directory and file
@@ -24780,10 +25130,12 @@
24780 int rc = SQLITE_OK;
24781 if( id ){
24782 unixFile *pFile = (unixFile *)id;
24783 unixUnlock(id, NO_LOCK);
24784 unixEnterMutex();
 
 
24785 if( pFile->pInode && pFile->pInode->nLock ){
24786 /* If there are outstanding locks, do not actually close the file just
24787 ** yet because that would clear those locks. Instead, add the file
24788 ** descriptor to pInode->pUnused list. It will be automatically closed
24789 ** when the last lock is cleared.
@@ -24894,11 +25246,11 @@
24894 ** holds a lock on the file. No need to check further. */
24895 reserved = 1;
24896 }else{
24897 /* The lock is held if and only if the lockfile exists */
24898 const char *zLockFile = (const char*)pFile->lockingContext;
24899 reserved = access(zLockFile, 0)==0;
24900 }
24901 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
24902 *pResOut = reserved;
24903 return rc;
24904 }
@@ -24948,11 +25300,11 @@
24948 #endif
24949 return SQLITE_OK;
24950 }
24951
24952 /* grab an exclusive lock */
24953 fd = open(zLockFile,O_RDONLY|O_CREAT|O_EXCL,0600);
24954 if( fd<0 ){
24955 /* failed to open/create the file, someone else may have stolen the lock */
24956 int tErrno = errno;
24957 if( EEXIST == tErrno ){
24958 rc = SQLITE_BUSY;
@@ -25911,11 +26263,11 @@
25911 **
25912 ** If the locking level of the file descriptor is already at or below
25913 ** the requested locking level, this routine is a no-op.
25914 */
25915 static int nfsUnlock(sqlite3_file *id, int eFileLock){
25916 return _posixUnlock(id, eFileLock, 1);
25917 }
25918
25919 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
25920 /*
25921 ** The code above is the NFS lock implementation. The code is specific
@@ -25953,14 +26305,14 @@
25953 #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
25954 i64 newOffset;
25955 #endif
25956 TIMER_START;
25957 #if defined(USE_PREAD)
25958 do{ got = pread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
25959 SimulateIOError( got = -1 );
25960 #elif defined(USE_PREAD64)
25961 do{ got = pread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
25962 SimulateIOError( got = -1 );
25963 #else
25964 newOffset = lseek(id->h, offset, SEEK_SET);
25965 SimulateIOError( newOffset-- );
25966 if( newOffset!=offset ){
@@ -25969,11 +26321,11 @@
25969 }else{
25970 ((unixFile*)id)->lastErrno = 0;
25971 }
25972 return -1;
25973 }
25974 do{ got = read(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
25975 #endif
25976 TIMER_END;
25977 if( got<0 ){
25978 ((unixFile*)id)->lastErrno = errno;
25979 }
@@ -26031,13 +26383,13 @@
26031 #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
26032 i64 newOffset;
26033 #endif
26034 TIMER_START;
26035 #if defined(USE_PREAD)
26036 do{ got = pwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26037 #elif defined(USE_PREAD64)
26038 do{ got = pwrite64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26039 #else
26040 newOffset = lseek(id->h, offset, SEEK_SET);
26041 if( newOffset!=offset ){
26042 if( newOffset == -1 ){
26043 ((unixFile*)id)->lastErrno = errno;
@@ -26044,11 +26396,11 @@
26044 }else{
26045 ((unixFile*)id)->lastErrno = 0;
26046 }
26047 return -1;
26048 }
26049 do{ got = write(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
26050 #endif
26051 TIMER_END;
26052 if( got<0 ){
26053 ((unixFile*)id)->lastErrno = errno;
26054 }
@@ -26212,11 +26564,11 @@
26212 */
26213 #ifdef SQLITE_NO_SYNC
26214 rc = SQLITE_OK;
26215 #elif HAVE_FULLFSYNC
26216 if( fullSync ){
26217 rc = fcntl(fd, F_FULLFSYNC, 0);
26218 }else{
26219 rc = 1;
26220 }
26221 /* If the FULLFSYNC failed, fall back to attempting an fsync().
26222 ** It shouldn't be possible for fullfsync to fail on the local
@@ -26359,11 +26711,11 @@
26359 */
26360 static int unixFileSize(sqlite3_file *id, i64 *pSize){
26361 int rc;
26362 struct stat buf;
26363 assert( id );
26364 rc = fstat(((unixFile*)id)->h, &buf);
26365 SimulateIOError( rc=1 );
26366 if( rc!=0 ){
26367 ((unixFile*)id)->lastErrno = errno;
26368 return SQLITE_IOERR_FSTAT;
26369 }
@@ -26400,18 +26752,18 @@
26400 static int fcntlSizeHint(unixFile *pFile, i64 nByte){
26401 if( pFile->szChunk ){
26402 i64 nSize; /* Required file size */
26403 struct stat buf; /* Used to hold return values of fstat() */
26404
26405 if( fstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
26406
26407 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
26408 if( nSize>(i64)buf.st_size ){
26409 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
26410 int rc;
26411 do{
26412 rc = posix_fallocate(pFile-.h, buf.st_size, nSize-buf.st_size;
26413 }while( rc<0 && errno=EINTR );
26414 if( rc ) return SQLITE_IOERR_WRITE;
26415 #else
26416 /* If the OS does not have posix_fallocate(), fake it. First use
26417 ** ftruncate() to set the file size, then write a single byte to
@@ -26608,19 +26960,21 @@
26608 assert( n==1 || lockType!=F_RDLCK );
26609
26610 /* Locks are within range */
26611 assert( n>=1 && n<SQLITE_SHM_NLOCK );
26612
26613 /* Initialize the locking parameters */
26614 memset(&f, 0, sizeof(f));
26615 f.l_type = lockType;
26616 f.l_whence = SEEK_SET;
26617 f.l_start = ofst;
26618 f.l_len = n;
26619
26620 rc = fcntl(pShmNode->h, F_SETLK, &f);
26621 rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
 
 
26622
26623 /* Update the global lock state and do debug tracing */
26624 #ifdef SQLITE_DEBUG
26625 { u16 mask;
26626 OSTRACE(("SHM-LOCK "));
@@ -26671,11 +27025,15 @@
26671 if( p && p->nRef==0 ){
26672 int i;
26673 assert( p->pInode==pFd->pInode );
26674 if( p->mutex ) sqlite3_mutex_free(p->mutex);
26675 for(i=0; i<p->nRegion; i++){
26676 munmap(p->apRegion[i], p->szRegion);
 
 
 
 
26677 }
26678 sqlite3_free(p->apRegion);
26679 if( p->h>=0 ){
26680 robust_close(pFd, p->h, __LINE__);
26681 p->h = -1;
@@ -26711,10 +27069,16 @@
26711 ** "unsupported" and may go away in a future SQLite release.
26712 **
26713 ** When opening a new shared-memory file, if no other instances of that
26714 ** file are currently open, in this process or in other processes, then
26715 ** the file must be truncated to zero length or have its header cleared.
 
 
 
 
 
 
26716 */
26717 static int unixOpenSharedMemory(unixFile *pDbFd){
26718 struct unixShm *p = 0; /* The connection to be opened */
26719 struct unixShmNode *pShmNode; /* The underlying mmapped file */
26720 int rc; /* Result code */
@@ -26740,11 +27104,11 @@
26740 /* Call fstat() to figure out the permissions on the database file. If
26741 ** a new *-shm file is created, an attempt will be made to create it
26742 ** with the same permissions. The actual permissions the file is created
26743 ** with are subject to the current umask setting.
26744 */
26745 if( fstat(pDbFd->h, &sStat) ){
26746 rc = SQLITE_IOERR_FSTAT;
26747 goto shm_open_err;
26748 }
26749
26750 #ifdef SQLITE_SHM_DIRECTORY
@@ -26773,29 +27137,32 @@
26773 if( pShmNode->mutex==0 ){
26774 rc = SQLITE_NOMEM;
26775 goto shm_open_err;
26776 }
26777
26778 pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, (sStat.st_mode & 0777));
26779 if( pShmNode->h<0 ){
26780 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
26781 goto shm_open_err;
26782 }
26783
26784 /* Check to see if another process is holding the dead-man switch.
26785 ** If not, truncate the file to zero length.
26786 */
26787 rc = SQLITE_OK;
26788 if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
26789 if( robust_ftruncate(pShmNode->h, 0) ){
26790 rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
26791 }
26792 }
26793 if( rc==SQLITE_OK ){
26794 rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1);
26795 }
26796 if( rc ) goto shm_open_err;
 
 
 
26797 }
26798
26799 /* Make the new connection a child of the unixShmNode */
26800 p->pShmNode = pShmNode;
26801 #ifdef SQLITE_DEBUG
@@ -26865,38 +27232,44 @@
26865
26866 p = pDbFd->pShm;
26867 pShmNode = p->pShmNode;
26868 sqlite3_mutex_enter(pShmNode->mutex);
26869 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
 
 
 
26870
26871 if( pShmNode->nRegion<=iRegion ){
26872 char **apNew; /* New apRegion[] array */
26873 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
26874 struct stat sStat; /* Used by fstat() */
26875
26876 pShmNode->szRegion = szRegion;
26877
26878 /* The requested region is not mapped into this processes address space.
26879 ** Check to see if it has been allocated (i.e. if the wal-index file is
26880 ** large enough to contain the requested region).
26881 */
26882 if( fstat(pShmNode->h, &sStat) ){
26883 rc = SQLITE_IOERR_SHMSIZE;
26884 goto shmpage_out;
26885 }
26886
26887 if( sStat.st_size<nByte ){
26888 /* The requested memory region does not exist. If bExtend is set to
26889 ** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
26890 **
26891 ** Alternatively, if bExtend is true, use ftruncate() to allocate
26892 ** the requested memory region.
26893 */
26894 if( !bExtend ) goto shmpage_out;
26895 if( robust_ftruncate(pShmNode->h, nByte) ){
26896 rc = unixLogError(SQLITE_IOERR_SHMSIZE,"ftruncate",pShmNode->zFilename);
26897 goto shmpage_out;
 
 
 
26898 }
26899 }
26900
26901 /* Map the requested memory region into this processes address space. */
26902 apNew = (char **)sqlite3_realloc(
@@ -26906,16 +27279,26 @@
26906 rc = SQLITE_IOERR_NOMEM;
26907 goto shmpage_out;
26908 }
26909 pShmNode->apRegion = apNew;
26910 while(pShmNode->nRegion<=iRegion){
26911 void *pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
26912 MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
26913 );
26914 if( pMem==MAP_FAILED ){
26915 rc = SQLITE_IOERR;
26916 goto shmpage_out;
 
 
 
 
 
 
 
 
 
 
26917 }
26918 pShmNode->apRegion[pShmNode->nRegion] = pMem;
26919 pShmNode->nRegion++;
26920 }
26921 }
@@ -26958,10 +27341,12 @@
26958 assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
26959 || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
26960 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
26961 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
26962 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
 
 
26963
26964 mask = (1<<(ofst+n)) - (1<<ofst);
26965 assert( n>1 || mask==(1<<ofst) );
26966 sqlite3_mutex_enter(pShmNode->mutex);
26967 if( flags & SQLITE_SHM_UNLOCK ){
@@ -27095,11 +27480,11 @@
27095 ** shared-memory file, too */
27096 unixEnterMutex();
27097 assert( pShmNode->nRef>0 );
27098 pShmNode->nRef--;
27099 if( pShmNode->nRef==0 ){
27100 if( deleteFlag ) unlink(pShmNode->zFilename);
27101 unixShmPurge(pDbFd);
27102 }
27103 unixLeaveMutex();
27104
27105 return SQLITE_OK;
@@ -27336,11 +27721,11 @@
27336 */
27337 lockInfo.l_len = 1;
27338 lockInfo.l_start = 0;
27339 lockInfo.l_whence = SEEK_SET;
27340 lockInfo.l_type = F_RDLCK;
27341 if( fcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
27342 if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){
27343 return &nfsIoMethods;
27344 } else {
27345 return &posixIoMethods;
27346 }
@@ -27378,11 +27763,11 @@
27378 */
27379 lockInfo.l_len = 1;
27380 lockInfo.l_start = 0;
27381 lockInfo.l_whence = SEEK_SET;
27382 lockInfo.l_type = F_RDLCK;
27383 if( fcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
27384 return &posixIoMethods;
27385 }else{
27386 return &semIoMethods;
27387 }
27388 }
@@ -27412,11 +27797,12 @@
27412 int h, /* Open file descriptor of file being opened */
27413 int dirfd, /* Directory file descriptor */
27414 sqlite3_file *pId, /* Write to the unixFile structure here */
27415 const char *zFilename, /* Name of the file being opened */
27416 int noLock, /* Omit locking if true */
27417 int isDelete /* Delete on close if true */
 
27418 ){
27419 const sqlite3_io_methods *pLockingStyle;
27420 unixFile *pNew = (unixFile *)pId;
27421 int rc = SQLITE_OK;
27422
@@ -27439,12 +27825,19 @@
27439 #endif
27440
27441 OSTRACE(("OPEN %-3d %s\n", h, zFilename));
27442 pNew->h = h;
27443 pNew->dirfd = dirfd;
27444 pNew->fileFlags = 0;
27445 pNew->zPath = zFilename;
 
 
 
 
 
 
 
 
27446
27447 #if OS_VXWORKS
27448 pNew->pId = vxworksFindFileId(zFilename);
27449 if( pNew->pId==0 ){
27450 noLock = 1;
@@ -27601,14 +27994,14 @@
27601
27602 sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename);
27603 for(ii=(int)strlen(zDirname); ii>1 && zDirname[ii]!='/'; ii--);
27604 if( ii>0 ){
27605 zDirname[ii] = '\0';
27606 fd = open(zDirname, O_RDONLY|O_BINARY, 0);
27607 if( fd>=0 ){
27608 #ifdef FD_CLOEXEC
27609 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
27610 #endif
27611 OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
27612 }
27613 }
27614 *pFd = fd;
@@ -27634,13 +28027,13 @@
27634
27635 azDirs[0] = sqlite3_temp_directory;
27636 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
27637 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
27638 if( zDir==0 ) continue;
27639 if( stat(zDir, &buf) ) continue;
27640 if( !S_ISDIR(buf.st_mode) ) continue;
27641 if( access(zDir, 07) ) continue;
27642 break;
27643 }
27644 return zDir;
27645 }
27646
@@ -27679,11 +28072,11 @@
27679 sqlite3_randomness(15, &zBuf[j]);
27680 for(i=0; i<15; i++, j++){
27681 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
27682 }
27683 zBuf[j] = 0;
27684 }while( access(zBuf,0)==0 );
27685 return SQLITE_OK;
27686 }
27687
27688 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
27689 /*
@@ -27940,19 +28333,20 @@
27940 if( rc!=SQLITE_OK ){
27941 assert( !p->pUnused );
27942 assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
27943 return rc;
27944 }
27945 fd = open(zName, openFlags, openMode);
27946 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
27947 if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){
27948 /* Failed to open the file for read/write access. Try read-only. */
27949 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
27950 openFlags &= ~(O_RDWR|O_CREAT);
27951 flags |= SQLITE_OPEN_READONLY;
27952 openFlags |= O_RDONLY;
27953 fd = open(zName, openFlags, openMode);
 
27954 }
27955 if( fd<0 ){
27956 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
27957 goto open_finished;
27958 }
@@ -27992,11 +28386,11 @@
27992 goto open_finished;
27993 }
27994 }
27995
27996 #ifdef FD_CLOEXEC
27997 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
27998 #endif
27999
28000 noLock = eType!=SQLITE_OPEN_MAIN_DB;
28001
28002
@@ -28044,11 +28438,12 @@
28044 goto open_finished;
28045 }
28046 useProxy = !(fsInfo.f_flags&MNT_LOCAL);
28047 }
28048 if( useProxy ){
28049 rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock, isDelete);
 
28050 if( rc==SQLITE_OK ){
28051 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
28052 if( rc!=SQLITE_OK ){
28053 /* Use unixClose to clean up the resources added in fillInUnixFile
28054 ** and clear all the structure's references. Specifically,
@@ -28061,11 +28456,12 @@
28061 goto open_finished;
28062 }
28063 }
28064 #endif
28065
28066 rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock, isDelete);
 
28067 open_finished:
28068 if( rc!=SQLITE_OK ){
28069 sqlite3_free(p->pUnused);
28070 }
28071 return rc;
@@ -28138,11 +28534,11 @@
28138 break;
28139
28140 default:
28141 assert(!"Invalid flags argument");
28142 }
28143 *pResOut = (access(zPath, amode)==0);
28144 if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){
28145 struct stat buf;
28146 if( 0==stat(zPath, &buf) && buf.st_size==0 ){
28147 *pResOut = 0;
28148 }
@@ -28180,11 +28576,11 @@
28180 zOut[nOut-1] = '\0';
28181 if( zPath[0]=='/' ){
28182 sqlite3_snprintf(nOut, zOut, "%s", zPath);
28183 }else{
28184 int nCwd;
28185 if( getcwd(zOut, nOut-1)==0 ){
28186 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
28187 }
28188 nCwd = (int)strlen(zOut);
28189 sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath);
28190 }
@@ -28275,21 +28671,21 @@
28275 */
28276 memset(zBuf, 0, nBuf);
28277 #if !defined(SQLITE_TEST)
28278 {
28279 int pid, fd;
28280 fd = open("/dev/urandom", O_RDONLY);
28281 if( fd<0 ){
28282 time_t t;
28283 time(&t);
28284 memcpy(zBuf, &t, sizeof(t));
28285 pid = getpid();
28286 memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
28287 assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
28288 nBuf = sizeof(t) + sizeof(pid);
28289 }else{
28290 do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
28291 robust_close(0, fd, __LINE__);
28292 }
28293 }
28294 #endif
28295 return nBuf;
@@ -28684,21 +29080,21 @@
28684 if( !pUnused ){
28685 return SQLITE_NOMEM;
28686 }
28687 }
28688 if( fd<0 ){
28689 fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
28690 terrno = errno;
28691 if( fd<0 && errno==ENOENT && islockfile ){
28692 if( proxyCreateLockPath(path) == SQLITE_OK ){
28693 fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
28694 }
28695 }
28696 }
28697 if( fd<0 ){
28698 openFlags = O_RDONLY;
28699 fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
28700 terrno = errno;
28701 }
28702 if( fd<0 ){
28703 if( islockfile ){
28704 return SQLITE_BUSY;
@@ -28723,11 +29119,11 @@
28723 dummyVfs.pAppData = (void*)&autolockIoFinder;
28724 pUnused->fd = fd;
28725 pUnused->flags = openFlags;
28726 pNew->pUnused = pUnused;
28727
28728 rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0);
28729 if( rc==SQLITE_OK ){
28730 *ppFile = pNew;
28731 return SQLITE_OK;
28732 }
28733 end_create_proxy:
@@ -28808,22 +29204,23 @@
28808 (strlcpy(&tPath[pathLen-5], "break", 6) != 5) ){
28809 sqlite3_snprintf(sizeof(errmsg),errmsg,"path error (len %d)",(int)pathLen);
28810 goto end_breaklock;
28811 }
28812 /* read the conch content */
28813 readLen = pread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
28814 if( readLen<PROXY_PATHINDEX ){
28815 sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
28816 goto end_breaklock;
28817 }
28818 /* write it out to the temporary break file */
28819 fd = open(tPath, (O_RDWR|O_CREAT|O_EXCL), SQLITE_DEFAULT_FILE_PERMISSIONS);
 
28820 if( fd<0 ){
28821 sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
28822 goto end_breaklock;
28823 }
28824 if( pwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
28825 sqlite3_snprintf(sizeof(errmsg), errmsg, "write failed (%d)", errno);
28826 goto end_breaklock;
28827 }
28828 if( rename(tPath, cPath) ){
28829 sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno);
@@ -28865,11 +29262,11 @@
28865 * 2nd try: fail if the mod time changed or host id is different, wait
28866 * 10 sec and try again
28867 * 3rd try: break the lock unless the mod time has changed.
28868 */
28869 struct stat buf;
28870 if( fstat(conchFile->h, &buf) ){
28871 pFile->lastErrno = errno;
28872 return SQLITE_IOERR_LOCK;
28873 }
28874
28875 if( nTries==1 ){
@@ -28884,11 +29281,11 @@
28884 return SQLITE_BUSY;
28885 }
28886
28887 if( nTries==2 ){
28888 char tBuf[PROXY_MAXCONCHLEN];
28889 int len = pread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
28890 if( len<0 ){
28891 pFile->lastErrno = errno;
28892 return SQLITE_IOERR_LOCK;
28893 }
28894 if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){
@@ -29054,20 +29451,20 @@
29054 /* If we created a new conch file (not just updated the contents of a
29055 ** valid conch file), try to match the permissions of the database
29056 */
29057 if( rc==SQLITE_OK && createConch ){
29058 struct stat buf;
29059 int err = fstat(pFile->h, &buf);
29060 if( err==0 ){
29061 mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
29062 S_IROTH|S_IWOTH);
29063 /* try to match the database file R/W permissions, ignore failure */
29064 #ifndef SQLITE_PROXY_DEBUG
29065 fchmod(conchFile->h, cmode);
29066 #else
29067 do{
29068 rc = fchmod(conchFile->h, cmode);
29069 }while( rc==(-1) && errno==EINTR );
29070 if( rc!=0 ){
29071 int code = errno;
29072 fprintf(stderr, "fchmod %o FAILED with %d %s\n",
29073 cmode, code, strerror(code));
@@ -29089,11 +29486,11 @@
29089 if( rc==SQLITE_OK && pFile->openFlags ){
29090 if( pFile->h>=0 ){
29091 robust_close(pFile, pFile->h, __LINE__);
29092 }
29093 pFile->h = -1;
29094 int fd = open(pCtx->dbPath, pFile->openFlags,
29095 SQLITE_DEFAULT_FILE_PERMISSIONS);
29096 OSTRACE(("TRANSPROXY: OPEN %d\n", fd));
29097 if( fd>=0 ){
29098 pFile->h = fd;
29099 }else{
@@ -29315,11 +29712,11 @@
29315 */
29316 struct statfs fsInfo;
29317 struct stat conchInfo;
29318 int goLockless = 0;
29319
29320 if( stat(pCtx->conchFilePath, &conchInfo) == -1 ) {
29321 int err = errno;
29322 if( (err==ENOENT) && (statfs(dbPath, &fsInfo) != -1) ){
29323 goLockless = (fsInfo.f_flags&MNT_RDONLY) == MNT_RDONLY;
29324 }
29325 }
@@ -29600,11 +29997,11 @@
29600 ** more than that; it looks at the filesystem type that hosts the
29601 ** database file and tries to choose an locking method appropriate for
29602 ** that filesystem time.
29603 */
29604 #define UNIXVFS(VFSNAME, FINDER) { \
29605 2, /* iVersion */ \
29606 sizeof(unixFile), /* szOsFile */ \
29607 MAX_PATHNAME, /* mxPathname */ \
29608 0, /* pNext */ \
29609 VFSNAME, /* zName */ \
29610 (void*)&FINDER, /* pAppData */ \
@@ -29619,10 +30016,13 @@
29619 unixRandomness, /* xRandomness */ \
29620 unixSleep, /* xSleep */ \
29621 unixCurrentTime, /* xCurrentTime */ \
29622 unixGetLastError, /* xGetLastError */ \
29623 unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
 
 
 
29624 }
29625
29626 /*
29627 ** All default VFSes for unix are contained in the following array.
29628 **
@@ -29636,10 +30036,11 @@
29636 #else
29637 UNIXVFS("unix", posixIoFinder ),
29638 #endif
29639 UNIXVFS("unix-none", nolockIoFinder ),
29640 UNIXVFS("unix-dotfile", dotlockIoFinder ),
 
29641 #if OS_VXWORKS
29642 UNIXVFS("unix-namedsem", semIoFinder ),
29643 #endif
29644 #if SQLITE_ENABLE_LOCKING_STYLE
29645 UNIXVFS("unix-posix", posixIoFinder ),
@@ -32626,11 +33027,11 @@
32626 /*
32627 ** Initialize and deinitialize the operating system interface.
32628 */
32629 SQLITE_API int sqlite3_os_init(void){
32630 static sqlite3_vfs winVfs = {
32631 2, /* iVersion */
32632 sizeof(winFile), /* szOsFile */
32633 MAX_PATH, /* mxPathname */
32634 0, /* pNext */
32635 "win32", /* zName */
32636 0, /* pAppData */
@@ -32645,10 +33046,13 @@
32645 winRandomness, /* xRandomness */
32646 winSleep, /* xSleep */
32647 winCurrentTime, /* xCurrentTime */
32648 winGetLastError, /* xGetLastError */
32649 winCurrentTimeInt64, /* xCurrentTimeInt64 */
 
 
 
32650 };
32651
32652 #ifndef SQLITE_OMIT_WAL
32653 /* get memory map allocation granularity */
32654 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
@@ -50782,15 +51186,13 @@
50782 }
50783 if( nearby>0 ){
50784 u32 i;
50785 int dist;
50786 closest = 0;
50787 dist = get4byte(&aData[8]) - nearby;
50788 if( dist<0 ) dist = -dist;
50789 for(i=1; i<k; i++){
50790 int d2 = get4byte(&aData[8+i*4]) - nearby;
50791 if( d2<0 ) d2 = -d2;
50792 if( d2<dist ){
50793 closest = i;
50794 dist = d2;
50795 }
50796 }
@@ -55777,13 +56179,18 @@
55777 }
55778 }else if( op==TK_UMINUS ) {
55779 /* This branch happens for multiple negative signs. Ex: -(-5) */
55780 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
55781 sqlite3VdbeMemNumerify(pVal);
55782 pVal->u.i = -1 * pVal->u.i;
55783 /* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */
55784 pVal->r = (double)-1 * pVal->r;
 
 
 
 
 
55785 sqlite3ValueApplyAffinity(pVal, affinity, enc);
55786 }
55787 }else if( op==TK_NULL ){
55788 pVal = sqlite3ValueNew(db);
55789 if( pVal==0 ) goto no_mem;
@@ -56805,12 +57212,12 @@
56805 ** will be used so that it can acquire mutexes on them all in sorted
56806 ** order (via sqlite3VdbeMutexArrayEnter(). Mutexes are acquired
56807 ** in order (and released in reverse order) to avoid deadlocks.
56808 */
56809 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){
56810 int mask;
56811 assert( i>=0 && i<p->db->nDb && i<sizeof(u32)*8 );
56812 assert( i<(int)sizeof(p->btreeMask)*8 );
56813 mask = ((u32)1)<<i;
56814 if( (p->btreeMask & mask)==0 ){
56815 p->btreeMask |= mask;
56816 sqlite3BtreeMutexArrayInsert(&p->aMutex, p->db->aDb[i].pBt);
@@ -61309,10 +61716,11 @@
61309 struct OP_SetCookie_stack_vars {
61310 Db *pDb;
61311 } au;
61312 struct OP_VerifyCookie_stack_vars {
61313 int iMeta;
 
61314 Btree *pBt;
61315 } av;
61316 struct OP_OpenWrite_stack_vars {
61317 int nField;
61318 KeyInfo *pKeyInfo;
@@ -63931,14 +64339,16 @@
63931 p->expired = 0;
63932 }
63933 break;
63934 }
63935
63936 /* Opcode: VerifyCookie P1 P2 *
63937 **
63938 ** Check the value of global database parameter number 0 (the
63939 ** schema version) and make sure it is equal to P2.
 
 
63940 ** P1 is the database number which is 0 for the main database file
63941 ** and 1 for the file holding temporary tables and some higher number
63942 ** for auxiliary databases.
63943 **
63944 ** The cookie changes its value whenever the database schema changes.
@@ -63950,21 +64360,24 @@
63950 ** invoked.
63951 */
63952 case OP_VerifyCookie: {
63953 #if 0 /* local variables moved into u.av */
63954 int iMeta;
 
63955 Btree *pBt;
63956 #endif /* local variables moved into u.av */
 
63957 assert( pOp->p1>=0 && pOp->p1<db->nDb );
63958 assert( (p->btreeMask & (1<<pOp->p1))!=0 );
63959 u.av.pBt = db->aDb[pOp->p1].pBt;
63960 if( u.av.pBt ){
63961 sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta);
 
63962 }else{
63963 u.av.iMeta = 0;
63964 }
63965 if( u.av.iMeta!=pOp->p2 ){
63966 sqlite3DbFree(db, p->zErrMsg);
63967 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
63968 /* If the schema-cookie from the database file matches the cookie
63969 ** stored with the in-memory representation of the schema, do
63970 ** not reload the schema from the database file.
@@ -65694,18 +66107,14 @@
65694 rc = sqlite3BtreeCreateTable(u.bt.pDb->pBt, &u.bt.pgno, u.bt.flags);
65695 pOut->u.i = u.bt.pgno;
65696 break;
65697 }
65698
65699 /* Opcode: ParseSchema P1 P2 * P4 *
65700 **
65701 ** Read and parse all entries from the SQLITE_MASTER table of database P1
65702 ** that match the WHERE clause P4. P2 is the "force" flag. Always do
65703 ** the parsing if P2 is true. If P2 is false, then this routine is a
65704 ** no-op if the schema is not currently loaded. In other words, if P2
65705 ** is false, the SQLITE_MASTER table is only parsed if the rest of the
65706 ** schema is already loaded into the symbol table.
65707 **
65708 ** This opcode invokes the parser to create a new virtual machine,
65709 ** then runs the new virtual machine. It is thus a re-entrant opcode.
65710 */
65711 case OP_ParseSchema: {
@@ -65717,18 +66126,11 @@
65717 #endif /* local variables moved into u.bu */
65718
65719 u.bu.iDb = pOp->p1;
65720 assert( u.bu.iDb>=0 && u.bu.iDb<db->nDb );
65721
65722 /* If pOp->p2 is 0, then this opcode is being executed to read a
65723 ** single row, for example the row corresponding to a new index
65724 ** created by this VDBE, from the sqlite_master table. It only
65725 ** does this if the corresponding in-memory schema is currently
65726 ** loaded. Otherwise, the new index definition can be loaded along
65727 ** with the rest of the schema when it is required.
65728 **
65729 ** Although the mutex on the BtShared object that corresponds to
65730 ** database u.bu.iDb (the database containing the sqlite_master table
65731 ** read by this instruction) is currently held, it is necessary to
65732 ** obtain the mutexes on all attached databases before checking if
65733 ** the schema of u.bu.iDb is loaded. This is because, at the start of
65734 ** the sqlite3_exec() call below, SQLite will invoke
@@ -65740,11 +66142,11 @@
65740 ** can result in a "no such table: sqlite_master" or "malformed
65741 ** database schema" error being returned to the user.
65742 */
65743 assert( sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) );
65744 sqlite3BtreeEnterAll(db);
65745 if( pOp->p2 || DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded) ){
65746 u.bu.zMaster = SCHEMA_TABLE(u.bu.iDb);
65747 u.bu.initData.db = db;
65748 u.bu.initData.iDb = pOp->p1;
65749 u.bu.initData.pzErrMsg = &p->zErrMsg;
65750 u.bu.zSql = sqlite3MPrintf(db,
@@ -67395,10 +67797,11 @@
67395 sqlite3VdbeChangeP2(v, 0, flags);
67396
67397 /* Configure the OP_VerifyCookie */
67398 sqlite3VdbeChangeP1(v, 1, iDb);
67399 sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie);
 
67400
67401 /* Make sure a mutex is held on the table to be accessed */
67402 sqlite3VdbeUsesBtree(v, iDb);
67403
67404 /* Configure the OP_TableLock instruction */
@@ -69826,10 +70229,11 @@
69826
69827 if( pToken ){
69828 if( op!=TK_INTEGER || pToken->z==0
69829 || sqlite3GetInt32(pToken->z, &iValue)==0 ){
69830 nExtra = pToken->n+1;
 
69831 }
69832 }
69833 pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
69834 if( pNew ){
69835 pNew->op = (u8)op;
@@ -70051,10 +70455,12 @@
70051 /*
70052 ** Recursively delete an expression tree.
70053 */
70054 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
70055 if( p==0 ) return;
 
 
70056 if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
70057 sqlite3ExprDelete(db, p->pLeft);
70058 sqlite3ExprDelete(db, p->pRight);
70059 if( !ExprHasProperty(p, EP_Reduced) && (p->flags2 & EP2_MallocedToken)!=0 ){
70060 sqlite3DbFree(db, p->u.zToken);
@@ -70660,17 +71066,10 @@
70660 }
70661 break;
70662 }
70663 default: break;
70664 }
70665 if( rc ){
70666 assert( ExprHasAnyProperty(p, EP_Reduced|EP_TokenOnly)
70667 || (p->flags2 & EP2_MallocedToken)==0 );
70668 p->op = TK_INTEGER;
70669 p->flags |= EP_IntValue;
70670 p->u.iValue = *pValue;
70671 }
70672 return rc;
70673 }
70674
70675 /*
70676 ** Return FALSE if there is no chance that the expression can be NULL.
@@ -71391,10 +71790,11 @@
71391 */
71392 static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
71393 Vdbe *v = pParse->pVdbe;
71394 if( pExpr->flags & EP_IntValue ){
71395 int i = pExpr->u.iValue;
 
71396 if( negFlag ) i = -i;
71397 sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
71398 }else{
71399 int c;
71400 i64 value;
@@ -75655,19 +76055,21 @@
75655 ** set for each database that is used. Generate code to start a
75656 ** transaction on each used database and to verify the schema cookie
75657 ** on each used database.
75658 */
75659 if( pParse->cookieGoto>0 ){
75660 u32 mask;
75661 int iDb;
75662 sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
75663 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
75664 if( (mask & pParse->cookieMask)==0 ) continue;
75665 sqlite3VdbeUsesBtree(v, iDb);
75666 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
75667 if( db->init.busy==0 ){
75668 sqlite3VdbeAddOp2(v,OP_VerifyCookie, iDb, pParse->cookieValue[iDb]);
 
 
75669 }
75670 }
75671 #ifndef SQLITE_OMIT_VIRTUALTABLE
75672 {
75673 int i;
@@ -75873,11 +76275,11 @@
75873 int len;
75874 Hash *pHash = &db->aDb[iDb].pSchema->idxHash;
75875
75876 len = sqlite3Strlen30(zIdxName);
75877 pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0);
75878 if( pIndex ){
75879 if( pIndex->pTable->pIndex==pIndex ){
75880 pIndex->pTable->pIndex = pIndex->pNext;
75881 }else{
75882 Index *p;
75883 /* Justification of ALWAYS(); The index must be on the list of
@@ -78949,16 +79351,16 @@
78949 if( v==0 ) return; /* This only happens if there was a prior error */
78950 pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1;
78951 }
78952 if( iDb>=0 ){
78953 sqlite3 *db = pToplevel->db;
78954 int mask;
78955
78956 assert( iDb<db->nDb );
78957 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
78958 assert( iDb<SQLITE_MAX_ATTACHED+2 );
78959 mask = 1<<iDb;
78960 if( (pToplevel->cookieMask & mask)==0 ){
78961 pToplevel->cookieMask |= mask;
78962 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
78963 if( !OMIT_TEMPDB && iDb==1 ){
78964 sqlite3OpenTempDatabase(pToplevel);
@@ -78981,11 +79383,11 @@
78981 ** necessary to undo a write and the checkpoint should not be set.
78982 */
78983 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
78984 Parse *pToplevel = sqlite3ParseToplevel(pParse);
78985 sqlite3CodeVerifySchema(pParse, iDb);
78986 pToplevel->writeMask |= 1<<iDb;
78987 pToplevel->isMultiWrite |= setStatement;
78988 }
78989
78990 /*
78991 ** Indicate that the statement currently under construction might write
@@ -79626,11 +80028,14 @@
79626 sqlite3DeleteTable(0, pTab);
79627 }
79628 sqlite3HashClear(&temp1);
79629 sqlite3HashClear(&pSchema->fkeyHash);
79630 pSchema->pSeqTab = 0;
79631 pSchema->flags &= ~DB_SchemaLoaded;
 
 
 
79632 }
79633
79634 /*
79635 ** Find and return the schema associated with a BTree. Create
79636 ** a new one if necessary.
@@ -84381,12 +84786,13 @@
84381 ** index and making sure that duplicate entries do not already exist.
84382 ** Add the new records to the indices as we go.
84383 */
84384 for(iCur=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, iCur++){
84385 int regIdx;
 
84386 int regR;
84387
84388 if( aRegIdx[iCur]==0 ) continue; /* Skip unused indices */
84389
84390 /* Create a key for accessing the index entry */
84391 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn+1);
84392 for(i=0; i<pIdx->nColumn; i++){
@@ -84399,10 +84805,15 @@
84399 }
84400 sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
84401 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]);
84402 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);
84403 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1);
 
 
 
 
 
84404
84405 /* Find out what action to take in case there is an indexing conflict */
84406 onError = pIdx->onError;
84407 if( onError==OE_None ){
84408 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
@@ -84473,10 +84884,11 @@
84473 break;
84474 }
84475 }
84476 sqlite3VdbeJumpHere(v, j3);
84477 sqlite3ReleaseTempReg(pParse, regR);
 
84478 }
84479
84480 if( pbMayReplace ){
84481 *pbMayReplace = seenReplace;
84482 }
@@ -86501,12 +86913,11 @@
86501 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
86502 sqlite3VdbeChangeP1(v, addr, iDb);
86503 sqlite3VdbeChangeP1(v, addr+1, iDb);
86504 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
86505 }else{
86506 int size = sqlite3Atoi(zRight);
86507 if( size<0 ) size = -size;
86508 sqlite3BeginWriteOperation(pParse, 0, iDb);
86509 sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
86510 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
86511 pDb->pSchema->cache_size = size;
86512 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
@@ -86811,12 +87222,11 @@
86811 if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
86812 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
86813 if( !zRight ){
86814 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
86815 }else{
86816 int size = sqlite3Atoi(zRight);
86817 if( size<0 ) size = -size;
86818 pDb->pSchema->cache_size = size;
86819 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
86820 }
86821 }else
86822
@@ -87920,13 +88330,12 @@
87920 DbSetProperty(db, iDb, DB_Empty);
87921 }
87922 pDb->pSchema->enc = ENC(db);
87923
87924 if( pDb->pSchema->cache_size==0 ){
87925 size = meta[BTREE_DEFAULT_CACHE_SIZE-1];
87926 if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
87927 if( size<0 ) size = -size;
87928 pDb->pSchema->cache_size = size;
87929 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
87930 }
87931
87932 /*
@@ -93787,12 +94196,16 @@
93787 int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
93788 ExprList *pChanges, /* Columns that change in an UPDATE statement */
93789 int *pMask /* OUT: Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
93790 ){
93791 int mask = 0;
93792 Trigger *pList = sqlite3TriggerList(pParse, pTab);
93793 Trigger *p;
 
 
 
 
93794 assert( pList==0 || IsVirtual(pTab)==0 );
93795 for(p=pList; p; p=p->pNext){
93796 if( p->op==op && checkColumnOverlap(p->pColumns, pChanges) ){
93797 mask |= p->tr_tm;
93798 }
@@ -95642,11 +96055,11 @@
95642 v = sqlite3GetVdbe(pParse);
95643 sqlite3ChangeCookie(pParse, iDb);
95644
95645 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
95646 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
95647 sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 1, 0, zWhere, P4_DYNAMIC);
95648 sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0,
95649 pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
95650 }
95651
95652 /* If we are rereading the sqlite_master table create the in-memory
@@ -98732,11 +99145,12 @@
98732 /*
98733 ** Estimate the number of rows that will be returned based on
98734 ** an equality constraint x=VALUE and where that VALUE occurs in
98735 ** the histogram data. This only works when x is the left-most
98736 ** column of an index and sqlite_stat2 histogram data is available
98737 ** for that index.
 
98738 **
98739 ** Write the estimated row count into *pnRow and return SQLITE_OK.
98740 ** If unable to make an estimate, leave *pnRow unchanged and return
98741 ** non-zero.
98742 **
@@ -98757,12 +99171,16 @@
98757 int rc; /* Subfunction return code */
98758 double nRowEst; /* New estimate of the number of rows */
98759
98760 assert( p->aSample!=0 );
98761 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
98762 rc = valueFromExpr(pParse, pExpr, aff, &pRhs);
98763 if( rc ) goto whereEqualScanEst_cancel;
 
 
 
 
98764 if( pRhs==0 ) return SQLITE_NOTFOUND;
98765 rc = whereRangeRegion(pParse, p, pRhs, 0, &iLower);
98766 if( rc ) goto whereEqualScanEst_cancel;
98767 rc = whereRangeRegion(pParse, p, pRhs, 1, &iUpper);
98768 if( rc ) goto whereEqualScanEst_cancel;
@@ -99147,11 +99565,13 @@
99147 ** data is available for column x, then it might be possible
99148 ** to get a better estimate on the number of rows based on
99149 ** VALUE and how common that value is according to the histogram.
99150 */
99151 if( nRow>(double)1 && nEq==1 && pFirstTerm!=0 ){
99152 if( pFirstTerm->eOperator==WO_EQ ){
 
 
99153 whereEqualScanEst(pParse, pProbe, pFirstTerm->pExpr->pRight, &nRow);
99154 }else if( pFirstTerm->eOperator==WO_IN && bInEst==0 ){
99155 whereInScanEst(pParse, pProbe, pFirstTerm->pExpr->x.pList, &nRow);
99156 }
99157 }
@@ -100213,11 +100633,17 @@
100213 }
100214
100215 /* Record the instruction used to terminate the loop. Disable
100216 ** WHERE clause terms made redundant by the index range scan.
100217 */
100218 pLevel->op = bRev ? OP_Prev : OP_Next;
 
 
 
 
 
 
100219 pLevel->p1 = iIdxCur;
100220 }else
100221
100222 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
100223 if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
@@ -106160,10 +106586,17 @@
106160 case SQLITE_CONFIG_HEAP: {
106161 /* Designate a buffer for heap memory space */
106162 sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
106163 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
106164 sqlite3GlobalConfig.mnReq = va_arg(ap, int);
 
 
 
 
 
 
 
106165
106166 if( sqlite3GlobalConfig.pHeap==0 ){
106167 /* If the heap pointer is NULL, then restore the malloc implementation
106168 ** back to NULL pointers too. This will cause the malloc to go
106169 ** back to its default implementation when sqlite3_initialize() is
@@ -106301,11 +106734,39 @@
106301 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
106302 rc = setupLookaside(db, pBuf, sz, cnt);
106303 break;
106304 }
106305 default: {
 
 
 
 
 
 
 
 
106306 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106307 break;
106308 }
106309 }
106310 va_end(ap);
106311 return rc;
@@ -107474,12 +107935,12 @@
107474 # error SQLITE_MAX_VDBE_OP must be at least 40
107475 #endif
107476 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
107477 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
107478 #endif
107479 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>30
107480 # error SQLITE_MAX_ATTACHED must be between 0 and 30
107481 #endif
107482 #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
107483 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
107484 #endif
107485 #if SQLITE_MAX_COLUMN>32767
@@ -107634,11 +108095,11 @@
107634 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
107635 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
107636 db->autoCommit = 1;
107637 db->nextAutovac = -1;
107638 db->nextPagesize = 0;
107639 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex
107640 #if SQLITE_DEFAULT_FILE_FORMAT<4
107641 | SQLITE_LegacyFileFmt
107642 #endif
107643 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
107644 | SQLITE_LoadExtension
@@ -119847,17 +120308,17 @@
119847 Fts3Expr *pExpr, /* Phrase expression node */
119848 int iPhrase, /* Phrase number */
119849 void *pCtx /* Pointer to MatchInfo structure */
119850 ){
119851 MatchInfo *p = (MatchInfo *)pCtx;
 
 
 
 
119852
119853 if( pExpr->aDoclist ){
119854 char *pCsr;
119855 int iStart = iPhrase * p->nCol * 3;
119856 int i;
119857
119858 for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0;
119859
119860 pCsr = sqlite3Fts3FindPositions(pExpr, p->pCursor->iPrevId, -1);
119861 if( pCsr ){
119862 fts3LoadColumnlistCounts(&pCsr, &p->aMatchinfo[iStart], 0);
119863 }
@@ -121944,19 +122405,19 @@
121944 ** to which the constraint applies. The leftmost coordinate column
121945 ** is 'a', the second from the left 'b' etc.
121946 */
121947 static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
121948 int rc = SQLITE_OK;
121949 int ii, cCol;
121950
121951 int iIdx = 0;
121952 char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
121953 memset(zIdxStr, 0, sizeof(zIdxStr));
121954 UNUSED_PARAMETER(tab);
121955
121956 assert( pIdxInfo->idxStr==0 );
121957 for(ii=0; ii<pIdxInfo->nConstraint; ii++){
121958 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
121959
121960 if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
121961 /* We have an equality constraint on the rowid. Use strategy 1. */
121962 int jj;
@@ -121976,13 +122437,11 @@
121976 pIdxInfo->estimatedCost = 10.0;
121977 return SQLITE_OK;
121978 }
121979
121980 if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
121981 int j, opmsk;
121982 static const unsigned char compatible[] = { 0, 0, 1, 1, 2, 2 };
121983 u8 op = 0;
121984 switch( p->op ){
121985 case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
121986 case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
121987 case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
121988 case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
@@ -121990,41 +122449,14 @@
121990 default:
121991 assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH );
121992 op = RTREE_MATCH;
121993 break;
121994 }
121995 assert( op!=0 );
121996
121997 /* Make sure this particular constraint has not been used before.
121998 ** If it has been used before, ignore it.
121999 **
122000 ** A <= or < can be used if there is a prior >= or >.
122001 ** A >= or > can be used if there is a prior < or <=.
122002 ** A <= or < is disqualified if there is a prior <=, <, or ==.
122003 ** A >= or > is disqualified if there is a prior >=, >, or ==.
122004 ** A == is disqualifed if there is any prior constraint.
122005 */
122006 assert( compatible[RTREE_EQ & 7]==0 );
122007 assert( compatible[RTREE_LT & 7]==1 );
122008 assert( compatible[RTREE_LE & 7]==1 );
122009 assert( compatible[RTREE_GT & 7]==2 );
122010 assert( compatible[RTREE_GE & 7]==2 );
122011 cCol = p->iColumn - 1 + 'a';
122012 opmsk = compatible[op & 7];
122013 for(j=0; j<iIdx; j+=2){
122014 if( zIdxStr[j+1]==cCol && (compatible[zIdxStr[j] & 7] & opmsk)!=0 ){
122015 op = 0;
122016 break;
122017 }
122018 }
122019 if( op ){
122020 assert( iIdx<sizeof(zIdxStr)-1 );
122021 zIdxStr[iIdx++] = op;
122022 zIdxStr[iIdx++] = cCol;
122023 pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
122024 pIdxInfo->aConstraintUsage[ii].omit = 1;
122025 }
122026 }
122027 }
122028
122029 pIdxInfo->idxNum = 2;
122030 pIdxInfo->needToFreeIdxStr = 1;
122031
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.6"
654 #define SQLITE_VERSION_NUMBER 3007006
655 #define SQLITE_SOURCE_ID "2011-03-24 01:34:03 b6e268fce12829f058f1dfa223731ec8479493f8"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1439,14 +1439,27 @@
1439 ** a 24-hour day).
1440 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
1441 ** date and time if that method is available (if iVersion is 2 or
1442 ** greater and the function pointer is not NULL) and will fall back
1443 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1444 **
1445 ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
1446 ** are not used by the SQLite core. These optional interfaces are provided
1447 ** by some VFSes to facilitate testing of the VFS code. By overriding
1448 ** system calls with functions under its control, a test program can
1449 ** simulate faults and error conditions that would otherwise be difficult
1450 ** or impossible to induce. The set of system calls that can be overridden
1451 ** varies from one VFS to another, and from one version of the same VFS to the
1452 ** next. Applications that use these interfaces must be prepared for any
1453 ** or all of these interfaces to be NULL or for their behavior to change
1454 ** from one release to the next. Applications must not attempt to access
1455 ** any of these methods if the iVersion of the VFS is less than 3.
1456 */
1457 typedef struct sqlite3_vfs sqlite3_vfs;
1458 typedef void (*sqlite3_syscall_ptr)(void);
1459 struct sqlite3_vfs {
1460 int iVersion; /* Structure version number (currently 3) */
1461 int szOsFile; /* Size of subclassed sqlite3_file */
1462 int mxPathname; /* Maximum file pathname length */
1463 sqlite3_vfs *pNext; /* Next registered VFS */
1464 const char *zName; /* Name of this virtual file system */
1465 void *pAppData; /* Pointer to application-specific data */
@@ -1468,10 +1481,17 @@
1481 ** definition. Those that follow are added in version 2 or later
1482 */
1483 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1484 /*
1485 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1486 ** Those below are for version 3 and greater.
1487 */
1488 int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
1489 sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
1490 const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
1491 /*
1492 ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
1493 ** New fields may be appended in figure versions. The iVersion
1494 ** value will increment whenever this happens.
1495 */
1496 };
1497
@@ -1652,21 +1672,16 @@
1672 ** CAPI3REF: Configure database connections
1673 **
1674 ** The sqlite3_db_config() interface is used to make configuration
1675 ** changes to a [database connection]. The interface is similar to
1676 ** [sqlite3_config()] except that the changes apply to a single
1677 ** [database connection] (specified in the first argument).
 
 
 
1678 **
1679 ** The second argument to sqlite3_db_config(D,V,...) is the
1680 ** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code
1681 ** that indicates what aspect of the [database connection] is being configured.
1682 ** Subsequent arguments vary depending on the configuration verb.
 
 
1683 **
1684 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1685 ** the call is considered successful.
1686 */
1687 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
@@ -1887,11 +1902,13 @@
1902 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1903 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1904 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1905 ** allocator is engaged to handle all of SQLites memory allocation needs.
1906 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1907 ** boundary or subsequent behavior of SQLite will be undefined.
1908 ** The minimum allocation size is capped at 2^12. Reasonable values
1909 ** for the minimum allocation size are 2^5 through 2^8.</dd>
1910 **
1911 ** <dt>SQLITE_CONFIG_MUTEX</dt>
1912 ** <dd> ^(This option takes a single argument which is a pointer to an
1913 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1914 ** alternative low-level mutex routines to be used in place
@@ -2008,13 +2025,35 @@
2025 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2026 ** Any attempt to change the lookaside memory configuration when lookaside
2027 ** memory is in use leaves the configuration unchanged and returns
2028 ** [SQLITE_BUSY].)^</dd>
2029 **
2030 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2031 ** <dd> ^This option is used to enable or disable the enforcement of
2032 ** [foreign key constraints]. There should be two additional arguments.
2033 ** The first argument is an integer which is 0 to disable FK enforcement,
2034 ** positive to enable FK enforcement or negative to leave FK enforcement
2035 ** unchanged. The second parameter is a pointer to an integer into which
2036 ** is written 0 or 1 to indicate whether FK enforcement is off or on
2037 ** following this call. The second parameter may be a NULL pointer, in
2038 ** which case the FK enforcement setting is not reported back. </dd>
2039 **
2040 ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
2041 ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2042 ** There should be two additional arguments.
2043 ** The first argument is an integer which is 0 to disable triggers,
2044 ** positive to enable trigers or negative to leave the setting unchanged.
2045 ** The second parameter is a pointer to an integer into which
2046 ** is written 0 or 1 to indicate whether triggers are disabled or enabled
2047 ** following this call. The second parameter may be a NULL pointer, in
2048 ** which case the trigger setting is not reported back. </dd>
2049 **
2050 ** </dl>
2051 */
2052 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2053 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2054 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2055
2056
2057 /*
2058 ** CAPI3REF: Enable Or Disable Extended Result Codes
2059 **
@@ -8974,10 +9013,11 @@
9013 /*
9014 ** An instance of the following structure stores a database schema.
9015 */
9016 struct Schema {
9017 int schema_cookie; /* Database schema version number for this file */
9018 int iGeneration; /* Generation counter. Incremented with each change */
9019 Hash tblHash; /* All tables indexed by name */
9020 Hash idxHash; /* All (named) indices indexed by name */
9021 Hash trigHash; /* All triggers indexed by name */
9022 Hash fkeyHash; /* All foreign keys by referenced table name */
9023 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
@@ -9227,10 +9267,11 @@
9267 #define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
9268 #define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
9269 #define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
9270 #define SQLITE_PreferBuiltin 0x10000000 /* Preference to built-in funcs */
9271 #define SQLITE_LoadExtension 0x20000000 /* Enable load_extension */
9272 #define SQLITE_EnableTrigger 0x40000000 /* True to enable triggers */
9273
9274 /*
9275 ** Bits of the sqlite3.flags field that are used by the
9276 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
9277 ** These must be the low-order bits of the flags field.
@@ -9926,11 +9967,11 @@
9967 u8 op; /* Operation performed by this node */
9968 char affinity; /* The affinity of the column or 0 if not a column */
9969 u16 flags; /* Various flags. EP_* See below */
9970 union {
9971 char *zToken; /* Token value. Zero terminated and dequoted */
9972 int iValue; /* Non-negative integer value if EP_IntValue */
9973 } u;
9974
9975 /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no
9976 ** space is allocated for the fields below this point. An attempt to
9977 ** access them will result in a segfault or malfunction.
@@ -10426,10 +10467,17 @@
10467 SubProgram *pProgram; /* Program implementing pTrigger/orconf */
10468 u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */
10469 TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */
10470 };
10471
10472 /* Datatype for the bitmask of all attached databases */
10473 #if SQLITE_MAX_ATTACHED>30
10474 typedef sqlite3_uint64 tAttachMask;
10475 #else
10476 typedef unsigned int tAttachMask;
10477 #endif
10478
10479 /*
10480 ** An SQL parser context. A copy of this structure is passed through
10481 ** the parser and down into all the parser action routine in order to
10482 ** carry around information that is global to the entire parse.
10483 **
@@ -10474,12 +10522,12 @@
10522 u8 tempReg; /* iReg is a temp register that needs to be freed */
10523 int iLevel; /* Nesting level */
10524 int iReg; /* Reg with value of this column. 0 means none. */
10525 int lru; /* Least recently used entry has the smallest value */
10526 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
10527 tAttachMask writeMask; /* Start a write transaction on these databases */
10528 tAttachMask cookieMask; /* Bitmask of schema verified databases */
10529 u8 isMultiWrite; /* True if statement may affect/insert multiple rows */
10530 u8 mayAbort; /* True if statement may throw an ABORT exception */
10531 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
10532 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
10533 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -11209,10 +11257,11 @@
11257 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
11258 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
11259 SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64);
11260 SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64);
11261 SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64);
11262 SQLITE_PRIVATE int sqlite3AbsInt32(int);
11263
11264 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
11265 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
11266 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
11267 void(*)(void*));
@@ -12023,10 +12072,13 @@
12072 "OMIT_TRIGGER",
12073 #endif
12074 #ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
12075 "OMIT_TRUNCATE_OPTIMIZATION",
12076 #endif
12077 #ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT
12078 "OMIT_UNIQUE_ENFORCEMENT",
12079 #endif
12080 #ifdef SQLITE_OMIT_UTF16
12081 "OMIT_UTF16",
12082 #endif
12083 #ifdef SQLITE_OMIT_VACUUM
12084 "OMIT_VACUUM",
@@ -12436,11 +12488,11 @@
12488 u8 inVtabMethod; /* See comments above */
12489 u8 usesStmtJournal; /* True if uses a statement journal */
12490 u8 readOnly; /* True for read-only statements */
12491 u8 isPrepareV2; /* True if prepared with prepare_v2() */
12492 int nChange; /* Number of db changes made since last reset */
12493 tAttachMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
12494 int iStatement; /* Statement number (or 0 if has not opened stmt) */
12495 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
12496 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
12497 #ifndef SQLITE_OMIT_TRACE
12498 i64 startTime; /* Time when query started - used for profiling */
@@ -16155,11 +16207,11 @@
16207 ** memsys5Log(8) -> 3
16208 ** memsys5Log(9) -> 4
16209 */
16210 static int memsys5Log(int iValue){
16211 int iLog;
16212 for(iLog=0; (iLog<((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++);
16213 return iLog;
16214 }
16215
16216 /*
16217 ** Initialize the memory allocator.
@@ -16186,10 +16238,11 @@
16238
16239 nByte = sqlite3GlobalConfig.nHeap;
16240 zByte = (u8*)sqlite3GlobalConfig.pHeap;
16241 assert( zByte!=0 ); /* sqlite3_config() does not allow otherwise */
16242
16243 /* boundaries on sqlite3GlobalConfig.mnReq are enforced in sqlite3_config() */
16244 nMinLog = memsys5Log(sqlite3GlobalConfig.mnReq);
16245 mem5.szAtom = (1<<nMinLog);
16246 while( (int)sizeof(Mem5Link)>mem5.szAtom ){
16247 mem5.szAtom = mem5.szAtom << 1;
16248 }
@@ -16689,15 +16742,20 @@
16742 ** Each recursive mutex is an instance of the following structure.
16743 */
16744 struct sqlite3_mutex {
16745 HMTX mutex; /* Mutex controlling the lock */
16746 int id; /* Mutex type */
16747 #ifdef SQLITE_DEBUG
16748 int trace; /* True to trace changes */
16749 #endif
16750 };
16751
16752 #ifdef SQLITE_DEBUG
16753 #define SQLITE3_MUTEX_INITIALIZER { 0, 0, 0 }
16754 #else
16755 #define SQLITE3_MUTEX_INITIALIZER { 0, 0 }
16756 #endif
16757
16758 /*
16759 ** Initialize and deinitialize the mutex subsystem.
16760 */
16761 static int os2MutexInit(void){ return SQLITE_OK; }
@@ -16709,15 +16767,18 @@
16767 ** that means that a mutex could not be allocated.
16768 ** SQLite will unwind its stack and return an error. The argument
16769 ** to sqlite3_mutex_alloc() is one of these integer constants:
16770 **
16771 ** <ul>
16772 ** <li> SQLITE_MUTEX_FAST
16773 ** <li> SQLITE_MUTEX_RECURSIVE
16774 ** <li> SQLITE_MUTEX_STATIC_MASTER
16775 ** <li> SQLITE_MUTEX_STATIC_MEM
16776 ** <li> SQLITE_MUTEX_STATIC_MEM2
16777 ** <li> SQLITE_MUTEX_STATIC_PRNG
16778 ** <li> SQLITE_MUTEX_STATIC_LRU
16779 ** <li> SQLITE_MUTEX_STATIC_LRU2
16780 ** </ul>
16781 **
16782 ** The first two constants cause sqlite3_mutex_alloc() to create
16783 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
16784 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -16727,11 +16788,11 @@
16788 ** cases where it really needs one. If a faster non-recursive mutex
16789 ** implementation is available on the host platform, the mutex subsystem
16790 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
16791 **
16792 ** The other allowed parameters to sqlite3_mutex_alloc() each return
16793 ** a pointer to a static preexisting mutex. Six static mutexes are
16794 ** used by the current version of SQLite. Future versions of SQLite
16795 ** may add additional static mutexes. Static mutexes are for internal
16796 ** use by SQLite only. Applications that use SQLite mutexes should
16797 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
16798 ** SQLITE_MUTEX_RECURSIVE.
@@ -16757,17 +16818,17 @@
16818 }
16819 break;
16820 }
16821 default: {
16822 static volatile int isInit = 0;
16823 static sqlite3_mutex staticMutexes[6] = {
16824 SQLITE3_MUTEX_INITIALIZER,
16825 SQLITE3_MUTEX_INITIALIZER,
16826 SQLITE3_MUTEX_INITIALIZER,
16827 SQLITE3_MUTEX_INITIALIZER,
16828 SQLITE3_MUTEX_INITIALIZER,
16829 SQLITE3_MUTEX_INITIALIZER,
16830 };
16831 if ( !isInit ){
16832 APIRET rc;
16833 PTIB ptib;
16834 PPIB ppib;
@@ -16809,13 +16870,18 @@
16870 /*
16871 ** This routine deallocates a previously allocated mutex.
16872 ** SQLite is careful to deallocate every mutex that it allocates.
16873 */
16874 static void os2MutexFree(sqlite3_mutex *p){
16875 #ifdef SQLITE_DEBUG
16876 TID tid;
16877 PID pid;
16878 ULONG ulCount;
16879 DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16880 assert( ulCount==0 );
16881 assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
16882 #endif
16883 DosCloseMutexSem( p->mutex );
16884 sqlite3_free( p );
16885 }
16886
16887 #ifdef SQLITE_DEBUG
@@ -16826,30 +16892,33 @@
16892 static int os2MutexHeld(sqlite3_mutex *p){
16893 TID tid;
16894 PID pid;
16895 ULONG ulCount;
16896 PTIB ptib;
16897 DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16898 if( ulCount==0 || ( ulCount>1 && p->id!=SQLITE_MUTEX_RECURSIVE ) )
16899 return 0;
16900 DosGetInfoBlocks(&ptib, NULL);
16901 return tid==ptib->tib_ptib2->tib2_ultid;
 
 
16902 }
16903 static int os2MutexNotheld(sqlite3_mutex *p){
16904 TID tid;
16905 PID pid;
16906 ULONG ulCount;
16907 PTIB ptib;
16908 DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16909 if( ulCount==0 )
16910 return 1;
16911 DosGetInfoBlocks(&ptib, NULL);
16912 return tid!=ptib->tib_ptib2->tib2_ultid;
16913 }
16914 static void os2MutexTrace(sqlite3_mutex *p, char *pAction){
16915 TID tid;
16916 PID pid;
16917 ULONG ulCount;
16918 DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
16919 printf("%s mutex %p (%d) with nRef=%ld\n", pAction, (void*)p, p->trace, ulCount);
16920 }
16921 #endif
16922
16923 /*
16924 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
@@ -16861,36 +16930,25 @@
16930 ** mutex must be exited an equal number of times before another thread
16931 ** can enter. If the same thread tries to enter any other kind of mutex
16932 ** more than once, the behavior is undefined.
16933 */
16934 static void os2MutexEnter(sqlite3_mutex *p){
 
 
 
 
16935 assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) );
16936 DosRequestMutexSem(p->mutex, SEM_INDEFINITE_WAIT);
16937 #ifdef SQLITE_DEBUG
16938 if( p->trace ) os2MutexTrace(p, "enter");
16939 #endif
16940 }
16941 static int os2MutexTry(sqlite3_mutex *p){
16942 int rc = SQLITE_BUSY;
 
 
 
 
16943 assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) );
16944 if( DosRequestMutexSem(p->mutex, SEM_IMMEDIATE_RETURN) == NO_ERROR ) {
 
 
 
16945 rc = SQLITE_OK;
16946 #ifdef SQLITE_DEBUG
16947 if( p->trace ) os2MutexTrace(p, "try");
16948 #endif
16949 }
 
16950 return rc;
16951 }
16952
16953 /*
16954 ** The sqlite3_mutex_leave() routine exits a mutex that was
@@ -16897,23 +16955,18 @@
16955 ** previously entered by the same thread. The behavior
16956 ** is undefined if the mutex is not currently entered or
16957 ** is not currently allocated. SQLite will never do either.
16958 */
16959 static void os2MutexLeave(sqlite3_mutex *p){
16960 assert( os2MutexHeld(p) );
 
 
 
 
 
 
 
 
16961 DosReleaseMutexSem(p->mutex);
16962 #ifdef SQLITE_DEBUG
16963 if( p->trace ) os2MutexTrace(p, "leave");
16964 #endif
16965 }
16966
16967 SQLITE_PRIVATE SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
16968 static const sqlite3_mutex_methods sMutex = {
16969 os2MutexInit,
16970 os2MutexEnd,
16971 os2MutexAlloc,
16972 os2MutexFree,
@@ -16921,10 +16974,13 @@
16974 os2MutexTry,
16975 os2MutexLeave,
16976 #ifdef SQLITE_DEBUG
16977 os2MutexHeld,
16978 os2MutexNotheld
16979 #else
16980 0,
16981 0
16982 #endif
16983 };
16984
16985 return &sMutex;
16986 }
@@ -17564,11 +17620,11 @@
17620 #else
17621 UNUSED_PARAMETER(p);
17622 #endif
17623 #ifdef SQLITE_DEBUG
17624 if( rc==SQLITE_OK && p->trace ){
17625 printf("try mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
17626 }
17627 #endif
17628 return rc;
17629 }
17630
@@ -21270,10 +21326,20 @@
21326 r *= TWOPOWER32;
21327 if( sqlite3AddInt64(&r, iA0*iB0) ) return 1;
21328 *pA = r;
21329 return 0;
21330 }
21331
21332 /*
21333 ** Compute the absolute value of a 32-bit signed integer, of possible. Or
21334 ** if the integer has a value of -2147483648, return +2147483647
21335 */
21336 SQLITE_PRIVATE int sqlite3AbsInt32(int x){
21337 if( x>=0 ) return x;
21338 if( x==(int)0x80000000 ) return 0x7fffffff;
21339 return -x;
21340 }
21341
21342 /************** End of util.c ************************************************/
21343 /************** Begin file hash.c ********************************************/
21344 /*
21345 ** 2001 September 22
@@ -22560,23 +22626,27 @@
22626 /*
22627 ** This vector defines all the methods that can operate on an
22628 ** sqlite3_file for os2.
22629 */
22630 static const sqlite3_io_methods os2IoMethod = {
22631 1, /* iVersion */
22632 os2Close, /* xClose */
22633 os2Read, /* xRead */
22634 os2Write, /* xWrite */
22635 os2Truncate, /* xTruncate */
22636 os2Sync, /* xSync */
22637 os2FileSize, /* xFileSize */
22638 os2Lock, /* xLock */
22639 os2Unlock, /* xUnlock */
22640 os2CheckReservedLock, /* xCheckReservedLock */
22641 os2FileControl, /* xFileControl */
22642 os2SectorSize, /* xSectorSize */
22643 os2DeviceCharacteristics, /* xDeviceCharacteristics */
22644 0, /* xShmMap */
22645 0, /* xShmLock */
22646 0, /* xShmBarrier */
22647 0 /* xShmUnmap */
22648 };
22649
22650 /***************************************************************************
22651 ** Here ends the I/O methods that form the sqlite3_io_methods object.
22652 **
@@ -22664,115 +22734,151 @@
22734 /*
22735 ** Open a file.
22736 */
22737 static int os2Open(
22738 sqlite3_vfs *pVfs, /* Not used */
22739 const char *zName, /* Name of the file (UTF-8) */
22740 sqlite3_file *id, /* Write the SQLite file handle here */
22741 int flags, /* Open mode flags */
22742 int *pOutFlags /* Status return flags */
22743 ){
22744 HFILE h;
 
22745 ULONG ulOpenFlags = 0;
22746 ULONG ulOpenMode = 0;
22747 ULONG ulAction = 0;
22748 ULONG rc;
22749 os2File *pFile = (os2File*)id;
22750 const char *zUtf8Name = zName;
 
22751 char *zNameCp;
22752 char zTmpname[CCHMAXPATH];
22753
22754 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
22755 int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
22756 int isCreate = (flags & SQLITE_OPEN_CREATE);
22757 int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
22758 #ifndef NDEBUG
22759 int isReadonly = (flags & SQLITE_OPEN_READONLY);
22760 int eType = (flags & 0xFFFFFF00);
22761 int isOpenJournal = (isCreate && (
22762 eType==SQLITE_OPEN_MASTER_JOURNAL
22763 || eType==SQLITE_OPEN_MAIN_JOURNAL
22764 || eType==SQLITE_OPEN_WAL
22765 ));
22766 #endif
22767
22768 UNUSED_PARAMETER(pVfs);
22769 assert( id!=0 );
22770
22771 /* Check the following statements are true:
22772 **
22773 ** (a) Exactly one of the READWRITE and READONLY flags must be set, and
22774 ** (b) if CREATE is set, then READWRITE must also be set, and
22775 ** (c) if EXCLUSIVE is set, then CREATE must also be set.
22776 ** (d) if DELETEONCLOSE is set, then CREATE must also be set.
22777 */
22778 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
22779 assert(isCreate==0 || isReadWrite);
22780 assert(isExclusive==0 || isCreate);
22781 assert(isDelete==0 || isCreate);
22782
22783 /* The main DB, main journal, WAL file and master journal are never
22784 ** automatically deleted. Nor are they ever temporary files. */
22785 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
22786 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
22787 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
22788 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
22789
22790 /* Assert that the upper layer has set one of the "file-type" flags. */
22791 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
22792 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
22793 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
22794 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
22795 );
22796
22797 memset( pFile, 0, sizeof(*pFile) );
22798 pFile->pMethod = &os2IoMethod;
22799
22800 /* If the second argument to this function is NULL, generate a
22801 ** temporary file name to use
22802 */
22803 if( !zUtf8Name ){
22804 assert(isDelete && !isOpenJournal);
22805 rc = getTempname(CCHMAXPATH, zTmpname);
22806 if( rc!=SQLITE_OK ){
22807 return rc;
22808 }
22809 zUtf8Name = zTmpname;
22810 }
22811
22812 if( isReadWrite ){
 
 
 
 
 
22813 ulOpenMode |= OPEN_ACCESS_READWRITE;
 
22814 }else{
22815 ulOpenMode |= OPEN_ACCESS_READONLY;
22816 }
22817
22818 /* Open in random access mode for possibly better speed. Allow full
22819 ** sharing because file locks will provide exclusive access when needed.
22820 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22821 ulOpenMode |= OPEN_FLAGS_RANDOM;
22822 ulOpenMode |= OPEN_FLAGS_FAIL_ON_ERROR;
22823 ulOpenMode |= OPEN_FLAGS_NOINHERIT;
22824 ulOpenMode |= OPEN_SHARE_DENYNONE;
22825
22826 /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
22827 ** created. SQLite doesn't use it to indicate "exclusive access"
22828 ** as it is usually understood.
22829 */
22830 if( isExclusive ){
22831 /* Creates a new file, only if it does not already exist. */
22832 /* If the file exists, it fails. */
22833 ulOpenFlags |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_FAIL_IF_EXISTS;
22834 }else if( isCreate ){
22835 /* Open existing file, or create if it doesn't exist */
22836 ulOpenFlags |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
22837 }else{
22838 /* Opens a file, only if it exists. */
22839 ulOpenFlags |= OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
22840 }
22841
22842 /* For DELETEONCLOSE, save a pointer to the converted filename */
22843 if( isDelete ){
22844 char pathUtf8[CCHMAXPATH];
22845 os2FullPathname( pVfs, zUtf8Name, CCHMAXPATH, pathUtf8 );
22846 pFile->pathToDel = convertUtf8PathToCp( pathUtf8 );
22847 }
22848
22849 zNameCp = convertUtf8PathToCp( zUtf8Name );
22850 rc = DosOpen( (PSZ)zNameCp,
22851 &h,
22852 &ulAction,
22853 0L,
22854 FILE_NORMAL,
22855 ulOpenFlags,
22856 ulOpenMode,
22857 (PEAOP2)NULL );
22858 free( zNameCp );
22859
22860 if( rc != NO_ERROR ){
22861 OSTRACE(( "OPEN Invalid handle rc=%d: zName=%s, ulAction=%#lx, ulFlags=%#lx, ulMode=%#lx\n",
22862 rc, zUtf8Name, ulAction, ulOpenFlags, ulOpenMode ));
22863 if( pFile->pathToDel )
22864 free( pFile->pathToDel );
22865 pFile->pathToDel = NULL;
22866
22867 if( isReadWrite ){
 
22868 return os2Open( pVfs, zName, id,
22869 ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)),
22870 pOutFlags );
22871 }else{
22872 return SQLITE_CANTOPEN;
22873 }
22874 }
22875
22876 if( pOutFlags ){
22877 *pOutFlags = isReadWrite ? SQLITE_OPEN_READWRITE : SQLITE_OPEN_READONLY;
22878 }
22879
 
22880 pFile->h = h;
22881 OpenCounter(+1);
22882 OSTRACE(( "OPEN %d pOutFlags=%d\n", pFile->h, pOutFlags ));
22883 return SQLITE_OK;
22884 }
@@ -22783,17 +22889,20 @@
22889 static int os2Delete(
22890 sqlite3_vfs *pVfs, /* Not used on os2 */
22891 const char *zFilename, /* Name of file to delete */
22892 int syncDir /* Not used on os2 */
22893 ){
22894 APIRET rc;
22895 char *zFilenameCp;
22896 SimulateIOError( return SQLITE_IOERR_DELETE );
22897 zFilenameCp = convertUtf8PathToCp( zFilename );
22898 rc = DosDelete( (PSZ)zFilenameCp );
22899 free( zFilenameCp );
22900 OSTRACE(( "DELETE \"%s\"\n", zFilename ));
22901 return (rc == NO_ERROR ||
22902 rc == ERROR_FILE_NOT_FOUND ||
22903 rc == ERROR_PATH_NOT_FOUND ) ? SQLITE_OK : SQLITE_IOERR_DELETE;
22904 }
22905
22906 /*
22907 ** Check the existance and status of a file.
22908 */
@@ -22854,11 +22963,11 @@
22963 ** os2Dlopen returns zero if DosLoadModule is not successful.
22964 */
22965 static void os2DlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
22966 /* no-op */
22967 }
22968 static void (*os2DlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
22969 PFN pfn;
22970 APIRET rc;
22971 rc = DosQueryProcAddr((HMODULE)pHandle, 0L, zSymbol, &pfn);
22972 if( rc != NO_ERROR ){
22973 /* if the symbol itself was not found, search again for the same
@@ -22866,11 +22975,11 @@
22975 * on the calling convention */
22976 char _zSymbol[256] = "_";
22977 strncat(_zSymbol, zSymbol, 255);
22978 rc = DosQueryProcAddr((HMODULE)pHandle, 0L, _zSymbol, &pfn);
22979 }
22980 return rc != NO_ERROR ? 0 : (void(*)(void))pfn;
22981 }
22982 static void os2DlClose(sqlite3_vfs *pVfs, void *pHandle){
22983 DosFreeModule((HMODULE)pHandle);
22984 }
22985 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
@@ -22970,14 +23079,15 @@
23079 ** return 0. Return 1 if the time and date cannot be found.
23080 */
23081 int os2CurrentTime( sqlite3_vfs *pVfs, double *prNow ){
23082 double now;
23083 SHORT minute; /* needs to be able to cope with negative timezone offset */
23084 USHORT hundredths, second, hour,
23085 day, month, year;
23086 DATETIME dt;
23087 DosGetDateTime( &dt );
23088 hundredths = (USHORT)dt.hundredths;
23089 second = (USHORT)dt.seconds;
23090 minute = (SHORT)dt.minutes + dt.timezone;
23091 hour = (USHORT)dt.hours;
23092 day = (USHORT)dt.day;
23093 month = (USHORT)dt.month;
@@ -22993,18 +23103,35 @@
23103
23104 /* Add the fractional hours, mins and seconds */
23105 now += (hour + 12.0)/24.0;
23106 now += minute/1440.0;
23107 now += second/86400.0;
23108 now += hundredths/8640000.0;
23109 *prNow = now;
23110 #ifdef SQLITE_TEST
23111 if( sqlite3_current_time ){
23112 *prNow = sqlite3_current_time/86400.0 + 2440587.5;
23113 }
23114 #endif
23115 return 0;
23116 }
23117
23118 /*
23119 ** Find the current time (in Universal Coordinated Time). Write into *piNow
23120 ** the current time and date as a Julian Day number times 86_400_000. In
23121 ** other words, write into *piNow the number of milliseconds since the Julian
23122 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
23123 ** proleptic Gregorian calendar.
23124 **
23125 ** On success, return 0. Return 1 if the time and date cannot be found.
23126 */
23127 static int os2CurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){
23128 double now;
23129 os2CurrentTime(pVfs, &now);
23130 *piNow = now * 86400000;
23131 return 0;
23132 }
23133
23134 static int os2GetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
23135 return 0;
23136 }
23137
@@ -23011,11 +23138,11 @@
23138 /*
23139 ** Initialize and deinitialize the operating system interface.
23140 */
23141 SQLITE_API int sqlite3_os_init(void){
23142 static sqlite3_vfs os2Vfs = {
23143 3, /* iVersion */
23144 sizeof(os2File), /* szOsFile */
23145 CCHMAXPATH, /* mxPathname */
23146 0, /* pNext */
23147 "os2", /* zName */
23148 0, /* pAppData */
@@ -23030,10 +23157,14 @@
23157 os2DlClose, /* xDlClose */
23158 os2Randomness, /* xRandomness */
23159 os2Sleep, /* xSleep */
23160 os2CurrentTime, /* xCurrentTime */
23161 os2GetLastError, /* xGetLastError */
23162 os2CurrentTimeInt64 /* xCurrentTimeInt64 */
23163 0, /* xSetSystemCall */
23164 0, /* xGetSystemCall */
23165 0, /* xNextSystemCall */
23166 };
23167 sqlite3_vfs_register(&os2Vfs, 1);
23168 initUconvObjects();
23169 return SQLITE_OK;
23170 }
@@ -23249,14 +23380,14 @@
23380 sqlite3_io_methods const *pMethod; /* Always the first entry */
23381 unixInodeInfo *pInode; /* Info about locks on this inode */
23382 int h; /* The file descriptor */
23383 int dirfd; /* File descriptor for the directory */
23384 unsigned char eFileLock; /* The type of lock held on this fd */
23385 unsigned char ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */
23386 int lastErrno; /* The unix errno from last I/O error */
23387 void *lockingContext; /* Locking style specific state */
23388 UnixUnusedFd *pUnused; /* Pre-allocated UnixUnusedFd */
 
23389 const char *zPath; /* Name of the file */
23390 unixShm *pShm; /* Shared memory segment information */
23391 int szChunk; /* Configured by FCNTL_CHUNK_SIZE */
23392 #if SQLITE_ENABLE_LOCKING_STYLE
23393 int openFlags; /* The flags specified at open() */
@@ -23287,13 +23418,14 @@
23418 char aPadding[32];
23419 #endif
23420 };
23421
23422 /*
23423 ** Allowed values for the unixFile.ctrlFlags bitmask:
23424 */
23425 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
23426 #define UNIXFILE_RDONLY 0x02 /* Connection is read only */
23427
23428 /*
23429 ** Include code that is common to all os_*.c files
23430 */
23431 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -23518,20 +23650,10 @@
23650 #endif
23651 #ifndef O_BINARY
23652 # define O_BINARY 0
23653 #endif
23654
 
 
 
 
 
 
 
 
 
 
23655 /*
23656 ** The threadid macro resolves to the thread-id or to 0. Used for
23657 ** testing and debugging only.
23658 */
23659 #if SQLITE_THREADSAFE
@@ -23538,10 +23660,197 @@
23660 #define threadid pthread_self()
23661 #else
23662 #define threadid 0
23663 #endif
23664
23665 /*
23666 ** Many system calls are accessed through pointer-to-functions so that
23667 ** they may be overridden at runtime to facilitate fault injection during
23668 ** testing and sandboxing. The following array holds the names and pointers
23669 ** to all overrideable system calls.
23670 */
23671 static struct unix_syscall {
23672 const char *zName; /* Name of the sytem call */
23673 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
23674 sqlite3_syscall_ptr pDefault; /* Default value */
23675 } aSyscall[] = {
23676 { "open", (sqlite3_syscall_ptr)open, 0 },
23677 #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
23678
23679 { "close", (sqlite3_syscall_ptr)close, 0 },
23680 #define osClose ((int(*)(int))aSyscall[1].pCurrent)
23681
23682 { "access", (sqlite3_syscall_ptr)access, 0 },
23683 #define osAccess ((int(*)(const char*,int))aSyscall[2].pCurrent)
23684
23685 { "getcwd", (sqlite3_syscall_ptr)getcwd, 0 },
23686 #define osGetcwd ((char*(*)(char*,size_t))aSyscall[3].pCurrent)
23687
23688 { "stat", (sqlite3_syscall_ptr)stat, 0 },
23689 #define osStat ((int(*)(const char*,struct stat*))aSyscall[4].pCurrent)
23690
23691 /*
23692 ** The DJGPP compiler environment looks mostly like Unix, but it
23693 ** lacks the fcntl() system call. So redefine fcntl() to be something
23694 ** that always succeeds. This means that locking does not occur under
23695 ** DJGPP. But it is DOS - what did you expect?
23696 */
23697 #ifdef __DJGPP__
23698 { "fstat", 0, 0 },
23699 #define osFstat(a,b,c) 0
23700 #else
23701 { "fstat", (sqlite3_syscall_ptr)fstat, 0 },
23702 #define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
23703 #endif
23704
23705 { "ftruncate", (sqlite3_syscall_ptr)ftruncate, 0 },
23706 #define osFtruncate ((int(*)(int,off_t))aSyscall[6].pCurrent)
23707
23708 { "fcntl", (sqlite3_syscall_ptr)fcntl, 0 },
23709 #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent)
23710
23711 { "read", (sqlite3_syscall_ptr)read, 0 },
23712 #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
23713
23714 #if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
23715 { "pread", (sqlite3_syscall_ptr)pread, 0 },
23716 #else
23717 { "pread", (sqlite3_syscall_ptr)0, 0 },
23718 #endif
23719 #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
23720
23721 #if defined(USE_PREAD64)
23722 { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
23723 #else
23724 { "pread64", (sqlite3_syscall_ptr)0, 0 },
23725 #endif
23726 #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
23727
23728 { "write", (sqlite3_syscall_ptr)write, 0 },
23729 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
23730
23731 #if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
23732 { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
23733 #else
23734 { "pwrite", (sqlite3_syscall_ptr)0, 0 },
23735 #endif
23736 #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\
23737 aSyscall[12].pCurrent)
23738
23739 #if defined(USE_PREAD64)
23740 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
23741 #else
23742 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
23743 #endif
23744 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
23745 aSyscall[13].pCurrent)
23746
23747 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
23748 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
23749
23750 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
23751 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
23752 #else
23753 { "fallocate", (sqlite3_syscall_ptr)0, 0 },
23754 #endif
23755 #define osFallocate ((int(*)(int,off_t,off_t)aSyscall[15].pCurrent)
23756
23757 }; /* End of the overrideable system calls */
23758
23759 /*
23760 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
23761 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the
23762 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
23763 ** system call named zName.
23764 */
23765 static int unixSetSystemCall(
23766 sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */
23767 const char *zName, /* Name of system call to override */
23768 sqlite3_syscall_ptr pNewFunc /* Pointer to new system call value */
23769 ){
23770 unsigned int i;
23771 int rc = SQLITE_NOTFOUND;
23772
23773 UNUSED_PARAMETER(pNotUsed);
23774 if( zName==0 ){
23775 /* If no zName is given, restore all system calls to their default
23776 ** settings and return NULL
23777 */
23778 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
23779 if( aSyscall[i].pDefault ){
23780 aSyscall[i].pCurrent = aSyscall[i].pDefault;
23781 rc = SQLITE_OK;
23782 }
23783 }
23784 }else{
23785 /* If zName is specified, operate on only the one system call
23786 ** specified.
23787 */
23788 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
23789 if( strcmp(zName, aSyscall[i].zName)==0 ){
23790 if( aSyscall[i].pDefault==0 ){
23791 aSyscall[i].pDefault = aSyscall[i].pCurrent;
23792 }
23793 rc = SQLITE_OK;
23794 if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault;
23795 aSyscall[i].pCurrent = pNewFunc;
23796 break;
23797 }
23798 }
23799 }
23800 return rc;
23801 }
23802
23803 /*
23804 ** Return the value of a system call. Return NULL if zName is not a
23805 ** recognized system call name. NULL is also returned if the system call
23806 ** is currently undefined.
23807 */
23808 static sqlite3_syscall_ptr unixGetSystemCall(
23809 sqlite3_vfs *pNotUsed,
23810 const char *zName
23811 ){
23812 unsigned int i;
23813
23814 UNUSED_PARAMETER(pNotUsed);
23815 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
23816 if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent;
23817 }
23818 return 0;
23819 }
23820
23821 /*
23822 ** Return the name of the first system call after zName. If zName==NULL
23823 ** then return the name of the first system call. Return NULL if zName
23824 ** is the last system call or if zName is not the name of a valid
23825 ** system call.
23826 */
23827 static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){
23828 unsigned int i;
23829
23830 UNUSED_PARAMETER(p);
23831 if( zName==0 ){
23832 i = -1;
23833 }else{
23834 for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0])-1; i++){
23835 if( strcmp(zName, aSyscall[0].zName)==0 ) break;
23836 }
23837 }
23838 for(i++; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
23839 if( aSyscall[0].pCurrent!=0 ) return aSyscall[0].zName;
23840 }
23841 return 0;
23842 }
23843
23844 /*
23845 ** Retry open() calls that fail due to EINTR
23846 */
23847 static int robust_open(const char *z, int f, int m){
23848 int rc;
23849 do{ rc = osOpen(z,f,m); }while( rc<0 && errno==EINTR );
23850 return rc;
23851 }
23852
23853 /*
23854 ** Helper functions to obtain and relinquish the global mutex. The
23855 ** global mutex is used to protect the unixInodeInfo and
23856 ** vxworksFileId objects used by this file, all of which may be
@@ -23602,11 +23911,11 @@
23911 if( op==F_GETLK ){
23912 zOpName = "GETLK";
23913 }else if( op==F_SETLK ){
23914 zOpName = "SETLK";
23915 }else{
23916 s = osFcntl(fd, op, p);
23917 sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s);
23918 return s;
23919 }
23920 if( p->l_type==F_RDLCK ){
23921 zType = "RDLCK";
@@ -23616,19 +23925,19 @@
23925 zType = "UNLCK";
23926 }else{
23927 assert( 0 );
23928 }
23929 assert( p->l_whence==SEEK_SET );
23930 s = osFcntl(fd, op, p);
23931 savedErrno = errno;
23932 sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n",
23933 threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len,
23934 (int)p->l_pid, s);
23935 if( s==(-1) && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){
23936 struct flock l2;
23937 l2 = *p;
23938 osFcntl(fd, F_GETLK, &l2);
23939 if( l2.l_type==F_RDLCK ){
23940 zType = "RDLCK";
23941 }else if( l2.l_type==F_WRLCK ){
23942 zType = "WRLCK";
23943 }else if( l2.l_type==F_UNLCK ){
@@ -23640,27 +23949,22 @@
23949 zType, (int)l2.l_start, (int)l2.l_len, (int)l2.l_pid);
23950 }
23951 errno = savedErrno;
23952 return s;
23953 }
23954 #undef osFcntl
23955 #define osFcntl lockTrace
23956 #endif /* SQLITE_LOCK_TRACE */
 
23957
23958 /*
23959 ** Retry ftruncate() calls that fail due to EINTR
23960 */
 
23961 static int robust_ftruncate(int h, sqlite3_int64 sz){
23962 int rc;
23963 do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR );
23964 return rc;
23965 }
 
 
 
 
23966
23967 /*
23968 ** This routine translates a standard POSIX errno code into something
23969 ** useful to the clients of the sqlite3 functions. Specifically, it is
23970 ** intended to translate a variety of "try again" errors into SQLITE_BUSY
@@ -23978,11 +24282,12 @@
24282 ** object keeps a count of the number of unixFile pointing to it.
24283 */
24284 struct unixInodeInfo {
24285 struct unixFileId fileId; /* The lookup key */
24286 int nShared; /* Number of SHARED locks held */
24287 unsigned char eFileLock; /* One of SHARED_LOCK, RESERVED_LOCK etc. */
24288 unsigned char bProcessLock; /* An exclusive process lock is held */
24289 int nRef; /* Number of pointers to this structure */
24290 unixShmNode *pShmNode; /* Shared memory associated with this inode */
24291 int nLock; /* Number of outstanding file locks */
24292 UnixUnusedFd *pUnused; /* Unused file descriptors to close */
24293 unixInodeInfo *pNext; /* List of all unixInodeInfo objects */
@@ -24083,11 +24388,11 @@
24388 ** file descriptor might have already been reused by another thread.
24389 ** So we don't even try to recover from an EINTR. Just log the error
24390 ** and move on.
24391 */
24392 static void robust_close(unixFile *pFile, int h, int lineno){
24393 if( osClose(h) ){
24394 unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
24395 pFile ? pFile->zPath : 0, lineno);
24396 }
24397 }
24398
@@ -24160,11 +24465,11 @@
24465
24466 /* Get low-level information about the file that we can used to
24467 ** create a unique name for the file.
24468 */
24469 fd = pFile->h;
24470 rc = osFstat(fd, &statbuf);
24471 if( rc!=0 ){
24472 pFile->lastErrno = errno;
24473 #ifdef EOVERFLOW
24474 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
24475 #endif
@@ -24181,16 +24486,16 @@
24486 ** in the header of every SQLite database. In this way, if there
24487 ** is a race condition such that another thread has already populated
24488 ** the first page of the database, no damage is done.
24489 */
24490 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
24491 do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
24492 if( rc!=1 ){
24493 pFile->lastErrno = errno;
24494 return SQLITE_IOERR;
24495 }
24496 rc = osFstat(fd, &statbuf);
24497 if( rc!=0 ){
24498 pFile->lastErrno = errno;
24499 return SQLITE_IOERR;
24500 }
24501 }
@@ -24249,17 +24554,17 @@
24554 }
24555
24556 /* Otherwise see if some other process holds it.
24557 */
24558 #ifndef __DJGPP__
24559 if( !reserved && !pFile->pInode->bProcessLock ){
24560 struct flock lock;
24561 lock.l_whence = SEEK_SET;
24562 lock.l_start = RESERVED_BYTE;
24563 lock.l_len = 1;
24564 lock.l_type = F_WRLCK;
24565 if (-1 == osFcntl(pFile->h, F_GETLK, &lock)) {
24566 int tErrno = errno;
24567 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK);
24568 pFile->lastErrno = tErrno;
24569 } else if( lock.l_type!=F_UNLCK ){
24570 reserved = 1;
@@ -24271,10 +24576,54 @@
24576 OSTRACE(("TEST WR-LOCK %d %d %d (unix)\n", pFile->h, rc, reserved));
24577
24578 *pResOut = reserved;
24579 return rc;
24580 }
24581
24582 /*
24583 ** Attempt to set a system-lock on the file pFile. The lock is
24584 ** described by pLock.
24585 **
24586 ** If the pFile was opened read/write from unix-excl, then the only lock
24587 ** ever obtained is an exclusive lock, and it is obtained exactly once
24588 ** the first time any lock is attempted. All subsequent system locking
24589 ** operations become no-ops. Locking operations still happen internally,
24590 ** in order to coordinate access between separate database connections
24591 ** within this process, but all of that is handled in memory and the
24592 ** operating system does not participate.
24593 **
24594 ** This function is a pass-through to fcntl(F_SETLK) if pFile is using
24595 ** any VFS other than "unix-excl" or if pFile is opened on "unix-excl"
24596 ** and is read-only.
24597 */
24598 static int unixFileLock(unixFile *pFile, struct flock *pLock){
24599 int rc;
24600 unixInodeInfo *pInode = pFile->pInode;
24601 assert( unixMutexHeld() );
24602 assert( pInode!=0 );
24603 if( ((pFile->ctrlFlags & UNIXFILE_EXCL)!=0 || pInode->bProcessLock)
24604 && ((pFile->ctrlFlags & UNIXFILE_RDONLY)==0)
24605 ){
24606 if( pInode->bProcessLock==0 ){
24607 struct flock lock;
24608 assert( pInode->nLock==0 );
24609 lock.l_whence = SEEK_SET;
24610 lock.l_start = SHARED_FIRST;
24611 lock.l_len = SHARED_SIZE;
24612 lock.l_type = F_WRLCK;
24613 rc = osFcntl(pFile->h, F_SETLK, &lock);
24614 if( rc<0 ) return rc;
24615 pInode->bProcessLock = 1;
24616 pInode->nLock++;
24617 }else{
24618 rc = 0;
24619 }
24620 }else{
24621 rc = osFcntl(pFile->h, F_SETLK, pLock);
24622 }
24623 return rc;
24624 }
24625
24626 /*
24627 ** Lock the file with the lock specified by parameter eFileLock - one
24628 ** of the following:
24629 **
@@ -24408,11 +24757,11 @@
24757 if( eFileLock==SHARED_LOCK
24758 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
24759 ){
24760 lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK);
24761 lock.l_start = PENDING_BYTE;
24762 s = unixFileLock(pFile, &lock);
24763 if( s==(-1) ){
24764 tErrno = errno;
24765 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
24766 if( IS_LOCK_ERROR(rc) ){
24767 pFile->lastErrno = tErrno;
@@ -24430,18 +24779,18 @@
24779 assert( pInode->eFileLock==0 );
24780
24781 /* Now get the read-lock */
24782 lock.l_start = SHARED_FIRST;
24783 lock.l_len = SHARED_SIZE;
24784 if( (s = unixFileLock(pFile, &lock))==(-1) ){
24785 tErrno = errno;
24786 }
24787 /* Drop the temporary PENDING lock */
24788 lock.l_start = PENDING_BYTE;
24789 lock.l_len = 1L;
24790 lock.l_type = F_UNLCK;
24791 if( unixFileLock(pFile, &lock)!=0 ){
24792 if( s != -1 ){
24793 /* This could happen with a network mount */
24794 tErrno = errno;
24795 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
24796 if( IS_LOCK_ERROR(rc) ){
@@ -24480,11 +24829,11 @@
24829 lock.l_len = SHARED_SIZE;
24830 break;
24831 default:
24832 assert(0);
24833 }
24834 s = unixFileLock(pFile, &lock);
24835 if( s==(-1) ){
24836 tErrno = errno;
24837 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
24838 if( IS_LOCK_ERROR(rc) ){
24839 pFile->lastErrno = tErrno;
@@ -24549,11 +24898,11 @@
24898 ** the byte range is divided into 2 parts and the first part is unlocked then
24899 ** set to a read lock, then the other part is simply unlocked. This works
24900 ** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to
24901 ** remove the write lock on a region when a read lock is set.
24902 */
24903 static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
24904 unixFile *pFile = (unixFile*)id;
24905 unixInodeInfo *pInode;
24906 struct flock lock;
24907 int rc = SQLITE_OK;
24908 int h;
@@ -24605,10 +24954,11 @@
24954 ** 4: [RRRR.]
24955 */
24956 if( eFileLock==SHARED_LOCK ){
24957
24958 #if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE
24959 (void)handleNFSUnlock;
24960 assert( handleNFSUnlock==0 );
24961 #endif
24962 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
24963 if( handleNFSUnlock ){
24964 off_t divSize = SHARED_SIZE - 1;
@@ -24615,11 +24965,11 @@
24965
24966 lock.l_type = F_UNLCK;
24967 lock.l_whence = SEEK_SET;
24968 lock.l_start = SHARED_FIRST;
24969 lock.l_len = divSize;
24970 if( unixFileLock(pFile,, &lock)==(-1) ){
24971 tErrno = errno;
24972 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
24973 if( IS_LOCK_ERROR(rc) ){
24974 pFile->lastErrno = tErrno;
24975 }
@@ -24627,11 +24977,11 @@
24977 }
24978 lock.l_type = F_RDLCK;
24979 lock.l_whence = SEEK_SET;
24980 lock.l_start = SHARED_FIRST;
24981 lock.l_len = divSize;
24982 if( unixFileLock(pFile, &lock)==(-1) ){
24983 tErrno = errno;
24984 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
24985 if( IS_LOCK_ERROR(rc) ){
24986 pFile->lastErrno = tErrno;
24987 }
@@ -24639,11 +24989,11 @@
24989 }
24990 lock.l_type = F_UNLCK;
24991 lock.l_whence = SEEK_SET;
24992 lock.l_start = SHARED_FIRST+divSize;
24993 lock.l_len = SHARED_SIZE-divSize;
24994 if( unixFileLock(pFile, &lock)==(-1) ){
24995 tErrno = errno;
24996 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
24997 if( IS_LOCK_ERROR(rc) ){
24998 pFile->lastErrno = tErrno;
24999 }
@@ -24654,11 +25004,11 @@
25004 {
25005 lock.l_type = F_RDLCK;
25006 lock.l_whence = SEEK_SET;
25007 lock.l_start = SHARED_FIRST;
25008 lock.l_len = SHARED_SIZE;
25009 if( unixFileLock(pFile, &lock)==(-1) ){
25010 tErrno = errno;
25011 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
25012 if( IS_LOCK_ERROR(rc) ){
25013 pFile->lastErrno = tErrno;
25014 }
@@ -24668,11 +25018,11 @@
25018 }
25019 lock.l_type = F_UNLCK;
25020 lock.l_whence = SEEK_SET;
25021 lock.l_start = PENDING_BYTE;
25022 lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
25023 if( unixFileLock(pFile, &lock)!=(-1) ){
25024 pInode->eFileLock = SHARED_LOCK;
25025 }else{
25026 tErrno = errno;
25027 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
25028 if( IS_LOCK_ERROR(rc) ){
@@ -24692,11 +25042,11 @@
25042 lock.l_whence = SEEK_SET;
25043 lock.l_start = lock.l_len = 0L;
25044 SimulateIOErrorBenign(1);
25045 SimulateIOError( h=(-1) )
25046 SimulateIOErrorBenign(0);
25047 if( unixFileLock(pFile, &lock)!=(-1) ){
25048 pInode->eFileLock = NO_LOCK;
25049 }else{
25050 tErrno = errno;
25051 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
25052 if( IS_LOCK_ERROR(rc) ){
@@ -24730,11 +25080,11 @@
25080 **
25081 ** If the locking level of the file descriptor is already at or below
25082 ** the requested locking level, this routine is a no-op.
25083 */
25084 static int unixUnlock(sqlite3_file *id, int eFileLock){
25085 return posixUnlock(id, eFileLock, 0);
25086 }
25087
25088 /*
25089 ** This function performs the parts of the "close file" operation
25090 ** common to all locking schemes. It closes the directory and file
@@ -24780,10 +25130,12 @@
25130 int rc = SQLITE_OK;
25131 if( id ){
25132 unixFile *pFile = (unixFile *)id;
25133 unixUnlock(id, NO_LOCK);
25134 unixEnterMutex();
25135 assert( pFile->pInode==0 || pFile->pInode->nLock>0
25136 || pFile->pInode->bProcessLock==0 );
25137 if( pFile->pInode && pFile->pInode->nLock ){
25138 /* If there are outstanding locks, do not actually close the file just
25139 ** yet because that would clear those locks. Instead, add the file
25140 ** descriptor to pInode->pUnused list. It will be automatically closed
25141 ** when the last lock is cleared.
@@ -24894,11 +25246,11 @@
25246 ** holds a lock on the file. No need to check further. */
25247 reserved = 1;
25248 }else{
25249 /* The lock is held if and only if the lockfile exists */
25250 const char *zLockFile = (const char*)pFile->lockingContext;
25251 reserved = osAccess(zLockFile, 0)==0;
25252 }
25253 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
25254 *pResOut = reserved;
25255 return rc;
25256 }
@@ -24948,11 +25300,11 @@
25300 #endif
25301 return SQLITE_OK;
25302 }
25303
25304 /* grab an exclusive lock */
25305 fd = robust_open(zLockFile,O_RDONLY|O_CREAT|O_EXCL,0600);
25306 if( fd<0 ){
25307 /* failed to open/create the file, someone else may have stolen the lock */
25308 int tErrno = errno;
25309 if( EEXIST == tErrno ){
25310 rc = SQLITE_BUSY;
@@ -25911,11 +26263,11 @@
26263 **
26264 ** If the locking level of the file descriptor is already at or below
26265 ** the requested locking level, this routine is a no-op.
26266 */
26267 static int nfsUnlock(sqlite3_file *id, int eFileLock){
26268 return posixUnlock(id, eFileLock, 1);
26269 }
26270
26271 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
26272 /*
26273 ** The code above is the NFS lock implementation. The code is specific
@@ -25953,14 +26305,14 @@
26305 #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
26306 i64 newOffset;
26307 #endif
26308 TIMER_START;
26309 #if defined(USE_PREAD)
26310 do{ got = osPread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26311 SimulateIOError( got = -1 );
26312 #elif defined(USE_PREAD64)
26313 do{ got = osPread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR);
26314 SimulateIOError( got = -1 );
26315 #else
26316 newOffset = lseek(id->h, offset, SEEK_SET);
26317 SimulateIOError( newOffset-- );
26318 if( newOffset!=offset ){
@@ -25969,11 +26321,11 @@
26321 }else{
26322 ((unixFile*)id)->lastErrno = 0;
26323 }
26324 return -1;
26325 }
26326 do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
26327 #endif
26328 TIMER_END;
26329 if( got<0 ){
26330 ((unixFile*)id)->lastErrno = errno;
26331 }
@@ -26031,13 +26383,13 @@
26383 #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
26384 i64 newOffset;
26385 #endif
26386 TIMER_START;
26387 #if defined(USE_PREAD)
26388 do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26389 #elif defined(USE_PREAD64)
26390 do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR);
26391 #else
26392 newOffset = lseek(id->h, offset, SEEK_SET);
26393 if( newOffset!=offset ){
26394 if( newOffset == -1 ){
26395 ((unixFile*)id)->lastErrno = errno;
@@ -26044,11 +26396,11 @@
26396 }else{
26397 ((unixFile*)id)->lastErrno = 0;
26398 }
26399 return -1;
26400 }
26401 do{ got = osWrite(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
26402 #endif
26403 TIMER_END;
26404 if( got<0 ){
26405 ((unixFile*)id)->lastErrno = errno;
26406 }
@@ -26212,11 +26564,11 @@
26564 */
26565 #ifdef SQLITE_NO_SYNC
26566 rc = SQLITE_OK;
26567 #elif HAVE_FULLFSYNC
26568 if( fullSync ){
26569 rc = osFcntl(fd, F_FULLFSYNC, 0);
26570 }else{
26571 rc = 1;
26572 }
26573 /* If the FULLFSYNC failed, fall back to attempting an fsync().
26574 ** It shouldn't be possible for fullfsync to fail on the local
@@ -26359,11 +26711,11 @@
26711 */
26712 static int unixFileSize(sqlite3_file *id, i64 *pSize){
26713 int rc;
26714 struct stat buf;
26715 assert( id );
26716 rc = osFstat(((unixFile*)id)->h, &buf);
26717 SimulateIOError( rc=1 );
26718 if( rc!=0 ){
26719 ((unixFile*)id)->lastErrno = errno;
26720 return SQLITE_IOERR_FSTAT;
26721 }
@@ -26400,18 +26752,18 @@
26752 static int fcntlSizeHint(unixFile *pFile, i64 nByte){
26753 if( pFile->szChunk ){
26754 i64 nSize; /* Required file size */
26755 struct stat buf; /* Used to hold return values of fstat() */
26756
26757 if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
26758
26759 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
26760 if( nSize>(i64)buf.st_size ){
26761 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
26762 int rc;
26763 do{
26764 rc = osFallocate(pFile->.h, buf.st_size, nSize-buf.st_size;
26765 }while( rc<0 && errno=EINTR );
26766 if( rc ) return SQLITE_IOERR_WRITE;
26767 #else
26768 /* If the OS does not have posix_fallocate(), fake it. First use
26769 ** ftruncate() to set the file size, then write a single byte to
@@ -26608,19 +26960,21 @@
26960 assert( n==1 || lockType!=F_RDLCK );
26961
26962 /* Locks are within range */
26963 assert( n>=1 && n<SQLITE_SHM_NLOCK );
26964
26965 if( pShmNode->h>=0 ){
26966 /* Initialize the locking parameters */
26967 memset(&f, 0, sizeof(f));
26968 f.l_type = lockType;
26969 f.l_whence = SEEK_SET;
26970 f.l_start = ofst;
26971 f.l_len = n;
26972
26973 rc = osFcntl(pShmNode->h, F_SETLK, &f);
26974 rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
26975 }
26976
26977 /* Update the global lock state and do debug tracing */
26978 #ifdef SQLITE_DEBUG
26979 { u16 mask;
26980 OSTRACE(("SHM-LOCK "));
@@ -26671,11 +27025,15 @@
27025 if( p && p->nRef==0 ){
27026 int i;
27027 assert( p->pInode==pFd->pInode );
27028 if( p->mutex ) sqlite3_mutex_free(p->mutex);
27029 for(i=0; i<p->nRegion; i++){
27030 if( p->h>=0 ){
27031 munmap(p->apRegion[i], p->szRegion);
27032 }else{
27033 sqlite3_free(p->apRegion[i]);
27034 }
27035 }
27036 sqlite3_free(p->apRegion);
27037 if( p->h>=0 ){
27038 robust_close(pFd, p->h, __LINE__);
27039 p->h = -1;
@@ -26711,10 +27069,16 @@
27069 ** "unsupported" and may go away in a future SQLite release.
27070 **
27071 ** When opening a new shared-memory file, if no other instances of that
27072 ** file are currently open, in this process or in other processes, then
27073 ** the file must be truncated to zero length or have its header cleared.
27074 **
27075 ** If the original database file (pDbFd) is using the "unix-excl" VFS
27076 ** that means that an exclusive lock is held on the database file and
27077 ** that no other processes are able to read or write the database. In
27078 ** that case, we do not really need shared memory. No shared memory
27079 ** file is created. The shared memory will be simulated with heap memory.
27080 */
27081 static int unixOpenSharedMemory(unixFile *pDbFd){
27082 struct unixShm *p = 0; /* The connection to be opened */
27083 struct unixShmNode *pShmNode; /* The underlying mmapped file */
27084 int rc; /* Result code */
@@ -26740,11 +27104,11 @@
27104 /* Call fstat() to figure out the permissions on the database file. If
27105 ** a new *-shm file is created, an attempt will be made to create it
27106 ** with the same permissions. The actual permissions the file is created
27107 ** with are subject to the current umask setting.
27108 */
27109 if( osFstat(pDbFd->h, &sStat) && pInode->bProcessLock==0 ){
27110 rc = SQLITE_IOERR_FSTAT;
27111 goto shm_open_err;
27112 }
27113
27114 #ifdef SQLITE_SHM_DIRECTORY
@@ -26773,29 +27137,32 @@
27137 if( pShmNode->mutex==0 ){
27138 rc = SQLITE_NOMEM;
27139 goto shm_open_err;
27140 }
27141
27142 if( pInode->bProcessLock==0 ){
27143 pShmNode->h = robust_open(zShmFilename, O_RDWR|O_CREAT,
27144 (sStat.st_mode & 0777));
27145 if( pShmNode->h<0 ){
27146 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
27147 goto shm_open_err;
27148 }
27149
27150 /* Check to see if another process is holding the dead-man switch.
27151 ** If not, truncate the file to zero length.
27152 */
27153 rc = SQLITE_OK;
27154 if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
27155 if( robust_ftruncate(pShmNode->h, 0) ){
27156 rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
27157 }
27158 }
27159 if( rc==SQLITE_OK ){
27160 rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1);
27161 }
27162 if( rc ) goto shm_open_err;
27163 }
27164 }
27165
27166 /* Make the new connection a child of the unixShmNode */
27167 p->pShmNode = pShmNode;
27168 #ifdef SQLITE_DEBUG
@@ -26865,38 +27232,44 @@
27232
27233 p = pDbFd->pShm;
27234 pShmNode = p->pShmNode;
27235 sqlite3_mutex_enter(pShmNode->mutex);
27236 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
27237 assert( pShmNode->pInode==pDbFd->pInode );
27238 assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 );
27239 assert( pShmNode->h<0 || pDbFd->pInode->bProcessLock==0 );
27240
27241 if( pShmNode->nRegion<=iRegion ){
27242 char **apNew; /* New apRegion[] array */
27243 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
27244 struct stat sStat; /* Used by fstat() */
27245
27246 pShmNode->szRegion = szRegion;
27247
27248 if( pShmNode->h>=0 ){
27249 /* The requested region is not mapped into this processes address space.
27250 ** Check to see if it has been allocated (i.e. if the wal-index file is
27251 ** large enough to contain the requested region).
27252 */
27253 if( osFstat(pShmNode->h, &sStat) ){
27254 rc = SQLITE_IOERR_SHMSIZE;
27255 goto shmpage_out;
27256 }
27257
27258 if( sStat.st_size<nByte ){
27259 /* The requested memory region does not exist. If bExtend is set to
27260 ** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
27261 **
27262 ** Alternatively, if bExtend is true, use ftruncate() to allocate
27263 ** the requested memory region.
27264 */
27265 if( !bExtend ) goto shmpage_out;
27266 if( robust_ftruncate(pShmNode->h, nByte) ){
27267 rc = unixLogError(SQLITE_IOERR_SHMSIZE, "ftruncate",
27268 pShmNode->zFilename);
27269 goto shmpage_out;
27270 }
27271 }
27272 }
27273
27274 /* Map the requested memory region into this processes address space. */
27275 apNew = (char **)sqlite3_realloc(
@@ -26906,16 +27279,26 @@
27279 rc = SQLITE_IOERR_NOMEM;
27280 goto shmpage_out;
27281 }
27282 pShmNode->apRegion = apNew;
27283 while(pShmNode->nRegion<=iRegion){
27284 void *pMem;
27285 if( pShmNode->h>=0 ){
27286 pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE,
27287 MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion
27288 );
27289 if( pMem==MAP_FAILED ){
27290 rc = SQLITE_IOERR;
27291 goto shmpage_out;
27292 }
27293 }else{
27294 pMem = sqlite3_malloc(szRegion);
27295 if( pMem==0 ){
27296 rc = SQLITE_NOMEM;
27297 goto shmpage_out;
27298 }
27299 memset(pMem, 0, szRegion);
27300 }
27301 pShmNode->apRegion[pShmNode->nRegion] = pMem;
27302 pShmNode->nRegion++;
27303 }
27304 }
@@ -26958,10 +27341,12 @@
27341 assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
27342 || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
27343 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
27344 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
27345 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
27346 assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 );
27347 assert( pShmNode->h<0 || pDbFd->pInode->bProcessLock==0 );
27348
27349 mask = (1<<(ofst+n)) - (1<<ofst);
27350 assert( n>1 || mask==(1<<ofst) );
27351 sqlite3_mutex_enter(pShmNode->mutex);
27352 if( flags & SQLITE_SHM_UNLOCK ){
@@ -27095,11 +27480,11 @@
27480 ** shared-memory file, too */
27481 unixEnterMutex();
27482 assert( pShmNode->nRef>0 );
27483 pShmNode->nRef--;
27484 if( pShmNode->nRef==0 ){
27485 if( deleteFlag && pShmNode->h>=0 ) unlink(pShmNode->zFilename);
27486 unixShmPurge(pDbFd);
27487 }
27488 unixLeaveMutex();
27489
27490 return SQLITE_OK;
@@ -27336,11 +27721,11 @@
27721 */
27722 lockInfo.l_len = 1;
27723 lockInfo.l_start = 0;
27724 lockInfo.l_whence = SEEK_SET;
27725 lockInfo.l_type = F_RDLCK;
27726 if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
27727 if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){
27728 return &nfsIoMethods;
27729 } else {
27730 return &posixIoMethods;
27731 }
@@ -27378,11 +27763,11 @@
27763 */
27764 lockInfo.l_len = 1;
27765 lockInfo.l_start = 0;
27766 lockInfo.l_whence = SEEK_SET;
27767 lockInfo.l_type = F_RDLCK;
27768 if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
27769 return &posixIoMethods;
27770 }else{
27771 return &semIoMethods;
27772 }
27773 }
@@ -27412,11 +27797,12 @@
27797 int h, /* Open file descriptor of file being opened */
27798 int dirfd, /* Directory file descriptor */
27799 sqlite3_file *pId, /* Write to the unixFile structure here */
27800 const char *zFilename, /* Name of the file being opened */
27801 int noLock, /* Omit locking if true */
27802 int isDelete, /* Delete on close if true */
27803 int isReadOnly /* True if the file is opened read-only */
27804 ){
27805 const sqlite3_io_methods *pLockingStyle;
27806 unixFile *pNew = (unixFile *)pId;
27807 int rc = SQLITE_OK;
27808
@@ -27439,12 +27825,19 @@
27825 #endif
27826
27827 OSTRACE(("OPEN %-3d %s\n", h, zFilename));
27828 pNew->h = h;
27829 pNew->dirfd = dirfd;
 
27830 pNew->zPath = zFilename;
27831 if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
27832 pNew->ctrlFlags = UNIXFILE_EXCL;
27833 }else{
27834 pNew->ctrlFlags = 0;
27835 }
27836 if( isReadOnly ){
27837 pNew->ctrlFlags |= UNIXFILE_RDONLY;
27838 }
27839
27840 #if OS_VXWORKS
27841 pNew->pId = vxworksFindFileId(zFilename);
27842 if( pNew->pId==0 ){
27843 noLock = 1;
@@ -27601,14 +27994,14 @@
27994
27995 sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename);
27996 for(ii=(int)strlen(zDirname); ii>1 && zDirname[ii]!='/'; ii--);
27997 if( ii>0 ){
27998 zDirname[ii] = '\0';
27999 fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0);
28000 if( fd>=0 ){
28001 #ifdef FD_CLOEXEC
28002 osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
28003 #endif
28004 OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
28005 }
28006 }
28007 *pFd = fd;
@@ -27634,13 +28027,13 @@
28027
28028 azDirs[0] = sqlite3_temp_directory;
28029 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
28030 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
28031 if( zDir==0 ) continue;
28032 if( osStat(zDir, &buf) ) continue;
28033 if( !S_ISDIR(buf.st_mode) ) continue;
28034 if( osAccess(zDir, 07) ) continue;
28035 break;
28036 }
28037 return zDir;
28038 }
28039
@@ -27679,11 +28072,11 @@
28072 sqlite3_randomness(15, &zBuf[j]);
28073 for(i=0; i<15; i++, j++){
28074 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
28075 }
28076 zBuf[j] = 0;
28077 }while( osAccess(zBuf,0)==0 );
28078 return SQLITE_OK;
28079 }
28080
28081 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
28082 /*
@@ -27940,19 +28333,20 @@
28333 if( rc!=SQLITE_OK ){
28334 assert( !p->pUnused );
28335 assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
28336 return rc;
28337 }
28338 fd = robust_open(zName, openFlags, openMode);
28339 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
28340 if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){
28341 /* Failed to open the file for read/write access. Try read-only. */
28342 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
28343 openFlags &= ~(O_RDWR|O_CREAT);
28344 flags |= SQLITE_OPEN_READONLY;
28345 openFlags |= O_RDONLY;
28346 isReadonly = 1;
28347 fd = robust_open(zName, openFlags, openMode);
28348 }
28349 if( fd<0 ){
28350 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
28351 goto open_finished;
28352 }
@@ -27992,11 +28386,11 @@
28386 goto open_finished;
28387 }
28388 }
28389
28390 #ifdef FD_CLOEXEC
28391 osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
28392 #endif
28393
28394 noLock = eType!=SQLITE_OPEN_MAIN_DB;
28395
28396
@@ -28044,11 +28438,12 @@
28438 goto open_finished;
28439 }
28440 useProxy = !(fsInfo.f_flags&MNT_LOCAL);
28441 }
28442 if( useProxy ){
28443 rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock,
28444 isDelete, isReadonly);
28445 if( rc==SQLITE_OK ){
28446 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
28447 if( rc!=SQLITE_OK ){
28448 /* Use unixClose to clean up the resources added in fillInUnixFile
28449 ** and clear all the structure's references. Specifically,
@@ -28061,11 +28456,12 @@
28456 goto open_finished;
28457 }
28458 }
28459 #endif
28460
28461 rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock,
28462 isDelete, isReadonly);
28463 open_finished:
28464 if( rc!=SQLITE_OK ){
28465 sqlite3_free(p->pUnused);
28466 }
28467 return rc;
@@ -28138,11 +28534,11 @@
28534 break;
28535
28536 default:
28537 assert(!"Invalid flags argument");
28538 }
28539 *pResOut = (osAccess(zPath, amode)==0);
28540 if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){
28541 struct stat buf;
28542 if( 0==stat(zPath, &buf) && buf.st_size==0 ){
28543 *pResOut = 0;
28544 }
@@ -28180,11 +28576,11 @@
28576 zOut[nOut-1] = '\0';
28577 if( zPath[0]=='/' ){
28578 sqlite3_snprintf(nOut, zOut, "%s", zPath);
28579 }else{
28580 int nCwd;
28581 if( osGetcwd(zOut, nOut-1)==0 ){
28582 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
28583 }
28584 nCwd = (int)strlen(zOut);
28585 sqlite3_snprintf(nOut-nCwd, &zOut[nCwd], "/%s", zPath);
28586 }
@@ -28275,21 +28671,21 @@
28671 */
28672 memset(zBuf, 0, nBuf);
28673 #if !defined(SQLITE_TEST)
28674 {
28675 int pid, fd;
28676 fd = robust_open("/dev/urandom", O_RDONLY, 0);
28677 if( fd<0 ){
28678 time_t t;
28679 time(&t);
28680 memcpy(zBuf, &t, sizeof(t));
28681 pid = getpid();
28682 memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
28683 assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
28684 nBuf = sizeof(t) + sizeof(pid);
28685 }else{
28686 do{ nBuf = osRead(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
28687 robust_close(0, fd, __LINE__);
28688 }
28689 }
28690 #endif
28691 return nBuf;
@@ -28684,21 +29080,21 @@
29080 if( !pUnused ){
29081 return SQLITE_NOMEM;
29082 }
29083 }
29084 if( fd<0 ){
29085 fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
29086 terrno = errno;
29087 if( fd<0 && errno==ENOENT && islockfile ){
29088 if( proxyCreateLockPath(path) == SQLITE_OK ){
29089 fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
29090 }
29091 }
29092 }
29093 if( fd<0 ){
29094 openFlags = O_RDONLY;
29095 fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
29096 terrno = errno;
29097 }
29098 if( fd<0 ){
29099 if( islockfile ){
29100 return SQLITE_BUSY;
@@ -28723,11 +29119,11 @@
29119 dummyVfs.pAppData = (void*)&autolockIoFinder;
29120 pUnused->fd = fd;
29121 pUnused->flags = openFlags;
29122 pNew->pUnused = pUnused;
29123
29124 rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0, 0);
29125 if( rc==SQLITE_OK ){
29126 *ppFile = pNew;
29127 return SQLITE_OK;
29128 }
29129 end_create_proxy:
@@ -28808,22 +29204,23 @@
29204 (strlcpy(&tPath[pathLen-5], "break", 6) != 5) ){
29205 sqlite3_snprintf(sizeof(errmsg),errmsg,"path error (len %d)",(int)pathLen);
29206 goto end_breaklock;
29207 }
29208 /* read the conch content */
29209 readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
29210 if( readLen<PROXY_PATHINDEX ){
29211 sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
29212 goto end_breaklock;
29213 }
29214 /* write it out to the temporary break file */
29215 fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL),
29216 SQLITE_DEFAULT_FILE_PERMISSIONS);
29217 if( fd<0 ){
29218 sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
29219 goto end_breaklock;
29220 }
29221 if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
29222 sqlite3_snprintf(sizeof(errmsg), errmsg, "write failed (%d)", errno);
29223 goto end_breaklock;
29224 }
29225 if( rename(tPath, cPath) ){
29226 sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno);
@@ -28865,11 +29262,11 @@
29262 * 2nd try: fail if the mod time changed or host id is different, wait
29263 * 10 sec and try again
29264 * 3rd try: break the lock unless the mod time has changed.
29265 */
29266 struct stat buf;
29267 if( osFstat(conchFile->h, &buf) ){
29268 pFile->lastErrno = errno;
29269 return SQLITE_IOERR_LOCK;
29270 }
29271
29272 if( nTries==1 ){
@@ -28884,11 +29281,11 @@
29281 return SQLITE_BUSY;
29282 }
29283
29284 if( nTries==2 ){
29285 char tBuf[PROXY_MAXCONCHLEN];
29286 int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
29287 if( len<0 ){
29288 pFile->lastErrno = errno;
29289 return SQLITE_IOERR_LOCK;
29290 }
29291 if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){
@@ -29054,20 +29451,20 @@
29451 /* If we created a new conch file (not just updated the contents of a
29452 ** valid conch file), try to match the permissions of the database
29453 */
29454 if( rc==SQLITE_OK && createConch ){
29455 struct stat buf;
29456 int err = osFstat(pFile->h, &buf);
29457 if( err==0 ){
29458 mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
29459 S_IROTH|S_IWOTH);
29460 /* try to match the database file R/W permissions, ignore failure */
29461 #ifndef SQLITE_PROXY_DEBUG
29462 osFchmod(conchFile->h, cmode);
29463 #else
29464 do{
29465 rc = osFchmod(conchFile->h, cmode);
29466 }while( rc==(-1) && errno==EINTR );
29467 if( rc!=0 ){
29468 int code = errno;
29469 fprintf(stderr, "fchmod %o FAILED with %d %s\n",
29470 cmode, code, strerror(code));
@@ -29089,11 +29486,11 @@
29486 if( rc==SQLITE_OK && pFile->openFlags ){
29487 if( pFile->h>=0 ){
29488 robust_close(pFile, pFile->h, __LINE__);
29489 }
29490 pFile->h = -1;
29491 int fd = robust_open(pCtx->dbPath, pFile->openFlags,
29492 SQLITE_DEFAULT_FILE_PERMISSIONS);
29493 OSTRACE(("TRANSPROXY: OPEN %d\n", fd));
29494 if( fd>=0 ){
29495 pFile->h = fd;
29496 }else{
@@ -29315,11 +29712,11 @@
29712 */
29713 struct statfs fsInfo;
29714 struct stat conchInfo;
29715 int goLockless = 0;
29716
29717 if( osStat(pCtx->conchFilePath, &conchInfo) == -1 ) {
29718 int err = errno;
29719 if( (err==ENOENT) && (statfs(dbPath, &fsInfo) != -1) ){
29720 goLockless = (fsInfo.f_flags&MNT_RDONLY) == MNT_RDONLY;
29721 }
29722 }
@@ -29600,11 +29997,11 @@
29997 ** more than that; it looks at the filesystem type that hosts the
29998 ** database file and tries to choose an locking method appropriate for
29999 ** that filesystem time.
30000 */
30001 #define UNIXVFS(VFSNAME, FINDER) { \
30002 3, /* iVersion */ \
30003 sizeof(unixFile), /* szOsFile */ \
30004 MAX_PATHNAME, /* mxPathname */ \
30005 0, /* pNext */ \
30006 VFSNAME, /* zName */ \
30007 (void*)&FINDER, /* pAppData */ \
@@ -29619,10 +30016,13 @@
30016 unixRandomness, /* xRandomness */ \
30017 unixSleep, /* xSleep */ \
30018 unixCurrentTime, /* xCurrentTime */ \
30019 unixGetLastError, /* xGetLastError */ \
30020 unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
30021 unixSetSystemCall, /* xSetSystemCall */ \
30022 unixGetSystemCall, /* xGetSystemCall */ \
30023 unixNextSystemCall, /* xNextSystemCall */ \
30024 }
30025
30026 /*
30027 ** All default VFSes for unix are contained in the following array.
30028 **
@@ -29636,10 +30036,11 @@
30036 #else
30037 UNIXVFS("unix", posixIoFinder ),
30038 #endif
30039 UNIXVFS("unix-none", nolockIoFinder ),
30040 UNIXVFS("unix-dotfile", dotlockIoFinder ),
30041 UNIXVFS("unix-excl", posixIoFinder ),
30042 #if OS_VXWORKS
30043 UNIXVFS("unix-namedsem", semIoFinder ),
30044 #endif
30045 #if SQLITE_ENABLE_LOCKING_STYLE
30046 UNIXVFS("unix-posix", posixIoFinder ),
@@ -32626,11 +33027,11 @@
33027 /*
33028 ** Initialize and deinitialize the operating system interface.
33029 */
33030 SQLITE_API int sqlite3_os_init(void){
33031 static sqlite3_vfs winVfs = {
33032 3, /* iVersion */
33033 sizeof(winFile), /* szOsFile */
33034 MAX_PATH, /* mxPathname */
33035 0, /* pNext */
33036 "win32", /* zName */
33037 0, /* pAppData */
@@ -32645,10 +33046,13 @@
33046 winRandomness, /* xRandomness */
33047 winSleep, /* xSleep */
33048 winCurrentTime, /* xCurrentTime */
33049 winGetLastError, /* xGetLastError */
33050 winCurrentTimeInt64, /* xCurrentTimeInt64 */
33051 0, /* xSetSystemCall */
33052 0, /* xGetSystemCall */
33053 0, /* xNextSystemCall */
33054 };
33055
33056 #ifndef SQLITE_OMIT_WAL
33057 /* get memory map allocation granularity */
33058 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
@@ -50782,15 +51186,13 @@
51186 }
51187 if( nearby>0 ){
51188 u32 i;
51189 int dist;
51190 closest = 0;
51191 dist = sqlite3AbsInt32(get4byte(&aData[8]) - nearby);
 
51192 for(i=1; i<k; i++){
51193 int d2 = sqlite3AbsInt32(get4byte(&aData[8+i*4]) - nearby);
 
51194 if( d2<dist ){
51195 closest = i;
51196 dist = d2;
51197 }
51198 }
@@ -55777,13 +56179,18 @@
56179 }
56180 }else if( op==TK_UMINUS ) {
56181 /* This branch happens for multiple negative signs. Ex: -(-5) */
56182 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
56183 sqlite3VdbeMemNumerify(pVal);
56184 if( pVal->u.i==SMALLEST_INT64 ){
56185 pVal->flags &= MEM_Int;
56186 pVal->flags |= MEM_Real;
56187 pVal->r = (double)LARGEST_INT64;
56188 }else{
56189 pVal->u.i = -pVal->u.i;
56190 }
56191 pVal->r = -pVal->r;
56192 sqlite3ValueApplyAffinity(pVal, affinity, enc);
56193 }
56194 }else if( op==TK_NULL ){
56195 pVal = sqlite3ValueNew(db);
56196 if( pVal==0 ) goto no_mem;
@@ -56805,12 +57212,12 @@
57212 ** will be used so that it can acquire mutexes on them all in sorted
57213 ** order (via sqlite3VdbeMutexArrayEnter(). Mutexes are acquired
57214 ** in order (and released in reverse order) to avoid deadlocks.
57215 */
57216 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){
57217 tAttachMask mask;
57218 assert( i>=0 && i<p->db->nDb && i<sizeof(tAttachMask)*8 );
57219 assert( i<(int)sizeof(p->btreeMask)*8 );
57220 mask = ((u32)1)<<i;
57221 if( (p->btreeMask & mask)==0 ){
57222 p->btreeMask |= mask;
57223 sqlite3BtreeMutexArrayInsert(&p->aMutex, p->db->aDb[i].pBt);
@@ -61309,10 +61716,11 @@
61716 struct OP_SetCookie_stack_vars {
61717 Db *pDb;
61718 } au;
61719 struct OP_VerifyCookie_stack_vars {
61720 int iMeta;
61721 int iGen;
61722 Btree *pBt;
61723 } av;
61724 struct OP_OpenWrite_stack_vars {
61725 int nField;
61726 KeyInfo *pKeyInfo;
@@ -63931,14 +64339,16 @@
64339 p->expired = 0;
64340 }
64341 break;
64342 }
64343
64344 /* Opcode: VerifyCookie P1 P2 P3 * *
64345 **
64346 ** Check the value of global database parameter number 0 (the
64347 ** schema version) and make sure it is equal to P2 and that the
64348 ** generation counter on the local schema parse equals P3.
64349 **
64350 ** P1 is the database number which is 0 for the main database file
64351 ** and 1 for the file holding temporary tables and some higher number
64352 ** for auxiliary databases.
64353 **
64354 ** The cookie changes its value whenever the database schema changes.
@@ -63950,21 +64360,24 @@
64360 ** invoked.
64361 */
64362 case OP_VerifyCookie: {
64363 #if 0 /* local variables moved into u.av */
64364 int iMeta;
64365 int iGen;
64366 Btree *pBt;
64367 #endif /* local variables moved into u.av */
64368
64369 assert( pOp->p1>=0 && pOp->p1<db->nDb );
64370 assert( (p->btreeMask & (1<<pOp->p1))!=0 );
64371 u.av.pBt = db->aDb[pOp->p1].pBt;
64372 if( u.av.pBt ){
64373 sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta);
64374 u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
64375 }else{
64376 u.av.iMeta = 0;
64377 }
64378 if( u.av.iMeta!=pOp->p2 || u.av.iGen!=pOp->p3 ){
64379 sqlite3DbFree(db, p->zErrMsg);
64380 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
64381 /* If the schema-cookie from the database file matches the cookie
64382 ** stored with the in-memory representation of the schema, do
64383 ** not reload the schema from the database file.
@@ -65694,18 +66107,14 @@
66107 rc = sqlite3BtreeCreateTable(u.bt.pDb->pBt, &u.bt.pgno, u.bt.flags);
66108 pOut->u.i = u.bt.pgno;
66109 break;
66110 }
66111
66112 /* Opcode: ParseSchema P1 * * P4 *
66113 **
66114 ** Read and parse all entries from the SQLITE_MASTER table of database P1
66115 ** that match the WHERE clause P4.
 
 
 
 
66116 **
66117 ** This opcode invokes the parser to create a new virtual machine,
66118 ** then runs the new virtual machine. It is thus a re-entrant opcode.
66119 */
66120 case OP_ParseSchema: {
@@ -65717,18 +66126,11 @@
66126 #endif /* local variables moved into u.bu */
66127
66128 u.bu.iDb = pOp->p1;
66129 assert( u.bu.iDb>=0 && u.bu.iDb<db->nDb );
66130
66131 /* Although the mutex on the BtShared object that corresponds to
 
 
 
 
 
 
 
66132 ** database u.bu.iDb (the database containing the sqlite_master table
66133 ** read by this instruction) is currently held, it is necessary to
66134 ** obtain the mutexes on all attached databases before checking if
66135 ** the schema of u.bu.iDb is loaded. This is because, at the start of
66136 ** the sqlite3_exec() call below, SQLite will invoke
@@ -65740,11 +66142,11 @@
66142 ** can result in a "no such table: sqlite_master" or "malformed
66143 ** database schema" error being returned to the user.
66144 */
66145 assert( sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) );
66146 sqlite3BtreeEnterAll(db);
66147 if( ALWAYS(DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded)) ){
66148 u.bu.zMaster = SCHEMA_TABLE(u.bu.iDb);
66149 u.bu.initData.db = db;
66150 u.bu.initData.iDb = pOp->p1;
66151 u.bu.initData.pzErrMsg = &p->zErrMsg;
66152 u.bu.zSql = sqlite3MPrintf(db,
@@ -67395,10 +67797,11 @@
67797 sqlite3VdbeChangeP2(v, 0, flags);
67798
67799 /* Configure the OP_VerifyCookie */
67800 sqlite3VdbeChangeP1(v, 1, iDb);
67801 sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie);
67802 sqlite3VdbeChangeP3(v, 1, pTab->pSchema->iGeneration);
67803
67804 /* Make sure a mutex is held on the table to be accessed */
67805 sqlite3VdbeUsesBtree(v, iDb);
67806
67807 /* Configure the OP_TableLock instruction */
@@ -69826,10 +70229,11 @@
70229
70230 if( pToken ){
70231 if( op!=TK_INTEGER || pToken->z==0
70232 || sqlite3GetInt32(pToken->z, &iValue)==0 ){
70233 nExtra = pToken->n+1;
70234 assert( iValue>=0 );
70235 }
70236 }
70237 pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
70238 if( pNew ){
70239 pNew->op = (u8)op;
@@ -70051,10 +70455,12 @@
70455 /*
70456 ** Recursively delete an expression tree.
70457 */
70458 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
70459 if( p==0 ) return;
70460 /* Sanity check: Assert that the IntValue is non-negative if it exists */
70461 assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
70462 if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
70463 sqlite3ExprDelete(db, p->pLeft);
70464 sqlite3ExprDelete(db, p->pRight);
70465 if( !ExprHasProperty(p, EP_Reduced) && (p->flags2 & EP2_MallocedToken)!=0 ){
70466 sqlite3DbFree(db, p->u.zToken);
@@ -70660,17 +71066,10 @@
71066 }
71067 break;
71068 }
71069 default: break;
71070 }
 
 
 
 
 
 
 
71071 return rc;
71072 }
71073
71074 /*
71075 ** Return FALSE if there is no chance that the expression can be NULL.
@@ -71391,10 +71790,11 @@
71790 */
71791 static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
71792 Vdbe *v = pParse->pVdbe;
71793 if( pExpr->flags & EP_IntValue ){
71794 int i = pExpr->u.iValue;
71795 assert( i>=0 );
71796 if( negFlag ) i = -i;
71797 sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
71798 }else{
71799 int c;
71800 i64 value;
@@ -75655,19 +76055,21 @@
76055 ** set for each database that is used. Generate code to start a
76056 ** transaction on each used database and to verify the schema cookie
76057 ** on each used database.
76058 */
76059 if( pParse->cookieGoto>0 ){
76060 tAttachMask mask;
76061 int iDb;
76062 sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
76063 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
76064 if( (mask & pParse->cookieMask)==0 ) continue;
76065 sqlite3VdbeUsesBtree(v, iDb);
76066 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
76067 if( db->init.busy==0 ){
76068 sqlite3VdbeAddOp3(v, OP_VerifyCookie,
76069 iDb, pParse->cookieValue[iDb],
76070 db->aDb[iDb].pSchema->iGeneration);
76071 }
76072 }
76073 #ifndef SQLITE_OMIT_VIRTUALTABLE
76074 {
76075 int i;
@@ -75873,11 +76275,11 @@
76275 int len;
76276 Hash *pHash = &db->aDb[iDb].pSchema->idxHash;
76277
76278 len = sqlite3Strlen30(zIdxName);
76279 pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0);
76280 if( ALWAYS(pIndex) ){
76281 if( pIndex->pTable->pIndex==pIndex ){
76282 pIndex->pTable->pIndex = pIndex->pNext;
76283 }else{
76284 Index *p;
76285 /* Justification of ALWAYS(); The index must be on the list of
@@ -78949,16 +79351,16 @@
79351 if( v==0 ) return; /* This only happens if there was a prior error */
79352 pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1;
79353 }
79354 if( iDb>=0 ){
79355 sqlite3 *db = pToplevel->db;
79356 tAttachMask mask;
79357
79358 assert( iDb<db->nDb );
79359 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
79360 assert( iDb<SQLITE_MAX_ATTACHED+2 );
79361 mask = ((tAttachMask)1)<<iDb;
79362 if( (pToplevel->cookieMask & mask)==0 ){
79363 pToplevel->cookieMask |= mask;
79364 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
79365 if( !OMIT_TEMPDB && iDb==1 ){
79366 sqlite3OpenTempDatabase(pToplevel);
@@ -78981,11 +79383,11 @@
79383 ** necessary to undo a write and the checkpoint should not be set.
79384 */
79385 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
79386 Parse *pToplevel = sqlite3ParseToplevel(pParse);
79387 sqlite3CodeVerifySchema(pParse, iDb);
79388 pToplevel->writeMask |= ((tAttachMask)1)<<iDb;
79389 pToplevel->isMultiWrite |= setStatement;
79390 }
79391
79392 /*
79393 ** Indicate that the statement currently under construction might write
@@ -79626,11 +80028,14 @@
80028 sqlite3DeleteTable(0, pTab);
80029 }
80030 sqlite3HashClear(&temp1);
80031 sqlite3HashClear(&pSchema->fkeyHash);
80032 pSchema->pSeqTab = 0;
80033 if( pSchema->flags & DB_SchemaLoaded ){
80034 pSchema->iGeneration++;
80035 pSchema->flags &= ~DB_SchemaLoaded;
80036 }
80037 }
80038
80039 /*
80040 ** Find and return the schema associated with a BTree. Create
80041 ** a new one if necessary.
@@ -84381,12 +84786,13 @@
84786 ** index and making sure that duplicate entries do not already exist.
84787 ** Add the new records to the indices as we go.
84788 */
84789 for(iCur=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, iCur++){
84790 int regIdx;
84791 #ifndef SQLITE_OMIT_UNIQUE_ENFORCEMENT
84792 int regR;
84793 #endif
84794 if( aRegIdx[iCur]==0 ) continue; /* Skip unused indices */
84795
84796 /* Create a key for accessing the index entry */
84797 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn+1);
84798 for(i=0; i<pIdx->nColumn; i++){
@@ -84399,10 +84805,15 @@
84805 }
84806 sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i);
84807 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]);
84808 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0);
84809 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1);
84810
84811 #ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT
84812 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
84813 continue; /* Treat pIdx as if it is not a UNIQUE index */
84814 #else
84815
84816 /* Find out what action to take in case there is an indexing conflict */
84817 onError = pIdx->onError;
84818 if( onError==OE_None ){
84819 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
@@ -84473,10 +84884,11 @@
84884 break;
84885 }
84886 }
84887 sqlite3VdbeJumpHere(v, j3);
84888 sqlite3ReleaseTempReg(pParse, regR);
84889 #endif
84890 }
84891
84892 if( pbMayReplace ){
84893 *pbMayReplace = seenReplace;
84894 }
@@ -86501,12 +86913,11 @@
86913 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
86914 sqlite3VdbeChangeP1(v, addr, iDb);
86915 sqlite3VdbeChangeP1(v, addr+1, iDb);
86916 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
86917 }else{
86918 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
 
86919 sqlite3BeginWriteOperation(pParse, 0, iDb);
86920 sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
86921 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
86922 pDb->pSchema->cache_size = size;
86923 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
@@ -86811,12 +87222,11 @@
87222 if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
87223 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
87224 if( !zRight ){
87225 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
87226 }else{
87227 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
 
87228 pDb->pSchema->cache_size = size;
87229 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
87230 }
87231 }else
87232
@@ -87920,13 +88330,12 @@
88330 DbSetProperty(db, iDb, DB_Empty);
88331 }
88332 pDb->pSchema->enc = ENC(db);
88333
88334 if( pDb->pSchema->cache_size==0 ){
88335 size = sqlite3AbsInt32(meta[BTREE_DEFAULT_CACHE_SIZE-1]);
88336 if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
 
88337 pDb->pSchema->cache_size = size;
88338 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
88339 }
88340
88341 /*
@@ -93787,12 +94196,16 @@
94196 int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
94197 ExprList *pChanges, /* Columns that change in an UPDATE statement */
94198 int *pMask /* OUT: Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
94199 ){
94200 int mask = 0;
94201 Trigger *pList = 0;
94202 Trigger *p;
94203
94204 if( (pParse->db->flags & SQLITE_EnableTrigger)!=0 ){
94205 pList = sqlite3TriggerList(pParse, pTab);
94206 }
94207 assert( pList==0 || IsVirtual(pTab)==0 );
94208 for(p=pList; p; p=p->pNext){
94209 if( p->op==op && checkColumnOverlap(p->pColumns, pChanges) ){
94210 mask |= p->tr_tm;
94211 }
@@ -95642,11 +96055,11 @@
96055 v = sqlite3GetVdbe(pParse);
96056 sqlite3ChangeCookie(pParse, iDb);
96057
96058 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
96059 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
96060 sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
96061 sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0,
96062 pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
96063 }
96064
96065 /* If we are rereading the sqlite_master table create the in-memory
@@ -98732,11 +99145,12 @@
99145 /*
99146 ** Estimate the number of rows that will be returned based on
99147 ** an equality constraint x=VALUE and where that VALUE occurs in
99148 ** the histogram data. This only works when x is the left-most
99149 ** column of an index and sqlite_stat2 histogram data is available
99150 ** for that index. When pExpr==NULL that means the constraint is
99151 ** "x IS NULL" instead of "x=VALUE".
99152 **
99153 ** Write the estimated row count into *pnRow and return SQLITE_OK.
99154 ** If unable to make an estimate, leave *pnRow unchanged and return
99155 ** non-zero.
99156 **
@@ -98757,12 +99171,16 @@
99171 int rc; /* Subfunction return code */
99172 double nRowEst; /* New estimate of the number of rows */
99173
99174 assert( p->aSample!=0 );
99175 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
99176 if( pExpr ){
99177 rc = valueFromExpr(pParse, pExpr, aff, &pRhs);
99178 if( rc ) goto whereEqualScanEst_cancel;
99179 }else{
99180 pRhs = sqlite3ValueNew(pParse->db);
99181 }
99182 if( pRhs==0 ) return SQLITE_NOTFOUND;
99183 rc = whereRangeRegion(pParse, p, pRhs, 0, &iLower);
99184 if( rc ) goto whereEqualScanEst_cancel;
99185 rc = whereRangeRegion(pParse, p, pRhs, 1, &iUpper);
99186 if( rc ) goto whereEqualScanEst_cancel;
@@ -99147,11 +99565,13 @@
99565 ** data is available for column x, then it might be possible
99566 ** to get a better estimate on the number of rows based on
99567 ** VALUE and how common that value is according to the histogram.
99568 */
99569 if( nRow>(double)1 && nEq==1 && pFirstTerm!=0 ){
99570 if( pFirstTerm->eOperator & (WO_EQ|WO_ISNULL) ){
99571 testcase( pFirstTerm->eOperator==WO_EQ );
99572 testcase( pFirstTerm->pOperator==WO_ISNULL );
99573 whereEqualScanEst(pParse, pProbe, pFirstTerm->pExpr->pRight, &nRow);
99574 }else if( pFirstTerm->eOperator==WO_IN && bInEst==0 ){
99575 whereInScanEst(pParse, pProbe, pFirstTerm->pExpr->x.pList, &nRow);
99576 }
99577 }
@@ -100213,11 +100633,17 @@
100633 }
100634
100635 /* Record the instruction used to terminate the loop. Disable
100636 ** WHERE clause terms made redundant by the index range scan.
100637 */
100638 if( pLevel->plan.wsFlags & WHERE_UNIQUE ){
100639 pLevel->op = OP_Noop;
100640 }else if( bRev ){
100641 pLevel->op = OP_Prev;
100642 }else{
100643 pLevel->op = OP_Next;
100644 }
100645 pLevel->p1 = iIdxCur;
100646 }else
100647
100648 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
100649 if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
@@ -106160,10 +106586,17 @@
106586 case SQLITE_CONFIG_HEAP: {
106587 /* Designate a buffer for heap memory space */
106588 sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
106589 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
106590 sqlite3GlobalConfig.mnReq = va_arg(ap, int);
106591
106592 if( sqlite3GlobalConfig.mnReq<1 ){
106593 sqlite3GlobalConfig.mnReq = 1;
106594 }else if( sqlite3GlobalConfig.mnReq>(1<<12) ){
106595 /* cap min request size at 2^12 */
106596 sqlite3GlobalConfig.mnReq = (1<<12);
106597 }
106598
106599 if( sqlite3GlobalConfig.pHeap==0 ){
106600 /* If the heap pointer is NULL, then restore the malloc implementation
106601 ** back to NULL pointers too. This will cause the malloc to go
106602 ** back to its default implementation when sqlite3_initialize() is
@@ -106301,11 +106734,39 @@
106734 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
106735 rc = setupLookaside(db, pBuf, sz, cnt);
106736 break;
106737 }
106738 default: {
106739 static const struct {
106740 int op; /* The opcode */
106741 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
106742 } aFlagOp[] = {
106743 { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
106744 { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
106745 };
106746 unsigned int i;
106747 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
106748 for(i=0; i<ArraySize(aFlagOp); i++){
106749 if( aFlagOp[i].op==op ){
106750 int onoff = va_arg(ap, int);
106751 int *pRes = va_arg(ap, int*);
106752 int oldFlags = db->flags;
106753 if( onoff>0 ){
106754 db->flags |= aFlagOp[i].mask;
106755 }else if( onoff==0 ){
106756 db->flags &= ~aFlagOp[i].mask;
106757 }
106758 if( oldFlags!=db->flags ){
106759 sqlite3ExpirePreparedStatements(db);
106760 }
106761 if( pRes ){
106762 *pRes = (db->flags & aFlagOp[i].mask)!=0;
106763 }
106764 rc = SQLITE_OK;
106765 break;
106766 }
106767 }
106768 break;
106769 }
106770 }
106771 va_end(ap);
106772 return rc;
@@ -107474,12 +107935,12 @@
107935 # error SQLITE_MAX_VDBE_OP must be at least 40
107936 #endif
107937 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
107938 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
107939 #endif
107940 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>62
107941 # error SQLITE_MAX_ATTACHED must be between 0 and 62
107942 #endif
107943 #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
107944 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
107945 #endif
107946 #if SQLITE_MAX_COLUMN>32767
@@ -107634,11 +108095,11 @@
108095 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
108096 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
108097 db->autoCommit = 1;
108098 db->nextAutovac = -1;
108099 db->nextPagesize = 0;
108100 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger
108101 #if SQLITE_DEFAULT_FILE_FORMAT<4
108102 | SQLITE_LegacyFileFmt
108103 #endif
108104 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
108105 | SQLITE_LoadExtension
@@ -119847,17 +120308,17 @@
120308 Fts3Expr *pExpr, /* Phrase expression node */
120309 int iPhrase, /* Phrase number */
120310 void *pCtx /* Pointer to MatchInfo structure */
120311 ){
120312 MatchInfo *p = (MatchInfo *)pCtx;
120313 int iStart = iPhrase * p->nCol * 3;
120314 int i;
120315
120316 for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0;
120317
120318 if( pExpr->aDoclist ){
120319 char *pCsr;
 
 
 
 
120320
120321 pCsr = sqlite3Fts3FindPositions(pExpr, p->pCursor->iPrevId, -1);
120322 if( pCsr ){
120323 fts3LoadColumnlistCounts(&pCsr, &p->aMatchinfo[iStart], 0);
120324 }
@@ -121944,19 +122405,19 @@
122405 ** to which the constraint applies. The leftmost coordinate column
122406 ** is 'a', the second from the left 'b' etc.
122407 */
122408 static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
122409 int rc = SQLITE_OK;
122410 int ii;
122411
122412 int iIdx = 0;
122413 char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
122414 memset(zIdxStr, 0, sizeof(zIdxStr));
122415 UNUSED_PARAMETER(tab);
122416
122417 assert( pIdxInfo->idxStr==0 );
122418 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(sizeof(zIdxStr)-1); ii++){
122419 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
122420
122421 if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
122422 /* We have an equality constraint on the rowid. Use strategy 1. */
122423 int jj;
@@ -121976,13 +122437,11 @@
122437 pIdxInfo->estimatedCost = 10.0;
122438 return SQLITE_OK;
122439 }
122440
122441 if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
122442 u8 op;
 
 
122443 switch( p->op ){
122444 case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
122445 case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
122446 case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
122447 case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
@@ -121990,41 +122449,14 @@
122449 default:
122450 assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH );
122451 op = RTREE_MATCH;
122452 break;
122453 }
122454 zIdxStr[iIdx++] = op;
122455 zIdxStr[iIdx++] = p->iColumn - 1 + 'a';
122456 pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
122457 pIdxInfo->aConstraintUsage[ii].omit = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122458 }
122459 }
122460
122461 pIdxInfo->idxNum = 2;
122462 pIdxInfo->needToFreeIdxStr = 1;
122463
+52 -13
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.7.6"
111111
#define SQLITE_VERSION_NUMBER 3007006
112
-#define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61"
112
+#define SQLITE_SOURCE_ID "2011-03-24 01:34:03 b6e268fce12829f058f1dfa223731ec8479493f8"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -896,14 +896,27 @@
896896
** a 24-hour day).
897897
** ^SQLite will use the xCurrentTimeInt64() method to get the current
898898
** date and time if that method is available (if iVersion is 2 or
899899
** greater and the function pointer is not NULL) and will fall back
900900
** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
901
+**
902
+** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
903
+** are not used by the SQLite core. These optional interfaces are provided
904
+** by some VFSes to facilitate testing of the VFS code. By overriding
905
+** system calls with functions under its control, a test program can
906
+** simulate faults and error conditions that would otherwise be difficult
907
+** or impossible to induce. The set of system calls that can be overridden
908
+** varies from one VFS to another, and from one version of the same VFS to the
909
+** next. Applications that use these interfaces must be prepared for any
910
+** or all of these interfaces to be NULL or for their behavior to change
911
+** from one release to the next. Applications must not attempt to access
912
+** any of these methods if the iVersion of the VFS is less than 3.
901913
*/
902914
typedef struct sqlite3_vfs sqlite3_vfs;
915
+typedef void (*sqlite3_syscall_ptr)(void);
903916
struct sqlite3_vfs {
904
- int iVersion; /* Structure version number (currently 2) */
917
+ int iVersion; /* Structure version number (currently 3) */
905918
int szOsFile; /* Size of subclassed sqlite3_file */
906919
int mxPathname; /* Maximum file pathname length */
907920
sqlite3_vfs *pNext; /* Next registered VFS */
908921
const char *zName; /* Name of this virtual file system */
909922
void *pAppData; /* Pointer to application-specific data */
@@ -925,10 +938,17 @@
925938
** definition. Those that follow are added in version 2 or later
926939
*/
927940
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
928941
/*
929942
** The methods above are in versions 1 and 2 of the sqlite_vfs object.
943
+ ** Those below are for version 3 and greater.
944
+ */
945
+ int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
946
+ sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
947
+ const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
948
+ /*
949
+ ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
930950
** New fields may be appended in figure versions. The iVersion
931951
** value will increment whenever this happens.
932952
*/
933953
};
934954
@@ -1109,21 +1129,16 @@
11091129
** CAPI3REF: Configure database connections
11101130
**
11111131
** The sqlite3_db_config() interface is used to make configuration
11121132
** changes to a [database connection]. The interface is similar to
11131133
** [sqlite3_config()] except that the changes apply to a single
1114
-** [database connection] (specified in the first argument). The
1115
-** sqlite3_db_config() interface should only be used immediately after
1116
-** the database connection is created using [sqlite3_open()],
1117
-** [sqlite3_open16()], or [sqlite3_open_v2()].
1134
+** [database connection] (specified in the first argument).
11181135
**
11191136
** The second argument to sqlite3_db_config(D,V,...) is the
1120
-** configuration verb - an integer code that indicates what
1121
-** aspect of the [database connection] is being configured.
1122
-** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
1123
-** New verbs are likely to be added in future releases of SQLite.
1124
-** Additional arguments depend on the verb.
1137
+** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code
1138
+** that indicates what aspect of the [database connection] is being configured.
1139
+** Subsequent arguments vary depending on the configuration verb.
11251140
**
11261141
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
11271142
** the call is considered successful.
11281143
*/
11291144
SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
@@ -1344,11 +1359,13 @@
13441359
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
13451360
** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
13461361
** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
13471362
** allocator is engaged to handle all of SQLites memory allocation needs.
13481363
** The first pointer (the memory pointer) must be aligned to an 8-byte
1349
-** boundary or subsequent behavior of SQLite will be undefined.</dd>
1364
+** boundary or subsequent behavior of SQLite will be undefined.
1365
+** The minimum allocation size is capped at 2^12. Reasonable values
1366
+** for the minimum allocation size are 2^5 through 2^8.</dd>
13501367
**
13511368
** <dt>SQLITE_CONFIG_MUTEX</dt>
13521369
** <dd> ^(This option takes a single argument which is a pointer to an
13531370
** instance of the [sqlite3_mutex_methods] structure. The argument specifies
13541371
** alternative low-level mutex routines to be used in place
@@ -1465,13 +1482,35 @@
14651482
** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
14661483
** Any attempt to change the lookaside memory configuration when lookaside
14671484
** memory is in use leaves the configuration unchanged and returns
14681485
** [SQLITE_BUSY].)^</dd>
14691486
**
1487
+** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
1488
+** <dd> ^This option is used to enable or disable the enforcement of
1489
+** [foreign key constraints]. There should be two additional arguments.
1490
+** The first argument is an integer which is 0 to disable FK enforcement,
1491
+** positive to enable FK enforcement or negative to leave FK enforcement
1492
+** unchanged. The second parameter is a pointer to an integer into which
1493
+** is written 0 or 1 to indicate whether FK enforcement is off or on
1494
+** following this call. The second parameter may be a NULL pointer, in
1495
+** which case the FK enforcement setting is not reported back. </dd>
1496
+**
1497
+** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
1498
+** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
1499
+** There should be two additional arguments.
1500
+** The first argument is an integer which is 0 to disable triggers,
1501
+** positive to enable trigers or negative to leave the setting unchanged.
1502
+** The second parameter is a pointer to an integer into which
1503
+** is written 0 or 1 to indicate whether triggers are disabled or enabled
1504
+** following this call. The second parameter may be a NULL pointer, in
1505
+** which case the trigger setting is not reported back. </dd>
1506
+**
14701507
** </dl>
14711508
*/
1472
-#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1509
+#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1510
+#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1511
+#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
14731512
14741513
14751514
/*
14761515
** CAPI3REF: Enable Or Disable Extended Result Codes
14771516
**
14781517
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.6"
111 #define SQLITE_VERSION_NUMBER 3007006
112 #define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -896,14 +896,27 @@
896 ** a 24-hour day).
897 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
898 ** date and time if that method is available (if iVersion is 2 or
899 ** greater and the function pointer is not NULL) and will fall back
900 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
 
 
 
 
 
 
 
 
 
 
 
 
901 */
902 typedef struct sqlite3_vfs sqlite3_vfs;
 
903 struct sqlite3_vfs {
904 int iVersion; /* Structure version number (currently 2) */
905 int szOsFile; /* Size of subclassed sqlite3_file */
906 int mxPathname; /* Maximum file pathname length */
907 sqlite3_vfs *pNext; /* Next registered VFS */
908 const char *zName; /* Name of this virtual file system */
909 void *pAppData; /* Pointer to application-specific data */
@@ -925,10 +938,17 @@
925 ** definition. Those that follow are added in version 2 or later
926 */
927 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
928 /*
929 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
 
 
 
 
 
 
 
930 ** New fields may be appended in figure versions. The iVersion
931 ** value will increment whenever this happens.
932 */
933 };
934
@@ -1109,21 +1129,16 @@
1109 ** CAPI3REF: Configure database connections
1110 **
1111 ** The sqlite3_db_config() interface is used to make configuration
1112 ** changes to a [database connection]. The interface is similar to
1113 ** [sqlite3_config()] except that the changes apply to a single
1114 ** [database connection] (specified in the first argument). The
1115 ** sqlite3_db_config() interface should only be used immediately after
1116 ** the database connection is created using [sqlite3_open()],
1117 ** [sqlite3_open16()], or [sqlite3_open_v2()].
1118 **
1119 ** The second argument to sqlite3_db_config(D,V,...) is the
1120 ** configuration verb - an integer code that indicates what
1121 ** aspect of the [database connection] is being configured.
1122 ** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
1123 ** New verbs are likely to be added in future releases of SQLite.
1124 ** Additional arguments depend on the verb.
1125 **
1126 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1127 ** the call is considered successful.
1128 */
1129 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
@@ -1344,11 +1359,13 @@
1344 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1345 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1346 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1347 ** allocator is engaged to handle all of SQLites memory allocation needs.
1348 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1349 ** boundary or subsequent behavior of SQLite will be undefined.</dd>
 
 
1350 **
1351 ** <dt>SQLITE_CONFIG_MUTEX</dt>
1352 ** <dd> ^(This option takes a single argument which is a pointer to an
1353 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1354 ** alternative low-level mutex routines to be used in place
@@ -1465,13 +1482,35 @@
1465 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
1466 ** Any attempt to change the lookaside memory configuration when lookaside
1467 ** memory is in use leaves the configuration unchanged and returns
1468 ** [SQLITE_BUSY].)^</dd>
1469 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1470 ** </dl>
1471 */
1472 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
 
 
1473
1474
1475 /*
1476 ** CAPI3REF: Enable Or Disable Extended Result Codes
1477 **
1478
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.6"
111 #define SQLITE_VERSION_NUMBER 3007006
112 #define SQLITE_SOURCE_ID "2011-03-24 01:34:03 b6e268fce12829f058f1dfa223731ec8479493f8"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -896,14 +896,27 @@
896 ** a 24-hour day).
897 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
898 ** date and time if that method is available (if iVersion is 2 or
899 ** greater and the function pointer is not NULL) and will fall back
900 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
901 **
902 ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
903 ** are not used by the SQLite core. These optional interfaces are provided
904 ** by some VFSes to facilitate testing of the VFS code. By overriding
905 ** system calls with functions under its control, a test program can
906 ** simulate faults and error conditions that would otherwise be difficult
907 ** or impossible to induce. The set of system calls that can be overridden
908 ** varies from one VFS to another, and from one version of the same VFS to the
909 ** next. Applications that use these interfaces must be prepared for any
910 ** or all of these interfaces to be NULL or for their behavior to change
911 ** from one release to the next. Applications must not attempt to access
912 ** any of these methods if the iVersion of the VFS is less than 3.
913 */
914 typedef struct sqlite3_vfs sqlite3_vfs;
915 typedef void (*sqlite3_syscall_ptr)(void);
916 struct sqlite3_vfs {
917 int iVersion; /* Structure version number (currently 3) */
918 int szOsFile; /* Size of subclassed sqlite3_file */
919 int mxPathname; /* Maximum file pathname length */
920 sqlite3_vfs *pNext; /* Next registered VFS */
921 const char *zName; /* Name of this virtual file system */
922 void *pAppData; /* Pointer to application-specific data */
@@ -925,10 +938,17 @@
938 ** definition. Those that follow are added in version 2 or later
939 */
940 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
941 /*
942 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
943 ** Those below are for version 3 and greater.
944 */
945 int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
946 sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
947 const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
948 /*
949 ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
950 ** New fields may be appended in figure versions. The iVersion
951 ** value will increment whenever this happens.
952 */
953 };
954
@@ -1109,21 +1129,16 @@
1129 ** CAPI3REF: Configure database connections
1130 **
1131 ** The sqlite3_db_config() interface is used to make configuration
1132 ** changes to a [database connection]. The interface is similar to
1133 ** [sqlite3_config()] except that the changes apply to a single
1134 ** [database connection] (specified in the first argument).
 
 
 
1135 **
1136 ** The second argument to sqlite3_db_config(D,V,...) is the
1137 ** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code
1138 ** that indicates what aspect of the [database connection] is being configured.
1139 ** Subsequent arguments vary depending on the configuration verb.
 
 
1140 **
1141 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1142 ** the call is considered successful.
1143 */
1144 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
@@ -1344,11 +1359,13 @@
1359 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1360 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1361 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1362 ** allocator is engaged to handle all of SQLites memory allocation needs.
1363 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1364 ** boundary or subsequent behavior of SQLite will be undefined.
1365 ** The minimum allocation size is capped at 2^12. Reasonable values
1366 ** for the minimum allocation size are 2^5 through 2^8.</dd>
1367 **
1368 ** <dt>SQLITE_CONFIG_MUTEX</dt>
1369 ** <dd> ^(This option takes a single argument which is a pointer to an
1370 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1371 ** alternative low-level mutex routines to be used in place
@@ -1465,13 +1482,35 @@
1482 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
1483 ** Any attempt to change the lookaside memory configuration when lookaside
1484 ** memory is in use leaves the configuration unchanged and returns
1485 ** [SQLITE_BUSY].)^</dd>
1486 **
1487 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
1488 ** <dd> ^This option is used to enable or disable the enforcement of
1489 ** [foreign key constraints]. There should be two additional arguments.
1490 ** The first argument is an integer which is 0 to disable FK enforcement,
1491 ** positive to enable FK enforcement or negative to leave FK enforcement
1492 ** unchanged. The second parameter is a pointer to an integer into which
1493 ** is written 0 or 1 to indicate whether FK enforcement is off or on
1494 ** following this call. The second parameter may be a NULL pointer, in
1495 ** which case the FK enforcement setting is not reported back. </dd>
1496 **
1497 ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
1498 ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
1499 ** There should be two additional arguments.
1500 ** The first argument is an integer which is 0 to disable triggers,
1501 ** positive to enable trigers or negative to leave the setting unchanged.
1502 ** The second parameter is a pointer to an integer into which
1503 ** is written 0 or 1 to indicate whether triggers are disabled or enabled
1504 ** following this call. The second parameter may be a NULL pointer, in
1505 ** which case the trigger setting is not reported back. </dd>
1506 **
1507 ** </dl>
1508 */
1509 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1510 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1511 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1512
1513
1514 /*
1515 ** CAPI3REF: Enable Or Disable Extended Result Codes
1516 **
1517

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button