Compare commits

...

6 Commits

Author SHA1 Message Date
drh 12ad19e3a9 Add new interfaces sqlite3_result_pointer(), and
sqlite3_value_pointer() and use them to transfer the eponymous FTS3 column
pointer to the snippet() and offsets() routines.  This changes is
inspired by check-in [72de49f2] but is new implementation, not a cherry-pick.

FossilOrigin-Name: f0f492245e957f5339c5aef02716321e45c18914b9a78387e4158f87fc2d83f9
2017-07-21 03:09:35 +00:00
drh ed7fe4b751 Silently ignore any attempt to add a prefix index for prefixes zero bytes in size to an fts3/4 table. Or any prefix index size so large that it overflows a 32-bit signed integer. Cherrypick [ad4b19d2ac0889a]
FossilOrigin-Name: 000197cc4e3874711388d79d9ad5af6f0aba6cf9
2015-05-21 02:24:35 +00:00
drh c27d1bdb97 Ensure that tables names are dequoted exactly once by the trigger logic.
Cherrypick [59e92bd9521f1e8] and [9d887b92f8086961e].

FossilOrigin-Name: 9e3f64a4f4182ad80e82edb53095ed508e8b1d13
2015-05-21 02:20:47 +00:00
drh ec46983e44 When parsing the schema, ignore any SQL that does not begin
with "CREATE". Cherrypick of [d3c00d61581c] with additional changes.

FossilOrigin-Name: 09784f376b47b6ca539a5106dfa65d8abebe1ef2
2015-05-21 02:07:56 +00:00
drh faab2a699b Do not allow virtual table constructors to be called recursively.
Cherrypick [0a72726da21581ab]

FossilOrigin-Name: 0f0694e4245083f6abb4ce104c39add45f2eb71a
2015-05-21 01:04:17 +00:00
drh 55c7e7f9d6 Add the ".open" command to the command-line shell.
Cherrypick from [21eccb919441].

