mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-05 02:06:02 -04:00
Complete unit tests for Database::errmsg()
This commit is contained in:
parent
fb5508921a
commit
57d991b85e
@ -247,10 +247,8 @@ public:
|
|||||||
|
|
||||||
/// Return the numeric result code for the most recent failed API call (if any).
|
/// Return the numeric result code for the most recent failed API call (if any).
|
||||||
int getErrorCode() const noexcept; // nothrow
|
int getErrorCode() const noexcept; // nothrow
|
||||||
|
|
||||||
/// Return the extended numeric result code for the most recent failed API call (if any).
|
/// Return the extended numeric result code for the most recent failed API call (if any).
|
||||||
int getExtendedErrorCode() const noexcept; // nothrow
|
int getExtendedErrorCode() const noexcept; // nothrow
|
||||||
|
|
||||||
/// Return UTF-8 encoded English language explanation of the most recent failed API call (if any).
|
/// Return UTF-8 encoded English language explanation of the most recent failed API call (if any).
|
||||||
const char* errmsg() const noexcept; // nothrow
|
const char* errmsg() const noexcept; // nothrow
|
||||||
|
|
||||||
|
@ -479,6 +479,7 @@ public:
|
|||||||
{
|
{
|
||||||
return mbDone;
|
return mbDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the numeric result code for the most recent failed API call (if any).
|
/// Return the numeric result code for the most recent failed API call (if any).
|
||||||
int getErrorCode() const noexcept; // nothrow
|
int getErrorCode() const noexcept; // nothrow
|
||||||
/// Return the extended numeric result code for the most recent failed API call (if any).
|
/// Return the extended numeric result code for the most recent failed API call (if any).
|
||||||
|
@ -220,16 +220,19 @@ TEST(Database, execException) {
|
|||||||
EXPECT_THROW(db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)"), SQLite::Exception);
|
EXPECT_THROW(db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)"), SQLite::Exception);
|
||||||
EXPECT_EQ(SQLITE_ERROR, db.getErrorCode());
|
EXPECT_EQ(SQLITE_ERROR, db.getErrorCode());
|
||||||
EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode());
|
EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode());
|
||||||
|
EXPECT_STREQ("no such table: test", db.errmsg());
|
||||||
|
|
||||||
// Create a new table
|
// Create a new table
|
||||||
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT, weight INTEGER)");
|
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT, weight INTEGER)");
|
||||||
EXPECT_EQ(SQLITE_OK, db.getErrorCode());
|
EXPECT_EQ(SQLITE_OK, db.getErrorCode());
|
||||||
EXPECT_EQ(SQLITE_OK, db.getExtendedErrorCode());
|
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"
|
// 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_THROW(db.exec("INSERT INTO test VALUES (NULL, 3)"), SQLite::Exception);
|
||||||
EXPECT_EQ(SQLITE_ERROR, db.getErrorCode());
|
EXPECT_EQ(SQLITE_ERROR, db.getErrorCode());
|
||||||
EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode());
|
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"
|
// exception with SQL error: "No row to get a column from"
|
||||||
EXPECT_THROW(db.execAndGet("SELECT weight FROM test WHERE value=\"first\""), SQLite::Exception);
|
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_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.getErrorCode());
|
||||||
EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode());
|
EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode());
|
||||||
|
EXPECT_STREQ("table test has 3 columns but 4 values were supplied", db.errmsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test Database::createFunction()
|
// TODO: test Database::createFunction()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user