/ Check-in [43bf7978]
Login

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

Overview
Comment:Fix for an UPDATE on a virtual table when the WHERE clause matches zero rows. Ticket #2244. (CVS 3652)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 43bf797842f00a104f5c5619ad3215edddfc641b
User & Date: danielk1977 2007-02-21 16:52:12
Context
2007-02-21
17:04
Modify the fix for #2244 to avoid using a vdbe label. (CVS 3653) check-in: f7ce74b2 user: danielk1977 tags: trunk
16:52
Fix for an UPDATE on a virtual table when the WHERE clause matches zero rows. Ticket #2244. (CVS 3652) check-in: 43bf7978 user: danielk1977 tags: trunk
16:44
Add comments to the top of keywordhash.h. (CVS 3651) check-in: 0aa9ed5b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/update.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle UPDATE statements.
    14     14   **
    15         -** $Id: update.c,v 1.134 2007/02/07 01:06:53 drh Exp $
           15  +** $Id: update.c,v 1.135 2007/02/21 16:52:12 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   #ifndef SQLITE_OMIT_VIRTUALTABLE
    20     20   /* Forward declaration */
    21     21   static void updateVirtualTable(
    22     22     Parse *pParse,       /* The parsing context */
................................................................................
   564    564     Vdbe *v = pParse->pVdbe;  /* Virtual machine under construction */
   565    565     ExprList *pEList = 0;     /* The result set of the SELECT statement */
   566    566     Select *pSelect = 0;      /* The SELECT statement */
   567    567     Expr *pExpr;              /* Temporary expression */
   568    568     int ephemTab;             /* Table holding the result of the SELECT */
   569    569     int i;                    /* Loop counter */
   570    570     int addr;                 /* Address of top of loop */
          571  +  int iLabel;               /* Vdbe label used by the OP_Rewind op */
   571    572   
   572    573     /* Construct the SELECT statement that will find the new values for
   573    574     ** all updated rows. 
   574    575     */
   575    576     pEList = sqlite3ExprListAppend(0, sqlite3CreateIdExpr("_rowid_"), 0);
   576    577     if( pRowid ){
   577    578       pEList = sqlite3ExprListAppend(pEList, sqlite3ExprDup(pRowid), 0);
................................................................................
   598    599     */
   599    600     sqlite3Select(pParse, pSelect, SRT_Table, ephemTab, 0, 0, 0, 0);
   600    601   
   601    602     /*
   602    603     ** Generate code to scan the ephemeral table and call VDelete and
   603    604     ** VInsert
   604    605     */
   605         -  sqlite3VdbeAddOp(v, OP_Rewind, ephemTab, 0);
          606  +  iLabel = sqlite3VdbeMakeLabel(v);
          607  +  sqlite3VdbeAddOp(v, OP_Rewind, ephemTab, iLabel);
   606    608     addr = sqlite3VdbeCurrentAddr(v);
   607    609     sqlite3VdbeAddOp(v, OP_Column,  ephemTab, 0);
   608    610     if( pRowid ){
   609    611       sqlite3VdbeAddOp(v, OP_Column, ephemTab, 1);
   610    612     }else{
   611    613       sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
   612    614     }
................................................................................
   613    615     for(i=0; i<pTab->nCol; i++){
   614    616       sqlite3VdbeAddOp(v, OP_Column, ephemTab, i+1+(pRowid!=0));
   615    617     }
   616    618     pParse->pVirtualLock = pTab;
   617    619     sqlite3VdbeOp3(v, OP_VUpdate, 0, pTab->nCol+2, 
   618    620                        (const char*)pTab->pVtab, P3_VTAB);
   619    621     sqlite3VdbeAddOp(v, OP_Next, ephemTab, addr);
          622  +  sqlite3VdbeResolveLabel(v, iLabel);
   620    623     sqlite3VdbeAddOp(v, OP_Close, ephemTab, 0);
   621    624   
   622    625     /* Cleanup */
   623    626     sqlite3SelectDelete(pSelect);  
   624    627   }
   625    628   #endif /* SQLITE_OMIT_VIRTUALTABLE */

Changes to test/vtab1.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is creating and dropping virtual tables.
    13     13   #
    14         -# $Id: vtab1.test,v 1.39 2007/01/09 14:01:14 drh Exp $
           14  +# $Id: vtab1.test,v 1.40 2007/02/21 16:52:12 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   ifcapable !vtab||!schema_pragmas {
    20     20     finish_test
    21     21     return
................................................................................
   885    885     }
   886    886   } {0 1}
   887    887   do_test vtab1.11-5 {
   888    888     execsql {
   889    889       SELECT  glob(a,'2') FROM e
   890    890     }
   891    891   } {{2 1} {2 2}}
          892  + 
          893  +# See ticket #2244
          894  +#
          895  +do_test vtab1.2244-1 {
          896  +  execsql {
          897  +    CREATE TABLE t2244(a, b);
          898  +    CREATE VIRTUAL TABLE t2244e USING echo(t2244);
          899  +    INSERT INTO t2244 VALUES('AA', 'BB');
          900  +    INSERT INTO t2244 VALUES('CC', 'DD');
          901  +    SELECT rowid, * FROM t2244e;
          902  +  }
          903  +} {1 AA BB 2 CC DD}
          904  +do_test vtab1.2244-2 {
          905  +  execsql {
          906  +    SELECT * FROM t2244e WHERE rowid = 10;
          907  +  }
          908  +} {}
          909  +do_test vtab1.2244-3 {
          910  +  execsql {
          911  +    UPDATE t2244e SET a = 'hello world' WHERE 0;
          912  +    SELECT rowid, * FROM t2244e;
          913  +  }
          914  +} {1 AA BB 2 CC DD}
   892    915   
   893    916   unset -nocomplain echo_module_begin_fail
   894    917   finish_test