From: drh Date: Sat, 13 Aug 2005 18:15:42 +0000 (+0000) Subject: Provide grave accent quoting of identifiers for MySQL compatibility. X-Git-Tag: version-3.6.10~3568 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3d94662a062a5da6340568b5ad656c3057f053c5;p=thirdparty%2Fsqlite.git Provide grave accent quoting of identifiers for MySQL compatibility. Ticket #1337. (CVS 2591) FossilOrigin-Name: 6b7a4e97528a4e179e0bbae69469cb1a3d1f794b --- diff --git a/manifest b/manifest index 63e30b20f9..46c9fd83ee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Give\sthe\ssame\saccess\spermissions\sto\sjournal\sfiles\sas\sis\sgiven\sto\sdatabases.\s(CVS\s2590) -D 2005-08-13T17:17:02 +C Provide\sgrave\saccent\squoting\sof\sidentifiers\sfor\sMySQL\scompatibility.\nTicket\s#1337.\s(CVS\s2591) +D 2005-08-13T18:15:43 F Makefile.in 22ea9c0fe748f591712d8fe3c6d972c6c173a165 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -73,11 +73,11 @@ F src/test2.c 792f203be69fea88668fa221321194f0a28dfdfa F src/test3.c f4e6a16a602091696619a1171bda25c0e3df49f7 F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f F src/test5.c 64f08b2a50ef371a1bd68ff206829e7b1b9997f5 -F src/tokenize.c 57ec9926612fb9e325b57a141303573bc20c79bf +F src/tokenize.c 0ea99e6d02287d6c46788fd5f97533636667244f F src/trigger.c f51dec15921629591cb98bf2e350018e268b109a F src/update.c a9d2c5f504212d62da1b094476f1389c0e02f83f F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c -F src/util.c 668d31be592753e5b8ea00e69ea8d3eedb29fa22 +F src/util.c f66b47d937bde79d458a18665b67a98dbba5108f F src/vacuum.c 829d9e1a6d7c094b80e0899686670932eafd768c F src/vdbe.c 69f33e22c7d0a64b23fbb69e6da95a1bb6869032 F src/vdbe.h 68e80f65658e7fd85561721f617bdebf8bb84b59 @@ -185,7 +185,7 @@ F test/pragma.test 95ea907adf68459e1be6f310c9ae94d1d59c465b F test/printf.test dc39f7c66db3adfe754b4fc0b97fdd97fa06a9c8 F test/progress.test 16496001da445e6534afb94562c286708316d82f x F test/quick.test a94d12658a2b590c1a5be580bef09bbb04c1266b -F test/quote.test 6d75cf635d93ba2484dc9cb378d88cbae9dc2c62 +F test/quote.test c1ca5e18800455f1c882baf5b0274755a3836549 F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b F test/rollback.test 94cd981ee3a627d9f6466f69dcf1f7dbfe695d7a F test/rowid.test 040a3bef06f970c45f5fcd14b2355f7f4d62f0cf @@ -291,7 +291,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b -P 4f07661279fb11a06b3ddffeda672f077c0d306a -R b836f0b3a75836080ea6277724098755 +P 7961ec0ccbc99d890689013b9602635941f308a6 +R 8fe3c3a40a20fda764293dad136929fd U drh -Z 529dbcca7dd17d3d06b72e71d043be10 +Z 59ce15d25edf70c7b49901f8f0f074fa diff --git a/manifest.uuid b/manifest.uuid index 3b647afb64..1ee2ab737c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7961ec0ccbc99d890689013b9602635941f308a6 \ No newline at end of file +6b7a4e97528a4e179e0bbae69469cb1a3d1f794b \ No newline at end of file diff --git a/src/tokenize.c b/src/tokenize.c index 1dab3c528a..5ab7ec0665 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -15,7 +15,7 @@ ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** -** $Id: tokenize.c,v 1.104 2005/06/22 08:48:06 drh Exp $ +** $Id: tokenize.c,v 1.105 2005/08/13 18:15:43 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -183,7 +183,9 @@ static int getToken(const unsigned char *z, int *tokenType){ *tokenType = TK_BITNOT; return 1; } - case '\'': case '"': { + case '`': + case '\'': + case '"': { int delim = z[0]; for(i=1; (c=z[i])!=0; i++){ if( c==delim ){ @@ -565,6 +567,7 @@ int sqlite3_complete(const char *zSql){ token = tkOTHER; break; } + case '`': /* Grave-accent quoted symbols used by MySQL */ case '"': /* single- and double-quoted strings */ case '\'': { int c = *zSql; diff --git a/src/util.c b/src/util.c index 18b5ada247..80ac674374 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,7 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.141 2005/07/20 14:31:53 drh Exp $ +** $Id: util.c,v 1.142 2005/08/13 18:15:43 drh Exp $ */ #include "sqliteInt.h" #include @@ -470,7 +470,8 @@ void sqlite3Dequote(char *z){ switch( quote ){ case '\'': break; case '"': break; - case '[': quote = ']'; break; + case '`': break; /* For MySQL compatibility */ + case '[': quote = ']'; break; /* For MS SqlServer compatibility */ default: return; } for(i=1, j=0; z[i]; i++){ diff --git a/test/quote.test b/test/quote.test index 14d676e6f0..54df546410 100644 --- a/test/quote.test +++ b/test/quote.test @@ -12,7 +12,7 @@ # focus of this file is the ability to specify table and column names # as quoted strings. # -# $Id: quote.test,v 1.4 2004/08/20 18:34:20 drh Exp $ +# $Id: quote.test,v 1.5 2005/08/13 18:15:43 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -20,31 +20,27 @@ source $testdir/tester.tcl # Create a table with a strange name and with strange column names. # do_test quote-1.0 { - set r [catch { - execsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );} - } msg] - lappend r $msg + catchsql {CREATE TABLE '@abc' ( '#xyz' int, '!pqr' text );} } {0 {}} # Insert, update and query the table. # do_test quote-1.1 { - set r [catch { - execsql {INSERT INTO '@abc' VALUES(5,'hello')} - } msg] - lappend r $msg + catchsql {INSERT INTO '@abc' VALUES(5,'hello')} } {0 {}} -do_test quote-1.2 { - set r [catch { - execsql {SELECT * FROM '@abc'} - } msg ] - lappend r $msg +do_test quote-1.2.1 { + catchsql {SELECT * FROM '@abc'} +} {0 {5 hello}} +do_test quote-1.2.2 { + catchsql {SELECT * FROM [@abc]} ;# SqlServer compatibility +} {0 {5 hello}} +do_test quote-1.2.3 { + catchsql {SELECT * FROM `@abc`} ;# MySQL compatibility } {0 {5 hello}} do_test quote-1.3 { - set r [catch { - execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'} - } msg ] - lappend r $msg + catchsql { + SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc' + } } {0 {hello 10}} do_test quote-1.3.1 { catchsql { @@ -56,6 +52,11 @@ do_test quote-1.3.2 { SELECT "!pqr", "#xyz"+5 FROM '@abc' } } {0 {hello 10}} +do_test quote-1.3.3 { + catchsql { + SELECT [!pqr], `#xyz`+5 FROM '@abc' + } +} {0 {hello 10}} do_test quote-1.3 { set r [catch { execsql {SELECT '@abc'.'!pqr', '@abc'.'#xyz'+5 FROM '@abc'}