How to capture database insert/update triggers with Wt::Dbo and get the id ?
Added by Lamiel Toch almost 4 years ago
Hello,
I followed this thread : https://redmine.webtoolkit.eu/boards/1/topics/9199
and I would like to capture the id of an inserted row in the database with Wt/Dbo
Is there a way to do that with Wt::SaveDbAction or Wt:Dbo::TransactionDoneAction ?
Thanks in advance.
Regards
Lamiel
Replies (3)
RE: How to capture database insert/update triggers with Wt::Dbo and get the id ? - Added by Korneel Dumon almost 4 years ago
If you want to know the id immediately after an insert, you can flush the session, like so:
auto myPtr = session.add(...);
session.flush();
std::cout << "myPtr ID = " << myPtr.id() << std::endl;
RE: How to capture database insert/update triggers with Wt::Dbo and get the id ? - Added by Lamiel Toch almost 4 years ago
Hi Korneel,
Yes, I already know that.
I mean I would like to capture the id with Wt::Dbo in persist method :
class Path
{
public:
...
template<class Action>
void persist(Action& a)
{
// Application side trigger
if (typeid(a) == typeid(Wt::Dbo::InitSchema))
{
// Initialize Schema
std::cout << "typeid(a) = " << typeid(a).name() << std::endl;
}
if (typeid(a) == typeid(Wt::Dbo::SessionAddAction))
{
// Insert action
}
else if (typeid(a) == typeid(Wt::Dbo::SaveDbAction<Path>))
{
// Save action
}
else if (typeid(a) == typeid(Wt::Dbo::LoadDbAction<Path>))
{
// Load action
}
else if (typeid(a) == typeid(Wt::Dbo::TransactionDoneAction))
{
// Transaction Done
}
else
{
// Other cases
std::cout << "typeid(a) = " << typeid(a).name() << std::endl;
}
...
}
};
Do you know how to get the id ?
RE: How to capture database insert/update triggers with Wt::Dbo and get the id ? - Added by Korneel Dumon almost 4 years ago
You can get the id from within the object itself by inheriting Wt::Dbo::Dbo, see
https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Dbo_1_1Dbo.html