SQLite

Check-in [d1c875320a]
Login

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

Overview
Comment:Fixes to allow fts3 tables to be renamed mid-transaction.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d1c875320a045c3938c765ceb543dfba1a0ecf0b
User & Date: dan 2010-08-24 16:59:48.000
Context
2010-08-24
18:06
Comment enhancements and typo fixes in pcache1.c. (check-in: c2dc39c0c4 user: drh tags: trunk)
16:59
Fixes to allow fts3 tables to be renamed mid-transaction. (check-in: d1c875320a user: dan tags: trunk)
13:11
Add tests to e_expr.test. (check-in: 5c1c694ee1 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/fts3/fts3.c.
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588



2589
2590
2591
2592
2593
2594
2595
** Implementation of FTS3 xRename method. Rename an fts3 table.
*/
static int fts3RenameMethod(
  sqlite3_vtab *pVtab,            /* Virtual table handle */
  const char *zName               /* New name of table */
){
  Fts3Table *p = (Fts3Table *)pVtab;
  sqlite3 *db;                    /* Database connection */
  int rc;                         /* Return Code */
 
  db = p->db;
  rc = SQLITE_OK;



  fts3DbExec(&rc, db,
    "ALTER TABLE %Q.'%q_content'  RENAME TO '%q_content';",
    p->zDb, p->zName, zName
  );
  if( rc==SQLITE_ERROR ) rc = SQLITE_OK;
  if( p->bHasDocsize ){
    fts3DbExec(&rc, db,







|

|
|
|
>
>
>







2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
** Implementation of FTS3 xRename method. Rename an fts3 table.
*/
static int fts3RenameMethod(
  sqlite3_vtab *pVtab,            /* Virtual table handle */
  const char *zName               /* New name of table */
){
  Fts3Table *p = (Fts3Table *)pVtab;
  sqlite3 *db = p->db;            /* Database connection */
  int rc;                         /* Return Code */

  rc = sqlite3Fts3PendingTermsFlush(p);
  if( rc!=SQLITE_OK ){
    return rc;
  }

  fts3DbExec(&rc, db,
    "ALTER TABLE %Q.'%q_content'  RENAME TO '%q_content';",
    p->zDb, p->zName, zName
  );
  if( rc==SQLITE_ERROR ) rc = SQLITE_OK;
  if( p->bHasDocsize ){
    fts3DbExec(&rc, db,
Changes to src/vdbe.c.
5644
5645
5646
5647
5648
5649
5650

5651
5652
5653
5654
5655
5656
5657
  pVtab = pOp->p4.pVtab->pVtab;
  pName = &aMem[pOp->p1];
  assert( pVtab->pModule->xRename );
  REGISTER_TRACE(pOp->p1, pName);
  assert( pName->flags & MEM_Str );
  rc = pVtab->pModule->xRename(pVtab, pName->z);
  importVtabErrMsg(p, pVtab);


  break;
}
#endif

#ifndef SQLITE_OMIT_VIRTUALTABLE
/* Opcode: VUpdate P1 P2 P3 P4 *







>







5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
  pVtab = pOp->p4.pVtab->pVtab;
  pName = &aMem[pOp->p1];
  assert( pVtab->pModule->xRename );
  REGISTER_TRACE(pOp->p1, pName);
  assert( pName->flags & MEM_Str );
  rc = pVtab->pModule->xRename(pVtab, pName->z);
  importVtabErrMsg(p, pVtab);
  p->expired = 0;

  break;
}
#endif

#ifndef SQLITE_OMIT_VIRTUALTABLE
/* Opcode: VUpdate P1 P2 P3 P4 *
Changes to test/fts3ao.test.
162
163
164
165
166
167
168

































169

  execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; }
} {{neung song sahm} {neung see} {neung see song}}

do_test fts3ao-3.3 {
  execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
} {{one three four} {one four} {one two}}


































finish_test








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
  execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; }
} {{neung song sahm} {neung see} {neung see song}}

do_test fts3ao-3.3 {
  execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
} {{one three four} {one four} {one two}}

#---------------------------------------------------------------------
# Test that it is possible to rename an fts3 table within a 
# transaction.
#
do_test fts3ao-4.1 {
  execsql {
    CREATE VIRTUAL TABLE t4 USING fts3;
    INSERT INTO t4 VALUES('the quick brown fox');
  }
} {}
do_test fts3ao-4.2 {
  execsql {
    BEGIN;
      INSERT INTO t4 VALUES('jumped over the');
  }
} {}
do_test fts3ao-4.3 { execsql { ALTER TABLE t4 RENAME TO t5; } } {}
do_test fts3ao-4.4 { execsql { INSERT INTO t5 VALUES('lazy dog'); } } {}
do_test fts3ao-4.5 { execsql COMMIT } {}
do_test fts3ao-4.6 {
  execsql { SELECT * FROM t5 }
} {{the quick brown fox} {jumped over the} {lazy dog}}
do_test fts3ao-4.7 {
  execsql {
    BEGIN;
      INSERT INTO t5 VALUES('Down came a jumbuck to drink at that billabong');
      ALTER TABLE t5 RENAME TO t6;
      INSERT INTO t6 VALUES('Down came the troopers, one, two, three');
    ROLLBACK;
    SELECT * FROM t5;
  }
} {{the quick brown fox} {jumped over the} {lazy dog}}

finish_test