1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Merge all the latest trunk enhancements into the sessions branch.

FossilOrigin-Name: 94fd5bb6da5ef4d850c2ed4ad38afabc5569dae6
This commit is contained in:
drh
2011-03-18 12:35:36 +00:00
45 changed files with 2358 additions and 556 deletions

View File

@@ -1246,19 +1246,12 @@ case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
iA = pIn1->u.i;
iB = pIn2->u.i;
switch( pOp->opcode ){
case OP_Add: iB += iA; break;
case OP_Subtract: iB -= iA; break;
case OP_Multiply: iB *= iA; break;
case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break;
case OP_Divide: {
if( iA==0 ) goto arithmetic_result_is_null;
/* Dividing the largest possible negative 64-bit integer (1<<63) by
** -1 returns an integer too large to store in a 64-bit data-type. On
** some architectures, the value overflows to (1<<63). On others,
** a SIGFPE is issued. The following statement normalizes this
** behavior so that all architectures behave as if integer
** overflow occurred.
*/
if( iA==-1 && iB==SMALLEST_INT64 ) iA = 1;
if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math;
iB /= iA;
break;
}
@@ -1272,6 +1265,7 @@ case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
pOut->u.i = iB;
MemSetTypeFlag(pOut, MEM_Int);
}else{
fp_math:
rA = sqlite3VdbeRealValue(pIn1);
rB = sqlite3VdbeRealValue(pIn2);
switch( pOp->opcode ){
@@ -1466,8 +1460,10 @@ case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
i64 a;
i64 b;
i64 iA;
u64 uA;
i64 iB;
u8 op;
pIn1 = &aMem[pOp->p1];
pIn2 = &aMem[pOp->p2];
@@ -1476,16 +1472,38 @@ case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
sqlite3VdbeMemSetNull(pOut);
break;
}
a = sqlite3VdbeIntValue(pIn2);
b = sqlite3VdbeIntValue(pIn1);
switch( pOp->opcode ){
case OP_BitAnd: a &= b; break;
case OP_BitOr: a |= b; break;
case OP_ShiftLeft: a <<= b; break;
default: assert( pOp->opcode==OP_ShiftRight );
a >>= b; break;
iA = sqlite3VdbeIntValue(pIn2);
iB = sqlite3VdbeIntValue(pIn1);
op = pOp->opcode;
if( op==OP_BitAnd ){
iA &= iB;
}else if( op==OP_BitOr ){
iA |= iB;
}else if( iB!=0 ){
assert( op==OP_ShiftRight || op==OP_ShiftLeft );
/* If shifting by a negative amount, shift in the other direction */
if( iB<0 ){
assert( OP_ShiftRight==OP_ShiftLeft+1 );
op = 2*OP_ShiftLeft + 1 - op;
iB = iB>(-64) ? -iB : 64;
}
if( iB>=64 ){
iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1;
}else{
memcpy(&uA, &iA, sizeof(uA));
if( op==OP_ShiftLeft ){
uA <<= iB;
}else{
uA >>= iB;
/* Sign-extend on a right shift of a negative number */
if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
}
memcpy(&iA, &uA, sizeof(iA));
}
}
pOut->u.i = a;
pOut->u.i = iA;
MemSetTypeFlag(pOut, MEM_Int);
break;
}
@@ -2411,7 +2429,6 @@ case OP_MakeRecord: {
*/
nData = 0; /* Number of bytes of data space */
nHdr = 0; /* Number of bytes of header space */
nByte = 0; /* Data space required for this record */
nZero = 0; /* Number of zero bytes at the end of the record */
nField = pOp->p1;
zAffinity = pOp->p4.z;
@@ -3685,7 +3702,6 @@ case OP_NewRowid: { /* out2-prerelease */
** and try again, up to 100 times.
*/
assert( pC->isTable );
cnt = 0;
#ifdef SQLITE_32BIT_ROWID
# define MAX_ROWID 0x7fffffff