/ Check-in [f6c4908e]
Login

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

Overview
Comment:Add initial test cases for the new sqlite_bind() API. Fix bugs that the new test cases found. (CVS 1096)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f6c4908e9b5b6ac9adc4af50dc5110dbb655dae3
User & Date: drh 2003-09-06 22:45:21
Context
2003-09-09
00:47
Add test cases that check out sqlite_get_table() on queries with results sets containing 100 columns. (CVS 1097) check-in: f9feedec user: drh tags: trunk
2003-09-06
22:45
Add initial test cases for the new sqlite_bind() API. Fix bugs that the new test cases found. (CVS 1096) check-in: f6c4908e user: drh tags: trunk
22:18
Update Makefile.in for the new vdbeaux.c file. Remove the experimental "sqlite_instantiate()" routine and replace it with "sqlite_bind()" which is more like ODBC and JDBC. (CVS 1095) check-in: 990bb118 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

   572    572     sqlite_callback xCallback,     /* Result callback */
   573    573     void *pCallbackArg,            /* 1st argument to xCallback() */
   574    574     int isExplain                  /* True if the EXPLAIN keywords is present */
   575    575   ){
   576    576     int n;
   577    577   
   578    578     assert( p!=0 );
   579         -  assert( p->aStack==0 );
   580    579     assert( p->magic==VDBE_MAGIC_INIT );
   581    580   
   582    581     /* Add a HALT instruction to the very end of the program.
   583    582     */
   584    583     if( p->nOp==0 || (p->aOp && p->aOp[p->nOp-1].opcode!=OP_Halt) ){
   585    584       sqliteVdbeAddOp(p, OP_Halt, 0, 0);
   586    585     }
................................................................................
   588    587     /* No instruction ever pushes more than a single element onto the
   589    588     ** stack.  And the stack never grows on successive executions of the
   590    589     ** same loop.  So the total number of instructions is an upper bound
   591    590     ** on the maximum stack depth required.
   592    591     **
   593    592     ** Allocation all the stack space we will ever need.
   594    593     */
   595         -  p->nVar = nVar>=0 ? nVar : p->nVar;
   596         -  n = isExplain ? 10 : p->nOp;
   597         -  p->aStack = sqliteMalloc(
          594  +  if( p->aStack==0 ){
          595  +    p->nVar = nVar;
          596  +    assert( nVar>=0 );
          597  +    n = isExplain ? 10 : p->nOp;
          598  +    p->aStack = sqliteMalloc(
   598    599       n*(sizeof(p->aStack[0]) + 2*sizeof(char*))   /* aStack and zStack */
   599         -    + p->nVar*(sizeof(char*)+sizeof(int)+1)      /* azVar, anVar, abVar */
   600         -  );
   601         -  p->zStack = (char**)&p->aStack[n];
   602         -  p->azColName = (char**)&p->zStack[n];
   603         -  p->azVar = (char**)&p->azColName[n];
   604         -  p->anVar = (int*)&p->azVar[p->nVar];
   605         -  p->abVar = (u8*)&p->anVar[p->nVar];
          600  +      + p->nVar*(sizeof(char*)+sizeof(int)+1)      /* azVar, anVar, abVar */
          601  +    );
          602  +    p->zStack = (char**)&p->aStack[n];
          603  +    p->azColName = (char**)&p->zStack[n];
          604  +    p->azVar = (char**)&p->azColName[n];
          605  +    p->anVar = (int*)&p->azVar[p->nVar];
          606  +    p->abVar = (u8*)&p->anVar[p->nVar];
          607  +  }
   606    608   
   607    609     sqliteHashInit(&p->agg.hash, SQLITE_HASH_BINARY, 0);
   608    610     p->agg.pSearch = 0;
   609    611   #ifdef MEMORY_DEBUG
   610    612     if( sqliteOsFileExists("vdbe_trace") ){
   611    613       p->trace = stdout;
   612    614     }
................................................................................
   944    946     if( len<0 ){
   945    947       len = strlen(zVal)+1;
   946    948     }
   947    949     if( copy ){
   948    950       p->azVar[i] = sqliteMalloc( len );
   949    951       if( p->azVar[i] ) memcpy(p->azVar[i], zVal, len);
   950    952     }else{
   951         -    p->azVar[i] = zVal;
          953  +    p->azVar[i] = (char*)zVal;
   952    954     }
   953    955     p->abVar[i] = copy;
   954    956     p->anVar[i] = len;
   955    957     return SQLITE_OK;
   956    958   }
   957    959   
   958    960   

Added test/bind.test.

            1  +# 2003 September 6
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this script testing the sqlite_bind API.
           13  +#
           14  +# $Id: bind.test,v 1.1 2003/09/06 22:45:21 drh Exp $
           15  +#
           16  +
           17  +set testdir [file dirname $argv0]
           18  +source $testdir/tester.tcl
           19  +
           20  +do_test bind-1.1 {
           21  +  db close
           22  +  set DB [sqlite db test.db]
           23  +  execsql {CREATE TABLE t1(a,b,c)}
           24  +  set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
           25  +  set TAIL
           26  +} {}
           27  +do_test bind-1.2 {
           28  +  sqlite_step $VM N VALUES COLNAMES
           29  +} {SQLITE_DONE}
           30  +do_test bind-1.3 {
           31  +  execsql {SELECT rowid, * FROM t1}
           32  +} {1 {} {} {}}
           33  +do_test bind-1.4 {
           34  +  sqlite_reset $VM
           35  +  sqlite_bind $VM 1 {test value 1} normal
           36  +  sqlite_step $VM N VALUES COLNAMES
           37  +} SQLITE_DONE
           38  +do_test bind-1.5 {
           39  +  execsql {SELECT rowid, * FROM t1}
           40  +} {1 {} {} {} 2 {test value 1} {} {}}
           41  +do_test bind-1.6 {
           42  +  sqlite_reset $VM
           43  +  sqlite_bind $VM 3 {'test value 2'} normal
           44  +  sqlite_step $VM N VALUES COLNAMES
           45  +} SQLITE_DONE
           46  +do_test bind-1.7 {
           47  +  execsql {SELECT rowid, * FROM t1}
           48  +} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}}
           49  +do_test bind-1.8 {
           50  +  sqlite_reset $VM
           51  +  set sqlite_static_bind_value 123
           52  +  sqlite_bind $VM 1 {} static
           53  +  sqlite_bind $VM 2 {abcdefg} normal
           54  +  sqlite_bind $VM 3 {} null
           55  +  execsql {DELETE FROM t1}
           56  +  sqlite_step $VM N VALUES COLNAMES
           57  +  execsql {SELECT rowid, * FROM t1}
           58  +} {1 123 abcdefg {}}
           59  +do_test bind-1.9 {
           60  +  sqlite_reset $VM
           61  +  sqlite_bind $VM 1 {456} normal
           62  +  sqlite_step $VM N VALUES COLNAMES
           63  +  execsql {SELECT rowid, * FROM t1}
           64  +} {1 123 abcdefg {} 2 456 abcdefg {}}
           65  +
           66  +
           67  +do_test bind-1.99 {
           68  +  sqlite_finalize $VM
           69  +} {}
           70  +
           71  +
           72  +finish_test