1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 ***************************************************************************/
20 bool AllDataType::compareIntVal(void* src1
, void *src2
, ComparisionOp op
)
22 printf("This function should never be called by anyone\n");
24 if (*(int*)src1
== *(int*)src2
) return true;
26 }else if (OpGreaterThan
== op
) {
27 if (*(int*)src1
> *(int*)src2
) return true;
29 }else if (OpLessThan
== op
) {
30 if (*(int*)src1
< *(int*)src2
) return true;
32 }else if (OpLessThanEquals
== op
) {
33 if (*(int*)src1
<= *(int*)src2
) return true;
35 }else if (OpGreaterThanEquals
== op
) {
36 if (*(int*)src1
>= *(int*)src2
) return true;
38 }else if (OpNotEquals
== op
) {
39 if (*(int*)src1
!= *(int*)src2
) return true;
45 bool AllDataType::compareLongVal(void* src1
, void *src2
, ComparisionOp op
)
51 if (*(long*)src1
== *(long*)src2
) result
= true;
55 if (*(long*)src1
!= *(long*)src2
) result
= true;
59 if (*(long*)src1
< *(long*)src2
) result
= true;
62 case OpLessThanEquals
:
63 if (*(long*)src1
<= *(long*)src2
) result
= true;
67 if (*(long*)src1
> *(long*)src2
) result
= true;
70 case OpGreaterThanEquals
:
71 if (*(long*)src1
>= *(long*)src2
) result
= true;
78 bool AllDataType::compareLongLongVal(void* src1
, void *src2
,
85 if (*(long long*)src1
== *(long long*)src2
) result
= true;
89 if (*(long long*)src1
!= *(long long*)src2
) result
= true;
93 if (*(long long*)src1
< *(long long*)src2
) result
= true;
96 case OpLessThanEquals
:
97 if (*(long long*)src1
<= *(long long*)src2
) result
= true;
101 if (*(long long*)src1
> *(long long*)src2
) result
= true;
104 case OpGreaterThanEquals
:
105 if (*(long long*)src1
>= *(long long*)src2
) result
= true;
112 bool AllDataType::compareShortVal(void* src1
, void *src2
, ComparisionOp op
)
118 if (*(short*)src1
== *(short*)src2
) result
= true;
122 if (*(short*)src1
!= *(short*)src2
) result
= true;
126 if (*(short*)src1
< *(short*)src2
) result
= true;
129 case OpLessThanEquals
:
130 if (*(short*)src1
<= *(short*)src2
) result
= true;
134 if (*(short*)src1
> *(short*)src2
) result
= true;
137 case OpGreaterThanEquals
:
138 if (*(short*)src1
>= *(short*)src2
) result
= true;
145 bool AllDataType::compareByteIntVal(void* src1
, void *src2
, ComparisionOp op
)
151 if (*(ByteInt
*)src1
== *(ByteInt
*)src2
) result
= true;
155 if (*(ByteInt
*)src1
!= *(ByteInt
*)src2
) result
= true;
159 if (*(ByteInt
*)src1
< *(ByteInt
*)src2
) result
= true;
162 case OpLessThanEquals
:
163 if (*(ByteInt
*)src1
<= *(ByteInt
*)src2
) result
= true;
167 if (*(ByteInt
*)src1
> *(ByteInt
*)src2
) result
= true;
170 case OpGreaterThanEquals
:
171 if (*(ByteInt
*)src1
>= *(ByteInt
*)src2
) result
= true;
178 bool AllDataType::compareDoubleVal(void* src1
, void *src2
, ComparisionOp op
)
184 if (*(double*)src1
== *(double*)src2
) result
= true;
188 if (*(double*)src1
!= *(double*)src2
) result
= true;
192 if (*(double*)src1
< *(double*)src2
) result
= true;
195 case OpLessThanEquals
:
196 if (*(double*)src1
<= *(double*)src2
) result
= true;
200 if (*(double*)src1
> *(double*)src2
) result
= true;
203 case OpGreaterThanEquals
:
204 if (*(double*)src1
>= *(double*)src2
) result
= true;
211 bool AllDataType::compareFloatVal(void* src1
, void *src2
, ComparisionOp op
)
217 if (*(float*)src1
== *(float*)src2
) result
= true;
221 if (*(float*)src1
!= *(float*)src2
) result
= true;
225 if (*(float*)src1
< *(float*)src2
) result
= true;
228 case OpLessThanEquals
:
229 if (*(float*)src1
<= *(float*)src2
) result
= true;
233 if (*(float*)src1
> *(float*)src2
) result
= true;
236 case OpGreaterThanEquals
:
237 if (*(float*)src1
>= *(float*)src2
) result
= true;
244 bool AllDataType::compareDateVal(void* src1
, void *src2
, ComparisionOp op
)
250 if (*(Date
*)src1
== *(Date
*)src2
) result
= true;
254 if (*(Date
*)src1
!= *(Date
*)src2
) result
= true;
258 if (*(Date
*)src1
< *(Date
*)src2
) result
= true;
261 case OpLessThanEquals
:
262 if (*(Date
*)src1
<= *(Date
*)src2
) result
= true;
266 if (*(Date
*)src1
> *(Date
*)src2
) result
= true;
269 case OpGreaterThanEquals
:
270 if (*(Date
*)src1
>= *(Date
*)src2
) result
= true;
277 bool AllDataType::compareTimeVal(void* src1
, void *src2
, ComparisionOp op
)
283 if (*(Time
*)src1
== *(Time
*)src2
) result
= true;
287 if (*(Time
*)src1
!= *(Time
*)src2
) result
= true;
291 if (*(Time
*)src1
< *(Time
*)src2
) result
= true;
294 case OpLessThanEquals
:
295 if (*(Time
*)src1
<= *(Time
*)src2
) result
= true;
299 if (*(Time
*)src1
> *(Time
*)src2
) result
= true;
302 case OpGreaterThanEquals
:
303 if (*(Time
*)src1
>= *(Time
*)src2
) result
= true;
310 bool AllDataType::compareTimeStampVal(void* src1
, void *src2
, ComparisionOp op
)
316 if (*(TimeStamp
*)src1
== *(TimeStamp
*)src2
) result
= true;
320 if (*(TimeStamp
*)src1
!= *(TimeStamp
*)src2
) result
= true;
324 if (*(TimeStamp
*)src1
< *(TimeStamp
*)src2
) result
= true;
327 case OpLessThanEquals
:
328 if (*(TimeStamp
*)src1
<= *(TimeStamp
*)src2
) result
= true;
332 if (*(TimeStamp
*)src1
> *(TimeStamp
*)src2
) result
= true;
335 case OpGreaterThanEquals
:
336 if (*(TimeStamp
*)src1
>= *(TimeStamp
*)src2
) result
= true;
343 bool AllDataType::compareStringVal(void* src1
, void *src2
, ComparisionOp op
)
345 if (OpEquals
== op
) {
346 if (strcmp((char*)src1
, (char*)src2
) ==0) return true;
348 }else if (OpGreaterThan
== op
) {
349 if (strcmp((char*)src1
, (char*)src2
) >0) return true;
351 }else if (OpLessThan
== op
) {
352 if (strcmp((char*)src1
, (char*)src2
) <0 ) return true;
354 }else if (OpLessThanEquals
== op
) {
355 // printf("Illegal Operator:Not Supported for String\n");
357 if (strcmp((char*)src1
, (char*)src2
)<= 0) return true;
359 }else if (OpGreaterThanEquals
== op
) {
360 // printf("Illegal Operator:Not Supported for String\n");
362 if (strcmp((char*)src1
, (char*)src2
) >=0) return true;
364 }else if (OpNotEquals
== op
) {
365 if (strcmp((char*)src1
, (char*)src2
) != 0) return true;
367 }else if (OpLike
== op
) {
368 return !os::strmatch((char*)src2
, (char*)src1
);
370 printf("Illegeal Operator:Not supported for String\n");
374 bool AllDataType::compareBinaryVal(void* src1
, void *src2
,
375 ComparisionOp op
, int length
)
378 int ret
= os::memcmp(src1
, src2
, length
);
382 if (ret
== 0 ) result
= true; else result
= false;
385 if (ret
!= 0 ) result
= true; else result
= false;
388 if (ret
< 0 ) result
= true; else result
= false;
390 case OpLessThanEquals
:
391 printf("Illegal Operator:Not Supported for Binary\n");
394 if (ret
> 0 ) result
= true; else result
= false;
396 case OpGreaterThanEquals
:
397 printf("Illegal Operator:Not Supported for Binary\n");