os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/colmeta.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/colmeta.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,94 @@
     1.4 +#
     1.5 +# 2006 February 9
     1.6 +#
     1.7 +# The author disclaims copyright to this source code.  In place of
     1.8 +# a legal notice, here is a blessing:
     1.9 +#
    1.10 +#    May you do good and not evil.
    1.11 +#    May you find forgiveness for yourself and forgive others.
    1.12 +#    May you share freely, never taking more than you give.
    1.13 +#
    1.14 +#***********************************************************************
    1.15 +# This file implements regression tests for SQLite library.  The
    1.16 +# focus of this script is the sqlite3_table_column_metadata() API.
    1.17 +#
    1.18 +# $Id: colmeta.test,v 1.4 2008/01/23 12:52:41 drh Exp $
    1.19 +
    1.20 +set testdir [file dirname $argv0]
    1.21 +source $testdir/tester.tcl
    1.22 +
    1.23 +ifcapable !columnmetadata {
    1.24 +  finish_test
    1.25 +  return
    1.26 +}
    1.27 +
    1.28 +# Set up a schema in the main and temp test databases.
    1.29 +do_test colmeta-0 {
    1.30 +  execsql {
    1.31 +    CREATE TABLE abc(a, b, c);
    1.32 +    CREATE TABLE abc2(a PRIMARY KEY COLLATE NOCASE, b VARCHAR(32), c);
    1.33 +    CREATE TABLE abc3(a NOT NULL, b INTEGER PRIMARY KEY, c);
    1.34 +  }
    1.35 +  ifcapable autoinc {
    1.36 +    execsql {
    1.37 +      CREATE TABLE abc4(a, b INTEGER PRIMARY KEY AUTOINCREMENT, c);
    1.38 +    }
    1.39 +  }
    1.40 +  ifcapable view {
    1.41 +    execsql {
    1.42 +      CREATE VIEW v1 AS SELECT * FROM abc2;
    1.43 +    }
    1.44 +  }
    1.45 +} {}
    1.46 +
    1.47 +
    1.48 +# Return values are of the form:
    1.49 +#
    1.50 +#   {<decl-type> <collation> <not null> <primary key> <auto increment>}
    1.51 +#
    1.52 +set tests {
    1.53 +  1  {main abc a}                {0 {{} BINARY 0 0 0}}
    1.54 +  2  {{} abc a}                  {0 {{} BINARY 0 0 0}}
    1.55 +  3  {{} abc2 b}                 {0 {VARCHAR(32) BINARY 0 0 0}}
    1.56 +  4  {main abc2 b}               {0 {VARCHAR(32) BINARY 0 0 0}}
    1.57 +  5  {{} abc2 a}                 {0 {{} NOCASE 0 1 0}}
    1.58 +  6  {{} abc3 a}                 {0 {{} BINARY 1 0 0}}
    1.59 +  7  {{} abc3 b}                 {0 {INTEGER BINARY 0 1 0}}
    1.60 +  13 {main abc rowid}            {0 {INTEGER BINARY 0 1 0}}
    1.61 +  14 {main abc3 rowid}           {0 {INTEGER BINARY 0 1 0}}
    1.62 +  16 {main abc d}                {1 {no such table column: abc.d}}
    1.63 +}
    1.64 +ifcapable view {
    1.65 +  set tests [concat $tests {
    1.66 +    8  {{} abc4 b}                 {0 {INTEGER BINARY 0 1 1}}
    1.67 +    15 {main abc4 rowid}           {0 {INTEGER BINARY 0 1 1}}
    1.68 +  }]
    1.69 +}
    1.70 +ifcapable view {
    1.71 +  set tests [concat $tests {
    1.72 +    9  {{} v1 a}                   {1 {no such table column: v1.a}}
    1.73 +    10 {main v1 b}                 {1 {no such table column: v1.b}}
    1.74 +    11 {main v1 badname}           {1 {no such table column: v1.badname}}
    1.75 +    12 {main v1 rowid}             {1 {no such table column: v1.rowid}}
    1.76 +  }]
    1.77 +}
    1.78 +
    1.79 +foreach {tn params results} $tests {
    1.80 +  set ::DB [sqlite3_connection_pointer db]
    1.81 +
    1.82 +  set tstbody [concat sqlite3_table_column_metadata $::DB $params] 
    1.83 +  do_test colmeta-$tn.1 {
    1.84 +    list [catch $tstbody msg] [set msg]
    1.85 +  } $results
    1.86 +
    1.87 +  db close
    1.88 +  sqlite3 db test.db
    1.89 +
    1.90 +  set ::DB [sqlite3_connection_pointer db]
    1.91 +  set tstbody [concat sqlite3_table_column_metadata $::DB $params] 
    1.92 +  do_test colmeta-$tn.2 {
    1.93 +    list [catch $tstbody msg] [set msg]
    1.94 +  } $results
    1.95 +}
    1.96 +
    1.97 +finish_test