SQLite

Changes On Branch default-in-values
Login

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

Changes In Branch default-in-values Excluding Merge-Ins

This is equivalent to a diff from 0cfbe349d4 to d67e28cb1b

2025-02-13
23:33
Omit an optimization that did not work - it runs faster with the optimization removed. CLOSED: Development on this branch has stopped. See the new implementation in the default-in-values-2 branch. (Closed-Leaf check-in: d67e28cb1b user: drh tags: default-in-values)
19:19
Remove an unnecessary branch. Improvements to error messages. (check-in: f49ddd80b1 user: drh tags: default-in-values)
2025-02-12
18:22
Merge the latest trunk changes into the default-in-values branch. (check-in: 480d7c1a1a user: drh tags: default-in-values)
16:59
configure --help cleanups and eliminate the use of a JS-esque inner function in sqlite-config.tcl. No functional changes. (check-in: 6df859cd18 user: stephan tags: trunk)
15:31
Remove old function declaration accidentally left in sqlite3session.h. (check-in: 0cfbe349d4 user: dan tags: trunk)
14:51
Tiny tcl comment tweaks. No functional changes. (check-in: da94e551c0 user: stephan tags: trunk)

Changes to src/expr.c.
4891
4892
4893
4894
4895
4896
4897




4898
4899
4900
4901
4902
4903
4904
      return target;
    }
#endif
    case TK_STRING: {
      assert( !ExprHasProperty(pExpr, EP_IntValue) );
      sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
      return target;




    }
    default: {
      /* Make NULL the default case so that if a bug causes an illegal
      ** Expr node to be passed into this function, it will be handled
      ** sanely and not crash.  But keep the assert() to bring the problem
      ** to the attention of the developers. */
      assert( op==TK_NULL || op==TK_ERROR || pParse->db->mallocFailed );







>
>
>
>







4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
      return target;
    }
#endif
    case TK_STRING: {
      assert( !ExprHasProperty(pExpr, EP_IntValue) );
      sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
      return target;
    }
    case TK_DEFAULT: {
      sqlite3VdbeAddOp1(v, OP_DfltNull, target);
      return target;
    }
    default: {
      /* Make NULL the default case so that if a bug causes an illegal
      ** Expr node to be passed into this function, it will be handled
      ** sanely and not crash.  But keep the assert() to bring the problem
      ** to the attention of the developers. */
      assert( op==TK_NULL || op==TK_ERROR || pParse->db->mallocFailed );
Changes to src/insert.c.
786
787
788
789
790
791
792































793
794
795
796
797
798
799
static int xferOptimization(
  Parse *pParse,        /* Parser context */
  Table *pDest,         /* The table we are inserting into */
  Select *pSelect,      /* A SELECT statement to use as the data source */
  int onError,          /* How to handle constraint errors */
  int iDbDest           /* The database of pDest */
);
































/*
** This routine is called to handle SQL of the following forms:
**
**    insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
**    insert into TABLE (IDLIST) select
**    insert into TABLE (IDLIST) default values







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







786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
static int xferOptimization(
  Parse *pParse,        /* Parser context */
  Table *pDest,         /* The table we are inserting into */
  Select *pSelect,      /* A SELECT statement to use as the data source */
  int onError,          /* How to handle constraint errors */
  int iDbDest           /* The database of pDest */
);

/*
** If the iCol-th column of pTab has a default value, then add
** code that checks the content of register iReg to see if it
** is a SQLITE_NULL_DEFAULT and if it is, changes the content
** of iReg to the default value of the iCol-th column of pTab.
*/
static void insertResolveValuesDflt(
  Parse *pParse,         /* Parsing context */
  Table *pTab,           /* Table being inserted into */
  int iCol,              /* Column being inserted into */
  int iReg               /* Register containing the value to insert */
){
  Vdbe *v = pParse->pVdbe;
  sqlite3 *db = pParse->db;
  sqlite3_value *pValue = 0;
  Column *pCol;

  assert( pParse->bValuesDflt );
  assert( pParse->pVdbe!=0 );
  assert( pTab->aCol[iCol].iDflt>0 );
  assert( !IsView(pTab) );
  assert( iCol<pTab->nCol );

  pCol = &pTab->aCol[iCol];
  sqlite3ValueFromExpr(db,
                       sqlite3ColumnExpr(pTab,pCol), ENC(db),
                       pCol->affinity, &pValue);
  sqlite3VdbeAddOp1(v, OP_ToDefault, iReg);
  sqlite3VdbeAppendP4(v, pValue, P4_MEM);
}

/*
** This routine is called to handle SQL of the following forms:
**
**    insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
**    insert into TABLE (IDLIST) select
**    insert into TABLE (IDLIST) default values
1419
1420
1421
1422
1423
1424
1425



1426
1427








1428
1429
1430
1431
1432
1433
1434
1435

    if( useTempTable ){
      sqlite3VdbeAddOp3(v, OP_Column, srcTab, k, iRegStore);
    }else if( pSelect ){
      if( regFromSelect!=regData ){
        sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+k, iRegStore);
      }



    }else{
      Expr *pX = pList->a[k].pExpr;








      int y = sqlite3ExprCodeTarget(pParse, pX, iRegStore);
      if( y!=iRegStore ){
        sqlite3VdbeAddOp2(v,
          ExprHasProperty(pX, EP_Subquery) ? OP_Copy : OP_SCopy, y, iRegStore);
      }
    }
  }








>
>
>


>
>
>
>
>
>
>
>
|







1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477

    if( useTempTable ){
      sqlite3VdbeAddOp3(v, OP_Column, srcTab, k, iRegStore);
    }else if( pSelect ){
      if( regFromSelect!=regData ){
        sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+k, iRegStore);
      }
      if( pParse->bValuesDflt && pTab->aCol[i].iDflt ){
        insertResolveValuesDflt(pParse, pTab, i, iRegStore);
      }
    }else{
      Expr *pX = pList->a[k].pExpr;
      int y;
      if( pX->op==TK_DEFAULT ){
        Expr *pDflt = sqlite3ColumnExpr(pTab, &pTab->aCol[i]);
        if( pDflt ){
          sqlite3ExprCodeFactorable(pParse, pDflt, iRegStore);
          continue;
        }
      }
      y = sqlite3ExprCodeTarget(pParse, pX, iRegStore);
      if( y!=iRegStore ){
        sqlite3VdbeAddOp2(v,
          ExprHasProperty(pX, EP_Subquery) ? OP_Copy : OP_SCopy, y, iRegStore);
      }
    }
  }

Changes to src/parse.y.
116
117
118
119
120
121
122

123

124
125
126
127
128
129
130

struct FrameBound     { int eType; Expr *pExpr; };

/*
** Generate a syntax error
*/
static void parserSyntaxError(Parse *pParse, Token *p){

  sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", p);

}

