@@ -13,6 +13,7 @@ private slots:
1313 void notnull ();
1414
1515 void parseSQL ();
16+ void parseSQLdefaultexpr ();
1617 void parseSQLMultiPk ();
1718};
1819
@@ -73,7 +74,7 @@ void TestTable::notnull()
7374
7475void TestTable::parseSQL ()
7576{
76- QString sSQL = " CREATE TABLE hero (\n "
77+ QString sSQL = " create TABLE hero (\n "
7778 " \t id integer PRIMARY KEY AUTOINCREMENT,\n "
7879 " \t name text NOT NULL DEFAULT 'xxxx',\n "
7980 " \t info VARCHAR(255) CHECK (info == x)\n "
@@ -92,8 +93,35 @@ void TestTable::parseSQL()
9293
9394 QVERIFY (tab.fields ().at (0 )->autoIncrement ());
9495 QVERIFY (tab.fields ().at (1 )->notnull ());
96+ QCOMPARE (tab.fields ().at (1 )->defaultValue (), QString (" 'xxxx'" ));
9597 QCOMPARE (tab.fields ().at (1 )->check (), QString (" " ));
96- QCOMPARE (tab.fields ().at (2 )->check (), QString (" (info==x)" ));
98+ QCOMPARE (tab.fields ().at (2 )->check (), QString (" info==x" ));
99+
100+ QVERIFY (tab.primarykey ().contains (tab.fields ().at (0 )));
101+ }
102+
103+ void TestTable::parseSQLdefaultexpr ()
104+ {
105+ QString sSQL = " CREATE TABLE chtest(\n "
106+ " id integer primary key,\n "
107+ " dumpytext text default('axa') CHECK(dumpytext == \" aa\" ),\n "
108+ " zoi integer)" ;
109+
110+ Table tab = Table::parseSQL (sSQL );
111+
112+ QVERIFY (tab.name () == " chtest" );
113+ QVERIFY (tab.fields ().at (0 )->name () == " id" );
114+ QVERIFY (tab.fields ().at (1 )->name () == " dumpytext" );
115+ QVERIFY (tab.fields ().at (2 )->name () == " zoi" );
116+
117+ QVERIFY (tab.fields ().at (0 )->type () == " integer" );
118+ QVERIFY (tab.fields ().at (1 )->type () == " text" );
119+ QVERIFY (tab.fields ().at (2 )->type () == " integer" );
120+
121+ QCOMPARE (tab.fields ().at (1 )->defaultValue (), QString (" ('axa')" ));
122+ QCOMPARE (tab.fields ().at (1 )->check (), QString (" dumpytext==\" aa\" " ));
123+ QCOMPARE (tab.fields ().at (2 )->defaultValue (), QString (" " ));
124+ QCOMPARE (tab.fields ().at (2 )->check (), QString (" " ));
97125
98126 QVERIFY (tab.primarykey ().contains (tab.fields ().at (0 )));
99127}
0 commit comments