sl@0: # 2001 September 15 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this file is the ability to specify table and column names sl@0: # as quoted strings. sl@0: # sl@0: # $Id: quote.test,v 1.7 2007/04/25 11:32:30 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # Create a table with a strange name and with strange column names. sl@0: # sl@0: do_test quote-1.0 { sl@0: catchsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );} sl@0: } {0 {}} sl@0: sl@0: # Insert, update and query the table. sl@0: # sl@0: do_test quote-1.1 { sl@0: catchsql {INSERT INTO '@abc' VALUES(5,'hello')} sl@0: } {0 {}} sl@0: do_test quote-1.2.1 { sl@0: catchsql {SELECT * FROM '@abc'} sl@0: } {0 {5 hello}} sl@0: do_test quote-1.2.2 { sl@0: catchsql {SELECT * FROM [@abc]} ;# SqlServer compatibility sl@0: } {0 {5 hello}} sl@0: do_test quote-1.2.3 { sl@0: catchsql {SELECT * FROM `@abc`} ;# MySQL compatibility sl@0: } {0 {5 hello}} sl@0: do_test quote-1.3 { sl@0: catchsql { sl@0: SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc' sl@0: } sl@0: } {0 {hello 10}} sl@0: do_test quote-1.3.1 { sl@0: catchsql { sl@0: SELECT '!pqr', '#xyz'+5 FROM '@abc' sl@0: } sl@0: } {0 {!pqr 5}} sl@0: do_test quote-1.3.2 { sl@0: catchsql { sl@0: SELECT "!pqr", "#xyz"+5 FROM '@abc' sl@0: } sl@0: } {0 {hello 10}} sl@0: do_test quote-1.3.3 { sl@0: catchsql { sl@0: SELECT [!pqr], `#xyz`+5 FROM '@abc' sl@0: } sl@0: } {0 {hello 10}} sl@0: do_test quote-1.3.4 { sl@0: set r [catch { sl@0: execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'} sl@0: } msg ] sl@0: lappend r $msg sl@0: } {0 {hello 10}} sl@0: do_test quote-1.4 { sl@0: set r [catch { sl@0: execsql {UPDATE '@abc' SET '#xyz'=11} sl@0: } msg ] sl@0: lappend r $msg sl@0: } {0 {}} sl@0: do_test quote-1.5 { sl@0: set r [catch { sl@0: execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'} sl@0: } msg ] sl@0: lappend r $msg sl@0: } {0 {hello 16}} sl@0: sl@0: # Drop the table with the strange name. sl@0: # sl@0: do_test quote-1.6 { sl@0: set r [catch { sl@0: execsql {DROP TABLE '@abc'} sl@0: } msg ] sl@0: lappend r $msg sl@0: } {0 {}} sl@0: sl@0: sl@0: finish_test