diff --git a/manifest b/manifest index 11065ada70..4078050015 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C New\sFTS1\stest\sdata\sbased\son\senron\semails.\s(CVS\s3421) -D 2006-09-14T21:08:55 +C Add\ssupport\sfor\sextended\sresult\scodes\s-\sadditional\sresult\sinformation\ncarried\sin\sthe\shigher\sbits\sof\sthe\sinteger\sreturn\scodes.\s\sThis\smust\sbe\nenabled\susing\sthe\ssqlite3_extended_result_code()\sAPI.\s\sOnly\sa\sfew\sextra\nresult\scodes\sare\scurrently\sdefined.\s(CVS\s3422) +D 2006-09-15T07:28:50 F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -61,9 +61,9 @@ F src/func.c dd9cea8ed3246d7a4c49fd01034d470d5702b8b0 F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564 F src/insert.c e9526ced19978a55687b55faea969b6ff2a53fb4 -F src/legacy.c 10e01a902d7f2c872c7922fedf19a2df70935857 -F src/loadext.c 7a41142266dd2570fedf00108e1772047f98a673 -F src/main.c f780d73b3093807bd177d21af703665b3b15a452 +F src/legacy.c 2631df6a861f830d6b1c0fe92b9fdd745b2c0cd6 +F src/loadext.c 5ffbf47d9ed168507e38ab7d09b1827ea3c9ca6d +F src/main.c e284169854d429cc6550a22b8b136ca70164ce5b F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/os.c 59f05de8c5777c34876607114a2fbe55ae578235 F src/os.h 3fd6a022bafd620fdfd779a51dccb42f31c97f75 @@ -72,26 +72,26 @@ F src/os_os2.c 361964755f361b5ba879549c201284ce61ee9431 F src/os_os2.h e5f17dd69333632bbc3112881ea407c37d245eb3 F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3 -F src/os_unix.c 4a99fca111a7189b095d09301b950e323fede937 +F src/os_unix.c 3ed7fd1639c052d1df167321917a39ba738c46c9 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c a66763099e093785bee7e8cff3baef01868b2e73 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c e51c079b3cad8394898a6c22330150339103700a +F src/pager.c 65bb33144cad89f9a52054ec884e0fd5f4b0849b F src/pager.h 0cff9de5e9019cb695a04d18df8caaaff933a272 F src/parse.y 3279443a2b8173230dd27b9821373b681bb1f3c8 F src/pragma.c dcb79b8170231f3aed99d4004b4d0a0fc14c4b4d -F src/prepare.c 84e2c855600c7bfbe2ca691b263301de525f9123 +F src/prepare.c bc003436a4897b8f30b940e023a70297e860f805 F src/printf.c b179b6ed12f793e028dd169e2e2e2b2a37eedc63 F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261 F src/select.c 0d4724930a1f34c747105ed1802fa4af0d8eb519 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/shell.c 672326e8d90394218509f1820ab0835e7ed2bc06 -F src/sqlite.h.in 19f5390cce182242b309a053aa1ee2b902bee147 +F src/sqlite.h.in 0d1b16b059bfcd286779ef40dd567f1e642f0df5 F src/sqlite3ext.h 11a046b3519c4b9b7709e6d6a95c3a36366f684a -F src/sqliteInt.h fc2439b695dd80a3c58c8f14759e621dbf630b03 -F src/table.c d8817f43a6c6bf139487db161760b9e1e02da3f1 +F src/sqliteInt.h 74b39f55f30c3cff8935eb7adbd8842bca68331e +F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06 F src/tclsqlite.c e029f739bed90071789fe81a226d53e97a80a4d8 -F src/test1.c 9c77e6ac13fc7eb3a2fa2c9fe6b2230ee51c524b +F src/test1.c 47f1d62d90fbf131dc5bbcd1b1aa18791fa3bc79 F src/test2.c ca74a1d8aeb7d9606e8f6b762c5daf85c1a3f92b F src/test3.c 85135c09560c48bdb0a23c9b890ab405486b8ec9 F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25 @@ -110,16 +110,16 @@ F src/tokenize.c dfdff21768fbedd40e8d3ca84fc5d0d7af2b46dd F src/trigger.c 74ccec784683232f89f3b4db34a089d8cace2058 F src/update.c 951f95ef044cf6d28557c48dc35cb0711a0b9129 F src/utf.c 4459801e9b00cfd69993bfca58545d3775682d6e -F src/util.c 5409031819ee4672c5f9c3ac7cf517e267a25845 +F src/util.c 91d4cb189476906639ae611927d939691d1365f6 F src/vacuum.c fb65647c362589ed4ebb342c85665cadbcbf980c F src/vdbe.c a77869949ddd0afe01443611edb949e24e67c91c F src/vdbe.h 258b5d1c0aaa72192f09ff0568ce42b383f156fa F src/vdbeInt.h e3eaab262b67b84474625cfc38aec1125c32834b -F src/vdbeapi.c 81f531d7dc5c898131b02ef85f6c6144ab2892cf -F src/vdbeaux.c 736d6d07daf7a99f619697cf3bf5ae65643e12c9 +F src/vdbeapi.c d5d3cb0701b66e541059a53c8a32d034bc86b7f7 +F src/vdbeaux.c 7d15dcf0eab43b0f6b1bb840dc2a3126eb370f5b F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5 F src/vdbemem.c 26623176bf1c616aa478da958fac49502491a921 -F src/vtab.c 82d915c0a41546d47779c03c53ff884cec6c032e +F src/vtab.c 2582c4e4a939072608bd8b4557c46f4343759197 F src/where.c 75a89957fcb8c068bec55caa4e9d2ed5fa0b0724 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -192,7 +192,7 @@ F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce F test/format4.test bf3bed3b13c63abfb3cfec232597a319a31d0bcc F test/fts1a.test 54fd9451c00fb91074d5abdc207b05dcba6d2d65 F test/fts1b.test 5742c32c69ec9667c8d32df5bc79aa416d5f363a -F test/fts1c.test 653cf73bf12b2bd96a2322c7105330a02bf4663f +F test/fts1c.test 324895adf9855751f0ea7a6b735f8b7fcf28c3f8 F test/func.test 7f2c91a948a0a177635835dc9afa078413c54ae1 F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a F test/in.test 369cb2aa1eab02296b4ec470732fe8c131260b1d @@ -204,7 +204,7 @@ F test/insert2.test 5a20e1ace5fa0800b58d28284212290189b49aed F test/insert3.test 09a532d5b6f3a788d91be0d4d368462f522685d1 F test/interrupt.test c38b7f7c17914f0cd6a119beed5d03bc3f47f9eb F test/intpkey.test af4fd826c4784ec5c93b444de07adea0254d0d30 -F test/ioerr.test 804d56cfa698e7c90590921f984eb49ceb30c2a9 +F test/ioerr.test 6f67d9328a3909dc43b1f66864f7fbc7fd399812 F test/join.test af0443185378b64878750aa1cf4b83c216f246b4 F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 @@ -275,7 +275,7 @@ F test/table.test feea6a3eb08cf166f570255eea5447e42ef82498 F test/tableapi.test a1982276274d292110d549206bc365b2da43e2ee F test/tclsqlite.test 51334389283c74bcbe28645a73159b17e239e9f3 F test/temptable.test c36f3e5a94507abb64f7ba23deeb4e1a8a8c3821 -F test/tester.tcl ddb510a86b1d50ef3a97bde94df13185422c0616 +F test/tester.tcl d5c5389036769acf24636965cabab90fe42020f4 F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35 F test/thread2.test 6d7b30102d600f51b4055ee3a5a19228799049fb F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b @@ -399,7 +399,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 373a575f745dc2002090328f30539bbfef3119d5 -R 72387d13baea83dd775b1ba37f717ce1 +P 01651a32c6e67c4ac2cd23f1da7f3cc3adad1b33 +R 245c2c9e4179a89b58543a7e5cb6292b U drh -Z 84e9bd49c14301b0acf5fa8e0f7c865a +Z dc51ea3ae28793482c78f8fbf55dff83 diff --git a/manifest.uuid b/manifest.uuid index f6ba93d9ed..eccf5f6cd7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -01651a32c6e67c4ac2cd23f1da7f3cc3adad1b33 \ No newline at end of file +ba579ddc4361fc6e8ea66f9385770d70dfe94751 \ No newline at end of file diff --git a/src/legacy.c b/src/legacy.c index 39e1361fac..a74ad4f159 100644 --- a/src/legacy.c +++ b/src/legacy.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: legacy.c,v 1.15 2006/06/26 21:35:45 drh Exp $ +** $Id: legacy.c,v 1.16 2006/09/15 07:28:50 drh Exp $ */ #include "sqliteInt.h" @@ -131,5 +131,6 @@ exec_out: *pzErrMsg = 0; } + assert( (rc&db->errMask)==rc ); return rc; } diff --git a/src/loadext.c b/src/loadext.c index 81f6856d52..80cfc4cccd 100644 --- a/src/loadext.c +++ b/src/loadext.c @@ -385,7 +385,8 @@ int sqlite3_auto_extension(void *xInit){ aAutoExtension[nAutoExtension-1] = xInit; } } - sqlite3OsLeaveMutex(); + sqlite3OsLeaveMutex(); + assert( (rc&0xff)==rc ); return rc; } diff --git a/src/main.c b/src/main.c index b7e2cf16d5..476577f118 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.356 2006/09/02 13:58:07 drh Exp $ +** $Id: main.c,v 1.357 2006/09/15 07:28:50 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -223,7 +223,7 @@ void sqlite3RollbackAll(sqlite3 *db){ */ const char *sqlite3ErrStr(int rc){ const char *z; - switch( rc ){ + switch( rc & 0xff ){ case SQLITE_ROW: case SQLITE_DONE: case SQLITE_OK: z = "not an error"; break; @@ -763,7 +763,7 @@ int sqlite3_errcode(sqlite3 *db){ if( sqlite3SafetyCheck(db) ){ return SQLITE_MISUSE; } - return db->errCode; + return db->errCode & db->errMask; } /* @@ -841,6 +841,7 @@ static int openDatabase( /* Allocate the sqlite data structure */ db = sqliteMalloc( sizeof(sqlite3) ); if( db==0 ) goto opendb_out; + db->errMask = 0xff; db->priorNewRowid = 0; db->magic = SQLITE_MAGIC_BUSY; db->nDb = 2; @@ -1011,6 +1012,7 @@ int sqlite3_reset(sqlite3_stmt *pStmt){ }else{ rc = sqlite3VdbeReset((Vdbe*)pStmt); sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0, 0, 0); + assert( (rc & (sqlite3_db_handle(pStmt)->errMask))==rc ); } return rc; } @@ -1297,3 +1299,11 @@ int sqlite3_clear_bindings(sqlite3_stmt *pStmt){ int sqlite3_sleep(int ms){ return sqlite3OsSleep(ms); } + +/* +** Enable or disable the extended result codes. +*/ +int sqlite3_extended_result_codes(sqlite3 *db, int onoff){ + db->errMask = onoff ? 0xffffffff : 0xff; + return SQLITE_OK; +} diff --git a/src/os_unix.c b/src/os_unix.c index ed810d6df2..ada697463c 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -937,8 +937,10 @@ static int unixRead(OsFile *id, void *pBuf, int amt){ SimulateIOError( got=0 ); if( got==amt ){ return SQLITE_OK; + }else if( got<0 ){ + return SQLITE_IOERR_READ; }else{ - return SQLITE_IOERR; + return SQLITE_IOERR_SHORT_READ; } } @@ -982,7 +984,7 @@ static int unixWrite(OsFile *id, const void *pBuf, int amt){ SimulateDiskfullError(( wrote=0, amt=1 )); if( amt>0 ){ if( wrote<0 ){ - return SQLITE_IOERR; + return SQLITE_IOERR_WRITE; }else{ return SQLITE_FULL; } @@ -1065,19 +1067,13 @@ static int full_fsync(int fd, int fullSync, int dataOnly){ #if HAVE_FULLFSYNC if( fullSync ){ rc = fcntl(fd, F_FULLFSYNC, 0); - }else{ - rc = 1; - } - /* If the FULLSYNC failed, try to do a normal fsync() */ - if( rc ) rc = fsync(fd); - -#else /* if !defined(F_FULLSYNC) */ + }else +#endif /* HAVE_FULLFSYNC */ if( dataOnly ){ rc = fdatasync(fd); }else{ rc = fsync(fd); } -#endif /* defined(F_FULLFSYNC) */ #endif /* defined(SQLITE_NO_SYNC) */ return rc; @@ -1106,7 +1102,7 @@ static int unixSync(OsFile *id, int dataOnly){ rc = full_fsync(pFile->h, pFile->fullSync, dataOnly); SimulateIOError( rc=1 ); if( rc ){ - return SQLITE_IOERR; + return SQLITE_IOERR_FSYNC; } if( pFile->dirfd>=0 ){ TRACE4("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd, @@ -1155,7 +1151,7 @@ int sqlite3UnixSyncDirectory(const char *zDirname){ close(fd); SimulateIOError( r=1 ); if( r ){ - return SQLITE_IOERR; + return SQLITE_IOERR_DIR_FSYNC; }else{ return SQLITE_OK; } @@ -1171,7 +1167,7 @@ static int unixTruncate(OsFile *id, i64 nByte){ rc = ftruncate(((unixFile*)id)->h, nByte); SimulateIOError( rc=1 ); if( rc ){ - return SQLITE_IOERR; + return SQLITE_IOERR_TRUNCATE; }else{ return SQLITE_OK; } @@ -1187,7 +1183,7 @@ static int unixFileSize(OsFile *id, i64 *pSize){ rc = fstat(((unixFile*)id)->h, &buf); SimulateIOError( rc=1 ); if( rc!=0 ){ - return SQLITE_IOERR; + return SQLITE_IOERR_FSTAT; } *pSize = buf.st_size; return SQLITE_OK; @@ -1397,7 +1393,7 @@ static int unixLock(OsFile *id, int locktype){ lock.l_len = 1L; lock.l_type = F_UNLCK; if( fcntl(pFile->h, F_SETLK, &lock)!=0 ){ - rc = SQLITE_IOERR; /* This should never happen */ + rc = SQLITE_IOERR_UNLOCK; /* This should never happen */ goto end_lock; } if( s ){ @@ -1486,7 +1482,7 @@ static int unixUnlock(OsFile *id, int locktype){ lock.l_len = SHARED_SIZE; if( fcntl(pFile->h, F_SETLK, &lock)!=0 ){ /* This should never happen */ - rc = SQLITE_IOERR; + rc = SQLITE_IOERR_RDLOCK; } } lock.l_type = F_UNLCK; @@ -1496,7 +1492,7 @@ static int unixUnlock(OsFile *id, int locktype){ if( fcntl(pFile->h, F_SETLK, &lock)==0 ){ pLock->locktype = SHARED_LOCK; }else{ - rc = SQLITE_IOERR; /* This should never happen */ + rc = SQLITE_IOERR_UNLOCK; /* This should never happen */ } } if( locktype==NO_LOCK ){ @@ -1514,7 +1510,7 @@ static int unixUnlock(OsFile *id, int locktype){ if( fcntl(pFile->h, F_SETLK, &lock)==0 ){ pLock->locktype = NO_LOCK; }else{ - rc = SQLITE_IOERR; /* This should never happen */ + rc = SQLITE_IOERR_UNLOCK; /* This should never happen */ } } diff --git a/src/pager.c b/src/pager.c index 1013c1c2c3..e8923e06fc 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.271 2006/08/08 13:51:43 drh Exp $ +** @(#) $Id: pager.c,v 1.272 2006/09/15 07:28:50 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -476,12 +476,13 @@ static u32 retrieve32bits(PgHdr *p, int offset){ ** will immediately return the same error code. */ static int pager_error(Pager *pPager, int rc){ + int rc2 = rc & 0xff; assert( pPager->errCode==SQLITE_FULL || pPager->errCode==SQLITE_OK ); if( - rc==SQLITE_FULL || - rc==SQLITE_IOERR || - rc==SQLITE_CORRUPT || - rc==SQLITE_PROTOCOL + rc2==SQLITE_FULL || + rc2==SQLITE_IOERR || + rc2==SQLITE_CORRUPT || + rc2==SQLITE_PROTOCOL ){ pPager->errCode = rc; } @@ -2578,7 +2579,7 @@ int sqlite3pager_release_memory(int nReq){ ** The error will be returned to the user (or users, in the case ** of a shared pager cache) of the pager for which the error occured. */ - assert( rc==SQLITE_IOERR || rc==SQLITE_FULL ); + assert( (rc&0xff)==SQLITE_IOERR || rc==SQLITE_FULL ); assert( p->state>=PAGER_RESERVED ); pager_error(p, rc); } diff --git a/src/prepare.c b/src/prepare.c index b89059b85d..7e52c87871 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.38 2006/08/12 13:28:23 drh Exp $ +** $Id: prepare.c,v 1.39 2006/09/15 07:28:50 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -546,6 +546,7 @@ int sqlite3_prepare( rc = sqlite3ApiExit(db, rc); sqlite3ReleaseThreadData(); + assert( (rc&db->errMask)==rc ); return rc; } diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 2cd534b6dc..3028148840 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -12,7 +12,7 @@ ** This header file defines the interface that the SQLite library ** presents to client programs. ** -** @(#) $Id: sqlite.h.in,v 1.192 2006/09/11 00:34:22 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.193 2006/09/15 07:28:50 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -198,6 +198,44 @@ int sqlite3_exec( #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ /* end-of-error-codes */ +/* +** Using the sqlite3_extended_result_codes() API, you can cause +** SQLite to return result codes with additional information in +** their upper bits. The lower 8 bits will be the same as the +** primary result codes above. But the upper bits might contain +** more specific error information. +** +** To extract the primary result code from an extended result code, +** simply mask off the lower 8 bits. +** +** primary = extended & 0xff; +** +** New result error codes may be added from time to time. Software +** that uses the extended result codes should plan accordingly and be +** sure to always handle new unknown codes gracefully. +** +** The SQLITE_OK result code will never be extended. It will always +** be exactly zero. +** +** The extended result codes always have the primary result code +** as a prefix. Primary result codes only contain a single "_" +** character. Extended result codes contain two or more "_" characters. +*/ +#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) +#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) +#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) +#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) +#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) +#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) +#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) +#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) +#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) + +/* +** Enable or disable the extended result codes. +*/ +int sqlite3_extended_result_codes(sqlite3*, int onoff); + /* ** Each entry in an SQLite table has a unique integer key. (The key is ** the value of the INTEGER PRIMARY KEY column if there is such a column, diff --git a/src/sqliteInt.h b/src/sqliteInt.h index fae55f2ec7..3aa94ff34a 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.526 2006/09/11 23:45:50 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.527 2006/09/15 07:28:50 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -447,6 +447,7 @@ struct sqlite3 { Db *aDb; /* All backends */ int flags; /* Miscellanous flags. See below */ int errCode; /* Most recent error code (SQLITE_*) */ + int errMask; /* & result codes with this before returning */ u8 autoCommit; /* The auto-commit flag. */ u8 temp_store; /* 1: file 2: memory 0: default */ int nTable; /* Number of tables in the database */ diff --git a/src/table.c b/src/table.c index c4e228361f..30c1484898 100644 --- a/src/table.c +++ b/src/table.c @@ -146,7 +146,7 @@ int sqlite3_get_table( assert( sizeof(res.azResult[0])>= sizeof(res.nData) ); res.azResult[0] = (char*)res.nData; } - if( rc==SQLITE_ABORT ){ + if( (rc&0xff)==SQLITE_ABORT ){ sqlite3_free_table(&res.azResult[1]); if( res.zErrMsg ){ if( pzErrMsg ){ @@ -156,12 +156,12 @@ int sqlite3_get_table( sqliteFree(res.zErrMsg); } db->errCode = res.rc; - return res.rc; + return res.rc & db->errMask; } sqliteFree(res.zErrMsg); if( rc!=SQLITE_OK ){ sqlite3_free_table(&res.azResult[1]); - return rc; + return rc & db->errMask; } if( res.nAlloc>res.nData ){ char **azNew; @@ -176,7 +176,7 @@ int sqlite3_get_table( *pazResult = &res.azResult[1]; if( pnColumn ) *pnColumn = res.nColumn; if( pnRow ) *pnRow = res.nRow; - return rc; + return rc & db->errMask; } /* diff --git a/src/test1.c b/src/test1.c index e4e1359d15..b9dce6b993 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.221 2006/09/13 19:21:28 drh Exp $ +** $Id: test1.c,v 1.222 2006/09/15 07:28:51 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -65,7 +65,7 @@ static int get_sqlite_pointer( const char *sqlite3TestErrorName(int rc){ const char *zName = 0; - switch( rc ){ + switch( rc & 0xff ){ case SQLITE_OK: zName = "SQLITE_OK"; break; case SQLITE_ERROR: zName = "SQLITE_ERROR"; break; case SQLITE_PERM: zName = "SQLITE_PERM"; break; @@ -1061,6 +1061,29 @@ static int test_enable_shared( } #endif +/* +** Usage: sqlite3_extended_result_codes DB BOOLEAN +** +*/ +static int test_extended_result_codes( + ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ + Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ + int objc, /* Number of arguments */ + Tcl_Obj *CONST objv[] /* Command arguments */ +){ + int enable; + sqlite3 *db; + + if( objc!=3 ){ + Tcl_WrongNumArgs(interp, 1, objv, "DB BOOLEAN"); + return TCL_ERROR; + } + if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; + if( Tcl_GetBooleanFromObj(interp, objv[2], &enable) ) return TCL_ERROR; + sqlite3_extended_result_codes(db, enable); + return TCL_OK; +} + /* ** Usage: sqlite3_libversion_number ** @@ -2331,6 +2354,8 @@ static int test_errcode( Tcl_Obj *CONST objv[] ){ sqlite3 *db; + int rc; + char zBuf[30]; if( objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", @@ -2338,7 +2363,13 @@ static int test_errcode( return TCL_ERROR; } if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; - Tcl_SetResult(interp, (char *)errorName(sqlite3_errcode(db)), 0); + rc = sqlite3_errcode(db); + if( (rc&0xff)==rc ){ + zBuf[0] = 0; + }else{ + sprintf(zBuf,"+%d", rc>>8); + } + Tcl_AppendResult(interp, (char *)errorName(rc), zBuf, 0); return TCL_OK; } @@ -3861,6 +3892,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "sqlite3_load_extension", test_load_extension, 0}, { "sqlite3_enable_load_extension", test_enable_load, 0}, + { "sqlite3_extended_result_codes", test_extended_result_codes, 0}, /* sqlite3_column_*() API */ { "sqlite3_column_count", test_column_count ,0 }, diff --git a/src/util.c b/src/util.c index 905477d1f5..457227da0e 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.192 2006/07/26 01:39:30 drh Exp $ +** $Id: util.c,v 1.193 2006/09/15 07:28:51 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -1446,7 +1446,7 @@ int sqlite3ApiExit(sqlite3* db, int rc){ sqlite3Error(db, SQLITE_NOMEM, 0); rc = SQLITE_NOMEM; } - return rc; + return rc & (db ? db->errMask : 0xff); } /* diff --git a/src/vdbeapi.c b/src/vdbeapi.c index a0ced3d791..983f164cbd 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -254,6 +254,7 @@ int sqlite3_step(sqlite3_stmt *pStmt){ sqlite3Error(p->db, rc, 0); p->rc = sqlite3ApiExit(p->db, p->rc); + assert( (rc&0xff)==rc ); return rc; } @@ -815,6 +816,7 @@ int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]); sqlite3MallocAllow(); } + assert( rc==SQLITE_OK || rc==SQLITE_NOMEM ); return rc; } diff --git a/src/vdbeaux.c b/src/vdbeaux.c index a6ca9c3c76..5c534d1220 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1435,18 +1435,20 @@ int sqlite3VdbeHalt(Vdbe *p){ ** VDBE_MAGIC_INIT. */ int sqlite3VdbeReset(Vdbe *p){ + sqlite3 *db; if( p->magic!=VDBE_MAGIC_RUN && p->magic!=VDBE_MAGIC_HALT ){ sqlite3Error(p->db, SQLITE_MISUSE, 0); return SQLITE_MISUSE; } + db = p->db; /* If the VM did not run to completion or if it encountered an ** error, then it might not have been halted properly. So halt ** it now. */ - sqlite3SafetyOn(p->db); + sqlite3SafetyOn(db); sqlite3VdbeHalt(p); - sqlite3SafetyOff(p->db); + sqlite3SafetyOff(db); /* If the VDBE has be run even partially, then transfer the error code ** and error message from the VDBE into the main database structure. But @@ -1455,21 +1457,20 @@ int sqlite3VdbeReset(Vdbe *p){ */ if( p->pc>=0 ){ if( p->zErrMsg ){ - sqlite3* db = p->db; sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, sqlite3FreeX); db->errCode = p->rc; p->zErrMsg = 0; }else if( p->rc ){ - sqlite3Error(p->db, p->rc, 0); + sqlite3Error(db, p->rc, 0); }else{ - sqlite3Error(p->db, SQLITE_OK, 0); + sqlite3Error(db, SQLITE_OK, 0); } }else if( p->rc && p->expired ){ /* The expired flag was set on the VDBE before the first call ** to sqlite3_step(). For consistency (since sqlite3_step() was ** called), set the database error in this case as well. */ - sqlite3Error(p->db, p->rc, 0); + sqlite3Error(db, p->rc, 0); } /* Reclaim all memory used by the VDBE @@ -1504,9 +1505,9 @@ int sqlite3VdbeReset(Vdbe *p){ p->magic = VDBE_MAGIC_INIT; p->aborted = 0; if( p->rc==SQLITE_SCHEMA ){ - sqlite3ResetInternalSchema(p->db, 0); + sqlite3ResetInternalSchema(db, 0); } - return p->rc; + return p->rc & db->errMask; } /* @@ -1517,6 +1518,7 @@ int sqlite3VdbeFinalize(Vdbe *p){ int rc = SQLITE_OK; if( p->magic==VDBE_MAGIC_RUN || p->magic==VDBE_MAGIC_HALT ){ rc = sqlite3VdbeReset(p); + assert( (rc & p->db->errMask)==rc ); }else if( p->magic!=VDBE_MAGIC_INIT ){ return SQLITE_MISUSE; } diff --git a/src/vtab.c b/src/vtab.c index 2fa389b433..c3e2481a63 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.35 2006/09/13 19:21:28 drh Exp $ +** $Id: vtab.c,v 1.36 2006/09/15 07:28:51 drh Exp $ */ #ifndef SQLITE_OMIT_VIRTUALTABLE #include "sqliteInt.h" @@ -471,6 +471,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ sParse.pNewTable = 0; db->pVTab = 0; + assert( (rc&0xff)==rc ); return rc; } diff --git a/test/fts1c.test b/test/fts1c.test index eafb41d634..76bd854974 100644 --- a/test/fts1c.test +++ b/test/fts1c.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is testing the FTS1 module. # -# $Id: fts1c.test,v 1.3 2006/09/14 21:08:55 drh Exp $ +# $Id: fts1c.test,v 1.4 2006/09/15 07:28:51 drh Exp $ # set testdir [file dirname $argv0] @@ -1060,6 +1060,11 @@ do_test fts1c-1.8 { SELECT rowid FROM email WHERE _all MATCH '-mark susan' } } {24} +do_test fts1c-1.9 { + execsql { + SELECT rowid FROM email WHERE _all MATCH 'mark OR susan' + } +} {6 17 24 25 38 40 42 73 74} finish_test diff --git a/test/ioerr.test b/test/ioerr.test index 278e1682ad..8f1088225c 100644 --- a/test/ioerr.test +++ b/test/ioerr.test @@ -15,7 +15,7 @@ # The tests in this file use special facilities that are only # available in the SQLite test fixture. # -# $Id: ioerr.test,v 1.26 2006/02/10 13:33:31 danielk1977 Exp $ +# $Id: ioerr.test,v 1.27 2006/09/15 07:28:51 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -28,7 +28,7 @@ source $testdir/tester.tcl # file when the file on disk is only 1 page. The pager layer detects that # this has happened and suppresses the error returned by the OS layer. # -do_ioerr_test ioerr-1 -sqlprep { +do_ioerr_test ioerr-1 -erc 1 -sqlprep { SELECT * FROM sqlite_master; } -sqlbody { CREATE TABLE t1(a,b,c); diff --git a/test/tester.tcl b/test/tester.tcl index 2fa576dd17..df1f00e14c 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -11,7 +11,7 @@ # This file implements some common TCL routines used for regression # testing the SQLite library # -# $Id: tester.tcl,v 1.66 2006/09/02 14:50:24 drh Exp $ +# $Id: tester.tcl,v 1.67 2006/09/15 07:28:51 drh Exp $ # Make sure tclsqlite3 was compiled correctly. Abort now with an # error message if not. @@ -317,6 +317,7 @@ proc crashsql {crashdelay crashfile sql} { # -tclbody TCL script to run with IO error simulation. # -sqlbody TCL script to run with IO error simulation. # -exclude List of 'N' values not to test. +# -erc Use extended result codes # -start Value of 'N' to begin with (default 1) # # -cksum Boolean. If true, test that the database does @@ -326,7 +327,7 @@ proc do_ioerr_test {testname args} { set ::ioerropts(-start) 1 set ::ioerropts(-cksum) 0 - + set ::ioerropts(-erc) 0 array set ::ioerropts $args set ::go 1 @@ -347,6 +348,7 @@ proc do_ioerr_test {testname args} { catch {file delete -force test2.db} catch {file delete -force test2.db-journal} set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db] + sqlite3_extended_result_codes $::DB $::ioerropts(-erc) if {[info exists ::ioerropts(-tclprep)]} { eval $::ioerropts(-tclprep) } @@ -381,6 +383,7 @@ proc do_ioerr_test {testname args} { # a result of the script, the Nth will fail. do_test $testname.$n.3 { set r [catch $::ioerrorbody msg] + # puts rc=[sqlite3_errcode $::DB] set ::go [expr {$::sqlite_io_error_pending<=0}] set s [expr $::sqlite_io_error_hit==0] set ::sqlite_io_error_hit 0