diff --git a/main.mk b/main.mk index ed3db27fb4..68c3e313b9 100644 --- a/main.mk +++ b/main.mk @@ -172,7 +172,6 @@ TESTSRC = \ $(TOP)/src/date.c \ $(TOP)/src/func.c \ $(TOP)/src/insert.c \ - $(TOP)/src/main.c \ $(TOP)/src/malloc.c \ $(TOP)/src/os.c \ $(TOP)/src/os_os2.c \ diff --git a/manifest b/manifest index 7ef96f6c16..727be3b5cb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stest\sfor\smalloc()\sfailure\swhen\scompiling\sa\strigger\sstep\sof\sthe\sform\s"INSERT\sINTO\s...\sSELECT\s...".\sCurrently\scauses\sa\ssegfault.\s(CVS\s4232) -D 2007-08-16T04:39:01 +C More\swork\son\srefactoring\sof\smalloc()\sinterfaces.\sThere\sare\sstill\smany\serrors.\s(CVS\s4233) +D 2007-08-16T10:09:02 F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -51,7 +51,7 @@ F ext/icu/README.txt 3b130aa66e7a681136f6add198b076a2f90d1e33 F ext/icu/icu.c 61a345d8126686aa3487aa8d2d0f68abd655f7a4 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 F ltmain.sh 56abb507100ed2d4261f6dd1653dec3cf4066387 -F main.mk dad2269dd2a097892536482c12acaab001e930c2 +F main.mk 659cad1c400ab92948087d46c499e0330215db7b F mkdll.sh 37fa8a7412e51b5ab2bc6d4276135f022a0feffb F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb @@ -64,33 +64,33 @@ F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2 F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc F sqlite3.def a96c1d0d39362b763d2ddba220a32da41a15c4b4 F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a -F src/alter.c 27b0c0d371a825f9a8b7198a3f3f94c2e027f25e -F src/analyze.c e2bbd2510b4009bc9839e32ceac21ac1bd711f37 +F src/alter.c f0aac0060ae8102e58f210b44d35b53438d53173 +F src/analyze.c a14237d869c6bea0846493b59317e4097e81a0b6 F src/attach.c a52225c75b107be8c5bc144a2b6d20201be3f8f8 F src/auth.c 5ea90bc93dfea46e9fe4bf531e14c7cd98219ecb -F src/btree.c 1f7c009817a03a3cbf4f78d4d373543d89ebc890 +F src/btree.c f371e9d7a24ba330c108bf1bb795280051f696ac F src/btree.h 1d527bf61ed176f980c34999d5793a0fd45dcf8c F src/btreeInt.h ac1ab1fb624ffbe571786cd2bd9559f9ae336355 -F src/build.c a25bf9d25623c7730bc58922e0e84204ad98c968 -F src/callback.c 5680c2b84177e52c54b42e94291d30b4b6ed2126 -F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675 -F src/date.c 6c6ae019e78fec543988c8d907fa9524dc2c2934 +F src/build.c 923d6643c8f59fbcd10cd9e2f2690e82f48db69e +F src/callback.c 143436453bb93e831c9574fea0b9b9eb90e40ff3 +F src/complete.c ea63834e798a0ab14159bdc6e6cabc3df21aa346 +F src/date.c c44aa498ee9a289ba2b2c62e8269b74b1b81351f F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b -F src/expr.c 002266066377f542e776448e04816d2a887d7dc3 -F src/func.c bd94a8aabeecc741df71afba856133738f1c1638 -F src/hash.c 05ebefb85d77caed0454408ee1e069702d289bff +F src/expr.c beb6b40974ddb22d683b8239d635c37f28b16f95 +F src/func.c 4195c626d09662a2cc040a35057f2b3828dd7465 +F src/hash.c 2f322979071dd2bdba7503b5276d66f028744382 F src/hash.h 3ad3da76bfb954978d227bf495568b0e6da2c19e F src/insert.c bca11ad7b7ab4a1ba4808b6e0a6fd842923f88bb F src/legacy.c 6013a7cb7da1b72550b3d35d4fc598b3c3e5b8c1 F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35 F src/loadext.c aa1c6e584d39cc241226ec9390387bc2d4a23e8f -F src/main.c 7850774e64fc1f804a3f91a8a66ba4215e9fa05b -F src/malloc.c bec719bda3db0ea797b03c5e6536b125d0e618ff +F src/main.c 47c6d4918394cf86e38502527ca652ac0602fac1 +F src/malloc.c 613c65f12ff0ee4edd017aa458209ab7a23cd7b1 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/mem1.c 6d4b9efe51242fcc63d410fb326824f1208b3d4e F src/mem2.c d0ba3b23da2e95bced1818ade8a8a2dc9526111c -F src/mutex.c 667dae0de95f8fb92a3ffc8c3f20c0d26115a1a6 +F src/mutex.c b4f963ebdcb0622b3026937826afefd8a05884e1 F src/os.c e2faefbe0f5a8ca5e3b1c49ee1b5c6cfa0f0e279 F src/os.h 8eff07babf74e5bc3f895f8a6c7c294dad5ff997 F src/os_common.h a5c446d3b93f09f369d13bf217de4bed3437dd1c @@ -98,34 +98,34 @@ F src/os_os2.c cba4e96fadb949076c717108fe0599d1a3c2e446 F src/os_os2.h e5f17dd69333632bbc3112881ea407c37d245eb3 F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3 -F src/os_unix.c 67601899b573c8a7a23aee9d3eeeb7aa724501ee +F src/os_unix.c 7c7dcb7dcc93fcecf870d070fe9de8e2e7a44167 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c d868d5f9e95ec9c1b9e2a30c54c996053db6dddd F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c ddb0279c4030128b2f06cdd02b68ae266a8f4fe7 +F src/pager.c 812a3f78ea398764991d668d2d3d81a951e58fa3 F src/pager.h 94110a5570dca30d54a883e880a3633b2e4c05ae -F src/parse.y 4934dc7e7a679f71359420de11aae7c281a73151 -F src/pragma.c 9ecc2bcd790fc1723a5f78ff46493ce4d2b77ced -F src/prepare.c 237ed8ce0509da9e28a4773b96ec4c44015b970e -F src/printf.c 326386450a8fa31853503b3a8cc758d72d41fc7e +F src/parse.y c03529c3b82702ada98ce405b390e3a9409708cf +F src/pragma.c 873b0b2ab56248ef76d0387193b8f7a87782b73c +F src/prepare.c 03292beeffce2d65debab12508a8ec1f5aec7241 +F src/printf.c a8f46e0ed360c18d40e89aa636533be300b406c2 F src/random.c 6119474a6f6917f708c1dee25b9a8e519a620e88 -F src/select.c 4df152ea0cd13b37cc4e41c56cad7c8ed2d9718c +F src/select.c 98c367bce3f38c5adfcc97de9ab5c79b0e5dc2b2 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/shell.c ac29402b538515fa4697282387be9c1205e6e9eb F src/sqlite.h.in 165913eb3426fbaa8a2a51d87f84593bfe5bee15 -F src/sqlite3ext.h a27bedc222df5e5f0f458ac99726d0483b953a91 -F src/sqliteInt.h acdc2d5b997504c3b1d1cc7ac31ec064f23c26b5 +F src/sqlite3ext.h 647a6b8a8f76ff6c9611e4a071531d8e63ff2d6b +F src/sqliteInt.h 2649e0cbf0073e0d5c88080c642de4a3bac58c09 F src/sqliteLimit.h f14609c27636ebc217c9603ade26dbdd7d0f6afa -F src/table.c a8de75bcedf84d4060d804264b067ab3b1a3561d +F src/table.c c725e47f6f3092b9a7b569fc58e408e2173ee008 F src/tclsqlite.c 0606c4f31711492eb4d7480a981eebb80914f3d9 -F src/test1.c b5b36bdf40a78e351cb0def7bc900991adcc4c4f -F src/test2.c 5c3edc610852a8f67990cd08c5d5dbb79e3f8db9 -F src/test3.c 497ed07038ea79ab683b0beba6a39c89540ce632 +F src/test1.c f2969f28574433743f7439da62f0cfd9063fc26b +F src/test2.c 4db48e4a487d4d18c2926d9600875613ad286ba8 +F src/test3.c c337cff70c3bf9c30f77e953106ef7ddf655dd51 F src/test4.c d22cb3ab4f9fdfd0a595b70d5328cee923b7322c -F src/test5.c 27f3aa4eebfec94769d199f85212708ec77536c7 -F src/test6.c b0aea6299100bee055ff9d8f30d87e393384e607 +F src/test5.c 7bc8a87c2b6fd076ec2ca9972946e71a367883ad +F src/test6.c 14919eef8504da6814db7ab19608c786d836fcb2 F src/test7.c 91d914c2c2b2806157213f41f4185ad3a4970c07 -F src/test8.c 95c9e0639e555768e15f88c87ae805c10340d8c2 +F src/test8.c 0dc64e1a676df556cbcc3f7fcbaa583d7f234826 F src/test9.c c0f38f7795cc51d37db6c63874d90f40f10d0f0e F src/test_async.c 871ffbe4a520be74b403aca87aa622ebdb690232 F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436 @@ -138,22 +138,22 @@ F src/test_md5.c d9f828765b242ff86f58cd879259c3da4eaede02 F src/test_schema.c 12c9de7661d6294eec2d57afbb52e2af1128084f F src/test_server.c 76c0baf509abe65ca6e5c7974ab0097cfdd8b833 F src/test_tclvar.c 51f69f526ed4a044dc7c13c7badccd33cb41132b -F src/tokenize.c 418842048447c6d0889fd2e0b414288615d28aaa -F src/trigger.c f29b1d40a329f33dd683b500cc5d493f2acb9558 -F src/update.c b20d7730bfe46367a8d3f540a0b0632840c82fec -F src/utf.c e2212080d74559a1a351ab4d235b97f522132995 -F src/util.c c831d17623ffb0e09a3710f8f679eeeb42a423c2 +F src/tokenize.c 3a3fd71cfb2abb8e11ed6ab6b764b790c534defc +F src/trigger.c dccc6fbf37d12193c90ede5b026bbd195d505ff4 +F src/update.c e89b980b443d44b68bfc0b1746cdb6308e049ac9 +F src/utf.c 853f97ce0d3cff8dbaef517a6dc475f7001a67c5 +F src/util.c 0273ba16dbf9bab423b1b84c6d548d8f14c25f64 F src/vacuum.c f45bd9d3aad8d68bb3b85cf89d7a797be5075fde -F src/vdbe.c dd6f17be86fde2ca07d4b065ed79815a617615cd +F src/vdbe.c 10052a4f1e42e629aee0466b40983e2b61e0295a F src/vdbe.h 001c5b257567c1d3de7feb2203aac71d0d7b16a3 -F src/vdbeInt.h 0629275fd265cf1ba039c08e1d41c91258f02f64 -F src/vdbeapi.c fce4ee6ab2cb8fd209f53b8a9261603c82993b8c -F src/vdbeaux.c e59e50659a5e19298e6b3e21e7ae309d43607305 +F src/vdbeInt.h e0bd068cf607dcb10021aefa9390b96f56fc3e03 +F src/vdbeapi.c ca82e14ac4ef0c15d7ed8851b0bf9377d7eb0058 +F src/vdbeaux.c aa079bb65d3ebe81eab4765c26c3e69deabc6825 F src/vdbeblob.c cf9ee3c7d9977cbd896f8b118da4fb4268637f4f F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6 -F src/vdbemem.c 59fde3ec6178bee1e6200a524c2cf5937cfe33ab -F src/vtab.c ea2557202d0e6d01dc810be9007a63e1ef357820 -F src/where.c 366bfb2b03b1b1fa63dc6a1b14f86509fe0d12ed +F src/vdbemem.c 52ec18736ff0203cd34a1b55043027a312f23646 +F src/vtab.c 8d65679ab4ef3efce5d946d7f2d2dac5a33313b4 +F src/where.c b5af62312d2ac6b22897cd0f06fb0eca477d8589 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/all.test 56bc526a6cbb262c5b678dd606de8c92ae39705e @@ -529,7 +529,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P deb7ecd65f7b83eaf0ba610eeef3b0ede61db1c3 -R cf90298b3b3d07ca81013abb6b566a4c +P 161643a694458e76849cd663f277892ae7c6b729 +R 78bb61c2e514dbedee0545c75b0d9447 U danielk1977 -Z d365a125dcbfa4a995190ff632cb9301 +Z 4f8b342764fab083222a09714d137d45 diff --git a/manifest.uuid b/manifest.uuid index 1398c8c2c2..743147b3de 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -161643a694458e76849cd663f277892ae7c6b729 \ No newline at end of file +77b1671351fe94b0ebc126a63140643deae2aa64 \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index 88fe11bc6f..93748520e3 100644 --- a/src/alter.c +++ b/src/alter.c @@ -12,7 +12,7 @@ ** This file contains C code routines that used to generate VDBE code ** that implements the ALTER TABLE command. ** -** $Id: alter.c,v 1.28 2007/08/16 04:30:39 drh Exp $ +** $Id: alter.c,v 1.29 2007/08/16 10:09:02 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -51,6 +51,8 @@ static void renameTableFunc( int len = 0; char *zRet; + sqlite3 *db = sqlite3_user_data(context); + /* The principle used to locate the table name in the CREATE TABLE ** statement is that the table name is the first token that is immediatedly ** followed by a left parenthesis - TK_LP - or "USING" TK_USING. @@ -76,9 +78,9 @@ static void renameTableFunc( assert( len>0 ); } while( token!=TK_LP && token!=TK_USING ); - zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql, + zRet = sqlite3MPrintf(db, "%.*s%Q%s", tname.z - zSql, zSql, zTableName, tname.z+tname.n); - sqlite3_result_text(context, zRet, -1, sqlite3FreeX); + sqlite3_result_text(context, zRet, -1, sqlite3_free); } } @@ -105,6 +107,8 @@ static void renameTriggerFunc( int len = 0; char *zRet; + sqlite3 *db = sqlite3_user_data(context); + /* The principle used to locate the table name in the CREATE TRIGGER ** statement is that the table name is the first token that is immediatedly ** preceded by either TK_ON or TK_DOT and immediatedly followed by one @@ -149,9 +153,9 @@ static void renameTriggerFunc( /* Variable tname now contains the token that is the old table-name ** in the CREATE TRIGGER statement. */ - zRet = sqlite3MPrintf("%.*s%Q%s", tname.z - zSql, zSql, + zRet = sqlite3MPrintf(db, "%.*s%Q%s", tname.z - zSql, zSql, zTableName, tname.z+tname.n); - sqlite3_result_text(context, zRet, -1, sqlite3FreeX); + sqlite3_result_text(context, zRet, -1, sqlite3_free); } } #endif /* !SQLITE_OMIT_TRIGGER */ @@ -174,7 +178,7 @@ void sqlite3AlterFunctions(sqlite3 *db){ for(i=0; ipSchema!=pTempSchema ){ + sqlite3 *db = pParse->db; for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){ if( pTrig->pSchema==pTempSchema ){ if( !zWhere ){ - zWhere = sqlite3MPrintf("name=%Q", pTrig->name); + zWhere = sqlite3MPrintf(db, "name=%Q", pTrig->name); }else{ tmp = zWhere; - zWhere = sqlite3MPrintf("%s OR name=%Q", zWhere, pTrig->name); + zWhere = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, pTrig->name); sqlite3_free(tmp); } } @@ -245,7 +250,7 @@ static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){ sqlite3VdbeOp3(v, OP_DropTable, iDb, 0, pTab->zName, 0); /* Reload the table, index and permanent trigger schemas. */ - zWhere = sqlite3MPrintf("tbl_name=%Q", zName); + zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName); if( !zWhere ) return; sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, zWhere, P3_DYNAMIC); @@ -487,7 +492,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ */ if( pDflt ){ sqlite3_value *pVal; - if( sqlite3ValueFromExpr(pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){ + if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){ db->mallocFailed = 1; return; } diff --git a/src/analyze.c b/src/analyze.c index 7ce218d66e..497fe72949 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code associated with the ANALYZE command. ** -** @(#) $Id: analyze.c,v 1.20 2007/08/16 04:30:39 drh Exp $ +** @(#) $Id: analyze.c,v 1.21 2007/08/16 10:09:02 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_ANALYZE #include "sqliteInt.h" @@ -397,7 +397,7 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){ /* Load new statistics out of the sqlite_stat1 table */ - zSql = sqlite3MPrintf("SELECT idx, stat FROM %Q.sqlite_stat1", + zSql = sqlite3MPrintf(db, "SELECT idx, stat FROM %Q.sqlite_stat1", sInfo.zDatabase); sqlite3SafetyOff(db); rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0); diff --git a/src/btree.c b/src/btree.c index 31c64311ed..ea2651a35d 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.397 2007/08/16 04:30:39 drh Exp $ +** $Id: btree.c,v 1.398 2007/08/16 10:09:02 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -5741,7 +5741,7 @@ static void checkAppendMsg( pCheck->mxErr--; pCheck->nErr++; va_start(ap, zFormat); - zMsg2 = sqlite3VMPrintf(zFormat, ap); + zMsg2 = sqlite3VMPrintf(0, zFormat, ap); va_end(ap); if( zMsg1==0 ) zMsg1 = ""; if( pCheck->zErrMsg ){ @@ -6091,7 +6091,7 @@ char *sqlite3BtreeIntegrityCheck( if( !sCheck.anRef ){ unlockBtreeIfUnused(pBt); *pnErr = 1; - return sqlite3MPrintf("Unable to malloc %d bytes", + return sqlite3MPrintf(p->pSqlite, "Unable to malloc %d bytes", (sCheck.nPage+1)*sizeof(sCheck.anRef[0])); } for(i=0; i<=sCheck.nPage; i++){ sCheck.anRef[i] = 0; } diff --git a/src/build.c b/src/build.c index 09ab2e8170..510682f411 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.434 2007/08/16 04:30:39 drh Exp $ +** $Id: build.c,v 1.435 2007/08/16 10:09:02 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -235,10 +235,9 @@ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ if( pParse->nErr ) return; assert( pParse->nested<10 ); /* Nesting should only be of limited depth */ va_start(ap, zFormat); - zSql = sqlite3VMPrintf(zFormat, ap); + zSql = sqlite3VMPrintf(pParse->db, zFormat, ap); va_end(ap); if( zSql==0 ){ - pParse->db->mallocFailed = 1; return; /* A malloc must have failed */ } pParse->nested++; @@ -1498,10 +1497,12 @@ void sqlite3EndTable( /* Compute the complete text of the CREATE statement */ if( pSelect ){ - zStmt = createTableStmt(p, p->pSchema==pParse->db->aDb[1].pSchema); + zStmt = createTableStmt(p, p->pSchema==db->aDb[1].pSchema); }else{ n = pEnd->z - pParse->sNameToken.z + 1; - zStmt = sqlite3MPrintf("CREATE %s %.*s", zType2, n, pParse->sNameToken.z); + zStmt = sqlite3MPrintf(db, + "CREATE %s %.*s", zType2, n, pParse->sNameToken.z + ); } /* A slot for the record has already been allocated in the @@ -1540,7 +1541,7 @@ void sqlite3EndTable( /* Reparse everything to update our internal data structures */ sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, - sqlite3MPrintf("tbl_name='%q'",p->zName), P3_DYNAMIC); + sqlite3MPrintf(db, "tbl_name='%q'",p->zName), P3_DYNAMIC); } @@ -2405,7 +2406,7 @@ void sqlite3CreateIndex( if( pList==0 ){ nullId.z = (u8*)pTab->aCol[pTab->nCol-1].zName; nullId.n = strlen((char*)nullId.z); - pList = sqlite3ExprListAppend(0, 0, &nullId); + pList = sqlite3ExprListAppend(pParse, 0, 0, &nullId); if( pList==0 ) goto exit_create_index; pList->a[0].sortOrder = sortOrder; } @@ -2607,7 +2608,7 @@ void sqlite3CreateIndex( */ if( pStart && pEnd ){ /* A named index with an explicit CREATE INDEX statement */ - zStmt = sqlite3MPrintf("CREATE%s INDEX %.*s", + zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s", onError==OE_None ? "" : " UNIQUE", pEnd->z - pName->z + 1, pName->z); @@ -2636,7 +2637,7 @@ void sqlite3CreateIndex( sqlite3RefillIndex(pParse, pIndex, iMem); sqlite3ChangeCookie(db, v, iDb); sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, - sqlite3MPrintf("name='%q'", pIndex->zName), P3_DYNAMIC); + sqlite3MPrintf(db, "name='%q'", pIndex->zName), P3_DYNAMIC); sqlite3VdbeAddOp(v, OP_Expire, 0, 0); } } @@ -3366,7 +3367,7 @@ KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){ int i; int nCol = pIdx->nColumn; int nBytes = sizeof(KeyInfo) + (nCol-1)*sizeof(CollSeq*) + nCol; - KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZer(pParse->db, nBytes); + KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZero(pParse->db, nBytes); if( pKey ){ pKey->aSortOrder = (u8 *)&(pKey->aColl[nCol]); diff --git a/src/callback.c b/src/callback.c index 1b2fff1303..9c0df707b6 100644 --- a/src/callback.c +++ b/src/callback.c @@ -13,7 +13,7 @@ ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** -** $Id: callback.c,v 1.19 2007/08/16 04:30:39 drh Exp $ +** $Id: callback.c,v 1.20 2007/08/16 10:09:02 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -35,9 +35,9 @@ static void callCollNeeded(sqlite3 *db, const char *zName, int nName){ #ifndef SQLITE_OMIT_UTF16 if( db->xCollNeeded16 ){ char const *zExternal; - sqlite3_value *pTmp = sqlite3ValueNew(); - sqlite3ValueSetStr(pTmp, nName, zName, SQLITE_UTF8, SQLITE_STATIC); - zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE); + sqlite3_value *pTmp = sqlite3ValueNew(db); + sqlite3ValueSetStr(db, pTmp, nName, zName, SQLITE_UTF8, SQLITE_STATIC); + zExternal = sqlite3ValueText(db, pTmp, SQLITE_UTF16NATIVE); if( zExternal ){ db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal); } diff --git a/src/complete.c b/src/complete.c index 536ffadbc2..052b9ab1e9 100644 --- a/src/complete.c +++ b/src/complete.c @@ -16,7 +16,7 @@ ** separating it out, the code will be automatically omitted from ** static links that do not use it. ** -** $Id: complete.c,v 1.3 2006/01/18 15:25:17 danielk1977 Exp $ +** $Id: complete.c,v 1.4 2007/08/16 10:09:02 danielk1977 Exp $ */ #include "sqliteInt.h" #ifndef SQLITE_OMIT_COMPLETE @@ -248,11 +248,11 @@ int sqlite3_complete(const char *zSql){ int sqlite3_complete16(const void *zSql){ sqlite3_value *pVal; char const *zSql8; - int rc = 0; + int rc = SQLITE_NOMEM; - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC); - zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8); + pVal = sqlite3ValueNew(0); + sqlite3ValueSetStr(0, pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC); + zSql8 = sqlite3ValueText(0, pVal, SQLITE_UTF8); if( zSql8 ){ rc = sqlite3_complete(zSql8); } diff --git a/src/date.c b/src/date.c index d1b80038e1..ec2d34ab8f 100644 --- a/src/date.c +++ b/src/date.c @@ -16,7 +16,7 @@ ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.67 2007/08/16 04:30:40 drh Exp $ +** $Id: date.c,v 1.68 2007/08/16 10:09:03 danielk1977 Exp $ ** ** SQLite processes all times and dates as Julian Day numbers. The ** dates and times are stored as the number of days since noon @@ -894,9 +894,9 @@ static void ctimeFunc( int argc, sqlite3_value **argv ){ - sqlite3_value *pVal = sqlite3ValueNew(); + sqlite3_value *pVal = sqlite3ValueNew(0); if( pVal ){ - sqlite3ValueSetStr(pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC); + sqlite3ValueSetStr(0, pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC); timeFunc(context, 1, &pVal); sqlite3ValueFree(pVal); } @@ -912,9 +912,9 @@ static void cdateFunc( int argc, sqlite3_value **argv ){ - sqlite3_value *pVal = sqlite3ValueNew(); + sqlite3_value *pVal = sqlite3ValueNew(0); if( pVal ){ - sqlite3ValueSetStr(pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC); + sqlite3ValueSetStr(0, pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC); dateFunc(context, 1, &pVal); sqlite3ValueFree(pVal); } @@ -930,9 +930,9 @@ static void ctimestampFunc( int argc, sqlite3_value **argv ){ - sqlite3_value *pVal = sqlite3ValueNew(); + sqlite3_value *pVal = sqlite3ValueNew(0); if( pVal ){ - sqlite3ValueSetStr(pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC); + sqlite3ValueSetStr(0, pVal, -1, "now", SQLITE_UTF8, SQLITE_STATIC); datetimeFunc(context, 1, &pVal); sqlite3ValueFree(pVal); } diff --git a/src/expr.c b/src/expr.c index a85c5ef374..5c281fbacf 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.304 2007/08/16 04:30:40 drh Exp $ +** $Id: expr.c,v 1.305 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -318,7 +318,7 @@ Expr *sqlite3RegisterExpr(Parse *pParse, Token *pToken){ ** Join two expressions using an AND operator. If either expression is ** NULL, then just return the other expression. */ -Expr *sqlite3ExprAnd(sqlite *db, Expr *pLeft, Expr *pRight){ +Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){ if( pLeft==0 ){ return pRight; }else if( pRight==0 ){ @@ -328,6 +328,7 @@ Expr *sqlite3ExprAnd(sqlite *db, Expr *pLeft, Expr *pRight){ if( p==0 ){ db->mallocFailed = 1; } + return p; } } @@ -491,7 +492,7 @@ void sqlite3DequoteExpr(sqlite3 *db, Expr *p){ ** ** Any tables that the SrcList might point to are not duplicated. */ -Expr *sqlite3ExprDup(sqlite *db, Expr *p){ +Expr *sqlite3ExprDup(sqlite3 *db, Expr *p){ Expr *pNew; if( p==0 ) return 0; pNew = sqlite3DbMallocRaw(db, sizeof(*p) ); @@ -1179,7 +1180,7 @@ static int lookupName( sqlite3_free(zCol); return 2; } - pDup = sqlite3ExprDup(pOrig); + pDup = sqlite3ExprDup(db, pOrig); if( pExpr->flags & EP_ExpCollate ){ pDup->pColl = pExpr->pColl; pDup->flags |= EP_ExpCollate; @@ -1780,7 +1781,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){ case TK_STRING: { assert( TK_FLOAT==OP_Real ); assert( TK_STRING==OP_String8 ); - sqlite3DequoteExpr(pExpr); + sqlite3DequoteExpr(pParse->db, pExpr); sqlite3VdbeOp3(v, op, 0, 0, (char*)pExpr->token.z, pExpr->token.n); break; } @@ -1883,7 +1884,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){ assert( pLeft ); if( pLeft->op==TK_FLOAT || pLeft->op==TK_INTEGER ){ Token *p = &pLeft->token; - char *z = sqlite3MPrintf("-%.*s", p->n, p->z); + char *z = sqlite3MPrintf(pParse->db, "-%.*s", p->n, p->z); if( pLeft->op==TK_FLOAT ){ sqlite3VdbeOp3(v, OP_Real, 0, 0, z, p->n+1); }else{ @@ -2095,7 +2096,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){ assert( pExpr->iColumn==OE_Rollback || pExpr->iColumn == OE_Abort || pExpr->iColumn == OE_Fail ); - sqlite3DequoteExpr(pExpr); + sqlite3DequoteExpr(pParse->db, pExpr); sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn, (char*)pExpr->token.z, pExpr->token.n); } else { @@ -2465,7 +2466,6 @@ static int analyzeAggregate(void *pArg, Expr *pExpr){ Parse *pParse = pNC->pParse; SrcList *pSrcList = pNC->pSrcList; AggInfo *pAggInfo = pNC->pAggInfo; - switch( pExpr->op ){ case TK_AGG_COLUMN: @@ -2491,7 +2491,9 @@ static int analyzeAggregate(void *pArg, Expr *pExpr){ break; } } - if( k>=pAggInfo->nColumn && (k = addAggInfoColumn(pAggInfo))>=0 ){ + if( (k>=pAggInfo->nColumn) + && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0 + ){ pCol = &pAggInfo->aCol[k]; pCol->pTab = pExpr->pTab; pCol->iTable = pExpr->iTable; @@ -2548,7 +2550,7 @@ static int analyzeAggregate(void *pArg, Expr *pExpr){ /* pExpr is original. Make a new entry in pAggInfo->aFunc[] */ u8 enc = ENC(pParse->db); - i = addAggInfoFunc(pAggInfo); + i = addAggInfoFunc(pParse->db, pAggInfo); if( i>=0 ){ pItem = &pAggInfo->aFunc[i]; pItem->pExpr = pExpr; diff --git a/src/func.c b/src/func.c index 18cd74a1f0..c5b2e6cadf 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.164 2007/08/16 04:30:40 drh Exp $ +** $Id: func.c,v 1.165 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -1064,13 +1064,13 @@ static void test_destructor( test_destructor_count_var++; assert( nArg==1 ); if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; - len = sqlite3ValueBytes(argv[0], ENC(db)); - zVal = sqliteMalloc(len+3); + len = sqlite3ValueBytes(0, argv[0], ENC(db)); + zVal = sqlite3_malloc(len+3); zVal[len] = 0; zVal[len-1] = 0; assert( zVal ); zVal++; - memcpy(zVal, sqlite3ValueText(argv[0], ENC(db)), len); + memcpy(zVal, sqlite3ValueText(0, argv[0], ENC(db)), len); if( ENC(db)==SQLITE_UTF8 ){ sqlite3_result_text(pCtx, zVal, -1, destructor); #ifndef SQLITE_OMIT_UTF16 @@ -1109,7 +1109,7 @@ static void test_auxdata( sqlite3_value **argv ){ int i; - char *zRet = sqliteMalloc(nArg*2); + char *zRet = sqlite3_malloc(nArg*2); if( !zRet ) return; for(i=0; i0) ){ - sqlite3VdbeMemCopy(pBest, pArg); + sqlite3VdbeMemCopy(0, pBest, pArg); } }else{ - sqlite3VdbeMemCopy(pBest, pArg); + sqlite3VdbeMemCopy(0, pBest, pArg); } } static void minMaxFinalize(sqlite3_context *context){ @@ -1408,11 +1408,11 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){ } } sqlite3RegisterDateTimeFunctions(db); - if( !sqlite3MallocFailed() ){ + if( !db->mallocFailed ){ int rc = sqlite3_overload_function(db, "MATCH", 2); assert( rc==SQLITE_NOMEM || rc==SQLITE_OK ); if( rc==SQLITE_NOMEM ){ - sqlite3FailedMalloc(); + db->mallocFailed = 1; } } #ifdef SQLITE_SSE diff --git a/src/hash.c b/src/hash.c index 5154752a18..fd1ceba98b 100644 --- a/src/hash.c +++ b/src/hash.c @@ -12,7 +12,7 @@ ** This is the implementation of generic hash-tables ** used in SQLite. ** -** $Id: hash.c,v 1.20 2007/08/16 04:30:40 drh Exp $ +** $Id: hash.c,v 1.21 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -222,7 +222,7 @@ static void rehash(Hash *pH, int new_size){ int (*xHash)(const void*,int); /* The hash function */ assert( (new_size & (new_size-1))==0 ); - new_ht = (struct _ht *)sqlite3_malloc( new_size*sizeof(struct _ht) ); + new_ht = (struct _ht *)sqlite3MallocZero( new_size*sizeof(struct _ht) ); if( new_ht==0 ) return; if( pH->ht ) sqlite3_free(pH->ht); pH->ht = new_ht; diff --git a/src/main.c b/src/main.c index eebe1692d2..ead52dbf1d 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.380 2007/08/16 04:30:40 drh Exp $ +** $Id: main.c,v 1.381 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -219,7 +219,7 @@ int sqlite3_close(sqlite3 *db){ */ sqlite3_free(db->aDb[1].pSchema); sqlite3_free(db); - sqlite3ReleaseThreadData(); + /* sqlite3ReleaseThreadData(); */ return SQLITE_OK; } @@ -542,7 +542,7 @@ int sqlite3_create_function16( char *zFunc8; assert( !db->mallocFailed ); - zFunc8 = sqlite3Utf16to8(zFunctionName, -1); + zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1); rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal); sqlite3_free(zFunc8); @@ -780,7 +780,7 @@ const void *sqlite3_errmsg16(sqlite3 *db){ } z = sqlite3_value_text16(db->pErr); if( z==0 ){ - sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode), + sqlite3ValueSetStr(db, db->pErr, -1, sqlite3ErrStr(db->errCode), SQLITE_UTF8, SQLITE_STATIC); z = sqlite3_value_text16(db->pErr); } @@ -1044,15 +1044,15 @@ int sqlite3_open16( sqlite3 **ppDb ){ char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ - int rc = SQLITE_OK; sqlite3_value *pVal; + int rc = SQLITE_NOMEM; assert( zFilename ); assert( ppDb ); *ppDb = 0; - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); - zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8); + pVal = sqlite3ValueNew(0); + sqlite3ValueSetStr(0, pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); + zFilename8 = sqlite3ValueText(0, pVal, SQLITE_UTF8); if( zFilename8 ){ rc = openDatabase(zFilename8, ppDb); if( rc==SQLITE_OK && *ppDb ){ @@ -1155,7 +1155,7 @@ int sqlite3_create_collation16( int rc = SQLITE_OK; char *zName8; assert( !db->mallocFailed ); - zName8 = sqlite3Utf16to8(zName, -1); + zName8 = sqlite3Utf16to8(db, zName, -1); if( zName8 ){ rc = createCollation(db, zName8, enc, pCtx, xCompare, 0); sqlite3_free(zName8); @@ -1258,7 +1258,7 @@ int sqlite3_enable_shared_cache(int enable){ } pTd->useSharedData = enable; - sqlite3ReleaseThreadData(); + /* sqlite3ReleaseThreadData(); */ } return sqlite3ApiExit(0, SQLITE_OK); } diff --git a/src/malloc.c b/src/malloc.c index e0a678eaee..adafe3daf9 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ ** Memory allocation functions used throughout sqlite. ** ** -** $Id: malloc.c,v 1.5 2007/08/16 04:30:40 drh Exp $ +** $Id: malloc.c,v 1.6 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -24,18 +24,24 @@ ** value indicates no limit. */ void sqlite3_soft_heap_limit(int n){ +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT ThreadData *pTd = sqlite3ThreadData(); if( pTd ){ pTd->nSoftHeapLimit = n; } sqlite3ReleaseThreadData(); +#endif } /* ** Release memory held by SQLite instances created by the current thread. */ int sqlite3_release_memory(int n){ +#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO) return sqlite3PagerReleaseMemory(n); +#else + return SQLITE_OK; +#endif } @@ -84,7 +90,7 @@ void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){ void *pNew; pNew = sqlite3_realloc(p, n); if( !pNew ){ - sqlite3FreeX(p); + sqlite3_free(p); db->mallocFailed = 1; } return pNew; @@ -103,14 +109,14 @@ char *sqlite3StrDup(const char *z){ int n; if( z==0 ) return 0; n = strlen(z)+1; - zNew = sqlite3MallocRaw(n, 1); + zNew = sqlite3_malloc(n); if( zNew ) memcpy(zNew, z, n); return zNew; } char *sqlite3StrNDup(const char *z, int n){ char *zNew; if( z==0 ) return 0; - zNew = sqlite3MallocRaw(n+1, 1); + zNew = sqlite3_malloc(n+1); if( zNew ){ memcpy(zNew, z, n); zNew[n] = 0; @@ -118,6 +124,21 @@ char *sqlite3StrNDup(const char *z, int n){ return zNew; } +char *sqlite3DbStrDup(sqlite3 *db, const char *z){ + char *zNew = sqlite3StrDup(z); + if( z && !zNew ){ + db->mallocFailed = 1; + } + return zNew; +} +char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){ + char *zNew = sqlite3StrNDup(z, n); + if( z && !zNew ){ + db->mallocFailed = 1; + } + return zNew; +} + /* ** Create a string from the 2nd and subsequent arguments (up to the ** first NULL argument), store the string in memory obtained from @@ -138,8 +159,8 @@ void sqlite3SetString(char **pz, ...){ nByte += strlen(z); } va_end(ap); - sqliteFree(*pz); - *pz = zResult = sqliteMallocRaw( nByte ); + sqlite3_free(*pz); + *pz = zResult = sqlite3_malloc(nByte); if( zResult==0 ){ return; } @@ -169,7 +190,7 @@ void sqlite3SetString(char **pz, ...){ ** is set to SQLITE_NOMEM. */ int sqlite3ApiExit(sqlite3* db, int rc){ - if( db->mallocFailed ){ + if( db && db->mallocFailed ){ sqlite3Error(db, SQLITE_NOMEM, 0); db->mallocFailed = 0; rc = SQLITE_NOMEM; @@ -182,6 +203,7 @@ int sqlite3ApiExit(sqlite3* db, int rc){ ** This function sets a flag in the thread-specific-data structure that will ** cause an assert to fail if sqliteMalloc() or sqliteRealloc() is called. */ +#if 0 void sqlite3MallocDisallow(){ #if 0 assert( sqlite3_mallocDisallowed>=0 ); @@ -200,3 +222,4 @@ void sqlite3MallocAllow(){ #endif } #endif +#endif diff --git a/src/mutex.c b/src/mutex.c index 5c9e151204..f347de4f48 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -12,7 +12,7 @@ ** This file contains the C functions that implement mutexes for ** use by the SQLite core. ** -** $Id: mutex.c,v 1.1 2007/08/15 13:04:54 drh Exp $ +** $Id: mutex.c,v 1.2 2007/08/16 10:09:03 danielk1977 Exp $ */ /* @@ -92,6 +92,7 @@ void sqlite3_mutex_leave(sqlite3_mutex *pNotUsed){ */ int sqlite3_mutex_serialize(void (*xCallback)(void*), void *pArg){ xCallback(pArg); + return SQLITE_OK; } #if 0 diff --git a/src/os_unix.c b/src/os_unix.c index ff842b8966..3bb8a5bb45 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -2296,7 +2296,7 @@ char *sqlite3UnixFullPathname(const char *zRelative){ zBuf[0] = 0; sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative, (char*)0); - sqliteFree(zBuf); + sqlite3_free(zBuf); } #if 0 @@ -2899,11 +2899,13 @@ ThreadData *sqlite3UnixThreadSpecificData(int allocateFlag){ static ThreadData *pTsd = 0; if( allocateFlag>0 ){ if( pTsd==0 ){ +#if 0 if( !sqlite3TestMallocFail() ){ pTsd = sqlite3OsMalloc( sizeof(zeroData) ); } #ifdef SQLITE_MEMDEBUG sqlite3_isFail = 0; +#endif #endif if( pTsd ){ *pTsd = zeroData; diff --git a/src/pager.c b/src/pager.c index ca11cf5800..418b13ef14 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.357 2007/08/16 04:30:40 drh Exp $ +** @(#) $Id: pager.c,v 1.358 2007/08/16 10:09:03 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -2745,7 +2745,15 @@ int sqlite3PagerReleaseMemory(int nReq){ for( pTmp=pPager->pAll; pTmp->pNextAll!=pPg; pTmp=pTmp->pNextAll ){} pTmp->pNextAll = pPg->pNextAll; } +#if 0 nReleased += sqliteAllocSize(pPg); +#else + nReleased += ( + sizeof(*pPg) + pPager->pageSize + + sizeof(u32) + pPager->nExtra + + MEMDB*sizeof(PgHistory) + ); +#endif IOTRACE(("PGFREE %p %d *\n", pPager, pPg->pgno)); PAGER_INCR(sqlite3_pager_pgfree_count); sqlite3_free(pPg); @@ -3121,7 +3129,9 @@ int sqlite3PagerAcquire( pPg->pgno = pgno; assert( !MEMDB || pgno>pPager->stmtSize ); if( pPager->aInJournal && (int)pgno<=pPager->origDbSize ){ +#if 0 sqlite3CheckMemory(pPager->aInJournal, pgno/8); +#endif assert( pPager->journalOpen ); pPg->inJournal = (pPager->aInJournal[pgno/8] & (1<<(pgno&7)))!=0; pPg->needSync = 0; diff --git a/src/parse.y b/src/parse.y index c4d7238dcf..a051b64a93 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.232 2007/08/16 04:30:40 drh Exp $ +** @(#) $Id: parse.y,v 1.233 2007/08/16 10:09:03 danielk1977 Exp $ */ // All token codes are small integers with #defines that begin with "TK_" @@ -419,7 +419,7 @@ selcollist(A) ::= sclp(P) expr(X) as(Y). { A = sqlite3ExprListAppend(pParse,P,X,Y.n?&Y:0); } selcollist(A) ::= sclp(P) STAR. { - Expr *p = sqlite3Expr(pParse, TK_ALL, 0, 0, 0); + Expr *p = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0); A = sqlite3ExprListAppend(pParse, P, p, 0); } selcollist(A) ::= sclp(P) nm(X) DOT STAR. { @@ -806,7 +806,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&Y,&Z); A = sqlite3PExpr(pParse, TK_IN, X, 0, 0); if( A ){ - A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0); + A->pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); sqlite3ExprSetHeight(A); }else{ sqlite3SrcListDelete(pSrc); diff --git a/src/pragma.c b/src/pragma.c index ec047eb3b0..66edcee87b 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.143 2007/08/16 04:30:40 drh Exp $ +** $Id: pragma.c,v 1.144 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -864,7 +864,7 @@ void sqlite3Pragma( sqlite3VdbeAddOp(v, OP_IntegrityCk, 0, i); addr = sqlite3VdbeAddOp(v, OP_IsNull, -1, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, - sqlite3MPrintf("*** in database %s ***\n", db->aDb[i].zName), + sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName), P3_DYNAMIC); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); sqlite3VdbeAddOp(v, OP_Concat, 0, 0); diff --git a/src/prepare.c b/src/prepare.c index b173566a59..256a3e27ad 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -13,7 +13,7 @@ ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.53 2007/08/16 04:30:40 drh Exp $ +** $Id: prepare.c,v 1.54 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -290,7 +290,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ rc = SQLITE_OK; }else{ char *zSql; - zSql = sqlite3MPrintf( + zSql = sqlite3MPrintf(db, "SELECT name, rootpage, sql FROM '%q'.%s", db->aDb[iDb].zName, zMasterName); sqlite3SafetyOff(db); @@ -560,7 +560,7 @@ int sqlite3Prepare( } rc = sqlite3ApiExit(db, rc); - sqlite3ReleaseThreadData(); + /* sqlite3ReleaseThreadData(); */ assert( (rc&db->errMask)==rc ); return rc; } @@ -647,7 +647,7 @@ static int sqlite3Prepare16( if( sqlite3SafetyCheck(db) ){ return SQLITE_MISUSE; } - zSql8 = sqlite3Utf16to8(zSql, nBytes); + zSql8 = sqlite3Utf16to8(db, zSql, nBytes); if( zSql8 ){ rc = sqlite3Prepare(db, zSql8, -1, saveSqlFlag, ppStmt, &zTail8); } diff --git a/src/printf.c b/src/printf.c index fb7a786559..55fe3566a5 100644 --- a/src/printf.c +++ b/src/printf.c @@ -701,7 +701,7 @@ static int vxprintf( } } if( zExtra ){ - sqliteFree(zExtra); + sqlite3_free(zExtra); } }/* End for loop over the format string */ return errorflag ? -1 : count; @@ -717,7 +717,7 @@ struct sgMprintf { int nChar; /* Length of the string so far */ int nTotal; /* Output size if unconstrained */ int nAlloc; /* Amount of space allocated in zText */ - void *(*xRealloc)(void*,int); /* Function used to realloc memory */ + void *(*xRealloc)(void*, unsigned int); /* Function used to realloc memory */ }; /* @@ -769,7 +769,7 @@ static void mout(void *arg, const char *zNewText, int nNewChar){ ** the consumer. */ static char *base_vprintf( - void *(*xRealloc)(void*,int), /* Routine to realloc memory. May be NULL */ + void *(*xRealloc)(void*, unsigned int), /* realloc() function. May be NULL */ int useInternal, /* Use internal %-conversions if true */ char *zInitBuf, /* Initially write here, before mallocing */ int nInitBuf, /* Size of zInitBuf[] */ @@ -801,8 +801,8 @@ static char *base_vprintf( /* ** Realloc that is a real function, not a macro. */ -static void *printf_realloc(void *old, int size){ - return sqlite3_realloc(old,size); +static void *printf_realloc(void *old, unsigned int size){ + return sqlite3_realloc(old, size); } /* diff --git a/src/select.c b/src/select.c index e9b1958bdc..7cf96bb1c0 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.355 2007/08/16 04:30:40 drh Exp $ +** $Id: select.c,v 1.356 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -193,11 +193,13 @@ static void setToken(Token *p, const char *z){ ** ** {a"bc} -> {"a""bc"} */ -static void setQuotedToken(Token *p, const char *z){ - p->z = (u8 *)sqlite3MPrintf("\"%w\"", z); +static void setQuotedToken(Parse *pParse, Token *p, const char *z){ + p->z = (u8 *)sqlite3MPrintf(0, "\"%w\"", z); p->dyn = 1; if( p->z ){ p->n = strlen((char *)p->z); + }else{ + pParse->db->mallocFailed = 1; } } @@ -241,7 +243,7 @@ static void addWhereTerm( pE2b = sqlite3CreateIdExpr(pParse, zAlias2); pE1c = sqlite3PExpr(pParse, TK_DOT, pE1b, pE1a, 0); pE2c = sqlite3PExpr(pParse, TK_DOT, pE2b, pE2a, 0); - pE = sqlite3DbExpr(pParse, TK_EQ, pE1c, pE2c, 0); + pE = sqlite3PExpr(pParse, TK_EQ, pE1c, pE2c, 0); if( pE ){ ExprSetProperty(pE, EP_FromJoin); pE->iRightJoinTable = iRightJoinTable; @@ -328,7 +330,7 @@ static int sqliteProcessJoin(Parse *pParse, Select *p){ for(j=0; jnCol; j++){ char *zName = pLeftTab->aCol[j].zName; if( columnIndex(pRightTab, zName)>=0 ){ - addWhereTerm(zName, pLeftTab, pLeft->zAlias, + addWhereTerm(pParse, zName, pLeftTab, pLeft->zAlias, pRightTab, pRight->zAlias, pRight->iCursor, &p->pWhere); @@ -369,7 +371,7 @@ static int sqliteProcessJoin(Parse *pParse, Select *p){ "not present in both tables", zName); return 1; } - addWhereTerm(zName, pLeftTab, pLeft->zAlias, + addWhereTerm(pParse, zName, pLeftTab, pLeft->zAlias, pRightTab, pRight->zAlias, pRight->iCursor, &p->pWhere); } @@ -1139,7 +1141,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){ for(j=cnt=0; jpSelect!=0 ); if( pFrom->zAlias==0 ){ pFrom->zAlias = - sqlite3MPrintf("sqlite_subquery_%p_", (void*)pFrom->pSelect); + sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pFrom->pSelect); } assert( pFrom->pTab==0 ); pFrom->pTab = pTab = @@ -1364,13 +1366,14 @@ static int prepSelectStmt(Parse *pParse, Select *p){ } pRight = sqlite3Expr(TK_ID, 0, 0, 0); if( pRight==0 ) break; - setQuotedToken(&pRight->token, zName); + setQuotedToken(pParse, &pRight->token, zName); if( zTabName && (longNames || pTabList->nSrc>1) ){ Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, 0); pExpr = sqlite3Expr(TK_DOT, pLeft, pRight, 0); if( pExpr==0 ) break; - setQuotedToken(&pLeft->token, zTabName); - setToken(&pExpr->span, sqlite3MPrintf("%s.%s", zTabName, zName)); + setQuotedToken(pParse, &pLeft->token, zTabName); + setToken(&pExpr->span, + sqlite3MPrintf(db, "%s.%s", zTabName, zName)); pExpr->span.dyn = 1; pExpr->token.z = 0; pExpr->token.n = 0; @@ -2354,17 +2357,17 @@ static int flattenSubquery( sqlite3DbStrNDup(db, (char*)pExpr->span.z, pExpr->span.n); } } - substExprList(p->pEList, iParent, pSub->pEList); + substExprList(db, p->pEList, iParent, pSub->pEList); if( isAgg ){ - substExprList(p->pGroupBy, iParent, pSub->pEList); - substExpr(p->pHaving, iParent, pSub->pEList); + substExprList(db, p->pGroupBy, iParent, pSub->pEList); + substExpr(db, p->pHaving, iParent, pSub->pEList); } if( pSub->pOrderBy ){ assert( p->pOrderBy==0 ); p->pOrderBy = pSub->pOrderBy; pSub->pOrderBy = 0; }else if( p->pOrderBy ){ - substExprList(p->pOrderBy, iParent, pSub->pEList); + substExprList(db, p->pOrderBy, iParent, pSub->pEList); } if( pSub->pWhere ){ pWhere = sqlite3ExprDup(db, pSub->pWhere); @@ -2375,13 +2378,13 @@ static int flattenSubquery( assert( p->pHaving==0 ); p->pHaving = p->pWhere; p->pWhere = pWhere; - substExpr(p->pHaving, iParent, pSub->pEList); + substExpr(db, p->pHaving, iParent, pSub->pEList); p->pHaving = sqlite3ExprAnd(db, p->pHaving, sqlite3ExprDup(db, pSub->pHaving)); assert( p->pGroupBy==0 ); p->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy); }else{ - substExpr(p->pWhere, iParent, pSub->pEList); + substExpr(db, p->pWhere, iParent, pSub->pEList); p->pWhere = sqlite3ExprAnd(db, p->pWhere, pWhere); } @@ -2718,7 +2721,7 @@ int sqlite3SelectResolve( } } - if( db->mallocFailed ){ + if( pParse->db->mallocFailed ){ return SQLITE_NOMEM; } diff --git a/src/sqlite3ext.h b/src/sqlite3ext.h index ba6d378b21..4da2ca2a0f 100644 --- a/src/sqlite3ext.h +++ b/src/sqlite3ext.h @@ -15,7 +15,7 @@ ** as extensions by SQLite should #include this file instead of ** sqlite3.h. ** -** @(#) $Id: sqlite3ext.h,v 1.12 2007/07/20 10:48:36 drh Exp $ +** @(#) $Id: sqlite3ext.h,v 1.13 2007/08/16 10:09:03 danielk1977 Exp $ */ #ifndef _SQLITE3EXT_H_ #define _SQLITE3EXT_H_ @@ -102,7 +102,7 @@ struct sqlite3_api_routines { sqlite_int64 (*last_insert_rowid)(sqlite3*); const char * (*libversion)(void); int (*libversion_number)(void); - void *(*malloc)(int); + void *(*malloc)(unsigned int); char * (*mprintf)(const char*,...); int (*open)(const char*,sqlite3**); int (*open16)(const void*,sqlite3**); @@ -110,7 +110,7 @@ struct sqlite3_api_routines { int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*); void (*progress_handler)(sqlite3*,int,int(*)(void*),void*); - void *(*realloc)(void*,int); + void *(*realloc)(void*,unsigned int); int (*reset)(sqlite3_stmt*pStmt); void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*)); void (*result_double)(sqlite3_context*,double); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 1adba20d49..da3a192f7e 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.587 2007/08/16 04:30:40 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.588 2007/08/16 10:09:03 danielk1977 Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -1606,7 +1606,7 @@ void sqlite3FinishCoding(Parse*); Expr *sqlite3Expr(int, Expr*, Expr*, const Token*); Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); Expr *sqlite3RegisterExpr(Parse*,Token*); -Expr *sqlite3ExprAnd(sqlite*,Expr*, Expr*); +Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); void sqlite3ExprSpan(Expr*,Token*,Token*); Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); void sqlite3ExprAssignVarNumber(Parse*, Expr*); @@ -1685,7 +1685,7 @@ int sqlite3ExprResolveNames(NameContext *, Expr *); int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); Vdbe *sqlite3GetVdbe(Parse*); -Expr *sqlite3CreateIdExpr(const char*); +Expr *sqlite3CreateIdExpr(Parse *, const char*); void sqlite3Randomness(int, void*); void sqlite3RollbackAll(sqlite3*); void sqlite3CodeVerifySchema(Parse*, int); @@ -1786,7 +1786,7 @@ int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); char sqlite3ExprAffinity(Expr *pExpr); int sqlite3Atoi64(const char*, i64*); void sqlite3Error(sqlite3*, int, const char*,...); -void *sqlite3HexToBlob(const char *z); +void *sqlite3HexToBlob(sqlite3*, const char *z); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); const char *sqlite3ErrStr(int); int sqlite3ReadSchema(Parse *pParse); @@ -1798,14 +1798,15 @@ int sqlite3CheckCollSeq(Parse *, CollSeq *); int sqlite3CheckObjectName(Parse *, const char *); void sqlite3VdbeSetChanges(sqlite3 *, int); -const void *sqlite3ValueText(sqlite3_value*, u8); -int sqlite3ValueBytes(sqlite3_value*, u8); -void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*)); +const void *sqlite3ValueText(sqlite3 *db, sqlite3_value*, u8); +int sqlite3ValueBytes(sqlite3 *db, sqlite3_value*, u8); +void sqlite3ValueSetStr(sqlite3 *,sqlite3_value*, int, const void *,u8, + void(*)(void*)); void sqlite3ValueFree(sqlite3_value*); -sqlite3_value *sqlite3ValueNew(void); -char *sqlite3Utf16to8(const void*, int); -int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **); -void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); +sqlite3_value *sqlite3ValueNew(sqlite3 *); +char *sqlite3Utf16to8(sqlite3 *, const void*, int); +int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); +void sqlite3ValueApplyAffinity(sqlite3 *, sqlite3_value *, u8, u8); extern const unsigned char sqlite3UpperToLower[]; void sqlite3RootPageMoved(Db*, int, int); void sqlite3Reindex(Parse*, Token*, Token*); @@ -1834,7 +1835,7 @@ void sqlite3ReleaseThreadData(void); void sqlite3AttachFunctions(sqlite3 *); void sqlite3MinimumFileFormat(Parse*, int, int); void sqlite3SchemaFree(void *); -Schema *sqlite3SchemaGet(Btree *); +Schema *sqlite3SchemaGet(sqlite3 *, Btree *); int sqlite3SchemaToIndex(sqlite3 *db, Schema *); KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *); int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, @@ -1845,6 +1846,9 @@ void sqlite3FailedMalloc(void); void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *); int sqlite3OpenTempDatabase(Parse *); +void *sqlite3DbReallocOrFree(sqlite3 *, void *, int); +sqlite3 *sqlite3DbOfVdbe(Vdbe *); + /* ** The interface to the LEMON-generated parser */ @@ -1898,7 +1902,7 @@ int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **); int sqlite3VtabCallConnect(Parse*, Table*); int sqlite3VtabCallDestroy(sqlite3*, int, const char *); int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *); -FuncDef *sqlite3VtabOverloadFunction(FuncDef*, int nArg, Expr*); +FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**); int sqlite3Reprepare(Vdbe*); void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*); diff --git a/src/table.c b/src/table.c index d58fb3ced2..7a1be0f616 100644 --- a/src/table.c +++ b/src/table.c @@ -154,12 +154,12 @@ int sqlite3_get_table( sqlite3_free(*pzErrMsg); *pzErrMsg = sqlite3_mprintf("%s",res.zErrMsg); } - sqliteFree(res.zErrMsg); + sqlite3_free(res.zErrMsg); } db->errCode = res.rc; return res.rc & db->errMask; } - sqliteFree(res.zErrMsg); + sqlite3_free(res.zErrMsg); if( rc!=SQLITE_OK ){ sqlite3_free_table(&res.azResult[1]); return rc & db->errMask; diff --git a/src/test1.c b/src/test1.c index f956742904..2089c5117b 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.260 2007/08/16 04:30:40 drh Exp $ +** $Id: test1.c,v 1.261 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -192,9 +192,9 @@ static int getStmtPointer( static int getFilePointer( Tcl_Interp *interp, const char *zArg, - OsFile **ppFile + sqlite3_file **ppFile ){ - *ppFile = (OsFile*)sqlite3TextToPtr(zArg); + *ppFile = (sqlite3_file*)sqlite3TextToPtr(zArg); return TCL_OK; } @@ -412,7 +412,7 @@ static int test_mprintf_z( int i; for(i=2; i0 ){ sqlite3_iMallocFail++; } #endif - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE_UTF8, SQLITE_STATIC); + pVal = sqlite3ValueNew(0); + sqlite3ValueSetStr(0,pVal, -1, "x_sqlite_exec", SQLITE_UTF8, SQLITE_STATIC); rc = sqlite3_create_function16(db, - sqlite3ValueText(pVal, SQLITE_UTF16NATIVE), + sqlite3ValueText(0, pVal, SQLITE_UTF16NATIVE), 1, SQLITE_UTF16, db, sqlite3ExecFunc, 0, 0); sqlite3ValueFree(pVal); } @@ -2055,12 +2055,12 @@ static int test_collate_func( assert(0); } - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC); + pVal = sqlite3ValueNew(0); + sqlite3ValueSetStr(0, pVal, nA, zA, encin, SQLITE_STATIC); n = sqlite3_value_bytes(pVal); Tcl_ListObjAppendElement(i,pX, Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); - sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC); + sqlite3ValueSetStr(0, pVal, nB, zB, encin, SQLITE_STATIC); n = sqlite3_value_bytes(pVal); Tcl_ListObjAppendElement(i,pX, Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); @@ -2100,10 +2100,10 @@ static int test_collate( sqlite3_iMallocFail++; } #endif - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC); + pVal = sqlite3ValueNew(0); + sqlite3ValueSetStr(0, pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC); rc = sqlite3_create_collation16(db, - sqlite3ValueText(pVal, SQLITE_UTF16NATIVE), SQLITE_UTF16BE, + sqlite3ValueText(0, pVal, SQLITE_UTF16NATIVE), SQLITE_UTF16BE, (void *)SQLITE_UTF16BE, val?test_collate_func:0); sqlite3ValueFree(pVal); } @@ -2269,8 +2269,8 @@ static void test_function_utf8( Tcl_EvalObjEx(interp, pX, 0); Tcl_DecrRefCount(pX); sqlite3_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE_TRANSIENT); - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), + pVal = sqlite3ValueNew(0); + sqlite3ValueSetStr(0, pVal, -1, Tcl_GetStringResult(interp), SQLITE_UTF8, SQLITE_STATIC); sqlite3_result_text16be(pCtx, sqlite3_value_text16be(pVal), -1, SQLITE_TRANSIENT); @@ -2292,8 +2292,8 @@ static void test_function_utf16le( Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); Tcl_EvalObjEx(interp, pX, 0); Tcl_DecrRefCount(pX); - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), + pVal = sqlite3ValueNew(0); + sqlite3ValueSetStr(0, pVal, -1, Tcl_GetStringResult(interp), SQLITE_UTF8, SQLITE_STATIC); sqlite3_result_text(pCtx,(char*)sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT); sqlite3ValueFree(pVal); @@ -2314,8 +2314,8 @@ static void test_function_utf16be( Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); Tcl_EvalObjEx(interp, pX, 0); Tcl_DecrRefCount(pX); - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), + pVal = sqlite3ValueNew(0); + sqlite3ValueSetStr(0, pVal, -1, Tcl_GetStringResult(interp), SQLITE_UTF8, SQLITE_STATIC); sqlite3_result_text16le(pCtx, sqlite3_value_text16le(pVal), -1, SQLITE_TRANSIENT); @@ -3595,7 +3595,7 @@ static int test_sqlite3OsOpenReadWrite( int objc, Tcl_Obj *CONST objv[] ){ - OsFile *pFile; + sqlite3_file *pFile; int rc; int dummy; char zBuf[100]; @@ -3625,7 +3625,7 @@ static int test_sqlite3OsClose( int objc, Tcl_Obj *CONST objv[] ){ - OsFile *pFile; + sqlite3_file *pFile; int rc; if( objc!=2 ){ @@ -3654,7 +3654,7 @@ static int test_sqlite3OsLock( int objc, Tcl_Obj *CONST objv[] ){ - OsFile * pFile; + sqlite3_file * pFile; int rc; if( objc!=3 ){ @@ -3702,7 +3702,7 @@ static int test_sqlite3OsUnlock( int objc, Tcl_Obj *CONST objv[] ){ - OsFile * pFile; + sqlite3_file * pFile; int rc; if( objc!=2 ){ diff --git a/src/test2.c b/src/test2.c index 540957e348..c8464c6c94 100644 --- a/src/test2.c +++ b/src/test2.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test2.c,v 1.44 2007/08/15 17:08:46 danielk1977 Exp $ +** $Id: test2.c,v 1.45 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -531,7 +531,7 @@ static int fake_big_file( int rc; int n; i64 offset; - OsFile *fd = 0; + sqlite3_file *fd = 0; int readOnly = 0; if( argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], diff --git a/src/test3.c b/src/test3.c index e5b2cc1857..53cdc17f2f 100644 --- a/src/test3.c +++ b/src/test3.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test3.c,v 1.76 2007/08/16 04:30:40 drh Exp $ +** $Id: test3.c,v 1.77 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "pager.h" @@ -589,7 +589,7 @@ static int btree_integrity_check( sqlite3_free((void*)aRoot); if( zResult ){ Tcl_AppendResult(interp, zResult, 0); - sqliteFree(zResult); + sqlite3_free(zResult); } return TCL_OK; } diff --git a/src/test5.c b/src/test5.c index c9b86c2bcf..b9e69d272c 100644 --- a/src/test5.c +++ b/src/test5.c @@ -15,7 +15,7 @@ ** is used for testing the SQLite routines for converting between ** the various supported unicode encodings. ** -** $Id: test5.c,v 1.17 2007/08/16 04:30:40 drh Exp $ +** $Id: test5.c,v 1.18 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" @@ -142,7 +142,7 @@ static int test_translate( return TCL_ERROR; } if( objc==5 ){ - xDel = sqlite3FreeX; + xDel = sqlite3_free; } enc_from = name_to_enc(interp, objv[2]); @@ -150,14 +150,14 @@ static int test_translate( enc_to = name_to_enc(interp, objv[3]); if( !enc_to ) return TCL_ERROR; - pVal = sqlite3ValueNew(); + pVal = sqlite3ValueNew(0); if( enc_from==SQLITE_UTF8 ){ z = Tcl_GetString(objv[1]); if( objc==5 ){ z = sqlite3StrDup(z); } - sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel); + sqlite3ValueSetStr(0, pVal, -1, z, enc_from, xDel); }else{ z = (char*)Tcl_GetByteArrayFromObj(objv[1], &len); if( objc==5 ){ @@ -165,11 +165,11 @@ static int test_translate( z = sqlite3_malloc(len); memcpy(z, zTmp, len); } - sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel); + sqlite3ValueSetStr(0, pVal, -1, z, enc_from, xDel); } - z = (char *)sqlite3ValueText(pVal, enc_to); - len = sqlite3ValueBytes(pVal, enc_to) + (enc_to==SQLITE_UTF8?1:2); + z = (char *)sqlite3ValueText(0, pVal, enc_to); + len = sqlite3ValueBytes(0, pVal, enc_to) + (enc_to==SQLITE_UTF8?1:2); Tcl_SetObjResult(interp, Tcl_NewByteArrayObj((u8*)z, len)); sqlite3ValueFree(pVal); diff --git a/src/test6.c b/src/test6.c index dc8d0913df..6c9dc6787f 100644 --- a/src/test6.c +++ b/src/test6.c @@ -125,7 +125,7 @@ struct WriteBuffer { struct CrashFile { const sqlite3_io_methods *pMethod; /* Must be first */ sqlite3_file *pRealFile; /* Underlying "real" file handle */ - const char *zName; + char *zName; }; struct CrashGlobal { @@ -224,7 +224,7 @@ static int writeListSync(CrashFile *pFile, int isCrash){ for(i=iFirst; rc==SQLITE_OK && i<=iLast; i++){ sqlite3Randomness(g.iSectorSize, zGarbage); rc = sqlite3OsWrite( - pFile->pRealFile, i*g.iSectorSize, zGarbage, g.iSectorSize + pFile->pRealFile, zGarbage, g.iSectorSize, i*g.iSectorSize ); } sqlite3_free(zGarbage); @@ -286,7 +286,7 @@ static int writeListAppend( /* ** Close a crash-file. */ -int cfClose(sqlite3_file *pFile){ +static int cfClose(sqlite3_file *pFile){ CrashFile *pCrash = (CrashFile *)pFile; writeListSync(pCrash, 0); sqlite3OsClose(&pCrash->pRealFile); @@ -296,7 +296,12 @@ int cfClose(sqlite3_file *pFile){ /* ** Read data from a crash-file. */ -int cfRead(sqlite3_file *pFile, void *zBuf, int iAmt, sqlite_int64 iOfst){ +static int cfRead( + sqlite3_file *pFile, + void *zBuf, + int iAmt, + sqlite_int64 iOfst +){ CrashFile *pCrash = (CrashFile *)pFile; sqlite3_int64 iSize; int rc; @@ -361,21 +366,26 @@ int cfRead(sqlite3_file *pFile, void *zBuf, int iAmt, sqlite_int64 iOfst){ /* ** Write data to a crash-file. */ -int cfWrite(sqlite3_file *pFile, void *zBuf, int iAmt, sqlite_int64 iOfst){ +static int cfWrite( + sqlite3_file *pFile, + const void *zBuf, + int iAmt, + sqlite_int64 iOfst +){ return writeListAppend(pFile, iOfst, zBuf, iAmt); } /* ** Truncate a crash-file. */ -int cfTruncate(sqlite3_file *pFile, sqlite_int64 size){ +static int cfTruncate(sqlite3_file *pFile, sqlite_int64 size){ return writeListAppend(pFile, size, 0, 0); } /* ** Sync a crash-file. */ -int cfSync(sqlite3_file *pFile, int flags){ +static int cfSync(sqlite3_file *pFile, int flags){ CrashFile *pCrash = (CrashFile *)pFile; int isCrash = 0; @@ -391,7 +401,7 @@ int cfSync(sqlite3_file *pFile, int flags){ /* ** Return the current file-size of the crash-file. */ -int cfFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ +static int cfFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ CrashFile *pCrash = (CrashFile *)pFile; WriteBuffer *pWrite; int rc; @@ -416,16 +426,16 @@ int cfFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ /* ** Calls related to file-locks are passed on to the real file handle. */ -int cfLock(sqlite3_file *pFile, int eLock){ +static int cfLock(sqlite3_file *pFile, int eLock){ return sqlite3OsLock(((CrashFile *)pFile)->pRealFile, eLock); } -int cfUnlock(sqlite3_file *pFile, int eLock){ +static int cfUnlock(sqlite3_file *pFile, int eLock){ return sqlite3OsUnlock(((CrashFile *)pFile)->pRealFile, eLock); } -int cfCheckReservedLock(sqlite3_file *pFile){ +static int cfCheckReservedLock(sqlite3_file *pFile){ return sqlite3OsCheckReservedLock(((CrashFile *)pFile)->pRealFile); } -int cfBreakLock(sqlite3_file *pFile){ +static int cfBreakLock(sqlite3_file *pFile){ return sqlite3OsBreakLock(((CrashFile *)pFile)->pRealFile); } @@ -434,10 +444,10 @@ int cfBreakLock(sqlite3_file *pFile){ ** the global values configured by the [sqlite_crashparams] tcl * interface. */ -int cfSectorSize(sqlite3_file *pFile){ +static int cfSectorSize(sqlite3_file *pFile){ return g.iSectorSize; } -int cfDeviceCharacteristics(sqlite3_file *pFile){ +static int cfDeviceCharacteristics(sqlite3_file *pFile){ return g.iDeviceCharacteristics; } @@ -474,7 +484,7 @@ int sqlite3CrashFileOpen( pReal = (sqlite3_file *)sqlite3_malloc(pVfs->szOsFile); if( pReal ){ pWrapper->pMethod = &CrashFileVtab; - pWrapper->zName = zName; + pWrapper->zName = (char *)zName; rc = pVfs->xOpen(pVfs->pAppData, zName, pReal, flags, pOutFlags); if( rc==SQLITE_OK ){ pWrapper->pRealFile = pFile; @@ -498,7 +508,7 @@ int sqlite3CrashFileWrap( pWrapper->pMethod = &CrashFileVtab; pWrapper->pRealFile = pFile; - pWrapper->zName = &pWrapper[1]; + pWrapper->zName = (char *)&pWrapper[1]; memcpy(pWrapper->zName, zName, strlen(zName)+1); *ppWrapper = (sqlite3_file *)pWrapper; diff --git a/src/test8.c b/src/test8.c index 3b6631bb8e..5f3074b591 100644 --- a/src/test8.c +++ b/src/test8.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test8.c,v 1.49 2007/08/16 04:30:40 drh Exp $ +** $Id: test8.c,v 1.50 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -220,7 +220,7 @@ static int getIndexArray( } /* Compile an sqlite pragma to loop through all indices on table zTab */ - zSql = sqlite3MPrintf("PRAGMA index_list(%s)", zTab); + zSql = sqlite3MPrintf(0, "PRAGMA index_list(%s)", zTab); if( !zSql ){ rc = SQLITE_NOMEM; goto get_index_array_out; @@ -234,7 +234,7 @@ static int getIndexArray( while( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){ const char *zIdx = (const char *)sqlite3_column_text(pStmt, 1); sqlite3_stmt *pStmt2 = 0; - zSql = sqlite3MPrintf("PRAGMA index_info(%s)", zIdx); + zSql = sqlite3MPrintf(0, "PRAGMA index_info(%s)", zIdx); if( !zSql ){ rc = SQLITE_NOMEM; goto get_index_array_out; @@ -372,7 +372,7 @@ static int echoConstructor( pVtab->db = db; /* Allocate echo_vtab.zThis */ - pVtab->zThis = sqlite3MPrintf("%s", argv[2]); + pVtab->zThis = sqlite3MPrintf(0, "%s", argv[2]); if( !pVtab->zThis ){ echoDestructor((sqlite3_vtab *)pVtab); return SQLITE_NOMEM; @@ -380,10 +380,10 @@ static int echoConstructor( /* Allocate echo_vtab.zTableName */ if( argc>3 ){ - pVtab->zTableName = sqlite3MPrintf("%s", argv[3]); + pVtab->zTableName = sqlite3MPrintf(0, "%s", argv[3]); dequoteString(pVtab->zTableName); if( pVtab->zTableName && pVtab->zTableName[0]=='*' ){ - char *z = sqlite3MPrintf("%s%s", argv[2], &(pVtab->zTableName[1])); + char *z = sqlite3MPrintf(0, "%s%s", argv[2], &(pVtab->zTableName[1])); sqlite3_free(pVtab->zTableName); pVtab->zTableName = z; pVtab->isPattern = 1; @@ -440,8 +440,8 @@ static int echoCreate( if( rc==SQLITE_OK && argc==5 ){ char *zSql; echo_vtab *pVtab = *(echo_vtab **)ppVtab; - pVtab->zLogName = sqlite3MPrintf("%s", argv[4]); - zSql = sqlite3MPrintf("CREATE TABLE %Q(logmsg)", pVtab->zLogName); + pVtab->zLogName = sqlite3MPrintf(0, "%s", argv[4]); + zSql = sqlite3MPrintf(0, "CREATE TABLE %Q(logmsg)", pVtab->zLogName); rc = sqlite3_exec(db, zSql, 0, 0, 0); sqlite3_free(zSql); } @@ -482,7 +482,7 @@ static int echoDestroy(sqlite3_vtab *pVtab){ /* Drop the "log" table, if one exists (see echoCreate() for details) */ if( p && p->zLogName ){ char *zSql; - zSql = sqlite3MPrintf("DROP TABLE %Q", p->zLogName); + zSql = sqlite3MPrintf(0, "DROP TABLE %Q", p->zLogName); rc = sqlite3_exec(p->db, zSql, 0, 0, 0); sqlite3_free(zSql); } @@ -1037,7 +1037,7 @@ static int echoRename(sqlite3_vtab *vtab, const char *zNewName){ if( p->isPattern ){ int nThis = strlen(p->zThis); - char *zSql = sqlite3MPrintf("ALTER TABLE %s RENAME TO %s%s", + char *zSql = sqlite3MPrintf(0, "ALTER TABLE %s RENAME TO %s%s", p->zTableName, zNewName, &p->zTableName[nThis] ); rc = sqlite3_exec(p->db, zSql, 0, 0, 0); diff --git a/src/tokenize.c b/src/tokenize.c index 72f8c075b6..774166d7fe 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -15,7 +15,7 @@ ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** -** $Id: tokenize.c,v 1.132 2007/08/16 04:30:40 drh Exp $ +** $Id: tokenize.c,v 1.133 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -435,7 +435,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ case TK_ILLEGAL: { if( pzErrMsg ){ sqlite3_free(*pzErrMsg); - *pzErrMsg = sqlite3MPrintf("unrecognized token: \"%T\"", + *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"", &pParse->sLastToken); } nErr++; diff --git a/src/trigger.c b/src/trigger.c index 6a581b2d88..785e57e43e 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -253,8 +253,9 @@ void sqlite3FinishTrigger( sqlite3VdbeChangeP3(v, addr+6, (char*)pAll->z, pAll->n); sqlite3ChangeCookie(db, v, iDb); sqlite3VdbeAddOp(v, OP_Close, 0, 0); - sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, - sqlite3MPrintf("type='trigger' AND name='%q'", pTrig->name), P3_DYNAMIC); + sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, sqlite3MPrintf( + db, "type='trigger' AND name='%q'", pTrig->name), P3_DYNAMIC + ); } if( db->init.busy ){ diff --git a/src/update.c b/src/update.c index 3348470fe6..6cf7f73635 100644 --- a/src/update.c +++ b/src/update.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle UPDATE statements. ** -** $Id: update.c,v 1.139 2007/08/16 04:30:40 drh Exp $ +** $Id: update.c,v 1.140 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -60,7 +60,7 @@ void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){ u8 enc = ENC(sqlite3VdbeDb(v)); Column *pCol = &pTab->aCol[i]; assert( inCol ); - sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue); + sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc, pCol->affinity, &pValue); if( pValue ){ sqlite3VdbeChangeP3(v, -1, (const char *)pValue, P3_MEM); }else{ diff --git a/src/utf.c b/src/utf.c index 76c3a15fa8..3c1a16f108 100644 --- a/src/utf.c +++ b/src/utf.c @@ -12,7 +12,7 @@ ** This file contains routines used to translate between UTF-8, ** UTF-16, UTF-16BE, and UTF-16LE. ** -** $Id: utf.c,v 1.54 2007/08/16 04:30:40 drh Exp $ +** $Id: utf.c,v 1.55 2007/08/16 10:09:03 danielk1977 Exp $ ** ** Notes on UTF-8: ** @@ -216,7 +216,7 @@ int sqlite3VdbeMemTranslate(sqlite3 *db, Mem *pMem, u8 desiredEnc){ if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){ u8 temp; int rc; - rc = sqlite3VdbeMemMakeWriteable(pMem); + rc = sqlite3VdbeMemMakeWriteable(db, pMem); if( rc!=SQLITE_OK ){ assert( rc==SQLITE_NOMEM ); return SQLITE_NOMEM; @@ -336,7 +336,7 @@ translate_out: ** The allocation (static, dynamic etc.) and encoding of the Mem may be ** changed by this function. */ -int sqlite3VdbeMemHandleBom(Mem *pMem){ +int sqlite3VdbeMemHandleBom(sqlite3 *db, Mem *pMem){ int rc = SQLITE_OK; u8 bom = 0; @@ -364,10 +364,11 @@ int sqlite3VdbeMemHandleBom(Mem *pMem){ char *z = pMem->z; pMem->z = 0; pMem->xDel = 0; - rc = sqlite3VdbeMemSetStr(pMem, &z[2], pMem->n-2, bom, SQLITE_TRANSIENT); + rc = sqlite3VdbeMemSetStr(db, pMem, &z[2], pMem->n-2, bom, + SQLITE_TRANSIENT); xDel(z); }else{ - rc = sqlite3VdbeMemSetStr(pMem, &pMem->z[2], pMem->n-2, bom, + rc = sqlite3VdbeMemSetStr(db, pMem, &pMem->z[2], pMem->n-2, bom, SQLITE_TRANSIENT); } } diff --git a/src/util.c b/src/util.c index fef1c00c8a..975aa19ba6 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,7 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.208 2007/08/16 04:30:40 drh Exp $ +** $Id: util.c,v 1.209 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -44,17 +44,17 @@ ** to NULL. */ void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){ - if( db && (db->pErr || (db->pErr = sqlite3ValueNew())!=0) ){ + if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){ db->errCode = err_code; if( zFormat ){ char *z; va_list ap; va_start(ap, zFormat); - z = sqlite3VMPrintf(zFormat, ap); + z = sqlite3VMPrintf(db, zFormat, ap); va_end(ap); - sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, sqlite3FreeX); + sqlite3ValueSetStr(db, db->pErr, -1, z, SQLITE_UTF8, sqlite3_free); }else{ - sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC); + sqlite3ValueSetStr(db, db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC); } } } @@ -79,9 +79,9 @@ void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){ void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){ va_list ap; pParse->nErr++; - sqliteFree(pParse->zErrMsg); + sqlite3_free(pParse->zErrMsg); va_start(ap, zFormat); - pParse->zErrMsg = sqlite3VMPrintf(zFormat, ap); + pParse->zErrMsg = sqlite3VMPrintf(pParse->db, zFormat, ap); va_end(ap); if( pParse->rc==SQLITE_OK ){ pParse->rc = SQLITE_ERROR; @@ -92,7 +92,7 @@ void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){ ** Clear the error message in pParse, if any */ void sqlite3ErrorClear(Parse *pParse){ - sqliteFree(pParse->zErrMsg); + sqlite3_free(pParse->zErrMsg); pParse->zErrMsg = 0; pParse->nErr = 0; } diff --git a/src/vdbe.c b/src/vdbe.c index 00abd1630d..02069a3f48 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.640 2007/08/16 04:30:40 drh Exp $ +** $Id: vdbe.c,v 1.641 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -106,8 +106,8 @@ int sqlite3_max_blobsize = 0; ** Convert the given stack entity into a string if it isn't one ** already. Return non-zero if a malloc() fails. */ -#define Stringify(P, enc) \ - if(((P)->flags&(MEM_Str|MEM_Blob))==0 && sqlite3VdbeMemStringify(P,enc)) \ +#define Stringify(db, P, enc) \ + if(((P)->flags&(MEM_Str|MEM_Blob))==0 && sqlite3VdbeMemStringify(db,P,enc)) \ { goto no_mem; } /* @@ -138,15 +138,15 @@ int sqlite3_max_blobsize = 0; ** string that the stack entry itself controls. In other words, it ** converts an MEM_Ephem string into an MEM_Dyn string. */ -#define Deephemeralize(P) \ +#define Deephemeralize(db,P) \ if( ((P)->flags&MEM_Ephem)!=0 \ - && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;} + && sqlite3VdbeMemMakeWriteable(db, P) ){ goto no_mem;} /* ** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*) ** P if required. */ -#define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) +#define ExpandBlob(D,P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(D,P):0) /* ** Argument pMem points at a memory cell that will be passed to a @@ -282,7 +282,7 @@ static void applyAffinity( */ int sqlite3_value_numeric_type(sqlite3_value *pVal){ Mem *pMem = (Mem*)pVal; - applyNumericAffinity(pMem); + applyNumericAffinity(0, pMem); storeTypeInfo(pMem, 0); return pMem->type; } @@ -291,8 +291,13 @@ int sqlite3_value_numeric_type(sqlite3_value *pVal){ ** Exported version of applyAffinity(). This one works on sqlite3_value*, ** not the internal Mem* type. */ -void sqlite3ValueApplyAffinity(sqlite3_value *pVal, u8 affinity, u8 enc){ - applyAffinity((Mem *)pVal, affinity, enc); +void sqlite3ValueApplyAffinity( + sqlite3 *db, + sqlite3_value *pVal, + u8 affinity, + u8 enc +){ + applyAffinity(db, (Mem *)pVal, affinity, enc); } #ifdef SQLITE_DEBUG @@ -728,7 +733,7 @@ case OP_Real: { /* same as TK_FLOAT, */ pTos->enc = SQLITE_UTF8; pTos->r = sqlite3VdbeRealValue(pTos); pTos->flags |= MEM_Real; - sqlite3VdbeChangeEncoding(pTos, encoding); + sqlite3VdbeChangeEncoding(db, pTos, encoding); break; } @@ -747,8 +752,8 @@ case OP_String8: { /* same as TK_STRING */ #ifndef SQLITE_OMIT_UTF16 if( encoding!=SQLITE_UTF8 ){ pTos++; - sqlite3VdbeMemSetStr(pTos, pOp->p3, -1, SQLITE_UTF8, SQLITE_STATIC); - if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pTos, encoding) ) goto no_mem; + sqlite3VdbeMemSetStr(db, pTos, pOp->p3, -1, SQLITE_UTF8, SQLITE_STATIC); + if( SQLITE_OK!=sqlite3VdbeChangeEncoding(db, pTos, encoding) ) goto no_mem; if( SQLITE_OK!=sqlite3VdbeMemDynamicify(db, pTos) ) goto no_mem; pTos->flags &= ~(MEM_Dyn); pTos->flags |= MEM_Static; @@ -807,7 +812,7 @@ case OP_HexBlob: { /* same as TK_BLOB */ assert( SQLITE_MAX_SQL_LENGTH < SQLITE_MAX_LENGTH ); assert( pOp->p1 < SQLITE_MAX_LENGTH ); if( pOp->p1 ){ - char *zBlob = sqlite3HexToBlob(pOp->p3); + char *zBlob = sqlite3HexToBlob(db, pOp->p3); if( !zBlob ) goto no_mem; if( pOp->p3type==P3_DYNAMIC ){ sqlite3_free(pOp->p3); @@ -837,7 +842,7 @@ case OP_HexBlob: { /* same as TK_BLOB */ case OP_Blob: { pTos++; assert( pOp->p1 < SQLITE_MAX_LENGTH ); /* Due to SQLITE_MAX_SQL_LENGTH */ - sqlite3VdbeMemSetStr(pTos, pOp->p3, pOp->p1, 0, 0); + sqlite3VdbeMemSetStr(db, pTos, pOp->p3, pOp->p1, 0, 0); pTos->enc = encoding; break; } @@ -898,7 +903,7 @@ case OP_Dup: { pTos++; sqlite3VdbeMemShallowCopy(pTos, pFrom, MEM_Ephem); if( pOp->p2 ){ - Deephemeralize(pTos); + Deephemeralize(db, pTos); } break; } @@ -919,9 +924,9 @@ case OP_Pull: { /* no-push */ Mem ts; ts = *pFrom; - Deephemeralize(pTos); + Deephemeralize(db, pTos); for(i=0; ip1; i++, pFrom++){ - Deephemeralize(&pFrom[1]); + Deephemeralize(db, &pFrom[1]); assert( (pFrom[1].flags & MEM_Ephem)==0 ); *pFrom = pFrom[1]; if( pFrom->flags & MEM_Short ){ @@ -949,7 +954,7 @@ case OP_Push: { /* no-push */ Mem *pTo = &pTos[-pOp->p1]; assert( pTo>=p->aStack ); - sqlite3VdbeMemMove(pTo, pTos); + sqlite3VdbeMemMove(db, pTo, pTos); pTos--; break; } @@ -977,7 +982,7 @@ case OP_Callback: { /* no-push */ */ pFirstColumn = &pTos[0-pOp->p1]; for(pMem = p->aStack; pMemn; } @@ -1316,10 +1321,10 @@ case OP_Function: { } /* Copy the result of the function to the top of the stack */ - sqlite3VdbeChangeEncoding(&ctx.s, encoding); + sqlite3VdbeChangeEncoding(db, &ctx.s, encoding); pTos++; pTos->flags = 0; - sqlite3VdbeMemMove(pTos, &ctx.s); + sqlite3VdbeMemMove(db, pTos, &ctx.s); if( sqlite3VdbeMemTooBig(pTos) ){ goto too_big; } @@ -1412,7 +1417,7 @@ case OP_AddImm: { /* no-push */ case OP_ForceInt: { /* no-push */ i64 v; assert( pTos>=p->aStack ); - applyAffinity(pTos, SQLITE_AFF_NUMERIC, encoding); + applyAffinity(db, pTos, SQLITE_AFF_NUMERIC, encoding); if( (pTos->flags & (MEM_Int|MEM_Real))==0 ){ Release(pTos); pTos--; @@ -1447,7 +1452,7 @@ case OP_ForceInt: { /* no-push */ */ case OP_MustBeInt: { /* no-push */ assert( pTos>=p->aStack ); - applyAffinity(pTos, SQLITE_AFF_NUMERIC, encoding); + applyAffinity(db, pTos, SQLITE_AFF_NUMERIC, encoding); if( (pTos->flags & MEM_Int)==0 ){ if( pOp->p2==0 ){ rc = SQLITE_MISMATCH; @@ -1495,8 +1500,8 @@ case OP_ToText: { /* same as TK_TO_TEXT, no-push */ if( pTos->flags & MEM_Null ) break; assert( MEM_Str==(MEM_Blob>>3) ); pTos->flags |= (pTos->flags&MEM_Blob)>>3; - applyAffinity(pTos, SQLITE_AFF_TEXT, encoding); - rc = ExpandBlob(pTos); + applyAffinity(db, pTos, SQLITE_AFF_TEXT, encoding); + rc = ExpandBlob(db, pTos); assert( pTos->flags & MEM_Str ); pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Blob); break; @@ -1515,7 +1520,7 @@ case OP_ToBlob: { /* same as TK_TO_BLOB, no-push */ assert( pTos>=p->aStack ); if( pTos->flags & MEM_Null ) break; if( (pTos->flags & MEM_Blob)==0 ){ - applyAffinity(pTos, SQLITE_AFF_TEXT, encoding); + applyAffinity(db, pTos, SQLITE_AFF_TEXT, encoding); assert( pTos->flags & MEM_Str ); pTos->flags |= MEM_Blob; } @@ -1696,13 +1701,13 @@ case OP_Ge: { /* same as TK_GE, no-push */ affinity = pOp->p1 & 0xFF; if( affinity ){ - applyAffinity(pNos, affinity, encoding); - applyAffinity(pTos, affinity, encoding); + applyAffinity(db, pNos, affinity, encoding); + applyAffinity(db, pTos, affinity, encoding); } assert( pOp->p3type==P3_COLLSEQ || pOp->p3==0 ); - ExpandBlob(pNos); - ExpandBlob(pTos); + ExpandBlob(db, pNos); + ExpandBlob(db, pTos); res = sqlite3MemCompare(pNos, pTos, (CollSeq*)pOp->p3); switch( pOp->opcode ){ case OP_Eq: res = res==0; break; @@ -2113,7 +2118,7 @@ case OP_Column: { ** acquire the complete header text. */ if( !zRec && availisIndex, &sMem); + rc = sqlite3VdbeMemFromBtree(db, pCrsr, 0, offset, pC->isIndex, &sMem); if( rc!=SQLITE_OK ){ goto op_column_out; } @@ -2167,7 +2172,8 @@ case OP_Column: { zData = &zRec[aOffset[p2]]; }else{ len = sqlite3VdbeSerialTypeLen(aType[p2]); - rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, pC->isIndex,&sMem); + rc = sqlite3VdbeMemFromBtree( + db, pCrsr, aOffset[p2], len, pC->isIndex, &sMem); if( rc!=SQLITE_OK ){ goto op_column_out; } @@ -2199,7 +2205,7 @@ case OP_Column: { /* pTos->z might be pointing to sMem.zShort[]. Fix that so that we ** can abandon sMem */ - rc = sqlite3VdbeMemMakeWriteable(pTos); + rc = sqlite3VdbeMemMakeWriteable(db, pTos); op_column_out: break; @@ -2295,13 +2301,13 @@ case OP_MakeRecord: { for(pRec=pData0; pRec<=pTos; pRec++){ int len; if( zAffinity ){ - applyAffinity(pRec, zAffinity[pRec-pData0], encoding); + applyAffinity(db, pRec, zAffinity[pRec-pData0], encoding); } if( pRec->flags&MEM_Null ){ containsNull = 1; } if( pRec->flags&MEM_Zero && pRec->n>0 ){ - ExpandBlob(pRec); + ExpandBlob(db, pRec); } serial_type = sqlite3VdbeSerialType(pRec, file_format); len = sqlite3VdbeSerialTypeLen(serial_type); @@ -2967,7 +2973,7 @@ case OP_MoveGt: { /* no-push */ pC->rowidIsValid = res==0; }else{ assert( pTos->flags & MEM_Blob ); - ExpandBlob(pTos); + ExpandBlob(db, pTos); rc = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, 0, &res); if( rc!=SQLITE_OK ){ goto abort_due_to_error; @@ -3075,7 +3081,7 @@ case OP_Found: { /* no-push */ int res, rx; assert( pC->isTable==0 ); assert( pTos->flags & MEM_Blob ); - Stringify(pTos, encoding); + Stringify(db, pTos, encoding); rx = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, 0, &res); alreadyExists = rx==SQLITE_OK && res==0; pC->deferredMoveto = 0; @@ -3143,7 +3149,7 @@ case OP_IsUnique: { /* no-push */ /* Make sure K is a string and make zKey point to K */ assert( pNos->flags & MEM_Blob ); - Stringify(pNos, encoding); + Stringify(db, pNos, encoding); zKey = pNos->z; nKey = pNos->n; @@ -3166,7 +3172,7 @@ case OP_IsUnique: { /* no-push */ break; } } - rc = sqlite3VdbeIdxKeyCompare(pCx, len, (u8*)zKey, &res); + rc = sqlite3VdbeIdxKeyCompare(db, pCx, len, (u8*)zKey, &res); if( rc!=SQLITE_OK ) goto abort_due_to_error; if( res>0 ){ pc = pOp->p2 - 1; @@ -3178,7 +3184,7 @@ case OP_IsUnique: { /* no-push */ ** final rowid column is different from R. If it equals R then jump ** immediately to P2. */ - rc = sqlite3VdbeIdxRowid(pCrsr, &v); + rc = sqlite3VdbeIdxRowid(db, pCrsr, &v); if( rc!=SQLITE_OK ){ goto abort_due_to_error; } @@ -3870,7 +3876,7 @@ case OP_IdxInsert: { /* no-push */ assert( pTos->flags & MEM_Blob ); if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){ assert( pC->isTable==0 ); - rc = ExpandBlob(pTos); + rc = ExpandBlob(db, pTos); if( rc==SQLITE_OK ){ int nKey = pTos->n; const char *zKey = pTos->z; @@ -3937,7 +3943,7 @@ case OP_IdxRowid: { if( pC->nullRow ){ pTos->flags = MEM_Null; }else{ - rc = sqlite3VdbeIdxRowid(pCrsr, &rowid); + rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid); if( rc!=SQLITE_OK ){ goto abort_due_to_error; } @@ -4006,10 +4012,10 @@ case OP_IdxGE: { /* no-push */ assert( pTos->flags & MEM_Blob ); /* Created using OP_MakeRecord */ assert( pC->deferredMoveto==0 ); - ExpandBlob(pTos); + ExpandBlob(db, pTos); *pC->pIncrKey = pOp->p3!=0; assert( pOp->p3==0 || pOp->opcode!=OP_IdxGT ); - rc = sqlite3VdbeIdxKeyCompare(pC, pTos->n, (u8*)pTos->z, &res); + rc = sqlite3VdbeIdxKeyCompare(db, pC, pTos->n, (u8*)pTos->z, &res); *pC->pIncrKey = 0; if( rc!=SQLITE_OK ){ break; @@ -4202,7 +4208,7 @@ case OP_ParseSchema: { /* no-push */ initData.db = db; initData.iDb = pOp->p1; initData.pzErrMsg = &p->zErrMsg; - zSql = sqlite3MPrintf( + zSql = sqlite3MPrintf(db, "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s", db->aDb[iDb].zName, zMaster, pOp->p3); if( zSql==0 ) goto no_mem; @@ -4331,7 +4337,7 @@ case OP_IntegrityCk: { pTos->xDel = 0; } pTos->enc = SQLITE_UTF8; - sqlite3VdbeChangeEncoding(pTos, encoding); + sqlite3VdbeChangeEncoding(db, pTos, encoding); sqlite3_free(aRoot); break; } @@ -4346,7 +4352,7 @@ case OP_FifoWrite: { /* no-push */ assert( pTos>=p->aStack ); sqlite3VdbeMemIntegerify(pTos); if( sqlite3VdbeFifoPush(&p->sFifo, pTos->u.i)==SQLITE_NOMEM ){ - goto nomem; + goto no_mem; } assert( (pTos->flags & MEM_Dyn)==0 ); pTos--; @@ -4387,7 +4393,7 @@ case OP_ContextPush: { /* no-push */ /* FIX ME: This should be allocated as part of the vdbe at compile-time */ if( i>=p->contextStackDepth ){ p->contextStackDepth = i+1; - p->contextStack = sqlite3ReallocOrFree(db, p->contextStack, + p->contextStack = sqlite3DbReallocOrFree(db, p->contextStack, sizeof(Context)*(i+1)); if( p->contextStack==0 ) goto no_mem; } @@ -4429,7 +4435,7 @@ case OP_ContextPop: { /* no-push */ case OP_MemStore: { /* no-push */ assert( pTos>=p->aStack ); assert( pOp->p1>=0 && pOp->p1nMem ); - rc = sqlite3VdbeMemMove(&p->aMem[pOp->p1], pTos); + rc = sqlite3VdbeMemMove(db, &p->aMem[pOp->p1], pTos); pTos--; /* If P2 is 0 then fall thru to the next opcode, OP_MemLoad, that will @@ -4583,7 +4589,7 @@ case OP_MemInt: { case OP_MemMove: { assert( pOp->p1>=0 && pOp->p1nMem ); assert( pOp->p2>=0 && pOp->p2nMem ); - rc = sqlite3VdbeMemMove(&p->aMem[pOp->p1], &p->aMem[pOp->p2]); + rc = sqlite3VdbeMemMove(db, &p->aMem[pOp->p1], &p->aMem[pOp->p2]); break; } @@ -4950,10 +4956,10 @@ case OP_VColumn: { ** do this regardless of whether or not an error occured to ensure any ** dynamic allocation in sContext.s (a Mem struct) is released. */ - sqlite3VdbeChangeEncoding(&sContext.s, encoding); + sqlite3VdbeChangeEncoding(db, &sContext.s, encoding); pTos++; pTos->flags = 0; - sqlite3VdbeMemMove(pTos, &sContext.s); + sqlite3VdbeMemMove(db, pTos, &sContext.s); if( sqlite3SafetyOn(db) ){ goto abort_due_to_misuse; @@ -5022,7 +5028,7 @@ case OP_VRename: { /* no-push */ sqlite3_vtab *pVtab = (sqlite3_vtab *)(pOp->p3); assert( pVtab->pModule->xRename ); - Stringify(pTos, encoding); + Stringify(db, pTos, encoding); if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse; sqlite3VtabLock(pVtab); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 9ed2e4fadb..a7b711bfc9 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -376,56 +376,56 @@ int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); void sqlite3VdbeDeleteAuxData(VdbeFunc*, int); int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); -int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*); -int sqlite3VdbeIdxRowid(BtCursor *, i64 *); +int sqlite3VdbeIdxKeyCompare(sqlite3*,Cursor*,int,const unsigned char*,int*); +int sqlite3VdbeIdxRowid(sqlite3 *, BtCursor *, i64 *); int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); int sqlite3VdbeRecordCompare(void*,int,const void*,int, const void*); int sqlite3VdbeIdxRowidLen(const u8*); int sqlite3VdbeExec(Vdbe*); int sqlite3VdbeList(Vdbe*); int sqlite3VdbeHalt(Vdbe*); -int sqlite3VdbeChangeEncoding(Mem *, int); +int sqlite3VdbeChangeEncoding(sqlite3 *, Mem *, int); int sqlite3VdbeMemTooBig(Mem*); -int sqlite3VdbeMemCopy(Mem*, const Mem*); +int sqlite3VdbeMemCopy(sqlite3*, Mem*, const Mem*); void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int); -int sqlite3VdbeMemMove(Mem*, Mem*); -int sqlite3VdbeMemNulTerminate(Mem*); -int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*)); +int sqlite3VdbeMemMove(sqlite3*, Mem*, Mem*); +int sqlite3VdbeMemNulTerminate(sqlite3 *, Mem*); +int sqlite3VdbeMemSetStr(sqlite3 *, Mem*, const char*, int, u8, void(*)(void*)); void sqlite3VdbeMemSetInt64(Mem*, i64); void sqlite3VdbeMemSetDouble(Mem*, double); void sqlite3VdbeMemSetNull(Mem*); void sqlite3VdbeMemSetZeroBlob(Mem*,int); -int sqlite3VdbeMemMakeWriteable(Mem*); -int sqlite3VdbeMemDynamicify(Mem*); -int sqlite3VdbeMemStringify(Mem*, int); +int sqlite3VdbeMemMakeWriteable(sqlite3 *, Mem*); +int sqlite3VdbeMemDynamicify(sqlite3 *, Mem*); +int sqlite3VdbeMemStringify(sqlite3*, Mem*, int); i64 sqlite3VdbeIntValue(Mem*); int sqlite3VdbeMemIntegerify(Mem*); double sqlite3VdbeRealValue(Mem*); void sqlite3VdbeIntegerAffinity(Mem*); int sqlite3VdbeMemRealify(Mem*); int sqlite3VdbeMemNumerify(Mem*); -int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*); +int sqlite3VdbeMemFromBtree(sqlite3*,BtCursor*,int,int,int,Mem*); void sqlite3VdbeMemRelease(Mem *p); int sqlite3VdbeMemFinalize(Mem*, FuncDef*); #ifndef NDEBUG void sqlite3VdbeMemSanity(Mem*); int sqlite3VdbeOpcodeNoPush(u8); #endif -int sqlite3VdbeMemTranslate(Mem*, u8); +int sqlite3VdbeMemTranslate(sqlite3 *, Mem*, u8); #ifdef SQLITE_DEBUG void sqlite3VdbePrintSql(Vdbe*); void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf); #endif -int sqlite3VdbeMemHandleBom(Mem *pMem); +int sqlite3VdbeMemHandleBom(sqlite3 *, Mem *pMem); void sqlite3VdbeFifoInit(Fifo*); int sqlite3VdbeFifoPush(Fifo*, i64); int sqlite3VdbeFifoPop(Fifo*, i64*); void sqlite3VdbeFifoClear(Fifo*); #ifndef SQLITE_OMIT_INCRBLOB - int sqlite3VdbeMemExpandBlob(Mem *); + int sqlite3VdbeMemExpandBlob(sqlite3 *, Mem *); #else - #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK + #define sqlite3VdbeMemExpandBlob(d,x) SQLITE_OK #endif #endif /* !defined(_VDBEINT_H_) */ diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 808d496c39..6b80796a0e 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -37,7 +37,7 @@ int sqlite3_expired(sqlite3_stmt *pStmt){ const void *sqlite3_value_blob(sqlite3_value *pVal){ Mem *p = (Mem*)pVal; if( p->flags & (MEM_Blob|MEM_Str) ){ - sqlite3VdbeMemExpandBlob(p); + sqlite3VdbeMemExpandBlob(0, p); p->flags &= ~MEM_Str; p->flags |= MEM_Blob; return p->z; @@ -46,10 +46,10 @@ const void *sqlite3_value_blob(sqlite3_value *pVal){ } } int sqlite3_value_bytes(sqlite3_value *pVal){ - return sqlite3ValueBytes(pVal, SQLITE_UTF8); + return sqlite3ValueBytes(0, pVal, SQLITE_UTF8); } int sqlite3_value_bytes16(sqlite3_value *pVal){ - return sqlite3ValueBytes(pVal, SQLITE_UTF16NATIVE); + return sqlite3ValueBytes(0, pVal, SQLITE_UTF16NATIVE); } double sqlite3_value_double(sqlite3_value *pVal){ return sqlite3VdbeRealValue((Mem*)pVal); @@ -61,17 +61,17 @@ sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){ return sqlite3VdbeIntValue((Mem*)pVal); } const unsigned char *sqlite3_value_text(sqlite3_value *pVal){ - return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8); + return (const unsigned char *)sqlite3ValueText(0, pVal, SQLITE_UTF8); } #ifndef SQLITE_OMIT_UTF16 const void *sqlite3_value_text16(sqlite3_value* pVal){ - return sqlite3ValueText(pVal, SQLITE_UTF16NATIVE); + return sqlite3ValueText(0, pVal, SQLITE_UTF16NATIVE); } const void *sqlite3_value_text16be(sqlite3_value *pVal){ - return sqlite3ValueText(pVal, SQLITE_UTF16BE); + return sqlite3ValueText(0, pVal, SQLITE_UTF16BE); } const void *sqlite3_value_text16le(sqlite3_value *pVal){ - return sqlite3ValueText(pVal, SQLITE_UTF16LE); + return sqlite3ValueText(0, pVal, SQLITE_UTF16LE); } #endif /* SQLITE_OMIT_UTF16 */ int sqlite3_value_type(sqlite3_value* pVal){ @@ -90,19 +90,19 @@ void sqlite3_result_blob( void (*xDel)(void *) ){ assert( n>=0 ); - sqlite3VdbeMemSetStr(&pCtx->s, z, n, 0, xDel); + sqlite3VdbeMemSetStr(0, &pCtx->s, z, n, 0, xDel); } void sqlite3_result_double(sqlite3_context *pCtx, double rVal){ sqlite3VdbeMemSetDouble(&pCtx->s, rVal); } void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ pCtx->isError = 1; - sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); + sqlite3VdbeMemSetStr(0, &pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); } #ifndef SQLITE_OMIT_UTF16 void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ pCtx->isError = 1; - sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); + sqlite3VdbeMemSetStr(0, &pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); } #endif void sqlite3_result_int(sqlite3_context *pCtx, int iVal){ @@ -120,7 +120,7 @@ void sqlite3_result_text( int n, void (*xDel)(void *) ){ - sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, xDel); + sqlite3VdbeMemSetStr(0, &pCtx->s, z, n, SQLITE_UTF8, xDel); } #ifndef SQLITE_OMIT_UTF16 void sqlite3_result_text16( @@ -129,7 +129,7 @@ void sqlite3_result_text16( int n, void (*xDel)(void *) ){ - sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, xDel); + sqlite3VdbeMemSetStr(0, &pCtx->s, z, n, SQLITE_UTF16NATIVE, xDel); } void sqlite3_result_text16be( sqlite3_context *pCtx, @@ -137,7 +137,7 @@ void sqlite3_result_text16be( int n, void (*xDel)(void *) ){ - sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16BE, xDel); + sqlite3VdbeMemSetStr(0, &pCtx->s, z, n, SQLITE_UTF16BE, xDel); } void sqlite3_result_text16le( sqlite3_context *pCtx, @@ -145,11 +145,11 @@ void sqlite3_result_text16le( int n, void (*xDel)(void *) ){ - sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16LE, xDel); + sqlite3VdbeMemSetStr(0, &pCtx->s, z, n, SQLITE_UTF16LE, xDel); } #endif /* SQLITE_OMIT_UTF16 */ void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){ - sqlite3VdbeMemCopy(&pCtx->s, pValue); + sqlite3VdbeMemCopy(0, &pCtx->s, pValue); } void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){ sqlite3VdbeMemSetZeroBlob(&pCtx->s, n); @@ -332,10 +332,10 @@ void sqlite3InvalidFunction( ){ const char *zName = context->pFunc->zName; char *zErr; - zErr = sqlite3MPrintf( + zErr = sqlite3MPrintf(0, "unable to use function %s in the requested context", zName); sqlite3_result_error(context, zErr, -1); - sqliteFree(zErr); + sqlite3_free(zErr); } /* @@ -352,7 +352,7 @@ void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){ pMem->z = 0; }else{ pMem->flags = MEM_Agg; - pMem->xDel = sqlite3FreeX; + pMem->xDel = sqlite3_free; pMem->u.pDef = p->pFunc; if( nByte<=NBFS ){ pMem->z = pMem->zShort; @@ -736,13 +736,13 @@ static int bindText( return rc; } pVar = &p->aVar[i-1]; - rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel); + rc = sqlite3VdbeMemSetStr(0, pVar, zData, nData, encoding, xDel); if( rc==SQLITE_OK && encoding!=0 ){ - rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db)); + rc = sqlite3VdbeChangeEncoding(p->db, pVar, ENC(p->db)); } - sqlite3Error(((Vdbe *)pStmt)->db, rc, 0); - return sqlite3ApiExit(((Vdbe *)pStmt)->db, rc); + sqlite3Error(p->db, rc, 0); + return sqlite3ApiExit(p->db, rc); } @@ -807,7 +807,7 @@ int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){ Vdbe *p = (Vdbe *)pStmt; rc = vdbeUnbind(p, i); if( rc==SQLITE_OK ){ - sqlite3VdbeMemCopy(&p->aVar[i-1], pValue); + rc = sqlite3VdbeMemCopy(0, &p->aVar[i-1], pValue); } return rc; } @@ -905,7 +905,7 @@ int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ } for(i=0; rc==SQLITE_OK && inVar; i++){ sqlite3MallocDisallow(); - rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]); + rc = sqlite3VdbeMemMove(0, &pTo->aVar[i], &pFrom->aVar[i]); sqlite3MallocAllow(); } assert( rc==SQLITE_OK || rc==SQLITE_NOMEM ); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index f5ccec0b6a..47b55c0328 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -122,7 +122,7 @@ static void resizeOpArray(Vdbe *p, int N){ VdbeOp *pNew; int nNew = N + 100*(!runMode); int oldSize = p->nOpAlloc; - pNew = sqlite_realloc(p->aOp, nNew*sizeof(Op)); + pNew = sqlite3_realloc(p->aOp, nNew*sizeof(Op)); if( pNew ){ p->nOpAlloc = nNew; p->aOp = pNew; @@ -206,7 +206,7 @@ int sqlite3VdbeMakeLabel(Vdbe *p){ assert( p->magic==VDBE_MAGIC_INIT ); if( i>=p->nLabelAlloc ){ p->nLabelAlloc = p->nLabelAlloc*2 + 10; - p->aLabel = sqlite3ReallocOrFree(p->db, p->aLabel, + p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, p->nLabelAlloc*sizeof(p->aLabel[0])); } if( p->aLabel ){ @@ -579,7 +579,7 @@ void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){ assert( p->nOp>0 || p->aOp==0 ); assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 || p->db->mallocFailed ); va_start(ap, zFormat); - sqlite3VdbeChangeP3(p, -1, sqlite3VMPrintf(zFormat, ap), P3_DYNAMIC); + sqlite3VdbeChangeP3(p, -1, sqlite3VMPrintf(p->db, zFormat, ap), P3_DYNAMIC); va_end(ap); } #endif @@ -840,6 +840,7 @@ void sqlite3VdbeMakeReady( int isExplain /* True if the EXPLAIN keywords is present */ ){ int n; + sqlite3 *db = p->db; assert( p!=0 ); assert( p->magic==VDBE_MAGIC_INIT ); @@ -874,7 +875,7 @@ void sqlite3VdbeMakeReady( if( isExplain ){ nStack = 10; } - p->aStack = sqlite3DbMallocZer(db, + p->aStack = sqlite3DbMallocZero(db, nStack*sizeof(p->aStack[0]) /* aStack */ + nArg*sizeof(Mem*) /* apArg */ + nVar*sizeof(Mem) /* aVar */ @@ -1012,7 +1013,7 @@ void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){ sqlite3_free(p->aColName); n = nResColumn*COLNAME_N; p->nResColumn = nResColumn; - p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n ); + p->aColName = pColName = (Mem*)sqlite3DbMallocZero(p->db, sizeof(Mem)*n ); if( p->aColName==0 ) return; while( n-- > 0 ){ (pColName++)->flags = MEM_Null; @@ -1039,9 +1040,11 @@ int sqlite3VdbeSetColName(Vdbe *p, int idx, int var, const char *zName, int N){ assert( p->aColName!=0 ); pColName = &(p->aColName[idx+var*p->nResColumn]); if( N==P3_DYNAMIC || N==P3_STATIC ){ - rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, SQLITE_STATIC); + rc = sqlite3VdbeMemSetStr(p->db, + pColName, zName, -1, SQLITE_UTF8, SQLITE_STATIC); }else{ - rc = sqlite3VdbeMemSetStr(pColName, zName, N, SQLITE_UTF8,SQLITE_TRANSIENT); + rc = sqlite3VdbeMemSetStr(p->db, + pColName, zName, N, SQLITE_UTF8, SQLITE_TRANSIENT); } if( rc==SQLITE_OK && N==P3_DYNAMIC ){ pColName->flags = (pColName->flags&(~MEM_Static))|MEM_Dyn; @@ -1147,7 +1150,7 @@ static int vdbeCommit(sqlite3 *db){ u32 random; sqlite3_free(zMaster); sqlite3Randomness(sizeof(random), &random); - zMaster = sqlite3MPrintf("%s-mj%08X", zMainFile, random&0x7fffffff); + zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, random&0x7fffffff); if( !zMaster ){ return SQLITE_NOMEM; } @@ -1166,7 +1169,7 @@ static int vdbeCommit(sqlite3 *db){ ** still have 'null' as the master journal pointer, so they will roll ** back independently if a failure occurs. */ - for(i=0; inDb; i++){ + for(i=0; inDb; i++){ Btree *pBt = db->aDb[i].pBt; if( i==1 ) continue; /* Ignore the TEMP database */ if( pBt && sqlite3BtreeIsInTrans(pBt) ){ @@ -1567,7 +1570,7 @@ int sqlite3VdbeReset(Vdbe *p){ */ if( p->pc>=0 ){ if( p->zErrMsg ){ - sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, sqlite3FreeX); + sqlite3ValueSetStr(db,db->pErr,-1,p->zErrMsg,SQLITE_UTF8,sqlite3_free); db->errCode = p->rc; p->zErrMsg = 0; }else if( p->rc ){ @@ -2123,7 +2126,7 @@ int sqlite3VdbeIdxRowidLen(const u8 *aKey){ ** Read the rowid (the last field in the record) and store it in *rowid. ** Return SQLITE_OK if everything works, or an error code otherwise. */ -int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){ +int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){ i64 nCellKey = 0; int rc; u32 szHdr; /* Size of the header */ @@ -2135,7 +2138,7 @@ int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){ if( nCellKey<=0 ){ return SQLITE_CORRUPT_BKPT; } - rc = sqlite3VdbeMemFromBtree(pCur, 0, nCellKey, 1, &m); + rc = sqlite3VdbeMemFromBtree(db, pCur, 0, nCellKey, 1, &m); if( rc ){ return rc; } @@ -2159,6 +2162,7 @@ int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){ ** is ignored as well. */ int sqlite3VdbeIdxKeyCompare( + sqlite3 *db, Cursor *pC, /* The cursor to compare against */ int nKey, const u8 *pKey, /* The key to compare */ int *res /* Write the comparison result here */ @@ -2174,7 +2178,7 @@ int sqlite3VdbeIdxKeyCompare( *res = 0; return SQLITE_OK; } - rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, nCellKey, 1, &m); + rc = sqlite3VdbeMemFromBtree(db, pC->pCursor, 0, nCellKey, 1, &m); if( rc ){ return rc; } diff --git a/src/vdbemem.c b/src/vdbemem.c index b0f26995dc..5d0cc9f7fa 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -40,7 +40,7 @@ ** SQLITE_NOMEM may be returned if a malloc() fails during conversion ** between formats. */ -int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){ +int sqlite3VdbeChangeEncoding(sqlite3 *db, Mem *pMem, int desiredEnc){ int rc; if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){ return SQLITE_OK; @@ -49,11 +49,10 @@ int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){ return SQLITE_ERROR; #else - /* MemTranslate() may return SQLITE_OK or SQLITE_NOMEM. If NOMEM is returned, ** then the encoding of the value may not have changed. */ - rc = sqlite3VdbeMemTranslate(pMem, desiredEnc); + rc = sqlite3VdbeMemTranslate(db, pMem, desiredEnc); assert(rc==SQLITE_OK || rc==SQLITE_NOMEM); assert(rc==SQLITE_OK || pMem->enc!=desiredEnc); assert(rc==SQLITE_NOMEM || pMem->enc==desiredEnc); @@ -165,7 +164,7 @@ int sqlite3VdbeMemNulTerminate(sqlite3 *db, Mem *pMem){ return SQLITE_OK; /* Nothing to do */ } if( pMem->flags & (MEM_Static|MEM_Ephem) ){ - return sqlite3VdbeMemMakeWriteable(pMem); + return sqlite3VdbeMemMakeWriteable(db, pMem); }else{ char *z; sqlite3VdbeMemExpandBlob(db, pMem); @@ -202,7 +201,7 @@ int sqlite3VdbeMemNulTerminate(sqlite3 *db, Mem *pMem){ ** keys are strings. In the former case a NULL pointer is returned the ** user and the later is an internal programming error. */ -int sqlite3VdbeMemStringify(Mem *pMem, int enc){ +int sqlite3VdbeMemStringify(sqlite3 *db, Mem *pMem, int enc){ int rc = SQLITE_OK; int fg = pMem->flags; char *z = pMem->zShort; @@ -227,7 +226,7 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){ pMem->z = z; pMem->enc = SQLITE_UTF8; pMem->flags |= MEM_Str | MEM_Short | MEM_Term; - sqlite3VdbeChangeEncoding(pMem, enc); + sqlite3VdbeChangeEncoding(db, pMem, enc); return rc; } @@ -306,8 +305,8 @@ i64 sqlite3VdbeIntValue(Mem *pMem){ }else if( flags & (MEM_Str|MEM_Blob) ){ i64 value; pMem->flags |= MEM_Str; - if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8) - || sqlite3VdbeMemNulTerminate(pMem) ){ + if( sqlite3VdbeChangeEncoding(0, pMem, SQLITE_UTF8) + || sqlite3VdbeMemNulTerminate(0, pMem) ){ return 0; } assert( pMem->z ); @@ -332,8 +331,8 @@ double sqlite3VdbeRealValue(Mem *pMem){ }else if( pMem->flags & (MEM_Str|MEM_Blob) ){ double val = 0.0; pMem->flags |= MEM_Str; - if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8) - || sqlite3VdbeMemNulTerminate(pMem) ){ + if( sqlite3VdbeChangeEncoding(0, pMem, SQLITE_UTF8) + || sqlite3VdbeMemNulTerminate(0, pMem) ){ return 0.0; } assert( pMem->z ); @@ -485,14 +484,14 @@ void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){ ** Make a full copy of pFrom into pTo. Prior contents of pTo are ** freed before the copy is made. */ -int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){ +int sqlite3VdbeMemCopy(sqlite3 *db, Mem *pTo, const Mem *pFrom){ int rc; if( pTo->flags & MEM_Dyn ){ sqlite3VdbeMemRelease(pTo); } sqlite3VdbeMemShallowCopy(pTo, pFrom, MEM_Ephem); if( pTo->flags & MEM_Ephem ){ - rc = sqlite3VdbeMemMakeWriteable(pTo); + rc = sqlite3VdbeMemMakeWriteable(db, pTo); }else{ rc = SQLITE_OK; } @@ -507,7 +506,7 @@ int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){ ** might be returned if pFrom held ephemeral data and we were unable ** to allocate enough space to make a copy. */ -int sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){ +int sqlite3VdbeMemMove(sqlite3 *db, Mem *pTo, Mem *pFrom){ int rc; if( pTo->flags & MEM_Dyn ){ sqlite3VdbeMemRelease(pTo); @@ -519,7 +518,7 @@ int sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){ pFrom->flags = MEM_Null; pFrom->xDel = 0; if( pTo->flags & MEM_Ephem ){ - rc = sqlite3VdbeMemMakeWriteable(pTo); + rc = sqlite3VdbeMemMakeWriteable(db, pTo); }else{ rc = SQLITE_OK; } @@ -530,6 +529,7 @@ int sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){ ** Change the value of a Mem to be a string or a BLOB. */ int sqlite3VdbeMemSetStr( + sqlite3 *db, Mem *pMem, /* Memory cell to set to string value */ const char *z, /* String pointer */ int n, /* Bytes in string, or negative */ @@ -581,13 +581,13 @@ int sqlite3VdbeMemSetStr( pMem->n = sqlite3Utf16ByteLen(pMem->z,-1); pMem->flags |= MEM_Term; } - if( sqlite3VdbeMemHandleBom(pMem) ){ + if( sqlite3VdbeMemHandleBom(db, pMem) ){ return SQLITE_NOMEM; } #endif /* SQLITE_OMIT_UTF16 */ } if( pMem->flags&MEM_Ephem ){ - return sqlite3VdbeMemMakeWriteable(pMem); + return sqlite3VdbeMemMakeWriteable(db, pMem); } return SQLITE_OK; } @@ -687,17 +687,17 @@ int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){ int n1, n2; /* Convert the strings into the encoding that the comparison ** function expects */ - v1 = sqlite3ValueText((sqlite3_value*)pMem1, pColl->enc); + v1 = sqlite3ValueText(0, (sqlite3_value*)pMem1, pColl->enc); n1 = v1==0 ? 0 : pMem1->n; - assert( n1==sqlite3ValueBytes((sqlite3_value*)pMem1, pColl->enc) ); - v2 = sqlite3ValueText((sqlite3_value*)pMem2, pColl->enc); + assert( n1==sqlite3ValueBytes(0, (sqlite3_value*)pMem1, pColl->enc) ); + v2 = sqlite3ValueText(0, (sqlite3_value*)pMem2, pColl->enc); n2 = v2==0 ? 0 : pMem2->n; - assert( n2==sqlite3ValueBytes((sqlite3_value*)pMem2, pColl->enc) ); + assert( n2==sqlite3ValueBytes(0, (sqlite3_value*)pMem2, pColl->enc) ); /* Do the comparison */ rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2); /* Convert the strings back into the database encoding */ - sqlite3ValueText((sqlite3_value*)pMem1, origEnc); - sqlite3ValueText((sqlite3_value*)pMem2, origEnc); + sqlite3ValueText(0, (sqlite3_value*)pMem1, origEnc); + sqlite3ValueText(0, (sqlite3_value*)pMem2, origEnc); return rc; } } @@ -859,7 +859,7 @@ const void *sqlite3ValueText(sqlite3 *db, sqlite3_value* pVal, u8 enc){ pVal->flags |= (pVal->flags & MEM_Blob)>>3; expandBlob(db, pVal); if( pVal->flags&MEM_Str ){ - sqlite3VdbeChangeEncoding(pVal, enc & ~SQLITE_UTF16_ALIGNED); + sqlite3VdbeChangeEncoding(db, pVal, enc & ~SQLITE_UTF16_ALIGNED); if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&(int)pVal->z) ){ assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 ); if( sqlite3VdbeMemMakeWriteable(db, pVal)!=SQLITE_OK ){ @@ -926,14 +926,14 @@ int sqlite3ValueFromExpr( pVal = sqlite3ValueNew(db); if( !zVal || !pVal ) goto no_mem; sqlite3Dequote(zVal); - sqlite3ValueSetStr(db, pVal, -1, zVal, SQLITE_UTF8, sqlite3FreeX); + sqlite3ValueSetStr(db, pVal, -1, zVal, SQLITE_UTF8, sqlite3_free); if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){ - sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc); + sqlite3ValueApplyAffinity(db, pVal, SQLITE_AFF_NUMERIC, enc); }else{ - sqlite3ValueApplyAffinity(pVal, affinity, enc); + sqlite3ValueApplyAffinity(db, pVal, affinity, enc); } }else if( op==TK_UMINUS ) { - if( SQLITE_OK==sqlite3ValueFromExpr(pExpr->pLeft, enc, affinity, &pVal) ){ + if( SQLITE_OK==sqlite3ValueFromExpr(db, pExpr->pLeft, enc, affinity, &pVal) ){ pVal->u.i = -1 * pVal->u.i; pVal->r = -1.0 * pVal->r; } @@ -941,12 +941,13 @@ int sqlite3ValueFromExpr( #ifndef SQLITE_OMIT_BLOB_LITERAL else if( op==TK_BLOB ){ int nVal; - pVal = sqlite3ValueNew(); + pVal = sqlite3ValueNew(db); zVal = sqlite3StrNDup((char*)pExpr->token.z+1, pExpr->token.n-1); if( !zVal || !pVal ) goto no_mem; sqlite3Dequote(zVal); nVal = strlen(zVal)/2; - sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(zVal), nVal, 0, sqlite3FreeX); + sqlite3VdbeMemSetStr( + db, pVal, sqlite3HexToBlob(db, zVal), nVal, 0, sqlite3_free); sqlite3_free(zVal); } #endif @@ -981,7 +982,7 @@ void sqlite3ValueSetStr( */ void sqlite3ValueFree(sqlite3_value *v){ if( !v ) return; - sqlite3ValueSetStr(v, 0, 0, SQLITE_UTF8, SQLITE_STATIC); + sqlite3ValueSetStr(0, v, 0, 0, SQLITE_UTF8, SQLITE_STATIC); sqlite3_free(v); } @@ -989,9 +990,9 @@ void sqlite3ValueFree(sqlite3_value *v){ ** Return the number of bytes in the sqlite3_value object assuming ** that it uses the encoding "enc" */ -int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){ +int sqlite3ValueBytes(sqlite3 *db, sqlite3_value *pVal, u8 enc){ Mem *p = (Mem*)pVal; - if( (p->flags & MEM_Blob)!=0 || sqlite3ValueText(pVal, enc) ){ + if( (p->flags & MEM_Blob)!=0 || sqlite3ValueText(db, pVal, enc) ){ if( p->flags & MEM_Zero ){ return p->n+p->u.i; }else{ diff --git a/src/vtab.c b/src/vtab.c index ebc1216f40..2f305acca0 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to help implement virtual tables. ** -** $Id: vtab.c,v 1.49 2007/08/16 04:30:41 drh Exp $ +** $Id: vtab.c,v 1.50 2007/08/16 10:09:03 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_VIRTUALTABLE #include "sqliteInt.h" @@ -250,7 +250,7 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){ if( pEnd ){ pParse->sNameToken.n = pEnd->z - pParse->sNameToken.z + pEnd->n; } - zStmt = sqlite3MPrintf("CREATE VIRTUAL TABLE %T", &pParse->sNameToken); + zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken); /* A slot for the record has already been allocated in the ** SQLITE_MASTER table. We just need to update that slot with all @@ -276,7 +276,7 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){ sqlite3ChangeCookie(db, v, iDb); sqlite3VdbeAddOp(v, OP_Expire, 0, 0); - zWhere = sqlite3MPrintf("name='%q'", pTab->zName); + zWhere = sqlite3MPrintf(db, "name='%q'", pTab->zName); sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 1, zWhere, P3_DYNAMIC); sqlite3VdbeOp3(v, OP_VCreate, iDb, 0, pTab->zName, strlen(pTab->zName) + 1); } @@ -343,7 +343,7 @@ static int vtabCallConstructor( const char *const*azArg = (const char *const*)pTab->azModuleArg; int nArg = pTab->nModuleArg; char *zErr = 0; - char *zModuleName = sqlite3MPrintf("%s", pTab->zName); + char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); if( !zModuleName ){ return SQLITE_NOMEM; @@ -365,14 +365,14 @@ static int vtabCallConstructor( if( SQLITE_OK!=rc ){ if( zErr==0 ){ - *pzErr = sqlite3MPrintf("vtable constructor failed: %s", zModuleName); + *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); }else { - *pzErr = sqlite3MPrintf("%s", zErr); + *pzErr = sqlite3MPrintf(db, "%s", zErr); sqlite3_free(zErr); } }else if( db->pVTab ){ const char *zFormat = "vtable constructor did not declare schema: %s"; - *pzErr = sqlite3MPrintf(zFormat, pTab->zName); + *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName); rc = SQLITE_ERROR; } if( rc==SQLITE_OK ){ @@ -503,7 +503,7 @@ int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){ ** error. Otherwise, do nothing. */ if( !pMod ){ - *pzErr = sqlite3MPrintf("no such module: %s", zModule); + *pzErr = sqlite3MPrintf(db, "no such module: %s", zModule); rc = SQLITE_ERROR; }else{ rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr); diff --git a/src/where.c b/src/where.c index f55d3b89d7..d7ddc4ceb9 100644 --- a/src/where.c +++ b/src/where.c @@ -16,7 +16,7 @@ ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.255 2007/08/16 04:30:41 drh Exp $ +** $Id: where.c,v 1.256 2007/08/16 10:09:03 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -716,7 +716,8 @@ static void exprAnalyze( int nPattern; int isComplete; int op; - sqlite3 *db = pWC->pParse->db; + Parse *pParse = pWC->pParse; + sqlite3 *db = pParse->db; if( db->mallocFailed ) return; prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); @@ -2152,24 +2153,24 @@ WhereInfo *sqlite3WhereBegin( if( pParse->explain==2 ){ char *zMsg; struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom]; - zMsg = sqlite3MPrintf("TABLE %s", pItem->zName); + zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName); if( pItem->zAlias ){ - zMsg = sqlite3MPrintf("%z AS %s", zMsg, pItem->zAlias); + zMsg = sqlite3MPrintf(db, "%z AS %s", zMsg, pItem->zAlias); } if( (pIx = pLevel->pIdx)!=0 ){ - zMsg = sqlite3MPrintf("%z WITH INDEX %s", zMsg, pIx->zName); + zMsg = sqlite3MPrintf(db, "%z WITH INDEX %s", zMsg, pIx->zName); }else if( pLevel->flags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){ - zMsg = sqlite3MPrintf("%z USING PRIMARY KEY", zMsg); + zMsg = sqlite3MPrintf(db, "%z USING PRIMARY KEY", zMsg); } #ifndef SQLITE_OMIT_VIRTUALTABLE else if( pLevel->pBestIdx ){ sqlite3_index_info *pBestIdx = pLevel->pBestIdx; - zMsg = sqlite3MPrintf("%z VIRTUAL TABLE INDEX %d:%s", zMsg, + zMsg = sqlite3MPrintf(db, "%z VIRTUAL TABLE INDEX %d:%s", zMsg, pBestIdx->idxNum, pBestIdx->idxStr); } #endif if( pLevel->flags & WHERE_ORDERBY ){ - zMsg = sqlite3MPrintf("%z ORDER BY", zMsg); + zMsg = sqlite3MPrintf(db, "%z ORDER BY", zMsg); } sqlite3VdbeOp3(v, OP_Explain, i, pLevel->iFrom, zMsg, P3_DYNAMIC); }