/ Check-in [e03c8189]
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:Modify the Tcl test command 'sqlite3_bind_blob' to make use of the Tcl_GetByteArrayFromObj() API.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sqlite3_trace_v2
Files: files | file ages | folders
SHA1: e03c81895e52096ab055d8231841e9070602ca84
User & Date: mistachkin 2016-07-15 01:49:25
Context
2016-07-15
02:55
Merge fixes from trunk. Fix the tclsqlite.test script. check-in: d2b1fa55 user: drh tags: sqlite3_trace_v2
01:49
Modify the Tcl test command 'sqlite3_bind_blob' to make use of the Tcl_GetByteArrayFromObj() API. check-in: e03c8189 user: mistachkin tags: sqlite3_trace_v2
00:39
Fix typo in sqlite3_trace_v2(). check-in: 97ccf15f user: mistachkin tags: sqlite3_trace_v2
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/test1.c.

3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
....
3648
3649
3650
3651
3652
3653
3654

3655
3656








3657
3658
3659
3660
3661
3662
3663
static int test_bind_blob(
  void * clientData,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  sqlite3_stmt *pStmt;
  int idx;
  int bytes;
  char *value;
  int rc;
  sqlite3_destructor_type xDestructor = SQLITE_TRANSIENT;

  if( objc!=5 && objc!=6 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"",
................................................................................
  if( objc==6 ){
    xDestructor = SQLITE_STATIC;
    objv++;
  }

  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;

  value = Tcl_GetString(objv[3]);
  if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;









  rc = sqlite3_bind_blob(pStmt, idx, value, bytes, xDestructor);
  if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  if( rc!=SQLITE_OK ){
    return TCL_ERROR;
  }








|







 







>
|

>
>
>
>
>
>
>
>







3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
....
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
static int test_bind_blob(
  void * clientData,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  sqlite3_stmt *pStmt;
  int len, idx;
  int bytes;
  char *value;
  int rc;
  sqlite3_destructor_type xDestructor = SQLITE_TRANSIENT;

  if( objc!=5 && objc!=6 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"",
................................................................................
  if( objc==6 ){
    xDestructor = SQLITE_STATIC;
    objv++;
  }

  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;

  value = Tcl_GetByteArrayFromObj(objv[3], &len);
  if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;

  if( bytes>len ){
    char zBuf[200];
    sqlite3_snprintf(sizeof(zBuf), zBuf,
                     "cannot use %d blob bytes, have %d", bytes, len);
    Tcl_AppendResult(interp, zBuf, -1);
    return TCL_ERROR;
  }

  rc = sqlite3_bind_blob(pStmt, idx, value, bytes, xDestructor);
  if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
  if( rc!=SQLITE_OK ){
    return TCL_ERROR;
  }

Changes to test/trace3.test.

188
189
190
191
192
193
194




195
196
197
198
199
200
201
      [encoding convertto unicode hi\000yall\000] 16] \
      [sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = 'hi' ORDER BY a;}}
do_test trace3-8.8 {
  list [sqlite3_bind_blob $STMT 1 "\x12\x34\x56" 3] \
      [sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = x'123456' ORDER BY a;}}





do_test trace3-9.1 {
  sqlite3_finalize $STMT
} {SQLITE_OK}

do_test trace3-10.1 {
  db trace_v2 ""







>
>
>
>







188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
      [encoding convertto unicode hi\000yall\000] 16] \
      [sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = 'hi' ORDER BY a;}}
do_test trace3-8.8 {
  list [sqlite3_bind_blob $STMT 1 "\x12\x34\x56" 3] \
      [sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = x'123456' ORDER BY a;}}
do_test trace3-8.9 {
  list [sqlite3_bind_blob $STMT 1 "\xAB\xCD\xEF" 3] \
      [sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = x'abcdef' ORDER BY a;}}

do_test trace3-9.1 {
  sqlite3_finalize $STMT
} {SQLITE_OK}

do_test trace3-10.1 {
  db trace_v2 ""