but this sample works fine!:
boost::int64_t id;
std::string usertype; // (for enum type)
soci::statement st = (sql.prepare <<
"SELECT "
"id, "
"my_enum_type "
"FROM cheme1.test_table",
soci::into(id),
soci::into(usertype));
st.execute();
while (st.fetch())
std::cout << "id: " << id << "; usertype: " << usertype << std::endl;
output:
id: 302; usertype: two
id: 303; usertype: one
2012/5/4 Sergey Beloborodov <[email protected]>
> Hello, I have some problem with enum of postgres.
> Next code works fine (my_type is enum type ({'one', 'two'}) in database):
>
> std::string my_type;
> try
> {
> sql << "SELECT my_type "
> "FROM cheme1.test_table "
> "WHERE id = :id ",
> soci::into(my_type),
> soci::use(302);
> }
> catch (soci::postgresql_soci_error const& e) {
> std::cerr << "PostgreSQL error: " << e.what() << std::endl;
> }
> std::cout << my_type;
>
> output:
> one
>
> It's ok.
>
> BUT if I try next code:
>
> try
> {
> soci::rowset<soci::row> rows = (sql.prepare << "SELECT my_type FROM
> cheme1.test_table");
> for (const auto& row_item: rows) {
> (void)row_item;
> }
> }
> catch (soci::postgresql_soci_error const & e) {
> std::cerr << "PostgreSQL error: " << e.what() << std::endl;
> }
>
> OR (with type_conversion):
>
> struct info
> {
> boost::int64_t _id;
> std::string _my_type;
> };
>
> // template<> struct type_conversion<info> {...}
>
> soci::rowset<info> rows = (sql.prepare << "SELECT id, my_type FROM
> cheme1.test_table");
>
> I've an assertion:
> terminate called after throwing an instance of 'soci::soci_error'
> what(): Unknown data type.
>
> What am I doing wrong? Please help me and very thanks!
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users