Fossil SCM

merge diff-eolws

jan.nijtmans 2014-03-05 15:11 UTC diff-eolws merge
Commit 91add0e03d8c632ab79dabca2242f7714b49d4ed
+20 -14
--- src/diff.c
+++ src/diff.c
@@ -77,11 +77,11 @@
7777
*/
7878
typedef struct DLine DLine;
7979
struct DLine {
8080
const char *z; /* The text of the line */
8181
unsigned int h; /* Hash of the line */
82
- unsigned int indent; /* Indent of the line. Only !=0 with --ignore-space-at sol option */
82
+ unsigned short indent; /* Indent of the line. Only !=0 with --ignore-space-at sol option */
8383
unsigned int iNext; /* 1+(Index of next line with same the same hash) */
8484
8585
/* an array of DLine elements serves two purposes. The fields
8686
** above are one per line of input text. But each entry is also
8787
** a bucket in a hash table, as follows: */
@@ -1972,11 +1972,14 @@
19721972
typedef struct Annotator Annotator;
19731973
struct Annotator {
19741974
DContext c; /* The diff-engine context */
19751975
struct AnnLine { /* Lines of the original files... */
19761976
const char *z; /* The text of the line */
1977
- short int n; /* Number of bytes (omitting trailing space and \n) */
1977
+ short int n; /* Number of bytes. Whether this omits sol/eol spacing
1978
+ depends on the diffFlags) */
1979
+ unsigned short indent; /* Indenting (number of initial spaces, only used
1980
+ if sol-spacing is ignored in the diffFlags) */
19781981
short int iVers; /* Level at which tag was set */
19791982
} *aOrig;
19801983
int nOrig; /* Number of elements in aOrig[] */
19811984
int nVers; /* Number of versions analyzed */
19821985
int bLimit; /* True if the iLimit was reached */
@@ -2007,10 +2010,11 @@
20072010
}
20082011
p->aOrig = fossil_malloc( sizeof(p->aOrig[0])*p->c.nTo );
20092012
for(i=0; i<p->c.nTo; i++){
20102013
p->aOrig[i].z = p->c.aTo[i].z;
20112014
p->aOrig[i].n = p->c.aTo[i].h & LENGTH_MASK;
2015
+ p->aOrig[i].indent = p->c.aTo[i].indent;
20122016
p->aOrig[i].iVers = -1;
20132017
}
20142018
p->nOrig = p->c.nTo;
20152019
return 0;
20162020
}
@@ -2312,10 +2316,11 @@
23122316
@ <pre>
23132317
for(i=0; i<ann.nOrig; i++){
23142318
int iVers = ann.aOrig[i].iVers;
23152319
char *z = (char*)ann.aOrig[i].z;
23162320
int n = ann.aOrig[i].n;
2321
+ int indent = ann.aOrig[i].indent+1;
23172322
char zPrefix[300];
23182323
z[n] = 0;
23192324
if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
23202325
23212326
if( bBlame ){
@@ -2326,26 +2331,26 @@
23262331
"<span style='background-color:%s'>"
23272332
"%s%.10s</a> %s</span> %13.13s:",
23282333
p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
23292334
fossil_free(zLink);
23302335
}else{
2331
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s", "");
2336
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s%*s", indent, " ");
23322337
}
23332338
}else{
23342339
if( iVers>=0 ){
23352340
struct AnnVers *p = ann.aVers+iVers;
23362341
char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
23372342
sqlite3_snprintf(sizeof(zPrefix), zPrefix,
23382343
"<span style='background-color:%s'>"
2339
- "%s%.10s</a> %s</span> %4d:",
2340
- p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2344
+ "%s%.10s</a> %s</span> %4d:%*s",
2345
+ p->zBgColor, zLink, p->zMUuid, p->zDate, i+1, indent, " ");
23412346
fossil_free(zLink);
23422347
}else{
2343
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2348
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:%*s", "", i+1, indent, " ");
23442349
}
23452350
}
2346
- @ %s(zPrefix) %h(z)
2351
+ @ %s(zPrefix)%h(z)
23472352
23482353
}
23492354
@ </pre>
23502355
style_footer();
23512356
}
@@ -2430,27 +2435,28 @@
24302435
fossil_print("---------------------------------------------------\n");
24312436
}
24322437
for(i=0; i<ann.nOrig; i++){
24332438
int iVers = ann.aOrig[i].iVers;
24342439
char *z = (char*)ann.aOrig[i].z;
2440
+ int indent = ann.aOrig[i].indent + 1;
24352441
int n = ann.aOrig[i].n;
24362442
struct AnnVers *p;
24372443
if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
24382444
p = ann.aVers + iVers;
24392445
if( bBlame ){
24402446
if( iVers>=0 ){
2441
- fossil_print("%.10s %s %13.13s: %.*s\n",
2442
- fileVers ? p->zFUuid : p->zMUuid, p->zDate, p->zUser, n, z);
2447
+ fossil_print("%.10s %s %13.13s:%*s%.*s\n",
2448
+ fileVers ? p->zFUuid : p->zMUuid, p->zDate, p->zUser, indent, " ", n, z);
24432449
}else{
2444
- fossil_print("%35s %.*s\n", "", n, z);
2450
+ fossil_print("%35s %*s%.*s\n", "", indent, " ", n, z);
24452451
}
24462452
}else{
24472453
if( iVers>=0 ){
2448
- fossil_print("%.10s %s %5d: %.*s\n",
2449
- fileVers ? p->zFUuid : p->zMUuid, p->zDate, i+1, n, z);
2454
+ fossil_print("%.10s %s %5d:%*s%.*s\n",
2455
+ fileVers ? p->zFUuid : p->zMUuid, p->zDate, i+1, indent, " ", n, z);
24502456
}else{
2451
- fossil_print("%21s %5d: %.*s\n",
2452
- "", i+1, n, z);
2457
+ fossil_print("%21s %5d:%*s%.*s\n",
2458
+ "", i+1, indent, " ", n, z);
24532459
}
24542460
}
24552461
}
24562462
}
24572463
--- src/diff.c
+++ src/diff.c
@@ -77,11 +77,11 @@
77 */
78 typedef struct DLine DLine;
79 struct DLine {
80 const char *z; /* The text of the line */
81 unsigned int h; /* Hash of the line */
82 unsigned int indent; /* Indent of the line. Only !=0 with --ignore-space-at sol option */
83 unsigned int iNext; /* 1+(Index of next line with same the same hash) */
84
85 /* an array of DLine elements serves two purposes. The fields
86 ** above are one per line of input text. But each entry is also
87 ** a bucket in a hash table, as follows: */
@@ -1972,11 +1972,14 @@
1972 typedef struct Annotator Annotator;
1973 struct Annotator {
1974 DContext c; /* The diff-engine context */
1975 struct AnnLine { /* Lines of the original files... */
1976 const char *z; /* The text of the line */
1977 short int n; /* Number of bytes (omitting trailing space and \n) */
 
 
 
1978 short int iVers; /* Level at which tag was set */
1979 } *aOrig;
1980 int nOrig; /* Number of elements in aOrig[] */
1981 int nVers; /* Number of versions analyzed */
1982 int bLimit; /* True if the iLimit was reached */
@@ -2007,10 +2010,11 @@
2007 }
2008 p->aOrig = fossil_malloc( sizeof(p->aOrig[0])*p->c.nTo );
2009 for(i=0; i<p->c.nTo; i++){
2010 p->aOrig[i].z = p->c.aTo[i].z;
2011 p->aOrig[i].n = p->c.aTo[i].h & LENGTH_MASK;
 
2012 p->aOrig[i].iVers = -1;
2013 }
2014 p->nOrig = p->c.nTo;
2015 return 0;
2016 }
@@ -2312,10 +2316,11 @@
2312 @ <pre>
2313 for(i=0; i<ann.nOrig; i++){
2314 int iVers = ann.aOrig[i].iVers;
2315 char *z = (char*)ann.aOrig[i].z;
2316 int n = ann.aOrig[i].n;
 
2317 char zPrefix[300];
2318 z[n] = 0;
2319 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2320
2321 if( bBlame ){
@@ -2326,26 +2331,26 @@
2326 "<span style='background-color:%s'>"
2327 "%s%.10s</a> %s</span> %13.13s:",
2328 p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
2329 fossil_free(zLink);
2330 }else{
2331 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s", "");
2332 }
2333 }else{
2334 if( iVers>=0 ){
2335 struct AnnVers *p = ann.aVers+iVers;
2336 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2337 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2338 "<span style='background-color:%s'>"
2339 "%s%.10s</a> %s</span> %4d:",
2340 p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2341 fossil_free(zLink);
2342 }else{
2343 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2344 }
2345 }
2346 @ %s(zPrefix) %h(z)
2347
2348 }
2349 @ </pre>
2350 style_footer();
2351 }
@@ -2430,27 +2435,28 @@
2430 fossil_print("---------------------------------------------------\n");
2431 }
2432 for(i=0; i<ann.nOrig; i++){
2433 int iVers = ann.aOrig[i].iVers;
2434 char *z = (char*)ann.aOrig[i].z;
 
2435 int n = ann.aOrig[i].n;
2436 struct AnnVers *p;
2437 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2438 p = ann.aVers + iVers;
2439 if( bBlame ){
2440 if( iVers>=0 ){
2441 fossil_print("%.10s %s %13.13s: %.*s\n",
2442 fileVers ? p->zFUuid : p->zMUuid, p->zDate, p->zUser, n, z);
2443 }else{
2444 fossil_print("%35s %.*s\n", "", n, z);
2445 }
2446 }else{
2447 if( iVers>=0 ){
2448 fossil_print("%.10s %s %5d: %.*s\n",
2449 fileVers ? p->zFUuid : p->zMUuid, p->zDate, i+1, n, z);
2450 }else{
2451 fossil_print("%21s %5d: %.*s\n",
2452 "", i+1, n, z);
2453 }
2454 }
2455 }
2456 }
2457
--- src/diff.c
+++ src/diff.c
@@ -77,11 +77,11 @@
77 */
78 typedef struct DLine DLine;
79 struct DLine {
80 const char *z; /* The text of the line */
81 unsigned int h; /* Hash of the line */
82 unsigned short indent; /* Indent of the line. Only !=0 with --ignore-space-at sol option */
83 unsigned int iNext; /* 1+(Index of next line with same the same hash) */
84
85 /* an array of DLine elements serves two purposes. The fields
86 ** above are one per line of input text. But each entry is also
87 ** a bucket in a hash table, as follows: */
@@ -1972,11 +1972,14 @@
1972 typedef struct Annotator Annotator;
1973 struct Annotator {
1974 DContext c; /* The diff-engine context */
1975 struct AnnLine { /* Lines of the original files... */
1976 const char *z; /* The text of the line */
1977 short int n; /* Number of bytes. Whether this omits sol/eol spacing
1978 depends on the diffFlags) */
1979 unsigned short indent; /* Indenting (number of initial spaces, only used
1980 if sol-spacing is ignored in the diffFlags) */
1981 short int iVers; /* Level at which tag was set */
1982 } *aOrig;
1983 int nOrig; /* Number of elements in aOrig[] */
1984 int nVers; /* Number of versions analyzed */
1985 int bLimit; /* True if the iLimit was reached */
@@ -2007,10 +2010,11 @@
2010 }
2011 p->aOrig = fossil_malloc( sizeof(p->aOrig[0])*p->c.nTo );
2012 for(i=0; i<p->c.nTo; i++){
2013 p->aOrig[i].z = p->c.aTo[i].z;
2014 p->aOrig[i].n = p->c.aTo[i].h & LENGTH_MASK;
2015 p->aOrig[i].indent = p->c.aTo[i].indent;
2016 p->aOrig[i].iVers = -1;
2017 }
2018 p->nOrig = p->c.nTo;
2019 return 0;
2020 }
@@ -2312,10 +2316,11 @@
2316 @ <pre>
2317 for(i=0; i<ann.nOrig; i++){
2318 int iVers = ann.aOrig[i].iVers;
2319 char *z = (char*)ann.aOrig[i].z;
2320 int n = ann.aOrig[i].n;
2321 int indent = ann.aOrig[i].indent+1;
2322 char zPrefix[300];
2323 z[n] = 0;
2324 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2325
2326 if( bBlame ){
@@ -2326,26 +2331,26 @@
2331 "<span style='background-color:%s'>"
2332 "%s%.10s</a> %s</span> %13.13s:",
2333 p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
2334 fossil_free(zLink);
2335 }else{
2336 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s%*s", indent, " ");
2337 }
2338 }else{
2339 if( iVers>=0 ){
2340 struct AnnVers *p = ann.aVers+iVers;
2341 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2342 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2343 "<span style='background-color:%s'>"
2344 "%s%.10s</a> %s</span> %4d:%*s",
2345 p->zBgColor, zLink, p->zMUuid, p->zDate, i+1, indent, " ");
2346 fossil_free(zLink);
2347 }else{
2348 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:%*s", "", i+1, indent, " ");
2349 }
2350 }
2351 @ %s(zPrefix)%h(z)
2352
2353 }
2354 @ </pre>
2355 style_footer();
2356 }
@@ -2430,27 +2435,28 @@
2435 fossil_print("---------------------------------------------------\n");
2436 }
2437 for(i=0; i<ann.nOrig; i++){
2438 int iVers = ann.aOrig[i].iVers;
2439 char *z = (char*)ann.aOrig[i].z;
2440 int indent = ann.aOrig[i].indent + 1;
2441 int n = ann.aOrig[i].n;
2442 struct AnnVers *p;
2443 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2444 p = ann.aVers + iVers;
2445 if( bBlame ){
2446 if( iVers>=0 ){
2447 fossil_print("%.10s %s %13.13s:%*s%.*s\n",
2448 fileVers ? p->zFUuid : p->zMUuid, p->zDate, p->zUser, indent, " ", n, z);
2449 }else{
2450 fossil_print("%35s %*s%.*s\n", "", indent, " ", n, z);
2451 }
2452 }else{
2453 if( iVers>=0 ){
2454 fossil_print("%.10s %s %5d:%*s%.*s\n",
2455 fileVers ? p->zFUuid : p->zMUuid, p->zDate, i+1, indent, " ", n, z);
2456 }else{
2457 fossil_print("%21s %5d:%*s%.*s\n",
2458 "", i+1, indent, " ", n, z);
2459 }
2460 }
2461 }
2462 }
2463
+20 -14
--- src/diff.c
+++ src/diff.c
@@ -77,11 +77,11 @@
7777
*/
7878
typedef struct DLine DLine;
7979
struct DLine {
8080
const char *z; /* The text of the line */
8181
unsigned int h; /* Hash of the line */
82
- unsigned int indent; /* Indent of the line. Only !=0 with --ignore-space-at sol option */
82
+ unsigned short indent; /* Indent of the line. Only !=0 with --ignore-space-at sol option */
8383
unsigned int iNext; /* 1+(Index of next line with same the same hash) */
8484
8585
/* an array of DLine elements serves two purposes. The fields
8686
** above are one per line of input text. But each entry is also
8787
** a bucket in a hash table, as follows: */
@@ -1972,11 +1972,14 @@
19721972
typedef struct Annotator Annotator;
19731973
struct Annotator {
19741974
DContext c; /* The diff-engine context */
19751975
struct AnnLine { /* Lines of the original files... */
19761976
const char *z; /* The text of the line */
1977
- short int n; /* Number of bytes (omitting trailing space and \n) */
1977
+ short int n; /* Number of bytes. Whether this omits sol/eol spacing
1978
+ depends on the diffFlags) */
1979
+ unsigned short indent; /* Indenting (number of initial spaces, only used
1980
+ if sol-spacing is ignored in the diffFlags) */
19781981
short int iVers; /* Level at which tag was set */
19791982
} *aOrig;
19801983
int nOrig; /* Number of elements in aOrig[] */
19811984
int nVers; /* Number of versions analyzed */
19821985
int bLimit; /* True if the iLimit was reached */
@@ -2007,10 +2010,11 @@
20072010
}
20082011
p->aOrig = fossil_malloc( sizeof(p->aOrig[0])*p->c.nTo );
20092012
for(i=0; i<p->c.nTo; i++){
20102013
p->aOrig[i].z = p->c.aTo[i].z;
20112014
p->aOrig[i].n = p->c.aTo[i].h & LENGTH_MASK;
2015
+ p->aOrig[i].indent = p->c.aTo[i].indent;
20122016
p->aOrig[i].iVers = -1;
20132017
}
20142018
p->nOrig = p->c.nTo;
20152019
return 0;
20162020
}
@@ -2312,10 +2316,11 @@
23122316
@ <pre>
23132317
for(i=0; i<ann.nOrig; i++){
23142318
int iVers = ann.aOrig[i].iVers;
23152319
char *z = (char*)ann.aOrig[i].z;
23162320
int n = ann.aOrig[i].n;
2321
+ int indent = ann.aOrig[i].indent+1;
23172322
char zPrefix[300];
23182323
z[n] = 0;
23192324
if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
23202325
23212326
if( bBlame ){
@@ -2326,26 +2331,26 @@
23262331
"<span style='background-color:%s'>"
23272332
"%s%.10s</a> %s</span> %13.13s:",
23282333
p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
23292334
fossil_free(zLink);
23302335
}else{
2331
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s", "");
2336
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s%*s", indent, " ");
23322337
}
23332338
}else{
23342339
if( iVers>=0 ){
23352340
struct AnnVers *p = ann.aVers+iVers;
23362341
char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
23372342
sqlite3_snprintf(sizeof(zPrefix), zPrefix,
23382343
"<span style='background-color:%s'>"
2339
- "%s%.10s</a> %s</span> %4d:",
2340
- p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2344
+ "%s%.10s</a> %s</span> %4d:%*s",
2345
+ p->zBgColor, zLink, p->zMUuid, p->zDate, i+1, indent, " ");
23412346
fossil_free(zLink);
23422347
}else{
2343
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2348
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:%*s", "", i+1, indent, " ");
23442349
}
23452350
}
2346
- @ %s(zPrefix) %h(z)
2351
+ @ %s(zPrefix)%h(z)
23472352
23482353
}
23492354
@ </pre>
23502355
style_footer();
23512356
}
@@ -2430,27 +2435,28 @@
24302435
fossil_print("---------------------------------------------------\n");
24312436
}
24322437
for(i=0; i<ann.nOrig; i++){
24332438
int iVers = ann.aOrig[i].iVers;
24342439
char *z = (char*)ann.aOrig[i].z;
2440
+ int indent = ann.aOrig[i].indent + 1;
24352441
int n = ann.aOrig[i].n;
24362442
struct AnnVers *p;
24372443
if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
24382444
p = ann.aVers + iVers;
24392445
if( bBlame ){
24402446
if( iVers>=0 ){
2441
- fossil_print("%.10s %s %13.13s: %.*s\n",
2442
- fileVers ? p->zFUuid : p->zMUuid, p->zDate, p->zUser, n, z);
2447
+ fossil_print("%.10s %s %13.13s:%*s%.*s\n",
2448
+ fileVers ? p->zFUuid : p->zMUuid, p->zDate, p->zUser, indent, " ", n, z);
24432449
}else{
2444
- fossil_print("%35s %.*s\n", "", n, z);
2450
+ fossil_print("%35s %*s%.*s\n", "", indent, " ", n, z);
24452451
}
24462452
}else{
24472453
if( iVers>=0 ){
2448
- fossil_print("%.10s %s %5d: %.*s\n",
2449
- fileVers ? p->zFUuid : p->zMUuid, p->zDate, i+1, n, z);
2454
+ fossil_print("%.10s %s %5d:%*s%.*s\n",
2455
+ fileVers ? p->zFUuid : p->zMUuid, p->zDate, i+1, indent, " ", n, z);
24502456
}else{
2451
- fossil_print("%21s %5d: %.*s\n",
2452
- "", i+1, n, z);
2457
+ fossil_print("%21s %5d:%*s%.*s\n",
2458
+ "", i+1, indent, " ", n, z);
24532459
}
24542460
}
24552461
}
24562462
}
24572463
--- src/diff.c
+++ src/diff.c
@@ -77,11 +77,11 @@
77 */
78 typedef struct DLine DLine;
79 struct DLine {
80 const char *z; /* The text of the line */
81 unsigned int h; /* Hash of the line */
82 unsigned int indent; /* Indent of the line. Only !=0 with --ignore-space-at sol option */
83 unsigned int iNext; /* 1+(Index of next line with same the same hash) */
84
85 /* an array of DLine elements serves two purposes. The fields
86 ** above are one per line of input text. But each entry is also
87 ** a bucket in a hash table, as follows: */
@@ -1972,11 +1972,14 @@
1972 typedef struct Annotator Annotator;
1973 struct Annotator {
1974 DContext c; /* The diff-engine context */
1975 struct AnnLine { /* Lines of the original files... */
1976 const char *z; /* The text of the line */
1977 short int n; /* Number of bytes (omitting trailing space and \n) */
 
 
 
1978 short int iVers; /* Level at which tag was set */
1979 } *aOrig;
1980 int nOrig; /* Number of elements in aOrig[] */
1981 int nVers; /* Number of versions analyzed */
1982 int bLimit; /* True if the iLimit was reached */
@@ -2007,10 +2010,11 @@
2007 }
2008 p->aOrig = fossil_malloc( sizeof(p->aOrig[0])*p->c.nTo );
2009 for(i=0; i<p->c.nTo; i++){
2010 p->aOrig[i].z = p->c.aTo[i].z;
2011 p->aOrig[i].n = p->c.aTo[i].h & LENGTH_MASK;
 
2012 p->aOrig[i].iVers = -1;
2013 }
2014 p->nOrig = p->c.nTo;
2015 return 0;
2016 }
@@ -2312,10 +2316,11 @@
2312 @ <pre>
2313 for(i=0; i<ann.nOrig; i++){
2314 int iVers = ann.aOrig[i].iVers;
2315 char *z = (char*)ann.aOrig[i].z;
2316 int n = ann.aOrig[i].n;
 
2317 char zPrefix[300];
2318 z[n] = 0;
2319 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2320
2321 if( bBlame ){
@@ -2326,26 +2331,26 @@
2326 "<span style='background-color:%s'>"
2327 "%s%.10s</a> %s</span> %13.13s:",
2328 p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
2329 fossil_free(zLink);
2330 }else{
2331 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s", "");
2332 }
2333 }else{
2334 if( iVers>=0 ){
2335 struct AnnVers *p = ann.aVers+iVers;
2336 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2337 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2338 "<span style='background-color:%s'>"
2339 "%s%.10s</a> %s</span> %4d:",
2340 p->zBgColor, zLink, p->zMUuid, p->zDate, i+1);
2341 fossil_free(zLink);
2342 }else{
2343 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:", "", i+1);
2344 }
2345 }
2346 @ %s(zPrefix) %h(z)
2347
2348 }
2349 @ </pre>
2350 style_footer();
2351 }
@@ -2430,27 +2435,28 @@
2430 fossil_print("---------------------------------------------------\n");
2431 }
2432 for(i=0; i<ann.nOrig; i++){
2433 int iVers = ann.aOrig[i].iVers;
2434 char *z = (char*)ann.aOrig[i].z;
 
2435 int n = ann.aOrig[i].n;
2436 struct AnnVers *p;
2437 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2438 p = ann.aVers + iVers;
2439 if( bBlame ){
2440 if( iVers>=0 ){
2441 fossil_print("%.10s %s %13.13s: %.*s\n",
2442 fileVers ? p->zFUuid : p->zMUuid, p->zDate, p->zUser, n, z);
2443 }else{
2444 fossil_print("%35s %.*s\n", "", n, z);
2445 }
2446 }else{
2447 if( iVers>=0 ){
2448 fossil_print("%.10s %s %5d: %.*s\n",
2449 fileVers ? p->zFUuid : p->zMUuid, p->zDate, i+1, n, z);
2450 }else{
2451 fossil_print("%21s %5d: %.*s\n",
2452 "", i+1, n, z);
2453 }
2454 }
2455 }
2456 }
2457
--- src/diff.c
+++ src/diff.c
@@ -77,11 +77,11 @@
77 */
78 typedef struct DLine DLine;
79 struct DLine {
80 const char *z; /* The text of the line */
81 unsigned int h; /* Hash of the line */
82 unsigned short indent; /* Indent of the line. Only !=0 with --ignore-space-at sol option */
83 unsigned int iNext; /* 1+(Index of next line with same the same hash) */
84
85 /* an array of DLine elements serves two purposes. The fields
86 ** above are one per line of input text. But each entry is also
87 ** a bucket in a hash table, as follows: */
@@ -1972,11 +1972,14 @@
1972 typedef struct Annotator Annotator;
1973 struct Annotator {
1974 DContext c; /* The diff-engine context */
1975 struct AnnLine { /* Lines of the original files... */
1976 const char *z; /* The text of the line */
1977 short int n; /* Number of bytes. Whether this omits sol/eol spacing
1978 depends on the diffFlags) */
1979 unsigned short indent; /* Indenting (number of initial spaces, only used
1980 if sol-spacing is ignored in the diffFlags) */
1981 short int iVers; /* Level at which tag was set */
1982 } *aOrig;
1983 int nOrig; /* Number of elements in aOrig[] */
1984 int nVers; /* Number of versions analyzed */
1985 int bLimit; /* True if the iLimit was reached */
@@ -2007,10 +2010,11 @@
2010 }
2011 p->aOrig = fossil_malloc( sizeof(p->aOrig[0])*p->c.nTo );
2012 for(i=0; i<p->c.nTo; i++){
2013 p->aOrig[i].z = p->c.aTo[i].z;
2014 p->aOrig[i].n = p->c.aTo[i].h & LENGTH_MASK;
2015 p->aOrig[i].indent = p->c.aTo[i].indent;
2016 p->aOrig[i].iVers = -1;
2017 }
2018 p->nOrig = p->c.nTo;
2019 return 0;
2020 }
@@ -2312,10 +2316,11 @@
2316 @ <pre>
2317 for(i=0; i<ann.nOrig; i++){
2318 int iVers = ann.aOrig[i].iVers;
2319 char *z = (char*)ann.aOrig[i].z;
2320 int n = ann.aOrig[i].n;
2321 int indent = ann.aOrig[i].indent+1;
2322 char zPrefix[300];
2323 z[n] = 0;
2324 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2325
2326 if( bBlame ){
@@ -2326,26 +2331,26 @@
2331 "<span style='background-color:%s'>"
2332 "%s%.10s</a> %s</span> %13.13s:",
2333 p->zBgColor, zLink, p->zMUuid, p->zDate, p->zUser);
2334 fossil_free(zLink);
2335 }else{
2336 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%36s%*s", indent, " ");
2337 }
2338 }else{
2339 if( iVers>=0 ){
2340 struct AnnVers *p = ann.aVers+iVers;
2341 char *zLink = xhref("target='infowindow'", "%R/info/%S", p->zMUuid);
2342 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
2343 "<span style='background-color:%s'>"
2344 "%s%.10s</a> %s</span> %4d:%*s",
2345 p->zBgColor, zLink, p->zMUuid, p->zDate, i+1, indent, " ");
2346 fossil_free(zLink);
2347 }else{
2348 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%22s%4d:%*s", "", i+1, indent, " ");
2349 }
2350 }
2351 @ %s(zPrefix)%h(z)
2352
2353 }
2354 @ </pre>
2355 style_footer();
2356 }
@@ -2430,27 +2435,28 @@
2435 fossil_print("---------------------------------------------------\n");
2436 }
2437 for(i=0; i<ann.nOrig; i++){
2438 int iVers = ann.aOrig[i].iVers;
2439 char *z = (char*)ann.aOrig[i].z;
2440 int indent = ann.aOrig[i].indent + 1;
2441 int n = ann.aOrig[i].n;
2442 struct AnnVers *p;
2443 if( iLimit>ann.nVers && iVers<0 ) iVers = ann.nVers-1;
2444 p = ann.aVers + iVers;
2445 if( bBlame ){
2446 if( iVers>=0 ){
2447 fossil_print("%.10s %s %13.13s:%*s%.*s\n",
2448 fileVers ? p->zFUuid : p->zMUuid, p->zDate, p->zUser, indent, " ", n, z);
2449 }else{
2450 fossil_print("%35s %*s%.*s\n", "", indent, " ", n, z);
2451 }
2452 }else{
2453 if( iVers>=0 ){
2454 fossil_print("%.10s %s %5d:%*s%.*s\n",
2455 fileVers ? p->zFUuid : p->zMUuid, p->zDate, i+1, indent, " ", n, z);
2456 }else{
2457 fossil_print("%21s %5d:%*s%.*s\n",
2458 "", i+1, indent, " ", n, z);
2459 }
2460 }
2461 }
2462 }
2463
+25
--- src/shell.c
+++ src/shell.c
@@ -444,10 +444,11 @@
444444
** state and mode information.
445445
*/
446446
struct callback_data {
447447
sqlite3 *db; /* The database */
448448
int echoOn; /* True to echo input commands */
449
+ int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL statement */
449450
int statsOn; /* True to display memory stats before each finalize */
450451
int cnt; /* Number of records displayed so far */
451452
FILE *out; /* Write results here */
452453
FILE *traceOut; /* Output for sqlite3_trace() */
453454
int nErr; /* Number of errors seen */
@@ -1299,10 +1300,27 @@
12991300
/* echo the sql statement if echo on */
13001301
if( pArg && pArg->echoOn ){
13011302
const char *zStmtSql = sqlite3_sql(pStmt);
13021303
fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
13031304
}
1305
+
1306
+ /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1307
+ if( pArg && pArg->autoEQP ){
1308
+ sqlite3_stmt *pExplain;
1309
+ char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt));
1310
+ rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1311
+ if( rc==SQLITE_OK ){
1312
+ while( sqlite3_step(pExplain)==SQLITE_ROW ){
1313
+ fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1314
+ fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
1315
+ fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
1316
+ fprintf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1317
+ }
1318
+ }
1319
+ sqlite3_finalize(pExplain);
1320
+ sqlite3_free(zEQP);
1321
+ }
13041322
13051323
/* Output TESTCTRL_EXPLAIN text of requested */
13061324
if( pArg && pArg->mode==MODE_Explain ){
13071325
const char *zExplain = 0;
13081326
sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
@@ -2298,10 +2316,14 @@
22982316
}else
22992317
23002318
if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
23012319
p->echoOn = booleanValue(azArg[1]);
23022320
}else
2321
+
2322
+ if( c=='e' && strncmp(azArg[0], "eqp", n)==0 && nArg>1 && nArg<3 ){
2323
+ p->autoEQP = booleanValue(azArg[1]);
2324
+ }else
23032325
23042326
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
23052327
if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
23062328
rc = 2;
23072329
}else
@@ -2871,10 +2893,11 @@
28712893
}else
28722894
28732895
if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
28742896
int i;
28752897
fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
2898
+ fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
28762899
fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
28772900
fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
28782901
fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
28792902
fprintf(p->out,"%9.9s: ", "nullvalue");
28802903
output_c_string(p->out, p->nullvalue);
@@ -3708,10 +3731,12 @@
37083731
data.showHeader = 1;
37093732
}else if( strcmp(z,"-noheader")==0 ){
37103733
data.showHeader = 0;
37113734
}else if( strcmp(z,"-echo")==0 ){
37123735
data.echoOn = 1;
3736
+ }else if( strcmp(z,"-eqp")==0 ){
3737
+ data.autoEQP = 1;
37133738
}else if( strcmp(z,"-stats")==0 ){
37143739
data.statsOn = 1;
37153740
}else if( strcmp(z,"-bail")==0 ){
37163741
bail_on_error = 1;
37173742
}else if( strcmp(z,"-version")==0 ){
37183743
--- src/shell.c
+++ src/shell.c
@@ -444,10 +444,11 @@
444 ** state and mode information.
445 */
446 struct callback_data {
447 sqlite3 *db; /* The database */
448 int echoOn; /* True to echo input commands */
 
449 int statsOn; /* True to display memory stats before each finalize */
450 int cnt; /* Number of records displayed so far */
451 FILE *out; /* Write results here */
452 FILE *traceOut; /* Output for sqlite3_trace() */
453 int nErr; /* Number of errors seen */
@@ -1299,10 +1300,27 @@
1299 /* echo the sql statement if echo on */
1300 if( pArg && pArg->echoOn ){
1301 const char *zStmtSql = sqlite3_sql(pStmt);
1302 fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1303 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1304
1305 /* Output TESTCTRL_EXPLAIN text of requested */
1306 if( pArg && pArg->mode==MODE_Explain ){
1307 const char *zExplain = 0;
1308 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
@@ -2298,10 +2316,14 @@
2298 }else
2299
2300 if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
2301 p->echoOn = booleanValue(azArg[1]);
2302 }else
 
 
 
 
2303
2304 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
2305 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
2306 rc = 2;
2307 }else
@@ -2871,10 +2893,11 @@
2871 }else
2872
2873 if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
2874 int i;
2875 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
 
2876 fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
2877 fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
2878 fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
2879 fprintf(p->out,"%9.9s: ", "nullvalue");
2880 output_c_string(p->out, p->nullvalue);
@@ -3708,10 +3731,12 @@
3708 data.showHeader = 1;
3709 }else if( strcmp(z,"-noheader")==0 ){
3710 data.showHeader = 0;
3711 }else if( strcmp(z,"-echo")==0 ){
3712 data.echoOn = 1;
 
 
3713 }else if( strcmp(z,"-stats")==0 ){
3714 data.statsOn = 1;
3715 }else if( strcmp(z,"-bail")==0 ){
3716 bail_on_error = 1;
3717 }else if( strcmp(z,"-version")==0 ){
3718
--- src/shell.c
+++ src/shell.c
@@ -444,10 +444,11 @@
444 ** state and mode information.
445 */
446 struct callback_data {
447 sqlite3 *db; /* The database */
448 int echoOn; /* True to echo input commands */
449 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL statement */
450 int statsOn; /* True to display memory stats before each finalize */
451 int cnt; /* Number of records displayed so far */
452 FILE *out; /* Write results here */
453 FILE *traceOut; /* Output for sqlite3_trace() */
454 int nErr; /* Number of errors seen */
@@ -1299,10 +1300,27 @@
1300 /* echo the sql statement if echo on */
1301 if( pArg && pArg->echoOn ){
1302 const char *zStmtSql = sqlite3_sql(pStmt);
1303 fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1304 }
1305
1306 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1307 if( pArg && pArg->autoEQP ){
1308 sqlite3_stmt *pExplain;
1309 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt));
1310 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1311 if( rc==SQLITE_OK ){
1312 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1313 fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1314 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
1315 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
1316 fprintf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1317 }
1318 }
1319 sqlite3_finalize(pExplain);
1320 sqlite3_free(zEQP);
1321 }
1322
1323 /* Output TESTCTRL_EXPLAIN text of requested */
1324 if( pArg && pArg->mode==MODE_Explain ){
1325 const char *zExplain = 0;
1326 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
@@ -2298,10 +2316,14 @@
2316 }else
2317
2318 if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
2319 p->echoOn = booleanValue(azArg[1]);
2320 }else
2321
2322 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 && nArg>1 && nArg<3 ){
2323 p->autoEQP = booleanValue(azArg[1]);
2324 }else
2325
2326 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
2327 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
2328 rc = 2;
2329 }else
@@ -2871,10 +2893,11 @@
2893 }else
2894
2895 if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
2896 int i;
2897 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
2898 fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
2899 fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
2900 fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
2901 fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
2902 fprintf(p->out,"%9.9s: ", "nullvalue");
2903 output_c_string(p->out, p->nullvalue);
@@ -3708,10 +3731,12 @@
3731 data.showHeader = 1;
3732 }else if( strcmp(z,"-noheader")==0 ){
3733 data.showHeader = 0;
3734 }else if( strcmp(z,"-echo")==0 ){
3735 data.echoOn = 1;
3736 }else if( strcmp(z,"-eqp")==0 ){
3737 data.autoEQP = 1;
3738 }else if( strcmp(z,"-stats")==0 ){
3739 data.statsOn = 1;
3740 }else if( strcmp(z,"-bail")==0 ){
3741 bail_on_error = 1;
3742 }else if( strcmp(z,"-version")==0 ){
3743
+701 -237
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -189,11 +189,11 @@
189189
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190190
** [sqlite_version()] and [sqlite_source_id()].
191191
*/
192192
#define SQLITE_VERSION "3.8.4"
193193
#define SQLITE_VERSION_NUMBER 3008004
194
-#define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
194
+#define SQLITE_SOURCE_ID "2014-03-04 13:18:23 9830c343bc954b828f6ca752f8ae63e2c0a980c1"
195195
196196
/*
197197
** CAPI3REF: Run-Time Library Version Numbers
198198
** KEYWORDS: sqlite3_version, sqlite3_sourceid
199199
**
@@ -9334,12 +9334,15 @@
93349334
#ifndef SQLITE_OMIT_TRACE
93359335
SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
93369336
#endif
93379337
93389338
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9339
-SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
9339
+SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,const UnpackedRecord*,int);
93409340
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
9341
+
9342
+typedef int (*RecordCompare)(int,const void*,const UnpackedRecord*,int);
9343
+SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
93419344
93429345
#ifndef SQLITE_OMIT_TRIGGER
93439346
SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
93449347
#endif
93459348
@@ -10950,23 +10953,23 @@
1095010953
** the OP_MakeRecord opcode of the VDBE and is disassembled by the
1095110954
** OP_Column opcode.
1095210955
**
1095310956
** This structure holds a record that has already been disassembled
1095410957
** into its constituent fields.
10958
+**
10959
+** The r1 and r2 member variables are only used by the optimized comparison
10960
+** functions vdbeRecordCompareInt() and vdbeRecordCompareString().
1095510961
*/
1095610962
struct UnpackedRecord {
1095710963
KeyInfo *pKeyInfo; /* Collation and sort-order information */
1095810964
u16 nField; /* Number of entries in apMem[] */
10959
- u8 flags; /* Boolean settings. UNPACKED_... below */
10965
+ i8 default_rc; /* Comparison result if keys are equal */
1096010966
Mem *aMem; /* Values */
10967
+ int r1; /* Value to return if (lhs > rhs) */
10968
+ int r2; /* Value to return if (rhs < lhs) */
1096110969
};
1096210970
10963
-/*
10964
-** Allowed values of UnpackedRecord.flags
10965
-*/
10966
-#define UNPACKED_INCRKEY 0x01 /* Make this key an epsilon larger */
10967
-#define UNPACKED_PREFIX_MATCH 0x02 /* A prefix match is considered OK */
1096810971
1096910972
/*
1097010973
** Each SQL index is represented in memory by an
1097110974
** instance of the following structure.
1097210975
**
@@ -13840,11 +13843,11 @@
1384013843
** the following flags must be set to determine the memory management
1384113844
** policy for Mem.z. The MEM_Term flag tells us whether or not the
1384213845
** string is \000 or \u0000 terminated
1384313846
*/
1384413847
#define MEM_Term 0x0200 /* String rep is nul terminated */
13845
-#define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
13848
+#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
1384613849
#define MEM_Static 0x0800 /* Mem.z points to a static string */
1384713850
#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
1384813851
#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
1384913852
#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
1385013853
#ifdef SQLITE_OMIT_INCRBLOB
@@ -14023,11 +14026,11 @@
1402314026
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
1402414027
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
1402514028
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
1402614029
1402714030
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
14028
-SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
14031
+SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,const UnpackedRecord*,int*);
1402914032
SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
1403014033
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
1403114034
SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
1403214035
SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
1403314036
SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
@@ -14088,10 +14091,11 @@
1408814091
# define sqlite3VdbeLeave(X)
1408914092
#endif
1409014093
1409114094
#ifdef SQLITE_DEBUG
1409214095
SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
14096
+SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem*);
1409314097
#endif
1409414098
1409514099
#ifndef SQLITE_OMIT_FOREIGN_KEY
1409614100
SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
1409714101
#else
@@ -21471,11 +21475,11 @@
2147121475
assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
2147221476
2147321477
sqlite3VdbeMemRelease(pMem);
2147421478
pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
2147521479
pMem->enc = desiredEnc;
21476
- pMem->flags |= (MEM_Term|MEM_Dyn);
21480
+ pMem->flags |= (MEM_Term);
2147721481
pMem->z = (char*)zOut;
2147821482
pMem->zMalloc = pMem->z;
2147921483
2148021484
translate_out:
2148121485
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
@@ -21599,11 +21603,10 @@
2159921603
sqlite3VdbeMemRelease(&m);
2160021604
m.z = 0;
2160121605
}
2160221606
assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
2160321607
assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
21604
- assert( (m.flags & MEM_Dyn)!=0 || db->mallocFailed );
2160521608
assert( m.z || db->mallocFailed );
2160621609
return m.z;
2160721610
}
2160821611
2160921612
/*
@@ -55305,10 +55308,11 @@
5530555308
i64 intKey, /* The table key */
5530655309
int biasRight, /* If true, bias the search to the high end */
5530755310
int *pRes /* Write search results here */
5530855311
){
5530955312
int rc;
55313
+ RecordCompare xRecordCompare;
5531055314
5531155315
assert( cursorHoldsMutex(pCur) );
5531255316
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5531355317
assert( pRes );
5531455318
assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
@@ -55325,10 +55329,20 @@
5532555329
if( pCur->atLast && pCur->info.nKey<intKey ){
5532655330
*pRes = -1;
5532755331
return SQLITE_OK;
5532855332
}
5532955333
}
55334
+
55335
+ if( pIdxKey ){
55336
+ xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
55337
+ assert( pIdxKey->default_rc==1
55338
+ || pIdxKey->default_rc==0
55339
+ || pIdxKey->default_rc==-1
55340
+ );
55341
+ }else{
55342
+ xRecordCompare = 0; /* Not actually used. Avoids a compiler warning. */
55343
+ }
5533055344
5533155345
rc = moveToRoot(pCur);
5533255346
if( rc ){
5533355347
return rc;
5533455348
}
@@ -55410,18 +55424,18 @@
5541055424
if( nCell<=pPage->max1bytePayload ){
5541155425
/* This branch runs if the record-size field of the cell is a
5541255426
** single byte varint and the record fits entirely on the main
5541355427
** b-tree page. */
5541455428
testcase( pCell+nCell+1==pPage->aDataEnd );
55415
- c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
55429
+ c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey, 0);
5541655430
}else if( !(pCell[1] & 0x80)
5541755431
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
5541855432
){
5541955433
/* The record-size field is a 2 byte varint and the record
5542055434
** fits entirely on the main b-tree page. */
5542155435
testcase( pCell+nCell+2==pPage->aDataEnd );
55422
- c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
55436
+ c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey, 0);
5542355437
}else{
5542455438
/* The record flows over onto one or more overflow pages. In
5542555439
** this case the whole cell needs to be parsed, a buffer allocated
5542655440
** and accessPayload() used to retrieve the record into the
5542755441
** buffer before VdbeRecordCompare() can be called. */
@@ -55438,11 +55452,11 @@
5543855452
rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
5543955453
if( rc ){
5544055454
sqlite3_free(pCellKey);
5544155455
goto moveto_finish;
5544255456
}
55443
- c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
55457
+ c = xRecordCompare(nCell, pCellKey, pIdxKey, 0);
5544455458
sqlite3_free(pCellKey);
5544555459
}
5544655460
if( c<0 ){
5544755461
lwr = idx+1;
5544855462
}else if( c>0 ){
@@ -60001,10 +60015,46 @@
6000160015
** This file contains code use to manipulate "Mem" structure. A "Mem"
6000260016
** stores a single value in the VDBE. Mem is an opaque structure visible
6000360017
** only within the VDBE. Interface routines refer to a Mem using the
6000460018
** name sqlite_value
6000560019
*/
60020
+
60021
+#ifdef SQLITE_DEBUG
60022
+/*
60023
+** Check invariants on a Mem object.
60024
+**
60025
+** This routine is intended for use inside of assert() statements, like
60026
+** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
60027
+*/
60028
+SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
60029
+ /* The MEM_Dyn bit is set if and only if Mem.xDel is a non-NULL destructor
60030
+ ** function for Mem.z
60031
+ */
60032
+ assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
60033
+ assert( (p->flags & MEM_Dyn)!=0 || p->xDel==0 );
60034
+
60035
+ /* If p holds a string or blob, the Mem.z must point to exactly
60036
+ ** one of the following:
60037
+ **
60038
+ ** (1) Memory in Mem.zMalloc and managed by the Mem object
60039
+ ** (2) Memory to be freed using Mem.xDel
60040
+ ** (3) An ephermal string or blob
60041
+ ** (4) A static string or blob
60042
+ */
60043
+ if( (p->flags & (MEM_Str|MEM_Blob)) && p->z!=0 ){
60044
+ assert(
60045
+ ((p->z==p->zMalloc)? 1 : 0) +
60046
+ ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
60047
+ ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
60048
+ ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
60049
+ );
60050
+ }
60051
+
60052
+ return 1;
60053
+}
60054
+#endif
60055
+
6000660056
6000760057
/*
6000860058
** If pMem is an object with a valid string representation, this routine
6000960059
** ensures the internal encoding for the string representation is
6001060060
** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
@@ -60051,16 +60101,11 @@
6005160101
** pMem->z into the new allocation. pMem must be either a string or
6005260102
** blob if bPreserve is true. If bPreserve is false, any prior content
6005360103
** in pMem->z is discarded.
6005460104
*/
6005560105
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
60056
- assert( 1 >=
60057
- ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
60058
- (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
60059
- ((pMem->flags&MEM_Ephem) ? 1 : 0) +
60060
- ((pMem->flags&MEM_Static) ? 1 : 0)
60061
- );
60106
+ assert( sqlite3VdbeCheckMemInvariants(pMem) );
6006260107
assert( (pMem->flags&MEM_RowSet)==0 );
6006360108
6006460109
/* If the bPreserve flag is set to true, then the memory cell must already
6006560110
** contain a valid string or blob value. */
6006660111
assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
@@ -60074,26 +60119,26 @@
6007460119
}else{
6007560120
sqlite3DbFree(pMem->db, pMem->zMalloc);
6007660121
pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
6007760122
}
6007860123
if( pMem->zMalloc==0 ){
60079
- sqlite3VdbeMemRelease(pMem);
60124
+ VdbeMemRelease(pMem);
6008060125
pMem->flags = MEM_Null;
6008160126
return SQLITE_NOMEM;
6008260127
}
6008360128
}
6008460129
6008560130
if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
6008660131
memcpy(pMem->zMalloc, pMem->z, pMem->n);
6008760132
}
60088
- if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
60089
- assert( pMem->xDel!=SQLITE_DYNAMIC );
60133
+ if( (pMem->flags&MEM_Dyn)!=0 ){
60134
+ assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
6009060135
pMem->xDel((void *)(pMem->z));
6009160136
}
6009260137
6009360138
pMem->z = pMem->zMalloc;
60094
- pMem->flags &= ~(MEM_Ephem|MEM_Static);
60139
+ pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
6009560140
pMem->xDel = 0;
6009660141
return SQLITE_OK;
6009760142
}
6009860143
6009960144
/*
@@ -60258,13 +60303,13 @@
6025860303
assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
6025960304
if( p->flags&MEM_Agg ){
6026060305
sqlite3VdbeMemFinalize(p, p->u.pDef);
6026160306
assert( (p->flags & MEM_Agg)==0 );
6026260307
sqlite3VdbeMemRelease(p);
60263
- }else if( p->flags&MEM_Dyn && p->xDel ){
60308
+ }else if( p->flags&MEM_Dyn ){
6026460309
assert( (p->flags&MEM_RowSet)==0 );
60265
- assert( p->xDel!=SQLITE_DYNAMIC );
60310
+ assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
6026660311
p->xDel((void *)p->z);
6026760312
p->xDel = 0;
6026860313
}else if( p->flags&MEM_RowSet ){
6026960314
sqlite3RowSetClear(p->u.pRowSet);
6027060315
}else if( p->flags&MEM_Frame ){
@@ -60276,10 +60321,11 @@
6027660321
** Release any memory held by the Mem. This may leave the Mem in an
6027760322
** inconsistent state, for example with (Mem.z==0) and
6027860323
** (Mem.memType==MEM_Str).
6027960324
*/
6028060325
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
60326
+ assert( sqlite3VdbeCheckMemInvariants(p) );
6028160327
VdbeMemRelease(p);
6028260328
if( p->zMalloc ){
6028360329
sqlite3DbFree(p->db, p->zMalloc);
6028460330
p->zMalloc = 0;
6028560331
}
@@ -60613,10 +60659,11 @@
6061360659
6061460660
assert( (pFrom->flags & MEM_RowSet)==0 );
6061560661
VdbeMemRelease(pTo);
6061660662
memcpy(pTo, pFrom, MEMCELLSIZE);
6061760663
pTo->flags &= ~MEM_Dyn;
60664
+ pTo->xDel = 0;
6061860665
6061960666
if( pTo->flags&(MEM_Str|MEM_Blob) ){
6062060667
if( 0==(pFrom->flags&MEM_Static) ){
6062160668
pTo->flags |= MEM_Ephem;
6062260669
rc = sqlite3VdbeMemMakeWriteable(pTo);
@@ -60738,123 +60785,10 @@
6073860785
}
6073960786
6074060787
return SQLITE_OK;
6074160788
}
6074260789
60743
-/*
60744
-** Compare the values contained by the two memory cells, returning
60745
-** negative, zero or positive if pMem1 is less than, equal to, or greater
60746
-** than pMem2. Sorting order is NULL's first, followed by numbers (integers
60747
-** and reals) sorted numerically, followed by text ordered by the collating
60748
-** sequence pColl and finally blob's ordered by memcmp().
60749
-**
60750
-** Two NULL values are considered equal by this function.
60751
-*/
60752
-SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
60753
- int rc;
60754
- int f1, f2;
60755
- int combined_flags;
60756
-
60757
- f1 = pMem1->flags;
60758
- f2 = pMem2->flags;
60759
- combined_flags = f1|f2;
60760
- assert( (combined_flags & MEM_RowSet)==0 );
60761
-
60762
- /* If one value is NULL, it is less than the other. If both values
60763
- ** are NULL, return 0.
60764
- */
60765
- if( combined_flags&MEM_Null ){
60766
- return (f2&MEM_Null) - (f1&MEM_Null);
60767
- }
60768
-
60769
- /* If one value is a number and the other is not, the number is less.
60770
- ** If both are numbers, compare as reals if one is a real, or as integers
60771
- ** if both values are integers.
60772
- */
60773
- if( combined_flags&(MEM_Int|MEM_Real) ){
60774
- double r1, r2;
60775
- if( (f1 & f2 & MEM_Int)!=0 ){
60776
- if( pMem1->u.i < pMem2->u.i ) return -1;
60777
- if( pMem1->u.i > pMem2->u.i ) return 1;
60778
- return 0;
60779
- }
60780
- if( (f1&MEM_Real)!=0 ){
60781
- r1 = pMem1->r;
60782
- }else if( (f1&MEM_Int)!=0 ){
60783
- r1 = (double)pMem1->u.i;
60784
- }else{
60785
- return 1;
60786
- }
60787
- if( (f2&MEM_Real)!=0 ){
60788
- r2 = pMem2->r;
60789
- }else if( (f2&MEM_Int)!=0 ){
60790
- r2 = (double)pMem2->u.i;
60791
- }else{
60792
- return -1;
60793
- }
60794
- if( r1<r2 ) return -1;
60795
- if( r1>r2 ) return 1;
60796
- return 0;
60797
- }
60798
-
60799
- /* If one value is a string and the other is a blob, the string is less.
60800
- ** If both are strings, compare using the collating functions.
60801
- */
60802
- if( combined_flags&MEM_Str ){
60803
- if( (f1 & MEM_Str)==0 ){
60804
- return 1;
60805
- }
60806
- if( (f2 & MEM_Str)==0 ){
60807
- return -1;
60808
- }
60809
-
60810
- assert( pMem1->enc==pMem2->enc );
60811
- assert( pMem1->enc==SQLITE_UTF8 ||
60812
- pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
60813
-
60814
- /* The collation sequence must be defined at this point, even if
60815
- ** the user deletes the collation sequence after the vdbe program is
60816
- ** compiled (this was not always the case).
60817
- */
60818
- assert( !pColl || pColl->xCmp );
60819
-
60820
- if( pColl ){
60821
- if( pMem1->enc==pColl->enc ){
60822
- /* The strings are already in the correct encoding. Call the
60823
- ** comparison function directly */
60824
- return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
60825
- }else{
60826
- const void *v1, *v2;
60827
- int n1, n2;
60828
- Mem c1;
60829
- Mem c2;
60830
- memset(&c1, 0, sizeof(c1));
60831
- memset(&c2, 0, sizeof(c2));
60832
- sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
60833
- sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
60834
- v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
60835
- n1 = v1==0 ? 0 : c1.n;
60836
- v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
60837
- n2 = v2==0 ? 0 : c2.n;
60838
- rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
60839
- sqlite3VdbeMemRelease(&c1);
60840
- sqlite3VdbeMemRelease(&c2);
60841
- return rc;
60842
- }
60843
- }
60844
- /* If a NULL pointer was passed as the collate function, fall through
60845
- ** to the blob case and use memcmp(). */
60846
- }
60847
-
60848
- /* Both values must be blobs. Compare using memcmp(). */
60849
- rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
60850
- if( rc==0 ){
60851
- rc = pMem1->n - pMem2->n;
60852
- }
60853
- return rc;
60854
-}
60855
-
6085660790
/*
6085760791
** Move data out of a btree key or data field and into a Mem structure.
6085860792
** The data or key is taken from the entry that pCur is currently pointing
6085960793
** to. offset and amt determine what portion of the data or key to retrieve.
6086060794
** key is true to get the key or false to get data. The result is written
@@ -60891,26 +60825,27 @@
6089160825
6089260826
if( offset+amt<=available ){
6089360827
sqlite3VdbeMemRelease(pMem);
6089460828
pMem->z = &zData[offset];
6089560829
pMem->flags = MEM_Blob|MEM_Ephem;
60830
+ pMem->n = (int)amt;
6089660831
}else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60897
- pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
60898
- pMem->enc = 0;
60899
- pMem->memType = MEM_Blob;
6090060832
if( key ){
6090160833
rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
6090260834
}else{
6090360835
rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
6090460836
}
60905
- pMem->z[amt] = 0;
60906
- pMem->z[amt+1] = 0;
60907
- if( rc!=SQLITE_OK ){
60837
+ if( rc==SQLITE_OK ){
60838
+ pMem->z[amt] = 0;
60839
+ pMem->z[amt+1] = 0;
60840
+ pMem->flags = MEM_Blob|MEM_Term;
60841
+ pMem->memType = MEM_Blob;
60842
+ pMem->n = (int)amt;
60843
+ }else{
6090860844
sqlite3VdbeMemRelease(pMem);
6090960845
}
6091060846
}
60911
- pMem->n = (int)amt;
6091260847
6091360848
return rc;
6091460849
}
6091560850
6091660851
/* This function is only available internally, it is not part of the
@@ -61010,11 +60945,10 @@
6101060945
if( pRec ){
6101160946
pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
6101260947
if( pRec->pKeyInfo ){
6101360948
assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
6101460949
assert( pRec->pKeyInfo->enc==ENC(db) );
61015
- pRec->flags = UNPACKED_PREFIX_MATCH;
6101660950
pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
6101760951
for(i=0; i<nCol; i++){
6101860952
pRec->aMem[i].flags = MEM_Null;
6101960953
pRec->aMem[i].memType = MEM_Null;
6102060954
pRec->aMem[i].db = db;
@@ -62591,10 +62525,11 @@
6259162525
}
6259262526
return;
6259362527
}
6259462528
for(pEnd=&p[N]; p<pEnd; p++){
6259562529
assert( (&p[1])==pEnd || p[0].db==p[1].db );
62530
+ assert( sqlite3VdbeCheckMemInvariants(p) );
6259662531
6259762532
/* This block is really an inlined version of sqlite3VdbeMemRelease()
6259862533
** that takes advantage of the fact that the memory cell value is
6259962534
** being set to NULL after releasing any dynamic resources.
6260062535
**
@@ -62784,11 +62719,11 @@
6278462719
6278562720
if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
6278662721
assert( p->db->mallocFailed );
6278762722
return SQLITE_ERROR;
6278862723
}
62789
- pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62724
+ pMem->flags = MEM_Str|MEM_Term;
6279062725
zP4 = displayP4(pOp, pMem->z, 32);
6279162726
if( zP4!=pMem->z ){
6279262727
sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
6279362728
}else{
6279462729
assert( pMem->z!=0 );
@@ -62801,11 +62736,11 @@
6280162736
if( p->explain==1 ){
6280262737
if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
6280362738
assert( p->db->mallocFailed );
6280462739
return SQLITE_ERROR;
6280562740
}
62806
- pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62741
+ pMem->flags = MEM_Str|MEM_Term;
6280762742
pMem->n = 2;
6280862743
sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
6280962744
pMem->memType = MEM_Str;
6281062745
pMem->enc = SQLITE_UTF8;
6281162746
pMem++;
@@ -62813,11 +62748,11 @@
6281362748
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6281462749
if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
6281562750
assert( p->db->mallocFailed );
6281662751
return SQLITE_ERROR;
6281762752
}
62818
- pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62753
+ pMem->flags = MEM_Str|MEM_Term;
6281962754
pMem->n = displayComment(pOp, zP4, pMem->z, 500);
6282062755
pMem->memType = MEM_Str;
6282162756
pMem->enc = SQLITE_UTF8;
6282262757
#else
6282362758
pMem->flags = MEM_Null; /* Comment */
@@ -64312,10 +64247,18 @@
6431264247
6431364248
/* NULL or constants 0 or 1 */
6431464249
return 0;
6431564250
}
6431664251
64252
+/* Input "x" is a sequence of unsigned characters that represent a
64253
+** big-endian integer. Return the equivalent native integer
64254
+*/
64255
+#define ONE_BYTE_INT(x) ((i8)(x)[0])
64256
+#define TWO_BYTE_INT(x) (256*(i8)((x)[0])|(x)[1])
64257
+#define THREE_BYTE_INT(x) (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2])
64258
+#define FOUR_BYTE_UINT(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
64259
+
6431764260
/*
6431864261
** Deserialize the data blob pointed to by buf as serial type serial_type
6431964262
** and store the result in pMem. Return the number of bytes read.
6432064263
*/
6432164264
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(
@@ -64323,46 +64266,40 @@
6432364266
u32 serial_type, /* Serial type to deserialize */
6432464267
Mem *pMem /* Memory cell to write value into */
6432564268
){
6432664269
u64 x;
6432764270
u32 y;
64328
- int i;
6432964271
switch( serial_type ){
6433064272
case 10: /* Reserved for future use */
6433164273
case 11: /* Reserved for future use */
6433264274
case 0: { /* NULL */
6433364275
pMem->flags = MEM_Null;
6433464276
break;
6433564277
}
6433664278
case 1: { /* 1-byte signed integer */
64337
- pMem->u.i = (signed char)buf[0];
64279
+ pMem->u.i = ONE_BYTE_INT(buf);
6433864280
pMem->flags = MEM_Int;
6433964281
return 1;
6434064282
}
6434164283
case 2: { /* 2-byte signed integer */
64342
- i = 256*(signed char)buf[0] | buf[1];
64343
- pMem->u.i = (i64)i;
64284
+ pMem->u.i = TWO_BYTE_INT(buf);
6434464285
pMem->flags = MEM_Int;
6434564286
return 2;
6434664287
}
6434764288
case 3: { /* 3-byte signed integer */
64348
- i = 65536*(signed char)buf[0] | (buf[1]<<8) | buf[2];
64349
- pMem->u.i = (i64)i;
64289
+ pMem->u.i = THREE_BYTE_INT(buf);
6435064290
pMem->flags = MEM_Int;
6435164291
return 3;
6435264292
}
6435364293
case 4: { /* 4-byte signed integer */
64354
- y = ((unsigned)buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
64294
+ y = FOUR_BYTE_UINT(buf);
6435564295
pMem->u.i = (i64)*(int*)&y;
6435664296
pMem->flags = MEM_Int;
6435764297
return 4;
6435864298
}
6435964299
case 5: { /* 6-byte signed integer */
64360
- x = 256*(signed char)buf[0] + buf[1];
64361
- y = ((unsigned)buf[2]<<24) | (buf[3]<<16) | (buf[4]<<8) | buf[5];
64362
- x = (x<<32) | y;
64363
- pMem->u.i = *(i64*)&x;
64300
+ pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
6436464301
pMem->flags = MEM_Int;
6436564302
return 6;
6436664303
}
6436764304
case 6: /* 8-byte signed integer */
6436864305
case 7: { /* IEEE floating point */
@@ -64376,12 +64313,12 @@
6437664313
static const double r1 = 1.0;
6437764314
u64 t2 = t1;
6437864315
swapMixedEndianFloat(t2);
6437964316
assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
6438064317
#endif
64381
- x = ((unsigned)buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
64382
- y = ((unsigned)buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7];
64318
+ x = FOUR_BYTE_UINT(buf);
64319
+ y = FOUR_BYTE_UINT(buf+4);
6438364320
x = (x<<32) | y;
6438464321
if( serial_type==6 ){
6438564322
pMem->u.i = *(i64*)&x;
6438664323
pMem->flags = MEM_Int;
6438764324
}else{
@@ -64473,11 +64410,11 @@
6447364410
u32 idx; /* Offset in aKey[] to read from */
6447464411
u16 u; /* Unsigned loop counter */
6447564412
u32 szHdr;
6447664413
Mem *pMem = p->aMem;
6447764414
64478
- p->flags = 0;
64415
+ p->default_rc = 0;
6447964416
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
6448064417
idx = getVarint32(aKey, szHdr);
6448164418
d = szHdr;
6448264419
u = 0;
6448364420
while( idx<szHdr && u<p->nField && d<=nKey ){
@@ -64494,30 +64431,22 @@
6449464431
}
6449564432
assert( u<=pKeyInfo->nField + 1 );
6449664433
p->nField = u;
6449764434
}
6449864435
64436
+#if SQLITE_DEBUG
6449964437
/*
64500
-** This function compares the two table rows or index records
64501
-** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
64502
-** or positive integer if key1 is less than, equal to or
64503
-** greater than key2. The {nKey1, pKey1} key must be a blob
64504
-** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
64505
-** key must be a parsed key such as obtained from
64506
-** sqlite3VdbeParseRecord.
64507
-**
64508
-** Key1 and Key2 do not have to contain the same number of fields.
64509
-** The key with fewer fields is usually compares less than the
64510
-** longer key. However if the UNPACKED_INCRKEY flags in pPKey2 is set
64511
-** and the common prefixes are equal, then key1 is less than key2.
64512
-** Or if the UNPACKED_MATCH_PREFIX flag is set and the prefixes are
64513
-** equal, then the keys are considered to be equal and
64514
-** the parts beyond the common prefix are ignored.
64438
+** This function compares two index or table record keys in the same way
64439
+** as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(),
64440
+** this function deserializes and compares values using the
64441
+** sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used
64442
+** in assert() statements to ensure that the optimized code in
64443
+** sqlite3VdbeRecordCompare() returns results with these two primitives.
6451564444
*/
64516
-SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
64445
+static int vdbeRecordCompareDebug(
6451764446
int nKey1, const void *pKey1, /* Left key */
64518
- UnpackedRecord *pPKey2 /* Right key */
64447
+ const UnpackedRecord *pPKey2 /* Right key */
6451964448
){
6452064449
u32 d1; /* Offset into aKey[] of next data element */
6452164450
u32 idx1; /* Offset into aKey[] of next header element */
6452264451
u32 szHdr1; /* Number of bytes in header */
6452364452
int i = 0;
@@ -64587,28 +64516,558 @@
6458764516
** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
6458864517
*/
6458964518
assert( mem1.zMalloc==0 );
6459064519
6459164520
/* rc==0 here means that one of the keys ran out of fields and
64592
- ** all the fields up to that point were equal. If the UNPACKED_INCRKEY
64593
- ** flag is set, then break the tie by treating key2 as larger.
64594
- ** If the UPACKED_PREFIX_MATCH flag is set, then keys with common prefixes
64595
- ** are considered to be equal. Otherwise, the longer key is the
64596
- ** larger. As it happens, the pPKey2 will always be the longer
64597
- ** if there is a difference.
64598
- */
64599
- assert( rc==0 );
64600
- if( pPKey2->flags & UNPACKED_INCRKEY ){
64601
- rc = -1;
64602
- }else if( pPKey2->flags & UNPACKED_PREFIX_MATCH ){
64603
- /* Leave rc==0 */
64604
- }else if( idx1<szHdr1 ){
64605
- rc = 1;
64606
- }
64607
- return rc;
64608
-}
64609
-
64521
+ ** all the fields up to that point were equal. Return the the default_rc
64522
+ ** value. */
64523
+ return pPKey2->default_rc;
64524
+}
64525
+#endif
64526
+
64527
+/*
64528
+** Both *pMem1 and *pMem2 contain string values. Compare the two values
64529
+** using the collation sequence pColl. As usual, return a negative , zero
64530
+** or positive value if *pMem1 is less than, equal to or greater than
64531
+** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
64532
+*/
64533
+static int vdbeCompareMemString(
64534
+ const Mem *pMem1,
64535
+ const Mem *pMem2,
64536
+ const CollSeq *pColl
64537
+){
64538
+ if( pMem1->enc==pColl->enc ){
64539
+ /* The strings are already in the correct encoding. Call the
64540
+ ** comparison function directly */
64541
+ return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
64542
+ }else{
64543
+ int rc;
64544
+ const void *v1, *v2;
64545
+ int n1, n2;
64546
+ Mem c1;
64547
+ Mem c2;
64548
+ memset(&c1, 0, sizeof(c1));
64549
+ memset(&c2, 0, sizeof(c2));
64550
+ sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
64551
+ sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
64552
+ v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
64553
+ n1 = v1==0 ? 0 : c1.n;
64554
+ v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
64555
+ n2 = v2==0 ? 0 : c2.n;
64556
+ rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
64557
+ sqlite3VdbeMemRelease(&c1);
64558
+ sqlite3VdbeMemRelease(&c2);
64559
+ return rc;
64560
+ }
64561
+}
64562
+
64563
+/*
64564
+** Compare the values contained by the two memory cells, returning
64565
+** negative, zero or positive if pMem1 is less than, equal to, or greater
64566
+** than pMem2. Sorting order is NULL's first, followed by numbers (integers
64567
+** and reals) sorted numerically, followed by text ordered by the collating
64568
+** sequence pColl and finally blob's ordered by memcmp().
64569
+**
64570
+** Two NULL values are considered equal by this function.
64571
+*/
64572
+SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
64573
+ int rc;
64574
+ int f1, f2;
64575
+ int combined_flags;
64576
+
64577
+ f1 = pMem1->flags;
64578
+ f2 = pMem2->flags;
64579
+ combined_flags = f1|f2;
64580
+ assert( (combined_flags & MEM_RowSet)==0 );
64581
+
64582
+ /* If one value is NULL, it is less than the other. If both values
64583
+ ** are NULL, return 0.
64584
+ */
64585
+ if( combined_flags&MEM_Null ){
64586
+ return (f2&MEM_Null) - (f1&MEM_Null);
64587
+ }
64588
+
64589
+ /* If one value is a number and the other is not, the number is less.
64590
+ ** If both are numbers, compare as reals if one is a real, or as integers
64591
+ ** if both values are integers.
64592
+ */
64593
+ if( combined_flags&(MEM_Int|MEM_Real) ){
64594
+ double r1, r2;
64595
+ if( (f1 & f2 & MEM_Int)!=0 ){
64596
+ if( pMem1->u.i < pMem2->u.i ) return -1;
64597
+ if( pMem1->u.i > pMem2->u.i ) return 1;
64598
+ return 0;
64599
+ }
64600
+ if( (f1&MEM_Real)!=0 ){
64601
+ r1 = pMem1->r;
64602
+ }else if( (f1&MEM_Int)!=0 ){
64603
+ r1 = (double)pMem1->u.i;
64604
+ }else{
64605
+ return 1;
64606
+ }
64607
+ if( (f2&MEM_Real)!=0 ){
64608
+ r2 = pMem2->r;
64609
+ }else if( (f2&MEM_Int)!=0 ){
64610
+ r2 = (double)pMem2->u.i;
64611
+ }else{
64612
+ return -1;
64613
+ }
64614
+ if( r1<r2 ) return -1;
64615
+ if( r1>r2 ) return 1;
64616
+ return 0;
64617
+ }
64618
+
64619
+ /* If one value is a string and the other is a blob, the string is less.
64620
+ ** If both are strings, compare using the collating functions.
64621
+ */
64622
+ if( combined_flags&MEM_Str ){
64623
+ if( (f1 & MEM_Str)==0 ){
64624
+ return 1;
64625
+ }
64626
+ if( (f2 & MEM_Str)==0 ){
64627
+ return -1;
64628
+ }
64629
+
64630
+ assert( pMem1->enc==pMem2->enc );
64631
+ assert( pMem1->enc==SQLITE_UTF8 ||
64632
+ pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
64633
+
64634
+ /* The collation sequence must be defined at this point, even if
64635
+ ** the user deletes the collation sequence after the vdbe program is
64636
+ ** compiled (this was not always the case).
64637
+ */
64638
+ assert( !pColl || pColl->xCmp );
64639
+
64640
+ if( pColl ){
64641
+ return vdbeCompareMemString(pMem1, pMem2, pColl);
64642
+ }
64643
+ /* If a NULL pointer was passed as the collate function, fall through
64644
+ ** to the blob case and use memcmp(). */
64645
+ }
64646
+
64647
+ /* Both values must be blobs. Compare using memcmp(). */
64648
+ rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
64649
+ if( rc==0 ){
64650
+ rc = pMem1->n - pMem2->n;
64651
+ }
64652
+ return rc;
64653
+}
64654
+
64655
+
64656
+/*
64657
+** The first argument passed to this function is a serial-type that
64658
+** corresponds to an integer - all values between 1 and 9 inclusive
64659
+** except 7. The second points to a buffer containing an integer value
64660
+** serialized according to serial_type. This function deserializes
64661
+** and returns the value.
64662
+*/
64663
+static i64 vdbeRecordDecodeInt(u32 serial_type, const u8 *aKey){
64664
+ u32 y;
64665
+ assert( CORRUPT_DB || (serial_type>=1 && serial_type<=9 && serial_type!=7) );
64666
+ switch( serial_type ){
64667
+ case 0:
64668
+ case 1:
64669
+ return ONE_BYTE_INT(aKey);
64670
+ case 2:
64671
+ return TWO_BYTE_INT(aKey);
64672
+ case 3:
64673
+ return THREE_BYTE_INT(aKey);
64674
+ case 4: {
64675
+ y = FOUR_BYTE_UINT(aKey);
64676
+ return (i64)*(int*)&y;
64677
+ }
64678
+ case 5: {
64679
+ return FOUR_BYTE_UINT(aKey+2) + (((i64)1)<<32)*TWO_BYTE_INT(aKey);
64680
+ }
64681
+ case 6: {
64682
+ u64 x = FOUR_BYTE_UINT(aKey);
64683
+ x = (x<<32) | FOUR_BYTE_UINT(aKey+4);
64684
+ return (i64)*(i64*)&x;
64685
+ }
64686
+ }
64687
+
64688
+ return (serial_type - 8);
64689
+}
64690
+
64691
+/*
64692
+** This function compares the two table rows or index records
64693
+** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
64694
+** or positive integer if key1 is less than, equal to or
64695
+** greater than key2. The {nKey1, pKey1} key must be a blob
64696
+** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
64697
+** key must be a parsed key such as obtained from
64698
+** sqlite3VdbeParseRecord.
64699
+**
64700
+** If argument bSkip is non-zero, it is assumed that the caller has already
64701
+** determined that the first fields of the keys are equal.
64702
+**
64703
+** Key1 and Key2 do not have to contain the same number of fields. If all
64704
+** fields that appear in both keys are equal, then pPKey2->default_rc is
64705
+** returned.
64706
+*/
64707
+SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
64708
+ int nKey1, const void *pKey1, /* Left key */
64709
+ const UnpackedRecord *pPKey2, /* Right key */
64710
+ int bSkip /* If true, skip the first field */
64711
+){
64712
+ u32 d1; /* Offset into aKey[] of next data element */
64713
+ int i; /* Index of next field to compare */
64714
+ u32 szHdr1; /* Size of record header in bytes */
64715
+ u32 idx1; /* Offset of first type in header */
64716
+ int rc = 0; /* Return value */
64717
+ Mem *pRhs = pPKey2->aMem; /* Next field of pPKey2 to compare */
64718
+ KeyInfo *pKeyInfo = pPKey2->pKeyInfo;
64719
+ const unsigned char *aKey1 = (const unsigned char *)pKey1;
64720
+ Mem mem1;
64721
+
64722
+ /* If bSkip is true, then the caller has already determined that the first
64723
+ ** two elements in the keys are equal. Fix the various stack variables so
64724
+ ** that this routine begins comparing at the second field. */
64725
+ if( bSkip ){
64726
+ u32 s1;
64727
+ idx1 = 1 + getVarint32(&aKey1[1], s1);
64728
+ szHdr1 = aKey1[0];
64729
+ d1 = szHdr1 + sqlite3VdbeSerialTypeLen(s1);
64730
+ i = 1;
64731
+ pRhs++;
64732
+ }else{
64733
+ idx1 = getVarint32(aKey1, szHdr1);
64734
+ d1 = szHdr1;
64735
+ i = 0;
64736
+ }
64737
+
64738
+ VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */
64739
+ assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField
64740
+ || CORRUPT_DB );
64741
+ assert( pPKey2->pKeyInfo->aSortOrder!=0 );
64742
+ assert( pPKey2->pKeyInfo->nField>0 );
64743
+ assert( idx1<=szHdr1 || CORRUPT_DB );
64744
+ do{
64745
+ u32 serial_type;
64746
+
64747
+ /* RHS is an integer */
64748
+ if( pRhs->flags & MEM_Int ){
64749
+ serial_type = aKey1[idx1];
64750
+ if( serial_type>=12 ){
64751
+ rc = +1;
64752
+ }else if( serial_type==0 ){
64753
+ rc = -1;
64754
+ }else if( serial_type==7 ){
64755
+ double rhs = (double)pRhs->u.i;
64756
+ sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
64757
+ if( mem1.r<rhs ){
64758
+ rc = -1;
64759
+ }else if( mem1.r>rhs ){
64760
+ rc = +1;
64761
+ }
64762
+ }else{
64763
+ i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
64764
+ i64 rhs = pRhs->u.i;
64765
+ if( lhs<rhs ){
64766
+ rc = -1;
64767
+ }else if( lhs>rhs ){
64768
+ rc = +1;
64769
+ }
64770
+ }
64771
+ }
64772
+
64773
+ /* RHS is real */
64774
+ else if( pRhs->flags & MEM_Real ){
64775
+ serial_type = aKey1[idx1];
64776
+ if( serial_type>=12 ){
64777
+ rc = +1;
64778
+ }else if( serial_type==0 ){
64779
+ rc = -1;
64780
+ }else{
64781
+ double rhs = pRhs->r;
64782
+ double lhs;
64783
+ sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
64784
+ if( serial_type==7 ){
64785
+ lhs = mem1.r;
64786
+ }else{
64787
+ lhs = (double)mem1.u.i;
64788
+ }
64789
+ if( lhs<rhs ){
64790
+ rc = -1;
64791
+ }else if( lhs>rhs ){
64792
+ rc = +1;
64793
+ }
64794
+ }
64795
+ }
64796
+
64797
+ /* RHS is a string */
64798
+ else if( pRhs->flags & MEM_Str ){
64799
+ getVarint32(&aKey1[idx1], serial_type);
64800
+ if( serial_type<12 ){
64801
+ rc = -1;
64802
+ }else if( !(serial_type & 0x01) ){
64803
+ rc = +1;
64804
+ }else{
64805
+ mem1.n = (serial_type - 12) / 2;
64806
+ if( (d1+mem1.n) > (unsigned)nKey1 ){
64807
+ rc = 1; /* Corruption */
64808
+ }else if( pKeyInfo->aColl[i] ){
64809
+ mem1.enc = pKeyInfo->enc;
64810
+ mem1.db = pKeyInfo->db;
64811
+ mem1.flags = MEM_Str;
64812
+ mem1.z = (char*)&aKey1[d1];
64813
+ rc = vdbeCompareMemString(&mem1, pRhs, pKeyInfo->aColl[i]);
64814
+ }else{
64815
+ int nCmp = MIN(mem1.n, pRhs->n);
64816
+ rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
64817
+ if( rc==0 ) rc = mem1.n - pRhs->n;
64818
+ }
64819
+ }
64820
+ }
64821
+
64822
+ /* RHS is a blob */
64823
+ else if( pRhs->flags & MEM_Blob ){
64824
+ getVarint32(&aKey1[idx1], serial_type);
64825
+ if( serial_type<12 || (serial_type & 0x01) ){
64826
+ rc = -1;
64827
+ }else{
64828
+ int nStr = (serial_type - 12) / 2;
64829
+ if( (d1+nStr) > (unsigned)nKey1 ){
64830
+ rc = 1; /* Corruption */
64831
+ }else{
64832
+ int nCmp = MIN(nStr, pRhs->n);
64833
+ rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
64834
+ if( rc==0 ) rc = nStr - pRhs->n;
64835
+ }
64836
+ }
64837
+ }
64838
+
64839
+ /* RHS is null */
64840
+ else{
64841
+ serial_type = aKey1[idx1];
64842
+ rc = (serial_type!=0);
64843
+ }
64844
+
64845
+ if( rc!=0 ){
64846
+ if( pKeyInfo->aSortOrder[i] ){
64847
+ rc = -rc;
64848
+ }
64849
+ assert( CORRUPT_DB
64850
+ || (rc<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
64851
+ || (rc>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
64852
+ );
64853
+ assert( mem1.zMalloc==0 ); /* See comment below */
64854
+ return rc;
64855
+ }
64856
+
64857
+ i++;
64858
+ pRhs++;
64859
+ d1 += sqlite3VdbeSerialTypeLen(serial_type);
64860
+ idx1 += sqlite3VarintLen(serial_type);
64861
+ }while( idx1<(unsigned)szHdr1 && i<pPKey2->nField && d1<=(unsigned)nKey1 );
64862
+
64863
+ /* No memory allocation is ever used on mem1. Prove this using
64864
+ ** the following assert(). If the assert() fails, it indicates a
64865
+ ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). */
64866
+ assert( mem1.zMalloc==0 );
64867
+
64868
+ /* rc==0 here means that one or both of the keys ran out of fields and
64869
+ ** all the fields up to that point were equal. Return the the default_rc
64870
+ ** value. */
64871
+ assert( CORRUPT_DB
64872
+ || pPKey2->default_rc==vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)
64873
+ );
64874
+ return pPKey2->default_rc;
64875
+}
64876
+
64877
+/*
64878
+** This function is an optimized version of sqlite3VdbeRecordCompare()
64879
+** that (a) the first field of pPKey2 is an integer, and (b) the
64880
+** size-of-header varint at the start of (pKey1/nKey1) fits in a single
64881
+** byte (i.e. is less than 128).
64882
+*/
64883
+static int vdbeRecordCompareInt(
64884
+ int nKey1, const void *pKey1, /* Left key */
64885
+ const UnpackedRecord *pPKey2, /* Right key */
64886
+ int bSkip /* Ignored */
64887
+){
64888
+ const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
64889
+ int serial_type = ((const u8*)pKey1)[1];
64890
+ int res;
64891
+ u32 y;
64892
+ u64 x;
64893
+ i64 v = pPKey2->aMem[0].u.i;
64894
+ i64 lhs;
64895
+ UNUSED_PARAMETER(bSkip);
64896
+
64897
+ assert( bSkip==0 );
64898
+ switch( serial_type ){
64899
+ case 1: { /* 1-byte signed integer */
64900
+ lhs = ONE_BYTE_INT(aKey);
64901
+ break;
64902
+ }
64903
+ case 2: { /* 2-byte signed integer */
64904
+ lhs = TWO_BYTE_INT(aKey);
64905
+ break;
64906
+ }
64907
+ case 3: { /* 3-byte signed integer */
64908
+ lhs = THREE_BYTE_INT(aKey);
64909
+ break;
64910
+ }
64911
+ case 4: { /* 4-byte signed integer */
64912
+ y = FOUR_BYTE_UINT(aKey);
64913
+ lhs = (i64)*(int*)&y;
64914
+ break;
64915
+ }
64916
+ case 5: { /* 6-byte signed integer */
64917
+ lhs = FOUR_BYTE_UINT(aKey+2) + (((i64)1)<<32)*TWO_BYTE_INT(aKey);
64918
+ break;
64919
+ }
64920
+ case 6: { /* 8-byte signed integer */
64921
+ x = FOUR_BYTE_UINT(aKey);
64922
+ x = (x<<32) | FOUR_BYTE_UINT(aKey+4);
64923
+ lhs = *(i64*)&x;
64924
+ break;
64925
+ }
64926
+ case 8:
64927
+ lhs = 0;
64928
+ break;
64929
+ case 9:
64930
+ lhs = 1;
64931
+ break;
64932
+
64933
+ /* This case could be removed without changing the results of running
64934
+ ** this code. Including it causes gcc to generate a faster switch
64935
+ ** statement (since the range of switch targets now starts at zero and
64936
+ ** is contiguous) but does not cause any duplicate code to be generated
64937
+ ** (as gcc is clever enough to combine the two like cases). Other
64938
+ ** compilers might be similar. */
64939
+ case 0: case 7:
64940
+ return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
64941
+
64942
+ default:
64943
+ return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
64944
+ }
64945
+
64946
+ if( v>lhs ){
64947
+ res = pPKey2->r1;
64948
+ }else if( v<lhs ){
64949
+ res = pPKey2->r2;
64950
+ }else if( pPKey2->nField>1 ){
64951
+ /* The first fields of the two keys are equal. Compare the trailing
64952
+ ** fields. */
64953
+ res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
64954
+ }else{
64955
+ /* The first fields of the two keys are equal and there are no trailing
64956
+ ** fields. Return pPKey2->default_rc in this case. */
64957
+ res = pPKey2->default_rc;
64958
+ }
64959
+
64960
+ assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
64961
+ || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
64962
+ || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
64963
+ || CORRUPT_DB
64964
+ );
64965
+ return res;
64966
+}
64967
+
64968
+/*
64969
+** This function is an optimized version of sqlite3VdbeRecordCompare()
64970
+** that (a) the first field of pPKey2 is a string, that (b) the first field
64971
+** uses the collation sequence BINARY and (c) that the size-of-header varint
64972
+** at the start of (pKey1/nKey1) fits in a single byte.
64973
+*/
64974
+static int vdbeRecordCompareString(
64975
+ int nKey1, const void *pKey1, /* Left key */
64976
+ const UnpackedRecord *pPKey2, /* Right key */
64977
+ int bSkip
64978
+){
64979
+ const u8 *aKey1 = (const u8*)pKey1;
64980
+ int serial_type;
64981
+ int res;
64982
+ UNUSED_PARAMETER(bSkip);
64983
+
64984
+ assert( bSkip==0 );
64985
+ getVarint32(&aKey1[1], serial_type);
64986
+
64987
+ if( serial_type<12 ){
64988
+ res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
64989
+ }else if( !(serial_type & 0x01) ){
64990
+ res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
64991
+ }else{
64992
+ int nCmp;
64993
+ int nStr;
64994
+ int szHdr = aKey1[0];
64995
+
64996
+ nStr = (serial_type-12) / 2;
64997
+ if( (szHdr + nStr) > nKey1 ) return 0; /* Corruption */
64998
+ nCmp = MIN( pPKey2->aMem[0].n, nStr );
64999
+ res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp);
65000
+
65001
+ if( res==0 ){
65002
+ res = nStr - pPKey2->aMem[0].n;
65003
+ if( res==0 ){
65004
+ if( pPKey2->nField>1 ){
65005
+ res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
65006
+ }else{
65007
+ res = pPKey2->default_rc;
65008
+ }
65009
+ }else if( res>0 ){
65010
+ res = pPKey2->r2;
65011
+ }else{
65012
+ res = pPKey2->r1;
65013
+ }
65014
+ }else if( res>0 ){
65015
+ res = pPKey2->r2;
65016
+ }else{
65017
+ res = pPKey2->r1;
65018
+ }
65019
+ }
65020
+
65021
+ assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
65022
+ || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
65023
+ || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
65024
+ || CORRUPT_DB
65025
+ );
65026
+ return res;
65027
+}
65028
+
65029
+/*
65030
+** Return a pointer to an sqlite3VdbeRecordCompare() compatible function
65031
+** suitable for comparing serialized records to the unpacked record passed
65032
+** as the only argument.
65033
+*/
65034
+SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
65035
+ /* varintRecordCompareInt() and varintRecordCompareString() both assume
65036
+ ** that the size-of-header varint that occurs at the start of each record
65037
+ ** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
65038
+ ** also assumes that it is safe to overread a buffer by at least the
65039
+ ** maximum possible legal header size plus 8 bytes. Because there is
65040
+ ** guaranteed to be at least 74 (but not 136) bytes of padding following each
65041
+ ** buffer passed to varintRecordCompareInt() this makes it convenient to
65042
+ ** limit the size of the header to 64 bytes in cases where the first field
65043
+ ** is an integer.
65044
+ **
65045
+ ** The easiest way to enforce this limit is to consider only records with
65046
+ ** 13 fields or less. If the first field is an integer, the maximum legal
65047
+ ** header size is (12*5 + 1 + 1) bytes. */
65048
+ if( (p->pKeyInfo->nField + p->pKeyInfo->nXField)<=13 ){
65049
+ int flags = p->aMem[0].flags;
65050
+ if( p->pKeyInfo->aSortOrder[0] ){
65051
+ p->r1 = 1;
65052
+ p->r2 = -1;
65053
+ }else{
65054
+ p->r1 = -1;
65055
+ p->r2 = 1;
65056
+ }
65057
+ if( (flags & MEM_Int) ){
65058
+ return vdbeRecordCompareInt;
65059
+ }
65060
+ if( (flags & (MEM_Int|MEM_Real|MEM_Null|MEM_Blob))==0
65061
+ && p->pKeyInfo->aColl[0]==0
65062
+ ){
65063
+ return vdbeRecordCompareString;
65064
+ }
65065
+ }
65066
+
65067
+ return sqlite3VdbeRecordCompare;
65068
+}
6461065069
6461165070
/*
6461265071
** pCur points at an index entry created using the OP_MakeRecord opcode.
6461365072
** Read the rowid (the last field in the record) and store it in *rowid.
6461465073
** Return SQLITE_OK if everything works, or an error code otherwise.
@@ -64695,23 +65154,23 @@
6469565154
** omits the rowid at the end. The rowid at the end of the index entry
6469665155
** is ignored as well. Hence, this routine only compares the prefixes
6469765156
** of the keys prior to the final rowid, not the entire key.
6469865157
*/
6469965158
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
64700
- VdbeCursor *pC, /* The cursor to compare against */
64701
- UnpackedRecord *pUnpacked, /* Unpacked version of key to compare against */
64702
- int *res /* Write the comparison result here */
65159
+ VdbeCursor *pC, /* The cursor to compare against */
65160
+ const UnpackedRecord *pUnpacked, /* Unpacked version of key */
65161
+ int *res /* Write the comparison result here */
6470365162
){
6470465163
i64 nCellKey = 0;
6470565164
int rc;
6470665165
BtCursor *pCur = pC->pCursor;
6470765166
Mem m;
6470865167
6470965168
assert( sqlite3BtreeCursorIsValid(pCur) );
6471065169
VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
6471165170
assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
64712
- /* nCellKey will always be between 0 and 0xffffffff because of the say
65171
+ /* nCellKey will always be between 0 and 0xffffffff because of the way
6471365172
** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
6471465173
if( nCellKey<=0 || nCellKey>0x7fffffff ){
6471565174
*res = 0;
6471665175
return SQLITE_CORRUPT_BKPT;
6471765176
}
@@ -64718,12 +65177,11 @@
6471865177
memset(&m, 0, sizeof(m));
6471965178
rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
6472065179
if( rc ){
6472165180
return rc;
6472265181
}
64723
- assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
64724
- *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
65182
+ *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked, 0);
6472565183
sqlite3VdbeMemRelease(&m);
6472665184
return SQLITE_OK;
6472765185
}
6472865186
6472965187
/*
@@ -66629,11 +67087,11 @@
6662967087
** does not control the string, it might be deleted without the register
6663067088
** knowing it.
6663167089
**
6663267090
** This routine converts an ephemeral string into a dynamically allocated
6663367091
** string that the register itself controls. In other words, it
66634
-** converts an MEM_Ephem string into an MEM_Dyn string.
67092
+** converts an MEM_Ephem string into a string with P.z==P.zMalloc.
6663567093
*/
6663667094
#define Deephemeralize(P) \
6663767095
if( ((P)->flags&MEM_Ephem)!=0 \
6663867096
&& sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
6663967097
@@ -67166,22 +67624,25 @@
6716667624
#ifdef SQLITE_DEBUG
6716767625
if( (pOp->opflags & OPFLG_IN1)!=0 ){
6716867626
assert( pOp->p1>0 );
6716967627
assert( pOp->p1<=(p->nMem-p->nCursor) );
6717067628
assert( memIsValid(&aMem[pOp->p1]) );
67629
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
6717167630
REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
6717267631
}
6717367632
if( (pOp->opflags & OPFLG_IN2)!=0 ){
6717467633
assert( pOp->p2>0 );
6717567634
assert( pOp->p2<=(p->nMem-p->nCursor) );
6717667635
assert( memIsValid(&aMem[pOp->p2]) );
67636
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
6717767637
REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
6717867638
}
6717967639
if( (pOp->opflags & OPFLG_IN3)!=0 ){
6718067640
assert( pOp->p3>0 );
6718167641
assert( pOp->p3<=(p->nMem-p->nCursor) );
6718267642
assert( memIsValid(&aMem[pOp->p3]) );
67643
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
6718367644
REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
6718467645
}
6718567646
if( (pOp->opflags & OPFLG_OUT2)!=0 ){
6718667647
assert( pOp->p2>0 );
6718767648
assert( pOp->p2<=(p->nMem-p->nCursor) );
@@ -67279,11 +67740,11 @@
6727967740
** and then jump to address P2.
6728067741
*/
6728167742
case OP_Gosub: { /* jump */
6728267743
assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
6728367744
pIn1 = &aMem[pOp->p1];
67284
- assert( (pIn1->flags & MEM_Dyn)==0 );
67745
+ assert( VdbeMemDynamic(pIn1)==0 );
6728567746
memAboutToChange(p, pIn1);
6728667747
pIn1->flags = MEM_Int;
6728767748
pIn1->u.i = pc;
6728867749
REGISTER_TRACE(pOp->p1, pIn1);
6728967750
pc = pOp->p2 - 1;
@@ -67352,11 +67813,11 @@
6735267813
** OP_EndCoroutine, jump immediately to P2.
6735367814
*/
6735467815
case OP_Yield: { /* in1, jump */
6735567816
int pcDest;
6735667817
pIn1 = &aMem[pOp->p1];
67357
- assert( (pIn1->flags & MEM_Dyn)==0 );
67818
+ assert( VdbeMemDynamic(pIn1)==0 );
6735867819
pIn1->flags = MEM_Int;
6735967820
pcDest = (int)pIn1->u.i;
6736067821
pIn1->u.i = pc;
6736167822
REGISTER_TRACE(pOp->p1, pIn1);
6736267823
pc = pcDest;
@@ -67525,14 +67986,13 @@
6752567986
if( encoding!=SQLITE_UTF8 ){
6752667987
rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
6752767988
if( rc==SQLITE_TOOBIG ) goto too_big;
6752867989
if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
6752967990
assert( pOut->zMalloc==pOut->z );
67530
- assert( pOut->flags & MEM_Dyn );
67991
+ assert( VdbeMemDynamic(pOut)==0 );
6753167992
pOut->zMalloc = 0;
6753267993
pOut->flags |= MEM_Static;
67533
- pOut->flags &= ~MEM_Dyn;
6753467994
if( pOp->p4type==P4_DYNAMIC ){
6753567995
sqlite3DbFree(db, pOp->p4.z);
6753667996
}
6753767997
pOp->p4type = P4_DYNAMIC;
6753867998
pOp->p4.z = pOut->z;
@@ -67664,18 +68124,20 @@
6766468124
do{
6766568125
assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
6766668126
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
6766768127
assert( memIsValid(pIn1) );
6766868128
memAboutToChange(p, pOut);
68129
+ VdbeMemRelease(pOut);
6766968130
zMalloc = pOut->zMalloc;
67670
- pOut->zMalloc = 0;
67671
- sqlite3VdbeMemMove(pOut, pIn1);
68131
+ memcpy(pOut, pIn1, sizeof(Mem));
6767268132
#ifdef SQLITE_DEBUG
6767368133
if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
6767468134
pOut->pScopyFrom += p1 - pOp->p2;
6767568135
}
6767668136
#endif
68137
+ pIn1->flags = MEM_Undefined;
68138
+ pIn1->xDel = 0;
6767768139
pIn1->zMalloc = zMalloc;
6767868140
REGISTER_TRACE(p2++, pOut);
6767968141
pIn1++;
6768068142
pOut++;
6768168143
}while( n-- );
@@ -67848,14 +68310,14 @@
6784868310
Stringify(pIn2, encoding);
6784968311
nByte = pIn1->n + pIn2->n;
6785068312
if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
6785168313
goto too_big;
6785268314
}
67853
- MemSetTypeFlag(pOut, MEM_Str);
6785468315
if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
6785568316
goto no_mem;
6785668317
}
68318
+ MemSetTypeFlag(pOut, MEM_Str);
6785768319
if( pOut!=pIn2 ){
6785868320
memcpy(pOut->z, pIn2->z, pIn2->n);
6785968321
}
6786068322
memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
6786168323
pOut->z[nByte]=0;
@@ -69026,10 +69488,11 @@
6902669488
** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
6902769489
** all valid.
6902869490
*/
6902969491
assert( p2<pC->nHdrParsed );
6903069492
assert( rc==SQLITE_OK );
69493
+ assert( sqlite3VdbeCheckMemInvariants(pDest) );
6903169494
if( pC->szRow>=aOffset[p2+1] ){
6903269495
/* This is the common case where the desired content fits on the original
6903369496
** page - where the content is not on an overflow page */
6903469497
VdbeMemRelease(pDest);
6903569498
sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
@@ -69063,12 +69526,12 @@
6906369526
** sqlite3VdbeMemFromBtree() call above) then transfer control of that
6906469527
** dynamically allocated space over to the pDest structure.
6906569528
** This prevents a memory copy. */
6906669529
if( sMem.zMalloc ){
6906769530
assert( sMem.z==sMem.zMalloc );
69068
- assert( !(pDest->flags & MEM_Dyn) );
69069
- assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z );
69531
+ assert( VdbeMemDynamic(pDest)==0 );
69532
+ assert( (pDest->flags & (MEM_Blob|MEM_Str))==0 || pDest->z==sMem.z );
6907069533
pDest->flags &= ~(MEM_Ephem|MEM_Static);
6907169534
pDest->flags |= MEM_Term;
6907269535
pDest->z = sMem.z;
6907369536
pDest->zMalloc = sMem.zMalloc;
6907469537
}
@@ -69247,11 +69710,11 @@
6924769710
assert( i==nHdr );
6924869711
assert( j==nByte );
6924969712
6925069713
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
6925169714
pOut->n = (int)nByte;
69252
- pOut->flags = MEM_Blob | MEM_Dyn;
69715
+ pOut->flags = MEM_Blob;
6925369716
pOut->xDel = 0;
6925469717
if( nZero ){
6925569718
pOut->u.nZero = nZero;
6925669719
pOut->flags |= MEM_Zero;
6925769720
}
@@ -70121,20 +70584,20 @@
7012170584
r.pKeyInfo = pC->pKeyInfo;
7012270585
r.nField = (u16)nField;
7012370586
7012470587
/* The next line of code computes as follows, only faster:
7012570588
** if( oc==OP_SeekGT || oc==OP_SeekLE ){
70126
- ** r.flags = UNPACKED_INCRKEY;
70589
+ ** r.default_rc = -1;
7012770590
** }else{
70128
- ** r.flags = 0;
70591
+ ** r.default_rc = +1;
7012970592
** }
7013070593
*/
70131
- r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLT)));
70132
- assert( oc!=OP_SeekGT || r.flags==UNPACKED_INCRKEY );
70133
- assert( oc!=OP_SeekLE || r.flags==UNPACKED_INCRKEY );
70134
- assert( oc!=OP_SeekGE || r.flags==0 );
70135
- assert( oc!=OP_SeekLT || r.flags==0 );
70594
+ r.default_rc = ((1 & (oc - OP_SeekLT)) ? -1 : +1);
70595
+ assert( oc!=OP_SeekGT || r.default_rc==-1 );
70596
+ assert( oc!=OP_SeekLE || r.default_rc==-1 );
70597
+ assert( oc!=OP_SeekGE || r.default_rc==+1 );
70598
+ assert( oc!=OP_SeekLT || r.default_rc==+1 );
7013670599
7013770600
r.aMem = &aMem[pOp->p3];
7013870601
#ifdef SQLITE_DEBUG
7013970602
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7014070603
#endif
@@ -70288,22 +70751,21 @@
7028870751
ExpandBlob(&r.aMem[ii]);
7028970752
#ifdef SQLITE_DEBUG
7029070753
if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
7029170754
#endif
7029270755
}
70293
- r.flags = UNPACKED_PREFIX_MATCH;
7029470756
pIdxKey = &r;
7029570757
}else{
7029670758
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
7029770759
pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
7029870760
);
7029970761
if( pIdxKey==0 ) goto no_mem;
7030070762
assert( pIn3->flags & MEM_Blob );
7030170763
assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
7030270764
sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
70303
- pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
7030470765
}
70766
+ pIdxKey->default_rc = 0;
7030570767
if( pOp->opcode==OP_NoConflict ){
7030670768
/* For the OP_NoConflict opcode, take the jump if any of the
7030770769
** input fields are NULL, since any key with a NULL will not
7030870770
** conflict */
7030970771
for(ii=0; ii<r.nField; ii++){
@@ -71188,11 +71650,11 @@
7118871650
pCrsr = pC->pCursor;
7118971651
assert( pCrsr!=0 );
7119071652
assert( pOp->p5==0 );
7119171653
r.pKeyInfo = pC->pKeyInfo;
7119271654
r.nField = (u16)pOp->p3;
71193
- r.flags = UNPACKED_PREFIX_MATCH;
71655
+ r.default_rc = 0;
7119471656
r.aMem = &aMem[pOp->p2];
7119571657
#ifdef SQLITE_DEBUG
7119671658
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7119771659
#endif
7119871660
rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
@@ -71302,14 +71764,14 @@
7130271764
assert( pOp->p4type==P4_INT32 );
7130371765
r.pKeyInfo = pC->pKeyInfo;
7130471766
r.nField = (u16)pOp->p4.i;
7130571767
if( pOp->opcode<OP_IdxLT ){
7130671768
assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
71307
- r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71769
+ r.default_rc = -1;
7130871770
}else{
7130971771
assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
71310
- r.flags = UNPACKED_PREFIX_MATCH;
71772
+ r.default_rc = 0;
7131171773
}
7131271774
r.aMem = &aMem[pOp->p3];
7131371775
#ifdef SQLITE_DEBUG
7131471776
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7131571777
#endif
@@ -73809,14 +74271,14 @@
7380974271
if( r2->aMem[i].flags & MEM_Null ){
7381074272
*pRes = -1;
7381174273
return;
7381274274
}
7381374275
}
73814
- r2->flags |= UNPACKED_PREFIX_MATCH;
74276
+ assert( r2->default_rc==0 );
7381574277
}
7381674278
73817
- *pRes = sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
74279
+ *pRes = sqlite3VdbeRecordCompare(nKey1, pKey1, r2, 0);
7381874280
}
7381974281
7382074282
/*
7382174283
** This function is called to compare two iterator keys when merging
7382274284
** multiple b-tree segments. Parameter iOut is the index of the aTree[]
@@ -75449,10 +75911,12 @@
7544975911
pExpr->iTable = 1;
7545075912
pTab = pParse->pTriggerTab;
7545175913
}else if( op!=TK_INSERT && sqlite3StrICmp("old",zTab)==0 ){
7545275914
pExpr->iTable = 0;
7545375915
pTab = pParse->pTriggerTab;
75916
+ }else{
75917
+ pTab = 0;
7545475918
}
7545575919
7545675920
if( pTab ){
7545775921
int iCol;
7545875922
pSchema = pTab->pSchema;
@@ -100117,11 +100581,11 @@
100117100581
}else if( eDest!=SRT_Exists ){
100118100582
/* If the destination is an EXISTS(...) expression, the actual
100119100583
** values returned by the SELECT are not required.
100120100584
*/
100121100585
sqlite3ExprCodeExprList(pParse, pEList, regResult,
100122
- (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100586
+ (eDest==SRT_Output||eDest==SRT_Coroutine)?SQLITE_ECEL_DUP:0);
100123100587
}
100124100588
100125100589
/* If the DISTINCT keyword was present on the SELECT statement
100126100590
** and this row has been seen before, then do not make this row
100127100591
** part of the result.
@@ -110767,11 +111231,11 @@
110767111231
iCol = pRec->nField - 1;
110768111232
assert( pIdx->nSample>0 );
110769111233
assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
110770111234
do{
110771111235
iTest = (iMin+i)/2;
110772
- res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec);
111236
+ res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec, 0);
110773111237
if( res<0 ){
110774111238
iMin = iTest+1;
110775111239
}else{
110776111240
i = iTest;
110777111241
}
@@ -110782,20 +111246,20 @@
110782111246
** above found the right answer. This block serves no purpose other
110783111247
** than to invoke the asserts. */
110784111248
if( res==0 ){
110785111249
/* If (res==0) is true, then sample $i must be equal to pRec */
110786111250
assert( i<pIdx->nSample );
110787
- assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
111251
+ assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)
110788111252
|| pParse->db->mallocFailed );
110789111253
}else{
110790111254
/* Otherwise, pRec must be smaller than sample $i and larger than
110791111255
** sample ($i-1). */
110792111256
assert( i==pIdx->nSample
110793
- || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
111257
+ || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)>0
110794111258
|| pParse->db->mallocFailed );
110795111259
assert( i==0
110796
- || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
111260
+ || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec, 0)<0
110797111261
|| pParse->db->mallocFailed );
110798111262
}
110799111263
#endif /* ifdef SQLITE_DEBUG */
110800111264
110801111265
/* At this point, aSample[i] is the first sample that is greater than
@@ -114724,11 +115188,11 @@
114724115188
114725115189
/* For a co-routine, change all OP_Column references to the table of
114726115190
** the co-routine into OP_SCopy of result contained in a register.
114727115191
** OP_Rowid becomes OP_Null.
114728115192
*/
114729
- if( pTabItem->viaCoroutine ){
115193
+ if( pTabItem->viaCoroutine && !db->mallocFailed ){
114730115194
last = sqlite3VdbeCurrentAddr(v);
114731115195
k = pLevel->addrBody;
114732115196
pOp = sqlite3VdbeGetOp(v, k);
114733115197
for(; k<last; k++, pOp++){
114734115198
if( pOp->p1!=pLevel->iTabCur ) continue;
114735115199
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -189,11 +189,11 @@
189 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190 ** [sqlite_version()] and [sqlite_source_id()].
191 */
192 #define SQLITE_VERSION "3.8.4"
193 #define SQLITE_VERSION_NUMBER 3008004
194 #define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
195
196 /*
197 ** CAPI3REF: Run-Time Library Version Numbers
198 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
199 **
@@ -9334,12 +9334,15 @@
9334 #ifndef SQLITE_OMIT_TRACE
9335 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
9336 #endif
9337
9338 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9339 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
9340 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
 
 
 
9341
9342 #ifndef SQLITE_OMIT_TRIGGER
9343 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
9344 #endif
9345
@@ -10950,23 +10953,23 @@
10950 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
10951 ** OP_Column opcode.
10952 **
10953 ** This structure holds a record that has already been disassembled
10954 ** into its constituent fields.
 
 
 
10955 */
10956 struct UnpackedRecord {
10957 KeyInfo *pKeyInfo; /* Collation and sort-order information */
10958 u16 nField; /* Number of entries in apMem[] */
10959 u8 flags; /* Boolean settings. UNPACKED_... below */
10960 Mem *aMem; /* Values */
 
 
10961 };
10962
10963 /*
10964 ** Allowed values of UnpackedRecord.flags
10965 */
10966 #define UNPACKED_INCRKEY 0x01 /* Make this key an epsilon larger */
10967 #define UNPACKED_PREFIX_MATCH 0x02 /* A prefix match is considered OK */
10968
10969 /*
10970 ** Each SQL index is represented in memory by an
10971 ** instance of the following structure.
10972 **
@@ -13840,11 +13843,11 @@
13840 ** the following flags must be set to determine the memory management
13841 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
13842 ** string is \000 or \u0000 terminated
13843 */
13844 #define MEM_Term 0x0200 /* String rep is nul terminated */
13845 #define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
13846 #define MEM_Static 0x0800 /* Mem.z points to a static string */
13847 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
13848 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
13849 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
13850 #ifdef SQLITE_OMIT_INCRBLOB
@@ -14023,11 +14026,11 @@
14023 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
14024 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
14025 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
14026
14027 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
14028 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
14029 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
14030 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
14031 SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
14032 SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
14033 SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
@@ -14088,10 +14091,11 @@
14088 # define sqlite3VdbeLeave(X)
14089 #endif
14090
14091 #ifdef SQLITE_DEBUG
14092 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
 
14093 #endif
14094
14095 #ifndef SQLITE_OMIT_FOREIGN_KEY
14096 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
14097 #else
@@ -21471,11 +21475,11 @@
21471 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
21472
21473 sqlite3VdbeMemRelease(pMem);
21474 pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
21475 pMem->enc = desiredEnc;
21476 pMem->flags |= (MEM_Term|MEM_Dyn);
21477 pMem->z = (char*)zOut;
21478 pMem->zMalloc = pMem->z;
21479
21480 translate_out:
21481 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
@@ -21599,11 +21603,10 @@
21599 sqlite3VdbeMemRelease(&m);
21600 m.z = 0;
21601 }
21602 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
21603 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
21604 assert( (m.flags & MEM_Dyn)!=0 || db->mallocFailed );
21605 assert( m.z || db->mallocFailed );
21606 return m.z;
21607 }
21608
21609 /*
@@ -55305,10 +55308,11 @@
55305 i64 intKey, /* The table key */
55306 int biasRight, /* If true, bias the search to the high end */
55307 int *pRes /* Write search results here */
55308 ){
55309 int rc;
 
55310
55311 assert( cursorHoldsMutex(pCur) );
55312 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
55313 assert( pRes );
55314 assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
@@ -55325,10 +55329,20 @@
55325 if( pCur->atLast && pCur->info.nKey<intKey ){
55326 *pRes = -1;
55327 return SQLITE_OK;
55328 }
55329 }
 
 
 
 
 
 
 
 
 
 
55330
55331 rc = moveToRoot(pCur);
55332 if( rc ){
55333 return rc;
55334 }
@@ -55410,18 +55424,18 @@
55410 if( nCell<=pPage->max1bytePayload ){
55411 /* This branch runs if the record-size field of the cell is a
55412 ** single byte varint and the record fits entirely on the main
55413 ** b-tree page. */
55414 testcase( pCell+nCell+1==pPage->aDataEnd );
55415 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
55416 }else if( !(pCell[1] & 0x80)
55417 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
55418 ){
55419 /* The record-size field is a 2 byte varint and the record
55420 ** fits entirely on the main b-tree page. */
55421 testcase( pCell+nCell+2==pPage->aDataEnd );
55422 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
55423 }else{
55424 /* The record flows over onto one or more overflow pages. In
55425 ** this case the whole cell needs to be parsed, a buffer allocated
55426 ** and accessPayload() used to retrieve the record into the
55427 ** buffer before VdbeRecordCompare() can be called. */
@@ -55438,11 +55452,11 @@
55438 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
55439 if( rc ){
55440 sqlite3_free(pCellKey);
55441 goto moveto_finish;
55442 }
55443 c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
55444 sqlite3_free(pCellKey);
55445 }
55446 if( c<0 ){
55447 lwr = idx+1;
55448 }else if( c>0 ){
@@ -60001,10 +60015,46 @@
60001 ** This file contains code use to manipulate "Mem" structure. A "Mem"
60002 ** stores a single value in the VDBE. Mem is an opaque structure visible
60003 ** only within the VDBE. Interface routines refer to a Mem using the
60004 ** name sqlite_value
60005 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60006
60007 /*
60008 ** If pMem is an object with a valid string representation, this routine
60009 ** ensures the internal encoding for the string representation is
60010 ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
@@ -60051,16 +60101,11 @@
60051 ** pMem->z into the new allocation. pMem must be either a string or
60052 ** blob if bPreserve is true. If bPreserve is false, any prior content
60053 ** in pMem->z is discarded.
60054 */
60055 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
60056 assert( 1 >=
60057 ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
60058 (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
60059 ((pMem->flags&MEM_Ephem) ? 1 : 0) +
60060 ((pMem->flags&MEM_Static) ? 1 : 0)
60061 );
60062 assert( (pMem->flags&MEM_RowSet)==0 );
60063
60064 /* If the bPreserve flag is set to true, then the memory cell must already
60065 ** contain a valid string or blob value. */
60066 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
@@ -60074,26 +60119,26 @@
60074 }else{
60075 sqlite3DbFree(pMem->db, pMem->zMalloc);
60076 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
60077 }
60078 if( pMem->zMalloc==0 ){
60079 sqlite3VdbeMemRelease(pMem);
60080 pMem->flags = MEM_Null;
60081 return SQLITE_NOMEM;
60082 }
60083 }
60084
60085 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
60086 memcpy(pMem->zMalloc, pMem->z, pMem->n);
60087 }
60088 if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
60089 assert( pMem->xDel!=SQLITE_DYNAMIC );
60090 pMem->xDel((void *)(pMem->z));
60091 }
60092
60093 pMem->z = pMem->zMalloc;
60094 pMem->flags &= ~(MEM_Ephem|MEM_Static);
60095 pMem->xDel = 0;
60096 return SQLITE_OK;
60097 }
60098
60099 /*
@@ -60258,13 +60303,13 @@
60258 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
60259 if( p->flags&MEM_Agg ){
60260 sqlite3VdbeMemFinalize(p, p->u.pDef);
60261 assert( (p->flags & MEM_Agg)==0 );
60262 sqlite3VdbeMemRelease(p);
60263 }else if( p->flags&MEM_Dyn && p->xDel ){
60264 assert( (p->flags&MEM_RowSet)==0 );
60265 assert( p->xDel!=SQLITE_DYNAMIC );
60266 p->xDel((void *)p->z);
60267 p->xDel = 0;
60268 }else if( p->flags&MEM_RowSet ){
60269 sqlite3RowSetClear(p->u.pRowSet);
60270 }else if( p->flags&MEM_Frame ){
@@ -60276,10 +60321,11 @@
60276 ** Release any memory held by the Mem. This may leave the Mem in an
60277 ** inconsistent state, for example with (Mem.z==0) and
60278 ** (Mem.memType==MEM_Str).
60279 */
60280 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
 
