mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Merge the Mem.r value into the MemValue union as Mem.u.r. Hence, a Mem can
now store an integer or a real but not both at the same time. Strings are still stored in a separate element Mem.z, for now. FossilOrigin-Name: 4c8c89d7e62aecfe2eb735f7bb114aed6b452847
This commit is contained in:
19
src/vdbe.c
19
src/vdbe.c
@@ -243,12 +243,13 @@ static void applyNumericAffinity(Mem *pRec, int bTryForInt){
|
||||
i64 iValue;
|
||||
u8 enc = pRec->enc;
|
||||
if( (pRec->flags&MEM_Str)==0 ) return;
|
||||
if( (pRec->flags&(MEM_Int|MEM_Real))!=0 ) return;
|
||||
if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
|
||||
if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
|
||||
pRec->u.i = iValue;
|
||||
pRec->flags |= MEM_Int;
|
||||
}else{
|
||||
pRec->r = rValue;
|
||||
pRec->u.r = rValue;
|
||||
pRec->flags |= MEM_Real;
|
||||
if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec);
|
||||
}
|
||||
@@ -329,13 +330,13 @@ void sqlite3ValueApplyAffinity(
|
||||
/*
|
||||
** pMem currently only holds a string type (or maybe a BLOB that we can
|
||||
** interpret as a string if we want to). Compute its corresponding
|
||||
** numeric type, if has one. Set the pMem->r and pMem->u.i fields
|
||||
** numeric type, if has one. Set the pMem->u.r and pMem->u.i fields
|
||||
** accordingly.
|
||||
*/
|
||||
static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
|
||||
assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
|
||||
assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
|
||||
if( sqlite3AtoF(pMem->z, &pMem->r, pMem->n, pMem->enc)==0 ){
|
||||
if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
|
||||
return 0;
|
||||
}
|
||||
if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==SQLITE_OK ){
|
||||
@@ -349,7 +350,7 @@ static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
|
||||
** none.
|
||||
**
|
||||
** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
|
||||
** But it does set pMem->r and pMem->u.i appropriately.
|
||||
** But it does set pMem->u.r and pMem->u.i appropriately.
|
||||
*/
|
||||
static u16 numericType(Mem *pMem){
|
||||
if( pMem->flags & (MEM_Int|MEM_Real) ){
|
||||
@@ -459,7 +460,7 @@ static void memTracePrint(Mem *p){
|
||||
printf(" i:%lld", p->u.i);
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
}else if( p->flags & MEM_Real ){
|
||||
printf(" r:%g", p->r);
|
||||
printf(" r:%g", p->u.r);
|
||||
#endif
|
||||
}else if( p->flags & MEM_RowSet ){
|
||||
printf(" (rowset)");
|
||||
@@ -1002,7 +1003,7 @@ case OP_Int64: { /* out2-prerelease */
|
||||
case OP_Real: { /* same as TK_FLOAT, out2-prerelease */
|
||||
pOut->flags = MEM_Real;
|
||||
assert( !sqlite3IsNaN(*pOp->p4.pReal) );
|
||||
pOut->r = *pOp->p4.pReal;
|
||||
pOut->u.r = *pOp->p4.pReal;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -1479,7 +1480,7 @@ fp_math:
|
||||
if( sqlite3IsNaN(rB) ){
|
||||
goto arithmetic_result_is_null;
|
||||
}
|
||||
pOut->r = rB;
|
||||
pOut->u.r = rB;
|
||||
MemSetTypeFlag(pOut, MEM_Real);
|
||||
if( ((type1|type2)&MEM_Real)==0 && !bIntint ){
|
||||
sqlite3VdbeIntegerAffinity(pOut);
|
||||
@@ -3572,7 +3573,7 @@ case OP_SeekGT: { /* jump, in3 */
|
||||
** (x > 4.9) -> (x >= 5)
|
||||
** (x <= 4.9) -> (x < 5)
|
||||
*/
|
||||
if( pIn3->r<(double)iKey ){
|
||||
if( pIn3->u.r<(double)iKey ){
|
||||
assert( OP_SeekGE==(OP_SeekGT-1) );
|
||||
assert( OP_SeekLT==(OP_SeekLE-1) );
|
||||
assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
|
||||
@@ -3581,7 +3582,7 @@ case OP_SeekGT: { /* jump, in3 */
|
||||
|
||||
/* If the approximation iKey is smaller than the actual real search
|
||||
** term, substitute <= for < and > for >=. */
|
||||
else if( pIn3->r>(double)iKey ){
|
||||
else if( pIn3->u.r>(double)iKey ){
|
||||
assert( OP_SeekLE==(OP_SeekLT+1) );
|
||||
assert( OP_SeekGT==(OP_SeekGE+1) );
|
||||
assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
|
||||
|
Reference in New Issue
Block a user