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 ***************************************************************************/
18 long AllDataType::size(DataType type
, int length
)
20 if (type
== typeInt
) return sizeof(int);
21 else if (type
== typeString
) return length
;
33 size
= sizeof(long long);
42 size
= sizeof(double);
49 //fldDef.length_ = sizeof(long double);
58 size
= sizeof(TimeStamp
);
71 void AllDataType::copyVal(void* dest
, void *src
, DataType type
, int length
)
73 //Performance optimization. putting likely case first
76 *(int*)dest
= *(int*)src
;
78 }else if (typeString
== type
)
80 //null is always put at the last byte by insert
81 //so using strcpy is safe
82 //strcpy((char*)dest, (char*)src);
83 memcpy((char*)dest
, (char*)src
, length
);
84 //strncpy((char*)dest, (char*)src, length);
85 //char *d =(char*)dest;
88 }else if (typeShort
== type
) {
89 *(short*)dest
= *(short*)src
;
90 }else if (typeDouble
== type
) {
91 *(double*)dest
= *(double*)src
;
92 }else if (typeTimeStamp
== type
) {
93 *(TimeStamp
*)dest
= *(TimeStamp
*)src
;
94 }else if (typeDate
== type
) {
95 *(Date
*)dest
= *(Date
*)src
;
96 }else if (typeFloat
== type
) {
97 *(float*)dest
= *(float*)src
;
98 }else if (typeTime
== type
) {
99 *(Time
*)dest
= *(Time
*)src
;
100 }else if (typeLong
== type
) {
101 *(long*)dest
= *(long*)src
;
102 }else if (typeLongLong
== type
) {
103 *(long long*)dest
= *(long long*)src
;
104 }else if (typeByteInt
== type
) {
105 *(char*)dest
= *(char*)src
;
106 }else if (typeBinary
== type
) {
107 os::memcpy(dest
, src
, length
);
108 }else if (typeComposite
== type
) {
109 os::memcpy(dest
, src
, length
);
113 void AllDataType::addVal(void* dest
, void *src
, DataType type
)
117 *(int*)dest
= *(int*)dest
+ *(int*)src
;
123 *(int*)dest
= *(int*)dest
+ *(int*)src
;
126 *(long*)dest
= *(long*)dest
+ *(long*)src
;
129 *(long long*)dest
= *(long long*)dest
+ *(long long*)src
;
132 *(short*)dest
= *(short*)dest
+ *(short*)src
;
135 *(char*)dest
= *(char*)dest
+ *(char*)src
;
138 *(double*)dest
= *(double*)dest
+ *(double*)src
;
141 *(float*)dest
= *(float*)dest
+ *(float*)src
;
155 bool AllDataType::compareVal(void *val1
, void *val2
, ComparisionOp op
,
156 DataType type
, long length
)
158 //Performance optimization.
159 //do not convert compareXXXVal to virtual functions. it takes more time
162 //as int is the heavily used type, hardcoding the compare here itself
163 if (OpEquals
== op
) {
164 if (*(int*)val1
== *(int*)val2
) return true;
166 }else if (OpLessThanEquals
== op
) {
167 if (*(int*)val1
<= *(int*)val2
) return true;
169 }else if (OpGreaterThanEquals
== op
) {
170 if (*(int*)val1
>= *(int*)val2
) return true;
172 }else if (OpGreaterThan
== op
) {
173 if (*(int*)val1
> *(int*)val2
) return true;
175 }else if (OpLessThan
== op
) {
176 if (*(int*)val1
< *(int*)val2
) return true;
178 }else if (OpNotEquals
== op
) {
179 if (*(int*)val1
!= *(int*)val2
) return true;
183 }else if(typeString
== type
) {
184 return AllDataType::compareStringVal(val1
, val2
, op
);
185 } else if (typeShort
== type
) {
186 return AllDataType::compareShortVal(val1
, val2
, op
);
187 } else if (typeDouble
== type
) {
188 return AllDataType::compareDoubleVal(val1
, val2
, op
);
189 } else if (typeFloat
== type
) {
190 return AllDataType::compareFloatVal(val1
, val2
, op
);
191 } else if (typeLong
== type
) {
192 return AllDataType::compareLongVal(val1
, val2
, op
);
193 } else if (typeLongLong
== type
) {
194 return AllDataType::compareLongLongVal(val1
, val2
, op
);
195 } else if (typeByteInt
== type
) {
196 return AllDataType::compareByteIntVal(val1
, val2
, op
);
197 } else if (typeTimeStamp
== type
) {
198 return AllDataType::compareTimeStampVal(val1
, val2
, op
);
199 } else if (typeDate
== type
) {
200 return AllDataType::compareDateVal(val1
, val2
, op
);
201 } else if (typeTime
== type
) {
202 return AllDataType::compareTimeVal(val1
, val2
, op
);
203 } else if (typeBinary
== type
) {
204 return AllDataType::compareBinaryVal(val1
, val2
, op
, length
);
205 } else if (typeComposite
== type
) {
206 return AllDataType::compareBinaryVal(val1
, val2
, op
, length
);
209 ComparisionOp
AllDataType::getComparisionOperator(char *str
)
212 if (strcmp(str
, "<=") == 0)
213 op
= OpLessThanEquals
;
214 else if (strcmp(str
, ">=") == 0)
215 op
= OpGreaterThanEquals
;
216 else if (strcmp(str
, "<") == 0)
218 else if (strcmp(str
, ">") == 0)
220 else if (strcmp(str
, "=") == 0)
222 else if (strcmp(str
, "!=") == 0 || strcmp(str
, "<>") == 0 )
224 else if (strcasecmp(str
, "LIKE") == 0 )
227 op
= OpInvalidComparisionOp
;