blob: f13d6f9ee9485e28fd986bba226896fa9cca4d92 [file] [log] [blame]
drhb19a2bc2001-09-16 00:13:26 +00001# 2001 September 15
drh87c40e82001-07-23 14:33:02 +00002#
drhb19a2bc2001-09-16 00:13:26 +00003# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
drh87c40e82001-07-23 14:33:02 +00005#
drhb19a2bc2001-09-16 00:13:26 +00006# 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.
drh87c40e82001-07-23 14:33:02 +00009#
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#
drhb556ce12007-04-25 11:32:30 +000015# $Id: quote.test,v 1.7 2007/04/25 11:32:30 drh Exp $
drh87c40e82001-07-23 14:33:02 +000016
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20# Create a table with a strange name and with strange column names.
21#
22do_test quote-1.0 {
drh3d946622005-08-13 18:15:42 +000023 catchsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );}
drh87c40e82001-07-23 14:33:02 +000024} {0 {}}
25
26# Insert, update and query the table.
27#
28do_test quote-1.1 {
drh3d946622005-08-13 18:15:42 +000029 catchsql {INSERT INTO '@abc' VALUES(5,'hello')}
drh87c40e82001-07-23 14:33:02 +000030} {0 {}}
drh3d946622005-08-13 18:15:42 +000031do_test quote-1.2.1 {
32 catchsql {SELECT * FROM '@abc'}
33} {0 {5 hello}}
34do_test quote-1.2.2 {
35 catchsql {SELECT * FROM [@abc]} ;# SqlServer compatibility
36} {0 {5 hello}}
37do_test quote-1.2.3 {
38 catchsql {SELECT * FROM `@abc`} ;# MySQL compatibility
drh87c40e82001-07-23 14:33:02 +000039} {0 {5 hello}}
40do_test quote-1.3 {
drh3d946622005-08-13 18:15:42 +000041 catchsql {
42 SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'
43 }
drh87c40e82001-07-23 14:33:02 +000044} {0 {hello 10}}
drh23989372002-05-21 13:43:04 +000045do_test quote-1.3.1 {
46 catchsql {
47 SELECT '!pqr', '#xyz'+5 FROM '@abc'
48 }
drh8df447f2005-11-01 15:48:24 +000049} {0 {!pqr 5}}
drh23989372002-05-21 13:43:04 +000050do_test quote-1.3.2 {
51 catchsql {
52 SELECT "!pqr", "#xyz"+5 FROM '@abc'
53 }
54} {0 {hello 10}}
drh3d946622005-08-13 18:15:42 +000055do_test quote-1.3.3 {
56 catchsql {
57 SELECT [!pqr], `#xyz`+5 FROM '@abc'
58 }
59} {0 {hello 10}}
drhb556ce12007-04-25 11:32:30 +000060do_test quote-1.3.4 {
drh23989372002-05-21 13:43:04 +000061 set r [catch {
62 execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
63 } msg ]
64 lappend r $msg
65} {0 {hello 10}}
drh87c40e82001-07-23 14:33:02 +000066do_test quote-1.4 {
67 set r [catch {
68 execsql {UPDATE '@abc' SET '#xyz'=11}
69 } msg ]
70 lappend r $msg
71} {0 {}}
72do_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#
81do_test quote-1.6 {
82 set r [catch {
83 execsql {DROP TABLE '@abc'}
84 } msg ]
85 lappend r $msg
86} {0 {}}
87
88
89finish_test