colmeta.test 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.4 2008/01/23 12:52:41 drh Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. ifcapable !columnmetadata {
  19. finish_test
  20. return
  21. }
  22. # Set up a schema in the main and temp test databases.
  23. do_test colmeta-0 {
  24. execsql {
  25. CREATE TABLE abc(a, b, c);
  26. CREATE TABLE abc2(a PRIMARY KEY COLLATE NOCASE, b VARCHAR(32), c);
  27. CREATE TABLE abc3(a NOT NULL, b INTEGER PRIMARY KEY, c);
  28. }
  29. ifcapable autoinc {
  30. execsql {
  31. CREATE TABLE abc4(a, b INTEGER PRIMARY KEY AUTOINCREMENT, c);
  32. }
  33. }
  34. ifcapable view {
  35. execsql {
  36. CREATE VIEW v1 AS SELECT * FROM abc2;
  37. }
  38. }
  39. } {}
  40. # Return values are of the form:
  41. #
  42. # {<decl-type> <collation> <not null> <primary key> <auto increment>}
  43. #
  44. set tests {
  45. 1 {main abc a} {0 {{} BINARY 0 0 0}}
  46. 2 {{} abc a} {0 {{} BINARY 0 0 0}}
  47. 3 {{} abc2 b} {0 {VARCHAR(32) BINARY 0 0 0}}
  48. 4 {main abc2 b} {0 {VARCHAR(32) BINARY 0 0 0}}
  49. 5 {{} abc2 a} {0 {{} NOCASE 0 1 0}}
  50. 6 {{} abc3 a} {0 {{} BINARY 1 0 0}}
  51. 7 {{} abc3 b} {0 {INTEGER BINARY 0 1 0}}
  52. 13 {main abc rowid} {0 {INTEGER BINARY 0 1 0}}
  53. 14 {main abc3 rowid} {0 {INTEGER BINARY 0 1 0}}
  54. 16 {main abc d} {1 {no such table column: abc.d}}
  55. }
  56. ifcapable view {
  57. set tests [concat $tests {
  58. 8 {{} abc4 b} {0 {INTEGER BINARY 0 1 1}}
  59. 15 {main abc4 rowid} {0 {INTEGER BINARY 0 1 1}}
  60. }]
  61. }
  62. ifcapable view {
  63. set tests [concat $tests {
  64. 9 {{} v1 a} {1 {no such table column: v1.a}}
  65. 10 {main v1 b} {1 {no such table column: v1.b}}
  66. 11 {main v1 badname} {1 {no such table column: v1.badname}}
  67. 12 {main v1 rowid} {1 {no such table column: v1.rowid}}
  68. }]
  69. }
  70. foreach {tn params results} $tests {
  71. set ::DB [sqlite3_connection_pointer db]
  72. set tstbody [concat sqlite3_table_column_metadata $::DB $params]
  73. do_test colmeta-$tn.1 {
  74. list [catch $tstbody msg] [set msg]
  75. } $results
  76. db close
  77. sqlite3 db test.db
  78. set ::DB [sqlite3_connection_pointer db]
  79. set tstbody [concat sqlite3_table_column_metadata $::DB $params]
  80. do_test colmeta-$tn.2 {
  81. list [catch $tstbody msg] [set msg]
  82. } $results
  83. }
  84. finish_test