mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-04-26 14:39:01 -05:00
Use some more SQL containers instead of their Qt equivalents
This commit is contained in:
+25
-19
@@ -4,7 +4,7 @@
|
||||
#include <QtTest/QTest>
|
||||
#include <QCoreApplication>
|
||||
#include <QTextStream>
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
|
||||
#include "csvparser.h"
|
||||
#include "TestImport.h"
|
||||
@@ -27,7 +27,7 @@ void TestImport::csvImport()
|
||||
QFETCH(char, quote);
|
||||
QFETCH(QString, encoding);
|
||||
QFETCH(int, numfields);
|
||||
QFETCH(QVector<QVector<QByteArray>>, result);
|
||||
QFETCH(std::vector<std::vector<QByteArray>>, result);
|
||||
|
||||
// Create temporary CSV file
|
||||
QTemporaryFile file;
|
||||
@@ -44,10 +44,10 @@ void TestImport::csvImport()
|
||||
QTextStream tstream(&file);
|
||||
tstream.setCodec(encoding.toUtf8());
|
||||
|
||||
QVector<QVector<QByteArray>> parsedCsv;
|
||||
std::vector<std::vector<QByteArray>> parsedCsv;
|
||||
int parsedCsvColumns = 0;
|
||||
csvparser.parse([&parsedCsv, &parsedCsvColumns](size_t /*rowNum*/, const CSVRow& data) -> bool {
|
||||
QVector<QByteArray> row;
|
||||
std::vector<QByteArray> row;
|
||||
for(size_t i=0;i<data.num_fields;i++)
|
||||
row.push_back(QByteArray(data.fields[i].data, data.fields[i].data_length));
|
||||
parsedCsv.push_back(row);
|
||||
@@ -75,12 +75,13 @@ void TestImport::csvImport_data()
|
||||
QTest::addColumn<char>("quote");
|
||||
QTest::addColumn<QString>("encoding");
|
||||
QTest::addColumn<int>("numfields");
|
||||
QTest::addColumn<QVector<QVector<QByteArray>>>("result");
|
||||
QTest::addColumn<std::vector<std::vector<QByteArray>>>("result");
|
||||
|
||||
QVector<QVector<QByteArray>> result;
|
||||
result.append(QVector<QByteArray>() << "a" << "b" << "c");
|
||||
result.append(QVector<QByteArray>() << "d" << "e" << "f");
|
||||
result.append(QVector<QByteArray>() << "g" << "h" << "i");
|
||||
std::vector<std::vector<QByteArray>> result{
|
||||
{"a", "b", "c"},
|
||||
{"d", "e", "f"},
|
||||
{"g", "h", "i"}
|
||||
};
|
||||
QTest::newRow("commas_noquotes") << "a,b,c\nd,e,f\ng,h,i\n"
|
||||
<< ','
|
||||
<< static_cast<char>(0)
|
||||
@@ -119,11 +120,13 @@ void TestImport::csvImport_data()
|
||||
<< result;
|
||||
|
||||
result.clear();
|
||||
result.append(QVector<QByteArray>() << "a" << "b" << "");
|
||||
result.append(QVector<QByteArray>() << "c" << "");
|
||||
result.append(QVector<QByteArray>() << "d" << "" << "e");
|
||||
result.append(QVector<QByteArray>() << "");
|
||||
result.append(QVector<QByteArray>() << "" << "" << "f");
|
||||
result = {
|
||||
{"a", "b", ""},
|
||||
{"c", ""},
|
||||
{"d", "", "e"},
|
||||
{""},
|
||||
{"", "", "f"}
|
||||
};
|
||||
QTest::newRow("emptyvalues") << "a,b,\nc,\nd,,e\n\n,,f"
|
||||
<< ','
|
||||
<< static_cast<char>(0)
|
||||
@@ -132,7 +135,7 @@ void TestImport::csvImport_data()
|
||||
<< result;
|
||||
|
||||
result.clear();
|
||||
result.append(QVector<QByteArray>() << "a" << "b" << "c");
|
||||
result = {{"a", "b", "c"}};
|
||||
QTest::newRow("oneline") << "a,b,c"
|
||||
<< ','
|
||||
<< static_cast<char>(0)
|
||||
@@ -141,8 +144,11 @@ void TestImport::csvImport_data()
|
||||
<< result;
|
||||
|
||||
result.clear();
|
||||
result.append(QVector<QByteArray>() << "a,a\"" << "b" << "c");
|
||||
result.append(QVector<QByteArray>() << "d" << "e" << "\"\"f,f");
|
||||
result = {
|
||||
{"a,a\"", "b", "c"},
|
||||
{"d", "e", "\"\"f,f"}
|
||||
};
|
||||
|
||||
QTest::newRow("manyquotes") << "\"a,a\"\"\",\"b\",\"c\"\n\"d\",\"e\",\"\"\"\"\"f,f\"\n"
|
||||
<< ','
|
||||
<< '"'
|
||||
@@ -151,7 +157,7 @@ void TestImport::csvImport_data()
|
||||
<< result;
|
||||
|
||||
result.clear();
|
||||
result.append(QVector<QByteArray>() << QByteArray("\xC2\xAE") << QByteArray("\xC9\x85") << QByteArray("\xC6\x89"));
|
||||
result = {{QByteArray("\xC2\xAE"), QByteArray("\xC9\x85"), QByteArray("\xC6\x89")}};
|
||||
QString csv = QString::fromUtf8("\xC2\xAE") + "," + QString::fromUtf8("\xC9\x85") + "," + QString::fromUtf8("\xC6\x89") + "\n";
|
||||
QTest::newRow("utf8chars") << csv
|
||||
<< ','
|
||||
@@ -161,7 +167,7 @@ void TestImport::csvImport_data()
|
||||
<< result;
|
||||
|
||||
result.clear();
|
||||
result.append(QVector<QByteArray>() << QByteArray("\u4E18") << QByteArray("\u4E26") << QByteArray("\u4E4B"));
|
||||
result = {{QByteArray("\u4E18"), QByteArray("\u4E26"), QByteArray("\u4E4B")}};
|
||||
QString csv2 = QString::fromUtf8("\u4E18") + "," + QString::fromUtf8("\u4E26") + "," + QString::fromUtf8("\u4E4B") + "\n";
|
||||
QTest::newRow("utf16chars") << csv2
|
||||
<< ','
|
||||
|
||||
+155
-155
@@ -30,12 +30,12 @@ void TestTable::sqlOutput()
|
||||
tt.fields.push_back(fkm);
|
||||
tt.addConstraint({f.name(), fkm.name()}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"id\"\tinteger,\n"
|
||||
"\t\"car\"\ttext,\n"
|
||||
"\t\"km\"\tinteger CHECK(km > 1000),\n"
|
||||
"\tPRIMARY KEY(\"id\",\"km\")\n"
|
||||
");"));
|
||||
QCOMPARE(tt.sql(), "CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"id\"\tinteger,\n"
|
||||
"\t\"car\"\ttext,\n"
|
||||
"\t\"km\"\tinteger CHECK(km > 1000),\n"
|
||||
"\tPRIMARY KEY(\"id\",\"km\")\n"
|
||||
");");
|
||||
}
|
||||
|
||||
void TestTable::sqlGraveAccentOutput()
|
||||
@@ -49,12 +49,12 @@ void TestTable::sqlGraveAccentOutput()
|
||||
tt.addConstraint({f.name(), fkm.name()}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
sqlb::setIdentifierQuoting(sqlb::GraveAccents);
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\t`id`\tinteger,\n"
|
||||
"\t`car`\ttext,\n"
|
||||
"\t`km`\tinteger CHECK(km > 1000),\n"
|
||||
"\tPRIMARY KEY(`id`,`km`)\n"
|
||||
");"));
|
||||
QCOMPARE(tt.sql(), "CREATE TABLE `testtable` (\n"
|
||||
"\t`id`\tinteger,\n"
|
||||
"\t`car`\ttext,\n"
|
||||
"\t`km`\tinteger CHECK(km > 1000),\n"
|
||||
"\tPRIMARY KEY(`id`,`km`)\n"
|
||||
");");
|
||||
|
||||
sqlb::setIdentifierQuoting(sqlb::DoubleQuotes);
|
||||
}
|
||||
@@ -71,12 +71,12 @@ void TestTable::sqlSquareBracketsOutput()
|
||||
tt.addConstraint({f.name(), fkm.name()}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
sqlb::setIdentifierQuoting(sqlb::SquareBrackets);
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE [testtable] (\n"
|
||||
"\t[id]\tinteger,\n"
|
||||
"\t[car]\ttext,\n"
|
||||
"\t[km]\tinteger CHECK(km > 1000),\n"
|
||||
"\tPRIMARY KEY([id],[km])\n"
|
||||
");"));
|
||||
QCOMPARE(tt.sql(), "CREATE TABLE [testtable] (\n"
|
||||
"\t[id]\tinteger,\n"
|
||||
"\t[car]\ttext,\n"
|
||||
"\t[km]\tinteger CHECK(km > 1000),\n"
|
||||
"\tPRIMARY KEY([id],[km])\n"
|
||||
");");
|
||||
|
||||
sqlb::setIdentifierQuoting(sqlb::DoubleQuotes);
|
||||
}
|
||||
@@ -92,11 +92,11 @@ void TestTable::autoincrement()
|
||||
tt.fields.push_back(fkm);
|
||||
tt.addConstraint({f.name()}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"id\"\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\t\"car\"\ttext,\n"
|
||||
"\t\"km\"\tinteger\n"
|
||||
");"));
|
||||
QCOMPARE(tt.sql(), "CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"id\"\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\t\"car\"\ttext,\n"
|
||||
"\t\"km\"\tinteger\n"
|
||||
");");
|
||||
}
|
||||
|
||||
void TestTable::notnull()
|
||||
@@ -110,11 +110,11 @@ void TestTable::notnull()
|
||||
tt.fields.push_back(fkm);
|
||||
tt.addConstraint({f.name()}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"id\"\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\t\"car\"\ttext NOT NULL,\n"
|
||||
"\t\"km\"\tinteger\n"
|
||||
");"));
|
||||
QCOMPARE(tt.sql(), "CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"id\"\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\t\"car\"\ttext NOT NULL,\n"
|
||||
"\t\"km\"\tinteger\n"
|
||||
");");
|
||||
}
|
||||
|
||||
void TestTable::withoutRowid()
|
||||
@@ -127,10 +127,10 @@ void TestTable::withoutRowid()
|
||||
tt.setWithoutRowidTable(true);
|
||||
tt.addConstraint({f.name()}, ConstraintPtr(new PrimaryKeyConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"a\"\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\t\"b\"\tinteger\n"
|
||||
") WITHOUT ROWID;"));
|
||||
QCOMPARE(tt.sql(), "CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"a\"\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\t\"b\"\tinteger\n"
|
||||
") WITHOUT ROWID;");
|
||||
}
|
||||
|
||||
void TestTable::foreignKeys()
|
||||
@@ -138,12 +138,12 @@ void TestTable::foreignKeys()
|
||||
Table tt("testtable");
|
||||
Field f("a", "integer");
|
||||
tt.fields.push_back(f);
|
||||
tt.addConstraint({f.name()}, sqlb::ConstraintPtr(new sqlb::ForeignKeyClause("b", QStringList("c"))));
|
||||
tt.addConstraint({f.name()}, sqlb::ConstraintPtr(new sqlb::ForeignKeyClause("b", sqlb::StringVector{"c"})));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"a\"\tinteger,\n"
|
||||
"\tFOREIGN KEY(\"a\") REFERENCES \"b\"(\"c\")\n"
|
||||
");"));
|
||||
QCOMPARE(tt.sql(), "CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"a\"\tinteger,\n"
|
||||
"\tFOREIGN KEY(\"a\") REFERENCES \"b\"(\"c\")\n"
|
||||
");");
|
||||
}
|
||||
|
||||
void TestTable::uniqueConstraint()
|
||||
@@ -158,21 +158,21 @@ void TestTable::uniqueConstraint()
|
||||
tt.fields.push_back(f3);
|
||||
tt.addConstraint({f2.name(), f3.name()}, sqlb::ConstraintPtr(new sqlb::UniqueConstraint()));
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"a\"\tinteger UNIQUE,\n"
|
||||
"\t\"b\"\tinteger,\n"
|
||||
"\t\"c\"\tinteger,\n"
|
||||
"\tUNIQUE(\"b\",\"c\")\n"
|
||||
");"));
|
||||
QCOMPARE(tt.sql(), "CREATE TABLE \"testtable\" (\n"
|
||||
"\t\"a\"\tinteger UNIQUE,\n"
|
||||
"\t\"b\"\tinteger,\n"
|
||||
"\t\"c\"\tinteger,\n"
|
||||
"\tUNIQUE(\"b\",\"c\")\n"
|
||||
");");
|
||||
}
|
||||
|
||||
void TestTable::parseSQL()
|
||||
{
|
||||
QString sSQL = "create TABLE hero (\n"
|
||||
"\tid integer PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\tname text NOT NULL DEFAULT 'xxxx',\n"
|
||||
"\tinfo VARCHAR(255) CHECK (info == 'x')\n"
|
||||
");";
|
||||
std::string sSQL = "create TABLE hero (\n"
|
||||
"\tid integer PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\tname text NOT NULL DEFAULT 'xxxx',\n"
|
||||
"\tinfo VARCHAR(255) CHECK (info == 'x')\n"
|
||||
");";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -184,59 +184,59 @@ void TestTable::parseSQL()
|
||||
|
||||
QCOMPARE(tab.fields.at(0).type(), "integer");
|
||||
QCOMPARE(tab.fields.at(1).type(), "text");
|
||||
QCOMPARE(tab.fields.at(2).type(), QString("VARCHAR(255)"));
|
||||
QCOMPARE(tab.fields.at(2).type(), "VARCHAR(255)");
|
||||
|
||||
QStringList pk = tab.primaryKey();
|
||||
sqlb::StringVector pk = tab.primaryKey();
|
||||
QVERIFY(tab.fields.at(0).autoIncrement());
|
||||
QCOMPARE(pk.size(), 1);
|
||||
QCOMPARE(pk.at(0), tab.fields.at(0).name());
|
||||
QVERIFY(tab.fields.at(1).notnull());
|
||||
QCOMPARE(tab.fields.at(1).defaultValue(), QString("'xxxx'"));
|
||||
QCOMPARE(tab.fields.at(1).check(), QString(""));
|
||||
QCOMPARE(tab.fields.at(2).check(), QString("info=='x'"));
|
||||
QCOMPARE(tab.fields.at(1).defaultValue(), "'xxxx'");
|
||||
QCOMPARE(tab.fields.at(1).check(), "");
|
||||
QCOMPARE(tab.fields.at(2).check(), "info=='x'");
|
||||
}
|
||||
|
||||
void TestTable::parseSQLdefaultexpr()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE chtest(\n"
|
||||
"id integer primary key,\n"
|
||||
"dumpytext text default('axa') CHECK(dumpytext == \"aa\"),\n"
|
||||
"date datetime default CURRENT_TIMESTAMP,"
|
||||
"zoi integer)";
|
||||
std::string sSQL = "CREATE TABLE chtest(\n"
|
||||
"id integer primary key,\n"
|
||||
"dumpytext text default('axa') CHECK(dumpytext == \"aa\"),\n"
|
||||
"date datetime default CURRENT_TIMESTAMP,"
|
||||
"zoi integer)";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
QCOMPARE(tab.name(), QString("chtest"));
|
||||
QCOMPARE(tab.fields.at(0).name(), QString("id"));
|
||||
QCOMPARE(tab.fields.at(1).name(), QString("dumpytext"));
|
||||
QCOMPARE(tab.fields.at(2).name(), QString("date"));
|
||||
QCOMPARE(tab.fields.at(3).name(), QString("zoi"));
|
||||
QCOMPARE(tab.name(), "chtest");
|
||||
QCOMPARE(tab.fields.at(0).name(), "id");
|
||||
QCOMPARE(tab.fields.at(1).name(), "dumpytext");
|
||||
QCOMPARE(tab.fields.at(2).name(), "date");
|
||||
QCOMPARE(tab.fields.at(3).name(), "zoi");
|
||||
|
||||
QCOMPARE(tab.fields.at(0).type(), QString("integer"));
|
||||
QCOMPARE(tab.fields.at(1).type(), QString("text"));
|
||||
QCOMPARE(tab.fields.at(2).type(), QString("datetime"));
|
||||
QCOMPARE(tab.fields.at(3).type(), QString("integer"));
|
||||
QCOMPARE(tab.fields.at(0).type(), "integer");
|
||||
QCOMPARE(tab.fields.at(1).type(), "text");
|
||||
QCOMPARE(tab.fields.at(2).type(), "datetime");
|
||||
QCOMPARE(tab.fields.at(3).type(), "integer");
|
||||
|
||||
QCOMPARE(tab.fields.at(1).defaultValue(), QString("('axa')"));
|
||||
QCOMPARE(tab.fields.at(1).check(), QString("dumpytext==\"aa\""));
|
||||
QCOMPARE(tab.fields.at(2).defaultValue(), QString("CURRENT_TIMESTAMP"));
|
||||
QCOMPARE(tab.fields.at(2).check(), QString(""));
|
||||
QCOMPARE(tab.fields.at(3).defaultValue(), QString(""));
|
||||
QCOMPARE(tab.fields.at(3).check(), QString(""));
|
||||
QCOMPARE(tab.fields.at(1).defaultValue(), "('axa')");
|
||||
QCOMPARE(tab.fields.at(1).check(), "dumpytext==\"aa\"");
|
||||
QCOMPARE(tab.fields.at(2).defaultValue(), "CURRENT_TIMESTAMP");
|
||||
QCOMPARE(tab.fields.at(2).check(), "");
|
||||
QCOMPARE(tab.fields.at(3).defaultValue(), "");
|
||||
QCOMPARE(tab.fields.at(3).check(), "");
|
||||
|
||||
QStringList pk = tab.primaryKey();
|
||||
sqlb::StringVector pk = tab.primaryKey();
|
||||
QCOMPARE(pk.size(), 1);
|
||||
QCOMPARE(pk.at(0), tab.fields.at(0).name());
|
||||
}
|
||||
|
||||
void TestTable::parseSQLMultiPk()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE hero (\n"
|
||||
"\tid1 integer,\n"
|
||||
"\tid2 integer,\n"
|
||||
"\tnonpkfield blob,\n"
|
||||
"PRIMARY KEY(\"id1\",\"id2\")\n"
|
||||
");";
|
||||
std::string sSQL = "CREATE TABLE hero (\n"
|
||||
"\tid1 integer,\n"
|
||||
"\tid2 integer,\n"
|
||||
"\tnonpkfield blob,\n"
|
||||
"PRIMARY KEY(\"id1\",\"id2\")\n"
|
||||
");";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -247,7 +247,7 @@ void TestTable::parseSQLMultiPk()
|
||||
QCOMPARE(tab.fields.at(0).type(), "integer");
|
||||
QCOMPARE(tab.fields.at(1).type(), "integer");
|
||||
|
||||
QStringList pk = tab.primaryKey();
|
||||
sqlb::StringVector pk = tab.primaryKey();
|
||||
QCOMPARE(pk.size(), 2);
|
||||
QCOMPARE(pk.at(0), tab.fields.at(0).name());
|
||||
QCOMPARE(pk.at(1), tab.fields.at(1).name());
|
||||
@@ -255,7 +255,7 @@ void TestTable::parseSQLMultiPk()
|
||||
|
||||
void TestTable::parseSQLForeignKey()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE grammar_test(id, test, FOREIGN KEY(test) REFERENCES other_table);";
|
||||
std::string sSQL = "CREATE TABLE grammar_test(id, test, FOREIGN KEY(test) REFERENCES other_table);";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -266,7 +266,7 @@ void TestTable::parseSQLForeignKey()
|
||||
|
||||
void TestTable::parseSQLSingleQuotes()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE 'test'('id','test');";
|
||||
std::string sSQL = "CREATE TABLE 'test'('id','test');";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -277,7 +277,7 @@ void TestTable::parseSQLSingleQuotes()
|
||||
|
||||
void TestTable::parseSQLSquareBrackets()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE [test]([id],[test]);";
|
||||
std::string sSQL = "CREATE TABLE [test]([id],[test]);";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -289,7 +289,7 @@ void TestTable::parseSQLSquareBrackets()
|
||||
|
||||
void TestTable::parseSQLKeywordInIdentifier()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE deffered(key integer primary key, if text);";
|
||||
std::string sSQL = "CREATE TABLE deffered(key integer primary key, if text);";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -301,9 +301,9 @@ void TestTable::parseSQLKeywordInIdentifier()
|
||||
|
||||
void TestTable::parseSQLSomeKeywordsInIdentifier()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE \"Average Number of Volunteers by Area of Work\" ("
|
||||
"`Area of Work` TEXT,"
|
||||
"`Average Number of Volunteers` INTEGER);";
|
||||
std::string sSQL = "CREATE TABLE \"Average Number of Volunteers by Area of Work\" ("
|
||||
"`Area of Work` TEXT,"
|
||||
"`Average Number of Volunteers` INTEGER);";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -314,7 +314,7 @@ void TestTable::parseSQLSomeKeywordsInIdentifier()
|
||||
|
||||
void TestTable::parseSQLWithoutRowid()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE test(a integer primary key, b integer) WITHOUT ROWID;";
|
||||
std::string sSQL = "CREATE TABLE test(a integer primary key, b integer) WITHOUT ROWID;";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -324,10 +324,10 @@ void TestTable::parseSQLWithoutRowid()
|
||||
|
||||
void TestTable::parseNonASCIIChars()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE `lösung` ("
|
||||
"`Fieldöäüß` INTEGER,"
|
||||
"PRIMARY KEY(`Fieldöäüß`)"
|
||||
");";
|
||||
std::string sSQL = "CREATE TABLE `lösung` ("
|
||||
"`Fieldöäüß` INTEGER,"
|
||||
"PRIMARY KEY(`Fieldöäüß`)"
|
||||
");";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -337,10 +337,10 @@ void TestTable::parseNonASCIIChars()
|
||||
|
||||
void TestTable::parseNonASCIICharsEs()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE \"Cigüeñas de Alcalá\" ("
|
||||
"\"Field áéíóúÁÉÍÓÚñÑçÇ\" INTEGER,"
|
||||
"PRIMARY KEY(\"Field áéíóúÁÉÍÓÚñÑçÇ\")"
|
||||
");";
|
||||
std::string sSQL = "CREATE TABLE \"Cigüeñas de Alcalá\" ("
|
||||
"\"Field áéíóúÁÉÍÓÚñÑçÇ\" INTEGER,"
|
||||
"PRIMARY KEY(\"Field áéíóúÁÉÍÓÚñÑçÇ\")"
|
||||
");";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
|
||||
@@ -350,69 +350,69 @@ void TestTable::parseNonASCIICharsEs()
|
||||
|
||||
void TestTable::parseSQLEscapedQuotes()
|
||||
{
|
||||
QString sSql = "CREATE TABLE double_quotes(a text default 'a''a');";
|
||||
std::string sSql = "CREATE TABLE double_quotes(a text default 'a''a');";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSql)));
|
||||
|
||||
QCOMPARE(tab.name(), QString("double_quotes"));
|
||||
QCOMPARE(tab.fields.at(0).name(), QString("a"));
|
||||
QCOMPARE(tab.fields.at(0).defaultValue(), QString("'a''a'"));
|
||||
QCOMPARE(tab.name(), "double_quotes");
|
||||
QCOMPARE(tab.fields.at(0).name(), "a");
|
||||
QCOMPARE(tab.fields.at(0).defaultValue(), "'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(y,z) on delete set null);";
|
||||
std::string sql = "CREATE TABLE foreign_key_test(a int, b int, foreign key (a) references x, foreign key (b) references w(y,z) on delete set null);";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sql)));
|
||||
|
||||
QCOMPARE(tab.name(), QString("foreign_key_test"));
|
||||
QCOMPARE(tab.fields.at(0).name(), QString("a"));
|
||||
QCOMPARE(tab.fields.at(0).type(), QString("int"));
|
||||
QCOMPARE(std::dynamic_pointer_cast<sqlb::ForeignKeyClause>(tab.constraint({tab.fields.at(0).name()}, sqlb::Constraint::ForeignKeyConstraintType))->table(), QString("x"));
|
||||
QCOMPARE(tab.fields.at(1).name(), QString("b"));
|
||||
QCOMPARE(tab.fields.at(1).type(), QString("int"));
|
||||
QCOMPARE(std::dynamic_pointer_cast<sqlb::ForeignKeyClause>(tab.constraint({tab.fields.at(1).name()}, sqlb::Constraint::ForeignKeyConstraintType))->toString(), QString("\"w\"(\"y\",\"z\") on delete set null"));
|
||||
QCOMPARE(tab.name(), "foreign_key_test");
|
||||
QCOMPARE(tab.fields.at(0).name(), "a");
|
||||
QCOMPARE(tab.fields.at(0).type(), "int");
|
||||
QCOMPARE(std::dynamic_pointer_cast<sqlb::ForeignKeyClause>(tab.constraint({tab.fields.at(0).name()}, sqlb::Constraint::ForeignKeyConstraintType))->table(), "x");
|
||||
QCOMPARE(tab.fields.at(1).name(), "b");
|
||||
QCOMPARE(tab.fields.at(1).type(), "int");
|
||||
QCOMPARE(std::dynamic_pointer_cast<sqlb::ForeignKeyClause>(tab.constraint({tab.fields.at(1).name()}, sqlb::Constraint::ForeignKeyConstraintType))->toString(), "\"w\"(\"y\",\"z\") on delete set null");
|
||||
}
|
||||
|
||||
void TestTable::parseSQLCheckConstraint()
|
||||
{
|
||||
QString sql = "CREATE TABLE a (\"b\" text CHECK(\"b\"='A' or \"b\"='B'));";
|
||||
std::string sql = "CREATE TABLE a (\"b\" text CHECK(\"b\"='A' or \"b\"='B'));";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sql)));
|
||||
|
||||
QCOMPARE(tab.name(), QString("a"));
|
||||
QCOMPARE(tab.fields.at(0).name(), QString("b"));
|
||||
QCOMPARE(tab.fields.at(0).type(), QString("text"));
|
||||
QCOMPARE(tab.fields.at(0).check(), QString("\"b\"='A' or \"b\"='B'"));
|
||||
QCOMPARE(tab.name(), "a");
|
||||
QCOMPARE(tab.fields.at(0).name(), "b");
|
||||
QCOMPARE(tab.fields.at(0).type(), "text");
|
||||
QCOMPARE(tab.fields.at(0).check(), "\"b\"='A' or \"b\"='B'");
|
||||
}
|
||||
|
||||
void TestTable::parseDefaultValues()
|
||||
{
|
||||
QString sql = "CREATE TABLE test(a int DEFAULT 0, b int DEFAULT -1, c text DEFAULT 'hello', d text DEFAULT '0');";
|
||||
std::string sql = "CREATE TABLE test(a int DEFAULT 0, b int DEFAULT -1, c text DEFAULT 'hello', d text DEFAULT '0');";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sql)));
|
||||
|
||||
QCOMPARE(tab.name(), QString("test"));
|
||||
QCOMPARE(tab.fields.at(0).name(), QString("a"));
|
||||
QCOMPARE(tab.fields.at(0).type(), QString("int"));
|
||||
QCOMPARE(tab.fields.at(0).defaultValue(), QString("0"));
|
||||
QCOMPARE(tab.fields.at(1).name(), QString("b"));
|
||||
QCOMPARE(tab.fields.at(1).type(), QString("int"));
|
||||
QCOMPARE(tab.fields.at(1).defaultValue(), QString("-1"));
|
||||
QCOMPARE(tab.fields.at(2).name(), QString("c"));
|
||||
QCOMPARE(tab.fields.at(2).type(), QString("text"));
|
||||
QCOMPARE(tab.fields.at(2).defaultValue(), QString("'hello'"));
|
||||
QCOMPARE(tab.fields.at(3).name(), QString("d"));
|
||||
QCOMPARE(tab.fields.at(3).type(), QString("text"));
|
||||
QCOMPARE(tab.fields.at(3).defaultValue(), QString("'0'"));
|
||||
QCOMPARE(tab.name(), "test");
|
||||
QCOMPARE(tab.fields.at(0).name(), "a");
|
||||
QCOMPARE(tab.fields.at(0).type(), "int");
|
||||
QCOMPARE(tab.fields.at(0).defaultValue(), "0");
|
||||
QCOMPARE(tab.fields.at(1).name(), "b");
|
||||
QCOMPARE(tab.fields.at(1).type(), "int");
|
||||
QCOMPARE(tab.fields.at(1).defaultValue(), "-1");
|
||||
QCOMPARE(tab.fields.at(2).name(), "c");
|
||||
QCOMPARE(tab.fields.at(2).type(), "text");
|
||||
QCOMPARE(tab.fields.at(2).defaultValue(), "'hello'");
|
||||
QCOMPARE(tab.fields.at(3).name(), "d");
|
||||
QCOMPARE(tab.fields.at(3).type(), "text");
|
||||
QCOMPARE(tab.fields.at(3).defaultValue(), "'0'");
|
||||
}
|
||||
|
||||
void TestTable::createTableWithIn()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE not_working("
|
||||
"_id PRIMARY KEY NOT NULL,"
|
||||
"value NVARCHAR(5) CHECK (value IN ('a', 'b', 'c'))"
|
||||
");";
|
||||
std::string sSQL = "CREATE TABLE not_working("
|
||||
"_id PRIMARY KEY NOT NULL,"
|
||||
"value NVARCHAR(5) CHECK (value IN ('a', 'b', 'c'))"
|
||||
");";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
QCOMPARE(tab.name(), "not_working");
|
||||
@@ -422,14 +422,14 @@ void TestTable::createTableWithIn()
|
||||
|
||||
void TestTable::createTableWithNotLikeConstraint()
|
||||
{
|
||||
QString sSQL = "CREATE TABLE hopefully_working(\n"
|
||||
"value TEXT CONSTRAINT 'value' CHECK(value NOT LIKE 'prefix%'),\n"
|
||||
"value2 TEXT CONSTRAINT 'value' CHECK(value2 NOT MATCH 'prefix%'),\n"
|
||||
"value3 TEXT CONSTRAINT 'value' CHECK(value3 NOT REGEXP 'prefix%'),\n"
|
||||
"value4 TEXT CONSTRAINT 'value' CHECK(value4 NOT GLOB 'prefix%'),\n"
|
||||
"value5 INTEGER CONSTRAINT 'value' CHECK(value5 BETWEEN 1+4 AND 100 OR 200),\n"
|
||||
"value6 INTEGER CONSTRAINT 'value' CHECK(value6 NOT BETWEEN 1 AND 100)\n"
|
||||
");";
|
||||
std::string sSQL = "CREATE TABLE hopefully_working(\n"
|
||||
"value TEXT CHECK(value NOT LIKE 'prefix%'),\n"
|
||||
"value2 TEXT CHECK(value2 NOT MATCH 'prefix%'),\n"
|
||||
"value3 TEXT CHECK(value3 NOT REGEXP 'prefix%'),\n"
|
||||
"value4 TEXT CHECK(value4 NOT GLOB 'prefix%'),\n"
|
||||
"value5 INTEGER CHECK(value5 BETWEEN 1+4 AND 100 OR 200),\n"
|
||||
"value6 INTEGER CHECK(value6 NOT BETWEEN 1 AND 100)\n"
|
||||
");";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sSQL)));
|
||||
QCOMPARE(tab.name(), "hopefully_working");
|
||||
@@ -444,26 +444,26 @@ void TestTable::createTableWithNotLikeConstraint()
|
||||
|
||||
void TestTable::rowValues()
|
||||
{
|
||||
QString sql = "CREATE TABLE test(\n"
|
||||
"a INTEGER,\n"
|
||||
"b INTEGER,\n"
|
||||
"CHECK((a, b) = (1, 2))\n"
|
||||
");";
|
||||
std::string sql = "CREATE TABLE test(\n"
|
||||
"a INTEGER,\n"
|
||||
"b INTEGER,\n"
|
||||
"CHECK((a, b) = (1, 2))\n"
|
||||
");";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sql)));
|
||||
QCOMPARE(tab.name(), "test");
|
||||
|
||||
QCOMPARE(std::dynamic_pointer_cast<sqlb::CheckConstraint>(tab.constraint({}, sqlb::Constraint::CheckConstraintType))->expression(), QString("(a,b)=(1,2)"));
|
||||
QCOMPARE(std::dynamic_pointer_cast<sqlb::CheckConstraint>(tab.constraint({}, sqlb::Constraint::CheckConstraintType))->expression(), "(a,b)=(1,2)");
|
||||
}
|
||||
|
||||
void TestTable::complexExpressions()
|
||||
{
|
||||
QString sql = "CREATE TABLE test(\n"
|
||||
"a INTEGER CHECK((a > 0)),\n"
|
||||
"b INTEGER CHECK((b > 0 and b > 1)),\n"
|
||||
"c INTEGER CHECK((c = -1) or (c > 0 and c > 1) or (c = 0)),\n"
|
||||
"d INTEGER CHECK((((d > 0))))\n"
|
||||
");";
|
||||
std::string sql = "CREATE TABLE test(\n"
|
||||
"a INTEGER CHECK((a > 0)),\n"
|
||||
"b INTEGER CHECK((b > 0 and b > 1)),\n"
|
||||
"c INTEGER CHECK((c = -1) or (c > 0 and c > 1) or (c = 0)),\n"
|
||||
"d INTEGER CHECK((((d > 0))))\n"
|
||||
");";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sql)));
|
||||
QCOMPARE(tab.name(), "test");
|
||||
@@ -476,9 +476,9 @@ void TestTable::complexExpressions()
|
||||
|
||||
void TestTable::datetimeExpression()
|
||||
{
|
||||
QString sql = "CREATE TABLE test(\n"
|
||||
"entry INTEGER DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'LOCALTIME'))\n"
|
||||
");";
|
||||
std::string sql = "CREATE TABLE test(\n"
|
||||
"entry INTEGER DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'LOCALTIME'))\n"
|
||||
");";
|
||||
|
||||
Table tab = *(std::dynamic_pointer_cast<sqlb::Table>(Table::parseSQL(sql)));
|
||||
QCOMPARE(tab.name(), "test");
|
||||
|
||||
Reference in New Issue
Block a user