SQLite

Check-in [74097ecdb0]
Login

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

Overview
Comment:More test cases for the new query API. (CVS 1468)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 74097ecdb0b1e0eec143c5a3f8ca2f0d63d6f38d
User & Date: danielk1977 2004-05-27 01:49:51.000
Context
2004-05-27
01:53
More MEM changes in the vdbe.c. Still will not compile. (CVS 1469) (check-in: dbdd1a7f31 user: drh tags: trunk)
01:49
More test cases for the new query API. (CVS 1468) (check-in: 74097ecdb0 user: danielk1977 tags: trunk)
01:04
Add TCL test bindings and some more test cases for the new query API. (CVS 1467) (check-in: d72adf0c52 user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/test1.c.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the printf() interface to SQLite.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.60 2004/05/27 01:04:07 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>








|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the printf() interface to SQLite.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.61 2004/05/27 01:49:51 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

1413
1414
1415
1416
1417
1418
1419






























1420
1421
1422
1423
1424
1425
1426
  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;

  iVal = sqlite3_column_int64(pStmt, col);
  Tcl_SetObjResult(interp, Tcl_NewWideIntObj(iVal));
  return TCL_OK;
}































/*
** Usage: sqlite3_column_double STMT column
**
** Return the data in column 'column' of the current row cast as a double.
*/
static int test_column_double(







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;

  iVal = sqlite3_column_int64(pStmt, col);
  Tcl_SetObjResult(interp, Tcl_NewWideIntObj(iVal));
  return TCL_OK;
}

/*
** Usage: sqlite3_column_blob STMT column
*/
static int test_column_blob(
  void * clientData,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  sqlite3_stmt *pStmt;
  int col;

  int len;
  void *pBlob;

  if( objc!=3 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", 
       Tcl_GetString(objv[0]), " STMT column", 0);
    return TCL_ERROR;
  }

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

  pBlob = sqlite3_column_blob(pStmt, col);
  len = sqlite3_column_bytes(pStmt, col);
  Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pBlob, len));
  return TCL_OK;
}

/*
** Usage: sqlite3_column_double STMT column
**
** Return the data in column 'column' of the current row cast as a double.
*/
static int test_column_double(
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
     { "sqlite3_reset",                 test_reset         ,0 },
     { "sqlite3_step",                  test_step,0 },

     /* sqlite3_column_*() API */
     { "sqlite3_column_count",          test_column_count  ,0 },
     { "sqlite3_data_count",            test_data_count    ,0 },
     { "sqlite3_column_type",           test_column_type   ,0 },
     { "sqlite3_column_blob",           test_column_name   ,0 },
     { "sqlite3_column_double",         test_column_double ,0 },
     { "sqlite3_column_int64",          test_column_int64  ,0 },
     { "sqlite3_column_int", test_stmt_int ,sqlite3_column_int },
     { "sqlite3_column_bytes", test_stmt_int ,sqlite3_column_bytes },
     { "sqlite3_column_bytes16", test_stmt_int ,sqlite3_column_bytes16 },
     { "sqlite3_column_text", test_stmt_utf8,       sqlite3_column_text},
     { "sqlite3_column_decltype", test_stmt_utf8,   sqlite3_column_decltype},







|







1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
     { "sqlite3_reset",                 test_reset         ,0 },
     { "sqlite3_step",                  test_step,0 },

     /* sqlite3_column_*() API */
     { "sqlite3_column_count",          test_column_count  ,0 },
     { "sqlite3_data_count",            test_data_count    ,0 },
     { "sqlite3_column_type",           test_column_type   ,0 },
     { "sqlite3_column_blob",           test_column_blob   ,0 },
     { "sqlite3_column_double",         test_column_double ,0 },
     { "sqlite3_column_int64",          test_column_int64  ,0 },
     { "sqlite3_column_int", test_stmt_int ,sqlite3_column_int },
     { "sqlite3_column_bytes", test_stmt_int ,sqlite3_column_bytes },
     { "sqlite3_column_bytes16", test_stmt_int ,sqlite3_column_bytes16 },
     { "sqlite3_column_text", test_stmt_utf8,       sqlite3_column_text},
     { "sqlite3_column_decltype", test_stmt_utf8,   sqlite3_column_decltype},
Changes to test/capi3.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2003 January 29
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.6 2004/05/27 01:04:07 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Return the UTF-16 representation of the supplied UTF-8 string $str.
# If $nt is true, append two 0x00 bytes as a nul terminator.













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2003 January 29
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.7 2004/05/27 01:49:51 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Return the UTF-16 representation of the supplied UTF-8 string $str.
# If $nt is true, append two 0x00 bytes as a nul terminator.
152
153
154
155
156
157
158



















159






160






161






162






163
164






165



















166



167






168






169






170
171





172
173





174






175






176






177






178
179





180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
do_test capi3-4.4 {
  utf8 [sqlite3_errmsg16 $db2]
} {unable to open database file}
do_test capi3-4.4 {
  sqlite3_close $db2
} {}




















# The tests cases capi3-5.* test work as follows:






#






# capi3-5.0: Prepare a statement, and check we can retrieve the number of






#            columns (before the statement is executed).






# capi3-5.1: Check we can retrieve column names (before statement execution)
# capi3-5.2: Check we can retrieve column names in UTF-16






#



















# capi3-5.1.3: Step the statement.



# capi3-5.1.4: Check the types of the values.






# capi3-5.1.5: Check the values can be retrieved as integers.






# capi3-5.1.6: Check the values can be retrieved as UTF-8 text.






# capi3-5.1.7: Check the values can be retrieved as floats.
# capi3-5.1.8: Check the values can be retrieved as UTF-16 text.





# capi3-5.1.9: Check the values can be retrieved as integers.
# capi3-5.1.10: Check the values can be retrieved as floats.





# capi3-5.1.11: Check the values can still be retrieved as UTF-8 text.






# capi3-5.1.12: Check that the types of the values have not been altered by






#               retrieving the values as text.






#






# Test cases capi3-5.2.3 - capi3-5.2.12 are a repeat of 1.3-1.12, with a
# different row of data.





#


do_test capi3-5.0 {
  execsql {
    CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16));
    INSERT INTO t1 VALUES(1, 2, 3);
    INSERT INTO t1 VALUES('one', 'two', NULL);
  }
  set sql "SELECT * FROM t1"
  set STMT [sqlite3_prepare $DB $sql -1 TAIL]

  sqlite3_column_count $STMT
} 3

do_test capi3-5.1 {
  set cnamelist [list]
  foreach i {0 1 2} {lappend cnamelist [sqlite3_column_name $STMT $i]} 
  set cnamelist
} {a b c}

do_test capi3-5.2 {
  set cnamelist [list]
  foreach i {0 1 2} {lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]}
  set cnamelist
} {a b c}

do_test capi3-5.1.3 {
  sqlite3_step $STMT
} SQLITE_ROW

# types
do_test capi3-5.1.4 {
  set types [list]
  foreach i {0 1 2} {lappend types [sqlite3_column_type $STMT $i]}
  set types
} {INTEGER INTEGER TEXT}

# Integers
do_test capi3-5.1.5 {
  set ints [list]
  foreach i {0 1 2} {lappend ints [sqlite3_column_int $STMT $i]}
  set ints
} {1 2 3}

# UTF-8
do_test capi3-5.1.6 {
  set utf8 [list]
  foreach i {0 1 2} {lappend utf8 [sqlite3_column_data $STMT $i]}
  set utf8
} {1 2 3}

# Floats
do_test capi3-5.1.7 {
  set utf8 [list]
  foreach i {0 1 2} {lappend utf8 [sqlite3_column_double $STMT $i]}
  set utf8
} {1 2 3}

# UTF-16
do_test capi3-5.1.8 {
  set utf8 [list]
  foreach i {0 1 2} {lappend utf8 [utf8 [sqlite3_column_data16 $STMT $i]]}
  set utf8
} {1 2 3}

# Integers
do_test capi3-5.1.9 {
  set ints [list]
  foreach i {0 1 2} {lappend ints [sqlite3_column_int $STMT $i]}
  set ints
} {1 2 3}

# Floats
do_test capi3-5.1.10 {
  set utf8 [list]
  foreach i {0 1 2} {lappend utf8 [sqlite3_column_double $STMT $i]}
  set utf8
} {1 2 3}

# UTF-8
do_test capi3-5.1.11 {
  set utf8 [list]
  foreach i {0 1 2} {lappend utf8 [sqlite3_column_data $STMT $i]}
  set utf8
} {1 2 3}

# Types
do_test capi3-5.1.12 {
  set types [list]
  foreach i {0 1 2} {lappend types [sqlite3_column_type $STMT $i]}
  set types
} {INTEGER INTEGER TEXT}



do_test capi3-5.9 {
  sqlite3_step $STMT
} SQLITE_ROW

do_test capi3-5.10 {
  set types [list]
  foreach i {0 1 2} {lappend types [sqlite3_column_type $STMT $i]}
  set types
} {TEXT TEXT NULL}

do_test capi3-5.11 {
  set ints [list]
  foreach i {0 1 2} {lappend ints [sqlite3_column_int $STMT $i]}
  set ints
} {0 0 0}

do_test capi3-5.12 {
  set utf8 [list]
  foreach i {0 1 2} {lappend utf8 [sqlite3_column_data $STMT $i]}
  set utf8
} {one two {}}

do_test capi3-5.13 {
  set utf8 [list]
  foreach i {0 1 2} {lappend utf8 [utf8 [sqlite3_column_data16 $STMT $i]]}
  set utf8
} {one two {}}

do_test capi3-5.14 {
  set types [list]
  foreach i {0 1 2} {lappend types [sqlite3_column_type $STMT $i]}
  set types
} {TEXT TEXT NULL}

do_test capi3-5.15 {
  sqlite3_step $STMT
} SQLITE_DONE

do_test capi3-5.99 {
  sqlite3_finalize $STMT
} {SQLITE_OK}


db close

finish_test










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
|
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
|
>
>
>
>
>
|
|
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
|
>
>
>
>
>
|
>













|
<
<
<
<


<
<
<
<
<
<



<
|
<
<
<
|

<
|
<
<
<
<
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|

|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



|

|
<






<
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323




324
325






326
327
328

329



330
331

332




333






334



























335






336

















337
338
339
























340
341
342
343
344
345

346
347
348
349
350
351

do_test capi3-4.4 {
  utf8 [sqlite3_errmsg16 $db2]
} {unable to open database file}
do_test capi3-4.4 {
  sqlite3_close $db2
} {}

# This proc is used to test the following API calls:
#
# sqlite3_column_count
# sqlite3_column_name
# sqlite3_column_name16
# sqlite3_column_decltype
# sqlite3_column_decltype16
#
# $STMT is a compiled SQL statement. $test is a prefix
# to use for test names within this proc. $names is a list
# of the column names that should be returned by $STMT.
# $decltypes is a list of column declaration types for $STMT.
#
# Example:
#
# set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY]
# check_header test1.1 {1 2 3} {"" "" ""}
#
proc check_header {STMT test names decltypes} }

  # Use the return value of sqlite3_column_count() to build
  # a list of column indexes. i.e. If sqlite3_column_count
  # is 3, build the list {0 1 2}.
  set idxlist [list]
  set numcols [sqlite3_column_count $STMT]
  for {set i 0} {$i < $numcols} {incr i} {lappend idxlist $i}

  # Column names in UTF-8
  do_test $test.1 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} 
    set cnamelist
  } $names

  # Column names in UTF-16
  do_test $test.2 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]}
    set cnamelist
  } $names

  # Column names in UTF-8
  do_test $test.3 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} 
    set cnamelist
  } $names

  # Column names in UTF-16
  do_test $test.4 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]}
    set cnamelist
  } $names
} 

# This proc is used to test the following APIs:
#
# sqlite3_data_count
# sqlite3_column_type
# sqlite3_column_int
# sqlite3_column_text
# sqlite3_column_text16
# sqlite3_column_double
#
# $STMT is a compiled SQL statement for which the previous call 
# to sqlite3_step returned SQLITE_ROW. $test is a prefix to use 
# for test names within this proc. $types is a list of the 
# manifest types for the current row. $ints, $doubles and $strings
# are lists of the integer, real and string representations of
# the values in the current row.
#
# Example:
#
# set STMT [sqlite3_prepare "SELECT 'hello', 1.1, NULL" -1 DUMMY]
# sqlite3_step $STMT
# check_data test1.2 {TEXT REAL NULL} {0 1 0} {0 1.1 0} {hello 1.1 {}}
#
proc check_data {STMT test types ints doubles strings} {

  # Use the return value of sqlite3_column_count() to build
  # a list of column indexes. i.e. If sqlite3_column_count
  # is 3, build the list {0 1 2}.
  set idxlist [list]
  set numcols [sqlite3_data_count $STMT]
  for {set i 0} {$i < $numcols} {incr i} {lappend idxlist $i}

# types
do_test $test.1 {
  set types [list]
  foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
  set types
} $types

# Integers
do_test $test.2 {
  set ints [list]
  foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]}
  set ints
} $ints

# UTF-8
do_test $test.3 {
  set utf8 [list]
  foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
  set utf8
} $strings

# Floats
do_test $test.4 {
  set utf8 [list]
  foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
  set utf8
} $doubles

# UTF-16
do_test $test.5 {
  set utf8 [list]
  foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]}
  set utf8
} $strings

# Integers
do_test $test.6 {
  set ints [list]
  foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]}
  set ints
} $ints

# Floats
do_test $test.7 {
  set utf8 [list]
  foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
  set utf8
} $doubles

# UTF-8
do_test $test.8 {
  set utf8 [list]
  foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
  set utf8
} $strings

# Types
do_test $test.9 {
  set types [list]
  foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
  set types
} $types

}

do_test capi3-5.0 {
  execsql {
    CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16));
    INSERT INTO t1 VALUES(1, 2, 3);
    INSERT INTO t1 VALUES('one', 'two', NULL);
  }
  set sql "SELECT * FROM t1"
  set STMT [sqlite3_prepare $DB $sql -1 TAIL]

  sqlite3_column_count $STMT
} 3

check_header $STMT capi3-5.1 {a b c} {VARIANT BLOB VARCHAR(16)}





do_test capi3-5.2 {






  sqlite3_step $STMT
} SQLITE_ROW


check_header $STMT capi3-5.3 {a b c} {VARIANT BLOB VARCHAR(16)}



check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1 2 3} {1 2 3}


do_test capi3-5.5 {




  sqlite3_step $STMT






} SQLITE_ROW


































check_header $STMT capi3-5.6 {a b c} {VARIANT BLOB VARCHAR(16)}

















check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0 0 0} {one two {}}

do_test capi3-5.8 {
























  sqlite3_step $STMT
} SQLITE_DONE

do_test capi3-5.9 {
  sqlite3_finalize $STMT
} SQLITE_OK


db close

finish_test