Fossil SCM

Merged with trunk.

michael 2010-08-13 03:26 ttmrichter merge
Commit 7f61175d27790d71e5fa1488b4539533cbe83415
+7 -3
--- src/add.c
+++ src/add.c
@@ -39,12 +39,16 @@
3939
file_tree_name(zName, &pathname, 1);
4040
zPath = blob_str(&pathname);
4141
if( strcmp(zPath, "manifest")==0
4242
|| strcmp(zPath, "_FOSSIL_")==0
4343
|| strcmp(zPath, "_FOSSIL_-journal")==0
44
+ || strcmp(zPath, "_FOSSIL_-wal")==0
45
+ || strcmp(zPath, "_FOSSIL_-shm")==0
4446
|| strcmp(zPath, ".fos")==0
4547
|| strcmp(zPath, ".fos-journal")==0
48
+ || strcmp(zPath, ".fos-wal")==0
49
+ || strcmp(zPath, ".fos-shm")==0
4650
|| strcmp(zPath, "manifest.uuid")==0
4751
|| blob_compare(&pathname, pOmit)==0
4852
){
4953
fossil_warning("cannot add %s", zPath);
5054
}else{
@@ -223,22 +227,22 @@
223227
blob_reset(&path);
224228
}
225229
226230
/*
227231
** COMMAND: rm
228
-** COMMAND: del
232
+** COMMAND: delete
229233
**
230234
** Usage: %fossil rm FILE...
231
-** or: %fossil del FILE...
235
+** or: %fossil delete FILE...
232236
**
233237
** Remove one or more files from the tree.
234238
**
235239
** This command does not remove the files from disk. It just marks the
236240
** files as no longer being part of the project. In other words, future
237241
** changes to the named files will not be versioned.
238242
*/
239
-void del_cmd(void){
243
+void delete_cmd(void){
240244
int i;
241245
int vid;
242246
243247
db_must_be_within_tree();
244248
vid = db_lget_int("checkout", 0);
245249
--- src/add.c
+++ src/add.c
@@ -39,12 +39,16 @@
39 file_tree_name(zName, &pathname, 1);
40 zPath = blob_str(&pathname);
41 if( strcmp(zPath, "manifest")==0
42 || strcmp(zPath, "_FOSSIL_")==0
43 || strcmp(zPath, "_FOSSIL_-journal")==0
 
 
44 || strcmp(zPath, ".fos")==0
45 || strcmp(zPath, ".fos-journal")==0
 
 
46 || strcmp(zPath, "manifest.uuid")==0
47 || blob_compare(&pathname, pOmit)==0
48 ){
49 fossil_warning("cannot add %s", zPath);
50 }else{
@@ -223,22 +227,22 @@
223 blob_reset(&path);
224 }
225
226 /*
227 ** COMMAND: rm
228 ** COMMAND: del
229 **
230 ** Usage: %fossil rm FILE...
231 ** or: %fossil del FILE...
232 **
233 ** Remove one or more files from the tree.
234 **
235 ** This command does not remove the files from disk. It just marks the
236 ** files as no longer being part of the project. In other words, future
237 ** changes to the named files will not be versioned.
238 */
239 void del_cmd(void){
240 int i;
241 int vid;
242
243 db_must_be_within_tree();
244 vid = db_lget_int("checkout", 0);
245
--- src/add.c
+++ src/add.c
@@ -39,12 +39,16 @@
39 file_tree_name(zName, &pathname, 1);
40 zPath = blob_str(&pathname);
41 if( strcmp(zPath, "manifest")==0
42 || strcmp(zPath, "_FOSSIL_")==0
43 || strcmp(zPath, "_FOSSIL_-journal")==0
44 || strcmp(zPath, "_FOSSIL_-wal")==0
45 || strcmp(zPath, "_FOSSIL_-shm")==0
46 || strcmp(zPath, ".fos")==0
47 || strcmp(zPath, ".fos-journal")==0
48 || strcmp(zPath, ".fos-wal")==0
49 || strcmp(zPath, ".fos-shm")==0
50 || strcmp(zPath, "manifest.uuid")==0
51 || blob_compare(&pathname, pOmit)==0
52 ){
53 fossil_warning("cannot add %s", zPath);
54 }else{
@@ -223,22 +227,22 @@
227 blob_reset(&path);
228 }
229
230 /*
231 ** COMMAND: rm
232 ** COMMAND: delete
233 **
234 ** Usage: %fossil rm FILE...
235 ** or: %fossil delete FILE...
236 **
237 ** Remove one or more files from the tree.
238 **
239 ** This command does not remove the files from disk. It just marks the
240 ** files as no longer being part of the project. In other words, future
241 ** changes to the named files will not be versioned.
242 */
243 void delete_cmd(void){
244 int i;
245 int vid;
246
247 db_must_be_within_tree();
248 vid = db_lget_int("checkout", 0);
249
+6 -2
--- src/checkin.c
+++ src/checkin.c
@@ -271,11 +271,13 @@
271271
}
272272
vfile_scan(0, &path, blob_size(&path), allFlag);
273273
db_prepare(&q,
274274
"SELECT x FROM sfile"
275275
" WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
276
- "'_FOSSIL_-journal','.fos','.fos-journal')"
276
+ "'_FOSSIL_-journal','.fos','.fos-journal',"
277
+ "'_FOSSIL_-wal','_FOSSIL_-shm','.fos-wal',"
278
+ "'.fos-shm')"
277279
" AND NOT %s"
278280
" ORDER BY 1",
279281
glob_expr("x", zIgnoreFlag)
280282
);
281283
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -317,11 +319,13 @@
317319
blob_init(&path, g.zLocalRoot, n-1);
318320
vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
319321
db_prepare(&q,
320322
"SELECT %Q || x FROM sfile"
321323
" WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
322
- "'_FOSSIL_-journal','.fos','.fos-journal')"
324
+ "'_FOSSIL_-journal','.fos','.fos-journal',"
325
+ "'_FOSSIL_-wal','_FOSSIL_-shm','.fos-wal',"
326
+ "'.fos-shm')"
323327
" ORDER BY 1", g.zLocalRoot);
324328
if( file_tree_name(g.zRepositoryName, &repo, 0) ){
325329
db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
326330
}
327331
while( db_step(&q)==SQLITE_ROW ){
328332
--- src/checkin.c
+++ src/checkin.c
@@ -271,11 +271,13 @@
271 }
272 vfile_scan(0, &path, blob_size(&path), allFlag);
273 db_prepare(&q,
274 "SELECT x FROM sfile"
275 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
276 "'_FOSSIL_-journal','.fos','.fos-journal')"
 
 
277 " AND NOT %s"
278 " ORDER BY 1",
279 glob_expr("x", zIgnoreFlag)
280 );
281 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -317,11 +319,13 @@
317 blob_init(&path, g.zLocalRoot, n-1);
318 vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
319 db_prepare(&q,
320 "SELECT %Q || x FROM sfile"
321 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
322 "'_FOSSIL_-journal','.fos','.fos-journal')"
 
 
323 " ORDER BY 1", g.zLocalRoot);
324 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
325 db_multi_exec("DELETE FROM sfile WHERE x=%B", &repo);
326 }
327 while( db_step(&q)==SQLITE_ROW ){
328
--- src/checkin.c
+++ src/checkin.c
@@ -271,11 +271,13 @@
271 }
272 vfile_scan(0, &path, blob_size(&path), allFlag);
273 db_prepare(&q,
274 "SELECT x FROM sfile"
275 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
276 "'_FOSSIL_-journal','.fos','.fos-journal',"
277 "'_FOSSIL_-wal','_FOSSIL_-shm','.fos-wal',"
278 "'.fos-shm')"
279 " AND NOT %s"
280 " ORDER BY 1",
281 glob_expr("x", zIgnoreFlag)
282 );
283 if( file_tree_name(g.zRepositoryName, &repo, 0) ){
@@ -317,11 +319,13 @@
319 blob_init(&path, g.zLocalRoot, n-1);
320 vfile_scan(0, &path, blob_size(&path), dotfilesFlag);
321 db_prepare(&q,
322 "SELECT %Q || x FROM sfile"
323 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_',"
324 "'_FOSSIL_-journal','.fos','.fos-journal',"
325 "'_FOSSIL_-wal','_FOSSIL_-shm','.fos-wal',"
326 "'.fos-shm')"
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/checkout.c
+++ src/checkout.c
@@ -232,12 +232,16 @@
232232
*/
233233
void unlink_local_database(void){
234234
static const char *azFile[] = {
235235
"%s_FOSSIL_",
236236
"%s_FOSSIL_-journal",
237
+ "%s_FOSSIL_-wal",
238
+ "%s_FOSSIL_-shm",
237239
"%s.fos",
238240
"%s.fos-journal",
241
+ "%s.fos-wal",
242
+ "%s.fos-shm",
239243
};
240244
int i;
241245
for(i=0; i<sizeof(azFile)/sizeof(azFile[0]); i++){
242246
char *z = mprintf(azFile[i], g.zLocalRoot);
243247
unlink(z);
244248
--- src/checkout.c
+++ src/checkout.c
@@ -232,12 +232,16 @@
232 */
233 void unlink_local_database(void){
234 static const char *azFile[] = {
235 "%s_FOSSIL_",
236 "%s_FOSSIL_-journal",
 
 
237 "%s.fos",
238 "%s.fos-journal",
 
 
239 };
240 int i;
241 for(i=0; i<sizeof(azFile)/sizeof(azFile[0]); i++){
242 char *z = mprintf(azFile[i], g.zLocalRoot);
243 unlink(z);
244
--- src/checkout.c
+++ src/checkout.c
@@ -232,12 +232,16 @@
232 */
233 void unlink_local_database(void){
234 static const char *azFile[] = {
235 "%s_FOSSIL_",
236 "%s_FOSSIL_-journal",
237 "%s_FOSSIL_-wal",
238 "%s_FOSSIL_-shm",
239 "%s.fos",
240 "%s.fos-journal",
241 "%s.fos-wal",
242 "%s.fos-shm",
243 };
244 int i;
245 for(i=0; i<sizeof(azFile)/sizeof(azFile[0]); i++){
246 char *z = mprintf(azFile[i], g.zLocalRoot);
247 unlink(z);
248
+43 -2
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -271,11 +271,11 @@
271271
blob_reset(&content);
272272
}
273273
free(zFullName);
274274
}
275275
db_finalize(&q);
276
- db_end_transaction(1);
276
+ db_end_transaction(1); /* ROLLBACK */
277277
}
278278
279279
/*
280280
** Output the differences between two versions of a single file.
281281
** zFrom and zTo are the check-ins containing the two file versions.
@@ -305,10 +305,52 @@
305305
static void diff_all_two_versions(
306306
const char *zFrom,
307307
const char *zTo,
308308
const char *zDiffCmd
309309
){
310
+ Manifest mFrom, mTo;
311
+ int iFrom, iTo;
312
+
313
+ manifest_from_name(zFrom, &mFrom);
314
+ manifest_from_name(zTo, &mTo);
315
+ iFrom = iTo = 0;
316
+ while( iFrom<mFrom.nFile && iTo<mTo.nFile ){
317
+ int cmp;
318
+ if( iFrom>=mFrom.nFile ){
319
+ cmp = +1;
320
+ }else if( iTo>=mTo.nFile ){
321
+ cmp = -1;
322
+ }else{
323
+ cmp = strcmp(mFrom.aFile[iFrom].zName, mTo.aFile[iTo].zName);
324
+ }
325
+ if( cmp<0 ){
326
+ printf("DELETED %s\n", mFrom.aFile[iFrom].zName);
327
+ iFrom++;
328
+ }else if( cmp>0 ){
329
+ printf("ADDED %s\n", mTo.aFile[iTo].zName);
330
+ iTo++;
331
+ }else if( strcmp(mFrom.aFile[iFrom].zUuid, mTo.aFile[iTo].zUuid)==0 ){
332
+ /* No changes */
333
+ iFrom++;
334
+ iTo++;
335
+ }else{
336
+ Blob f1, f2;
337
+ int rid;
338
+ printf("CHANGED %s\n", mFrom.aFile[iFrom].zName);
339
+ rid = uuid_to_rid(mFrom.aFile[iFrom].zUuid, 0);
340
+ content_get(rid, &f1);
341
+ rid = uuid_to_rid(mTo.aFile[iTo].zUuid, 0);
342
+ content_get(rid, &f2);
343
+ diff_file_mem(&f1, &f2, mFrom.aFile[iFrom].zName, zDiffCmd);
344
+ blob_reset(&f1);
345
+ blob_reset(&f2);
346
+ iFrom++;
347
+ iTo++;
348
+ }
349
+ }
350
+ manifest_clear(&mFrom);
351
+ manifest_clear(&mTo);
310352
}
311353
312354
/*
313355
** COMMAND: diff
314356
** COMMAND: gdiff
@@ -366,10 +408,9 @@
366408
zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
367409
}
368410
if( g.argc==3 ){
369411
diff_one_two_versions(zFrom, zTo, zDiffCmd);
370412
}else{
371
- fossil_fatal("--to on complete check-ins not yet implemented");
372413
diff_all_two_versions(zFrom, zTo, zDiffCmd);
373414
}
374415
}
375416
}
376417
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -271,11 +271,11 @@
271 blob_reset(&content);
272 }
273 free(zFullName);
274 }
275 db_finalize(&q);
276 db_end_transaction(1);
277 }
278
279 /*
280 ** Output the differences between two versions of a single file.
281 ** zFrom and zTo are the check-ins containing the two file versions.
@@ -305,10 +305,52 @@
305 static void diff_all_two_versions(
306 const char *zFrom,
307 const char *zTo,
308 const char *zDiffCmd
309 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310 }
311
312 /*
313 ** COMMAND: diff
314 ** COMMAND: gdiff
@@ -366,10 +408,9 @@
366 zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
367 }
368 if( g.argc==3 ){
369 diff_one_two_versions(zFrom, zTo, zDiffCmd);
370 }else{
371 fossil_fatal("--to on complete check-ins not yet implemented");
372 diff_all_two_versions(zFrom, zTo, zDiffCmd);
373 }
374 }
375 }
376
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -271,11 +271,11 @@
271 blob_reset(&content);
272 }
273 free(zFullName);
274 }
275 db_finalize(&q);
276 db_end_transaction(1); /* ROLLBACK */
277 }
278
279 /*
280 ** Output the differences between two versions of a single file.
281 ** zFrom and zTo are the check-ins containing the two file versions.
@@ -305,10 +305,52 @@
305 static void diff_all_two_versions(
306 const char *zFrom,
307 const char *zTo,
308 const char *zDiffCmd
309 ){
310 Manifest mFrom, mTo;
311 int iFrom, iTo;
312
313 manifest_from_name(zFrom, &mFrom);
314 manifest_from_name(zTo, &mTo);
315 iFrom = iTo = 0;
316 while( iFrom<mFrom.nFile && iTo<mTo.nFile ){
317 int cmp;
318 if( iFrom>=mFrom.nFile ){
319 cmp = +1;
320 }else if( iTo>=mTo.nFile ){
321 cmp = -1;
322 }else{
323 cmp = strcmp(mFrom.aFile[iFrom].zName, mTo.aFile[iTo].zName);
324 }
325 if( cmp<0 ){
326 printf("DELETED %s\n", mFrom.aFile[iFrom].zName);
327 iFrom++;
328 }else if( cmp>0 ){
329 printf("ADDED %s\n", mTo.aFile[iTo].zName);
330 iTo++;
331 }else if( strcmp(mFrom.aFile[iFrom].zUuid, mTo.aFile[iTo].zUuid)==0 ){
332 /* No changes */
333 iFrom++;
334 iTo++;
335 }else{
336 Blob f1, f2;
337 int rid;
338 printf("CHANGED %s\n", mFrom.aFile[iFrom].zName);
339 rid = uuid_to_rid(mFrom.aFile[iFrom].zUuid, 0);
340 content_get(rid, &f1);
341 rid = uuid_to_rid(mTo.aFile[iTo].zUuid, 0);
342 content_get(rid, &f2);
343 diff_file_mem(&f1, &f2, mFrom.aFile[iFrom].zName, zDiffCmd);
344 blob_reset(&f1);
345 blob_reset(&f2);
346 iFrom++;
347 iTo++;
348 }
349 }
350 manifest_clear(&mFrom);
351 manifest_clear(&mTo);
352 }
353
354 /*
355 ** COMMAND: diff
356 ** COMMAND: gdiff
@@ -366,10 +408,9 @@
408 zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
409 }
410 if( g.argc==3 ){
411 diff_one_two_versions(zFrom, zTo, zDiffCmd);
412 }else{
 
413 diff_all_two_versions(zFrom, zTo, zDiffCmd);
414 }
415 }
416 }
417
+160 -88
--- src/info.c
+++ src/info.c
@@ -238,10 +238,51 @@
238238
blob_reset(&from);
239239
blob_reset(&to);
240240
blob_reset(&out);
241241
}
242242
243
+/*
244
+** Write a line of web-page output that shows changes that have occurred
245
+** to a file between two check-ins.
246
+*/
247
+static void append_file_change_line(
248
+ const char *zName, /* Name of the file that has changed */
249
+ const char *zOld, /* blob.uuid before change. NULL for added files */
250
+ const char *zNew, /* blob.uuid after change. NULL for deletes */
251
+ int showDiff /* Show edit diffs if true */
252
+){
253
+ if( !g.okHistory ){
254
+ if( zNew==0 ){
255
+ @ <p>Deleted %h(zName)</p>
256
+ }else if( zOld==0 ){
257
+ @ <p>Added %h(zName)</p>
258
+ }else{
259
+ @ <p>Changes to %h(zName)</p>
260
+ }
261
+ }else if( zOld && zNew ){
262
+ @ <p>Modified <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
263
+ @ from <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a>
264
+ @ to <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)].</a>
265
+ if( !showDiff ){
266
+ @ &nbsp;&nbsp;
267
+ @ <a href="%s(g.zTop)/fdiff?v1=%S(zOld)&v2=%S(zNew)">[diff]</a>
268
+ }else{
269
+ int rid1 = uuid_to_rid(zOld, 0);
270
+ int rid2 = uuid_to_rid(zNew, 0);
271
+ @ <blockquote><pre>
272
+ append_diff(rid1, rid2);
273
+ @ </pre></blockquote>
274
+ }
275
+ }else if( zOld ){
276
+ @ <p>Deleted <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
277
+ @ version <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a></p>
278
+ }else{
279
+ @ <p>Added <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
280
+ @ version <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)]</a></p>
281
+ }
282
+}
283
+
243284
244285
/*
245286
** WEBPAGE: vinfo
246287
** WEBPAGE: ci
247288
** URL: /ci?name=RID|ARTIFACTID
@@ -391,52 +432,23 @@
391432
}else{
392433
@ <a href="%s(g.zBaseURL)/vinfo/%T(zName)">[show&nbsp;diffs]</a><br/>
393434
}
394435
}
395436
db_prepare(&q,
396
- "SELECT pid, fid, name,"
437
+ "SELECT name,"
397438
" (SELECT uuid FROM blob WHERE rid=mlink.pid),"
398439
" (SELECT uuid FROM blob WHERE rid=mlink.fid)"
399440
" FROM mlink JOIN filename ON filename.fnid=mlink.fnid"
400441
" WHERE mlink.mid=%d"
401442
" ORDER BY name",
402443
rid
403444
);
404445
while( db_step(&q)==SQLITE_ROW ){
405
- int pid = db_column_int(&q,0);
406
- int fid = db_column_int(&q,1);
407
- const char *zName = db_column_text(&q,2);
408
- const char *zOld = db_column_text(&q,3);
409
- const char *zNew = db_column_text(&q,4);
410
- if( !g.okHistory ){
411
- if( zNew==0 ){
412
- @ <p>Deleted %h(zName)</p>
413
- continue;
414
- }else{
415
- @ <p>Changes to %h(zName)</p>
416
- }
417
- }else if( zOld && zNew ){
418
- @ <p>Modified <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
419
- @ from <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a>
420
- @ to <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)].</a>
421
- if( !showDiff ){
422
- @ &nbsp;&nbsp;
423
- @ <a href="%s(g.zTop)/fdiff?v1=%S(zOld)&v2=%S(zNew)">[diff]</a>
424
- }
425
- }else if( zOld ){
426
- @ <p>Deleted <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
427
- @ version <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a></p>
428
- continue;
429
- }else{
430
- @ <p>Added <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
431
- @ version <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)]</a></p>
432
- }
433
- if( showDiff ){
434
- @ <blockquote><pre>
435
- append_diff(pid, fid);
436
- @ </pre></blockquote>
437
- }
446
+ const char *zName = db_column_text(&q,0);
447
+ const char *zOld = db_column_text(&q,1);
448
+ const char *zNew = db_column_text(&q,2);
449
+ append_file_change_line(zName, zOld, zNew, showDiff);
438450
}
439451
db_finalize(&q);
440452
style_footer();
441453
}
442454
@@ -520,76 +532,135 @@
520532
}
521533
manifest_clear(&m);
522534
}
523535
style_footer();
524536
}
537
+
538
+/*
539
+** Show a webpage error message
540
+*/
541
+void webpage_error(const char *zFormat, ...){
542
+ va_list ap;
543
+ const char *z;
544
+ va_start(ap, zFormat);
545
+ z = vmprintf(zFormat, ap);
546
+ va_end(ap);
547
+ style_header("URL Error");
548
+ @ <h1>Error</h1>
549
+ @ <p>%h(z)</p>
550
+ style_footer();
551
+}
552
+
553
+/*
554
+** Find an checkin based on query parameter zParam and parse its
555
+** manifest. Return the number of errors.
556
+*/
557
+static int vdiff_parse_manifest(const char *zParam, int *pRid, Manifest *pM){
558
+ int rid;
559
+ Blob content;
560
+
561
+ *pRid = rid = name_to_rid_www(zParam);
562
+ if( rid==0 ){
563
+ webpage_error("Missing \"%s\" query parameter.", zParam);
564
+ return 1;
565
+ }
566
+ if( !is_a_version(rid) ){
567
+ webpage_error("Artifact %s is not a checkin.", P(zParam));
568
+ return 1;
569
+ }
570
+ content_get(rid, &content);
571
+ manifest_parse(pM, &content);
572
+ return 0;
573
+}
574
+
575
+/*
576
+** Output a description of a check-in
577
+*/
578
+void checkin_description(int rid){
579
+ Stmt q;
580
+ db_prepare(&q,
581
+ "SELECT datetime(mtime), coalesce(euser,user),"
582
+ " coalesce(ecomment,comment), uuid"
583
+ " FROM event, blob"
584
+ " WHERE event.objid=%d AND type='ci'"
585
+ " AND blob.rid=%d",
586
+ rid, rid
587
+ );
588
+ while( db_step(&q)==SQLITE_ROW ){
589
+ const char *zDate = db_column_text(&q, 0);
590
+ const char *zUser = db_column_text(&q, 1);
591
+ const char *zCom = db_column_text(&q, 2);
592
+ const char *zUuid = db_column_text(&q, 3);
593
+ @ Check-in
594
+ hyperlink_to_uuid(zUuid);
595
+ @ - %w(zCom) by
596
+ hyperlink_to_user(zUser,zDate," on");
597
+ hyperlink_to_date(zDate, ".");
598
+ }
599
+ db_finalize(&q);
600
+}
601
+
525602
526603
/*
527604
** WEBPAGE: vdiff
528
-** URL: /vdiff?name=RID
605
+** URL: /vdiff?from=UUID&to=UUID&detail=BOOLEAN
529606
**
530
-** Show all differences for a particular check-in.
607
+** Show all differences between two checkins.
531608
*/
532609
void vdiff_page(void){
533
- int rid;
534
- Stmt q;
535
- char *zUuid;
610
+ int ridFrom, ridTo;
611
+ int showDetail = 0;
612
+ int iFrom, iTo;
613
+ Manifest mFrom, mTo;
536614
537615
login_check_credentials();
538616
if( !g.okRead ){ login_needed(); return; }
539617
login_anonymous_available();
540618
541
- rid = name_to_rid_www("name");
542
- if( rid==0 ){
543
- fossil_redirect_home();
544
- }
545
- zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
546
- style_header("Check-in [%.10s]", zUuid);
547
- db_prepare(&q,
548
- "SELECT datetime(mtime), "
549
- " coalesce(event.ecomment,event.comment),"
550
- " coalesce(event.euser,event.user)"
551
- " FROM event WHERE type='ci' AND objid=%d",
552
- rid
553
- );
554
- while( db_step(&q)==SQLITE_ROW ){
555
- const char *zDate = db_column_text(&q, 0);
556
- const char *zUser = db_column_text(&q, 2);
557
- const char *zComment = db_column_text(&q, 1);
558
- @ <h2>Check-in %s(zUuid)</h2>
559
- @ <p>Made by
560
- hyperlink_to_user(zUser,zDate," on");
561
- hyperlink_to_date(zDate, ":");
562
- @ %w(zComment).
563
- if( g.okHistory ){
564
- @ <a href="%s(g.zBaseURL)/ci/%s(zUuid)">[details]</a>
565
- }
566
- @ </p><hr>
567
- }
568
- db_finalize(&q);
569
- db_prepare(&q,
570
- "SELECT pid, fid, name"
571
- " FROM mlink, filename"
572
- " WHERE mlink.mid=%d"
573
- " AND filename.fnid=mlink.fnid"
574
- " ORDER BY name",
575
- rid
576
- );
577
- while( db_step(&q)==SQLITE_ROW ){
578
- int pid = db_column_int(&q,0);
579
- int fid = db_column_int(&q,1);
580
- const char *zName = db_column_text(&q,2);
581
- if( g.okHistory ){
582
- @ <p><a href="%s(g.zBaseURL)/finfo?name=%T(zName)">%h(zName)</a></p>
619
+ if( vdiff_parse_manifest("from", &ridFrom, &mFrom) ) return;
620
+ if( vdiff_parse_manifest("to", &ridTo, &mTo) ) return;
621
+ showDetail = atoi(PD("detail","0"));
622
+ style_header("Check-in Differences");
623
+ @ <h2>Difference From:</h2><blockquote>
624
+ checkin_description(ridFrom);
625
+ @ </blockquote><h2>To:</h2><blockquote>
626
+ checkin_description(ridTo);
627
+ @ </blockquote><hr><p>
628
+
629
+ iFrom = iTo = 0;
630
+ while( iFrom<mFrom.nFile && iTo<mTo.nFile ){
631
+ int cmp;
632
+ if( iFrom>=mFrom.nFile ){
633
+ cmp = +1;
634
+ }else if( iTo>=mTo.nFile ){
635
+ cmp = -1;
636
+ }else{
637
+ cmp = strcmp(mFrom.aFile[iFrom].zName, mTo.aFile[iTo].zName);
638
+ }
639
+ if( cmp<0 ){
640
+ append_file_change_line(mFrom.aFile[iFrom].zName,
641
+ mFrom.aFile[iFrom].zUuid, 0, 0);
642
+ iFrom++;
643
+ }else if( cmp>0 ){
644
+ append_file_change_line(mTo.aFile[iTo].zName,
645
+ 0, mTo.aFile[iTo].zUuid, 0);
646
+ iTo++;
647
+ }else if( strcmp(mFrom.aFile[iFrom].zUuid, mTo.aFile[iTo].zUuid)==0 ){
648
+ /* No changes */
649
+ iFrom++;
650
+ iTo++;
583651
}else{
584
- @ <p>%h(zName)</p>
652
+ append_file_change_line(mFrom.aFile[iFrom].zName,
653
+ mFrom.aFile[iFrom].zUuid,
654
+ mTo.aFile[iTo].zUuid, showDetail);
655
+ iFrom++;
656
+ iTo++;
585657
}
586
- @ <blockquote><pre>
587
- append_diff(pid, fid);
588
- @ </pre></blockquote>
589658
}
590
- db_finalize(&q);
659
+ manifest_clear(&mFrom);
660
+ manifest_clear(&mTo);
661
+
591662
style_footer();
592663
}
593664
594665
/*
595666
** Write a description of an object to the www reply.
@@ -783,16 +854,17 @@
783854
**
784855
** Two arguments, v1 and v2, are integers. Show the difference between
785856
** the two records.
786857
*/
787858
void diff_page(void){
788
- int v1 = name_to_rid(P("v1"));
789
- int v2 = name_to_rid(P("v2"));
859
+ int v1, v2;
790860
Blob c1, c2, diff;
791861
792862
login_check_credentials();
793863
if( !g.okRead ){ login_needed(); return; }
864
+ v1 = name_to_rid_www("v1");
865
+ v2 = name_to_rid_www("v2");
794866
if( v1==0 || v2==0 ) fossil_redirect_home();
795867
style_header("Diff");
796868
@ <h2>Differences From:</h2>
797869
@ <blockquote>
798870
object_description(v1, 1, 0);
799871
--- src/info.c
+++ src/info.c
@@ -238,10 +238,51 @@
238 blob_reset(&from);
239 blob_reset(&to);
240 blob_reset(&out);
241 }
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
244 /*
245 ** WEBPAGE: vinfo
246 ** WEBPAGE: ci
247 ** URL: /ci?name=RID|ARTIFACTID
@@ -391,52 +432,23 @@
391 }else{
392 @ <a href="%s(g.zBaseURL)/vinfo/%T(zName)">[show&nbsp;diffs]</a><br/>
393 }
394 }
395 db_prepare(&q,
396 "SELECT pid, fid, name,"
397 " (SELECT uuid FROM blob WHERE rid=mlink.pid),"
398 " (SELECT uuid FROM blob WHERE rid=mlink.fid)"
399 " FROM mlink JOIN filename ON filename.fnid=mlink.fnid"
400 " WHERE mlink.mid=%d"
401 " ORDER BY name",
402 rid
403 );
404 while( db_step(&q)==SQLITE_ROW ){
405 int pid = db_column_int(&q,0);
406 int fid = db_column_int(&q,1);
407 const char *zName = db_column_text(&q,2);
408 const char *zOld = db_column_text(&q,3);
409 const char *zNew = db_column_text(&q,4);
410 if( !g.okHistory ){
411 if( zNew==0 ){
412 @ <p>Deleted %h(zName)</p>
413 continue;
414 }else{
415 @ <p>Changes to %h(zName)</p>
416 }
417 }else if( zOld && zNew ){
418 @ <p>Modified <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
419 @ from <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a>
420 @ to <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)].</a>
421 if( !showDiff ){
422 @ &nbsp;&nbsp;
423 @ <a href="%s(g.zTop)/fdiff?v1=%S(zOld)&v2=%S(zNew)">[diff]</a>
424 }
425 }else if( zOld ){
426 @ <p>Deleted <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
427 @ version <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a></p>
428 continue;
429 }else{
430 @ <p>Added <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
431 @ version <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)]</a></p>
432 }
433 if( showDiff ){
434 @ <blockquote><pre>
435 append_diff(pid, fid);
436 @ </pre></blockquote>
437 }
438 }
439 db_finalize(&q);
440 style_footer();
441 }
442
@@ -520,76 +532,135 @@
520 }
521 manifest_clear(&m);
522 }
523 style_footer();
524 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
526 /*
527 ** WEBPAGE: vdiff
528 ** URL: /vdiff?name=RID
529 **
530 ** Show all differences for a particular check-in.
531 */
532 void vdiff_page(void){
533 int rid;
534 Stmt q;
535 char *zUuid;
 
536
537 login_check_credentials();
538 if( !g.okRead ){ login_needed(); return; }
539 login_anonymous_available();
540
541 rid = name_to_rid_www("name");
542 if( rid==0 ){
543 fossil_redirect_home();
544 }
545 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
546 style_header("Check-in [%.10s]", zUuid);
547 db_prepare(&q,
548 "SELECT datetime(mtime), "
549 " coalesce(event.ecomment,event.comment),"
550 " coalesce(event.euser,event.user)"
551 " FROM event WHERE type='ci' AND objid=%d",
552 rid
553 );
554 while( db_step(&q)==SQLITE_ROW ){
555 const char *zDate = db_column_text(&q, 0);
556 const char *zUser = db_column_text(&q, 2);
557 const char *zComment = db_column_text(&q, 1);
558 @ <h2>Check-in %s(zUuid)</h2>
559 @ <p>Made by
560 hyperlink_to_user(zUser,zDate," on");
561 hyperlink_to_date(zDate, ":");
562 @ %w(zComment).
563 if( g.okHistory ){
564 @ <a href="%s(g.zBaseURL)/ci/%s(zUuid)">[details]</a>
565 }
566 @ </p><hr>
567 }
568 db_finalize(&q);
569 db_prepare(&q,
570 "SELECT pid, fid, name"
571 " FROM mlink, filename"
572 " WHERE mlink.mid=%d"
573 " AND filename.fnid=mlink.fnid"
574 " ORDER BY name",
575 rid
576 );
577 while( db_step(&q)==SQLITE_ROW ){
578 int pid = db_column_int(&q,0);
579 int fid = db_column_int(&q,1);
580 const char *zName = db_column_text(&q,2);
581 if( g.okHistory ){
582 @ <p><a href="%s(g.zBaseURL)/finfo?name=%T(zName)">%h(zName)</a></p>
583 }else{
584 @ <p>%h(zName)</p>
 
 
 
 
585 }
586 @ <blockquote><pre>
587 append_diff(pid, fid);
588 @ </pre></blockquote>
589 }
590 db_finalize(&q);
 
 
591 style_footer();
592 }
593
594 /*
595 ** Write a description of an object to the www reply.
@@ -783,16 +854,17 @@
783 **
784 ** Two arguments, v1 and v2, are integers. Show the difference between
785 ** the two records.
786 */
787 void diff_page(void){
788 int v1 = name_to_rid(P("v1"));
789 int v2 = name_to_rid(P("v2"));
790 Blob c1, c2, diff;
791
792 login_check_credentials();
793 if( !g.okRead ){ login_needed(); return; }
 
 
794 if( v1==0 || v2==0 ) fossil_redirect_home();
795 style_header("Diff");
796 @ <h2>Differences From:</h2>
797 @ <blockquote>
798 object_description(v1, 1, 0);
799
--- src/info.c
+++ src/info.c
@@ -238,10 +238,51 @@
238 blob_reset(&from);
239 blob_reset(&to);
240 blob_reset(&out);
241 }
242
243 /*
244 ** Write a line of web-page output that shows changes that have occurred
245 ** to a file between two check-ins.
246 */
247 static void append_file_change_line(
248 const char *zName, /* Name of the file that has changed */
249 const char *zOld, /* blob.uuid before change. NULL for added files */
250 const char *zNew, /* blob.uuid after change. NULL for deletes */
251 int showDiff /* Show edit diffs if true */
252 ){
253 if( !g.okHistory ){
254 if( zNew==0 ){
255 @ <p>Deleted %h(zName)</p>
256 }else if( zOld==0 ){
257 @ <p>Added %h(zName)</p>
258 }else{
259 @ <p>Changes to %h(zName)</p>
260 }
261 }else if( zOld && zNew ){
262 @ <p>Modified <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
263 @ from <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a>
264 @ to <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)].</a>
265 if( !showDiff ){
266 @ &nbsp;&nbsp;
267 @ <a href="%s(g.zTop)/fdiff?v1=%S(zOld)&v2=%S(zNew)">[diff]</a>
268 }else{
269 int rid1 = uuid_to_rid(zOld, 0);
270 int rid2 = uuid_to_rid(zNew, 0);
271 @ <blockquote><pre>
272 append_diff(rid1, rid2);
273 @ </pre></blockquote>
274 }
275 }else if( zOld ){
276 @ <p>Deleted <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
277 @ version <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a></p>
278 }else{
279 @ <p>Added <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
280 @ version <a href="%s(g.zTop)/artifact/%s(zNew)">[%S(zNew)]</a></p>
281 }
282 }
283
284
285 /*
286 ** WEBPAGE: vinfo
287 ** WEBPAGE: ci
288 ** URL: /ci?name=RID|ARTIFACTID
@@ -391,52 +432,23 @@
432 }else{
433 @ <a href="%s(g.zBaseURL)/vinfo/%T(zName)">[show&nbsp;diffs]</a><br/>
434 }
435 }
436 db_prepare(&q,
437 "SELECT name,"
438 " (SELECT uuid FROM blob WHERE rid=mlink.pid),"
439 " (SELECT uuid FROM blob WHERE rid=mlink.fid)"
440 " FROM mlink JOIN filename ON filename.fnid=mlink.fnid"
441 " WHERE mlink.mid=%d"
442 " ORDER BY name",
443 rid
444 );
445 while( db_step(&q)==SQLITE_ROW ){
446 const char *zName = db_column_text(&q,0);
447 const char *zOld = db_column_text(&q,1);
448 const char *zNew = db_column_text(&q,2);
449 append_file_change_line(zName, zOld, zNew, showDiff);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450 }
451 db_finalize(&q);
452 style_footer();
453 }
454
@@ -520,76 +532,135 @@
532 }
533 manifest_clear(&m);
534 }
535 style_footer();
536 }
537
538 /*
539 ** Show a webpage error message
540 */
541 void webpage_error(const char *zFormat, ...){
542 va_list ap;
543 const char *z;
544 va_start(ap, zFormat);
545 z = vmprintf(zFormat, ap);
546 va_end(ap);
547 style_header("URL Error");
548 @ <h1>Error</h1>
549 @ <p>%h(z)</p>
550 style_footer();
551 }
552
553 /*
554 ** Find an checkin based on query parameter zParam and parse its
555 ** manifest. Return the number of errors.
556 */
557 static int vdiff_parse_manifest(const char *zParam, int *pRid, Manifest *pM){
558 int rid;
559 Blob content;
560
561 *pRid = rid = name_to_rid_www(zParam);
562 if( rid==0 ){
563 webpage_error("Missing \"%s\" query parameter.", zParam);
564 return 1;
565 }
566 if( !is_a_version(rid) ){
567 webpage_error("Artifact %s is not a checkin.", P(zParam));
568 return 1;
569 }
570 content_get(rid, &content);
571 manifest_parse(pM, &content);
572 return 0;
573 }
574
575 /*
576 ** Output a description of a check-in
577 */
578 void checkin_description(int rid){
579 Stmt q;
580 db_prepare(&q,
581 "SELECT datetime(mtime), coalesce(euser,user),"
582 " coalesce(ecomment,comment), uuid"
583 " FROM event, blob"
584 " WHERE event.objid=%d AND type='ci'"
585 " AND blob.rid=%d",
586 rid, rid
587 );
588 while( db_step(&q)==SQLITE_ROW ){
589 const char *zDate = db_column_text(&q, 0);
590 const char *zUser = db_column_text(&q, 1);
591 const char *zCom = db_column_text(&q, 2);
592 const char *zUuid = db_column_text(&q, 3);
593 @ Check-in
594 hyperlink_to_uuid(zUuid);
595 @ - %w(zCom) by
596 hyperlink_to_user(zUser,zDate," on");
597 hyperlink_to_date(zDate, ".");
598 }
599 db_finalize(&q);
600 }
601
602
603 /*
604 ** WEBPAGE: vdiff
605 ** URL: /vdiff?from=UUID&to=UUID&detail=BOOLEAN
606 **
607 ** Show all differences between two checkins.
608 */
609 void vdiff_page(void){
610 int ridFrom, ridTo;
611 int showDetail = 0;
612 int iFrom, iTo;
613 Manifest mFrom, mTo;
614
615 login_check_credentials();
616 if( !g.okRead ){ login_needed(); return; }
617 login_anonymous_available();
618
619 if( vdiff_parse_manifest("from", &ridFrom, &mFrom) ) return;
620 if( vdiff_parse_manifest("to", &ridTo, &mTo) ) return;
621 showDetail = atoi(PD("detail","0"));
622 style_header("Check-in Differences");
623 @ <h2>Difference From:</h2><blockquote>
624 checkin_description(ridFrom);
625 @ </blockquote><h2>To:</h2><blockquote>
626 checkin_description(ridTo);
627 @ </blockquote><hr><p>
628
629 iFrom = iTo = 0;
630 while( iFrom<mFrom.nFile && iTo<mTo.nFile ){
631 int cmp;
632 if( iFrom>=mFrom.nFile ){
633 cmp = +1;
634 }else if( iTo>=mTo.nFile ){
635 cmp = -1;
636 }else{
637 cmp = strcmp(mFrom.aFile[iFrom].zName, mTo.aFile[iTo].zName);
638 }
639 if( cmp<0 ){
640 append_file_change_line(mFrom.aFile[iFrom].zName,
641 mFrom.aFile[iFrom].zUuid, 0, 0);
642 iFrom++;
643 }else if( cmp>0 ){
644 append_file_change_line(mTo.aFile[iTo].zName,
645 0, mTo.aFile[iTo].zUuid, 0);
646 iTo++;
647 }else if( strcmp(mFrom.aFile[iFrom].zUuid, mTo.aFile[iTo].zUuid)==0 ){
648 /* No changes */
649 iFrom++;
650 iTo++;
 
 
 
 
 
 
 
 
 
 
651 }else{
652 append_file_change_line(mFrom.aFile[iFrom].zName,
653 mFrom.aFile[iFrom].zUuid,
654 mTo.aFile[iTo].zUuid, showDetail);
655 iFrom++;
656 iTo++;
657 }
 
 
 
658 }
659 manifest_clear(&mFrom);
660 manifest_clear(&mTo);
661
662 style_footer();
663 }
664
665 /*
666 ** Write a description of an object to the www reply.
@@ -783,16 +854,17 @@
854 **
855 ** Two arguments, v1 and v2, are integers. Show the difference between
856 ** the two records.
857 */
858 void diff_page(void){
859 int v1, v2;
 
860 Blob c1, c2, diff;
861
862 login_check_credentials();
863 if( !g.okRead ){ login_needed(); return; }
864 v1 = name_to_rid_www("v1");
865 v2 = name_to_rid_www("v2");
866 if( v1==0 || v2==0 ) fossil_redirect_home();
867 style_header("Diff");
868 @ <h2>Differences From:</h2>
869 @ <blockquote>
870 object_description(v1, 1, 0);
871
--- src/manifest.c
+++ src/manifest.c
@@ -1174,5 +1174,26 @@
11741174
}
11751175
db_end_transaction(0);
11761176
manifest_clear(&m);
11771177
return 1;
11781178
}
1179
+
1180
+/*
1181
+** Given a checkin name, load and parse the manifest for that checkin.
1182
+** Throw a fatal error if anything goes wrong.
1183
+*/
1184
+void manifest_from_name(
1185
+ const char *zName,
1186
+ Manifest *pM
1187
+){
1188
+ int rid;
1189
+ Blob content;
1190
+
1191
+ rid = name_to_rid(zName);
1192
+ if( !is_a_version(rid) ){
1193
+ fossil_fatal("no such checkin: %s", zName);
1194
+ }
1195
+ content_get(rid, &content);
1196
+ if( !manifest_parse(pM, &content) ){
1197
+ fossil_fatal("cannot parse manifest for checkin: %s", zName);
1198
+ }
1199
+}
11791200
--- src/manifest.c
+++ src/manifest.c
@@ -1174,5 +1174,26 @@
1174 }
1175 db_end_transaction(0);
1176 manifest_clear(&m);
1177 return 1;
1178 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1179
--- src/manifest.c
+++ src/manifest.c
@@ -1174,5 +1174,26 @@
1174 }
1175 db_end_transaction(0);
1176 manifest_clear(&m);
1177 return 1;
1178 }
1179
1180 /*
1181 ** Given a checkin name, load and parse the manifest for that checkin.
1182 ** Throw a fatal error if anything goes wrong.
1183 */
1184 void manifest_from_name(
1185 const char *zName,
1186 Manifest *pM
1187 ){
1188 int rid;
1189 Blob content;
1190
1191 rid = name_to_rid(zName);
1192 if( !is_a_version(rid) ){
1193 fossil_fatal("no such checkin: %s", zName);
1194 }
1195 content_get(rid, &content);
1196 if( !manifest_parse(pM, &content) ){
1197 fossil_fatal("cannot parse manifest for checkin: %s", zName);
1198 }
1199 }
1200
--- src/rebuild.c
+++ src/rebuild.c
@@ -18,10 +18,12 @@
1818
** This file contains code used to rebuild the database.
1919
*/
2020
#include "config.h"
2121
#include "rebuild.h"
2222
#include <assert.h>
23
+#include <dirent.h>
24
+#include <errno.h>
2325
2426
/*
2527
** Schema changes
2628
*/
2729
static const char zSchemaUpdates[] =
@@ -399,5 +401,64 @@
399401
}else{
400402
rebuild_db(0, 1);
401403
db_end_transaction(0);
402404
}
403405
}
406
+
407
+/*
408
+** COMMAND: reconstruct
409
+**
410
+** Usage: %fossil reconstruct FILENAME DIRECTORY
411
+**
412
+** This command studies the artifacts (files) in DIRECTORY and
413
+** reconstructs the fossil record from them. It places the new
414
+** fossil repository in FILENAME
415
+**
416
+*/
417
+void reconstruct_cmd(void) {
418
+ char *zPassword;
419
+ DIR *d;
420
+ struct dirent *pEntry;
421
+ Blob aContent; /* content of the just read artifact */
422
+ if( g.argc!=4 ){
423
+ usage("FILENAME DIRECTORY");
424
+ }
425
+ if( file_isdir(g.argv[3])!=1 ){
426
+ printf("\"%s\" is not a directory\n\n", g.argv[3]);
427
+ usage("FILENAME DIRECTORY");
428
+ }
429
+ db_create_repository(g.argv[2]);
430
+ db_open_repository(g.argv[2]);
431
+ db_open_config(0);
432
+ db_begin_transaction();
433
+ db_initial_setup(0, 0, 1);
434
+
435
+ d = opendir(g.argv[3]);
436
+ if( d ){
437
+ while( (pEntry=readdir(d))!=0 ){
438
+ Blob path;
439
+ blob_init(&path, 0, 0);
440
+ if( pEntry->d_name[0]=='.' ){
441
+ continue;
442
+ }
443
+ if( file_isdir(pEntry->d_name)==1 ){
444
+ continue;
445
+ }
446
+ blob_appendf(&path, "%s/%s", g.argv[3], pEntry->d_name);
447
+ if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
448
+ fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
449
+ }
450
+ content_put(&aContent, 0, 0);
451
+ }
452
+ }
453
+ else {
454
+ fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[3]);
455
+ }
456
+
457
+ rebuild_db(0, 1);
458
+
459
+ db_end_transaction(0);
460
+ printf("project-id: %s\n", db_get("project-code", 0));
461
+ printf("server-id: %s\n", db_get("server-code", 0));
462
+ zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
463
+ printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
464
+}
404465
--- src/rebuild.c
+++ src/rebuild.c
@@ -18,10 +18,12 @@
18 ** This file contains code used to rebuild the database.
19 */
20 #include "config.h"
21 #include "rebuild.h"
22 #include <assert.h>
 
 
23
24 /*
25 ** Schema changes
26 */
27 static const char zSchemaUpdates[] =
@@ -399,5 +401,64 @@
399 }else{
400 rebuild_db(0, 1);
401 db_end_transaction(0);
402 }
403 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
--- src/rebuild.c
+++ src/rebuild.c
@@ -18,10 +18,12 @@
18 ** This file contains code used to rebuild the database.
19 */
20 #include "config.h"
21 #include "rebuild.h"
22 #include <assert.h>
23 #include <dirent.h>
24 #include <errno.h>
25
26 /*
27 ** Schema changes
28 */
29 static const char zSchemaUpdates[] =
@@ -399,5 +401,64 @@
401 }else{
402 rebuild_db(0, 1);
403 db_end_transaction(0);
404 }
405 }
406
407 /*
408 ** COMMAND: reconstruct
409 **
410 ** Usage: %fossil reconstruct FILENAME DIRECTORY
411 **
412 ** This command studies the artifacts (files) in DIRECTORY and
413 ** reconstructs the fossil record from them. It places the new
414 ** fossil repository in FILENAME
415 **
416 */
417 void reconstruct_cmd(void) {
418 char *zPassword;
419 DIR *d;
420 struct dirent *pEntry;
421 Blob aContent; /* content of the just read artifact */
422 if( g.argc!=4 ){
423 usage("FILENAME DIRECTORY");
424 }
425 if( file_isdir(g.argv[3])!=1 ){
426 printf("\"%s\" is not a directory\n\n", g.argv[3]);
427 usage("FILENAME DIRECTORY");
428 }
429 db_create_repository(g.argv[2]);
430 db_open_repository(g.argv[2]);
431 db_open_config(0);
432 db_begin_transaction();
433 db_initial_setup(0, 0, 1);
434
435 d = opendir(g.argv[3]);
436 if( d ){
437 while( (pEntry=readdir(d))!=0 ){
438 Blob path;
439 blob_init(&path, 0, 0);
440 if( pEntry->d_name[0]=='.' ){
441 continue;
442 }
443 if( file_isdir(pEntry->d_name)==1 ){
444 continue;
445 }
446 blob_appendf(&path, "%s/%s", g.argv[3], pEntry->d_name);
447 if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
448 fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
449 }
450 content_put(&aContent, 0, 0);
451 }
452 }
453 else {
454 fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[3]);
455 }
456
457 rebuild_db(0, 1);
458
459 db_end_transaction(0);
460 printf("project-id: %s\n", db_get("project-code", 0));
461 printf("server-id: %s\n", db_get("server-code", 0));
462 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
463 printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
464 }
465
+1061 -794
--- 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.7.0. By combining all the individual C code files into this
3
+** version 3.7.1. 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.
@@ -641,13 +641,13 @@
641641
**
642642
** See also: [sqlite3_libversion()],
643643
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
644644
** [sqlite_version()] and [sqlite_source_id()].
645645
*/
646
-#define SQLITE_VERSION "3.7.0"
647
-#define SQLITE_VERSION_NUMBER 3007000
648
-#define SQLITE_SOURCE_ID "2010-07-21 16:16:28 b36b105eab6fd3195f4bfba6cb5cda0f063b7460"
646
+#define SQLITE_VERSION "3.7.1"
647
+#define SQLITE_VERSION_NUMBER 3007001
648
+#define SQLITE_SOURCE_ID "2010-08-05 03:21:40 fbe70e1106bcc5086ceb9d8f39cc39baf3643092"
649649
650650
/*
651651
** CAPI3REF: Run-Time Library Version Numbers
652652
** KEYWORDS: sqlite3_version, sqlite3_sourceid
653653
**
@@ -2710,11 +2710,17 @@
27102710
** contain a UTF-8 SQL comment that identifies the trigger.)^
27112711
**
27122712
** ^The callback function registered by sqlite3_profile() is invoked
27132713
** as each SQL statement finishes. ^The profile callback contains
27142714
** the original statement text and an estimate of wall-clock time
2715
-** of how long that statement took to run.
2715
+** of how long that statement took to run. ^The profile callback
2716
+** time is in units of nanoseconds, however the current implementation
2717
+** is only capable of millisecond resolution so the six least significant
2718
+** digits in the time are meaningless. Future versions of SQLite
2719
+** might provide greater resolution on the profiler callback. The
2720
+** sqlite3_profile() function is considered experimental and is
2721
+** subject to change in future versions of SQLite.
27162722
*/
27172723
SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
27182724
SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
27192725
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
27202726
@@ -4859,22 +4865,25 @@
48594865
48604866
/*
48614867
** CAPI3REF: Virtual Table Indexing Information
48624868
** KEYWORDS: sqlite3_index_info
48634869
**
4864
-** The sqlite3_index_info structure and its substructures is used to
4870
+** The sqlite3_index_info structure and its substructures is used as part
4871
+** of the [virtual table] interface to
48654872
** pass information into and receive the reply from the [xBestIndex]
48664873
** method of a [virtual table module]. The fields under **Inputs** are the
48674874
** inputs to xBestIndex and are read-only. xBestIndex inserts its
48684875
** results into the **Outputs** fields.
48694876
**
48704877
** ^(The aConstraint[] array records WHERE clause constraints of the form:
48714878
**
4872
-** <pre>column OP expr</pre>
4879
+** <blockquote>column OP expr</blockquote>
48734880
**
48744881
** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
4875
-** stored in aConstraint[].op.)^ ^(The index of the column is stored in
4882
+** stored in aConstraint[].op using one of the
4883
+** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
4884
+** ^(The index of the column is stored in
48764885
** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
48774886
** expr on the right-hand side can be evaluated (and thus the constraint
48784887
** is usable) and false if it cannot.)^
48794888
**
48804889
** ^The optimizer automatically inverts terms of the form "expr OP column"
@@ -4930,10 +4939,19 @@
49304939
char *idxStr; /* String, possibly obtained from sqlite3_malloc */
49314940
int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
49324941
int orderByConsumed; /* True if output is already ordered */
49334942
double estimatedCost; /* Estimated cost of using this index */
49344943
};
4944
+
4945
+/*
4946
+** CAPI3REF: Virtual Table Constraint Operator Codes
4947
+**
4948
+** These macros defined the allowed values for the
4949
+** [sqlite3_index_info].aConstraint[].op field. Each value represents
4950
+** an operator that is part of a constraint term in the wHERE clause of
4951
+** a query that uses a [virtual table].
4952
+*/
49354953
#define SQLITE_INDEX_CONSTRAINT_EQ 2
49364954
#define SQLITE_INDEX_CONSTRAINT_GT 4
49374955
#define SQLITE_INDEX_CONSTRAINT_LE 8
49384956
#define SQLITE_INDEX_CONSTRAINT_LT 16
49394957
#define SQLITE_INDEX_CONSTRAINT_GE 32
@@ -5670,10 +5688,13 @@
56705688
** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
56715689
** internal equivalents). Only the value returned in the
56725690
** *pHighwater parameter to [sqlite3_status()] is of interest.
56735691
** The value written into the *pCurrent parameter is undefined.</dd>)^
56745692
**
5693
+** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5694
+** <dd>This parameter records the number of separate memory allocations.</dd>)^
5695
+**
56755696
** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
56765697
** <dd>This parameter returns the number of pages used out of the
56775698
** [pagecache memory allocator] that was configured using
56785699
** [SQLITE_CONFIG_PAGECACHE]. The
56795700
** value returned is in pages, not in bytes.</dd>)^
@@ -5731,10 +5752,11 @@
57315752
#define SQLITE_STATUS_SCRATCH_OVERFLOW 4
57325753
#define SQLITE_STATUS_MALLOC_SIZE 5
57335754
#define SQLITE_STATUS_PARSER_STACK 6
57345755
#define SQLITE_STATUS_PAGECACHE_SIZE 7
57355756
#define SQLITE_STATUS_SCRATCH_SIZE 8
5757
+#define SQLITE_STATUS_MALLOC_COUNT 9
57365758
57375759
/*
57385760
** CAPI3REF: Database Connection Status
57395761
**
57405762
** ^This interface is used to retrieve runtime status information
@@ -5770,20 +5792,37 @@
57705792
** <dl>
57715793
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
57725794
** <dd>This parameter returns the number of lookaside memory slots currently
57735795
** checked out.</dd>)^
57745796
**
5775
-** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5776
-** <dd>^This parameter returns the approximate number of of bytes of heap
5777
-** memory used by all pager caches associated with the database connection.
5797
+** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5798
+** <dd>This parameter returns the approximate number of of bytes of heap
5799
+** memory used by all pager caches associated with the database connection.)^
57785800
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5801
+**
5802
+** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
5803
+** <dd>This parameter returns the approximate number of of bytes of heap
5804
+** memory used to store the schema for all databases associated
5805
+** with the connection - main, temp, and any [ATTACH]-ed databases.)^
5806
+** ^The full amount of memory used by the schemas is reported, even if the
5807
+** schema memory is shared with other database connections due to
5808
+** [shared cache mode] being enabled.
5809
+** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
5810
+**
5811
+** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
5812
+** <dd>This parameter returns the approximate number of of bytes of heap
5813
+** and lookaside memory used by all prepared statements associated with
5814
+** the database connection.)^
5815
+** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
57795816
** </dd>
57805817
** </dl>
57815818
*/
57825819
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
57835820
#define SQLITE_DBSTATUS_CACHE_USED 1
5784
-#define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
5821
+#define SQLITE_DBSTATUS_SCHEMA_USED 2
5822
+#define SQLITE_DBSTATUS_STMT_USED 3
5823
+#define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
57855824
57865825
57875826
/*
57885827
** CAPI3REF: Prepared Statement Status
57895828
**
@@ -7257,10 +7296,14 @@
72577296
#ifdef SQLITE_TEST
72587297
SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
72597298
SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*);
72607299
#endif
72617300
7301
+#ifndef SQLITE_OMIT_WAL
7302
+SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*);
7303
+#endif
7304
+
72627305
/*
72637306
** If we are not using shared cache, then there is no need to
72647307
** use mutexes to access the BtShared structures. So make the
72657308
** Enter and Leave procedures no-ops.
72667309
*/
@@ -7386,12 +7429,12 @@
73867429
struct SubProgram {
73877430
VdbeOp *aOp; /* Array of opcodes for sub-program */
73887431
int nOp; /* Elements in aOp[] */
73897432
int nMem; /* Number of memory cells required */
73907433
int nCsr; /* Number of cursors required */
7391
- int nRef; /* Number of pointers to this structure */
73927434
void *token; /* id that may be used to recursive triggers */
7435
+ SubProgram *pNext; /* Next sub-program already visited */
73937436
};
73947437
73957438
/*
73967439
** A smaller version of VdbeOp used for the VdbeAddOpList() function because
73977440
** it takes up less space.
@@ -7675,10 +7718,11 @@
76757718
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
76767719
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
76777720
SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
76787721
SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
76797722
SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
7723
+SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3*,Vdbe*);
76807724
SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int,int,int);
76817725
SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
76827726
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
76837727
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
76847728
#ifdef SQLITE_DEBUG
@@ -7692,20 +7736,23 @@
76927736
SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
76937737
SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
76947738
SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, int);
76957739
SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe*,Vdbe*);
76967740
SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*);
7697
-SQLITE_PRIVATE void sqlite3VdbeProgramDelete(sqlite3 *, SubProgram *, int);
76987741
SQLITE_PRIVATE sqlite3_value *sqlite3VdbeGetValue(Vdbe*, int, u8);
76997742
SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe*, int);
77007743
#ifndef SQLITE_OMIT_TRACE
77017744
SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
77027745
#endif
77037746
77047747
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,char*,int);
77057748
SQLITE_PRIVATE void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord*);
77067749
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
7750
+
7751
+#ifndef SQLITE_OMIT_TRIGGER
7752
+SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
7753
+#endif
77077754
77087755
77097756
#ifndef NDEBUG
77107757
SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...);
77117758
# define VdbeComment(X) sqlite3VdbeComment X
@@ -7851,10 +7898,11 @@
78517898
78527899
/* Functions used to manage pager transactions and savepoints. */
78537900
SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*, int*);
78547901
SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
78557902
SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
7903
+SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
78567904
SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
78577905
SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
78587906
SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
78597907
SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
78607908
SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
@@ -8442,18 +8490,10 @@
84428490
Schema *pSchema; /* Pointer to database schema (possibly shared) */
84438491
};
84448492
84458493
/*
84468494
** An instance of the following structure stores a database schema.
8447
-**
8448
-** If there are no virtual tables configured in this schema, the
8449
-** Schema.db variable is set to NULL. After the first virtual table
8450
-** has been added, it is set to point to the database connection
8451
-** used to create the connection. Once a virtual table has been
8452
-** added to the Schema structure and the Schema.db variable populated,
8453
-** only that database connection may use the Schema to prepare
8454
-** statements.
84558495
*/
84568496
struct Schema {
84578497
int schema_cookie; /* Database schema version number for this file */
84588498
Hash tblHash; /* All tables indexed by name */
84598499
Hash idxHash; /* All (named) indices indexed by name */
@@ -8462,13 +8502,10 @@
84628502
Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
84638503
u8 file_format; /* Schema format version for this file */
84648504
u8 enc; /* Text encoding used by this database */
84658505
u16 flags; /* Flags associated with this schema */
84668506
int cache_size; /* Number of pages to use in the cache */
8467
-#ifndef SQLITE_OMIT_VIRTUALTABLE
8468
- sqlite3 *db; /* "Owner" connection. See comment above */
8469
-#endif
84708507
};
84718508
84728509
/*
84738510
** These macros can be used to test, set, or clear bits in the
84748511
** Db.pSchema->flags field.
@@ -8652,10 +8689,11 @@
86528689
Savepoint *pSavepoint; /* List of active savepoints */
86538690
int nSavepoint; /* Number of non-transaction savepoints */
86548691
int nStatement; /* Number of nested statement-transactions */
86558692
u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
86568693
i64 nDeferredCons; /* Net deferred constraints this transaction. */
8694
+ int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
86578695
86588696
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
86598697
/* The following variables are all protected by the STATIC_MASTER
86608698
** mutex, not by sqlite3.mutex. They are used by code in notify.c.
86618699
**
@@ -9009,11 +9047,10 @@
90099047
** page number. Transient tables are used to hold the results of a
90109048
** sub-query that appears instead of a real table name in the FROM clause
90119049
** of a SELECT statement.
90129050
*/
90139051
struct Table {
9014
- sqlite3 *dbMem; /* DB connection used for lookaside allocations. */
90159052
char *zName; /* Name of the table or view */
90169053
int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
90179054
int nCol; /* Number of columns in this table */
90189055
Column *aCol; /* Information about each column */
90199056
Index *pIndex; /* List of SQL indexes on this table. */
@@ -10118,11 +10155,11 @@
1011810155
char *zText; /* The string collected so far */
1011910156
int nChar; /* Length of the string so far */
1012010157
int nAlloc; /* Amount of space allocated in zText */
1012110158
int mxAlloc; /* Maximum allowed string length */
1012210159
u8 mallocFailed; /* Becomes true if any memory allocation fails */
10123
- u8 useMalloc; /* True if zText is enlargeable using realloc */
10160
+ u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
1012410161
u8 tooBig; /* Becomes true if string size exceeds limits */
1012510162
};
1012610163
1012710164
/*
1012810165
** A pointer to this structure is used to communicate information
@@ -10416,11 +10453,11 @@
1041610453
#else
1041710454
# define sqlite3ViewGetColumnNames(A,B) 0
1041810455
#endif
1041910456
1042010457
SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
10421
-SQLITE_PRIVATE void sqlite3DeleteTable(Table*);
10458
+SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
1042210459
#ifndef SQLITE_OMIT_AUTOINCREMENT
1042310460
SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
1042410461
SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
1042510462
#else
1042610463
# define sqlite3AutoincrementBegin(X)
@@ -10650,11 +10687,12 @@
1065010687
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
1065110688
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
1065210689
SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
1065310690
SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
1065410691
SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
10655
-SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *);
10692
+SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*);
10693
+SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*);
1065610694
SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
1065710695
SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
1065810696
SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
1065910697
1066010698
SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
@@ -10700,11 +10738,11 @@
1070010738
SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*);
1070110739
SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*);
1070210740
SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*);
1070310741
SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *);
1070410742
SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB);
10705
-SQLITE_PRIVATE void sqlite3DeleteIndexSamples(Index*);
10743
+SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*);
1070610744
SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
1070710745
SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
1070810746
SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
1070910747
SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
1071010748
SQLITE_PRIVATE void sqlite3SchemaFree(void *);
@@ -10762,11 +10800,11 @@
1076210800
# define sqlite3VtabInSync(db) 0
1076310801
# define sqlite3VtabLock(X)
1076410802
# define sqlite3VtabUnlock(X)
1076510803
# define sqlite3VtabUnlockList(X)
1076610804
#else
10767
-SQLITE_PRIVATE void sqlite3VtabClear(Table*);
10805
+SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
1076810806
SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
1076910807
SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
1077010808
SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
1077110809
SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
1077210810
SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
@@ -10815,13 +10853,13 @@
1081510853
#define sqlite3FkDropTable(a,b,c)
1081610854
#define sqlite3FkOldmask(a,b) 0
1081710855
#define sqlite3FkRequired(a,b,c,d) 0
1081810856
#endif
1081910857
#ifndef SQLITE_OMIT_FOREIGN_KEY
10820
-SQLITE_PRIVATE void sqlite3FkDelete(Table*);
10858
+SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
1082110859
#else
10822
- #define sqlite3FkDelete(a)
10860
+ #define sqlite3FkDelete(a,b)
1082310861
#endif
1082410862
1082510863
1082610864
/*
1082710865
** Available fault injectors. Should be numbered beginning with 0.
@@ -10910,36 +10948,40 @@
1091010948
** a single bit set.
1091110949
**
1091210950
** sqlite3MemdebugHasType() returns true if any of the bits in its second
1091310951
** argument match the type set by the previous sqlite3MemdebugSetType().
1091410952
** sqlite3MemdebugHasType() is intended for use inside assert() statements.
10915
-** For example:
1091610953
**
10917
-** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
10954
+** sqlite3MemdebugNoType() returns true if none of the bits in its second
10955
+** argument match the type set by the previous sqlite3MemdebugSetType().
1091810956
**
1091910957
** Perhaps the most important point is the difference between MEMTYPE_HEAP
10920
-** and MEMTYPE_DB. If an allocation is MEMTYPE_DB, that means it might have
10921
-** been allocated by lookaside, except the allocation was too large or
10922
-** lookaside was already full. It is important to verify that allocations
10923
-** that might have been satisfied by lookaside are not passed back to
10924
-** non-lookaside free() routines. Asserts such as the example above are
10925
-** placed on the non-lookaside free() routines to verify this constraint.
10958
+** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means
10959
+** it might have been allocated by lookaside, except the allocation was
10960
+** too large or lookaside was already full. It is important to verify
10961
+** that allocations that might have been satisfied by lookaside are not
10962
+** passed back to non-lookaside free() routines. Asserts such as the
10963
+** example above are placed on the non-lookaside free() routines to verify
10964
+** this constraint.
1092610965
**
1092710966
** All of this is no-op for a production build. It only comes into
1092810967
** play when the SQLITE_MEMDEBUG compile-time option is used.
1092910968
*/
1093010969
#ifdef SQLITE_MEMDEBUG
1093110970
SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
1093210971
SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
10972
+SQLITE_PRIVATE int sqlite3MemdebugNoType(void*,u8);
1093310973
#else
1093410974
# define sqlite3MemdebugSetType(X,Y) /* no-op */
1093510975
# define sqlite3MemdebugHasType(X,Y) 1
10976
+# define sqlite3MemdebugNoType(X,Y) 1
1093610977
#endif
10937
-#define MEMTYPE_HEAP 0x01 /* General heap allocations */
10938
-#define MEMTYPE_DB 0x02 /* Associated with a database connection */
10939
-#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
10940
-#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
10978
+#define MEMTYPE_HEAP 0x01 /* General heap allocations */
10979
+#define MEMTYPE_LOOKASIDE 0x02 /* Might have been lookaside memory */
10980
+#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
10981
+#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
10982
+#define MEMTYPE_DB 0x10 /* Uses sqlite3DbMalloc, not sqlite_malloc */
1094110983
1094210984
#endif /* _SQLITEINT_H_ */
1094310985
1094410986
/************** End of sqliteInt.h *******************************************/
1094510987
/************** Begin file global.c ******************************************/
@@ -11566,18 +11608,442 @@
1156611608
*************************************************************************
1156711609
**
1156811610
** This module implements the sqlite3_status() interface and related
1156911611
** functionality.
1157011612
*/
11613
+/************** Include vdbeInt.h in the middle of status.c ******************/
11614
+/************** Begin file vdbeInt.h *****************************************/
11615
+/*
11616
+** 2003 September 6
11617
+**
11618
+** The author disclaims copyright to this source code. In place of
11619
+** a legal notice, here is a blessing:
11620
+**
11621
+** May you do good and not evil.
11622
+** May you find forgiveness for yourself and forgive others.
11623
+** May you share freely, never taking more than you give.
11624
+**
11625
+*************************************************************************
11626
+** This is the header file for information that is private to the
11627
+** VDBE. This information used to all be at the top of the single
11628
+** source code file "vdbe.c". When that file became too big (over
11629
+** 6000 lines long) it was split up into several smaller files and
11630
+** this header information was factored out.
11631
+*/
11632
+#ifndef _VDBEINT_H_
11633
+#define _VDBEINT_H_
11634
+
11635
+/*
11636
+** SQL is translated into a sequence of instructions to be
11637
+** executed by a virtual machine. Each instruction is an instance
11638
+** of the following structure.
11639
+*/
11640
+typedef struct VdbeOp Op;
11641
+
11642
+/*
11643
+** Boolean values
11644
+*/
11645
+typedef unsigned char Bool;
11646
+
11647
+/*
11648
+** A cursor is a pointer into a single BTree within a database file.
11649
+** The cursor can seek to a BTree entry with a particular key, or
11650
+** loop over all entries of the Btree. You can also insert new BTree
11651
+** entries or retrieve the key or data from the entry that the cursor
11652
+** is currently pointing to.
11653
+**
11654
+** Every cursor that the virtual machine has open is represented by an
11655
+** instance of the following structure.
11656
+**
11657
+** If the VdbeCursor.isTriggerRow flag is set it means that this cursor is
11658
+** really a single row that represents the NEW or OLD pseudo-table of
11659
+** a row trigger. The data for the row is stored in VdbeCursor.pData and
11660
+** the rowid is in VdbeCursor.iKey.
11661
+*/
11662
+struct VdbeCursor {
11663
+ BtCursor *pCursor; /* The cursor structure of the backend */
11664
+ int iDb; /* Index of cursor database in db->aDb[] (or -1) */
11665
+ i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
11666
+ Bool zeroed; /* True if zeroed out and ready for reuse */
11667
+ Bool rowidIsValid; /* True if lastRowid is valid */
11668
+ Bool atFirst; /* True if pointing to first entry */
11669
+ Bool useRandomRowid; /* Generate new record numbers semi-randomly */
11670
+ Bool nullRow; /* True if pointing to a row with no data */
11671
+ Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
11672
+ Bool isTable; /* True if a table requiring integer keys */
11673
+ Bool isIndex; /* True if an index containing keys only - no data */
11674
+ i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
11675
+ Btree *pBt; /* Separate file holding temporary table */
11676
+ int pseudoTableReg; /* Register holding pseudotable content. */
11677
+ KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
11678
+ int nField; /* Number of fields in the header */
11679
+ i64 seqCount; /* Sequence counter */
11680
+ sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
11681
+ const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
11682
+
11683
+ /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
11684
+ ** OP_IsUnique opcode on this cursor. */
11685
+ int seekResult;
11686
+
11687
+ /* Cached information about the header for the data record that the
11688
+ ** cursor is currently pointing to. Only valid if cacheStatus matches
11689
+ ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
11690
+ ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
11691
+ ** the cache is out of date.
11692
+ **
11693
+ ** aRow might point to (ephemeral) data for the current row, or it might
11694
+ ** be NULL.
11695
+ */
11696
+ u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
11697
+ int payloadSize; /* Total number of bytes in the record */
11698
+ u32 *aType; /* Type values for all entries in the record */
11699
+ u32 *aOffset; /* Cached offsets to the start of each columns data */
11700
+ u8 *aRow; /* Data for the current row, if all on one page */
11701
+};
11702
+typedef struct VdbeCursor VdbeCursor;
11703
+
11704
+/*
11705
+** When a sub-program is executed (OP_Program), a structure of this type
11706
+** is allocated to store the current value of the program counter, as
11707
+** well as the current memory cell array and various other frame specific
11708
+** values stored in the Vdbe struct. When the sub-program is finished,
11709
+** these values are copied back to the Vdbe from the VdbeFrame structure,
11710
+** restoring the state of the VM to as it was before the sub-program
11711
+** began executing.
11712
+**
11713
+** Frames are stored in a linked list headed at Vdbe.pParent. Vdbe.pParent
11714
+** is the parent of the current frame, or zero if the current frame
11715
+** is the main Vdbe program.
11716
+*/
11717
+typedef struct VdbeFrame VdbeFrame;
11718
+struct VdbeFrame {
11719
+ Vdbe *v; /* VM this frame belongs to */
11720
+ int pc; /* Program Counter */
11721
+ Op *aOp; /* Program instructions */
11722
+ int nOp; /* Size of aOp array */
11723
+ Mem *aMem; /* Array of memory cells */
11724
+ int nMem; /* Number of entries in aMem */
11725
+ VdbeCursor **apCsr; /* Element of Vdbe cursors */
11726
+ u16 nCursor; /* Number of entries in apCsr */
11727
+ void *token; /* Copy of SubProgram.token */
11728
+ int nChildMem; /* Number of memory cells for child frame */
11729
+ int nChildCsr; /* Number of cursors for child frame */
11730
+ i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
11731
+ int nChange; /* Statement changes (Vdbe.nChanges) */
11732
+ VdbeFrame *pParent; /* Parent of this frame */
11733
+};
11734
+
11735
+#define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
11736
+
11737
+/*
11738
+** A value for VdbeCursor.cacheValid that means the cache is always invalid.
11739
+*/
11740
+#define CACHE_STALE 0
11741
+
11742
+/*
11743
+** Internally, the vdbe manipulates nearly all SQL values as Mem
11744
+** structures. Each Mem struct may cache multiple representations (string,
11745
+** integer etc.) of the same value. A value (and therefore Mem structure)
11746
+** has the following properties:
11747
+**
11748
+** Each value has a manifest type. The manifest type of the value stored
11749
+** in a Mem struct is returned by the MemType(Mem*) macro. The type is
11750
+** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
11751
+** SQLITE_BLOB.
11752
+*/
11753
+struct Mem {
11754
+ union {
11755
+ i64 i; /* Integer value. */
11756
+ int nZero; /* Used when bit MEM_Zero is set in flags */
11757
+ FuncDef *pDef; /* Used only when flags==MEM_Agg */
11758
+ RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
11759
+ VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
11760
+ } u;
11761
+ double r; /* Real value */
11762
+ sqlite3 *db; /* The associated database connection */
11763
+ char *z; /* String or BLOB value */
11764
+ int n; /* Number of characters in string value, excluding '\0' */
11765
+ u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
11766
+ u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
11767
+ u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
11768
+ void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
11769
+ char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
11770
+};
11771
+
11772
+/* One or more of the following flags are set to indicate the validOK
11773
+** representations of the value stored in the Mem struct.
11774
+**
11775
+** If the MEM_Null flag is set, then the value is an SQL NULL value.
11776
+** No other flags may be set in this case.
11777
+**
11778
+** If the MEM_Str flag is set then Mem.z points at a string representation.
11779
+** Usually this is encoded in the same unicode encoding as the main
11780
+** database (see below for exceptions). If the MEM_Term flag is also
11781
+** set, then the string is nul terminated. The MEM_Int and MEM_Real
11782
+** flags may coexist with the MEM_Str flag.
11783
+**
11784
+** Multiple of these values can appear in Mem.flags. But only one
11785
+** at a time can appear in Mem.type.
11786
+*/
11787
+#define MEM_Null 0x0001 /* Value is NULL */
11788
+#define MEM_Str 0x0002 /* Value is a string */
11789
+#define MEM_Int 0x0004 /* Value is an integer */
11790
+#define MEM_Real 0x0008 /* Value is a real number */
11791
+#define MEM_Blob 0x0010 /* Value is a BLOB */
11792
+#define MEM_RowSet 0x0020 /* Value is a RowSet object */
11793
+#define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
11794
+#define MEM_TypeMask 0x00ff /* Mask of type bits */
11795
+
11796
+/* Whenever Mem contains a valid string or blob representation, one of
11797
+** the following flags must be set to determine the memory management
11798
+** policy for Mem.z. The MEM_Term flag tells us whether or not the
11799
+** string is \000 or \u0000 terminated
11800
+*/
11801
+#define MEM_Term 0x0200 /* String rep is nul terminated */
11802
+#define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
11803
+#define MEM_Static 0x0800 /* Mem.z points to a static string */
11804
+#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
11805
+#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
11806
+#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
11807
+
11808
+#ifdef SQLITE_OMIT_INCRBLOB
11809
+ #undef MEM_Zero
11810
+ #define MEM_Zero 0x0000
11811
+#endif
11812
+
11813
+
11814
+/*
11815
+** Clear any existing type flags from a Mem and replace them with f
11816
+*/
11817
+#define MemSetTypeFlag(p, f) \
11818
+ ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
11819
+
11820
+
11821
+/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
11822
+** additional information about auxiliary information bound to arguments
11823
+** of the function. This is used to implement the sqlite3_get_auxdata()
11824
+** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
11825
+** that can be associated with a constant argument to a function. This
11826
+** allows functions such as "regexp" to compile their constant regular
11827
+** expression argument once and reused the compiled code for multiple
11828
+** invocations.
11829
+*/
11830
+struct VdbeFunc {
11831
+ FuncDef *pFunc; /* The definition of the function */
11832
+ int nAux; /* Number of entries allocated for apAux[] */
11833
+ struct AuxData {
11834
+ void *pAux; /* Aux data for the i-th argument */
11835
+ void (*xDelete)(void *); /* Destructor for the aux data */
11836
+ } apAux[1]; /* One slot for each function argument */
11837
+};
11838
+
11839
+/*
11840
+** The "context" argument for a installable function. A pointer to an
11841
+** instance of this structure is the first argument to the routines used
11842
+** implement the SQL functions.
11843
+**
11844
+** There is a typedef for this structure in sqlite.h. So all routines,
11845
+** even the public interface to SQLite, can use a pointer to this structure.
11846
+** But this file is the only place where the internal details of this
11847
+** structure are known.
11848
+**
11849
+** This structure is defined inside of vdbeInt.h because it uses substructures
11850
+** (Mem) which are only defined there.
11851
+*/
11852
+struct sqlite3_context {
11853
+ FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
11854
+ VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
11855
+ Mem s; /* The return value is stored here */
11856
+ Mem *pMem; /* Memory cell used to store aggregate context */
11857
+ int isError; /* Error code returned by the function. */
11858
+ CollSeq *pColl; /* Collating sequence */
11859
+};
11860
+
11861
+/*
11862
+** A Set structure is used for quick testing to see if a value
11863
+** is part of a small set. Sets are used to implement code like
11864
+** this:
11865
+** x.y IN ('hi','hoo','hum')
11866
+*/
11867
+typedef struct Set Set;
11868
+struct Set {
11869
+ Hash hash; /* A set is just a hash table */
11870
+ HashElem *prev; /* Previously accessed hash elemen */
11871
+};
11872
+
11873
+/*
11874
+** An instance of the virtual machine. This structure contains the complete
11875
+** state of the virtual machine.
11876
+**
11877
+** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()
11878
+** is really a pointer to an instance of this structure.
11879
+**
11880
+** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
11881
+** any virtual table method invocations made by the vdbe program. It is
11882
+** set to 2 for xDestroy method calls and 1 for all other methods. This
11883
+** variable is used for two purposes: to allow xDestroy methods to execute
11884
+** "DROP TABLE" statements and to prevent some nasty side effects of
11885
+** malloc failure when SQLite is invoked recursively by a virtual table
11886
+** method function.
11887
+*/
11888
+struct Vdbe {
11889
+ sqlite3 *db; /* The database connection that owns this statement */
11890
+ Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
11891
+ int nOp; /* Number of instructions in the program */
11892
+ int nOpAlloc; /* Number of slots allocated for aOp[] */
11893
+ Op *aOp; /* Space to hold the virtual machine's program */
11894
+ int nLabel; /* Number of labels used */
11895
+ int nLabelAlloc; /* Number of slots allocated in aLabel[] */
11896
+ int *aLabel; /* Space to hold the labels */
11897
+ Mem **apArg; /* Arguments to currently executing user function */
11898
+ Mem *aColName; /* Column names to return */
11899
+ Mem *pResultSet; /* Pointer to an array of results */
11900
+ u16 nResColumn; /* Number of columns in one row of the result set */
11901
+ u16 nCursor; /* Number of slots in apCsr[] */
11902
+ VdbeCursor **apCsr; /* One element of this array for each open cursor */
11903
+ u8 errorAction; /* Recovery action to do in case of an error */
11904
+ u8 okVar; /* True if azVar[] has been initialized */
11905
+ ynVar nVar; /* Number of entries in aVar[] */
11906
+ Mem *aVar; /* Values for the OP_Variable opcode. */
11907
+ char **azVar; /* Name of variables */
11908
+ u32 magic; /* Magic number for sanity checking */
11909
+ int nMem; /* Number of memory locations currently allocated */
11910
+ Mem *aMem; /* The memory locations */
11911
+ u32 cacheCtr; /* VdbeCursor row cache generation counter */
11912
+ int pc; /* The program counter */
11913
+ int rc; /* Value to return */
11914
+ char *zErrMsg; /* Error message written here */
11915
+ u8 explain; /* True if EXPLAIN present on SQL command */
11916
+ u8 changeCntOn; /* True to update the change-counter */
11917
+ u8 expired; /* True if the VM needs to be recompiled */
11918
+ u8 runOnlyOnce; /* Automatically expire on reset */
11919
+ u8 minWriteFileFormat; /* Minimum file format for writable database files */
11920
+ u8 inVtabMethod; /* See comments above */
11921
+ u8 usesStmtJournal; /* True if uses a statement journal */
11922
+ u8 readOnly; /* True for read-only statements */
11923
+ u8 isPrepareV2; /* True if prepared with prepare_v2() */
11924
+ int nChange; /* Number of db changes made since last reset */
11925
+ int btreeMask; /* Bitmask of db->aDb[] entries referenced */
11926
+ i64 startTime; /* Time when query started - used for profiling */
11927
+ BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
11928
+ int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
11929
+ char *zSql; /* Text of the SQL statement that generated this */
11930
+ void *pFree; /* Free this when deleting the vdbe */
11931
+ i64 nFkConstraint; /* Number of imm. FK constraints this VM */
11932
+ i64 nStmtDefCons; /* Number of def. constraints when stmt started */
11933
+ int iStatement; /* Statement number (or 0 if has not opened stmt) */
11934
+#ifdef SQLITE_DEBUG
11935
+ FILE *trace; /* Write an execution trace here, if not NULL */
11936
+#endif
11937
+ VdbeFrame *pFrame; /* Parent frame */
11938
+ int nFrame; /* Number of frames in pFrame list */
11939
+ u32 expmask; /* Binding to these vars invalidates VM */
11940
+ SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
11941
+};
11942
+
11943
+/*
11944
+** The following are allowed values for Vdbe.magic
11945
+*/
11946
+#define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */
11947
+#define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */
11948
+#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */
11949
+#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */
11950
+
11951
+/*
11952
+** Function prototypes
11953
+*/
11954
+SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
11955
+void sqliteVdbePopStack(Vdbe*,int);
11956
+SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
11957
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
11958
+SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
11959
+#endif
11960
+SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
11961
+SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
11962
+SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
11963
+SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
11964
+SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
11965
+
11966
+int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
11967
+SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
11968
+SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
11969
+SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
11970
+SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
11971
+SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
11972
+SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
11973
+SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int);
11974
+SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*);
11975
+SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem*, const Mem*);
11976
+SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
11977
+SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem*, Mem*);
11978
+SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem*);
11979
+SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
11980
+SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem*, i64);
11981
+#ifdef SQLITE_OMIT_FLOATING_POINT
11982
+# define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
11983
+#else
11984
+SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
11985
+#endif
11986
+SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
11987
+SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
11988
+SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
11989
+SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
11990
+SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, int);
11991
+SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*);
11992
+SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
11993
+SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
11994
+SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
11995
+SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
11996
+SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
11997
+SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
11998
+SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
11999
+SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
12000
+SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
12001
+SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
12002
+SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
12003
+SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
12004
+SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
12005
+SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
12006
+SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
12007
+
12008
+#ifndef SQLITE_OMIT_FOREIGN_KEY
12009
+SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
12010
+#else
12011
+# define sqlite3VdbeCheckFk(p,i) 0
12012
+#endif
12013
+
12014
+#ifndef SQLITE_OMIT_SHARED_CACHE
12015
+SQLITE_PRIVATE void sqlite3VdbeMutexArrayEnter(Vdbe *p);
12016
+#else
12017
+# define sqlite3VdbeMutexArrayEnter(p)
12018
+#endif
12019
+
12020
+SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
12021
+#ifdef SQLITE_DEBUG
12022
+SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*);
12023
+SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
12024
+#endif
12025
+SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
12026
+
12027
+#ifndef SQLITE_OMIT_INCRBLOB
12028
+SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *);
12029
+#else
12030
+ #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
12031
+#endif
12032
+
12033
+#endif /* !defined(_VDBEINT_H_) */
12034
+
12035
+/************** End of vdbeInt.h *********************************************/
12036
+/************** Continuing where we left off in status.c *********************/
1157112037
1157212038
/*
1157312039
** Variables in which to record status information.
1157412040
*/
1157512041
typedef struct sqlite3StatType sqlite3StatType;
1157612042
static SQLITE_WSD struct sqlite3StatType {
11577
- int nowValue[9]; /* Current value */
11578
- int mxValue[9]; /* Maximum value */
12043
+ int nowValue[10]; /* Current value */
12044
+ int mxValue[10]; /* Maximum value */
1157912045
} sqlite3Stat = { {0,}, {0,} };
1158012046
1158112047
1158212048
/* The "wsdStat" macro will resolve to the status information
1158312049
** state vector. If writable static data is unsupported on the target,
@@ -11655,10 +12121,12 @@
1165512121
int op, /* Status verb */
1165612122
int *pCurrent, /* Write current value here */
1165712123
int *pHighwater, /* Write high-water mark here */
1165812124
int resetFlag /* Reset high-water mark if true */
1165912125
){
12126
+ int rc = SQLITE_OK; /* Return code */
12127
+ sqlite3_mutex_enter(db->mutex);
1166012128
switch( op ){
1166112129
case SQLITE_DBSTATUS_LOOKASIDE_USED: {
1166212130
*pCurrent = db->lookaside.nOut;
1166312131
*pHighwater = db->lookaside.mxOut;
1166412132
if( resetFlag ){
@@ -11673,26 +12141,92 @@
1167312141
** highwater mark is meaningless and is returned as zero.
1167412142
*/
1167512143
case SQLITE_DBSTATUS_CACHE_USED: {
1167612144
int totalUsed = 0;
1167712145
int i;
12146
+ sqlite3BtreeEnterAll(db);
1167812147
for(i=0; i<db->nDb; i++){
1167912148
Btree *pBt = db->aDb[i].pBt;
1168012149
if( pBt ){
1168112150
Pager *pPager = sqlite3BtreePager(pBt);
1168212151
totalUsed += sqlite3PagerMemUsed(pPager);
1168312152
}
1168412153
}
12154
+ sqlite3BtreeLeaveAll(db);
1168512155
*pCurrent = totalUsed;
1168612156
*pHighwater = 0;
1168712157
break;
1168812158
}
12159
+
12160
+ /*
12161
+ ** *pCurrent gets an accurate estimate of the amount of memory used
12162
+ ** to store the schema for all databases (main, temp, and any ATTACHed
12163
+ ** databases. *pHighwater is set to zero.
12164
+ */
12165
+ case SQLITE_DBSTATUS_SCHEMA_USED: {
12166
+ int i; /* Used to iterate through schemas */
12167
+ int nByte = 0; /* Used to accumulate return value */
12168
+
12169
+ db->pnBytesFreed = &nByte;
12170
+ for(i=0; i<db->nDb; i++){
12171
+ Schema *pSchema = db->aDb[i].pSchema;
12172
+ if( ALWAYS(pSchema!=0) ){
12173
+ HashElem *p;
12174
+
12175
+ nByte += sqlite3GlobalConfig.m.xRoundup(sizeof(HashElem)) * (
12176
+ pSchema->tblHash.count
12177
+ + pSchema->trigHash.count
12178
+ + pSchema->idxHash.count
12179
+ + pSchema->fkeyHash.count
12180
+ );
12181
+ nByte += sqlite3MallocSize(pSchema->tblHash.ht);
12182
+ nByte += sqlite3MallocSize(pSchema->trigHash.ht);
12183
+ nByte += sqlite3MallocSize(pSchema->idxHash.ht);
12184
+ nByte += sqlite3MallocSize(pSchema->fkeyHash.ht);
12185
+
12186
+ for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){
12187
+ sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
12188
+ }
12189
+ for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
12190
+ sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
12191
+ }
12192
+ }
12193
+ }
12194
+ db->pnBytesFreed = 0;
12195
+
12196
+ *pHighwater = 0;
12197
+ *pCurrent = nByte;
12198
+ break;
12199
+ }
12200
+
12201
+ /*
12202
+ ** *pCurrent gets an accurate estimate of the amount of memory used
12203
+ ** to store all prepared statements.
12204
+ ** *pHighwater is set to zero.
12205
+ */
12206
+ case SQLITE_DBSTATUS_STMT_USED: {
12207
+ struct Vdbe *pVdbe; /* Used to iterate through VMs */
12208
+ int nByte = 0; /* Used to accumulate return value */
12209
+
12210
+ db->pnBytesFreed = &nByte;
12211
+ for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
12212
+ sqlite3VdbeDeleteObject(db, pVdbe);
12213
+ }
12214
+ db->pnBytesFreed = 0;
12215
+
12216
+ *pHighwater = 0;
12217
+ *pCurrent = nByte;
12218
+
12219
+ break;
12220
+ }
12221
+
1168912222
default: {
11690
- return SQLITE_ERROR;
12223
+ rc = SQLITE_ERROR;
1169112224
}
1169212225
}
11693
- return SQLITE_OK;
12226
+ sqlite3_mutex_leave(db->mutex);
12227
+ return rc;
1169412228
}
1169512229
1169612230
/************** End of status.c **********************************************/
1169712231
/************** Begin file date.c ********************************************/
1169812232
/*
@@ -13820,23 +14354,38 @@
1382014354
int rc = 1;
1382114355
if( p ){
1382214356
struct MemBlockHdr *pHdr;
1382314357
pHdr = sqlite3MemsysGetHeader(p);
1382414358
assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
13825
- assert( (pHdr->eType & (pHdr->eType-1))==0 ); /* Only one type bit set */
1382614359
if( (pHdr->eType&eType)==0 ){
13827
- void **pBt;
13828
- pBt = (void**)pHdr;
13829
- pBt -= pHdr->nBacktraceSlots;
13830
- backtrace_symbols_fd(pBt, pHdr->nBacktrace, fileno(stderr));
13831
- fprintf(stderr, "\n");
14360
+ rc = 0;
14361
+ }
14362
+ }
14363
+ return rc;
14364
+}
14365
+
14366
+/*
14367
+** Return TRUE if the mask of type in eType matches no bits of the type of the
14368
+** allocation p. Also return true if p==NULL.
14369
+**
14370
+** This routine is designed for use within an assert() statement, to
14371
+** verify the type of an allocation. For example:
14372
+**
14373
+** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
14374
+*/
14375
+SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
14376
+ int rc = 1;
14377
+ if( p ){
14378
+ struct MemBlockHdr *pHdr;
14379
+ pHdr = sqlite3MemsysGetHeader(p);
14380
+ assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
14381
+ if( (pHdr->eType&eType)!=0 ){
1383214382
rc = 0;
1383314383
}
1383414384
}
1383514385
return rc;
1383614386
}
13837
-
1383814387
1383914388
/*
1384014389
** Set the number of backtrace levels kept for each allocation.
1384114390
** A value of zero turns off backtracing. The number is always rounded
1384214391
** up to a multiple of 2.
@@ -16773,10 +17322,11 @@
1677317322
p = sqlite3GlobalConfig.m.xMalloc(nFull);
1677417323
}
1677517324
if( p ){
1677617325
nFull = sqlite3MallocSize(p);
1677717326
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull);
17327
+ sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, 1);
1677817328
}
1677917329
*pp = p;
1678017330
return nFull;
1678117331
}
1678217332
@@ -16890,16 +17440,18 @@
1689017440
if( p ){
1689117441
if( sqlite3GlobalConfig.pScratch==0
1689217442
|| p<sqlite3GlobalConfig.pScratch
1689317443
|| p>=(void*)mem0.aScratchFree ){
1689417444
assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
17445
+ assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) );
1689517446
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
1689617447
if( sqlite3GlobalConfig.bMemstat ){
1689717448
int iSize = sqlite3MallocSize(p);
1689817449
sqlite3_mutex_enter(mem0.mutex);
1689917450
sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
1690017451
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
17452
+ sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
1690117453
sqlite3GlobalConfig.m.xFree(p);
1690217454
sqlite3_mutex_leave(mem0.mutex);
1690317455
}else{
1690417456
sqlite3GlobalConfig.m.xFree(p);
1690517457
}
@@ -16930,11 +17482,11 @@
1693017482
/*
1693117483
** TRUE if p is a lookaside memory allocation from db
1693217484
*/
1693317485
#ifndef SQLITE_OMIT_LOOKASIDE
1693417486
static int isLookaside(sqlite3 *db, void *p){
16935
- return db && p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
17487
+ return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
1693617488
}
1693717489
#else
1693817490
#define isLookaside(A,B) 0
1693917491
#endif
1694017492
@@ -16942,32 +17494,36 @@
1694217494
** Return the size of a memory allocation previously obtained from
1694317495
** sqlite3Malloc() or sqlite3_malloc().
1694417496
*/
1694517497
SQLITE_PRIVATE int sqlite3MallocSize(void *p){
1694617498
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
17499
+ assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
1694717500
return sqlite3GlobalConfig.m.xSize(p);
1694817501
}
1694917502
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
1695017503
assert( db==0 || sqlite3_mutex_held(db->mutex) );
16951
- if( isLookaside(db, p) ){
17504
+ if( db && isLookaside(db, p) ){
1695217505
return db->lookaside.sz;
1695317506
}else{
16954
- assert( sqlite3MemdebugHasType(p,
16955
- db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
17507
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17508
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
17509
+ assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
1695617510
return sqlite3GlobalConfig.m.xSize(p);
1695717511
}
1695817512
}
1695917513
1696017514
/*
1696117515
** Free memory previously obtained from sqlite3Malloc().
1696217516
*/
1696317517
SQLITE_API void sqlite3_free(void *p){
1696417518
if( p==0 ) return;
17519
+ assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
1696517520
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1696617521
if( sqlite3GlobalConfig.bMemstat ){
1696717522
sqlite3_mutex_enter(mem0.mutex);
1696817523
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
17524
+ sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
1696917525
sqlite3GlobalConfig.m.xFree(p);
1697017526
sqlite3_mutex_leave(mem0.mutex);
1697117527
}else{
1697217528
sqlite3GlobalConfig.m.xFree(p);
1697317529
}
@@ -16977,20 +17533,28 @@
1697717533
** Free memory that might be associated with a particular database
1697817534
** connection.
1697917535
*/
1698017536
SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
1698117537
assert( db==0 || sqlite3_mutex_held(db->mutex) );
16982
- if( isLookaside(db, p) ){
16983
- LookasideSlot *pBuf = (LookasideSlot*)p;
16984
- pBuf->pNext = db->lookaside.pFree;
16985
- db->lookaside.pFree = pBuf;
16986
- db->lookaside.nOut--;
16987
- }else{
16988
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16989
- sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
16990
- sqlite3_free(p);
16991
- }
17538
+ if( db ){
17539
+ if( db->pnBytesFreed ){
17540
+ *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
17541
+ return;
17542
+ }
17543
+ if( isLookaside(db, p) ){
17544
+ LookasideSlot *pBuf = (LookasideSlot*)p;
17545
+ pBuf->pNext = db->lookaside.pFree;
17546
+ db->lookaside.pFree = pBuf;
17547
+ db->lookaside.nOut--;
17548
+ return;
17549
+ }
17550
+ }
17551
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17552
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
17553
+ assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
17554
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
17555
+ sqlite3_free(p);
1699217556
}
1699317557
1699417558
/*
1699517559
** Change the size of an existing memory allocation
1699617560
*/
@@ -17018,10 +17582,11 @@
1701817582
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
1701917583
mem0.alarmThreshold ){
1702017584
sqlite3MallocAlarm(nNew-nOld);
1702117585
}
1702217586
assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
17587
+ assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
1702317588
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1702417589
if( pNew==0 && mem0.alarmCallback ){
1702517590
sqlite3MallocAlarm(nBytes);
1702617591
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1702717592
}
@@ -17090,10 +17655,11 @@
1709017655
** that all prior mallocs (ex: "a") worked too.
1709117656
*/
1709217657
SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
1709317658
void *p;
1709417659
assert( db==0 || sqlite3_mutex_held(db->mutex) );
17660
+ assert( db==0 || db->pnBytesFreed==0 );
1709517661
#ifndef SQLITE_OMIT_LOOKASIDE
1709617662
if( db ){
1709717663
LookasideSlot *pBuf;
1709817664
if( db->mallocFailed ){
1709917665
return 0;
@@ -17115,12 +17681,12 @@
1711517681
#endif
1711617682
p = sqlite3Malloc(n);
1711717683
if( !p && db ){
1711817684
db->mallocFailed = 1;
1711917685
}
17120
- sqlite3MemdebugSetType(p,
17121
- (db && db->lookaside.bEnabled) ? MEMTYPE_DB : MEMTYPE_HEAP);
17686
+ sqlite3MemdebugSetType(p, MEMTYPE_DB |
17687
+ ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
1712217688
return p;
1712317689
}
1712417690
1712517691
/*
1712617692
** Resize the block of memory pointed to by p to n bytes. If the
@@ -17142,18 +17708,20 @@
1714217708
if( pNew ){
1714317709
memcpy(pNew, p, db->lookaside.sz);
1714417710
sqlite3DbFree(db, p);
1714517711
}
1714617712
}else{
17147
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
17713
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17714
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
1714817715
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
1714917716
pNew = sqlite3_realloc(p, n);
1715017717
if( !pNew ){
17718
+ sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
1715117719
db->mallocFailed = 1;
1715217720
}
17153
- sqlite3MemdebugSetType(pNew,
17154
- db->lookaside.bEnabled ? MEMTYPE_DB : MEMTYPE_HEAP);
17721
+ sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
17722
+ (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
1715517723
}
1715617724
}
1715717725
return pNew;
1715817726
}
1715917727
@@ -18022,11 +18590,15 @@
1802218590
p->tooBig = 1;
1802318591
return;
1802418592
}else{
1802518593
p->nAlloc = (int)szNew;
1802618594
}
18027
- zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
18595
+ if( p->useMalloc==1 ){
18596
+ zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
18597
+ }else{
18598
+ zNew = sqlite3_malloc(p->nAlloc);
18599
+ }
1802818600
if( zNew ){
1802918601
memcpy(zNew, p->zText, p->nChar);
1803018602
sqlite3StrAccumReset(p);
1803118603
p->zText = zNew;
1803218604
}else{
@@ -18047,11 +18619,15 @@
1804718619
*/
1804818620
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
1804918621
if( p->zText ){
1805018622
p->zText[p->nChar] = 0;
1805118623
if( p->useMalloc && p->zText==p->zBase ){
18052
- p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
18624
+ if( p->useMalloc==1 ){
18625
+ p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
18626
+ }else{
18627
+ p->zText = sqlite3_malloc(p->nChar+1);
18628
+ }
1805318629
if( p->zText ){
1805418630
memcpy(p->zText, p->zBase, p->nChar+1);
1805518631
}else{
1805618632
p->mallocFailed = 1;
1805718633
}
@@ -18063,11 +18639,15 @@
1806318639
/*
1806418640
** Reset an StrAccum string. Reclaim all malloced memory.
1806518641
*/
1806618642
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
1806718643
if( p->zText!=p->zBase ){
18068
- sqlite3DbFree(p->db, p->zText);
18644
+ if( p->useMalloc==1 ){
18645
+ sqlite3DbFree(p->db, p->zText);
18646
+ }else{
18647
+ sqlite3_free(p->zText);
18648
+ }
1806918649
}
1807018650
p->zText = 0;
1807118651
}
1807218652
1807318653
/*
@@ -18145,10 +18725,11 @@
1814518725
StrAccum acc;
1814618726
#ifndef SQLITE_OMIT_AUTOINIT
1814718727
if( sqlite3_initialize() ) return 0;
1814818728
#endif
1814918729
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
18730
+ acc.useMalloc = 2;
1815018731
sqlite3VXPrintf(&acc, 0, zFormat, ap);
1815118732
z = sqlite3StrAccumFinish(&acc);
1815218733
return z;
1815318734
}
1815418735
@@ -18438,433 +19019,10 @@
1843819019
** BOM or Byte Order Mark:
1843919020
** 0xff 0xfe little-endian utf-16 follows
1844019021
** 0xfe 0xff big-endian utf-16 follows
1844119022
**
1844219023
*/
18443
-/************** Include vdbeInt.h in the middle of utf.c *********************/
18444
-/************** Begin file vdbeInt.h *****************************************/
18445
-/*
18446
-** 2003 September 6
18447
-**
18448
-** The author disclaims copyright to this source code. In place of
18449
-** a legal notice, here is a blessing:
18450
-**
18451
-** May you do good and not evil.
18452
-** May you find forgiveness for yourself and forgive others.
18453
-** May you share freely, never taking more than you give.
18454
-**
18455
-*************************************************************************
18456
-** This is the header file for information that is private to the
18457
-** VDBE. This information used to all be at the top of the single
18458
-** source code file "vdbe.c". When that file became too big (over
18459
-** 6000 lines long) it was split up into several smaller files and
18460
-** this header information was factored out.
18461
-*/
18462
-#ifndef _VDBEINT_H_
18463
-#define _VDBEINT_H_
18464
-
18465
-/*
18466
-** SQL is translated into a sequence of instructions to be
18467
-** executed by a virtual machine. Each instruction is an instance
18468
-** of the following structure.
18469
-*/
18470
-typedef struct VdbeOp Op;
18471
-
18472
-/*
18473
-** Boolean values
18474
-*/
18475
-typedef unsigned char Bool;
18476
-
18477
-/*
18478
-** A cursor is a pointer into a single BTree within a database file.
18479
-** The cursor can seek to a BTree entry with a particular key, or
18480
-** loop over all entries of the Btree. You can also insert new BTree
18481
-** entries or retrieve the key or data from the entry that the cursor
18482
-** is currently pointing to.
18483
-**
18484
-** Every cursor that the virtual machine has open is represented by an
18485
-** instance of the following structure.
18486
-**
18487
-** If the VdbeCursor.isTriggerRow flag is set it means that this cursor is
18488
-** really a single row that represents the NEW or OLD pseudo-table of
18489
-** a row trigger. The data for the row is stored in VdbeCursor.pData and
18490
-** the rowid is in VdbeCursor.iKey.
18491
-*/
18492
-struct VdbeCursor {
18493
- BtCursor *pCursor; /* The cursor structure of the backend */
18494
- int iDb; /* Index of cursor database in db->aDb[] (or -1) */
18495
- i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
18496
- Bool zeroed; /* True if zeroed out and ready for reuse */
18497
- Bool rowidIsValid; /* True if lastRowid is valid */
18498
- Bool atFirst; /* True if pointing to first entry */
18499
- Bool useRandomRowid; /* Generate new record numbers semi-randomly */
18500
- Bool nullRow; /* True if pointing to a row with no data */
18501
- Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
18502
- Bool isTable; /* True if a table requiring integer keys */
18503
- Bool isIndex; /* True if an index containing keys only - no data */
18504
- i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
18505
- Btree *pBt; /* Separate file holding temporary table */
18506
- int pseudoTableReg; /* Register holding pseudotable content. */
18507
- KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
18508
- int nField; /* Number of fields in the header */
18509
- i64 seqCount; /* Sequence counter */
18510
- sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
18511
- const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
18512
-
18513
- /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
18514
- ** OP_IsUnique opcode on this cursor. */
18515
- int seekResult;
18516
-
18517
- /* Cached information about the header for the data record that the
18518
- ** cursor is currently pointing to. Only valid if cacheStatus matches
18519
- ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
18520
- ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
18521
- ** the cache is out of date.
18522
- **
18523
- ** aRow might point to (ephemeral) data for the current row, or it might
18524
- ** be NULL.
18525
- */
18526
- u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
18527
- int payloadSize; /* Total number of bytes in the record */
18528
- u32 *aType; /* Type values for all entries in the record */
18529
- u32 *aOffset; /* Cached offsets to the start of each columns data */
18530
- u8 *aRow; /* Data for the current row, if all on one page */
18531
-};
18532
-typedef struct VdbeCursor VdbeCursor;
18533
-
18534
-/*
18535
-** When a sub-program is executed (OP_Program), a structure of this type
18536
-** is allocated to store the current value of the program counter, as
18537
-** well as the current memory cell array and various other frame specific
18538
-** values stored in the Vdbe struct. When the sub-program is finished,
18539
-** these values are copied back to the Vdbe from the VdbeFrame structure,
18540
-** restoring the state of the VM to as it was before the sub-program
18541
-** began executing.
18542
-**
18543
-** Frames are stored in a linked list headed at Vdbe.pParent. Vdbe.pParent
18544
-** is the parent of the current frame, or zero if the current frame
18545
-** is the main Vdbe program.
18546
-*/
18547
-typedef struct VdbeFrame VdbeFrame;
18548
-struct VdbeFrame {
18549
- Vdbe *v; /* VM this frame belongs to */
18550
- int pc; /* Program Counter */
18551
- Op *aOp; /* Program instructions */
18552
- int nOp; /* Size of aOp array */
18553
- Mem *aMem; /* Array of memory cells */
18554
- int nMem; /* Number of entries in aMem */
18555
- VdbeCursor **apCsr; /* Element of Vdbe cursors */
18556
- u16 nCursor; /* Number of entries in apCsr */
18557
- void *token; /* Copy of SubProgram.token */
18558
- int nChildMem; /* Number of memory cells for child frame */
18559
- int nChildCsr; /* Number of cursors for child frame */
18560
- i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
18561
- int nChange; /* Statement changes (Vdbe.nChanges) */
18562
- VdbeFrame *pParent; /* Parent of this frame */
18563
-};
18564
-
18565
-#define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
18566
-
18567
-/*
18568
-** A value for VdbeCursor.cacheValid that means the cache is always invalid.
18569
-*/
18570
-#define CACHE_STALE 0
18571
-
18572
-/*
18573
-** Internally, the vdbe manipulates nearly all SQL values as Mem
18574
-** structures. Each Mem struct may cache multiple representations (string,
18575
-** integer etc.) of the same value. A value (and therefore Mem structure)
18576
-** has the following properties:
18577
-**
18578
-** Each value has a manifest type. The manifest type of the value stored
18579
-** in a Mem struct is returned by the MemType(Mem*) macro. The type is
18580
-** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
18581
-** SQLITE_BLOB.
18582
-*/
18583
-struct Mem {
18584
- union {
18585
- i64 i; /* Integer value. */
18586
- int nZero; /* Used when bit MEM_Zero is set in flags */
18587
- FuncDef *pDef; /* Used only when flags==MEM_Agg */
18588
- RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
18589
- VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
18590
- } u;
18591
- double r; /* Real value */
18592
- sqlite3 *db; /* The associated database connection */
18593
- char *z; /* String or BLOB value */
18594
- int n; /* Number of characters in string value, excluding '\0' */
18595
- u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
18596
- u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
18597
- u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
18598
- void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
18599
- char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
18600
-};
18601
-
18602
-/* One or more of the following flags are set to indicate the validOK
18603
-** representations of the value stored in the Mem struct.
18604
-**
18605
-** If the MEM_Null flag is set, then the value is an SQL NULL value.
18606
-** No other flags may be set in this case.
18607
-**
18608
-** If the MEM_Str flag is set then Mem.z points at a string representation.
18609
-** Usually this is encoded in the same unicode encoding as the main
18610
-** database (see below for exceptions). If the MEM_Term flag is also
18611
-** set, then the string is nul terminated. The MEM_Int and MEM_Real
18612
-** flags may coexist with the MEM_Str flag.
18613
-**
18614
-** Multiple of these values can appear in Mem.flags. But only one
18615
-** at a time can appear in Mem.type.
18616
-*/
18617
-#define MEM_Null 0x0001 /* Value is NULL */
18618
-#define MEM_Str 0x0002 /* Value is a string */
18619
-#define MEM_Int 0x0004 /* Value is an integer */
18620
-#define MEM_Real 0x0008 /* Value is a real number */
18621
-#define MEM_Blob 0x0010 /* Value is a BLOB */
18622
-#define MEM_RowSet 0x0020 /* Value is a RowSet object */
18623
-#define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
18624
-#define MEM_TypeMask 0x00ff /* Mask of type bits */
18625
-
18626
-/* Whenever Mem contains a valid string or blob representation, one of
18627
-** the following flags must be set to determine the memory management
18628
-** policy for Mem.z. The MEM_Term flag tells us whether or not the
18629
-** string is \000 or \u0000 terminated
18630
-*/
18631
-#define MEM_Term 0x0200 /* String rep is nul terminated */
18632
-#define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
18633
-#define MEM_Static 0x0800 /* Mem.z points to a static string */
18634
-#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
18635
-#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
18636
-#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
18637
-
18638
-#ifdef SQLITE_OMIT_INCRBLOB
18639
- #undef MEM_Zero
18640
- #define MEM_Zero 0x0000
18641
-#endif
18642
-
18643
-
18644
-/*
18645
-** Clear any existing type flags from a Mem and replace them with f
18646
-*/
18647
-#define MemSetTypeFlag(p, f) \
18648
- ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
18649
-
18650
-
18651
-/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
18652
-** additional information about auxiliary information bound to arguments
18653
-** of the function. This is used to implement the sqlite3_get_auxdata()
18654
-** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
18655
-** that can be associated with a constant argument to a function. This
18656
-** allows functions such as "regexp" to compile their constant regular
18657
-** expression argument once and reused the compiled code for multiple
18658
-** invocations.
18659
-*/
18660
-struct VdbeFunc {
18661
- FuncDef *pFunc; /* The definition of the function */
18662
- int nAux; /* Number of entries allocated for apAux[] */
18663
- struct AuxData {
18664
- void *pAux; /* Aux data for the i-th argument */
18665
- void (*xDelete)(void *); /* Destructor for the aux data */
18666
- } apAux[1]; /* One slot for each function argument */
18667
-};
18668
-
18669
-/*
18670
-** The "context" argument for a installable function. A pointer to an
18671
-** instance of this structure is the first argument to the routines used
18672
-** implement the SQL functions.
18673
-**
18674
-** There is a typedef for this structure in sqlite.h. So all routines,
18675
-** even the public interface to SQLite, can use a pointer to this structure.
18676
-** But this file is the only place where the internal details of this
18677
-** structure are known.
18678
-**
18679
-** This structure is defined inside of vdbeInt.h because it uses substructures
18680
-** (Mem) which are only defined there.
18681
-*/
18682
-struct sqlite3_context {
18683
- FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
18684
- VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
18685
- Mem s; /* The return value is stored here */
18686
- Mem *pMem; /* Memory cell used to store aggregate context */
18687
- int isError; /* Error code returned by the function. */
18688
- CollSeq *pColl; /* Collating sequence */
18689
-};
18690
-
18691
-/*
18692
-** A Set structure is used for quick testing to see if a value
18693
-** is part of a small set. Sets are used to implement code like
18694
-** this:
18695
-** x.y IN ('hi','hoo','hum')
18696
-*/
18697
-typedef struct Set Set;
18698
-struct Set {
18699
- Hash hash; /* A set is just a hash table */
18700
- HashElem *prev; /* Previously accessed hash elemen */
18701
-};
18702
-
18703
-/*
18704
-** An instance of the virtual machine. This structure contains the complete
18705
-** state of the virtual machine.
18706
-**
18707
-** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()
18708
-** is really a pointer to an instance of this structure.
18709
-**
18710
-** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
18711
-** any virtual table method invocations made by the vdbe program. It is
18712
-** set to 2 for xDestroy method calls and 1 for all other methods. This
18713
-** variable is used for two purposes: to allow xDestroy methods to execute
18714
-** "DROP TABLE" statements and to prevent some nasty side effects of
18715
-** malloc failure when SQLite is invoked recursively by a virtual table
18716
-** method function.
18717
-*/
18718
-struct Vdbe {
18719
- sqlite3 *db; /* The database connection that owns this statement */
18720
- Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
18721
- int nOp; /* Number of instructions in the program */
18722
- int nOpAlloc; /* Number of slots allocated for aOp[] */
18723
- Op *aOp; /* Space to hold the virtual machine's program */
18724
- int nLabel; /* Number of labels used */
18725
- int nLabelAlloc; /* Number of slots allocated in aLabel[] */
18726
- int *aLabel; /* Space to hold the labels */
18727
- Mem **apArg; /* Arguments to currently executing user function */
18728
- Mem *aColName; /* Column names to return */
18729
- Mem *pResultSet; /* Pointer to an array of results */
18730
- u16 nResColumn; /* Number of columns in one row of the result set */
18731
- u16 nCursor; /* Number of slots in apCsr[] */
18732
- VdbeCursor **apCsr; /* One element of this array for each open cursor */
18733
- u8 errorAction; /* Recovery action to do in case of an error */
18734
- u8 okVar; /* True if azVar[] has been initialized */
18735
- ynVar nVar; /* Number of entries in aVar[] */
18736
- Mem *aVar; /* Values for the OP_Variable opcode. */
18737
- char **azVar; /* Name of variables */
18738
- u32 magic; /* Magic number for sanity checking */
18739
- int nMem; /* Number of memory locations currently allocated */
18740
- Mem *aMem; /* The memory locations */
18741
- u32 cacheCtr; /* VdbeCursor row cache generation counter */
18742
- int pc; /* The program counter */
18743
- int rc; /* Value to return */
18744
- char *zErrMsg; /* Error message written here */
18745
- u8 explain; /* True if EXPLAIN present on SQL command */
18746
- u8 changeCntOn; /* True to update the change-counter */
18747
- u8 expired; /* True if the VM needs to be recompiled */
18748
- u8 runOnlyOnce; /* Automatically expire on reset */
18749
- u8 minWriteFileFormat; /* Minimum file format for writable database files */
18750
- u8 inVtabMethod; /* See comments above */
18751
- u8 usesStmtJournal; /* True if uses a statement journal */
18752
- u8 readOnly; /* True for read-only statements */
18753
- u8 isPrepareV2; /* True if prepared with prepare_v2() */
18754
- int nChange; /* Number of db changes made since last reset */
18755
- int btreeMask; /* Bitmask of db->aDb[] entries referenced */
18756
- i64 startTime; /* Time when query started - used for profiling */
18757
- BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
18758
- int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
18759
- char *zSql; /* Text of the SQL statement that generated this */
18760
- void *pFree; /* Free this when deleting the vdbe */
18761
- i64 nFkConstraint; /* Number of imm. FK constraints this VM */
18762
- i64 nStmtDefCons; /* Number of def. constraints when stmt started */
18763
- int iStatement; /* Statement number (or 0 if has not opened stmt) */
18764
-#ifdef SQLITE_DEBUG
18765
- FILE *trace; /* Write an execution trace here, if not NULL */
18766
-#endif
18767
- VdbeFrame *pFrame; /* Parent frame */
18768
- int nFrame; /* Number of frames in pFrame list */
18769
- u32 expmask; /* Binding to these vars invalidates VM */
18770
-};
18771
-
18772
-/*
18773
-** The following are allowed values for Vdbe.magic
18774
-*/
18775
-#define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */
18776
-#define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */
18777
-#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */
18778
-#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */
18779
-
18780
-/*
18781
-** Function prototypes
18782
-*/
18783
-SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
18784
-void sqliteVdbePopStack(Vdbe*,int);
18785
-SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
18786
-#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
18787
-SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
18788
-#endif
18789
-SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
18790
-SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
18791
-SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
18792
-SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
18793
-SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
18794
-
18795
-int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
18796
-SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
18797
-SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
18798
-SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
18799
-SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
18800
-SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
18801
-SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
18802
-SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int);
18803
-SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*);
18804
-SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem*, const Mem*);
18805
-SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
18806
-SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem*, Mem*);
18807
-SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem*);
18808
-SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
18809
-SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem*, i64);
18810
-#ifdef SQLITE_OMIT_FLOATING_POINT
18811
-# define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
18812
-#else
18813
-SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
18814
-#endif
18815
-SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
18816
-SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
18817
-SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
18818
-SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
18819
-SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, int);
18820
-SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*);
18821
-SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
18822
-SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
18823
-SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
18824
-SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
18825
-SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
18826
-SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
18827
-SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
18828
-SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
18829
-SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
18830
-SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
18831
-SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
18832
-SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
18833
-SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
18834
-SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
18835
-SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
18836
-
18837
-#ifndef SQLITE_OMIT_FOREIGN_KEY
18838
-SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
18839
-#else
18840
-# define sqlite3VdbeCheckFk(p,i) 0
18841
-#endif
18842
-
18843
-#ifndef SQLITE_OMIT_SHARED_CACHE
18844
-SQLITE_PRIVATE void sqlite3VdbeMutexArrayEnter(Vdbe *p);
18845
-#else
18846
-# define sqlite3VdbeMutexArrayEnter(p)
18847
-#endif
18848
-
18849
-SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
18850
-#ifdef SQLITE_DEBUG
18851
-SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*);
18852
-SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
18853
-#endif
18854
-SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
18855
-
18856
-#ifndef SQLITE_OMIT_INCRBLOB
18857
-SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *);
18858
-#else
18859
- #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
18860
-#endif
18861
-
18862
-#endif /* !defined(_VDBEINT_H_) */
18863
-
18864
-/************** End of vdbeInt.h *********************************************/
18865
-/************** Continuing where we left off in utf.c ************************/
1886619024
1886719025
#ifndef SQLITE_AMALGAMATION
1886819026
/*
1886919027
** The following constant value is used by the SQLITE_BIGENDIAN and
1887019028
** SQLITE_LITTLEENDIAN macros.
@@ -21891,11 +22049,11 @@
2189122049
}
2189222050
2189322051
2189422052
memset( pFile, 0, sizeof(*pFile) );
2189522053
21896
- OSTRACE( "OPEN want %d\n", flags ));
22054
+ OSTRACE(( "OPEN want %d\n", flags ));
2189722055
2189822056
if( flags & SQLITE_OPEN_READWRITE ){
2189922057
ulOpenMode |= OPEN_ACCESS_READWRITE;
2190022058
OSTRACE(( "OPEN read/write\n" ));
2190122059
}else{
@@ -32701,15 +32859,15 @@
3270132859
** back to sqlite3Malloc().
3270232860
*/
3270332861
static void *pcache1Alloc(int nByte){
3270432862
void *p;
3270532863
assert( sqlite3_mutex_held(pcache1.mutex) );
32864
+ sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
3270632865
if( nByte<=pcache1.szSlot && pcache1.pFree ){
3270732866
assert( pcache1.isInit );
3270832867
p = (PgHdr1 *)pcache1.pFree;
3270932868
pcache1.pFree = pcache1.pFree->pNext;
32710
- sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
3271132869
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
3271232870
}else{
3271332871
3271432872
/* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
3271532873
** global pcache mutex and unlock the pager-cache object pCache. This is
@@ -34150,34 +34308,42 @@
3415034308
** It is used when committing or otherwise ending a transaction. If
3415134309
** the dbModified flag is clear then less work has to be done.
3415234310
**
3415334311
** journalStarted
3415434312
**
34155
-** This flag is set whenever the the main journal is opened and
34156
-** initialized
34313
+** This flag is set during a write-transaction after the first
34314
+** journal-header is written and synced to disk.
3415734315
**
34158
-** The point of this flag is that it must be set after the
34159
-** first journal header in a journal file has been synced to disk.
3416034316
** After this has happened, new pages appended to the database
3416134317
** do not need the PGHDR_NEED_SYNC flag set, as they do not need
3416234318
** to wait for a journal sync before they can be written out to
3416334319
** the database file (see function pager_write()).
3416434320
**
3416534321
** setMaster
3416634322
**
34167
-** This variable is used to ensure that the master journal file name
34168
-** (if any) is only written into the journal file once.
34323
+** When PagerCommitPhaseOne() is called to commit a transaction, it may
34324
+** (or may not) specify a master-journal name to be written into the
34325
+** journal file before it is synced to disk.
3416934326
**
34170
-** When committing a transaction, the master journal file name (if any)
34171
-** may be written into the journal file while the pager is still in
34172
-** PAGER_RESERVED state (see CommitPhaseOne() for the action). It
34173
-** then attempts to upgrade to an exclusive lock. If this attempt
34174
-** fails, then SQLITE_BUSY may be returned to the user and the user
34175
-** may attempt to commit the transaction again later (calling
34176
-** CommitPhaseOne() again). This flag is used to ensure that the
34177
-** master journal name is only written to the journal file the first
34178
-** time CommitPhaseOne() is called.
34327
+** Whether or not a journal file contains a master-journal pointer affects
34328
+** the way in which the journal file is finalized after the transaction is
34329
+** committed or rolled back when running in "journal_mode=PERSIST" mode.
34330
+** If a journal file does not contain a master-journal pointer, it is
34331
+** finalized by overwriting the first journal header with zeroes. If,
34332
+** on the other hand, it does contain a master-journal pointer, the
34333
+** journal file is finalized by truncating it to zero bytes, just as if
34334
+** the connection were running in "journal_mode=truncate" mode.
34335
+**
34336
+** Journal files that contain master journal pointers cannot be finalized
34337
+** simply by overwriting the first journal-header with zeroes, as the
34338
+** master journal pointer could interfere with hot-journal rollback of any
34339
+** subsequently interrupted transaction that reuses the journal file.
34340
+**
34341
+** The flag is cleared as soon as the journal file is finalized (either
34342
+** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
34343
+** journal file from being successfully finalized, the setMaster flag
34344
+** is cleared anyway.
3417934345
**
3418034346
** doNotSpill, doNotSyncSpill
3418134347
**
3418234348
** When enabled, cache spills are prohibited. The doNotSpill variable
3418334349
** inhibits all cache spill and doNotSyncSpill inhibits those spills that
@@ -34941,11 +35107,12 @@
3494135107
int nMaster; /* Length of string zMaster */
3494235108
i64 iHdrOff; /* Offset of header in journal file */
3494335109
i64 jrnlSize; /* Size of journal file on disk */
3494435110
u32 cksum = 0; /* Checksum of string zMaster */
3494535111
34946
- if( !zMaster || pPager->setMaster
35112
+ assert( pPager->setMaster==0 );
35113
+ if( !zMaster
3494735114
|| pPager->journalMode==PAGER_JOURNALMODE_MEMORY
3494835115
|| pPager->journalMode==PAGER_JOURNALMODE_OFF
3494935116
){
3495035117
return SQLITE_OK;
3495135118
}
@@ -38928,10 +39095,30 @@
3892839095
}else{
3892939096
rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
3893039097
}
3893139098
return rc;
3893239099
}
39100
+
39101
+/*
39102
+** This function may only be called while a write-transaction is active in
39103
+** rollback. If the connection is in WAL mode, this call is a no-op.
39104
+** Otherwise, if the connection does not already have an EXCLUSIVE lock on
39105
+** the database file, an attempt is made to obtain one.
39106
+**
39107
+** If the EXCLUSIVE lock is already held or the attempt to obtain it is
39108
+** successful, or the connection is in WAL mode, SQLITE_OK is returned.
39109
+** Otherwise, either SQLITE_BUSY or an SQLITE_IOERR_XXX error code is
39110
+** returned.
39111
+*/
39112
+SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager *pPager){
39113
+ int rc = SQLITE_OK;
39114
+ assert( pPager->state>=PAGER_RESERVED );
39115
+ if( 0==pagerUseWal(pPager) ){
39116
+ rc = pager_wait_on_lock(pPager, PAGER_EXCLUSIVE);
39117
+ }
39118
+ return rc;
39119
+}
3893339120
3893439121
/*
3893539122
** Sync the database file for the pager pPager. zMaster points to the name
3893639123
** of a master journal file that should be written into the individual
3893739124
** journal file. zMaster may be NULL, which is interpreted as no master
@@ -38977,11 +39164,11 @@
3897739164
/* If this is an in-memory db, or no pages have been written to, or this
3897839165
** function has already been called, it is mostly a no-op. However, any
3897939166
** backup in progress needs to be restarted.
3898039167
*/
3898139168
sqlite3BackupRestart(pPager->pBackup);
38982
- }else if( pPager->state!=PAGER_SYNCED && pPager->dbModified ){
39169
+ }else if( pPager->dbModified ){
3898339170
if( pagerUseWal(pPager) ){
3898439171
PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
3898539172
if( pList ){
3898639173
rc = pagerWalFrames(pPager, pList, pPager->dbSize, 1,
3898739174
(pPager->fullSync ? pPager->sync_flags : 0)
@@ -39115,10 +39302,11 @@
3911539302
rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
3911639303
}
3911739304
IOTRACE(("DBSYNC %p\n", pPager))
3911839305
}
3911939306
39307
+ assert( pPager->state!=PAGER_SYNCED );
3912039308
pPager->state = PAGER_SYNCED;
3912139309
}
3912239310
3912339311
commit_phase_one_exit:
3912439312
return rc;
@@ -39282,13 +39470,15 @@
3928239470
/*
3928339471
** Return the approximate number of bytes of memory currently
3928439472
** used by the pager and its associated cache.
3928539473
*/
3928639474
SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
39287
- int perPageSize = pPager->pageSize + pPager->nExtra + 20;
39475
+ int perPageSize = pPager->pageSize + pPager->nExtra + sizeof(PgHdr)
39476
+ + 5*sizeof(void*);
3928839477
return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
39289
- + sqlite3MallocSize(pPager);
39478
+ + sqlite3MallocSize(pPager)
39479
+ + pPager->pageSize;
3929039480
}
3929139481
3929239482
/*
3929339483
** Return the number of references to the specified page.
3929439484
*/
@@ -45683,11 +45873,11 @@
4568345873
assert( !pBt->pCursor );
4568445874
sqlite3PagerClose(pBt->pPager);
4568545875
if( pBt->xFreeSchema && pBt->pSchema ){
4568645876
pBt->xFreeSchema(pBt->pSchema);
4568745877
}
45688
- sqlite3_free(pBt->pSchema);
45878
+ sqlite3DbFree(0, pBt->pSchema);
4568945879
freeTempSpace(pBt);
4569045880
sqlite3_free(pBt);
4569145881
}
4569245882
4569345883
#ifndef SQLITE_OMIT_SHARED_CACHE
@@ -46248,17 +46438,31 @@
4624846438
}
4624946439
p->inTrans = (wrflag?TRANS_WRITE:TRANS_READ);
4625046440
if( p->inTrans>pBt->inTransaction ){
4625146441
pBt->inTransaction = p->inTrans;
4625246442
}
46253
-#ifndef SQLITE_OMIT_SHARED_CACHE
4625446443
if( wrflag ){
46444
+ MemPage *pPage1 = pBt->pPage1;
46445
+#ifndef SQLITE_OMIT_SHARED_CACHE
4625546446
assert( !pBt->pWriter );
4625646447
pBt->pWriter = p;
4625746448
pBt->isExclusive = (u8)(wrflag>1);
46449
+#endif
46450
+
46451
+ /* If the db-size header field is incorrect (as it may be if an old
46452
+ ** client has been writing the database file), update it now. Doing
46453
+ ** this sooner rather than later means the database size can safely
46454
+ ** re-read the database size from page 1 if a savepoint or transaction
46455
+ ** rollback occurs within the transaction.
46456
+ */
46457
+ if( pBt->nPage!=get4byte(&pPage1->aData[28]) ){
46458
+ rc = sqlite3PagerWrite(pPage1->pDbPage);
46459
+ if( rc==SQLITE_OK ){
46460
+ put4byte(&pPage1->aData[28], pBt->nPage);
46461
+ }
46462
+ }
4625846463
}
46259
-#endif
4626046464
}
4626146465
4626246466
4626346467
trans_begun:
4626446468
if( rc==SQLITE_OK && wrflag ){
@@ -46993,13 +47197,15 @@
4699347197
rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
4699447198
if( rc==SQLITE_OK ){
4699547199
if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
4699647200
rc = newDatabase(pBt);
4699747201
pBt->nPage = get4byte(28 + pBt->pPage1->aData);
46998
- if( pBt->nPage==0 ){
46999
- sqlite3PagerPagecount(pBt->pPager, (int*)&pBt->nPage);
47000
- }
47202
+
47203
+ /* The database size was written into the offset 28 of the header
47204
+ ** when the transaction started, so we know that the value at offset
47205
+ ** 28 is nonzero. */
47206
+ assert( pBt->nPage>0 );
4700147207
}
4700247208
sqlite3BtreeLeave(p);
4700347209
}
4700447210
return rc;
4700547211
}
@@ -51428,10 +51634,11 @@
5142851634
i = PENDING_BYTE_PAGE(pBt);
5142951635
if( i<=sCheck.nPage ){
5143051636
sCheck.anRef[i] = 1;
5143151637
}
5143251638
sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000);
51639
+ sCheck.errMsg.useMalloc = 2;
5143351640
5143451641
/* Check the integrity of the freelist
5143551642
*/
5143651643
checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
5143751644
get4byte(&pBt->pPage1->aData[36]), "Main freelist: ");
@@ -51526,10 +51733,33 @@
5152651733
SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree *p){
5152751734
assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
5152851735
return (p && (p->inTrans==TRANS_WRITE));
5152951736
}
5153051737
51738
+#ifndef SQLITE_OMIT_WAL
51739
+/*
51740
+** Run a checkpoint on the Btree passed as the first argument.
51741
+**
51742
+** Return SQLITE_LOCKED if this or any other connection has an open
51743
+** transaction on the shared-cache the argument Btree is connected to.
51744
+*/
51745
+SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree *p){
51746
+ int rc = SQLITE_OK;
51747
+ if( p ){
51748
+ BtShared *pBt = p->pBt;
51749
+ sqlite3BtreeEnter(p);
51750
+ if( pBt->inTransaction!=TRANS_NONE ){
51751
+ rc = SQLITE_LOCKED;
51752
+ }else{
51753
+ rc = sqlite3PagerCheckpoint(pBt->pPager);
51754
+ }
51755
+ sqlite3BtreeLeave(p);
51756
+ }
51757
+ return rc;
51758
+}
51759
+#endif
51760
+
5153151761
/*
5153251762
** Return non-zero if a read (or write) transaction is active.
5153351763
*/
5153451764
SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
5153551765
assert( p );
@@ -51565,11 +51795,11 @@
5156551795
*/
5156651796
SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
5156751797
BtShared *pBt = p->pBt;
5156851798
sqlite3BtreeEnter(p);
5156951799
if( !pBt->pSchema && nBytes ){
51570
- pBt->pSchema = sqlite3MallocZero(nBytes);
51800
+ pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
5157151801
pBt->xFreeSchema = xFree;
5157251802
}
5157351803
sqlite3BtreeLeave(p);
5157451804
return pBt->pSchema;
5157551805
}
@@ -53373,11 +53603,11 @@
5337353603
*ppVal = 0;
5337453604
return SQLITE_OK;
5337553605
}
5337653606
op = pExpr->op;
5337753607
53378
- /* op can only be TK_REGISTER is we have compiled with SQLITE_ENABLE_STAT2.
53608
+ /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT2.
5337953609
** The ifdef here is to enable us to achieve 100% branch test coverage even
5338053610
** when SQLITE_ENABLE_STAT2 is omitted.
5338153611
*/
5338253612
#ifdef SQLITE_ENABLE_STAT2
5338353613
if( op==TK_REGISTER ) op = pExpr->op2;
@@ -54051,47 +54281,55 @@
5405154281
if( ALWAYS(pDef) && (pDef->flags & SQLITE_FUNC_EPHEM)!=0 ){
5405254282
sqlite3DbFree(db, pDef);
5405354283
}
5405454284
}
5405554285
54286
+static void vdbeFreeOpArray(sqlite3 *, Op *, int);
54287
+
5405654288
/*
5405754289
** Delete a P4 value if necessary.
5405854290
*/
5405954291
static void freeP4(sqlite3 *db, int p4type, void *p4){
5406054292
if( p4 ){
54293
+ assert( db );
5406154294
switch( p4type ){
5406254295
case P4_REAL:
5406354296
case P4_INT64:
54064
- case P4_MPRINTF:
5406554297
case P4_DYNAMIC:
5406654298
case P4_KEYINFO:
5406754299
case P4_INTARRAY:
5406854300
case P4_KEYINFO_HANDOFF: {
5406954301
sqlite3DbFree(db, p4);
5407054302
break;
54303
+ }
54304
+ case P4_MPRINTF: {
54305
+ if( db->pnBytesFreed==0 ) sqlite3_free(p4);
54306
+ break;
5407154307
}
5407254308
case P4_VDBEFUNC: {
5407354309
VdbeFunc *pVdbeFunc = (VdbeFunc *)p4;
5407454310
freeEphemeralFunction(db, pVdbeFunc->pFunc);
54075
- sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
54311
+ if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
5407654312
sqlite3DbFree(db, pVdbeFunc);
5407754313
break;
5407854314
}
5407954315
case P4_FUNCDEF: {
5408054316
freeEphemeralFunction(db, (FuncDef*)p4);
5408154317
break;
5408254318
}
5408354319
case P4_MEM: {
54084
- sqlite3ValueFree((sqlite3_value*)p4);
54320
+ if( db->pnBytesFreed==0 ){
54321
+ sqlite3ValueFree((sqlite3_value*)p4);
54322
+ }else{
54323
+ Mem *p = (Mem*)p4;
54324
+ sqlite3DbFree(db, p->zMalloc);
54325
+ sqlite3DbFree(db, p);
54326
+ }
5408554327
break;
5408654328
}
5408754329
case P4_VTAB : {
54088
- sqlite3VtabUnlock((VTable *)p4);
54089
- break;
54090
- }
54091
- case P4_SUBPROGRAM : {
54092
- sqlite3VdbeProgramDelete(db, (SubProgram *)p4, 1);
54330
+ if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
5409354331
break;
5409454332
}
5409554333
}
5409654334
}
5409754335
}
@@ -54113,38 +54351,18 @@
5411354351
}
5411454352
sqlite3DbFree(db, aOp);
5411554353
}
5411654354
5411754355
/*
54118
-** Decrement the ref-count on the SubProgram structure passed as the
54119
-** second argument. If the ref-count reaches zero, free the structure.
54120
-**
54121
-** The array of VDBE opcodes stored as SubProgram.aOp is freed if
54122
-** either the ref-count reaches zero or parameter freeop is non-zero.
54123
-**
54124
-** Since the array of opcodes pointed to by SubProgram.aOp may directly
54125
-** or indirectly contain a reference to the SubProgram structure itself.
54126
-** By passing a non-zero freeop parameter, the caller may ensure that all
54127
-** SubProgram structures and their aOp arrays are freed, even when there
54128
-** are such circular references.
54356
+** Link the SubProgram object passed as the second argument into the linked
54357
+** list at Vdbe.pSubProgram. This list is used to delete all sub-program
54358
+** objects when the VM is no longer required.
5412954359
*/
54130
-SQLITE_PRIVATE void sqlite3VdbeProgramDelete(sqlite3 *db, SubProgram *p, int freeop){
54131
- if( p ){
54132
- assert( p->nRef>0 );
54133
- if( freeop || p->nRef==1 ){
54134
- Op *aOp = p->aOp;
54135
- p->aOp = 0;
54136
- vdbeFreeOpArray(db, aOp, p->nOp);
54137
- p->nOp = 0;
54138
- }
54139
- p->nRef--;
54140
- if( p->nRef==0 ){
54141
- sqlite3DbFree(db, p);
54142
- }
54143
- }
54144
-}
54145
-
54360
+SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *pVdbe, SubProgram *p){
54361
+ p->pNext = pVdbe->pProgram;
54362
+ pVdbe->pProgram = p;
54363
+}
5414654364
5414754365
/*
5414854366
** Change N opcodes starting at addr to No-ops.
5414954367
*/
5415054368
SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe *p, int addr, int N){
@@ -54217,11 +54435,11 @@
5421754435
KeyInfo *pKeyInfo;
5421854436
int nField, nByte;
5421954437
5422054438
nField = ((KeyInfo*)zP4)->nField;
5422154439
nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
54222
- pKeyInfo = sqlite3Malloc( nByte );
54440
+ pKeyInfo = sqlite3DbMallocRaw(0, nByte);
5422354441
pOp->p4.pKeyInfo = pKeyInfo;
5422454442
if( pKeyInfo ){
5422554443
u8 *aSortOrder;
5422654444
memcpy((char*)pKeyInfo, zP4, nByte - nField);
5422754445
aSortOrder = pKeyInfo->aSortOrder;
@@ -54481,10 +54699,16 @@
5448154699
static void releaseMemArray(Mem *p, int N){
5448254700
if( p && N ){
5448354701
Mem *pEnd;
5448454702
sqlite3 *db = p->db;
5448554703
u8 malloc_failed = db->mallocFailed;
54704
+ if( db->pnBytesFreed ){
54705
+ for(pEnd=&p[N]; p<pEnd; p++){
54706
+ sqlite3DbFree(db, p->zMalloc);
54707
+ }
54708
+ return;
54709
+ }
5448654710
for(pEnd=&p[N]; p<pEnd; p++){
5448754711
assert( (&p[1])==pEnd || p[0].db==p[1].db );
5448854712
5448954713
/* This block is really an inlined version of sqlite3VdbeMemRelease()
5449054714
** that takes advantage of the fact that the memory cell value is
@@ -55130,26 +55354,27 @@
5513055354
** be done before determining whether a master journal file is
5513155355
** required, as an xSync() callback may add an attached database
5513255356
** to the transaction.
5513355357
*/
5513455358
rc = sqlite3VtabSync(db, &p->zErrMsg);
55135
- if( rc!=SQLITE_OK ){
55136
- return rc;
55137
- }
5513855359
5513955360
/* This loop determines (a) if the commit hook should be invoked and
5514055361
** (b) how many database files have open write transactions, not
5514155362
** including the temp database. (b) is important because if more than
5514255363
** one database file has an open write transaction, a master journal
5514355364
** file is required for an atomic commit.
5514455365
*/
55145
- for(i=0; i<db->nDb; i++){
55366
+ for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
5514655367
Btree *pBt = db->aDb[i].pBt;
5514755368
if( sqlite3BtreeIsInTrans(pBt) ){
5514855369
needXcommit = 1;
5514955370
if( i!=1 ) nTrans++;
55371
+ rc = sqlite3PagerExclusiveLock(sqlite3BtreePager(pBt));
5515055372
}
55373
+ }
55374
+ if( rc!=SQLITE_OK ){
55375
+ return rc;
5515155376
}
5515255377
5515355378
/* If there are any write-transactions at all, invoke the commit hook */
5515455379
if( needXcommit && db->xCommitCallback ){
5515555380
rc = db->xCommitCallback(db->pCommitArg);
@@ -55285,10 +55510,11 @@
5528555510
if( pBt ){
5528655511
rc = sqlite3BtreeCommitPhaseOne(pBt, zMaster);
5528755512
}
5528855513
}
5528955514
sqlite3OsCloseFree(pMaster);
55515
+ assert( rc!=SQLITE_BUSY );
5529055516
if( rc!=SQLITE_OK ){
5529155517
sqlite3DbFree(db, zMaster);
5529255518
return rc;
5529355519
}
5529455520
@@ -55812,10 +56038,34 @@
5581256038
}
5581356039
pAux->pAux = 0;
5581456040
}
5581556041
}
5581656042
}
56043
+
56044
+/*
56045
+** Free all memory associated with the Vdbe passed as the second argument.
56046
+** The difference between this function and sqlite3VdbeDelete() is that
56047
+** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
56048
+** the database connection.
56049
+*/
56050
+SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3 *db, Vdbe *p){
56051
+ SubProgram *pSub, *pNext;
56052
+ assert( p->db==0 || p->db==db );
56053
+ releaseMemArray(p->aVar, p->nVar);
56054
+ releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
56055
+ for(pSub=p->pProgram; pSub; pSub=pNext){
56056
+ pNext = pSub->pNext;
56057
+ vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
56058
+ sqlite3DbFree(db, pSub);
56059
+ }
56060
+ vdbeFreeOpArray(db, p->aOp, p->nOp);
56061
+ sqlite3DbFree(db, p->aLabel);
56062
+ sqlite3DbFree(db, p->aColName);
56063
+ sqlite3DbFree(db, p->zSql);
56064
+ sqlite3DbFree(db, p->pFree);
56065
+ sqlite3DbFree(db, p);
56066
+}
5581756067
5581856068
/*
5581956069
** Delete an entire VDBE.
5582056070
*/
5582156071
SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){
@@ -55830,20 +56080,13 @@
5583056080
db->pVdbe = p->pNext;
5583156081
}
5583256082
if( p->pNext ){
5583356083
p->pNext->pPrev = p->pPrev;
5583456084
}
55835
- releaseMemArray(p->aVar, p->nVar);
55836
- releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
55837
- vdbeFreeOpArray(db, p->aOp, p->nOp);
55838
- sqlite3DbFree(db, p->aLabel);
55839
- sqlite3DbFree(db, p->aColName);
55840
- sqlite3DbFree(db, p->zSql);
5584156085
p->magic = VDBE_MAGIC_DEAD;
55842
- sqlite3DbFree(db, p->pFree);
5584356086
p->db = 0;
55844
- sqlite3DbFree(db, p);
56087
+ sqlite3VdbeDeleteObject(db, p);
5584556088
}
5584656089
5584756090
/*
5584856091
** Make sure the cursor p is ready to read or write the row to which it
5584956092
** was last positioned. Return an error code if an OOM fault or I/O error
@@ -55865,15 +56108,12 @@
5586556108
#endif
5586656109
assert( p->isTable );
5586756110
rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
5586856111
if( rc ) return rc;
5586956112
p->lastRowid = p->movetoTarget;
55870
- p->rowidIsValid = ALWAYS(res==0) ?1:0;
55871
- if( NEVER(res<0) ){
55872
- rc = sqlite3BtreeNext(p->pCursor, &res);
55873
- if( rc ) return rc;
55874
- }
56113
+ if( res!=0 ) return SQLITE_CORRUPT_BKPT;
56114
+ p->rowidIsValid = 1;
5587556115
#ifdef SQLITE_TEST
5587656116
sqlite3_search_count++;
5587756117
#endif
5587856118
p->deferredMoveto = 0;
5587956119
p->cacheStatus = CACHE_STALE;
@@ -57013,11 +57253,11 @@
5701357253
/* Invoke the profile callback if there is one
5701457254
*/
5701557255
if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
5701657256
sqlite3_int64 iNow;
5701757257
sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
57018
- db->xProfile(db->pProfileArg, p->zSql, iNow - p->startTime);
57258
+ db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
5701957259
}
5702057260
#endif
5702157261
5702257262
if( rc==SQLITE_DONE ){
5702357263
assert( p->rc==SQLITE_OK );
@@ -58628,10 +58868,24 @@
5862858868
for(p=db->pSavepoint; p; p=p->pNext) n++;
5862958869
assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
5863058870
return 1;
5863158871
}
5863258872
#endif
58873
+
58874
+/*
58875
+** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
58876
+** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
58877
+** in memory obtained from sqlite3DbMalloc).
58878
+*/
58879
+static void importVtabErrMsg(Vdbe *p, sqlite3_vtab *pVtab){
58880
+ sqlite3 *db = p->db;
58881
+ sqlite3DbFree(db, p->zErrMsg);
58882
+ p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
58883
+ sqlite3_free(pVtab->zErrMsg);
58884
+ pVtab->zErrMsg = 0;
58885
+}
58886
+
5863358887
5863458888
/*
5863558889
** Execute as much of a VDBE program as we can then return.
5863658890
**
5863758891
** sqlite3VdbeMakeReady() must be called before this routine in order to
@@ -62627,13 +62881,11 @@
6262762881
}else if( u.bi.pC->pVtabCursor ){
6262862882
u.bi.pVtab = u.bi.pC->pVtabCursor->pVtab;
6262962883
u.bi.pModule = u.bi.pVtab->pModule;
6263062884
assert( u.bi.pModule->xRowid );
6263162885
rc = u.bi.pModule->xRowid(u.bi.pC->pVtabCursor, &u.bi.v);
62632
- sqlite3DbFree(db, p->zErrMsg);
62633
- p->zErrMsg = u.bi.pVtab->zErrMsg;
62634
- u.bi.pVtab->zErrMsg = 0;
62886
+ importVtabErrMsg(p, u.bi.pVtab);
6263562887
#endif /* SQLITE_OMIT_VIRTUALTABLE */
6263662888
}else{
6263762889
assert( u.bi.pC->pCursor!=0 );
6263862890
rc = sqlite3VdbeCursorMoveto(u.bi.pC);
6263962891
if( rc ) goto abort_due_to_error;
@@ -64018,15 +64270,11 @@
6401864270
#if 0 /* local variables moved into u.cf */
6401964271
VTable *pVTab;
6402064272
#endif /* local variables moved into u.cf */
6402164273
u.cf.pVTab = pOp->p4.pVtab;
6402264274
rc = sqlite3VtabBegin(db, u.cf.pVTab);
64023
- if( u.cf.pVTab ){
64024
- sqlite3DbFree(db, p->zErrMsg);
64025
- p->zErrMsg = u.cf.pVTab->pVtab->zErrMsg;
64026
- u.cf.pVTab->pVtab->zErrMsg = 0;
64027
- }
64275
+ if( u.cf.pVTab ) importVtabErrMsg(p, u.cf.pVTab->pVtab);
6402864276
break;
6402964277
}
6403064278
#endif /* SQLITE_OMIT_VIRTUALTABLE */
6403164279
6403264280
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -64074,13 +64322,11 @@
6407464322
u.cg.pVtabCursor = 0;
6407564323
u.cg.pVtab = pOp->p4.pVtab->pVtab;
6407664324
u.cg.pModule = (sqlite3_module *)u.cg.pVtab->pModule;
6407764325
assert(u.cg.pVtab && u.cg.pModule);
6407864326
rc = u.cg.pModule->xOpen(u.cg.pVtab, &u.cg.pVtabCursor);
64079
- sqlite3DbFree(db, p->zErrMsg);
64080
- p->zErrMsg = u.cg.pVtab->zErrMsg;
64081
- u.cg.pVtab->zErrMsg = 0;
64327
+ importVtabErrMsg(p, u.cg.pVtab);
6408264328
if( SQLITE_OK==rc ){
6408364329
/* Initialize sqlite3_vtab_cursor base class */
6408464330
u.cg.pVtabCursor->pVtab = u.cg.pVtab;
6408564331
6408664332
/* Initialise vdbe cursor object */
@@ -64155,13 +64401,11 @@
6415564401
}
6415664402
6415764403
p->inVtabMethod = 1;
6415864404
rc = u.ch.pModule->xFilter(u.ch.pVtabCursor, u.ch.iQuery, pOp->p4.z, u.ch.nArg, u.ch.apArg);
6415964405
p->inVtabMethod = 0;
64160
- sqlite3DbFree(db, p->zErrMsg);
64161
- p->zErrMsg = u.ch.pVtab->zErrMsg;
64162
- u.ch.pVtab->zErrMsg = 0;
64406
+ importVtabErrMsg(p, u.ch.pVtab);
6416364407
if( rc==SQLITE_OK ){
6416464408
u.ch.res = u.ch.pModule->xEof(u.ch.pVtabCursor);
6416564409
}
6416664410
6416764411
if( u.ch.res ){
@@ -64209,13 +64453,11 @@
6420964453
*/
6421064454
sqlite3VdbeMemMove(&u.ci.sContext.s, u.ci.pDest);
6421164455
MemSetTypeFlag(&u.ci.sContext.s, MEM_Null);
6421264456
6421364457
rc = u.ci.pModule->xColumn(pCur->pVtabCursor, &u.ci.sContext, pOp->p2);
64214
- sqlite3DbFree(db, p->zErrMsg);
64215
- p->zErrMsg = u.ci.pVtab->zErrMsg;
64216
- u.ci.pVtab->zErrMsg = 0;
64458
+ importVtabErrMsg(p, u.ci.pVtab);
6421764459
if( u.ci.sContext.isError ){
6421864460
rc = u.ci.sContext.isError;
6421964461
}
6422064462
6422164463
/* Copy the result of the function to the P3 register. We
@@ -64266,13 +64508,11 @@
6426664508
** some other method is next invoked on the save virtual table cursor.
6426764509
*/
6426864510
p->inVtabMethod = 1;
6426964511
rc = u.cj.pModule->xNext(u.cj.pCur->pVtabCursor);
6427064512
p->inVtabMethod = 0;
64271
- sqlite3DbFree(db, p->zErrMsg);
64272
- p->zErrMsg = u.cj.pVtab->zErrMsg;
64273
- u.cj.pVtab->zErrMsg = 0;
64513
+ importVtabErrMsg(p, u.cj.pVtab);
6427464514
if( rc==SQLITE_OK ){
6427564515
u.cj.res = u.cj.pModule->xEof(u.cj.pCur->pVtabCursor);
6427664516
}
6427764517
6427864518
if( !u.cj.res ){
@@ -64300,13 +64540,11 @@
6430064540
u.ck.pName = &aMem[pOp->p1];
6430164541
assert( u.ck.pVtab->pModule->xRename );
6430264542
REGISTER_TRACE(pOp->p1, u.ck.pName);
6430364543
assert( u.ck.pName->flags & MEM_Str );
6430464544
rc = u.ck.pVtab->pModule->xRename(u.ck.pVtab, u.ck.pName->z);
64305
- sqlite3DbFree(db, p->zErrMsg);
64306
- p->zErrMsg = u.ck.pVtab->zErrMsg;
64307
- u.ck.pVtab->zErrMsg = 0;
64545
+ importVtabErrMsg(p, u.ck.pVtab);
6430864546
6430964547
break;
6431064548
}
6431164549
#endif
6431264550
@@ -64356,13 +64594,11 @@
6435664594
sqlite3VdbeMemStoreType(u.cl.pX);
6435764595
u.cl.apArg[u.cl.i] = u.cl.pX;
6435864596
u.cl.pX++;
6435964597
}
6436064598
rc = u.cl.pModule->xUpdate(u.cl.pVtab, u.cl.nArg, u.cl.apArg, &u.cl.rowid);
64361
- sqlite3DbFree(db, p->zErrMsg);
64362
- p->zErrMsg = u.cl.pVtab->zErrMsg;
64363
- u.cl.pVtab->zErrMsg = 0;
64599
+ importVtabErrMsg(p, u.cl.pVtab);
6436464600
if( rc==SQLITE_OK && pOp->p1 ){
6436564601
assert( u.cl.nArg>1 && u.cl.apArg[0] && (u.cl.apArg[0]->flags&MEM_Null) );
6436664602
db->lastRowid = u.cl.rowid;
6436764603
}
6436864604
p->nChange++;
@@ -66811,30 +67047,37 @@
6681167047
assert( pExpr->pTab && j<pExpr->pTab->nCol );
6681267048
return pExpr->pTab->aCol[j].affinity;
6681367049
}
6681467050
return pExpr->affinity;
6681567051
}
67052
+
67053
+/*
67054
+** Set the explicit collating sequence for an expression to the
67055
+** collating sequence supplied in the second argument.
67056
+*/
67057
+SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr *pExpr, CollSeq *pColl){
67058
+ if( pExpr && pColl ){
67059
+ pExpr->pColl = pColl;
67060
+ pExpr->flags |= EP_ExpCollate;
67061
+ }
67062
+ return pExpr;
67063
+}
6681667064
6681767065
/*
6681867066
** Set the collating sequence for expression pExpr to be the collating
6681967067
** sequence named by pToken. Return a pointer to the revised expression.
6682067068
** The collating sequence is marked as "explicit" using the EP_ExpCollate
6682167069
** flag. An explicit collating sequence will override implicit
6682267070
** collating sequences.
6682367071
*/
66824
-SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Parse *pParse, Expr *pExpr, Token *pCollName){
67072
+SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr *pExpr, Token *pCollName){
6682567073
char *zColl = 0; /* Dequoted name of collation sequence */
6682667074
CollSeq *pColl;
6682767075
sqlite3 *db = pParse->db;
6682867076
zColl = sqlite3NameFromToken(db, pCollName);
66829
- if( pExpr && zColl ){
66830
- pColl = sqlite3LocateCollSeq(pParse, zColl);
66831
- if( pColl ){
66832
- pExpr->pColl = pColl;
66833
- pExpr->flags |= EP_ExpCollate;
66834
- }
66835
- }
67077
+ pColl = sqlite3LocateCollSeq(pParse, zColl);
67078
+ sqlite3ExprSetColl(pExpr, pColl);
6683667079
sqlite3DbFree(db, zColl);
6683767080
return pExpr;
6683867081
}
6683967082
6684067083
/*
@@ -68262,18 +68505,24 @@
6826268505
6826368506
if( eType==0 ){
6826468507
/* Could not found an existing table or index to use as the RHS b-tree.
6826568508
** We will have to generate an ephemeral table to do the job.
6826668509
*/
68510
+ double savedNQueryLoop = pParse->nQueryLoop;
6826768511
int rMayHaveNull = 0;
6826868512
eType = IN_INDEX_EPH;
6826968513
if( prNotFound ){
6827068514
*prNotFound = rMayHaveNull = ++pParse->nMem;
68271
- }else if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
68272
- eType = IN_INDEX_ROWID;
68515
+ }else{
68516
+ testcase( pParse->nQueryLoop>(double)1 );
68517
+ pParse->nQueryLoop = (double)1;
68518
+ if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
68519
+ eType = IN_INDEX_ROWID;
68520
+ }
6827368521
}
6827468522
sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
68523
+ pParse->nQueryLoop = savedNQueryLoop;
6827568524
}else{
6827668525
pX->iTable = iTab;
6827768526
}
6827868527
return eType;
6827968528
}
@@ -71302,11 +71551,10 @@
7130271551
*/
7130371552
pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
7130471553
if( !pNew ) goto exit_begin_add_column;
7130571554
pParse->pNewTable = pNew;
7130671555
pNew->nRef = 1;
71307
- pNew->dbMem = pTab->dbMem;
7130871556
pNew->nCol = pTab->nCol;
7130971557
assert( pNew->nCol>0 );
7131071558
nAlloc = (((pNew->nCol-1)/8)*8)+8;
7131171559
assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
7131271560
pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
@@ -71831,23 +72079,21 @@
7183172079
7183272080
/*
7183372081
** If the Index.aSample variable is not NULL, delete the aSample[] array
7183472082
** and its contents.
7183572083
*/
71836
-SQLITE_PRIVATE void sqlite3DeleteIndexSamples(Index *pIdx){
72084
+SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
7183772085
#ifdef SQLITE_ENABLE_STAT2
7183872086
if( pIdx->aSample ){
7183972087
int j;
71840
- sqlite3 *dbMem = pIdx->pTable->dbMem;
7184172088
for(j=0; j<SQLITE_INDEX_SAMPLES; j++){
7184272089
IndexSample *p = &pIdx->aSample[j];
7184372090
if( p->eType==SQLITE_TEXT || p->eType==SQLITE_BLOB ){
71844
- sqlite3DbFree(pIdx->pTable->dbMem, p->u.z);
72091
+ sqlite3DbFree(db, p->u.z);
7184572092
}
7184672093
}
71847
- sqlite3DbFree(dbMem, pIdx->aSample);
71848
- pIdx->aSample = 0;
72094
+ sqlite3DbFree(db, pIdx->aSample);
7184972095
}
7185072096
#else
7185172097
UNUSED_PARAMETER(pIdx);
7185272098
#endif
7185372099
}
@@ -71884,11 +72130,12 @@
7188472130
7188572131
/* Clear any prior statistics */
7188672132
for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
7188772133
Index *pIdx = sqliteHashData(i);
7188872134
sqlite3DefaultRowEst(pIdx);
71889
- sqlite3DeleteIndexSamples(pIdx);
72135
+ sqlite3DeleteIndexSamples(db, pIdx);
72136
+ pIdx->aSample = 0;
7189072137
}
7189172138
7189272139
/* Check to make sure the sqlite_stat1 table exists */
7189372140
sInfo.db = db;
7189472141
sInfo.zDatabase = db->aDb[iDb].zName;
@@ -71928,22 +72175,21 @@
7192872175
while( sqlite3_step(pStmt)==SQLITE_ROW ){
7192972176
char *zIndex = (char *)sqlite3_column_text(pStmt, 0);
7193072177
Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
7193172178
if( pIdx ){
7193272179
int iSample = sqlite3_column_int(pStmt, 1);
71933
- sqlite3 *dbMem = pIdx->pTable->dbMem;
71934
- assert( dbMem==db || dbMem==0 );
7193572180
if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
7193672181
int eType = sqlite3_column_type(pStmt, 2);
7193772182
7193872183
if( pIdx->aSample==0 ){
7193972184
static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
71940
- pIdx->aSample = (IndexSample *)sqlite3DbMallocZero(dbMem, sz);
72185
+ pIdx->aSample = (IndexSample *)sqlite3DbMallocRaw(0, sz);
7194172186
if( pIdx->aSample==0 ){
7194272187
db->mallocFailed = 1;
7194372188
break;
7194472189
}
72190
+ memset(pIdx->aSample, 0, sz);
7194572191
}
7194672192
7194772193
assert( pIdx->aSample );
7194872194
{
7194972195
IndexSample *pSample = &pIdx->aSample[iSample];
@@ -71962,14 +72208,12 @@
7196272208
}
7196372209
pSample->nByte = (u8)n;
7196472210
if( n < 1){
7196572211
pSample->u.z = 0;
7196672212
}else{
71967
- pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
71968
- if( pSample->u.z ){
71969
- memcpy(pSample->u.z, z, n);
71970
- }else{
72213
+ pSample->u.z = sqlite3DbStrNDup(0, z, n);
72214
+ if( pSample->u.z==0 ){
7197172215
db->mallocFailed = 1;
7197272216
break;
7197372217
}
7197472218
}
7197572219
}
@@ -73128,37 +73372,18 @@
7312873372
}
7312973373
7313073374
/*
7313173375
** Reclaim the memory used by an index
7313273376
*/
73133
-static void freeIndex(Index *p){
73134
- sqlite3 *db = p->pTable->dbMem;
73377
+static void freeIndex(sqlite3 *db, Index *p){
7313573378
#ifndef SQLITE_OMIT_ANALYZE
73136
- sqlite3DeleteIndexSamples(p);
73379
+ sqlite3DeleteIndexSamples(db, p);
7313773380
#endif
7313873381
sqlite3DbFree(db, p->zColAff);
7313973382
sqlite3DbFree(db, p);
7314073383
}
7314173384
73142
-/*
73143
-** Remove the given index from the index hash table, and free
73144
-** its memory structures.
73145
-**
73146
-** The index is removed from the database hash tables but
73147
-** it is not unlinked from the Table that it indexes.
73148
-** Unlinking from the Table must be done by the calling function.
73149
-*/
73150
-static void sqlite3DeleteIndex(Index *p){
73151
- Index *pOld;
73152
- const char *zName = p->zName;
73153
-
73154
- pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName,
73155
- sqlite3Strlen30(zName), 0);
73156
- assert( pOld==0 || pOld==p );
73157
- freeIndex(p);
73158
-}
73159
-
7316073385
/*
7316173386
** For the index called zIdxName which is found in the database iDb,
7316273387
** unlike that index from its Table then remove the index from
7316373388
** the index hash table and free all memory structures associated
7316473389
** with the index.
@@ -73181,11 +73406,11 @@
7318173406
while( ALWAYS(p) && p->pNext!=pIndex ){ p = p->pNext; }
7318273407
if( ALWAYS(p && p->pNext==pIndex) ){
7318373408
p->pNext = pIndex->pNext;
7318473409
}
7318573410
}
73186
- freeIndex(pIndex);
73411
+ freeIndex(db, pIndex);
7318773412
}
7318873413
db->flags |= SQLITE_InternChanges;
7318973414
}
7319073415
7319173416
/*
@@ -73252,17 +73477,16 @@
7325273477
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
7325373478
db->flags &= ~SQLITE_InternChanges;
7325473479
}
7325573480
7325673481
/*
73257
-** Clear the column names from a table or view.
73482
+** Delete memory allocated for the column names of a table or view (the
73483
+** Table.aCol[] array).
7325873484
*/
73259
-static void sqliteResetColumnNames(Table *pTable){
73485
+static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
7326073486
int i;
7326173487
Column *pCol;
73262
- sqlite3 *db = pTable->dbMem;
73263
- testcase( db==0 );
7326473488
assert( pTable!=0 );
7326573489
if( (pCol = pTable->aCol)!=0 ){
7326673490
for(i=0; i<pTable->nCol; i++, pCol++){
7326773491
sqlite3DbFree(db, pCol->zName);
7326873492
sqlite3ExprDelete(db, pCol->pDflt);
@@ -73270,12 +73494,10 @@
7327073494
sqlite3DbFree(db, pCol->zType);
7327173495
sqlite3DbFree(db, pCol->zColl);
7327273496
}
7327373497
sqlite3DbFree(db, pTable->aCol);
7327473498
}
73275
- pTable->aCol = 0;
73276
- pTable->nCol = 0;
7327773499
}
7327873500
7327973501
/*
7328073502
** Remove the memory data structures associated with the given
7328173503
** Table. No changes are made to disk by this routine.
@@ -73283,46 +73505,48 @@
7328373505
** This routine just deletes the data structure. It does not unlink
7328473506
** the table data structure from the hash table. But it does destroy
7328573507
** memory structures of the indices and foreign keys associated with
7328673508
** the table.
7328773509
*/
73288
-SQLITE_PRIVATE void sqlite3DeleteTable(Table *pTable){
73510
+SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
7328973511
Index *pIndex, *pNext;
73290
- sqlite3 *db;
7329173512
73292
- if( pTable==0 ) return;
73293
- db = pTable->dbMem;
73294
- testcase( db==0 );
73513
+ assert( !pTable || pTable->nRef>0 );
7329573514
7329673515
/* Do not delete the table until the reference count reaches zero. */
73297
- pTable->nRef--;
73298
- if( pTable->nRef>0 ){
73299
- return;
73300
- }
73301
- assert( pTable->nRef==0 );
73302
-
73303
- /* Delete all indices associated with this table
73304
- */
73516
+ if( !pTable ) return;
73517
+ if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
73518
+
73519
+ /* Delete all indices associated with this table. */
7330573520
for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
7330673521
pNext = pIndex->pNext;
7330773522
assert( pIndex->pSchema==pTable->pSchema );
73308
- sqlite3DeleteIndex(pIndex);
73523
+ if( !db || db->pnBytesFreed==0 ){
73524
+ char *zName = pIndex->zName;
73525
+ TESTONLY ( Index *pOld = ) sqlite3HashInsert(
73526
+ &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
73527
+ );
73528
+ assert( pOld==pIndex || pOld==0 );
73529
+ }
73530
+ freeIndex(db, pIndex);
7330973531
}
7331073532
7331173533
/* Delete any foreign keys attached to this table. */
73312
- sqlite3FkDelete(pTable);
73534
+ sqlite3FkDelete(db, pTable);
7331373535
7331473536
/* Delete the Table structure itself.
7331573537
*/
73316
- sqliteResetColumnNames(pTable);
73538
+ sqliteDeleteColumnNames(db, pTable);
7331773539
sqlite3DbFree(db, pTable->zName);
7331873540
sqlite3DbFree(db, pTable->zColAff);
7331973541
sqlite3SelectDelete(db, pTable->pSelect);
7332073542
#ifndef SQLITE_OMIT_CHECK
7332173543
sqlite3ExprDelete(db, pTable->pCheck);
7332273544
#endif
73323
- sqlite3VtabClear(pTable);
73545
+#ifndef SQLITE_OMIT_VIRTUALTABLE
73546
+ sqlite3VtabClear(db, pTable);
73547
+#endif
7332473548
sqlite3DbFree(db, pTable);
7332573549
}
7332673550
7332773551
/*
7332873552
** Unlink the given table from the hash tables and the delete the
@@ -73337,11 +73561,11 @@
7333773561
assert( zTabName );
7333873562
testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
7333973563
pDb = &db->aDb[iDb];
7334073564
p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
7334173565
sqlite3Strlen30(zTabName),0);
73342
- sqlite3DeleteTable(p);
73566
+ sqlite3DeleteTable(db, p);
7334373567
db->flags |= SQLITE_InternChanges;
7334473568
}
7334573569
7334673570
/*
7334773571
** Given a token, return a string that consists of the text of that
@@ -73605,11 +73829,10 @@
7360573829
}
7360673830
pTable->zName = zName;
7360773831
pTable->iPKey = -1;
7360873832
pTable->pSchema = db->aDb[iDb].pSchema;
7360973833
pTable->nRef = 1;
73610
- pTable->dbMem = 0;
7361173834
assert( pParse->pNewTable==0 );
7361273835
pParse->pNewTable = pTable;
7361373836
7361473837
/* If this is the magic sqlite_sequence table used by autoincrement,
7361573838
** then record a pointer to this table in the main database structure
@@ -74157,11 +74380,11 @@
7415774380
zSep = "\n ";
7415874381
zSep2 = ",\n ";
7415974382
zEnd = "\n)";
7416074383
}
7416174384
n += 35 + 6*p->nCol;
74162
- zStmt = sqlite3Malloc( n );
74385
+ zStmt = sqlite3DbMallocRaw(0, n);
7416374386
if( zStmt==0 ){
7416474387
db->mallocFailed = 1;
7416574388
return 0;
7416674389
}
7416774390
sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
@@ -74338,11 +74561,11 @@
7433874561
assert( p->aCol==0 );
7433974562
p->nCol = pSelTab->nCol;
7434074563
p->aCol = pSelTab->aCol;
7434174564
pSelTab->nCol = 0;
7434274565
pSelTab->aCol = 0;
74343
- sqlite3DeleteTable(pSelTab);
74566
+ sqlite3DeleteTable(db, pSelTab);
7434474567
}
7434574568
}
7434674569
7434774570
/* Compute the complete text of the CREATE statement */
7434874571
if( pSelect ){
@@ -74582,11 +74805,11 @@
7458274805
assert( pTable->aCol==0 );
7458374806
pTable->nCol = pSelTab->nCol;
7458474807
pTable->aCol = pSelTab->aCol;
7458574808
pSelTab->nCol = 0;
7458674809
pSelTab->aCol = 0;
74587
- sqlite3DeleteTable(pSelTab);
74810
+ sqlite3DeleteTable(db, pSelTab);
7458874811
pTable->pSchema->flags |= DB_UnresetViews;
7458974812
}else{
7459074813
pTable->nCol = 0;
7459174814
nErr++;
7459274815
}
@@ -74607,11 +74830,13 @@
7460774830
HashElem *i;
7460874831
if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
7460974832
for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
7461074833
Table *pTab = sqliteHashData(i);
7461174834
if( pTab->pSelect ){
74612
- sqliteResetColumnNames(pTab);
74835
+ sqliteDeleteColumnNames(db, pTab);
74836
+ pTab->aCol = 0;
74837
+ pTab->nCol = 0;
7461374838
}
7461474839
}
7461574840
DbClearProperty(db, idx, DB_UnresetViews);
7461674841
}
7461774842
#else
@@ -75604,11 +75829,11 @@
7560475829
}
7560575830
7560675831
/* Clean up before exiting */
7560775832
exit_create_index:
7560875833
if( pIndex ){
75609
- sqlite3_free(pIndex->zColAff);
75834
+ sqlite3DbFree(db, pIndex->zColAff);
7561075835
sqlite3DbFree(db, pIndex);
7561175836
}
7561275837
sqlite3ExprListDelete(db, pList);
7561375838
sqlite3SrcListDelete(db, pTblName);
7561475839
sqlite3DbFree(db, zName);
@@ -75983,11 +76208,11 @@
7598376208
for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
7598476209
sqlite3DbFree(db, pItem->zDatabase);
7598576210
sqlite3DbFree(db, pItem->zName);
7598676211
sqlite3DbFree(db, pItem->zAlias);
7598776212
sqlite3DbFree(db, pItem->zIndex);
75988
- sqlite3DeleteTable(pItem->pTab);
76213
+ sqlite3DeleteTable(db, pItem->pTab);
7598976214
sqlite3SelectDelete(db, pItem->pSelect);
7599076215
sqlite3ExprDelete(db, pItem->pOn);
7599176216
sqlite3IdListDelete(db, pItem->pUsing);
7599276217
}
7599376218
sqlite3DbFree(db, pList);
@@ -76914,12 +77139,11 @@
7691477139
}
7691577140
sqlite3HashClear(&temp2);
7691677141
sqlite3HashInit(&pSchema->tblHash);
7691777142
for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
7691877143
Table *pTab = sqliteHashData(pElem);
76919
- assert( pTab->dbMem==0 );
76920
- sqlite3DeleteTable(pTab);
77144
+ sqlite3DeleteTable(0, pTab);
7692177145
}
7692277146
sqlite3HashClear(&temp1);
7692377147
sqlite3HashClear(&pSchema->fkeyHash);
7692477148
pSchema->pSeqTab = 0;
7692577149
pSchema->flags &= ~DB_SchemaLoaded;
@@ -76932,11 +77156,11 @@
7693277156
SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
7693377157
Schema * p;
7693477158
if( pBt ){
7693577159
p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree);
7693677160
}else{
76937
- p = (Schema *)sqlite3MallocZero(sizeof(Schema));
77161
+ p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
7693877162
}
7693977163
if( !p ){
7694077164
db->mallocFailed = 1;
7694177165
}else if ( 0==p->file_format ){
7694277166
sqlite3HashInit(&p->tblHash);
@@ -76973,11 +77197,11 @@
7697377197
SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
7697477198
struct SrcList_item *pItem = pSrc->a;
7697577199
Table *pTab;
7697677200
assert( pItem && pSrc->nSrc==1 );
7697777201
pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase);
76978
- sqlite3DeleteTable(pItem->pTab);
77202
+ sqlite3DeleteTable(pParse->db, pItem->pTab);
7697977203
pItem->pTab = pTab;
7698077204
if( pTab ){
7698177205
pTab->nRef++;
7698277206
}
7698377207
if( sqlite3IndexedByLookup(pParse, pItem) ){
@@ -78370,12 +78594,14 @@
7837078594
sqlite3_value **argv
7837178595
){
7837278596
const char *zOptName;
7837378597
assert( argc==1 );
7837478598
UNUSED_PARAMETER(argc);
78375
- /* IMP: R-xxxx This function is an SQL wrapper around the
78376
- ** sqlite3_compileoption_used() C interface. */
78599
+ /* IMP: R-39564-36305 The sqlite_compileoption_used() SQL
78600
+ ** function is a wrapper around the sqlite3_compileoption_used() C/C++
78601
+ ** function.
78602
+ */
7837778603
if( (zOptName = (const char*)sqlite3_value_text(argv[0]))!=0 ){
7837878604
sqlite3_result_int(context, sqlite3_compileoption_used(zOptName));
7837978605
}
7838078606
}
7838178607
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
@@ -78392,12 +78618,13 @@
7839278618
sqlite3_value **argv
7839378619
){
7839478620
int n;
7839578621
assert( argc==1 );
7839678622
UNUSED_PARAMETER(argc);
78397
- /* IMP: R-xxxx This function is an SQL wrapper around the
78398
- ** sqlite3_compileoption_get() C interface. */
78623
+ /* IMP: R-04922-24076 The sqlite_compileoption_get() SQL function
78624
+ ** is a wrapper around the sqlite3_compileoption_get() C/C++ function.
78625
+ */
7839978626
n = sqlite3_value_int(argv[0]);
7840078627
sqlite3_result_text(context, sqlite3_compileoption_get(n), -1, SQLITE_STATIC);
7840178628
}
7840278629
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
7840378630
@@ -78592,18 +78819,18 @@
7859278819
nOut += nRep - nPattern;
7859378820
testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
7859478821
testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
7859578822
if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
7859678823
sqlite3_result_error_toobig(context);
78597
- sqlite3DbFree(db, zOut);
78824
+ sqlite3_free(zOut);
7859878825
return;
7859978826
}
7860078827
zOld = zOut;
7860178828
zOut = sqlite3_realloc(zOut, (int)nOut);
7860278829
if( zOut==0 ){
7860378830
sqlite3_result_error_nomem(context);
78604
- sqlite3DbFree(db, zOld);
78831
+ sqlite3_free(zOld);
7860578832
return;
7860678833
}
7860778834
memcpy(&zOut[j], zRep, nRep);
7860878835
j += nRep;
7860978836
i += nPattern-1;
@@ -78960,11 +79187,11 @@
7896079187
pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
7896179188
7896279189
if( pAccum ){
7896379190
sqlite3 *db = sqlite3_context_db_handle(context);
7896479191
int firstTerm = pAccum->useMalloc==0;
78965
- pAccum->useMalloc = 1;
79192
+ pAccum->useMalloc = 2;
7896679193
pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
7896779194
if( !firstTerm ){
7896879195
if( argc==2 ){
7896979196
zSep = (char*)sqlite3_value_text(argv[1]);
7897079197
nSep = sqlite3_value_bytes(argv[1]);
@@ -79677,11 +79904,12 @@
7967779904
/* Set the collation sequence and affinity of the LHS of each TK_EQ
7967879905
** expression to the parent key column defaults. */
7967979906
if( pIdx ){
7968079907
Column *pCol;
7968179908
iCol = pIdx->aiColumn[i];
79682
- pCol = &pIdx->pTable->aCol[iCol];
79909
+ pCol = &pTab->aCol[iCol];
79910
+ if( pTab->iPKey==iCol ) iCol = -1;
7968379911
pLeft->iTable = regData+iCol+1;
7968479912
pLeft->affinity = pCol->affinity;
7968579913
pLeft->pColl = sqlite3LocateCollSeq(pParse, pCol->zColl);
7968679914
}else{
7968779915
pLeft->iTable = regData;
@@ -80238,15 +80466,11 @@
8023880466
0, 0, 0, 0, 0, 0
8023980467
);
8024080468
pWhere = 0;
8024180469
}
8024280470
80243
- /* In the current implementation, pTab->dbMem==0 for all tables except
80244
- ** for temporary tables used to describe subqueries. And temporary
80245
- ** tables do not have foreign key constraints. Hence, pTab->dbMem
80246
- ** should always be 0 there.
80247
- */
80471
+ /* Disable lookaside memory allocation */
8024880472
enableLookaside = db->lookaside.bEnabled;
8024980473
db->lookaside.bEnabled = 0;
8025080474
8025180475
pTrigger = (Trigger *)sqlite3DbMallocZero(db,
8025280476
sizeof(Trigger) + /* struct Trigger */
@@ -80332,41 +80556,43 @@
8033280556
/*
8033380557
** Free all memory associated with foreign key definitions attached to
8033480558
** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
8033580559
** hash table.
8033680560
*/
80337
-SQLITE_PRIVATE void sqlite3FkDelete(Table *pTab){
80561
+SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
8033880562
FKey *pFKey; /* Iterator variable */
8033980563
FKey *pNext; /* Copy of pFKey->pNextFrom */
8034080564
8034180565
for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
8034280566
8034380567
/* Remove the FK from the fkeyHash hash table. */
80344
- if( pFKey->pPrevTo ){
80345
- pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
80346
- }else{
80347
- void *data = (void *)pFKey->pNextTo;
80348
- const char *z = (data ? pFKey->pNextTo->zTo : pFKey->zTo);
80349
- sqlite3HashInsert(&pTab->pSchema->fkeyHash, z, sqlite3Strlen30(z), data);
80350
- }
80351
- if( pFKey->pNextTo ){
80352
- pFKey->pNextTo->pPrevTo = pFKey->pPrevTo;
80353
- }
80354
-
80355
- /* Delete any triggers created to implement actions for this FK. */
80356
-#ifndef SQLITE_OMIT_TRIGGER
80357
- fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[0]);
80358
- fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[1]);
80359
-#endif
80568
+ if( !db || db->pnBytesFreed==0 ){
80569
+ if( pFKey->pPrevTo ){
80570
+ pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
80571
+ }else{
80572
+ void *p = (void *)pFKey->pNextTo;
80573
+ const char *z = (p ? pFKey->pNextTo->zTo : pFKey->zTo);
80574
+ sqlite3HashInsert(&pTab->pSchema->fkeyHash, z, sqlite3Strlen30(z), p);
80575
+ }
80576
+ if( pFKey->pNextTo ){
80577
+ pFKey->pNextTo->pPrevTo = pFKey->pPrevTo;
80578
+ }
80579
+ }
8036080580
8036180581
/* EV: R-30323-21917 Each foreign key constraint in SQLite is
8036280582
** classified as either immediate or deferred.
8036380583
*/
8036480584
assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 );
80585
+
80586
+ /* Delete any triggers created to implement actions for this FK. */
80587
+#ifndef SQLITE_OMIT_TRIGGER
80588
+ fkTriggerDelete(db, pFKey->apTrigger[0]);
80589
+ fkTriggerDelete(db, pFKey->apTrigger[1]);
80590
+#endif
8036580591
8036680592
pNext = pFKey->pNextFrom;
80367
- sqlite3DbFree(pTab->dbMem, pFKey);
80593
+ sqlite3DbFree(db, pFKey);
8036880594
}
8036980595
}
8037080596
#endif /* ifndef SQLITE_OMIT_FOREIGN_KEY */
8037180597
8037280598
/************** End of fkey.c ************************************************/
@@ -80437,11 +80663,11 @@
8043780663
** up.
8043880664
*/
8043980665
int n;
8044080666
Table *pTab = pIdx->pTable;
8044180667
sqlite3 *db = sqlite3VdbeDb(v);
80442
- pIdx->zColAff = (char *)sqlite3Malloc(pIdx->nColumn+2);
80668
+ pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+2);
8044380669
if( !pIdx->zColAff ){
8044480670
db->mallocFailed = 1;
8044580671
return 0;
8044680672
}
8044780673
for(n=0; n<pIdx->nColumn; n++){
@@ -80479,11 +80705,11 @@
8047980705
if( !pTab->zColAff ){
8048080706
char *zColAff;
8048180707
int i;
8048280708
sqlite3 *db = sqlite3VdbeDb(v);
8048380709
80484
- zColAff = (char *)sqlite3Malloc(pTab->nCol+1);
80710
+ zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
8048580711
if( !zColAff ){
8048680712
db->mallocFailed = 1;
8048780713
return;
8048880714
}
8048980715
@@ -81590,10 +81816,11 @@
8159081816
sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, SQLITE_JUMPIFNULL);
8159181817
onError = overrideError!=OE_Default ? overrideError : OE_Abort;
8159281818
if( onError==OE_Ignore ){
8159381819
sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
8159481820
}else{
81821
+ if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
8159581822
sqlite3HaltConstraint(pParse, onError, 0, 0);
8159681823
}
8159781824
sqlite3VdbeResolveLabel(v, allOk);
8159881825
}
8159981826
#endif /* !defined(SQLITE_OMIT_CHECK) */
@@ -83104,32 +83331,28 @@
8310483331
}
8310583332
8310683333
handle = sqlite3OsDlOpen(pVfs, zFile);
8310783334
if( handle==0 ){
8310883335
if( pzErrMsg ){
83109
- zErrmsg = sqlite3StackAllocZero(db, nMsg);
83336
+ *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
8311083337
if( zErrmsg ){
8311183338
sqlite3_snprintf(nMsg, zErrmsg,
8311283339
"unable to open shared library [%s]", zFile);
8311383340
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
83114
- *pzErrMsg = sqlite3DbStrDup(0, zErrmsg);
83115
- sqlite3StackFree(db, zErrmsg);
8311683341
}
8311783342
}
8311883343
return SQLITE_ERROR;
8311983344
}
8312083345
xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
8312183346
sqlite3OsDlSym(pVfs, handle, zProc);
8312283347
if( xInit==0 ){
8312383348
if( pzErrMsg ){
83124
- zErrmsg = sqlite3StackAllocZero(db, nMsg);
83349
+ *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
8312583350
if( zErrmsg ){
8312683351
sqlite3_snprintf(nMsg, zErrmsg,
8312783352
"no entry point [%s] in shared library [%s]", zProc,zFile);
8312883353
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
83129
- *pzErrMsg = sqlite3DbStrDup(0, zErrmsg);
83130
- sqlite3StackFree(db, zErrmsg);
8313183354
}
8313283355
sqlite3OsDlClose(pVfs, handle);
8313383356
}
8313483357
return SQLITE_ERROR;
8313583358
}else if( xInit(db, &zErrmsg, &sqlite3Apis) ){
@@ -84104,11 +84327,11 @@
8410484327
){
8410584328
invalidateTempStorage(pParse);
8410684329
}
8410784330
sqlite3_free(sqlite3_temp_directory);
8410884331
if( zRight[0] ){
84109
- sqlite3_temp_directory = sqlite3DbStrDup(0, zRight);
84332
+ sqlite3_temp_directory = sqlite3_mprintf("%s", zRight);
8411084333
}else{
8411184334
sqlite3_temp_directory = 0;
8411284335
}
8411384336
#endif /* SQLITE_OMIT_WSD */
8411484337
}
@@ -85525,11 +85748,10 @@
8552585748
8552685749
/* Delete any TriggerPrg structures allocated while parsing this statement. */
8552785750
while( pParse->pTriggerPrg ){
8552885751
TriggerPrg *pT = pParse->pTriggerPrg;
8552985752
pParse->pTriggerPrg = pT->pNext;
85530
- sqlite3VdbeProgramDelete(db, pT->pProgram, 0);
8553185753
sqlite3DbFree(db, pT);
8553285754
}
8553385755
8553485756
end_prepare:
8553585757
@@ -87016,20 +87238,19 @@
8701687238
pTab = sqlite3DbMallocZero(db, sizeof(Table) );
8701787239
if( pTab==0 ){
8701887240
return 0;
8701987241
}
8702087242
/* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
87021
- ** is disabled, so we might as well hard-code pTab->dbMem to NULL. */
87243
+ ** is disabled */
8702287244
assert( db->lookaside.bEnabled==0 );
87023
- pTab->dbMem = 0;
8702487245
pTab->nRef = 1;
8702587246
pTab->zName = 0;
8702687247
selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
8702787248
selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect);
8702887249
pTab->iPKey = -1;
8702987250
if( db->mallocFailed ){
87030
- sqlite3DeleteTable(pTab);
87251
+ sqlite3DeleteTable(db, pTab);
8703187252
return 0;
8703287253
}
8703387254
return pTab;
8703487255
}
8703587256
@@ -88814,11 +89035,10 @@
8881489035
assert( pSel!=0 );
8881589036
assert( pFrom->pTab==0 );
8881689037
sqlite3WalkSelect(pWalker, pSel);
8881789038
pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
8881889039
if( pTab==0 ) return WRC_Abort;
88819
- pTab->dbMem = db->lookaside.bEnabled ? db : 0;
8882089040
pTab->nRef = 1;
8882189041
pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
8882289042
while( pSel->pPrior ){ pSel = pSel->pPrior; }
8882389043
selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
8882489044
pTab->iPKey = -1;
@@ -91028,10 +91248,11 @@
9102891248
SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
9102991249
Parse *pSubParse; /* Parse context for sub-vdbe */
9103091250
int iEndTrigger = 0; /* Label to jump to if WHEN is false */
9103191251
9103291252
assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
91253
+ assert( pTop->pVdbe );
9103391254
9103491255
/* Allocate the TriggerPrg and SubProgram objects. To ensure that they
9103591256
** are freed if an error occurs, link them into the Parse.pTriggerPrg
9103691257
** list of the top-level Parse object sooner rather than later. */
9103791258
pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
@@ -91038,11 +91259,11 @@
9103891259
if( !pPrg ) return 0;
9103991260
pPrg->pNext = pTop->pTriggerPrg;
9104091261
pTop->pTriggerPrg = pPrg;
9104191262
pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
9104291263
if( !pProgram ) return 0;
91043
- pProgram->nRef = 1;
91264
+ sqlite3VdbeLinkSubProgram(pTop->pVdbe, pProgram);
9104491265
pPrg->pTrigger = pTrigger;
9104591266
pPrg->orconf = orconf;
9104691267
pPrg->aColmask[0] = 0xffffffff;
9104791268
pPrg->aColmask[1] = 0xffffffff;
9104891269
@@ -91172,22 +91393,23 @@
9117291393
assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
9117391394
9117491395
/* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
9117591396
** is a pointer to the sub-vdbe containing the trigger program. */
9117691397
if( pPrg ){
91398
+ int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
91399
+
9117791400
sqlite3VdbeAddOp3(v, OP_Program, reg, ignoreJump, ++pParse->nMem);
91178
- pPrg->pProgram->nRef++;
9117991401
sqlite3VdbeChangeP4(v, -1, (const char *)pPrg->pProgram, P4_SUBPROGRAM);
9118091402
VdbeComment(
9118191403
(v, "Call: %s.%s", (p->zName?p->zName:"fkey"), onErrorText(orconf)));
9118291404
9118391405
/* Set the P5 operand of the OP_Program instruction to non-zero if
9118491406
** recursive invocation of this trigger program is disallowed. Recursive
9118591407
** invocation is disallowed if (a) the sub-program is really a trigger,
9118691408
** not a foreign key action, and (b) the flag to enable recursive triggers
9118791409
** is clear. */
91188
- sqlite3VdbeChangeP5(v, (u8)(p->zName && !(pParse->db->flags&SQLITE_RecTriggers)));
91410
+ sqlite3VdbeChangeP5(v, (u8)bRecursive);
9118991411
}
9119091412
}
9119191413
9119291414
/*
9119391415
** This is called to code the required FOR EACH ROW triggers for an operation
@@ -91332,11 +91554,11 @@
9133291554
**
9133391555
** May you do good and not evil.
9133491556
** May you find forgiveness for yourself and forgive others.
9133591557
** May you share freely, never taking more than you give.
9133691558
**
91337
-sqlite*************************************************************************
91559
+*************************************************************************
9133891560
** This file contains C code routines that are called by the parser
9133991561
** to handle UPDATE statements.
9134091562
*/
9134191563
9134291564
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -92551,18 +92773,18 @@
9255192773
** connection db is decremented immediately (which may lead to the
9255292774
** structure being xDisconnected and free). Any other VTable structures
9255392775
** in the list are moved to the sqlite3.pDisconnect list of the associated
9255492776
** database connection.
9255592777
*/
92556
-SQLITE_PRIVATE void sqlite3VtabClear(Table *p){
92557
- vtabDisconnectAll(0, p);
92778
+SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
92779
+ if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
9255892780
if( p->azModuleArg ){
9255992781
int i;
9256092782
for(i=0; i<p->nModuleArg; i++){
92561
- sqlite3DbFree(p->dbMem, p->azModuleArg[i]);
92783
+ sqlite3DbFree(db, p->azModuleArg[i]);
9256292784
}
92563
- sqlite3DbFree(p->dbMem, p->azModuleArg);
92785
+ sqlite3DbFree(db, p->azModuleArg);
9256492786
}
9256592787
}
9256692788
9256792789
/*
9256892790
** Add a new module argument to pTable->azModuleArg[].
@@ -92723,11 +92945,10 @@
9272392945
if( pOld ){
9272492946
db->mallocFailed = 1;
9272592947
assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
9272692948
return;
9272792949
}
92728
- pSchema->db = pParse->db;
9272992950
pParse->pNewTable = 0;
9273092951
}
9273192952
}
9273292953
9273392954
/*
@@ -92797,11 +93018,11 @@
9279793018
if( SQLITE_OK!=rc ){
9279893019
if( zErr==0 ){
9279993020
*pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
9280093021
}else {
9280193022
*pzErr = sqlite3MPrintf(db, "%s", zErr);
92802
- sqlite3DbFree(db, zErr);
93023
+ sqlite3_free(zErr);
9280393024
}
9280493025
sqlite3DbFree(db, pVTable);
9280593026
}else if( ALWAYS(pVTable->pVtab) ){
9280693027
/* Justification of ALWAYS(): A correct vtab constructor must allocate
9280793028
** the sqlite3_vtab object if successful. */
@@ -93004,19 +93225,19 @@
9300493225
pParse->pNewTable->aCol = 0;
9300593226
}
9300693227
db->pVTab = 0;
9300793228
}else{
9300893229
sqlite3Error(db, SQLITE_ERROR, zErr);
93009
- sqlite3DbFree(db, zErr);
93230
+ sqlite3_free(zErr);
9301093231
rc = SQLITE_ERROR;
9301193232
}
9301293233
pParse->declareVtab = 0;
9301393234
9301493235
if( pParse->pVdbe ){
9301593236
sqlite3VdbeFinalize(pParse->pVdbe);
9301693237
}
93017
- sqlite3DeleteTable(pParse->pNewTable);
93238
+ sqlite3DeleteTable(db, pParse->pNewTable);
9301893239
sqlite3StackFree(db, pParse);
9301993240
}
9302093241
9302193242
assert( (rc&0xff)==rc );
9302293243
rc = sqlite3ApiExit(db, rc);
@@ -93099,12 +93320,12 @@
9309993320
int (*x)(sqlite3_vtab *);
9310093321
sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
9310193322
if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
9310293323
rc = x(pVtab);
9310393324
sqlite3DbFree(db, *pzErrmsg);
93104
- *pzErrmsg = pVtab->zErrMsg;
93105
- pVtab->zErrMsg = 0;
93325
+ *pzErrmsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
93326
+ sqlite3_free(pVtab->zErrMsg);
9310693327
}
9310793328
}
9310893329
db->aVTrans = aVTrans;
9310993330
return rc;
9311093331
}
@@ -93600,10 +93821,11 @@
9360093821
** the pWC->a[] array.
9360193822
*/
9360293823
static int whereClauseInsert(WhereClause *pWC, Expr *p, u8 wtFlags){
9360393824
WhereTerm *pTerm;
9360493825
int idx;
93826
+ testcase( wtFlags & TERM_VIRTUAL ); /* EV: R-00211-15100 */
9360593827
if( pWC->nTerm>=pWC->nSlot ){
9360693828
WhereTerm *pOld = pWC->a;
9360793829
sqlite3 *db = pWC->pParse->db;
9360893830
pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
9360993831
if( pWC->a==0 ){
@@ -93745,10 +93967,17 @@
9374593967
9374693968
/*
9374793969
** Return TRUE if the given operator is one of the operators that is
9374893970
** allowed for an indexable WHERE clause term. The allowed operators are
9374993971
** "=", "<", ">", "<=", ">=", and "IN".
93972
+**
93973
+** IMPLEMENTATION-OF: R-59926-26393 To be usable by an index a term must be
93974
+** of one of the following forms: column = expression column > expression
93975
+** column >= expression column < expression column <= expression
93976
+** expression = column expression > column expression >= column
93977
+** expression < column expression <= column column IN
93978
+** (expression-list) column IN (subquery) column IS NULL
9375093979
*/
9375193980
static int allowedOp(int op){
9375293981
assert( TK_GT>TK_EQ && TK_GT<TK_GE );
9375393982
assert( TK_LT>TK_EQ && TK_LT<TK_GE );
9375493983
assert( TK_LE>TK_EQ && TK_LE<TK_GE );
@@ -93908,11 +94137,10 @@
9390894137
Expr *pRight, *pLeft; /* Right and left size of LIKE operator */
9390994138
ExprList *pList; /* List of operands to the LIKE operator */
9391094139
int c; /* One character in z[] */
9391194140
int cnt; /* Number of non-wildcard prefix characters */
9391294141
char wc[3]; /* Wildcard characters */
93913
- CollSeq *pColl; /* Collating sequence for LHS */
9391494142
sqlite3 *db = pParse->db; /* Database connection */
9391594143
sqlite3_value *pVal = 0;
9391694144
int op; /* Opcode of pRight */
9391794145
9391894146
if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
@@ -93927,23 +94155,10 @@
9392794155
/* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
9392894156
** be the name of an indexed column with TEXT affinity. */
9392994157
return 0;
9393094158
}
9393194159
assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
93932
- pColl = sqlite3ExprCollSeq(pParse, pLeft);
93933
- if( pColl==0 ) return 0; /* Happens when LHS has an undefined collation */
93934
- if( (pColl->type!=SQLITE_COLL_BINARY || *pnoCase) &&
93935
- (pColl->type!=SQLITE_COLL_NOCASE || !*pnoCase) ){
93936
- /* IMP: R-09003-32046 For the GLOB operator, the column must use the
93937
- ** default BINARY collating sequence.
93938
- ** IMP: R-41408-28306 For the LIKE operator, if case_sensitive_like mode
93939
- ** is enabled then the column must use the default BINARY collating
93940
- ** sequence, or if case_sensitive_like mode is disabled then the column
93941
- ** must use the built-in NOCASE collating sequence.
93942
- */
93943
- return 0;
93944
- }
9394594160
9394694161
pRight = pList->a[0].pExpr;
9394794162
op = pRight->op;
9394894163
if( op==TK_REGISTER ){
9394994164
op = pRight->op2;
@@ -93962,13 +94177,13 @@
9396294177
if( z ){
9396394178
cnt = 0;
9396494179
while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
9396594180
cnt++;
9396694181
}
93967
- if( cnt!=0 && c!=0 && 255!=(u8)z[cnt-1] ){
94182
+ if( cnt!=0 && 255!=(u8)z[cnt-1] ){
9396894183
Expr *pPrefix;
93969
- *pisComplete = z[cnt]==wc[0] && z[cnt+1]==0;
94184
+ *pisComplete = c==wc[0] && z[cnt+1]==0;
9397094185
pPrefix = sqlite3Expr(db, TK_STRING, z);
9397194186
if( pPrefix ) pPrefix->u.zToken[cnt] = 0;
9397294187
*ppPrefix = pPrefix;
9397394188
if( op==TK_VARIABLE ){
9397494189
Vdbe *v = pParse->pVdbe;
@@ -94303,10 +94518,12 @@
9430394518
}
9430494519
9430594520
/* At this point, okToChngToIN is true if original pTerm satisfies
9430694521
** case 1. In that case, construct a new virtual term that is
9430794522
** pTerm converted into an IN operator.
94523
+ **
94524
+ ** EV: R-00211-15100
9430894525
*/
9430994526
if( okToChngToIN ){
9431094527
Expr *pDup; /* A transient duplicate expression */
9431194528
ExprList *pList = 0; /* The RHS of the IN operator */
9431294529
Expr *pLeft = 0; /* The LHS of the IN operator */
@@ -94519,10 +94736,11 @@
9451994736
Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */
9452094737
Expr *pNewExpr1;
9452194738
Expr *pNewExpr2;
9452294739
int idxNew1;
9452394740
int idxNew2;
94741
+ CollSeq *pColl; /* Collating sequence to use */
9452494742
9452594743
pLeft = pExpr->x.pList->a[1].pExpr;
9452694744
pStr2 = sqlite3ExprDup(db, pStr1, 0);
9452794745
if( !db->mallocFailed ){
9452894746
u8 c, *pC; /* Last character before the first wildcard */
@@ -94533,21 +94751,27 @@
9453394751
** wildcard. But if we increment '@', that will push it into the
9453494752
** alphabetic range where case conversions will mess up the
9453594753
** inequality. To avoid this, make sure to also run the full
9453694754
** LIKE on all candidate expressions by clearing the isComplete flag
9453794755
*/
94538
- if( c=='A'-1 ) isComplete = 0;
94756
+ if( c=='A'-1 ) isComplete = 0; /* EV: R-64339-08207 */
94757
+
9453994758
9454094759
c = sqlite3UpperToLower[c];
9454194760
}
9454294761
*pC = c + 1;
9454394762
}
94544
- pNewExpr1 = sqlite3PExpr(pParse, TK_GE, sqlite3ExprDup(db,pLeft,0),pStr1,0);
94763
+ pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, noCase ? "NOCASE" : "BINARY",0);
94764
+ pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
94765
+ sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
94766
+ pStr1, 0);
9454594767
idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC);
9454694768
testcase( idxNew1==0 );
9454794769
exprAnalyze(pSrc, pWC, idxNew1);
94548
- pNewExpr2 = sqlite3PExpr(pParse, TK_LT, sqlite3ExprDup(db,pLeft,0),pStr2,0);
94770
+ pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
94771
+ sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
94772
+ pStr2, 0);
9454994773
idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
9455094774
testcase( idxNew2==0 );
9455194775
exprAnalyze(pSrc, pWC, idxNew2);
9455294776
pTerm = &pWC->a[idxTerm];
9455394777
if( isComplete ){
@@ -95295,11 +95519,11 @@
9529595519
sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
9529695520
}else{
9529795521
sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg);
9529895522
}
9529995523
}
95300
- sqlite3DbFree(pParse->db, pVtab->zErrMsg);
95524
+ sqlite3_free(pVtab->zErrMsg);
9530195525
pVtab->zErrMsg = 0;
9530295526
9530395527
for(i=0; i<p->nConstraint; i++){
9530495528
if( !p->aConstraint[i].usable && p->aConstraintUsage[i].argvIndex>0 ){
9530595529
sqlite3ErrorMsg(pParse,
@@ -96159,10 +96383,13 @@
9615996383
** (3) SELECT * FROM t1, t2 WHERE t1.a=t2.x AND t2.z='ok'
9616096384
**
9616196385
** The t2.z='ok' is disabled in the in (2) because it originates
9616296386
** in the ON clause. The term is disabled in (3) because it is not part
9616396387
** of a LEFT OUTER JOIN. In (1), the term is not disabled.
96388
+**
96389
+** IMPLEMENTATION-OF: R-24597-58655 No tests are done for terms that are
96390
+** completely satisfied by indices.
9616496391
**
9616596392
** Disabling a term causes that term to not be tested in the inner loop
9616696393
** of the join. Disabling is an optimization. When terms are satisfied
9616796394
** by indices, we disable them to prevent redundant tests in the inner
9616896395
** loop. We would get the correct results if nothing were ever disabled,
@@ -96371,10 +96598,11 @@
9637196598
pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx);
9637296599
if( NEVER(pTerm==0) ) break;
9637396600
/* The following true for indices with redundant columns.
9637496601
** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
9637596602
testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
96603
+ testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
9637696604
r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
9637796605
if( r1!=regBase+j ){
9637896606
if( nReg==1 ){
9637996607
sqlite3ReleaseTempReg(pParse, regBase);
9638096608
regBase = r1;
@@ -96514,10 +96742,11 @@
9651496742
pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
9651596743
assert( pTerm!=0 );
9651696744
assert( pTerm->pExpr!=0 );
9651796745
assert( pTerm->leftCursor==iCur );
9651896746
assert( omitTable==0 );
96747
+ testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
9651996748
iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, iReleaseReg);
9652096749
addrNxt = pLevel->addrNxt;
9652196750
sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
9652296751
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
9652396752
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
@@ -96554,10 +96783,11 @@
9655496783
};
9655596784
assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
9655696785
assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
9655796786
assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
9655896787
96788
+ testcase( pStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
9655996789
pX = pStart->pExpr;
9656096790
assert( pX!=0 );
9656196791
assert( pStart->leftCursor==iCur );
9656296792
r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
9656396793
sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
@@ -96571,10 +96801,11 @@
9657196801
if( pEnd ){
9657296802
Expr *pX;
9657396803
pX = pEnd->pExpr;
9657496804
assert( pX!=0 );
9657596805
assert( pEnd->leftCursor==iCur );
96806
+ testcase( pEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
9657696807
memEndValue = ++pParse->nMem;
9657796808
sqlite3ExprCode(pParse, pX->pRight, memEndValue);
9657896809
if( pX->op==TK_LT || pX->op==TK_GT ){
9657996810
testOp = bRev ? OP_Le : OP_Ge;
9658096811
}else{
@@ -96738,10 +96969,11 @@
9673896969
if( sqlite3ExprNeedsNoAffinityChange(pRight, zStartAff[nEq]) ){
9673996970
zStartAff[nEq] = SQLITE_AFF_NONE;
9674096971
}
9674196972
}
9674296973
nConstraint++;
96974
+ testcase( pRangeStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
9674396975
}else if( isMinQuery ){
9674496976
sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
9674596977
nConstraint++;
9674696978
startEq = 0;
9674796979
start_constraints = 1;
@@ -96777,10 +97009,11 @@
9677797009
zEndAff[nEq] = SQLITE_AFF_NONE;
9677897010
}
9677997011
}
9678097012
codeApplyAffinity(pParse, regBase, nEq+1, zEndAff);
9678197013
nConstraint++;
97014
+ testcase( pRangeEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
9678297015
}
9678397016
sqlite3DbFree(pParse->db, zStartAff);
9678497017
sqlite3DbFree(pParse->db, zEndAff);
9678597018
9678697019
/* Top of the loop body */
@@ -96983,15 +97216,19 @@
9698397216
}
9698497217
notReady &= ~getMask(pWC->pMaskSet, iCur);
9698597218
9698697219
/* Insert code to test every subexpression that can be completely
9698797220
** computed using the current set of tables.
97221
+ **
97222
+ ** IMPLEMENTATION-OF: R-49525-50935 Terms that cannot be satisfied through
97223
+ ** the use of indices become tests that are evaluated against each row of
97224
+ ** the relevant input tables.
9698897225
*/
9698997226
k = 0;
9699097227
for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
9699197228
Expr *pE;
96992
- testcase( pTerm->wtFlags & TERM_VIRTUAL );
97229
+ testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */
9699397230
testcase( pTerm->wtFlags & TERM_CODED );
9699497231
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
9699597232
if( (pTerm->prereqAll & notReady)!=0 ){
9699697233
testcase( pWInfo->untestedTerms==0
9699797234
&& (pWInfo->wctrlFlags & WHERE_ONETABLE_ONLY)!=0 );
@@ -97015,11 +97252,11 @@
9701597252
pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
9701697253
sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
9701797254
VdbeComment((v, "record LEFT JOIN hit"));
9701897255
sqlite3ExprCacheClear(pParse);
9701997256
for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
97020
- testcase( pTerm->wtFlags & TERM_VIRTUAL );
97257
+ testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */
9702197258
testcase( pTerm->wtFlags & TERM_CODED );
9702297259
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
9702397260
if( (pTerm->prereqAll & notReady)!=0 ){
9702497261
assert( pWInfo->untestedTerms );
9702597262
continue;
@@ -97233,11 +97470,11 @@
9723397470
** subexpression is separated by an AND operator.
9723497471
*/
9723597472
initMaskSet(pMaskSet);
9723697473
whereClauseInit(pWC, pParse, pMaskSet);
9723797474
sqlite3ExprCodeConstants(pParse, pWhere);
97238
- whereSplit(pWC, pWhere, TK_AND);
97475
+ whereSplit(pWC, pWhere, TK_AND); /* IMP: R-15842-53296 */
9723997476
9724097477
/* Special case: a WHERE clause that is constant. Evaluate the
9724197478
** expression and either jump over all of the code or fall thru.
9724297479
*/
9724397480
if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
@@ -97321,10 +97558,12 @@
9732197558
Index *pIdx; /* Index for FROM table at pTabItem */
9732297559
int j; /* For looping over FROM tables */
9732397560
int bestJ = -1; /* The value of j */
9732497561
Bitmask m; /* Bitmask value for j or bestJ */
9732597562
int isOptimal; /* Iterator for optimal/non-optimal search */
97563
+ int nUnconstrained; /* Number tables without INDEXED BY */
97564
+ Bitmask notIndexed; /* Mask of tables that cannot use an index */
9732697565
9732797566
memset(&bestPlan, 0, sizeof(bestPlan));
9732897567
bestPlan.rCost = SQLITE_BIG_DBL;
9732997568
9733097569
/* Loop through the remaining entries in the FROM clause to find the
@@ -97362,12 +97601,14 @@
9736297601
** However, since the cost of a linear scan through table t2 is the same
9736397602
** as the cost of a linear scan through table t1, a simple greedy
9736497603
** algorithm may choose to use t2 for the outer loop, which is a much
9736597604
** costlier approach.
9736697605
*/
97606
+ nUnconstrained = 0;
97607
+ notIndexed = 0;
9736797608
for(isOptimal=(iFrom<nTabList-1); isOptimal>=0; isOptimal--){
97368
- Bitmask mask; /* Mask of tables not yet ready */
97609
+ Bitmask mask; /* Mask of tables not yet ready */
9736997610
for(j=iFrom, pTabItem=&pTabList->a[j]; j<nTabList; j++, pTabItem++){
9737097611
int doNotReorder; /* True if this table should not be reordered */
9737197612
WhereCost sCost; /* Cost information from best[Virtual]Index() */
9737297613
ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
9737397614
@@ -97378,10 +97619,11 @@
9737897619
if( j==iFrom ) iFrom++;
9737997620
continue;
9738097621
}
9738197622
mask = (isOptimal ? m : notReady);
9738297623
pOrderBy = ((i==0 && ppOrderBy )?*ppOrderBy:0);
97624
+ if( pTabItem->pIndex==0 ) nUnconstrained++;
9738397625
9738497626
assert( pTabItem->pTab );
9738597627
#ifndef SQLITE_OMIT_VIRTUALTABLE
9738697628
if( IsVirtual(pTabItem->pTab) ){
9738797629
sqlite3_index_info **pp = &pWInfo->a[j].pIdxInfo;
@@ -97391,13 +97633,47 @@
9739197633
{
9739297634
bestBtreeIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost);
9739397635
}
9739497636
assert( isOptimal || (sCost.used&notReady)==0 );
9739597637
97396
- if( (sCost.used&notReady)==0
97397
- && (bestJ<0 || sCost.rCost<bestPlan.rCost
97398
- || (sCost.rCost<=bestPlan.rCost && sCost.nRow<bestPlan.nRow))
97638
+ /* If an INDEXED BY clause is present, then the plan must use that
97639
+ ** index if it uses any index at all */
97640
+ assert( pTabItem->pIndex==0
97641
+ || (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)==0
97642
+ || sCost.plan.u.pIdx==pTabItem->pIndex );
97643
+
97644
+ if( isOptimal && (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ){
97645
+ notIndexed |= m;
97646
+ }
97647
+
97648
+ /* Conditions under which this table becomes the best so far:
97649
+ **
97650
+ ** (1) The table must not depend on other tables that have not
97651
+ ** yet run.
97652
+ **
97653
+ ** (2) A full-table-scan plan cannot supercede another plan unless
97654
+ ** it is an "optimal" plan as defined above.
97655
+ **
97656
+ ** (3) All tables have an INDEXED BY clause or this table lacks an
97657
+ ** INDEXED BY clause or this table uses the specific
97658
+ ** index specified by its INDEXED BY clause. This rule ensures
97659
+ ** that a best-so-far is always selected even if an impossible
97660
+ ** combination of INDEXED BY clauses are given. The error
97661
+ ** will be detected and relayed back to the application later.
97662
+ ** The NEVER() comes about because rule (2) above prevents
97663
+ ** An indexable full-table-scan from reaching rule (3).
97664
+ **
97665
+ ** (4) The plan cost must be lower than prior plans or else the
97666
+ ** cost must be the same and the number of rows must be lower.
97667
+ */
97668
+ if( (sCost.used&notReady)==0 /* (1) */
97669
+ && (bestJ<0 || (notIndexed&m)!=0 /* (2) */
97670
+ || (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)
97671
+ && (nUnconstrained==0 || pTabItem->pIndex==0 /* (3) */
97672
+ || NEVER((sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0))
97673
+ && (bestJ<0 || sCost.rCost<bestPlan.rCost /* (4) */
97674
+ || (sCost.rCost<=bestPlan.rCost && sCost.nRow<bestPlan.nRow))
9739997675
){
9740097676
WHERETRACE(("... best so far with cost=%g and nRow=%g\n",
9740197677
sCost.rCost, sCost.nRow));
9740297678
bestPlan = sCost;
9740397679
bestJ = j;
@@ -100408,11 +100684,11 @@
100408100684
spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
100409100685
}
100410100686
break;
100411100687
case 195: /* expr ::= expr COLLATE ids */
100412100688
{
100413
- yygotominor.yy118.pExpr = sqlite3ExprSetColl(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
100689
+ yygotominor.yy118.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
100414100690
yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
100415100691
yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
100416100692
}
100417100693
break;
100418100694
case 196: /* expr ::= CAST LP expr AS typetoken RP */
@@ -100664,11 +100940,11 @@
100664100940
case 248: /* idxlist ::= idxlist COMMA nm collate sortorder */
100665100941
{
100666100942
Expr *p = 0;
100667100943
if( yymsp[-1].minor.yy0.n>0 ){
100668100944
p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
100669
- sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
100945
+ sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
100670100946
}
100671100947
yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, p);
100672100948
sqlite3ExprListSetName(pParse,yygotominor.yy322,&yymsp[-2].minor.yy0,1);
100673100949
sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
100674100950
if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
@@ -100677,11 +100953,11 @@
100677100953
case 249: /* idxlist ::= nm collate sortorder */
100678100954
{
100679100955
Expr *p = 0;
100680100956
if( yymsp[-1].minor.yy0.n>0 ){
100681100957
p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
100682
- sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
100958
+ sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
100683100959
}
100684100960
yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, p);
100685100961
sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
100686100962
sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
100687100963
if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
@@ -101957,19 +102233,19 @@
101957102233
pParse->aTableLock = 0;
101958102234
pParse->nTableLock = 0;
101959102235
}
101960102236
#endif
101961102237
#ifndef SQLITE_OMIT_VIRTUALTABLE
101962
- sqlite3DbFree(db, pParse->apVtabLock);
102238
+ sqlite3_free(pParse->apVtabLock);
101963102239
#endif
101964102240
101965102241
if( !IN_DECLARE_VTAB ){
101966102242
/* If the pParse->declareVtab flag is set, do not delete any table
101967102243
** structure built up in pParse->pNewTable. The calling code (see vtab.c)
101968102244
** will take responsibility for freeing the Table structure.
101969102245
*/
101970
- sqlite3DeleteTable(pParse->pNewTable);
102246
+ sqlite3DeleteTable(db, pParse->pNewTable);
101971102247
}
101972102248
101973102249
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
101974102250
sqlite3DbFree(db, pParse->apVarExpr);
101975102251
sqlite3DbFree(db, pParse->aAlias);
@@ -101979,11 +102255,11 @@
101979102255
sqlite3DbFree(db, p);
101980102256
}
101981102257
while( pParse->pZombieTab ){
101982102258
Table *p = pParse->pZombieTab;
101983102259
pParse->pZombieTab = p->pNextZombie;
101984
- sqlite3DeleteTable(p);
102260
+ sqlite3DeleteTable(db, p);
101985102261
}
101986102262
if( nErr>0 && pParse->rc==SQLITE_OK ){
101987102263
pParse->rc = SQLITE_ERROR;
101988102264
}
101989102265
return nErr;
@@ -103671,20 +103947,11 @@
103671103947
103672103948
assert( sqlite3_mutex_held(db->mutex) );
103673103949
103674103950
for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
103675103951
if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){
103676
- Btree *pBt = db->aDb[i].pBt;
103677
- if( pBt ){
103678
- if( sqlite3BtreeIsInReadTrans(pBt) ){
103679
- rc = SQLITE_LOCKED;
103680
- }else{
103681
- sqlite3BtreeEnter(pBt);
103682
- rc = sqlite3PagerCheckpoint(sqlite3BtreePager(pBt));
103683
- sqlite3BtreeLeave(pBt);
103684
- }
103685
- }
103952
+ rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt);
103686103953
}
103687103954
}
103688103955
103689103956
return rc;
103690103957
}
@@ -105129,11 +105396,11 @@
105129105396
105130105397
sqlite3BeginBenignMalloc();
105131105398
assert( aArg==aDyn || (aDyn==0 && aArg==aStatic) );
105132105399
assert( nArg<=(int)ArraySize(aStatic) || aArg==aDyn );
105133105400
if( (!aDyn && nArg==(int)ArraySize(aStatic))
105134
- || (aDyn && nArg==(int)(sqlite3DbMallocSize(db, aDyn)/sizeof(void*)))
105401
+ || (aDyn && nArg==(int)(sqlite3MallocSize(aDyn)/sizeof(void*)))
105135105402
){
105136105403
/* The aArg[] array needs to grow. */
105137105404
void **pNew = (void **)sqlite3Malloc(nArg*sizeof(void *)*2);
105138105405
if( pNew ){
105139105406
memcpy(pNew, aArg, nArg*sizeof(void *));
105140105407
--- 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.7.0. 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.
@@ -641,13 +641,13 @@
641 **
642 ** See also: [sqlite3_libversion()],
643 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
644 ** [sqlite_version()] and [sqlite_source_id()].
645 */
646 #define SQLITE_VERSION "3.7.0"
647 #define SQLITE_VERSION_NUMBER 3007000
648 #define SQLITE_SOURCE_ID "2010-07-21 16:16:28 b36b105eab6fd3195f4bfba6cb5cda0f063b7460"
649
650 /*
651 ** CAPI3REF: Run-Time Library Version Numbers
652 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
653 **
@@ -2710,11 +2710,17 @@
2710 ** contain a UTF-8 SQL comment that identifies the trigger.)^
2711 **
2712 ** ^The callback function registered by sqlite3_profile() is invoked
2713 ** as each SQL statement finishes. ^The profile callback contains
2714 ** the original statement text and an estimate of wall-clock time
2715 ** of how long that statement took to run.
 
 
 
 
 
 
2716 */
2717 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2718 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2719 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2720
@@ -4859,22 +4865,25 @@
4859
4860 /*
4861 ** CAPI3REF: Virtual Table Indexing Information
4862 ** KEYWORDS: sqlite3_index_info
4863 **
4864 ** The sqlite3_index_info structure and its substructures is used to
 
4865 ** pass information into and receive the reply from the [xBestIndex]
4866 ** method of a [virtual table module]. The fields under **Inputs** are the
4867 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
4868 ** results into the **Outputs** fields.
4869 **
4870 ** ^(The aConstraint[] array records WHERE clause constraints of the form:
4871 **
4872 ** <pre>column OP expr</pre>
4873 **
4874 ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
4875 ** stored in aConstraint[].op.)^ ^(The index of the column is stored in
 
 
4876 ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
4877 ** expr on the right-hand side can be evaluated (and thus the constraint
4878 ** is usable) and false if it cannot.)^
4879 **
4880 ** ^The optimizer automatically inverts terms of the form "expr OP column"
@@ -4930,10 +4939,19 @@
4930 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
4931 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
4932 int orderByConsumed; /* True if output is already ordered */
4933 double estimatedCost; /* Estimated cost of using this index */
4934 };
 
 
 
 
 
 
 
 
 
4935 #define SQLITE_INDEX_CONSTRAINT_EQ 2
4936 #define SQLITE_INDEX_CONSTRAINT_GT 4
4937 #define SQLITE_INDEX_CONSTRAINT_LE 8
4938 #define SQLITE_INDEX_CONSTRAINT_LT 16
4939 #define SQLITE_INDEX_CONSTRAINT_GE 32
@@ -5670,10 +5688,13 @@
5670 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
5671 ** internal equivalents). Only the value returned in the
5672 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5673 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5674 **
 
 
 
5675 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5676 ** <dd>This parameter returns the number of pages used out of the
5677 ** [pagecache memory allocator] that was configured using
5678 ** [SQLITE_CONFIG_PAGECACHE]. The
5679 ** value returned is in pages, not in bytes.</dd>)^
@@ -5731,10 +5752,11 @@
5731 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
5732 #define SQLITE_STATUS_MALLOC_SIZE 5
5733 #define SQLITE_STATUS_PARSER_STACK 6
5734 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5735 #define SQLITE_STATUS_SCRATCH_SIZE 8
 
5736
5737 /*
5738 ** CAPI3REF: Database Connection Status
5739 **
5740 ** ^This interface is used to retrieve runtime status information
@@ -5770,20 +5792,37 @@
5770 ** <dl>
5771 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5772 ** <dd>This parameter returns the number of lookaside memory slots currently
5773 ** checked out.</dd>)^
5774 **
5775 ** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5776 ** <dd>^This parameter returns the approximate number of of bytes of heap
5777 ** memory used by all pager caches associated with the database connection.
5778 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5779 ** </dd>
5780 ** </dl>
5781 */
5782 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5783 #define SQLITE_DBSTATUS_CACHE_USED 1
5784 #define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
 
 
5785
5786
5787 /*
5788 ** CAPI3REF: Prepared Statement Status
5789 **
@@ -7257,10 +7296,14 @@
7257 #ifdef SQLITE_TEST
7258 SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
7259 SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*);
7260 #endif
7261
 
 
 
 
7262 /*
7263 ** If we are not using shared cache, then there is no need to
7264 ** use mutexes to access the BtShared structures. So make the
7265 ** Enter and Leave procedures no-ops.
7266 */
@@ -7386,12 +7429,12 @@
7386 struct SubProgram {
7387 VdbeOp *aOp; /* Array of opcodes for sub-program */
7388 int nOp; /* Elements in aOp[] */
7389 int nMem; /* Number of memory cells required */
7390 int nCsr; /* Number of cursors required */
7391 int nRef; /* Number of pointers to this structure */
7392 void *token; /* id that may be used to recursive triggers */
 
7393 };
7394
7395 /*
7396 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
7397 ** it takes up less space.
@@ -7675,10 +7718,11 @@
7675 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
7676 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
7677 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
7678 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
7679 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
 
7680 SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int,int,int);
7681 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
7682 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
7683 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
7684 #ifdef SQLITE_DEBUG
@@ -7692,20 +7736,23 @@
7692 SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
7693 SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
7694 SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, int);
7695 SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe*,Vdbe*);
7696 SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*);
7697 SQLITE_PRIVATE void sqlite3VdbeProgramDelete(sqlite3 *, SubProgram *, int);
7698 SQLITE_PRIVATE sqlite3_value *sqlite3VdbeGetValue(Vdbe*, int, u8);
7699 SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe*, int);
7700 #ifndef SQLITE_OMIT_TRACE
7701 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
7702 #endif
7703
7704 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,char*,int);
7705 SQLITE_PRIVATE void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord*);
7706 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
 
 
 
 
7707
7708
7709 #ifndef NDEBUG
7710 SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...);
7711 # define VdbeComment(X) sqlite3VdbeComment X
@@ -7851,10 +7898,11 @@
7851
7852 /* Functions used to manage pager transactions and savepoints. */
7853 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*, int*);
7854 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
7855 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
 
7856 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
7857 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
7858 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
7859 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
7860 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
@@ -8442,18 +8490,10 @@
8442 Schema *pSchema; /* Pointer to database schema (possibly shared) */
8443 };
8444
8445 /*
8446 ** An instance of the following structure stores a database schema.
8447 **
8448 ** If there are no virtual tables configured in this schema, the
8449 ** Schema.db variable is set to NULL. After the first virtual table
8450 ** has been added, it is set to point to the database connection
8451 ** used to create the connection. Once a virtual table has been
8452 ** added to the Schema structure and the Schema.db variable populated,
8453 ** only that database connection may use the Schema to prepare
8454 ** statements.
8455 */
8456 struct Schema {
8457 int schema_cookie; /* Database schema version number for this file */
8458 Hash tblHash; /* All tables indexed by name */
8459 Hash idxHash; /* All (named) indices indexed by name */
@@ -8462,13 +8502,10 @@
8462 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
8463 u8 file_format; /* Schema format version for this file */
8464 u8 enc; /* Text encoding used by this database */
8465 u16 flags; /* Flags associated with this schema */
8466 int cache_size; /* Number of pages to use in the cache */
8467 #ifndef SQLITE_OMIT_VIRTUALTABLE
8468 sqlite3 *db; /* "Owner" connection. See comment above */
8469 #endif
8470 };
8471
8472 /*
8473 ** These macros can be used to test, set, or clear bits in the
8474 ** Db.pSchema->flags field.
@@ -8652,10 +8689,11 @@
8652 Savepoint *pSavepoint; /* List of active savepoints */
8653 int nSavepoint; /* Number of non-transaction savepoints */
8654 int nStatement; /* Number of nested statement-transactions */
8655 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
8656 i64 nDeferredCons; /* Net deferred constraints this transaction. */
 
8657
8658 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
8659 /* The following variables are all protected by the STATIC_MASTER
8660 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
8661 **
@@ -9009,11 +9047,10 @@
9009 ** page number. Transient tables are used to hold the results of a
9010 ** sub-query that appears instead of a real table name in the FROM clause
9011 ** of a SELECT statement.
9012 */
9013 struct Table {
9014 sqlite3 *dbMem; /* DB connection used for lookaside allocations. */
9015 char *zName; /* Name of the table or view */
9016 int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
9017 int nCol; /* Number of columns in this table */
9018 Column *aCol; /* Information about each column */
9019 Index *pIndex; /* List of SQL indexes on this table. */
@@ -10118,11 +10155,11 @@
10118 char *zText; /* The string collected so far */
10119 int nChar; /* Length of the string so far */
10120 int nAlloc; /* Amount of space allocated in zText */
10121 int mxAlloc; /* Maximum allowed string length */
10122 u8 mallocFailed; /* Becomes true if any memory allocation fails */
10123 u8 useMalloc; /* True if zText is enlargeable using realloc */
10124 u8 tooBig; /* Becomes true if string size exceeds limits */
10125 };
10126
10127 /*
10128 ** A pointer to this structure is used to communicate information
@@ -10416,11 +10453,11 @@
10416 #else
10417 # define sqlite3ViewGetColumnNames(A,B) 0
10418 #endif
10419
10420 SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
10421 SQLITE_PRIVATE void sqlite3DeleteTable(Table*);
10422 #ifndef SQLITE_OMIT_AUTOINCREMENT
10423 SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
10424 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
10425 #else
10426 # define sqlite3AutoincrementBegin(X)
@@ -10650,11 +10687,12 @@
10650 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
10651 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
10652 SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
10653 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
10654 SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
10655 SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *);
 
10656 SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
10657 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
10658 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
10659
10660 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
@@ -10700,11 +10738,11 @@
10700 SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*);
10701 SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*);
10702 SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*);
10703 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *);
10704 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB);
10705 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(Index*);
10706 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
10707 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
10708 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
10709 SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
10710 SQLITE_PRIVATE void sqlite3SchemaFree(void *);
@@ -10762,11 +10800,11 @@
10762 # define sqlite3VtabInSync(db) 0
10763 # define sqlite3VtabLock(X)
10764 # define sqlite3VtabUnlock(X)
10765 # define sqlite3VtabUnlockList(X)
10766 #else
10767 SQLITE_PRIVATE void sqlite3VtabClear(Table*);
10768 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
10769 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
10770 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
10771 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
10772 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
@@ -10815,13 +10853,13 @@
10815 #define sqlite3FkDropTable(a,b,c)
10816 #define sqlite3FkOldmask(a,b) 0
10817 #define sqlite3FkRequired(a,b,c,d) 0
10818 #endif
10819 #ifndef SQLITE_OMIT_FOREIGN_KEY
10820 SQLITE_PRIVATE void sqlite3FkDelete(Table*);
10821 #else
10822 #define sqlite3FkDelete(a)
10823 #endif
10824
10825
10826 /*
10827 ** Available fault injectors. Should be numbered beginning with 0.
@@ -10910,36 +10948,40 @@
10910 ** a single bit set.
10911 **
10912 ** sqlite3MemdebugHasType() returns true if any of the bits in its second
10913 ** argument match the type set by the previous sqlite3MemdebugSetType().
10914 ** sqlite3MemdebugHasType() is intended for use inside assert() statements.
10915 ** For example:
10916 **
10917 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 
10918 **
10919 ** Perhaps the most important point is the difference between MEMTYPE_HEAP
10920 ** and MEMTYPE_DB. If an allocation is MEMTYPE_DB, that means it might have
10921 ** been allocated by lookaside, except the allocation was too large or
10922 ** lookaside was already full. It is important to verify that allocations
10923 ** that might have been satisfied by lookaside are not passed back to
10924 ** non-lookaside free() routines. Asserts such as the example above are
10925 ** placed on the non-lookaside free() routines to verify this constraint.
 
10926 **
10927 ** All of this is no-op for a production build. It only comes into
10928 ** play when the SQLITE_MEMDEBUG compile-time option is used.
10929 */
10930 #ifdef SQLITE_MEMDEBUG
10931 SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
10932 SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
 
10933 #else
10934 # define sqlite3MemdebugSetType(X,Y) /* no-op */
10935 # define sqlite3MemdebugHasType(X,Y) 1
 
10936 #endif
10937 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
10938 #define MEMTYPE_DB 0x02 /* Associated with a database connection */
10939 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
10940 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
 
10941
10942 #endif /* _SQLITEINT_H_ */
10943
10944 /************** End of sqliteInt.h *******************************************/
10945 /************** Begin file global.c ******************************************/
@@ -11566,18 +11608,442 @@
11566 *************************************************************************
11567 **
11568 ** This module implements the sqlite3_status() interface and related
11569 ** functionality.
11570 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11571
11572 /*
11573 ** Variables in which to record status information.
11574 */
11575 typedef struct sqlite3StatType sqlite3StatType;
11576 static SQLITE_WSD struct sqlite3StatType {
11577 int nowValue[9]; /* Current value */
11578 int mxValue[9]; /* Maximum value */
11579 } sqlite3Stat = { {0,}, {0,} };
11580
11581
11582 /* The "wsdStat" macro will resolve to the status information
11583 ** state vector. If writable static data is unsupported on the target,
@@ -11655,10 +12121,12 @@
11655 int op, /* Status verb */
11656 int *pCurrent, /* Write current value here */
11657 int *pHighwater, /* Write high-water mark here */
11658 int resetFlag /* Reset high-water mark if true */
11659 ){
 
 
11660 switch( op ){
11661 case SQLITE_DBSTATUS_LOOKASIDE_USED: {
11662 *pCurrent = db->lookaside.nOut;
11663 *pHighwater = db->lookaside.mxOut;
11664 if( resetFlag ){
@@ -11673,26 +12141,92 @@
11673 ** highwater mark is meaningless and is returned as zero.
11674 */
11675 case SQLITE_DBSTATUS_CACHE_USED: {
11676 int totalUsed = 0;
11677 int i;
 
11678 for(i=0; i<db->nDb; i++){
11679 Btree *pBt = db->aDb[i].pBt;
11680 if( pBt ){
11681 Pager *pPager = sqlite3BtreePager(pBt);
11682 totalUsed += sqlite3PagerMemUsed(pPager);
11683 }
11684 }
 
11685 *pCurrent = totalUsed;
11686 *pHighwater = 0;
11687 break;
11688 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11689 default: {
11690 return SQLITE_ERROR;
11691 }
11692 }
11693 return SQLITE_OK;
 
11694 }
11695
11696 /************** End of status.c **********************************************/
11697 /************** Begin file date.c ********************************************/
11698 /*
@@ -13820,23 +14354,38 @@
13820 int rc = 1;
13821 if( p ){
13822 struct MemBlockHdr *pHdr;
13823 pHdr = sqlite3MemsysGetHeader(p);
13824 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
13825 assert( (pHdr->eType & (pHdr->eType-1))==0 ); /* Only one type bit set */
13826 if( (pHdr->eType&eType)==0 ){
13827 void **pBt;
13828 pBt = (void**)pHdr;
13829 pBt -= pHdr->nBacktraceSlots;
13830 backtrace_symbols_fd(pBt, pHdr->nBacktrace, fileno(stderr));
13831 fprintf(stderr, "\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13832 rc = 0;
13833 }
13834 }
13835 return rc;
13836 }
13837
13838
13839 /*
13840 ** Set the number of backtrace levels kept for each allocation.
13841 ** A value of zero turns off backtracing. The number is always rounded
13842 ** up to a multiple of 2.
@@ -16773,10 +17322,11 @@
16773 p = sqlite3GlobalConfig.m.xMalloc(nFull);
16774 }
16775 if( p ){
16776 nFull = sqlite3MallocSize(p);
16777 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull);
 
16778 }
16779 *pp = p;
16780 return nFull;
16781 }
16782
@@ -16890,16 +17440,18 @@
16890 if( p ){
16891 if( sqlite3GlobalConfig.pScratch==0
16892 || p<sqlite3GlobalConfig.pScratch
16893 || p>=(void*)mem0.aScratchFree ){
16894 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
 
16895 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
16896 if( sqlite3GlobalConfig.bMemstat ){
16897 int iSize = sqlite3MallocSize(p);
16898 sqlite3_mutex_enter(mem0.mutex);
16899 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
16900 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
 
16901 sqlite3GlobalConfig.m.xFree(p);
16902 sqlite3_mutex_leave(mem0.mutex);
16903 }else{
16904 sqlite3GlobalConfig.m.xFree(p);
16905 }
@@ -16930,11 +17482,11 @@
16930 /*
16931 ** TRUE if p is a lookaside memory allocation from db
16932 */
16933 #ifndef SQLITE_OMIT_LOOKASIDE
16934 static int isLookaside(sqlite3 *db, void *p){
16935 return db && p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
16936 }
16937 #else
16938 #define isLookaside(A,B) 0
16939 #endif
16940
@@ -16942,32 +17494,36 @@
16942 ** Return the size of a memory allocation previously obtained from
16943 ** sqlite3Malloc() or sqlite3_malloc().
16944 */
16945 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
16946 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 
16947 return sqlite3GlobalConfig.m.xSize(p);
16948 }
16949 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
16950 assert( db==0 || sqlite3_mutex_held(db->mutex) );
16951 if( isLookaside(db, p) ){
16952 return db->lookaside.sz;
16953 }else{
16954 assert( sqlite3MemdebugHasType(p,
16955 db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
 
16956 return sqlite3GlobalConfig.m.xSize(p);
16957 }
16958 }
16959
16960 /*
16961 ** Free memory previously obtained from sqlite3Malloc().
16962 */
16963 SQLITE_API void sqlite3_free(void *p){
16964 if( p==0 ) return;
 
16965 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
16966 if( sqlite3GlobalConfig.bMemstat ){
16967 sqlite3_mutex_enter(mem0.mutex);
16968 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
 
16969 sqlite3GlobalConfig.m.xFree(p);
16970 sqlite3_mutex_leave(mem0.mutex);
16971 }else{
16972 sqlite3GlobalConfig.m.xFree(p);
16973 }
@@ -16977,20 +17533,28 @@
16977 ** Free memory that might be associated with a particular database
16978 ** connection.
16979 */
16980 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
16981 assert( db==0 || sqlite3_mutex_held(db->mutex) );
16982 if( isLookaside(db, p) ){
16983 LookasideSlot *pBuf = (LookasideSlot*)p;
16984 pBuf->pNext = db->lookaside.pFree;
16985 db->lookaside.pFree = pBuf;
16986 db->lookaside.nOut--;
16987 }else{
16988 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16989 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
16990 sqlite3_free(p);
16991 }
 
 
 
 
 
 
 
 
16992 }
16993
16994 /*
16995 ** Change the size of an existing memory allocation
16996 */
@@ -17018,10 +17582,11 @@
17018 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
17019 mem0.alarmThreshold ){
17020 sqlite3MallocAlarm(nNew-nOld);
17021 }
17022 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
 
17023 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
17024 if( pNew==0 && mem0.alarmCallback ){
17025 sqlite3MallocAlarm(nBytes);
17026 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
17027 }
@@ -17090,10 +17655,11 @@
17090 ** that all prior mallocs (ex: "a") worked too.
17091 */
17092 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
17093 void *p;
17094 assert( db==0 || sqlite3_mutex_held(db->mutex) );
 
17095 #ifndef SQLITE_OMIT_LOOKASIDE
17096 if( db ){
17097 LookasideSlot *pBuf;
17098 if( db->mallocFailed ){
17099 return 0;
@@ -17115,12 +17681,12 @@
17115 #endif
17116 p = sqlite3Malloc(n);
17117 if( !p && db ){
17118 db->mallocFailed = 1;
17119 }
17120 sqlite3MemdebugSetType(p,
17121 (db && db->lookaside.bEnabled) ? MEMTYPE_DB : MEMTYPE_HEAP);
17122 return p;
17123 }
17124
17125 /*
17126 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -17142,18 +17708,20 @@
17142 if( pNew ){
17143 memcpy(pNew, p, db->lookaside.sz);
17144 sqlite3DbFree(db, p);
17145 }
17146 }else{
17147 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
 
17148 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
17149 pNew = sqlite3_realloc(p, n);
17150 if( !pNew ){
 
17151 db->mallocFailed = 1;
17152 }
17153 sqlite3MemdebugSetType(pNew,
17154 db->lookaside.bEnabled ? MEMTYPE_DB : MEMTYPE_HEAP);
17155 }
17156 }
17157 return pNew;
17158 }
17159
@@ -18022,11 +18590,15 @@
18022 p->tooBig = 1;
18023 return;
18024 }else{
18025 p->nAlloc = (int)szNew;
18026 }
18027 zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
 
 
 
 
18028 if( zNew ){
18029 memcpy(zNew, p->zText, p->nChar);
18030 sqlite3StrAccumReset(p);
18031 p->zText = zNew;
18032 }else{
@@ -18047,11 +18619,15 @@
18047 */
18048 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
18049 if( p->zText ){
18050 p->zText[p->nChar] = 0;
18051 if( p->useMalloc && p->zText==p->zBase ){
18052 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
 
 
 
 
18053 if( p->zText ){
18054 memcpy(p->zText, p->zBase, p->nChar+1);
18055 }else{
18056 p->mallocFailed = 1;
18057 }
@@ -18063,11 +18639,15 @@
18063 /*
18064 ** Reset an StrAccum string. Reclaim all malloced memory.
18065 */
18066 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
18067 if( p->zText!=p->zBase ){
18068 sqlite3DbFree(p->db, p->zText);
 
 
 
 
18069 }
18070 p->zText = 0;
18071 }
18072
18073 /*
@@ -18145,10 +18725,11 @@
18145 StrAccum acc;
18146 #ifndef SQLITE_OMIT_AUTOINIT
18147 if( sqlite3_initialize() ) return 0;
18148 #endif
18149 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
 
18150 sqlite3VXPrintf(&acc, 0, zFormat, ap);
18151 z = sqlite3StrAccumFinish(&acc);
18152 return z;
18153 }
18154
@@ -18438,433 +19019,10 @@
18438 ** BOM or Byte Order Mark:
18439 ** 0xff 0xfe little-endian utf-16 follows
18440 ** 0xfe 0xff big-endian utf-16 follows
18441 **
18442 */
18443 /************** Include vdbeInt.h in the middle of utf.c *********************/
18444 /************** Begin file vdbeInt.h *****************************************/
18445 /*
18446 ** 2003 September 6
18447 **
18448 ** The author disclaims copyright to this source code. In place of
18449 ** a legal notice, here is a blessing:
18450 **
18451 ** May you do good and not evil.
18452 ** May you find forgiveness for yourself and forgive others.
18453 ** May you share freely, never taking more than you give.
18454 **
18455 *************************************************************************
18456 ** This is the header file for information that is private to the
18457 ** VDBE. This information used to all be at the top of the single
18458 ** source code file "vdbe.c". When that file became too big (over
18459 ** 6000 lines long) it was split up into several smaller files and
18460 ** this header information was factored out.
18461 */
18462 #ifndef _VDBEINT_H_
18463 #define _VDBEINT_H_
18464
18465 /*
18466 ** SQL is translated into a sequence of instructions to be
18467 ** executed by a virtual machine. Each instruction is an instance
18468 ** of the following structure.
18469 */
18470 typedef struct VdbeOp Op;
18471
18472 /*
18473 ** Boolean values
18474 */
18475 typedef unsigned char Bool;
18476
18477 /*
18478 ** A cursor is a pointer into a single BTree within a database file.
18479 ** The cursor can seek to a BTree entry with a particular key, or
18480 ** loop over all entries of the Btree. You can also insert new BTree
18481 ** entries or retrieve the key or data from the entry that the cursor
18482 ** is currently pointing to.
18483 **
18484 ** Every cursor that the virtual machine has open is represented by an
18485 ** instance of the following structure.
18486 **
18487 ** If the VdbeCursor.isTriggerRow flag is set it means that this cursor is
18488 ** really a single row that represents the NEW or OLD pseudo-table of
18489 ** a row trigger. The data for the row is stored in VdbeCursor.pData and
18490 ** the rowid is in VdbeCursor.iKey.
18491 */
18492 struct VdbeCursor {
18493 BtCursor *pCursor; /* The cursor structure of the backend */
18494 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
18495 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
18496 Bool zeroed; /* True if zeroed out and ready for reuse */
18497 Bool rowidIsValid; /* True if lastRowid is valid */
18498 Bool atFirst; /* True if pointing to first entry */
18499 Bool useRandomRowid; /* Generate new record numbers semi-randomly */
18500 Bool nullRow; /* True if pointing to a row with no data */
18501 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
18502 Bool isTable; /* True if a table requiring integer keys */
18503 Bool isIndex; /* True if an index containing keys only - no data */
18504 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
18505 Btree *pBt; /* Separate file holding temporary table */
18506 int pseudoTableReg; /* Register holding pseudotable content. */
18507 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
18508 int nField; /* Number of fields in the header */
18509 i64 seqCount; /* Sequence counter */
18510 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
18511 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
18512
18513 /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
18514 ** OP_IsUnique opcode on this cursor. */
18515 int seekResult;
18516
18517 /* Cached information about the header for the data record that the
18518 ** cursor is currently pointing to. Only valid if cacheStatus matches
18519 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
18520 ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
18521 ** the cache is out of date.
18522 **
18523 ** aRow might point to (ephemeral) data for the current row, or it might
18524 ** be NULL.
18525 */
18526 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
18527 int payloadSize; /* Total number of bytes in the record */
18528 u32 *aType; /* Type values for all entries in the record */
18529 u32 *aOffset; /* Cached offsets to the start of each columns data */
18530 u8 *aRow; /* Data for the current row, if all on one page */
18531 };
18532 typedef struct VdbeCursor VdbeCursor;
18533
18534 /*
18535 ** When a sub-program is executed (OP_Program), a structure of this type
18536 ** is allocated to store the current value of the program counter, as
18537 ** well as the current memory cell array and various other frame specific
18538 ** values stored in the Vdbe struct. When the sub-program is finished,
18539 ** these values are copied back to the Vdbe from the VdbeFrame structure,
18540 ** restoring the state of the VM to as it was before the sub-program
18541 ** began executing.
18542 **
18543 ** Frames are stored in a linked list headed at Vdbe.pParent. Vdbe.pParent
18544 ** is the parent of the current frame, or zero if the current frame
18545 ** is the main Vdbe program.
18546 */
18547 typedef struct VdbeFrame VdbeFrame;
18548 struct VdbeFrame {
18549 Vdbe *v; /* VM this frame belongs to */
18550 int pc; /* Program Counter */
18551 Op *aOp; /* Program instructions */
18552 int nOp; /* Size of aOp array */
18553 Mem *aMem; /* Array of memory cells */
18554 int nMem; /* Number of entries in aMem */
18555 VdbeCursor **apCsr; /* Element of Vdbe cursors */
18556 u16 nCursor; /* Number of entries in apCsr */
18557 void *token; /* Copy of SubProgram.token */
18558 int nChildMem; /* Number of memory cells for child frame */
18559 int nChildCsr; /* Number of cursors for child frame */
18560 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
18561 int nChange; /* Statement changes (Vdbe.nChanges) */
18562 VdbeFrame *pParent; /* Parent of this frame */
18563 };
18564
18565 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
18566
18567 /*
18568 ** A value for VdbeCursor.cacheValid that means the cache is always invalid.
18569 */
18570 #define CACHE_STALE 0
18571
18572 /*
18573 ** Internally, the vdbe manipulates nearly all SQL values as Mem
18574 ** structures. Each Mem struct may cache multiple representations (string,
18575 ** integer etc.) of the same value. A value (and therefore Mem structure)
18576 ** has the following properties:
18577 **
18578 ** Each value has a manifest type. The manifest type of the value stored
18579 ** in a Mem struct is returned by the MemType(Mem*) macro. The type is
18580 ** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
18581 ** SQLITE_BLOB.
18582 */
18583 struct Mem {
18584 union {
18585 i64 i; /* Integer value. */
18586 int nZero; /* Used when bit MEM_Zero is set in flags */
18587 FuncDef *pDef; /* Used only when flags==MEM_Agg */
18588 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
18589 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
18590 } u;
18591 double r; /* Real value */
18592 sqlite3 *db; /* The associated database connection */
18593 char *z; /* String or BLOB value */
18594 int n; /* Number of characters in string value, excluding '\0' */
18595 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
18596 u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
18597 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
18598 void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
18599 char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
18600 };
18601
18602 /* One or more of the following flags are set to indicate the validOK
18603 ** representations of the value stored in the Mem struct.
18604 **
18605 ** If the MEM_Null flag is set, then the value is an SQL NULL value.
18606 ** No other flags may be set in this case.
18607 **
18608 ** If the MEM_Str flag is set then Mem.z points at a string representation.
18609 ** Usually this is encoded in the same unicode encoding as the main
18610 ** database (see below for exceptions). If the MEM_Term flag is also
18611 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
18612 ** flags may coexist with the MEM_Str flag.
18613 **
18614 ** Multiple of these values can appear in Mem.flags. But only one
18615 ** at a time can appear in Mem.type.
18616 */
18617 #define MEM_Null 0x0001 /* Value is NULL */
18618 #define MEM_Str 0x0002 /* Value is a string */
18619 #define MEM_Int 0x0004 /* Value is an integer */
18620 #define MEM_Real 0x0008 /* Value is a real number */
18621 #define MEM_Blob 0x0010 /* Value is a BLOB */
18622 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
18623 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
18624 #define MEM_TypeMask 0x00ff /* Mask of type bits */
18625
18626 /* Whenever Mem contains a valid string or blob representation, one of
18627 ** the following flags must be set to determine the memory management
18628 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
18629 ** string is \000 or \u0000 terminated
18630 */
18631 #define MEM_Term 0x0200 /* String rep is nul terminated */
18632 #define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
18633 #define MEM_Static 0x0800 /* Mem.z points to a static string */
18634 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
18635 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
18636 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
18637
18638 #ifdef SQLITE_OMIT_INCRBLOB
18639 #undef MEM_Zero
18640 #define MEM_Zero 0x0000
18641 #endif
18642
18643
18644 /*
18645 ** Clear any existing type flags from a Mem and replace them with f
18646 */
18647 #define MemSetTypeFlag(p, f) \
18648 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
18649
18650
18651 /* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
18652 ** additional information about auxiliary information bound to arguments
18653 ** of the function. This is used to implement the sqlite3_get_auxdata()
18654 ** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
18655 ** that can be associated with a constant argument to a function. This
18656 ** allows functions such as "regexp" to compile their constant regular
18657 ** expression argument once and reused the compiled code for multiple
18658 ** invocations.
18659 */
18660 struct VdbeFunc {
18661 FuncDef *pFunc; /* The definition of the function */
18662 int nAux; /* Number of entries allocated for apAux[] */
18663 struct AuxData {
18664 void *pAux; /* Aux data for the i-th argument */
18665 void (*xDelete)(void *); /* Destructor for the aux data */
18666 } apAux[1]; /* One slot for each function argument */
18667 };
18668
18669 /*
18670 ** The "context" argument for a installable function. A pointer to an
18671 ** instance of this structure is the first argument to the routines used
18672 ** implement the SQL functions.
18673 **
18674 ** There is a typedef for this structure in sqlite.h. So all routines,
18675 ** even the public interface to SQLite, can use a pointer to this structure.
18676 ** But this file is the only place where the internal details of this
18677 ** structure are known.
18678 **
18679 ** This structure is defined inside of vdbeInt.h because it uses substructures
18680 ** (Mem) which are only defined there.
18681 */
18682 struct sqlite3_context {
18683 FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
18684 VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
18685 Mem s; /* The return value is stored here */
18686 Mem *pMem; /* Memory cell used to store aggregate context */
18687 int isError; /* Error code returned by the function. */
18688 CollSeq *pColl; /* Collating sequence */
18689 };
18690
18691 /*
18692 ** A Set structure is used for quick testing to see if a value
18693 ** is part of a small set. Sets are used to implement code like
18694 ** this:
18695 ** x.y IN ('hi','hoo','hum')
18696 */
18697 typedef struct Set Set;
18698 struct Set {
18699 Hash hash; /* A set is just a hash table */
18700 HashElem *prev; /* Previously accessed hash elemen */
18701 };
18702
18703 /*
18704 ** An instance of the virtual machine. This structure contains the complete
18705 ** state of the virtual machine.
18706 **
18707 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()
18708 ** is really a pointer to an instance of this structure.
18709 **
18710 ** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
18711 ** any virtual table method invocations made by the vdbe program. It is
18712 ** set to 2 for xDestroy method calls and 1 for all other methods. This
18713 ** variable is used for two purposes: to allow xDestroy methods to execute
18714 ** "DROP TABLE" statements and to prevent some nasty side effects of
18715 ** malloc failure when SQLite is invoked recursively by a virtual table
18716 ** method function.
18717 */
18718 struct Vdbe {
18719 sqlite3 *db; /* The database connection that owns this statement */
18720 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
18721 int nOp; /* Number of instructions in the program */
18722 int nOpAlloc; /* Number of slots allocated for aOp[] */
18723 Op *aOp; /* Space to hold the virtual machine's program */
18724 int nLabel; /* Number of labels used */
18725 int nLabelAlloc; /* Number of slots allocated in aLabel[] */
18726 int *aLabel; /* Space to hold the labels */
18727 Mem **apArg; /* Arguments to currently executing user function */
18728 Mem *aColName; /* Column names to return */
18729 Mem *pResultSet; /* Pointer to an array of results */
18730 u16 nResColumn; /* Number of columns in one row of the result set */
18731 u16 nCursor; /* Number of slots in apCsr[] */
18732 VdbeCursor **apCsr; /* One element of this array for each open cursor */
18733 u8 errorAction; /* Recovery action to do in case of an error */
18734 u8 okVar; /* True if azVar[] has been initialized */
18735 ynVar nVar; /* Number of entries in aVar[] */
18736 Mem *aVar; /* Values for the OP_Variable opcode. */
18737 char **azVar; /* Name of variables */
18738 u32 magic; /* Magic number for sanity checking */
18739 int nMem; /* Number of memory locations currently allocated */
18740 Mem *aMem; /* The memory locations */
18741 u32 cacheCtr; /* VdbeCursor row cache generation counter */
18742 int pc; /* The program counter */
18743 int rc; /* Value to return */
18744 char *zErrMsg; /* Error message written here */
18745 u8 explain; /* True if EXPLAIN present on SQL command */
18746 u8 changeCntOn; /* True to update the change-counter */
18747 u8 expired; /* True if the VM needs to be recompiled */
18748 u8 runOnlyOnce; /* Automatically expire on reset */
18749 u8 minWriteFileFormat; /* Minimum file format for writable database files */
18750 u8 inVtabMethod; /* See comments above */
18751 u8 usesStmtJournal; /* True if uses a statement journal */
18752 u8 readOnly; /* True for read-only statements */
18753 u8 isPrepareV2; /* True if prepared with prepare_v2() */
18754 int nChange; /* Number of db changes made since last reset */
18755 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
18756 i64 startTime; /* Time when query started - used for profiling */
18757 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
18758 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
18759 char *zSql; /* Text of the SQL statement that generated this */
18760 void *pFree; /* Free this when deleting the vdbe */
18761 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
18762 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
18763 int iStatement; /* Statement number (or 0 if has not opened stmt) */
18764 #ifdef SQLITE_DEBUG
18765 FILE *trace; /* Write an execution trace here, if not NULL */
18766 #endif
18767 VdbeFrame *pFrame; /* Parent frame */
18768 int nFrame; /* Number of frames in pFrame list */
18769 u32 expmask; /* Binding to these vars invalidates VM */
18770 };
18771
18772 /*
18773 ** The following are allowed values for Vdbe.magic
18774 */
18775 #define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */
18776 #define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */
18777 #define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */
18778 #define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */
18779
18780 /*
18781 ** Function prototypes
18782 */
18783 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
18784 void sqliteVdbePopStack(Vdbe*,int);
18785 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
18786 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
18787 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
18788 #endif
18789 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
18790 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
18791 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
18792 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
18793 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
18794
18795 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
18796 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
18797 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
18798 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
18799 SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
18800 SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
18801 SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
18802 SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int);
18803 SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*);
18804 SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem*, const Mem*);
18805 SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
18806 SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem*, Mem*);
18807 SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem*);
18808 SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
18809 SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem*, i64);
18810 #ifdef SQLITE_OMIT_FLOATING_POINT
18811 # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
18812 #else
18813 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
18814 #endif
18815 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
18816 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
18817 SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
18818 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
18819 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, int);
18820 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*);
18821 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
18822 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
18823 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
18824 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
18825 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
18826 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
18827 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
18828 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
18829 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
18830 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
18831 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
18832 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
18833 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
18834 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
18835 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
18836
18837 #ifndef SQLITE_OMIT_FOREIGN_KEY
18838 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
18839 #else
18840 # define sqlite3VdbeCheckFk(p,i) 0
18841 #endif
18842
18843 #ifndef SQLITE_OMIT_SHARED_CACHE
18844 SQLITE_PRIVATE void sqlite3VdbeMutexArrayEnter(Vdbe *p);
18845 #else
18846 # define sqlite3VdbeMutexArrayEnter(p)
18847 #endif
18848
18849 SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
18850 #ifdef SQLITE_DEBUG
18851 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*);
18852 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
18853 #endif
18854 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
18855
18856 #ifndef SQLITE_OMIT_INCRBLOB
18857 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *);
18858 #else
18859 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
18860 #endif
18861
18862 #endif /* !defined(_VDBEINT_H_) */
18863
18864 /************** End of vdbeInt.h *********************************************/
18865 /************** Continuing where we left off in utf.c ************************/
18866
18867 #ifndef SQLITE_AMALGAMATION
18868 /*
18869 ** The following constant value is used by the SQLITE_BIGENDIAN and
18870 ** SQLITE_LITTLEENDIAN macros.
@@ -21891,11 +22049,11 @@
21891 }
21892
21893
21894 memset( pFile, 0, sizeof(*pFile) );
21895
21896 OSTRACE( "OPEN want %d\n", flags ));
21897
21898 if( flags & SQLITE_OPEN_READWRITE ){
21899 ulOpenMode |= OPEN_ACCESS_READWRITE;
21900 OSTRACE(( "OPEN read/write\n" ));
21901 }else{
@@ -32701,15 +32859,15 @@
32701 ** back to sqlite3Malloc().
32702 */
32703 static void *pcache1Alloc(int nByte){
32704 void *p;
32705 assert( sqlite3_mutex_held(pcache1.mutex) );
 
32706 if( nByte<=pcache1.szSlot && pcache1.pFree ){
32707 assert( pcache1.isInit );
32708 p = (PgHdr1 *)pcache1.pFree;
32709 pcache1.pFree = pcache1.pFree->pNext;
32710 sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
32711 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
32712 }else{
32713
32714 /* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
32715 ** global pcache mutex and unlock the pager-cache object pCache. This is
@@ -34150,34 +34308,42 @@
34150 ** It is used when committing or otherwise ending a transaction. If
34151 ** the dbModified flag is clear then less work has to be done.
34152 **
34153 ** journalStarted
34154 **
34155 ** This flag is set whenever the the main journal is opened and
34156 ** initialized
34157 **
34158 ** The point of this flag is that it must be set after the
34159 ** first journal header in a journal file has been synced to disk.
34160 ** After this has happened, new pages appended to the database
34161 ** do not need the PGHDR_NEED_SYNC flag set, as they do not need
34162 ** to wait for a journal sync before they can be written out to
34163 ** the database file (see function pager_write()).
34164 **
34165 ** setMaster
34166 **
34167 ** This variable is used to ensure that the master journal file name
34168 ** (if any) is only written into the journal file once.
 
34169 **
34170 ** When committing a transaction, the master journal file name (if any)
34171 ** may be written into the journal file while the pager is still in
34172 ** PAGER_RESERVED state (see CommitPhaseOne() for the action). It
34173 ** then attempts to upgrade to an exclusive lock. If this attempt
34174 ** fails, then SQLITE_BUSY may be returned to the user and the user
34175 ** may attempt to commit the transaction again later (calling
34176 ** CommitPhaseOne() again). This flag is used to ensure that the
34177 ** master journal name is only written to the journal file the first
34178 ** time CommitPhaseOne() is called.
 
 
 
 
 
 
 
 
 
34179 **
34180 ** doNotSpill, doNotSyncSpill
34181 **
34182 ** When enabled, cache spills are prohibited. The doNotSpill variable
34183 ** inhibits all cache spill and doNotSyncSpill inhibits those spills that
@@ -34941,11 +35107,12 @@
34941 int nMaster; /* Length of string zMaster */
34942 i64 iHdrOff; /* Offset of header in journal file */
34943 i64 jrnlSize; /* Size of journal file on disk */
34944 u32 cksum = 0; /* Checksum of string zMaster */
34945
34946 if( !zMaster || pPager->setMaster
 
34947 || pPager->journalMode==PAGER_JOURNALMODE_MEMORY
34948 || pPager->journalMode==PAGER_JOURNALMODE_OFF
34949 ){
34950 return SQLITE_OK;
34951 }
@@ -38928,10 +39095,30 @@
38928 }else{
38929 rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
38930 }
38931 return rc;
38932 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38933
38934 /*
38935 ** Sync the database file for the pager pPager. zMaster points to the name
38936 ** of a master journal file that should be written into the individual
38937 ** journal file. zMaster may be NULL, which is interpreted as no master
@@ -38977,11 +39164,11 @@
38977 /* If this is an in-memory db, or no pages have been written to, or this
38978 ** function has already been called, it is mostly a no-op. However, any
38979 ** backup in progress needs to be restarted.
38980 */
38981 sqlite3BackupRestart(pPager->pBackup);
38982 }else if( pPager->state!=PAGER_SYNCED && pPager->dbModified ){
38983 if( pagerUseWal(pPager) ){
38984 PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
38985 if( pList ){
38986 rc = pagerWalFrames(pPager, pList, pPager->dbSize, 1,
38987 (pPager->fullSync ? pPager->sync_flags : 0)
@@ -39115,10 +39302,11 @@
39115 rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
39116 }
39117 IOTRACE(("DBSYNC %p\n", pPager))
39118 }
39119
 
39120 pPager->state = PAGER_SYNCED;
39121 }
39122
39123 commit_phase_one_exit:
39124 return rc;
@@ -39282,13 +39470,15 @@
39282 /*
39283 ** Return the approximate number of bytes of memory currently
39284 ** used by the pager and its associated cache.
39285 */
39286 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
39287 int perPageSize = pPager->pageSize + pPager->nExtra + 20;
 
39288 return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
39289 + sqlite3MallocSize(pPager);
 
39290 }
39291
39292 /*
39293 ** Return the number of references to the specified page.
39294 */
@@ -45683,11 +45873,11 @@
45683 assert( !pBt->pCursor );
45684 sqlite3PagerClose(pBt->pPager);
45685 if( pBt->xFreeSchema && pBt->pSchema ){
45686 pBt->xFreeSchema(pBt->pSchema);
45687 }
45688 sqlite3_free(pBt->pSchema);
45689 freeTempSpace(pBt);
45690 sqlite3_free(pBt);
45691 }
45692
45693 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -46248,17 +46438,31 @@
46248 }
46249 p->inTrans = (wrflag?TRANS_WRITE:TRANS_READ);
46250 if( p->inTrans>pBt->inTransaction ){
46251 pBt->inTransaction = p->inTrans;
46252 }
46253 #ifndef SQLITE_OMIT_SHARED_CACHE
46254 if( wrflag ){
 
 
46255 assert( !pBt->pWriter );
46256 pBt->pWriter = p;
46257 pBt->isExclusive = (u8)(wrflag>1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46258 }
46259 #endif
46260 }
46261
46262
46263 trans_begun:
46264 if( rc==SQLITE_OK && wrflag ){
@@ -46993,13 +47197,15 @@
46993 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
46994 if( rc==SQLITE_OK ){
46995 if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
46996 rc = newDatabase(pBt);
46997 pBt->nPage = get4byte(28 + pBt->pPage1->aData);
46998 if( pBt->nPage==0 ){
46999 sqlite3PagerPagecount(pBt->pPager, (int*)&pBt->nPage);
47000 }
 
 
47001 }
47002 sqlite3BtreeLeave(p);
47003 }
47004 return rc;
47005 }
@@ -51428,10 +51634,11 @@
51428 i = PENDING_BYTE_PAGE(pBt);
51429 if( i<=sCheck.nPage ){
51430 sCheck.anRef[i] = 1;
51431 }
51432 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000);
 
51433
51434 /* Check the integrity of the freelist
51435 */
51436 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
51437 get4byte(&pBt->pPage1->aData[36]), "Main freelist: ");
@@ -51526,10 +51733,33 @@
51526 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree *p){
51527 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
51528 return (p && (p->inTrans==TRANS_WRITE));
51529 }
51530
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51531 /*
51532 ** Return non-zero if a read (or write) transaction is active.
51533 */
51534 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
51535 assert( p );
@@ -51565,11 +51795,11 @@
51565 */
51566 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
51567 BtShared *pBt = p->pBt;
51568 sqlite3BtreeEnter(p);
51569 if( !pBt->pSchema && nBytes ){
51570 pBt->pSchema = sqlite3MallocZero(nBytes);
51571 pBt->xFreeSchema = xFree;
51572 }
51573 sqlite3BtreeLeave(p);
51574 return pBt->pSchema;
51575 }
@@ -53373,11 +53603,11 @@
53373 *ppVal = 0;
53374 return SQLITE_OK;
53375 }
53376 op = pExpr->op;
53377
53378 /* op can only be TK_REGISTER is we have compiled with SQLITE_ENABLE_STAT2.
53379 ** The ifdef here is to enable us to achieve 100% branch test coverage even
53380 ** when SQLITE_ENABLE_STAT2 is omitted.
53381 */
53382 #ifdef SQLITE_ENABLE_STAT2
53383 if( op==TK_REGISTER ) op = pExpr->op2;
@@ -54051,47 +54281,55 @@
54051 if( ALWAYS(pDef) && (pDef->flags & SQLITE_FUNC_EPHEM)!=0 ){
54052 sqlite3DbFree(db, pDef);
54053 }
54054 }
54055
 
 
54056 /*
54057 ** Delete a P4 value if necessary.
54058 */
54059 static void freeP4(sqlite3 *db, int p4type, void *p4){
54060 if( p4 ){
 
54061 switch( p4type ){
54062 case P4_REAL:
54063 case P4_INT64:
54064 case P4_MPRINTF:
54065 case P4_DYNAMIC:
54066 case P4_KEYINFO:
54067 case P4_INTARRAY:
54068 case P4_KEYINFO_HANDOFF: {
54069 sqlite3DbFree(db, p4);
54070 break;
 
 
 
 
54071 }
54072 case P4_VDBEFUNC: {
54073 VdbeFunc *pVdbeFunc = (VdbeFunc *)p4;
54074 freeEphemeralFunction(db, pVdbeFunc->pFunc);
54075 sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
54076 sqlite3DbFree(db, pVdbeFunc);
54077 break;
54078 }
54079 case P4_FUNCDEF: {
54080 freeEphemeralFunction(db, (FuncDef*)p4);
54081 break;
54082 }
54083 case P4_MEM: {
54084 sqlite3ValueFree((sqlite3_value*)p4);
 
 
 
 
 
 
54085 break;
54086 }
54087 case P4_VTAB : {
54088 sqlite3VtabUnlock((VTable *)p4);
54089 break;
54090 }
54091 case P4_SUBPROGRAM : {
54092 sqlite3VdbeProgramDelete(db, (SubProgram *)p4, 1);
54093 break;
54094 }
54095 }
54096 }
54097 }
@@ -54113,38 +54351,18 @@
54113 }
54114 sqlite3DbFree(db, aOp);
54115 }
54116
54117 /*
54118 ** Decrement the ref-count on the SubProgram structure passed as the
54119 ** second argument. If the ref-count reaches zero, free the structure.
54120 **
54121 ** The array of VDBE opcodes stored as SubProgram.aOp is freed if
54122 ** either the ref-count reaches zero or parameter freeop is non-zero.
54123 **
54124 ** Since the array of opcodes pointed to by SubProgram.aOp may directly
54125 ** or indirectly contain a reference to the SubProgram structure itself.
54126 ** By passing a non-zero freeop parameter, the caller may ensure that all
54127 ** SubProgram structures and their aOp arrays are freed, even when there
54128 ** are such circular references.
54129 */
54130 SQLITE_PRIVATE void sqlite3VdbeProgramDelete(sqlite3 *db, SubProgram *p, int freeop){
54131 if( p ){
54132 assert( p->nRef>0 );
54133 if( freeop || p->nRef==1 ){
54134 Op *aOp = p->aOp;
54135 p->aOp = 0;
54136 vdbeFreeOpArray(db, aOp, p->nOp);
54137 p->nOp = 0;
54138 }
54139 p->nRef--;
54140 if( p->nRef==0 ){
54141 sqlite3DbFree(db, p);
54142 }
54143 }
54144 }
54145
54146
54147 /*
54148 ** Change N opcodes starting at addr to No-ops.
54149 */
54150 SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe *p, int addr, int N){
@@ -54217,11 +54435,11 @@
54217 KeyInfo *pKeyInfo;
54218 int nField, nByte;
54219
54220 nField = ((KeyInfo*)zP4)->nField;
54221 nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
54222 pKeyInfo = sqlite3Malloc( nByte );
54223 pOp->p4.pKeyInfo = pKeyInfo;
54224 if( pKeyInfo ){
54225 u8 *aSortOrder;
54226 memcpy((char*)pKeyInfo, zP4, nByte - nField);
54227 aSortOrder = pKeyInfo->aSortOrder;
@@ -54481,10 +54699,16 @@
54481 static void releaseMemArray(Mem *p, int N){
54482 if( p && N ){
54483 Mem *pEnd;
54484 sqlite3 *db = p->db;
54485 u8 malloc_failed = db->mallocFailed;
 
 
 
 
 
 
54486 for(pEnd=&p[N]; p<pEnd; p++){
54487 assert( (&p[1])==pEnd || p[0].db==p[1].db );
54488
54489 /* This block is really an inlined version of sqlite3VdbeMemRelease()
54490 ** that takes advantage of the fact that the memory cell value is
@@ -55130,26 +55354,27 @@
55130 ** be done before determining whether a master journal file is
55131 ** required, as an xSync() callback may add an attached database
55132 ** to the transaction.
55133 */
55134 rc = sqlite3VtabSync(db, &p->zErrMsg);
55135 if( rc!=SQLITE_OK ){
55136 return rc;
55137 }
55138
55139 /* This loop determines (a) if the commit hook should be invoked and
55140 ** (b) how many database files have open write transactions, not
55141 ** including the temp database. (b) is important because if more than
55142 ** one database file has an open write transaction, a master journal
55143 ** file is required for an atomic commit.
55144 */
55145 for(i=0; i<db->nDb; i++){
55146 Btree *pBt = db->aDb[i].pBt;
55147 if( sqlite3BtreeIsInTrans(pBt) ){
55148 needXcommit = 1;
55149 if( i!=1 ) nTrans++;
 
55150 }
 
 
 
55151 }
55152
55153 /* If there are any write-transactions at all, invoke the commit hook */
55154 if( needXcommit && db->xCommitCallback ){
55155 rc = db->xCommitCallback(db->pCommitArg);
@@ -55285,10 +55510,11 @@
55285 if( pBt ){
55286 rc = sqlite3BtreeCommitPhaseOne(pBt, zMaster);
55287 }
55288 }
55289 sqlite3OsCloseFree(pMaster);
 
55290 if( rc!=SQLITE_OK ){
55291 sqlite3DbFree(db, zMaster);
55292 return rc;
55293 }
55294
@@ -55812,10 +56038,34 @@
55812 }
55813 pAux->pAux = 0;
55814 }
55815 }
55816 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55817
55818 /*
55819 ** Delete an entire VDBE.
55820 */
55821 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){
@@ -55830,20 +56080,13 @@
55830 db->pVdbe = p->pNext;
55831 }
55832 if( p->pNext ){
55833 p->pNext->pPrev = p->pPrev;
55834 }
55835 releaseMemArray(p->aVar, p->nVar);
55836 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
55837 vdbeFreeOpArray(db, p->aOp, p->nOp);
55838 sqlite3DbFree(db, p->aLabel);
55839 sqlite3DbFree(db, p->aColName);
55840 sqlite3DbFree(db, p->zSql);
55841 p->magic = VDBE_MAGIC_DEAD;
55842 sqlite3DbFree(db, p->pFree);
55843 p->db = 0;
55844 sqlite3DbFree(db, p);
55845 }
55846
55847 /*
55848 ** Make sure the cursor p is ready to read or write the row to which it
55849 ** was last positioned. Return an error code if an OOM fault or I/O error
@@ -55865,15 +56108,12 @@
55865 #endif
55866 assert( p->isTable );
55867 rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
55868 if( rc ) return rc;
55869 p->lastRowid = p->movetoTarget;
55870 p->rowidIsValid = ALWAYS(res==0) ?1:0;
55871 if( NEVER(res<0) ){
55872 rc = sqlite3BtreeNext(p->pCursor, &res);
55873 if( rc ) return rc;
55874 }
55875 #ifdef SQLITE_TEST
55876 sqlite3_search_count++;
55877 #endif
55878 p->deferredMoveto = 0;
55879 p->cacheStatus = CACHE_STALE;
@@ -57013,11 +57253,11 @@
57013 /* Invoke the profile callback if there is one
57014 */
57015 if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
57016 sqlite3_int64 iNow;
57017 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
57018 db->xProfile(db->pProfileArg, p->zSql, iNow - p->startTime);
57019 }
57020 #endif
57021
57022 if( rc==SQLITE_DONE ){
57023 assert( p->rc==SQLITE_OK );
@@ -58628,10 +58868,24 @@
58628 for(p=db->pSavepoint; p; p=p->pNext) n++;
58629 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
58630 return 1;
58631 }
58632 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58633
58634 /*
58635 ** Execute as much of a VDBE program as we can then return.
58636 **
58637 ** sqlite3VdbeMakeReady() must be called before this routine in order to
@@ -62627,13 +62881,11 @@
62627 }else if( u.bi.pC->pVtabCursor ){
62628 u.bi.pVtab = u.bi.pC->pVtabCursor->pVtab;
62629 u.bi.pModule = u.bi.pVtab->pModule;
62630 assert( u.bi.pModule->xRowid );
62631 rc = u.bi.pModule->xRowid(u.bi.pC->pVtabCursor, &u.bi.v);
62632 sqlite3DbFree(db, p->zErrMsg);
62633 p->zErrMsg = u.bi.pVtab->zErrMsg;
62634 u.bi.pVtab->zErrMsg = 0;
62635 #endif /* SQLITE_OMIT_VIRTUALTABLE */
62636 }else{
62637 assert( u.bi.pC->pCursor!=0 );
62638 rc = sqlite3VdbeCursorMoveto(u.bi.pC);
62639 if( rc ) goto abort_due_to_error;
@@ -64018,15 +64270,11 @@
64018 #if 0 /* local variables moved into u.cf */
64019 VTable *pVTab;
64020 #endif /* local variables moved into u.cf */
64021 u.cf.pVTab = pOp->p4.pVtab;
64022 rc = sqlite3VtabBegin(db, u.cf.pVTab);
64023 if( u.cf.pVTab ){
64024 sqlite3DbFree(db, p->zErrMsg);
64025 p->zErrMsg = u.cf.pVTab->pVtab->zErrMsg;
64026 u.cf.pVTab->pVtab->zErrMsg = 0;
64027 }
64028 break;
64029 }
64030 #endif /* SQLITE_OMIT_VIRTUALTABLE */
64031
64032 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -64074,13 +64322,11 @@
64074 u.cg.pVtabCursor = 0;
64075 u.cg.pVtab = pOp->p4.pVtab->pVtab;
64076 u.cg.pModule = (sqlite3_module *)u.cg.pVtab->pModule;
64077 assert(u.cg.pVtab && u.cg.pModule);
64078 rc = u.cg.pModule->xOpen(u.cg.pVtab, &u.cg.pVtabCursor);
64079 sqlite3DbFree(db, p->zErrMsg);
64080 p->zErrMsg = u.cg.pVtab->zErrMsg;
64081 u.cg.pVtab->zErrMsg = 0;
64082 if( SQLITE_OK==rc ){
64083 /* Initialize sqlite3_vtab_cursor base class */
64084 u.cg.pVtabCursor->pVtab = u.cg.pVtab;
64085
64086 /* Initialise vdbe cursor object */
@@ -64155,13 +64401,11 @@
64155 }
64156
64157 p->inVtabMethod = 1;
64158 rc = u.ch.pModule->xFilter(u.ch.pVtabCursor, u.ch.iQuery, pOp->p4.z, u.ch.nArg, u.ch.apArg);
64159 p->inVtabMethod = 0;
64160 sqlite3DbFree(db, p->zErrMsg);
64161 p->zErrMsg = u.ch.pVtab->zErrMsg;
64162 u.ch.pVtab->zErrMsg = 0;
64163 if( rc==SQLITE_OK ){
64164 u.ch.res = u.ch.pModule->xEof(u.ch.pVtabCursor);
64165 }
64166
64167 if( u.ch.res ){
@@ -64209,13 +64453,11 @@
64209 */
64210 sqlite3VdbeMemMove(&u.ci.sContext.s, u.ci.pDest);
64211 MemSetTypeFlag(&u.ci.sContext.s, MEM_Null);
64212
64213 rc = u.ci.pModule->xColumn(pCur->pVtabCursor, &u.ci.sContext, pOp->p2);
64214 sqlite3DbFree(db, p->zErrMsg);
64215 p->zErrMsg = u.ci.pVtab->zErrMsg;
64216 u.ci.pVtab->zErrMsg = 0;
64217 if( u.ci.sContext.isError ){
64218 rc = u.ci.sContext.isError;
64219 }
64220
64221 /* Copy the result of the function to the P3 register. We
@@ -64266,13 +64508,11 @@
64266 ** some other method is next invoked on the save virtual table cursor.
64267 */
64268 p->inVtabMethod = 1;
64269 rc = u.cj.pModule->xNext(u.cj.pCur->pVtabCursor);
64270 p->inVtabMethod = 0;
64271 sqlite3DbFree(db, p->zErrMsg);
64272 p->zErrMsg = u.cj.pVtab->zErrMsg;
64273 u.cj.pVtab->zErrMsg = 0;
64274 if( rc==SQLITE_OK ){
64275 u.cj.res = u.cj.pModule->xEof(u.cj.pCur->pVtabCursor);
64276 }
64277
64278 if( !u.cj.res ){
@@ -64300,13 +64540,11 @@
64300 u.ck.pName = &aMem[pOp->p1];
64301 assert( u.ck.pVtab->pModule->xRename );
64302 REGISTER_TRACE(pOp->p1, u.ck.pName);
64303 assert( u.ck.pName->flags & MEM_Str );
64304 rc = u.ck.pVtab->pModule->xRename(u.ck.pVtab, u.ck.pName->z);
64305 sqlite3DbFree(db, p->zErrMsg);
64306 p->zErrMsg = u.ck.pVtab->zErrMsg;
64307 u.ck.pVtab->zErrMsg = 0;
64308
64309 break;
64310 }
64311 #endif
64312
@@ -64356,13 +64594,11 @@
64356 sqlite3VdbeMemStoreType(u.cl.pX);
64357 u.cl.apArg[u.cl.i] = u.cl.pX;
64358 u.cl.pX++;
64359 }
64360 rc = u.cl.pModule->xUpdate(u.cl.pVtab, u.cl.nArg, u.cl.apArg, &u.cl.rowid);
64361 sqlite3DbFree(db, p->zErrMsg);
64362 p->zErrMsg = u.cl.pVtab->zErrMsg;
64363 u.cl.pVtab->zErrMsg = 0;
64364 if( rc==SQLITE_OK && pOp->p1 ){
64365 assert( u.cl.nArg>1 && u.cl.apArg[0] && (u.cl.apArg[0]->flags&MEM_Null) );
64366 db->lastRowid = u.cl.rowid;
64367 }
64368 p->nChange++;
@@ -66811,30 +67047,37 @@
66811 assert( pExpr->pTab && j<pExpr->pTab->nCol );
66812 return pExpr->pTab->aCol[j].affinity;
66813 }
66814 return pExpr->affinity;
66815 }
 
 
 
 
 
 
 
 
 
 
 
 
66816
66817 /*
66818 ** Set the collating sequence for expression pExpr to be the collating
66819 ** sequence named by pToken. Return a pointer to the revised expression.
66820 ** The collating sequence is marked as "explicit" using the EP_ExpCollate
66821 ** flag. An explicit collating sequence will override implicit
66822 ** collating sequences.
66823 */
66824 SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Parse *pParse, Expr *pExpr, Token *pCollName){
66825 char *zColl = 0; /* Dequoted name of collation sequence */
66826 CollSeq *pColl;
66827 sqlite3 *db = pParse->db;
66828 zColl = sqlite3NameFromToken(db, pCollName);
66829 if( pExpr && zColl ){
66830 pColl = sqlite3LocateCollSeq(pParse, zColl);
66831 if( pColl ){
66832 pExpr->pColl = pColl;
66833 pExpr->flags |= EP_ExpCollate;
66834 }
66835 }
66836 sqlite3DbFree(db, zColl);
66837 return pExpr;
66838 }
66839
66840 /*
@@ -68262,18 +68505,24 @@
68262
68263 if( eType==0 ){
68264 /* Could not found an existing table or index to use as the RHS b-tree.
68265 ** We will have to generate an ephemeral table to do the job.
68266 */
 
68267 int rMayHaveNull = 0;
68268 eType = IN_INDEX_EPH;
68269 if( prNotFound ){
68270 *prNotFound = rMayHaveNull = ++pParse->nMem;
68271 }else if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
68272 eType = IN_INDEX_ROWID;
 
 
 
 
68273 }
68274 sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
 
68275 }else{
68276 pX->iTable = iTab;
68277 }
68278 return eType;
68279 }
@@ -71302,11 +71551,10 @@
71302 */
71303 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
71304 if( !pNew ) goto exit_begin_add_column;
71305 pParse->pNewTable = pNew;
71306 pNew->nRef = 1;
71307 pNew->dbMem = pTab->dbMem;
71308 pNew->nCol = pTab->nCol;
71309 assert( pNew->nCol>0 );
71310 nAlloc = (((pNew->nCol-1)/8)*8)+8;
71311 assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
71312 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
@@ -71831,23 +72079,21 @@
71831
71832 /*
71833 ** If the Index.aSample variable is not NULL, delete the aSample[] array
71834 ** and its contents.
71835 */
71836 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(Index *pIdx){
71837 #ifdef SQLITE_ENABLE_STAT2
71838 if( pIdx->aSample ){
71839 int j;
71840 sqlite3 *dbMem = pIdx->pTable->dbMem;
71841 for(j=0; j<SQLITE_INDEX_SAMPLES; j++){
71842 IndexSample *p = &pIdx->aSample[j];
71843 if( p->eType==SQLITE_TEXT || p->eType==SQLITE_BLOB ){
71844 sqlite3DbFree(pIdx->pTable->dbMem, p->u.z);
71845 }
71846 }
71847 sqlite3DbFree(dbMem, pIdx->aSample);
71848 pIdx->aSample = 0;
71849 }
71850 #else
71851 UNUSED_PARAMETER(pIdx);
71852 #endif
71853 }
@@ -71884,11 +72130,12 @@
71884
71885 /* Clear any prior statistics */
71886 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
71887 Index *pIdx = sqliteHashData(i);
71888 sqlite3DefaultRowEst(pIdx);
71889 sqlite3DeleteIndexSamples(pIdx);
 
71890 }
71891
71892 /* Check to make sure the sqlite_stat1 table exists */
71893 sInfo.db = db;
71894 sInfo.zDatabase = db->aDb[iDb].zName;
@@ -71928,22 +72175,21 @@
71928 while( sqlite3_step(pStmt)==SQLITE_ROW ){
71929 char *zIndex = (char *)sqlite3_column_text(pStmt, 0);
71930 Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
71931 if( pIdx ){
71932 int iSample = sqlite3_column_int(pStmt, 1);
71933 sqlite3 *dbMem = pIdx->pTable->dbMem;
71934 assert( dbMem==db || dbMem==0 );
71935 if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
71936 int eType = sqlite3_column_type(pStmt, 2);
71937
71938 if( pIdx->aSample==0 ){
71939 static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
71940 pIdx->aSample = (IndexSample *)sqlite3DbMallocZero(dbMem, sz);
71941 if( pIdx->aSample==0 ){
71942 db->mallocFailed = 1;
71943 break;
71944 }
 
71945 }
71946
71947 assert( pIdx->aSample );
71948 {
71949 IndexSample *pSample = &pIdx->aSample[iSample];
@@ -71962,14 +72208,12 @@
71962 }
71963 pSample->nByte = (u8)n;
71964 if( n < 1){
71965 pSample->u.z = 0;
71966 }else{
71967 pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
71968 if( pSample->u.z ){
71969 memcpy(pSample->u.z, z, n);
71970 }else{
71971 db->mallocFailed = 1;
71972 break;
71973 }
71974 }
71975 }
@@ -73128,37 +73372,18 @@
73128 }
73129
73130 /*
73131 ** Reclaim the memory used by an index
73132 */
73133 static void freeIndex(Index *p){
73134 sqlite3 *db = p->pTable->dbMem;
73135 #ifndef SQLITE_OMIT_ANALYZE
73136 sqlite3DeleteIndexSamples(p);
73137 #endif
73138 sqlite3DbFree(db, p->zColAff);
73139 sqlite3DbFree(db, p);
73140 }
73141
73142 /*
73143 ** Remove the given index from the index hash table, and free
73144 ** its memory structures.
73145 **
73146 ** The index is removed from the database hash tables but
73147 ** it is not unlinked from the Table that it indexes.
73148 ** Unlinking from the Table must be done by the calling function.
73149 */
73150 static void sqlite3DeleteIndex(Index *p){
73151 Index *pOld;
73152 const char *zName = p->zName;
73153
73154 pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName,
73155 sqlite3Strlen30(zName), 0);
73156 assert( pOld==0 || pOld==p );
73157 freeIndex(p);
73158 }
73159
73160 /*
73161 ** For the index called zIdxName which is found in the database iDb,
73162 ** unlike that index from its Table then remove the index from
73163 ** the index hash table and free all memory structures associated
73164 ** with the index.
@@ -73181,11 +73406,11 @@
73181 while( ALWAYS(p) && p->pNext!=pIndex ){ p = p->pNext; }
73182 if( ALWAYS(p && p->pNext==pIndex) ){
73183 p->pNext = pIndex->pNext;
73184 }
73185 }
73186 freeIndex(pIndex);
73187 }
73188 db->flags |= SQLITE_InternChanges;
73189 }
73190
73191 /*
@@ -73252,17 +73477,16 @@
73252 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
73253 db->flags &= ~SQLITE_InternChanges;
73254 }
73255
73256 /*
73257 ** Clear the column names from a table or view.
 
73258 */
73259 static void sqliteResetColumnNames(Table *pTable){
73260 int i;
73261 Column *pCol;
73262 sqlite3 *db = pTable->dbMem;
73263 testcase( db==0 );
73264 assert( pTable!=0 );
73265 if( (pCol = pTable->aCol)!=0 ){
73266 for(i=0; i<pTable->nCol; i++, pCol++){
73267 sqlite3DbFree(db, pCol->zName);
73268 sqlite3ExprDelete(db, pCol->pDflt);
@@ -73270,12 +73494,10 @@
73270 sqlite3DbFree(db, pCol->zType);
73271 sqlite3DbFree(db, pCol->zColl);
73272 }
73273 sqlite3DbFree(db, pTable->aCol);
73274 }
73275 pTable->aCol = 0;
73276 pTable->nCol = 0;
73277 }
73278
73279 /*
73280 ** Remove the memory data structures associated with the given
73281 ** Table. No changes are made to disk by this routine.
@@ -73283,46 +73505,48 @@
73283 ** This routine just deletes the data structure. It does not unlink
73284 ** the table data structure from the hash table. But it does destroy
73285 ** memory structures of the indices and foreign keys associated with
73286 ** the table.
73287 */
73288 SQLITE_PRIVATE void sqlite3DeleteTable(Table *pTable){
73289 Index *pIndex, *pNext;
73290 sqlite3 *db;
73291
73292 if( pTable==0 ) return;
73293 db = pTable->dbMem;
73294 testcase( db==0 );
73295
73296 /* Do not delete the table until the reference count reaches zero. */
73297 pTable->nRef--;
73298 if( pTable->nRef>0 ){
73299 return;
73300 }
73301 assert( pTable->nRef==0 );
73302
73303 /* Delete all indices associated with this table
73304 */
73305 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
73306 pNext = pIndex->pNext;
73307 assert( pIndex->pSchema==pTable->pSchema );
73308 sqlite3DeleteIndex(pIndex);
 
 
 
 
 
 
 
73309 }
73310
73311 /* Delete any foreign keys attached to this table. */
73312 sqlite3FkDelete(pTable);
73313
73314 /* Delete the Table structure itself.
73315 */
73316 sqliteResetColumnNames(pTable);
73317 sqlite3DbFree(db, pTable->zName);
73318 sqlite3DbFree(db, pTable->zColAff);
73319 sqlite3SelectDelete(db, pTable->pSelect);
73320 #ifndef SQLITE_OMIT_CHECK
73321 sqlite3ExprDelete(db, pTable->pCheck);
73322 #endif
73323 sqlite3VtabClear(pTable);
 
 
73324 sqlite3DbFree(db, pTable);
73325 }
73326
73327 /*
73328 ** Unlink the given table from the hash tables and the delete the
@@ -73337,11 +73561,11 @@
73337 assert( zTabName );
73338 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
73339 pDb = &db->aDb[iDb];
73340 p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
73341 sqlite3Strlen30(zTabName),0);
73342 sqlite3DeleteTable(p);
73343 db->flags |= SQLITE_InternChanges;
73344 }
73345
73346 /*
73347 ** Given a token, return a string that consists of the text of that
@@ -73605,11 +73829,10 @@
73605 }
73606 pTable->zName = zName;
73607 pTable->iPKey = -1;
73608 pTable->pSchema = db->aDb[iDb].pSchema;
73609 pTable->nRef = 1;
73610 pTable->dbMem = 0;
73611 assert( pParse->pNewTable==0 );
73612 pParse->pNewTable = pTable;
73613
73614 /* If this is the magic sqlite_sequence table used by autoincrement,
73615 ** then record a pointer to this table in the main database structure
@@ -74157,11 +74380,11 @@
74157 zSep = "\n ";
74158 zSep2 = ",\n ";
74159 zEnd = "\n)";
74160 }
74161 n += 35 + 6*p->nCol;
74162 zStmt = sqlite3Malloc( n );
74163 if( zStmt==0 ){
74164 db->mallocFailed = 1;
74165 return 0;
74166 }
74167 sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
@@ -74338,11 +74561,11 @@
74338 assert( p->aCol==0 );
74339 p->nCol = pSelTab->nCol;
74340 p->aCol = pSelTab->aCol;
74341 pSelTab->nCol = 0;
74342 pSelTab->aCol = 0;
74343 sqlite3DeleteTable(pSelTab);
74344 }
74345 }
74346
74347 /* Compute the complete text of the CREATE statement */
74348 if( pSelect ){
@@ -74582,11 +74805,11 @@
74582 assert( pTable->aCol==0 );
74583 pTable->nCol = pSelTab->nCol;
74584 pTable->aCol = pSelTab->aCol;
74585 pSelTab->nCol = 0;
74586 pSelTab->aCol = 0;
74587 sqlite3DeleteTable(pSelTab);
74588 pTable->pSchema->flags |= DB_UnresetViews;
74589 }else{
74590 pTable->nCol = 0;
74591 nErr++;
74592 }
@@ -74607,11 +74830,13 @@
74607 HashElem *i;
74608 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
74609 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
74610 Table *pTab = sqliteHashData(i);
74611 if( pTab->pSelect ){
74612 sqliteResetColumnNames(pTab);
 
 
74613 }
74614 }
74615 DbClearProperty(db, idx, DB_UnresetViews);
74616 }
74617 #else
@@ -75604,11 +75829,11 @@
75604 }
75605
75606 /* Clean up before exiting */
75607 exit_create_index:
75608 if( pIndex ){
75609 sqlite3_free(pIndex->zColAff);
75610 sqlite3DbFree(db, pIndex);
75611 }
75612 sqlite3ExprListDelete(db, pList);
75613 sqlite3SrcListDelete(db, pTblName);
75614 sqlite3DbFree(db, zName);
@@ -75983,11 +76208,11 @@
75983 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
75984 sqlite3DbFree(db, pItem->zDatabase);
75985 sqlite3DbFree(db, pItem->zName);
75986 sqlite3DbFree(db, pItem->zAlias);
75987 sqlite3DbFree(db, pItem->zIndex);
75988 sqlite3DeleteTable(pItem->pTab);
75989 sqlite3SelectDelete(db, pItem->pSelect);
75990 sqlite3ExprDelete(db, pItem->pOn);
75991 sqlite3IdListDelete(db, pItem->pUsing);
75992 }
75993 sqlite3DbFree(db, pList);
@@ -76914,12 +77139,11 @@
76914 }
76915 sqlite3HashClear(&temp2);
76916 sqlite3HashInit(&pSchema->tblHash);
76917 for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
76918 Table *pTab = sqliteHashData(pElem);
76919 assert( pTab->dbMem==0 );
76920 sqlite3DeleteTable(pTab);
76921 }
76922 sqlite3HashClear(&temp1);
76923 sqlite3HashClear(&pSchema->fkeyHash);
76924 pSchema->pSeqTab = 0;
76925 pSchema->flags &= ~DB_SchemaLoaded;
@@ -76932,11 +77156,11 @@
76932 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
76933 Schema * p;
76934 if( pBt ){
76935 p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree);
76936 }else{
76937 p = (Schema *)sqlite3MallocZero(sizeof(Schema));
76938 }
76939 if( !p ){
76940 db->mallocFailed = 1;
76941 }else if ( 0==p->file_format ){
76942 sqlite3HashInit(&p->tblHash);
@@ -76973,11 +77197,11 @@
76973 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
76974 struct SrcList_item *pItem = pSrc->a;
76975 Table *pTab;
76976 assert( pItem && pSrc->nSrc==1 );
76977 pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase);
76978 sqlite3DeleteTable(pItem->pTab);
76979 pItem->pTab = pTab;
76980 if( pTab ){
76981 pTab->nRef++;
76982 }
76983 if( sqlite3IndexedByLookup(pParse, pItem) ){
@@ -78370,12 +78594,14 @@
78370 sqlite3_value **argv
78371 ){
78372 const char *zOptName;
78373 assert( argc==1 );
78374 UNUSED_PARAMETER(argc);
78375 /* IMP: R-xxxx This function is an SQL wrapper around the
78376 ** sqlite3_compileoption_used() C interface. */
 
 
78377 if( (zOptName = (const char*)sqlite3_value_text(argv[0]))!=0 ){
78378 sqlite3_result_int(context, sqlite3_compileoption_used(zOptName));
78379 }
78380 }
78381 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
@@ -78392,12 +78618,13 @@
78392 sqlite3_value **argv
78393 ){
78394 int n;
78395 assert( argc==1 );
78396 UNUSED_PARAMETER(argc);
78397 /* IMP: R-xxxx This function is an SQL wrapper around the
78398 ** sqlite3_compileoption_get() C interface. */
 
78399 n = sqlite3_value_int(argv[0]);
78400 sqlite3_result_text(context, sqlite3_compileoption_get(n), -1, SQLITE_STATIC);
78401 }
78402 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
78403
@@ -78592,18 +78819,18 @@
78592 nOut += nRep - nPattern;
78593 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
78594 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
78595 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
78596 sqlite3_result_error_toobig(context);
78597 sqlite3DbFree(db, zOut);
78598 return;
78599 }
78600 zOld = zOut;
78601 zOut = sqlite3_realloc(zOut, (int)nOut);
78602 if( zOut==0 ){
78603 sqlite3_result_error_nomem(context);
78604 sqlite3DbFree(db, zOld);
78605 return;
78606 }
78607 memcpy(&zOut[j], zRep, nRep);
78608 j += nRep;
78609 i += nPattern-1;
@@ -78960,11 +79187,11 @@
78960 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
78961
78962 if( pAccum ){
78963 sqlite3 *db = sqlite3_context_db_handle(context);
78964 int firstTerm = pAccum->useMalloc==0;
78965 pAccum->useMalloc = 1;
78966 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
78967 if( !firstTerm ){
78968 if( argc==2 ){
78969 zSep = (char*)sqlite3_value_text(argv[1]);
78970 nSep = sqlite3_value_bytes(argv[1]);
@@ -79677,11 +79904,12 @@
79677 /* Set the collation sequence and affinity of the LHS of each TK_EQ
79678 ** expression to the parent key column defaults. */
79679 if( pIdx ){
79680 Column *pCol;
79681 iCol = pIdx->aiColumn[i];
79682 pCol = &pIdx->pTable->aCol[iCol];
 
79683 pLeft->iTable = regData+iCol+1;
79684 pLeft->affinity = pCol->affinity;
79685 pLeft->pColl = sqlite3LocateCollSeq(pParse, pCol->zColl);
79686 }else{
79687 pLeft->iTable = regData;
@@ -80238,15 +80466,11 @@
80238 0, 0, 0, 0, 0, 0
80239 );
80240 pWhere = 0;
80241 }
80242
80243 /* In the current implementation, pTab->dbMem==0 for all tables except
80244 ** for temporary tables used to describe subqueries. And temporary
80245 ** tables do not have foreign key constraints. Hence, pTab->dbMem
80246 ** should always be 0 there.
80247 */
80248 enableLookaside = db->lookaside.bEnabled;
80249 db->lookaside.bEnabled = 0;
80250
80251 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
80252 sizeof(Trigger) + /* struct Trigger */
@@ -80332,41 +80556,43 @@
80332 /*
80333 ** Free all memory associated with foreign key definitions attached to
80334 ** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
80335 ** hash table.
80336 */
80337 SQLITE_PRIVATE void sqlite3FkDelete(Table *pTab){
80338 FKey *pFKey; /* Iterator variable */
80339 FKey *pNext; /* Copy of pFKey->pNextFrom */
80340
80341 for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
80342
80343 /* Remove the FK from the fkeyHash hash table. */
80344 if( pFKey->pPrevTo ){
80345 pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
80346 }else{
80347 void *data = (void *)pFKey->pNextTo;
80348 const char *z = (data ? pFKey->pNextTo->zTo : pFKey->zTo);
80349 sqlite3HashInsert(&pTab->pSchema->fkeyHash, z, sqlite3Strlen30(z), data);
80350 }
80351 if( pFKey->pNextTo ){
80352 pFKey->pNextTo->pPrevTo = pFKey->pPrevTo;
80353 }
80354
80355 /* Delete any triggers created to implement actions for this FK. */
80356 #ifndef SQLITE_OMIT_TRIGGER
80357 fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[0]);
80358 fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[1]);
80359 #endif
80360
80361 /* EV: R-30323-21917 Each foreign key constraint in SQLite is
80362 ** classified as either immediate or deferred.
80363 */
80364 assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 );
 
 
 
 
 
 
80365
80366 pNext = pFKey->pNextFrom;
80367 sqlite3DbFree(pTab->dbMem, pFKey);
80368 }
80369 }
80370 #endif /* ifndef SQLITE_OMIT_FOREIGN_KEY */
80371
80372 /************** End of fkey.c ************************************************/
@@ -80437,11 +80663,11 @@
80437 ** up.
80438 */
80439 int n;
80440 Table *pTab = pIdx->pTable;
80441 sqlite3 *db = sqlite3VdbeDb(v);
80442 pIdx->zColAff = (char *)sqlite3Malloc(pIdx->nColumn+2);
80443 if( !pIdx->zColAff ){
80444 db->mallocFailed = 1;
80445 return 0;
80446 }
80447 for(n=0; n<pIdx->nColumn; n++){
@@ -80479,11 +80705,11 @@
80479 if( !pTab->zColAff ){
80480 char *zColAff;
80481 int i;
80482 sqlite3 *db = sqlite3VdbeDb(v);
80483
80484 zColAff = (char *)sqlite3Malloc(pTab->nCol+1);
80485 if( !zColAff ){
80486 db->mallocFailed = 1;
80487 return;
80488 }
80489
@@ -81590,10 +81816,11 @@
81590 sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, SQLITE_JUMPIFNULL);
81591 onError = overrideError!=OE_Default ? overrideError : OE_Abort;
81592 if( onError==OE_Ignore ){
81593 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
81594 }else{
 
81595 sqlite3HaltConstraint(pParse, onError, 0, 0);
81596 }
81597 sqlite3VdbeResolveLabel(v, allOk);
81598 }
81599 #endif /* !defined(SQLITE_OMIT_CHECK) */
@@ -83104,32 +83331,28 @@
83104 }
83105
83106 handle = sqlite3OsDlOpen(pVfs, zFile);
83107 if( handle==0 ){
83108 if( pzErrMsg ){
83109 zErrmsg = sqlite3StackAllocZero(db, nMsg);
83110 if( zErrmsg ){
83111 sqlite3_snprintf(nMsg, zErrmsg,
83112 "unable to open shared library [%s]", zFile);
83113 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
83114 *pzErrMsg = sqlite3DbStrDup(0, zErrmsg);
83115 sqlite3StackFree(db, zErrmsg);
83116 }
83117 }
83118 return SQLITE_ERROR;
83119 }
83120 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
83121 sqlite3OsDlSym(pVfs, handle, zProc);
83122 if( xInit==0 ){
83123 if( pzErrMsg ){
83124 zErrmsg = sqlite3StackAllocZero(db, nMsg);
83125 if( zErrmsg ){
83126 sqlite3_snprintf(nMsg, zErrmsg,
83127 "no entry point [%s] in shared library [%s]", zProc,zFile);
83128 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
83129 *pzErrMsg = sqlite3DbStrDup(0, zErrmsg);
83130 sqlite3StackFree(db, zErrmsg);
83131 }
83132 sqlite3OsDlClose(pVfs, handle);
83133 }
83134 return SQLITE_ERROR;
83135 }else if( xInit(db, &zErrmsg, &sqlite3Apis) ){
@@ -84104,11 +84327,11 @@
84104 ){
84105 invalidateTempStorage(pParse);
84106 }
84107 sqlite3_free(sqlite3_temp_directory);
84108 if( zRight[0] ){
84109 sqlite3_temp_directory = sqlite3DbStrDup(0, zRight);
84110 }else{
84111 sqlite3_temp_directory = 0;
84112 }
84113 #endif /* SQLITE_OMIT_WSD */
84114 }
@@ -85525,11 +85748,10 @@
85525
85526 /* Delete any TriggerPrg structures allocated while parsing this statement. */
85527 while( pParse->pTriggerPrg ){
85528 TriggerPrg *pT = pParse->pTriggerPrg;
85529 pParse->pTriggerPrg = pT->pNext;
85530 sqlite3VdbeProgramDelete(db, pT->pProgram, 0);
85531 sqlite3DbFree(db, pT);
85532 }
85533
85534 end_prepare:
85535
@@ -87016,20 +87238,19 @@
87016 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
87017 if( pTab==0 ){
87018 return 0;
87019 }
87020 /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
87021 ** is disabled, so we might as well hard-code pTab->dbMem to NULL. */
87022 assert( db->lookaside.bEnabled==0 );
87023 pTab->dbMem = 0;
87024 pTab->nRef = 1;
87025 pTab->zName = 0;
87026 selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
87027 selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect);
87028 pTab->iPKey = -1;
87029 if( db->mallocFailed ){
87030 sqlite3DeleteTable(pTab);
87031 return 0;
87032 }
87033 return pTab;
87034 }
87035
@@ -88814,11 +89035,10 @@
88814 assert( pSel!=0 );
88815 assert( pFrom->pTab==0 );
88816 sqlite3WalkSelect(pWalker, pSel);
88817 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
88818 if( pTab==0 ) return WRC_Abort;
88819 pTab->dbMem = db->lookaside.bEnabled ? db : 0;
88820 pTab->nRef = 1;
88821 pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
88822 while( pSel->pPrior ){ pSel = pSel->pPrior; }
88823 selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
88824 pTab->iPKey = -1;
@@ -91028,10 +91248,11 @@
91028 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
91029 Parse *pSubParse; /* Parse context for sub-vdbe */
91030 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
91031
91032 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
 
91033
91034 /* Allocate the TriggerPrg and SubProgram objects. To ensure that they
91035 ** are freed if an error occurs, link them into the Parse.pTriggerPrg
91036 ** list of the top-level Parse object sooner rather than later. */
91037 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
@@ -91038,11 +91259,11 @@
91038 if( !pPrg ) return 0;
91039 pPrg->pNext = pTop->pTriggerPrg;
91040 pTop->pTriggerPrg = pPrg;
91041 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
91042 if( !pProgram ) return 0;
91043 pProgram->nRef = 1;
91044 pPrg->pTrigger = pTrigger;
91045 pPrg->orconf = orconf;
91046 pPrg->aColmask[0] = 0xffffffff;
91047 pPrg->aColmask[1] = 0xffffffff;
91048
@@ -91172,22 +91393,23 @@
91172 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
91173
91174 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
91175 ** is a pointer to the sub-vdbe containing the trigger program. */
91176 if( pPrg ){
 
 
91177 sqlite3VdbeAddOp3(v, OP_Program, reg, ignoreJump, ++pParse->nMem);
91178 pPrg->pProgram->nRef++;
91179 sqlite3VdbeChangeP4(v, -1, (const char *)pPrg->pProgram, P4_SUBPROGRAM);
91180 VdbeComment(
91181 (v, "Call: %s.%s", (p->zName?p->zName:"fkey"), onErrorText(orconf)));
91182
91183 /* Set the P5 operand of the OP_Program instruction to non-zero if
91184 ** recursive invocation of this trigger program is disallowed. Recursive
91185 ** invocation is disallowed if (a) the sub-program is really a trigger,
91186 ** not a foreign key action, and (b) the flag to enable recursive triggers
91187 ** is clear. */
91188 sqlite3VdbeChangeP5(v, (u8)(p->zName && !(pParse->db->flags&SQLITE_RecTriggers)));
91189 }
91190 }
91191
91192 /*
91193 ** This is called to code the required FOR EACH ROW triggers for an operation
@@ -91332,11 +91554,11 @@
91332 **
91333 ** May you do good and not evil.
91334 ** May you find forgiveness for yourself and forgive others.
91335 ** May you share freely, never taking more than you give.
91336 **
91337 sqlite*************************************************************************
91338 ** This file contains C code routines that are called by the parser
91339 ** to handle UPDATE statements.
91340 */
91341
91342 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -92551,18 +92773,18 @@
92551 ** connection db is decremented immediately (which may lead to the
92552 ** structure being xDisconnected and free). Any other VTable structures
92553 ** in the list are moved to the sqlite3.pDisconnect list of the associated
92554 ** database connection.
92555 */
92556 SQLITE_PRIVATE void sqlite3VtabClear(Table *p){
92557 vtabDisconnectAll(0, p);
92558 if( p->azModuleArg ){
92559 int i;
92560 for(i=0; i<p->nModuleArg; i++){
92561 sqlite3DbFree(p->dbMem, p->azModuleArg[i]);
92562 }
92563 sqlite3DbFree(p->dbMem, p->azModuleArg);
92564 }
92565 }
92566
92567 /*
92568 ** Add a new module argument to pTable->azModuleArg[].
@@ -92723,11 +92945,10 @@
92723 if( pOld ){
92724 db->mallocFailed = 1;
92725 assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
92726 return;
92727 }
92728 pSchema->db = pParse->db;
92729 pParse->pNewTable = 0;
92730 }
92731 }
92732
92733 /*
@@ -92797,11 +93018,11 @@
92797 if( SQLITE_OK!=rc ){
92798 if( zErr==0 ){
92799 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
92800 }else {
92801 *pzErr = sqlite3MPrintf(db, "%s", zErr);
92802 sqlite3DbFree(db, zErr);
92803 }
92804 sqlite3DbFree(db, pVTable);
92805 }else if( ALWAYS(pVTable->pVtab) ){
92806 /* Justification of ALWAYS(): A correct vtab constructor must allocate
92807 ** the sqlite3_vtab object if successful. */
@@ -93004,19 +93225,19 @@
93004 pParse->pNewTable->aCol = 0;
93005 }
93006 db->pVTab = 0;
93007 }else{
93008 sqlite3Error(db, SQLITE_ERROR, zErr);
93009 sqlite3DbFree(db, zErr);
93010 rc = SQLITE_ERROR;
93011 }
93012 pParse->declareVtab = 0;
93013
93014 if( pParse->pVdbe ){
93015 sqlite3VdbeFinalize(pParse->pVdbe);
93016 }
93017 sqlite3DeleteTable(pParse->pNewTable);
93018 sqlite3StackFree(db, pParse);
93019 }
93020
93021 assert( (rc&0xff)==rc );
93022 rc = sqlite3ApiExit(db, rc);
@@ -93099,12 +93320,12 @@
93099 int (*x)(sqlite3_vtab *);
93100 sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
93101 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
93102 rc = x(pVtab);
93103 sqlite3DbFree(db, *pzErrmsg);
93104 *pzErrmsg = pVtab->zErrMsg;
93105 pVtab->zErrMsg = 0;
93106 }
93107 }
93108 db->aVTrans = aVTrans;
93109 return rc;
93110 }
@@ -93600,10 +93821,11 @@
93600 ** the pWC->a[] array.
93601 */
93602 static int whereClauseInsert(WhereClause *pWC, Expr *p, u8 wtFlags){
93603 WhereTerm *pTerm;
93604 int idx;
 
93605 if( pWC->nTerm>=pWC->nSlot ){
93606 WhereTerm *pOld = pWC->a;
93607 sqlite3 *db = pWC->pParse->db;
93608 pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
93609 if( pWC->a==0 ){
@@ -93745,10 +93967,17 @@
93745
93746 /*
93747 ** Return TRUE if the given operator is one of the operators that is
93748 ** allowed for an indexable WHERE clause term. The allowed operators are
93749 ** "=", "<", ">", "<=", ">=", and "IN".
 
 
 
 
 
 
 
93750 */
93751 static int allowedOp(int op){
93752 assert( TK_GT>TK_EQ && TK_GT<TK_GE );
93753 assert( TK_LT>TK_EQ && TK_LT<TK_GE );
93754 assert( TK_LE>TK_EQ && TK_LE<TK_GE );
@@ -93908,11 +94137,10 @@
93908 Expr *pRight, *pLeft; /* Right and left size of LIKE operator */
93909 ExprList *pList; /* List of operands to the LIKE operator */
93910 int c; /* One character in z[] */
93911 int cnt; /* Number of non-wildcard prefix characters */
93912 char wc[3]; /* Wildcard characters */
93913 CollSeq *pColl; /* Collating sequence for LHS */
93914 sqlite3 *db = pParse->db; /* Database connection */
93915 sqlite3_value *pVal = 0;
93916 int op; /* Opcode of pRight */
93917
93918 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
@@ -93927,23 +94155,10 @@
93927 /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
93928 ** be the name of an indexed column with TEXT affinity. */
93929 return 0;
93930 }
93931 assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
93932 pColl = sqlite3ExprCollSeq(pParse, pLeft);
93933 if( pColl==0 ) return 0; /* Happens when LHS has an undefined collation */
93934 if( (pColl->type!=SQLITE_COLL_BINARY || *pnoCase) &&
93935 (pColl->type!=SQLITE_COLL_NOCASE || !*pnoCase) ){
93936 /* IMP: R-09003-32046 For the GLOB operator, the column must use the
93937 ** default BINARY collating sequence.
93938 ** IMP: R-41408-28306 For the LIKE operator, if case_sensitive_like mode
93939 ** is enabled then the column must use the default BINARY collating
93940 ** sequence, or if case_sensitive_like mode is disabled then the column
93941 ** must use the built-in NOCASE collating sequence.
93942 */
93943 return 0;
93944 }
93945
93946 pRight = pList->a[0].pExpr;
93947 op = pRight->op;
93948 if( op==TK_REGISTER ){
93949 op = pRight->op2;
@@ -93962,13 +94177,13 @@
93962 if( z ){
93963 cnt = 0;
93964 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
93965 cnt++;
93966 }
93967 if( cnt!=0 && c!=0 && 255!=(u8)z[cnt-1] ){
93968 Expr *pPrefix;
93969 *pisComplete = z[cnt]==wc[0] && z[cnt+1]==0;
93970 pPrefix = sqlite3Expr(db, TK_STRING, z);
93971 if( pPrefix ) pPrefix->u.zToken[cnt] = 0;
93972 *ppPrefix = pPrefix;
93973 if( op==TK_VARIABLE ){
93974 Vdbe *v = pParse->pVdbe;
@@ -94303,10 +94518,12 @@
94303 }
94304
94305 /* At this point, okToChngToIN is true if original pTerm satisfies
94306 ** case 1. In that case, construct a new virtual term that is
94307 ** pTerm converted into an IN operator.
 
 
94308 */
94309 if( okToChngToIN ){
94310 Expr *pDup; /* A transient duplicate expression */
94311 ExprList *pList = 0; /* The RHS of the IN operator */
94312 Expr *pLeft = 0; /* The LHS of the IN operator */
@@ -94519,10 +94736,11 @@
94519 Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */
94520 Expr *pNewExpr1;
94521 Expr *pNewExpr2;
94522 int idxNew1;
94523 int idxNew2;
 
94524
94525 pLeft = pExpr->x.pList->a[1].pExpr;
94526 pStr2 = sqlite3ExprDup(db, pStr1, 0);
94527 if( !db->mallocFailed ){
94528 u8 c, *pC; /* Last character before the first wildcard */
@@ -94533,21 +94751,27 @@
94533 ** wildcard. But if we increment '@', that will push it into the
94534 ** alphabetic range where case conversions will mess up the
94535 ** inequality. To avoid this, make sure to also run the full
94536 ** LIKE on all candidate expressions by clearing the isComplete flag
94537 */
94538 if( c=='A'-1 ) isComplete = 0;
 
94539
94540 c = sqlite3UpperToLower[c];
94541 }
94542 *pC = c + 1;
94543 }
94544 pNewExpr1 = sqlite3PExpr(pParse, TK_GE, sqlite3ExprDup(db,pLeft,0),pStr1,0);
 
 
 
94545 idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC);
94546 testcase( idxNew1==0 );
94547 exprAnalyze(pSrc, pWC, idxNew1);
94548 pNewExpr2 = sqlite3PExpr(pParse, TK_LT, sqlite3ExprDup(db,pLeft,0),pStr2,0);
 
 
94549 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
94550 testcase( idxNew2==0 );
94551 exprAnalyze(pSrc, pWC, idxNew2);
94552 pTerm = &pWC->a[idxTerm];
94553 if( isComplete ){
@@ -95295,11 +95519,11 @@
95295 sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
95296 }else{
95297 sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg);
95298 }
95299 }
95300 sqlite3DbFree(pParse->db, pVtab->zErrMsg);
95301 pVtab->zErrMsg = 0;
95302
95303 for(i=0; i<p->nConstraint; i++){
95304 if( !p->aConstraint[i].usable && p->aConstraintUsage[i].argvIndex>0 ){
95305 sqlite3ErrorMsg(pParse,
@@ -96159,10 +96383,13 @@
96159 ** (3) SELECT * FROM t1, t2 WHERE t1.a=t2.x AND t2.z='ok'
96160 **
96161 ** The t2.z='ok' is disabled in the in (2) because it originates
96162 ** in the ON clause. The term is disabled in (3) because it is not part
96163 ** of a LEFT OUTER JOIN. In (1), the term is not disabled.
 
 
 
96164 **
96165 ** Disabling a term causes that term to not be tested in the inner loop
96166 ** of the join. Disabling is an optimization. When terms are satisfied
96167 ** by indices, we disable them to prevent redundant tests in the inner
96168 ** loop. We would get the correct results if nothing were ever disabled,
@@ -96371,10 +96598,11 @@
96371 pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx);
96372 if( NEVER(pTerm==0) ) break;
96373 /* The following true for indices with redundant columns.
96374 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
96375 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
 
96376 r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
96377 if( r1!=regBase+j ){
96378 if( nReg==1 ){
96379 sqlite3ReleaseTempReg(pParse, regBase);
96380 regBase = r1;
@@ -96514,10 +96742,11 @@
96514 pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
96515 assert( pTerm!=0 );
96516 assert( pTerm->pExpr!=0 );
96517 assert( pTerm->leftCursor==iCur );
96518 assert( omitTable==0 );
 
96519 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, iReleaseReg);
96520 addrNxt = pLevel->addrNxt;
96521 sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
96522 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
96523 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
@@ -96554,10 +96783,11 @@
96554 };
96555 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
96556 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
96557 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
96558
 
96559 pX = pStart->pExpr;
96560 assert( pX!=0 );
96561 assert( pStart->leftCursor==iCur );
96562 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
96563 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
@@ -96571,10 +96801,11 @@
96571 if( pEnd ){
96572 Expr *pX;
96573 pX = pEnd->pExpr;
96574 assert( pX!=0 );
96575 assert( pEnd->leftCursor==iCur );
 
96576 memEndValue = ++pParse->nMem;
96577 sqlite3ExprCode(pParse, pX->pRight, memEndValue);
96578 if( pX->op==TK_LT || pX->op==TK_GT ){
96579 testOp = bRev ? OP_Le : OP_Ge;
96580 }else{
@@ -96738,10 +96969,11 @@
96738 if( sqlite3ExprNeedsNoAffinityChange(pRight, zStartAff[nEq]) ){
96739 zStartAff[nEq] = SQLITE_AFF_NONE;
96740 }
96741 }
96742 nConstraint++;
 
96743 }else if( isMinQuery ){
96744 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
96745 nConstraint++;
96746 startEq = 0;
96747 start_constraints = 1;
@@ -96777,10 +97009,11 @@
96777 zEndAff[nEq] = SQLITE_AFF_NONE;
96778 }
96779 }
96780 codeApplyAffinity(pParse, regBase, nEq+1, zEndAff);
96781 nConstraint++;
 
96782 }
96783 sqlite3DbFree(pParse->db, zStartAff);
96784 sqlite3DbFree(pParse->db, zEndAff);
96785
96786 /* Top of the loop body */
@@ -96983,15 +97216,19 @@
96983 }
96984 notReady &= ~getMask(pWC->pMaskSet, iCur);
96985
96986 /* Insert code to test every subexpression that can be completely
96987 ** computed using the current set of tables.
 
 
 
 
96988 */
96989 k = 0;
96990 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
96991 Expr *pE;
96992 testcase( pTerm->wtFlags & TERM_VIRTUAL );
96993 testcase( pTerm->wtFlags & TERM_CODED );
96994 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
96995 if( (pTerm->prereqAll & notReady)!=0 ){
96996 testcase( pWInfo->untestedTerms==0
96997 && (pWInfo->wctrlFlags & WHERE_ONETABLE_ONLY)!=0 );
@@ -97015,11 +97252,11 @@
97015 pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
97016 sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
97017 VdbeComment((v, "record LEFT JOIN hit"));
97018 sqlite3ExprCacheClear(pParse);
97019 for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
97020 testcase( pTerm->wtFlags & TERM_VIRTUAL );
97021 testcase( pTerm->wtFlags & TERM_CODED );
97022 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
97023 if( (pTerm->prereqAll & notReady)!=0 ){
97024 assert( pWInfo->untestedTerms );
97025 continue;
@@ -97233,11 +97470,11 @@
97233 ** subexpression is separated by an AND operator.
97234 */
97235 initMaskSet(pMaskSet);
97236 whereClauseInit(pWC, pParse, pMaskSet);
97237 sqlite3ExprCodeConstants(pParse, pWhere);
97238 whereSplit(pWC, pWhere, TK_AND);
97239
97240 /* Special case: a WHERE clause that is constant. Evaluate the
97241 ** expression and either jump over all of the code or fall thru.
97242 */
97243 if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
@@ -97321,10 +97558,12 @@
97321 Index *pIdx; /* Index for FROM table at pTabItem */
97322 int j; /* For looping over FROM tables */
97323 int bestJ = -1; /* The value of j */
97324 Bitmask m; /* Bitmask value for j or bestJ */
97325 int isOptimal; /* Iterator for optimal/non-optimal search */
 
 
97326
97327 memset(&bestPlan, 0, sizeof(bestPlan));
97328 bestPlan.rCost = SQLITE_BIG_DBL;
97329
97330 /* Loop through the remaining entries in the FROM clause to find the
@@ -97362,12 +97601,14 @@
97362 ** However, since the cost of a linear scan through table t2 is the same
97363 ** as the cost of a linear scan through table t1, a simple greedy
97364 ** algorithm may choose to use t2 for the outer loop, which is a much
97365 ** costlier approach.
97366 */
 
 
97367 for(isOptimal=(iFrom<nTabList-1); isOptimal>=0; isOptimal--){
97368 Bitmask mask; /* Mask of tables not yet ready */
97369 for(j=iFrom, pTabItem=&pTabList->a[j]; j<nTabList; j++, pTabItem++){
97370 int doNotReorder; /* True if this table should not be reordered */
97371 WhereCost sCost; /* Cost information from best[Virtual]Index() */
97372 ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
97373
@@ -97378,10 +97619,11 @@
97378 if( j==iFrom ) iFrom++;
97379 continue;
97380 }
97381 mask = (isOptimal ? m : notReady);
97382 pOrderBy = ((i==0 && ppOrderBy )?*ppOrderBy:0);
 
97383
97384 assert( pTabItem->pTab );
97385 #ifndef SQLITE_OMIT_VIRTUALTABLE
97386 if( IsVirtual(pTabItem->pTab) ){
97387 sqlite3_index_info **pp = &pWInfo->a[j].pIdxInfo;
@@ -97391,13 +97633,47 @@
97391 {
97392 bestBtreeIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost);
97393 }
97394 assert( isOptimal || (sCost.used&notReady)==0 );
97395
97396 if( (sCost.used&notReady)==0
97397 && (bestJ<0 || sCost.rCost<bestPlan.rCost
97398 || (sCost.rCost<=bestPlan.rCost && sCost.nRow<bestPlan.nRow))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97399 ){
97400 WHERETRACE(("... best so far with cost=%g and nRow=%g\n",
97401 sCost.rCost, sCost.nRow));
97402 bestPlan = sCost;
97403 bestJ = j;
@@ -100408,11 +100684,11 @@
100408 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
100409 }
100410 break;
100411 case 195: /* expr ::= expr COLLATE ids */
100412 {
100413 yygotominor.yy118.pExpr = sqlite3ExprSetColl(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
100414 yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
100415 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
100416 }
100417 break;
100418 case 196: /* expr ::= CAST LP expr AS typetoken RP */
@@ -100664,11 +100940,11 @@
100664 case 248: /* idxlist ::= idxlist COMMA nm collate sortorder */
100665 {
100666 Expr *p = 0;
100667 if( yymsp[-1].minor.yy0.n>0 ){
100668 p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
100669 sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
100670 }
100671 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, p);
100672 sqlite3ExprListSetName(pParse,yygotominor.yy322,&yymsp[-2].minor.yy0,1);
100673 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
100674 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
@@ -100677,11 +100953,11 @@
100677 case 249: /* idxlist ::= nm collate sortorder */
100678 {
100679 Expr *p = 0;
100680 if( yymsp[-1].minor.yy0.n>0 ){
100681 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
100682 sqlite3ExprSetColl(pParse, p, &yymsp[-1].minor.yy0);
100683 }
100684 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, p);
100685 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
100686 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
100687 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
@@ -101957,19 +102233,19 @@
101957 pParse->aTableLock = 0;
101958 pParse->nTableLock = 0;
101959 }
101960 #endif
101961 #ifndef SQLITE_OMIT_VIRTUALTABLE
101962 sqlite3DbFree(db, pParse->apVtabLock);
101963 #endif
101964
101965 if( !IN_DECLARE_VTAB ){
101966 /* If the pParse->declareVtab flag is set, do not delete any table
101967 ** structure built up in pParse->pNewTable. The calling code (see vtab.c)
101968 ** will take responsibility for freeing the Table structure.
101969 */
101970 sqlite3DeleteTable(pParse->pNewTable);
101971 }
101972
101973 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
101974 sqlite3DbFree(db, pParse->apVarExpr);
101975 sqlite3DbFree(db, pParse->aAlias);
@@ -101979,11 +102255,11 @@
101979 sqlite3DbFree(db, p);
101980 }
101981 while( pParse->pZombieTab ){
101982 Table *p = pParse->pZombieTab;
101983 pParse->pZombieTab = p->pNextZombie;
101984 sqlite3DeleteTable(p);
101985 }
101986 if( nErr>0 && pParse->rc==SQLITE_OK ){
101987 pParse->rc = SQLITE_ERROR;
101988 }
101989 return nErr;
@@ -103671,20 +103947,11 @@
103671
103672 assert( sqlite3_mutex_held(db->mutex) );
103673
103674 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
103675 if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){
103676 Btree *pBt = db->aDb[i].pBt;
103677 if( pBt ){
103678 if( sqlite3BtreeIsInReadTrans(pBt) ){
103679 rc = SQLITE_LOCKED;
103680 }else{
103681 sqlite3BtreeEnter(pBt);
103682 rc = sqlite3PagerCheckpoint(sqlite3BtreePager(pBt));
103683 sqlite3BtreeLeave(pBt);
103684 }
103685 }
103686 }
103687 }
103688
103689 return rc;
103690 }
@@ -105129,11 +105396,11 @@
105129
105130 sqlite3BeginBenignMalloc();
105131 assert( aArg==aDyn || (aDyn==0 && aArg==aStatic) );
105132 assert( nArg<=(int)ArraySize(aStatic) || aArg==aDyn );
105133 if( (!aDyn && nArg==(int)ArraySize(aStatic))
105134 || (aDyn && nArg==(int)(sqlite3DbMallocSize(db, aDyn)/sizeof(void*)))
105135 ){
105136 /* The aArg[] array needs to grow. */
105137 void **pNew = (void **)sqlite3Malloc(nArg*sizeof(void *)*2);
105138 if( pNew ){
105139 memcpy(pNew, aArg, nArg*sizeof(void *));
105140
--- 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.7.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.
@@ -641,13 +641,13 @@
641 **
642 ** See also: [sqlite3_libversion()],
643 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
644 ** [sqlite_version()] and [sqlite_source_id()].
645 */
646 #define SQLITE_VERSION "3.7.1"
647 #define SQLITE_VERSION_NUMBER 3007001
648 #define SQLITE_SOURCE_ID "2010-08-05 03:21:40 fbe70e1106bcc5086ceb9d8f39cc39baf3643092"
649
650 /*
651 ** CAPI3REF: Run-Time Library Version Numbers
652 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
653 **
@@ -2710,11 +2710,17 @@
2710 ** contain a UTF-8 SQL comment that identifies the trigger.)^
2711 **
2712 ** ^The callback function registered by sqlite3_profile() is invoked
2713 ** as each SQL statement finishes. ^The profile callback contains
2714 ** the original statement text and an estimate of wall-clock time
2715 ** of how long that statement took to run. ^The profile callback
2716 ** time is in units of nanoseconds, however the current implementation
2717 ** is only capable of millisecond resolution so the six least significant
2718 ** digits in the time are meaningless. Future versions of SQLite
2719 ** might provide greater resolution on the profiler callback. The
2720 ** sqlite3_profile() function is considered experimental and is
2721 ** subject to change in future versions of SQLite.
2722 */
2723 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2724 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2725 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2726
@@ -4859,22 +4865,25 @@
4865
4866 /*
4867 ** CAPI3REF: Virtual Table Indexing Information
4868 ** KEYWORDS: sqlite3_index_info
4869 **
4870 ** The sqlite3_index_info structure and its substructures is used as part
4871 ** of the [virtual table] interface to
4872 ** pass information into and receive the reply from the [xBestIndex]
4873 ** method of a [virtual table module]. The fields under **Inputs** are the
4874 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
4875 ** results into the **Outputs** fields.
4876 **
4877 ** ^(The aConstraint[] array records WHERE clause constraints of the form:
4878 **
4879 ** <blockquote>column OP expr</blockquote>
4880 **
4881 ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
4882 ** stored in aConstraint[].op using one of the
4883 ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
4884 ** ^(The index of the column is stored in
4885 ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
4886 ** expr on the right-hand side can be evaluated (and thus the constraint
4887 ** is usable) and false if it cannot.)^
4888 **
4889 ** ^The optimizer automatically inverts terms of the form "expr OP column"
@@ -4930,10 +4939,19 @@
4939 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
4940 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
4941 int orderByConsumed; /* True if output is already ordered */
4942 double estimatedCost; /* Estimated cost of using this index */
4943 };
4944
4945 /*
4946 ** CAPI3REF: Virtual Table Constraint Operator Codes
4947 **
4948 ** These macros defined the allowed values for the
4949 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
4950 ** an operator that is part of a constraint term in the wHERE clause of
4951 ** a query that uses a [virtual table].
4952 */
4953 #define SQLITE_INDEX_CONSTRAINT_EQ 2
4954 #define SQLITE_INDEX_CONSTRAINT_GT 4
4955 #define SQLITE_INDEX_CONSTRAINT_LE 8
4956 #define SQLITE_INDEX_CONSTRAINT_LT 16
4957 #define SQLITE_INDEX_CONSTRAINT_GE 32
@@ -5670,10 +5688,13 @@
5688 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
5689 ** internal equivalents). Only the value returned in the
5690 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5691 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5692 **
5693 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5694 ** <dd>This parameter records the number of separate memory allocations.</dd>)^
5695 **
5696 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5697 ** <dd>This parameter returns the number of pages used out of the
5698 ** [pagecache memory allocator] that was configured using
5699 ** [SQLITE_CONFIG_PAGECACHE]. The
5700 ** value returned is in pages, not in bytes.</dd>)^
@@ -5731,10 +5752,11 @@
5752 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
5753 #define SQLITE_STATUS_MALLOC_SIZE 5
5754 #define SQLITE_STATUS_PARSER_STACK 6
5755 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5756 #define SQLITE_STATUS_SCRATCH_SIZE 8
5757 #define SQLITE_STATUS_MALLOC_COUNT 9
5758
5759 /*
5760 ** CAPI3REF: Database Connection Status
5761 **
5762 ** ^This interface is used to retrieve runtime status information
@@ -5770,20 +5792,37 @@
5792 ** <dl>
5793 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5794 ** <dd>This parameter returns the number of lookaside memory slots currently
5795 ** checked out.</dd>)^
5796 **
5797 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5798 ** <dd>This parameter returns the approximate number of of bytes of heap
5799 ** memory used by all pager caches associated with the database connection.)^
5800 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5801 **
5802 ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
5803 ** <dd>This parameter returns the approximate number of of bytes of heap
5804 ** memory used to store the schema for all databases associated
5805 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
5806 ** ^The full amount of memory used by the schemas is reported, even if the
5807 ** schema memory is shared with other database connections due to
5808 ** [shared cache mode] being enabled.
5809 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
5810 **
5811 ** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
5812 ** <dd>This parameter returns the approximate number of of bytes of heap
5813 ** and lookaside memory used by all prepared statements associated with
5814 ** the database connection.)^
5815 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5816 ** </dd>
5817 ** </dl>
5818 */
5819 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5820 #define SQLITE_DBSTATUS_CACHE_USED 1
5821 #define SQLITE_DBSTATUS_SCHEMA_USED 2
5822 #define SQLITE_DBSTATUS_STMT_USED 3
5823 #define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
5824
5825
5826 /*
5827 ** CAPI3REF: Prepared Statement Status
5828 **
@@ -7257,10 +7296,14 @@
7296 #ifdef SQLITE_TEST
7297 SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
7298 SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*);
7299 #endif
7300
7301 #ifndef SQLITE_OMIT_WAL
7302 SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*);
7303 #endif
7304
7305 /*
7306 ** If we are not using shared cache, then there is no need to
7307 ** use mutexes to access the BtShared structures. So make the
7308 ** Enter and Leave procedures no-ops.
7309 */
@@ -7386,12 +7429,12 @@
7429 struct SubProgram {
7430 VdbeOp *aOp; /* Array of opcodes for sub-program */
7431 int nOp; /* Elements in aOp[] */
7432 int nMem; /* Number of memory cells required */
7433 int nCsr; /* Number of cursors required */
 
7434 void *token; /* id that may be used to recursive triggers */
7435 SubProgram *pNext; /* Next sub-program already visited */
7436 };
7437
7438 /*
7439 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
7440 ** it takes up less space.
@@ -7675,10 +7718,11 @@
7718 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
7719 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
7720 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
7721 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
7722 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
7723 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3*,Vdbe*);
7724 SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int,int,int);
7725 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
7726 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
7727 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
7728 #ifdef SQLITE_DEBUG
@@ -7692,20 +7736,23 @@
7736 SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
7737 SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
7738 SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, int);
7739 SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe*,Vdbe*);
7740 SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*);
 
7741 SQLITE_PRIVATE sqlite3_value *sqlite3VdbeGetValue(Vdbe*, int, u8);
7742 SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe*, int);
7743 #ifndef SQLITE_OMIT_TRACE
7744 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
7745 #endif
7746
7747 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,char*,int);
7748 SQLITE_PRIVATE void sqlite3VdbeDeleteUnpackedRecord(UnpackedRecord*);
7749 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
7750
7751 #ifndef SQLITE_OMIT_TRIGGER
7752 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
7753 #endif
7754
7755
7756 #ifndef NDEBUG
7757 SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...);
7758 # define VdbeComment(X) sqlite3VdbeComment X
@@ -7851,10 +7898,11 @@
7898
7899 /* Functions used to manage pager transactions and savepoints. */
7900 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*, int*);
7901 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
7902 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
7903 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
7904 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
7905 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
7906 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
7907 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
7908 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
@@ -8442,18 +8490,10 @@
8490 Schema *pSchema; /* Pointer to database schema (possibly shared) */
8491 };
8492
8493 /*
8494 ** An instance of the following structure stores a database schema.
 
 
 
 
 
 
 
 
8495 */
8496 struct Schema {
8497 int schema_cookie; /* Database schema version number for this file */
8498 Hash tblHash; /* All tables indexed by name */
8499 Hash idxHash; /* All (named) indices indexed by name */
@@ -8462,13 +8502,10 @@
8502 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */
8503 u8 file_format; /* Schema format version for this file */
8504 u8 enc; /* Text encoding used by this database */
8505 u16 flags; /* Flags associated with this schema */
8506 int cache_size; /* Number of pages to use in the cache */
 
 
 
8507 };
8508
8509 /*
8510 ** These macros can be used to test, set, or clear bits in the
8511 ** Db.pSchema->flags field.
@@ -8652,10 +8689,11 @@
8689 Savepoint *pSavepoint; /* List of active savepoints */
8690 int nSavepoint; /* Number of non-transaction savepoints */
8691 int nStatement; /* Number of nested statement-transactions */
8692 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
8693 i64 nDeferredCons; /* Net deferred constraints this transaction. */
8694 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
8695
8696 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
8697 /* The following variables are all protected by the STATIC_MASTER
8698 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
8699 **
@@ -9009,11 +9047,10 @@
9047 ** page number. Transient tables are used to hold the results of a
9048 ** sub-query that appears instead of a real table name in the FROM clause
9049 ** of a SELECT statement.
9050 */
9051 struct Table {
 
9052 char *zName; /* Name of the table or view */
9053 int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
9054 int nCol; /* Number of columns in this table */
9055 Column *aCol; /* Information about each column */
9056 Index *pIndex; /* List of SQL indexes on this table. */
@@ -10118,11 +10155,11 @@
10155 char *zText; /* The string collected so far */
10156 int nChar; /* Length of the string so far */
10157 int nAlloc; /* Amount of space allocated in zText */
10158 int mxAlloc; /* Maximum allowed string length */
10159 u8 mallocFailed; /* Becomes true if any memory allocation fails */
10160 u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
10161 u8 tooBig; /* Becomes true if string size exceeds limits */
10162 };
10163
10164 /*
10165 ** A pointer to this structure is used to communicate information
@@ -10416,11 +10453,11 @@
10453 #else
10454 # define sqlite3ViewGetColumnNames(A,B) 0
10455 #endif
10456
10457 SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
10458 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
10459 #ifndef SQLITE_OMIT_AUTOINCREMENT
10460 SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
10461 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
10462 #else
10463 # define sqlite3AutoincrementBegin(X)
@@ -10650,11 +10687,12 @@
10687 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
10688 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
10689 SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
10690 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
10691 SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
10692 SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*);
10693 SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*);
10694 SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
10695 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
10696 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
10697
10698 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
@@ -10700,11 +10738,11 @@
10738 SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*);
10739 SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*);
10740 SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*);
10741 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *);
10742 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB);
10743 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*);
10744 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
10745 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
10746 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
10747 SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
10748 SQLITE_PRIVATE void sqlite3SchemaFree(void *);
@@ -10762,11 +10800,11 @@
10800 # define sqlite3VtabInSync(db) 0
10801 # define sqlite3VtabLock(X)
10802 # define sqlite3VtabUnlock(X)
10803 # define sqlite3VtabUnlockList(X)
10804 #else
10805 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
10806 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
10807 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
10808 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
10809 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
10810 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
@@ -10815,13 +10853,13 @@
10853 #define sqlite3FkDropTable(a,b,c)
10854 #define sqlite3FkOldmask(a,b) 0
10855 #define sqlite3FkRequired(a,b,c,d) 0
10856 #endif
10857 #ifndef SQLITE_OMIT_FOREIGN_KEY
10858 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
10859 #else
10860 #define sqlite3FkDelete(a,b)
10861 #endif
10862
10863
10864 /*
10865 ** Available fault injectors. Should be numbered beginning with 0.
@@ -10910,36 +10948,40 @@
10948 ** a single bit set.
10949 **
10950 ** sqlite3MemdebugHasType() returns true if any of the bits in its second
10951 ** argument match the type set by the previous sqlite3MemdebugSetType().
10952 ** sqlite3MemdebugHasType() is intended for use inside assert() statements.
 
10953 **
10954 ** sqlite3MemdebugNoType() returns true if none of the bits in its second
10955 ** argument match the type set by the previous sqlite3MemdebugSetType().
10956 **
10957 ** Perhaps the most important point is the difference between MEMTYPE_HEAP
10958 ** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means
10959 ** it might have been allocated by lookaside, except the allocation was
10960 ** too large or lookaside was already full. It is important to verify
10961 ** that allocations that might have been satisfied by lookaside are not
10962 ** passed back to non-lookaside free() routines. Asserts such as the
10963 ** example above are placed on the non-lookaside free() routines to verify
10964 ** this constraint.
10965 **
10966 ** All of this is no-op for a production build. It only comes into
10967 ** play when the SQLITE_MEMDEBUG compile-time option is used.
10968 */
10969 #ifdef SQLITE_MEMDEBUG
10970 SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
10971 SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
10972 SQLITE_PRIVATE int sqlite3MemdebugNoType(void*,u8);
10973 #else
10974 # define sqlite3MemdebugSetType(X,Y) /* no-op */
10975 # define sqlite3MemdebugHasType(X,Y) 1
10976 # define sqlite3MemdebugNoType(X,Y) 1
10977 #endif
10978 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
10979 #define MEMTYPE_LOOKASIDE 0x02 /* Might have been lookaside memory */
10980 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
10981 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
10982 #define MEMTYPE_DB 0x10 /* Uses sqlite3DbMalloc, not sqlite_malloc */
10983
10984 #endif /* _SQLITEINT_H_ */
10985
10986 /************** End of sqliteInt.h *******************************************/
10987 /************** Begin file global.c ******************************************/
@@ -11566,18 +11608,442 @@
11608 *************************************************************************
11609 **
11610 ** This module implements the sqlite3_status() interface and related
11611 ** functionality.
11612 */
11613 /************** Include vdbeInt.h in the middle of status.c ******************/
11614 /************** Begin file vdbeInt.h *****************************************/
11615 /*
11616 ** 2003 September 6
11617 **
11618 ** The author disclaims copyright to this source code. In place of
11619 ** a legal notice, here is a blessing:
11620 **
11621 ** May you do good and not evil.
11622 ** May you find forgiveness for yourself and forgive others.
11623 ** May you share freely, never taking more than you give.
11624 **
11625 *************************************************************************
11626 ** This is the header file for information that is private to the
11627 ** VDBE. This information used to all be at the top of the single
11628 ** source code file "vdbe.c". When that file became too big (over
11629 ** 6000 lines long) it was split up into several smaller files and
11630 ** this header information was factored out.
11631 */
11632 #ifndef _VDBEINT_H_
11633 #define _VDBEINT_H_
11634
11635 /*
11636 ** SQL is translated into a sequence of instructions to be
11637 ** executed by a virtual machine. Each instruction is an instance
11638 ** of the following structure.
11639 */
11640 typedef struct VdbeOp Op;
11641
11642 /*
11643 ** Boolean values
11644 */
11645 typedef unsigned char Bool;
11646
11647 /*
11648 ** A cursor is a pointer into a single BTree within a database file.
11649 ** The cursor can seek to a BTree entry with a particular key, or
11650 ** loop over all entries of the Btree. You can also insert new BTree
11651 ** entries or retrieve the key or data from the entry that the cursor
11652 ** is currently pointing to.
11653 **
11654 ** Every cursor that the virtual machine has open is represented by an
11655 ** instance of the following structure.
11656 **
11657 ** If the VdbeCursor.isTriggerRow flag is set it means that this cursor is
11658 ** really a single row that represents the NEW or OLD pseudo-table of
11659 ** a row trigger. The data for the row is stored in VdbeCursor.pData and
11660 ** the rowid is in VdbeCursor.iKey.
11661 */
11662 struct VdbeCursor {
11663 BtCursor *pCursor; /* The cursor structure of the backend */
11664 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
11665 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
11666 Bool zeroed; /* True if zeroed out and ready for reuse */
11667 Bool rowidIsValid; /* True if lastRowid is valid */
11668 Bool atFirst; /* True if pointing to first entry */
11669 Bool useRandomRowid; /* Generate new record numbers semi-randomly */
11670 Bool nullRow; /* True if pointing to a row with no data */
11671 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
11672 Bool isTable; /* True if a table requiring integer keys */
11673 Bool isIndex; /* True if an index containing keys only - no data */
11674 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
11675 Btree *pBt; /* Separate file holding temporary table */
11676 int pseudoTableReg; /* Register holding pseudotable content. */
11677 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
11678 int nField; /* Number of fields in the header */
11679 i64 seqCount; /* Sequence counter */
11680 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
11681 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
11682
11683 /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
11684 ** OP_IsUnique opcode on this cursor. */
11685 int seekResult;
11686
11687 /* Cached information about the header for the data record that the
11688 ** cursor is currently pointing to. Only valid if cacheStatus matches
11689 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
11690 ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
11691 ** the cache is out of date.
11692 **
11693 ** aRow might point to (ephemeral) data for the current row, or it might
11694 ** be NULL.
11695 */
11696 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
11697 int payloadSize; /* Total number of bytes in the record */
11698 u32 *aType; /* Type values for all entries in the record */
11699 u32 *aOffset; /* Cached offsets to the start of each columns data */
11700 u8 *aRow; /* Data for the current row, if all on one page */
11701 };
11702 typedef struct VdbeCursor VdbeCursor;
11703
11704 /*
11705 ** When a sub-program is executed (OP_Program), a structure of this type
11706 ** is allocated to store the current value of the program counter, as
11707 ** well as the current memory cell array and various other frame specific
11708 ** values stored in the Vdbe struct. When the sub-program is finished,
11709 ** these values are copied back to the Vdbe from the VdbeFrame structure,
11710 ** restoring the state of the VM to as it was before the sub-program
11711 ** began executing.
11712 **
11713 ** Frames are stored in a linked list headed at Vdbe.pParent. Vdbe.pParent
11714 ** is the parent of the current frame, or zero if the current frame
11715 ** is the main Vdbe program.
11716 */
11717 typedef struct VdbeFrame VdbeFrame;
11718 struct VdbeFrame {
11719 Vdbe *v; /* VM this frame belongs to */
11720 int pc; /* Program Counter */
11721 Op *aOp; /* Program instructions */
11722 int nOp; /* Size of aOp array */
11723 Mem *aMem; /* Array of memory cells */
11724 int nMem; /* Number of entries in aMem */
11725 VdbeCursor **apCsr; /* Element of Vdbe cursors */
11726 u16 nCursor; /* Number of entries in apCsr */
11727 void *token; /* Copy of SubProgram.token */
11728 int nChildMem; /* Number of memory cells for child frame */
11729 int nChildCsr; /* Number of cursors for child frame */
11730 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
11731 int nChange; /* Statement changes (Vdbe.nChanges) */
11732 VdbeFrame *pParent; /* Parent of this frame */
11733 };
11734
11735 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
11736
11737 /*
11738 ** A value for VdbeCursor.cacheValid that means the cache is always invalid.
11739 */
11740 #define CACHE_STALE 0
11741
11742 /*
11743 ** Internally, the vdbe manipulates nearly all SQL values as Mem
11744 ** structures. Each Mem struct may cache multiple representations (string,
11745 ** integer etc.) of the same value. A value (and therefore Mem structure)
11746 ** has the following properties:
11747 **
11748 ** Each value has a manifest type. The manifest type of the value stored
11749 ** in a Mem struct is returned by the MemType(Mem*) macro. The type is
11750 ** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
11751 ** SQLITE_BLOB.
11752 */
11753 struct Mem {
11754 union {
11755 i64 i; /* Integer value. */
11756 int nZero; /* Used when bit MEM_Zero is set in flags */
11757 FuncDef *pDef; /* Used only when flags==MEM_Agg */
11758 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
11759 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
11760 } u;
11761 double r; /* Real value */
11762 sqlite3 *db; /* The associated database connection */
11763 char *z; /* String or BLOB value */
11764 int n; /* Number of characters in string value, excluding '\0' */
11765 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
11766 u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
11767 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
11768 void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
11769 char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
11770 };
11771
11772 /* One or more of the following flags are set to indicate the validOK
11773 ** representations of the value stored in the Mem struct.
11774 **
11775 ** If the MEM_Null flag is set, then the value is an SQL NULL value.
11776 ** No other flags may be set in this case.
11777 **
11778 ** If the MEM_Str flag is set then Mem.z points at a string representation.
11779 ** Usually this is encoded in the same unicode encoding as the main
11780 ** database (see below for exceptions). If the MEM_Term flag is also
11781 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
11782 ** flags may coexist with the MEM_Str flag.
11783 **
11784 ** Multiple of these values can appear in Mem.flags. But only one
11785 ** at a time can appear in Mem.type.
11786 */
11787 #define MEM_Null 0x0001 /* Value is NULL */
11788 #define MEM_Str 0x0002 /* Value is a string */
11789 #define MEM_Int 0x0004 /* Value is an integer */
11790 #define MEM_Real 0x0008 /* Value is a real number */
11791 #define MEM_Blob 0x0010 /* Value is a BLOB */
11792 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
11793 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
11794 #define MEM_TypeMask 0x00ff /* Mask of type bits */
11795
11796 /* Whenever Mem contains a valid string or blob representation, one of
11797 ** the following flags must be set to determine the memory management
11798 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
11799 ** string is \000 or \u0000 terminated
11800 */
11801 #define MEM_Term 0x0200 /* String rep is nul terminated */
11802 #define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
11803 #define MEM_Static 0x0800 /* Mem.z points to a static string */
11804 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
11805 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
11806 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
11807
11808 #ifdef SQLITE_OMIT_INCRBLOB
11809 #undef MEM_Zero
11810 #define MEM_Zero 0x0000
11811 #endif
11812
11813
11814 /*
11815 ** Clear any existing type flags from a Mem and replace them with f
11816 */
11817 #define MemSetTypeFlag(p, f) \
11818 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
11819
11820
11821 /* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
11822 ** additional information about auxiliary information bound to arguments
11823 ** of the function. This is used to implement the sqlite3_get_auxdata()
11824 ** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
11825 ** that can be associated with a constant argument to a function. This
11826 ** allows functions such as "regexp" to compile their constant regular
11827 ** expression argument once and reused the compiled code for multiple
11828 ** invocations.
11829 */
11830 struct VdbeFunc {
11831 FuncDef *pFunc; /* The definition of the function */
11832 int nAux; /* Number of entries allocated for apAux[] */
11833 struct AuxData {
11834 void *pAux; /* Aux data for the i-th argument */
11835 void (*xDelete)(void *); /* Destructor for the aux data */
11836 } apAux[1]; /* One slot for each function argument */
11837 };
11838
11839 /*
11840 ** The "context" argument for a installable function. A pointer to an
11841 ** instance of this structure is the first argument to the routines used
11842 ** implement the SQL functions.
11843 **
11844 ** There is a typedef for this structure in sqlite.h. So all routines,
11845 ** even the public interface to SQLite, can use a pointer to this structure.
11846 ** But this file is the only place where the internal details of this
11847 ** structure are known.
11848 **
11849 ** This structure is defined inside of vdbeInt.h because it uses substructures
11850 ** (Mem) which are only defined there.
11851 */
11852 struct sqlite3_context {
11853 FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
11854 VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
11855 Mem s; /* The return value is stored here */
11856 Mem *pMem; /* Memory cell used to store aggregate context */
11857 int isError; /* Error code returned by the function. */
11858 CollSeq *pColl; /* Collating sequence */
11859 };
11860
11861 /*
11862 ** A Set structure is used for quick testing to see if a value
11863 ** is part of a small set. Sets are used to implement code like
11864 ** this:
11865 ** x.y IN ('hi','hoo','hum')
11866 */
11867 typedef struct Set Set;
11868 struct Set {
11869 Hash hash; /* A set is just a hash table */
11870 HashElem *prev; /* Previously accessed hash elemen */
11871 };
11872
11873 /*
11874 ** An instance of the virtual machine. This structure contains the complete
11875 ** state of the virtual machine.
11876 **
11877 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()
11878 ** is really a pointer to an instance of this structure.
11879 **
11880 ** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
11881 ** any virtual table method invocations made by the vdbe program. It is
11882 ** set to 2 for xDestroy method calls and 1 for all other methods. This
11883 ** variable is used for two purposes: to allow xDestroy methods to execute
11884 ** "DROP TABLE" statements and to prevent some nasty side effects of
11885 ** malloc failure when SQLite is invoked recursively by a virtual table
11886 ** method function.
11887 */
11888 struct Vdbe {
11889 sqlite3 *db; /* The database connection that owns this statement */
11890 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
11891 int nOp; /* Number of instructions in the program */
11892 int nOpAlloc; /* Number of slots allocated for aOp[] */
11893 Op *aOp; /* Space to hold the virtual machine's program */
11894 int nLabel; /* Number of labels used */
11895 int nLabelAlloc; /* Number of slots allocated in aLabel[] */
11896 int *aLabel; /* Space to hold the labels */
11897 Mem **apArg; /* Arguments to currently executing user function */
11898 Mem *aColName; /* Column names to return */
11899 Mem *pResultSet; /* Pointer to an array of results */
11900 u16 nResColumn; /* Number of columns in one row of the result set */
11901 u16 nCursor; /* Number of slots in apCsr[] */
11902 VdbeCursor **apCsr; /* One element of this array for each open cursor */
11903 u8 errorAction; /* Recovery action to do in case of an error */
11904 u8 okVar; /* True if azVar[] has been initialized */
11905 ynVar nVar; /* Number of entries in aVar[] */
11906 Mem *aVar; /* Values for the OP_Variable opcode. */
11907 char **azVar; /* Name of variables */
11908 u32 magic; /* Magic number for sanity checking */
11909 int nMem; /* Number of memory locations currently allocated */
11910 Mem *aMem; /* The memory locations */
11911 u32 cacheCtr; /* VdbeCursor row cache generation counter */
11912 int pc; /* The program counter */
11913 int rc; /* Value to return */
11914 char *zErrMsg; /* Error message written here */
11915 u8 explain; /* True if EXPLAIN present on SQL command */
11916 u8 changeCntOn; /* True to update the change-counter */
11917 u8 expired; /* True if the VM needs to be recompiled */
11918 u8 runOnlyOnce; /* Automatically expire on reset */
11919 u8 minWriteFileFormat; /* Minimum file format for writable database files */
11920 u8 inVtabMethod; /* See comments above */
11921 u8 usesStmtJournal; /* True if uses a statement journal */
11922 u8 readOnly; /* True for read-only statements */
11923 u8 isPrepareV2; /* True if prepared with prepare_v2() */
11924 int nChange; /* Number of db changes made since last reset */
11925 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
11926 i64 startTime; /* Time when query started - used for profiling */
11927 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
11928 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
11929 char *zSql; /* Text of the SQL statement that generated this */
11930 void *pFree; /* Free this when deleting the vdbe */
11931 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
11932 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
11933 int iStatement; /* Statement number (or 0 if has not opened stmt) */
11934 #ifdef SQLITE_DEBUG
11935 FILE *trace; /* Write an execution trace here, if not NULL */
11936 #endif
11937 VdbeFrame *pFrame; /* Parent frame */
11938 int nFrame; /* Number of frames in pFrame list */
11939 u32 expmask; /* Binding to these vars invalidates VM */
11940 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
11941 };
11942
11943 /*
11944 ** The following are allowed values for Vdbe.magic
11945 */
11946 #define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */
11947 #define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */
11948 #define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */
11949 #define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */
11950
11951 /*
11952 ** Function prototypes
11953 */
11954 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
11955 void sqliteVdbePopStack(Vdbe*,int);
11956 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
11957 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
11958 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
11959 #endif
11960 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
11961 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
11962 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
11963 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
11964 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
11965
11966 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
11967 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
11968 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
11969 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
11970 SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
11971 SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
11972 SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
11973 SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int);
11974 SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*);
11975 SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem*, const Mem*);
11976 SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
11977 SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem*, Mem*);
11978 SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem*);
11979 SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
11980 SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem*, i64);
11981 #ifdef SQLITE_OMIT_FLOATING_POINT
11982 # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
11983 #else
11984 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
11985 #endif
11986 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
11987 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
11988 SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
11989 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
11990 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, int);
11991 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*);
11992 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
11993 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
11994 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
11995 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
11996 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
11997 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
11998 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
11999 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
12000 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
12001 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
12002 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
12003 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
12004 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
12005 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
12006 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
12007
12008 #ifndef SQLITE_OMIT_FOREIGN_KEY
12009 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
12010 #else
12011 # define sqlite3VdbeCheckFk(p,i) 0
12012 #endif
12013
12014 #ifndef SQLITE_OMIT_SHARED_CACHE
12015 SQLITE_PRIVATE void sqlite3VdbeMutexArrayEnter(Vdbe *p);
12016 #else
12017 # define sqlite3VdbeMutexArrayEnter(p)
12018 #endif
12019
12020 SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
12021 #ifdef SQLITE_DEBUG
12022 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*);
12023 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
12024 #endif
12025 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
12026
12027 #ifndef SQLITE_OMIT_INCRBLOB
12028 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *);
12029 #else
12030 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
12031 #endif
12032
12033 #endif /* !defined(_VDBEINT_H_) */
12034
12035 /************** End of vdbeInt.h *********************************************/
12036 /************** Continuing where we left off in status.c *********************/
12037
12038 /*
12039 ** Variables in which to record status information.
12040 */
12041 typedef struct sqlite3StatType sqlite3StatType;
12042 static SQLITE_WSD struct sqlite3StatType {
12043 int nowValue[10]; /* Current value */
12044 int mxValue[10]; /* Maximum value */
12045 } sqlite3Stat = { {0,}, {0,} };
12046
12047
12048 /* The "wsdStat" macro will resolve to the status information
12049 ** state vector. If writable static data is unsupported on the target,
@@ -11655,10 +12121,12 @@
12121 int op, /* Status verb */
12122 int *pCurrent, /* Write current value here */
12123 int *pHighwater, /* Write high-water mark here */
12124 int resetFlag /* Reset high-water mark if true */
12125 ){
12126 int rc = SQLITE_OK; /* Return code */
12127 sqlite3_mutex_enter(db->mutex);
12128 switch( op ){
12129 case SQLITE_DBSTATUS_LOOKASIDE_USED: {
12130 *pCurrent = db->lookaside.nOut;
12131 *pHighwater = db->lookaside.mxOut;
12132 if( resetFlag ){
@@ -11673,26 +12141,92 @@
12141 ** highwater mark is meaningless and is returned as zero.
12142 */
12143 case SQLITE_DBSTATUS_CACHE_USED: {
12144 int totalUsed = 0;
12145 int i;
12146 sqlite3BtreeEnterAll(db);
12147 for(i=0; i<db->nDb; i++){
12148 Btree *pBt = db->aDb[i].pBt;
12149 if( pBt ){
12150 Pager *pPager = sqlite3BtreePager(pBt);
12151 totalUsed += sqlite3PagerMemUsed(pPager);
12152 }
12153 }
12154 sqlite3BtreeLeaveAll(db);
12155 *pCurrent = totalUsed;
12156 *pHighwater = 0;
12157 break;
12158 }
12159
12160 /*
12161 ** *pCurrent gets an accurate estimate of the amount of memory used
12162 ** to store the schema for all databases (main, temp, and any ATTACHed
12163 ** databases. *pHighwater is set to zero.
12164 */
12165 case SQLITE_DBSTATUS_SCHEMA_USED: {
12166 int i; /* Used to iterate through schemas */
12167 int nByte = 0; /* Used to accumulate return value */
12168
12169 db->pnBytesFreed = &nByte;
12170 for(i=0; i<db->nDb; i++){
12171 Schema *pSchema = db->aDb[i].pSchema;
12172 if( ALWAYS(pSchema!=0) ){
12173 HashElem *p;
12174
12175 nByte += sqlite3GlobalConfig.m.xRoundup(sizeof(HashElem)) * (
12176 pSchema->tblHash.count
12177 + pSchema->trigHash.count
12178 + pSchema->idxHash.count
12179 + pSchema->fkeyHash.count
12180 );
12181 nByte += sqlite3MallocSize(pSchema->tblHash.ht);
12182 nByte += sqlite3MallocSize(pSchema->trigHash.ht);
12183 nByte += sqlite3MallocSize(pSchema->idxHash.ht);
12184 nByte += sqlite3MallocSize(pSchema->fkeyHash.ht);
12185
12186 for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){
12187 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
12188 }
12189 for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
12190 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
12191 }
12192 }
12193 }
12194 db->pnBytesFreed = 0;
12195
12196 *pHighwater = 0;
12197 *pCurrent = nByte;
12198 break;
12199 }
12200
12201 /*
12202 ** *pCurrent gets an accurate estimate of the amount of memory used
12203 ** to store all prepared statements.
12204 ** *pHighwater is set to zero.
12205 */
12206 case SQLITE_DBSTATUS_STMT_USED: {
12207 struct Vdbe *pVdbe; /* Used to iterate through VMs */
12208 int nByte = 0; /* Used to accumulate return value */
12209
12210 db->pnBytesFreed = &nByte;
12211 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
12212 sqlite3VdbeDeleteObject(db, pVdbe);
12213 }
12214 db->pnBytesFreed = 0;
12215
12216 *pHighwater = 0;
12217 *pCurrent = nByte;
12218
12219 break;
12220 }
12221
12222 default: {
12223 rc = SQLITE_ERROR;
12224 }
12225 }
12226 sqlite3_mutex_leave(db->mutex);
12227 return rc;
12228 }
12229
12230 /************** End of status.c **********************************************/
12231 /************** Begin file date.c ********************************************/
12232 /*
@@ -13820,23 +14354,38 @@
14354 int rc = 1;
14355 if( p ){
14356 struct MemBlockHdr *pHdr;
14357 pHdr = sqlite3MemsysGetHeader(p);
14358 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
 
14359 if( (pHdr->eType&eType)==0 ){
14360 rc = 0;
14361 }
14362 }
14363 return rc;
14364 }
14365
14366 /*
14367 ** Return TRUE if the mask of type in eType matches no bits of the type of the
14368 ** allocation p. Also return true if p==NULL.
14369 **
14370 ** This routine is designed for use within an assert() statement, to
14371 ** verify the type of an allocation. For example:
14372 **
14373 ** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
14374 */
14375 SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
14376 int rc = 1;
14377 if( p ){
14378 struct MemBlockHdr *pHdr;
14379 pHdr = sqlite3MemsysGetHeader(p);
14380 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
14381 if( (pHdr->eType&eType)!=0 ){
14382 rc = 0;
14383 }
14384 }
14385 return rc;
14386 }
 
14387
14388 /*
14389 ** Set the number of backtrace levels kept for each allocation.
14390 ** A value of zero turns off backtracing. The number is always rounded
14391 ** up to a multiple of 2.
@@ -16773,10 +17322,11 @@
17322 p = sqlite3GlobalConfig.m.xMalloc(nFull);
17323 }
17324 if( p ){
17325 nFull = sqlite3MallocSize(p);
17326 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull);
17327 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, 1);
17328 }
17329 *pp = p;
17330 return nFull;
17331 }
17332
@@ -16890,16 +17440,18 @@
17440 if( p ){
17441 if( sqlite3GlobalConfig.pScratch==0
17442 || p<sqlite3GlobalConfig.pScratch
17443 || p>=(void*)mem0.aScratchFree ){
17444 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
17445 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) );
17446 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
17447 if( sqlite3GlobalConfig.bMemstat ){
17448 int iSize = sqlite3MallocSize(p);
17449 sqlite3_mutex_enter(mem0.mutex);
17450 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
17451 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
17452 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
17453 sqlite3GlobalConfig.m.xFree(p);
17454 sqlite3_mutex_leave(mem0.mutex);
17455 }else{
17456 sqlite3GlobalConfig.m.xFree(p);
17457 }
@@ -16930,11 +17482,11 @@
17482 /*
17483 ** TRUE if p is a lookaside memory allocation from db
17484 */
17485 #ifndef SQLITE_OMIT_LOOKASIDE
17486 static int isLookaside(sqlite3 *db, void *p){
17487 return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
17488 }
17489 #else
17490 #define isLookaside(A,B) 0
17491 #endif
17492
@@ -16942,32 +17494,36 @@
17494 ** Return the size of a memory allocation previously obtained from
17495 ** sqlite3Malloc() or sqlite3_malloc().
17496 */
17497 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
17498 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
17499 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
17500 return sqlite3GlobalConfig.m.xSize(p);
17501 }
17502 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
17503 assert( db==0 || sqlite3_mutex_held(db->mutex) );
17504 if( db && isLookaside(db, p) ){
17505 return db->lookaside.sz;
17506 }else{
17507 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17508 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
17509 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
17510 return sqlite3GlobalConfig.m.xSize(p);
17511 }
17512 }
17513
17514 /*
17515 ** Free memory previously obtained from sqlite3Malloc().
17516 */
17517 SQLITE_API void sqlite3_free(void *p){
17518 if( p==0 ) return;
17519 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
17520 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
17521 if( sqlite3GlobalConfig.bMemstat ){
17522 sqlite3_mutex_enter(mem0.mutex);
17523 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
17524 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
17525 sqlite3GlobalConfig.m.xFree(p);
17526 sqlite3_mutex_leave(mem0.mutex);
17527 }else{
17528 sqlite3GlobalConfig.m.xFree(p);
17529 }
@@ -16977,20 +17533,28 @@
17533 ** Free memory that might be associated with a particular database
17534 ** connection.
17535 */
17536 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
17537 assert( db==0 || sqlite3_mutex_held(db->mutex) );
17538 if( db ){
17539 if( db->pnBytesFreed ){
17540 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
17541 return;
17542 }
17543 if( isLookaside(db, p) ){
17544 LookasideSlot *pBuf = (LookasideSlot*)p;
17545 pBuf->pNext = db->lookaside.pFree;
17546 db->lookaside.pFree = pBuf;
17547 db->lookaside.nOut--;
17548 return;
17549 }
17550 }
17551 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17552 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
17553 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
17554 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
17555 sqlite3_free(p);
17556 }
17557
17558 /*
17559 ** Change the size of an existing memory allocation
17560 */
@@ -17018,10 +17582,11 @@
17582 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
17583 mem0.alarmThreshold ){
17584 sqlite3MallocAlarm(nNew-nOld);
17585 }
17586 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
17587 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
17588 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
17589 if( pNew==0 && mem0.alarmCallback ){
17590 sqlite3MallocAlarm(nBytes);
17591 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
17592 }
@@ -17090,10 +17655,11 @@
17655 ** that all prior mallocs (ex: "a") worked too.
17656 */
17657 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
17658 void *p;
17659 assert( db==0 || sqlite3_mutex_held(db->mutex) );
17660 assert( db==0 || db->pnBytesFreed==0 );
17661 #ifndef SQLITE_OMIT_LOOKASIDE
17662 if( db ){
17663 LookasideSlot *pBuf;
17664 if( db->mallocFailed ){
17665 return 0;
@@ -17115,12 +17681,12 @@
17681 #endif
17682 p = sqlite3Malloc(n);
17683 if( !p && db ){
17684 db->mallocFailed = 1;
17685 }
17686 sqlite3MemdebugSetType(p, MEMTYPE_DB |
17687 ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
17688 return p;
17689 }
17690
17691 /*
17692 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -17142,18 +17708,20 @@
17708 if( pNew ){
17709 memcpy(pNew, p, db->lookaside.sz);
17710 sqlite3DbFree(db, p);
17711 }
17712 }else{
17713 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17714 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
17715 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
17716 pNew = sqlite3_realloc(p, n);
17717 if( !pNew ){
17718 sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
17719 db->mallocFailed = 1;
17720 }
17721 sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
17722 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
17723 }
17724 }
17725 return pNew;
17726 }
17727
@@ -18022,11 +18590,15 @@
18590 p->tooBig = 1;
18591 return;
18592 }else{
18593 p->nAlloc = (int)szNew;
18594 }
18595 if( p->useMalloc==1 ){
18596 zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
18597 }else{
18598 zNew = sqlite3_malloc(p->nAlloc);
18599 }
18600 if( zNew ){
18601 memcpy(zNew, p->zText, p->nChar);
18602 sqlite3StrAccumReset(p);
18603 p->zText = zNew;
18604 }else{
@@ -18047,11 +18619,15 @@
18619 */
18620 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
18621 if( p->zText ){
18622 p->zText[p->nChar] = 0;
18623 if( p->useMalloc && p->zText==p->zBase ){
18624 if( p->useMalloc==1 ){
18625 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
18626 }else{
18627 p->zText = sqlite3_malloc(p->nChar+1);
18628 }
18629 if( p->zText ){
18630 memcpy(p->zText, p->zBase, p->nChar+1);
18631 }else{
18632 p->mallocFailed = 1;
18633 }
@@ -18063,11 +18639,15 @@
18639 /*
18640 ** Reset an StrAccum string. Reclaim all malloced memory.
18641 */
18642 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
18643 if( p->zText!=p->zBase ){
18644 if( p->useMalloc==1 ){
18645 sqlite3DbFree(p->db, p->zText);
18646 }else{
18647 sqlite3_free(p->zText);
18648 }
18649 }
18650 p->zText = 0;
18651 }
18652
18653 /*
@@ -18145,10 +18725,11 @@
18725 StrAccum acc;
18726 #ifndef SQLITE_OMIT_AUTOINIT
18727 if( sqlite3_initialize() ) return 0;
18728 #endif
18729 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
18730 acc.useMalloc = 2;
18731 sqlite3VXPrintf(&acc, 0, zFormat, ap);
18732 z = sqlite3StrAccumFinish(&acc);
18733 return z;
18734 }
18735
@@ -18438,433 +19019,10 @@
19019 ** BOM or Byte Order Mark:
19020 ** 0xff 0xfe little-endian utf-16 follows
19021 ** 0xfe 0xff big-endian utf-16 follows
19022 **
19023 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19024
19025 #ifndef SQLITE_AMALGAMATION
19026 /*
19027 ** The following constant value is used by the SQLITE_BIGENDIAN and
19028 ** SQLITE_LITTLEENDIAN macros.
@@ -21891,11 +22049,11 @@
22049 }
22050
22051
22052 memset( pFile, 0, sizeof(*pFile) );
22053
22054 OSTRACE(( "OPEN want %d\n", flags ));
22055
22056 if( flags & SQLITE_OPEN_READWRITE ){
22057 ulOpenMode |= OPEN_ACCESS_READWRITE;
22058 OSTRACE(( "OPEN read/write\n" ));
22059 }else{
@@ -32701,15 +32859,15 @@
32859 ** back to sqlite3Malloc().
32860 */
32861 static void *pcache1Alloc(int nByte){
32862 void *p;
32863 assert( sqlite3_mutex_held(pcache1.mutex) );
32864 sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
32865 if( nByte<=pcache1.szSlot && pcache1.pFree ){
32866 assert( pcache1.isInit );
32867 p = (PgHdr1 *)pcache1.pFree;
32868 pcache1.pFree = pcache1.pFree->pNext;
 
32869 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
32870 }else{
32871
32872 /* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
32873 ** global pcache mutex and unlock the pager-cache object pCache. This is
@@ -34150,34 +34308,42 @@
34308 ** It is used when committing or otherwise ending a transaction. If
34309 ** the dbModified flag is clear then less work has to be done.
34310 **
34311 ** journalStarted
34312 **
34313 ** This flag is set during a write-transaction after the first
34314 ** journal-header is written and synced to disk.
34315 **
 
 
34316 ** After this has happened, new pages appended to the database
34317 ** do not need the PGHDR_NEED_SYNC flag set, as they do not need
34318 ** to wait for a journal sync before they can be written out to
34319 ** the database file (see function pager_write()).
34320 **
34321 ** setMaster
34322 **
34323 ** When PagerCommitPhaseOne() is called to commit a transaction, it may
34324 ** (or may not) specify a master-journal name to be written into the
34325 ** journal file before it is synced to disk.
34326 **
34327 ** Whether or not a journal file contains a master-journal pointer affects
34328 ** the way in which the journal file is finalized after the transaction is
34329 ** committed or rolled back when running in "journal_mode=PERSIST" mode.
34330 ** If a journal file does not contain a master-journal pointer, it is
34331 ** finalized by overwriting the first journal header with zeroes. If,
34332 ** on the other hand, it does contain a master-journal pointer, the
34333 ** journal file is finalized by truncating it to zero bytes, just as if
34334 ** the connection were running in "journal_mode=truncate" mode.
34335 **
34336 ** Journal files that contain master journal pointers cannot be finalized
34337 ** simply by overwriting the first journal-header with zeroes, as the
34338 ** master journal pointer could interfere with hot-journal rollback of any
34339 ** subsequently interrupted transaction that reuses the journal file.
34340 **
34341 ** The flag is cleared as soon as the journal file is finalized (either
34342 ** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
34343 ** journal file from being successfully finalized, the setMaster flag
34344 ** is cleared anyway.
34345 **
34346 ** doNotSpill, doNotSyncSpill
34347 **
34348 ** When enabled, cache spills are prohibited. The doNotSpill variable
34349 ** inhibits all cache spill and doNotSyncSpill inhibits those spills that
@@ -34941,11 +35107,12 @@
35107 int nMaster; /* Length of string zMaster */
35108 i64 iHdrOff; /* Offset of header in journal file */
35109 i64 jrnlSize; /* Size of journal file on disk */
35110 u32 cksum = 0; /* Checksum of string zMaster */
35111
35112 assert( pPager->setMaster==0 );
35113 if( !zMaster
35114 || pPager->journalMode==PAGER_JOURNALMODE_MEMORY
35115 || pPager->journalMode==PAGER_JOURNALMODE_OFF
35116 ){
35117 return SQLITE_OK;
35118 }
@@ -38928,10 +39095,30 @@
39095 }else{
39096 rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
39097 }
39098 return rc;
39099 }
39100
39101 /*
39102 ** This function may only be called while a write-transaction is active in
39103 ** rollback. If the connection is in WAL mode, this call is a no-op.
39104 ** Otherwise, if the connection does not already have an EXCLUSIVE lock on
39105 ** the database file, an attempt is made to obtain one.
39106 **
39107 ** If the EXCLUSIVE lock is already held or the attempt to obtain it is
39108 ** successful, or the connection is in WAL mode, SQLITE_OK is returned.
39109 ** Otherwise, either SQLITE_BUSY or an SQLITE_IOERR_XXX error code is
39110 ** returned.
39111 */
39112 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager *pPager){
39113 int rc = SQLITE_OK;
39114 assert( pPager->state>=PAGER_RESERVED );
39115 if( 0==pagerUseWal(pPager) ){
39116 rc = pager_wait_on_lock(pPager, PAGER_EXCLUSIVE);
39117 }
39118 return rc;
39119 }
39120
39121 /*
39122 ** Sync the database file for the pager pPager. zMaster points to the name
39123 ** of a master journal file that should be written into the individual
39124 ** journal file. zMaster may be NULL, which is interpreted as no master
@@ -38977,11 +39164,11 @@
39164 /* If this is an in-memory db, or no pages have been written to, or this
39165 ** function has already been called, it is mostly a no-op. However, any
39166 ** backup in progress needs to be restarted.
39167 */
39168 sqlite3BackupRestart(pPager->pBackup);
39169 }else if( pPager->dbModified ){
39170 if( pagerUseWal(pPager) ){
39171 PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
39172 if( pList ){
39173 rc = pagerWalFrames(pPager, pList, pPager->dbSize, 1,
39174 (pPager->fullSync ? pPager->sync_flags : 0)
@@ -39115,10 +39302,11 @@
39302 rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
39303 }
39304 IOTRACE(("DBSYNC %p\n", pPager))
39305 }
39306
39307 assert( pPager->state!=PAGER_SYNCED );
39308 pPager->state = PAGER_SYNCED;
39309 }
39310
39311 commit_phase_one_exit:
39312 return rc;
@@ -39282,13 +39470,15 @@
39470 /*
39471 ** Return the approximate number of bytes of memory currently
39472 ** used by the pager and its associated cache.
39473 */
39474 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
39475 int perPageSize = pPager->pageSize + pPager->nExtra + sizeof(PgHdr)
39476 + 5*sizeof(void*);
39477 return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
39478 + sqlite3MallocSize(pPager)
39479 + pPager->pageSize;
39480 }
39481
39482 /*
39483 ** Return the number of references to the specified page.
39484 */
@@ -45683,11 +45873,11 @@
45873 assert( !pBt->pCursor );
45874 sqlite3PagerClose(pBt->pPager);
45875 if( pBt->xFreeSchema && pBt->pSchema ){
45876 pBt->xFreeSchema(pBt->pSchema);
45877 }
45878 sqlite3DbFree(0, pBt->pSchema);
45879 freeTempSpace(pBt);
45880 sqlite3_free(pBt);
45881 }
45882
45883 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -46248,17 +46438,31 @@
46438 }
46439 p->inTrans = (wrflag?TRANS_WRITE:TRANS_READ);
46440 if( p->inTrans>pBt->inTransaction ){
46441 pBt->inTransaction = p->inTrans;
46442 }
 
46443 if( wrflag ){
46444 MemPage *pPage1 = pBt->pPage1;
46445 #ifndef SQLITE_OMIT_SHARED_CACHE
46446 assert( !pBt->pWriter );
46447 pBt->pWriter = p;
46448 pBt->isExclusive = (u8)(wrflag>1);
46449 #endif
46450
46451 /* If the db-size header field is incorrect (as it may be if an old
46452 ** client has been writing the database file), update it now. Doing
46453 ** this sooner rather than later means the database size can safely
46454 ** re-read the database size from page 1 if a savepoint or transaction
46455 ** rollback occurs within the transaction.
46456 */
46457 if( pBt->nPage!=get4byte(&pPage1->aData[28]) ){
46458 rc = sqlite3PagerWrite(pPage1->pDbPage);
46459 if( rc==SQLITE_OK ){
46460 put4byte(&pPage1->aData[28], pBt->nPage);
46461 }
46462 }
46463 }
 
46464 }
46465
46466
46467 trans_begun:
46468 if( rc==SQLITE_OK && wrflag ){
@@ -46993,13 +47197,15 @@
47197 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
47198 if( rc==SQLITE_OK ){
47199 if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
47200 rc = newDatabase(pBt);
47201 pBt->nPage = get4byte(28 + pBt->pPage1->aData);
47202
47203 /* The database size was written into the offset 28 of the header
47204 ** when the transaction started, so we know that the value at offset
47205 ** 28 is nonzero. */
47206 assert( pBt->nPage>0 );
47207 }
47208 sqlite3BtreeLeave(p);
47209 }
47210 return rc;
47211 }
@@ -51428,10 +51634,11 @@
51634 i = PENDING_BYTE_PAGE(pBt);
51635 if( i<=sCheck.nPage ){
51636 sCheck.anRef[i] = 1;
51637 }
51638 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000);
51639 sCheck.errMsg.useMalloc = 2;
51640
51641 /* Check the integrity of the freelist
51642 */
51643 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
51644 get4byte(&pBt->pPage1->aData[36]), "Main freelist: ");
@@ -51526,10 +51733,33 @@
51733 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree *p){
51734 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
51735 return (p && (p->inTrans==TRANS_WRITE));
51736 }
51737
51738 #ifndef SQLITE_OMIT_WAL
51739 /*
51740 ** Run a checkpoint on the Btree passed as the first argument.
51741 **
51742 ** Return SQLITE_LOCKED if this or any other connection has an open
51743 ** transaction on the shared-cache the argument Btree is connected to.
51744 */
51745 SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree *p){
51746 int rc = SQLITE_OK;
51747 if( p ){
51748 BtShared *pBt = p->pBt;
51749 sqlite3BtreeEnter(p);
51750 if( pBt->inTransaction!=TRANS_NONE ){
51751 rc = SQLITE_LOCKED;
51752 }else{
51753 rc = sqlite3PagerCheckpoint(pBt->pPager);
51754 }
51755 sqlite3BtreeLeave(p);
51756 }
51757 return rc;
51758 }
51759 #endif
51760
51761 /*
51762 ** Return non-zero if a read (or write) transaction is active.
51763 */
51764 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
51765 assert( p );
@@ -51565,11 +51795,11 @@
51795 */
51796 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
51797 BtShared *pBt = p->pBt;
51798 sqlite3BtreeEnter(p);
51799 if( !pBt->pSchema && nBytes ){
51800 pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
51801 pBt->xFreeSchema = xFree;
51802 }
51803 sqlite3BtreeLeave(p);
51804 return pBt->pSchema;
51805 }
@@ -53373,11 +53603,11 @@
53603 *ppVal = 0;
53604 return SQLITE_OK;
53605 }
53606 op = pExpr->op;
53607
53608 /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT2.
53609 ** The ifdef here is to enable us to achieve 100% branch test coverage even
53610 ** when SQLITE_ENABLE_STAT2 is omitted.
53611 */
53612 #ifdef SQLITE_ENABLE_STAT2
53613 if( op==TK_REGISTER ) op = pExpr->op2;
@@ -54051,47 +54281,55 @@
54281 if( ALWAYS(pDef) && (pDef->flags & SQLITE_FUNC_EPHEM)!=0 ){
54282 sqlite3DbFree(db, pDef);
54283 }
54284 }
54285
54286 static void vdbeFreeOpArray(sqlite3 *, Op *, int);
54287
54288 /*
54289 ** Delete a P4 value if necessary.
54290 */
54291 static void freeP4(sqlite3 *db, int p4type, void *p4){
54292 if( p4 ){
54293 assert( db );
54294 switch( p4type ){
54295 case P4_REAL:
54296 case P4_INT64:
 
54297 case P4_DYNAMIC:
54298 case P4_KEYINFO:
54299 case P4_INTARRAY:
54300 case P4_KEYINFO_HANDOFF: {
54301 sqlite3DbFree(db, p4);
54302 break;
54303 }
54304 case P4_MPRINTF: {
54305 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
54306 break;
54307 }
54308 case P4_VDBEFUNC: {
54309 VdbeFunc *pVdbeFunc = (VdbeFunc *)p4;
54310 freeEphemeralFunction(db, pVdbeFunc->pFunc);
54311 if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
54312 sqlite3DbFree(db, pVdbeFunc);
54313 break;
54314 }
54315 case P4_FUNCDEF: {
54316 freeEphemeralFunction(db, (FuncDef*)p4);
54317 break;
54318 }
54319 case P4_MEM: {
54320 if( db->pnBytesFreed==0 ){
54321 sqlite3ValueFree((sqlite3_value*)p4);
54322 }else{
54323 Mem *p = (Mem*)p4;
54324 sqlite3DbFree(db, p->zMalloc);
54325 sqlite3DbFree(db, p);
54326 }
54327 break;
54328 }
54329 case P4_VTAB : {
54330 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
 
 
 
 
54331 break;
54332 }
54333 }
54334 }
54335 }
@@ -54113,38 +54351,18 @@
54351 }
54352 sqlite3DbFree(db, aOp);
54353 }
54354
54355 /*
54356 ** Link the SubProgram object passed as the second argument into the linked
54357 ** list at Vdbe.pSubProgram. This list is used to delete all sub-program
54358 ** objects when the VM is no longer required.
 
 
 
 
 
 
 
 
54359 */
54360 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *pVdbe, SubProgram *p){
54361 p->pNext = pVdbe->pProgram;
54362 pVdbe->pProgram = p;
54363 }
 
 
 
 
 
 
 
 
 
 
 
 
54364
54365 /*
54366 ** Change N opcodes starting at addr to No-ops.
54367 */
54368 SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe *p, int addr, int N){
@@ -54217,11 +54435,11 @@
54435 KeyInfo *pKeyInfo;
54436 int nField, nByte;
54437
54438 nField = ((KeyInfo*)zP4)->nField;
54439 nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
54440 pKeyInfo = sqlite3DbMallocRaw(0, nByte);
54441 pOp->p4.pKeyInfo = pKeyInfo;
54442 if( pKeyInfo ){
54443 u8 *aSortOrder;
54444 memcpy((char*)pKeyInfo, zP4, nByte - nField);
54445 aSortOrder = pKeyInfo->aSortOrder;
@@ -54481,10 +54699,16 @@
54699 static void releaseMemArray(Mem *p, int N){
54700 if( p && N ){
54701 Mem *pEnd;
54702 sqlite3 *db = p->db;
54703 u8 malloc_failed = db->mallocFailed;
54704 if( db->pnBytesFreed ){
54705 for(pEnd=&p[N]; p<pEnd; p++){
54706 sqlite3DbFree(db, p->zMalloc);
54707 }
54708 return;
54709 }
54710 for(pEnd=&p[N]; p<pEnd; p++){
54711 assert( (&p[1])==pEnd || p[0].db==p[1].db );
54712
54713 /* This block is really an inlined version of sqlite3VdbeMemRelease()
54714 ** that takes advantage of the fact that the memory cell value is
@@ -55130,26 +55354,27 @@
55354 ** be done before determining whether a master journal file is
55355 ** required, as an xSync() callback may add an attached database
55356 ** to the transaction.
55357 */
55358 rc = sqlite3VtabSync(db, &p->zErrMsg);
 
 
 
55359
55360 /* This loop determines (a) if the commit hook should be invoked and
55361 ** (b) how many database files have open write transactions, not
55362 ** including the temp database. (b) is important because if more than
55363 ** one database file has an open write transaction, a master journal
55364 ** file is required for an atomic commit.
55365 */
55366 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
55367 Btree *pBt = db->aDb[i].pBt;
55368 if( sqlite3BtreeIsInTrans(pBt) ){
55369 needXcommit = 1;
55370 if( i!=1 ) nTrans++;
55371 rc = sqlite3PagerExclusiveLock(sqlite3BtreePager(pBt));
55372 }
55373 }
55374 if( rc!=SQLITE_OK ){
55375 return rc;
55376 }
55377
55378 /* If there are any write-transactions at all, invoke the commit hook */
55379 if( needXcommit && db->xCommitCallback ){
55380 rc = db->xCommitCallback(db->pCommitArg);
@@ -55285,10 +55510,11 @@
55510 if( pBt ){
55511 rc = sqlite3BtreeCommitPhaseOne(pBt, zMaster);
55512 }
55513 }
55514 sqlite3OsCloseFree(pMaster);
55515 assert( rc!=SQLITE_BUSY );
55516 if( rc!=SQLITE_OK ){
55517 sqlite3DbFree(db, zMaster);
55518 return rc;
55519 }
55520
@@ -55812,10 +56038,34 @@
56038 }
56039 pAux->pAux = 0;
56040 }
56041 }
56042 }
56043
56044 /*
56045 ** Free all memory associated with the Vdbe passed as the second argument.
56046 ** The difference between this function and sqlite3VdbeDelete() is that
56047 ** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
56048 ** the database connection.
56049 */
56050 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3 *db, Vdbe *p){
56051 SubProgram *pSub, *pNext;
56052 assert( p->db==0 || p->db==db );
56053 releaseMemArray(p->aVar, p->nVar);
56054 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
56055 for(pSub=p->pProgram; pSub; pSub=pNext){
56056 pNext = pSub->pNext;
56057 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
56058 sqlite3DbFree(db, pSub);
56059 }
56060 vdbeFreeOpArray(db, p->aOp, p->nOp);
56061 sqlite3DbFree(db, p->aLabel);
56062 sqlite3DbFree(db, p->aColName);
56063 sqlite3DbFree(db, p->zSql);
56064 sqlite3DbFree(db, p->pFree);
56065 sqlite3DbFree(db, p);
56066 }
56067
56068 /*
56069 ** Delete an entire VDBE.
56070 */
56071 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){
@@ -55830,20 +56080,13 @@
56080 db->pVdbe = p->pNext;
56081 }
56082 if( p->pNext ){
56083 p->pNext->pPrev = p->pPrev;
56084 }
 
 
 
 
 
 
56085 p->magic = VDBE_MAGIC_DEAD;
 
56086 p->db = 0;
56087 sqlite3VdbeDeleteObject(db, p);
56088 }
56089
56090 /*
56091 ** Make sure the cursor p is ready to read or write the row to which it
56092 ** was last positioned. Return an error code if an OOM fault or I/O error
@@ -55865,15 +56108,12 @@
56108 #endif
56109 assert( p->isTable );
56110 rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
56111 if( rc ) return rc;
56112 p->lastRowid = p->movetoTarget;
56113 if( res!=0 ) return SQLITE_CORRUPT_BKPT;
56114 p->rowidIsValid = 1;
 
 
 
56115 #ifdef SQLITE_TEST
56116 sqlite3_search_count++;
56117 #endif
56118 p->deferredMoveto = 0;
56119 p->cacheStatus = CACHE_STALE;
@@ -57013,11 +57253,11 @@
57253 /* Invoke the profile callback if there is one
57254 */
57255 if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
57256 sqlite3_int64 iNow;
57257 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
57258 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
57259 }
57260 #endif
57261
57262 if( rc==SQLITE_DONE ){
57263 assert( p->rc==SQLITE_OK );
@@ -58628,10 +58868,24 @@
58868 for(p=db->pSavepoint; p; p=p->pNext) n++;
58869 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
58870 return 1;
58871 }
58872 #endif
58873
58874 /*
58875 ** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
58876 ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
58877 ** in memory obtained from sqlite3DbMalloc).
58878 */
58879 static void importVtabErrMsg(Vdbe *p, sqlite3_vtab *pVtab){
58880 sqlite3 *db = p->db;
58881 sqlite3DbFree(db, p->zErrMsg);
58882 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
58883 sqlite3_free(pVtab->zErrMsg);
58884 pVtab->zErrMsg = 0;
58885 }
58886
58887
58888 /*
58889 ** Execute as much of a VDBE program as we can then return.
58890 **
58891 ** sqlite3VdbeMakeReady() must be called before this routine in order to
@@ -62627,13 +62881,11 @@
62881 }else if( u.bi.pC->pVtabCursor ){
62882 u.bi.pVtab = u.bi.pC->pVtabCursor->pVtab;
62883 u.bi.pModule = u.bi.pVtab->pModule;
62884 assert( u.bi.pModule->xRowid );
62885 rc = u.bi.pModule->xRowid(u.bi.pC->pVtabCursor, &u.bi.v);
62886 importVtabErrMsg(p, u.bi.pVtab);
 
 
62887 #endif /* SQLITE_OMIT_VIRTUALTABLE */
62888 }else{
62889 assert( u.bi.pC->pCursor!=0 );
62890 rc = sqlite3VdbeCursorMoveto(u.bi.pC);
62891 if( rc ) goto abort_due_to_error;
@@ -64018,15 +64270,11 @@
64270 #if 0 /* local variables moved into u.cf */
64271 VTable *pVTab;
64272 #endif /* local variables moved into u.cf */
64273 u.cf.pVTab = pOp->p4.pVtab;
64274 rc = sqlite3VtabBegin(db, u.cf.pVTab);
64275 if( u.cf.pVTab ) importVtabErrMsg(p, u.cf.pVTab->pVtab);
 
 
 
 
64276 break;
64277 }
64278 #endif /* SQLITE_OMIT_VIRTUALTABLE */
64279
64280 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -64074,13 +64322,11 @@
64322 u.cg.pVtabCursor = 0;
64323 u.cg.pVtab = pOp->p4.pVtab->pVtab;
64324 u.cg.pModule = (sqlite3_module *)u.cg.pVtab->pModule;
64325 assert(u.cg.pVtab && u.cg.pModule);
64326 rc = u.cg.pModule->xOpen(u.cg.pVtab, &u.cg.pVtabCursor);
64327 importVtabErrMsg(p, u.cg.pVtab);
 
 
64328 if( SQLITE_OK==rc ){
64329 /* Initialize sqlite3_vtab_cursor base class */
64330 u.cg.pVtabCursor->pVtab = u.cg.pVtab;
64331
64332 /* Initialise vdbe cursor object */
@@ -64155,13 +64401,11 @@
64401 }
64402
64403 p->inVtabMethod = 1;
64404 rc = u.ch.pModule->xFilter(u.ch.pVtabCursor, u.ch.iQuery, pOp->p4.z, u.ch.nArg, u.ch.apArg);
64405 p->inVtabMethod = 0;
64406 importVtabErrMsg(p, u.ch.pVtab);
 
 
64407 if( rc==SQLITE_OK ){
64408 u.ch.res = u.ch.pModule->xEof(u.ch.pVtabCursor);
64409 }
64410
64411 if( u.ch.res ){
@@ -64209,13 +64453,11 @@
64453 */
64454 sqlite3VdbeMemMove(&u.ci.sContext.s, u.ci.pDest);
64455 MemSetTypeFlag(&u.ci.sContext.s, MEM_Null);
64456
64457 rc = u.ci.pModule->xColumn(pCur->pVtabCursor, &u.ci.sContext, pOp->p2);
64458 importVtabErrMsg(p, u.ci.pVtab);
 
 
64459 if( u.ci.sContext.isError ){
64460 rc = u.ci.sContext.isError;
64461 }
64462
64463 /* Copy the result of the function to the P3 register. We
@@ -64266,13 +64508,11 @@
64508 ** some other method is next invoked on the save virtual table cursor.
64509 */
64510 p->inVtabMethod = 1;
64511 rc = u.cj.pModule->xNext(u.cj.pCur->pVtabCursor);
64512 p->inVtabMethod = 0;
64513 importVtabErrMsg(p, u.cj.pVtab);
 
 
64514 if( rc==SQLITE_OK ){
64515 u.cj.res = u.cj.pModule->xEof(u.cj.pCur->pVtabCursor);
64516 }
64517
64518 if( !u.cj.res ){
@@ -64300,13 +64540,11 @@
64540 u.ck.pName = &aMem[pOp->p1];
64541 assert( u.ck.pVtab->pModule->xRename );
64542 REGISTER_TRACE(pOp->p1, u.ck.pName);
64543 assert( u.ck.pName->flags & MEM_Str );
64544 rc = u.ck.pVtab->pModule->xRename(u.ck.pVtab, u.ck.pName->z);
64545 importVtabErrMsg(p, u.ck.pVtab);
 
 
64546
64547 break;
64548 }
64549 #endif
64550
@@ -64356,13 +64594,11 @@
64594 sqlite3VdbeMemStoreType(u.cl.pX);
64595 u.cl.apArg[u.cl.i] = u.cl.pX;
64596 u.cl.pX++;
64597 }
64598 rc = u.cl.pModule->xUpdate(u.cl.pVtab, u.cl.nArg, u.cl.apArg, &u.cl.rowid);
64599 importVtabErrMsg(p, u.cl.pVtab);
 
 
64600 if( rc==SQLITE_OK && pOp->p1 ){
64601 assert( u.cl.nArg>1 && u.cl.apArg[0] && (u.cl.apArg[0]->flags&MEM_Null) );
64602 db->lastRowid = u.cl.rowid;
64603 }
64604 p->nChange++;
@@ -66811,30 +67047,37 @@
67047 assert( pExpr->pTab && j<pExpr->pTab->nCol );
67048 return pExpr->pTab->aCol[j].affinity;
67049 }
67050 return pExpr->affinity;
67051 }
67052
67053 /*
67054 ** Set the explicit collating sequence for an expression to the
67055 ** collating sequence supplied in the second argument.
67056 */
67057 SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr *pExpr, CollSeq *pColl){
67058 if( pExpr && pColl ){
67059 pExpr->pColl = pColl;
67060 pExpr->flags |= EP_ExpCollate;
67061 }
67062 return pExpr;
67063 }
67064
67065 /*
67066 ** Set the collating sequence for expression pExpr to be the collating
67067 ** sequence named by pToken. Return a pointer to the revised expression.
67068 ** The collating sequence is marked as "explicit" using the EP_ExpCollate
67069 ** flag. An explicit collating sequence will override implicit
67070 ** collating sequences.
67071 */
67072 SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr *pExpr, Token *pCollName){
67073 char *zColl = 0; /* Dequoted name of collation sequence */
67074 CollSeq *pColl;
67075 sqlite3 *db = pParse->db;
67076 zColl = sqlite3NameFromToken(db, pCollName);
67077 pColl = sqlite3LocateCollSeq(pParse, zColl);
67078 sqlite3ExprSetColl(pExpr, pColl);
 
 
 
 
 
67079 sqlite3DbFree(db, zColl);
67080 return pExpr;
67081 }
67082
67083 /*
@@ -68262,18 +68505,24 @@
68505
68506 if( eType==0 ){
68507 /* Could not found an existing table or index to use as the RHS b-tree.
68508 ** We will have to generate an ephemeral table to do the job.
68509 */
68510 double savedNQueryLoop = pParse->nQueryLoop;
68511 int rMayHaveNull = 0;
68512 eType = IN_INDEX_EPH;
68513 if( prNotFound ){
68514 *prNotFound = rMayHaveNull = ++pParse->nMem;
68515 }else{
68516 testcase( pParse->nQueryLoop>(double)1 );
68517 pParse->nQueryLoop = (double)1;
68518 if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
68519 eType = IN_INDEX_ROWID;
68520 }
68521 }
68522 sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
68523 pParse->nQueryLoop = savedNQueryLoop;
68524 }else{
68525 pX->iTable = iTab;
68526 }
68527 return eType;
68528 }
@@ -71302,11 +71551,10 @@
71551 */
71552 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
71553 if( !pNew ) goto exit_begin_add_column;
71554 pParse->pNewTable = pNew;
71555 pNew->nRef = 1;
 
71556 pNew->nCol = pTab->nCol;
71557 assert( pNew->nCol>0 );
71558 nAlloc = (((pNew->nCol-1)/8)*8)+8;
71559 assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
71560 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
@@ -71831,23 +72079,21 @@
72079
72080 /*
72081 ** If the Index.aSample variable is not NULL, delete the aSample[] array
72082 ** and its contents.
72083 */
72084 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
72085 #ifdef SQLITE_ENABLE_STAT2
72086 if( pIdx->aSample ){
72087 int j;
 
72088 for(j=0; j<SQLITE_INDEX_SAMPLES; j++){
72089 IndexSample *p = &pIdx->aSample[j];
72090 if( p->eType==SQLITE_TEXT || p->eType==SQLITE_BLOB ){
72091 sqlite3DbFree(db, p->u.z);
72092 }
72093 }
72094 sqlite3DbFree(db, pIdx->aSample);
 
72095 }
72096 #else
72097 UNUSED_PARAMETER(pIdx);
72098 #endif
72099 }
@@ -71884,11 +72130,12 @@
72130
72131 /* Clear any prior statistics */
72132 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
72133 Index *pIdx = sqliteHashData(i);
72134 sqlite3DefaultRowEst(pIdx);
72135 sqlite3DeleteIndexSamples(db, pIdx);
72136 pIdx->aSample = 0;
72137 }
72138
72139 /* Check to make sure the sqlite_stat1 table exists */
72140 sInfo.db = db;
72141 sInfo.zDatabase = db->aDb[iDb].zName;
@@ -71928,22 +72175,21 @@
72175 while( sqlite3_step(pStmt)==SQLITE_ROW ){
72176 char *zIndex = (char *)sqlite3_column_text(pStmt, 0);
72177 Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
72178 if( pIdx ){
72179 int iSample = sqlite3_column_int(pStmt, 1);
 
 
72180 if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
72181 int eType = sqlite3_column_type(pStmt, 2);
72182
72183 if( pIdx->aSample==0 ){
72184 static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
72185 pIdx->aSample = (IndexSample *)sqlite3DbMallocRaw(0, sz);
72186 if( pIdx->aSample==0 ){
72187 db->mallocFailed = 1;
72188 break;
72189 }
72190 memset(pIdx->aSample, 0, sz);
72191 }
72192
72193 assert( pIdx->aSample );
72194 {
72195 IndexSample *pSample = &pIdx->aSample[iSample];
@@ -71962,14 +72208,12 @@
72208 }
72209 pSample->nByte = (u8)n;
72210 if( n < 1){
72211 pSample->u.z = 0;
72212 }else{
72213 pSample->u.z = sqlite3DbStrNDup(0, z, n);
72214 if( pSample->u.z==0 ){
 
 
72215 db->mallocFailed = 1;
72216 break;
72217 }
72218 }
72219 }
@@ -73128,37 +73372,18 @@
73372 }
73373
73374 /*
73375 ** Reclaim the memory used by an index
73376 */
73377 static void freeIndex(sqlite3 *db, Index *p){
 
73378 #ifndef SQLITE_OMIT_ANALYZE
73379 sqlite3DeleteIndexSamples(db, p);
73380 #endif
73381 sqlite3DbFree(db, p->zColAff);
73382 sqlite3DbFree(db, p);
73383 }
73384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73385 /*
73386 ** For the index called zIdxName which is found in the database iDb,
73387 ** unlike that index from its Table then remove the index from
73388 ** the index hash table and free all memory structures associated
73389 ** with the index.
@@ -73181,11 +73406,11 @@
73406 while( ALWAYS(p) && p->pNext!=pIndex ){ p = p->pNext; }
73407 if( ALWAYS(p && p->pNext==pIndex) ){
73408 p->pNext = pIndex->pNext;
73409 }
73410 }
73411 freeIndex(db, pIndex);
73412 }
73413 db->flags |= SQLITE_InternChanges;
73414 }
73415
73416 /*
@@ -73252,17 +73477,16 @@
73477 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
73478 db->flags &= ~SQLITE_InternChanges;
73479 }
73480
73481 /*
73482 ** Delete memory allocated for the column names of a table or view (the
73483 ** Table.aCol[] array).
73484 */
73485 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
73486 int i;
73487 Column *pCol;
 
 
73488 assert( pTable!=0 );
73489 if( (pCol = pTable->aCol)!=0 ){
73490 for(i=0; i<pTable->nCol; i++, pCol++){
73491 sqlite3DbFree(db, pCol->zName);
73492 sqlite3ExprDelete(db, pCol->pDflt);
@@ -73270,12 +73494,10 @@
73494 sqlite3DbFree(db, pCol->zType);
73495 sqlite3DbFree(db, pCol->zColl);
73496 }
73497 sqlite3DbFree(db, pTable->aCol);
73498 }
 
 
73499 }
73500
73501 /*
73502 ** Remove the memory data structures associated with the given
73503 ** Table. No changes are made to disk by this routine.
@@ -73283,46 +73505,48 @@
73505 ** This routine just deletes the data structure. It does not unlink
73506 ** the table data structure from the hash table. But it does destroy
73507 ** memory structures of the indices and foreign keys associated with
73508 ** the table.
73509 */
73510 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
73511 Index *pIndex, *pNext;
 
73512
73513 assert( !pTable || pTable->nRef>0 );
 
 
73514
73515 /* Do not delete the table until the reference count reaches zero. */
73516 if( !pTable ) return;
73517 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
73518
73519 /* Delete all indices associated with this table. */
 
 
 
 
73520 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
73521 pNext = pIndex->pNext;
73522 assert( pIndex->pSchema==pTable->pSchema );
73523 if( !db || db->pnBytesFreed==0 ){
73524 char *zName = pIndex->zName;
73525 TESTONLY ( Index *pOld = ) sqlite3HashInsert(
73526 &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
73527 );
73528 assert( pOld==pIndex || pOld==0 );
73529 }
73530 freeIndex(db, pIndex);
73531 }
73532
73533 /* Delete any foreign keys attached to this table. */
73534 sqlite3FkDelete(db, pTable);
73535
73536 /* Delete the Table structure itself.
73537 */
73538 sqliteDeleteColumnNames(db, pTable);
73539 sqlite3DbFree(db, pTable->zName);
73540 sqlite3DbFree(db, pTable->zColAff);
73541 sqlite3SelectDelete(db, pTable->pSelect);
73542 #ifndef SQLITE_OMIT_CHECK
73543 sqlite3ExprDelete(db, pTable->pCheck);
73544 #endif
73545 #ifndef SQLITE_OMIT_VIRTUALTABLE
73546 sqlite3VtabClear(db, pTable);
73547 #endif
73548 sqlite3DbFree(db, pTable);
73549 }
73550
73551 /*
73552 ** Unlink the given table from the hash tables and the delete the
@@ -73337,11 +73561,11 @@
73561 assert( zTabName );
73562 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
73563 pDb = &db->aDb[iDb];
73564 p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
73565 sqlite3Strlen30(zTabName),0);
73566 sqlite3DeleteTable(db, p);
73567 db->flags |= SQLITE_InternChanges;
73568 }
73569
73570 /*
73571 ** Given a token, return a string that consists of the text of that
@@ -73605,11 +73829,10 @@
73829 }
73830 pTable->zName = zName;
73831 pTable->iPKey = -1;
73832 pTable->pSchema = db->aDb[iDb].pSchema;
73833 pTable->nRef = 1;
 
73834 assert( pParse->pNewTable==0 );
73835 pParse->pNewTable = pTable;
73836
73837 /* If this is the magic sqlite_sequence table used by autoincrement,
73838 ** then record a pointer to this table in the main database structure
@@ -74157,11 +74380,11 @@
74380 zSep = "\n ";
74381 zSep2 = ",\n ";
74382 zEnd = "\n)";
74383 }
74384 n += 35 + 6*p->nCol;
74385 zStmt = sqlite3DbMallocRaw(0, n);
74386 if( zStmt==0 ){
74387 db->mallocFailed = 1;
74388 return 0;
74389 }
74390 sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
@@ -74338,11 +74561,11 @@
74561 assert( p->aCol==0 );
74562 p->nCol = pSelTab->nCol;
74563 p->aCol = pSelTab->aCol;
74564 pSelTab->nCol = 0;
74565 pSelTab->aCol = 0;
74566 sqlite3DeleteTable(db, pSelTab);
74567 }
74568 }
74569
74570 /* Compute the complete text of the CREATE statement */
74571 if( pSelect ){
@@ -74582,11 +74805,11 @@
74805 assert( pTable->aCol==0 );
74806 pTable->nCol = pSelTab->nCol;
74807 pTable->aCol = pSelTab->aCol;
74808 pSelTab->nCol = 0;
74809 pSelTab->aCol = 0;
74810 sqlite3DeleteTable(db, pSelTab);
74811 pTable->pSchema->flags |= DB_UnresetViews;
74812 }else{
74813 pTable->nCol = 0;
74814 nErr++;
74815 }
@@ -74607,11 +74830,13 @@
74830 HashElem *i;
74831 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
74832 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
74833 Table *pTab = sqliteHashData(i);
74834 if( pTab->pSelect ){
74835 sqliteDeleteColumnNames(db, pTab);
74836 pTab->aCol = 0;
74837 pTab->nCol = 0;
74838 }
74839 }
74840 DbClearProperty(db, idx, DB_UnresetViews);
74841 }
74842 #else
@@ -75604,11 +75829,11 @@
75829 }
75830
75831 /* Clean up before exiting */
75832 exit_create_index:
75833 if( pIndex ){
75834 sqlite3DbFree(db, pIndex->zColAff);
75835 sqlite3DbFree(db, pIndex);
75836 }
75837 sqlite3ExprListDelete(db, pList);
75838 sqlite3SrcListDelete(db, pTblName);
75839 sqlite3DbFree(db, zName);
@@ -75983,11 +76208,11 @@
76208 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
76209 sqlite3DbFree(db, pItem->zDatabase);
76210 sqlite3DbFree(db, pItem->zName);
76211 sqlite3DbFree(db, pItem->zAlias);
76212 sqlite3DbFree(db, pItem->zIndex);
76213 sqlite3DeleteTable(db, pItem->pTab);
76214 sqlite3SelectDelete(db, pItem->pSelect);
76215 sqlite3ExprDelete(db, pItem->pOn);
76216 sqlite3IdListDelete(db, pItem->pUsing);
76217 }
76218 sqlite3DbFree(db, pList);
@@ -76914,12 +77139,11 @@
77139 }
77140 sqlite3HashClear(&temp2);
77141 sqlite3HashInit(&pSchema->tblHash);
77142 for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
77143 Table *pTab = sqliteHashData(pElem);
77144 sqlite3DeleteTable(0, pTab);
 
77145 }
77146 sqlite3HashClear(&temp1);
77147 sqlite3HashClear(&pSchema->fkeyHash);
77148 pSchema->pSeqTab = 0;
77149 pSchema->flags &= ~DB_SchemaLoaded;
@@ -76932,11 +77156,11 @@
77156 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
77157 Schema * p;
77158 if( pBt ){
77159 p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree);
77160 }else{
77161 p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
77162 }
77163 if( !p ){
77164 db->mallocFailed = 1;
77165 }else if ( 0==p->file_format ){
77166 sqlite3HashInit(&p->tblHash);
@@ -76973,11 +77197,11 @@
77197 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
77198 struct SrcList_item *pItem = pSrc->a;
77199 Table *pTab;
77200 assert( pItem && pSrc->nSrc==1 );
77201 pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase);
77202 sqlite3DeleteTable(pParse->db, pItem->pTab);
77203 pItem->pTab = pTab;
77204 if( pTab ){
77205 pTab->nRef++;
77206 }
77207 if( sqlite3IndexedByLookup(pParse, pItem) ){
@@ -78370,12 +78594,14 @@
78594 sqlite3_value **argv
78595 ){
78596 const char *zOptName;
78597 assert( argc==1 );
78598 UNUSED_PARAMETER(argc);
78599 /* IMP: R-39564-36305 The sqlite_compileoption_used() SQL
78600 ** function is a wrapper around the sqlite3_compileoption_used() C/C++
78601 ** function.
78602 */
78603 if( (zOptName = (const char*)sqlite3_value_text(argv[0]))!=0 ){
78604 sqlite3_result_int(context, sqlite3_compileoption_used(zOptName));
78605 }
78606 }
78607 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
@@ -78392,12 +78618,13 @@
78618 sqlite3_value **argv
78619 ){
78620 int n;
78621 assert( argc==1 );
78622 UNUSED_PARAMETER(argc);
78623 /* IMP: R-04922-24076 The sqlite_compileoption_get() SQL function
78624 ** is a wrapper around the sqlite3_compileoption_get() C/C++ function.
78625 */
78626 n = sqlite3_value_int(argv[0]);
78627 sqlite3_result_text(context, sqlite3_compileoption_get(n), -1, SQLITE_STATIC);
78628 }
78629 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
78630
@@ -78592,18 +78819,18 @@
78819 nOut += nRep - nPattern;
78820 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
78821 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
78822 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
78823 sqlite3_result_error_toobig(context);
78824 sqlite3_free(zOut);
78825 return;
78826 }
78827 zOld = zOut;
78828 zOut = sqlite3_realloc(zOut, (int)nOut);
78829 if( zOut==0 ){
78830 sqlite3_result_error_nomem(context);
78831 sqlite3_free(zOld);
78832 return;
78833 }
78834 memcpy(&zOut[j], zRep, nRep);
78835 j += nRep;
78836 i += nPattern-1;
@@ -78960,11 +79187,11 @@
79187 pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
79188
79189 if( pAccum ){
79190 sqlite3 *db = sqlite3_context_db_handle(context);
79191 int firstTerm = pAccum->useMalloc==0;
79192 pAccum->useMalloc = 2;
79193 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
79194 if( !firstTerm ){
79195 if( argc==2 ){
79196 zSep = (char*)sqlite3_value_text(argv[1]);
79197 nSep = sqlite3_value_bytes(argv[1]);
@@ -79677,11 +79904,12 @@
79904 /* Set the collation sequence and affinity of the LHS of each TK_EQ
79905 ** expression to the parent key column defaults. */
79906 if( pIdx ){
79907 Column *pCol;
79908 iCol = pIdx->aiColumn[i];
79909 pCol = &pTab->aCol[iCol];
79910 if( pTab->iPKey==iCol ) iCol = -1;
79911 pLeft->iTable = regData+iCol+1;
79912 pLeft->affinity = pCol->affinity;
79913 pLeft->pColl = sqlite3LocateCollSeq(pParse, pCol->zColl);
79914 }else{
79915 pLeft->iTable = regData;
@@ -80238,15 +80466,11 @@
80466 0, 0, 0, 0, 0, 0
80467 );
80468 pWhere = 0;
80469 }
80470
80471 /* Disable lookaside memory allocation */
 
 
 
 
80472 enableLookaside = db->lookaside.bEnabled;
80473 db->lookaside.bEnabled = 0;
80474
80475 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
80476 sizeof(Trigger) + /* struct Trigger */
@@ -80332,41 +80556,43 @@
80556 /*
80557 ** Free all memory associated with foreign key definitions attached to
80558 ** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
80559 ** hash table.
80560 */
80561 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
80562 FKey *pFKey; /* Iterator variable */
80563 FKey *pNext; /* Copy of pFKey->pNextFrom */
80564
80565 for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
80566
80567 /* Remove the FK from the fkeyHash hash table. */
80568 if( !db || db->pnBytesFreed==0 ){
80569 if( pFKey->pPrevTo ){
80570 pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
80571 }else{
80572 void *p = (void *)pFKey->pNextTo;
80573 const char *z = (p ? pFKey->pNextTo->zTo : pFKey->zTo);
80574 sqlite3HashInsert(&pTab->pSchema->fkeyHash, z, sqlite3Strlen30(z), p);
80575 }
80576 if( pFKey->pNextTo ){
80577 pFKey->pNextTo->pPrevTo = pFKey->pPrevTo;
80578 }
80579 }
 
 
 
 
80580
80581 /* EV: R-30323-21917 Each foreign key constraint in SQLite is
80582 ** classified as either immediate or deferred.
80583 */
80584 assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 );
80585
80586 /* Delete any triggers created to implement actions for this FK. */
80587 #ifndef SQLITE_OMIT_TRIGGER
80588 fkTriggerDelete(db, pFKey->apTrigger[0]);
80589 fkTriggerDelete(db, pFKey->apTrigger[1]);
80590 #endif
80591
80592 pNext = pFKey->pNextFrom;
80593 sqlite3DbFree(db, pFKey);
80594 }
80595 }
80596 #endif /* ifndef SQLITE_OMIT_FOREIGN_KEY */
80597
80598 /************** End of fkey.c ************************************************/
@@ -80437,11 +80663,11 @@
80663 ** up.
80664 */
80665 int n;
80666 Table *pTab = pIdx->pTable;
80667 sqlite3 *db = sqlite3VdbeDb(v);
80668 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+2);
80669 if( !pIdx->zColAff ){
80670 db->mallocFailed = 1;
80671 return 0;
80672 }
80673 for(n=0; n<pIdx->nColumn; n++){
@@ -80479,11 +80705,11 @@
80705 if( !pTab->zColAff ){
80706 char *zColAff;
80707 int i;
80708 sqlite3 *db = sqlite3VdbeDb(v);
80709
80710 zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
80711 if( !zColAff ){
80712 db->mallocFailed = 1;
80713 return;
80714 }
80715
@@ -81590,10 +81816,11 @@
81816 sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, SQLITE_JUMPIFNULL);
81817 onError = overrideError!=OE_Default ? overrideError : OE_Abort;
81818 if( onError==OE_Ignore ){
81819 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
81820 }else{
81821 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
81822 sqlite3HaltConstraint(pParse, onError, 0, 0);
81823 }
81824 sqlite3VdbeResolveLabel(v, allOk);
81825 }
81826 #endif /* !defined(SQLITE_OMIT_CHECK) */
@@ -83104,32 +83331,28 @@
83331 }
83332
83333 handle = sqlite3OsDlOpen(pVfs, zFile);
83334 if( handle==0 ){
83335 if( pzErrMsg ){
83336 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
83337 if( zErrmsg ){
83338 sqlite3_snprintf(nMsg, zErrmsg,
83339 "unable to open shared library [%s]", zFile);
83340 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
 
 
83341 }
83342 }
83343 return SQLITE_ERROR;
83344 }
83345 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
83346 sqlite3OsDlSym(pVfs, handle, zProc);
83347 if( xInit==0 ){
83348 if( pzErrMsg ){
83349 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
83350 if( zErrmsg ){
83351 sqlite3_snprintf(nMsg, zErrmsg,
83352 "no entry point [%s] in shared library [%s]", zProc,zFile);
83353 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
 
 
83354 }
83355 sqlite3OsDlClose(pVfs, handle);
83356 }
83357 return SQLITE_ERROR;
83358 }else if( xInit(db, &zErrmsg, &sqlite3Apis) ){
@@ -84104,11 +84327,11 @@
84327 ){
84328 invalidateTempStorage(pParse);
84329 }
84330 sqlite3_free(sqlite3_temp_directory);
84331 if( zRight[0] ){
84332 sqlite3_temp_directory = sqlite3_mprintf("%s", zRight);
84333 }else{
84334 sqlite3_temp_directory = 0;
84335 }
84336 #endif /* SQLITE_OMIT_WSD */
84337 }
@@ -85525,11 +85748,10 @@
85748
85749 /* Delete any TriggerPrg structures allocated while parsing this statement. */
85750 while( pParse->pTriggerPrg ){
85751 TriggerPrg *pT = pParse->pTriggerPrg;
85752 pParse->pTriggerPrg = pT->pNext;
 
85753 sqlite3DbFree(db, pT);
85754 }
85755
85756 end_prepare:
85757
@@ -87016,20 +87238,19 @@
87238 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
87239 if( pTab==0 ){
87240 return 0;
87241 }
87242 /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
87243 ** is disabled */
87244 assert( db->lookaside.bEnabled==0 );
 
87245 pTab->nRef = 1;
87246 pTab->zName = 0;
87247 selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
87248 selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect);
87249 pTab->iPKey = -1;
87250 if( db->mallocFailed ){
87251 sqlite3DeleteTable(db, pTab);
87252 return 0;
87253 }
87254 return pTab;
87255 }
87256
@@ -88814,11 +89035,10 @@
89035 assert( pSel!=0 );
89036 assert( pFrom->pTab==0 );
89037 sqlite3WalkSelect(pWalker, pSel);
89038 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
89039 if( pTab==0 ) return WRC_Abort;
 
89040 pTab->nRef = 1;
89041 pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
89042 while( pSel->pPrior ){ pSel = pSel->pPrior; }
89043 selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
89044 pTab->iPKey = -1;
@@ -91028,10 +91248,11 @@
91248 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
91249 Parse *pSubParse; /* Parse context for sub-vdbe */
91250 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
91251
91252 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
91253 assert( pTop->pVdbe );
91254
91255 /* Allocate the TriggerPrg and SubProgram objects. To ensure that they
91256 ** are freed if an error occurs, link them into the Parse.pTriggerPrg
91257 ** list of the top-level Parse object sooner rather than later. */
91258 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
@@ -91038,11 +91259,11 @@
91259 if( !pPrg ) return 0;
91260 pPrg->pNext = pTop->pTriggerPrg;
91261 pTop->pTriggerPrg = pPrg;
91262 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
91263 if( !pProgram ) return 0;
91264 sqlite3VdbeLinkSubProgram(pTop->pVdbe, pProgram);
91265 pPrg->pTrigger = pTrigger;
91266 pPrg->orconf = orconf;
91267 pPrg->aColmask[0] = 0xffffffff;
91268 pPrg->aColmask[1] = 0xffffffff;
91269
@@ -91172,22 +91393,23 @@
91393 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
91394
91395 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
91396 ** is a pointer to the sub-vdbe containing the trigger program. */
91397 if( pPrg ){
91398 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
91399
91400 sqlite3VdbeAddOp3(v, OP_Program, reg, ignoreJump, ++pParse->nMem);
 
91401 sqlite3VdbeChangeP4(v, -1, (const char *)pPrg->pProgram, P4_SUBPROGRAM);
91402 VdbeComment(
91403 (v, "Call: %s.%s", (p->zName?p->zName:"fkey"), onErrorText(orconf)));
91404
91405 /* Set the P5 operand of the OP_Program instruction to non-zero if
91406 ** recursive invocation of this trigger program is disallowed. Recursive
91407 ** invocation is disallowed if (a) the sub-program is really a trigger,
91408 ** not a foreign key action, and (b) the flag to enable recursive triggers
91409 ** is clear. */
91410 sqlite3VdbeChangeP5(v, (u8)bRecursive);
91411 }
91412 }
91413
91414 /*
91415 ** This is called to code the required FOR EACH ROW triggers for an operation
@@ -91332,11 +91554,11 @@
91554 **
91555 ** May you do good and not evil.
91556 ** May you find forgiveness for yourself and forgive others.
91557 ** May you share freely, never taking more than you give.
91558 **
91559 *************************************************************************
91560 ** This file contains C code routines that are called by the parser
91561 ** to handle UPDATE statements.
91562 */
91563
91564 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -92551,18 +92773,18 @@
92773 ** connection db is decremented immediately (which may lead to the
92774 ** structure being xDisconnected and free). Any other VTable structures
92775 ** in the list are moved to the sqlite3.pDisconnect list of the associated
92776 ** database connection.
92777 */
92778 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
92779 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
92780 if( p->azModuleArg ){
92781 int i;
92782 for(i=0; i<p->nModuleArg; i++){
92783 sqlite3DbFree(db, p->azModuleArg[i]);
92784 }
92785 sqlite3DbFree(db, p->azModuleArg);
92786 }
92787 }
92788
92789 /*
92790 ** Add a new module argument to pTable->azModuleArg[].
@@ -92723,11 +92945,10 @@
92945 if( pOld ){
92946 db->mallocFailed = 1;
92947 assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
92948 return;
92949 }
 
92950 pParse->pNewTable = 0;
92951 }
92952 }
92953
92954 /*
@@ -92797,11 +93018,11 @@
93018 if( SQLITE_OK!=rc ){
93019 if( zErr==0 ){
93020 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
93021 }else {
93022 *pzErr = sqlite3MPrintf(db, "%s", zErr);
93023 sqlite3_free(zErr);
93024 }
93025 sqlite3DbFree(db, pVTable);
93026 }else if( ALWAYS(pVTable->pVtab) ){
93027 /* Justification of ALWAYS(): A correct vtab constructor must allocate
93028 ** the sqlite3_vtab object if successful. */
@@ -93004,19 +93225,19 @@
93225 pParse->pNewTable->aCol = 0;
93226 }
93227 db->pVTab = 0;
93228 }else{
93229 sqlite3Error(db, SQLITE_ERROR, zErr);
93230 sqlite3_free(zErr);
93231 rc = SQLITE_ERROR;
93232 }
93233 pParse->declareVtab = 0;
93234
93235 if( pParse->pVdbe ){
93236 sqlite3VdbeFinalize(pParse->pVdbe);
93237 }
93238 sqlite3DeleteTable(db, pParse->pNewTable);
93239 sqlite3StackFree(db, pParse);
93240 }
93241
93242 assert( (rc&0xff)==rc );
93243 rc = sqlite3ApiExit(db, rc);
@@ -93099,12 +93320,12 @@
93320 int (*x)(sqlite3_vtab *);
93321 sqlite3_vtab *pVtab = aVTrans[i]->pVtab;
93322 if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
93323 rc = x(pVtab);
93324 sqlite3DbFree(db, *pzErrmsg);
93325 *pzErrmsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
93326 sqlite3_free(pVtab->zErrMsg);
93327 }
93328 }
93329 db->aVTrans = aVTrans;
93330 return rc;
93331 }
@@ -93600,10 +93821,11 @@
93821 ** the pWC->a[] array.
93822 */
93823 static int whereClauseInsert(WhereClause *pWC, Expr *p, u8 wtFlags){
93824 WhereTerm *pTerm;
93825 int idx;
93826 testcase( wtFlags & TERM_VIRTUAL ); /* EV: R-00211-15100 */
93827 if( pWC->nTerm>=pWC->nSlot ){
93828 WhereTerm *pOld = pWC->a;
93829 sqlite3 *db = pWC->pParse->db;
93830 pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
93831 if( pWC->a==0 ){
@@ -93745,10 +93967,17 @@
93967
93968 /*
93969 ** Return TRUE if the given operator is one of the operators that is
93970 ** allowed for an indexable WHERE clause term. The allowed operators are
93971 ** "=", "<", ">", "<=", ">=", and "IN".
93972 **
93973 ** IMPLEMENTATION-OF: R-59926-26393 To be usable by an index a term must be
93974 ** of one of the following forms: column = expression column > expression
93975 ** column >= expression column < expression column <= expression
93976 ** expression = column expression > column expression >= column
93977 ** expression < column expression <= column column IN
93978 ** (expression-list) column IN (subquery) column IS NULL
93979 */
93980 static int allowedOp(int op){
93981 assert( TK_GT>TK_EQ && TK_GT<TK_GE );
93982 assert( TK_LT>TK_EQ && TK_LT<TK_GE );
93983 assert( TK_LE>TK_EQ && TK_LE<TK_GE );
@@ -93908,11 +94137,10 @@
94137 Expr *pRight, *pLeft; /* Right and left size of LIKE operator */
94138 ExprList *pList; /* List of operands to the LIKE operator */
94139 int c; /* One character in z[] */
94140 int cnt; /* Number of non-wildcard prefix characters */
94141 char wc[3]; /* Wildcard characters */
 
94142 sqlite3 *db = pParse->db; /* Database connection */
94143 sqlite3_value *pVal = 0;
94144 int op; /* Opcode of pRight */
94145
94146 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
@@ -93927,23 +94155,10 @@
94155 /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
94156 ** be the name of an indexed column with TEXT affinity. */
94157 return 0;
94158 }
94159 assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
 
 
 
 
 
 
 
 
 
 
 
 
 
94160
94161 pRight = pList->a[0].pExpr;
94162 op = pRight->op;
94163 if( op==TK_REGISTER ){
94164 op = pRight->op2;
@@ -93962,13 +94177,13 @@
94177 if( z ){
94178 cnt = 0;
94179 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
94180 cnt++;
94181 }
94182 if( cnt!=0 && 255!=(u8)z[cnt-1] ){
94183 Expr *pPrefix;
94184 *pisComplete = c==wc[0] && z[cnt+1]==0;
94185 pPrefix = sqlite3Expr(db, TK_STRING, z);
94186 if( pPrefix ) pPrefix->u.zToken[cnt] = 0;
94187 *ppPrefix = pPrefix;
94188 if( op==TK_VARIABLE ){
94189 Vdbe *v = pParse->pVdbe;
@@ -94303,10 +94518,12 @@
94518 }
94519
94520 /* At this point, okToChngToIN is true if original pTerm satisfies
94521 ** case 1. In that case, construct a new virtual term that is
94522 ** pTerm converted into an IN operator.
94523 **
94524 ** EV: R-00211-15100
94525 */
94526 if( okToChngToIN ){
94527 Expr *pDup; /* A transient duplicate expression */
94528 ExprList *pList = 0; /* The RHS of the IN operator */
94529 Expr *pLeft = 0; /* The LHS of the IN operator */
@@ -94519,10 +94736,11 @@
94736 Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */
94737 Expr *pNewExpr1;
94738 Expr *pNewExpr2;
94739 int idxNew1;
94740 int idxNew2;
94741 CollSeq *pColl; /* Collating sequence to use */
94742
94743 pLeft = pExpr->x.pList->a[1].pExpr;
94744 pStr2 = sqlite3ExprDup(db, pStr1, 0);
94745 if( !db->mallocFailed ){
94746 u8 c, *pC; /* Last character before the first wildcard */
@@ -94533,21 +94751,27 @@
94751 ** wildcard. But if we increment '@', that will push it into the
94752 ** alphabetic range where case conversions will mess up the
94753 ** inequality. To avoid this, make sure to also run the full
94754 ** LIKE on all candidate expressions by clearing the isComplete flag
94755 */
94756 if( c=='A'-1 ) isComplete = 0; /* EV: R-64339-08207 */
94757
94758
94759 c = sqlite3UpperToLower[c];
94760 }
94761 *pC = c + 1;
94762 }
94763 pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, noCase ? "NOCASE" : "BINARY",0);
94764 pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
94765 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
94766 pStr1, 0);
94767 idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC);
94768 testcase( idxNew1==0 );
94769 exprAnalyze(pSrc, pWC, idxNew1);
94770 pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
94771 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
94772 pStr2, 0);
94773 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
94774 testcase( idxNew2==0 );
94775 exprAnalyze(pSrc, pWC, idxNew2);
94776 pTerm = &pWC->a[idxTerm];
94777 if( isComplete ){
@@ -95295,11 +95519,11 @@
95519 sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
95520 }else{
95521 sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg);
95522 }
95523 }
95524 sqlite3_free(pVtab->zErrMsg);
95525 pVtab->zErrMsg = 0;
95526
95527 for(i=0; i<p->nConstraint; i++){
95528 if( !p->aConstraint[i].usable && p->aConstraintUsage[i].argvIndex>0 ){
95529 sqlite3ErrorMsg(pParse,
@@ -96159,10 +96383,13 @@
96383 ** (3) SELECT * FROM t1, t2 WHERE t1.a=t2.x AND t2.z='ok'
96384 **
96385 ** The t2.z='ok' is disabled in the in (2) because it originates
96386 ** in the ON clause. The term is disabled in (3) because it is not part
96387 ** of a LEFT OUTER JOIN. In (1), the term is not disabled.
96388 **
96389 ** IMPLEMENTATION-OF: R-24597-58655 No tests are done for terms that are
96390 ** completely satisfied by indices.
96391 **
96392 ** Disabling a term causes that term to not be tested in the inner loop
96393 ** of the join. Disabling is an optimization. When terms are satisfied
96394 ** by indices, we disable them to prevent redundant tests in the inner
96395 ** loop. We would get the correct results if nothing were ever disabled,
@@ -96371,10 +96598,11 @@
96598 pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx);
96599 if( NEVER(pTerm==0) ) break;
96600 /* The following true for indices with redundant columns.
96601 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
96602 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
96603 testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
96604 r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
96605 if( r1!=regBase+j ){
96606 if( nReg==1 ){
96607 sqlite3ReleaseTempReg(pParse, regBase);
96608 regBase = r1;
@@ -96514,10 +96742,11 @@
96742 pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
96743 assert( pTerm!=0 );
96744 assert( pTerm->pExpr!=0 );
96745 assert( pTerm->leftCursor==iCur );
96746 assert( omitTable==0 );
96747 testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
96748 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, iReleaseReg);
96749 addrNxt = pLevel->addrNxt;
96750 sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
96751 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
96752 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
@@ -96554,10 +96783,11 @@
96783 };
96784 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
96785 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
96786 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
96787
96788 testcase( pStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
96789 pX = pStart->pExpr;
96790 assert( pX!=0 );
96791 assert( pStart->leftCursor==iCur );
96792 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
96793 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
@@ -96571,10 +96801,11 @@
96801 if( pEnd ){
96802 Expr *pX;
96803 pX = pEnd->pExpr;
96804 assert( pX!=0 );
96805 assert( pEnd->leftCursor==iCur );
96806 testcase( pEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
96807 memEndValue = ++pParse->nMem;
96808 sqlite3ExprCode(pParse, pX->pRight, memEndValue);
96809 if( pX->op==TK_LT || pX->op==TK_GT ){
96810 testOp = bRev ? OP_Le : OP_Ge;
96811 }else{
@@ -96738,10 +96969,11 @@
96969 if( sqlite3ExprNeedsNoAffinityChange(pRight, zStartAff[nEq]) ){
96970 zStartAff[nEq] = SQLITE_AFF_NONE;
96971 }
96972 }
96973 nConstraint++;
96974 testcase( pRangeStart->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
96975 }else if( isMinQuery ){
96976 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
96977 nConstraint++;
96978 startEq = 0;
96979 start_constraints = 1;
@@ -96777,10 +97009,11 @@
97009 zEndAff[nEq] = SQLITE_AFF_NONE;
97010 }
97011 }
97012 codeApplyAffinity(pParse, regBase, nEq+1, zEndAff);
97013 nConstraint++;
97014 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
97015 }
97016 sqlite3DbFree(pParse->db, zStartAff);
97017 sqlite3DbFree(pParse->db, zEndAff);
97018
97019 /* Top of the loop body */
@@ -96983,15 +97216,19 @@
97216 }
97217 notReady &= ~getMask(pWC->pMaskSet, iCur);
97218
97219 /* Insert code to test every subexpression that can be completely
97220 ** computed using the current set of tables.
97221 **
97222 ** IMPLEMENTATION-OF: R-49525-50935 Terms that cannot be satisfied through
97223 ** the use of indices become tests that are evaluated against each row of
97224 ** the relevant input tables.
97225 */
97226 k = 0;
97227 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
97228 Expr *pE;
97229 testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */
97230 testcase( pTerm->wtFlags & TERM_CODED );
97231 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
97232 if( (pTerm->prereqAll & notReady)!=0 ){
97233 testcase( pWInfo->untestedTerms==0
97234 && (pWInfo->wctrlFlags & WHERE_ONETABLE_ONLY)!=0 );
@@ -97015,11 +97252,11 @@
97252 pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
97253 sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
97254 VdbeComment((v, "record LEFT JOIN hit"));
97255 sqlite3ExprCacheClear(pParse);
97256 for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
97257 testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */
97258 testcase( pTerm->wtFlags & TERM_CODED );
97259 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
97260 if( (pTerm->prereqAll & notReady)!=0 ){
97261 assert( pWInfo->untestedTerms );
97262 continue;
@@ -97233,11 +97470,11 @@
97470 ** subexpression is separated by an AND operator.
97471 */
97472 initMaskSet(pMaskSet);
97473 whereClauseInit(pWC, pParse, pMaskSet);
97474 sqlite3ExprCodeConstants(pParse, pWhere);
97475 whereSplit(pWC, pWhere, TK_AND); /* IMP: R-15842-53296 */
97476
97477 /* Special case: a WHERE clause that is constant. Evaluate the
97478 ** expression and either jump over all of the code or fall thru.
97479 */
97480 if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
@@ -97321,10 +97558,12 @@
97558 Index *pIdx; /* Index for FROM table at pTabItem */
97559 int j; /* For looping over FROM tables */
97560 int bestJ = -1; /* The value of j */
97561 Bitmask m; /* Bitmask value for j or bestJ */
97562 int isOptimal; /* Iterator for optimal/non-optimal search */
97563 int nUnconstrained; /* Number tables without INDEXED BY */
97564 Bitmask notIndexed; /* Mask of tables that cannot use an index */
97565
97566 memset(&bestPlan, 0, sizeof(bestPlan));
97567 bestPlan.rCost = SQLITE_BIG_DBL;
97568
97569 /* Loop through the remaining entries in the FROM clause to find the
@@ -97362,12 +97601,14 @@
97601 ** However, since the cost of a linear scan through table t2 is the same
97602 ** as the cost of a linear scan through table t1, a simple greedy
97603 ** algorithm may choose to use t2 for the outer loop, which is a much
97604 ** costlier approach.
97605 */
97606 nUnconstrained = 0;
97607 notIndexed = 0;
97608 for(isOptimal=(iFrom<nTabList-1); isOptimal>=0; isOptimal--){
97609 Bitmask mask; /* Mask of tables not yet ready */
97610 for(j=iFrom, pTabItem=&pTabList->a[j]; j<nTabList; j++, pTabItem++){
97611 int doNotReorder; /* True if this table should not be reordered */
97612 WhereCost sCost; /* Cost information from best[Virtual]Index() */
97613 ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
97614
@@ -97378,10 +97619,11 @@
97619 if( j==iFrom ) iFrom++;
97620 continue;
97621 }
97622 mask = (isOptimal ? m : notReady);
97623 pOrderBy = ((i==0 && ppOrderBy )?*ppOrderBy:0);
97624 if( pTabItem->pIndex==0 ) nUnconstrained++;
97625
97626 assert( pTabItem->pTab );
97627 #ifndef SQLITE_OMIT_VIRTUALTABLE
97628 if( IsVirtual(pTabItem->pTab) ){
97629 sqlite3_index_info **pp = &pWInfo->a[j].pIdxInfo;
@@ -97391,13 +97633,47 @@
97633 {
97634 bestBtreeIndex(pParse, pWC, pTabItem, mask, pOrderBy, &sCost);
97635 }
97636 assert( isOptimal || (sCost.used&notReady)==0 );
97637
97638 /* If an INDEXED BY clause is present, then the plan must use that
97639 ** index if it uses any index at all */
97640 assert( pTabItem->pIndex==0
97641 || (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)==0
97642 || sCost.plan.u.pIdx==pTabItem->pIndex );
97643
97644 if( isOptimal && (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 ){
97645 notIndexed |= m;
97646 }
97647
97648 /* Conditions under which this table becomes the best so far:
97649 **
97650 ** (1) The table must not depend on other tables that have not
97651 ** yet run.
97652 **
97653 ** (2) A full-table-scan plan cannot supercede another plan unless
97654 ** it is an "optimal" plan as defined above.
97655 **
97656 ** (3) All tables have an INDEXED BY clause or this table lacks an
97657 ** INDEXED BY clause or this table uses the specific
97658 ** index specified by its INDEXED BY clause. This rule ensures
97659 ** that a best-so-far is always selected even if an impossible
97660 ** combination of INDEXED BY clauses are given. The error
97661 ** will be detected and relayed back to the application later.
97662 ** The NEVER() comes about because rule (2) above prevents
97663 ** An indexable full-table-scan from reaching rule (3).
97664 **
97665 ** (4) The plan cost must be lower than prior plans or else the
97666 ** cost must be the same and the number of rows must be lower.
97667 */
97668 if( (sCost.used&notReady)==0 /* (1) */
97669 && (bestJ<0 || (notIndexed&m)!=0 /* (2) */
97670 || (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)
97671 && (nUnconstrained==0 || pTabItem->pIndex==0 /* (3) */
97672 || NEVER((sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0))
97673 && (bestJ<0 || sCost.rCost<bestPlan.rCost /* (4) */
97674 || (sCost.rCost<=bestPlan.rCost && sCost.nRow<bestPlan.nRow))
97675 ){
97676 WHERETRACE(("... best so far with cost=%g and nRow=%g\n",
97677 sCost.rCost, sCost.nRow));
97678 bestPlan = sCost;
97679 bestJ = j;
@@ -100408,11 +100684,11 @@
100684 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
100685 }
100686 break;
100687 case 195: /* expr ::= expr COLLATE ids */
100688 {
100689 yygotominor.yy118.pExpr = sqlite3ExprSetCollByToken(pParse, yymsp[-2].minor.yy118.pExpr, &yymsp[0].minor.yy0);
100690 yygotominor.yy118.zStart = yymsp[-2].minor.yy118.zStart;
100691 yygotominor.yy118.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
100692 }
100693 break;
100694 case 196: /* expr ::= CAST LP expr AS typetoken RP */
@@ -100664,11 +100940,11 @@
100940 case 248: /* idxlist ::= idxlist COMMA nm collate sortorder */
100941 {
100942 Expr *p = 0;
100943 if( yymsp[-1].minor.yy0.n>0 ){
100944 p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
100945 sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
100946 }
100947 yygotominor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, p);
100948 sqlite3ExprListSetName(pParse,yygotominor.yy322,&yymsp[-2].minor.yy0,1);
100949 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
100950 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
@@ -100677,11 +100953,11 @@
100953 case 249: /* idxlist ::= nm collate sortorder */
100954 {
100955 Expr *p = 0;
100956 if( yymsp[-1].minor.yy0.n>0 ){
100957 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
100958 sqlite3ExprSetCollByToken(pParse, p, &yymsp[-1].minor.yy0);
100959 }
100960 yygotominor.yy322 = sqlite3ExprListAppend(pParse,0, p);
100961 sqlite3ExprListSetName(pParse, yygotominor.yy322, &yymsp[-2].minor.yy0, 1);
100962 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
100963 if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy4;
@@ -101957,19 +102233,19 @@
102233 pParse->aTableLock = 0;
102234 pParse->nTableLock = 0;
102235 }
102236 #endif
102237 #ifndef SQLITE_OMIT_VIRTUALTABLE
102238 sqlite3_free(pParse->apVtabLock);
102239 #endif
102240
102241 if( !IN_DECLARE_VTAB ){
102242 /* If the pParse->declareVtab flag is set, do not delete any table
102243 ** structure built up in pParse->pNewTable. The calling code (see vtab.c)
102244 ** will take responsibility for freeing the Table structure.
102245 */
102246 sqlite3DeleteTable(db, pParse->pNewTable);
102247 }
102248
102249 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
102250 sqlite3DbFree(db, pParse->apVarExpr);
102251 sqlite3DbFree(db, pParse->aAlias);
@@ -101979,11 +102255,11 @@
102255 sqlite3DbFree(db, p);
102256 }
102257 while( pParse->pZombieTab ){
102258 Table *p = pParse->pZombieTab;
102259 pParse->pZombieTab = p->pNextZombie;
102260 sqlite3DeleteTable(db, p);
102261 }
102262 if( nErr>0 && pParse->rc==SQLITE_OK ){
102263 pParse->rc = SQLITE_ERROR;
102264 }
102265 return nErr;
@@ -103671,20 +103947,11 @@
103947
103948 assert( sqlite3_mutex_held(db->mutex) );
103949
103950 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
103951 if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){
103952 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt);
 
 
 
 
 
 
 
 
 
103953 }
103954 }
103955
103956 return rc;
103957 }
@@ -105129,11 +105396,11 @@
105396
105397 sqlite3BeginBenignMalloc();
105398 assert( aArg==aDyn || (aDyn==0 && aArg==aStatic) );
105399 assert( nArg<=(int)ArraySize(aStatic) || aArg==aDyn );
105400 if( (!aDyn && nArg==(int)ArraySize(aStatic))
105401 || (aDyn && nArg==(int)(sqlite3MallocSize(aDyn)/sizeof(void*)))
105402 ){
105403 /* The aArg[] array needs to grow. */
105404 void **pNew = (void **)sqlite3Malloc(nArg*sizeof(void *)*2);
105405 if( pNew ){
105406 memcpy(pNew, aArg, nArg*sizeof(void *));
105407
+50 -11
--- 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.7.0"
111
-#define SQLITE_VERSION_NUMBER 3007000
112
-#define SQLITE_SOURCE_ID "2010-07-21 16:16:28 b36b105eab6fd3195f4bfba6cb5cda0f063b7460"
110
+#define SQLITE_VERSION "3.7.1"
111
+#define SQLITE_VERSION_NUMBER 3007001
112
+#define SQLITE_SOURCE_ID "2010-08-05 03:21:40 fbe70e1106bcc5086ceb9d8f39cc39baf3643092"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -2174,11 +2174,17 @@
21742174
** contain a UTF-8 SQL comment that identifies the trigger.)^
21752175
**
21762176
** ^The callback function registered by sqlite3_profile() is invoked
21772177
** as each SQL statement finishes. ^The profile callback contains
21782178
** the original statement text and an estimate of wall-clock time
2179
-** of how long that statement took to run.
2179
+** of how long that statement took to run. ^The profile callback
2180
+** time is in units of nanoseconds, however the current implementation
2181
+** is only capable of millisecond resolution so the six least significant
2182
+** digits in the time are meaningless. Future versions of SQLite
2183
+** might provide greater resolution on the profiler callback. The
2184
+** sqlite3_profile() function is considered experimental and is
2185
+** subject to change in future versions of SQLite.
21802186
*/
21812187
SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
21822188
SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
21832189
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
21842190
@@ -4323,22 +4329,25 @@
43234329
43244330
/*
43254331
** CAPI3REF: Virtual Table Indexing Information
43264332
** KEYWORDS: sqlite3_index_info
43274333
**
4328
-** The sqlite3_index_info structure and its substructures is used to
4334
+** The sqlite3_index_info structure and its substructures is used as part
4335
+** of the [virtual table] interface to
43294336
** pass information into and receive the reply from the [xBestIndex]
43304337
** method of a [virtual table module]. The fields under **Inputs** are the
43314338
** inputs to xBestIndex and are read-only. xBestIndex inserts its
43324339
** results into the **Outputs** fields.
43334340
**
43344341
** ^(The aConstraint[] array records WHERE clause constraints of the form:
43354342
**
4336
-** <pre>column OP expr</pre>
4343
+** <blockquote>column OP expr</blockquote>
43374344
**
43384345
** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
4339
-** stored in aConstraint[].op.)^ ^(The index of the column is stored in
4346
+** stored in aConstraint[].op using one of the
4347
+** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
4348
+** ^(The index of the column is stored in
43404349
** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
43414350
** expr on the right-hand side can be evaluated (and thus the constraint
43424351
** is usable) and false if it cannot.)^
43434352
**
43444353
** ^The optimizer automatically inverts terms of the form "expr OP column"
@@ -4394,10 +4403,19 @@
43944403
char *idxStr; /* String, possibly obtained from sqlite3_malloc */
43954404
int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
43964405
int orderByConsumed; /* True if output is already ordered */
43974406
double estimatedCost; /* Estimated cost of using this index */
43984407
};
4408
+
4409
+/*
4410
+** CAPI3REF: Virtual Table Constraint Operator Codes
4411
+**
4412
+** These macros defined the allowed values for the
4413
+** [sqlite3_index_info].aConstraint[].op field. Each value represents
4414
+** an operator that is part of a constraint term in the wHERE clause of
4415
+** a query that uses a [virtual table].
4416
+*/
43994417
#define SQLITE_INDEX_CONSTRAINT_EQ 2
44004418
#define SQLITE_INDEX_CONSTRAINT_GT 4
44014419
#define SQLITE_INDEX_CONSTRAINT_LE 8
44024420
#define SQLITE_INDEX_CONSTRAINT_LT 16
44034421
#define SQLITE_INDEX_CONSTRAINT_GE 32
@@ -5134,10 +5152,13 @@
51345152
** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
51355153
** internal equivalents). Only the value returned in the
51365154
** *pHighwater parameter to [sqlite3_status()] is of interest.
51375155
** The value written into the *pCurrent parameter is undefined.</dd>)^
51385156
**
5157
+** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5158
+** <dd>This parameter records the number of separate memory allocations.</dd>)^
5159
+**
51395160
** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
51405161
** <dd>This parameter returns the number of pages used out of the
51415162
** [pagecache memory allocator] that was configured using
51425163
** [SQLITE_CONFIG_PAGECACHE]. The
51435164
** value returned is in pages, not in bytes.</dd>)^
@@ -5195,10 +5216,11 @@
51955216
#define SQLITE_STATUS_SCRATCH_OVERFLOW 4
51965217
#define SQLITE_STATUS_MALLOC_SIZE 5
51975218
#define SQLITE_STATUS_PARSER_STACK 6
51985219
#define SQLITE_STATUS_PAGECACHE_SIZE 7
51995220
#define SQLITE_STATUS_SCRATCH_SIZE 8
5221
+#define SQLITE_STATUS_MALLOC_COUNT 9
52005222
52015223
/*
52025224
** CAPI3REF: Database Connection Status
52035225
**
52045226
** ^This interface is used to retrieve runtime status information
@@ -5234,20 +5256,37 @@
52345256
** <dl>
52355257
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
52365258
** <dd>This parameter returns the number of lookaside memory slots currently
52375259
** checked out.</dd>)^
52385260
**
5239
-** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5240
-** <dd>^This parameter returns the approximate number of of bytes of heap
5241
-** memory used by all pager caches associated with the database connection.
5261
+** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5262
+** <dd>This parameter returns the approximate number of of bytes of heap
5263
+** memory used by all pager caches associated with the database connection.)^
52425264
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5265
+**
5266
+** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
5267
+** <dd>This parameter returns the approximate number of of bytes of heap
5268
+** memory used to store the schema for all databases associated
5269
+** with the connection - main, temp, and any [ATTACH]-ed databases.)^
5270
+** ^The full amount of memory used by the schemas is reported, even if the
5271
+** schema memory is shared with other database connections due to
5272
+** [shared cache mode] being enabled.
5273
+** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
5274
+**
5275
+** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
5276
+** <dd>This parameter returns the approximate number of of bytes of heap
5277
+** and lookaside memory used by all prepared statements associated with
5278
+** the database connection.)^
5279
+** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
52435280
** </dd>
52445281
** </dl>
52455282
*/
52465283
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
52475284
#define SQLITE_DBSTATUS_CACHE_USED 1
5248
-#define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
5285
+#define SQLITE_DBSTATUS_SCHEMA_USED 2
5286
+#define SQLITE_DBSTATUS_STMT_USED 3
5287
+#define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
52495288
52505289
52515290
/*
52525291
** CAPI3REF: Prepared Statement Status
52535292
**
52545293
--- 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.7.0"
111 #define SQLITE_VERSION_NUMBER 3007000
112 #define SQLITE_SOURCE_ID "2010-07-21 16:16:28 b36b105eab6fd3195f4bfba6cb5cda0f063b7460"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2174,11 +2174,17 @@
2174 ** contain a UTF-8 SQL comment that identifies the trigger.)^
2175 **
2176 ** ^The callback function registered by sqlite3_profile() is invoked
2177 ** as each SQL statement finishes. ^The profile callback contains
2178 ** the original statement text and an estimate of wall-clock time
2179 ** of how long that statement took to run.
 
 
 
 
 
 
2180 */
2181 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2182 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2183 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2184
@@ -4323,22 +4329,25 @@
4323
4324 /*
4325 ** CAPI3REF: Virtual Table Indexing Information
4326 ** KEYWORDS: sqlite3_index_info
4327 **
4328 ** The sqlite3_index_info structure and its substructures is used to
 
4329 ** pass information into and receive the reply from the [xBestIndex]
4330 ** method of a [virtual table module]. The fields under **Inputs** are the
4331 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
4332 ** results into the **Outputs** fields.
4333 **
4334 ** ^(The aConstraint[] array records WHERE clause constraints of the form:
4335 **
4336 ** <pre>column OP expr</pre>
4337 **
4338 ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
4339 ** stored in aConstraint[].op.)^ ^(The index of the column is stored in
 
 
4340 ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
4341 ** expr on the right-hand side can be evaluated (and thus the constraint
4342 ** is usable) and false if it cannot.)^
4343 **
4344 ** ^The optimizer automatically inverts terms of the form "expr OP column"
@@ -4394,10 +4403,19 @@
4394 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
4395 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
4396 int orderByConsumed; /* True if output is already ordered */
4397 double estimatedCost; /* Estimated cost of using this index */
4398 };
 
 
 
 
 
 
 
 
 
4399 #define SQLITE_INDEX_CONSTRAINT_EQ 2
4400 #define SQLITE_INDEX_CONSTRAINT_GT 4
4401 #define SQLITE_INDEX_CONSTRAINT_LE 8
4402 #define SQLITE_INDEX_CONSTRAINT_LT 16
4403 #define SQLITE_INDEX_CONSTRAINT_GE 32
@@ -5134,10 +5152,13 @@
5134 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
5135 ** internal equivalents). Only the value returned in the
5136 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5137 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5138 **
 
 
 
5139 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5140 ** <dd>This parameter returns the number of pages used out of the
5141 ** [pagecache memory allocator] that was configured using
5142 ** [SQLITE_CONFIG_PAGECACHE]. The
5143 ** value returned is in pages, not in bytes.</dd>)^
@@ -5195,10 +5216,11 @@
5195 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
5196 #define SQLITE_STATUS_MALLOC_SIZE 5
5197 #define SQLITE_STATUS_PARSER_STACK 6
5198 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5199 #define SQLITE_STATUS_SCRATCH_SIZE 8
 
5200
5201 /*
5202 ** CAPI3REF: Database Connection Status
5203 **
5204 ** ^This interface is used to retrieve runtime status information
@@ -5234,20 +5256,37 @@
5234 ** <dl>
5235 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5236 ** <dd>This parameter returns the number of lookaside memory slots currently
5237 ** checked out.</dd>)^
5238 **
5239 ** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5240 ** <dd>^This parameter returns the approximate number of of bytes of heap
5241 ** memory used by all pager caches associated with the database connection.
5242 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5243 ** </dd>
5244 ** </dl>
5245 */
5246 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5247 #define SQLITE_DBSTATUS_CACHE_USED 1
5248 #define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
 
 
5249
5250
5251 /*
5252 ** CAPI3REF: Prepared Statement Status
5253 **
5254
--- 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.7.1"
111 #define SQLITE_VERSION_NUMBER 3007001
112 #define SQLITE_SOURCE_ID "2010-08-05 03:21:40 fbe70e1106bcc5086ceb9d8f39cc39baf3643092"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2174,11 +2174,17 @@
2174 ** contain a UTF-8 SQL comment that identifies the trigger.)^
2175 **
2176 ** ^The callback function registered by sqlite3_profile() is invoked
2177 ** as each SQL statement finishes. ^The profile callback contains
2178 ** the original statement text and an estimate of wall-clock time
2179 ** of how long that statement took to run. ^The profile callback
2180 ** time is in units of nanoseconds, however the current implementation
2181 ** is only capable of millisecond resolution so the six least significant
2182 ** digits in the time are meaningless. Future versions of SQLite
2183 ** might provide greater resolution on the profiler callback. The
2184 ** sqlite3_profile() function is considered experimental and is
2185 ** subject to change in future versions of SQLite.
2186 */
2187 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2188 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2189 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2190
@@ -4323,22 +4329,25 @@
4329
4330 /*
4331 ** CAPI3REF: Virtual Table Indexing Information
4332 ** KEYWORDS: sqlite3_index_info
4333 **
4334 ** The sqlite3_index_info structure and its substructures is used as part
4335 ** of the [virtual table] interface to
4336 ** pass information into and receive the reply from the [xBestIndex]
4337 ** method of a [virtual table module]. The fields under **Inputs** are the
4338 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
4339 ** results into the **Outputs** fields.
4340 **
4341 ** ^(The aConstraint[] array records WHERE clause constraints of the form:
4342 **
4343 ** <blockquote>column OP expr</blockquote>
4344 **
4345 ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
4346 ** stored in aConstraint[].op using one of the
4347 ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
4348 ** ^(The index of the column is stored in
4349 ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
4350 ** expr on the right-hand side can be evaluated (and thus the constraint
4351 ** is usable) and false if it cannot.)^
4352 **
4353 ** ^The optimizer automatically inverts terms of the form "expr OP column"
@@ -4394,10 +4403,19 @@
4403 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
4404 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
4405 int orderByConsumed; /* True if output is already ordered */
4406 double estimatedCost; /* Estimated cost of using this index */
4407 };
4408
4409 /*
4410 ** CAPI3REF: Virtual Table Constraint Operator Codes
4411 **
4412 ** These macros defined the allowed values for the
4413 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
4414 ** an operator that is part of a constraint term in the wHERE clause of
4415 ** a query that uses a [virtual table].
4416 */
4417 #define SQLITE_INDEX_CONSTRAINT_EQ 2
4418 #define SQLITE_INDEX_CONSTRAINT_GT 4
4419 #define SQLITE_INDEX_CONSTRAINT_LE 8
4420 #define SQLITE_INDEX_CONSTRAINT_LT 16
4421 #define SQLITE_INDEX_CONSTRAINT_GE 32
@@ -5134,10 +5152,13 @@
5152 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
5153 ** internal equivalents). Only the value returned in the
5154 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5155 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5156 **
5157 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5158 ** <dd>This parameter records the number of separate memory allocations.</dd>)^
5159 **
5160 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5161 ** <dd>This parameter returns the number of pages used out of the
5162 ** [pagecache memory allocator] that was configured using
5163 ** [SQLITE_CONFIG_PAGECACHE]. The
5164 ** value returned is in pages, not in bytes.</dd>)^
@@ -5195,10 +5216,11 @@
5216 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
5217 #define SQLITE_STATUS_MALLOC_SIZE 5
5218 #define SQLITE_STATUS_PARSER_STACK 6
5219 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5220 #define SQLITE_STATUS_SCRATCH_SIZE 8
5221 #define SQLITE_STATUS_MALLOC_COUNT 9
5222
5223 /*
5224 ** CAPI3REF: Database Connection Status
5225 **
5226 ** ^This interface is used to retrieve runtime status information
@@ -5234,20 +5256,37 @@
5256 ** <dl>
5257 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5258 ** <dd>This parameter returns the number of lookaside memory slots currently
5259 ** checked out.</dd>)^
5260 **
5261 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5262 ** <dd>This parameter returns the approximate number of of bytes of heap
5263 ** memory used by all pager caches associated with the database connection.)^
5264 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5265 **
5266 ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
5267 ** <dd>This parameter returns the approximate number of of bytes of heap
5268 ** memory used to store the schema for all databases associated
5269 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
5270 ** ^The full amount of memory used by the schemas is reported, even if the
5271 ** schema memory is shared with other database connections due to
5272 ** [shared cache mode] being enabled.
5273 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
5274 **
5275 ** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
5276 ** <dd>This parameter returns the approximate number of of bytes of heap
5277 ** and lookaside memory used by all prepared statements associated with
5278 ** the database connection.)^
5279 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5280 ** </dd>
5281 ** </dl>
5282 */
5283 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5284 #define SQLITE_DBSTATUS_CACHE_USED 1
5285 #define SQLITE_DBSTATUS_SCHEMA_USED 2
5286 #define SQLITE_DBSTATUS_STMT_USED 3
5287 #define SQLITE_DBSTATUS_MAX 3 /* Largest defined DBSTATUS */
5288
5289
5290 /*
5291 ** CAPI3REF: Prepared Statement Status
5292 **
5293
+8 -5
--- src/update.c
+++ src/update.c
@@ -292,14 +292,15 @@
292292
}
293293
}
294294
295295
296296
/*
297
-** Get the contents of a file within a given revision.
297
+** Get the contents of a file within the checking "revision". If
298
+** revision==NULL then get the file content for the current checkout.
298299
*/
299300
int historical_version_of_file(
300
- const char *revision, /* The baseline name containing the file */
301
+ const char *revision, /* The checkin containing the file */
301302
const char *file, /* Full treename of the file */
302303
Blob *content, /* Put the content here */
303304
int errCode /* Error code if file not found. Panic if 0. */
304305
){
305306
Blob mfile;
@@ -311,26 +312,28 @@
311312
}else{
312313
rid = db_lget_int("checkout", 0);
313314
}
314315
if( !is_a_version(rid) ){
315316
if( errCode>0 ) return errCode;
316
- fossil_fatal("no such check-out: %s", revision);
317
+ fossil_fatal("no such checkin: %s", revision);
317318
}
318319
content_get(rid, &mfile);
319320
320321
if( manifest_parse(&m, &mfile) ){
321322
for(i=0; i<m.nFile; i++){
322323
if( strcmp(m.aFile[i].zName, file)==0 ){
323324
rid = uuid_to_rid(m.aFile[i].zUuid, 0);
325
+ manifest_clear(&m);
324326
return content_get(rid, content);
325327
}
326328
}
329
+ manifest_clear(&m);
327330
if( errCode<=0 ){
328
- fossil_fatal("file %s does not exist in baseline: %s", file, revision);
331
+ fossil_fatal("file %s does not exist in checkin: %s", file, revision);
329332
}
330333
}else if( errCode<=0 ){
331
- fossil_panic("could not parse manifest for baseline: %s", revision);
334
+ fossil_panic("could not parse manifest for checkin: %s", revision);
332335
}
333336
return errCode;
334337
}
335338
336339
337340
--- src/update.c
+++ src/update.c
@@ -292,14 +292,15 @@
292 }
293 }
294
295
296 /*
297 ** Get the contents of a file within a given revision.
 
298 */
299 int historical_version_of_file(
300 const char *revision, /* The baseline name containing the file */
301 const char *file, /* Full treename of the file */
302 Blob *content, /* Put the content here */
303 int errCode /* Error code if file not found. Panic if 0. */
304 ){
305 Blob mfile;
@@ -311,26 +312,28 @@
311 }else{
312 rid = db_lget_int("checkout", 0);
313 }
314 if( !is_a_version(rid) ){
315 if( errCode>0 ) return errCode;
316 fossil_fatal("no such check-out: %s", revision);
317 }
318 content_get(rid, &mfile);
319
320 if( manifest_parse(&m, &mfile) ){
321 for(i=0; i<m.nFile; i++){
322 if( strcmp(m.aFile[i].zName, file)==0 ){
323 rid = uuid_to_rid(m.aFile[i].zUuid, 0);
 
324 return content_get(rid, content);
325 }
326 }
 
327 if( errCode<=0 ){
328 fossil_fatal("file %s does not exist in baseline: %s", file, revision);
329 }
330 }else if( errCode<=0 ){
331 fossil_panic("could not parse manifest for baseline: %s", revision);
332 }
333 return errCode;
334 }
335
336
337
--- src/update.c
+++ src/update.c
@@ -292,14 +292,15 @@
292 }
293 }
294
295
296 /*
297 ** Get the contents of a file within the checking "revision". If
298 ** revision==NULL then get the file content for the current checkout.
299 */
300 int historical_version_of_file(
301 const char *revision, /* The checkin containing the file */
302 const char *file, /* Full treename of the file */
303 Blob *content, /* Put the content here */
304 int errCode /* Error code if file not found. Panic if 0. */
305 ){
306 Blob mfile;
@@ -311,26 +312,28 @@
312 }else{
313 rid = db_lget_int("checkout", 0);
314 }
315 if( !is_a_version(rid) ){
316 if( errCode>0 ) return errCode;
317 fossil_fatal("no such checkin: %s", revision);
318 }
319 content_get(rid, &mfile);
320
321 if( manifest_parse(&m, &mfile) ){
322 for(i=0; i<m.nFile; i++){
323 if( strcmp(m.aFile[i].zName, file)==0 ){
324 rid = uuid_to_rid(m.aFile[i].zUuid, 0);
325 manifest_clear(&m);
326 return content_get(rid, content);
327 }
328 }
329 manifest_clear(&m);
330 if( errCode<=0 ){
331 fossil_fatal("file %s does not exist in checkin: %s", file, revision);
332 }
333 }else if( errCode<=0 ){
334 fossil_panic("could not parse manifest for checkin: %s", revision);
335 }
336 return errCode;
337 }
338
339
340
+9 -4
--- src/vfile.c
+++ src/vfile.c
@@ -60,12 +60,17 @@
6060
6161
/*
6262
** Verify that an object is not a phantom. If the object is
6363
** a phantom, output an error message and quick.
6464
*/
65
-void vfile_verify_not_phantom(int rid, const char *zFilename){
66
- if( db_int(-1, "SELECT size FROM blob WHERE rid=%d", rid)<0 ){
65
+static void vfile_verify_not_phantom(
66
+ int rid, /* The RID to verify */
67
+ const char *zFilename, /* Filename. Might be NULL */
68
+ const char *zUuid /* UUID. Might be NULL */
69
+){
70
+ if( db_int(-1, "SELECT size FROM blob WHERE rid=%d", rid)<0
71
+ && (zUuid==0 || !db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid)) ){
6772
if( zFilename ){
6873
fossil_fatal("content missing for %s", zFilename);
6974
}else{
7075
char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
7176
if( zUuid ){
@@ -90,11 +95,11 @@
9095
char *zName, *zUuid;
9196
Stmt ins;
9297
Blob line, token, name, uuid;
9398
int seenHeader = 0;
9499
db_begin_transaction();
95
- vfile_verify_not_phantom(vid, 0);
100
+ vfile_verify_not_phantom(vid, 0, 0);
96101
db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid);
97102
db_prepare(&ins,
98103
"INSERT INTO vfile(vid,rid,mrid,pathname) "
99104
" VALUES(:vid,:id,:id,:name)");
100105
db_bind_int(&ins, ":vid", vid);
@@ -112,11 +117,11 @@
112117
if( blob_token(&line, &uuid)==0 ) break;
113118
zName = blob_str(&name);
114119
defossilize(zName);
115120
zUuid = blob_str(&uuid);
116121
rid = uuid_to_rid(zUuid, 0);
117
- vfile_verify_not_phantom(rid, zName);
122
+ vfile_verify_not_phantom(rid, zName, zUuid);
118123
if( rid>0 && file_is_simple_pathname(zName) ){
119124
db_bind_int(&ins, ":id", rid);
120125
db_bind_text(&ins, ":name", zName);
121126
db_step(&ins);
122127
db_reset(&ins);
123128
--- src/vfile.c
+++ src/vfile.c
@@ -60,12 +60,17 @@
60
61 /*
62 ** Verify that an object is not a phantom. If the object is
63 ** a phantom, output an error message and quick.
64 */
65 void vfile_verify_not_phantom(int rid, const char *zFilename){
66 if( db_int(-1, "SELECT size FROM blob WHERE rid=%d", rid)<0 ){
 
 
 
 
 
67 if( zFilename ){
68 fossil_fatal("content missing for %s", zFilename);
69 }else{
70 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
71 if( zUuid ){
@@ -90,11 +95,11 @@
90 char *zName, *zUuid;
91 Stmt ins;
92 Blob line, token, name, uuid;
93 int seenHeader = 0;
94 db_begin_transaction();
95 vfile_verify_not_phantom(vid, 0);
96 db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid);
97 db_prepare(&ins,
98 "INSERT INTO vfile(vid,rid,mrid,pathname) "
99 " VALUES(:vid,:id,:id,:name)");
100 db_bind_int(&ins, ":vid", vid);
@@ -112,11 +117,11 @@
112 if( blob_token(&line, &uuid)==0 ) break;
113 zName = blob_str(&name);
114 defossilize(zName);
115 zUuid = blob_str(&uuid);
116 rid = uuid_to_rid(zUuid, 0);
117 vfile_verify_not_phantom(rid, zName);
118 if( rid>0 && file_is_simple_pathname(zName) ){
119 db_bind_int(&ins, ":id", rid);
120 db_bind_text(&ins, ":name", zName);
121 db_step(&ins);
122 db_reset(&ins);
123
--- src/vfile.c
+++ src/vfile.c
@@ -60,12 +60,17 @@
60
61 /*
62 ** Verify that an object is not a phantom. If the object is
63 ** a phantom, output an error message and quick.
64 */
65 static void vfile_verify_not_phantom(
66 int rid, /* The RID to verify */
67 const char *zFilename, /* Filename. Might be NULL */
68 const char *zUuid /* UUID. Might be NULL */
69 ){
70 if( db_int(-1, "SELECT size FROM blob WHERE rid=%d", rid)<0
71 && (zUuid==0 || !db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid)) ){
72 if( zFilename ){
73 fossil_fatal("content missing for %s", zFilename);
74 }else{
75 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
76 if( zUuid ){
@@ -90,11 +95,11 @@
95 char *zName, *zUuid;
96 Stmt ins;
97 Blob line, token, name, uuid;
98 int seenHeader = 0;
99 db_begin_transaction();
100 vfile_verify_not_phantom(vid, 0, 0);
101 db_multi_exec("DELETE FROM vfile WHERE vid=%d", vid);
102 db_prepare(&ins,
103 "INSERT INTO vfile(vid,rid,mrid,pathname) "
104 " VALUES(:vid,:id,:id,:name)");
105 db_bind_int(&ins, ":vid", vid);
@@ -112,11 +117,11 @@
117 if( blob_token(&line, &uuid)==0 ) break;
118 zName = blob_str(&name);
119 defossilize(zName);
120 zUuid = blob_str(&uuid);
121 rid = uuid_to_rid(zUuid, 0);
122 vfile_verify_not_phantom(rid, zName, zUuid);
123 if( rid>0 && file_is_simple_pathname(zName) ){
124 db_bind_int(&ins, ":id", rid);
125 db_bind_text(&ins, ":name", zName);
126 db_step(&ins);
127 db_reset(&ins);
128
--- www/index.wiki
+++ www/index.wiki
@@ -124,10 +124,12 @@
124124
* Some (unfinished but expanding) extended
125125
[./reference.wiki | reference documentation] for the fossil command line.
126126
* Documentation on the
127127
[http://www.sqliteconcepts.org/THManual.pdf | TH1 Script Language] used
128128
to configure the ticketing subsystem.
129
+ * A free hosting server for Fossil repositories is available at
130
+ [http://chiselapp.com/].
129131
* How to [./server.wiki | set up a server] for your repository.
130132
* Customizing the [./custom_ticket.wiki | ticket system].
131133
132134
<h3>Links For Fossil Developer:</h3>
133135
134136
--- www/index.wiki
+++ www/index.wiki
@@ -124,10 +124,12 @@
124 * Some (unfinished but expanding) extended
125 [./reference.wiki | reference documentation] for the fossil command line.
126 * Documentation on the
127 [http://www.sqliteconcepts.org/THManual.pdf | TH1 Script Language] used
128 to configure the ticketing subsystem.
 
 
129 * How to [./server.wiki | set up a server] for your repository.
130 * Customizing the [./custom_ticket.wiki | ticket system].
131
132 <h3>Links For Fossil Developer:</h3>
133
134
--- www/index.wiki
+++ www/index.wiki
@@ -124,10 +124,12 @@
124 * Some (unfinished but expanding) extended
125 [./reference.wiki | reference documentation] for the fossil command line.
126 * Documentation on the
127 [http://www.sqliteconcepts.org/THManual.pdf | TH1 Script Language] used
128 to configure the ticketing subsystem.
129 * A free hosting server for Fossil repositories is available at
130 [http://chiselapp.com/].
131 * How to [./server.wiki | set up a server] for your repository.
132 * Customizing the [./custom_ticket.wiki | ticket system].
133
134 <h3>Links For Fossil Developer:</h3>
135
136
+3 -3
--- www/server.wiki
+++ www/server.wiki
@@ -56,11 +56,11 @@
5656
5757
<h3>One script per repository</h3><blockquote>
5858
<p>
5959
Create a script (let's call it 'repo') in your CGI directory which has content like this:
6060
<blockquote><tt>
61
-#!/path-to/fossil
61
+#!/path-to/fossil<br>
6262
repository: /path-to-repo/repository
6363
</tt></blockquote>
6464
</p>
6565
<p>
6666
It may be necessary to set permissions properly, or to modify an ".htaccess" file or other server-specific things like that. Consult with your server provider if you need that sort of assistance.
@@ -72,12 +72,12 @@
7272
7373
<h3>Serving multiple repositories with one script</h3><blockquote>
7474
<p>
7575
This scenario is almost identical to the previous one. However, here we will assume you have multiple repositories, in one directory (call it 'fossils'). So as before, create a script (again, 'repo'):
7676
<blockquote><tt>
77
-#!/path-to/fossil
78
-directory: /path-to-repo/fossils
77
+#!/path-to/fossil<br>
78
+directory: /path-to-repo/fossils<br>
7979
notfound: http://url-to-go-to-if-repo-not-found/
8080
</tt></blockquote>
8181
</p>
8282
<p>
8383
Once deployed, a URL like: <tt>http://mydomain.org/cgi-bin/repo/XYZ</tt> will serve up the repository "fossils/XYX" (if it exists). This makes serving multiple projects on one server pretty painless.
8484
--- www/server.wiki
+++ www/server.wiki
@@ -56,11 +56,11 @@
56
57 <h3>One script per repository</h3><blockquote>
58 <p>
59 Create a script (let's call it 'repo') in your CGI directory which has content like this:
60 <blockquote><tt>
61 #!/path-to/fossil
62 repository: /path-to-repo/repository
63 </tt></blockquote>
64 </p>
65 <p>
66 It may be necessary to set permissions properly, or to modify an ".htaccess" file or other server-specific things like that. Consult with your server provider if you need that sort of assistance.
@@ -72,12 +72,12 @@
72
73 <h3>Serving multiple repositories with one script</h3><blockquote>
74 <p>
75 This scenario is almost identical to the previous one. However, here we will assume you have multiple repositories, in one directory (call it 'fossils'). So as before, create a script (again, 'repo'):
76 <blockquote><tt>
77 #!/path-to/fossil
78 directory: /path-to-repo/fossils
79 notfound: http://url-to-go-to-if-repo-not-found/
80 </tt></blockquote>
81 </p>
82 <p>
83 Once deployed, a URL like: <tt>http://mydomain.org/cgi-bin/repo/XYZ</tt> will serve up the repository "fossils/XYX" (if it exists). This makes serving multiple projects on one server pretty painless.
84
--- www/server.wiki
+++ www/server.wiki
@@ -56,11 +56,11 @@
56
57 <h3>One script per repository</h3><blockquote>
58 <p>
59 Create a script (let's call it 'repo') in your CGI directory which has content like this:
60 <blockquote><tt>
61 #!/path-to/fossil<br>
62 repository: /path-to-repo/repository
63 </tt></blockquote>
64 </p>
65 <p>
66 It may be necessary to set permissions properly, or to modify an ".htaccess" file or other server-specific things like that. Consult with your server provider if you need that sort of assistance.
@@ -72,12 +72,12 @@
72
73 <h3>Serving multiple repositories with one script</h3><blockquote>
74 <p>
75 This scenario is almost identical to the previous one. However, here we will assume you have multiple repositories, in one directory (call it 'fossils'). So as before, create a script (again, 'repo'):
76 <blockquote><tt>
77 #!/path-to/fossil<br>
78 directory: /path-to-repo/fossils<br>
79 notfound: http://url-to-go-to-if-repo-not-found/
80 </tt></blockquote>
81 </p>
82 <p>
83 Once deployed, a URL like: <tt>http://mydomain.org/cgi-bin/repo/XYZ</tt> will serve up the repository "fossils/XYX" (if it exists). This makes serving multiple projects on one server pretty painless.
84

Keyboard Shortcuts

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