diff options
| author | 2021-12-17 07:06:30 -0500 | |
|---|---|---|
| committer | 2021-12-17 07:06:30 -0500 | |
| commit | 1fdc150116cad39aae5c5da407c3312b47a59e3a (patch) | |
| tree | 123c79a4d7ad2d45781ba03ce939f7539fb428d8 /SQLiteStudio3/guiSQLiteStudio/windows | |
| parent | feda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (diff) | |
New upstream version 3.3.3+dfsg1.upstream/3.3.3+dfsg1
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows')
18 files changed, 287 insertions, 150 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/collationseditor.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/collationseditor.cpp index 5d36683..5cf5be4 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/collationseditor.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/collationseditor.cpp @@ -1,6 +1,7 @@ #include "collationseditor.h" #include "ui_collationseditor.h" #include "common/unused.h" +#include "common/compatibility.h" #include "selectabledbmodel.h" #include "dbtree/dbtree.h" #include "dbtree/dbtreemodel.h" @@ -163,9 +164,9 @@ void CollationsEditor::collationSelected(int row) void CollationsEditor::clearEdits() { - ui->nameEdit->setText(QString::null); - ui->codeEdit->setPlainText(QString::null); - ui->langCombo->setCurrentText(QString::null); + ui->nameEdit->setText(QString()); + ui->codeEdit->setPlainText(QString()); + ui->langCombo->setCurrentText(QString()); ui->allDatabasesRadio->setChecked(true); ui->langCombo->setCurrentIndex(-1); } @@ -350,7 +351,7 @@ void CollationsEditor::updateModified() bool codeDiff = model->getCode(row) != ui->codeEdit->toPlainText(); bool langDiff = model->getLang(row) != ui->langCombo->currentText(); bool allDatabasesDiff = model->getAllDatabases(row) != ui->allDatabasesRadio->isChecked(); - bool dbDiff = getCurrentDatabases().toSet() != model->getDatabases(row).toSet(); // QSet to ignore order + bool dbDiff = toSet(getCurrentDatabases()) != toSet(model->getDatabases(row)); // QSet to ignore order currentModified = (nameDiff || codeDiff || langDiff || allDatabasesDiff || dbDiff); } diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/constrainttabmodel.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/constrainttabmodel.cpp index 1144fda..becb060 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/constrainttabmodel.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/constrainttabmodel.cpp @@ -82,7 +82,7 @@ QVariant ConstraintTabModel::data(SqliteCreateTable::Constraint* constr, int col case Columns::NAME: { if (role == Qt::DisplayRole) - return stripObjName(constr->name, createTable->dialect); + return stripObjName(constr->name); break; } @@ -124,7 +124,7 @@ QVariant ConstraintTabModel::data(SqliteCreateTable::Column::Constraint* constr, case Columns::NAME: { if (role == Qt::DisplayRole) - return stripObjName(constr->name, createTable->dialect); + return stripObjName(constr->name); break; } @@ -186,9 +186,9 @@ QString ConstraintTabModel::getTypeLabel(SqliteCreateTable::Constraint::Type typ case SqliteCreateTable::Constraint::FOREIGN_KEY: return "FOREIGN KEY"; case SqliteCreateTable::Constraint::NAME_ONLY: - return QString::null; + return QString(); } - return QString::null; + return QString(); } QString ConstraintTabModel::getTypeLabel(SqliteCreateTable::Column::Constraint::Type type) const @@ -207,6 +207,8 @@ QString ConstraintTabModel::getTypeLabel(SqliteCreateTable::Column::Constraint:: return "DEFAULT"; case SqliteCreateTable::Column::Constraint::COLLATE: return "COLLATE"; + case SqliteCreateTable::Column::Constraint::GENERATED: + return "GENERATED"; case SqliteCreateTable::Column::Constraint::FOREIGN_KEY: return "FOREIGN KEY"; case SqliteCreateTable::Column::Constraint::NULL_: @@ -214,7 +216,7 @@ QString ConstraintTabModel::getTypeLabel(SqliteCreateTable::Column::Constraint:: case SqliteCreateTable::Column::Constraint::DEFERRABLE_ONLY: break; } - return QString::null; + return QString(); } QIcon ConstraintTabModel::getTypeIcon(SqliteCreateTable::Constraint::Type type) const @@ -251,6 +253,8 @@ QIcon ConstraintTabModel::getTypeIcon(SqliteCreateTable::Column::Constraint::Typ return ICONS.CONSTRAINT_DEFAULT; case SqliteCreateTable::Column::Constraint::COLLATE: return ICONS.CONSTRAINT_COLLATION; + case SqliteCreateTable::Column::Constraint::GENERATED: + return ICONS.CONSTRAINT_GENERATED; case SqliteCreateTable::Column::Constraint::FOREIGN_KEY: return ICONS.CONSTRAINT_FOREIGN_KEY; case SqliteCreateTable::Column::Constraint::NULL_: @@ -274,9 +278,9 @@ QString ConstraintTabModel::getDetails(SqliteCreateTable::Constraint* constr) co case SqliteCreateTable::Constraint::FOREIGN_KEY: return getFkDetails(constr); case SqliteCreateTable::Constraint::NAME_ONLY: - return QString::null; + return QString(); } - return QString::null; + return QString(); } QString ConstraintTabModel::getDetails(SqliteCreateTable::Column::Constraint* constr) const @@ -295,6 +299,8 @@ QString ConstraintTabModel::getDetails(SqliteCreateTable::Column::Constraint* co return getDefaultDetails(constr); case SqliteCreateTable::Column::Constraint::COLLATE: return getCollateDetails(constr); + case SqliteCreateTable::Column::Constraint::GENERATED: + return getGeneratedDetails(constr); case SqliteCreateTable::Column::Constraint::FOREIGN_KEY: return getFkDetails(constr); case SqliteCreateTable::Column::Constraint::NULL_: @@ -302,7 +308,7 @@ QString ConstraintTabModel::getDetails(SqliteCreateTable::Column::Constraint* co case SqliteCreateTable::Column::Constraint::DEFERRABLE_ONLY: break; } - return QString::null; + return QString(); } QString ConstraintTabModel::getPkDetails(SqliteCreateTable::Constraint* constr) const @@ -365,6 +371,12 @@ QString ConstraintTabModel::getCollateDetails(SqliteCreateTable::Column::Constra return getConstrDetails(constr, idx + 1); } +QString ConstraintTabModel::getGeneratedDetails(SqliteCreateTable::Column::Constraint* constr) const +{ + int idx = constr->tokens.indexOf(Token::KEYWORD, "GENERATED", Qt::CaseInsensitive); + return getConstrDetails(constr, idx + 1); +} + QString ConstraintTabModel::getDefaultDetails(SqliteCreateTable::Column::Constraint* constr) const { int idx = constr->tokens.indexOf(Token::KEYWORD, "DEFAULT", Qt::CaseInsensitive); diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/constrainttabmodel.h b/SQLiteStudio3/guiSQLiteStudio/windows/constrainttabmodel.h index f93415b..3292117 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/constrainttabmodel.h +++ b/SQLiteStudio3/guiSQLiteStudio/windows/constrainttabmodel.h @@ -52,6 +52,7 @@ class GUI_API_EXPORT ConstraintTabModel : public QAbstractTableModel QString getFkDetails(SqliteCreateTable::Column::Constraint* constr) const; QString getNotNullDetails(SqliteCreateTable::Column::Constraint* constr) const; QString getCollateDetails(SqliteCreateTable::Column::Constraint* constr) const; + QString getGeneratedDetails(SqliteCreateTable::Column::Constraint* constr) const; QString getDefaultDetails(SqliteCreateTable::Column::Constraint* constr) const; QString getConstrDetails(SqliteCreateTable::Constraint* constr, int tokenOffset) const; diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/editorwindow.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/editorwindow.cpp index cd3e135..f0f980d 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/editorwindow.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/editorwindow.cpp @@ -22,6 +22,7 @@ #include "themetuner.h" #include "dialogs/bindparamsdialog.h" #include "common/bindparam.h" +#include "common/dbcombobox.h" #include <QComboBox> #include <QDebug> #include <QStringListModel> @@ -106,7 +107,7 @@ void EditorWindow::init() Db* treeSelectedDb = DBTREE->getSelectedOpenDb(); if (treeSelectedDb) - dbCombo->setCurrentIndex(dbComboModel->getIndexForDb(treeSelectedDb)); + dbCombo->setCurrentDb(treeSelectedDb); Db* currentDb = getCurrentDb(); resultsModel->setDb(currentDb); @@ -230,11 +231,8 @@ QString EditorWindow::getQueryToExecute(bool doSelectCurrentQuery) bool EditorWindow::setCurrentDb(Db *db) { - if (dbCombo->findText(db->getName()) == -1) - return false; - - dbCombo->setCurrentText(db->getName()); - return true; + dbCombo->setCurrentDb(db); + return dbCombo->currentIndex() > -1; } void EditorWindow::setContents(const QString &sql) @@ -319,7 +317,7 @@ void EditorWindow::changeEvent(QEvent *e) Db* EditorWindow::getCurrentDb() { - return dbComboModel->getDb(dbCombo->currentIndex()); + return dbCombo->currentDb(); } void EditorWindow::updateResultsDisplayMode() @@ -366,6 +364,8 @@ void EditorWindow::updateResultsDisplayMode() void EditorWindow::createActions() { // SQL editor toolbar + actionMap[CURRENT_DB] = ui->toolBar->addWidget(dbCombo); + ui->toolBar->addSeparator(); createAction(EXEC_QUERY, ICONS.EXEC_QUERY, tr("Execute query"), this, SLOT(execQuery()), ui->toolBar, ui->sqlEdit); createAction(EXPLAIN_QUERY, ICONS.EXPLAIN_QUERY, tr("Explain query"), this, SLOT(explainQuery()), ui->toolBar, ui->sqlEdit); ui->toolBar->addSeparator(); @@ -383,8 +383,6 @@ void EditorWindow::createActions() ui->toolBar->addAction(ui->sqlEdit->getAction(SqlEditor::FIND)); ui->toolBar->addAction(ui->sqlEdit->getAction(SqlEditor::REPLACE)); ui->toolBar->addSeparator(); - actionMap[CURRENT_DB] = ui->toolBar->addWidget(dbCombo); - ui->toolBar->addSeparator(); ui->toolBar->addAction(staticActions[RESULTS_IN_TAB]); ui->toolBar->addAction(staticActions[RESULTS_BELOW]); createAction(PREV_DB, tr("Previous database"), this, SLOT(prevDb()), this); @@ -404,10 +402,7 @@ void EditorWindow::createActions() void EditorWindow::createDbCombo() { - dbCombo = new QComboBox(this); - dbComboModel = new DbListModel(this); - dbComboModel->setCombo(dbCombo); - dbCombo->setModel(dbComboModel); + dbCombo = new DbComboBox(this); dbCombo->setEditable(false); dbCombo->setFixedWidth(100); connect(dbCombo, SIGNAL(currentTextChanged(QString)), this, SLOT(dbChanged())); @@ -424,17 +419,12 @@ void EditorWindow::setupDefShortcuts() void EditorWindow::selectCurrentQuery(bool fallBackToPreviousIfNecessary) { - Dialect dialect = Dialect::Sqlite3; - Db* db = getCurrentDb(); - if (db && db->isValid()) - dialect = db->getDialect(); - QTextCursor cursor = ui->sqlEdit->textCursor(); int pos = cursor.position(); int queryStartPos; QString contents = ui->sqlEdit->toPlainText(); QString query = getQueryWithPosition(contents, pos, &queryStartPos); - TokenList tokens = Lexer::tokenize(query, dialect); + TokenList tokens = Lexer::tokenize(query); tokens.trim(); tokens.trimRight(Token::OPERATOR, ";"); @@ -445,7 +435,7 @@ void EditorWindow::selectCurrentQuery(bool fallBackToPreviousIfNecessary) if (pos > -1) { query = getQueryWithPosition(contents, pos, &queryStartPos); - tokens = Lexer::tokenize(query, dialect); + tokens = Lexer::tokenize(query); tokens.trim(); tokens.trimRight(Token::OPERATOR, ";"); } @@ -504,14 +494,8 @@ void EditorWindow::explainQuery() bool EditorWindow::processBindParams(QString& sql, QHash<QString, QVariant>& queryParams) { - // Determin dialect - Dialect dialect = Dialect::Sqlite3; - Db* db = getCurrentDb(); - if (db && db->isValid()) - dialect = db->getDialect(); - // Get all bind parameters from the query - TokenList tokens = Lexer::tokenize(sql, dialect); + TokenList tokens = Lexer::tokenize(sql); TokenList bindTokens = tokens.filter(Token::BIND_PARAM); // No bind tokens? Return fast. @@ -522,18 +506,29 @@ bool EditorWindow::processBindParams(QString& sql, QHash<QString, QVariant>& que static_qstring(paramTpl, ":arg%1"); QString arg; QVector<BindParam*> bindParams; + QHash<QString, QString> namedBindParams; BindParam* bindParam = nullptr; + bool isNamed = false; + bool nameAlreadyInList = false; int i = 0; for (const TokenPtr& token : bindTokens) { + isNamed = (token->value != "?"); + nameAlreadyInList = isNamed && namedBindParams.contains(token->value); + bindParam = new BindParam(); bindParam->position = i; bindParam->originalName = token->value; - bindParam->newName = paramTpl.arg(i); - bindParams << bindParam; - i++; - + bindParam->newName = (isNamed && nameAlreadyInList) ? namedBindParams[token->value] : paramTpl.arg(i); token->value = bindParam->newName; + + if (!isNamed || !nameAlreadyInList) + bindParams << bindParam; + + if (isNamed && !nameAlreadyInList) + namedBindParams[bindParam->originalName] = bindParam->newName; + + i++; } // Show dialog to query user for values @@ -719,7 +714,7 @@ void EditorWindow::exportResults() } QString query = lastSuccessfulQuery.isEmpty() ? getQueryToExecute() : lastSuccessfulQuery; - QStringList queries = splitQueries(query, getCurrentDb()->getDialect(), false, true); + QStringList queries = splitQueries(query, false, true); if (queries.size() == 0) { qWarning() << "No queries after split in EditorWindow::exportResults()"; diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/editorwindow.h b/SQLiteStudio3/guiSQLiteStudio/windows/editorwindow.h index 296a9e2..35a3b9b 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/editorwindow.h +++ b/SQLiteStudio3/guiSQLiteStudio/windows/editorwindow.h @@ -22,6 +22,7 @@ class IntValidator; class FormView; class SqlQueryItem; class SqlEditor; +class DbComboBox; CFG_KEY_LIST(EditorWindow, QObject::tr("SQL editor window"), CFG_KEY_ENTRY(EXEC_QUERY, Qt::Key_F9, QObject::tr("Execute query")) @@ -128,8 +129,7 @@ class GUI_API_EXPORT EditorWindow : public MdiChild Ui::EditorWindow *ui = nullptr; SqlQueryModel* resultsModel = nullptr; QHash<ActionGroup,QActionGroup*> actionGroups; - QComboBox* dbCombo = nullptr; - DbListModel* dbComboModel = nullptr; + DbComboBox* dbCombo = nullptr; int sqlEditorNum = 1; qint64 lastQueryHistoryId = 0; QString lastSuccessfulQuery; diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp index 9894098..3ac32ac 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp @@ -2,6 +2,7 @@ #include "ui_functionseditor.h" #include "common/unused.h" #include "common/utils.h" +#include "common/compatibility.h" #include "uiutils.h" #include "functionseditormodel.h" #include "services/pluginmanager.h" @@ -178,8 +179,8 @@ void FunctionsEditor::functionDeselected(int row) } else { - model->setInitCode(row, QString::null); - model->setFinalCode(row, QString::null); + model->setInitCode(row, QString()); + model->setFinalCode(row, QString()); } if (!ui->undefArgsCheck->isChecked()) @@ -239,9 +240,9 @@ void FunctionsEditor::functionSelected(int row) void FunctionsEditor::clearEdits() { - ui->nameEdit->setText(QString::null); - ui->mainCodeEdit->setPlainText(QString::null); - ui->langCombo->setCurrentText(QString::null); + ui->nameEdit->setText(QString()); + ui->mainCodeEdit->setPlainText(QString()); + ui->langCombo->setCurrentText(QString()); ui->undefArgsCheck->setChecked(true); ui->argsList->clear(); ui->allDatabasesRadio->setChecked(true); @@ -371,7 +372,7 @@ void FunctionsEditor::updateModified() bool undefArgsDiff = model->getUndefinedArgs(row) != ui->undefArgsCheck->isChecked(); bool allDatabasesDiff = model->getAllDatabases(row) != ui->allDatabasesRadio->isChecked(); bool argDiff = getCurrentArgList() != model->getArguments(row); - bool dbDiff = getCurrentDatabases().toSet() != model->getDatabases(row).toSet(); // QSet to ignore order + bool dbDiff = toSet(getCurrentDatabases()) != toSet(model->getDatabases(row)); // QSet to ignore order bool typeDiff = model->getType(row) != getCurrentFunctionType(); currentModified = (nameDiff || codeDiff || typeDiff || langDiff || undefArgsDiff || allDatabasesDiff || argDiff || dbDiff || diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp index 623ebd8..8d6d87c 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp @@ -87,7 +87,7 @@ void FunctionsEditorModel::setCode(int row, const QString& code) QString FunctionsEditorModel::getCode(int row) const { - GETTER(functionList[row]->data.code, QString::null); + GETTER(functionList[row]->data.code, QString()); } void FunctionsEditorModel::setFinalCode(int row, const QString& code) @@ -97,7 +97,7 @@ void FunctionsEditorModel::setFinalCode(int row, const QString& code) QString FunctionsEditorModel::getFinalCode(int row) const { - GETTER(functionList[row]->data.finalCode, QString::null); + GETTER(functionList[row]->data.finalCode, QString()); } void FunctionsEditorModel::setInitCode(int row, const QString& code) @@ -107,7 +107,7 @@ void FunctionsEditorModel::setInitCode(int row, const QString& code) QString FunctionsEditorModel::getInitCode(int row) const { - GETTER(functionList[row]->data.initCode, QString::null); + GETTER(functionList[row]->data.initCode, QString()); } void FunctionsEditorModel::setName(int row, const QString& newName) @@ -117,7 +117,7 @@ void FunctionsEditorModel::setName(int row, const QString& newName) QString FunctionsEditorModel::getName(int row) const { - GETTER(functionList[row]->data.name, QString::null); + GETTER(functionList[row]->data.name, QString()); } void FunctionsEditorModel::setLang(int row, const QString& lang) @@ -127,7 +127,7 @@ void FunctionsEditorModel::setLang(int row, const QString& lang) QString FunctionsEditorModel::getLang(int row) const { - GETTER(functionList[row]->data.lang, QString::null); + GETTER(functionList[row]->data.lang, QString()); } bool FunctionsEditorModel::getUndefinedArgs(int row) const diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/sqliteextensioneditor.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/sqliteextensioneditor.cpp index ca45eff..4351312 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/sqliteextensioneditor.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/sqliteextensioneditor.cpp @@ -11,6 +11,7 @@ #include "services/dbmanager.h" #include "services/notifymanager.h" #include "common/lazytrigger.h" +#include "common/compatibility.h" #include <QDesktopServices> #include <QFileDialog> #include <QSortFilterProxyModel> @@ -173,8 +174,8 @@ void SqliteExtensionEditor::extensionSelected(int row) void SqliteExtensionEditor::clearEdits() { - ui->fileEdit->setText(QString::null); - ui->initEdit->setText(QString::null); + ui->fileEdit->setText(QString()); + ui->initEdit->setText(QString()); ui->allDatabasesRadio->setChecked(true); } @@ -220,7 +221,7 @@ bool SqliteExtensionEditor::validateExtension(int row) { QString filePath = model->getFilePath(row); QString initFunc = model->getInitFunction(row); - return validateExtension(filePath, initFunc); + return validateExtension(filePath, initFunc, nullptr, nullptr, new QString); } bool SqliteExtensionEditor::validateExtension(const QString& filePath, const QString& initFunc, bool* fileOk, bool* initOk, QString* fileError) @@ -388,7 +389,7 @@ void SqliteExtensionEditor::updateModified() bool fileDiff = model->getFilePath(row) != ui->fileEdit->text(); bool initDiff = model->getInitFunction(row) != ui->initEdit->text(); bool allDatabasesDiff = model->getAllDatabases(row) != ui->allDatabasesRadio->isChecked(); - bool dbDiff = getCurrentDatabases().toSet() != model->getDatabases(row).toSet(); // QSet to ignore order + bool dbDiff = toSet(getCurrentDatabases()) != toSet(model->getDatabases(row)); // QSet to ignore order currentModified = (fileDiff || initDiff || allDatabasesDiff || dbDiff); } diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/sqliteextensioneditor.h b/SQLiteStudio3/guiSQLiteStudio/windows/sqliteextensioneditor.h index c8ea3d0..5d81085 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/sqliteextensioneditor.h +++ b/SQLiteStudio3/guiSQLiteStudio/windows/sqliteextensioneditor.h @@ -61,9 +61,15 @@ class SqliteExtensionEditor : public MdiChild void selectExtension(int row); QStringList getCurrentDatabases() const; bool tryToLoad(const QString& filePath, const QString& initFunc, QString* resultError); - bool validateExtension(bool* fileOk = nullptr, bool* initOk = nullptr, QString* fileError = nullptr); + bool validateExtension(bool* fileOk = nullptr, + bool* initOk = nullptr, + QString* fileError = nullptr); bool validateExtension(int row); - bool validateExtension(const QString& filePath, const QString& initFunc, bool* fileOk = nullptr, bool* initOk = nullptr, QString* fileError = nullptr); + bool validateExtension(const QString& filePath, + const QString& initFunc, + bool* fileOk = nullptr, + bool* initOk = nullptr, + QString* fileError = nullptr); void initStateForAll(); Ui::SqliteExtensionEditor *ui; diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/tableconstraintsmodel.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/tableconstraintsmodel.cpp index 0f95a98..74e7dd8 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/tableconstraintsmodel.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/tableconstraintsmodel.cpp @@ -46,7 +46,7 @@ QVariant TableConstraintsModel::data(const QModelIndex& index, int role) const case Columns::NAME: { if (role == Qt::DisplayRole) - return stripObjName(constr->name, createTable->dialect); + return stripObjName(constr->name); break; } @@ -321,9 +321,9 @@ QString TableConstraintsModel::getTypeLabel(SqliteCreateTable::Constraint::Type case SqliteCreateTable::Constraint::FOREIGN_KEY: return "FOREIGN KEY"; case SqliteCreateTable::Constraint::NAME_ONLY: - return QString::null; + return QString(); } - return QString::null; + return QString(); } QIcon TableConstraintsModel::getTypeIcon(SqliteCreateTable::Constraint::Type type) const @@ -357,9 +357,9 @@ QString TableConstraintsModel::getDetails(SqliteCreateTable::Constraint* constr) case SqliteCreateTable::Constraint::FOREIGN_KEY: return getFkDetails(constr); case SqliteCreateTable::Constraint::NAME_ONLY: - return QString::null; + return QString(); } - return QString::null; + return QString(); } QString TableConstraintsModel::getPkDetails(SqliteCreateTable::Constraint* constr) const diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp index 62b6613..41d6ed9 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.cpp @@ -1,10 +1,11 @@ #include "tablestructuremodel.h" #include "iconmanager.h" #include "common/unused.h" -#include "uiconfig.h" #include <QFont> #include <QDebug> #include <QMimeData> +#include <QApplication> +#include <QStyle> TableStructureModel::TableStructureModel(QObject *parent) : QAbstractTableModel(parent) @@ -26,14 +27,7 @@ int TableStructureModel::columnCount(const QModelIndex& parent) const if (createTable.isNull()) return 0; - switch (createTable->dialect) - { - case Dialect::Sqlite3: - return 9; - case Dialect::Sqlite2: - return 7; - } - return 0; + return 10; } QVariant TableStructureModel::data(const QModelIndex& index, int role) const @@ -109,6 +103,13 @@ QVariant TableStructureModel::data(const QModelIndex& index, int role) const return getColumnCollate(row); } + case TableStructureModel::Columns::GENERATED: + { + if (role != Qt::DecorationRole) + break; + + return getColumnGenerate(row); + } case TableStructureModel::Columns::DEFAULT: { if (role == Qt::FontRole) @@ -142,23 +143,12 @@ QVariant TableStructureModel::headerData(int section, Qt::Orientation orientatio TableStructureModel::Columns TableStructureModel::getHeaderColumn(int colIdx) const { - if (!createTable.isNull() && createTable->dialect == Dialect::Sqlite2) - { - if (colIdx >= 3) - colIdx++; // skip FK - - if (colIdx >= 7) - colIdx++; // skip COLLATE - } return static_cast<Columns>(colIdx); } bool TableStructureModel::isValidColumnIdx(int colIdx) const { - if (!createTable.isNull() && createTable->dialect == Dialect::Sqlite2) - return colIdx >= 0 && colIdx < 7; - - return colIdx >= 0 && colIdx < 9; + return colIdx >= 0 && colIdx < 10; } SqliteCreateTable::Column* TableStructureModel::getColumn(int colIdx) const @@ -313,10 +303,12 @@ QString TableStructureModel::columnLabel(int column) const return tr("Not\nNULL", "table structure columns"); case Columns::COLLATE: return tr("Collate", "table structure columns"); + case Columns::GENERATED: + return tr("Generated", "table structure columns"); case Columns::DEFAULT: return tr("Default value", "table structure columns"); } - return QString::null; + return QString(); } QVariant TableStructureModel::getColumnName(int row) const @@ -378,6 +370,23 @@ QVariant TableStructureModel::getColumnCollate(int row) const return QVariant(); } +QVariant TableStructureModel::getColumnGenerate(int row) const +{ + SqliteCreateTable::Column* column = getColumn(row); + SqliteCreateTable::Column::Constraint* constr = column->getConstraint(SqliteCreateTable::Column::Constraint::GENERATED); + if (!constr) + return QVariant(); + + switch (constr->generatedType) { + case SqliteCreateTable::Column::Constraint::GeneratedType::STORED: + return ICONS.CONSTRAINT_GENERATED_STORED; + case SqliteCreateTable::Column::Constraint::GeneratedType::VIRTUAL: + case SqliteCreateTable::Column::Constraint::GeneratedType::null: + break; + } + return ICONS.CONSTRAINT_GENERATED_VIRTUAL; +} + QVariant TableStructureModel::getColumnDefaultValue(int row) const { QVariant value = getColumnDefault(row); @@ -403,7 +412,7 @@ QVariant TableStructureModel::getColumnDefaultColor(int row) const { QVariant value = getColumnDefault(row); if (value.isNull()) - return QColor(CFG_UI.Colors.DataNullFg); + return QApplication::style()->standardPalette().dark().color(); return QVariant(); } @@ -494,6 +503,14 @@ bool TableStructureModel::isColumnCollate(SqliteCreateTable::Column* column) con return false; } +bool TableStructureModel::isColumnGenerate(SqliteCreateTable::Column* column) const +{ + if (column->hasConstraint(SqliteCreateTable::Column::Constraint::GENERATED)) + return true; + + return false; +} + void TableStructureModel::setCreateTable(SqliteCreateTable* value) { beginResetModel(); diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.h b/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.h index e1cfa4e..088a964 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.h +++ b/SQLiteStudio3/guiSQLiteStudio/windows/tablestructuremodel.h @@ -47,6 +47,7 @@ class GUI_API_EXPORT TableStructureModel : public QAbstractTableModel CHECK, NOTNULL, COLLATE, + GENERATED, DEFAULT }; @@ -54,7 +55,6 @@ class GUI_API_EXPORT TableStructureModel : public QAbstractTableModel bool isValidColumnIdx(int colIdx) const; bool doesColumnHasConstraint(SqliteCreateTable::Column* column, SqliteCreateTable::Column::Constraint::Type type); QString columnLabel(int column) const; - QString columnLabelForSqlite2(int column) const; QVariant getColumnName(int row) const; QVariant getColumnType(int row) const; QVariant getColumnPk(int row) const; @@ -63,6 +63,7 @@ class GUI_API_EXPORT TableStructureModel : public QAbstractTableModel QVariant getColumnCheck(int row) const; QVariant getColumnNotNull(int row) const; QVariant getColumnCollate(int row) const; + QVariant getColumnGenerate(int row) const; QVariant getColumnDefaultValue(int row) const; QVariant getColumnDefaultFont(int row) const; QVariant getColumnDefaultColor(int row) const; @@ -73,6 +74,7 @@ class GUI_API_EXPORT TableStructureModel : public QAbstractTableModel bool isColumnCheck(SqliteCreateTable::Column* column) const; bool isColumnNotNull(SqliteCreateTable::Column* column) const; bool isColumnCollate(SqliteCreateTable::Column* column) const; + bool isColumnGenerate(SqliteCreateTable::Column* column) const; static const constexpr char* mimeType = "application/x-sqlitestudio-tablestructuremodel-row-index"; diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp index 526ae1b..c9356d8 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp @@ -38,6 +38,7 @@ #include "dialogs/importdialog.h" #include "dialogs/populatedialog.h" #include "datagrid/sqlqueryitem.h" +#include "common/dbcombobox.h" #include <QMenu> #include <QToolButton> #include <QLabel> @@ -164,6 +165,7 @@ void TableWindow::init() initActions(); updateTabsOrder(); + createDbCombo(); connect(dataModel, SIGNAL(executionSuccessful()), this, SLOT(executionSuccessful())); connect(dataModel, SIGNAL(executionFailed(QString)), this, SLOT(executionFailed(QString))); @@ -225,6 +227,9 @@ void TableWindow::createStructureActions() createAction(MOVE_COLUMN_UP, ICONS.MOVE_UP, tr("Move column up", "table window"), this, SLOT(moveColumnUp()), ui->structureToolBar, ui->structureView); createAction(MOVE_COLUMN_DOWN, ICONS.MOVE_DOWN, tr("Move column down", "table window"), this, SLOT(moveColumnDown()), ui->structureToolBar, ui->structureView); ui->structureToolBar->addSeparator(); + createAction(ADD_INDEX_STRUCT, ICONS.INDEX_ADD, tr("Create index", "table window"), this, SLOT(addIndex()), ui->structureToolBar, ui->structureView); + createAction(ADD_TRIGGER_STRUCT, ICONS.TRIGGER_ADD, tr("Create trigger", "table window"), this, SLOT(addTrigger()), ui->structureToolBar, ui->structureView); + ui->structureToolBar->addSeparator(); ui->structureToolBar->addAction(actionMap[IMPORT]); ui->structureToolBar->addAction(actionMap[EXPORT]); ui->structureToolBar->addAction(actionMap[POPULATE]); @@ -289,12 +294,16 @@ void TableWindow::editColumn(const QModelIndex& idx) SqliteCreateTable::Column* column = structureModel->getColumn(idx.row()); ColumnDialog columnDialog(db, this); columnDialog.setColumn(column); + if (hasAnyPkDefined() && !column->hasConstraint(SqliteCreateTable::Column::Constraint::PRIMARY_KEY)) + columnDialog.disableConstraint(ConstraintDialog::Constraint::PK); + if (columnDialog.exec() != QDialog::Accepted) return; SqliteCreateTable::Column* modifiedColumn = columnDialog.getModifiedColumn(); structureModel->replaceColumn(idx.row(), modifiedColumn); resizeStructureViewColumns(); + updateTableConstraintsToolbarState(); } void TableWindow::delColumn(const QModelIndex& idx) @@ -314,6 +323,7 @@ void TableWindow::delColumn(const QModelIndex& idx) structureModel->delColumn(idx.row()); resizeStructureViewColumns(); + updateTableConstraintsToolbarState(); } void TableWindow::executeStructureChanges() @@ -441,6 +451,7 @@ void TableWindow::updateTableConstraintsToolbarState() actionMap[DEL_TABLE_CONSTRAINT]->setEnabled(anyColumn && validIdx); actionMap[MOVE_CONSTRAINT_UP]->setEnabled(anyColumn && validIdx && !isFirst); actionMap[MOVE_CONSTRAINT_DOWN]->setEnabled(anyColumn && validIdx && !isLast); + actionMap[ADD_TABLE_PK]->setEnabled(!hasAnyPkDefined()); } void TableWindow::setupDefShortcuts() @@ -480,21 +491,15 @@ void TableWindow::executionFailed(const QString& errorText) void TableWindow::initDbAndTable() { - int totalConstrCols = 6; - if (db->getVersion() == 2) - { - ui->withoutRowIdCheck->setVisible(false); - totalConstrCols -= 2; - } - - totalConstrCols += 2; // we start at 3rd column - for (int colIdx = 2; colIdx < totalConstrCols; colIdx++) + for (int colIdx = 2; colIdx < 9; colIdx++) ui->structureView->setItemDelegateForColumn(colIdx, constraintColumnsDelegate); + ui->dbCombo->setCurrentDb(db); if (existingTable) { dataModel->setDb(db); dataModel->setDatabaseAndTable(database, table); + ui->dbCombo->setDisabled(true); } ui->tableNameEdit->setText(table); // TODO no attached/temp db name support here @@ -563,7 +568,6 @@ void TableWindow::initDbAndTable() connect(ui->withoutRowIdCheck, SIGNAL(clicked()), this, SLOT(withOutRowIdChanged())); - ui->ddlEdit->setSqliteVersion(db->getVersion()); parseDdl(); updateIndexes(); updateTriggers(); @@ -605,7 +609,6 @@ void TableWindow::parseDdl() { createTable = SqliteCreateTablePtr::create(); createTable->table = table; - createTable->dialect = db->getDialect(); } originalCreateTable = SqliteCreateTablePtr::create(*createTable); structureModel->setCreateTable(createTable.data()); @@ -621,6 +624,13 @@ void TableWindow::parseDdl() updateDdlTab(); } +void TableWindow::createDbCombo() +{ + ui->dbCombo->setFixedWidth(100); + ui->dbCombo->setToolTip(tr("Database")); + connect(ui->dbCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(dbChanged())); +} + void TableWindow::changeEvent(QEvent *e) { QWidget::changeEvent(e); @@ -904,6 +914,9 @@ void TableWindow::addColumn() ColumnDialog columnDialog(db, this); columnDialog.setColumn(&column); + if (hasAnyPkDefined()) + columnDialog.disableConstraint(ConstraintDialog::Constraint::PK); + if (columnDialog.exec() != QDialog::Accepted) return; @@ -913,6 +926,7 @@ void TableWindow::addColumn() ui->structureView->setCurrentIndex(structureModel->index(structureModel->rowCount()-1, 0)); resizeStructureViewColumns(); + updateTableConstraintsToolbarState(); } void TableWindow::editColumn() @@ -954,6 +968,9 @@ void TableWindow::moveColumnDown() void TableWindow::addConstraint(ConstraintDialog::Constraint mode) { NewConstraintDialog dialog(mode, createTable.data(), db, this); + if (hasAnyPkDefined()) + dialog.disableMode(ConstraintDialog::PK); + if (dialog.exec() != QDialog::Accepted) return; @@ -968,6 +985,7 @@ void TableWindow::addConstraint(ConstraintDialog::Constraint mode) structureConstraintsModel->appendConstraint(tableConstr); ui->tableConstraintsView->resizeColumnToContents(0); ui->tableConstraintsView->resizeColumnToContents(1); + updateTableConstraintsToolbarState(); } bool TableWindow::validate(bool skipWarning) @@ -1060,7 +1078,7 @@ QString TableWindow::getCurrentIndex() const int row = ui->indexList->currentRow(); QTableWidgetItem* item = ui->indexList->item(row, 0); if (!item) - return QString::null; + return QString(); return item->text(); } @@ -1070,7 +1088,7 @@ QString TableWindow::getCurrentTrigger() const int row = ui->triggerList->currentRow(); QTableWidgetItem* item = ui->triggerList->item(row, 0); if (!item) - return QString::null; + return QString(); return item->text(); } @@ -1100,6 +1118,31 @@ int TableWindow::getStructureTabIdx() const return ui->tabWidget->indexOf(ui->structureTab); } +bool TableWindow::hasAnyPkDefined() const +{ + if (structureConstraintsModel) + { + for (int i = 0, total = structureConstraintsModel->rowCount(); i < total; ++i) + { + SqliteCreateTable::Constraint* constraint = structureConstraintsModel->getConstraint(i); + if (constraint->type == SqliteCreateTable::Constraint::PRIMARY_KEY) + return true; + } + } + + if (structureModel) + { + for (int i = 0, total = structureModel->rowCount(); i < total; ++i) + { + SqliteCreateTable::Column* column = structureModel->getColumn(i); + if (column->hasConstraint(SqliteCreateTable::Column::Constraint::PRIMARY_KEY)) + return true; + } + } + + return false; +} + void TableWindow::updateDdlTab() { createTable->rebuildTokens(); @@ -1121,6 +1164,8 @@ void TableWindow::updateNewTableState() actionMap[CREATE_SIMILAR]->setEnabled(existingTable); actionMap[RESET_AUTOINCREMENT]->setEnabled(existingTable); actionMap[REFRESH_STRUCTURE]->setEnabled(existingTable); + actionMap[ADD_INDEX_STRUCT]->setEnabled(existingTable); + actionMap[ADD_TRIGGER_STRUCT]->setEnabled(existingTable); } void TableWindow::addConstraint() @@ -1173,6 +1218,7 @@ void TableWindow::delConstraint(const QModelIndex& idx) structureConstraintsModel->delConstraint(idx.row()); ui->structureView->resizeColumnToContents(0); + updateTableConstraintsToolbarState(); } void TableWindow::moveConstraintUp() @@ -1309,7 +1355,7 @@ void TableWindow::withOutRowIdChanged() if (!createTable) return; - createTable->withOutRowId = ui->withoutRowIdCheck->isChecked() ? QStringLiteral("ROWID") : QString::null; + createTable->withOutRowId = ui->withoutRowIdCheck->isChecked() ? QStringLiteral("ROWID") : QString(); updateDdlTab(); emit modifyStatusChanged(); } @@ -1446,7 +1492,7 @@ void TableWindow::updateIndexes() return; SchemaResolver resolver(db); - resolver.setIgnoreSystemObjects(true); + resolver.setIgnoreSystemObjects(false); QList<SqliteCreateIndexPtr> indexes = resolver.getParsedIndexesForTable(database, table); ui->indexList->setColumnCount(4); @@ -1458,10 +1504,6 @@ void TableWindow::updateIndexes() tr("Partial index condition", "table window indexes"), }); - Dialect dialect= db->getDialect(); - if (dialect == Dialect::Sqlite2) - ui->indexList->setColumnCount(3); - ui->indexList->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); QTableWidgetItem* item = nullptr; @@ -1482,12 +1524,9 @@ void TableWindow::updateIndexes() item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable); ui->indexList->setItem(row, 2, item); - if (dialect == Dialect::Sqlite3) - { - item = new QTableWidgetItem(index->where ? index->where->detokenize() : ""); - item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable); - ui->indexList->setItem(row, 3, item); - } + item = new QTableWidgetItem(index->where ? index->where->detokenize() : ""); + item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable); + ui->indexList->setItem(row, 3, item); row++; } @@ -1653,3 +1692,13 @@ void TableWindow::updateFont() view->verticalHeader()->setDefaultSectionSize(fm.height() + 4); } } + +void TableWindow::dbChanged() +{ + disconnect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfTableDeleted(QString,QString,DbObjectType))); + + db = ui->dbCombo->currentDb(); + dataModel->setDb(db); + + connect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfTableDeleted(QString,QString,DbObjectType))); +} diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.h b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.h index f44af4f..fb4d67d 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.h +++ b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.h @@ -23,6 +23,7 @@ class WidgetCover; class SqliteSyntaxHighlighter; class CenteredIconItemDelegate; class ConstraintTabModel; +class DbComboBox; namespace Ui { class TableWindow; @@ -76,6 +77,8 @@ class GUI_API_EXPORT TableWindow : public MdiChild ADD_TABLE_CHECK, MOVE_CONSTRAINT_UP, MOVE_CONSTRAINT_DOWN, + ADD_INDEX_STRUCT, + ADD_TRIGGER_STRUCT, EXPORT, IMPORT, POPULATE, @@ -138,6 +141,7 @@ class GUI_API_EXPORT TableWindow : public MdiChild void init(); void newTable(); void parseDdl(); + void createDbCombo(); void initDbAndTable(); void setupCoverWidget(); void createStructureActions(); @@ -162,6 +166,7 @@ class GUI_API_EXPORT TableWindow : public MdiChild void resizeStructureViewColumns(); int getDataTabIdx() const; int getStructureTabIdx() const; + bool hasAnyPkDefined() const; int newTableWindowNum = 1; @@ -183,6 +188,7 @@ class GUI_API_EXPORT TableWindow : public MdiChild bool modifyingThisTable = false; CenteredIconItemDelegate* constraintColumnsDelegate = nullptr; bool tabsMoving = false; + DbComboBox* dbCombo = nullptr; private slots: void executionSuccessful(); @@ -238,6 +244,7 @@ class GUI_API_EXPORT TableWindow : public MdiChild void prevTab(); void updateTabsOrder(); void updateFont(); + void dbChanged(); public slots: void updateIndexes(); diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.ui b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.ui index 14e278a..4ae8bdf 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.ui +++ b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.ui @@ -55,6 +55,16 @@ <number>2</number> </property> <item> + <widget class="DbComboBox" name="dbCombo"> + <property name="maximumSize"> + <size> + <width>200</width> + <height>16777215</height> + </size> + </property> + </widget> + </item> + <item> <widget class="QLabel" name="tableNameLabel"> <property name="text"> <string>Table name:</string> @@ -317,6 +327,11 @@ <extends>QTableWidget</extends> <header>common/exttablewidget.h</header> </customwidget> + <customwidget> + <class>DbComboBox</class> + <extends>QComboBox</extends> + <header>common/dbcombobox.h</header> + </customwidget> </customwidgets> <resources/> <connections/> diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp index c7ec7d8..2181934 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp @@ -45,8 +45,8 @@ ViewWindow::ViewWindow(Db* db, QWidget* parent) : { newView(); init(); + ui->dbCombo->setCurrentDb(db); applyInitialTab(); - updateDbRelatedUiElements(); } ViewWindow::ViewWindow(const ViewWindow& win) : @@ -59,7 +59,6 @@ ViewWindow::ViewWindow(const ViewWindow& win) : init(); initView(); applyInitialTab(); - updateDbRelatedUiElements(); } ViewWindow::ViewWindow(QWidget* parent, Db* db, const QString& database, const QString& view) : @@ -72,7 +71,6 @@ ViewWindow::ViewWindow(QWidget* parent, Db* db, const QString& database, const Q init(); initView(); applyInitialTab(); - updateDbRelatedUiElements(); } ViewWindow::~ViewWindow() @@ -94,6 +92,9 @@ void ViewWindow::changeEvent(QEvent *e) QVariant ViewWindow::saveSession() { + if (!db || DBLIST->isTemporary(db)) + return QVariant(); + QHash<QString,QVariant> sessionValue; sessionValue["view"] = view; sessionValue["db"] = db->getName(); @@ -139,7 +140,6 @@ bool ViewWindow::restoreSession(const QVariant& sessionValue) initView(); applyInitialTab(); - updateDbRelatedUiElements(); return true; } @@ -192,7 +192,7 @@ void ViewWindow::setupDefShortcuts() bool ViewWindow::restoreSessionNextTime() { - return existingView; + return existingView && db && !DBLIST->isTemporary(db); } QToolBar* ViewWindow::getToolBar(int toolbar) const @@ -253,6 +253,7 @@ void ViewWindow::init() updateOutputColumnsVisibility(); updateTabsOrder(); + createDbCombo(); updateFont(); refreshTriggers(); @@ -268,6 +269,13 @@ void ViewWindow::updateAfterInit() ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(tab), existingView); } +void ViewWindow::createDbCombo() +{ + ui->dbCombo->setFixedWidth(100); + ui->dbCombo->setToolTip(tr("Database")); + connect(ui->dbCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(dbChanged())); +} + void ViewWindow::newView() { existingView = false; @@ -283,14 +291,16 @@ void ViewWindow::initView() if (!createView) return; // error occured while parsing ddl, window will be closed + ui->dbCombo->setCurrentDb(db); if (existingView) { dataModel->setDb(db); dataModel->setQuery(originalCreateView->select->detokenize()); dataModel->setView(view); + ui->dbCombo->setDisabled(true); } - ui->queryEdit->setDb(db); + ui->queryEdit->setPlainText(createView->select->detokenize()); if (createView->columns.size() > 0) @@ -301,8 +311,6 @@ void ViewWindow::initView() updateDdlTab(); - ui->ddlEdit->setSqliteVersion(db->getVersion()); - refreshTriggers(); connect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfViewDeleted(QString,QString,DbObjectType))); @@ -454,7 +462,7 @@ QString ViewWindow::getCurrentTrigger() const int row = ui->triggersList->currentRow(); QTableWidgetItem* item = ui->triggersList->item(row, 0); if (!item) - return QString::null; + return QString(); return item->text(); } @@ -475,7 +483,7 @@ QString ViewWindow::getCurrentDdl() const columnsStr = "(" + collectColumnNames().join(", ") + ")"; return ddlTpl.arg( - wrapObjIfNeeded(ui->nameEdit->text(), db->getDialect()), + wrapObjIfNeeded(ui->nameEdit->text()), columnsStr, ui->queryEdit->toPlainText() ); @@ -492,10 +500,9 @@ QStringList ViewWindow::indexedColumnsToNamesOnly(const QList<SqliteIndexedColum QStringList ViewWindow::collectColumnNames() const { - Dialect dialect = db ? db->getDialect() : Dialect::Sqlite3; QStringList cols; for (int row = 0; row < ui->outputColumnsTable->count(); row++) - cols << wrapObjIfNeeded(ui->outputColumnsTable->item(row)->text(), dialect); + cols << wrapObjIfNeeded(ui->outputColumnsTable->item(row)->text()); return cols; } @@ -627,17 +634,20 @@ void ViewWindow::changesSuccessfullyCommitted() database = createView->database; QString oldView = view; view = createView->view; + + if (!existingView) + notifyInfo(tr("View '%1' was committed successfully.").arg(view)); + else if (oldView.compare(view, Qt::CaseInsensitive) == 0) + notifyInfo(tr("Committed changes for view '%1' successfully.").arg(view)); + else + notifyInfo(tr("Committed changes for view '%1' (named before '%2') successfully.").arg(view, oldView)); + existingView = true; initView(); updateQueryToolbarStatus(); updateWindowTitle(); updateAfterInit(); - if (oldView.compare(view, Qt::CaseInsensitive) == 0) - notifyInfo(tr("Committed changes for view '%1' successfully.").arg(view)); - else - notifyInfo(tr("Committed changes for view '%1' (named before '%2') successfully.").arg(view, oldView)); - DBTREE->refreshSchema(db); } @@ -675,6 +685,7 @@ void ViewWindow::prevTab() void ViewWindow::dbClosedFinalCleanup() { + db = nullptr; dataModel->setDb(nullptr); ui->queryEdit->setDb(nullptr); structureExecutor->setDb(nullptr); @@ -827,13 +838,6 @@ void ViewWindow::generateOutputColumns() } } -void ViewWindow::updateDbRelatedUiElements() -{ - bool enabled = db->getDialect() == Dialect::Sqlite3; - outputColumnsCheck->setVisible(enabled); - outputColumnsSeparator->setVisible(enabled); -} - void ViewWindow::updateTabsOrder() { tabsMoving = true; @@ -927,7 +931,6 @@ void ViewWindow::parseDdl() { createView = SqliteCreateViewPtr::create(); createView->view = view; - createView->dialect = db->getDialect(); } originalCreateView = SqliteCreateViewPtr::create(*createView); @@ -972,7 +975,7 @@ bool ViewWindow::validate(bool skipWarnings) // Rebuilding createView statement and validating it on the fly. QString ddl = getCurrentDdl(); - Parser parser(db->getDialect()); + Parser parser; if (!parser.parse(ddl) || parser.getQueries().size() < 1) { notifyError(tr("The SELECT statement could not be parsed. Please correct the query and retry.\nDetails: %1").arg(parser.getErrorString())); @@ -1005,7 +1008,7 @@ void ViewWindow::executeStructureChanges() } else { - Parser parser(db->getDialect()); + Parser parser; if (!parser.parse(theDdl)) { qCritical() << "Could not re-parse the view for executing it:" << parser.getErrorString(); @@ -1069,3 +1072,14 @@ void ViewWindow::updateFont() view->verticalHeader()->setDefaultSectionSize(fm.height() + 4); } } + +void ViewWindow::dbChanged() +{ + disconnect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfViewDeleted(QString,QString,DbObjectType))); + + db = ui->dbCombo->currentDb(); + dataModel->setDb(db); + ui->queryEdit->setDb(db); + + connect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfViewDeleted(QString,QString,DbObjectType))); +} diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.h b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.h index 1a8b5b3..a2ef4f7 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.h +++ b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.h @@ -97,6 +97,7 @@ class GUI_API_EXPORT ViewWindow : public MdiChild private: void init(); void updateAfterInit(); + void createDbCombo(); void newView(); void initView(); void setupCoverWidget(); @@ -163,10 +164,10 @@ class GUI_API_EXPORT ViewWindow : public MdiChild void moveColumnDown(); void updateColumnButtons(); void generateOutputColumns(); - void updateDbRelatedUiElements(); void updateTabsOrder(); void triggerViewDoubleClicked(const QModelIndex& idx); void updateFont(); + void dbChanged(); public slots: void refreshTriggers(); diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.ui b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.ui index 8c17205..5f2acef 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.ui +++ b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.ui @@ -55,6 +55,16 @@ <number>2</number> </property> <item> + <widget class="DbComboBox" name="dbCombo"> + <property name="maximumSize"> + <size> + <width>200</width> + <height>16777215</height> + </size> + </property> + </widget> + </item> + <item> <widget class="QLabel" name="nameLabel"> <property name="text"> <string>View name:</string> @@ -228,15 +238,20 @@ <container>1</container> </customwidget> <customwidget> - <class>SqlEditor</class> - <extends>QPlainTextEdit</extends> - <header>sqleditor.h</header> - </customwidget> - <customwidget> <class>ExtTableWidget</class> <extends>QTableWidget</extends> <header>common/exttablewidget.h</header> </customwidget> + <customwidget> + <class>DbComboBox</class> + <extends>QComboBox</extends> + <header>common/dbcombobox.h</header> + </customwidget> + <customwidget> + <class>SqlEditor</class> + <extends>QPlainTextEdit</extends> + <header>sqleditor.h</header> + </customwidget> </customwidgets> <resources/> <connections/> |
