/ Check-in [6b995259]
Login

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

Overview
Comment:Remove the anonymous union from the sqlite3_value structure since some compilers are unable to deal with it. (CVS 3758)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:6b995259bc974519379dee55c1ef00d28c76bf21
User & Date: drh 2007-03-30 11:23:45
Context
2007-03-30
11:29
Move the sqlite3_temp_directory global variable out of the OS porting layer and into main.c so that it is more accessible to non-standard OS porting layers. (CVS 3759) check-in: 23653f7a user: drh tags: trunk
11:23
Remove the anonymous union from the sqlite3_value structure since some compilers are unable to deal with it. (CVS 3758) check-in: 6b995259 user: drh tags: trunk
11:12
Comment changes in btree.c and added a missing "else" in pragma.c. (CVS 3757) check-in: 9a7d7e31 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.596 2007/03/29 05:51:49 drh Exp $
           46  +** $Id: vdbe.c,v 1.597 2007/03/30 11:23:45 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
   207    207       sqlite3VdbeMemNulTerminate(pRec);
   208    208       if( (pRec->flags&MEM_Str)
   209    209            && sqlite3IsNumber(pRec->z, &realnum, pRec->enc) ){
   210    210         i64 value;
   211    211         sqlite3VdbeChangeEncoding(pRec, SQLITE_UTF8);
   212    212         if( !realnum && sqlite3atoi64(pRec->z, &value) ){
   213    213           sqlite3VdbeMemRelease(pRec);
   214         -        pRec->i = value;
          214  +        pRec->u.i = value;
   215    215           pRec->flags = MEM_Int;
   216    216         }else{
   217    217           sqlite3VdbeMemRealify(pRec);
   218    218         }
   219    219       }
   220    220     }
   221    221   }
