Fossil SCM

Update the built-in SQLite to the latest 3.7.6 alpha.

drh 2011-03-07 03:02 trunk
Commit c38a726932b625b0b54e66c5868e64143d237132
2 files changed +238 -171 +1 -1
+238 -171
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651651
** [sqlite_version()] and [sqlite_source_id()].
652652
*/
653653
#define SQLITE_VERSION "3.7.6"
654654
#define SQLITE_VERSION_NUMBER 3007006
655
-#define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a"
655
+#define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -11206,10 +11206,13 @@
1120611206
SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*);
1120711207
SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*);
1120811208
SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
1120911209
SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
1121011210
SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
11211
+SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64);
11212
+SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64);
11213
+SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64);
1121111214
1121211215
SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
1121311216
SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
1121411217
SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
1121511218
void(*)(void*));
@@ -18792,11 +18795,15 @@
1879218795
v = va_arg(ap,long int);
1879318796
}else{
1879418797
v = va_arg(ap,int);
1879518798
}
1879618799
if( v<0 ){
18797
- longvalue = -v;
18800
+ if( v==SMALLEST_INT64 ){
18801
+ longvalue = ((u64)1)<<63;
18802
+ }else{
18803
+ longvalue = -v;
18804
+ }
1879818805
prefix = '-';
1879918806
}else{
1880018807
longvalue = v;
1880118808
if( flag_plussign ) prefix = '+';
1880218809
else if( flag_blanksign ) prefix = ' ';
@@ -20566,64 +20573,84 @@
2056620573
return c;
2056720574
}
2056820575
2056920576
2057020577
/*
20571
-** Convert zNum to a 64-bit signed integer and write
20572
-** the value of the integer into *pNum.
20573
-** If zNum is exactly 9223372036854665808, return 2.
20574
-** This is a special case as the context will determine
20575
-** if it is too big (used as a negative).
20576
-** If zNum is not an integer or is an integer that
20577
-** is too large to be expressed with 64 bits,
20578
-** then return 1. Otherwise return 0.
20578
+** Convert zNum to a 64-bit signed integer.
20579
+**
20580
+** If the zNum value is representable as a 64-bit twos-complement
20581
+** integer, then write that value into *pNum and return 0.
20582
+**
20583
+** If zNum is exactly 9223372036854665808, return 2. This special
20584
+** case is broken out because while 9223372036854665808 cannot be a
20585
+** signed 64-bit integer, its negative -9223372036854665808 can be.
20586
+**
20587
+** If zNum is too big for a 64-bit integer and is not
20588
+** 9223372036854665808 then return 1.
2057920589
**
2058020590
** length is the number of bytes in the string (bytes, not characters).
2058120591
** The string is not necessarily zero-terminated. The encoding is
2058220592
** given by enc.
2058320593
*/
2058420594
SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
2058520595
int incr = (enc==SQLITE_UTF8?1:2);
20586
- i64 v = 0;
20596
+ u64 u = 0;
2058720597
int neg = 0; /* assume positive */
2058820598
int i;
2058920599
int c = 0;
2059020600
const char *zStart;
2059120601
const char *zEnd = zNum + length;
2059220602
if( enc==SQLITE_UTF16BE ) zNum++;
2059320603
while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
20594
- if( zNum>=zEnd ) goto do_atoi_calc;
20595
- if( *zNum=='-' ){
20596
- neg = 1;
20597
- zNum+=incr;
20598
- }else if( *zNum=='+' ){
20599
- zNum+=incr;
20600
- }
20601
-do_atoi_calc:
20604
+ if( zNum<zEnd ){
20605
+ if( *zNum=='-' ){
20606
+ neg = 1;
20607
+ zNum+=incr;
20608
+ }else if( *zNum=='+' ){
20609
+ zNum+=incr;
20610
+ }
20611
+ }
2060220612
zStart = zNum;
2060320613
while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
2060420614
for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
20605
- v = v*10 + c - '0';
20615
+ u = u*10 + c - '0';
2060620616
}
20607
- *pNum = neg ? -v : v;
20617
+ if( u>LARGEST_INT64 ){
20618
+ *pNum = SMALLEST_INT64;
20619
+ }else if( neg ){
20620
+ *pNum = -(i64)u;
20621
+ }else{
20622
+ *pNum = (i64)u;
20623
+ }
2060820624
testcase( i==18 );
2060920625
testcase( i==19 );
2061020626
testcase( i==20 );
2061120627
if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
2061220628
/* zNum is empty or contains non-numeric text or is longer
2061320629
** than 19 digits (thus guaranteeing that it is too large) */
2061420630
return 1;
2061520631
}else if( i<19*incr ){
2061620632
/* Less than 19 digits, so we know that it fits in 64 bits */
20633
+ assert( u<=LARGEST_INT64 );
2061720634
return 0;
2061820635
}else{
20619
- /* 19-digit numbers must be no larger than 9223372036854775807 if positive
20620
- ** or 9223372036854775808 if negative. Note that 9223372036854665808
20621
- ** is 2^63. Return 1 if to large */
20622
- c=compare2pow63(zNum, incr);
20623
- if( c==0 && neg==0 ) return 2; /* too big, exactly 9223372036854665808 */
20624
- return c<neg ? 0 : 1;
20636
+ /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
20637
+ c = compare2pow63(zNum, incr);
20638
+ if( c<0 ){
20639
+ /* zNum is less than 9223372036854775808 so it fits */
20640
+ assert( u<=LARGEST_INT64 );
20641
+ return 0;
20642
+ }else if( c>0 ){
20643
+ /* zNum is greater than 9223372036854775808 so it overflows */
20644
+ return 1;
20645
+ }else{
20646
+ /* zNum is exactly 9223372036854775808. Fits if negative. The
20647
+ ** special case 2 overflow if positive */
20648
+ assert( u-1==LARGEST_INT64 );
20649
+ assert( (*pNum)==SMALLEST_INT64 );
20650
+ return neg ? 0 : 2;
20651
+ }
2062520652
}
2062620653
}
2062720654
2062820655
/*
2062920656
** If zNum represents an integer that will fit in 32-bits, then set
@@ -21185,10 +21212,68 @@
2118521212
return 0;
2118621213
}else{
2118721214
return 1;
2118821215
}
2118921216
}
21217
+
21218
+/*
21219
+** Attempt to add, substract, or multiply the 64-bit signed value iB against
21220
+** the other 64-bit signed integer at *pA and store the result in *pA.
21221
+** Return 0 on success. Or if the operation would have resulted in an
21222
+** overflow, leave *pA unchanged and return 1.
21223
+*/
21224
+SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
21225
+ i64 iA = *pA;
21226
+ testcase( iA==0 ); testcase( iA==1 );
21227
+ testcase( iB==-1 ); testcase( iB==0 );
21228
+ if( iB>=0 ){
21229
+ testcase( iA>0 && LARGEST_INT64 - iA == iB );
21230
+ testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
21231
+ if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
21232
+ *pA += iB;
21233
+ }else{
21234
+ testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
21235
+ testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
21236
+ if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
21237
+ *pA += iB;
21238
+ }
21239
+ return 0;
21240
+}
21241
+SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
21242
+ testcase( iB==SMALLEST_INT64+1 );
21243
+ if( iB==SMALLEST_INT64 ){
21244
+ testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
21245
+ if( (*pA)>=0 ) return 1;
21246
+ *pA -= iB;
21247
+ return 0;
21248
+ }else{
21249
+ return sqlite3AddInt64(pA, -iB);
21250
+ }
21251
+}
21252
+#define TWOPOWER32 (((i64)1)<<32)
21253
+#define TWOPOWER31 (((i64)1)<<31)
21254
+SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
21255
+ i64 iA = *pA;
21256
+ i64 iA1, iA0, iB1, iB0, r;
21257
+
21258
+ iA1 = iA/TWOPOWER32;
21259
+ iA0 = iA % TWOPOWER32;
21260
+ iB1 = iB/TWOPOWER32;
21261
+ iB0 = iB % TWOPOWER32;
21262
+ if( iA1*iB1 != 0 ) return 1;
21263
+ assert( iA1*iB0==0 || iA0*iB1==0 );
21264
+ r = iA1*iB0 + iA0*iB1;
21265
+ testcase( r==(-TWOPOWER31)-1 );
21266
+ testcase( r==(-TWOPOWER31) );
21267
+ testcase( r==TWOPOWER31 );
21268
+ testcase( r==TWOPOWER31-1 );
21269
+ if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
21270
+ r *= TWOPOWER32;
21271
+ if( sqlite3AddInt64(&r, iA0*iB0) ) return 1;
21272
+ *pA = r;
21273
+ return 0;
21274
+}
2119021275
2119121276
/************** End of util.c ************************************************/
2119221277
/************** Begin file hash.c ********************************************/
2119321278
/*
2119421279
** 2001 September 22
@@ -23930,18 +24015,19 @@
2393024015
** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
2393124016
** The two subsequent arguments should be the name of the OS function that
2393224017
** failed (e.g. "unlink", "open") and the the associated file-system path,
2393324018
** if any.
2393424019
*/
23935
-#define unixLogError(a,b,c) unixLogError_x(a,b,c,__LINE__)
23936
-static int unixLogError_x(
24020
+#define unixLogError(a,b,c) unixLogErrorAtLine(a,b,c,__LINE__)
24021
+static int unixLogErrorAtLine(
2393724022
int errcode, /* SQLite error code */
2393824023
const char *zFunc, /* Name of OS function that failed */
2393924024
const char *zPath, /* File path associated with error */
2394024025
int iLine /* Source line number where error occurred */
2394124026
){
2394224027
char *zErr; /* Message from strerror() or equivalent */
24028
+ int iErrno = errno; /* Saved syscall error number */
2394324029
2394424030
/* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
2394524031
** the strerror() function to obtain the human-readable error message
2394624032
** equivalent to errno. Otherwise, use strerror_r().
2394724033
*/
@@ -23963,58 +24049,63 @@
2396324049
** could lead to a segfault though.
2396424050
*/
2396524051
#if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
2396624052
zErr =
2396724053
# endif
23968
- strerror_r(errno, aErr, sizeof(aErr)-1);
24054
+ strerror_r(iErrno, aErr, sizeof(aErr)-1);
2396924055
2397024056
#elif SQLITE_THREADSAFE
2397124057
/* This is a threadsafe build, but strerror_r() is not available. */
2397224058
zErr = "";
2397324059
#else
2397424060
/* Non-threadsafe build, use strerror(). */
23975
- zErr = strerror(errno);
24061
+ zErr = strerror(iErrno);
2397624062
#endif
2397724063
2397824064
assert( errcode!=SQLITE_OK );
24065
+ if( zPath==0 ) zPath = "";
2397924066
sqlite3_log(errcode,
23980
- "os_unix.c: %s() at line %d - \"%s\" errno=%d path=%s",
23981
- zFunc, iLine, zErr, errno, (zPath ? zPath : "n/a")
24067
+ "os_unix.c:%d: (%d) %s(%s) - %s",
24068
+ iLine, iErrno, zFunc, zPath, zErr
2398224069
);
2398324070
2398424071
return errcode;
2398524072
}
2398624073
24074
+/*
24075
+** Close a file descriptor.
24076
+**
24077
+** We assume that close() almost always works, since it is only in a
24078
+** very sick application or on a very sick platform that it might fail.
24079
+** If it does fail, simply leak the file descriptor, but do log the
24080
+** error.
24081
+**
24082
+** Note that it is not safe to retry close() after EINTR since the
24083
+** file descriptor might have already been reused by another thread.
24084
+** So we don't even try to recover from an EINTR. Just log the error
24085
+** and move on.
24086
+*/
24087
+static void robust_close(unixFile *pFile, int h, int lineno){
24088
+ if( close(h) ){
24089
+ unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
24090
+ pFile ? pFile->zPath : 0, lineno);
24091
+ }
24092
+}
2398724093
2398824094
/*
2398924095
** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
23990
-** If all such file descriptors are closed without error, the list is
23991
-** cleared and SQLITE_OK returned.
23992
-**
23993
-** Otherwise, if an error occurs, then successfully closed file descriptor
23994
-** entries are removed from the list, and SQLITE_IOERR_CLOSE returned.
23995
-** not deleted and SQLITE_IOERR_CLOSE returned.
2399624096
*/
23997
-static int closePendingFds(unixFile *pFile){
23998
- int rc = SQLITE_OK;
24097
+static void closePendingFds(unixFile *pFile){
2399924098
unixInodeInfo *pInode = pFile->pInode;
24000
- UnixUnusedFd *pError = 0;
2400124099
UnixUnusedFd *p;
2400224100
UnixUnusedFd *pNext;
2400324101
for(p=pInode->pUnused; p; p=pNext){
2400424102
pNext = p->pNext;
24005
- if( close(p->fd) ){
24006
- pFile->lastErrno = errno;
24007
- rc = unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath);
24008
- p->pNext = pError;
24009
- pError = p;
24010
- }else{
24011
- sqlite3_free(p);
24012
- }
24013
- }
24014
- pInode->pUnused = pError;
24015
- return rc;
24103
+ robust_close(pFile, p->fd, __LINE__);
24104
+ sqlite3_free(p);
24105
+ }
24106
+ pInode->pUnused = 0;
2401624107
}
2401724108
2401824109
/*
2401924110
** Release a unixInodeInfo structure previously allocated by findInodeInfo().
2402024111
**
@@ -24621,14 +24712,11 @@
2462124712
** was deferred because of outstanding locks.
2462224713
*/
2462324714
pInode->nLock--;
2462424715
assert( pInode->nLock>=0 );
2462524716
if( pInode->nLock==0 ){
24626
- int rc2 = closePendingFds(pFile);
24627
- if( rc==SQLITE_OK ){
24628
- rc = rc2;
24629
- }
24717
+ closePendingFds(pFile);
2463024718
}
2463124719
}
2463224720
2463324721
end_unlock:
2463424722
unixLeaveMutex();
@@ -24659,24 +24747,16 @@
2465924747
*/
2466024748
static int closeUnixFile(sqlite3_file *id){
2466124749
unixFile *pFile = (unixFile*)id;
2466224750
if( pFile ){
2466324751
if( pFile->dirfd>=0 ){
24664
- int err = close(pFile->dirfd);
24665
- if( err ){
24666
- pFile->lastErrno = errno;
24667
- return unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath);
24668
- }else{
24669
- pFile->dirfd=-1;
24670
- }
24752
+ robust_close(pFile, pFile->dirfd, __LINE__);
24753
+ pFile->dirfd=-1;
2467124754
}
2467224755
if( pFile->h>=0 ){
24673
- int err = close(pFile->h);
24674
- if( err ){
24675
- pFile->lastErrno = errno;
24676
- return unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath);
24677
- }
24756
+ robust_close(pFile, pFile->h, __LINE__);
24757
+ pFile->h = -1;
2467824758
}
2467924759
#if OS_VXWORKS
2468024760
if( pFile->pId ){
2468124761
if( pFile->isDelete ){
2468224762
unlink(pFile->pId->zCanonicalName);
@@ -24882,14 +24962,11 @@
2488224962
pFile->lastErrno = tErrno;
2488324963
}
2488424964
}
2488524965
return rc;
2488624966
}
24887
- if( close(fd) ){
24888
- pFile->lastErrno = errno;
24889
- rc = SQLITE_IOERR_CLOSE;
24890
- }
24967
+ robust_close(pFile, fd, __LINE__);
2489124968
2489224969
/* got it, set the type and return ok */
2489324970
pFile->eFileLock = eFileLock;
2489424971
return rc;
2489524972
}
@@ -25777,11 +25854,11 @@
2577725854
}
2577825855
if( rc==SQLITE_OK ){
2577925856
pInode->nLock--;
2578025857
assert( pInode->nLock>=0 );
2578125858
if( pInode->nLock==0 ){
25782
- rc = closePendingFds(pFile);
25859
+ closePendingFds(pFile);
2578325860
}
2578425861
}
2578525862
}
2578625863
2578725864
unixLeaveMutex();
@@ -26210,11 +26287,10 @@
2621026287
if( rc ){
2621126288
pFile->lastErrno = errno;
2621226289
return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
2621326290
}
2621426291
if( pFile->dirfd>=0 ){
26215
- int err;
2621626292
OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd,
2621726293
HAVE_FULLFSYNC, isFullsync));
2621826294
#ifndef SQLITE_DISABLE_DIRSYNC
2621926295
/* The directory sync is only attempted if full_fsync is
2622026296
** turned off or unavailable. If a full_fsync occurred above,
@@ -26229,17 +26305,13 @@
2622926305
*/
2623026306
/* pFile->lastErrno = errno; */
2623126307
/* return SQLITE_IOERR; */
2623226308
}
2623326309
#endif
26234
- err = close(pFile->dirfd); /* Only need to sync once, so close the */
26235
- if( err==0 ){ /* directory when we are done */
26236
- pFile->dirfd = -1;
26237
- }else{
26238
- pFile->lastErrno = errno;
26239
- rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath);
26240
- }
26310
+ /* Only need to sync once, so close the directory when we are done */
26311
+ robust_close(pFile, pFile->dirfd, __LINE__);
26312
+ pFile->dirfd = -1;
2624126313
}
2624226314
return rc;
2624326315
}
2624426316
2624526317
/*
@@ -26602,11 +26674,14 @@
2660226674
if( p->mutex ) sqlite3_mutex_free(p->mutex);
2660326675
for(i=0; i<p->nRegion; i++){
2660426676
munmap(p->apRegion[i], p->szRegion);
2660526677
}
2660626678
sqlite3_free(p->apRegion);
26607
- if( p->h>=0 ) close(p->h);
26679
+ if( p->h>=0 ){
26680
+ robust_close(pFd, p->h, __LINE__);
26681
+ p->h = -1;
26682
+ }
2660826683
p->pInode->pShmNode = 0;
2660926684
sqlite3_free(p);
2661026685
}
2661126686
}
2661226687
@@ -27413,11 +27488,11 @@
2741327488
**
2741427489
** If scenario (a) caused the error then things are not so safe. The
2741527490
** implicit assumption here is that if fstat() fails, things are in
2741627491
** such bad shape that dropping a lock or two doesn't matter much.
2741727492
*/
27418
- close(h);
27493
+ robust_close(pNew, h, __LINE__);
2741927494
h = -1;
2742027495
}
2742127496
unixLeaveMutex();
2742227497
}
2742327498
@@ -27439,11 +27514,11 @@
2743927514
srandomdev();
2744027515
unixEnterMutex();
2744127516
rc = findInodeInfo(pNew, &pNew->pInode);
2744227517
if( rc!=SQLITE_OK ){
2744327518
sqlite3_free(pNew->lockingContext);
27444
- close(h);
27519
+ robust_close(pNew, h, __LINE__);
2744527520
h = -1;
2744627521
}
2744727522
unixLeaveMutex();
2744827523
}
2744927524
}
@@ -27490,20 +27565,20 @@
2749027565
#endif
2749127566
2749227567
pNew->lastErrno = 0;
2749327568
#if OS_VXWORKS
2749427569
if( rc!=SQLITE_OK ){
27495
- if( h>=0 ) close(h);
27570
+ if( h>=0 ) robust_close(pNew, h, __LINE__);
2749627571
h = -1;
2749727572
unlink(zFilename);
2749827573
isDelete = 0;
2749927574
}
2750027575
pNew->isDelete = isDelete;
2750127576
#endif
2750227577
if( rc!=SQLITE_OK ){
27503
- if( dirfd>=0 ) close(dirfd); /* silent leak if fail, already in error */
27504
- if( h>=0 ) close(h);
27578
+ if( dirfd>=0 ) robust_close(pNew, dirfd, __LINE__);
27579
+ if( h>=0 ) robust_close(pNew, h, __LINE__);
2750527580
}else{
2750627581
pNew->pMethod = pLockingStyle;
2750727582
OpenCounter(+1);
2750827583
}
2750927584
return rc;
@@ -27911,11 +27986,11 @@
2791127986
/* It is safe to close fd at this point, because it is guaranteed not
2791227987
** to be open on a database file. If it were open on a database file,
2791327988
** it would not be safe to close as this would release any locks held
2791427989
** on the file by this process. */
2791527990
assert( eType!=SQLITE_OPEN_MAIN_DB );
27916
- close(fd); /* silently leak if fail, already in error */
27991
+ robust_close(p, fd, __LINE__);
2791727992
goto open_finished;
2791827993
}
2791927994
}
2792027995
2792127996
#ifdef FD_CLOEXEC
@@ -27927,12 +28002,12 @@
2792728002
2792828003
#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
2792928004
struct statfs fsInfo;
2793028005
if( fstatfs(fd, &fsInfo) == -1 ){
2793128006
((unixFile*)pFile)->lastErrno = errno;
27932
- if( dirfd>=0 ) close(dirfd); /* silently leak if fail, in error */
27933
- close(fd); /* silently leak if fail, in error */
28007
+ if( dirfd>=0 ) robust_close(p, dirfd, __LINE__);
28008
+ robust_close(p, fd, __LINE__);
2793428009
return SQLITE_IOERR_ACCESS;
2793528010
}
2793628011
if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
2793728012
((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
2793828013
}
@@ -27960,13 +28035,13 @@
2796028035
** we're assuming that statfs() doesn't fail very often. At least
2796128036
** not while other file descriptors opened by the same process on
2796228037
** the same file are working. */
2796328038
p->lastErrno = errno;
2796428039
if( dirfd>=0 ){
27965
- close(dirfd); /* silently leak if fail, in error */
28040
+ robust_close(p, dirfd, __LINE__);
2796628041
}
27967
- close(fd); /* silently leak if fail, in error */
28042
+ robust_close(p, fd, __LINE__);
2796828043
rc = SQLITE_IOERR_ACCESS;
2796928044
goto open_finished;
2797028045
}
2797128046
useProxy = !(fsInfo.f_flags&MNT_LOCAL);
2797228047
}
@@ -28023,13 +28098,11 @@
2802328098
if( fsync(fd) )
2802428099
#endif
2802528100
{
2802628101
rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath);
2802728102
}
28028
- if( close(fd)&&!rc ){
28029
- rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", zPath);
28030
- }
28103
+ robust_close(0, fd, __LINE__);
2803128104
}
2803228105
}
2803328106
#endif
2803428107
return rc;
2803528108
}
@@ -28213,11 +28286,11 @@
2821328286
memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
2821428287
assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
2821528288
nBuf = sizeof(t) + sizeof(pid);
2821628289
}else{
2821728290
do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
28218
- close(fd);
28291
+ robust_close(0, fd, __LINE__);
2821928292
}
2822028293
}
2822128294
#endif
2822228295
return nBuf;
2822328296
}
@@ -28656,11 +28729,11 @@
2865628729
if( rc==SQLITE_OK ){
2865728730
*ppFile = pNew;
2865828731
return SQLITE_OK;
2865928732
}
2866028733
end_create_proxy:
28661
- close(fd); /* silently leak fd if error, we're already in error */
28734
+ robust_close(pNew, fd, __LINE__);
2866228735
sqlite3_free(pNew);
2866328736
sqlite3_free(pUnused);
2866428737
return rc;
2866528738
}
2866628739
@@ -28756,19 +28829,19 @@
2875628829
sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno);
2875728830
goto end_breaklock;
2875828831
}
2875928832
rc = 0;
2876028833
fprintf(stderr, "broke stale lock on %s\n", cPath);
28761
- close(conchFile->h);
28834
+ robust_close(pFile, conchFile->h, __LINE__);
2876228835
conchFile->h = fd;
2876328836
conchFile->openFlags = O_RDWR | O_CREAT;
2876428837
2876528838
end_breaklock:
2876628839
if( rc ){
2876728840
if( fd>=0 ){
2876828841
unlink(tPath);
28769
- close(fd);
28842
+ robust_close(pFile, fd, __LINE__);
2877028843
}
2877128844
fprintf(stderr, "failed to break stale lock on %s, %s\n", cPath, errmsg);
2877228845
}
2877328846
return rc;
2877428847
}
@@ -28981,11 +29054,10 @@
2898129054
/* If we created a new conch file (not just updated the contents of a
2898229055
** valid conch file), try to match the permissions of the database
2898329056
*/
2898429057
if( rc==SQLITE_OK && createConch ){
2898529058
struct stat buf;
28986
- int rc;
2898729059
int err = fstat(pFile->h, &buf);
2898829060
if( err==0 ){
2898929061
mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
2899029062
S_IROTH|S_IWOTH);
2899129063
/* try to match the database file R/W permissions, ignore failure */
@@ -29014,18 +29086,11 @@
2901429086
2901529087
end_takeconch:
2901629088
OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h));
2901729089
if( rc==SQLITE_OK && pFile->openFlags ){
2901829090
if( pFile->h>=0 ){
29019
-#ifdef STRICT_CLOSE_ERROR
29020
- if( close(pFile->h) ){
29021
- pFile->lastErrno = errno;
29022
- return SQLITE_IOERR_CLOSE;
29023
- }
29024
-#else
29025
- close(pFile->h); /* silently leak fd if fail */
29026
-#endif
29091
+ robust_close(pFile, pFile->h, __LINE__);
2902729092
}
2902829093
pFile->h = -1;
2902929094
int fd = open(pCtx->dbPath, pFile->openFlags,
2903029095
SQLITE_DEFAULT_FILE_PERMISSIONS);
2903129096
OSTRACE(("TRANSPROXY: OPEN %d\n", fd));
@@ -43555,11 +43620,10 @@
4355543620
if( rc!=SQLITE_OK ){
4355643621
return rc;
4355743622
}
4355843623
assert( pIter );
4355943624
43560
- mxPage = pWal->hdr.nPage;
4356143625
if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall;
4356243626
4356343627
/* Compute in mxSafeFrame the index of the last frame of the WAL that is
4356443628
** safe to write into the database. Frames beyond mxSafeFrame might
4356543629
** overwrite database pages that are in use by active readers and thus
@@ -51996,13 +52060,11 @@
5199652060
minI = j;
5199752061
minV = apNew[j]->pgno;
5199852062
}
5199952063
}
5200052064
if( minI>i ){
52001
- int t;
5200252065
MemPage *pT;
52003
- t = apNew[i]->pgno;
5200452066
pT = apNew[i];
5200552067
apNew[i] = apNew[minI];
5200652068
apNew[minI] = pT;
5200752069
}
5200852070
}
@@ -55005,11 +55067,11 @@
5500555067
if( flags & MEM_Int ){
5500655068
return pMem->u.i;
5500755069
}else if( flags & MEM_Real ){
5500855070
return doubleToInt64(pMem->r);
5500955071
}else if( flags & (MEM_Str|MEM_Blob) ){
55010
- i64 value;
55072
+ i64 value = 0;
5501155073
assert( pMem->z || pMem->n==0 );
5501255074
testcase( pMem->z==0 );
5501355075
sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
5501455076
return value;
5501555077
}else{
@@ -57310,11 +57372,11 @@
5731057372
** pointers to VdbeFrame objects, which may in turn contain pointers to
5731157373
** open cursors.
5731257374
*/
5731357375
static void closeAllCursors(Vdbe *p){
5731457376
if( p->pFrame ){
57315
- VdbeFrame *pFrame = p->pFrame;
57377
+ VdbeFrame *pFrame;
5731657378
for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
5731757379
sqlite3VdbeFrameRestore(pFrame);
5731857380
}
5731957381
p->pFrame = 0;
5732057382
p->nFrame = 0;
@@ -58290,11 +58352,17 @@
5829058352
i64 i = pMem->u.i;
5829158353
u64 u;
5829258354
if( file_format>=4 && (i&1)==i ){
5829358355
return 8+(u32)i;
5829458356
}
58295
- u = i<0 ? -i : i;
58357
+ if( i<0 ){
58358
+ if( i<(-MAX_6BYTE) ) return 6;
58359
+ /* Previous test prevents: u = -(-9223372036854775808) */
58360
+ u = -i;
58361
+ }else{
58362
+ u = i;
58363
+ }
5829658364
if( u<=127 ) return 1;
5829758365
if( u<=32767 ) return 2;
5829858366
if( u<=8388607 ) return 3;
5829958367
if( u<=2147483647 ) return 4;
5830058368
if( u<=MAX_6BYTE ) return 5;
@@ -59640,17 +59708,15 @@
5964059708
** If iCol is not valid, return a pointer to a Mem which has a value
5964159709
** of NULL.
5964259710
*/
5964359711
static Mem *columnMem(sqlite3_stmt *pStmt, int i){
5964459712
Vdbe *pVm;
59645
- int vals;
5964659713
Mem *pOut;
5964759714
5964859715
pVm = (Vdbe *)pStmt;
5964959716
if( pVm && pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){
5965059717
sqlite3_mutex_enter(pVm->db->mutex);
59651
- vals = sqlite3_data_count(pStmt);
5965259718
pOut = &pVm->pResultSet[i];
5965359719
}else{
5965459720
/* If the value passed as the second argument is out of range, return
5965559721
** a pointer to the following static Mem object which contains the
5965659722
** value SQL NULL. Even though the Mem structure contains an element
@@ -61138,12 +61204,14 @@
6113861204
sqlite3_context ctx;
6113961205
sqlite3_value **apVal;
6114061206
int n;
6114161207
} ag;
6114261208
struct OP_ShiftRight_stack_vars {
61143
- i64 a;
61144
- i64 b;
61209
+ i64 iA;
61210
+ u64 uA;
61211
+ i64 iB;
61212
+ u8 op;
6114561213
} ah;
6114661214
struct OP_Ge_stack_vars {
6114761215
int res; /* Result of the comparison of pIn1 against pIn3 */
6114861216
char affinity; /* Affinity to use for comparison */
6114961217
u16 flags1; /* Copy of initial value of pIn1->flags */
@@ -62189,23 +62257,16 @@
6218962257
if( (u.af.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
6219062258
if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
6219162259
u.af.iA = pIn1->u.i;
6219262260
u.af.iB = pIn2->u.i;
6219362261
switch( pOp->opcode ){
62194
- case OP_Add: u.af.iB += u.af.iA; break;
62195
- case OP_Subtract: u.af.iB -= u.af.iA; break;
62196
- case OP_Multiply: u.af.iB *= u.af.iA; break;
62262
+ case OP_Add: if( sqlite3AddInt64(&u.af.iB,u.af.iA) ) goto fp_math; break;
62263
+ case OP_Subtract: if( sqlite3SubInt64(&u.af.iB,u.af.iA) ) goto fp_math; break;
62264
+ case OP_Multiply: if( sqlite3MulInt64(&u.af.iB,u.af.iA) ) goto fp_math; break;
6219762265
case OP_Divide: {
6219862266
if( u.af.iA==0 ) goto arithmetic_result_is_null;
62199
- /* Dividing the largest possible negative 64-bit integer (1<<63) by
62200
- ** -1 returns an integer too large to store in a 64-bit data-type. On
62201
- ** some architectures, the value overflows to (1<<63). On others,
62202
- ** a SIGFPE is issued. The following statement normalizes this
62203
- ** behavior so that all architectures behave as if integer
62204
- ** overflow occurred.
62205
- */
62206
- if( u.af.iA==-1 && u.af.iB==SMALLEST_INT64 ) u.af.iA = 1;
62267
+ if( u.af.iA==-1 && u.af.iB==SMALLEST_INT64 ) goto fp_math;
6220762268
u.af.iB /= u.af.iA;
6220862269
break;
6220962270
}
6221062271
default: {
6221162272
if( u.af.iA==0 ) goto arithmetic_result_is_null;
@@ -62215,10 +62276,11 @@
6221562276
}
6221662277
}
6221762278
pOut->u.i = u.af.iB;
6221862279
MemSetTypeFlag(pOut, MEM_Int);
6221962280
}else{
62281
+fp_math:
6222062282
u.af.rA = sqlite3VdbeRealValue(pIn1);
6222162283
u.af.rB = sqlite3VdbeRealValue(pIn2);
6222262284
switch( pOp->opcode ){
6222362285
case OP_Add: u.af.rB += u.af.rA; break;
6222462286
case OP_Subtract: u.af.rB -= u.af.rA; break;
@@ -62412,31 +62474,55 @@
6241262474
case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
6241362475
case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
6241462476
case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
6241562477
case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
6241662478
#if 0 /* local variables moved into u.ah */
62417
- i64 a;
62418
- i64 b;
62479
+ i64 iA;
62480
+ u64 uA;
62481
+ i64 iB;
62482
+ u8 op;
6241962483
#endif /* local variables moved into u.ah */
6242062484
6242162485
pIn1 = &aMem[pOp->p1];
6242262486
pIn2 = &aMem[pOp->p2];
6242362487
pOut = &aMem[pOp->p3];
6242462488
if( (pIn1->flags | pIn2->flags) & MEM_Null ){
6242562489
sqlite3VdbeMemSetNull(pOut);
6242662490
break;
6242762491
}
62428
- u.ah.a = sqlite3VdbeIntValue(pIn2);
62429
- u.ah.b = sqlite3VdbeIntValue(pIn1);
62430
- switch( pOp->opcode ){
62431
- case OP_BitAnd: u.ah.a &= u.ah.b; break;
62432
- case OP_BitOr: u.ah.a |= u.ah.b; break;
62433
- case OP_ShiftLeft: u.ah.a <<= u.ah.b; break;
62434
- default: assert( pOp->opcode==OP_ShiftRight );
62435
- u.ah.a >>= u.ah.b; break;
62436
- }
62437
- pOut->u.i = u.ah.a;
62492
+ u.ah.iA = sqlite3VdbeIntValue(pIn2);
62493
+ u.ah.iB = sqlite3VdbeIntValue(pIn1);
62494
+ u.ah.op = pOp->opcode;
62495
+ if( u.ah.op==OP_BitAnd ){
62496
+ u.ah.iA &= u.ah.iB;
62497
+ }else if( u.ah.op==OP_BitOr ){
62498
+ u.ah.iA |= u.ah.iB;
62499
+ }else if( u.ah.iB!=0 ){
62500
+ assert( u.ah.op==OP_ShiftRight || u.ah.op==OP_ShiftLeft );
62501
+
62502
+ /* If shifting by a negative amount, shift in the other direction */
62503
+ if( u.ah.iB<0 ){
62504
+ assert( OP_ShiftRight==OP_ShiftLeft+1 );
62505
+ u.ah.op = 2*OP_ShiftLeft + 1 - u.ah.op;
62506
+ u.ah.iB = u.ah.iB>(-64) ? -u.ah.iB : 64;
62507
+ }
62508
+
62509
+ if( u.ah.iB>=64 ){
62510
+ u.ah.iA = (u.ah.iA>=0 || u.ah.op==OP_ShiftLeft) ? 0 : -1;
62511
+ }else{
62512
+ memcpy(&u.ah.uA, &u.ah.iA, sizeof(u.ah.uA));
62513
+ if( u.ah.op==OP_ShiftLeft ){
62514
+ u.ah.uA <<= u.ah.iB;
62515
+ }else{
62516
+ u.ah.uA >>= u.ah.iB;
62517
+ /* Sign-extend on a right shift of a negative number */
62518
+ if( u.ah.iA<0 ) u.ah.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ah.iB);
62519
+ }
62520
+ memcpy(&u.ah.iA, &u.ah.uA, sizeof(u.ah.iA));
62521
+ }
62522
+ }
62523
+ pOut->u.i = u.ah.iA;
6243862524
MemSetTypeFlag(pOut, MEM_Int);
6243962525
break;
6244062526
}
6244162527
6244262528
/* Opcode: AddImm P1 P2 * * *
@@ -63372,11 +63458,10 @@
6337263458
** hdr-size field is also a varint which is the offset from the beginning
6337363459
** of the record to data0.
6337463460
*/
6337563461
u.ao.nData = 0; /* Number of bytes of data space */
6337663462
u.ao.nHdr = 0; /* Number of bytes of header space */
63377
- u.ao.nByte = 0; /* Data space required for this record */
6337863463
u.ao.nZero = 0; /* Number of zero bytes at the end of the record */
6337963464
u.ao.nField = pOp->p1;
6338063465
u.ao.zAffinity = pOp->p4.z;
6338163466
assert( u.ao.nField>0 && pOp->p2>0 && pOp->p2+u.ao.nField<=p->nMem+1 );
6338263467
u.ao.pData0 = &aMem[u.ao.nField];
@@ -64678,11 +64763,10 @@
6467864763
** it already exists in the table. If it does not exist, we have
6467964764
** succeeded. If the random rowid does exist, we select a new one
6468064765
** and try again, up to 100 times.
6468164766
*/
6468264767
assert( u.be.pC->isTable );
64683
- u.be.cnt = 0;
6468464768
6468564769
#ifdef SQLITE_32BIT_ROWID
6468664770
# define MAX_ROWID 0x7fffffff
6468764771
#else
6468864772
/* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -71317,11 +71401,11 @@
7131771401
const char *z = pExpr->u.zToken;
7131871402
assert( z!=0 );
7131971403
c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
7132071404
if( c==0 || (c==2 && negFlag) ){
7132171405
char *zV;
71322
- if( negFlag ){ value = -value; }
71406
+ if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
7132371407
zV = dup8bytes(v, (char*)&value);
7132471408
sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
7132571409
}else{
7132671410
#ifdef SQLITE_OMIT_FLOATING_POINT
7132771411
sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
@@ -81443,17 +81527,12 @@
8144381527
if( p && type!=SQLITE_NULL ){
8144481528
p->cnt++;
8144581529
if( type==SQLITE_INTEGER ){
8144681530
i64 v = sqlite3_value_int64(argv[0]);
8144781531
p->rSum += v;
81448
- if( (p->approx|p->overflow)==0 ){
81449
- i64 iNewSum = p->iSum + v;
81450
- int s1 = (int)(p->iSum >> (sizeof(i64)*8-1));
81451
- int s2 = (int)(v >> (sizeof(i64)*8-1));
81452
- int s3 = (int)(iNewSum >> (sizeof(i64)*8-1));
81453
- p->overflow = ((s1&s2&~s3) | (~s1&~s2&s3))?1:0;
81454
- p->iSum = iNewSum;
81532
+ if( (p->approx|p->overflow)==0 && sqlite3AddInt64(&p->iSum, v) ){
81533
+ p->overflow = 1;
8145581534
}
8145681535
}else{
8145781536
p->rSum += sqlite3_value_double(argv[0]);
8145881537
p->approx = 1;
8145981538
}
@@ -82489,11 +82568,10 @@
8248982568
Table *pTab, /* Row is being deleted from this table */
8249082569
int regOld, /* Previous row data is stored here */
8249182570
int regNew /* New row data is stored here */
8249282571
){
8249382572
sqlite3 *db = pParse->db; /* Database handle */
82494
- Vdbe *v; /* VM to write code to */
8249582573
FKey *pFKey; /* Used to iterate through FKs */
8249682574
int iDb; /* Index of database containing pTab */
8249782575
const char *zDb; /* Name of database containing pTab */
8249882576
int isIgnoreErrors = pParse->disableTriggers;
8249982577
@@ -82501,11 +82579,10 @@
8250182579
assert( (regOld==0)!=(regNew==0) );
8250282580
8250382581
/* If foreign-keys are disabled, this function is a no-op. */
8250482582
if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
8250582583
82506
- v = sqlite3GetVdbe(pParse);
8250782584
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
8250882585
zDb = db->aDb[iDb].zName;
8250982586
8251082587
/* Loop through all the foreign key constraints for which pTab is the
8251182588
** child table (the table that the foreign key definition is part of). */
@@ -83459,11 +83536,10 @@
8345983536
int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
8346083537
int regRowCount = 0; /* Memory cell used for the row counter */
8346183538
int regIns; /* Block of regs holding rowid+data being inserted */
8346283539
int regRowid; /* registers holding insert rowid */
8346383540
int regData; /* register holding first column to insert */
83464
- int regRecord; /* Holds the assemblied row record */
8346583541
int regEof = 0; /* Register recording end of SELECT data */
8346683542
int *aRegIdx = 0; /* One register allocated to each index */
8346783543
8346883544
#ifndef SQLITE_OMIT_TRIGGER
8346983545
int isView; /* True if attempting to insert into a view */
@@ -83788,11 +83864,10 @@
8378883864
}
8378983865
8379083866
/* Allocate registers for holding the rowid of the new row,
8379183867
** the content of the new row, and the assemblied row record.
8379283868
*/
83793
- regRecord = ++pParse->nMem;
8379483869
regRowid = regIns = pParse->nMem+1;
8379583870
pParse->nMem += pTab->nCol + 1;
8379683871
if( IsVirtual(pTab) ){
8379783872
regRowid++;
8379883873
pParse->nMem++;
@@ -84182,11 +84257,11 @@
8418284257
case OE_Abort:
8418384258
sqlite3MayAbort(pParse);
8418484259
case OE_Rollback:
8418584260
case OE_Fail: {
8418684261
char *zMsg;
84187
- j1 = sqlite3VdbeAddOp3(v, OP_HaltIfNull,
84262
+ sqlite3VdbeAddOp3(v, OP_HaltIfNull,
8418884263
SQLITE_CONSTRAINT, onError, regData+i);
8418984264
zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL",
8419084265
pTab->zName, pTab->aCol[i].zName);
8419184266
sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC);
8419284267
break;
@@ -87708,11 +87783,11 @@
8770887783
Db *pDb;
8770987784
char const *azArg[4];
8771087785
int meta[5];
8771187786
InitData initData;
8771287787
char const *zMasterSchema;
87713
- char const *zMasterName = SCHEMA_TABLE(iDb);
87788
+ char const *zMasterName;
8771487789
int openedTransaction = 0;
8771587790
8771687791
/*
8771787792
** The master database table has a structure like this
8771887793
*/
@@ -93351,11 +93426,10 @@
9335193426
sqlite3 *db = pParse->db; /* The database */
9335293427
DbFixer sFix; /* Fixer object */
9335393428
int iDb; /* Database containing the trigger */
9335493429
Token nameToken; /* Trigger name for error reporting */
9335593430
93356
- pTrig = pParse->pNewTrigger;
9335793431
pParse->pNewTrigger = 0;
9335893432
if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
9335993433
zName = pTrig->zName;
9336093434
iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
9336193435
pTrig->step_list = pStepList;
@@ -94314,11 +94388,10 @@
9431494388
int regOldRowid; /* The old rowid */
9431594389
int regNewRowid; /* The new rowid */
9431694390
int regNew;
9431794391
int regOld = 0;
9431894392
int regRowSet = 0; /* Rowset of rows to be updated */
94319
- int regRec; /* Register used for new table record to insert */
9432094393
9432194394
memset(&sContext, 0, sizeof(sContext));
9432294395
db = pParse->db;
9432394396
if( pParse->nErr || db->mallocFailed ){
9432494397
goto update_cleanup;
@@ -94472,11 +94545,10 @@
9447294545
if( chngRowid || pTrigger || hasFK ){
9447394546
regNewRowid = ++pParse->nMem;
9447494547
}
9447594548
regNew = pParse->nMem + 1;
9447694549
pParse->nMem += pTab->nCol;
94477
- regRec = ++pParse->nMem;
9447894550
9447994551
/* Start the view context. */
9448094552
if( isView ){
9448194553
sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
9448294554
}
@@ -94582,11 +94654,11 @@
9458294654
u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
9458394655
oldmask |= sqlite3TriggerColmask(pParse,
9458494656
pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
9458594657
);
9458694658
for(i=0; i<pTab->nCol; i++){
94587
- if( aXRef[i]<0 || oldmask==0xffffffff || (oldmask & (1<<i)) ){
94659
+ if( aXRef[i]<0 || oldmask==0xffffffff || (i<32 && (oldmask & (1<<i))) ){
9458894660
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);
9458994661
}else{
9459094662
sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);
9459194663
}
9459294664
}
@@ -100187,11 +100259,10 @@
100187100259
**
100188100260
** B: <after the loop>
100189100261
**
100190100262
*/
100191100263
WhereClause *pOrWc; /* The OR-clause broken out into subterms */
100192
- WhereTerm *pFinal; /* Final subterm within the OR-clause. */
100193100264
SrcList *pOrTab; /* Shortened table list or OR-clause generation */
100194100265
100195100266
int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */
100196100267
int regRowset = 0; /* Register for RowSet object */
100197100268
int regRowid = 0; /* Register holding rowid */
@@ -100203,11 +100274,10 @@
100203100274
pTerm = pLevel->plan.u.pTerm;
100204100275
assert( pTerm!=0 );
100205100276
assert( pTerm->eOperator==WO_OR );
100206100277
assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
100207100278
pOrWc = &pTerm->u.pOrInfo->wc;
100208
- pFinal = &pOrWc->a[pOrWc->nTerm-1];
100209100279
pLevel->op = OP_Return;
100210100280
pLevel->p1 = regReturn;
100211100281
100212100282
/* Set up a new SrcList ni pOrTab containing the table being scanned
100213100283
** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
@@ -100312,11 +100382,10 @@
100312100382
**
100313100383
** IMPLEMENTATION-OF: R-49525-50935 Terms that cannot be satisfied through
100314100384
** the use of indices become tests that are evaluated against each row of
100315100385
** the relevant input tables.
100316100386
*/
100317
- k = 0;
100318100387
for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
100319100388
Expr *pE;
100320100389
testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */
100321100390
testcase( pTerm->wtFlags & TERM_CODED );
100322100391
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
@@ -100330,11 +100399,10 @@
100330100399
assert( pE!=0 );
100331100400
if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
100332100401
continue;
100333100402
}
100334100403
sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
100335
- k = 1;
100336100404
pTerm->wtFlags |= TERM_CODED;
100337100405
}
100338100406
100339100407
/* For a LEFT OUTER JOIN, generate code that will record the fact that
100340100408
** at least one row of the right table has matched the left table.
@@ -100638,12 +100706,10 @@
100638100706
**
100639100707
** This loop also figures out the nesting order of tables in the FROM
100640100708
** clause.
100641100709
*/
100642100710
notReady = ~(Bitmask)0;
100643
- pTabItem = pTabList->a;
100644
- pLevel = pWInfo->a;
100645100711
andFlags = ~0;
100646100712
WHERETRACE(("*** Optimizer Start ***\n"));
100647100713
for(i=iFrom=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
100648100714
WhereCost bestPlan; /* Most efficient plan seen so far */
100649100715
Index *pIdx; /* Index for FROM table at pTabItem */
@@ -100750,12 +100816,12 @@
100750100816
/* Conditions under which this table becomes the best so far:
100751100817
**
100752100818
** (1) The table must not depend on other tables that have not
100753100819
** yet run.
100754100820
**
100755
- ** (2) A full-table-scan plan cannot supercede another plan unless
100756
- ** it is an "optimal" plan as defined above.
100821
+ ** (2) A full-table-scan plan cannot supercede indexed plan unless
100822
+ ** the full-table-scan is an "optimal" plan as defined above.
100757100823
**
100758100824
** (3) All tables have an INDEXED BY clause or this table lacks an
100759100825
** INDEXED BY clause or this table uses the specific
100760100826
** index specified by its INDEXED BY clause. This rule ensures
100761100827
** that a best-so-far is always selected even if an impossible
@@ -100767,10 +100833,11 @@
100767100833
** (4) The plan cost must be lower than prior plans or else the
100768100834
** cost must be the same and the number of rows must be lower.
100769100835
*/
100770100836
if( (sCost.used&notReady)==0 /* (1) */
100771100837
&& (bestJ<0 || (notIndexed&m)!=0 /* (2) */
100838
+ || (bestPlan.plan.wsFlags & WHERE_NOT_FULLSCAN)==0
100772100839
|| (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)
100773100840
&& (nUnconstrained==0 || pTabItem->pIndex==0 /* (3) */
100774100841
|| NEVER((sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0))
100775100842
&& (bestJ<0 || sCost.rCost<bestPlan.rCost /* (4) */
100776100843
|| (sCost.rCost<=bestPlan.rCost
@@ -123657,11 +123724,11 @@
123657123724
int nCell = 0;
123658123725
RtreeCell cell;
123659123726
int jj;
123660123727
123661123728
nodeGetCell(&tree, &node, ii, &cell);
123662
- sqlite3_snprintf(512-nCell,&zCell[nCell],"%d", cell.iRowid);
123729
+ sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
123663123730
nCell = strlen(zCell);
123664123731
for(jj=0; jj<tree.nDim*2; jj++){
123665123732
sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f);
123666123733
nCell = strlen(zCell);
123667123734
}
123668123735
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.6"
654 #define SQLITE_VERSION_NUMBER 3007006
655 #define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -11206,10 +11206,13 @@
11206 SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*);
11207 SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*);
11208 SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
11209 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
11210 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
 
 
 
11211
11212 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
11213 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
11214 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
11215 void(*)(void*));
@@ -18792,11 +18795,15 @@
18792 v = va_arg(ap,long int);
18793 }else{
18794 v = va_arg(ap,int);
18795 }
18796 if( v<0 ){
18797 longvalue = -v;
 
 
 
 
18798 prefix = '-';
18799 }else{
18800 longvalue = v;
18801 if( flag_plussign ) prefix = '+';
18802 else if( flag_blanksign ) prefix = ' ';
@@ -20566,64 +20573,84 @@
20566 return c;
20567 }
20568
20569
20570 /*
20571 ** Convert zNum to a 64-bit signed integer and write
20572 ** the value of the integer into *pNum.
20573 ** If zNum is exactly 9223372036854665808, return 2.
20574 ** This is a special case as the context will determine
20575 ** if it is too big (used as a negative).
20576 ** If zNum is not an integer or is an integer that
20577 ** is too large to be expressed with 64 bits,
20578 ** then return 1. Otherwise return 0.
 
 
 
20579 **
20580 ** length is the number of bytes in the string (bytes, not characters).
20581 ** The string is not necessarily zero-terminated. The encoding is
20582 ** given by enc.
20583 */
20584 SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
20585 int incr = (enc==SQLITE_UTF8?1:2);
20586 i64 v = 0;
20587 int neg = 0; /* assume positive */
20588 int i;
20589 int c = 0;
20590 const char *zStart;
20591 const char *zEnd = zNum + length;
20592 if( enc==SQLITE_UTF16BE ) zNum++;
20593 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
20594 if( zNum>=zEnd ) goto do_atoi_calc;
20595 if( *zNum=='-' ){
20596 neg = 1;
20597 zNum+=incr;
20598 }else if( *zNum=='+' ){
20599 zNum+=incr;
20600 }
20601 do_atoi_calc:
20602 zStart = zNum;
20603 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
20604 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
20605 v = v*10 + c - '0';
20606 }
20607 *pNum = neg ? -v : v;
 
 
 
 
 
 
20608 testcase( i==18 );
20609 testcase( i==19 );
20610 testcase( i==20 );
20611 if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
20612 /* zNum is empty or contains non-numeric text or is longer
20613 ** than 19 digits (thus guaranteeing that it is too large) */
20614 return 1;
20615 }else if( i<19*incr ){
20616 /* Less than 19 digits, so we know that it fits in 64 bits */
 
20617 return 0;
20618 }else{
20619 /* 19-digit numbers must be no larger than 9223372036854775807 if positive
20620 ** or 9223372036854775808 if negative. Note that 9223372036854665808
20621 ** is 2^63. Return 1 if to large */
20622 c=compare2pow63(zNum, incr);
20623 if( c==0 && neg==0 ) return 2; /* too big, exactly 9223372036854665808 */
20624 return c<neg ? 0 : 1;
 
 
 
 
 
 
 
 
 
 
20625 }
20626 }
20627
20628 /*
20629 ** If zNum represents an integer that will fit in 32-bits, then set
@@ -21185,10 +21212,68 @@
21185 return 0;
21186 }else{
21187 return 1;
21188 }
21189 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21190
21191 /************** End of util.c ************************************************/
21192 /************** Begin file hash.c ********************************************/
21193 /*
21194 ** 2001 September 22
@@ -23930,18 +24015,19 @@
23930 ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
23931 ** The two subsequent arguments should be the name of the OS function that
23932 ** failed (e.g. "unlink", "open") and the the associated file-system path,
23933 ** if any.
23934 */
23935 #define unixLogError(a,b,c) unixLogError_x(a,b,c,__LINE__)
23936 static int unixLogError_x(
23937 int errcode, /* SQLite error code */
23938 const char *zFunc, /* Name of OS function that failed */
23939 const char *zPath, /* File path associated with error */
23940 int iLine /* Source line number where error occurred */
23941 ){
23942 char *zErr; /* Message from strerror() or equivalent */
 
23943
23944 /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
23945 ** the strerror() function to obtain the human-readable error message
23946 ** equivalent to errno. Otherwise, use strerror_r().
23947 */
@@ -23963,58 +24049,63 @@
23963 ** could lead to a segfault though.
23964 */
23965 #if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
23966 zErr =
23967 # endif
23968 strerror_r(errno, aErr, sizeof(aErr)-1);
23969
23970 #elif SQLITE_THREADSAFE
23971 /* This is a threadsafe build, but strerror_r() is not available. */
23972 zErr = "";
23973 #else
23974 /* Non-threadsafe build, use strerror(). */
23975 zErr = strerror(errno);
23976 #endif
23977
23978 assert( errcode!=SQLITE_OK );
 
23979 sqlite3_log(errcode,
23980 "os_unix.c: %s() at line %d - \"%s\" errno=%d path=%s",
23981 zFunc, iLine, zErr, errno, (zPath ? zPath : "n/a")
23982 );
23983
23984 return errcode;
23985 }
23986
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23987
23988 /*
23989 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
23990 ** If all such file descriptors are closed without error, the list is
23991 ** cleared and SQLITE_OK returned.
23992 **
23993 ** Otherwise, if an error occurs, then successfully closed file descriptor
23994 ** entries are removed from the list, and SQLITE_IOERR_CLOSE returned.
23995 ** not deleted and SQLITE_IOERR_CLOSE returned.
23996 */
23997 static int closePendingFds(unixFile *pFile){
23998 int rc = SQLITE_OK;
23999 unixInodeInfo *pInode = pFile->pInode;
24000 UnixUnusedFd *pError = 0;
24001 UnixUnusedFd *p;
24002 UnixUnusedFd *pNext;
24003 for(p=pInode->pUnused; p; p=pNext){
24004 pNext = p->pNext;
24005 if( close(p->fd) ){
24006 pFile->lastErrno = errno;
24007 rc = unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath);
24008 p->pNext = pError;
24009 pError = p;
24010 }else{
24011 sqlite3_free(p);
24012 }
24013 }
24014 pInode->pUnused = pError;
24015 return rc;
24016 }
24017
24018 /*
24019 ** Release a unixInodeInfo structure previously allocated by findInodeInfo().
24020 **
@@ -24621,14 +24712,11 @@
24621 ** was deferred because of outstanding locks.
24622 */
24623 pInode->nLock--;
24624 assert( pInode->nLock>=0 );
24625 if( pInode->nLock==0 ){
24626 int rc2 = closePendingFds(pFile);
24627 if( rc==SQLITE_OK ){
24628 rc = rc2;
24629 }
24630 }
24631 }
24632
24633 end_unlock:
24634 unixLeaveMutex();
@@ -24659,24 +24747,16 @@
24659 */
24660 static int closeUnixFile(sqlite3_file *id){
24661 unixFile *pFile = (unixFile*)id;
24662 if( pFile ){
24663 if( pFile->dirfd>=0 ){
24664 int err = close(pFile->dirfd);
24665 if( err ){
24666 pFile->lastErrno = errno;
24667 return unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath);
24668 }else{
24669 pFile->dirfd=-1;
24670 }
24671 }
24672 if( pFile->h>=0 ){
24673 int err = close(pFile->h);
24674 if( err ){
24675 pFile->lastErrno = errno;
24676 return unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath);
24677 }
24678 }
24679 #if OS_VXWORKS
24680 if( pFile->pId ){
24681 if( pFile->isDelete ){
24682 unlink(pFile->pId->zCanonicalName);
@@ -24882,14 +24962,11 @@
24882 pFile->lastErrno = tErrno;
24883 }
24884 }
24885 return rc;
24886 }
24887 if( close(fd) ){
24888 pFile->lastErrno = errno;
24889 rc = SQLITE_IOERR_CLOSE;
24890 }
24891
24892 /* got it, set the type and return ok */
24893 pFile->eFileLock = eFileLock;
24894 return rc;
24895 }
@@ -25777,11 +25854,11 @@
25777 }
25778 if( rc==SQLITE_OK ){
25779 pInode->nLock--;
25780 assert( pInode->nLock>=0 );
25781 if( pInode->nLock==0 ){
25782 rc = closePendingFds(pFile);
25783 }
25784 }
25785 }
25786
25787 unixLeaveMutex();
@@ -26210,11 +26287,10 @@
26210 if( rc ){
26211 pFile->lastErrno = errno;
26212 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
26213 }
26214 if( pFile->dirfd>=0 ){
26215 int err;
26216 OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd,
26217 HAVE_FULLFSYNC, isFullsync));
26218 #ifndef SQLITE_DISABLE_DIRSYNC
26219 /* The directory sync is only attempted if full_fsync is
26220 ** turned off or unavailable. If a full_fsync occurred above,
@@ -26229,17 +26305,13 @@
26229 */
26230 /* pFile->lastErrno = errno; */
26231 /* return SQLITE_IOERR; */
26232 }
26233 #endif
26234 err = close(pFile->dirfd); /* Only need to sync once, so close the */
26235 if( err==0 ){ /* directory when we are done */
26236 pFile->dirfd = -1;
26237 }else{
26238 pFile->lastErrno = errno;
26239 rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath);
26240 }
26241 }
26242 return rc;
26243 }
26244
26245 /*
@@ -26602,11 +26674,14 @@
26602 if( p->mutex ) sqlite3_mutex_free(p->mutex);
26603 for(i=0; i<p->nRegion; i++){
26604 munmap(p->apRegion[i], p->szRegion);
26605 }
26606 sqlite3_free(p->apRegion);
26607 if( p->h>=0 ) close(p->h);
 
 
 
26608 p->pInode->pShmNode = 0;
26609 sqlite3_free(p);
26610 }
26611 }
26612
@@ -27413,11 +27488,11 @@
27413 **
27414 ** If scenario (a) caused the error then things are not so safe. The
27415 ** implicit assumption here is that if fstat() fails, things are in
27416 ** such bad shape that dropping a lock or two doesn't matter much.
27417 */
27418 close(h);
27419 h = -1;
27420 }
27421 unixLeaveMutex();
27422 }
27423
@@ -27439,11 +27514,11 @@
27439 srandomdev();
27440 unixEnterMutex();
27441 rc = findInodeInfo(pNew, &pNew->pInode);
27442 if( rc!=SQLITE_OK ){
27443 sqlite3_free(pNew->lockingContext);
27444 close(h);
27445 h = -1;
27446 }
27447 unixLeaveMutex();
27448 }
27449 }
@@ -27490,20 +27565,20 @@
27490 #endif
27491
27492 pNew->lastErrno = 0;
27493 #if OS_VXWORKS
27494 if( rc!=SQLITE_OK ){
27495 if( h>=0 ) close(h);
27496 h = -1;
27497 unlink(zFilename);
27498 isDelete = 0;
27499 }
27500 pNew->isDelete = isDelete;
27501 #endif
27502 if( rc!=SQLITE_OK ){
27503 if( dirfd>=0 ) close(dirfd); /* silent leak if fail, already in error */
27504 if( h>=0 ) close(h);
27505 }else{
27506 pNew->pMethod = pLockingStyle;
27507 OpenCounter(+1);
27508 }
27509 return rc;
@@ -27911,11 +27986,11 @@
27911 /* It is safe to close fd at this point, because it is guaranteed not
27912 ** to be open on a database file. If it were open on a database file,
27913 ** it would not be safe to close as this would release any locks held
27914 ** on the file by this process. */
27915 assert( eType!=SQLITE_OPEN_MAIN_DB );
27916 close(fd); /* silently leak if fail, already in error */
27917 goto open_finished;
27918 }
27919 }
27920
27921 #ifdef FD_CLOEXEC
@@ -27927,12 +28002,12 @@
27927
27928 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
27929 struct statfs fsInfo;
27930 if( fstatfs(fd, &fsInfo) == -1 ){
27931 ((unixFile*)pFile)->lastErrno = errno;
27932 if( dirfd>=0 ) close(dirfd); /* silently leak if fail, in error */
27933 close(fd); /* silently leak if fail, in error */
27934 return SQLITE_IOERR_ACCESS;
27935 }
27936 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
27937 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
27938 }
@@ -27960,13 +28035,13 @@
27960 ** we're assuming that statfs() doesn't fail very often. At least
27961 ** not while other file descriptors opened by the same process on
27962 ** the same file are working. */
27963 p->lastErrno = errno;
27964 if( dirfd>=0 ){
27965 close(dirfd); /* silently leak if fail, in error */
27966 }
27967 close(fd); /* silently leak if fail, in error */
27968 rc = SQLITE_IOERR_ACCESS;
27969 goto open_finished;
27970 }
27971 useProxy = !(fsInfo.f_flags&MNT_LOCAL);
27972 }
@@ -28023,13 +28098,11 @@
28023 if( fsync(fd) )
28024 #endif
28025 {
28026 rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath);
28027 }
28028 if( close(fd)&&!rc ){
28029 rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", zPath);
28030 }
28031 }
28032 }
28033 #endif
28034 return rc;
28035 }
@@ -28213,11 +28286,11 @@
28213 memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
28214 assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
28215 nBuf = sizeof(t) + sizeof(pid);
28216 }else{
28217 do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
28218 close(fd);
28219 }
28220 }
28221 #endif
28222 return nBuf;
28223 }
@@ -28656,11 +28729,11 @@
28656 if( rc==SQLITE_OK ){
28657 *ppFile = pNew;
28658 return SQLITE_OK;
28659 }
28660 end_create_proxy:
28661 close(fd); /* silently leak fd if error, we're already in error */
28662 sqlite3_free(pNew);
28663 sqlite3_free(pUnused);
28664 return rc;
28665 }
28666
@@ -28756,19 +28829,19 @@
28756 sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno);
28757 goto end_breaklock;
28758 }
28759 rc = 0;
28760 fprintf(stderr, "broke stale lock on %s\n", cPath);
28761 close(conchFile->h);
28762 conchFile->h = fd;
28763 conchFile->openFlags = O_RDWR | O_CREAT;
28764
28765 end_breaklock:
28766 if( rc ){
28767 if( fd>=0 ){
28768 unlink(tPath);
28769 close(fd);
28770 }
28771 fprintf(stderr, "failed to break stale lock on %s, %s\n", cPath, errmsg);
28772 }
28773 return rc;
28774 }
@@ -28981,11 +29054,10 @@
28981 /* If we created a new conch file (not just updated the contents of a
28982 ** valid conch file), try to match the permissions of the database
28983 */
28984 if( rc==SQLITE_OK && createConch ){
28985 struct stat buf;
28986 int rc;
28987 int err = fstat(pFile->h, &buf);
28988 if( err==0 ){
28989 mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
28990 S_IROTH|S_IWOTH);
28991 /* try to match the database file R/W permissions, ignore failure */
@@ -29014,18 +29086,11 @@
29014
29015 end_takeconch:
29016 OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h));
29017 if( rc==SQLITE_OK && pFile->openFlags ){
29018 if( pFile->h>=0 ){
29019 #ifdef STRICT_CLOSE_ERROR
29020 if( close(pFile->h) ){
29021 pFile->lastErrno = errno;
29022 return SQLITE_IOERR_CLOSE;
29023 }
29024 #else
29025 close(pFile->h); /* silently leak fd if fail */
29026 #endif
29027 }
29028 pFile->h = -1;
29029 int fd = open(pCtx->dbPath, pFile->openFlags,
29030 SQLITE_DEFAULT_FILE_PERMISSIONS);
29031 OSTRACE(("TRANSPROXY: OPEN %d\n", fd));
@@ -43555,11 +43620,10 @@
43555 if( rc!=SQLITE_OK ){
43556 return rc;
43557 }
43558 assert( pIter );
43559
43560 mxPage = pWal->hdr.nPage;
43561 if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall;
43562
43563 /* Compute in mxSafeFrame the index of the last frame of the WAL that is
43564 ** safe to write into the database. Frames beyond mxSafeFrame might
43565 ** overwrite database pages that are in use by active readers and thus
@@ -51996,13 +52060,11 @@
51996 minI = j;
51997 minV = apNew[j]->pgno;
51998 }
51999 }
52000 if( minI>i ){
52001 int t;
52002 MemPage *pT;
52003 t = apNew[i]->pgno;
52004 pT = apNew[i];
52005 apNew[i] = apNew[minI];
52006 apNew[minI] = pT;
52007 }
52008 }
@@ -55005,11 +55067,11 @@
55005 if( flags & MEM_Int ){
55006 return pMem->u.i;
55007 }else if( flags & MEM_Real ){
55008 return doubleToInt64(pMem->r);
55009 }else if( flags & (MEM_Str|MEM_Blob) ){
55010 i64 value;
55011 assert( pMem->z || pMem->n==0 );
55012 testcase( pMem->z==0 );
55013 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
55014 return value;
55015 }else{
@@ -57310,11 +57372,11 @@
57310 ** pointers to VdbeFrame objects, which may in turn contain pointers to
57311 ** open cursors.
57312 */
57313 static void closeAllCursors(Vdbe *p){
57314 if( p->pFrame ){
57315 VdbeFrame *pFrame = p->pFrame;
57316 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
57317 sqlite3VdbeFrameRestore(pFrame);
57318 }
57319 p->pFrame = 0;
57320 p->nFrame = 0;
@@ -58290,11 +58352,17 @@
58290 i64 i = pMem->u.i;
58291 u64 u;
58292 if( file_format>=4 && (i&1)==i ){
58293 return 8+(u32)i;
58294 }
58295 u = i<0 ? -i : i;
 
 
 
 
 
 
58296 if( u<=127 ) return 1;
58297 if( u<=32767 ) return 2;
58298 if( u<=8388607 ) return 3;
58299 if( u<=2147483647 ) return 4;
58300 if( u<=MAX_6BYTE ) return 5;
@@ -59640,17 +59708,15 @@
59640 ** If iCol is not valid, return a pointer to a Mem which has a value
59641 ** of NULL.
59642 */
59643 static Mem *columnMem(sqlite3_stmt *pStmt, int i){
59644 Vdbe *pVm;
59645 int vals;
59646 Mem *pOut;
59647
59648 pVm = (Vdbe *)pStmt;
59649 if( pVm && pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){
59650 sqlite3_mutex_enter(pVm->db->mutex);
59651 vals = sqlite3_data_count(pStmt);
59652 pOut = &pVm->pResultSet[i];
59653 }else{
59654 /* If the value passed as the second argument is out of range, return
59655 ** a pointer to the following static Mem object which contains the
59656 ** value SQL NULL. Even though the Mem structure contains an element
@@ -61138,12 +61204,14 @@
61138 sqlite3_context ctx;
61139 sqlite3_value **apVal;
61140 int n;
61141 } ag;
61142 struct OP_ShiftRight_stack_vars {
61143 i64 a;
61144 i64 b;
 
 
61145 } ah;
61146 struct OP_Ge_stack_vars {
61147 int res; /* Result of the comparison of pIn1 against pIn3 */
61148 char affinity; /* Affinity to use for comparison */
61149 u16 flags1; /* Copy of initial value of pIn1->flags */
@@ -62189,23 +62257,16 @@
62189 if( (u.af.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
62190 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
62191 u.af.iA = pIn1->u.i;
62192 u.af.iB = pIn2->u.i;
62193 switch( pOp->opcode ){
62194 case OP_Add: u.af.iB += u.af.iA; break;
62195 case OP_Subtract: u.af.iB -= u.af.iA; break;
62196 case OP_Multiply: u.af.iB *= u.af.iA; break;
62197 case OP_Divide: {
62198 if( u.af.iA==0 ) goto arithmetic_result_is_null;
62199 /* Dividing the largest possible negative 64-bit integer (1<<63) by
62200 ** -1 returns an integer too large to store in a 64-bit data-type. On
62201 ** some architectures, the value overflows to (1<<63). On others,
62202 ** a SIGFPE is issued. The following statement normalizes this
62203 ** behavior so that all architectures behave as if integer
62204 ** overflow occurred.
62205 */
62206 if( u.af.iA==-1 && u.af.iB==SMALLEST_INT64 ) u.af.iA = 1;
62207 u.af.iB /= u.af.iA;
62208 break;
62209 }
62210 default: {
62211 if( u.af.iA==0 ) goto arithmetic_result_is_null;
@@ -62215,10 +62276,11 @@
62215 }
62216 }
62217 pOut->u.i = u.af.iB;
62218 MemSetTypeFlag(pOut, MEM_Int);
62219 }else{
 
62220 u.af.rA = sqlite3VdbeRealValue(pIn1);
62221 u.af.rB = sqlite3VdbeRealValue(pIn2);
62222 switch( pOp->opcode ){
62223 case OP_Add: u.af.rB += u.af.rA; break;
62224 case OP_Subtract: u.af.rB -= u.af.rA; break;
@@ -62412,31 +62474,55 @@
62412 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
62413 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
62414 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
62415 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
62416 #if 0 /* local variables moved into u.ah */
62417 i64 a;
62418 i64 b;
 
 
62419 #endif /* local variables moved into u.ah */
62420
62421 pIn1 = &aMem[pOp->p1];
62422 pIn2 = &aMem[pOp->p2];
62423 pOut = &aMem[pOp->p3];
62424 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
62425 sqlite3VdbeMemSetNull(pOut);
62426 break;
62427 }
62428 u.ah.a = sqlite3VdbeIntValue(pIn2);
62429 u.ah.b = sqlite3VdbeIntValue(pIn1);
62430 switch( pOp->opcode ){
62431 case OP_BitAnd: u.ah.a &= u.ah.b; break;
62432 case OP_BitOr: u.ah.a |= u.ah.b; break;
62433 case OP_ShiftLeft: u.ah.a <<= u.ah.b; break;
62434 default: assert( pOp->opcode==OP_ShiftRight );
62435 u.ah.a >>= u.ah.b; break;
62436 }
62437 pOut->u.i = u.ah.a;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62438 MemSetTypeFlag(pOut, MEM_Int);
62439 break;
62440 }
62441
62442 /* Opcode: AddImm P1 P2 * * *
@@ -63372,11 +63458,10 @@
63372 ** hdr-size field is also a varint which is the offset from the beginning
63373 ** of the record to data0.
63374 */
63375 u.ao.nData = 0; /* Number of bytes of data space */
63376 u.ao.nHdr = 0; /* Number of bytes of header space */
63377 u.ao.nByte = 0; /* Data space required for this record */
63378 u.ao.nZero = 0; /* Number of zero bytes at the end of the record */
63379 u.ao.nField = pOp->p1;
63380 u.ao.zAffinity = pOp->p4.z;
63381 assert( u.ao.nField>0 && pOp->p2>0 && pOp->p2+u.ao.nField<=p->nMem+1 );
63382 u.ao.pData0 = &aMem[u.ao.nField];
@@ -64678,11 +64763,10 @@
64678 ** it already exists in the table. If it does not exist, we have
64679 ** succeeded. If the random rowid does exist, we select a new one
64680 ** and try again, up to 100 times.
64681 */
64682 assert( u.be.pC->isTable );
64683 u.be.cnt = 0;
64684
64685 #ifdef SQLITE_32BIT_ROWID
64686 # define MAX_ROWID 0x7fffffff
64687 #else
64688 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -71317,11 +71401,11 @@
71317 const char *z = pExpr->u.zToken;
71318 assert( z!=0 );
71319 c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
71320 if( c==0 || (c==2 && negFlag) ){
71321 char *zV;
71322 if( negFlag ){ value = -value; }
71323 zV = dup8bytes(v, (char*)&value);
71324 sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
71325 }else{
71326 #ifdef SQLITE_OMIT_FLOATING_POINT
71327 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
@@ -81443,17 +81527,12 @@
81443 if( p && type!=SQLITE_NULL ){
81444 p->cnt++;
81445 if( type==SQLITE_INTEGER ){
81446 i64 v = sqlite3_value_int64(argv[0]);
81447 p->rSum += v;
81448 if( (p->approx|p->overflow)==0 ){
81449 i64 iNewSum = p->iSum + v;
81450 int s1 = (int)(p->iSum >> (sizeof(i64)*8-1));
81451 int s2 = (int)(v >> (sizeof(i64)*8-1));
81452 int s3 = (int)(iNewSum >> (sizeof(i64)*8-1));
81453 p->overflow = ((s1&s2&~s3) | (~s1&~s2&s3))?1:0;
81454 p->iSum = iNewSum;
81455 }
81456 }else{
81457 p->rSum += sqlite3_value_double(argv[0]);
81458 p->approx = 1;
81459 }
@@ -82489,11 +82568,10 @@
82489 Table *pTab, /* Row is being deleted from this table */
82490 int regOld, /* Previous row data is stored here */
82491 int regNew /* New row data is stored here */
82492 ){
82493 sqlite3 *db = pParse->db; /* Database handle */
82494 Vdbe *v; /* VM to write code to */
82495 FKey *pFKey; /* Used to iterate through FKs */
82496 int iDb; /* Index of database containing pTab */
82497 const char *zDb; /* Name of database containing pTab */
82498 int isIgnoreErrors = pParse->disableTriggers;
82499
@@ -82501,11 +82579,10 @@
82501 assert( (regOld==0)!=(regNew==0) );
82502
82503 /* If foreign-keys are disabled, this function is a no-op. */
82504 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
82505
82506 v = sqlite3GetVdbe(pParse);
82507 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
82508 zDb = db->aDb[iDb].zName;
82509
82510 /* Loop through all the foreign key constraints for which pTab is the
82511 ** child table (the table that the foreign key definition is part of). */
@@ -83459,11 +83536,10 @@
83459 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
83460 int regRowCount = 0; /* Memory cell used for the row counter */
83461 int regIns; /* Block of regs holding rowid+data being inserted */
83462 int regRowid; /* registers holding insert rowid */
83463 int regData; /* register holding first column to insert */
83464 int regRecord; /* Holds the assemblied row record */
83465 int regEof = 0; /* Register recording end of SELECT data */
83466 int *aRegIdx = 0; /* One register allocated to each index */
83467
83468 #ifndef SQLITE_OMIT_TRIGGER
83469 int isView; /* True if attempting to insert into a view */
@@ -83788,11 +83864,10 @@
83788 }
83789
83790 /* Allocate registers for holding the rowid of the new row,
83791 ** the content of the new row, and the assemblied row record.
83792 */
83793 regRecord = ++pParse->nMem;
83794 regRowid = regIns = pParse->nMem+1;
83795 pParse->nMem += pTab->nCol + 1;
83796 if( IsVirtual(pTab) ){
83797 regRowid++;
83798 pParse->nMem++;
@@ -84182,11 +84257,11 @@
84182 case OE_Abort:
84183 sqlite3MayAbort(pParse);
84184 case OE_Rollback:
84185 case OE_Fail: {
84186 char *zMsg;
84187 j1 = sqlite3VdbeAddOp3(v, OP_HaltIfNull,
84188 SQLITE_CONSTRAINT, onError, regData+i);
84189 zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL",
84190 pTab->zName, pTab->aCol[i].zName);
84191 sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC);
84192 break;
@@ -87708,11 +87783,11 @@
87708 Db *pDb;
87709 char const *azArg[4];
87710 int meta[5];
87711 InitData initData;
87712 char const *zMasterSchema;
87713 char const *zMasterName = SCHEMA_TABLE(iDb);
87714 int openedTransaction = 0;
87715
87716 /*
87717 ** The master database table has a structure like this
87718 */
@@ -93351,11 +93426,10 @@
93351 sqlite3 *db = pParse->db; /* The database */
93352 DbFixer sFix; /* Fixer object */
93353 int iDb; /* Database containing the trigger */
93354 Token nameToken; /* Trigger name for error reporting */
93355
93356 pTrig = pParse->pNewTrigger;
93357 pParse->pNewTrigger = 0;
93358 if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
93359 zName = pTrig->zName;
93360 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
93361 pTrig->step_list = pStepList;
@@ -94314,11 +94388,10 @@
94314 int regOldRowid; /* The old rowid */
94315 int regNewRowid; /* The new rowid */
94316 int regNew;
94317 int regOld = 0;
94318 int regRowSet = 0; /* Rowset of rows to be updated */
94319 int regRec; /* Register used for new table record to insert */
94320
94321 memset(&sContext, 0, sizeof(sContext));
94322 db = pParse->db;
94323 if( pParse->nErr || db->mallocFailed ){
94324 goto update_cleanup;
@@ -94472,11 +94545,10 @@
94472 if( chngRowid || pTrigger || hasFK ){
94473 regNewRowid = ++pParse->nMem;
94474 }
94475 regNew = pParse->nMem + 1;
94476 pParse->nMem += pTab->nCol;
94477 regRec = ++pParse->nMem;
94478
94479 /* Start the view context. */
94480 if( isView ){
94481 sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
94482 }
@@ -94582,11 +94654,11 @@
94582 u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
94583 oldmask |= sqlite3TriggerColmask(pParse,
94584 pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
94585 );
94586 for(i=0; i<pTab->nCol; i++){
94587 if( aXRef[i]<0 || oldmask==0xffffffff || (oldmask & (1<<i)) ){
94588 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);
94589 }else{
94590 sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);
94591 }
94592 }
@@ -100187,11 +100259,10 @@
100187 **
100188 ** B: <after the loop>
100189 **
100190 */
100191 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
100192 WhereTerm *pFinal; /* Final subterm within the OR-clause. */
100193 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
100194
100195 int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */
100196 int regRowset = 0; /* Register for RowSet object */
100197 int regRowid = 0; /* Register holding rowid */
@@ -100203,11 +100274,10 @@
100203 pTerm = pLevel->plan.u.pTerm;
100204 assert( pTerm!=0 );
100205 assert( pTerm->eOperator==WO_OR );
100206 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
100207 pOrWc = &pTerm->u.pOrInfo->wc;
100208 pFinal = &pOrWc->a[pOrWc->nTerm-1];
100209 pLevel->op = OP_Return;
100210 pLevel->p1 = regReturn;
100211
100212 /* Set up a new SrcList ni pOrTab containing the table being scanned
100213 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
@@ -100312,11 +100382,10 @@
100312 **
100313 ** IMPLEMENTATION-OF: R-49525-50935 Terms that cannot be satisfied through
100314 ** the use of indices become tests that are evaluated against each row of
100315 ** the relevant input tables.
100316 */
100317 k = 0;
100318 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
100319 Expr *pE;
100320 testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */
100321 testcase( pTerm->wtFlags & TERM_CODED );
100322 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
@@ -100330,11 +100399,10 @@
100330 assert( pE!=0 );
100331 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
100332 continue;
100333 }
100334 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
100335 k = 1;
100336 pTerm->wtFlags |= TERM_CODED;
100337 }
100338
100339 /* For a LEFT OUTER JOIN, generate code that will record the fact that
100340 ** at least one row of the right table has matched the left table.
@@ -100638,12 +100706,10 @@
100638 **
100639 ** This loop also figures out the nesting order of tables in the FROM
100640 ** clause.
100641 */
100642 notReady = ~(Bitmask)0;
100643 pTabItem = pTabList->a;
100644 pLevel = pWInfo->a;
100645 andFlags = ~0;
100646 WHERETRACE(("*** Optimizer Start ***\n"));
100647 for(i=iFrom=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
100648 WhereCost bestPlan; /* Most efficient plan seen so far */
100649 Index *pIdx; /* Index for FROM table at pTabItem */
@@ -100750,12 +100816,12 @@
100750 /* Conditions under which this table becomes the best so far:
100751 **
100752 ** (1) The table must not depend on other tables that have not
100753 ** yet run.
100754 **
100755 ** (2) A full-table-scan plan cannot supercede another plan unless
100756 ** it is an "optimal" plan as defined above.
100757 **
100758 ** (3) All tables have an INDEXED BY clause or this table lacks an
100759 ** INDEXED BY clause or this table uses the specific
100760 ** index specified by its INDEXED BY clause. This rule ensures
100761 ** that a best-so-far is always selected even if an impossible
@@ -100767,10 +100833,11 @@
100767 ** (4) The plan cost must be lower than prior plans or else the
100768 ** cost must be the same and the number of rows must be lower.
100769 */
100770 if( (sCost.used&notReady)==0 /* (1) */
100771 && (bestJ<0 || (notIndexed&m)!=0 /* (2) */
 
100772 || (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)
100773 && (nUnconstrained==0 || pTabItem->pIndex==0 /* (3) */
100774 || NEVER((sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0))
100775 && (bestJ<0 || sCost.rCost<bestPlan.rCost /* (4) */
100776 || (sCost.rCost<=bestPlan.rCost
@@ -123657,11 +123724,11 @@
123657 int nCell = 0;
123658 RtreeCell cell;
123659 int jj;
123660
123661 nodeGetCell(&tree, &node, ii, &cell);
123662 sqlite3_snprintf(512-nCell,&zCell[nCell],"%d", cell.iRowid);
123663 nCell = strlen(zCell);
123664 for(jj=0; jj<tree.nDim*2; jj++){
123665 sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f);
123666 nCell = strlen(zCell);
123667 }
123668
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -650,11 +650,11 @@
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.6"
654 #define SQLITE_VERSION_NUMBER 3007006
655 #define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -11206,10 +11206,13 @@
11206 SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*);
11207 SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*);
11208 SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
11209 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
11210 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
11211 SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64);
11212 SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64);
11213 SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64);
11214
11215 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
11216 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
11217 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
11218 void(*)(void*));
@@ -18792,11 +18795,15 @@
18795 v = va_arg(ap,long int);
18796 }else{
18797 v = va_arg(ap,int);
18798 }
18799 if( v<0 ){
18800 if( v==SMALLEST_INT64 ){
18801 longvalue = ((u64)1)<<63;
18802 }else{
18803 longvalue = -v;
18804 }
18805 prefix = '-';
18806 }else{
18807 longvalue = v;
18808 if( flag_plussign ) prefix = '+';
18809 else if( flag_blanksign ) prefix = ' ';
@@ -20566,64 +20573,84 @@
20573 return c;
20574 }
20575
20576
20577 /*
20578 ** Convert zNum to a 64-bit signed integer.
20579 **
20580 ** If the zNum value is representable as a 64-bit twos-complement
20581 ** integer, then write that value into *pNum and return 0.
20582 **
20583 ** If zNum is exactly 9223372036854665808, return 2. This special
20584 ** case is broken out because while 9223372036854665808 cannot be a
20585 ** signed 64-bit integer, its negative -9223372036854665808 can be.
20586 **
20587 ** If zNum is too big for a 64-bit integer and is not
20588 ** 9223372036854665808 then return 1.
20589 **
20590 ** length is the number of bytes in the string (bytes, not characters).
20591 ** The string is not necessarily zero-terminated. The encoding is
20592 ** given by enc.
20593 */
20594 SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
20595 int incr = (enc==SQLITE_UTF8?1:2);
20596 u64 u = 0;
20597 int neg = 0; /* assume positive */
20598 int i;
20599 int c = 0;
20600 const char *zStart;
20601 const char *zEnd = zNum + length;
20602 if( enc==SQLITE_UTF16BE ) zNum++;
20603 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
20604 if( zNum<zEnd ){
20605 if( *zNum=='-' ){
20606 neg = 1;
20607 zNum+=incr;
20608 }else if( *zNum=='+' ){
20609 zNum+=incr;
20610 }
20611 }
20612 zStart = zNum;
20613 while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
20614 for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
20615 u = u*10 + c - '0';
20616 }
20617 if( u>LARGEST_INT64 ){
20618 *pNum = SMALLEST_INT64;
20619 }else if( neg ){
20620 *pNum = -(i64)u;
20621 }else{
20622 *pNum = (i64)u;
20623 }
20624 testcase( i==18 );
20625 testcase( i==19 );
20626 testcase( i==20 );
20627 if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
20628 /* zNum is empty or contains non-numeric text or is longer
20629 ** than 19 digits (thus guaranteeing that it is too large) */
20630 return 1;
20631 }else if( i<19*incr ){
20632 /* Less than 19 digits, so we know that it fits in 64 bits */
20633 assert( u<=LARGEST_INT64 );
20634 return 0;
20635 }else{
20636 /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
20637 c = compare2pow63(zNum, incr);
20638 if( c<0 ){
20639 /* zNum is less than 9223372036854775808 so it fits */
20640 assert( u<=LARGEST_INT64 );
20641 return 0;
20642 }else if( c>0 ){
20643 /* zNum is greater than 9223372036854775808 so it overflows */
20644 return 1;
20645 }else{
20646 /* zNum is exactly 9223372036854775808. Fits if negative. The
20647 ** special case 2 overflow if positive */
20648 assert( u-1==LARGEST_INT64 );
20649 assert( (*pNum)==SMALLEST_INT64 );
20650 return neg ? 0 : 2;
20651 }
20652 }
20653 }
20654
20655 /*
20656 ** If zNum represents an integer that will fit in 32-bits, then set
@@ -21185,10 +21212,68 @@
21212 return 0;
21213 }else{
21214 return 1;
21215 }
21216 }
21217
21218 /*
21219 ** Attempt to add, substract, or multiply the 64-bit signed value iB against
21220 ** the other 64-bit signed integer at *pA and store the result in *pA.
21221 ** Return 0 on success. Or if the operation would have resulted in an
21222 ** overflow, leave *pA unchanged and return 1.
21223 */
21224 SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
21225 i64 iA = *pA;
21226 testcase( iA==0 ); testcase( iA==1 );
21227 testcase( iB==-1 ); testcase( iB==0 );
21228 if( iB>=0 ){
21229 testcase( iA>0 && LARGEST_INT64 - iA == iB );
21230 testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
21231 if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
21232 *pA += iB;
21233 }else{
21234 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
21235 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
21236 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
21237 *pA += iB;
21238 }
21239 return 0;
21240 }
21241 SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
21242 testcase( iB==SMALLEST_INT64+1 );
21243 if( iB==SMALLEST_INT64 ){
21244 testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
21245 if( (*pA)>=0 ) return 1;
21246 *pA -= iB;
21247 return 0;
21248 }else{
21249 return sqlite3AddInt64(pA, -iB);
21250 }
21251 }
21252 #define TWOPOWER32 (((i64)1)<<32)
21253 #define TWOPOWER31 (((i64)1)<<31)
21254 SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
21255 i64 iA = *pA;
21256 i64 iA1, iA0, iB1, iB0, r;
21257
21258 iA1 = iA/TWOPOWER32;
21259 iA0 = iA % TWOPOWER32;
21260 iB1 = iB/TWOPOWER32;
21261 iB0 = iB % TWOPOWER32;
21262 if( iA1*iB1 != 0 ) return 1;
21263 assert( iA1*iB0==0 || iA0*iB1==0 );
21264 r = iA1*iB0 + iA0*iB1;
21265 testcase( r==(-TWOPOWER31)-1 );
21266 testcase( r==(-TWOPOWER31) );
21267 testcase( r==TWOPOWER31 );
21268 testcase( r==TWOPOWER31-1 );
21269 if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
21270 r *= TWOPOWER32;
21271 if( sqlite3AddInt64(&r, iA0*iB0) ) return 1;
21272 *pA = r;
21273 return 0;
21274 }
21275
21276 /************** End of util.c ************************************************/
21277 /************** Begin file hash.c ********************************************/
21278 /*
21279 ** 2001 September 22
@@ -23930,18 +24015,19 @@
24015 ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
24016 ** The two subsequent arguments should be the name of the OS function that
24017 ** failed (e.g. "unlink", "open") and the the associated file-system path,
24018 ** if any.
24019 */
24020 #define unixLogError(a,b,c) unixLogErrorAtLine(a,b,c,__LINE__)
24021 static int unixLogErrorAtLine(
24022 int errcode, /* SQLite error code */
24023 const char *zFunc, /* Name of OS function that failed */
24024 const char *zPath, /* File path associated with error */
24025 int iLine /* Source line number where error occurred */
24026 ){
24027 char *zErr; /* Message from strerror() or equivalent */
24028 int iErrno = errno; /* Saved syscall error number */
24029
24030 /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
24031 ** the strerror() function to obtain the human-readable error message
24032 ** equivalent to errno. Otherwise, use strerror_r().
24033 */
@@ -23963,58 +24049,63 @@
24049 ** could lead to a segfault though.
24050 */
24051 #if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
24052 zErr =
24053 # endif
24054 strerror_r(iErrno, aErr, sizeof(aErr)-1);
24055
24056 #elif SQLITE_THREADSAFE
24057 /* This is a threadsafe build, but strerror_r() is not available. */
24058 zErr = "";
24059 #else
24060 /* Non-threadsafe build, use strerror(). */
24061 zErr = strerror(iErrno);
24062 #endif
24063
24064 assert( errcode!=SQLITE_OK );
24065 if( zPath==0 ) zPath = "";
24066 sqlite3_log(errcode,
24067 "os_unix.c:%d: (%d) %s(%s) - %s",
24068 iLine, iErrno, zFunc, zPath, zErr
24069 );
24070
24071 return errcode;
24072 }
24073
24074 /*
24075 ** Close a file descriptor.
24076 **
24077 ** We assume that close() almost always works, since it is only in a
24078 ** very sick application or on a very sick platform that it might fail.
24079 ** If it does fail, simply leak the file descriptor, but do log the
24080 ** error.
24081 **
24082 ** Note that it is not safe to retry close() after EINTR since the
24083 ** file descriptor might have already been reused by another thread.
24084 ** So we don't even try to recover from an EINTR. Just log the error
24085 ** and move on.
24086 */
24087 static void robust_close(unixFile *pFile, int h, int lineno){
24088 if( close(h) ){
24089 unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
24090 pFile ? pFile->zPath : 0, lineno);
24091 }
24092 }
24093
24094 /*
24095 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
 
 
 
 
 
 
24096 */
24097 static void closePendingFds(unixFile *pFile){
 
24098 unixInodeInfo *pInode = pFile->pInode;
 
24099 UnixUnusedFd *p;
24100 UnixUnusedFd *pNext;
24101 for(p=pInode->pUnused; p; p=pNext){
24102 pNext = p->pNext;
24103 robust_close(pFile, p->fd, __LINE__);
24104 sqlite3_free(p);
24105 }
24106 pInode->pUnused = 0;
 
 
 
 
 
 
 
24107 }
24108
24109 /*
24110 ** Release a unixInodeInfo structure previously allocated by findInodeInfo().
24111 **
@@ -24621,14 +24712,11 @@
24712 ** was deferred because of outstanding locks.
24713 */
24714 pInode->nLock--;
24715 assert( pInode->nLock>=0 );
24716 if( pInode->nLock==0 ){
24717 closePendingFds(pFile);
 
 
 
24718 }
24719 }
24720
24721 end_unlock:
24722 unixLeaveMutex();
@@ -24659,24 +24747,16 @@
24747 */
24748 static int closeUnixFile(sqlite3_file *id){
24749 unixFile *pFile = (unixFile*)id;
24750 if( pFile ){
24751 if( pFile->dirfd>=0 ){
24752 robust_close(pFile, pFile->dirfd, __LINE__);
24753 pFile->dirfd=-1;
 
 
 
 
 
24754 }
24755 if( pFile->h>=0 ){
24756 robust_close(pFile, pFile->h, __LINE__);
24757 pFile->h = -1;
 
 
 
24758 }
24759 #if OS_VXWORKS
24760 if( pFile->pId ){
24761 if( pFile->isDelete ){
24762 unlink(pFile->pId->zCanonicalName);
@@ -24882,14 +24962,11 @@
24962 pFile->lastErrno = tErrno;
24963 }
24964 }
24965 return rc;
24966 }
24967 robust_close(pFile, fd, __LINE__);
 
 
 
24968
24969 /* got it, set the type and return ok */
24970 pFile->eFileLock = eFileLock;
24971 return rc;
24972 }
@@ -25777,11 +25854,11 @@
25854 }
25855 if( rc==SQLITE_OK ){
25856 pInode->nLock--;
25857 assert( pInode->nLock>=0 );
25858 if( pInode->nLock==0 ){
25859 closePendingFds(pFile);
25860 }
25861 }
25862 }
25863
25864 unixLeaveMutex();
@@ -26210,11 +26287,10 @@
26287 if( rc ){
26288 pFile->lastErrno = errno;
26289 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
26290 }
26291 if( pFile->dirfd>=0 ){
 
26292 OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd,
26293 HAVE_FULLFSYNC, isFullsync));
26294 #ifndef SQLITE_DISABLE_DIRSYNC
26295 /* The directory sync is only attempted if full_fsync is
26296 ** turned off or unavailable. If a full_fsync occurred above,
@@ -26229,17 +26305,13 @@
26305 */
26306 /* pFile->lastErrno = errno; */
26307 /* return SQLITE_IOERR; */
26308 }
26309 #endif
26310 /* Only need to sync once, so close the directory when we are done */
26311 robust_close(pFile, pFile->dirfd, __LINE__);
26312 pFile->dirfd = -1;
 
 
 
 
26313 }
26314 return rc;
26315 }
26316
26317 /*
@@ -26602,11 +26674,14 @@
26674 if( p->mutex ) sqlite3_mutex_free(p->mutex);
26675 for(i=0; i<p->nRegion; i++){
26676 munmap(p->apRegion[i], p->szRegion);
26677 }
26678 sqlite3_free(p->apRegion);
26679 if( p->h>=0 ){
26680 robust_close(pFd, p->h, __LINE__);
26681 p->h = -1;
26682 }
26683 p->pInode->pShmNode = 0;
26684 sqlite3_free(p);
26685 }
26686 }
26687
@@ -27413,11 +27488,11 @@
27488 **
27489 ** If scenario (a) caused the error then things are not so safe. The
27490 ** implicit assumption here is that if fstat() fails, things are in
27491 ** such bad shape that dropping a lock or two doesn't matter much.
27492 */
27493 robust_close(pNew, h, __LINE__);
27494 h = -1;
27495 }
27496 unixLeaveMutex();
27497 }
27498
@@ -27439,11 +27514,11 @@
27514 srandomdev();
27515 unixEnterMutex();
27516 rc = findInodeInfo(pNew, &pNew->pInode);
27517 if( rc!=SQLITE_OK ){
27518 sqlite3_free(pNew->lockingContext);
27519 robust_close(pNew, h, __LINE__);
27520 h = -1;
27521 }
27522 unixLeaveMutex();
27523 }
27524 }
@@ -27490,20 +27565,20 @@
27565 #endif
27566
27567 pNew->lastErrno = 0;
27568 #if OS_VXWORKS
27569 if( rc!=SQLITE_OK ){
27570 if( h>=0 ) robust_close(pNew, h, __LINE__);
27571 h = -1;
27572 unlink(zFilename);
27573 isDelete = 0;
27574 }
27575 pNew->isDelete = isDelete;
27576 #endif
27577 if( rc!=SQLITE_OK ){
27578 if( dirfd>=0 ) robust_close(pNew, dirfd, __LINE__);
27579 if( h>=0 ) robust_close(pNew, h, __LINE__);
27580 }else{
27581 pNew->pMethod = pLockingStyle;
27582 OpenCounter(+1);
27583 }
27584 return rc;
@@ -27911,11 +27986,11 @@
27986 /* It is safe to close fd at this point, because it is guaranteed not
27987 ** to be open on a database file. If it were open on a database file,
27988 ** it would not be safe to close as this would release any locks held
27989 ** on the file by this process. */
27990 assert( eType!=SQLITE_OPEN_MAIN_DB );
27991 robust_close(p, fd, __LINE__);
27992 goto open_finished;
27993 }
27994 }
27995
27996 #ifdef FD_CLOEXEC
@@ -27927,12 +28002,12 @@
28002
28003 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
28004 struct statfs fsInfo;
28005 if( fstatfs(fd, &fsInfo) == -1 ){
28006 ((unixFile*)pFile)->lastErrno = errno;
28007 if( dirfd>=0 ) robust_close(p, dirfd, __LINE__);
28008 robust_close(p, fd, __LINE__);
28009 return SQLITE_IOERR_ACCESS;
28010 }
28011 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
28012 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
28013 }
@@ -27960,13 +28035,13 @@
28035 ** we're assuming that statfs() doesn't fail very often. At least
28036 ** not while other file descriptors opened by the same process on
28037 ** the same file are working. */
28038 p->lastErrno = errno;
28039 if( dirfd>=0 ){
28040 robust_close(p, dirfd, __LINE__);
28041 }
28042 robust_close(p, fd, __LINE__);
28043 rc = SQLITE_IOERR_ACCESS;
28044 goto open_finished;
28045 }
28046 useProxy = !(fsInfo.f_flags&MNT_LOCAL);
28047 }
@@ -28023,13 +28098,11 @@
28098 if( fsync(fd) )
28099 #endif
28100 {
28101 rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath);
28102 }
28103 robust_close(0, fd, __LINE__);
 
 
28104 }
28105 }
28106 #endif
28107 return rc;
28108 }
@@ -28213,11 +28286,11 @@
28286 memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
28287 assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
28288 nBuf = sizeof(t) + sizeof(pid);
28289 }else{
28290 do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
28291 robust_close(0, fd, __LINE__);
28292 }
28293 }
28294 #endif
28295 return nBuf;
28296 }
@@ -28656,11 +28729,11 @@
28729 if( rc==SQLITE_OK ){
28730 *ppFile = pNew;
28731 return SQLITE_OK;
28732 }
28733 end_create_proxy:
28734 robust_close(pNew, fd, __LINE__);
28735 sqlite3_free(pNew);
28736 sqlite3_free(pUnused);
28737 return rc;
28738 }
28739
@@ -28756,19 +28829,19 @@
28829 sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno);
28830 goto end_breaklock;
28831 }
28832 rc = 0;
28833 fprintf(stderr, "broke stale lock on %s\n", cPath);
28834 robust_close(pFile, conchFile->h, __LINE__);
28835 conchFile->h = fd;
28836 conchFile->openFlags = O_RDWR | O_CREAT;
28837
28838 end_breaklock:
28839 if( rc ){
28840 if( fd>=0 ){
28841 unlink(tPath);
28842 robust_close(pFile, fd, __LINE__);
28843 }
28844 fprintf(stderr, "failed to break stale lock on %s, %s\n", cPath, errmsg);
28845 }
28846 return rc;
28847 }
@@ -28981,11 +29054,10 @@
29054 /* If we created a new conch file (not just updated the contents of a
29055 ** valid conch file), try to match the permissions of the database
29056 */
29057 if( rc==SQLITE_OK && createConch ){
29058 struct stat buf;
 
29059 int err = fstat(pFile->h, &buf);
29060 if( err==0 ){
29061 mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
29062 S_IROTH|S_IWOTH);
29063 /* try to match the database file R/W permissions, ignore failure */
@@ -29014,18 +29086,11 @@
29086
29087 end_takeconch:
29088 OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h));
29089 if( rc==SQLITE_OK && pFile->openFlags ){
29090 if( pFile->h>=0 ){
29091 robust_close(pFile, pFile->h, __LINE__);
 
 
 
 
 
 
 
29092 }
29093 pFile->h = -1;
29094 int fd = open(pCtx->dbPath, pFile->openFlags,
29095 SQLITE_DEFAULT_FILE_PERMISSIONS);
29096 OSTRACE(("TRANSPROXY: OPEN %d\n", fd));
@@ -43555,11 +43620,10 @@
43620 if( rc!=SQLITE_OK ){
43621 return rc;
43622 }
43623 assert( pIter );
43624
 
43625 if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall;
43626
43627 /* Compute in mxSafeFrame the index of the last frame of the WAL that is
43628 ** safe to write into the database. Frames beyond mxSafeFrame might
43629 ** overwrite database pages that are in use by active readers and thus
@@ -51996,13 +52060,11 @@
52060 minI = j;
52061 minV = apNew[j]->pgno;
52062 }
52063 }
52064 if( minI>i ){
 
52065 MemPage *pT;
 
52066 pT = apNew[i];
52067 apNew[i] = apNew[minI];
52068 apNew[minI] = pT;
52069 }
52070 }
@@ -55005,11 +55067,11 @@
55067 if( flags & MEM_Int ){
55068 return pMem->u.i;
55069 }else if( flags & MEM_Real ){
55070 return doubleToInt64(pMem->r);
55071 }else if( flags & (MEM_Str|MEM_Blob) ){
55072 i64 value = 0;
55073 assert( pMem->z || pMem->n==0 );
55074 testcase( pMem->z==0 );
55075 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
55076 return value;
55077 }else{
@@ -57310,11 +57372,11 @@
57372 ** pointers to VdbeFrame objects, which may in turn contain pointers to
57373 ** open cursors.
57374 */
57375 static void closeAllCursors(Vdbe *p){
57376 if( p->pFrame ){
57377 VdbeFrame *pFrame;
57378 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
57379 sqlite3VdbeFrameRestore(pFrame);
57380 }
57381 p->pFrame = 0;
57382 p->nFrame = 0;
@@ -58290,11 +58352,17 @@
58352 i64 i = pMem->u.i;
58353 u64 u;
58354 if( file_format>=4 && (i&1)==i ){
58355 return 8+(u32)i;
58356 }
58357 if( i<0 ){
58358 if( i<(-MAX_6BYTE) ) return 6;
58359 /* Previous test prevents: u = -(-9223372036854775808) */
58360 u = -i;
58361 }else{
58362 u = i;
58363 }
58364 if( u<=127 ) return 1;
58365 if( u<=32767 ) return 2;
58366 if( u<=8388607 ) return 3;
58367 if( u<=2147483647 ) return 4;
58368 if( u<=MAX_6BYTE ) return 5;
@@ -59640,17 +59708,15 @@
59708 ** If iCol is not valid, return a pointer to a Mem which has a value
59709 ** of NULL.
59710 */
59711 static Mem *columnMem(sqlite3_stmt *pStmt, int i){
59712 Vdbe *pVm;
 
59713 Mem *pOut;
59714
59715 pVm = (Vdbe *)pStmt;
59716 if( pVm && pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){
59717 sqlite3_mutex_enter(pVm->db->mutex);
 
59718 pOut = &pVm->pResultSet[i];
59719 }else{
59720 /* If the value passed as the second argument is out of range, return
59721 ** a pointer to the following static Mem object which contains the
59722 ** value SQL NULL. Even though the Mem structure contains an element
@@ -61138,12 +61204,14 @@
61204 sqlite3_context ctx;
61205 sqlite3_value **apVal;
61206 int n;
61207 } ag;
61208 struct OP_ShiftRight_stack_vars {
61209 i64 iA;
61210 u64 uA;
61211 i64 iB;
61212 u8 op;
61213 } ah;
61214 struct OP_Ge_stack_vars {
61215 int res; /* Result of the comparison of pIn1 against pIn3 */
61216 char affinity; /* Affinity to use for comparison */
61217 u16 flags1; /* Copy of initial value of pIn1->flags */
@@ -62189,23 +62257,16 @@
62257 if( (u.af.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
62258 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
62259 u.af.iA = pIn1->u.i;
62260 u.af.iB = pIn2->u.i;
62261 switch( pOp->opcode ){
62262 case OP_Add: if( sqlite3AddInt64(&u.af.iB,u.af.iA) ) goto fp_math; break;
62263 case OP_Subtract: if( sqlite3SubInt64(&u.af.iB,u.af.iA) ) goto fp_math; break;
62264 case OP_Multiply: if( sqlite3MulInt64(&u.af.iB,u.af.iA) ) goto fp_math; break;
62265 case OP_Divide: {
62266 if( u.af.iA==0 ) goto arithmetic_result_is_null;
62267 if( u.af.iA==-1 && u.af.iB==SMALLEST_INT64 ) goto fp_math;
 
 
 
 
 
 
 
62268 u.af.iB /= u.af.iA;
62269 break;
62270 }
62271 default: {
62272 if( u.af.iA==0 ) goto arithmetic_result_is_null;
@@ -62215,10 +62276,11 @@
62276 }
62277 }
62278 pOut->u.i = u.af.iB;
62279 MemSetTypeFlag(pOut, MEM_Int);
62280 }else{
62281 fp_math:
62282 u.af.rA = sqlite3VdbeRealValue(pIn1);
62283 u.af.rB = sqlite3VdbeRealValue(pIn2);
62284 switch( pOp->opcode ){
62285 case OP_Add: u.af.rB += u.af.rA; break;
62286 case OP_Subtract: u.af.rB -= u.af.rA; break;
@@ -62412,31 +62474,55 @@
62474 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
62475 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
62476 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
62477 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
62478 #if 0 /* local variables moved into u.ah */
62479 i64 iA;
62480 u64 uA;
62481 i64 iB;
62482 u8 op;
62483 #endif /* local variables moved into u.ah */
62484
62485 pIn1 = &aMem[pOp->p1];
62486 pIn2 = &aMem[pOp->p2];
62487 pOut = &aMem[pOp->p3];
62488 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
62489 sqlite3VdbeMemSetNull(pOut);
62490 break;
62491 }
62492 u.ah.iA = sqlite3VdbeIntValue(pIn2);
62493 u.ah.iB = sqlite3VdbeIntValue(pIn1);
62494 u.ah.op = pOp->opcode;
62495 if( u.ah.op==OP_BitAnd ){
62496 u.ah.iA &= u.ah.iB;
62497 }else if( u.ah.op==OP_BitOr ){
62498 u.ah.iA |= u.ah.iB;
62499 }else if( u.ah.iB!=0 ){
62500 assert( u.ah.op==OP_ShiftRight || u.ah.op==OP_ShiftLeft );
62501
62502 /* If shifting by a negative amount, shift in the other direction */
62503 if( u.ah.iB<0 ){
62504 assert( OP_ShiftRight==OP_ShiftLeft+1 );
62505 u.ah.op = 2*OP_ShiftLeft + 1 - u.ah.op;
62506 u.ah.iB = u.ah.iB>(-64) ? -u.ah.iB : 64;
62507 }
62508
62509 if( u.ah.iB>=64 ){
62510 u.ah.iA = (u.ah.iA>=0 || u.ah.op==OP_ShiftLeft) ? 0 : -1;
62511 }else{
62512 memcpy(&u.ah.uA, &u.ah.iA, sizeof(u.ah.uA));
62513 if( u.ah.op==OP_ShiftLeft ){
62514 u.ah.uA <<= u.ah.iB;
62515 }else{
62516 u.ah.uA >>= u.ah.iB;
62517 /* Sign-extend on a right shift of a negative number */
62518 if( u.ah.iA<0 ) u.ah.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ah.iB);
62519 }
62520 memcpy(&u.ah.iA, &u.ah.uA, sizeof(u.ah.iA));
62521 }
62522 }
62523 pOut->u.i = u.ah.iA;
62524 MemSetTypeFlag(pOut, MEM_Int);
62525 break;
62526 }
62527
62528 /* Opcode: AddImm P1 P2 * * *
@@ -63372,11 +63458,10 @@
63458 ** hdr-size field is also a varint which is the offset from the beginning
63459 ** of the record to data0.
63460 */
63461 u.ao.nData = 0; /* Number of bytes of data space */
63462 u.ao.nHdr = 0; /* Number of bytes of header space */
 
63463 u.ao.nZero = 0; /* Number of zero bytes at the end of the record */
63464 u.ao.nField = pOp->p1;
63465 u.ao.zAffinity = pOp->p4.z;
63466 assert( u.ao.nField>0 && pOp->p2>0 && pOp->p2+u.ao.nField<=p->nMem+1 );
63467 u.ao.pData0 = &aMem[u.ao.nField];
@@ -64678,11 +64763,10 @@
64763 ** it already exists in the table. If it does not exist, we have
64764 ** succeeded. If the random rowid does exist, we select a new one
64765 ** and try again, up to 100 times.
64766 */
64767 assert( u.be.pC->isTable );
 
64768
64769 #ifdef SQLITE_32BIT_ROWID
64770 # define MAX_ROWID 0x7fffffff
64771 #else
64772 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -71317,11 +71401,11 @@
71401 const char *z = pExpr->u.zToken;
71402 assert( z!=0 );
71403 c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
71404 if( c==0 || (c==2 && negFlag) ){
71405 char *zV;
71406 if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
71407 zV = dup8bytes(v, (char*)&value);
71408 sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
71409 }else{
71410 #ifdef SQLITE_OMIT_FLOATING_POINT
71411 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
@@ -81443,17 +81527,12 @@
81527 if( p && type!=SQLITE_NULL ){
81528 p->cnt++;
81529 if( type==SQLITE_INTEGER ){
81530 i64 v = sqlite3_value_int64(argv[0]);
81531 p->rSum += v;
81532 if( (p->approx|p->overflow)==0 && sqlite3AddInt64(&p->iSum, v) ){
81533 p->overflow = 1;
 
 
 
 
 
81534 }
81535 }else{
81536 p->rSum += sqlite3_value_double(argv[0]);
81537 p->approx = 1;
81538 }
@@ -82489,11 +82568,10 @@
82568 Table *pTab, /* Row is being deleted from this table */
82569 int regOld, /* Previous row data is stored here */
82570 int regNew /* New row data is stored here */
82571 ){
82572 sqlite3 *db = pParse->db; /* Database handle */
 
82573 FKey *pFKey; /* Used to iterate through FKs */
82574 int iDb; /* Index of database containing pTab */
82575 const char *zDb; /* Name of database containing pTab */
82576 int isIgnoreErrors = pParse->disableTriggers;
82577
@@ -82501,11 +82579,10 @@
82579 assert( (regOld==0)!=(regNew==0) );
82580
82581 /* If foreign-keys are disabled, this function is a no-op. */
82582 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
82583
 
82584 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
82585 zDb = db->aDb[iDb].zName;
82586
82587 /* Loop through all the foreign key constraints for which pTab is the
82588 ** child table (the table that the foreign key definition is part of). */
@@ -83459,11 +83536,10 @@
83536 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
83537 int regRowCount = 0; /* Memory cell used for the row counter */
83538 int regIns; /* Block of regs holding rowid+data being inserted */
83539 int regRowid; /* registers holding insert rowid */
83540 int regData; /* register holding first column to insert */
 
83541 int regEof = 0; /* Register recording end of SELECT data */
83542 int *aRegIdx = 0; /* One register allocated to each index */
83543
83544 #ifndef SQLITE_OMIT_TRIGGER
83545 int isView; /* True if attempting to insert into a view */
@@ -83788,11 +83864,10 @@
83864 }
83865
83866 /* Allocate registers for holding the rowid of the new row,
83867 ** the content of the new row, and the assemblied row record.
83868 */
 
83869 regRowid = regIns = pParse->nMem+1;
83870 pParse->nMem += pTab->nCol + 1;
83871 if( IsVirtual(pTab) ){
83872 regRowid++;
83873 pParse->nMem++;
@@ -84182,11 +84257,11 @@
84257 case OE_Abort:
84258 sqlite3MayAbort(pParse);
84259 case OE_Rollback:
84260 case OE_Fail: {
84261 char *zMsg;
84262 sqlite3VdbeAddOp3(v, OP_HaltIfNull,
84263 SQLITE_CONSTRAINT, onError, regData+i);
84264 zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL",
84265 pTab->zName, pTab->aCol[i].zName);
84266 sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC);
84267 break;
@@ -87708,11 +87783,11 @@
87783 Db *pDb;
87784 char const *azArg[4];
87785 int meta[5];
87786 InitData initData;
87787 char const *zMasterSchema;
87788 char const *zMasterName;
87789 int openedTransaction = 0;
87790
87791 /*
87792 ** The master database table has a structure like this
87793 */
@@ -93351,11 +93426,10 @@
93426 sqlite3 *db = pParse->db; /* The database */
93427 DbFixer sFix; /* Fixer object */
93428 int iDb; /* Database containing the trigger */
93429 Token nameToken; /* Trigger name for error reporting */
93430
 
93431 pParse->pNewTrigger = 0;
93432 if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup;
93433 zName = pTrig->zName;
93434 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
93435 pTrig->step_list = pStepList;
@@ -94314,11 +94388,10 @@
94388 int regOldRowid; /* The old rowid */
94389 int regNewRowid; /* The new rowid */
94390 int regNew;
94391 int regOld = 0;
94392 int regRowSet = 0; /* Rowset of rows to be updated */
 
94393
94394 memset(&sContext, 0, sizeof(sContext));
94395 db = pParse->db;
94396 if( pParse->nErr || db->mallocFailed ){
94397 goto update_cleanup;
@@ -94472,11 +94545,10 @@
94545 if( chngRowid || pTrigger || hasFK ){
94546 regNewRowid = ++pParse->nMem;
94547 }
94548 regNew = pParse->nMem + 1;
94549 pParse->nMem += pTab->nCol;
 
94550
94551 /* Start the view context. */
94552 if( isView ){
94553 sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
94554 }
@@ -94582,11 +94654,11 @@
94654 u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0);
94655 oldmask |= sqlite3TriggerColmask(pParse,
94656 pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError
94657 );
94658 for(i=0; i<pTab->nCol; i++){
94659 if( aXRef[i]<0 || oldmask==0xffffffff || (i<32 && (oldmask & (1<<i))) ){
94660 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i);
94661 }else{
94662 sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i);
94663 }
94664 }
@@ -100187,11 +100259,10 @@
100259 **
100260 ** B: <after the loop>
100261 **
100262 */
100263 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
 
100264 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
100265
100266 int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */
100267 int regRowset = 0; /* Register for RowSet object */
100268 int regRowid = 0; /* Register holding rowid */
@@ -100203,11 +100274,10 @@
100274 pTerm = pLevel->plan.u.pTerm;
100275 assert( pTerm!=0 );
100276 assert( pTerm->eOperator==WO_OR );
100277 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
100278 pOrWc = &pTerm->u.pOrInfo->wc;
 
100279 pLevel->op = OP_Return;
100280 pLevel->p1 = regReturn;
100281
100282 /* Set up a new SrcList ni pOrTab containing the table being scanned
100283 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
@@ -100312,11 +100382,10 @@
100382 **
100383 ** IMPLEMENTATION-OF: R-49525-50935 Terms that cannot be satisfied through
100384 ** the use of indices become tests that are evaluated against each row of
100385 ** the relevant input tables.
100386 */
 
100387 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
100388 Expr *pE;
100389 testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */
100390 testcase( pTerm->wtFlags & TERM_CODED );
100391 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
@@ -100330,11 +100399,10 @@
100399 assert( pE!=0 );
100400 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
100401 continue;
100402 }
100403 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
 
100404 pTerm->wtFlags |= TERM_CODED;
100405 }
100406
100407 /* For a LEFT OUTER JOIN, generate code that will record the fact that
100408 ** at least one row of the right table has matched the left table.
@@ -100638,12 +100706,10 @@
100706 **
100707 ** This loop also figures out the nesting order of tables in the FROM
100708 ** clause.
100709 */
100710 notReady = ~(Bitmask)0;
 
 
100711 andFlags = ~0;
100712 WHERETRACE(("*** Optimizer Start ***\n"));
100713 for(i=iFrom=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
100714 WhereCost bestPlan; /* Most efficient plan seen so far */
100715 Index *pIdx; /* Index for FROM table at pTabItem */
@@ -100750,12 +100816,12 @@
100816 /* Conditions under which this table becomes the best so far:
100817 **
100818 ** (1) The table must not depend on other tables that have not
100819 ** yet run.
100820 **
100821 ** (2) A full-table-scan plan cannot supercede indexed plan unless
100822 ** the full-table-scan is an "optimal" plan as defined above.
100823 **
100824 ** (3) All tables have an INDEXED BY clause or this table lacks an
100825 ** INDEXED BY clause or this table uses the specific
100826 ** index specified by its INDEXED BY clause. This rule ensures
100827 ** that a best-so-far is always selected even if an impossible
@@ -100767,10 +100833,11 @@
100833 ** (4) The plan cost must be lower than prior plans or else the
100834 ** cost must be the same and the number of rows must be lower.
100835 */
100836 if( (sCost.used&notReady)==0 /* (1) */
100837 && (bestJ<0 || (notIndexed&m)!=0 /* (2) */
100838 || (bestPlan.plan.wsFlags & WHERE_NOT_FULLSCAN)==0
100839 || (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)
100840 && (nUnconstrained==0 || pTabItem->pIndex==0 /* (3) */
100841 || NEVER((sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0))
100842 && (bestJ<0 || sCost.rCost<bestPlan.rCost /* (4) */
100843 || (sCost.rCost<=bestPlan.rCost
@@ -123657,11 +123724,11 @@
123724 int nCell = 0;
123725 RtreeCell cell;
123726 int jj;
123727
123728 nodeGetCell(&tree, &node, ii, &cell);
123729 sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
123730 nCell = strlen(zCell);
123731 for(jj=0; jj<tree.nDim*2; jj++){
123732 sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f);
123733 nCell = strlen(zCell);
123734 }
123735
+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.7.6"
111111
#define SQLITE_VERSION_NUMBER 3007006
112
-#define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a"
112
+#define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61"
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.7.6"
111 #define SQLITE_VERSION_NUMBER 3007006
112 #define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a"
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.7.6"
111 #define SQLITE_VERSION_NUMBER 3007006
112 #define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

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