diff --git a/ext/fts1/fts1.c b/ext/fts1/fts1.c index 3a4c210719..383b2d7c98 100644 --- a/ext/fts1/fts1.c +++ b/ext/fts1/fts1.c @@ -3262,6 +3262,28 @@ static int fulltextFindFunction( return 0; } +/* +** Rename an fts1 table. +*/ +static int fulltextRename( + sqlite3_vtab *pVtab, + const char *zName +){ + fulltext_vtab *p = (fulltext_vtab *)pVtab; + int rc = SQLITE_NOMEM; + char *zSql = sqlite3_mprintf( + "ALTER TABLE %Q.'%q_content' RENAME TO '%q_content';" + "ALTER TABLE %Q.'%q_term' RENAME TO '%q_term';" + , p->zDb, p->zName, zName + , p->zDb, p->zName, zName + ); + if( zSql ){ + rc = sqlite3_exec(p->db, zSql, 0, 0, 0); + sqlite3_free(zSql); + } + return rc; +} + static const sqlite3_module fulltextModule = { /* iVersion */ 0, /* xCreate */ fulltextCreate, @@ -3282,6 +3304,7 @@ static const sqlite3_module fulltextModule = { /* xCommit */ 0, /* xRollback */ 0, /* xFindFunction */ fulltextFindFunction, + /* xRename */ fulltextRename, }; int sqlite3Fts1Init(sqlite3 *db){ diff --git a/manifest b/manifest index d9fd69c85a..7e63fb4333 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replicates\shttp://www.sqlite.org/cvstrac/chngview?cn=4151\swhich\nmodified\sfts2:\n\nModify\shandling\sof\sSQLITE_SCHEMA\sin\sfts2\scode.\sAn\sSQLITE_SCHEMA\serror\nmay\scause\sSQLite\sto\sreload\sthe\sinternal\sschema,\sdeleting\sand\nrecreating\sv-table\sobjects.\sSo\sthe\ssqlite3_vtab\sstructure\scan\sbe\ndeleted\sout\sfrom\sunder\sa\sv-table\simplementation.\s(CVS\s4183) -D 2007-07-25T00:38:06 +C Implement\sxRename()\sfor\sfts1\sso\sthat\sit\sis\spossible\sto\srename\sfts1\stables.\nSee\shttp://www.sqlite.org/cvstrac/chngview?cn=4143\s(CVS\s4184) +D 2007-07-25T00:56:10 F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -24,7 +24,7 @@ F ext/README.txt 913a7bd3f4837ab14d7e063304181787658b14e1 F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b F ext/fts1/ft_hash.h 1a35e654a235c2c662d3ca0dfc3138ad60b8b7d5 -F ext/fts1/fts1.c 61fa4154f754f79f044c9534d0f52505050b57cc +F ext/fts1/fts1.c d32c32029e07b844cb6f501bd133fcb82d9071b6 F ext/fts1/fts1.h 6060b8f62c1d925ea8356cb1a6598073eb9159a6 F ext/fts1/fts1_hash.c 3196cee866edbebb1c0521e21672e6d599965114 F ext/fts1/fts1_hash.h 957d378355ed29f672cd5add012ce8b088a5e089 @@ -244,6 +244,7 @@ F test/fts1k.test fdf295cb797ba6a2ef81ec41cb98df0ceb2e572c F test/fts1l.test 15c119ed2362b2b28d5300c0540a6a43eab66c36 F test/fts1m.test 2d9ca67b095d49f037a914087cc0a61e89da4f0c F test/fts1n.test a2317dcd27b1d087ee3878b30e0a59c593c98b7a +F test/fts1o.test 81c87d789090daee172f307d9fdafc1e2583d1ce F test/fts1porter.test d86e9c3e0c7f8ff95add6582b4b585fb4e02b96d F test/fts2a.test 473a5c8b473a4e21a8e3fddaed1e59666e0c6ab7 F test/fts2b.test 964abc0236c849c07ca1ae496bb25c268ae94816 @@ -522,7 +523,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 5db25e369a1a4b5a4d87947abdbf25f96fe64807 -R 4f3383b3dfe35035aa76c90af94680b3 +P f9020cffda02923ef45979bb447ec2e232086ad5 +R 113424230958cdea7f4818042b790004 U shess -Z f88d97eea6886d33f533493eb19a7860 +Z d58c62915852491e824945ca31f01cbb diff --git a/manifest.uuid b/manifest.uuid index 7d385f7388..99a90bc83f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9020cffda02923ef45979bb447ec2e232086ad5 \ No newline at end of file +febf75f022b9414fc456ddf274d301f95d61e1b8 \ No newline at end of file diff --git a/test/fts1o.test b/test/fts1o.test new file mode 100644 index 0000000000..6ce7d0f91d --- /dev/null +++ b/test/fts1o.test @@ -0,0 +1,134 @@ +# 2007 July 24 +# +# 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# of this script is testing the FTS1 module rename functionality. Mostly +# copied from fts2o.test. +# +# $Id: fts1o.test,v 1.1 2007/07/25 00:56:10 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS1 is not defined, omit this file. +ifcapable !fts1 { + finish_test + return +} + +db eval { + CREATE VIRTUAL TABLE t1 USING fts2(a, b, c); + INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two'); +} + +#--------------------------------------------------------------------- +# Test that it is possible to rename an fts1 table. +# +do_test fts1o-1.1 { + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} +} {t1 t1_content t1_segments t1_segdir} +do_test fts1o-1.2 { + execsql { ALTER TABLE t1 RENAME to fts_t1; } +} {} +do_test fts1o-1.3 { + execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } +} {1 {one three four}} +do_test fts1o-1.4 { + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} +} {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir} + +# See what happens when renaming the fts1 table fails. +# +do_test fts1o-2.1 { + catchsql { + CREATE TABLE t1_segdir(a, b, c); + ALTER TABLE fts_t1 RENAME to t1; + } +} {1 {SQL logic error or missing database}} +do_test fts1o-2.2 { + execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } +} {1 {one three four}} +do_test fts1o-2.3 { + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} +} {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir} + +# See what happens when renaming the fts1 table fails inside a transaction. +# +do_test fts1o-3.1 { + execsql { + BEGIN; + INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two'); + } +} {} +do_test fts1o-3.2 { + catchsql { + ALTER TABLE fts_t1 RENAME to t1; + } +} {1 {SQL logic error or missing database}} +do_test fts1o-3.3 { + execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } +} {1 {one three four}} +do_test fts1o-3.4 { + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} +} {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir} +do_test fts1o-3.5 { + execsql COMMIT + execsql {SELECT a FROM fts_t1} +} {{one three four} {one two three}} +do_test fts1o-3.6 { + execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; } +} {{one three four} {one four} {one four two}} + +#--------------------------------------------------------------------- +# Test that it is possible to rename an fts1 table in an attached +# database. +# +file delete -force test2.db test2.db-journal + +do_test fts1o-4.1 { + execsql { + DROP TABLE t1_segdir; + ALTER TABLE fts_t1 RENAME to t1; + SELECT a, b, c FROM t1 WHERE c MATCH 'two'; + } +} {{one three four} {one four} {one four two} {one two three} {one four} {one two}} + +do_test fts1o-4.2 { + execsql { + ATTACH 'test2.db' AS aux; + CREATE VIRTUAL TABLE aux.t1 USING fts1(a, b, c); + INSERT INTO aux.t1(a, b, c) VALUES( + 'neung song sahm', 'neung see', 'neung see song' + ); + } +} {} + +do_test fts1o-4.3 { + execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; } +} {{neung song sahm} {neung see} {neung see song}} + +do_test fts1o-4.4 { + execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } +} {{one three four} {one four} {one four two} {one two three} {one four} {one two}} + +do_test fts1o-4.5 { + execsql { ALTER TABLE aux.t1 RENAME TO t2 } +} {} + +do_test fts1o-4.6 { + execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; } +} {{neung song sahm} {neung see} {neung see song}} + +do_test fts1o-4.7 { + execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } +} {{one three four} {one four} {one four two} {one two three} {one four} {one two}} + +finish_test