[odb-users] Prepared statements alreadys exists
meike.talbach at women-at-work.org
meike.talbach at women-at-work.org
Wed Nov 18 10:55:24 EST 2015
Dear all,
I'm trying to use ODB in a new project with a PostgreSQL database.
I basically have this code:
void test(boost::posix_time::ptime from, boost::posix_time::ptime to)
{
std::shared_ptr<odb::database> db = ...;
odb::transaction txn(db->begin());
database::HistoryQuery qryHistories(database::HistoryQuery::device == dbDevice->GetId());
qryHistories += " AND (" + (database::HistoryQuery::dateRecorded >= from) + ")";
qryHistories += " AND (" + (database::HistoryQuery::dateRecorded <= cmp) + ")";
odb::result<databse::HistoryPtr> result(db->query(query));
if(!result.empty())
result.begin().load();
}
I then call test with invalid ptimes which is expected to fail.
However my second call should succeed, but in fact fails too.
Something like this:
void testWrapper()
{
try
{
test(boost::posix_time::ptime(boost::posix_time::special_values::not_a_date_time), boost::posix_time::ptime(boost::posix_time::special_values::not_a_date_time))
}
catch(const std::exception &ex)
{
std::cout << "fail" << std::endl;
}
try
{
test(boost::posix_time::ptime(boost::gregorian::date(2015, 11, 18)), boost::posix_time::ptime(boost::gregorian::date(2015, 11, 18)));
}
catch(const std::exception &ex)
{
std::cout << "fail" << std::endl;
}
}
Postgres logs this error:
Oct 24 15:12:53 test1 postgres[52801]: [3-1] ERROR: timestamp out of range
Oct 24 15:12:53 test1 postgres[52801]: [3-2] STATEMENT: SELECT "test_history"."id", "test_history"."deviceid", "test_history"."type", "test_history"."latitude", "test_history"."longitude", "test_history"."address", "test_history"."daterecorded" FROM "test_history" WHERE "test_history"."deviceid" = $1 AND ("test_history"."daterecorded" >= $2) AND ("test_history"."daterecorded" <= $3)
Oct 24 15:12:53 test1 postgres[52801]: [4-1] ERROR: current transaction is aborted, commands ignored until end of transaction block
Oct 24 15:12:53 test1 postgres[52801]: [4-2] STATEMENT: deallocate "mc_test_database_History_query"
Oct 24 15:54:19 test1 postgres[52801]: [5-1] ERROR: prepared statement "mc_test_database_History_query" already exists
Oct 24 15:54:19 test1 postgres[52801]: [5-2] STATEMENT: SELECT "test_history"."id", "test_history"."deviceid", "test_history"."type", "test_history"."latitude", "test_history"."longitude", "test_history"."address", "test_history"."daterecorded" FROM "test_history" WHERE "test_history"."deviceid" = $1 ORDER BY "test_history"."daterecorded" ASC LIMIT 1
It seems that the prepared statement from the first call is not deallocated.
Then the second call tries to recreate it and fails.
Any ideas how to solve this ?
Thank you
Meike
More information about the odb-users
mailing list