/ Check-in [b83cfe89]
Login

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

Overview
Comment:Fix some incorrect comments and typos in comments. Add testcase() macros to some of the new record comparison code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b83cfe899d84fe9d61540e9984321ca30401638c
User & Date: drh 2014-03-06 01:56:33
Context
2014-03-06
02:15
Cosmetic change to the shell in-memory database warning to skip coloring the trailing period. check-in: c87d8e07 user: mistachkin tags: trunk
01:56
Fix some incorrect comments and typos in comments. Add testcase() macros to some of the new record comparison code. check-in: b83cfe89 user: drh tags: trunk
00:30
Better loadable extension handling in the Win32 VFS when compiled for Cygwin. check-in: 29b0a4f1 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  4572   4572     if( pIdxKey ){
  4573   4573       xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
  4574   4574       assert( pIdxKey->default_rc==1 
  4575   4575            || pIdxKey->default_rc==0 
  4576   4576            || pIdxKey->default_rc==-1
  4577   4577       );
  4578   4578     }else{
  4579         -    xRecordCompare = 0; /* Not actually used.  Avoids a compiler warning. */
         4579  +    xRecordCompare = 0; /* All keys are integers */
  4580   4580     }
  4581   4581   
  4582   4582     rc = moveToRoot(pCur);
  4583   4583     if( rc ){
  4584   4584       return rc;
  4585   4585     }
  4586   4586     assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] );

