mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
SqliteTypes: Move PK flag from table to field
Store the primary key flag(s) inside the sqlb::Field objects instead of the sqlb::Table object. Technically this doesn't make a lot of sense but then again it makes things a lot easier for us. So this should fix quite a few issues in the entire program, especially - again - in renameColumn(). It also magically fixes createColumn() which had no chance of guessing which column should be a PK prior to this. To benefit from these changes the EditTableDialog has changes as well. - It should now be possible to set and unset PK and AI flags and they are actually saved. - Setting the AI flag automatically sets the data type to Integer because that's the only type SQLite can handle in an autoincrement field. - Clicking on the entry in the data type combobox which is currently selected doesn't update the DB anymore. This commit also makes some changes to the unit tests to reflect the API changes made. But it also adds missing quote characters in some verification strings. I hope this is a worthy 500th commit - at least it's got a long commit message...
This commit is contained in:
@@ -22,19 +22,17 @@ void TestTable::sqlOutput()
|
||||
{
|
||||
Table tt("testtable");
|
||||
FieldPtr f = FieldPtr(new Field("id", "integer"));
|
||||
f->setPrimaryKey(true);
|
||||
FieldPtr fkm = FieldPtr(new Field("km", "integer", false, "", "km > 1000"));
|
||||
fkm->setPrimaryKey(true);
|
||||
tt.addField(f);
|
||||
tt.addField(FieldPtr(new Field("car", "text")));
|
||||
tt.addField(fkm);
|
||||
FieldVector pk;
|
||||
pk.append(f);
|
||||
pk.append(fkm);
|
||||
tt.setPrimaryKey(pk);
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\tid\tinteger,\n"
|
||||
"\tcar\ttext,\n"
|
||||
"\tkm\tinteger CHECK(km > 1000),\n"
|
||||
"\t`id`\tinteger,\n"
|
||||
"\t`car`\ttext,\n"
|
||||
"\t`km`\tinteger CHECK(km > 1000),\n"
|
||||
"\tPRIMARY KEY(id,km)\n"
|
||||
");"));
|
||||
}
|
||||
@@ -43,16 +41,17 @@ void TestTable::autoincrement()
|
||||
{
|
||||
Table tt("testtable");
|
||||
FieldPtr f = FieldPtr(new Field("id", "integer"));
|
||||
f->setPrimaryKey(true);
|
||||
f->setAutoIncrement(true);
|
||||
FieldPtr fkm = FieldPtr(new Field("km", "integer"));
|
||||
tt.addField(f);
|
||||
tt.addField(FieldPtr(new Field("car", "text")));
|
||||
tt.addField(fkm);
|
||||
tt.setPrimaryKey(f, true);
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\tid\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\tcar\ttext,\n"
|
||||
"\tkm\tinteger\n"
|
||||
"\t`id`\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\t`car`\ttext,\n"
|
||||
"\t`km`\tinteger\n"
|
||||
");"));
|
||||
}
|
||||
|
||||
@@ -60,16 +59,17 @@ void TestTable::notnull()
|
||||
{
|
||||
Table tt("testtable");
|
||||
FieldPtr f = FieldPtr(new Field("id", "integer"));
|
||||
f->setPrimaryKey(true);
|
||||
f->setAutoIncrement(true);
|
||||
FieldPtr fkm = FieldPtr(new Field("km", "integer"));
|
||||
tt.addField(f);
|
||||
tt.addField(FieldPtr(new Field("car", "text", true)));
|
||||
tt.addField(fkm);
|
||||
tt.setPrimaryKey(f, true);
|
||||
|
||||
QCOMPARE(tt.sql(), QString("CREATE TABLE `testtable` (\n"
|
||||
"\tid\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\tcar\ttext NOT NULL,\n"
|
||||
"\tkm\tinteger\n"
|
||||
"\t`id`\tinteger PRIMARY KEY AUTOINCREMENT,\n"
|
||||
"\t`car`\ttext NOT NULL,\n"
|
||||
"\t`km`\tinteger\n"
|
||||
");"));
|
||||
}
|
||||
|
||||
@@ -93,12 +93,13 @@ void TestTable::parseSQL()
|
||||
QVERIFY(tab.fields().at(2)->type() == "VARCHAR(255)");
|
||||
|
||||
QVERIFY(tab.fields().at(0)->autoIncrement());
|
||||
QVERIFY(tab.fields().at(0)->primaryKey());
|
||||
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"));
|
||||
|
||||
QVERIFY(tab.primarykey().contains(tab.fields().at(0)));
|
||||
|
||||
}
|
||||
|
||||
void TestTable::parseSQLdefaultexpr()
|
||||
@@ -124,7 +125,7 @@ void TestTable::parseSQLdefaultexpr()
|
||||
QCOMPARE(tab.fields().at(2)->defaultValue(), QString(""));
|
||||
QCOMPARE(tab.fields().at(2)->check(), QString(""));
|
||||
|
||||
QVERIFY(tab.primarykey().contains(tab.fields().at(0)));
|
||||
QVERIFY(tab.fields().at(0)->primaryKey());
|
||||
}
|
||||
|
||||
void TestTable::parseSQLMultiPk()
|
||||
@@ -145,8 +146,8 @@ void TestTable::parseSQLMultiPk()
|
||||
QVERIFY(tab.fields().at(0)->type() == "integer");
|
||||
QVERIFY(tab.fields().at(1)->type() == "integer");
|
||||
|
||||
QVERIFY(tab.primarykey().contains(tab.fields().at(0)));
|
||||
QVERIFY(tab.primarykey().contains(tab.fields().at(1)));
|
||||
QVERIFY(tab.fields().at(0)->primaryKey());
|
||||
QVERIFY(tab.fields().at(1)->primaryKey());
|
||||
}
|
||||
|
||||
void TestTable::parseSQLForeignKey()
|
||||
|
||||
Reference in New Issue
Block a user