/ Check-in [0f7fd513]
Login

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

Overview
Comment:Fix the fts5 xRename() method.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts5
Files: files | file ages | folders
SHA1: 0f7fd51325875fbf0f1eaca3bbbd170ef99c4208
User & Date: dan 2015-06-10 10:45:34
Context
2015-06-23
15:06
Merge latest trunk changes with this branch. Add tests for columnsize=0. check-in: ef44c71a user: dan tags: fts5
2015-06-10
10:45
Fix the fts5 xRename() method. check-in: 0f7fd513 user: dan tags: fts5
2015-06-09
20:58
Add the "columnsize=" option to fts5, similar to fts4's "matchinfo=fts3". check-in: aa12f9d9 user: dan tags: fts5
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5.c.

  1999   1999   /*
  2000   2000   ** Implementation of FTS5 xRename method. Rename an fts5 table.
  2001   2001   */
  2002   2002   static int fts5RenameMethod(
  2003   2003     sqlite3_vtab *pVtab,            /* Virtual table handle */
  2004   2004     const char *zName               /* New name of table */
  2005   2005   ){
  2006         -  int rc = SQLITE_OK;
  2007         -  return rc;
         2006  +  Fts5Table *pTab = (Fts5Table*)pVtab;
         2007  +  return sqlite3Fts5StorageRename(pTab->pStorage, zName);
  2008   2008   }
  2009   2009   
  2010   2010   /*
  2011   2011   ** The xSavepoint() method.
  2012   2012   **
  2013   2013   ** Flush the contents of the pending-terms table to disk.
  2014   2014   */

Changes to ext/fts5/fts5Int.h.

   500    500   #define FTS5_STMT_SCAN_DESC 1     /* SELECT rowid, * FROM ... ORDER BY 1 DESC */
   501    501   #define FTS5_STMT_LOOKUP    2     /* SELECT rowid, * FROM ... WHERE rowid=? */
   502    502   
   503    503   typedef struct Fts5Storage Fts5Storage;
   504    504   
   505    505   int sqlite3Fts5StorageOpen(Fts5Config*, Fts5Index*, int, Fts5Storage**, char**);
   506    506   int sqlite3Fts5StorageClose(Fts5Storage *p);
          507  +int sqlite3Fts5StorageRename(Fts5Storage*, const char *zName);
   507    508   
   508    509   int sqlite3Fts5DropAll(Fts5Config*);
   509    510   int sqlite3Fts5CreateTable(Fts5Config*, const char*, const char*, int, char **);
   510    511   
   511    512   int sqlite3Fts5StorageDelete(Fts5Storage *p, i64);
   512    513   int sqlite3Fts5StorageInsert(Fts5Storage *p, sqlite3_value **apVal, int, i64*);
   513    514   

Changes to ext/fts5/fts5_storage.c.

   193    193       rc = fts5ExecPrintf(pConfig->db, 0, 
   194    194           "DROP TABLE IF EXISTS %Q.'%q_content';",
   195    195           pConfig->zDb, pConfig->zName
   196    196       );
   197    197     }
   198    198     return rc;
   199    199   }
          200  +
          201  +static void fts5StorageRenameOne(
          202  +  Fts5Config *pConfig,            /* Current FTS5 configuration */
          203  +  int *pRc,                       /* IN/OUT: Error code */
          204  +  const char *zTail,              /* Tail of table name e.g. "data", "config" */
          205  +  const char *zName               /* New name of FTS5 table */
          206  +){
          207  +  if( *pRc==SQLITE_OK ){
          208  +    *pRc = fts5ExecPrintf(pConfig->db, 0, 
          209  +        "ALTER TABLE %Q.'%q_%s' RENAME TO '%q_%s';",
          210  +        pConfig->zDb, pConfig->zName, zTail, zName, zTail
          211  +    );
          212  +  }
          213  +}
          214  +
          215  +int sqlite3Fts5StorageRename(Fts5Storage *pStorage, const char *zName){
          216  +  Fts5Config *pConfig = pStorage->pConfig;
          217  +  int rc = sqlite3Fts5StorageSync(pStorage, 1);
          218  +
          219  +  fts5StorageRenameOne(pConfig, &rc, "data", zName);
          220  +  fts5StorageRenameOne(pConfig, &rc, "config", zName);
          221  +  if( pConfig->bColumnsize ){
          222  +    fts5StorageRenameOne(pConfig, &rc, "docsize", zName);
          223  +  }
          224  +  if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
          225  +    fts5StorageRenameOne(pConfig, &rc, "content", zName);
          226  +  }
          227  +  return rc;
          228  +}
   200    229   
   201    230   /*
   202    231   ** Create the shadow table named zPost, with definition zDefn. Return
   203    232   ** SQLITE_OK if successful, or an SQLite error code otherwise.
   204    233   */
   205    234   int sqlite3Fts5CreateTable(
   206    235     Fts5Config *pConfig,            /* FTS5 configuration */

Added ext/fts5/test/fts5alter.test.

            1  +# 2015 Jun 10
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# The tests in this file focus on renaming FTS5 tables using the
           13  +# "ALTER TABLE ... RENAME TO ..." command
           14  +#
           15  +
           16  +source [file join [file dirname [info script]] fts5_common.tcl]
           17  +set testprefix fts5alter
           18  +
           19  +
           20  +#-------------------------------------------------------------------------
           21  +# Test renaming regular, contentless and columnsize=0 FTS5 tables.
           22  +#
           23  +do_execsql_test 1.1.0 {
           24  +  CREATE VIRTUAL TABLE "a x" USING fts5(a, x);
           25  +  INSERT INTO "a x" VALUES('a a a', 'x x x');
           26  +  ALTER TABLE "a x" RENAME TO "x y";
           27  +}
           28  +do_execsql_test 1.1.1 {
           29  +  SELECT * FROM "x y";
           30  +  SELECT rowid FROM "x y" WHERE "x y" MATCH 'a'
           31  +} {{a a a} {x x x} 1}
           32  +
           33  +do_execsql_test 1.2.0 {
           34  +  CREATE VIRTUAL TABLE "one/two" USING fts5(one, columnsize=0);
           35  +  INSERT INTO "one/two"(rowid, one) VALUES(456, 'd d d');
           36  +  ALTER TABLE "one/two" RENAME TO "three/four";
           37  +}
           38  +do_execsql_test 1.2.1 {
           39  +  SELECT * FROM "three/four";
           40  +  SELECT rowid FROM "three/four" WHERE "three/four" MATCH 'd'
           41  +} {{d d d} 456}
           42  +
           43  +do_execsql_test 1.3.0 {
           44  +  CREATE VIRTUAL TABLE t1 USING fts5(val, content='');
           45  +  INSERT INTO t1(rowid, val) VALUES(-1, 'drop table');
           46  +  INSERT INTO t1(rowid, val) VALUES(-2, 'drop view');
           47  +  ALTER TABLE t1 RENAME TO t2;
           48  +}
           49  +do_execsql_test 1.3.1 {
           50  +  SELECT rowid, * FROM t2;
           51  +  SELECT rowid FROM t2 WHERE t2 MATCH 'table'
           52  +} {-2 {} -1 {} -1}
           53  +
           54  +#-------------------------------------------------------------------------
           55  +# Test renaming an FTS5 table within a transaction.
           56  +#
           57  +do_execsql_test 2.1 {
           58  +  CREATE VIRTUAL TABLE zz USING fts5(a);
           59  +  INSERT INTO zz(rowid, a) VALUES(-56, 'a b c');
           60  +  BEGIN;
           61  +    INSERT INTO zz(rowid, a) VALUES(-22, 'a b c');
           62  +    ALTER TABLE zz RENAME TO yy;
           63  +    SELECT rowid FROM yy WHERE yy MATCH 'a + b + c';
           64  +  COMMIT;
           65  +} {-56 -22}
           66  +
           67  +do_execsql_test 2.2 {
           68  +  BEGIN;
           69  +    ALTER TABLE yy RENAME TO ww;
           70  +    INSERT INTO ww(rowid, a) VALUES(-11, 'a b c');
           71  +    SELECT rowid FROM ww WHERE ww MATCH 'a + b + c';
           72  +} {-56 -22 -11}
           73  +
           74  +do_execsql_test 2.3 {
           75  +  ROLLBACK;
           76  +  SELECT rowid FROM yy WHERE yy MATCH 'a + b + c';
           77  +} {-56 -22}
           78  +
           79  +
           80  +finish_test
           81  +