Skip to content

Commit

Permalink
Add tests for the new 'without rowid' parsing
Browse files Browse the repository at this point in the history
Add tests for the 'without rowid' parsing in our SQL grammar added in
commit 3761acf.
  • Loading branch information
MKleusberg committed May 9, 2014
1 parent 3761acf commit 1f8686d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/tests/testsqlobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ void TestTable::notnull()
");"));
}

void TestTable::withoutRowid()
{
Table tt("testtable");
FieldPtr f = FieldPtr(new Field("a", "integer"));
f->setPrimaryKey(true);
f->setAutoIncrement(true);
tt.addField(f);
tt.addField(FieldPtr(new Field("b", "integer")));
tt.setRowidColumn("a");

QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
"\t`a`\tinteger PRIMARY KEY AUTOINCREMENT,\n"
"\t`b`\tinteger\n"
") WITHOUT ROWID;"));
}

void TestTable::parseSQL()
{
QString sSQL = "create TABLE hero (\n"
Expand All @@ -71,6 +87,7 @@ void TestTable::parseSQL()
Table tab = Table::parseSQL(sSQL);

QVERIFY(tab.name() == "hero");
QVERIFY(tab.rowidColumn() == "rowid");
QVERIFY(tab.fields().at(0)->name() == "id");
QVERIFY(tab.fields().at(1)->name() == "name");
QVERIFY(tab.fields().at(2)->name() == "info");
Expand All @@ -85,8 +102,6 @@ void TestTable::parseSQL()
QCOMPARE(tab.fields().at(1)->defaultValue(), QString("'xxxx'"));
QCOMPARE(tab.fields().at(1)->check(), QString(""));
QCOMPARE(tab.fields().at(2)->check(), QString("info=='x'"));


}

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

void TestTable::parseSQLWithoutRowid()
{
QString sSQL = "CREATE TABLE test(a integer primary key, b integer) WITHOUT ROWID;";

Table tab = Table::parseSQL(sSQL);

QVERIFY(tab.fields().at(tab.findPk())->name() == "a");
QVERIFY(tab.rowidColumn() == "a");
}

void TestTable::parseNonASCIIChars()
{
QString sSQL = "CREATE TABLE `lösung` ("
Expand Down
2 changes: 2 additions & 0 deletions src/tests/testsqlobjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ private slots:
void sqlOutput();
void autoincrement();
void notnull();
void withoutRowid();

void parseSQL();
void parseSQLdefaultexpr();
void parseSQLMultiPk();
void parseSQLForeignKey();
void parseSQLSingleQuotes();
void parseSQLKeywordInIdentifier();
void parseSQLWithoutRowid();
void parseNonASCIIChars();
};

0 comments on commit 1f8686d

Please sign in to comment.