Project

General

Profile

How to capture database insert/update triggers with Wt::Dbo and get the id ?

Added by Lamiel Toch about 3 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 about 3 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 about 3 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 ?

    (1-3/3)