/*
** Disable lookaside memory allocation for objects that might be
** shared across database connections.
*/
static void disableLookaside(Parse *pParse){







>
|
>







116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

struct FrameBound     { int eType; Expr *pExpr; };

/*
** Generate a syntax error
*/
static void parserSyntaxError(Parse *pParse, Token *p){
  if( sqlite3_strglob("*syntax error*", pParse->zErrMsg)!=0 ){
    sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", p);
  }
}

/*
** Disable lookaside memory allocation for objects that might be
** shared across database connections.
*/
static void disableLookaside(Parse *pParse){
1528
1529
1530
1531
1532
1533
1534



































































1535
1536
1537
1538
1539
1540
1541
exprlist(A) ::= nexprlist(A).
exprlist(A) ::= .                            {A = 0;}
nexprlist(A) ::= nexprlist(A) COMMA expr(Y).
    {A = sqlite3ExprListAppend(pParse,A,Y);}
nexprlist(A) ::= expr(Y).
    {A = sqlite3ExprListAppend(pParse,0,Y); /*A-overwrites-Y*/}




































































%ifndef SQLITE_OMIT_SUBQUERY
/* A paren_exprlist is an optional expression list contained inside
** of parenthesis */
%type paren_exprlist {ExprList*}
%destructor paren_exprlist {sqlite3ExprListDelete(pParse->db, $$);}
paren_exprlist(A) ::= .   {A = 0;}
paren_exprlist(A) ::= LP exprlist(X) RP.  {A = X;}







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







1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
exprlist(A) ::= nexprlist(A).
exprlist(A) ::= .                            {A = 0;}
nexprlist(A) ::= nexprlist(A) COMMA expr(Y).
    {A = sqlite3ExprListAppend(pParse,A,Y);}
nexprlist(A) ::= expr(Y).
    {A = sqlite3ExprListAppend(pParse,0,Y); /*A-overwrites-Y*/}


%include {
  /* Forward declaration */
  static SQLITE_NOINLINE void parserRequireInsertContext(
    Parse *pParse,                /* The SQLite parsing context */
    void *pLemon,                 /* The LEMON parser state */
    Token *pErrToken,             /* Token that might be a syntax error */
    int nRhs                      /* Number of RHS tokens on the ruls */
  );
}
%code {
  /* This routine checks to see if the parser stack looks like either of these:
  **
  **     insert_cmd INTO xfullname idlist_opt VALUES LP
  **     insert_cmd INTO xfullname idlist_opt values COMMA LP
  **
  ** If the parser stack is different from both of these, then raise a syntax error
  ** on pErrToken.
  */
  static SQLITE_NOINLINE void parserRequireInsertContext(
    Parse *pParse,                /* The SQLite parsing context */
    void *pLemon,                 /* The LEMON parser state */
    Token *pErrToken,             /* Token that might be a syntax error */
    int nRhs                      /* Number of RHS tokens on the ruls */
  ){
    yyParser *yypParser = (yyParser*)pLemon;
    yyStackEntry *yytos = yypParser->yytos - nRhs;
    int bFault = 0;
    if( (yytos - yypParser->yystack) < 6
     || yytos[0].major!=TK_LP
    ){
      bFault = 1;
    }else
    if( yytos[-1].major==TK_COMMA
     && (yytos[-2].major==YYNT_values || yytos[-2].major==YYNT_mvalues)
     && yytos[-3].major==YYNT_idlist_opt
    ){
      /* This is ok */
    }else
    if( yytos[-1].major==TK_VALUES
     && yytos[-2].major==YYNT_idlist_opt
    ){
      /* This is ok */
    }else
    {
      bFault = 1;  /* Cannot match */
    }
    if( bFault ) parserSyntaxError(pParse, pErrToken);
    pParse->bValuesDflt = 1;
  }
}

// The following reduction rules only succeed if the previous two
// tokens are "VALUES LP".  If the previous two tokens are anything
// different, a syntax error is raised.
//
nexprlist(A) ::= nexprlist(A) COMMA DEFAULT(D). {
  Expr *p = sqlite3PExpr(pParse,TK_DEFAULT,0,0);
  parserRequireInsertContext(pParse, yypParser, &D, 3);
  A = sqlite3ExprListAppend(pParse,A,p);
}
nexprlist(A) ::= DEFAULT(D). {
  Expr *p = sqlite3PExpr(pParse,TK_DEFAULT,0,0);
  parserRequireInsertContext(pParse, yypParser, &D, 1);
  A = sqlite3ExprListAppend(pParse,0,p);
}

%ifndef SQLITE_OMIT_SUBQUERY
/* A paren_exprlist is an optional expression list contained inside
** of parenthesis */
%type paren_exprlist {ExprList*}
%destructor paren_exprlist {sqlite3ExprListDelete(pParse->db, $$);}
paren_exprlist(A) ::= .   {A = 0;}
paren_exprlist(A) ::= LP exprlist(X) RP.  {A = X;}
Changes to src/pragma.c.
1817
1818
1819
1820
1821
1822
1823
1824

1825
1826
1827
1828
1829
1830
1831
        if( !IsOrdinaryTable(pTab) ) continue;
        if( isQuick || HasRowid(pTab) ){
          pPk = 0;
          r2 = 0;
        }else{
          pPk = sqlite3PrimaryKeyIndex(pTab);
          r2 = sqlite3GetTempRange(pParse, pPk->nKeyCol);
          sqlite3VdbeAddOp3(v, OP_Null, 1, r2, r2+pPk->nKeyCol-1);

        }
        sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
                                   1, 0, &iDataCur, &iIdxCur);
        /* reg[7] counts the number of entries in the table.
        ** reg[8+i] counts the number of entries in the i-th index
        */
        sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);







|
>







1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
        if( !IsOrdinaryTable(pTab) ) continue;
        if( isQuick || HasRowid(pTab) ){
          pPk = 0;
          r2 = 0;
        }else{
          pPk = sqlite3PrimaryKeyIndex(pTab);
          r2 = sqlite3GetTempRange(pParse, pPk->nKeyCol);
          sqlite3VdbeAddOp3(v, OP_Null,
                            SQLITE_NULL_CLEARED, r2, r2+pPk->nKeyCol-1);
        }
        sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
                                   1, 0, &iDataCur, &iIdxCur);
        /* reg[7] counts the number of entries in the table.
        ** reg[8+i] counts the number of entries in the i-th index
        */
        sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
Changes to src/select.c.
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
    if( eTnctType==WHERE_DISTINCT_ORDERED ){
      /* Change the OP_OpenEphemeral to an OP_Null that sets the MEM_Cleared
      ** bit on the first register of the previous value.  This will cause the
      ** OP_Ne added in codeDistinct() to always fail on the first iteration of
      ** the loop even if the first row is all NULLs.  */
      VdbeOp *pOp = sqlite3VdbeGetOp(v, iOpenEphAddr);
      pOp->opcode = OP_Null;
      pOp->p1 = 1;
      pOp->p2 = iVal;
    }
  }
}

#ifdef SQLITE_ENABLE_SORTER_REFERENCES
/*







|







1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
    if( eTnctType==WHERE_DISTINCT_ORDERED ){
      /* Change the OP_OpenEphemeral to an OP_Null that sets the MEM_Cleared
      ** bit on the first register of the previous value.  This will cause the
      ** OP_Ne added in codeDistinct() to always fail on the first iteration of
      ** the loop even if the first row is all NULLs.  */
      VdbeOp *pOp = sqlite3VdbeGetOp(v, iOpenEphAddr);
      pOp->opcode = OP_Null;
      pOp->p1 = SQLITE_NULL_CLEARED;
      pOp->p2 = iVal;
    }
  }
}

#ifdef SQLITE_ENABLE_SORTER_REFERENCES
/*
Changes to src/sqliteInt.h.
3851
3852
3853
3854
3855
3856
3857

3858
3859
3860
3861
3862
3863
3864
  u8 isCreate;         /* CREATE TABLE, INDEX, or VIEW (but not TRIGGER)
                       ** and ALTER TABLE ADD COLUMN. */
#endif
  bft colNamesSet :1;   /* TRUE after OP_ColumnName has been issued to pVdbe */
  bft bHasWith :1;      /* True if statement contains WITH */
  bft okConstFactor :1; /* OK to factor out constants */
  bft checkSchema :1;   /* Causes schema cookie check after an error */

  int nRangeReg;       /* Size of the temporary register block */
  int iRangeReg;       /* First register in temporary register block */
  int nErr;            /* Number of errors seen */
  int nTab;            /* Number of previously allocated VDBE cursors */
  int nMem;            /* Number of memory cells used so far */
  int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  int iSelfTab;        /* Table associated with an index on expr, or negative







>







3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
  u8 isCreate;         /* CREATE TABLE, INDEX, or VIEW (but not TRIGGER)
                       ** and ALTER TABLE ADD COLUMN. */
#endif
  bft colNamesSet :1;   /* TRUE after OP_ColumnName has been issued to pVdbe */
  bft bHasWith :1;      /* True if statement contains WITH */
  bft okConstFactor :1; /* OK to factor out constants */
  bft checkSchema :1;   /* Causes schema cookie check after an error */
  bft bValuesDflt :1;   /* DEFAULT keyword appears in a VALUES clause */
  int nRangeReg;       /* Size of the temporary register block */
  int iRangeReg;       /* First register in temporary register block */
  int nErr;            /* Number of errors seen */
  int nTab;            /* Number of previously allocated VDBE cursors */
  int nMem;            /* Number of memory cells used so far */
  int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  int iSelfTab;        /* Table associated with an index on expr, or negative
Changes to src/vdbe.c.
577
578
579
580
581
582
583



584

585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603



604

605
606
607
608
609
610
611
/*
** Print the value of a register for tracing purposes:
*/
static void memTracePrint(Mem *p){
  if( p->flags & MEM_Undefined ){
    printf(" undefined");
  }else if( p->flags & MEM_Null ){



    printf(p->flags & MEM_Zero ? " NULL-nochng" : " NULL");

  }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
    printf(" si:%lld", p->u.i);
  }else if( (p->flags & (MEM_IntReal))!=0 ){
    printf(" ir:%lld", p->u.i);
  }else if( p->flags & MEM_Int ){
    printf(" i:%lld", p->u.i);
#ifndef SQLITE_OMIT_FLOATING_POINT
  }else if( p->flags & MEM_Real ){
    printf(" r:%.17g", p->u.r);
#endif
  }else if( sqlite3VdbeMemIsRowSet(p) ){
    printf(" (rowset)");
  }else{
    StrAccum acc;
    char zBuf[1000];
    sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
    sqlite3VdbeMemPrettyPrint(p, &acc);
    printf(" %s", sqlite3StrAccumFinish(&acc));
  }



  if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);

}
static void registerTrace(int iReg, Mem *p){
  printf("R[%d] = ", iReg);
  memTracePrint(p);
  if( p->pScopyFrom ){
    assert( p->pScopyFrom->bScopy );
    printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));







>
>
>
|
>



















>
>
>
|
>







577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
/*
** Print the value of a register for tracing purposes:
*/
static void memTracePrint(Mem *p){
  if( p->flags & MEM_Undefined ){
    printf(" undefined");
  }else if( p->flags & MEM_Null ){
    if( p->flags==(MEM_Null|MEM_Term|MEM_Subtype) && p->eSubtype==0 ){
      printf(" NULL-default");
    }else{
      printf(p->flags & MEM_Zero ? " NULL-nochng" : " NULL");
    }
  }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
    printf(" si:%lld", p->u.i);
  }else if( (p->flags & (MEM_IntReal))!=0 ){
    printf(" ir:%lld", p->u.i);
  }else if( p->flags & MEM_Int ){
    printf(" i:%lld", p->u.i);
#ifndef SQLITE_OMIT_FLOATING_POINT
  }else if( p->flags & MEM_Real ){
    printf(" r:%.17g", p->u.r);
#endif
  }else if( sqlite3VdbeMemIsRowSet(p) ){
    printf(" (rowset)");
  }else{
    StrAccum acc;
    char zBuf[1000];
    sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
    sqlite3VdbeMemPrettyPrint(p, &acc);
    printf(" %s", sqlite3StrAccumFinish(&acc));
  }
  if( (p->flags & MEM_Subtype)!=0
   && (p->eSubtype!=0 || (p->flags & MEM_Null)==0)
  ){
    printf(" subtype=0x%02x", p->eSubtype);
  }
}
static void registerTrace(int iReg, Mem *p){
  printf("R[%d] = ", iReg);
  memTracePrint(p);
  if( p->pScopyFrom ){
    assert( p->pScopyFrom->bScopy );
    printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
1469
1470
1471
1472
1473
1474
1475
1476
1477

1478
1479
1480
1481
1482
1483
1484
1485
1486


1487
1488
1489
1490
1491
1492
1493
1494
** Synopsis: r[P2..P3]=NULL
**
** Write a NULL into registers P2.  If P3 greater than P2, then also write
** NULL into register P3 and every register in between P2 and P3.  If P3
** is less than P2 (typically P3 is zero) then only register P2 is
** set to NULL.
**
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
** NULL values will not compare equal even if SQLITE_NULLEQ is set on

** OP_Ne or OP_Eq.
*/
case OP_BeginSubrtn:
case OP_Null: {           /* out2 */
  int cnt;
  u16 nullFlag;
  pOut = out2Prerelease(p, pOp);
  cnt = pOp->p3-pOp->p2;
  assert( pOp->p3<=(p->nMem+1 - p->nCursor) );


  pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
  pOut->n = 0;
#ifdef SQLITE_DEBUG
  pOut->uTemp = 0;
#endif
  while( cnt>0 ){
    pOut++;
    memAboutToChange(p, pOut);







|
|
>
|








>
>
|







1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
** Synopsis: r[P2..P3]=NULL
**
** Write a NULL into registers P2.  If P3 greater than P2, then also write
** NULL into register P3 and every register in between P2 and P3.  If P3
** is less than P2 (typically P3 is zero) then only register P2 is
** set to NULL.
**
** If the P1 value can be SQLITE_NULL_CLEARED to create a NULL value that 
** will not compare equal even if SQLITE_NULLEQ is set on OP_Ne or OP_Eq.
** In other words, SQLITE_NULL_CLEARED creates a NULL that never compares
** equal to any other NULL.
*/
case OP_BeginSubrtn:
case OP_Null: {           /* out2 */
  int cnt;
  u16 nullFlag;
  pOut = out2Prerelease(p, pOp);
  cnt = pOp->p3-pOp->p2;
  assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
  assert( pOp->p1==0 || pOp->p1==MEM_Cleared );
  assert( SQLITE_NULL_CLEARED==MEM_Cleared );
  pOut->flags = nullFlag = pOp->p1 | MEM_Null;
  pOut->n = 0;
#ifdef SQLITE_DEBUG
  pOut->uTemp = 0;
#endif
  while( cnt>0 ){
    pOut++;
    memAboutToChange(p, pOut);
1510
1511
1512
1513
1514
1515
1516







































1517
1518
1519
1520
1521
1522
1523
*/
case OP_SoftNull: {
  assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
  pOut = &aMem[pOp->p1];
  pOut->flags = (pOut->flags&~(MEM_Undefined|MEM_AffMask))|MEM_Null;
  break;
}








































/* Opcode: Blob P1 P2 * P4 *
** Synopsis: r[P2]=P4 (len=P1)
**
** P4 points to a blob of data P1 bytes long.  Store this
** blob in register P2.  If P4 is a NULL pointer, then construct
** a zero-filled blob that is P1 bytes long in P2.







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







1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
*/
case OP_SoftNull: {
  assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
  pOut = &aMem[pOp->p1];
  pOut->flags = (pOut->flags&~(MEM_Undefined|MEM_AffMask))|MEM_Null;
  break;
}

/* Opcode: DfltNull P1 * * * *
** Synopsis: r[P1]=DEFAULT-NULL
**
** Set register P1 to have the value NULL that has a special pointer
** value to indicate that it originated as a DEFAULT keyword in a VALUES
** clause.
*/
case OP_DfltNull: {
  assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
  pOut = &aMem[pOp->p1];
  memAboutToChange(p, pOut);
  sqlite3VdbeMemSetNull(pOut);
  pOut->flags = MEM_Null|MEM_Term|MEM_Subtype;
  pOut->eSubtype = 0;
  break;
}

/* Opcode: ToDefault P1 * * P4 *
** Synopsis: if r[P1]==DEFAULT then r[P1]=P4
**
** If register P1 contains the special NULL value created by the
** OP_DfltNull opcode that indicates that it originated from the
** DEFAULT keyword in a VALUES clause, then change its value to
** the value in P4.
*/
case OP_ToDefault: {            /* in1 */
  assert( pOp->p4type==P4_MEM );
  pIn1 = &aMem[pOp->p1];
  if( (pIn1->flags & (MEM_TypeMask|MEM_Term))==(MEM_Null|MEM_Term|MEM_Subtype)
   && pIn1->eSubtype==0
  ){
    memAboutToChange(p, pIn1);
    sqlite3VdbeMemShallowCopy(pIn1, pOp->p4.pMem, MEM_Static);
    UPDATE_MAX_BLOBSIZE(pIn1);
    REGISTER_TRACE(pOp->p1, pIn1);
  }
  break;
}

/* Opcode: Blob P1 P2 * P4 *
** Synopsis: r[P2]=P4 (len=P1)
**
** P4 points to a blob of data P1 bytes long.  Store this
** blob in register P2.  If P4 is a NULL pointer, then construct
** a zero-filled blob that is P1 bytes long in P2.
Changes to src/vdbe.h.
184
185
186
187
188
189
190





191
192
193
194
195
196
197

/*
** Additional non-public SQLITE_PREPARE_* flags
*/
#define SQLITE_PREPARE_SAVESQL  0x80  /* Preserve SQL text */
#define SQLITE_PREPARE_MASK     0x1f  /* Mask of public flags */






/*
** Prototypes for the VDBE interface.  See comments on the implementation
** for a description of what each of these routines does.
*/
Vdbe *sqlite3VdbeCreate(Parse*);
Parse *sqlite3VdbeParser(Vdbe*);
int sqlite3VdbeAddOp0(Vdbe*,int);







>
>
>
>
>







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

/*
** Additional non-public SQLITE_PREPARE_* flags
*/
#define SQLITE_PREPARE_SAVESQL  0x80  /* Preserve SQL text */
#define SQLITE_PREPARE_MASK     0x1f  /* Mask of public flags */

/*
** Allowed P1 arguments to OP_Null for special kinds of NULLs.
*/
#define SQLITE_NULL_CLEARED  0x0100   /* NULL always <> to other NULLs */

/*
** Prototypes for the VDBE interface.  See comments on the implementation
** for a description of what each of these routines does.
*/
Vdbe *sqlite3VdbeCreate(Parse*);
Parse *sqlite3VdbeParser(Vdbe*);
int sqlite3VdbeAddOp0(Vdbe*,int);
Changes to src/vdbeInt.h.
255
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
#define MEMCELLSIZE offsetof(Mem,db)

/* One or more of the following flags are set to indicate the
** representations of the value stored in the Mem struct.
**
**  *  MEM_Null                An SQL NULL value
**
**  *  MEM_Null|MEM_Zero       An SQL NULL with the virtual table
**                             UPDATE no-change flag set

**
**  *  MEM_Null|MEM_Term|      An SQL NULL, but also contains a
**        MEM_Subtype          pointer accessible using
**                             sqlite3_value_pointer().
**
**  *  MEM_Null|MEM_Cleared    Special SQL NULL that compares non-equal
**                             to other NULLs even using the IS operator.







|
|
>







255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#define MEMCELLSIZE offsetof(Mem,db)

/* One or more of the following flags are set to indicate the
** representations of the value stored in the Mem struct.
**
**  *  MEM_Null                An SQL NULL value
**
**  *  MEM_Null|MEM_Zero       An SQL NULL with flag that indicates
**                             UPDATE no-change for virtual tables and
**                             DEFAULT for ordinary tables.
**
**  *  MEM_Null|MEM_Term|      An SQL NULL, but also contains a
**        MEM_Subtype          pointer accessible using
**                             sqlite3_value_pointer().
**
**  *  MEM_Null|MEM_Cleared    Special SQL NULL that compares non-equal
**                             to other NULLs even using the IS operator.
Changes to src/where.c.
745
746
747
748
749
750
751

752
753
754
755
756
757
758
      }
#endif
      pOp->opcode = OP_Sequence;
      pOp->p1 = iAutoidxCur;
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
      if( iAutoidxCur==0 ){
        pOp->opcode = OP_Null;

        pOp->p3 = 0;
      }
#endif
    }
  }
}








>







745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
      }
#endif
      pOp->opcode = OP_Sequence;
      pOp->p1 = iAutoidxCur;
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
      if( iAutoidxCur==0 ){
        pOp->opcode = OP_Null;
        pOp->p1 = 0;
        pOp->p3 = 0;
      }
#endif
    }
  }
}

Changes to tool/lemon.c.
4929
4930
4931
4932
4933
4934
4935








4936
4937
4938
4939
4940
4941
4942

  /* Generate a table containing the symbolic name of every symbol
  */
  for(i=0; i<lemp->nsymbol; i++){
    fprintf(out,"  /* %4d */ \"%s\",\n",i, lemp->symbols[i]->name); lineno++;
  }
  tplt_xfer(lemp->name,in,out,&lineno);









  /* Generate a table containing a text string that describes every
  ** rule in the rule set of the grammar.  This information is used
  ** when tracing REDUCE actions.
  */
  for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){
    assert( rp->iRule==i );







>
>
>
>
>
>
>
>







4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950

  /* Generate a table containing the symbolic name of every symbol
  */
  for(i=0; i<lemp->nsymbol; i++){
    fprintf(out,"  /* %4d */ \"%s\",\n",i, lemp->symbols[i]->name); lineno++;
  }
  tplt_xfer(lemp->name,in,out,&lineno);

  /* Generate internal #defines for every non-terminal symbol.
  */
  for(i=0; i<lemp->nsymbol; i++){
    if( !ISLOWER(lemp->symbols[i]->name[0]) ) continue;
    fprintf(out,"#define YYNT_%-20s %4d\n",lemp->symbols[i]->name, i);lineno++;
  }
  tplt_xfer(lemp->name,in,out,&lineno);

  /* Generate a table containing a text string that describes every
  ** rule in the rule set of the grammar.  This information is used
  ** when tracing REDUCE actions.
  */
  for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){
    assert( rp->iRule==i );
Changes to tool/lempar.c.
275
276
277
278
279
280
281



282
283
284
285
286
287
288
#if defined(YYCOVERAGE) || !defined(NDEBUG)
/* For tracing shifts, the names of all terminals and nonterminals
** are required.  The following table supplies these names */
static const char *const yyTokenName[] = { 
%%
};
#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */




#ifndef NDEBUG
/* For tracing reduce actions, the names of all rules are required.
*/
static const char *const yyRuleName[] = {
%%
};







>
>
>







275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#if defined(YYCOVERAGE) || !defined(NDEBUG)
/* For tracing shifts, the names of all terminals and nonterminals
** are required.  The following table supplies these names */
static const char *const yyTokenName[] = { 
%%
};
#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */

/* Numeric values assigned to non-terminal symbols. */
%%

#ifndef NDEBUG
/* For tracing reduce actions, the names of all rules are required.
*/
static const char *const yyRuleName[] = {
%%
};