|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // SQL Comparison predicate node class |
|
15 // |
|
16 // |
|
17 |
|
18 #include "UQ_STD.H" |
|
19 #include "D32COMP.H" |
|
20 |
|
21 // class CSqlCompPredicate |
|
22 |
|
23 CSqlCompPredicate::CSqlCompPredicate(TType aType,const TDesC& aColumn,const RSqlLiteral& aLiteral) |
|
24 : CSqlLiteralNode(aType,aColumn,aLiteral) |
|
25 { |
|
26 __ASSERT(aType==ELess||aType==ELessEqual||aType==EEqual||aType==EGreaterEqual||aType==EGreater||aType==ENotEqual); |
|
27 } |
|
28 |
|
29 TInt CSqlCompPredicate::CompareLongText8L(const TDbBlob& aBlob,const TTextOps& aTextOp) const |
|
30 { |
|
31 TInt r=Comp::Compare8L(StreamLC(aBlob),aBlob.Size(),Value().Text8(),aTextOp); |
|
32 CleanupStack::PopAndDestroy(); |
|
33 return r; |
|
34 } |
|
35 |
|
36 TInt CSqlCompPredicate::CompareLongText16L(const TDbBlob& aBlob,const TTextOps& aTextOp) const |
|
37 { |
|
38 TInt r=Comp::Compare16L(StreamLC(aBlob),aBlob.Size(),Value().Text16(),aTextOp); |
|
39 CleanupStack::PopAndDestroy(); |
|
40 return r; |
|
41 } |
|
42 |
|
43 TBool CSqlCompPredicate::EvaluateL(const TTextOps& aTextOp) const |
|
44 // |
|
45 // Evaluate a comparison between the columns and the data |
|
46 // NULL numeric data always compares false |
|
47 // |
|
48 { |
|
49 TDbColumnC col=Column(); |
|
50 TDbColType t=ColType(); |
|
51 if (t<=EDbColDateTime && col.IsNull()) |
|
52 return EFalse; // NULL always compares false for non-text columns |
|
53 TInt r; |
|
54 switch (t) |
|
55 { |
|
56 default: |
|
57 __ASSERT(0); |
|
58 case EDbColBit: |
|
59 case EDbColUint8: |
|
60 case EDbColUint16: |
|
61 case EDbColUint32: |
|
62 r=Comp::Compare(TInt64(TUint(col.Uint32())),Value().Int64()); |
|
63 break; |
|
64 case EDbColInt8: |
|
65 case EDbColInt16: |
|
66 case EDbColInt32: |
|
67 r=Comp::Compare(TInt64(TInt(col.Int32())),Value().Int64()); |
|
68 break; |
|
69 case EDbColInt64: |
|
70 r=Comp::Compare(col.Int64(),Value().Int64()); |
|
71 break; |
|
72 case EDbColReal32: |
|
73 r=Comp::Compare(TReal(col.Real32()),Value().Real64()); |
|
74 break; |
|
75 case EDbColReal64: |
|
76 r=Comp::Compare(col.Real64(),Value().Real64()); |
|
77 break; |
|
78 case EDbColDateTime: |
|
79 r=Comp::Compare(col.Time(),Value().Time()); |
|
80 break; |
|
81 case EDbColText8: |
|
82 r=aTextOp.Compare(col.PtrC8(),Value().Text8()); |
|
83 break; |
|
84 case EDbColText16: |
|
85 r=aTextOp.Compare(col.PtrC16(),Value().Text16()); |
|
86 break; |
|
87 case EDbColLongText8: |
|
88 { |
|
89 const TDbBlob& blob=col.Blob(); |
|
90 if (blob.IsInline()) |
|
91 r=aTextOp.Compare(blob.PtrC8(),Value().Text8()); |
|
92 else |
|
93 r=CompareLongText8L(blob,aTextOp); |
|
94 } |
|
95 break; |
|
96 case EDbColLongText16: |
|
97 { |
|
98 const TDbBlob& blob=col.Blob(); |
|
99 if (blob.IsInline()) |
|
100 r=aTextOp.Compare(blob.PtrC16(),Value().Text16()); |
|
101 else |
|
102 r=CompareLongText16L(blob,aTextOp); |
|
103 } |
|
104 break; |
|
105 } |
|
106 switch (NodeType()) |
|
107 { |
|
108 default: |
|
109 __ASSERT(0); |
|
110 case EGreater: |
|
111 r=-r; |
|
112 // drop throught to ELess |
|
113 case ELess: |
|
114 return r<0; |
|
115 case EGreaterEqual: |
|
116 r=-r; |
|
117 // drop throught to LessEqual |
|
118 case ELessEqual: |
|
119 return r<=0; |
|
120 case EEqual: |
|
121 return r==0; |
|
122 case ENotEqual: |
|
123 return r!=0; |
|
124 } |
|
125 } |