Changes to src/insert.c.

    97     97     return pIdx->zColAff;
    98     98   }
    99     99   
   100    100   /*
   101    101   ** Compute the affinity string for table pTab, if it has not already been
   102    102   ** computed.  As an optimization, omit trailing SQLITE_AFF_NONE affinities.
   103    103   **
   104         -** If the affinity exists (if it is no entirely SQLITE_AFF_NONE values and
          104  +** If the affinity exists (if it is no entirely SQLITE_AFF_NONE values) and
   105    105   ** if iReg>0 then code an OP_Affinity opcode that will set the affinities
   106    106   ** for register iReg and following.  Or if affinities exists and iReg==0,
   107    107   ** then just set the P4 operand of the previous opcode (which should  be
   108    108   ** an OP_MakeRecord) to the affinity string.
   109    109   **
   110         -** A column affinity string has one character column:
          110  +** A column affinity string has one character per column:
   111    111   **
   112    112   **  Character      Column affinity
   113    113   **  ------------------------------
   114    114   **  'a'            TEXT
   115    115   **  'b'            NONE
   116    116   **  'c'            NUMERIC
   117    117   **  'd'            INTEGER
................................................................................
   144    144         sqlite3VdbeChangeP4(v, -1, zColAff, i);
   145    145       }
   146    146     }
   147    147   }
   148    148   
   149    149   /*
   150    150   ** Return non-zero if the table pTab in database iDb or any of its indices
   151         -** have been opened at any point in the VDBE program beginning at location
   152         -** iStartAddr throught the end of the program.  This is used to see if 
          151  +** have been opened at any point in the VDBE program. This is used to see if 
   153    152   ** a statement of the form  "INSERT INTO <iDb, pTab> SELECT ..." can 
   154         -** run without using temporary table for the results of the SELECT. 
          153  +** run without using a temporary table for the results of the SELECT. 
   155    154   */
   156    155   static int readsTable(Parse *p, int iDb, Table *pTab){
   157    156     Vdbe *v = sqlite3GetVdbe(p);
   158    157     int i;
   159    158     int iEnd = sqlite3VdbeCurrentAddr(v);
   160    159   #ifndef SQLITE_OMIT_VIRTUALTABLE
   161    160     VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;

Changes to src/vdbe.c.

    24     24   /*
    25     25   ** Invoke this macro on memory cells just prior to changing the
    26     26   ** value of the cell.  This macro verifies that shallow copies are
    27     27   ** not misused.  A shallow copy of a string or blob just copies a
    28     28   ** pointer to the string or blob, not the content.  If the original
    29     29   ** is changed while the copy is still in use, the string or blob might
    30     30   ** be changed out from under the copy.  This macro verifies that nothing
    31         -** like that every happens.
           31  +** like that ever happens.
    32     32   */
    33     33   #ifdef SQLITE_DEBUG
    34     34   # define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M)
    35     35   #else
    36     36   # define memAboutToChange(P,M)
    37     37   #endif
    38     38   
................................................................................
  2162   2162     break;
  2163   2163   }
  2164   2164   
  2165   2165   /* Opcode: Once P1 P2 * * *
  2166   2166   **
  2167   2167   ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
  2168   2168   ** set the flag and fall through to the next instruction.  In other words,
  2169         -** this opcode causes all following up codes up through P2 (but not including
  2170         -** P2) to run just once and skipped on subsequent times through the loop.
         2169  +** this opcode causes all following opcodes up through P2 (but not including
         2170  +** P2) to run just once and to be skipped on subsequent times through the loop.
  2171   2171   */
  2172   2172   case OP_Once: {             /* jump */
  2173   2173     assert( pOp->p1<p->nOnceFlag );
  2174   2174     VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
  2175   2175     if( p->aOnceFlag[pOp->p1] ){
  2176   2176       pc = pOp->p2-1;
  2177   2177     }else{

Changes to src/vdbeaux.c.

  1230   1230         ** callgrind, this causes a certain test case to hit the CPU 4.7 
  1231   1231         ** percent less (x86 linux, gcc version 4.1.2, -O6) than if 
  1232   1232         ** sqlite3MemRelease() were called from here. With -O2, this jumps
  1233   1233         ** to 6.6 percent. The test case is inserting 1000 rows into a table 
  1234   1234         ** with no indexes using a single prepared INSERT statement, bind() 
  1235   1235         ** and reset(). Inserts are grouped into a transaction.
  1236   1236         */
         1237  +      testcase( p->flags & MEM_Agg );
         1238  +      testcase( p->flags & MEM_Dyn );
         1239  +      testcase( p->flags & MEM_Frame );
         1240  +      testcase( p->flags & MEM_RowSet );
  1237   1241         if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
  1238   1242           sqlite3VdbeMemRelease(p);
  1239   1243         }else if( p->zMalloc ){
  1240   1244           sqlite3DbFree(db, p->zMalloc);
  1241   1245           p->zMalloc = 0;
  1242   1246         }
  1243   1247   
................................................................................
  2958   2962       case 0: {  /* NULL */
  2959   2963         pMem->flags = MEM_Null;
  2960   2964         break;
  2961   2965       }
  2962   2966       case 1: { /* 1-byte signed integer */
  2963   2967         pMem->u.i = ONE_BYTE_INT(buf);
  2964   2968         pMem->flags = MEM_Int;
         2969  +      testcase( pMem->u.i<0 );
  2965   2970         return 1;
  2966   2971       }
  2967   2972       case 2: { /* 2-byte signed integer */
  2968   2973         pMem->u.i = TWO_BYTE_INT(buf);
  2969   2974         pMem->flags = MEM_Int;
         2975  +      testcase( pMem->u.i<0 );
  2970   2976         return 2;
  2971   2977       }
  2972   2978       case 3: { /* 3-byte signed integer */
  2973   2979         pMem->u.i = THREE_BYTE_INT(buf);
  2974   2980         pMem->flags = MEM_Int;
         2981  +      testcase( pMem->u.i<0 );
  2975   2982         return 3;
  2976   2983       }
  2977   2984       case 4: { /* 4-byte signed integer */
  2978   2985         y = FOUR_BYTE_UINT(buf);
  2979   2986         pMem->u.i = (i64)*(int*)&y;
  2980   2987         pMem->flags = MEM_Int;
         2988  +      testcase( pMem->u.i<0 );
  2981   2989         return 4;
  2982   2990       }
  2983   2991       case 5: { /* 6-byte signed integer */
  2984   2992         pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
  2985   2993         pMem->flags = MEM_Int;
         2994  +      testcase( pMem->u.i<0 );
  2986   2995         return 6;
  2987   2996       }
  2988   2997       case 6:   /* 8-byte signed integer */
  2989   2998       case 7: { /* IEEE floating point */
  2990   2999   #if !defined(NDEBUG) && !defined(SQLITE_OMIT_FLOATING_POINT)
  2991   3000         /* Verify that integers and floating point values use the same
  2992   3001         ** byte order.  Or, that if SQLITE_MIXED_ENDIAN_64BIT_FLOAT is
................................................................................
  3001   3010   #endif
  3002   3011         x = FOUR_BYTE_UINT(buf);
  3003   3012         y = FOUR_BYTE_UINT(buf+4);
  3004   3013         x = (x<<32) | y;
  3005   3014         if( serial_type==6 ){
  3006   3015           pMem->u.i = *(i64*)&x;
  3007   3016           pMem->flags = MEM_Int;
         3017  +        testcase( pMem->u.i<0 );
  3008   3018         }else{
  3009   3019           assert( sizeof(x)==8 && sizeof(pMem->r)==8 );
  3010   3020           swapMixedEndianFloat(x);
  3011   3021           memcpy(&pMem->r, &x, sizeof(x));
  3012   3022           pMem->flags = sqlite3IsNaN(pMem->r) ? MEM_Null : MEM_Real;
  3013   3023         }
  3014   3024         return 8;
................................................................................
  3346   3356   */
  3347   3357   static i64 vdbeRecordDecodeInt(u32 serial_type, const u8 *aKey){
  3348   3358     u32 y;
  3349   3359     assert( CORRUPT_DB || (serial_type>=1 && serial_type<=9 && serial_type!=7) );
  3350   3360     switch( serial_type ){
  3351   3361       case 0:
  3352   3362       case 1:
         3363  +      testcase( aKey[0]&0x80 );
  3353   3364         return ONE_BYTE_INT(aKey);
  3354   3365       case 2:
         3366  +      testcase( aKey[0]&0x80 );
  3355   3367         return TWO_BYTE_INT(aKey);
  3356   3368       case 3:
         3369  +      testcase( aKey[0]&0x80 );
  3357   3370         return THREE_BYTE_INT(aKey);
  3358   3371       case 4: {
         3372  +      testcase( aKey[0]&0x80 );
  3359   3373         y = FOUR_BYTE_UINT(aKey);
  3360   3374         return (i64)*(int*)&y;
  3361   3375       }
  3362   3376       case 5: {
         3377  +      testcase( aKey[0]&0x80 );
  3363   3378         return FOUR_BYTE_UINT(aKey+2) + (((i64)1)<<32)*TWO_BYTE_INT(aKey);
  3364   3379       }
  3365   3380       case 6: {
  3366   3381         u64 x = FOUR_BYTE_UINT(aKey);
         3382  +      testcase( aKey[0]&0x80 );
  3367   3383         x = (x<<32) | FOUR_BYTE_UINT(aKey+4);
  3368   3384         return (i64)*(i64*)&x;
  3369   3385       }
  3370   3386     }
  3371   3387   
  3372   3388     return (serial_type - 8);
  3373   3389   }
................................................................................
  3427   3443     assert( idx1<=szHdr1 || CORRUPT_DB );
  3428   3444     do{
  3429   3445       u32 serial_type;
  3430   3446   
  3431   3447       /* RHS is an integer */
  3432   3448       if( pRhs->flags & MEM_Int ){
  3433   3449         serial_type = aKey1[idx1];
         3450  +      testcase( serial_type==12 );
  3434   3451         if( serial_type>=12 ){
  3435   3452           rc = +1;
  3436   3453         }else if( serial_type==0 ){
  3437   3454           rc = -1;
  3438   3455         }else if( serial_type==7 ){
  3439   3456           double rhs = (double)pRhs->u.i;
  3440   3457           sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
................................................................................
  3477   3494           }
  3478   3495         }
  3479   3496       }
  3480   3497   
  3481   3498       /* RHS is a string */
  3482   3499       else if( pRhs->flags & MEM_Str ){
  3483   3500         getVarint32(&aKey1[idx1], serial_type);
         3501  +      testcase( serial_type==12 );
  3484   3502         if( serial_type<12 ){
  3485   3503           rc = -1;
  3486   3504         }else if( !(serial_type & 0x01) ){
  3487   3505           rc = +1;
  3488   3506         }else{
  3489   3507           mem1.n = (serial_type - 12) / 2;
         3508  +        testcase( (d1+mem1.n)==(unsigned)nKey1 );
         3509  +        testcase( (d1+mem1.n+1)==(unsigned)nKey1 );
  3490   3510           if( (d1+mem1.n) > (unsigned)nKey1 ){
  3491   3511             rc = 1;                /* Corruption */
  3492   3512           }else if( pKeyInfo->aColl[i] ){
  3493   3513             mem1.enc = pKeyInfo->enc;
  3494   3514             mem1.db = pKeyInfo->db;
  3495   3515             mem1.flags = MEM_Str;
  3496   3516             mem1.z = (char*)&aKey1[d1];
................................................................................
  3502   3522           }
  3503   3523         }
  3504   3524       }
  3505   3525   
  3506   3526       /* RHS is a blob */
  3507   3527       else if( pRhs->flags & MEM_Blob ){
  3508   3528         getVarint32(&aKey1[idx1], serial_type);
         3529  +      testcase( serial_type==12 );
  3509   3530         if( serial_type<12 || (serial_type & 0x01) ){
  3510   3531           rc = -1;
  3511   3532         }else{
  3512   3533           int nStr = (serial_type - 12) / 2;
         3534  +        testcase( (d1+nStr)==(unsigned)nKey1 );
         3535  +        testcase( (d1+nStr+1)==(unsigned)nKey1 );
  3513   3536           if( (d1+nStr) > (unsigned)nKey1 ){
  3514   3537             rc = 1;                /* Corruption */
  3515   3538           }else{
  3516   3539             int nCmp = MIN(nStr, pRhs->n);
  3517   3540             rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
  3518   3541             if( rc==0 ) rc = nStr - pRhs->n;
  3519   3542           }
................................................................................
  3579   3602     i64 lhs;
  3580   3603     UNUSED_PARAMETER(bSkip);
  3581   3604   
  3582   3605     assert( bSkip==0 );
  3583   3606     switch( serial_type ){
  3584   3607       case 1: { /* 1-byte signed integer */
  3585   3608         lhs = ONE_BYTE_INT(aKey);
         3609  +      testcase( lhs<0 );
  3586   3610         break;
  3587   3611       }
  3588   3612       case 2: { /* 2-byte signed integer */
  3589   3613         lhs = TWO_BYTE_INT(aKey);
         3614  +      testcase( lhs<0 );
  3590   3615         break;
  3591   3616       }
  3592   3617       case 3: { /* 3-byte signed integer */
  3593   3618         lhs = THREE_BYTE_INT(aKey);
         3619  +      testcase( lhs<0 );
  3594   3620         break;
  3595   3621       }
  3596   3622       case 4: { /* 4-byte signed integer */
  3597   3623         y = FOUR_BYTE_UINT(aKey);
  3598   3624         lhs = (i64)*(int*)&y;
         3625  +      testcase( lhs<0 );
  3599   3626         break;
  3600   3627       }
  3601   3628       case 5: { /* 6-byte signed integer */
  3602   3629         lhs = FOUR_BYTE_UINT(aKey+2) + (((i64)1)<<32)*TWO_BYTE_INT(aKey);
         3630  +      testcase( lhs<0 );
  3603   3631         break;
  3604   3632       }
  3605   3633       case 6: { /* 8-byte signed integer */
  3606   3634         x = FOUR_BYTE_UINT(aKey);
  3607   3635         x = (x<<32) | FOUR_BYTE_UINT(aKey+4);
  3608   3636         lhs = *(i64*)&x;
         3637  +      testcase( lhs<0 );
  3609   3638         break;
  3610   3639       }
  3611   3640       case 8: 
  3612   3641         lhs = 0;
  3613   3642         break;
  3614   3643       case 9:
  3615   3644         lhs = 1;
................................................................................
  3738   3767       }else{
  3739   3768         p->r1 = -1;
  3740   3769         p->r2 = 1;
  3741   3770       }
  3742   3771       if( (flags & MEM_Int) ){
  3743   3772         return vdbeRecordCompareInt;
  3744   3773       }
  3745         -    if( (flags & (MEM_Int|MEM_Real|MEM_Null|MEM_Blob))==0 
  3746         -        && p->pKeyInfo->aColl[0]==0 
  3747         -    ){
         3774  +    testcase( flags & MEM_Real );
         3775  +    testcase( flags & MEM_Null );
         3776  +    testcase( flags & MEM_Blob );
         3777  +    if( (flags & (MEM_Real|MEM_Null|MEM_Blob))==0 && p->pKeyInfo->aColl[0]==0 ){
         3778  +      assert( flags & MEM_Str );
  3748   3779         return vdbeRecordCompareString;
  3749   3780       }
  3750   3781     }
  3751   3782   
  3752   3783     return sqlite3VdbeRecordCompare;
  3753   3784   }
  3754   3785