]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the Oracle and MS-Sql command-line terminator logic in the CLI.
authordrh <drh@noemail.net>
Thu, 18 Dec 2008 22:25:13 +0000 (22:25 +0000)
committerdrh <drh@noemail.net>
Thu, 18 Dec 2008 22:25:13 +0000 (22:25 +0000)
Ticket #3544. (CVS 6041)

FossilOrigin-Name: dcc8935fa0ccf86648c22818823bf1daef8f3939

manifest
manifest.uuid
src/shell.c

index 2cda36e9ed9e2cf1c8b0268e245928790228e790..dcc330ee32df65ab664e869be168a3d0918d078a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Increase\stest\scoverage\sof\snew\ssavepoint\scode.\s(CVS\s6040)
-D 2008-12-18T18:31:39
+C Fix\sthe\sOracle\sand\sMS-Sql\scommand-line\sterminator\slogic\sin\sthe\sCLI.\nTicket\s#3544.\s(CVS\s6041)
+D 2008-12-18T22:25:14
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in f7e4c81c347b04f7b0f1c1b081a168645d7b8af7
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -154,7 +154,7 @@ F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
 F src/resolve.c 18dc9f0df1d60048e012ce6632251063e0dd356a
 F src/rowset.c 2256fa4a928f750e2f3d6fc733523034beceb1d6
 F src/select.c a4316c5e8a417687e159b3d3ae689363d1dec5df
-F src/shell.c 60638e2fdfe97f1eb9c18caf87d3744d8269d012
+F src/shell.c 65d19f8996a160f288087e31810f24025439c62a
 F src/sqlite.h.in 065a828e299960316aa34f05b9f0f10f33afe4c8
 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
 F src/sqliteInt.h d7f8532c81038b1133d55c68f96afaf93ffb9138
@@ -681,7 +681,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 98a53d91f6c0c2692d3b56687fdaba8eeab0959d
-R 62d8e49e78bd385c3c1bd94a9682f5e4
-U danielk1977
-Z 22b6c1944a6bc7d00fc6f077bed85661
+P d915718d0b346982d686d131a159b67e28fc02a8
+R 5310eca4075c4ebf704f216d6b1c02dc
+U drh
+Z 24e69d5ad73c2571e030bbcae477397b
index a182d096c3a7663affd88ce9c490140b4a89a6be..3f1352e18a6182a340fe5ecfa562155b916b0ea8 100644 (file)
@@ -1 +1 @@
-d915718d0b346982d686d131a159b67e28fc02a8
\ No newline at end of file
+dcc8935fa0ccf86648c22818823bf1daef8f3939
\ No newline at end of file
index 493905032a55f62c79b952e084a93d7c3f77036c..705bae05c6e41b6c94b78663520cafc354f93a99 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains code to implement the "sqlite" command line
 ** utility for accessing SQLite databases.
 **
-** $Id: shell.c,v 1.195 2008/12/11 02:58:27 shane Exp $
+** $Id: shell.c,v 1.196 2008/12/18 22:25:14 drh Exp $
 */
 #if defined(_WIN32) || defined(WIN32)
 /* This needs to come before any includes for MSVC compiler */
@@ -1677,7 +1677,9 @@ static int _all_whitespace(const char *z){
 */
 static int _is_command_terminator(const char *zLine){
   while( isspace(*(unsigned char*)zLine) ){ zLine++; };
-  if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ) return 1;  /* Oracle */
+  if( zLine[0]=='/' && _all_whitespace(&zLine[1]) ){
+    return 1;  /* Oracle */
+  }
   if( tolower(zLine[0])=='g' && tolower(zLine[1])=='o'
          && _all_whitespace(&zLine[2]) ){
     return 1;  /* SQL Server */
@@ -1685,6 +1687,20 @@ static int _is_command_terminator(const char *zLine){
   return 0;
 }
 
+/*
+** Return true if zSql is a complete SQL statement.  Return false if it
+** ends in the middle of a string literal or C-style comment.
+*/
+static int _is_complete(char *zSql, int nSql){
+  int rc;
+  if( zSql==0 ) return 1;
+  zSql[nSql] = ';';
+  zSql[nSql+1] = 0;
+  rc = sqlite3_complete(zSql);
+  zSql[nSql] = 0;
+  return rc;
+}
+
 /*
 ** Read input from *in and process it.  If *in==0 then input
 ** is interactive - the user is typing it it.  Otherwise, input
@@ -1728,7 +1744,7 @@ static int process_input(struct callback_data *p, FILE *in){
       }
       continue;
     }
-    if( _is_command_terminator(zLine) && sqlite3_complete(zSql) ){
+    if( _is_command_terminator(zLine) && _is_complete(zSql, nSql) ){
       memcpy(zLine,";",2);
     }
     nSqlPrior = nSql;
@@ -1737,7 +1753,7 @@ static int process_input(struct callback_data *p, FILE *in){
       for(i=0; zLine[i] && isspace((unsigned char)zLine[i]); i++){}
       if( zLine[i]!=0 ){
         nSql = strlen30(zLine);
-        zSql = malloc( nSql+1 );
+        zSql = malloc( nSql+3 );
         if( zSql==0 ){
           fprintf(stderr, "out of memory\n");
           exit(1);
@@ -1747,7 +1763,7 @@ static int process_input(struct callback_data *p, FILE *in){
       }
     }else{
       int len = strlen30(zLine);
-      zSql = realloc( zSql, nSql + len + 2 );
+      zSql = realloc( zSql, nSql + len + 4 );
       if( zSql==0 ){
         fprintf(stderr,"%s: out of memory!\n", Argv0);
         exit(1);