diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 085da10..775a8e5 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -247,10 +247,8 @@ public: /// Return the numeric result code for the most recent failed API call (if any). int getErrorCode() const noexcept; // nothrow - /// Return the extended numeric result code for the most recent failed API call (if any). int getExtendedErrorCode() const noexcept; // nothrow - /// Return UTF-8 encoded English language explanation of the most recent failed API call (if any). const char* errmsg() const noexcept; // nothrow diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index a3344aa..511d989 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -479,6 +479,7 @@ public: { return mbDone; } + /// Return the numeric result code for the most recent failed API call (if any). int getErrorCode() const noexcept; // nothrow /// Return the extended numeric result code for the most recent failed API call (if any). diff --git a/tests/Database_test.cpp b/tests/Database_test.cpp index f87dba3..4124486 100644 --- a/tests/Database_test.cpp +++ b/tests/Database_test.cpp @@ -220,16 +220,19 @@ TEST(Database, execException) { EXPECT_THROW(db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)"), SQLite::Exception); EXPECT_EQ(SQLITE_ERROR, db.getErrorCode()); EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode()); + EXPECT_STREQ("no such table: test", db.errmsg()); // Create a new table db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT, weight INTEGER)"); EXPECT_EQ(SQLITE_OK, db.getErrorCode()); EXPECT_EQ(SQLITE_OK, db.getExtendedErrorCode()); + EXPECT_STREQ("not an error", db.errmsg()); // exception with SQL error: "table test has 3 columns but 2 values were supplied" EXPECT_THROW(db.exec("INSERT INTO test VALUES (NULL, 3)"), SQLite::Exception); EXPECT_EQ(SQLITE_ERROR, db.getErrorCode()); EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode()); + EXPECT_STREQ("table test has 3 columns but 2 values were supplied", db.errmsg()); // exception with SQL error: "No row to get a column from" EXPECT_THROW(db.execAndGet("SELECT weight FROM test WHERE value=\"first\""), SQLite::Exception); @@ -242,6 +245,7 @@ TEST(Database, execException) { EXPECT_THROW(db.exec("INSERT INTO test VALUES (NULL, \"first\", 123, 0.123)"), SQLite::Exception); EXPECT_EQ(SQLITE_ERROR, db.getErrorCode()); EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode()); + EXPECT_STREQ("table test has 3 columns but 4 values were supplied", db.errmsg()); } // TODO: test Database::createFunction()