tests: Add tests for foreign key parsing

This commit is contained in:
Martin Kleusberg
2014-11-06 18:29:34 +01:00
parent f2c3c2b1a4
commit 4b7766a0fe
2 changed files with 30 additions and 0 deletions

View File

@@ -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("

View File

@@ -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();
};