Changing default value for MAX_THREAD to 10
[csql.git] / include / DataType.h
blob567b4fc8320a05580e7e1a424d964110f2ddd030
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
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. *
9 * *
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. *
14 * *
15 ***************************************************************************/
16 #ifndef DATATYPE_H
17 #define DATATYPE_H
19 //#include<os.h>
20 typedef int JulianRep;
23 /**
24 * @class DataType
25 * Data Types supported by the database system.
26 * <br/>
27 * @author Prabakaran Thirumalai
29 enum DataType {
30 typeInt = 0, /**<integer type*/
31 typeLong = 1,
32 typeLongLong = 2,
33 typeShort = 3,
34 typeByteInt = 4,
36 typeDouble = 10,
37 typeFloat = 11,
38 typeDecimal = 12,
40 typeDate = 20,
41 typeTime = 21,
42 typeTimeStamp = 22,
44 typeString = 30,
45 typeBinary = 31,
47 typeULong = 99,
48 typeUnknown = 100
51 /**
52 * @class ComparisionOp
53 * Comparision operators supported by the database system.
54 * <br/>
55 * @author Prabakaran Thirumalai
57 enum ComparisionOp {
58 OpEquals = 0,
59 OpNotEquals,
60 OpLessThan,
61 OpLessThanEquals,
62 OpGreaterThan,
63 OpGreaterThanEquals,
64 OpInvalidComparision
67 /**
68 * @class LogicalOp
69 * Logical operators supported by the database system.
70 * <br/>
71 * @author Prabakaran Thirumalai
73 enum LogicalOp {
74 OpAnd = 0,
75 OpOr,
76 OpNot
80 class AllDataType
82 public:
83 static long size(DataType type);
84 static void copyVal(void* dest, void *src, DataType type, int length = 0);
86 static bool compareVal(void *src1, void *src2, ComparisionOp op,
87 DataType type, long length = 0);
88 static bool compareIntVal(void* src1, void* src2, ComparisionOp op);
89 static bool compareLongVal(void* src1, void* src2, ComparisionOp op);
90 static bool compareLongLongVal(void* src1, void* src2, ComparisionOp op);
91 static bool compareShortVal(void* src1, void* src2, ComparisionOp op);
92 static bool compareByteIntVal(void* src1, void* src2, ComparisionOp op);
93 static bool compareDoubleVal(void* src1, void* src2, ComparisionOp op);
94 static bool compareFloatVal(void* src1, void* src2, ComparisionOp op);
95 static bool compareDateVal(void* src1, void* src2, ComparisionOp op);
96 static bool compareTimeVal(void* src1, void* src2, ComparisionOp op);
97 static bool compareTimeStampVal(void* src1, void* src2, ComparisionOp op);
98 static bool compareStringVal(void* src1, void* src2, ComparisionOp op);
99 static bool compareBinaryVal(void* src1, void* src2,
100 ComparisionOp op, int length);
102 static ComparisionOp getComparisionOperator(char *str);
104 static void* alloc(DataType type);
105 static void strToValue(void *dest, char *src, DataType type);
112 * @class ByteInt
113 * Represents 8 bit integer.
114 * <br/>
115 * @author Prabakaran Thirumalai
117 class ByteInt {
119 public:
120 ByteInt() { }
122 /** copy constructor
124 ByteInt(const ByteInt &v) { val = v.val; }
125 /** constructor with char
126 * @param v char value
128 ByteInt(char v) { val = v; }
129 operator int() const { return (int) val; }
130 char operator=(ByteInt v) { return val = v.val; }
131 char operator=(char v) { return val = v; }
132 char operator+=(ByteInt v) { return val += v.val; }
133 char operator+=(char v) { return val += v; }
134 char operator-=(ByteInt v) { return val -= v.val; }
135 char operator-=(char v) { return val -= v; }
136 char operator*=(ByteInt v) { return val *= v.val; }
137 char operator*=(char v) { return val *= v; }
138 char operator/=(ByteInt v) { return val /= v.val; }
139 char operator/=(char v) { return val /= v; }
140 char operator%=(ByteInt v) { return val %= v.val; }
141 char operator%=(char v) { return val %= v; }
142 char operator<<=(ByteInt v) { return val <<= v.val; }
143 char operator<<=(char v) { return val <<= v; }
144 char operator>>=(ByteInt v) { return val >>= v.val; }
145 char operator>>=(char v) { return val >>= v; }
146 char operator&=(ByteInt v) { return val &= v.val; }
147 char operator&=(char v) { return val &= v; }
148 char operator|=(ByteInt v) { return val |= v.val; }
149 char operator|=(char v) { return val |= v; }
150 char operator^=(ByteInt v) { return val ^= v.val; }
151 char operator^=(char v) { return val ^= v; }
152 char operator++() { return val++; }
153 char operator--() { return val--; }
155 private:
156 signed char val;
161 * @class Date
162 * Represents Date Data type.
163 * <br/>
164 * @author Prabakaran Thirumalai
166 class Date { // The class a user would declare to hold date
168 public:
169 Date() {julianDate = 0;}
170 Date(JulianRep julian) : julianDate(julian) {}
172 /** constructor with year, month, day
173 * @param year year
174 * @param month month
175 * @param day day
177 Date(int year, int month, int day);
179 Date(const Date &d2) { julianDate = d2.julianDate; }
180 Date& operator=(const Date& d2)
181 { julianDate=d2.julianDate; return *this; }
183 /** sets the date with specified year, month, day
184 * @param year year
185 * @param month month
186 * @param day day
188 int set(int year, int month, int day);
189 int set(const struct tm *tmptr);
191 /** get year, month, day of the date
192 * @param year year IN
193 * @param month month IN
194 * @param day day IN
196 int get(int &year, int &month, int &day) const;
198 /** checks for the validity of the date
200 bool isValid() const;
202 /** resets the date to zero
204 void setNull() { julianDate = 0;}
206 /** returns day of the week
208 int dayOfWeek() const;
210 /** returns day of the week.
211 * values are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday".
213 const char *dayOfWeekName() const;
215 /** returns day of the week abbreviation
216 * values are "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
218 const char *dayOfWeekAbbr() const;
220 /** returns day of the week.
221 * values are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday".
223 static const char *dayOfWeekName(int day); // 0--> Sunday
225 /** returns day of the week abbreviation
226 * values are "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
228 static const char *dayOfWeekAbbr(int day);
230 static int dayOfWeek(JulianRep juldate);
233 /** returns the day of the month. Values are 1 to 31
235 int dayOfMonth() const;
237 int dayOfYear() const;
239 /** returns the month Values are 1 to 12.
241 int month() const;
243 /** returns the month name
244 * values are "January", "February", "March", "April", "May", "June",
245 * "July", "August", "September", "October", "November", "December"
247 const char *monthName() const;
249 /** returns the month name abbreviation
250 * values are "Jan", "Feb", "Mar", "Apr", "May", "Jun",
251 * "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
253 const char *monthAbbr() const;
255 /** returns the month name
256 * values are "January", "February", "March", "April", "May", "June",
257 * "July", "August", "September", "October", "November", "December"
259 static const char *monthName(int month);
262 /** returns the month name abbreviation
263 * values are "Jan", "Feb", "Mar", "Apr", "May", "Jun",
264 * "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
266 static const char *monthAbbr(int month);
268 /** parses the date string passed and stores it
269 *It should of the format "mm/dd/yyyy"
271 int parseFrom(const char *s);
273 Date &operator++() { julianDate++; return *this; }
274 Date &operator--() { julianDate--; return *this; }
276 Date &operator+=(int days) { julianDate += days; return *this;}
277 Date &operator-=(int days) { julianDate -= days; return *this;}
279 /** returns the year
281 int year() const;
283 /** checks for the validity of the date
285 static bool isValidDate(int year, int month, int day);
287 friend Date operator+(const Date &d1, int days);
288 friend Date operator+(int days, const Date &d1);
289 friend Date operator-(const Date &d1, int days);
290 friend int operator-(const Date &d1, const Date & d2);
291 friend int operator<(const Date &d1 ,const Date &d2);
292 friend int operator>(const Date &d1 ,const Date &d2);
293 friend int operator<=(const Date &d1 ,const Date &d2);
294 friend int operator>=(const Date &d1 ,const Date &d2);
295 friend int operator==(const Date &d1 ,const Date &d2);
296 friend int operator!=(const Date &d1 ,const Date &d2);
298 /** checks for leap year
300 static bool isLeapYear(int year);
302 /** returns the number of days in the specified month of the year.
304 static int daysInMonth(int month, int year);
306 static int YMDToJulian(int year,int mon,int day, JulianRep &julian);
307 static int julianToYMD(JulianRep julian,int &year,int &month,int &day);
309 private:
310 JulianRep julianDate;
317 * @class Time
318 * Represents Time Data type.
319 * <br/>
320 * @author Prabakaran Thirumalai
322 class Time { // The class a user would declare to hold time
323 public:
324 Time() {timeVal = 0;}
326 /** Overloaded constructor
327 * @param hours hours
328 * @param mins mins
329 * @param secs secs
330 * @param usec usec
332 Time(int hours, int mins, int secs, int usec = 0);
333 Time(int totalSecs) : timeVal(totalSecs) {;}
334 Time(const Time &d2) { timeVal = d2.timeVal; }
335 Time& operator=(const Time& d2) { timeVal=d2.timeVal; return *this; }
337 /** sets the time with specified hours, mins, secs
338 * @param hours hours
339 * @param mins mins
340 * @param secs secs
341 * @param usec usec
343 int set(int hours, int mins, int secs, int usec = 0);
345 /** retrieves the time using IN parameters
346 * @param hours hours
347 * @param mins mins
348 * @param secs secs
350 int get(int &hours, int &mins, int &secs) const;
352 /** checks for the validity of the time
354 bool isValid() const;
356 /** resets the time
358 void setNull() { timeVal = -1;}
360 int secondsSinceMidnight() const { return timeVal/10000;}
362 /** returns the microsecs
364 int usec() const; // to nearest 100 of usec.
366 /** returns the millisecs
368 int msec() const;
370 /** returns the secs
372 int seconds() const;
374 /** returns the minutes
376 int minutes() const;
378 /** returns the hours
380 int hours() const;
383 /** sets the millisecs
385 int setMsec(int ms);
387 /** sets the microsecs
389 int setUsec(int us);
391 /** parses the time string passed and stores it
392 *It should of the format "hh:mm::ss"
394 int parseFrom(const char *s);
396 Time &operator++() { timeVal += 10000; return *this; }
397 Time &operator--() { timeVal -= 10000; return *this; }
399 Time &operator+=(int seconds) { timeVal += seconds*10000; return *this; }
400 Time &operator-=(int seconds) { timeVal -= seconds*10000; return *this; }
403 /** checks for the validity of the time specified
405 static bool isValidTime(int hours, int mins, int secs);
407 friend Time operator+(const Time &t1, int seconds);
408 friend Time operator+(int seconds, const Time &t1);
409 friend Time operator-(const Time &t1, int seconds);
410 friend int operator-(const Time &t1, const Time& t2);
411 friend int operator<(const Time &t1 ,const Time &t2 );
412 friend int operator>(const Time &t1 ,const Time &t2 );
413 friend int operator<=(const Time &t1 ,const Time &t2 );
414 friend int operator>=(const Time &t1 ,const Time &t2 );
415 friend int operator==(const Time &t1 ,const Time &t2 );
416 friend int operator!=(const Time &t1 ,const Time &t2 );
419 private:
420 int timeVal;
424 * @class TimeStamp
425 * Represents TimeStamp Data type.
426 * <br/>
427 * @author Prabakaran Thirumalai
429 class TimeStamp {
431 public:
432 TimeStamp() {}
434 /** Overloaded constructor
435 * @param year year
436 * @param month month
437 * @param day day
438 * @param hours hours
439 * @param mins mins
440 * @param secs secs
441 * @param usec usec
443 TimeStamp(int year, int month, int day, int hour, int minute, int sec, int usec = 0) :
444 date(year, month, day), time(hour, minute, sec, usec) { }
446 TimeStamp(const TimeStamp &ts)
447 { date = ts.date; time = ts.time; }
448 TimeStamp(const Date &d, Time &t) : date(d), time(t) {}
451 TimeStamp& operator=(const TimeStamp& d2)
452 { date=d2.date; time = d2.time; return *this; }
454 /** get year, month, day from the date part of the timestamp
455 * @param year year IN
456 * @param month month IN
457 * @param day day IN
459 int getDate(int &year, int &month, int &day)
460 { return date.get(year, month, day); }
462 /** get the date part of the timestamp
463 * @param Date date
465 void getDate(Date &newDate) const
466 { newDate = date; }
468 /** sets the date with specified year, month, day
469 * @param year year
470 * @param month month
471 * @param day day
473 int setDate(int year, int month, int day)
474 { return date.set(year, month, day); }
476 /** set the date part of the timestamp
477 * @param Date date
479 void setDate(const Date &newDate)
480 { date = newDate; }
483 operator Date() { return date; }
484 operator Time() { return time; }
488 /** retrieves the time using IN parameters
489 * @param hours hours
490 * @param mins mins
491 * @param secs secs
493 int getTime(int &hours, int &mins, int &secs) const
494 { return time.get(hours, mins, secs); }
495 /** retrieves the time part of the timestamp
496 * @param newTime Time
498 void getTime(Time &newTime) const
499 { newTime = time; }
501 /** sets the time with specified hours, mins, secs
502 * @param hours hours
503 * @param mins mins
504 * @param secs secs
505 * @param usec usec
507 int setTime(int hours, int mins, int secs, int usec = 0)
508 { return time.set(hours, mins, secs, usec); }
510 /** set the time part of the timestamp
511 * @param newTime Time
513 void setTime(const Time &newTime)
514 { time = newTime; }
516 /** checks for the validity of the timestamp
518 bool isValid() const { return date.isValid() && time.isValid(); }
520 /** resets the date and time */
521 void setNull() { date.setNull(); time.setNull(); }
523 /** returns day of the week. Values are 1-7
525 int dayOfWeek() const { return date.dayOfWeek(); }
527 /** returns day of the week.
528 * values are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Satur
529 day".
531 const char *dayOfWeekName() const { return date.dayOfWeekName(); }
533 /** returns day of the week abbreviation
534 * values are "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
536 const char *dayOfWeekAbbr() const { return date.dayOfWeekAbbr(); }
538 /** returns the day of the month. Values are 1 to 31
540 int dayOfMonth() const { return date.dayOfMonth(); }
541 int dayOfYear() const { return date.dayOfYear(); }
543 /** returns the month. Values are 1 to 12.
546 int month() const { return date.month(); }
548 /** returns the month name
549 * values are "January", "February", "March", "April", "May", "June",
550 * "July", "August", "September", "October", "November", "December"
552 const char *monthName() const { return date.monthName(); }
554 /** returns the month name abbreviation
555 * Values are "Jan", "Feb", "Mar", "Apr", "May", "Jun",
556 * "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
558 const char *monthAbbr() const { return date.monthAbbr(); }
560 /** returns the year
562 int year() const { return date.year(); }
564 int secondsSinceMidnight() const { return time.secondsSinceMidnight(); }
565 /** returns the seconds */
566 int seconds() const { return time.seconds(); }
567 /** returns the minutes */
568 int minutes() const { return time.minutes(); }
569 /** returns the hours */
570 int hours() const { return time.hours(); }
571 /** returns the millisecs */
572 int msec() const { return time.msec(); }
573 /** returns the microsecs */
574 int usec() const { return time.usec(); }
576 /** sets the millisecs */
577 int setMsec(int ms) { return time.setMsec(ms) ; }
578 /** sets the microsecs */
579 int setUsec(int us) { return time.setUsec(us) ; }
581 /** parses the date string passed and stores it
582 *It should of the format "mm/dd/yyyy"
584 int parseDateFrom(const char *s) { return date.parseFrom(s); }
586 /** parses the time string passed and stores it
587 *It should of the format "hh:mm::ss"
590 int parseTimeFrom(const char *s) { return time.parseFrom(s); }
592 friend int operator<(const TimeStamp &d1, const TimeStamp &d2);
593 friend int operator>(const TimeStamp &d1, const TimeStamp &d2);
594 friend int operator<=(const TimeStamp &d1, const TimeStamp &d2);
595 friend int operator>=(const TimeStamp &d1, const TimeStamp &d2);
596 friend int operator==(const TimeStamp &d1, const TimeStamp &d2);
597 friend int operator!=(const TimeStamp &d1, const TimeStamp &d2);
600 private:
601 Date date;
602 Time time;
606 #endif