aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c8
-rw-r--r--src/test1.c98
-rw-r--r--src/test3.c49
3 files changed, 121 insertions, 34 deletions
diff --git a/src/main.c b/src/main.c
index 0bb3496d7..c2cb938f7 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.241 2004/06/29 11:26:59 drh Exp $
+** $Id: main.c,v 1.242 2004/06/29 13:18:24 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -894,7 +894,10 @@ const void *sqlite3_errmsg16(sqlite3 *db){
};
if( db && db->pErr ){
- if( db->magic==SQLITE_MAGIC_ERROR ){
+ if( db->magic!=SQLITE_MAGIC_OPEN &&
+ db->magic!=SQLITE_MAGIC_BUSY &&
+ db->magic!=SQLITE_MAGIC_CLOSED
+ ){
return (void *)(&misuseBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);
}
if( !sqlite3_value_text16(db->pErr) ){
@@ -1277,6 +1280,7 @@ int sqlite3_create_collation(
}else{
pColl->xCmp = xCompare;
pColl->pUser = pCtx;
+ pColl->enc = enc;
}
sqlite3Error(db, rc, 0);
return rc;
diff --git a/src/test1.c b/src/test1.c
index d5dcfa2a2..92a1a2056 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.89 2004/06/26 09:50:12 danielk1977 Exp $
+** $Id: test1.c,v 1.90 2004/06/29 13:18:24 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -76,6 +76,7 @@ static const char * errorName(int rc){
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
+ case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break;
default: zName = "SQLITE_Unknown"; break;
}
return zName;
@@ -437,17 +438,25 @@ static int test_create_function(
char **argv /* Text of each argument */
){
sqlite *db;
+ sqlite3_value *pVal;
extern void Md5_Register(sqlite*);
+
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" FILENAME\"", 0);
return TCL_ERROR;
}
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
- sqlite3_create_function(db, "x_coalesce", -1, SQLITE_UTF8, 0,
+ sqlite3_create_function(db, "x_coalesce", -1, SQLITE_ANY, 0,
ifnullFunc, 0, 0);
- sqlite3_create_function(db, "x_sqlite_exec", 1, SQLITE_UTF8, db,
- sqlite3ExecFunc, 0, 0);
+
+ /* Use the sqlite3_create_function16() API here. Mainly for fun, but also
+ ** because it is not tested anywhere else. */
+ pVal = sqlite3ValueNew();
+ sqlite3ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE_UTF8, SQLITE_STATIC);
+ sqlite3_create_function16(db, sqlite3ValueText(pVal, SQLITE_UTF16NATIVE),
+ 1, SQLITE_UTF16, db, sqlite3ExecFunc, 0, 0);
+ sqlite3ValueFree(pVal);
return TCL_OK;
}
@@ -984,6 +993,7 @@ static int test_collate(
){
sqlite3 *db;
int val;
+ sqlite3_value *pVal;
if( objc!=5 ) goto bad_args;
pTestCollateInterp = interp;
@@ -996,8 +1006,12 @@ static int test_collate(
sqlite3_create_collation(db, "test_collate", SQLITE_UTF16LE,
(void *)SQLITE_UTF16LE, val?test_collate_func:0);
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR;
- sqlite3_create_collation(db, "test_collate", SQLITE_UTF16BE,
- (void *)SQLITE_UTF16BE, val?test_collate_func:0);
+
+ pVal = sqlite3ValueNew();
+ sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC);
+ sqlite3_create_collation16(db, sqlite3ValueText(pVal, SQLITE_UTF16NATIVE),
+ SQLITE_UTF16BE, (void *)SQLITE_UTF16BE, val?test_collate_func:0);
+ sqlite3ValueFree(pVal);
return TCL_OK;
@@ -1007,6 +1021,38 @@ bad_args:
return TCL_ERROR;
}
+static void test_collate_needed_cb(
+ void *pCtx,
+ sqlite3 *db,
+ int eTextRep,
+ const void *notUsed
+){
+ int enc = db->enc;
+ sqlite3_create_collation(
+ db, "test_collate", db->enc, (void *)enc, test_collate_func);
+}
+
+/*
+** Usage: add_test_collate_needed DB
+*/
+static int test_collate_needed(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ sqlite3 *db;
+
+ if( objc!=2 ) goto bad_args;
+ if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
+ sqlite3_collation_needed16(db, 0, test_collate_needed_cb);
+ return TCL_OK;
+
+bad_args:
+ Tcl_WrongNumArgs(interp, 1, objv, "DB");
+ return TCL_ERROR;
+}
+
/*
** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be>
**
@@ -1136,6 +1182,34 @@ bad_args:
return TCL_ERROR;
}
+/*
+** Usage: test_errstr <err code>
+**
+** Test that the english language string equivalents for sqlite error codes
+** are sane. The parameter is an integer representing an sqlite error code.
+** The result is a list of two elements, the string representation of the
+** error code and the english language explanation.
+*/
+static int test_errstr(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ char *zCode;
+ int i;
+ if( objc!=1 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "<error code>");
+ }
+
+ zCode = Tcl_GetString(objv[1]);
+ for(i=0; i<200; i++){
+ if( 0==strcmp(errorName(i), zCode) ) break;
+ }
+ Tcl_SetResult(interp, (char *)sqlite3ErrStr(i), 0);
+ return TCL_OK;
+}
+
static int sqlite3_crashparams(
void * clientData,
Tcl_Interp *interp,
@@ -2219,10 +2293,14 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3OsOpenReadWrite",test_sqlite3OsOpenReadWrite, 0 },
{ "sqlite3OsClose", test_sqlite3OsClose, 0 },
{ "sqlite3OsLock", test_sqlite3OsLock, 0 },
- { "sqlite3OsUnlock", test_sqlite3OsUnlock, 0 },
- { "add_test_collate", test_collate, 0 },
- { "add_test_function", test_function, 0 },
- { "sqlite3_crashparams", sqlite3_crashparams, 0 },
+
+ /* Custom test interfaces */
+ { "sqlite3OsUnlock", test_sqlite3OsUnlock, 0 },
+ { "add_test_collate", test_collate, 0 },
+ { "add_test_collate_needed", test_collate_needed, 0 },
+ { "add_test_function", test_function, 0 },
+ { "sqlite3_crashparams", sqlite3_crashparams, 0 },
+ { "sqlite3_test_errstr", test_errstr, 0 },
};
int i;
diff --git a/src/test3.c b/src/test3.c
index f841ff357..0e2020ba9 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.45 2004/06/26 08:38:25 danielk1977 Exp $
+** $Id: test3.c,v 1.46 2004/06/29 13:18:24 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
@@ -750,35 +750,35 @@ static int btree_delete(
** exists with the same key the old entry is overwritten.
*/
static int btree_insert(
- void *NotUsed,
- Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
- int argc, /* Number of arguments */
- const char **argv /* Text of each argument */
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
){
BtCursor *pCur;
int rc;
- if( argc!=4 ){
- Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- " ID KEY DATA\"", 0);
+ if( objc!=4 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "ID KEY DATA");
return TCL_ERROR;
}
- if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
+
+ if( Tcl_GetIntFromObj(interp, objv[1], (int*)&pCur) ) return TCL_ERROR;
if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){
-/*
- int iKey;
- if( Tcl_GetInt(interp, argv[2], &iKey) ) return TCL_ERROR;
-*/
i64 iKey;
- Tcl_Obj *obj = Tcl_NewStringObj(argv[2], -1);
- Tcl_IncrRefCount(obj);
- if( Tcl_GetWideIntFromObj(interp, obj, &iKey) ) return TCL_ERROR;
- Tcl_DecrRefCount(obj);
-
- rc = sqlite3BtreeInsert(pCur, 0, iKey, argv[3], strlen(argv[3]));
+ int len;
+ unsigned char *pBuf;
+ if( Tcl_GetWideIntFromObj(interp, objv[2], &iKey) ) return TCL_ERROR;
+ pBuf = Tcl_GetByteArrayFromObj(objv[3], &len);
+ rc = sqlite3BtreeInsert(pCur, 0, iKey, pBuf, len);
}else{
- rc = sqlite3BtreeInsert(pCur, argv[2], strlen(argv[2]),
- argv[3], strlen(argv[3]));
+ int keylen;
+ int dlen;
+ unsigned char *pKBuf;
+ unsigned char *pDBuf;
+ pKBuf = Tcl_GetByteArrayFromObj(objv[2], &keylen);
+ pDBuf = Tcl_GetByteArrayFromObj(objv[3], &dlen);
+ rc = sqlite3BtreeInsert(pCur, pKBuf, keylen, pDBuf, dlen);
}
if( rc ){
Tcl_AppendResult(interp, errorName(rc), 0);
@@ -1319,7 +1319,6 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
{ "btree_close_cursor", (Tcl_CmdProc*)btree_close_cursor },
{ "btree_move_to", (Tcl_CmdProc*)btree_move_to },
{ "btree_delete", (Tcl_CmdProc*)btree_delete },
- { "btree_insert", (Tcl_CmdProc*)btree_insert },
{ "btree_next", (Tcl_CmdProc*)btree_next },
{ "btree_prev", (Tcl_CmdProc*)btree_prev },
{ "btree_eof", (Tcl_CmdProc*)btree_eof },
@@ -1349,5 +1348,11 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
TCL_LINK_INT);
Tcl_LinkVar(interp, "btree_trace", (char*)&sqlite3_btree_trace,
TCL_LINK_INT);
+
+ /* The btree_insert command is implemented using the tcl 'object'
+ ** interface, not the string interface like the other commands in this
+ ** file. This is so binary data can be inserted into btree tables.
+ */
+ Tcl_CreateObjCommand(interp, "btree_insert", btree_insert, 0, 0);
return TCL_OK;
}