diff options
author | drh <drh@noemail.net> | 2008-07-07 17:53:07 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2008-07-07 17:53:07 +0000 |
commit | d55d57ed5ea492f60d276b42da1dc5750bd901f6 (patch) | |
tree | 34d2d32b8db7158cb3364243cdc9b5dd69039f14 /src | |
parent | 2ef684875ff0959044bb7f377caac381a199d976 (diff) | |
download | sqlite-d55d57ed5ea492f60d276b42da1dc5750bd901f6.tar.gz sqlite-d55d57ed5ea492f60d276b42da1dc5750bd901f6.zip |
When sqlite3_create_collation is called with an invalid encoding, return
SQLITE_MISUSE. (CVS 5354)
FossilOrigin-Name: eae4105d8a162ba80ca6fde40ae24fdc6c3eccdf
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 10 | ||||
-rw-r--r-- | src/sqlite.h.in | 6 | ||||
-rw-r--r-- | src/test1.c | 13 |
3 files changed, 20 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c index cfeff0c6e..5fb9c229d 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.467 2008/07/07 14:50:14 drh Exp $ +** $Id: main.c,v 1.468 2008/07/07 17:53:08 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -999,7 +999,7 @@ const char *sqlite3_errmsg(sqlite3 *db){ if( !db ){ return sqlite3ErrStr(SQLITE_NOMEM); } - if( !sqlite3SafetyCheckSickOrOk(db) || db->errCode==SQLITE_MISUSE ){ + if( !sqlite3SafetyCheckSickOrOk(db) ){ return sqlite3ErrStr(SQLITE_MISUSE); } sqlite3_mutex_enter(db->mutex); @@ -1042,7 +1042,7 @@ const void *sqlite3_errmsg16(sqlite3 *db){ if( !db ){ return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]); } - if( !sqlite3SafetyCheckSickOrOk(db) || db->errCode==SQLITE_MISUSE ){ + if( !sqlite3SafetyCheckSickOrOk(db) ){ return (void *)(&misuseBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]); } sqlite3_mutex_enter(db->mutex); @@ -1103,10 +1103,8 @@ static int createCollation( if( enc2==SQLITE_UTF16 ){ enc2 = SQLITE_UTF16NATIVE; } - if( (enc2&~3)!=0 ){ - sqlite3Error(db, SQLITE_ERROR, "unknown encoding"); - return SQLITE_ERROR; + return SQLITE_MISUSE; } /* Check if this call is removing or replacing an existing collation diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 4e0334ad5..9bca7ebf2 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -30,7 +30,7 @@ ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.362 2008/06/28 11:23:00 danielk1977 Exp $ +** @(#) $Id: sqlite.h.in,v 1.363 2008/07/07 17:53:08 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -2433,6 +2433,10 @@ int sqlite3_open_v2( ** However, the error string might be overwritten or deallocated by ** subsequent calls to other SQLite interface functions. ** +** If an interface fails with SQLITE_MISUSE, that means the interface +** was invoked incorrectly by the application. In that case, the +** error code and message may or may not be set. +** ** INVARIANTS: ** ** {F12801} The [sqlite3_errcode(D)] interface returns the numeric diff --git a/src/test1.c b/src/test1.c index 28b625e5d..1baa8073f 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.310 2008/07/07 14:50:14 drh Exp $ +** $Id: test1.c,v 1.311 2008/07/07 17:53:08 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -1665,6 +1665,7 @@ static int test_create_collation_v2( ){ TestCollationX *p; sqlite3 *db; + int rc; if( objc!=5 ){ Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE NAME CMP-PROC DEL-PROC"); @@ -1679,7 +1680,15 @@ static int test_create_collation_v2( Tcl_IncrRefCount(p->pCmp); Tcl_IncrRefCount(p->pDel); - sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), SQLITE_UTF8, + rc = sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), 16, + (void *)p, testCreateCollationCmp, testCreateCollationDel + ); + if( rc!=SQLITE_MISUSE ){ + Tcl_AppendResult(interp, "sqlite3_create_collate_v2() failed to detect " + "an invalid encoding", (char*)0); + return TCL_ERROR; + } + rc = sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), SQLITE_UTF8, (void *)p, testCreateCollationCmp, testCreateCollationDel ); return TCL_OK; |