quote.test 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 SQLite library. The
  12. # focus of this file is the ability to specify table and column names
  13. # as quoted strings.
  14. #
  15. # $Id: quote.test,v 1.3 2002/05/21 13:43:04 drh Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # Create a table with a strange name and with strange column names.
  19. #
  20. do_test quote-1.0 {
  21. set r [catch {
  22. execsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );}
  23. } msg]
  24. lappend r $msg
  25. } {0 {}}
  26. # Insert, update and query the table.
  27. #
  28. do_test quote-1.1 {
  29. set r [catch {
  30. execsql {INSERT INTO '@abc' VALUES(5,'hello')}
  31. } msg]
  32. lappend r $msg
  33. } {0 {}}
  34. do_test quote-1.2 {
  35. set r [catch {
  36. execsql {SELECT * FROM '@abc'}
  37. } msg ]
  38. lappend r $msg
  39. } {0 {5 hello}}
  40. do_test quote-1.3 {
  41. set r [catch {
  42. execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
  43. } msg ]
  44. lappend r $msg
  45. } {0 {hello 10}}
  46. do_test quote-1.3.1 {
  47. catchsql {
  48. SELECT '!pqr', '#xyz'+5 FROM '@abc'
  49. }
  50. } {0 {!pqr 5}}
  51. do_test quote-1.3.2 {
  52. catchsql {
  53. SELECT "!pqr", "#xyz"+5 FROM '@abc'
  54. }
  55. } {0 {hello 10}}
  56. do_test quote-1.3 {
  57. set r [catch {
  58. execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
  59. } msg ]
  60. lappend r $msg
  61. } {0 {hello 10}}
  62. do_test quote-1.4 {
  63. set r [catch {
  64. execsql {UPDATE '@abc' SET '#xyz'=11}
  65. } msg ]
  66. lappend r $msg
  67. } {0 {}}
  68. do_test quote-1.5 {
  69. set r [catch {
  70. execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
  71. } msg ]
  72. lappend r $msg
  73. } {0 {hello 16}}
  74. # Drop the table with the strange name.
  75. #
  76. do_test quote-1.6 {
  77. set r [catch {
  78. execsql {DROP TABLE '@abc'}
  79. } msg ]
  80. lappend r $msg
  81. } {0 {}}
  82. finish_test