drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 1 | # 2001 September 15 |
drh | 87c40e8 | 2001-07-23 14:33:02 +0000 | [diff] [blame] | 2 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
drh | 87c40e8 | 2001-07-23 14:33:02 +0000 | [diff] [blame] | 5 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 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. |
drh | 87c40e8 | 2001-07-23 14:33:02 +0000 | [diff] [blame] | 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 | # |
drh | b556ce1 | 2007-04-25 11:32:30 +0000 | [diff] [blame] | 15 | # $Id: quote.test,v 1.7 2007/04/25 11:32:30 drh Exp $ |
drh | 87c40e8 | 2001-07-23 14:33:02 +0000 | [diff] [blame] | 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
| 19 | |
| 20 | # Create a table with a strange name and with strange column names. |
| 21 | # |
| 22 | do_test quote-1.0 { |
drh | 3d94662 | 2005-08-13 18:15:42 +0000 | [diff] [blame] | 23 | catchsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );} |
drh | 87c40e8 | 2001-07-23 14:33:02 +0000 | [diff] [blame] | 24 | } {0 {}} |
| 25 | |
| 26 | # Insert, update and query the table. |
| 27 | # |
| 28 | do_test quote-1.1 { |
drh | 3d94662 | 2005-08-13 18:15:42 +0000 | [diff] [blame] | 29 | catchsql {INSERT INTO '@abc' VALUES(5,'hello')} |
drh | 87c40e8 | 2001-07-23 14:33:02 +0000 | [diff] [blame] | 30 | } {0 {}} |
drh | 3d94662 | 2005-08-13 18:15:42 +0000 | [diff] [blame] | 31 | do_test quote-1.2.1 { |
| 32 | catchsql {SELECT * FROM '@abc'} |
| 33 | } {0 {5 hello}} |
| 34 | do_test quote-1.2.2 { |
| 35 | catchsql {SELECT * FROM [@abc]} ;# SqlServer compatibility |
| 36 | } {0 {5 hello}} |
| 37 | do_test quote-1.2.3 { |
| 38 | catchsql {SELECT * FROM `@abc`} ;# MySQL compatibility |
drh | 87c40e8 | 2001-07-23 14:33:02 +0000 | [diff] [blame] | 39 | } {0 {5 hello}} |
| 40 | do_test quote-1.3 { |
drh | 3d94662 | 2005-08-13 18:15:42 +0000 | [diff] [blame] | 41 | catchsql { |
| 42 | SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc' |
| 43 | } |
drh | 87c40e8 | 2001-07-23 14:33:02 +0000 | [diff] [blame] | 44 | } {0 {hello 10}} |
drh | 2398937 | 2002-05-21 13:43:04 +0000 | [diff] [blame] | 45 | do_test quote-1.3.1 { |
| 46 | catchsql { |
| 47 | SELECT '!pqr', '#xyz'+5 FROM '@abc' |
| 48 | } |
drh | 8df447f | 2005-11-01 15:48:24 +0000 | [diff] [blame] | 49 | } {0 {!pqr 5}} |
drh | 2398937 | 2002-05-21 13:43:04 +0000 | [diff] [blame] | 50 | do_test quote-1.3.2 { |
| 51 | catchsql { |
| 52 | SELECT "!pqr", "#xyz"+5 FROM '@abc' |
| 53 | } |
| 54 | } {0 {hello 10}} |
drh | 3d94662 | 2005-08-13 18:15:42 +0000 | [diff] [blame] | 55 | do_test quote-1.3.3 { |
| 56 | catchsql { |
| 57 | SELECT [!pqr], `#xyz`+5 FROM '@abc' |
| 58 | } |
| 59 | } {0 {hello 10}} |
drh | b556ce1 | 2007-04-25 11:32:30 +0000 | [diff] [blame] | 60 | do_test quote-1.3.4 { |
drh | 2398937 | 2002-05-21 13:43:04 +0000 | [diff] [blame] | 61 | set r [catch { |
| 62 | execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'} |
| 63 | } msg ] |
| 64 | lappend r $msg |
| 65 | } {0 {hello 10}} |
drh | 87c40e8 | 2001-07-23 14:33:02 +0000 | [diff] [blame] | 66 | do_test quote-1.4 { |
| 67 | set r [catch { |
| 68 | execsql {UPDATE '@abc' SET '#xyz'=11} |
| 69 | } msg ] |
| 70 | lappend r $msg |
| 71 | } {0 {}} |
| 72 | do_test quote-1.5 { |
| 73 | set r [catch { |
| 74 | execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'} |
| 75 | } msg ] |
| 76 | lappend r $msg |
| 77 | } {0 {hello 16}} |
| 78 | |
| 79 | # Drop the table with the strange name. |
| 80 | # |
| 81 | do_test quote-1.6 { |
| 82 | set r [catch { |
| 83 | execsql {DROP TABLE '@abc'} |
| 84 | } msg ] |
| 85 | lappend r $msg |
| 86 | } {0 {}} |
| 87 | |
| 88 | |
| 89 | finish_test |