]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
By default, make all "ALTER TABLE RENAME" statements executed within a virtual legacy-alter-table
authordan <dan@noemail.net>
Thu, 20 Sep 2018 17:21:21 +0000 (17:21 +0000)
committerdan <dan@noemail.net>
Thu, 20 Sep 2018 17:21:21 +0000 (17:21 +0000)
table xRename() method exhibit the legacy behaviour.

FossilOrigin-Name: 71947337e98b90debb13b390119bc2a6b39dd41535151b836071ee327a31e45d

manifest
manifest.uuid
src/alter.c
src/vdbe.c
test/altermalloc2.test
test/altertab2.test [new file with mode: 0644]

index fbd12d638d0304bcbafa38e6fe10d00486502d14..8bb18d6bf806f660052258ff800d14a132d31530 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sa\sPRAGMA\sthat\srestores\sthe\slegacy\sALTER\sTABLE\sRENAME\sTO\sbehaviour.
-D 2018-09-20T08:28:01.757
+C By\sdefault,\smake\sall\s"ALTER\sTABLE\sRENAME"\sstatements\sexecuted\swithin\sa\svirtual\ntable\sxRename()\smethod\sexhibit\sthe\slegacy\sbehaviour.
+D 2018-09-20T17:21:21.872
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in 01e95208a78b57d056131382c493c963518f36da4c42b12a97eb324401b3a334
@@ -436,7 +436,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
 F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
 F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
-F src/alter.c 5bca9ae02fb3eb52bb39da57fcbf0af249910f05d268df4797cf32c75173c9ff
+F src/alter.c 70dd115eb1f949f69f61773733dc89d6494915ec6a736f259c7a7de4aeb51726
 F src/analyze.c 3dc6b98cf007b005af89df165c966baaa48e8124f38c87b4d2b276fe7f0b9eb9
 F src/attach.c 4bd5b92633671d3e8ce431153ebb1893b50335818423b5373f3f27969f79769a
 F src/auth.c 32a5bbe3b755169ab6c66311c5225a3cd4f75a46c041f7fb117e0cbb68055114
@@ -573,7 +573,7 @@ F src/upsert.c 0dd81b40206841814d46942a7337786932475f085716042d0cb2fc7791bf8ca4
 F src/utf.c 810fbfebe12359f10bc2a011520a6e10879ab2a163bcb26c74768eab82ea62a5
 F src/util.c d9eb0a6c4aae1b00a7369eadd7ca0bbe946cb4c953b6751aa20d357c2f482157
 F src/vacuum.c 36e7d21a20c0bf6ef4ef7c399d192b5239410b7c4d3c1070fba4e30810d0b855
-F src/vdbe.c 80603eb66708c2f27879912a4e9456900e66491c3409ca5e392109114e8f6337
+F src/vdbe.c 7433ac76608b80b745f57b8544416dc0178db52ce2cc806a10353309e5f781fb
 F src/vdbe.h 5081dcc497777efe5e9ebe7330d283a044a005e4bdda2e2e984f03bf89a0d907
 F src/vdbeInt.h f1f35f70460698d8f5a2bdef1001114babf318e2983a067804e2ae077d8e9827
 F src/vdbeapi.c 2ba821c5929a2769e4b217dd85843479c718b8989d414723ec8af0616a83d611
@@ -607,8 +607,9 @@ F test/alterauth.test 63442ba61ceb0c1eeb63aac1f4f5cebfa509d352276059d27106ae256b
 F test/altercol.test 53fb5e218c9296afc160f2c4fcbeaf42bd0604815d9b3896a7d2eec583ad8704
 F test/alterlegacy.test e7c07d605c2a85e7d1696c89e6bf64dfc932fc6d9320fe8708c8f5fc0b524d41
 F test/altermalloc.test 167a47de41b5c638f5f5c6efb59784002b196fff70f98d9b4ed3cd74a3fb80c9
-F test/altermalloc2.test 0231398534c494401a70a1d06a63d7849cb5b317fcc14228cbdb53039eba7eae
+F test/altermalloc2.test fa7b1c1139ea39b8dec407cf1feb032ca8e0076bd429574969b619175ad0174b
 F test/altertab.test 3b830144c18ae00abd2a27e3d2851c8bb1ee8fe655fa16d8a5971066dc71b58a
+F test/altertab2.test 159fd5f7b23ddc841fe678f579f9b1b8e69f44296f3ff75d1b4c155d37a59832
 F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f
 F test/analyze.test b3a9c67d00e1df7588a5b7be9a0292899f94fe8cac1f94a017277474ca2e59df
 F test/analyze3.test ff62d9029e6deb2c914490c6b00caf7fae47cc85cdc046e4a0d0a4d4b87c71d8
@@ -1768,10 +1769,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 221f3f572ed49d7af69a2e7c88741fa5206ea33ca59ee791eac7698bdd11ca4d
-R 02fc275d8f952db75795f9c11e6b826b
-T *branch * legacy-alter-table
-T *sym-legacy-alter-table *
-T -sym-trunk *
+P 5acad2e92c11c209bedc6ac8a709595e8070eed028ffc82af61499e5ceaa5e2b
+R 8383c830cd4c7d4950233283e48dfa70
 U dan
