/ Check-in [eac2aa7d]
Login

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

Overview
Comment:Ensure b-tree mutexes are always held when sqlite3FindTable() is called. Do not invoke the authorizer callback when parsing schema items as part of ALTER TABLE commands. Fix test script issues.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | alter-table-rename-table
Files: files | file ages | folders
SHA3-256:eac2aa7dce577f1998cc2078dd8ac384070f8acf1ceb565999a5cf719092024e
User & Date: dan 2018-08-31 18:23:53
Context
2018-09-01
15:49
Merge fixes and enhancements from trunk. check-in: 589186c0 user: drh tags: alter-table-rename-table
2018-08-31
18:23
Ensure b-tree mutexes are always held when sqlite3FindTable() is called. Do not invoke the authorizer callback when parsing schema items as part of ALTER TABLE commands. Fix test script issues. check-in: eac2aa7d user: dan tags: alter-table-rename-table
2018-08-30
20:03
Test the schema after renaming a table. Ensure that temp database triggers and views are updated when renaming a column. check-in: f3c27d91 user: dan tags: alter-table-rename-table
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

  1157   1157         sqlite3WalkExprList(pWalker, pUpsert->pUpsertTarget);
  1158   1158         sqlite3WalkExprList(pWalker, pUpsert->pUpsertSet);
  1159   1159         sqlite3WalkExpr(pWalker, pUpsert->pUpsertWhere);
  1160   1160         sqlite3WalkExpr(pWalker, pUpsert->pUpsertTargetWhere);
  1161   1161       }
  1162   1162     }
  1163   1163   }
         1164  +
         1165  +static void renameParseCleanup(Parse *pParse){
         1166  +  sqlite3 *db = pParse->db;
         1167  +  if( pParse->pVdbe ){
         1168  +    sqlite3VdbeFinalize(pParse->pVdbe);
         1169  +  }
         1170  +  sqlite3DeleteTable(db, pParse->pNewTable);
         1171  +  if( pParse->pNewIndex ) sqlite3FreeIndex(db, pParse->pNewIndex);
         1172  +  sqlite3DeleteTrigger(db, pParse->pNewTrigger);
         1173  +  sqlite3DbFree(db, pParse->zErrMsg);
         1174  +  renameTokenFree(db, pParse->pRename);
         1175  +  sqlite3ParserReset(pParse);
         1176  +}
  1164   1177   
  1165   1178   /*
  1166   1179   ** SQL function:
  1167   1180   **
  1168   1181   **     sqlite_rename_column(zSql, iCol, bQuote, zNew, zTable, zOld)
  1169   1182   **
  1170   1183   **   0. zSql:     SQL statement to rewrite
................................................................................
  1204   1217     const char *zTable = (const char*)sqlite3_value_text(argv[4]);
  1205   1218     int iCol = sqlite3_value_int(argv[5]);
  1206   1219     const char *zNew = (const char*)sqlite3_value_text(argv[6]);
  1207   1220     int nNew = sqlite3_value_bytes(argv[6]);
  1208   1221     int bQuote = sqlite3_value_int(argv[7]);
  1209   1222     const char *zOld;
  1210   1223     int bTemp = 0;
  1211         -
  1212   1224     int rc;
  1213   1225     char *zErr = 0;
  1214   1226     Parse sParse;
  1215   1227     Walker sWalker;
  1216   1228     Index *pIdx;
  1217   1229     char *zOut = 0;
  1218         -
  1219   1230     int i;
  1220   1231     Table *pTab;
         1232  +#ifndef SQLITE_OMIT_AUTHORIZATION
         1233  +  sqlite3_xauth xAuth = db->xAuth;
         1234  +#endif
  1221   1235   
  1222   1236     UNUSED_PARAMETER(NotUsed);
  1223   1237     if( zSql==0 ) return;
  1224   1238     if( zTable==0 ) return;
  1225   1239     if( zNew==0 ) return;
  1226   1240     if( iCol<0 ) return;
  1227   1241     sqlite3BtreeEnterAll(db);
................................................................................
  1230   1244       sqlite3BtreeLeaveAll(db);
  1231   1245       return;
  1232   1246     }
  1233   1247     zOld = pTab->aCol[iCol].zName;
  1234   1248     memset(&sCtx, 0, sizeof(sCtx));
  1235   1249     sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
  1236   1250   
         1251  +#ifndef SQLITE_OMIT_AUTHORIZATION
         1252  +  db->xAuth = 0;
         1253  +#endif
  1237   1254     rc = renameParseSql(&sParse, zDb, 0, db, zSql, bTemp);
  1238   1255   
  1239   1256     /* Find tokens that need to be replaced. */
  1240   1257     memset(&sWalker, 0, sizeof(Walker));
  1241   1258     sWalker.pParse = &sParse;
  1242   1259     sWalker.xExprCallback = renameColumnExprCb;
  1243   1260     sWalker.xSelectCallback = renameColumnSelectCb;
................................................................................
  1328   1345       if( sParse.zErrMsg ){
  1329   1346         renameColumnParseError(context, 0, argv[1], argv[2], &sParse);
  1330   1347       }else{
  1331   1348         sqlite3_result_error_code(context, rc);
  1332   1349       }
  1333   1350     }
  1334   1351   
  1335         -  if( sParse.pVdbe ){
  1336         -    sqlite3VdbeFinalize(sParse.pVdbe);
  1337         -  }
  1338         -  sqlite3DeleteTable(db, sParse.pNewTable);
  1339         -  if( sParse.pNewIndex ) sqlite3FreeIndex(db, sParse.pNewIndex);
  1340         -  sqlite3DeleteTrigger(db, sParse.pNewTrigger);
  1341         -  renameTokenFree(db, sParse.pRename);
         1352  +  renameParseCleanup(&sParse);
  1342   1353     renameTokenFree(db, sCtx.pList);
  1343         -  sqlite3DbFree(db, sParse.zErrMsg);
  1344         -  sqlite3ParserReset(&sParse);
         1354  +#ifndef SQLITE_OMIT_AUTHORIZATION
         1355  +  db->xAuth = xAuth;
         1356  +#endif
  1345   1357     sqlite3BtreeLeaveAll(db);
  1346   1358   }
  1347   1359   
  1348   1360   static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
  1349   1361     RenameCtx *p = pWalker->u.pRename;
  1350   1362     if( pExpr->op==TK_COLUMN && p->pTab==pExpr->pTab ){
  1351   1363       renameTokenFind(pWalker->pParse, p, (void*)&pExpr->pTab);
................................................................................
  1373   1385   
  1374   1386   /*
  1375   1387   ** This C function implements an SQL user function that is used by SQL code
  1376   1388   ** generated by the ALTER TABLE ... RENAME command to modify the definition
  1377   1389   ** of any foreign key constraints that use the table being renamed as the 
  1378   1390   ** parent table. It is passed three arguments:
  1379   1391   **
  1380         -**   1) The complete text of the CREATE TABLE statement being modified,
  1381         -**   2) The old name of the table being renamed, and
  1382         -**   3) The new name of the table being renamed.
         1392  +**   0: The database containing the table being renamed.
         1393  +**   1: The complete text of the schema statement being modified,
         1394  +**   2: The old name of the table being renamed, and
         1395  +**   3: The new name of the table being renamed.
         1396  +**   4: True if the schema statement comes from the temp db.
         1397  +**
         1398  +** It returns the new schema statement. For example:
  1383   1399   **
  1384         -** It returns the new CREATE TABLE statement. For example:
  1385         -**
  1386         -**   sqlite_rename_table('CREATE TABLE t1(a REFERENCES t2)', 't2', 't3')
         1400  +** sqlite_rename_table('main', 'CREATE TABLE t1(a REFERENCES t2)','t2','t3',0)
  1387   1401   **       -> 'CREATE TABLE t1(a REFERENCES t3)'
  1388   1402   */
  1389   1403   static void renameTableFunc(
  1390   1404     sqlite3_context *context,
  1391   1405     int NotUsed,
  1392   1406     sqlite3_value **argv
  1393   1407   ){
................................................................................
  1396   1410     char *zResult;
  1397   1411     unsigned char const *zDb = sqlite3_value_text(argv[0]);
  1398   1412     unsigned char const *zInput = sqlite3_value_text(argv[1]);
  1399   1413     unsigned char const *zOld = sqlite3_value_text(argv[2]);
  1400   1414     unsigned char const *zNew = sqlite3_value_text(argv[3]);
  1401   1415     int bTemp = sqlite3_value_int(argv[4]);
  1402   1416   
  1403         -  unsigned const char *z;         /* Pointer to token */
  1404         -  int n;                          /* Length of token z */
  1405         -  int token;                      /* Type of token */
  1406         -
  1407         -  Parse sParse;
  1408         -  int rc;
  1409         -  int bQuote = 1;
  1410         -  RenameCtx sCtx;
  1411         -  Walker sWalker;
  1412         -
  1413         -  if( zInput==0 || zOld==0 || zNew==0 ) return;
  1414         -
  1415         -  memset(&sCtx, 0, sizeof(RenameCtx));
  1416         -  sCtx.pTab = sqlite3FindTable(db, zOld, zDb);
  1417         -  memset(&sWalker, 0, sizeof(Walker));
  1418         -  sWalker.pParse = &sParse;
  1419         -  sWalker.xExprCallback = renameTableExprCb;
  1420         -  sWalker.xSelectCallback = renameTableSelectCb;
  1421         -  sWalker.u.pRename = &sCtx;
  1422         -
  1423         -  sqlite3BtreeEnterAll(db);
  1424         -
  1425         -  rc = renameParseSql(&sParse, zDb, 1, db, zInput, bTemp);
  1426         -
  1427         -  if( rc==SQLITE_OK ){
  1428         -    if( sParse.pNewTable ){
  1429         -      Table *pTab = sParse.pNewTable;
  1430         -
  1431         -      if( pTab->pSelect ){
  1432         -        NameContext sNC;
  1433         -        memset(&sNC, 0, sizeof(sNC));
  1434         -        sNC.pParse = &sParse;
  1435         -
  1436         -        sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC);
  1437         -        if( sParse.nErr ) rc = sParse.rc;
  1438         -        sqlite3WalkSelect(&sWalker, pTab->pSelect);
  1439         -      }else{
  1440         -        /* Modify any FK definitions to point to the new table. */
         1417  +  if( zInput && zOld && zNew ){
         1418  +    unsigned const char *z;         /* Pointer to token */
         1419  +    int n;                          /* Length of token z */
         1420  +    int token;                      /* Type of token */
         1421  +
         1422  +    Parse sParse;
         1423  +    int rc;
         1424  +    int bQuote = 1;
         1425  +    RenameCtx sCtx;
         1426  +    Walker sWalker;
         1427  +
         1428  +#ifndef SQLITE_OMIT_AUTHORIZATION
         1429  +    sqlite3_xauth xAuth = db->xAuth;
         1430  +    db->xAuth = 0;
         1431  +#endif
         1432  +
         1433  +    sqlite3BtreeEnterAll(db);
         1434  +
         1435  +    memset(&sCtx, 0, sizeof(RenameCtx));
         1436  +    sCtx.pTab = sqlite3FindTable(db, zOld, zDb);
         1437  +    memset(&sWalker, 0, sizeof(Walker));
         1438  +    sWalker.pParse = &sParse;
         1439  +    sWalker.xExprCallback = renameTableExprCb;
         1440  +    sWalker.xSelectCallback = renameTableSelectCb;
         1441  +    sWalker.u.pRename = &sCtx;
         1442  +
         1443  +    rc = renameParseSql(&sParse, zDb, 1, db, zInput, bTemp);
         1444  +
         1445  +    if( rc==SQLITE_OK ){
         1446  +      if( sParse.pNewTable ){
         1447  +        Table *pTab = sParse.pNewTable;
         1448  +
         1449  +        if( pTab->pSelect ){
         1450  +          NameContext sNC;
         1451  +          memset(&sNC, 0, sizeof(sNC));
         1452  +          sNC.pParse = &sParse;
         1453  +
         1454  +          sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC);
         1455  +          if( sParse.nErr ) rc = sParse.rc;
         1456  +          sqlite3WalkSelect(&sWalker, pTab->pSelect);
         1457  +        }else{
         1458  +          /* Modify any FK definitions to point to the new table. */
  1441   1459   #ifndef SQLITE_OMIT_FOREIGN_KEY
  1442         -        FKey *pFKey;
  1443         -        for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
  1444         -          if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
  1445         -            renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
         1460  +          FKey *pFKey;
         1461  +          for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
         1462  +            if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
         1463  +              renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
         1464  +            }
  1446   1465             }
  1447         -        }
  1448   1466   #endif
  1449   1467   
  1450         -        /* If this is the table being altered, fix any table refs in CHECK
  1451         -        ** expressions. Also update the name that appears right after the
  1452         -        ** "CREATE [VIRTUAL] TABLE" bit. */
  1453         -        if( sqlite3_stricmp(zOld, pTab->zName)==0 ){
  1454         -          sCtx.pTab = pTab;
  1455         -          sqlite3WalkExprList(&sWalker, pTab->pCheck);
  1456         -          renameTokenFind(&sParse, &sCtx, pTab->zName);
         1468  +          /* If this is the table being altered, fix any table refs in CHECK
         1469  +          ** expressions. Also update the name that appears right after the
         1470  +          ** "CREATE [VIRTUAL] TABLE" bit. */
         1471  +          if( sqlite3_stricmp(zOld, pTab->zName)==0 ){
         1472  +            sCtx.pTab = pTab;
         1473  +            sqlite3WalkExprList(&sWalker, pTab->pCheck);
         1474  +            renameTokenFind(&sParse, &sCtx, pTab->zName);
         1475  +          }
  1457   1476           }
  1458   1477         }
  1459         -    }
  1460   1478   
  1461         -    else if( sParse.pNewIndex ){
  1462         -      renameTokenFind(&sParse, &sCtx, sParse.pNewIndex->zName);
  1463         -      sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere);
  1464         -    }
         1479  +      else if( sParse.pNewIndex ){
         1480  +        renameTokenFind(&sParse, &sCtx, sParse.pNewIndex->zName);
         1481  +        sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere);
         1482  +      }
  1465   1483   
  1466   1484   #ifndef SQLITE_OMIT_TRIGGER
  1467         -    else if( sParse.pNewTrigger ){
  1468         -      Trigger *pTrigger = sParse.pNewTrigger;
  1469         -      TriggerStep *pStep;
  1470         -      if( 0==sqlite3_stricmp(sParse.pNewTrigger->table, zOld) 
  1471         -       && sCtx.pTab->pSchema==pTrigger->pTabSchema
  1472         -      ){
  1473         -        renameTokenFind(&sParse, &sCtx, sParse.pNewTrigger->table);
  1474         -      }
         1485  +      else if( sParse.pNewTrigger ){
         1486  +        Trigger *pTrigger = sParse.pNewTrigger;
         1487  +        TriggerStep *pStep;
         1488  +        if( 0==sqlite3_stricmp(sParse.pNewTrigger->table, zOld) 
         1489  +            && sCtx.pTab->pSchema==pTrigger->pTabSchema
         1490  +          ){
         1491  +          renameTokenFind(&sParse, &sCtx, sParse.pNewTrigger->table);
         1492  +        }
  1475   1493   
  1476         -      rc = renameResolveTrigger(&sParse, bTemp ? 0 : zDb);
  1477         -      if( rc==SQLITE_OK ){
  1478         -        renameWalkTrigger(&sWalker, pTrigger);
  1479         -        for(pStep=pTrigger->step_list; pStep; pStep=pStep->pNext){
  1480         -          if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
  1481         -            renameTokenFind(&sParse, &sCtx, pStep->zTarget);
         1494  +        rc = renameResolveTrigger(&sParse, bTemp ? 0 : zDb);
         1495  +        if( rc==SQLITE_OK ){
         1496  +          renameWalkTrigger(&sWalker, pTrigger);
         1497  +          for(pStep=pTrigger->step_list; pStep; pStep=pStep->pNext){
         1498  +            if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
         1499  +              renameTokenFind(&sParse, &sCtx, pStep->zTarget);
         1500  +            }
  1482   1501             }
  1483   1502           }
  1484   1503         }
         1504  +#endif
         1505  +    }
         1506  +
         1507  +    if( rc==SQLITE_OK ){
         1508  +      rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote);
         1509  +    }
         1510  +    if( rc!=SQLITE_OK ){
         1511  +      sqlite3_result_error_code(context, rc);
  1485   1512       }
         1513  +
         1514  +    renameParseCleanup(&sParse);
         1515  +    renameTokenFree(db, sCtx.pList);
         1516  +    sqlite3BtreeLeaveAll(db);
         1517  +#ifndef SQLITE_OMIT_AUTHORIZATION
         1518  +    db->xAuth = xAuth;
  1486   1519   #endif
  1487   1520     }
  1488   1521   
  1489         -  if( rc==SQLITE_OK ){
  1490         -    rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote);
  1491         -  }
  1492         -
  1493         -  if( rc!=SQLITE_OK ){
  1494         -    sqlite3_result_error_code(context, rc);
  1495         -  }
  1496         -  if( sParse.pVdbe ){
  1497         -    sqlite3VdbeFinalize(sParse.pVdbe);
  1498         -  }
  1499         -  sqlite3DeleteTable(db, sParse.pNewTable);
  1500         -  if( sParse.pNewIndex ) sqlite3FreeIndex(db, sParse.pNewIndex);
  1501         -  sqlite3DeleteTrigger(db, sParse.pNewTrigger);
  1502         -  renameTokenFree(db, sParse.pRename);
  1503         -  renameTokenFree(db, sCtx.pList);
  1504         -  sqlite3DbFree(db, sParse.zErrMsg);
  1505         -  sqlite3ParserReset(&sParse);
  1506         -  sqlite3BtreeLeaveAll(db);
  1507         -
  1508   1522     return;
  1509   1523   }
  1510   1524   
  1511   1525   static void renameTableTest(
  1512   1526     sqlite3_context *context,
  1513   1527     int NotUsed,
  1514   1528     sqlite3_value **argv
................................................................................
  1515   1529   ){
  1516   1530     sqlite3 *db = sqlite3_context_db_handle(context);
  1517   1531     unsigned char const *zDb = sqlite3_value_text(argv[0]);
  1518   1532     unsigned char const *zInput = sqlite3_value_text(argv[1]);
  1519   1533     int bTemp = sqlite3_value_int(argv[4]);
  1520   1534     int rc;
  1521   1535     Parse sParse;
         1536  +
         1537  +#ifndef SQLITE_OMIT_AUTHORIZATION
         1538  +  sqlite3_xauth xAuth = db->xAuth;
         1539  +  db->xAuth = 0;
         1540  +#endif
  1522   1541   
  1523   1542     rc = renameParseSql(&sParse, zDb, 1, db, zInput, bTemp);
  1524   1543     if( rc==SQLITE_OK ){
  1525   1544       if( sParse.pNewTable && sParse.pNewTable->pSelect ){
  1526   1545         NameContext sNC;
  1527   1546         memset(&sNC, 0, sizeof(sNC));
  1528   1547         sNC.pParse = &sParse;
................................................................................
  1534   1553         rc = renameResolveTrigger(&sParse, bTemp ? 0 : zDb);
  1535   1554       }
  1536   1555     }
  1537   1556   
  1538   1557     if( rc!=SQLITE_OK ){
  1539   1558       renameColumnParseError(context, 1, argv[2], argv[3], &sParse);
  1540   1559     }
         1560  +  renameParseCleanup(&sParse);
  1541   1561   
  1542         -  if( sParse.pVdbe ){
  1543         -    sqlite3VdbeFinalize(sParse.pVdbe);
  1544         -  }
  1545         -  sqlite3DeleteTable(db, sParse.pNewTable);
  1546         -  if( sParse.pNewIndex ) sqlite3FreeIndex(db, sParse.pNewIndex);
  1547         -  sqlite3DeleteTrigger(db, sParse.pNewTrigger);
  1548         -  sqlite3DbFree(db, sParse.zErrMsg);
  1549         -  renameTokenFree(db, sParse.pRename);
  1550         -  sqlite3ParserReset(&sParse);
         1562  +#ifndef SQLITE_OMIT_AUTHORIZATION
         1563  +  db->xAuth = xAuth;
         1564  +#endif
  1551   1565   }
  1552   1566   
  1553   1567   /*
  1554   1568   ** Register built-in functions used to help implement ALTER TABLE
  1555   1569   */
  1556   1570   void sqlite3AlterFunctions(void){
  1557   1571     static FuncDef aAlterTableFuncs[] = {

Changes to test/alter.test.

   677    677   do_test alter-8.2 {
   678    678     execsql {
   679    679       SELECT a, sum(b) FROM t2 GROUP BY a;
   680    680     }
   681    681   } {1 18 2 9}
   682    682   
   683    683   #--------------------------------------------------------------------------
   684         -# alter-9.X - Special test: Make sure the sqlite_rename_trigger() and
          684  +# alter-9.X - Special test: Make sure the sqlite_rename_column() and
   685    685   # rename_table() functions do not crash when handed bad input.
   686    686   #
   687         -ifcapable trigger {
   688         -  do_test alter-9.1 {
   689         -    execsql {SELECT SQLITE_RENAME_TRIGGER(0,0)}
   690         -  } {{}}
          687  +do_test alter-9.1 {
          688  +  execsql {SELECT SQLITE_RENAME_COLUMN(0,0,0,0,0,0,0,0)}
          689  +} {{}}
          690  +foreach {tn sql} {
          691  +    1 { SELECT SQLITE_RENAME_TABLE(0,0,0,0,0) }
          692  +    2 { SELECT SQLITE_RENAME_TABLE(10,20,30,40,50) }
          693  +    3 { SELECT SQLITE_RENAME_TABLE('foo', 'foo', 'foo', 'foo', 'foo') }
          694  +} {
          695  +  do_catchsql_test alter-9.2.$tn $sql {1 {SQL logic error}}
   691    696   }
   692         -do_test alter-9.2 {
   693         -  execsql {
   694         -    SELECT SQLITE_RENAME_TABLE(0,0);
   695         -    SELECT SQLITE_RENAME_TABLE(10,20);
   696         -    SELECT SQLITE_RENAME_TABLE('foo', 'foo');
   697         -  }
   698         -} {{} {} {}}
   699    697   
   700    698   #------------------------------------------------------------------------
   701    699   # alter-10.X - Make sure ALTER TABLE works with multi-byte UTF-8 characters 
   702    700   # in the names.
   703    701   #
   704    702   do_test alter-10.1 {
   705    703     execsql "CREATE TABLE xyz(x UNIQUE)"
................................................................................
   871    869     SELECT * FROM t16a ORDER BY a;
   872    870   } {abc 1.25 99 xyzzy cba 5.5 98 fizzle}
   873    871   do_execsql_test alter-16.2 {
   874    872     ALTER TABLE t16a RENAME TO t16a_rn;
   875    873     SELECT * FROM t16a_rn ORDER BY a;
   876    874   } {abc 1.25 99 xyzzy cba 5.5 98 fizzle}
   877    875   
   878         -#-------------------------------------------------------------------------
   879         -# Verify that NULL values into the internal-use-only sqlite_rename_*()
   880         -# functions do not cause problems.
   881         -#
   882         -do_execsql_test alter-17.1 {
   883         -  SELECT sqlite_rename_table('CREATE TABLE xyz(a,b,c)','abc');
   884         -} {{CREATE TABLE "abc"(a,b,c)}}
   885         -do_execsql_test alter-17.2 {
   886         -  SELECT sqlite_rename_table('CREATE TABLE xyz(a,b,c)',NULL);
   887         -} {{CREATE TABLE "(NULL)"(a,b,c)}}
   888         -do_execsql_test alter-17.3 {
   889         -  SELECT sqlite_rename_table(NULL,'abc');
   890         -} {{}}
   891         -do_execsql_test alter-17.4 {
   892         -  SELECT sqlite_rename_trigger('CREATE TRIGGER r1 ON xyz WHEN','abc');
   893         -} {{CREATE TRIGGER r1 ON "abc" WHEN}}
   894         -do_execsql_test alter-17.5 {
   895         -  SELECT sqlite_rename_trigger('CREATE TRIGGER r1 ON xyz WHEN',NULL);
   896         -} {{CREATE TRIGGER r1 ON "(NULL)" WHEN}}
   897         -do_execsql_test alter-17.6 {
   898         -  SELECT sqlite_rename_trigger(NULL,'abc');
   899         -} {{}}
   900         -do_execsql_test alter-17.7 {
   901         -  SELECT sqlite_rename_parent('main', 'CREATE TABLE t1(a REFERENCES "xyzzy")',
   902         -         'xyzzy','lmnop');
   903         -} {{CREATE TABLE t1(a REFERENCES "lmnop")}}
   904         -do_execsql_test alter-17.8 {
   905         -  SELECT sqlite_rename_parent('main', 'CREATE TABLE t1(a REFERENCES "xyzzy")',
   906         -         'xyzzy',NULL);
   907         -} {{}}
   908         -do_execsql_test alter-17.9 {
   909         -  SELECT sqlite_rename_parent('main', 'CREATE TABLE t1(a REFERENCES "xyzzy")',
   910         -         NULL, 'lmnop');
   911         -} {{}}
   912         -do_execsql_test alter-17.10 {
   913         -  SELECT sqlite_rename_parent('main', NULL,'abc','xyz');
   914         -} {{}}
   915         -do_catchsql_test alter-17.11 {
   916         -  SELECT sqlite_rename_parent('main', 'create references ''','abc','xyz');
   917         -} {1 {SQL logic error}}
   918         -do_catchsql_test alter-17.12 {
   919         -  SELECT sqlite_rename_parent('main', 'create references "abc"123" ','abc','xyz');
   920         -} {1 {SQL logic error}}
   921         -do_catchsql_test alter-17.13 {
   922         -  SELECT sqlite_rename_parent('main', "references '''",'abc','xyz');
   923         -} {1 {SQL logic error}}
   924         -
   925    876   finish_test
          877  +

Changes to test/fkey2.test.

   979    979       }
   980    980     } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}}
   981    981     
   982    982     
   983    983     # Test the sqlite_rename_parent() function directly.
   984    984     #
   985    985     proc test_rename_parent {zCreate zOld zNew} {
   986         -    db eval {SELECT sqlite_rename_parent($zCreate, $zOld, $zNew)}
          986  +    db eval {SELECT sqlite_rename_table('main', $zCreate, $zOld, $zNew, 0)}
   987    987     }
   988    988     do_test fkey2-14.2.1.1 {
   989    989       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
   990    990     } {{CREATE TABLE t1(a REFERENCES "t3")}}
   991    991     do_test fkey2-14.2.1.2 {
   992    992       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
   993    993     } {{CREATE TABLE t1(a REFERENCES t2)}}

Changes to test/without_rowid3.test.

   945    945       }
   946    946     } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}}
   947    947     
   948    948     
   949    949     # Test the sqlite_rename_parent() function directly.
   950    950     #
   951    951     proc test_rename_parent {zCreate zOld zNew} {
   952         -    db eval {SELECT sqlite_rename_parent($zCreate, $zOld, $zNew)}
          952  +    db eval {SELECT sqlite_rename_table('main', $zCreate, $zOld, $zNew, 0)}
   953    953     }
   954    954     do_test without_rowid3-14.2.1.1 {
   955    955       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
   956    956     } {{CREATE TABLE t1(a REFERENCES "t3")}}
   957    957     do_test without_rowid3-14.2.1.2 {
   958    958       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
   959    959     } {{CREATE TABLE t1(a REFERENCES t2)}}