/ Check-in [6c6fb1c6]
Login

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

Overview
Comment:Raise an error if the argument to VACUUM INTO is an identifier.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6c6fb1c6ea452c70b56fd4ac796affebee21512adba0455ae81c291b715f544f
User & Date: drh 2019-01-02 14:34:46
References
2019-01-02
15:27
Add test cases for commit [6c6fb1c6]. check-in: 3961995c user: dan tags: trunk
Context
2019-01-02
15:27
Add test cases for commit [6c6fb1c6]. check-in: 3961995c user: dan tags: trunk
14:34
Raise an error if the argument to VACUUM INTO is an identifier. check-in: 6c6fb1c6 user: drh tags: trunk
2019-01-01
19:17
Fix another fts5 problem caused by a corrupt database. check-in: 911342f7 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/resolve.c.

  1658   1658     w.xSelectCallback2 = 0;
  1659   1659     w.pParse = pParse;
  1660   1660     w.u.pNC = pOuterNC;
  1661   1661     sqlite3WalkSelect(&w, p);
  1662   1662   }
  1663   1663   
  1664   1664   /*
  1665         -** Resolve names in expressions that can only reference a single table:
         1665  +** Resolve names in expressions that can only reference a single table
         1666  +** or which cannot reference any tables at all.  Examples:
  1666   1667   **
  1667         -**    *   CHECK constraints
  1668         -**    *   WHERE clauses on partial indices
         1668  +**    (1)   CHECK constraints
         1669  +**    (2)   WHERE clauses on partial indices
         1670  +**    (3)   Expressions in indexes on expressions
         1671  +**    (4)   Expression arguments to VACUUM INTO.
  1669   1672   **
  1670         -** The Expr.iTable value for Expr.op==TK_COLUMN nodes of the expression
  1671         -** is set to -1 and the Expr.iColumn value is set to the column number.
         1673  +** In all cases except (4), the Expr.iTable value for Expr.op==TK_COLUMN
         1674  +** nodes of the expression is set to -1 and the Expr.iColumn value is
         1675  +** set to the column number.  In case (4), TK_COLUMN nodes cause an error.
  1672   1676   **
  1673   1677   ** Any errors cause an error message to be set in pParse.
  1674   1678   */
  1675         -void sqlite3ResolveSelfReference(
         1679  +int sqlite3ResolveSelfReference(
  1676   1680     Parse *pParse,      /* Parsing context */
  1677         -  Table *pTab,        /* The table being referenced */
  1678         -  int type,           /* NC_IsCheck or NC_PartIdx or NC_IdxExpr */
         1681  +  Table *pTab,        /* The table being referenced, or NULL */
         1682  +  int type,           /* NC_IsCheck or NC_PartIdx or NC_IdxExpr, or 0 */
  1679   1683     Expr *pExpr,        /* Expression to resolve.  May be NULL. */
  1680   1684     ExprList *pList     /* Expression list to resolve.  May be NULL. */
  1681   1685   ){
  1682   1686     SrcList sSrc;                   /* Fake SrcList for pParse->pNewTable */
  1683   1687     NameContext sNC;                /* Name context for pParse->pNewTable */
         1688  +  int rc;
  1684   1689   
  1685         -  assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr );
         1690  +  assert( type==0 || pTab!=0 );
         1691  +  assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr || pTab==0 );
  1686   1692     memset(&sNC, 0, sizeof(sNC));
  1687   1693     memset(&sSrc, 0, sizeof(sSrc));
  1688         -  sSrc.nSrc = 1;
  1689         -  sSrc.a[0].zName = pTab->zName;
  1690         -  sSrc.a[0].pTab = pTab;
  1691         -  sSrc.a[0].iCursor = -1;
         1694  +  if( pTab ){
         1695  +    sSrc.nSrc = 1;
         1696  +    sSrc.a[0].zName = pTab->zName;
         1697  +    sSrc.a[0].pTab = pTab;
         1698  +    sSrc.a[0].iCursor = -1;
         1699  +  }
  1692   1700     sNC.pParse = pParse;
  1693   1701     sNC.pSrcList = &sSrc;
  1694   1702     sNC.ncFlags = type;
  1695         -  if( sqlite3ResolveExprNames(&sNC, pExpr) ) return;
  1696         -  if( pList ) sqlite3ResolveExprListNames(&sNC, pList);
         1703  +  if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc;
         1704  +  if( pList ) rc = sqlite3ResolveExprListNames(&sNC, pList);
         1705  +  return rc;
  1697   1706   }

Changes to src/sqliteInt.h.

  4267   4267   int sqlite3CodeSubselect(Parse*, Expr*);
  4268   4268   void sqlite3SelectPrep(Parse*, Select*, NameContext*);
  4269   4269   void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
  4270   4270   int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
  4271   4271   int sqlite3ResolveExprNames(NameContext*, Expr*);
  4272   4272   int sqlite3ResolveExprListNames(NameContext*, ExprList*);
  4273   4273   void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
  4274         -void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
         4274  +int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
  4275   4275   int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
  4276   4276   void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
  4277   4277   void sqlite3AlterFinishAddColumn(Parse *, Token *);
  4278   4278   void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  4279   4279   void *sqlite3RenameTokenMap(Parse*, void*, Token*);
  4280   4280   void sqlite3RenameTokenRemap(Parse*, void *pTo, void *pFrom);
  4281   4281   void sqlite3RenameExprUnmap(Parse*, Expr*);

Changes to src/vacuum.c.

   120    120       ** legacy applications. */
   121    121       iDb = sqlite3FindDb(pParse->db, pNm);
   122    122       if( iDb<0 ) iDb = 0;
   123    123   #endif
   124    124     }
   125    125     if( iDb!=1 ){
   126    126       int iIntoReg = 0;
   127         -    if( pInto ){
          127  +    if( pInto && sqlite3ResolveSelfReference(pParse,0,0,pInto,0)==0 ){
   128    128         iIntoReg = ++pParse->nMem;
   129    129         sqlite3ExprCode(pParse, pInto, iIntoReg);
   130    130       }
   131    131       sqlite3VdbeAddOp2(v, OP_Vacuum, iDb, iIntoReg);
   132    132       sqlite3VdbeUsesBtree(v, iDb);
   133    133     }
   134    134   build_vacuum_end:

Changes to test/vacuum-into.test.

    61     61     CREATE TABLE t2(name TEXT);
    62     62     INSERT INTO t2 VALUES(':memory:');
    63     63     VACUUM main INTO (SELECT name FROM t2);
    64     64   } {}
    65     65   do_catchsql_test vacuum-into-310 {
    66     66     VACUUM INTO null;
    67     67   } {1 {non-text filename}}
           68  +do_catchsql_test vacuum-into-320 {
           69  +  VACUUM INTO x;
           70  +} {1 {no such column: x}}
    68     71   
    69     72   finish_test