Discussion:
[soci-users] SQLite3 + double + use(id) = bad_cast
Rodrigo Madera
2014-01-29 17:58:24 UTC
Permalink
TLDR: Using sqlite3 backend, when using soci::use(some_id) the query throws
bad_cast when reaching get<double>().

--------------------------------------------------------

Hello there.

I'm having a bit of a pickle with a very curious error. I'm using sqlite3.

I'm aware of SOCI's limitations on integer conversion, but this rather
strange execution difference induced by a soci::use() statement is puzzling.

If I read a double from table Person:

boost::fusion::vector<int, double> db_tuple;
session << "select id, height from person where id=:1",
soci::into(db_tuple);

All is well and fine.

But if I try to read the height from a specific user using its id, then I
get a bad_cast blown to my face:

int id = 1;
boost::fusion::vector<int, double> db_tuple;
session << "select id, height from person where id=:id",
soci::use(id), soci::into(db_tuple);
}

So basically, if I want a specific ID, the conversion fails at
soci::details::holder::get<T>, which we all know and love, with T=double.

Thanks for any insight on why I can't use my specific ID!!

Rodrigo
Rodrigo Madera
2014-01-29 18:15:48 UTC
Permalink
Complementing:

While debugging I found out that the value is converted to string.

So it looks like: not using id? --> double. Using an id with soci::use(id)?
--> std::string.

Anyone knows why this is happening?

Thanks,
Rodrigo
Post by Rodrigo Madera
TLDR: Using sqlite3 backend, when using soci::use(some_id) the query
throws bad_cast when reaching get<double>().
--------------------------------------------------------
Hello there.
I'm having a bit of a pickle with a very curious error. I'm using sqlite3.
I'm aware of SOCI's limitations on integer conversion, but this rather
strange execution difference induced by a soci::use() statement is puzzling.
boost::fusion::vector<int, double> db_tuple;
session << "select id, height from person where id=:1",
soci::into(db_tuple);
All is well and fine.
But if I try to read the height from a specific user using its id, then I
int id = 1;
boost::fusion::vector<int, double> db_tuple;
session << "select id, height from person where id=:id",
soci::use(id), soci::into(db_tuple);
}
So basically, if I want a specific ID, the conversion fails at
soci::details::holder::get<T>, which we all know and love, with T=double.
Thanks for any insight on why I can't use my specific ID!!
Rodrigo
Loading...