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