Index: src/tclsqlite.c ================================================================== --- src/tclsqlite.c +++ src/tclsqlite.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** A TCL Interface to SQLite. Append this file to sqlite3.c and ** compile the whole thing to build a TCL-enabled version of SQLite. ** -** $Id: tclsqlite.c,v 1.189 2007/06/15 18:53:14 drh Exp $ +** $Id: tclsqlite.c,v 1.190 2007/06/19 17:15:47 drh Exp $ */ #include "tcl.h" #include /* @@ -1585,20 +1585,22 @@ }else{ apParm = aParm; } for(i=1; i<=nVar; i++){ const char *zVar = sqlite3_bind_parameter_name(pStmt, i); - if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':') ){ + if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':' || zVar[0]=='@') ){ Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0); if( pVar ){ int n; u8 *data; char *zType = pVar->typePtr ? pVar->typePtr->name : ""; char c = zType[0]; - if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){ + if( c=='b' && strcmp(zType,"bytearray")==0 + && (pVar->bytes==0 || zVar[0]=='@') ){ /* Only load a BLOB type if the Tcl variable is a bytearray and - ** has no string representation. */ + ** either it has no string representation or the host + ** parameter name begins with "@". */ data = Tcl_GetByteArrayFromObj(pVar, &n); sqlite3_bind_blob(pStmt, i, data, n, SQLITE_STATIC); Tcl_IncrRefCount(pVar); apParm[nParm++] = pVar; }else if( (c=='b' && strcmp(zType,"boolean")==0) || Index: test/tclsqlite.test ================================================================== --- test/tclsqlite.test +++ test/tclsqlite.test @@ -13,11 +13,11 @@ # # Actually, all tests are based on the TCL interface, so the main # interface is pretty well tested. This file contains some addition # tests for fringe issues that the main test suite does not cover. # -# $Id: tclsqlite.test,v 1.57 2007/05/01 17:49:49 danielk1977 Exp $ +# $Id: tclsqlite.test,v 1.58 2007/06/19 17:15:47 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Check the error messages generated by tclsqlite @@ -452,6 +452,34 @@ set version [db version] scan $version "%d.%d.%d" a b c expr $a*1000000 + $b*1000 + $c } [sqlite3_libversion_number] + +# Check to see that when bindings of the form @aaa are used instead +# of $aaa, that objects with a bytearray representation are inserted +# as BLOBs even if they also have a string representation. +# +do_test tcl-13.1 { + db eval {CREATE TABLE t5(x BLOB)} + set x abc123 + db eval {INSERT INTO t5 VALUES($x)} + db eval {SELECT typeof(x) FROM t5} +} {text} +do_test tcl-13.2 { + binary scan $x H notUsed + db eval { + DELETE FROM t5; + INSERT INTO t5 VALUES($x); + SELECT typeof(x) FROM t5; + } +} {text} +do_test tcl-13.3 { +btree_breakpoint + db eval { + DELETE FROM t5; + INSERT INTO t5 VALUES(@x); + SELECT typeof(x) FROM t5; + } +} {blob} + finish_test