| 1 |
# 2021 February 15 |
| 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 file is testing the sqlite3_column_count() API. |
| 13 |
# |
| 14 |
|
| 15 |
set testdir [file dirname $argv0] |
| 16 |
source $testdir/tester.tcl |
| 17 |
set testprefix columncount |
| 18 |
|
| 19 |
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. |
| 20 |
ifcapable !altertable { |
| 21 |
finish_test |
| 22 |
return |
| 23 |
} |
| 24 |
|
| 25 |
proc do_ccsql_test {tn sql res} { |
| 26 |
|
| 27 |
uplevel [list do_test $tn [subst -nocommands { |
| 28 |
set stmt [sqlite3_prepare_v2 db {$sql} -1 dummy] |
| 29 |
set res [sqlite3_column_count [set stmt]] |
| 30 |
while {[sqlite3_step [set stmt]]=="SQLITE_ROW"} { |
| 31 |
for {set i 0} {[set i] < [sqlite3_data_count [set stmt]]} {incr i} { |
| 32 |
lappend res [sqlite3_column_text [set stmt] [set i]] |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
set rc [sqlite3_finalize [set stmt]] |
| 37 |
if {[set rc]!="SQLITE_OK"} { |
| 38 |
error [sqlite3_errmsg db] |
| 39 |
} |
| 40 |
|
| 41 |
set res |
| 42 |
}] [list {*}$res]] |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
do_execsql_test 1.0 { |
| 47 |
CREATE TABLE t1(x, y, z); |
| 48 |
INSERT INTO t1 VALUES('a', 'b', 'c'); |
| 49 |
} |
| 50 |
|
| 51 |
do_ccsql_test 1.1 { SELECT * FROM t1 } {3 a b c} |
| 52 |
do_ccsql_test 1.2 { CREATE TABLE t2(a, b) } {0} |
| 53 |
|
| 54 |
do_ccsql_test 1.3 { ALTER TABLE t2 RENAME TO t3 } {0} |
| 55 |
do_ccsql_test 1.4 { ALTER TABLE t3 RENAME b TO ccc } {0} |
| 56 |
do_ccsql_test 1.5 { ALTER TABLE t3 ADD COLUMN d } {0} |
| 57 |
|
| 58 |
do_ccsql_test 1.6 { DROP TABLE t3 } {0} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
finish_test |