8 #ifndef SOCI_FIREBIRD_COMMON_H_INCLUDED 9 #define SOCI_FIREBIRD_COMMON_H_INCLUDED 33 void tmEncode(
short type, std::tm * src,
void * dst);
35 void tmDecode(
short type,
void * src, std::tm * dst);
37 void setTextParam(
char const * s, std::size_t size,
char * buf_,
42 template <
typename IntType>
43 const char *
str2dec(
const char * s, IntType &out,
int &scale)
56 for (out = 0; *s; ++s, out = res)
68 res = res * 10 + d * sign;
86 void to_isc(
void * val, XSQLVAR * var,
int x_scale = 0)
88 T1 value = *
reinterpret_cast<T1*
>(val);
89 short scale = var->sqlscale + x_scale;
90 short type = var->sqltype & ~1;
91 long long divisor = 1, multiplier = 1;
93 if ((std::numeric_limits<T1>::is_integer ==
false) && scale >= 0 &&
94 (type == SQL_SHORT || type == SQL_LONG || type == SQL_INT64))
96 throw soci_error(
"Can't convert non-integral value to integral column type");
99 for (
int i = 0; i > scale; --i)
101 for (
int i = 0; i < scale; ++i)
108 short tmp =
static_cast<short>(value*multiplier/divisor);
109 std::memcpy(var->sqldata, &tmp,
sizeof(
short));
114 int tmp =
static_cast<int>(value*multiplier/divisor);
115 std::memcpy(var->sqldata, &tmp,
sizeof(
int));
120 long long tmp =
static_cast<long long>(value*multiplier/divisor);
121 std::memcpy(var->sqldata, &tmp,
sizeof(
long long));
126 float sql_value =
static_cast<float>(value);
127 std::memcpy(var->sqldata, &sql_value,
sizeof(
float));
132 double sql_value =
static_cast<double>(value);
133 std::memcpy(var->sqldata, &sql_value,
sizeof(
double));
137 throw soci_error(
"Incorrect data type for numeric conversion");
141 template<
typename IntType,
typename UIntType>
148 std::memcpy(val, &t1,
sizeof(t1));
149 else if (!*
str2dec(s, t2, scale))
150 std::memcpy(val, &t2,
sizeof(t2));
152 throw soci_error(
"Could not parse decimal value.");
153 to_isc<IntType>(val, var, scale);
156 template<
typename IntType>
159 IntType x = *
reinterpret_cast<const IntType *
>(sqldata);
160 std::stringstream out;
162 std::string r = out.str();
165 if (static_cast<int>(r.size()) - (x < 0) <= -sqlscale)
167 r = std::string(
size_t(x < 0),
'-') +
168 std::string(-sqlscale - (r.size() - (x < 0)) + 1,
'0') +
169 r.substr(
size_t(x < 0), std::string::npos);
171 return r.substr(0, r.size() + sqlscale) +
'.' +
172 r.substr(r.size() + sqlscale, std::string::npos);
174 return r + std::string(sqlscale,
'0');
177 template<
typename T1>
180 short scale = var->sqlscale;
185 if (std::numeric_limits<T1>::is_integer)
187 std::ostringstream msg;
188 msg <<
"Can't convert value with scale " << -scale
189 <<
" to integral type";
193 for (
int i = 0; i > scale; --i)
199 switch (var->sqltype & ~1)
202 return static_cast<T1
>(*
reinterpret_cast<short*
>(var->sqldata)/tens);
204 return static_cast<T1
>(*
reinterpret_cast<int*
>(var->sqldata)/tens);
206 return static_cast<T1
>(*
reinterpret_cast<long long*
>(var->sqldata)/tens);
208 return static_cast<T1
>(*
reinterpret_cast<float*
>(var->sqldata));
210 return static_cast<T1
>(*
reinterpret_cast<double*
>(var->sqldata));
212 throw soci_error(
"Incorrect data type for numeric conversion");
216 template <
typename T>
219 std::vector<T> *v =
static_cast<std::vector<T> *
>(p);
223 template <
typename T>
226 std::vector<T> *v =
static_cast<std::vector<T> *
>(p);
236 #endif // SOCI_FIREBIRD_COMMON_H_INCLUDED void tmEncode(short type, std::tm *src, void *dst)
void parse_decimal(void *val, XSQLVAR *var, const char *s)
void setTextParam(char const *s, std::size_t size, char *buf_, XSQLVAR *var)
const char * str2dec(const char *s, IntType &out, int &scale)
T1 from_isc(XSQLVAR *var)
std::string format_decimal(const void *sqldata, int sqlscale)
void to_isc(void *val, XSQLVAR *var, int x_scale=0)
void resizeVector(void *p, std::size_t sz)
char * allocBuffer(XSQLVAR *var)
SOCI_FIREBIRD_DECL firebird_backend_factory const firebird
void tmDecode(short type, void *src, std::tm *dst)
std::size_t getVectorSize(void *p)
std::string getTextParam(XSQLVAR const *var)