Fossil SCM

Pull the latest trunk changes into clear-title.

drh 2010-05-16 11:18 clear-title merge
Commit 96722b6d011b9cb30111b9199f3fae01119e35ce
+3
--- src/add.c
+++ src/add.c
@@ -44,10 +44,13 @@
4444
4545
file_tree_name(zName, &pathname, 1);
4646
zPath = blob_str(&pathname);
4747
if( strcmp(zPath, "manifest")==0
4848
|| strcmp(zPath, "_FOSSIL_")==0
49
+ || strcmp(zPath, "_FOSSIL_-journal")==0
50
+ || strcmp(zPath, ".fos")==0
51
+ || strcmp(zPath, ".fos-journal")==0
4952
|| strcmp(zPath, "manifest.uuid")==0
5053
|| blob_compare(&pathname, pOmit)==0
5154
){
5255
fossil_warning("cannot add %s", zPath);
5356
}else{
5457
--- src/add.c
+++ src/add.c
@@ -44,10 +44,13 @@
44
45 file_tree_name(zName, &pathname, 1);
46 zPath = blob_str(&pathname);
47 if( strcmp(zPath, "manifest")==0
48 || strcmp(zPath, "_FOSSIL_")==0
 
 
 
49 || strcmp(zPath, "manifest.uuid")==0
50 || blob_compare(&pathname, pOmit)==0
51 ){
52 fossil_warning("cannot add %s", zPath);
53 }else{
54
--- src/add.c
+++ src/add.c
@@ -44,10 +44,13 @@
44
45 file_tree_name(zName, &pathname, 1);
46 zPath = blob_str(&pathname);
47 if( strcmp(zPath, "manifest")==0
48 || strcmp(zPath, "_FOSSIL_")==0
49 || strcmp(zPath, "_FOSSIL_-journal")==0
50 || strcmp(zPath, ".fos")==0
51 || strcmp(zPath, ".fos-journal")==0
52 || strcmp(zPath, "manifest.uuid")==0
53 || blob_compare(&pathname, pOmit)==0
54 ){
55 fossil_warning("cannot add %s", zPath);
56 }else{
57
+3
--- src/add.c
+++ src/add.c
@@ -44,10 +44,13 @@
4444
4545
file_tree_name(zName, &pathname, 1);
4646
zPath = blob_str(&pathname);
4747
if( strcmp(zPath, "manifest")==0
4848
|| strcmp(zPath, "_FOSSIL_")==0
49
+ || strcmp(zPath, "_FOSSIL_-journal")==0
50
+ || strcmp(zPath, ".fos")==0
51
+ || strcmp(zPath, ".fos-journal")==0
4952
|| strcmp(zPath, "manifest.uuid")==0
5053
|| blob_compare(&pathname, pOmit)==0
5154
){
5255
fossil_warning("cannot add %s", zPath);
5356
}else{
5457
--- src/add.c
+++ src/add.c
@@ -44,10 +44,13 @@
44
45 file_tree_name(zName, &pathname, 1);
46 zPath = blob_str(&pathname);
47 if( strcmp(zPath, "manifest")==0
48 || strcmp(zPath, "_FOSSIL_")==0
 
 
 
49 || strcmp(zPath, "manifest.uuid")==0
50 || blob_compare(&pathname, pOmit)==0
51 ){
52 fossil_warning("cannot add %s", zPath);
53 }else{
54
--- src/add.c
+++ src/add.c
@@ -44,10 +44,13 @@
44
45 file_tree_name(zName, &pathname, 1);
46 zPath = blob_str(&pathname);
47 if( strcmp(zPath, "manifest")==0
48 || strcmp(zPath, "_FOSSIL_")==0
49 || strcmp(zPath, "_FOSSIL_-journal")==0
50 || strcmp(zPath, ".fos")==0
51 || strcmp(zPath, ".fos-journal")==0
52 || strcmp(zPath, "manifest.uuid")==0
53 || blob_compare(&pathname, pOmit)==0
54 ){
55 fossil_warning("cannot add %s", zPath);
56 }else{
57
+4 -2
--- src/checkin.c
+++ src/checkin.c
@@ -276,11 +276,12 @@
276276
zIgnoreFlag = db_get("ignore-glob", 0);
277277
}
278278
vfile_scan(0, &path, blob_size(&path), allFlag);
279279
db_prepare(&q,
280280
"SELECT x FROM sfile"
281
- " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
281
+ " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
282
+ "'_FOSSIL_-journal','.fos','.fos-journal')"
282283
" AND NOT %s"
283284
" ORDER BY 1",
284285
glob_expr("x", zIgnoreFlag)
285286
);
286287
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -321,11 +322,12 @@
321322
n = strlen(g.zLocalRoot);
322323
blob_init(&path, g.zLocalRoot, n-1);
323324
vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
324325
db_prepare(&q,
325326
"SELECT %Q || x FROM sfile"
326
- " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
327
+ " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
328
+ "'_FOSSIL_-journal','.fos','.fos-journal')"
327329
" ORDER BY 1", g.zLocalRoot);
328330
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
329331
db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
330332
}
331333
while( db_step(&q)==SQLITE_ROW ){
332334
--- src/checkin.c
+++ src/checkin.c
@@ -276,11 +276,12 @@
276 zIgnoreFlag = db_get("ignore-glob", 0);
277 }
278 vfile_scan(0, &path, blob_size(&path), allFlag);
279 db_prepare(&q,
280 "SELECT x FROM sfile"
281 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
 
282 " AND NOT %s"
283 " ORDER BY 1",
284 glob_expr("x", zIgnoreFlag)
285 );
286 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -321,11 +322,12 @@
321 n = strlen(g.zLocalRoot);
322 blob_init(&path, g.zLocalRoot, n-1);
323 vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
324 db_prepare(&q,
325 "SELECT %Q || x FROM sfile"
326 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
 
327 " ORDER BY 1", g.zLocalRoot);
328 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
329 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
330 }
331 while( db_step(&q)==SQLITE_ROW ){
332
--- src/checkin.c
+++ src/checkin.c
@@ -276,11 +276,12 @@
276 zIgnoreFlag = db_get("ignore-glob", 0);
277 }
278 vfile_scan(0, &path, blob_size(&path), allFlag);
279 db_prepare(&q,
280 "SELECT x FROM sfile"
281 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
282 "'_FOSSIL_-journal','.fos','.fos-journal')"
283 " AND NOT %s"
284 " ORDER BY 1",
285 glob_expr("x", zIgnoreFlag)
286 );
287 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -321,11 +322,12 @@
322 n = strlen(g.zLocalRoot);
323 blob_init(&path, g.zLocalRoot, n-1);
324 vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
325 db_prepare(&q,
326 "SELECT %Q || x FROM sfile"
327 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
328 "'_FOSSIL_-journal','.fos','.fos-journal')"
329 " ORDER BY 1", g.zLocalRoot);
330 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
331 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
332 }
333 while( db_step(&q)==SQLITE_ROW ){
334
+4 -2
--- src/checkin.c
+++ src/checkin.c
@@ -276,11 +276,12 @@
276276
zIgnoreFlag = db_get("ignore-glob", 0);
277277
}
278278
vfile_scan(0, &path, blob_size(&path), allFlag);
279279
db_prepare(&q,
280280
"SELECT x FROM sfile"
281
- " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
281
+ " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
282
+ "'_FOSSIL_-journal','.fos','.fos-journal')"
282283
" AND NOT %s"
283284
" ORDER BY 1",
284285
glob_expr("x", zIgnoreFlag)
285286
);
286287
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -321,11 +322,12 @@
321322
n = strlen(g.zLocalRoot);
322323
blob_init(&path, g.zLocalRoot, n-1);
323324
vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
324325
db_prepare(&q,
325326
"SELECT %Q || x FROM sfile"
326
- " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
327
+ " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
328
+ "'_FOSSIL_-journal','.fos','.fos-journal')"
327329
" ORDER BY 1", g.zLocalRoot);
328330
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
329331
db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
330332
}
331333
while( db_step(&q)==SQLITE_ROW ){
332334
--- src/checkin.c
+++ src/checkin.c
@@ -276,11 +276,12 @@
276 zIgnoreFlag = db_get("ignore-glob", 0);
277 }
278 vfile_scan(0, &path, blob_size(&path), allFlag);
279 db_prepare(&q,
280 "SELECT x FROM sfile"
281 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
 
282 " AND NOT %s"
283 " ORDER BY 1",
284 glob_expr("x", zIgnoreFlag)
285 );
286 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -321,11 +322,12 @@
321 n = strlen(g.zLocalRoot);
322 blob_init(&path, g.zLocalRoot, n-1);
323 vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
324 db_prepare(&q,
325 "SELECT %Q || x FROM sfile"
326 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
 
327 " ORDER BY 1", g.zLocalRoot);
328 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
329 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
330 }
331 while( db_step(&q)==SQLITE_ROW ){
332
--- src/checkin.c
+++ src/checkin.c
@@ -276,11 +276,12 @@
276 zIgnoreFlag = db_get("ignore-glob", 0);
277 }
278 vfile_scan(0, &path, blob_size(&path), allFlag);
279 db_prepare(&q,
280 "SELECT x FROM sfile"
281 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
282 "'_FOSSIL_-journal','.fos','.fos-journal')"
283 " AND NOT %s"
284 " ORDER BY 1",
285 glob_expr("x", zIgnoreFlag)
286 );
287 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -321,11 +322,12 @@
322 n = strlen(g.zLocalRoot);
323 blob_init(&path, g.zLocalRoot, n-1);
324 vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
325 db_prepare(&q,
326 "SELECT %Q || x FROM sfile"
327 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
328 "'_FOSSIL_-journal','.fos','.fos-journal')"
329 " ORDER BY 1", g.zLocalRoot);
330 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
331 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
332 }
333 while( db_step(&q)==SQLITE_ROW ){
334
--- src/content.c
+++ src/content.c
@@ -280,40 +280,10 @@
280280
bag_insert(&contentCache.available, rid);
281281
}
282282
return rc;
283283
}
284284
285
-/*
286
-** Get the contents of a file within a given baseline.
287
-*/
288
-int content_get_historical_file(
289
- const char *revision, /* Name of the baseline containing the file */
290
- const char *file, /* Name of the file */
291
- Blob *content /* Write file content here */
292
-){
293
- Blob mfile;
294
- Manifest m;
295
- int i, rid=0;
296
-
297
- rid = name_to_rid(revision);
298
- content_get(rid, &mfile);
299
-
300
- if( manifest_parse(&m, &mfile) ){
301
- for(i=0; i<m.nFile; i++){
302
- if( strcmp(m.aFile[i].zName, file)==0 ){
303
- rid = uuid_to_rid(m.aFile[i].zUuid, 0);
304
- return content_get(rid, content);
305
- }
306
- }
307
- fossil_panic("file: %s does not exist in revision: %s", file, revision);
308
- }else{
309
- fossil_panic("could not parse manifest for revision: %s", revision);
310
- }
311
-
312
- return 0;
313
-}
314
-
315285
/*
316286
** COMMAND: artifact
317287
**
318288
** Usage: %fossil artifact ARTIFACT-ID ?OUTPUT-FILENAME?
319289
**
320290
--- src/content.c
+++ src/content.c
@@ -280,40 +280,10 @@
280 bag_insert(&contentCache.available, rid);
281 }
282 return rc;
283 }
284
285 /*
286 ** Get the contents of a file within a given baseline.
287 */
288 int content_get_historical_file(
289 const char *revision, /* Name of the baseline containing the file */
290 const char *file, /* Name of the file */
291 Blob *content /* Write file content here */
292 ){
293 Blob mfile;
294 Manifest m;
295 int i, rid=0;
296
297 rid = name_to_rid(revision);
298 content_get(rid, &mfile);
299
300 if( manifest_parse(&m, &mfile) ){
301 for(i=0; i<m.nFile; i++){
302 if( strcmp(m.aFile[i].zName, file)==0 ){
303 rid = uuid_to_rid(m.aFile[i].zUuid, 0);
304 return content_get(rid, content);
305 }
306 }
307 fossil_panic("file: %s does not exist in revision: %s", file, revision);
308 }else{
309 fossil_panic("could not parse manifest for revision: %s", revision);
310 }
311
312 return 0;
313 }
314
315 /*
316 ** COMMAND: artifact
317 **
318 ** Usage: %fossil artifact ARTIFACT-ID ?OUTPUT-FILENAME?
319 **
320
--- src/content.c
+++ src/content.c
@@ -280,40 +280,10 @@
280 bag_insert(&contentCache.available, rid);
281 }
282 return rc;
283 }
284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285 /*
286 ** COMMAND: artifact
287 **
288 ** Usage: %fossil artifact ARTIFACT-ID ?OUTPUT-FILENAME?
289 **
290
+20 -9
--- src/db.c
+++ src/db.c
@@ -70,12 +70,12 @@
7070
if( g.xferPanic ){
7171
cgi_reset_content();
7272
@ error Database\serror:\s%F(z)
7373
cgi_reply();
7474
}
75
- if( g.cgiPanic ){
76
- g.cgiPanic = 0;
75
+ if( g.cgiOutput ){
76
+ g.cgiOutput = 0;
7777
cgi_printf("<h1>Database Error</h1>\n"
7878
"<pre>%h</pre><p>%s</p>", z, zRebuildMsg);
7979
cgi_reply();
8080
}else{
8181
fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
@@ -277,18 +277,21 @@
277277
/*
278278
** Print warnings if a query is inefficient.
279279
*/
280280
static void db_stats(Stmt *pStmt){
281281
#ifdef FOSSIL_DEBUG
282
- int c1, c2;
282
+ int c1, c2, c3;
283283
const char *zSql = sqlite3_sql(pStmt->pStmt);
284284
if( zSql==0 ) return;
285285
c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
286
- c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
286
+ c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, 1);
287
+ c3 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
287288
if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
288289
fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
289
- }else if( c2 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
290
+ }else if( c2 ){
291
+ fossil_warning("%d automatic index rows in [%s]", c2, zSql);
292
+ }else if( c3 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
290293
fossil_warning("sort w/o index in [%s]", zSql);
291294
}
292295
pStmt->nStep = 0;
293296
#endif
294297
}
@@ -647,18 +650,26 @@
647650
if( zHome==0 ){
648651
zHome = getenv("HOMEPATH");
649652
}
650653
}
651654
if( zHome==0 ){
652
- db_err("cannot locate home directory - "
653
- "please set the HOMEPATH environment variable");
655
+ fossil_fatal("cannot locate home directory - "
656
+ "please set the HOMEPATH environment variable");
654657
}
655658
#else
656659
zHome = getenv("HOME");
657660
if( zHome==0 ){
658
- db_err("cannot locate home directory - "
659
- "please set the HOME environment variable");
661
+ fossil_fatal("cannot locate home directory - "
662
+ "please set the HOME environment variable");
663
+ }
664
+#endif
665
+ if( file_isdir(zHome)!=1 ){
666
+ fossil_fatal("invalid home directory: %s", zHome);
667
+ }
668
+#ifndef __MINGW32__
669
+ if( access(zHome, W_OK) ){
670
+ fossil_fatal("home directory %s must be writeable", zHome);
660671
}
661672
#endif
662673
g.zHome = mprintf("%/", zHome);
663674
#ifdef __MINGW32__
664675
/* . filenames give some window systems problems and many apps problems */
665676
--- src/db.c
+++ src/db.c
@@ -70,12 +70,12 @@
70 if( g.xferPanic ){
71 cgi_reset_content();
72 @ error Database\serror:\s%F(z)
73 cgi_reply();
74 }
75 if( g.cgiPanic ){
76 g.cgiPanic = 0;
77 cgi_printf("<h1>Database Error</h1>\n"
78 "<pre>%h</pre><p>%s</p>", z, zRebuildMsg);
79 cgi_reply();
80 }else{
81 fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
@@ -277,18 +277,21 @@
277 /*
278 ** Print warnings if a query is inefficient.
279 */
280 static void db_stats(Stmt *pStmt){
281 #ifdef FOSSIL_DEBUG
282 int c1, c2;
283 const char *zSql = sqlite3_sql(pStmt->pStmt);
284 if( zSql==0 ) return;
285 c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
286 c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
 
287 if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
288 fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
289 }else if( c2 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
 
 
290 fossil_warning("sort w/o index in [%s]", zSql);
291 }
292 pStmt->nStep = 0;
293 #endif
294 }
@@ -647,18 +650,26 @@
647 if( zHome==0 ){
648 zHome = getenv("HOMEPATH");
649 }
650 }
651 if( zHome==0 ){
652 db_err("cannot locate home directory - "
653 "please set the HOMEPATH environment variable");
654 }
655 #else
656 zHome = getenv("HOME");
657 if( zHome==0 ){
658 db_err("cannot locate home directory - "
659 "please set the HOME environment variable");
 
 
 
 
 
 
 
 
660 }
661 #endif
662 g.zHome = mprintf("%/", zHome);
663 #ifdef __MINGW32__
664 /* . filenames give some window systems problems and many apps problems */
665
--- src/db.c
+++ src/db.c
@@ -70,12 +70,12 @@
70 if( g.xferPanic ){
71 cgi_reset_content();
72 @ error Database\serror:\s%F(z)
73 cgi_reply();
74 }
75 if( g.cgiOutput ){
76 g.cgiOutput = 0;
77 cgi_printf("<h1>Database Error</h1>\n"
78 "<pre>%h</pre><p>%s</p>", z, zRebuildMsg);
79 cgi_reply();
80 }else{
81 fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
@@ -277,18 +277,21 @@
277 /*
278 ** Print warnings if a query is inefficient.
279 */
280 static void db_stats(Stmt *pStmt){
281 #ifdef FOSSIL_DEBUG
282 int c1, c2, c3;
283 const char *zSql = sqlite3_sql(pStmt->pStmt);
284 if( zSql==0 ) return;
285 c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
286 c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, 1);
287 c3 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
288 if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
289 fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
290 }else if( c2 ){
291 fossil_warning("%d automatic index rows in [%s]", c2, zSql);
292 }else if( c3 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
293 fossil_warning("sort w/o index in [%s]", zSql);
294 }
295 pStmt->nStep = 0;
296 #endif
297 }
@@ -647,18 +650,26 @@
650 if( zHome==0 ){
651 zHome = getenv("HOMEPATH");
652 }
653 }
654 if( zHome==0 ){
655 fossil_fatal("cannot locate home directory - "
656 "please set the HOMEPATH environment variable");
657 }
658 #else
659 zHome = getenv("HOME");
660 if( zHome==0 ){
661 fossil_fatal("cannot locate home directory - "
662 "please set the HOME environment variable");
663 }
664 #endif
665 if( file_isdir(zHome)!=1 ){
666 fossil_fatal("invalid home directory: %s", zHome);
667 }
668 #ifndef __MINGW32__
669 if( access(zHome, W_OK) ){
670 fossil_fatal("home directory %s must be writeable", zHome);
671 }
672 #endif
673 g.zHome = mprintf("%/", zHome);
674 #ifdef __MINGW32__
675 /* . filenames give some window systems problems and many apps problems */
676
+20 -9
--- src/db.c
+++ src/db.c
@@ -70,12 +70,12 @@
7070
if( g.xferPanic ){
7171
cgi_reset_content();
7272
@ error Database\serror:\s%F(z)
7373
cgi_reply();
7474
}
75
- if( g.cgiPanic ){
76
- g.cgiPanic = 0;
75
+ if( g.cgiOutput ){
76
+ g.cgiOutput = 0;
7777
cgi_printf("<h1>Database Error</h1>\n"
7878
"<pre>%h</pre><p>%s</p>", z, zRebuildMsg);
7979
cgi_reply();
8080
}else{
8181
fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
@@ -277,18 +277,21 @@
277277
/*
278278
** Print warnings if a query is inefficient.
279279
*/
280280
static void db_stats(Stmt *pStmt){
281281
#ifdef FOSSIL_DEBUG
282
- int c1, c2;
282
+ int c1, c2, c3;
283283
const char *zSql = sqlite3_sql(pStmt->pStmt);
284284
if( zSql==0 ) return;
285285
c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
286
- c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
286
+ c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, 1);
287
+ c3 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
287288
if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
288289
fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
289
- }else if( c2 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
290
+ }else if( c2 ){
291
+ fossil_warning("%d automatic index rows in [%s]", c2, zSql);
292
+ }else if( c3 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
290293
fossil_warning("sort w/o index in [%s]", zSql);
291294
}
292295
pStmt->nStep = 0;
293296
#endif
294297
}
@@ -647,18 +650,26 @@
647650
if( zHome==0 ){
648651
zHome = getenv("HOMEPATH");
649652
}
650653
}
651654
if( zHome==0 ){
652
- db_err("cannot locate home directory - "
653
- "please set the HOMEPATH environment variable");
655
+ fossil_fatal("cannot locate home directory - "
656
+ "please set the HOMEPATH environment variable");
654657
}
655658
#else
656659
zHome = getenv("HOME");
657660
if( zHome==0 ){
658
- db_err("cannot locate home directory - "
659
- "please set the HOME environment variable");
661
+ fossil_fatal("cannot locate home directory - "
662
+ "please set the HOME environment variable");
663
+ }
664
+#endif
665
+ if( file_isdir(zHome)!=1 ){
666
+ fossil_fatal("invalid home directory: %s", zHome);
667
+ }
668
+#ifndef __MINGW32__
669
+ if( access(zHome, W_OK) ){
670
+ fossil_fatal("home directory %s must be writeable", zHome);
660671
}
661672
#endif
662673
g.zHome = mprintf("%/", zHome);
663674
#ifdef __MINGW32__
664675
/* . filenames give some window systems problems and many apps problems */
665676
--- src/db.c
+++ src/db.c
@@ -70,12 +70,12 @@
70 if( g.xferPanic ){
71 cgi_reset_content();
72 @ error Database\serror:\s%F(z)
73 cgi_reply();
74 }
75 if( g.cgiPanic ){
76 g.cgiPanic = 0;
77 cgi_printf("<h1>Database Error</h1>\n"
78 "<pre>%h</pre><p>%s</p>", z, zRebuildMsg);
79 cgi_reply();
80 }else{
81 fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
@@ -277,18 +277,21 @@
277 /*
278 ** Print warnings if a query is inefficient.
279 */
280 static void db_stats(Stmt *pStmt){
281 #ifdef FOSSIL_DEBUG
282 int c1, c2;
283 const char *zSql = sqlite3_sql(pStmt->pStmt);
284 if( zSql==0 ) return;
285 c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
286 c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
 
287 if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
288 fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
289 }else if( c2 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
 
 
290 fossil_warning("sort w/o index in [%s]", zSql);
291 }
292 pStmt->nStep = 0;
293 #endif
294 }
@@ -647,18 +650,26 @@
647 if( zHome==0 ){
648 zHome = getenv("HOMEPATH");
649 }
650 }
651 if( zHome==0 ){
652 db_err("cannot locate home directory - "
653 "please set the HOMEPATH environment variable");
654 }
655 #else
656 zHome = getenv("HOME");
657 if( zHome==0 ){
658 db_err("cannot locate home directory - "
659 "please set the HOME environment variable");
 
 
 
 
 
 
 
 
660 }
661 #endif
662 g.zHome = mprintf("%/", zHome);
663 #ifdef __MINGW32__
664 /* . filenames give some window systems problems and many apps problems */
665
--- src/db.c
+++ src/db.c
@@ -70,12 +70,12 @@
70 if( g.xferPanic ){
71 cgi_reset_content();
72 @ error Database\serror:\s%F(z)
73 cgi_reply();
74 }
75 if( g.cgiOutput ){
76 g.cgiOutput = 0;
77 cgi_printf("<h1>Database Error</h1>\n"
78 "<pre>%h</pre><p>%s</p>", z, zRebuildMsg);
79 cgi_reply();
80 }else{
81 fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
@@ -277,18 +277,21 @@
277 /*
278 ** Print warnings if a query is inefficient.
279 */
280 static void db_stats(Stmt *pStmt){
281 #ifdef FOSSIL_DEBUG
282 int c1, c2, c3;
283 const char *zSql = sqlite3_sql(pStmt->pStmt);
284 if( zSql==0 ) return;
285 c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
286 c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, 1);
287 c3 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
288 if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
289 fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
290 }else if( c2 ){
291 fossil_warning("%d automatic index rows in [%s]", c2, zSql);
292 }else if( c3 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
293 fossil_warning("sort w/o index in [%s]", zSql);
294 }
295 pStmt->nStep = 0;
296 #endif
297 }
@@ -647,18 +650,26 @@
650 if( zHome==0 ){
651 zHome = getenv("HOMEPATH");
652 }
653 }
654 if( zHome==0 ){
655 fossil_fatal("cannot locate home directory - "
656 "please set the HOMEPATH environment variable");
657 }
658 #else
659 zHome = getenv("HOME");
660 if( zHome==0 ){
661 fossil_fatal("cannot locate home directory - "
662 "please set the HOME environment variable");
663 }
664 #endif
665 if( file_isdir(zHome)!=1 ){
666 fossil_fatal("invalid home directory: %s", zHome);
667 }
668 #ifndef __MINGW32__
669 if( access(zHome, W_OK) ){
670 fossil_fatal("home directory %s must be writeable", zHome);
671 }
672 #endif
673 g.zHome = mprintf("%/", zHome);
674 #ifdef __MINGW32__
675 /* . filenames give some window systems problems and many apps problems */
676
+1 -1
--- src/finfo.c
+++ src/finfo.c
@@ -159,11 +159,11 @@
159159
int gidx;
160160
char zTime[10];
161161
char zShort[20];
162162
char zShortCkin[20];
163163
if( zBr==0 ) zBr = "trunk";
164
- gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr);
164
+ gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr, zBgClr);
165165
if( memcmp(zDate, zPrevDate, 10) ){
166166
sprintf(zPrevDate, "%.10s", zDate);
167167
@ <tr><td>
168168
@ <div class="divider"><nobr>%s(zPrevDate)</nobr></div>
169169
@ </td></tr>
170170
--- src/finfo.c
+++ src/finfo.c
@@ -159,11 +159,11 @@
159 int gidx;
160 char zTime[10];
161 char zShort[20];
162 char zShortCkin[20];
163 if( zBr==0 ) zBr = "trunk";
164 gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr);
165 if( memcmp(zDate, zPrevDate, 10) ){
166 sprintf(zPrevDate, "%.10s", zDate);
167 @ <tr><td>
168 @ <div class="divider"><nobr>%s(zPrevDate)</nobr></div>
169 @ </td></tr>
170
--- src/finfo.c
+++ src/finfo.c
@@ -159,11 +159,11 @@
159 int gidx;
160 char zTime[10];
161 char zShort[20];
162 char zShortCkin[20];
163 if( zBr==0 ) zBr = "trunk";
164 gidx = graph_add_row(pGraph, frid, fpid>0 ? 1 : 0, &fpid, zBr, zBgClr);
165 if( memcmp(zDate, zPrevDate, 10) ){
166 sprintf(zPrevDate, "%.10s", zDate);
167 @ <tr><td>
168 @ <div class="divider"><nobr>%s(zPrevDate)</nobr></div>
169 @ </td></tr>
170
+31 -16
--- src/graph.c
+++ src/graph.c
@@ -38,10 +38,11 @@
3838
struct GraphRow {
3939
int rid; /* The rid for the check-in */
4040
int nParent; /* Number of parents */
4141
int aParent[GR_MAX_PARENT]; /* Array of parents. 0 element is primary .*/
4242
char *zBranch; /* Branch name */
43
+ char *zBgClr; /* Background Color */
4344
4445
GraphRow *pNext; /* Next row down in the list of all rows */
4546
GraphRow *pPrev; /* Previous row */
4647
4748
int idx; /* Row index. First is 1. 0 used for "none" */
@@ -140,10 +141,12 @@
140141
141142
/*
142143
** Return the canonical pointer for a given branch name.
143144
** Multiple calls to this routine with equivalent strings
144145
** will return the same pointer.
146
+**
147
+** Note: also used for background color names.
145148
*/
146149
static char *persistBranchName(GraphContext *p, const char *zBranch){
147150
int i;
148151
for(i=0; i<p->nBranch; i++){
149152
if( strcmp(zBranch, p->azBranch[i])==0 ) return p->azBranch[i];
@@ -161,20 +164,23 @@
161164
int graph_add_row(
162165
GraphContext *p, /* The context to which the row is added */
163166
int rid, /* RID for the check-in */
164167
int nParent, /* Number of parents */
165168
int *aParent, /* Array of parents */
166
- const char *zBranch /* Branch for this check-in */
169
+ const char *zBranch, /* Branch for this check-in */
170
+ const char *zBgClr /* Background color. NULL or "" for white. */
167171
){
168172
GraphRow *pRow;
169173
170174
if( p->nErr ) return 0;
171175
if( nParent>GR_MAX_PARENT ){ p->nErr++; return 0; }
172176
pRow = (GraphRow*)safeMalloc( sizeof(GraphRow) );
173177
pRow->rid = rid;
174178
pRow->nParent = nParent;
175179
pRow->zBranch = persistBranchName(p, zBranch);
180
+ if( zBgClr==0 || zBgClr[0]==0 ) zBgClr = "white";
181
+ pRow->zBgClr = persistBranchName(p, zBgClr);
176182
memcpy(pRow->aParent, aParent, sizeof(aParent[0])*nParent);
177183
if( p->pFirst==0 ){
178184
p->pFirst = pRow;
179185
}else{
180186
p->pLast->pNext = pRow;
@@ -229,10 +235,11 @@
229235
GraphRow *pRow, *pDesc, *pDup, *pLoop;
230236
int i;
231237
u32 mask;
232238
u32 inUse;
233239
int hasDup = 0; /* True if one or more isDup entries */
240
+ const char *zTrunk;
234241
235242
if( p==0 || p->pFirst==0 || p->nErr ) return;
236243
237244
/* Initialize all rows */
238245
p->nHash = p->nRow*2 + 1;
@@ -278,25 +285,33 @@
278285
}
279286
280287
/* Identify rows where the primary parent is off screen. Assign
281288
** each to a rail and draw descenders to the bottom of the screen.
282289
*/
283
- for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
284
- if( pRow->nParent==0 || hashFind(p,pRow->aParent[0])==0 ){
285
- if( omitDescenders ){
286
- pRow->iRail = findFreeRail(p, pRow->idx, pRow->idx, 0, 0);
287
- }else{
288
- pRow->iRail = ++p->mxRail;
289
- }
290
- mask = 1<<(pRow->iRail);
291
- if( omitDescenders ){
292
- pRow->railInUse |= mask;
293
- if( pRow->pNext ) pRow->pNext->railInUse |= mask;
294
- }else{
295
- pRow->bDescender = pRow->nParent>0;
296
- for(pDesc=pRow; pDesc; pDesc=pDesc->pNext){
297
- pDesc->railInUse |= mask;
290
+ zTrunk = persistBranchName(p, "trunk");
291
+ for(i=0; i<2; i++){
292
+ for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
293
+ if( i==0 ){
294
+ if( pRow->zBranch!=zTrunk ) continue;
295
+ }else {
296
+ if( pRow->iRail>=0 ) continue;
297
+ }
298
+ if( pRow->nParent==0 || hashFind(p,pRow->aParent[0])==0 ){
299
+ if( omitDescenders ){
300
+ pRow->iRail = findFreeRail(p, pRow->idx, pRow->idx, 0, 0);
301
+ }else{
302
+ pRow->iRail = ++p->mxRail;
303
+ }
304
+ mask = 1<<(pRow->iRail);
305
+ if( omitDescenders ){
306
+ pRow->railInUse |= mask;
307
+ if( pRow->pNext ) pRow->pNext->railInUse |= mask;
308
+ }else{
309
+ pRow->bDescender = pRow->nParent>0;
310
+ for(pDesc=pRow; pDesc; pDesc=pDesc->pNext){
311
+ pDesc->railInUse |= mask;
312
+ }
298313
}
299314
}
300315
}
301316
}
302317
303318
--- src/graph.c
+++ src/graph.c
@@ -38,10 +38,11 @@
38 struct GraphRow {
39 int rid; /* The rid for the check-in */
40 int nParent; /* Number of parents */
41 int aParent[GR_MAX_PARENT]; /* Array of parents. 0 element is primary .*/
42 char *zBranch; /* Branch name */
 
43
44 GraphRow *pNext; /* Next row down in the list of all rows */
45 GraphRow *pPrev; /* Previous row */
46
47 int idx; /* Row index. First is 1. 0 used for "none" */
@@ -140,10 +141,12 @@
140
141 /*
142 ** Return the canonical pointer for a given branch name.
143 ** Multiple calls to this routine with equivalent strings
144 ** will return the same pointer.
 
 
145 */
146 static char *persistBranchName(GraphContext *p, const char *zBranch){
147 int i;
148 for(i=0; i<p->nBranch; i++){
149 if( strcmp(zBranch, p->azBranch[i])==0 ) return p->azBranch[i];
@@ -161,20 +164,23 @@
161 int graph_add_row(
162 GraphContext *p, /* The context to which the row is added */
163 int rid, /* RID for the check-in */
164 int nParent, /* Number of parents */
165 int *aParent, /* Array of parents */
166 const char *zBranch /* Branch for this check-in */
 
167 ){
168 GraphRow *pRow;
169
170 if( p->nErr ) return 0;
171 if( nParent>GR_MAX_PARENT ){ p->nErr++; return 0; }
172 pRow = (GraphRow*)safeMalloc( sizeof(GraphRow) );
173 pRow->rid = rid;
174 pRow->nParent = nParent;
175 pRow->zBranch = persistBranchName(p, zBranch);
 
 
176 memcpy(pRow->aParent, aParent, sizeof(aParent[0])*nParent);
177 if( p->pFirst==0 ){
178 p->pFirst = pRow;
179 }else{
180 p->pLast->pNext = pRow;
@@ -229,10 +235,11 @@
229 GraphRow *pRow, *pDesc, *pDup, *pLoop;
230 int i;
231 u32 mask;
232 u32 inUse;
233 int hasDup = 0; /* True if one or more isDup entries */
 
234
235 if( p==0 || p->pFirst==0 || p->nErr ) return;
236
237 /* Initialize all rows */
238 p->nHash = p->nRow*2 + 1;
@@ -278,25 +285,33 @@
278 }
279
280 /* Identify rows where the primary parent is off screen. Assign
281 ** each to a rail and draw descenders to the bottom of the screen.
282 */
283 for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
284 if( pRow->nParent==0 || hashFind(p,pRow->aParent[0])==0 ){
285 if( omitDescenders ){
286 pRow->iRail = findFreeRail(p, pRow->idx, pRow->idx, 0, 0);
287 }else{
288 pRow->iRail = ++p->mxRail;
289 }
290 mask = 1<<(pRow->iRail);
291 if( omitDescenders ){
292 pRow->railInUse |= mask;
293 if( pRow->pNext ) pRow->pNext->railInUse |= mask;
294 }else{
295 pRow->bDescender = pRow->nParent>0;
296 for(pDesc=pRow; pDesc; pDesc=pDesc->pNext){
297 pDesc->railInUse |= mask;
 
 
 
 
 
 
 
 
298 }
299 }
300 }
301 }
302
303
--- src/graph.c
+++ src/graph.c
@@ -38,10 +38,11 @@
38 struct GraphRow {
39 int rid; /* The rid for the check-in */
40 int nParent; /* Number of parents */
41 int aParent[GR_MAX_PARENT]; /* Array of parents. 0 element is primary .*/
42 char *zBranch; /* Branch name */
43 char *zBgClr; /* Background Color */
44
45 GraphRow *pNext; /* Next row down in the list of all rows */
46 GraphRow *pPrev; /* Previous row */
47
48 int idx; /* Row index. First is 1. 0 used for "none" */
@@ -140,10 +141,12 @@
141
142 /*
143 ** Return the canonical pointer for a given branch name.
144 ** Multiple calls to this routine with equivalent strings
145 ** will return the same pointer.
146 **
147 ** Note: also used for background color names.
148 */
149 static char *persistBranchName(GraphContext *p, const char *zBranch){
150 int i;
151 for(i=0; i<p->nBranch; i++){
152 if( strcmp(zBranch, p->azBranch[i])==0 ) return p->azBranch[i];
@@ -161,20 +164,23 @@
164 int graph_add_row(
165 GraphContext *p, /* The context to which the row is added */
166 int rid, /* RID for the check-in */
167 int nParent, /* Number of parents */
168 int *aParent, /* Array of parents */
169 const char *zBranch, /* Branch for this check-in */
170 const char *zBgClr /* Background color. NULL or "" for white. */
171 ){
172 GraphRow *pRow;
173
174 if( p->nErr ) return 0;
175 if( nParent>GR_MAX_PARENT ){ p->nErr++; return 0; }
176 pRow = (GraphRow*)safeMalloc( sizeof(GraphRow) );
177 pRow->rid = rid;
178 pRow->nParent = nParent;
179 pRow->zBranch = persistBranchName(p, zBranch);
180 if( zBgClr==0 || zBgClr[0]==0 ) zBgClr = "white";
181 pRow->zBgClr = persistBranchName(p, zBgClr);
182 memcpy(pRow->aParent, aParent, sizeof(aParent[0])*nParent);
183 if( p->pFirst==0 ){
184 p->pFirst = pRow;
185 }else{
186 p->pLast->pNext = pRow;
@@ -229,10 +235,11 @@
235 GraphRow *pRow, *pDesc, *pDup, *pLoop;
236 int i;
237 u32 mask;
238 u32 inUse;
239 int hasDup = 0; /* True if one or more isDup entries */
240 const char *zTrunk;
241
242 if( p==0 || p->pFirst==0 || p->nErr ) return;
243
244 /* Initialize all rows */
245 p->nHash = p->nRow*2 + 1;
@@ -278,25 +285,33 @@
285 }
286
287 /* Identify rows where the primary parent is off screen. Assign
288 ** each to a rail and draw descenders to the bottom of the screen.
289 */
290 zTrunk = persistBranchName(p, "trunk");
291 for(i=0; i<2; i++){
292 for(pRow=p->pFirst; pRow; pRow=pRow->pNext){
293 if( i==0 ){
294 if( pRow->zBranch!=zTrunk ) continue;
295 }else {
296 if( pRow->iRail>=0 ) continue;
297 }
298 if( pRow->nParent==0 || hashFind(p,pRow->aParent[0])==0 ){
299 if( omitDescenders ){
300 pRow->iRail = findFreeRail(p, pRow->idx, pRow->idx, 0, 0);
301 }else{
302 pRow->iRail = ++p->mxRail;
303 }
304 mask = 1<<(pRow->iRail);
305 if( omitDescenders ){
306 pRow->railInUse |= mask;
307 if( pRow->pNext ) pRow->pNext->railInUse |= mask;
308 }else{
309 pRow->bDescender = pRow->nParent>0;
310 for(pDesc=pRow; pDesc; pDesc=pDesc->pNext){
311 pDesc->railInUse |= mask;
312 }
313 }
314 }
315 }
316 }
317
318
+6 -1
--- src/http.c
+++ src/http.c
@@ -55,11 +55,16 @@
5555
sha1sum_blob(pPayload, &nonce);
5656
blob_copy(&pw, &nonce);
5757
zLogin = g.urlUser;
5858
if( g.urlPasswd ){
5959
zPw = g.urlPasswd;
60
+ }else if( g.cgiOutput ){
61
+ /* Password failure while doing a sync from the web interface */
62
+ cgi_printf("*** incorrect or missing password for user %h\n", zLogin);
63
+ zPw = 0;
6064
}else{
65
+ /* Password failure while doing a sync from the command-line interface */
6166
url_prompt_for_password();
6267
zPw = g.urlPasswd;
6368
if( !g.dontKeepUrl ) db_set("last-sync-pw", zPw, 0);
6469
}
6570
@@ -223,11 +228,11 @@
223228
int i, j;
224229
for(i=9; zLine[i] && zLine[i]==' '; i++){}
225230
if( zLine[i]==0 ) fossil_fatal("malformed redirect: %s", zLine);
226231
j = strlen(zLine) - 1;
227232
if( j>4 && strcmp(&zLine[j-4],"/xfer")==0 ) zLine[j-4] = 0;
228
- printf("redirect to %s\n", &zLine[i]);
233
+ fossil_print("redirect to %s\n", &zLine[i]);
229234
url_parse(&zLine[i]);
230235
transport_close();
231236
http_exchange(pSend, pReply, useLogin);
232237
return;
233238
}
234239
--- src/http.c
+++ src/http.c
@@ -55,11 +55,16 @@
55 sha1sum_blob(pPayload, &nonce);
56 blob_copy(&pw, &nonce);
57 zLogin = g.urlUser;
58 if( g.urlPasswd ){
59 zPw = g.urlPasswd;
 
 
 
 
60 }else{
 
61 url_prompt_for_password();
62 zPw = g.urlPasswd;
63 if( !g.dontKeepUrl ) db_set("last-sync-pw", zPw, 0);
64 }
65
@@ -223,11 +228,11 @@
223 int i, j;
224 for(i=9; zLine[i] && zLine[i]==' '; i++){}
225 if( zLine[i]==0 ) fossil_fatal("malformed redirect: %s", zLine);
226 j = strlen(zLine) - 1;
227 if( j>4 && strcmp(&zLine[j-4],"/xfer")==0 ) zLine[j-4] = 0;
228 printf("redirect to %s\n", &zLine[i]);
229 url_parse(&zLine[i]);
230 transport_close();
231 http_exchange(pSend, pReply, useLogin);
232 return;
233 }
234
--- src/http.c
+++ src/http.c
@@ -55,11 +55,16 @@
55 sha1sum_blob(pPayload, &nonce);
56 blob_copy(&pw, &nonce);
57 zLogin = g.urlUser;
58 if( g.urlPasswd ){
59 zPw = g.urlPasswd;
60 }else if( g.cgiOutput ){
61 /* Password failure while doing a sync from the web interface */
62 cgi_printf("*** incorrect or missing password for user %h\n", zLogin);
63 zPw = 0;
64 }else{
65 /* Password failure while doing a sync from the command-line interface */
66 url_prompt_for_password();
67 zPw = g.urlPasswd;
68 if( !g.dontKeepUrl ) db_set("last-sync-pw", zPw, 0);
69 }
70
@@ -223,11 +228,11 @@
228 int i, j;
229 for(i=9; zLine[i] && zLine[i]==' '; i++){}
230 if( zLine[i]==0 ) fossil_fatal("malformed redirect: %s", zLine);
231 j = strlen(zLine) - 1;
232 if( j>4 && strcmp(&zLine[j-4],"/xfer")==0 ) zLine[j-4] = 0;
233 fossil_print("redirect to %s\n", &zLine[i]);
234 url_parse(&zLine[i]);
235 transport_close();
236 http_exchange(pSend, pReply, useLogin);
237 return;
238 }
239
+58 -25
--- src/info.c
+++ src/info.c
@@ -269,12 +269,12 @@
269269
int showDiff;
270270
const char *zName;
271271
272272
login_check_credentials();
273273
if( !g.okRead ){ login_needed(); return; }
274
- zName = PD("name","0");
275
- rid = name_to_rid(zName);
274
+ zName = P("name");
275
+ rid = name_to_rid_www("name");
276276
if( rid==0 ){
277277
style_header("Check-in Information Error");
278278
@ No such object: %h(g.argv[2])
279279
style_footer();
280280
return;
@@ -456,11 +456,11 @@
456456
Stmt q;
457457
int rid;
458458
459459
login_check_credentials();
460460
if( !g.okRdWiki ){ login_needed(); return; }
461
- rid = name_to_rid(PD("name","0"));
461
+ rid = name_to_rid_www("name");
462462
if( rid==0 ){
463463
style_header("Wiki Page Information Error");
464464
@ No such object: %h(g.argv[2])
465465
style_footer();
466466
return;
@@ -542,11 +542,11 @@
542542
543543
login_check_credentials();
544544
if( !g.okRead ){ login_needed(); return; }
545545
login_anonymous_available();
546546
547
- rid = name_to_rid(PD("name",""));
547
+ rid = name_to_rid_www("name");
548548
if( rid==0 ){
549549
fossil_redirect_home();
550550
}
551551
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
552552
style_header("Check-in [%.10s]", zUuid);
@@ -610,11 +610,11 @@
610610
**
611611
** * It's artifact ID
612612
** * date of check-in
613613
** * Comment & user
614614
*/
615
-static void object_description(
615
+void object_description(
616616
int rid, /* The artifact ID */
617617
int linkToView, /* Add viewer link if true */
618618
Blob *pDownloadName /* Fill with an appropriate download name */
619619
){
620620
Stmt q;
@@ -735,11 +735,11 @@
735735
}
736736
db_prepare(&q,
737737
"SELECT target, filename, datetime(mtime), user, src"
738738
" FROM attachment"
739739
" WHERE src=(SELECT uuid FROM blob WHERE rid=%d)"
740
- " ORDER BY mtime DESC",
740
+ " ORDER BY mtime DESC /*sort*/",
741741
rid
742742
);
743743
while( db_step(&q)==SQLITE_ROW ){
744744
const char *zTarget = db_column_text(&q, 0);
745745
const char *zFilename = db_column_text(&q, 1);
@@ -797,10 +797,11 @@
797797
int v2 = name_to_rid(P("v2"));
798798
Blob c1, c2, diff;
799799
800800
login_check_credentials();
801801
if( !g.okRead ){ login_needed(); return; }
802
+ if( v1==0 || v2==0 ) fossil_redirect_home();
802803
style_header("Diff");
803804
@ <h2>Differences From:</h2>
804805
@ <blockquote>
805806
object_description(v1, 1, 0);
806807
@ </blockquote>
@@ -832,15 +833,15 @@
832833
void rawartifact_page(void){
833834
int rid;
834835
const char *zMime;
835836
Blob content;
836837
837
- rid = name_to_rid(PD("name","0"));
838
+ rid = name_to_rid_www("name");
838839
zMime = PD("m","application/x-fossil-artifact");
839840
login_check_credentials();
840841
if( !g.okRead ){ login_needed(); return; }
841
- if( rid==0 ){ cgi_redirect("/home"); }
842
+ if( rid==0 ) fossil_redirect_home();
842843
content_get(rid, &content);
843844
cgi_set_content_type(zMime);
844845
cgi_set_content(&content);
845846
}
846847
@@ -906,14 +907,14 @@
906907
int rid;
907908
Blob content;
908909
Blob downloadName;
909910
char *zUuid;
910911
911
- rid = name_to_rid(PD("name","0"));
912
+ rid = name_to_rid_www("name");
912913
login_check_credentials();
913914
if( !g.okRead ){ login_needed(); return; }
914
- if( rid==0 ){ cgi_redirect("/home"); }
915
+ if( rid==0 ) fossil_redirect_home();
915916
if( g.okAdmin ){
916917
const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
917918
if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){
918919
style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1",
919920
g.zTop, zUuid);
@@ -936,31 +937,66 @@
936937
@ <blockquote><pre>
937938
hexdump(&content);
938939
@ </pre></blockquote>
939940
style_footer();
940941
}
942
+
943
+/*
944
+** Look for "ci" and "filename" query parameters. If found, try to
945
+** use them to extract the record ID of an artifact for the file.
946
+*/
947
+int artifact_from_ci_and_filename(void){
948
+ const char *zFilename;
949
+ const char *zCI;
950
+ int cirid;
951
+ Blob content;
952
+ Manifest m;
953
+ int i;
954
+
955
+ zCI = P("ci");
956
+ if( zCI==0 ) return 0;
957
+ zFilename = P("filename");
958
+ if( zFilename==0 ) return 0;
959
+ cirid = name_to_rid_www("ci");
960
+ if( !content_get(cirid, &content) ) return 0;
961
+ if( !manifest_parse(&m, &content) ) return 0;
962
+ if( m.type!=CFTYPE_MANIFEST ) return 0;
963
+ for(i=0; i<m.nFile; i++){
964
+ if( strcmp(zFilename, m.aFile[i].zName)==0 ){
965
+ return db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", m.aFile[i].zUuid);
966
+ }
967
+ }
968
+ return 0;
969
+}
970
+
941971
942972
/*
943973
** WEBPAGE: artifact
944974
** URL: /artifact?name=ARTIFACTID
975
+** URL: /artifact?ci=CHECKIN&filename=PATH
945976
**
946977
** Show the complete content of a file identified by ARTIFACTID
947978
** as preformatted text.
948979
*/
949980
void artifact_page(void){
950
- int rid;
981
+ int rid = 0;
951982
Blob content;
952983
const char *zMime;
953984
Blob downloadName;
954985
int renderAsWiki = 0;
955986
int renderAsHtml = 0;
956987
const char *zUuid;
988
+ if( P("ci") && P("filename") ){
989
+ rid = artifact_from_ci_and_filename();
990
+ }
991
+ if( rid==0 ){
992
+ rid = name_to_rid_www("name");
993
+ }
957994
958
- rid = name_to_rid(PD("name","0"));
959995
login_check_credentials();
960996
if( !g.okRead ){ login_needed(); return; }
961
- if( rid==0 ){ cgi_redirect("/home"); }
997
+ if( rid==0 ) fossil_redirect_home();
962998
if( g.okAdmin ){
963999
const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
9641000
if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){
9651001
style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1",
9661002
g.zTop, zUuid);
@@ -1043,11 +1079,11 @@
10431079
char zTktName[20];
10441080
Manifest m;
10451081
10461082
login_check_credentials();
10471083
if( !g.okRdTkt ){ login_needed(); return; }
1048
- rid = name_to_rid(PD("name","0"));
1084
+ rid = name_to_rid_www("name");
10491085
if( rid==0 ){ fossil_redirect_home(); }
10501086
zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
10511087
if( g.okAdmin ){
10521088
if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){
10531089
style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1",
@@ -1093,11 +1129,11 @@
10931129
/*
10941130
** WEBPAGE: info
10951131
** URL: info/ARTIFACTID
10961132
**
10971133
** The argument is a artifact ID which might be a baseline or a file or
1098
-** a ticket changes or a wiki editor or something else.
1134
+** a ticket changes or a wiki edit or something else.
10991135
**
11001136
** Figure out what the artifact ID is and jump to it.
11011137
*/
11021138
void info_page(void){
11031139
const char *zName;
@@ -1105,11 +1141,11 @@
11051141
int rid;
11061142
11071143
zName = P("name");
11081144
if( zName==0 ) fossil_redirect_home();
11091145
if( validate16(zName, strlen(zName))
1110
- && db_exists("SELECT 1 FROM ticket WHERE tkt_uuid LIKE '%q%%'", zName) ){
1146
+ && db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){
11111147
tktview_page();
11121148
return;
11131149
}
11141150
blob_set(&uuid, zName);
11151151
if( name_to_uuid(&uuid, 1) ){
@@ -1438,19 +1474,16 @@
14381474
}
14391475
}
14401476
db_finalize(&q);
14411477
@ </td></tr>
14421478
1443
- if( db_exists("SELECT 1 FROM tagxref WHERE rid=%d AND tagid=%d AND srcid>0",
1444
- rid, TAG_BRANCH)==0 ){
1445
- @ <tr><td align="right" valign="top"><b>Branching:</b></td>
1446
- @ <td valign="top">
1447
- @ <input type="checkbox" name="newbr"%s(zNewBrFlag)>
1448
- @ Make this check-in the start of a new branch named:
1449
- @ <input type="text" width="15" name="brname" value="%h(zNewBranch)">
1450
- @ </td></tr>
1451
- }
1479
+ @ <tr><td align="right" valign="top"><b>Branching:</b></td>
1480
+ @ <td valign="top">
1481
+ @ <input type="checkbox" name="newbr"%s(zNewBrFlag)>
1482
+ @ Make this check-in the start of a new branch named:
1483
+ @ <input type="text" width="15" name="brname" value="%h(zNewBranch)">
1484
+ @ </td></tr>
14521485
14531486
if( is_a_leaf(rid)
14541487
&& !db_exists("SELECT 1 FROM tagxref "
14551488
" WHERE tagid=%d AND rid=%d AND tagtype>0",
14561489
TAG_CLOSED, rid)
14571490
--- src/info.c
+++ src/info.c
@@ -269,12 +269,12 @@
269 int showDiff;
270 const char *zName;
271
272 login_check_credentials();
273 if( !g.okRead ){ login_needed(); return; }
274 zName = PD("name","0");
275 rid = name_to_rid(zName);
276 if( rid==0 ){
277 style_header("Check-in Information Error");
278 @ No such object: %h(g.argv[2])
279 style_footer();
280 return;
@@ -456,11 +456,11 @@
456 Stmt q;
457 int rid;
458
459 login_check_credentials();
460 if( !g.okRdWiki ){ login_needed(); return; }
461 rid = name_to_rid(PD("name","0"));
462 if( rid==0 ){
463 style_header("Wiki Page Information Error");
464 @ No such object: %h(g.argv[2])
465 style_footer();
466 return;
@@ -542,11 +542,11 @@
542
543 login_check_credentials();
544 if( !g.okRead ){ login_needed(); return; }
545 login_anonymous_available();
546
547 rid = name_to_rid(PD("name",""));
548 if( rid==0 ){
549 fossil_redirect_home();
550 }
551 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
552 style_header("Check-in [%.10s]", zUuid);
@@ -610,11 +610,11 @@
610 **
611 ** * It's artifact ID
612 ** * date of check-in
613 ** * Comment & user
614 */
615 static void object_description(
616 int rid, /* The artifact ID */
617 int linkToView, /* Add viewer link if true */
618 Blob *pDownloadName /* Fill with an appropriate download name */
619 ){
620 Stmt q;
@@ -735,11 +735,11 @@
735 }
736 db_prepare(&q,
737 "SELECT target, filename, datetime(mtime), user, src"
738 " FROM attachment"
739 " WHERE src=(SELECT uuid FROM blob WHERE rid=%d)"
740 " ORDER BY mtime DESC",
741 rid
742 );
743 while( db_step(&q)==SQLITE_ROW ){
744 const char *zTarget = db_column_text(&q, 0);
745 const char *zFilename = db_column_text(&q, 1);
@@ -797,10 +797,11 @@
797 int v2 = name_to_rid(P("v2"));
798 Blob c1, c2, diff;
799
800 login_check_credentials();
801 if( !g.okRead ){ login_needed(); return; }
 
802 style_header("Diff");
803 @ <h2>Differences From:</h2>
804 @ <blockquote>
805 object_description(v1, 1, 0);
806 @ </blockquote>
@@ -832,15 +833,15 @@
832 void rawartifact_page(void){
833 int rid;
834 const char *zMime;
835 Blob content;
836
837 rid = name_to_rid(PD("name","0"));
838 zMime = PD("m","application/x-fossil-artifact");
839 login_check_credentials();
840 if( !g.okRead ){ login_needed(); return; }
841 if( rid==0 ){ cgi_redirect("/home"); }
842 content_get(rid, &content);
843 cgi_set_content_type(zMime);
844 cgi_set_content(&content);
845 }
846
@@ -906,14 +907,14 @@
906 int rid;
907 Blob content;
908 Blob downloadName;
909 char *zUuid;
910
911 rid = name_to_rid(PD("name","0"));
912 login_check_credentials();
913 if( !g.okRead ){ login_needed(); return; }
914 if( rid==0 ){ cgi_redirect("/home"); }
915 if( g.okAdmin ){
916 const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
917 if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){
918 style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1",
919 g.zTop, zUuid);
@@ -936,31 +937,66 @@
936 @ <blockquote><pre>
937 hexdump(&content);
938 @ </pre></blockquote>
939 style_footer();
940 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
941
942 /*
943 ** WEBPAGE: artifact
944 ** URL: /artifact?name=ARTIFACTID
 
945 **
946 ** Show the complete content of a file identified by ARTIFACTID
947 ** as preformatted text.
948 */
949 void artifact_page(void){
950 int rid;
951 Blob content;
952 const char *zMime;
953 Blob downloadName;
954 int renderAsWiki = 0;
955 int renderAsHtml = 0;
956 const char *zUuid;
 
 
 
 
 
 
957
958 rid = name_to_rid(PD("name","0"));
959 login_check_credentials();
960 if( !g.okRead ){ login_needed(); return; }
961 if( rid==0 ){ cgi_redirect("/home"); }
962 if( g.okAdmin ){
963 const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
964 if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){
965 style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1",
966 g.zTop, zUuid);
@@ -1043,11 +1079,11 @@
1043 char zTktName[20];
1044 Manifest m;
1045
1046 login_check_credentials();
1047 if( !g.okRdTkt ){ login_needed(); return; }
1048 rid = name_to_rid(PD("name","0"));
1049 if( rid==0 ){ fossil_redirect_home(); }
1050 zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
1051 if( g.okAdmin ){
1052 if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){
1053 style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1",
@@ -1093,11 +1129,11 @@
1093 /*
1094 ** WEBPAGE: info
1095 ** URL: info/ARTIFACTID
1096 **
1097 ** The argument is a artifact ID which might be a baseline or a file or
1098 ** a ticket changes or a wiki editor or something else.
1099 **
1100 ** Figure out what the artifact ID is and jump to it.
1101 */
1102 void info_page(void){
1103 const char *zName;
@@ -1105,11 +1141,11 @@
1105 int rid;
1106
1107 zName = P("name");
1108 if( zName==0 ) fossil_redirect_home();
1109 if( validate16(zName, strlen(zName))
1110 && db_exists("SELECT 1 FROM ticket WHERE tkt_uuid LIKE '%q%%'", zName) ){
1111 tktview_page();
1112 return;
1113 }
1114 blob_set(&uuid, zName);
1115 if( name_to_uuid(&uuid, 1) ){
@@ -1438,19 +1474,16 @@
1438 }
1439 }
1440 db_finalize(&q);
1441 @ </td></tr>
1442
1443 if( db_exists("SELECT 1 FROM tagxref WHERE rid=%d AND tagid=%d AND srcid>0",
1444 rid, TAG_BRANCH)==0 ){
1445 @ <tr><td align="right" valign="top"><b>Branching:</b></td>
1446 @ <td valign="top">
1447 @ <input type="checkbox" name="newbr"%s(zNewBrFlag)>
1448 @ Make this check-in the start of a new branch named:
1449 @ <input type="text" width="15" name="brname" value="%h(zNewBranch)">
1450 @ </td></tr>
1451 }
1452
1453 if( is_a_leaf(rid)
1454 && !db_exists("SELECT 1 FROM tagxref "
1455 " WHERE tagid=%d AND rid=%d AND tagtype>0",
1456 TAG_CLOSED, rid)
1457
--- src/info.c
+++ src/info.c
@@ -269,12 +269,12 @@
269 int showDiff;
270 const char *zName;
271
272 login_check_credentials();
273 if( !g.okRead ){ login_needed(); return; }
274 zName = P("name");
275 rid = name_to_rid_www("name");
276 if( rid==0 ){
277 style_header("Check-in Information Error");
278 @ No such object: %h(g.argv[2])
279 style_footer();
280 return;
@@ -456,11 +456,11 @@
456 Stmt q;
457 int rid;
458
459 login_check_credentials();
460 if( !g.okRdWiki ){ login_needed(); return; }
461 rid = name_to_rid_www("name");
462 if( rid==0 ){
463 style_header("Wiki Page Information Error");
464 @ No such object: %h(g.argv[2])
465 style_footer();
466 return;
@@ -542,11 +542,11 @@
542
543 login_check_credentials();
544 if( !g.okRead ){ login_needed(); return; }
545 login_anonymous_available();
546
547 rid = name_to_rid_www("name");
548 if( rid==0 ){
549 fossil_redirect_home();
550 }
551 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
552 style_header("Check-in [%.10s]", zUuid);
@@ -610,11 +610,11 @@
610 **
611 ** * It's artifact ID
612 ** * date of check-in
613 ** * Comment & user
614 */
615 void object_description(
616 int rid, /* The artifact ID */
617 int linkToView, /* Add viewer link if true */
618 Blob *pDownloadName /* Fill with an appropriate download name */
619 ){
620 Stmt q;
@@ -735,11 +735,11 @@
735 }
736 db_prepare(&q,
737 "SELECT target, filename, datetime(mtime), user, src"
738 " FROM attachment"
739 " WHERE src=(SELECT uuid FROM blob WHERE rid=%d)"
740 " ORDER BY mtime DESC /*sort*/",
741 rid
742 );
743 while( db_step(&q)==SQLITE_ROW ){
744 const char *zTarget = db_column_text(&q, 0);
745 const char *zFilename = db_column_text(&q, 1);
@@ -797,10 +797,11 @@
797 int v2 = name_to_rid(P("v2"));
798 Blob c1, c2, diff;
799
800 login_check_credentials();
801 if( !g.okRead ){ login_needed(); return; }
802 if( v1==0 || v2==0 ) fossil_redirect_home();
803 style_header("Diff");
804 @ <h2>Differences From:</h2>
805 @ <blockquote>
806 object_description(v1, 1, 0);
807 @ </blockquote>
@@ -832,15 +833,15 @@
833 void rawartifact_page(void){
834 int rid;
835 const char *zMime;
836 Blob content;
837
838 rid = name_to_rid_www("name");
839 zMime = PD("m","application/x-fossil-artifact");
840 login_check_credentials();
841 if( !g.okRead ){ login_needed(); return; }
842 if( rid==0 ) fossil_redirect_home();
843 content_get(rid, &content);
844 cgi_set_content_type(zMime);
845 cgi_set_content(&content);
846 }
847
@@ -906,14 +907,14 @@
907 int rid;
908 Blob content;
909 Blob downloadName;
910 char *zUuid;
911
912 rid = name_to_rid_www("name");
913 login_check_credentials();
914 if( !g.okRead ){ login_needed(); return; }
915 if( rid==0 ) fossil_redirect_home();
916 if( g.okAdmin ){
917 const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
918 if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){
919 style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1",
920 g.zTop, zUuid);
@@ -936,31 +937,66 @@
937 @ <blockquote><pre>
938 hexdump(&content);
939 @ </pre></blockquote>
940 style_footer();
941 }
942
943 /*
944 ** Look for "ci" and "filename" query parameters. If found, try to
945 ** use them to extract the record ID of an artifact for the file.
946 */
947 int artifact_from_ci_and_filename(void){
948 const char *zFilename;
949 const char *zCI;
950 int cirid;
951 Blob content;
952 Manifest m;
953 int i;
954
955 zCI = P("ci");
956 if( zCI==0 ) return 0;
957 zFilename = P("filename");
958 if( zFilename==0 ) return 0;
959 cirid = name_to_rid_www("ci");
960 if( !content_get(cirid, &content) ) return 0;
961 if( !manifest_parse(&m, &content) ) return 0;
962 if( m.type!=CFTYPE_MANIFEST ) return 0;
963 for(i=0; i<m.nFile; i++){
964 if( strcmp(zFilename, m.aFile[i].zName)==0 ){
965 return db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", m.aFile[i].zUuid);
966 }
967 }
968 return 0;
969 }
970
971
972 /*
973 ** WEBPAGE: artifact
974 ** URL: /artifact?name=ARTIFACTID
975 ** URL: /artifact?ci=CHECKIN&filename=PATH
976 **
977 ** Show the complete content of a file identified by ARTIFACTID
978 ** as preformatted text.
979 */
980 void artifact_page(void){
981 int rid = 0;
982 Blob content;
983 const char *zMime;
984 Blob downloadName;
985 int renderAsWiki = 0;
986 int renderAsHtml = 0;
987 const char *zUuid;
988 if( P("ci") && P("filename") ){
989 rid = artifact_from_ci_and_filename();
990 }
991 if( rid==0 ){
992 rid = name_to_rid_www("name");
993 }
994
 
995 login_check_credentials();
996 if( !g.okRead ){ login_needed(); return; }
997 if( rid==0 ) fossil_redirect_home();
998 if( g.okAdmin ){
999 const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
1000 if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){
1001 style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1",
1002 g.zTop, zUuid);
@@ -1043,11 +1079,11 @@
1079 char zTktName[20];
1080 Manifest m;
1081
1082 login_check_credentials();
1083 if( !g.okRdTkt ){ login_needed(); return; }
1084 rid = name_to_rid_www("name");
1085 if( rid==0 ){ fossil_redirect_home(); }
1086 zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
1087 if( g.okAdmin ){
1088 if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){
1089 style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1",
@@ -1093,11 +1129,11 @@
1129 /*
1130 ** WEBPAGE: info
1131 ** URL: info/ARTIFACTID
1132 **
1133 ** The argument is a artifact ID which might be a baseline or a file or
1134 ** a ticket changes or a wiki edit or something else.
1135 **
1136 ** Figure out what the artifact ID is and jump to it.
1137 */
1138 void info_page(void){
1139 const char *zName;
@@ -1105,11 +1141,11 @@
1141 int rid;
1142
1143 zName = P("name");
1144 if( zName==0 ) fossil_redirect_home();
1145 if( validate16(zName, strlen(zName))
1146 && db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){
1147 tktview_page();
1148 return;
1149 }
1150 blob_set(&uuid, zName);
1151 if( name_to_uuid(&uuid, 1) ){
@@ -1438,19 +1474,16 @@
1474 }
1475 }
1476 db_finalize(&q);
1477 @ </td></tr>
1478
1479 @ <tr><td align="right" valign="top"><b>Branching:</b></td>
1480 @ <td valign="top">
1481 @ <input type="checkbox" name="newbr"%s(zNewBrFlag)>
1482 @ Make this check-in the start of a new branch named:
1483 @ <input type="text" width="15" name="brname" value="%h(zNewBranch)">
1484 @ </td></tr>
 
 
 
1485
1486 if( is_a_leaf(rid)
1487 && !db_exists("SELECT 1 FROM tagxref "
1488 " WHERE tagid=%d AND rid=%d AND tagtype>0",
1489 TAG_CLOSED, rid)
1490
+10 -10
--- src/main.c
+++ src/main.c
@@ -78,11 +78,11 @@
7878
char *zTop; /* Parent directory of zPath */
7979
const char *zContentType; /* The content type of the input HTTP request */
8080
int iErrPriority; /* Priority of current error message */
8181
char *zErrMsg; /* Text of an error message */
8282
Blob cgiIn; /* Input to an xfer www method */
83
- int cgiPanic; /* Write error messages to CGI */
83
+ int cgiOutput; /* Write error and status messages to CGI */
8484
int xferPanic; /* Write error messages in XFER protocol */
8585
int fullHttpReply; /* True for full HTTP reply. False for CGI reply */
8686
Th_Interp *interp; /* The TH1 interpreter */
8787
FILE *httpIn; /* Accept HTTP input from here */
8888
FILE *httpOut; /* Send HTTP output here */
@@ -278,11 +278,11 @@
278278
static int once = 1;
279279
mainInFatalError = 1;
280280
va_start(ap, zFormat);
281281
z = vmprintf(zFormat, ap);
282282
va_end(ap);
283
- if( g.cgiPanic && once ){
283
+ if( g.cgiOutput && once ){
284284
once = 0;
285285
cgi_printf("<p><font color=\"red\">%h</font></p>", z);
286286
cgi_reply();
287287
}else{
288288
fprintf(stderr, "%s: %s\n", g.argv[0], z);
@@ -295,12 +295,12 @@
295295
va_list ap;
296296
mainInFatalError = 1;
297297
va_start(ap, zFormat);
298298
z = vmprintf(zFormat, ap);
299299
va_end(ap);
300
- if( g.cgiPanic ){
301
- g.cgiPanic = 0;
300
+ if( g.cgiOutput ){
301
+ g.cgiOutput = 0;
302302
cgi_printf("<p><font color=\"red\">%h</font></p>", z);
303303
cgi_reply();
304304
}else{
305305
fprintf(stderr, "%s: %s\n", g.argv[0], z);
306306
}
@@ -323,12 +323,12 @@
323323
if( mainInFatalError ) return;
324324
mainInFatalError = 1;
325325
va_start(ap, zFormat);
326326
z = vmprintf(zFormat, ap);
327327
va_end(ap);
328
- if( g.cgiPanic ){
329
- g.cgiPanic = 0;
328
+ if( g.cgiOutput ){
329
+ g.cgiOutput = 0;
330330
cgi_printf("<p><font color=\"red\">%h</font></p>", z);
331331
cgi_reply();
332332
}else{
333333
fprintf(stderr, "%s: %s\n", g.argv[0], z);
334334
}
@@ -342,11 +342,11 @@
342342
char *z;
343343
va_list ap;
344344
va_start(ap, zFormat);
345345
z = vmprintf(zFormat, ap);
346346
va_end(ap);
347
- if( g.cgiPanic ){
347
+ if( g.cgiOutput ){
348348
cgi_printf("<p><font color=\"red\">%h</font></p>", z);
349349
}else{
350350
fprintf(stderr, "%s: %s\n", g.argv[0], z);
351351
}
352352
}
@@ -811,11 +811,11 @@
811811
#ifdef __EMX__
812812
/* Similar hack for OS/2 */
813813
setmode(fileno(g.httpOut), O_BINARY);
814814
setmode(fileno(g.httpIn), O_BINARY);
815815
#endif
816
- g.cgiPanic = 1;
816
+ g.cgiOutput = 1;
817817
blob_read_from_file(&config, zFile);
818818
while( blob_line(&config, &line) ){
819819
if( !blob_token(&line, &key) ) continue;
820820
if( blob_buffer(&key)[0]=='#' ) continue;
821821
if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){
@@ -909,11 +909,11 @@
909909
const char *zNotFound;
910910
zNotFound = find_option("notfound", 0, 1);
911911
if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
912912
cgi_panic("no repository specified");
913913
}
914
- g.cgiPanic = 1;
914
+ g.cgiOutput = 1;
915915
g.fullHttpReply = 1;
916916
if( g.argc==6 ){
917917
g.httpIn = fopen(g.argv[3], "rb");
918918
g.httpOut = fopen(g.argv[4], "wb");
919919
zIpAddr = g.argv[5];
@@ -1039,11 +1039,11 @@
10391039
g.httpIn = stdin;
10401040
g.httpOut = stdout;
10411041
if( g.fHttpTrace || g.fSqlTrace ){
10421042
fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
10431043
}
1044
- g.cgiPanic = 1;
1044
+ g.cgiOutput = 1;
10451045
find_server_repository(isUiCmd);
10461046
g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
10471047
cgi_handle_http_request(0);
10481048
process_one_web_page(zNotFound);
10491049
#else
10501050
--- src/main.c
+++ src/main.c
@@ -78,11 +78,11 @@
78 char *zTop; /* Parent directory of zPath */
79 const char *zContentType; /* The content type of the input HTTP request */
80 int iErrPriority; /* Priority of current error message */
81 char *zErrMsg; /* Text of an error message */
82 Blob cgiIn; /* Input to an xfer www method */
83 int cgiPanic; /* Write error messages to CGI */
84 int xferPanic; /* Write error messages in XFER protocol */
85 int fullHttpReply; /* True for full HTTP reply. False for CGI reply */
86 Th_Interp *interp; /* The TH1 interpreter */
87 FILE *httpIn; /* Accept HTTP input from here */
88 FILE *httpOut; /* Send HTTP output here */
@@ -278,11 +278,11 @@
278 static int once = 1;
279 mainInFatalError = 1;
280 va_start(ap, zFormat);
281 z = vmprintf(zFormat, ap);
282 va_end(ap);
283 if( g.cgiPanic && once ){
284 once = 0;
285 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
286 cgi_reply();
287 }else{
288 fprintf(stderr, "%s: %s\n", g.argv[0], z);
@@ -295,12 +295,12 @@
295 va_list ap;
296 mainInFatalError = 1;
297 va_start(ap, zFormat);
298 z = vmprintf(zFormat, ap);
299 va_end(ap);
300 if( g.cgiPanic ){
301 g.cgiPanic = 0;
302 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
303 cgi_reply();
304 }else{
305 fprintf(stderr, "%s: %s\n", g.argv[0], z);
306 }
@@ -323,12 +323,12 @@
323 if( mainInFatalError ) return;
324 mainInFatalError = 1;
325 va_start(ap, zFormat);
326 z = vmprintf(zFormat, ap);
327 va_end(ap);
328 if( g.cgiPanic ){
329 g.cgiPanic = 0;
330 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
331 cgi_reply();
332 }else{
333 fprintf(stderr, "%s: %s\n", g.argv[0], z);
334 }
@@ -342,11 +342,11 @@
342 char *z;
343 va_list ap;
344 va_start(ap, zFormat);
345 z = vmprintf(zFormat, ap);
346 va_end(ap);
347 if( g.cgiPanic ){
348 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
349 }else{
350 fprintf(stderr, "%s: %s\n", g.argv[0], z);
351 }
352 }
@@ -811,11 +811,11 @@
811 #ifdef __EMX__
812 /* Similar hack for OS/2 */
813 setmode(fileno(g.httpOut), O_BINARY);
814 setmode(fileno(g.httpIn), O_BINARY);
815 #endif
816 g.cgiPanic = 1;
817 blob_read_from_file(&config, zFile);
818 while( blob_line(&config, &line) ){
819 if( !blob_token(&line, &key) ) continue;
820 if( blob_buffer(&key)[0]=='#' ) continue;
821 if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){
@@ -909,11 +909,11 @@
909 const char *zNotFound;
910 zNotFound = find_option("notfound", 0, 1);
911 if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
912 cgi_panic("no repository specified");
913 }
914 g.cgiPanic = 1;
915 g.fullHttpReply = 1;
916 if( g.argc==6 ){
917 g.httpIn = fopen(g.argv[3], "rb");
918 g.httpOut = fopen(g.argv[4], "wb");
919 zIpAddr = g.argv[5];
@@ -1039,11 +1039,11 @@
1039 g.httpIn = stdin;
1040 g.httpOut = stdout;
1041 if( g.fHttpTrace || g.fSqlTrace ){
1042 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
1043 }
1044 g.cgiPanic = 1;
1045 find_server_repository(isUiCmd);
1046 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
1047 cgi_handle_http_request(0);
1048 process_one_web_page(zNotFound);
1049 #else
1050
--- src/main.c
+++ src/main.c
@@ -78,11 +78,11 @@
78 char *zTop; /* Parent directory of zPath */
79 const char *zContentType; /* The content type of the input HTTP request */
80 int iErrPriority; /* Priority of current error message */
81 char *zErrMsg; /* Text of an error message */
82 Blob cgiIn; /* Input to an xfer www method */
83 int cgiOutput; /* Write error and status messages to CGI */
84 int xferPanic; /* Write error messages in XFER protocol */
85 int fullHttpReply; /* True for full HTTP reply. False for CGI reply */
86 Th_Interp *interp; /* The TH1 interpreter */
87 FILE *httpIn; /* Accept HTTP input from here */
88 FILE *httpOut; /* Send HTTP output here */
@@ -278,11 +278,11 @@
278 static int once = 1;
279 mainInFatalError = 1;
280 va_start(ap, zFormat);
281 z = vmprintf(zFormat, ap);
282 va_end(ap);
283 if( g.cgiOutput && once ){
284 once = 0;
285 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
286 cgi_reply();
287 }else{
288 fprintf(stderr, "%s: %s\n", g.argv[0], z);
@@ -295,12 +295,12 @@
295 va_list ap;
296 mainInFatalError = 1;
297 va_start(ap, zFormat);
298 z = vmprintf(zFormat, ap);
299 va_end(ap);
300 if( g.cgiOutput ){
301 g.cgiOutput = 0;
302 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
303 cgi_reply();
304 }else{
305 fprintf(stderr, "%s: %s\n", g.argv[0], z);
306 }
@@ -323,12 +323,12 @@
323 if( mainInFatalError ) return;
324 mainInFatalError = 1;
325 va_start(ap, zFormat);
326 z = vmprintf(zFormat, ap);
327 va_end(ap);
328 if( g.cgiOutput ){
329 g.cgiOutput = 0;
330 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
331 cgi_reply();
332 }else{
333 fprintf(stderr, "%s: %s\n", g.argv[0], z);
334 }
@@ -342,11 +342,11 @@
342 char *z;
343 va_list ap;
344 va_start(ap, zFormat);
345 z = vmprintf(zFormat, ap);
346 va_end(ap);
347 if( g.cgiOutput ){
348 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
349 }else{
350 fprintf(stderr, "%s: %s\n", g.argv[0], z);
351 }
352 }
@@ -811,11 +811,11 @@
811 #ifdef __EMX__
812 /* Similar hack for OS/2 */
813 setmode(fileno(g.httpOut), O_BINARY);
814 setmode(fileno(g.httpIn), O_BINARY);
815 #endif
816 g.cgiOutput = 1;
817 blob_read_from_file(&config, zFile);
818 while( blob_line(&config, &line) ){
819 if( !blob_token(&line, &key) ) continue;
820 if( blob_buffer(&key)[0]=='#' ) continue;
821 if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){
@@ -909,11 +909,11 @@
909 const char *zNotFound;
910 zNotFound = find_option("notfound", 0, 1);
911 if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
912 cgi_panic("no repository specified");
913 }
914 g.cgiOutput = 1;
915 g.fullHttpReply = 1;
916 if( g.argc==6 ){
917 g.httpIn = fopen(g.argv[3], "rb");
918 g.httpOut = fopen(g.argv[4], "wb");
919 zIpAddr = g.argv[5];
@@ -1039,11 +1039,11 @@
1039 g.httpIn = stdin;
1040 g.httpOut = stdout;
1041 if( g.fHttpTrace || g.fSqlTrace ){
1042 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
1043 }
1044 g.cgiOutput = 1;
1045 find_server_repository(isUiCmd);
1046 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
1047 cgi_handle_http_request(0);
1048 process_one_web_page(zNotFound);
1049 #else
1050
+75 -3
--- src/name.c
+++ src/name.c
@@ -43,11 +43,12 @@
4343
** If the input is not a tag, then try to match it as an ISO-8601 date
4444
** string YYYY-MM-DD HH:MM:SS and pick the nearest check-in to that date.
4545
** If the input is of the form "date:*" or "localtime:*" or "utc:*" then
4646
** always resolve the name as a date.
4747
**
48
-** Return the number of errors.
48
+** Return 0 on success. Return 1 if the name cannot be resolved.
49
+** Return 2 name is ambiguous.
4950
*/
5051
int name_to_uuid(Blob *pName, int iErrPriority){
5152
int rc;
5253
int sz;
5354
sz = blob_size(pName);
@@ -102,11 +103,11 @@
102103
fossil_error(iErrPriority,
103104
"multiple artifacts match"
104105
);
105106
blob_reset(pName);
106107
db_finalize(&q);
107
- return 1;
108
+ return 2;
108109
}
109110
db_finalize(&q);
110111
rc = 0;
111112
}else{
112113
rc = 0;
@@ -273,11 +274,11 @@
273274
** Convert a name to a rid. If the name is a small integer value then
274275
** just use atoi() to do the conversion. If the name contains alphabetic
275276
** characters or is not an existing rid, then use name_to_uuid then
276277
** convert the uuid to a rid.
277278
**
278
-** This routine is used in test routines to resolve command-line inputs
279
+** This routine is used by command-line routines to resolve command-line inputs
279280
** into a rid.
280281
*/
281282
int name_to_rid(const char *zName){
282283
int i;
283284
int rid;
@@ -300,5 +301,76 @@
300301
rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
301302
blob_reset(&name);
302303
}
303304
return rid;
304305
}
306
+
307
+/*
308
+** WEBPAGE: ambiguous
309
+** URL: /ambiguous?name=UUID&src=WEBPAGE
310
+**
311
+** The UUID given by the name paramager is ambiguous. Display a page
312
+** that shows all possible choices and let the user select between them.
313
+*/
314
+void ambiguous_page(void){
315
+ Stmt q;
316
+ const char *zName = P("name");
317
+ const char *zSrc = P("src");
318
+ char *z;
319
+
320
+ if( zName==0 || zName[0]==0 || zSrc==0 || zSrc[0]==0 ){
321
+ fossil_redirect_home();
322
+ }
323
+ style_header("Ambiguous Artifact ID");
324
+ @ <p>The artifact id <b>%h(zName)</b> is ambiguous and might
325
+ @ mean any of the following:
326
+ @ <ol>
327
+ z = mprintf("%s", zName);
328
+ canonical16(z, strlen(z));
329
+ db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z);
330
+ while( db_step(&q)==SQLITE_ROW ){
331
+ const char *zUuid = db_column_text(&q, 0);
332
+ int rid = db_column_int(&q, 1);
333
+ @ <li><p><a href="%s(g.zBaseURL)/%T(zSrc)/%S(zUuid)">
334
+ @ %S(zUuid)</a> -
335
+ object_description(rid, 0, 0);
336
+ @ </p></li>
337
+ }
338
+ @ </ol>
339
+ style_footer();
340
+}
341
+
342
+/*
343
+** Convert the name in CGI parameter zParamName into a rid and return that
344
+** rid. If the CGI parameter is missing or is not a valid artifact tag,
345
+** return 0. If the CGI parameter is ambiguous, redirect to a page that
346
+** shows all possibilities and do not return.
347
+*/
348
+int name_to_rid_www(const char *zParamName){
349
+ int i, rc;
350
+ int rid;
351
+ const char *zName = P(zParamName);
352
+ Blob name;
353
+
354
+ if( zName==0 || zName[0]==0 ) return 0;
355
+ blob_init(&name, zName, -1);
356
+ rc = name_to_uuid(&name, -1);
357
+ if( rc==1 ){
358
+ blob_reset(&name);
359
+ for(i=0; zName[i] && isdigit(zName[i]); i++){}
360
+ if( zName[i]==0 ){
361
+ rid = atoi(zName);
362
+ if( db_exists("SELECT 1 FROM blob WHERE rid=%d", rid) ){
363
+ return rid;
364
+ }
365
+ }
366
+ return 0;
367
+ }else if( rc==2 ){
368
+ cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath);
369
+ return 0;
370
+ }else{
371
+ rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
372
+ blob_reset(&name);
373
+ }
374
+ return rid;
375
+}
376
+
305377
--- src/name.c
+++ src/name.c
@@ -43,11 +43,12 @@
43 ** If the input is not a tag, then try to match it as an ISO-8601 date
44 ** string YYYY-MM-DD HH:MM:SS and pick the nearest check-in to that date.
45 ** If the input is of the form "date:*" or "localtime:*" or "utc:*" then
46 ** always resolve the name as a date.
47 **
48 ** Return the number of errors.
 
49 */
50 int name_to_uuid(Blob *pName, int iErrPriority){
51 int rc;
52 int sz;
53 sz = blob_size(pName);
@@ -102,11 +103,11 @@
102 fossil_error(iErrPriority,
103 "multiple artifacts match"
104 );
105 blob_reset(pName);
106 db_finalize(&q);
107 return 1;
108 }
109 db_finalize(&q);
110 rc = 0;
111 }else{
112 rc = 0;
@@ -273,11 +274,11 @@
273 ** Convert a name to a rid. If the name is a small integer value then
274 ** just use atoi() to do the conversion. If the name contains alphabetic
275 ** characters or is not an existing rid, then use name_to_uuid then
276 ** convert the uuid to a rid.
277 **
278 ** This routine is used in test routines to resolve command-line inputs
279 ** into a rid.
280 */
281 int name_to_rid(const char *zName){
282 int i;
283 int rid;
@@ -300,5 +301,76 @@
300 rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
301 blob_reset(&name);
302 }
303 return rid;
304 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
--- src/name.c
+++ src/name.c
@@ -43,11 +43,12 @@
43 ** If the input is not a tag, then try to match it as an ISO-8601 date
44 ** string YYYY-MM-DD HH:MM:SS and pick the nearest check-in to that date.
45 ** If the input is of the form "date:*" or "localtime:*" or "utc:*" then
46 ** always resolve the name as a date.
47 **
48 ** Return 0 on success. Return 1 if the name cannot be resolved.
49 ** Return 2 name is ambiguous.
50 */
51 int name_to_uuid(Blob *pName, int iErrPriority){
52 int rc;
53 int sz;
54 sz = blob_size(pName);
@@ -102,11 +103,11 @@
103 fossil_error(iErrPriority,
104 "multiple artifacts match"
105 );
106 blob_reset(pName);
107 db_finalize(&q);
108 return 2;
109 }
110 db_finalize(&q);
111 rc = 0;
112 }else{
113 rc = 0;
@@ -273,11 +274,11 @@
274 ** Convert a name to a rid. If the name is a small integer value then
275 ** just use atoi() to do the conversion. If the name contains alphabetic
276 ** characters or is not an existing rid, then use name_to_uuid then
277 ** convert the uuid to a rid.
278 **
279 ** This routine is used by command-line routines to resolve command-line inputs
280 ** into a rid.
281 */
282 int name_to_rid(const char *zName){
283 int i;
284 int rid;
@@ -300,5 +301,76 @@
301 rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
302 blob_reset(&name);
303 }
304 return rid;
305 }
306
307 /*
308 ** WEBPAGE: ambiguous
309 ** URL: /ambiguous?name=UUID&src=WEBPAGE
310 **
311 ** The UUID given by the name paramager is ambiguous. Display a page
312 ** that shows all possible choices and let the user select between them.
313 */
314 void ambiguous_page(void){
315 Stmt q;
316 const char *zName = P("name");
317 const char *zSrc = P("src");
318 char *z;
319
320 if( zName==0 || zName[0]==0 || zSrc==0 || zSrc[0]==0 ){
321 fossil_redirect_home();
322 }
323 style_header("Ambiguous Artifact ID");
324 @ <p>The artifact id <b>%h(zName)</b> is ambiguous and might
325 @ mean any of the following:
326 @ <ol>
327 z = mprintf("%s", zName);
328 canonical16(z, strlen(z));
329 db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z);
330 while( db_step(&q)==SQLITE_ROW ){
331 const char *zUuid = db_column_text(&q, 0);
332 int rid = db_column_int(&q, 1);
333 @ <li><p><a href="%s(g.zBaseURL)/%T(zSrc)/%S(zUuid)">
334 @ %S(zUuid)</a> -
335 object_description(rid, 0, 0);
336 @ </p></li>
337 }
338 @ </ol>
339 style_footer();
340 }
341
342 /*
343 ** Convert the name in CGI parameter zParamName into a rid and return that
344 ** rid. If the CGI parameter is missing or is not a valid artifact tag,
345 ** return 0. If the CGI parameter is ambiguous, redirect to a page that
346 ** shows all possibilities and do not return.
347 */
348 int name_to_rid_www(const char *zParamName){
349 int i, rc;
350 int rid;
351 const char *zName = P(zParamName);
352 Blob name;
353
354 if( zName==0 || zName[0]==0 ) return 0;
355 blob_init(&name, zName, -1);
356 rc = name_to_uuid(&name, -1);
357 if( rc==1 ){
358 blob_reset(&name);
359 for(i=0; zName[i] && isdigit(zName[i]); i++){}
360 if( zName[i]==0 ){
361 rid = atoi(zName);
362 if( db_exists("SELECT 1 FROM blob WHERE rid=%d", rid) ){
363 return rid;
364 }
365 }
366 return 0;
367 }else if( rc==2 ){
368 cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath);
369 return 0;
370 }else{
371 rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
372 blob_reset(&name);
373 }
374 return rid;
375 }
376
377
+15
--- src/printf.c
+++ src/printf.c
@@ -804,5 +804,20 @@
804804
void fossil_error_reset(void){
805805
free(g.zErrMsg);
806806
g.zErrMsg = 0;
807807
g.iErrPriority = 0;
808808
}
809
+
810
+/*
811
+** Write output for user consumption. If g.cgiOutput is enabled, then
812
+** send the output as part of the CGI reply. If g.cgiOutput is false,
813
+** then write on standard output.
814
+*/
815
+void fossil_print(const char *zFormat, ...){
816
+ va_list ap;
817
+ va_start(ap, zFormat);
818
+ if( g.cgiOutput ){
819
+ cgi_vprintf(zFormat, ap);
820
+ }else{
821
+ vprintf(zFormat, ap);
822
+ }
823
+}
809824
--- src/printf.c
+++ src/printf.c
@@ -804,5 +804,20 @@
804 void fossil_error_reset(void){
805 free(g.zErrMsg);
806 g.zErrMsg = 0;
807 g.iErrPriority = 0;
808 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
809
--- src/printf.c
+++ src/printf.c
@@ -804,5 +804,20 @@
804 void fossil_error_reset(void){
805 free(g.zErrMsg);
806 g.zErrMsg = 0;
807 g.iErrPriority = 0;
808 }
809
810 /*
811 ** Write output for user consumption. If g.cgiOutput is enabled, then
812 ** send the output as part of the CGI reply. If g.cgiOutput is false,
813 ** then write on standard output.
814 */
815 void fossil_print(const char *zFormat, ...){
816 va_list ap;
817 va_start(ap, zFormat);
818 if( g.cgiOutput ){
819 cgi_vprintf(zFormat, ap);
820 }else{
821 vprintf(zFormat, ap);
822 }
823 }
824
-12
--- src/setup.c
+++ src/setup.c
@@ -84,12 +84,10 @@
8484
"Show artifacts that are shunned by this repository");
8585
setup_menu_entry("Log", "rcvfromlist",
8686
"A record of received artifacts and their sources");
8787
setup_menu_entry("Stats", "stat",
8888
"Display repository statistics");
89
- setup_menu_entry("Sync now", "setup_sync",
90
- "Sync this repository with the 'remote-url' it was set up with");
9189
@ </table>
9290
9391
style_footer();
9492
}
9593
@@ -1066,15 +1064,5 @@
10661064
@ changing the logo to provoke your browser to reload the new logo image.
10671065
@ </p>
10681066
style_footer();
10691067
db_end_transaction(0);
10701068
}
1071
-
1072
-/*
1073
-** WEBPAGE: setup_sync
1074
-*/
1075
-void setup_sync(void){
1076
- sync_cmd();
1077
- style_header("Synchronized");
1078
- @ <p>The project has been synchronized</p>
1079
- style_footer();
1080
-}
10811069
--- src/setup.c
+++ src/setup.c
@@ -84,12 +84,10 @@
84 "Show artifacts that are shunned by this repository");
85 setup_menu_entry("Log", "rcvfromlist",
86 "A record of received artifacts and their sources");
87 setup_menu_entry("Stats", "stat",
88 "Display repository statistics");
89 setup_menu_entry("Sync now", "setup_sync",
90 "Sync this repository with the 'remote-url' it was set up with");
91 @ </table>
92
93 style_footer();
94 }
95
@@ -1066,15 +1064,5 @@
1066 @ changing the logo to provoke your browser to reload the new logo image.
1067 @ </p>
1068 style_footer();
1069 db_end_transaction(0);
1070 }
1071
1072 /*
1073 ** WEBPAGE: setup_sync
1074 */
1075 void setup_sync(void){
1076 sync_cmd();
1077 style_header("Synchronized");
1078 @ <p>The project has been synchronized</p>
1079 style_footer();
1080 }
1081
--- src/setup.c
+++ src/setup.c
@@ -84,12 +84,10 @@
84 "Show artifacts that are shunned by this repository");
85 setup_menu_entry("Log", "rcvfromlist",
86 "A record of received artifacts and their sources");
87 setup_menu_entry("Stats", "stat",
88 "Display repository statistics");
 
 
89 @ </table>
90
91 style_footer();
92 }
93
@@ -1066,15 +1064,5 @@
1064 @ changing the logo to provoke your browser to reload the new logo image.
1065 @ </p>
1066 style_footer();
1067 db_end_transaction(0);
1068 }
 
 
 
 
 
 
 
 
 
 
1069
-12
--- src/setup.c
+++ src/setup.c
@@ -84,12 +84,10 @@
8484
"Show artifacts that are shunned by this repository");
8585
setup_menu_entry("Log", "rcvfromlist",
8686
"A record of received artifacts and their sources");
8787
setup_menu_entry("Stats", "stat",
8888
"Display repository statistics");
89
- setup_menu_entry("Sync now", "setup_sync",
90
- "Sync this repository with the 'remote-url' it was set up with");
9189
@ </table>
9290
9391
style_footer();
9492
}
9593
@@ -1066,15 +1064,5 @@
10661064
@ changing the logo to provoke your browser to reload the new logo image.
10671065
@ </p>
10681066
style_footer();
10691067
db_end_transaction(0);
10701068
}
1071
-
1072
-/*
1073
-** WEBPAGE: setup_sync
1074
-*/
1075
-void setup_sync(void){
1076
- sync_cmd();
1077
- style_header("Synchronized");
1078
- @ <p>The project has been synchronized</p>
1079
- style_footer();
1080
-}
10811069
--- src/setup.c
+++ src/setup.c
@@ -84,12 +84,10 @@
84 "Show artifacts that are shunned by this repository");
85 setup_menu_entry("Log", "rcvfromlist",
86 "A record of received artifacts and their sources");
87 setup_menu_entry("Stats", "stat",
88 "Display repository statistics");
89 setup_menu_entry("Sync now", "setup_sync",
90 "Sync this repository with the 'remote-url' it was set up with");
91 @ </table>
92
93 style_footer();
94 }
95
@@ -1066,15 +1064,5 @@
1066 @ changing the logo to provoke your browser to reload the new logo image.
1067 @ </p>
1068 style_footer();
1069 db_end_transaction(0);
1070 }
1071
1072 /*
1073 ** WEBPAGE: setup_sync
1074 */
1075 void setup_sync(void){
1076 sync_cmd();
1077 style_header("Synchronized");
1078 @ <p>The project has been synchronized</p>
1079 style_footer();
1080 }
1081
--- src/setup.c
+++ src/setup.c
@@ -84,12 +84,10 @@
84 "Show artifacts that are shunned by this repository");
85 setup_menu_entry("Log", "rcvfromlist",
86 "A record of received artifacts and their sources");
87 setup_menu_entry("Stats", "stat",
88 "Display repository statistics");
 
 
89 @ </table>
90
91 style_footer();
92 }
93
@@ -1066,15 +1064,5 @@
1064 @ changing the logo to provoke your browser to reload the new logo image.
1065 @ </p>
1066 style_footer();
1067 db_end_transaction(0);
1068 }
 
 
 
 
 
 
 
 
 
 
1069
+1310 -532
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.6.23.1. By combining all the individual C code files into this
3
+** version 3.6.23. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a one translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% are more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -321,11 +321,11 @@
321321
** to generate appropriate macros for a wide range of compilers.
322322
**
323323
** The correct "ANSI" way to do this is to use the intptr_t type.
324324
** Unfortunately, that typedef is not available on all compilers, or
325325
** if it is available, it requires an #include of specific headers
326
-** that very from one machine to the next.
326
+** that vary from one machine to the next.
327327
**
328328
** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
329329
** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
330330
** So we have to define the macros in different ways depending on the
331331
** compiler.
@@ -626,13 +626,13 @@
626626
**
627627
** See also: [sqlite3_libversion()],
628628
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
629629
** [sqlite_version()] and [sqlite_source_id()].
630630
*/
631
-#define SQLITE_VERSION "3.6.23.1"
631
+#define SQLITE_VERSION "3.6.23"
632632
#define SQLITE_VERSION_NUMBER 3006023
633
-#define SQLITE_SOURCE_ID "2010-03-26 22:28:06 ex-b078b588d617e07886ad156e9f54ade6d823568e"
633
+#define SQLITE_SOURCE_ID "2010-04-15 23:24:29 f96782b389b5b97b488dc5814f7082e0393f64cd"
634634
635635
/*
636636
** CAPI3REF: Run-Time Library Version Numbers
637637
** KEYWORDS: sqlite3_version, sqlite3_sourceid
638638
**
@@ -665,11 +665,10 @@
665665
SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
666666
SQLITE_API const char *sqlite3_libversion(void);
667667
SQLITE_API const char *sqlite3_sourceid(void);
668668
SQLITE_API int sqlite3_libversion_number(void);
669669
670
-#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
671670
/*
672671
** CAPI3REF: Run-Time Library Compilation Options Diagnostics
673672
**
674673
** ^The sqlite3_compileoption_used() function returns 0 or 1
675674
** indicating whether the specified option was defined at
@@ -688,13 +687,14 @@
688687
** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
689688
**
690689
** See also: SQL functions [sqlite_compileoption_used()] and
691690
** [sqlite_compileoption_get()] and the [compile_options pragma].
692691
*/
692
+#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
693693
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
694694
SQLITE_API const char *sqlite3_compileoption_get(int N);
695
-#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
695
+#endif
696696
697697
/*
698698
** CAPI3REF: Test To See If The Library Is Threadsafe
699699
**
700700
** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -1492,15 +1492,14 @@
14921492
**
14931493
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
14941494
** ^If the option is unknown or SQLite is unable to set the option
14951495
** then this routine returns a non-zero [error code].
14961496
*/
1497
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
1497
+SQLITE_API int sqlite3_config(int, ...);
14981498
14991499
/*
15001500
** CAPI3REF: Configure database connections
1501
-** EXPERIMENTAL
15021501
**
15031502
** The sqlite3_db_config() interface is used to make configuration
15041503
** changes to a [database connection]. The interface is similar to
15051504
** [sqlite3_config()] except that the changes apply to a single
15061505
** [database connection] (specified in the first argument). The
@@ -1516,15 +1515,14 @@
15161515
** Additional arguments depend on the verb.
15171516
**
15181517
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
15191518
** the call is considered successful.
15201519
*/
1521
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
1520
+SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
15221521
15231522
/*
15241523
** CAPI3REF: Memory Allocation Routines
1525
-** EXPERIMENTAL
15261524
**
15271525
** An instance of this object defines the interface between SQLite
15281526
** and low-level memory allocation routines.
15291527
**
15301528
** This object is used in only one place in the SQLite interface.
@@ -1602,11 +1600,10 @@
16021600
void *pAppData; /* Argument to xInit() and xShutdown() */
16031601
};
16041602
16051603
/*
16061604
** CAPI3REF: Configuration Options
1607
-** EXPERIMENTAL
16081605
**
16091606
** These constants are the available integer configuration options that
16101607
** can be passed as the first argument to the [sqlite3_config()] interface.
16111608
**
16121609
** New configuration options may be added in future releases of SQLite.
@@ -1788,10 +1785,28 @@
17881785
** <dt>SQLITE_CONFIG_GETPCACHE</dt>
17891786
** <dd> ^(This option takes a single argument which is a pointer to an
17901787
** [sqlite3_pcache_methods] object. SQLite copies of the current
17911788
** page cache implementation into that object.)^ </dd>
17921789
**
1790
+** <dt>SQLITE_CONFIG_LOG</dt>
1791
+** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1792
+** function with a call signature of void(*)(void*,int,const char*),
1793
+** and a pointer to void. ^If the function pointer is not NULL, it is
1794
+** invoked by [sqlite3_log()] to process each logging event. ^If the
1795
+** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1796
+** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1797
+** passed through as the first parameter to the application-defined logger
1798
+** function whenever that function is invoked. ^The second parameter to
1799
+** the logger function is a copy of the first parameter to the corresponding
1800
+** [sqlite3_log()] call and is intended to be a [result code] or an
1801
+** [extended result code]. ^The third parameter passed to the logger is
1802
+** log message after formatting via [sqlite3_snprintf()].
1803
+** The SQLite logging interface is not reentrant; the logger function
1804
+** supplied by the application must not invoke any SQLite interface.
1805
+** In a multi-threaded application, the application-defined logger
1806
+** function must be threadsafe. </dd>
1807
+**
17931808
** </dl>
17941809
*/
17951810
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
17961811
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
17971812
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1808,12 +1823,11 @@
18081823
#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
18091824
#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
18101825
#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
18111826
18121827
/*
1813
-** CAPI3REF: Configuration Options
1814
-** EXPERIMENTAL
1828
+** CAPI3REF: Database Connection Configuration Options
18151829
**
18161830
** These constants are the available integer configuration options that
18171831
** can be passed as the second argument to the [sqlite3_db_config()] interface.
18181832
**
18191833
** New configuration options may be added in future releases of SQLite.
@@ -2585,11 +2599,10 @@
25852599
#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
25862600
#define SQLITE_COPY 0 /* No longer used */
25872601
25882602
/*
25892603
** CAPI3REF: Tracing And Profiling Functions
2590
-** EXPERIMENTAL
25912604
**
25922605
** These routines register callback functions that can be used for
25932606
** tracing and profiling the execution of SQL statements.
25942607
**
25952608
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2603,11 +2616,11 @@
26032616
** ^The callback function registered by sqlite3_profile() is invoked
26042617
** as each SQL statement finishes. ^The profile callback contains
26052618
** the original statement text and an estimate of wall-clock time
26062619
** of how long that statement took to run.
26072620
*/
2608
-SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2621
+SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
26092622
SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
26102623
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
26112624
26122625
/*
26132626
** CAPI3REF: Query Progress Callbacks
@@ -4208,11 +4221,11 @@
42084221
sqlite3*,
42094222
void*,
42104223
void(*)(void*,sqlite3*,int eTextRep,const void*)
42114224
);
42124225
4213
-#if SQLITE_HAS_CODEC
4226
+#ifdef SQLITE_HAS_CODEC
42144227
/*
42154228
** Specify the key for an encrypted database. This routine should be
42164229
** called right after sqlite3_open().
42174230
**
42184231
** The code to implement this API is not available in the public release
@@ -4391,12 +4404,10 @@
43914404
** ^For the purposes of this API, a transaction is said to have been
43924405
** rolled back if an explicit "ROLLBACK" statement is executed, or
43934406
** an error or constraint causes an implicit rollback to occur.
43944407
** ^The rollback callback is not invoked if a transaction is
43954408
** automatically rolled back because the database connection is closed.
4396
-** ^The rollback callback is not invoked if a transaction is
4397
-** rolled back because a commit callback returned non-zero.
43984409
**
43994410
** See also the [sqlite3_update_hook()] interface.
44004411
*/
44014412
SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
44024413
SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
@@ -4678,12 +4689,10 @@
46784689
** ^This function disables automatic extensions in all threads.
46794690
*/
46804691
SQLITE_API void sqlite3_reset_auto_extension(void);
46814692
46824693
/*
4683
-****** EXPERIMENTAL - subject to change without notice **************
4684
-**
46854694
** The interface to the virtual-table mechanism is currently considered
46864695
** to be experimental. The interface might change in incompatible ways.
46874696
** If this is a problem for you, do not use the interface at this time.
46884697
**
46894698
** When the virtual-table mechanism stabilizes, we will declare the
@@ -4699,11 +4708,10 @@
46994708
typedef struct sqlite3_module sqlite3_module;
47004709
47014710
/*
47024711
** CAPI3REF: Virtual Table Object
47034712
** KEYWORDS: sqlite3_module {virtual table module}
4704
-** EXPERIMENTAL
47054713
**
47064714
** This structure, sometimes called a a "virtual table module",
47074715
** defines the implementation of a [virtual tables].
47084716
** This structure consists mostly of methods for the module.
47094717
**
@@ -4746,11 +4754,10 @@
47464754
};
47474755
47484756
/*
47494757
** CAPI3REF: Virtual Table Indexing Information
47504758
** KEYWORDS: sqlite3_index_info
4751
-** EXPERIMENTAL
47524759
**
47534760
** The sqlite3_index_info structure and its substructures is used to
47544761
** pass information into and receive the reply from the [xBestIndex]
47554762
** method of a [virtual table module]. The fields under **Inputs** are the
47564763
** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4828,11 +4835,10 @@
48284835
#define SQLITE_INDEX_CONSTRAINT_GE 32
48294836
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
48304837
48314838
/*
48324839
** CAPI3REF: Register A Virtual Table Implementation
4833
-** EXPERIMENTAL
48344840
**
48354841
** ^These routines are used to register a new [virtual table module] name.
48364842
** ^Module names must be registered before
48374843
** creating a new [virtual table] using the module and before using a
48384844
** preexisting [virtual table] for the module.
@@ -4850,17 +4856,17 @@
48504856
** invoke the destructor function (if it is not NULL) when SQLite
48514857
** no longer needs the pClientData pointer. ^The sqlite3_create_module()
48524858
** interface is equivalent to sqlite3_create_module_v2() with a NULL
48534859
** destructor.
48544860
*/
4855
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
4861
+SQLITE_API int sqlite3_create_module(
48564862
sqlite3 *db, /* SQLite connection to register module with */
48574863
const char *zName, /* Name of the module */
48584864
const sqlite3_module *p, /* Methods for the module */
48594865
void *pClientData /* Client data for xCreate/xConnect */
48604866
);
4861
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
4867
+SQLITE_API int sqlite3_create_module_v2(
48624868
sqlite3 *db, /* SQLite connection to register module with */
48634869
const char *zName, /* Name of the module */
48644870
const sqlite3_module *p, /* Methods for the module */
48654871
void *pClientData, /* Client data for xCreate/xConnect */
48664872
void(*xDestroy)(void*) /* Module destructor function */
@@ -4867,11 +4873,10 @@
48674873
);
48684874
48694875
/*
48704876
** CAPI3REF: Virtual Table Instance Object
48714877
** KEYWORDS: sqlite3_vtab
4872
-** EXPERIMENTAL
48734878
**
48744879
** Every [virtual table module] implementation uses a subclass
48754880
** of this object to describe a particular instance
48764881
** of the [virtual table]. Each subclass will
48774882
** be tailored to the specific needs of the module implementation.
@@ -4893,11 +4898,10 @@
48934898
};
48944899
48954900
/*
48964901
** CAPI3REF: Virtual Table Cursor Object
48974902
** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
4898
-** EXPERIMENTAL
48994903
**
49004904
** Every [virtual table module] implementation uses a subclass of the
49014905
** following structure to describe cursors that point into the
49024906
** [virtual table] and are used
49034907
** to loop through the virtual table. Cursors are created using the
@@ -4915,22 +4919,20 @@
49154919
/* Virtual table implementations will typically add additional fields */
49164920
};
49174921
49184922
/*
49194923
** CAPI3REF: Declare The Schema Of A Virtual Table
4920
-** EXPERIMENTAL
49214924
**
49224925
** ^The [xCreate] and [xConnect] methods of a
49234926
** [virtual table module] call this interface
49244927
** to declare the format (the names and datatypes of the columns) of
49254928
** the virtual tables they implement.
49264929
*/
4927
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4930
+SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
49284931
49294932
/*
49304933
** CAPI3REF: Overload A Function For A Virtual Table
4931
-** EXPERIMENTAL
49324934
**
49334935
** ^(Virtual tables can provide alternative implementations of functions
49344936
** using the [xFindFunction] method of the [virtual table module].
49354937
** But global versions of those functions
49364938
** must exist in order to be overloaded.)^
@@ -4941,22 +4943,20 @@
49414943
** of the new function always causes an exception to be thrown. So
49424944
** the new function is not good for anything by itself. Its only
49434945
** purpose is to be a placeholder function that can be overloaded
49444946
** by a [virtual table].
49454947
*/
4946
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4948
+SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
49474949
49484950
/*
49494951
** The interface to the virtual-table mechanism defined above (back up
49504952
** to a comment remarkably similar to this one) is currently considered
49514953
** to be experimental. The interface might change in incompatible ways.
49524954
** If this is a problem for you, do not use the interface at this time.
49534955
**
49544956
** When the virtual-table mechanism stabilizes, we will declare the
49554957
** interface fixed, support it indefinitely, and remove this comment.
4956
-**
4957
-****** EXPERIMENTAL - subject to change without notice **************
49584958
*/
49594959
49604960
/*
49614961
** CAPI3REF: A Handle To An Open BLOB
49624962
** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -5295,11 +5295,10 @@
52955295
SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
52965296
SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
52975297
52985298
/*
52995299
** CAPI3REF: Mutex Methods Object
5300
-** EXPERIMENTAL
53015300
**
53025301
** An instance of this structure defines the low-level routines
53035302
** used to allocate and use mutexes.
53045303
**
53055304
** Usually, the default mutex implementations provided by SQLite are
@@ -5512,11 +5511,10 @@
55125511
#define SQLITE_TESTCTRL_ISKEYWORD 16
55135512
#define SQLITE_TESTCTRL_LAST 16
55145513
55155514
/*
55165515
** CAPI3REF: SQLite Runtime Status
5517
-** EXPERIMENTAL
55185516
**
55195517
** ^This interface is used to retrieve runtime status information
55205518
** about the preformance of SQLite, and optionally to reset various
55215519
** highwater marks. ^The first argument is an integer code for
55225520
** the specific parameter to measure. ^(Recognized integer codes
@@ -5540,16 +5538,15 @@
55405538
** and it is possible that another thread might change the parameter
55415539
** in between the times when *pCurrent and *pHighwater are written.
55425540
**
55435541
** See also: [sqlite3_db_status()]
55445542
*/
5545
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5543
+SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
55465544
55475545
55485546
/*
55495547
** CAPI3REF: Status Parameters
5550
-** EXPERIMENTAL
55515548
**
55525549
** These integer constants designate various run-time status parameters
55535550
** that can be returned by [sqlite3_status()].
55545551
**
55555552
** <dl>
@@ -5632,31 +5629,31 @@
56325629
#define SQLITE_STATUS_PAGECACHE_SIZE 7
56335630
#define SQLITE_STATUS_SCRATCH_SIZE 8
56345631
56355632
/*
56365633
** CAPI3REF: Database Connection Status
5637
-** EXPERIMENTAL
56385634
**
56395635
** ^This interface is used to retrieve runtime status information
56405636
** about a single [database connection]. ^The first argument is the
56415637
** database connection object to be interrogated. ^The second argument
5642
-** is the parameter to interrogate. ^Currently, the only allowed value
5643
-** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
5644
-** Additional options will likely appear in future releases of SQLite.
5638
+** is an integer constant, taken from the set of
5639
+** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5640
+** determiness the parameter to interrogate. The set of
5641
+** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5642
+** to grow in future releases of SQLite.
56455643
**
56465644
** ^The current value of the requested parameter is written into *pCur
56475645
** and the highest instantaneous value is written into *pHiwtr. ^If
56485646
** the resetFlg is true, then the highest instantaneous value is
56495647
** reset back down to the current value.
56505648
**
56515649
** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
56525650
*/
5653
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5651
+SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
56545652
56555653
/*
56565654
** CAPI3REF: Status Parameters for database connections
5657
-** EXPERIMENTAL
56585655
**
56595656
** These constants are the available integer "verbs" that can be passed as
56605657
** the second argument to the [sqlite3_db_status()] interface.
56615658
**
56625659
** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5667,18 +5664,25 @@
56675664
**
56685665
** <dl>
56695666
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
56705667
** <dd>This parameter returns the number of lookaside memory slots currently
56715668
** checked out.</dd>)^
5669
+**
5670
+** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5671
+** <dd>^This parameter returns the approximate number of of bytes of heap
5672
+** memory used by all pager caches associated with the database connection.
5673
+** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5674
+** checked out.</dd>)^
56725675
** </dl>
56735676
*/
56745677
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5678
+#define SQLITE_DBSTATUS_CACHE_USED 1
5679
+#define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
56755680
56765681
56775682
/*
56785683
** CAPI3REF: Prepared Statement Status
5679
-** EXPERIMENTAL
56805684
**
56815685
** ^(Each prepared statement maintains various
56825686
** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
56835687
** of times it has performed specific operations.)^ These counters can
56845688
** be used to monitor the performance characteristics of the prepared
@@ -5696,15 +5700,14 @@
56965700
** ^If the resetFlg is true, then the counter is reset to zero after this
56975701
** interface call returns.
56985702
**
56995703
** See also: [sqlite3_status()] and [sqlite3_db_status()].
57005704
*/
5701
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5705
+SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
57025706
57035707
/*
57045708
** CAPI3REF: Status Parameters for prepared statements
5705
-** EXPERIMENTAL
57065709
**
57075710
** These preprocessor macros define integer codes that name counter
57085711
** values associated with the [sqlite3_stmt_status()] interface.
57095712
** The meanings of the various counters are as follows:
57105713
**
@@ -5718,18 +5721,25 @@
57185721
** <dt>SQLITE_STMTSTATUS_SORT</dt>
57195722
** <dd>^This is the number of sort operations that have occurred.
57205723
** A non-zero value in this counter may indicate an opportunity to
57215724
** improvement performance through careful use of indices.</dd>
57225725
**
5726
+** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5727
+** <dd>^This is the number of rows inserted into transient indices that
5728
+** were created automatically in order to help joins run faster.
5729
+** A non-zero value in this counter may indicate an opportunity to
5730
+** improvement performance by adding permanent indices that do not
5731
+** need to be reinitialized each time the statement is run.</dd>
5732
+**
57235733
** </dl>
57245734
*/
57255735
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
57265736
#define SQLITE_STMTSTATUS_SORT 2
5737
+#define SQLITE_STMTSTATUS_AUTOINDEX 3
57275738
57285739
/*
57295740
** CAPI3REF: Custom Page Cache Object
5730
-** EXPERIMENTAL
57315741
**
57325742
** The sqlite3_pcache type is opaque. It is implemented by
57335743
** the pluggable module. The SQLite core has no knowledge of
57345744
** its size or internal structure and never deals with the
57355745
** sqlite3_pcache object except by holding and passing pointers
@@ -5740,11 +5750,10 @@
57405750
typedef struct sqlite3_pcache sqlite3_pcache;
57415751
57425752
/*
57435753
** CAPI3REF: Application Defined Page Cache.
57445754
** KEYWORDS: {page cache}
5745
-** EXPERIMENTAL
57465755
**
57475756
** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
57485757
** register an alternative page cache implementation by passing in an
57495758
** instance of the sqlite3_pcache_methods structure.)^ The majority of the
57505759
** heap memory used by SQLite is used by the page cache to cache data read
@@ -5882,11 +5891,10 @@
58825891
void (*xDestroy)(sqlite3_pcache*);
58835892
};
58845893
58855894
/*
58865895
** CAPI3REF: Online Backup Object
5887
-** EXPERIMENTAL
58885896
**
58895897
** The sqlite3_backup object records state information about an ongoing
58905898
** online backup operation. ^The sqlite3_backup object is created by
58915899
** a call to [sqlite3_backup_init()] and is destroyed by a call to
58925900
** [sqlite3_backup_finish()].
@@ -5895,11 +5903,10 @@
58955903
*/
58965904
typedef struct sqlite3_backup sqlite3_backup;
58975905
58985906
/*
58995907
** CAPI3REF: Online Backup API.
5900
-** EXPERIMENTAL
59015908
**
59025909
** The backup API copies the content of one database into another.
59035910
** It is useful either for creating backups of databases or
59045911
** for copying in-memory databases to or from persistent files.
59055912
**
@@ -6083,11 +6090,10 @@
60836090
SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
60846091
SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
60856092
60866093
/*
60876094
** CAPI3REF: Unlock Notification
6088
-** EXPERIMENTAL
60896095
**
60906096
** ^When running in shared-cache mode, a database operation may fail with
60916097
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
60926098
** individual tables within the shared-cache cannot be obtained. See
60936099
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -6205,11 +6211,10 @@
62056211
);
62066212
62076213
62086214
/*
62096215
** CAPI3REF: String Comparison
6210
-** EXPERIMENTAL
62116216
**
62126217
** ^The [sqlite3_strnicmp()] API allows applications and extensions to
62136218
** compare the contents of two buffers containing UTF-8 strings in a
62146219
** case-indendent fashion, using the same definition of case independence
62156220
** that SQLite uses internally when comparing identifiers.
@@ -6216,16 +6221,15 @@
62166221
*/
62176222
SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
62186223
62196224
/*
62206225
** CAPI3REF: Error Logging Interface
6221
-** EXPERIMENTAL
62226226
**
62236227
** ^The [sqlite3_log()] interface writes a message into the error log
62246228
** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
62256229
** ^If logging is enabled, the zFormat string and subsequent arguments are
6226
-** passed through to [sqlite3_vmprintf()] to generate the final output string.
6230
+** used with [sqlite3_snprintf()] to generate the final output string.
62276231
**
62286232
** The sqlite3_log() interface is intended for use by extensions such as
62296233
** virtual tables, collating functions, and SQL functions. While there is
62306234
** nothing to prevent an application from calling sqlite3_log(), doing so
62316235
** is considered bad form.
@@ -6529,10 +6533,11 @@
65296533
** If compiling for a processor that lacks floating point support,
65306534
** substitute integer for floating-point
65316535
*/
65326536
#ifdef SQLITE_OMIT_FLOATING_POINT
65336537
# define double sqlite_int64
6538
+# define float sqlite_int64
65346539
# define LONGDOUBLE_TYPE sqlite_int64
65356540
# ifndef SQLITE_BIG_DBL
65366541
# define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
65376542
# endif
65386543
# define SQLITE_OMIT_DATETIME_FUNCS 1
@@ -6940,10 +6945,11 @@
69406945
SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
69416946
SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
69426947
SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
69436948
SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
69446949
SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
6950
+SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
69456951
SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
69466952
SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
69476953
SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
69486954
SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
69496955
SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
@@ -7334,85 +7340,85 @@
73347340
#define OP_ReadCookie 35
73357341
#define OP_SetCookie 36
73367342
#define OP_VerifyCookie 37
73377343
#define OP_OpenRead 38
73387344
#define OP_OpenWrite 39
7339
-#define OP_OpenEphemeral 40
7340
-#define OP_OpenPseudo 41
7341
-#define OP_Close 42
7342
-#define OP_SeekLt 43
7343
-#define OP_SeekLe 44
7344
-#define OP_SeekGe 45
7345
-#define OP_SeekGt 46
7346
-#define OP_Seek 47
7347
-#define OP_NotFound 48
7348
-#define OP_Found 49
7349
-#define OP_IsUnique 50
7350
-#define OP_NotExists 51
7351
-#define OP_Sequence 52
7352
-#define OP_NewRowid 53
7353
-#define OP_Insert 54
7354
-#define OP_InsertInt 55
7355
-#define OP_Delete 56
7356
-#define OP_ResetCount 57
7357
-#define OP_RowKey 58
7358
-#define OP_RowData 59
7359
-#define OP_Rowid 60
7360
-#define OP_NullRow 61
7361
-#define OP_Last 62
7362
-#define OP_Sort 63
7363
-#define OP_Rewind 64
7364
-#define OP_Prev 65
7365
-#define OP_Next 66
7366
-#define OP_IdxInsert 67
7367
-#define OP_IdxDelete 70
7368
-#define OP_IdxRowid 71
7369
-#define OP_IdxLT 72
7370
-#define OP_IdxGE 81
7371
-#define OP_Destroy 92
7372
-#define OP_Clear 95
7373
-#define OP_CreateIndex 96
7374
-#define OP_CreateTable 97
7375
-#define OP_ParseSchema 98
7376
-#define OP_LoadAnalysis 99
7377
-#define OP_DropTable 100
7378
-#define OP_DropIndex 101
7379
-#define OP_DropTrigger 102
7380
-#define OP_IntegrityCk 103
7381
-#define OP_RowSetAdd 104
7382
-#define OP_RowSetRead 105
7383
-#define OP_RowSetTest 106
7384
-#define OP_Program 107
7385
-#define OP_Param 108
7386
-#define OP_FkCounter 109
7387
-#define OP_FkIfZero 110
7388
-#define OP_MemMax 111
7389
-#define OP_IfPos 112
7390
-#define OP_IfNeg 113
7391
-#define OP_IfZero 114
7392
-#define OP_AggStep 115
7393
-#define OP_AggFinal 116
7394
-#define OP_Vacuum 117
7395
-#define OP_IncrVacuum 118
7396
-#define OP_Expire 119
7397
-#define OP_TableLock 120
7398
-#define OP_VBegin 121
7399
-#define OP_VCreate 122
7400
-#define OP_VDestroy 123
7401
-#define OP_VOpen 124
7402
-#define OP_VFilter 125
7403
-#define OP_VColumn 126
7404
-#define OP_VNext 127
7405
-#define OP_VRename 128
7406
-#define OP_VUpdate 129
7407
-#define OP_Pagecount 131
7408
-#define OP_Trace 132
7409
-#define OP_Noop 133
7410
-#define OP_Explain 134
7411
-
7412
-/* The following opcode values are never used */
7413
-#define OP_NotUsed_135 135
7345
+#define OP_OpenAutoindex 40
7346
+#define OP_OpenEphemeral 41
7347
+#define OP_OpenPseudo 42
7348
+#define OP_Close 43
7349
+#define OP_SeekLt 44
7350
+#define OP_SeekLe 45
7351
+#define OP_SeekGe 46
7352
+#define OP_SeekGt 47
7353
+#define OP_Seek 48
7354
+#define OP_NotFound 49
7355
+#define OP_Found 50
7356
+#define OP_IsUnique 51
7357
+#define OP_NotExists 52
7358
+#define OP_Sequence 53
7359
+#define OP_NewRowid 54
7360
+#define OP_Insert 55
7361
+#define OP_InsertInt 56
7362
+#define OP_Delete 57
7363
+#define OP_ResetCount 58
7364
+#define OP_RowKey 59
7365
+#define OP_RowData 60
7366
+#define OP_Rowid 61
7367
+#define OP_NullRow 62
7368
+#define OP_Last 63
7369
+#define OP_Sort 64
7370
+#define OP_Rewind 65
7371
+#define OP_Prev 66
7372
+#define OP_Next 67
7373
+#define OP_IdxInsert 70
7374
+#define OP_IdxDelete 71
7375
+#define OP_IdxRowid 72
7376
+#define OP_IdxLT 81
7377
+#define OP_IdxGE 92
7378
+#define OP_Destroy 95
7379
+#define OP_Clear 96
7380
+#define OP_CreateIndex 97
7381
+#define OP_CreateTable 98
7382
+#define OP_ParseSchema 99
7383
+#define OP_LoadAnalysis 100
7384
+#define OP_DropTable 101
7385
+#define OP_DropIndex 102
7386
+#define OP_DropTrigger 103
7387
+#define OP_IntegrityCk 104
7388
+#define OP_RowSetAdd 105
7389
+#define OP_RowSetRead 106
7390
+#define OP_RowSetTest 107
7391
+#define OP_Program 108
7392
+#define OP_Param 109
7393
+#define OP_FkCounter 110
7394
+#define OP_FkIfZero 111
7395
+#define OP_MemMax 112
7396
+#define OP_IfPos 113
7397
+#define OP_IfNeg 114
7398
+#define OP_IfZero 115
7399
+#define OP_AggStep 116
7400
+#define OP_AggFinal 117
7401
+#define OP_Vacuum 118
7402
+#define OP_IncrVacuum 119
7403
+#define OP_Expire 120
7404
+#define OP_TableLock 121
7405
+#define OP_VBegin 122
7406
+#define OP_VCreate 123
7407
+#define OP_VDestroy 124
7408
+#define OP_VOpen 125
7409
+#define OP_VFilter 126
7410
+#define OP_VColumn 127
7411
+#define OP_VNext 128
7412
+#define OP_VRename 129
7413
+#define OP_VUpdate 131
7414
+#define OP_Pagecount 132
7415
+#define OP_Trace 133
7416
+#define OP_Noop 134
7417
+#define OP_Explain 135
7418
+
7419
+/* The following opcode values are never used */
74147420
#define OP_NotUsed_136 136
74157421
#define OP_NotUsed_137 137
74167422
#define OP_NotUsed_138 138
74177423
#define OP_NotUsed_139 139
74187424
#define OP_NotUsed_140 140
@@ -7433,22 +7439,22 @@
74337439
/* 0 */ 0x00, 0x01, 0x05, 0x04, 0x04, 0x10, 0x00, 0x02,\
74347440
/* 8 */ 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x24, 0x24,\
74357441
/* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\
74367442
/* 24 */ 0x00, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\
74377443
/* 32 */ 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00,\
7438
-/* 40 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
7439
-/* 48 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x00,\
7440
-/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
7441
-/* 64 */ 0x01, 0x01, 0x01, 0x08, 0x4c, 0x4c, 0x00, 0x02,\
7442
-/* 72 */ 0x01, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
7444
+/* 40 */ 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11,\
7445
+/* 48 */ 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00,\
7446
+/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\
7447
+/* 64 */ 0x01, 0x01, 0x01, 0x01, 0x4c, 0x4c, 0x08, 0x00,\
7448
+/* 72 */ 0x02, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
74437449
/* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
7444
-/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x02, 0x24, 0x02, 0x00,\
7445
-/* 96 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
7446
-/* 104 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
7447
-/* 112 */ 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00,\
7448
-/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,\
7449
-/* 128 */ 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
7450
+/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x01, 0x24, 0x02, 0x02,\
7451
+/* 96 */ 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\
7452
+/* 104 */ 0x00, 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01,\
7453
+/* 112 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x01,\
7454
+/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,\
7455
+/* 128 */ 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,\
74507456
/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
74517457
/* 144 */ 0x04, 0x04,}
74527458
74537459
/************** End of opcodes.h *********************************************/
74547460
/************** Continuing where we left off in vdbe.h ***********************/
@@ -7658,10 +7664,11 @@
76587664
SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
76597665
76607666
/* Functions used to query pager state and configuration. */
76617667
SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
76627668
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
7669
+SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
76637670
SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
76647671
SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
76657672
SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
76667673
SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
76677674
SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
@@ -8478,10 +8485,11 @@
84788485
#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
84798486
#define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */
84808487
#define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */
84818488
#define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
84828489
#define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
8490
+#define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
84838491
84848492
/*
84858493
** Bits of the sqlite3.flags field that are used by the
84868494
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
84878495
** These must be the low-order bits of the flags field.
@@ -9340,10 +9348,13 @@
93409348
**
93419349
** The jointype starts out showing the join type between the current table
93429350
** and the next table on the list. The parser builds the list this way.
93439351
** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
93449352
** jointype expresses the join between the table and the previous table.
9353
+**
9354
+** In the colUsed field, the high-order bit (bit 63) is set if the table
9355
+** contains more than 63 columns and the 64-th or later column is used.
93459356
*/
93469357
struct SrcList {
93479358
i16 nSrc; /* Number of tables or subqueries in the FROM clause */
93489359
i16 nAlloc; /* Number of entries allocated in a[] below */
93499360
struct SrcList_item {
@@ -9451,11 +9462,11 @@
94519462
#define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
94529463
#define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
94539464
#define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
94549465
#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
94559466
#define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
9456
-#define WHERE_OMIT_OPEN 0x0010 /* Table cursor are already open */
9467
+#define WHERE_OMIT_OPEN 0x0010 /* Table cursors are already open */
94579468
#define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
94589469
#define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
94599470
#define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
94609471
94619472
/*
@@ -9474,10 +9485,11 @@
94749485
int iTop; /* The very beginning of the WHERE loop */
94759486
int iContinue; /* Jump here to continue with next record */
94769487
int iBreak; /* Jump here to break out of the loop */
94779488
int nLevel; /* Number of nested loop */
94789489
struct WhereClause *pWC; /* Decomposition of the WHERE clause */
9490
+ double savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
94799491
WhereLevel a[1]; /* Information about each nest loop in WHERE */
94809492
};
94819493
94829494
/*
94839495
** A NameContext defines a context in which to resolve table and column
@@ -9715,10 +9727,11 @@
97159727
u32 oldmask; /* Mask of old.* columns referenced */
97169728
u32 newmask; /* Mask of new.* columns referenced */
97179729
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
97189730
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
97199731
u8 disableTriggers; /* True to disable triggers */
9732
+ double nQueryLoop; /* Estimated number of iterations of a query */
97209733
97219734
/* Above is constant between recursions. Below is reset before and after
97229735
** each recursion */
97239736
97249737
int nVar; /* Number of '?' variables seen in the SQL so far */
@@ -10656,11 +10669,50 @@
1065610669
#else
1065710670
# define IOTRACE(A)
1065810671
# define sqlite3VdbeIOTraceSql(X)
1065910672
#endif
1066010673
10674
+/*
10675
+** These routines are available for the mem2.c debugging memory allocator
10676
+** only. They are used to verify that different "types" of memory
10677
+** allocations are properly tracked by the system.
10678
+**
10679
+** sqlite3MemdebugSetType() sets the "type" of an allocation to one of
10680
+** the MEMTYPE_* macros defined below. The type must be a bitmask with
10681
+** a single bit set.
10682
+**
10683
+** sqlite3MemdebugHasType() returns true if any of the bits in its second
10684
+** argument match the type set by the previous sqlite3MemdebugSetType().
10685
+** sqlite3MemdebugHasType() is intended for use inside assert() statements.
10686
+** For example:
10687
+**
10688
+** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
10689
+**
10690
+** Perhaps the most important point is the difference between MEMTYPE_HEAP
10691
+** and MEMTYPE_DB. If an allocation is MEMTYPE_DB, that means it might have
10692
+** been allocated by lookaside, except the allocation was too large or
10693
+** lookaside was already full. It is important to verify that allocations
10694
+** that might have been satisfied by lookaside are not passed back to
10695
+** non-lookaside free() routines. Asserts such as the example above are
10696
+** placed on the non-lookaside free() routines to verify this constraint.
10697
+**
10698
+** All of this is no-op for a production build. It only comes into
10699
+** play when the SQLITE_MEMDEBUG compile-time option is used.
10700
+*/
10701
+#ifdef SQLITE_MEMDEBUG
10702
+SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
10703
+SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
10704
+#else
10705
+# define sqlite3MemdebugSetType(X,Y) /* no-op */
10706
+# define sqlite3MemdebugHasType(X,Y) 1
1066110707
#endif
10708
+#define MEMTYPE_HEAP 0x01 /* General heap allocations */
10709
+#define MEMTYPE_DB 0x02 /* Associated with a database connection */
10710
+#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
10711
+#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
10712
+
10713
+#endif /* _SQLITEINT_H_ */
1066210714
1066310715
/************** End of sqliteInt.h *******************************************/
1066410716
/************** Begin file global.c ******************************************/
1066510717
/*
1066610718
** 2008 June 13
@@ -11038,10 +11090,13 @@
1103811090
#ifdef SQLITE_OMIT_AUTOINCREMENT
1103911091
"OMIT_AUTOINCREMENT",
1104011092
#endif
1104111093
#ifdef SQLITE_OMIT_AUTOINIT
1104211094
"OMIT_AUTOINIT",
11095
+#endif
11096
+#ifdef SQLITE_OMIT_AUTOMATIC_INDEX
11097
+ "OMIT_AUTOMATIC_INDEX",
1104311098
#endif
1104411099
#ifdef SQLITE_OMIT_AUTOVACUUM
1104511100
"OMIT_AUTOVACUUM",
1104611101
#endif
1104711102
#ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
@@ -11367,10 +11422,30 @@
1136711422
if( resetFlag ){
1136811423
db->lookaside.mxOut = db->lookaside.nOut;
1136911424
}
1137011425
break;
1137111426
}
11427
+
11428
+ /*
11429
+ ** Return an approximation for the amount of memory currently used
11430
+ ** by all pagers associated with the given database connection. The
11431
+ ** highwater mark is meaningless and is returned as zero.
11432
+ */
11433
+ case SQLITE_DBSTATUS_CACHE_USED: {
11434
+ int totalUsed = 0;
11435
+ int i;
11436
+ for(i=0; i<db->nDb; i++){
11437
+ Btree *pBt = db->aDb[i].pBt;
11438
+ if( pBt ){
11439
+ Pager *pPager = sqlite3BtreePager(pBt);
11440
+ totalUsed += sqlite3PagerMemUsed(pPager);
11441
+ }
11442
+ }
11443
+ *pCurrent = totalUsed;
11444
+ *pHighwater = 0;
11445
+ break;
11446
+ }
1137211447
default: {
1137311448
return SQLITE_ERROR;
1137411449
}
1137511450
}
1137611451
return SQLITE_OK;
@@ -13140,11 +13215,12 @@
1314013215
struct MemBlockHdr {
1314113216
i64 iSize; /* Size of this allocation */
1314213217
struct MemBlockHdr *pNext, *pPrev; /* Linked list of all unfreed memory */
1314313218
char nBacktrace; /* Number of backtraces on this alloc */
1314413219
char nBacktraceSlots; /* Available backtrace slots */
13145
- short nTitle; /* Bytes of title; includes '\0' */
13220
+ u8 nTitle; /* Bytes of title; includes '\0' */
13221
+ u8 eType; /* Allocation type code */
1314613222
int iForeGuard; /* Guard word for sanity */
1314713223
};
1314813224
1314913225
/*
1315013226
** Guard words
@@ -13348,10 +13424,11 @@
1334813424
}else{
1334913425
mem.pFirst = pHdr;
1335013426
}
1335113427
mem.pLast = pHdr;
1335213428
pHdr->iForeGuard = FOREGUARD;
13429
+ pHdr->eType = MEMTYPE_HEAP;
1335313430
pHdr->nBacktraceSlots = mem.nBacktrace;
1335413431
pHdr->nTitle = mem.nTitle;
1335513432
if( mem.nBacktrace ){
1335613433
void *aAddr[40];
1335713434
pHdr->nBacktrace = backtrace(aAddr, mem.nBacktrace+1)-1;
@@ -13454,10 +13531,51 @@
1345413531
sqlite3MemShutdown,
1345513532
0
1345613533
};
1345713534
sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
1345813535
}
13536
+
13537
+/*
13538
+** Set the "type" of an allocation.
13539
+*/
13540
+SQLITE_PRIVATE void sqlite3MemdebugSetType(void *p, u8 eType){
13541
+ if( p ){
13542
+ struct MemBlockHdr *pHdr;
13543
+ pHdr = sqlite3MemsysGetHeader(p);
13544
+ assert( pHdr->iForeGuard==FOREGUARD );
13545
+ pHdr->eType = eType;
13546
+ }
13547
+}
13548
+
13549
+/*
13550
+** Return TRUE if the mask of type in eType matches the type of the
13551
+** allocation p. Also return true if p==NULL.
13552
+**
13553
+** This routine is designed for use within an assert() statement, to
13554
+** verify the type of an allocation. For example:
13555
+**
13556
+** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
13557
+*/
13558
+SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
13559
+ int rc = 1;
13560
+ if( p ){
13561
+ struct MemBlockHdr *pHdr;
13562
+ pHdr = sqlite3MemsysGetHeader(p);
13563
+ assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
13564
+ assert( (pHdr->eType & (pHdr->eType-1))==0 ); /* Only one type bit set */
13565
+ if( (pHdr->eType&eType)==0 ){
13566
+ void **pBt;
13567
+ pBt = (void**)pHdr;
13568
+ pBt -= pHdr->nBacktraceSlots;
13569
+ backtrace_symbols_fd(pBt, pHdr->nBacktrace, fileno(stderr));
13570
+ fprintf(stderr, "\n");
13571
+ rc = 0;
13572
+ }
13573
+ }
13574
+ return rc;
13575
+}
13576
+
1345913577
1346013578
/*
1346113579
** Set the number of backtrace levels kept for each allocation.
1346213580
** A value of zero turns off backtracing. The number is always rounded
1346313581
** up to a multiple of 2.
@@ -16446,10 +16564,11 @@
1644616564
if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
1644716565
sqlite3_mutex_leave(mem0.mutex);
1644816566
}else{
1644916567
p = sqlite3GlobalConfig.m.xMalloc(n);
1645016568
}
16569
+ sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
1645116570
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
1645216571
scratchAllocOut = p!=0;
1645316572
#endif
1645416573
return p;
1645516574
}
@@ -16466,10 +16585,12 @@
1646616585
#endif
1646716586
1646816587
if( sqlite3GlobalConfig.pScratch==0
1646916588
|| p<sqlite3GlobalConfig.pScratch
1647016589
|| p>=(void*)mem0.aScratchFree ){
16590
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
16591
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
1647116592
if( sqlite3GlobalConfig.bMemstat ){
1647216593
int iSize = sqlite3MallocSize(p);
1647316594
sqlite3_mutex_enter(mem0.mutex);
1647416595
sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
1647516596
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
@@ -16506,26 +16627,30 @@
1650616627
/*
1650716628
** Return the size of a memory allocation previously obtained from
1650816629
** sqlite3Malloc() or sqlite3_malloc().
1650916630
*/
1651016631
SQLITE_PRIVATE int sqlite3MallocSize(void *p){
16632
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1651116633
return sqlite3GlobalConfig.m.xSize(p);
1651216634
}
1651316635
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
1651416636
assert( db==0 || sqlite3_mutex_held(db->mutex) );
1651516637
if( isLookaside(db, p) ){
1651616638
return db->lookaside.sz;
1651716639
}else{
16640
+ assert( sqlite3MemdebugHasType(p,
16641
+ db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
1651816642
return sqlite3GlobalConfig.m.xSize(p);
1651916643
}
1652016644
}
1652116645
1652216646
/*
1652316647
** Free memory previously obtained from sqlite3Malloc().
1652416648
*/
1652516649
SQLITE_API void sqlite3_free(void *p){
1652616650
if( p==0 ) return;
16651
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1652716652
if( sqlite3GlobalConfig.bMemstat ){
1652816653
sqlite3_mutex_enter(mem0.mutex);
1652916654
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
1653016655
sqlite3GlobalConfig.m.xFree(p);
1653116656
sqlite3_mutex_leave(mem0.mutex);
@@ -16544,10 +16669,12 @@
1654416669
LookasideSlot *pBuf = (LookasideSlot*)p;
1654516670
pBuf->pNext = db->lookaside.pFree;
1654616671
db->lookaside.pFree = pBuf;
1654716672
db->lookaside.nOut--;
1654816673
}else{
16674
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16675
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
1654916676
sqlite3_free(p);
1655016677
}
1655116678
}
1655216679
1655316680
/*
@@ -16576,10 +16703,11 @@
1657616703
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
1657716704
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
1657816705
mem0.alarmThreshold ){
1657916706
sqlite3MallocAlarm(nNew-nOld);
1658016707
}
16708
+ assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
1658116709
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1658216710
if( pNew==0 && mem0.alarmCallback ){
1658316711
sqlite3MallocAlarm(nBytes);
1658416712
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1658516713
}
@@ -16673,10 +16801,12 @@
1667316801
#endif
1667416802
p = sqlite3Malloc(n);
1667516803
if( !p && db ){
1667616804
db->mallocFailed = 1;
1667716805
}
16806
+ sqlite3MemdebugSetType(p,
16807
+ (db && db->lookaside.bEnabled) ? MEMTYPE_DB : MEMTYPE_HEAP);
1667816808
return p;
1667916809
}
1668016810
1668116811
/*
1668216812
** Resize the block of memory pointed to by p to n bytes. If the
@@ -16698,14 +16828,18 @@
1669816828
if( pNew ){
1669916829
memcpy(pNew, p, db->lookaside.sz);
1670016830
sqlite3DbFree(db, p);
1670116831
}
1670216832
}else{
16833
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16834
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
1670316835
pNew = sqlite3_realloc(p, n);
1670416836
if( !pNew ){
1670516837
db->mallocFailed = 1;
1670616838
}
16839
+ sqlite3MemdebugSetType(pNew,
16840
+ db->lookaside.bEnabled ? MEMTYPE_DB : MEMTYPE_HEAP);
1670716841
}
1670816842
}
1670916843
return pNew;
1671016844
}
1671116845
@@ -18305,11 +18439,11 @@
1830518439
u8 isPrepareV2; /* True if prepared with prepare_v2() */
1830618440
int nChange; /* Number of db changes made since last reset */
1830718441
int btreeMask; /* Bitmask of db->aDb[] entries referenced */
1830818442
i64 startTime; /* Time when query started - used for profiling */
1830918443
BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
18310
- int aCounter[2]; /* Counters used by sqlite3_stmt_status() */
18444
+ int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
1831118445
char *zSql; /* Text of the SQL statement that generated this */
1831218446
void *pFree; /* Free this when deleting the vdbe */
1831318447
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1831418448
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
1831518449
int iStatement; /* Statement number (or 0 if has not opened stmt) */
@@ -20345,52 +20479,52 @@
2034520479
/* 35 */ "ReadCookie",
2034620480
/* 36 */ "SetCookie",
2034720481
/* 37 */ "VerifyCookie",
2034820482
/* 38 */ "OpenRead",
2034920483
/* 39 */ "OpenWrite",
20350
- /* 40 */ "OpenEphemeral",
20351
- /* 41 */ "OpenPseudo",
20352
- /* 42 */ "Close",
20353
- /* 43 */ "SeekLt",
20354
- /* 44 */ "SeekLe",
20355
- /* 45 */ "SeekGe",
20356
- /* 46 */ "SeekGt",
20357
- /* 47 */ "Seek",
20358
- /* 48 */ "NotFound",
20359
- /* 49 */ "Found",
20360
- /* 50 */ "IsUnique",
20361
- /* 51 */ "NotExists",
20362
- /* 52 */ "Sequence",
20363
- /* 53 */ "NewRowid",
20364
- /* 54 */ "Insert",
20365
- /* 55 */ "InsertInt",
20366
- /* 56 */ "Delete",
20367
- /* 57 */ "ResetCount",
20368
- /* 58 */ "RowKey",
20369
- /* 59 */ "RowData",
20370
- /* 60 */ "Rowid",
20371
- /* 61 */ "NullRow",
20372
- /* 62 */ "Last",
20373
- /* 63 */ "Sort",
20374
- /* 64 */ "Rewind",
20375
- /* 65 */ "Prev",
20376
- /* 66 */ "Next",
20377
- /* 67 */ "IdxInsert",
20484
+ /* 40 */ "OpenAutoindex",
20485
+ /* 41 */ "OpenEphemeral",
20486
+ /* 42 */ "OpenPseudo",
20487
+ /* 43 */ "Close",
20488
+ /* 44 */ "SeekLt",
20489
+ /* 45 */ "SeekLe",
20490
+ /* 46 */ "SeekGe",
20491
+ /* 47 */ "SeekGt",
20492
+ /* 48 */ "Seek",
20493
+ /* 49 */ "NotFound",
20494
+ /* 50 */ "Found",
20495
+ /* 51 */ "IsUnique",
20496
+ /* 52 */ "NotExists",
20497
+ /* 53 */ "Sequence",
20498
+ /* 54 */ "NewRowid",
20499
+ /* 55 */ "Insert",
20500
+ /* 56 */ "InsertInt",
20501
+ /* 57 */ "Delete",
20502
+ /* 58 */ "ResetCount",
20503
+ /* 59 */ "RowKey",
20504
+ /* 60 */ "RowData",
20505
+ /* 61 */ "Rowid",
20506
+ /* 62 */ "NullRow",
20507
+ /* 63 */ "Last",
20508
+ /* 64 */ "Sort",
20509
+ /* 65 */ "Rewind",
20510
+ /* 66 */ "Prev",
20511
+ /* 67 */ "Next",
2037820512
/* 68 */ "Or",
2037920513
/* 69 */ "And",
20380
- /* 70 */ "IdxDelete",
20381
- /* 71 */ "IdxRowid",
20382
- /* 72 */ "IdxLT",
20514
+ /* 70 */ "IdxInsert",
20515
+ /* 71 */ "IdxDelete",
20516
+ /* 72 */ "IdxRowid",
2038320517
/* 73 */ "IsNull",
2038420518
/* 74 */ "NotNull",
2038520519
/* 75 */ "Ne",
2038620520
/* 76 */ "Eq",
2038720521
/* 77 */ "Gt",
2038820522
/* 78 */ "Le",
2038920523
/* 79 */ "Lt",
2039020524
/* 80 */ "Ge",
20391
- /* 81 */ "IdxGE",
20525
+ /* 81 */ "IdxLT",
2039220526
/* 82 */ "BitAnd",
2039320527
/* 83 */ "BitOr",
2039420528
/* 84 */ "ShiftLeft",
2039520529
/* 85 */ "ShiftRight",
2039620530
/* 86 */ "Add",
@@ -20397,54 +20531,54 @@
2039720531
/* 87 */ "Subtract",
2039820532
/* 88 */ "Multiply",
2039920533
/* 89 */ "Divide",
2040020534
/* 90 */ "Remainder",
2040120535
/* 91 */ "Concat",
20402
- /* 92 */ "Destroy",
20536
+ /* 92 */ "IdxGE",
2040320537
/* 93 */ "BitNot",
2040420538
/* 94 */ "String8",
20405
- /* 95 */ "Clear",
20406
- /* 96 */ "CreateIndex",
20407
- /* 97 */ "CreateTable",
20408
- /* 98 */ "ParseSchema",
20409
- /* 99 */ "LoadAnalysis",
20410
- /* 100 */ "DropTable",
20411
- /* 101 */ "DropIndex",
20412
- /* 102 */ "DropTrigger",
20413
- /* 103 */ "IntegrityCk",
20414
- /* 104 */ "RowSetAdd",
20415
- /* 105 */ "RowSetRead",
20416
- /* 106 */ "RowSetTest",
20417
- /* 107 */ "Program",
20418
- /* 108 */ "Param",
20419
- /* 109 */ "FkCounter",
20420
- /* 110 */ "FkIfZero",
20421
- /* 111 */ "MemMax",
20422
- /* 112 */ "IfPos",
20423
- /* 113 */ "IfNeg",
20424
- /* 114 */ "IfZero",
20425
- /* 115 */ "AggStep",
20426
- /* 116 */ "AggFinal",
20427
- /* 117 */ "Vacuum",
20428
- /* 118 */ "IncrVacuum",
20429
- /* 119 */ "Expire",
20430
- /* 120 */ "TableLock",
20431
- /* 121 */ "VBegin",
20432
- /* 122 */ "VCreate",
20433
- /* 123 */ "VDestroy",
20434
- /* 124 */ "VOpen",
20435
- /* 125 */ "VFilter",
20436
- /* 126 */ "VColumn",
20437
- /* 127 */ "VNext",
20438
- /* 128 */ "VRename",
20439
- /* 129 */ "VUpdate",
20539
+ /* 95 */ "Destroy",
20540
+ /* 96 */ "Clear",
20541
+ /* 97 */ "CreateIndex",
20542
+ /* 98 */ "CreateTable",
20543
+ /* 99 */ "ParseSchema",
20544
+ /* 100 */ "LoadAnalysis",
20545
+ /* 101 */ "DropTable",
20546
+ /* 102 */ "DropIndex",
20547
+ /* 103 */ "DropTrigger",
20548
+ /* 104 */ "IntegrityCk",
20549
+ /* 105 */ "RowSetAdd",
20550
+ /* 106 */ "RowSetRead",
20551
+ /* 107 */ "RowSetTest",
20552
+ /* 108 */ "Program",
20553
+ /* 109 */ "Param",
20554
+ /* 110 */ "FkCounter",
20555
+ /* 111 */ "FkIfZero",
20556
+ /* 112 */ "MemMax",
20557
+ /* 113 */ "IfPos",
20558
+ /* 114 */ "IfNeg",
20559
+ /* 115 */ "IfZero",
20560
+ /* 116 */ "AggStep",
20561
+ /* 117 */ "AggFinal",
20562
+ /* 118 */ "Vacuum",
20563
+ /* 119 */ "IncrVacuum",
20564
+ /* 120 */ "Expire",
20565
+ /* 121 */ "TableLock",
20566
+ /* 122 */ "VBegin",
20567
+ /* 123 */ "VCreate",
20568
+ /* 124 */ "VDestroy",
20569
+ /* 125 */ "VOpen",
20570
+ /* 126 */ "VFilter",
20571
+ /* 127 */ "VColumn",
20572
+ /* 128 */ "VNext",
20573
+ /* 129 */ "VRename",
2044020574
/* 130 */ "Real",
20441
- /* 131 */ "Pagecount",
20442
- /* 132 */ "Trace",
20443
- /* 133 */ "Noop",
20444
- /* 134 */ "Explain",
20445
- /* 135 */ "NotUsed_135",
20575
+ /* 131 */ "VUpdate",
20576
+ /* 132 */ "Pagecount",
20577
+ /* 133 */ "Trace",
20578
+ /* 134 */ "Noop",
20579
+ /* 135 */ "Explain",
2044620580
/* 136 */ "NotUsed_136",
2044720581
/* 137 */ "NotUsed_137",
2044820582
/* 138 */ "NotUsed_138",
2044920583
/* 139 */ "NotUsed_139",
2045020584
/* 140 */ "NotUsed_140",
@@ -26155,13 +26289,11 @@
2615526289
flags |= SQLITE_OPEN_READONLY;
2615626290
openFlags |= O_RDONLY;
2615726291
fd = open(zName, openFlags, openMode);
2615826292
}
2615926293
if( fd<0 ){
26160
- sqlite3_log(SQLITE_CANTOPEN, "cannot open file [%s]: %s", zName,
26161
- strerror(errno));
26162
- rc = SQLITE_CANTOPEN;
26294
+ rc = SQLITE_CANTOPEN_BKPT;
2616326295
goto open_finished;
2616426296
}
2616526297
}
2616626298
assert( fd>=0 );
2616726299
if( pOutFlags ){
@@ -30816,11 +30948,16 @@
3081630948
if( pCache->pCache ){
3081730949
PgHdr *p;
3081830950
PgHdr *pNext;
3081930951
for(p=pCache->pDirty; p; p=pNext){
3082030952
pNext = p->pDirtyNext;
30821
- if( p->pgno>pgno ){
30953
+ /* This routine never gets call with a positive pgno except right
30954
+ ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
30955
+ ** it must be that pgno==0.
30956
+ */
30957
+ assert( p->pgno>0 );
30958
+ if( ALWAYS(p->pgno>pgno) ){
3082230959
assert( p->flags&PGHDR_DIRTY );
3082330960
sqlite3PcacheMakeClean(p);
3082430961
}
3082530962
}
3082630963
if( pgno==0 && pCache->pPage1 ){
@@ -31160,10 +31297,11 @@
3116031297
pcache1EnterMutex();
3116131298
if( p ){
3116231299
int sz = sqlite3MallocSize(p);
3116331300
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
3116431301
}
31302
+ sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
3116531303
}
3116631304
return p;
3116731305
}
3116831306
3116931307
/*
@@ -31177,11 +31315,14 @@
3117731315
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
3117831316
pSlot = (PgFreeslot*)p;
3117931317
pSlot->pNext = pcache1.pFree;
3118031318
pcache1.pFree = pSlot;
3118131319
}else{
31182
- int iSize = sqlite3MallocSize(p);
31320
+ int iSize;
31321
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
31322
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
31323
+ iSize = sqlite3MallocSize(p);
3118331324
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
3118431325
sqlite3_free(p);
3118531326
}
3118631327
}
3118731328
@@ -32213,10 +32354,91 @@
3221332354
** file simultaneously, or one process from reading the database while
3221432355
** another is writing.
3221532356
*/
3221632357
#ifndef SQLITE_OMIT_DISKIO
3221732358
32359
+/*
32360
+******************** NOTES ON THE DESIGN OF THE PAGER ************************
32361
+**
32362
+** Within this comment block, a page is deemed to have been synced
32363
+** automatically as soon as it is written when PRAGMA synchronous=OFF.
32364
+** Otherwise, the page is not synced until the xSync method of the VFS
32365
+** is called successfully on the file containing the page.
32366
+**
32367
+** Definition: A page of the database file is said to be "overwriteable" if
32368
+** one or more of the following are true about the page:
32369
+**
32370
+** (a) The original content of the page as it was at the beginning of
32371
+** the transaction has been written into the rollback journal and
32372
+** synced.
32373
+**
32374
+** (b) The page was a freelist leaf page at the start of the transaction.
32375
+**
32376
+** (c) The page number is greater than the largest page that existed in
32377
+** the database file at the start of the transaction.
32378
+**
32379
+** (1) A page of the database file is never overwritten unless one of the
32380
+** following are true:
32381
+**
32382
+** (a) The page and all other pages on the same sector are overwriteable.
32383
+**
32384
+** (b) The atomic page write optimization is enabled, and the entire
32385
+** transaction other than the update of the transaction sequence
32386
+** number consists of a single page change.
32387
+**
32388
+** (2) The content of a page written into the rollback journal exactly matches
32389
+** both the content in the database when the rollback journal was written
32390
+** and the content in the database at the beginning of the current
32391
+** transaction.
32392
+**
32393
+** (3) Writes to the database file are an integer multiple of the page size
32394
+** in length and are aligned to a page boundary.
32395
+**
32396
+** (4) Reads from the database file are either aligned on a page boundary and
32397
+** an integer multiple of the page size in length or are taken from the
32398
+** first 100 bytes of the database file.
32399
+**
32400
+** (5) All writes to the database file are synced prior to the rollback journal
32401
+** being deleted, truncated, or zeroed.
32402
+**
32403
+** (6) If a master journal file is used, then all writes to the database file
32404
+** are synced prior to the master journal being deleted.
32405
+**
32406
+** Definition: Two databases (or the same database at two points it time)
32407
+** are said to be "logically equivalent" if they give the same answer to
32408
+** all queries. Note in particular the the content of freelist leaf
32409
+** pages can be changed arbitarily without effecting the logical equivalence
32410
+** of the database.
32411
+**
32412
+** (7) At any time, if any subset, including the empty set and the total set,
32413
+** of the unsynced changes to a rollback journal are removed and the
32414
+** journal is rolled back, the resulting database file will be logical
32415
+** equivalent to the database file at the beginning of the transaction.
32416
+**
32417
+** (8) When a transaction is rolled back, the xTruncate method of the VFS
32418
+** is called to restore the database file to the same size it was at
32419
+** the beginning of the transaction. (In some VFSes, the xTruncate
32420
+** method is a no-op, but that does not change the fact the SQLite will
32421
+** invoke it.)
32422
+**
32423
+** (9) Whenever the database file is modified, at least one bit in the range
32424
+** of bytes from 24 through 39 inclusive will be changed prior to releasing
32425
+** the EXCLUSIVE lock.
32426
+**
32427
+** (10) The pattern of bits in bytes 24 through 39 shall not repeat in less
32428
+** than one billion transactions.
32429
+**
32430
+** (11) A database file is well-formed at the beginning and at the conclusion
32431
+** of every transaction.
32432
+**
32433
+** (12) An EXCLUSIVE lock is held on the database file when writing to
32434
+** the database file.
32435
+**
32436
+** (13) A SHARED lock is held on the database file while reading any
32437
+** content out of the database file.
32438
+*/
32439
+
3221832440
/*
3221932441
** Macros for troubleshooting. Normally turned off
3222032442
*/
3222132443
#if 0
3222232444
int sqlite3PagerTrace=1; /* True to enable tracing */
@@ -32389,11 +32611,12 @@
3238932611
** It is used when committing or otherwise ending a transaction. If
3239032612
** the dbModified flag is clear then less work has to be done.
3239132613
**
3239232614
** journalStarted
3239332615
**
32394
-** This flag is set whenever the the main journal is synced.
32616
+** This flag is set whenever the the main journal is opened and
32617
+** initialized
3239532618
**
3239632619
** The point of this flag is that it must be set after the
3239732620
** first journal header in a journal file has been synced to disk.
3239832621
** After this has happened, new pages appended to the database
3239932622
** do not need the PGHDR_NEED_SYNC flag set, as they do not need
@@ -32415,11 +32638,14 @@
3241532638
** master journal name is only written to the journal file the first
3241632639
** time CommitPhaseOne() is called.
3241732640
**
3241832641
** doNotSync
3241932642
**
32420
-** This variable is set and cleared by sqlite3PagerWrite().
32643
+** When enabled, cache spills are prohibited and the journal file cannot
32644
+** be synced. This variable is set and cleared by sqlite3PagerWrite()
32645
+** in order to prevent a journal sync from happening in between the
32646
+** journalling of two pages on the same sector.
3242132647
**
3242232648
** needSync
3242332649
**
3242432650
** TODO: It might be easier to set this variable in writeJournalHdr()
3242532651
** and writeMasterJournal() only. Change its meaning to "unsynced data
@@ -32475,10 +32701,11 @@
3247532701
sqlite3_file *fd; /* File descriptor for database */
3247632702
sqlite3_file *jfd; /* File descriptor for main journal */
3247732703
sqlite3_file *sjfd; /* File descriptor for sub-journal */
3247832704
i64 journalOff; /* Current write offset in the journal file */
3247932705
i64 journalHdr; /* Byte offset to previous journal header */
32706
+ i64 journalSizeLimit; /* Size limit for persistent journal files */
3248032707
PagerSavepoint *aSavepoint; /* Array of active savepoints */
3248132708
int nSavepoint; /* Number of elements in aSavepoint[] */
3248232709
char dbFileVers[16]; /* Changes whenever database file changes */
3248332710
u32 sectorSize; /* Assumed sector size during rollback */
3248432711
@@ -32501,11 +32728,10 @@
3250132728
void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */
3250232729
void (*xCodecFree)(void*); /* Destructor for the codec */
3250332730
void *pCodec; /* First argument to xCodec... methods */
3250432731
#endif
3250532732
char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
32506
- i64 journalSizeLimit; /* Size limit for persistent journal files */
3250732733
PCache *pPCache; /* Pointer to page cache object */
3250832734
sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
3250932735
};
3251032736
3251132737
/*
@@ -33017,10 +33243,11 @@
3301733243
** to populate the entire journal header sector.
3301833244
*/
3301933245
for(nWrite=0; rc==SQLITE_OK&&nWrite<JOURNAL_HDR_SZ(pPager); nWrite+=nHeader){
3302033246
IOTRACE(("JHDR %p %lld %d\n", pPager, pPager->journalHdr, nHeader))
3302133247
rc = sqlite3OsWrite(pPager->jfd, zHeader, nHeader, pPager->journalOff);
33248
+ assert( pPager->journalHdr <= pPager->journalOff );
3302233249
pPager->journalOff += nHeader;
3302333250
}
3302433251
3302533252
return rc;
3302633253
}
@@ -33175,10 +33402,11 @@
3317533402
){
3317633403
return SQLITE_OK;
3317733404
}
3317833405
pPager->setMaster = 1;
3317933406
assert( isOpen(pPager->jfd) );
33407
+ assert( pPager->journalHdr <= pPager->journalOff );
3318033408
3318133409
/* Calculate the length in bytes and the checksum of zMaster */
3318233410
for(nMaster=0; zMaster[nMaster]; nMaster++){
3318333411
cksum += zMaster[nMaster];
3318433412
}
@@ -33315,12 +33543,13 @@
3331533543
pPager->pInJournal = 0;
3331633544
releaseAllSavepoints(pPager);
3331733545
3331833546
/* If the file is unlocked, somebody else might change it. The
3331933547
** values stored in Pager.dbSize etc. might become invalid if
33320
- ** this happens. TODO: Really, this doesn't need to be cleared
33548
+ ** this happens. One can argue that this doesn't need to be cleared
3332133549
** until the change-counter check fails in PagerSharedLock().
33550
+ ** Clearing the page size cache here is being conservative.
3332233551
*/
3332333552
pPager->dbSizeValid = 0;
3332433553
3332533554
rc = osUnlock(pPager->fd, NO_LOCK);
3332633555
if( rc ){
@@ -33506,16 +33735,15 @@
3350633735
}
3350733736
3350833737
#ifdef SQLITE_CHECK_PAGES
3350933738
sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
3351033739
#endif
33511
-
33512
- sqlite3PcacheCleanAll(pPager->pPCache);
33513
- sqlite3BitvecDestroy(pPager->pInJournal);
33514
- pPager->pInJournal = 0;
33515
- pPager->nRec = 0;
3351633740
}
33741
+ sqlite3BitvecDestroy(pPager->pInJournal);
33742
+ pPager->pInJournal = 0;
33743
+ pPager->nRec = 0;
33744
+ sqlite3PcacheCleanAll(pPager->pPCache);
3351733745
3351833746
if( !pPager->exclusiveMode ){
3351933747
rc2 = osUnlock(pPager->fd, SHARED_LOCK);
3352033748
pPager->state = PAGER_SHARED;
3352133749
pPager->changeCountDone = 0;
@@ -33604,22 +33832,22 @@
3360433832
** allocated by this function. If this is the case and an allocation fails,
3360533833
** SQLITE_NOMEM is returned.
3360633834
*/
3360733835
static int pager_playback_one_page(
3360833836
Pager *pPager, /* The pager being played back */
33609
- int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
33610
- int isUnsync, /* True if reading from unsynced main journal */
3361133837
i64 *pOffset, /* Offset of record to playback */
33612
- int isSavepnt, /* True for a savepoint rollback */
33613
- Bitvec *pDone /* Bitvec of pages already played back */
33838
+ Bitvec *pDone, /* Bitvec of pages already played back */
33839
+ int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
33840
+ int isSavepnt /* True for a savepoint rollback */
3361433841
){
3361533842
int rc;
3361633843
PgHdr *pPg; /* An existing page in the cache */
3361733844
Pgno pgno; /* The page number of a page in journal */
3361833845
u32 cksum; /* Checksum used for sanity checking */
3361933846
char *aData; /* Temporary storage for the page */
3362033847
sqlite3_file *jfd; /* The file descriptor for the journal file */
33848
+ int isSynced; /* True if journal page is synced */
3362133849
3362233850
assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
3362333851
assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
3362433852
assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */
3362533853
assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
@@ -33699,16 +33927,21 @@
3369933927
assert( pPg || !MEMDB );
3370033928
PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
3370133929
PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
3370233930
(isMainJrnl?"main-journal":"sub-journal")
3370333931
));
33932
+ if( isMainJrnl ){
33933
+ isSynced = pPager->noSync || (*pOffset <= pPager->journalHdr);
33934
+ }else{
33935
+ isSynced = (pPg==0 || 0==(pPg->flags & PGHDR_NEED_SYNC));
33936
+ }
3370433937
if( (pPager->state>=PAGER_EXCLUSIVE)
33705
- && (pPg==0 || 0==(pPg->flags&PGHDR_NEED_SYNC))
3370633938
&& isOpen(pPager->fd)
33707
- && !isUnsync
33939
+ && isSynced
3370833940
){
3370933941
i64 ofst = (pgno-1)*(i64)pPager->pageSize;
33942
+ testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
3371033943
rc = sqlite3OsWrite(pPager->fd, (u8*)aData, pPager->pageSize, ofst);
3371133944
if( pgno>pPager->dbFileSize ){
3371233945
pPager->dbFileSize = pgno;
3371333946
}
3371433947
if( pPager->pBackup ){
@@ -33753,11 +33986,12 @@
3375333986
pPager->xReiniter(pPg);
3375433987
if( isMainJrnl && (!isSavepnt || *pOffset<=pPager->journalHdr) ){
3375533988
/* If the contents of this page were just restored from the main
3375633989
** journal file, then its content must be as they were when the
3375733990
** transaction was first opened. In this case we can mark the page
33758
- ** as clean, since there will be no need to write it out to the.
33991
+ ** as clean, since there will be no need to write it out to the
33992
+ ** database.
3375933993
**
3376033994
** There is one exception to this rule. If the page is being rolled
3376133995
** back as part of a savepoint (or statement) rollback from an
3376233996
** unsynced portion of the main journal file, then it is not safe
3376333997
** to mark the page as clean. This is because marking the page as
@@ -34100,12 +34334,10 @@
3410034334
/* This loop terminates either when a readJournalHdr() or
3410134335
** pager_playback_one_page() call returns SQLITE_DONE or an IO error
3410234336
** occurs.
3410334337
*/
3410434338
while( 1 ){
34105
- int isUnsync = 0;
34106
-
3410734339
/* Read the next journal header from the journal file. If there are
3410834340
** not enough bytes left in the journal file for a complete header, or
3410934341
** it is corrupted, then a process must of failed while writing it.
3411034342
** This indicates nothing more needs to be rolled back.
3411134343
*/
@@ -34142,11 +34374,10 @@
3414234374
** should be computed based on the journal file size.
3414334375
*/
3414434376
if( nRec==0 && !isHot &&
3414534377
pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){
3414634378
nRec = (int)((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager));
34147
- isUnsync = 1;
3414834379
}
3414934380
3415034381
/* If this is the first header read from the journal, truncate the
3415134382
** database file back to its original size.
3415234383
*/
@@ -34164,16 +34395,24 @@
3416434395
for(u=0; u<nRec; u++){
3416534396
if( needPagerReset ){
3416634397
pager_reset(pPager);
3416734398
needPagerReset = 0;
3416834399
}
34169
- rc = pager_playback_one_page(pPager,1,isUnsync,&pPager->journalOff,0,0);
34400
+ rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
3417034401
if( rc!=SQLITE_OK ){
3417134402
if( rc==SQLITE_DONE ){
3417234403
rc = SQLITE_OK;
3417334404
pPager->journalOff = szJ;
3417434405
break;
34406
+ }else if( rc==SQLITE_IOERR_SHORT_READ ){
34407
+ /* If the journal has been truncated, simply stop reading and
34408
+ ** processing the journal. This might happen if the journal was
34409
+ ** not completely written and synced prior to a crash. In that
34410
+ ** case, the database should have never been written in the
34411
+ ** first place so it is OK to simply abandon the rollback. */
34412
+ rc = SQLITE_OK;
34413
+ goto end_playback;
3417534414
}else{
3417634415
/* If we are unable to rollback, quit and return the error
3417734416
** code. This will cause the pager to enter the error state
3417834417
** so that no further harm will be done. Perhaps the next
3417934418
** process to come along will be able to rollback the database.
@@ -34309,11 +34548,11 @@
3430934548
*/
3431034549
if( pSavepoint ){
3431134550
iHdrOff = pSavepoint->iHdrOffset ? pSavepoint->iHdrOffset : szJ;
3431234551
pPager->journalOff = pSavepoint->iOffset;
3431334552
while( rc==SQLITE_OK && pPager->journalOff<iHdrOff ){
34314
- rc = pager_playback_one_page(pPager, 1, 0, &pPager->journalOff, 1, pDone);
34553
+ rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
3431534554
}
3431634555
assert( rc!=SQLITE_DONE );
3431734556
}else{
3431834557
pPager->journalOff = 0;
3431934558
}
@@ -34339,11 +34578,11 @@
3433934578
&& pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff
3434034579
){
3434134580
nJRec = (u32)((szJ - pPager->journalOff)/JOURNAL_PG_SZ(pPager));
3434234581
}
3434334582
for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
34344
- rc = pager_playback_one_page(pPager, 1, 0, &pPager->journalOff, 1, pDone);
34583
+ rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
3434534584
}
3434634585
assert( rc!=SQLITE_DONE );
3434734586
}
3434834587
assert( rc!=SQLITE_OK || pPager->journalOff==szJ );
3434934588
@@ -34354,11 +34593,11 @@
3435434593
if( pSavepoint ){
3435534594
u32 ii; /* Loop counter */
3435634595
i64 offset = pSavepoint->iSubRec*(4+pPager->pageSize);
3435734596
for(ii=pSavepoint->iSubRec; rc==SQLITE_OK && ii<pPager->nSubRec; ii++){
3435834597
assert( offset==ii*(4+pPager->pageSize) );
34359
- rc = pager_playback_one_page(pPager, 0, 0, &offset, 1, pDone);
34598
+ rc = pager_playback_one_page(pPager, &offset, pDone, 0, 1);
3436034599
}
3436134600
assert( rc!=SQLITE_DONE );
3436234601
}
3436334602
3436434603
sqlite3BitvecDestroy(pDone);
@@ -34575,14 +34814,16 @@
3457534814
** maximum page count below the current size of the database.
3457634815
**
3457734816
** Regardless of mxPage, return the current maximum page count.
3457834817
*/
3457934818
SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
34819
+ int nPage;
3458034820
if( mxPage>0 ){
3458134821
pPager->mxPgno = mxPage;
3458234822
}
34583
- sqlite3PagerPagecount(pPager, 0);
34823
+ sqlite3PagerPagecount(pPager, &nPage);
34824
+ assert( pPager->mxPgno>=nPage );
3458434825
return pPager->mxPgno;
3458534826
}
3458634827
3458734828
/*
3458834829
** The following set of routines are used to disable the simulated
@@ -34652,15 +34893,10 @@
3465234893
** and *pnPage is set to the number of pages in the database.
3465334894
*/
3465434895
SQLITE_PRIVATE int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
3465534896
Pgno nPage; /* Value to return via *pnPage */
3465634897
34657
- /* If the pager is already in the error state, return the error code. */
34658
- if( pPager->errCode ){
34659
- return pPager->errCode;
34660
- }
34661
-
3466234898
/* Determine the number of pages in the file. Store this in nPage. */
3466334899
if( pPager->dbSizeValid ){
3466434900
nPage = pPager->dbSize;
3466534901
}else{
3466634902
int rc; /* Error returned by OsFileSize() */
@@ -34690,13 +34926,11 @@
3469034926
if( nPage>pPager->mxPgno ){
3469134927
pPager->mxPgno = (Pgno)nPage;
3469234928
}
3469334929
3469434930
/* Set the output variable and return SQLITE_OK */
34695
- if( pnPage ){
34696
- *pnPage = nPage;
34697
- }
34931
+ *pnPage = nPage;
3469834932
return SQLITE_OK;
3469934933
}
3470034934
3470134935
3470234936
/*
@@ -34796,10 +35030,35 @@
3479635030
assert( pPager->dbSize>=nPage );
3479735031
assert( pPager->state>=PAGER_RESERVED );
3479835032
pPager->dbSize = nPage;
3479935033
assertTruncateConstraint(pPager);
3480035034
}
35035
+
35036
+/*
35037
+** This function is called before attempting a hot-journal rollback. It
35038
+** syncs the journal file to disk, then sets pPager->journalHdr to the
35039
+** size of the journal file so that the pager_playback() routine knows
35040
+** that the entire journal file has been synced.
35041
+**
35042
+** Syncing a hot-journal to disk before attempting to roll it back ensures
35043
+** that if a power-failure occurs during the rollback, the process that
35044
+** attempts rollback following system recovery sees the same journal
35045
+** content as this process.
35046
+**
35047
+** If everything goes as planned, SQLITE_OK is returned. Otherwise,
35048
+** an SQLite error code.
35049
+*/
35050
+static int pagerSyncHotJournal(Pager *pPager){
35051
+ int rc = SQLITE_OK;
35052
+ if( !pPager->noSync ){
35053
+ rc = sqlite3OsSync(pPager->jfd, SQLITE_SYNC_NORMAL);
35054
+ }
35055
+ if( rc==SQLITE_OK ){
35056
+ rc = sqlite3OsFileSize(pPager->jfd, &pPager->journalHdr);
35057
+ }
35058
+ return rc;
35059
+}
3480135060
3480235061
/*
3480335062
** Shutdown the page cache. Free all memory and close all files.
3480435063
**
3480535064
** If a transaction was in progress when this routine is called, that
@@ -34826,11 +35085,13 @@
3482635085
** call which may be made from within pagerUnlockAndRollback(). If it
3482735086
** is not -1, then the unsynced portion of an open journal file may
3482835087
** be played back into the database. If a power failure occurs while
3482935088
** this is happening, the database may become corrupt.
3483035089
*/
34831
- pPager->journalHdr = -1;
35090
+ if( isOpen(pPager->jfd) ){
35091
+ pPager->errCode = pagerSyncHotJournal(pPager);
35092
+ }
3483235093
pagerUnlockAndRollback(pPager);
3483335094
}
3483435095
sqlite3EndBenignMalloc();
3483535096
enable_simulated_io_errors();
3483635097
PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
@@ -34916,11 +35177,11 @@
3491635177
/* This block deals with an obscure problem. If the last connection
3491735178
** that wrote to this database was operating in persistent-journal
3491835179
** mode, then the journal file may at this point actually be larger
3491935180
** than Pager.journalOff bytes. If the next thing in the journal
3492035181
** file happens to be a journal-header (written as part of the
34921
- ** previous connections transaction), and a crash or power-failure
35182
+ ** previous connection's transaction), and a crash or power-failure
3492235183
** occurs after nRec is updated but before this connection writes
3492335184
** anything else to the journal file (or commits/rolls back its
3492435185
** transaction), then SQLite may become confused when doing the
3492535186
** hot-journal rollback following recovery. It may roll back all
3492635187
** of this connections data, then proceed to rolling back the old,
@@ -34988,10 +35249,11 @@
3498835249
/* The journal file was just successfully synced. Set Pager.needSync
3498935250
** to zero and clear the PGHDR_NEED_SYNC flag on all pagess.
3499035251
*/
3499135252
pPager->needSync = 0;
3499235253
pPager->journalStarted = 1;
35254
+ pPager->journalHdr = pPager->journalOff;
3499335255
sqlite3PcacheClearSyncFlags(pPager->pPCache);
3499435256
}
3499535257
3499635258
return SQLITE_OK;
3499735259
}
@@ -35850,23 +36112,32 @@
3585036112
}
3585136113
if( rc!=SQLITE_OK ){
3585236114
goto failed;
3585336115
}
3585436116
35855
- /* TODO: Why are these cleared here? Is it necessary? */
36117
+ /* Reset the journal status fields to indicates that we have no
36118
+ ** rollback journal at this time. */
3585636119
pPager->journalStarted = 0;
3585736120
pPager->journalOff = 0;
3585836121
pPager->setMaster = 0;
3585936122
pPager->journalHdr = 0;
36123
+
36124
+ /* Make sure the journal file has been synced to disk. */
3586036125
3586136126
/* Playback and delete the journal. Drop the database write
3586236127
** lock and reacquire the read lock. Purge the cache before
3586336128
** playing back the hot-journal so that we don't end up with
35864
- ** an inconsistent cache.
36129
+ ** an inconsistent cache. Sync the hot journal before playing
36130
+ ** it back since the process that crashed and left the hot journal
36131
+ ** probably did not sync it and we are required to always sync
36132
+ ** the journal before playing it back.
3586536133
*/
3586636134
if( isOpen(pPager->jfd) ){
35867
- rc = pager_playback(pPager, 1);
36135
+ rc = pagerSyncHotJournal(pPager);
36136
+ if( rc==SQLITE_OK ){
36137
+ rc = pager_playback(pPager, 1);
36138
+ }
3586836139
if( rc!=SQLITE_OK ){
3586936140
rc = pager_error(pPager, rc);
3587036141
goto failed;
3587136142
}
3587236143
}
@@ -35890,20 +36161,20 @@
3589036161
**
3589136162
** There is a vanishingly small chance that a change will not be
3589236163
** detected. The chance of an undetected change is so small that
3589336164
** it can be neglected.
3589436165
*/
36166
+ int nPage;
3589536167
char dbFileVers[sizeof(pPager->dbFileVers)];
35896
- sqlite3PagerPagecount(pPager, 0);
36168
+ sqlite3PagerPagecount(pPager, &nPage);
3589736169
3589836170
if( pPager->errCode ){
3589936171
rc = pPager->errCode;
3590036172
goto failed;
3590136173
}
3590236174
35903
- assert( pPager->dbSizeValid );
35904
- if( pPager->dbSize>0 ){
36175
+ if( nPage>0 ){
3590536176
IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
3590636177
rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
3590736178
if( rc!=SQLITE_OK ){
3590836179
goto failed;
3590936180
}
@@ -35968,11 +36239,11 @@
3596836239
** of the page. This occurs in two seperate scenarios:
3596936240
**
3597036241
** a) When reading a free-list leaf page from the database, and
3597136242
**
3597236243
** b) When a savepoint is being rolled back and we need to load
35973
-** a new page into the cache to populate with the data read
36244
+** a new page into the cache to be filled with the data read
3597436245
** from the savepoint journal.
3597536246
**
3597636247
** If noContent is true, then the data returned is zeroed instead of
3597736248
** being read from the database. Additionally, the bits corresponding
3597836249
** to pgno in Pager.pInJournal (bitvec of pages already written to the
@@ -36024,11 +36295,11 @@
3602436295
goto pager_acquire_err;
3602536296
}
3602636297
assert( (*ppPage)->pgno==pgno );
3602736298
assert( (*ppPage)->pPager==pPager || (*ppPage)->pPager==0 );
3602836299
36029
- if( (*ppPage)->pPager ){
36300
+ if( (*ppPage)->pPager && !noContent ){
3603036301
/* In this case the pcache already contains an initialized copy of
3603136302
** the page. Return without further ado. */
3603236303
assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
3603336304
PAGER_INCR(pPager->nHit);
3603436305
return SQLITE_OK;
@@ -36184,10 +36455,11 @@
3618436455
** SQLITE_NOMEM if the attempt to allocate Pager.pInJournal fails, or
3618536456
** an IO error code if opening or writing the journal file fails.
3618636457
*/
3618736458
static int pager_open_journal(Pager *pPager){
3618836459
int rc = SQLITE_OK; /* Return code */
36460
+ int nPage; /* Size of database file */
3618936461
sqlite3_vfs * const pVfs = pPager->pVfs; /* Local cache of vfs pointer */
3619036462
3619136463
assert( pPager->state>=PAGER_RESERVED );
3619236464
assert( pPager->useJournal );
3619336465
assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF );
@@ -36196,17 +36468,14 @@
3619636468
/* If already in the error state, this function is a no-op. But on
3619736469
** the other hand, this routine is never called if we are already in
3619836470
** an error state. */
3619936471
if( NEVER(pPager->errCode) ) return pPager->errCode;
3620036472
36201
- /* TODO: Is it really possible to get here with dbSizeValid==0? If not,
36202
- ** the call to PagerPagecount() can be removed.
36203
- */
3620436473
testcase( pPager->dbSizeValid==0 );
36205
- sqlite3PagerPagecount(pPager, 0);
36206
-
36207
- pPager->pInJournal = sqlite3BitvecCreate(pPager->dbSize);
36474
+ rc = sqlite3PagerPagecount(pPager, &nPage);
36475
+ if( rc ) return rc;
36476
+ pPager->pInJournal = sqlite3BitvecCreate(nPage);
3620836477
if( pPager->pInJournal==0 ){
3620936478
return SQLITE_NOMEM;
3621036479
}
3621136480
3621236481
/* Open the journal file if it is not already open. */
@@ -36301,16 +36570,15 @@
3630136570
if( exFlag ){
3630236571
rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
3630336572
}
3630436573
}
3630536574
36306
- /* If the required locks were successfully obtained, open the journal
36307
- ** file and write the first journal-header to it.
36575
+ /* No need to open the journal file at this time. It will be
36576
+ ** opened before it is written to. If we defer opening the journal,
36577
+ ** we might save the work of creating a file if the transaction
36578
+ ** ends up being a no-op.
3630836579
*/
36309
- if( rc==SQLITE_OK && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
36310
- rc = pager_open_journal(pPager);
36311
- }
3631236580
}else if( isOpen(pPager->jfd) && pPager->journalOff==0 ){
3631336581
/* This happens when the pager was in exclusive-access mode the last
3631436582
** time a (read or write) transaction was successfully concluded
3631536583
** by this connection. Instead of deleting the journal file it was
3631636584
** kept open and either was truncated to 0 bytes or its header was
@@ -36321,11 +36589,10 @@
3632136589
assert( pPager->pInJournal==0 );
3632236590
rc = pager_open_journal(pPager);
3632336591
}
3632436592
3632536593
PAGERTRACE(("TRANSACTION %d\n", PAGERID(pPager)));
36326
- assert( !isOpen(pPager->jfd) || pPager->journalOff>0 || rc!=SQLITE_OK );
3632736594
if( rc!=SQLITE_OK ){
3632836595
assert( !pPager->dbModified );
3632936596
/* Ignore any IO error that occurs within pager_end_transaction(). The
3633036597
** purpose of this call is to reset the internal state of the pager
3633136598
** sub-system. It doesn't matter if the journal-file is not properly
@@ -36351,12 +36618,12 @@
3635136618
/* This routine is not called unless a transaction has already been
3635236619
** started.
3635336620
*/
3635436621
assert( pPager->state>=PAGER_RESERVED );
3635536622
36356
- /* If an error has been previously detected, we should not be
36357
- ** calling this routine. Repeat the error for robustness.
36623
+ /* If an error has been previously detected, report the same error
36624
+ ** again.
3635836625
*/
3635936626
if( NEVER(pPager->errCode) ) return pPager->errCode;
3636036627
3636136628
/* Higher-level routines never call this function if database is not
3636236629
** writable. But check anyway, just for robustness. */
@@ -36377,15 +36644,15 @@
3637736644
/* If we get this far, it means that the page needs to be
3637836645
** written to the transaction journal or the ckeckpoint journal
3637936646
** or both.
3638036647
**
3638136648
** Higher level routines should have already started a transaction,
36382
- ** which means they have acquired the necessary locks and opened
36383
- ** a rollback journal. Double-check to makes sure this is the case.
36649
+ ** which means they have acquired the necessary locks but the rollback
36650
+ ** journal might not yet be open.
3638436651
*/
3638536652
rc = sqlite3PagerBegin(pPager, 0, pPager->subjInMemory);
36386
- if( NEVER(rc!=SQLITE_OK) ){
36653
+ if( rc!=SQLITE_OK ){
3638736654
return rc;
3638836655
}
3638936656
if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
3639036657
assert( pPager->useJournal );
3639136658
rc = pager_open_journal(pPager);
@@ -36404,10 +36671,12 @@
3640436671
3640536672
/* We should never write to the journal file the page that
3640636673
** contains the database locks. The following assert verifies
3640736674
** that we do not. */
3640836675
assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
36676
+
36677
+ assert( pPager->journalHdr <= pPager->journalOff );
3640936678
CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
3641036679
cksum = pager_cksum(pPager, (u8*)pData2);
3641136680
rc = write32bits(pPager->jfd, pPager->journalOff, pPg->pgno);
3641236681
if( rc==SQLITE_OK ){
3641336682
rc = sqlite3OsWrite(pPager->jfd, pData2, pPager->pageSize,
@@ -36523,11 +36792,12 @@
3652336792
** an integer power of 2. It sets variable pg1 to the identifier
3652436793
** of the first page of the sector pPg is located on.
3652536794
*/
3652636795
pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
3652736796
36528
- sqlite3PagerPagecount(pPager, (int *)&nPageCount);
36797
+ rc = sqlite3PagerPagecount(pPager, (int *)&nPageCount);
36798
+ if( rc ) return rc;
3652936799
if( pPg->pgno>nPageCount ){
3653036800
nPage = (pPg->pgno - pg1)+1;
3653136801
}else if( (pg1+nPagePerSector-1)>nPageCount ){
3653236802
nPage = nPageCount+1-pg1;
3653336803
}else{
@@ -36684,10 +36954,13 @@
3668436954
/* Increment the value just read and write it back to byte 24. */
3668536955
change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
3668636956
change_counter++;
3668736957
put32bits(((char*)pPgHdr->pData)+24, change_counter);
3668836958
36959
+ /* Also store the SQLite version number in bytes 96..99 */
36960
+ put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
36961
+
3668936962
/* If running in direct mode, write the contents of page 1 to the file. */
3669036963
if( DIRECT_MODE ){
3669136964
const void *zBuf = pPgHdr->pData;
3669236965
assert( pPager->dbFileSize>0 );
3669336966
rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
@@ -36757,13 +37030,11 @@
3675737030
int rc = SQLITE_OK; /* Return code */
3675837031
3675937032
/* The dbOrigSize is never set if journal_mode=OFF */
3676037033
assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF || pPager->dbOrigSize==0 );
3676137034
36762
- /* If a prior error occurred, this routine should not be called. ROLLBACK
36763
- ** is the appropriate response to an error, not COMMIT. Guard against
36764
- ** coding errors by repeating the prior error. */
37035
+ /* If a prior error occurred, report that error again. */
3676537036
if( NEVER(pPager->errCode) ) return pPager->errCode;
3676637037
3676737038
PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
3676837039
pPager->zFilename, zMaster, pPager->dbSize));
3676937040
@@ -37048,10 +37319,20 @@
3704837319
** Return the number of references to the pager.
3704937320
*/
3705037321
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
3705137322
return sqlite3PcacheRefCount(pPager->pPCache);
3705237323
}
37324
+
37325
+/*
37326
+** Return the approximate number of bytes of memory currently
37327
+** used by the pager and its associated cache.
37328
+*/
37329
+SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
37330
+ int perPageSize = pPager->pageSize + pPager->nExtra + 20;
37331
+ return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
37332
+ + sqlite3MallocSize(pPager);
37333
+}
3705337334
3705437335
/*
3705537336
** Return the number of references to the specified page.
3705637337
*/
3705737338
SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage *pPage){
@@ -37101,15 +37382,14 @@
3710137382
int nCurrent = pPager->nSavepoint; /* Current number of savepoints */
3710237383
3710337384
if( nSavepoint>nCurrent && pPager->useJournal ){
3710437385
int ii; /* Iterator variable */
3710537386
PagerSavepoint *aNew; /* New Pager.aSavepoint array */
37387
+ int nPage; /* Size of database file */
3710637388
37107
- /* Either there is no active journal or the sub-journal is open or
37108
- ** the journal is always stored in memory */
37109
- assert( pPager->nSavepoint==0 || isOpen(pPager->sjfd) ||
37110
- pPager->journalMode==PAGER_JOURNALMODE_MEMORY );
37389
+ rc = sqlite3PagerPagecount(pPager, &nPage);
37390
+ if( rc ) return rc;
3711137391
3711237392
/* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
3711337393
** if the allocation fails. Otherwise, zero the new portion in case a
3711437394
** malloc failure occurs while populating it in the for(...) loop below.
3711537395
*/
@@ -37123,19 +37403,18 @@
3712337403
pPager->aSavepoint = aNew;
3712437404
pPager->nSavepoint = nSavepoint;
3712537405
3712637406
/* Populate the PagerSavepoint structures just allocated. */
3712737407
for(ii=nCurrent; ii<nSavepoint; ii++){
37128
- assert( pPager->dbSizeValid );
37129
- aNew[ii].nOrig = pPager->dbSize;
37130
- if( isOpen(pPager->jfd) && ALWAYS(pPager->journalOff>0) ){
37408
+ aNew[ii].nOrig = nPage;
37409
+ if( isOpen(pPager->jfd) && pPager->journalOff>0 ){
3713137410
aNew[ii].iOffset = pPager->journalOff;
3713237411
}else{
3713337412
aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
3713437413
}
3713537414
aNew[ii].iSubRec = pPager->nSubRec;
37136
- aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
37415
+ aNew[ii].pInSavepoint = sqlite3BitvecCreate(nPage);
3713737416
if( !aNew[ii].pInSavepoint ){
3713837417
return SQLITE_NOMEM;
3713937418
}
3714037419
}
3714137420
@@ -37518,10 +37797,19 @@
3751837797
&& (!isOpen(pPager->jfd) || 0==pPager->journalOff)
3751937798
){
3752037799
if( isOpen(pPager->jfd) ){
3752137800
sqlite3OsClose(pPager->jfd);
3752237801
}
37802
+ assert( (PAGER_JOURNALMODE_TRUNCATE & 1)==1 );
37803
+ assert( (PAGER_JOURNALMODE_PERSIST & 1)==1 );
37804
+ assert( (PAGER_JOURNALMODE_DELETE & 1)==0 );
37805
+ assert( (PAGER_JOURNALMODE_MEMORY & 1)==0 );
37806
+ assert( (PAGER_JOURNALMODE_OFF & 1)==0 );
37807
+ if( (pPager->journalMode & 1)==1 && (eMode & 1)==0
37808
+ && !pPager->exclusiveMode ){
37809
+ sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
37810
+ }
3752337811
pPager->journalMode = (u8)eMode;
3752437812
}
3752537813
return (int)pPager->journalMode;
3752637814
}
3752737815
@@ -37978,10 +38266,11 @@
3797838266
BtCursor *pCursor; /* A list of all open cursors */
3797938267
MemPage *pPage1; /* First page of the database */
3798038268
u8 readOnly; /* True if the underlying file is readonly */
3798138269
u8 pageSizeFixed; /* True if the page size can no longer be changed */
3798238270
u8 secureDelete; /* True if secure_delete is enabled */
38271
+ u8 initiallyEmpty; /* Database is empty at start of transaction */
3798338272
#ifndef SQLITE_OMIT_AUTOVACUUM
3798438273
u8 autoVacuum; /* True if auto-vacuum is enabled */
3798538274
u8 incrVacuum; /* True if incr-vacuum is enabled */
3798638275
#endif
3798738276
u16 pageSize; /* Total number of bytes on a page */
@@ -37990,10 +38279,11 @@
3799038279
u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
3799138280
u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
3799238281
u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
3799338282
u8 inTransaction; /* Transaction state */
3799438283
int nTransaction; /* Number of open transactions (read + write) */
38284
+ u32 nPage; /* Number of pages in the database */
3799538285
void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
3799638286
void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */
3799738287
sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
3799838288
Bitvec *pHasContent; /* Set of pages moved to free-list this transaction */
3799938289
#ifndef SQLITE_OMIT_SHARED_CACHE
@@ -39070,15 +39360,12 @@
3907039360
** at the end of every transaction.
3907139361
*/
3907239362
static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
3907339363
int rc = SQLITE_OK;
3907439364
if( !pBt->pHasContent ){
39075
- int nPage = 100;
39076
- sqlite3PagerPagecount(pBt->pPager, &nPage);
39077
- /* If sqlite3PagerPagecount() fails there is no harm because the
39078
- ** nPage variable is unchanged from its default value of 100 */
39079
- pBt->pHasContent = sqlite3BitvecCreate((u32)nPage);
39365
+ assert( pgno<=pBt->nPage );
39366
+ pBt->pHasContent = sqlite3BitvecCreate(pBt->nPage);
3908039367
if( !pBt->pHasContent ){
3908139368
rc = SQLITE_NOMEM;
3908239369
}
3908339370
}
3908439371
if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
@@ -40117,17 +40404,17 @@
4011740404
4011840405
/*
4011940406
** Return the size of the database file in pages. If there is any kind of
4012040407
** error, return ((unsigned int)-1).
4012140408
*/
40122
-static Pgno pagerPagecount(BtShared *pBt){
40123
- int nPage = -1;
40124
- int rc;
40125
- assert( pBt->pPage1 );
40126
- rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40127
- assert( rc==SQLITE_OK || nPage==-1 );
40128
- return (Pgno)nPage;
40409
+static Pgno btreePagecount(BtShared *pBt){
40410
+ return pBt->nPage;
40411
+}
40412
+SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
40413
+ assert( sqlite3BtreeHoldsMutex(p) );
40414
+ assert( ((p->pBt->nPage)&0x8000000)==0 );
40415
+ return (int)btreePagecount(p->pBt);
4012940416
}
4013040417
4013140418
/*
4013240419
** Get a page from the pager and initialize it. This routine is just a
4013340420
** convenience wrapper around separate calls to btreeGetPage() and
@@ -40140,29 +40427,22 @@
4014040427
BtShared *pBt, /* The database file */
4014140428
Pgno pgno, /* Number of the page to get */
4014240429
MemPage **ppPage /* Write the page pointer here */
4014340430
){
4014440431
int rc;
40145
- TESTONLY( Pgno iLastPg = pagerPagecount(pBt); )
4014640432
assert( sqlite3_mutex_held(pBt->mutex) );
4014740433
40434
+ if( pgno<=0 || pgno>btreePagecount(pBt) ){
40435
+ return SQLITE_CORRUPT_BKPT;
40436
+ }
4014840437
rc = btreeGetPage(pBt, pgno, ppPage, 0);
4014940438
if( rc==SQLITE_OK ){
4015040439
rc = btreeInitPage(*ppPage);
4015140440
if( rc!=SQLITE_OK ){
4015240441
releasePage(*ppPage);
4015340442
}
4015440443
}
40155
-
40156
- /* If the requested page number was either 0 or greater than the page
40157
- ** number of the last page in the database, this function should return
40158
- ** SQLITE_CORRUPT or some other error (i.e. SQLITE_FULL). Check that this
40159
- ** is the case. */
40160
- assert( (pgno>0 && pgno<=iLastPg) || rc!=SQLITE_OK );
40161
- testcase( pgno==0 );
40162
- testcase( pgno==iLastPg );
40163
-
4016440444
return rc;
4016540445
}
4016640446
4016740447
/*
4016840448
** Release a MemPage. This should be called once for each prior
@@ -40794,13 +41074,15 @@
4079441074
** well-formed database file, then SQLITE_CORRUPT is returned.
4079541075
** SQLITE_BUSY is returned if the database is locked. SQLITE_NOMEM
4079641076
** is returned if we run out of memory.
4079741077
*/
4079841078
static int lockBtree(BtShared *pBt){
40799
- int rc;
40800
- MemPage *pPage1;
40801
- int nPage;
41079
+ int rc; /* Result code from subfunctions */
41080
+ MemPage *pPage1; /* Page 1 of the database file */
41081
+ int nPage; /* Number of pages in the database */
41082
+ int nPageFile = 0; /* Number of pages in the database file */
41083
+ int nPageHeader; /* Number of pages in the database according to hdr */
4080241084
4080341085
assert( sqlite3_mutex_held(pBt->mutex) );
4080441086
assert( pBt->pPage1==0 );
4080541087
rc = sqlite3PagerSharedLock(pBt->pPager);
4080641088
if( rc!=SQLITE_OK ) return rc;
@@ -40808,14 +41090,18 @@
4080841090
if( rc!=SQLITE_OK ) return rc;
4080941091
4081041092
/* Do some checking to help insure the file we opened really is
4081141093
** a valid database file.
4081241094
*/
40813
- rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40814
- if( rc!=SQLITE_OK ){
41095
+ nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData);
41096
+ if( (rc = sqlite3PagerPagecount(pBt->pPager, &nPageFile))!=SQLITE_OK ){;
4081541097
goto page1_init_failed;
40816
- }else if( nPage>0 ){
41098
+ }
41099
+ if( nPage==0 ){
41100
+ nPage = nPageFile;
41101
+ }
41102
+ if( nPage>0 ){
4081741103
int pageSize;
4081841104
int usableSize;
4081941105
u8 *page1 = pPage1->aData;
4082041106
rc = SQLITE_NOTADB;
4082141107
if( memcmp(page1, zMagicHeader, 16)!=0 ){
@@ -40857,10 +41143,14 @@
4085741143
freeTempSpace(pBt);
4085841144
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
4085941145
pageSize-usableSize);
4086041146
return rc;
4086141147
}
41148
+ if( nPageHeader>nPageFile ){
41149
+ rc = SQLITE_CORRUPT_BKPT;
41150
+ goto page1_init_failed;
41151
+ }
4086241152
if( usableSize<480 ){
4086341153
goto page1_init_failed;
4086441154
}
4086541155
pBt->pageSize = (u16)pageSize;
4086641156
pBt->usableSize = (u16)usableSize;
@@ -40887,10 +41177,11 @@
4088741177
pBt->minLocal = (pBt->usableSize-12)*32/255 - 23;
4088841178
pBt->maxLeaf = pBt->usableSize - 35;
4088941179
pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23;
4089041180
assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
4089141181
pBt->pPage1 = pPage1;
41182
+ pBt->nPage = nPage;
4089241183
return SQLITE_OK;
4089341184
4089441185
page1_init_failed:
4089541186
releasePage(pPage1);
4089641187
pBt->pPage1 = 0;
@@ -40924,16 +41215,14 @@
4092441215
*/
4092541216
static int newDatabase(BtShared *pBt){
4092641217
MemPage *pP1;
4092741218
unsigned char *data;
4092841219
int rc;
40929
- int nPage;
4093041220
4093141221
assert( sqlite3_mutex_held(pBt->mutex) );
40932
- rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40933
- if( rc!=SQLITE_OK || nPage>0 ){
40934
- return rc;
41222
+ if( pBt->nPage>0 ){
41223
+ return SQLITE_OK;
4093541224
}
4093641225
pP1 = pBt->pPage1;
4093741226
assert( pP1!=0 );
4093841227
data = pP1->aData;
4093941228
rc = sqlite3PagerWrite(pP1->pDbPage);
@@ -40955,10 +41244,12 @@
4095541244
assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
4095641245
assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
4095741246
put4byte(&data[36 + 4*4], pBt->autoVacuum);
4095841247
put4byte(&data[36 + 7*4], pBt->incrVacuum);
4095941248
#endif
41249
+ pBt->nPage = 1;
41250
+ data[31] = 1;
4096041251
return SQLITE_OK;
4096141252
}
4096241253
4096341254
/*
4096441255
** Attempt to start a new transaction. A write-transaction
@@ -41044,10 +41335,11 @@
4104441335
** page 1. So if some other shared-cache client already has a write-lock
4104541336
** on page 1, the transaction cannot be opened. */
4104641337
rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
4104741338
if( SQLITE_OK!=rc ) goto trans_begun;
4104841339
41340
+ pBt->initiallyEmpty = pBt->nPage==0;
4104941341
do {
4105041342
/* Call lockBtree() until either pBt->pPage1 is populated or
4105141343
** lockBtree() returns something other than SQLITE_OK. lockBtree()
4105241344
** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
4105341345
** reading page 1 it discovers that the page-size of the database
@@ -41323,16 +41615,16 @@
4132341615
** which may or may not empty the freelist. A full autovacuum
4132441616
** has nFin>0. A "PRAGMA incremental_vacuum" has nFin==0.
4132541617
*/
4132641618
static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg){
4132741619
Pgno nFreeList; /* Number of pages still on the free-list */
41620
+ int rc;
4132841621
4132941622
assert( sqlite3_mutex_held(pBt->mutex) );
4133041623
assert( iLastPg>nFin );
4133141624
4133241625
if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
41333
- int rc;
4133441626
u8 eType;
4133541627
Pgno iPtrPage;
4133641628
4133741629
nFreeList = get4byte(&pBt->pPage1->aData[36]);
4133841630
if( nFreeList==0 ){
@@ -41404,11 +41696,11 @@
4140441696
if( nFin==0 ){
4140541697
iLastPg--;
4140641698
while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
4140741699
if( PTRMAP_ISPAGE(pBt, iLastPg) ){
4140841700
MemPage *pPg;
41409
- int rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
41701
+ rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
4141041702
if( rc!=SQLITE_OK ){
4141141703
return rc;
4141241704
}
4141341705
rc = sqlite3PagerWrite(pPg->pDbPage);
4141441706
releasePage(pPg);
@@ -41417,10 +41709,11 @@
4141741709
}
4141841710
}
4141941711
iLastPg--;
4142041712
}
4142141713
sqlite3PagerTruncateImage(pBt->pPager, iLastPg);
41714
+ pBt->nPage = iLastPg;
4142241715
}
4142341716
return SQLITE_OK;
4142441717
}
4142541718
4142641719
/*
@@ -41439,11 +41732,15 @@
4143941732
assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
4144041733
if( !pBt->autoVacuum ){
4144141734
rc = SQLITE_DONE;
4144241735
}else{
4144341736
invalidateAllOverflowCache(pBt);
41444
- rc = incrVacuumStep(pBt, 0, pagerPagecount(pBt));
41737
+ rc = incrVacuumStep(pBt, 0, btreePagecount(pBt));
41738
+ if( rc==SQLITE_OK ){
41739
+ rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
41740
+ put4byte(&pBt->pPage1->aData[28], pBt->nPage);
41741
+ }
4144541742
}
4144641743
sqlite3BtreeLeave(p);
4144741744
return rc;
4144841745
}
4144941746
@@ -41470,11 +41767,11 @@
4147041767
Pgno nPtrmap; /* Number of PtrMap pages to be freed */
4147141768
Pgno iFree; /* The next page to be freed */
4147241769
int nEntry; /* Number of entries on one ptrmap page */
4147341770
Pgno nOrig; /* Database size before freeing */
4147441771
41475
- nOrig = pagerPagecount(pBt);
41772
+ nOrig = btreePagecount(pBt);
4147641773
if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
4147741774
/* It is not possible to create a database for which the final page
4147841775
** is either a pointer-map page or the pending-byte page. If one
4147941776
** is encountered, this indicates corruption.
4148041777
*/
@@ -41495,15 +41792,16 @@
4149541792
4149641793
for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
4149741794
rc = incrVacuumStep(pBt, nFin, iFree);
4149841795
}
4149941796
if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
41500
- rc = SQLITE_OK;
4150141797
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
4150241798
put4byte(&pBt->pPage1->aData[32], 0);
4150341799
put4byte(&pBt->pPage1->aData[36], 0);
41800
+ put4byte(&pBt->pPage1->aData[28], nFin);
4150441801
sqlite3PagerTruncateImage(pBt->pPager, nFin);
41802
+ pBt->nPage = nFin;
4150541803
}
4150641804
if( rc!=SQLITE_OK ){
4150741805
sqlite3PagerRollback(pPager);
4150841806
}
4150941807
}
@@ -41749,10 +42047,15 @@
4174942047
4175042048
/* The rollback may have destroyed the pPage1->aData value. So
4175142049
** call btreeGetPage() on page 1 again to make
4175242050
** sure pPage1->aData is set correctly. */
4175342051
if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
42052
+ int nPage = get4byte(28+(u8*)pPage1->aData);
42053
+ testcase( nPage==0 );
42054
+ if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
42055
+ testcase( pBt->nPage!=nPage );
42056
+ pBt->nPage = nPage;
4175442057
releasePage(pPage1);
4175542058
}
4175642059
assert( countWriteCursors(pBt)==0 );
4175742060
pBt->inTransaction = TRANS_READ;
4175842061
}
@@ -41786,21 +42089,17 @@
4178642089
sqlite3BtreeEnter(p);
4178742090
assert( p->inTrans==TRANS_WRITE );
4178842091
assert( pBt->readOnly==0 );
4178942092
assert( iStatement>0 );
4179042093
assert( iStatement>p->db->nSavepoint );
41791
- if( NEVER(p->inTrans!=TRANS_WRITE || pBt->readOnly) ){
41792
- rc = SQLITE_INTERNAL;
41793
- }else{
41794
- assert( pBt->inTransaction==TRANS_WRITE );
41795
- /* At the pager level, a statement transaction is a savepoint with
41796
- ** an index greater than all savepoints created explicitly using
41797
- ** SQL statements. It is illegal to open, release or rollback any
41798
- ** such savepoints while the statement transaction savepoint is active.
41799
- */
41800
- rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
41801
- }
42094
+ assert( pBt->inTransaction==TRANS_WRITE );
42095
+ /* At the pager level, a statement transaction is a savepoint with
42096
+ ** an index greater than all savepoints created explicitly using
42097
+ ** SQL statements. It is illegal to open, release or rollback any
42098
+ ** such savepoints while the statement transaction savepoint is active.
42099
+ */
42100
+ rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
4180242101
sqlite3BtreeLeave(p);
4180342102
return rc;
4180442103
}
4180542104
4180642105
/*
@@ -41822,11 +42121,16 @@
4182242121
assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
4182342122
assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
4182442123
sqlite3BtreeEnter(p);
4182542124
rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
4182642125
if( rc==SQLITE_OK ){
42126
+ if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
4182742127
rc = newDatabase(pBt);
42128
+ pBt->nPage = get4byte(28 + pBt->pPage1->aData);
42129
+ if( pBt->nPage==0 ){
42130
+ sqlite3PagerPagecount(pBt->pPager, (int*)&pBt->nPage);
42131
+ }
4182842132
}
4182942133
sqlite3BtreeLeave(p);
4183042134
}
4183142135
return rc;
4183242136
}
@@ -41888,11 +42192,11 @@
4188842192
assert( pBt->pPage1 && pBt->pPage1->aData );
4188942193
4189042194
if( NEVER(wrFlag && pBt->readOnly) ){
4189142195
return SQLITE_READONLY;
4189242196
}
41893
- if( iTable==1 && pagerPagecount(pBt)==0 ){
42197
+ if( iTable==1 && btreePagecount(pBt)==0 ){
4189442198
return SQLITE_EMPTY;
4189542199
}
4189642200
4189742201
/* Now that no other errors can occur, finish filling in the BtCursor
4189842202
** variables and link the cursor into the BtShared list. */
@@ -42159,11 +42463,11 @@
4215942463
4216042464
while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){
4216142465
iGuess++;
4216242466
}
4216342467
42164
- if( iGuess<=pagerPagecount(pBt) ){
42468
+ if( iGuess<=btreePagecount(pBt) ){
4216542469
rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
4216642470
if( rc==SQLITE_OK && eType==PTRMAP_OVERFLOW2 && pgno==ovfl ){
4216742471
next = iGuess;
4216842472
rc = SQLITE_DONE;
4216942473
}
@@ -43191,11 +43495,11 @@
4319143495
MemPage *pPrevTrunk = 0;
4319243496
Pgno mxPage; /* Total size of the database file */
4319343497
4319443498
assert( sqlite3_mutex_held(pBt->mutex) );
4319543499
pPage1 = pBt->pPage1;
43196
- mxPage = pagerPagecount(pBt);
43500
+ mxPage = btreePagecount(pBt);
4319743501
n = get4byte(&pPage1->aData[36]);
4319843502
testcase( n==mxPage-1 );
4319943503
if( n>=mxPage ){
4320043504
return SQLITE_CORRUPT_BKPT;
4320143505
}
@@ -43387,39 +43691,39 @@
4338743691
pPrevTrunk = 0;
4338843692
}while( searchList );
4338943693
}else{
4339043694
/* There are no pages on the freelist, so create a new page at the
4339143695
** end of the file */
43392
- int nPage = pagerPagecount(pBt);
43393
- *pPgno = nPage + 1;
43394
-
43395
- if( *pPgno==PENDING_BYTE_PAGE(pBt) ){
43396
- (*pPgno)++;
43397
- }
43696
+ rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
43697
+ if( rc ) return rc;
43698
+ pBt->nPage++;
43699
+ if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
4339843700
4339943701
#ifndef SQLITE_OMIT_AUTOVACUUM
43400
- if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
43702
+ if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, pBt->nPage) ){
4340143703
/* If *pPgno refers to a pointer-map page, allocate two new pages
4340243704
** at the end of the file instead of one. The first allocated page
4340343705
** becomes a new pointer-map page, the second is used by the caller.
4340443706
*/
4340543707
MemPage *pPg = 0;
43406
- TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
43407
- assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43408
- rc = btreeGetPage(pBt, *pPgno, &pPg, 0);
43708
+ TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
43709
+ assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
43710
+ rc = btreeGetPage(pBt, pBt->nPage, &pPg, 1);
4340943711
if( rc==SQLITE_OK ){
4341043712
rc = sqlite3PagerWrite(pPg->pDbPage);
4341143713
releasePage(pPg);
4341243714
}
4341343715
if( rc ) return rc;
43414
- (*pPgno)++;
43415
- if( *pPgno==PENDING_BYTE_PAGE(pBt) ){ (*pPgno)++; }
43716
+ pBt->nPage++;
43717
+ if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ){ pBt->nPage++; }
4341643718
}
4341743719
#endif
43720
+ put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
43721
+ *pPgno = pBt->nPage;
4341843722
4341943723
assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43420
- rc = btreeGetPage(pBt, *pPgno, ppPage, 0);
43724
+ rc = btreeGetPage(pBt, *pPgno, ppPage, 1);
4342143725
if( rc ) return rc;
4342243726
rc = sqlite3PagerWrite((*ppPage)->pDbPage);
4342343727
if( rc!=SQLITE_OK ){
4342443728
releasePage(*ppPage);
4342543729
}
@@ -43605,11 +43909,11 @@
4360543909
nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
4360643910
assert( ovflPgno==0 || nOvfl>0 );
4360743911
while( nOvfl-- ){
4360843912
Pgno iNext = 0;
4360943913
MemPage *pOvfl = 0;
43610
- if( ovflPgno<2 || ovflPgno>pagerPagecount(pBt) ){
43914
+ if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
4361143915
/* 0 is not a legal page number and page 1 cannot be an
4361243916
** overflow page. Therefore if ovflPgno<2 or past the end of the
4361343917
** file the database must be corrupt. */
4361443918
return SQLITE_CORRUPT_BKPT;
4361543919
}
@@ -45437,12 +45741,18 @@
4543745741
ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
4543845742
if( rc ){
4543945743
releasePage(pRoot);
4544045744
return rc;
4544145745
}
45746
+
45747
+ /* When the new root page was allocated, page 1 was made writable in
45748
+ ** order either to increase the database filesize, or to decrement the
45749
+ ** freelist count. Hence, the sqlite3BtreeUpdateMeta() call cannot fail.
45750
+ */
45751
+ assert( sqlite3PagerIswriteable(pBt->pPage1->pDbPage) );
4544245752
rc = sqlite3BtreeUpdateMeta(p, 4, pgnoRoot);
45443
- if( rc ){
45753
+ if( NEVER(rc) ){
4544445754
releasePage(pRoot);
4544545755
return rc;
4544645756
}
4544745757
4544845758
}else{
@@ -45478,11 +45788,11 @@
4547845788
int rc;
4547945789
unsigned char *pCell;
4548045790
int i;
4548145791
4548245792
assert( sqlite3_mutex_held(pBt->mutex) );
45483
- if( pgno>pagerPagecount(pBt) ){
45793
+ if( pgno>btreePagecount(pBt) ){
4548445794
return SQLITE_CORRUPT_BKPT;
4548545795
}
4548645796
4548745797
rc = getAndInitPage(pBt, pgno, &pPage);
4548845798
if( rc ) return rc;
@@ -46229,11 +46539,11 @@
4622946539
sqlite3BtreeEnter(p);
4623046540
assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
4623146541
nRef = sqlite3PagerRefcount(pBt->pPager);
4623246542
sCheck.pBt = pBt;
4623346543
sCheck.pPager = pBt->pPager;
46234
- sCheck.nPage = pagerPagecount(sCheck.pBt);
46544
+ sCheck.nPage = btreePagecount(sCheck.pBt);
4623546545
sCheck.mxErr = mxErr;
4623646546
sCheck.nErr = 0;
4623746547
sCheck.mallocFailed = 0;
4623846548
*pnErr = 0;
4623946549
if( sCheck.nPage==0 ){
@@ -46831,13 +47141,12 @@
4683147141
}
4683247142
4683347143
/* Now that there is a read-lock on the source database, query the
4683447144
** source pager for the number of pages in the database.
4683547145
*/
46836
- if( rc==SQLITE_OK ){
46837
- rc = sqlite3PagerPagecount(pSrcPager, &nSrcPage);
46838
- }
47146
+ nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc);
47147
+ assert( nSrcPage>=0 );
4683947148
for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
4684047149
const Pgno iSrcPg = p->iNext; /* Source page number */
4684147150
if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
4684247151
DbPage *pSrcPg; /* Source page object */
4684347152
rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
@@ -48986,11 +49295,11 @@
4898649295
nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
4898749296
pKeyInfo = sqlite3Malloc( nByte );
4898849297
pOp->p4.pKeyInfo = pKeyInfo;
4898949298
if( pKeyInfo ){
4899049299
u8 *aSortOrder;
48991
- memcpy(pKeyInfo, zP4, nByte);
49300
+ memcpy((char*)pKeyInfo, zP4, nByte - nField);
4899249301
aSortOrder = pKeyInfo->aSortOrder;
4899349302
if( aSortOrder ){
4899449303
pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
4899549304
memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
4899649305
}
@@ -53812,18 +54121,13 @@
5381254121
int i;
5381354122
sqlite_int64 rowid;
5381454123
Mem **apArg;
5381554124
Mem *pX;
5381654125
} ck;
53817
- struct OP_Pagecount_stack_vars {
53818
- int p1;
53819
- int nPage;
53820
- Pager *pPager;
53821
- } cl;
5382254126
struct OP_Trace_stack_vars {
5382354127
char *zTrace;
53824
- } cm;
54128
+ } cl;
5382554129
} u;
5382654130
/* End automatically generated code
5382754131
********************************************************************/
5382854132
5382954133
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
@@ -54646,11 +54950,11 @@
5464654950
assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ag.n );
5464754951
u.ag.pArg = &aMem[pOp->p2];
5464854952
for(u.ag.i=0; u.ag.i<u.ag.n; u.ag.i++, u.ag.pArg++){
5464954953
u.ag.apVal[u.ag.i] = u.ag.pArg;
5465054954
sqlite3VdbeMemStoreType(u.ag.pArg);
54651
- REGISTER_TRACE(pOp->p2, u.ag.pArg);
54955
+ REGISTER_TRACE(pOp->p2+u.ag.i, u.ag.pArg);
5465254956
}
5465354957
5465454958
assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
5465554959
if( pOp->p4type==P4_FUNCDEF ){
5465654960
u.ag.ctx.pFunc = pOp->p4.pFunc;
@@ -56363,14 +56667,14 @@
5636356667
5636456668
/* Opcode: OpenEphemeral P1 P2 * P4 *
5636556669
**
5636656670
** Open a new cursor P1 to a transient table.
5636756671
** The cursor is always opened read/write even if
56368
-** the main database is read-only. The transient or virtual
56672
+** the main database is read-only. The ephemeral
5636956673
** table is deleted automatically when the cursor is closed.
5637056674
**
56371
-** P2 is the number of columns in the virtual table.
56675
+** P2 is the number of columns in the ephemeral table.
5637256676
** The cursor points to a BTree table if P4==0 and to a BTree index
5637356677
** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
5637456678
** that defines the format of keys in the index.
5637556679
**
5637656680
** This opcode was once called OpenTemp. But that created
@@ -56377,10 +56681,18 @@
5637756681
** confusion because the term "temp table", might refer either
5637856682
** to a TEMP table at the SQL level, or to a table opened by
5637956683
** this opcode. Then this opcode was call OpenVirtual. But
5638056684
** that created confusion with the whole virtual-table idea.
5638156685
*/
56686
+/* Opcode: OpenAutoindex P1 P2 * P4 *
56687
+**
56688
+** This opcode works the same as OP_OpenEphemeral. It has a
56689
+** different name to distinguish its use. Tables created using
56690
+** by this opcode will be used for automatically created transient
56691
+** indices in joins.
56692
+*/
56693
+case OP_OpenAutoindex:
5638256694
case OP_OpenEphemeral: {
5638356695
#if 0 /* local variables moved into u.ax */
5638456696
VdbeCursor *pCx;
5638556697
#endif /* local variables moved into u.ax */
5638656698
static const int openFlags =
@@ -57515,29 +57827,35 @@
5751557827
pc = pOp->p2 - 1;
5751657828
}
5751757829
break;
5751857830
}
5751957831
57520
-/* Opcode: Next P1 P2 * * *
57832
+/* Opcode: Next P1 P2 * * P5
5752157833
**
5752257834
** Advance cursor P1 so that it points to the next key/data pair in its
5752357835
** table or index. If there are no more key/value pairs then fall through
5752457836
** to the following instruction. But if the cursor advance was successful,
5752557837
** jump immediately to P2.
5752657838
**
5752757839
** The P1 cursor must be for a real table, not a pseudo-table.
5752857840
**
57841
+** If P5 is positive and the jump is taken, then event counter
57842
+** number P5-1 in the prepared statement is incremented.
57843
+**
5752957844
** See also: Prev
5753057845
*/
57531
-/* Opcode: Prev P1 P2 * * *
57846
+/* Opcode: Prev P1 P2 * * P5
5753257847
**
5753357848
** Back up cursor P1 so that it points to the previous key/data pair in its
5753457849
** table or index. If there is no previous key/value pairs then fall through
5753557850
** to the following instruction. But if the cursor backup was successful,
5753657851
** jump immediately to P2.
5753757852
**
5753857853
** The P1 cursor must be for a real table, not a pseudo-table.
57854
+**
57855
+** If P5 is positive and the jump is taken, then event counter
57856
+** number P5-1 in the prepared statement is incremented.
5753957857
*/
5754057858
case OP_Prev: /* jump */
5754157859
case OP_Next: { /* jump */
5754257860
#if 0 /* local variables moved into u.bm */
5754357861
VdbeCursor *pC;
@@ -57545,10 +57863,11 @@
5754557863
int res;
5754657864
#endif /* local variables moved into u.bm */
5754757865
5754857866
CHECK_FOR_INTERRUPT;
5754957867
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
57868
+ assert( pOp->p5<=ArraySize(p->aCounter) );
5755057869
u.bm.pC = p->apCsr[pOp->p1];
5755157870
if( u.bm.pC==0 ){
5755257871
break; /* See ticket #2273 */
5755357872
}
5755457873
u.bm.pCrsr = u.bm.pC->pCursor;
@@ -58991,25 +59310,11 @@
5899159310
/* Opcode: Pagecount P1 P2 * * *
5899259311
**
5899359312
** Write the current number of pages in database P1 to memory cell P2.
5899459313
*/
5899559314
case OP_Pagecount: { /* out2-prerelease */
58996
-#if 0 /* local variables moved into u.cl */
58997
- int p1;
58998
- int nPage;
58999
- Pager *pPager;
59000
-#endif /* local variables moved into u.cl */
59001
-
59002
- u.cl.p1 = pOp->p1;
59003
- u.cl.pPager = sqlite3BtreePager(db->aDb[u.cl.p1].pBt);
59004
- rc = sqlite3PagerPagecount(u.cl.pPager, &u.cl.nPage);
59005
- /* OP_Pagecount is always called from within a read transaction. The
59006
- ** page count has already been successfully read and cached. So the
59007
- ** sqlite3PagerPagecount() call above cannot fail. */
59008
- if( ALWAYS(rc==SQLITE_OK) ){
59009
- pOut->u.i = u.cl.nPage;
59010
- }
59315
+ pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
5901159316
break;
5901259317
}
5901359318
#endif
5901459319
5901559320
#ifndef SQLITE_OMIT_TRACE
@@ -59017,24 +59322,24 @@
5901759322
**
5901859323
** If tracing is enabled (by the sqlite3_trace()) interface, then
5901959324
** the UTF-8 string contained in P4 is emitted on the trace callback.
5902059325
*/
5902159326
case OP_Trace: {
59022
-#if 0 /* local variables moved into u.cm */
59327
+#if 0 /* local variables moved into u.cl */
5902359328
char *zTrace;
59024
-#endif /* local variables moved into u.cm */
59329
+#endif /* local variables moved into u.cl */
5902559330
59026
- u.cm.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
59027
- if( u.cm.zTrace ){
59331
+ u.cl.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
59332
+ if( u.cl.zTrace ){
5902859333
if( db->xTrace ){
59029
- char *z = sqlite3VdbeExpandSql(p, u.cm.zTrace);
59334
+ char *z = sqlite3VdbeExpandSql(p, u.cl.zTrace);
5903059335
db->xTrace(db->pTraceArg, z);
5903159336
sqlite3DbFree(db, z);
5903259337
}
5903359338
#ifdef SQLITE_DEBUG
5903459339
if( (db->flags & SQLITE_SqlTrace)!=0 ){
59035
- sqlite3DebugPrintf("SQL-trace: %s\n", u.cm.zTrace);
59340
+ sqlite3DebugPrintf("SQL-trace: %s\n", u.cl.zTrace);
5903659341
}
5903759342
#endif /* SQLITE_DEBUG */
5903859343
}
5903959344
break;
5904059345
}
@@ -59973,15 +60278,14 @@
5997360278
** Syncing an in-memory journal is a no-op. And, in fact, this routine
5997460279
** is never called in a working implementation. This implementation
5997560280
** exists purely as a contingency, in case some malfunction in some other
5997660281
** part of SQLite causes Sync to be called by mistake.
5997760282
*/
59978
-static int memjrnlSync(sqlite3_file *NotUsed, int NotUsed2){ /*NO_TEST*/
59979
- UNUSED_PARAMETER2(NotUsed, NotUsed2); /*NO_TEST*/
59980
- assert( 0 ); /*NO_TEST*/
59981
- return SQLITE_OK; /*NO_TEST*/
59982
-} /*NO_TEST*/
60283
+static int memjrnlSync(sqlite3_file *NotUsed, int NotUsed2){
60284
+ UNUSED_PARAMETER2(NotUsed, NotUsed2);
60285
+ return SQLITE_OK;
60286
+}
5998360287
5998460288
/*
5998560289
** Query the size of the file in bytes.
5998660290
*/
5998760291
static int memjrnlFileSize(sqlite3_file *pJfd, sqlite_int64 *pSize){
@@ -60573,11 +60877,11 @@
6057360877
}
6057460878
}
6057560879
6057660880
/*
6057760881
** Allocate and return a pointer to an expression to load the column iCol
60578
-** from datasource iSrc datasource in SrcList pSrc.
60882
+** from datasource iSrc in SrcList pSrc.
6057960883
*/
6058060884
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
6058160885
Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
6058260886
if( p ){
6058360887
struct SrcList_item *pItem = &pSrc->a[iSrc];
@@ -60585,10 +60889,12 @@
6058560889
p->iTable = pItem->iCursor;
6058660890
if( p->pTab->iPKey==iCol ){
6058760891
p->iColumn = -1;
6058860892
}else{
6058960893
p->iColumn = (ynVar)iCol;
60894
+ testcase( iCol==BMS );
60895
+ testcase( iCol==BMS-1 );
6059060896
pItem->colUsed |= ((Bitmask)1)<<(iCol>=BMS ? BMS-1 : iCol);
6059160897
}
6059260898
ExprSetProperty(p, EP_Resolved);
6059360899
}
6059460900
return p;
@@ -66537,16 +66843,20 @@
6653766843
int n = sqlite3_column_bytes(pStmt, 2);
6653866844
if( n>24 ){
6653966845
n = 24;
6654066846
}
6654166847
pSample->nByte = (u8)n;
66542
- pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
66543
- if( pSample->u.z ){
66544
- memcpy(pSample->u.z, z, n);
66848
+ if( n < 1){
66849
+ pSample->u.z = 0;
6654566850
}else{
66546
- db->mallocFailed = 1;
66547
- break;
66851
+ pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
66852
+ if( pSample->u.z ){
66853
+ memcpy(pSample->u.z, z, n);
66854
+ }else{
66855
+ db->mallocFailed = 1;
66856
+ break;
66857
+ }
6654866858
}
6654966859
}
6655066860
}
6655166861
}
6655266862
}
@@ -75790,11 +76100,11 @@
7579076100
}else{
7579176101
for(j=0; j<pColumn->nId; j++){
7579276102
if( pColumn->a[j].idx==i ) break;
7579376103
}
7579476104
}
75795
- if( pColumn && j>=pColumn->nId ){
76105
+ if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) ){
7579676106
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1);
7579776107
}else if( useTempTable ){
7579876108
sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1);
7579976109
}else{
7580076110
assert( pSelect==0 ); /* Otherwise useTempTable is true */
@@ -78086,10 +78396,13 @@
7808678396
{ "count_changes", SQLITE_CountRows },
7808778397
{ "empty_result_callbacks", SQLITE_NullCallback },
7808878398
{ "legacy_file_format", SQLITE_LegacyFileFmt },
7808978399
{ "fullfsync", SQLITE_FullFSync },
7809078400
{ "reverse_unordered_selects", SQLITE_ReverseOrder },
78401
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
78402
+ { "automatic_index", SQLITE_AutoIndex },
78403
+#endif
7809178404
#ifdef SQLITE_DEBUG
7809278405
{ "sql_trace", SQLITE_SqlTrace },
7809378406
{ "vdbe_listing", SQLITE_VdbeListing },
7809478407
{ "vdbe_trace", SQLITE_VdbeTrace },
7809578408
#endif
@@ -79461,32 +79774,32 @@
7946179774
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
7946279775
** But because db->init.busy is set to 1, no VDBE code is generated
7946379776
** or executed. All the parser does is build the internal data
7946479777
** structures that describe the table, index, or view.
7946579778
*/
79466
- char *zErr;
7946779779
int rc;
79780
+ sqlite3_stmt *pStmt;
79781
+
7946879782
assert( db->init.busy );
7946979783
db->init.iDb = iDb;
7947079784
db->init.newTnum = atoi(argv[1]);
7947179785
db->init.orphanTrigger = 0;
79472
- rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
79786
+ rc = sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
7947379787
db->init.iDb = 0;
79474
- assert( rc!=SQLITE_OK || zErr==0 );
7947579788
if( SQLITE_OK!=rc ){
7947679789
if( db->init.orphanTrigger ){
7947779790
assert( iDb==1 );
7947879791
}else{
7947979792
pData->rc = rc;
7948079793
if( rc==SQLITE_NOMEM ){
7948179794
db->mallocFailed = 1;
7948279795
}else if( rc!=SQLITE_INTERRUPT && rc!=SQLITE_LOCKED ){
79483
- corruptSchema(pData, argv[0], zErr);
79796
+ corruptSchema(pData, argv[0], sqlite3_errmsg(db));
7948479797
}
7948579798
}
79486
- sqlite3DbFree(db, zErr);
7948779799
}
79800
+ sqlite3_finalize(pStmt);
7948879801
}else if( argv[0]==0 ){
7948979802
corruptSchema(pData, 0, 0);
7949079803
}else{
7949179804
/* If the SQL column is blank it means this is an index that
7949279805
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
@@ -79967,10 +80280,11 @@
7996780280
}
7996880281
7996980282
sqlite3VtabUnlockList(db);
7997080283
7997180284
pParse->db = db;
80285
+ pParse->nQueryLoop = (double)1;
7997280286
if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
7997380287
char *zSqlCopy;
7997480288
int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
7997580289
testcase( nBytes==mxLen );
7997680290
testcase( nBytes==mxLen+1 );
@@ -79988,10 +80302,11 @@
7998880302
pParse->zTail = &zSql[nBytes];
7998980303
}
7999080304
}else{
7999180305
sqlite3RunParser(pParse, zSql, &zErrMsg);
7999280306
}
80307
+ assert( 1==(int)pParse->nQueryLoop );
7999380308
7999480309
if( db->mallocFailed ){
7999580310
pParse->rc = SQLITE_NOMEM;
7999680311
}
7999780312
if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
@@ -82772,12 +83087,12 @@
8277283087
** (13) The subquery and outer query do not both use LIMIT
8277383088
**
8277483089
** (14) The subquery does not use OFFSET
8277583090
**
8277683091
** (15) The outer query is not part of a compound select or the
82777
-** subquery does not have both an ORDER BY and a LIMIT clause.
82778
-** (See ticket #2339)
83092
+** subquery does not have a LIMIT clause.
83093
+** (See ticket #2339 and ticket [02a8e81d44]).
8277983094
**
8278083095
** (16) The outer query is not an aggregate or the subquery does
8278183096
** not contain ORDER BY. (Ticket #2942) This used to not matter
8278283097
** until we introduced the group_concat() function.
8278383098
**
@@ -82856,11 +83171,11 @@
8285683171
** because they could be computed at compile-time. But when LIMIT and OFFSET
8285783172
** became arbitrary expressions, we were forced to add restrictions (13)
8285883173
** and (14). */
8285983174
if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
8286083175
if( pSub->pOffset ) return 0; /* Restriction (14) */
82861
- if( p->pRightmost && pSub->pLimit && pSub->pOrderBy ){
83176
+ if( p->pRightmost && pSub->pLimit ){
8286283177
return 0; /* Restriction (15) */
8286383178
}
8286483179
if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
8286583180
if( ((pSub->selFlags & SF_Distinct)!=0 || pSub->pLimit)
8286683181
&& (pSrc->nSrc>1 || isAgg) ){ /* Restrictions (4)(5)(8)(9) */
@@ -83744,10 +84059,22 @@
8374484059
if( addrNext ){
8374584060
sqlite3VdbeResolveLabel(v, addrNext);
8374684061
sqlite3ExprCacheClear(pParse);
8374784062
}
8374884063
}
84064
+
84065
+ /* Before populating the accumulator registers, clear the column cache.
84066
+ ** Otherwise, if any of the required column values are already present
84067
+ ** in registers, sqlite3ExprCode() may use OP_SCopy to copy the value
84068
+ ** to pC->iMem. But by the time the value is used, the original register
84069
+ ** may have been used, invalidating the underlying buffer holding the
84070
+ ** text or blob value. See ticket [883034dcb5].
84071
+ **
84072
+ ** Another solution would be to change the OP_SCopy used to copy cached
84073
+ ** values to an OP_Copy.
84074
+ */
84075
+ sqlite3ExprCacheClear(pParse);
8374984076
for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
8375084077
sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
8375184078
}
8375284079
pAggInfo->directMode = 0;
8375384080
sqlite3ExprCacheClear(pParse);
@@ -85557,10 +85884,11 @@
8555785884
pSubParse->db = db;
8555885885
pSubParse->pTriggerTab = pTab;
8555985886
pSubParse->pToplevel = pTop;
8556085887
pSubParse->zAuthContext = pTrigger->zName;
8556185888
pSubParse->eTriggerOp = pTrigger->op;
85889
+ pSubParse->nQueryLoop = pParse->nQueryLoop;
8556285890
8556385891
v = sqlite3GetVdbe(pSubParse);
8556485892
if( v ){
8556585893
VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
8556685894
pTrigger->zName, onErrorText(orconf),
@@ -87477,10 +87805,11 @@
8747787805
if( pParse==0 ){
8747887806
rc = SQLITE_NOMEM;
8747987807
}else{
8748087808
pParse->declareVtab = 1;
8748187809
pParse->db = db;
87810
+ pParse->nQueryLoop = 1;
8748287811
8748387812
if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
8748487813
&& pParse->pNewTable
8748587814
&& !db->mallocFailed
8748687815
&& !pParse->pNewTable->pSelect
@@ -87997,19 +88326,21 @@
8799788326
#define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */
8799888327
#define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
8799988328
#define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
8800088329
#define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
8800188330
#define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
88331
+#define WHERE_NOT_FULLSCAN 0x000f3000 /* Does not do a full table scan */
8800288332
#define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */
8800388333
#define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
8800488334
#define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
8800588335
#define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
8800688336
#define WHERE_ORDERBY 0x01000000 /* Output will appear in correct order */
8800788337
#define WHERE_REVERSE 0x02000000 /* Scan in reverse order */
8800888338
#define WHERE_UNIQUE 0x04000000 /* Selects no more than one row */
8800988339
#define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
8801088340
#define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
88341
+#define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
8801188342
8801288343
/*
8801388344
** Initialize a preallocated WhereClause structure.
8801488345
*/
8801588346
static void whereClauseInit(
@@ -89334,10 +89665,15 @@
8933489665
#ifndef SQLITE_OMIT_OR_OPTIMIZATION
8933589666
const int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
8933689667
const Bitmask maskSrc = getMask(pWC->pMaskSet, iCur); /* Bitmask for pSrc */
8933789668
WhereTerm * const pWCEnd = &pWC->a[pWC->nTerm]; /* End of pWC->a[] */
8933889669
WhereTerm *pTerm; /* A single term of the WHERE clause */
89670
+
89671
+ /* No OR-clause optimization allowed if the NOT INDEXED clause is used */
89672
+ if( pSrc->notIndexed ){
89673
+ return;
89674
+ }
8933989675
8934089676
/* Search the WHERE clause terms for a usable WO_OR term. */
8934189677
for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
8934289678
if( pTerm->eOperator==WO_OR
8934389679
&& ((pTerm->prereqAll & ~maskSrc) & notReady)==0
@@ -89377,12 +89713,13 @@
8937789713
}
8937889714
8937989715
/* If there is an ORDER BY clause, increase the scan cost to account
8938089716
** for the cost of the sort. */
8938189717
if( pOrderBy!=0 ){
89718
+ WHERETRACE(("... sorting increases OR cost %.9g to %.9g\n",
89719
+ rTotal, rTotal+nRow*estLog(nRow)));
8938289720
rTotal += nRow*estLog(nRow);
89383
- WHERETRACE(("... sorting increases OR cost to %.9g\n", rTotal));
8938489721
}
8938589722
8938689723
/* If the cost of scanning using this OR term for optimization is
8938789724
** less than the current cost stored in pCost, replace the contents
8938889725
** of pCost. */
@@ -89397,10 +89734,251 @@
8939789734
}
8939889735
}
8939989736
#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
8940089737
}
8940189738
89739
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89740
+/*
89741
+** Return TRUE if the WHERE clause term pTerm is of a form where it
89742
+** could be used with an index to access pSrc, assuming an appropriate
89743
+** index existed.
89744
+*/
89745
+static int termCanDriveIndex(
89746
+ WhereTerm *pTerm, /* WHERE clause term to check */
89747
+ struct SrcList_item *pSrc, /* Table we are trying to access */
89748
+ Bitmask notReady /* Tables in outer loops of the join */
89749
+){
89750
+ char aff;
89751
+ if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
89752
+ if( pTerm->eOperator!=WO_EQ ) return 0;
89753
+ if( (pTerm->prereqRight & notReady)!=0 ) return 0;
89754
+ aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;
89755
+ if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
89756
+ return 1;
89757
+}
89758
+#endif
89759
+
89760
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89761
+/*
89762
+** If the query plan for pSrc specified in pCost is a full table scan
89763
+** and indexing is allows (if there is no NOT INDEXED clause) and it
89764
+** possible to construct a transient index that would perform better
89765
+** than a full table scan even when the cost of constructing the index
89766
+** is taken into account, then alter the query plan to use the
89767
+** transient index.
89768
+*/
89769
+static void bestAutomaticIndex(
89770
+ Parse *pParse, /* The parsing context */
89771
+ WhereClause *pWC, /* The WHERE clause */
89772
+ struct SrcList_item *pSrc, /* The FROM clause term to search */
89773
+ Bitmask notReady, /* Mask of cursors that are not available */
89774
+ WhereCost *pCost /* Lowest cost query plan */
89775
+){
89776
+ double nTableRow; /* Rows in the input table */
89777
+ double logN; /* log(nTableRow) */
89778
+ double costTempIdx; /* per-query cost of the transient index */
89779
+ WhereTerm *pTerm; /* A single term of the WHERE clause */
89780
+ WhereTerm *pWCEnd; /* End of pWC->a[] */
89781
+ Table *pTable; /* Table tht might be indexed */
89782
+
89783
+ if( (pParse->db->flags & SQLITE_AutoIndex)==0 ){
89784
+ /* Automatic indices are disabled at run-time */
89785
+ return;
89786
+ }
89787
+ if( (pCost->plan.wsFlags & WHERE_NOT_FULLSCAN)!=0 ){
89788
+ /* We already have some kind of index in use for this query. */
89789
+ return;
89790
+ }
89791
+ if( pSrc->notIndexed ){
89792
+ /* The NOT INDEXED clause appears in the SQL. */
89793
+ return;
89794
+ }
89795
+
89796
+ assert( pParse->nQueryLoop >= (double)1 );
89797
+ pTable = pSrc->pTab;
89798
+ nTableRow = pTable->pIndex ? pTable->pIndex->aiRowEst[0] : 1000000;
89799
+ logN = estLog(nTableRow);
89800
+ costTempIdx = 2*logN*(nTableRow/pParse->nQueryLoop + 1);
89801
+ if( costTempIdx>=pCost->rCost ){
89802
+ /* The cost of creating the transient table would be greater than
89803
+ ** doing the full table scan */
89804
+ return;
89805
+ }
89806
+
89807
+ /* Search for any equality comparison term */
89808
+ pWCEnd = &pWC->a[pWC->nTerm];
89809
+ for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89810
+ if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89811
+ WHERETRACE(("auto-index reduces cost from %.2f to %.2f\n",
89812
+ pCost->rCost, costTempIdx));
89813
+ pCost->rCost = costTempIdx;
89814
+ pCost->nRow = logN + 1;
89815
+ pCost->plan.wsFlags = WHERE_TEMP_INDEX;
89816
+ pCost->used = pTerm->prereqRight;
89817
+ break;
89818
+ }
89819
+ }
89820
+}
89821
+#else
89822
+# define bestAutomaticIndex(A,B,C,D,E) /* no-op */
89823
+#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
89824
+
89825
+
89826
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89827
+/*
89828
+** Generate code to construct the Index object for an automatic index
89829
+** and to set up the WhereLevel object pLevel so that the code generator
89830
+** makes use of the automatic index.
89831
+*/
89832
+static void constructAutomaticIndex(
89833
+ Parse *pParse, /* The parsing context */
89834
+ WhereClause *pWC, /* The WHERE clause */
89835
+ struct SrcList_item *pSrc, /* The FROM clause term to get the next index */
89836
+ Bitmask notReady, /* Mask of cursors that are not available */
89837
+ WhereLevel *pLevel /* Write new index here */
89838
+){
89839
+ int nColumn; /* Number of columns in the constructed index */
89840
+ WhereTerm *pTerm; /* A single term of the WHERE clause */
89841
+ WhereTerm *pWCEnd; /* End of pWC->a[] */
89842
+ int nByte; /* Byte of memory needed for pIdx */
89843
+ Index *pIdx; /* Object describing the transient index */
89844
+ Vdbe *v; /* Prepared statement under construction */
89845
+ int regIsInit; /* Register set by initialization */
89846
+ int addrInit; /* Address of the initialization bypass jump */
89847
+ Table *pTable; /* The table being indexed */
89848
+ KeyInfo *pKeyinfo; /* Key information for the index */
89849
+ int addrTop; /* Top of the index fill loop */
89850
+ int regRecord; /* Register holding an index record */
89851
+ int n; /* Column counter */
89852
+ int i; /* Loop counter */
89853
+ int mxBitCol; /* Maximum column in pSrc->colUsed */
89854
+ CollSeq *pColl; /* Collating sequence to on a column */
89855
+ Bitmask idxCols; /* Bitmap of columns used for indexing */
89856
+ Bitmask extraCols; /* Bitmap of additional columns */
89857
+
89858
+ /* Generate code to skip over the creation and initialization of the
89859
+ ** transient index on 2nd and subsequent iterations of the loop. */
89860
+ v = pParse->pVdbe;
89861
+ assert( v!=0 );
89862
+ regIsInit = ++pParse->nMem;
89863
+ addrInit = sqlite3VdbeAddOp1(v, OP_If, regIsInit);
89864
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, regIsInit);
89865
+
89866
+ /* Count the number of columns that will be added to the index
89867
+ ** and used to match WHERE clause constraints */
89868
+ nColumn = 0;
89869
+ pTable = pSrc->pTab;
89870
+ pWCEnd = &pWC->a[pWC->nTerm];
89871
+ idxCols = 0;
89872
+ for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89873
+ if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89874
+ int iCol = pTerm->u.leftColumn;
89875
+ Bitmask cMask = iCol>=BMS ? ((Bitmask)1)<<(BMS-1) : ((Bitmask)1)<<iCol;
89876
+ testcase( iCol==BMS );
89877
+ testcase( iCol==BMS-1 );
89878
+ if( (idxCols & cMask)==0 ){
89879
+ nColumn++;
89880
+ idxCols |= cMask;
89881
+ }
89882
+ }
89883
+ }
89884
+ assert( nColumn>0 );
89885
+ pLevel->plan.nEq = nColumn;
89886
+
89887
+ /* Count the number of additional columns needed to create a
89888
+ ** covering index. A "covering index" is an index that contains all
89889
+ ** columns that are needed by the query. With a covering index, the
89890
+ ** original table never needs to be accessed. Automatic indices must
89891
+ ** be a covering index because the index will not be updated if the
89892
+ ** original table changes and the index and table cannot both be used
89893
+ ** if they go out of sync.
89894
+ */
89895
+ extraCols = pSrc->colUsed & (~idxCols | (((Bitmask)1)<<(BMS-1)));
89896
+ mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
89897
+ testcase( pTable->nCol==BMS-1 );
89898
+ testcase( pTable->nCol==BMS-2 );
89899
+ for(i=0; i<mxBitCol; i++){
89900
+ if( extraCols & (((Bitmask)1)<<i) ) nColumn++;
89901
+ }
89902
+ if( pSrc->colUsed & (((Bitmask)1)<<(BMS-1)) ){
89903
+ nColumn += pTable->nCol - BMS + 1;
89904
+ }
89905
+ pLevel->plan.wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WO_EQ;
89906
+
89907
+ /* Construct the Index object to describe this index */
89908
+ nByte = sizeof(Index);
89909
+ nByte += nColumn*sizeof(int); /* Index.aiColumn */
89910
+ nByte += nColumn*sizeof(char*); /* Index.azColl */
89911
+ nByte += nColumn; /* Index.aSortOrder */
89912
+ pIdx = sqlite3DbMallocZero(pParse->db, nByte);
89913
+ if( pIdx==0 ) return;
89914
+ pLevel->plan.u.pIdx = pIdx;
89915
+ pIdx->azColl = (char**)&pIdx[1];
89916
+ pIdx->aiColumn = (int*)&pIdx->azColl[nColumn];
89917
+ pIdx->aSortOrder = (u8*)&pIdx->aiColumn[nColumn];
89918
+ pIdx->zName = "auto-index";
89919
+ pIdx->nColumn = nColumn;
89920
+ pIdx->pTable = pTable;
89921
+ n = 0;
89922
+ idxCols = 0;
89923
+ for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89924
+ if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89925
+ int iCol = pTerm->u.leftColumn;
89926
+ Bitmask cMask = iCol>=BMS ? ((Bitmask)1)<<(BMS-1) : ((Bitmask)1)<<iCol;
89927
+ if( (idxCols & cMask)==0 ){
89928
+ Expr *pX = pTerm->pExpr;
89929
+ idxCols |= cMask;
89930
+ pIdx->aiColumn[n] = pTerm->u.leftColumn;
89931
+ pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
89932
+ pIdx->azColl[n] = pColl->zName;
89933
+ n++;
89934
+ }
89935
+ }
89936
+ }
89937
+ assert( n==pLevel->plan.nEq );
89938
+
89939
+ /* Add additional columns needed to make the automatic index into
89940
+ ** a covering index */
89941
+ for(i=0; i<mxBitCol; i++){
89942
+ if( extraCols & (((Bitmask)1)<<i) ){
89943
+ pIdx->aiColumn[n] = i;
89944
+ pIdx->azColl[n] = "BINARY";
89945
+ n++;
89946
+ }
89947
+ }
89948
+ if( pSrc->colUsed & (((Bitmask)1)<<(BMS-1)) ){
89949
+ for(i=BMS-1; i<pTable->nCol; i++){
89950
+ pIdx->aiColumn[n] = i;
89951
+ pIdx->azColl[n] = "BINARY";
89952
+ n++;
89953
+ }
89954
+ }
89955
+ assert( n==nColumn );
89956
+
89957
+ /* Create the automatic index */
89958
+ pKeyinfo = sqlite3IndexKeyinfo(pParse, pIdx);
89959
+ assert( pLevel->iIdxCur>=0 );
89960
+ sqlite3VdbeAddOp4(v, OP_OpenAutoindex, pLevel->iIdxCur, nColumn+1, 0,
89961
+ (char*)pKeyinfo, P4_KEYINFO_HANDOFF);
89962
+ VdbeComment((v, "for %s", pTable->zName));
89963
+
89964
+ /* Fill the automatic index with content */
89965
+ addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
89966
+ regRecord = sqlite3GetTempReg(pParse);
89967
+ sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 1);
89968
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
89969
+ sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
89970
+ sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
89971
+ sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
89972
+ sqlite3VdbeJumpHere(v, addrTop);
89973
+ sqlite3ReleaseTempReg(pParse, regRecord);
89974
+
89975
+ /* Jump here when skipping the initialization */
89976
+ sqlite3VdbeJumpHere(v, addrInit);
89977
+}
89978
+#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
89979
+
8940289980
#ifndef SQLITE_OMIT_VIRTUALTABLE
8940389981
/*
8940489982
** Allocate and populate an sqlite3_index_info structure. It is the
8940589983
** responsibility of the caller to eventually release the structure
8940689984
** by passing the pointer returned by this function to sqlite3_free().
@@ -89581,10 +90159,11 @@
8958190159
struct sqlite3_index_constraint *pIdxCons;
8958290160
struct sqlite3_index_constraint_usage *pUsage;
8958390161
WhereTerm *pTerm;
8958490162
int i, j;
8958590163
int nOrderBy;
90164
+ double rCost;
8958690165
8958790166
/* Make sure wsFlags is initialized to some sane value. Otherwise, if the
8958890167
** malloc in allocateIndexInfo() fails and this function returns leaving
8958990168
** wsFlags in an uninitialized state, the caller may behave unpredictably.
8959090169
*/
@@ -89666,22 +90245,31 @@
8966690245
for(i=0; i<pIdxInfo->nConstraint; i++){
8966790246
if( pUsage[i].argvIndex>0 ){
8966890247
pCost->used |= pWC->a[pIdxCons[i].iTermOffset].prereqRight;
8966990248
}
8967090249
}
90250
+
90251
+ /* If there is an ORDER BY clause, and the selected virtual table index
90252
+ ** does not satisfy it, increase the cost of the scan accordingly. This
90253
+ ** matches the processing for non-virtual tables in bestBtreeIndex().
90254
+ */
90255
+ rCost = pIdxInfo->estimatedCost;
90256
+ if( pOrderBy && pIdxInfo->orderByConsumed==0 ){
90257
+ rCost += estLog(rCost)*rCost;
90258
+ }
8967190259
8967290260
/* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
8967390261
** inital value of lowestCost in this loop. If it is, then the
8967490262
** (cost<lowestCost) test below will never be true.
8967590263
**
8967690264
** Use "(double)2" instead of "2.0" in case OMIT_FLOATING_POINT
8967790265
** is defined.
8967890266
*/
89679
- if( (SQLITE_BIG_DBL/((double)2))<pIdxInfo->estimatedCost ){
90267
+ if( (SQLITE_BIG_DBL/((double)2))<rCost ){
8968090268
pCost->rCost = (SQLITE_BIG_DBL/((double)2));
8968190269
}else{
89682
- pCost->rCost = pIdxInfo->estimatedCost;
90270
+ pCost->rCost = rCost;
8968390271
}
8968490272
pCost->plan.u.pVtabIdx = pIdxInfo;
8968590273
if( pIdxInfo->orderByConsumed ){
8968690274
pCost->plan.wsFlags |= WHERE_ORDERBY;
8968790275
}
@@ -90078,18 +90666,18 @@
9007890666
**
9007990667
** bInEst:
9008090668
** Set to true if there was at least one "x IN (SELECT ...)" term used
9008190669
** in determining the value of nInMul.
9008290670
**
90083
- ** nBound:
90671
+ ** estBound:
9008490672
** An estimate on the amount of the table that must be searched. A
9008590673
** value of 100 means the entire table is searched. Range constraints
9008690674
** might reduce this to a value less than 100 to indicate that only
9008790675
** a fraction of the table needs searching. In the absence of
9008890676
** sqlite_stat2 ANALYZE data, a single inequality reduces the search
9008990677
** space to 1/3rd its original size. So an x>? constraint reduces
90090
- ** nBound to 33. Two constraints (x>? AND x<?) reduce nBound to 11.
90678
+ ** estBound to 33. Two constraints (x>? AND x<?) reduce estBound to 11.
9009190679
**
9009290680
** bSort:
9009390681
** Boolean. True if there is an ORDER BY clause that will require an
9009490682
** external sort (i.e. scanning the index being evaluated will not
9009590683
** correctly order records).
@@ -90107,17 +90695,18 @@
9010790695
** SELECT a, b, c FROM tbl WHERE a = 1;
9010890696
*/
9010990697
int nEq;
9011090698
int bInEst = 0;
9011190699
int nInMul = 1;
90112
- int nBound = 100;
90700
+ int estBound = 100;
90701
+ int nBound = 0; /* Number of range constraints seen */
9011390702
int bSort = 0;
9011490703
int bLookup = 0;
90704
+ WhereTerm *pTerm; /* A single term of the WHERE clause */
9011590705
9011690706
/* Determine the values of nEq and nInMul */
9011790707
for(nEq=0; nEq<pProbe->nColumn; nEq++){
90118
- WhereTerm *pTerm; /* A single term of the WHERE clause */
9011990708
int j = pProbe->aiColumn[nEq];
9012090709
pTerm = findTerm(pWC, iCur, j, notReady, eqTermMask, pIdx);
9012190710
if( pTerm==0 ) break;
9012290711
wsFlags |= (WHERE_COLUMN_EQ|WHERE_ROWID_EQ);
9012390712
if( pTerm->eOperator & WO_IN ){
@@ -90133,22 +90722,24 @@
9013390722
wsFlags |= WHERE_COLUMN_NULL;
9013490723
}
9013590724
used |= pTerm->prereqRight;
9013690725
}
9013790726
90138
- /* Determine the value of nBound. */
90727
+ /* Determine the value of estBound. */
9013990728
if( nEq<pProbe->nColumn ){
9014090729
int j = pProbe->aiColumn[nEq];
9014190730
if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pIdx) ){
9014290731
WhereTerm *pTop = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pIdx);
9014390732
WhereTerm *pBtm = findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pIdx);
90144
- whereRangeScanEst(pParse, pProbe, nEq, pBtm, pTop, &nBound);
90733
+ whereRangeScanEst(pParse, pProbe, nEq, pBtm, pTop, &estBound);
9014590734
if( pTop ){
90735
+ nBound = 1;
9014690736
wsFlags |= WHERE_TOP_LIMIT;
9014790737
used |= pTop->prereqRight;
9014890738
}
9014990739
if( pBtm ){
90740
+ nBound++;
9015090741
wsFlags |= WHERE_BTM_LIMIT;
9015190742
used |= pBtm->prereqRight;
9015290743
}
9015390744
wsFlags |= (WHERE_COLUMN_RANGE|WHERE_ROWID_RANGE);
9015490745
}
@@ -90175,11 +90766,11 @@
9017590766
}
9017690767
}
9017790768
9017890769
/* If currently calculating the cost of using an index (not the IPK
9017990770
** index), determine if all required column data may be obtained without
90180
- ** seeking to entries in the main table (i.e. if the index is a covering
90771
+ ** using the main table (i.e. if the index is a covering
9018190772
** index for this query). If it is, set the WHERE_IDX_ONLY flag in
9018290773
** wsFlags. Otherwise, set the bLookup variable to true. */
9018390774
if( pIdx && wsFlags ){
9018490775
Bitmask m = pSrc->colUsed;
9018590776
int j;
@@ -90194,12 +90785,11 @@
9019490785
}else{
9019590786
bLookup = 1;
9019690787
}
9019790788
}
9019890789
90199
- /**** Begin adding up the cost of using this index (Needs improvements)
90200
- **
90790
+ /*
9020190791
** Estimate the number of rows of output. For an IN operator,
9020290792
** do not let the estimate exceed half the rows in the table.
9020390793
*/
9020490794
nRow = (double)(aiRowEst[nEq] * nInMul);
9020590795
if( bInEst && nRow*2>aiRowEst[0] ){
@@ -90214,12 +90804,12 @@
9021490804
cost = nRow + nInMul*estLog(aiRowEst[0]);
9021590805
9021690806
/* Adjust the number of rows and the cost downward to reflect rows
9021790807
** that are excluded by range constraints.
9021890808
*/
90219
- nRow = (nRow * (double)nBound) / (double)100;
90220
- cost = (cost * (double)nBound) / (double)100;
90809
+ nRow = (nRow * (double)estBound) / (double)100;
90810
+ cost = (cost * (double)estBound) / (double)100;
9022190811
9022290812
/* Add in the estimated cost of sorting the result
9022390813
*/
9022490814
if( bSort ){
9022590815
cost += cost*estLog(cost);
@@ -90231,22 +90821,80 @@
9023190821
*/
9023290822
if( pIdx && bLookup==0 ){
9023390823
cost /= (double)2;
9023490824
}
9023590825
/**** Cost of using this index has now been computed ****/
90826
+
90827
+ /* If there are additional constraints on this table that cannot
90828
+ ** be used with the current index, but which might lower the number
90829
+ ** of output rows, adjust the nRow value accordingly. This only
90830
+ ** matters if the current index is the least costly, so do not bother
90831
+ ** with this step if we already know this index will not be chosen.
90832
+ ** Also, never reduce the output row count below 2 using this step.
90833
+ **
90834
+ ** Do not reduce the output row count if pSrc is the only table that
90835
+ ** is notReady; if notReady is a power of two. This will be the case
90836
+ ** when the main sqlite3WhereBegin() loop is scanning for a table with
90837
+ ** and "optimal" index, and on such a scan the output row count
90838
+ ** reduction is not valid because it does not update the "pCost->used"
90839
+ ** bitmap. The notReady bitmap will also be a power of two when we
90840
+ ** are scanning for the last table in a 64-way join. We are willing
90841
+ ** to bypass this optimization in that corner case.
90842
+ */
90843
+ if( nRow>2 && cost<=pCost->rCost && (notReady & (notReady-1))!=0 ){
90844
+ int k; /* Loop counter */
90845
+ int nSkipEq = nEq; /* Number of == constraints to skip */
90846
+ int nSkipRange = nBound; /* Number of < constraints to skip */
90847
+ Bitmask thisTab; /* Bitmap for pSrc */
90848
+
90849
+ thisTab = getMask(pWC->pMaskSet, iCur);
90850
+ for(pTerm=pWC->a, k=pWC->nTerm; nRow>2 && k; k--, pTerm++){
90851
+ if( pTerm->wtFlags & TERM_VIRTUAL ) continue;
90852
+ if( (pTerm->prereqAll & notReady)!=thisTab ) continue;
90853
+ if( pTerm->eOperator & (WO_EQ|WO_IN|WO_ISNULL) ){
90854
+ if( nSkipEq ){
90855
+ /* Ignore the first nEq equality matches since the index
90856
+ ** has already accounted for these */
90857
+ nSkipEq--;
90858
+ }else{
90859
+ /* Assume each additional equality match reduces the result
90860
+ ** set size by a factor of 10 */
90861
+ nRow /= 10;
90862
+ }
90863
+ }else if( pTerm->eOperator & (WO_LT|WO_LE|WO_GT|WO_GE) ){
90864
+ if( nSkipRange ){
90865
+ /* Ignore the first nBound range constraints since the index
90866
+ ** has already accounted for these */
90867
+ nSkipRange--;
90868
+ }else{
90869
+ /* Assume each additional range constraint reduces the result
90870
+ ** set size by a factor of 3 */
90871
+ nRow /= 3;
90872
+ }
90873
+ }else{
90874
+ /* Any other expression lowers the output row count by half */
90875
+ nRow /= 2;
90876
+ }
90877
+ }
90878
+ if( nRow<2 ) nRow = 2;
90879
+ }
90880
+
9023690881
9023790882
WHERETRACE((
90238
- "tbl=%s idx=%s nEq=%d nInMul=%d nBound=%d bSort=%d bLookup=%d"
90239
- " wsFlags=%d (nRow=%.2f cost=%.2f)\n",
90883
+ "%s(%s): nEq=%d nInMul=%d estBound=%d bSort=%d bLookup=%d wsFlags=0x%x\n"
90884
+ " notReady=0x%llx nRow=%.2f cost=%.2f used=0x%llx\n",
9024090885
pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
90241
- nEq, nInMul, nBound, bSort, bLookup, wsFlags, nRow, cost
90886
+ nEq, nInMul, estBound, bSort, bLookup, wsFlags,
90887
+ notReady, nRow, cost, used
9024290888
));
9024390889
9024490890
/* If this index is the best we have seen so far, then record this
9024590891
** index and its cost in the pCost structure.
9024690892
*/
90247
- if( (!pIdx || wsFlags) && cost<pCost->rCost ){
90893
+ if( (!pIdx || wsFlags)
90894
+ && (cost<pCost->rCost || (cost<=pCost->rCost && nRow<pCost->nRow))
90895
+ ){
9024890896
pCost->rCost = cost;
9024990897
pCost->nRow = nRow;
9025090898
pCost->used = used;
9025190899
pCost->plan.wsFlags = (wsFlags&wsFlagMask);
9025290900
pCost->plan.nEq = nEq;
@@ -90277,14 +90925,16 @@
9027790925
|| pCost->plan.u.pIdx==0
9027890926
|| pCost->plan.u.pIdx==pSrc->pIndex
9027990927
);
9028090928
9028190929
WHERETRACE(("best index is: %s\n",
90282
- (pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
90930
+ ((pCost->plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ? "none" :
90931
+ pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
9028390932
));
9028490933
9028590934
bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
90935
+ bestAutomaticIndex(pParse, pWC, pSrc, notReady, pCost);
9028690936
pCost->plan.wsFlags |= eqTermMask;
9028790937
}
9028890938
9028990939
/*
9029090940
** Find the query plan for accessing table pSrc->pTab. Write the
@@ -90750,11 +91400,15 @@
9075091400
}
9075191401
start = sqlite3VdbeCurrentAddr(v);
9075291402
pLevel->op = bRev ? OP_Prev : OP_Next;
9075391403
pLevel->p1 = iCur;
9075491404
pLevel->p2 = start;
90755
- pLevel->p5 = (pStart==0 && pEnd==0) ?1:0;
91405
+ if( pStart==0 && pEnd==0 ){
91406
+ pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
91407
+ }else{
91408
+ assert( pLevel->p5==0 );
91409
+ }
9075691410
if( testOp!=OP_Noop ){
9075791411
iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
9075891412
sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
9075991413
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
9076091414
sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
@@ -91208,20 +91862,27 @@
9120891862
9120991863
/*
9121091864
** Free a WhereInfo structure
9121191865
*/
9121291866
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
91213
- if( pWInfo ){
91867
+ if( ALWAYS(pWInfo) ){
9121491868
int i;
9121591869
for(i=0; i<pWInfo->nLevel; i++){
9121691870
sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo;
9121791871
if( pInfo ){
9121891872
/* assert( pInfo->needToFreeIdxStr==0 || db->mallocFailed ); */
9121991873
if( pInfo->needToFreeIdxStr ){
9122091874
sqlite3_free(pInfo->idxStr);
9122191875
}
9122291876
sqlite3DbFree(db, pInfo);
91877
+ }
91878
+ if( pWInfo->a[i].plan.wsFlags & WHERE_TEMP_INDEX ){
91879
+ Index *pIdx = pWInfo->a[i].plan.u.pIdx;
91880
+ if( pIdx ){
91881
+ sqlite3DbFree(db, pIdx->zColAff);
91882
+ sqlite3DbFree(db, pIdx);
91883
+ }
9122391884
}
9122491885
}
9122591886
whereClauseClear(pWInfo->pWC);
9122691887
sqlite3DbFree(db, pWInfo);
9122791888
}
@@ -91338,10 +91999,11 @@
9133891999
sqlite3 *db; /* Database connection */
9133992000
9134092001
/* The number of tables in the FROM clause is limited by the number of
9134192002
** bits in a Bitmask
9134292003
*/
92004
+ testcase( pTabList->nSrc==BMS );
9134392005
if( pTabList->nSrc>BMS ){
9134492006
sqlite3ErrorMsg(pParse, "at most %d tables in a join", BMS);
9134592007
return 0;
9134692008
}
9134792009
@@ -91365,18 +92027,21 @@
9136592027
nByteWInfo +
9136692028
sizeof(WhereClause) +
9136792029
sizeof(WhereMaskSet)
9136892030
);
9136992031
if( db->mallocFailed ){
92032
+ sqlite3DbFree(db, pWInfo);
92033
+ pWInfo = 0;
9137092034
goto whereBeginError;
9137192035
}
9137292036
pWInfo->nLevel = nTabList;
9137392037
pWInfo->pParse = pParse;
9137492038
pWInfo->pTabList = pTabList;
9137592039
pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
9137692040
pWInfo->pWC = pWC = (WhereClause *)&((u8 *)pWInfo)[nByteWInfo];
9137792041
pWInfo->wctrlFlags = wctrlFlags;
92042
+ pWInfo->savedNQueryLoop = pParse->nQueryLoop;
9137892043
pMaskSet = (WhereMaskSet*)&pWC[1];
9137992044
9138092045
/* Split the WHERE clause into separate subexpressions where each
9138192046
** subexpression is separated by an AND operator.
9138292047
*/
@@ -91474,24 +92139,29 @@
9147492139
9147592140
memset(&bestPlan, 0, sizeof(bestPlan));
9147692141
bestPlan.rCost = SQLITE_BIG_DBL;
9147792142
9147892143
/* Loop through the remaining entries in the FROM clause to find the
91479
- ** next nested loop. The FROM clause entries may be iterated through
92144
+ ** next nested loop. The loop tests all FROM clause entries
9148092145
** either once or twice.
9148192146
**
91482
- ** The first iteration, which is always performed, searches for the
91483
- ** FROM clause entry that permits the lowest-cost, "optimal" scan. In
92147
+ ** The first test is always performed if there are two or more entries
92148
+ ** remaining and never performed if there is only one FROM clause entry
92149
+ ** to choose from. The first test looks for an "optimal" scan. In
9148492150
** this context an optimal scan is one that uses the same strategy
9148592151
** for the given FROM clause entry as would be selected if the entry
9148692152
** were used as the innermost nested loop. In other words, a table
9148792153
** is chosen such that the cost of running that table cannot be reduced
91488
- ** by waiting for other tables to run first.
92154
+ ** by waiting for other tables to run first. This "optimal" test works
92155
+ ** by first assuming that the FROM clause is on the inner loop and finding
92156
+ ** its query plan, then checking to see if that query plan uses any
92157
+ ** other FROM clause terms that are notReady. If no notReady terms are
92158
+ ** used then the "optimal" query plan works.
9148992159
**
91490
- ** The second iteration is only performed if no optimal scan strategies
91491
- ** were found by the first. This iteration is used to search for the
91492
- ** lowest cost scan overall.
92160
+ ** The second loop iteration is only performed if no optimal scan
92161
+ ** strategies were found by the first loop. This 2nd iteration is used to
92162
+ ** search for the lowest cost scan overall.
9149392163
**
9149492164
** Previous versions of SQLite performed only the second iteration -
9149592165
** the next outermost loop was always that with the lowest overall
9149692166
** cost. However, this meant that SQLite could select the wrong plan
9149792167
** for scripts such as the following:
@@ -91505,13 +92175,12 @@
9150592175
** However, since the cost of a linear scan through table t2 is the same
9150692176
** as the cost of a linear scan through table t1, a simple greedy
9150792177
** algorithm may choose to use t2 for the outer loop, which is a much
9150892178
** costlier approach.
9150992179
*/
91510
- for(isOptimal=1; isOptimal>=0 && bestJ<0; isOptimal--){
91511
- Bitmask mask = (isOptimal ? 0 : notReady);
91512
- assert( (nTabList-iFrom)>1 || isOptimal );
92180
+ for(isOptimal=(iFrom<nTabList-1); isOptimal>=0; isOptimal--){
92181
+ Bitmask mask; /* Mask of tables not yet ready */
9151392182
for(j=iFrom, pTabItem=&pTabList->a[j]; j<nTabList; j++, pTabItem++){
9151492183
int doNotReorder; /* True if this table should not be reordered */
9151592184
WhereCost sCost; /* Cost information from best[Virtual]Index() */
9151692185
ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
9151792186
@@ -91520,10 +92189,11 @@
9152092189
m = getMask(pMaskSet, pTabItem->iCursor);
9152192190
if( (m & notReady)==0 ){
9152292191
if( j==iFrom ) iFrom++;
9152392192
continue;
9152492193
}
92194
+ mask = (isOptimal ? m : notReady);
9152592195
pOrderBy = ((i==0 && ppOrderBy )?*ppOrderBy:0);
9152692196
9152792197
assert( pTabItem->pTab );
9152892198
#ifndef SQLITE_OMIT_VIRTUALTABLE
9152992199
if( IsVirtual(pTabItem->pTab) ){
@@ -91535,12 +92205,15 @@
9153592205
bestBtreeIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost);
9153692206
}
9153792207
assert( isOptimal || (sCost.used&notReady)==0 );
9153892208
9153992209
if( (sCost.used&notReady)==0
91540
- && (j==iFrom || sCost.rCost<bestPlan.rCost)
92210
+ && (bestJ<0 || sCost.rCost<bestPlan.rCost
92211
+ || (sCost.rCost<=bestPlan.rCost && sCost.nRow<bestPlan.nRow))
9154192212
){
92213
+ WHERETRACE(("... best so far with cost=%g and nRow=%g\n",
92214
+ sCost.rCost, sCost.nRow));
9154292215
bestPlan = sCost;
9154392216
bestJ = j;
9154492217
}
9154592218
if( doNotReorder ) break;
9154692219
}
@@ -91552,17 +92225,20 @@
9155292225
if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
9155392226
*ppOrderBy = 0;
9155492227
}
9155592228
andFlags &= bestPlan.plan.wsFlags;
9155692229
pLevel->plan = bestPlan.plan;
91557
- if( bestPlan.plan.wsFlags & WHERE_INDEXED ){
92230
+ testcase( bestPlan.plan.wsFlags & WHERE_INDEXED );
92231
+ testcase( bestPlan.plan.wsFlags & WHERE_TEMP_INDEX );
92232
+ if( bestPlan.plan.wsFlags & (WHERE_INDEXED|WHERE_TEMP_INDEX) ){
9155892233
pLevel->iIdxCur = pParse->nTab++;
9155992234
}else{
9156092235
pLevel->iIdxCur = -1;
9156192236
}
9156292237
notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
9156392238
pLevel->iFrom = (u8)bestJ;
92239
+ if( bestPlan.nRow>=(double)1 ) pParse->nQueryLoop *= bestPlan.nRow;
9156492240
9156592241
/* Check that if the table scanned by this loop iteration had an
9156692242
** INDEXED BY clause attached to it, that the named index is being
9156792243
** used for the scan. If not, then query compilation has failed.
9156892244
** Return an error.
@@ -91605,10 +92281,11 @@
9160592281
9160692282
/* Open all tables in the pTabList and any indices selected for
9160792283
** searching those tables.
9160892284
*/
9160992285
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
92286
+ notReady = ~(Bitmask)0;
9161092287
for(i=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
9161192288
Table *pTab; /* Table to open */
9161292289
int iDb; /* Index of database containing table/index */
9161392290
9161492291
#ifndef SQLITE_OMIT_EXPLAIN
@@ -91617,11 +92294,13 @@
9161792294
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
9161892295
zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName);
9161992296
if( pItem->zAlias ){
9162092297
zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
9162192298
}
91622
- if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
92299
+ if( (pLevel->plan.wsFlags & WHERE_TEMP_INDEX)!=0 ){
92300
+ zMsg = sqlite3MAppendf(db, zMsg, "%s WITH AUTOMATIC INDEX", zMsg);
92301
+ }else if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
9162392302
zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s",
9162492303
zMsg, pLevel->plan.u.pIdx->zName);
9162592304
}else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
9162692305
zMsg = sqlite3MAppendf(db, zMsg, "%s VIA MULTI-INDEX UNION", zMsg);
9162792306
}else if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
@@ -91640,12 +92319,15 @@
9164092319
sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC);
9164192320
}
9164292321
#endif /* SQLITE_OMIT_EXPLAIN */
9164392322
pTabItem = &pTabList->a[pLevel->iFrom];
9164492323
pTab = pTabItem->pTab;
92324
+ pLevel->iTabCur = pTabItem->iCursor;
9164592325
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
91646
- if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
92326
+ if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){
92327
+ /* Do nothing */
92328
+ }else
9164792329
#ifndef SQLITE_OMIT_VIRTUALTABLE
9164892330
if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
9164992331
const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
9165092332
int iCur = pTabItem->iCursor;
9165192333
sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
@@ -91653,10 +92335,12 @@
9165392335
#endif
9165492336
if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0
9165592337
&& (wctrlFlags & WHERE_OMIT_OPEN)==0 ){
9165692338
int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
9165792339
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
92340
+ testcase( pTab->nCol==BMS-1 );
92341
+ testcase( pTab->nCol==BMS );
9165892342
if( !pWInfo->okOnePass && pTab->nCol<BMS ){
9165992343
Bitmask b = pTabItem->colUsed;
9166092344
int n = 0;
9166192345
for(; b; b=b>>1, n++){}
9166292346
sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1,
@@ -91664,11 +92348,15 @@
9166492348
assert( n<=pTab->nCol );
9166592349
}
9166692350
}else{
9166792351
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
9166892352
}
91669
- pLevel->iTabCur = pTabItem->iCursor;
92353
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
92354
+ if( (pLevel->plan.wsFlags & WHERE_TEMP_INDEX)!=0 ){
92355
+ constructAutomaticIndex(pParse, pWC, pTabItem, notReady, pLevel);
92356
+ }else
92357
+#endif
9167092358
if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
9167192359
Index *pIx = pLevel->plan.u.pIdx;
9167292360
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
9167392361
int iIdxCur = pLevel->iIdxCur;
9167492362
assert( pIx->pSchema==pTab->pSchema );
@@ -91676,12 +92364,14 @@
9167692364
sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIx->tnum, iDb,
9167792365
(char*)pKey, P4_KEYINFO_HANDOFF);
9167892366
VdbeComment((v, "%s", pIx->zName));
9167992367
}
9168092368
sqlite3CodeVerifySchema(pParse, iDb);
92369
+ notReady &= ~getMask(pWC->pMaskSet, pTabItem->iCursor);
9168192370
}
9168292371
pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
92372
+ if( db->mallocFailed ) goto whereBeginError;
9168392373
9168492374
/* Generate the code to do the search. Each iteration of the for
9168592375
** loop below generates code for a single nested loop of the VM
9168692376
** program.
9168792377
*/
@@ -91745,11 +92435,14 @@
9174592435
*/
9174692436
return pWInfo;
9174792437
9174892438
/* Jump here if malloc fails */
9174992439
whereBeginError:
91750
- whereInfoFree(db, pWInfo);
92440
+ if( pWInfo ){
92441
+ pParse->nQueryLoop = pWInfo->savedNQueryLoop;
92442
+ whereInfoFree(db, pWInfo);
92443
+ }
9175192444
return 0;
9175292445
}
9175392446
9175492447
/*
9175592448
** Generate the end of the WHERE loop. See comments on
@@ -91815,16 +92508,19 @@
9181592508
assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
9181692509
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
9181792510
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
9181892511
Table *pTab = pTabItem->pTab;
9181992512
assert( pTab!=0 );
91820
- if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
91821
- if( (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0 ){
91822
- if( !pWInfo->okOnePass && (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 ){
92513
+ if( (pTab->tabFlags & TF_Ephemeral)==0
92514
+ && pTab->pSelect==0
92515
+ && (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0
92516
+ ){
92517
+ int ws = pLevel->plan.wsFlags;
92518
+ if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
9182392519
sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
9182492520
}
91825
- if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
92521
+ if( (ws & WHERE_INDEXED)!=0 && (ws & WHERE_TEMP_INDEX)==0 ){
9182692522
sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
9182792523
}
9182892524
}
9182992525
9183092526
/* If this scan uses an index, make code substitutions to read data
@@ -91868,10 +92564,11 @@
9186892564
}
9186992565
}
9187092566
9187192567
/* Final cleanup
9187292568
*/
92569
+ pParse->nQueryLoop = pWInfo->savedNQueryLoop;
9187392570
whereInfoFree(db, pWInfo);
9187492571
return;
9187592572
}
9187692573
9187792574
/************** End of where.c ***********************************************/
@@ -98071,11 +98768,11 @@
9807198768
assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
9807298769
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
9807398770
db->autoCommit = 1;
9807498771
db->nextAutovac = -1;
9807598772
db->nextPagesize = 0;
98076
- db->flags |= SQLITE_ShortColNames
98773
+ db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex
9807798774
#if SQLITE_DEFAULT_FILE_FORMAT<4
9807898775
| SQLITE_LegacyFileFmt
9807998776
#endif
9808098777
#ifdef SQLITE_ENABLE_LOAD_EXTENSION
9808198778
| SQLITE_LoadExtension
@@ -99199,11 +99896,11 @@
9919999896
** and so on.
9920099897
**
9920199898
** This is similar in concept to how sqlite encodes "varints" but
9920299899
** the encoding is not the same. SQLite varints are big-endian
9920399900
** are are limited to 9 bytes in length whereas FTS3 varints are
99204
-** little-endian and can be upt to 10 bytes in length (in theory).
99901
+** little-endian and can be up to 10 bytes in length (in theory).
9920599902
**
9920699903
** Example encodings:
9920799904
**
9920899905
** 1: 0x01
9920999906
** 127: 0x7f
@@ -99210,30 +99907,30 @@
9921099907
** 128: 0x81 0x00
9921199908
**
9921299909
**
9921399910
**** Document lists ****
9921499911
** A doclist (document list) holds a docid-sorted list of hits for a
99215
-** given term. Doclists hold docids, and can optionally associate
99216
-** token positions and offsets with docids. A position is the index
99217
-** of a word within the document. The first word of the document has
99218
-** a position of 0.
99912
+** given term. Doclists hold docids and associated token positions.
99913
+** A docid is the unique integer identifier for a single document.
99914
+** A position is the index of a word within the document. The first
99915
+** word of the document has a position of 0.
9921999916
**
9922099917
** FTS3 used to optionally store character offsets using a compile-time
9922199918
** option. But that functionality is no longer supported.
9922299919
**
99223
-** A DL_POSITIONS_OFFSETS doclist is stored like this:
99920
+** A doclist is stored like this:
9922499921
**
9922599922
** array {
9922699923
** varint docid;
9922799924
** array { (position list for column 0)
99228
-** varint position; (delta from previous position plus POS_BASE)
99925
+** varint position; (2 more than the delta from previous position)
9922999926
** }
9923099927
** array {
9923199928
** varint POS_COLUMN; (marks start of position list for new column)
9923299929
** varint column; (index of new column)
9923399930
** array {
99234
-** varint position; (delta from previous position plus POS_BASE)
99931
+** varint position; (2 more than the delta from previous position)
9923599932
** }
9923699933
** }
9923799934
** varint POS_END; (marks end of positions for this document.
9923899935
** }
9923999936
**
@@ -99241,11 +99938,11 @@
9924199938
** memory. A "position" is an index of a token in the token stream
9924299939
** generated by the tokenizer. Note that POS_END and POS_COLUMN occur
9924399940
** in the same logical place as the position element, and act as sentinals
9924499941
** ending a position list array. POS_END is 0. POS_COLUMN is 1.
9924599942
** The positions numbers are not stored literally but rather as two more
99246
-** the difference from the prior position, or the just the position plus
99943
+** than the difference from the prior position, or the just the position plus
9924799944
** 2 for the first position. Example:
9924899945
**
9924999946
** label: A B C D E F G H I J K
9925099947
** value: 123 5 9 1 1 14 35 0 234 72 0
9925199948
**
@@ -99255,18 +99952,18 @@
9925599952
** new column is column number 1. There are two positions at 12 and 45
9925699953
** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
9925799954
** 234 at I is the next docid. It has one position 72 (72-2) and then
9925899955
** terminates with the 0 at K.
9925999956
**
99260
-** A DL_POSITIONS doclist omits the startOffset and endOffset
99261
-** information. A DL_DOCIDS doclist omits both the position and
99262
-** offset information, becoming an array of varint-encoded docids.
99263
-**
99264
-** On-disk data is stored as type DL_DEFAULT, so we don't serialize
99265
-** the type. Due to how deletion is implemented in the segmentation
99266
-** system, on-disk doclists MUST store at least positions.
99267
-**
99957
+** A "position-list" is the list of positions for multiple columns for
99958
+** a single docid. A "column-list" is the set of positions for a single
99959
+** column. Hence, a position-list consists of one or more column-lists,
99960
+** a document record consists of a docid followed by a position-list and
99961
+** a doclist consists of one or more document records.
99962
+**
99963
+** A bare doclist omits the position information, becoming an
99964
+** array of varint-encoded docids.
9926899965
**
9926999966
**** Segment leaf nodes ****
9927099967
** Segment leaf nodes store terms and doclists, ordered by term. Leaf
9927199968
** nodes are written using LeafWriter, and read using LeafReader (to
9927299969
** iterate through a single leaf node's data) and LeavesReader (to
@@ -99776,10 +100473,24 @@
99776100473
** Maximum length of a varint encoded integer. The varint format is different
99777100474
** from that used by SQLite, so the maximum length is 10, not 9.
99778100475
*/
99779100476
#define FTS3_VARINT_MAX 10
99780100477
100478
+/*
100479
+** The testcase() macro is only used by the amalgamation. If undefined,
100480
+** make it a no-op.
100481
+*/
100482
+#ifndef testcase
100483
+# define testcase(X)
100484
+#endif
100485
+
100486
+/*
100487
+** Terminator values for position-lists and column-lists.
100488
+*/
100489
+#define POS_COLUMN (1) /* Column-list terminator */
100490
+#define POS_END (0) /* Position-list terminator */
100491
+
99781100492
/*
99782100493
** This section provides definitions to allow the
99783100494
** FTS3 extension to be compiled outside of the
99784100495
** amalgamation.
99785100496
*/
@@ -100087,12 +100798,11 @@
100087100798
*pi = (int) i;
100088100799
return ret;
100089100800
}
100090100801
100091100802
/*
100092
-** Return the number of bytes required to store the value passed as the
100093
-** first argument in varint form.
100803
+** Return the number of bytes required to encode v as a varint
100094100804
*/
100095100805
SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64 v){
100096100806
int i = 0;
100097100807
do{
100098100808
i++;
@@ -100139,11 +100849,11 @@
100139100849
}
100140100850
}
100141100851
100142100852
/*
100143100853
** Read a single varint from the doclist at *pp and advance *pp to point
100144
-** to the next element of the varlist. Add the value of the varint
100854
+** to the first byte past the end of the varint. Add the value of the varint
100145100855
** to *pVal.
100146100856
*/
100147100857
static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){
100148100858
sqlite3_int64 iVal;
100149100859
*pp += sqlite3Fts3GetVarint(*pp, &iVal);
@@ -100195,11 +100905,11 @@
100195100905
** and then evaluate those statements. The success code is writting
100196100906
** into *pRc.
100197100907
**
100198100908
** If *pRc is initially non-zero then this routine is a no-op.
100199100909
*/
100200
-void fts3DbExec(
100910
+static void fts3DbExec(
100201100911
int *pRc, /* Success code */
100202100912
sqlite3 *db, /* Database in which to run SQL */
100203100913
const char *zFormat, /* Format string for SQL */
100204100914
... /* Arguments to the format string */
100205100915
){
@@ -100275,10 +100985,14 @@
100275100985
100276100986
/*
100277100987
** Create the backing store tables (%_content, %_segments and %_segdir)
100278100988
** required by the FTS3 table passed as the only argument. This is done
100279100989
** as part of the vtab xCreate() method.
100990
+**
100991
+** If the p->bHasDocsize boolean is true (indicating that this is an
100992
+** FTS4 table, not an FTS3 table) then also create the %_docsize and
100993
+** %_stat tables required by FTS4.
100280100994
*/
100281100995
static int fts3CreateTables(Fts3Table *p){
100282100996
int rc = SQLITE_OK; /* Return code */
100283100997
int i; /* Iterator variable */
100284100998
char *zContentCols; /* Columns of %_content table */
@@ -100367,11 +101081,11 @@
100367101081
** This function is the implementation of both the xConnect and xCreate
100368101082
** methods of the FTS3 virtual table.
100369101083
**
100370101084
** The argv[] array contains the following:
100371101085
**
100372
-** argv[0] -> module name
101086
+** argv[0] -> module name ("fts3" or "fts4")
100373101087
** argv[1] -> database name
100374101088
** argv[2] -> table name
100375101089
** argv[...] -> "column name" and other module argument fields.
100376101090
*/
100377101091
static int fts3InitVtab(
@@ -100386,16 +101100,16 @@
100386101100
Fts3Hash *pHash = (Fts3Hash *)pAux;
100387101101
Fts3Table *p; /* Pointer to allocated vtab */
100388101102
int rc; /* Return code */
100389101103
int i; /* Iterator variable */
100390101104
int nByte; /* Size of allocation used for *p */
100391
- int iCol;
100392
- int nString = 0;
100393
- int nCol = 0;
100394
- char *zCsr;
100395
- int nDb;
100396
- int nName;
101105
+ int iCol; /* Column index */
101106
+ int nString = 0; /* Bytes required to hold all column names */
101107
+ int nCol = 0; /* Number of columns in the FTS table */
101108
+ char *zCsr; /* Space for holding column names */
101109
+ int nDb; /* Bytes required to hold database name */
101110
+ int nName; /* Bytes required to hold table name */
100397101111
100398101112
const char *zTokenizer = 0; /* Name of tokenizer to use */
100399101113
sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
100400101114
100401101115
nDb = (int)strlen(argv[1]) + 1;
@@ -100621,10 +101335,15 @@
100621101335
sqlite3_free(pCsr->aMatchinfo);
100622101336
sqlite3_free(pCsr);
100623101337
return SQLITE_OK;
100624101338
}
100625101339
101340
+/*
101341
+** Position the pCsr->pStmt statement so that it is on the row
101342
+** of the %_content table that contains the last match. Return
101343
+** SQLITE_OK on success.
101344
+*/
100626101345
static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
100627101346
if( pCsr->isRequireSeek ){
100628101347
pCsr->isRequireSeek = 0;
100629101348
sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
100630101349
if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
@@ -100647,10 +101366,21 @@
100647101366
}else{
100648101367
return SQLITE_OK;
100649101368
}
100650101369
}
100651101370
101371
+/*
101372
+** Advance the cursor to the next row in the %_content table that
101373
+** matches the search criteria. For a MATCH search, this will be
101374
+** the next row that matches. For a full-table scan, this will be
101375
+** simply the next row in the %_content table. For a docid lookup,
101376
+** this routine simply sets the EOF flag.
101377
+**
101378
+** Return SQLITE_OK if nothing goes wrong. SQLITE_OK is returned
101379
+** even if we reach end-of-file. The fts3EofMethod() will be called
101380
+** subsequently to determine whether or not an EOF was hit.
101381
+*/
100652101382
static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
100653101383
int rc = SQLITE_OK; /* Return code */
100654101384
Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
100655101385
100656101386
if( pCsr->aDoclist==0 ){
@@ -100782,10 +101512,15 @@
100782101512
100783101513
/*
100784101514
** When this function is called, *ppPoslist is assumed to point to the
100785101515
** start of a position-list. After it returns, *ppPoslist points to the
100786101516
** first byte after the position-list.
101517
+**
101518
+** A position list is list of positions (delta encoded) and columns for
101519
+** a single document record of a doclist. So, in other words, this
101520
+** routine advances *ppPoslist so that it points to the next docid in
101521
+** the doclist, or to the first byte past the end of the doclist.
100787101522
**
100788101523
** If pp is not NULL, then the contents of the position list are copied
100789101524
** to *pp. *pp is set to point to the first byte past the last byte copied
100790101525
** before this function returns.
100791101526
*/
@@ -100792,21 +101527,24 @@
100792101527
static void fts3PoslistCopy(char **pp, char **ppPoslist){
100793101528
char *pEnd = *ppPoslist;
100794101529
char c = 0;
100795101530
100796101531
/* The end of a position list is marked by a zero encoded as an FTS3
100797
- ** varint. A single 0x00 byte. Except, if the 0x00 byte is preceded by
101532
+ ** varint. A single POS_END (0) byte. Except, if the 0 byte is preceded by
100798101533
** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
100799101534
** of some other, multi-byte, value.
100800101535
**
100801
- ** The following block moves pEnd to point to the first byte that is not
101536
+ ** The following while-loop moves pEnd to point to the first byte that is not
100802101537
** immediately preceded by a byte with the 0x80 bit set. Then increments
100803101538
** pEnd once more so that it points to the byte immediately following the
100804101539
** last byte in the position-list.
100805101540
*/
100806
- while( *pEnd | c ) c = *pEnd++ & 0x80;
100807
- pEnd++;
101541
+ while( *pEnd | c ){
101542
+ c = *pEnd++ & 0x80;
101543
+ testcase( c!=0 && (*pEnd)==0 );
101544
+ }
101545
+ pEnd++; /* Advance past the POS_END terminator byte */
100808101546
100809101547
if( pp ){
100810101548
int n = (int)(pEnd - *ppPoslist);
100811101549
char *p = *pp;
100812101550
memcpy(p, *ppPoslist, n);
@@ -100814,16 +101552,38 @@
100814101552
*pp = p;
100815101553
}
100816101554
*ppPoslist = pEnd;
100817101555
}
100818101556
101557
+/*
101558
+** When this function is called, *ppPoslist is assumed to point to the
101559
+** start of a column-list. After it returns, *ppPoslist points to the
101560
+** to the terminator (POS_COLUMN or POS_END) byte of the column-list.
101561
+**
101562
+** A column-list is list of delta-encoded positions for a single column
101563
+** within a single document within a doclist.
101564
+**
101565
+** The column-list is terminated either by a POS_COLUMN varint (1) or
101566
+** a POS_END varint (0). This routine leaves *ppPoslist pointing to
101567
+** the POS_COLUMN or POS_END that terminates the column-list.
101568
+**
101569
+** If pp is not NULL, then the contents of the column-list are copied
101570
+** to *pp. *pp is set to point to the first byte past the last byte copied
101571
+** before this function returns. The POS_COLUMN or POS_END terminator
101572
+** is not copied into *pp.
101573
+*/
100819101574
static void fts3ColumnlistCopy(char **pp, char **ppPoslist){
100820101575
char *pEnd = *ppPoslist;
100821101576
char c = 0;
100822101577
100823
- /* A column-list is terminated by either a 0x01 or 0x00. */
100824
- while( 0xFE & (*pEnd | c) ) c = *pEnd++ & 0x80;
101578
+ /* A column-list is terminated by either a 0x01 or 0x00 byte that is
101579
+ ** not part of a multi-byte varint.
101580
+ */
101581
+ while( 0xFE & (*pEnd | c) ){
101582
+ c = *pEnd++ & 0x80;
101583
+ testcase( c!=0 && ((*pEnd)&0xfe)==0 );
101584
+ }
100825101585
if( pp ){
100826101586
int n = (int)(pEnd - *ppPoslist);
100827101587
char *p = *pp;
100828101588
memcpy(p, *ppPoslist, n);
100829101589
p += n;
@@ -100831,41 +101591,49 @@
100831101591
}
100832101592
*ppPoslist = pEnd;
100833101593
}
100834101594
100835101595
/*
100836
-** Value used to signify the end of an offset-list. This is safe because
101596
+** Value used to signify the end of an position-list. This is safe because
100837101597
** it is not possible to have a document with 2^31 terms.
100838101598
*/
100839
-#define OFFSET_LIST_END 0x7fffffff
101599
+#define POSITION_LIST_END 0x7fffffff
100840101600
100841101601
/*
100842
-** This function is used to help parse offset-lists. When this function is
100843
-** called, *pp may point to the start of the next varint in the offset-list
100844
-** being parsed, or it may point to 1 byte past the end of the offset-list
100845
-** (in which case **pp will be 0x00 or 0x01).
101602
+** This function is used to help parse position-lists. When this function is
101603
+** called, *pp may point to the start of the next varint in the position-list
101604
+** being parsed, or it may point to 1 byte past the end of the position-list
101605
+** (in which case **pp will be a terminator bytes POS_END (0) or
101606
+** (1)).
100846101607
**
100847
-** If *pp points past the end of the current offset list, set *pi to
100848
-** OFFSET_LIST_END and return. Otherwise, read the next varint from *pp,
101608
+** If *pp points past the end of the current position-list, set *pi to
101609
+** POSITION_LIST_END and return. Otherwise, read the next varint from *pp,
100849101610
** increment the current value of *pi by the value read, and set *pp to
100850101611
** point to the next value before returning.
101612
+**
101613
+** Before calling this routine *pi must be initialized to the value of
101614
+** the previous position, or zero if we are reading the first position
101615
+** in the position-list. Because positions are delta-encoded, the value
101616
+** of the previous position is needed in order to compute the value of
101617
+** the next position.
100851101618
*/
100852101619
static void fts3ReadNextPos(
100853
- char **pp, /* IN/OUT: Pointer into offset-list buffer */
100854
- sqlite3_int64 *pi /* IN/OUT: Value read from offset-list */
101620
+ char **pp, /* IN/OUT: Pointer into position-list buffer */
101621
+ sqlite3_int64 *pi /* IN/OUT: Value read from position-list */
100855101622
){
100856
- if( **pp&0xFE ){
101623
+ if( (**pp)&0xFE ){
100857101624
fts3GetDeltaVarint(pp, pi);
100858101625
*pi -= 2;
100859101626
}else{
100860
- *pi = OFFSET_LIST_END;
101627
+ *pi = POSITION_LIST_END;
100861101628
}
100862101629
}
100863101630
100864101631
/*
100865
-** If parameter iCol is not 0, write an 0x01 byte followed by the value of
100866
-** iCol encoded as a varint to *pp.
101632
+** If parameter iCol is not 0, write an POS_COLUMN (1) byte followed by
101633
+** the value of iCol encoded as a varint to *pp. This will start a new
101634
+** column list.
100867101635
**
100868101636
** Set *pp to point to the byte just after the last byte written before
100869101637
** returning (do not modify it if iCol==0). Return the total number of bytes
100870101638
** written (0 if iCol==0).
100871101639
*/
@@ -100879,11 +101647,15 @@
100879101647
}
100880101648
return n;
100881101649
}
100882101650
100883101651
/*
100884
-**
101652
+** Compute the union of two position lists. The output written
101653
+** into *pp contains all positions of both *pp1 and *pp2 in sorted
101654
+** order and with any duplicates removed. All pointers are
101655
+** updated appropriately. The caller is responsible for insuring
101656
+** that there is enough space in *pp to hold the complete output.
100885101657
*/
100886101658
static void fts3PoslistMerge(
100887101659
char **pp, /* Output buffer */
100888101660
char **pp1, /* Left input list */
100889101661
char **pp2 /* Right input list */
@@ -100891,36 +101663,37 @@
100891101663
char *p = *pp;
100892101664
char *p1 = *pp1;
100893101665
char *p2 = *pp2;
100894101666
100895101667
while( *p1 || *p2 ){
100896
- int iCol1;
100897
- int iCol2;
101668
+ int iCol1; /* The current column index in pp1 */
101669
+ int iCol2; /* The current column index in pp2 */
100898101670
100899
- if( *p1==0x01 ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
100900
- else if( *p1==0x00 ) iCol1 = OFFSET_LIST_END;
101671
+ if( *p1==POS_COLUMN ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
101672
+ else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
100901101673
else iCol1 = 0;
100902101674
100903
- if( *p2==0x01 ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
100904
- else if( *p2==0x00 ) iCol2 = OFFSET_LIST_END;
101675
+ if( *p2==POS_COLUMN ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
101676
+ else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
100905101677
else iCol2 = 0;
100906101678
100907101679
if( iCol1==iCol2 ){
100908
- sqlite3_int64 i1 = 0;
100909
- sqlite3_int64 i2 = 0;
101680
+ sqlite3_int64 i1 = 0; /* Last position from pp1 */
101681
+ sqlite3_int64 i2 = 0; /* Last position from pp2 */
100910101682
sqlite3_int64 iPrev = 0;
100911101683
int n = fts3PutColNumber(&p, iCol1);
100912101684
p1 += n;
100913101685
p2 += n;
100914101686
100915
- /* At this point, both p1 and p2 point to the start of offset-lists.
100916
- ** An offset-list is a list of non-negative delta-encoded varints, each
100917
- ** incremented by 2 before being stored. Each list is terminated by a 0
100918
- ** or 1 value (0x00 or 0x01). The following block merges the two lists
101687
+ /* At this point, both p1 and p2 point to the start of column-lists
101688
+ ** for the same column (the column with index iCol1 and iCol2).
101689
+ ** A column-list is a list of non-negative delta-encoded varints, each
101690
+ ** incremented by 2 before being stored. Each list is terminated by a
101691
+ ** POS_END (0) or POS_COLUMN (1). The following block merges the two lists
100919101692
** and writes the results to buffer p. p is left pointing to the byte
100920
- ** after the list written. No terminator (0x00 or 0x01) is written to
100921
- ** the output.
101693
+ ** after the list written. No terminator (POS_END or POS_COLUMN) is
101694
+ ** written to the output.
100922101695
*/
100923101696
fts3GetDeltaVarint(&p1, &i1);
100924101697
fts3GetDeltaVarint(&p2, &i2);
100925101698
do {
100926101699
fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
@@ -100931,21 +101704,21 @@
100931101704
}else if( i1<i2 ){
100932101705
fts3ReadNextPos(&p1, &i1);
100933101706
}else{
100934101707
fts3ReadNextPos(&p2, &i2);
100935101708
}
100936
- }while( i1!=OFFSET_LIST_END || i2!=OFFSET_LIST_END );
101709
+ }while( i1!=POSITION_LIST_END || i2!=POSITION_LIST_END );
100937101710
}else if( iCol1<iCol2 ){
100938101711
p1 += fts3PutColNumber(&p, iCol1);
100939101712
fts3ColumnlistCopy(&p, &p1);
100940101713
}else{
100941101714
p2 += fts3PutColNumber(&p, iCol2);
100942101715
fts3ColumnlistCopy(&p, &p2);
100943101716
}
100944101717
}
100945101718
100946
- *p++ = '\0';
101719
+ *p++ = POS_END;
100947101720
*pp = p;
100948101721
*pp1 = p1 + 1;
100949101722
*pp2 = p2 + 1;
100950101723
}
100951101724
@@ -100964,15 +101737,15 @@
100964101737
char *p2 = *pp2;
100965101738
100966101739
int iCol1 = 0;
100967101740
int iCol2 = 0;
100968101741
assert( *p1!=0 && *p2!=0 );
100969
- if( *p1==0x01 ){
101742
+ if( *p1==POS_COLUMN ){
100970101743
p1++;
100971101744
p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
100972101745
}
100973
- if( *p2==0x01 ){
101746
+ if( *p2==POS_COLUMN ){
100974101747
p2++;
100975101748
p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
100976101749
}
100977101750
100978101751
while( 1 ){
@@ -100981,15 +101754,16 @@
100981101754
sqlite3_int64 iPrev = 0;
100982101755
sqlite3_int64 iPos1 = 0;
100983101756
sqlite3_int64 iPos2 = 0;
100984101757
100985101758
if( pp && iCol1 ){
100986
- *p++ = 0x01;
101759
+ *p++ = POS_COLUMN;
100987101760
p += sqlite3Fts3PutVarint(p, iCol1);
100988101761
}
100989101762
100990
- assert( *p1!=0x00 && *p2!=0x00 && *p1!=0x01 && *p2!=0x01 );
101763
+ assert( *p1!=POS_END && *p1!=POS_COLUMN );
101764
+ assert( *p2!=POS_END && *p2!=POS_COLUMN );
100991101765
fts3GetDeltaVarint(&p1, &iPos1); iPos1 -= 2;
100992101766
fts3GetDeltaVarint(&p2, &iPos2); iPos2 -= 2;
100993101767
100994101768
while( 1 ){
100995101769
if( iPos2>iPos1 && iPos2<=iPos1+nToken ){
@@ -101237,10 +102011,11 @@
101237102011
}
101238102012
101239102013
default: assert( mergetype==MERGE_POS_NEAR || mergetype==MERGE_NEAR ); {
101240102014
char *aTmp = 0;
101241102015
char **ppPos = 0;
102016
+
101242102017
if( mergetype==MERGE_POS_NEAR ){
101243102018
ppPos = &p;
101244102019
aTmp = sqlite3_malloc(2*(n1+n2+1));
101245102020
if( !aTmp ){
101246102021
return SQLITE_NOMEM;
@@ -101341,13 +102116,13 @@
101341102116
** This function retreives the doclist for the specified term (or term
101342102117
** prefix) from the database.
101343102118
**
101344102119
** The returned doclist may be in one of two formats, depending on the
101345102120
** value of parameter isReqPos. If isReqPos is zero, then the doclist is
101346
-** a sorted list of delta-compressed docids. If isReqPos is non-zero,
101347
-** then the returned list is in the same format as is stored in the
101348
-** database without the found length specifier at the start of on-disk
102121
+** a sorted list of delta-compressed docids (a bare doclist). If isReqPos
102122
+** is non-zero, then the returned list is in the same format as is stored
102123
+** in the database without the found length specifier at the start of on-disk
101349102124
** doclists.
101350102125
*/
101351102126
static int fts3TermSelect(
101352102127
Fts3Table *p, /* Virtual table handle */
101353102128
int iColumn, /* Column to query (or -ve for all columns) */
@@ -101603,11 +102378,13 @@
101603102378
return rc;
101604102379
}
101605102380
101606102381
/*
101607102382
** Evaluate the full-text expression pExpr against fts3 table pTab. Store
101608
-** the resulting doclist in *paOut and *pnOut.
102383
+** the resulting doclist in *paOut and *pnOut. This routine mallocs for
102384
+** the space needed to store the output. The caller is responsible for
102385
+** freeing the space when it has finished.
101609102386
*/
101610102387
static int evalFts3Expr(
101611102388
Fts3Table *p, /* Virtual table handle */
101612102389
Fts3Expr *pExpr, /* Parsed fts3 expression */
101613102390
char **paOut, /* OUT: Pointer to malloc'd result buffer */
@@ -108163,11 +108940,11 @@
108163108940
** This is done as part of extracting the snippet text, not when selecting
108164108941
** the snippet. Snippet selection is done based on doclists only, so there
108165108942
** is no way for fts3BestSnippet() to know whether or not the document
108166108943
** actually contains terms that follow the final highlighted term.
108167108944
*/
108168
-int fts3SnippetShift(
108945
+static int fts3SnippetShift(
108169108946
Fts3Table *pTab, /* FTS3 table snippet comes from */
108170108947
int nSnippet, /* Number of tokens desired for snippet */
108171108948
const char *zDoc, /* Document text to extract snippet from */
108172108949
int nDoc, /* Size of buffer zDoc in bytes */
108173108950
int *piPos, /* IN/OUT: First token of snippet */
@@ -111280,10 +112057,11 @@
111280112057
rc = SQLITE_CONSTRAINT;
111281112058
goto constraint;
111282112059
}
111283112060
rc = sqlite3_reset(pRtree->pReadRowid);
111284112061
}
112062
+ *pRowid = cell.iRowid;
111285112063
111286112064
if( rc==SQLITE_OK ){
111287112065
rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
111288112066
}
111289112067
if( rc==SQLITE_OK ){
111290112068
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.6.23.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% are more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -321,11 +321,11 @@
321 ** to generate appropriate macros for a wide range of compilers.
322 **
323 ** The correct "ANSI" way to do this is to use the intptr_t type.
324 ** Unfortunately, that typedef is not available on all compilers, or
325 ** if it is available, it requires an #include of specific headers
326 ** that very from one machine to the next.
327 **
328 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
329 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
330 ** So we have to define the macros in different ways depending on the
331 ** compiler.
@@ -626,13 +626,13 @@
626 **
627 ** See also: [sqlite3_libversion()],
628 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
629 ** [sqlite_version()] and [sqlite_source_id()].
630 */
631 #define SQLITE_VERSION "3.6.23.1"
632 #define SQLITE_VERSION_NUMBER 3006023
633 #define SQLITE_SOURCE_ID "2010-03-26 22:28:06 ex-b078b588d617e07886ad156e9f54ade6d823568e"
634
635 /*
636 ** CAPI3REF: Run-Time Library Version Numbers
637 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
638 **
@@ -665,11 +665,10 @@
665 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
666 SQLITE_API const char *sqlite3_libversion(void);
667 SQLITE_API const char *sqlite3_sourceid(void);
668 SQLITE_API int sqlite3_libversion_number(void);
669
670 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
671 /*
672 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
673 **
674 ** ^The sqlite3_compileoption_used() function returns 0 or 1
675 ** indicating whether the specified option was defined at
@@ -688,13 +687,14 @@
688 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
689 **
690 ** See also: SQL functions [sqlite_compileoption_used()] and
691 ** [sqlite_compileoption_get()] and the [compile_options pragma].
692 */
 
693 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
694 SQLITE_API const char *sqlite3_compileoption_get(int N);
695 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
696
697 /*
698 ** CAPI3REF: Test To See If The Library Is Threadsafe
699 **
700 ** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -1492,15 +1492,14 @@
1492 **
1493 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1494 ** ^If the option is unknown or SQLite is unable to set the option
1495 ** then this routine returns a non-zero [error code].
1496 */
1497 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
1498
1499 /*
1500 ** CAPI3REF: Configure database connections
1501 ** EXPERIMENTAL
1502 **
1503 ** The sqlite3_db_config() interface is used to make configuration
1504 ** changes to a [database connection]. The interface is similar to
1505 ** [sqlite3_config()] except that the changes apply to a single
1506 ** [database connection] (specified in the first argument). The
@@ -1516,15 +1515,14 @@
1516 ** Additional arguments depend on the verb.
1517 **
1518 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1519 ** the call is considered successful.
1520 */
1521 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
1522
1523 /*
1524 ** CAPI3REF: Memory Allocation Routines
1525 ** EXPERIMENTAL
1526 **
1527 ** An instance of this object defines the interface between SQLite
1528 ** and low-level memory allocation routines.
1529 **
1530 ** This object is used in only one place in the SQLite interface.
@@ -1602,11 +1600,10 @@
1602 void *pAppData; /* Argument to xInit() and xShutdown() */
1603 };
1604
1605 /*
1606 ** CAPI3REF: Configuration Options
1607 ** EXPERIMENTAL
1608 **
1609 ** These constants are the available integer configuration options that
1610 ** can be passed as the first argument to the [sqlite3_config()] interface.
1611 **
1612 ** New configuration options may be added in future releases of SQLite.
@@ -1788,10 +1785,28 @@
1788 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1789 ** <dd> ^(This option takes a single argument which is a pointer to an
1790 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1791 ** page cache implementation into that object.)^ </dd>
1792 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1793 ** </dl>
1794 */
1795 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1796 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1797 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1808,12 +1823,11 @@
1808 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1809 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1810 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1811
1812 /*
1813 ** CAPI3REF: Configuration Options
1814 ** EXPERIMENTAL
1815 **
1816 ** These constants are the available integer configuration options that
1817 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
1818 **
1819 ** New configuration options may be added in future releases of SQLite.
@@ -2585,11 +2599,10 @@
2585 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2586 #define SQLITE_COPY 0 /* No longer used */
2587
2588 /*
2589 ** CAPI3REF: Tracing And Profiling Functions
2590 ** EXPERIMENTAL
2591 **
2592 ** These routines register callback functions that can be used for
2593 ** tracing and profiling the execution of SQL statements.
2594 **
2595 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2603,11 +2616,11 @@
2603 ** ^The callback function registered by sqlite3_profile() is invoked
2604 ** as each SQL statement finishes. ^The profile callback contains
2605 ** the original statement text and an estimate of wall-clock time
2606 ** of how long that statement took to run.
2607 */
2608 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2609 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2610 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2611
2612 /*
2613 ** CAPI3REF: Query Progress Callbacks
@@ -4208,11 +4221,11 @@
4208 sqlite3*,
4209 void*,
4210 void(*)(void*,sqlite3*,int eTextRep,const void*)
4211 );
4212
4213 #if SQLITE_HAS_CODEC
4214 /*
4215 ** Specify the key for an encrypted database. This routine should be
4216 ** called right after sqlite3_open().
4217 **
4218 ** The code to implement this API is not available in the public release
@@ -4391,12 +4404,10 @@
4391 ** ^For the purposes of this API, a transaction is said to have been
4392 ** rolled back if an explicit "ROLLBACK" statement is executed, or
4393 ** an error or constraint causes an implicit rollback to occur.
4394 ** ^The rollback callback is not invoked if a transaction is
4395 ** automatically rolled back because the database connection is closed.
4396 ** ^The rollback callback is not invoked if a transaction is
4397 ** rolled back because a commit callback returned non-zero.
4398 **
4399 ** See also the [sqlite3_update_hook()] interface.
4400 */
4401 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
4402 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
@@ -4678,12 +4689,10 @@
4678 ** ^This function disables automatic extensions in all threads.
4679 */
4680 SQLITE_API void sqlite3_reset_auto_extension(void);
4681
4682 /*
4683 ****** EXPERIMENTAL - subject to change without notice **************
4684 **
4685 ** The interface to the virtual-table mechanism is currently considered
4686 ** to be experimental. The interface might change in incompatible ways.
4687 ** If this is a problem for you, do not use the interface at this time.
4688 **
4689 ** When the virtual-table mechanism stabilizes, we will declare the
@@ -4699,11 +4708,10 @@
4699 typedef struct sqlite3_module sqlite3_module;
4700
4701 /*
4702 ** CAPI3REF: Virtual Table Object
4703 ** KEYWORDS: sqlite3_module {virtual table module}
4704 ** EXPERIMENTAL
4705 **
4706 ** This structure, sometimes called a a "virtual table module",
4707 ** defines the implementation of a [virtual tables].
4708 ** This structure consists mostly of methods for the module.
4709 **
@@ -4746,11 +4754,10 @@
4746 };
4747
4748 /*
4749 ** CAPI3REF: Virtual Table Indexing Information
4750 ** KEYWORDS: sqlite3_index_info
4751 ** EXPERIMENTAL
4752 **
4753 ** The sqlite3_index_info structure and its substructures is used to
4754 ** pass information into and receive the reply from the [xBestIndex]
4755 ** method of a [virtual table module]. The fields under **Inputs** are the
4756 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4828,11 +4835,10 @@
4828 #define SQLITE_INDEX_CONSTRAINT_GE 32
4829 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
4830
4831 /*
4832 ** CAPI3REF: Register A Virtual Table Implementation
4833 ** EXPERIMENTAL
4834 **
4835 ** ^These routines are used to register a new [virtual table module] name.
4836 ** ^Module names must be registered before
4837 ** creating a new [virtual table] using the module and before using a
4838 ** preexisting [virtual table] for the module.
@@ -4850,17 +4856,17 @@
4850 ** invoke the destructor function (if it is not NULL) when SQLite
4851 ** no longer needs the pClientData pointer. ^The sqlite3_create_module()
4852 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
4853 ** destructor.
4854 */
4855 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
4856 sqlite3 *db, /* SQLite connection to register module with */
4857 const char *zName, /* Name of the module */
4858 const sqlite3_module *p, /* Methods for the module */
4859 void *pClientData /* Client data for xCreate/xConnect */
4860 );
4861 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
4862 sqlite3 *db, /* SQLite connection to register module with */
4863 const char *zName, /* Name of the module */
4864 const sqlite3_module *p, /* Methods for the module */
4865 void *pClientData, /* Client data for xCreate/xConnect */
4866 void(*xDestroy)(void*) /* Module destructor function */
@@ -4867,11 +4873,10 @@
4867 );
4868
4869 /*
4870 ** CAPI3REF: Virtual Table Instance Object
4871 ** KEYWORDS: sqlite3_vtab
4872 ** EXPERIMENTAL
4873 **
4874 ** Every [virtual table module] implementation uses a subclass
4875 ** of this object to describe a particular instance
4876 ** of the [virtual table]. Each subclass will
4877 ** be tailored to the specific needs of the module implementation.
@@ -4893,11 +4898,10 @@
4893 };
4894
4895 /*
4896 ** CAPI3REF: Virtual Table Cursor Object
4897 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
4898 ** EXPERIMENTAL
4899 **
4900 ** Every [virtual table module] implementation uses a subclass of the
4901 ** following structure to describe cursors that point into the
4902 ** [virtual table] and are used
4903 ** to loop through the virtual table. Cursors are created using the
@@ -4915,22 +4919,20 @@
4915 /* Virtual table implementations will typically add additional fields */
4916 };
4917
4918 /*
4919 ** CAPI3REF: Declare The Schema Of A Virtual Table
4920 ** EXPERIMENTAL
4921 **
4922 ** ^The [xCreate] and [xConnect] methods of a
4923 ** [virtual table module] call this interface
4924 ** to declare the format (the names and datatypes of the columns) of
4925 ** the virtual tables they implement.
4926 */
4927 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4928
4929 /*
4930 ** CAPI3REF: Overload A Function For A Virtual Table
4931 ** EXPERIMENTAL
4932 **
4933 ** ^(Virtual tables can provide alternative implementations of functions
4934 ** using the [xFindFunction] method of the [virtual table module].
4935 ** But global versions of those functions
4936 ** must exist in order to be overloaded.)^
@@ -4941,22 +4943,20 @@
4941 ** of the new function always causes an exception to be thrown. So
4942 ** the new function is not good for anything by itself. Its only
4943 ** purpose is to be a placeholder function that can be overloaded
4944 ** by a [virtual table].
4945 */
4946 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4947
4948 /*
4949 ** The interface to the virtual-table mechanism defined above (back up
4950 ** to a comment remarkably similar to this one) is currently considered
4951 ** to be experimental. The interface might change in incompatible ways.
4952 ** If this is a problem for you, do not use the interface at this time.
4953 **
4954 ** When the virtual-table mechanism stabilizes, we will declare the
4955 ** interface fixed, support it indefinitely, and remove this comment.
4956 **
4957 ****** EXPERIMENTAL - subject to change without notice **************
4958 */
4959
4960 /*
4961 ** CAPI3REF: A Handle To An Open BLOB
4962 ** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -5295,11 +5295,10 @@
5295 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
5296 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
5297
5298 /*
5299 ** CAPI3REF: Mutex Methods Object
5300 ** EXPERIMENTAL
5301 **
5302 ** An instance of this structure defines the low-level routines
5303 ** used to allocate and use mutexes.
5304 **
5305 ** Usually, the default mutex implementations provided by SQLite are
@@ -5512,11 +5511,10 @@
5512 #define SQLITE_TESTCTRL_ISKEYWORD 16
5513 #define SQLITE_TESTCTRL_LAST 16
5514
5515 /*
5516 ** CAPI3REF: SQLite Runtime Status
5517 ** EXPERIMENTAL
5518 **
5519 ** ^This interface is used to retrieve runtime status information
5520 ** about the preformance of SQLite, and optionally to reset various
5521 ** highwater marks. ^The first argument is an integer code for
5522 ** the specific parameter to measure. ^(Recognized integer codes
@@ -5540,16 +5538,15 @@
5540 ** and it is possible that another thread might change the parameter
5541 ** in between the times when *pCurrent and *pHighwater are written.
5542 **
5543 ** See also: [sqlite3_db_status()]
5544 */
5545 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5546
5547
5548 /*
5549 ** CAPI3REF: Status Parameters
5550 ** EXPERIMENTAL
5551 **
5552 ** These integer constants designate various run-time status parameters
5553 ** that can be returned by [sqlite3_status()].
5554 **
5555 ** <dl>
@@ -5632,31 +5629,31 @@
5632 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5633 #define SQLITE_STATUS_SCRATCH_SIZE 8
5634
5635 /*
5636 ** CAPI3REF: Database Connection Status
5637 ** EXPERIMENTAL
5638 **
5639 ** ^This interface is used to retrieve runtime status information
5640 ** about a single [database connection]. ^The first argument is the
5641 ** database connection object to be interrogated. ^The second argument
5642 ** is the parameter to interrogate. ^Currently, the only allowed value
5643 ** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
5644 ** Additional options will likely appear in future releases of SQLite.
 
 
5645 **
5646 ** ^The current value of the requested parameter is written into *pCur
5647 ** and the highest instantaneous value is written into *pHiwtr. ^If
5648 ** the resetFlg is true, then the highest instantaneous value is
5649 ** reset back down to the current value.
5650 **
5651 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5652 */
5653 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5654
5655 /*
5656 ** CAPI3REF: Status Parameters for database connections
5657 ** EXPERIMENTAL
5658 **
5659 ** These constants are the available integer "verbs" that can be passed as
5660 ** the second argument to the [sqlite3_db_status()] interface.
5661 **
5662 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5667,18 +5664,25 @@
5667 **
5668 ** <dl>
5669 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5670 ** <dd>This parameter returns the number of lookaside memory slots currently
5671 ** checked out.</dd>)^
 
 
 
 
 
 
5672 ** </dl>
5673 */
5674 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
 
 
5675
5676
5677 /*
5678 ** CAPI3REF: Prepared Statement Status
5679 ** EXPERIMENTAL
5680 **
5681 ** ^(Each prepared statement maintains various
5682 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5683 ** of times it has performed specific operations.)^ These counters can
5684 ** be used to monitor the performance characteristics of the prepared
@@ -5696,15 +5700,14 @@
5696 ** ^If the resetFlg is true, then the counter is reset to zero after this
5697 ** interface call returns.
5698 **
5699 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
5700 */
5701 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5702
5703 /*
5704 ** CAPI3REF: Status Parameters for prepared statements
5705 ** EXPERIMENTAL
5706 **
5707 ** These preprocessor macros define integer codes that name counter
5708 ** values associated with the [sqlite3_stmt_status()] interface.
5709 ** The meanings of the various counters are as follows:
5710 **
@@ -5718,18 +5721,25 @@
5718 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
5719 ** <dd>^This is the number of sort operations that have occurred.
5720 ** A non-zero value in this counter may indicate an opportunity to
5721 ** improvement performance through careful use of indices.</dd>
5722 **
 
 
 
 
 
 
 
5723 ** </dl>
5724 */
5725 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5726 #define SQLITE_STMTSTATUS_SORT 2
 
5727
5728 /*
5729 ** CAPI3REF: Custom Page Cache Object
5730 ** EXPERIMENTAL
5731 **
5732 ** The sqlite3_pcache type is opaque. It is implemented by
5733 ** the pluggable module. The SQLite core has no knowledge of
5734 ** its size or internal structure and never deals with the
5735 ** sqlite3_pcache object except by holding and passing pointers
@@ -5740,11 +5750,10 @@
5740 typedef struct sqlite3_pcache sqlite3_pcache;
5741
5742 /*
5743 ** CAPI3REF: Application Defined Page Cache.
5744 ** KEYWORDS: {page cache}
5745 ** EXPERIMENTAL
5746 **
5747 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5748 ** register an alternative page cache implementation by passing in an
5749 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5750 ** heap memory used by SQLite is used by the page cache to cache data read
@@ -5882,11 +5891,10 @@
5882 void (*xDestroy)(sqlite3_pcache*);
5883 };
5884
5885 /*
5886 ** CAPI3REF: Online Backup Object
5887 ** EXPERIMENTAL
5888 **
5889 ** The sqlite3_backup object records state information about an ongoing
5890 ** online backup operation. ^The sqlite3_backup object is created by
5891 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
5892 ** [sqlite3_backup_finish()].
@@ -5895,11 +5903,10 @@
5895 */
5896 typedef struct sqlite3_backup sqlite3_backup;
5897
5898 /*
5899 ** CAPI3REF: Online Backup API.
5900 ** EXPERIMENTAL
5901 **
5902 ** The backup API copies the content of one database into another.
5903 ** It is useful either for creating backups of databases or
5904 ** for copying in-memory databases to or from persistent files.
5905 **
@@ -6083,11 +6090,10 @@
6083 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
6084 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
6085
6086 /*
6087 ** CAPI3REF: Unlock Notification
6088 ** EXPERIMENTAL
6089 **
6090 ** ^When running in shared-cache mode, a database operation may fail with
6091 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
6092 ** individual tables within the shared-cache cannot be obtained. See
6093 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -6205,11 +6211,10 @@
6205 );
6206
6207
6208 /*
6209 ** CAPI3REF: String Comparison
6210 ** EXPERIMENTAL
6211 **
6212 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
6213 ** compare the contents of two buffers containing UTF-8 strings in a
6214 ** case-indendent fashion, using the same definition of case independence
6215 ** that SQLite uses internally when comparing identifiers.
@@ -6216,16 +6221,15 @@
6216 */
6217 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
6218
6219 /*
6220 ** CAPI3REF: Error Logging Interface
6221 ** EXPERIMENTAL
6222 **
6223 ** ^The [sqlite3_log()] interface writes a message into the error log
6224 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
6225 ** ^If logging is enabled, the zFormat string and subsequent arguments are
6226 ** passed through to [sqlite3_vmprintf()] to generate the final output string.
6227 **
6228 ** The sqlite3_log() interface is intended for use by extensions such as
6229 ** virtual tables, collating functions, and SQL functions. While there is
6230 ** nothing to prevent an application from calling sqlite3_log(), doing so
6231 ** is considered bad form.
@@ -6529,10 +6533,11 @@
6529 ** If compiling for a processor that lacks floating point support,
6530 ** substitute integer for floating-point
6531 */
6532 #ifdef SQLITE_OMIT_FLOATING_POINT
6533 # define double sqlite_int64
 
6534 # define LONGDOUBLE_TYPE sqlite_int64
6535 # ifndef SQLITE_BIG_DBL
6536 # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
6537 # endif
6538 # define SQLITE_OMIT_DATETIME_FUNCS 1
@@ -6940,10 +6945,11 @@
6940 SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
6941 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
6942 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
6943 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
6944 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
 
6945 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
6946 SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
6947 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
6948 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
6949 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
@@ -7334,85 +7340,85 @@
7334 #define OP_ReadCookie 35
7335 #define OP_SetCookie 36
7336 #define OP_VerifyCookie 37
7337 #define OP_OpenRead 38
7338 #define OP_OpenWrite 39
7339 #define OP_OpenEphemeral 40
7340 #define OP_OpenPseudo 41
7341 #define OP_Close 42
7342 #define OP_SeekLt 43
7343 #define OP_SeekLe 44
7344 #define OP_SeekGe 45
7345 #define OP_SeekGt 46
7346 #define OP_Seek 47
7347 #define OP_NotFound 48
7348 #define OP_Found 49
7349 #define OP_IsUnique 50
7350 #define OP_NotExists 51
7351 #define OP_Sequence 52
7352 #define OP_NewRowid 53
7353 #define OP_Insert 54
7354 #define OP_InsertInt 55
7355 #define OP_Delete 56
7356 #define OP_ResetCount 57
7357 #define OP_RowKey 58
7358 #define OP_RowData 59
7359 #define OP_Rowid 60
7360 #define OP_NullRow 61
7361 #define OP_Last 62
7362 #define OP_Sort 63
7363 #define OP_Rewind 64
7364 #define OP_Prev 65
7365 #define OP_Next 66
7366 #define OP_IdxInsert 67
7367 #define OP_IdxDelete 70
7368 #define OP_IdxRowid 71
7369 #define OP_IdxLT 72
7370 #define OP_IdxGE 81
7371 #define OP_Destroy 92
7372 #define OP_Clear 95
7373 #define OP_CreateIndex 96
7374 #define OP_CreateTable 97
7375 #define OP_ParseSchema 98
7376 #define OP_LoadAnalysis 99
7377 #define OP_DropTable 100
7378 #define OP_DropIndex 101
7379 #define OP_DropTrigger 102
7380 #define OP_IntegrityCk 103
7381 #define OP_RowSetAdd 104
7382 #define OP_RowSetRead 105
7383 #define OP_RowSetTest 106
7384 #define OP_Program 107
7385 #define OP_Param 108
7386 #define OP_FkCounter 109
7387 #define OP_FkIfZero 110
7388 #define OP_MemMax 111
7389 #define OP_IfPos 112
7390 #define OP_IfNeg 113
7391 #define OP_IfZero 114
7392 #define OP_AggStep 115
7393 #define OP_AggFinal 116
7394 #define OP_Vacuum 117
7395 #define OP_IncrVacuum 118
7396 #define OP_Expire 119
7397 #define OP_TableLock 120
7398 #define OP_VBegin 121
7399 #define OP_VCreate 122
7400 #define OP_VDestroy 123
7401 #define OP_VOpen 124
7402 #define OP_VFilter 125
7403 #define OP_VColumn 126
7404 #define OP_VNext 127
7405 #define OP_VRename 128
7406 #define OP_VUpdate 129
7407 #define OP_Pagecount 131
7408 #define OP_Trace 132
7409 #define OP_Noop 133
7410 #define OP_Explain 134
7411
7412 /* The following opcode values are never used */
7413 #define OP_NotUsed_135 135
7414 #define OP_NotUsed_136 136
7415 #define OP_NotUsed_137 137
7416 #define OP_NotUsed_138 138
7417 #define OP_NotUsed_139 139
7418 #define OP_NotUsed_140 140
@@ -7433,22 +7439,22 @@
7433 /* 0 */ 0x00, 0x01, 0x05, 0x04, 0x04, 0x10, 0x00, 0x02,\
7434 /* 8 */ 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x24, 0x24,\
7435 /* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\
7436 /* 24 */ 0x00, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\
7437 /* 32 */ 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00,\
7438 /* 40 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
7439 /* 48 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x00,\
7440 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
7441 /* 64 */ 0x01, 0x01, 0x01, 0x08, 0x4c, 0x4c, 0x00, 0x02,\
7442 /* 72 */ 0x01, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
7443 /* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
7444 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x02, 0x24, 0x02, 0x00,\
7445 /* 96 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
7446 /* 104 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
7447 /* 112 */ 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00,\
7448 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,\
7449 /* 128 */ 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
7450 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
7451 /* 144 */ 0x04, 0x04,}
7452
7453 /************** End of opcodes.h *********************************************/
7454 /************** Continuing where we left off in vdbe.h ***********************/
@@ -7658,10 +7664,11 @@
7658 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
7659
7660 /* Functions used to query pager state and configuration. */
7661 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
7662 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
 
7663 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
7664 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
7665 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
7666 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
7667 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
@@ -8478,10 +8485,11 @@
8478 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
8479 #define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */
8480 #define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */
8481 #define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
8482 #define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
 
8483
8484 /*
8485 ** Bits of the sqlite3.flags field that are used by the
8486 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
8487 ** These must be the low-order bits of the flags field.
@@ -9340,10 +9348,13 @@
9340 **
9341 ** The jointype starts out showing the join type between the current table
9342 ** and the next table on the list. The parser builds the list this way.
9343 ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
9344 ** jointype expresses the join between the table and the previous table.
 
 
 
9345 */
9346 struct SrcList {
9347 i16 nSrc; /* Number of tables or subqueries in the FROM clause */
9348 i16 nAlloc; /* Number of entries allocated in a[] below */
9349 struct SrcList_item {
@@ -9451,11 +9462,11 @@
9451 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
9452 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
9453 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
9454 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
9455 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
9456 #define WHERE_OMIT_OPEN 0x0010 /* Table cursor are already open */
9457 #define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
9458 #define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
9459 #define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
9460
9461 /*
@@ -9474,10 +9485,11 @@
9474 int iTop; /* The very beginning of the WHERE loop */
9475 int iContinue; /* Jump here to continue with next record */
9476 int iBreak; /* Jump here to break out of the loop */
9477 int nLevel; /* Number of nested loop */
9478 struct WhereClause *pWC; /* Decomposition of the WHERE clause */
 
9479 WhereLevel a[1]; /* Information about each nest loop in WHERE */
9480 };
9481
9482 /*
9483 ** A NameContext defines a context in which to resolve table and column
@@ -9715,10 +9727,11 @@
9715 u32 oldmask; /* Mask of old.* columns referenced */
9716 u32 newmask; /* Mask of new.* columns referenced */
9717 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
9718 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
9719 u8 disableTriggers; /* True to disable triggers */
 
9720
9721 /* Above is constant between recursions. Below is reset before and after
9722 ** each recursion */
9723
9724 int nVar; /* Number of '?' variables seen in the SQL so far */
@@ -10656,11 +10669,50 @@
10656 #else
10657 # define IOTRACE(A)
10658 # define sqlite3VdbeIOTraceSql(X)
10659 #endif
10660
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10661 #endif
 
 
 
 
 
 
10662
10663 /************** End of sqliteInt.h *******************************************/
10664 /************** Begin file global.c ******************************************/
10665 /*
10666 ** 2008 June 13
@@ -11038,10 +11090,13 @@
11038 #ifdef SQLITE_OMIT_AUTOINCREMENT
11039 "OMIT_AUTOINCREMENT",
11040 #endif
11041 #ifdef SQLITE_OMIT_AUTOINIT
11042 "OMIT_AUTOINIT",
 
 
 
11043 #endif
11044 #ifdef SQLITE_OMIT_AUTOVACUUM
11045 "OMIT_AUTOVACUUM",
11046 #endif
11047 #ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
@@ -11367,10 +11422,30 @@
11367 if( resetFlag ){
11368 db->lookaside.mxOut = db->lookaside.nOut;
11369 }
11370 break;
11371 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11372 default: {
11373 return SQLITE_ERROR;
11374 }
11375 }
11376 return SQLITE_OK;
@@ -13140,11 +13215,12 @@
13140 struct MemBlockHdr {
13141 i64 iSize; /* Size of this allocation */
13142 struct MemBlockHdr *pNext, *pPrev; /* Linked list of all unfreed memory */
13143 char nBacktrace; /* Number of backtraces on this alloc */
13144 char nBacktraceSlots; /* Available backtrace slots */
13145 short nTitle; /* Bytes of title; includes '\0' */
 
13146 int iForeGuard; /* Guard word for sanity */
13147 };
13148
13149 /*
13150 ** Guard words
@@ -13348,10 +13424,11 @@
13348 }else{
13349 mem.pFirst = pHdr;
13350 }
13351 mem.pLast = pHdr;
13352 pHdr->iForeGuard = FOREGUARD;
 
13353 pHdr->nBacktraceSlots = mem.nBacktrace;
13354 pHdr->nTitle = mem.nTitle;
13355 if( mem.nBacktrace ){
13356 void *aAddr[40];
13357 pHdr->nBacktrace = backtrace(aAddr, mem.nBacktrace+1)-1;
@@ -13454,10 +13531,51 @@
13454 sqlite3MemShutdown,
13455 0
13456 };
13457 sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
13458 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13459
13460 /*
13461 ** Set the number of backtrace levels kept for each allocation.
13462 ** A value of zero turns off backtracing. The number is always rounded
13463 ** up to a multiple of 2.
@@ -16446,10 +16564,11 @@
16446 if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
16447 sqlite3_mutex_leave(mem0.mutex);
16448 }else{
16449 p = sqlite3GlobalConfig.m.xMalloc(n);
16450 }
 
16451 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
16452 scratchAllocOut = p!=0;
16453 #endif
16454 return p;
16455 }
@@ -16466,10 +16585,12 @@
16466 #endif
16467
16468 if( sqlite3GlobalConfig.pScratch==0
16469 || p<sqlite3GlobalConfig.pScratch
16470 || p>=(void*)mem0.aScratchFree ){
 
 
16471 if( sqlite3GlobalConfig.bMemstat ){
16472 int iSize = sqlite3MallocSize(p);
16473 sqlite3_mutex_enter(mem0.mutex);
16474 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
16475 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
@@ -16506,26 +16627,30 @@
16506 /*
16507 ** Return the size of a memory allocation previously obtained from
16508 ** sqlite3Malloc() or sqlite3_malloc().
16509 */
16510 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
 
16511 return sqlite3GlobalConfig.m.xSize(p);
16512 }
16513 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
16514 assert( db==0 || sqlite3_mutex_held(db->mutex) );
16515 if( isLookaside(db, p) ){
16516 return db->lookaside.sz;
16517 }else{
 
 
16518 return sqlite3GlobalConfig.m.xSize(p);
16519 }
16520 }
16521
16522 /*
16523 ** Free memory previously obtained from sqlite3Malloc().
16524 */
16525 SQLITE_API void sqlite3_free(void *p){
16526 if( p==0 ) return;
 
16527 if( sqlite3GlobalConfig.bMemstat ){
16528 sqlite3_mutex_enter(mem0.mutex);
16529 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
16530 sqlite3GlobalConfig.m.xFree(p);
16531 sqlite3_mutex_leave(mem0.mutex);
@@ -16544,10 +16669,12 @@
16544 LookasideSlot *pBuf = (LookasideSlot*)p;
16545 pBuf->pNext = db->lookaside.pFree;
16546 db->lookaside.pFree = pBuf;
16547 db->lookaside.nOut--;
16548 }else{
 
 
16549 sqlite3_free(p);
16550 }
16551 }
16552
16553 /*
@@ -16576,10 +16703,11 @@
16576 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
16577 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
16578 mem0.alarmThreshold ){
16579 sqlite3MallocAlarm(nNew-nOld);
16580 }
 
16581 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
16582 if( pNew==0 && mem0.alarmCallback ){
16583 sqlite3MallocAlarm(nBytes);
16584 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
16585 }
@@ -16673,10 +16801,12 @@
16673 #endif
16674 p = sqlite3Malloc(n);
16675 if( !p && db ){
16676 db->mallocFailed = 1;
16677 }
 
 
16678 return p;
16679 }
16680
16681 /*
16682 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -16698,14 +16828,18 @@
16698 if( pNew ){
16699 memcpy(pNew, p, db->lookaside.sz);
16700 sqlite3DbFree(db, p);
16701 }
16702 }else{
 
 
16703 pNew = sqlite3_realloc(p, n);
16704 if( !pNew ){
16705 db->mallocFailed = 1;
16706 }
 
 
16707 }
16708 }
16709 return pNew;
16710 }
16711
@@ -18305,11 +18439,11 @@
18305 u8 isPrepareV2; /* True if prepared with prepare_v2() */
18306 int nChange; /* Number of db changes made since last reset */
18307 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
18308 i64 startTime; /* Time when query started - used for profiling */
18309 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
18310 int aCounter[2]; /* Counters used by sqlite3_stmt_status() */
18311 char *zSql; /* Text of the SQL statement that generated this */
18312 void *pFree; /* Free this when deleting the vdbe */
18313 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
18314 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
18315 int iStatement; /* Statement number (or 0 if has not opened stmt) */
@@ -20345,52 +20479,52 @@
20345 /* 35 */ "ReadCookie",
20346 /* 36 */ "SetCookie",
20347 /* 37 */ "VerifyCookie",
20348 /* 38 */ "OpenRead",
20349 /* 39 */ "OpenWrite",
20350 /* 40 */ "OpenEphemeral",
20351 /* 41 */ "OpenPseudo",
20352 /* 42 */ "Close",
20353 /* 43 */ "SeekLt",
20354 /* 44 */ "SeekLe",
20355 /* 45 */ "SeekGe",
20356 /* 46 */ "SeekGt",
20357 /* 47 */ "Seek",
20358 /* 48 */ "NotFound",
20359 /* 49 */ "Found",
20360 /* 50 */ "IsUnique",
20361 /* 51 */ "NotExists",
20362 /* 52 */ "Sequence",
20363 /* 53 */ "NewRowid",
20364 /* 54 */ "Insert",
20365 /* 55 */ "InsertInt",
20366 /* 56 */ "Delete",
20367 /* 57 */ "ResetCount",
20368 /* 58 */ "RowKey",
20369 /* 59 */ "RowData",
20370 /* 60 */ "Rowid",
20371 /* 61 */ "NullRow",
20372 /* 62 */ "Last",
20373 /* 63 */ "Sort",
20374 /* 64 */ "Rewind",
20375 /* 65 */ "Prev",
20376 /* 66 */ "Next",
20377 /* 67 */ "IdxInsert",
20378 /* 68 */ "Or",
20379 /* 69 */ "And",
20380 /* 70 */ "IdxDelete",
20381 /* 71 */ "IdxRowid",
20382 /* 72 */ "IdxLT",
20383 /* 73 */ "IsNull",
20384 /* 74 */ "NotNull",
20385 /* 75 */ "Ne",
20386 /* 76 */ "Eq",
20387 /* 77 */ "Gt",
20388 /* 78 */ "Le",
20389 /* 79 */ "Lt",
20390 /* 80 */ "Ge",
20391 /* 81 */ "IdxGE",
20392 /* 82 */ "BitAnd",
20393 /* 83 */ "BitOr",
20394 /* 84 */ "ShiftLeft",
20395 /* 85 */ "ShiftRight",
20396 /* 86 */ "Add",
@@ -20397,54 +20531,54 @@
20397 /* 87 */ "Subtract",
20398 /* 88 */ "Multiply",
20399 /* 89 */ "Divide",
20400 /* 90 */ "Remainder",
20401 /* 91 */ "Concat",
20402 /* 92 */ "Destroy",
20403 /* 93 */ "BitNot",
20404 /* 94 */ "String8",
20405 /* 95 */ "Clear",
20406 /* 96 */ "CreateIndex",
20407 /* 97 */ "CreateTable",
20408 /* 98 */ "ParseSchema",
20409 /* 99 */ "LoadAnalysis",
20410 /* 100 */ "DropTable",
20411 /* 101 */ "DropIndex",
20412 /* 102 */ "DropTrigger",
20413 /* 103 */ "IntegrityCk",
20414 /* 104 */ "RowSetAdd",
20415 /* 105 */ "RowSetRead",
20416 /* 106 */ "RowSetTest",
20417 /* 107 */ "Program",
20418 /* 108 */ "Param",
20419 /* 109 */ "FkCounter",
20420 /* 110 */ "FkIfZero",
20421 /* 111 */ "MemMax",
20422 /* 112 */ "IfPos",
20423 /* 113 */ "IfNeg",
20424 /* 114 */ "IfZero",
20425 /* 115 */ "AggStep",
20426 /* 116 */ "AggFinal",
20427 /* 117 */ "Vacuum",
20428 /* 118 */ "IncrVacuum",
20429 /* 119 */ "Expire",
20430 /* 120 */ "TableLock",
20431 /* 121 */ "VBegin",
20432 /* 122 */ "VCreate",
20433 /* 123 */ "VDestroy",
20434 /* 124 */ "VOpen",
20435 /* 125 */ "VFilter",
20436 /* 126 */ "VColumn",
20437 /* 127 */ "VNext",
20438 /* 128 */ "VRename",
20439 /* 129 */ "VUpdate",
20440 /* 130 */ "Real",
20441 /* 131 */ "Pagecount",
20442 /* 132 */ "Trace",
20443 /* 133 */ "Noop",
20444 /* 134 */ "Explain",
20445 /* 135 */ "NotUsed_135",
20446 /* 136 */ "NotUsed_136",
20447 /* 137 */ "NotUsed_137",
20448 /* 138 */ "NotUsed_138",
20449 /* 139 */ "NotUsed_139",
20450 /* 140 */ "NotUsed_140",
@@ -26155,13 +26289,11 @@
26155 flags |= SQLITE_OPEN_READONLY;
26156 openFlags |= O_RDONLY;
26157 fd = open(zName, openFlags, openMode);
26158 }
26159 if( fd<0 ){
26160 sqlite3_log(SQLITE_CANTOPEN, "cannot open file [%s]: %s", zName,
26161 strerror(errno));
26162 rc = SQLITE_CANTOPEN;
26163 goto open_finished;
26164 }
26165 }
26166 assert( fd>=0 );
26167 if( pOutFlags ){
@@ -30816,11 +30948,16 @@
30816 if( pCache->pCache ){
30817 PgHdr *p;
30818 PgHdr *pNext;
30819 for(p=pCache->pDirty; p; p=pNext){
30820 pNext = p->pDirtyNext;
30821 if( p->pgno>pgno ){
 
 
 
 
 
30822 assert( p->flags&PGHDR_DIRTY );
30823 sqlite3PcacheMakeClean(p);
30824 }
30825 }
30826 if( pgno==0 && pCache->pPage1 ){
@@ -31160,10 +31297,11 @@
31160 pcache1EnterMutex();
31161 if( p ){
31162 int sz = sqlite3MallocSize(p);
31163 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
31164 }
 
31165 }
31166 return p;
31167 }
31168
31169 /*
@@ -31177,11 +31315,14 @@
31177 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
31178 pSlot = (PgFreeslot*)p;
31179 pSlot->pNext = pcache1.pFree;
31180 pcache1.pFree = pSlot;
31181 }else{
31182 int iSize = sqlite3MallocSize(p);
 
 
 
31183 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
31184 sqlite3_free(p);
31185 }
31186 }
31187
@@ -32213,10 +32354,91 @@
32213 ** file simultaneously, or one process from reading the database while
32214 ** another is writing.
32215 */
32216 #ifndef SQLITE_OMIT_DISKIO
32217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32218 /*
32219 ** Macros for troubleshooting. Normally turned off
32220 */
32221 #if 0
32222 int sqlite3PagerTrace=1; /* True to enable tracing */
@@ -32389,11 +32611,12 @@
32389 ** It is used when committing or otherwise ending a transaction. If
32390 ** the dbModified flag is clear then less work has to be done.
32391 **
32392 ** journalStarted
32393 **
32394 ** This flag is set whenever the the main journal is synced.
 
32395 **
32396 ** The point of this flag is that it must be set after the
32397 ** first journal header in a journal file has been synced to disk.
32398 ** After this has happened, new pages appended to the database
32399 ** do not need the PGHDR_NEED_SYNC flag set, as they do not need
@@ -32415,11 +32638,14 @@
32415 ** master journal name is only written to the journal file the first
32416 ** time CommitPhaseOne() is called.
32417 **
32418 ** doNotSync
32419 **
32420 ** This variable is set and cleared by sqlite3PagerWrite().
 
 
 
32421 **
32422 ** needSync
32423 **
32424 ** TODO: It might be easier to set this variable in writeJournalHdr()
32425 ** and writeMasterJournal() only. Change its meaning to "unsynced data
@@ -32475,10 +32701,11 @@
32475 sqlite3_file *fd; /* File descriptor for database */
32476 sqlite3_file *jfd; /* File descriptor for main journal */
32477 sqlite3_file *sjfd; /* File descriptor for sub-journal */
32478 i64 journalOff; /* Current write offset in the journal file */
32479 i64 journalHdr; /* Byte offset to previous journal header */
 
32480 PagerSavepoint *aSavepoint; /* Array of active savepoints */
32481 int nSavepoint; /* Number of elements in aSavepoint[] */
32482 char dbFileVers[16]; /* Changes whenever database file changes */
32483 u32 sectorSize; /* Assumed sector size during rollback */
32484
@@ -32501,11 +32728,10 @@
32501 void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */
32502 void (*xCodecFree)(void*); /* Destructor for the codec */
32503 void *pCodec; /* First argument to xCodec... methods */
32504 #endif
32505 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
32506 i64 journalSizeLimit; /* Size limit for persistent journal files */
32507 PCache *pPCache; /* Pointer to page cache object */
32508 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
32509 };
32510
32511 /*
@@ -33017,10 +33243,11 @@
33017 ** to populate the entire journal header sector.
33018 */
33019 for(nWrite=0; rc==SQLITE_OK&&nWrite<JOURNAL_HDR_SZ(pPager); nWrite+=nHeader){
33020 IOTRACE(("JHDR %p %lld %d\n", pPager, pPager->journalHdr, nHeader))
33021 rc = sqlite3OsWrite(pPager->jfd, zHeader, nHeader, pPager->journalOff);
 
33022 pPager->journalOff += nHeader;
33023 }
33024
33025 return rc;
33026 }
@@ -33175,10 +33402,11 @@
33175 ){
33176 return SQLITE_OK;
33177 }
33178 pPager->setMaster = 1;
33179 assert( isOpen(pPager->jfd) );
 
33180
33181 /* Calculate the length in bytes and the checksum of zMaster */
33182 for(nMaster=0; zMaster[nMaster]; nMaster++){
33183 cksum += zMaster[nMaster];
33184 }
@@ -33315,12 +33543,13 @@
33315 pPager->pInJournal = 0;
33316 releaseAllSavepoints(pPager);
33317
33318 /* If the file is unlocked, somebody else might change it. The
33319 ** values stored in Pager.dbSize etc. might become invalid if
33320 ** this happens. TODO: Really, this doesn't need to be cleared
33321 ** until the change-counter check fails in PagerSharedLock().
 
33322 */
33323 pPager->dbSizeValid = 0;
33324
33325 rc = osUnlock(pPager->fd, NO_LOCK);
33326 if( rc ){
@@ -33506,16 +33735,15 @@
33506 }
33507
33508 #ifdef SQLITE_CHECK_PAGES
33509 sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
33510 #endif
33511
33512 sqlite3PcacheCleanAll(pPager->pPCache);
33513 sqlite3BitvecDestroy(pPager->pInJournal);
33514 pPager->pInJournal = 0;
33515 pPager->nRec = 0;
33516 }
 
 
 
 
33517
33518 if( !pPager->exclusiveMode ){
33519 rc2 = osUnlock(pPager->fd, SHARED_LOCK);
33520 pPager->state = PAGER_SHARED;
33521 pPager->changeCountDone = 0;
@@ -33604,22 +33832,22 @@
33604 ** allocated by this function. If this is the case and an allocation fails,
33605 ** SQLITE_NOMEM is returned.
33606 */
33607 static int pager_playback_one_page(
33608 Pager *pPager, /* The pager being played back */
33609 int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
33610 int isUnsync, /* True if reading from unsynced main journal */
33611 i64 *pOffset, /* Offset of record to playback */
33612 int isSavepnt, /* True for a savepoint rollback */
33613 Bitvec *pDone /* Bitvec of pages already played back */
 
33614 ){
33615 int rc;
33616 PgHdr *pPg; /* An existing page in the cache */
33617 Pgno pgno; /* The page number of a page in journal */
33618 u32 cksum; /* Checksum used for sanity checking */
33619 char *aData; /* Temporary storage for the page */
33620 sqlite3_file *jfd; /* The file descriptor for the journal file */
 
33621
33622 assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
33623 assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
33624 assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */
33625 assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
@@ -33699,16 +33927,21 @@
33699 assert( pPg || !MEMDB );
33700 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
33701 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
33702 (isMainJrnl?"main-journal":"sub-journal")
33703 ));
 
 
 
 
 
33704 if( (pPager->state>=PAGER_EXCLUSIVE)
33705 && (pPg==0 || 0==(pPg->flags&PGHDR_NEED_SYNC))
33706 && isOpen(pPager->fd)
33707 && !isUnsync
33708 ){
33709 i64 ofst = (pgno-1)*(i64)pPager->pageSize;
 
33710 rc = sqlite3OsWrite(pPager->fd, (u8*)aData, pPager->pageSize, ofst);
33711 if( pgno>pPager->dbFileSize ){
33712 pPager->dbFileSize = pgno;
33713 }
33714 if( pPager->pBackup ){
@@ -33753,11 +33986,12 @@
33753 pPager->xReiniter(pPg);
33754 if( isMainJrnl && (!isSavepnt || *pOffset<=pPager->journalHdr) ){
33755 /* If the contents of this page were just restored from the main
33756 ** journal file, then its content must be as they were when the
33757 ** transaction was first opened. In this case we can mark the page
33758 ** as clean, since there will be no need to write it out to the.
 
33759 **
33760 ** There is one exception to this rule. If the page is being rolled
33761 ** back as part of a savepoint (or statement) rollback from an
33762 ** unsynced portion of the main journal file, then it is not safe
33763 ** to mark the page as clean. This is because marking the page as
@@ -34100,12 +34334,10 @@
34100 /* This loop terminates either when a readJournalHdr() or
34101 ** pager_playback_one_page() call returns SQLITE_DONE or an IO error
34102 ** occurs.
34103 */
34104 while( 1 ){
34105 int isUnsync = 0;
34106
34107 /* Read the next journal header from the journal file. If there are
34108 ** not enough bytes left in the journal file for a complete header, or
34109 ** it is corrupted, then a process must of failed while writing it.
34110 ** This indicates nothing more needs to be rolled back.
34111 */
@@ -34142,11 +34374,10 @@
34142 ** should be computed based on the journal file size.
34143 */
34144 if( nRec==0 && !isHot &&
34145 pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){
34146 nRec = (int)((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager));
34147 isUnsync = 1;
34148 }
34149
34150 /* If this is the first header read from the journal, truncate the
34151 ** database file back to its original size.
34152 */
@@ -34164,16 +34395,24 @@
34164 for(u=0; u<nRec; u++){
34165 if( needPagerReset ){
34166 pager_reset(pPager);
34167 needPagerReset = 0;
34168 }
34169 rc = pager_playback_one_page(pPager,1,isUnsync,&pPager->journalOff,0,0);
34170 if( rc!=SQLITE_OK ){
34171 if( rc==SQLITE_DONE ){
34172 rc = SQLITE_OK;
34173 pPager->journalOff = szJ;
34174 break;
 
 
 
 
 
 
 
 
34175 }else{
34176 /* If we are unable to rollback, quit and return the error
34177 ** code. This will cause the pager to enter the error state
34178 ** so that no further harm will be done. Perhaps the next
34179 ** process to come along will be able to rollback the database.
@@ -34309,11 +34548,11 @@
34309 */
34310 if( pSavepoint ){
34311 iHdrOff = pSavepoint->iHdrOffset ? pSavepoint->iHdrOffset : szJ;
34312 pPager->journalOff = pSavepoint->iOffset;
34313 while( rc==SQLITE_OK && pPager->journalOff<iHdrOff ){
34314 rc = pager_playback_one_page(pPager, 1, 0, &pPager->journalOff, 1, pDone);
34315 }
34316 assert( rc!=SQLITE_DONE );
34317 }else{
34318 pPager->journalOff = 0;
34319 }
@@ -34339,11 +34578,11 @@
34339 && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff
34340 ){
34341 nJRec = (u32)((szJ - pPager->journalOff)/JOURNAL_PG_SZ(pPager));
34342 }
34343 for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
34344 rc = pager_playback_one_page(pPager, 1, 0, &pPager->journalOff, 1, pDone);
34345 }
34346 assert( rc!=SQLITE_DONE );
34347 }
34348 assert( rc!=SQLITE_OK || pPager->journalOff==szJ );
34349
@@ -34354,11 +34593,11 @@
34354 if( pSavepoint ){
34355 u32 ii; /* Loop counter */
34356 i64 offset = pSavepoint->iSubRec*(4+pPager->pageSize);
34357 for(ii=pSavepoint->iSubRec; rc==SQLITE_OK && ii<pPager->nSubRec; ii++){
34358 assert( offset==ii*(4+pPager->pageSize) );
34359 rc = pager_playback_one_page(pPager, 0, 0, &offset, 1, pDone);
34360 }
34361 assert( rc!=SQLITE_DONE );
34362 }
34363
34364 sqlite3BitvecDestroy(pDone);
@@ -34575,14 +34814,16 @@
34575 ** maximum page count below the current size of the database.
34576 **
34577 ** Regardless of mxPage, return the current maximum page count.
34578 */
34579 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
 
34580 if( mxPage>0 ){
34581 pPager->mxPgno = mxPage;
34582 }
34583 sqlite3PagerPagecount(pPager, 0);
 
34584 return pPager->mxPgno;
34585 }
34586
34587 /*
34588 ** The following set of routines are used to disable the simulated
@@ -34652,15 +34893,10 @@
34652 ** and *pnPage is set to the number of pages in the database.
34653 */
34654 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
34655 Pgno nPage; /* Value to return via *pnPage */
34656
34657 /* If the pager is already in the error state, return the error code. */
34658 if( pPager->errCode ){
34659 return pPager->errCode;
34660 }
34661
34662 /* Determine the number of pages in the file. Store this in nPage. */
34663 if( pPager->dbSizeValid ){
34664 nPage = pPager->dbSize;
34665 }else{
34666 int rc; /* Error returned by OsFileSize() */
@@ -34690,13 +34926,11 @@
34690 if( nPage>pPager->mxPgno ){
34691 pPager->mxPgno = (Pgno)nPage;
34692 }
34693
34694 /* Set the output variable and return SQLITE_OK */
34695 if( pnPage ){
34696 *pnPage = nPage;
34697 }
34698 return SQLITE_OK;
34699 }
34700
34701
34702 /*
@@ -34796,10 +35030,35 @@
34796 assert( pPager->dbSize>=nPage );
34797 assert( pPager->state>=PAGER_RESERVED );
34798 pPager->dbSize = nPage;
34799 assertTruncateConstraint(pPager);
34800 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34801
34802 /*
34803 ** Shutdown the page cache. Free all memory and close all files.
34804 **
34805 ** If a transaction was in progress when this routine is called, that
@@ -34826,11 +35085,13 @@
34826 ** call which may be made from within pagerUnlockAndRollback(). If it
34827 ** is not -1, then the unsynced portion of an open journal file may
34828 ** be played back into the database. If a power failure occurs while
34829 ** this is happening, the database may become corrupt.
34830 */
34831 pPager->journalHdr = -1;
 
 
34832 pagerUnlockAndRollback(pPager);
34833 }
34834 sqlite3EndBenignMalloc();
34835 enable_simulated_io_errors();
34836 PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
@@ -34916,11 +35177,11 @@
34916 /* This block deals with an obscure problem. If the last connection
34917 ** that wrote to this database was operating in persistent-journal
34918 ** mode, then the journal file may at this point actually be larger
34919 ** than Pager.journalOff bytes. If the next thing in the journal
34920 ** file happens to be a journal-header (written as part of the
34921 ** previous connections transaction), and a crash or power-failure
34922 ** occurs after nRec is updated but before this connection writes
34923 ** anything else to the journal file (or commits/rolls back its
34924 ** transaction), then SQLite may become confused when doing the
34925 ** hot-journal rollback following recovery. It may roll back all
34926 ** of this connections data, then proceed to rolling back the old,
@@ -34988,10 +35249,11 @@
34988 /* The journal file was just successfully synced. Set Pager.needSync
34989 ** to zero and clear the PGHDR_NEED_SYNC flag on all pagess.
34990 */
34991 pPager->needSync = 0;
34992 pPager->journalStarted = 1;
 
34993 sqlite3PcacheClearSyncFlags(pPager->pPCache);
34994 }
34995
34996 return SQLITE_OK;
34997 }
@@ -35850,23 +36112,32 @@
35850 }
35851 if( rc!=SQLITE_OK ){
35852 goto failed;
35853 }
35854
35855 /* TODO: Why are these cleared here? Is it necessary? */
 
35856 pPager->journalStarted = 0;
35857 pPager->journalOff = 0;
35858 pPager->setMaster = 0;
35859 pPager->journalHdr = 0;
 
 
35860
35861 /* Playback and delete the journal. Drop the database write
35862 ** lock and reacquire the read lock. Purge the cache before
35863 ** playing back the hot-journal so that we don't end up with
35864 ** an inconsistent cache.
 
 
 
35865 */
35866 if( isOpen(pPager->jfd) ){
35867 rc = pager_playback(pPager, 1);
 
 
 
35868 if( rc!=SQLITE_OK ){
35869 rc = pager_error(pPager, rc);
35870 goto failed;
35871 }
35872 }
@@ -35890,20 +36161,20 @@
35890 **
35891 ** There is a vanishingly small chance that a change will not be
35892 ** detected. The chance of an undetected change is so small that
35893 ** it can be neglected.
35894 */
 
35895 char dbFileVers[sizeof(pPager->dbFileVers)];
35896 sqlite3PagerPagecount(pPager, 0);
35897
35898 if( pPager->errCode ){
35899 rc = pPager->errCode;
35900 goto failed;
35901 }
35902
35903 assert( pPager->dbSizeValid );
35904 if( pPager->dbSize>0 ){
35905 IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
35906 rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
35907 if( rc!=SQLITE_OK ){
35908 goto failed;
35909 }
@@ -35968,11 +36239,11 @@
35968 ** of the page. This occurs in two seperate scenarios:
35969 **
35970 ** a) When reading a free-list leaf page from the database, and
35971 **
35972 ** b) When a savepoint is being rolled back and we need to load
35973 ** a new page into the cache to populate with the data read
35974 ** from the savepoint journal.
35975 **
35976 ** If noContent is true, then the data returned is zeroed instead of
35977 ** being read from the database. Additionally, the bits corresponding
35978 ** to pgno in Pager.pInJournal (bitvec of pages already written to the
@@ -36024,11 +36295,11 @@
36024 goto pager_acquire_err;
36025 }
36026 assert( (*ppPage)->pgno==pgno );
36027 assert( (*ppPage)->pPager==pPager || (*ppPage)->pPager==0 );
36028
36029 if( (*ppPage)->pPager ){
36030 /* In this case the pcache already contains an initialized copy of
36031 ** the page. Return without further ado. */
36032 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
36033 PAGER_INCR(pPager->nHit);
36034 return SQLITE_OK;
@@ -36184,10 +36455,11 @@
36184 ** SQLITE_NOMEM if the attempt to allocate Pager.pInJournal fails, or
36185 ** an IO error code if opening or writing the journal file fails.
36186 */
36187 static int pager_open_journal(Pager *pPager){
36188 int rc = SQLITE_OK; /* Return code */
 
36189 sqlite3_vfs * const pVfs = pPager->pVfs; /* Local cache of vfs pointer */
36190
36191 assert( pPager->state>=PAGER_RESERVED );
36192 assert( pPager->useJournal );
36193 assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF );
@@ -36196,17 +36468,14 @@
36196 /* If already in the error state, this function is a no-op. But on
36197 ** the other hand, this routine is never called if we are already in
36198 ** an error state. */
36199 if( NEVER(pPager->errCode) ) return pPager->errCode;
36200
36201 /* TODO: Is it really possible to get here with dbSizeValid==0? If not,
36202 ** the call to PagerPagecount() can be removed.
36203 */
36204 testcase( pPager->dbSizeValid==0 );
36205 sqlite3PagerPagecount(pPager, 0);
36206
36207 pPager->pInJournal = sqlite3BitvecCreate(pPager->dbSize);
36208 if( pPager->pInJournal==0 ){
36209 return SQLITE_NOMEM;
36210 }
36211
36212 /* Open the journal file if it is not already open. */
@@ -36301,16 +36570,15 @@
36301 if( exFlag ){
36302 rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
36303 }
36304 }
36305
36306 /* If the required locks were successfully obtained, open the journal
36307 ** file and write the first journal-header to it.
 
 
36308 */
36309 if( rc==SQLITE_OK && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
36310 rc = pager_open_journal(pPager);
36311 }
36312 }else if( isOpen(pPager->jfd) && pPager->journalOff==0 ){
36313 /* This happens when the pager was in exclusive-access mode the last
36314 ** time a (read or write) transaction was successfully concluded
36315 ** by this connection. Instead of deleting the journal file it was
36316 ** kept open and either was truncated to 0 bytes or its header was
@@ -36321,11 +36589,10 @@
36321 assert( pPager->pInJournal==0 );
36322 rc = pager_open_journal(pPager);
36323 }
36324
36325 PAGERTRACE(("TRANSACTION %d\n", PAGERID(pPager)));
36326 assert( !isOpen(pPager->jfd) || pPager->journalOff>0 || rc!=SQLITE_OK );
36327 if( rc!=SQLITE_OK ){
36328 assert( !pPager->dbModified );
36329 /* Ignore any IO error that occurs within pager_end_transaction(). The
36330 ** purpose of this call is to reset the internal state of the pager
36331 ** sub-system. It doesn't matter if the journal-file is not properly
@@ -36351,12 +36618,12 @@
36351 /* This routine is not called unless a transaction has already been
36352 ** started.
36353 */
36354 assert( pPager->state>=PAGER_RESERVED );
36355
36356 /* If an error has been previously detected, we should not be
36357 ** calling this routine. Repeat the error for robustness.
36358 */
36359 if( NEVER(pPager->errCode) ) return pPager->errCode;
36360
36361 /* Higher-level routines never call this function if database is not
36362 ** writable. But check anyway, just for robustness. */
@@ -36377,15 +36644,15 @@
36377 /* If we get this far, it means that the page needs to be
36378 ** written to the transaction journal or the ckeckpoint journal
36379 ** or both.
36380 **
36381 ** Higher level routines should have already started a transaction,
36382 ** which means they have acquired the necessary locks and opened
36383 ** a rollback journal. Double-check to makes sure this is the case.
36384 */
36385 rc = sqlite3PagerBegin(pPager, 0, pPager->subjInMemory);
36386 if( NEVER(rc!=SQLITE_OK) ){
36387 return rc;
36388 }
36389 if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
36390 assert( pPager->useJournal );
36391 rc = pager_open_journal(pPager);
@@ -36404,10 +36671,12 @@
36404
36405 /* We should never write to the journal file the page that
36406 ** contains the database locks. The following assert verifies
36407 ** that we do not. */
36408 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
 
 
36409 CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
36410 cksum = pager_cksum(pPager, (u8*)pData2);
36411 rc = write32bits(pPager->jfd, pPager->journalOff, pPg->pgno);
36412 if( rc==SQLITE_OK ){
36413 rc = sqlite3OsWrite(pPager->jfd, pData2, pPager->pageSize,
@@ -36523,11 +36792,12 @@
36523 ** an integer power of 2. It sets variable pg1 to the identifier
36524 ** of the first page of the sector pPg is located on.
36525 */
36526 pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
36527
36528 sqlite3PagerPagecount(pPager, (int *)&nPageCount);
 
36529 if( pPg->pgno>nPageCount ){
36530 nPage = (pPg->pgno - pg1)+1;
36531 }else if( (pg1+nPagePerSector-1)>nPageCount ){
36532 nPage = nPageCount+1-pg1;
36533 }else{
@@ -36684,10 +36954,13 @@
36684 /* Increment the value just read and write it back to byte 24. */
36685 change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
36686 change_counter++;
36687 put32bits(((char*)pPgHdr->pData)+24, change_counter);
36688
 
 
 
36689 /* If running in direct mode, write the contents of page 1 to the file. */
36690 if( DIRECT_MODE ){
36691 const void *zBuf = pPgHdr->pData;
36692 assert( pPager->dbFileSize>0 );
36693 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
@@ -36757,13 +37030,11 @@
36757 int rc = SQLITE_OK; /* Return code */
36758
36759 /* The dbOrigSize is never set if journal_mode=OFF */
36760 assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF || pPager->dbOrigSize==0 );
36761
36762 /* If a prior error occurred, this routine should not be called. ROLLBACK
36763 ** is the appropriate response to an error, not COMMIT. Guard against
36764 ** coding errors by repeating the prior error. */
36765 if( NEVER(pPager->errCode) ) return pPager->errCode;
36766
36767 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
36768 pPager->zFilename, zMaster, pPager->dbSize));
36769
@@ -37048,10 +37319,20 @@
37048 ** Return the number of references to the pager.
37049 */
37050 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
37051 return sqlite3PcacheRefCount(pPager->pPCache);
37052 }
 
 
 
 
 
 
 
 
 
 
37053
37054 /*
37055 ** Return the number of references to the specified page.
37056 */
37057 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage *pPage){
@@ -37101,15 +37382,14 @@
37101 int nCurrent = pPager->nSavepoint; /* Current number of savepoints */
37102
37103 if( nSavepoint>nCurrent && pPager->useJournal ){
37104 int ii; /* Iterator variable */
37105 PagerSavepoint *aNew; /* New Pager.aSavepoint array */
 
37106
37107 /* Either there is no active journal or the sub-journal is open or
37108 ** the journal is always stored in memory */
37109 assert( pPager->nSavepoint==0 || isOpen(pPager->sjfd) ||
37110 pPager->journalMode==PAGER_JOURNALMODE_MEMORY );
37111
37112 /* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
37113 ** if the allocation fails. Otherwise, zero the new portion in case a
37114 ** malloc failure occurs while populating it in the for(...) loop below.
37115 */
@@ -37123,19 +37403,18 @@
37123 pPager->aSavepoint = aNew;
37124 pPager->nSavepoint = nSavepoint;
37125
37126 /* Populate the PagerSavepoint structures just allocated. */
37127 for(ii=nCurrent; ii<nSavepoint; ii++){
37128 assert( pPager->dbSizeValid );
37129 aNew[ii].nOrig = pPager->dbSize;
37130 if( isOpen(pPager->jfd) && ALWAYS(pPager->journalOff>0) ){
37131 aNew[ii].iOffset = pPager->journalOff;
37132 }else{
37133 aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
37134 }
37135 aNew[ii].iSubRec = pPager->nSubRec;
37136 aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
37137 if( !aNew[ii].pInSavepoint ){
37138 return SQLITE_NOMEM;
37139 }
37140 }
37141
@@ -37518,10 +37797,19 @@
37518 && (!isOpen(pPager->jfd) || 0==pPager->journalOff)
37519 ){
37520 if( isOpen(pPager->jfd) ){
37521 sqlite3OsClose(pPager->jfd);
37522 }
 
 
 
 
 
 
 
 
 
37523 pPager->journalMode = (u8)eMode;
37524 }
37525 return (int)pPager->journalMode;
37526 }
37527
@@ -37978,10 +38266,11 @@
37978 BtCursor *pCursor; /* A list of all open cursors */
37979 MemPage *pPage1; /* First page of the database */
37980 u8 readOnly; /* True if the underlying file is readonly */
37981 u8 pageSizeFixed; /* True if the page size can no longer be changed */
37982 u8 secureDelete; /* True if secure_delete is enabled */
 
37983 #ifndef SQLITE_OMIT_AUTOVACUUM
37984 u8 autoVacuum; /* True if auto-vacuum is enabled */
37985 u8 incrVacuum; /* True if incr-vacuum is enabled */
37986 #endif
37987 u16 pageSize; /* Total number of bytes on a page */
@@ -37990,10 +38279,11 @@
37990 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
37991 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
37992 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
37993 u8 inTransaction; /* Transaction state */
37994 int nTransaction; /* Number of open transactions (read + write) */
 
37995 void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
37996 void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */
37997 sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
37998 Bitvec *pHasContent; /* Set of pages moved to free-list this transaction */
37999 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -39070,15 +39360,12 @@
39070 ** at the end of every transaction.
39071 */
39072 static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
39073 int rc = SQLITE_OK;
39074 if( !pBt->pHasContent ){
39075 int nPage = 100;
39076 sqlite3PagerPagecount(pBt->pPager, &nPage);
39077 /* If sqlite3PagerPagecount() fails there is no harm because the
39078 ** nPage variable is unchanged from its default value of 100 */
39079 pBt->pHasContent = sqlite3BitvecCreate((u32)nPage);
39080 if( !pBt->pHasContent ){
39081 rc = SQLITE_NOMEM;
39082 }
39083 }
39084 if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
@@ -40117,17 +40404,17 @@
40117
40118 /*
40119 ** Return the size of the database file in pages. If there is any kind of
40120 ** error, return ((unsigned int)-1).
40121 */
40122 static Pgno pagerPagecount(BtShared *pBt){
40123 int nPage = -1;
40124 int rc;
40125 assert( pBt->pPage1 );
40126 rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40127 assert( rc==SQLITE_OK || nPage==-1 );
40128 return (Pgno)nPage;
40129 }
40130
40131 /*
40132 ** Get a page from the pager and initialize it. This routine is just a
40133 ** convenience wrapper around separate calls to btreeGetPage() and
@@ -40140,29 +40427,22 @@
40140 BtShared *pBt, /* The database file */
40141 Pgno pgno, /* Number of the page to get */
40142 MemPage **ppPage /* Write the page pointer here */
40143 ){
40144 int rc;
40145 TESTONLY( Pgno iLastPg = pagerPagecount(pBt); )
40146 assert( sqlite3_mutex_held(pBt->mutex) );
40147
 
 
 
40148 rc = btreeGetPage(pBt, pgno, ppPage, 0);
40149 if( rc==SQLITE_OK ){
40150 rc = btreeInitPage(*ppPage);
40151 if( rc!=SQLITE_OK ){
40152 releasePage(*ppPage);
40153 }
40154 }
40155
40156 /* If the requested page number was either 0 or greater than the page
40157 ** number of the last page in the database, this function should return
40158 ** SQLITE_CORRUPT or some other error (i.e. SQLITE_FULL). Check that this
40159 ** is the case. */
40160 assert( (pgno>0 && pgno<=iLastPg) || rc!=SQLITE_OK );
40161 testcase( pgno==0 );
40162 testcase( pgno==iLastPg );
40163
40164 return rc;
40165 }
40166
40167 /*
40168 ** Release a MemPage. This should be called once for each prior
@@ -40794,13 +41074,15 @@
40794 ** well-formed database file, then SQLITE_CORRUPT is returned.
40795 ** SQLITE_BUSY is returned if the database is locked. SQLITE_NOMEM
40796 ** is returned if we run out of memory.
40797 */
40798 static int lockBtree(BtShared *pBt){
40799 int rc;
40800 MemPage *pPage1;
40801 int nPage;
 
 
40802
40803 assert( sqlite3_mutex_held(pBt->mutex) );
40804 assert( pBt->pPage1==0 );
40805 rc = sqlite3PagerSharedLock(pBt->pPager);
40806 if( rc!=SQLITE_OK ) return rc;
@@ -40808,14 +41090,18 @@
40808 if( rc!=SQLITE_OK ) return rc;
40809
40810 /* Do some checking to help insure the file we opened really is
40811 ** a valid database file.
40812 */
40813 rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40814 if( rc!=SQLITE_OK ){
40815 goto page1_init_failed;
40816 }else if( nPage>0 ){
 
 
 
 
40817 int pageSize;
40818 int usableSize;
40819 u8 *page1 = pPage1->aData;
40820 rc = SQLITE_NOTADB;
40821 if( memcmp(page1, zMagicHeader, 16)!=0 ){
@@ -40857,10 +41143,14 @@
40857 freeTempSpace(pBt);
40858 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
40859 pageSize-usableSize);
40860 return rc;
40861 }
 
 
 
 
40862 if( usableSize<480 ){
40863 goto page1_init_failed;
40864 }
40865 pBt->pageSize = (u16)pageSize;
40866 pBt->usableSize = (u16)usableSize;
@@ -40887,10 +41177,11 @@
40887 pBt->minLocal = (pBt->usableSize-12)*32/255 - 23;
40888 pBt->maxLeaf = pBt->usableSize - 35;
40889 pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23;
40890 assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
40891 pBt->pPage1 = pPage1;
 
40892 return SQLITE_OK;
40893
40894 page1_init_failed:
40895 releasePage(pPage1);
40896 pBt->pPage1 = 0;
@@ -40924,16 +41215,14 @@
40924 */
40925 static int newDatabase(BtShared *pBt){
40926 MemPage *pP1;
40927 unsigned char *data;
40928 int rc;
40929 int nPage;
40930
40931 assert( sqlite3_mutex_held(pBt->mutex) );
40932 rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40933 if( rc!=SQLITE_OK || nPage>0 ){
40934 return rc;
40935 }
40936 pP1 = pBt->pPage1;
40937 assert( pP1!=0 );
40938 data = pP1->aData;
40939 rc = sqlite3PagerWrite(pP1->pDbPage);
@@ -40955,10 +41244,12 @@
40955 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
40956 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
40957 put4byte(&data[36 + 4*4], pBt->autoVacuum);
40958 put4byte(&data[36 + 7*4], pBt->incrVacuum);
40959 #endif
 
 
40960 return SQLITE_OK;
40961 }
40962
40963 /*
40964 ** Attempt to start a new transaction. A write-transaction
@@ -41044,10 +41335,11 @@
41044 ** page 1. So if some other shared-cache client already has a write-lock
41045 ** on page 1, the transaction cannot be opened. */
41046 rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
41047 if( SQLITE_OK!=rc ) goto trans_begun;
41048
 
41049 do {
41050 /* Call lockBtree() until either pBt->pPage1 is populated or
41051 ** lockBtree() returns something other than SQLITE_OK. lockBtree()
41052 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
41053 ** reading page 1 it discovers that the page-size of the database
@@ -41323,16 +41615,16 @@
41323 ** which may or may not empty the freelist. A full autovacuum
41324 ** has nFin>0. A "PRAGMA incremental_vacuum" has nFin==0.
41325 */
41326 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg){
41327 Pgno nFreeList; /* Number of pages still on the free-list */
 
41328
41329 assert( sqlite3_mutex_held(pBt->mutex) );
41330 assert( iLastPg>nFin );
41331
41332 if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
41333 int rc;
41334 u8 eType;
41335 Pgno iPtrPage;
41336
41337 nFreeList = get4byte(&pBt->pPage1->aData[36]);
41338 if( nFreeList==0 ){
@@ -41404,11 +41696,11 @@
41404 if( nFin==0 ){
41405 iLastPg--;
41406 while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
41407 if( PTRMAP_ISPAGE(pBt, iLastPg) ){
41408 MemPage *pPg;
41409 int rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
41410 if( rc!=SQLITE_OK ){
41411 return rc;
41412 }
41413 rc = sqlite3PagerWrite(pPg->pDbPage);
41414 releasePage(pPg);
@@ -41417,10 +41709,11 @@
41417 }
41418 }
41419 iLastPg--;
41420 }
41421 sqlite3PagerTruncateImage(pBt->pPager, iLastPg);
 
41422 }
41423 return SQLITE_OK;
41424 }
41425
41426 /*
@@ -41439,11 +41732,15 @@
41439 assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
41440 if( !pBt->autoVacuum ){
41441 rc = SQLITE_DONE;
41442 }else{
41443 invalidateAllOverflowCache(pBt);
41444 rc = incrVacuumStep(pBt, 0, pagerPagecount(pBt));
 
 
 
 
41445 }
41446 sqlite3BtreeLeave(p);
41447 return rc;
41448 }
41449
@@ -41470,11 +41767,11 @@
41470 Pgno nPtrmap; /* Number of PtrMap pages to be freed */
41471 Pgno iFree; /* The next page to be freed */
41472 int nEntry; /* Number of entries on one ptrmap page */
41473 Pgno nOrig; /* Database size before freeing */
41474
41475 nOrig = pagerPagecount(pBt);
41476 if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
41477 /* It is not possible to create a database for which the final page
41478 ** is either a pointer-map page or the pending-byte page. If one
41479 ** is encountered, this indicates corruption.
41480 */
@@ -41495,15 +41792,16 @@
41495
41496 for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
41497 rc = incrVacuumStep(pBt, nFin, iFree);
41498 }
41499 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
41500 rc = SQLITE_OK;
41501 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
41502 put4byte(&pBt->pPage1->aData[32], 0);
41503 put4byte(&pBt->pPage1->aData[36], 0);
 
41504 sqlite3PagerTruncateImage(pBt->pPager, nFin);
 
41505 }
41506 if( rc!=SQLITE_OK ){
41507 sqlite3PagerRollback(pPager);
41508 }
41509 }
@@ -41749,10 +42047,15 @@
41749
41750 /* The rollback may have destroyed the pPage1->aData value. So
41751 ** call btreeGetPage() on page 1 again to make
41752 ** sure pPage1->aData is set correctly. */
41753 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
 
 
 
 
 
41754 releasePage(pPage1);
41755 }
41756 assert( countWriteCursors(pBt)==0 );
41757 pBt->inTransaction = TRANS_READ;
41758 }
@@ -41786,21 +42089,17 @@
41786 sqlite3BtreeEnter(p);
41787 assert( p->inTrans==TRANS_WRITE );
41788 assert( pBt->readOnly==0 );
41789 assert( iStatement>0 );
41790 assert( iStatement>p->db->nSavepoint );
41791 if( NEVER(p->inTrans!=TRANS_WRITE || pBt->readOnly) ){
41792 rc = SQLITE_INTERNAL;
41793 }else{
41794 assert( pBt->inTransaction==TRANS_WRITE );
41795 /* At the pager level, a statement transaction is a savepoint with
41796 ** an index greater than all savepoints created explicitly using
41797 ** SQL statements. It is illegal to open, release or rollback any
41798 ** such savepoints while the statement transaction savepoint is active.
41799 */
41800 rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
41801 }
41802 sqlite3BtreeLeave(p);
41803 return rc;
41804 }
41805
41806 /*
@@ -41822,11 +42121,16 @@
41822 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
41823 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
41824 sqlite3BtreeEnter(p);
41825 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
41826 if( rc==SQLITE_OK ){
 
41827 rc = newDatabase(pBt);
 
 
 
 
41828 }
41829 sqlite3BtreeLeave(p);
41830 }
41831 return rc;
41832 }
@@ -41888,11 +42192,11 @@
41888 assert( pBt->pPage1 && pBt->pPage1->aData );
41889
41890 if( NEVER(wrFlag && pBt->readOnly) ){
41891 return SQLITE_READONLY;
41892 }
41893 if( iTable==1 && pagerPagecount(pBt)==0 ){
41894 return SQLITE_EMPTY;
41895 }
41896
41897 /* Now that no other errors can occur, finish filling in the BtCursor
41898 ** variables and link the cursor into the BtShared list. */
@@ -42159,11 +42463,11 @@
42159
42160 while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){
42161 iGuess++;
42162 }
42163
42164 if( iGuess<=pagerPagecount(pBt) ){
42165 rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
42166 if( rc==SQLITE_OK && eType==PTRMAP_OVERFLOW2 && pgno==ovfl ){
42167 next = iGuess;
42168 rc = SQLITE_DONE;
42169 }
@@ -43191,11 +43495,11 @@
43191 MemPage *pPrevTrunk = 0;
43192 Pgno mxPage; /* Total size of the database file */
43193
43194 assert( sqlite3_mutex_held(pBt->mutex) );
43195 pPage1 = pBt->pPage1;
43196 mxPage = pagerPagecount(pBt);
43197 n = get4byte(&pPage1->aData[36]);
43198 testcase( n==mxPage-1 );
43199 if( n>=mxPage ){
43200 return SQLITE_CORRUPT_BKPT;
43201 }
@@ -43387,39 +43691,39 @@
43387 pPrevTrunk = 0;
43388 }while( searchList );
43389 }else{
43390 /* There are no pages on the freelist, so create a new page at the
43391 ** end of the file */
43392 int nPage = pagerPagecount(pBt);
43393 *pPgno = nPage + 1;
43394
43395 if( *pPgno==PENDING_BYTE_PAGE(pBt) ){
43396 (*pPgno)++;
43397 }
43398
43399 #ifndef SQLITE_OMIT_AUTOVACUUM
43400 if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
43401 /* If *pPgno refers to a pointer-map page, allocate two new pages
43402 ** at the end of the file instead of one. The first allocated page
43403 ** becomes a new pointer-map page, the second is used by the caller.
43404 */
43405 MemPage *pPg = 0;
43406 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
43407 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43408 rc = btreeGetPage(pBt, *pPgno, &pPg, 0);
43409 if( rc==SQLITE_OK ){
43410 rc = sqlite3PagerWrite(pPg->pDbPage);
43411 releasePage(pPg);
43412 }
43413 if( rc ) return rc;
43414 (*pPgno)++;
43415 if( *pPgno==PENDING_BYTE_PAGE(pBt) ){ (*pPgno)++; }
43416 }
43417 #endif
 
 
43418
43419 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43420 rc = btreeGetPage(pBt, *pPgno, ppPage, 0);
43421 if( rc ) return rc;
43422 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
43423 if( rc!=SQLITE_OK ){
43424 releasePage(*ppPage);
43425 }
@@ -43605,11 +43909,11 @@
43605 nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
43606 assert( ovflPgno==0 || nOvfl>0 );
43607 while( nOvfl-- ){
43608 Pgno iNext = 0;
43609 MemPage *pOvfl = 0;
43610 if( ovflPgno<2 || ovflPgno>pagerPagecount(pBt) ){
43611 /* 0 is not a legal page number and page 1 cannot be an
43612 ** overflow page. Therefore if ovflPgno<2 or past the end of the
43613 ** file the database must be corrupt. */
43614 return SQLITE_CORRUPT_BKPT;
43615 }
@@ -45437,12 +45741,18 @@
45437 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
45438 if( rc ){
45439 releasePage(pRoot);
45440 return rc;
45441 }
 
 
 
 
 
 
45442 rc = sqlite3BtreeUpdateMeta(p, 4, pgnoRoot);
45443 if( rc ){
45444 releasePage(pRoot);
45445 return rc;
45446 }
45447
45448 }else{
@@ -45478,11 +45788,11 @@
45478 int rc;
45479 unsigned char *pCell;
45480 int i;
45481
45482 assert( sqlite3_mutex_held(pBt->mutex) );
45483 if( pgno>pagerPagecount(pBt) ){
45484 return SQLITE_CORRUPT_BKPT;
45485 }
45486
45487 rc = getAndInitPage(pBt, pgno, &pPage);
45488 if( rc ) return rc;
@@ -46229,11 +46539,11 @@
46229 sqlite3BtreeEnter(p);
46230 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
46231 nRef = sqlite3PagerRefcount(pBt->pPager);
46232 sCheck.pBt = pBt;
46233 sCheck.pPager = pBt->pPager;
46234 sCheck.nPage = pagerPagecount(sCheck.pBt);
46235 sCheck.mxErr = mxErr;
46236 sCheck.nErr = 0;
46237 sCheck.mallocFailed = 0;
46238 *pnErr = 0;
46239 if( sCheck.nPage==0 ){
@@ -46831,13 +47141,12 @@
46831 }
46832
46833 /* Now that there is a read-lock on the source database, query the
46834 ** source pager for the number of pages in the database.
46835 */
46836 if( rc==SQLITE_OK ){
46837 rc = sqlite3PagerPagecount(pSrcPager, &nSrcPage);
46838 }
46839 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
46840 const Pgno iSrcPg = p->iNext; /* Source page number */
46841 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
46842 DbPage *pSrcPg; /* Source page object */
46843 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
@@ -48986,11 +49295,11 @@
48986 nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
48987 pKeyInfo = sqlite3Malloc( nByte );
48988 pOp->p4.pKeyInfo = pKeyInfo;
48989 if( pKeyInfo ){
48990 u8 *aSortOrder;
48991 memcpy(pKeyInfo, zP4, nByte);
48992 aSortOrder = pKeyInfo->aSortOrder;
48993 if( aSortOrder ){
48994 pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
48995 memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
48996 }
@@ -53812,18 +54121,13 @@
53812 int i;
53813 sqlite_int64 rowid;
53814 Mem **apArg;
53815 Mem *pX;
53816 } ck;
53817 struct OP_Pagecount_stack_vars {
53818 int p1;
53819 int nPage;
53820 Pager *pPager;
53821 } cl;
53822 struct OP_Trace_stack_vars {
53823 char *zTrace;
53824 } cm;
53825 } u;
53826 /* End automatically generated code
53827 ********************************************************************/
53828
53829 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
@@ -54646,11 +54950,11 @@
54646 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ag.n );
54647 u.ag.pArg = &aMem[pOp->p2];
54648 for(u.ag.i=0; u.ag.i<u.ag.n; u.ag.i++, u.ag.pArg++){
54649 u.ag.apVal[u.ag.i] = u.ag.pArg;
54650 sqlite3VdbeMemStoreType(u.ag.pArg);
54651 REGISTER_TRACE(pOp->p2, u.ag.pArg);
54652 }
54653
54654 assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
54655 if( pOp->p4type==P4_FUNCDEF ){
54656 u.ag.ctx.pFunc = pOp->p4.pFunc;
@@ -56363,14 +56667,14 @@
56363
56364 /* Opcode: OpenEphemeral P1 P2 * P4 *
56365 **
56366 ** Open a new cursor P1 to a transient table.
56367 ** The cursor is always opened read/write even if
56368 ** the main database is read-only. The transient or virtual
56369 ** table is deleted automatically when the cursor is closed.
56370 **
56371 ** P2 is the number of columns in the virtual table.
56372 ** The cursor points to a BTree table if P4==0 and to a BTree index
56373 ** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
56374 ** that defines the format of keys in the index.
56375 **
56376 ** This opcode was once called OpenTemp. But that created
@@ -56377,10 +56681,18 @@
56377 ** confusion because the term "temp table", might refer either
56378 ** to a TEMP table at the SQL level, or to a table opened by
56379 ** this opcode. Then this opcode was call OpenVirtual. But
56380 ** that created confusion with the whole virtual-table idea.
56381 */
 
 
 
 
 
 
 
 
56382 case OP_OpenEphemeral: {
56383 #if 0 /* local variables moved into u.ax */
56384 VdbeCursor *pCx;
56385 #endif /* local variables moved into u.ax */
56386 static const int openFlags =
@@ -57515,29 +57827,35 @@
57515 pc = pOp->p2 - 1;
57516 }
57517 break;
57518 }
57519
57520 /* Opcode: Next P1 P2 * * *
57521 **
57522 ** Advance cursor P1 so that it points to the next key/data pair in its
57523 ** table or index. If there are no more key/value pairs then fall through
57524 ** to the following instruction. But if the cursor advance was successful,
57525 ** jump immediately to P2.
57526 **
57527 ** The P1 cursor must be for a real table, not a pseudo-table.
57528 **
 
 
 
57529 ** See also: Prev
57530 */
57531 /* Opcode: Prev P1 P2 * * *
57532 **
57533 ** Back up cursor P1 so that it points to the previous key/data pair in its
57534 ** table or index. If there is no previous key/value pairs then fall through
57535 ** to the following instruction. But if the cursor backup was successful,
57536 ** jump immediately to P2.
57537 **
57538 ** The P1 cursor must be for a real table, not a pseudo-table.
 
 
 
57539 */
57540 case OP_Prev: /* jump */
57541 case OP_Next: { /* jump */
57542 #if 0 /* local variables moved into u.bm */
57543 VdbeCursor *pC;
@@ -57545,10 +57863,11 @@
57545 int res;
57546 #endif /* local variables moved into u.bm */
57547
57548 CHECK_FOR_INTERRUPT;
57549 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 
57550 u.bm.pC = p->apCsr[pOp->p1];
57551 if( u.bm.pC==0 ){
57552 break; /* See ticket #2273 */
57553 }
57554 u.bm.pCrsr = u.bm.pC->pCursor;
@@ -58991,25 +59310,11 @@
58991 /* Opcode: Pagecount P1 P2 * * *
58992 **
58993 ** Write the current number of pages in database P1 to memory cell P2.
58994 */
58995 case OP_Pagecount: { /* out2-prerelease */
58996 #if 0 /* local variables moved into u.cl */
58997 int p1;
58998 int nPage;
58999 Pager *pPager;
59000 #endif /* local variables moved into u.cl */
59001
59002 u.cl.p1 = pOp->p1;
59003 u.cl.pPager = sqlite3BtreePager(db->aDb[u.cl.p1].pBt);
59004 rc = sqlite3PagerPagecount(u.cl.pPager, &u.cl.nPage);
59005 /* OP_Pagecount is always called from within a read transaction. The
59006 ** page count has already been successfully read and cached. So the
59007 ** sqlite3PagerPagecount() call above cannot fail. */
59008 if( ALWAYS(rc==SQLITE_OK) ){
59009 pOut->u.i = u.cl.nPage;
59010 }
59011 break;
59012 }
59013 #endif
59014
59015 #ifndef SQLITE_OMIT_TRACE
@@ -59017,24 +59322,24 @@
59017 **
59018 ** If tracing is enabled (by the sqlite3_trace()) interface, then
59019 ** the UTF-8 string contained in P4 is emitted on the trace callback.
59020 */
59021 case OP_Trace: {
59022 #if 0 /* local variables moved into u.cm */
59023 char *zTrace;
59024 #endif /* local variables moved into u.cm */
59025
59026 u.cm.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
59027 if( u.cm.zTrace ){
59028 if( db->xTrace ){
59029 char *z = sqlite3VdbeExpandSql(p, u.cm.zTrace);
59030 db->xTrace(db->pTraceArg, z);
59031 sqlite3DbFree(db, z);
59032 }
59033 #ifdef SQLITE_DEBUG
59034 if( (db->flags & SQLITE_SqlTrace)!=0 ){
59035 sqlite3DebugPrintf("SQL-trace: %s\n", u.cm.zTrace);
59036 }
59037 #endif /* SQLITE_DEBUG */
59038 }
59039 break;
59040 }
@@ -59973,15 +60278,14 @@
59973 ** Syncing an in-memory journal is a no-op. And, in fact, this routine
59974 ** is never called in a working implementation. This implementation
59975 ** exists purely as a contingency, in case some malfunction in some other
59976 ** part of SQLite causes Sync to be called by mistake.
59977 */
59978 static int memjrnlSync(sqlite3_file *NotUsed, int NotUsed2){ /*NO_TEST*/
59979 UNUSED_PARAMETER2(NotUsed, NotUsed2); /*NO_TEST*/
59980 assert( 0 ); /*NO_TEST*/
59981 return SQLITE_OK; /*NO_TEST*/
59982 } /*NO_TEST*/
59983
59984 /*
59985 ** Query the size of the file in bytes.
59986 */
59987 static int memjrnlFileSize(sqlite3_file *pJfd, sqlite_int64 *pSize){
@@ -60573,11 +60877,11 @@
60573 }
60574 }
60575
60576 /*
60577 ** Allocate and return a pointer to an expression to load the column iCol
60578 ** from datasource iSrc datasource in SrcList pSrc.
60579 */
60580 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
60581 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
60582 if( p ){
60583 struct SrcList_item *pItem = &pSrc->a[iSrc];
@@ -60585,10 +60889,12 @@
60585 p->iTable = pItem->iCursor;
60586 if( p->pTab->iPKey==iCol ){
60587 p->iColumn = -1;
60588 }else{
60589 p->iColumn = (ynVar)iCol;
 
 
60590 pItem->colUsed |= ((Bitmask)1)<<(iCol>=BMS ? BMS-1 : iCol);
60591 }
60592 ExprSetProperty(p, EP_Resolved);
60593 }
60594 return p;
@@ -66537,16 +66843,20 @@
66537 int n = sqlite3_column_bytes(pStmt, 2);
66538 if( n>24 ){
66539 n = 24;
66540 }
66541 pSample->nByte = (u8)n;
66542 pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
66543 if( pSample->u.z ){
66544 memcpy(pSample->u.z, z, n);
66545 }else{
66546 db->mallocFailed = 1;
66547 break;
 
 
 
 
 
66548 }
66549 }
66550 }
66551 }
66552 }
@@ -75790,11 +76100,11 @@
75790 }else{
75791 for(j=0; j<pColumn->nId; j++){
75792 if( pColumn->a[j].idx==i ) break;
75793 }
75794 }
75795 if( pColumn && j>=pColumn->nId ){
75796 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1);
75797 }else if( useTempTable ){
75798 sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1);
75799 }else{
75800 assert( pSelect==0 ); /* Otherwise useTempTable is true */
@@ -78086,10 +78396,13 @@
78086 { "count_changes", SQLITE_CountRows },
78087 { "empty_result_callbacks", SQLITE_NullCallback },
78088 { "legacy_file_format", SQLITE_LegacyFileFmt },
78089 { "fullfsync", SQLITE_FullFSync },
78090 { "reverse_unordered_selects", SQLITE_ReverseOrder },
 
 
 
78091 #ifdef SQLITE_DEBUG
78092 { "sql_trace", SQLITE_SqlTrace },
78093 { "vdbe_listing", SQLITE_VdbeListing },
78094 { "vdbe_trace", SQLITE_VdbeTrace },
78095 #endif
@@ -79461,32 +79774,32 @@
79461 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
79462 ** But because db->init.busy is set to 1, no VDBE code is generated
79463 ** or executed. All the parser does is build the internal data
79464 ** structures that describe the table, index, or view.
79465 */
79466 char *zErr;
79467 int rc;
 
 
79468 assert( db->init.busy );
79469 db->init.iDb = iDb;
79470 db->init.newTnum = atoi(argv[1]);
79471 db->init.orphanTrigger = 0;
79472 rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
79473 db->init.iDb = 0;
79474 assert( rc!=SQLITE_OK || zErr==0 );
79475 if( SQLITE_OK!=rc ){
79476 if( db->init.orphanTrigger ){
79477 assert( iDb==1 );
79478 }else{
79479 pData->rc = rc;
79480 if( rc==SQLITE_NOMEM ){
79481 db->mallocFailed = 1;
79482 }else if( rc!=SQLITE_INTERRUPT && rc!=SQLITE_LOCKED ){
79483 corruptSchema(pData, argv[0], zErr);
79484 }
79485 }
79486 sqlite3DbFree(db, zErr);
79487 }
 
79488 }else if( argv[0]==0 ){
79489 corruptSchema(pData, 0, 0);
79490 }else{
79491 /* If the SQL column is blank it means this is an index that
79492 ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
@@ -79967,10 +80280,11 @@
79967 }
79968
79969 sqlite3VtabUnlockList(db);
79970
79971 pParse->db = db;
 
79972 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
79973 char *zSqlCopy;
79974 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
79975 testcase( nBytes==mxLen );
79976 testcase( nBytes==mxLen+1 );
@@ -79988,10 +80302,11 @@
79988 pParse->zTail = &zSql[nBytes];
79989 }
79990 }else{
79991 sqlite3RunParser(pParse, zSql, &zErrMsg);
79992 }
 
79993
79994 if( db->mallocFailed ){
79995 pParse->rc = SQLITE_NOMEM;
79996 }
79997 if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
@@ -82772,12 +83087,12 @@
82772 ** (13) The subquery and outer query do not both use LIMIT
82773 **
82774 ** (14) The subquery does not use OFFSET
82775 **
82776 ** (15) The outer query is not part of a compound select or the
82777 ** subquery does not have both an ORDER BY and a LIMIT clause.
82778 ** (See ticket #2339)
82779 **
82780 ** (16) The outer query is not an aggregate or the subquery does
82781 ** not contain ORDER BY. (Ticket #2942) This used to not matter
82782 ** until we introduced the group_concat() function.
82783 **
@@ -82856,11 +83171,11 @@
82856 ** because they could be computed at compile-time. But when LIMIT and OFFSET
82857 ** became arbitrary expressions, we were forced to add restrictions (13)
82858 ** and (14). */
82859 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
82860 if( pSub->pOffset ) return 0; /* Restriction (14) */
82861 if( p->pRightmost && pSub->pLimit && pSub->pOrderBy ){
82862 return 0; /* Restriction (15) */
82863 }
82864 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
82865 if( ((pSub->selFlags & SF_Distinct)!=0 || pSub->pLimit)
82866 && (pSrc->nSrc>1 || isAgg) ){ /* Restrictions (4)(5)(8)(9) */
@@ -83744,10 +84059,22 @@
83744 if( addrNext ){
83745 sqlite3VdbeResolveLabel(v, addrNext);
83746 sqlite3ExprCacheClear(pParse);
83747 }
83748 }
 
 
 
 
 
 
 
 
 
 
 
 
83749 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
83750 sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
83751 }
83752 pAggInfo->directMode = 0;
83753 sqlite3ExprCacheClear(pParse);
@@ -85557,10 +85884,11 @@
85557 pSubParse->db = db;
85558 pSubParse->pTriggerTab = pTab;
85559 pSubParse->pToplevel = pTop;
85560 pSubParse->zAuthContext = pTrigger->zName;
85561 pSubParse->eTriggerOp = pTrigger->op;
 
85562
85563 v = sqlite3GetVdbe(pSubParse);
85564 if( v ){
85565 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
85566 pTrigger->zName, onErrorText(orconf),
@@ -87477,10 +87805,11 @@
87477 if( pParse==0 ){
87478 rc = SQLITE_NOMEM;
87479 }else{
87480 pParse->declareVtab = 1;
87481 pParse->db = db;
 
87482
87483 if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
87484 && pParse->pNewTable
87485 && !db->mallocFailed
87486 && !pParse->pNewTable->pSelect
@@ -87997,19 +88326,21 @@
87997 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */
87998 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
87999 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
88000 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
88001 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
 
88002 #define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */
88003 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
88004 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
88005 #define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
88006 #define WHERE_ORDERBY 0x01000000 /* Output will appear in correct order */
88007 #define WHERE_REVERSE 0x02000000 /* Scan in reverse order */
88008 #define WHERE_UNIQUE 0x04000000 /* Selects no more than one row */
88009 #define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
88010 #define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
 
88011
88012 /*
88013 ** Initialize a preallocated WhereClause structure.
88014 */
88015 static void whereClauseInit(
@@ -89334,10 +89665,15 @@
89334 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
89335 const int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
89336 const Bitmask maskSrc = getMask(pWC->pMaskSet, iCur); /* Bitmask for pSrc */
89337 WhereTerm * const pWCEnd = &pWC->a[pWC->nTerm]; /* End of pWC->a[] */
89338 WhereTerm *pTerm; /* A single term of the WHERE clause */
 
 
 
 
 
89339
89340 /* Search the WHERE clause terms for a usable WO_OR term. */
89341 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89342 if( pTerm->eOperator==WO_OR
89343 && ((pTerm->prereqAll & ~maskSrc) & notReady)==0
@@ -89377,12 +89713,13 @@
89377 }
89378
89379 /* If there is an ORDER BY clause, increase the scan cost to account
89380 ** for the cost of the sort. */
89381 if( pOrderBy!=0 ){
 
 
89382 rTotal += nRow*estLog(nRow);
89383 WHERETRACE(("... sorting increases OR cost to %.9g\n", rTotal));
89384 }
89385
89386 /* If the cost of scanning using this OR term for optimization is
89387 ** less than the current cost stored in pCost, replace the contents
89388 ** of pCost. */
@@ -89397,10 +89734,251 @@
89397 }
89398 }
89399 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
89400 }
89401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89402 #ifndef SQLITE_OMIT_VIRTUALTABLE
89403 /*
89404 ** Allocate and populate an sqlite3_index_info structure. It is the
89405 ** responsibility of the caller to eventually release the structure
89406 ** by passing the pointer returned by this function to sqlite3_free().
@@ -89581,10 +90159,11 @@
89581 struct sqlite3_index_constraint *pIdxCons;
89582 struct sqlite3_index_constraint_usage *pUsage;
89583 WhereTerm *pTerm;
89584 int i, j;
89585 int nOrderBy;
 
89586
89587 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the
89588 ** malloc in allocateIndexInfo() fails and this function returns leaving
89589 ** wsFlags in an uninitialized state, the caller may behave unpredictably.
89590 */
@@ -89666,22 +90245,31 @@
89666 for(i=0; i<pIdxInfo->nConstraint; i++){
89667 if( pUsage[i].argvIndex>0 ){
89668 pCost->used |= pWC->a[pIdxCons[i].iTermOffset].prereqRight;
89669 }
89670 }
 
 
 
 
 
 
 
 
 
89671
89672 /* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
89673 ** inital value of lowestCost in this loop. If it is, then the
89674 ** (cost<lowestCost) test below will never be true.
89675 **
89676 ** Use "(double)2" instead of "2.0" in case OMIT_FLOATING_POINT
89677 ** is defined.
89678 */
89679 if( (SQLITE_BIG_DBL/((double)2))<pIdxInfo->estimatedCost ){
89680 pCost->rCost = (SQLITE_BIG_DBL/((double)2));
89681 }else{
89682 pCost->rCost = pIdxInfo->estimatedCost;
89683 }
89684 pCost->plan.u.pVtabIdx = pIdxInfo;
89685 if( pIdxInfo->orderByConsumed ){
89686 pCost->plan.wsFlags |= WHERE_ORDERBY;
89687 }
@@ -90078,18 +90666,18 @@
90078 **
90079 ** bInEst:
90080 ** Set to true if there was at least one "x IN (SELECT ...)" term used
90081 ** in determining the value of nInMul.
90082 **
90083 ** nBound:
90084 ** An estimate on the amount of the table that must be searched. A
90085 ** value of 100 means the entire table is searched. Range constraints
90086 ** might reduce this to a value less than 100 to indicate that only
90087 ** a fraction of the table needs searching. In the absence of
90088 ** sqlite_stat2 ANALYZE data, a single inequality reduces the search
90089 ** space to 1/3rd its original size. So an x>? constraint reduces
90090 ** nBound to 33. Two constraints (x>? AND x<?) reduce nBound to 11.
90091 **
90092 ** bSort:
90093 ** Boolean. True if there is an ORDER BY clause that will require an
90094 ** external sort (i.e. scanning the index being evaluated will not
90095 ** correctly order records).
@@ -90107,17 +90695,18 @@
90107 ** SELECT a, b, c FROM tbl WHERE a = 1;
90108 */
90109 int nEq;
90110 int bInEst = 0;
90111 int nInMul = 1;
90112 int nBound = 100;
 
90113 int bSort = 0;
90114 int bLookup = 0;
 
90115
90116 /* Determine the values of nEq and nInMul */
90117 for(nEq=0; nEq<pProbe->nColumn; nEq++){
90118 WhereTerm *pTerm; /* A single term of the WHERE clause */
90119 int j = pProbe->aiColumn[nEq];
90120 pTerm = findTerm(pWC, iCur, j, notReady, eqTermMask, pIdx);
90121 if( pTerm==0 ) break;
90122 wsFlags |= (WHERE_COLUMN_EQ|WHERE_ROWID_EQ);
90123 if( pTerm->eOperator & WO_IN ){
@@ -90133,22 +90722,24 @@
90133 wsFlags |= WHERE_COLUMN_NULL;
90134 }
90135 used |= pTerm->prereqRight;
90136 }
90137
90138 /* Determine the value of nBound. */
90139 if( nEq<pProbe->nColumn ){
90140 int j = pProbe->aiColumn[nEq];
90141 if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pIdx) ){
90142 WhereTerm *pTop = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pIdx);
90143 WhereTerm *pBtm = findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pIdx);
90144 whereRangeScanEst(pParse, pProbe, nEq, pBtm, pTop, &nBound);
90145 if( pTop ){
 
90146 wsFlags |= WHERE_TOP_LIMIT;
90147 used |= pTop->prereqRight;
90148 }
90149 if( pBtm ){
 
90150 wsFlags |= WHERE_BTM_LIMIT;
90151 used |= pBtm->prereqRight;
90152 }
90153 wsFlags |= (WHERE_COLUMN_RANGE|WHERE_ROWID_RANGE);
90154 }
@@ -90175,11 +90766,11 @@
90175 }
90176 }
90177
90178 /* If currently calculating the cost of using an index (not the IPK
90179 ** index), determine if all required column data may be obtained without
90180 ** seeking to entries in the main table (i.e. if the index is a covering
90181 ** index for this query). If it is, set the WHERE_IDX_ONLY flag in
90182 ** wsFlags. Otherwise, set the bLookup variable to true. */
90183 if( pIdx && wsFlags ){
90184 Bitmask m = pSrc->colUsed;
90185 int j;
@@ -90194,12 +90785,11 @@
90194 }else{
90195 bLookup = 1;
90196 }
90197 }
90198
90199 /**** Begin adding up the cost of using this index (Needs improvements)
90200 **
90201 ** Estimate the number of rows of output. For an IN operator,
90202 ** do not let the estimate exceed half the rows in the table.
90203 */
90204 nRow = (double)(aiRowEst[nEq] * nInMul);
90205 if( bInEst && nRow*2>aiRowEst[0] ){
@@ -90214,12 +90804,12 @@
90214 cost = nRow + nInMul*estLog(aiRowEst[0]);
90215
90216 /* Adjust the number of rows and the cost downward to reflect rows
90217 ** that are excluded by range constraints.
90218 */
90219 nRow = (nRow * (double)nBound) / (double)100;
90220 cost = (cost * (double)nBound) / (double)100;
90221
90222 /* Add in the estimated cost of sorting the result
90223 */
90224 if( bSort ){
90225 cost += cost*estLog(cost);
@@ -90231,22 +90821,80 @@
90231 */
90232 if( pIdx && bLookup==0 ){
90233 cost /= (double)2;
90234 }
90235 /**** Cost of using this index has now been computed ****/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90236
90237 WHERETRACE((
90238 "tbl=%s idx=%s nEq=%d nInMul=%d nBound=%d bSort=%d bLookup=%d"
90239 " wsFlags=%d (nRow=%.2f cost=%.2f)\n",
90240 pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
90241 nEq, nInMul, nBound, bSort, bLookup, wsFlags, nRow, cost
 
90242 ));
90243
90244 /* If this index is the best we have seen so far, then record this
90245 ** index and its cost in the pCost structure.
90246 */
90247 if( (!pIdx || wsFlags) && cost<pCost->rCost ){
 
 
90248 pCost->rCost = cost;
90249 pCost->nRow = nRow;
90250 pCost->used = used;
90251 pCost->plan.wsFlags = (wsFlags&wsFlagMask);
90252 pCost->plan.nEq = nEq;
@@ -90277,14 +90925,16 @@
90277 || pCost->plan.u.pIdx==0
90278 || pCost->plan.u.pIdx==pSrc->pIndex
90279 );
90280
90281 WHERETRACE(("best index is: %s\n",
90282 (pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
 
90283 ));
90284
90285 bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
 
90286 pCost->plan.wsFlags |= eqTermMask;
90287 }
90288
90289 /*
90290 ** Find the query plan for accessing table pSrc->pTab. Write the
@@ -90750,11 +91400,15 @@
90750 }
90751 start = sqlite3VdbeCurrentAddr(v);
90752 pLevel->op = bRev ? OP_Prev : OP_Next;
90753 pLevel->p1 = iCur;
90754 pLevel->p2 = start;
90755 pLevel->p5 = (pStart==0 && pEnd==0) ?1:0;
 
 
 
 
90756 if( testOp!=OP_Noop ){
90757 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
90758 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
90759 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
90760 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
@@ -91208,20 +91862,27 @@
91208
91209 /*
91210 ** Free a WhereInfo structure
91211 */
91212 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
91213 if( pWInfo ){
91214 int i;
91215 for(i=0; i<pWInfo->nLevel; i++){
91216 sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo;
91217 if( pInfo ){
91218 /* assert( pInfo->needToFreeIdxStr==0 || db->mallocFailed ); */
91219 if( pInfo->needToFreeIdxStr ){
91220 sqlite3_free(pInfo->idxStr);
91221 }
91222 sqlite3DbFree(db, pInfo);
 
 
 
 
 
 
 
91223 }
91224 }
91225 whereClauseClear(pWInfo->pWC);
91226 sqlite3DbFree(db, pWInfo);
91227 }
@@ -91338,10 +91999,11 @@
91338 sqlite3 *db; /* Database connection */
91339
91340 /* The number of tables in the FROM clause is limited by the number of
91341 ** bits in a Bitmask
91342 */
 
91343 if( pTabList->nSrc>BMS ){
91344 sqlite3ErrorMsg(pParse, "at most %d tables in a join", BMS);
91345 return 0;
91346 }
91347
@@ -91365,18 +92027,21 @@
91365 nByteWInfo +
91366 sizeof(WhereClause) +
91367 sizeof(WhereMaskSet)
91368 );
91369 if( db->mallocFailed ){
 
 
91370 goto whereBeginError;
91371 }
91372 pWInfo->nLevel = nTabList;
91373 pWInfo->pParse = pParse;
91374 pWInfo->pTabList = pTabList;
91375 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
91376 pWInfo->pWC = pWC = (WhereClause *)&((u8 *)pWInfo)[nByteWInfo];
91377 pWInfo->wctrlFlags = wctrlFlags;
 
91378 pMaskSet = (WhereMaskSet*)&pWC[1];
91379
91380 /* Split the WHERE clause into separate subexpressions where each
91381 ** subexpression is separated by an AND operator.
91382 */
@@ -91474,24 +92139,29 @@
91474
91475 memset(&bestPlan, 0, sizeof(bestPlan));
91476 bestPlan.rCost = SQLITE_BIG_DBL;
91477
91478 /* Loop through the remaining entries in the FROM clause to find the
91479 ** next nested loop. The FROM clause entries may be iterated through
91480 ** either once or twice.
91481 **
91482 ** The first iteration, which is always performed, searches for the
91483 ** FROM clause entry that permits the lowest-cost, "optimal" scan. In
 
91484 ** this context an optimal scan is one that uses the same strategy
91485 ** for the given FROM clause entry as would be selected if the entry
91486 ** were used as the innermost nested loop. In other words, a table
91487 ** is chosen such that the cost of running that table cannot be reduced
91488 ** by waiting for other tables to run first.
 
 
 
 
91489 **
91490 ** The second iteration is only performed if no optimal scan strategies
91491 ** were found by the first. This iteration is used to search for the
91492 ** lowest cost scan overall.
91493 **
91494 ** Previous versions of SQLite performed only the second iteration -
91495 ** the next outermost loop was always that with the lowest overall
91496 ** cost. However, this meant that SQLite could select the wrong plan
91497 ** for scripts such as the following:
@@ -91505,13 +92175,12 @@
91505 ** However, since the cost of a linear scan through table t2 is the same
91506 ** as the cost of a linear scan through table t1, a simple greedy
91507 ** algorithm may choose to use t2 for the outer loop, which is a much
91508 ** costlier approach.
91509 */
91510 for(isOptimal=1; isOptimal>=0 && bestJ<0; isOptimal--){
91511 Bitmask mask = (isOptimal ? 0 : notReady);
91512 assert( (nTabList-iFrom)>1 || isOptimal );
91513 for(j=iFrom, pTabItem=&pTabList->a[j]; j<nTabList; j++, pTabItem++){
91514 int doNotReorder; /* True if this table should not be reordered */
91515 WhereCost sCost; /* Cost information from best[Virtual]Index() */
91516 ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
91517
@@ -91520,10 +92189,11 @@
91520 m = getMask(pMaskSet, pTabItem->iCursor);
91521 if( (m & notReady)==0 ){
91522 if( j==iFrom ) iFrom++;
91523 continue;
91524 }
 
91525 pOrderBy = ((i==0 && ppOrderBy )?*ppOrderBy:0);
91526
91527 assert( pTabItem->pTab );
91528 #ifndef SQLITE_OMIT_VIRTUALTABLE
91529 if( IsVirtual(pTabItem->pTab) ){
@@ -91535,12 +92205,15 @@
91535 bestBtreeIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost);
91536 }
91537 assert( isOptimal || (sCost.used&notReady)==0 );
91538
91539 if( (sCost.used&notReady)==0
91540 && (j==iFrom || sCost.rCost<bestPlan.rCost)
 
91541 ){
 
 
91542 bestPlan = sCost;
91543 bestJ = j;
91544 }
91545 if( doNotReorder ) break;
91546 }
@@ -91552,17 +92225,20 @@
91552 if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
91553 *ppOrderBy = 0;
91554 }
91555 andFlags &= bestPlan.plan.wsFlags;
91556 pLevel->plan = bestPlan.plan;
91557 if( bestPlan.plan.wsFlags & WHERE_INDEXED ){
 
 
91558 pLevel->iIdxCur = pParse->nTab++;
91559 }else{
91560 pLevel->iIdxCur = -1;
91561 }
91562 notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
91563 pLevel->iFrom = (u8)bestJ;
 
91564
91565 /* Check that if the table scanned by this loop iteration had an
91566 ** INDEXED BY clause attached to it, that the named index is being
91567 ** used for the scan. If not, then query compilation has failed.
91568 ** Return an error.
@@ -91605,10 +92281,11 @@
91605
91606 /* Open all tables in the pTabList and any indices selected for
91607 ** searching those tables.
91608 */
91609 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
 
91610 for(i=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
91611 Table *pTab; /* Table to open */
91612 int iDb; /* Index of database containing table/index */
91613
91614 #ifndef SQLITE_OMIT_EXPLAIN
@@ -91617,11 +92294,13 @@
91617 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
91618 zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName);
91619 if( pItem->zAlias ){
91620 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
91621 }
91622 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
 
 
91623 zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s",
91624 zMsg, pLevel->plan.u.pIdx->zName);
91625 }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
91626 zMsg = sqlite3MAppendf(db, zMsg, "%s VIA MULTI-INDEX UNION", zMsg);
91627 }else if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
@@ -91640,12 +92319,15 @@
91640 sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC);
91641 }
91642 #endif /* SQLITE_OMIT_EXPLAIN */
91643 pTabItem = &pTabList->a[pLevel->iFrom];
91644 pTab = pTabItem->pTab;
 
91645 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
91646 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
 
 
91647 #ifndef SQLITE_OMIT_VIRTUALTABLE
91648 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
91649 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
91650 int iCur = pTabItem->iCursor;
91651 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
@@ -91653,10 +92335,12 @@
91653 #endif
91654 if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0
91655 && (wctrlFlags & WHERE_OMIT_OPEN)==0 ){
91656 int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
91657 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
 
 
91658 if( !pWInfo->okOnePass && pTab->nCol<BMS ){
91659 Bitmask b = pTabItem->colUsed;
91660 int n = 0;
91661 for(; b; b=b>>1, n++){}
91662 sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1,
@@ -91664,11 +92348,15 @@
91664 assert( n<=pTab->nCol );
91665 }
91666 }else{
91667 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
91668 }
91669 pLevel->iTabCur = pTabItem->iCursor;
 
 
 
 
91670 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
91671 Index *pIx = pLevel->plan.u.pIdx;
91672 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
91673 int iIdxCur = pLevel->iIdxCur;
91674 assert( pIx->pSchema==pTab->pSchema );
@@ -91676,12 +92364,14 @@
91676 sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIx->tnum, iDb,
91677 (char*)pKey, P4_KEYINFO_HANDOFF);
91678 VdbeComment((v, "%s", pIx->zName));
91679 }
91680 sqlite3CodeVerifySchema(pParse, iDb);
 
91681 }
91682 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
 
91683
91684 /* Generate the code to do the search. Each iteration of the for
91685 ** loop below generates code for a single nested loop of the VM
91686 ** program.
91687 */
@@ -91745,11 +92435,14 @@
91745 */
91746 return pWInfo;
91747
91748 /* Jump here if malloc fails */
91749 whereBeginError:
91750 whereInfoFree(db, pWInfo);
 
 
 
91751 return 0;
91752 }
91753
91754 /*
91755 ** Generate the end of the WHERE loop. See comments on
@@ -91815,16 +92508,19 @@
91815 assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
91816 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
91817 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
91818 Table *pTab = pTabItem->pTab;
91819 assert( pTab!=0 );
91820 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
91821 if( (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0 ){
91822 if( !pWInfo->okOnePass && (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 ){
 
 
 
91823 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
91824 }
91825 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
91826 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
91827 }
91828 }
91829
91830 /* If this scan uses an index, make code substitutions to read data
@@ -91868,10 +92564,11 @@
91868 }
91869 }
91870
91871 /* Final cleanup
91872 */
 
91873 whereInfoFree(db, pWInfo);
91874 return;
91875 }
91876
91877 /************** End of where.c ***********************************************/
@@ -98071,11 +98768,11 @@
98071 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
98072 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
98073 db->autoCommit = 1;
98074 db->nextAutovac = -1;
98075 db->nextPagesize = 0;
98076 db->flags |= SQLITE_ShortColNames
98077 #if SQLITE_DEFAULT_FILE_FORMAT<4
98078 | SQLITE_LegacyFileFmt
98079 #endif
98080 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
98081 | SQLITE_LoadExtension
@@ -99199,11 +99896,11 @@
99199 ** and so on.
99200 **
99201 ** This is similar in concept to how sqlite encodes "varints" but
99202 ** the encoding is not the same. SQLite varints are big-endian
99203 ** are are limited to 9 bytes in length whereas FTS3 varints are
99204 ** little-endian and can be upt to 10 bytes in length (in theory).
99205 **
99206 ** Example encodings:
99207 **
99208 ** 1: 0x01
99209 ** 127: 0x7f
@@ -99210,30 +99907,30 @@
99210 ** 128: 0x81 0x00
99211 **
99212 **
99213 **** Document lists ****
99214 ** A doclist (document list) holds a docid-sorted list of hits for a
99215 ** given term. Doclists hold docids, and can optionally associate
99216 ** token positions and offsets with docids. A position is the index
99217 ** of a word within the document. The first word of the document has
99218 ** a position of 0.
99219 **
99220 ** FTS3 used to optionally store character offsets using a compile-time
99221 ** option. But that functionality is no longer supported.
99222 **
99223 ** A DL_POSITIONS_OFFSETS doclist is stored like this:
99224 **
99225 ** array {
99226 ** varint docid;
99227 ** array { (position list for column 0)
99228 ** varint position; (delta from previous position plus POS_BASE)
99229 ** }
99230 ** array {
99231 ** varint POS_COLUMN; (marks start of position list for new column)
99232 ** varint column; (index of new column)
99233 ** array {
99234 ** varint position; (delta from previous position plus POS_BASE)
99235 ** }
99236 ** }
99237 ** varint POS_END; (marks end of positions for this document.
99238 ** }
99239 **
@@ -99241,11 +99938,11 @@
99241 ** memory. A "position" is an index of a token in the token stream
99242 ** generated by the tokenizer. Note that POS_END and POS_COLUMN occur
99243 ** in the same logical place as the position element, and act as sentinals
99244 ** ending a position list array. POS_END is 0. POS_COLUMN is 1.
99245 ** The positions numbers are not stored literally but rather as two more
99246 ** the difference from the prior position, or the just the position plus
99247 ** 2 for the first position. Example:
99248 **
99249 ** label: A B C D E F G H I J K
99250 ** value: 123 5 9 1 1 14 35 0 234 72 0
99251 **
@@ -99255,18 +99952,18 @@
99255 ** new column is column number 1. There are two positions at 12 and 45
99256 ** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
99257 ** 234 at I is the next docid. It has one position 72 (72-2) and then
99258 ** terminates with the 0 at K.
99259 **
99260 ** A DL_POSITIONS doclist omits the startOffset and endOffset
99261 ** information. A DL_DOCIDS doclist omits both the position and
99262 ** offset information, becoming an array of varint-encoded docids.
99263 **
99264 ** On-disk data is stored as type DL_DEFAULT, so we don't serialize
99265 ** the type. Due to how deletion is implemented in the segmentation
99266 ** system, on-disk doclists MUST store at least positions.
99267 **
99268 **
99269 **** Segment leaf nodes ****
99270 ** Segment leaf nodes store terms and doclists, ordered by term. Leaf
99271 ** nodes are written using LeafWriter, and read using LeafReader (to
99272 ** iterate through a single leaf node's data) and LeavesReader (to
@@ -99776,10 +100473,24 @@
99776 ** Maximum length of a varint encoded integer. The varint format is different
99777 ** from that used by SQLite, so the maximum length is 10, not 9.
99778 */
99779 #define FTS3_VARINT_MAX 10
99780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99781 /*
99782 ** This section provides definitions to allow the
99783 ** FTS3 extension to be compiled outside of the
99784 ** amalgamation.
99785 */
@@ -100087,12 +100798,11 @@
100087 *pi = (int) i;
100088 return ret;
100089 }
100090
100091 /*
100092 ** Return the number of bytes required to store the value passed as the
100093 ** first argument in varint form.
100094 */
100095 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64 v){
100096 int i = 0;
100097 do{
100098 i++;
@@ -100139,11 +100849,11 @@
100139 }
100140 }
100141
100142 /*
100143 ** Read a single varint from the doclist at *pp and advance *pp to point
100144 ** to the next element of the varlist. Add the value of the varint
100145 ** to *pVal.
100146 */
100147 static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){
100148 sqlite3_int64 iVal;
100149 *pp += sqlite3Fts3GetVarint(*pp, &iVal);
@@ -100195,11 +100905,11 @@
100195 ** and then evaluate those statements. The success code is writting
100196 ** into *pRc.
100197 **
100198 ** If *pRc is initially non-zero then this routine is a no-op.
100199 */
100200 void fts3DbExec(
100201 int *pRc, /* Success code */
100202 sqlite3 *db, /* Database in which to run SQL */
100203 const char *zFormat, /* Format string for SQL */
100204 ... /* Arguments to the format string */
100205 ){
@@ -100275,10 +100985,14 @@
100275
100276 /*
100277 ** Create the backing store tables (%_content, %_segments and %_segdir)
100278 ** required by the FTS3 table passed as the only argument. This is done
100279 ** as part of the vtab xCreate() method.
 
 
 
 
100280 */
100281 static int fts3CreateTables(Fts3Table *p){
100282 int rc = SQLITE_OK; /* Return code */
100283 int i; /* Iterator variable */
100284 char *zContentCols; /* Columns of %_content table */
@@ -100367,11 +101081,11 @@
100367 ** This function is the implementation of both the xConnect and xCreate
100368 ** methods of the FTS3 virtual table.
100369 **
100370 ** The argv[] array contains the following:
100371 **
100372 ** argv[0] -> module name
100373 ** argv[1] -> database name
100374 ** argv[2] -> table name
100375 ** argv[...] -> "column name" and other module argument fields.
100376 */
100377 static int fts3InitVtab(
@@ -100386,16 +101100,16 @@
100386 Fts3Hash *pHash = (Fts3Hash *)pAux;
100387 Fts3Table *p; /* Pointer to allocated vtab */
100388 int rc; /* Return code */
100389 int i; /* Iterator variable */
100390 int nByte; /* Size of allocation used for *p */
100391 int iCol;
100392 int nString = 0;
100393 int nCol = 0;
100394 char *zCsr;
100395 int nDb;
100396 int nName;
100397
100398 const char *zTokenizer = 0; /* Name of tokenizer to use */
100399 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
100400
100401 nDb = (int)strlen(argv[1]) + 1;
@@ -100621,10 +101335,15 @@
100621 sqlite3_free(pCsr->aMatchinfo);
100622 sqlite3_free(pCsr);
100623 return SQLITE_OK;
100624 }
100625
 
 
 
 
 
100626 static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
100627 if( pCsr->isRequireSeek ){
100628 pCsr->isRequireSeek = 0;
100629 sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
100630 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
@@ -100647,10 +101366,21 @@
100647 }else{
100648 return SQLITE_OK;
100649 }
100650 }
100651
 
 
 
 
 
 
 
 
 
 
 
100652 static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
100653 int rc = SQLITE_OK; /* Return code */
100654 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
100655
100656 if( pCsr->aDoclist==0 ){
@@ -100782,10 +101512,15 @@
100782
100783 /*
100784 ** When this function is called, *ppPoslist is assumed to point to the
100785 ** start of a position-list. After it returns, *ppPoslist points to the
100786 ** first byte after the position-list.
 
 
 
 
 
100787 **
100788 ** If pp is not NULL, then the contents of the position list are copied
100789 ** to *pp. *pp is set to point to the first byte past the last byte copied
100790 ** before this function returns.
100791 */
@@ -100792,21 +101527,24 @@
100792 static void fts3PoslistCopy(char **pp, char **ppPoslist){
100793 char *pEnd = *ppPoslist;
100794 char c = 0;
100795
100796 /* The end of a position list is marked by a zero encoded as an FTS3
100797 ** varint. A single 0x00 byte. Except, if the 0x00 byte is preceded by
100798 ** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
100799 ** of some other, multi-byte, value.
100800 **
100801 ** The following block moves pEnd to point to the first byte that is not
100802 ** immediately preceded by a byte with the 0x80 bit set. Then increments
100803 ** pEnd once more so that it points to the byte immediately following the
100804 ** last byte in the position-list.
100805 */
100806 while( *pEnd | c ) c = *pEnd++ & 0x80;
100807 pEnd++;
 
 
 
100808
100809 if( pp ){
100810 int n = (int)(pEnd - *ppPoslist);
100811 char *p = *pp;
100812 memcpy(p, *ppPoslist, n);
@@ -100814,16 +101552,38 @@
100814 *pp = p;
100815 }
100816 *ppPoslist = pEnd;
100817 }
100818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100819 static void fts3ColumnlistCopy(char **pp, char **ppPoslist){
100820 char *pEnd = *ppPoslist;
100821 char c = 0;
100822
100823 /* A column-list is terminated by either a 0x01 or 0x00. */
100824 while( 0xFE & (*pEnd | c) ) c = *pEnd++ & 0x80;
 
 
 
 
 
100825 if( pp ){
100826 int n = (int)(pEnd - *ppPoslist);
100827 char *p = *pp;
100828 memcpy(p, *ppPoslist, n);
100829 p += n;
@@ -100831,41 +101591,49 @@
100831 }
100832 *ppPoslist = pEnd;
100833 }
100834
100835 /*
100836 ** Value used to signify the end of an offset-list. This is safe because
100837 ** it is not possible to have a document with 2^31 terms.
100838 */
100839 #define OFFSET_LIST_END 0x7fffffff
100840
100841 /*
100842 ** This function is used to help parse offset-lists. When this function is
100843 ** called, *pp may point to the start of the next varint in the offset-list
100844 ** being parsed, or it may point to 1 byte past the end of the offset-list
100845 ** (in which case **pp will be 0x00 or 0x01).
 
100846 **
100847 ** If *pp points past the end of the current offset list, set *pi to
100848 ** OFFSET_LIST_END and return. Otherwise, read the next varint from *pp,
100849 ** increment the current value of *pi by the value read, and set *pp to
100850 ** point to the next value before returning.
 
 
 
 
 
 
100851 */
100852 static void fts3ReadNextPos(
100853 char **pp, /* IN/OUT: Pointer into offset-list buffer */
100854 sqlite3_int64 *pi /* IN/OUT: Value read from offset-list */
100855 ){
100856 if( **pp&0xFE ){
100857 fts3GetDeltaVarint(pp, pi);
100858 *pi -= 2;
100859 }else{
100860 *pi = OFFSET_LIST_END;
100861 }
100862 }
100863
100864 /*
100865 ** If parameter iCol is not 0, write an 0x01 byte followed by the value of
100866 ** iCol encoded as a varint to *pp.
 
100867 **
100868 ** Set *pp to point to the byte just after the last byte written before
100869 ** returning (do not modify it if iCol==0). Return the total number of bytes
100870 ** written (0 if iCol==0).
100871 */
@@ -100879,11 +101647,15 @@
100879 }
100880 return n;
100881 }
100882
100883 /*
100884 **
 
 
 
 
100885 */
100886 static void fts3PoslistMerge(
100887 char **pp, /* Output buffer */
100888 char **pp1, /* Left input list */
100889 char **pp2 /* Right input list */
@@ -100891,36 +101663,37 @@
100891 char *p = *pp;
100892 char *p1 = *pp1;
100893 char *p2 = *pp2;
100894
100895 while( *p1 || *p2 ){
100896 int iCol1;
100897 int iCol2;
100898
100899 if( *p1==0x01 ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
100900 else if( *p1==0x00 ) iCol1 = OFFSET_LIST_END;
100901 else iCol1 = 0;
100902
100903 if( *p2==0x01 ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
100904 else if( *p2==0x00 ) iCol2 = OFFSET_LIST_END;
100905 else iCol2 = 0;
100906
100907 if( iCol1==iCol2 ){
100908 sqlite3_int64 i1 = 0;
100909 sqlite3_int64 i2 = 0;
100910 sqlite3_int64 iPrev = 0;
100911 int n = fts3PutColNumber(&p, iCol1);
100912 p1 += n;
100913 p2 += n;
100914
100915 /* At this point, both p1 and p2 point to the start of offset-lists.
100916 ** An offset-list is a list of non-negative delta-encoded varints, each
100917 ** incremented by 2 before being stored. Each list is terminated by a 0
100918 ** or 1 value (0x00 or 0x01). The following block merges the two lists
 
100919 ** and writes the results to buffer p. p is left pointing to the byte
100920 ** after the list written. No terminator (0x00 or 0x01) is written to
100921 ** the output.
100922 */
100923 fts3GetDeltaVarint(&p1, &i1);
100924 fts3GetDeltaVarint(&p2, &i2);
100925 do {
100926 fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
@@ -100931,21 +101704,21 @@
100931 }else if( i1<i2 ){
100932 fts3ReadNextPos(&p1, &i1);
100933 }else{
100934 fts3ReadNextPos(&p2, &i2);
100935 }
100936 }while( i1!=OFFSET_LIST_END || i2!=OFFSET_LIST_END );
100937 }else if( iCol1<iCol2 ){
100938 p1 += fts3PutColNumber(&p, iCol1);
100939 fts3ColumnlistCopy(&p, &p1);
100940 }else{
100941 p2 += fts3PutColNumber(&p, iCol2);
100942 fts3ColumnlistCopy(&p, &p2);
100943 }
100944 }
100945
100946 *p++ = '\0';
100947 *pp = p;
100948 *pp1 = p1 + 1;
100949 *pp2 = p2 + 1;
100950 }
100951
@@ -100964,15 +101737,15 @@
100964 char *p2 = *pp2;
100965
100966 int iCol1 = 0;
100967 int iCol2 = 0;
100968 assert( *p1!=0 && *p2!=0 );
100969 if( *p1==0x01 ){
100970 p1++;
100971 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
100972 }
100973 if( *p2==0x01 ){
100974 p2++;
100975 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
100976 }
100977
100978 while( 1 ){
@@ -100981,15 +101754,16 @@
100981 sqlite3_int64 iPrev = 0;
100982 sqlite3_int64 iPos1 = 0;
100983 sqlite3_int64 iPos2 = 0;
100984
100985 if( pp && iCol1 ){
100986 *p++ = 0x01;
100987 p += sqlite3Fts3PutVarint(p, iCol1);
100988 }
100989
100990 assert( *p1!=0x00 && *p2!=0x00 && *p1!=0x01 && *p2!=0x01 );
 
100991 fts3GetDeltaVarint(&p1, &iPos1); iPos1 -= 2;
100992 fts3GetDeltaVarint(&p2, &iPos2); iPos2 -= 2;
100993
100994 while( 1 ){
100995 if( iPos2>iPos1 && iPos2<=iPos1+nToken ){
@@ -101237,10 +102011,11 @@
101237 }
101238
101239 default: assert( mergetype==MERGE_POS_NEAR || mergetype==MERGE_NEAR ); {
101240 char *aTmp = 0;
101241 char **ppPos = 0;
 
101242 if( mergetype==MERGE_POS_NEAR ){
101243 ppPos = &p;
101244 aTmp = sqlite3_malloc(2*(n1+n2+1));
101245 if( !aTmp ){
101246 return SQLITE_NOMEM;
@@ -101341,13 +102116,13 @@
101341 ** This function retreives the doclist for the specified term (or term
101342 ** prefix) from the database.
101343 **
101344 ** The returned doclist may be in one of two formats, depending on the
101345 ** value of parameter isReqPos. If isReqPos is zero, then the doclist is
101346 ** a sorted list of delta-compressed docids. If isReqPos is non-zero,
101347 ** then the returned list is in the same format as is stored in the
101348 ** database without the found length specifier at the start of on-disk
101349 ** doclists.
101350 */
101351 static int fts3TermSelect(
101352 Fts3Table *p, /* Virtual table handle */
101353 int iColumn, /* Column to query (or -ve for all columns) */
@@ -101603,11 +102378,13 @@
101603 return rc;
101604 }
101605
101606 /*
101607 ** Evaluate the full-text expression pExpr against fts3 table pTab. Store
101608 ** the resulting doclist in *paOut and *pnOut.
 
 
101609 */
101610 static int evalFts3Expr(
101611 Fts3Table *p, /* Virtual table handle */
101612 Fts3Expr *pExpr, /* Parsed fts3 expression */
101613 char **paOut, /* OUT: Pointer to malloc'd result buffer */
@@ -108163,11 +108940,11 @@
108163 ** This is done as part of extracting the snippet text, not when selecting
108164 ** the snippet. Snippet selection is done based on doclists only, so there
108165 ** is no way for fts3BestSnippet() to know whether or not the document
108166 ** actually contains terms that follow the final highlighted term.
108167 */
108168 int fts3SnippetShift(
108169 Fts3Table *pTab, /* FTS3 table snippet comes from */
108170 int nSnippet, /* Number of tokens desired for snippet */
108171 const char *zDoc, /* Document text to extract snippet from */
108172 int nDoc, /* Size of buffer zDoc in bytes */
108173 int *piPos, /* IN/OUT: First token of snippet */
@@ -111280,10 +112057,11 @@
111280 rc = SQLITE_CONSTRAINT;
111281 goto constraint;
111282 }
111283 rc = sqlite3_reset(pRtree->pReadRowid);
111284 }
 
111285
111286 if( rc==SQLITE_OK ){
111287 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
111288 }
111289 if( rc==SQLITE_OK ){
111290
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.6.23. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% are more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -321,11 +321,11 @@
321 ** to generate appropriate macros for a wide range of compilers.
322 **
323 ** The correct "ANSI" way to do this is to use the intptr_t type.
324 ** Unfortunately, that typedef is not available on all compilers, or
325 ** if it is available, it requires an #include of specific headers
326 ** that vary from one machine to the next.
327 **
328 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
329 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
330 ** So we have to define the macros in different ways depending on the
331 ** compiler.
@@ -626,13 +626,13 @@
626 **
627 ** See also: [sqlite3_libversion()],
628 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
629 ** [sqlite_version()] and [sqlite_source_id()].
630 */
631 #define SQLITE_VERSION "3.6.23"
632 #define SQLITE_VERSION_NUMBER 3006023
633 #define SQLITE_SOURCE_ID "2010-04-15 23:24:29 f96782b389b5b97b488dc5814f7082e0393f64cd"
634
635 /*
636 ** CAPI3REF: Run-Time Library Version Numbers
637 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
638 **
@@ -665,11 +665,10 @@
665 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
666 SQLITE_API const char *sqlite3_libversion(void);
667 SQLITE_API const char *sqlite3_sourceid(void);
668 SQLITE_API int sqlite3_libversion_number(void);
669
 
670 /*
671 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
672 **
673 ** ^The sqlite3_compileoption_used() function returns 0 or 1
674 ** indicating whether the specified option was defined at
@@ -688,13 +687,14 @@
687 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
688 **
689 ** See also: SQL functions [sqlite_compileoption_used()] and
690 ** [sqlite_compileoption_get()] and the [compile_options pragma].
691 */
692 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
693 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
694 SQLITE_API const char *sqlite3_compileoption_get(int N);
695 #endif
696
697 /*
698 ** CAPI3REF: Test To See If The Library Is Threadsafe
699 **
700 ** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -1492,15 +1492,14 @@
1492 **
1493 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1494 ** ^If the option is unknown or SQLite is unable to set the option
1495 ** then this routine returns a non-zero [error code].
1496 */
1497 SQLITE_API int sqlite3_config(int, ...);
1498
1499 /*
1500 ** CAPI3REF: Configure database connections
 
1501 **
1502 ** The sqlite3_db_config() interface is used to make configuration
1503 ** changes to a [database connection]. The interface is similar to
1504 ** [sqlite3_config()] except that the changes apply to a single
1505 ** [database connection] (specified in the first argument). The
@@ -1516,15 +1515,14 @@
1515 ** Additional arguments depend on the verb.
1516 **
1517 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1518 ** the call is considered successful.
1519 */
1520 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
1521
1522 /*
1523 ** CAPI3REF: Memory Allocation Routines
 
1524 **
1525 ** An instance of this object defines the interface between SQLite
1526 ** and low-level memory allocation routines.
1527 **
1528 ** This object is used in only one place in the SQLite interface.
@@ -1602,11 +1600,10 @@
1600 void *pAppData; /* Argument to xInit() and xShutdown() */
1601 };
1602
1603 /*
1604 ** CAPI3REF: Configuration Options
 
1605 **
1606 ** These constants are the available integer configuration options that
1607 ** can be passed as the first argument to the [sqlite3_config()] interface.
1608 **
1609 ** New configuration options may be added in future releases of SQLite.
@@ -1788,10 +1785,28 @@
1785 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1786 ** <dd> ^(This option takes a single argument which is a pointer to an
1787 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1788 ** page cache implementation into that object.)^ </dd>
1789 **
1790 ** <dt>SQLITE_CONFIG_LOG</dt>
1791 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1792 ** function with a call signature of void(*)(void*,int,const char*),
1793 ** and a pointer to void. ^If the function pointer is not NULL, it is
1794 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1795 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1796 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1797 ** passed through as the first parameter to the application-defined logger
1798 ** function whenever that function is invoked. ^The second parameter to
1799 ** the logger function is a copy of the first parameter to the corresponding
1800 ** [sqlite3_log()] call and is intended to be a [result code] or an
1801 ** [extended result code]. ^The third parameter passed to the logger is
1802 ** log message after formatting via [sqlite3_snprintf()].
1803 ** The SQLite logging interface is not reentrant; the logger function
1804 ** supplied by the application must not invoke any SQLite interface.
1805 ** In a multi-threaded application, the application-defined logger
1806 ** function must be threadsafe. </dd>
1807 **
1808 ** </dl>
1809 */
1810 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1811 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1812 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1808,12 +1823,11 @@
1823 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1824 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1825 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1826
1827 /*
1828 ** CAPI3REF: Database Connection Configuration Options
 
1829 **
1830 ** These constants are the available integer configuration options that
1831 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
1832 **
1833 ** New configuration options may be added in future releases of SQLite.
@@ -2585,11 +2599,10 @@
2599 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2600 #define SQLITE_COPY 0 /* No longer used */
2601
2602 /*
2603 ** CAPI3REF: Tracing And Profiling Functions
 
2604 **
2605 ** These routines register callback functions that can be used for
2606 ** tracing and profiling the execution of SQL statements.
2607 **
2608 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2603,11 +2616,11 @@
2616 ** ^The callback function registered by sqlite3_profile() is invoked
2617 ** as each SQL statement finishes. ^The profile callback contains
2618 ** the original statement text and an estimate of wall-clock time
2619 ** of how long that statement took to run.
2620 */
2621 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2622 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2623 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2624
2625 /*
2626 ** CAPI3REF: Query Progress Callbacks
@@ -4208,11 +4221,11 @@
4221 sqlite3*,
4222 void*,
4223 void(*)(void*,sqlite3*,int eTextRep,const void*)
4224 );
4225
4226 #ifdef SQLITE_HAS_CODEC
4227 /*
4228 ** Specify the key for an encrypted database. This routine should be
4229 ** called right after sqlite3_open().
4230 **
4231 ** The code to implement this API is not available in the public release
@@ -4391,12 +4404,10 @@
4404 ** ^For the purposes of this API, a transaction is said to have been
4405 ** rolled back if an explicit "ROLLBACK" statement is executed, or
4406 ** an error or constraint causes an implicit rollback to occur.
4407 ** ^The rollback callback is not invoked if a transaction is
4408 ** automatically rolled back because the database connection is closed.
 
 
4409 **
4410 ** See also the [sqlite3_update_hook()] interface.
4411 */
4412 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
4413 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
@@ -4678,12 +4689,10 @@
4689 ** ^This function disables automatic extensions in all threads.
4690 */
4691 SQLITE_API void sqlite3_reset_auto_extension(void);
4692
4693 /*
 
 
4694 ** The interface to the virtual-table mechanism is currently considered
4695 ** to be experimental. The interface might change in incompatible ways.
4696 ** If this is a problem for you, do not use the interface at this time.
4697 **
4698 ** When the virtual-table mechanism stabilizes, we will declare the
@@ -4699,11 +4708,10 @@
4708 typedef struct sqlite3_module sqlite3_module;
4709
4710 /*
4711 ** CAPI3REF: Virtual Table Object
4712 ** KEYWORDS: sqlite3_module {virtual table module}
 
4713 **
4714 ** This structure, sometimes called a a "virtual table module",
4715 ** defines the implementation of a [virtual tables].
4716 ** This structure consists mostly of methods for the module.
4717 **
@@ -4746,11 +4754,10 @@
4754 };
4755
4756 /*
4757 ** CAPI3REF: Virtual Table Indexing Information
4758 ** KEYWORDS: sqlite3_index_info
 
4759 **
4760 ** The sqlite3_index_info structure and its substructures is used to
4761 ** pass information into and receive the reply from the [xBestIndex]
4762 ** method of a [virtual table module]. The fields under **Inputs** are the
4763 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4828,11 +4835,10 @@
4835 #define SQLITE_INDEX_CONSTRAINT_GE 32
4836 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
4837
4838 /*
4839 ** CAPI3REF: Register A Virtual Table Implementation
 
4840 **
4841 ** ^These routines are used to register a new [virtual table module] name.
4842 ** ^Module names must be registered before
4843 ** creating a new [virtual table] using the module and before using a
4844 ** preexisting [virtual table] for the module.
@@ -4850,17 +4856,17 @@
4856 ** invoke the destructor function (if it is not NULL) when SQLite
4857 ** no longer needs the pClientData pointer. ^The sqlite3_create_module()
4858 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
4859 ** destructor.
4860 */
4861 SQLITE_API int sqlite3_create_module(
4862 sqlite3 *db, /* SQLite connection to register module with */
4863 const char *zName, /* Name of the module */
4864 const sqlite3_module *p, /* Methods for the module */
4865 void *pClientData /* Client data for xCreate/xConnect */
4866 );
4867 SQLITE_API int sqlite3_create_module_v2(
4868 sqlite3 *db, /* SQLite connection to register module with */
4869 const char *zName, /* Name of the module */
4870 const sqlite3_module *p, /* Methods for the module */
4871 void *pClientData, /* Client data for xCreate/xConnect */
4872 void(*xDestroy)(void*) /* Module destructor function */
@@ -4867,11 +4873,10 @@
4873 );
4874
4875 /*
4876 ** CAPI3REF: Virtual Table Instance Object
4877 ** KEYWORDS: sqlite3_vtab
 
4878 **
4879 ** Every [virtual table module] implementation uses a subclass
4880 ** of this object to describe a particular instance
4881 ** of the [virtual table]. Each subclass will
4882 ** be tailored to the specific needs of the module implementation.
@@ -4893,11 +4898,10 @@
4898 };
4899
4900 /*
4901 ** CAPI3REF: Virtual Table Cursor Object
4902 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
 
4903 **
4904 ** Every [virtual table module] implementation uses a subclass of the
4905 ** following structure to describe cursors that point into the
4906 ** [virtual table] and are used
4907 ** to loop through the virtual table. Cursors are created using the
@@ -4915,22 +4919,20 @@
4919 /* Virtual table implementations will typically add additional fields */
4920 };
4921
4922 /*
4923 ** CAPI3REF: Declare The Schema Of A Virtual Table
 
4924 **
4925 ** ^The [xCreate] and [xConnect] methods of a
4926 ** [virtual table module] call this interface
4927 ** to declare the format (the names and datatypes of the columns) of
4928 ** the virtual tables they implement.
4929 */
4930 SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4931
4932 /*
4933 ** CAPI3REF: Overload A Function For A Virtual Table
 
4934 **
4935 ** ^(Virtual tables can provide alternative implementations of functions
4936 ** using the [xFindFunction] method of the [virtual table module].
4937 ** But global versions of those functions
4938 ** must exist in order to be overloaded.)^
@@ -4941,22 +4943,20 @@
4943 ** of the new function always causes an exception to be thrown. So
4944 ** the new function is not good for anything by itself. Its only
4945 ** purpose is to be a placeholder function that can be overloaded
4946 ** by a [virtual table].
4947 */
4948 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4949
4950 /*
4951 ** The interface to the virtual-table mechanism defined above (back up
4952 ** to a comment remarkably similar to this one) is currently considered
4953 ** to be experimental. The interface might change in incompatible ways.
4954 ** If this is a problem for you, do not use the interface at this time.
4955 **
4956 ** When the virtual-table mechanism stabilizes, we will declare the
4957 ** interface fixed, support it indefinitely, and remove this comment.
 
 
4958 */
4959
4960 /*
4961 ** CAPI3REF: A Handle To An Open BLOB
4962 ** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -5295,11 +5295,10 @@
5295 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
5296 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
5297
5298 /*
5299 ** CAPI3REF: Mutex Methods Object
 
5300 **
5301 ** An instance of this structure defines the low-level routines
5302 ** used to allocate and use mutexes.
5303 **
5304 ** Usually, the default mutex implementations provided by SQLite are
@@ -5512,11 +5511,10 @@
5511 #define SQLITE_TESTCTRL_ISKEYWORD 16
5512 #define SQLITE_TESTCTRL_LAST 16
5513
5514 /*
5515 ** CAPI3REF: SQLite Runtime Status
 
5516 **
5517 ** ^This interface is used to retrieve runtime status information
5518 ** about the preformance of SQLite, and optionally to reset various
5519 ** highwater marks. ^The first argument is an integer code for
5520 ** the specific parameter to measure. ^(Recognized integer codes
@@ -5540,16 +5538,15 @@
5538 ** and it is possible that another thread might change the parameter
5539 ** in between the times when *pCurrent and *pHighwater are written.
5540 **
5541 ** See also: [sqlite3_db_status()]
5542 */
5543 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5544
5545
5546 /*
5547 ** CAPI3REF: Status Parameters
 
5548 **
5549 ** These integer constants designate various run-time status parameters
5550 ** that can be returned by [sqlite3_status()].
5551 **
5552 ** <dl>
@@ -5632,31 +5629,31 @@
5629 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5630 #define SQLITE_STATUS_SCRATCH_SIZE 8
5631
5632 /*
5633 ** CAPI3REF: Database Connection Status
 
5634 **
5635 ** ^This interface is used to retrieve runtime status information
5636 ** about a single [database connection]. ^The first argument is the
5637 ** database connection object to be interrogated. ^The second argument
5638 ** is an integer constant, taken from the set of
5639 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5640 ** determiness the parameter to interrogate. The set of
5641 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5642 ** to grow in future releases of SQLite.
5643 **
5644 ** ^The current value of the requested parameter is written into *pCur
5645 ** and the highest instantaneous value is written into *pHiwtr. ^If
5646 ** the resetFlg is true, then the highest instantaneous value is
5647 ** reset back down to the current value.
5648 **
5649 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5650 */
5651 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5652
5653 /*
5654 ** CAPI3REF: Status Parameters for database connections
 
5655 **
5656 ** These constants are the available integer "verbs" that can be passed as
5657 ** the second argument to the [sqlite3_db_status()] interface.
5658 **
5659 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5667,18 +5664,25 @@
5664 **
5665 ** <dl>
5666 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5667 ** <dd>This parameter returns the number of lookaside memory slots currently
5668 ** checked out.</dd>)^
5669 **
5670 ** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5671 ** <dd>^This parameter returns the approximate number of of bytes of heap
5672 ** memory used by all pager caches associated with the database connection.
5673 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5674 ** checked out.</dd>)^
5675 ** </dl>
5676 */
5677 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5678 #define SQLITE_DBSTATUS_CACHE_USED 1
5679 #define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
5680
5681
5682 /*
5683 ** CAPI3REF: Prepared Statement Status
 
5684 **
5685 ** ^(Each prepared statement maintains various
5686 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5687 ** of times it has performed specific operations.)^ These counters can
5688 ** be used to monitor the performance characteristics of the prepared
@@ -5696,15 +5700,14 @@
5700 ** ^If the resetFlg is true, then the counter is reset to zero after this
5701 ** interface call returns.
5702 **
5703 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
5704 */
5705 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5706
5707 /*
5708 ** CAPI3REF: Status Parameters for prepared statements
 
5709 **
5710 ** These preprocessor macros define integer codes that name counter
5711 ** values associated with the [sqlite3_stmt_status()] interface.
5712 ** The meanings of the various counters are as follows:
5713 **
@@ -5718,18 +5721,25 @@
5721 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
5722 ** <dd>^This is the number of sort operations that have occurred.
5723 ** A non-zero value in this counter may indicate an opportunity to
5724 ** improvement performance through careful use of indices.</dd>
5725 **
5726 ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5727 ** <dd>^This is the number of rows inserted into transient indices that
5728 ** were created automatically in order to help joins run faster.
5729 ** A non-zero value in this counter may indicate an opportunity to
5730 ** improvement performance by adding permanent indices that do not
5731 ** need to be reinitialized each time the statement is run.</dd>
5732 **
5733 ** </dl>
5734 */
5735 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5736 #define SQLITE_STMTSTATUS_SORT 2
5737 #define SQLITE_STMTSTATUS_AUTOINDEX 3
5738
5739 /*
5740 ** CAPI3REF: Custom Page Cache Object
 
5741 **
5742 ** The sqlite3_pcache type is opaque. It is implemented by
5743 ** the pluggable module. The SQLite core has no knowledge of
5744 ** its size or internal structure and never deals with the
5745 ** sqlite3_pcache object except by holding and passing pointers
@@ -5740,11 +5750,10 @@
5750 typedef struct sqlite3_pcache sqlite3_pcache;
5751
5752 /*
5753 ** CAPI3REF: Application Defined Page Cache.
5754 ** KEYWORDS: {page cache}
 
5755 **
5756 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5757 ** register an alternative page cache implementation by passing in an
5758 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5759 ** heap memory used by SQLite is used by the page cache to cache data read
@@ -5882,11 +5891,10 @@
5891 void (*xDestroy)(sqlite3_pcache*);
5892 };
5893
5894 /*
5895 ** CAPI3REF: Online Backup Object
 
5896 **
5897 ** The sqlite3_backup object records state information about an ongoing
5898 ** online backup operation. ^The sqlite3_backup object is created by
5899 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
5900 ** [sqlite3_backup_finish()].
@@ -5895,11 +5903,10 @@
5903 */
5904 typedef struct sqlite3_backup sqlite3_backup;
5905
5906 /*
5907 ** CAPI3REF: Online Backup API.
 
5908 **
5909 ** The backup API copies the content of one database into another.
5910 ** It is useful either for creating backups of databases or
5911 ** for copying in-memory databases to or from persistent files.
5912 **
@@ -6083,11 +6090,10 @@
6090 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
6091 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
6092
6093 /*
6094 ** CAPI3REF: Unlock Notification
 
6095 **
6096 ** ^When running in shared-cache mode, a database operation may fail with
6097 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
6098 ** individual tables within the shared-cache cannot be obtained. See
6099 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -6205,11 +6211,10 @@
6211 );
6212
6213
6214 /*
6215 ** CAPI3REF: String Comparison
 
6216 **
6217 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
6218 ** compare the contents of two buffers containing UTF-8 strings in a
6219 ** case-indendent fashion, using the same definition of case independence
6220 ** that SQLite uses internally when comparing identifiers.
@@ -6216,16 +6221,15 @@
6221 */
6222 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
6223
6224 /*
6225 ** CAPI3REF: Error Logging Interface
 
6226 **
6227 ** ^The [sqlite3_log()] interface writes a message into the error log
6228 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
6229 ** ^If logging is enabled, the zFormat string and subsequent arguments are
6230 ** used with [sqlite3_snprintf()] to generate the final output string.
6231 **
6232 ** The sqlite3_log() interface is intended for use by extensions such as
6233 ** virtual tables, collating functions, and SQL functions. While there is
6234 ** nothing to prevent an application from calling sqlite3_log(), doing so
6235 ** is considered bad form.
@@ -6529,10 +6533,11 @@
6533 ** If compiling for a processor that lacks floating point support,
6534 ** substitute integer for floating-point
6535 */
6536 #ifdef SQLITE_OMIT_FLOATING_POINT
6537 # define double sqlite_int64
6538 # define float sqlite_int64
6539 # define LONGDOUBLE_TYPE sqlite_int64
6540 # ifndef SQLITE_BIG_DBL
6541 # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
6542 # endif
6543 # define SQLITE_OMIT_DATETIME_FUNCS 1
@@ -6940,10 +6945,11 @@
6945 SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
6946 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
6947 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
6948 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
6949 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
6950 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
6951 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
6952 SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
6953 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
6954 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
6955 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
@@ -7334,85 +7340,85 @@
7340 #define OP_ReadCookie 35
7341 #define OP_SetCookie 36
7342 #define OP_VerifyCookie 37
7343 #define OP_OpenRead 38
7344 #define OP_OpenWrite 39
7345 #define OP_OpenAutoindex 40
7346 #define OP_OpenEphemeral 41
7347 #define OP_OpenPseudo 42
7348 #define OP_Close 43
7349 #define OP_SeekLt 44
7350 #define OP_SeekLe 45
7351 #define OP_SeekGe 46
7352 #define OP_SeekGt 47
7353 #define OP_Seek 48
7354 #define OP_NotFound 49
7355 #define OP_Found 50
7356 #define OP_IsUnique 51
7357 #define OP_NotExists 52
7358 #define OP_Sequence 53
7359 #define OP_NewRowid 54
7360 #define OP_Insert 55
7361 #define OP_InsertInt 56
7362 #define OP_Delete 57
7363 #define OP_ResetCount 58
7364 #define OP_RowKey 59
7365 #define OP_RowData 60
7366 #define OP_Rowid 61
7367 #define OP_NullRow 62
7368 #define OP_Last 63
7369 #define OP_Sort 64
7370 #define OP_Rewind 65
7371 #define OP_Prev 66
7372 #define OP_Next 67
7373 #define OP_IdxInsert 70
7374 #define OP_IdxDelete 71
7375 #define OP_IdxRowid 72
7376 #define OP_IdxLT 81
7377 #define OP_IdxGE 92
7378 #define OP_Destroy 95
7379 #define OP_Clear 96
7380 #define OP_CreateIndex 97
7381 #define OP_CreateTable 98
7382 #define OP_ParseSchema 99
7383 #define OP_LoadAnalysis 100
7384 #define OP_DropTable 101
7385 #define OP_DropIndex 102
7386 #define OP_DropTrigger 103
7387 #define OP_IntegrityCk 104
7388 #define OP_RowSetAdd 105
7389 #define OP_RowSetRead 106
7390 #define OP_RowSetTest 107
7391 #define OP_Program 108
7392 #define OP_Param 109
7393 #define OP_FkCounter 110
7394 #define OP_FkIfZero 111
7395 #define OP_MemMax 112
7396 #define OP_IfPos 113
7397 #define OP_IfNeg 114
7398 #define OP_IfZero 115
7399 #define OP_AggStep 116
7400 #define OP_AggFinal 117
7401 #define OP_Vacuum 118
7402 #define OP_IncrVacuum 119
7403 #define OP_Expire 120
7404 #define OP_TableLock 121
7405 #define OP_VBegin 122
7406 #define OP_VCreate 123
7407 #define OP_VDestroy 124
7408 #define OP_VOpen 125
7409 #define OP_VFilter 126
7410 #define OP_VColumn 127
7411 #define OP_VNext 128
7412 #define OP_VRename 129
7413 #define OP_VUpdate 131
7414 #define OP_Pagecount 132
7415 #define OP_Trace 133
7416 #define OP_Noop 134
7417 #define OP_Explain 135
7418
7419 /* The following opcode values are never used */
7420 #define OP_NotUsed_136 136
7421 #define OP_NotUsed_137 137
7422 #define OP_NotUsed_138 138
7423 #define OP_NotUsed_139 139
7424 #define OP_NotUsed_140 140
@@ -7433,22 +7439,22 @@
7439 /* 0 */ 0x00, 0x01, 0x05, 0x04, 0x04, 0x10, 0x00, 0x02,\
7440 /* 8 */ 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x24, 0x24,\
7441 /* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\
7442 /* 24 */ 0x00, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\
7443 /* 32 */ 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00,\
7444 /* 40 */ 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11,\
7445 /* 48 */ 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00,\
7446 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\
7447 /* 64 */ 0x01, 0x01, 0x01, 0x01, 0x4c, 0x4c, 0x08, 0x00,\
7448 /* 72 */ 0x02, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
7449 /* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
7450 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x01, 0x24, 0x02, 0x02,\
7451 /* 96 */ 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\
7452 /* 104 */ 0x00, 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01,\
7453 /* 112 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x01,\
7454 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,\
7455 /* 128 */ 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,\
7456 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
7457 /* 144 */ 0x04, 0x04,}
7458
7459 /************** End of opcodes.h *********************************************/
7460 /************** Continuing where we left off in vdbe.h ***********************/
@@ -7658,10 +7664,11 @@
7664 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
7665
7666 /* Functions used to query pager state and configuration. */
7667 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
7668 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
7669 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
7670 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
7671 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
7672 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
7673 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
7674 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
@@ -8478,10 +8485,11 @@
8485 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
8486 #define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */
8487 #define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */
8488 #define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
8489 #define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
8490 #define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
8491
8492 /*
8493 ** Bits of the sqlite3.flags field that are used by the
8494 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
8495 ** These must be the low-order bits of the flags field.
@@ -9340,10 +9348,13 @@
9348 **
9349 ** The jointype starts out showing the join type between the current table
9350 ** and the next table on the list. The parser builds the list this way.
9351 ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
9352 ** jointype expresses the join between the table and the previous table.
9353 **
9354 ** In the colUsed field, the high-order bit (bit 63) is set if the table
9355 ** contains more than 63 columns and the 64-th or later column is used.
9356 */
9357 struct SrcList {
9358 i16 nSrc; /* Number of tables or subqueries in the FROM clause */
9359 i16 nAlloc; /* Number of entries allocated in a[] below */
9360 struct SrcList_item {
@@ -9451,11 +9462,11 @@
9462 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
9463 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
9464 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
9465 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
9466 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
9467 #define WHERE_OMIT_OPEN 0x0010 /* Table cursors are already open */
9468 #define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
9469 #define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
9470 #define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
9471
9472 /*
@@ -9474,10 +9485,11 @@
9485 int iTop; /* The very beginning of the WHERE loop */
9486 int iContinue; /* Jump here to continue with next record */
9487 int iBreak; /* Jump here to break out of the loop */
9488 int nLevel; /* Number of nested loop */
9489 struct WhereClause *pWC; /* Decomposition of the WHERE clause */
9490 double savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
9491 WhereLevel a[1]; /* Information about each nest loop in WHERE */
9492 };
9493
9494 /*
9495 ** A NameContext defines a context in which to resolve table and column
@@ -9715,10 +9727,11 @@
9727 u32 oldmask; /* Mask of old.* columns referenced */
9728 u32 newmask; /* Mask of new.* columns referenced */
9729 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
9730 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
9731 u8 disableTriggers; /* True to disable triggers */
9732 double nQueryLoop; /* Estimated number of iterations of a query */
9733
9734 /* Above is constant between recursions. Below is reset before and after
9735 ** each recursion */
9736
9737 int nVar; /* Number of '?' variables seen in the SQL so far */
@@ -10656,11 +10669,50 @@
10669 #else
10670 # define IOTRACE(A)
10671 # define sqlite3VdbeIOTraceSql(X)
10672 #endif
10673
10674 /*
10675 ** These routines are available for the mem2.c debugging memory allocator
10676 ** only. They are used to verify that different "types" of memory
10677 ** allocations are properly tracked by the system.
10678 **
10679 ** sqlite3MemdebugSetType() sets the "type" of an allocation to one of
10680 ** the MEMTYPE_* macros defined below. The type must be a bitmask with
10681 ** a single bit set.
10682 **
10683 ** sqlite3MemdebugHasType() returns true if any of the bits in its second
10684 ** argument match the type set by the previous sqlite3MemdebugSetType().
10685 ** sqlite3MemdebugHasType() is intended for use inside assert() statements.
10686 ** For example:
10687 **
10688 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
10689 **
10690 ** Perhaps the most important point is the difference between MEMTYPE_HEAP
10691 ** and MEMTYPE_DB. If an allocation is MEMTYPE_DB, that means it might have
10692 ** been allocated by lookaside, except the allocation was too large or
10693 ** lookaside was already full. It is important to verify that allocations
10694 ** that might have been satisfied by lookaside are not passed back to
10695 ** non-lookaside free() routines. Asserts such as the example above are
10696 ** placed on the non-lookaside free() routines to verify this constraint.
10697 **
10698 ** All of this is no-op for a production build. It only comes into
10699 ** play when the SQLITE_MEMDEBUG compile-time option is used.
10700 */
10701 #ifdef SQLITE_MEMDEBUG
10702 SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
10703 SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
10704 #else
10705 # define sqlite3MemdebugSetType(X,Y) /* no-op */
10706 # define sqlite3MemdebugHasType(X,Y) 1
10707 #endif
10708 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
10709 #define MEMTYPE_DB 0x02 /* Associated with a database connection */
10710 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
10711 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
10712
10713 #endif /* _SQLITEINT_H_ */
10714
10715 /************** End of sqliteInt.h *******************************************/
10716 /************** Begin file global.c ******************************************/
10717 /*
10718 ** 2008 June 13
@@ -11038,10 +11090,13 @@
11090 #ifdef SQLITE_OMIT_AUTOINCREMENT
11091 "OMIT_AUTOINCREMENT",
11092 #endif
11093 #ifdef SQLITE_OMIT_AUTOINIT
11094 "OMIT_AUTOINIT",
11095 #endif
11096 #ifdef SQLITE_OMIT_AUTOMATIC_INDEX
11097 "OMIT_AUTOMATIC_INDEX",
11098 #endif
11099 #ifdef SQLITE_OMIT_AUTOVACUUM
11100 "OMIT_AUTOVACUUM",
11101 #endif
11102 #ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
@@ -11367,10 +11422,30 @@
11422 if( resetFlag ){
11423 db->lookaside.mxOut = db->lookaside.nOut;
11424 }
11425 break;
11426 }
11427
11428 /*
11429 ** Return an approximation for the amount of memory currently used
11430 ** by all pagers associated with the given database connection. The
11431 ** highwater mark is meaningless and is returned as zero.
11432 */
11433 case SQLITE_DBSTATUS_CACHE_USED: {
11434 int totalUsed = 0;
11435 int i;
11436 for(i=0; i<db->nDb; i++){
11437 Btree *pBt = db->aDb[i].pBt;
11438 if( pBt ){
11439 Pager *pPager = sqlite3BtreePager(pBt);
11440 totalUsed += sqlite3PagerMemUsed(pPager);
11441 }
11442 }
11443 *pCurrent = totalUsed;
11444 *pHighwater = 0;
11445 break;
11446 }
11447 default: {
11448 return SQLITE_ERROR;
11449 }
11450 }
11451 return SQLITE_OK;
@@ -13140,11 +13215,12 @@
13215 struct MemBlockHdr {
13216 i64 iSize; /* Size of this allocation */
13217 struct MemBlockHdr *pNext, *pPrev; /* Linked list of all unfreed memory */
13218 char nBacktrace; /* Number of backtraces on this alloc */
13219 char nBacktraceSlots; /* Available backtrace slots */
13220 u8 nTitle; /* Bytes of title; includes '\0' */
13221 u8 eType; /* Allocation type code */
13222 int iForeGuard; /* Guard word for sanity */
13223 };
13224
13225 /*
13226 ** Guard words
@@ -13348,10 +13424,11 @@
13424 }else{
13425 mem.pFirst = pHdr;
13426 }
13427 mem.pLast = pHdr;
13428 pHdr->iForeGuard = FOREGUARD;
13429 pHdr->eType = MEMTYPE_HEAP;
13430 pHdr->nBacktraceSlots = mem.nBacktrace;
13431 pHdr->nTitle = mem.nTitle;
13432 if( mem.nBacktrace ){
13433 void *aAddr[40];
13434 pHdr->nBacktrace = backtrace(aAddr, mem.nBacktrace+1)-1;
@@ -13454,10 +13531,51 @@
13531 sqlite3MemShutdown,
13532 0
13533 };
13534 sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
13535 }
13536
13537 /*
13538 ** Set the "type" of an allocation.
13539 */
13540 SQLITE_PRIVATE void sqlite3MemdebugSetType(void *p, u8 eType){
13541 if( p ){
13542 struct MemBlockHdr *pHdr;
13543 pHdr = sqlite3MemsysGetHeader(p);
13544 assert( pHdr->iForeGuard==FOREGUARD );
13545 pHdr->eType = eType;
13546 }
13547 }
13548
13549 /*
13550 ** Return TRUE if the mask of type in eType matches the type of the
13551 ** allocation p. Also return true if p==NULL.
13552 **
13553 ** This routine is designed for use within an assert() statement, to
13554 ** verify the type of an allocation. For example:
13555 **
13556 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
13557 */
13558 SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
13559 int rc = 1;
13560 if( p ){
13561 struct MemBlockHdr *pHdr;
13562 pHdr = sqlite3MemsysGetHeader(p);
13563 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
13564 assert( (pHdr->eType & (pHdr->eType-1))==0 ); /* Only one type bit set */
13565 if( (pHdr->eType&eType)==0 ){
13566 void **pBt;
13567 pBt = (void**)pHdr;
13568 pBt -= pHdr->nBacktraceSlots;
13569 backtrace_symbols_fd(pBt, pHdr->nBacktrace, fileno(stderr));
13570 fprintf(stderr, "\n");
13571 rc = 0;
13572 }
13573 }
13574 return rc;
13575 }
13576
13577
13578 /*
13579 ** Set the number of backtrace levels kept for each allocation.
13580 ** A value of zero turns off backtracing. The number is always rounded
13581 ** up to a multiple of 2.
@@ -16446,10 +16564,11 @@
16564 if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
16565 sqlite3_mutex_leave(mem0.mutex);
16566 }else{
16567 p = sqlite3GlobalConfig.m.xMalloc(n);
16568 }
16569 sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
16570 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
16571 scratchAllocOut = p!=0;
16572 #endif
16573 return p;
16574 }
@@ -16466,10 +16585,12 @@
16585 #endif
16586
16587 if( sqlite3GlobalConfig.pScratch==0
16588 || p<sqlite3GlobalConfig.pScratch
16589 || p>=(void*)mem0.aScratchFree ){
16590 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
16591 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
16592 if( sqlite3GlobalConfig.bMemstat ){
16593 int iSize = sqlite3MallocSize(p);
16594 sqlite3_mutex_enter(mem0.mutex);
16595 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
16596 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
@@ -16506,26 +16627,30 @@
16627 /*
16628 ** Return the size of a memory allocation previously obtained from
16629 ** sqlite3Malloc() or sqlite3_malloc().
16630 */
16631 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
16632 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
16633 return sqlite3GlobalConfig.m.xSize(p);
16634 }
16635 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
16636 assert( db==0 || sqlite3_mutex_held(db->mutex) );
16637 if( isLookaside(db, p) ){
16638 return db->lookaside.sz;
16639 }else{
16640 assert( sqlite3MemdebugHasType(p,
16641 db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
16642 return sqlite3GlobalConfig.m.xSize(p);
16643 }
16644 }
16645
16646 /*
16647 ** Free memory previously obtained from sqlite3Malloc().
16648 */
16649 SQLITE_API void sqlite3_free(void *p){
16650 if( p==0 ) return;
16651 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
16652 if( sqlite3GlobalConfig.bMemstat ){
16653 sqlite3_mutex_enter(mem0.mutex);
16654 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
16655 sqlite3GlobalConfig.m.xFree(p);
16656 sqlite3_mutex_leave(mem0.mutex);
@@ -16544,10 +16669,12 @@
16669 LookasideSlot *pBuf = (LookasideSlot*)p;
16670 pBuf->pNext = db->lookaside.pFree;
16671 db->lookaside.pFree = pBuf;
16672 db->lookaside.nOut--;
16673 }else{
16674 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16675 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
16676 sqlite3_free(p);
16677 }
16678 }
16679
16680 /*
@@ -16576,10 +16703,11 @@
16703 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
16704 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
16705 mem0.alarmThreshold ){
16706 sqlite3MallocAlarm(nNew-nOld);
16707 }
16708 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
16709 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
16710 if( pNew==0 && mem0.alarmCallback ){
16711 sqlite3MallocAlarm(nBytes);
16712 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
16713 }
@@ -16673,10 +16801,12 @@
16801 #endif
16802 p = sqlite3Malloc(n);
16803 if( !p && db ){
16804 db->mallocFailed = 1;
16805 }
16806 sqlite3MemdebugSetType(p,
16807 (db && db->lookaside.bEnabled) ? MEMTYPE_DB : MEMTYPE_HEAP);
16808 return p;
16809 }
16810
16811 /*
16812 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -16698,14 +16828,18 @@
16828 if( pNew ){
16829 memcpy(pNew, p, db->lookaside.sz);
16830 sqlite3DbFree(db, p);
16831 }
16832 }else{
16833 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16834 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
16835 pNew = sqlite3_realloc(p, n);
16836 if( !pNew ){
16837 db->mallocFailed = 1;
16838 }
16839 sqlite3MemdebugSetType(pNew,
16840 db->lookaside.bEnabled ? MEMTYPE_DB : MEMTYPE_HEAP);
16841 }
16842 }
16843 return pNew;
16844 }
16845
@@ -18305,11 +18439,11 @@
18439 u8 isPrepareV2; /* True if prepared with prepare_v2() */
18440 int nChange; /* Number of db changes made since last reset */
18441 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
18442 i64 startTime; /* Time when query started - used for profiling */
18443 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
18444 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
18445 char *zSql; /* Text of the SQL statement that generated this */
18446 void *pFree; /* Free this when deleting the vdbe */
18447 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
18448 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
18449 int iStatement; /* Statement number (or 0 if has not opened stmt) */
@@ -20345,52 +20479,52 @@
20479 /* 35 */ "ReadCookie",
20480 /* 36 */ "SetCookie",
20481 /* 37 */ "VerifyCookie",
20482 /* 38 */ "OpenRead",
20483 /* 39 */ "OpenWrite",
20484 /* 40 */ "OpenAutoindex",
20485 /* 41 */ "OpenEphemeral",
20486 /* 42 */ "OpenPseudo",
20487 /* 43 */ "Close",
20488 /* 44 */ "SeekLt",
20489 /* 45 */ "SeekLe",
20490 /* 46 */ "SeekGe",
20491 /* 47 */ "SeekGt",
20492 /* 48 */ "Seek",
20493 /* 49 */ "NotFound",
20494 /* 50 */ "Found",
20495 /* 51 */ "IsUnique",
20496 /* 52 */ "NotExists",
20497 /* 53 */ "Sequence",
20498 /* 54 */ "NewRowid",
20499 /* 55 */ "Insert",
20500 /* 56 */ "InsertInt",
20501 /* 57 */ "Delete",
20502 /* 58 */ "ResetCount",
20503 /* 59 */ "RowKey",
20504 /* 60 */ "RowData",
20505 /* 61 */ "Rowid",
20506 /* 62 */ "NullRow",
20507 /* 63 */ "Last",
20508 /* 64 */ "Sort",
20509 /* 65 */ "Rewind",
20510 /* 66 */ "Prev",
20511 /* 67 */ "Next",
20512 /* 68 */ "Or",
20513 /* 69 */ "And",
20514 /* 70 */ "IdxInsert",
20515 /* 71 */ "IdxDelete",
20516 /* 72 */ "IdxRowid",
20517 /* 73 */ "IsNull",
20518 /* 74 */ "NotNull",
20519 /* 75 */ "Ne",
20520 /* 76 */ "Eq",
20521 /* 77 */ "Gt",
20522 /* 78 */ "Le",
20523 /* 79 */ "Lt",
20524 /* 80 */ "Ge",
20525 /* 81 */ "IdxLT",
20526 /* 82 */ "BitAnd",
20527 /* 83 */ "BitOr",
20528 /* 84 */ "ShiftLeft",
20529 /* 85 */ "ShiftRight",
20530 /* 86 */ "Add",
@@ -20397,54 +20531,54 @@
20531 /* 87 */ "Subtract",
20532 /* 88 */ "Multiply",
20533 /* 89 */ "Divide",
20534 /* 90 */ "Remainder",
20535 /* 91 */ "Concat",
20536 /* 92 */ "IdxGE",
20537 /* 93 */ "BitNot",
20538 /* 94 */ "String8",
20539 /* 95 */ "Destroy",
20540 /* 96 */ "Clear",
20541 /* 97 */ "CreateIndex",
20542 /* 98 */ "CreateTable",
20543 /* 99 */ "ParseSchema",
20544 /* 100 */ "LoadAnalysis",
20545 /* 101 */ "DropTable",
20546 /* 102 */ "DropIndex",
20547 /* 103 */ "DropTrigger",
20548 /* 104 */ "IntegrityCk",
20549 /* 105 */ "RowSetAdd",
20550 /* 106 */ "RowSetRead",
20551 /* 107 */ "RowSetTest",
20552 /* 108 */ "Program",
20553 /* 109 */ "Param",
20554 /* 110 */ "FkCounter",
20555 /* 111 */ "FkIfZero",
20556 /* 112 */ "MemMax",
20557 /* 113 */ "IfPos",
20558 /* 114 */ "IfNeg",
20559 /* 115 */ "IfZero",
20560 /* 116 */ "AggStep",
20561 /* 117 */ "AggFinal",
20562 /* 118 */ "Vacuum",
20563 /* 119 */ "IncrVacuum",
20564 /* 120 */ "Expire",
20565 /* 121 */ "TableLock",
20566 /* 122 */ "VBegin",
20567 /* 123 */ "VCreate",
20568 /* 124 */ "VDestroy",
20569 /* 125 */ "VOpen",
20570 /* 126 */ "VFilter",
20571 /* 127 */ "VColumn",
20572 /* 128 */ "VNext",
20573 /* 129 */ "VRename",
20574 /* 130 */ "Real",
20575 /* 131 */ "VUpdate",
20576 /* 132 */ "Pagecount",
20577 /* 133 */ "Trace",
20578 /* 134 */ "Noop",
20579 /* 135 */ "Explain",
20580 /* 136 */ "NotUsed_136",
20581 /* 137 */ "NotUsed_137",
20582 /* 138 */ "NotUsed_138",
20583 /* 139 */ "NotUsed_139",
20584 /* 140 */ "NotUsed_140",
@@ -26155,13 +26289,11 @@
26289 flags |= SQLITE_OPEN_READONLY;
26290 openFlags |= O_RDONLY;
26291 fd = open(zName, openFlags, openMode);
26292 }
26293 if( fd<0 ){
26294 rc = SQLITE_CANTOPEN_BKPT;
 
 
26295 goto open_finished;
26296 }
26297 }
26298 assert( fd>=0 );
26299 if( pOutFlags ){
@@ -30816,11 +30948,16 @@
30948 if( pCache->pCache ){
30949 PgHdr *p;
30950 PgHdr *pNext;
30951 for(p=pCache->pDirty; p; p=pNext){
30952 pNext = p->pDirtyNext;
30953 /* This routine never gets call with a positive pgno except right
30954 ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
30955 ** it must be that pgno==0.
30956 */
30957 assert( p->pgno>0 );
30958 if( ALWAYS(p->pgno>pgno) ){
30959 assert( p->flags&PGHDR_DIRTY );
30960 sqlite3PcacheMakeClean(p);
30961 }
30962 }
30963 if( pgno==0 && pCache->pPage1 ){
@@ -31160,10 +31297,11 @@
31297 pcache1EnterMutex();
31298 if( p ){
31299 int sz = sqlite3MallocSize(p);
31300 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
31301 }
31302 sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
31303 }
31304 return p;
31305 }
31306
31307 /*
@@ -31177,11 +31315,14 @@
31315 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
31316 pSlot = (PgFreeslot*)p;
31317 pSlot->pNext = pcache1.pFree;
31318 pcache1.pFree = pSlot;
31319 }else{
31320 int iSize;
31321 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
31322 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
31323 iSize = sqlite3MallocSize(p);
31324 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
31325 sqlite3_free(p);
31326 }
31327 }
31328
@@ -32213,10 +32354,91 @@
32354 ** file simultaneously, or one process from reading the database while
32355 ** another is writing.
32356 */
32357 #ifndef SQLITE_OMIT_DISKIO
32358
32359 /*
32360 ******************** NOTES ON THE DESIGN OF THE PAGER ************************
32361 **
32362 ** Within this comment block, a page is deemed to have been synced
32363 ** automatically as soon as it is written when PRAGMA synchronous=OFF.
32364 ** Otherwise, the page is not synced until the xSync method of the VFS
32365 ** is called successfully on the file containing the page.
32366 **
32367 ** Definition: A page of the database file is said to be "overwriteable" if
32368 ** one or more of the following are true about the page:
32369 **
32370 ** (a) The original content of the page as it was at the beginning of
32371 ** the transaction has been written into the rollback journal and
32372 ** synced.
32373 **
32374 ** (b) The page was a freelist leaf page at the start of the transaction.
32375 **
32376 ** (c) The page number is greater than the largest page that existed in
32377 ** the database file at the start of the transaction.
32378 **
32379 ** (1) A page of the database file is never overwritten unless one of the
32380 ** following are true:
32381 **
32382 ** (a) The page and all other pages on the same sector are overwriteable.
32383 **
32384 ** (b) The atomic page write optimization is enabled, and the entire
32385 ** transaction other than the update of the transaction sequence
32386 ** number consists of a single page change.
32387 **
32388 ** (2) The content of a page written into the rollback journal exactly matches
32389 ** both the content in the database when the rollback journal was written
32390 ** and the content in the database at the beginning of the current
32391 ** transaction.
32392 **
32393 ** (3) Writes to the database file are an integer multiple of the page size
32394 ** in length and are aligned to a page boundary.
32395 **
32396 ** (4) Reads from the database file are either aligned on a page boundary and
32397 ** an integer multiple of the page size in length or are taken from the
32398 ** first 100 bytes of the database file.
32399 **
32400 ** (5) All writes to the database file are synced prior to the rollback journal
32401 ** being deleted, truncated, or zeroed.
32402 **
32403 ** (6) If a master journal file is used, then all writes to the database file
32404 ** are synced prior to the master journal being deleted.
32405 **
32406 ** Definition: Two databases (or the same database at two points it time)
32407 ** are said to be "logically equivalent" if they give the same answer to
32408 ** all queries. Note in particular the the content of freelist leaf
32409 ** pages can be changed arbitarily without effecting the logical equivalence
32410 ** of the database.
32411 **
32412 ** (7) At any time, if any subset, including the empty set and the total set,
32413 ** of the unsynced changes to a rollback journal are removed and the
32414 ** journal is rolled back, the resulting database file will be logical
32415 ** equivalent to the database file at the beginning of the transaction.
32416 **
32417 ** (8) When a transaction is rolled back, the xTruncate method of the VFS
32418 ** is called to restore the database file to the same size it was at
32419 ** the beginning of the transaction. (In some VFSes, the xTruncate
32420 ** method is a no-op, but that does not change the fact the SQLite will
32421 ** invoke it.)
32422 **
32423 ** (9) Whenever the database file is modified, at least one bit in the range
32424 ** of bytes from 24 through 39 inclusive will be changed prior to releasing
32425 ** the EXCLUSIVE lock.
32426 **
32427 ** (10) The pattern of bits in bytes 24 through 39 shall not repeat in less
32428 ** than one billion transactions.
32429 **
32430 ** (11) A database file is well-formed at the beginning and at the conclusion
32431 ** of every transaction.
32432 **
32433 ** (12) An EXCLUSIVE lock is held on the database file when writing to
32434 ** the database file.
32435 **
32436 ** (13) A SHARED lock is held on the database file while reading any
32437 ** content out of the database file.
32438 */
32439
32440 /*
32441 ** Macros for troubleshooting. Normally turned off
32442 */
32443 #if 0
32444 int sqlite3PagerTrace=1; /* True to enable tracing */
@@ -32389,11 +32611,12 @@
32611 ** It is used when committing or otherwise ending a transaction. If
32612 ** the dbModified flag is clear then less work has to be done.
32613 **
32614 ** journalStarted
32615 **
32616 ** This flag is set whenever the the main journal is opened and
32617 ** initialized
32618 **
32619 ** The point of this flag is that it must be set after the
32620 ** first journal header in a journal file has been synced to disk.
32621 ** After this has happened, new pages appended to the database
32622 ** do not need the PGHDR_NEED_SYNC flag set, as they do not need
@@ -32415,11 +32638,14 @@
32638 ** master journal name is only written to the journal file the first
32639 ** time CommitPhaseOne() is called.
32640 **
32641 ** doNotSync
32642 **
32643 ** When enabled, cache spills are prohibited and the journal file cannot
32644 ** be synced. This variable is set and cleared by sqlite3PagerWrite()
32645 ** in order to prevent a journal sync from happening in between the
32646 ** journalling of two pages on the same sector.
32647 **
32648 ** needSync
32649 **
32650 ** TODO: It might be easier to set this variable in writeJournalHdr()
32651 ** and writeMasterJournal() only. Change its meaning to "unsynced data
@@ -32475,10 +32701,11 @@
32701 sqlite3_file *fd; /* File descriptor for database */
32702 sqlite3_file *jfd; /* File descriptor for main journal */
32703 sqlite3_file *sjfd; /* File descriptor for sub-journal */
32704 i64 journalOff; /* Current write offset in the journal file */
32705 i64 journalHdr; /* Byte offset to previous journal header */
32706 i64 journalSizeLimit; /* Size limit for persistent journal files */
32707 PagerSavepoint *aSavepoint; /* Array of active savepoints */
32708 int nSavepoint; /* Number of elements in aSavepoint[] */
32709 char dbFileVers[16]; /* Changes whenever database file changes */
32710 u32 sectorSize; /* Assumed sector size during rollback */
32711
@@ -32501,11 +32728,10 @@
32728 void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */
32729 void (*xCodecFree)(void*); /* Destructor for the codec */
32730 void *pCodec; /* First argument to xCodec... methods */
32731 #endif
32732 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
 
32733 PCache *pPCache; /* Pointer to page cache object */
32734 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
32735 };
32736
32737 /*
@@ -33017,10 +33243,11 @@
33243 ** to populate the entire journal header sector.
33244 */
33245 for(nWrite=0; rc==SQLITE_OK&&nWrite<JOURNAL_HDR_SZ(pPager); nWrite+=nHeader){
33246 IOTRACE(("JHDR %p %lld %d\n", pPager, pPager->journalHdr, nHeader))
33247 rc = sqlite3OsWrite(pPager->jfd, zHeader, nHeader, pPager->journalOff);
33248 assert( pPager->journalHdr <= pPager->journalOff );
33249 pPager->journalOff += nHeader;
33250 }
33251
33252 return rc;
33253 }
@@ -33175,10 +33402,11 @@
33402 ){
33403 return SQLITE_OK;
33404 }
33405 pPager->setMaster = 1;
33406 assert( isOpen(pPager->jfd) );
33407 assert( pPager->journalHdr <= pPager->journalOff );
33408
33409 /* Calculate the length in bytes and the checksum of zMaster */
33410 for(nMaster=0; zMaster[nMaster]; nMaster++){
33411 cksum += zMaster[nMaster];
33412 }
@@ -33315,12 +33543,13 @@
33543 pPager->pInJournal = 0;
33544 releaseAllSavepoints(pPager);
33545
33546 /* If the file is unlocked, somebody else might change it. The
33547 ** values stored in Pager.dbSize etc. might become invalid if
33548 ** this happens. One can argue that this doesn't need to be cleared
33549 ** until the change-counter check fails in PagerSharedLock().
33550 ** Clearing the page size cache here is being conservative.
33551 */
33552 pPager->dbSizeValid = 0;
33553
33554 rc = osUnlock(pPager->fd, NO_LOCK);
33555 if( rc ){
@@ -33506,16 +33735,15 @@
33735 }
33736
33737 #ifdef SQLITE_CHECK_PAGES
33738 sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
33739 #endif
 
 
 
 
 
33740 }
33741 sqlite3BitvecDestroy(pPager->pInJournal);
33742 pPager->pInJournal = 0;
33743 pPager->nRec = 0;
33744 sqlite3PcacheCleanAll(pPager->pPCache);
33745
33746 if( !pPager->exclusiveMode ){
33747 rc2 = osUnlock(pPager->fd, SHARED_LOCK);
33748 pPager->state = PAGER_SHARED;
33749 pPager->changeCountDone = 0;
@@ -33604,22 +33832,22 @@
33832 ** allocated by this function. If this is the case and an allocation fails,
33833 ** SQLITE_NOMEM is returned.
33834 */
33835 static int pager_playback_one_page(
33836 Pager *pPager, /* The pager being played back */
 
 
33837 i64 *pOffset, /* Offset of record to playback */
33838 Bitvec *pDone, /* Bitvec of pages already played back */
33839 int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
33840 int isSavepnt /* True for a savepoint rollback */
33841 ){
33842 int rc;
33843 PgHdr *pPg; /* An existing page in the cache */
33844 Pgno pgno; /* The page number of a page in journal */
33845 u32 cksum; /* Checksum used for sanity checking */
33846 char *aData; /* Temporary storage for the page */
33847 sqlite3_file *jfd; /* The file descriptor for the journal file */
33848 int isSynced; /* True if journal page is synced */
33849
33850 assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
33851 assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
33852 assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */
33853 assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
@@ -33699,16 +33927,21 @@
33927 assert( pPg || !MEMDB );
33928 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
33929 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
33930 (isMainJrnl?"main-journal":"sub-journal")
33931 ));
33932 if( isMainJrnl ){
33933 isSynced = pPager->noSync || (*pOffset <= pPager->journalHdr);
33934 }else{
33935 isSynced = (pPg==0 || 0==(pPg->flags & PGHDR_NEED_SYNC));
33936 }
33937 if( (pPager->state>=PAGER_EXCLUSIVE)
 
33938 && isOpen(pPager->fd)
33939 && isSynced
33940 ){
33941 i64 ofst = (pgno-1)*(i64)pPager->pageSize;
33942 testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
33943 rc = sqlite3OsWrite(pPager->fd, (u8*)aData, pPager->pageSize, ofst);
33944 if( pgno>pPager->dbFileSize ){
33945 pPager->dbFileSize = pgno;
33946 }
33947 if( pPager->pBackup ){
@@ -33753,11 +33986,12 @@
33986 pPager->xReiniter(pPg);
33987 if( isMainJrnl && (!isSavepnt || *pOffset<=pPager->journalHdr) ){
33988 /* If the contents of this page were just restored from the main
33989 ** journal file, then its content must be as they were when the
33990 ** transaction was first opened. In this case we can mark the page
33991 ** as clean, since there will be no need to write it out to the
33992 ** database.
33993 **
33994 ** There is one exception to this rule. If the page is being rolled
33995 ** back as part of a savepoint (or statement) rollback from an
33996 ** unsynced portion of the main journal file, then it is not safe
33997 ** to mark the page as clean. This is because marking the page as
@@ -34100,12 +34334,10 @@
34334 /* This loop terminates either when a readJournalHdr() or
34335 ** pager_playback_one_page() call returns SQLITE_DONE or an IO error
34336 ** occurs.
34337 */
34338 while( 1 ){
 
 
34339 /* Read the next journal header from the journal file. If there are
34340 ** not enough bytes left in the journal file for a complete header, or
34341 ** it is corrupted, then a process must of failed while writing it.
34342 ** This indicates nothing more needs to be rolled back.
34343 */
@@ -34142,11 +34374,10 @@
34374 ** should be computed based on the journal file size.
34375 */
34376 if( nRec==0 && !isHot &&
34377 pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){
34378 nRec = (int)((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager));
 
34379 }
34380
34381 /* If this is the first header read from the journal, truncate the
34382 ** database file back to its original size.
34383 */
@@ -34164,16 +34395,24 @@
34395 for(u=0; u<nRec; u++){
34396 if( needPagerReset ){
34397 pager_reset(pPager);
34398 needPagerReset = 0;
34399 }
34400 rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
34401 if( rc!=SQLITE_OK ){
34402 if( rc==SQLITE_DONE ){
34403 rc = SQLITE_OK;
34404 pPager->journalOff = szJ;
34405 break;
34406 }else if( rc==SQLITE_IOERR_SHORT_READ ){
34407 /* If the journal has been truncated, simply stop reading and
34408 ** processing the journal. This might happen if the journal was
34409 ** not completely written and synced prior to a crash. In that
34410 ** case, the database should have never been written in the
34411 ** first place so it is OK to simply abandon the rollback. */
34412 rc = SQLITE_OK;
34413 goto end_playback;
34414 }else{
34415 /* If we are unable to rollback, quit and return the error
34416 ** code. This will cause the pager to enter the error state
34417 ** so that no further harm will be done. Perhaps the next
34418 ** process to come along will be able to rollback the database.
@@ -34309,11 +34548,11 @@
34548 */
34549 if( pSavepoint ){
34550 iHdrOff = pSavepoint->iHdrOffset ? pSavepoint->iHdrOffset : szJ;
34551 pPager->journalOff = pSavepoint->iOffset;
34552 while( rc==SQLITE_OK && pPager->journalOff<iHdrOff ){
34553 rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
34554 }
34555 assert( rc!=SQLITE_DONE );
34556 }else{
34557 pPager->journalOff = 0;
34558 }
@@ -34339,11 +34578,11 @@
34578 && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff
34579 ){
34580 nJRec = (u32)((szJ - pPager->journalOff)/JOURNAL_PG_SZ(pPager));
34581 }
34582 for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
34583 rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
34584 }
34585 assert( rc!=SQLITE_DONE );
34586 }
34587 assert( rc!=SQLITE_OK || pPager->journalOff==szJ );
34588
@@ -34354,11 +34593,11 @@
34593 if( pSavepoint ){
34594 u32 ii; /* Loop counter */
34595 i64 offset = pSavepoint->iSubRec*(4+pPager->pageSize);
34596 for(ii=pSavepoint->iSubRec; rc==SQLITE_OK && ii<pPager->nSubRec; ii++){
34597 assert( offset==ii*(4+pPager->pageSize) );
34598 rc = pager_playback_one_page(pPager, &offset, pDone, 0, 1);
34599 }
34600 assert( rc!=SQLITE_DONE );
34601 }
34602
34603 sqlite3BitvecDestroy(pDone);
@@ -34575,14 +34814,16 @@
34814 ** maximum page count below the current size of the database.
34815 **
34816 ** Regardless of mxPage, return the current maximum page count.
34817 */
34818 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
34819 int nPage;
34820 if( mxPage>0 ){
34821 pPager->mxPgno = mxPage;
34822 }
34823 sqlite3PagerPagecount(pPager, &nPage);
34824 assert( pPager->mxPgno>=nPage );
34825 return pPager->mxPgno;
34826 }
34827
34828 /*
34829 ** The following set of routines are used to disable the simulated
@@ -34652,15 +34893,10 @@
34893 ** and *pnPage is set to the number of pages in the database.
34894 */
34895 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
34896 Pgno nPage; /* Value to return via *pnPage */
34897
 
 
 
 
 
34898 /* Determine the number of pages in the file. Store this in nPage. */
34899 if( pPager->dbSizeValid ){
34900 nPage = pPager->dbSize;
34901 }else{
34902 int rc; /* Error returned by OsFileSize() */
@@ -34690,13 +34926,11 @@
34926 if( nPage>pPager->mxPgno ){
34927 pPager->mxPgno = (Pgno)nPage;
34928 }
34929
34930 /* Set the output variable and return SQLITE_OK */
34931 *pnPage = nPage;
 
 
34932 return SQLITE_OK;
34933 }
34934
34935
34936 /*
@@ -34796,10 +35030,35 @@
35030 assert( pPager->dbSize>=nPage );
35031 assert( pPager->state>=PAGER_RESERVED );
35032 pPager->dbSize = nPage;
35033 assertTruncateConstraint(pPager);
35034 }
35035
35036 /*
35037 ** This function is called before attempting a hot-journal rollback. It
35038 ** syncs the journal file to disk, then sets pPager->journalHdr to the
35039 ** size of the journal file so that the pager_playback() routine knows
35040 ** that the entire journal file has been synced.
35041 **
35042 ** Syncing a hot-journal to disk before attempting to roll it back ensures
35043 ** that if a power-failure occurs during the rollback, the process that
35044 ** attempts rollback following system recovery sees the same journal
35045 ** content as this process.
35046 **
35047 ** If everything goes as planned, SQLITE_OK is returned. Otherwise,
35048 ** an SQLite error code.
35049 */
35050 static int pagerSyncHotJournal(Pager *pPager){
35051 int rc = SQLITE_OK;
35052 if( !pPager->noSync ){
35053 rc = sqlite3OsSync(pPager->jfd, SQLITE_SYNC_NORMAL);
35054 }
35055 if( rc==SQLITE_OK ){
35056 rc = sqlite3OsFileSize(pPager->jfd, &pPager->journalHdr);
35057 }
35058 return rc;
35059 }
35060
35061 /*
35062 ** Shutdown the page cache. Free all memory and close all files.
35063 **
35064 ** If a transaction was in progress when this routine is called, that
@@ -34826,11 +35085,13 @@
35085 ** call which may be made from within pagerUnlockAndRollback(). If it
35086 ** is not -1, then the unsynced portion of an open journal file may
35087 ** be played back into the database. If a power failure occurs while
35088 ** this is happening, the database may become corrupt.
35089 */
35090 if( isOpen(pPager->jfd) ){
35091 pPager->errCode = pagerSyncHotJournal(pPager);
35092 }
35093 pagerUnlockAndRollback(pPager);
35094 }
35095 sqlite3EndBenignMalloc();
35096 enable_simulated_io_errors();
35097 PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
@@ -34916,11 +35177,11 @@
35177 /* This block deals with an obscure problem. If the last connection
35178 ** that wrote to this database was operating in persistent-journal
35179 ** mode, then the journal file may at this point actually be larger
35180 ** than Pager.journalOff bytes. If the next thing in the journal
35181 ** file happens to be a journal-header (written as part of the
35182 ** previous connection's transaction), and a crash or power-failure
35183 ** occurs after nRec is updated but before this connection writes
35184 ** anything else to the journal file (or commits/rolls back its
35185 ** transaction), then SQLite may become confused when doing the
35186 ** hot-journal rollback following recovery. It may roll back all
35187 ** of this connections data, then proceed to rolling back the old,
@@ -34988,10 +35249,11 @@
35249 /* The journal file was just successfully synced. Set Pager.needSync
35250 ** to zero and clear the PGHDR_NEED_SYNC flag on all pagess.
35251 */
35252 pPager->needSync = 0;
35253 pPager->journalStarted = 1;
35254 pPager->journalHdr = pPager->journalOff;
35255 sqlite3PcacheClearSyncFlags(pPager->pPCache);
35256 }
35257
35258 return SQLITE_OK;
35259 }
@@ -35850,23 +36112,32 @@
36112 }
36113 if( rc!=SQLITE_OK ){
36114 goto failed;
36115 }
36116
36117 /* Reset the journal status fields to indicates that we have no
36118 ** rollback journal at this time. */
36119 pPager->journalStarted = 0;
36120 pPager->journalOff = 0;
36121 pPager->setMaster = 0;
36122 pPager->journalHdr = 0;
36123
36124 /* Make sure the journal file has been synced to disk. */
36125
36126 /* Playback and delete the journal. Drop the database write
36127 ** lock and reacquire the read lock. Purge the cache before
36128 ** playing back the hot-journal so that we don't end up with
36129 ** an inconsistent cache. Sync the hot journal before playing
36130 ** it back since the process that crashed and left the hot journal
36131 ** probably did not sync it and we are required to always sync
36132 ** the journal before playing it back.
36133 */
36134 if( isOpen(pPager->jfd) ){
36135 rc = pagerSyncHotJournal(pPager);
36136 if( rc==SQLITE_OK ){
36137 rc = pager_playback(pPager, 1);
36138 }
36139 if( rc!=SQLITE_OK ){
36140 rc = pager_error(pPager, rc);
36141 goto failed;
36142 }
36143 }
@@ -35890,20 +36161,20 @@
36161 **
36162 ** There is a vanishingly small chance that a change will not be
36163 ** detected. The chance of an undetected change is so small that
36164 ** it can be neglected.
36165 */
36166 int nPage;
36167 char dbFileVers[sizeof(pPager->dbFileVers)];
36168 sqlite3PagerPagecount(pPager, &nPage);
36169
36170 if( pPager->errCode ){
36171 rc = pPager->errCode;
36172 goto failed;
36173 }
36174
36175 if( nPage>0 ){
 
36176 IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
36177 rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
36178 if( rc!=SQLITE_OK ){
36179 goto failed;
36180 }
@@ -35968,11 +36239,11 @@
36239 ** of the page. This occurs in two seperate scenarios:
36240 **
36241 ** a) When reading a free-list leaf page from the database, and
36242 **
36243 ** b) When a savepoint is being rolled back and we need to load
36244 ** a new page into the cache to be filled with the data read
36245 ** from the savepoint journal.
36246 **
36247 ** If noContent is true, then the data returned is zeroed instead of
36248 ** being read from the database. Additionally, the bits corresponding
36249 ** to pgno in Pager.pInJournal (bitvec of pages already written to the
@@ -36024,11 +36295,11 @@
36295 goto pager_acquire_err;
36296 }
36297 assert( (*ppPage)->pgno==pgno );
36298 assert( (*ppPage)->pPager==pPager || (*ppPage)->pPager==0 );
36299
36300 if( (*ppPage)->pPager && !noContent ){
36301 /* In this case the pcache already contains an initialized copy of
36302 ** the page. Return without further ado. */
36303 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
36304 PAGER_INCR(pPager->nHit);
36305 return SQLITE_OK;
@@ -36184,10 +36455,11 @@
36455 ** SQLITE_NOMEM if the attempt to allocate Pager.pInJournal fails, or
36456 ** an IO error code if opening or writing the journal file fails.
36457 */
36458 static int pager_open_journal(Pager *pPager){
36459 int rc = SQLITE_OK; /* Return code */
36460 int nPage; /* Size of database file */
36461 sqlite3_vfs * const pVfs = pPager->pVfs; /* Local cache of vfs pointer */
36462
36463 assert( pPager->state>=PAGER_RESERVED );
36464 assert( pPager->useJournal );
36465 assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF );
@@ -36196,17 +36468,14 @@
36468 /* If already in the error state, this function is a no-op. But on
36469 ** the other hand, this routine is never called if we are already in
36470 ** an error state. */
36471 if( NEVER(pPager->errCode) ) return pPager->errCode;
36472
 
 
 
36473 testcase( pPager->dbSizeValid==0 );
36474 rc = sqlite3PagerPagecount(pPager, &nPage);
36475 if( rc ) return rc;
36476 pPager->pInJournal = sqlite3BitvecCreate(nPage);
36477 if( pPager->pInJournal==0 ){
36478 return SQLITE_NOMEM;
36479 }
36480
36481 /* Open the journal file if it is not already open. */
@@ -36301,16 +36570,15 @@
36570 if( exFlag ){
36571 rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
36572 }
36573 }
36574
36575 /* No need to open the journal file at this time. It will be
36576 ** opened before it is written to. If we defer opening the journal,
36577 ** we might save the work of creating a file if the transaction
36578 ** ends up being a no-op.
36579 */
 
 
 
36580 }else if( isOpen(pPager->jfd) && pPager->journalOff==0 ){
36581 /* This happens when the pager was in exclusive-access mode the last
36582 ** time a (read or write) transaction was successfully concluded
36583 ** by this connection. Instead of deleting the journal file it was
36584 ** kept open and either was truncated to 0 bytes or its header was
@@ -36321,11 +36589,10 @@
36589 assert( pPager->pInJournal==0 );
36590 rc = pager_open_journal(pPager);
36591 }
36592
36593 PAGERTRACE(("TRANSACTION %d\n", PAGERID(pPager)));
 
36594 if( rc!=SQLITE_OK ){
36595 assert( !pPager->dbModified );
36596 /* Ignore any IO error that occurs within pager_end_transaction(). The
36597 ** purpose of this call is to reset the internal state of the pager
36598 ** sub-system. It doesn't matter if the journal-file is not properly
@@ -36351,12 +36618,12 @@
36618 /* This routine is not called unless a transaction has already been
36619 ** started.
36620 */
36621 assert( pPager->state>=PAGER_RESERVED );
36622
36623 /* If an error has been previously detected, report the same error
36624 ** again.
36625 */
36626 if( NEVER(pPager->errCode) ) return pPager->errCode;
36627
36628 /* Higher-level routines never call this function if database is not
36629 ** writable. But check anyway, just for robustness. */
@@ -36377,15 +36644,15 @@
36644 /* If we get this far, it means that the page needs to be
36645 ** written to the transaction journal or the ckeckpoint journal
36646 ** or both.
36647 **
36648 ** Higher level routines should have already started a transaction,
36649 ** which means they have acquired the necessary locks but the rollback
36650 ** journal might not yet be open.
36651 */
36652 rc = sqlite3PagerBegin(pPager, 0, pPager->subjInMemory);
36653 if( rc!=SQLITE_OK ){
36654 return rc;
36655 }
36656 if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
36657 assert( pPager->useJournal );
36658 rc = pager_open_journal(pPager);
@@ -36404,10 +36671,12 @@
36671
36672 /* We should never write to the journal file the page that
36673 ** contains the database locks. The following assert verifies
36674 ** that we do not. */
36675 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
36676
36677 assert( pPager->journalHdr <= pPager->journalOff );
36678 CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
36679 cksum = pager_cksum(pPager, (u8*)pData2);
36680 rc = write32bits(pPager->jfd, pPager->journalOff, pPg->pgno);
36681 if( rc==SQLITE_OK ){
36682 rc = sqlite3OsWrite(pPager->jfd, pData2, pPager->pageSize,
@@ -36523,11 +36792,12 @@
36792 ** an integer power of 2. It sets variable pg1 to the identifier
36793 ** of the first page of the sector pPg is located on.
36794 */
36795 pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
36796
36797 rc = sqlite3PagerPagecount(pPager, (int *)&nPageCount);
36798 if( rc ) return rc;
36799 if( pPg->pgno>nPageCount ){
36800 nPage = (pPg->pgno - pg1)+1;
36801 }else if( (pg1+nPagePerSector-1)>nPageCount ){
36802 nPage = nPageCount+1-pg1;
36803 }else{
@@ -36684,10 +36954,13 @@
36954 /* Increment the value just read and write it back to byte 24. */
36955 change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
36956 change_counter++;
36957 put32bits(((char*)pPgHdr->pData)+24, change_counter);
36958
36959 /* Also store the SQLite version number in bytes 96..99 */
36960 put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
36961
36962 /* If running in direct mode, write the contents of page 1 to the file. */
36963 if( DIRECT_MODE ){
36964 const void *zBuf = pPgHdr->pData;
36965 assert( pPager->dbFileSize>0 );
36966 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
@@ -36757,13 +37030,11 @@
37030 int rc = SQLITE_OK; /* Return code */
37031
37032 /* The dbOrigSize is never set if journal_mode=OFF */
37033 assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF || pPager->dbOrigSize==0 );
37034
37035 /* If a prior error occurred, report that error again. */
 
 
37036 if( NEVER(pPager->errCode) ) return pPager->errCode;
37037
37038 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
37039 pPager->zFilename, zMaster, pPager->dbSize));
37040
@@ -37048,10 +37319,20 @@
37319 ** Return the number of references to the pager.
37320 */
37321 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
37322 return sqlite3PcacheRefCount(pPager->pPCache);
37323 }
37324
37325 /*
37326 ** Return the approximate number of bytes of memory currently
37327 ** used by the pager and its associated cache.
37328 */
37329 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
37330 int perPageSize = pPager->pageSize + pPager->nExtra + 20;
37331 return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
37332 + sqlite3MallocSize(pPager);
37333 }
37334
37335 /*
37336 ** Return the number of references to the specified page.
37337 */
37338 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage *pPage){
@@ -37101,15 +37382,14 @@
37382 int nCurrent = pPager->nSavepoint; /* Current number of savepoints */
37383
37384 if( nSavepoint>nCurrent && pPager->useJournal ){
37385 int ii; /* Iterator variable */
37386 PagerSavepoint *aNew; /* New Pager.aSavepoint array */
37387 int nPage; /* Size of database file */
37388
37389 rc = sqlite3PagerPagecount(pPager, &nPage);
37390 if( rc ) return rc;
 
 
37391
37392 /* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
37393 ** if the allocation fails. Otherwise, zero the new portion in case a
37394 ** malloc failure occurs while populating it in the for(...) loop below.
37395 */
@@ -37123,19 +37403,18 @@
37403 pPager->aSavepoint = aNew;
37404 pPager->nSavepoint = nSavepoint;
37405
37406 /* Populate the PagerSavepoint structures just allocated. */
37407 for(ii=nCurrent; ii<nSavepoint; ii++){
37408 aNew[ii].nOrig = nPage;
37409 if( isOpen(pPager->jfd) && pPager->journalOff>0 ){
 
37410 aNew[ii].iOffset = pPager->journalOff;
37411 }else{
37412 aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
37413 }
37414 aNew[ii].iSubRec = pPager->nSubRec;
37415 aNew[ii].pInSavepoint = sqlite3BitvecCreate(nPage);
37416 if( !aNew[ii].pInSavepoint ){
37417 return SQLITE_NOMEM;
37418 }
37419 }
37420
@@ -37518,10 +37797,19 @@
37797 && (!isOpen(pPager->jfd) || 0==pPager->journalOff)
37798 ){
37799 if( isOpen(pPager->jfd) ){
37800 sqlite3OsClose(pPager->jfd);
37801 }
37802 assert( (PAGER_JOURNALMODE_TRUNCATE & 1)==1 );
37803 assert( (PAGER_JOURNALMODE_PERSIST & 1)==1 );
37804 assert( (PAGER_JOURNALMODE_DELETE & 1)==0 );
37805 assert( (PAGER_JOURNALMODE_MEMORY & 1)==0 );
37806 assert( (PAGER_JOURNALMODE_OFF & 1)==0 );
37807 if( (pPager->journalMode & 1)==1 && (eMode & 1)==0
37808 && !pPager->exclusiveMode ){
37809 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
37810 }
37811 pPager->journalMode = (u8)eMode;
37812 }
37813 return (int)pPager->journalMode;
37814 }
37815
@@ -37978,10 +38266,11 @@
38266 BtCursor *pCursor; /* A list of all open cursors */
38267 MemPage *pPage1; /* First page of the database */
38268 u8 readOnly; /* True if the underlying file is readonly */
38269 u8 pageSizeFixed; /* True if the page size can no longer be changed */
38270 u8 secureDelete; /* True if secure_delete is enabled */
38271 u8 initiallyEmpty; /* Database is empty at start of transaction */
38272 #ifndef SQLITE_OMIT_AUTOVACUUM
38273 u8 autoVacuum; /* True if auto-vacuum is enabled */
38274 u8 incrVacuum; /* True if incr-vacuum is enabled */
38275 #endif
38276 u16 pageSize; /* Total number of bytes on a page */
@@ -37990,10 +38279,11 @@
38279 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
38280 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
38281 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
38282 u8 inTransaction; /* Transaction state */
38283 int nTransaction; /* Number of open transactions (read + write) */
38284 u32 nPage; /* Number of pages in the database */
38285 void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
38286 void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */
38287 sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
38288 Bitvec *pHasContent; /* Set of pages moved to free-list this transaction */
38289 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -39070,15 +39360,12 @@
39360 ** at the end of every transaction.
39361 */
39362 static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
39363 int rc = SQLITE_OK;
39364 if( !pBt->pHasContent ){
39365 assert( pgno<=pBt->nPage );
39366 pBt->pHasContent = sqlite3BitvecCreate(pBt->nPage);
 
 
 
39367 if( !pBt->pHasContent ){
39368 rc = SQLITE_NOMEM;
39369 }
39370 }
39371 if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
@@ -40117,17 +40404,17 @@
40404
40405 /*
40406 ** Return the size of the database file in pages. If there is any kind of
40407 ** error, return ((unsigned int)-1).
40408 */
40409 static Pgno btreePagecount(BtShared *pBt){
40410 return pBt->nPage;
40411 }
40412 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
40413 assert( sqlite3BtreeHoldsMutex(p) );
40414 assert( ((p->pBt->nPage)&0x8000000)==0 );
40415 return (int)btreePagecount(p->pBt);
40416 }
40417
40418 /*
40419 ** Get a page from the pager and initialize it. This routine is just a
40420 ** convenience wrapper around separate calls to btreeGetPage() and
@@ -40140,29 +40427,22 @@
40427 BtShared *pBt, /* The database file */
40428 Pgno pgno, /* Number of the page to get */
40429 MemPage **ppPage /* Write the page pointer here */
40430 ){
40431 int rc;
 
40432 assert( sqlite3_mutex_held(pBt->mutex) );
40433
40434 if( pgno<=0 || pgno>btreePagecount(pBt) ){
40435 return SQLITE_CORRUPT_BKPT;
40436 }
40437 rc = btreeGetPage(pBt, pgno, ppPage, 0);
40438 if( rc==SQLITE_OK ){
40439 rc = btreeInitPage(*ppPage);
40440 if( rc!=SQLITE_OK ){
40441 releasePage(*ppPage);
40442 }
40443 }
 
 
 
 
 
 
 
 
 
40444 return rc;
40445 }
40446
40447 /*
40448 ** Release a MemPage. This should be called once for each prior
@@ -40794,13 +41074,15 @@
41074 ** well-formed database file, then SQLITE_CORRUPT is returned.
41075 ** SQLITE_BUSY is returned if the database is locked. SQLITE_NOMEM
41076 ** is returned if we run out of memory.
41077 */
41078 static int lockBtree(BtShared *pBt){
41079 int rc; /* Result code from subfunctions */
41080 MemPage *pPage1; /* Page 1 of the database file */
41081 int nPage; /* Number of pages in the database */
41082 int nPageFile = 0; /* Number of pages in the database file */
41083 int nPageHeader; /* Number of pages in the database according to hdr */
41084
41085 assert( sqlite3_mutex_held(pBt->mutex) );
41086 assert( pBt->pPage1==0 );
41087 rc = sqlite3PagerSharedLock(pBt->pPager);
41088 if( rc!=SQLITE_OK ) return rc;
@@ -40808,14 +41090,18 @@
41090 if( rc!=SQLITE_OK ) return rc;
41091
41092 /* Do some checking to help insure the file we opened really is
41093 ** a valid database file.
41094 */
41095 nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData);
41096 if( (rc = sqlite3PagerPagecount(pBt->pPager, &nPageFile))!=SQLITE_OK ){;
41097 goto page1_init_failed;
41098 }
41099 if( nPage==0 ){
41100 nPage = nPageFile;
41101 }
41102 if( nPage>0 ){
41103 int pageSize;
41104 int usableSize;
41105 u8 *page1 = pPage1->aData;
41106 rc = SQLITE_NOTADB;
41107 if( memcmp(page1, zMagicHeader, 16)!=0 ){
@@ -40857,10 +41143,14 @@
41143 freeTempSpace(pBt);
41144 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
41145 pageSize-usableSize);
41146 return rc;
41147 }
41148 if( nPageHeader>nPageFile ){
41149 rc = SQLITE_CORRUPT_BKPT;
41150 goto page1_init_failed;
41151 }
41152 if( usableSize<480 ){
41153 goto page1_init_failed;
41154 }
41155 pBt->pageSize = (u16)pageSize;
41156 pBt->usableSize = (u16)usableSize;
@@ -40887,10 +41177,11 @@
41177 pBt->minLocal = (pBt->usableSize-12)*32/255 - 23;
41178 pBt->maxLeaf = pBt->usableSize - 35;
41179 pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23;
41180 assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
41181 pBt->pPage1 = pPage1;
41182 pBt->nPage = nPage;
41183 return SQLITE_OK;
41184
41185 page1_init_failed:
41186 releasePage(pPage1);
41187 pBt->pPage1 = 0;
@@ -40924,16 +41215,14 @@
41215 */
41216 static int newDatabase(BtShared *pBt){
41217 MemPage *pP1;
41218 unsigned char *data;
41219 int rc;
 
41220
41221 assert( sqlite3_mutex_held(pBt->mutex) );
41222 if( pBt->nPage>0 ){
41223 return SQLITE_OK;
 
41224 }
41225 pP1 = pBt->pPage1;
41226 assert( pP1!=0 );
41227 data = pP1->aData;
41228 rc = sqlite3PagerWrite(pP1->pDbPage);
@@ -40955,10 +41244,12 @@
41244 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
41245 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
41246 put4byte(&data[36 + 4*4], pBt->autoVacuum);
41247 put4byte(&data[36 + 7*4], pBt->incrVacuum);
41248 #endif
41249 pBt->nPage = 1;
41250 data[31] = 1;
41251 return SQLITE_OK;
41252 }
41253
41254 /*
41255 ** Attempt to start a new transaction. A write-transaction
@@ -41044,10 +41335,11 @@
41335 ** page 1. So if some other shared-cache client already has a write-lock
41336 ** on page 1, the transaction cannot be opened. */
41337 rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
41338 if( SQLITE_OK!=rc ) goto trans_begun;
41339
41340 pBt->initiallyEmpty = pBt->nPage==0;
41341 do {
41342 /* Call lockBtree() until either pBt->pPage1 is populated or
41343 ** lockBtree() returns something other than SQLITE_OK. lockBtree()
41344 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
41345 ** reading page 1 it discovers that the page-size of the database
@@ -41323,16 +41615,16 @@
41615 ** which may or may not empty the freelist. A full autovacuum
41616 ** has nFin>0. A "PRAGMA incremental_vacuum" has nFin==0.
41617 */
41618 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg){
41619 Pgno nFreeList; /* Number of pages still on the free-list */
41620 int rc;
41621
41622 assert( sqlite3_mutex_held(pBt->mutex) );
41623 assert( iLastPg>nFin );
41624
41625 if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
 
41626 u8 eType;
41627 Pgno iPtrPage;
41628
41629 nFreeList = get4byte(&pBt->pPage1->aData[36]);
41630 if( nFreeList==0 ){
@@ -41404,11 +41696,11 @@
41696 if( nFin==0 ){
41697 iLastPg--;
41698 while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
41699 if( PTRMAP_ISPAGE(pBt, iLastPg) ){
41700 MemPage *pPg;
41701 rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
41702 if( rc!=SQLITE_OK ){
41703 return rc;
41704 }
41705 rc = sqlite3PagerWrite(pPg->pDbPage);
41706 releasePage(pPg);
@@ -41417,10 +41709,11 @@
41709 }
41710 }
41711 iLastPg--;
41712 }
41713 sqlite3PagerTruncateImage(pBt->pPager, iLastPg);
41714 pBt->nPage = iLastPg;
41715 }
41716 return SQLITE_OK;
41717 }
41718
41719 /*
@@ -41439,11 +41732,15 @@
41732 assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
41733 if( !pBt->autoVacuum ){
41734 rc = SQLITE_DONE;
41735 }else{
41736 invalidateAllOverflowCache(pBt);
41737 rc = incrVacuumStep(pBt, 0, btreePagecount(pBt));
41738 if( rc==SQLITE_OK ){
41739 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
41740 put4byte(&pBt->pPage1->aData[28], pBt->nPage);
41741 }
41742 }
41743 sqlite3BtreeLeave(p);
41744 return rc;
41745 }
41746
@@ -41470,11 +41767,11 @@
41767 Pgno nPtrmap; /* Number of PtrMap pages to be freed */
41768 Pgno iFree; /* The next page to be freed */
41769 int nEntry; /* Number of entries on one ptrmap page */
41770 Pgno nOrig; /* Database size before freeing */
41771
41772 nOrig = btreePagecount(pBt);
41773 if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
41774 /* It is not possible to create a database for which the final page
41775 ** is either a pointer-map page or the pending-byte page. If one
41776 ** is encountered, this indicates corruption.
41777 */
@@ -41495,15 +41792,16 @@
41792
41793 for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
41794 rc = incrVacuumStep(pBt, nFin, iFree);
41795 }
41796 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
 
41797 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
41798 put4byte(&pBt->pPage1->aData[32], 0);
41799 put4byte(&pBt->pPage1->aData[36], 0);
41800 put4byte(&pBt->pPage1->aData[28], nFin);
41801 sqlite3PagerTruncateImage(pBt->pPager, nFin);
41802 pBt->nPage = nFin;
41803 }
41804 if( rc!=SQLITE_OK ){
41805 sqlite3PagerRollback(pPager);
41806 }
41807 }
@@ -41749,10 +42047,15 @@
42047
42048 /* The rollback may have destroyed the pPage1->aData value. So
42049 ** call btreeGetPage() on page 1 again to make
42050 ** sure pPage1->aData is set correctly. */
42051 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
42052 int nPage = get4byte(28+(u8*)pPage1->aData);
42053 testcase( nPage==0 );
42054 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
42055 testcase( pBt->nPage!=nPage );
42056 pBt->nPage = nPage;
42057 releasePage(pPage1);
42058 }
42059 assert( countWriteCursors(pBt)==0 );
42060 pBt->inTransaction = TRANS_READ;
42061 }
@@ -41786,21 +42089,17 @@
42089 sqlite3BtreeEnter(p);
42090 assert( p->inTrans==TRANS_WRITE );
42091 assert( pBt->readOnly==0 );
42092 assert( iStatement>0 );
42093 assert( iStatement>p->db->nSavepoint );
42094 assert( pBt->inTransaction==TRANS_WRITE );
42095 /* At the pager level, a statement transaction is a savepoint with
42096 ** an index greater than all savepoints created explicitly using
42097 ** SQL statements. It is illegal to open, release or rollback any
42098 ** such savepoints while the statement transaction savepoint is active.
42099 */
42100 rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
 
 
 
 
42101 sqlite3BtreeLeave(p);
42102 return rc;
42103 }
42104
42105 /*
@@ -41822,11 +42121,16 @@
42121 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
42122 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
42123 sqlite3BtreeEnter(p);
42124 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
42125 if( rc==SQLITE_OK ){
42126 if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
42127 rc = newDatabase(pBt);
42128 pBt->nPage = get4byte(28 + pBt->pPage1->aData);
42129 if( pBt->nPage==0 ){
42130 sqlite3PagerPagecount(pBt->pPager, (int*)&pBt->nPage);
42131 }
42132 }
42133 sqlite3BtreeLeave(p);
42134 }
42135 return rc;
42136 }
@@ -41888,11 +42192,11 @@
42192 assert( pBt->pPage1 && pBt->pPage1->aData );
42193
42194 if( NEVER(wrFlag && pBt->readOnly) ){
42195 return SQLITE_READONLY;
42196 }
42197 if( iTable==1 && btreePagecount(pBt)==0 ){
42198 return SQLITE_EMPTY;
42199 }
42200
42201 /* Now that no other errors can occur, finish filling in the BtCursor
42202 ** variables and link the cursor into the BtShared list. */
@@ -42159,11 +42463,11 @@
42463
42464 while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){
42465 iGuess++;
42466 }
42467
42468 if( iGuess<=btreePagecount(pBt) ){
42469 rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
42470 if( rc==SQLITE_OK && eType==PTRMAP_OVERFLOW2 && pgno==ovfl ){
42471 next = iGuess;
42472 rc = SQLITE_DONE;
42473 }
@@ -43191,11 +43495,11 @@
43495 MemPage *pPrevTrunk = 0;
43496 Pgno mxPage; /* Total size of the database file */
43497
43498 assert( sqlite3_mutex_held(pBt->mutex) );
43499 pPage1 = pBt->pPage1;
43500 mxPage = btreePagecount(pBt);
43501 n = get4byte(&pPage1->aData[36]);
43502 testcase( n==mxPage-1 );
43503 if( n>=mxPage ){
43504 return SQLITE_CORRUPT_BKPT;
43505 }
@@ -43387,39 +43691,39 @@
43691 pPrevTrunk = 0;
43692 }while( searchList );
43693 }else{
43694 /* There are no pages on the freelist, so create a new page at the
43695 ** end of the file */
43696 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
43697 if( rc ) return rc;
43698 pBt->nPage++;
43699 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
 
 
43700
43701 #ifndef SQLITE_OMIT_AUTOVACUUM
43702 if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, pBt->nPage) ){
43703 /* If *pPgno refers to a pointer-map page, allocate two new pages
43704 ** at the end of the file instead of one. The first allocated page
43705 ** becomes a new pointer-map page, the second is used by the caller.
43706 */
43707 MemPage *pPg = 0;
43708 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
43709 assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
43710 rc = btreeGetPage(pBt, pBt->nPage, &pPg, 1);
43711 if( rc==SQLITE_OK ){
43712 rc = sqlite3PagerWrite(pPg->pDbPage);
43713 releasePage(pPg);
43714 }
43715 if( rc ) return rc;
43716 pBt->nPage++;
43717 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ){ pBt->nPage++; }
43718 }
43719 #endif
43720 put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
43721 *pPgno = pBt->nPage;
43722
43723 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43724 rc = btreeGetPage(pBt, *pPgno, ppPage, 1);
43725 if( rc ) return rc;
43726 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
43727 if( rc!=SQLITE_OK ){
43728 releasePage(*ppPage);
43729 }
@@ -43605,11 +43909,11 @@
43909 nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
43910 assert( ovflPgno==0 || nOvfl>0 );
43911 while( nOvfl-- ){
43912 Pgno iNext = 0;
43913 MemPage *pOvfl = 0;
43914 if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
43915 /* 0 is not a legal page number and page 1 cannot be an
43916 ** overflow page. Therefore if ovflPgno<2 or past the end of the
43917 ** file the database must be corrupt. */
43918 return SQLITE_CORRUPT_BKPT;
43919 }
@@ -45437,12 +45741,18 @@
45741 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
45742 if( rc ){
45743 releasePage(pRoot);
45744 return rc;
45745 }
45746
45747 /* When the new root page was allocated, page 1 was made writable in
45748 ** order either to increase the database filesize, or to decrement the
45749 ** freelist count. Hence, the sqlite3BtreeUpdateMeta() call cannot fail.
45750 */
45751 assert( sqlite3PagerIswriteable(pBt->pPage1->pDbPage) );
45752 rc = sqlite3BtreeUpdateMeta(p, 4, pgnoRoot);
45753 if( NEVER(rc) ){
45754 releasePage(pRoot);
45755 return rc;
45756 }
45757
45758 }else{
@@ -45478,11 +45788,11 @@
45788 int rc;
45789 unsigned char *pCell;
45790 int i;
45791
45792 assert( sqlite3_mutex_held(pBt->mutex) );
45793 if( pgno>btreePagecount(pBt) ){
45794 return SQLITE_CORRUPT_BKPT;
45795 }
45796
45797 rc = getAndInitPage(pBt, pgno, &pPage);
45798 if( rc ) return rc;
@@ -46229,11 +46539,11 @@
46539 sqlite3BtreeEnter(p);
46540 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
46541 nRef = sqlite3PagerRefcount(pBt->pPager);
46542 sCheck.pBt = pBt;
46543 sCheck.pPager = pBt->pPager;
46544 sCheck.nPage = btreePagecount(sCheck.pBt);
46545 sCheck.mxErr = mxErr;
46546 sCheck.nErr = 0;
46547 sCheck.mallocFailed = 0;
46548 *pnErr = 0;
46549 if( sCheck.nPage==0 ){
@@ -46831,13 +47141,12 @@
47141 }
47142
47143 /* Now that there is a read-lock on the source database, query the
47144 ** source pager for the number of pages in the database.
47145 */
47146 nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc);
47147 assert( nSrcPage>=0 );
 
47148 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
47149 const Pgno iSrcPg = p->iNext; /* Source page number */
47150 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
47151 DbPage *pSrcPg; /* Source page object */
47152 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
@@ -48986,11 +49295,11 @@
49295 nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
49296 pKeyInfo = sqlite3Malloc( nByte );
49297 pOp->p4.pKeyInfo = pKeyInfo;
49298 if( pKeyInfo ){
49299 u8 *aSortOrder;
49300 memcpy((char*)pKeyInfo, zP4, nByte - nField);
49301 aSortOrder = pKeyInfo->aSortOrder;
49302 if( aSortOrder ){
49303 pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
49304 memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
49305 }
@@ -53812,18 +54121,13 @@
54121 int i;
54122 sqlite_int64 rowid;
54123 Mem **apArg;
54124 Mem *pX;
54125 } ck;
 
 
 
 
 
54126 struct OP_Trace_stack_vars {
54127 char *zTrace;
54128 } cl;
54129 } u;
54130 /* End automatically generated code
54131 ********************************************************************/
54132
54133 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
@@ -54646,11 +54950,11 @@
54950 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ag.n );
54951 u.ag.pArg = &aMem[pOp->p2];
54952 for(u.ag.i=0; u.ag.i<u.ag.n; u.ag.i++, u.ag.pArg++){
54953 u.ag.apVal[u.ag.i] = u.ag.pArg;
54954 sqlite3VdbeMemStoreType(u.ag.pArg);
54955 REGISTER_TRACE(pOp->p2+u.ag.i, u.ag.pArg);
54956 }
54957
54958 assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
54959 if( pOp->p4type==P4_FUNCDEF ){
54960 u.ag.ctx.pFunc = pOp->p4.pFunc;
@@ -56363,14 +56667,14 @@
56667
56668 /* Opcode: OpenEphemeral P1 P2 * P4 *
56669 **
56670 ** Open a new cursor P1 to a transient table.
56671 ** The cursor is always opened read/write even if
56672 ** the main database is read-only. The ephemeral
56673 ** table is deleted automatically when the cursor is closed.
56674 **
56675 ** P2 is the number of columns in the ephemeral table.
56676 ** The cursor points to a BTree table if P4==0 and to a BTree index
56677 ** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
56678 ** that defines the format of keys in the index.
56679 **
56680 ** This opcode was once called OpenTemp. But that created
@@ -56377,10 +56681,18 @@
56681 ** confusion because the term "temp table", might refer either
56682 ** to a TEMP table at the SQL level, or to a table opened by
56683 ** this opcode. Then this opcode was call OpenVirtual. But
56684 ** that created confusion with the whole virtual-table idea.
56685 */
56686 /* Opcode: OpenAutoindex P1 P2 * P4 *
56687 **
56688 ** This opcode works the same as OP_OpenEphemeral. It has a
56689 ** different name to distinguish its use. Tables created using
56690 ** by this opcode will be used for automatically created transient
56691 ** indices in joins.
56692 */
56693 case OP_OpenAutoindex:
56694 case OP_OpenEphemeral: {
56695 #if 0 /* local variables moved into u.ax */
56696 VdbeCursor *pCx;
56697 #endif /* local variables moved into u.ax */
56698 static const int openFlags =
@@ -57515,29 +57827,35 @@
57827 pc = pOp->p2 - 1;
57828 }
57829 break;
57830 }
57831
57832 /* Opcode: Next P1 P2 * * P5
57833 **
57834 ** Advance cursor P1 so that it points to the next key/data pair in its
57835 ** table or index. If there are no more key/value pairs then fall through
57836 ** to the following instruction. But if the cursor advance was successful,
57837 ** jump immediately to P2.
57838 **
57839 ** The P1 cursor must be for a real table, not a pseudo-table.
57840 **
57841 ** If P5 is positive and the jump is taken, then event counter
57842 ** number P5-1 in the prepared statement is incremented.
57843 **
57844 ** See also: Prev
57845 */
57846 /* Opcode: Prev P1 P2 * * P5
57847 **
57848 ** Back up cursor P1 so that it points to the previous key/data pair in its
57849 ** table or index. If there is no previous key/value pairs then fall through
57850 ** to the following instruction. But if the cursor backup was successful,
57851 ** jump immediately to P2.
57852 **
57853 ** The P1 cursor must be for a real table, not a pseudo-table.
57854 **
57855 ** If P5 is positive and the jump is taken, then event counter
57856 ** number P5-1 in the prepared statement is incremented.
57857 */
57858 case OP_Prev: /* jump */
57859 case OP_Next: { /* jump */
57860 #if 0 /* local variables moved into u.bm */
57861 VdbeCursor *pC;
@@ -57545,10 +57863,11 @@
57863 int res;
57864 #endif /* local variables moved into u.bm */
57865
57866 CHECK_FOR_INTERRUPT;
57867 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
57868 assert( pOp->p5<=ArraySize(p->aCounter) );
57869 u.bm.pC = p->apCsr[pOp->p1];
57870 if( u.bm.pC==0 ){
57871 break; /* See ticket #2273 */
57872 }
57873 u.bm.pCrsr = u.bm.pC->pCursor;
@@ -58991,25 +59310,11 @@
59310 /* Opcode: Pagecount P1 P2 * * *
59311 **
59312 ** Write the current number of pages in database P1 to memory cell P2.
59313 */
59314 case OP_Pagecount: { /* out2-prerelease */
59315 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59316 break;
59317 }
59318 #endif
59319
59320 #ifndef SQLITE_OMIT_TRACE
@@ -59017,24 +59322,24 @@
59322 **
59323 ** If tracing is enabled (by the sqlite3_trace()) interface, then
59324 ** the UTF-8 string contained in P4 is emitted on the trace callback.
59325 */
59326 case OP_Trace: {
59327 #if 0 /* local variables moved into u.cl */
59328 char *zTrace;
59329 #endif /* local variables moved into u.cl */
59330
59331 u.cl.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
59332 if( u.cl.zTrace ){
59333 if( db->xTrace ){
59334 char *z = sqlite3VdbeExpandSql(p, u.cl.zTrace);
59335 db->xTrace(db->pTraceArg, z);
59336 sqlite3DbFree(db, z);
59337 }
59338 #ifdef SQLITE_DEBUG
59339 if( (db->flags & SQLITE_SqlTrace)!=0 ){
59340 sqlite3DebugPrintf("SQL-trace: %s\n", u.cl.zTrace);
59341 }
59342 #endif /* SQLITE_DEBUG */
59343 }
59344 break;
59345 }
@@ -59973,15 +60278,14 @@
60278 ** Syncing an in-memory journal is a no-op. And, in fact, this routine
60279 ** is never called in a working implementation. This implementation
60280 ** exists purely as a contingency, in case some malfunction in some other
60281 ** part of SQLite causes Sync to be called by mistake.
60282 */
60283 static int memjrnlSync(sqlite3_file *NotUsed, int NotUsed2){
60284 UNUSED_PARAMETER2(NotUsed, NotUsed2);
60285 return SQLITE_OK;
60286 }
 
60287
60288 /*
60289 ** Query the size of the file in bytes.
60290 */
60291 static int memjrnlFileSize(sqlite3_file *pJfd, sqlite_int64 *pSize){
@@ -60573,11 +60877,11 @@
60877 }
60878 }
60879
60880 /*
60881 ** Allocate and return a pointer to an expression to load the column iCol
60882 ** from datasource iSrc in SrcList pSrc.
60883 */
60884 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
60885 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
60886 if( p ){
60887 struct SrcList_item *pItem = &pSrc->a[iSrc];
@@ -60585,10 +60889,12 @@
60889 p->iTable = pItem->iCursor;
60890 if( p->pTab->iPKey==iCol ){
60891 p->iColumn = -1;
60892 }else{
60893 p->iColumn = (ynVar)iCol;
60894 testcase( iCol==BMS );
60895 testcase( iCol==BMS-1 );
60896 pItem->colUsed |= ((Bitmask)1)<<(iCol>=BMS ? BMS-1 : iCol);
60897 }
60898 ExprSetProperty(p, EP_Resolved);
60899 }
60900 return p;
@@ -66537,16 +66843,20 @@
66843 int n = sqlite3_column_bytes(pStmt, 2);
66844 if( n>24 ){
66845 n = 24;
66846 }
66847 pSample->nByte = (u8)n;
66848 if( n < 1){
66849 pSample->u.z = 0;
 
66850 }else{
66851 pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
66852 if( pSample->u.z ){
66853 memcpy(pSample->u.z, z, n);
66854 }else{
66855 db->mallocFailed = 1;
66856 break;
66857 }
66858 }
66859 }
66860 }
66861 }
66862 }
@@ -75790,11 +76100,11 @@
76100 }else{
76101 for(j=0; j<pColumn->nId; j++){
76102 if( pColumn->a[j].idx==i ) break;
76103 }
76104 }
76105 if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) ){
76106 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1);
76107 }else if( useTempTable ){
76108 sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1);
76109 }else{
76110 assert( pSelect==0 ); /* Otherwise useTempTable is true */
@@ -78086,10 +78396,13 @@
78396 { "count_changes", SQLITE_CountRows },
78397 { "empty_result_callbacks", SQLITE_NullCallback },
78398 { "legacy_file_format", SQLITE_LegacyFileFmt },
78399 { "fullfsync", SQLITE_FullFSync },
78400 { "reverse_unordered_selects", SQLITE_ReverseOrder },
78401 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
78402 { "automatic_index", SQLITE_AutoIndex },
78403 #endif
78404 #ifdef SQLITE_DEBUG
78405 { "sql_trace", SQLITE_SqlTrace },
78406 { "vdbe_listing", SQLITE_VdbeListing },
78407 { "vdbe_trace", SQLITE_VdbeTrace },
78408 #endif
@@ -79461,32 +79774,32 @@
79774 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
79775 ** But because db->init.busy is set to 1, no VDBE code is generated
79776 ** or executed. All the parser does is build the internal data
79777 ** structures that describe the table, index, or view.
79778 */
 
79779 int rc;
79780 sqlite3_stmt *pStmt;
79781
79782 assert( db->init.busy );
79783 db->init.iDb = iDb;
79784 db->init.newTnum = atoi(argv[1]);
79785 db->init.orphanTrigger = 0;
79786 rc = sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
79787 db->init.iDb = 0;
 
79788 if( SQLITE_OK!=rc ){
79789 if( db->init.orphanTrigger ){
79790 assert( iDb==1 );
79791 }else{
79792 pData->rc = rc;
79793 if( rc==SQLITE_NOMEM ){
79794 db->mallocFailed = 1;
79795 }else if( rc!=SQLITE_INTERRUPT && rc!=SQLITE_LOCKED ){
79796 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
79797 }
79798 }
 
79799 }
79800 sqlite3_finalize(pStmt);
79801 }else if( argv[0]==0 ){
79802 corruptSchema(pData, 0, 0);
79803 }else{
79804 /* If the SQL column is blank it means this is an index that
79805 ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
@@ -79967,10 +80280,11 @@
80280 }
80281
80282 sqlite3VtabUnlockList(db);
80283
80284 pParse->db = db;
80285 pParse->nQueryLoop = (double)1;
80286 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
80287 char *zSqlCopy;
80288 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
80289 testcase( nBytes==mxLen );
80290 testcase( nBytes==mxLen+1 );
@@ -79988,10 +80302,11 @@
80302 pParse->zTail = &zSql[nBytes];
80303 }
80304 }else{
80305 sqlite3RunParser(pParse, zSql, &zErrMsg);
80306 }
80307 assert( 1==(int)pParse->nQueryLoop );
80308
80309 if( db->mallocFailed ){
80310 pParse->rc = SQLITE_NOMEM;
80311 }
80312 if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
@@ -82772,12 +83087,12 @@
83087 ** (13) The subquery and outer query do not both use LIMIT
83088 **
83089 ** (14) The subquery does not use OFFSET
83090 **
83091 ** (15) The outer query is not part of a compound select or the
83092 ** subquery does not have a LIMIT clause.
83093 ** (See ticket #2339 and ticket [02a8e81d44]).
83094 **
83095 ** (16) The outer query is not an aggregate or the subquery does
83096 ** not contain ORDER BY. (Ticket #2942) This used to not matter
83097 ** until we introduced the group_concat() function.
83098 **
@@ -82856,11 +83171,11 @@
83171 ** because they could be computed at compile-time. But when LIMIT and OFFSET
83172 ** became arbitrary expressions, we were forced to add restrictions (13)
83173 ** and (14). */
83174 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
83175 if( pSub->pOffset ) return 0; /* Restriction (14) */
83176 if( p->pRightmost && pSub->pLimit ){
83177 return 0; /* Restriction (15) */
83178 }
83179 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
83180 if( ((pSub->selFlags & SF_Distinct)!=0 || pSub->pLimit)
83181 && (pSrc->nSrc>1 || isAgg) ){ /* Restrictions (4)(5)(8)(9) */
@@ -83744,10 +84059,22 @@
84059 if( addrNext ){
84060 sqlite3VdbeResolveLabel(v, addrNext);
84061 sqlite3ExprCacheClear(pParse);
84062 }
84063 }
84064
84065 /* Before populating the accumulator registers, clear the column cache.
84066 ** Otherwise, if any of the required column values are already present
84067 ** in registers, sqlite3ExprCode() may use OP_SCopy to copy the value
84068 ** to pC->iMem. But by the time the value is used, the original register
84069 ** may have been used, invalidating the underlying buffer holding the
84070 ** text or blob value. See ticket [883034dcb5].
84071 **
84072 ** Another solution would be to change the OP_SCopy used to copy cached
84073 ** values to an OP_Copy.
84074 */
84075 sqlite3ExprCacheClear(pParse);
84076 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
84077 sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
84078 }
84079 pAggInfo->directMode = 0;
84080 sqlite3ExprCacheClear(pParse);
@@ -85557,10 +85884,11 @@
85884 pSubParse->db = db;
85885 pSubParse->pTriggerTab = pTab;
85886 pSubParse->pToplevel = pTop;
85887 pSubParse->zAuthContext = pTrigger->zName;
85888 pSubParse->eTriggerOp = pTrigger->op;
85889 pSubParse->nQueryLoop = pParse->nQueryLoop;
85890
85891 v = sqlite3GetVdbe(pSubParse);
85892 if( v ){
85893 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
85894 pTrigger->zName, onErrorText(orconf),
@@ -87477,10 +87805,11 @@
87805 if( pParse==0 ){
87806 rc = SQLITE_NOMEM;
87807 }else{
87808 pParse->declareVtab = 1;
87809 pParse->db = db;
87810 pParse->nQueryLoop = 1;
87811
87812 if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
87813 && pParse->pNewTable
87814 && !db->mallocFailed
87815 && !pParse->pNewTable->pSelect
@@ -87997,19 +88326,21 @@
88326 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */
88327 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
88328 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
88329 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
88330 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
88331 #define WHERE_NOT_FULLSCAN 0x000f3000 /* Does not do a full table scan */
88332 #define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */
88333 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
88334 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
88335 #define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
88336 #define WHERE_ORDERBY 0x01000000 /* Output will appear in correct order */
88337 #define WHERE_REVERSE 0x02000000 /* Scan in reverse order */
88338 #define WHERE_UNIQUE 0x04000000 /* Selects no more than one row */
88339 #define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
88340 #define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
88341 #define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
88342
88343 /*
88344 ** Initialize a preallocated WhereClause structure.
88345 */
88346 static void whereClauseInit(
@@ -89334,10 +89665,15 @@
89665 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
89666 const int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */
89667 const Bitmask maskSrc = getMask(pWC->pMaskSet, iCur); /* Bitmask for pSrc */
89668 WhereTerm * const pWCEnd = &pWC->a[pWC->nTerm]; /* End of pWC->a[] */
89669 WhereTerm *pTerm; /* A single term of the WHERE clause */
89670
89671 /* No OR-clause optimization allowed if the NOT INDEXED clause is used */
89672 if( pSrc->notIndexed ){
89673 return;
89674 }
89675
89676 /* Search the WHERE clause terms for a usable WO_OR term. */
89677 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89678 if( pTerm->eOperator==WO_OR
89679 && ((pTerm->prereqAll & ~maskSrc) & notReady)==0
@@ -89377,12 +89713,13 @@
89713 }
89714
89715 /* If there is an ORDER BY clause, increase the scan cost to account
89716 ** for the cost of the sort. */
89717 if( pOrderBy!=0 ){
89718 WHERETRACE(("... sorting increases OR cost %.9g to %.9g\n",
89719 rTotal, rTotal+nRow*estLog(nRow)));
89720 rTotal += nRow*estLog(nRow);
 
89721 }
89722
89723 /* If the cost of scanning using this OR term for optimization is
89724 ** less than the current cost stored in pCost, replace the contents
89725 ** of pCost. */
@@ -89397,10 +89734,251 @@
89734 }
89735 }
89736 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
89737 }
89738
89739 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89740 /*
89741 ** Return TRUE if the WHERE clause term pTerm is of a form where it
89742 ** could be used with an index to access pSrc, assuming an appropriate
89743 ** index existed.
89744 */
89745 static int termCanDriveIndex(
89746 WhereTerm *pTerm, /* WHERE clause term to check */
89747 struct SrcList_item *pSrc, /* Table we are trying to access */
89748 Bitmask notReady /* Tables in outer loops of the join */
89749 ){
89750 char aff;
89751 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
89752 if( pTerm->eOperator!=WO_EQ ) return 0;
89753 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
89754 aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;
89755 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
89756 return 1;
89757 }
89758 #endif
89759
89760 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89761 /*
89762 ** If the query plan for pSrc specified in pCost is a full table scan
89763 ** and indexing is allows (if there is no NOT INDEXED clause) and it
89764 ** possible to construct a transient index that would perform better
89765 ** than a full table scan even when the cost of constructing the index
89766 ** is taken into account, then alter the query plan to use the
89767 ** transient index.
89768 */
89769 static void bestAutomaticIndex(
89770 Parse *pParse, /* The parsing context */
89771 WhereClause *pWC, /* The WHERE clause */
89772 struct SrcList_item *pSrc, /* The FROM clause term to search */
89773 Bitmask notReady, /* Mask of cursors that are not available */
89774 WhereCost *pCost /* Lowest cost query plan */
89775 ){
89776 double nTableRow; /* Rows in the input table */
89777 double logN; /* log(nTableRow) */
89778 double costTempIdx; /* per-query cost of the transient index */
89779 WhereTerm *pTerm; /* A single term of the WHERE clause */
89780 WhereTerm *pWCEnd; /* End of pWC->a[] */
89781 Table *pTable; /* Table tht might be indexed */
89782
89783 if( (pParse->db->flags & SQLITE_AutoIndex)==0 ){
89784 /* Automatic indices are disabled at run-time */
89785 return;
89786 }
89787 if( (pCost->plan.wsFlags & WHERE_NOT_FULLSCAN)!=0 ){
89788 /* We already have some kind of index in use for this query. */
89789 return;
89790 }
89791 if( pSrc->notIndexed ){
89792 /* The NOT INDEXED clause appears in the SQL. */
89793 return;
89794 }
89795
89796 assert( pParse->nQueryLoop >= (double)1 );
89797 pTable = pSrc->pTab;
89798 nTableRow = pTable->pIndex ? pTable->pIndex->aiRowEst[0] : 1000000;
89799 logN = estLog(nTableRow);
89800 costTempIdx = 2*logN*(nTableRow/pParse->nQueryLoop + 1);
89801 if( costTempIdx>=pCost->rCost ){
89802 /* The cost of creating the transient table would be greater than
89803 ** doing the full table scan */
89804 return;
89805 }
89806
89807 /* Search for any equality comparison term */
89808 pWCEnd = &pWC->a[pWC->nTerm];
89809 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89810 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89811 WHERETRACE(("auto-index reduces cost from %.2f to %.2f\n",
89812 pCost->rCost, costTempIdx));
89813 pCost->rCost = costTempIdx;
89814 pCost->nRow = logN + 1;
89815 pCost->plan.wsFlags = WHERE_TEMP_INDEX;
89816 pCost->used = pTerm->prereqRight;
89817 break;
89818 }
89819 }
89820 }
89821 #else
89822 # define bestAutomaticIndex(A,B,C,D,E) /* no-op */
89823 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
89824
89825
89826 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89827 /*
89828 ** Generate code to construct the Index object for an automatic index
89829 ** and to set up the WhereLevel object pLevel so that the code generator
89830 ** makes use of the automatic index.
89831 */
89832 static void constructAutomaticIndex(
89833 Parse *pParse, /* The parsing context */
89834 WhereClause *pWC, /* The WHERE clause */
89835 struct SrcList_item *pSrc, /* The FROM clause term to get the next index */
89836 Bitmask notReady, /* Mask of cursors that are not available */
89837 WhereLevel *pLevel /* Write new index here */
89838 ){
89839 int nColumn; /* Number of columns in the constructed index */
89840 WhereTerm *pTerm; /* A single term of the WHERE clause */
89841 WhereTerm *pWCEnd; /* End of pWC->a[] */
89842 int nByte; /* Byte of memory needed for pIdx */
89843 Index *pIdx; /* Object describing the transient index */
89844 Vdbe *v; /* Prepared statement under construction */
89845 int regIsInit; /* Register set by initialization */
89846 int addrInit; /* Address of the initialization bypass jump */
89847 Table *pTable; /* The table being indexed */
89848 KeyInfo *pKeyinfo; /* Key information for the index */
89849 int addrTop; /* Top of the index fill loop */
89850 int regRecord; /* Register holding an index record */
89851 int n; /* Column counter */
89852 int i; /* Loop counter */
89853 int mxBitCol; /* Maximum column in pSrc->colUsed */
89854 CollSeq *pColl; /* Collating sequence to on a column */
89855 Bitmask idxCols; /* Bitmap of columns used for indexing */
89856 Bitmask extraCols; /* Bitmap of additional columns */
89857
89858 /* Generate code to skip over the creation and initialization of the
89859 ** transient index on 2nd and subsequent iterations of the loop. */
89860 v = pParse->pVdbe;
89861 assert( v!=0 );
89862 regIsInit = ++pParse->nMem;
89863 addrInit = sqlite3VdbeAddOp1(v, OP_If, regIsInit);
89864 sqlite3VdbeAddOp2(v, OP_Integer, 1, regIsInit);
89865
89866 /* Count the number of columns that will be added to the index
89867 ** and used to match WHERE clause constraints */
89868 nColumn = 0;
89869 pTable = pSrc->pTab;
89870 pWCEnd = &pWC->a[pWC->nTerm];
89871 idxCols = 0;
89872 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89873 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89874 int iCol = pTerm->u.leftColumn;
89875 Bitmask cMask = iCol>=BMS ? ((Bitmask)1)<<(BMS-1) : ((Bitmask)1)<<iCol;
89876 testcase( iCol==BMS );
89877 testcase( iCol==BMS-1 );
89878 if( (idxCols & cMask)==0 ){
89879 nColumn++;
89880 idxCols |= cMask;
89881 }
89882 }
89883 }
89884 assert( nColumn>0 );
89885 pLevel->plan.nEq = nColumn;
89886
89887 /* Count the number of additional columns needed to create a
89888 ** covering index. A "covering index" is an index that contains all
89889 ** columns that are needed by the query. With a covering index, the
89890 ** original table never needs to be accessed. Automatic indices must
89891 ** be a covering index because the index will not be updated if the
89892 ** original table changes and the index and table cannot both be used
89893 ** if they go out of sync.
89894 */
89895 extraCols = pSrc->colUsed & (~idxCols | (((Bitmask)1)<<(BMS-1)));
89896 mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
89897 testcase( pTable->nCol==BMS-1 );
89898 testcase( pTable->nCol==BMS-2 );
89899 for(i=0; i<mxBitCol; i++){
89900 if( extraCols & (((Bitmask)1)<<i) ) nColumn++;
89901 }
89902 if( pSrc->colUsed & (((Bitmask)1)<<(BMS-1)) ){
89903 nColumn += pTable->nCol - BMS + 1;
89904 }
89905 pLevel->plan.wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WO_EQ;
89906
89907 /* Construct the Index object to describe this index */
89908 nByte = sizeof(Index);
89909 nByte += nColumn*sizeof(int); /* Index.aiColumn */
89910 nByte += nColumn*sizeof(char*); /* Index.azColl */
89911 nByte += nColumn; /* Index.aSortOrder */
89912 pIdx = sqlite3DbMallocZero(pParse->db, nByte);
89913 if( pIdx==0 ) return;
89914 pLevel->plan.u.pIdx = pIdx;
89915 pIdx->azColl = (char**)&pIdx[1];
89916 pIdx->aiColumn = (int*)&pIdx->azColl[nColumn];
89917 pIdx->aSortOrder = (u8*)&pIdx->aiColumn[nColumn];
89918 pIdx->zName = "auto-index";
89919 pIdx->nColumn = nColumn;
89920 pIdx->pTable = pTable;
89921 n = 0;
89922 idxCols = 0;
89923 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89924 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89925 int iCol = pTerm->u.leftColumn;
89926 Bitmask cMask = iCol>=BMS ? ((Bitmask)1)<<(BMS-1) : ((Bitmask)1)<<iCol;
89927 if( (idxCols & cMask)==0 ){
89928 Expr *pX = pTerm->pExpr;
89929 idxCols |= cMask;
89930 pIdx->aiColumn[n] = pTerm->u.leftColumn;
89931 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
89932 pIdx->azColl[n] = pColl->zName;
89933 n++;
89934 }
89935 }
89936 }
89937 assert( n==pLevel->plan.nEq );
89938
89939 /* Add additional columns needed to make the automatic index into
89940 ** a covering index */
89941 for(i=0; i<mxBitCol; i++){
89942 if( extraCols & (((Bitmask)1)<<i) ){
89943 pIdx->aiColumn[n] = i;
89944 pIdx->azColl[n] = "BINARY";
89945 n++;
89946 }
89947 }
89948 if( pSrc->colUsed & (((Bitmask)1)<<(BMS-1)) ){
89949 for(i=BMS-1; i<pTable->nCol; i++){
89950 pIdx->aiColumn[n] = i;
89951 pIdx->azColl[n] = "BINARY";
89952 n++;
89953 }
89954 }
89955 assert( n==nColumn );
89956
89957 /* Create the automatic index */
89958 pKeyinfo = sqlite3IndexKeyinfo(pParse, pIdx);
89959 assert( pLevel->iIdxCur>=0 );
89960 sqlite3VdbeAddOp4(v, OP_OpenAutoindex, pLevel->iIdxCur, nColumn+1, 0,
89961 (char*)pKeyinfo, P4_KEYINFO_HANDOFF);
89962 VdbeComment((v, "for %s", pTable->zName));
89963
89964 /* Fill the automatic index with content */
89965 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
89966 regRecord = sqlite3GetTempReg(pParse);
89967 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 1);
89968 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
89969 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
89970 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
89971 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
89972 sqlite3VdbeJumpHere(v, addrTop);
89973 sqlite3ReleaseTempReg(pParse, regRecord);
89974
89975 /* Jump here when skipping the initialization */
89976 sqlite3VdbeJumpHere(v, addrInit);
89977 }
89978 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
89979
89980 #ifndef SQLITE_OMIT_VIRTUALTABLE
89981 /*
89982 ** Allocate and populate an sqlite3_index_info structure. It is the
89983 ** responsibility of the caller to eventually release the structure
89984 ** by passing the pointer returned by this function to sqlite3_free().
@@ -89581,10 +90159,11 @@
90159 struct sqlite3_index_constraint *pIdxCons;
90160 struct sqlite3_index_constraint_usage *pUsage;
90161 WhereTerm *pTerm;
90162 int i, j;
90163 int nOrderBy;
90164 double rCost;
90165
90166 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the
90167 ** malloc in allocateIndexInfo() fails and this function returns leaving
90168 ** wsFlags in an uninitialized state, the caller may behave unpredictably.
90169 */
@@ -89666,22 +90245,31 @@
90245 for(i=0; i<pIdxInfo->nConstraint; i++){
90246 if( pUsage[i].argvIndex>0 ){
90247 pCost->used |= pWC->a[pIdxCons[i].iTermOffset].prereqRight;
90248 }
90249 }
90250
90251 /* If there is an ORDER BY clause, and the selected virtual table index
90252 ** does not satisfy it, increase the cost of the scan accordingly. This
90253 ** matches the processing for non-virtual tables in bestBtreeIndex().
90254 */
90255 rCost = pIdxInfo->estimatedCost;
90256 if( pOrderBy && pIdxInfo->orderByConsumed==0 ){
90257 rCost += estLog(rCost)*rCost;
90258 }
90259
90260 /* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
90261 ** inital value of lowestCost in this loop. If it is, then the
90262 ** (cost<lowestCost) test below will never be true.
90263 **
90264 ** Use "(double)2" instead of "2.0" in case OMIT_FLOATING_POINT
90265 ** is defined.
90266 */
90267 if( (SQLITE_BIG_DBL/((double)2))<rCost ){
90268 pCost->rCost = (SQLITE_BIG_DBL/((double)2));
90269 }else{
90270 pCost->rCost = rCost;
90271 }
90272 pCost->plan.u.pVtabIdx = pIdxInfo;
90273 if( pIdxInfo->orderByConsumed ){
90274 pCost->plan.wsFlags |= WHERE_ORDERBY;
90275 }
@@ -90078,18 +90666,18 @@
90666 **
90667 ** bInEst:
90668 ** Set to true if there was at least one "x IN (SELECT ...)" term used
90669 ** in determining the value of nInMul.
90670 **
90671 ** estBound:
90672 ** An estimate on the amount of the table that must be searched. A
90673 ** value of 100 means the entire table is searched. Range constraints
90674 ** might reduce this to a value less than 100 to indicate that only
90675 ** a fraction of the table needs searching. In the absence of
90676 ** sqlite_stat2 ANALYZE data, a single inequality reduces the search
90677 ** space to 1/3rd its original size. So an x>? constraint reduces
90678 ** estBound to 33. Two constraints (x>? AND x<?) reduce estBound to 11.
90679 **
90680 ** bSort:
90681 ** Boolean. True if there is an ORDER BY clause that will require an
90682 ** external sort (i.e. scanning the index being evaluated will not
90683 ** correctly order records).
@@ -90107,17 +90695,18 @@
90695 ** SELECT a, b, c FROM tbl WHERE a = 1;
90696 */
90697 int nEq;
90698 int bInEst = 0;
90699 int nInMul = 1;
90700 int estBound = 100;
90701 int nBound = 0; /* Number of range constraints seen */
90702 int bSort = 0;
90703 int bLookup = 0;
90704 WhereTerm *pTerm; /* A single term of the WHERE clause */
90705
90706 /* Determine the values of nEq and nInMul */
90707 for(nEq=0; nEq<pProbe->nColumn; nEq++){
 
90708 int j = pProbe->aiColumn[nEq];
90709 pTerm = findTerm(pWC, iCur, j, notReady, eqTermMask, pIdx);
90710 if( pTerm==0 ) break;
90711 wsFlags |= (WHERE_COLUMN_EQ|WHERE_ROWID_EQ);
90712 if( pTerm->eOperator & WO_IN ){
@@ -90133,22 +90722,24 @@
90722 wsFlags |= WHERE_COLUMN_NULL;
90723 }
90724 used |= pTerm->prereqRight;
90725 }
90726
90727 /* Determine the value of estBound. */
90728 if( nEq<pProbe->nColumn ){
90729 int j = pProbe->aiColumn[nEq];
90730 if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pIdx) ){
90731 WhereTerm *pTop = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pIdx);
90732 WhereTerm *pBtm = findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pIdx);
90733 whereRangeScanEst(pParse, pProbe, nEq, pBtm, pTop, &estBound);
90734 if( pTop ){
90735 nBound = 1;
90736 wsFlags |= WHERE_TOP_LIMIT;
90737 used |= pTop->prereqRight;
90738 }
90739 if( pBtm ){
90740 nBound++;
90741 wsFlags |= WHERE_BTM_LIMIT;
90742 used |= pBtm->prereqRight;
90743 }
90744 wsFlags |= (WHERE_COLUMN_RANGE|WHERE_ROWID_RANGE);
90745 }
@@ -90175,11 +90766,11 @@
90766 }
90767 }
90768
90769 /* If currently calculating the cost of using an index (not the IPK
90770 ** index), determine if all required column data may be obtained without
90771 ** using the main table (i.e. if the index is a covering
90772 ** index for this query). If it is, set the WHERE_IDX_ONLY flag in
90773 ** wsFlags. Otherwise, set the bLookup variable to true. */
90774 if( pIdx && wsFlags ){
90775 Bitmask m = pSrc->colUsed;
90776 int j;
@@ -90194,12 +90785,11 @@
90785 }else{
90786 bLookup = 1;
90787 }
90788 }
90789
90790 /*
 
90791 ** Estimate the number of rows of output. For an IN operator,
90792 ** do not let the estimate exceed half the rows in the table.
90793 */
90794 nRow = (double)(aiRowEst[nEq] * nInMul);
90795 if( bInEst && nRow*2>aiRowEst[0] ){
@@ -90214,12 +90804,12 @@
90804 cost = nRow + nInMul*estLog(aiRowEst[0]);
90805
90806 /* Adjust the number of rows and the cost downward to reflect rows
90807 ** that are excluded by range constraints.
90808 */
90809 nRow = (nRow * (double)estBound) / (double)100;
90810 cost = (cost * (double)estBound) / (double)100;
90811
90812 /* Add in the estimated cost of sorting the result
90813 */
90814 if( bSort ){
90815 cost += cost*estLog(cost);
@@ -90231,22 +90821,80 @@
90821 */
90822 if( pIdx && bLookup==0 ){
90823 cost /= (double)2;
90824 }
90825 /**** Cost of using this index has now been computed ****/
90826
90827 /* If there are additional constraints on this table that cannot
90828 ** be used with the current index, but which might lower the number
90829 ** of output rows, adjust the nRow value accordingly. This only
90830 ** matters if the current index is the least costly, so do not bother
90831 ** with this step if we already know this index will not be chosen.
90832 ** Also, never reduce the output row count below 2 using this step.
90833 **
90834 ** Do not reduce the output row count if pSrc is the only table that
90835 ** is notReady; if notReady is a power of two. This will be the case
90836 ** when the main sqlite3WhereBegin() loop is scanning for a table with
90837 ** and "optimal" index, and on such a scan the output row count
90838 ** reduction is not valid because it does not update the "pCost->used"
90839 ** bitmap. The notReady bitmap will also be a power of two when we
90840 ** are scanning for the last table in a 64-way join. We are willing
90841 ** to bypass this optimization in that corner case.
90842 */
90843 if( nRow>2 && cost<=pCost->rCost && (notReady & (notReady-1))!=0 ){
90844 int k; /* Loop counter */
90845 int nSkipEq = nEq; /* Number of == constraints to skip */
90846 int nSkipRange = nBound; /* Number of < constraints to skip */
90847 Bitmask thisTab; /* Bitmap for pSrc */
90848
90849 thisTab = getMask(pWC->pMaskSet, iCur);
90850 for(pTerm=pWC->a, k=pWC->nTerm; nRow>2 && k; k--, pTerm++){
90851 if( pTerm->wtFlags & TERM_VIRTUAL ) continue;
90852 if( (pTerm->prereqAll & notReady)!=thisTab ) continue;
90853 if( pTerm->eOperator & (WO_EQ|WO_IN|WO_ISNULL) ){
90854 if( nSkipEq ){
90855 /* Ignore the first nEq equality matches since the index
90856 ** has already accounted for these */
90857 nSkipEq--;
90858 }else{
90859 /* Assume each additional equality match reduces the result
90860 ** set size by a factor of 10 */
90861 nRow /= 10;
90862 }
90863 }else if( pTerm->eOperator & (WO_LT|WO_LE|WO_GT|WO_GE) ){
90864 if( nSkipRange ){
90865 /* Ignore the first nBound range constraints since the index
90866 ** has already accounted for these */
90867 nSkipRange--;
90868 }else{
90869 /* Assume each additional range constraint reduces the result
90870 ** set size by a factor of 3 */
90871 nRow /= 3;
90872 }
90873 }else{
90874 /* Any other expression lowers the output row count by half */
90875 nRow /= 2;
90876 }
90877 }
90878 if( nRow<2 ) nRow = 2;
90879 }
90880
90881
90882 WHERETRACE((
90883 "%s(%s): nEq=%d nInMul=%d estBound=%d bSort=%d bLookup=%d wsFlags=0x%x\n"
90884 " notReady=0x%llx nRow=%.2f cost=%.2f used=0x%llx\n",
90885 pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
90886 nEq, nInMul, estBound, bSort, bLookup, wsFlags,
90887 notReady, nRow, cost, used
90888 ));
90889
90890 /* If this index is the best we have seen so far, then record this
90891 ** index and its cost in the pCost structure.
90892 */
90893 if( (!pIdx || wsFlags)
90894 && (cost<pCost->rCost || (cost<=pCost->rCost && nRow<pCost->nRow))
90895 ){
90896 pCost->rCost = cost;
90897 pCost->nRow = nRow;
90898 pCost->used = used;
90899 pCost->plan.wsFlags = (wsFlags&wsFlagMask);
90900 pCost->plan.nEq = nEq;
@@ -90277,14 +90925,16 @@
90925 || pCost->plan.u.pIdx==0
90926 || pCost->plan.u.pIdx==pSrc->pIndex
90927 );
90928
90929 WHERETRACE(("best index is: %s\n",
90930 ((pCost->plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ? "none" :
90931 pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
90932 ));
90933
90934 bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
90935 bestAutomaticIndex(pParse, pWC, pSrc, notReady, pCost);
90936 pCost->plan.wsFlags |= eqTermMask;
90937 }
90938
90939 /*
90940 ** Find the query plan for accessing table pSrc->pTab. Write the
@@ -90750,11 +91400,15 @@
91400 }
91401 start = sqlite3VdbeCurrentAddr(v);
91402 pLevel->op = bRev ? OP_Prev : OP_Next;
91403 pLevel->p1 = iCur;
91404 pLevel->p2 = start;
91405 if( pStart==0 && pEnd==0 ){
91406 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
91407 }else{
91408 assert( pLevel->p5==0 );
91409 }
91410 if( testOp!=OP_Noop ){
91411 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
91412 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
91413 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
91414 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
@@ -91208,20 +91862,27 @@
91862
91863 /*
91864 ** Free a WhereInfo structure
91865 */
91866 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
91867 if( ALWAYS(pWInfo) ){
91868 int i;
91869 for(i=0; i<pWInfo->nLevel; i++){
91870 sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo;
91871 if( pInfo ){
91872 /* assert( pInfo->needToFreeIdxStr==0 || db->mallocFailed ); */
91873 if( pInfo->needToFreeIdxStr ){
91874 sqlite3_free(pInfo->idxStr);
91875 }
91876 sqlite3DbFree(db, pInfo);
91877 }
91878 if( pWInfo->a[i].plan.wsFlags & WHERE_TEMP_INDEX ){
91879 Index *pIdx = pWInfo->a[i].plan.u.pIdx;
91880 if( pIdx ){
91881 sqlite3DbFree(db, pIdx->zColAff);
91882 sqlite3DbFree(db, pIdx);
91883 }
91884 }
91885 }
91886 whereClauseClear(pWInfo->pWC);
91887 sqlite3DbFree(db, pWInfo);
91888 }
@@ -91338,10 +91999,11 @@
91999 sqlite3 *db; /* Database connection */
92000
92001 /* The number of tables in the FROM clause is limited by the number of
92002 ** bits in a Bitmask
92003 */
92004 testcase( pTabList->nSrc==BMS );
92005 if( pTabList->nSrc>BMS ){
92006 sqlite3ErrorMsg(pParse, "at most %d tables in a join", BMS);
92007 return 0;
92008 }
92009
@@ -91365,18 +92027,21 @@
92027 nByteWInfo +
92028 sizeof(WhereClause) +
92029 sizeof(WhereMaskSet)
92030 );
92031 if( db->mallocFailed ){
92032 sqlite3DbFree(db, pWInfo);
92033 pWInfo = 0;
92034 goto whereBeginError;
92035 }
92036 pWInfo->nLevel = nTabList;
92037 pWInfo->pParse = pParse;
92038 pWInfo->pTabList = pTabList;
92039 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
92040 pWInfo->pWC = pWC = (WhereClause *)&((u8 *)pWInfo)[nByteWInfo];
92041 pWInfo->wctrlFlags = wctrlFlags;
92042 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
92043 pMaskSet = (WhereMaskSet*)&pWC[1];
92044
92045 /* Split the WHERE clause into separate subexpressions where each
92046 ** subexpression is separated by an AND operator.
92047 */
@@ -91474,24 +92139,29 @@
92139
92140 memset(&bestPlan, 0, sizeof(bestPlan));
92141 bestPlan.rCost = SQLITE_BIG_DBL;
92142
92143 /* Loop through the remaining entries in the FROM clause to find the
92144 ** next nested loop. The loop tests all FROM clause entries
92145 ** either once or twice.
92146 **
92147 ** The first test is always performed if there are two or more entries
92148 ** remaining and never performed if there is only one FROM clause entry
92149 ** to choose from. The first test looks for an "optimal" scan. In
92150 ** this context an optimal scan is one that uses the same strategy
92151 ** for the given FROM clause entry as would be selected if the entry
92152 ** were used as the innermost nested loop. In other words, a table
92153 ** is chosen such that the cost of running that table cannot be reduced
92154 ** by waiting for other tables to run first. This "optimal" test works
92155 ** by first assuming that the FROM clause is on the inner loop and finding
92156 ** its query plan, then checking to see if that query plan uses any
92157 ** other FROM clause terms that are notReady. If no notReady terms are
92158 ** used then the "optimal" query plan works.
92159 **
92160 ** The second loop iteration is only performed if no optimal scan
92161 ** strategies were found by the first loop. This 2nd iteration is used to
92162 ** search for the lowest cost scan overall.
92163 **
92164 ** Previous versions of SQLite performed only the second iteration -
92165 ** the next outermost loop was always that with the lowest overall
92166 ** cost. However, this meant that SQLite could select the wrong plan
92167 ** for scripts such as the following:
@@ -91505,13 +92175,12 @@
92175 ** However, since the cost of a linear scan through table t2 is the same
92176 ** as the cost of a linear scan through table t1, a simple greedy
92177 ** algorithm may choose to use t2 for the outer loop, which is a much
92178 ** costlier approach.
92179 */
92180 for(isOptimal=(iFrom<nTabList-1); isOptimal>=0; isOptimal--){
92181 Bitmask mask; /* Mask of tables not yet ready */
 
92182 for(j=iFrom, pTabItem=&pTabList->a[j]; j<nTabList; j++, pTabItem++){
92183 int doNotReorder; /* True if this table should not be reordered */
92184 WhereCost sCost; /* Cost information from best[Virtual]Index() */
92185 ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
92186
@@ -91520,10 +92189,11 @@
92189 m = getMask(pMaskSet, pTabItem->iCursor);
92190 if( (m & notReady)==0 ){
92191 if( j==iFrom ) iFrom++;
92192 continue;
92193 }
92194 mask = (isOptimal ? m : notReady);
92195 pOrderBy = ((i==0 && ppOrderBy )?*ppOrderBy:0);
92196
92197 assert( pTabItem->pTab );
92198 #ifndef SQLITE_OMIT_VIRTUALTABLE
92199 if( IsVirtual(pTabItem->pTab) ){
@@ -91535,12 +92205,15 @@
92205 bestBtreeIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost);
92206 }
92207 assert( isOptimal || (sCost.used&notReady)==0 );
92208
92209 if( (sCost.used&notReady)==0
92210 && (bestJ<0 || sCost.rCost<bestPlan.rCost
92211 || (sCost.rCost<=bestPlan.rCost && sCost.nRow<bestPlan.nRow))
92212 ){
92213 WHERETRACE(("... best so far with cost=%g and nRow=%g\n",
92214 sCost.rCost, sCost.nRow));
92215 bestPlan = sCost;
92216 bestJ = j;
92217 }
92218 if( doNotReorder ) break;
92219 }
@@ -91552,17 +92225,20 @@
92225 if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
92226 *ppOrderBy = 0;
92227 }
92228 andFlags &= bestPlan.plan.wsFlags;
92229 pLevel->plan = bestPlan.plan;
92230 testcase( bestPlan.plan.wsFlags & WHERE_INDEXED );
92231 testcase( bestPlan.plan.wsFlags & WHERE_TEMP_INDEX );
92232 if( bestPlan.plan.wsFlags & (WHERE_INDEXED|WHERE_TEMP_INDEX) ){
92233 pLevel->iIdxCur = pParse->nTab++;
92234 }else{
92235 pLevel->iIdxCur = -1;
92236 }
92237 notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
92238 pLevel->iFrom = (u8)bestJ;
92239 if( bestPlan.nRow>=(double)1 ) pParse->nQueryLoop *= bestPlan.nRow;
92240
92241 /* Check that if the table scanned by this loop iteration had an
92242 ** INDEXED BY clause attached to it, that the named index is being
92243 ** used for the scan. If not, then query compilation has failed.
92244 ** Return an error.
@@ -91605,10 +92281,11 @@
92281
92282 /* Open all tables in the pTabList and any indices selected for
92283 ** searching those tables.
92284 */
92285 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
92286 notReady = ~(Bitmask)0;
92287 for(i=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
92288 Table *pTab; /* Table to open */
92289 int iDb; /* Index of database containing table/index */
92290
92291 #ifndef SQLITE_OMIT_EXPLAIN
@@ -91617,11 +92294,13 @@
92294 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
92295 zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName);
92296 if( pItem->zAlias ){
92297 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
92298 }
92299 if( (pLevel->plan.wsFlags & WHERE_TEMP_INDEX)!=0 ){
92300 zMsg = sqlite3MAppendf(db, zMsg, "%s WITH AUTOMATIC INDEX", zMsg);
92301 }else if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
92302 zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s",
92303 zMsg, pLevel->plan.u.pIdx->zName);
92304 }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
92305 zMsg = sqlite3MAppendf(db, zMsg, "%s VIA MULTI-INDEX UNION", zMsg);
92306 }else if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
@@ -91640,12 +92319,15 @@
92319 sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC);
92320 }
92321 #endif /* SQLITE_OMIT_EXPLAIN */
92322 pTabItem = &pTabList->a[pLevel->iFrom];
92323 pTab = pTabItem->pTab;
92324 pLevel->iTabCur = pTabItem->iCursor;
92325 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
92326 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){
92327 /* Do nothing */
92328 }else
92329 #ifndef SQLITE_OMIT_VIRTUALTABLE
92330 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
92331 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
92332 int iCur = pTabItem->iCursor;
92333 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
@@ -91653,10 +92335,12 @@
92335 #endif
92336 if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0
92337 && (wctrlFlags & WHERE_OMIT_OPEN)==0 ){
92338 int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
92339 sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
92340 testcase( pTab->nCol==BMS-1 );
92341 testcase( pTab->nCol==BMS );
92342 if( !pWInfo->okOnePass && pTab->nCol<BMS ){
92343 Bitmask b = pTabItem->colUsed;
92344 int n = 0;
92345 for(; b; b=b>>1, n++){}
92346 sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1,
@@ -91664,11 +92348,15 @@
92348 assert( n<=pTab->nCol );
92349 }
92350 }else{
92351 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
92352 }
92353 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
92354 if( (pLevel->plan.wsFlags & WHERE_TEMP_INDEX)!=0 ){
92355 constructAutomaticIndex(pParse, pWC, pTabItem, notReady, pLevel);
92356 }else
92357 #endif
92358 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
92359 Index *pIx = pLevel->plan.u.pIdx;
92360 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
92361 int iIdxCur = pLevel->iIdxCur;
92362 assert( pIx->pSchema==pTab->pSchema );
@@ -91676,12 +92364,14 @@
92364 sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIx->tnum, iDb,
92365 (char*)pKey, P4_KEYINFO_HANDOFF);
92366 VdbeComment((v, "%s", pIx->zName));
92367 }
92368 sqlite3CodeVerifySchema(pParse, iDb);
92369 notReady &= ~getMask(pWC->pMaskSet, pTabItem->iCursor);
92370 }
92371 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
92372 if( db->mallocFailed ) goto whereBeginError;
92373
92374 /* Generate the code to do the search. Each iteration of the for
92375 ** loop below generates code for a single nested loop of the VM
92376 ** program.
92377 */
@@ -91745,11 +92435,14 @@
92435 */
92436 return pWInfo;
92437
92438 /* Jump here if malloc fails */
92439 whereBeginError:
92440 if( pWInfo ){
92441 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
92442 whereInfoFree(db, pWInfo);
92443 }
92444 return 0;
92445 }
92446
92447 /*
92448 ** Generate the end of the WHERE loop. See comments on
@@ -91815,16 +92508,19 @@
92508 assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
92509 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
92510 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
92511 Table *pTab = pTabItem->pTab;
92512 assert( pTab!=0 );
92513 if( (pTab->tabFlags & TF_Ephemeral)==0
92514 && pTab->pSelect==0
92515 && (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0
92516 ){
92517 int ws = pLevel->plan.wsFlags;
92518 if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
92519 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
92520 }
92521 if( (ws & WHERE_INDEXED)!=0 && (ws & WHERE_TEMP_INDEX)==0 ){
92522 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
92523 }
92524 }
92525
92526 /* If this scan uses an index, make code substitutions to read data
@@ -91868,10 +92564,11 @@
92564 }
92565 }
92566
92567 /* Final cleanup
92568 */
92569 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
92570 whereInfoFree(db, pWInfo);
92571 return;
92572 }
92573
92574 /************** End of where.c ***********************************************/
@@ -98071,11 +98768,11 @@
98768 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
98769 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
98770 db->autoCommit = 1;
98771 db->nextAutovac = -1;
98772 db->nextPagesize = 0;
98773 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex
98774 #if SQLITE_DEFAULT_FILE_FORMAT<4
98775 | SQLITE_LegacyFileFmt
98776 #endif
98777 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
98778 | SQLITE_LoadExtension
@@ -99199,11 +99896,11 @@
99896 ** and so on.
99897 **
99898 ** This is similar in concept to how sqlite encodes "varints" but
99899 ** the encoding is not the same. SQLite varints are big-endian
99900 ** are are limited to 9 bytes in length whereas FTS3 varints are
99901 ** little-endian and can be up to 10 bytes in length (in theory).
99902 **
99903 ** Example encodings:
99904 **
99905 ** 1: 0x01
99906 ** 127: 0x7f
@@ -99210,30 +99907,30 @@
99907 ** 128: 0x81 0x00
99908 **
99909 **
99910 **** Document lists ****
99911 ** A doclist (document list) holds a docid-sorted list of hits for a
99912 ** given term. Doclists hold docids and associated token positions.
99913 ** A docid is the unique integer identifier for a single document.
99914 ** A position is the index of a word within the document. The first
99915 ** word of the document has a position of 0.
99916 **
99917 ** FTS3 used to optionally store character offsets using a compile-time
99918 ** option. But that functionality is no longer supported.
99919 **
99920 ** A doclist is stored like this:
99921 **
99922 ** array {
99923 ** varint docid;
99924 ** array { (position list for column 0)
99925 ** varint position; (2 more than the delta from previous position)
99926 ** }
99927 ** array {
99928 ** varint POS_COLUMN; (marks start of position list for new column)
99929 ** varint column; (index of new column)
99930 ** array {
99931 ** varint position; (2 more than the delta from previous position)
99932 ** }
99933 ** }
99934 ** varint POS_END; (marks end of positions for this document.
99935 ** }
99936 **
@@ -99241,11 +99938,11 @@
99938 ** memory. A "position" is an index of a token in the token stream
99939 ** generated by the tokenizer. Note that POS_END and POS_COLUMN occur
99940 ** in the same logical place as the position element, and act as sentinals
99941 ** ending a position list array. POS_END is 0. POS_COLUMN is 1.
99942 ** The positions numbers are not stored literally but rather as two more
99943 ** than the difference from the prior position, or the just the position plus
99944 ** 2 for the first position. Example:
99945 **
99946 ** label: A B C D E F G H I J K
99947 ** value: 123 5 9 1 1 14 35 0 234 72 0
99948 **
@@ -99255,18 +99952,18 @@
99952 ** new column is column number 1. There are two positions at 12 and 45
99953 ** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
99954 ** 234 at I is the next docid. It has one position 72 (72-2) and then
99955 ** terminates with the 0 at K.
99956 **
99957 ** A "position-list" is the list of positions for multiple columns for
99958 ** a single docid. A "column-list" is the set of positions for a single
99959 ** column. Hence, a position-list consists of one or more column-lists,
99960 ** a document record consists of a docid followed by a position-list and
99961 ** a doclist consists of one or more document records.
99962 **
99963 ** A bare doclist omits the position information, becoming an
99964 ** array of varint-encoded docids.
99965 **
99966 **** Segment leaf nodes ****
99967 ** Segment leaf nodes store terms and doclists, ordered by term. Leaf
99968 ** nodes are written using LeafWriter, and read using LeafReader (to
99969 ** iterate through a single leaf node's data) and LeavesReader (to
@@ -99776,10 +100473,24 @@
100473 ** Maximum length of a varint encoded integer. The varint format is different
100474 ** from that used by SQLite, so the maximum length is 10, not 9.
100475 */
100476 #define FTS3_VARINT_MAX 10
100477
100478 /*
100479 ** The testcase() macro is only used by the amalgamation. If undefined,
100480 ** make it a no-op.
100481 */
100482 #ifndef testcase
100483 # define testcase(X)
100484 #endif
100485
100486 /*
100487 ** Terminator values for position-lists and column-lists.
100488 */
100489 #define POS_COLUMN (1) /* Column-list terminator */
100490 #define POS_END (0) /* Position-list terminator */
100491
100492 /*
100493 ** This section provides definitions to allow the
100494 ** FTS3 extension to be compiled outside of the
100495 ** amalgamation.
100496 */
@@ -100087,12 +100798,11 @@
100798 *pi = (int) i;
100799 return ret;
100800 }
100801
100802 /*
100803 ** Return the number of bytes required to encode v as a varint
 
100804 */
100805 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64 v){
100806 int i = 0;
100807 do{
100808 i++;
@@ -100139,11 +100849,11 @@
100849 }
100850 }
100851
100852 /*
100853 ** Read a single varint from the doclist at *pp and advance *pp to point
100854 ** to the first byte past the end of the varint. Add the value of the varint
100855 ** to *pVal.
100856 */
100857 static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){
100858 sqlite3_int64 iVal;
100859 *pp += sqlite3Fts3GetVarint(*pp, &iVal);
@@ -100195,11 +100905,11 @@
100905 ** and then evaluate those statements. The success code is writting
100906 ** into *pRc.
100907 **
100908 ** If *pRc is initially non-zero then this routine is a no-op.
100909 */
100910 static void fts3DbExec(
100911 int *pRc, /* Success code */
100912 sqlite3 *db, /* Database in which to run SQL */
100913 const char *zFormat, /* Format string for SQL */
100914 ... /* Arguments to the format string */
100915 ){
@@ -100275,10 +100985,14 @@
100985
100986 /*
100987 ** Create the backing store tables (%_content, %_segments and %_segdir)
100988 ** required by the FTS3 table passed as the only argument. This is done
100989 ** as part of the vtab xCreate() method.
100990 **
100991 ** If the p->bHasDocsize boolean is true (indicating that this is an
100992 ** FTS4 table, not an FTS3 table) then also create the %_docsize and
100993 ** %_stat tables required by FTS4.
100994 */
100995 static int fts3CreateTables(Fts3Table *p){
100996 int rc = SQLITE_OK; /* Return code */
100997 int i; /* Iterator variable */
100998 char *zContentCols; /* Columns of %_content table */
@@ -100367,11 +101081,11 @@
101081 ** This function is the implementation of both the xConnect and xCreate
101082 ** methods of the FTS3 virtual table.
101083 **
101084 ** The argv[] array contains the following:
101085 **
101086 ** argv[0] -> module name ("fts3" or "fts4")
101087 ** argv[1] -> database name
101088 ** argv[2] -> table name
101089 ** argv[...] -> "column name" and other module argument fields.
101090 */
101091 static int fts3InitVtab(
@@ -100386,16 +101100,16 @@
101100 Fts3Hash *pHash = (Fts3Hash *)pAux;
101101 Fts3Table *p; /* Pointer to allocated vtab */
101102 int rc; /* Return code */
101103 int i; /* Iterator variable */
101104 int nByte; /* Size of allocation used for *p */
101105 int iCol; /* Column index */
101106 int nString = 0; /* Bytes required to hold all column names */
101107 int nCol = 0; /* Number of columns in the FTS table */
101108 char *zCsr; /* Space for holding column names */
101109 int nDb; /* Bytes required to hold database name */
101110 int nName; /* Bytes required to hold table name */
101111
101112 const char *zTokenizer = 0; /* Name of tokenizer to use */
101113 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
101114
101115 nDb = (int)strlen(argv[1]) + 1;
@@ -100621,10 +101335,15 @@
101335 sqlite3_free(pCsr->aMatchinfo);
101336 sqlite3_free(pCsr);
101337 return SQLITE_OK;
101338 }
101339
101340 /*
101341 ** Position the pCsr->pStmt statement so that it is on the row
101342 ** of the %_content table that contains the last match. Return
101343 ** SQLITE_OK on success.
101344 */
101345 static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
101346 if( pCsr->isRequireSeek ){
101347 pCsr->isRequireSeek = 0;
101348 sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
101349 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
@@ -100647,10 +101366,21 @@
101366 }else{
101367 return SQLITE_OK;
101368 }
101369 }
101370
101371 /*
101372 ** Advance the cursor to the next row in the %_content table that
101373 ** matches the search criteria. For a MATCH search, this will be
101374 ** the next row that matches. For a full-table scan, this will be
101375 ** simply the next row in the %_content table. For a docid lookup,
101376 ** this routine simply sets the EOF flag.
101377 **
101378 ** Return SQLITE_OK if nothing goes wrong. SQLITE_OK is returned
101379 ** even if we reach end-of-file. The fts3EofMethod() will be called
101380 ** subsequently to determine whether or not an EOF was hit.
101381 */
101382 static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
101383 int rc = SQLITE_OK; /* Return code */
101384 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
101385
101386 if( pCsr->aDoclist==0 ){
@@ -100782,10 +101512,15 @@
101512
101513 /*
101514 ** When this function is called, *ppPoslist is assumed to point to the
101515 ** start of a position-list. After it returns, *ppPoslist points to the
101516 ** first byte after the position-list.
101517 **
101518 ** A position list is list of positions (delta encoded) and columns for
101519 ** a single document record of a doclist. So, in other words, this
101520 ** routine advances *ppPoslist so that it points to the next docid in
101521 ** the doclist, or to the first byte past the end of the doclist.
101522 **
101523 ** If pp is not NULL, then the contents of the position list are copied
101524 ** to *pp. *pp is set to point to the first byte past the last byte copied
101525 ** before this function returns.
101526 */
@@ -100792,21 +101527,24 @@
101527 static void fts3PoslistCopy(char **pp, char **ppPoslist){
101528 char *pEnd = *ppPoslist;
101529 char c = 0;
101530
101531 /* The end of a position list is marked by a zero encoded as an FTS3
101532 ** varint. A single POS_END (0) byte. Except, if the 0 byte is preceded by
101533 ** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
101534 ** of some other, multi-byte, value.
101535 **
101536 ** The following while-loop moves pEnd to point to the first byte that is not
101537 ** immediately preceded by a byte with the 0x80 bit set. Then increments
101538 ** pEnd once more so that it points to the byte immediately following the
101539 ** last byte in the position-list.
101540 */
101541 while( *pEnd | c ){
101542 c = *pEnd++ & 0x80;
101543 testcase( c!=0 && (*pEnd)==0 );
101544 }
101545 pEnd++; /* Advance past the POS_END terminator byte */
101546
101547 if( pp ){
101548 int n = (int)(pEnd - *ppPoslist);
101549 char *p = *pp;
101550 memcpy(p, *ppPoslist, n);
@@ -100814,16 +101552,38 @@
101552 *pp = p;
101553 }
101554 *ppPoslist = pEnd;
101555 }
101556
101557 /*
101558 ** When this function is called, *ppPoslist is assumed to point to the
101559 ** start of a column-list. After it returns, *ppPoslist points to the
101560 ** to the terminator (POS_COLUMN or POS_END) byte of the column-list.
101561 **
101562 ** A column-list is list of delta-encoded positions for a single column
101563 ** within a single document within a doclist.
101564 **
101565 ** The column-list is terminated either by a POS_COLUMN varint (1) or
101566 ** a POS_END varint (0). This routine leaves *ppPoslist pointing to
101567 ** the POS_COLUMN or POS_END that terminates the column-list.
101568 **
101569 ** If pp is not NULL, then the contents of the column-list are copied
101570 ** to *pp. *pp is set to point to the first byte past the last byte copied
101571 ** before this function returns. The POS_COLUMN or POS_END terminator
101572 ** is not copied into *pp.
101573 */
101574 static void fts3ColumnlistCopy(char **pp, char **ppPoslist){
101575 char *pEnd = *ppPoslist;
101576 char c = 0;
101577
101578 /* A column-list is terminated by either a 0x01 or 0x00 byte that is
101579 ** not part of a multi-byte varint.
101580 */
101581 while( 0xFE & (*pEnd | c) ){
101582 c = *pEnd++ & 0x80;
101583 testcase( c!=0 && ((*pEnd)&0xfe)==0 );
101584 }
101585 if( pp ){
101586 int n = (int)(pEnd - *ppPoslist);
101587 char *p = *pp;
101588 memcpy(p, *ppPoslist, n);
101589 p += n;
@@ -100831,41 +101591,49 @@
101591 }
101592 *ppPoslist = pEnd;
101593 }
101594
101595 /*
101596 ** Value used to signify the end of an position-list. This is safe because
101597 ** it is not possible to have a document with 2^31 terms.
101598 */
101599 #define POSITION_LIST_END 0x7fffffff
101600
101601 /*
101602 ** This function is used to help parse position-lists. When this function is
101603 ** called, *pp may point to the start of the next varint in the position-list
101604 ** being parsed, or it may point to 1 byte past the end of the position-list
101605 ** (in which case **pp will be a terminator bytes POS_END (0) or
101606 ** (1)).
101607 **
101608 ** If *pp points past the end of the current position-list, set *pi to
101609 ** POSITION_LIST_END and return. Otherwise, read the next varint from *pp,
101610 ** increment the current value of *pi by the value read, and set *pp to
101611 ** point to the next value before returning.
101612 **
101613 ** Before calling this routine *pi must be initialized to the value of
101614 ** the previous position, or zero if we are reading the first position
101615 ** in the position-list. Because positions are delta-encoded, the value
101616 ** of the previous position is needed in order to compute the value of
101617 ** the next position.
101618 */
101619 static void fts3ReadNextPos(
101620 char **pp, /* IN/OUT: Pointer into position-list buffer */
101621 sqlite3_int64 *pi /* IN/OUT: Value read from position-list */
101622 ){
101623 if( (**pp)&0xFE ){
101624 fts3GetDeltaVarint(pp, pi);
101625 *pi -= 2;
101626 }else{
101627 *pi = POSITION_LIST_END;
101628 }
101629 }
101630
101631 /*
101632 ** If parameter iCol is not 0, write an POS_COLUMN (1) byte followed by
101633 ** the value of iCol encoded as a varint to *pp. This will start a new
101634 ** column list.
101635 **
101636 ** Set *pp to point to the byte just after the last byte written before
101637 ** returning (do not modify it if iCol==0). Return the total number of bytes
101638 ** written (0 if iCol==0).
101639 */
@@ -100879,11 +101647,15 @@
101647 }
101648 return n;
101649 }
101650
101651 /*
101652 ** Compute the union of two position lists. The output written
101653 ** into *pp contains all positions of both *pp1 and *pp2 in sorted
101654 ** order and with any duplicates removed. All pointers are
101655 ** updated appropriately. The caller is responsible for insuring
101656 ** that there is enough space in *pp to hold the complete output.
101657 */
101658 static void fts3PoslistMerge(
101659 char **pp, /* Output buffer */
101660 char **pp1, /* Left input list */
101661 char **pp2 /* Right input list */
@@ -100891,36 +101663,37 @@
101663 char *p = *pp;
101664 char *p1 = *pp1;
101665 char *p2 = *pp2;
101666
101667 while( *p1 || *p2 ){
101668 int iCol1; /* The current column index in pp1 */
101669 int iCol2; /* The current column index in pp2 */
101670
101671 if( *p1==POS_COLUMN ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
101672 else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
101673 else iCol1 = 0;
101674
101675 if( *p2==POS_COLUMN ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
101676 else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
101677 else iCol2 = 0;
101678
101679 if( iCol1==iCol2 ){
101680 sqlite3_int64 i1 = 0; /* Last position from pp1 */
101681 sqlite3_int64 i2 = 0; /* Last position from pp2 */
101682 sqlite3_int64 iPrev = 0;
101683 int n = fts3PutColNumber(&p, iCol1);
101684 p1 += n;
101685 p2 += n;
101686
101687 /* At this point, both p1 and p2 point to the start of column-lists
101688 ** for the same column (the column with index iCol1 and iCol2).
101689 ** A column-list is a list of non-negative delta-encoded varints, each
101690 ** incremented by 2 before being stored. Each list is terminated by a
101691 ** POS_END (0) or POS_COLUMN (1). The following block merges the two lists
101692 ** and writes the results to buffer p. p is left pointing to the byte
101693 ** after the list written. No terminator (POS_END or POS_COLUMN) is
101694 ** written to the output.
101695 */
101696 fts3GetDeltaVarint(&p1, &i1);
101697 fts3GetDeltaVarint(&p2, &i2);
101698 do {
101699 fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
@@ -100931,21 +101704,21 @@
101704 }else if( i1<i2 ){
101705 fts3ReadNextPos(&p1, &i1);
101706 }else{
101707 fts3ReadNextPos(&p2, &i2);
101708 }
101709 }while( i1!=POSITION_LIST_END || i2!=POSITION_LIST_END );
101710 }else if( iCol1<iCol2 ){
101711 p1 += fts3PutColNumber(&p, iCol1);
101712 fts3ColumnlistCopy(&p, &p1);
101713 }else{
101714 p2 += fts3PutColNumber(&p, iCol2);
101715 fts3ColumnlistCopy(&p, &p2);
101716 }
101717 }
101718
101719 *p++ = POS_END;
101720 *pp = p;
101721 *pp1 = p1 + 1;
101722 *pp2 = p2 + 1;
101723 }
101724
@@ -100964,15 +101737,15 @@
101737 char *p2 = *pp2;
101738
101739 int iCol1 = 0;
101740 int iCol2 = 0;
101741 assert( *p1!=0 && *p2!=0 );
101742 if( *p1==POS_COLUMN ){
101743 p1++;
101744 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
101745 }
101746 if( *p2==POS_COLUMN ){
101747 p2++;
101748 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
101749 }
101750
101751 while( 1 ){
@@ -100981,15 +101754,16 @@
101754 sqlite3_int64 iPrev = 0;
101755 sqlite3_int64 iPos1 = 0;
101756 sqlite3_int64 iPos2 = 0;
101757
101758 if( pp && iCol1 ){
101759 *p++ = POS_COLUMN;
101760 p += sqlite3Fts3PutVarint(p, iCol1);
101761 }
101762
101763 assert( *p1!=POS_END && *p1!=POS_COLUMN );
101764 assert( *p2!=POS_END && *p2!=POS_COLUMN );
101765 fts3GetDeltaVarint(&p1, &iPos1); iPos1 -= 2;
101766 fts3GetDeltaVarint(&p2, &iPos2); iPos2 -= 2;
101767
101768 while( 1 ){
101769 if( iPos2>iPos1 && iPos2<=iPos1+nToken ){
@@ -101237,10 +102011,11 @@
102011 }
102012
102013 default: assert( mergetype==MERGE_POS_NEAR || mergetype==MERGE_NEAR ); {
102014 char *aTmp = 0;
102015 char **ppPos = 0;
102016
102017 if( mergetype==MERGE_POS_NEAR ){
102018 ppPos = &p;
102019 aTmp = sqlite3_malloc(2*(n1+n2+1));
102020 if( !aTmp ){
102021 return SQLITE_NOMEM;
@@ -101341,13 +102116,13 @@
102116 ** This function retreives the doclist for the specified term (or term
102117 ** prefix) from the database.
102118 **
102119 ** The returned doclist may be in one of two formats, depending on the
102120 ** value of parameter isReqPos. If isReqPos is zero, then the doclist is
102121 ** a sorted list of delta-compressed docids (a bare doclist). If isReqPos
102122 ** is non-zero, then the returned list is in the same format as is stored
102123 ** in the database without the found length specifier at the start of on-disk
102124 ** doclists.
102125 */
102126 static int fts3TermSelect(
102127 Fts3Table *p, /* Virtual table handle */
102128 int iColumn, /* Column to query (or -ve for all columns) */
@@ -101603,11 +102378,13 @@
102378 return rc;
102379 }
102380
102381 /*
102382 ** Evaluate the full-text expression pExpr against fts3 table pTab. Store
102383 ** the resulting doclist in *paOut and *pnOut. This routine mallocs for
102384 ** the space needed to store the output. The caller is responsible for
102385 ** freeing the space when it has finished.
102386 */
102387 static int evalFts3Expr(
102388 Fts3Table *p, /* Virtual table handle */
102389 Fts3Expr *pExpr, /* Parsed fts3 expression */
102390 char **paOut, /* OUT: Pointer to malloc'd result buffer */
@@ -108163,11 +108940,11 @@
108940 ** This is done as part of extracting the snippet text, not when selecting
108941 ** the snippet. Snippet selection is done based on doclists only, so there
108942 ** is no way for fts3BestSnippet() to know whether or not the document
108943 ** actually contains terms that follow the final highlighted term.
108944 */
108945 static int fts3SnippetShift(
108946 Fts3Table *pTab, /* FTS3 table snippet comes from */
108947 int nSnippet, /* Number of tokens desired for snippet */
108948 const char *zDoc, /* Document text to extract snippet from */
108949 int nDoc, /* Size of buffer zDoc in bytes */
108950 int *piPos, /* IN/OUT: First token of snippet */
@@ -111280,10 +112057,11 @@
112057 rc = SQLITE_CONSTRAINT;
112058 goto constraint;
112059 }
112060 rc = sqlite3_reset(pRtree->pReadRowid);
112061 }
112062 *pRowid = cell.iRowid;
112063
112064 if( rc==SQLITE_OK ){
112065 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
112066 }
112067 if( rc==SQLITE_OK ){
112068
+56 -52
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.6.23.1"
110
+#define SQLITE_VERSION "3.6.23"
111111
#define SQLITE_VERSION_NUMBER 3006023
112
-#define SQLITE_SOURCE_ID "2010-03-26 22:28:06 b078b588d617e07886ad156e9f54ade6d823568e"
112
+#define SQLITE_SOURCE_ID "2010-04-15 23:24:29 f96782b389b5b97b488dc5814f7082e0393f64cd"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -144,11 +144,10 @@
144144
SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
145145
SQLITE_API const char *sqlite3_libversion(void);
146146
SQLITE_API const char *sqlite3_sourceid(void);
147147
SQLITE_API int sqlite3_libversion_number(void);
148148
149
-#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
150149
/*
151150
** CAPI3REF: Run-Time Library Compilation Options Diagnostics
152151
**
153152
** ^The sqlite3_compileoption_used() function returns 0 or 1
154153
** indicating whether the specified option was defined at
@@ -167,13 +166,14 @@
167166
** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
168167
**
169168
** See also: SQL functions [sqlite_compileoption_used()] and
170169
** [sqlite_compileoption_get()] and the [compile_options pragma].
171170
*/
171
+#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
172172
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
173173
SQLITE_API const char *sqlite3_compileoption_get(int N);
174
-#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
174
+#endif
175175
176176
/*
177177
** CAPI3REF: Test To See If The Library Is Threadsafe
178178
**
179179
** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -971,15 +971,14 @@
971971
**
972972
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
973973
** ^If the option is unknown or SQLite is unable to set the option
974974
** then this routine returns a non-zero [error code].
975975
*/
976
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
976
+SQLITE_API int sqlite3_config(int, ...);
977977
978978
/*
979979
** CAPI3REF: Configure database connections
980
-** EXPERIMENTAL
981980
**
982981
** The sqlite3_db_config() interface is used to make configuration
983982
** changes to a [database connection]. The interface is similar to
984983
** [sqlite3_config()] except that the changes apply to a single
985984
** [database connection] (specified in the first argument). The
@@ -995,15 +994,14 @@
995994
** Additional arguments depend on the verb.
996995
**
997996
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
998997
** the call is considered successful.
999998
*/
1000
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
999
+SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
10011000
10021001
/*
10031002
** CAPI3REF: Memory Allocation Routines
1004
-** EXPERIMENTAL
10051003
**
10061004
** An instance of this object defines the interface between SQLite
10071005
** and low-level memory allocation routines.
10081006
**
10091007
** This object is used in only one place in the SQLite interface.
@@ -1081,11 +1079,10 @@
10811079
void *pAppData; /* Argument to xInit() and xShutdown() */
10821080
};
10831081
10841082
/*
10851083
** CAPI3REF: Configuration Options
1086
-** EXPERIMENTAL
10871084
**
10881085
** These constants are the available integer configuration options that
10891086
** can be passed as the first argument to the [sqlite3_config()] interface.
10901087
**
10911088
** New configuration options may be added in future releases of SQLite.
@@ -1267,10 +1264,28 @@
12671264
** <dt>SQLITE_CONFIG_GETPCACHE</dt>
12681265
** <dd> ^(This option takes a single argument which is a pointer to an
12691266
** [sqlite3_pcache_methods] object. SQLite copies of the current
12701267
** page cache implementation into that object.)^ </dd>
12711268
**
1269
+** <dt>SQLITE_CONFIG_LOG</dt>
1270
+** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1271
+** function with a call signature of void(*)(void*,int,const char*),
1272
+** and a pointer to void. ^If the function pointer is not NULL, it is
1273
+** invoked by [sqlite3_log()] to process each logging event. ^If the
1274
+** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1275
+** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1276
+** passed through as the first parameter to the application-defined logger
1277
+** function whenever that function is invoked. ^The second parameter to
1278
+** the logger function is a copy of the first parameter to the corresponding
1279
+** [sqlite3_log()] call and is intended to be a [result code] or an
1280
+** [extended result code]. ^The third parameter passed to the logger is
1281
+** log message after formatting via [sqlite3_snprintf()].
1282
+** The SQLite logging interface is not reentrant; the logger function
1283
+** supplied by the application must not invoke any SQLite interface.
1284
+** In a multi-threaded application, the application-defined logger
1285
+** function must be threadsafe. </dd>
1286
+**
12721287
** </dl>
12731288
*/
12741289
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
12751290
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
12761291
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1287,12 +1302,11 @@
12871302
#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
12881303
#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
12891304
#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
12901305
12911306
/*
1292
-** CAPI3REF: Configuration Options
1293
-** EXPERIMENTAL
1307
+** CAPI3REF: Database Connection Configuration Options
12941308
**
12951309
** These constants are the available integer configuration options that
12961310
** can be passed as the second argument to the [sqlite3_db_config()] interface.
12971311
**
12981312
** New configuration options may be added in future releases of SQLite.
@@ -2064,11 +2078,10 @@
20642078
#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
20652079
#define SQLITE_COPY 0 /* No longer used */
20662080
20672081
/*
20682082
** CAPI3REF: Tracing And Profiling Functions
2069
-** EXPERIMENTAL
20702083
**
20712084
** These routines register callback functions that can be used for
20722085
** tracing and profiling the execution of SQL statements.
20732086
**
20742087
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2082,11 +2095,11 @@
20822095
** ^The callback function registered by sqlite3_profile() is invoked
20832096
** as each SQL statement finishes. ^The profile callback contains
20842097
** the original statement text and an estimate of wall-clock time
20852098
** of how long that statement took to run.
20862099
*/
2087
-SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2100
+SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
20882101
SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
20892102
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
20902103
20912104
/*
20922105
** CAPI3REF: Query Progress Callbacks
@@ -3687,11 +3700,11 @@
36873700
sqlite3*,
36883701
void*,
36893702
void(*)(void*,sqlite3*,int eTextRep,const void*)
36903703
);
36913704
3692
-#if SQLITE_HAS_CODEC
3705
+#ifdef SQLITE_HAS_CODEC
36933706
/*
36943707
** Specify the key for an encrypted database. This routine should be
36953708
** called right after sqlite3_open().
36963709
**
36973710
** The code to implement this API is not available in the public release
@@ -3870,12 +3883,10 @@
38703883
** ^For the purposes of this API, a transaction is said to have been
38713884
** rolled back if an explicit "ROLLBACK" statement is executed, or
38723885
** an error or constraint causes an implicit rollback to occur.
38733886
** ^The rollback callback is not invoked if a transaction is
38743887
** automatically rolled back because the database connection is closed.
3875
-** ^The rollback callback is not invoked if a transaction is
3876
-** rolled back because a commit callback returned non-zero.
38773888
**
38783889
** See also the [sqlite3_update_hook()] interface.
38793890
*/
38803891
SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
38813892
SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
@@ -4157,12 +4168,10 @@
41574168
** ^This function disables automatic extensions in all threads.
41584169
*/
41594170
SQLITE_API void sqlite3_reset_auto_extension(void);
41604171
41614172
/*
4162
-****** EXPERIMENTAL - subject to change without notice **************
4163
-**
41644173
** The interface to the virtual-table mechanism is currently considered
41654174
** to be experimental. The interface might change in incompatible ways.
41664175
** If this is a problem for you, do not use the interface at this time.
41674176
**
41684177
** When the virtual-table mechanism stabilizes, we will declare the
@@ -4178,11 +4187,10 @@
41784187
typedef struct sqlite3_module sqlite3_module;
41794188
41804189
/*
41814190
** CAPI3REF: Virtual Table Object
41824191
** KEYWORDS: sqlite3_module {virtual table module}
4183
-** EXPERIMENTAL
41844192
**
41854193
** This structure, sometimes called a a "virtual table module",
41864194
** defines the implementation of a [virtual tables].
41874195
** This structure consists mostly of methods for the module.
41884196
**
@@ -4225,11 +4233,10 @@
42254233
};
42264234
42274235
/*
42284236
** CAPI3REF: Virtual Table Indexing Information
42294237
** KEYWORDS: sqlite3_index_info
4230
-** EXPERIMENTAL
42314238
**
42324239
** The sqlite3_index_info structure and its substructures is used to
42334240
** pass information into and receive the reply from the [xBestIndex]
42344241
** method of a [virtual table module]. The fields under **Inputs** are the
42354242
** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4307,11 +4314,10 @@
43074314
#define SQLITE_INDEX_CONSTRAINT_GE 32
43084315
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
43094316
43104317
/*
43114318
** CAPI3REF: Register A Virtual Table Implementation
4312
-** EXPERIMENTAL
43134319
**
43144320
** ^These routines are used to register a new [virtual table module] name.
43154321
** ^Module names must be registered before
43164322
** creating a new [virtual table] using the module and before using a
43174323
** preexisting [virtual table] for the module.
@@ -4329,17 +4335,17 @@
43294335
** invoke the destructor function (if it is not NULL) when SQLite
43304336
** no longer needs the pClientData pointer. ^The sqlite3_create_module()
43314337
** interface is equivalent to sqlite3_create_module_v2() with a NULL
43324338
** destructor.
43334339
*/
4334
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
4340
+SQLITE_API int sqlite3_create_module(
43354341
sqlite3 *db, /* SQLite connection to register module with */
43364342
const char *zName, /* Name of the module */
43374343
const sqlite3_module *p, /* Methods for the module */
43384344
void *pClientData /* Client data for xCreate/xConnect */
43394345
);
4340
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
4346
+SQLITE_API int sqlite3_create_module_v2(
43414347
sqlite3 *db, /* SQLite connection to register module with */
43424348
const char *zName, /* Name of the module */
43434349
const sqlite3_module *p, /* Methods for the module */
43444350
void *pClientData, /* Client data for xCreate/xConnect */
43454351
void(*xDestroy)(void*) /* Module destructor function */
@@ -4346,11 +4352,10 @@
43464352
);
43474353
43484354
/*
43494355
** CAPI3REF: Virtual Table Instance Object
43504356
** KEYWORDS: sqlite3_vtab
4351
-** EXPERIMENTAL
43524357
**
43534358
** Every [virtual table module] implementation uses a subclass
43544359
** of this object to describe a particular instance
43554360
** of the [virtual table]. Each subclass will
43564361
** be tailored to the specific needs of the module implementation.
@@ -4372,11 +4377,10 @@
43724377
};
43734378
43744379
/*
43754380
** CAPI3REF: Virtual Table Cursor Object
43764381
** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
4377
-** EXPERIMENTAL
43784382
**
43794383
** Every [virtual table module] implementation uses a subclass of the
43804384
** following structure to describe cursors that point into the
43814385
** [virtual table] and are used
43824386
** to loop through the virtual table. Cursors are created using the
@@ -4394,22 +4398,20 @@
43944398
/* Virtual table implementations will typically add additional fields */
43954399
};
43964400
43974401
/*
43984402
** CAPI3REF: Declare The Schema Of A Virtual Table
4399
-** EXPERIMENTAL
44004403
**
44014404
** ^The [xCreate] and [xConnect] methods of a
44024405
** [virtual table module] call this interface
44034406
** to declare the format (the names and datatypes of the columns) of
44044407
** the virtual tables they implement.
44054408
*/
4406
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4409
+SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
44074410
44084411
/*
44094412
** CAPI3REF: Overload A Function For A Virtual Table
4410
-** EXPERIMENTAL
44114413
**
44124414
** ^(Virtual tables can provide alternative implementations of functions
44134415
** using the [xFindFunction] method of the [virtual table module].
44144416
** But global versions of those functions
44154417
** must exist in order to be overloaded.)^
@@ -4420,22 +4422,20 @@
44204422
** of the new function always causes an exception to be thrown. So
44214423
** the new function is not good for anything by itself. Its only
44224424
** purpose is to be a placeholder function that can be overloaded
44234425
** by a [virtual table].
44244426
*/
4425
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4427
+SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
44264428
44274429
/*
44284430
** The interface to the virtual-table mechanism defined above (back up
44294431
** to a comment remarkably similar to this one) is currently considered
44304432
** to be experimental. The interface might change in incompatible ways.
44314433
** If this is a problem for you, do not use the interface at this time.
44324434
**
44334435
** When the virtual-table mechanism stabilizes, we will declare the
44344436
** interface fixed, support it indefinitely, and remove this comment.
4435
-**
4436
-****** EXPERIMENTAL - subject to change without notice **************
44374437
*/
44384438
44394439
/*
44404440
** CAPI3REF: A Handle To An Open BLOB
44414441
** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -4774,11 +4774,10 @@
47744774
SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
47754775
SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
47764776
47774777
/*
47784778
** CAPI3REF: Mutex Methods Object
4779
-** EXPERIMENTAL
47804779
**
47814780
** An instance of this structure defines the low-level routines
47824781
** used to allocate and use mutexes.
47834782
**
47844783
** Usually, the default mutex implementations provided by SQLite are
@@ -4991,11 +4990,10 @@
49914990
#define SQLITE_TESTCTRL_ISKEYWORD 16
49924991
#define SQLITE_TESTCTRL_LAST 16
49934992
49944993
/*
49954994
** CAPI3REF: SQLite Runtime Status
4996
-** EXPERIMENTAL
49974995
**
49984996
** ^This interface is used to retrieve runtime status information
49994997
** about the preformance of SQLite, and optionally to reset various
50004998
** highwater marks. ^The first argument is an integer code for
50014999
** the specific parameter to measure. ^(Recognized integer codes
@@ -5019,16 +5017,15 @@
50195017
** and it is possible that another thread might change the parameter
50205018
** in between the times when *pCurrent and *pHighwater are written.
50215019
**
50225020
** See also: [sqlite3_db_status()]
50235021
*/
5024
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5022
+SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
50255023
50265024
50275025
/*
50285026
** CAPI3REF: Status Parameters
5029
-** EXPERIMENTAL
50305027
**
50315028
** These integer constants designate various run-time status parameters
50325029
** that can be returned by [sqlite3_status()].
50335030
**
50345031
** <dl>
@@ -5111,31 +5108,31 @@
51115108
#define SQLITE_STATUS_PAGECACHE_SIZE 7
51125109
#define SQLITE_STATUS_SCRATCH_SIZE 8
51135110
51145111
/*
51155112
** CAPI3REF: Database Connection Status
5116
-** EXPERIMENTAL
51175113
**
51185114
** ^This interface is used to retrieve runtime status information
51195115
** about a single [database connection]. ^The first argument is the
51205116
** database connection object to be interrogated. ^The second argument
5121
-** is the parameter to interrogate. ^Currently, the only allowed value
5122
-** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
5123
-** Additional options will likely appear in future releases of SQLite.
5117
+** is an integer constant, taken from the set of
5118
+** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5119
+** determiness the parameter to interrogate. The set of
5120
+** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5121
+** to grow in future releases of SQLite.
51245122
**
51255123
** ^The current value of the requested parameter is written into *pCur
51265124
** and the highest instantaneous value is written into *pHiwtr. ^If
51275125
** the resetFlg is true, then the highest instantaneous value is
51285126
** reset back down to the current value.
51295127
**
51305128
** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
51315129
*/
5132
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5130
+SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
51335131
51345132
/*
51355133
** CAPI3REF: Status Parameters for database connections
5136
-** EXPERIMENTAL
51375134
**
51385135
** These constants are the available integer "verbs" that can be passed as
51395136
** the second argument to the [sqlite3_db_status()] interface.
51405137
**
51415138
** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5146,18 +5143,25 @@
51465143
**
51475144
** <dl>
51485145
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
51495146
** <dd>This parameter returns the number of lookaside memory slots currently
51505147
** checked out.</dd>)^
5148
+**
5149
+** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5150
+** <dd>^This parameter returns the approximate number of of bytes of heap
5151
+** memory used by all pager caches associated with the database connection.
5152
+** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5153
+** checked out.</dd>)^
51515154
** </dl>
51525155
*/
51535156
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5157
+#define SQLITE_DBSTATUS_CACHE_USED 1
5158
+#define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
51545159
51555160
51565161
/*
51575162
** CAPI3REF: Prepared Statement Status
5158
-** EXPERIMENTAL
51595163
**
51605164
** ^(Each prepared statement maintains various
51615165
** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
51625166
** of times it has performed specific operations.)^ These counters can
51635167
** be used to monitor the performance characteristics of the prepared
@@ -5175,15 +5179,14 @@
51755179
** ^If the resetFlg is true, then the counter is reset to zero after this
51765180
** interface call returns.
51775181
**
51785182
** See also: [sqlite3_status()] and [sqlite3_db_status()].
51795183
*/
5180
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5184
+SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
51815185
51825186
/*
51835187
** CAPI3REF: Status Parameters for prepared statements
5184
-** EXPERIMENTAL
51855188
**
51865189
** These preprocessor macros define integer codes that name counter
51875190
** values associated with the [sqlite3_stmt_status()] interface.
51885191
** The meanings of the various counters are as follows:
51895192
**
@@ -5197,18 +5200,25 @@
51975200
** <dt>SQLITE_STMTSTATUS_SORT</dt>
51985201
** <dd>^This is the number of sort operations that have occurred.
51995202
** A non-zero value in this counter may indicate an opportunity to
52005203
** improvement performance through careful use of indices.</dd>
52015204
**
5205
+** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5206
+** <dd>^This is the number of rows inserted into transient indices that
5207
+** were created automatically in order to help joins run faster.
5208
+** A non-zero value in this counter may indicate an opportunity to
5209
+** improvement performance by adding permanent indices that do not
5210
+** need to be reinitialized each time the statement is run.</dd>
5211
+**
52025212
** </dl>
52035213
*/
52045214
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
52055215
#define SQLITE_STMTSTATUS_SORT 2
5216
+#define SQLITE_STMTSTATUS_AUTOINDEX 3
52065217
52075218
/*
52085219
** CAPI3REF: Custom Page Cache Object
5209
-** EXPERIMENTAL
52105220
**
52115221
** The sqlite3_pcache type is opaque. It is implemented by
52125222
** the pluggable module. The SQLite core has no knowledge of
52135223
** its size or internal structure and never deals with the
52145224
** sqlite3_pcache object except by holding and passing pointers
@@ -5219,11 +5229,10 @@
52195229
typedef struct sqlite3_pcache sqlite3_pcache;
52205230
52215231
/*
52225232
** CAPI3REF: Application Defined Page Cache.
52235233
** KEYWORDS: {page cache}
5224
-** EXPERIMENTAL
52255234
**
52265235
** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
52275236
** register an alternative page cache implementation by passing in an
52285237
** instance of the sqlite3_pcache_methods structure.)^ The majority of the
52295238
** heap memory used by SQLite is used by the page cache to cache data read
@@ -5361,11 +5370,10 @@
53615370
void (*xDestroy)(sqlite3_pcache*);
53625371
};
53635372
53645373
/*
53655374
** CAPI3REF: Online Backup Object
5366
-** EXPERIMENTAL
53675375
**
53685376
** The sqlite3_backup object records state information about an ongoing
53695377
** online backup operation. ^The sqlite3_backup object is created by
53705378
** a call to [sqlite3_backup_init()] and is destroyed by a call to
53715379
** [sqlite3_backup_finish()].
@@ -5374,11 +5382,10 @@
53745382
*/
53755383
typedef struct sqlite3_backup sqlite3_backup;
53765384
53775385
/*
53785386
** CAPI3REF: Online Backup API.
5379
-** EXPERIMENTAL
53805387
**
53815388
** The backup API copies the content of one database into another.
53825389
** It is useful either for creating backups of databases or
53835390
** for copying in-memory databases to or from persistent files.
53845391
**
@@ -5562,11 +5569,10 @@
55625569
SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
55635570
SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
55645571
55655572
/*
55665573
** CAPI3REF: Unlock Notification
5567
-** EXPERIMENTAL
55685574
**
55695575
** ^When running in shared-cache mode, a database operation may fail with
55705576
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
55715577
** individual tables within the shared-cache cannot be obtained. See
55725578
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -5684,11 +5690,10 @@
56845690
);
56855691
56865692
56875693
/*
56885694
** CAPI3REF: String Comparison
5689
-** EXPERIMENTAL
56905695
**
56915696
** ^The [sqlite3_strnicmp()] API allows applications and extensions to
56925697
** compare the contents of two buffers containing UTF-8 strings in a
56935698
** case-indendent fashion, using the same definition of case independence
56945699
** that SQLite uses internally when comparing identifiers.
@@ -5695,16 +5700,15 @@
56955700
*/
56965701
SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
56975702
56985703
/*
56995704
** CAPI3REF: Error Logging Interface
5700
-** EXPERIMENTAL
57015705
**
57025706
** ^The [sqlite3_log()] interface writes a message into the error log
57035707
** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
57045708
** ^If logging is enabled, the zFormat string and subsequent arguments are
5705
-** passed through to [sqlite3_vmprintf()] to generate the final output string.
5709
+** used with [sqlite3_snprintf()] to generate the final output string.
57065710
**
57075711
** The sqlite3_log() interface is intended for use by extensions such as
57085712
** virtual tables, collating functions, and SQL functions. While there is
57095713
** nothing to prevent an application from calling sqlite3_log(), doing so
57105714
** is considered bad form.
57115715
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.6.23.1"
111 #define SQLITE_VERSION_NUMBER 3006023
112 #define SQLITE_SOURCE_ID "2010-03-26 22:28:06 b078b588d617e07886ad156e9f54ade6d823568e"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -144,11 +144,10 @@
144 SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
145 SQLITE_API const char *sqlite3_libversion(void);
146 SQLITE_API const char *sqlite3_sourceid(void);
147 SQLITE_API int sqlite3_libversion_number(void);
148
149 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
150 /*
151 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
152 **
153 ** ^The sqlite3_compileoption_used() function returns 0 or 1
154 ** indicating whether the specified option was defined at
@@ -167,13 +166,14 @@
167 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
168 **
169 ** See also: SQL functions [sqlite_compileoption_used()] and
170 ** [sqlite_compileoption_get()] and the [compile_options pragma].
171 */
 
172 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
173 SQLITE_API const char *sqlite3_compileoption_get(int N);
174 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
175
176 /*
177 ** CAPI3REF: Test To See If The Library Is Threadsafe
178 **
179 ** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -971,15 +971,14 @@
971 **
972 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
973 ** ^If the option is unknown or SQLite is unable to set the option
974 ** then this routine returns a non-zero [error code].
975 */
976 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
977
978 /*
979 ** CAPI3REF: Configure database connections
980 ** EXPERIMENTAL
981 **
982 ** The sqlite3_db_config() interface is used to make configuration
983 ** changes to a [database connection]. The interface is similar to
984 ** [sqlite3_config()] except that the changes apply to a single
985 ** [database connection] (specified in the first argument). The
@@ -995,15 +994,14 @@
995 ** Additional arguments depend on the verb.
996 **
997 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
998 ** the call is considered successful.
999 */
1000 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
1001
1002 /*
1003 ** CAPI3REF: Memory Allocation Routines
1004 ** EXPERIMENTAL
1005 **
1006 ** An instance of this object defines the interface between SQLite
1007 ** and low-level memory allocation routines.
1008 **
1009 ** This object is used in only one place in the SQLite interface.
@@ -1081,11 +1079,10 @@
1081 void *pAppData; /* Argument to xInit() and xShutdown() */
1082 };
1083
1084 /*
1085 ** CAPI3REF: Configuration Options
1086 ** EXPERIMENTAL
1087 **
1088 ** These constants are the available integer configuration options that
1089 ** can be passed as the first argument to the [sqlite3_config()] interface.
1090 **
1091 ** New configuration options may be added in future releases of SQLite.
@@ -1267,10 +1264,28 @@
1267 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1268 ** <dd> ^(This option takes a single argument which is a pointer to an
1269 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1270 ** page cache implementation into that object.)^ </dd>
1271 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1272 ** </dl>
1273 */
1274 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1275 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1276 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1287,12 +1302,11 @@
1287 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1288 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1289 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1290
1291 /*
1292 ** CAPI3REF: Configuration Options
1293 ** EXPERIMENTAL
1294 **
1295 ** These constants are the available integer configuration options that
1296 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
1297 **
1298 ** New configuration options may be added in future releases of SQLite.
@@ -2064,11 +2078,10 @@
2064 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2065 #define SQLITE_COPY 0 /* No longer used */
2066
2067 /*
2068 ** CAPI3REF: Tracing And Profiling Functions
2069 ** EXPERIMENTAL
2070 **
2071 ** These routines register callback functions that can be used for
2072 ** tracing and profiling the execution of SQL statements.
2073 **
2074 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2082,11 +2095,11 @@
2082 ** ^The callback function registered by sqlite3_profile() is invoked
2083 ** as each SQL statement finishes. ^The profile callback contains
2084 ** the original statement text and an estimate of wall-clock time
2085 ** of how long that statement took to run.
2086 */
2087 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2088 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2089 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2090
2091 /*
2092 ** CAPI3REF: Query Progress Callbacks
@@ -3687,11 +3700,11 @@
3687 sqlite3*,
3688 void*,
3689 void(*)(void*,sqlite3*,int eTextRep,const void*)
3690 );
3691
3692 #if SQLITE_HAS_CODEC
3693 /*
3694 ** Specify the key for an encrypted database. This routine should be
3695 ** called right after sqlite3_open().
3696 **
3697 ** The code to implement this API is not available in the public release
@@ -3870,12 +3883,10 @@
3870 ** ^For the purposes of this API, a transaction is said to have been
3871 ** rolled back if an explicit "ROLLBACK" statement is executed, or
3872 ** an error or constraint causes an implicit rollback to occur.
3873 ** ^The rollback callback is not invoked if a transaction is
3874 ** automatically rolled back because the database connection is closed.
3875 ** ^The rollback callback is not invoked if a transaction is
3876 ** rolled back because a commit callback returned non-zero.
3877 **
3878 ** See also the [sqlite3_update_hook()] interface.
3879 */
3880 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
3881 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
@@ -4157,12 +4168,10 @@
4157 ** ^This function disables automatic extensions in all threads.
4158 */
4159 SQLITE_API void sqlite3_reset_auto_extension(void);
4160
4161 /*
4162 ****** EXPERIMENTAL - subject to change without notice **************
4163 **
4164 ** The interface to the virtual-table mechanism is currently considered
4165 ** to be experimental. The interface might change in incompatible ways.
4166 ** If this is a problem for you, do not use the interface at this time.
4167 **
4168 ** When the virtual-table mechanism stabilizes, we will declare the
@@ -4178,11 +4187,10 @@
4178 typedef struct sqlite3_module sqlite3_module;
4179
4180 /*
4181 ** CAPI3REF: Virtual Table Object
4182 ** KEYWORDS: sqlite3_module {virtual table module}
4183 ** EXPERIMENTAL
4184 **
4185 ** This structure, sometimes called a a "virtual table module",
4186 ** defines the implementation of a [virtual tables].
4187 ** This structure consists mostly of methods for the module.
4188 **
@@ -4225,11 +4233,10 @@
4225 };
4226
4227 /*
4228 ** CAPI3REF: Virtual Table Indexing Information
4229 ** KEYWORDS: sqlite3_index_info
4230 ** EXPERIMENTAL
4231 **
4232 ** The sqlite3_index_info structure and its substructures is used to
4233 ** pass information into and receive the reply from the [xBestIndex]
4234 ** method of a [virtual table module]. The fields under **Inputs** are the
4235 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4307,11 +4314,10 @@
4307 #define SQLITE_INDEX_CONSTRAINT_GE 32
4308 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
4309
4310 /*
4311 ** CAPI3REF: Register A Virtual Table Implementation
4312 ** EXPERIMENTAL
4313 **
4314 ** ^These routines are used to register a new [virtual table module] name.
4315 ** ^Module names must be registered before
4316 ** creating a new [virtual table] using the module and before using a
4317 ** preexisting [virtual table] for the module.
@@ -4329,17 +4335,17 @@
4329 ** invoke the destructor function (if it is not NULL) when SQLite
4330 ** no longer needs the pClientData pointer. ^The sqlite3_create_module()
4331 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
4332 ** destructor.
4333 */
4334 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
4335 sqlite3 *db, /* SQLite connection to register module with */
4336 const char *zName, /* Name of the module */
4337 const sqlite3_module *p, /* Methods for the module */
4338 void *pClientData /* Client data for xCreate/xConnect */
4339 );
4340 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
4341 sqlite3 *db, /* SQLite connection to register module with */
4342 const char *zName, /* Name of the module */
4343 const sqlite3_module *p, /* Methods for the module */
4344 void *pClientData, /* Client data for xCreate/xConnect */
4345 void(*xDestroy)(void*) /* Module destructor function */
@@ -4346,11 +4352,10 @@
4346 );
4347
4348 /*
4349 ** CAPI3REF: Virtual Table Instance Object
4350 ** KEYWORDS: sqlite3_vtab
4351 ** EXPERIMENTAL
4352 **
4353 ** Every [virtual table module] implementation uses a subclass
4354 ** of this object to describe a particular instance
4355 ** of the [virtual table]. Each subclass will
4356 ** be tailored to the specific needs of the module implementation.
@@ -4372,11 +4377,10 @@
4372 };
4373
4374 /*
4375 ** CAPI3REF: Virtual Table Cursor Object
4376 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
4377 ** EXPERIMENTAL
4378 **
4379 ** Every [virtual table module] implementation uses a subclass of the
4380 ** following structure to describe cursors that point into the
4381 ** [virtual table] and are used
4382 ** to loop through the virtual table. Cursors are created using the
@@ -4394,22 +4398,20 @@
4394 /* Virtual table implementations will typically add additional fields */
4395 };
4396
4397 /*
4398 ** CAPI3REF: Declare The Schema Of A Virtual Table
4399 ** EXPERIMENTAL
4400 **
4401 ** ^The [xCreate] and [xConnect] methods of a
4402 ** [virtual table module] call this interface
4403 ** to declare the format (the names and datatypes of the columns) of
4404 ** the virtual tables they implement.
4405 */
4406 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4407
4408 /*
4409 ** CAPI3REF: Overload A Function For A Virtual Table
4410 ** EXPERIMENTAL
4411 **
4412 ** ^(Virtual tables can provide alternative implementations of functions
4413 ** using the [xFindFunction] method of the [virtual table module].
4414 ** But global versions of those functions
4415 ** must exist in order to be overloaded.)^
@@ -4420,22 +4422,20 @@
4420 ** of the new function always causes an exception to be thrown. So
4421 ** the new function is not good for anything by itself. Its only
4422 ** purpose is to be a placeholder function that can be overloaded
4423 ** by a [virtual table].
4424 */
4425 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4426
4427 /*
4428 ** The interface to the virtual-table mechanism defined above (back up
4429 ** to a comment remarkably similar to this one) is currently considered
4430 ** to be experimental. The interface might change in incompatible ways.
4431 ** If this is a problem for you, do not use the interface at this time.
4432 **
4433 ** When the virtual-table mechanism stabilizes, we will declare the
4434 ** interface fixed, support it indefinitely, and remove this comment.
4435 **
4436 ****** EXPERIMENTAL - subject to change without notice **************
4437 */
4438
4439 /*
4440 ** CAPI3REF: A Handle To An Open BLOB
4441 ** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -4774,11 +4774,10 @@
4774 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
4775 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
4776
4777 /*
4778 ** CAPI3REF: Mutex Methods Object
4779 ** EXPERIMENTAL
4780 **
4781 ** An instance of this structure defines the low-level routines
4782 ** used to allocate and use mutexes.
4783 **
4784 ** Usually, the default mutex implementations provided by SQLite are
@@ -4991,11 +4990,10 @@
4991 #define SQLITE_TESTCTRL_ISKEYWORD 16
4992 #define SQLITE_TESTCTRL_LAST 16
4993
4994 /*
4995 ** CAPI3REF: SQLite Runtime Status
4996 ** EXPERIMENTAL
4997 **
4998 ** ^This interface is used to retrieve runtime status information
4999 ** about the preformance of SQLite, and optionally to reset various
5000 ** highwater marks. ^The first argument is an integer code for
5001 ** the specific parameter to measure. ^(Recognized integer codes
@@ -5019,16 +5017,15 @@
5019 ** and it is possible that another thread might change the parameter
5020 ** in between the times when *pCurrent and *pHighwater are written.
5021 **
5022 ** See also: [sqlite3_db_status()]
5023 */
5024 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5025
5026
5027 /*
5028 ** CAPI3REF: Status Parameters
5029 ** EXPERIMENTAL
5030 **
5031 ** These integer constants designate various run-time status parameters
5032 ** that can be returned by [sqlite3_status()].
5033 **
5034 ** <dl>
@@ -5111,31 +5108,31 @@
5111 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5112 #define SQLITE_STATUS_SCRATCH_SIZE 8
5113
5114 /*
5115 ** CAPI3REF: Database Connection Status
5116 ** EXPERIMENTAL
5117 **
5118 ** ^This interface is used to retrieve runtime status information
5119 ** about a single [database connection]. ^The first argument is the
5120 ** database connection object to be interrogated. ^The second argument
5121 ** is the parameter to interrogate. ^Currently, the only allowed value
5122 ** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
5123 ** Additional options will likely appear in future releases of SQLite.
 
 
5124 **
5125 ** ^The current value of the requested parameter is written into *pCur
5126 ** and the highest instantaneous value is written into *pHiwtr. ^If
5127 ** the resetFlg is true, then the highest instantaneous value is
5128 ** reset back down to the current value.
5129 **
5130 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5131 */
5132 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5133
5134 /*
5135 ** CAPI3REF: Status Parameters for database connections
5136 ** EXPERIMENTAL
5137 **
5138 ** These constants are the available integer "verbs" that can be passed as
5139 ** the second argument to the [sqlite3_db_status()] interface.
5140 **
5141 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5146,18 +5143,25 @@
5146 **
5147 ** <dl>
5148 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5149 ** <dd>This parameter returns the number of lookaside memory slots currently
5150 ** checked out.</dd>)^
 
 
 
 
 
 
5151 ** </dl>
5152 */
5153 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
 
 
5154
5155
5156 /*
5157 ** CAPI3REF: Prepared Statement Status
5158 ** EXPERIMENTAL
5159 **
5160 ** ^(Each prepared statement maintains various
5161 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5162 ** of times it has performed specific operations.)^ These counters can
5163 ** be used to monitor the performance characteristics of the prepared
@@ -5175,15 +5179,14 @@
5175 ** ^If the resetFlg is true, then the counter is reset to zero after this
5176 ** interface call returns.
5177 **
5178 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
5179 */
5180 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5181
5182 /*
5183 ** CAPI3REF: Status Parameters for prepared statements
5184 ** EXPERIMENTAL
5185 **
5186 ** These preprocessor macros define integer codes that name counter
5187 ** values associated with the [sqlite3_stmt_status()] interface.
5188 ** The meanings of the various counters are as follows:
5189 **
@@ -5197,18 +5200,25 @@
5197 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
5198 ** <dd>^This is the number of sort operations that have occurred.
5199 ** A non-zero value in this counter may indicate an opportunity to
5200 ** improvement performance through careful use of indices.</dd>
5201 **
 
 
 
 
 
 
 
5202 ** </dl>
5203 */
5204 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5205 #define SQLITE_STMTSTATUS_SORT 2
 
5206
5207 /*
5208 ** CAPI3REF: Custom Page Cache Object
5209 ** EXPERIMENTAL
5210 **
5211 ** The sqlite3_pcache type is opaque. It is implemented by
5212 ** the pluggable module. The SQLite core has no knowledge of
5213 ** its size or internal structure and never deals with the
5214 ** sqlite3_pcache object except by holding and passing pointers
@@ -5219,11 +5229,10 @@
5219 typedef struct sqlite3_pcache sqlite3_pcache;
5220
5221 /*
5222 ** CAPI3REF: Application Defined Page Cache.
5223 ** KEYWORDS: {page cache}
5224 ** EXPERIMENTAL
5225 **
5226 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5227 ** register an alternative page cache implementation by passing in an
5228 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5229 ** heap memory used by SQLite is used by the page cache to cache data read
@@ -5361,11 +5370,10 @@
5361 void (*xDestroy)(sqlite3_pcache*);
5362 };
5363
5364 /*
5365 ** CAPI3REF: Online Backup Object
5366 ** EXPERIMENTAL
5367 **
5368 ** The sqlite3_backup object records state information about an ongoing
5369 ** online backup operation. ^The sqlite3_backup object is created by
5370 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
5371 ** [sqlite3_backup_finish()].
@@ -5374,11 +5382,10 @@
5374 */
5375 typedef struct sqlite3_backup sqlite3_backup;
5376
5377 /*
5378 ** CAPI3REF: Online Backup API.
5379 ** EXPERIMENTAL
5380 **
5381 ** The backup API copies the content of one database into another.
5382 ** It is useful either for creating backups of databases or
5383 ** for copying in-memory databases to or from persistent files.
5384 **
@@ -5562,11 +5569,10 @@
5562 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
5563 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
5564
5565 /*
5566 ** CAPI3REF: Unlock Notification
5567 ** EXPERIMENTAL
5568 **
5569 ** ^When running in shared-cache mode, a database operation may fail with
5570 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
5571 ** individual tables within the shared-cache cannot be obtained. See
5572 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -5684,11 +5690,10 @@
5684 );
5685
5686
5687 /*
5688 ** CAPI3REF: String Comparison
5689 ** EXPERIMENTAL
5690 **
5691 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
5692 ** compare the contents of two buffers containing UTF-8 strings in a
5693 ** case-indendent fashion, using the same definition of case independence
5694 ** that SQLite uses internally when comparing identifiers.
@@ -5695,16 +5700,15 @@
5695 */
5696 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
5697
5698 /*
5699 ** CAPI3REF: Error Logging Interface
5700 ** EXPERIMENTAL
5701 **
5702 ** ^The [sqlite3_log()] interface writes a message into the error log
5703 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
5704 ** ^If logging is enabled, the zFormat string and subsequent arguments are
5705 ** passed through to [sqlite3_vmprintf()] to generate the final output string.
5706 **
5707 ** The sqlite3_log() interface is intended for use by extensions such as
5708 ** virtual tables, collating functions, and SQL functions. While there is
5709 ** nothing to prevent an application from calling sqlite3_log(), doing so
5710 ** is considered bad form.
5711
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.6.23"
111 #define SQLITE_VERSION_NUMBER 3006023
112 #define SQLITE_SOURCE_ID "2010-04-15 23:24:29 f96782b389b5b97b488dc5814f7082e0393f64cd"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -144,11 +144,10 @@
144 SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
145 SQLITE_API const char *sqlite3_libversion(void);
146 SQLITE_API const char *sqlite3_sourceid(void);
147 SQLITE_API int sqlite3_libversion_number(void);
148
 
149 /*
150 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
151 **
152 ** ^The sqlite3_compileoption_used() function returns 0 or 1
153 ** indicating whether the specified option was defined at
@@ -167,13 +166,14 @@
166 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
167 **
168 ** See also: SQL functions [sqlite_compileoption_used()] and
169 ** [sqlite_compileoption_get()] and the [compile_options pragma].
170 */
171 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
172 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
173 SQLITE_API const char *sqlite3_compileoption_get(int N);
174 #endif
175
176 /*
177 ** CAPI3REF: Test To See If The Library Is Threadsafe
178 **
179 ** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -971,15 +971,14 @@
971 **
972 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
973 ** ^If the option is unknown or SQLite is unable to set the option
974 ** then this routine returns a non-zero [error code].
975 */
976 SQLITE_API int sqlite3_config(int, ...);
977
978 /*
979 ** CAPI3REF: Configure database connections
 
980 **
981 ** The sqlite3_db_config() interface is used to make configuration
982 ** changes to a [database connection]. The interface is similar to
983 ** [sqlite3_config()] except that the changes apply to a single
984 ** [database connection] (specified in the first argument). The
@@ -995,15 +994,14 @@
994 ** Additional arguments depend on the verb.
995 **
996 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
997 ** the call is considered successful.
998 */
999 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
1000
1001 /*
1002 ** CAPI3REF: Memory Allocation Routines
 
1003 **
1004 ** An instance of this object defines the interface between SQLite
1005 ** and low-level memory allocation routines.
1006 **
1007 ** This object is used in only one place in the SQLite interface.
@@ -1081,11 +1079,10 @@
1079 void *pAppData; /* Argument to xInit() and xShutdown() */
1080 };
1081
1082 /*
1083 ** CAPI3REF: Configuration Options
 
1084 **
1085 ** These constants are the available integer configuration options that
1086 ** can be passed as the first argument to the [sqlite3_config()] interface.
1087 **
1088 ** New configuration options may be added in future releases of SQLite.
@@ -1267,10 +1264,28 @@
1264 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1265 ** <dd> ^(This option takes a single argument which is a pointer to an
1266 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1267 ** page cache implementation into that object.)^ </dd>
1268 **
1269 ** <dt>SQLITE_CONFIG_LOG</dt>
1270 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1271 ** function with a call signature of void(*)(void*,int,const char*),
1272 ** and a pointer to void. ^If the function pointer is not NULL, it is
1273 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1274 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1275 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1276 ** passed through as the first parameter to the application-defined logger
1277 ** function whenever that function is invoked. ^The second parameter to
1278 ** the logger function is a copy of the first parameter to the corresponding
1279 ** [sqlite3_log()] call and is intended to be a [result code] or an
1280 ** [extended result code]. ^The third parameter passed to the logger is
1281 ** log message after formatting via [sqlite3_snprintf()].
1282 ** The SQLite logging interface is not reentrant; the logger function
1283 ** supplied by the application must not invoke any SQLite interface.
1284 ** In a multi-threaded application, the application-defined logger
1285 ** function must be threadsafe. </dd>
1286 **
1287 ** </dl>
1288 */
1289 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1290 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1291 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1287,12 +1302,11 @@
1302 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1303 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1304 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1305
1306 /*
1307 ** CAPI3REF: Database Connection Configuration Options
 
1308 **
1309 ** These constants are the available integer configuration options that
1310 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
1311 **
1312 ** New configuration options may be added in future releases of SQLite.
@@ -2064,11 +2078,10 @@
2078 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2079 #define SQLITE_COPY 0 /* No longer used */
2080
2081 /*
2082 ** CAPI3REF: Tracing And Profiling Functions
 
2083 **
2084 ** These routines register callback functions that can be used for
2085 ** tracing and profiling the execution of SQL statements.
2086 **
2087 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2082,11 +2095,11 @@
2095 ** ^The callback function registered by sqlite3_profile() is invoked
2096 ** as each SQL statement finishes. ^The profile callback contains
2097 ** the original statement text and an estimate of wall-clock time
2098 ** of how long that statement took to run.
2099 */
2100 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2101 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2102 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2103
2104 /*
2105 ** CAPI3REF: Query Progress Callbacks
@@ -3687,11 +3700,11 @@
3700 sqlite3*,
3701 void*,
3702 void(*)(void*,sqlite3*,int eTextRep,const void*)
3703 );
3704
3705 #ifdef SQLITE_HAS_CODEC
3706 /*
3707 ** Specify the key for an encrypted database. This routine should be
3708 ** called right after sqlite3_open().
3709 **
3710 ** The code to implement this API is not available in the public release
@@ -3870,12 +3883,10 @@
3883 ** ^For the purposes of this API, a transaction is said to have been
3884 ** rolled back if an explicit "ROLLBACK" statement is executed, or
3885 ** an error or constraint causes an implicit rollback to occur.
3886 ** ^The rollback callback is not invoked if a transaction is
3887 ** automatically rolled back because the database connection is closed.
 
 
3888 **
3889 ** See also the [sqlite3_update_hook()] interface.
3890 */
3891 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
3892 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
@@ -4157,12 +4168,10 @@
4168 ** ^This function disables automatic extensions in all threads.
4169 */
4170 SQLITE_API void sqlite3_reset_auto_extension(void);
4171
4172 /*
 
 
4173 ** The interface to the virtual-table mechanism is currently considered
4174 ** to be experimental. The interface might change in incompatible ways.
4175 ** If this is a problem for you, do not use the interface at this time.
4176 **
4177 ** When the virtual-table mechanism stabilizes, we will declare the
@@ -4178,11 +4187,10 @@
4187 typedef struct sqlite3_module sqlite3_module;
4188
4189 /*
4190 ** CAPI3REF: Virtual Table Object
4191 ** KEYWORDS: sqlite3_module {virtual table module}
 
4192 **
4193 ** This structure, sometimes called a a "virtual table module",
4194 ** defines the implementation of a [virtual tables].
4195 ** This structure consists mostly of methods for the module.
4196 **
@@ -4225,11 +4233,10 @@
4233 };
4234
4235 /*
4236 ** CAPI3REF: Virtual Table Indexing Information
4237 ** KEYWORDS: sqlite3_index_info
 
4238 **
4239 ** The sqlite3_index_info structure and its substructures is used to
4240 ** pass information into and receive the reply from the [xBestIndex]
4241 ** method of a [virtual table module]. The fields under **Inputs** are the
4242 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4307,11 +4314,10 @@
4314 #define SQLITE_INDEX_CONSTRAINT_GE 32
4315 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
4316
4317 /*
4318 ** CAPI3REF: Register A Virtual Table Implementation
 
4319 **
4320 ** ^These routines are used to register a new [virtual table module] name.
4321 ** ^Module names must be registered before
4322 ** creating a new [virtual table] using the module and before using a
4323 ** preexisting [virtual table] for the module.
@@ -4329,17 +4335,17 @@
4335 ** invoke the destructor function (if it is not NULL) when SQLite
4336 ** no longer needs the pClientData pointer. ^The sqlite3_create_module()
4337 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
4338 ** destructor.
4339 */
4340 SQLITE_API int sqlite3_create_module(
4341 sqlite3 *db, /* SQLite connection to register module with */
4342 const char *zName, /* Name of the module */
4343 const sqlite3_module *p, /* Methods for the module */
4344 void *pClientData /* Client data for xCreate/xConnect */
4345 );
4346 SQLITE_API int sqlite3_create_module_v2(
4347 sqlite3 *db, /* SQLite connection to register module with */
4348 const char *zName, /* Name of the module */
4349 const sqlite3_module *p, /* Methods for the module */
4350 void *pClientData, /* Client data for xCreate/xConnect */
4351 void(*xDestroy)(void*) /* Module destructor function */
@@ -4346,11 +4352,10 @@
4352 );
4353
4354 /*
4355 ** CAPI3REF: Virtual Table Instance Object
4356 ** KEYWORDS: sqlite3_vtab
 
4357 **
4358 ** Every [virtual table module] implementation uses a subclass
4359 ** of this object to describe a particular instance
4360 ** of the [virtual table]. Each subclass will
4361 ** be tailored to the specific needs of the module implementation.
@@ -4372,11 +4377,10 @@
4377 };
4378
4379 /*
4380 ** CAPI3REF: Virtual Table Cursor Object
4381 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
 
4382 **
4383 ** Every [virtual table module] implementation uses a subclass of the
4384 ** following structure to describe cursors that point into the
4385 ** [virtual table] and are used
4386 ** to loop through the virtual table. Cursors are created using the
@@ -4394,22 +4398,20 @@
4398 /* Virtual table implementations will typically add additional fields */
4399 };
4400
4401 /*
4402 ** CAPI3REF: Declare The Schema Of A Virtual Table
 
4403 **
4404 ** ^The [xCreate] and [xConnect] methods of a
4405 ** [virtual table module] call this interface
4406 ** to declare the format (the names and datatypes of the columns) of
4407 ** the virtual tables they implement.
4408 */
4409 SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4410
4411 /*
4412 ** CAPI3REF: Overload A Function For A Virtual Table
 
4413 **
4414 ** ^(Virtual tables can provide alternative implementations of functions
4415 ** using the [xFindFunction] method of the [virtual table module].
4416 ** But global versions of those functions
4417 ** must exist in order to be overloaded.)^
@@ -4420,22 +4422,20 @@
4422 ** of the new function always causes an exception to be thrown. So
4423 ** the new function is not good for anything by itself. Its only
4424 ** purpose is to be a placeholder function that can be overloaded
4425 ** by a [virtual table].
4426 */
4427 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4428
4429 /*
4430 ** The interface to the virtual-table mechanism defined above (back up
4431 ** to a comment remarkably similar to this one) is currently considered
4432 ** to be experimental. The interface might change in incompatible ways.
4433 ** If this is a problem for you, do not use the interface at this time.
4434 **
4435 ** When the virtual-table mechanism stabilizes, we will declare the
4436 ** interface fixed, support it indefinitely, and remove this comment.
 
 
4437 */
4438
4439 /*
4440 ** CAPI3REF: A Handle To An Open BLOB
4441 ** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -4774,11 +4774,10 @@
4774 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
4775 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
4776
4777 /*
4778 ** CAPI3REF: Mutex Methods Object
 
4779 **
4780 ** An instance of this structure defines the low-level routines
4781 ** used to allocate and use mutexes.
4782 **
4783 ** Usually, the default mutex implementations provided by SQLite are
@@ -4991,11 +4990,10 @@
4990 #define SQLITE_TESTCTRL_ISKEYWORD 16
4991 #define SQLITE_TESTCTRL_LAST 16
4992
4993 /*
4994 ** CAPI3REF: SQLite Runtime Status
 
4995 **
4996 ** ^This interface is used to retrieve runtime status information
4997 ** about the preformance of SQLite, and optionally to reset various
4998 ** highwater marks. ^The first argument is an integer code for
4999 ** the specific parameter to measure. ^(Recognized integer codes
@@ -5019,16 +5017,15 @@
5017 ** and it is possible that another thread might change the parameter
5018 ** in between the times when *pCurrent and *pHighwater are written.
5019 **
5020 ** See also: [sqlite3_db_status()]
5021 */
5022 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5023
5024
5025 /*
5026 ** CAPI3REF: Status Parameters
 
5027 **
5028 ** These integer constants designate various run-time status parameters
5029 ** that can be returned by [sqlite3_status()].
5030 **
5031 ** <dl>
@@ -5111,31 +5108,31 @@
5108 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5109 #define SQLITE_STATUS_SCRATCH_SIZE 8
5110
5111 /*
5112 ** CAPI3REF: Database Connection Status
 
5113 **
5114 ** ^This interface is used to retrieve runtime status information
5115 ** about a single [database connection]. ^The first argument is the
5116 ** database connection object to be interrogated. ^The second argument
5117 ** is an integer constant, taken from the set of
5118 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5119 ** determiness the parameter to interrogate. The set of
5120 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5121 ** to grow in future releases of SQLite.
5122 **
5123 ** ^The current value of the requested parameter is written into *pCur
5124 ** and the highest instantaneous value is written into *pHiwtr. ^If
5125 ** the resetFlg is true, then the highest instantaneous value is
5126 ** reset back down to the current value.
5127 **
5128 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5129 */
5130 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5131
5132 /*
5133 ** CAPI3REF: Status Parameters for database connections
 
5134 **
5135 ** These constants are the available integer "verbs" that can be passed as
5136 ** the second argument to the [sqlite3_db_status()] interface.
5137 **
5138 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5146,18 +5143,25 @@
5143 **
5144 ** <dl>
5145 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5146 ** <dd>This parameter returns the number of lookaside memory slots currently
5147 ** checked out.</dd>)^
5148 **
5149 ** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5150 ** <dd>^This parameter returns the approximate number of of bytes of heap
5151 ** memory used by all pager caches associated with the database connection.
5152 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5153 ** checked out.</dd>)^
5154 ** </dl>
5155 */
5156 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5157 #define SQLITE_DBSTATUS_CACHE_USED 1
5158 #define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
5159
5160
5161 /*
5162 ** CAPI3REF: Prepared Statement Status
 
5163 **
5164 ** ^(Each prepared statement maintains various
5165 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5166 ** of times it has performed specific operations.)^ These counters can
5167 ** be used to monitor the performance characteristics of the prepared
@@ -5175,15 +5179,14 @@
5179 ** ^If the resetFlg is true, then the counter is reset to zero after this
5180 ** interface call returns.
5181 **
5182 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
5183 */
5184 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5185
5186 /*
5187 ** CAPI3REF: Status Parameters for prepared statements
 
5188 **
5189 ** These preprocessor macros define integer codes that name counter
5190 ** values associated with the [sqlite3_stmt_status()] interface.
5191 ** The meanings of the various counters are as follows:
5192 **
@@ -5197,18 +5200,25 @@
5200 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
5201 ** <dd>^This is the number of sort operations that have occurred.
5202 ** A non-zero value in this counter may indicate an opportunity to
5203 ** improvement performance through careful use of indices.</dd>
5204 **
5205 ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5206 ** <dd>^This is the number of rows inserted into transient indices that
5207 ** were created automatically in order to help joins run faster.
5208 ** A non-zero value in this counter may indicate an opportunity to
5209 ** improvement performance by adding permanent indices that do not
5210 ** need to be reinitialized each time the statement is run.</dd>
5211 **
5212 ** </dl>
5213 */
5214 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5215 #define SQLITE_STMTSTATUS_SORT 2
5216 #define SQLITE_STMTSTATUS_AUTOINDEX 3
5217
5218 /*
5219 ** CAPI3REF: Custom Page Cache Object
 
5220 **
5221 ** The sqlite3_pcache type is opaque. It is implemented by
5222 ** the pluggable module. The SQLite core has no knowledge of
5223 ** its size or internal structure and never deals with the
5224 ** sqlite3_pcache object except by holding and passing pointers
@@ -5219,11 +5229,10 @@
5229 typedef struct sqlite3_pcache sqlite3_pcache;
5230
5231 /*
5232 ** CAPI3REF: Application Defined Page Cache.
5233 ** KEYWORDS: {page cache}
 
5234 **
5235 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5236 ** register an alternative page cache implementation by passing in an
5237 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5238 ** heap memory used by SQLite is used by the page cache to cache data read
@@ -5361,11 +5370,10 @@
5370 void (*xDestroy)(sqlite3_pcache*);
5371 };
5372
5373 /*
5374 ** CAPI3REF: Online Backup Object
 
5375 **
5376 ** The sqlite3_backup object records state information about an ongoing
5377 ** online backup operation. ^The sqlite3_backup object is created by
5378 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
5379 ** [sqlite3_backup_finish()].
@@ -5374,11 +5382,10 @@
5382 */
5383 typedef struct sqlite3_backup sqlite3_backup;
5384
5385 /*
5386 ** CAPI3REF: Online Backup API.
 
5387 **
5388 ** The backup API copies the content of one database into another.
5389 ** It is useful either for creating backups of databases or
5390 ** for copying in-memory databases to or from persistent files.
5391 **
@@ -5562,11 +5569,10 @@
5569 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
5570 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
5571
5572 /*
5573 ** CAPI3REF: Unlock Notification
 
5574 **
5575 ** ^When running in shared-cache mode, a database operation may fail with
5576 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
5577 ** individual tables within the shared-cache cannot be obtained. See
5578 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -5684,11 +5690,10 @@
5690 );
5691
5692
5693 /*
5694 ** CAPI3REF: String Comparison
 
5695 **
5696 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
5697 ** compare the contents of two buffers containing UTF-8 strings in a
5698 ** case-indendent fashion, using the same definition of case independence
5699 ** that SQLite uses internally when comparing identifiers.
@@ -5695,16 +5700,15 @@
5700 */
5701 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
5702
5703 /*
5704 ** CAPI3REF: Error Logging Interface
 
5705 **
5706 ** ^The [sqlite3_log()] interface writes a message into the error log
5707 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
5708 ** ^If logging is enabled, the zFormat string and subsequent arguments are
5709 ** used with [sqlite3_snprintf()] to generate the final output string.
5710 **
5711 ** The sqlite3_log() interface is intended for use by extensions such as
5712 ** virtual tables, collating functions, and SQL functions. While there is
5713 ** nothing to prevent an application from calling sqlite3_log(), doing so
5714 ** is considered bad form.
5715
+1 -1
--- src/style.c
+++ src/style.c
@@ -110,11 +110,11 @@
110110
if( g.thTrace ) Th_Trace("BEGIN_HEADER_SCRIPT<br />\n", -1);
111111
Th_Render(zHeader);
112112
if( g.thTrace ) Th_Trace("END_HEADER<br />\n", -1);
113113
Th_Unstore("title"); /* Avoid collisions with ticket field names */
114114
cgi_destination(CGI_BODY);
115
- g.cgiPanic = 1;
115
+ g.cgiOutput = 1;
116116
headerHasBeenGenerated = 1;
117117
}
118118
119119
/*
120120
** Draw the footer at the bottom of the page.
121121
--- src/style.c
+++ src/style.c
@@ -110,11 +110,11 @@
110 if( g.thTrace ) Th_Trace("BEGIN_HEADER_SCRIPT<br />\n", -1);
111 Th_Render(zHeader);
112 if( g.thTrace ) Th_Trace("END_HEADER<br />\n", -1);
113 Th_Unstore("title"); /* Avoid collisions with ticket field names */
114 cgi_destination(CGI_BODY);
115 g.cgiPanic = 1;
116 headerHasBeenGenerated = 1;
117 }
118
119 /*
120 ** Draw the footer at the bottom of the page.
121
--- src/style.c
+++ src/style.c
@@ -110,11 +110,11 @@
110 if( g.thTrace ) Th_Trace("BEGIN_HEADER_SCRIPT<br />\n", -1);
111 Th_Render(zHeader);
112 if( g.thTrace ) Th_Trace("END_HEADER<br />\n", -1);
113 Th_Unstore("title"); /* Avoid collisions with ticket field names */
114 cgi_destination(CGI_BODY);
115 g.cgiOutput = 1;
116 headerHasBeenGenerated = 1;
117 }
118
119 /*
120 ** Draw the footer at the bottom of the page.
121
+1 -1
--- src/th_main.c
+++ src/th_main.c
@@ -95,11 +95,11 @@
9595
if( n<0 ) n = strlen(z);
9696
if( encode ){
9797
z = htmlize(z, n);
9898
n = strlen(z);
9999
}
100
- if( g.cgiPanic ){
100
+ if( g.cgiOutput ){
101101
cgi_append_content(z, n);
102102
}else{
103103
fwrite(z, 1, n, stdout);
104104
}
105105
if( encode ) free((char*)z);
106106
--- src/th_main.c
+++ src/th_main.c
@@ -95,11 +95,11 @@
95 if( n<0 ) n = strlen(z);
96 if( encode ){
97 z = htmlize(z, n);
98 n = strlen(z);
99 }
100 if( g.cgiPanic ){
101 cgi_append_content(z, n);
102 }else{
103 fwrite(z, 1, n, stdout);
104 }
105 if( encode ) free((char*)z);
106
--- src/th_main.c
+++ src/th_main.c
@@ -95,11 +95,11 @@
95 if( n<0 ) n = strlen(z);
96 if( encode ){
97 z = htmlize(z, n);
98 n = strlen(z);
99 }
100 if( g.cgiOutput ){
101 cgi_append_content(z, n);
102 }else{
103 fwrite(z, 1, n, stdout);
104 }
105 if( encode ) free((char*)z);
106
+19 -50
--- src/timeline.c
+++ src/timeline.c
@@ -166,18 +166,16 @@
166166
** 0. rid
167167
** 1. UUID
168168
** 2. Date/Time
169169
** 3. Comment string
170170
** 4. User
171
-** 5. Number of non-merge children
172
-** 6. Number of parents
173
-** 7. True if is a leaf
174
-** 8. background color
175
-** 9. type ("ci", "w", "t")
176
-** 10. list of symbolic tags.
177
-** 11. tagid for ticket or wiki
178
-** 12. Short comment to user for repeated tickets and wiki
171
+** 5. True if is a leaf
172
+** 6. background color
173
+** 7. type ("ci", "w", "t")
174
+** 8. list of symbolic tags.
175
+** 9. tagid for ticket or wiki
176
+** 10. Short comment to user for repeated tickets and wiki
179177
*/
180178
void www_print_timeline(
181179
Stmt *pQuery, /* Query to implement the timeline */
182180
int tmFlags, /* Flags controlling display behavior */
183181
void (*xExtra)(int) /* Routine to call on each line of display */
@@ -205,28 +203,26 @@
205203
@ <table cellspacing=0 border=0 cellpadding=0>
206204
blob_zero(&comment);
207205
while( db_step(pQuery)==SQLITE_ROW ){
208206
int rid = db_column_int(pQuery, 0);
209207
const char *zUuid = db_column_text(pQuery, 1);
210
- int nPChild = db_column_int(pQuery, 5);
211
- int nParent = db_column_int(pQuery, 6);
212
- int isLeaf = db_column_int(pQuery, 7);
213
- const char *zBgClr = db_column_text(pQuery, 8);
208
+ int isLeaf = db_column_int(pQuery, 5);
209
+ const char *zBgClr = db_column_text(pQuery, 6);
214210
const char *zDate = db_column_text(pQuery, 2);
215
- const char *zType = db_column_text(pQuery, 9);
211
+ const char *zType = db_column_text(pQuery, 7);
216212
const char *zUser = db_column_text(pQuery, 4);
217
- const char *zTagList = db_column_text(pQuery, 10);
218
- int tagid = db_column_int(pQuery, 11);
213
+ const char *zTagList = db_column_text(pQuery, 8);
214
+ int tagid = db_column_int(pQuery, 9);
219215
int commentColumn = 3; /* Column containing comment text */
220216
char zTime[8];
221217
if( tagid ){
222218
if( tagid==prevTagid ){
223219
if( tmFlags & TIMELINE_BRIEF ){
224220
suppressCnt++;
225221
continue;
226222
}else{
227
- commentColumn = 12;
223
+ commentColumn = 10;
228224
}
229225
}
230226
}
231227
prevTagid = tagid;
232228
if( suppressCnt ){
@@ -273,48 +269,28 @@
273269
if( db_step(&qbranch)==SQLITE_ROW ){
274270
zBr = db_column_text(&qbranch, 0);
275271
}else{
276272
zBr = "trunk";
277273
}
278
- gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr);
274
+ gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr);
279275
db_reset(&qbranch);
280276
@ <div id="m%d(gidx)"></div>
281277
}
282278
if( zBgClr && zBgClr[0] ){
283279
@ <td valign="top" align="left" bgcolor="%h(zBgClr)">
284280
}else{
285281
@ <td valign="top" align="left">
286282
}
287283
if( zType[0]=='c' ){
288
- const char *azTag[5];
289
- int nTag = 0;
290284
hyperlink_to_uuid(zUuid);
291
- if( (tmFlags & TIMELINE_LEAFONLY)==0 ){
292
- if( nParent>1 ){
293
- azTag[nTag++] = "Merge";
294
- }
295
- if( nPChild>1 ){
296
- if( count_nonbranch_children(rid)>1 ){
297
- azTag[nTag++] = "Fork";
298
- }else{
299
- azTag[nTag++] = "Branch-Point";
300
- }
301
- }
302
- }
303285
if( isLeaf ){
304286
if( db_exists("SELECT 1 FROM tagxref"
305287
" WHERE rid=%d AND tagid=%d AND tagtype>0",
306288
rid, TAG_CLOSED) ){
307
- azTag[nTag++] = "Closed-Leaf";
289
+ @ <b>Closed-Leaf:</b>
308290
}else{
309
- azTag[nTag++] = "Leaf";
310
- }
311
- }
312
- if( nTag>0 ){
313
- int i;
314
- for(i=0; i<nTag; i++){
315
- @ <b>%s(azTag[i])%s(i==nTag-1?"":",")</b>
291
+ @ <b>Leaf:</b>
316292
}
317293
}
318294
}else if( (tmFlags & TIMELINE_ARTID)!=0 ){
319295
hyperlink_to_uuid(zUuid);
320296
}
@@ -369,12 +345,13 @@
369345
int i;
370346
char cSep;
371347
@ <script type="text/JavaScript">
372348
cgi_printf("var rowinfo = [\n");
373349
for(pRow=pGraph->pFirst; pRow; pRow=pRow->pNext){
374
- cgi_printf("{id:\"m%d\",r:%d,d:%d,mo:%d,mu:%d,u:%d,au:",
350
+ cgi_printf("{id:\"m%d\",bg:\"%s\",r:%d,d:%d,mo:%d,mu:%d,u:%d,au:",
375351
pRow->idx,
352
+ pRow->zBgClr,
376353
pRow->iRail,
377354
pRow->bDescender,
378355
pRow->mergeOut,
379356
pRow->mergeUpto,
380357
pRow->aiRaiser[pRow->iRail]
@@ -464,11 +441,11 @@
464441
@ function drawThinLine(x0,y0,x1,y1){
465442
@ drawBox("black",x0,y0,x1,y1);
466443
@ }
467444
@ function drawNode(p, left, btm){
468445
@ drawBox("black",p.x-5,p.y-5,p.x+6,p.y+6);
469
- @ drawBox("white",p.x-4,p.y-4,p.x+5,p.y+5);
446
+ @ drawBox(p.bg,p.x-4,p.y-4,p.x+5,p.y+5);
470447
@ if( p.u>0 ){
471448
@ var u = rowinfo[p.u-1];
472449
@ drawUpArrow(p.x, u.y+6, p.y-5);
473450
@ }
474451
@ if( p.d ){
@@ -525,18 +502,14 @@
525502
@ var context;
526503
@ if( realCanvas && realCanvas.getContext
527504
@ && (context = realCanvas.getContext('2d'))) {
528505
@ drawBox = function(color,x0,y0,x1,y1) {
529506
@ if( y0>32767 || y1>32767 ) return;
530
- @ var colors = {
531
- @ 'white':'rgba(255,255,255,1)',
532
- @ 'black':'rgba(0,0,0,1)'
533
- @ };
534507
@ if( x0>x1 ){ var t=x0; x0=x1; x1=t; }
535508
@ if( y0>y1 ){ var t=y0; y0=y1; y1=t; }
536509
@ if(isNaN(x0) || isNaN(y0) || isNaN(x1) || isNaN(y1)) return;
537
- @ context.fillStyle = colors[color];
510
+ @ context.fillStyle = color;
538511
@ context.fillRect(x0-left+5,y0,x1-x0+1,y1-y0+1);
539512
@ };
540513
@ }
541514
@ for(var i in rowinfo){
542515
@ drawNode(rowinfo[i], left, btm);
@@ -566,12 +539,10 @@
566539
@ rid INTEGER PRIMARY KEY,
567540
@ uuid TEXT,
568541
@ timestamp TEXT,
569542
@ comment TEXT,
570543
@ user TEXT,
571
- @ nchild INTEGER,
572
- @ nparent INTEGER,
573544
@ isleaf BOOLEAN,
574545
@ bgcolor TEXT,
575546
@ etype TEXT,
576547
@ taglist TEXT,
577548
@ tagid INTEGER,
@@ -592,12 +563,10 @@
592563
@ blob.rid,
593564
@ uuid,
594565
@ datetime(event.mtime,'localtime') AS timestamp,
595566
@ coalesce(ecomment, comment),
596567
@ coalesce(euser, user),
597
- @ (SELECT count(*) FROM plink WHERE pid=blob.rid AND isprim=1),
598
- @ (SELECT count(*) FROM plink WHERE cid=blob.rid),
599568
@ NOT EXISTS(SELECT 1 FROM plink
600569
@ WHERE pid=blob.rid
601570
@ AND coalesce((SELECT value FROM tagxref
602571
@ WHERE tagid=%d AND rid=plink.pid), 'trunk')
603572
@ = coalesce((SELECT value FROM tagxref
604573
--- src/timeline.c
+++ src/timeline.c
@@ -166,18 +166,16 @@
166 ** 0. rid
167 ** 1. UUID
168 ** 2. Date/Time
169 ** 3. Comment string
170 ** 4. User
171 ** 5. Number of non-merge children
172 ** 6. Number of parents
173 ** 7. True if is a leaf
174 ** 8. background color
175 ** 9. type ("ci", "w", "t")
176 ** 10. list of symbolic tags.
177 ** 11. tagid for ticket or wiki
178 ** 12. Short comment to user for repeated tickets and wiki
179 */
180 void www_print_timeline(
181 Stmt *pQuery, /* Query to implement the timeline */
182 int tmFlags, /* Flags controlling display behavior */
183 void (*xExtra)(int) /* Routine to call on each line of display */
@@ -205,28 +203,26 @@
205 @ <table cellspacing=0 border=0 cellpadding=0>
206 blob_zero(&comment);
207 while( db_step(pQuery)==SQLITE_ROW ){
208 int rid = db_column_int(pQuery, 0);
209 const char *zUuid = db_column_text(pQuery, 1);
210 int nPChild = db_column_int(pQuery, 5);
211 int nParent = db_column_int(pQuery, 6);
212 int isLeaf = db_column_int(pQuery, 7);
213 const char *zBgClr = db_column_text(pQuery, 8);
214 const char *zDate = db_column_text(pQuery, 2);
215 const char *zType = db_column_text(pQuery, 9);
216 const char *zUser = db_column_text(pQuery, 4);
217 const char *zTagList = db_column_text(pQuery, 10);
218 int tagid = db_column_int(pQuery, 11);
219 int commentColumn = 3; /* Column containing comment text */
220 char zTime[8];
221 if( tagid ){
222 if( tagid==prevTagid ){
223 if( tmFlags & TIMELINE_BRIEF ){
224 suppressCnt++;
225 continue;
226 }else{
227 commentColumn = 12;
228 }
229 }
230 }
231 prevTagid = tagid;
232 if( suppressCnt ){
@@ -273,48 +269,28 @@
273 if( db_step(&qbranch)==SQLITE_ROW ){
274 zBr = db_column_text(&qbranch, 0);
275 }else{
276 zBr = "trunk";
277 }
278 gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr);
279 db_reset(&qbranch);
280 @ <div id="m%d(gidx)"></div>
281 }
282 if( zBgClr && zBgClr[0] ){
283 @ <td valign="top" align="left" bgcolor="%h(zBgClr)">
284 }else{
285 @ <td valign="top" align="left">
286 }
287 if( zType[0]=='c' ){
288 const char *azTag[5];
289 int nTag = 0;
290 hyperlink_to_uuid(zUuid);
291 if( (tmFlags & TIMELINE_LEAFONLY)==0 ){
292 if( nParent>1 ){
293 azTag[nTag++] = "Merge";
294 }
295 if( nPChild>1 ){
296 if( count_nonbranch_children(rid)>1 ){
297 azTag[nTag++] = "Fork";
298 }else{
299 azTag[nTag++] = "Branch-Point";
300 }
301 }
302 }
303 if( isLeaf ){
304 if( db_exists("SELECT 1 FROM tagxref"
305 " WHERE rid=%d AND tagid=%d AND tagtype>0",
306 rid, TAG_CLOSED) ){
307 azTag[nTag++] = "Closed-Leaf";
308 }else{
309 azTag[nTag++] = "Leaf";
310 }
311 }
312 if( nTag>0 ){
313 int i;
314 for(i=0; i<nTag; i++){
315 @ <b>%s(azTag[i])%s(i==nTag-1?"":",")</b>
316 }
317 }
318 }else if( (tmFlags & TIMELINE_ARTID)!=0 ){
319 hyperlink_to_uuid(zUuid);
320 }
@@ -369,12 +345,13 @@
369 int i;
370 char cSep;
371 @ <script type="text/JavaScript">
372 cgi_printf("var rowinfo = [\n");
373 for(pRow=pGraph->pFirst; pRow; pRow=pRow->pNext){
374 cgi_printf("{id:\"m%d\",r:%d,d:%d,mo:%d,mu:%d,u:%d,au:",
375 pRow->idx,
 
376 pRow->iRail,
377 pRow->bDescender,
378 pRow->mergeOut,
379 pRow->mergeUpto,
380 pRow->aiRaiser[pRow->iRail]
@@ -464,11 +441,11 @@
464 @ function drawThinLine(x0,y0,x1,y1){
465 @ drawBox("black",x0,y0,x1,y1);
466 @ }
467 @ function drawNode(p, left, btm){
468 @ drawBox("black",p.x-5,p.y-5,p.x+6,p.y+6);
469 @ drawBox("white",p.x-4,p.y-4,p.x+5,p.y+5);
470 @ if( p.u>0 ){
471 @ var u = rowinfo[p.u-1];
472 @ drawUpArrow(p.x, u.y+6, p.y-5);
473 @ }
474 @ if( p.d ){
@@ -525,18 +502,14 @@
525 @ var context;
526 @ if( realCanvas && realCanvas.getContext
527 @ && (context = realCanvas.getContext('2d'))) {
528 @ drawBox = function(color,x0,y0,x1,y1) {
529 @ if( y0>32767 || y1>32767 ) return;
530 @ var colors = {
531 @ 'white':'rgba(255,255,255,1)',
532 @ 'black':'rgba(0,0,0,1)'
533 @ };
534 @ if( x0>x1 ){ var t=x0; x0=x1; x1=t; }
535 @ if( y0>y1 ){ var t=y0; y0=y1; y1=t; }
536 @ if(isNaN(x0) || isNaN(y0) || isNaN(x1) || isNaN(y1)) return;
537 @ context.fillStyle = colors[color];
538 @ context.fillRect(x0-left+5,y0,x1-x0+1,y1-y0+1);
539 @ };
540 @ }
541 @ for(var i in rowinfo){
542 @ drawNode(rowinfo[i], left, btm);
@@ -566,12 +539,10 @@
566 @ rid INTEGER PRIMARY KEY,
567 @ uuid TEXT,
568 @ timestamp TEXT,
569 @ comment TEXT,
570 @ user TEXT,
571 @ nchild INTEGER,
572 @ nparent INTEGER,
573 @ isleaf BOOLEAN,
574 @ bgcolor TEXT,
575 @ etype TEXT,
576 @ taglist TEXT,
577 @ tagid INTEGER,
@@ -592,12 +563,10 @@
592 @ blob.rid,
593 @ uuid,
594 @ datetime(event.mtime,'localtime') AS timestamp,
595 @ coalesce(ecomment, comment),
596 @ coalesce(euser, user),
597 @ (SELECT count(*) FROM plink WHERE pid=blob.rid AND isprim=1),
598 @ (SELECT count(*) FROM plink WHERE cid=blob.rid),
599 @ NOT EXISTS(SELECT 1 FROM plink
600 @ WHERE pid=blob.rid
601 @ AND coalesce((SELECT value FROM tagxref
602 @ WHERE tagid=%d AND rid=plink.pid), 'trunk')
603 @ = coalesce((SELECT value FROM tagxref
604
--- src/timeline.c
+++ src/timeline.c
@@ -166,18 +166,16 @@
166 ** 0. rid
167 ** 1. UUID
168 ** 2. Date/Time
169 ** 3. Comment string
170 ** 4. User
171 ** 5. True if is a leaf
172 ** 6. background color
173 ** 7. type ("ci", "w", "t")
174 ** 8. list of symbolic tags.
175 ** 9. tagid for ticket or wiki
176 ** 10. Short comment to user for repeated tickets and wiki
 
 
177 */
178 void www_print_timeline(
179 Stmt *pQuery, /* Query to implement the timeline */
180 int tmFlags, /* Flags controlling display behavior */
181 void (*xExtra)(int) /* Routine to call on each line of display */
@@ -205,28 +203,26 @@
203 @ <table cellspacing=0 border=0 cellpadding=0>
204 blob_zero(&comment);
205 while( db_step(pQuery)==SQLITE_ROW ){
206 int rid = db_column_int(pQuery, 0);
207 const char *zUuid = db_column_text(pQuery, 1);
208 int isLeaf = db_column_int(pQuery, 5);
209 const char *zBgClr = db_column_text(pQuery, 6);
 
 
210 const char *zDate = db_column_text(pQuery, 2);
211 const char *zType = db_column_text(pQuery, 7);
212 const char *zUser = db_column_text(pQuery, 4);
213 const char *zTagList = db_column_text(pQuery, 8);
214 int tagid = db_column_int(pQuery, 9);
215 int commentColumn = 3; /* Column containing comment text */
216 char zTime[8];
217 if( tagid ){
218 if( tagid==prevTagid ){
219 if( tmFlags & TIMELINE_BRIEF ){
220 suppressCnt++;
221 continue;
222 }else{
223 commentColumn = 10;
224 }
225 }
226 }
227 prevTagid = tagid;
228 if( suppressCnt ){
@@ -273,48 +269,28 @@
269 if( db_step(&qbranch)==SQLITE_ROW ){
270 zBr = db_column_text(&qbranch, 0);
271 }else{
272 zBr = "trunk";
273 }
274 gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr);
275 db_reset(&qbranch);
276 @ <div id="m%d(gidx)"></div>
277 }
278 if( zBgClr && zBgClr[0] ){
279 @ <td valign="top" align="left" bgcolor="%h(zBgClr)">
280 }else{
281 @ <td valign="top" align="left">
282 }
283 if( zType[0]=='c' ){
 
 
284 hyperlink_to_uuid(zUuid);
 
 
 
 
 
 
 
 
 
 
 
 
285 if( isLeaf ){
286 if( db_exists("SELECT 1 FROM tagxref"
287 " WHERE rid=%d AND tagid=%d AND tagtype>0",
288 rid, TAG_CLOSED) ){
289 @ <b>Closed-Leaf:</b>
290 }else{
291 @ <b>Leaf:</b>
 
 
 
 
 
 
292 }
293 }
294 }else if( (tmFlags & TIMELINE_ARTID)!=0 ){
295 hyperlink_to_uuid(zUuid);
296 }
@@ -369,12 +345,13 @@
345 int i;
346 char cSep;
347 @ <script type="text/JavaScript">
348 cgi_printf("var rowinfo = [\n");
349 for(pRow=pGraph->pFirst; pRow; pRow=pRow->pNext){
350 cgi_printf("{id:\"m%d\",bg:\"%s\",r:%d,d:%d,mo:%d,mu:%d,u:%d,au:",
351 pRow->idx,
352 pRow->zBgClr,
353 pRow->iRail,
354 pRow->bDescender,
355 pRow->mergeOut,
356 pRow->mergeUpto,
357 pRow->aiRaiser[pRow->iRail]
@@ -464,11 +441,11 @@
441 @ function drawThinLine(x0,y0,x1,y1){
442 @ drawBox("black",x0,y0,x1,y1);
443 @ }
444 @ function drawNode(p, left, btm){
445 @ drawBox("black",p.x-5,p.y-5,p.x+6,p.y+6);
446 @ drawBox(p.bg,p.x-4,p.y-4,p.x+5,p.y+5);
447 @ if( p.u>0 ){
448 @ var u = rowinfo[p.u-1];
449 @ drawUpArrow(p.x, u.y+6, p.y-5);
450 @ }
451 @ if( p.d ){
@@ -525,18 +502,14 @@
502 @ var context;
503 @ if( realCanvas && realCanvas.getContext
504 @ && (context = realCanvas.getContext('2d'))) {
505 @ drawBox = function(color,x0,y0,x1,y1) {
506 @ if( y0>32767 || y1>32767 ) return;
 
 
 
 
507 @ if( x0>x1 ){ var t=x0; x0=x1; x1=t; }
508 @ if( y0>y1 ){ var t=y0; y0=y1; y1=t; }
509 @ if(isNaN(x0) || isNaN(y0) || isNaN(x1) || isNaN(y1)) return;
510 @ context.fillStyle = color;
511 @ context.fillRect(x0-left+5,y0,x1-x0+1,y1-y0+1);
512 @ };
513 @ }
514 @ for(var i in rowinfo){
515 @ drawNode(rowinfo[i], left, btm);
@@ -566,12 +539,10 @@
539 @ rid INTEGER PRIMARY KEY,
540 @ uuid TEXT,
541 @ timestamp TEXT,
542 @ comment TEXT,
543 @ user TEXT,
 
 
544 @ isleaf BOOLEAN,
545 @ bgcolor TEXT,
546 @ etype TEXT,
547 @ taglist TEXT,
548 @ tagid INTEGER,
@@ -592,12 +563,10 @@
563 @ blob.rid,
564 @ uuid,
565 @ datetime(event.mtime,'localtime') AS timestamp,
566 @ coalesce(ecomment, comment),
567 @ coalesce(euser, user),
 
 
568 @ NOT EXISTS(SELECT 1 FROM plink
569 @ WHERE pid=blob.rid
570 @ AND coalesce((SELECT value FROM tagxref
571 @ WHERE tagid=%d AND rid=plink.pid), 'trunk')
572 @ = coalesce((SELECT value FROM tagxref
573
+38 -20
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -89,10 +89,11 @@
8989
#define AMSK_TYPE 0x0100000
9090
#define AMSK_VALIGN 0x0200000
9191
#define AMSK_VALUE 0x0400000
9292
#define AMSK_VSPACE 0x0800000
9393
#define AMSK_WIDTH 0x1000000
94
+#define AMSK_CLASS 0x2000000
9495
9596
static const struct AllowedAttribute {
9697
const char *zName;
9798
unsigned int iMask;
9899
} aAttribute[] = {
@@ -101,10 +102,11 @@
101102
{ "alt", AMSK_ALT, },
102103
{ "bgcolor", AMSK_BGCOLOR, },
103104
{ "border", AMSK_BORDER, },
104105
{ "cellpadding", AMSK_CELLPADDING, },
105106
{ "cellspacing", AMSK_CELLSPACING, },
107
+ { "class", AMSK_CLASS, },
106108
{ "clear", AMSK_CLEAR, },
107109
{ "color", AMSK_COLOR, },
108110
{ "colspan", AMSK_COLSPAN, },
109111
{ "compact", AMSK_COMPACT, },
110112
{ "face", AMSK_FACE, },
@@ -235,11 +237,11 @@
235237
short int iType; /* The MUTYPE_* code */
236238
int allowedAttr; /* Allowed attributes on this markup */
237239
} aMarkup[] = {
238240
{ 0, MARKUP_INVALID, 0, 0 },
239241
{ "a", MARKUP_A, MUTYPE_HYPERLINK,
240
- AMSK_HREF|AMSK_NAME },
242
+ AMSK_HREF|AMSK_NAME|AMSK_CLASS },
241243
{ "address", MARKUP_ADDRESS, MUTYPE_BLOCK, 0 },
242244
{ "b", MARKUP_B, MUTYPE_FONT, 0 },
243245
{ "big", MARKUP_BIG, MUTYPE_FONT, 0 },
244246
{ "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, 0 },
245247
{ "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR },
@@ -246,24 +248,24 @@
246248
{ "center", MARKUP_CENTER, MUTYPE_BLOCK, 0 },
247249
{ "cite", MARKUP_CITE, MUTYPE_FONT, 0 },
248250
{ "code", MARKUP_CODE, MUTYPE_FONT, 0 },
249251
{ "dd", MARKUP_DD, MUTYPE_LI, 0 },
250252
{ "dfn", MARKUP_DFN, MUTYPE_FONT, 0 },
251
- { "div", MARKUP_DIV, MUTYPE_BLOCK, AMSK_ID },
253
+ { "div", MARKUP_DIV, MUTYPE_BLOCK, AMSK_ID|AMSK_CLASS },
252254
{ "dl", MARKUP_DL, MUTYPE_LIST, AMSK_COMPACT },
253255
{ "dt", MARKUP_DT, MUTYPE_LI, 0 },
254256
{ "em", MARKUP_EM, MUTYPE_FONT, 0 },
255257
{ "font", MARKUP_FONT, MUTYPE_FONT,
256258
AMSK_COLOR|AMSK_FACE|AMSK_SIZE },
257
- { "h1", MARKUP_H1, MUTYPE_BLOCK, AMSK_ALIGN },
258
- { "h2", MARKUP_H2, MUTYPE_BLOCK, AMSK_ALIGN },
259
- { "h3", MARKUP_H3, MUTYPE_BLOCK, AMSK_ALIGN },
260
- { "h4", MARKUP_H4, MUTYPE_BLOCK, AMSK_ALIGN },
261
- { "h5", MARKUP_H5, MUTYPE_BLOCK, AMSK_ALIGN },
262
- { "h6", MARKUP_H6, MUTYPE_BLOCK, AMSK_ALIGN },
259
+ { "h1", MARKUP_H1, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
260
+ { "h2", MARKUP_H2, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
261
+ { "h3", MARKUP_H3, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
262
+ { "h4", MARKUP_H4, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
263
+ { "h5", MARKUP_H5, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
264
+ { "h6", MARKUP_H6, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
263265
{ "hr", MARKUP_HR, MUTYPE_SINGLE,
264
- AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH },
266
+ AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH|AMSK_CLASS },
265267
{ "i", MARKUP_I, MUTYPE_FONT, 0 },
266268
{ "img", MARKUP_IMG, MUTYPE_SINGLE,
267269
AMSK_ALIGN|AMSK_ALT|AMSK_BORDER|AMSK_HEIGHT|
268270
AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH },
269271
{ "kbd", MARKUP_KBD, MUTYPE_FONT, 0 },
@@ -271,11 +273,11 @@
271273
AMSK_TYPE|AMSK_VALUE },
272274
{ "nobr", MARKUP_NOBR, MUTYPE_FONT, 0 },
273275
{ "nowiki", MARKUP_NOWIKI, MUTYPE_SPECIAL, 0 },
274276
{ "ol", MARKUP_OL, MUTYPE_LIST,
275277
AMSK_START|AMSK_TYPE|AMSK_COMPACT },
276
- { "p", MARKUP_P, MUTYPE_BLOCK, AMSK_ALIGN },
278
+ { "p", MARKUP_P, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
277279
{ "pre", MARKUP_PRE, MUTYPE_BLOCK, 0 },
278280
{ "s", MARKUP_S, MUTYPE_FONT, 0 },
279281
{ "samp", MARKUP_SAMP, MUTYPE_FONT, 0 },
280282
{ "small", MARKUP_SMALL, MUTYPE_FONT, 0 },
281283
{ "strike", MARKUP_STRIKE, MUTYPE_FONT, 0 },
@@ -282,19 +284,19 @@
282284
{ "strong", MARKUP_STRONG, MUTYPE_FONT, 0 },
283285
{ "sub", MARKUP_SUB, MUTYPE_FONT, 0 },
284286
{ "sup", MARKUP_SUP, MUTYPE_FONT, 0 },
285287
{ "table", MARKUP_TABLE, MUTYPE_TABLE,
286288
AMSK_ALIGN|AMSK_BGCOLOR|AMSK_BORDER|AMSK_CELLPADDING|
287
- AMSK_CELLSPACING|AMSK_HSPACE|AMSK_VSPACE },
289
+ AMSK_CELLSPACING|AMSK_HSPACE|AMSK_VSPACE|AMSK_CLASS },
288290
{ "td", MARKUP_TD, MUTYPE_TD,
289291
AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
290
- AMSK_ROWSPAN|AMSK_VALIGN },
292
+ AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
291293
{ "th", MARKUP_TH, MUTYPE_TD,
292294
AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
293
- AMSK_ROWSPAN|AMSK_VALIGN },
295
+ AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
294296
{ "tr", MARKUP_TR, MUTYPE_TR,
295
- AMSK_ALIGN|AMSK_BGCOLOR||AMSK_VALIGN },
297
+ AMSK_ALIGN|AMSK_BGCOLOR||AMSK_VALIGN|AMSK_CLASS },
296298
{ "tt", MARKUP_TT, MUTYPE_FONT, 0 },
297299
{ "u", MARKUP_U, MUTYPE_FONT, 0 },
298300
{ "ul", MARKUP_UL, MUTYPE_LIST,
299301
AMSK_TYPE|AMSK_COMPACT },
300302
{ "var", MARKUP_VAR, MUTYPE_FONT, 0 },
@@ -392,17 +394,20 @@
392394
** it is not well-formed markup, return 0.
393395
*/
394396
static int markupLength(const char *z){
395397
int n = 1;
396398
int inparen = 0;
399
+ int c;
397400
if( z[n]=='/' ){ n++; }
398401
if( !isalpha(z[n]) ) return 0;
399402
while( isalnum(z[n]) ){ n++; }
400
- if( z[n]!='>' && !isspace(z[n]) ) return 0;
401
- while( z[n] && (z[n]!='>' || inparen) ){
402
- if( z[n]=='"' ){
403
- inparen = !inparen;
403
+ if( (c = z[n])!='>' && !isspace(c) ) return 0;
404
+ while( (c = z[n])!=0 && (c!='>' || inparen) ){
405
+ if( c==inparen ){
406
+ inparen = 0;
407
+ }else if( c=='"' || c=='\'' ){
408
+ inparen = c;
404409
}
405410
n++;
406411
}
407412
if( z[n]!='>' ) return 0;
408413
return n+1;
@@ -713,10 +718,14 @@
713718
while( isspace(z[i]) ){ z++; }
714719
if( z[i]=='"' ){
715720
i++;
716721
zValue = &z[i];
717722
while( z[i] && z[i]!='"' ){ i++; }
723
+ }else if( z[i]=='\'' ){
724
+ i++;
725
+ zValue = &z[i];
726
+ while( z[i] && z[i]!='\'' ){ i++; }
718727
}else{
719728
zValue = &z[i];
720729
while( !isspace(z[i]) && z[i]!='>' ){ z++; }
721730
}
722731
if( attrOk ){
@@ -1381,10 +1390,19 @@
13811390
}
13821391
z += n;
13831392
}
13841393
}
13851394
1395
+/*
1396
+** Skip over the UTF-8 Byte-Order-Mark that some broken Windows
1397
+** tools add to the beginning of text files.
1398
+*/
1399
+char *skip_bom(char *z){
1400
+ static const char bom[] = { 0xEF, 0xBB, 0xBF };
1401
+ if( z && memcmp(z, bom, 3)==0 ) z += 3;
1402
+ return z;
1403
+}
13861404
13871405
/*
13881406
** Transform the text in the pIn blob. Write the results
13891407
** into the pOut blob. The pOut blob should already be
13901408
** initialized. The output is merely appended to pOut.
@@ -1412,11 +1430,11 @@
14121430
renderer.pOut = pOut;
14131431
}else{
14141432
renderer.pOut = cgi_output_blob();
14151433
}
14161434
1417
- z = blob_str(pIn);
1435
+ z = skip_bom(blob_str(pIn));
14181436
wiki_render(&renderer, z);
14191437
endAutoParagraph(&renderer);
14201438
while( renderer.nStack ){
14211439
popStack(&renderer);
14221440
}
@@ -1447,11 +1465,11 @@
14471465
*/
14481466
int wiki_find_title(Blob *pIn, Blob *pTitle, Blob *pTail){
14491467
char *z;
14501468
int i;
14511469
int iStart;
1452
- z = blob_str(pIn);
1470
+ z = skip_bom(blob_str(pIn));
14531471
for(i=0; isspace(z[i]); i++){}
14541472
if( z[i]!='<' ) return 0;
14551473
i++;
14561474
if( strncmp(&z[i],"title>", 6)!=0 ) return 0;
14571475
iStart = i+6;
14581476
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -89,10 +89,11 @@
89 #define AMSK_TYPE 0x0100000
90 #define AMSK_VALIGN 0x0200000
91 #define AMSK_VALUE 0x0400000
92 #define AMSK_VSPACE 0x0800000
93 #define AMSK_WIDTH 0x1000000
 
94
95 static const struct AllowedAttribute {
96 const char *zName;
97 unsigned int iMask;
98 } aAttribute[] = {
@@ -101,10 +102,11 @@
101 { "alt", AMSK_ALT, },
102 { "bgcolor", AMSK_BGCOLOR, },
103 { "border", AMSK_BORDER, },
104 { "cellpadding", AMSK_CELLPADDING, },
105 { "cellspacing", AMSK_CELLSPACING, },
 
106 { "clear", AMSK_CLEAR, },
107 { "color", AMSK_COLOR, },
108 { "colspan", AMSK_COLSPAN, },
109 { "compact", AMSK_COMPACT, },
110 { "face", AMSK_FACE, },
@@ -235,11 +237,11 @@
235 short int iType; /* The MUTYPE_* code */
236 int allowedAttr; /* Allowed attributes on this markup */
237 } aMarkup[] = {
238 { 0, MARKUP_INVALID, 0, 0 },
239 { "a", MARKUP_A, MUTYPE_HYPERLINK,
240 AMSK_HREF|AMSK_NAME },
241 { "address", MARKUP_ADDRESS, MUTYPE_BLOCK, 0 },
242 { "b", MARKUP_B, MUTYPE_FONT, 0 },
243 { "big", MARKUP_BIG, MUTYPE_FONT, 0 },
244 { "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, 0 },
245 { "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR },
@@ -246,24 +248,24 @@
246 { "center", MARKUP_CENTER, MUTYPE_BLOCK, 0 },
247 { "cite", MARKUP_CITE, MUTYPE_FONT, 0 },
248 { "code", MARKUP_CODE, MUTYPE_FONT, 0 },
249 { "dd", MARKUP_DD, MUTYPE_LI, 0 },
250 { "dfn", MARKUP_DFN, MUTYPE_FONT, 0 },
251 { "div", MARKUP_DIV, MUTYPE_BLOCK, AMSK_ID },
252 { "dl", MARKUP_DL, MUTYPE_LIST, AMSK_COMPACT },
253 { "dt", MARKUP_DT, MUTYPE_LI, 0 },
254 { "em", MARKUP_EM, MUTYPE_FONT, 0 },
255 { "font", MARKUP_FONT, MUTYPE_FONT,
256 AMSK_COLOR|AMSK_FACE|AMSK_SIZE },
257 { "h1", MARKUP_H1, MUTYPE_BLOCK, AMSK_ALIGN },
258 { "h2", MARKUP_H2, MUTYPE_BLOCK, AMSK_ALIGN },
259 { "h3", MARKUP_H3, MUTYPE_BLOCK, AMSK_ALIGN },
260 { "h4", MARKUP_H4, MUTYPE_BLOCK, AMSK_ALIGN },
261 { "h5", MARKUP_H5, MUTYPE_BLOCK, AMSK_ALIGN },
262 { "h6", MARKUP_H6, MUTYPE_BLOCK, AMSK_ALIGN },
263 { "hr", MARKUP_HR, MUTYPE_SINGLE,
264 AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH },
265 { "i", MARKUP_I, MUTYPE_FONT, 0 },
266 { "img", MARKUP_IMG, MUTYPE_SINGLE,
267 AMSK_ALIGN|AMSK_ALT|AMSK_BORDER|AMSK_HEIGHT|
268 AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH },
269 { "kbd", MARKUP_KBD, MUTYPE_FONT, 0 },
@@ -271,11 +273,11 @@
271 AMSK_TYPE|AMSK_VALUE },
272 { "nobr", MARKUP_NOBR, MUTYPE_FONT, 0 },
273 { "nowiki", MARKUP_NOWIKI, MUTYPE_SPECIAL, 0 },
274 { "ol", MARKUP_OL, MUTYPE_LIST,
275 AMSK_START|AMSK_TYPE|AMSK_COMPACT },
276 { "p", MARKUP_P, MUTYPE_BLOCK, AMSK_ALIGN },
277 { "pre", MARKUP_PRE, MUTYPE_BLOCK, 0 },
278 { "s", MARKUP_S, MUTYPE_FONT, 0 },
279 { "samp", MARKUP_SAMP, MUTYPE_FONT, 0 },
280 { "small", MARKUP_SMALL, MUTYPE_FONT, 0 },
281 { "strike", MARKUP_STRIKE, MUTYPE_FONT, 0 },
@@ -282,19 +284,19 @@
282 { "strong", MARKUP_STRONG, MUTYPE_FONT, 0 },
283 { "sub", MARKUP_SUB, MUTYPE_FONT, 0 },
284 { "sup", MARKUP_SUP, MUTYPE_FONT, 0 },
285 { "table", MARKUP_TABLE, MUTYPE_TABLE,
286 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_BORDER|AMSK_CELLPADDING|
287 AMSK_CELLSPACING|AMSK_HSPACE|AMSK_VSPACE },
288 { "td", MARKUP_TD, MUTYPE_TD,
289 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
290 AMSK_ROWSPAN|AMSK_VALIGN },
291 { "th", MARKUP_TH, MUTYPE_TD,
292 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
293 AMSK_ROWSPAN|AMSK_VALIGN },
294 { "tr", MARKUP_TR, MUTYPE_TR,
295 AMSK_ALIGN|AMSK_BGCOLOR||AMSK_VALIGN },
296 { "tt", MARKUP_TT, MUTYPE_FONT, 0 },
297 { "u", MARKUP_U, MUTYPE_FONT, 0 },
298 { "ul", MARKUP_UL, MUTYPE_LIST,
299 AMSK_TYPE|AMSK_COMPACT },
300 { "var", MARKUP_VAR, MUTYPE_FONT, 0 },
@@ -392,17 +394,20 @@
392 ** it is not well-formed markup, return 0.
393 */
394 static int markupLength(const char *z){
395 int n = 1;
396 int inparen = 0;
 
397 if( z[n]=='/' ){ n++; }
398 if( !isalpha(z[n]) ) return 0;
399 while( isalnum(z[n]) ){ n++; }
400 if( z[n]!='>' && !isspace(z[n]) ) return 0;
401 while( z[n] && (z[n]!='>' || inparen) ){
402 if( z[n]=='"' ){
403 inparen = !inparen;
 
 
404 }
405 n++;
406 }
407 if( z[n]!='>' ) return 0;
408 return n+1;
@@ -713,10 +718,14 @@
713 while( isspace(z[i]) ){ z++; }
714 if( z[i]=='"' ){
715 i++;
716 zValue = &z[i];
717 while( z[i] && z[i]!='"' ){ i++; }
 
 
 
 
718 }else{
719 zValue = &z[i];
720 while( !isspace(z[i]) && z[i]!='>' ){ z++; }
721 }
722 if( attrOk ){
@@ -1381,10 +1390,19 @@
1381 }
1382 z += n;
1383 }
1384 }
1385
 
 
 
 
 
 
 
 
 
1386
1387 /*
1388 ** Transform the text in the pIn blob. Write the results
1389 ** into the pOut blob. The pOut blob should already be
1390 ** initialized. The output is merely appended to pOut.
@@ -1412,11 +1430,11 @@
1412 renderer.pOut = pOut;
1413 }else{
1414 renderer.pOut = cgi_output_blob();
1415 }
1416
1417 z = blob_str(pIn);
1418 wiki_render(&renderer, z);
1419 endAutoParagraph(&renderer);
1420 while( renderer.nStack ){
1421 popStack(&renderer);
1422 }
@@ -1447,11 +1465,11 @@
1447 */
1448 int wiki_find_title(Blob *pIn, Blob *pTitle, Blob *pTail){
1449 char *z;
1450 int i;
1451 int iStart;
1452 z = blob_str(pIn);
1453 for(i=0; isspace(z[i]); i++){}
1454 if( z[i]!='<' ) return 0;
1455 i++;
1456 if( strncmp(&z[i],"title>", 6)!=0 ) return 0;
1457 iStart = i+6;
1458
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -89,10 +89,11 @@
89 #define AMSK_TYPE 0x0100000
90 #define AMSK_VALIGN 0x0200000
91 #define AMSK_VALUE 0x0400000
92 #define AMSK_VSPACE 0x0800000
93 #define AMSK_WIDTH 0x1000000
94 #define AMSK_CLASS 0x2000000
95
96 static const struct AllowedAttribute {
97 const char *zName;
98 unsigned int iMask;
99 } aAttribute[] = {
@@ -101,10 +102,11 @@
102 { "alt", AMSK_ALT, },
103 { "bgcolor", AMSK_BGCOLOR, },
104 { "border", AMSK_BORDER, },
105 { "cellpadding", AMSK_CELLPADDING, },
106 { "cellspacing", AMSK_CELLSPACING, },
107 { "class", AMSK_CLASS, },
108 { "clear", AMSK_CLEAR, },
109 { "color", AMSK_COLOR, },
110 { "colspan", AMSK_COLSPAN, },
111 { "compact", AMSK_COMPACT, },
112 { "face", AMSK_FACE, },
@@ -235,11 +237,11 @@
237 short int iType; /* The MUTYPE_* code */
238 int allowedAttr; /* Allowed attributes on this markup */
239 } aMarkup[] = {
240 { 0, MARKUP_INVALID, 0, 0 },
241 { "a", MARKUP_A, MUTYPE_HYPERLINK,
242 AMSK_HREF|AMSK_NAME|AMSK_CLASS },
243 { "address", MARKUP_ADDRESS, MUTYPE_BLOCK, 0 },
244 { "b", MARKUP_B, MUTYPE_FONT, 0 },
245 { "big", MARKUP_BIG, MUTYPE_FONT, 0 },
246 { "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, 0 },
247 { "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR },
@@ -246,24 +248,24 @@
248 { "center", MARKUP_CENTER, MUTYPE_BLOCK, 0 },
249 { "cite", MARKUP_CITE, MUTYPE_FONT, 0 },
250 { "code", MARKUP_CODE, MUTYPE_FONT, 0 },
251 { "dd", MARKUP_DD, MUTYPE_LI, 0 },
252 { "dfn", MARKUP_DFN, MUTYPE_FONT, 0 },
253 { "div", MARKUP_DIV, MUTYPE_BLOCK, AMSK_ID|AMSK_CLASS },
254 { "dl", MARKUP_DL, MUTYPE_LIST, AMSK_COMPACT },
255 { "dt", MARKUP_DT, MUTYPE_LI, 0 },
256 { "em", MARKUP_EM, MUTYPE_FONT, 0 },
257 { "font", MARKUP_FONT, MUTYPE_FONT,
258 AMSK_COLOR|AMSK_FACE|AMSK_SIZE },
259 { "h1", MARKUP_H1, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
260 { "h2", MARKUP_H2, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
261 { "h3", MARKUP_H3, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
262 { "h4", MARKUP_H4, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
263 { "h5", MARKUP_H5, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
264 { "h6", MARKUP_H6, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
265 { "hr", MARKUP_HR, MUTYPE_SINGLE,
266 AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH|AMSK_CLASS },
267 { "i", MARKUP_I, MUTYPE_FONT, 0 },
268 { "img", MARKUP_IMG, MUTYPE_SINGLE,
269 AMSK_ALIGN|AMSK_ALT|AMSK_BORDER|AMSK_HEIGHT|
270 AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH },
271 { "kbd", MARKUP_KBD, MUTYPE_FONT, 0 },
@@ -271,11 +273,11 @@
273 AMSK_TYPE|AMSK_VALUE },
274 { "nobr", MARKUP_NOBR, MUTYPE_FONT, 0 },
275 { "nowiki", MARKUP_NOWIKI, MUTYPE_SPECIAL, 0 },
276 { "ol", MARKUP_OL, MUTYPE_LIST,
277 AMSK_START|AMSK_TYPE|AMSK_COMPACT },
278 { "p", MARKUP_P, MUTYPE_BLOCK, AMSK_ALIGN|AMSK_CLASS },
279 { "pre", MARKUP_PRE, MUTYPE_BLOCK, 0 },
280 { "s", MARKUP_S, MUTYPE_FONT, 0 },
281 { "samp", MARKUP_SAMP, MUTYPE_FONT, 0 },
282 { "small", MARKUP_SMALL, MUTYPE_FONT, 0 },
283 { "strike", MARKUP_STRIKE, MUTYPE_FONT, 0 },
@@ -282,19 +284,19 @@
284 { "strong", MARKUP_STRONG, MUTYPE_FONT, 0 },
285 { "sub", MARKUP_SUB, MUTYPE_FONT, 0 },
286 { "sup", MARKUP_SUP, MUTYPE_FONT, 0 },
287 { "table", MARKUP_TABLE, MUTYPE_TABLE,
288 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_BORDER|AMSK_CELLPADDING|
289 AMSK_CELLSPACING|AMSK_HSPACE|AMSK_VSPACE|AMSK_CLASS },
290 { "td", MARKUP_TD, MUTYPE_TD,
291 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
292 AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
293 { "th", MARKUP_TH, MUTYPE_TD,
294 AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN|
295 AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS },
296 { "tr", MARKUP_TR, MUTYPE_TR,
297 AMSK_ALIGN|AMSK_BGCOLOR||AMSK_VALIGN|AMSK_CLASS },
298 { "tt", MARKUP_TT, MUTYPE_FONT, 0 },
299 { "u", MARKUP_U, MUTYPE_FONT, 0 },
300 { "ul", MARKUP_UL, MUTYPE_LIST,
301 AMSK_TYPE|AMSK_COMPACT },
302 { "var", MARKUP_VAR, MUTYPE_FONT, 0 },
@@ -392,17 +394,20 @@
394 ** it is not well-formed markup, return 0.
395 */
396 static int markupLength(const char *z){
397 int n = 1;
398 int inparen = 0;
399 int c;
400 if( z[n]=='/' ){ n++; }
401 if( !isalpha(z[n]) ) return 0;
402 while( isalnum(z[n]) ){ n++; }
403 if( (c = z[n])!='>' && !isspace(c) ) return 0;
404 while( (c = z[n])!=0 && (c!='>' || inparen) ){
405 if( c==inparen ){
406 inparen = 0;
407 }else if( c=='"' || c=='\'' ){
408 inparen = c;
409 }
410 n++;
411 }
412 if( z[n]!='>' ) return 0;
413 return n+1;
@@ -713,10 +718,14 @@
718 while( isspace(z[i]) ){ z++; }
719 if( z[i]=='"' ){
720 i++;
721 zValue = &z[i];
722 while( z[i] && z[i]!='"' ){ i++; }
723 }else if( z[i]=='\'' ){
724 i++;
725 zValue = &z[i];
726 while( z[i] && z[i]!='\'' ){ i++; }
727 }else{
728 zValue = &z[i];
729 while( !isspace(z[i]) && z[i]!='>' ){ z++; }
730 }
731 if( attrOk ){
@@ -1381,10 +1390,19 @@
1390 }
1391 z += n;
1392 }
1393 }
1394
1395 /*
1396 ** Skip over the UTF-8 Byte-Order-Mark that some broken Windows
1397 ** tools add to the beginning of text files.
1398 */
1399 char *skip_bom(char *z){
1400 static const char bom[] = { 0xEF, 0xBB, 0xBF };
1401 if( z && memcmp(z, bom, 3)==0 ) z += 3;
1402 return z;
1403 }
1404
1405 /*
1406 ** Transform the text in the pIn blob. Write the results
1407 ** into the pOut blob. The pOut blob should already be
1408 ** initialized. The output is merely appended to pOut.
@@ -1412,11 +1430,11 @@
1430 renderer.pOut = pOut;
1431 }else{
1432 renderer.pOut = cgi_output_blob();
1433 }
1434
1435 z = skip_bom(blob_str(pIn));
1436 wiki_render(&renderer, z);
1437 endAutoParagraph(&renderer);
1438 while( renderer.nStack ){
1439 popStack(&renderer);
1440 }
@@ -1447,11 +1465,11 @@
1465 */
1466 int wiki_find_title(Blob *pIn, Blob *pTitle, Blob *pTail){
1467 char *z;
1468 int i;
1469 int iStart;
1470 z = skip_bom(blob_str(pIn));
1471 for(i=0; isspace(z[i]); i++){}
1472 if( z[i]!='<' ) return 0;
1473 i++;
1474 if( strncmp(&z[i],"title>", 6)!=0 ) return 0;
1475 iStart = i+6;
1476
+11 -11
--- src/xfer.c
+++ src/xfer.c
@@ -992,11 +992,11 @@
992992
if( pushFlag ){
993993
blob_appendf(&send, "push %s %s\n", zSCode, zPCode);
994994
nCardSent++;
995995
}
996996
manifest_crosslink_begin();
997
- printf(zLabelFormat, "", "Bytes", "Cards", "Artifacts", "Deltas");
997
+ fossil_print(zLabelFormat, "", "Bytes", "Cards", "Artifacts", "Deltas");
998998
999999
while( go ){
10001000
int newPhantom = 0;
10011001
char *zRandomness;
10021002
@@ -1058,13 +1058,13 @@
10581058
blob_appendf(&send, "# %s\n", zRandomness);
10591059
free(zRandomness);
10601060
10611061
/* Exchange messages with the server */
10621062
nFileSend = xfer.nFileSent + xfer.nDeltaSent;
1063
- printf(zValueFormat, "Send:",
1064
- blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent,
1065
- xfer.nFileSent, xfer.nDeltaSent);
1063
+ fossil_print(zValueFormat, "Send:",
1064
+ blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent,
1065
+ xfer.nFileSent, xfer.nDeltaSent);
10661066
nCardSent = 0;
10671067
nCardRcvd = 0;
10681068
xfer.nFileSent = 0;
10691069
xfer.nDeltaSent = 0;
10701070
xfer.nGimmeSent = 0;
@@ -1091,11 +1091,11 @@
10911091
if( blob_buffer(&xfer.line)[0]=='#' ){
10921092
continue;
10931093
}
10941094
xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
10951095
nCardRcvd++;
1096
- if (!g.fQuiet) {
1096
+ if( !g.cgiOutput && !g.fQuiet ){
10971097
printf("\r%d", nCardRcvd);
10981098
fflush(stdout);
10991099
}
11001100
11011101
/* file UUID SIZE \n CONTENT
@@ -1232,11 +1232,11 @@
12321232
** to the next cycle.
12331233
*/
12341234
if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
12351235
char *zMsg = blob_terminate(&xfer.aToken[1]);
12361236
defossilize(zMsg);
1237
- if( zMsg ) printf("\rServer says: %s\n", zMsg);
1237
+ if( zMsg ) fossil_print("\rServer says: %s\n", zMsg);
12381238
}else
12391239
12401240
/* error MESSAGE
12411241
**
12421242
** Report an error and abandon the sync session.
@@ -1284,13 +1284,13 @@
12841284
if( origConfigRcvMask & (CONFIGSET_TKT|CONFIGSET_USER) ){
12851285
configure_finalize_receive();
12861286
}
12871287
origConfigRcvMask = 0;
12881288
if( nCardRcvd>0 ){
1289
- printf(zValueFormat, "Received:",
1290
- blob_size(&recv), nCardRcvd,
1291
- xfer.nFileRcvd, xfer.nDeltaRcvd + xfer.nDanglingFile);
1289
+ fossil_print(zValueFormat, "Received:",
1290
+ blob_size(&recv), nCardRcvd,
1291
+ xfer.nFileRcvd, xfer.nDeltaRcvd + xfer.nDanglingFile);
12921292
}
12931293
blob_reset(&recv);
12941294
nCycle++;
12951295
12961296
/* If we received one or more files on the previous exchange but
@@ -1316,13 +1316,13 @@
13161316
13171317
/* If this is a clone, the go at least two rounds */
13181318
if( cloneFlag && nCycle==1 ) go = 1;
13191319
};
13201320
transport_stats(&nSent, &nRcvd, 1);
1321
- printf("Total network traffic: %d bytes sent, %d bytes received\n",
1322
- nSent, nRcvd);
1321
+ fossil_print("Total network traffic: %d bytes sent, %d bytes received\n",
1322
+ nSent, nRcvd);
13231323
transport_close();
13241324
transport_global_shutdown();
13251325
db_multi_exec("DROP TABLE onremote");
13261326
manifest_crosslink_end();
13271327
db_end_transaction(0);
13281328
}
13291329
--- src/xfer.c
+++ src/xfer.c
@@ -992,11 +992,11 @@
992 if( pushFlag ){
993 blob_appendf(&send, "push %s %s\n", zSCode, zPCode);
994 nCardSent++;
995 }
996 manifest_crosslink_begin();
997 printf(zLabelFormat, "", "Bytes", "Cards", "Artifacts", "Deltas");
998
999 while( go ){
1000 int newPhantom = 0;
1001 char *zRandomness;
1002
@@ -1058,13 +1058,13 @@
1058 blob_appendf(&send, "# %s\n", zRandomness);
1059 free(zRandomness);
1060
1061 /* Exchange messages with the server */
1062 nFileSend = xfer.nFileSent + xfer.nDeltaSent;
1063 printf(zValueFormat, "Send:",
1064 blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent,
1065 xfer.nFileSent, xfer.nDeltaSent);
1066 nCardSent = 0;
1067 nCardRcvd = 0;
1068 xfer.nFileSent = 0;
1069 xfer.nDeltaSent = 0;
1070 xfer.nGimmeSent = 0;
@@ -1091,11 +1091,11 @@
1091 if( blob_buffer(&xfer.line)[0]=='#' ){
1092 continue;
1093 }
1094 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
1095 nCardRcvd++;
1096 if (!g.fQuiet) {
1097 printf("\r%d", nCardRcvd);
1098 fflush(stdout);
1099 }
1100
1101 /* file UUID SIZE \n CONTENT
@@ -1232,11 +1232,11 @@
1232 ** to the next cycle.
1233 */
1234 if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
1235 char *zMsg = blob_terminate(&xfer.aToken[1]);
1236 defossilize(zMsg);
1237 if( zMsg ) printf("\rServer says: %s\n", zMsg);
1238 }else
1239
1240 /* error MESSAGE
1241 **
1242 ** Report an error and abandon the sync session.
@@ -1284,13 +1284,13 @@
1284 if( origConfigRcvMask & (CONFIGSET_TKT|CONFIGSET_USER) ){
1285 configure_finalize_receive();
1286 }
1287 origConfigRcvMask = 0;
1288 if( nCardRcvd>0 ){
1289 printf(zValueFormat, "Received:",
1290 blob_size(&recv), nCardRcvd,
1291 xfer.nFileRcvd, xfer.nDeltaRcvd + xfer.nDanglingFile);
1292 }
1293 blob_reset(&recv);
1294 nCycle++;
1295
1296 /* If we received one or more files on the previous exchange but
@@ -1316,13 +1316,13 @@
1316
1317 /* If this is a clone, the go at least two rounds */
1318 if( cloneFlag && nCycle==1 ) go = 1;
1319 };
1320 transport_stats(&nSent, &nRcvd, 1);
1321 printf("Total network traffic: %d bytes sent, %d bytes received\n",
1322 nSent, nRcvd);
1323 transport_close();
1324 transport_global_shutdown();
1325 db_multi_exec("DROP TABLE onremote");
1326 manifest_crosslink_end();
1327 db_end_transaction(0);
1328 }
1329
--- src/xfer.c
+++ src/xfer.c
@@ -992,11 +992,11 @@
992 if( pushFlag ){
993 blob_appendf(&send, "push %s %s\n", zSCode, zPCode);
994 nCardSent++;
995 }
996 manifest_crosslink_begin();
997 fossil_print(zLabelFormat, "", "Bytes", "Cards", "Artifacts", "Deltas");
998
999 while( go ){
1000 int newPhantom = 0;
1001 char *zRandomness;
1002
@@ -1058,13 +1058,13 @@
1058 blob_appendf(&send, "# %s\n", zRandomness);
1059 free(zRandomness);
1060
1061 /* Exchange messages with the server */
1062 nFileSend = xfer.nFileSent + xfer.nDeltaSent;
1063 fossil_print(zValueFormat, "Send:",
1064 blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent,
1065 xfer.nFileSent, xfer.nDeltaSent);
1066 nCardSent = 0;
1067 nCardRcvd = 0;
1068 xfer.nFileSent = 0;
1069 xfer.nDeltaSent = 0;
1070 xfer.nGimmeSent = 0;
@@ -1091,11 +1091,11 @@
1091 if( blob_buffer(&xfer.line)[0]=='#' ){
1092 continue;
1093 }
1094 xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));
1095 nCardRcvd++;
1096 if( !g.cgiOutput && !g.fQuiet ){
1097 printf("\r%d", nCardRcvd);
1098 fflush(stdout);
1099 }
1100
1101 /* file UUID SIZE \n CONTENT
@@ -1232,11 +1232,11 @@
1232 ** to the next cycle.
1233 */
1234 if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
1235 char *zMsg = blob_terminate(&xfer.aToken[1]);
1236 defossilize(zMsg);
1237 if( zMsg ) fossil_print("\rServer says: %s\n", zMsg);
1238 }else
1239
1240 /* error MESSAGE
1241 **
1242 ** Report an error and abandon the sync session.
@@ -1284,13 +1284,13 @@
1284 if( origConfigRcvMask & (CONFIGSET_TKT|CONFIGSET_USER) ){
1285 configure_finalize_receive();
1286 }
1287 origConfigRcvMask = 0;
1288 if( nCardRcvd>0 ){
1289 fossil_print(zValueFormat, "Received:",
1290 blob_size(&recv), nCardRcvd,
1291 xfer.nFileRcvd, xfer.nDeltaRcvd + xfer.nDanglingFile);
1292 }
1293 blob_reset(&recv);
1294 nCycle++;
1295
1296 /* If we received one or more files on the previous exchange but
@@ -1316,13 +1316,13 @@
1316
1317 /* If this is a clone, the go at least two rounds */
1318 if( cloneFlag && nCycle==1 ) go = 1;
1319 };
1320 transport_stats(&nSent, &nRcvd, 1);
1321 fossil_print("Total network traffic: %d bytes sent, %d bytes received\n",
1322 nSent, nRcvd);
1323 transport_close();
1324 transport_global_shutdown();
1325 db_multi_exec("DROP TABLE onremote");
1326 manifest_crosslink_end();
1327 db_end_transaction(0);
1328 }
1329
--- www/branching.wiki
+++ www/branching.wiki
@@ -194,11 +194,11 @@
194194
are symbolic name tags. When a symbolic name tag is attached to a
195195
check-in, that allows you to refer to that check-in by its symbolic
196196
name rather than by its 40-character SHA1 hash name. When a symbolic name
197197
tag propagates (as does the <b>sym-trunk</b> tag) then referring to that
198198
name is the same as referring to the most recent check-in with that name.
199
-Thus the two tags on check-in once cause all decendents to be in the
199
+Thus the two tags on check-in one cause all decendents to be in the
200200
"trunk" branch and to have the symbolic name "trunk".
201201
202202
Check-in 4 has a <b>branch</b> tag which changes the name of the branch
203203
to "test". The branch tag on check-in 4 propagates to check-ins 6 and 9.
204204
But because tag propagation does not follow merge links, the <b>branch=test</b>
205205
--- www/branching.wiki
+++ www/branching.wiki
@@ -194,11 +194,11 @@
194 are symbolic name tags. When a symbolic name tag is attached to a
195 check-in, that allows you to refer to that check-in by its symbolic
196 name rather than by its 40-character SHA1 hash name. When a symbolic name
197 tag propagates (as does the <b>sym-trunk</b> tag) then referring to that
198 name is the same as referring to the most recent check-in with that name.
199 Thus the two tags on check-in once cause all decendents to be in the
200 "trunk" branch and to have the symbolic name "trunk".
201
202 Check-in 4 has a <b>branch</b> tag which changes the name of the branch
203 to "test". The branch tag on check-in 4 propagates to check-ins 6 and 9.
204 But because tag propagation does not follow merge links, the <b>branch=test</b>
205
--- www/branching.wiki
+++ www/branching.wiki
@@ -194,11 +194,11 @@
194 are symbolic name tags. When a symbolic name tag is attached to a
195 check-in, that allows you to refer to that check-in by its symbolic
196 name rather than by its 40-character SHA1 hash name. When a symbolic name
197 tag propagates (as does the <b>sym-trunk</b> tag) then referring to that
198 name is the same as referring to the most recent check-in with that name.
199 Thus the two tags on check-in one cause all decendents to be in the
200 "trunk" branch and to have the symbolic name "trunk".
201
202 Check-in 4 has a <b>branch</b> tag which changes the name of the branch
203 to "test". The branch tag on check-in 4 propagates to check-ins 6 and 9.
204 But because tag propagation does not follow merge links, the <b>branch=test</b>
205

Keyboard Shortcuts

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