Skip to content

Commit 1f8686d

Browse files
committed
Add tests for the new 'without rowid' parsing
Add tests for the 'without rowid' parsing in our SQL grammar added in commit 3761acf.
1 parent 3761acf commit 1f8686d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/tests/testsqlobjects.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ void TestTable::notnull()
6060
");"));
6161
}
6262

63+
void TestTable::withoutRowid()
64+
{
65+
Table tt("testtable");
66+
FieldPtr f = FieldPtr(new Field("a", "integer"));
67+
f->setPrimaryKey(true);
68+
f->setAutoIncrement(true);
69+
tt.addField(f);
70+
tt.addField(FieldPtr(new Field("b", "integer")));
71+
tt.setRowidColumn("a");
72+
73+
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
74+
"\t`a`\tinteger PRIMARY KEY AUTOINCREMENT,\n"
75+
"\t`b`\tinteger\n"
76+
") WITHOUT ROWID;"));
77+
}
78+
6379
void TestTable::parseSQL()
6480
{
6581
QString sSQL = "create TABLE hero (\n"
@@ -71,6 +87,7 @@ void TestTable::parseSQL()
7187
Table tab = Table::parseSQL(sSQL);
7288

7389
QVERIFY(tab.name() == "hero");
90+
QVERIFY(tab.rowidColumn() == "rowid");
7491
QVERIFY(tab.fields().at(0)->name() == "id");
7592
QVERIFY(tab.fields().at(1)->name() == "name");
7693
QVERIFY(tab.fields().at(2)->name() == "info");
@@ -85,8 +102,6 @@ void TestTable::parseSQL()
85102
QCOMPARE(tab.fields().at(1)->defaultValue(), QString("'xxxx'"));
86103
QCOMPARE(tab.fields().at(1)->check(), QString(""));
87104
QCOMPARE(tab.fields().at(2)->check(), QString("info=='x'"));
88-
89-
90105
}
91106

92107
void TestTable::parseSQLdefaultexpr()
@@ -170,6 +185,16 @@ void TestTable::parseSQLKeywordInIdentifier()
170185
QVERIFY(tab.fields().at(1)->name() == "if");
171186
}
172187

188+
void TestTable::parseSQLWithoutRowid()
189+
{
190+
QString sSQL = "CREATE TABLE test(a integer primary key, b integer) WITHOUT ROWID;";
191+
192+
Table tab = Table::parseSQL(sSQL);
193+
194+
QVERIFY(tab.fields().at(tab.findPk())->name() == "a");
195+
QVERIFY(tab.rowidColumn() == "a");
196+
}
197+
173198
void TestTable::parseNonASCIIChars()
174199
{
175200
QString sSQL = "CREATE TABLE `lösung` ("

src/tests/testsqlobjects.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ private slots:
77
void sqlOutput();
88
void autoincrement();
99
void notnull();
10+
void withoutRowid();
1011

1112
void parseSQL();
1213
void parseSQLdefaultexpr();
1314
void parseSQLMultiPk();
1415
void parseSQLForeignKey();
1516
void parseSQLSingleQuotes();
1617
void parseSQLKeywordInIdentifier();
18+
void parseSQLWithoutRowid();
1719
void parseNonASCIIChars();
1820
};
1921

0 commit comments

Comments
 (0)