WIP createdb dialog
This commit is contained in:
parent
c20427e10d
commit
d3080a08bb
10 changed files with 113 additions and 45 deletions
|
|
@ -1,9 +1,12 @@
|
||||||
#include "CreateDatabaseDialog.h"
|
#include "CreateDatabaseDialog.h"
|
||||||
#include "ui_CreateDatabaseDialog.h"
|
#include "ui_CreateDatabaseDialog.h"
|
||||||
|
#include <QStringBuilder>
|
||||||
|
|
||||||
CreateDatabaseDialog::CreateDatabaseDialog(QWidget *parent) :
|
CreateDatabaseDialog::CreateDatabaseDialog(std::shared_ptr<PgDatabaseCatalog> catalog, QWidget *parent)
|
||||||
QDialog(parent),
|
: QDialog(parent)
|
||||||
ui(new Ui::CreateDatabaseDialog)
|
, ui(new Ui::CreateDatabaseDialog)
|
||||||
|
, m_catalog(catalog)
|
||||||
|
, definition(*catalog, InvalidOid, "")
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
}
|
}
|
||||||
|
|
@ -23,3 +26,29 @@ CreateDatabaseDialog::~CreateDatabaseDialog()
|
||||||
// [ ALLOW_CONNECTIONS [=] allowconn ]
|
// [ ALLOW_CONNECTIONS [=] allowconn ]
|
||||||
// [ CONNECTION LIMIT [=] connlimit ]
|
// [ CONNECTION LIMIT [=] connlimit ]
|
||||||
// [ IS_TEMPLATE [=] istemplate ] ]
|
// [ IS_TEMPLATE [=] istemplate ] ]
|
||||||
|
|
||||||
|
void CreateDatabaseDialog::on_tabWidget_currentChanged(int index)
|
||||||
|
{
|
||||||
|
if (index == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// update the sql
|
||||||
|
definition.setObjectName(ui->name->text());
|
||||||
|
|
||||||
|
// definition.setOwnerOid()
|
||||||
|
definition.dbTemplate = ui->dbTemplate->currentText();
|
||||||
|
|
||||||
|
//QString drop_sql = definition.dropSql();
|
||||||
|
QString create_sql = definition.createSql();
|
||||||
|
ui->sqlPreview->setPlainText(create_sql);
|
||||||
|
|
||||||
|
// create_sql += "\n\n-- set Privileges\n";
|
||||||
|
// create_sql += definition.grantSql() % "\n";
|
||||||
|
|
||||||
|
// create_sql += "-- set comment\n";
|
||||||
|
// create_sql += definition.commentSql() % "\n";
|
||||||
|
|
||||||
|
// ui->sqlPreview->setPlainText(drop_sql % "\n\n" % create_sql);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
#include "catalog\PgDatabase.h"
|
||||||
|
|
||||||
|
class PgDatabaseCatalog;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class CreateDatabaseDialog;
|
class CreateDatabaseDialog;
|
||||||
}
|
}
|
||||||
|
|
@ -12,11 +16,17 @@ class CreateDatabaseDialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CreateDatabaseDialog(QWidget *parent = 0);
|
CreateDatabaseDialog(std::shared_ptr<PgDatabaseCatalog> catalog, QWidget *parent = 0);
|
||||||
~CreateDatabaseDialog();
|
~CreateDatabaseDialog();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_tabWidget_currentChanged(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CreateDatabaseDialog *ui;
|
Ui::CreateDatabaseDialog *ui;
|
||||||
|
|
||||||
|
std::shared_ptr<PgDatabaseCatalog> m_catalog;
|
||||||
|
PgDatabase definition;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CREATEDATABASEDIALOG_H
|
#endif // CREATEDATABASEDIALOG_H
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>506</width>
|
<width>506</width>
|
||||||
<height>371</height>
|
<height>542</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
|
@ -15,11 +15,11 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="Input" native="true">
|
<widget class="QWidget" name="Input">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Input</string>
|
<string>Input</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="lineEdit"/>
|
<widget class="QLineEdit" name="name"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
|
|
@ -42,7 +42,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QComboBox" name="comboBox"/>
|
<widget class="QComboBox" name="dbTemplate"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QComboBox" name="comboBox_2"/>
|
<widget class="QComboBox" name="encoding"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
|
|
@ -62,7 +62,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QComboBox" name="comboBox_3"/>
|
<widget class="QComboBox" name="collationOrder"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0">
|
<item row="5" column="0">
|
||||||
<widget class="QLabel" name="label_5">
|
<widget class="QLabel" name="label_5">
|
||||||
|
|
@ -72,7 +72,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="1">
|
<item row="5" column="1">
|
||||||
<widget class="QComboBox" name="comboBox_4"/>
|
<widget class="QComboBox" name="characterClassification"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0">
|
<item row="6" column="0">
|
||||||
<widget class="QLabel" name="label_6">
|
<widget class="QLabel" name="label_6">
|
||||||
|
|
@ -82,7 +82,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="1">
|
<item row="6" column="1">
|
||||||
<widget class="QSpinBox" name="spinBox"/>
|
<widget class="QSpinBox" name="connectionLimit"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0">
|
<item row="7" column="0">
|
||||||
<widget class="QLabel" name="label_8">
|
<widget class="QLabel" name="label_8">
|
||||||
|
|
@ -92,10 +92,10 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="1">
|
<item row="7" column="1">
|
||||||
<widget class="QComboBox" name="comboBox_5"/>
|
<widget class="QComboBox" name="tablespace"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QComboBox" name="comboBox_6"/>
|
<widget class="QComboBox" name="owner"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_7">
|
<widget class="QLabel" name="label_7">
|
||||||
|
|
@ -105,14 +105,14 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="1">
|
<item row="8" column="1">
|
||||||
<widget class="QCheckBox" name="checkBox">
|
<widget class="QCheckBox" name="templateDatabase">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Template database</string>
|
<string>Template database</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="9" column="1">
|
<item row="9" column="1">
|
||||||
<widget class="QCheckBox" name="checkBox_2">
|
<widget class="QCheckBox" name="allowConnections">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Allow connections</string>
|
<string>Allow connections</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -124,6 +124,11 @@
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>SQL</string>
|
<string>SQL</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="CodeEditor" name="sqlPreview"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -139,6 +144,13 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>CodeEditor</class>
|
||||||
|
<extends>QPlainTextEdit</extends>
|
||||||
|
<header>codeeditor\CodeEditor.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,23 @@
|
||||||
#include "DatabasesPage.h"
|
#include "DatabasesPage.h"
|
||||||
|
|
||||||
#include "catalog/models/DatabasesTableModel.h"
|
#include "catalog/models/DatabasesTableModel.h"
|
||||||
#include "widgets/SqlCodePreview.h"
|
#include "widgets/SqlCodePreview.h"
|
||||||
#include "SqlFormattingUtils.h"
|
#include "SqlFormattingUtils.h"
|
||||||
#include "catalog/PgDatabaseCatalog.h"
|
#include "catalog/PgDatabaseCatalog.h"
|
||||||
#include "util/PgLabTableView.h"
|
#include "util/PgLabTableView.h"
|
||||||
|
#include <CreateDatabaseDialog.h>
|
||||||
|
#include <QAction>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
|
||||||
|
|
||||||
DatabasesPage::DatabasesPage(std::shared_ptr<OpenDatabase> opendatabase, QWidget * parent)
|
DatabasesPage::DatabasesPage(std::shared_ptr<OpenDatabase> opendatabase, QWidget * parent)
|
||||||
: QSplitter(Qt::Horizontal, parent)
|
: QSplitter(Qt::Horizontal, parent)
|
||||||
, m_databasesTableView(this, new DatabasesTableModel(opendatabase, this))
|
, m_databasesTableView(this, new DatabasesTableModel(opendatabase, this))
|
||||||
{
|
{
|
||||||
auto tv = m_databasesTableView.tableView();
|
auto tv = m_databasesTableView.tableView();
|
||||||
tv->setSelectionMode(QAbstractItemView::SingleSelection);
|
tv->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
tv->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||||
|
|
||||||
|
auto createDbAction = new QAction("Create database", this);
|
||||||
|
tv->addAction(createDbAction);
|
||||||
|
|
||||||
addWidget(tv);
|
addWidget(tv);
|
||||||
m_tableSql = new SqlCodePreview(this);
|
m_tableSql = new SqlCodePreview(this);
|
||||||
|
|
@ -21,6 +25,12 @@ DatabasesPage::DatabasesPage(std::shared_ptr<OpenDatabase> opendatabase, QWidget
|
||||||
|
|
||||||
connect(m_databasesTableView.tableView()->selectionModel(), &QItemSelectionModel::currentRowChanged,
|
connect(m_databasesTableView.tableView()->selectionModel(), &QItemSelectionModel::currentRowChanged,
|
||||||
this, &DatabasesPage::databaseSelectionChanged);
|
this, &DatabasesPage::databaseSelectionChanged);
|
||||||
|
connect(createDbAction, &QAction::triggered,
|
||||||
|
[this](auto checked)
|
||||||
|
{
|
||||||
|
auto dlg = new CreateDatabaseDialog(this->m_catalog, this);
|
||||||
|
dlg->show();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabasesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
void DatabasesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PgLabTableViewHelper<DatabasesTableModel> m_databasesTableView;
|
PgLabTableViewHelper<DatabasesTableModel> m_databasesTableView;
|
||||||
// QTabWidget *m_detailsTabs = nullptr;
|
|
||||||
SqlCodePreview *m_tableSql = nullptr;
|
SqlCodePreview *m_tableSql = nullptr;
|
||||||
|
|
||||||
std::shared_ptr<PgDatabaseCatalog> m_catalog;
|
std::shared_ptr<PgDatabaseCatalog> m_catalog;
|
||||||
|
|
|
||||||
|
|
@ -23,29 +23,30 @@ QString PgDatabase::dropSql() const
|
||||||
|
|
||||||
QString PgDatabase::createSql() const
|
QString PgDatabase::createSql() const
|
||||||
{
|
{
|
||||||
QString s = "CREATE DATABASE " % quotedObjectName()
|
QString s = "CREATE DATABASE " % quotedObjectName();
|
||||||
// TEMPLATE is missing as this is not stored in the catalog
|
|
||||||
% "\n OWNER " % quoteIdent(ownerName())
|
if (hasOwner())
|
||||||
% "\n ENCODING " % escapeLiteral(encodingString)
|
s += "\n OWNER " % quoteIdent(ownerName());
|
||||||
% "\n LC_COLLATE " % escapeLiteral(collate)
|
if (!dbTemplate.isEmpty())
|
||||||
% "\n LC_TYPE " % escapeLiteral(ctype);
|
s += "\n TEMPLATE " % escapeLiteral(dbTemplate);
|
||||||
|
if (!encodingString.isEmpty())
|
||||||
|
s += "\n ENCODING " % escapeLiteral(encodingString);
|
||||||
|
if (!collate.isEmpty())
|
||||||
|
s += "\n LC_COLLATE " % escapeLiteral(collate);
|
||||||
|
if (!ctype.isEmpty())
|
||||||
|
s += "\n LC_TYPE " % escapeLiteral(ctype);
|
||||||
|
if (tablespace != InvalidOid)
|
||||||
|
{
|
||||||
auto ns = getTablespaceDisplayString(catalog(), tablespace);
|
auto ns = getTablespaceDisplayString(catalog(), tablespace);
|
||||||
if (ns != "pg_default")
|
if (ns != "pg_default")
|
||||||
{
|
|
||||||
s += "\n TABLESPACE " % quoteIdent(ns);
|
s += "\n TABLESPACE " % quoteIdent(ns);
|
||||||
}
|
}
|
||||||
if (!allowConn)
|
if (!allowConn)
|
||||||
{
|
|
||||||
s += "\n ALLOW_CONNECTIONS FALSE";
|
s += "\n ALLOW_CONNECTIONS FALSE";
|
||||||
}
|
|
||||||
if (connLimit >= 0)
|
if (connLimit >= 0)
|
||||||
{
|
|
||||||
s += "\n CONNECTION LIMIT " % QString::number(connLimit);
|
s += "\n CONNECTION LIMIT " % QString::number(connLimit);
|
||||||
}
|
|
||||||
if (isTemplate)
|
if (isTemplate)
|
||||||
{
|
|
||||||
s += "\n IS_TEMPLATE TRUE";
|
s += "\n IS_TEMPLATE TRUE";
|
||||||
}
|
|
||||||
s += ";";
|
s += ";";
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,15 @@
|
||||||
class PgDatabase: public PgServerObject {
|
class PgDatabase: public PgServerObject {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
int encoding;
|
int encoding = 0;
|
||||||
QString encodingString;
|
QString encodingString;
|
||||||
QString collate;
|
QString collate;
|
||||||
QString ctype;
|
QString ctype;
|
||||||
bool isTemplate;
|
QString dbTemplate; ///< Not stored in the catalog but can be present in CREATE DATABASE statement
|
||||||
bool allowConn;
|
bool isTemplate = false;
|
||||||
int connLimit;
|
bool allowConn = true;
|
||||||
Oid tablespace;
|
int connLimit = -1;
|
||||||
|
Oid tablespace = InvalidOid;
|
||||||
|
|
||||||
using PgServerObject::PgServerObject;
|
using PgServerObject::PgServerObject;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,11 @@ const QString& PgObject::objectName() const
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PgObject::setObjectName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
QString PgObject::quotedObjectName() const
|
QString PgObject::quotedObjectName() const
|
||||||
{
|
{
|
||||||
return quoteIdent(objectName());
|
return quoteIdent(objectName());
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ public:
|
||||||
|
|
||||||
Oid oid() const;
|
Oid oid() const;
|
||||||
const QString& objectName() const;
|
const QString& objectName() const;
|
||||||
|
void setObjectName(const QString &name);
|
||||||
/// Default implementation uses objectName and add quotes when needed.
|
/// Default implementation uses objectName and add quotes when needed.
|
||||||
virtual QString quotedObjectName() const;
|
virtual QString quotedObjectName() const;
|
||||||
/// By default same as quotedObjectName however for objects that reside in namespaces
|
/// By default same as quotedObjectName however for objects that reside in namespaces
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ public:
|
||||||
QString commentSql() const;
|
QString commentSql() const;
|
||||||
private:
|
private:
|
||||||
Oid m_ownerOid = InvalidOid;
|
Oid m_ownerOid = InvalidOid;
|
||||||
const PgAuthId * m_owner;
|
const PgAuthId * m_owner = nullptr;
|
||||||
boost::optional<AclList> m_acls;
|
boost::optional<AclList> m_acls;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue