@@ -76,6 +76,19 @@ void TestTable::withoutRowid()
7676 " ) WITHOUT ROWID;" ));
7777}
7878
79+ void TestTable::foreignKeys ()
80+ {
81+ Table tt (" testtable" );
82+ FieldPtr f = FieldPtr (new Field (" a" , " integer" ));
83+ f->setForeignKey (" b(c)" );
84+ tt.addField (f);
85+
86+ QCOMPARE (tt.sql (), QString (" CREATE TABLE `testtable` (\n "
87+ " \t `a`\t integer,\n "
88+ " \t FOREIGN KEY(`a`) REFERENCES b(c)\n "
89+ " );" ));
90+ }
91+
7992void TestTable::parseSQL ()
8093{
8194 QString sSQL = " create TABLE hero (\n "
@@ -224,6 +237,21 @@ void TestTable::parseSQLEscapedQuotes()
224237 QCOMPARE (tab.fields ().at (0 )->defaultValue (), QString (" 'a''a'" ));
225238}
226239
240+ void TestTable::parseSQLForeignKeys ()
241+ {
242+ 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);" ;
243+
244+ Table tab = Table::parseSQL (sql).first ;
245+
246+ QCOMPARE (tab.name (), QString (" foreign_key_test" ));
247+ QCOMPARE (tab.fields ().at (0 )->name (), QString (" a" ));
248+ QCOMPARE (tab.fields ().at (0 )->type (), QString (" int" ));
249+ QCOMPARE (tab.fields ().at (0 )->foreignKey (), QString (" x" ));
250+ QCOMPARE (tab.fields ().at (1 )->name (), QString (" b" ));
251+ QCOMPARE (tab.fields ().at (1 )->type (), QString (" int" ));
252+ QCOMPARE (tab.fields ().at (1 )->foreignKey (), QString (" w ( z ) on delete set null" ));
253+ }
254+
227255void TestTable::createTableWithIn ()
228256{
229257 QString sSQL = " CREATE TABLE not_working("
0 commit comments