Project

General

Profile

Preventing fatal errors on Dbo::query failure inside a QueryModel

Added by Roy Wiggins about 7 years ago

If I have a query that's totally misformed and unparsable, I get a nice exception (error parsing SQL query).

But if it's basically correct but mistaken (selecting a column that doesn't exist, etc) Wt kills the session with a fatal error.

Is there any way to recover from this? I want to expose arbitrary SQL queries to users- this is an intranet application where SQL injection isn't an issue, and authenticated users are assumed to be trustworthy.

The query is coming into a model like this:

     auto query = app->db.query<queryType>(searchEdit->text().toUTF8());
     model->setQuery(query,true);

I can sidestep this by trying to run the query first but it's kind of awkward.

        Wt::Dbo::Query<queryType> query = app->db.query<queryType>(searchEdit->text().toUTF8());
        dbo::Transaction t(app->db);
        auto test = query.limit(1).resultValue();
        t.commit();
        model->setQuery(query.limit(-1),true);

Replies (1)

RE: Preventing fatal errors on Dbo::query failure inside a QueryModel - Added by Koen Deforche about 7 years ago

Hey Roy,

At least one way to do this is to catch the exception from within a reimplemented WApplication::notify().

Another solution is to just query the rowCount() of the model after creating it? That isn't a redundant thing to do as the size is cached anyway.

Regards,

koen

    (1-1/1)