Hello
When I hit a stale object exception, the code can not continue from
that using the try/catch structure shown in attached file.
However, if I rearrange the code so the dbo::ptr stays in scope after
the exception is hit, then I can do a reread() on the dbo::ptr and the
code can then do more reads.
Using: wt 3.1.6
Is that the expected behavior? If a dbo::ptr falls out of scope, why
does that not also clean up sync issue?
Eric
#include <Wt/Dbo/Session>
#include <Wt/Dbo/backend/Postgres>
#include <Wt/Dbo/Types>
#include <Wt/Dbo/Impl>
#include <iostream>
namespace dbo = Wt::Dbo;
class Test {
public:
int value;
template<class Action>
void persist(Action& a) {
dbo::field(a, value, "value");
}
};
DBO_INSTANTIATE_TEMPLATES(Test);
int main()
{
dbo::backend::Postgres postgresConnection("host=127.0.0.1 dbname=testdb user=testuser password=testpw");
dbo::Session session;
session.setConnection(postgresConnection);
session.mapClass<Test>("test");
if (1) {
session.createTables();
dbo::Transaction transaction(session);
dbo::ptr<Test> test = session.add(new Test);
test.modify()->value = 10;
transaction.commit();
}
try {
dbo::Transaction transaction(session);
dbo::ptr<Test> test = session.find<Test>(); // only one row in table
test.modify()->value++;
std::cout << "modify table outside of program" << std::endl;
std::cin.get();
std::cout << "value to write = " << test->value << std::endl;
transaction.commit(); // this should throw
}
catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
{
dbo::Transaction transaction(session);
std::cout << "doing read" << std::endl;
dbo::ptr<Test> test = session.find<Test>(); // this throws, should it?
std::cout << "value after read = " << test->value << std::endl;
}
return 0;
}
------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest