SOCI/soci

sqlite3 fails to report row count with get_affected_rows().

Opened this issue · 1 comments

I'm sorry that I'm not good at reading/writing English.

I met a problem while I was writing a test for my project:

  1. create a blank table.
  2. false update.
  3. insert a record into the table.
  4. update against the inserted record.

Attached code below should re-produce the problem.

--

/*
 * sqlite3 fails to report row count with get_affected_rows().
 * Confirmed on CentOS7 and FreeBSD11.
 */
#include <cassert>
#include <iostream>
#include <soci.h>
namespace {
void test001_sub(::soci::session& s) {
  s << "drop table if exists test_table";
  s << "create table if not exists test_table(p integer, q integer)";
  int p=0, q=0;
  ::soci::statement inserter((s.prepare<<"insert into test_table(p,q)values(:p,:q)",::soci::use(p,"p"),::soci::use(q,"q")));
  ::soci::statement updator((s.prepare<<"update test_table set p=2 where q=:q",::soci::use(q,"q")));
  updator.execute(true); assert(0 == updator.get_affected_rows());
  inserter.execute(true); assert(0 < inserter.get_affected_rows());
  /*
backend = postgresql
backend = sqlite3
Assertion failed: (0 < updator.get_affected_rows()), function test001_sub, file dbtest.cpp, line 19.
   */
  std::cout << "backend = " << s.get_backend_name() << std::endl;
  updator.execute(true); assert(0 < updator.get_affected_rows());
  s << "drop table if exists test_table";
}
void test001() {
  bool result = false;
  try {
    for (auto name : {"postgresql://user=postgres","sqlite3://:memory:"}) {
      ::soci::session s(name);
      test001_sub(s);
    }
    result = true;
  } catch (const std::exception& e) {
    std::cout << e.what() << std::endl;
  }
  assert(result);
}
} // namespace
int
main() {
  test001();
  return 0;
}

(I posted wrong text before)