sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // SQL Comparison predicate node class sl@0: // sl@0: // sl@0: sl@0: #include "UQ_STD.H" sl@0: #include "D32COMP.H" sl@0: sl@0: // class CSqlCompPredicate sl@0: sl@0: CSqlCompPredicate::CSqlCompPredicate(TType aType,const TDesC& aColumn,const RSqlLiteral& aLiteral) sl@0: : CSqlLiteralNode(aType,aColumn,aLiteral) sl@0: { sl@0: __ASSERT(aType==ELess||aType==ELessEqual||aType==EEqual||aType==EGreaterEqual||aType==EGreater||aType==ENotEqual); sl@0: } sl@0: sl@0: TInt CSqlCompPredicate::CompareLongText8L(const TDbBlob& aBlob,const TTextOps& aTextOp) const sl@0: { sl@0: TInt r=Comp::Compare8L(StreamLC(aBlob),aBlob.Size(),Value().Text8(),aTextOp); sl@0: CleanupStack::PopAndDestroy(); sl@0: return r; sl@0: } sl@0: sl@0: TInt CSqlCompPredicate::CompareLongText16L(const TDbBlob& aBlob,const TTextOps& aTextOp) const sl@0: { sl@0: TInt r=Comp::Compare16L(StreamLC(aBlob),aBlob.Size(),Value().Text16(),aTextOp); sl@0: CleanupStack::PopAndDestroy(); sl@0: return r; sl@0: } sl@0: sl@0: TBool CSqlCompPredicate::EvaluateL(const TTextOps& aTextOp) const sl@0: // sl@0: // Evaluate a comparison between the columns and the data sl@0: // NULL numeric data always compares false sl@0: // sl@0: { sl@0: TDbColumnC col=Column(); sl@0: TDbColType t=ColType(); sl@0: if (t<=EDbColDateTime && col.IsNull()) sl@0: return EFalse; // NULL always compares false for non-text columns sl@0: TInt r; sl@0: switch (t) sl@0: { sl@0: default: sl@0: __ASSERT(0); sl@0: case EDbColBit: sl@0: case EDbColUint8: sl@0: case EDbColUint16: sl@0: case EDbColUint32: sl@0: r=Comp::Compare(TInt64(TUint(col.Uint32())),Value().Int64()); sl@0: break; sl@0: case EDbColInt8: sl@0: case EDbColInt16: sl@0: case EDbColInt32: sl@0: r=Comp::Compare(TInt64(TInt(col.Int32())),Value().Int64()); sl@0: break; sl@0: case EDbColInt64: sl@0: r=Comp::Compare(col.Int64(),Value().Int64()); sl@0: break; sl@0: case EDbColReal32: sl@0: r=Comp::Compare(TReal(col.Real32()),Value().Real64()); sl@0: break; sl@0: case EDbColReal64: sl@0: r=Comp::Compare(col.Real64(),Value().Real64()); sl@0: break; sl@0: case EDbColDateTime: sl@0: r=Comp::Compare(col.Time(),Value().Time()); sl@0: break; sl@0: case EDbColText8: sl@0: r=aTextOp.Compare(col.PtrC8(),Value().Text8()); sl@0: break; sl@0: case EDbColText16: sl@0: r=aTextOp.Compare(col.PtrC16(),Value().Text16()); sl@0: break; sl@0: case EDbColLongText8: sl@0: { sl@0: const TDbBlob& blob=col.Blob(); sl@0: if (blob.IsInline()) sl@0: r=aTextOp.Compare(blob.PtrC8(),Value().Text8()); sl@0: else sl@0: r=CompareLongText8L(blob,aTextOp); sl@0: } sl@0: break; sl@0: case EDbColLongText16: sl@0: { sl@0: const TDbBlob& blob=col.Blob(); sl@0: if (blob.IsInline()) sl@0: r=aTextOp.Compare(blob.PtrC16(),Value().Text16()); sl@0: else sl@0: r=CompareLongText16L(blob,aTextOp); sl@0: } sl@0: break; sl@0: } sl@0: switch (NodeType()) sl@0: { sl@0: default: sl@0: __ASSERT(0); sl@0: case EGreater: sl@0: r=-r; sl@0: // drop throught to ELess sl@0: case ELess: sl@0: return r<0; sl@0: case EGreaterEqual: sl@0: r=-r; sl@0: // drop throught to LessEqual sl@0: case ELessEqual: sl@0: return r<=0; sl@0: case EEqual: sl@0: return r==0; sl@0: case ENotEqual: sl@0: return r!=0; sl@0: } sl@0: }