/ Check-in [ccef5d2d]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix a problem with inserting zeroblob() into an indexed column. (CVS 3982)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ccef5d2daaa5a88dd3f23666f022296ef42f9d73
User & Date: danielk1977 2007-05-11 07:08:28
Context
2007-05-11
10:10
Expand the expressions tested by fuzz.test. Fix for (CAST zeroblob() AS text). (CVS 3983) check-in: 4e1bb41f user: danielk1977 tags: trunk
07:08
Fix a problem with inserting zeroblob() into an indexed column. (CVS 3982) check-in: ccef5d2d user: danielk1977 tags: trunk
01:44
Additional parsing bugs fixed. (CVS 3981) check-in: d12a8924 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.615 2007/05/10 21:14:03 drh Exp $
           46  +** $Id: vdbe.c,v 1.616 2007/05/11 07:08:28 danielk1977 Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include <math.h>
    52     52   #include "vdbeInt.h"
    53     53   
................................................................................
   915    915     int i;
   916    916     Mem ts;
   917    917   
   918    918     ts = *pFrom;
   919    919     Deephemeralize(pTos);
   920    920     for(i=0; i<pOp->p1; i++, pFrom++){
   921    921       Deephemeralize(&pFrom[1]);
   922         -    assert( (pFrom->flags & MEM_Ephem)==0 );
          922  +    assert( (pFrom[1].flags & MEM_Ephem)==0 );
   923    923       *pFrom = pFrom[1];
   924    924       if( pFrom->flags & MEM_Short ){
   925    925         assert( pFrom->flags & (MEM_Str|MEM_Blob) );
   926    926         assert( pFrom->z==pFrom[1].zShort );
   927    927         pFrom->z = pFrom->zShort;
   928    928       }
   929    929     }
................................................................................
  2271   2271     for(pRec=pData0; pRec<=pTos; pRec++){
  2272   2272       int len;
  2273   2273       if( zAffinity ){
  2274   2274         applyAffinity(pRec, zAffinity[pRec-pData0], encoding);
  2275   2275       }
  2276   2276       if( pRec->flags&MEM_Null ){
  2277   2277         containsNull = 1;
         2278  +    }
         2279  +    if( pRec->flags&MEM_Zero && pRec->n>0 ){
         2280  +      sqlite3VdbeMemExpandBlob(pRec);
  2278   2281       }
  2279   2282       serial_type = sqlite3VdbeSerialType(pRec, file_format);
  2280   2283       len = sqlite3VdbeSerialTypeLen(serial_type);
  2281   2284       nData += len;
  2282   2285       nHdr += sqlite3VarintLen(serial_type);
  2283   2286       if( pRec->flags & MEM_Zero ){
  2284   2287         /* Only pure zero-filled BLOBs can be input to this Opcode.
  2285   2288         ** We do not allow blobs with a prefix and a zero-filled tail. */
  2286         -      assert( pRec->n==0 );
  2287   2289         nZero += pRec->u.i;
  2288   2290       }else if( len ){
  2289   2291         nZero = 0;
  2290   2292       }
  2291   2293     }
  2292   2294   
  2293   2295     /* If we have to append a varint rowid to this record, set pRowid
................................................................................
  3826   3828     Cursor *pC;
  3827   3829     BtCursor *pCrsr;
  3828   3830     assert( pTos>=p->aStack );
  3829   3831     assert( i>=0 && i<p->nCursor );
  3830   3832     assert( p->apCsr[i]!=0 );
  3831   3833     assert( pTos->flags & MEM_Blob );
  3832   3834     if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
  3833         -    int nKey = pTos->n;
  3834         -    const char *zKey = pTos->z;
  3835   3835       assert( pC->isTable==0 );
  3836         -    rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p2);
  3837         -    assert( pC->deferredMoveto==0 );
  3838         -    pC->cacheStatus = CACHE_STALE;
         3836  +    rc = sqlite3VdbeMemExpandBlob(pTos);
         3837  +    if( rc==SQLITE_OK ){
         3838  +      int nKey = pTos->n;
         3839  +      const char *zKey = pTos->z;
         3840  +      rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p2);
         3841  +      assert( pC->deferredMoveto==0 );
         3842  +      pC->cacheStatus = CACHE_STALE;
         3843  +    }
  3839   3844     }
  3840   3845     Release(pTos);
  3841   3846     pTos--;
  3842   3847     break;
  3843   3848   }
  3844   3849   
  3845   3850   /* Opcode: IdxDelete P1 * *

Changes to test/fuzz.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is generating semi-random strings of SQL
    13     13   # (a.k.a. "fuzz") and sending it into the parser to try to generate
    14     14   # errors.
    15     15   #
    16         -# $Id: fuzz.test,v 1.4 2007/05/11 00:20:08 drh Exp $
           16  +# $Id: fuzz.test,v 1.5 2007/05/11 07:08:29 danielk1977 Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   proc fuzz {TemplateList} {
    22     22     set n [llength $TemplateList]
    23     23     set i [expr {int(rand()*$n)}]
................................................................................
   131    131     execsql {
   132    132       SELECT 'abc', zeroblob(1) FROM (SELECT 1) ORDER BY 1
   133    133     }
   134    134   } [execsql {SELECT 'abc', zeroblob(1)}]
   135    135   
   136    136   do_test fuzz-1.7 {
   137    137     execsql {
   138         -    SELECT (
   139         -      SELECT zeroblob(1000) FROM (
   140         -        SELECT * FROM (SELECT 'first') ORDER BY NOT 'in'
   141         -      )
          138  +    SELECT ( SELECT zeroblob(1000) FROM ( 
          139  +      SELECT * FROM (SELECT 'first') ORDER BY NOT 'in') 
   142    140       )
   143    141     }
   144         -} {}
          142  +} [execsql {SELECT zeroblob(1000)}]
   145    143   
   146    144   #----------------------------------------------------------------
   147    145   # Test some fuzzily generated expressions.
   148    146   #
   149    147   for {set ii 0} {$ii < 2000} {incr ii} {
   150    148     do_test fuzz-2.1.$ii {
   151    149       set ::expr [Expr]