/ Check-in [a2ead8aa]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a problem with renaming a table that starts with "sqlite". Fix for ticket [f00d7b65].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a2ead8aa4517b63cda7bf84464326e9cb5e228224caa603568c0e04ea44e6588
User & Date: dan 2019-04-19 16:34:22
Context
2019-04-19
17:26
Improved optimization of the AND and OR operators. check-in: 0fbd154e user: drh tags: trunk
16:34
Fix a problem with renaming a table that starts with "sqlite". Fix for ticket [f00d7b65]. check-in: a2ead8aa user: dan tags: trunk
16:21
Use macros to determine if an expression is always true or always false. check-in: 6de980a0 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

    50     50   ** statement to ensure that the operation has not rendered any schema
    51     51   ** objects unusable.
    52     52   */
    53     53   static void renameTestSchema(Parse *pParse, const char *zDb, int bTemp){
    54     54     sqlite3NestedParse(pParse, 
    55     55         "SELECT 1 "
    56     56         "FROM \"%w\".%s "
    57         -      "WHERE name NOT LIKE 'sqlite_%%'"
           57  +      "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
    58     58         " AND sql NOT LIKE 'create virtual%%'"
    59     59         " AND sqlite_rename_test(%Q, sql, type, name, %d)=NULL ",
    60     60         zDb, MASTER_NAME, 
    61     61         zDb, bTemp
    62     62     );
    63     63   
    64     64     if( bTemp==0 ){
    65     65       sqlite3NestedParse(pParse, 
    66     66           "SELECT 1 "
    67     67           "FROM temp.%s "
    68         -        "WHERE name NOT LIKE 'sqlite_%%'"
           68  +        "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
    69     69           " AND sql NOT LIKE 'create virtual%%'"
    70     70           " AND sqlite_rename_test(%Q, sql, type, name, 1)=NULL ",
    71     71           MASTER_NAME, zDb 
    72     72       );
    73     73     }
    74     74   }
    75     75   
................................................................................
   182    182   
   183    183     /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
   184    184     ** the schema to use the new table name.  */
   185    185     sqlite3NestedParse(pParse, 
   186    186         "UPDATE \"%w\".%s SET "
   187    187         "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) "
   188    188         "WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)"
   189         -      "AND   name NOT LIKE 'sqlite_%%'"
          189  +      "AND   name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
   190    190         , zDb, MASTER_NAME, zDb, zTabName, zName, (iDb==1), zTabName
   191    191     );
   192    192   
   193    193     /* Update the tbl_name and name columns of the sqlite_master table
   194    194     ** as required.  */
   195    195     sqlite3NestedParse(pParse,
   196    196         "UPDATE %Q.%s SET "
   197    197             "tbl_name = %Q, "
   198    198             "name = CASE "
   199    199               "WHEN type='table' THEN %Q "
   200         -            "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
          200  +            "WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' "
          201  +            "     AND type='index' THEN "
   201    202                "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
   202    203               "ELSE name END "
   203    204         "WHERE tbl_name=%Q COLLATE nocase AND "
   204    205             "(type='table' OR type='index' OR type='trigger');", 
   205    206         zDb, MASTER_NAME, 
   206    207         zName, zName, zName, 
   207    208         nTabName, zTabName
................................................................................
   567    568     zNew = sqlite3NameFromToken(db, pNew);
   568    569     if( !zNew ) goto exit_rename_column;
   569    570     assert( pNew->n>0 );
   570    571     bQuote = sqlite3Isquote(pNew->z[0]);
   571    572     sqlite3NestedParse(pParse, 
   572    573         "UPDATE \"%w\".%s SET "
   573    574         "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
   574         -      "WHERE name NOT LIKE 'sqlite_%%' AND (type != 'index' OR tbl_name = %Q)"
          575  +      "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
          576  +      " AND (type != 'index' OR tbl_name = %Q)"
   575    577         " AND sql NOT LIKE 'create virtual%%'",
   576    578         zDb, MASTER_NAME, 
   577    579         zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1,
   578    580         pTab->zName
   579    581     );
   580    582   
   581    583     sqlite3NestedParse(pParse, 

Changes to test/altertab.test.

   554    554       ALTER TABLE y1 RENAME TO z1;
   555    555     }
   556    556   
   557    557     do_execsql_test 16.4 {
   558    558       SELECT * FROM z1_segments;
   559    559     }
   560    560   }
          561  +
          562  +#-------------------------------------------------------------------------
          563  +reset_db
          564  +do_execsql_test 17.0 {
          565  +  CREATE TABLE sqlite1234 (id integer);
          566  +  ALTER TABLE sqlite1234 RENAME TO User;
          567  +  SELECT name, sql FROM sqlite_master WHERE sql IS NOT NULL;
          568  +} {
          569  +  User {CREATE TABLE "User" (id integer)}
          570  +}
   561    571   
   562    572   finish_test