Commit 1d0ffbf8 authored by msobczak's avatar msobczak

Added support for long long.

parent f430cad5
......@@ -90,6 +90,12 @@ void firebird_standard_into_type_backend::exchangeData()
*reinterpret_cast<unsigned long*>(data_) = t;
}
break;
case eXInteger:
{
long long t = from_isc<long long>(var);
*reinterpret_cast<long long *>(data_) = t;
}
break;
case eXDouble:
{
double t = from_isc<double>(var);
......
......@@ -111,6 +111,9 @@ void firebird_standard_use_type_backend::exchangeData()
case eXUnsignedLong:
to_isc<unsigned long>(data_, var);
break;
case eXLongLong:
to_isc<long long>(data_, var);
break;
case eXDouble:
to_isc<double>(data_, var);
break;
......
......@@ -597,11 +597,7 @@ void firebird_statement_backend::describe_column(int colNum,
}
else
{
// 64bit integers are not supported
std::ostringstream msg;
msg << "Type of column ["<< colNum << "] \"" << columnName
<< "\" is not supported for dynamic queries";
throw soci_error(msg.str());
type = eLongLong;
}
break;
/* case SQL_BLOB:
......
......@@ -80,6 +80,12 @@ void firebird_vector_into_type_backend::exchangeData(std::size_t row)
setIntoVector(data_, row, tmp);
}
break;
case eXLongLong:
{
long long tmp = from_isc<long long>(var);
setIntoVector(data_, row, tmp);
}
break;
case eXDouble:
{
double tmp = from_isc<double>(var);
......@@ -144,6 +150,9 @@ void firebird_vector_into_type_backend::resize(std::size_t sz)
case eXUnsignedLong:
resizeVector<unsigned long>(data_, sz);
break;
case eXLongLong:
resizeVector<long long> (data_, sz);
break;
case eXDouble:
resizeVector<double> (data_, sz);
break;
......@@ -177,6 +186,9 @@ std::size_t firebird_vector_into_type_backend::size()
case eXUnsignedLong:
sz = getVectorSize<unsigned long>(data_);
break;
case eXLongLong:
sz = getVectorSize<long long> (data_);
break;
case eXDouble:
sz = getVectorSize<double> (data_);
break;
......
......@@ -137,6 +137,11 @@ void firebird_vector_use_type_backend::exchangeData(std::size_t row)
static_cast<void*>(getUseVectorValue<unsigned long>(data_, row)),
var);
break;
case eXLongLong:
to_isc<long long>(
static_cast<void*>(getUseVectorValue<long long>(data_, row)),
var);
break;
case eXDouble:
to_isc<double>(
static_cast<void*>(getUseVectorValue<double>(data_, row)),
......@@ -180,6 +185,9 @@ std::size_t firebird_vector_use_type_backend::size()
case eXUnsignedLong:
sz = getVectorSize<unsigned long>(data_);
break;
case eXLongLong:
sz = getVectorSize<long long> (data_);
break;
case eXDouble:
sz = getVectorSize<double> (data_);
break;
......
......@@ -117,6 +117,12 @@ void mysql_standard_into_type_backend::post_fetch(
*dest = static_cast<unsigned long>(val);
}
break;
case eXLongLong:
{
long long *dest = static_cast<long long *>(data_);
*dest = strtoll(buf, NULL, 10);
}
break;
case eXDouble:
{
double *dest = static_cast<double*>(data_);
......
......@@ -97,6 +97,14 @@ void mysql_standard_use_type_backend::pre_use(eIndicator const *ind)
*static_cast<unsigned long*>(data_));
}
break;
case eXLongLong:
{
std::size_t const bufSize
= std::numeric_limits<long long>::digits10 + 3;
buf_ = new char[bufSize];
snprintf(buf_, bufSize, "%lld", *static_cast<long long *>(data_));
}
break;
case eXDouble:
{
// no need to overengineer it (KISS)...
......
......@@ -360,10 +360,12 @@ void mysql_statement_backend::describe_column(int colNum,
case FIELD_TYPE_CHAR: //MYSQL_TYPE_TINY:
case FIELD_TYPE_SHORT: //MYSQL_TYPE_SHORT:
case FIELD_TYPE_LONG: //MYSQL_TYPE_LONG:
case FIELD_TYPE_LONGLONG: //MYSQL_TYPE_LONGLONG:
case FIELD_TYPE_INT24: //MYSQL_TYPE_INT24:
type = eInteger;
break;
case FIELD_TYPE_LONGLONG: //MYSQL_TYPE_LONGLONG:
type = eLongLong;
break;
case FIELD_TYPE_FLOAT: //MYSQL_TYPE_FLOAT:
case FIELD_TYPE_DOUBLE: //MYSQL_TYPE_DOUBLE:
case FIELD_TYPE_DECIMAL: //MYSQL_TYPE_DECIMAL:
......
......@@ -37,8 +37,8 @@ void mysql_vector_into_type_backend::pre_fetch()
namespace // anonymous
{
template <typename T, typename U>
void set_invector_(void *p, int indx, U const &val)
template <typename T>
void set_invector_(void *p, int indx, T const &val)
{
std::vector<T> *dest =
static_cast<std::vector<T> *>(p);
......@@ -91,7 +91,7 @@ void mysql_vector_into_type_backend::post_fetch(bool gotData, eIndicator *ind)
switch (type_)
{
case eXChar:
set_invector_<char>(data_, i, *buf);
set_invector_(data_, i, *buf);
break;
case eXStdString:
set_invector_<std::string>(data_, i, buf);
......@@ -99,26 +99,31 @@ void mysql_vector_into_type_backend::post_fetch(bool gotData, eIndicator *ind)
case eXShort:
{
long val = strtol(buf, NULL, 10);
set_invector_<short>(data_, i, static_cast<short>(val));
set_invector_(data_, i, static_cast<short>(val));
}
break;
case eXInteger:
{
long val = strtol(buf, NULL, 10);
set_invector_<int>(data_, i, static_cast<int>(val));
set_invector_(data_, i, static_cast<int>(val));
}
break;
case eXUnsignedLong:
{
long long val = strtoll(buf, NULL, 10);
set_invector_<unsigned long>(data_, i,
static_cast<unsigned long>(val));
set_invector_(data_, i, static_cast<unsigned long>(val));
}
break;
case eXLongLong:
{
long long val = strtoll(buf, NULL, 10);
set_invector_(data_, i, val);
}
break;
case eXDouble:
{
double val = strtod(buf, NULL);
set_invector_<double>(data_, i, val);
set_invector_(data_, i, val);
}
break;
case eXStdTm:
......@@ -127,7 +132,7 @@ void mysql_vector_into_type_backend::post_fetch(bool gotData, eIndicator *ind)
std::tm t;
parse_std_tm(buf, t);
set_invector_<std::tm>(data_, i, t);
set_invector_(data_, i, t);
}
break;
......@@ -163,6 +168,7 @@ void mysql_vector_into_type_backend::resize(std::size_t sz)
case eXShort: resizevector_<short> (data_, sz); break;
case eXInteger: resizevector_<int> (data_, sz); break;
case eXUnsignedLong: resizevector_<unsigned long>(data_, sz); break;
case eXLongLong: resizevector_<long long> (data_, sz); break;
case eXDouble: resizevector_<double> (data_, sz); break;
case eXStdString: resizevector_<std::string> (data_, sz); break;
case eXStdTm: resizevector_<std::tm> (data_, sz); break;
......@@ -182,6 +188,7 @@ std::size_t mysql_vector_into_type_backend::size()
case eXShort: sz = get_vector_size<short> (data_); break;
case eXInteger: sz = get_vector_size<int> (data_); break;
case eXUnsignedLong: sz = get_vector_size<unsigned long>(data_); break;
case eXLongLong: sz = get_vector_size<long long> (data_); break;
case eXDouble: sz = get_vector_size<double> (data_); break;
case eXStdString: sz = get_vector_size<std::string> (data_); break;
case eXStdTm: sz = get_vector_size<std::tm> (data_); break;
......
......@@ -112,6 +112,18 @@ void mysql_vector_use_type_backend::pre_use(eIndicator const *ind)
snprintf(buf, bufSize, "%lu", v[i]);
}
break;
case eXInteger:
{
std::vector<long long> *pv
= static_cast<std::vector<long long> *>(data_);
std::vector<long long> &v = *pv;
std::size_t const bufSize
= std::numeric_limits<long long>::digits10 + 3;
buf = new char[bufSize];
snprintf(buf, bufSize, "%lld", v[i]);
}
break;
case eXDouble:
{
// no need to overengineer it (KISS)...
......@@ -172,6 +184,7 @@ std::size_t mysql_vector_use_type_backend::size()
case eXShort: sz = get_vector_size<short> (data_); break;
case eXInteger: sz = get_vector_size<int> (data_); break;
case eXUnsignedLong: sz = get_vector_size<unsigned long>(data_); break;
case eXLongLong: sz = get_vector_size<long long> (data_); break;
case eXDouble: sz = get_vector_size<double> (data_); break;
case eXStdString: sz = get_vector_size<std::string> (data_); break;
case eXStdTm: sz = get_vector_size<std::tm> (data_); break;
......
......@@ -132,11 +132,16 @@ void postgresql_standard_into_type_backend::post_fetch(
*dest = static_cast<unsigned long>(val);
}
break;
case eXLongLong:
{
long long *dest = static_cast<long long *>(data_);
*dest = strtoll(buf, NULL, 10);
}
break;
case eXDouble:
{
double *dest = static_cast<double*>(data_);
double val = strtod(buf, NULL);
*dest = static_cast<double>(val);
*dest = strtod(buf, NULL);
}
break;
case eXStdTm:
......
......@@ -115,6 +115,15 @@ void postgresql_standard_use_type_backend::pre_use(eIndicator const *ind)
*static_cast<unsigned long*>(data_));
}
break;
case eXLongLong:
{
std::size_t const bufSize
= std::numeric_limits<long long>::digits10 + 3;
buf_ = new char[bufSize];
snprintf(buf_, bufSize, "%lld",
*static_cast<long long *>(data_));
}
break;
case eXDouble:
{
// no need to overengineer it (KISS)...
......
......@@ -470,10 +470,13 @@ void postgresql_statement_backend::describe_column(int colNum, eDataType &type,
case 16: // bool
case 21: // int2
case 23: // int4
case 20: // int8
type = eInteger;
break;
case 20: // int8
type = eLongLong;
break;
case 26: // oid
type = eUnsignedLong;
break;
......
......@@ -190,6 +190,7 @@ struct blob_table_creator : public table_creator_base
}
};
// long long test
void test3()
{
{
......@@ -233,6 +234,36 @@ void test3()
std::cout << "test 3 passed" << std::endl;
}
struct longlong_table_creator : table_creator_base
{
longlong_table_creator(session & sql)
: table_creator_base(sql)
{
sql << "create table soci_test(val int8)";
}
};
void test4()
{
{
session sql(backEnd, connectString);
longlong_table_creator tableCreator(sql);
long long v1 = 1000000000000LL;
assert(v1 / 1000000 == 1000000);
sql << "insert into soci_test(val) values(:val)", use(v1);
long long v2 = 0LL;
sql << "select val from soci_test", into(v2);
assert(v2 == v1);
}
std::cout << "test 4 passed" << std::endl;
}
// DDL Creation objects for common tests
struct table_creator_one : public table_creator_base
{
......@@ -336,6 +367,7 @@ int main(int argc, char** argv)
test1();
test2();
test3();
test4();
std::cout << "\nOK, all tests passed.\n\n";
return EXIT_SUCCESS;
......
......@@ -45,8 +45,8 @@ void postgresql_vector_into_type_backend::pre_fetch()
namespace // anonymous
{
template <typename T, typename U>
void set_invector_(void *p, int indx, U const &val)
template <typename T>
void set_invector_(void *p, int indx, T const &val)
{
std::vector<T> *dest =
static_cast<std::vector<T> *>(p);
......@@ -97,7 +97,7 @@ void postgresql_vector_into_type_backend::post_fetch(bool gotData, eIndicator *i
switch (type_)
{
case eXChar:
set_invector_<char>(data_, i, *buf);
set_invector_(data_, i, *buf);
break;
case eXStdString:
set_invector_<std::string>(data_, i, buf);
......@@ -105,26 +105,31 @@ void postgresql_vector_into_type_backend::post_fetch(bool gotData, eIndicator *i
case eXShort:
{
long val = strtol(buf, NULL, 10);
set_invector_<short>(data_, i, static_cast<short>(val));
set_invector_(data_, i, static_cast<short>(val));
}
break;
case eXInteger:
{
long val = strtol(buf, NULL, 10);
set_invector_<int>(data_, i, static_cast<int>(val));
set_invector_(data_, i, static_cast<int>(val));
}
break;
case eXUnsignedLong:
{
long long val = strtoll(buf, NULL, 10);
set_invector_<unsigned long>(data_, i,
static_cast<unsigned long>(val));
set_invector_(data_, i, static_cast<unsigned long>(val));
}
break;
case eXLongLong:
{
long long val = strtoll(buf, NULL, 10);
set_invector_(data_, i, val);
}
break;
case eXDouble:
{
double val = strtod(buf, NULL);
set_invector_<double>(data_, i, val);
set_invector_(data_, i, val);
}
break;
case eXStdTm:
......@@ -133,7 +138,7 @@ void postgresql_vector_into_type_backend::post_fetch(bool gotData, eIndicator *i
std::tm t;
parse_std_tm(buf, t);
set_invector_<std::tm>(data_, i, t);
set_invector_(data_, i, t);
}
break;
......@@ -169,6 +174,7 @@ void postgresql_vector_into_type_backend::resize(std::size_t sz)
case eXShort: resizevector_<short> (data_, sz); break;
case eXInteger: resizevector_<int> (data_, sz); break;
case eXUnsignedLong: resizevector_<unsigned long>(data_, sz); break;
case eXLongLong: resizevector_<long long> (data_, sz); break;
case eXDouble: resizevector_<double> (data_, sz); break;
case eXStdString: resizevector_<std::string> (data_, sz); break;
case eXStdTm: resizevector_<std::tm> (data_, sz); break;
......@@ -188,6 +194,7 @@ std::size_t postgresql_vector_into_type_backend::size()
case eXShort: sz = get_vector_size<short> (data_); break;
case eXInteger: sz = get_vector_size<int> (data_); break;
case eXUnsignedLong: sz = get_vector_size<unsigned long>(data_); break;
case eXLongLong: sz = get_vector_size<long long> (data_); break;
case eXDouble: sz = get_vector_size<double> (data_); break;
case eXStdString: sz = get_vector_size<std::string> (data_); break;
case eXStdTm: sz = get_vector_size<std::tm> (data_); break;
......
......@@ -122,6 +122,18 @@ void postgresql_vector_use_type_backend::pre_use(eIndicator const *ind)
snprintf(buf, bufSize, "%lu", v[i]);
}
break;
case eXLongLong:
{
std::vector<long long> *pv
= static_cast<std::vector<long long> *>(data_);
std::vector<long long> &v = *pv;
std::size_t const bufSize
= std::numeric_limits<long long>::digits10 + 3;
buf = new char[bufSize];
snprintf(buf, bufSize, "%lld", v[i]);
}
break;
case eXDouble:
{
// no need to overengineer it (KISS)...
......@@ -182,6 +194,7 @@ std::size_t postgresql_vector_use_type_backend::size()
case eXShort: sz = get_vector_size<short> (data_); break;
case eXInteger: sz = get_vector_size<int> (data_); break;
case eXUnsignedLong: sz = get_vector_size<unsigned long>(data_); break;
case eXLongLong: sz = get_vector_size<long long> (data_); break;
case eXDouble: sz = get_vector_size<double> (data_); break;
case eXStdString: sz = get_vector_size<std::string> (data_); break;
case eXStdTm: sz = get_vector_size<std::tm> (data_); break;
......
......@@ -126,6 +126,12 @@ void sqlite3_standard_into_type_backend::post_fetch(bool gotData,
*dest = static_cast<unsigned long>(val);
}
break;
case eXLongLong:
{
long long *dest = static_cast<long long *>(data_);
*desc = strtoll(buf, NULL, 10);
}
break;
case eXDouble:
{
double *dest = static_cast<double*>(data_);
......
......@@ -131,6 +131,15 @@ void sqlite3_standard_use_type_backend::pre_use(eIndicator const * ind)
*static_cast<unsigned long*>(data_));
}
break;
case eXLongLong:
{
std::size_t const bufSize
= std::numeric_limits<long long>::digits10 + 3;
buf_ = new char[bufSize];
snprintf(buf_, bufSize, "%lld",
*static_cast<long long *>(data_));
}
break;
case eXDouble:
{
// no need to overengineer it (KISS)...
......
......@@ -36,8 +36,8 @@ void sqlite3_vector_into_type_backend::pre_fetch()
namespace // anonymous
{
template <typename T, typename U>
void setInVector(void *p, int indx, U const &val)
template <typename T>
void setInVector(void *p, int indx, T const &val)
{
std::vector<T> *dest =
static_cast<std::vector<T> *>(p);
......@@ -88,7 +88,7 @@ void sqlite3_vector_into_type_backend::post_fetch(bool gotData, eIndicator * ind
switch (type_)
{
case eXChar:
setInVector<char>(data_, i, *buf);
setInVector(data_, i, *buf);
break;
case eXStdString:
setInVector<std::string>(data_, i, buf);
......@@ -96,26 +96,31 @@ void sqlite3_vector_into_type_backend::post_fetch(bool gotData, eIndicator * ind
case eXShort:
{
long val = strtol(buf, NULL, 10);
setInVector<short>(data_, i, static_cast<short>(val));
setInVector(data_, i, static_cast<short>(val));
}
break;
case eXInteger:
{
long val = strtol(buf, NULL, 10);
setInVector<int>(data_, i, static_cast<int>(val));
setInVector(data_, i, static_cast<int>(val));
}
break;
case eXUnsignedLong:
{
long long val = strtoll(buf, NULL, 10);
setInVector<unsigned long>(data_, i,
static_cast<unsigned long>(val));
setInVector(data_, i, static_cast<unsigned long>(val));
}
break;
case eXLongLong:
{
long long val = strtoll(buf, NULL, 10);
setInVector(data_, i, val);
}
break;
case eXDouble:
{
double val = strtod(buf, NULL);
setInVector<double>(data_, i, val);
setInVector(data_, i, val);
}
break;
case eXStdTm:
......@@ -124,7 +129,7 @@ void sqlite3_vector_into_type_backend::post_fetch(bool gotData, eIndicator * ind
std::tm t;
parseStdTm(buf, t);
setInVector<std::tm>(data_, i, t);
setInVector(data_, i, t);
}
break;
......@@ -148,6 +153,7 @@ void sqlite3_vector_into_type_backend::resize(std::size_t sz)
case eXShort: resizeVector<short> (data_, sz); break;
case eXInteger: resizeVector<int> (data_, sz); break;
case eXUnsignedLong: resizeVector<unsigned long>(data_, sz); break;
case eXLongLong: resizeVector<long long> (data_, sz); break;
case eXDouble: resizeVector<double> (data_, sz); break;
case eXStdString: resizeVector<std::string> (data_, sz); break;
case eXStdTm: resizeVector<std::tm> (data_, sz); break;
......@@ -167,6 +173,7 @@ std::size_t sqlite3_vector_into_type_backend::size()
case eXShort: sz = getVectorSize<short> (data_); break;
case eXInteger: sz = getVectorSize<int> (data_); break;
case eXUnsignedLong: sz = getVectorSize<unsigned long>(data_); break;
case eXLongLong: sz = getVectorSize<long long> (data_); break;
case eXDouble: sz = getVectorSize<double> (data_); break;
case eXStdString: sz = getVectorSize<std::string> (data_); break;
case eXStdTm: sz = getVectorSize<std::tm> (data_); break;
......
......@@ -152,6 +152,18 @@ void sqlite3_vector_use_type_backend::pre_use(eIndicator const * ind)
snprintf(buf, bufSize, "%lu", v[i]);
}
break;
case eXLongLong:
{
std::vector<long long> *pv
= static_cast<std::vector<long long> *>(data_);
std::vector<long long> &v = *pv;
std::size_t const bufSize
= std::numeric_limits<long long>::digits10 + 3;
buf = new char[bufSize];
snprintf(buf, bufSize, "%lld", v[i]);
}
break;
case eXDouble:
{
// no need to overengineer it (KISS)...
......@@ -206,6 +218,7 @@ std::size_t sqlite3_vector_use_type_backend::size()
case eXShort: sz = getVectorSize<short> (data_); break;
case eXInteger: sz = getVectorSize<int> (data_); break;
case eXUnsignedLong: sz = getVectorSize<unsigned long>(data_); break;
case eXLongLong: sz = getVectorSize<long long> (data_); break;
case eXDouble: sz = getVectorSize<double> (data_); break;
case eXStdString: sz = getVectorSize<std::string> (data_); break;
case eXStdTm: sz = getVectorSize<std::tm> (data_); break;
......
......@@ -64,6 +64,13 @@ struct exchange_traits<unsigned long>
enum { eXType = eXUnsignedLong };
};
template <>
struct exchange_traits<long long>
{
typedef basic_type_tag type_family;
enum { eXType = eXLongLong };
};
template <>
struct exchange_traits<double>
{
......
......@@ -21,7 +21,7 @@ namespace soci
// data types, as seen by the user
enum eDataType
{
eString, eChar, eDate, eDouble, eInteger, eUnsignedLong
eString, eChar, eDate, eDouble, eInteger, eUnsignedLong, eLongLong
};
// the enum type for indicator variables
......@@ -34,7 +34,7 @@ namespace details
enum eExchangeType
{
eXChar, eXCString, eXStdString, eXShort, eXInteger,
eXUnsignedLong, eXDouble, eXStdTm, eXStatement,
eXUnsignedLong, eXLongLong, eXDouble, eXStdTm, eXStatement,
eXRowID, eXBLOB
};
......
......@@ -564,6 +564,12 @@ void statement_impl::bind_into<eUnsignedLong>()
into_row<unsigned long>();
}
template<>
void statement_impl::bind_into<eLongLong>()
{
into_row<long long>();
}
template<>
void statement_impl::bind_into<eDate>()
{
......@@ -599,6 +605,9 @@ void statement_impl::describe()
case eUnsignedLong:
bind_into<eUnsignedLong>();
break;
case eLongLong:
bind_into<eLongLong>();
break;
case eDate:
bind_into<eDate>();
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment