29 #endif //ENABLE_CFITSIO 34 void copyTimeStruct(MYSQL_TIME mysql,
struct tm* tm) {
35 tm->tm_sec = mysql.second;
36 tm->tm_min = mysql.minute;
37 tm->tm_hour = mysql.hour;
38 tm->tm_mday = mysql.day;
39 tm->tm_mon = mysql.month - 1;
40 tm->tm_year = mysql.year - 1900;
44 void copyTimeStruct(
struct tm tm, MYSQL_TIME* mysql) {
45 mysql->second = tm.tm_sec ;
46 mysql->minute = tm.tm_min ;
47 mysql->hour = tm.tm_hour;
48 mysql->day = tm.tm_mday;
49 mysql->month = tm.tm_mon + 1;
50 mysql->year = tm.tm_year + 1900;
63 const char* ret = NULL;
65 static const char* templ[] = {
89 static const int ntempl =
sizeof(templ) /
sizeof(
char*);
93 memset(tm,
'\0',
sizeof (*tm));
95 for (i=0; i<ntempl; i++) {
96 ret = strptime(s, templ[i], tm);
129 case UTC: gmtime_r(&time, &tm);
break;
130 case LOCAL: localtime_r(&time, &tm);
133 copyTimeStruct(tm, mysql);
146 memset(&tm,
'\0',
sizeof(tm));
147 copyTimeStruct(*mysql, &tm);
150 case UTC: ret = timegm(&tm);
break;
151 case LOCAL: ret = my_timelocal(&tm);
169 { this->mysql = mysql; }
195 time_t mcs::my_timelocal(
struct tm* tm) {
196 bool h2 = (tm->tm_hour == 2);
197 time_t time = timelocal(tm);
200 if (tm->tm_isdst == 1) {
205 localtime_r(&t, &tm_before);
207 if (h2 && (tm_before.tm_isdst == 0))
208 cout <<
"DST Warning: given datetime does not exists!" << endl;
210 if (tm_before.tm_isdst == 1)
218 localtime_r(&t, &tm_after);
220 if (h2 && (tm_after.tm_isdst == 0))
221 cout <<
"DST Warning: given datetime is ambiguous!" << endl;
232 parseTime(s.c_str(), &tm);
235 case UTC: time = timegm(&tm);
break;
236 case LOCAL: time = my_timelocal(&tm);
break;
251 case UTC: time = timegm(&tm);
break;
252 case LOCAL: time = my_timelocal(&tm);
break;
269 time_t time = getTime();
272 case UTC: gmtime_r(&time, &tm);
break;
273 case LOCAL: localtime_r(&time, &tm);
break;
285 time_t time = getTime();
288 case UTC: gmtime_r(&time, &tm);
break;
289 case LOCAL: localtime_r(&time, &tm);
break;
292 strftime(buf, 30,
"%F %T", &tm);
316 if (isunsigned) ret =
"UNSIGNED ";
320 ret +=
"TINY";
break;
322 ret +=
"SMALL";
break;
324 ret +=
"MEDIUM";
break;
328 ret +=
"BIGINT";
break;
330 ret =
"FLOAT";
break;
332 ret =
"DOUBLE";
break;
334 ret =
"STRING";
break;
338 ret =
"TINY_BLOB";
break;
340 ret =
"BLOB" ;
break;
398 case MYSQL_TYPE_TINY:
399 ret =
"TINYINT";
break;
400 case MYSQL_TYPE_SHORT:
401 ret =
"SMALLINT";
break;
402 case MYSQL_TYPE_INT24:
403 ret =
"MEDIUMINT";
break;
404 case MYSQL_TYPE_LONG:
406 case MYSQL_TYPE_LONGLONG:
407 ret =
"BIGINT";
break;
408 case MYSQL_TYPE_FLOAT:
409 ret =
"FLOAT";
break;
410 case MYSQL_TYPE_DOUBLE:
411 ret =
"DOUBLE";
break;
412 case MYSQL_TYPE_STRING:
414 case MYSQL_TYPE_VAR_STRING:
416 case MYSQL_TYPE_TIME:
418 case MYSQL_TYPE_DATE:
420 case MYSQL_TYPE_DATETIME:
422 case MYSQL_TYPE_TIMESTAMP:
424 case MYSQL_TYPE_TINY_BLOB:
425 ret =
"TINYBLOB";
break;
426 case MYSQL_TYPE_BLOB:
439 case MYSQL_TYPE_TINY:
441 case MYSQL_TYPE_SHORT:
443 case MYSQL_TYPE_INT24:
445 case MYSQL_TYPE_LONG:
447 case MYSQL_TYPE_LONGLONG:
449 case MYSQL_TYPE_FLOAT:
451 case MYSQL_TYPE_DOUBLE:
453 case MYSQL_TYPE_STRING:
455 case MYSQL_TYPE_VAR_STRING:
457 case MYSQL_TYPE_TIME:
459 case MYSQL_TYPE_DATE:
461 case MYSQL_TYPE_DATETIME:
463 case MYSQL_TYPE_TIMESTAMP:
465 case MYSQL_TYPE_TINY_BLOB:
467 case MYSQL_TYPE_BLOB:
481 mtype = MYSQL_TYPE_TINY;
break;
483 mtype = MYSQL_TYPE_SHORT;
break;
485 mtype = MYSQL_TYPE_INT24;
break;
487 mtype = MYSQL_TYPE_LONG;
break;
489 mtype = MYSQL_TYPE_LONGLONG;
break;
491 mtype = MYSQL_TYPE_FLOAT;
break;
493 mtype = MYSQL_TYPE_DOUBLE;
break;
495 mtype = MYSQL_TYPE_STRING;
break;
497 mtype = MYSQL_TYPE_DATETIME;
break;
499 mtype = MYSQL_TYPE_TINY_BLOB;
break;
501 mtype = MYSQL_TYPE_BLOB;
break;
511 enum enum_field_types mtype;
531 dbt =
TINY; isunsigned = true ;
break;
533 dbt =
TINY; isunsigned = true ;
break;
537 dbt =
SMALL; ;
break;
539 dbt =
SMALL; isunsigned = true ;
break;
545 dbt =
INT; isunsigned = true ;
break;
547 dbt =
INT; isunsigned = true ;
break;
568 if (isunsigned) fits = TBYTE;
572 if (isunsigned) fits = TLONG;
576 if (isunsigned) fits = TLONGLONG;
580 if (isunsigned) fits = TLONGLONG;
584 if (isunsigned)
return false;
585 else fits = TLONGLONG;
588 fits = TFLOAT;
break;
590 fits = TDOUBLE;
break;
592 fits = TSTRING;
break;
594 fits = TSTRING;
break;
619 if (isunsigned) fits =
"1B";
623 if (isunsigned) fits =
"1J";
627 if (isunsigned) fits =
"1K";
630 if (isunsigned) fits =
"1K";
634 if (isunsigned)
return false;
635 else fits =
"1K";
break;
641 fits =
itos(len) +
"A";
break;
657 {
return ldimspec & 15; }
662 {
return ldimspec >> 4; }
666 string buildDimSpec(
int ldimspec,
const unsigned short int ldim[MCS_DATA_NDIM])
670 int howManyDim = ldimspec & 15;
671 int varyingDim = ldimspec >> 4;
673 for (i=0; (i<howManyDim) || (i<varyingDim); i++) {
692 unsigned char howManyDim, varyingDim;
702 throw MCS_ERROR( MSG_CANT_BIND_AND_HAVE_DIMSPEC );
705 for (i=0; i<MCS_DATA_NDIM; i++)
713 vector<string> values =
split(dimSpec,
"x");
714 if (values.size() > MCS_DATA_NDIM)
715 throw MCS_ERROR( MSG_TOO_MANY_DIMSPEC, MCS_DATA_NDIM);
718 for (i=0; i<values.size(); i++) {
719 string s = values[i];
723 if (strchr(s.c_str(),
'*')) {
725 if (i != values.size() - 1)
726 throw MCS_ERROR( MSG_VARYING_MUST_BE_LAST );
734 s.replace(s.find(
"*", 0), 1,
" ");
749 lmaxlength = ldim[0];
752 for (i=0; i<MCS_DATA_NDIM-2; i++)
755 ldim[MCS_DATA_NDIM-1] = 1;
769 llength = lmaxlength;
771 ldimspec = (varyingDim << 4) + howManyDim;
774 for (i=1; i<MCS_DATA_NDIM-1; i++)
775 mult[i] = mult[i-1] * ldim[i-1];
796 array(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15);
802 unsigned short int i2,
803 unsigned short int i3,
804 unsigned short int i4,
805 unsigned short int i5,
806 unsigned short int i6,
807 unsigned short int i7,
808 unsigned short int i8,
809 unsigned short int i9,
810 unsigned short int i10,
811 unsigned short int i11,
812 unsigned short int i12,
813 unsigned short int i13,
814 unsigned short int i14,
815 unsigned short int i15)
818 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 1, i1);
821 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 2, i2);
824 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 3, i3);
827 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 4, i4);
830 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 5, i5);
833 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 6, i6);
836 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 7, i7);
839 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 8, i8);
842 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 9, i9);
845 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 10, i10);
848 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 11, i11);
851 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 12, i12);
854 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 13, i13);
857 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 14, i14);
860 throw MCS_ERROR(MSG_WRONG_DIM_SPEC, 15, i15);
898 else if (d > MCS_DATA_NDIM)
918 if (varyingDim() == 0)
919 throw MCS_ERROR( MSG_NO_DIM_ALLOWED_TO_CHANGE );
922 ldim[varyingDim() - 1] = newsize;
929 void mcs::Data::reallocBuffer()
931 unsigned int old_bufsize = bufsize;
935 for (
int i=0; i<MCS_DATA_NDIM; i++)
938 bufsize = lmaxlength * arrsize;
941 buf = (
char*) malloc(bufsize);
942 memset(buf, 0, bufsize);
945 buf = (
char*) realloc(buf, bufsize);
947 if (bufsize > old_bufsize) {
949 memset(buf + old_bufsize, 0, bufsize - old_bufsize);
957 unsigned short int maxLength,
bool isunsigned,
960 MCS_DEBUG_SETUP(0,
"Data");
965 lname = string(name);
966 lisunsigned = isunsigned;
968 lautoincr = (bool) (flags & AUTO_INCREMENT_FLAG);
971 setSourceID(MCS_ID_UNKNOWN);
972 setDestID(MCS_ID_UNKNOWN);
979 for (
int i=0; i<MCS_DATA_NDIM; i++)
985 lmaxlength =
sizeof(char);
break;
987 lmaxlength =
sizeof(
short int);
break;
989 lmaxlength =
sizeof(int);
break;
991 lmaxlength =
sizeof(int);
break;
993 lmaxlength =
sizeof(
long long int);
break;
995 lmaxlength =
sizeof(float);
break;
997 lmaxlength =
sizeof(double);
break;
999 lmaxlength =
sizeof(char) * maxLength;
1009 lmaxlength =
sizeof(MYSQL_TIME);
1012 lmaxlength =
sizeof(char) * maxLength;
break;
1014 lmaxlength =
sizeof(char) * maxLength;
break;
1016 lmaxlength =
sizeof(
void*);
break;
1018 throw MCS_ERROR(MSG_TYPE_NOT_HANDLED, 0, ltype);
1029 dt.setMysqlBuffer((MYSQL_TIME*) buf);
1032 llength = lmaxlength;
1035 enum_field_types mytype;
1040 memset(lbind, 0,
sizeof(MYSQL_BIND));
1041 lbind->buffer = buf;
1043 lbind->buffer_type =
1044 (mytype == MYSQL_TYPE_INT24 ? MYSQL_TYPE_LONG : mytype);
1046 lbind->buffer_length = lmaxlength;
1047 lbind->is_unsigned = lisunsigned;
1048 lbind->is_null = &lisnull;
1049 lbind->length = &llength;
1065 unsigned short int maxLength,
bool isunsigned,
1066 unsigned int flags,
unsigned char tag)
1070 init(bind, type, name, maxLength, isunsigned, flags);
1072 MCS_DEBUG(
"-> " <<
sval());
1081 init(NULL, type,
"", maxLength, isunsigned, 0);
1096 (
char*) from.
lname.c_str(),
1115 init(NULL,
INT,
"", 0,
false, 0);
1118 MCS_DEBUG(
"-> " <<
sval());
1128 MCS_DEBUG(
"-> " <<
sval());
1138 MCS_DEBUG(
"-> " <<
sval());
1145 init(NULL,
STRING,
"", v.length(),
false, 0);
1151 MCS_DEBUG(
"-> " <<
sval());
1160 MCS_DEBUG(
"-> " <<
sval());
1169 MCS_DEBUG(
"-> " <<
sval());
1203 unsigned int pos =
arrpos;
1216 if (
lisunsigned) ret = (*((
unsigned char* ) buf));
1217 else ret = (*((
char* ) buf));
1220 if (
lisunsigned) ret = (*((
unsigned short int* ) buf));
1221 else ret = (*((
short int* ) buf));
1225 else ret = (*((
int* ) buf));
1229 else ret = (*((
int* ) buf));
1232 if (
lisunsigned) ret = (*((
unsigned long long int*) buf));
1233 else ret = (*((
long long int* ) buf));
1236 ret = (int) rintf(*((
float*)
buf));
1239 ret = (int) rint(*((
double*)
buf));
1242 if (sscanf(buf,
ifmt, &ret) != 1)
1243 throw MCS_ERROR(MSG_CONVERSION_STRING_INT);
1246 return (
int)
tval();
1249 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1252 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1255 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1262 if (
lisunsigned) ret = (*((
unsigned char* ) buf));
1263 else ret = (*((
char* ) buf));
1266 if (
lisunsigned) ret = (*((
unsigned short int* ) buf));
1267 else ret = (*((
short int* ) buf));
1271 else ret = (*((
int* ) buf));
1275 else ret = (*((
int* ) buf));
1278 if (
lisunsigned) ret = (*((
unsigned long long int*) buf));
1279 else ret = (*((
long long int* ) buf));
1282 ret = (int) rintf(*((
float*)
buf));
1285 ret = (int) rint(*((
double*)
buf));
1288 if (sscanf(buf,
ifmt, &ret) != 1)
1289 throw MCS_ERROR(MSG_CONVERSION_STRING_INT);
1292 return (
int)
tval();
1295 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1298 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1301 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1316 if (
lisunsigned) ret = (*((
unsigned char* ) buf));
1317 else ret = (*((
char* ) buf));
1320 if (
lisunsigned) ret = (*((
unsigned short int* ) buf));
1321 else ret = (*((
short int* ) buf));
1325 else ret = (*((
int* ) buf));
1329 else ret = (*((
int* ) buf));
1332 if (
lisunsigned) ret = (*((
unsigned long long int*) buf));
1333 else ret = (*((
long long int* ) buf));
1336 ret = (
unsigned int) rintf(*((
float*)
buf));
1339 ret = (
unsigned int) rint(*((
double*)
buf));
1342 if (sscanf(buf,
ifmt, &ret) != 1)
1343 throw MCS_ERROR(MSG_CONVERSION_STRING_INT);
1346 return (
unsigned int)
tval();
1348 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1351 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1354 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1377 ret = (*((
unsigned long long int*) buf));
1379 ret = (*((
long long int*) buf));
1381 case FLOAT : ret = (
long long int) rintf(*((
float*)
buf));
break;
1382 case DOUBLE: ret = (
long long int) rint(*((
double*)
buf));
break;
1383 case TIME : ret = (
long long int)
tval();
break;
1385 if (sscanf(buf,
lfmt, &ret) != 1)
1386 throw MCS_ERROR(MSG_CONVERSION_STRING_INT);
1391 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1400 unsigned long long int ret;
1413 ret = (*((
unsigned long long int*) buf));
1415 ret = (*((
long long int*) buf));
1417 case FLOAT : ret = (
long long int) rintf(*((
float*)
buf));
break;
1418 case DOUBLE: ret = (
long long int) rint(*((
double*)
buf));
break;
1419 case TIME : ret = (
long long int)
tval();
break;
1421 if (sscanf(buf,
lfmt, &ret) != 1)
1422 throw MCS_ERROR(MSG_CONVERSION_STRING_INT);
1427 throw MCS_ERROR(MSG_CONVERSION_BLOB_INT);
1449 case FLOAT: ret = (*((
float*) buf));
break;
1450 case DOUBLE: ret = (float) (*((
double*)
buf));
break;
1452 if (sscanf(buf,
ffmt, &ret) != 1)
1453 throw MCS_ERROR(MSG_CONVERSION_STRING_FLOAT);
1458 throw MCS_ERROR(MSG_CONVERSION_BLOB_FLOAT);
1481 case DOUBLE: ret = (*((
double*) buf));
break;
1483 if (sscanf(buf,
dfmt, &ret) != 1)
1484 throw MCS_ERROR(MSG_CONVERSION_STRING_FLOAT);
1489 throw MCS_ERROR(MSG_CONVERSION_BLOB_FLOAT);
1560 unsigned long long int ul;
1571 sprintf(lbuf,
ifmt, l);
1577 sprintf(lbuf,
lfmt, l);
1581 sprintf(lbuf,
lfmt, ul);
1586 sprintf(lbuf,
ffmt, f);
1590 sprintf(lbuf,
dfmt, d);
1602 if (! addWhiteSpaces)
1621 if (l < maxlength) {
1622 memcpy(c, s.c_str(), l+1);
1631 void* mcs::Data::pval()
const 1634 memcpy(&p,
buf,
sizeof(
void*));
1638 void mcs::Data::setpval(
void* p)
1640 memcpy(
buf, &p,
sizeof(
void*));
1667 typedef int64_t MCS_TIME;
1669 #define MCS_TIME_MICROSEC 0xFFFFF // 20 bit, 0 tot, microsecond resolution, not yet used. 1670 #define MCS_TIME_SEC 0x3F // 6 bit, 20 tot 1671 #define MCS_TIME_MIN 0x3F // 6 bit, 26 tot 1672 #define MCS_TIME_HOUR 0x1F // 5 bit, 32 tot 1673 #define MCS_TIME_DAY 0x1F // 5 bit, 37 tot 1674 #define MCS_TIME_MONTH 0xF // 4 bit, 42 tot 1675 #define MCS_TIME_YEAR 0xFFFF // 16 bit, 46 tot 1676 #define MCS_TIME_FLAGS 0x3 // 2 bit, 52 tot, not yet used 1679 MCS_TIME struct_tm2MCS_TIME(
struct tm* ct)
1682 time_t t = timelocal(ct);
1686 (((MCS_TIME) ct->tm_sec ) << 20) +
1687 (((MCS_TIME) ct->tm_min ) << 26) +
1688 (((MCS_TIME) ct->tm_hour) << 32) +
1689 (((MCS_TIME) ct->tm_mday) << 37) +
1690 (((MCS_TIME) ct->tm_mon ) << 42) +
1691 (((MCS_TIME) ct->tm_year) << 46) ;
1697 int MCS_TIME2struct_tm(MCS_TIME mt,
struct tm* ct)
1699 ct->tm_sec = (int) ((mt >> 20) & MCS_TIME_SEC );
1700 ct->tm_min = (int) ((mt >> 26) & MCS_TIME_MIN );
1701 ct->tm_hour = (int) ((mt >> 32) & MCS_TIME_HOUR );
1702 ct->tm_mday = (int) ((mt >> 37) & MCS_TIME_DAY );
1703 ct->tm_mon = (int) ((mt >> 42) & MCS_TIME_MONTH);
1704 ct->tm_year = (int) ((mt >> 46) & MCS_TIME_YEAR );
1707 time_t t = timegm(ct);
1708 localtime_r(&t, ct);
1715 #define DATETIME_PARSE_NTEMPL 16 1717 static const char* templ[DATETIME_PARSE_NTEMPL] = {
1745 const char* ret = NULL;
1747 memset(tm,
'\0',
sizeof(*tm));
1749 for (i=0; i<DATETIME_PARSE_NTEMPL; i++) {
1750 ret = strptime(s.c_str(), templ[i], tm);
1751 if (ret != NULL)
break;
1755 throw MCS_ERROR(MSG_CONVERSION_DATETIME, s.c_str());
1830 throw MCS_ERROR(MSG_CONVERSION_BLOB_DATETIME);
1832 time_t tt = (time_t)
dval();
1833 localtime_r(&tt, ts);
1842 return timelocal(&ts);
1850 void mcs::Data::setTimeMode(
enum TimeMode tm)
1878 throw MCS_ERROR(MSG_CONVERSION_TIME_LINT);
1890 throw MCS_ERROR(MSG_CONVERSION_STRING_TOO_LONG);
1892 strftime(buf, 30,
"%F %T", &tm);
1904 localtime_r(&tt, &ts);
1947 if (us) (*((
unsigned char*) buf)) = (
unsigned char) v;
1948 else (*((
char*)
buf)) = (char) v;
1951 if (us) (*((
unsigned short int*) buf)) = (
unsigned short int) v;
1952 else (*((
short int*)
buf)) = (
short int) v;
1955 if (us) (*((
unsigned int*) buf)) = (
unsigned int) v;
1956 else (*((
int*)
buf)) = (int) v;
1959 if (us) (*((
unsigned int*) buf)) = (
unsigned int) v;
1960 else (*((
int*)
buf)) = (int) v;
1963 if (us) (*((
unsigned long long int*) buf)) = (
unsigned long long int) v;
1964 else (*((
long long int*)
buf)) = (
long long int) v;
1967 (*((
float*) buf)) = v;
break;
1969 (*((
double*) buf)) = v;
break;
1976 throw MCS_ERROR(MSG_CONVERSION_INT_BLOB);
break;
1978 throw MCS_ERROR(MSG_CONVERSION_INT_BLOB);
break;
1980 throw MCS_ERROR(MSG_CONVERSION_INT_BLOB);
break;
1982 time_t tt = (time_t) v;
1988 MCS_DEBUG(
"-> " <<
sval());
2003 if (us) (*((
unsigned char*) buf)) = (
unsigned char) v;
2004 else (*((
char*)
buf)) = (char) v;
2007 if (us) (*((
unsigned short int*) buf)) = (
unsigned short int) v;
2008 else (*((
short int*)
buf)) = (
short int) v;
2011 if (us) (*((
unsigned int*) buf)) = (
unsigned int) v;
2012 else (*((
int*)
buf)) = (int) v;
2015 if (us) (*((
unsigned int*) buf)) = (
unsigned int) v;
2016 else (*((
int*)
buf)) = (int) v;
2019 if (us) (*((
unsigned long long int*) buf)) = (
unsigned long long int) v;
2020 else (*((
long long int*)
buf)) = (
long long int) v;
2023 (*((
float*) buf)) = v;
break;
2025 (*((
double*) buf)) = v;
break;
2032 throw MCS_ERROR(MSG_CONVERSION_INT_BLOB);
break;
2034 throw MCS_ERROR(MSG_CONVERSION_INT_BLOB);
break;
2036 throw MCS_ERROR(MSG_CONVERSION_INT_BLOB);
break;
2038 time_t tt = (time_t) v;
2044 MCS_DEBUG(
"-> " <<
sval());
2061 if (us) (*((
unsigned char*) buf)) = (
unsigned char) nearbyint(v);
2062 else (*((
char*) buf)) = (char) nearbyint(v);
2065 if (us) (*((
unsigned short int*) buf)) = (
unsigned short int) nearbyint(v);
2066 else (*((
short int*) buf)) = (
short int) nearbyint(v);
2069 if (us) (*((
unsigned int*) buf)) = (
unsigned int) nearbyint(v);
2070 else (*((
int*) buf)) = (int) nearbyint(v);
2073 if (us) (*((
unsigned int*) buf)) = (
unsigned int) nearbyint(v);
2074 else (*((
int*) buf)) = (int) nearbyint(v);
2077 if (us) (*((
unsigned long long int*) buf)) = (
unsigned long long int) nearbyint(v);
2078 else (*((
long long int*) buf)) = (
long long int) nearbyint(v);
2081 (*((
float*) buf)) = v;
break;
2083 (*((
double*) buf)) = v;
break;
2090 throw MCS_ERROR(MSG_CONVERSION_FLOAT_BLOB);
break;
2092 throw MCS_ERROR(MSG_CONVERSION_FLOAT_BLOB);
break;
2094 throw MCS_ERROR(MSG_CONVERSION_FLOAT_BLOB);
break;
2096 time_t tt = (time_t) nearbyint(v);
2102 MCS_DEBUG(
"-> " <<
sval());
2109 MCS_DEBUG(
"-> " <<
sval());
2122 if (us) ret=sscanf(v.c_str(),
"%hhd", ((
unsigned char*) buf));
2123 else ret=sscanf(v.c_str(),
"%hhd", ((
char*) buf));
2126 if (us) ret=sscanf(v.c_str(),
"%hd" , ((
unsigned short int*) buf));
2127 else ret=sscanf(v.c_str(),
"%hd" , ((
short int*) buf));
2130 if (us) ret=sscanf(v.c_str(),
"%d" , ((
unsigned int*) buf));
2131 else ret=sscanf(v.c_str(),
"%d" , ((
int*) buf));
2134 if (us) ret=sscanf(v.c_str(),
"%d" , ((
unsigned int*) buf));
2135 else ret=sscanf(v.c_str(),
"%d" , ((
int*) buf));
2138 if (us) ret=sscanf(v.c_str(),
"%lld", ((
unsigned long long int*) buf));
2139 else ret=sscanf(v.c_str(),
"%lld", ((
long long int*) buf));
2142 ret=sscanf(v.c_str(),
"%f" , ((
float*) buf));
break;
2144 ret=sscanf(v.c_str(),
"%lf", ((
double*) buf));
break;
2163 throw MCS_ERROR(MSG_CONVERSION_STRING_TOO_LONG);
2167 memcpy(buf, v.c_str(),
llength);
2171 throw MCS_ERROR(MSG_CONVERSION_STRING_BLOB);
break;
2173 throw MCS_ERROR(MSG_CONVERSION_STRING_BLOB);
break;
2175 throw MCS_ERROR(MSG_CONVERSION_STRING_BLOB);
break;
2178 if (ret!=-1000 && ret!=1)
2181 MCS_DEBUG(
"-> " <<
sval());
2197 memcpy(buf, lbuf, size);
2222 return (
long long int) (-1 * (pow(2.0, nbit) / 2));
2244 return (
long long int) (pow(2.0, nbit) - 1);
2246 return (
long long int) ((pow(2.0, nbit) / 2) - 1);
2308 unsigned int size = 1;
2312 size +=
sizeof(
unsigned short int);
2314 size +=
sizeof(
tag);
2315 size +=
lname.length()+1;
2319 size +=
sizeof(MCS_TIME);
2332 unsigned char tmp_mix = 0;
2334 tmp_mix += (
unsigned char)
ltype;
2346 abuf(
sizeof(tmp_mix)) << &tmp_mix;
2351 unsigned short int dim;
2354 abuf(
sizeof(dim)) << &
dim;
2361 unsigned short int tmp_llength =
llength;
2362 abuf(
sizeof(tmp_llength)) << &tmp_llength;
2365 abuf(
sizeof(
tag)) << &
tag;
2384 char* ll = this->
buf;
2385 for (
unsigned int i=0; i<
arrsize; i++) {
2391 abuf(
sizeof(time_t)) << &t;
2411 char* lbuf = (
char*) llbuf;
2413 unsigned char tmp_mix;
2414 memcpy(&tmp_mix, lbuf,
sizeof(tmp_mix));
2415 lbuf +=
sizeof(tmp_mix);
2419 bool lisnull = (bool) (tmp_mix & 32);
2421 bool hasDimSpec = ((bool) (tmp_mix & 128));
2422 string dimspec =
"";
2428 for (
unsigned int i=0; i<MCS_DATA_NDIM; i++) {
2430 memcpy(&(
ldim[i]), lbuf,
sizeof(
unsigned short int));
2431 lbuf +=
sizeof(
unsigned short int);
2442 unsigned short int tmp_llength = 0;
2447 memcpy(&tmp_llength, lbuf,
sizeof(tmp_llength));
2448 lbuf +=
sizeof(tmp_llength);
2453 unsigned char tmp_ltag;
2454 memcpy(&tmp_ltag , lbuf,
sizeof(
tag) ); lbuf +=
sizeof(tmp_ltag) ;
2456 string tmp_lname = string(lbuf);
2457 lbuf += tmp_lname.length()+1;
2461 (
char*) tmp_lname.c_str(),
2483 char* ll = this->
buf;
2485 for (
unsigned int i=0; i<
arrsize; i++) {
2486 memcpy(&t, lbuf,
sizeof(time_t));
2487 lbuf +=
sizeof(size_t);
2511 else if (size < 65536)
2512 init(NULL,
BLOB,
"", size,
false, 0);
2514 throw MCS_ERROR(MSG_BLOB_TOO_BIG, size);
2526 s = string(
"N=") +
name() +
2535 for (i=0; i<
length(); i++)
2536 s +=
itos(p[i]) + string(
" ");
2555 int mcs::Data::getSourceID()
2560 void mcs::Data::setSourceID(
int id)
2565 int mcs::Data::getDestID()
2570 void mcs::Data::setDestID(
int id)
unsigned char tag
Tag for user convenience.
string print()
Returns a string representation of the object, for debug purpose.
string itos(int i)
Convert an integer to a string.
Data & operator=(const int v)
Wrapper assignment operator to setival(int).
void settimenow()
Convert current time value to base type and store in internal buffer.
Types type()
Return the base type of the object.
TimeMode
Enumerate operational mode for a DateTime object.
unsigned long long int ulval() const
Convert internal data to an unsigned long long integer value.
Serialize memory buffers or files into chunks.
bool Types2FITS(Types dbt, bool isunsigned, int &fits)
Convert a MCS type into a FITSIO type.
bool isAutoIncrement()
Tells if the database field is an auto increment field.
bool lautoincr
If the AUTO_INCREMENT flag is true.
bool IntType(Types type)
Tell if "type" is an integer type.
unsigned int size()
Return size of the buffer.
static const char * tmfmt
Format to handle time in sprintf/sscanf calls.
string sval(bool addWhiteSpaces=false) const
Convert internal data to a string object.
static const char * dfmt
Format to handle double float in sprintf/sscanf calls.
Data()
Build Data object of base type STRING and length zero.
unsigned short int dim(int d)
Return length of a dimension.
unsigned int arrpos
Last selected array cell.
void setTag(unsigned char tag)
Set a new value to internal tag.
struct tm tmval() const
Retrieve a struct tm object.
unsigned short int ldim[15]
Size of each dimension.
unsigned int arrsize
Array size, i.e. how many cells are in the array.
unsigned long llength
Actual length of real data in the buffer, useful only when the base type is a variable length type...
Data & operator()(const int i1=0, const int i2=0, const int i3=0, const int i4=0, const int i5=0, const int i6=0, const int i7=0, const int i8=0, const int i9=0, const int i10=0, const int i11=0, const int i12=0, const int i13=0, const int i14=0, const int i15=0)
Same as array().
void setNull(bool null=true)
Set null flag. Following call to isNull() returns the value used here as parameter.
string name()
Return the name of the object.
void init(MYSQL_BIND *bind, Types type, const char *name="", unsigned short int maxLength=0, bool isunsigned=false, unsigned int flags=0)
Initialize internal structures.
string MYSQL2Str(enum_field_types type)
Return the name of the MySQL type given in "type".
void settmval(struct tm <m)
Assign a struct tm value.
static void parseTime(string s, struct tm *ts)
Fills the "struct tm*" passed as argument with the current local datetime.
unsigned char ldimspec
Multi-dimensional array specification.
void setsval(string v)
Convert string value to base type and store in internal buffer.
void settval(time_t t)
Assign a time_t value.
void setMysqlBuffer(MYSQL_TIME *mysql)
Set a pointer to a MYSQL_TIME structure.
void setsval(string s)
Parse a string to extract a datetime value.
~Data()
Destructor Frees internal buffer.
void setulval(unsigned long long int v)
Convert unsigned long int value to base type and store in internal buffer.
#define MCS_ERROR(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
void setcval(const char *v)
Convert string value to base type and store in internal buffer.
char * from
Pointer to source buffer, if type = MCS_SERIAL_BUFFER.
int cval(char *c, int maxlength) const
Convert internal data to a NULL terminated string and store it in a buffer.
string Types2Str(Types type, bool isunsigned)
Return the name of the type given in "type" and "isunsigned".
unsigned int varyingDim()
Return the index of the dimension that may vary.
bool isUnsigned()
Tell if the object contains unsigned integers.
static const char * dtfmt
Format to handle datetime in sprintf/sscanf calls.
string Types2MYSQLStr(Types &type, bool isunsigned)
Convert a MCS type into a MySQL type.
bool isNull()
Tells if no value is stored.
unsigned char getTag()
Retrieve the value of the tag.
bool FloatType(Types type)
Tell if "type" is a float type.
unsigned int size()
If knowSize() is true, return the size of the entire block of data.
time_t tval() const
Retrieve a time_t value.
bool serialize_buffer(char *&from, unsigned int &size)
Prepare a buffer with all informations contained in the object.
int stoi(string s)
Convert a string to an integer.
double dval() const
Convert internal data to a double (8 bytes) floating point value.
bool Types2S_FITS(Types dbt, int len, bool isunsigned, string &fits)
Convert a MCS type into a FITSIO type code.
void setival(int v)
Convert int value to base type and store in internal buffer.
unsigned int howManyDim()
Return how many dimensions are in the array.
static const char * parseTime(const char *s, struct tm *tm)
Parse a string to extract datetime information.
unsigned int uival() const
Convert internal data to an unsigned integer value.
static const char * lfmt
Format to handle long integers in sprintf/sscanf calls.
vector< string > split(string s, string sep=" ")
Split a string into tokens.
unsigned int arraySize()
Return size of array.
Main include file for all MCS based applications.
void emptyName()
Set the object name to an empty string.
static const char * ifmt
Format to handle integers in sprintf/sscanf calls.
unsigned short int lmaxlength
Max number of bytes that can be stored in the buffer (size of the buffer).
void resizeVaryingDim(unsigned short int newsize)
Resize variable length dimension.
static long long int MinValue(Types ltype, bool flunsigned)
Return the minimum integer value for the base type specified.
bool VarLenType(Types type)
Tell if "type" is a variable length type.
long long int lval() const
Convert internal data to a long long integer value.
void settimeval(struct tm v)
Convert "struct tm" value to base type and store in internal buffer.
void now()
Set the current datetime value.
void setlval(long long int v)
Convert long int value to base type and store in internal buffer.
void setTimeMode(enum TimeMode tm)
Set operational time mode.
A general purpose data type.
time_t getTime() const
Return stored time.
float fval() const
Convert internal data to a floating point value.
bool MYSQL2Types(enum_field_types mtype, Types &type)
Convert a MySQL type into a MCS type.
unsigned short int length()
Return the actual length of the data in the internal buffer.
Types ltype
Object base type.
int id_source
The userid of the thread who send this object.
void setdval(double v)
Convert double value to base type and store in internal buffer.
void setuival(unsigned int v)
Convert unsigned int value to base type and store in internal buffer.
void to_MYSQL_TIME()
Update linked MYSQL_TIME structure (if any) with internal value.
string sval() const
Retrieve a string representation of the datetime value.
time_t tval() const
Convert internal data to a time_t value.
string trim(string s)
Remove any leading or trailing blanks.
bool FITS2Types(int fits, Types &dbt, bool &isunsigned)
Convert a FITSIO type into a MCS type.
string hexDump(const void *buf, unsigned int size)
Return a string with an hex dump of the buffer pointed by "buf", with a length of "size"...
void * buffer() const
Return a pointer to the internal buffer, use this at your own risk.
unsigned int lflags
Flags (EXPERIMENTAL).
int ival() const
Convert internal data to a integer value.
unsigned int array(unsigned short int i1=0, unsigned short int i2=0, unsigned short int i3=0, unsigned short int i4=0, unsigned short int i5=0, unsigned short int i6=0, unsigned short int i7=0, unsigned short int i8=0, unsigned short int i9=0, unsigned short int i10=0, unsigned short int i11=0, unsigned short int i12=0, unsigned short int i13=0, unsigned short int i14=0, unsigned short int i15=0)
Select a cell from the array.
unsigned short int maxLength()
Return the size of the internal buffer.
void setblob(void *lbuf, unsigned int size)
Copy "size" bytes from the address given in "lbuf" parameter.
static const char * ffmt
Format to handle float in sprintf/sscanf calls.
my_bool lisnull
The object has a null value.
bool Types2MYSQL(Types &type, enum_field_types &mtype)
Convert a MCS type into a MySQL type.
static long long int MaxValue(Types ltype, bool flunsigned)
Return the maximum integer value for the base type specified.
bool lisunsigned
Base type is unsigned.
static const char * dafmt
Format to handle date in sprintf/sscanf calls.
void resize(string dimSpec)
Create or resize a multi-dimensional array.
unsigned int objSize()
Return how many bytes require the object to be serialized.
Namespace for MCS library.
Types
Enumeration of base type for Data.
int id_dest
The userid of the thread that will receive this object.