60281 VdbeMemRelease(p);
60282 if( p->zMalloc ){
60283 sqlite3DbFree(p->db, p->zMalloc);
60284 p->zMalloc = 0;
60285 }
@@ -60613,10 +60659,11 @@
60613
60614 assert( (pFrom->flags & MEM_RowSet)==0 );
60615 VdbeMemRelease(pTo);
60616 memcpy(pTo, pFrom, MEMCELLSIZE);
60617 pTo->flags &= ~MEM_Dyn;
 
60618
60619 if( pTo->flags&(MEM_Str|MEM_Blob) ){
60620 if( 0==(pFrom->flags&MEM_Static) ){
60621 pTo->flags |= MEM_Ephem;
60622 rc = sqlite3VdbeMemMakeWriteable(pTo);
@@ -60738,123 +60785,10 @@
60738 }
60739
60740 return SQLITE_OK;
60741 }
60742
60743 /*
60744 ** Compare the values contained by the two memory cells, returning
60745 ** negative, zero or positive if pMem1 is less than, equal to, or greater
60746 ** than pMem2. Sorting order is NULL's first, followed by numbers (integers
60747 ** and reals) sorted numerically, followed by text ordered by the collating
60748 ** sequence pColl and finally blob's ordered by memcmp().
60749 **
60750 ** Two NULL values are considered equal by this function.
60751 */
60752 SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
60753 int rc;
60754 int f1, f2;
60755 int combined_flags;
60756
60757 f1 = pMem1->flags;
60758 f2 = pMem2->flags;
60759 combined_flags = f1|f2;
60760 assert( (combined_flags & MEM_RowSet)==0 );
60761
60762 /* If one value is NULL, it is less than the other. If both values
60763 ** are NULL, return 0.
60764 */
60765 if( combined_flags&MEM_Null ){
60766 return (f2&MEM_Null) - (f1&MEM_Null);
60767 }
60768
60769 /* If one value is a number and the other is not, the number is less.
60770 ** If both are numbers, compare as reals if one is a real, or as integers
60771 ** if both values are integers.
60772 */
60773 if( combined_flags&(MEM_Int|MEM_Real) ){
60774 double r1, r2;
60775 if( (f1 & f2 & MEM_Int)!=0 ){
60776 if( pMem1->u.i < pMem2->u.i ) return -1;
60777 if( pMem1->u.i > pMem2->u.i ) return 1;
60778 return 0;
60779 }
60780 if( (f1&MEM_Real)!=0 ){
60781 r1 = pMem1->r;
60782 }else if( (f1&MEM_Int)!=0 ){
60783 r1 = (double)pMem1->u.i;
60784 }else{
60785 return 1;
60786 }
60787 if( (f2&MEM_Real)!=0 ){
60788 r2 = pMem2->r;
60789 }else if( (f2&MEM_Int)!=0 ){
60790 r2 = (double)pMem2->u.i;
60791 }else{
60792 return -1;
60793 }
60794 if( r1<r2 ) return -1;
60795 if( r1>r2 ) return 1;
60796 return 0;
60797 }
60798
60799 /* If one value is a string and the other is a blob, the string is less.
60800 ** If both are strings, compare using the collating functions.
60801 */
60802 if( combined_flags&MEM_Str ){
60803 if( (f1 & MEM_Str)==0 ){
60804 return 1;
60805 }
60806 if( (f2 & MEM_Str)==0 ){
60807 return -1;
60808 }
60809
60810 assert( pMem1->enc==pMem2->enc );
60811 assert( pMem1->enc==SQLITE_UTF8 ||
60812 pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
60813
60814 /* The collation sequence must be defined at this point, even if
60815 ** the user deletes the collation sequence after the vdbe program is
60816 ** compiled (this was not always the case).
60817 */
60818 assert( !pColl || pColl->xCmp );
60819
60820 if( pColl ){
60821 if( pMem1->enc==pColl->enc ){
60822 /* The strings are already in the correct encoding. Call the
60823 ** comparison function directly */
60824 return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
60825 }else{
60826 const void *v1, *v2;
60827 int n1, n2;
60828 Mem c1;
60829 Mem c2;
60830 memset(&c1, 0, sizeof(c1));
60831 memset(&c2, 0, sizeof(c2));
60832 sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
60833 sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
60834 v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
60835 n1 = v1==0 ? 0 : c1.n;
60836 v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
60837 n2 = v2==0 ? 0 : c2.n;
60838 rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
60839 sqlite3VdbeMemRelease(&c1);
60840 sqlite3VdbeMemRelease(&c2);
60841 return rc;
60842 }
60843 }
60844 /* If a NULL pointer was passed as the collate function, fall through
60845 ** to the blob case and use memcmp(). */
60846 }
60847
60848 /* Both values must be blobs. Compare using memcmp(). */
60849 rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
60850 if( rc==0 ){
60851 rc = pMem1->n - pMem2->n;
60852 }
60853 return rc;
60854 }
60855
60856 /*
60857 ** Move data out of a btree key or data field and into a Mem structure.
60858 ** The data or key is taken from the entry that pCur is currently pointing
60859 ** to. offset and amt determine what portion of the data or key to retrieve.
60860 ** key is true to get the key or false to get data. The result is written
@@ -60891,26 +60825,27 @@
60891
60892 if( offset+amt<=available ){
60893 sqlite3VdbeMemRelease(pMem);
60894 pMem->z = &zData[offset];
60895 pMem->flags = MEM_Blob|MEM_Ephem;
 
60896 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60897 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
60898 pMem->enc = 0;
60899 pMem->memType = MEM_Blob;
60900 if( key ){
60901 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
60902 }else{
60903 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
60904 }
60905 pMem->z[amt] = 0;
60906 pMem->z[amt+1] = 0;
60907 if( rc!=SQLITE_OK ){
 
 
 
 
60908 sqlite3VdbeMemRelease(pMem);
60909 }
60910 }
60911 pMem->n = (int)amt;
60912
60913 return rc;
60914 }
60915
60916 /* This function is only available internally, it is not part of the
@@ -61010,11 +60945,10 @@
61010 if( pRec ){
61011 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
61012 if( pRec->pKeyInfo ){
61013 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
61014 assert( pRec->pKeyInfo->enc==ENC(db) );
61015 pRec->flags = UNPACKED_PREFIX_MATCH;
61016 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
61017 for(i=0; i<nCol; i++){
61018 pRec->aMem[i].flags = MEM_Null;
61019 pRec->aMem[i].memType = MEM_Null;
61020 pRec->aMem[i].db = db;
@@ -62591,10 +62525,11 @@
62591 }
62592 return;
62593 }
62594 for(pEnd=&p[N]; p<pEnd; p++){
62595 assert( (&p[1])==pEnd || p[0].db==p[1].db );
 
62596
62597 /* This block is really an inlined version of sqlite3VdbeMemRelease()
62598 ** that takes advantage of the fact that the memory cell value is
62599 ** being set to NULL after releasing any dynamic resources.
62600 **
@@ -62784,11 +62719,11 @@
62784
62785 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
62786 assert( p->db->mallocFailed );
62787 return SQLITE_ERROR;
62788 }
62789 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62790 zP4 = displayP4(pOp, pMem->z, 32);
62791 if( zP4!=pMem->z ){
62792 sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
62793 }else{
62794 assert( pMem->z!=0 );
@@ -62801,11 +62736,11 @@
62801 if( p->explain==1 ){
62802 if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
62803 assert( p->db->mallocFailed );
62804 return SQLITE_ERROR;
62805 }
62806 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62807 pMem->n = 2;
62808 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62809 pMem->memType = MEM_Str;
62810 pMem->enc = SQLITE_UTF8;
62811 pMem++;
@@ -62813,11 +62748,11 @@
62813 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62814 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
62815 assert( p->db->mallocFailed );
62816 return SQLITE_ERROR;
62817 }
62818 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62819 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62820 pMem->memType = MEM_Str;
62821 pMem->enc = SQLITE_UTF8;
62822 #else
62823 pMem->flags = MEM_Null; /* Comment */
@@ -64312,10 +64247,18 @@
64312
64313 /* NULL or constants 0 or 1 */
64314 return 0;
64315 }
64316
 
 
 
 
 
 
 
 
64317 /*
64318 ** Deserialize the data blob pointed to by buf as serial type serial_type
64319 ** and store the result in pMem. Return the number of bytes read.
64320 */
64321 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(
@@ -64323,46 +64266,40 @@
64323 u32 serial_type, /* Serial type to deserialize */
64324 Mem *pMem /* Memory cell to write value into */
64325 ){
64326 u64 x;
64327 u32 y;
64328 int i;
64329 switch( serial_type ){
64330 case 10: /* Reserved for future use */
64331 case 11: /* Reserved for future use */
64332 case 0: { /* NULL */
64333 pMem->flags = MEM_Null;
64334 break;
64335 }
64336 case 1: { /* 1-byte signed integer */
64337 pMem->u.i = (signed char)buf[0];
64338 pMem->flags = MEM_Int;
64339 return 1;
64340 }
64341 case 2: { /* 2-byte signed integer */
64342 i = 256*(signed char)buf[0] | buf[1];
64343 pMem->u.i = (i64)i;
64344 pMem->flags = MEM_Int;
64345 return 2;
64346 }
64347 case 3: { /* 3-byte signed integer */
64348 i = 65536*(signed char)buf[0] | (buf[1]<<8) | buf[2];
64349 pMem->u.i = (i64)i;
64350 pMem->flags = MEM_Int;
64351 return 3;
64352 }
64353 case 4: { /* 4-byte signed integer */
64354 y = ((unsigned)buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
64355 pMem->u.i = (i64)*(int*)&y;
64356 pMem->flags = MEM_Int;
64357 return 4;
64358 }
64359 case 5: { /* 6-byte signed integer */
64360 x = 256*(signed char)buf[0] + buf[1];
64361 y = ((unsigned)buf[2]<<24) | (buf[3]<<16) | (buf[4]<<8) | buf[5];
64362 x = (x<<32) | y;
64363 pMem->u.i = *(i64*)&x;
64364 pMem->flags = MEM_Int;
64365 return 6;
64366 }
64367 case 6: /* 8-byte signed integer */
64368 case 7: { /* IEEE floating point */
@@ -64376,12 +64313,12 @@
64376 static const double r1 = 1.0;
64377 u64 t2 = t1;
64378 swapMixedEndianFloat(t2);
64379 assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
64380 #endif
64381 x = ((unsigned)buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
64382 y = ((unsigned)buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7];
64383 x = (x<<32) | y;
64384 if( serial_type==6 ){
64385 pMem->u.i = *(i64*)&x;
64386 pMem->flags = MEM_Int;
64387 }else{
@@ -64473,11 +64410,11 @@
64473 u32 idx; /* Offset in aKey[] to read from */
64474 u16 u; /* Unsigned loop counter */
64475 u32 szHdr;
64476 Mem *pMem = p->aMem;
64477
64478 p->flags = 0;
64479 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
64480 idx = getVarint32(aKey, szHdr);
64481 d = szHdr;
64482 u = 0;
64483 while( idx<szHdr && u<p->nField && d<=nKey ){
@@ -64494,30 +64431,22 @@
64494 }
64495 assert( u<=pKeyInfo->nField + 1 );
64496 p->nField = u;
64497 }
64498
 
64499 /*
64500 ** This function compares the two table rows or index records
64501 ** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
64502 ** or positive integer if key1 is less than, equal to or
64503 ** greater than key2. The {nKey1, pKey1} key must be a blob
64504 ** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
64505 ** key must be a parsed key such as obtained from
64506 ** sqlite3VdbeParseRecord.
64507 **
64508 ** Key1 and Key2 do not have to contain the same number of fields.
64509 ** The key with fewer fields is usually compares less than the
64510 ** longer key. However if the UNPACKED_INCRKEY flags in pPKey2 is set
64511 ** and the common prefixes are equal, then key1 is less than key2.
64512 ** Or if the UNPACKED_MATCH_PREFIX flag is set and the prefixes are
64513 ** equal, then the keys are considered to be equal and
64514 ** the parts beyond the common prefix are ignored.
64515 */
64516 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
64517 int nKey1, const void *pKey1, /* Left key */
64518 UnpackedRecord *pPKey2 /* Right key */
64519 ){
64520 u32 d1; /* Offset into aKey[] of next data element */
64521 u32 idx1; /* Offset into aKey[] of next header element */
64522 u32 szHdr1; /* Number of bytes in header */
64523 int i = 0;
@@ -64587,28 +64516,558 @@
64587 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
64588 */
64589 assert( mem1.zMalloc==0 );
64590
64591 /* rc==0 here means that one of the keys ran out of fields and
64592 ** all the fields up to that point were equal. If the UNPACKED_INCRKEY
64593 ** flag is set, then break the tie by treating key2 as larger.
64594 ** If the UPACKED_PREFIX_MATCH flag is set, then keys with common prefixes
64595 ** are considered to be equal. Otherwise, the longer key is the
64596 ** larger. As it happens, the pPKey2 will always be the longer
64597 ** if there is a difference.
64598 */
64599 assert( rc==0 );
64600 if( pPKey2->flags & UNPACKED_INCRKEY ){
64601 rc = -1;
64602 }else if( pPKey2->flags & UNPACKED_PREFIX_MATCH ){
64603 /* Leave rc==0 */
64604 }else if( idx1<szHdr1 ){
64605 rc = 1;
64606 }
64607 return rc;
64608 }
64609
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64610
64611 /*
64612 ** pCur points at an index entry created using the OP_MakeRecord opcode.
64613 ** Read the rowid (the last field in the record) and store it in *rowid.
64614 ** Return SQLITE_OK if everything works, or an error code otherwise.
@@ -64695,23 +65154,23 @@
64695 ** omits the rowid at the end. The rowid at the end of the index entry
64696 ** is ignored as well. Hence, this routine only compares the prefixes
64697 ** of the keys prior to the final rowid, not the entire key.
64698 */
64699 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
64700 VdbeCursor *pC, /* The cursor to compare against */
64701 UnpackedRecord *pUnpacked, /* Unpacked version of key to compare against */
64702 int *res /* Write the comparison result here */
64703 ){
64704 i64 nCellKey = 0;
64705 int rc;
64706 BtCursor *pCur = pC->pCursor;
64707 Mem m;
64708
64709 assert( sqlite3BtreeCursorIsValid(pCur) );
64710 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
64711 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
64712 /* nCellKey will always be between 0 and 0xffffffff because of the say
64713 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
64714 if( nCellKey<=0 || nCellKey>0x7fffffff ){
64715 *res = 0;
64716 return SQLITE_CORRUPT_BKPT;
64717 }
@@ -64718,12 +65177,11 @@
64718 memset(&m, 0, sizeof(m));
64719 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
64720 if( rc ){
64721 return rc;
64722 }
64723 assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
64724 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
64725 sqlite3VdbeMemRelease(&m);
64726 return SQLITE_OK;
64727 }
64728
64729 /*
@@ -66629,11 +67087,11 @@
66629 ** does not control the string, it might be deleted without the register
66630 ** knowing it.
66631 **
66632 ** This routine converts an ephemeral string into a dynamically allocated
66633 ** string that the register itself controls. In other words, it
66634 ** converts an MEM_Ephem string into an MEM_Dyn string.
66635 */
66636 #define Deephemeralize(P) \
66637 if( ((P)->flags&MEM_Ephem)!=0 \
66638 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
66639
@@ -67166,22 +67624,25 @@
67166 #ifdef SQLITE_DEBUG
67167 if( (pOp->opflags & OPFLG_IN1)!=0 ){
67168 assert( pOp->p1>0 );
67169 assert( pOp->p1<=(p->nMem-p->nCursor) );
67170 assert( memIsValid(&aMem[pOp->p1]) );
 
67171 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
67172 }
67173 if( (pOp->opflags & OPFLG_IN2)!=0 ){
67174 assert( pOp->p2>0 );
67175 assert( pOp->p2<=(p->nMem-p->nCursor) );
67176 assert( memIsValid(&aMem[pOp->p2]) );
 
67177 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
67178 }
67179 if( (pOp->opflags & OPFLG_IN3)!=0 ){
67180 assert( pOp->p3>0 );
67181 assert( pOp->p3<=(p->nMem-p->nCursor) );
67182 assert( memIsValid(&aMem[pOp->p3]) );
 
67183 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
67184 }
67185 if( (pOp->opflags & OPFLG_OUT2)!=0 ){
67186 assert( pOp->p2>0 );
67187 assert( pOp->p2<=(p->nMem-p->nCursor) );
@@ -67279,11 +67740,11 @@
67279 ** and then jump to address P2.
67280 */
67281 case OP_Gosub: { /* jump */
67282 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67283 pIn1 = &aMem[pOp->p1];
67284 assert( (pIn1->flags & MEM_Dyn)==0 );
67285 memAboutToChange(p, pIn1);
67286 pIn1->flags = MEM_Int;
67287 pIn1->u.i = pc;
67288 REGISTER_TRACE(pOp->p1, pIn1);
67289 pc = pOp->p2 - 1;
@@ -67352,11 +67813,11 @@
67352 ** OP_EndCoroutine, jump immediately to P2.
67353 */
67354 case OP_Yield: { /* in1, jump */
67355 int pcDest;
67356 pIn1 = &aMem[pOp->p1];
67357 assert( (pIn1->flags & MEM_Dyn)==0 );
67358 pIn1->flags = MEM_Int;
67359 pcDest = (int)pIn1->u.i;
67360 pIn1->u.i = pc;
67361 REGISTER_TRACE(pOp->p1, pIn1);
67362 pc = pcDest;
@@ -67525,14 +67986,13 @@
67525 if( encoding!=SQLITE_UTF8 ){
67526 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
67527 if( rc==SQLITE_TOOBIG ) goto too_big;
67528 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
67529 assert( pOut->zMalloc==pOut->z );
67530 assert( pOut->flags & MEM_Dyn );
67531 pOut->zMalloc = 0;
67532 pOut->flags |= MEM_Static;
67533 pOut->flags &= ~MEM_Dyn;
67534 if( pOp->p4type==P4_DYNAMIC ){
67535 sqlite3DbFree(db, pOp->p4.z);
67536 }
67537 pOp->p4type = P4_DYNAMIC;
67538 pOp->p4.z = pOut->z;
@@ -67664,18 +68124,20 @@
67664 do{
67665 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67666 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67667 assert( memIsValid(pIn1) );
67668 memAboutToChange(p, pOut);
 
67669 zMalloc = pOut->zMalloc;
67670 pOut->zMalloc = 0;
67671 sqlite3VdbeMemMove(pOut, pIn1);
67672 #ifdef SQLITE_DEBUG
67673 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
67674 pOut->pScopyFrom += p1 - pOp->p2;
67675 }
67676 #endif
 
 
67677 pIn1->zMalloc = zMalloc;
67678 REGISTER_TRACE(p2++, pOut);
67679 pIn1++;
67680 pOut++;
67681 }while( n-- );
@@ -67848,14 +68310,14 @@
67848 Stringify(pIn2, encoding);
67849 nByte = pIn1->n + pIn2->n;
67850 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67851 goto too_big;
67852 }
67853 MemSetTypeFlag(pOut, MEM_Str);
67854 if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
67855 goto no_mem;
67856 }
 
67857 if( pOut!=pIn2 ){
67858 memcpy(pOut->z, pIn2->z, pIn2->n);
67859 }
67860 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67861 pOut->z[nByte]=0;
@@ -69026,10 +69488,11 @@
69026 ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
69027 ** all valid.
69028 */
69029 assert( p2<pC->nHdrParsed );
69030 assert( rc==SQLITE_OK );
 
69031 if( pC->szRow>=aOffset[p2+1] ){
69032 /* This is the common case where the desired content fits on the original
69033 ** page - where the content is not on an overflow page */
69034 VdbeMemRelease(pDest);
69035 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
@@ -69063,12 +69526,12 @@
69063 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
69064 ** dynamically allocated space over to the pDest structure.
69065 ** This prevents a memory copy. */
69066 if( sMem.zMalloc ){
69067 assert( sMem.z==sMem.zMalloc );
69068 assert( !(pDest->flags & MEM_Dyn) );
69069 assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z );
69070 pDest->flags &= ~(MEM_Ephem|MEM_Static);
69071 pDest->flags |= MEM_Term;
69072 pDest->z = sMem.z;
69073 pDest->zMalloc = sMem.zMalloc;
69074 }
@@ -69247,11 +69710,11 @@
69247 assert( i==nHdr );
69248 assert( j==nByte );
69249
69250 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69251 pOut->n = (int)nByte;
69252 pOut->flags = MEM_Blob | MEM_Dyn;
69253 pOut->xDel = 0;
69254 if( nZero ){
69255 pOut->u.nZero = nZero;
69256 pOut->flags |= MEM_Zero;
69257 }
@@ -70121,20 +70584,20 @@
70121 r.pKeyInfo = pC->pKeyInfo;
70122 r.nField = (u16)nField;
70123
70124 /* The next line of code computes as follows, only faster:
70125 ** if( oc==OP_SeekGT || oc==OP_SeekLE ){
70126 ** r.flags = UNPACKED_INCRKEY;
70127 ** }else{
70128 ** r.flags = 0;
70129 ** }
70130 */
70131 r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLT)));
70132 assert( oc!=OP_SeekGT || r.flags==UNPACKED_INCRKEY );
70133 assert( oc!=OP_SeekLE || r.flags==UNPACKED_INCRKEY );
70134 assert( oc!=OP_SeekGE || r.flags==0 );
70135 assert( oc!=OP_SeekLT || r.flags==0 );
70136
70137 r.aMem = &aMem[pOp->p3];
70138 #ifdef SQLITE_DEBUG
70139 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70140 #endif
@@ -70288,22 +70751,21 @@
70288 ExpandBlob(&r.aMem[ii]);
70289 #ifdef SQLITE_DEBUG
70290 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
70291 #endif
70292 }
70293 r.flags = UNPACKED_PREFIX_MATCH;
70294 pIdxKey = &r;
70295 }else{
70296 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70297 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
70298 );
70299 if( pIdxKey==0 ) goto no_mem;
70300 assert( pIn3->flags & MEM_Blob );
70301 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70302 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
70303 pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
70304 }
 
70305 if( pOp->opcode==OP_NoConflict ){
70306 /* For the OP_NoConflict opcode, take the jump if any of the
70307 ** input fields are NULL, since any key with a NULL will not
70308 ** conflict */
70309 for(ii=0; ii<r.nField; ii++){
@@ -71188,11 +71650,11 @@
71188 pCrsr = pC->pCursor;
71189 assert( pCrsr!=0 );
71190 assert( pOp->p5==0 );
71191 r.pKeyInfo = pC->pKeyInfo;
71192 r.nField = (u16)pOp->p3;
71193 r.flags = UNPACKED_PREFIX_MATCH;
71194 r.aMem = &aMem[pOp->p2];
71195 #ifdef SQLITE_DEBUG
71196 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71197 #endif
71198 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
@@ -71302,14 +71764,14 @@
71302 assert( pOp->p4type==P4_INT32 );
71303 r.pKeyInfo = pC->pKeyInfo;
71304 r.nField = (u16)pOp->p4.i;
71305 if( pOp->opcode<OP_IdxLT ){
71306 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
71307 r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71308 }else{
71309 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
71310 r.flags = UNPACKED_PREFIX_MATCH;
71311 }
71312 r.aMem = &aMem[pOp->p3];
71313 #ifdef SQLITE_DEBUG
71314 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71315 #endif
@@ -73809,14 +74271,14 @@
73809 if( r2->aMem[i].flags & MEM_Null ){
73810 *pRes = -1;
73811 return;
73812 }
73813 }
73814 r2->flags |= UNPACKED_PREFIX_MATCH;
73815 }
73816
73817 *pRes = sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
73818 }
73819
73820 /*
73821 ** This function is called to compare two iterator keys when merging
73822 ** multiple b-tree segments. Parameter iOut is the index of the aTree[]
@@ -75449,10 +75911,12 @@
75449 pExpr->iTable = 1;
75450 pTab = pParse->pTriggerTab;
75451 }else if( op!=TK_INSERT && sqlite3StrICmp("old",zTab)==0 ){
75452 pExpr->iTable = 0;
75453 pTab = pParse->pTriggerTab;
 
 
75454 }
75455
75456 if( pTab ){
75457 int iCol;
75458 pSchema = pTab->pSchema;
@@ -100117,11 +100581,11 @@
100117 }else if( eDest!=SRT_Exists ){
100118 /* If the destination is an EXISTS(...) expression, the actual
100119 ** values returned by the SELECT are not required.
100120 */
100121 sqlite3ExprCodeExprList(pParse, pEList, regResult,
100122 (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100123 }
100124
100125 /* If the DISTINCT keyword was present on the SELECT statement
100126 ** and this row has been seen before, then do not make this row
100127 ** part of the result.
@@ -110767,11 +111231,11 @@
110767 iCol = pRec->nField - 1;
110768 assert( pIdx->nSample>0 );
110769 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
110770 do{
110771 iTest = (iMin+i)/2;
110772 res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec);
110773 if( res<0 ){
110774 iMin = iTest+1;
110775 }else{
110776 i = iTest;
110777 }
@@ -110782,20 +111246,20 @@
110782 ** above found the right answer. This block serves no purpose other
110783 ** than to invoke the asserts. */
110784 if( res==0 ){
110785 /* If (res==0) is true, then sample $i must be equal to pRec */
110786 assert( i<pIdx->nSample );
110787 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
110788 || pParse->db->mallocFailed );
110789 }else{
110790 /* Otherwise, pRec must be smaller than sample $i and larger than
110791 ** sample ($i-1). */
110792 assert( i==pIdx->nSample
110793 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
110794 || pParse->db->mallocFailed );
110795 assert( i==0
110796 || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
110797 || pParse->db->mallocFailed );
110798 }
110799 #endif /* ifdef SQLITE_DEBUG */
110800
110801 /* At this point, aSample[i] is the first sample that is greater than
@@ -114724,11 +115188,11 @@
114724
114725 /* For a co-routine, change all OP_Column references to the table of
114726 ** the co-routine into OP_SCopy of result contained in a register.
114727 ** OP_Rowid becomes OP_Null.
114728 */
114729 if( pTabItem->viaCoroutine ){
114730 last = sqlite3VdbeCurrentAddr(v);
114731 k = pLevel->addrBody;
114732 pOp = sqlite3VdbeGetOp(v, k);
114733 for(; k<last; k++, pOp++){
114734 if( pOp->p1!=pLevel->iTabCur ) continue;
114735
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -189,11 +189,11 @@
189 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190 ** [sqlite_version()] and [sqlite_source_id()].
191 */
192 #define SQLITE_VERSION "3.8.4"
193 #define SQLITE_VERSION_NUMBER 3008004
194 #define SQLITE_SOURCE_ID "2014-03-04 13:18:23 9830c343bc954b828f6ca752f8ae63e2c0a980c1"
195
196 /*
197 ** CAPI3REF: Run-Time Library Version Numbers
198 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
199 **
@@ -9334,12 +9334,15 @@
9334 #ifndef SQLITE_OMIT_TRACE
9335 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
9336 #endif
9337
9338 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9339 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,const UnpackedRecord*,int);
9340 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
9341
9342 typedef int (*RecordCompare)(int,const void*,const UnpackedRecord*,int);
9343 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
9344
9345 #ifndef SQLITE_OMIT_TRIGGER
9346 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
9347 #endif
9348
@@ -10950,23 +10953,23 @@
10953 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
10954 ** OP_Column opcode.
10955 **
10956 ** This structure holds a record that has already been disassembled
10957 ** into its constituent fields.
10958 **
10959 ** The r1 and r2 member variables are only used by the optimized comparison
10960 ** functions vdbeRecordCompareInt() and vdbeRecordCompareString().
10961 */
10962 struct UnpackedRecord {
10963 KeyInfo *pKeyInfo; /* Collation and sort-order information */
10964 u16 nField; /* Number of entries in apMem[] */
10965 i8 default_rc; /* Comparison result if keys are equal */
10966 Mem *aMem; /* Values */
10967 int r1; /* Value to return if (lhs > rhs) */
10968 int r2; /* Value to return if (rhs < lhs) */
10969 };
10970
 
 
 
 
 
10971
10972 /*
10973 ** Each SQL index is represented in memory by an
10974 ** instance of the following structure.
10975 **
@@ -13840,11 +13843,11 @@
13843 ** the following flags must be set to determine the memory management
13844 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
13845 ** string is \000 or \u0000 terminated
13846 */
13847 #define MEM_Term 0x0200 /* String rep is nul terminated */
13848 #define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
13849 #define MEM_Static 0x0800 /* Mem.z points to a static string */
13850 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
13851 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
13852 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
13853 #ifdef SQLITE_OMIT_INCRBLOB
@@ -14023,11 +14026,11 @@
14026 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
14027 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
14028 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
14029
14030 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
14031 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,const UnpackedRecord*,int*);
14032 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
14033 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
14034 SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
14035 SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
14036 SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
@@ -14088,10 +14091,11 @@
14091 # define sqlite3VdbeLeave(X)
14092 #endif
14093
14094 #ifdef SQLITE_DEBUG
14095 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
14096 SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem*);
14097 #endif
14098
14099 #ifndef SQLITE_OMIT_FOREIGN_KEY
14100 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
14101 #else
@@ -21471,11 +21475,11 @@
21475 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
21476
21477 sqlite3VdbeMemRelease(pMem);
21478 pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
21479 pMem->enc = desiredEnc;
21480 pMem->flags |= (MEM_Term);
21481 pMem->z = (char*)zOut;
21482 pMem->zMalloc = pMem->z;
21483
21484 translate_out:
21485 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
@@ -21599,11 +21603,10 @@
21603 sqlite3VdbeMemRelease(&m);
21604 m.z = 0;
21605 }
21606 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
21607 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
 
21608 assert( m.z || db->mallocFailed );
21609 return m.z;
21610 }
21611
21612 /*
@@ -55305,10 +55308,11 @@
55308 i64 intKey, /* The table key */
55309 int biasRight, /* If true, bias the search to the high end */
55310 int *pRes /* Write search results here */
55311 ){
55312 int rc;
55313 RecordCompare xRecordCompare;
55314
55315 assert( cursorHoldsMutex(pCur) );
55316 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
55317 assert( pRes );
55318 assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
@@ -55325,10 +55329,20 @@
55329 if( pCur->atLast && pCur->info.nKey<intKey ){
55330 *pRes = -1;
55331 return SQLITE_OK;
55332 }
55333 }
55334
55335 if( pIdxKey ){
55336 xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
55337 assert( pIdxKey->default_rc==1
55338 || pIdxKey->default_rc==0
55339 || pIdxKey->default_rc==-1
55340 );
55341 }else{
55342 xRecordCompare = 0; /* Not actually used. Avoids a compiler warning. */
55343 }
55344
55345 rc = moveToRoot(pCur);
55346 if( rc ){
55347 return rc;
55348 }
@@ -55410,18 +55424,18 @@
55424 if( nCell<=pPage->max1bytePayload ){
55425 /* This branch runs if the record-size field of the cell is a
55426 ** single byte varint and the record fits entirely on the main
55427 ** b-tree page. */
55428 testcase( pCell+nCell+1==pPage->aDataEnd );
55429 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey, 0);
55430 }else if( !(pCell[1] & 0x80)
55431 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
55432 ){
55433 /* The record-size field is a 2 byte varint and the record
55434 ** fits entirely on the main b-tree page. */
55435 testcase( pCell+nCell+2==pPage->aDataEnd );
55436 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey, 0);
55437 }else{
55438 /* The record flows over onto one or more overflow pages. In
55439 ** this case the whole cell needs to be parsed, a buffer allocated
55440 ** and accessPayload() used to retrieve the record into the
55441 ** buffer before VdbeRecordCompare() can be called. */
@@ -55438,11 +55452,11 @@
55452 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
55453 if( rc ){
55454 sqlite3_free(pCellKey);
55455 goto moveto_finish;
55456 }
55457 c = xRecordCompare(nCell, pCellKey, pIdxKey, 0);
55458 sqlite3_free(pCellKey);
55459 }
55460 if( c<0 ){
55461 lwr = idx+1;
55462 }else if( c>0 ){
@@ -60001,10 +60015,46 @@
60015 ** This file contains code use to manipulate "Mem" structure. A "Mem"
60016 ** stores a single value in the VDBE. Mem is an opaque structure visible
60017 ** only within the VDBE. Interface routines refer to a Mem using the
60018 ** name sqlite_value
60019 */
60020
60021 #ifdef SQLITE_DEBUG
60022 /*
60023 ** Check invariants on a Mem object.
60024 **
60025 ** This routine is intended for use inside of assert() statements, like
60026 ** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
60027 */
60028 SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
60029 /* The MEM_Dyn bit is set if and only if Mem.xDel is a non-NULL destructor
60030 ** function for Mem.z
60031 */
60032 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
60033 assert( (p->flags & MEM_Dyn)!=0 || p->xDel==0 );
60034
60035 /* If p holds a string or blob, the Mem.z must point to exactly
60036 ** one of the following:
60037 **
60038 ** (1) Memory in Mem.zMalloc and managed by the Mem object
60039 ** (2) Memory to be freed using Mem.xDel
60040 ** (3) An ephermal string or blob
60041 ** (4) A static string or blob
60042 */
60043 if( (p->flags & (MEM_Str|MEM_Blob)) && p->z!=0 ){
60044 assert(
60045 ((p->z==p->zMalloc)? 1 : 0) +
60046 ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
60047 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
60048 ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
60049 );
60050 }
60051
60052 return 1;
60053 }
60054 #endif
60055
60056
60057 /*
60058 ** If pMem is an object with a valid string representation, this routine
60059 ** ensures the internal encoding for the string representation is
60060 ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
@@ -60051,16 +60101,11 @@
60101 ** pMem->z into the new allocation. pMem must be either a string or
60102 ** blob if bPreserve is true. If bPreserve is false, any prior content
60103 ** in pMem->z is discarded.
60104 */
60105 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
60106 assert( sqlite3VdbeCheckMemInvariants(pMem) );
 
 
 
 
 
60107 assert( (pMem->flags&MEM_RowSet)==0 );
60108
60109 /* If the bPreserve flag is set to true, then the memory cell must already
60110 ** contain a valid string or blob value. */
60111 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
@@ -60074,26 +60119,26 @@
60119 }else{
60120 sqlite3DbFree(pMem->db, pMem->zMalloc);
60121 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
60122 }
60123 if( pMem->zMalloc==0 ){
60124 VdbeMemRelease(pMem);
60125 pMem->flags = MEM_Null;
60126 return SQLITE_NOMEM;
60127 }
60128 }
60129
60130 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
60131 memcpy(pMem->zMalloc, pMem->z, pMem->n);
60132 }
60133 if( (pMem->flags&MEM_Dyn)!=0 ){
60134 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
60135 pMem->xDel((void *)(pMem->z));
60136 }
60137
60138 pMem->z = pMem->zMalloc;
60139 pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
60140 pMem->xDel = 0;
60141 return SQLITE_OK;
60142 }
60143
60144 /*
@@ -60258,13 +60303,13 @@
60303 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
60304 if( p->flags&MEM_Agg ){
60305 sqlite3VdbeMemFinalize(p, p->u.pDef);
60306 assert( (p->flags & MEM_Agg)==0 );
60307 sqlite3VdbeMemRelease(p);
60308 }else if( p->flags&MEM_Dyn ){
60309 assert( (p->flags&MEM_RowSet)==0 );
60310 assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
60311 p->xDel((void *)p->z);
60312 p->xDel = 0;
60313 }else if( p->flags&MEM_RowSet ){
60314 sqlite3RowSetClear(p->u.pRowSet);
60315 }else if( p->flags&MEM_Frame ){
@@ -60276,10 +60321,11 @@
60321 ** Release any memory held by the Mem. This may leave the Mem in an
60322 ** inconsistent state, for example with (Mem.z==0) and
60323 ** (Mem.memType==MEM_Str).
60324 */
60325 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
60326 assert( sqlite3VdbeCheckMemInvariants(p) );
60327 VdbeMemRelease(p);
60328 if( p->zMalloc ){
60329 sqlite3DbFree(p->db, p->zMalloc);
60330 p->zMalloc = 0;
60331 }
@@ -60613,10 +60659,11 @@
60659
60660 assert( (pFrom->flags & MEM_RowSet)==0 );
60661 VdbeMemRelease(pTo);
60662 memcpy(pTo, pFrom, MEMCELLSIZE);
60663 pTo->flags &= ~MEM_Dyn;
60664 pTo->xDel = 0;
60665
60666 if( pTo->flags&(MEM_Str|MEM_Blob) ){
60667 if( 0==(pFrom->flags&MEM_Static) ){
60668 pTo->flags |= MEM_Ephem;
60669 rc = sqlite3VdbeMemMakeWriteable(pTo);
@@ -60738,123 +60785,10 @@
60785 }
60786
60787 return SQLITE_OK;
60788 }
60789
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60790 /*
60791 ** Move data out of a btree key or data field and into a Mem structure.
60792 ** The data or key is taken from the entry that pCur is currently pointing
60793 ** to. offset and amt determine what portion of the data or key to retrieve.
60794 ** key is true to get the key or false to get data. The result is written
@@ -60891,26 +60825,27 @@
60825
60826 if( offset+amt<=available ){
60827 sqlite3VdbeMemRelease(pMem);
60828 pMem->z = &zData[offset];
60829 pMem->flags = MEM_Blob|MEM_Ephem;
60830 pMem->n = (int)amt;
60831 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
 
 
 
60832 if( key ){
60833 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
60834 }else{
60835 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
60836 }
60837 if( rc==SQLITE_OK ){
60838 pMem->z[amt] = 0;
60839 pMem->z[amt+1] = 0;
60840 pMem->flags = MEM_Blob|MEM_Term;
60841 pMem->memType = MEM_Blob;
60842 pMem->n = (int)amt;
60843 }else{
60844 sqlite3VdbeMemRelease(pMem);
60845 }
60846 }
 
60847
60848 return rc;
60849 }
60850
60851 /* This function is only available internally, it is not part of the
@@ -61010,11 +60945,10 @@
60945 if( pRec ){
60946 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
60947 if( pRec->pKeyInfo ){
60948 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
60949 assert( pRec->pKeyInfo->enc==ENC(db) );
 
60950 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
60951 for(i=0; i<nCol; i++){
60952 pRec->aMem[i].flags = MEM_Null;
60953 pRec->aMem[i].memType = MEM_Null;
60954 pRec->aMem[i].db = db;
@@ -62591,10 +62525,11 @@
62525 }
62526 return;
62527 }
62528 for(pEnd=&p[N]; p<pEnd; p++){
62529 assert( (&p[1])==pEnd || p[0].db==p[1].db );
62530 assert( sqlite3VdbeCheckMemInvariants(p) );
62531
62532 /* This block is really an inlined version of sqlite3VdbeMemRelease()
62533 ** that takes advantage of the fact that the memory cell value is
62534 ** being set to NULL after releasing any dynamic resources.
62535 **
@@ -62784,11 +62719,11 @@
62719
62720 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
62721 assert( p->db->mallocFailed );
62722 return SQLITE_ERROR;
62723 }
62724 pMem->flags = MEM_Str|MEM_Term;
62725 zP4 = displayP4(pOp, pMem->z, 32);
62726 if( zP4!=pMem->z ){
62727 sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
62728 }else{
62729 assert( pMem->z!=0 );
@@ -62801,11 +62736,11 @@
62736 if( p->explain==1 ){
62737 if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
62738 assert( p->db->mallocFailed );
62739 return SQLITE_ERROR;
62740 }
62741 pMem->flags = MEM_Str|MEM_Term;
62742 pMem->n = 2;
62743 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62744 pMem->memType = MEM_Str;
62745 pMem->enc = SQLITE_UTF8;
62746 pMem++;
@@ -62813,11 +62748,11 @@
62748 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62749 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
62750 assert( p->db->mallocFailed );
62751 return SQLITE_ERROR;
62752 }
62753 pMem->flags = MEM_Str|MEM_Term;
62754 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62755 pMem->memType = MEM_Str;
62756 pMem->enc = SQLITE_UTF8;
62757 #else
62758 pMem->flags = MEM_Null; /* Comment */
@@ -64312,10 +64247,18 @@
64247
64248 /* NULL or constants 0 or 1 */
64249 return 0;
64250 }
64251
64252 /* Input "x" is a sequence of unsigned characters that represent a
64253 ** big-endian integer. Return the equivalent native integer
64254 */
64255 #define ONE_BYTE_INT(x) ((i8)(x)[0])
64256 #define TWO_BYTE_INT(x) (256*(i8)((x)[0])|(x)[1])
64257 #define THREE_BYTE_INT(x) (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2])
64258 #define FOUR_BYTE_UINT(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
64259
64260 /*
64261 ** Deserialize the data blob pointed to by buf as serial type serial_type
64262 ** and store the result in pMem. Return the number of bytes read.
64263 */
64264 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(
@@ -64323,46 +64266,40 @@
64266 u32 serial_type, /* Serial type to deserialize */
64267 Mem *pMem /* Memory cell to write value into */
64268 ){
64269 u64 x;
64270 u32 y;
 
64271 switch( serial_type ){
64272 case 10: /* Reserved for future use */
64273 case 11: /* Reserved for future use */
64274 case 0: { /* NULL */
64275 pMem->flags = MEM_Null;
64276 break;
64277 }
64278 case 1: { /* 1-byte signed integer */
64279 pMem->u.i = ONE_BYTE_INT(buf);
64280 pMem->flags = MEM_Int;
64281 return 1;
64282 }
64283 case 2: { /* 2-byte signed integer */
64284 pMem->u.i = TWO_BYTE_INT(buf);
 
64285 pMem->flags = MEM_Int;
64286 return 2;
64287 }
64288 case 3: { /* 3-byte signed integer */
64289 pMem->u.i = THREE_BYTE_INT(buf);
 
64290 pMem->flags = MEM_Int;
64291 return 3;
64292 }
64293 case 4: { /* 4-byte signed integer */
64294 y = FOUR_BYTE_UINT(buf);
64295 pMem->u.i = (i64)*(int*)&y;
64296 pMem->flags = MEM_Int;
64297 return 4;
64298 }
64299 case 5: { /* 6-byte signed integer */
64300 pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
 
 
 
64301 pMem->flags = MEM_Int;
64302 return 6;
64303 }
64304 case 6: /* 8-byte signed integer */
64305 case 7: { /* IEEE floating point */
@@ -64376,12 +64313,12 @@
64313 static const double r1 = 1.0;
64314 u64 t2 = t1;
64315 swapMixedEndianFloat(t2);
64316 assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 );
64317 #endif
64318 x = FOUR_BYTE_UINT(buf);
64319 y = FOUR_BYTE_UINT(buf+4);
64320 x = (x<<32) | y;
64321 if( serial_type==6 ){
64322 pMem->u.i = *(i64*)&x;
64323 pMem->flags = MEM_Int;
64324 }else{
@@ -64473,11 +64410,11 @@
64410 u32 idx; /* Offset in aKey[] to read from */
64411 u16 u; /* Unsigned loop counter */
64412 u32 szHdr;
64413 Mem *pMem = p->aMem;
64414
64415 p->default_rc = 0;
64416 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
64417 idx = getVarint32(aKey, szHdr);
64418 d = szHdr;
64419 u = 0;
64420 while( idx<szHdr && u<p->nField && d<=nKey ){
@@ -64494,30 +64431,22 @@
64431 }
64432 assert( u<=pKeyInfo->nField + 1 );
64433 p->nField = u;
64434 }
64435
64436 #if SQLITE_DEBUG
64437 /*
64438 ** This function compares two index or table record keys in the same way
64439 ** as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(),
64440 ** this function deserializes and compares values using the
64441 ** sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used
64442 ** in assert() statements to ensure that the optimized code in
64443 ** sqlite3VdbeRecordCompare() returns results with these two primitives.
 
 
 
 
 
 
 
 
 
64444 */
64445 static int vdbeRecordCompareDebug(
64446 int nKey1, const void *pKey1, /* Left key */
64447 const UnpackedRecord *pPKey2 /* Right key */
64448 ){
64449 u32 d1; /* Offset into aKey[] of next data element */
64450 u32 idx1; /* Offset into aKey[] of next header element */
64451 u32 szHdr1; /* Number of bytes in header */
64452 int i = 0;
@@ -64587,28 +64516,558 @@
64516 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
64517 */
64518 assert( mem1.zMalloc==0 );
64519
64520 /* rc==0 here means that one of the keys ran out of fields and
64521 ** all the fields up to that point were equal. Return the the default_rc
64522 ** value. */
64523 return pPKey2->default_rc;
64524 }
64525 #endif
64526
64527 /*
64528 ** Both *pMem1 and *pMem2 contain string values. Compare the two values
64529 ** using the collation sequence pColl. As usual, return a negative , zero
64530 ** or positive value if *pMem1 is less than, equal to or greater than
64531 ** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
64532 */
64533 static int vdbeCompareMemString(
64534 const Mem *pMem1,
64535 const Mem *pMem2,
64536 const CollSeq *pColl
64537 ){
64538 if( pMem1->enc==pColl->enc ){
64539 /* The strings are already in the correct encoding. Call the
64540 ** comparison function directly */
64541 return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
64542 }else{
64543 int rc;
64544 const void *v1, *v2;
64545 int n1, n2;
64546 Mem c1;
64547 Mem c2;
64548 memset(&c1, 0, sizeof(c1));
64549 memset(&c2, 0, sizeof(c2));
64550 sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
64551 sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
64552 v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
64553 n1 = v1==0 ? 0 : c1.n;
64554 v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
64555 n2 = v2==0 ? 0 : c2.n;
64556 rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
64557 sqlite3VdbeMemRelease(&c1);
64558 sqlite3VdbeMemRelease(&c2);
64559 return rc;
64560 }
64561 }
64562
64563 /*
64564 ** Compare the values contained by the two memory cells, returning
64565 ** negative, zero or positive if pMem1 is less than, equal to, or greater
64566 ** than pMem2. Sorting order is NULL's first, followed by numbers (integers
64567 ** and reals) sorted numerically, followed by text ordered by the collating
64568 ** sequence pColl and finally blob's ordered by memcmp().
64569 **
64570 ** Two NULL values are considered equal by this function.
64571 */
64572 SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
64573 int rc;
64574 int f1, f2;
64575 int combined_flags;
64576
64577 f1 = pMem1->flags;
64578 f2 = pMem2->flags;
64579 combined_flags = f1|f2;
64580 assert( (combined_flags & MEM_RowSet)==0 );
64581
64582 /* If one value is NULL, it is less than the other. If both values
64583 ** are NULL, return 0.
64584 */
64585 if( combined_flags&MEM_Null ){
64586 return (f2&MEM_Null) - (f1&MEM_Null);
64587 }
64588
64589 /* If one value is a number and the other is not, the number is less.
64590 ** If both are numbers, compare as reals if one is a real, or as integers
64591 ** if both values are integers.
64592 */
64593 if( combined_flags&(MEM_Int|MEM_Real) ){
64594 double r1, r2;
64595 if( (f1 & f2 & MEM_Int)!=0 ){
64596 if( pMem1->u.i < pMem2->u.i ) return -1;
64597 if( pMem1->u.i > pMem2->u.i ) return 1;
64598 return 0;
64599 }
64600 if( (f1&MEM_Real)!=0 ){
64601 r1 = pMem1->r;
64602 }else if( (f1&MEM_Int)!=0 ){
64603 r1 = (double)pMem1->u.i;
64604 }else{
64605 return 1;
64606 }
64607 if( (f2&MEM_Real)!=0 ){
64608 r2 = pMem2->r;
64609 }else if( (f2&MEM_Int)!=0 ){
64610 r2 = (double)pMem2->u.i;
64611 }else{
64612 return -1;
64613 }
64614 if( r1<r2 ) return -1;
64615 if( r1>r2 ) return 1;
64616 return 0;
64617 }
64618
64619 /* If one value is a string and the other is a blob, the string is less.
64620 ** If both are strings, compare using the collating functions.
64621 */
64622 if( combined_flags&MEM_Str ){
64623 if( (f1 & MEM_Str)==0 ){
64624 return 1;
64625 }
64626 if( (f2 & MEM_Str)==0 ){
64627 return -1;
64628 }
64629
64630 assert( pMem1->enc==pMem2->enc );
64631 assert( pMem1->enc==SQLITE_UTF8 ||
64632 pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
64633
64634 /* The collation sequence must be defined at this point, even if
64635 ** the user deletes the collation sequence after the vdbe program is
64636 ** compiled (this was not always the case).
64637 */
64638 assert( !pColl || pColl->xCmp );
64639
64640 if( pColl ){
64641 return vdbeCompareMemString(pMem1, pMem2, pColl);
64642 }
64643 /* If a NULL pointer was passed as the collate function, fall through
64644 ** to the blob case and use memcmp(). */
64645 }
64646
64647 /* Both values must be blobs. Compare using memcmp(). */
64648 rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
64649 if( rc==0 ){
64650 rc = pMem1->n - pMem2->n;
64651 }
64652 return rc;
64653 }
64654
64655
64656 /*
64657 ** The first argument passed to this function is a serial-type that
64658 ** corresponds to an integer - all values between 1 and 9 inclusive
64659 ** except 7. The second points to a buffer containing an integer value
64660 ** serialized according to serial_type. This function deserializes
64661 ** and returns the value.
64662 */
64663 static i64 vdbeRecordDecodeInt(u32 serial_type, const u8 *aKey){
64664 u32 y;
64665 assert( CORRUPT_DB || (serial_type>=1 && serial_type<=9 && serial_type!=7) );
64666 switch( serial_type ){
64667 case 0:
64668 case 1:
64669 return ONE_BYTE_INT(aKey);
64670 case 2:
64671 return TWO_BYTE_INT(aKey);
64672 case 3:
64673 return THREE_BYTE_INT(aKey);
64674 case 4: {
64675 y = FOUR_BYTE_UINT(aKey);
64676 return (i64)*(int*)&y;
64677 }
64678 case 5: {
64679 return FOUR_BYTE_UINT(aKey+2) + (((i64)1)<<32)*TWO_BYTE_INT(aKey);
64680 }
64681 case 6: {
64682 u64 x = FOUR_BYTE_UINT(aKey);
64683 x = (x<<32) | FOUR_BYTE_UINT(aKey+4);
64684 return (i64)*(i64*)&x;
64685 }
64686 }
64687
64688 return (serial_type - 8);
64689 }
64690
64691 /*
64692 ** This function compares the two table rows or index records
64693 ** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
64694 ** or positive integer if key1 is less than, equal to or
64695 ** greater than key2. The {nKey1, pKey1} key must be a blob
64696 ** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
64697 ** key must be a parsed key such as obtained from
64698 ** sqlite3VdbeParseRecord.
64699 **
64700 ** If argument bSkip is non-zero, it is assumed that the caller has already
64701 ** determined that the first fields of the keys are equal.
64702 **
64703 ** Key1 and Key2 do not have to contain the same number of fields. If all
64704 ** fields that appear in both keys are equal, then pPKey2->default_rc is
64705 ** returned.
64706 */
64707 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
64708 int nKey1, const void *pKey1, /* Left key */
64709 const UnpackedRecord *pPKey2, /* Right key */
64710 int bSkip /* If true, skip the first field */
64711 ){
64712 u32 d1; /* Offset into aKey[] of next data element */
64713 int i; /* Index of next field to compare */
64714 u32 szHdr1; /* Size of record header in bytes */
64715 u32 idx1; /* Offset of first type in header */
64716 int rc = 0; /* Return value */
64717 Mem *pRhs = pPKey2->aMem; /* Next field of pPKey2 to compare */
64718 KeyInfo *pKeyInfo = pPKey2->pKeyInfo;
64719 const unsigned char *aKey1 = (const unsigned char *)pKey1;
64720 Mem mem1;
64721
64722 /* If bSkip is true, then the caller has already determined that the first
64723 ** two elements in the keys are equal. Fix the various stack variables so
64724 ** that this routine begins comparing at the second field. */
64725 if( bSkip ){
64726 u32 s1;
64727 idx1 = 1 + getVarint32(&aKey1[1], s1);
64728 szHdr1 = aKey1[0];
64729 d1 = szHdr1 + sqlite3VdbeSerialTypeLen(s1);
64730 i = 1;
64731 pRhs++;
64732 }else{
64733 idx1 = getVarint32(aKey1, szHdr1);
64734 d1 = szHdr1;
64735 i = 0;
64736 }
64737
64738 VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */
64739 assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField
64740 || CORRUPT_DB );
64741 assert( pPKey2->pKeyInfo->aSortOrder!=0 );
64742 assert( pPKey2->pKeyInfo->nField>0 );
64743 assert( idx1<=szHdr1 || CORRUPT_DB );
64744 do{
64745 u32 serial_type;
64746
64747 /* RHS is an integer */
64748 if( pRhs->flags & MEM_Int ){
64749 serial_type = aKey1[idx1];
64750 if( serial_type>=12 ){
64751 rc = +1;
64752 }else if( serial_type==0 ){
64753 rc = -1;
64754 }else if( serial_type==7 ){
64755 double rhs = (double)pRhs->u.i;
64756 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
64757 if( mem1.r<rhs ){
64758 rc = -1;
64759 }else if( mem1.r>rhs ){
64760 rc = +1;
64761 }
64762 }else{
64763 i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
64764 i64 rhs = pRhs->u.i;
64765 if( lhs<rhs ){
64766 rc = -1;
64767 }else if( lhs>rhs ){
64768 rc = +1;
64769 }
64770 }
64771 }
64772
64773 /* RHS is real */
64774 else if( pRhs->flags & MEM_Real ){
64775 serial_type = aKey1[idx1];
64776 if( serial_type>=12 ){
64777 rc = +1;
64778 }else if( serial_type==0 ){
64779 rc = -1;
64780 }else{
64781 double rhs = pRhs->r;
64782 double lhs;
64783 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
64784 if( serial_type==7 ){
64785 lhs = mem1.r;
64786 }else{
64787 lhs = (double)mem1.u.i;
64788 }
64789 if( lhs<rhs ){
64790 rc = -1;
64791 }else if( lhs>rhs ){
64792 rc = +1;
64793 }
64794 }
64795 }
64796
64797 /* RHS is a string */
64798 else if( pRhs->flags & MEM_Str ){
64799 getVarint32(&aKey1[idx1], serial_type);
64800 if( serial_type<12 ){
64801 rc = -1;
64802 }else if( !(serial_type & 0x01) ){
64803 rc = +1;
64804 }else{
64805 mem1.n = (serial_type - 12) / 2;
64806 if( (d1+mem1.n) > (unsigned)nKey1 ){
64807 rc = 1; /* Corruption */
64808 }else if( pKeyInfo->aColl[i] ){
64809 mem1.enc = pKeyInfo->enc;
64810 mem1.db = pKeyInfo->db;
64811 mem1.flags = MEM_Str;
64812 mem1.z = (char*)&aKey1[d1];
64813 rc = vdbeCompareMemString(&mem1, pRhs, pKeyInfo->aColl[i]);
64814 }else{
64815 int nCmp = MIN(mem1.n, pRhs->n);
64816 rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
64817 if( rc==0 ) rc = mem1.n - pRhs->n;
64818 }
64819 }
64820 }
64821
64822 /* RHS is a blob */
64823 else if( pRhs->flags & MEM_Blob ){
64824 getVarint32(&aKey1[idx1], serial_type);
64825 if( serial_type<12 || (serial_type & 0x01) ){
64826 rc = -1;
64827 }else{
64828 int nStr = (serial_type - 12) / 2;
64829 if( (d1+nStr) > (unsigned)nKey1 ){
64830 rc = 1; /* Corruption */
64831 }else{
64832 int nCmp = MIN(nStr, pRhs->n);
64833 rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
64834 if( rc==0 ) rc = nStr - pRhs->n;
64835 }
64836 }
64837 }
64838
64839 /* RHS is null */
64840 else{
64841 serial_type = aKey1[idx1];
64842 rc = (serial_type!=0);
64843 }
64844
64845 if( rc!=0 ){
64846 if( pKeyInfo->aSortOrder[i] ){
64847 rc = -rc;
64848 }
64849 assert( CORRUPT_DB
64850 || (rc<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
64851 || (rc>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
64852 );
64853 assert( mem1.zMalloc==0 ); /* See comment below */
64854 return rc;
64855 }
64856
64857 i++;
64858 pRhs++;
64859 d1 += sqlite3VdbeSerialTypeLen(serial_type);
64860 idx1 += sqlite3VarintLen(serial_type);
64861 }while( idx1<(unsigned)szHdr1 && i<pPKey2->nField && d1<=(unsigned)nKey1 );
64862
64863 /* No memory allocation is ever used on mem1. Prove this using
64864 ** the following assert(). If the assert() fails, it indicates a
64865 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). */
64866 assert( mem1.zMalloc==0 );
64867
64868 /* rc==0 here means that one or both of the keys ran out of fields and
64869 ** all the fields up to that point were equal. Return the the default_rc
64870 ** value. */
64871 assert( CORRUPT_DB
64872 || pPKey2->default_rc==vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)
64873 );
64874 return pPKey2->default_rc;
64875 }
64876
64877 /*
64878 ** This function is an optimized version of sqlite3VdbeRecordCompare()
64879 ** that (a) the first field of pPKey2 is an integer, and (b) the
64880 ** size-of-header varint at the start of (pKey1/nKey1) fits in a single
64881 ** byte (i.e. is less than 128).
64882 */
64883 static int vdbeRecordCompareInt(
64884 int nKey1, const void *pKey1, /* Left key */
64885 const UnpackedRecord *pPKey2, /* Right key */
64886 int bSkip /* Ignored */
64887 ){
64888 const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
64889 int serial_type = ((const u8*)pKey1)[1];
64890 int res;
64891 u32 y;
64892 u64 x;
64893 i64 v = pPKey2->aMem[0].u.i;
64894 i64 lhs;
64895 UNUSED_PARAMETER(bSkip);
64896
64897 assert( bSkip==0 );
64898 switch( serial_type ){
64899 case 1: { /* 1-byte signed integer */
64900 lhs = ONE_BYTE_INT(aKey);
64901 break;
64902 }
64903 case 2: { /* 2-byte signed integer */
64904 lhs = TWO_BYTE_INT(aKey);
64905 break;
64906 }
64907 case 3: { /* 3-byte signed integer */
64908 lhs = THREE_BYTE_INT(aKey);
64909 break;
64910 }
64911 case 4: { /* 4-byte signed integer */
64912 y = FOUR_BYTE_UINT(aKey);
64913 lhs = (i64)*(int*)&y;
64914 break;
64915 }
64916 case 5: { /* 6-byte signed integer */
64917 lhs = FOUR_BYTE_UINT(aKey+2) + (((i64)1)<<32)*TWO_BYTE_INT(aKey);
64918 break;
64919 }
64920 case 6: { /* 8-byte signed integer */
64921 x = FOUR_BYTE_UINT(aKey);
64922 x = (x<<32) | FOUR_BYTE_UINT(aKey+4);
64923 lhs = *(i64*)&x;
64924 break;
64925 }
64926 case 8:
64927 lhs = 0;
64928 break;
64929 case 9:
64930 lhs = 1;
64931 break;
64932
64933 /* This case could be removed without changing the results of running
64934 ** this code. Including it causes gcc to generate a faster switch
64935 ** statement (since the range of switch targets now starts at zero and
64936 ** is contiguous) but does not cause any duplicate code to be generated
64937 ** (as gcc is clever enough to combine the two like cases). Other
64938 ** compilers might be similar. */
64939 case 0: case 7:
64940 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
64941
64942 default:
64943 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
64944 }
64945
64946 if( v>lhs ){
64947 res = pPKey2->r1;
64948 }else if( v<lhs ){
64949 res = pPKey2->r2;
64950 }else if( pPKey2->nField>1 ){
64951 /* The first fields of the two keys are equal. Compare the trailing
64952 ** fields. */
64953 res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
64954 }else{
64955 /* The first fields of the two keys are equal and there are no trailing
64956 ** fields. Return pPKey2->default_rc in this case. */
64957 res = pPKey2->default_rc;
64958 }
64959
64960 assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
64961 || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
64962 || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
64963 || CORRUPT_DB
64964 );
64965 return res;
64966 }
64967
64968 /*
64969 ** This function is an optimized version of sqlite3VdbeRecordCompare()
64970 ** that (a) the first field of pPKey2 is a string, that (b) the first field
64971 ** uses the collation sequence BINARY and (c) that the size-of-header varint
64972 ** at the start of (pKey1/nKey1) fits in a single byte.
64973 */
64974 static int vdbeRecordCompareString(
64975 int nKey1, const void *pKey1, /* Left key */
64976 const UnpackedRecord *pPKey2, /* Right key */
64977 int bSkip
64978 ){
64979 const u8 *aKey1 = (const u8*)pKey1;
64980 int serial_type;
64981 int res;
64982 UNUSED_PARAMETER(bSkip);
64983
64984 assert( bSkip==0 );
64985 getVarint32(&aKey1[1], serial_type);
64986
64987 if( serial_type<12 ){
64988 res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
64989 }else if( !(serial_type & 0x01) ){
64990 res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
64991 }else{
64992 int nCmp;
64993 int nStr;
64994 int szHdr = aKey1[0];
64995
64996 nStr = (serial_type-12) / 2;
64997 if( (szHdr + nStr) > nKey1 ) return 0; /* Corruption */
64998 nCmp = MIN( pPKey2->aMem[0].n, nStr );
64999 res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp);
65000
65001 if( res==0 ){
65002 res = nStr - pPKey2->aMem[0].n;
65003 if( res==0 ){
65004 if( pPKey2->nField>1 ){
65005 res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
65006 }else{
65007 res = pPKey2->default_rc;
65008 }
65009 }else if( res>0 ){
65010 res = pPKey2->r2;
65011 }else{
65012 res = pPKey2->r1;
65013 }
65014 }else if( res>0 ){
65015 res = pPKey2->r2;
65016 }else{
65017 res = pPKey2->r1;
65018 }
65019 }
65020
65021 assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
65022 || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
65023 || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
65024 || CORRUPT_DB
65025 );
65026 return res;
65027 }
65028
65029 /*
65030 ** Return a pointer to an sqlite3VdbeRecordCompare() compatible function
65031 ** suitable for comparing serialized records to the unpacked record passed
65032 ** as the only argument.
65033 */
65034 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
65035 /* varintRecordCompareInt() and varintRecordCompareString() both assume
65036 ** that the size-of-header varint that occurs at the start of each record
65037 ** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
65038 ** also assumes that it is safe to overread a buffer by at least the
65039 ** maximum possible legal header size plus 8 bytes. Because there is
65040 ** guaranteed to be at least 74 (but not 136) bytes of padding following each
65041 ** buffer passed to varintRecordCompareInt() this makes it convenient to
65042 ** limit the size of the header to 64 bytes in cases where the first field
65043 ** is an integer.
65044 **
65045 ** The easiest way to enforce this limit is to consider only records with
65046 ** 13 fields or less. If the first field is an integer, the maximum legal
65047 ** header size is (12*5 + 1 + 1) bytes. */
65048 if( (p->pKeyInfo->nField + p->pKeyInfo->nXField)<=13 ){
65049 int flags = p->aMem[0].flags;
65050 if( p->pKeyInfo->aSortOrder[0] ){
65051 p->r1 = 1;
65052 p->r2 = -1;
65053 }else{
65054 p->r1 = -1;
65055 p->r2 = 1;
65056 }
65057 if( (flags & MEM_Int) ){
65058 return vdbeRecordCompareInt;
65059 }
65060 if( (flags & (MEM_Int|MEM_Real|MEM_Null|MEM_Blob))==0
65061 && p->pKeyInfo->aColl[0]==0
65062 ){
65063 return vdbeRecordCompareString;
65064 }
65065 }
65066
65067 return sqlite3VdbeRecordCompare;
65068 }
65069
65070 /*
65071 ** pCur points at an index entry created using the OP_MakeRecord opcode.
65072 ** Read the rowid (the last field in the record) and store it in *rowid.
65073 ** Return SQLITE_OK if everything works, or an error code otherwise.
@@ -64695,23 +65154,23 @@
65154 ** omits the rowid at the end. The rowid at the end of the index entry
65155 ** is ignored as well. Hence, this routine only compares the prefixes
65156 ** of the keys prior to the final rowid, not the entire key.
65157 */
65158 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
65159 VdbeCursor *pC, /* The cursor to compare against */
65160 const UnpackedRecord *pUnpacked, /* Unpacked version of key */
65161 int *res /* Write the comparison result here */
65162 ){
65163 i64 nCellKey = 0;
65164 int rc;
65165 BtCursor *pCur = pC->pCursor;
65166 Mem m;
65167
65168 assert( sqlite3BtreeCursorIsValid(pCur) );
65169 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
65170 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
65171 /* nCellKey will always be between 0 and 0xffffffff because of the way
65172 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
65173 if( nCellKey<=0 || nCellKey>0x7fffffff ){
65174 *res = 0;
65175 return SQLITE_CORRUPT_BKPT;
65176 }
@@ -64718,12 +65177,11 @@
65177 memset(&m, 0, sizeof(m));
65178 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
65179 if( rc ){
65180 return rc;
65181 }
65182 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked, 0);
 
65183 sqlite3VdbeMemRelease(&m);
65184 return SQLITE_OK;
65185 }
65186
65187 /*
@@ -66629,11 +67087,11 @@
67087 ** does not control the string, it might be deleted without the register
67088 ** knowing it.
67089 **
67090 ** This routine converts an ephemeral string into a dynamically allocated
67091 ** string that the register itself controls. In other words, it
67092 ** converts an MEM_Ephem string into a string with P.z==P.zMalloc.
67093 */
67094 #define Deephemeralize(P) \
67095 if( ((P)->flags&MEM_Ephem)!=0 \
67096 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
67097
@@ -67166,22 +67624,25 @@
67624 #ifdef SQLITE_DEBUG
67625 if( (pOp->opflags & OPFLG_IN1)!=0 ){
67626 assert( pOp->p1>0 );
67627 assert( pOp->p1<=(p->nMem-p->nCursor) );
67628 assert( memIsValid(&aMem[pOp->p1]) );
67629 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
67630 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
67631 }
67632 if( (pOp->opflags & OPFLG_IN2)!=0 ){
67633 assert( pOp->p2>0 );
67634 assert( pOp->p2<=(p->nMem-p->nCursor) );
67635 assert( memIsValid(&aMem[pOp->p2]) );
67636 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
67637 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
67638 }
67639 if( (pOp->opflags & OPFLG_IN3)!=0 ){
67640 assert( pOp->p3>0 );
67641 assert( pOp->p3<=(p->nMem-p->nCursor) );
67642 assert( memIsValid(&aMem[pOp->p3]) );
67643 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
67644 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
67645 }
67646 if( (pOp->opflags & OPFLG_OUT2)!=0 ){
67647 assert( pOp->p2>0 );
67648 assert( pOp->p2<=(p->nMem-p->nCursor) );
@@ -67279,11 +67740,11 @@
67740 ** and then jump to address P2.
67741 */
67742 case OP_Gosub: { /* jump */
67743 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67744 pIn1 = &aMem[pOp->p1];
67745 assert( VdbeMemDynamic(pIn1)==0 );
67746 memAboutToChange(p, pIn1);
67747 pIn1->flags = MEM_Int;
67748 pIn1->u.i = pc;
67749 REGISTER_TRACE(pOp->p1, pIn1);
67750 pc = pOp->p2 - 1;
@@ -67352,11 +67813,11 @@
67813 ** OP_EndCoroutine, jump immediately to P2.
67814 */
67815 case OP_Yield: { /* in1, jump */
67816 int pcDest;
67817 pIn1 = &aMem[pOp->p1];
67818 assert( VdbeMemDynamic(pIn1)==0 );
67819 pIn1->flags = MEM_Int;
67820 pcDest = (int)pIn1->u.i;
67821 pIn1->u.i = pc;
67822 REGISTER_TRACE(pOp->p1, pIn1);
67823 pc = pcDest;
@@ -67525,14 +67986,13 @@
67986 if( encoding!=SQLITE_UTF8 ){
67987 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
67988 if( rc==SQLITE_TOOBIG ) goto too_big;
67989 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
67990 assert( pOut->zMalloc==pOut->z );
67991 assert( VdbeMemDynamic(pOut)==0 );
67992 pOut->zMalloc = 0;
67993 pOut->flags |= MEM_Static;
 
67994 if( pOp->p4type==P4_DYNAMIC ){
67995 sqlite3DbFree(db, pOp->p4.z);
67996 }
67997 pOp->p4type = P4_DYNAMIC;
67998 pOp->p4.z = pOut->z;
@@ -67664,18 +68124,20 @@
68124 do{
68125 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
68126 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
68127 assert( memIsValid(pIn1) );
68128 memAboutToChange(p, pOut);
68129 VdbeMemRelease(pOut);
68130 zMalloc = pOut->zMalloc;
68131 memcpy(pOut, pIn1, sizeof(Mem));
 
68132 #ifdef SQLITE_DEBUG
68133 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
68134 pOut->pScopyFrom += p1 - pOp->p2;
68135 }
68136 #endif
68137 pIn1->flags = MEM_Undefined;
68138 pIn1->xDel = 0;
68139 pIn1->zMalloc = zMalloc;
68140 REGISTER_TRACE(p2++, pOut);
68141 pIn1++;
68142 pOut++;
68143 }while( n-- );
@@ -67848,14 +68310,14 @@
68310 Stringify(pIn2, encoding);
68311 nByte = pIn1->n + pIn2->n;
68312 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
68313 goto too_big;
68314 }
 
68315 if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
68316 goto no_mem;
68317 }
68318 MemSetTypeFlag(pOut, MEM_Str);
68319 if( pOut!=pIn2 ){
68320 memcpy(pOut->z, pIn2->z, pIn2->n);
68321 }
68322 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
68323 pOut->z[nByte]=0;
@@ -69026,10 +69488,11 @@
69488 ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
69489 ** all valid.
69490 */
69491 assert( p2<pC->nHdrParsed );
69492 assert( rc==SQLITE_OK );
69493 assert( sqlite3VdbeCheckMemInvariants(pDest) );
69494 if( pC->szRow>=aOffset[p2+1] ){
69495 /* This is the common case where the desired content fits on the original
69496 ** page - where the content is not on an overflow page */
69497 VdbeMemRelease(pDest);
69498 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
@@ -69063,12 +69526,12 @@
69526 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
69527 ** dynamically allocated space over to the pDest structure.
69528 ** This prevents a memory copy. */
69529 if( sMem.zMalloc ){
69530 assert( sMem.z==sMem.zMalloc );
69531 assert( VdbeMemDynamic(pDest)==0 );
69532 assert( (pDest->flags & (MEM_Blob|MEM_Str))==0 || pDest->z==sMem.z );
69533 pDest->flags &= ~(MEM_Ephem|MEM_Static);
69534 pDest->flags |= MEM_Term;
69535 pDest->z = sMem.z;
69536 pDest->zMalloc = sMem.zMalloc;
69537 }
@@ -69247,11 +69710,11 @@
69710 assert( i==nHdr );
69711 assert( j==nByte );
69712
69713 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69714 pOut->n = (int)nByte;
69715 pOut->flags = MEM_Blob;
69716 pOut->xDel = 0;
69717 if( nZero ){
69718 pOut->u.nZero = nZero;
69719 pOut->flags |= MEM_Zero;
69720 }
@@ -70121,20 +70584,20 @@
70584 r.pKeyInfo = pC->pKeyInfo;
70585 r.nField = (u16)nField;
70586
70587 /* The next line of code computes as follows, only faster:
70588 ** if( oc==OP_SeekGT || oc==OP_SeekLE ){
70589 ** r.default_rc = -1;
70590 ** }else{
70591 ** r.default_rc = +1;
70592 ** }
70593 */
70594 r.default_rc = ((1 & (oc - OP_SeekLT)) ? -1 : +1);
70595 assert( oc!=OP_SeekGT || r.default_rc==-1 );
70596 assert( oc!=OP_SeekLE || r.default_rc==-1 );
70597 assert( oc!=OP_SeekGE || r.default_rc==+1 );
70598 assert( oc!=OP_SeekLT || r.default_rc==+1 );
70599
70600 r.aMem = &aMem[pOp->p3];
70601 #ifdef SQLITE_DEBUG
70602 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70603 #endif
@@ -70288,22 +70751,21 @@
70751 ExpandBlob(&r.aMem[ii]);
70752 #ifdef SQLITE_DEBUG
70753 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
70754 #endif
70755 }
 
70756 pIdxKey = &r;
70757 }else{
70758 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70759 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
70760 );
70761 if( pIdxKey==0 ) goto no_mem;
70762 assert( pIn3->flags & MEM_Blob );
70763 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70764 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
 
70765 }
70766 pIdxKey->default_rc = 0;
70767 if( pOp->opcode==OP_NoConflict ){
70768 /* For the OP_NoConflict opcode, take the jump if any of the
70769 ** input fields are NULL, since any key with a NULL will not
70770 ** conflict */
70771 for(ii=0; ii<r.nField; ii++){
@@ -71188,11 +71650,11 @@
71650 pCrsr = pC->pCursor;
71651 assert( pCrsr!=0 );
71652 assert( pOp->p5==0 );
71653 r.pKeyInfo = pC->pKeyInfo;
71654 r.nField = (u16)pOp->p3;
71655 r.default_rc = 0;
71656 r.aMem = &aMem[pOp->p2];
71657 #ifdef SQLITE_DEBUG
71658 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71659 #endif
71660 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
@@ -71302,14 +71764,14 @@
71764 assert( pOp->p4type==P4_INT32 );
71765 r.pKeyInfo = pC->pKeyInfo;
71766 r.nField = (u16)pOp->p4.i;
71767 if( pOp->opcode<OP_IdxLT ){
71768 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
71769 r.default_rc = -1;
71770 }else{
71771 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
71772 r.default_rc = 0;
71773 }
71774 r.aMem = &aMem[pOp->p3];
71775 #ifdef SQLITE_DEBUG
71776 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71777 #endif
@@ -73809,14 +74271,14 @@
74271 if( r2->aMem[i].flags & MEM_Null ){
74272 *pRes = -1;
74273 return;
74274 }
74275 }
74276 assert( r2->default_rc==0 );
74277 }
74278
74279 *pRes = sqlite3VdbeRecordCompare(nKey1, pKey1, r2, 0);
74280 }
74281
74282 /*
74283 ** This function is called to compare two iterator keys when merging
74284 ** multiple b-tree segments. Parameter iOut is the index of the aTree[]
@@ -75449,10 +75911,12 @@
75911 pExpr->iTable = 1;
75912 pTab = pParse->pTriggerTab;
75913 }else if( op!=TK_INSERT && sqlite3StrICmp("old",zTab)==0 ){
75914 pExpr->iTable = 0;
75915 pTab = pParse->pTriggerTab;
75916 }else{
75917 pTab = 0;
75918 }
75919
75920 if( pTab ){
75921 int iCol;
75922 pSchema = pTab->pSchema;
@@ -100117,11 +100581,11 @@
100581 }else if( eDest!=SRT_Exists ){
100582 /* If the destination is an EXISTS(...) expression, the actual
100583 ** values returned by the SELECT are not required.
100584 */
100585 sqlite3ExprCodeExprList(pParse, pEList, regResult,
100586 (eDest==SRT_Output||eDest==SRT_Coroutine)?SQLITE_ECEL_DUP:0);
100587 }
100588
100589 /* If the DISTINCT keyword was present on the SELECT statement
100590 ** and this row has been seen before, then do not make this row
100591 ** part of the result.
@@ -110767,11 +111231,11 @@
111231 iCol = pRec->nField - 1;
111232 assert( pIdx->nSample>0 );
111233 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
111234 do{
111235 iTest = (iMin+i)/2;
111236 res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec, 0);
111237 if( res<0 ){
111238 iMin = iTest+1;
111239 }else{
111240 i = iTest;
111241 }
@@ -110782,20 +111246,20 @@
111246 ** above found the right answer. This block serves no purpose other
111247 ** than to invoke the asserts. */
111248 if( res==0 ){
111249 /* If (res==0) is true, then sample $i must be equal to pRec */
111250 assert( i<pIdx->nSample );
111251 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)
111252 || pParse->db->mallocFailed );
111253 }else{
111254 /* Otherwise, pRec must be smaller than sample $i and larger than
111255 ** sample ($i-1). */
111256 assert( i==pIdx->nSample
111257 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)>0
111258 || pParse->db->mallocFailed );
111259 assert( i==0
111260 || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec, 0)<0
111261 || pParse->db->mallocFailed );
111262 }
111263 #endif /* ifdef SQLITE_DEBUG */
111264
111265 /* At this point, aSample[i] is the first sample that is greater than
@@ -114724,11 +115188,11 @@
115188
115189 /* For a co-routine, change all OP_Column references to the table of
115190 ** the co-routine into OP_SCopy of result contained in a register.
115191 ** OP_Rowid becomes OP_Null.
115192 */
115193 if( pTabItem->viaCoroutine && !db->mallocFailed ){
115194 last = sqlite3VdbeCurrentAddr(v);
115195 k = pLevel->addrBody;
115196 pOp = sqlite3VdbeGetOp(v, k);
115197 for(; k<last; k++, pOp++){
115198 if( pOp->p1!=pLevel->iTabCur ) continue;
115199
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.4"
111111
#define SQLITE_VERSION_NUMBER 3008004
112
-#define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
112
+#define SQLITE_SOURCE_ID "2014-03-04 13:18:23 9830c343bc954b828f6ca752f8ae63e2c0a980c1"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.4"
111 #define SQLITE_VERSION_NUMBER 3008004
112 #define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.4"
111 #define SQLITE_VERSION_NUMBER 3008004
112 #define SQLITE_SOURCE_ID "2014-03-04 13:18:23 9830c343bc954b828f6ca752f8ae63e2c0a980c1"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- www/changes.wiki
+++ www/changes.wiki
@@ -11,10 +11,13 @@
1111
filter links.
1212
* The [/help/info | info command] now shows leaf status of the checkout.
1313
* Add support for tunneling https through a http proxy (Ticket [e854101c4f]).
1414
* Add option --empty to the "[/help?cmd=open | fossil open]" command.
1515
* Enhanced [/help?cmd=/fileage|the fileage page] to support a glob parameter.
16
+ * Add --ignore-space-at-sol and --ignore-space-at-eol options to [/help?cmd=diff|fossil (g)diff],
17
+ [/help?cmd=stash|fossil stash diff]. The option -w activates both of them.
18
+ * Add button "Ignore Whitespace" to /ci, /vdiff and /fdiff UI pages.
1619
1720
<h2>Changes For Version 1.28 (2014-01-27)</h2>
1821
* Enhance [/help?cmd=/reports | /reports] to support event type filtering.
1922
* When cloning a repository, the user name passed via the URL (if any)
2023
is now used as the default local admin user's name.
2124
--- www/changes.wiki
+++ www/changes.wiki
@@ -11,10 +11,13 @@
11 filter links.
12 * The [/help/info | info command] now shows leaf status of the checkout.
13 * Add support for tunneling https through a http proxy (Ticket [e854101c4f]).
14 * Add option --empty to the "[/help?cmd=open | fossil open]" command.
15 * Enhanced [/help?cmd=/fileage|the fileage page] to support a glob parameter.
 
 
 
16
17 <h2>Changes For Version 1.28 (2014-01-27)</h2>
18 * Enhance [/help?cmd=/reports | /reports] to support event type filtering.
19 * When cloning a repository, the user name passed via the URL (if any)
20 is now used as the default local admin user's name.
21
--- www/changes.wiki
+++ www/changes.wiki
@@ -11,10 +11,13 @@
11 filter links.
12 * The [/help/info | info command] now shows leaf status of the checkout.
13 * Add support for tunneling https through a http proxy (Ticket [e854101c4f]).
14 * Add option --empty to the "[/help?cmd=open | fossil open]" command.
15 * Enhanced [/help?cmd=/fileage|the fileage page] to support a glob parameter.
16 * Add --ignore-space-at-sol and --ignore-space-at-eol options to [/help?cmd=diff|fossil (g)diff],
17 [/help?cmd=stash|fossil stash diff]. The option -w activates both of them.
18 * Add button "Ignore Whitespace" to /ci, /vdiff and /fdiff UI pages.
19
20 <h2>Changes For Version 1.28 (2014-01-27)</h2>
21 * Enhance [/help?cmd=/reports | /reports] to support event type filtering.
22 * When cloning a repository, the user name passed via the URL (if any)
23 is now used as the default local admin user's name.
24

Keyboard Shortcuts

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