mirror of
https://github.com/SOCI/soci.git
synced 2026-05-01 16:49:27 -05:00
Merge branch 'sqlite-enable-fks'
Enable foreign keys in SQLite tests to make the behaviour more compatible with the other databases by default. See #1195.
This commit is contained in:
@@ -123,30 +123,32 @@ private:
|
||||
soci::session& m_sql;
|
||||
};
|
||||
|
||||
TEST_CASE("SQLite foreign keys are disabled by default", "[sqlite][foreignkeys]")
|
||||
TEST_CASE("SQLite foreign keys", "[sqlite][foreignkeys]")
|
||||
{
|
||||
soci::session sql(backEnd, connectString);
|
||||
|
||||
SetupForeignKeys setupForeignKeys(sql);
|
||||
|
||||
sql << "delete from parent where id = 1";
|
||||
SECTION("Off")
|
||||
{
|
||||
sql << "pragma foreign_keys = off";
|
||||
|
||||
int parent = 0;
|
||||
sql << "select parent from child where id = 100 ", into(parent);
|
||||
sql << "delete from parent where id = 1";
|
||||
|
||||
CHECK(parent == 1);
|
||||
}
|
||||
int parent = 0;
|
||||
sql << "select parent from child where id = 100 ", into(parent);
|
||||
CHECK(parent == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("SQLite foreign keys are enabled by foreign_keys option", "[sqlite][foreignkeys]")
|
||||
{
|
||||
soci::session sql(backEnd, "dbname=:memory: foreign_keys=on");
|
||||
SECTION("On")
|
||||
{
|
||||
sql << "pragma foreign_keys = on";
|
||||
|
||||
SetupForeignKeys setupForeignKeys(sql);
|
||||
|
||||
CHECK_THROWS_WITH(sql << "delete from parent where id = 1",
|
||||
"sqlite3_statement_backend::loadOne: FOREIGN KEY "
|
||||
"constraint failed while executing "
|
||||
"\"delete from parent where id = 1\".");
|
||||
CHECK_THROWS_WITH(sql << "delete from parent where id = 1",
|
||||
"sqlite3_statement_backend::loadOne: FOREIGN KEY "
|
||||
"constraint failed while executing "
|
||||
"\"delete from parent where id = 1\".");
|
||||
}
|
||||
}
|
||||
|
||||
class SetupAutoIncrementTable
|
||||
@@ -949,7 +951,9 @@ public:
|
||||
// database if nothing is specified on the command line.
|
||||
if (argFromCommandLine.empty())
|
||||
{
|
||||
argFromCommandLine = ":memory:";
|
||||
// Enable FKs by default to make SQLite behaviour more compatible
|
||||
// with the other backends.
|
||||
argFromCommandLine = "db=:memory: foreign_keys=on";
|
||||
}
|
||||
|
||||
return test_context_base::initialize_connect_string(argFromCommandLine);
|
||||
|
||||
Reference in New Issue
Block a user