Hello all,

while working with ORM mapping, which is probably one of the attraction of
SOCI for me I got bad cast error from the type_conversion, here is the code
(using sqlite3 as backend)

table:
CREATE TABLE user_card (
  user_card_idx  integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  pincode           numeric(4),
  refid              numeric(6)
);

the 'entity':
class __declspec(dllexport) UserCard
{
public:
unsigned int cardIdx;
unsigned long refid;
unsigned int pincode;
};

function call:
try
{
soci::session sql.... //create session
UserCard  c;
soci::statement st = (sql.prepare << U_CARD_SELECT_SQL, soci::into(c));
//here I add the soci::use() when needed.
st.execute();
while(st.fetch())
{
list ->push_back(UserCard(c));
}
st.clean_up();
}
catch (std::exception const & e)
{
//throw something
e.what();
}

the type_conversion:
namespace soci
{
template<> struct type_conversion<VehicleCard>
{
typedef values base_type;
static void from_base(values const & v, indicator /* ind */, UserCard & c)
{
c.cardIdx =  v.get<int>("idx");
c.refid = v.get<int>("refid");
            c.pincode = v.get<int>("pincode");
}

static void to_base(const UserCard & c, values & v, indicator & ind)
{
v.set("idx", c.cardIdx);
v.set("refid", c.refid);
v.set("pincode", c.pincode);
ind = i_ok;
}
};
}

now here it gets intresting, I try to selects
1) this works fine: SELECT user_card_idx AS idx, pincode, refid FROM
user_card
2) but, when I use: SELECT user_card_idx AS idx, pincode, refid FROM
user_card WHERE refid = :refid
   (with addition of soci::use()) I get a cast error from the type
conversion.

from debugging I can see that both 'pincode' and 'refid' columns are
mistaken for dt_string causing the type cast error.

so:
my questions are:
1) am I missing something?
2) can I somehow 'tell' the soci::statement that these column are of
dt_integer (or any other).

Thank you,
Gal
------------------------------------------------------------------------------

_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to