1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

More test cases for the new query API. (CVS 1468)

FossilOrigin-Name: 74097ecdb0b1e0eec143c5a3f8ca2f0d63d6f38d
This commit is contained in:
danielk1977
2004-05-27 01:49:51 +00:00
parent 04f2e68d0c
commit ea61b2c4fc
4 changed files with 197 additions and 139 deletions

View File

@ -11,7 +11,7 @@
# 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 $
# $Id: capi3.test,v 1.7 2004/05/27 01:49:51 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@ -156,28 +156,157 @@ do_test capi3-4.4 {
sqlite3_close $db2
} {}
# The tests cases capi3-5.* test work as follows:
# This proc is used to test the following API calls:
#
# 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
# sqlite3_column_count
# sqlite3_column_name
# sqlite3_column_name16
# sqlite3_column_decltype
# sqlite3_column_decltype16
#
# 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.
# $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.
#
# Test cases capi3-5.2.3 - capi3-5.2.12 are a repeat of 1.3-1.12, with a
# different row of data.
# 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 {
@ -191,133 +320,32 @@ do_test capi3-5.0 {
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}
check_header $STMT capi3-5.1 {a b c} {VARIANT BLOB VARCHAR(16)}
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}
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}
# 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 {
do_test capi3-5.5 {
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}
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.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 {
do_test capi3-5.8 {
sqlite3_step $STMT
} SQLITE_DONE
do_test capi3-5.99 {
do_test capi3-5.9 {
sqlite3_finalize $STMT
} {SQLITE_OK}
} SQLITE_OK
db close
finish_test