sl@0
|
1 |
#
|
sl@0
|
2 |
# 2006 February 9
|
sl@0
|
3 |
#
|
sl@0
|
4 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
5 |
# a legal notice, here is a blessing:
|
sl@0
|
6 |
#
|
sl@0
|
7 |
# May you do good and not evil.
|
sl@0
|
8 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
9 |
# May you share freely, never taking more than you give.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
#***********************************************************************
|
sl@0
|
12 |
# This file implements regression tests for SQLite library. The
|
sl@0
|
13 |
# focus of this script is the sqlite3_table_column_metadata() API.
|
sl@0
|
14 |
#
|
sl@0
|
15 |
# $Id: colmeta.test,v 1.4 2008/01/23 12:52:41 drh Exp $
|
sl@0
|
16 |
|
sl@0
|
17 |
set testdir [file dirname $argv0]
|
sl@0
|
18 |
source $testdir/tester.tcl
|
sl@0
|
19 |
|
sl@0
|
20 |
ifcapable !columnmetadata {
|
sl@0
|
21 |
finish_test
|
sl@0
|
22 |
return
|
sl@0
|
23 |
}
|
sl@0
|
24 |
|
sl@0
|
25 |
# Set up a schema in the main and temp test databases.
|
sl@0
|
26 |
do_test colmeta-0 {
|
sl@0
|
27 |
execsql {
|
sl@0
|
28 |
CREATE TABLE abc(a, b, c);
|
sl@0
|
29 |
CREATE TABLE abc2(a PRIMARY KEY COLLATE NOCASE, b VARCHAR(32), c);
|
sl@0
|
30 |
CREATE TABLE abc3(a NOT NULL, b INTEGER PRIMARY KEY, c);
|
sl@0
|
31 |
}
|
sl@0
|
32 |
ifcapable autoinc {
|
sl@0
|
33 |
execsql {
|
sl@0
|
34 |
CREATE TABLE abc4(a, b INTEGER PRIMARY KEY AUTOINCREMENT, c);
|
sl@0
|
35 |
}
|
sl@0
|
36 |
}
|
sl@0
|
37 |
ifcapable view {
|
sl@0
|
38 |
execsql {
|
sl@0
|
39 |
CREATE VIEW v1 AS SELECT * FROM abc2;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
}
|
sl@0
|
42 |
} {}
|
sl@0
|
43 |
|
sl@0
|
44 |
|
sl@0
|
45 |
# Return values are of the form:
|
sl@0
|
46 |
#
|
sl@0
|
47 |
# {<decl-type> <collation> <not null> <primary key> <auto increment>}
|
sl@0
|
48 |
#
|
sl@0
|
49 |
set tests {
|
sl@0
|
50 |
1 {main abc a} {0 {{} BINARY 0 0 0}}
|
sl@0
|
51 |
2 {{} abc a} {0 {{} BINARY 0 0 0}}
|
sl@0
|
52 |
3 {{} abc2 b} {0 {VARCHAR(32) BINARY 0 0 0}}
|
sl@0
|
53 |
4 {main abc2 b} {0 {VARCHAR(32) BINARY 0 0 0}}
|
sl@0
|
54 |
5 {{} abc2 a} {0 {{} NOCASE 0 1 0}}
|
sl@0
|
55 |
6 {{} abc3 a} {0 {{} BINARY 1 0 0}}
|
sl@0
|
56 |
7 {{} abc3 b} {0 {INTEGER BINARY 0 1 0}}
|
sl@0
|
57 |
13 {main abc rowid} {0 {INTEGER BINARY 0 1 0}}
|
sl@0
|
58 |
14 {main abc3 rowid} {0 {INTEGER BINARY 0 1 0}}
|
sl@0
|
59 |
16 {main abc d} {1 {no such table column: abc.d}}
|
sl@0
|
60 |
}
|
sl@0
|
61 |
ifcapable view {
|
sl@0
|
62 |
set tests [concat $tests {
|
sl@0
|
63 |
8 {{} abc4 b} {0 {INTEGER BINARY 0 1 1}}
|
sl@0
|
64 |
15 {main abc4 rowid} {0 {INTEGER BINARY 0 1 1}}
|
sl@0
|
65 |
}]
|
sl@0
|
66 |
}
|
sl@0
|
67 |
ifcapable view {
|
sl@0
|
68 |
set tests [concat $tests {
|
sl@0
|
69 |
9 {{} v1 a} {1 {no such table column: v1.a}}
|
sl@0
|
70 |
10 {main v1 b} {1 {no such table column: v1.b}}
|
sl@0
|
71 |
11 {main v1 badname} {1 {no such table column: v1.badname}}
|
sl@0
|
72 |
12 {main v1 rowid} {1 {no such table column: v1.rowid}}
|
sl@0
|
73 |
}]
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
foreach {tn params results} $tests {
|
sl@0
|
77 |
set ::DB [sqlite3_connection_pointer db]
|
sl@0
|
78 |
|
sl@0
|
79 |
set tstbody [concat sqlite3_table_column_metadata $::DB $params]
|
sl@0
|
80 |
do_test colmeta-$tn.1 {
|
sl@0
|
81 |
list [catch $tstbody msg] [set msg]
|
sl@0
|
82 |
} $results
|
sl@0
|
83 |
|
sl@0
|
84 |
db close
|
sl@0
|
85 |
sqlite3 db test.db
|
sl@0
|
86 |
|
sl@0
|
87 |
set ::DB [sqlite3_connection_pointer db]
|
sl@0
|
88 |
set tstbody [concat sqlite3_table_column_metadata $::DB $params]
|
sl@0
|
89 |
do_test colmeta-$tn.2 {
|
sl@0
|
90 |
list [catch $tstbody msg] [set msg]
|
sl@0
|
91 |
} $results
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
finish_test
|