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