additonal SQL on the columns page
After the "all in one" ALTER TABLE ADD COLUMN statement ALTER TABLE ALTER COLUMN statements are listed for setting the default and the NOT NULL constraint.
This commit is contained in:
parent
53997f94da
commit
5777a9c834
1 changed files with 43 additions and 20 deletions
|
|
@ -54,14 +54,17 @@ void ColumnPage::tableView_selectionChanged(const QItemSelection &/*selected*/,
|
|||
for (const auto &e : indexes)
|
||||
rijen.insert(m_sortFilterProxy->mapToSource(e).row());
|
||||
|
||||
const QString alterTable = "ALTER TABLE " % m_Class->fullyQualifiedQuotedObjectName();
|
||||
|
||||
QString completeSql;
|
||||
if (!rijen.empty()) {
|
||||
QString drops;
|
||||
QString addsql;
|
||||
auto iter = rijen.begin();
|
||||
if (iter != rijen.end()) {
|
||||
auto && col = m_columnModel->column(*iter);
|
||||
drops = "ALTER TABLE " % m_Class->fullyQualifiedQuotedObjectName() % "\n DROP COLUMN " % quoteIdent(col.name);
|
||||
addsql = "ALTER TABLE " % m_Class->fullyQualifiedQuotedObjectName() % "\n ADD COLUMN " % col.columnDefinition(*m_catalog);
|
||||
drops = alterTable % "\n DROP COLUMN " % quoteIdent(col.name);
|
||||
addsql = alterTable % "\n ADD COLUMN " % col.columnDefinition(*m_catalog);
|
||||
for (++iter; iter != rijen.end(); ++iter) {
|
||||
auto && col = m_columnModel->column(*iter);
|
||||
drops += ",\n DROP COLUMN " % quoteIdent(col.name);
|
||||
|
|
@ -70,9 +73,29 @@ void ColumnPage::tableView_selectionChanged(const QItemSelection &/*selected*/,
|
|||
drops += ";";
|
||||
addsql += ";";
|
||||
m_definitionView->setPlainText(drops % "\n\n" % addsql);
|
||||
completeSql += drops % "\n\n" % addsql;
|
||||
}
|
||||
else {
|
||||
m_definitionView->setPlainText("");
|
||||
}
|
||||
|
||||
completeSql += "\n-- SQL to correct just the defaults\n";
|
||||
for (auto r : rijen) {
|
||||
auto && col = m_columnModel->column(r);
|
||||
completeSql += alterTable % " ALTER COLUMN " % quoteIdent(col.name);
|
||||
if (col.hasdef)
|
||||
completeSql += " SET DEFAULT " % col.defaultValue % ";\n";
|
||||
else
|
||||
completeSql += " DROP DEFAULT;\n";
|
||||
}
|
||||
completeSql += "\n-- SQL to correct NULLABLE\n";
|
||||
for (auto r : rijen) {
|
||||
auto && col = m_columnModel->column(r);
|
||||
completeSql += alterTable % " ALTER COLUMN " % quoteIdent(col.name);
|
||||
if (col.notnull)
|
||||
completeSql += " SET NOT NULL;\n";
|
||||
else
|
||||
completeSql += " DROP NOT NULL;\n";
|
||||
}
|
||||
}
|
||||
m_definitionView->setPlainText(completeSql);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue