| | @@ -135,11 +135,11 @@ |
| 135 | 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | 137 | */ |
| 138 | 138 | #define SQLITE_VERSION "3.8.2" |
| 139 | 139 | #define SQLITE_VERSION_NUMBER 3008002 |
| 140 | | -#define SQLITE_SOURCE_ID "2013-11-27 14:50:51 c75f561f337a56c14335366ed9990e44bc9fc594" |
| 140 | +#define SQLITE_SOURCE_ID "2013-12-03 02:52:11 7d99858bec699dface548c77649dfc50e7fb50d8" |
| 141 | 141 | |
| 142 | 142 | /* |
| 143 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | 145 | ** |
| | @@ -3806,23 +3806,23 @@ |
| 3806 | 3806 | ** <table border="1"> |
| 3807 | 3807 | ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion |
| 3808 | 3808 | ** |
| 3809 | 3809 | ** <tr><td> NULL <td> INTEGER <td> Result is 0 |
| 3810 | 3810 | ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 |
| 3811 | | -** <tr><td> NULL <td> TEXT <td> Result is NULL pointer |
| 3812 | | -** <tr><td> NULL <td> BLOB <td> Result is NULL pointer |
| 3811 | +** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer |
| 3812 | +** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer |
| 3813 | 3813 | ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float |
| 3814 | 3814 | ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer |
| 3815 | 3815 | ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT |
| 3816 | | -** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer |
| 3816 | +** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER |
| 3817 | 3817 | ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float |
| 3818 | | -** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT |
| 3819 | | -** <tr><td> TEXT <td> INTEGER <td> Use atoi() |
| 3820 | | -** <tr><td> TEXT <td> FLOAT <td> Use atof() |
| 3818 | +** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB |
| 3819 | +** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER |
| 3820 | +** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL |
| 3821 | 3821 | ** <tr><td> TEXT <td> BLOB <td> No change |
| 3822 | | -** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi() |
| 3823 | | -** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof() |
| 3822 | +** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER |
| 3823 | +** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL |
| 3824 | 3824 | ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed |
| 3825 | 3825 | ** </table> |
| 3826 | 3826 | ** </blockquote>)^ |
| 3827 | 3827 | ** |
| 3828 | 3828 | ** The table above makes reference to standard C library functions atoi() |
| | @@ -6100,11 +6100,12 @@ |
| 6100 | 6100 | #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 |
| 6101 | 6101 | #define SQLITE_TESTCTRL_ISKEYWORD 16 |
| 6102 | 6102 | #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 |
| 6103 | 6103 | #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 |
| 6104 | 6104 | #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 |
| 6105 | | -#define SQLITE_TESTCTRL_LAST 19 |
| 6105 | +#define SQLITE_TESTCTRL_NEVER_CORRUPT 20 |
| 6106 | +#define SQLITE_TESTCTRL_LAST 20 |
| 6106 | 6107 | |
| 6107 | 6108 | /* |
| 6108 | 6109 | ** CAPI3REF: SQLite Runtime Status |
| 6109 | 6110 | ** |
| 6110 | 6111 | ** ^This interface is used to retrieve runtime status information |
| | @@ -11807,10 +11808,11 @@ |
| 11807 | 11808 | int bCoreMutex; /* True to enable core mutexing */ |
| 11808 | 11809 | int bFullMutex; /* True to enable full mutexing */ |
| 11809 | 11810 | int bOpenUri; /* True to interpret filenames as URIs */ |
| 11810 | 11811 | int bUseCis; /* Use covering indices for full-scans */ |
| 11811 | 11812 | int mxStrlen; /* Maximum string length */ |
| 11813 | + int neverCorrupt; /* Database is always well-formed */ |
| 11812 | 11814 | int szLookaside; /* Default lookaside buffer size */ |
| 11813 | 11815 | int nLookaside; /* Default lookaside buffer count */ |
| 11814 | 11816 | sqlite3_mem_methods m; /* Low-level memory allocation interface */ |
| 11815 | 11817 | sqlite3_mutex_methods mutex; /* Low-level mutex interface */ |
| 11816 | 11818 | sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */ |
| | @@ -11843,10 +11845,28 @@ |
| 11843 | 11845 | void(*xSqllog)(void*,sqlite3*,const char*, int); |
| 11844 | 11846 | void *pSqllogArg; |
| 11845 | 11847 | #endif |
| 11846 | 11848 | }; |
| 11847 | 11849 | |
| 11850 | +/* |
| 11851 | +** This macro is used inside of assert() statements to indicate that |
| 11852 | +** the assert is only valid on a well-formed database. Instead of: |
| 11853 | +** |
| 11854 | +** assert( X ); |
| 11855 | +** |
| 11856 | +** One writes: |
| 11857 | +** |
| 11858 | +** assert( X || CORRUPT_DB ); |
| 11859 | +** |
| 11860 | +** CORRUPT_DB is true during normal operation. CORRUPT_DB does not indicate |
| 11861 | +** that the database is definitely corrupt, only that it might be corrupt. |
| 11862 | +** For most test cases, CORRUPT_DB is set to false using a special |
| 11863 | +** sqlite3_test_control(). This enables assert() statements to prove |
| 11864 | +** things that are always true for well-formed databases. |
| 11865 | +*/ |
| 11866 | +#define CORRUPT_DB (sqlite3Config.neverCorrupt==0) |
| 11867 | + |
| 11848 | 11868 | /* |
| 11849 | 11869 | ** Context pointer passed down through the tree-walk. |
| 11850 | 11870 | */ |
| 11851 | 11871 | struct Walker { |
| 11852 | 11872 | int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| | @@ -12870,10 +12890,11 @@ |
| 12870 | 12890 | 1, /* bCoreMutex */ |
| 12871 | 12891 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
| 12872 | 12892 | SQLITE_USE_URI, /* bOpenUri */ |
| 12873 | 12893 | SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ |
| 12874 | 12894 | 0x7ffffffe, /* mxStrlen */ |
| 12895 | + 0, /* neverCorrupt */ |
| 12875 | 12896 | 128, /* szLookaside */ |
| 12876 | 12897 | 500, /* nLookaside */ |
| 12877 | 12898 | {0,0,0,0,0,0,0,0}, /* m */ |
| 12878 | 12899 | {0,0,0,0,0,0,0,0,0}, /* mutex */ |
| 12879 | 12900 | {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */ |
| | @@ -12904,11 +12925,10 @@ |
| 12904 | 12925 | #ifdef SQLITE_ENABLE_SQLLOG |
| 12905 | 12926 | 0, /* xSqllog */ |
| 12906 | 12927 | 0 /* pSqllogArg */ |
| 12907 | 12928 | #endif |
| 12908 | 12929 | }; |
| 12909 | | - |
| 12910 | 12930 | |
| 12911 | 12931 | /* |
| 12912 | 12932 | ** Hash table for global functions - functions common to all |
| 12913 | 12933 | ** database connections. After initialization, this table is |
| 12914 | 12934 | ** read-only. |
| | @@ -21793,16 +21813,16 @@ |
| 21793 | 21813 | ** Convert zNum to a 64-bit signed integer. |
| 21794 | 21814 | ** |
| 21795 | 21815 | ** If the zNum value is representable as a 64-bit twos-complement |
| 21796 | 21816 | ** integer, then write that value into *pNum and return 0. |
| 21797 | 21817 | ** |
| 21798 | | -** If zNum is exactly 9223372036854665808, return 2. This special |
| 21799 | | -** case is broken out because while 9223372036854665808 cannot be a |
| 21800 | | -** signed 64-bit integer, its negative -9223372036854665808 can be. |
| 21818 | +** If zNum is exactly 9223372036854775808, return 2. This special |
| 21819 | +** case is broken out because while 9223372036854775808 cannot be a |
| 21820 | +** signed 64-bit integer, its negative -9223372036854775808 can be. |
| 21801 | 21821 | ** |
| 21802 | 21822 | ** If zNum is too big for a 64-bit integer and is not |
| 21803 | | -** 9223372036854665808 or if zNum contains any non-numeric text, |
| 21823 | +** 9223372036854775808 or if zNum contains any non-numeric text, |
| 21804 | 21824 | ** then return 1. |
| 21805 | 21825 | ** |
| 21806 | 21826 | ** length is the number of bytes in the string (bytes, not characters). |
| 21807 | 21827 | ** The string is not necessarily zero-terminated. The encoding is |
| 21808 | 21828 | ** given by enc. |
| | @@ -51013,10 +51033,14 @@ |
| 51013 | 51033 | pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 51014 | 51034 | pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree |
| 51015 | 51035 | ); |
| 51016 | 51036 | if( pIdxKey==0 ) return SQLITE_NOMEM; |
| 51017 | 51037 | sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey); |
| 51038 | + if( pIdxKey->nField==0 ){ |
| 51039 | + sqlite3DbFree(pCur->pKeyInfo->db, pFree); |
| 51040 | + return SQLITE_CORRUPT_BKPT; |
| 51041 | + } |
| 51018 | 51042 | }else{ |
| 51019 | 51043 | pIdxKey = 0; |
| 51020 | 51044 | } |
| 51021 | 51045 | rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes); |
| 51022 | 51046 | if( pFree ){ |
| | @@ -60677,20 +60701,11 @@ |
| 60677 | 60701 | if( !pExpr ){ |
| 60678 | 60702 | *ppVal = 0; |
| 60679 | 60703 | return SQLITE_OK; |
| 60680 | 60704 | } |
| 60681 | 60705 | op = pExpr->op; |
| 60682 | | - |
| 60683 | | - /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT4. |
| 60684 | | - ** The ifdef here is to enable us to achieve 100% branch test coverage even |
| 60685 | | - ** when SQLITE_ENABLE_STAT4 is omitted. |
| 60686 | | - */ |
| 60687 | | -#ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 60688 | | - if( op==TK_REGISTER ) op = pExpr->op2; |
| 60689 | | -#else |
| 60690 | 60706 | if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; |
| 60691 | | -#endif |
| 60692 | 60707 | |
| 60693 | 60708 | /* Handle negative integers in a single step. This is needed in the |
| 60694 | 60709 | ** case when the value is -9223372036854775808. |
| 60695 | 60710 | */ |
| 60696 | 60711 | if( op==TK_UMINUS |
| | @@ -60908,11 +60923,11 @@ |
| 60908 | 60923 | if( pVal ){ |
| 60909 | 60924 | sqlite3VdbeMemSetNull((Mem*)pVal); |
| 60910 | 60925 | *pbOk = 1; |
| 60911 | 60926 | } |
| 60912 | 60927 | }else if( pExpr->op==TK_VARIABLE |
| 60913 | | - || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE) |
| 60928 | + || NEVER(pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE) |
| 60914 | 60929 | ){ |
| 60915 | 60930 | Vdbe *v; |
| 60916 | 60931 | int iBindVar = pExpr->iColumn; |
| 60917 | 60932 | sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar); |
| 60918 | 60933 | if( (v = pParse->pReprepare)!=0 ){ |
| | @@ -64108,13 +64123,13 @@ |
| 64108 | 64123 | */ |
| 64109 | 64124 | /* mem1.u.i = 0; // not needed, here to silence compiler warning */ |
| 64110 | 64125 | |
| 64111 | 64126 | idx1 = getVarint32(aKey1, szHdr1); |
| 64112 | 64127 | d1 = szHdr1; |
| 64113 | | - assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField ); |
| 64128 | + assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB ); |
| 64114 | 64129 | assert( pKeyInfo->aSortOrder!=0 ); |
| 64115 | | - assert( idx1<szHdr1 && i<pPKey2->nField ); |
| 64130 | + assert( (idx1<=szHdr1 && i<pPKey2->nField) || CORRUPT_DB ); |
| 64116 | 64131 | do{ |
| 64117 | 64132 | u32 serial_type1; |
| 64118 | 64133 | |
| 64119 | 64134 | /* Read the serial types for the next element in each key. */ |
| 64120 | 64135 | idx1 += getVarint32( aKey1+idx1, serial_type1 ); |
| | @@ -70718,13 +70733,12 @@ |
| 70718 | 70733 | rc = sqlite3BtreeDelete(u.bj.pC->pCursor); |
| 70719 | 70734 | u.bj.pC->cacheStatus = CACHE_STALE; |
| 70720 | 70735 | |
| 70721 | 70736 | /* Invoke the update-hook if required. */ |
| 70722 | 70737 | if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && u.bj.pC->isTable ){ |
| 70723 | | - const char *zDb = db->aDb[u.bj.pC->iDb].zName; |
| 70724 | | - const char *zTbl = pOp->p4.z; |
| 70725 | | - db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, u.bj.iKey); |
| 70738 | + db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, |
| 70739 | + db->aDb[u.bj.pC->iDb].zName, pOp->p4.z, u.bj.iKey); |
| 70726 | 70740 | assert( u.bj.pC->iDb>=0 ); |
| 70727 | 70741 | } |
| 70728 | 70742 | if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; |
| 70729 | 70743 | break; |
| 70730 | 70744 | } |
| | @@ -87011,11 +87025,11 @@ |
| 87011 | 87025 | Token *pName = 0; /* Unqualified name of the index to create */ |
| 87012 | 87026 | struct ExprList_item *pListItem; /* For looping over pList */ |
| 87013 | 87027 | const Column *pTabCol; /* A column in the table */ |
| 87014 | 87028 | int nExtra = 0; /* Space allocated for zExtra[] */ |
| 87015 | 87029 | int nExtraCol; /* Number of extra columns needed */ |
| 87016 | | - char *zExtra; /* Extra space after the Index object */ |
| 87030 | + char *zExtra = 0; /* Extra space after the Index object */ |
| 87017 | 87031 | Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */ |
| 87018 | 87032 | |
| 87019 | 87033 | assert( pParse->nErr==0 ); /* Never called with prior errors */ |
| 87020 | 87034 | if( db->mallocFailed || IN_DECLARE_VTAB ){ |
| 87021 | 87035 | goto exit_create_index; |
| | @@ -122278,10 +122292,23 @@ |
| 122278 | 122292 | const char **pzRet = va_arg(ap, const char**); |
| 122279 | 122293 | *pzRet = sqlite3VdbeExplanation((Vdbe*)pStmt); |
| 122280 | 122294 | break; |
| 122281 | 122295 | } |
| 122282 | 122296 | #endif |
| 122297 | + |
| 122298 | + /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int); |
| 122299 | + ** |
| 122300 | + ** Set or clear a flag that indicates that the database file is always well- |
| 122301 | + ** formed and never corrupt. This flag is clear by default, indicating that |
| 122302 | + ** database files might have arbitrary corruption. Setting the flag during |
| 122303 | + ** testing causes certain assert() statements in the code to be activated |
| 122304 | + ** that demonstrat invariants on well-formed database files. |
| 122305 | + */ |
| 122306 | + case SQLITE_TESTCTRL_NEVER_CORRUPT: { |
| 122307 | + sqlite3Config.neverCorrupt = va_arg(ap, int); |
| 122308 | + break; |
| 122309 | + } |
| 122283 | 122310 | |
| 122284 | 122311 | } |
| 122285 | 122312 | va_end(ap); |
| 122286 | 122313 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 122287 | 122314 | return rc; |
| 122288 | 122315 | |