/ Check-in [2b221bb15f]
Login

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

Overview
Comment:Fix the OP_Affinity operator so that when applying REAL affinity, it only sets MEM_IntReal if the integer value will fit in 6 bytes or less. Fix for ticket [ba2f4585cf495231]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2b221bb15fd2b9f6a426e5eb439f7dbabbe3c4cab010c49b87dae3bb1f16c081
User & Date: drh 2019-07-29 06:06:53
Context
2019-07-29
15:32
When using an index for both DISTINCT and ORDER BY, do not confuse the number of columns required for distinctness with the number required to get the correct sort order. Fix for [6749cb3c]. check-in: 6ac0f82245 user: dan tags: trunk
06:06
Fix the OP_Affinity operator so that when applying REAL affinity, it only sets MEM_IntReal if the integer value will fit in 6 bytes or less. Fix for ticket [ba2f4585cf495231] check-in: 2b221bb15f user: drh tags: trunk
05:23
Fix a minor typo in a comment. check-in: cea8a892f7 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

  2813   2813     assert( zAffinity[pOp->p2]==0 );
  2814   2814     pIn1 = &aMem[pOp->p1];
  2815   2815     while( 1 /*exit-by-break*/ ){
  2816   2816       assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
  2817   2817       assert( memIsValid(pIn1) );
  2818   2818       applyAffinity(pIn1, zAffinity[0], encoding);
  2819   2819       if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
  2820         -      /* When applying REAL affinity, if the result is still MEM_Int, 
  2821         -      ** indicate that REAL is actually desired */
  2822         -      pIn1->flags |= MEM_IntReal;
  2823         -      pIn1->flags &= ~MEM_Int;
         2820  +      /* When applying REAL affinity, if the result is still an MEM_Int
         2821  +      ** that will fit in 6 bytes, then change the type to MEM_IntReal
         2822  +      ** so that we keep the high-resolution integer value but know that
         2823  +      ** the type really wants to be REAL. */
         2824  +      testcase( pIn1->u.i==140737488355328LL );
         2825  +      testcase( pIn1->u.i==140737488355327LL );
         2826  +      testcase( pIn1->u.i==-140737488355328LL );
         2827  +      testcase( pIn1->u.i==-140737488355329LL );
         2828  +      if( pIn1->u.i<=140737488355327LL && pIn1->u.i>=-140737488355328LL ){
         2829  +        pIn1->flags |= MEM_IntReal;
         2830  +        pIn1->flags &= ~MEM_Int;
         2831  +      }else{
         2832  +        pIn1->u.r = (double)pIn1->u.i;
         2833  +        pIn1->flags |= MEM_Real;
         2834  +        pIn1->flags &= ~MEM_Int;
         2835  +      }
  2824   2836       }
  2825   2837       REGISTER_TRACE((int)(pIn1-aMem), pIn1);
  2826   2838       zAffinity++;
  2827   2839       if( zAffinity[0]==0 ) break;
  2828   2840       pIn1++;
  2829   2841     }
  2830   2842     break;

Changes to test/intreal.test.

    78     78     SELECT * FROM t0, t1 
    79     79     WHERE (
    80     80           t1.c1 >= CAST(8366271098608253588 AS REAL) 
    81     81       AND t1.c1 <= CAST(8366271098608253588 AS REAL)
    82     82     );
    83     83   } [list a $D]
    84     84   
           85  +# 2019-07-29 ticket ba2f4585cf495231
           86  +#
           87  +db close
           88  +sqlite3 db :memory:
           89  +do_execsql_test 3.0 {
           90  +  CREATE TABLE t0 (c0 REAL, c1);
           91  +  CREATE UNIQUE INDEX i0 ON t0(c1, 0 | c0);
           92  +  INSERT INTO t0(c0) VALUES (4750228396194493326), (0);
           93  +  UPDATE OR REPLACE t0 SET c0 = 'a', c1 = '';
           94  +  SELECT * FROM t0 ORDER BY t0.c1;
           95  +  PRAGMA integrity_check;
           96  +} {a {} ok}
    85     97   
    86     98   finish_test