mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-19 10:20:17 -06:00
tests: Add tests for foreign key parsing
This commit is contained in:
@@ -76,6 +76,19 @@ void TestTable::withoutRowid()
|
||||
") WITHOUT ROWID;"));
|
||||
}
|
||||
|
||||
void TestTable::foreignKeys()
|
||||
{
|
||||
Table tt("testtable");
|
||||
FieldPtr f = FieldPtr(new Field("a", "integer"));
|
||||
f->setForeignKey("b(c)");
|
||||
tt.addField(f);
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\t`a`\tinteger,\n"
|
||||
"\tFOREIGN KEY(`a`) REFERENCES b(c)\n"
|
||||
");"));
|
||||
}
|
||||
|
||||
void TestTable::parseSQL()
|
||||
{
|
||||
QString sSQL = "create TABLE hero (\n"
|
||||
@@ -224,6 +237,21 @@ void TestTable::parseSQLEscapedQuotes()
|
||||
QCOMPARE(tab.fields().at(0)->defaultValue(), QString("'a''a'"));
|
||||
}
|
||||
|
||||
void TestTable::parseSQLForeignKeys()
|
||||
{
|
||||
QString sql = "CREATE TABLE foreign_key_test(a int, b int, foreign key (a) references x, foreign key (b) references w(z) on delete set null);";
|
||||
|
||||
Table tab = Table::parseSQL(sql).first;
|
||||
|
||||
QCOMPARE(tab.name(), QString("foreign_key_test"));
|
||||
QCOMPARE(tab.fields().at(0)->name(), QString("a"));
|
||||
QCOMPARE(tab.fields().at(0)->type(), QString("int"));
|
||||
QCOMPARE(tab.fields().at(0)->foreignKey(), QString("x"));
|
||||
QCOMPARE(tab.fields().at(1)->name(), QString("b"));
|
||||
QCOMPARE(tab.fields().at(1)->type(), QString("int"));
|
||||
QCOMPARE(tab.fields().at(1)->foreignKey(), QString("w ( z ) on delete set null"));
|
||||
}
|
||||
|
||||
void TestTable::createTableWithIn()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE not_working("
|
||||
|
||||
@@ -11,6 +11,7 @@ private slots:
|
||||
void autoincrement();
|
||||
void notnull();
|
||||
void withoutRowid();
|
||||
void foreignKeys();
|
||||
|
||||
void parseSQL();
|
||||
void parseSQLdefaultexpr();
|
||||
@@ -21,6 +22,7 @@ private slots:
|
||||
void parseSQLWithoutRowid();
|
||||
void parseNonASCIIChars();
|
||||
void parseSQLEscapedQuotes();
|
||||
void parseSQLForeignKeys();
|
||||
void createTableWithIn();
|
||||
void createTableWithNotLikeConstraint();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user