Some stuff I had on another machine and which might provide useful.
This commit is contained in:
parent
23e307f93a
commit
36e5526f5f
10 changed files with 325 additions and 13 deletions
14
pglab/CreateDatabaseDialog.cpp
Normal file
14
pglab/CreateDatabaseDialog.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include "CreateDatabaseDialog.h"
|
||||
#include "ui_CreateDatabaseDialog.h"
|
||||
|
||||
CreateDatabaseDialog::CreateDatabaseDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::CreateDatabaseDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
CreateDatabaseDialog::~CreateDatabaseDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
22
pglab/CreateDatabaseDialog.h
Normal file
22
pglab/CreateDatabaseDialog.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef CREATEDATABASEDIALOG_H
|
||||
#define CREATEDATABASEDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class CreateDatabaseDialog;
|
||||
}
|
||||
|
||||
class CreateDatabaseDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CreateDatabaseDialog(QWidget *parent = 0);
|
||||
~CreateDatabaseDialog();
|
||||
|
||||
private:
|
||||
Ui::CreateDatabaseDialog *ui;
|
||||
};
|
||||
|
||||
#endif // CREATEDATABASEDIALOG_H
|
||||
162
pglab/CreateDatabaseDialog.ui
Normal file
162
pglab/CreateDatabaseDialog.ui
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CreateDatabaseDialog</class>
|
||||
<widget class="QDialog" name="CreateDatabaseDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>506</width>
|
||||
<height>371</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Template</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Encoding</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="comboBox_2"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Collation order</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="comboBox_3"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Character classification</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="comboBox_4"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Connection limit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QSpinBox" name="spinBox"/>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Tablespace</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QComboBox" name="comboBox_5"/>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Owner</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QComboBox" name="comboBox_6"/>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>Template database</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_2">
|
||||
<property name="text">
|
||||
<string>Allow connections</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>CreateDatabaseDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>CreateDatabaseDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
|
@ -32,7 +32,7 @@ bool OpenDatabase::Init()
|
|||
auto kw = m_config.getKeywords();
|
||||
auto vals = m_config.getValues();
|
||||
if (conn.connect(kw, vals, 0)) {
|
||||
m_catalogue->loadAll(conn);
|
||||
m_catalogue->loadAll(conn, nullptr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "PgDatabaseCatalog.h"
|
||||
|
||||
#include "ASyncDBConnection.h"
|
||||
#include "PgAttributeContainer.h"
|
||||
#include "PgAuthIdContainer.h"
|
||||
#include "PgClassContainer.h"
|
||||
|
|
@ -11,6 +12,8 @@
|
|||
#include "Pgsql_Connection.h"
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
#include <QThread>
|
||||
|
||||
using namespace Pgsql;
|
||||
|
||||
QString getRoleNameFromOid(const PgDatabaseCatalog &cat, Oid oid)
|
||||
|
|
@ -100,17 +103,35 @@ PgDatabaseCatalog::~PgDatabaseCatalog()
|
|||
{
|
||||
}
|
||||
|
||||
void PgDatabaseCatalog::loadAll(Pgsql::Connection &conn)
|
||||
void PgDatabaseCatalog::loadAll(Pgsql::Connection &conn,
|
||||
std::function<bool(int, int)> progress_callback)
|
||||
{
|
||||
loadInfo(conn);
|
||||
if (progress_callback && !progress_callback(1, 9))
|
||||
return;
|
||||
load2(m_attributes, conn);
|
||||
if (progress_callback && !progress_callback(2, 9))
|
||||
return;
|
||||
load2(m_authIds, conn);
|
||||
if (progress_callback && !progress_callback(3, 9))
|
||||
return;
|
||||
load2(m_classes, conn);
|
||||
if (progress_callback && !progress_callback(4, 9))
|
||||
return;
|
||||
load2(m_constraints, conn);
|
||||
if (progress_callback && !progress_callback(5, 9))
|
||||
return;
|
||||
load2(m_databases, conn);
|
||||
if (progress_callback && !progress_callback(6, 9))
|
||||
return;
|
||||
load2(m_indexes, conn);
|
||||
if (progress_callback && !progress_callback(7, 9))
|
||||
return;
|
||||
load2(m_namespaces, conn);
|
||||
if (progress_callback && !progress_callback(8, 9))
|
||||
return;
|
||||
load2(m_types, conn);
|
||||
progress_callback && progress_callback(9, 9);
|
||||
}
|
||||
|
||||
void PgDatabaseCatalog::loadInfo(Pgsql::Connection &conn)
|
||||
|
|
@ -128,6 +149,7 @@ void PgDatabaseCatalog::loadInfo(Pgsql::Connection &conn)
|
|||
|
||||
void load(Pgsql::Connection &conn, IPgContainter &pg_cont)
|
||||
{
|
||||
QThread::msleep(400);
|
||||
std::string q = pg_cont.getLoadQuery();
|
||||
Pgsql::Result result = conn.query(q.c_str());
|
||||
if (result && result.resultStatus() == PGRES_TUPLES_OK)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <libpq-fe.h>
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -26,22 +27,13 @@ public:
|
|||
PgDatabaseCatalog();
|
||||
PgDatabaseCatalog(const PgDatabaseCatalog&) = delete;
|
||||
PgDatabaseCatalog& operator = (const PgDatabaseCatalog&) = delete;
|
||||
|
||||
~PgDatabaseCatalog();
|
||||
|
||||
void loadAll(Pgsql::Connection &conn,
|
||||
std::function<bool(int, int)> progress_callback);
|
||||
|
||||
void loadAll(Pgsql::Connection &conn);
|
||||
void loadInfo(Pgsql::Connection &conn);
|
||||
|
||||
//void loadAttributes(Pgsql::Connection &conn);
|
||||
// void loadAuthIds(Pgsql::Connection &conn);
|
||||
// void loadClasses(Pgsql::Connection &conn);
|
||||
// void loadConstraints(Pgsql::Connection &conn);
|
||||
// void loadDatabases(Pgsql::Connection &conn);
|
||||
// void loadIndexes(Pgsql::Connection &conn);
|
||||
// void loadNamespaces(Pgsql::Connection &conn);
|
||||
// void loadTypes(Pgsql::Connection &conn);
|
||||
|
||||
const QString& serverVersionString() const;
|
||||
int serverVersion() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ SOURCES += main.cpp\
|
|||
QueryExplainModel.cpp \
|
||||
ASyncDBConnection.cpp \
|
||||
tsqueue.cpp \
|
||||
CreateDatabaseDialog.cpp \
|
||||
DatabaseWindow.cpp \
|
||||
ConnectionManagerWindow.cpp \
|
||||
ConnectionListModel.cpp \
|
||||
|
|
@ -89,6 +90,7 @@ HEADERS += \
|
|||
QueryExplainModel.h \
|
||||
ASyncDBConnection.h \
|
||||
tsqueue.h \
|
||||
CreateDatabaseDialog.h \
|
||||
DatabaseWindow.h \
|
||||
ConnectionManagerWindow.h \
|
||||
ConnectionListModel.h \
|
||||
|
|
@ -141,6 +143,7 @@ HEADERS += \
|
|||
FORMS += mainwindow.ui \
|
||||
DatabaseWindow.ui \
|
||||
ConnectionManagerWindow.ui \
|
||||
CreateDatabaseDialog.ui \
|
||||
DatabaseInspectorWidget.ui \
|
||||
TuplesResultWidget.ui \
|
||||
QueryTab.ui \
|
||||
|
|
|
|||
1
pgsql/Pgsql_PgException.cpp
Normal file
1
pgsql/Pgsql_PgException.cpp
Normal file
|
|
@ -0,0 +1 @@
|
|||
#include "Pgsql_PgException.h"
|
||||
94
pgsql/Pgsql_PgException.h
Normal file
94
pgsql/Pgsql_PgException.h
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#ifndef PGEXCEPTION_H
|
||||
#define PGEXCEPTION_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace Pgsql {
|
||||
|
||||
class PgException {
|
||||
public:
|
||||
PgException(const char *msg)
|
||||
: message(msg)
|
||||
{}
|
||||
PgException(std::string msg)
|
||||
: message(std::move(msg))
|
||||
{}
|
||||
|
||||
|
||||
private:
|
||||
std::string message;
|
||||
|
||||
};
|
||||
|
||||
class PgResultError: public PgException {
|
||||
public:
|
||||
PgResultError(std::string msg, std::string result_code)
|
||||
: PgException(std::move(msg))
|
||||
{}
|
||||
};
|
||||
|
||||
class PgConnectionError: public PgResultError, std::runtime_error {
|
||||
PgConnectionError(const std::string &msg, std::string result_code)
|
||||
: PgResultError(msg, std::move(result_code))
|
||||
, std::runtime_error(msg)
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* postgresq error classes
|
||||
*
|
||||
* success
|
||||
* warning
|
||||
* no data
|
||||
*
|
||||
* 03 sql statement not yet complete
|
||||
* 08 connection exception -> could be resolved by reconnecting / resetting connection
|
||||
* 09 triggered action exception
|
||||
* 0A feature not supported
|
||||
* 0B invalid transaction initiation
|
||||
* 0F locator exception
|
||||
* 0L invalid grantor
|
||||
* 0P invalid role
|
||||
* 0Z diagnostic exception
|
||||
* 20 case not fount
|
||||
* 21 cardinality violation
|
||||
* 22 data exception
|
||||
* 23 integrity constraint error
|
||||
* 24 invalid cursor statement
|
||||
* 25 invalid transaction state
|
||||
* 26 invalid sql statement name
|
||||
* 27 triggered data change violation
|
||||
* 28 invalid authorization specification
|
||||
* 2B Dependent Privilege Descriptors Still Exist
|
||||
* 2D Invalid Transaction Termination
|
||||
* 2F SQL Routine Exception
|
||||
* 34 Invalid Cursor Name
|
||||
* 38 External Routine Exception
|
||||
* 39 External Routine Invocation Exception
|
||||
* 3B Savepoint Exception
|
||||
* 3D Invalid Catalog Name
|
||||
* 3F Invalid Schema Name
|
||||
* 40 Transaction Rollback
|
||||
* 42 Syntax Error or Access Rule Violation
|
||||
* 44 WITH CHECK OPTION Violation
|
||||
* 53 Insufficient Resources
|
||||
* 54 Program Limit Exceeded
|
||||
* 55 Object Not In Prerequisite State
|
||||
* 57 Operator Intervention
|
||||
* 58 System Error (errors external to PostgreSQL itself)
|
||||
* 72 Snapshot Failure
|
||||
* F0 Configuration File Error
|
||||
* HV Foreign Data Wrapper Error (SQL/MED)
|
||||
* P0 PL/pgSQL Error
|
||||
* XX Internal Error
|
||||
*
|
||||
* At what levels can the communication with postgresql fail
|
||||
* - network -> reset/reconnecting
|
||||
* -
|
||||
*/
|
||||
}
|
||||
|
||||
#endif // PGEXCEPTION_H
|
||||
|
|
@ -34,6 +34,7 @@ release {
|
|||
|
||||
SOURCES += Pgsql_Connection.cpp \
|
||||
Pgsql_Params.cpp \
|
||||
Pgsql_PgException.cpp \
|
||||
Pgsql_Result.cpp \
|
||||
Pgsql_Row.cpp \
|
||||
Pgsql_Value.cpp \
|
||||
|
|
@ -43,6 +44,7 @@ SOURCES += Pgsql_Connection.cpp \
|
|||
|
||||
HEADERS += Pgsql_Connection.h \
|
||||
Pgsql_Params.h \
|
||||
Pgsql_PgException.h \
|
||||
Pgsql_Result.h \
|
||||
Pgsql_Row.h \
|
||||
Pgsql_Value.h \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue