tclsqlite.test 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # 2001 September 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 TCL interface to the
  12. # SQLite library.
  13. #
  14. # Actually, all tests are based on the TCL interface, so the main
  15. # interface is pretty well tested. This file contains some addition
  16. # tests for fringe issues that the main test suite does not cover.
  17. #
  18. # $Id: tclsqlite.test,v 1.6 2002/04/12 10:09:00 drh Exp $
  19. set testdir [file dirname $argv0]
  20. source $testdir/tester.tcl
  21. # Check the error messages generated by tclsqlite
  22. #
  23. do_test tcl-1.1 {
  24. set v [catch {sqlite bogus} msg]
  25. lappend v $msg
  26. } {1 {wrong # args: should be "sqlite HANDLE FILENAME ?MODE?"}}
  27. do_test tcl-1.2 {
  28. set v [catch {db bogus} msg]
  29. lappend v $msg
  30. } {1 {bad option "bogus": must be busy, changes, close, complete, eval, last_insert_rowid, or timeout}}
  31. do_test tcl-1.3 {
  32. execsql {CREATE TABLE t1(a int, b int)}
  33. execsql {INSERT INTO t1 VALUES(10,20)}
  34. set v [catch {
  35. db eval {SELECT * FROM t1} data {
  36. error "The error message"
  37. }
  38. } msg]
  39. lappend v $msg
  40. } {1 {The error message}}
  41. do_test tcl-1.4 {
  42. set v [catch {
  43. db eval {SELECT * FROM t2} data {
  44. error "The error message"
  45. }
  46. } msg]
  47. lappend v $msg
  48. } {1 {no such table: t2}}
  49. do_test tcl-1.5 {
  50. set v [catch {
  51. db eval {SELECT * FROM t1} data {
  52. break
  53. }
  54. } msg]
  55. lappend v $msg
  56. } {0 {}}
  57. do_test tcl-1.6 {
  58. set v [catch {
  59. db eval {SELECT * FROM t1} data {
  60. expr x*
  61. }
  62. } msg]
  63. regsub {:.*$} $msg {} msg
  64. lappend v $msg
  65. } {1 {syntax error in expression "x*"}}
  66. if {[sqlite -encoding]=="UTF-8" && [sqlite -tcl-uses-utf]} {
  67. do_test tcl-2.1 {
  68. execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)"
  69. execsql "PRAGMA table_info(t\u0123x)"
  70. } "0 a int 0 {} 1 b\u1235 float 0 {}"
  71. do_test tcl-2.2 {
  72. execsql "INSERT INTO t\u0123x VALUES(1,2.3)"
  73. db eval "SELECT * FROM t\u0123x" result break
  74. set result(*)
  75. } "a b\u1235"
  76. }
  77. if {[sqlite -encoding]=="iso8859" && [sqlite -tcl-uses-utf]} {
  78. do_test tcl-2.1 {
  79. execsql "CREATE TABLE t\251x(a int, b\306 float)"
  80. execsql "PRAGMA table_info(t\251x)"
  81. } "0 a int 0 {} 1 b\306 float 0 {}"
  82. do_test tcl-2.2 {
  83. execsql "INSERT INTO t\251x VALUES(1,2.3)"
  84. db eval "SELECT * FROM t\251x" result break
  85. set result(*)
  86. } "a b\306"
  87. }
  88. finish_test