/ Check-in [dcb104bd]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:In the TCL bindings, if a TCL variable has a bytearray representation and the host parameter starts with @ instead of $, then always store the content as a BLOB not as a string even if a string representation is also available. (CVS 4092)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: dcb104bd41f5e992d4c84b8947cb5099ae746891
User & Date: drh 2007-06-19 17:15:47
Context
2007-06-19
17:48
Cleanup the TCL interface source code and add documentation for recently added methods on the SQLite object of TCL. (CVS 4093) check-in: d88b7981 user: drh tags: trunk
17:15
In the TCL bindings, if a TCL variable has a bytearray representation and the host parameter starts with @ instead of $, then always store the content as a BLOB not as a string even if a string representation is also available. (CVS 4092) check-in: dcb104bd user: drh tags: trunk
15:23
Change the name of the "limits.h" source file to "sqliteLimit.h". Ticket #2428. (CVS 4091) check-in: 64bcc41f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/tclsqlite.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** A TCL Interface to SQLite.  Append this file to sqlite3.c and
    13     13   ** compile the whole thing to build a TCL-enabled version of SQLite.
    14     14   **
    15         -** $Id: tclsqlite.c,v 1.189 2007/06/15 18:53:14 drh Exp $
           15  +** $Id: tclsqlite.c,v 1.190 2007/06/19 17:15:47 drh Exp $
    16     16   */
    17     17   #include "tcl.h"
    18     18   #include <errno.h>
    19     19   
    20     20   /*
    21     21   ** Some additional include files are needed if this file is not
    22     22   ** appended to the amalgamation.
................................................................................
  1583   1583         if( nVar>sizeof(aParm)/sizeof(aParm[0]) ){
  1584   1584           apParm = (Tcl_Obj**)Tcl_Alloc(nVar*sizeof(apParm[0]));
  1585   1585         }else{
  1586   1586           apParm = aParm;
  1587   1587         }
  1588   1588         for(i=1; i<=nVar; i++){
  1589   1589           const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
  1590         -        if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':') ){
         1590  +        if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':' || zVar[0]=='@') ){
  1591   1591             Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0);
  1592   1592             if( pVar ){
  1593   1593               int n;
  1594   1594               u8 *data;
  1595   1595               char *zType = pVar->typePtr ? pVar->typePtr->name : "";
  1596   1596               char c = zType[0];
  1597         -            if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){
         1597  +            if( c=='b' && strcmp(zType,"bytearray")==0 
         1598  +                 && (pVar->bytes==0 || zVar[0]=='@') ){
  1598   1599                 /* Only load a BLOB type if the Tcl variable is a bytearray and
  1599         -              ** has no string representation. */
         1600  +              ** either it has no string representation or the host
         1601  +              ** parameter name begins with "@". */
  1600   1602                 data = Tcl_GetByteArrayFromObj(pVar, &n);
  1601   1603                 sqlite3_bind_blob(pStmt, i, data, n, SQLITE_STATIC);
  1602   1604                 Tcl_IncrRefCount(pVar);
  1603   1605                 apParm[nParm++] = pVar;
  1604   1606               }else if( (c=='b' && strcmp(zType,"boolean")==0) ||
  1605   1607                     (c=='i' && strcmp(zType,"int")==0) ){
  1606   1608                 Tcl_GetIntFromObj(interp, pVar, &n);

Changes to test/tclsqlite.test.

    11     11   # This file implements regression tests for TCL interface to the
    12     12   # SQLite library. 
    13     13   #
    14     14   # Actually, all tests are based on the TCL interface, so the main
    15     15   # interface is pretty well tested.  This file contains some addition
    16     16   # tests for fringe issues that the main test suite does not cover.
    17     17   #
    18         -# $Id: tclsqlite.test,v 1.57 2007/05/01 17:49:49 danielk1977 Exp $
           18  +# $Id: tclsqlite.test,v 1.58 2007/06/19 17:15:47 drh Exp $
    19     19   
    20     20   set testdir [file dirname $argv0]
    21     21   source $testdir/tester.tcl
    22     22   
    23     23   # Check the error messages generated by tclsqlite
    24     24   #
    25     25   if {[sqlite3 -has-codec]} {
................................................................................
   450    450   do_test tcl-12.1 {
   451    451     unset -nocomplain a b c version
   452    452     set version [db version]
   453    453     scan $version "%d.%d.%d" a b c
   454    454     expr $a*1000000 + $b*1000 + $c
   455    455   } [sqlite3_libversion_number]
   456    456   
          457  +
          458  +# Check to see that when bindings of the form @aaa are used instead
          459  +# of $aaa, that objects with a bytearray representation are inserted
          460  +# as BLOBs even if they also have a string representation.
          461  +#
          462  +do_test tcl-13.1 {
          463  +  db eval {CREATE TABLE t5(x BLOB)}
          464  +  set x abc123
          465  +  db eval {INSERT INTO t5 VALUES($x)}
          466  +  db eval {SELECT typeof(x) FROM t5}
          467  +} {text}
          468  +do_test tcl-13.2 {
          469  +  binary scan $x H notUsed
          470  +  db eval {
          471  +    DELETE FROM t5;
          472  +    INSERT INTO t5 VALUES($x);
          473  +    SELECT typeof(x) FROM t5;
          474  +  }
          475  +} {text}
          476  +do_test tcl-13.3 {
          477  +btree_breakpoint
          478  +  db eval {
          479  +    DELETE FROM t5;
          480  +    INSERT INTO t5 VALUES(@x);
          481  +    SELECT typeof(x) FROM t5;
          482  +  }
          483  +} {blob}
          484  +
   457    485   finish_test