diff --git a/CMakeLists.txt b/CMakeLists.txt index 89cd6432..238eb8f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -325,7 +325,7 @@ else (SQLITECPP_INTERNAL_SQLITE) endif() else() find_package (SQLite3 REQUIRED) - message(STATUS "Link to sqlite3 system library") + message(STATUS "Link to sqlite3 system library ${SQLite3_VERSION}") target_link_libraries(SQLiteCpp PUBLIC SQLite::SQLite3) if(SQLite3_VERSION VERSION_LESS "3.19") set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT") diff --git a/examples/example1/main.cpp b/examples/example1/main.cpp index 9c2b3616..122cc6cd 100644 --- a/examples/example1/main.cpp +++ b/examples/example1/main.cpp @@ -298,16 +298,16 @@ int main() db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"); // first row - int nb = db.exec("INSERT INTO test VALUES (NULL, \"test\")"); - std::cout << "INSERT INTO test VALUES (NULL, \"test\")\", returned " << nb << std::endl; + int nb = db.exec("INSERT INTO test VALUES (NULL, 'test')"); + std::cout << "INSERT INTO test VALUES (NULL, 'test')\", returned " << nb << std::endl; // second row - nb = db.exec("INSERT INTO test VALUES (NULL, \"second\")"); - std::cout << "INSERT INTO test VALUES (NULL, \"second\")\", returned " << nb << std::endl; + nb = db.exec("INSERT INTO test VALUES (NULL, 'second')"); + std::cout << "INSERT INTO test VALUES (NULL, 'second')\", returned " << nb << std::endl; // update the second row - nb = db.exec("UPDATE test SET value=\"second-updated\" WHERE id='2'"); - std::cout << "UPDATE test SET value=\"second-updated\" WHERE id='2', returned " << nb << std::endl; + nb = db.exec("UPDATE test SET value='second-updated' WHERE id='2'"); + std::cout << "UPDATE test SET value='second-updated' WHERE id='2', returned " << nb << std::endl; nb = db.getTotalChanges(); std::cout << "Nb of total changes since connection: " << nb << std::endl; @@ -347,8 +347,8 @@ int main() db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"); - int nb = db.exec("INSERT INTO test VALUES (NULL, \"test\")"); - std::cout << "INSERT INTO test VALUES (NULL, \"test\")\", returned " << nb << std::endl; + int nb = db.exec("INSERT INTO test VALUES (NULL, 'test')"); + std::cout << "INSERT INTO test VALUES (NULL, 'test')\", returned " << nb << std::endl; // Commit transaction transaction.commit(); @@ -365,8 +365,8 @@ int main() // Begin transaction SQLite::Transaction transaction(db); - int nb = db.exec("INSERT INTO test VALUES (NULL, \"second\")"); - std::cout << "INSERT INTO test VALUES (NULL, \"second\")\", returned " << nb << std::endl; + int nb = db.exec("INSERT INTO test VALUES (NULL, 'second')"); + std::cout << "INSERT INTO test VALUES (NULL, 'second')\", returned " << nb << std::endl; nb = db.exec("INSERT INTO test ObviousError"); std::cout << "INSERT INTO test \"error\", returned " << nb << std::endl; diff --git a/tests/Backup_test.cpp b/tests/Backup_test.cpp index 1b28542b..c59834c4 100644 --- a/tests/Backup_test.cpp +++ b/tests/Backup_test.cpp @@ -27,8 +27,8 @@ TEST(Backup, initException) { SQLite::Database srcDB("backup_test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); srcDB.exec("CREATE TABLE backup_test (id INTEGER PRIMARY KEY, value TEXT)"); - ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (1, \"first\")")); - ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (2, \"second\")")); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (1, 'first')")); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (2, 'second')")); EXPECT_THROW(SQLite::Backup backup(srcDB, srcDB), SQLite::Exception); EXPECT_THROW(SQLite::Backup backup(srcDB, "main", srcDB, "main"), SQLite::Exception); const std::string name("main"); @@ -44,8 +44,8 @@ TEST(Backup, executeStepOne) { SQLite::Database srcDB("backup_test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); srcDB.exec("CREATE TABLE backup_test (id INTEGER PRIMARY KEY, value TEXT)"); - ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (1, \"first\")")); - ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (2, \"second\")")); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (1, 'first')")); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (2, 'second')")); SQLite::Database destDB("backup_test.db3.backup", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); SQLite::Backup backup(destDB, "main", srcDB, "main"); @@ -79,8 +79,8 @@ TEST(Backup, executeStepAll) { SQLite::Database srcDB("backup_test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); srcDB.exec("CREATE TABLE backup_test (id INTEGER PRIMARY KEY, value TEXT)"); - ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (1, \"first\")")); - ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (2, \"second\")")); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (1, 'first')")); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (2, 'second')")); SQLite::Database destDB("backup_test.db3.backup", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); SQLite::Backup backup(destDB, srcDB); @@ -110,8 +110,8 @@ TEST(Backup, executeStepException) { SQLite::Database srcDB("backup_test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); srcDB.exec("CREATE TABLE backup_test (id INTEGER PRIMARY KEY, value TEXT)"); - ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (1, \"first\")")); - ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (2, \"second\")")); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (1, 'first')")); + ASSERT_EQ(1, srcDB.exec("INSERT INTO backup_test VALUES (2, 'second')")); { SQLite::Database destDB("backup_test.db3.backup", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); (void)destDB; diff --git a/tests/Column_test.cpp b/tests/Column_test.cpp index 4417cb17..0cfffdc5 100644 --- a/tests/Column_test.cpp +++ b/tests/Column_test.cpp @@ -38,7 +38,7 @@ static void test_column_basis(bool utf16) EXPECT_EQ(0, db.getLastInsertRowid()); // Create a first row (autoid: 1) with all kind of data and a null value - SQLite::Statement insert(db, "INSERT INTO test VALUES (NULL, \"first\", -123, 0.123, ?, NULL)"); + SQLite::Statement insert(db, "INSERT INTO test VALUES (NULL, 'first', -123, 0.123, ?, NULL)"); // Bind the blob value to the first parameter of the SQL query const char buffer[] = {'b', 'l', '\0', 'b'}; // "bl\0b" : 4 char, with a null byte inside const int size = sizeof(buffer); // size = 4 @@ -214,7 +214,7 @@ TEST(Column, getName) // Create a new database SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT)")); - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first')")); // Compile a SQL query, using the "id" column name as-is, but aliasing the "msg" column with new name "value" SQLite::Statement query(db, "SELECT id, msg as value FROM test"); @@ -267,7 +267,7 @@ TEST(Column, shared_ptr) // Create a new database SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE); EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT)")); - EXPECT_EQ(1, db.exec(R"(INSERT INTO test VALUES (42, "fortytwo"))")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (42, 'fortytwo')")); const char* query_str = "SELECT id, msg FROM test"; std::unique_ptr query{ new SQLite::Statement(db, query_str) }; diff --git a/tests/Database_test.cpp b/tests/Database_test.cpp index ec9adefa..79f5c876 100644 --- a/tests/Database_test.cpp +++ b/tests/Database_test.cpp @@ -219,26 +219,26 @@ TEST(Database, exec) EXPECT_EQ(0, db.getTotalChanges()); // first row : insert the "first" text value into new row of id 1 - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first')")); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(1, db.getLastInsertRowid()); EXPECT_EQ(1, db.getTotalChanges()); // second row : insert the "second" text value into new row of id 2 - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"second\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'second')")); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(2, db.getLastInsertRowid()); EXPECT_EQ(2, db.getTotalChanges()); // third row : insert the "third" text value into new row of id 3 - const std::string insert("INSERT INTO test VALUES (NULL, \"third\")"); + const std::string insert("INSERT INTO test VALUES (NULL, 'third')"); EXPECT_EQ(1, db.exec(insert)); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(3, db.getLastInsertRowid()); EXPECT_EQ(3, db.getTotalChanges()); // update the second row : update text value to "second_updated" - EXPECT_EQ(1, db.exec("UPDATE test SET value=\"second-updated\" WHERE id='2'")); + EXPECT_EQ(1, db.exec("UPDATE test SET value='second-updated' WHERE id='2'")); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(3, db.getLastInsertRowid()); // last inserted row ID is still 3 EXPECT_EQ(4, db.getTotalChanges()); @@ -261,14 +261,14 @@ TEST(Database, exec) EXPECT_EQ(5, db.getTotalChanges()); // insert two rows with two *different* statements => returns only 1, ie. for the second INSERT statement - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\");INSERT INTO test VALUES (NULL, \"second\");")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first');INSERT INTO test VALUES (NULL, 'second');")); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(2, db.getLastInsertRowid()); EXPECT_EQ(7, db.getTotalChanges()); #if (SQLITE_VERSION_NUMBER >= 3007011) // insert two rows with only one statement (starting with SQLite 3.7.11) => returns 2 - EXPECT_EQ(2, db.exec("INSERT INTO test VALUES (NULL, \"third\"), (NULL, \"fourth\");")); + EXPECT_EQ(2, db.exec("INSERT INTO test VALUES (NULL, 'third'), (NULL, 'fourth');")); EXPECT_EQ(2, db.getChanges()); EXPECT_EQ(4, db.getLastInsertRowid()); EXPECT_EQ(9, db.getTotalChanges()); @@ -287,26 +287,26 @@ TEST(Database, tryExec) EXPECT_EQ(0, db.getTotalChanges()); // first row : insert the "first" text value into new row of id 1 - EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, \"first\")")); + EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, 'first')")); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(1, db.getLastInsertRowid()); EXPECT_EQ(1, db.getTotalChanges()); // second row : insert the "second" text value into new row of id 2 - EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, \"second\")")); + EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, 'second')")); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(2, db.getLastInsertRowid()); EXPECT_EQ(2, db.getTotalChanges()); // third row : insert the "third" text value into new row of id 3 - const std::string insert("INSERT INTO test VALUES (NULL, \"third\")"); + const std::string insert("INSERT INTO test VALUES (NULL, 'third')"); EXPECT_EQ(SQLite::OK, db.tryExec(insert)); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(3, db.getLastInsertRowid()); EXPECT_EQ(3, db.getTotalChanges()); // update the second row : update text value to "second_updated" - EXPECT_EQ(SQLite::OK, db.tryExec("UPDATE test SET value=\"second-updated\" WHERE id='2'")); + EXPECT_EQ(SQLite::OK, db.tryExec("UPDATE test SET value='second-updated' WHERE id='2'")); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(3, db.getLastInsertRowid()); // last inserted row ID is still 3 EXPECT_EQ(4, db.getTotalChanges()); @@ -327,14 +327,14 @@ TEST(Database, tryExec) EXPECT_EQ(5, db.getTotalChanges()); // insert two rows with two *different* statements => only 1 change, ie. for the second INSERT statement - EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, \"first\");INSERT INTO test VALUES (NULL, \"second\");")); + EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, 'first');INSERT INTO test VALUES (NULL, 'second');")); EXPECT_EQ(1, db.getChanges()); EXPECT_EQ(2, db.getLastInsertRowid()); EXPECT_EQ(7, db.getTotalChanges()); #if (SQLITE_VERSION_NUMBER >= 3007011) // insert two rows with only one statement (starting with SQLite 3.7.11) - EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, \"third\"), (NULL, \"fourth\");")); + EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, 'third'), (NULL, 'fourth');")); EXPECT_EQ(2, db.getChanges()); EXPECT_EQ(4, db.getLastInsertRowid()); EXPECT_EQ(9, db.getTotalChanges()); @@ -350,14 +350,14 @@ TEST(Database, execAndGet) db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT, weight INTEGER)"); // insert a few rows - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)")); - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"second\", 5)")); - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"third\", 7)")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first', 3)")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'second', 5)")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'third', 7)")); // Get a single value result with an easy to use shortcut EXPECT_STREQ("second", db.execAndGet("SELECT value FROM test WHERE id=2")); EXPECT_STREQ("third", db.execAndGet("SELECT value FROM test WHERE weight=7")); - const std::string query("SELECT weight FROM test WHERE value=\"first\""); + const std::string query("SELECT weight FROM test WHERE value='first'"); EXPECT_EQ(3, db.execAndGet(query).getInt()); } @@ -369,7 +369,7 @@ TEST(Database, execException) EXPECT_EQ(SQLite::OK, db.getExtendedErrorCode()); // exception with SQL error: "no such table" - 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.getExtendedErrorCode()); EXPECT_STREQ("no such table: test", db.getErrorMsg()); @@ -387,14 +387,14 @@ TEST(Database, execException) EXPECT_STREQ("table test has 3 columns but 2 values were supplied", db.getErrorMsg()); // 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); - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first', 3)")); // exception with SQL error: "No row to get a column from" - EXPECT_THROW(db.execAndGet("SELECT weight FROM test WHERE value=\"second\""), SQLite::Exception); + EXPECT_THROW(db.execAndGet("SELECT weight FROM test WHERE value='second'"), SQLite::Exception); // Add a row with more values than columns in the table: "table test has 3 columns but 4 values were supplied" - 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.getExtendedErrorCode()); EXPECT_STREQ("table test has 3 columns but 4 values were supplied", db.getErrorMsg()); @@ -408,7 +408,7 @@ TEST(Database, tryExecError) EXPECT_EQ(SQLite::OK, db.getExtendedErrorCode()); // Insert into nonexistent table: "no such table" - EXPECT_EQ(SQLITE_ERROR, db.tryExec("INSERT INTO test VALUES (NULL, \"first\", 3)")); + EXPECT_EQ(SQLITE_ERROR, db.tryExec("INSERT INTO test VALUES (NULL, 'first', 3)")); EXPECT_EQ(SQLITE_ERROR, db.getErrorCode()); EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode()); EXPECT_STREQ("no such table: test", db.getErrorMsg()); @@ -426,17 +426,17 @@ TEST(Database, tryExecError) EXPECT_STREQ("table test has 3 columns but 2 values were supplied", db.getErrorMsg()); // Add a row with more values than columns in the table: "table test has 3 columns but 4 values were supplied" - EXPECT_EQ(SQLITE_ERROR, db.tryExec("INSERT INTO test VALUES (NULL, \"first\", 123, 0.123)")); + EXPECT_EQ(SQLITE_ERROR, db.tryExec("INSERT INTO test VALUES (NULL, 'first', 123, 0.123)")); 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.getErrorMsg()); // Create a first row - EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, \"first\", 3)")); + EXPECT_EQ(SQLite::OK, db.tryExec("INSERT INTO test VALUES (NULL, 'first', 3)")); EXPECT_EQ(1, db.getLastInsertRowid()); // Try to insert a new row with the same PRIMARY KEY: "UNIQUE constraint failed: test.id" - EXPECT_EQ(SQLITE_CONSTRAINT, db.tryExec("INSERT INTO test VALUES (1, \"impossible\", 456)")); + EXPECT_EQ(SQLITE_CONSTRAINT, db.tryExec("INSERT INTO test VALUES (1, 'impossible', 456)")); EXPECT_EQ(SQLITE_CONSTRAINT, db.getErrorCode()); EXPECT_EQ(SQLITE_CONSTRAINT_PRIMARYKEY, db.getExtendedErrorCode()); EXPECT_STREQ("UNIQUE constraint failed: test.id", db.getErrorMsg()); @@ -464,8 +464,8 @@ TEST(Database, createFunction) SQLite::Database db(":memory:", SQLite::OPEN_READWRITE); db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"); - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\")")); - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"second\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first')")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'second')")); // exception with SQL error: "no such function: firstchar" EXPECT_THROW(db.exec("SELECT firstchar(value) FROM test WHERE id=1"), SQLite::Exception); diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index 83208e53..a76d06a8 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -87,7 +87,7 @@ TEST(Statement, invalid) EXPECT_THROW(query.exec(), SQLite::Exception); // exec() shall throw as it needs to be reseted // Add a first row - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first')")); EXPECT_EQ(1, db.getLastInsertRowid()); EXPECT_EQ(1, db.getTotalChanges()); @@ -110,7 +110,7 @@ TEST(Statement, moveConstructor) // Create a new database SQLite::Database db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE); EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)")); - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first')")); EXPECT_EQ(1, db.getLastInsertRowid()); SQLite::Statement query = StatementBuilder(db, "SELECT * FROM test"); @@ -153,7 +153,7 @@ TEST(Statement, executeStep) EXPECT_EQ(SQLite::OK, db.getErrorCode()); // Create a first row - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 123, 0.123)")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first', 123, 0.123)")); EXPECT_EQ(1, db.getLastInsertRowid()); // Compile a SQL query @@ -185,13 +185,13 @@ TEST(Statement, executeStep) EXPECT_THROW(query.executeStep(), SQLite::Exception); // Try to insert a new row with the same PRIMARY KEY: "UNIQUE constraint failed: test.id" - SQLite::Statement insert(db, "INSERT INTO test VALUES (1, \"impossible\", 456, 0.456)"); + SQLite::Statement insert(db, "INSERT INTO test VALUES (1, 'impossible', 456, 0.456)"); EXPECT_THROW(insert.executeStep(), SQLite::Exception); // in this case, reset() do throw again the same error EXPECT_THROW(insert.reset(), SQLite::Exception); // Try again to insert a new row with the same PRIMARY KEY (with an alternative method): "UNIQUE constraint failed: test.id" - SQLite::Statement insert2(db, "INSERT INTO test VALUES (1, \"impossible\", 456, 0.456)"); + SQLite::Statement insert2(db, "INSERT INTO test VALUES (1, 'impossible', 456, 0.456)"); EXPECT_THROW(insert2.exec(), SQLite::Exception); } @@ -206,7 +206,7 @@ TEST(Statement, tryExecuteStep) EXPECT_EQ(SQLite::OK, db.getErrorCode()); // Create a first row - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 123, 0.123)")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first', 123, 0.123)")); EXPECT_EQ(1, db.getLastInsertRowid()); // Compile a SQL query @@ -235,7 +235,7 @@ TEST(Statement, tryExecuteStep) EXPECT_TRUE (query.isDone()); // "done" is "the end" // Try to insert a new row with the same PRIMARY KEY: "UNIQUE constraint failed: test.id" - SQLite::Statement insert(db, "INSERT INTO test VALUES (1, \"impossible\", 456, 0.456)"); + SQLite::Statement insert(db, "INSERT INTO test VALUES (1, 'impossible', 456, 0.456)"); EXPECT_EQ(insert.tryExecuteStep(), SQLITE_CONSTRAINT); // in this case, reset() do throw again the same error EXPECT_EQ(insert.tryReset(), SQLITE_CONSTRAINT); @@ -750,10 +750,10 @@ TEST(Statement, isColumnNull) ASSERT_EQ(SQLite::OK, db.getErrorCode()); // Create a first row with no null values, then other rows with each time a NULL value - ASSERT_EQ(1, db.exec("INSERT INTO test VALUES (\"first\", 123, 0.123)")); + ASSERT_EQ(1, db.exec("INSERT INTO test VALUES ('first', 123, 0.123)")); ASSERT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 123, 0.123)")); - ASSERT_EQ(1, db.exec("INSERT INTO test VALUES (\"first\", NULL, 0.123)")); - ASSERT_EQ(1, db.exec("INSERT INTO test VALUES (\"first\", 123, NULL)")); + ASSERT_EQ(1, db.exec("INSERT INTO test VALUES ('first', NULL, 0.123)")); + ASSERT_EQ(1, db.exec("INSERT INTO test VALUES ('first', 123, NULL)")); // Compile a SQL query const std::string select("SELECT * FROM test"); @@ -813,10 +813,10 @@ TEST(Statement, isColumnNullByName) ASSERT_EQ(SQLITE_OK, db.getErrorCode()); // Create a first row with no null values, then other rows with each time a NULL value - ASSERT_EQ(1, db.exec("INSERT INTO test VALUES (\"first\", 123, 0.123)")); + ASSERT_EQ(1, db.exec("INSERT INTO test VALUES ('first', 123, 0.123)")); ASSERT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 123, 0.123)")); - ASSERT_EQ(1, db.exec("INSERT INTO test VALUES (\"first\", NULL, 0.123)")); - ASSERT_EQ(1, db.exec("INSERT INTO test VALUES (\"first\", 123, NULL)")); + ASSERT_EQ(1, db.exec("INSERT INTO test VALUES ('first', NULL, 0.123)")); + ASSERT_EQ(1, db.exec("INSERT INTO test VALUES ('first', 123, NULL)")); // Compile a SQL query const std::string select("SELECT * FROM test"); @@ -878,7 +878,7 @@ TEST(Statement, getColumnByName) EXPECT_EQ(SQLite::OK, db.getExtendedErrorCode()); // Create a first row - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 123, 0.123)")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first', 123, 0.123)")); EXPECT_EQ(1, db.getLastInsertRowid()); EXPECT_EQ(1, db.getTotalChanges()); @@ -983,7 +983,7 @@ TEST(Statement, getColumns) EXPECT_EQ(SQLite::OK, db.getExtendedErrorCode()); // Create a first row - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 123, 0.123)")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first', 123, 0.123)")); EXPECT_EQ(1, db.getLastInsertRowid()); EXPECT_EQ(1, db.getTotalChanges()); diff --git a/tests/Transaction_test.cpp b/tests/Transaction_test.cpp index 45937697..0db1a181 100644 --- a/tests/Transaction_test.cpp +++ b/tests/Transaction_test.cpp @@ -32,7 +32,7 @@ TEST(Transaction, commitRollback) EXPECT_EQ(SQLite::OK, db.getErrorCode()); // Insert a first value - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first')")); EXPECT_EQ(1, db.getLastInsertRowid()); // Commit transaction @@ -62,7 +62,7 @@ TEST(Transaction, commitRollback) SQLite::Transaction transaction(db); // Insert a second value (that will be rollbacked) - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"third\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'third')")); EXPECT_EQ(2, db.getLastInsertRowid()); // end of scope: automatic rollback @@ -75,7 +75,7 @@ TEST(Transaction, commitRollback) SQLite::Transaction transaction(db); // Insert a second value (that will be rollbacked) - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"second\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'second')")); EXPECT_EQ(2, db.getLastInsertRowid()); // Execute with an error => exception with auto-rollback @@ -96,7 +96,7 @@ TEST(Transaction, commitRollback) SQLite::Transaction transaction(db); // Insert a second value (that will be rollbacked) - EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"third\")")); + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'third')")); EXPECT_EQ(2, db.getLastInsertRowid()); // Execute a manual rollback