/ Check-in [afadddc3]
Login

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

Overview
Comment:Fix a problem that could cause a crash when a shared-cache schema contains column default values. (CVS 6353)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:afadddc34eee3d6a39102b790ce1a869b33d4286
User & Date: danielk1977 2009-03-17 17:49:00
Context
2009-03-17
22:33
Move the rowid cache out of VdbeCursor and into BtCursor. When multiple BtCursors are open on the same table, set their rowid cache all at the same time. Ticket #3731. (CVS 6354) check-in: 18978583 user: drh tags: trunk
17:49
Fix a problem that could cause a crash when a shared-cache schema contains column default values. (CVS 6353) check-in: afadddc3 user: danielk1977 tags: trunk
15:39
Fix test script bugs in the thread002.test and thread_common.tcl. (CVS 6352) check-in: d137e841 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.522 2009/03/14 08:37:24 danielk1977 Exp $
           25  +** $Id: build.c,v 1.523 2009/03/17 17:49:00 danielk1977 Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   
    29     29   /*
    30     30   ** This routine is called when a new SQL statement is beginning to
    31     31   ** be parsed.  Initialize the pParse structure as needed.
    32     32   */
................................................................................
  1107   1107             pCol->zName);
  1108   1108       }else{
  1109   1109         /* A copy of pExpr is used instead of the original, as pExpr contains
  1110   1110         ** tokens that point to volatile memory. The 'span' of the expression
  1111   1111         ** is required by pragma table_info.
  1112   1112         */
  1113   1113         sqlite3ExprDelete(db, pCol->pDflt);
  1114         -      pCol->pDflt = sqlite3ExprDup(db, pExpr, EXPRDUP_REDUCE|EXPRDUP_SPAN);
         1114  +      pCol->pDflt = sqlite3ExprDup(
         1115  +          db, pExpr, EXPRDUP_REDUCE|EXPRDUP_DISTINCTSPAN
         1116  +      );
  1115   1117       }
  1116   1118     }
  1117   1119     sqlite3ExprDelete(db, pExpr);
  1118   1120   }
  1119   1121   
  1120   1122   /*
  1121   1123   ** Designate the PRIMARY KEY for the table.  pList is a list of names 

Changes to src/expr.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 routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.418 2009/03/05 14:53:18 danielk1977 Exp $
           15  +** $Id: expr.c,v 1.419 2009/03/17 17:49:00 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Return the 'affinity' of the expression pExpr if any.
    21     21   **
    22     22   ** If pExpr is a column, a reference to a column via an 'AS' alias,
................................................................................
   645    645   ** If so, remove the quotation marks.
   646    646   */
   647    647   void sqlite3DequoteExpr(sqlite3 *db, Expr *p){
   648    648     if( ExprHasAnyProperty(p, EP_Dequoted) ){
   649    649       return;
   650    650     }
   651    651     ExprSetProperty(p, EP_Dequoted);
   652         -  if( p->token.dyn==0 && !ExprHasProperty(p, EP_Reduced) ){
          652  +  if( p->token.dyn==0
          653  +   && !ExprHasAnyProperty(p, EP_Reduced|EP_TokenOnly|EP_SpanOnly) 
          654  +  ){
   653    655       sqlite3TokenCopy(db, &p->token, &p->token);
   654    656     }
   655    657     sqlite3Dequote((char*)p->token.z);
   656    658   }
   657    659   
   658    660   /*
   659    661   ** Return the number of bytes allocated for the expression structure 
................................................................................
   675    677   */
   676    678   static int dupedExprStructSize(Expr *p, int flags){
   677    679     int nSize;
   678    680     if( 0==(flags&EXPRDUP_REDUCE) ){
   679    681       nSize = EXPR_FULLSIZE;
   680    682     }else if( p->pLeft || p->pRight || p->pColl || p->x.pList ){
   681    683       nSize = EXPR_REDUCEDSIZE;
   682         -  }else if( flags&EXPRDUP_SPAN ){
          684  +  }else if( flags&(EXPRDUP_SPAN|EXPRDUP_DISTINCTSPAN) ){
   683    685       nSize = EXPR_SPANONLYSIZE;
   684    686     }else{
   685    687       nSize = EXPR_TOKENONLYSIZE;
   686    688     }
   687    689     return nSize;
   688    690   }
   689    691   
................................................................................
   692    694   ** the EXPRDUP_XXX passed as the second argument. This function returns
   693    695   ** the space in bytes required to store the copy of the Expr structure
   694    696   ** and the copies of the Expr.token.z and Expr.span.z (if applicable)
   695    697   ** string buffers.
   696    698   */
   697    699   static int dupedExprNodeSize(Expr *p, int flags){
   698    700     int nByte = dupedExprStructSize(p, flags) + (p->token.z ? p->token.n + 1 : 0);
   699         -  if( flags&EXPRDUP_SPAN && (p->token.z!=p->span.z || p->token.n!=p->span.n) ){
          701  +  if( (flags&EXPRDUP_DISTINCTSPAN)
          702  +   || (flags&EXPRDUP_SPAN && (p->token.z!=p->span.z || p->token.n!=p->span.n)) 
          703  +  ){
   700    704       nByte += p->span.n;
   701    705     }
   702    706     return (nByte+7)&~7;
   703    707   }
   704    708   
   705    709   /*
   706    710   ** Return the number of bytes required to create a duplicate of the 
................................................................................
   718    722   ** descended from the Expr.x.pList or Expr.x.pSelect variables).
   719    723   */
   720    724   static int dupedExprSize(Expr *p, int flags){
   721    725     int nByte = 0;
   722    726     if( p ){
   723    727       nByte = dupedExprNodeSize(p, flags);
   724    728       if( flags&EXPRDUP_REDUCE ){
   725         -      int f = flags&(~EXPRDUP_SPAN);
          729  +      int f = flags&(~(EXPRDUP_SPAN|EXPRDUP_DISTINCTSPAN));
   726    730         nByte += dupedExprSize(p->pLeft, f) + dupedExprSize(p->pRight, f);
   727    731       }
   728    732     }
   729    733     return nByte;
   730    734   }
   731    735   
   732    736   /*
................................................................................
   736    740   ** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
   737    741   ** if any. Before returning, *pzBuffer is set to the first byte passed the
   738    742   ** portion of the buffer copied into by this function.
   739    743   */
   740    744   static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
   741    745     Expr *pNew = 0;                      /* Value to return */
   742    746     if( p ){
   743         -    const int isRequireSpan = (flags&EXPRDUP_SPAN);
          747  +    const int isRequireDistinctSpan = (flags&EXPRDUP_DISTINCTSPAN);
          748  +    const int isRequireSpan = (flags&(EXPRDUP_SPAN|EXPRDUP_DISTINCTSPAN));
   744    749       const int isReduced = (flags&EXPRDUP_REDUCE);
   745    750       u8 *zAlloc;
   746    751   
   747    752       assert( pzBuffer==0 || isReduced );
   748    753   
   749    754       /* Figure out where to write the new Expr structure. */
   750    755       if( pzBuffer ){
................................................................................
   787    792           pNew->token.dyn = 0;
   788    793           pNew->token.z = zToken;
   789    794         }
   790    795   
   791    796         if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){
   792    797           /* Fill in the pNew->span token, if required. */
   793    798           if( isRequireSpan ){
   794         -          if( p->token.z!=p->span.z || p->token.n!=p->span.n ){
          799  +          if( isRequireDistinctSpan 
          800  +           || p->token.z!=p->span.z || p->token.n!=p->span.n
          801  +          ){
   795    802               pNew->span.z = &zAlloc[nNewSize+nToken];
   796    803               memcpy((char *)pNew->span.z, p->span.z, p->span.n);
   797    804               pNew->span.dyn = 0;
   798    805             }else{
   799    806               pNew->span.z = pNew->token.z;
   800    807               pNew->span.n = pNew->token.n;
   801    808             }

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.841 2009/03/16 13:19:36 danielk1977 Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.842 2009/03/17 17:49:00 danielk1977 Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Include the configuration header output by 'configure' if we're using the
    21     21   ** autoconf-based build
................................................................................
  1518   1518   #define EXPR_TOKENONLYSIZE      offsetof(Expr,span)
  1519   1519   #define EXPR_SPANONLYSIZE       offsetof(Expr,pLeft)
  1520   1520   
  1521   1521   /*
  1522   1522   ** Flags passed to the sqlite3ExprDup() function. See the header comment 
  1523   1523   ** above sqlite3ExprDup() for details.
  1524   1524   */
  1525         -#define EXPRDUP_REDUCE 0x0001
  1526         -#define EXPRDUP_SPAN   0x0002
         1525  +#define EXPRDUP_REDUCE         0x0001
         1526  +#define EXPRDUP_SPAN           0x0002
         1527  +#define EXPRDUP_DISTINCTSPAN   0x0004
  1527   1528   
  1528   1529   /*
  1529   1530   ** A list of expressions.  Each expression may optionally have a
  1530   1531   ** name.  An expr/name combination can be used in several ways, such
  1531   1532   ** as the list of "expr AS ID" fields following a "SELECT" or in the
  1532   1533   ** list of "ID = expr" items in an UPDATE.  A list of expressions can
  1533   1534   ** also be used as the argument to a function, in which case the a.zName

Changes to test/shared2.test.

     5      5   #
     6      6   #    May you do good and not evil.
     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   #
    12         -# $Id: shared2.test,v 1.5 2007/08/23 02:47:54 drh Exp $
           12  +# $Id: shared2.test,v 1.6 2009/03/17 17:49:00 danielk1977 Exp $
    13     13   
    14     14   set testdir [file dirname $argv0]
    15     15   source $testdir/tester.tcl
    16     16   db close
    17     17   
    18     18   ifcapable !shared_cache {
    19     19     finish_test
................................................................................
   122    122   
   123    123   db1 close
   124    124   db2 close
   125    125   
   126    126   do_test shared2-3.2 {
   127    127     sqlite3_enable_shared_cache 1
   128    128   } {1}
          129  +
          130  +file delete -force test.db
          131  +
          132  +sqlite3 db test.db
          133  +do_test shared2-4.1 {
          134  +  execsql {
          135  +    CREATE TABLE t0(a, b);
          136  +    CREATE TABLE t1(a, b DEFAULT 'hello world');
          137  +  }
          138  +} {}
          139  +db close
          140  +
          141  +sqlite3 db test.db
          142  +sqlite3 db2 test.db
          143  +
          144  +do_test shared2-4.2 {
          145  +  execsql { SELECT a, b FROM t0 } db
          146  +  execsql { INSERT INTO t1(a) VALUES(1) } db2
          147  +} {}
          148  +
          149  +do_test shared2-4.3 {
          150  +  db2 close
          151  +  db close
          152  +} {}
   129    153   
   130    154   sqlite3_enable_shared_cache $::enable_shared_cache
   131    155   finish_test
          156  +