diff --git a/flaim/src/fqdecl.cpp b/flaim/src/fqdecl.cpp index a81529e..26f6d42 100644 --- a/flaim/src/fqdecl.cpp +++ b/flaim/src/fqdecl.cpp @@ -290,8 +290,8 @@ FSTATIC RCODE flmSendCursorWhere( case FLM_UINT32_VAL: if (RC_BAD( rc = gedAddField( pPool, pRootNode, FCS_ITERATOR_NUMBER_VALUE, - (void *)&pQNode->pQAtom->val.uiVal, - 0, FLM_NUMBER_TYPE))) + (void *)&pQNode->pQAtom->val.ui32Val, + 4, FLM_NUMBER_TYPE))) { goto Exit; } @@ -314,7 +314,7 @@ FSTATIC RCODE flmSendCursorWhere( } GedChildGraft( pRootNode, pFldNode, GED_LAST); if (RC_BAD( rc = GedPutINT( pPool, pFldNode, - pQNode->pQAtom->val.iVal))) + (FLMINT)pQNode->pQAtom->val.i32Val))) { goto Exit; } @@ -336,8 +336,8 @@ FSTATIC RCODE flmSendCursorWhere( case FLM_REC_PTR_VAL: if (RC_BAD( rc = gedAddField( pPool, pRootNode, FCS_ITERATOR_REC_PTR_VALUE, - (void *)&pQNode->pQAtom->val.uiVal, - 0, FLM_NUMBER_TYPE))) + (void *)&pQNode->pQAtom->val.ui32Val, + 4, FLM_NUMBER_TYPE))) { goto Exit; } diff --git a/flaim/src/fqeval.cpp b/flaim/src/fqeval.cpp index 12b07e0..13ce673 100644 --- a/flaim/src/fqeval.cpp +++ b/flaim/src/fqeval.cpp @@ -240,7 +240,7 @@ FINLINE FLMUINT64 fqGetUInt64( { if (pValue->eType == FLM_UINT32_VAL) { - return( (FLMUINT64)pValue->val.uiVal); + return( (FLMUINT64)pValue->val.ui32Val); } else if( pValue->eType == FLM_UINT64_VAL) { @@ -255,9 +255,9 @@ FINLINE FLMUINT64 fqGetUInt64( } else if( pValue->eType == FLM_INT32_VAL) { - if( pValue->val.iVal >= 0) + if( pValue->val.i32Val >= 0) { - return( (FLMUINT64)pValue->val.iVal); + return( (FLMUINT64)pValue->val.i32Val); } } @@ -273,7 +273,7 @@ FINLINE FLMINT64 fqGetInt64( { if (pValue->eType == FLM_INT32_VAL) { - return( (FLMINT64)pValue->val.iVal); + return( (FLMINT64)pValue->val.i32Val); } else if( pValue->eType == FLM_INT64_VAL) { @@ -281,7 +281,7 @@ FINLINE FLMINT64 fqGetInt64( } else if( pValue->eType == FLM_UINT32_VAL) { - return( (FLMINT64)pValue->val.uiVal); + return( (FLMINT64)pValue->val.ui32Val); } else if( pValue->eType == FLM_UINT64_VAL) { @@ -305,7 +305,7 @@ FSTATIC void fqOpUUBitAND( { if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) { - pResult->val.uiVal = pLValue->val.uiVal & pRValue->val.uiVal; + pResult->val.ui32Val = pLValue->val.ui32Val & pRValue->val.ui32Val; pResult->eType = FLM_UINT32_VAL; } else @@ -326,7 +326,7 @@ FSTATIC void fqOpUUBitOR( { if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) { - pResult->val.uiVal = pLValue->val.uiVal | pRValue->val.uiVal; + pResult->val.ui32Val = pLValue->val.ui32Val | pRValue->val.ui32Val; pResult->eType = FLM_UINT32_VAL; } else @@ -347,7 +347,7 @@ FSTATIC void fqOpUUBitXOR( { if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) { - pResult->val.uiVal = pLValue->val.uiVal ^ pRValue->val.uiVal; + pResult->val.ui32Val = pLValue->val.ui32Val ^ pRValue->val.ui32Val; pResult->eType = FLM_UINT32_VAL; } else @@ -358,6 +358,45 @@ FSTATIC void fqOpUUBitXOR( } } +/*************************************************************************** +Desc: Put an unsigned result into a result atom. +***************************************************************************/ +FINLINE void setUnsignedResult( + FLMUINT64 ui64Result, + FQATOM * pResult) +{ + if (ui64Result <= (FLMUINT64)(FLM_MAX_UINT32)) + { + pResult->val.ui32Val = (FLMUINT32)ui64Result; + pResult->eType = FLM_UINT32_VAL; + } + else + { + pResult->val.ui64Val = ui64Result; + pResult->eType = FLM_UINT64_VAL; + } +} + +/*************************************************************************** +Desc: Put a signed result into a result atom. +***************************************************************************/ +FINLINE void setSignedResult( + FLMINT64 i64Result, + FQATOM * pResult) +{ + if (i64Result >= (FLMINT64)(FLM_MIN_INT32) && + i64Result <= (FLMINT64)(FLM_MAX_INT32)) + { + pResult->val.i32Val = (FLMINT32)i64Result; + pResult->eType = FLM_INT32_VAL; + } + else + { + pResult->val.i64Val = i64Result; + pResult->eType = FLM_INT64_VAL; + } +} + /*************************************************************************** Desc: Performs the multiply operation ***************************************************************************/ @@ -365,18 +404,9 @@ FSTATIC void fqOpUUMult( FQATOM * pLValue, FQATOM * pRValue, FQATOM * pResult) -{ - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) - { - pResult->val.uiVal = pLValue->val.uiVal * pRValue->val.uiVal; - pResult->eType = FLM_UINT32_VAL; - } - else - { - pResult->val.ui64Val = - fqGetUInt64( pLValue) * fqGetUInt64( pRValue); - pResult->eType = FLM_UINT64_VAL; - } +{ + FLMUINT64 ui64Result = fqGetUInt64( pLValue) * fqGetUInt64( pRValue); + setUnsignedResult( ui64Result, pResult); } /*************************************************************************** @@ -387,16 +417,20 @@ FSTATIC void fqOpUSMult( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMUINT64 ui64Left = fqGetUInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (i64Right < 0) { - pResult->val.iVal = (FLMINT)pLValue->val.uiVal * pRValue->val.iVal; - pResult->eType = FLM_INT32_VAL; + i64Result = (FLMINT64)ui64Left * i64Right; + setSignedResult( i64Result, pResult); } else { - pResult->val.i64Val = (FLMINT64) - fqGetUInt64( pLValue) * fqGetInt64( pRValue); - pResult->eType = FLM_INT64_VAL; + ui64Result = ui64Left * (FLMUINT64)i64Right; + setUnsignedResult( ui64Result, pResult); } } @@ -408,21 +442,57 @@ FSTATIC void fqOpSSMult( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (i64Left < 0) { - pResult->val.iVal = pLValue->val.iVal * pRValue->val.iVal; - pResult->eType = (pResult->val.iVal < 0) - ? FLM_INT32_VAL - : FLM_UINT32_VAL; + if (i64Right < 0) + { + if (i64Left == FLM_MIN_INT64) + { + if (i64Right == FLM_MIN_INT64) + { + // The result will actually overflow, but there is + // nothing we can do about that. + ui64Result = FLM_MAX_UINT64; + } + else + { + i64Right = -i64Right; + ui64Result = ((FLMUINT64)(FLM_MAX_INT64) + 1) * (FLMUINT64)i64Right; + } + } + else if (i64Right == FLM_MIN_INT64) + { + i64Left = -i64Left; + ui64Result = (FLMUINT64)i64Left * ((FLMUINT64)(FLM_MAX_INT64) + 1); + } + else + { + i64Left = -i64Left; + i64Right = -i64Right; + ui64Result = (FLMUINT64)i64Left * (FLMUINT64)i64Right; + } + setUnsignedResult( ui64Result, pResult); + } + else + { + i64Result = i64Left * i64Right; + setSignedResult( i64Result, pResult); + } + } + else if (i64Right < 0) + { + i64Result = i64Left * i64Right; + setSignedResult( i64Result, pResult); } else { - pResult->val.i64Val = (FLMINT64)(fqGetInt64( pLValue) * - fqGetInt64( pRValue)); - - pResult->eType = (pResult->val.i64Val < 0) - ? FLM_INT64_VAL - : FLM_UINT64_VAL; + ui64Result = (FLMUINT64)i64Left * (FLMUINT64)i64Right; + setUnsignedResult( ui64Result, pResult); } } @@ -434,17 +504,20 @@ FSTATIC void fqOpSUMult( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMUINT64 ui64Right = fqGetUInt64( pRValue); + FLMINT64 i64Result; + FLMUINT64 ui64Result; + + if (i64Left < 0) { - pResult->val.iVal = pLValue->val.iVal * - (FLMINT)pRValue->val.uiVal; - pResult->eType = FLM_INT32_VAL; + i64Result = i64Left * (FLMINT64)ui64Right; + setSignedResult( i64Result, pResult); } else { - pResult->val.i64Val = (FLMINT64) - (fqGetInt64( pLValue) * fqGetUInt64( pRValue)); - pResult->eType = FLM_INT64_VAL; + ui64Result = (FLMUINT64)i64Left * ui64Right; + setUnsignedResult( ui64Result, pResult); } } @@ -456,34 +529,19 @@ FSTATIC void fqOpUUDiv( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMUINT64 ui64Left = fqGetUInt64( pLValue); + FLMUINT64 ui64Right = fqGetUInt64( pRValue); + FLMUINT64 ui64Result; + + if (ui64Right) { - if( pRValue->val.uiVal) - { - pResult->val.uiVal = pLValue->val.uiVal / pRValue->val.uiVal; - pResult->eType = FLM_UINT32_VAL; - } - else - { - pResult->val.uiVal = 0; // Divide by ZERO case. - pResult->eType = NO_TYPE; - } + ui64Result = ui64Left / ui64Right; + setUnsignedResult( ui64Result, pResult); } else { - FLMUINT64 ui64LValue = fqGetUInt64( pLValue); - FLMUINT64 ui64RValue = fqGetUInt64( pRValue); - - if( ui64RValue) - { - pResult->val.ui64Val = ui64LValue / ui64RValue; - pResult->eType = FLM_UINT64_VAL; - } - else - { - pResult->val.uiVal = 0; // Divide by ZERO case. - pResult->eType = NO_TYPE; - } + pResult->val.ui32Val = 0; // Divide by ZERO case. + pResult->eType = NO_TYPE; } } @@ -495,34 +553,33 @@ FSTATIC void fqOpUSDiv( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMUINT64 ui64Left = fqGetUInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (i64Right < 0) { - if( pRValue->val.iVal) + if (i64Right == FLM_MIN_INT64) { - pResult->val.iVal = pLValue->val.uiVal / pRValue->val.iVal; - pResult->eType = FLM_INT32_VAL; + i64Result = -((FLMINT64)(ui64Left / ((FLMUINT64)(FLM_MAX_INT64) + 1))); } else { - pResult->val.uiVal = 0; // Divide by ZERO case. - pResult->eType = NO_TYPE; + i64Right = -i64Right; + i64Result = -((FLMINT64)(ui64Left / (FLMUINT64)i64Right)); } + setSignedResult( i64Result, pResult); + } + else if (!i64Right) + { + pResult->val.ui32Val = 0; // Divide by ZERO case. + pResult->eType = NO_TYPE; } else { - FLMUINT64 ui64LValue = fqGetUInt64( pLValue); - FLMINT64 i64RValue = fqGetInt64( pRValue); - - if( i64RValue) - { - pResult->val.i64Val = ui64LValue / i64RValue; - pResult->eType = FLM_INT64_VAL; - } - else - { - pResult->val.uiVal = 0; // Divide by ZERO case. - pResult->eType = NO_TYPE; - } + ui64Result = ui64Left / (FLMUINT64)i64Right; + setUnsignedResult( ui64Result, pResult); } } @@ -534,36 +591,19 @@ FSTATIC void fqOpSSDiv( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMINT64 i64Result; + + if (i64Right) { - if( pRValue->val.iVal) - { - pResult->val.iVal = pLValue->val.iVal / pRValue->val.iVal; - pResult->eType = (pResult->val.iVal < 0) - ? FLM_INT32_VAL : FLM_UINT32_VAL; - } - else - { - pResult->val.uiVal = 0; // Divide by ZERO case. - pResult->eType = NO_TYPE; - } + i64Result = i64Left / i64Right; + setSignedResult( i64Result, pResult); } else { - FLMINT64 i64LValue = fqGetInt64( pLValue); - FLMINT64 i64RValue = fqGetInt64( pRValue); - - if( i64RValue) - { - pResult->val.i64Val = i64LValue / i64RValue; - pResult->eType = (pResult->val.i64Val < 0) - ? FLM_INT64_VAL : FLM_UINT64_VAL; - } - else - { - pResult->val.uiVal = 0; // Divide by ZERO case. - pResult->eType = NO_TYPE; - } + pResult->val.ui32Val = 0; // Divide by ZERO case. + pResult->eType = NO_TYPE; } } @@ -575,34 +615,32 @@ FSTATIC void fqOpSUDiv( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMUINT64 ui64Right = fqGetUInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (!ui64Right) { - if( pRValue->val.uiVal) + pResult->val.ui32Val = 0; // Divide by ZERO case. + pResult->eType = NO_TYPE; + } + else if (i64Left < 0) + { + if (ui64Right >= (FLMUINT64)(FLM_MAX_INT64) + 1) { - pResult->val.iVal = pLValue->val.iVal / pRValue->val.uiVal; - pResult->eType = FLM_INT32_VAL; + setUnsignedResult( 0, pResult); } else { - pResult->val.uiVal = 0; // Divide by ZERO case. - pResult->eType = NO_TYPE; + i64Result = i64Left / (FLMINT64)ui64Right; + setSignedResult( i64Result, pResult); } } else { - FLMINT64 i64LValue = fqGetInt64( pLValue); - FLMUINT64 ui64RValue = fqGetUInt64( pRValue); - - if( ui64RValue) - { - pResult->val.i64Val = i64LValue / ui64RValue; - pResult->eType = FLM_INT64_VAL; - } - else - { - pResult->val.uiVal = 0; // Divide by ZERO case. - pResult->eType = NO_TYPE; - } + ui64Result = (FLMUINT64)i64Left / ui64Right; + setUnsignedResult( ui64Result, pResult); } } @@ -614,34 +652,19 @@ FSTATIC void fqOpUUMod( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMUINT64 ui64Left = fqGetUInt64( pLValue); + FLMUINT64 ui64Right = fqGetUInt64( pRValue); + FLMUINT64 ui64Result; + + if (ui64Right) { - if( pRValue->val.uiVal) - { - pResult->val.uiVal = pLValue->val.uiVal % pRValue->val.uiVal; - pResult->eType = FLM_UINT32_VAL; - } - else - { - pResult->val.uiVal = 0; // MOD by ZERO case. - pResult->eType = NO_TYPE; - } + ui64Result = ui64Left % ui64Right; + setUnsignedResult( ui64Result, pResult); } else { - FLMUINT64 ui64LValue = fqGetUInt64( pLValue); - FLMUINT64 ui64RValue = fqGetUInt64( pRValue); - - if( ui64RValue) - { - pResult->val.ui64Val = ui64LValue % ui64RValue; - pResult->eType = FLM_UINT64_VAL; - } - else - { - pResult->val.uiVal = 0; // MOD by ZERO case. - pResult->eType = NO_TYPE; - } + pResult->val.ui32Val = 0; // Divide by ZERO case. + pResult->eType = NO_TYPE; } } @@ -653,34 +676,33 @@ FSTATIC void fqOpUSMod( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMUINT64 ui64Left = fqGetUInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (i64Right) { - if( pRValue->val.iVal) + if (i64Right == FLM_MIN_INT64) { - pResult->val.iVal = pLValue->val.uiVal % pRValue->val.iVal; - pResult->eType = FLM_INT32_VAL; + i64Result = -((FLMINT64)(ui64Left % ((FLMUINT64)(FLM_MAX_INT64) + 1))); } else { - pResult->val.uiVal = 0; // MOD by ZERO case. - pResult->eType = NO_TYPE; + i64Right = -i64Right; + i64Result = -((FLMINT64)(ui64Left % (FLMUINT64)i64Right)); } + setSignedResult( i64Result, pResult); + } + else if (!i64Right) + { + pResult->val.ui32Val = 0; // Divide by ZERO case. + pResult->eType = NO_TYPE; } else { - FLMUINT64 ui64LValue = fqGetUInt64( pLValue); - FLMINT64 i64RValue = fqGetInt64( pRValue); - - if( i64RValue) - { - pResult->val.i64Val = ui64LValue % i64RValue; - pResult->eType = FLM_INT64_VAL; - } - else - { - pResult->val.uiVal = 0; // MOD by ZERO case. - pResult->eType = NO_TYPE; - } + ui64Result = ui64Left % (FLMUINT64)i64Right; + setUnsignedResult( ui64Result, pResult); } } @@ -692,36 +714,19 @@ FSTATIC void fqOpSSMod( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMINT64 i64Result; + + if (i64Right) { - if( pRValue->val.iVal) - { - pResult->val.iVal = pLValue->val.iVal % pRValue->val.iVal; - pResult->eType = (pResult->val.iVal < 0) - ? FLM_INT32_VAL : FLM_UINT32_VAL; - } - else - { - pResult->val.uiVal = 0; // MOD by ZERO case. - pResult->eType = NO_TYPE; - } + i64Result = i64Left % i64Right; + setSignedResult( i64Result, pResult); } else { - FLMINT64 i64LValue = fqGetInt64( pLValue); - FLMINT64 i64RValue = fqGetInt64( pRValue); - - if( i64RValue) - { - pResult->val.i64Val = i64LValue % i64RValue; - pResult->eType = (pResult->val.i64Val < 0) - ? FLM_INT64_VAL : FLM_UINT64_VAL; - } - else - { - pResult->val.uiVal = 0; // MOD by ZERO case. - pResult->eType = NO_TYPE; - } + pResult->val.ui32Val = 0; // Divide by ZERO case. + pResult->eType = NO_TYPE; } } @@ -733,34 +738,32 @@ FSTATIC void fqOpSUMod( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMUINT64 ui64Right = fqGetUInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (!ui64Right) { - if( pRValue->val.uiVal) + pResult->val.ui32Val = 0; // Divide by ZERO case. + pResult->eType = NO_TYPE; + } + else if (i64Left < 0) + { + if (ui64Right >= (FLMUINT64)(FLM_MAX_INT64) + 1) { - pResult->val.iVal = pLValue->val.iVal % pRValue->val.uiVal; - pResult->eType = FLM_INT32_VAL; + setSignedResult( i64Left, pResult); } else { - pResult->val.uiVal = 0; // MOD by ZERO case. - pResult->eType = NO_TYPE; + i64Result = i64Left % (FLMINT64)ui64Right; + setSignedResult( i64Result, pResult); } } else { - FLMINT64 i64LValue = fqGetInt64( pLValue); - FLMUINT64 ui64RValue = fqGetUInt64( pRValue); - - if( ui64RValue) - { - pResult->val.i64Val = i64LValue % ui64RValue; - pResult->eType = FLM_INT64_VAL; - } - else - { - pResult->val.uiVal = 0; // MOD by ZERO case. - pResult->eType = NO_TYPE; - } + ui64Result = (FLMUINT64)i64Left % ui64Right; + setUnsignedResult( ui64Result, pResult); } } @@ -772,17 +775,8 @@ FSTATIC void fqOpUUPlus( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) - { - pResult->val.uiVal = pLValue->val.uiVal + pRValue->val.uiVal; - pResult->eType = FLM_UINT32_VAL; - } - else - { - pResult->val.ui64Val = - fqGetUInt64( pLValue) + fqGetUInt64( pRValue); - pResult->eType = FLM_UINT64_VAL; - } + FLMUINT64 ui64Result = fqGetUInt64( pLValue) + fqGetUInt64( pRValue); + setUnsignedResult( ui64Result, pResult); } /*************************************************************************** @@ -793,54 +787,52 @@ FSTATIC void fqOpUSPlus( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMUINT64 ui64Left = fqGetUInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (i64Right < 0) { - if (pRValue->val.iVal < 0) + if (i64Right == FLM_MIN_INT64) { - FLMINT iTmpVal = -pRValue->val.iVal; - - if ((FLMUINT)iTmpVal > pLValue->val.uiVal) + if (ui64Left < (FLMUINT64)(FLM_MAX_INT64) + 1) { - pResult->val.iVal = -(iTmpVal - (FLMINT)pLValue->val.uiVal); - pResult->eType = FLM_INT32_VAL; + if (!ui64Left) + { + i64Result = FLM_MIN_INT64; + } + else + { + i64Result = -((FLMINT64)((FLMUINT64)(FLM_MAX_INT64) + 1 - ui64Left)); + } + setSignedResult( i64Result, pResult); } else { - pResult->val.uiVal = pLValue->val.uiVal - (FLMUINT)iTmpVal; - pResult->eType = FLM_UINT32_VAL; + ui64Result = ui64Left - (FLMUINT64)(FLM_MAX_INT64) - 1; + setUnsignedResult( ui64Result, pResult); } } else { - pResult->val.uiVal = pLValue->val.uiVal + (FLMUINT)pRValue->val.iVal; - pResult->eType = FLM_UINT32_VAL; + i64Right = -i64Right; + if ((FLMUINT64)i64Right > ui64Left) + { + i64Result = -(i64Right - (FLMINT64)ui64Left); + setSignedResult( i64Result, pResult); + } + else + { + ui64Result = ui64Left - (FLMUINT64)i64Right; + setUnsignedResult( ui64Result, pResult); + } } } else { - FLMUINT64 ui64LValue = fqGetUInt64( pLValue); - FLMINT64 i64RValue = fqGetInt64( pRValue); - - if (i64RValue < 0) - { - i64RValue = -i64RValue; - - if ((FLMUINT64)i64RValue > ui64LValue) - { - pResult->val.i64Val = -(i64RValue - (FLMINT64)ui64LValue); - pResult->eType = FLM_INT64_VAL; - } - else - { - pResult->val.ui64Val = ui64LValue - (FLMUINT64)i64RValue; - pResult->eType = FLM_UINT64_VAL; - } - } - else - { - pResult->val.ui64Val = ui64LValue + (FLMUINT64)i64RValue; - pResult->eType = FLM_UINT64_VAL; - } + ui64Result = ui64Left + (FLMUINT64)i64Right; + setUnsignedResult( ui64Result, pResult); } } @@ -852,18 +844,20 @@ FSTATIC void fqOpSSPlus( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMINT64 i64Result; + FLMUINT64 ui64Result; + + if (i64Left >= 0 && i64Right >= 0) { - pResult->val.iVal = pLValue->val.iVal + pRValue->val.iVal; - pResult->eType = (pResult->val.iVal < 0) - ? FLM_INT32_VAL : FLM_UINT32_VAL; + ui64Result = (FLMUINT64)i64Left + (FLMUINT64)i64Right; + setUnsignedResult( ui64Result, pResult); } else { - pResult->val.i64Val = - fqGetInt64( pLValue) + fqGetInt64( pRValue); - pResult->eType = (pResult->val.i64Val < 0) - ? FLM_INT64_VAL : FLM_UINT64_VAL; + i64Result = i64Left + i64Right; + setSignedResult( i64Result, pResult); } } @@ -875,54 +869,52 @@ FSTATIC void fqOpSUPlus( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMUINT64 ui64Right = fqGetUInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (i64Left < 0) { - if (pLValue->val.iVal < 0) + if (i64Left == FLM_MIN_INT64) { - FLMINT iTmpVal = -pLValue->val.iVal; - - if ((FLMUINT)iTmpVal > pRValue->val.uiVal) + if (ui64Right < (FLMUINT64)(FLM_MAX_INT64) + 1) { - pResult->val.iVal = -(iTmpVal - (FLMINT)pRValue->val.uiVal); - pResult->eType = FLM_INT32_VAL; + if (!ui64Right) + { + i64Result = FLM_MIN_INT64; + } + else + { + i64Result = -((FLMINT64)((FLMUINT64)(FLM_MAX_INT64) + 1 - ui64Right)); + } + setSignedResult( i64Result, pResult); } else { - pResult->val.uiVal = pRValue->val.uiVal - (FLMUINT)iTmpVal; - pResult->eType = FLM_UINT32_VAL; + ui64Result = ui64Right - (FLMUINT64)(FLM_MAX_INT64) - 1; + setUnsignedResult( ui64Result, pResult); } } else { - pResult->val.uiVal = (FLMUINT)pLValue->val.iVal + pRValue->val.uiVal; - pResult->eType = FLM_UINT32_VAL; + i64Left = -i64Left; + if ((FLMUINT64)i64Left > ui64Right) + { + i64Result = -(i64Left - (FLMINT64)ui64Right); + setSignedResult( i64Result, pResult); + } + else + { + ui64Result = ui64Right - (FLMUINT64)i64Left; + setUnsignedResult( ui64Result, pResult); + } } } else { - FLMINT64 i64LValue = fqGetInt64( pLValue); - FLMUINT64 ui64RValue = fqGetUInt64( pRValue); - - if (i64LValue < 0) - { - i64LValue = -i64LValue; - - if ((FLMUINT64)i64LValue > ui64RValue) - { - pResult->val.i64Val = -(i64LValue - (FLMINT64)ui64RValue); - pResult->eType = FLM_INT64_VAL; - } - else - { - pResult->val.ui64Val = ui64RValue - (FLMUINT64)i64LValue; - pResult->eType = FLM_UINT64_VAL; - } - } - else - { - pResult->val.ui64Val = (FLMUINT64)i64LValue + ui64RValue; - pResult->eType = FLM_UINT64_VAL; - } + ui64Result = ui64Right + (FLMUINT64)i64Left; + setUnsignedResult( ui64Result, pResult); } } @@ -934,34 +926,20 @@ FSTATIC void fqOpUUMinus( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMUINT64 ui64Left = fqGetUInt64( pLValue); + FLMUINT64 ui64Right = fqGetUInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if( ui64Left >= ui64Right) { - if( pLValue->val.uiVal >= pRValue->val.uiVal) - { - pResult->val.uiVal = pLValue->val.uiVal - pRValue->val.uiVal; - pResult->eType = FLM_UINT32_VAL; - } - else - { - pResult->val.iVal = -((FLMINT)(pRValue->val.uiVal - pLValue->val.uiVal)); - pResult->eType = FLM_INT32_VAL; - } + ui64Result = ui64Left - ui64Right; + setUnsignedResult( ui64Result, pResult); } else { - FLMUINT64 ui64LValue = fqGetUInt64( pLValue); - FLMUINT64 ui64RValue = fqGetUInt64( pRValue); - - if( ui64LValue >= ui64RValue) - { - pResult->val.ui64Val = ui64LValue - ui64RValue; - pResult->eType = FLM_UINT64_VAL; - } - else - { - pResult->val.i64Val = -((FLMINT64)(ui64RValue - ui64LValue)); - pResult->eType = FLM_INT64_VAL; - } + i64Result = -((FLMINT64)(ui64Right - ui64Left)); + setSignedResult( i64Result, pResult); } } @@ -973,47 +951,35 @@ FSTATIC void fqOpUSMinus( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMUINT64 ui64Left = fqGetUInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (i64Right < 0) { - if( pRValue->val.iVal < 0) + if (i64Right == FLM_MIN_INT64) { - FLMINT iTmpVal = -pRValue->val.iVal; - - pResult->val.uiVal = pLValue->val.uiVal + (FLMUINT)iTmpVal; - pResult->eType = FLM_UINT32_VAL; - } - else if ((FLMUINT)pRValue->val.iVal > pLValue->val.uiVal) - { - pResult->val.iVal = (FLMINT)pLValue->val.uiVal - pRValue->val.iVal; - pResult->eType = FLM_INT32_VAL; + ui64Result = ui64Left + (FLMUINT64)FLM_MAX_INT64 + 1; } else { - pResult->val.uiVal = pLValue->val.uiVal - (FLMUINT)pRValue->val.iVal; - pResult->eType = FLM_UINT32_VAL; + i64Right = -i64Right; + ui64Result = ui64Left + (FLMUINT64)i64Right; } + setUnsignedResult( ui64Result, pResult); } else { - FLMUINT64 ui64LValue = fqGetUInt64( pLValue); - FLMINT64 i64RValue = fqGetInt64( pRValue); - - if( i64RValue < 0) + if( ui64Left >= (FLMUINT64)i64Right) { - i64RValue = -i64RValue; - - pResult->val.ui64Val = ui64LValue + (FLMUINT64)i64RValue; - pResult->eType = FLM_UINT64_VAL; - } - else if ((FLMUINT64)i64RValue > ui64LValue) - { - pResult->val.i64Val = (FLMINT64)ui64LValue - i64RValue; - pResult->eType = FLM_INT64_VAL; + ui64Result = ui64Left - (FLMUINT64)i64Right; + setUnsignedResult( ui64Result, pResult); } else { - pResult->val.ui64Val = ui64LValue - (FLMUINT64)i64RValue; - pResult->eType = FLM_UINT64_VAL; + i64Result = -((FLMINT64)(i64Right - (FLMINT64)ui64Left)); + setSignedResult( i64Result, pResult); } } } @@ -1026,15 +992,54 @@ FSTATIC void fqOpSSMinus( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMINT64 i64Right = fqGetInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (i64Left < 0) { - pResult->val.iVal = pLValue->val.iVal - pRValue->val.iVal; - pResult->eType = FLM_INT32_VAL; + if (i64Right >= 0) + { + i64Result = i64Left - i64Right; + setSignedResult( i64Result, pResult); + } + else if (i64Right == FLM_MIN_INT64) + { + if (i64Left == FLM_MIN_INT64) + { + ui64Result = 0; + } + else + { + i64Left = -i64Left; + ui64Result = (FLMUINT64)FLM_MAX_INT64 + 1 - (FLMUINT64)i64Left; + } + setUnsignedResult( ui64Result, pResult); + } + else + { + i64Result = i64Left - i64Right; + setSignedResult( i64Result, pResult); + } + } + else if (i64Right < 0) + { + if (i64Right == FLM_MIN_INT64) + { + ui64Result = (FLMUINT64)i64Left + (FLMUINT64)(FLM_MAX_INT64) + 1; + } + else + { + i64Right = -i64Right; + ui64Result = (FLMUINT64)i64Left + (FLMUINT64)i64Right; + } + setUnsignedResult( ui64Result, pResult); } else { - pResult->val.i64Val = fqGetInt64( pLValue) - fqGetInt64( pRValue); - pResult->eType = FLM_INT64_VAL; + i64Result = i64Left - i64Right; + setSignedResult( i64Result, pResult); } } @@ -1046,18 +1051,28 @@ FSTATIC void fqOpSUMinus( FQATOM * pRValue, FQATOM * pResult) { - if (isNativeNum( pLValue->eType) && isNativeNum( pRValue->eType)) + FLMINT64 i64Left = fqGetInt64( pLValue); + FLMUINT64 ui64Right = fqGetUInt64( pRValue); + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + if (i64Left < 0) { - pResult->val.iVal = pLValue->val.iVal - (FLMINT)pRValue->val.uiVal; - pResult->eType = FLM_INT32_VAL; + i64Result = i64Left - (FLMINT64)ui64Right; + setSignedResult( i64Result, pResult); } else { - FLMINT64 i64LValue = fqGetInt64( pLValue); - FLMUINT64 ui64RValue = fqGetUInt64( pRValue); - - pResult->val.i64Val = i64LValue - (FLMINT64)ui64RValue; - pResult->eType = FLM_INT64_VAL; + if( (FLMUINT64)i64Left >= ui64Right) + { + ui64Result = (FLMUINT64)i64Left - ui64Right; + setUnsignedResult( ui64Result, pResult); + } + else + { + i64Result = -((FLMINT64)(ui64Right - (FLMUINT64)i64Left)); + setSignedResult( i64Result, pResult); + } } } @@ -1100,7 +1115,7 @@ FSTATIC FLMUINT flmCurEvalTrueFalse( uiTrueFalse |= FLM_UNK; break; case FLM_INT32_VAL: - if (pTmpQAtom->val.iVal) + if (pTmpQAtom->val.i32Val) { uiTrueFalse |= FLM_TRUE; } @@ -1120,7 +1135,7 @@ FSTATIC FLMUINT flmCurEvalTrueFalse( } break; case FLM_UINT32_VAL: - if (pTmpQAtom->val.uiVal) + if (pTmpQAtom->val.ui32Val) { uiTrueFalse |= FLM_TRUE; } @@ -1216,150 +1231,36 @@ RCODE flmCurGetAtomVal( } case FLM_INT32_VAL: - { - if (!pField || pRecord->getDataLength( pField) == 0) - { - // Default value - - pResult->val.iVal = 0; - } - else if (uiType == FLM_NUMBER_TYPE || uiType == FLM_TEXT_TYPE) - { - if (RC_BAD( rc = pRecord->getINT( pField, &pResult->val.iVal))) - { - - // Try to get the number as an unsigned value. For purposes - // of evaluation, the 32-bit value will still be treated as - // signed. In effect, the large positive value is wrapped and - // becomes a negative value. - - if (rc == FERR_CONV_NUM_OVERFLOW) - { - rc = pRecord->getUINT( pField, &pResult->val.uiVal); - eFldType = FLM_UINT32_VAL; - } - } - } - else if (uiType == FLM_CONTEXT_TYPE) - { - rc = pRecord->getUINT( pField, &pResult->val.uiVal); - eFldType = FLM_UINT32_VAL; - } - else - { - rc = RC_SET( FERR_CONV_BAD_SRC_TYPE); - } - - if (RC_OK( rc)) - { - pResult->eType = eFldType; - } - break; - } - case FLM_INT64_VAL: - { - if (!pField || pRecord->getDataLength( pField) == 0) - { - // Default value - - pResult->val.i64Val = 0; - } - else if (uiType == FLM_NUMBER_TYPE || uiType == FLM_TEXT_TYPE) - { - if (RC_BAD( rc = pRecord->getINT64( pField, &pResult->val.i64Val))) - { - - // Try to get the number as an unsigned value. For purposes - // of evaluation, the 64-bit value will still be treated as - // signed. In effect, the large positive value is wrapped and - // becomes a negative value. - - if (rc == FERR_CONV_NUM_OVERFLOW) - { - rc = pRecord->getUINT64( pField, &pResult->val.ui64Val); - eFldType = FLM_UINT64_VAL; - } - } - } - else if (uiType == FLM_CONTEXT_TYPE) - { - rc = pRecord->getUINT( pField, &pResult->val.uiVal); - eFldType = FLM_UINT32_VAL; - } - else - { - rc = RC_SET( FERR_CONV_BAD_SRC_TYPE); - } - - if (RC_OK( rc)) - { - pResult->eType = eFldType; - } - break; - } - case FLM_UINT32_VAL: + case FLM_UINT64_VAL: case FLM_REC_PTR_VAL: { if (!pField || pRecord->getDataLength( pField) == 0) { // Default value - pResult->val.uiVal = 0; + pResult->val.ui32Val = 0; + eFldType = FLM_UINT32_VAL; } else if (uiType == FLM_NUMBER_TYPE || uiType == FLM_TEXT_TYPE) { - if (RC_BAD( rc = pRecord->getUINT( pField, &pResult->val.uiVal))) + if (RC_OK( rc = pRecord->getUINT32( pField, &pResult->val.ui32Val))) { - - // Try to get the number as a signed value. For purposes of - // evaluation, the 32-bit value will still be treated as - // unsigned. In effect, the negative value is wrapped and - // becomes a large positive value. - - if (rc == FERR_CONV_NUM_UNDERFLOW) + eFldType = FLM_UINT32_VAL; + } + else if (rc == FERR_CONV_NUM_OVERFLOW) + { + rc = pRecord->getUINT64( pField, &pResult->val.ui64Val); + eFldType = FLM_UINT64_VAL; + } + else if (rc == FERR_CONV_NUM_UNDERFLOW) + { + if (RC_OK( rc= pRecord->getINT32( pField, &pResult->val.i32Val))) { - rc = pRecord->getINT( pField, &pResult->val.iVal); eFldType = FLM_INT32_VAL; } - } - } - else if (uiType == FLM_CONTEXT_TYPE) - { - rc = pRecord->getUINT( pField, &(pResult->val.uiVal)); - } - else - { - rc = RC_SET( FERR_CONV_BAD_SRC_TYPE); - } - - if (RC_OK( rc)) - { - pResult->eType = eFldType; - } - break; - } - - case FLM_UINT64_VAL: - { - if (!pField || pRecord->getDataLength( pField) == 0) - { - // Default value - - pResult->val.ui64Val = 0; - } - else if (uiType == FLM_NUMBER_TYPE || uiType == FLM_TEXT_TYPE) - { - if (RC_BAD( rc = pRecord->getUINT64( pField, &pResult->val.ui64Val))) - { - - // Try to get the number as a signed value. For purposes of - // evaluation, the 64-bit value will still be treated as - // unsigned. In effect, the negative value is wrapped and - // becomes a large positive value. - - if (rc == FERR_CONV_NUM_UNDERFLOW) + else if (rc == FERR_CONV_NUM_UNDERFLOW) { rc = pRecord->getINT64( pField, &pResult->val.i64Val); eFldType = FLM_INT64_VAL; @@ -1368,7 +1269,7 @@ RCODE flmCurGetAtomVal( } else if (uiType == FLM_CONTEXT_TYPE) { - rc = pRecord->getUINT( pField, &(pResult->val.uiVal)); + rc = pRecord->getUINT32( pField, &pResult->val.ui32Val); eFldType = FLM_REC_PTR_VAL; } else @@ -1476,33 +1377,42 @@ RCODE flmCurGetAtomVal( case FLM_NUMBER_TYPE: { - if (RC_OK( rc = pRecord->getUINT( pField, - &pResult->val.uiVal))) + if (RC_OK( rc = pRecord->getUINT32( pField, + &pResult->val.ui32Val))) { pResult->eType = FLM_UINT32_VAL; } - else if (RC_OK( rc = pRecord->getINT( pField, - &pResult->val.iVal))) + else if (rc == FERR_CONV_NUM_UNDERFLOW) { - pResult->eType = FLM_INT32_VAL; + if (RC_OK( rc = pRecord->getINT32( pField, + &pResult->val.i32Val))) + { + pResult->eType = FLM_INT32_VAL; + } + else if (rc == FERR_CONV_NUM_UNDERFLOW) + { + if (RC_OK( rc = pRecord->getINT64( pField, + &pResult->val.i64Val))) + { + pResult->eType = FLM_INT64_VAL; + } + } } - else if (RC_OK( rc = pRecord->getUINT64( pField, - &pResult->val.ui64Val))) + else if (rc == FERR_CONV_NUM_OVERFLOW) { - pResult->eType = FLM_UINT64_VAL; - } - else if (RC_OK( rc = pRecord->getINT64( pField, - &pResult->val.i64Val))) - { - pResult->eType = FLM_INT64_VAL; + if (RC_OK( rc = pRecord->getUINT64( pField, + &pResult->val.ui64Val))) + { + pResult->eType = FLM_UINT64_VAL; + } } break; } case FLM_CONTEXT_TYPE: { - if (RC_OK( rc = pRecord->getUINT( pField, - &(pResult->val.uiVal)))) + if (RC_OK( rc = pRecord->getUINT32( pField, + &(pResult->val.ui32Val)))) { pResult->eType = FLM_UINT32_VAL; } @@ -1610,7 +1520,7 @@ FSTATIC RCODE flmCurGetAtomFromRec( if (*puiFldPath == FLM_RECID_FIELD) { pResult->eType = FLM_UINT32_VAL; - pResult->val.uiVal = pRecord->getID(); + pResult->val.ui32Val = (FLMUINT32)pRecord->getID(); goto Exit; } @@ -2007,13 +1917,13 @@ FSTATIC RCODE flmCurEvalArithOp( pLhs->pFieldRec = NULL; pLhs->eType = NO_TYPE; pLhs->uiBufLen = 0; - pLhs->val.uiVal = 0; + pLhs->val.ui32Val = 0; pRhs->pNext = NULL; pRhs->pFieldRec = NULL; pRhs->eType = NO_TYPE; pRhs->uiBufLen = 0; - pRhs->val.uiVal = 0; + pRhs->val.ui32Val = 0; // Get the two operands (may be multiple values per operand) @@ -2375,7 +2285,7 @@ void flmCompareOperands( if (pLhs->eType == FLM_UINT32_VAL && pRhs->eType == FLM_UINT32_VAL) { *puiTrueFalse = - (FQ_COMPARE( pLhs->val.uiVal, pRhs->val.uiVal) == 0) + (FQ_COMPARE( pLhs->val.ui32Val, pRhs->val.ui32Val) == 0) ? FLM_TRUE : FLM_FALSE; } else @@ -3015,7 +2925,7 @@ Get_Operand: pTmpQAtom->pFieldRec = NULL; pTmpQAtom->eType = NO_TYPE; pTmpQAtom->uiBufLen = 0; - pTmpQAtom->val.uiVal = 0; + pTmpQAtom->val.ui32Val = 0; eType = GET_QNODE_TYPE( pTmpQNode); if (IS_FLD_CB( eType, pTmpQNode)) @@ -3515,13 +3425,13 @@ FSTATIC RCODE flmCurDoNeg( { if (isNativeNum( pTmpQAtom->eType)) { - if (pTmpQAtom->val.uiVal >= (FLMUINT)(FLM_MAX_INT32) + 1) + if (pTmpQAtom->val.ui32Val >= (FLMUINT)(FLM_MAX_INT32) + 1) { pTmpQAtom->eType = NO_TYPE; } else { - pTmpQAtom->val.iVal = -((FLMINT)(pTmpQAtom->val.uiVal)); + pTmpQAtom->val.i32Val = -((FLMINT32)(pTmpQAtom->val.ui32Val)); pTmpQAtom->eType = FLM_INT32_VAL; } } @@ -3542,7 +3452,7 @@ FSTATIC RCODE flmCurDoNeg( { if (isNativeNum( pTmpQAtom->eType)) { - pTmpQAtom->val.iVal *= -1; + pTmpQAtom->val.i32Val *= -1; } else { @@ -3709,27 +3619,27 @@ FLMINT flmCurDoRelationalOp( { case FLM_UINT32_VAL: { - iCompVal = FQ_COMPARE( pLhs->val.uiVal, pRhs->val.uiVal); + iCompVal = FQ_COMPARE( pLhs->val.ui32Val, pRhs->val.ui32Val); break; } case FLM_UINT64_VAL: { - iCompVal = FQ_COMPARE( (FLMUINT64)(pLhs->val.uiVal), + iCompVal = FQ_COMPARE( (FLMUINT64)(pLhs->val.ui32Val), pRhs->val.ui64Val); break; } case FLM_INT32_VAL: { - if (pRhs->val.iVal < 0) + if (pRhs->val.i32Val < 0) { iCompVal = 1; } else { - iCompVal = FQ_COMPARE( pLhs->val.uiVal, - (FLMUINT) pRhs->val.iVal); + iCompVal = FQ_COMPARE( pLhs->val.ui32Val, + (FLMUINT32)pRhs->val.i32Val); } break; } @@ -3742,7 +3652,7 @@ FLMINT flmCurDoRelationalOp( } else { - iCompVal = FQ_COMPARE( (FLMINT64)(pLhs->val.uiVal), + iCompVal = FQ_COMPARE( (FLMINT64)(pLhs->val.ui32Val), pRhs->val.i64Val); } break; @@ -3764,7 +3674,7 @@ FLMINT flmCurDoRelationalOp( { case FLM_UINT32_VAL: { - iCompVal = FQ_COMPARE( pLhs->val.ui64Val, (FLMUINT64)pRhs->val.uiVal); + iCompVal = FQ_COMPARE( pLhs->val.ui64Val, (FLMUINT64)pRhs->val.ui32Val); break; } @@ -3776,14 +3686,14 @@ FLMINT flmCurDoRelationalOp( case FLM_INT32_VAL: { - if (pRhs->val.iVal < 0) + if (pRhs->val.i32Val < 0) { iCompVal = 1; } else { iCompVal = FQ_COMPARE( pLhs->val.ui64Val, - (FLMUINT64)(pRhs->val.iVal)); + (FLMUINT64)(pRhs->val.i32Val)); } break; } @@ -3818,39 +3728,39 @@ FLMINT flmCurDoRelationalOp( { case FLM_INT32_VAL: { - iCompVal = FQ_COMPARE( pLhs->val.iVal, pRhs->val.iVal); + iCompVal = FQ_COMPARE( pLhs->val.i32Val, pRhs->val.i32Val); break; } case FLM_INT64_VAL: { - iCompVal = FQ_COMPARE( (FLMINT64)(pLhs->val.iVal), pRhs->val.i64Val); + iCompVal = FQ_COMPARE( (FLMINT64)(pLhs->val.i32Val), pRhs->val.i64Val); break; } case FLM_UINT32_VAL: { - if (pLhs->val.iVal < 0) + if (pLhs->val.i32Val < 0) { iCompVal = -1; } else { - iCompVal = FQ_COMPARE( (FLMUINT) pLhs->val.iVal, - pRhs->val.uiVal); + iCompVal = FQ_COMPARE( (FLMUINT) pLhs->val.i32Val, + pRhs->val.ui32Val); } break; } case FLM_UINT64_VAL: { - if (pLhs->val.iVal < 0) + if (pLhs->val.i32Val < 0) { iCompVal = -1; } else { - iCompVal = FQ_COMPARE( (FLMUINT64)(pLhs->val.iVal), + iCompVal = FQ_COMPARE( (FLMUINT64)(pLhs->val.i32Val), pRhs->val.ui64Val); } break; @@ -3871,7 +3781,7 @@ FLMINT flmCurDoRelationalOp( { case FLM_INT32_VAL: { - iCompVal = FQ_COMPARE( pLhs->val.i64Val, (FLMINT64)(pRhs->val.iVal)); + iCompVal = FQ_COMPARE( pLhs->val.i64Val, (FLMINT64)(pRhs->val.i32Val)); break; } @@ -3890,7 +3800,7 @@ FLMINT flmCurDoRelationalOp( else { iCompVal = FQ_COMPARE( pLhs->val.i64Val, - (FLMINT64)(pRhs->val.uiVal)); + (FLMINT64)(pRhs->val.ui32Val)); } break; } @@ -3923,11 +3833,11 @@ FLMINT flmCurDoRelationalOp( if (pRhs->eType == FLM_REC_PTR_VAL || pRhs->eType == FLM_UINT32_VAL) { - iCompVal = FQ_COMPARE( pLhs->val.uiVal, pRhs->val.uiVal); + iCompVal = FQ_COMPARE( pLhs->val.ui32Val, pRhs->val.ui32Val); } else if (pRhs->eType == FLM_UINT64_VAL) { - iCompVal = FQ_COMPARE( (FLMUINT64)(pLhs->val.uiVal), pRhs->val.ui64Val); + iCompVal = FQ_COMPARE( (FLMUINT64)(pLhs->val.ui32Val), pRhs->val.ui64Val); } else { diff --git a/flaim/src/fqkeys.cpp b/flaim/src/fqkeys.cpp index 1bd894c..168c926 100644 --- a/flaim/src/fqkeys.cpp +++ b/flaim/src/fqkeys.cpp @@ -2006,7 +2006,7 @@ RCODE flmBuildFromAndUntilKeys( { case FLM_INT32_VAL: { - FLMINT iValue = pCurPred->pVal->val.iVal; + FLMINT iValue = (FLMINT)pCurPred->pVal->val.i32Val; if (pCurPred->eOperator == FLM_GT_OP) { iValue++; @@ -2049,7 +2049,7 @@ RCODE flmBuildFromAndUntilKeys( case FLM_UINT32_VAL: case FLM_REC_PTR_VAL: { - FLMUINT uiValue = pCurPred->pVal->val.uiVal; + FLMUINT uiValue = (FLMUINT)pCurPred->pVal->val.ui32Val; if (pCurPred->eOperator == FLM_GT_OP) { uiValue++; diff --git a/flaim/src/fqlog.cpp b/flaim/src/fqlog.cpp index 46b8fdf..81afa1f 100644 --- a/flaim/src/fqlog.cpp +++ b/flaim/src/fqlog.cpp @@ -449,7 +449,7 @@ FSTATIC void flmLogPredicate( case FLM_REC_PTR_VAL: case FLM_UINT32_VAL: f_logPrintf( pLogMsg, "%u", - (unsigned)pQNode->pQAtom->val.uiVal); + (unsigned)pQNode->pQAtom->val.ui32Val); break; case FLM_UINT64_VAL: f_logPrintf( pLogMsg, "%I64u", @@ -457,7 +457,7 @@ FSTATIC void flmLogPredicate( break; case FLM_INT32_VAL: f_logPrintf( pLogMsg, "%d", - (int)pQNode->pQAtom->val.iVal); + (int)pQNode->pQAtom->val.i32Val); break; case FLM_INT64_VAL: f_logPrintf( pLogMsg, "%I64d", diff --git a/flaim/src/fqopt.cpp b/flaim/src/fqopt.cpp index 288a4b7..a091820 100644 --- a/flaim/src/fqopt.cpp +++ b/flaim/src/fqopt.cpp @@ -446,7 +446,7 @@ FSTATIC RCODE flmSQGenPredicateList( flmAssert( eSibOp == FLM_UINT32_VAL); if (RC_BAD( rc = flmSQGetDrnRanges( pSubQuery, pPredicate->eOperator, - pPredicate->pVal->val.uiVal))) + (FLMUINT)pPredicate->pVal->val.ui32Val))) { goto Exit; } diff --git a/flaim/src/fqprep.cpp b/flaim/src/fqprep.cpp index 80a53e4..dbb29a4 100644 --- a/flaim/src/fqprep.cpp +++ b/flaim/src/fqprep.cpp @@ -636,7 +636,7 @@ RCODE flmCurCopyQNode( case FLM_INT32_VAL: { - pVal = (void *)&pSrcNode->pQAtom->val.iVal; + pVal = (void *)&pSrcNode->pQAtom->val.i32Val; break; } @@ -649,7 +649,7 @@ RCODE flmCurCopyQNode( case FLM_REC_PTR_VAL: case FLM_UINT32_VAL: { - pVal = (void *)&pSrcNode->pQAtom->val.uiVal; + pVal = (void *)&pSrcNode->pQAtom->val.ui32Val; break; } diff --git a/flaim/src/fqstack.cpp b/flaim/src/fqstack.cpp index 5bc1ae6..dfcfa2c 100644 --- a/flaim/src/fqstack.cpp +++ b/flaim/src/fqstack.cpp @@ -519,13 +519,13 @@ RCODE flmPutValInAtom( break; case FLM_UINT32_VAL: case FLM_REC_PTR_VAL: - pQAtom->val.uiVal = *((FLMUINT *)pvVal); + pQAtom->val.ui32Val = *((FLMUINT32 *)pvVal); break; case FLM_UINT64_VAL: pQAtom->val.ui64Val = *((FLMUINT64 *)pvVal); break; case FLM_INT32_VAL: - pQAtom->val.iVal = *((FLMINT *)pvVal); + pQAtom->val.i32Val = *((FLMINT32 *)pvVal); break; case FLM_INT64_VAL: pQAtom->val.i64Val = *((FLMINT64 *)pvVal); @@ -616,7 +616,7 @@ RCODE flmCurMakeQNode( case FLM_INT32_VAL: { - pQAtom->val.iVal = *(FLMINT *)pVal; + pQAtom->val.i32Val = *(FLMINT32 *)pVal; break; } @@ -629,7 +629,7 @@ RCODE flmCurMakeQNode( case FLM_REC_PTR_VAL: case FLM_UINT32_VAL: { - pQAtom->val.uiVal = *(FLMUINT *)pVal; + pQAtom->val.ui32Val = *(FLMUINT32 *)pVal; break; } @@ -749,7 +749,6 @@ FLMEXP RCODE FLMAPI FlmCursorAddValue( ) { RCODE rc = FERR_OK; - FLMINT iVal; FLMUINT uiVal; void * pTmpVal = pVal; CURSOR * pCursor = (CURSOR *)hCursor; @@ -828,35 +827,8 @@ FLMEXP RCODE FLMAPI FlmCursorAddValue( break; case FLM_INT32_VAL: - - // Need to make switch to FLMINT, because that is what - // flmCurMakeQNode is expecting. No need to change - // eValType. - - iVal = (FLMINT)(*(FLMINT32 *)pVal); - pTmpVal = &iVal; - break; - case FLM_UINT32_VAL: - - // Need to make switch to FLMUINT, because that is what - // flmCurMakeQNode is expecting. No need to change - // eValType. - - uiVal = (FLMUINT)(*(FLMUINT32 *)pVal); - pTmpVal = &uiVal; - break; - case FLM_REC_PTR_VAL: - - // Need to make switch to FLMUINT, because that is what - // flmCurMakeQNode is expecting. No need to change - // eValType. - - uiVal = (FLMUINT)(*(FLMUINT32 *)pVal); - pTmpVal = &uiVal; - break; - case FLM_UINT64_VAL: case FLM_INT64_VAL: case FLM_TEXT_VAL: diff --git a/flaim/src/fquery.h b/flaim/src/fquery.h index 021e69b..7ed59c9 100644 --- a/flaim/src/fquery.h +++ b/flaim/src/fquery.h @@ -148,8 +148,8 @@ typedef struct FQATOM union { FLMUINT uiBool; - FLMUINT uiVal; - FLMINT iVal; + FLMUINT32 ui32Val; + FLMINT32 i32Val; FLMUINT64 ui64Val; FLMINT64 i64Val; F_TIME Time; diff --git a/flaim/src/imonqury.cpp b/flaim/src/imonqury.cpp index 09700c2..a0d76fd 100644 --- a/flaim/src/imonqury.cpp +++ b/flaim/src/imonqury.cpp @@ -949,7 +949,7 @@ void F_QueryFormatter::outputPredicate( break; case FLM_REC_PTR_VAL: case FLM_UINT32_VAL: - f_sprintf( szBuf, "%u", (unsigned)pQNode->pQAtom->val.uiVal); + f_sprintf( szBuf, "%u", (unsigned)pQNode->pQAtom->val.ui32Val); appendString( szBuf, Q_VALUE_COLOR); break; case FLM_UINT64_VAL: @@ -957,7 +957,7 @@ void F_QueryFormatter::outputPredicate( appendString( szBuf, Q_VALUE_COLOR); break; case FLM_INT32_VAL: - f_sprintf( szBuf, "%d", (int)pQNode->pQAtom->val.iVal); + f_sprintf( szBuf, "%d", (int)pQNode->pQAtom->val.i32Val); appendString( szBuf, Q_VALUE_COLOR); break; case FLM_INT64_VAL: diff --git a/flaim/util/basic_test.cpp b/flaim/util/basic_test.cpp index 214fe97..f259136 100644 --- a/flaim/util/basic_test.cpp +++ b/flaim/util/basic_test.cpp @@ -238,6 +238,41 @@ static FLMINT64_TEST gv_FLMINT64Tests [NUM_FLMINT64_TESTS] = #endif }; +FSTATIC const char * opToStr( + QTYPES eOp); + +FSTATIC const char * addOrSubtractOne( + FLMBOOL bAddOne, + FLMBOOL bSubtractOne); + +FSTATIC FLMBOOL nonNegResultMatchesNonNegValueExpr( + FLMUINT64 ui64Result, + FLMUINT64 ui64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne); + +FSTATIC FLMBOOL nonNegResultMatchesNegValueExpr( + FLMUINT64 ui64Result, + FLMINT64 i64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne); + +FSTATIC FLMBOOL negResultMatchesNonNegValueExpr( + FLMINT64 i64Result, + FLMUINT64 ui64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne); + +FSTATIC FLMBOOL negResultMatchesNegValueExpr( + FLMINT64 i64Result, + FLMINT64 i64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne); + /*************************************************************************** Desc: ****************************************************************************/ @@ -347,6 +382,61 @@ public: RCODE numbersKeyRetrieveTest( void); + RCODE verifyFLMUINT64ValueExpr( + FLMUINT64 ui64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne, + FlmRecord * pRec); + + RCODE verifyFLMINT64ValueExpr( + FLMINT64 i64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne, + FlmRecord * pRec); + + RCODE doFLMUINT64QueryTest( + FLMUINT64 ui64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne); + + RCODE queryTestsFLMUINT64( + FLMUINT64 ui64Value); + + RCODE doFLMINT64QueryTest( + FLMINT64 i64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne); + + RCODE queryTestsFLMINT64( + FLMINT64 i64Value); + + RCODE doFLMUINT32QueryTest( + FLMUINT32 ui32Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne); + + RCODE queryTestsFLMUINT32( + FLMUINT32 ui32Value); + + RCODE doFLMINT32QueryTest( + FLMINT32 i32Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne); + + RCODE queryTestsFLMINT32( + FLMINT32 i32Value); + + RCODE doNumQueryTests( + NUM_IX_VALUE * pValue); + + RCODE numbersQueryTest( void); + RCODE backupRestoreDbTest( void); RCODE compareRecords( @@ -827,7 +917,7 @@ RCODE IFlmTestImpl::addRecordTest( pCopyRec->root(), FIRST_NAME_TAG)) == NULL) { rc = RC_SET( FERR_DATA_ERROR); - MAKE_ERROR_STRING( "corruption calling FlmRecord->copy()", + MAKE_ERROR_STRING( "corruption calling FlmRecord->find()", rc, m_szFailInfo); goto Exit; } @@ -3775,6 +3865,1845 @@ Exit: return( rc); } +/*************************************************************************** +Desc: +****************************************************************************/ +FSTATIC const char * opToStr( + QTYPES eOp) +{ + switch (eOp) + { + case FLM_EQ_OP: return( "=="); + case FLM_GT_OP: return( ">"); + case FLM_LT_OP: return( "<"); + case FLM_GE_OP: return( ">="); + case FLM_LE_OP: return( "<="); + case FLM_NE_OP: return( "!="); + default: + flmAssert( 0); + return( "!!!"); + } +} + +/*************************************************************************** +Desc: +****************************************************************************/ +FSTATIC const char * addOrSubtractOne( + FLMBOOL bAddOne, + FLMBOOL bSubtractOne) +{ + if (bAddOne) + { + return( "+ 1"); + } + else if (bSubtractOne) + { + return( "- 1"); + } + else + { + return( " "); + } +} + +/*************************************************************************** +Desc: +****************************************************************************/ +FSTATIC FLMBOOL nonNegResultMatchesNonNegValueExpr( + FLMUINT64 ui64Result, + FLMUINT64 ui64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne) +{ + FLMBOOL bMatches = TRUE; + + switch (eOp) + { + case FLM_EQ_OP: + if (bAddOne) + { + if (ui64Value == FLM_MAX_UINT64 || ui64Result != ui64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (!ui64Value || ui64Result != ui64Value - 1) + { + bMatches = FALSE; + } + } + else if (ui64Result != ui64Value) + { + bMatches = FALSE; + } + break; + case FLM_GT_OP: + if (bAddOne) + { + if (ui64Value == FLM_MAX_UINT64 || ui64Result <= ui64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (ui64Value && ui64Result <= ui64Value - 1) + { + bMatches = FALSE; + } + } + else if (ui64Result <= ui64Value) + { + bMatches = FALSE; + } + break; + case FLM_LT_OP: + if (bAddOne) + { + if (ui64Value < FLM_MAX_UINT64 && ui64Result >= ui64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (!ui64Value || ui64Result >= ui64Value - 1) + { + bMatches = FALSE; + } + } + else if (ui64Result >= ui64Value) + { + bMatches = FALSE; + } + break; + case FLM_GE_OP: + if (bAddOne) + { + if (ui64Value == FLM_MAX_UINT64 || ui64Result < ui64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (ui64Value && ui64Result < ui64Value - 1) + { + bMatches = FALSE; + } + } + else if (ui64Result < ui64Value) + { + bMatches = FALSE; + } + break; + case FLM_LE_OP: + if (bAddOne) + { + if (ui64Value < FLM_MAX_UINT64 && ui64Result > ui64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (!ui64Value || ui64Result > ui64Value - 1) + { + bMatches = FALSE; + } + } + else if (ui64Result > ui64Value) + { + bMatches = FALSE; + } + break; + case FLM_NE_OP: + if (bAddOne) + { + if (ui64Value == FLM_MAX_UINT64 || ui64Result == ui64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (ui64Value && ui64Result == ui64Value - 1) + { + bMatches = FALSE; + } + } + else if (ui64Result == ui64Value) + { + bMatches = FALSE; + } + break; + default: + bMatches = FALSE; + flmAssert( 0); + break; + } + + return( bMatches); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +FSTATIC FLMBOOL nonNegResultMatchesNegValueExpr( + FLMUINT64 ui64Result, + FLMINT64 i64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL // bSubtractOne + ) +{ + FLMBOOL bMatches = TRUE; + + switch (eOp) + { + case FLM_EQ_OP: + + // Only matches if result is zero, and value is -1 + 1. + + if (ui64Result != 0 || i64Value != -1 || !bAddOne) + { + bMatches = FALSE; + } + break; + + case FLM_GT_OP: + + // Always true except when result is zero and value = -1 + 1 + + if (ui64Result == 0 && i64Value == -1 && bAddOne) + { + bMatches = FALSE; + } + break; + case FLM_LT_OP: + + // Result is always >= 0, and highest value is zero (-1 + 1), so result + // should never be < value +/- anything. + + bMatches = FALSE; + break; + + case FLM_GE_OP: + + // This will always be true + + break; + + case FLM_LE_OP: + + // This can only be true when result is zero and value is -1 + 1 + + if (ui64Result != 0 || i64Value != -1 || !bAddOne) + { + bMatches = FALSE; + } + break; + + case FLM_NE_OP: + + // This is always true except when result is zero and value is -1 + 1 + + if (ui64Result == 0 && i64Value == -1 && bAddOne) + { + bMatches = FALSE; + } + break; + + default: + bMatches = FALSE; + flmAssert( 0); + break; + } + + return( bMatches); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +FSTATIC FLMBOOL negResultMatchesNonNegValueExpr( + FLMINT64 i64Result, + FLMUINT64 ui64Value, + QTYPES eOp, + FLMBOOL, // bAddOne, + FLMBOOL bSubtractOne) +{ + FLMBOOL bMatches = TRUE; + + flmAssert( i64Result < 0); + + switch (eOp) + { + case FLM_EQ_OP: + + // This will only be true in one case: result is -1, and + // value is 0 - 1. + + if (i64Result != -1 || !bSubtractOne || ui64Value) + { + bMatches = FALSE; + } + break; + + case FLM_GT_OP: + + // The largest that result could be is -1, and the smallest + // value is 0 - 1, so > will never match. + + bMatches = FALSE; + break; + + case FLM_LT_OP: + + // This will always be true except for the case where + // result is -1, and value is 0 - 1. + + if (i64Result == -1 && bSubtractOne && !ui64Value) + { + bMatches = FALSE; + } + break; + case FLM_GE_OP: + + // This will only be true when result is -1 and value + // is 0 - 1 + + if (i64Result != -1 || !bSubtractOne || ui64Value) + { + bMatches = FALSE; + } + break; + + case FLM_LE_OP: + + // This will always be TRUE, as the largest result must be + // -1, and the smallest value can be 0 - 1. + + break; + + case FLM_NE_OP: + + // This will always be true, except for the case where + // result is -1, and value is 0 - 1. + + if (i64Result == -1 && bSubtractOne && !ui64Value) + { + bMatches = FALSE; + } + break; + + default: + flmAssert( 0); + bMatches = FALSE; + break; + } + + return( bMatches); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +FSTATIC FLMBOOL negResultMatchesNegValueExpr( + FLMINT64 i64Result, + FLMINT64 i64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne) +{ + FLMBOOL bMatches = TRUE; + + // Both values should be negative. + + flmAssert( i64Result < 0 && i64Value < 0); + + switch (eOp) + { + case FLM_EQ_OP: + if (bAddOne) + { + if (i64Result != i64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (i64Value == FLM_MIN_INT64 || i64Result != i64Value - 1) + { + bMatches = FALSE; + } + } + else if (i64Result != i64Value) + { + bMatches = FALSE; + } + break; + + case FLM_GT_OP: + if (bAddOne) + { + if (i64Result <= i64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (i64Value != FLM_MIN_INT64 && i64Result <= i64Value - 1) + { + bMatches = FALSE; + } + } + else if (i64Result <= i64Value) + { + bMatches = FALSE; + } + break; + + case FLM_LT_OP: + if (bAddOne) + { + if (i64Result >= i64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (i64Value == FLM_MIN_INT64 || i64Result >= i64Value - 1) + { + bMatches = FALSE; + } + } + else if (i64Result >= i64Value) + { + bMatches = FALSE; + } + break; + + case FLM_GE_OP: + if (bAddOne) + { + if (i64Result < i64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (i64Value != FLM_MIN_INT64 && i64Result < i64Value - 1) + { + bMatches = FALSE; + } + } + else if (i64Result < i64Value) + { + bMatches = FALSE; + } + break; + + case FLM_LE_OP: + if (bAddOne) + { + if (i64Result > i64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (i64Value == FLM_MIN_INT64 || i64Result > i64Value - 1) + { + bMatches = FALSE; + } + } + else if (i64Result > i64Value) + { + bMatches = FALSE; + } + break; + + case FLM_NE_OP: + if (bAddOne) + { + if (i64Result == i64Value + 1) + { + bMatches = FALSE; + } + } + else if (bSubtractOne) + { + if (i64Value != FLM_MIN_INT64 && i64Result == i64Value - 1) + { + bMatches = FALSE; + } + } + else if (i64Result == i64Value) + { + bMatches = FALSE; + } + break; + + default: + bMatches = FALSE; + flmAssert( 0); + break; + } + + return( bMatches); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::verifyFLMUINT64ValueExpr( + FLMUINT64 ui64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne, + FlmRecord * pRec) +{ + RCODE rc = FERR_OK; + void * pvField; + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + // Verify that the record has a field and that it matches the + // criteria we specified. + + if ((pvField = pRec->find( pRec->root(), NUMBER_TAG)) == NULL) + { + rc = RC_SET( FERR_DATA_ERROR); + MAKE_ERROR_STRING( "corruption calling FlmRecord->find()", + rc, m_szFailInfo); + goto Exit; + } + + if (RC_BAD( rc = pRec->getUINT64( pvField, &ui64Result))) + { + if (rc != FERR_CONV_NUM_UNDERFLOW) + { + MAKE_ERROR_STRING( "calling FlmRecord->getUINT64()", rc, m_szFailInfo); + goto Exit; + } + if (RC_BAD( rc = pRec->getINT64( pvField, &i64Result))) + { + MAKE_ERROR_STRING( "calling FlmRecord->getINT64()", + rc, m_szFailInfo); + goto Exit; + } + + // Results should only be negative at this point. + + if (!negResultMatchesNonNegValueExpr( i64Result, ui64Value, eOp, + bAddOne, bSubtractOne)) + { + rc = RC_SET( FERR_FAILURE); + f_sprintf( m_szFailInfo, "Invalid result returned for query: " + "%I64d %s %I64u %s", + i64Result, opToStr( eOp), ui64Value, + addOrSubtractOne( bAddOne, bSubtractOne)); + goto Exit; + } + } + else + { + if (!nonNegResultMatchesNonNegValueExpr( ui64Result, ui64Value, + eOp, bAddOne, bSubtractOne)) + { + rc = RC_SET( FERR_FAILURE); + f_sprintf( m_szFailInfo, "Invalid result returned for query: " + "%I64u %s %I64u %s", + ui64Result, opToStr( eOp), ui64Value, + addOrSubtractOne( bAddOne, bSubtractOne)); + goto Exit; + } + } + +Exit: + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::verifyFLMINT64ValueExpr( + FLMINT64 i64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne, + FlmRecord * pRec) +{ + RCODE rc = FERR_OK; + void * pvField; + FLMUINT64 ui64Result; + FLMINT64 i64Result; + + // Verify that the record has a field and that it matches the + // criteria we specified. + + if ((pvField = pRec->find( pRec->root(), NUMBER_TAG)) == NULL) + { + rc = RC_SET( FERR_DATA_ERROR); + MAKE_ERROR_STRING( "corruption calling FlmRecord->find()", + rc, m_szFailInfo); + goto Exit; + } + + if (RC_BAD( rc = pRec->getUINT64( pvField, &ui64Result))) + { + if (rc != FERR_CONV_NUM_UNDERFLOW) + { + MAKE_ERROR_STRING( "calling FlmRecord->getUINT64()", rc, m_szFailInfo); + goto Exit; + } + if (RC_BAD( rc = pRec->getINT64( pvField, &i64Result))) + { + MAKE_ERROR_STRING( "calling FlmRecord->getINT64()", + rc, m_szFailInfo); + goto Exit; + } + flmAssert( i64Result < 0); + + if (i64Value < 0) + { + if (!negResultMatchesNegValueExpr( i64Result, i64Value, + eOp, bAddOne, bSubtractOne)) + { +Err_Neg_Result: + rc = RC_SET( FERR_FAILURE); + f_sprintf( m_szFailInfo, "Invalid result returned for query: " + "%I64d %s %I64d %s", + i64Result, opToStr( eOp), i64Value, + addOrSubtractOne( bAddOne, bSubtractOne)); + goto Exit; + } + } + else + { + if (!negResultMatchesNonNegValueExpr( i64Result, (FLMUINT64)i64Value, + eOp, bAddOne, bSubtractOne)) + { + goto Err_Neg_Result; + } + } + } + else + { + if (i64Value < 0) + { + if (!nonNegResultMatchesNegValueExpr( ui64Result, i64Value, + eOp, bAddOne, bSubtractOne)) + { +Err_NonNeg_Result: + rc = RC_SET( FERR_FAILURE); + f_sprintf( m_szFailInfo, "Invalid result returned for query: " + "%I64u %s %I64d %s", + ui64Result, opToStr( eOp), i64Value, + addOrSubtractOne( bAddOne, bSubtractOne)); + goto Exit; + } + } + else + { + if (!nonNegResultMatchesNonNegValueExpr( ui64Result, (FLMUINT64)i64Value, + eOp, bAddOne, bSubtractOne)) + { + goto Err_NonNeg_Result; + } + } + } + +Exit: + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::doFLMUINT64QueryTest( + FLMUINT64 ui64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne) +{ + RCODE rc = FERR_OK; + HFCURSOR hCursor = HFCURSOR_NULL; + FLMUINT32 ui32Num; + FlmRecord * pRec = NULL; + + if( RC_BAD( rc = FlmCursorInit( m_hDb, FLM_DATA_CONTAINER, &hCursor))) + { + MAKE_ERROR_STRING( "calling FlmCursorInit", rc, m_szFailInfo); + goto Exit; + } + + // We will search on the number field. + + if (RC_BAD( rc = FlmCursorAddField( hCursor, NUMBER_TAG, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddField", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = FlmCursorAddOp( hCursor, eOp))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp", rc, m_szFailInfo); + goto Exit; + } + + // Add the value + + if( RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT64_VAL, + &ui64Value, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui64)", rc, m_szFailInfo); + goto Exit; + } + + if (bAddOne) + { + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_PLUS_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp(+)", rc, m_szFailInfo); + goto Exit; + } + + ui32Num = 1; + if (RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT32_VAL, &ui32Num, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui32=+1)", rc, m_szFailInfo); + goto Exit; + } + } + else if (bSubtractOne) + { + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_MINUS_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp(-)", rc, m_szFailInfo); + goto Exit; + } + ui32Num = 1; + if (RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT32_VAL, &ui32Num, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui32=-1)", rc, m_szFailInfo); + goto Exit; + } + } + + // Get the results + + for (;;) + { + if (RC_BAD( rc = FlmCursorNext( hCursor, &pRec))) + { + if (rc == FERR_EOF_HIT) + { + rc = FERR_OK; + break; + } + else + { + f_sprintf( m_szFailInfo, "Error %e (file: %s, line %u) calling FlmCursorNext for query: " + "FLD %s %I64u %s", + rc, __FILE__, (unsigned)__LINE__, + opToStr( eOp), ui64Value, + addOrSubtractOne( bAddOne, bSubtractOne)); + goto Exit; + } + } + + if (RC_BAD( rc = verifyFLMUINT64ValueExpr( ui64Value, eOp, bAddOne, + bSubtractOne, pRec))) + { + goto Exit; + } + + } + +Exit: + + if (pRec) + { + pRec->Release(); + } + + if (hCursor != HFCURSOR_NULL) + { + (void)FlmCursorFree( &hCursor); + } + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::queryTestsFLMUINT64( + FLMUINT64 ui64Value) +{ + RCODE rc = FERR_OK; + + // N == Value + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_EQ_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N == Value + 1 + + if (ui64Value < FLM_MAX_UINT64) + { + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_EQ_OP, TRUE, FALSE))) + { + goto Exit; + } + } + + // N == Value - 1 + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_EQ_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N > Value + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_GT_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N > Value + 1 + + if (ui64Value < FLM_MAX_UINT64) + { + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_GT_OP, TRUE, FALSE))) + { + goto Exit; + } + } + + // N > Value - 1 + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_GT_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N < Value + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_LT_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N < Value + 1 + + if (ui64Value < FLM_MAX_UINT64) + { + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_LT_OP, TRUE, FALSE))) + { + goto Exit; + } + } + + // N < Value - 1 + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_LT_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N >= Value + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_GE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N >= Value + 1 + + if (ui64Value < FLM_MAX_UINT64) + { + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_GE_OP, TRUE, FALSE))) + { + goto Exit; + } + } + + // N >= Value - 1 + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_GE_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N <= Value + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_LE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N <= Value + 1 + + if (ui64Value < FLM_MAX_UINT64) + { + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_LE_OP, TRUE, FALSE))) + { + goto Exit; + } + } + + // N <= Value - 1 + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_LE_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N != Value + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_NE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N != Value + 1 + + if (ui64Value < FLM_MAX_UINT64) + { + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_NE_OP, TRUE, FALSE))) + { + goto Exit; + } + } + + // N != Value - 1 + + if (RC_BAD( rc = doFLMUINT64QueryTest( ui64Value, FLM_NE_OP, FALSE, TRUE))) + { + goto Exit; + } + +Exit: + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::doFLMINT64QueryTest( + FLMINT64 i64Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne) +{ + RCODE rc = FERR_OK; + HFCURSOR hCursor = HFCURSOR_NULL; + FLMUINT32 ui32Num; + FlmRecord * pRec = NULL; + + if( RC_BAD( rc = FlmCursorInit( m_hDb, FLM_DATA_CONTAINER, &hCursor))) + { + MAKE_ERROR_STRING( "calling FlmCursorInit", rc, m_szFailInfo); + goto Exit; + } + + // We will search on the number field. + + if (RC_BAD( rc = FlmCursorAddField( hCursor, NUMBER_TAG, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddField", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = FlmCursorAddOp( hCursor, eOp))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp", rc, m_szFailInfo); + goto Exit; + } + + // Add the value + + if( RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_INT64_VAL, + &i64Value, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(i64)", rc, m_szFailInfo); + goto Exit; + } + + if (bAddOne) + { + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_PLUS_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp(+)", rc, m_szFailInfo); + goto Exit; + } + + ui32Num = 1; + if (RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT32_VAL, &ui32Num, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui32=+1)", rc, m_szFailInfo); + goto Exit; + } + } + else if (bSubtractOne) + { + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_MINUS_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp(-)", rc, m_szFailInfo); + goto Exit; + } + ui32Num = 1; + if (RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT32_VAL, &ui32Num, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui32=-1)", rc, m_szFailInfo); + goto Exit; + } + } + + // Get the results + + for (;;) + { + if (RC_BAD( rc = FlmCursorNext( hCursor, &pRec))) + { + if (rc == FERR_EOF_HIT) + { + rc = FERR_OK; + break; + } + else + { + f_sprintf( m_szFailInfo, "Error %e (file: %s, line %u) calling FlmCursorNext for query: " + "FLD %s %I64d %s", + rc, __FILE__, (unsigned)__LINE__, + opToStr( eOp), i64Value, + addOrSubtractOne( bAddOne, bSubtractOne)); + goto Exit; + } + } + + if (RC_BAD( rc = verifyFLMINT64ValueExpr( i64Value, eOp, bAddOne, + bSubtractOne, pRec))) + { + goto Exit; + } + + } + +Exit: + + if (pRec) + { + pRec->Release(); + } + + if (hCursor != HFCURSOR_NULL) + { + (void)FlmCursorFree( &hCursor); + } + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::queryTestsFLMINT64( + FLMINT64 i64Value) +{ + RCODE rc = FERR_OK; + + // N == Value + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_EQ_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N == Value + 1 + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_EQ_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N == Value - 1 + + if (i64Value > FLM_MIN_INT64) + { + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_EQ_OP, FALSE, TRUE))) + { + goto Exit; + } + } + + // N > Value + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_GT_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N > Value + 1 + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_GT_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N > Value - 1 + + if (i64Value > FLM_MIN_INT64) + { + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_GT_OP, FALSE, TRUE))) + { + goto Exit; + } + } + + // N < Value + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_LT_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N < Value + 1 + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_LT_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N < Value - 1 + + if (i64Value > FLM_MIN_INT64) + { + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_LT_OP, FALSE, TRUE))) + { + goto Exit; + } + } + + // N >= Value + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_GE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N >= Value + 1 + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_GE_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N >= Value - 1 + + if (i64Value > FLM_MIN_INT64) + { + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_GE_OP, FALSE, TRUE))) + { + goto Exit; + } + } + + // N <= Value + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_LE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N <= Value + 1 + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_LE_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N <= Value - 1 + + if (i64Value > FLM_MIN_INT64) + { + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_LE_OP, FALSE, TRUE))) + { + goto Exit; + } + } + + // N != Value + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_NE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N != Value + 1 + + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_NE_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N != Value - 1 + + if (i64Value > FLM_MIN_INT64) + { + if (RC_BAD( rc = doFLMINT64QueryTest( i64Value, FLM_NE_OP, FALSE, TRUE))) + { + goto Exit; + } + } + +Exit: + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::doFLMUINT32QueryTest( + FLMUINT32 ui32Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne) +{ + RCODE rc = FERR_OK; + HFCURSOR hCursor = HFCURSOR_NULL; + FLMUINT32 ui32Num; + FlmRecord * pRec = NULL; + + if( RC_BAD( rc = FlmCursorInit( m_hDb, FLM_DATA_CONTAINER, &hCursor))) + { + MAKE_ERROR_STRING( "calling FlmCursorInit", rc, m_szFailInfo); + goto Exit; + } + + // We will search on the number field. + + if (RC_BAD( rc = FlmCursorAddField( hCursor, NUMBER_TAG, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddField", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = FlmCursorAddOp( hCursor, eOp))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp", rc, m_szFailInfo); + goto Exit; + } + + // Add the value + + if( RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT32_VAL, + &ui32Value, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui32)", rc, m_szFailInfo); + goto Exit; + } + + if (bAddOne) + { + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_PLUS_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp(+)", rc, m_szFailInfo); + goto Exit; + } + + ui32Num = 1; + if (RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT32_VAL, &ui32Num, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui32=+1)", rc, m_szFailInfo); + goto Exit; + } + } + else if (bSubtractOne) + { + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_MINUS_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp(-)", rc, m_szFailInfo); + goto Exit; + } + ui32Num = 1; + if (RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT32_VAL, &ui32Num, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui32=-1)", rc, m_szFailInfo); + goto Exit; + } + } + + // Get the results + + for (;;) + { + if (RC_BAD( rc = FlmCursorNext( hCursor, &pRec))) + { + if (rc == FERR_EOF_HIT) + { + rc = FERR_OK; + break; + } + else + { + f_sprintf( m_szFailInfo, "Error %e (file: %s, line %u) calling FlmCursorNext for query: " + "FLD %s %u %s", + rc, __FILE__, (unsigned)__LINE__, + opToStr( eOp), (unsigned)ui32Value, + addOrSubtractOne( bAddOne, bSubtractOne)); + goto Exit; + } + } + + if (RC_BAD( rc = verifyFLMUINT64ValueExpr( (FLMUINT64)ui32Value, eOp, bAddOne, + bSubtractOne, pRec))) + { + goto Exit; + } + + } + +Exit: + + if (pRec) + { + pRec->Release(); + } + + if (hCursor != HFCURSOR_NULL) + { + (void)FlmCursorFree( &hCursor); + } + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::queryTestsFLMUINT32( + FLMUINT32 ui32Value) +{ + RCODE rc = FERR_OK; + + // N == Value + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_EQ_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N == Value + 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_EQ_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N == Value - 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_EQ_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N > Value + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_GT_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N > Value + 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_GT_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N > Value - 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_GT_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N < Value + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_LT_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N < Value + 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_LT_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N < Value - 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_LT_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N >= Value + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_GE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N >= Value + 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_GE_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N >= Value - 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_GE_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N <= Value + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_LE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N <= Value + 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_LE_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N <= Value - 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_LE_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N != Value + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_NE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N != Value + 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_NE_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N != Value - 1 + + if (RC_BAD( rc = doFLMUINT32QueryTest( ui32Value, FLM_NE_OP, FALSE, TRUE))) + { + goto Exit; + } + +Exit: + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::doFLMINT32QueryTest( + FLMINT32 i32Value, + QTYPES eOp, + FLMBOOL bAddOne, + FLMBOOL bSubtractOne) +{ + RCODE rc = FERR_OK; + HFCURSOR hCursor = HFCURSOR_NULL; + FLMUINT32 ui32Num; + FlmRecord * pRec = NULL; + + if( RC_BAD( rc = FlmCursorInit( m_hDb, FLM_DATA_CONTAINER, &hCursor))) + { + MAKE_ERROR_STRING( "calling FlmCursorInit", rc, m_szFailInfo); + goto Exit; + } + + // We will search on the number field. + + if (RC_BAD( rc = FlmCursorAddField( hCursor, NUMBER_TAG, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddField", rc, m_szFailInfo); + goto Exit; + } + + if( RC_BAD( rc = FlmCursorAddOp( hCursor, eOp))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp", rc, m_szFailInfo); + goto Exit; + } + + // Add the value + + if( RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_INT32_VAL, + &i32Value, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(i32)", rc, m_szFailInfo); + goto Exit; + } + + if (bAddOne) + { + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_PLUS_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp(+)", rc, m_szFailInfo); + goto Exit; + } + + ui32Num = 1; + if (RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT32_VAL, &ui32Num, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui32=+1)", rc, m_szFailInfo); + goto Exit; + } + } + else if (bSubtractOne) + { + if( RC_BAD( rc = FlmCursorAddOp( hCursor, FLM_MINUS_OP))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddOp(-)", rc, m_szFailInfo); + goto Exit; + } + ui32Num = 1; + if (RC_BAD( rc = FlmCursorAddValue( hCursor, FLM_UINT32_VAL, &ui32Num, 0))) + { + MAKE_ERROR_STRING( "calling FlmCursorAddValue(ui32=-1)", rc, m_szFailInfo); + goto Exit; + } + } + + // Get the results + + for (;;) + { + if (RC_BAD( rc = FlmCursorNext( hCursor, &pRec))) + { + if (rc == FERR_EOF_HIT) + { + rc = FERR_OK; + break; + } + else + { + f_sprintf( m_szFailInfo, "Error %e (file: %s, line %u) calling FlmCursorNext for query: " + "FLD %s %d %s", + rc, __FILE__, (unsigned)__LINE__, + opToStr( eOp), (int)i32Value, + addOrSubtractOne( bAddOne, bSubtractOne)); + goto Exit; + } + } + + if (RC_BAD( rc = verifyFLMINT64ValueExpr( (FLMINT64)i32Value, eOp, bAddOne, + bSubtractOne, pRec))) + { + goto Exit; + } + + } + +Exit: + + if (pRec) + { + pRec->Release(); + } + + if (hCursor != HFCURSOR_NULL) + { + (void)FlmCursorFree( &hCursor); + } + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::queryTestsFLMINT32( + FLMINT32 i32Value) +{ + RCODE rc = FERR_OK; + + // N == Value + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_EQ_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N == Value + 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_EQ_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N == Value - 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_EQ_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N > Value + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_GT_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N > Value + 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_GT_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N > Value - 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_GT_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N < Value + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_LT_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N < Value + 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_LT_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N < Value - 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_LT_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N >= Value + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_GE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N >= Value + 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_GE_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N >= Value - 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_GE_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N <= Value + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_LE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N <= Value + 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_LE_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N <= Value - 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_LE_OP, FALSE, TRUE))) + { + goto Exit; + } + + // N != Value + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_NE_OP, FALSE, FALSE))) + { + goto Exit; + } + + // N != Value + 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_NE_OP, TRUE, FALSE))) + { + goto Exit; + } + + // N != Value - 1 + + if (RC_BAD( rc = doFLMINT32QueryTest( i32Value, FLM_NE_OP, FALSE, TRUE))) + { + goto Exit; + } + +Exit: + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::doNumQueryTests( + NUM_IX_VALUE * pValue) +{ + RCODE rc = FERR_OK; + + if (pValue->bUnsigned) + { + if (RC_BAD( rc = queryTestsFLMUINT64( (FLMUINT)pValue->ui64Value))) + { + goto Exit; + } + if (pValue->ui64Value <= (FLMUINT64)(FLM_MAX_INT64)) + { + if (RC_BAD( rc = queryTestsFLMINT64( (FLMINT64)pValue->ui64Value))) + { + goto Exit; + } + } + if (pValue->ui64Value <= (FLMUINT64)(FLM_MAX_UINT32)) + { + if (RC_BAD( rc = queryTestsFLMUINT32( (FLMUINT32)pValue->ui64Value))) + { + goto Exit; + } + } + if (pValue->ui64Value <= (FLMUINT64)(FLM_MAX_INT32)) + { + if (RC_BAD( rc = queryTestsFLMINT32( (FLMINT32)pValue->ui64Value))) + { + goto Exit; + } + } + } + else + { + if (RC_BAD( rc = queryTestsFLMINT64( pValue->i64Value))) + { + goto Exit; + } + if (pValue->i64Value >= (FLMINT64)(FLM_MIN_INT32) && + pValue->i64Value <= (FLMINT64)(FLM_MAX_INT32)) + { + if (RC_BAD( rc = queryTestsFLMINT32( (FLMINT32)pValue->i64Value))) + { + goto Exit; + } + } + if (pValue->i64Value >= 0 && + pValue->i64Value <= (FLMINT64)(FLM_MAX_UINT32)) + { + if (RC_BAD( rc = queryTestsFLMUINT32( (FLMUINT32)pValue->i64Value))) + { + goto Exit; + } + } + if (pValue->i64Value >= 0) + { + if (RC_BAD( rc = queryTestsFLMUINT64( (FLMUINT64)pValue->i64Value))) + { + goto Exit; + } + } + } + +Exit: + + return( rc); +} + +/*************************************************************************** +Desc: +****************************************************************************/ +RCODE IFlmTestImpl::numbersQueryTest( void) +{ + RCODE rc = FERR_OK; + FLMBOOL bPassed = FALSE; + FLMUINT uiCurrKey; + FLMBOOL bTransActive = FALSE; + + beginTest( "Numbers Query Test"); + + if( RC_BAD( rc = FlmDbTransBegin( m_hDb, FLM_READ_TRANS, 15))) + { + MAKE_ERROR_STRING( "calling FlmDbTransBegin", rc, m_szFailInfo); + goto Exit; + } + bTransActive = TRUE; + + for (uiCurrKey = 0; uiCurrKey < NUM_NUM_KEYS; uiCurrKey++) + { + if (RC_BAD( rc = doNumQueryTests( &gv_ExpectedNumIxValues [uiCurrKey]))) + { + goto Exit; + } + } + bPassed = TRUE; + +Exit: + + if (bTransActive) + { + (void)FlmDbTransAbort( m_hDb); + } + + endTest( bPassed); + return( rc); +} + /*************************************************************************** Desc: ****************************************************************************/ @@ -4882,6 +6811,13 @@ RCODE IFlmTestImpl::execute( void) goto Exit; } + // Numbers query retrieve test. + + if (RC_BAD( rc = numbersQueryTest())) + { + goto Exit; + } + // Hot Backup/Restore test if (RC_BAD( rc = backupRestoreDbTest()))