From 53c0f7480b0722ee2a1580fb834a56b44a8aec3b Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Tue, 29 Mar 2005 03:10:59 +0000 Subject: [PATCH] Add the SQLITE_OMIT_TEMPDB compile time macro. (CVS 2427) FossilOrigin-Name: c41d55443c2dd532147962b87f542fb7d37075fd --- manifest | 86 +-- manifest.uuid | 2 +- src/build.c | 39 +- src/main.c | 29 +- src/parse.y | 4 +- src/pragma.c | 4 +- src/sqliteInt.h | 15 +- src/test1.c | 8 +- src/trigger.c | 4 +- src/vdbe.c | 4 +- test/alter.test | 119 ++-- test/alter3.test | 4 +- test/attach.test | 97 ++-- test/attach2.test | 12 +- test/attach3.test | 50 +- test/auth.test | 1096 +++++++++++++++++++------------------ test/autoinc.test | 297 +++++----- test/capi2.test | 6 +- test/func.test | 24 +- test/insert.test | 108 ++-- test/insert2.test | 50 +- test/interrupt.test | 64 +-- test/join4.test | 53 +- test/lastinsert.test | 2 +- test/laststmtchanges.test | 2 +- test/lock.test | 77 +-- test/malloc2.test | 53 +- test/misc1.test | 4 +- test/misc2.test | 86 +-- test/misc4.test | 63 ++- test/pager3.test | 66 +-- test/pragma.test | 64 ++- test/quick.test | 3 +- test/select7.test | 28 +- test/table.test | 18 +- test/temptable.test | 7 +- test/trans.test | 66 ++- test/trigger1.test | 503 +++++++++-------- test/trigger2.test | 23 +- test/vacuum.test | 5 +- 40 files changed, 1755 insertions(+), 1490 deletions(-) diff --git a/manifest b/manifest index 25d504bcfa..391954cbd2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\ssegfault\sdue\sto\sexception\shandler\sbeing\srun\swith\suninitialised\svariable.\s(CVS\s2426) -D 2005-03-29T02:54:03 +C Add\sthe\sSQLITE_OMIT_TEMPDB\scompile\stime\smacro.\s(CVS\s2427) +D 2005-03-29T03:10:59 F Makefile.in 5c00d0037104de2a50ac7647a5f12769795957a3 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -32,7 +32,7 @@ F src/attach.c 3615dbe960cbee4aa5ea300b8a213dad36527b0f F src/auth.c 18c5a0befe20f3a58a41e3ddd78f372faeeefe1f F src/btree.c 50f31eb0844ca14614686163f8939b2999272b25 F src/btree.h 41a71ce027db9ddee72cb43df2316bbe3a1d92af -F src/build.c 2589c2ffa263406526d0cc5728405c6c2f9638f6 +F src/build.c 8afb06c791adcde7787f157bbc55aeef27fb27c1 F src/date.c 2134ef4388256e8247405178df8a61bd60dc180a F src/delete.c d70d54a84695de92efc05b9db7d3684cd21d9094 F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d @@ -42,7 +42,7 @@ F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84 F src/insert.c 34c25c33f51a43644a42cc091ac967b070c6b6d5 F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b -F src/main.c 2062faded47289c50cdbc083e00d1aa9a872f1a1 +F src/main.c 531fab947f72d3b6e86476ed4594838a2fa277f5 F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070 F src/os.h 0c805df3df02b98eb78a7a86756c3cbd4e190939 F src/os_common.h 0e7f428ba0a6c40a61bc56c4e96f493231301b73 @@ -54,28 +54,28 @@ F src/os_win.c 2bbbe6fbb010763c3fa79d5e951afca9b138c6b5 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/pager.c 95e24c9134a00613ca87b963a84ad62d85d5b979 F src/pager.h 9a417a1e04737c227ebbba3bdf8597d6dd51513a -F src/parse.y 10c0ace9efce31d5a06e03488a4284b9d97abc56 -F src/pragma.c 4b20dbc0f4b97f412dc511853d3d0c2e0d4adedc +F src/parse.y 1770b8673c652756b2dd5bcec16f0bf741e5e879 +F src/pragma.c 845c8ab0ab7d09ed2115d3dfc859ba2364b365a7 F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 F src/select.c a324af36afe5f050a1e070806ad3ededf1d58f50 F src/shell.c 25b3217d7c64e6497225439d261a253a23efff26 F src/sqlite.h.in 33e7201f78b3f4aa306d885b69e68fa0f0286368 -F src/sqliteInt.h ecb1592406cf4c684f0ad9ce1bc4fe2a37a61efb +F src/sqliteInt.h 474c20597ee66bb3a666bed0abd76e7be579184a F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9 F src/tclsqlite.c 29e56ecdb94c4066dbe6b088d12cc2404bc9597e -F src/test1.c 13d1d2198b3267c8dc6abd22ada4a992c79acefc +F src/test1.c 32a158ca4aca2e9b43d911eda4552253df9a207d F src/test2.c 7f0ef466706ac01414e1136b96e5d8a65cb97545 F src/test3.c 683e1e3819152ffd35da2f201e507228921148d0 F src/test4.c 7c6b9fc33dd1f3f93c7f1ee6e5e6d016afa6c1df F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5 F src/tokenize.c 103cbaa932c790f540f8eceb63cd3010e117bdff -F src/trigger.c 0c3ec8a6cb7176aaecc3978bfc34050ec1a852c4 +F src/trigger.c 1a6d0c7c51b70bdc58d5068be72034071eff23ad F src/update.c 42823d00865c9fe4f01b3c62647858726345a28e F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c F src/util.c 02bc2750336b021b3f10e61538f665c4b0033b5d F src/vacuum.c 5cf598003191bd91c17a64742bad8e46241698a8 -F src/vdbe.c c7973dc0ab52538646018620e3d3c68aa9e6d6c4 +F src/vdbe.c e93a28aaa2a59c398ae243c2dc3b2da10cf1c5d2 F src/vdbe.h 7f586cb6d6b57764e5aac1f87107d6a95ddce24c F src/vdbeInt.h e80721cd8ff611789e20743eec43363a9fb5a48e F src/vdbeapi.c 467caa6e6fb9247528b1c7ab9132ae1b4748e8ac @@ -84,14 +84,14 @@ F src/vdbemem.c 4e853ce3151eaf7906150da85a1b3ce1fe5e8da8 F src/where.c c4b227458e8993decb515ed9a2fe2d4f5f8e3125 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42 F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3 -F test/alter.test 3a20ce14c3989f7e2e75da50797065c2e56f838b +F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6 F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50 -F test/alter3.test 1e88e71dde15a1c592ca2aba692bf70ff54886f6 -F test/attach.test e6bda19cc954fd84836fadbd70d80134cb17918a -F test/attach2.test 6f3a3a3a7f5be40388dd4d805e0e0712718dca9d -F test/attach3.test c05c70b933afbde0901dab9da3e66ee842c09f38 -F test/auth.test b24d12de3a6ba49237216429f8dc672a8a52b342 -F test/autoinc.test d619da7d5cb9a3d63e6a7925259fc173f7e2080e +F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38 +F test/attach.test f320e98bcca68d100cab7666a0c9a93ac5f236bd +F test/attach2.test 3396c012a39ddf7ba6b528d80bd79554168aa115 +F test/attach3.test 63013383adc4380af69779f34f4af19bd49f7cbe +F test/auth.test 5129bfe268133092ad2928b8644ef97fa4602b2e +F test/autoinc.test bef47b3c1c1093599905d1d9c79140f265896db0 F test/autovacuum.test cf2719b17659f7a011202ad05905654cedf26023 F test/autovacuum_crash.test 05a63b8805b20cfba7ace82856ce4ccdda075a31 F test/autovacuum_ioerr.test 9cf27275ca47b72e188a47c53b61b6d583a01d24 @@ -106,7 +106,7 @@ F test/btree4.test 3797b4305694c7af6828675b0f4b1424b8ca30e4 F test/btree5.test 8e5ff32c02e685d36516c6499add9375fe1377f2 F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027 F test/btree7.test a6d3b842db22af97dd14b989e90a2fd96066b72f -F test/capi2.test 2bd71f573b32e3ac5b97441a55873eae14eeab0d +F test/capi2.test f897209386fb21cfdc9267595e0c667ebaca9164 F test/capi3.test 7c1c91895239fef05427ceb628a193cb4f61031f F test/capi3b.test 5b6a66f9f295f79f443b5d3f33187fa5ef6cf336 F test/collate1.test f79736d2ebf5492167ee4d1f4ab4c09dda776b03 @@ -129,51 +129,51 @@ F test/enc2.test d1ab077b84f4d3099246915422b1ab6b81481e0a F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837 F test/expr.test 54d9d1cc05eb731fa62daa70f2d7163f8a03c54d F test/fkey1.test 81bb13caaa78f58d7d191d7f535529f7c91d821a -F test/func.test 9a467351e2a50c8846623ac7451d3bc2516b6e6d +F test/func.test 7d2d8489bede4495feca427c5efc7b7a2f3b1e94 F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda F test/in.test ed134f8d477a6280297ced1646de83cccf8f196d F test/index.test 51e01a0928b4b61228917ddd8c6c0e2466547f6f F test/index2.test 9ad98243fd7fe833795a9cc662f371f0eed4ff4f F test/index3.test 72bd07b508022db688ec536c460345d24a3912e3 -F test/insert.test 9a9c5774e4cf985d08edfe870d9db20c3849b5d2 -F test/insert2.test 065f179a21b42f9746b97571b8ad10b092e90913 +F test/insert.test 1781f8ec647ef96cadee3d0c63557fd0c16feceb +F test/insert2.test 8d71cb249cfed3803fa77def6336ff0592caffa0 F test/insert3.test c67f0240b1c17e71fa2ed8bb6de064928f549f95 -F test/interrupt.test 5b4d8389e6cf2d01b94f87cfd02d9df1073bfb2d +F test/interrupt.test 170f87c2819f0e56c76e0a754949ea103d05009c F test/intpkey.test ce2a5d91120a831fc076fbf98fce132e192bad69 F test/ioerr.test b27540c5873d28c0e77f02ce85b15f904d5b03a6 F test/join.test e08471279574487cac0d17fa1ea66aca15c4de7f F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 -F test/join4.test cc6cafe85e11aacacd0abcd247a46bed251308f8 +F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19 -F test/lastinsert.test b6a1db3e1ce2d3f0d6afe99d445084f543b6feaa -F test/laststmtchanges.test 07cbdabc52407c29e40abc25050f2434f044a6b1 +F test/lastinsert.test eaa89c6ee1f13062d87139fd32c1e56753d2fd89 +F test/laststmtchanges.test 19a6d0c11f7a31dc45465b495f7b845a62cbec17 F test/limit.test 270b076f31c5c32f7187de5727e74da4de43e477 -F test/lock.test 0b95ae28471f5123d24008d1c0fead911bf3c4be +F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107 F test/lock2.test 59c3dd7d9b24d1bf7ec91b2d1541c37e97939d5f F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9 F test/main.test febb69416071134dc38b9b1971c0c2e5b0ca3ff8 F test/malloc.test b7bc72bb1627e09d6003f58de9bcd6e4be839753 -F test/malloc2.test 5375a1cd53caffd56fd06410c5bddc10f6dccded +F test/malloc2.test 93b07cd12f9776161bc724dbf7b749817e982a49 F test/memdb.test 1860e060be810bf0775bc57408a5b7c4954bcaea F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac F test/minmax.test 9429a06f1f93acf76fcacafd17160a4392e88526 -F test/misc1.test ff817d3740458884fea535b44821ec7e84700457 -F test/misc2.test fc052267d5178367f955538ae34aae1b2f696a92 +F test/misc1.test a4a36c19f05e4c8646efe7a0d7242ba645d07379 +F test/misc2.test d51379cc670b850827cd37b7fc07c0f17736004e F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03 -F test/misc4.test 98e5fb5544aeac6cbbc529c79d4144b0936c22de +F test/misc4.test edd3e3adf5b6e3b995b29843565ca58dd602f9a7 F test/misc5.test 406d3f9523953a028307d076f2eb2687218cb46d F test/misuse.test 1c7fee3c4c0cb4008717ecccf5c72281fac0008e F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0 F test/null.test 69c62daf1630bf54c87bbc7ef2e22012e58d6da8 F test/pager.test 1579e8f07291ae8e24db62ffade5c101c3e76597 F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e -F test/pager3.test 647f696a9cf7409df00a1e0047c2eb55585a1b85 +F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4 F test/pagesize.test 1b826d1608fd86d2303aa895b5586052ad07eba1 -F test/pragma.test 52e4ba758004e2200ff153d09c8b92f19bf940bc +F test/pragma.test effcf2f0dea35223cbaa6bf40c47d0796ba39e40 F test/printf.test 92ba4c510b4fc61120ffa4a01820446ed917ae57 F test/progress.test 16496001da445e6534afb94562c286708316d82f x -F test/quick.test 869345bbe45fdad6e3fcc0fc9ec116c0499530c3 +F test/quick.test e9fdedf06bd06ff22fcbf6895c4f62fcbeb9e6b4 F test/quote.test 6d75cf635d93ba2484dc9cb378d88cbae9dc2c62 F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b F test/rollback.test 94cd981ee3a627d9f6466f69dcf1f7dbfe695d7a @@ -186,22 +186,22 @@ F test/select3.test 9de435aa84fc406708cd8dc1b1d60e7f27cea685 F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca F test/select5.test 2d414f712bff8e590091e08f9b7287600731be00 F test/select6.test 6e5a1a70a788cdbe515d1252dd0917d7e9d1d71e -F test/select7.test 8f3362336c10d828ab6fe9c1b8897b484da8b592 +F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6 F test/sort.test 312eade533cb3c7667110ccfa6e818db1078fd6c F test/subquery.test 6274cce7617bc7f625490759cbe4f0c0eef24895 F test/subselect.test 3f3f7a940dc3195c3139f4d530385cb54665d614 -F test/table.test a2a58cae70ef2511cbf27d40fb8f570106a2677e +F test/table.test e87fb2211b97c6a3a367fbc116e8572091b53160 F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1 F test/tclsqlite.test 4ac312b47632596516353948b59089b02312aed7 -F test/temptable.test 63a16e3ad19adf073cfbcdf7624c92ac5236522c +F test/temptable.test c71eeffe8af807f76eafdc5a39824639a1e301df F test/tester.tcl 69c0dc1accaf0ff26bff62b33e13590a4ecba17d F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35 F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b F test/trace.test a54fa8df0d01cf827289a7659d78959e8fd2f955 -F test/trans.test ab6924a953fd2b262f77ea1aa5f11c05f6a10447 -F test/trigger1.test 9db1a7c91930baa2dc60ce72c7e969900bf2ae8a -F test/trigger2.test cbc8fe3775904d5b49ff26888aa39df7341fae7c +F test/trans.test 10506dc30305cfb8c4098359f7f6f64786f69c5e +F test/trigger1.test 4c68031fbf62966311163586bdb504b168643b49 +F test/trigger2.test f671b922c88f70c3cd2c6f03fe7c256ae7a52fc4 F test/trigger3.test 9102fd3933db294dc654b5aee9edfe9e94f2b9e2 F test/trigger4.test e7c0812b14750754602468f15495260e8c6625e0 F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83 @@ -211,7 +211,7 @@ F test/types2.test 81dd1897be8ef4b5b73d0006e6076abe40610de3 F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf F test/utf16.test 5fb019e09601774743858ef7380b6c02103ff120 -F test/vacuum.test 76c4bc4589353d071e81c003a25338d02560474d +F test/vacuum.test 5d4857ae2afc9c20d0edb8acc58bdc8d630126a9 F test/vacuum2.test 5d77e98c458bcdbeecc6327de5107179ba1aa095 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/view.test 306cc4342eb03c28de1a92c681836189e03e5af9 @@ -278,7 +278,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b -P 4ca11ca015d798655170593c1b76d312185d6ed2 -R e4c51e3e56b7ef33b113201f3420a8cc +P 78df3d040443414ae5b440eeabc0c8c205ab311d +R ab70e88fa1e907bd768a36809abb74cd U danielk1977 -Z 36ddc864efbca1aee674c9701d1319c4 +Z a20882d0dd8ba8be64666597fc85c766 diff --git a/manifest.uuid b/manifest.uuid index 1e1d2a43ab..e120abc78a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -78df3d040443414ae5b440eeabc0c8c205ab311d \ No newline at end of file +c41d55443c2dd532147962b87f542fb7d37075fd \ No newline at end of file diff --git a/src/build.c b/src/build.c index f4b7003c4f..bff72c40c0 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.317 2005/03/28 03:39:56 drh Exp $ +** $Id: build.c,v 1.318 2005/03/29 03:10:59 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -168,7 +168,7 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){ int i; assert( zName!=0 ); assert( (db->flags & SQLITE_Initialized) || db->init.busy ); - for(i=0; inDb; i++){ + for(i=OMIT_TEMPDB; inDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue; p = sqlite3HashFind(&db->aDb[j].tblHash, zName, strlen(zName)+1); @@ -227,7 +227,7 @@ Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){ Index *p = 0; int i; assert( (db->flags & SQLITE_Initialized) || db->init.busy ); - for(i=0; inDb; i++){ + for(i=OMIT_TEMPDB; inDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue; p = sqlite3HashFind(&db->aDb[j].idxHash, zName, strlen(zName)+1); @@ -537,7 +537,8 @@ static int findDb(sqlite3 *db, Token *pName){ if( zName ){ n = strlen(zName); for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){ - if( n==strlen(pDb->zName) && 0==sqlite3StrICmp(pDb->zName, zName) ){ + if( (!OMIT_TEMPDB || i!=1 ) && n==strlen(pDb->zName) && + 0==sqlite3StrICmp(pDb->zName, zName) ){ break; } } @@ -656,12 +657,12 @@ void sqlite3StartTable( */ iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName); if( iDb<0 ) return; - if( isTemp && iDb>1 ){ + if( !OMIT_TEMPDB && isTemp && iDb>1 ){ /* If creating a temp table, the name may not be qualified */ sqlite3ErrorMsg(pParse, "temporary table name must be unqualified"); return; } - if( isTemp ) iDb = 1; + if( !OMIT_TEMPDB && isTemp ) iDb = 1; pParse->sNameToken = *pName; zName = sqlite3NameFromToken(pName); @@ -679,13 +680,13 @@ void sqlite3StartTable( goto begin_table_error; } if( isView ){ - if( isTemp ){ + if( !OMIT_TEMPDB && isTemp ){ code = SQLITE_CREATE_TEMP_VIEW; }else{ code = SQLITE_CREATE_VIEW; } }else{ - if( isTemp ){ + if( !OMIT_TEMPDB && isTemp ){ code = SQLITE_CREATE_TEMP_TABLE; }else{ code = SQLITE_CREATE_TABLE; @@ -1376,7 +1377,7 @@ static char *createTableStmt(Table *p){ n += 35 + 6*p->nCol; zStmt = sqliteMallocRaw( n ); if( zStmt==0 ) return 0; - strcpy(zStmt, p->iDb==1 ? "CREATE TEMP TABLE " : "CREATE TABLE "); + strcpy(zStmt, !OMIT_TEMPDB&&p->iDb==1 ? "CREATE TEMP TABLE ":"CREATE TABLE "); k = strlen(zStmt); identPut(zStmt, &k, p->zName); zStmt[k++] = '('; @@ -1865,13 +1866,13 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView){ goto exit_drop_table; } if( isView ){ - if( iDb==1 ){ + if( !OMIT_TEMPDB && iDb==1 ){ code = SQLITE_DROP_TEMP_VIEW; }else{ code = SQLITE_DROP_VIEW; } }else{ - if( iDb==1 ){ + if( !OMIT_TEMPDB && iDb==1 ){ code = SQLITE_DROP_TEMP_TABLE; }else{ code = SQLITE_DROP_TABLE; @@ -2189,7 +2190,6 @@ void sqlite3CreateIndex( int i, j; Token nullId; /* Fake token for an empty ID list */ DbFixer sFix; /* For assigning database names to pTable */ - int isTemp; /* True for a temporary index */ sqlite3 *db = pParse->db; int iDb; /* Index of the database that is being written */ @@ -2210,6 +2210,7 @@ void sqlite3CreateIndex( iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName); if( iDb<0 ) goto exit_create_index; +#ifndef SQLITE_OMIT_TEMPDB /* If the index name was unqualified, check if the the table ** is a temp table. If so, set the database to 1. */ @@ -2217,6 +2218,7 @@ void sqlite3CreateIndex( if( pName2 && pName2->n==0 && pTab && pTab->iDb==1 ){ iDb = 1; } +#endif if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && sqlite3FixSrcList(&sFix, pTblName) @@ -2244,7 +2246,6 @@ void sqlite3CreateIndex( goto exit_create_index; } #endif - isTemp = pTab->iDb==1; /* ** Find the name of the index. Make sure there is not already another @@ -2294,12 +2295,12 @@ void sqlite3CreateIndex( */ #ifndef SQLITE_OMIT_AUTHORIZATION { - const char *zDb = db->aDb[pTab->iDb].zName; - if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){ + const char *zDb = db->aDb[iDb].zName; + if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){ goto exit_create_index; } i = SQLITE_CREATE_INDEX; - if( isTemp ) i = SQLITE_CREATE_TEMP_INDEX; + if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX; if( sqlite3AuthCheck(pParse, i, zName, pTab->zName, zDb) ){ goto exit_create_index; } @@ -2562,7 +2563,7 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName){ if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){ goto exit_drop_index; } - if( pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX; + if( !OMIT_TEMPDB && pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX; if( sqlite3AuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){ goto exit_drop_index; } @@ -2870,7 +2871,7 @@ void sqlite3CodeVerifySchema(Parse *pParse, int iDb){ if( (pParse->cookieMask & mask)==0 ){ pParse->cookieMask |= mask; pParse->cookieValue[iDb] = db->aDb[iDb].schema_cookie; - if( iDb==1 ){ + if( !OMIT_TEMPDB && iDb==1 ){ sqlite3OpenTempDatabase(pParse); } } @@ -2903,7 +2904,7 @@ void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){ if( setStatement && pParse->nested==0 ){ sqlite3VdbeAddOp(v, OP_Statement, iDb, 0); } - if( iDb!=1 && pParse->db->aDb[1].pBt!=0 ){ + if( (OMIT_TEMPDB || iDb!=1) && pParse->db->aDb[1].pBt!=0 ){ sqlite3BeginWriteOperation(pParse, setStatement, 1); } } diff --git a/src/main.c b/src/main.c index dca52977c4..20335a01d3 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.283 2005/03/21 04:04:03 danielk1977 Exp $ +** $Id: main.c,v 1.284 2005/03/29 03:10:59 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -133,7 +133,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ int meta[10]; InitData initData; char const *zMasterSchema; - char const *zMasterName; + char const *zMasterName = SCHEMA_TABLE(iDb); /* ** The master database table has a structure like this @@ -147,6 +147,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ " sql text\n" ")" ; +#ifndef SQLITE_OMIT_TEMPDB static const char temp_master_schema[] = "CREATE TEMP TABLE sqlite_temp_master(\n" " type text,\n" @@ -156,6 +157,9 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ " sql text\n" ")" ; +#else + #define temp_master_schema 0 +#endif assert( iDb>=0 && iDbnDb ); @@ -163,13 +167,12 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ ** and initialisation script appropriate for the database being ** initialised. zMasterName is the name of the master table. */ - if( iDb==1 ){ + if( !OMIT_TEMPDB && iDb==1 ){ zMasterSchema = temp_master_schema; - zMasterName = TEMP_MASTER_NAME; }else{ zMasterSchema = master_schema; - zMasterName = MASTER_NAME; } + zMasterName = SCHEMA_TABLE(iDb); /* Construct the schema tables. */ sqlite3SafetyOff(db); @@ -195,7 +198,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ /* Create a cursor to hold the database open */ if( db->aDb[iDb].pBt==0 ){ - if( iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded); + if( !OMIT_TEMPDB && iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded); return SQLITE_OK; } rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain); @@ -351,12 +354,14 @@ int sqlite3Init(sqlite3 *db, char **pzErrMsg){ ** for the TEMP database. This is loaded last, as the TEMP database ** schema may contain references to objects in other databases. */ +#ifndef SQLITE_OMIT_TEMPDB if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){ rc = sqlite3InitOne(db, 1, pzErrMsg); if( rc ){ sqlite3ResetInternalSchema(db, 1); } } +#endif db->init.busy = 0; if( rc==SQLITE_OK ){ @@ -1205,13 +1210,17 @@ static int openDatabase( db->magic = SQLITE_MAGIC_CLOSED; goto opendb_out; } - db->aDb[0].zName = "main"; - db->aDb[1].zName = "temp"; - /* The default safety_level for the main database is 'full' for the temp - ** database it is 'NONE'. This matches the pager layer defaults. */ + /* The default safety_level for the main database is 'full'; for the temp + ** database it is 'NONE'. This matches the pager layer defaults. + */ + db->aDb[0].zName = "main"; db->aDb[0].safety_level = 3; +#ifndef SQLITE_OMIT_TEMPDB + db->aDb[1].zName = "temp"; db->aDb[1].safety_level = 1; +#endif + /* Register all built-in functions, but do not attempt to read the ** database schema yet. This is delayed until the first time the database diff --git a/src/parse.y b/src/parse.y index ad7fb2f985..e60fe1a43e 100644 --- a/src/parse.y +++ b/src/parse.y @@ -14,7 +14,7 @@ ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** -** @(#) $Id: parse.y,v 1.169 2005/03/17 05:03:40 danielk1977 Exp $ +** @(#) $Id: parse.y,v 1.170 2005/03/29 03:10:59 danielk1977 Exp $ */ %token_prefix TK_ %token_type {Token} @@ -112,7 +112,9 @@ create_table ::= CREATE(X) temp(T) TABLE nm(Y) dbnm(Z). { sqlite3StartTable(pParse,&X,&Y,&Z,T,0); } %type temp {int} +%ifndef SQLITE_OMIT_TEMPDB temp(A) ::= TEMP. {A = 1;} +%endif temp(A) ::= . {A = 0;} create_table_args ::= LP columnlist conslist_opt(X) RP(Y). { sqlite3EndTable(pParse,&X,&Y,0); diff --git a/src/pragma.c b/src/pragma.c index e46d374b58..22b47af9d2 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.90 2005/02/26 18:10:44 drh Exp $ +** $Id: pragma.c,v 1.91 2005/03/29 03:10:59 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -645,6 +645,8 @@ void sqlite3Pragma( HashElem *x; int cnt = 0; + if( OMIT_TEMPDB && i==1 ) continue; + sqlite3CodeVerifySchema(pParse, i); /* Do an integrity check of the B-Tree diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 3934a6b631..2cd0e95950 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.374 2005/03/21 04:04:03 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.375 2005/03/29 03:10:59 danielk1977 Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -67,6 +67,17 @@ # define TEMP_PAGES 500 #endif +/* +** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 +** afterward. Having this macro allows us to cause the C compiler +** to omit code used by TEMP tables without messy #ifndef statements. +*/ +#ifdef SQLITE_OMIT_TEMPDB +#define OMIT_TEMPDB 1 +#else +#define OMIT_TEMPDB 0 +#endif + /* ** If the following macro is set to 1, then NULL values are considered ** distinct for the SELECT DISTINCT statement and for UNION or EXCEPT @@ -292,7 +303,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */ /* ** The name of the schema table. */ -#define SCHEMA_TABLE(x) (x==1?TEMP_MASTER_NAME:MASTER_NAME) +#define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME) /* ** A convenience macro that returns the number of elements in diff --git a/src/test1.c b/src/test1.c index 62855f695d..2acfe7530f 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.135 2005/03/21 04:04:02 danielk1977 Exp $ +** $Id: test1.c,v 1.136 2005/03/29 03:11:00 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -2862,6 +2862,12 @@ static void set_options(Tcl_Interp *interp){ Tcl_SetVar2(interp, "sqlite_options", "trigger", "1", TCL_GLOBAL_ONLY); #endif +#ifdef SQLITE_OMIT_TEMPDB + Tcl_SetVar2(interp, "sqlite_options", "tempdb", "0", TCL_GLOBAL_ONLY); +#else + Tcl_SetVar2(interp, "sqlite_options", "tempdb", "1", TCL_GLOBAL_ONLY); +#endif + #ifdef SQLITE_OMIT_UTF16 Tcl_SetVar2(interp, "sqlite_options", "utf16", "0", TCL_GLOBAL_ONLY); #else diff --git a/src/trigger.c b/src/trigger.c index cdae012ead..29cbc37796 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -197,9 +197,9 @@ void sqlite3FinishTrigger( sqlite3 *db = pParse->db; /* The database */ DbFixer sFix; - if( pParse->nErr || pParse->pNewTrigger==0 ) goto triggerfinish_cleanup; pTrig = pParse->pNewTrigger; pParse->pNewTrigger = 0; + if( pParse->nErr || pTrig==0 ) goto triggerfinish_cleanup; pTrig->step_list = pStepList; while( pStepList ){ pStepList->pTrig = pTrig; @@ -439,7 +439,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){ zDb = pName->a[0].zDatabase; zName = pName->a[0].zName; nName = strlen(zName); - for(i=0; inDb; i++){ + for(i=OMIT_TEMPDB; inDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue; pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1); diff --git a/src/vdbe.c b/src/vdbe.c index 434183a5a3..d4901a74c3 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.460 2005/03/21 03:53:38 danielk1977 Exp $ +** $Id: vdbe.c,v 1.461 2005/03/29 03:11:00 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -3819,7 +3819,7 @@ case OP_ParseSchema: { assert( iDb>=0 && iDbnDb ); if( !DbHasProperty(db, iDb, DB_SchemaLoaded) ) break; - zMaster = iDb==1 ? TEMP_MASTER_NAME : MASTER_NAME; + zMaster = SCHEMA_TABLE(iDb); initData.db = db; initData.pzErrMsg = &p->zErrMsg; zSql = sqlite3MPrintf( diff --git a/test/alter.test b/test/alter.test index 4e9d176681..45d20f5e24 100644 --- a/test/alter.test +++ b/test/alter.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is testing the ALTER TABLE statement. # -# $Id: alter.test,v 1.10 2005/02/14 06:38:40 danielk1977 Exp $ +# $Id: alter.test,v 1.11 2005/03/29 03:11:00 danielk1977 Exp $ # set testdir [file dirname $argv0] @@ -43,7 +43,12 @@ ifcapable !altertable { # and some tables with odd names. # do_test alter-1.1 { - execsql { + ifcapable tempdb { + set ::temp TEMP + } else { + set ::temp {} + } + execsql [subst -nocommands { CREATE TABLE t1(a,b); INSERT INTO t1 VALUES(1,2); CREATE TABLE [t1'x1](c UNIQUE, b PRIMARY KEY); @@ -51,10 +56,10 @@ do_test alter-1.1 { CREATE INDEX t1i1 ON T1(B); CREATE INDEX t1i2 ON t1(a,b); CREATE INDEX i3 ON [t1'x1](b,c); - CREATE TEMP TABLE "temp table"(e,f,g UNIQUE); + CREATE $::temp TABLE "temp table"(e,f,g UNIQUE); CREATE INDEX i2 ON [temp table](f); INSERT INTO [temp table] VALUES(5,6,7); - } + }] execsql { SELECT 't1', * FROM t1; SELECT 't1''x1', * FROM "t1'x1"; @@ -62,11 +67,19 @@ do_test alter-1.1 { } } {t1 1 2 t1'x1 3 4 5 6 7} do_test alter-1.2 { + execsql [subst { + CREATE $::temp TABLE objlist(type, name, tbl_name); + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_master WHERE NAME!='objlist'; + }] + ifcapable tempdb { + execsql { + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_temp_master WHERE NAME!='objlist'; + } + } + execsql { - CREATE TEMP TABLE objlist(type, name, tbl_name); - INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master; - INSERT INTO objlist - SELECT type, name, tbl_name FROM sqlite_temp_master WHERE NAME!='objlist'; SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name; } } [list \ @@ -102,9 +115,14 @@ do_test alter-1.4 { do_test alter-1.5 { execsql { DELETE FROM objlist; - INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master; - INSERT INTO objlist - SELECT type, name, tbl_name FROM sqlite_temp_master WHERE NAME!='objlist'; + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_master WHERE NAME!='objlist'; + } + catchsql { + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_temp_master WHERE NAME!='objlist'; + } + execsql { SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name; } } [list \ @@ -123,27 +141,33 @@ do_test alter-1.5 { # Make sure the changes persist after restarting the database. # (The TEMP table will not persist, of course.) # -do_test alter-1.6 { - db close - set DB [sqlite3 db test.db] +ifcapable tempdb { + do_test alter-1.6 { + db close + set DB [sqlite3 db test.db] + execsql { + CREATE TEMP TABLE objlist(type, name, tbl_name); + INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master; + INSERT INTO objlist + SELECT type, name, tbl_name FROM sqlite_temp_master + WHERE NAME!='objlist'; + SELECT type, name, tbl_name FROM objlist + ORDER BY tbl_name, type desc, name; + } + } [list \ + table -t1- -t1- \ + index t1i1 -t1- \ + index t1i2 -t1- \ + table T2 T2 \ + index i3 T2 \ + index {sqlite_autoindex_T2_1} T2 \ + index {sqlite_autoindex_T2_2} T2 \ + ] +} else { execsql { - CREATE TEMP TABLE objlist(type, name, tbl_name); - INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master; - INSERT INTO objlist - SELECT type, name, tbl_name FROM sqlite_temp_master - WHERE NAME!='objlist'; - SELECT type, name, tbl_name FROM objlist - ORDER BY tbl_name, type desc, name; + DROP TABLE TempTab; } -} [list \ - table -t1- -t1- \ - index t1i1 -t1- \ - index t1i2 -t1- \ - table T2 T2 \ - index i3 T2 \ - index {sqlite_autoindex_T2_1} T2 \ - index {sqlite_autoindex_T2_2} T2 \ - ] +} # Make sure the ALTER TABLE statements work with the # non-callback API @@ -155,12 +179,15 @@ do_test alter-1.7 { } execsql { DELETE FROM objlist; - INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master; - INSERT INTO objlist - SELECT type, name, tbl_name FROM sqlite_temp_master - WHERE NAME!='objlist'; - SELECT type, name, tbl_name FROM objlist - ORDER BY tbl_name, type desc, name; + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_master WHERE NAME!='objlist'; + } + catchsql { + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_temp_master WHERE NAME!='objlist'; + } + execsql { + SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name; } } [list \ table *t1* *t1* \ @@ -419,12 +446,12 @@ do_test alter-3.2.10 { } {} do_test alter-3.3.1 { - execsql { + execsql [subst { CREATE TABLE tbl1(a, b, c); - CREATE TEMP TRIGGER trig1 AFTER INSERT ON tbl1 BEGIN + CREATE $::temp TRIGGER trig1 AFTER INSERT ON tbl1 BEGIN SELECT trigfunc('trig1', new.a, new.b, new.c); END; - } + }] } {} do_test alter-3.3.2 { execsql { @@ -440,11 +467,11 @@ do_test alter-3.3.3 { set ::TRIGGER } {trig1 d e f} do_test alter-3.3.4 { - execsql { - CREATE TEMP TRIGGER trig2 AFTER UPDATE ON tbl2 BEGIN + execsql [subst { + CREATE $::temp TRIGGER trig2 AFTER UPDATE ON tbl2 BEGIN SELECT trigfunc('trig2', new.a, new.b, new.c); END; - } + }] } {} do_test alter-3.3.5 { execsql { @@ -462,9 +489,15 @@ do_test alter-3.3.6 { do_test alter-3.3.7 { execsql { DROP TABLE tbl3; - SELECT * FROM sqlite_temp_master WHERE type = 'trigger'; } } {} +ifcapable tempdb { + do_test alter-3.3.8 { + execsql { + SELECT * FROM sqlite_temp_master WHERE type = 'trigger'; + } + } {} +} } ;# ifcapable trigger diff --git a/test/alter3.test b/test/alter3.test index a2c33d13cb..c08cb17757 100644 --- a/test/alter3.test +++ b/test/alter3.test @@ -13,7 +13,7 @@ # file format change that may be used in the future to implement # "ALTER TABLE ... ADD COLUMN". # -# $Id: alter3.test,v 1.5 2005/03/28 16:50:22 drh Exp $ +# $Id: alter3.test,v 1.6 2005/03/29 03:11:00 danielk1977 Exp $ # set testdir [file dirname $argv0] @@ -291,7 +291,7 @@ do_test alter3-5.99 { # Test that the table schema is correctly reloaded when a column # is added to a table. # -ifcapable trigger { +ifcapable trigger&&tempdb { do_test alter3-6.1 { execsql { CREATE TABLE t1(a, b); diff --git a/test/attach.test b/test/attach.test index 89b8d8ba64..b96d86d12b 100644 --- a/test/attach.test +++ b/test/attach.test @@ -12,7 +12,7 @@ # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # -# $Id: attach.test,v 1.39 2005/03/15 02:04:13 drh Exp $ +# $Id: attach.test,v 1.40 2005/03/29 03:11:00 danielk1977 Exp $ # set testdir [file dirname $argv0] @@ -127,11 +127,13 @@ do_test attach-1.15 { ATTACH 'test.db' as main; } } {1 {database main is already in use}} -do_test attach-1.16 { - catchsql { - ATTACH 'test.db' as temp; - } -} {1 {database temp is already in use}} +ifcapable tempdb { + do_test attach-1.16 { + catchsql { + ATTACH 'test.db' as temp; + } + } {1 {database temp is already in use}} +} do_test attach-1.17 { catchsql { ATTACH 'test.db' as MAIN; @@ -159,7 +161,9 @@ do_test attach-1.20.2 { } {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11} } ;# ifcapable schema_pragmas integrity_check attach-1.20.3 -execsql {select * from sqlite_temp_master} +ifcapable tempdb { + execsql {select * from sqlite_temp_master} +} do_test attach-1.21 { catchsql { ATTACH 'test.db' as db12; @@ -190,11 +194,21 @@ do_test attach-1.26 { DETACH main; } } {1 {cannot detach database main}} -do_test attach-1.27 { - catchsql { - DETACH Temp; - } -} {1 {cannot detach database Temp}} + +ifcapable tempdb { + do_test attach-1.27 { + catchsql { + DETACH Temp; + } + } {1 {cannot detach database Temp}} +} else { + do_test attach-1.27 { + catchsql { + DETACH Temp; + } + } {1 {no such database: Temp}} +} + do_test attach-1.28 { catchsql { DETACH db11; @@ -209,9 +223,15 @@ do_test attach-1.28 { } } {0 {}} ifcapable schema_pragmas { -do_test attach-1.29 { - db_list db -} {0 main 1 temp} + ifcapable tempdb { + do_test attach-1.29 { + db_list db + } {0 main 1 temp} + } else { + do_test attach-1.29 { + db_list db + } {0 main} + } } ;# ifcapable schema_pragmas ifcapable {trigger} { # Only do the following tests if triggers are enabled @@ -257,11 +277,18 @@ do_test attach-2.7 { SELECT type, name, tbl_name FROM db2.sqlite_master; } } {table t2 t2 table tx tx trigger r1 t2} -ifcapable schema_pragmas { -do_test attach-2.8 { - db_list db -} {0 main 1 temp 2 db2} -} ;# ifcapable schema_pragmas + +ifcapable schema_pragmas&&tempdb { + do_test attach-2.8 { + db_list db + } {0 main 1 temp 2 db2} +} ;# ifcapable schema_pragmas&&tempdb +ifcapable schema_pragmas&&!tempdb { + do_test attach-2.8 { + db_list db + } {0 main 2 db2} +} ;# ifcapable schema_pragmas&&!tempdb + do_test attach-2.9 { execsql { CREATE INDEX i2 ON t2(x); @@ -279,9 +306,15 @@ do_test attach-2.10 { # } #} {1 {database schema has changed}} ifcapable schema_pragmas { -do_test attach-2.12 { - db_list db -} {0 main 1 temp 2 db2} + ifcapable tempdb { + do_test attach-2.12 { + db_list db + } {0 main 1 temp 2 db2} + } else { + do_test attach-2.12 { + db_list db + } {0 main 2 db2} + } } ;# ifcapable schema_pragmas do_test attach-2.13 { catchsql { @@ -606,14 +639,16 @@ do_test attach-5.3 { END; } db2 } {1 {trigger r5 cannot reference objects in database orig}} -do_test attach-5.4 { - catchsql { - CREATE TEMP TABLE t6(p,q,r); - CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN - SELECT 'no-op' FROM temp.t6; - END; - } db2 -} {1 {trigger r5 cannot reference objects in database temp}} +ifcapable tempdb { + do_test attach-5.4 { + catchsql { + CREATE TEMP TABLE t6(p,q,r); + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' FROM temp.t6; + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} +} ifcapable subquery { do_test attach-5.5 { catchsql { diff --git a/test/attach2.test b/test/attach2.test index 69a3dd7825..700da97952 100644 --- a/test/attach2.test +++ b/test/attach2.test @@ -12,7 +12,7 @@ # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # -# $Id: attach2.test,v 1.31 2005/01/24 01:38:33 drh Exp $ +# $Id: attach2.test,v 1.32 2005/03/29 03:11:00 danielk1977 Exp $ # set testdir [file dirname $argv0] @@ -152,6 +152,16 @@ for {set i 2} {$i<=15} {incr i} { # A procedure to verify the status of locks on a database. # proc lock_status {testnum db expected_result} { + # If the database was compiled with OMIT_TEMPDB set, then + # the lock_status list will not contain an entry for the temp + # db. But the test code doesn't know this, so it's easiest + # to filter it out here. + ifcapable !tempdb { + set expected_result [concat \ + [lrange $expected_result 0 1] \ + [lrange $expected_result 4 end] \ + ] + } do_test attach2-$testnum [subst { $db cache flush ;# The lock_status pragma should not be cached execsql {PRAGMA lock_status} $db diff --git a/test/attach3.test b/test/attach3.test index 9844798947..6caf14e13f 100644 --- a/test/attach3.test +++ b/test/attach3.test @@ -12,7 +12,7 @@ # focus of this script is testing the ATTACH and DETACH commands # and schema changes to attached databases. # -# $Id: attach3.test,v 1.14 2004/11/22 08:43:32 danielk1977 Exp $ +# $Id: attach3.test,v 1.15 2005/03/29 03:11:00 danielk1977 Exp $ # @@ -189,29 +189,31 @@ do_test attach3-8.2 { } } {} -# Try to trick SQLite into dropping the wrong temp trigger. -do_test attach3-9.0 { - execsql { - CREATE TABLE main.t4(a, b, c); - CREATE TABLE aux.t4(a, b, c); - CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN - SELECT 'hello world'; - END; - SELECT count(*) FROM sqlite_temp_master; - } -} {1} -do_test attach3-9.1 { - execsql { - DROP TABLE main.t4; - SELECT count(*) FROM sqlite_temp_master; - } -} {1} -do_test attach3-9.2 { - execsql { - DROP TABLE aux.t4; - SELECT count(*) FROM sqlite_temp_master; - } -} {0} +ifcapable tempdb { + # Try to trick SQLite into dropping the wrong temp trigger. + do_test attach3-9.0 { + execsql { + CREATE TABLE main.t4(a, b, c); + CREATE TABLE aux.t4(a, b, c); + CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN + SELECT 'hello world'; + END; + SELECT count(*) FROM sqlite_temp_master; + } + } {1} + do_test attach3-9.1 { + execsql { + DROP TABLE main.t4; + SELECT count(*) FROM sqlite_temp_master; + } + } {1} + do_test attach3-9.2 { + execsql { + DROP TABLE aux.t4; + SELECT count(*) FROM sqlite_temp_master; + } + } {0} +} } ;# endif trigger # Make sure the aux.sqlite_master table is read-only diff --git a/test/auth.test b/test/auth.test index 90c548c0ce..1bd32cb65b 100644 --- a/test/auth.test +++ b/test/auth.test @@ -12,7 +12,7 @@ # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # -# $Id: auth.test,v 1.26 2005/01/24 10:26:00 danielk1977 Exp $ +# $Id: auth.test,v 1.27 2005/03/29 03:11:00 danielk1977 Exp $ # set testdir [file dirname $argv0] @@ -80,34 +80,36 @@ do_test auth-1.4 { execsql {SELECT name FROM sqlite_master} } {} -do_test auth-1.5 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { - return SQLITE_DENY +ifcapable tempdb { + do_test auth-1.5 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {CREATE TEMP TABLE t1(a,b,c)} -} {1 {not authorized}} -do_test auth-1.6 { - execsql {SELECT name FROM sqlite_temp_master} -} {} -do_test auth-1.7.1 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_CREATE_TEMP_TABLE"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_DENY + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {1 {not authorized}} + do_test auth-1.6 { + execsql {SELECT name FROM sqlite_temp_master} + } {} + do_test auth-1.7.1 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_CREATE_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {CREATE TEMP TABLE t1(a,b,c)} -} {1 {not authorized}} -do_test auth-1.7.2 { - set ::authargs -} {t1 {} temp {}} -do_test auth-1.8 { - execsql {SELECT name FROM sqlite_temp_master} -} {} + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {1 {not authorized}} + do_test auth-1.7.2 { + set ::authargs + } {t1 {} temp {}} + do_test auth-1.8 { + execsql {SELECT name FROM sqlite_temp_master} + } {} +} do_test auth-1.9 { proc auth {code arg1 arg2 arg3 arg4} { @@ -134,45 +136,49 @@ do_test auth-1.11 { do_test auth-1.12 { execsql {SELECT name FROM sqlite_master} } {} -do_test auth-1.13 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { - return SQLITE_IGNORE - } - return SQLITE_OK - } - catchsql {CREATE TEMP TABLE t1(a,b,c)} -} {0 {}} -do_test auth-1.14 { - execsql {SELECT name FROM sqlite_temp_master} -} {} -do_test auth-1.15 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_CREATE_TEMP_TABLE"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_IGNORE - } - return SQLITE_OK - } - catchsql {CREATE TEMP TABLE t1(a,b,c)} -} {0 {}} -do_test auth-1.16 { - execsql {SELECT name FROM sqlite_temp_master} -} {} -do_test auth-1.17 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_CREATE_TABLE"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_DENY +ifcapable tempdb { + do_test auth-1.13 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {CREATE TEMP TABLE t1(a,b,c)} -} {0 {}} -do_test auth-1.18 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {0 {}} + do_test auth-1.14 { + execsql {SELECT name FROM sqlite_temp_master} + } {} + do_test auth-1.15 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_CREATE_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {0 {}} + do_test auth-1.16 { + execsql {SELECT name FROM sqlite_temp_master} + } {} + + do_test auth-1.17 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_CREATE_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {0 {}} + do_test auth-1.18 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} + do_test auth-1.19.1 { set ::authargs {} proc auth {code arg1 arg2 arg3 arg4} { @@ -224,32 +230,34 @@ do_test auth-1.24 { execsql {SELECT name FROM sqlite_master} } {t2} -do_test auth-1.25 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DROP_TEMP_TABLE"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_DENY +ifcapable tempdb { + do_test auth-1.25 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DROP_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {DROP TABLE t1} -} {1 {not authorized}} -do_test auth-1.26 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} -do_test auth-1.27 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DROP_TEMP_TABLE"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_IGNORE + catchsql {DROP TABLE t1} + } {1 {not authorized}} + do_test auth-1.26 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.27 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DROP_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {DROP TABLE t1} -} {0 {}} -do_test auth-1.28 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} + catchsql {DROP TABLE t1} + } {0 {}} + do_test auth-1.28 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} do_test auth-1.29 { proc auth {code arg1 arg2 arg3 arg4} { @@ -472,30 +480,33 @@ do_test auth-1.65 { do_test auth-1.66 { execsql {SELECT name FROM sqlite_master} } {t2} -do_test auth-1.67 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { - return SQLITE_DENY + +ifcapable tempdb { + do_test auth-1.67 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {DROP TABLE t1} -} {1 {not authorized}} -do_test auth-1.68 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} -do_test auth-1.69 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DELETE" && $arg1=="t1"} { - return SQLITE_DENY + catchsql {DROP TABLE t1} + } {1 {not authorized}} + do_test auth-1.68 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.69 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DELETE" && $arg1=="t1"} { + return SQLITE_DENY + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {DROP TABLE t1} -} {1 {not authorized}} -do_test auth-1.70 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} + catchsql {DROP TABLE t1} + } {1 {not authorized}} + do_test auth-1.70 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} do_test auth-1.71 { proc auth {code arg1 arg2 arg3 arg4} { @@ -521,30 +532,33 @@ do_test auth-1.73 { do_test auth-1.74 { execsql {SELECT name FROM sqlite_master} } {t2} -do_test auth-1.75 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { - return SQLITE_IGNORE + +ifcapable tempdb { + do_test auth-1.75 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {DROP TABLE t1} -} {0 {}} -do_test auth-1.76 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} -do_test auth-1.77 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DELETE" && $arg1=="t1"} { - return SQLITE_IGNORE + catchsql {DROP TABLE t1} + } {0 {}} + do_test auth-1.76 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.77 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DELETE" && $arg1=="t1"} { + return SQLITE_IGNORE + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {DROP TABLE t1} -} {0 {}} -do_test auth-1.78 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} + catchsql {DROP TABLE t1} + } {0 {}} + do_test auth-1.78 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} # Test cases auth-1.79 to auth-1.124 test creating and dropping views. # Omit these if the library was compiled with views omitted. @@ -582,38 +596,40 @@ do_test auth-1.84 { execsql {SELECT name FROM sqlite_master} } {t2} -do_test auth-1.85 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_CREATE_TEMP_VIEW"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_DENY +ifcapable tempdb { + do_test auth-1.85 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_CREATE_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} -} {1 {not authorized}} -do_test auth-1.86 { - set ::authargs -} {v1 {} temp {}} -do_test auth-1.87 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} -do_test auth-1.88 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_CREATE_TEMP_VIEW"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_IGNORE + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {1 {not authorized}} + do_test auth-1.86 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.87 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.88 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_CREATE_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} -} {0 {}} -do_test auth-1.89 { - set ::authargs -} {v1 {} temp {}} -do_test auth-1.90 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {0 {}} + do_test auth-1.89 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.90 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} do_test auth-1.91 { proc auth {code arg1 arg2 arg3 arg4} { @@ -640,30 +656,32 @@ do_test auth-1.94 { execsql {SELECT name FROM sqlite_master} } {t2} -do_test auth-1.95 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { - return SQLITE_DENY +ifcapable tempdb { + do_test auth-1.95 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} -} {1 {not authorized}} -do_test auth-1.96 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} -do_test auth-1.97 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { - return SQLITE_IGNORE + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {1 {not authorized}} + do_test auth-1.96 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.97 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK } - return SQLITE_OK - } - catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} -} {0 {}} -do_test auth-1.98 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {0 {}} + do_test auth-1.98 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} do_test auth-1.99 { proc auth {code arg1 arg2 arg3 arg4} { @@ -742,87 +760,89 @@ do_test auth-1.111 { } {t2} -do_test auth-1.112 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { - return SQLITE_DENY - } - return SQLITE_OK - } - catchsql { - CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1; - DROP VIEW v1 - } -} {1 {not authorized}} -do_test auth-1.113 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1 v1} -do_test auth-1.114 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DROP_TEMP_VIEW"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_DENY - } - return SQLITE_OK - } - catchsql {DROP VIEW v1} -} {1 {not authorized}} -do_test auth-1.115 { - set ::authargs -} {v1 {} temp {}} -do_test auth-1.116 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1 v1} -do_test auth-1.117 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { - return SQLITE_IGNORE - } - return SQLITE_OK - } - catchsql {DROP VIEW v1} -} {0 {}} -do_test auth-1.118 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1 v1} -do_test auth-1.119 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DROP_TEMP_VIEW"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_IGNORE - } - return SQLITE_OK - } - catchsql {DROP VIEW v1} -} {0 {}} -do_test auth-1.120 { - set ::authargs -} {v1 {} temp {}} -do_test auth-1.121 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1 v1} -do_test auth-1.122 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DROP_TEMP_VIEW"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] +ifcapable tempdb { + do_test auth-1.112 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } return SQLITE_OK } - return SQLITE_OK - } - catchsql {DROP VIEW v1} -} {0 {}} -do_test auth-1.123 { - set ::authargs -} {v1 {} temp {}} -do_test auth-1.124 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} + catchsql { + CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1; + DROP VIEW v1 + } + } {1 {not authorized}} + do_test auth-1.113 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 v1} + do_test auth-1.114 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DROP_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {1 {not authorized}} + do_test auth-1.115 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.116 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 v1} + do_test auth-1.117 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {0 {}} + do_test auth-1.118 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 v1} + do_test auth-1.119 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DROP_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {0 {}} + do_test auth-1.120 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.121 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 v1} + do_test auth-1.122 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DROP_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {0 {}} + do_test auth-1.123 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.124 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} } ;# ifcapable view # Test cases auth-1.125 to auth-1.176 test creating and dropping triggers. # Omit these if the library was compiled with triggers omitted. # -ifcapable trigger { +ifcapable trigger&&tempdb { do_test auth-1.125 { proc auth {code arg1 arg2 arg3 arg4} { if {$code=="SQLITE_CREATE_TRIGGER"} { @@ -1254,78 +1274,80 @@ do_test auth-1.189 { execsql {SELECT name FROM sqlite_master} } {t2 i2} -do_test auth-1.190 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_CREATE_TEMP_INDEX"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_DENY - } - return SQLITE_OK - } - catchsql {CREATE INDEX i1 ON t1(a)} -} {1 {not authorized}} -do_test auth-1.191 { - set ::authargs -} {i1 t1 temp {}} -do_test auth-1.192 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} -do_test auth-1.193 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { - return SQLITE_DENY - } - return SQLITE_OK - } - catchsql {CREATE INDEX i1 ON t1(b)} -} {1 {not authorized}} -do_test auth-1.194 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} -do_test auth-1.195 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_CREATE_TEMP_INDEX"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_IGNORE - } - return SQLITE_OK - } - catchsql {CREATE INDEX i1 ON t1(b)} -} {0 {}} -do_test auth-1.196 { - set ::authargs -} {i1 t1 temp {}} -do_test auth-1.197 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} -do_test auth-1.198 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { - return SQLITE_IGNORE - } - return SQLITE_OK - } - catchsql {CREATE INDEX i1 ON t1(c)} -} {0 {}} -do_test auth-1.199 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} -do_test auth-1.200 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_CREATE_TEMP_INDEX"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] +ifcapable tempdb { + do_test auth-1.190 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_CREATE_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } return SQLITE_OK } - return SQLITE_OK - } - catchsql {CREATE INDEX i1 ON t1(a)} -} {0 {}} -do_test auth-1.201 { - set ::authargs -} {i1 t1 temp {}} -do_test auth-1.202 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1 i1} + catchsql {CREATE INDEX i1 ON t1(a)} + } {1 {not authorized}} + do_test auth-1.191 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.192 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.193 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(b)} + } {1 {not authorized}} + do_test auth-1.194 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.195 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_CREATE_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(b)} + } {0 {}} + do_test auth-1.196 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.197 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.198 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(c)} + } {0 {}} + do_test auth-1.199 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.200 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_CREATE_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(a)} + } {0 {}} + do_test auth-1.201 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.202 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 i1} +} do_test auth-1.203 { proc auth {code arg1 arg2 arg3 arg4} { @@ -1400,78 +1422,80 @@ do_test auth-1.215 { execsql {SELECT name FROM sqlite_master} } {t2} -do_test auth-1.216 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { - return SQLITE_DENY - } - return SQLITE_OK - } - catchsql {DROP INDEX i1} -} {1 {not authorized}} -do_test auth-1.217 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1 i1} -do_test auth-1.218 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DROP_TEMP_INDEX"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_DENY - } - return SQLITE_OK - } - catchsql {DROP INDEX i1} -} {1 {not authorized}} -do_test auth-1.219 { - set ::authargs -} {i1 t1 temp {}} -do_test auth-1.220 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1 i1} -do_test auth-1.221 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { - return SQLITE_IGNORE - } - return SQLITE_OK - } - catchsql {DROP INDEX i1} -} {0 {}} -do_test auth-1.222 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1 i1} -do_test auth-1.223 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DROP_TEMP_INDEX"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_IGNORE - } - return SQLITE_OK - } - catchsql {DROP INDEX i1} -} {0 {}} -do_test auth-1.224 { - set ::authargs -} {i1 t1 temp {}} -do_test auth-1.225 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1 i1} -do_test auth-1.226 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DROP_TEMP_INDEX"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] +ifcapable tempdb { + do_test auth-1.216 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } return SQLITE_OK } - return SQLITE_OK - } - catchsql {DROP INDEX i1} -} {0 {}} -do_test auth-1.227 { - set ::authargs -} {i1 t1 temp {}} -do_test auth-1.228 { - execsql {SELECT name FROM sqlite_temp_master} -} {t1} + catchsql {DROP INDEX i1} + } {1 {not authorized}} + do_test auth-1.217 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 i1} + do_test auth-1.218 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DROP_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {1 {not authorized}} + do_test auth-1.219 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.220 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 i1} + do_test auth-1.221 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {0 {}} + do_test auth-1.222 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 i1} + do_test auth-1.223 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DROP_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {0 {}} + do_test auth-1.224 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.225 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 i1} + do_test auth-1.226 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DROP_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {0 {}} + do_test auth-1.227 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.228 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} do_test auth-1.229 { proc auth {code arg1 arg2 arg3 arg4} { @@ -1662,90 +1686,101 @@ do_test auth-1.259 { DETACH DATABASE test1; } } {0 {}} -ifcapable schema_pragmas { -do_test auth-1.260 { - lindex [execsql {PRAGMA database_list}] 7 -} {test1} -} ;# ifcapable schema_pragmas -do_test auth-1.261 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_DETACH"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_DENY - } - return SQLITE_OK - } - catchsql { - DETACH DATABASE test1; - } -} {1 {not authorized}} -ifcapable schema_pragmas { -do_test auth-1.262 { - lindex [execsql {PRAGMA database_list}] 7 -} {test1} -} ;# ifcapable schema_pragmas -db authorizer {} -execsql {DETACH DATABASE test1} -db authorizer ::auth - -# Authorization for ALTER TABLE. These tests are omitted if the library -# was built without ALTER TABLE support. -ifcapable altertable { - -do_test auth-1.263 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_ALTER_TABLE"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] +ifcapable tempdb { + ifcapable schema_pragmas { + do_test auth-1.260 { + lindex [execsql {PRAGMA database_list}] 7 + } {test1} + } ;# ifcapable schema_pragmas + do_test auth-1.261 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_DETACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } return SQLITE_OK } - return SQLITE_OK - } - catchsql { - ALTER TABLE t1 RENAME TO t1x - } -} {0 {}} -do_test auth-1.264 { - execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} -} {t1x} -do_test auth-1.265 { - set authargs -} {temp t1 {} {}} -do_test auth-1.266 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_ALTER_TABLE"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_IGNORE + catchsql { + DETACH DATABASE test1; } - return SQLITE_OK + } {1 {not authorized}} + ifcapable schema_pragmas { + do_test auth-1.262 { + lindex [execsql {PRAGMA database_list}] 7 + } {test1} + } ;# ifcapable schema_pragmas + db authorizer {} + execsql {DETACH DATABASE test1} + db authorizer ::auth + + # Authorization for ALTER TABLE. These tests are omitted if the library + # was built without ALTER TABLE support. + ifcapable altertable { + + do_test auth-1.263 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1 RENAME TO t1x + } + } {0 {}} + do_test auth-1.264 { + execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} + } {t1x} + do_test auth-1.265 { + set authargs + } {temp t1 {} {}} + do_test auth-1.266 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1x RENAME TO t1 + } + } {0 {}} + do_test auth-1.267 { + execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} + } {t1x} + do_test auth-1.268 { + set authargs + } {temp t1x {} {}} + do_test auth-1.269 { + proc auth {code arg1 arg2 arg3 arg4} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1x RENAME TO t1 + } + } {1 {not authorized}} + do_test auth-1.270 { + execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} + } {t1x} + } ;# ifcapable altertable + + do_test auth-1.271 { + set authargs + } {temp t1x {} {}} +} else { + db authorizer {} + db eval { + DETACH DATABASE test1; } - catchsql { - ALTER TABLE t1x RENAME TO t1 - } -} {0 {}} -do_test auth-1.267 { - execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} -} {t1x} -do_test auth-1.268 { - set authargs -} {temp t1x {} {}} -do_test auth-1.269 { - proc auth {code arg1 arg2 arg3 arg4} { - if {$code=="SQLITE_ALTER_TABLE"} { - set ::authargs [list $arg1 $arg2 $arg3 $arg4] - return SQLITE_DENY - } - return SQLITE_OK - } - catchsql { - ALTER TABLE t1x RENAME TO t1 - } -} {1 {not authorized}} -do_test auth-1.270 { - execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} -} {t1x} -do_test auth-1.271 { - set authargs -} {temp t1x {} {}} +} + +ifcapable altertable { db authorizer {} catchsql {ALTER TABLE t1x RENAME TO t1} db authorizer ::auth @@ -1858,63 +1893,64 @@ do_test auth-1.286 { DROP TABLE t3; } } {} -do_test auth-1.287 { - execsql { - CREATE TEMP TABLE t3(a PRIMARY KEY, b, c); - CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY); - CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE); +ifcapable tempdb { + do_test auth-1.287 { + execsql { + CREATE TEMP TABLE t3(a PRIMARY KEY, b, c); + CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY); + CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE); + } + } {} + do_test auth-1.288 { + set ::authargs {} + execsql { + REINDEX temp.t3_idx1; + } + set ::authargs + } {t3_idx1 {} temp {}} + do_test auth-1.289 { + set ::authargs {} + execsql { + REINDEX BINARY; + } + set ::authargs + } {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}} + do_test auth-1.290 { + set ::authargs {} + execsql { + REINDEX NOCASE; + } + set ::authargs + } {t3_idx2 {} temp {}} + do_test auth-1.291 { + set ::authargs {} + execsql { + REINDEX temp.t3; + } + set ::authargs + } {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}} + proc auth {code args} { + if {$code=="SQLITE_REINDEX"} { + set ::authargs [concat $::authargs $args] + return SQLITE_DENY + } + return SQLITE_OK } -} {} -do_test auth-1.288 { - set ::authargs {} - execsql { - REINDEX temp.t3_idx1; - } - set ::authargs -} {t3_idx1 {} temp {}} -do_test auth-1.289 { - set ::authargs {} - execsql { - REINDEX BINARY; - } - set ::authargs -} {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}} -do_test auth-1.290 { - set ::authargs {} - execsql { - REINDEX NOCASE; - } - set ::authargs -} {t3_idx2 {} temp {}} -do_test auth-1.291 { - set ::authargs {} - execsql { - REINDEX temp.t3; - } - set ::authargs -} {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}} -proc auth {code args} { - if {$code=="SQLITE_REINDEX"} { - set ::authargs [concat $::authargs $args] - return SQLITE_DENY - } - return SQLITE_OK + do_test auth-1.292 { + set ::authargs {} + catchsql { + REINDEX temp.t3; + } + } {1 {not authorized}} + do_test auth-1.293 { + execsql { + DROP TABLE t3; + } + } {} } -do_test auth-1.292 { - set ::authargs {} - catchsql { - REINDEX temp.t3; - } -} {1 {not authorized}} -do_test auth-1.293 { - execsql { - DROP TABLE t3; - } -} {} } ;# ifcapable reindex - do_test auth-2.1 { proc auth {code arg1 arg2 arg3 arg4} { if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} { diff --git a/test/autoinc.test b/test/autoinc.test index 6a2a9fb772..e456a8e8cd 100644 --- a/test/autoinc.test +++ b/test/autoinc.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is testing the AUTOINCREMENT features. # -# $Id: autoinc.test,v 1.4 2005/02/17 00:03:07 drh Exp $ +# $Id: autoinc.test,v 1.5 2005/03/29 03:11:00 danielk1977 Exp $ # set testdir [file dirname $argv0] @@ -235,48 +235,53 @@ do_test autoinc-2.51 { SELECT * FROM sqlite_sequence } } {t1 1241} -do_test autoinc-2.52 { - execsql { - CREATE TEMP TABLE t2 AS SELECT y FROM t1; - INSERT INTO t1 SELECT NULL, y+4 FROM t2; - SELECT * FROM t1; - } -} {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8} -do_test autoinc-2.53 { - execsql { - SELECT * FROM sqlite_sequence - } -} {t1 1245} -do_test autoinc-2.54 { - execsql { - DELETE FROM t1; - INSERT INTO t1 SELECT NULL, y FROM t2; - SELECT * FROM t1; - } -} {1246 1 1247 2 1248 3 1249 4} -do_test autoinc-2.55 { - execsql { - SELECT * FROM sqlite_sequence - } -} {t1 1249} + +ifcapable tempdb { + do_test autoinc-2.52 { + execsql { + CREATE TEMP TABLE t2 AS SELECT y FROM t1; + INSERT INTO t1 SELECT NULL, y+4 FROM t2; + SELECT * FROM t1; + } + } {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8} + do_test autoinc-2.53 { + execsql { + SELECT * FROM sqlite_sequence + } + } {t1 1245} + do_test autoinc-2.54 { + execsql { + DELETE FROM t1; + INSERT INTO t1 SELECT NULL, y FROM t2; + SELECT * FROM t1; + } + } {1246 1 1247 2 1248 3 1249 4} + do_test autoinc-2.55 { + execsql { + SELECT * FROM sqlite_sequence + } + } {t1 1249} +} # Create multiple AUTOINCREMENT tables. Make sure all sequences are # tracked separately and do not interfere with one another. # do_test autoinc-2.70 { - execsql { + catchsql { DROP TABLE t2; + } + execsql { CREATE TABLE t2(d, e INTEGER PRIMARY KEY AUTOINCREMENT, f); INSERT INTO t2(d) VALUES(1); SELECT * FROM sqlite_sequence; } -} {t1 1249 t2 1} +} [ifcapable tempdb {list t1 1249 t2 1} else {list t1 1241 t2 1}] do_test autoinc-2.71 { execsql { INSERT INTO t2(d) VALUES(2); SELECT * FROM sqlite_sequence; } -} {t1 1249 t2 2} +} [ifcapable tempdb {list t1 1249 t2 2} else {list t1 1241 t2 2}] do_test autoinc-2.72 { execsql { INSERT INTO t1(x) VALUES(10000); @@ -326,125 +331,129 @@ do_test autoinc-3.4 { # AUTOINCREMENT on TEMP tables. # -do_test autoinc-4.1 { - execsql { - SELECT 1, name FROM sqlite_master WHERE type='table'; - SELECT 2, name FROM sqlite_temp_master WHERE type='table'; - } -} {1 sqlite_sequence} -do_test autoinc-4.2 { - execsql { - CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); - CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b); - SELECT 1, name FROM sqlite_master WHERE type='table'; - SELECT 2, name FROM sqlite_temp_master WHERE type='table'; - } -} {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence} -do_test autoinc-4.3 { - execsql { - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - } -} {} -do_test autoinc-4.4 { - execsql { - INSERT INTO t1 VALUES(10,1); - INSERT INTO t3 VALUES(20,2); - INSERT INTO t1 VALUES(NULL,3); - INSERT INTO t3 VALUES(NULL,4); - } -} {} - -ifcapable compound { -do_test autoinc-4.4.1 { - execsql { - SELECT * FROM t1 UNION ALL SELECT * FROM t3; - } -} {10 1 11 3 20 2 21 4} -} ;# ifcapable compound - -do_test autoinc-4.5 { - execsql { - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - } -} {1 t1 11 2 t3 21} -do_test autoinc-4.6 { - execsql { - INSERT INTO t1 SELECT * FROM t3; - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - } -} {1 t1 21 2 t3 21} -do_test autoinc-4.7 { - execsql { - INSERT INTO t3 SELECT x+100, y FROM t1; - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - } -} {1 t1 21 2 t3 121} -do_test autoinc-4.8 { - execsql { - DROP TABLE t3; - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - } -} {1 t1 21} -do_test autoinc-4.9 { - execsql { - CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q); - INSERT INTO t2 SELECT * FROM t1; - DROP TABLE t1; - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - } -} {2 t2 21} -do_test autoinc-4.10 { - execsql { - DROP TABLE t2; - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - } -} {} +ifcapable tempdb { + do_test autoinc-4.1 { + execsql { + SELECT 1, name FROM sqlite_master WHERE type='table'; + SELECT 2, name FROM sqlite_temp_master WHERE type='table'; + } + } {1 sqlite_sequence} + do_test autoinc-4.2 { + execsql { + CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b); + SELECT 1, name FROM sqlite_master WHERE type='table'; + SELECT 2, name FROM sqlite_temp_master WHERE type='table'; + } + } {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence} + do_test autoinc-4.3 { + execsql { + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {} + do_test autoinc-4.4 { + execsql { + INSERT INTO t1 VALUES(10,1); + INSERT INTO t3 VALUES(20,2); + INSERT INTO t1 VALUES(NULL,3); + INSERT INTO t3 VALUES(NULL,4); + } + } {} + + ifcapable compound { + do_test autoinc-4.4.1 { + execsql { + SELECT * FROM t1 UNION ALL SELECT * FROM t3; + } + } {10 1 11 3 20 2 21 4} + } ;# ifcapable compound + + do_test autoinc-4.5 { + execsql { + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 11 2 t3 21} + do_test autoinc-4.6 { + execsql { + INSERT INTO t1 SELECT * FROM t3; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 21 2 t3 21} + do_test autoinc-4.7 { + execsql { + INSERT INTO t3 SELECT x+100, y FROM t1; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 21 2 t3 121} + do_test autoinc-4.8 { + execsql { + DROP TABLE t3; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 21} + do_test autoinc-4.9 { + execsql { + CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q); + INSERT INTO t2 SELECT * FROM t1; + DROP TABLE t1; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {2 t2 21} + do_test autoinc-4.10 { + execsql { + DROP TABLE t2; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {} +} # Make sure AUTOINCREMENT works on ATTACH-ed tables. # -do_test autoinc-5.1 { - file delete -force test2.db - file delete -force test2.db-journal - sqlite3 db2 test2.db - execsql { - CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n); - CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT); - } db2; - execsql { - ATTACH 'test2.db' as aux; - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - SELECT 3, * FROM aux.sqlite_sequence; - } -} {} -do_test autoinc-5.2 { - execsql { - INSERT INTO t4 VALUES(NULL,1); - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - SELECT 3, * FROM aux.sqlite_sequence; - } -} {3 t4 1} -do_test autoinc-5.3 { - execsql { - INSERT INTO t5 VALUES(100,200); - SELECT * FROM sqlite_sequence - } db2 -} {t4 1 t5 200} -do_test autoinc-5.4 { - execsql { - SELECT 1, * FROM main.sqlite_sequence; - SELECT 2, * FROM temp.sqlite_sequence; - SELECT 3, * FROM aux.sqlite_sequence; - } -} {3 t4 1 3 t5 200} +ifcapable tempdb { + do_test autoinc-5.1 { + file delete -force test2.db + file delete -force test2.db-journal + sqlite3 db2 test2.db + execsql { + CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n); + CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT); + } db2; + execsql { + ATTACH 'test2.db' as aux; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + SELECT 3, * FROM aux.sqlite_sequence; + } + } {} + do_test autoinc-5.2 { + execsql { + INSERT INTO t4 VALUES(NULL,1); + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + SELECT 3, * FROM aux.sqlite_sequence; + } + } {3 t4 1} + do_test autoinc-5.3 { + execsql { + INSERT INTO t5 VALUES(100,200); + SELECT * FROM sqlite_sequence + } db2 + } {t4 1 t5 200} + do_test autoinc-5.4 { + execsql { + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + SELECT 3, * FROM aux.sqlite_sequence; + } + } {3 t4 1 3 t5 200} +} # Requirement REQ00310: Make sure an insert fails if the sequence is # already at its maximum value. diff --git a/test/capi2.test b/test/capi2.test index bbf0b2f73f..c54c879c83 100644 --- a/test/capi2.test +++ b/test/capi2.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script testing the callback-free C/C++ API. # -# $Id: capi2.test,v 1.25 2005/02/04 04:07:18 danielk1977 Exp $ +# $Id: capi2.test,v 1.26 2005/03/29 03:11:00 danielk1977 Exp $ # set testdir [file dirname $argv0] @@ -97,13 +97,13 @@ do_test capi2-1.11 { do_test capi2-2.1 { set SQL { SELECT name, rowid FROM sqlite_master; - SELECT name, rowid FROM sqlite_temp_master; + SELECT name, rowid FROM sqlite_master WHERE 0; -- A comment at the end } set VM [sqlite3_prepare $DB $SQL -1 SQL] set SQL } { - SELECT name, rowid FROM sqlite_temp_master; + SELECT name, rowid FROM sqlite_master WHERE 0; -- A comment at the end } do_test capi2-2.2 { diff --git a/test/func.test b/test/func.test index dd58668c11..feed0d03b1 100644 --- a/test/func.test +++ b/test/func.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing built-in functions. # -# $Id: func.test,v 1.33 2005/01/21 11:55:28 danielk1977 Exp $ +# $Id: func.test,v 1.34 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -260,12 +260,22 @@ do_test func-8.2 { SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t2; } } {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP} -do_test func-8.3 { - execsql { - CREATE TEMP TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC; - SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3; - } -} {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP} + +ifcapable tempdb { + do_test func-8.3 { + execsql { + CREATE TEMP TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC; + SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3; + } + } {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP} +} else { + do_test func-8.3 { + execsql { + CREATE TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC; + SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3; + } + } {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP} +} do_test func-8.4 { execsql { SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3; diff --git a/test/insert.test b/test/insert.test index 30d4fe04b6..ab4e7b42a5 100644 --- a/test/insert.test +++ b/test/insert.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the INSERT statement. # -# $Id: insert.test,v 1.24 2005/03/21 01:20:58 drh Exp $ +# $Id: insert.test,v 1.25 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -227,61 +227,63 @@ do_test insert-4.7 { # Test the ability to insert from a temporary table into itself. # Ticket #275. # -do_test insert-5.1 { - execsql { - CREATE TEMP TABLE t4(x); - INSERT INTO t4 VALUES(1); - SELECT * FROM t4; - } -} {1} -do_test insert-5.2 { - execsql { - INSERT INTO t4 SELECT x+1 FROM t4; - SELECT * FROM t4; - } -} {1 2} -ifcapable {explain} { - do_test insert-5.3 { - # verify that a temporary table is used to copy t4 to t4 - set x [execsql { - EXPLAIN INSERT INTO t4 SELECT x+2 FROM t4; - }] - expr {[lsearch $x OpenTemp]>0} +ifcapable tempdb { + do_test insert-5.1 { + execsql { + CREATE TEMP TABLE t4(x); + INSERT INTO t4 VALUES(1); + SELECT * FROM t4; + } } {1} -} - -do_test insert-5.4 { - # Verify that table "test1" begins on page 3. This should be the same - # page number used by "t4" above. - # - # Update for v3 - the first table now begins on page 2 of each file, not 3. - execsql { - SELECT rootpage FROM sqlite_master WHERE name='test1'; + do_test insert-5.2 { + execsql { + INSERT INTO t4 SELECT x+1 FROM t4; + SELECT * FROM t4; + } + } {1 2} + ifcapable {explain} { + do_test insert-5.3 { + # verify that a temporary table is used to copy t4 to t4 + set x [execsql { + EXPLAIN INSERT INTO t4 SELECT x+2 FROM t4; + }] + expr {[lsearch $x OpenTemp]>0} + } {1} } -} [expr $AUTOVACUUM?3:2] -do_test insert-5.5 { - # Verify that "t4" begins on page 3. - # - # Update for v3 - the first table now begins on page 2 of each file, not 3. - execsql { - SELECT rootpage FROM sqlite_temp_master WHERE name='t4'; + + do_test insert-5.4 { + # Verify that table "test1" begins on page 3. This should be the same + # page number used by "t4" above. + # + # Update for v3 - the first table now begins on page 2 of each file, not 3. + execsql { + SELECT rootpage FROM sqlite_master WHERE name='test1'; + } + } [expr $AUTOVACUUM?3:2] + do_test insert-5.5 { + # Verify that "t4" begins on page 3. + # + # Update for v3 - the first table now begins on page 2 of each file, not 3. + execsql { + SELECT rootpage FROM sqlite_temp_master WHERE name='t4'; + } + } {2} + do_test insert-5.6 { + # This should not use an intermediate temporary table. + execsql { + INSERT INTO t4 SELECT one FROM test1 WHERE three=7; + SELECT * FROM t4 + } + } {1 2 8} + ifcapable {explain} { + do_test insert-5.7 { + # verify that no temporary table is used to copy test1 to t4 + set x [execsql { + EXPLAIN INSERT INTO t4 SELECT one FROM test1; + }] + expr {[lsearch $x OpenTemp]>0} + } {0} } -} {2} -do_test insert-5.6 { - # This should not use an intermediate temporary table. - execsql { - INSERT INTO t4 SELECT one FROM test1 WHERE three=7; - SELECT * FROM t4 - } -} {1 2 8} -ifcapable {explain} { - do_test insert-5.7 { - # verify that no temporary table is used to copy test1 to t4 - set x [execsql { - EXPLAIN INSERT INTO t4 SELECT one FROM test1; - }] - expr {[lsearch $x OpenTemp]>0} - } {0} } # Ticket #334: REPLACE statement corrupting indices. diff --git a/test/insert2.test b/test/insert2.test index f213a9a9bb..1cb849c9ad 100644 --- a/test/insert2.test +++ b/test/insert2.test @@ -12,7 +12,7 @@ # focus of this file is testing the INSERT statement that takes is # result from a SELECT. # -# $Id: insert2.test,v 1.15 2005/02/08 08:42:29 danielk1977 Exp $ +# $Id: insert2.test,v 1.16 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -220,29 +220,31 @@ integrity_check insert2-3.9 # Ticket #901 # -do_test insert2-4.1 { - execsql { - CREATE TABLE Dependencies(depId integer primary key, - class integer, name str, flag str); - CREATE TEMPORARY TABLE DepCheck(troveId INT, depNum INT, - flagCount INT, isProvides BOOL, class INTEGER, name STRING, - flag STRING); - INSERT INTO DepCheck - VALUES(-1, 0, 1, 0, 2, 'libc.so.6', 'GLIBC_2.0'); - INSERT INTO Dependencies - SELECT DISTINCT - NULL, - DepCheck.class, - DepCheck.name, - DepCheck.flag - FROM DepCheck LEFT OUTER JOIN Dependencies ON - DepCheck.class == Dependencies.class AND - DepCheck.name == Dependencies.name AND - DepCheck.flag == Dependencies.flag - WHERE - Dependencies.depId is NULL; - }; -} {} +ifcapable tempdb { + do_test insert2-4.1 { + execsql { + CREATE TABLE Dependencies(depId integer primary key, + class integer, name str, flag str); + CREATE TEMPORARY TABLE DepCheck(troveId INT, depNum INT, + flagCount INT, isProvides BOOL, class INTEGER, name STRING, + flag STRING); + INSERT INTO DepCheck + VALUES(-1, 0, 1, 0, 2, 'libc.so.6', 'GLIBC_2.0'); + INSERT INTO Dependencies + SELECT DISTINCT + NULL, + DepCheck.class, + DepCheck.name, + DepCheck.flag + FROM DepCheck LEFT OUTER JOIN Dependencies ON + DepCheck.class == Dependencies.class AND + DepCheck.name == Dependencies.name AND + DepCheck.flag == Dependencies.flag + WHERE + Dependencies.depId is NULL; + }; + } {} +} #-------------------------------------------------------------------- # Test that the INSERT works when the SELECT statement (a) references diff --git a/test/interrupt.test b/test/interrupt.test index 4633471176..ba87d2907c 100644 --- a/test/interrupt.test +++ b/test/interrupt.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is the sqlite_interrupt() API. # -# $Id: interrupt.test,v 1.10 2005/01/11 17:46:42 drh Exp $ +# $Id: interrupt.test,v 1.11 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] @@ -123,36 +123,38 @@ integrity_check interrupt-2.6 # and that transaction is later rolled back, the internal schema tables do # not reset. # -for {set i 1} {$i<50} {incr i 5} { - do_test interrupt-3.$i.1 { - execsql { - BEGIN; - CREATE TEMP TABLE t2(x,y); - SELECT name FROM sqlite_temp_master; - } - } {t2} - do_test interrupt-3.$i.2 { - set ::sqlite_interrupt_count $::i - catchsql { - INSERT INTO t2 SELECT * FROM t1; - } - } {1 interrupted} - do_test interrupt-3.$i.3 { - execsql { - SELECT name FROM sqlite_temp_master; - } - } {t2} - do_test interrupt-3.$i.4 { - catchsql { - ROLLBACK - } - } {0 {}} - do_test interrupt-3.$i.5 { - catchsql {SELECT name FROM sqlite_temp_master}; - execsql { - SELECT name FROM sqlite_temp_master; - } - } {} +ifcapable tempdb { + for {set i 1} {$i<50} {incr i 5} { + do_test interrupt-3.$i.1 { + execsql { + BEGIN; + CREATE TEMP TABLE t2(x,y); + SELECT name FROM sqlite_temp_master; + } + } {t2} + do_test interrupt-3.$i.2 { + set ::sqlite_interrupt_count $::i + catchsql { + INSERT INTO t2 SELECT * FROM t1; + } + } {1 interrupted} + do_test interrupt-3.$i.3 { + execsql { + SELECT name FROM sqlite_temp_master; + } + } {t2} + do_test interrupt-3.$i.4 { + catchsql { + ROLLBACK + } + } {0 {}} + do_test interrupt-3.$i.5 { + catchsql {SELECT name FROM sqlite_temp_master}; + execsql { + SELECT name FROM sqlite_temp_master; + } + } {} + } } # There are reports of a memory leak if an interrupt occurs during diff --git a/test/join4.test b/test/join4.test index fba4425398..77db25ffb0 100644 --- a/test/join4.test +++ b/test/join4.test @@ -13,27 +13,46 @@ # This file implements tests for left outer joins containing WHERE # clauses that restrict the scope of the left term of the join. # -# $Id: join4.test,v 1.3 2005/01/21 03:12:16 danielk1977 Exp $ +# $Id: join4.test,v 1.4 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl -do_test join4-1.1 { - execsql { - create temp table t1(a integer, b varchar(10)); - insert into t1 values(1,'one'); - insert into t1 values(2,'two'); - insert into t1 values(3,'three'); - insert into t1 values(4,'four'); - - create temp table t2(x integer, y varchar(10), z varchar(10)); - insert into t2 values(2,'niban','ok'); - insert into t2 values(4,'yonban','err'); - } - execsql { - select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok' - } -} {2 two 2 niban ok} +ifcapable tempdb { + do_test join4-1.1 { + execsql { + create temp table t1(a integer, b varchar(10)); + insert into t1 values(1,'one'); + insert into t1 values(2,'two'); + insert into t1 values(3,'three'); + insert into t1 values(4,'four'); + + create temp table t2(x integer, y varchar(10), z varchar(10)); + insert into t2 values(2,'niban','ok'); + insert into t2 values(4,'yonban','err'); + } + execsql { + select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok' + } + } {2 two 2 niban ok} +} else { + do_test join4-1.1 { + execsql { + create table t1(a integer, b varchar(10)); + insert into t1 values(1,'one'); + insert into t1 values(2,'two'); + insert into t1 values(3,'three'); + insert into t1 values(4,'four'); + + create table t2(x integer, y varchar(10), z varchar(10)); + insert into t2 values(2,'niban','ok'); + insert into t2 values(4,'yonban','err'); + } + execsql { + select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok' + } + } {2 two 2 niban ok} +} do_test join4-1.2 { execsql { select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok' diff --git a/test/lastinsert.test b/test/lastinsert.test index f3ed2ec6ce..35f1ba6602 100644 --- a/test/lastinsert.test +++ b/test/lastinsert.test @@ -283,7 +283,7 @@ do_test lastinsert-6.4 { # 7.x - complex tests with temporary tables and nested instead of triggers # These do not run if views or triggers are disabled. -ifcapable {trigger && view} { +ifcapable {trigger && view && tempdb} { do_test lastinsert-7.1 { catchsql { drop table t1; drop table t2; drop trigger r1; diff --git a/test/laststmtchanges.test b/test/laststmtchanges.test index ec4f7e2faf..84cc903ca1 100644 --- a/test/laststmtchanges.test +++ b/test/laststmtchanges.test @@ -195,7 +195,7 @@ do_test laststmtchanges-4.3 { # 5.x - complex tests with temporary tables and nested instead of triggers # These tests cannot run if the library does not have view support enabled. -ifcapable view { +ifcapable view&&tempdb { do_test laststmtchanges-5.1 { catchsql { diff --git a/test/lock.test b/test/lock.test index b2a77a5cd6..c2f09eb196 100644 --- a/test/lock.test +++ b/test/lock.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is database locks. # -# $Id: lock.test,v 1.31 2005/03/14 02:01:50 drh Exp $ +# $Id: lock.test,v 1.32 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] @@ -303,42 +303,45 @@ do_test lock-5.2 { INSERT INTO t1(a,b) SELECT 3, tx_exec('SELECT y FROM t2 LIMIT 1'); } } {0 {}} -do_test lock-5.3 { - execsql { - CREATE TEMP TABLE t3(x); - SELECT * FROM t3; - } -} {} -do_test lock-5.4 { - catchsql { - INSERT INTO t3 SELECT tx_exec('SELECT y FROM t2 LIMIT 1'); - } -} {0 {}} -do_test lock-5.5 { - execsql { - SELECT * FROM t3; - } -} {8} -do_test lock-5.6 { - catchsql { - UPDATE t1 SET a=tx_exec('SELECT x FROM t2'); - } -} {0 {}} -do_test lock-5.7 { - execsql { - SELECT * FROM t1; - } -} {9 1 9 8} -do_test lock-5.8 { - catchsql { - UPDATE t3 SET x=tx_exec('SELECT x FROM t2'); - } -} {0 {}} -do_test lock-5.9 { - execsql { - SELECT * FROM t3; - } -} {9} + +ifcapable tempdb { + do_test lock-5.3 { + execsql { + CREATE TEMP TABLE t3(x); + SELECT * FROM t3; + } + } {} + do_test lock-5.4 { + catchsql { + INSERT INTO t3 SELECT tx_exec('SELECT y FROM t2 LIMIT 1'); + } + } {0 {}} + do_test lock-5.5 { + execsql { + SELECT * FROM t3; + } + } {8} + do_test lock-5.6 { + catchsql { + UPDATE t1 SET a=tx_exec('SELECT x FROM t2'); + } + } {0 {}} + do_test lock-5.7 { + execsql { + SELECT * FROM t1; + } + } {9 1 9 8} + do_test lock-5.8 { + catchsql { + UPDATE t3 SET x=tx_exec('SELECT x FROM t2'); + } + } {0 {}} + do_test lock-5.9 { + execsql { + SELECT * FROM t3; + } + } {9} +} do_test lock-999.1 { rename db2 {} diff --git a/test/malloc2.test b/test/malloc2.test index 15e41bfa5f..4935cba0eb 100644 --- a/test/malloc2.test +++ b/test/malloc2.test @@ -11,7 +11,7 @@ # This file attempts to check that the library can recover from a malloc() # failure when sqlite3_global_recover() is invoked. # -# $Id: malloc2.test,v 1.1 2005/03/21 04:04:03 danielk1977 Exp $ +# $Id: malloc2.test,v 1.2 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -35,11 +35,18 @@ ifcapable !globalrecover { # proc cksum {db} { set ret [list] - set sql { - SELECT name FROM sqlite_master WHERE type = 'table' UNION - SELECT name FROM sqlite_temp_master WHERE type = 'table' UNION - SELECT 'sqlite_master' UNION - SELECT 'sqlite_temp_master' + ifcapable tempdb { + set sql { + SELECT name FROM sqlite_master WHERE type = 'table' UNION + SELECT name FROM sqlite_temp_master WHERE type = 'table' UNION + SELECT 'sqlite_master' UNION + SELECT 'sqlite_temp_master' + } + } else { + set sql { + SELECT name FROM sqlite_master WHERE type = 'table' UNION + SELECT 'sqlite_master' + } } foreach tbl [$db eval $sql] { set cols [list] @@ -171,26 +178,28 @@ do_malloc2_test 2 -sql { COMMIT; } -do_test malloc2.3.setup { - execsql { - CREATE TEMP TABLE ghi(a, b, c); - BEGIN; - } - for {set i 0} {$i<20} {incr i} { +ifcapable tempdb { + do_test malloc2.3.setup { execsql { - INSERT INTO ghi VALUES(randstr(300,300),randstr(300,300),randstr(300,300)); + CREATE TEMP TABLE ghi(a, b, c); + BEGIN; } - } - execsql { + for {set i 0} {$i<20} {incr i} { + execsql { + INSERT INTO ghi VALUES(randstr(300,300),randstr(300,300),randstr(300,300)); + } + } + execsql { + COMMIT; + } + } {} + do_malloc2_test 3 -sql { + BEGIN; + CREATE INDEX ghi_i1 ON ghi(a); + UPDATE def SET a = randstr(100,100) WHERE (oid%2)==0; + UPDATE ghi SET a = randstr(100,100) WHERE (oid%2)==0; COMMIT; } -} {} -do_malloc2_test 3 -sql { - BEGIN; - CREATE INDEX ghi_i1 ON ghi(a); - UPDATE def SET a = randstr(100,100) WHERE (oid%2)==0; - UPDATE ghi SET a = randstr(100,100) WHERE (oid%2)==0; - COMMIT; } ############################################################################ diff --git a/test/misc1.test b/test/misc1.test index ef32f09886..2e85a55506 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -13,7 +13,7 @@ # This file implements tests for miscellanous features that were # left out of other test files. # -# $Id: misc1.test,v 1.33 2005/01/21 04:25:47 danielk1977 Exp $ +# $Id: misc1.test,v 1.34 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -540,7 +540,7 @@ do_test misc1-16.6 { } } {1 1 5 5 6 6} -ifcapable {trigger} { +ifcapable trigger&&tempdb { # Ticket #333: Temp triggers that modify persistent tables. # do_test misc1-17.1 { diff --git a/test/misc2.test b/test/misc2.test index 85e4032ca1..3c89777229 100644 --- a/test/misc2.test +++ b/test/misc2.test @@ -13,7 +13,7 @@ # This file implements tests for miscellanous features that were # left out of other test files. # -# $Id: misc2.test,v 1.20 2005/01/21 04:25:47 danielk1977 Exp $ +# $Id: misc2.test,v 1.21 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -206,46 +206,48 @@ do_test misc2-8.1 { # Ticket #513. Make sure the VDBE stack does not grow on a 3-way join. # -do_test misc2-9.1 { - execsql { - BEGIN; - CREATE TABLE counts(n INTEGER PRIMARY KEY); - INSERT INTO counts VALUES(0); - INSERT INTO counts VALUES(1); - INSERT INTO counts SELECT n+2 FROM counts; - INSERT INTO counts SELECT n+4 FROM counts; - INSERT INTO counts SELECT n+8 FROM counts; - COMMIT; - - CREATE TEMP TABLE x AS - SELECT dim1.n, dim2.n, dim3.n - FROM counts AS dim1, counts AS dim2, counts AS dim3 - WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10; - - SELECT count(*) FROM x; - } -} {1000} -do_test misc2-9.2 { - execsql { - DROP TABLE x; - CREATE TEMP TABLE x AS - SELECT dim1.n, dim2.n, dim3.n - FROM counts AS dim1, counts AS dim2, counts AS dim3 - WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6; - - SELECT count(*) FROM x; - } -} {1000} -do_test misc2-9.3 { - execsql { - DROP TABLE x; - CREATE TEMP TABLE x AS - SELECT dim1.n, dim2.n, dim3.n, dim4.n - FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4 - WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5; - - SELECT count(*) FROM x; - } -} [expr 5*5*5*5] +ifcapable tempdb { + do_test misc2-9.1 { + execsql { + BEGIN; + CREATE TABLE counts(n INTEGER PRIMARY KEY); + INSERT INTO counts VALUES(0); + INSERT INTO counts VALUES(1); + INSERT INTO counts SELECT n+2 FROM counts; + INSERT INTO counts SELECT n+4 FROM counts; + INSERT INTO counts SELECT n+8 FROM counts; + COMMIT; + + CREATE TEMP TABLE x AS + SELECT dim1.n, dim2.n, dim3.n + FROM counts AS dim1, counts AS dim2, counts AS dim3 + WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10; + + SELECT count(*) FROM x; + } + } {1000} + do_test misc2-9.2 { + execsql { + DROP TABLE x; + CREATE TEMP TABLE x AS + SELECT dim1.n, dim2.n, dim3.n + FROM counts AS dim1, counts AS dim2, counts AS dim3 + WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6; + + SELECT count(*) FROM x; + } + } {1000} + do_test misc2-9.3 { + execsql { + DROP TABLE x; + CREATE TEMP TABLE x AS + SELECT dim1.n, dim2.n, dim3.n, dim4.n + FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4 + WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5; + + SELECT count(*) FROM x; + } + } [expr 5*5*5*5] +} finish_test diff --git a/test/misc4.test b/test/misc4.test index cad97ffbb8..91fafb1ace 100644 --- a/test/misc4.test +++ b/test/misc4.test @@ -13,7 +13,7 @@ # This file implements tests for miscellanous features that were # left out of other test files. # -# $Id: misc4.test,v 1.15 2005/01/30 09:17:59 danielk1977 Exp $ +# $Id: misc4.test,v 1.16 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -29,36 +29,39 @@ do_test misc4-1.1 { INSERT INTO t1 VALUES(1); } } {} -do_test misc4-1.2 { - set sql {CREATE TEMP TABLE t2 AS SELECT * FROM t1} - set stmt [sqlite3_prepare $DB $sql -1 TAIL] - execsql { - BEGIN; - CREATE TABLE t3(a,b,c); - INSERT INTO t1 SELECT * FROM t1; - ROLLBACK; - } -} {} -do_test misc4-1.3 { - sqlite3_step $stmt -} SQLITE_DONE -do_test misc4-1.4 { - execsql { - SELECT * FROM temp.t2; - } -} {1} -# Drop the temporary table, then rerun the prepared statement to -# recreate it again. This recreates ticket #807. -# -do_test misc4-1.5 { - execsql {DROP TABLE t2} - sqlite3_reset $stmt - sqlite3_step $stmt -} {SQLITE_ERROR} -do_test misc4-1.6 { - sqlite3_finalize $stmt -} {SQLITE_SCHEMA} +ifcapable tempdb { + do_test misc4-1.2 { + set sql {CREATE TEMP TABLE t2 AS SELECT * FROM t1} + set stmt [sqlite3_prepare $DB $sql -1 TAIL] + execsql { + BEGIN; + CREATE TABLE t3(a,b,c); + INSERT INTO t1 SELECT * FROM t1; + ROLLBACK; + } + } {} + do_test misc4-1.3 { + sqlite3_step $stmt + } SQLITE_DONE + do_test misc4-1.4 { + execsql { + SELECT * FROM temp.t2; + } + } {1} + + # Drop the temporary table, then rerun the prepared statement to + # recreate it again. This recreates ticket #807. + # + do_test misc4-1.5 { + execsql {DROP TABLE t2} + sqlite3_reset $stmt + sqlite3_step $stmt + } {SQLITE_ERROR} + do_test misc4-1.6 { + sqlite3_finalize $stmt + } {SQLITE_SCHEMA} +} # Prepare but do not execute various CREATE statements. Then before # those statements are executed, try to use the tables, indices, views, diff --git a/test/pager3.test b/test/pager3.test index 9c3b6e1669..59a97c52bb 100644 --- a/test/pager3.test +++ b/test/pager3.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is page cache subsystem. # -# $Id: pager3.test,v 1.2 2004/11/04 14:47:13 drh Exp $ +# $Id: pager3.test,v 1.3 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] @@ -36,36 +36,38 @@ source $testdir/tester.tcl # This test was added because the second truncate at NOTE (3) was not # occurring on early versions of SQLite 3.0. # -do_test pager3-1.1 { - execsql { - create table t1(a unique, b); - insert into t1 values(1, 'abcdefghijklmnopqrstuvwxyz'); - insert into t1 values(2, 'abcdefghijklmnopqrstuvwxyz'); - update t1 set b=b||a||b; - update t1 set b=b||a||b; - update t1 set b=b||a||b; - update t1 set b=b||a||b; - update t1 set b=b||a||b; - update t1 set b=b||a||b; - create temp table t2 as select * from t1; - begin; ------- NOTE (1) - create table t3(x); - } - catchsql { - insert into t1 select 4-a, b from t2; ----- NOTE (2) - } - execsql { - rollback; ------- NOTE (3) - } - db close - sqlite3 db test.db - set r ok - ifcapable {integrityck} { - set r [execsql { - pragma integrity_check; - }] - } - set r -} ok +ifcapable tempdb { + do_test pager3-1.1 { + execsql { + create table t1(a unique, b); + insert into t1 values(1, 'abcdefghijklmnopqrstuvwxyz'); + insert into t1 values(2, 'abcdefghijklmnopqrstuvwxyz'); + update t1 set b=b||a||b; + update t1 set b=b||a||b; + update t1 set b=b||a||b; + update t1 set b=b||a||b; + update t1 set b=b||a||b; + update t1 set b=b||a||b; + create temp table t2 as select * from t1; + begin; ------- NOTE (1) + create table t3(x); + } + catchsql { + insert into t1 select 4-a, b from t2; ----- NOTE (2) + } + execsql { + rollback; ------- NOTE (3) + } + db close + sqlite3 db test.db + set r ok + ifcapable {integrityck} { + set r [execsql { + pragma integrity_check; + }] + } + set r + } ok +} finish_test diff --git a/test/pragma.test b/test/pragma.test index abb8ef1340..63dd2e54f7 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -12,7 +12,7 @@ # # This file implements tests for the PRAGMA command. # -# $Id: pragma.test,v 1.34 2005/02/13 23:34:25 drh Exp $ +# $Id: pragma.test,v 1.35 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -330,14 +330,16 @@ catchsql {COMMIT;} # Test schema-query pragmas # ifcapable schema_pragmas { -do_test pragma-6.1 { - set res {} - execsql {SELECT * FROM sqlite_temp_master} - foreach {idx name file} [execsql {pragma database_list}] { - lappend res $idx $name - } - set res -} {0 main 1 temp 2 aux} +ifcapable tempdb { + do_test pragma-6.1 { + set res {} + execsql {SELECT * FROM sqlite_temp_master} + foreach {idx name file} [execsql {pragma database_list}] { + lappend res $idx $name + } + set res + } {0 main 1 temp 2 aux} +} do_test pragma-6.2 { execsql { pragma table_info(t2) @@ -387,13 +389,23 @@ ifcapable {utf16} { } } {1 {unsupported encoding: bogus}} } -do_test pragma-7.3 { - db close - sqlite3 db test.db - execsql { - pragma lock_status; - } -} {main unlocked temp closed} +ifcapable tempdb { + do_test pragma-7.3 { + db close + sqlite3 db test.db + execsql { + pragma lock_status; + } + } {main unlocked temp closed} +} else { + do_test pragma-7.3 { + db close + sqlite3 db test.db + execsql { + pragma lock_status; + } + } {main unlocked} +} #---------------------------------------------------------------------- @@ -673,15 +685,17 @@ do_test pragma-9.8 { PRAGMA temp_store_directory=''; } } {} -do_test pragma-9.9 { - execsql { - PRAGMA temp_store_directory; - PRAGMA temp_store=FILE; - CREATE TEMP TABLE temp_store_directory_test(a integer); - INSERT INTO temp_store_directory_test values (2); - SELECT * FROM temp_store_directory_test; - } -} {2} +ifcapable tempdb { + do_test pragma-9.9 { + execsql { + PRAGMA temp_store_directory; + PRAGMA temp_store=FILE; + CREATE TEMP TABLE temp_store_directory_test(a integer); + INSERT INTO temp_store_directory_test values (2); + SELECT * FROM temp_store_directory_test; + } + } {2} +} do_test pragma-9.10 { catchsql " PRAGMA temp_store_directory='$pwd'; diff --git a/test/quick.test b/test/quick.test index 228a12e862..06ba9e540a 100644 --- a/test/quick.test +++ b/test/quick.test @@ -10,7 +10,7 @@ #*********************************************************************** # This file runs all tests. # -# $Id: quick.test,v 1.34 2005/03/21 04:04:03 danielk1977 Exp $ +# $Id: quick.test,v 1.35 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -19,6 +19,7 @@ proc finish_test {} {} set ISQUICK 1 set EXCLUDE { + alter.test all.test btree2.test btree3.test diff --git a/test/select7.test b/test/select7.test index 4f453669fb..fd0d573d9f 100644 --- a/test/select7.test +++ b/test/select7.test @@ -10,7 +10,7 @@ # focus of this file is testing compute SELECT statements and nested # views. # -# $Id: select7.test,v 1.6 2005/01/26 03:58:37 danielk1977 Exp $ +# $Id: select7.test,v 1.7 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] @@ -19,18 +19,20 @@ source $testdir/tester.tcl ifcapable compound { # A 3-way INTERSECT. Ticket #875 -do_test select7-1.1 { - execsql { - create temp table t1(x); - insert into t1 values('amx'); - insert into t1 values('anx'); - insert into t1 values('amy'); - insert into t1 values('bmy'); - select * from t1 where x like 'a__' - intersect select * from t1 where x like '_m_' - intersect select * from t1 where x like '__x'; - } -} {amx} +ifcapable tempdb { + do_test select7-1.1 { + execsql { + create temp table t1(x); + insert into t1 values('amx'); + insert into t1 values('anx'); + insert into t1 values('amy'); + insert into t1 values('bmy'); + select * from t1 where x like 'a__' + intersect select * from t1 where x like '_m_' + intersect select * from t1 where x like '__x'; + } + } {amx} +} # Nested views do not handle * properly. Ticket #826. diff --git a/test/table.test b/test/table.test index a5279644bd..b1d625381b 100644 --- a/test/table.test +++ b/test/table.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE TABLE statement. # -# $Id: table.test,v 1.38 2005/01/24 10:26:00 danielk1977 Exp $ +# $Id: table.test,v 1.39 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -349,12 +349,16 @@ do_test table-8.3.1 { SELECT sql FROM sqlite_master WHERE name='t4"abc' } } {{CREATE TABLE "t4""abc"(cnt,"max(b+c)")}} -do_test table-8.4 { - execsql2 { - CREATE TEMPORARY TABLE t5 AS SELECT count(*) AS [y'all] FROM [t3"xyz]; - SELECT * FROM t5; - } -} {y'all 1} + +ifcapable tempdb { + do_test table-8.4 { + execsql2 { + CREATE TEMPORARY TABLE t5 AS SELECT count(*) AS [y'all] FROM [t3"xyz]; + SELECT * FROM t5; + } + } {y'all 1} +} + do_test table-8.5 { db close sqlite3 db test.db diff --git a/test/temptable.test b/test/temptable.test index 089749003b..9a3218983d 100644 --- a/test/temptable.test +++ b/test/temptable.test @@ -12,11 +12,16 @@ # # This file implements tests for temporary tables and indices. # -# $Id: temptable.test,v 1.14 2004/06/19 00:16:31 drh Exp $ +# $Id: temptable.test,v 1.15 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl +ifcapable !tempdb { + finish_test + return +} + # Create an alternative connection to the database # do_test temptable-1.0 { diff --git a/test/trans.test b/test/trans.test index a7e942c310..c2eaa7e20e 100644 --- a/test/trans.test +++ b/test/trans.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is database locks. # -# $Id: trans.test,v 1.25 2005/03/11 04:41:40 drh Exp $ +# $Id: trans.test,v 1.26 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] @@ -728,41 +728,47 @@ do_test trans-7.7 { do_test trans-7.8 { execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} } $checksum2 -do_test trans-7.9 { - execsql { - BEGIN; - CREATE TEMP TABLE t3 AS SELECT * FROM t2; - INSERT INTO t2 SELECT * FROM t3; - ROLLBACK; - SELECT md5sum(x,y,z) FROM t2; - } -} $checksum +ifcapable tempdb { + do_test trans-7.9 { + execsql { + BEGIN; + CREATE TEMP TABLE t3 AS SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t3; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } + } $checksum +} do_test trans-7.10 { execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} } $checksum2 -do_test trans-7.11 { - execsql { - BEGIN; - CREATE TEMP TABLE t3 AS SELECT * FROM t2; - INSERT INTO t2 SELECT * FROM t3; - DROP INDEX i2x; - DROP INDEX i2y; - CREATE INDEX i3a ON t3(x); - ROLLBACK; - SELECT md5sum(x,y,z) FROM t2; - } -} $checksum +ifcapable tempdb { + do_test trans-7.11 { + execsql { + BEGIN; + CREATE TEMP TABLE t3 AS SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t3; + DROP INDEX i2x; + DROP INDEX i2y; + CREATE INDEX i3a ON t3(x); + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } + } $checksum +} do_test trans-7.12 { execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} } $checksum2 -do_test trans-7.13 { - execsql { - BEGIN; - DROP TABLE t2; - ROLLBACK; - SELECT md5sum(x,y,z) FROM t2; - } -} $checksum +ifcapable tempdb { + do_test trans-7.13 { + execsql { + BEGIN; + DROP TABLE t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } + } $checksum +} do_test trans-7.14 { execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} } $checksum2 diff --git a/test/trigger1.test b/test/trigger1.test index e80579e425..3864db1005 100644 --- a/test/trigger1.test +++ b/test/trigger1.test @@ -41,13 +41,16 @@ do_test trigger1-1.1.1 { END; } } {1 {no such table: main.no_such_table}} -do_test trigger1-1.1.2 { - catchsql { - CREATE TEMP TRIGGER trig UPDATE ON no_such_table BEGIN - SELECT * from sqlite_master; - END; - } -} {1 {no such table: no_such_table}} + +ifcapable tempdb { + do_test trigger1-1.1.2 { + catchsql { + CREATE TEMP TRIGGER trig UPDATE ON no_such_table BEGIN + SELECT * from sqlite_master; + END; + } + } {1 {no such table: no_such_table}} +} execsql { CREATE TABLE t1(a); @@ -107,17 +110,19 @@ do_test trigger1-1.7 { } } {1 {no such trigger: tr1}} -execsql { - CREATE TEMP TABLE temp_table(a); -} -do_test trigger1-1.8 { +ifcapable tempdb { execsql { - CREATE TRIGGER temp_trig UPDATE ON temp_table BEGIN - SELECT * from sqlite_master; - END; - SELECT count(*) FROM sqlite_master WHERE name = 'temp_trig'; - } -} {0} + CREATE TEMP TABLE temp_table(a); + } + do_test trigger1-1.8 { + execsql { + CREATE TRIGGER temp_trig UPDATE ON temp_table BEGIN + SELECT * from sqlite_master; + END; + SELECT count(*) FROM sqlite_master WHERE name = 'temp_trig'; + } + } {0} +} do_test trigger1-1.9 { catchsql { @@ -215,130 +220,140 @@ do_test trigger1-2.2 { # Create a trigger that refers to a table that might not exist. # -do_test trigger1-3.1 { +ifcapable tempdb { + do_test trigger1-3.1 { + execsql { + CREATE TEMP TABLE t2(x,y); + } + catchsql { + CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(NEW.a,NEW.b); + END; + } + } {0 {}} + do_test trigger-3.2 { + catchsql { + INSERT INTO t1 VALUES(1,2); + SELECT * FROM t2; + } + } {1 {no such table: main.t2}} + do_test trigger-3.3 { + db close + set rc [catch {sqlite3 db test.db} err] + if {$rc} {lappend rc $err} + set rc + } {0} + do_test trigger-3.4 { + catchsql { + INSERT INTO t1 VALUES(1,2); + SELECT * FROM t2; + } + } {1 {no such table: main.t2}} + do_test trigger-3.5 { + catchsql { + CREATE TEMP TABLE t2(x,y); + INSERT INTO t1 VALUES(1,2); + SELECT * FROM t2; + } + } {1 {no such table: main.t2}} + do_test trigger-3.6 { + catchsql { + DROP TRIGGER r1; + CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(NEW.a,NEW.b); + END; + INSERT INTO t1 VALUES(1,2); + SELECT * FROM t2; + } + } {0 {1 2}} + do_test trigger-3.7 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(x,y); + SELECT * FROM t2; + } + } {} + + # There are two versions of trigger-3.8 and trigger-3.9. One that uses + # compound SELECT statements, and another that does not. + ifcapable compound { + do_test trigger1-3.8 { + execsql { + INSERT INTO t1 VALUES(3,4); + SELECT * FROM t1 UNION ALL SELECT * FROM t2; + } + } {1 2 3 4 3 4} + do_test trigger1-3.9 { + db close + sqlite3 db test.db + execsql { + INSERT INTO t1 VALUES(5,6); + SELECT * FROM t1 UNION ALL SELECT * FROM t2; + } + } {1 2 3 4 5 6 3 4} + } ;# ifcapable compound + ifcapable !compound { + do_test trigger1-3.8 { + execsql { + INSERT INTO t1 VALUES(3,4); + SELECT * FROM t1; + SELECT * FROM t2; + } + } {1 2 3 4 3 4} + do_test trigger1-3.9 { + db close + sqlite3 db test.db + execsql { + INSERT INTO t1 VALUES(5,6); + SELECT * FROM t1; + SELECT * FROM t2; + } + } {1 2 3 4 5 6 3 4} + } ;# ifcapable !compound + + do_test trigger1-4.1 { + execsql { + CREATE TEMP TRIGGER r1 BEFORE INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(NEW.a,NEW.b); + END; + INSERT INTO t1 VALUES(7,8); + SELECT * FROM t2; + } + } {3 4 7 8} + do_test trigger1-4.2 { + sqlite3 db2 test.db + execsql { + INSERT INTO t1 VALUES(9,10); + } db2; + db2 close + execsql { + SELECT * FROM t2; + } + } {3 4 7 8} + do_test trigger1-4.3 { + execsql { + DROP TABLE t1; + SELECT * FROM t2; + }; + } {3 4 7 8} + do_test trigger1-4.4 { + db close + sqlite3 db test.db + execsql { + SELECT * FROM t2; + }; + } {3 4 7 8} +} else { execsql { - CREATE TEMP TABLE t2(x,y); - } - catchsql { - CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN - INSERT INTO t2 VALUES(NEW.a,NEW.b); - END; - } -} {0 {}} -do_test trigger-3.2 { - catchsql { - INSERT INTO t1 VALUES(1,2); - SELECT * FROM t2; - } -} {1 {no such table: main.t2}} -do_test trigger-3.3 { - db close - set rc [catch {sqlite3 db test.db} err] - if {$rc} {lappend rc $err} - set rc -} {0} -do_test trigger-3.4 { - catchsql { - INSERT INTO t1 VALUES(1,2); - SELECT * FROM t2; - } -} {1 {no such table: main.t2}} -do_test trigger-3.5 { - catchsql { - CREATE TEMP TABLE t2(x,y); - INSERT INTO t1 VALUES(1,2); - SELECT * FROM t2; - } -} {1 {no such table: main.t2}} -do_test trigger-3.6 { - catchsql { - DROP TRIGGER r1; - CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN - INSERT INTO t2 VALUES(NEW.a,NEW.b); - END; - INSERT INTO t1 VALUES(1,2); - SELECT * FROM t2; - } -} {0 {1 2}} -do_test trigger-3.7 { - execsql { - DROP TABLE t2; CREATE TABLE t2(x,y); - SELECT * FROM t2; - } -} {} - -# There are two versions of trigger-3.8 and trigger-3.9. One that uses -# compound SELECT statements, and another that does not. -ifcapable compound { -do_test trigger-3.8 { - execsql { - INSERT INTO t1 VALUES(3,4); - SELECT * FROM t1 UNION ALL SELECT * FROM t2; - } -} {1 2 3 4 3 4} -do_test trigger-3.9 { - db close - sqlite3 db test.db - execsql { - INSERT INTO t1 VALUES(5,6); - SELECT * FROM t1 UNION ALL SELECT * FROM t2; - } -} {1 2 3 4 5 6 3 4} -} ;# ifcapable compound -ifcapable !compound { -do_test trigger-3.8 { - execsql { - INSERT INTO t1 VALUES(3,4); - SELECT * FROM t1; - SELECT * FROM t2; - } -} {1 2 3 4 3 4} -do_test trigger-3.9 { - db close - sqlite3 db test.db - execsql { - INSERT INTO t1 VALUES(5,6); - SELECT * FROM t1; - SELECT * FROM t2; - } -} {1 2 3 4 5 6 3 4} -} ;# ifcapable !compound - -do_test trigger-4.1 { - execsql { - CREATE TEMP TRIGGER r1 BEFORE INSERT ON t1 BEGIN - INSERT INTO t2 VALUES(NEW.a,NEW.b); - END; - INSERT INTO t1 VALUES(7,8); - SELECT * FROM t2; - } -} {3 4 7 8} -do_test trigger-4.2 { - sqlite3 db2 test.db - execsql { - INSERT INTO t1 VALUES(9,10); - } db2; - db2 close - execsql { - SELECT * FROM t2; - } -} {3 4 7 8} -do_test trigger-4.3 { - execsql { DROP TABLE t1; - SELECT * FROM t2; - }; -} {3 4 7 8} -do_test trigger-4.4 { - db close - sqlite3 db test.db - execsql { - SELECT * FROM t2; - }; -} {3 4 7 8} + INSERT INTO t2 VALUES(3, 4); + INSERT INTO t2 VALUES(7, 8); + } +} -integrity_check trigger-5.1 + +integrity_check trigger1-5.1 # Create a trigger with the same name as a table. Make sure the # trigger works. Then drop the trigger. Make sure the table is @@ -348,10 +363,10 @@ set view_v1 {} ifcapable view { set view_v1 {view v1} } -do_test trigger-6.1 { +do_test trigger1-6.1 { execsql {SELECT type, name FROM sqlite_master} } [concat $view_v1 {table t2}] -do_test trigger-6.2 { +do_test trigger1-6.2 { execsql { CREATE TRIGGER t2 BEFORE DELETE ON t2 BEGIN SELECT RAISE(ABORT,'deletes are not allows'); @@ -359,27 +374,27 @@ do_test trigger-6.2 { SELECT type, name FROM sqlite_master; } } [concat $view_v1 {table t2 trigger t2}] -do_test trigger-6.3 { +do_test trigger1-6.3 { catchsql {DELETE FROM t2} } {1 {deletes are not allows}} -do_test trigger-6.4 { +do_test trigger1-6.4 { execsql {SELECT * FROM t2} } {3 4 7 8} -do_test trigger-6.5 { +do_test trigger1-6.5 { db close sqlite3 db test.db execsql {SELECT type, name FROM sqlite_master} } [concat $view_v1 {table t2 trigger t2}] -do_test trigger-6.6 { +do_test trigger1-6.6 { execsql { DROP TRIGGER t2; SELECT type, name FROM sqlite_master; } } [concat $view_v1 {table t2}] -do_test trigger-6.7 { +do_test trigger1-6.7 { execsql {SELECT * FROM t2} } {3 4 7 8} -do_test trigger-6.8 { +do_test trigger1-6.8 { db close sqlite3 db test.db execsql {SELECT * FROM t2} @@ -390,37 +405,37 @@ integrity_check trigger-7.1 # Check to make sure the name of a trigger can be quoted so that keywords # can be used as trigger names. Ticket #468 # -do_test trigger-8.1 { +do_test trigger1-8.1 { execsql { CREATE TRIGGER 'trigger' AFTER INSERT ON t2 BEGIN SELECT 1; END; SELECT name FROM sqlite_master WHERE type='trigger'; } } {trigger} -do_test trigger-8.2 { +do_test trigger1-8.2 { execsql { DROP TRIGGER 'trigger'; SELECT name FROM sqlite_master WHERE type='trigger'; } } {} -do_test trigger-8.3 { +do_test trigger1-8.3 { execsql { CREATE TRIGGER "trigger" AFTER INSERT ON t2 BEGIN SELECT 1; END; SELECT name FROM sqlite_master WHERE type='trigger'; } } {trigger} -do_test trigger-8.4 { +do_test trigger1-8.4 { execsql { DROP TRIGGER "trigger"; SELECT name FROM sqlite_master WHERE type='trigger'; } } {} -do_test trigger-8.5 { +do_test trigger1-8.5 { execsql { CREATE TRIGGER [trigger] AFTER INSERT ON t2 BEGIN SELECT 1; END; SELECT name FROM sqlite_master WHERE type='trigger'; } } {trigger} -do_test trigger-8.6 { +do_test trigger1-8.6 { execsql { DROP TRIGGER [trigger]; SELECT name FROM sqlite_master WHERE type='trigger'; @@ -432,7 +447,7 @@ do_test trigger-8.6 { # There are two versions of trigger-9.1 and trigger-9.2. One that uses # compound SELECT statements, and another that does not. ifcapable compound { -do_test trigger-9.1 { +do_test trigger1-9.1 { execsql { CREATE TABLE t3(a,b); CREATE TABLE t4(x UNIQUE, b); @@ -443,7 +458,7 @@ do_test trigger-9.1 { SELECT * FROM t3 UNION ALL SELECT 99, 99 UNION ALL SELECT * FROM t4; } } {1 2 99 99 1 2} -do_test trigger-9.2 { +do_test trigger1-9.2 { execsql { INSERT INTO t3 VALUES(1,3); SELECT * FROM t3 UNION ALL SELECT 99, 99 UNION ALL SELECT * FROM t4; @@ -451,7 +466,7 @@ do_test trigger-9.2 { } {1 2 1 3 99 99 1 3} } ifcapable !compound { -do_test trigger-9.1 { +do_test trigger1-9.1 { execsql { CREATE TABLE t3(a,b); CREATE TABLE t4(x UNIQUE, b); @@ -462,7 +477,7 @@ do_test trigger-9.1 { SELECT * FROM t3; SELECT 99, 99; SELECT * FROM t4; } } {1 2 99 99 1 2} -do_test trigger-9.2 { +do_test trigger1-9.2 { execsql { INSERT INTO t3 VALUES(1,3); SELECT * FROM t3; SELECT 99, 99; SELECT * FROM t4; @@ -483,93 +498,95 @@ execsql { # Also verify that references within trigger programs are resolved at # statement compile time, not trigger installation time. This means, for # example, that you can drop and re-create tables referenced by triggers. -do_test trigger-10.0 { - file delete -force test2.db - file delete -force test2.db-journal - execsql { - ATTACH 'test2.db' AS aux; - } -} {} -do_test trigger-10.1 { - execsql { - CREATE TABLE main.t4(a, b, c); - CREATE TABLE temp.t4(a, b, c); - CREATE TABLE aux.t4(a, b, c); - CREATE TABLE insert_log(db, a, b, c); - } -} {} -do_test trigger-10.2 { - execsql { - CREATE TEMP TRIGGER trig1 AFTER INSERT ON main.t4 BEGIN - INSERT INTO insert_log VALUES('main', new.a, new.b, new.c); - END; - CREATE TEMP TRIGGER trig2 AFTER INSERT ON temp.t4 BEGIN - INSERT INTO insert_log VALUES('temp', new.a, new.b, new.c); - END; - CREATE TEMP TRIGGER trig3 AFTER INSERT ON aux.t4 BEGIN - INSERT INTO insert_log VALUES('aux', new.a, new.b, new.c); - END; - } -} {} -do_test trigger-10.3 { - execsql { - INSERT INTO main.t4 VALUES(1, 2, 3); - INSERT INTO temp.t4 VALUES(4, 5, 6); - INSERT INTO aux.t4 VALUES(7, 8, 9); - } -} {} -do_test trigger-10.4 { - execsql { - SELECT * FROM insert_log; - } -} {main 1 2 3 temp 4 5 6 aux 7 8 9} -do_test trigger-10.5 { - execsql { - BEGIN; - INSERT INTO main.t4 VALUES(1, 2, 3); - INSERT INTO temp.t4 VALUES(4, 5, 6); - INSERT INTO aux.t4 VALUES(7, 8, 9); - ROLLBACK; - } -} {} -do_test trigger-10.6 { - execsql { - SELECT * FROM insert_log; - } -} {main 1 2 3 temp 4 5 6 aux 7 8 9} -do_test trigger-10.7 { - execsql { - DELETE FROM insert_log; - INSERT INTO main.t4 VALUES(11, 12, 13); - INSERT INTO temp.t4 VALUES(14, 15, 16); - INSERT INTO aux.t4 VALUES(17, 18, 19); - } -} {} -do_test trigger-10.8 { - execsql { - SELECT * FROM insert_log; - } -} {main 11 12 13 temp 14 15 16 aux 17 18 19} -do_test trigger-10.8 { -# Drop and re-create the insert_log table in a different database. Note -# that we can change the column names because the trigger programs don't -# use them explicitly. - execsql { - DROP TABLE insert_log; - CREATE TABLE aux.insert_log(db, d, e, f); - } -} {} -do_test trigger-10.10 { - execsql { - INSERT INTO main.t4 VALUES(21, 22, 23); - INSERT INTO temp.t4 VALUES(24, 25, 26); - INSERT INTO aux.t4 VALUES(27, 28, 29); - } -} {} -do_test trigger-10.11 { - execsql { - SELECT * FROM insert_log; - } -} {main 21 22 23 temp 24 25 26 aux 27 28 29} +ifcapable tempdb { + do_test trigger1-10.0 { + file delete -force test2.db + file delete -force test2.db-journal + execsql { + ATTACH 'test2.db' AS aux; + } + } {} + do_test trigger1-10.1 { + execsql { + CREATE TABLE main.t4(a, b, c); + CREATE TABLE temp.t4(a, b, c); + CREATE TABLE aux.t4(a, b, c); + CREATE TABLE insert_log(db, a, b, c); + } + } {} + do_test trigger1-10.2 { + execsql { + CREATE TEMP TRIGGER trig1 AFTER INSERT ON main.t4 BEGIN + INSERT INTO insert_log VALUES('main', new.a, new.b, new.c); + END; + CREATE TEMP TRIGGER trig2 AFTER INSERT ON temp.t4 BEGIN + INSERT INTO insert_log VALUES('temp', new.a, new.b, new.c); + END; + CREATE TEMP TRIGGER trig3 AFTER INSERT ON aux.t4 BEGIN + INSERT INTO insert_log VALUES('aux', new.a, new.b, new.c); + END; + } + } {} + do_test trigger1-10.3 { + execsql { + INSERT INTO main.t4 VALUES(1, 2, 3); + INSERT INTO temp.t4 VALUES(4, 5, 6); + INSERT INTO aux.t4 VALUES(7, 8, 9); + } + } {} + do_test trigger1-10.4 { + execsql { + SELECT * FROM insert_log; + } + } {main 1 2 3 temp 4 5 6 aux 7 8 9} + do_test trigger1-10.5 { + execsql { + BEGIN; + INSERT INTO main.t4 VALUES(1, 2, 3); + INSERT INTO temp.t4 VALUES(4, 5, 6); + INSERT INTO aux.t4 VALUES(7, 8, 9); + ROLLBACK; + } + } {} + do_test trigger1-10.6 { + execsql { + SELECT * FROM insert_log; + } + } {main 1 2 3 temp 4 5 6 aux 7 8 9} + do_test trigger1-10.7 { + execsql { + DELETE FROM insert_log; + INSERT INTO main.t4 VALUES(11, 12, 13); + INSERT INTO temp.t4 VALUES(14, 15, 16); + INSERT INTO aux.t4 VALUES(17, 18, 19); + } + } {} + do_test trigger1-10.8 { + execsql { + SELECT * FROM insert_log; + } + } {main 11 12 13 temp 14 15 16 aux 17 18 19} + do_test trigger1-10.8 { + # Drop and re-create the insert_log table in a different database. Note + # that we can change the column names because the trigger programs don't + # use them explicitly. + execsql { + DROP TABLE insert_log; + CREATE TABLE aux.insert_log(db, d, e, f); + } + } {} + do_test trigger1-10.10 { + execsql { + INSERT INTO main.t4 VALUES(21, 22, 23); + INSERT INTO temp.t4 VALUES(24, 25, 26); + INSERT INTO aux.t4 VALUES(27, 28, 29); + } + } {} + do_test trigger1-10.11 { + execsql { + SELECT * FROM insert_log; + } + } {main 21 22 23 temp 24 25 26 aux 27 28 29} +} finish_test diff --git a/test/trigger2.test b/test/trigger2.test index 9dc03ef44b..55f7bb9c29 100644 --- a/test/trigger2.test +++ b/test/trigger2.test @@ -57,15 +57,20 @@ ifcapable {!trigger} { # 1. ifcapable subquery { set ii 0 - foreach tbl_defn { - {CREATE TEMP TABLE tbl (a, b);} - {CREATE TABLE tbl (a, b);} - {CREATE TABLE tbl (a INTEGER PRIMARY KEY, b);} - {CREATE TEMPORARY TABLE tbl (a INTEGER PRIMARY KEY, b);} - {CREATE TABLE tbl (a, b PRIMARY KEY);} - {CREATE TABLE tbl (a, b); CREATE INDEX tbl_idx ON tbl(b);} - {CREATE TEMP TABLE tbl (a, b); CREATE INDEX tbl_idx ON tbl(b);} - } { + set tbl_definitions [list \ + {CREATE TABLE tbl (a, b);} \ + {CREATE TABLE tbl (a INTEGER PRIMARY KEY, b);} \ + {CREATE TABLE tbl (a, b PRIMARY KEY);} \ + {CREATE TABLE tbl (a, b); CREATE INDEX tbl_idx ON tbl(b);} \ + ] + ifcapable tempdb { + lappend tbl_definitions \ + {CREATE TEMP TABLE tbl (a, b); CREATE INDEX tbl_idx ON tbl(b);} + lappend tbl_definitions {CREATE TEMP TABLE tbl (a, b);} + lappend tbl_definitions \ + {CREATE TEMPORARY TABLE tbl (a INTEGER PRIMARY KEY, b);} + } + foreach tbl_defn $tbl_definitions { incr ii catchsql { DROP INDEX tbl_idx; } catchsql { diff --git a/test/vacuum.test b/test/vacuum.test index 5ba851710b..a5d9d151bb 100644 --- a/test/vacuum.test +++ b/test/vacuum.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the VACUUM statement. # -# $Id: vacuum.test,v 1.34 2005/02/12 00:19:30 drh Exp $ +# $Id: vacuum.test,v 1.35 2005/03/29 03:11:00 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -239,11 +239,12 @@ do_test vacuum-5.1 { CREATE VIEW viewTest AS SELECT * FROM Test; BEGIN; - CREATE TEMP TABLE tempTest (TestID int primary key, Test2 int NULL); + CREATE TABLE tempTest (TestID int primary key, Test2 int NULL); INSERT INTO tempTest SELECT TestID, 1 FROM Test; DROP TABLE Test; CREATE TABLE Test(TestID int primary key, Test2 int NULL); INSERT INTO Test SELECT * FROM tempTest; + DROP TABLE tempTest; COMMIT; VACUUM; }