diff --git a/manifest b/manifest index 2b2ffdf299..7c0220eb71 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\stesting\sof\sthe\smin/max\soptimization.\s(CVS\s5373) -D 2008-07-08T18:05:26 +C Completely\srework\sthe\ssqlite3SetString()\sprimitive\sso\sthat\sit\shonors\sthe\nSQLITE_LIMIT_LENGTH\sand\savoids\sthe\suse\sof\sstrlen().\s(CVS\s5374) +D 2008-07-08T19:34:07 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 325dfac0a0dd1cb4d975f1ace6453157892e6042 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -95,10 +95,10 @@ F src/attach.c b18ba42c77f7d3941f5d23d2ca20fa1d841a4e91 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627 F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2 -F src/btree.c 965da6ca8bbd51677db5587471a5b0ef08f49786 +F src/btree.c a52b0a1d0459e3a028a90df84a84ec1c58148574 F src/btree.h b1bd7e0b8c2e33658aaf447cb0d1d94f74664b6b -F src/btreeInt.h 02325f04758dba0fcd0c08ac55cd9b189dad61a5 -F src/build.c 142ceacdc14e479f337aeb01db631f22683496f8 +F src/btreeInt.h 8f6e0817365ac822da0afffedc664ba03047718b +F src/build.c f6a74df6d888a00ac91cec332d41f2292a002767 F src/callback.c aa492a0ad8c2d454edff9fb8a57fae13743cf71d F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c F src/date.c e841168e5520bbbb2a1cbcdce7531d8b23017b4d @@ -110,12 +110,12 @@ F src/global.c f12dc84d23f52d2ed42d1bdb5460fa3caf63e890 F src/hash.c eb64e48f3781100e5934f759fbe72a63a8fe78cb F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53 F src/hwtime.h 745961687a65ef8918cd551c02e5ccb4b8e772de -F src/insert.c 9af927a81fdc99624130dc83722b3ab6364035a6 +F src/insert.c 6203674c043a25ef2064743ca2c5553f5b58ccd9 F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c 3626c71fb70912abec9a4312beba753a9ce800df F src/loadext.c ae0eed9fa96d74172d2a90ee63b5bc36d284295c -F src/main.c 7f69c952cf2a95f21439cd260224d5341b705596 -F src/malloc.c f52166df8abd7ff6990dbee1a0ce3534addc8617 +F src/main.c 47b781b6752eef3ee36ed8269b6f0d48625e82a8 +F src/malloc.c 226a532e9e371d1bb3de2553bdd1f9b600ef099c F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a F src/mem1.c 8340fa5f969e9f9b9bdeb54106457a2003456d2b F src/mem2.c 23f9538f35fbcd5665afe7056a56be0c7ed65aa7 @@ -137,14 +137,14 @@ F src/pager.c 2cd554d474cfa0228ece30645fe7bb7d1f6824c7 F src/pager.h 6aa3050a3c684475a5a9dbad5ff1cebad612acba F src/parse.y 8c2c3145eebe1964eb279cb3c4e502eae28bb0fa F src/pragma.c 6fad83fbcc7ec6e76d91fe2805fe972ff3af6a0c -F src/prepare.c aba51dad52308e3d9d2074d8ff4e612e7f1cab51 -F src/printf.c 8b063da9dcde26b7c500a01444b718d86f21bc6e +F src/prepare.c c9bb0aacb7a571d049805699ed18f2bb136ea091 +F src/printf.c 0e4bd1413226e8aaeadec251ffcee93448400417 F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a -F src/select.c 46997b3399166b3c4b0d8db25c35ca099c277a50 +F src/select.c 5ff8bc0ec204d02fb9d61ce59d5efc80680b8897 F src/shell.c 484e7297e066f22830f9c15d7abbcdd2acb097b0 F src/sqlite.h.in 22c32cedf7e435d5b3bb8564ce0a640c40dbbfb1 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e -F src/sqliteInt.h 46e40a482ae3b93a3c26eaf6a82ea6502653d474 +F src/sqliteInt.h 5add05d6e2369503673c8795d684e366e8e14402 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8 F src/status.c 6cb10377992505bd69f1ca1d75c1240a65f25a58 F src/table.c 1fa8f8113ac9cbc09ae4801c6d2a7f0af82c5822 @@ -175,17 +175,17 @@ F src/test_schema.c 4b4bf7bb329326458c491b0e6facd4c8c4c5b479 F src/test_server.c f0a403b5f699c09bd2b1236b6f69830fd6221f6b F src/test_tclvar.c 73530070df8378571c8ce6bbbbb993236ae3ad0b F src/test_thread.c e297dd41db0b249646e69f97d36ec13e56e8b730 -F src/tokenize.c 36484c7774914b7e307800a9bfde6a6b2fcd5a57 +F src/tokenize.c b5fdc79fb7e00077b9c02af7a0da3b89c9f3398e F src/trigger.c 1e751f8d5ceeb328d26bf1ccfb2de50653670d49 F src/update.c 2d7143b9014e955509cc4f323f9a9584fb898f34 F src/utf.c 8d52f620a7153d90b058502124fe51d821fcdf57 F src/util.c e202291456d34f8e2cf1c0a6f7e2538a77587445 -F src/vacuum.c 14eb21b480924d87e791cd8ab6fb35ac563243ef -F src/vdbe.c fb6df1bd31a321647b4677f5d20716d8f7f71255 +F src/vacuum.c ef342828002debc97514617af3424aea8ef8522c +F src/vdbe.c 4b3c7d0c7f68ec241bebe075c26a46a1618a32cb F src/vdbe.h c46155c221418bea29ee3a749d5950fcf85a70e2 F src/vdbeInt.h 30535c1d30ba1b5fb58d8f0e1d1261af976558aa F src/vdbeapi.c a7c6b8db324cf7eccff32de871dea36aa305c994 -F src/vdbeaux.c 3f41742bf0588e68e48b32e5cb74cb5f19a8fe45 +F src/vdbeaux.c c037e3279ccef6c960ff1c529c7ab2a7431dc451 F src/vdbeblob.c 9345f6dcd675fdcfdb537d2d2f487542d9ea136a F src/vdbefifo.c c46dae1194e4277bf007144d7e5b0c0b1c24f136 F src/vdbemem.c ee1a032b44ab59bd83a064544a0895003eecaec1 @@ -600,7 +600,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 6c2adade34fdbe344cf73f6bac951e0c37dd003b -R f6042400124ac27240401c0ca180db80 +P fa07c360b708324c47c8e9931f1e2b1b24e4faf8 +R 161d27aeeb9c9182a2b10e68914e4114 U drh -Z fc19ef422ff146e4058b15fdc6559cae +Z 86cd29ba184c9dc2fd2c0974fe85e5ce diff --git a/manifest.uuid b/manifest.uuid index d6428cc831..eda69cd7ab 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fa07c360b708324c47c8e9931f1e2b1b24e4faf8 \ No newline at end of file +8ed04b1e26a55306e4baf3e93fb084514134d603 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index fa18163723..23df64f0d3 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.472 2008/07/08 17:13:59 danielk1977 Exp $ +** $Id: btree.c,v 1.473 2008/07/08 19:34:07 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -6401,23 +6401,18 @@ static void checkAppendMsg( ... ){ va_list ap; - char *zMsg2; if( !pCheck->mxErr ) return; pCheck->mxErr--; pCheck->nErr++; va_start(ap, zFormat); - zMsg2 = sqlite3VMPrintf(0, zFormat, ap); - va_end(ap); - if( zMsg1==0 ) zMsg1 = ""; - if( pCheck->zErrMsg ){ - char *zOld = pCheck->zErrMsg; - pCheck->zErrMsg = 0; - sqlite3SetString(&pCheck->zErrMsg, zOld, "\n", zMsg1, zMsg2, (char*)0); - sqlite3_free(zOld); - }else{ - sqlite3SetString(&pCheck->zErrMsg, zMsg1, zMsg2, (char*)0); + if( pCheck->errMsg.nChar ){ + sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1); } - sqlite3_free(zMsg2); + if( zMsg1 ){ + sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1); + } + sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); + va_end(ap); } #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ @@ -6733,6 +6728,7 @@ char *sqlite3BtreeIntegrityCheck( int nRef; IntegrityCk sCheck; BtShared *pBt = p->pBt; + char zErr[100]; sqlite3BtreeEnter(p); pBt->db = p->db; @@ -6770,7 +6766,7 @@ char *sqlite3BtreeIntegrityCheck( if( i<=sCheck.nPage ){ sCheck.anRef[i] = 1; } - sCheck.zErrMsg = 0; + sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000); /* Check the integrity of the freelist */ @@ -6826,7 +6822,8 @@ char *sqlite3BtreeIntegrityCheck( sqlite3BtreeLeave(p); sqlite3_free(sCheck.anRef); *pnErr = sCheck.nErr; - return sCheck.zErrMsg; + if( sCheck.nErr==0 ) sqlite3StrAccumReset(&sCheck.errMsg); + return sqlite3StrAccumFinish(&sCheck.errMsg); } #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ diff --git a/src/btreeInt.h b/src/btreeInt.h index f5783fa242..1bb5c6bf5b 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btreeInt.h,v 1.22 2008/06/15 02:51:47 drh Exp $ +** $Id: btreeInt.h,v 1.23 2008/07/08 19:34:07 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -612,8 +612,8 @@ struct IntegrityCk { int nPage; /* Number of pages in the database */ int *anRef; /* Number of times each page is referenced */ int mxErr; /* Stop accumulating errors when this reaches zero */ - char *zErrMsg; /* An error message. NULL if no errors seen. */ int nErr; /* Number of messages written to zErrMsg so far */ + StrAccum errMsg; /* Accumulate the error message text here */ }; /* diff --git a/src/build.c b/src/build.c index 30037e3fa6..1cff08b1fe 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.487 2008/07/08 14:52:08 drh Exp $ +** $Id: build.c,v 1.488 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" #include @@ -2458,15 +2458,11 @@ void sqlite3CreateIndex( goto exit_create_index; } }else{ - char zBuf[30]; int n; Index *pLoop; for(pLoop=pTab->pIndex, n=1; pLoop; pLoop=pLoop->pNext, n++){} - sqlite3_snprintf(sizeof(zBuf),zBuf,"_%d",n); - zName = 0; - sqlite3SetString(&zName, "sqlite_autoindex_", pTab->zName, zBuf, (char*)0); + zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n); if( zName==0 ){ - db->mallocFailed = 1; goto exit_create_index; } } diff --git a/src/insert.c b/src/insert.c index afb391473f..bada466542 100644 --- a/src/insert.c +++ b/src/insert.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle INSERT statements in SQLite. ** -** $Id: insert.c,v 1.244 2008/07/04 10:56:08 danielk1977 Exp $ +** $Id: insert.c,v 1.245 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" @@ -1130,10 +1130,10 @@ void sqlite3GenerateConstraintChecks( case OE_Rollback: case OE_Abort: case OE_Fail: { - char *zMsg = 0; + char *zMsg; sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_CONSTRAINT, onError); - sqlite3SetString(&zMsg, pTab->zName, ".", pTab->aCol[i].zName, - " may not be NULL", (char*)0); + zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL", + pTab->zName, pTab->aCol[i].zName); sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); break; } diff --git a/src/main.c b/src/main.c index 74e8aa90c7..2f31aa535e 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.471 2008/07/08 14:52:10 drh Exp $ +** $Id: main.c,v 1.472 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" #include @@ -1737,8 +1737,9 @@ error_out: if( pAutoinc ) *pAutoinc = autoinc; if( SQLITE_OK==rc && !pTab ){ - sqlite3SetString(&zErrMsg, "no such table column: ", zTableName, ".", - zColumnName, 0); + sqlite3_free(zErrMsg); + zErrMsg = sqlite3MPrintf("no such table column: %s.%s", zTableName, + zColumnName); rc = SQLITE_ERROR; } sqlite3Error(db, rc, (zErrMsg?"%s":0), zErrMsg); diff --git a/src/malloc.c b/src/malloc.c index 36f0faefe7..351a38ce37 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ ** ** Memory allocation functions used throughout sqlite. ** -** $Id: malloc.c,v 1.25 2008/06/23 14:03:45 danielk1977 Exp $ +** $Id: malloc.c,v 1.26 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" #include @@ -631,39 +631,19 @@ char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){ } /* -** Create a string from the 2nd and subsequent arguments (up to the -** first NULL argument), store the string in memory obtained from -** sqliteMalloc() and make the pointer indicated by the 1st argument -** point to that string. The 1st argument must either be NULL or -** point to memory obtained from sqliteMalloc(). +** Create a string from the zFromat argument and the va_list that follows. +** Store the string in memory obtained from sqliteMalloc() and make *pz +** point to that string. */ -void sqlite3SetString(char **pz, ...){ +void sqlite3SetString(char **pz, sqlite3 *db, const char *zFormat, ...){ va_list ap; - int nByte; - const char *z; - char *zResult; + char *z; - assert( pz!=0 ); - nByte = 1; - va_start(ap, pz); - while( (z = va_arg(ap, const char*))!=0 ){ - nByte += strlen(z); - } + va_start(ap, zFormat); + z = sqlite3VMPrintf(db, zFormat, ap); va_end(ap); sqlite3_free(*pz); - *pz = zResult = sqlite3Malloc(nByte); - if( zResult==0 ){ - return; - } - *zResult = 0; - va_start(ap, pz); - while( (z = va_arg(ap, const char*))!=0 ){ - int n = strlen(z); - memcpy(zResult, z, n); - zResult += n; - } - zResult[0] = 0; - va_end(ap); + *pz = z; } diff --git a/src/prepare.c b/src/prepare.c index ec2e1c07e1..6d984f1ad2 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.88 2008/06/23 16:53:47 danielk1977 Exp $ +** $Id: prepare.c,v 1.89 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" #include @@ -29,8 +29,12 @@ static void corruptSchema( ){ if( !pData->db->mallocFailed ){ if( zObj==0 ) zObj = "?"; - sqlite3SetString(pData->pzErrMsg, "malformed database schema (", zObj, ")", - zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0); + sqlite3SetString(pData->pzErrMsg, pData->db, + "malformed database schema (%s)", zObj); + if( zExtra && zExtra[0] ){ + *pData->pzErrMsg = sqlite3MPrintf(pData->db, "%z - %s", + *pData->pzErrMsg, zExtra); + } } pData->rc = SQLITE_CORRUPT; } @@ -215,7 +219,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ sqlite3BtreeEnter(pDb->pBt); rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, curMain); if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){ - sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0); + sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc)); goto leave_error_out; } @@ -242,7 +246,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]); } if( rc ){ - sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0); + sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc)); goto leave_error_out; } }else{ @@ -263,8 +267,8 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ }else{ /* If opening an attached database, the encoding much match ENC(db) */ if( meta[4]!=ENC(db) ){ - sqlite3SetString(pzErrMsg, "attached databases must use the same" - " text encoding as main database", (char*)0); + sqlite3SetString(pzErrMsg, db, "attached databases must use the same" + " text encoding as main database"); rc = SQLITE_ERROR; goto leave_error_out; } @@ -293,7 +297,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ pDb->pSchema->file_format = 1; } if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){ - sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0); + sqlite3SetString(pzErrMsg, db, "unsupported file format"); rc = SQLITE_ERROR; goto leave_error_out; } @@ -340,7 +344,6 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ #endif } if( db->mallocFailed ){ - /* sqlite3SetString(pzErrMsg, "out of memory", (char*)0); */ rc = SQLITE_NOMEM; sqlite3ResetInternalSchema(db, 0); } diff --git a/src/printf.c b/src/printf.c index dc8d711059..5a75fca225 100644 --- a/src/printf.c +++ b/src/printf.c @@ -5,7 +5,7 @@ ** an historical reference. Most of the "enhancements" have been backed ** out so that the functionality is now the same as standard printf(). ** -** $Id: printf.c,v 1.87 2008/06/16 20:51:16 drh Exp $ +** $Id: printf.c,v 1.88 2008/07/08 19:34:07 drh Exp $ ** ************************************************************************** ** @@ -221,7 +221,7 @@ static void appendSpace(StrAccum *pAccum, int N){ ** seems to make a big difference in determining how fast this beast ** will run. */ -static void vxprintf( +void sqlite3VXPrintf( StrAccum *pAccum, /* Accumulate results here */ int useExtended, /* Allow extended %-conversions */ const char *fmt, /* Format string */ @@ -794,14 +794,14 @@ char *sqlite3StrAccumFinish(StrAccum *p){ void sqlite3StrAccumReset(StrAccum *p){ if( p->zText!=p->zBase ){ sqlite3_free(p->zText); - p->zText = 0; } + p->zText = 0; } /* ** Initialize a string accumulator */ -static void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){ +void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){ p->zText = p->zBase = zBase; p->nChar = 0; p->nAlloc = n; @@ -821,7 +821,7 @@ char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ StrAccum acc; sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), db ? db->aLimit[SQLITE_LIMIT_LENGTH] : SQLITE_MAX_LENGTH); - vxprintf(&acc, 1, zFormat, ap); + sqlite3VXPrintf(&acc, 1, zFormat, ap); z = sqlite3StrAccumFinish(&acc); if( acc.mallocFailed && db ){ db->mallocFailed = 1; @@ -852,7 +852,7 @@ char *sqlite3_vmprintf(const char *zFormat, va_list ap){ StrAccum acc; sqlite3_initialize(); sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH); - vxprintf(&acc, 0, zFormat, ap); + sqlite3VXPrintf(&acc, 0, zFormat, ap); z = sqlite3StrAccumFinish(&acc); return z; } @@ -888,7 +888,7 @@ char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ sqlite3StrAccumInit(&acc, zBuf, n, 0); acc.useMalloc = 0; va_start(ap,zFormat); - vxprintf(&acc, 0, zFormat, ap); + sqlite3VXPrintf(&acc, 0, zFormat, ap); va_end(ap); z = sqlite3StrAccumFinish(&acc); return z; @@ -907,7 +907,7 @@ void sqlite3DebugPrintf(const char *zFormat, ...){ sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0); acc.useMalloc = 0; va_start(ap,zFormat); - vxprintf(&acc, 0, zFormat, ap); + sqlite3VXPrintf(&acc, 0, zFormat, ap); va_end(ap); sqlite3StrAccumFinish(&acc); fprintf(stdout,"%s", zBuf); diff --git a/src/select.c b/src/select.c index 6effc49d54..f7c5780adb 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.449 2008/07/08 18:05:26 drh Exp $ +** $Id: select.c,v 1.450 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" @@ -1111,7 +1111,7 @@ static void generateColumnNames( zTab = pTabList->a[j].zAlias; if( fullNames || zTab==0 ) zTab = pTab->zName; - sqlite3SetString(&zName, zTab, ".", zCol, (char*)0); + zName = sqlite3MPrintf(db, "%s.%s", zTab, zCol); sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, P4_DYNAMIC); }else{ sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, strlen(zCol)); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 7be67939bd..e56f6f5143 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.735 2008/07/08 14:52:10 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.736 2008/07/08 19:34:07 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -1826,6 +1826,7 @@ void sqlite3StatusSet(int, int); int sqlite3IsNaN(double); +void sqlite3VXPrintf(StrAccum*, int, const char*, va_list); char *sqlite3MPrintf(sqlite3*,const char*, ...); char *sqlite3VMPrintf(sqlite3*,const char*, va_list); #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) @@ -1834,7 +1835,7 @@ char *sqlite3VMPrintf(sqlite3*,const char*, va_list); #if defined(SQLITE_TEST) void *sqlite3TextToPtr(const char*); #endif -void sqlite3SetString(char **, ...); +void sqlite3SetString(char **, sqlite3*, const char*, ...); void sqlite3ErrorMsg(Parse*, const char*, ...); void sqlite3ErrorClear(Parse*); void sqlite3Dequote(char*); @@ -2146,6 +2147,7 @@ int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, int sqlite3ApiExit(sqlite3 *db, int); int sqlite3OpenTempDatabase(Parse *); +void sqlite3StrAccumInit(StrAccum*, char*, int, int); void sqlite3StrAccumAppend(StrAccum*,const char*,int); char *sqlite3StrAccumFinish(StrAccum*); void sqlite3StrAccumReset(StrAccum*); diff --git a/src/tokenize.c b/src/tokenize.c index 05622dae12..c7769f97f7 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.145 2008/07/08 00:06:50 drh Exp $ +** $Id: tokenize.c,v 1.146 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" #include @@ -421,7 +421,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ case TK_COMMENT: { if( db->u1.isInterrupted ){ pParse->rc = SQLITE_INTERRUPT; - sqlite3SetString(pzErrMsg, "interrupt", (char*)0); + sqlite3SetString(pzErrMsg, db, "interrupt"); goto abort_parse; } break; @@ -460,7 +460,7 @@ abort_parse: pParse->rc = SQLITE_NOMEM; } if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){ - sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc), (char*)0); + sqlite3SetString(&pParse->zErrMsg, db, "%s", sqlite3ErrStr(pParse->rc)); } if( pParse->zErrMsg ){ if( *pzErrMsg==0 ){ diff --git a/src/vacuum.c b/src/vacuum.c index 89e9a28039..45bc61e214 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -14,7 +14,7 @@ ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** -** $Id: vacuum.c,v 1.80 2008/06/17 01:03:26 drh Exp $ +** $Id: vacuum.c,v 1.81 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" @@ -96,8 +96,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks; if( !db->autoCommit ){ - sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction", - (char*)0); + sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction"); rc = SQLITE_ERROR; goto end_of_vacuum; } diff --git a/src/vdbe.c b/src/vdbe.c index 255ce71c7b..69bf418657 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.758 2008/07/07 17:13:09 danielk1977 Exp $ +** $Id: vdbe.c,v 1.759 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" #include @@ -830,7 +830,7 @@ case OP_Halt: { p->pc = pc; p->errorAction = pOp->p2; if( pOp->p4.z ){ - sqlite3SetString(&p->zErrMsg, pOp->p4.z, (char*)0); + sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); } rc = sqlite3VdbeHalt(p); assert( rc==SQLITE_BUSY || rc==SQLITE_OK ); @@ -1361,7 +1361,7 @@ case OP_Function: { /* If the function returned an error, throw an exception */ if( ctx.isError ){ - sqlite3SetString(&p->zErrMsg, sqlite3_value_text(&ctx.s), (char*)0); + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s)); rc = ctx.isError; } @@ -2447,8 +2447,9 @@ case OP_AutoCommit: { ** still running, and a transaction is active, return an error indicating ** that the other VMs must complete first. */ - sqlite3SetString(&p->zErrMsg, "cannot ", rollback?"rollback":"commit", - " transaction - SQL statements in progress", (char*)0); + sqlite3SetString(&p->zErrMsg, db, "cannot %s transaction - " + "SQL statements in progress", + rollback ? "rollback" : "commit"); rc = SQLITE_ERROR; }else if( i!=db->autoCommit ){ if( pOp->p2 ){ @@ -2471,10 +2472,10 @@ case OP_AutoCommit: { } goto vdbe_return; }else{ - sqlite3SetString(&p->zErrMsg, + sqlite3SetString(&p->zErrMsg, db, (!i)?"cannot start a transaction within a transaction":( (rollback)?"cannot rollback - no transaction is active": - "cannot commit - no transaction is active"), (char*)0); + "cannot commit - no transaction is active")); rc = SQLITE_ERROR; } @@ -4473,7 +4474,7 @@ case OP_AggStep: { } (ctx.pFunc->xStep)(&ctx, n, apVal); if( ctx.isError ){ - sqlite3SetString(&p->zErrMsg, sqlite3_value_text(&ctx.s), (char*)0); + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s)); rc = ctx.isError; } sqlite3VdbeMemRelease(&ctx.s); @@ -4499,7 +4500,7 @@ case OP_AggFinal: { assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc); if( rc==SQLITE_ERROR ){ - sqlite3SetString(&p->zErrMsg, sqlite3_value_text(pMem), (char*)0); + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem)); } sqlite3VdbeChangeEncoding(pMem, encoding); UPDATE_MAX_BLOBSIZE(pMem); @@ -4589,7 +4590,7 @@ case OP_TableLock: { rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock); if( rc==SQLITE_LOCKED ){ const char *z = pOp->p4.z; - sqlite3SetString(&p->zErrMsg, "database table is locked: ", z, (char*)0); + sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z); } break; } @@ -4912,7 +4913,7 @@ case OP_VUpdate: { int nArg = pOp->p2; assert( pOp->p4type==P4_VTAB ); if( pModule->xUpdate==0 ){ - sqlite3SetString(&p->zErrMsg, "read-only table", 0); + sqlite3SetString(&p->zErrMsg, db, "read-only table"); rc = SQLITE_ERROR; }else{ int i; @@ -5058,7 +5059,7 @@ vdbe_return: ** is encountered. */ too_big: - sqlite3SetString(&p->zErrMsg, "string or blob too big", (char*)0); + sqlite3SetString(&p->zErrMsg, db, "string or blob too big"); rc = SQLITE_TOOBIG; goto vdbe_error_halt; @@ -5066,7 +5067,7 @@ too_big: */ no_mem: db->mallocFailed = 1; - sqlite3SetString(&p->zErrMsg, "out of memory", (char*)0); + sqlite3SetString(&p->zErrMsg, db, "out of memory"); rc = SQLITE_NOMEM; goto vdbe_error_halt; @@ -5083,7 +5084,7 @@ abort_due_to_error: assert( p->zErrMsg==0 ); if( db->mallocFailed ) rc = SQLITE_NOMEM; if( rc!=SQLITE_IOERR_NOMEM ){ - sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(rc), (char*)0); + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc)); } goto vdbe_error_halt; @@ -5094,6 +5095,6 @@ abort_due_to_interrupt: assert( db->u1.isInterrupted ); rc = SQLITE_INTERRUPT; p->rc = rc; - sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(rc), (char*)0); + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc)); goto vdbe_error_halt; } diff --git a/src/vdbeaux.c b/src/vdbeaux.c index e2b235bc09..0a7dc6e6f8 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -14,7 +14,7 @@ ** to version 2.8.7, all this code was combined into the vdbe.c source file. ** But that file was getting too big so this subroutines were split out. ** -** $Id: vdbeaux.c,v 1.393 2008/06/25 00:12:42 drh Exp $ +** $Id: vdbeaux.c,v 1.394 2008/07/08 19:34:07 drh Exp $ */ #include "sqliteInt.h" #include @@ -832,7 +832,7 @@ int sqlite3VdbeList( }else if( db->u1.isInterrupted ){ p->rc = SQLITE_INTERRUPT; rc = SQLITE_ERROR; - sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(p->rc), (char*)0); + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(p->rc)); }else{ char *z; Op *pOp = &p->aOp[i]; @@ -1632,7 +1632,8 @@ int sqlite3VdbeHalt(Vdbe *p){ rc = xFunc(pBt); if( rc && (p->rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT) ){ p->rc = rc; - sqlite3SetString(&p->zErrMsg, 0); + sqlite3_free(p->zErrMsg); + p->zErrMsg = 0; } } }