/ Check-in [ddee56c9]
Login

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

Overview
Comment:Fix a problem with resolving "db.view.column" references that appear in UPDATE or DELETE statements executed against views.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ddee56c9b2b591b9386b1072c3b3a699f7c1f853
User & Date: dan 2013-03-09 14:40:24
Context
2013-03-09
14:49
Add a test case for the problem fixed by the previous commit. check-in: e899b058 user: dan tags: trunk
14:40
Fix a problem with resolving "db.view.column" references that appear in UPDATE or DELETE statements executed against views. check-in: ddee56c9 user: dan tags: trunk
2013-03-08
18:16
If SQLITE_OMIT_UTF16 is defined, avoid setting the 'enc' field of Schema objects to any value except SQLITE_UTF8. Otherwise, assert() statements may fail or spurious SQLITE_NOMEM errors may be returned at the vdbe level later on. check-in: f2fecfb2 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/delete.c.

    89     89   void sqlite3MaterializeView(
    90     90     Parse *pParse,       /* Parsing context */
    91     91     Table *pView,        /* View definition */
    92     92     Expr *pWhere,        /* Optional WHERE clause to be added */
    93     93     int iCur             /* Cursor number for ephemerial table */
    94     94   ){
    95     95     SelectDest dest;
    96         -  Select *pDup;
           96  +  Select *pSel;
           97  +  SrcList *pFrom;
    97     98     sqlite3 *db = pParse->db;
           99  +  int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
    98    100   
    99         -  pDup = sqlite3SelectDup(db, pView->pSelect, 0);
   100         -  if( pWhere ){
   101         -    SrcList *pFrom;
   102         -    
   103         -    pWhere = sqlite3ExprDup(db, pWhere, 0);
   104         -    pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
   105         -    if( pFrom ){
   106         -      assert( pFrom->nSrc==1 );
   107         -      pFrom->a[0].zAlias = sqlite3DbStrDup(db, pView->zName);
   108         -      pFrom->a[0].pSelect = pDup;
   109         -      assert( pFrom->a[0].pOn==0 );
   110         -      assert( pFrom->a[0].pUsing==0 );
   111         -    }else{
   112         -      sqlite3SelectDelete(db, pDup);
   113         -    }
   114         -    pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
   115         -    if( pDup ) pDup->selFlags |= SF_Materialize;
          101  +  pWhere = sqlite3ExprDup(db, pWhere, 0);
          102  +  pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
          103  +
          104  +  if( pFrom ){
          105  +    assert( pFrom->nSrc==1 );
          106  +    pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
          107  +    pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
          108  +    assert( pFrom->a[0].pOn==0 );
          109  +    assert( pFrom->a[0].pUsing==0 );
   116    110     }
          111  +
          112  +  pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
          113  +  if( pSel ) pSel->selFlags |= SF_Materialize;
          114  +
   117    115     sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
   118         -  sqlite3Select(pParse, pDup, &dest);
   119         -  sqlite3SelectDelete(db, pDup);
          116  +  sqlite3Select(pParse, pSel, &dest);
          117  +  sqlite3SelectDelete(db, pSel);
   120    118   }
   121    119   #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
   122    120   
   123    121   #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
   124    122   /*
   125    123   ** Generate an expression tree to implement the WHERE, ORDER BY,
   126    124   ** and LIMIT/OFFSET portion of DELETE and UPDATE statements.

Changes to test/auth.test.

  2258   2258     }
  2259   2259     set authargs
  2260   2260   } [list \
  2261   2261     SQLITE_UPDATE v1     x  main {} \
  2262   2262     SQLITE_SELECT {}     {} {}   v1 \
  2263   2263     SQLITE_READ   t2     a  main v1 \
  2264   2264     SQLITE_READ   t2     b  main v1 \
  2265         -  SQLITE_SELECT {}     {} {}   {} \
         2265  +  SQLITE_READ   v1     x  main v1 \
         2266  +  SQLITE_READ   v1     x  main v1 \
         2267  +  SQLITE_SELECT {}     {} {} v1   \
  2266   2268     SQLITE_READ   v1     x  main v1 \
  2267   2269     SQLITE_INSERT v1chng {} main r2 \
  2268   2270     SQLITE_READ   v1     x  main r2 \
  2269   2271     SQLITE_READ   v1     x  main r2 \
  2270   2272   ]
  2271   2273   
  2272   2274   do_test auth-4.4 {
................................................................................
  2284   2286     }
  2285   2287     set authargs
  2286   2288   } [list \
  2287   2289     SQLITE_DELETE v1     {} main {} \
  2288   2290     SQLITE_SELECT {}     {} {}   v1 \
  2289   2291     SQLITE_READ   t2     a  main v1 \
  2290   2292     SQLITE_READ   t2     b  main v1 \
  2291         -  SQLITE_SELECT {}     {} {}   {} \
         2293  +  SQLITE_READ   v1     x  main v1 \
         2294  +  SQLITE_READ   v1     x  main v1 \
         2295  +  SQLITE_SELECT {}     {} {} v1   \
  2292   2296     SQLITE_READ   v1     x  main v1 \
  2293   2297     SQLITE_INSERT v1chng {} main r3 \
  2294   2298     SQLITE_READ   v1     x  main r3 \
  2295   2299   ]
  2296   2300   
  2297   2301   } ;# ifcapable view && trigger
  2298   2302