Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Improve error messages caused by corrupt database schemas in OPEN_SHARED_SCHEMA mode. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | reuse-schema |
Files: | files | file ages | folders |
SHA3-256: |
8ac75b8a880447ea67cf7646fc5af137 |
User & Date: | dan 2019-02-19 18:00:28.023 |
Context
2019-02-20
| ||
17:36 | Add test and fixes for SQLITE_OPEN_SHARED_SCHEMA mode. (check-in: 9a78d89c84 user: dan tags: reuse-schema) | |
2019-02-19
| ||
18:00 | Improve error messages caused by corrupt database schemas in OPEN_SHARED_SCHEMA mode. (check-in: 8ac75b8a88 user: dan tags: reuse-schema) | |
2019-02-18
| ||
18:16 | Ensure that creating temp schema items does not cause an OPEN_SHARABLE_SCHEMA connection to load all schemas into memory. (check-in: 88cbf54eee user: dan tags: reuse-schema) | |
Changes
Changes to src/alter.c.
︙ | |||
120 121 122 123 124 125 126 | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | - + | /* Get a NULL terminated version of the new table name. */ zName = sqlite3NameFromToken(db, pName); if( !zName ) goto exit_rename_table; /* Check that a table or index named 'zName' does not already exist ** in database iDb. If so, this is an error. */ |
︙ | |||
207 208 209 210 211 212 213 | 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | - + | nTabName, zTabName ); #ifndef SQLITE_OMIT_AUTOINCREMENT /* If the sqlite_sequence table exists in this database, then update ** it with the new table name. */ |
︙ | |||
284 285 286 287 288 289 290 | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | - + | assert( sqlite3BtreeHoldsAllMutexes(db) ); iDb = sqlite3SchemaToIndex(db, pNew->pSchema); zDb = db->aDb[iDb].zDbSName; zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */ pCol = &pNew->aCol[pNew->nCol-1]; pDflt = pCol->pDflt; |
︙ | |||
1082 1083 1084 1085 1086 1087 1088 | 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 | - + | TriggerStep *pStep; NameContext sNC; int rc = SQLITE_OK; memset(&sNC, 0, sizeof(sNC)); sNC.pParse = pParse; assert( pNew->pTabSchema ); |
︙ | |||
1246 1247 1248 1249 1250 1251 1252 | 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | - + | UNUSED_PARAMETER(NotUsed); if( zSql==0 ) return; if( zTable==0 ) return; if( zNew==0 ) return; if( iCol<0 ) return; sqlite3BtreeEnterAll(db); |
︙ | |||
1448 1449 1450 1451 1452 1453 1454 | 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 | - + | sqlite3_xauth xAuth = db->xAuth; db->xAuth = 0; #endif sqlite3BtreeEnterAll(db); memset(&sCtx, 0, sizeof(RenameCtx)); |
︙ |
Changes to src/analyze.c.
︙ | |||
206 207 208 209 210 211 212 | 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | - + | /* Create new statistic tables if they do not exist, or clear them ** if they do already exist. */ for(i=0; i<ArraySize(aTable); i++){ const char *zTab = aTable[i].zName; Table *pStat; |
︙ | |||
1532 1533 1534 1535 1536 1537 1538 | 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 | - + | assert( argc==3 ); UNUSED_PARAMETER2(NotUsed, argc); if( argv==0 || argv[0]==0 || argv[2]==0 ){ return 0; } |
︙ | |||
1674 1675 1676 1677 1678 1679 1680 | 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 | - + | static Index *findIndexOrPrimaryKey( sqlite3 *db, const char *zName, const char *zDb ){ Index *pIdx = sqlite3FindIndex(db, zName, zDb); if( pIdx==0 ){ |
︙ | |||
1823 1824 1825 1826 1827 1828 1829 | 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 | - + - + | ** Load content from the sqlite_stat4 and sqlite_stat3 tables into ** the Index.aSample[] arrays of all indices. */ static int loadStat4(sqlite3 *db, const char *zDb){ int rc = SQLITE_OK; /* Result codes from subroutines */ assert( db->lookaside.bDisable ); |
︙ | |||
1891 1892 1893 1894 1895 1896 1897 | 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 | - + | pIdx->aSample = 0; #endif } /* Load new statistics out of the sqlite_stat1 table */ sInfo.db = db; sInfo.zDatabase = db->aDb[iDb].zDbSName; |
︙ |
Changes to src/build.c.
︙ | |||
317 318 319 320 321 322 323 | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | - + - - - - - - - - + + + + + + | ** If zDatabase is 0, all databases are searched for the table and the ** first matching table is returned. (No checking for duplicate table ** names is done.) The search order is TEMP first, then MAIN, then any ** auxiliary databases added using the ATTACH command. ** ** See also sqlite3LocateTable(). */ |
︙ | |||
389 390 391 392 393 394 395 | 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | - + | if( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 && !IsReuseSchema(db) && SQLITE_OK!=sqlite3ReadSchema(pParse) ){ return 0; } |
︙ | |||
421 422 423 424 425 426 427 | 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | - + | #endif if( flags & LOCATE_NOERR ) return 0; pParse->checkSchema = 1; }else if( IsVirtual(p) && pParse->disableVtab ){ p = 0; } |
︙ | |||
991 992 993 994 995 996 997 | 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 | - + | ** collisions. */ if( !IN_SPECIAL_PARSE ){ char *zDb = db->aDb[iDb].zDbSName; if( !IsReuseSchema(db) && SQLITE_OK!=sqlite3ReadSchema(pParse) ){ goto begin_table_error; } |
︙ | |||
1963 1964 1965 1966 1967 1968 1969 | 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 | - + | char *zTail; /* Pointer to the last "_" in zName */ Table *pTab; /* Table that zName is a shadow of */ Module *pMod; /* Module for the virtual table */ zTail = strrchr(zName, '_'); if( zTail==0 ) return 0; *zTail = 0; |
︙ | |||
2613 2614 2615 2616 2617 2618 2619 | 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 | - + | const char *zName /* Name of index or table */ ){ int i; const char *zDbName = pParse->db->aDb[iDb].zDbSName; for(i=1; i<=4; i++){ char zTab[24]; sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i); |
︙ | |||
3238 3239 3240 3241 3242 3243 3244 | 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 | - + | if( zName==0 ) goto exit_create_index; assert( pName->z!=0 ); if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto exit_create_index; } if( !IN_RENAME_OBJECT ){ if( !db->init.busy ){ |
︙ | |||
4592 4593 4594 4595 4596 4597 4598 | 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 | - + | sqlite3DbFree(db, zColl); } iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pObjName); if( iDb<0 ) return; z = sqlite3NameFromToken(db, pObjName); if( z==0 ) return; zDb = db->aDb[iDb].zDbSName; |
︙ |
Changes to src/fkey.c.
︙ | |||
904 905 906 907 908 909 910 | 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 | - + | } /* Find the parent table of this foreign key. Also find a unique index ** on the parent key columns in the parent table. If either of these ** schema items cannot be located, set an error in pParse and return ** early. */ if( pParse->disableTriggers ){ |
︙ |
Changes to src/main.c.
︙ | |||
3629 3630 3631 3632 3633 3634 3635 3636 | 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 | + + - + + | if( IsReuseSchema(db)==0 ){ rc = sqlite3Init(db, &zErrMsg); } /* Locate the table in question */ if( rc==SQLITE_OK ){ Parse sParse; /* Fake Parse object for FindTable */ Parse *pSaved = db->pParse; memset(&sParse, 0, sizeof(sParse)); db->pParse = &sParse; |
︙ |
Changes to src/pragma.c.
︙ | |||
1184 1185 1186 1187 1188 1189 1190 | 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 | - + | } break; case PragTyp_INDEX_LIST: if( zRight ){ Index *pIdx; Table *pTab; int i; |
︙ | |||
1273 1274 1275 1276 1277 1278 1279 | 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 | - + | #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */ #ifndef SQLITE_OMIT_FOREIGN_KEY case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ FKey *pFK; Table *pTab; |
︙ | |||
1343 1344 1345 1346 1347 1348 1349 | 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 | - + | iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema); sqlite3CodeVerifySchema(pParse, iTabDb); sqlite3TableLock(pParse, iTabDb, pTab->tnum, 0, pTab->zName); if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; sqlite3OpenTable(pParse, 0, iTabDb, pTab, OP_OpenRead); sqlite3VdbeLoadString(v, regResult, pTab->zName); for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
︙ | |||
1365 1366 1367 1368 1369 1370 1371 | 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 | - + | } } assert( pParse->nErr>0 || pFK==0 ); if( pFK ) break; if( pParse->nTab<i ) pParse->nTab = i; addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
︙ |
Changes to src/prepare.c.
︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | + + + + + | }else if( pData->pzErrMsg[0]!=0 ){ /* A error message has already been generated. Do not overwrite it */ }else if( pData->mInitFlags & INITFLAG_AlterTable ){ *pData->pzErrMsg = sqlite3DbStrDup(db, zExtra); pData->rc = SQLITE_ERROR; }else if( db->flags & SQLITE_WriteSchema ){ pData->rc = SQLITE_CORRUPT_BKPT; }else if( IsReuseSchema(db) && 0==sqlite3StrNICmp(zExtra, "malformed database schema", 17) ){ pData->rc = SQLITE_CORRUPT_BKPT; *pData->pzErrMsg = sqlite3DbStrDup(db, zExtra); }else{ char *z; if( zObj==0 ) zObj = "?"; z = sqlite3MPrintf(db, "malformed database schema (%s)", zObj); if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra); *pData->pzErrMsg = z; pData->rc = SQLITE_CORRUPT_BKPT; |
︙ |
Changes to src/sqliteInt.h.
︙ | |||
4009 4010 4011 4012 4013 4014 4015 | 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 | - + | #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */ #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */ #define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */ void sqlite3ExprIfTrue(Parse*, Expr*, int, int); void sqlite3ExprIfFalse(Parse*, Expr*, int, int); void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int); |
︙ |
Changes to src/vtab.c.
︙ | |||
715 716 717 718 719 720 721 | 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | - + | */ int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){ int rc = SQLITE_OK; Table *pTab; Module *pMod; const char *zMod; |
︙ | |||
839 840 841 842 843 844 845 | 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | - + | ** ** This call is a no-op if zTab is not a virtual table. */ int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ int rc = SQLITE_OK; Table *pTab; |
︙ |
Changes to test/reuse2.test.
︙ | |||
174 175 176 177 178 179 180 | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | - + | } {nref=2 nschema=1 ndelete=0} do_execsql_test -db db2 4.1.7 { SELECT * FROM x1 } do_execsql_test 4.1.8 { SELECT 'nref=' || nRef, 'nschema=' || nSchema, 'ndelete=' || nDelete FROM schemapool; |
︙ |
Changes to test/reuse3.test.
︙ | |||
78 79 80 81 82 83 84 | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | - + - + | UPDATE sqlite_master SET sql = 'CREATE TBL y1(d, e, f)' WHERE name = 'y1'; } db close sqlite3 db test.db -shared-schema 1 do_catchsql_test 2.1 { SELECT * FROM x1; |
︙ | |||
236 237 238 239 240 241 242 243 244 245 | 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | + + + + + + + + + + + + + + + + + + + | do_execsql_test 4.2.7 { DROP TRIGGER tr1; SELECT 'nref=' || nRef, 'nschema=' || nSchema, 'ndelete=' || nDelete FROM schemapool; } {nref=5 nschema=1 ndelete=4} #-------------------------------------------------------------------------- reset_db do_execsql_test 5.0 { CREATE TABLE t1(a, b); CREATE TABLE t2(a, b); CREATE TABLE t3(a, b); } sqlite3 db2 test.db -shared-schema 1 register_schemapool_module db2 do_execsql_test 5.1 { PRAGMA writable_schema = 1; UPDATE sqlite_master SET sql='CREATE TABLE t3 a,b' WHERE name = 't3'; } do_test 5.2 { catchsql { SELECT * FROM t1 } db2 } {1 {malformed database schema (t3) - near "a": syntax error}} finish_test |
Changes to test/with3.test.
︙ | |||
26 27 28 29 30 31 32 | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | - + | # do_catchsql_test 1.0 { WITH i(x) AS ( WITH j AS (SELECT 10) SELECT 5 FROM t0 UNION SELECT 8 FROM m ) SELECT * FROM i; |
︙ |