FossilOrigin-Name: a71e2a72c592f014051a00af9c7cb5c390612cb2
2015-05-21 00:50:37 +00:00
20 changed files with 352 additions and 96 deletions
+16 -10
View File
@@ -920,7 +920,6 @@ static int fts3PrefixParameter(
aIndex = sqlite3_malloc(sizeof(struct Fts3Index) * nIndex);
*apIndex = aIndex;
*pnIndex = nIndex;
if( !aIndex ){
return SQLITE_NOMEM;
}
@@ -932,11 +931,17 @@ static int fts3PrefixParameter(
for(i=1; i<nIndex; i++){
int nPrefix;
if( fts3GobbleInt(&p, &nPrefix) ) return SQLITE_ERROR;
aIndex[i].nPrefix = nPrefix;
if( nPrefix<=0 ){
nIndex--;
i--;
}else{
aIndex[i].nPrefix = nPrefix;
}
p++;
}
}
*pnIndex = nIndex;
return SQLITE_OK;
}
@@ -971,7 +976,8 @@ static int fts3ContentColumns(
const char *zTbl, /* Name of content table */
const char ***pazCol, /* OUT: Malloc'd array of column names */
int *pnCol, /* OUT: Size of array *pazCol */
int *pnStr /* OUT: Bytes of string content */
int *pnStr, /* OUT: Bytes of string content */
char **pzErr /* OUT: error message */
){
int rc = SQLITE_OK; /* Return code */
char *zSql; /* "SELECT *" statement on zTbl */
@@ -982,6 +988,9 @@ static int fts3ContentColumns(
rc = SQLITE_NOMEM;
}else{
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
if( rc!=SQLITE_OK ){
*pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
}
}
sqlite3_free(zSql);
@@ -1215,7 +1224,7 @@ static int fts3InitVtab(
if( nCol==0 ){
sqlite3_free((void*)aCol);
aCol = 0;
rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr);
/* If a languageid= option was specified, remove the language id
** column from the aCol[] array. */
@@ -3058,7 +3067,7 @@ static int fts3ColumnMethod(
}else if( iCol==p->nColumn ){
/* The extra column whose name is the same as the table.
** Return a blob which is a pointer to the cursor. */
sqlite3_result_blob(pCtx, &pCsr, sizeof(pCsr), SQLITE_TRANSIENT);
sqlite3_result_pointer(pCtx, pCsr);
}else if( iCol==p->nColumn+2 && pCsr->pExpr ){
sqlite3_result_int64(pCtx, pCsr->iLangid);
}else{
@@ -3185,16 +3194,13 @@ static int fts3FunctionArg(
sqlite3_value *pVal, /* argv[0] passed to function */
Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
){
Fts3Cursor *pRet;
if( sqlite3_value_type(pVal)!=SQLITE_BLOB
|| sqlite3_value_bytes(pVal)!=sizeof(Fts3Cursor *)
){
Fts3Cursor *pRet = (Fts3Cursor*)sqlite3_value_pointer(pVal);
if( pRet==0 ){
char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
sqlite3_result_error(pContext, zErr, -1);
sqlite3_free(zErr);
return SQLITE_ERROR;
}
memcpy(&pRet, sqlite3_value_blob(pVal), sizeof(Fts3Cursor *));
*ppCsr = pRet;
return SQLITE_OK;
}
+23 -24
View File
@@ -1,5 +1,5 @@
C Version\s3.7.11
D 2012-03-20T11:35:50.522
C Add\snew\sinterfaces\ssqlite3_result_pointer(),\sand\nsqlite3_value_pointer()\sand\suse\sthem\sto\stransfer\sthe\seponymous\sFTS3\scolumn\npointer\sto\sthe\ssnippet()\sand\soffsets()\sroutines.\s\sThis\schanges\sis\ninspired\sby\scheck-in\s[72de49f2]\sbut\sis\snew\simplementation,\snot\sa\scherry-pick.
D 2017-07-21T03:09:35.560
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2f37e468503dbe79d35c9f6dffcf3fae1ae9ec20
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -63,7 +63,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51
F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a
F ext/fts3/README.tokenizers 998756696647400de63d5ba60e9655036cb966e9
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
F ext/fts3/fts3.c a62e09140c00f9c401efca661e7f2ae9909194f6
F ext/fts3/fts3.c eca471e5a9c5b13efbd97f67cec501e666320d1e93d0851226356e289edbf545
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
F ext/fts3/fts3Int.h d1d7f964ddee067bcd16a6af4ba7ecf66220056d
F ext/fts3/fts3_aux.c 5205182bd8f372782597888156404766edf5781e
@@ -136,7 +136,7 @@ F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4
F src/delete.c 51d32f0a9c880663e54ce309f52e40c325d5e112
F src/expr.c 00675123e0beec98f999aa4594d2cbe1fec33c1b
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c 657212460bf5cfd3ae607d12ea62092844c227b5
F src/fkey.c 46f9dc13b4f3e8f9659d31e71cd5f76c8ae465cc
F src/func.c e75f41c421f00762ab9da7dc8fb90af3972cf99f
F src/global.c 4cfdca5cb0edd33c4d021baec4ede958cb2c793b
F src/hash.c 458488dcc159c301b8e7686280ab209f1fb915af
@@ -175,16 +175,16 @@ F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
F src/pcache.h 1b5dcc3dc8103d03e625b177023ee67764fa6b7c
F src/pcache1.c b30b1c35908346ecc43d8d9d17f2ddf6817f8f60
F src/pragma.c e708b3bb5704605816f617e0b1d63a5488060715
F src/prepare.c ec4989f7f480544bdc4192fe663470d2a2d7d61e
F src/prepare.c 5db3bd35634cf1e615e2015f92f2d6b96e20ca8b
F src/printf.c 7ffb4ebb8b341f67e049695ba031da717b3d2699
F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
F src/resolve.c 3d3e80a98f203ac6b9329e9621e29eda85ddfd40
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
F src/select.c 44ccdcb5d2a1c48622c179b2d72167b716388581
F src/shell.c aa28f117033ba3e44b5eaaf2ad572222bcdfd66e
F src/sqlite.h.in 6af2d92925bfed3dfd2c022fef48469762ccd435
F src/shell.c a31c37ed0959173dce7a565359e6372c68aa0268
F src/sqlite.h.in fe9d87c4e45203ddffa508f14ab39932ba6efdfae1c8fcb1bfbc04170fb9eeaf
F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477
F src/sqliteInt.h e65429a6f19b41720561b9434b2192574a91cfa2
F src/sqliteInt.h ce9a4d64a183a0d3500123445a905607abaeb0a1
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 4568e72dfd36b6a5911f93457364deb072e0b03a
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -235,21 +235,21 @@ F src/test_vfstrace.c 6b28adb2a0e8ecd0f2e3581482e1f658b11b4067
F src/test_wholenumber.c 6129adfbe7c7444f2e60cc785927f3aa74e12290
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/tokenize.c 1e86210d3976717a19238ea7b047fac481fe8c12
F src/trigger.c ee7e178fb9188f44b532cebd449a7c1df90fb684
F src/trigger.c bc7f94ec7a5e0067846acb0691996812a00336ca
F src/update.c d3076782c887c10e882996550345da9c4c9f9dea
F src/utf.c 890c67dcfcc7a74623c95baac7535aadfe265e84
F src/util.c 4f6cfad661b2e3454b0cdd5b1b9d39a54942d0e3
F src/vacuum.c bfd53f9bd20a8fdb70b0fa8e77182b866875c0d8
F src/vdbe.c 32720e873ed0a23e6ee928b676cd995864b984d6
F src/vdbe.h 18f581cac1f4339ec3299f3e0cc6e11aec654cdb
F src/vdbeInt.h 6ff4180a05683566a8835d12f7ec504b22932c82
F src/vdbeapi.c 3662b6a468a2a4605a15dfab313baa6dff81ad91
F src/vdbeInt.h 0fb63a812b973f2f845de68f82b552a7e4f9d3ac28602da448a7a4c0ad58c477
F src/vdbeapi.c ac2f07c42b18ad3f5703a8bd3c5102549676594c154e0e49cca3adf5b9f75651
F src/vdbeaux.c 79cf42b70e211a52d664fc4d585ee2da0a64deac
F src/vdbeblob.c 32f2a4899d67f69634ea4dd93e3f651936d732cb
F src/vdbemem.c fb0ac964ccbcd94f595eb993c05bfd9c52468a4a
F src/vdbesort.c b25814d385895544ebc8118245c8311ded7f81c9
F src/vdbetrace.c d6e50e04e1ec498150e519058f617d91b8f5c843
F src/vtab.c ab90fb600a3f5e4b7c48d22a4cdb2d6b23239847
F src/vtab.c a078fb78c0f7bfa4a365495badf53581d512b648
F src/wal.c 7bb3ad807afc7973406c805d5157ec7a2f65e146
F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
@@ -263,7 +263,7 @@ F test/alter2.test 7ea05c7d92ac99349a802ef7ada17294dd647060
F test/alter3.test 49c9d9fba2b8fcdce2dedeca97bbf1f369cc548d
F test/alter4.test b2debc14d8cbe4c1d12ccd6a41eef88a8c1f15d5
F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
F test/analyze.test f8ab7d15858b4093b06caf5e57e2a5ff7104bdae
F test/analyze.test 6f5feb496ce728cec33289630bc713d6e40a311e
F test/analyze3.test c3c7f6c3951900c188cf94b2d5ee3246d6b3ff89
F test/analyze4.test 757b37875cf9bb528d46f74497bc789c88365045
F test/analyze5.test 713354664c5ff1853ab2cbcb740f0cf5cb7c802e
@@ -384,7 +384,7 @@ F test/e_expr.test 5489424d3d9a452ac3701cdf4b680ae31a157894
F test/e_fkey.test 057eed81a41a2b21b1790032f4e8aaba0b2b0e17
F test/e_fts3.test 5c02288842e4f941896fd44afdef564dd5fc1459
F test/e_insert.test c6ac239a97cb16dfbd0c16496f8cd871b4068c0c
F test/e_reindex.test dfedfc32c5a282b0596c6537cbcd4217fbb1a216
F test/e_reindex.test ce2d2b773144c9b8de9e5f6d8ab26c8cdf5ba115
F test/e_resolve.test dcce9308fb13b934ce29591105d031d3e14fbba6
F test/e_select.test f5d4b81205701deacfae42051ae200969c41d2c0
F test/e_select2.test 5c3d3da19c7b3e90ae444579db2b70098599ab92
@@ -406,7 +406,7 @@ F test/expr.test 67c9fd6f8f829e239dc8b0f4a08a73c08b09196d
F test/fallocate.test b5d34437bd7ab01d41b1464b8117aefd4d32160e
F test/filectrl.test f0327bd804d9c7bd048fa7a151c5eab8e27df42b
F test/filefmt.test ffa17b5aebc3eb4b1e3be1ccb5ee906ffbd97f6e
F test/fkey1.test 01c7de578e11747e720c2d9aeef27f239853c4da
F test/fkey1.test fcaff62ae3c4322ba39bf01ee07944b72bccc76b
F test/fkey2.test 080969fe219b3b082b0e097ac18c6af2e5b0631f
F test/fkey3.test 5ec899d12b13bcf1e9ef40eff7fb692fdb91392e
F test/fkey4.test c6c8f9f9be885f95c85c7bceb26f243ad906fd49
@@ -487,7 +487,7 @@ F test/fts3first.test dbdedd20914c8d539aa3206c9b34a23775644641
F test/fts3malloc.test b86ea33db9e8c58c0c2f8027a9fcadaf6a1568be
F test/fts3matchinfo.test 6507fe1c342e542300d65ea637d4110eccf894e6
F test/fts3near.test 2e318ee434d32babd27c167142e2b94ddbab4844
F test/fts3prefix.test b36d4f00b128a51e7b386cc013a874246d9d7dc1
F test/fts3prefix.test 6bd3fc277769a373f90e96c04f8747bee823e4c5
F test/fts3prefix2.test 477ca96e67f60745b7ac931cfa6e9b080c562da5
F test/fts3query.test ef79d31fdb355d094baec1c1b24b60439a1fb8a2
F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0
@@ -495,7 +495,7 @@ F test/fts3shared.test 8bb266521d7c5495c0ae522bb4d376ad5387d4a2
F test/fts3snippet.test 8e956051221a34c7daeb504f023cb54d5fa5a8b2
F test/fts3sort.test 95be0b19d7e41c44b29014f13ea8bddd495fd659
F test/fts4aa.test 6e7f90420b837b2c685f3bcbe84c868492d40a68
F test/fts4content.test 17b2360f7d1a9a7e5aa8022783f5c5731b6dfd4f
F test/fts4content.test 655e5036c98272c93d8ec0eb8c6b7100928faeae
F test/fts4langid.test 2081c357bb6f170f34ef8e08c6abb88002b95c69
F test/func.test 6c5ce11e3a0021ca3c0649234e2d4454c89110ca
F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
@@ -523,7 +523,7 @@ F test/incrvacuum2.test 379eeb8740b0ef60c372c439ad4cbea20b34bb9b
F test/incrvacuum_ioerr.test 22f208d01c528403240e05beecc41dc98ed01637
F test/index.test b5429732b3b983fa810e3ac867d7ca85dae35097
F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
F test/index3.test 423a25c789fc8cc51aaf2a4370bbdde2d9e9eed7
F test/index3.test 8bbf1f05e8104ffbe663666e1516991e72e4cb29
F test/index4.test 2983216eb8c86ee62d9ed7cb206b5cc3331c0026
F test/indexedby.test be501e381b82b2f8ab406309ba7aac46e221f4ad
F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d
@@ -865,12 +865,12 @@ F test/trigger3.test d2c60d8be271c355d61727411e753181e877230a
F test/trigger4.test 74700b76ebf3947b2f7a92405141eb2cf2a5d359
F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83
F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9
F test/trigger7.test b39e6dee1debe0ff9c2ef66326668f149f07c9c4
F test/trigger7.test 200dd51e728c9cdc20c72d99d9e9d45c667248f8
F test/trigger8.test 30cb0530bd7c4728055420e3f739aa00412eafa4
F test/trigger9.test 5b0789f1c5c4600961f8e68511b825b87be53e31
F test/triggerA.test e0aaba16d3547193d36bbd82a1b0ed75e9c88d40
F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe
F test/triggerC.test 4d4bdaf0230c206b50d350330107ef9802bc2d4f
F test/triggerC.test a8fad3c4c87beb69c4e73497f8bde7285af9285f
F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650
F test/tt3_checkpoint.c 415eccce672d681b297485fc20f44cdf0eac93af
F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff
@@ -992,8 +992,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
P 7b449b301ea03295262b8d572b02625e4b39cfa5
R 4ef201d6122aecff56466ef062fb4020
T +sym-version-3.7.11 *
P 000197cc4e3874711388d79d9ad5af6f0aba6cf9
R 216f1f59a17a7632e354caa909677e48
U drh
Z 8740abf5f4801e70716f6cff3569cf87
Z 5a09f7760c2f0f7c70af841ad176b2e0
+1 -1
View File
@@ -1 +1 @@
00bb9c9ce4f465e6ac321ced2a9d0062dc364669
f0f492245e957f5339c5aef02716321e45c18914b9a78387e4158f87fc2d83f9
+12 -13
View File
@@ -1018,10 +1018,10 @@ static Trigger *fkActionTrigger(
** parent table are used for the comparison. */
pEq = sqlite3PExpr(pParse, TK_EQ,
sqlite3PExpr(pParse, TK_DOT,
sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
, 0),
sqlite3PExpr(pParse, TK_ID, 0, 0, &tFromCol)
sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
, 0);
pWhere = sqlite3ExprAnd(db, pWhere, pEq);
@@ -1033,12 +1033,12 @@ static Trigger *fkActionTrigger(
if( pChanges ){
pEq = sqlite3PExpr(pParse, TK_IS,
sqlite3PExpr(pParse, TK_DOT,
sqlite3PExpr(pParse, TK_ID, 0, 0, &tOld),
sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
0),
sqlite3PExpr(pParse, TK_DOT,
sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol),
sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
0),
0);
pWhen = sqlite3ExprAnd(db, pWhen, pEq);
@@ -1048,8 +1048,8 @@ static Trigger *fkActionTrigger(
Expr *pNew;
if( action==OE_Cascade ){
pNew = sqlite3PExpr(pParse, TK_DOT,
sqlite3PExpr(pParse, TK_ID, 0, 0, &tNew),
sqlite3PExpr(pParse, TK_ID, 0, 0, &tToCol)
sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
, 0);
}else if( action==OE_SetDflt ){
Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
@@ -1096,13 +1096,12 @@ static Trigger *fkActionTrigger(
pTrigger = (Trigger *)sqlite3DbMallocZero(db,
sizeof(Trigger) + /* struct Trigger */
sizeof(TriggerStep) + /* Single step in trigger program */
nFrom + 1 /* Space for pStep->target.z */
nFrom + 1 /* Space for pStep->zTarget */
);
if( pTrigger ){
pStep = pTrigger->step_list = (TriggerStep *)&pTrigger[1];
pStep->target.z = (char *)&pStep[1];
pStep->target.n = nFrom;
memcpy((char *)pStep->target.z, zFrom, nFrom);
pStep->zTarget = (char *)&pStep[1];
memcpy((char *)pStep->zTarget, zFrom, nFrom);
pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
+3 -3
View File
@@ -67,7 +67,7 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
if( argv[1]==0 ){
corruptSchema(pData, argv[0], 0);
}else if( argv[2] && argv[2][0] ){
}else if( argv[2] && sqlite3_strnicmp(argv[2],"create ",7)==0 ){
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
** But because db->init.busy is set to 1, no VDBE code is generated
** or executed. All the parser does is build the internal data
@@ -98,8 +98,8 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){
}
}
sqlite3_finalize(pStmt);
}else if( argv[0]==0 ){
corruptSchema(pData, 0, 0);
}else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){
corruptSchema(pData, argv[0], 0);
}else{
/* If the SQL column is blank it means this is an index that
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
+41 -17
View File
@@ -434,6 +434,7 @@ struct callback_data {
** .explain ON */
char outfile[FILENAME_MAX]; /* Filename for *out */
const char *zDbFilename; /* name of the database file */
char *zFreeOnClose; /* Filename to free when closing */
const char *zVfs; /* Name of VFS to use */
sqlite3_stmt *pStmt; /* Current statement if any. */
FILE *pLog; /* Write log output here */
@@ -1416,6 +1417,7 @@ static char zHelp[] =
" tabs Tab-separated values\n"
" tcl TCL list elements\n"
".nullvalue STRING Print STRING in place of NULL values\n"
".open ?FILENAME? Close existing database and reopen FILENAME\n"
".output FILENAME Send output to FILENAME\n"
".output stdout Send output to the screen\n"
".prompt MAIN CONTINUE Replace the standard prompts\n"
@@ -1447,7 +1449,7 @@ static int process_input(struct callback_data *p, FILE *in);
** Make sure the database is open. If it is not, then open it. If
** the database fails to open, print an error message and exit.
*/
static void open_db(struct callback_data *p){
static void open_db(struct callback_data *p, int keepAlive){
if( p->db==0 ){
sqlite3_open(p->zDbFilename, &p->db);
db = p->db;
@@ -1458,6 +1460,7 @@ static void open_db(struct callback_data *p){
if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
p->zDbFilename, sqlite3_errmsg(db));
if( keepAlive ) return;
exit(1);
}
#ifndef SQLITE_OMIT_LOAD_EXTENSION
@@ -1578,7 +1581,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
sqlite3_close(pDest);
return 1;
}
open_db(p);
open_db(p, 0);
pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
if( pBackup==0 ){
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
@@ -1603,7 +1606,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
struct callback_data data;
char *zErrMsg = 0;
open_db(p);
open_db(p, 0);
memcpy(&data, p, sizeof(data));
data.showHeader = 1;
data.mode = MODE_Column;
@@ -1620,7 +1623,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
}else
if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
open_db(p);
open_db(p, 0);
/* When playing back a "dump", the content might appear in an order
** which causes immediate foreign key constraints to be violated.
** So disable foreign-key constraint enforcement to prevent problems. */
@@ -1738,7 +1741,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
FILE *in; /* The input file */
int lineno = 0; /* Line number of input file */
open_db(p);
open_db(p, 0);
nSep = strlen30(p->separator);
if( nSep==0 ){
fprintf(stderr, "Error: non-null separator required for import\n");
@@ -1853,7 +1856,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
struct callback_data data;
char *zErrMsg = 0;
open_db(p);
open_db(p, 0);
memcpy(&data, p, sizeof(data));
data.showHeader = 0;
data.mode = MODE_List;
@@ -1919,7 +1922,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
char *zErrMsg = 0;
zFile = azArg[1];
zProc = nArg>=3 ? azArg[2] : 0;
open_db(p);
open_db(p, 0);
rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "Error: %s\n", zErrMsg);
@@ -1998,6 +2001,26 @@ static int do_meta_command(char *zLine, struct callback_data *p){
"%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
}else
if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
sqlite3 *savedDb = p->db;
const char *zSavedFilename = p->zDbFilename;
char *zNewFilename = 0;
p->db = 0;
if( nArg>=2 ){
p->zDbFilename = zNewFilename = sqlite3_mprintf("%s", azArg[1]);
}
open_db(p, 1);
if( p->db!=0 ){
sqlite3_close(savedDb);
sqlite3_free(p->zFreeOnClose);
p->zFreeOnClose = zNewFilename;
}else{
sqlite3_free(zNewFilename);
p->db = savedDb;
p->zDbFilename = zSavedFilename;
}
}else
if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
if( p->out!=stdout ){
fclose(p->out);
@@ -2061,7 +2084,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
sqlite3_close(pSrc);
return 1;
}
open_db(p);
open_db(p, 0);
pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
if( pBackup==0 ){
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
@@ -2091,7 +2114,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){
struct callback_data data;
char *zErrMsg = 0;
open_db(p);
open_db(p, 0);
memcpy(&data, p, sizeof(data));
data.showHeader = 0;
data.mode = MODE_Semi;
@@ -2197,7 +2220,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
char **azResult;
int nRow;
char *zErrMsg;
open_db(p);
open_db(p, 0);
if( nArg==1 ){
rc = sqlite3_get_table(p->db,
"SELECT name FROM sqlite_master "
@@ -2273,7 +2296,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
int testctrl = -1;
int rc = 0;
int i, n;
open_db(p);
open_db(p, 0);
/* convert testctrl text option to value. allow any unique prefix
** of the option name, or a numerical value. */
@@ -2372,7 +2395,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
}else
if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
open_db(p);
open_db(p, 0);
sqlite3_busy_timeout(p->db, atoi(azArg[1]));
}else
@@ -2381,7 +2404,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
){
enableTimer = booleanValue(azArg[1]);
}else
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
printf("SQLite %s %s\n" /*extra-version-info*/,
sqlite3_libversion(), sqlite3_sourceid());
@@ -2555,7 +2578,7 @@ static int process_input(struct callback_data *p, FILE *in){
if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
&& sqlite3_complete(zSql) ){
p->cnt = 0;
open_db(p);
open_db(p, 0);
BEGIN_TIMER;
rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
END_TIMER;
@@ -2883,7 +2906,7 @@ int main(int argc, char **argv){
** to the sqlite command-line tool.
*/
if( access(data.zDbFilename, 0)==0 ){
open_db(&data);
open_db(&data, 0);
}
/* Process the initialization file if there is one. If no -init option
@@ -2975,7 +2998,7 @@ int main(int argc, char **argv){
rc = do_meta_command(z, &data);
if( rc && bail_on_error ) return rc;
}else{
open_db(&data);
open_db(&data, 0);
rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
if( zErrMsg!=0 ){
fprintf(stderr,"Error: %s\n", zErrMsg);
@@ -2998,7 +3021,7 @@ int main(int argc, char **argv){
if( zFirstCmd[0]=='.' ){
rc = do_meta_command(zFirstCmd, &data);
}else{
open_db(&data);
open_db(&data, 0);
rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
if( zErrMsg!=0 ){
fprintf(stderr,"Error: %s\n", zErrMsg);
@@ -3046,5 +3069,6 @@ int main(int argc, char **argv){
if( data.db ){
sqlite3_close(data.db);
}
sqlite3_free(data.zFreeOnClose);
return rc;
}
+2
View File
@@ -3945,6 +3945,7 @@ int sqlite3_value_bytes16(sqlite3_value*);
double sqlite3_value_double(sqlite3_value*);
int sqlite3_value_int(sqlite3_value*);
sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
void *sqlite3_value_pointer(sqlite3_value*);
const unsigned char *sqlite3_value_text(sqlite3_value*);
const void *sqlite3_value_text16(sqlite3_value*);
const void *sqlite3_value_text16le(sqlite3_value*);
@@ -4202,6 +4203,7 @@ void sqlite3_result_error_code(sqlite3_context*, int);
void sqlite3_result_int(sqlite3_context*, int);
void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
void sqlite3_result_null(sqlite3_context*);
void sqlite3_result_pointer(sqlite3_context*, void*);
void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
+5 -5
View File
@@ -2341,7 +2341,7 @@ struct Trigger {
* orconf -> stores the ON CONFLICT algorithm
* pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
* this stores a pointer to the SELECT statement. Otherwise NULL.
* target -> A token holding the quoted name of the table to insert into.
* zTarget -> Dequoted name of the table to insert into.
* pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
* this stores values to be inserted. Otherwise NULL.
* pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
@@ -2349,12 +2349,12 @@ struct Trigger {
* inserted into.
*
* (op == TK_DELETE)
* target -> A token holding the quoted name of the table to delete from.
* zTarget -> Dequoted name of the table to delete from.
* pWhere -> The WHERE clause of the DELETE statement if one is specified.
* Otherwise NULL.
*
* (op == TK_UPDATE)
* target -> A token holding the quoted name of the table to update rows of.
* zTarget -> Dequoted name of the table to update.
* pWhere -> The WHERE clause of the UPDATE statement if one is specified.
* Otherwise NULL.
* pExprList -> A list of the columns to update and the expressions to update
@@ -2366,8 +2366,8 @@ struct TriggerStep {
u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
u8 orconf; /* OE_Rollback etc. */
Trigger *pTrig; /* The trigger that this step is a part of */
Select *pSelect; /* SELECT statment or RHS of INSERT INTO .. SELECT ... */
Token target; /* Target table for DELETE, UPDATE, INSERT */
Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
ExprList *pExprList; /* SET clause for UPDATE. VALUES clause for INSERT */
IdList *pIdList; /* Column names for INSERT */
+9 -9
View File
@@ -373,12 +373,12 @@ static TriggerStep *triggerStepAllocate(
){
TriggerStep *pTriggerStep;
pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
if( pTriggerStep ){
char *z = (char*)&pTriggerStep[1];
memcpy(z, pName->z, pName->n);
pTriggerStep->target.z = z;
pTriggerStep->target.n = pName->n;
sqlite3Dequote(z);
pTriggerStep->zTarget = z;
pTriggerStep->op = op;
}
return pTriggerStep;
@@ -667,7 +667,7 @@ Trigger *sqlite3TriggersExist(
}
/*
** Convert the pStep->target token into a SrcList and return a pointer
** Convert the pStep->zTarget string into a SrcList and return a pointer
** to that SrcList.
**
** This routine adds a specific database name, if needed, to the target when
@@ -680,17 +680,17 @@ static SrcList *targetSrcList(
Parse *pParse, /* The parsing context */
TriggerStep *pStep /* The trigger containing the target token */
){
sqlite3 *db = pParse->db;
int iDb; /* Index of the database to use */
SrcList *pSrc; /* SrcList to be returned */
pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
if( pSrc ){
assert( pSrc->nSrc>0 );
assert( pSrc->a!=0 );
iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
if( iDb==0 || iDb>=2 ){
sqlite3 *db = pParse->db;
assert( iDb<pParse->db->nDb );
assert( iDb<db->nDb );
pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
}
}
+3 -1
View File
@@ -151,6 +151,7 @@ struct Mem {
union {
i64 i; /* Integer value used when MEM_Int is set in flags */
int nZero; /* Used when bit MEM_Zero is set in flags */
void *pPtr; /* Pointer when flags==MEM_Ptr|MEM_Null */
FuncDef *pDef; /* Used only when flags==MEM_Agg */
RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
@@ -194,6 +195,7 @@ struct Mem {
** policy for Mem.z. The MEM_Term flag tells us whether or not the
** string is \000 or \u0000 terminated
*/
#define MEM_Ptr 0x8000 /* u.pPtr is valid if type==SQLITE_NULL */
#define MEM_Term 0x0200 /* String rep is nul terminated */
#define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
#define MEM_Static 0x0800 /* Mem.z points to a static string */
@@ -209,7 +211,7 @@ struct Mem {
** Clear any existing type flags from a Mem and replace them with f
*/
#define MemSetTypeFlag(p, f) \
((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero|MEM_Ptr))|f)
/*
** Return true if a memory cell is not marked as invalid. This macro
+12
View File
@@ -163,6 +163,11 @@ int sqlite3_value_int(sqlite3_value *pVal){
sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
return sqlite3VdbeIntValue((Mem*)pVal);
}
void *sqlite3_value_pointer(sqlite3_value *pVal){
Mem *p = (Mem*)pVal;
if( (p->flags&(MEM_TypeMask|MEM_Ptr))==(MEM_Null|MEM_Ptr) ) return p->u.pPtr;
return 0;
}
const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
}
@@ -234,6 +239,13 @@ void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){
assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
sqlite3VdbeMemSetInt64(&pCtx->s, iVal);
}
void sqlite3_result_pointer(sqlite3_context *pCtx, void *pPtr){
assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
sqlite3VdbeMemSetNull(&pCtx->s);
assert( (pCtx->s.flags & (MEM_TypeMask|MEM_Ptr))==MEM_Null );
pCtx->s.flags |= MEM_Ptr;
pCtx->s.u.pPtr = pPtr;
}
void sqlite3_result_null(sqlite3_context *pCtx){
assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
sqlite3VdbeMemSetNull(&pCtx->s);
+24 -6
View File
@@ -24,6 +24,8 @@
struct VtabCtx {
Table *pTab;
VTable *pVTable;
VtabCtx *pPrior; /* Parent context (if any) */
int bDeclared; /* True after sqlite3_declare_vtab() is called */
};
/*
@@ -453,8 +455,20 @@ static int vtabCallConstructor(
const char *const*azArg = (const char *const*)pTab->azModuleArg;
int nArg = pTab->nModuleArg;
char *zErr = 0;
char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
char *zModuleName;
VtabCtx *pCtx;
/* Check that the virtual-table is not already being initialized */
for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
if( pCtx->pTab==pTab ){
*pzErr = sqlite3MPrintf(db,
"vtable constructor called recursively: %s", pTab->zName
);
return SQLITE_LOCKED;
}
}
zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
if( !zModuleName ){
return SQLITE_NOMEM;
}
@@ -472,10 +486,13 @@ static int vtabCallConstructor(
assert( xConstruct );
sCtx.pTab = pTab;
sCtx.pVTable = pVTable;
sCtx.pPrior = db->pVtabCtx;
sCtx.bDeclared = 0;
db->pVtabCtx = &sCtx;
rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
db->pVtabCtx = 0;
db->pVtabCtx = sCtx.pPrior;
if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
assert( sCtx.pTab==pTab );
if( SQLITE_OK!=rc ){
if( zErr==0 ){
@@ -490,7 +507,7 @@ static int vtabCallConstructor(
** the sqlite3_vtab object if successful. */
pVTable->pVtab->pModule = pMod->pModule;
pVTable->nRef = 1;
if( sCtx.pTab ){
if( sCtx.bDeclared==0 ){
const char *zFormat = "vtable constructor did not declare schema: %s";
*pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
sqlite3VtabUnlock(pVTable);
@@ -660,18 +677,19 @@ int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
** virtual table module.
*/
int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
VtabCtx *pCtx = db->pVtabCtx;
Parse *pParse;
int rc = SQLITE_OK;
Table *pTab;
char *zErr = 0;
sqlite3_mutex_enter(db->mutex);
if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
if( !pCtx || pCtx->bDeclared ){
sqlite3Error(db, SQLITE_MISUSE, 0);
sqlite3_mutex_leave(db->mutex);
return SQLITE_MISUSE_BKPT;
}
pTab = pCtx->pTab;
assert( (pTab->tabFlags & TF_Virtual)!=0 );
pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
@@ -694,7 +712,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
pParse->pNewTable->nCol = 0;
pParse->pNewTable->aCol = 0;
}
db->pVtabCtx->pTab = 0;
pCtx->bDeclared = 1;
}else{
sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
sqlite3DbFree(db, zErr);
+1 -1
View File
@@ -358,7 +358,7 @@ do_test analyze-99.1 {
catchsql {
ANALYZE
}
} {1 {malformed database schema (sqlite_stat1) - near "nonsense": syntax error}}
} {1 {malformed database schema (sqlite_stat1)}}
finish_test
+5 -2
View File
@@ -48,8 +48,10 @@ do_execsql_test e_reindex-1.1 {
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(3, 4);
INSERT INTO t1 VALUES(5, 6);
CREATE TABLE saved(a,b,c,d,e);
INSERT INTO saved SELECT * FROM sqlite_master WHERE type = 'index';
PRAGMA writable_schema = 1;
UPDATE sqlite_master SET sql = '-- ' || sql WHERE type = 'index';
DELETE FROM sqlite_master WHERE type = 'index';
} {}
db close
@@ -59,7 +61,8 @@ do_execsql_test e_reindex-1.2 {
INSERT INTO t1 VALUES(7, 8);
INSERT INTO t1 VALUES(9, 10);
PRAGMA writable_schema = 1;
UPDATE sqlite_master SET sql = substr(sql, 4) WHERE type = 'index';
INSERT INTO sqlite_master SELECT * FROM saved;
DROP TABLE saved;
} {}
db close
+30
View File
@@ -118,4 +118,34 @@ do_test fkey1-3.4 {
{0 1 t5 e {} {SET DEFAULT} CASCADE NONE} \
]
# Stress the dequoting logic. The first test is not so bad.
do_execsql_test fkey1-4.0 {
PRAGMA foreign_keys=ON;
CREATE TABLE "xx1"("xx2" TEXT PRIMARY KEY, "xx3" TEXT);
INSERT INTO "xx1"("xx2","xx3") VALUES('abc','def');
CREATE TABLE "xx4"("xx5" TEXT REFERENCES "xx1" ON DELETE CASCADE);
INSERT INTO "xx4"("xx5") VALUES('abc');
INSERT INTO "xx1"("xx2","xx3") VALUES('uvw','xyz');
SELECT 1, "xx5" FROM "xx4";
DELETE FROM "xx1";
SELECT 2, "xx5" FROM "xx4";
} {1 abc}
# This case is identical to the previous except the "xx" in each name
# is changed to a single escaped double-quote character.
do_execsql_test fkey1-4.1 {
PRAGMA foreign_keys=ON;
CREATE TABLE """1"("""2" TEXT PRIMARY KEY, """3" TEXT);
INSERT INTO """1"("""2","""3") VALUES('abc','def');
CREATE TABLE """4"("""5" TEXT REFERENCES """1" ON DELETE CASCADE);
INSERT INTO """4"("""5") VALUES('abc');
INSERT INTO """1"("""2","""3") VALUES('uvw','xyz');
SELECT 1, """5" FROM """4";
DELETE FROM """1";
SELECT 2, """5" FROM """4";
} {1 abc}
do_execsql_test fkey1-4.2 {
PRAGMA table_info="""1";
} {0 {"2} TEXT 0 {} 1 1 {"3} TEXT 0 {} 0}
finish_test
+64
View File
@@ -209,5 +209,69 @@ do_catchsql_test 5.1 {
do_catchsql_test 5.2 {
CREATE VIRTUAL TABLE t4 USING fts4(prefix="");
} {0 {}}
do_catchsql_test 5.3 {
CREATE VIRTUAL TABLE t5 USING fts4(prefix="-1");
} {1 {error parsing prefix parameter: -1}}
#-------------------------------------------------------------------------
# Prefix indexes of size 0 are ignored. Demonstrate this by showing that
# adding prefix=0 does not change the contents of the %_segdir table.
#
reset_db
do_execsql_test 6.1.1 {
CREATE VIRTUAL TABLE t1 USING fts4(prefix=0);
CREATE VIRTUAL TABLE t2 USING fts4;
INSERT INTO t1 VALUES('Twas Mulga Bill, from Eaglehawk, ');
INSERT INTO t2 VALUES('Twas Mulga Bill, from Eaglehawk, ');
} {}
do_execsql_test 6.1.2 {
SELECT md5sum(quote(root)) FROM t1_segdir;
} [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}]
reset_db
do_execsql_test 6.2.1 {
CREATE VIRTUAL TABLE t1 USING fts4(prefix="1,0,2");
CREATE VIRTUAL TABLE t2 USING fts4(prefix="1,2");
INSERT INTO t1 VALUES('that caught the cycling craze;');
INSERT INTO t2 VALUES('that caught the cycling craze;');
} {}
do_execsql_test 6.2.2 {
SELECT md5sum(quote(root)) FROM t1_segdir;
} [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}]
reset_db
do_execsql_test 6.3.1 {
CREATE VIRTUAL TABLE t1 USING fts4(prefix="1,3,2");
CREATE VIRTUAL TABLE t2 USING fts4(prefix="1,2");
INSERT INTO t1 VALUES('He turned away the good old horse');
INSERT INTO t2 VALUES('He turned away the good old horse');
} {}
do_test 6.3.2 {
set one [db eval {SELECT md5sum(quote(root)) FROM t1_segdir}]
set two [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}]
expr {$one == $two}
} 0
reset_db
do_execsql_test 6.4.1 {
CREATE VIRTUAL TABLE t1 USING fts4(prefix="1,600,2");
CREATE VIRTUAL TABLE t2 USING fts4(prefix="1,2");
INSERT INTO t1 VALUES('that served him many days;');
INSERT INTO t2 VALUES('that served him many days;');
} {}
do_execsql_test 6.4.2 {
SELECT md5sum(quote(root)) FROM t1_segdir;
} [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}]
reset_db
do_execsql_test 6.5.1 {
CREATE VIRTUAL TABLE t1 USING fts4(prefix="2147483647,2147483648,2147483649");
CREATE VIRTUAL TABLE t2 USING fts4(prefix="");
INSERT INTO t1 VALUES('He dressed himself in cycling clothes');
INSERT INTO t2 VALUES('He dressed himself in cycling clothes');
} {}
do_execsql_test 6.5.2 {
SELECT md5sum(quote(root)) FROM t1_segdir;
} [db eval {SELECT md5sum(quote(root)) FROM t2_segdir}]
finish_test
+50 -2
View File
@@ -46,6 +46,9 @@ ifcapable !fts3 {
# 8.* - Test that if the content=xxx and prefix options are used together,
# the 'rebuild' command still works.
#
# 11.* - Test that circular references (e.g. "t1(content=t1)") are
# detected.
#
do_execsql_test 1.1.1 {
CREATE TABLE t1(a, b, c);
@@ -404,7 +407,7 @@ do_execsql_test 5.1.7 {
#
do_catchsql_test 6.1.1 {
CREATE VIRTUAL TABLE ft7 USING fts4(content=t7);
} {1 {vtable constructor failed: ft7}}
} {1 {no such table: main.t7}}
do_execsql_test 6.2.1 {
CREATE TABLE t7(one, two);
@@ -431,7 +434,7 @@ do_execsql_test 6.2.3 {
}
do_catchsql_test 6.2.4 {
SELECT * FROM ft7;
} {1 {vtable constructor failed: ft7}}
} {1 {no such table: main.t7}}
do_execsql_test 6.2.5 {
CREATE TABLE t7(x, y);
INSERT INTO t7 VALUES('A B', 'B A');
@@ -522,4 +525,49 @@ do_execsql_test 8.4 { SELECT rowid FROM ft10 WHERE a MATCH 'ab*'; } {1 2 3}
do_execsql_test 8.5 { SELECT rowid FROM ft10 WHERE b MATCH 'abav*'; } {3}
do_execsql_test 8.6 { SELECT rowid FROM ft10 WHERE ft10 MATCH 'abas*'; } {1}
#-------------------------------------------------------------------------
# Test cases 9.*
#
reset_db
register_echo_module [sqlite3_connection_pointer db]
do_execsql_test 9.1 {
CREATE TABLE tbl1(a, b);
INSERT INTO tbl1 VALUES('a b', 'c d');
INSERT INTO tbl1 VALUES('e f', 'a b');
CREATE VIRTUAL TABLE e1 USING echo(tbl1);
CREATE VIRTUAL TABLE ft1 USING fts4(content=e1);
INSERT INTO ft1(ft1) VALUES('rebuild');
}
do_execsql_test 9.2 {
SELECT rowid, * FROM ft1 WHERE ft1 MATCH 'e'
} {2 {e f} {a b}}
do_execsql_test 9.3 {
SELECT rowid, * FROM ft1 WHERE ft1 MATCH 'a'
} {1 {a b} {c d} 2 {e f} {a b}}
do_execsql_test 9.4 {
DELETE FROM ft1 WHERE docid=1;
}
do_execsql_test 9.5 {
SELECT rowid, * FROM ft1 WHERE ft1 MATCH 'a'
} {2 {e f} {a b}}
do_execsql_test 9.6 {
INSERT INTO ft1(ft1) VALUES('rebuild');
SELECT rowid, * FROM ft1 WHERE ft1 MATCH 'a'
} {1 {a b} {c d} 2 {e f} {a b}}
#-------------------------------------------------------------------------
# Test cases 11.*
#
reset_db
do_catchsql_test 11.1 {
CREATE VIRTUAL TABLE x1 USING fts4(content=x1);
} {1 {vtable constructor called recursively: x1}}
finish_test
+1 -1
View File
@@ -51,6 +51,6 @@ do_test index3-99.1 {
db close
catch { sqlite3 db test.db }
catchsql { DROP INDEX i1 }
} {1 {malformed database schema (t1) - near "nonsense": syntax error}}
} {1 {malformed database schema (t1)}}
finish_test
+1 -1
View File
@@ -114,6 +114,6 @@ do_test trigger7-99.1 {
db close
catch { sqlite3 db test.db }
catchsql { DROP TRIGGER t2r5 }
} {1 {malformed database schema (t2r12) - near "nonsense": syntax error}}
} {1 {malformed database schema (t2r12)}}
finish_test
+49
View File
@@ -12,6 +12,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix triggerC
ifcapable {!trigger} {
finish_test
return
@@ -951,4 +952,52 @@ do_catchsql_test triggerC-13.2 {
#-------------------------------------------------------------------------
# Check that table names used by trigger programs are dequoted exactly
# once.
#
do_execsql_test 15.1.1 {
PRAGMA recursive_triggers = 1;
CREATE TABLE node(
id int not null primary key,
pid int not null default 0 references node,
key varchar not null,
path varchar default '',
unique(pid, key)
);
CREATE TRIGGER node_delete_referencing AFTER DELETE ON "node"
BEGIN
DELETE FROM "node" WHERE pid = old."id";
END;
}
do_execsql_test 15.1.2 {
INSERT INTO node(id, pid, key) VALUES(9, 0, 'test');
INSERT INTO node(id, pid, key) VALUES(90, 9, 'test1');
INSERT INTO node(id, pid, key) VALUES(900, 90, 'test2');
DELETE FROM node WHERE id=9;
SELECT * FROM node;
}
do_execsql_test 15.2.1 {
CREATE TABLE x1 (x);
CREATE TABLE x2 (a, b);
CREATE TABLE '"x2"'(a, b);
INSERT INTO x2 VALUES(1, 2);
INSERT INTO x2 VALUES(3, 4);
INSERT INTO '"x2"' SELECT * FROM x2;
CREATE TRIGGER x1ai AFTER INSERT ON x1 BEGIN
INSERT INTO """x2""" VALUES('x', 'y');
DELETE FROM """x2""" WHERE a=1;
UPDATE """x2""" SET b = 11 WHERE a = 3;
END;
INSERT INTO x1 VALUES('go!');
}
do_execsql_test 15.2.2 { SELECT * FROM x2; } {1 2 3 4}
do_execsql_test 15.2.3 { SELECT * FROM """x2"""; } {3 11 x y}
finish_test