aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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) {