30 int type = var->sqltype & ~1;
31 if (type == SQL_VARYING)
33 size = var->sqllen +
sizeof(short);
35 else if (type == SQL_TIMESTAMP || type == SQL_TYPE_TIME
36 || type == SQL_TYPE_DATE)
38 size =
sizeof(std::tm);
45 return new char[size];
48 void tmEncode(
short type, std::tm * src,
void * dst)
55 isc_encode_timestamp(src, static_cast<ISC_TIMESTAMP*>(dst));
58 isc_encode_sql_time(src, static_cast<ISC_TIME*>(dst));
61 isc_encode_sql_date(src, static_cast<ISC_DATE*>(dst));
64 std::ostringstream msg;
65 msg <<
"Unexpected type of date/time field (" << type <<
")";
70 void tmDecode(
short type,
void * src, std::tm * dst)
75 isc_decode_timestamp(static_cast<ISC_TIMESTAMP*>(src), dst);
78 isc_decode_sql_time(static_cast<ISC_TIME*>(src), dst);
81 isc_decode_sql_date(static_cast<ISC_DATE*>(src), dst);
84 std::ostringstream msg;
85 msg <<
"Unexpected type of date/time field (" << type <<
")";
95 if (size < static_cast<std::size_t>(var->sqllen))
97 sz =
static_cast<short>(size);
104 if ((var->sqltype & ~1) == SQL_VARYING)
106 std::memcpy(buf_, &sz,
sizeof(
short));
107 std::memcpy(buf_ +
sizeof(
short), s, sz);
109 else if ((var->sqltype & ~1) == SQL_TEXT)
111 std::memcpy(buf_, s, sz);
112 if (sz < var->sqllen)
114 std::memset(buf_+sz,
' ', var->sqllen - sz);
117 else if ((var->sqltype & ~1) == SQL_SHORT)
119 parse_decimal<short, unsigned short>(buf_, var, s);
121 else if ((var->sqltype & ~1) == SQL_LONG)
123 parse_decimal<int, unsigned int>(buf_, var, s);
125 else if ((var->sqltype & ~1) == SQL_INT64)
127 parse_decimal<long long, unsigned long long>(buf_, var, s);
129 else if ((var->sqltype & ~1) == SQL_TIMESTAMP
130 || (var->sqltype & ~1) == SQL_TYPE_DATE)
132 unsigned short year, month, day, hour, min, sec;
133 if (std::sscanf(s,
"%hu-%hu-%hu %hu:%hu:%hu",
134 &year, &month, &day, &hour, &min, &sec) != 6)
136 if (std::sscanf(s,
"%hu-%hu-%huT%hu:%hu:%hu",
137 &year, &month, &day, &hour, &min, &sec) != 6)
139 hour = min = sec = 0;
140 if (std::sscanf(s,
"%hu-%hu-%hu", &year, &month, &day) != 3)
142 throw soci_error(
"Could not parse timestamp value.");
147 std::memset(&t, 0,
sizeof(t));
148 t.tm_year = year - 1900;
149 t.tm_mon = month - 1;
154 std::memcpy(buf_, &t,
sizeof(t));
157 else if ((var->sqltype & ~1) == SQL_TYPE_TIME)
159 unsigned short hour, min, sec;
160 if (std::sscanf(s,
"%hu:%hu:%hu", &hour, &min, &sec) != 3)
162 throw soci_error(
"Could not parse timestamp value.");
165 std::memset(&t, 0,
sizeof(t));
169 std::memcpy(buf_, &t,
sizeof(t));
182 std::size_t offset = 0;
184 if ((var->sqltype & ~1) == SQL_VARYING)
186 size = *
reinterpret_cast<short*
>(var->sqldata);
187 offset =
sizeof(short);
189 else if ((var->sqltype & ~1) == SQL_TEXT)
193 else if ((var->sqltype & ~1) == SQL_SHORT)
195 return format_decimal<short>(var->sqldata, var->sqlscale);
197 else if ((var->sqltype & ~1) == SQL_LONG)
199 return format_decimal<int>(var->sqldata, var->sqlscale);
201 else if ((var->sqltype & ~1) == SQL_INT64)
203 return format_decimal<long long>(var->sqldata, var->sqlscale);
208 return std::string(var->sqldata + offset, size);
void tmEncode(short type, std::tm *src, void *dst)
void setTextParam(char const *s, std::size_t size, char *buf_, XSQLVAR *var)
char * allocBuffer(XSQLVAR *var)
SOCI_FIREBIRD_DECL firebird_backend_factory const firebird
void tmDecode(short type, void *src, std::tm *dst)
std::string getTextParam(XSQLVAR const *var)