/ Check-in [bd4bda73]
Login

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

Overview
Comment:Improved detection of number of column mismatch for vector assignment in UPDATE statements. Ticket [78acc9d40f0786e8]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: bd4bda73df3794eef424eb13e08fc7cc54347d1ac69febaeec41f6b6cb4a42bc
User & Date: drh 2019-08-26 14:18:28
Context
2019-08-26
14:57
Tweak the shell tool ".recover" command so that it can recover rows that consist of a rowid and no fields. check-in: 279ac7fd user: dan tags: trunk
14:18
Improved detection of number of column mismatch for vector assignment in UPDATE statements. Ticket [78acc9d40f0786e8] check-in: bd4bda73 user: drh tags: trunk
13:45
Fix typo in a comment. No code changes. check-in: d0cc06d8 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  1628   1628       sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
  1629   1629                       pColumns->nId, n);
  1630   1630       goto vector_append_error;
  1631   1631     }
  1632   1632   
  1633   1633     for(i=0; i<pColumns->nId; i++){
  1634   1634       Expr *pSubExpr = sqlite3ExprForVectorField(pParse, pExpr, i);
         1635  +    assert( pSubExpr!=0 || db->mallocFailed );
         1636  +    assert( pSubExpr==0 || pSubExpr->iTable==0 );
         1637  +    if( pSubExpr==0 ) continue;
         1638  +    pSubExpr->iTable = pColumns->nId;
  1635   1639       pList = sqlite3ExprListAppend(pParse, pList, pSubExpr);
  1636   1640       if( pList ){
  1637   1641         assert( pList->nExpr==iFirst+i+1 );
  1638   1642         pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
  1639   1643         pColumns->a[i].zName = 0;
  1640   1644       }
  1641   1645     }
................................................................................
  3902   3906       }
  3903   3907       case TK_SELECT_COLUMN: {
  3904   3908         int n;
  3905   3909         if( pExpr->pLeft->iTable==0 ){
  3906   3910           pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft);
  3907   3911         }
  3908   3912         assert( pExpr->iTable==0 || pExpr->pLeft->op==TK_SELECT );
  3909         -      if( pExpr->iTable
  3910         -       && pExpr->iTable!=(n = sqlite3ExprVectorSize(pExpr->pLeft)) 
         3913  +      if( pExpr->iTable!=0
         3914  +       && pExpr->iTable!=(n = sqlite3ExprVectorSize(pExpr->pLeft))
  3911   3915         ){
  3912   3916           sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
  3913   3917                                   pExpr->iTable, n);
  3914   3918         }
  3915   3919         return pExpr->pLeft->iTable + pExpr->iColumn;
  3916   3920       }
  3917   3921       case TK_IN: {

Changes to src/sqliteInt.h.

  2466   2466   #if SQLITE_MAX_EXPR_DEPTH>0
  2467   2467     int nHeight;           /* Height of the tree headed by this node */
  2468   2468   #endif
  2469   2469     int iTable;            /* TK_COLUMN: cursor number of table holding column
  2470   2470                            ** TK_REGISTER: register number
  2471   2471                            ** TK_TRIGGER: 1 -> new, 0 -> old
  2472   2472                            ** EP_Unlikely:  134217728 times likelihood
         2473  +                         ** TK_SELECT_COLUMN: Number of columns on the LHS
  2473   2474                            ** TK_SELECT: 1st register of result vector */
  2474   2475     ynVar iColumn;         /* TK_COLUMN: column index.  -1 for rowid.
  2475   2476                            ** TK_VARIABLE: variable number (always >= 1).
  2476   2477                            ** TK_SELECT_COLUMN: column of the result vector */
  2477   2478     i16 iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  2478   2479     i16 iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
  2479   2480     u8 op2;                /* TK_REGISTER/TK_TRUTH: original value of Expr.op

Changes to test/rowvalue7.test.

    51     51     UPDATE t1 SET (c,d) = (SELECT x,y,z FROM t2 WHERE w=a);
    52     52   } {1 {2 columns assigned 3 values}}
    53     53   
    54     54   do_catchsql_test 2.2 {
    55     55     UPDATE t1 SET (b,c,d) = (SELECT x,y FROM t2 WHERE w=a);
    56     56   } {1 {3 columns assigned 2 values}}
    57     57   
           58  +# 2019-08-26
           59  +# ticket https://www.sqlite.org/src/info/78acc9d40f0786e8
           60  +#
           61  +do_catchsql_test 3.0 {
           62  +  DROP TABLE IF EXISTS t1;
           63  +  CREATE TABLE t1(a,b);
           64  +  INSERT INTO t1 VALUES(1,2);
           65  +  UPDATE t1 SET (a,a,a,b)=(SELECT 99,100);
           66  +} {1 {4 columns assigned 2 values}}
           67  +
    58     68   finish_test