Skip to content

Commit 9b53a7b

Browse files
committed
Merge pull request #144 from RenathoAzevedo/master
Function to return the count of database changes.
2 parents 30b9aa6 + 2ea2002 commit 9b53a7b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

hdr/sqlite_modern_cpp.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace sqlite {
8080
_inx(other._inx), execution_started(other.execution_started) { }
8181

8282
void execute();
83-
83+
8484
std::string sql() {
8585
#if SQLITE_VERSION_NUMBER >= 3014000
8686
auto sqlite_deleter = [](void *ptr) {sqlite3_free(ptr);};
@@ -101,7 +101,7 @@ namespace sqlite {
101101
_next_index();
102102
--_inx;
103103
}
104-
execution_started = state;
104+
execution_started = state;
105105
}
106106
bool used() const { return execution_started; }
107107
row_iterator begin();
@@ -445,7 +445,7 @@ namespace sqlite {
445445
Values&&... values
446446
);
447447
}
448-
448+
449449
enum class OpenFlags {
450450
READONLY = SQLITE_OPEN_READONLY,
451451
READWRITE = SQLITE_OPEN_READWRITE,
@@ -521,6 +521,10 @@ namespace sqlite {
521521
return sqlite3_last_insert_rowid(_db.get());
522522
}
523523

524+
int rows_modified() const {
525+
return sqlite3_changes(_db.get());
526+
}
527+
524528
template <typename Function>
525529
void define(const std::string &name, Function&& func) {
526530
typedef utility::function_traits<Function> traits;

tests/simple_examples.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <cstdlib>
44
#include <sqlite_modern_cpp.h>
55
#include <catch.hpp>
6-
using namespace sqlite;
6+
using namespace sqlite;
77
using namespace std;
88

99
TEST_CASE("simple examples", "[examples]") {
@@ -23,5 +23,14 @@ TEST_CASE("simple examples", "[examples]") {
2323
db << sql >> test;
2424

2525
REQUIRE(test == 2);
26+
27+
db << "UPDATE foo SET b=? WHERE a=?;" << "hi" << 1L;
28+
db << "SELECT b FROM foo WHERE a=?;" << 1L >> str;
2629

30+
REQUIRE(str == "hi");
31+
REQUIRE(db.rows_modified() == 1);
32+
33+
db << "UPDATE foo SET b=?;" << "hello world";
34+
35+
REQUIRE(db.rows_modified() == 2);
2736
}

0 commit comments

Comments
 (0)