rbock/sqlpp11-connector-sqlite3

Running a prepared select statement throws an exception

Closed this issue · 5 comments

Running the following prepared select statement throws an exception

auto prepared = m_db->prepare(
    select(count(objects.Id).as(numObjects))
    .from(objects)
    .where(objects.ParentId == parameter(objects.ParentId)));

prepared.params.ParentId = id;    
const auto& result = m_db->run(prepared);

In the connection class it will get executed:

auto rc = sqlite3_step(prepared.sqlite_statement);
if (rc != SQLITE_OK and rc != SQLITE_DONE)

But the rc in this case is SQLITE_ROW thus causing an exception.

This also occurs when executing string queries like this:

m_db->execute("SELECT (COUNT(objects.Id)) FROM objects WHERE (objects.ParentId='0')");

Yikes, guess it shows that the slite3 connector has not seen much use yet.

Thanks for your detailed reports! I think I fixed it in develop, I'll
add a test later today.

Regards,

Roland

The fix does cause the execute itself to succeed, but it causes the result of the query to be empty. After the successful execute the bool bind_result_t::next_impl() gets called which causes sqlite3_step to be executed which now returns SQLITE_DONE effectively always skipping the first row result.

And I think I fixed the problem in develop and added some tests now :-)

Cheers,

Roland

I can confirm the fix, thanks.

I must say I'm really satisfied with the library. The compile time query checks are brilliant. A big improvement coming from the sqlite c interface.

I can confirm the fix, thanks.

Great! I made a release of it yesterday, so you should be able to work
with the master branch again.

I must say I'm really satisfied with the library. The compile time
query checks are brilliant. A big improvement coming from the sqlite c
interface.

Thanks, nice to read that! Please spread the word :-)

Regards,

Roland