aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2015-07-25 18:54:06 +0200
committerRobin Krahl <me@robin-krahl.de>2015-07-25 18:54:06 +0200
commit6a00fdf8076537def530e635fbd2a6bbb1827094 (patch)
tree57380e590ceb511388badfd9b2998c79f27ea762 /src
parente04b08fdf55e6e964f6fc2198b882d07ee463456 (diff)
downloadsqlitepp-6a00fdf8076537def530e635fbd2a6bbb1827094.tar.gz
sqlitepp-6a00fdf8076537def530e635fbd2a6bbb1827094.tar.bz2
Add lastInsertRowId, minor improvements.
Diffstat (limited to 'src')
-rw-r--r--src/sqlitepp/sqlitepp.cc7
-rw-r--r--src/sqlitepp/sqlitepp_test.cc5
2 files changed, 11 insertions, 1 deletions
diff --git a/src/sqlitepp/sqlitepp.cc b/src/sqlitepp/sqlitepp.cc
index d64b5ba..ef0dfa8 100644
--- a/src/sqlitepp/sqlitepp.cc
+++ b/src/sqlitepp/sqlitepp.cc
@@ -187,6 +187,11 @@ void Database::execute(const std::string& sql) {
statement->step();
}
+int Database::lastInsertRowId() const {
+ requireOpen();
+ return sqlite3_last_insert_rowid(m_handle);
+}
+
void Database::open(const std::string& file) {
if (isOpen()) {
throw std::logic_error("sqlitepp::Database::open(std::string&): "
@@ -235,7 +240,7 @@ bool ResultSet::canRead() const {
int ResultSet::columnCount() const {
m_statement->requireOpen();
m_statement->requireCanRead();
- return sqlite3_column_count(m_statement->m_handle);
+ return sqlite3_data_count(m_statement->m_handle);
}
double ResultSet::readDouble(const int column) const {
diff --git a/src/sqlitepp/sqlitepp_test.cc b/src/sqlitepp/sqlitepp_test.cc
index b7ea5f6..dfa46d4 100644
--- a/src/sqlitepp/sqlitepp_test.cc
+++ b/src/sqlitepp/sqlitepp_test.cc
@@ -66,10 +66,15 @@ TEST(Database, insert) {
statement->bind(":id", 1);
statement->bind(2, "test value");
statement->execute();
+ const int rowId1 = database.lastInsertRowId();
+ EXPECT_NE(0, rowId1);
statement->reset();
statement->bind(":id", 2);
statement->bind(2, "other value");
statement->execute();
+ const int rowId2 = database.lastInsertRowId();
+ EXPECT_NE(0, rowId2);
+ EXPECT_NE(rowId1, rowId2);
}
TEST(Database, query) {