src/server/DataType.cxx

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015   ***************************************************************************/
00016 #include<os.h>
00017 #include<DataType.h>
00018 
00019 #define SmallestValJulDate (1721426)
00020 
00021 Date::Date(int year, int month, int day)
00022     { YMDToJulian(year, month, day, julianDate); }
00023 int Date::set(int year, int month, int day)
00024     { return YMDToJulian(year,month,day,julianDate); }
00025 int Date::get(int &year, int &month, int &day) const
00026     { return julianToYMD(julianDate,year,month,day); }
00027 
00028 int Date::parseFrom(const char *s) {
00029     int month,day,year;
00030     int count;
00031     count = sscanf(s,"%d/%d/%d",&year,&month,&day);
00032     if (count < 3) return -1;
00033 
00034     if (year < 100) year += 1900;
00035 
00036     if (!isValidDate(year, month, day))
00037         return -1;
00038     return set(year,month,day);
00039 }
00040 
00041 int Date::dayOfMonth() const {
00042     int year, month, day;
00043     get(year,month,day);
00044     return day;
00045 }
00046 int Date::month() const {
00047     int year, month, day;
00048     get(year,month,day);
00049     return month;
00050 }
00051 int Date::year() const {
00052     int year, month, day;
00053     get(year,month,day);
00054     return year;
00055 }
00056 
00057 int Date::dayOfWeek() const { return dayOfWeek(julianDate); }
00058 
00059 const char *Date::dayOfWeekName() const
00060     { return dayOfWeekName(dayOfWeek(julianDate)); }
00061 
00062 const char *Date::dayOfWeekAbbr() const
00063     { return dayOfWeekAbbr(dayOfWeek(julianDate)); }
00064 
00065 static const char *day_names[] = {
00066     "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
00067 };
00068 static const char *day_abbrs[] = {
00069     "Sun",    "Mon",    "Tue",     "Wed",       "Thu",      "Fri",    "Sat"
00070 };
00071 
00072 static const char *month_names[] = {
00073     "January", "February", "March",     "April",   "May",      "June",
00074     "July",    "August",   "September", "October", "November", "December"
00075 };
00076 static const char *month_abbrs[] = {
00077     "Jan",     "Feb",      "Mar",      "Apr",     "May",      "Jun",
00078     "Jul",     "Aug",      "Sep",      "Oct",     "Nov",      "Dec"
00079 };
00080 
00081 
00082 static int daysBeforeMonth[] = {
00083 0,  31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
00084 };
00085 static int days_per_month[] = {
00086     31, 28, 31,  30,   31, 30,  31,  31,  30,  31,  30,  31
00087 };
00088 
00089 const char * Date::dayOfWeekName(int day)
00090     { return (day < 1 || day > 7) ? 0 : day_names[day-1]; }
00091 
00092 const char * Date::dayOfWeekAbbr(int day)
00093     { return (day < 1 || day > 7) ? 0 : day_abbrs[day-1]; }
00094 
00095 const char * Date::monthName() const { return monthName(month()); }
00096 const char * Date::monthAbbr() const { return monthAbbr(month()); }
00097 const char * Date::monthName(int month)
00098     { return (month < 1 || month > 12) ? 0 : month_names[month-1]; }
00099 const char * Date::monthAbbr(int month)
00100     { return (month < 1 || month > 12) ? 0 : month_abbrs[month-1]; }
00101 Date operator+(const Date &d1, int days)
00102     { return Date(d1.julianDate + days); }
00103 Date operator+(int days, const Date &d1)
00104     { return Date(d1.julianDate + days); }
00105 Date operator-(const Date &d1, int days)
00106     { return Date(d1.julianDate - days); }
00107 
00108 int operator-(const Date &d1, const Date& d2)
00109     { return d1.julianDate - d2.julianDate; }
00110 
00111 int operator<(const Date &d1 ,const Date &d2 )
00112     { return d1.julianDate < d2.julianDate; }
00113 int operator>(const Date &d1 ,const Date &d2 )
00114     { return d1.julianDate > d2.julianDate; }
00115 int operator<=(const Date &d1 ,const Date &d2 )
00116     { return d1.julianDate <= d2.julianDate; }
00117 int operator>=(const Date &d1 ,const Date &d2 )
00118     { return d1.julianDate >= d2.julianDate; }
00119 int operator==(const Date &d1 ,const Date &d2 )
00120     { return d1.julianDate == d2.julianDate; }
00121 int operator!=(const Date &d1 ,const Date &d2 )
00122     { return d1.julianDate != d2.julianDate; }
00123 
00124 bool Date::isValid() const
00125     { return julianDate >= SmallestValJulDate; }
00126 
00127 bool Date::isLeapYear(int year)
00128 {
00129     return (year % 400 == 0) || ((year % 4 == 0) && !(year % 100 == 0));
00130 }
00131 
00132 int Date::dayOfYear() const {
00133     int year,month,day;
00134     get(year,month,day);
00135     int tmp = daysBeforeMonth[month-1];
00136     if (month >= 3 && isLeapYear(year))
00137         tmp++;
00138     return tmp + day;
00139 }
00140 
00141 int Date::daysInMonth(int month, int year) {
00142     --month;
00143     int tmp = days_per_month[month];
00144     if (month == 1 && isLeapYear(year)) tmp++;
00145     return tmp;
00146 }
00147 
00148 bool Date::isValidDate(int year, int month, int day) {
00149     if (year  < 1 || year  > 10000) return false;
00150     if (month < 1 || month > 12) return false;
00151     return (day >= 1) && (day <= daysInMonth(month,year));
00152 }
00153 
00154 // Algorithm Author: Robert G. Tantzen
00155 int Date::YMDToJulian(int year, int mon, int day, JulianRep &jul) {
00156     if (!isValidDate(year, mon, day))
00157         { jul = (JulianRep)0; return -1; }
00158 
00159     // year, month, day are assumed to be valid
00160     int m = mon, d = day, y = year;
00161     int c, ya, j;
00162 
00163     if (m > 2) m -= 3;
00164     else { m += 9; --y; }
00165     c = y/100;
00166     ya = y - (100 * c);
00167     j = (146097*c)/4 + (1461*ya)/4 + (153*m+2)/5 + d + 1721119;
00168     jul = (JulianRep)j;
00169     return 0;
00170 }
00171 
00172 // Julian date converter. Takes a julian date (the number of days since some
00173 // distant epoch or other), and returns month, day of month, and year in
00174 // integer references.
00175 // Algorithm Author: Robert G. Tantzen
00176 int Date::dayOfWeek(JulianRep jul) {
00177     return (int)((jul+1)%7+1);
00178 }
00179 
00180 int Date::julianToYMD(JulianRep jul, int &year, int &month, int &day) {
00181     int j = jul;
00182     int d, m, y;
00183 
00184     if (j < SmallestValJulDate)
00185         { year = month = day = 0; return -1; }
00186 
00187     j -= 1721119;
00188     y = (4 * j - 1)/146097;
00189     j = 4 * j - 1 - 146097 * y;
00190     d = j/4;
00191     j = (4 * d + 3)/1461;
00192     d = 4 * d + 3 - 1461 * j;
00193     d = (d + 4)/4;
00194     m = (5 * d - 3)/153;
00195     d = 5 * d - 3 - 153 * m;
00196     d = (d + 5) / 5;
00197     y = 100 * y + j;
00198     if (m < 10) m += 3;
00199     else { m -= 9; ++y; }
00200     month = m;
00201     day = d;
00202     year = y;
00203     return 0;
00204 }
00205 
00206 #define MAX_VALID_SECONDS (60 * 60 * 24 -1)
00207 Time::Time(int hours, int mins, int secs, int usec)
00208     { set(hours,mins,secs, usec); }
00209 
00210 int Time::set(int hours, int mins, int secs, int usec) {
00211         if((hours | mins | secs | usec) < 0) { timeVal = -1; return -1; }
00212         if(hours >= 24 | mins >= 60 | secs >= 62)
00213                 { timeVal = -1; return -1; }
00214         timeVal = secs + mins * 60 + hours * 3600;
00215         timeVal *= 10000;
00216         if(usec) timeVal += usec/100;
00217         return 0;
00218 }
00219 
00220 int Time::get(int &hours, int &mins, int &secs) const {
00221     if (timeVal < 0) return -1;
00222     int s = timeVal/10000;
00223     secs = s % 60;
00224     s /= 60;
00225     mins = s % 60;
00226     s /= 60;
00227     hours = s;
00228     return 0;
00229 }
00230 
00231 int Time::seconds() const { return (timeVal/10000) % 60; }
00232 int Time::minutes() const { return (timeVal /(60*10000)) % 60; }
00233 int Time::hours() const   { return timeVal / (3600*10000); }
00234 int Time::msec() const { return (timeVal % 10000) / 10; }
00235 int Time::usec() const { return (timeVal % 10000) * 100; }
00236 
00237 int Time::setMsec(int ms) {
00238         if(ms < 0 || ms >= 1000) return -1;
00239         timeVal = timeVal+(10*ms);
00240     return 0;
00241 }
00242 int Time::setUsec(int us) {
00243         if(us < 0 || us >= 1000000) return -1;
00244         timeVal = timeVal +us/100;
00245     return 0;
00246 }
00247 
00248 bool Time::isValid() const
00249     { return timeVal >= 0 && timeVal <= (10000*(MAX_VALID_SECONDS+1)-1); }
00250 
00251 bool Time::isValidTime(int hours, int mins, int secs) {
00252     return (hours >= 0 && hours < 24) &&
00253            (mins >= 0 && mins < 60) &&
00254            (secs >= 0 && secs < 60);
00255 }
00256 
00257 Time operator+(const Time &t1, int seconds)
00258     { return Time(t1.timeVal + seconds*10000); }
00259 Time operator+(int seconds, const Time &t1)
00260     { return Time(t1.timeVal + seconds*10000); }
00261 Time operator-(const Time &t1, int seconds)
00262     { return Time(t1.timeVal - seconds*10000); }
00263 
00264 int operator-(const Time &t1, const Time& t2)
00265     { return (t1.timeVal - t2.timeVal)/10000; }
00266 
00267 int operator<(const Time &t1 ,const Time &t2 )
00268     { return t1.timeVal < t2.timeVal; }
00269 int operator>(const Time &t1 ,const Time &t2 )
00270     { return t1.timeVal > t2.timeVal; }
00271 int operator<=(const Time &t1 ,const Time &t2 )
00272     { return t1.timeVal <= t2.timeVal; }
00273 int operator>=(const Time &t1 ,const Time &t2 )
00274     { return t1.timeVal >= t2.timeVal; }
00275 int operator==(const Time &t1 ,const Time &t2 )
00276     { return t1.timeVal == t2.timeVal; }
00277 int operator!=(const Time &t1 ,const Time &t2 )
00278     { return t1.timeVal != t2.timeVal; }
00279 
00280 int Time::parseFrom(const char *s) {
00281     int hours,mins,secs;
00282     int count;
00283     count = sscanf(s,"%d:%d:%d",&hours,&mins,&secs);
00284     if (count < 2) return -1;
00285     if (count == 2) secs = 0;
00286 
00287     if (!isValidTime(hours,mins,secs))
00288         return -1;
00289     return set(hours,mins,secs);
00290 }
00291 int TimeStamp::parseFrom(const char *s) {
00292     int hours,mins,secs;
00293     int month,day,year;
00294     int count;
00295     count = sscanf(s,"%d/%d/%d %d:%d:%d",&year,&month,&day, &hours, &mins, &secs);
00296     if (count < 5) return -1;
00297     if (count == 5) secs = 0;
00298 
00299     if (year < 100) year += 1900;
00300 
00301     if (!date.isValidDate(year, month, day))
00302         return -1;
00303 
00304     setDate(year,month,day);
00305 
00306 
00307     if (!time.isValidTime(hours,mins,secs))
00308         return -1;
00309     return setTime(hours,mins,secs);
00310 }
00311 
00312 int operator< (const TimeStamp &d1,  const TimeStamp &d2)
00313     { return (d1.date != d2.date) ? d1.date < d2.date : d1.time < d2.time; }
00314 int operator> (const TimeStamp &d1,  const TimeStamp &d2)
00315     { return (d1.date != d2.date) ? d1.date > d2.date : d1.time > d2.time; }
00316 int operator<=(const TimeStamp &d1, const TimeStamp &d2)
00317     { return (d1.date != d2.date) ? d1.date < d2.date : d1.time <= d2.time; }
00318 int operator>=(const TimeStamp &d1, const TimeStamp &d2)
00319     { return (d1.date != d2.date) ? d1.date > d2.date : d1.time >= d2.time; }
00320 int operator==(const TimeStamp &d1, const TimeStamp &d2)
00321     { return d1.date == d2.date && d1.time == d2.time; }
00322 int operator!=(const TimeStamp &d1, const TimeStamp &d2)
00323     { return d1.date != d2.date && d1.time != d2.time; }
00324 
00325 
00326 long AllDataType::size(DataType type, int length )
00327 {
00328     long size = 0;
00329     switch(type)
00330     {
00331         case typeInt:
00332             size = sizeof(int);
00333             break;
00334         case typeLong:
00335             size = sizeof(long);
00336             break;
00337         case typeLongLong:
00338             size = sizeof(long long);
00339             break;
00340         case typeShort:
00341             size = sizeof(short);
00342             break;
00343         case typeByteInt:
00344             size = sizeof(char);
00345             break;
00346         case typeDouble:
00347             size = sizeof(double);
00348             break;
00349         case typeFloat:
00350             size = sizeof(float);
00351             break;
00352         case typeDecimal:
00353             //TODO::for porting
00354             //fldDef.length_ = sizeof(long double);
00355             break;
00356         case typeDate:
00357             size = sizeof(Date);
00358             break;
00359         case typeTime:
00360             size = sizeof(Time);
00361             break;
00362         case typeTimeStamp:
00363             size = sizeof(TimeStamp);
00364             break;
00365         case typeString:
00366             size = length;
00367             break;
00368         default:
00369             size  = 0;
00370             break;
00371     }
00372     return size;
00373 }
00374 char* AllDataType::getSQLString(DataType type)
00375 {
00376     switch(type)
00377     {
00378         case typeInt: return "INT";
00379         case typeLong: return "INT";
00380         case typeLongLong: return "BIGINT";
00381         case typeShort: return "SMALLINT";
00382         case typeByteInt: return "TINYINT";
00383         case typeDouble: return "REAL";
00384         case typeFloat: return "FLOAT";
00385         case typeDate: return "DATE";
00386         case typeTime: return "TIME";
00387         case typeTimeStamp: return "TIMESTAMP";
00388         case typeString: return "CHAR";
00389         default: return "UNKNOWN";
00390     }
00391 }
00392 
00393 
00394 SQLSMALLINT AllDataType::convertToSQLType(DataType type)
00395 {
00396     switch(type)
00397     {
00398         case typeInt:
00399             return SQL_INTEGER;
00400         case typeLong:
00401             return SQL_INTEGER;
00402         case typeLongLong:
00403             //TODO
00404             return SQL_INTEGER;
00405         case typeShort:
00406             return SQL_SMALLINT;
00407         case typeByteInt:
00408             //TODO
00409             return SQL_INTEGER;
00410         case typeDouble:
00411             return SQL_DOUBLE;
00412         case typeFloat:
00413             return SQL_REAL;
00414         case typeDecimal:
00415             //TODO
00416             return SQL_INTEGER;
00417         case typeDate:
00418             return SQL_TYPE_DATE;
00419         case typeTime:
00420            return SQL_TYPE_TIME;
00421         case typeTimeStamp:
00422            return SQL_TYPE_TIMESTAMP;
00423         case typeString:
00424             return SQL_CHAR;
00425     }
00426     return SQL_INTEGER;
00427 }
00428 SQLSMALLINT AllDataType::convertToSQL_C_Type(DataType type)
00429 {
00430     switch(type)
00431     {
00432         case typeInt:
00433             return SQL_C_SLONG;
00434         case typeLong:
00435             return SQL_C_SLONG;
00436         case typeLongLong:
00437             return SQL_C_SBIGINT;
00438         case typeShort:
00439             return SQL_C_SSHORT;
00440         case typeByteInt:
00441             return SQL_C_STINYINT;
00442         case typeDouble:
00443             return SQL_C_DOUBLE;
00444         case typeFloat:
00445             return SQL_C_FLOAT;
00446         case typeDecimal:
00447             //TODO
00448             return SQL_INTEGER;
00449         case typeDate:
00450             return SQL_C_TYPE_DATE;
00451         case typeTime:
00452            return SQL_C_TYPE_TIME;
00453         case typeTimeStamp:
00454            return SQL_C_TYPE_TIMESTAMP;
00455         case typeString:
00456             return SQL_C_CHAR;
00457     }
00458     return SQL_C_SLONG;
00459 }
00460 
00461 DataType  AllDataType::convertFromSQLType(SQLSMALLINT type)
00462 {
00463     switch(type)
00464     {
00465         case SQL_INTEGER :
00466             return typeInt;
00467         case  SQL_SMALLINT:
00468             return typeShort;
00469         case  SQL_DOUBLE:
00470             return typeDouble;
00471         case  SQL_FLOAT:
00472         case  SQL_REAL:
00473             return typeFloat;
00474         case SQL_TYPE_DATE:
00475             return typeDate;
00476         case SQL_TYPE_TIME :
00477            return typeTime;
00478         case SQL_TYPE_TIMESTAMP :
00479            return typeTimeStamp;
00480         case SQL_CHAR:
00481             return typeString;
00482         case SQL_VARCHAR:
00483             return typeString;
00484     }
00485     return typeInt;
00486 }
00487 void AllDataType::copyVal(void* dest, void *src, DataType type, int length)
00488 {
00489     switch(type)
00490     {
00491         case typeInt:
00492             *(int*)dest = *(int*)src;
00493             break;
00494         case typeLong:
00495             *(long*)dest = *(long*)src;
00496             break;
00497         case typeLongLong:
00498             *(long long*)dest = *(long long*)src;
00499             break;
00500         case typeShort:
00501             *(short*)dest = *(short*)src;
00502             break;
00503         case typeByteInt:
00504             *(char*)dest = *(char*)src;
00505             break;
00506         case typeDouble:
00507             *(double*)dest = *(double*)src;
00508             break;
00509         case typeFloat:
00510             *(float*)dest = *(float*)src;
00511             break;
00512         case typeDecimal:
00513             //TODO::for porting
00514         case typeDate:
00515             *(Date*)dest = *(Date*)src;
00516             break;
00517         case typeTime:
00518             *(Time*)dest = *(Time*)src;
00519             break;
00520         case typeTimeStamp:
00521             *(TimeStamp*)dest = *(TimeStamp*)src;
00522             break;
00523         case typeString: 
00524             {
00525                 strncpy((char*)dest, (char*)src, length);
00526                 char *d =(char*)dest;
00527                 d[length-1] = '\0';
00528                 break;
00529             }
00530         case typeBinary:
00531             os::memcpy((char*)dest, (char*)src, length);
00532             break;
00533         default:
00534             break;
00535         }
00536 }
00537 
00538 bool AllDataType::compareVal(void *val1, void *val2, ComparisionOp op,
00539                              DataType type, long length)
00540 {
00541     bool result = false;
00542         switch(type)
00543         {
00544        case typeInt:
00545            result = AllDataType::compareIntVal(val1, val2, op );
00546            break;
00547        case typeLong:
00548            result = AllDataType::compareLongVal(val1, val2, op);
00549            break;
00550        case typeLongLong:
00551            result = AllDataType::compareLongLongVal(val1, val2, op);
00552            break;
00553        case typeShort:
00554            result = AllDataType::compareShortVal(val1, val2, op);
00555            break;
00556        case typeByteInt:
00557            result = AllDataType::compareByteIntVal(val1, val2, op);
00558            break;
00559        case typeDouble:
00560            result = AllDataType::compareDoubleVal(val1, val2, op);
00561            break;
00562        case typeFloat:
00563            result = AllDataType::compareFloatVal(val1, val2, op);
00564            break;
00565        case typeDecimal:
00566            //TODO::for porting
00567            break;
00568        case typeDate:
00569            result = AllDataType::compareDateVal(val1, val2, op);
00570            break;
00571        case typeTime:
00572            result = AllDataType::compareTimeVal(val1, val2, op);
00573            break;
00574        case typeTimeStamp:
00575            result = AllDataType::compareTimeStampVal(val1, val2, op);
00576            break;
00577        case typeString:
00578            result = AllDataType::compareStringVal(val1, val2, op);
00579            break;
00580        case typeBinary:
00581            result = AllDataType::compareBinaryVal(val1, val2, op, length);
00582            break;
00583     }
00584     return result;
00585 }
00586 
00587 bool AllDataType::compareIntVal(void* src1, void *src2, ComparisionOp op)
00588 {
00589     if (src1 == NULL) printf("src1 is null\n");
00590     if (src2 == NULL) printf("src2 is null\n");
00591     bool result = false;
00592     switch(op)
00593     {
00594         case OpEquals:
00595             if (*(int*)src1 == *(int*)src2) result = true;
00596             else result = false;
00597             break;
00598         case OpNotEquals:
00599             if (*(int*)src1 != *(int*)src2) result = true;
00600             else result = false;
00601             break;
00602         case OpLessThan:
00603             if (*(int*)src1 < *(int*)src2) result = true;
00604             else result = false;
00605             break;
00606         case OpLessThanEquals:
00607             if (*(int*)src1 <= *(int*)src2) result = true;
00608             else result = false;
00609             break;
00610         case OpGreaterThan:
00611             if (*(int*)src1 > *(int*)src2) result = true;
00612             else result = false;
00613             break;
00614         case OpGreaterThanEquals:
00615             if (*(int*)src1 >= *(int*)src2) result = true;
00616             else result = false;
00617             break;
00618    }
00619    return result;
00620 }
00621 
00622 bool AllDataType::compareLongVal(void* src1, void *src2, ComparisionOp op)
00623 {
00624     bool result = false;
00625     switch(op)
00626     {
00627         case OpEquals:
00628             if (*(long*)src1 == *(long*)src2) result = true;
00629             else result = false;
00630             break;
00631         case OpNotEquals:
00632             if (*(long*)src1 != *(long*)src2) result = true;
00633             else result = false;
00634             break;
00635         case OpLessThan:
00636             if (*(long*)src1 < *(long*)src2) result = true;
00637             else result = false;
00638             break;
00639         case OpLessThanEquals:
00640             if (*(long*)src1 <= *(long*)src2) result = true;
00641             else result = false;
00642             break;
00643         case OpGreaterThan:
00644             if (*(long*)src1 > *(long*)src2) result = true;
00645             else result = false;
00646             break;
00647         case OpGreaterThanEquals:
00648             if (*(long*)src1 >= *(long*)src2) result = true;
00649             else result = false;
00650             break;
00651    }
00652    return result;
00653 }
00654 
00655 bool AllDataType::compareLongLongVal(void* src1, void *src2,
00656                                       ComparisionOp op)
00657 {
00658     bool result = false;
00659     switch(op)
00660     {
00661         case OpEquals:
00662             if (*(long long*)src1 == *(long long*)src2) result = true;
00663             else result = false;
00664             break;
00665         case OpNotEquals:
00666             if (*(long long*)src1 != *(long long*)src2) result = true;
00667             else result = false;
00668             break;
00669         case OpLessThan:
00670             if (*(long long*)src1 < *(long long*)src2) result = true;
00671             else result = false;
00672             break;
00673         case OpLessThanEquals:
00674             if (*(long long*)src1 <= *(long long*)src2) result = true;
00675             else result = false;
00676             break;
00677         case OpGreaterThan:
00678             if (*(long long*)src1 > *(long long*)src2) result = true;
00679             else result = false;
00680             break;
00681         case OpGreaterThanEquals:
00682             if (*(long long*)src1 >= *(long long*)src2) result = true;
00683             else result = false;
00684             break;
00685    }
00686    return result;
00687 }
00688 
00689 bool AllDataType::compareShortVal(void* src1, void *src2, ComparisionOp op)
00690 {
00691     bool result = false;
00692     switch(op)
00693     {
00694         case OpEquals:
00695             if (*(short*)src1 == *(short*)src2) result = true;
00696             else result = false;
00697             break;
00698         case OpNotEquals:
00699             if (*(short*)src1 != *(short*)src2) result = true;
00700             else result = false;
00701             break;
00702         case OpLessThan:
00703             if (*(short*)src1 < *(short*)src2) result = true;
00704             else result = false;
00705             break;
00706         case OpLessThanEquals:
00707             if (*(short*)src1 <= *(short*)src2) result = true;
00708             else result = false;
00709             break;
00710         case OpGreaterThan:
00711             if (*(short*)src1 > *(short*)src2) result = true;
00712             else result = false;
00713             break;
00714         case OpGreaterThanEquals:
00715             if (*(short*)src1 >= *(short*)src2) result = true;
00716             else result = false;
00717             break;
00718    }
00719    return result;
00720 }
00721 
00722 bool AllDataType::compareByteIntVal(void* src1, void *src2, ComparisionOp op)
00723 {
00724     bool result = false;
00725     switch(op)
00726     {
00727         case OpEquals:
00728             if (*(ByteInt*)src1 == *(ByteInt*)src2) result = true;
00729             else result = false;
00730             break;
00731         case OpNotEquals:
00732             if (*(ByteInt*)src1 != *(ByteInt*)src2) result = true;
00733             else result = false;
00734             break;
00735         case OpLessThan:
00736             if (*(ByteInt*)src1 < *(ByteInt*)src2) result = true;
00737             else result = false;
00738             break;
00739         case OpLessThanEquals:
00740             if (*(ByteInt*)src1 <= *(ByteInt*)src2) result = true;
00741             else result = false;
00742             break;
00743         case OpGreaterThan:
00744             if (*(ByteInt*)src1 > *(ByteInt*)src2) result = true;
00745             else result = false;
00746             break;
00747         case OpGreaterThanEquals:
00748             if (*(ByteInt*)src1 >= *(ByteInt*)src2) result = true;
00749             else result = false;
00750             break;
00751    }
00752    return result;
00753 }
00754 
00755 bool AllDataType::compareDoubleVal(void* src1, void *src2, ComparisionOp op)
00756 {
00757     bool result = false;
00758     switch(op)
00759     {
00760         case OpEquals:
00761             if (*(double*)src1 == *(double*)src2) result = true;
00762             else result = false;
00763             break;
00764         case OpNotEquals:
00765             if (*(double*)src1 != *(double*)src2) result = true;
00766             else result = false;
00767             break;
00768         case OpLessThan:
00769             if (*(double*)src1 < *(double*)src2) result = true;
00770             else result = false;
00771             break;
00772         case OpLessThanEquals:
00773             if (*(double*)src1 <= *(double*)src2) result = true;
00774             else result = false;
00775             break;
00776         case OpGreaterThan:
00777             if (*(double*)src1 > *(double*)src2) result = true;
00778             else result = false;
00779             break;
00780         case OpGreaterThanEquals:
00781             if (*(double*)src1 >= *(double*)src2) result = true;
00782             else result = false;
00783             break;
00784    }
00785    return result;
00786 }
00787 
00788 bool AllDataType::compareFloatVal(void* src1, void *src2, ComparisionOp op)
00789 {
00790     bool result = false;
00791     switch(op)
00792     {
00793         case OpEquals:
00794             if (*(float*)src1 == *(float*)src2) result = true;
00795             else result = false;
00796             break;
00797         case OpNotEquals:
00798             if (*(float*)src1 != *(float*)src2) result = true;
00799             else result = false;
00800             break;
00801         case OpLessThan:
00802             if (*(float*)src1 < *(float*)src2) result = true;
00803             else result = false;
00804             break;
00805         case OpLessThanEquals:
00806             if (*(float*)src1 <= *(float*)src2) result = true;
00807             else result = false;
00808             break;
00809         case OpGreaterThan:
00810             if (*(float*)src1 > *(float*)src2) result = true;
00811             else result = false;
00812             break;
00813         case OpGreaterThanEquals:
00814             if (*(float*)src1 >= *(float*)src2) result = true;
00815             else result = false;
00816             break;
00817    }
00818    return result;
00819 }
00820 
00821 bool AllDataType::compareDateVal(void* src1, void *src2, ComparisionOp op)
00822 {
00823     bool result = false;
00824     switch(op)
00825     {
00826         case OpEquals:
00827             if (*(Date*)src1 == *(Date*)src2) result = true;
00828             else result = false;
00829             break;
00830         case OpNotEquals:
00831             if (*(Date*)src1 != *(Date*)src2) result = true;
00832             else result = false;
00833             break;
00834         case OpLessThan:
00835             if (*(Date*)src1 < *(Date*)src2) result = true;
00836             else result = false;
00837             break;
00838         case OpLessThanEquals:
00839             if (*(Date*)src1 <= *(Date*)src2) result = true;
00840             else result = false;
00841             break;
00842         case OpGreaterThan:
00843             if (*(Date*)src1 > *(Date*)src2) result = true;
00844             else result = false;
00845             break;
00846         case OpGreaterThanEquals:
00847             if (*(Date*)src1 >= *(Date*)src2) result = true;
00848             else result = false;
00849             break;
00850    }
00851    return result;
00852 }
00853 
00854 bool AllDataType::compareTimeVal(void* src1, void *src2, ComparisionOp op)
00855 {
00856     bool result = false;
00857     switch(op)
00858     {
00859         case OpEquals:
00860             if (*(Time*)src1 == *(Time*)src2) result = true;
00861             else result = false;
00862             break;
00863         case OpNotEquals:
00864             if (*(Time*)src1 != *(Time*)src2) result = true;
00865             else result = false;
00866             break;
00867         case OpLessThan:
00868             if (*(Time*)src1 < *(Time*)src2) result = true;
00869             else result = false;
00870             break;
00871         case OpLessThanEquals:
00872             if (*(Time*)src1 <= *(Time*)src2) result = true;
00873             else result = false;
00874             break;
00875         case OpGreaterThan:
00876             if (*(Time*)src1 > *(Time*)src2) result = true;
00877             else result = false;
00878             break;
00879         case OpGreaterThanEquals:
00880             if (*(Time*)src1 >= *(Time*)src2) result = true;
00881             else result = false;
00882             break;
00883    }
00884    return result;
00885 }
00886 
00887 bool AllDataType::compareTimeStampVal(void* src1, void *src2, ComparisionOp op)
00888 {
00889     bool result = false;
00890     switch(op)
00891     {
00892         case OpEquals:
00893             if (*(TimeStamp*)src1 == *(TimeStamp*)src2) result = true;
00894             else result = false;
00895             break;
00896         case OpNotEquals:
00897             if (*(TimeStamp*)src1 != *(TimeStamp*)src2) result = true;
00898             else result = false;
00899             break;
00900         case OpLessThan:
00901             if (*(TimeStamp*)src1 < *(TimeStamp*)src2) result = true;
00902             else result = false;
00903             break;
00904         case OpLessThanEquals:
00905             if (*(TimeStamp*)src1 <= *(TimeStamp*)src2) result = true;
00906             else result = false;
00907             break;
00908         case OpGreaterThan:
00909             if (*(TimeStamp*)src1 > *(TimeStamp*)src2) result = true;
00910             else result = false;
00911             break;
00912         case OpGreaterThanEquals:
00913             if (*(TimeStamp*)src1 >= *(TimeStamp*)src2) result = true;
00914             else result = false;
00915             break;
00916    }
00917    return result;
00918 }
00919 
00920 bool AllDataType::compareStringVal(void* src1, void *src2, ComparisionOp op)
00921 {
00922     bool result = false;
00923     int ret = strcmp((char*)src1, (char*)src2);
00924     switch(op)
00925     {
00926         case OpEquals:
00927             if (ret == 0 ) result= true; else result = false;
00928             break;
00929         case OpNotEquals:
00930             if (ret != 0 ) result= true; else result = false;
00931             break;
00932         case OpLessThan:
00933             if (ret < 0 ) result= true; else result = false;
00934             break;
00935         case OpLessThanEquals:
00936             printf("Illegal Operator:Not Supported for String\n");
00937             break;
00938         case OpGreaterThan:
00939             if (ret > 0 ) result= true; else result = false;
00940             break;
00941         case OpGreaterThanEquals:
00942             printf("Illegal Operator:Not Supported for String\n");
00943             break;
00944    }
00945    return result;
00946 }
00947 
00948 bool AllDataType::compareBinaryVal(void* src1, void *src2,
00949                                  ComparisionOp op, int length)
00950 {
00951     bool result = false;
00952     int ret = os::memcmp(src1, src2, length);
00953     switch(op)
00954     {
00955         case OpEquals:
00956             if (ret == 0 ) result= true; else result = false;
00957             break;
00958         case OpNotEquals:
00959             if (ret != 0 ) result= true; else result = false;
00960             break;
00961         case OpLessThan:
00962             if (ret < 0 ) result= true; else result = false;
00963             break;
00964         case OpLessThanEquals:
00965             printf("Illegal Operator:Not Supported for Binary\n");
00966             break;
00967         case OpGreaterThan:
00968             if (ret > 0 ) result= true; else result = false;
00969             break;
00970         case OpGreaterThanEquals:
00971             printf("Illegal Operator:Not Supported for Binary\n");
00972             break;
00973    }
00974    return result;
00975 }
00976 
00977 
00978 
00979 ComparisionOp AllDataType::getComparisionOperator(char *str)
00980 {
00981     ComparisionOp op;
00982     if (strcmp(str, "<=") == 0)
00983         op = OpLessThanEquals;
00984     else if (strcmp(str, ">=") == 0)
00985         op = OpGreaterThanEquals;
00986     else if (strcmp(str, "<") == 0)
00987         op = OpLessThan;
00988     else if (strcmp(str, ">") == 0)
00989         op = OpGreaterThan;
00990     else if (strcmp(str, "=") == 0)
00991         op = OpEquals;
00992     else if (strcmp(str, "!=") == 0 || strcmp(str, "<>") == 0 )
00993         op = OpNotEquals;
00994     else
00995         op = OpInvalidComparisionOp;
00996     return op;
00997 }
00998 
00999 void* AllDataType::alloc(DataType type, int length)
01000 {
01001     void *dest;
01002     switch(type)
01003     {
01004         case typeInt:
01005             dest = malloc(sizeof(int));
01006             break;
01007         case typeLong:
01008             dest = malloc(sizeof(long));
01009             break;
01010         case typeLongLong:
01011             dest = malloc(sizeof(long long));
01012             break;
01013         case typeShort:
01014             dest = malloc(sizeof(short));
01015             break;
01016         case typeByteInt:
01017             dest = malloc(sizeof(char));
01018             break;
01019         case typeDouble:
01020             dest = malloc(sizeof(double));
01021             break;
01022         case typeFloat:
01023             dest = malloc(sizeof(float));
01024             break;
01025         case typeDecimal:
01026             //TODO::for porting
01027             //fldDef.length_ = sizeof(long double);
01028             break;
01029         case typeString:
01030             if (length == 0 ) return NULL;
01031             dest = malloc(length);
01032             break;
01033         case typeDate:
01034             dest = malloc(sizeof(Date));
01035             break;
01036         case typeTime:
01037             dest = malloc(sizeof(Time));
01038             break;
01039         case typeTimeStamp:
01040             dest = malloc(sizeof(TimeStamp));
01041             break;
01042     }
01043     return dest;
01044 }
01045 void AllDataType::strToValue(void* dest, char *src, DataType type, int length)
01046 {
01047     switch(type)
01048     {
01049         case typeInt: {
01050             int val;
01051             sscanf( src, "%d",  &val);
01052             *(int*)dest = val;
01053             break; }
01054         case typeLong: {
01055             long val;
01056             sscanf( src, "%ld",  &val);
01057             *(long*)dest = val;
01058             break; }
01059         case typeLongLong: {
01060             long long val;
01061             sscanf( src, "%lld",  &val);
01062             *(long long*)dest = val;
01063             break; }
01064         case typeShort: {
01065             short val;
01066             sscanf( src, "%hd",  &val);
01067             *(short*)dest = val;
01068             break; }
01069         case typeByteInt: {
01070             char val;
01071             sscanf( src, "%c",  &val);
01072             *(char*)dest = val;
01073             break; }
01074         case typeDouble: {
01075             double val;
01076             sscanf( src, "%lg",  &val);
01077             *(double*)dest = val;
01078             break; }
01079         case typeFloat: {
01080             float val;
01081             sscanf( src, "%f",  &val);
01082             *(float*)dest = val;
01083             break; }
01084         case typeDecimal:
01085             //TODO::for porting
01086         case typeString: {
01087                 strncpy((char*)dest, (char*)src, length);
01088                 char *d =(char*)dest;
01089                 d[length-1] = '\0'; 
01090                 break;}
01091         case typeDate: {
01092             int d,m,y,res=0;
01093             res = sscanf( src, "%d-%d-%d", &y, &m, &d );
01094             if( res != 3 )
01095                  res = sscanf( src, "%d/%d/%d", &y, &m, &d );
01096             if( res != 3 )
01097             {
01098            fprintf(stderr,"Error reading date. yyyy{-/}mm{-/}dd is the valid format.");
01099                 d=m=y=0;
01100             }
01101             Date dateObj(y,m,d);
01102             *(Date*)dest = dateObj;
01103             break; }
01104         case typeTime: {
01105             int h,m,s,res=0;
01106             res = sscanf( src, "%d:%d:%d", &h, &m, &s );
01107             if( res != 3 )
01108             {
01109                 fprintf(stderr, "Error reading time, hh:mm:ss is the valid format.");
01110                 h=m=s=0;
01111             }
01112             Time timeObj(h,m,s);
01113             *(Time*)dest = timeObj;
01114             break; }
01115         case typeTimeStamp: {
01116             int d,m,y, h,mn,s, res=0;
01117             res = sscanf( src, "%d-%d-%d %d:%d:%d", &y, &m, &d, &h, &mn, &s );
01118             if( res != 6 )
01119                 res = sscanf( src, "%d-%d-%d, %d:%d:%d", &y, &m, &d, &h, &mn, &s );
01120             if( res != 6 )
01121                 res = sscanf( src, "%d/%d/%d %d:%d:%d", &y, &m, &d, &h, &mn, &s );
01122             if( res != 6 )
01123                 res = sscanf( src, "%d/%d/%d, %d:%d:%d", &y, &m, &d, &h, &mn, &s );
01124             if( res != 6 )
01125             {
01126                 fprintf(stderr, "Error reading timestamp, yyyy{-/}mm{-/}dd[,] hh:mm:ss is the valid format.");
01127                 d=m=y=h=mn=s=0;
01128             }
01129             TimeStamp timeStampObj(y,m,d,h,mn,s);
01130             *(TimeStamp*)dest = timeStampObj;
01131             break; }
01132         default:
01133             break;
01134         }
01135 }
01136 
01137 
01138 void AllDataType::convert(DataType srcType, void *src, 
01139                           DataType destType, void *dest)
01140 {
01141     switch ((DataType) destType )
01142     {
01143         case typeInt:        convertToInt(dest, src, srcType); break;
01144         case typeLong:       convertToLong(dest, src, srcType); break;
01145         case typeLongLong:   convertToLongLong(dest, src, srcType); break;
01146         case typeShort:      convertToShort(dest, src, srcType); break;
01147         case typeByteInt:    convertToByteInt(dest, src, srcType); break;
01148 
01149         case typeFloat:      convertToFloat(dest, src, srcType); break;
01150         case typeDouble:     convertToDouble(dest, src, srcType); break;
01151 
01152         //TODO 
01153         case typeDecimal:    convertToDouble(dest, src, srcType); break;
01154 
01155         case typeString:     convertToString(dest, src, srcType); break;
01156 
01157         case typeBinary:
01158         case typeDate:       convertToDate(dest, src, srcType); break;
01159         case typeTime:       convertToTime(dest, src, srcType); break;
01160         case typeTimeStamp:  convertToTimeStamp(dest, src, srcType); break;
01161         default: return;
01162     }
01163 }
01164 
01165 void AllDataType::convertToInt( void* dest, void* src, DataType srcType )
01166 {
01167     switch(srcType)
01168     {
01169         case typeInt:        *(int *)dest = *(int *)src; break;
01170         case typeLong:       *(int *)dest =(int) *(long *)src; break;
01171         case typeLongLong:   *(int *)dest =(int) *(long long *)src; break;
01172         case typeShort:      *(int *)dest =(int) *(short *)src; break;
01173         case typeByteInt:    *(int *)dest =(int) *(char *)src; break;
01174 
01175         case typeFloat:      *(int *)dest = (int) *(float *)src; break;
01176         case typeDouble:     *(int *)dest =(int) *(double *)src; break;
01177 
01178         case typeString:     sscanf((const char*)src, "%d", (int*) dest); break;
01179 
01180         case typeDate:
01181         case typeTime:
01182         case typeTimeStamp:
01183         case typeBinary:
01184         default:             *(int *)dest = (int) 0;
01185     }
01186 }
01187 
01188 void AllDataType::convertToLong( void* dest, void* src, DataType srcType )
01189 {
01190     switch(srcType)
01191     {
01192         case typeInt:        *(long *)dest =(long) *(int *)src; break;
01193         case typeLong:       *(long *)dest = *(long *)src; break;
01194         case typeLongLong:   *(long *)dest =(long) *(long long *)src; break;
01195         case typeShort:      *(long *)dest =(long) *(short *)src; break;
01196         case typeByteInt:    *(long *)dest =(long) *(char *)src; break;
01197 
01198         case typeFloat:      *(long *)dest = (long) *(float *)src; break;
01199         case typeDouble:     *(long *)dest =(long) *(double *)src; break;
01200 
01201         case typeString:     sscanf((const char*)src, "%ld", (long*) dest); break;
01202 
01203         case typeDate:
01204         case typeTime:
01205         case typeTimeStamp:
01206         case typeBinary:
01207         default:             *(long *)dest = (long) 0;
01208     }
01209 }
01210 
01211 
01212 void AllDataType::convertToLongLong( void* dest, void* src, DataType srcType )
01213 {
01214     switch(srcType)
01215     {
01216         case typeInt:        *(long long *)dest =(long long) *(int *)src; break;
01217         case typeLong:       *(long long *)dest = (long long) *(long *)src; break;
01218         case typeLongLong:   *(long long *)dest = *(long long *)src; break;
01219         case typeShort:      *(long long *)dest =(long long) *(short *)src; break;
01220         case typeByteInt:    *(long long *)dest =(long long) *(char *)src; break;
01221 
01222         case typeFloat:      *(long long *)dest = (long long) *(float *)src; break;
01223         case typeDouble:     *(long long *)dest =(long long) *(double *)src; break;
01224 
01225         case typeString:     sscanf((const char*)src, "%lld", (long long*) dest); break;
01226 
01227         case typeDate:
01228         case typeTime:
01229         case typeTimeStamp:
01230         case typeBinary:
01231         default:             *(long long *)dest = (long long) 0;
01232     }
01233 }
01234 
01235 void AllDataType::convertToShort( void* dest, void* src, DataType srcType )
01236 {
01237     switch(srcType)
01238     {
01239         case typeInt:        *(short*)dest =(short) *(int*)src; break;
01240         case typeLong:       *(short*)dest = (short) *(long*)src; break;
01241         case typeLongLong:   *(short*)dest = (short) *(long long*)src; break;
01242         case typeShort:      *(short*)dest = *(short*)src; break;
01243         case typeByteInt:    *(short*)dest =(short) *(char *)src; break;
01244 
01245         case typeFloat:      *(short*)dest = (short) *(float *)src; break;
01246         case typeDouble:     *(short*)dest =(short) *(double *)src; break;
01247 
01248         case typeString:     sscanf((const char*)src, "%hd", (short*) dest); break;
01249 
01250         case typeDate:
01251         case typeTime:
01252         case typeTimeStamp:
01253         case typeBinary:
01254         default:             *(short*)dest = (short) 0;
01255     }
01256 }
01257 
01258 void AllDataType::convertToByteInt( void* dest, void* src, DataType srcType )
01259 {
01260     switch(srcType)
01261     {
01262         case typeInt:        *(char*)dest = (char) *(int*)src; break;
01263         case typeLong:       *(char*)dest = (char) *(long*)src; break;
01264         case typeLongLong:   *(char*)dest = (char) *(long long*)src; break;
01265         case typeShort:      *(char*)dest = (char) *(short*)src; break;
01266         case typeByteInt:    *(char*)dest = *(char *)src; break;
01267 
01268         case typeFloat:      *(char*)dest = (char) *(float *)src; break;
01269         case typeDouble:     *(char*)dest =(char) *(double *)src; break;
01270 
01271         case typeString:     sscanf((const char*)src, "%c", (char*) dest); break;
01272 
01273         case typeDate:
01274         case typeTime:
01275         case typeTimeStamp:
01276         case typeBinary:
01277         default:             *(char*)dest = (char) 0;
01278     }
01279 }
01280 
01281 void AllDataType::convertToFloat( void* dest, void* src, DataType srcType )
01282 {
01283     switch(srcType)
01284     {
01285         case typeInt:        *(float *)dest =(float) *(int *)src; break;
01286         case typeLong:       *(float *)dest =(float) *(long *)src; break;
01287         case typeLongLong:   *(float *)dest =(float) *(long long *)src; break;
01288         case typeShort:      *(float *)dest =(float) *(short *)src; break;
01289         case typeByteInt:    *(float *)dest =(float) *(char *)src; break;
01290 
01291         case typeFloat:      *(float *)dest = *(float *)src; break;
01292         case typeDouble:     *(float *)dest =(float) *(double *)src; break;
01293 
01294         case typeString:     sscanf((const char*)src, "%f", (float*) dest); break;
01295 
01296         case typeDate:
01297         case typeTime:
01298         case typeTimeStamp:
01299         case typeBinary:
01300         default:             *(float *)dest = (float) 0;
01301     }
01302 }
01303 
01304 void AllDataType::convertToDouble( void* dest, void* src, DataType srcType )
01305 {
01306     switch(srcType)
01307     {
01308         case typeInt:        *(double *)dest =(double) *(int *)src; break;
01309         case typeLong:       *(double *)dest =(double) *(long *)src; break;
01310         case typeLongLong:   *(double *)dest =(double) *(long long *)src; break;
01311         case typeShort:      *(double *)dest =(double) *(short *)src; break;
01312         case typeByteInt:    *(double *)dest =(double) *(char *)src; break;
01313 
01314         case typeFloat:      *(double *)dest =(double) *(float *)src; break;
01315         case typeDouble:     *(double *)dest = *(double *)src; break;
01316 
01317         case typeString:     sscanf((const char*)src, "%lf", (double*) dest); break;
01318 
01319         case typeDate:
01320         case typeTime:
01321         case typeTimeStamp:
01322         case typeBinary:
01323         default:             *(double *)dest = (double) 0;
01324     }
01325 }
01326 
01327 void AllDataType::convertToString( void* dest, void* src, DataType srcType )
01328 {
01329     switch(srcType)
01330     {
01331         case typeInt:
01332         {
01333             sprintf ((char *)dest, "%d", *(int *)src); 
01334             break;
01335         }
01336         case typeLong:
01337         {
01338             sprintf ((char *)dest, "%ld", *(long *)src);
01339             break;
01340         }
01341         case typeLongLong:
01342         {
01343             sprintf ((char *)dest, "%lld", *(long long *)src); 
01344             break;
01345         }
01346         case typeShort:
01347         {
01348             sprintf ((char *)dest, "%hd", *(short *)src); 
01349             break;
01350         }
01351         case typeByteInt:
01352         {
01353             sprintf ((char *)dest, "%hd", *(char *)src); 
01354             break;
01355         }
01356 
01357         case typeFloat:
01358         {
01359             sprintf ((char *)dest, "%f", *(float *)src);
01360             break;
01361         }
01362         case typeDouble:
01363         {
01364             sprintf ((char *) dest, "%lf", *(double *)src); 
01365             break;
01366         }
01367 
01368         case typeString:
01369         {
01370             strcpy((char*)dest, (char*)src);
01371             break;
01372         }
01373         case typeDate:
01374         {
01375             Date* dt = (Date*)src;
01376             sprintf((char*) dest, "%d/%d/%d", dt->year(),
01377                                   dt->month(), dt->dayOfMonth());
01378             break;
01379         }
01380         case typeTime:
01381         {
01382             Time* tm = (Time*)src;
01383             sprintf((char*)dest,"%d:%d:%d.%d", tm->hours(), tm->minutes(), tm->seconds(), 0);
01384             break;
01385         }
01386         case typeTimeStamp:
01387         {
01388             TimeStamp* tm = (TimeStamp*)src;
01389             sprintf((char*)dest, "%d/%d/%d %d:%d:%d.%d", tm->year(),
01390                                 tm->month(), tm->dayOfMonth(), tm->hours(),
01391                                 tm->minutes(), tm->seconds(), 0 );
01392             break;
01393         }
01394         default: ((char*)dest)[0] = '\0';
01395     }
01396 
01397 }
01398 void AllDataType::convertToDate( void* dest, void* src, DataType srcType )
01399 {
01400     switch(srcType)
01401     {
01402         case typeInt:
01403         case typeLong:
01404         case typeLongLong:
01405         case typeShort:
01406         case typeByteInt:
01407         case typeFloat:
01408         case typeDouble:
01409         case typeDate:
01410         case typeTime:
01411         case typeTimeStamp:
01412         case typeString:
01413         {
01414             Date *dt = (Date*) dest;
01415             dt->parseFrom((char*)src);
01416             break;
01417         }
01418         default: ((char*)dest)[0] = '\0';
01419     }
01420 }
01421 
01422 void AllDataType::convertToTime( void* dest, void* src, DataType srcType )
01423 {
01424     switch(srcType)
01425     {
01426         case typeInt:
01427         case typeLong:
01428         case typeLongLong:
01429         case typeShort:
01430         case typeByteInt:
01431         case typeFloat:
01432         case typeDouble:
01433         case typeDate:
01434         case typeTime:
01435         case typeTimeStamp:
01436         case typeString:
01437         {
01438             Time *dt = (Time*) dest;
01439             dt->parseFrom((char*)src);
01440             break;
01441         }
01442         default: ((char*)dest)[0] = '\0';
01443     }
01444 }
01445 
01446 void AllDataType::convertToTimeStamp( void* dest, void* src, DataType srcType )
01447 {
01448     switch(srcType)
01449     {
01450         case typeInt:
01451         case typeLong:
01452         case typeLongLong:
01453         case typeShort:
01454         case typeByteInt:
01455         case typeFloat:
01456         case typeDouble:
01457         case typeDate:
01458         case typeTime:
01459         case typeTimeStamp:
01460         case typeString:
01461         {
01462             TimeStamp *dt = (TimeStamp*) dest;
01463             dt->parseFrom((char*)src);
01464             break;
01465         }
01466         default: ((char*)dest)[0] = '\0';
01467     }
01468 }
01469 
01470 int AllDataType::printVal(void* src, DataType srcType, int length )
01471 { 
01472     int count = 0;
01473     switch(srcType)
01474     {
01475         case typeInt:
01476         {
01477             count = printf ("%d", *(int *)src); 
01478             break;
01479         }
01480         case typeLong:
01481         {
01482             count = printf ("%ld", *(long *)src);
01483             break;
01484         }
01485         case typeLongLong:
01486         {
01487             count = printf ("%lld", *(long long *)src); 
01488             break;
01489         }
01490         case typeShort:
01491         {
01492             count = printf("%hd", *(short *)src); 
01493             break;
01494         }
01495         case typeByteInt:
01496         {
01497             count = printf("%hd", *(char *)src); 
01498             break;
01499         }
01500 
01501         case typeFloat:
01502         {
01503             count = printf("%f", *(float *)src);
01504             break;
01505         }
01506         case typeDouble:
01507         {
01508             count = printf("%lf", *(double *)src); 
01509             break;
01510         }
01511 
01512         case typeString:
01513         {
01514             count = printf("%s", (char*)src);
01515             break;
01516         }
01517         case typeDate:
01518         {
01519             Date* dt = (Date*)src;
01520             count = printf("%d/%d/%d", dt->year(),
01521                                   dt->month(), dt->dayOfMonth());
01522             break;
01523         }
01524         case typeTime:
01525         {
01526             Time* tm = (Time*)src;
01527             printf("%d:%d:%d.%d", tm->hours(), tm->minutes(), tm->seconds(), 0);
01528             break;
01529         }
01530         case typeTimeStamp:
01531         {
01532             TimeStamp* tm = (TimeStamp*)src;
01533             count = printf("%d/%d/%d %d:%d:%d.%d", tm->year(),
01534                                 tm->month(), tm->dayOfMonth(), tm->hours(),
01535                                 tm->minutes(), tm->seconds(), 0 );
01536             break;
01537         }
01538         default: { printf("DataType not supported\n"); break; }
01539     }
01540     return count;
01541 }
01542 
01543 
01544 

Generated on Mon Jun 9 22:37:15 2008 for csql by  doxygen 1.4.7