quote.test 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.7 2007/04/25 11:32:30 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. catchsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );}
  22. } {0 {}}
  23. # Insert, update and query the table.
  24. #
  25. do_test quote-1.1 {
  26. catchsql {INSERT INTO '@abc' VALUES(5,'hello')}
  27. } {0 {}}
  28. do_test quote-1.2.1 {
  29. catchsql {SELECT * FROM '@abc'}
  30. } {0 {5 hello}}
  31. do_test quote-1.2.2 {
  32. catchsql {SELECT * FROM [@abc]} ;# SqlServer compatibility
  33. } {0 {5 hello}}
  34. do_test quote-1.2.3 {
  35. catchsql {SELECT * FROM `@abc`} ;# MySQL compatibility
  36. } {0 {5 hello}}
  37. do_test quote-1.3 {
  38. catchsql {
  39. SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'
  40. }
  41. } {0 {hello 10}}
  42. do_test quote-1.3.1 {
  43. catchsql {
  44. SELECT '!pqr', '#xyz'+5 FROM '@abc'
  45. }
  46. } {0 {!pqr 5}}
  47. do_test quote-1.3.2 {
  48. catchsql {
  49. SELECT "!pqr", "#xyz"+5 FROM '@abc'
  50. }
  51. } {0 {hello 10}}
  52. do_test quote-1.3.3 {
  53. catchsql {
  54. SELECT [!pqr], `#xyz`+5 FROM '@abc'
  55. }
  56. } {0 {hello 10}}
  57. do_test quote-1.3.4 {
  58. set r [catch {
  59. execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
  60. } msg ]
  61. lappend r $msg
  62. } {0 {hello 10}}
  63. do_test quote-1.4 {
  64. set r [catch {
  65. execsql {UPDATE '@abc' SET '#xyz'=11}
  66. } msg ]
  67. lappend r $msg
  68. } {0 {}}
  69. do_test quote-1.5 {
  70. set r [catch {
  71. execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
  72. } msg ]
  73. lappend r $msg
  74. } {0 {hello 16}}
  75. # Drop the table with the strange name.
  76. #
  77. do_test quote-1.6 {
  78. set r [catch {
  79. execsql {DROP TABLE '@abc'}
  80. } msg ]
  81. lappend r $msg
  82. } {0 {}}
  83. finish_test