sl@0
|
1 |
# 2001 September 15
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library. The
|
sl@0
|
12 |
# focus of this file is the ability to specify table and column names
|
sl@0
|
13 |
# as quoted strings.
|
sl@0
|
14 |
#
|
sl@0
|
15 |
# $Id: quote.test,v 1.7 2007/04/25 11:32:30 drh Exp $
|
sl@0
|
16 |
|
sl@0
|
17 |
set testdir [file dirname $argv0]
|
sl@0
|
18 |
source $testdir/tester.tcl
|
sl@0
|
19 |
|
sl@0
|
20 |
# Create a table with a strange name and with strange column names.
|
sl@0
|
21 |
#
|
sl@0
|
22 |
do_test quote-1.0 {
|
sl@0
|
23 |
catchsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );}
|
sl@0
|
24 |
} {0 {}}
|
sl@0
|
25 |
|
sl@0
|
26 |
# Insert, update and query the table.
|
sl@0
|
27 |
#
|
sl@0
|
28 |
do_test quote-1.1 {
|
sl@0
|
29 |
catchsql {INSERT INTO '@abc' VALUES(5,'hello')}
|
sl@0
|
30 |
} {0 {}}
|
sl@0
|
31 |
do_test quote-1.2.1 {
|
sl@0
|
32 |
catchsql {SELECT * FROM '@abc'}
|
sl@0
|
33 |
} {0 {5 hello}}
|
sl@0
|
34 |
do_test quote-1.2.2 {
|
sl@0
|
35 |
catchsql {SELECT * FROM [@abc]} ;# SqlServer compatibility
|
sl@0
|
36 |
} {0 {5 hello}}
|
sl@0
|
37 |
do_test quote-1.2.3 {
|
sl@0
|
38 |
catchsql {SELECT * FROM `@abc`} ;# MySQL compatibility
|
sl@0
|
39 |
} {0 {5 hello}}
|
sl@0
|
40 |
do_test quote-1.3 {
|
sl@0
|
41 |
catchsql {
|
sl@0
|
42 |
SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'
|
sl@0
|
43 |
}
|
sl@0
|
44 |
} {0 {hello 10}}
|
sl@0
|
45 |
do_test quote-1.3.1 {
|
sl@0
|
46 |
catchsql {
|
sl@0
|
47 |
SELECT '!pqr', '#xyz'+5 FROM '@abc'
|
sl@0
|
48 |
}
|
sl@0
|
49 |
} {0 {!pqr 5}}
|
sl@0
|
50 |
do_test quote-1.3.2 {
|
sl@0
|
51 |
catchsql {
|
sl@0
|
52 |
SELECT "!pqr", "#xyz"+5 FROM '@abc'
|
sl@0
|
53 |
}
|
sl@0
|
54 |
} {0 {hello 10}}
|
sl@0
|
55 |
do_test quote-1.3.3 {
|
sl@0
|
56 |
catchsql {
|
sl@0
|
57 |
SELECT [!pqr], `#xyz`+5 FROM '@abc'
|
sl@0
|
58 |
}
|
sl@0
|
59 |
} {0 {hello 10}}
|
sl@0
|
60 |
do_test quote-1.3.4 {
|
sl@0
|
61 |
set r [catch {
|
sl@0
|
62 |
execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
|
sl@0
|
63 |
} msg ]
|
sl@0
|
64 |
lappend r $msg
|
sl@0
|
65 |
} {0 {hello 10}}
|
sl@0
|
66 |
do_test quote-1.4 {
|
sl@0
|
67 |
set r [catch {
|
sl@0
|
68 |
execsql {UPDATE '@abc' SET '#xyz'=11}
|
sl@0
|
69 |
} msg ]
|
sl@0
|
70 |
lappend r $msg
|
sl@0
|
71 |
} {0 {}}
|
sl@0
|
72 |
do_test quote-1.5 {
|
sl@0
|
73 |
set r [catch {
|
sl@0
|
74 |
execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}
|
sl@0
|
75 |
} msg ]
|
sl@0
|
76 |
lappend r $msg
|
sl@0
|
77 |
} {0 {hello 16}}
|
sl@0
|
78 |
|
sl@0
|
79 |
# Drop the table with the strange name.
|
sl@0
|
80 |
#
|
sl@0
|
81 |
do_test quote-1.6 {
|
sl@0
|
82 |
set r [catch {
|
sl@0
|
83 |
execsql {DROP TABLE '@abc'}
|
sl@0
|
84 |
} msg ]
|
sl@0
|
85 |
lappend r $msg
|
sl@0
|
86 |
} {0 {}}
|
sl@0
|
87 |
|
sl@0
|
88 |
|
sl@0
|
89 |
finish_test
|