................................................................................
   666    666   /* Opcode: Integer P1 * *
   667    667   **
   668    668   ** The 32-bit integer value P1 is pushed onto the stack.
   669    669   */
   670    670   case OP_Integer: {
   671    671     pTos++;
   672    672     pTos->flags = MEM_Int;
   673         -  pTos->i = pOp->p1;
          673  +  pTos->u.i = pOp->p1;
   674    674     break;
   675    675   }
   676    676   
   677    677   /* Opcode: Int64 * * P3
   678    678   **
   679    679   ** P3 is a string representation of an integer.  Convert that integer
   680    680   ** to a 64-bit value and push it onto the stack.
................................................................................
   682    682   case OP_Int64: {
   683    683     pTos++;
   684    684     assert( pOp->p3!=0 );
   685    685     pTos->flags = MEM_Str|MEM_Static|MEM_Term;
   686    686     pTos->z = pOp->p3;
   687    687     pTos->n = strlen(pTos->z);
   688    688     pTos->enc = SQLITE_UTF8;
   689         -  pTos->i = sqlite3VdbeIntValue(pTos);
          689  +  pTos->u.i = sqlite3VdbeIntValue(pTos);
   690    690     pTos->flags |= MEM_Int;
   691    691     break;
   692    692   }
   693    693   
   694    694   /* Opcode: Real * * P3
   695    695   **
   696    696   ** The string value P3 is converted to a real and pushed on to the stack.
................................................................................
  1095   1095     if( (flags & MEM_Null)!=0 ){
  1096   1096       Release(pTos);
  1097   1097       pTos--;
  1098   1098       Release(pTos);
  1099   1099       pTos->flags = MEM_Null;
  1100   1100     }else if( (pTos->flags & pNos->flags & MEM_Int)==MEM_Int ){
  1101   1101       i64 a, b;
  1102         -    a = pTos->i;
  1103         -    b = pNos->i;
         1102  +    a = pTos->u.i;
         1103  +    b = pNos->u.i;
  1104   1104       switch( pOp->opcode ){
  1105   1105         case OP_Add:         b += a;       break;
  1106   1106         case OP_Subtract:    b -= a;       break;
  1107   1107         case OP_Multiply:    b *= a;       break;
  1108   1108         case OP_Divide: {
  1109   1109           if( a==0 ) goto divide_by_zero;
  1110   1110           b /= a;
................................................................................
  1115   1115           b %= a;
  1116   1116           break;
  1117   1117         }
  1118   1118       }
  1119   1119       Release(pTos);
  1120   1120       pTos--;
  1121   1121       Release(pTos);
  1122         -    pTos->i = b;
         1122  +    pTos->u.i = b;
  1123   1123       pTos->flags = MEM_Int;
  1124   1124     }else{
  1125   1125       double a, b;
  1126   1126       a = sqlite3VdbeRealValue(pTos);
  1127   1127       b = sqlite3VdbeRealValue(pNos);
  1128   1128       switch( pOp->opcode ){
  1129   1129         case OP_Add:         b += a;       break;
................................................................................
  1306   1306       case OP_ShiftLeft:   a <<= b;    break;
  1307   1307       case OP_ShiftRight:  a >>= b;    break;
  1308   1308       default:   /* CANT HAPPEN */     break;
  1309   1309     }
  1310   1310     Release(pTos);
  1311   1311     pTos--;
  1312   1312     Release(pTos);
  1313         -  pTos->i = a;
         1313  +  pTos->u.i = a;
  1314   1314     pTos->flags = MEM_Int;
  1315   1315     break;
  1316   1316   }
  1317   1317   
  1318   1318   /* Opcode: AddImm  P1 * *
  1319   1319   ** 
  1320   1320   ** Add the value P1 to whatever is on top of the stack.  The result
................................................................................
  1321   1321   ** is always an integer.
  1322   1322   **
  1323   1323   ** To force the top of the stack to be an integer, just add 0.
  1324   1324   */
  1325   1325   case OP_AddImm: {            /* no-push */
  1326   1326     assert( pTos>=p->aStack );
  1327   1327     sqlite3VdbeMemIntegerify(pTos);
  1328         -  pTos->i += pOp->p1;
         1328  +  pTos->u.i += pOp->p1;
  1329   1329     break;
  1330   1330   }
  1331   1331   
  1332   1332   /* Opcode: ForceInt P1 P2 *
  1333   1333   **
  1334   1334   ** Convert the top of the stack into an integer.  If the current top of
  1335   1335   ** the stack is not numeric (meaning that is is a NULL or a string that
................................................................................
  1346   1346     if( (pTos->flags & (MEM_Int|MEM_Real))==0 ){
  1347   1347       Release(pTos);
  1348   1348       pTos--;
  1349   1349       pc = pOp->p2 - 1;
  1350   1350       break;
  1351   1351     }
  1352   1352     if( pTos->flags & MEM_Int ){
  1353         -    v = pTos->i + (pOp->p1!=0);
         1353  +    v = pTos->u.i + (pOp->p1!=0);
  1354   1354     }else{
  1355   1355       /* FIX ME:  should this not be assert( pTos->flags & MEM_Real ) ??? */
  1356   1356       sqlite3VdbeMemRealify(pTos);
  1357   1357       v = (int)pTos->r;
  1358   1358       if( pTos->r>(double)v ) v++;
  1359   1359       if( pOp->p1 && pTos->r==(double)v ) v++;
  1360   1360     }
  1361   1361     Release(pTos);
  1362         -  pTos->i = v;
         1362  +  pTos->u.i = v;
  1363   1363     pTos->flags = MEM_Int;
  1364   1364     break;
  1365   1365   }
  1366   1366   
  1367   1367   /* Opcode: MustBeInt P1 P2 *
  1368   1368   ** 
  1369   1369   ** Force the top of the stack to be an integer.  If the top of the
................................................................................
  1644   1644     if( pOp->p2 ){
  1645   1645       if( res ){
  1646   1646         pc = pOp->p2-1;
  1647   1647       }
  1648   1648     }else{
  1649   1649       pTos++;
  1650   1650       pTos->flags = MEM_Int;
  1651         -    pTos->i = res;
         1651  +    pTos->u.i = res;
  1652   1652     }
  1653   1653     break;
  1654   1654   }
  1655   1655   
  1656   1656   /* Opcode: And * * *
  1657   1657   **
  1658   1658   ** Pop two values off the stack.  Take the logical AND of the
................................................................................
  1671   1671     int v1, v2;    /* 0==TRUE, 1==FALSE, 2==UNKNOWN or NULL */
  1672   1672   
  1673   1673     assert( pNos>=p->aStack );
  1674   1674     if( pTos->flags & MEM_Null ){
  1675   1675       v1 = 2;
  1676   1676     }else{
  1677   1677       sqlite3VdbeMemIntegerify(pTos);
  1678         -    v1 = pTos->i==0;
         1678  +    v1 = pTos->u.i==0;
  1679   1679     }
  1680   1680     if( pNos->flags & MEM_Null ){
  1681   1681       v2 = 2;
  1682   1682     }else{
  1683   1683       sqlite3VdbeMemIntegerify(pNos);
  1684         -    v2 = pNos->i==0;
         1684  +    v2 = pNos->u.i==0;
  1685   1685     }
  1686   1686     if( pOp->opcode==OP_And ){
  1687   1687       static const unsigned char and_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
  1688   1688       v1 = and_logic[v1*3+v2];
  1689   1689     }else{
  1690   1690       static const unsigned char or_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
  1691   1691       v1 = or_logic[v1*3+v2];
  1692   1692     }
  1693   1693     popStack(&pTos, 2);
  1694   1694     pTos++;
  1695   1695     if( v1==2 ){
  1696   1696       pTos->flags = MEM_Null;
  1697   1697     }else{
  1698         -    pTos->i = v1==0;
         1698  +    pTos->u.i = v1==0;
  1699   1699       pTos->flags = MEM_Int;
  1700   1700     }
  1701   1701     break;
  1702   1702   }
  1703   1703   
  1704   1704   /* Opcode: Negative * * *
  1705   1705   **
................................................................................
  1721   1721       Release(pTos);
  1722   1722       if( pOp->opcode==OP_Negative || pTos->r<0.0 ){
  1723   1723         pTos->r = -pTos->r;
  1724   1724       }
  1725   1725       pTos->flags = MEM_Real;
  1726   1726     }else if( pTos->flags & MEM_Int ){
  1727   1727       Release(pTos);
  1728         -    if( pOp->opcode==OP_Negative || pTos->i<0 ){
  1729         -      pTos->i = -pTos->i;
         1728  +    if( pOp->opcode==OP_Negative || pTos->u.i<0 ){
         1729  +      pTos->u.i = -pTos->u.i;
  1730   1730       }
  1731   1731       pTos->flags = MEM_Int;
  1732   1732     }else if( pTos->flags & MEM_Null ){
  1733   1733       /* Do nothing */
  1734   1734     }else{
  1735   1735       sqlite3VdbeMemNumerify(pTos);
  1736   1736       goto neg_abs_real_case;
................................................................................
  1745   1745   ** is unchanged.
  1746   1746   */
  1747   1747   case OP_Not: {                /* same as TK_NOT, no-push */
  1748   1748     assert( pTos>=p->aStack );
  1749   1749     if( pTos->flags & MEM_Null ) break;  /* Do nothing to NULLs */
  1750   1750     sqlite3VdbeMemIntegerify(pTos);
  1751   1751     assert( (pTos->flags & MEM_Dyn)==0 );
  1752         -  pTos->i = !pTos->i;
         1752  +  pTos->u.i = !pTos->u.i;
  1753   1753     pTos->flags = MEM_Int;
  1754   1754     break;
  1755   1755   }
  1756   1756   
  1757   1757   /* Opcode: BitNot * * *
  1758   1758   **
  1759   1759   ** Interpret the top of the stack as an value.  Replace it
................................................................................
  1761   1761   ** value is unchanged.
  1762   1762   */
  1763   1763   case OP_BitNot: {             /* same as TK_BITNOT, no-push */
  1764   1764     assert( pTos>=p->aStack );
  1765   1765     if( pTos->flags & MEM_Null ) break;  /* Do nothing to NULLs */
  1766   1766     sqlite3VdbeMemIntegerify(pTos);
  1767   1767     assert( (pTos->flags & MEM_Dyn)==0 );
  1768         -  pTos->i = ~pTos->i;
         1768  +  pTos->u.i = ~pTos->u.i;
  1769   1769     pTos->flags = MEM_Int;
  1770   1770     break;
  1771   1771   }
  1772   1772   
  1773   1773   /* Opcode: Noop * * *
  1774   1774   **
  1775   1775   ** Do nothing.  This instruction is often useful as a jump
................................................................................
  2445   2445     ** be the number of free pages in the database (a read-only value)
  2446   2446     ** and meta[1] to be the schema cookie.  The schema layer considers
  2447   2447     ** meta[1] to be the schema cookie.  So we have to shift the index
  2448   2448     ** by one in the following statement.
  2449   2449     */
  2450   2450     rc = sqlite3BtreeGetMeta(db->aDb[pOp->p1].pBt, 1 + pOp->p2, (u32 *)&iMeta);
  2451   2451     pTos++;
  2452         -  pTos->i = iMeta;
         2452  +  pTos->u.i = iMeta;
  2453   2453     pTos->flags = MEM_Int;
  2454   2454     break;
  2455   2455   }
  2456   2456   
  2457   2457   /* Opcode: SetCookie P1 P2 *
  2458   2458   **
  2459   2459   ** Write the top of the stack into cookie number P2 of database P1.
................................................................................
  2469   2469     assert( pOp->p2<SQLITE_N_BTREE_META );
  2470   2470     assert( pOp->p1>=0 && pOp->p1<db->nDb );
  2471   2471     pDb = &db->aDb[pOp->p1];
  2472   2472     assert( pDb->pBt!=0 );
  2473   2473     assert( pTos>=p->aStack );
  2474   2474     sqlite3VdbeMemIntegerify(pTos);
  2475   2475     /* See note about index shifting on OP_ReadCookie */
  2476         -  rc = sqlite3BtreeUpdateMeta(pDb->pBt, 1+pOp->p2, (int)pTos->i);
         2476  +  rc = sqlite3BtreeUpdateMeta(pDb->pBt, 1+pOp->p2, (int)pTos->u.i);
  2477   2477     if( pOp->p2==0 ){
  2478   2478       /* When the schema cookie changes, record the new cookie internally */
  2479         -    pDb->pSchema->schema_cookie = pTos->i;
         2479  +    pDb->pSchema->schema_cookie = pTos->u.i;
  2480   2480       db->flags |= SQLITE_InternChanges;
  2481   2481     }else if( pOp->p2==1 ){
  2482   2482       /* Record changes in the file format */
  2483         -    pDb->pSchema->file_format = pTos->i;
         2483  +    pDb->pSchema->file_format = pTos->u.i;
  2484   2484     }
  2485   2485     assert( (pTos->flags & MEM_Dyn)==0 );
  2486   2486     pTos--;
  2487   2487     if( pOp->p1==1 ){
  2488   2488       /* Invalidate all prepared statements whenever the TEMP database
  2489   2489       ** schema is changed.  Ticket #1644 */
  2490   2490       sqlite3ExpirePreparedStatements(db);
................................................................................
  2578   2578     Btree *pX;
  2579   2579     int iDb;
  2580   2580     Cursor *pCur;
  2581   2581     Db *pDb;
  2582   2582     
  2583   2583     assert( pTos>=p->aStack );
  2584   2584     sqlite3VdbeMemIntegerify(pTos);
  2585         -  iDb = pTos->i;
         2585  +  iDb = pTos->u.i;
  2586   2586     assert( (pTos->flags & MEM_Dyn)==0 );
  2587   2587     pTos--;
  2588   2588     assert( iDb>=0 && iDb<db->nDb );
  2589   2589     pDb = &db->aDb[iDb];
  2590   2590     pX = pDb->pBt;
  2591   2591     assert( pX!=0 );
  2592   2592     if( pOp->opcode==OP_OpenWrite ){
................................................................................
  2596   2596       }
  2597   2597     }else{
  2598   2598       wrFlag = 0;
  2599   2599     }
  2600   2600     if( p2<=0 ){
  2601   2601       assert( pTos>=p->aStack );
  2602   2602       sqlite3VdbeMemIntegerify(pTos);
  2603         -    p2 = pTos->i;
         2603  +    p2 = pTos->u.i;
  2604   2604       assert( (pTos->flags & MEM_Dyn)==0 );
  2605   2605       pTos--;
  2606   2606       assert( p2>=2 );
  2607   2607     }
  2608   2608     assert( i>=0 );
  2609   2609     pCur = allocateCursor(p, i, iDb);
  2610   2610     if( pCur==0 ) goto no_mem;
