Two alternative patches, choose whichever you like.

Alternative 1: (IMO, preferred; tested)
Don't lowercase argument of .schema.
With PRAGMA case_sensitive_like = ON, you just need to use right case for table
names.

The author or authors of this code dedicate any and all copyright interest
in this code to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and successors.
We intend this dedication to be an overt act of relinquishment in perpetuity
of all present and future rights to this code under copyright law.

Signed-off-by: Yuriy M. Kaminskiy <yum...@gmail.com>

Index: sqlite3-3.7.8/src/shell.c
===================================================================
--- sqlite3-3.7.8.orig/src/shell.c      2011-10-23 14:00:50.000000000 +0400
+++ sqlite3-3.7.8/src/shell.c   2011-10-23 14:01:14.000000000 +0400
@@ -2018,9 +2018,7 @@ static int do_meta_command(char *zLine,
     data.showHeader = 0;
     data.mode = MODE_Semi;
     if( nArg>1 ){
-      int i;
-      for(i=0; azArg[1][i]; i++) azArg[1][i] = (char)tolower(azArg[1][i]);
-      if( strcmp(azArg[1],"sqlite_master")==0 ){
+      if( sqlite3_strnicmp(azArg[1],"sqlite_master",13+1)==0 ){
         char *new_argv[2], *new_colv[2];
         new_argv[0] = "CREATE TABLE sqlite_master (\n"
                       "  type text,\n"
@@ -2034,7 +2032,7 @@ static int do_meta_command(char *zLine,
         new_colv[1] = 0;
         callback(&data, 1, new_argv, new_colv);
         rc = SQLITE_OK;
-      }else if( strcmp(azArg[1],"sqlite_temp_master")==0 ){
+      }else if( sqlite3_strnicmp(azArg[1],"sqlite_temp_master",18+1)==0 ){
         char *new_argv[2], *new_colv[2];
         new_argv[0] = "CREATE TEMP TABLE sqlite_temp_master (\n"
                       "  type text,\n"
=============================================================================

Alternative 2: (partially tested)
Explicitly use case-insensitive comparison for table/indexes, no matter what
case_sensitive_like is.

Index: sqlite3-3.7.8/src/shell.c
===================================================================
--- sqlite3-3.7.8.orig/src/shell.c      2011-10-23 13:52:44.000000000 +0400
+++ sqlite3-3.7.8/src/shell.c   2011-10-23 13:54:13.000000000 +0400
@@ -1573,16 +1573,18 @@ static int do_meta_command(char *zLine,
     }else{
       int i;
       for(i=1; i<nArg; i++){
+        int j;
+        for(j=0; azArg[i][j]; i++) azArg[i][j] = (char)tolower(azArg[i][j]);
         zShellStatic = azArg[i];
         run_schema_dump_query(p,
           "SELECT name, type, sql FROM sqlite_master "
-          "WHERE tbl_name LIKE shellstatic() AND type=='table'"
+          "WHERE lower(tbl_name) LIKE shellstatic() AND type=='table'"
           "  AND sql NOT NULL", 0);
         run_table_dump_query(p->out, p->db,
           "SELECT sql FROM sqlite_master "
           "WHERE sql NOT NULL"
           "  AND type IN ('index','trigger','view')"
-          "  AND tbl_name LIKE shellstatic()", 0
+          "  AND lower(tbl_name) LIKE shellstatic()", 0
         );
         zShellStatic = 0;
       }
@@ -1790,13 +1792,15 @@ static int do_meta_command(char *zLine,
         callback, &data, &zErrMsg
       );
     }else{
+      int j;
+      for(j=0; azArg[1][j]; i++) azArg[1][j] = (char)tolower(azArg[1][j]);
       zShellStatic = azArg[1];
       rc = sqlite3_exec(p->db,
         "SELECT name FROM sqlite_master "
-        "WHERE type='index' AND tbl_name LIKE shellstatic() "
+        "WHERE type='index' AND lower(tbl_name) LIKE shellstatic() "
         "UNION ALL "
         "SELECT name FROM sqlite_temp_master "
-        "WHERE type='index' AND tbl_name LIKE shellstatic() "
+        "WHERE type='index' AND lower(tbl_name) LIKE shellstatic() "
         "ORDER BY 1",
         callback, &data, &zErrMsg
       );
@@ -2055,7 +2059,7 @@ static int do_meta_command(char *zLine,
           "  (SELECT sql sql, type type, tbl_name tbl_name, name name"
           "     FROM sqlite_master UNION ALL"
           "   SELECT sql, type, tbl_name, name FROM sqlite_temp_master) "
-          "WHERE tbl_name LIKE shellstatic() AND type!='meta' AND sql NOTNULL "
+          "WHERE lower(tbl_name) LIKE shellstatic() AND type!='meta' AND sql
NOTNULL "
           "ORDER BY substr(type,2,1), name",
           callback, &data, &zErrMsg);
         zShellStatic = 0;
@@ -2130,13 +2134,15 @@ static int do_meta_command(char *zLine,
         &azResult, &nRow, 0, &zErrMsg
       );
     }else{
+      int j;
+      for(j=0; azArg[1][j]; i++) azArg[1][j] = (char)tolower(azArg[1][j]);
       zShellStatic = azArg[1];
       rc = sqlite3_get_table(p->db,
         "SELECT name FROM sqlite_master "
-        "WHERE type IN ('table','view') AND name LIKE shellstatic() "
+        "WHERE type IN ('table','view') AND lower(name) LIKE shellstatic() "
         "UNION ALL "
         "SELECT name FROM sqlite_temp_master "
-        "WHERE type IN ('table','view') AND name LIKE shellstatic() "
+        "WHERE type IN ('table','view') AND lower(name) LIKE shellstatic() "
         "ORDER BY 1",
         &azResult, &nRow, 0, &zErrMsg
       );

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to