-Z 90941688fa5331b463302b9846d758b7
+Z 4aaec95aa70166b0f73ffe68586010e1
index 28d3ebfce5b1f94f81a181a9643508a99a7db858..41a08d75badd46c3ec40abe573de98e775c776cc 100644 (file)
@@ -1 +1 @@
-5acad2e92c11c209bedc6ac8a709595e8070eed028ffc82af61499e5ceaa5e2b
\ No newline at end of file
+71947337e98b90debb13b390119bc2a6b39dd41535151b836071ee327a31e45d
\ No newline at end of file
index 5b7f43c66c64ac6c6f8aa9a7985b51dd77b9a41d..6833a8c10bf00ff6b3de3fa052c0fef2a0e1a49f 100644 (file)
@@ -169,20 +169,6 @@ void sqlite3AlterRenameTable(
     goto exit_rename_table;
   }
 
-  /* If this is a virtual table, invoke the xRename() function if
-  ** one is defined. The xRename() callback will modify the names
-  ** of any resources used by the v-table implementation (including other
-  ** SQLite tables) that are identified by the name of the virtual table.
-  */
-#ifndef SQLITE_OMIT_VIRTUALTABLE
-  if( pVTab ){
-    int i = ++pParse->nMem;
-    sqlite3VdbeLoadString(v, i, zName);
-    sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
-    sqlite3MayAbort(pParse);
-  }
-#endif
-
   /* figure out how many UTF-8 characters are in zName */
   zTabName = pTab->zName;
   nTabName = sqlite3Utf8CharLen(zTabName, -1);
@@ -240,6 +226,20 @@ void sqlite3AlterRenameTable(
         , zDb, zTabName, zName, zTabName, zDb, zName);
   }
 
+  /* If this is a virtual table, invoke the xRename() function if
+  ** one is defined. The xRename() callback will modify the names
+  ** of any resources used by the v-table implementation (including other
+  ** SQLite tables) that are identified by the name of the virtual table.
+  */
+#ifndef SQLITE_OMIT_VIRTUALTABLE
+  if( pVTab ){
+    int i = ++pParse->nMem;
+    sqlite3VdbeLoadString(v, i, zName);
+    sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
+    sqlite3MayAbort(pParse);
+  }
+#endif
+
   renameReloadSchema(pParse, iDb);
   renameTestSchema(pParse, zDb, iDb==1);
 
index 0e6d7484b2ff4a3b0c2cf3aba160984a7de395e1..e57a1979755ff879265b146aa54819ff62e99bb4 100644 (file)
@@ -7059,7 +7059,10 @@ case OP_VNext: {   /* jump */
 case OP_VRename: {
   sqlite3_vtab *pVtab;
   Mem *pName;
-
+  int isLegacy;
+  
+  isLegacy = (db->flags & SQLITE_LegacyAlter);
+  db->flags |= SQLITE_LegacyAlter;
   pVtab = pOp->p4.pVtab->pVtab;
   pName = &aMem[pOp->p1];
   assert( pVtab->pModule->xRename );
@@ -7073,6 +7076,7 @@ case OP_VRename: {
   rc = sqlite3VdbeChangeEncoding(pName, SQLITE_UTF8);
   if( rc ) goto abort_due_to_error;
   rc = pVtab->pModule->xRename(pVtab, pName->z);
+  if( isLegacy==0 ) db->flags &= ~SQLITE_LegacyAlter;
   sqlite3VtabImportErrmsg(p, pVtab);
   p->expired = 0;
   if( rc ) goto abort_due_to_error;
index b23d1c7170676c440852fb3ecb90c487261a4d2a..610b3f6bf05d3a3f8a3e2fbca8b1d12191c239e4 100644 (file)
@@ -72,4 +72,30 @@ do_faultsim_test 3 -prep {
 } -test {
   faultsim_test_result {0 {}}
 }
+
+reset_db
+do_execsql_test 4.0 {
+  CREATE TABLE rr(a, b);
+  CREATE VIEW vv AS SELECT * FROM rr;
+
+  CREATE TRIGGER vv1 INSTEAD OF INSERT ON vv BEGIN
+    SELECT 1, 2, 3;
+  END;
+  CREATE TRIGGER tr1 AFTER INSERT ON rr BEGIN
+    INSERT INTO vv VALUES(new.a, new.b);
+  END;
+} {}
+
+faultsim_save_and_close
+do_faultsim_test 4 -faults oom-* -prep {
+  faultsim_restore_and_reopen
+  execsql { SELECT * FROM sqlite_master }
+} -body {
+  execsql {
+    ALTER TABLE rr RENAME a TO c;
+  }
+} -test {
+  faultsim_test_result {0 {}} 
+}
+
 finish_test
diff --git a/test/altertab2.test b/test/altertab2.test
new file mode 100644 (file)
index 0000000..5656def
--- /dev/null
@@ -0,0 +1,46 @@
+# 2018 September 30
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#*************************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix altertab
+
+# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
+ifcapable !altertable {
+  finish_test
+  return
+}
+
+ifcapable fts5 {
+  do_execsql_test 1.0 {
+    CREATE TABLE rr(a, b);
+    CREATE VIRTUAL TABLE ff USING fts5(a, b);
+    CREATE TRIGGER tr1 AFTER INSERT ON rr BEGIN
+      INSERT INTO ff VALUES(new.a, new.b);
+    END;
+    INSERT INTO rr VALUES('hello', 'world');
+    SELECT * FROM ff;
+  } {hello world}
+
+  do_execsql_test 1.1 {
+    ALTER TABLE ff RENAME TO ffff;
+  }
+
+  do_execsql_test 1.2 {
+    INSERT INTO rr VALUES('in', 'tcl');
+    SELECT * FROM ffff;
+  } {hello world in tcl}
+}
+
+
+finish_test
+