sqlpp11 icon indicating copy to clipboard operation
sqlpp11 copied to clipboard

Return value of insert statement.

Open slepasteur opened this issue 10 years ago • 3 comments

What is the return value of an insert statement like the one on the wiki? db.run(insert_into(tab).set(tab.gamma = true));

slepasteur avatar Sep 01 '16 14:09 slepasteur

In the end it is connector-dependent, but the typical behavior is to return the id of the line inserted, e.g. as returned by sqlite3_last_insert_rowid().

rbock avatar Sep 01 '16 16:09 rbock

So the error reporting is done via exceptions I suppose?

I have a problem with an sqlite3 db that is accessed from multiple processes and, after some time, the insert does not throw but nothing is inserted. I was wondering if an error occurred and I forgot to check it.

slepasteur avatar Sep 01 '16 16:09 slepasteur

Yes, errors are reported as exceptions, see src/connection.cpp:

  void execute_statement(detail::connection_handle& handle, detail::prepared_statement_handle_t& prepared)
  {
    auto rc = sqlite3_step(prepared.sqlite_statement);
    switch (rc)
    {
      case SQLITE_OK:
      case SQLITE_ROW:  // might occur if execute is called with a select
      case SQLITE_DONE:
        return;
      default:
        std::cerr << "Sqlite3 debug: sqlite3_step return code: " << rc << std::endl;
        throw sqlpp::exception("Sqlite3 error: Could not execute statement: " +
                               std::string(sqlite3_errmsg(handle.sqlite)));
    }

Please report a bug for the sqlite connector in case you trace it there.

Happy bug hunting!

Cheers,

Roland

rbock avatar Sep 01 '16 18:09 rbock