/ Check-in [e996ca32]
Login

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

Overview
Comment:Tighten the conditions under which applyNumericAffinity() be called and add assert() statements to prove that it is never called otherwise.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e996ca32cb643c558b616c0dd872f3351b6aa3ef
User & Date: drh 2014-09-19 22:01:54
Context
2014-09-19
22:30
Recognize the invariant that a Mem object cannot be MEM_Dyn and have a non-zero szMalloc at the same time. Enforce this with assert()s and exploit it in the sqlite3VdbeMemClearAndResize() routine for a performance increase. check-in: 3b21cf2b user: drh tags: trunk
22:01
Tighten the conditions under which applyNumericAffinity() be called and add assert() statements to prove that it is never called otherwise. check-in: e996ca32 user: drh tags: trunk
20:13
Fix the affinity on inserts into the ANALYZE tables. Change the affinity characters to be upper case, to make the P5 parameter of comparison operators easier to read. check-in: 3f3ca76a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

   238    238   ** point or exponential notation, the result is only MEM_Real, even
   239    239   ** if there is an exact integer representation of the quantity.
   240    240   */
   241    241   static void applyNumericAffinity(Mem *pRec, int bTryForInt){
   242    242     double rValue;
   243    243     i64 iValue;
   244    244     u8 enc = pRec->enc;
   245         -  if( (pRec->flags&MEM_Str)==0 ) return;
   246         -  if( (pRec->flags&(MEM_Int|MEM_Real))!=0 ) return;
          245  +  assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real))==MEM_Str );
   247    246     if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
   248    247     if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
   249    248       pRec->u.i = iValue;
   250    249       pRec->flags |= MEM_Int;
   251    250     }else{
   252    251       pRec->u.r = rValue;
   253    252       pRec->flags |= MEM_Real;
................................................................................
   279    278     u8 enc              /* Use this text encoding */
   280    279   ){
   281    280     if( affinity>=SQLITE_AFF_NUMERIC ){
   282    281       assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
   283    282                || affinity==SQLITE_AFF_NUMERIC );
   284    283       if( (pRec->flags & MEM_Int)==0 ){
   285    284         if( (pRec->flags & MEM_Real)==0 ){
   286         -        applyNumericAffinity(pRec,1);
          285  +        if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
   287    286         }else{
   288    287           sqlite3VdbeIntegerAffinity(pRec);
   289    288         }
   290    289       }
   291    290     }else if( affinity==SQLITE_AFF_TEXT ){
   292    291       /* Only attempt the conversion to TEXT if there is an integer or real
   293    292       ** representation (blob and NULL do not get converted) but no string
................................................................................
  3554   3553     pC->seekOp = pOp->opcode;
  3555   3554   #endif
  3556   3555     if( pC->isTable ){
  3557   3556       /* The input value in P3 might be of any type: integer, real, string,
  3558   3557       ** blob, or NULL.  But it needs to be an integer before we can do
  3559   3558       ** the seek, so convert it. */
  3560   3559       pIn3 = &aMem[pOp->p3];
  3561         -    if( (pIn3->flags & (MEM_Int|MEM_Real))==0 ){
         3560  +    if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
  3562   3561         applyNumericAffinity(pIn3, 0);
  3563   3562       }
  3564   3563       iKey = sqlite3VdbeIntValue(pIn3);
  3565   3564       pC->rowidIsValid = 0;
  3566   3565   
  3567   3566       /* If the P3 value could not be converted into an integer without
  3568   3567       ** loss of information, then special processing is required... */