sqlite3_vtab *pVtab, /* Virtual table handle */
const char *zName /* New name of table */
){
- int rc = SQLITE_OK;
- return rc;
+ Fts5Table *pTab = (Fts5Table*)pVtab;
+ return sqlite3Fts5StorageRename(pTab->pStorage, zName);
}
/*
int sqlite3Fts5StorageOpen(Fts5Config*, Fts5Index*, int, Fts5Storage**, char**);
int sqlite3Fts5StorageClose(Fts5Storage *p);
+int sqlite3Fts5StorageRename(Fts5Storage*, const char *zName);
int sqlite3Fts5DropAll(Fts5Config*);
int sqlite3Fts5CreateTable(Fts5Config*, const char*, const char*, int, char **);
return rc;
}
+static void fts5StorageRenameOne(
+ Fts5Config *pConfig, /* Current FTS5 configuration */
+ int *pRc, /* IN/OUT: Error code */
+ const char *zTail, /* Tail of table name e.g. "data", "config" */
+ const char *zName /* New name of FTS5 table */
+){
+ if( *pRc==SQLITE_OK ){
+ *pRc = fts5ExecPrintf(pConfig->db, 0,
+ "ALTER TABLE %Q.'%q_%s' RENAME TO '%q_%s';",
+ pConfig->zDb, pConfig->zName, zTail, zName, zTail
+ );
+ }
+}
+
+int sqlite3Fts5StorageRename(Fts5Storage *pStorage, const char *zName){
+ Fts5Config *pConfig = pStorage->pConfig;
+ int rc = sqlite3Fts5StorageSync(pStorage, 1);
+
+ fts5StorageRenameOne(pConfig, &rc, "data", zName);
+ fts5StorageRenameOne(pConfig, &rc, "config", zName);
+ if( pConfig->bColumnsize ){
+ fts5StorageRenameOne(pConfig, &rc, "docsize", zName);
+ }
+ if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
+ fts5StorageRenameOne(pConfig, &rc, "content", zName);
+ }
+ return rc;
+}
+
/*
** Create the shadow table named zPost, with definition zDefn. Return
** SQLITE_OK if successful, or an SQLite error code otherwise.
--- /dev/null
+# 2015 Jun 10
+#
+# 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.
+#
+#***********************************************************************
+#
+# The tests in this file focus on renaming FTS5 tables using the
+# "ALTER TABLE ... RENAME TO ..." command
+#
+
+source [file join [file dirname [info script]] fts5_common.tcl]
+set testprefix fts5alter
+
+
+#-------------------------------------------------------------------------
+# Test renaming regular, contentless and columnsize=0 FTS5 tables.
+#
+do_execsql_test 1.1.0 {
+ CREATE VIRTUAL TABLE "a x" USING fts5(a, x);
+ INSERT INTO "a x" VALUES('a a a', 'x x x');
+ ALTER TABLE "a x" RENAME TO "x y";
+}
+do_execsql_test 1.1.1 {
+ SELECT * FROM "x y";
+ SELECT rowid FROM "x y" WHERE "x y" MATCH 'a'
+} {{a a a} {x x x} 1}
+
+do_execsql_test 1.2.0 {
+ CREATE VIRTUAL TABLE "one/two" USING fts5(one, columnsize=0);
+ INSERT INTO "one/two"(rowid, one) VALUES(456, 'd d d');
+ ALTER TABLE "one/two" RENAME TO "three/four";
+}
+do_execsql_test 1.2.1 {
+ SELECT * FROM "three/four";
+ SELECT rowid FROM "three/four" WHERE "three/four" MATCH 'd'
+} {{d d d} 456}
+
+do_execsql_test 1.3.0 {
+ CREATE VIRTUAL TABLE t1 USING fts5(val, content='');
+ INSERT INTO t1(rowid, val) VALUES(-1, 'drop table');
+ INSERT INTO t1(rowid, val) VALUES(-2, 'drop view');
+ ALTER TABLE t1 RENAME TO t2;
+}
+do_execsql_test 1.3.1 {
+ SELECT rowid, * FROM t2;
+ SELECT rowid FROM t2 WHERE t2 MATCH 'table'
+} {-2 {} -1 {} -1}
+
+#-------------------------------------------------------------------------
+# Test renaming an FTS5 table within a transaction.
+#
+do_execsql_test 2.1 {
+ CREATE VIRTUAL TABLE zz USING fts5(a);
+ INSERT INTO zz(rowid, a) VALUES(-56, 'a b c');
+ BEGIN;
+ INSERT INTO zz(rowid, a) VALUES(-22, 'a b c');
+ ALTER TABLE zz RENAME TO yy;
+ SELECT rowid FROM yy WHERE yy MATCH 'a + b + c';
+ COMMIT;
+} {-56 -22}
+
+do_execsql_test 2.2 {
+ BEGIN;
+ ALTER TABLE yy RENAME TO ww;
+ INSERT INTO ww(rowid, a) VALUES(-11, 'a b c');
+ SELECT rowid FROM ww WHERE ww MATCH 'a + b + c';
+} {-56 -22 -11}
+
+do_execsql_test 2.3 {
+ ROLLBACK;
+ SELECT rowid FROM yy WHERE yy MATCH 'a + b + c';
+} {-56 -22}
+
+
+finish_test
+
-C Add\sthe\s"columnsize="\soption\sto\sfts5,\ssimilar\sto\sfts4's\s"matchinfo=fts3".
-D 2015-06-09T20:58:39.182
+C Fix\sthe\sfts5\sxRename()\smethod.
+D 2015-06-10T10:45:34.820
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in d272f8755b464f20e02dd7799bfe16794c9574c4
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F ext/fts3/unicode/mkunicode.tcl ed0534dd51efce39878bce33944c6073d37a1e20
F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95
F ext/fts5/extract_api_docs.tcl 55a6d648d516f35d9a1e580ac00de27154e1904a
-F ext/fts5/fts5.c 8af8014b40c382a987998a27f72490b339ce3726
+F ext/fts5/fts5.c 4ce5d0990c61a41155fc014b0066ae6d25a388d3
F ext/fts5/fts5.h 81d1a92fc2b4bd477af7e4e0b38b456f3e199fba
-F ext/fts5/fts5Int.h a6d1c30e1655bd91484cb98661581e35a130b87b
+F ext/fts5/fts5Int.h 21eb91e02ad119e1d92ff100f366a976e12190de
F ext/fts5/fts5_aux.c d53f00f31ad615ca4f139dd8751f9041afa00971
F ext/fts5/fts5_buffer.c be0dc80a9406151b350be27c7ec2956722578771
F ext/fts5/fts5_config.c 6ae691e36f90185896f4db0a819ae2394f880ca1
F ext/fts5/fts5_expr.c 549bda1f7edcf10365fbfbc002bdea1be3c287bb
F ext/fts5/fts5_hash.c c1cfdb2cae0fad00b06fae38a40eaf9261563ccc
F ext/fts5/fts5_index.c 7cea402924cd3d8cd5943a7f9514c9153696571b
-F ext/fts5/fts5_storage.c 684ef9575dd1709c3faacbfd1765e623fb1d0505
+F ext/fts5/fts5_storage.c 7e77d1b2da424283d1d58a77e9a98067dc96f2c7
F ext/fts5/fts5_tcl.c 7ea165878e4ae3598e89acd470a0ee1b5a00e33c
F ext/fts5/fts5_tokenize.c 97251d68d7a6a9415bde1203f9382864dfc1f989
F ext/fts5/fts5_unicode2.c da3cf712f05cd8347c8c5bc00964cc0361c88da9
F ext/fts5/test/fts5aj.test 05b569f5c16ea3098fb1984eec5cf50dbdaae5d8
F ext/fts5/test/fts5ak.test 7b8c5df96df599293f920b7e5521ebc79f647592
F ext/fts5/test/fts5al.test fc60ebeac9d8e366e71309d4c31fa72199d711d7
+F ext/fts5/test/fts5alter.test 3342e7fd58556d2a7e5299a7d9dec62e358028ed
F ext/fts5/test/fts5auto.test caa5bcf917db11944655a2a9bd38c67c520376ca
F ext/fts5/test/fts5aux.test e5631607bbc05ac1c38cf7d691000509aca71ef3
F ext/fts5/test/fts5auxdata.test c69b86092bf1a157172de5f9169731af3403179b
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P e964b5877497b16cf985d3d847e82529bb3fa4a3
-R 26fe69b53869c7d4cebecf3b1c47f607
+P aa12f9d9b79c2f523fd6b00e47bcb66dba09ce0c
+R 92d332093f5da6f2c10bbd12aba6b7b5
U dan
-Z 7aaa26406a2384f1f8538b962eb28bef
+Z 4c307463292fc937d885d935d5d6ac74
-aa12f9d9b79c2f523fd6b00e47bcb66dba09ce0c
\ No newline at end of file
+0f7fd51325875fbf0f1eaca3bbbd170ef99c4208
\ No newline at end of file