forked from qt-creator/qt-creator
Sqlite: Strict table support
With Sqlite 3.37 strict tables are introduced: https://www.sqlite.org/stricttables.html The introduce strict column types. So you can not add a text to an integer column anymore. Additionally they introduce the "any" column which is a dynamic type. Change-Id: I43c0410821aa154e7de83e24bd221a232f98e910 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -31,18 +31,19 @@ namespace {
|
||||
|
||||
using Sqlite::ColumnType;
|
||||
using Sqlite::ConstraintType;
|
||||
using Sqlite::JournalMode;
|
||||
using Sqlite::OpenMode;
|
||||
using Column = Sqlite::Column;
|
||||
using Sqlite::Enforment;
|
||||
using Sqlite::ForeignKey;
|
||||
using Sqlite::ForeignKeyAction;
|
||||
using Sqlite::SqliteColumns;
|
||||
using Sqlite::JournalMode;
|
||||
using Sqlite::OpenMode;
|
||||
using Sqlite::StrictColumnType;
|
||||
|
||||
class SqliteColumn : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
Sqlite::Column column;
|
||||
using Column = Sqlite::Column;
|
||||
|
||||
Column column;
|
||||
};
|
||||
|
||||
TEST_F(SqliteColumn, DefaultConstruct)
|
||||
@@ -50,7 +51,7 @@ TEST_F(SqliteColumn, DefaultConstruct)
|
||||
ASSERT_THAT(column,
|
||||
AllOf(Field(&Column::name, IsEmpty()),
|
||||
Field(&Column::tableName, IsEmpty()),
|
||||
Field(&Column::type, ColumnType::Numeric),
|
||||
Field(&Column::type, ColumnType::None),
|
||||
Field(&Column::constraints, IsEmpty())));
|
||||
}
|
||||
|
||||
@@ -66,20 +67,20 @@ TEST_F(SqliteColumn, Clear)
|
||||
ASSERT_THAT(column,
|
||||
AllOf(Field(&Column::name, IsEmpty()),
|
||||
Field(&Column::tableName, IsEmpty()),
|
||||
Field(&Column::type, ColumnType::Numeric),
|
||||
Field(&Column::type, ColumnType::None),
|
||||
Field(&Column::constraints, IsEmpty())));
|
||||
}
|
||||
|
||||
TEST_F(SqliteColumn, Constructor)
|
||||
{
|
||||
column = Sqlite::Column{"table",
|
||||
"column",
|
||||
ColumnType::Text,
|
||||
{ForeignKey{"referencedTable",
|
||||
"referencedColumn",
|
||||
ForeignKeyAction::SetNull,
|
||||
ForeignKeyAction::Cascade,
|
||||
Enforment::Deferred}}};
|
||||
column = Column{"table",
|
||||
"column",
|
||||
ColumnType::Text,
|
||||
{ForeignKey{"referencedTable",
|
||||
"referencedColumn",
|
||||
ForeignKeyAction::SetNull,
|
||||
ForeignKeyAction::Cascade,
|
||||
Enforment::Deferred}}};
|
||||
|
||||
ASSERT_THAT(column,
|
||||
AllOf(Field(&Column::name, Eq("column")),
|
||||
@@ -96,14 +97,14 @@ TEST_F(SqliteColumn, Constructor)
|
||||
|
||||
TEST_F(SqliteColumn, FlatConstructor)
|
||||
{
|
||||
column = Sqlite::Column{"table",
|
||||
"column",
|
||||
ColumnType::Text,
|
||||
{ForeignKey{"referencedTable",
|
||||
"referencedColumn",
|
||||
ForeignKeyAction::SetNull,
|
||||
ForeignKeyAction::Cascade,
|
||||
Enforment::Deferred}}};
|
||||
column = Column{"table",
|
||||
"column",
|
||||
ColumnType::Text,
|
||||
{ForeignKey{"referencedTable",
|
||||
"referencedColumn",
|
||||
ForeignKeyAction::SetNull,
|
||||
ForeignKeyAction::Cascade,
|
||||
Enforment::Deferred}}};
|
||||
|
||||
ASSERT_THAT(column,
|
||||
AllOf(Field(&Column::name, Eq("column")),
|
||||
@@ -118,4 +119,85 @@ TEST_F(SqliteColumn, FlatConstructor)
|
||||
Field(&ForeignKey::enforcement, Enforment::Deferred)))))));
|
||||
}
|
||||
|
||||
class SqliteStrictColumn : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
using Column = Sqlite::StrictColumn;
|
||||
|
||||
Column column;
|
||||
};
|
||||
|
||||
TEST_F(SqliteStrictColumn, DefaultConstruct)
|
||||
{
|
||||
ASSERT_THAT(column,
|
||||
AllOf(Field(&Column::name, IsEmpty()),
|
||||
Field(&Column::tableName, IsEmpty()),
|
||||
Field(&Column::type, StrictColumnType::Any),
|
||||
Field(&Column::constraints, IsEmpty())));
|
||||
}
|
||||
|
||||
TEST_F(SqliteStrictColumn, Clear)
|
||||
{
|
||||
column.name = "foo";
|
||||
column.name = "foo";
|
||||
column.type = StrictColumnType::Text;
|
||||
column.constraints = {Sqlite::PrimaryKey{}};
|
||||
|
||||
column.clear();
|
||||
|
||||
ASSERT_THAT(column,
|
||||
AllOf(Field(&Column::name, IsEmpty()),
|
||||
Field(&Column::tableName, IsEmpty()),
|
||||
Field(&Column::type, StrictColumnType::Any),
|
||||
Field(&Column::constraints, IsEmpty())));
|
||||
}
|
||||
|
||||
TEST_F(SqliteStrictColumn, Constructor)
|
||||
{
|
||||
column = Column{"table",
|
||||
"column",
|
||||
StrictColumnType::Text,
|
||||
{ForeignKey{"referencedTable",
|
||||
"referencedColumn",
|
||||
ForeignKeyAction::SetNull,
|
||||
ForeignKeyAction::Cascade,
|
||||
Enforment::Deferred}}};
|
||||
|
||||
ASSERT_THAT(column,
|
||||
AllOf(Field(&Column::name, Eq("column")),
|
||||
Field(&Column::tableName, Eq("table")),
|
||||
Field(&Column::type, StrictColumnType::Text),
|
||||
Field(&Column::constraints,
|
||||
ElementsAre(VariantWith<ForeignKey>(
|
||||
AllOf(Field(&ForeignKey::table, Eq("referencedTable")),
|
||||
Field(&ForeignKey::column, Eq("referencedColumn")),
|
||||
Field(&ForeignKey::updateAction, ForeignKeyAction::SetNull),
|
||||
Field(&ForeignKey::deleteAction, ForeignKeyAction::Cascade),
|
||||
Field(&ForeignKey::enforcement, Enforment::Deferred)))))));
|
||||
}
|
||||
|
||||
TEST_F(SqliteStrictColumn, FlatConstructor)
|
||||
{
|
||||
column = Column{"table",
|
||||
"column",
|
||||
StrictColumnType::Text,
|
||||
{ForeignKey{"referencedTable",
|
||||
"referencedColumn",
|
||||
ForeignKeyAction::SetNull,
|
||||
ForeignKeyAction::Cascade,
|
||||
Enforment::Deferred}}};
|
||||
|
||||
ASSERT_THAT(column,
|
||||
AllOf(Field(&Column::name, Eq("column")),
|
||||
Field(&Column::tableName, Eq("table")),
|
||||
Field(&Column::type, StrictColumnType::Text),
|
||||
Field(&Column::constraints,
|
||||
ElementsAre(VariantWith<ForeignKey>(
|
||||
AllOf(Field(&ForeignKey::table, Eq("referencedTable")),
|
||||
Field(&ForeignKey::column, Eq("referencedColumn")),
|
||||
Field(&ForeignKey::updateAction, ForeignKeyAction::SetNull),
|
||||
Field(&ForeignKey::deleteAction, ForeignKeyAction::Cascade),
|
||||
Field(&ForeignKey::enforcement, Enforment::Deferred)))))));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user