................................................................................
  2822   2822       int res, oc;
  2823   2823       oc = pOp->opcode;
  2824   2824       pC->nullRow = 0;
  2825   2825       *pC->pIncrKey = oc==OP_MoveGt || oc==OP_MoveLe;
  2826   2826       if( pC->isTable ){
  2827   2827         i64 iKey;
  2828   2828         sqlite3VdbeMemIntegerify(pTos);
  2829         -      iKey = intToKey(pTos->i);
         2829  +      iKey = intToKey(pTos->u.i);
  2830   2830         if( pOp->p2==0 && pOp->opcode==OP_MoveGe ){
  2831   2831           pC->movetoTarget = iKey;
  2832   2832           pC->deferredMoveto = 1;
  2833   2833           assert( (pTos->flags & MEM_Dyn)==0 );
  2834   2834           pTos--;
  2835   2835           break;
  2836   2836         }
  2837   2837         rc = sqlite3BtreeMoveto(pC->pCursor, 0, (u64)iKey, 0, &res);
  2838   2838         if( rc!=SQLITE_OK ){
  2839   2839           goto abort_due_to_error;
  2840   2840         }
  2841         -      pC->lastRowid = pTos->i;
         2841  +      pC->lastRowid = pTos->u.i;
  2842   2842         pC->rowidIsValid = res==0;
  2843   2843       }else{
  2844   2844         assert( pTos->flags & MEM_Blob );
  2845   2845         /* Stringify(pTos, encoding); */
  2846   2846         rc = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, 0, &res);
  2847   2847         if( rc!=SQLITE_OK ){
  2848   2848           goto abort_due_to_error;
................................................................................
  2995   2995     BtCursor *pCrsr;
  2996   2996     i64 R;
  2997   2997   
  2998   2998     /* Pop the value R off the top of the stack
  2999   2999     */
  3000   3000     assert( pNos>=p->aStack );
  3001   3001     sqlite3VdbeMemIntegerify(pTos);
  3002         -  R = pTos->i;
         3002  +  R = pTos->u.i;
  3003   3003     assert( (pTos->flags & MEM_Dyn)==0 );
  3004   3004     pTos--;
  3005   3005     assert( i>=0 && i<p->nCursor );
  3006   3006     pCx = p->apCsr[i];
  3007   3007     assert( pCx!=0 );
  3008   3008     pCrsr = pCx->pCursor;
  3009   3009     if( pCrsr!=0 ){
................................................................................
  3061   3061       }
  3062   3062   
  3063   3063       /* The final varint of the key is different from R.  Push it onto
  3064   3064       ** the stack.  (The record number of an entry that violates a UNIQUE
  3065   3065       ** constraint.)
  3066   3066       */
  3067   3067       pTos++;
  3068         -    pTos->i = v;
         3068  +    pTos->u.i = v;
  3069   3069       pTos->flags = MEM_Int;
  3070   3070     }
  3071   3071     break;
  3072   3072   }
  3073   3073   
  3074   3074   /* Opcode: NotExists P1 P2 *
  3075   3075   **
................................................................................
  3093   3093     assert( i>=0 && i<p->nCursor );
  3094   3094     assert( p->apCsr[i]!=0 );
  3095   3095     if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
  3096   3096       int res;
  3097   3097       u64 iKey;
  3098   3098       assert( pTos->flags & MEM_Int );
  3099   3099       assert( p->apCsr[i]->isTable );
  3100         -    iKey = intToKey(pTos->i);
         3100  +    iKey = intToKey(pTos->u.i);
  3101   3101       rc = sqlite3BtreeMoveto(pCrsr, 0, iKey, 0,&res);
  3102         -    pC->lastRowid = pTos->i;
         3102  +    pC->lastRowid = pTos->u.i;
  3103   3103       pC->rowidIsValid = res==0;
  3104   3104       pC->nullRow = 0;
  3105   3105       pC->cacheStatus = CACHE_STALE;
  3106   3106       /* res might be uninitialized if rc!=SQLITE_OK.  But if rc!=SQLITE_OK
  3107   3107       ** processing is about to abort so we really do not care whether or not
  3108   3108       ** the following jump is taken. */
  3109   3109       if( res!=0 ){
................................................................................
  3124   3124   */
  3125   3125   case OP_Sequence: {
  3126   3126     int i = pOp->p1;
  3127   3127     assert( pTos>=p->aStack );
  3128   3128     assert( i>=0 && i<p->nCursor );
  3129   3129     assert( p->apCsr[i]!=0 );
  3130   3130     pTos++;
  3131         -  pTos->i = p->apCsr[i]->seqCount++;
         3131  +  pTos->u.i = p->apCsr[i]->seqCount++;
  3132   3132     pTos->flags = MEM_Int;
  3133   3133     break;
  3134   3134   }
  3135   3135   
  3136   3136   
  3137   3137   /* Opcode: NewRowid P1 P2 *
  3138   3138   **
................................................................................
  3233   3233   #ifndef SQLITE_OMIT_AUTOINCREMENT
  3234   3234         if( pOp->p2 ){
  3235   3235           Mem *pMem;
  3236   3236           assert( pOp->p2>0 && pOp->p2<p->nMem );  /* P2 is a valid memory cell */
  3237   3237           pMem = &p->aMem[pOp->p2];
  3238   3238           sqlite3VdbeMemIntegerify(pMem);
  3239   3239           assert( (pMem->flags & MEM_Int)!=0 );  /* mem(P2) holds an integer */
  3240         -        if( pMem->i==MAX_ROWID || pC->useRandomRowid ){
         3240  +        if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
  3241   3241             rc = SQLITE_FULL;
  3242   3242             goto abort_due_to_error;
  3243   3243           }
  3244         -        if( v<pMem->i+1 ){
  3245         -          v = pMem->i + 1;
         3244  +        if( v<pMem->u.i+1 ){
         3245  +          v = pMem->u.i + 1;
  3246   3246           }
  3247         -        pMem->i = v;
         3247  +        pMem->u.i = v;
  3248   3248         }
  3249   3249   #endif
  3250   3250   
  3251   3251         if( v<MAX_ROWID ){
  3252   3252           pC->nextRowidValid = 1;
  3253   3253           pC->nextRowid = v+1;
  3254   3254         }else{
................................................................................
  3280   3280         }
  3281   3281       }
  3282   3282       pC->rowidIsValid = 0;
  3283   3283       pC->deferredMoveto = 0;
  3284   3284       pC->cacheStatus = CACHE_STALE;
  3285   3285     }
  3286   3286     pTos++;
  3287         -  pTos->i = v;
         3287  +  pTos->u.i = v;
  3288   3288     pTos->flags = MEM_Int;
  3289   3289     break;
  3290   3290   }
  3291   3291   
  3292   3292   /* Opcode: Insert P1 P2 P3
  3293   3293   **
  3294   3294   ** Write an entry into the table of cursor P1.  A new entry is
................................................................................
  3317   3317     assert( i>=0 && i<p->nCursor );
  3318   3318     assert( p->apCsr[i]!=0 );
  3319   3319     if( ((pC = p->apCsr[i])->pCursor!=0 || pC->pseudoTable) ){
  3320   3320       i64 iKey;   /* The integer ROWID or key for the record to be inserted */
  3321   3321   
  3322   3322       assert( pNos->flags & MEM_Int );
  3323   3323       assert( pC->isTable );
  3324         -    iKey = intToKey(pNos->i);
         3324  +    iKey = intToKey(pNos->u.i);
  3325   3325   
  3326   3326       if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
  3327         -    if( pOp->p2 & OPFLAG_LASTROWID ) db->lastRowid = pNos->i;
  3328         -    if( pC->nextRowidValid && pNos->i>=pC->nextRowid ){
         3327  +    if( pOp->p2 & OPFLAG_LASTROWID ) db->lastRowid = pNos->u.i;
         3328  +    if( pC->nextRowidValid && pNos->u.i>=pC->nextRowid ){
  3329   3329         pC->nextRowidValid = 0;
  3330   3330       }
  3331   3331       if( pTos->flags & MEM_Null ){
  3332   3332         pTos->z = 0;
  3333   3333         pTos->n = 0;
  3334   3334       }else{
  3335   3335         assert( pTos->flags & (MEM_Blob|MEM_Str) );
................................................................................
  3545   3545       pTos->flags = MEM_Null;
  3546   3546       break;
  3547   3547     }else{
  3548   3548       assert( pC->pCursor!=0 );
  3549   3549       sqlite3BtreeKeySize(pC->pCursor, &v);
  3550   3550       v = keyToInt(v);
  3551   3551     }
  3552         -  pTos->i = v;
         3552  +  pTos->u.i = v;
  3553   3553     pTos->flags = MEM_Int;
  3554   3554     break;
  3555   3555   }
  3556   3556   
  3557   3557   /* Opcode: NullRow P1 * *
  3558   3558   **
  3559   3559   ** Move the cursor P1 to a null row.  Any OP_Column operations
................................................................................
  3793   3793         pTos->flags = MEM_Null;
  3794   3794       }else{
  3795   3795         rc = sqlite3VdbeIdxRowid(pCrsr, &rowid);
  3796   3796         if( rc!=SQLITE_OK ){
  3797   3797           goto abort_due_to_error;
  3798   3798         }
  3799   3799         pTos->flags = MEM_Int;
  3800         -      pTos->i = rowid;
         3800  +      pTos->u.i = rowid;
  3801   3801       }
  3802   3802     }
  3803   3803     break;
  3804   3804   }
  3805   3805   
  3806   3806   /* Opcode: IdxGT P1 P2 *
  3807   3807   **
................................................................................
  3920   3920     if( iCnt>1 ){
  3921   3921       rc = SQLITE_LOCKED;
  3922   3922     }else{
  3923   3923       assert( iCnt==1 );
  3924   3924       rc = sqlite3BtreeDropTable(db->aDb[pOp->p2].pBt, pOp->p1, &iMoved);
  3925   3925       pTos++;
  3926   3926       pTos->flags = MEM_Int;
  3927         -    pTos->i = iMoved;
         3927  +    pTos->u.i = iMoved;
  3928   3928   #ifndef SQLITE_OMIT_AUTOVACUUM
  3929   3929       if( rc==SQLITE_OK && iMoved!=0 ){
  3930   3930         sqlite3RootPageMoved(&db->aDb[pOp->p2], iMoved, pOp->p1);
  3931   3931       }
  3932   3932   #endif
  3933   3933     }
  3934   3934     break;
................................................................................
  4019   4019       flags = BTREE_LEAFDATA|BTREE_INTKEY;
  4020   4020     }else{
  4021   4021       flags = BTREE_ZERODATA;
  4022   4022     }
  4023   4023     rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
  4024   4024     pTos++;
  4025   4025     if( rc==SQLITE_OK ){
  4026         -    pTos->i = pgno;
         4026  +    pTos->u.i = pgno;
  4027   4027       pTos->flags = MEM_Int;
  4028   4028     }else{
  4029   4029       pTos->flags = MEM_Null;
  4030   4030     }
  4031   4031     break;
  4032   4032   }
  4033   4033   
................................................................................
  4166   4166     if( aRoot==0 ) goto no_mem;
  4167   4167     j = pOp->p1;
  4168   4168     assert( j>=0 && j<p->nMem );
  4169   4169     pnErr = &p->aMem[j];
  4170   4170     assert( (pnErr->flags & MEM_Int)!=0 );
  4171   4171     for(j=0; j<nRoot; j++){
  4172   4172       Mem *pMem = &pTos[-j];
  4173         -    aRoot[j] = pMem->i;
         4173  +    aRoot[j] = pMem->u.i;
  4174   4174     }
  4175   4175     aRoot[j] = 0;
  4176   4176     popStack(&pTos, nRoot);
  4177   4177     pTos++;
  4178   4178     z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p2].pBt, aRoot, nRoot,
  4179         -                                 pnErr->i, &nErr);
  4180         -  pnErr->i -= nErr;
         4179  +                                 pnErr->u.i, &nErr);
         4180  +  pnErr->u.i -= nErr;
  4181   4181     if( nErr==0 ){
  4182   4182       assert( z==0 );
  4183   4183       pTos->flags = MEM_Null;
  4184   4184     }else{
  4185   4185       pTos->z = z;
  4186   4186       pTos->n = strlen(z);
  4187   4187       pTos->flags = MEM_Str | MEM_Dyn | MEM_Term;
................................................................................
  4198   4198   **
  4199   4199   ** Write the integer on the top of the stack
  4200   4200   ** into the Fifo.
  4201   4201   */
  4202   4202   case OP_FifoWrite: {        /* no-push */
  4203   4203     assert( pTos>=p->aStack );
  4204   4204     sqlite3VdbeMemIntegerify(pTos);
  4205         -  sqlite3VdbeFifoPush(&p->sFifo, pTos->i);
         4205  +  sqlite3VdbeFifoPush(&p->sFifo, pTos->u.i);
  4206   4206     assert( (pTos->flags & MEM_Dyn)==0 );
  4207   4207     pTos--;
  4208   4208     break;
  4209   4209   }
  4210   4210   
  4211   4211   /* Opcode: FifoRead * P2 *
  4212   4212   **
................................................................................
  4217   4217   case OP_FifoRead: {
  4218   4218     i64 v;
  4219   4219     CHECK_FOR_INTERRUPT;
  4220   4220     if( sqlite3VdbeFifoPop(&p->sFifo, &v)==SQLITE_DONE ){
  4221   4221       pc = pOp->p2 - 1;
  4222   4222     }else{
  4223   4223       pTos++;
  4224         -    pTos->i = v;
         4224  +    pTos->u.i = v;
  4225   4225       pTos->flags = MEM_Int;
  4226   4226     }
  4227   4227     break;
  4228   4228   }
  4229   4229   
  4230   4230   #ifndef SQLITE_OMIT_TRIGGER
  4231   4231   /* Opcode: ContextPush * * * 
................................................................................
  4324   4324     int i = pOp->p1;
  4325   4325     Mem *pMem;
  4326   4326     assert( pTos>=p->aStack );
  4327   4327     assert( i>=0 && i<p->nMem );
  4328   4328     pMem = &p->aMem[i];
  4329   4329     sqlite3VdbeMemIntegerify(pMem);
  4330   4330     sqlite3VdbeMemIntegerify(pTos);
  4331         -  if( pMem->i<pTos->i){
  4332         -    pMem->i = pTos->i;
         4331  +  if( pMem->u.i<pTos->u.i){
         4332  +    pMem->u.i = pTos->u.i;
  4333   4333     }
  4334   4334     break;
  4335   4335   }
  4336   4336   #endif /* SQLITE_OMIT_AUTOINCREMENT */
  4337   4337   
  4338   4338   /* Opcode: MemIncr P1 P2 *
  4339   4339   **
................................................................................
  4344   4344   */
  4345   4345   case OP_MemIncr: {        /* no-push */
  4346   4346     int i = pOp->p2;
  4347   4347     Mem *pMem;
  4348   4348     assert( i>=0 && i<p->nMem );
  4349   4349     pMem = &p->aMem[i];
  4350   4350     assert( pMem->flags==MEM_Int );
  4351         -  pMem->i += pOp->p1;
         4351  +  pMem->u.i += pOp->p1;
  4352   4352     break;
  4353   4353   }
  4354   4354   
  4355   4355   /* Opcode: IfMemPos P1 P2 *
  4356   4356   **
  4357   4357   ** If the value of memory cell P1 is 1 or greater, jump to P2.
  4358   4358   **
................................................................................
  4361   4361   */
  4362   4362   case OP_IfMemPos: {        /* no-push */
  4363   4363     int i = pOp->p1;
  4364   4364     Mem *pMem;
  4365   4365     assert( i>=0 && i<p->nMem );
  4366   4366     pMem = &p->aMem[i];
  4367   4367     assert( pMem->flags==MEM_Int );
  4368         -  if( pMem->i>0 ){
         4368  +  if( pMem->u.i>0 ){
  4369   4369        pc = pOp->p2 - 1;
  4370   4370     }
  4371   4371     break;
  4372   4372   }
  4373   4373   
  4374   4374   /* Opcode: IfMemNeg P1 P2 *
  4375   4375   **
................................................................................
  4380   4380   */
  4381   4381   case OP_IfMemNeg: {        /* no-push */
  4382   4382     int i = pOp->p1;
  4383   4383     Mem *pMem;
  4384   4384     assert( i>=0 && i<p->nMem );
  4385   4385     pMem = &p->aMem[i];
  4386   4386     assert( pMem->flags==MEM_Int );
  4387         -  if( pMem->i<0 ){
         4387  +  if( pMem->u.i<0 ){
  4388   4388        pc = pOp->p2 - 1;
  4389   4389     }
  4390   4390     break;
  4391   4391   }
  4392   4392   
  4393   4393   /* Opcode: IfMemZero P1 P2 *
  4394   4394   **
................................................................................
  4399   4399   */
  4400   4400   case OP_IfMemZero: {        /* no-push */
  4401   4401     int i = pOp->p1;
  4402   4402     Mem *pMem;
  4403   4403     assert( i>=0 && i<p->nMem );
  4404   4404     pMem = &p->aMem[i];
  4405   4405     assert( pMem->flags==MEM_Int );
  4406         -  if( pMem->i==0 ){
         4406  +  if( pMem->u.i==0 ){
  4407   4407        pc = pOp->p2 - 1;
  4408   4408     }
  4409   4409     break;
  4410   4410   }
  4411   4411   
  4412   4412   /* Opcode: MemNull P1 * *
  4413   4413   **
................................................................................
  4686   4686     Cursor *pCur = p->apCsr[pOp->p1];
  4687   4687     assert( pCur->pVtabCursor );
  4688   4688     pModule = pCur->pVtabCursor->pVtab->pModule;
  4689   4689   
  4690   4690     /* Grab the index number and argc parameters off the top of the stack. */
  4691   4691     assert( (&pTos[-1])>=p->aStack );
  4692   4692     assert( (pTos[0].flags&MEM_Int)!=0 && pTos[-1].flags==MEM_Int );
  4693         -  nArg = pTos[-1].i;
         4693  +  nArg = pTos[-1].u.i;
  4694   4694   
  4695   4695     /* Invoke the xFilter method */
  4696   4696     {
  4697   4697       int res = 0;
  4698   4698       int i;
  4699   4699       Mem **apArg = p->apArg;
  4700   4700       for(i = 0; i<nArg; i++){
  4701   4701         apArg[i] = &pTos[i+1-2-nArg];
  4702   4702         storeTypeInfo(apArg[i], 0);
  4703   4703       }
  4704   4704   
  4705   4705       if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
  4706   4706       p->inVtabMethod = 1;
  4707         -    rc = pModule->xFilter(pCur->pVtabCursor, pTos->i, pOp->p3, nArg, apArg);
         4707  +    rc = pModule->xFilter(pCur->pVtabCursor, pTos->u.i, pOp->p3, nArg, apArg);
  4708   4708       p->inVtabMethod = 0;
  4709   4709       if( rc==SQLITE_OK ){
  4710   4710         res = pModule->xEof(pCur->pVtabCursor);
  4711   4711       }
  4712   4712       if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
  4713   4713   
  4714   4714       if( res ){
................................................................................
  4742   4742   
  4743   4743       if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
  4744   4744       rc = pModule->xRowid(pCur->pVtabCursor, &iRow);
  4745   4745       if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
  4746   4746   
  4747   4747       pTos++;
  4748   4748       pTos->flags = MEM_Int;
  4749         -    pTos->i = iRow;
         4749  +    pTos->u.i = iRow;
  4750   4750     }
  4751   4751   
  4752   4752     break;
  4753   4753   }
  4754   4754   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  4755   4755   
  4756   4756   #ifndef SQLITE_OMIT_VIRTUALTABLE
................................................................................
  4941   4941       if( p->trace && pTos>=p->aStack ){
  4942   4942         int i;
  4943   4943         fprintf(p->trace, "Stack:");
  4944   4944         for(i=0; i>-5 && &pTos[i]>=p->aStack; i--){
  4945   4945           if( pTos[i].flags & MEM_Null ){
  4946   4946             fprintf(p->trace, " NULL");
  4947   4947           }else if( (pTos[i].flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
  4948         -          fprintf(p->trace, " si:%lld", pTos[i].i);
         4948  +          fprintf(p->trace, " si:%lld", pTos[i].u.i);
  4949   4949           }else if( pTos[i].flags & MEM_Int ){
  4950         -          fprintf(p->trace, " i:%lld", pTos[i].i);
         4950  +          fprintf(p->trace, " i:%lld", pTos[i].u.i);
  4951   4951           }else if( pTos[i].flags & MEM_Real ){
  4952   4952             fprintf(p->trace, " r:%g", pTos[i].r);
  4953   4953           }else{
  4954   4954             char zBuf[100];
  4955   4955             sqlite3VdbeMemPrettyPrint(&pTos[i], zBuf);
  4956   4956             fprintf(p->trace, " ");
  4957   4957             fprintf(p->trace, "%s", zBuf);

Changes to src/vdbeInt.h.

   123    123   ** in a Mem struct is returned by the MemType(Mem*) macro. The type is
   124    124   ** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
   125    125   ** SQLITE_BLOB.
   126    126   */
   127    127   struct Mem {
   128    128     union {
   129    129       i64 i;              /* Integer value. Or FuncDef* when flags==MEM_Agg */
   130         -    FuncDef *pDef;
   131         -  };
          130  +    FuncDef *pDef;      /* Used only when flags==MEM_Agg */
          131  +  } u;
   132    132     double r;           /* Real value */
   133    133     char *z;            /* String or BLOB value */
   134    134     int n;              /* Number of characters in string value, including '\0' */
   135    135     u16 flags;          /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
   136    136     u8  type;           /* One of MEM_Null, MEM_Str, etc. */
   137    137     u8  enc;            /* TEXT_Utf8, TEXT_Utf16le, or TEXT_Utf16be */
   138    138     void (*xDel)(void *);  /* If not null, call this function to delete Mem.z */

Changes to src/vdbeapi.c.

   337    337     if( (pMem->flags & MEM_Agg)==0 ){
   338    338       if( nByte==0 ){
   339    339         assert( pMem->flags==MEM_Null );
   340    340         pMem->z = 0;
   341    341       }else{
   342    342         pMem->flags = MEM_Agg;
   343    343         pMem->xDel = sqlite3FreeX;
   344         -      pMem->pDef = p->pFunc;
          344  +      pMem->u.pDef = p->pFunc;
   345    345         if( nByte<=NBFS ){
   346    346           pMem->z = pMem->zShort;
   347    347           memset(pMem->z, 0, nByte);
   348    348         }else{
   349    349           pMem->z = sqliteMalloc( nByte );
   350    350         }
   351    351       }

Changes to src/vdbeaux.c.

   715    715       rc = SQLITE_ERROR;
   716    716       sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(p->rc), (char*)0);
   717    717     }else{
   718    718       Op *pOp = &p->aOp[i];
   719    719       Mem *pMem = p->aStack;
   720    720       pMem->flags = MEM_Int;
   721    721       pMem->type = SQLITE_INTEGER;
   722         -    pMem->i = i;                                /* Program counter */
          722  +    pMem->u.i = i;                                /* Program counter */
   723    723       pMem++;
   724    724   
   725    725       pMem->flags = MEM_Static|MEM_Str|MEM_Term;
   726    726       pMem->z = (char*)sqlite3OpcodeNames[pOp->opcode];  /* Opcode */
   727    727       assert( pMem->z!=0 );
   728    728       pMem->n = strlen(pMem->z);
   729    729       pMem->type = SQLITE_TEXT;
   730    730       pMem->enc = SQLITE_UTF8;
   731    731       pMem++;
   732    732   
   733    733       pMem->flags = MEM_Int;
   734         -    pMem->i = pOp->p1;                          /* P1 */
          734  +    pMem->u.i = pOp->p1;                          /* P1 */
   735    735       pMem->type = SQLITE_INTEGER;
   736    736       pMem++;
   737    737   
   738    738       pMem->flags = MEM_Int;
   739         -    pMem->i = pOp->p2;                          /* P2 */
          739  +    pMem->u.i = pOp->p2;                          /* P2 */
   740    740       pMem->type = SQLITE_INTEGER;
   741    741       pMem++;
   742    742   
   743    743       pMem->flags = MEM_Ephem|MEM_Str|MEM_Term;   /* P3 */
   744    744       pMem->z = displayP3(pOp, pMem->zShort, sizeof(pMem->zShort));
   745    745       assert( pMem->z!=0 );
   746    746       pMem->n = strlen(pMem->z);
................................................................................
  1735   1735   
  1736   1736     if( flags&MEM_Null ){
  1737   1737       return 0;
  1738   1738     }
  1739   1739     if( flags&MEM_Int ){
  1740   1740       /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
  1741   1741   #   define MAX_6BYTE ((((i64)0x00001000)<<32)-1)
  1742         -    i64 i = pMem->i;
         1742  +    i64 i = pMem->u.i;
  1743   1743       u64 u;
  1744   1744       if( file_format>=4 && (i&1)==i ){
  1745   1745         return 8+i;
  1746   1746       }
  1747   1747       u = i<0 ? -i : i;
  1748   1748       if( u<=127 ) return 1;
  1749   1749       if( u<=32767 ) return 2;
................................................................................
  1791   1791     if( serial_type<=7 && serial_type>0 ){
  1792   1792       u64 v;
  1793   1793       int i;
  1794   1794       if( serial_type==7 ){
  1795   1795         assert( sizeof(v)==sizeof(pMem->r) );
  1796   1796         memcpy(&v, &pMem->r, sizeof(v));
  1797   1797       }else{
  1798         -      v = pMem->i;
         1798  +      v = pMem->u.i;
  1799   1799       }
  1800   1800       len = i = sqlite3VdbeSerialTypeLen(serial_type);
  1801   1801       while( i-- ){
  1802   1802         buf[i] = (v&0xFF);
  1803   1803         v >>= 8;
  1804   1804       }
  1805   1805       return len;
................................................................................
  1829   1829       case 10:   /* Reserved for future use */
  1830   1830       case 11:   /* Reserved for future use */
  1831   1831       case 0: {  /* NULL */
  1832   1832         pMem->flags = MEM_Null;
  1833   1833         break;
  1834   1834       }
  1835   1835       case 1: { /* 1-byte signed integer */
  1836         -      pMem->i = (signed char)buf[0];
         1836  +      pMem->u.i = (signed char)buf[0];
  1837   1837         pMem->flags = MEM_Int;
  1838   1838         return 1;
  1839   1839       }
  1840   1840       case 2: { /* 2-byte signed integer */
  1841         -      pMem->i = (((signed char)buf[0])<<8) | buf[1];
         1841  +      pMem->u.i = (((signed char)buf[0])<<8) | buf[1];
  1842   1842         pMem->flags = MEM_Int;
  1843   1843         return 2;
  1844   1844       }
  1845   1845       case 3: { /* 3-byte signed integer */
  1846         -      pMem->i = (((signed char)buf[0])<<16) | (buf[1]<<8) | buf[2];
         1846  +      pMem->u.i = (((signed char)buf[0])<<16) | (buf[1]<<8) | buf[2];
  1847   1847         pMem->flags = MEM_Int;
  1848   1848         return 3;
  1849   1849       }
  1850   1850       case 4: { /* 4-byte signed integer */
  1851         -      pMem->i = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
         1851  +      pMem->u.i = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
  1852   1852         pMem->flags = MEM_Int;
  1853   1853         return 4;
  1854   1854       }
  1855   1855       case 5: { /* 6-byte signed integer */
  1856   1856         u64 x = (((signed char)buf[0])<<8) | buf[1];
  1857   1857         u32 y = (buf[2]<<24) | (buf[3]<<16) | (buf[4]<<8) | buf[5];
  1858   1858         x = (x<<32) | y;
  1859         -      pMem->i = *(i64*)&x;
         1859  +      pMem->u.i = *(i64*)&x;
  1860   1860         pMem->flags = MEM_Int;
  1861   1861         return 6;
  1862   1862       }
  1863   1863       case 6:   /* 8-byte signed integer */
  1864   1864       case 7: { /* IEEE floating point */
  1865   1865         u64 x;
  1866   1866         u32 y;
................................................................................
  1873   1873         assert( sizeof(r1)==sizeof(t1) && memcmp(&r1, &t1, sizeof(r1))==0 );
  1874   1874   #endif
  1875   1875   
  1876   1876         x = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
  1877   1877         y = (buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7];
  1878   1878         x = (x<<32) | y;
  1879   1879         if( serial_type==6 ){
  1880         -        pMem->i = *(i64*)&x;
         1880  +        pMem->u.i = *(i64*)&x;
  1881   1881           pMem->flags = MEM_Int;
  1882   1882         }else{
  1883   1883           assert( sizeof(x)==8 && sizeof(pMem->r)==8 );
  1884   1884           memcpy(&pMem->r, &x, sizeof(x));
  1885   1885           /* pMem->r = *(double*)&x; */
  1886   1886           pMem->flags = MEM_Real;
  1887   1887         }
  1888   1888         return 8;
  1889   1889       }
  1890   1890       case 8:    /* Integer 0 */
  1891   1891       case 9: {  /* Integer 1 */
  1892         -      pMem->i = serial_type-8;
         1892  +      pMem->u.i = serial_type-8;
  1893   1893         pMem->flags = MEM_Int;
  1894   1894         return 0;
  1895   1895       }
  1896   1896       default: {
  1897   1897         int len = (serial_type-12)/2;
  1898   1898         pMem->z = (char *)buf;
  1899   1899         pMem->n = len;
................................................................................
  2041   2041     if( rc ){
  2042   2042       return rc;
  2043   2043     }
  2044   2044     sqlite3GetVarint32((u8*)m.z, &szHdr);
  2045   2045     sqlite3GetVarint32((u8*)&m.z[szHdr-1], &typeRowid);
  2046   2046     lenRowid = sqlite3VdbeSerialTypeLen(typeRowid);
  2047   2047     sqlite3VdbeSerialGet((u8*)&m.z[m.n-lenRowid], typeRowid, &v);
  2048         -  *rowid = v.i;
         2048  +  *rowid = v.u.i;
  2049   2049     sqlite3VdbeMemRelease(&m);
  2050   2050     return SQLITE_OK;
  2051   2051   }
  2052   2052   
  2053   2053   /*
  2054   2054   ** Compare the key of the index entry that cursor pC is point to against
  2055   2055   ** the key string in pKey (of length nKey).  Write into *pRes a number

Changes to src/vdbemem.c.

   166    166     /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
   167    167     ** string representation of the value. Then, if the required encoding
   168    168     ** is UTF-16le or UTF-16be do a translation.
   169    169     ** 
   170    170     ** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
   171    171     */
   172    172     if( fg & MEM_Int ){
   173         -    sqlite3_snprintf(NBFS, z, "%lld", pMem->i);
          173  +    sqlite3_snprintf(NBFS, z, "%lld", pMem->u.i);
   174    174     }else{
   175    175       assert( fg & MEM_Real );
   176    176       sqlite3_snprintf(NBFS, z, "%!.15g", pMem->r);
   177    177     }
   178    178     pMem->n = strlen(z);
   179    179     pMem->z = z;
   180    180     pMem->enc = SQLITE_UTF8;
................................................................................
   191    191   ** Return SQLITE_ERROR if the finalizer reports an error.  SQLITE_OK
   192    192   ** otherwise.
   193    193   */
   194    194   int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
   195    195     int rc = SQLITE_OK;
   196    196     if( pFunc && pFunc->xFinalize ){
   197    197       sqlite3_context ctx;
   198         -    assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->pDef );
          198  +    assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
   199    199       ctx.s.flags = MEM_Null;
   200    200       ctx.s.z = pMem->zShort;
   201    201       ctx.pMem = pMem;
   202    202       ctx.pFunc = pFunc;
   203    203       ctx.isError = 0;
   204    204       pFunc->xFinalize(&ctx);
   205    205       if( pMem->z && pMem->z!=pMem->zShort ){
................................................................................
   221    221   ** inconsistent state, for example with (Mem.z==0) and
   222    222   ** (Mem.type==SQLITE_TEXT).
   223    223   */
   224    224   void sqlite3VdbeMemRelease(Mem *p){
   225    225     if( p->flags & (MEM_Dyn|MEM_Agg) ){
   226    226       if( p->xDel ){
   227    227         if( p->flags & MEM_Agg ){
   228         -        sqlite3VdbeMemFinalize(p, p->pDef);
          228  +        sqlite3VdbeMemFinalize(p, p->u.pDef);
   229    229           assert( (p->flags & MEM_Agg)==0 );
   230    230           sqlite3VdbeMemRelease(p);
   231    231         }else{
   232    232           p->xDel((void *)p->z);
   233    233         }
   234    234       }else{
   235    235         sqliteFree(p->z);
................................................................................
   248    248   ** it into a integer and return that.  If pMem is NULL, return 0.
   249    249   **
   250    250   ** If pMem is a string, its encoding might be changed.
   251    251   */
   252    252   i64 sqlite3VdbeIntValue(Mem *pMem){
   253    253     int flags = pMem->flags;
   254    254     if( flags & MEM_Int ){
   255         -    return pMem->i;
          255  +    return pMem->u.i;
   256    256     }else if( flags & MEM_Real ){
   257    257       return (i64)pMem->r;
   258    258     }else if( flags & (MEM_Str|MEM_Blob) ){
   259    259       i64 value;
   260    260       if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
   261    261          || sqlite3VdbeMemNulTerminate(pMem) ){
   262    262         return 0;
................................................................................
   275    275   ** value.  If it is a string or blob, try to convert it to a double.
   276    276   ** If it is a NULL, return 0.0.
   277    277   */
   278    278   double sqlite3VdbeRealValue(Mem *pMem){
   279    279     if( pMem->flags & MEM_Real ){
   280    280       return pMem->r;
   281    281     }else if( pMem->flags & MEM_Int ){
   282         -    return (double)pMem->i;
          282  +    return (double)pMem->u.i;
   283    283     }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
   284    284       double val = 0.0;
   285    285       if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
   286    286          || sqlite3VdbeMemNulTerminate(pMem) ){
   287    287         return 0.0;
   288    288       }
   289    289       assert( pMem->z );
................................................................................
   296    296   
   297    297   /*
   298    298   ** The MEM structure is already a MEM_Real.  Try to also make it a
   299    299   ** MEM_Int if we can.
   300    300   */
   301    301   void sqlite3VdbeIntegerAffinity(Mem *pMem){
   302    302     assert( pMem->flags & MEM_Real );
   303         -  pMem->i = pMem->r;
   304         -  if( ((double)pMem->i)==pMem->r ){
          303  +  pMem->u.i = pMem->r;
          304  +  if( ((double)pMem->u.i)==pMem->r ){
   305    305       pMem->flags |= MEM_Int;
   306    306     }
   307    307   }
   308    308   
   309    309   /*
   310    310   ** Convert pMem to type integer.  Invalidate any prior representations.
   311    311   */
   312    312   int sqlite3VdbeMemIntegerify(Mem *pMem){
   313         -  pMem->i = sqlite3VdbeIntValue(pMem);
          313  +  pMem->u.i = sqlite3VdbeIntValue(pMem);
   314    314     sqlite3VdbeMemRelease(pMem);
   315    315     pMem->flags = MEM_Int;
   316    316     return SQLITE_OK;
   317    317   }
   318    318   
   319    319   /*
   320    320   ** Convert pMem so that it is of type MEM_Real.
................................................................................
   349    349   
   350    350   /*
   351    351   ** Delete any previous value and set the value stored in *pMem to val,
   352    352   ** manifest type INTEGER.
   353    353   */
   354    354   void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
   355    355     sqlite3VdbeMemRelease(pMem);
   356         -  pMem->i = val;
          356  +  pMem->u.i = val;
   357    357     pMem->flags = MEM_Int;
   358    358     pMem->type = SQLITE_INTEGER;
   359    359   }
   360    360   
   361    361   /*
   362    362   ** Delete any previous value and set the value stored in *pMem to val,
   363    363   ** manifest type REAL.
................................................................................
   534    534       }
   535    535       if( !(f2&(MEM_Int|MEM_Real)) ){
   536    536         return -1;
   537    537       }
   538    538       if( (f1 & f2 & MEM_Int)==0 ){
   539    539         double r1, r2;
   540    540         if( (f1&MEM_Real)==0 ){
   541         -        r1 = pMem1->i;
          541  +        r1 = pMem1->u.i;
   542    542         }else{
   543    543           r1 = pMem1->r;
   544    544         }
   545    545         if( (f2&MEM_Real)==0 ){
   546         -        r2 = pMem2->i;
          546  +        r2 = pMem2->u.i;
   547    547         }else{
   548    548           r2 = pMem2->r;
   549    549         }
   550    550         if( r1<r2 ) return -1;
   551    551         if( r1>r2 ) return 1;
   552    552         return 0;
   553    553       }else{
   554    554         assert( f1&MEM_Int );
   555    555         assert( f2&MEM_Int );
   556         -      if( pMem1->i < pMem2->i ) return -1;
   557         -      if( pMem1->i > pMem2->i ) return 1;
          556  +      if( pMem1->u.i < pMem2->u.i ) return -1;
          557  +      if( pMem1->u.i > pMem2->u.i ) return 1;
   558    558         return 0;
   559    559       }
   560    560     }
   561    561   
   562    562     /* If one value is a string and the other is a blob, the string is less.
   563    563     ** If both are strings, compare using the collating functions.
   564    564     */
................................................................................
   731    731       assert( pMem->xDel==0 );
   732    732     }
   733    733     /* MEM_Null excludes all other types */
   734    734     assert( (pMem->flags&(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0
   735    735             || (pMem->flags&MEM_Null)==0 );
   736    736     /* If the MEM is both real and integer, the values are equal */
   737    737     assert( (pMem->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) 
   738         -          || pMem->r==pMem->i );
          738  +          || pMem->r==pMem->u.i );
   739    739   }
   740    740   #endif
   741    741   
   742    742   /* This function is only available internally, it is not part of the
   743    743   ** external API. It works in a similar way to sqlite3_value_text(),
   744    744   ** except the data returned is in the encoding specified by the second
   745    745   ** parameter, which must be one of SQLITE_UTF16BE, SQLITE_UTF16LE or
................................................................................
   827    827       if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
   828    828         sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc);
   829    829       }else{
   830    830         sqlite3ValueApplyAffinity(pVal, affinity, enc);
   831    831       }
   832    832     }else if( op==TK_UMINUS ) {
   833    833       if( SQLITE_OK==sqlite3ValueFromExpr(pExpr->pLeft, enc, affinity, &pVal) ){
   834         -      pVal->i = -1 * pVal->i;
          834  +      pVal->u.i = -1 * pVal->u.i;
   835    835         pVal->r = -1.0 * pVal->r;
   836    836       }
   837    837     }
   838    838   #ifndef SQLITE_OMIT_BLOB_LITERAL
   839    839     else if( op==TK_BLOB ){
   840    840       int nVal;
   841    841       pVal = sqlite3ValueNew();