Rework of catalog objects. Several of them are now inheriting from common
base classes that implement common functionality.
This commit is contained in:
parent
840af1e0a9
commit
73c4cf4790
45 changed files with 340 additions and 265 deletions
|
|
@ -35,7 +35,7 @@ void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, con
|
||||||
m_table = table;
|
m_table = table;
|
||||||
m_catalog = cat;
|
m_catalog = cat;
|
||||||
if (m_table) {
|
if (m_table) {
|
||||||
m_columns = cat->attributes()->getColumnsForRelation(table->oid);
|
m_columns = cat->attributes()->getColumnsForRelation(table->oid());
|
||||||
// hide system and dropped columns
|
// hide system and dropped columns
|
||||||
auto column_filter_pred = table->hasoids ? ColumnFilterWithOidsPred : ColumnFilterWithoutOidsPred;
|
auto column_filter_pred = table->hasoids ? ColumnFilterWithOidsPred : ColumnFilterWithoutOidsPred;
|
||||||
auto si = std::remove_if(m_columns.begin(), m_columns.end(), column_filter_pred);
|
auto si = std::remove_if(m_columns.begin(), m_columns.end(), column_filter_pred);
|
||||||
|
|
@ -51,12 +51,12 @@ void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, con
|
||||||
|
|
||||||
|
|
||||||
if (m_table) {
|
if (m_table) {
|
||||||
m_indexes = m_catalog->indexes()->getIndexesForTable(table->oid);
|
m_indexes = m_catalog->indexes()->getIndexesForTable(table->oid());
|
||||||
std::sort(m_indexes.begin(), m_indexes.end(),
|
std::sort(m_indexes.begin(), m_indexes.end(),
|
||||||
[] (const auto &l, const auto &r) -> bool
|
[] (const auto &l, const auto &r) -> bool
|
||||||
{
|
{
|
||||||
return l.isprimary > r.isprimary
|
return l.isprimary > r.isprimary
|
||||||
|| (l.isprimary == r.isprimary && l.indexrelid < r.indexrelid);
|
|| (l.isprimary == r.isprimary && l.oid() < r.oid());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -109,7 +109,7 @@ QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation,
|
||||||
if (section >= colCount) {
|
if (section >= colCount) {
|
||||||
const auto &tbl_idx = m_indexes[section - colCount];
|
const auto &tbl_idx = m_indexes[section - colCount];
|
||||||
//auto idx_cls = m_catalog->classes()->getByKey(tbl_idx.indexrelid);
|
//auto idx_cls = m_catalog->classes()->getByKey(tbl_idx.indexrelid);
|
||||||
auto idx_class_name = getClassDisplayString(*m_catalog, tbl_idx.indexrelid);
|
auto idx_class_name = tbl_idx.objectName(); // getClassDisplayString(*m_catalog, tbl_idx.indexrelid);
|
||||||
QString s;
|
QString s;
|
||||||
if (tbl_idx.isprimary)
|
if (tbl_idx.isprimary)
|
||||||
s = tr("Primary key");
|
s = tr("Primary key");
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ void ConstraintModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, cons
|
||||||
m_table = table;
|
m_table = table;
|
||||||
m_catalog = cat;
|
m_catalog = cat;
|
||||||
if (table) {
|
if (table) {
|
||||||
m_constraints = cat->constraints()->getConstraintsForRelation(table->oid);
|
m_constraints = cat->constraints()->getConstraintsForRelation(table->oid());
|
||||||
std::sort(m_constraints.begin(), m_constraints.end(),
|
std::sort(m_constraints.begin(), m_constraints.end(),
|
||||||
[] (auto &l, auto &r) {
|
[] (auto &l, auto &r) {
|
||||||
return l.type < r.type ||
|
return l.type < r.type ||
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ void CrudModel::setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table
|
||||||
{
|
{
|
||||||
m_database = db;
|
m_database = db;
|
||||||
m_table = table;
|
m_table = table;
|
||||||
m_primaryKey = db->catalog()->constraints()->getPrimaryForRelation(table.oid);
|
m_primaryKey = db->catalog()->constraints()->getPrimaryForRelation(table.oid());
|
||||||
//cat->attributes()->getColumnsForRelation()
|
//cat->attributes()->getColumnsForRelation()
|
||||||
callLoadData = true;
|
callLoadData = true;
|
||||||
auto dbconfig = m_database->config();
|
auto dbconfig = m_database->config();
|
||||||
|
|
@ -163,7 +163,7 @@ QVariant CrudModel::data(const QModelIndex &index, int role) const
|
||||||
|
|
||||||
void CrudModel::loadData()
|
void CrudModel::loadData()
|
||||||
{
|
{
|
||||||
QString table_name = genFQTableName(*m_database->catalog(), m_table);
|
QString table_name = m_table->fullyQualifiedQuotedObjectName(); // genFQTableName(*m_database->catalog(), *m_table);
|
||||||
std::string q = "SELECT * FROM ";
|
std::string q = "SELECT * FROM ";
|
||||||
q += std::string(table_name.toUtf8().data());
|
q += std::string(table_name.toUtf8().data());
|
||||||
m_dbConn.send(q, [this] (Expected<std::shared_ptr<Pgsql::Result>> res, qint64) {
|
m_dbConn.send(q, [this] (Expected<std::shared_ptr<Pgsql::Result>> res, qint64) {
|
||||||
|
|
@ -295,7 +295,7 @@ std::tuple<QString, Pgsql::Params> CrudModel::createUpdateQuery(const PKeyValues
|
||||||
{
|
{
|
||||||
Pgsql::Params params;
|
Pgsql::Params params;
|
||||||
auto data = pending_row.data();
|
auto data = pending_row.data();
|
||||||
QString table_name = genFQTableName(*m_database->catalog(), m_table);
|
QString table_name = m_table->fullyQualifiedQuotedObjectName(); //genFQTableName(*m_database->catalog(), *m_table);
|
||||||
QString buffer;
|
QString buffer;
|
||||||
QTextStream q(&buffer);
|
QTextStream q(&buffer);
|
||||||
q << "UPDATE " << table_name << " AS d\n SET ";
|
q << "UPDATE " << table_name << " AS d\n SET ";
|
||||||
|
|
@ -329,12 +329,12 @@ std::tuple<QString, Pgsql::Params> CrudModel::createInsertQuery(const PendingRow
|
||||||
{
|
{
|
||||||
Pgsql::Params params;
|
Pgsql::Params params;
|
||||||
auto data = pending_row.data();
|
auto data = pending_row.data();
|
||||||
QString table_name = genFQTableName(*m_database->catalog(), m_table);
|
QString table_name = m_table->fullyQualifiedQuotedObjectName(); // genFQTableName(*m_database->catalog(), *m_table);
|
||||||
QString buffer;
|
QString buffer;
|
||||||
QTextStream q(&buffer);
|
QTextStream q(&buffer);
|
||||||
q << "INSERT INTO " << table_name << "(";
|
q << "INSERT INTO " << table_name << "(";
|
||||||
|
|
||||||
auto columns = m_database->catalog()->attributes()->getColumnsForRelation(m_table.oid);
|
auto columns = m_database->catalog()->attributes()->getColumnsForRelation(m_table->oid());
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto e : data) {
|
for (auto e : data) {
|
||||||
int num = e.first + 1;
|
int num = e.first + 1;
|
||||||
|
|
@ -362,7 +362,7 @@ std::tuple<QString, Pgsql::Params> CrudModel::createInsertQuery(const PendingRow
|
||||||
std::tuple<QString, Pgsql::Params> CrudModel::createDeleteStatement(const PKeyValues &pkey_values)
|
std::tuple<QString, Pgsql::Params> CrudModel::createDeleteStatement(const PKeyValues &pkey_values)
|
||||||
{
|
{
|
||||||
Pgsql::Params params;
|
Pgsql::Params params;
|
||||||
QString table_name = genFQTableName(*m_database->catalog(), m_table);
|
QString table_name = m_table->fullyQualifiedQuotedObjectName(); // genFQTableName(*m_database->catalog(), *m_table);
|
||||||
QString buffer;
|
QString buffer;
|
||||||
QTextStream q(&buffer);
|
QTextStream q(&buffer);
|
||||||
q << "DELETE FROM " << table_name;
|
q << "DELETE FROM " << table_name;
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class CrudModel: public QAbstractTableModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CrudModel(ASyncWindow *async_win);
|
explicit CrudModel(ASyncWindow *async_win);
|
||||||
~CrudModel();
|
~CrudModel() override;
|
||||||
|
|
||||||
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
||||||
|
|
||||||
|
|
@ -149,7 +149,7 @@ private:
|
||||||
*/
|
*/
|
||||||
class PendingRow {
|
class PendingRow {
|
||||||
public:
|
public:
|
||||||
using ValueMap = std::map<int16_t, Value>;
|
using ValueMap = std::map<int, Value>;
|
||||||
|
|
||||||
explicit PendingRow(int row)
|
explicit PendingRow(int row)
|
||||||
: m_row(row)
|
: m_row(row)
|
||||||
|
|
@ -232,7 +232,7 @@ private:
|
||||||
|
|
||||||
ASyncWindow * m_asyncWindow;
|
ASyncWindow * m_asyncWindow;
|
||||||
std::shared_ptr<OpenDatabase> m_database;
|
std::shared_ptr<OpenDatabase> m_database;
|
||||||
PgClass m_table;
|
std::optional<PgClass> m_table;
|
||||||
std::optional<PgConstraint> m_primaryKey;
|
std::optional<PgConstraint> m_primaryKey;
|
||||||
ASyncDBConnection m_dbConn;
|
ASyncDBConnection m_dbConn;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "PlgPage.h"
|
#include "PlgPage.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class CrudTab;
|
class CrudTab;
|
||||||
|
|
@ -20,7 +21,7 @@ class CrudTab : public PlgPage
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CrudTab(MainWindow *parent = 0);
|
explicit CrudTab(MainWindow *parent = 0);
|
||||||
~CrudTab();
|
~CrudTab() override;
|
||||||
|
|
||||||
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
||||||
|
|
||||||
|
|
@ -33,7 +34,7 @@ private:
|
||||||
MainWindow *m_window;
|
MainWindow *m_window;
|
||||||
|
|
||||||
std::shared_ptr<OpenDatabase> m_db;
|
std::shared_ptr<OpenDatabase> m_db;
|
||||||
PgClass m_table;
|
std::optional<PgClass> m_table;
|
||||||
|
|
||||||
CrudModel *m_crudModel = nullptr;
|
CrudModel *m_crudModel = nullptr;
|
||||||
std::vector<QAction*> actions;
|
std::vector<QAction*> actions;
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ QVariant DatabasesTableModel::getData(const QModelIndex &index) const
|
||||||
const PgDatabase &db = m_databases->getByIdx(index.row());
|
const PgDatabase &db = m_databases->getByIdx(index.row());
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case NameCol:
|
case NameCol:
|
||||||
v = db.name;
|
v = db.objectName();
|
||||||
break;
|
break;
|
||||||
case DbaCol:
|
case DbaCol:
|
||||||
v = getRoleDisplayString(*m_catalog, db.dba);
|
v = getRoleDisplayString(*m_catalog, db.dba);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ void IndexModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std
|
||||||
m_catalog = cat;
|
m_catalog = cat;
|
||||||
m_table = table;
|
m_table = table;
|
||||||
if (table)
|
if (table)
|
||||||
m_indexes = cat->indexes()->getIndexesForTable(table->oid);
|
m_indexes = cat->indexes()->getIndexesForTable(table->oid());
|
||||||
else
|
else
|
||||||
m_indexes.clear();
|
m_indexes.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +78,7 @@ QVariant IndexModel::getData(const QModelIndex &index) const
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NameCol:
|
case NameCol:
|
||||||
v = getIndexDisplayString(*m_catalog, dat.indexrelid);
|
v = dat.objectName(); // getIndexDisplayString(*m_catalog, dat.indexrelid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AmCol:
|
case AmCol:
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ void MainWindow::newCrudPage(const PgClass &table)
|
||||||
ct->setConfig(m_database, table);
|
ct->setConfig(m_database, table);
|
||||||
// ui->tabWidget->addTab(ct, table.name);
|
// ui->tabWidget->addTab(ct, table.name);
|
||||||
// ui->tabWidget->setCurrentWidget(ct);
|
// ui->tabWidget->setCurrentWidget(ct);
|
||||||
addPage(ct, table.name);
|
addPage(ct, table.objectName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
|
void MainWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ namespace NamespaceItemModel_impl {
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
v = ns.name;
|
v = ns.objectName();
|
||||||
}
|
}
|
||||||
else if (role == Qt::CheckStateRole) {
|
else if (role == Qt::CheckStateRole) {
|
||||||
v = getCheckState();
|
v = getCheckState();
|
||||||
|
|
@ -59,7 +59,7 @@ namespace NamespaceItemModel_impl {
|
||||||
|
|
||||||
bool operator < (const LeafNode &rhs) const
|
bool operator < (const LeafNode &rhs) const
|
||||||
{
|
{
|
||||||
return ns.name < rhs.ns.name;
|
return ns.objectName() < rhs.ns.objectName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,8 @@ QVariant ProcTableModel::getData(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
auto&& t = m_procs->getByIdx(index.row());
|
auto&& t = m_procs->getByIdx(index.row());
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case NameCol: return t.name;
|
case NameCol: return t.objectName();
|
||||||
case NamespaceCol: return t.schemaOid();
|
case NamespaceCol: return t.nsName();
|
||||||
case OwnerCol: return t.owner;
|
case OwnerCol: return t.owner;
|
||||||
case LangCol: return t.lang;
|
case LangCol: return t.lang;
|
||||||
case AclCol: return t.acl;
|
case AclCol: return t.acl;
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ void TablesPage::indexesTable_modelReset()
|
||||||
void TablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
void TablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
PgClass table = m_tablesModel->getTable(index.row());
|
PgClass table = m_tablesModel->getTable(index.row());
|
||||||
if (table.oid != InvalidOid) {
|
if (table.oid() != InvalidOid) {
|
||||||
m_window->newCrudPage(table);
|
m_window->newCrudPage(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@ void TablesTableModel::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||||
// How many?
|
// How many?
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (const auto &e : *classes)
|
for (const auto &e : *classes)
|
||||||
if (e.kind == RelKind::Table && !e.system_namespace) ++n;
|
if (e.kind == RelKind::Table && !e.ns().isSystemCatalog()) ++n;
|
||||||
|
|
||||||
m_tables.clear();
|
m_tables.clear();
|
||||||
m_tables.reserve(n); // reserve space
|
m_tables.reserve(n); // reserve space
|
||||||
for (const auto &e : *classes) {
|
for (const auto &e : *classes) {
|
||||||
if (e.kind == RelKind::Table && !e.system_namespace) {
|
if (e.kind == RelKind::Table && !e.ns().isSystemCatalog()) {
|
||||||
m_tables.push_back(e);
|
m_tables.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,14 +48,14 @@ namespace {
|
||||||
|
|
||||||
inline bool compareByName(PgClass l, PgClass r)
|
inline bool compareByName(PgClass l, PgClass r)
|
||||||
{
|
{
|
||||||
return l.name < r.name
|
return l.objectName() < r.objectName()
|
||||||
|| (l.name == r.name && l.relnamespace_name < r.relnamespace_name);
|
|| (l.objectName() == r.objectName() && l.nsName() < r.nsName());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool compareBySchema(PgClass l, PgClass r)
|
inline bool compareBySchema(PgClass l, PgClass r)
|
||||||
{
|
{
|
||||||
return l.relnamespace_name < r.relnamespace_name
|
return l.nsName() < r.nsName()
|
||||||
|| (l.relnamespace_name == r.relnamespace_name && l.name < r.name);
|
|| (l.nsName() == r.nsName() && l.objectName() < r.objectName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -138,9 +138,9 @@ QVariant TablesTableModel::getData(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
const auto &t = m_tables[index.row()];
|
const auto &t = m_tables[index.row()];
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case NameCol: return t.name; //formatTableName(t);
|
case NameCol: return t.objectName();
|
||||||
case NamespaceCol: return getNamespaceDisplayString(*m_catalog, t.relnamespace);
|
case NamespaceCol: return t.nsName(); //getNamespaceDisplayString(*m_catalog, t.relnamespace);
|
||||||
case OwnerCol: return getRoleDisplayString(*m_catalog, t.owner);
|
case OwnerCol: return t.ownerName();
|
||||||
case TablespaceCol: return getTablespaceDisplayString(*m_catalog, t.tablespace);
|
case TablespaceCol: return getTablespaceDisplayString(*m_catalog, t.tablespace);
|
||||||
case OptionsCol: break;
|
case OptionsCol: break;
|
||||||
case AclCol: return t.acl;
|
case AclCol: return t.acl;
|
||||||
|
|
@ -156,15 +156,15 @@ PgClass TablesTableModel::getTable(int row) const
|
||||||
|
|
||||||
Oid TablesTableModel::getTableOid(int row) const
|
Oid TablesTableModel::getTableOid(int row) const
|
||||||
{
|
{
|
||||||
return m_tables[row].oid;
|
return m_tables[row].oid();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TablesTableModel::formatTableName(const PgClass &cls) const
|
//QString TablesTableModel::formatTableName(const PgClass &cls) const
|
||||||
{
|
//{
|
||||||
const char * format = "%2 (%1)";
|
// const char * format = "%2 (%1)";
|
||||||
QString ns_name = getNamespaceDisplayString(*m_catalog, cls.relnamespace);
|
// QString ns_name = getNamespaceDisplayString(*m_catalog, cls.relnamespace);
|
||||||
return QString(format).arg(ns_name).arg(cls.name);
|
// return QString(format).arg(ns_name).arg(cls.objectName());
|
||||||
}
|
//}
|
||||||
|
|
||||||
QVariant TablesTableModel::data(const QModelIndex &index, int role) const
|
QVariant TablesTableModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ private:
|
||||||
|
|
||||||
Oid getType(int column) const;
|
Oid getType(int column) const;
|
||||||
QVariant getData(const QModelIndex &index) const;
|
QVariant getData(const QModelIndex &index) const;
|
||||||
QString formatTableName(const PgClass &cls) const;
|
// QString formatTableName(const PgClass &cls) const;
|
||||||
void doSort(int so);
|
void doSort(int so);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ void TriggerPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||||
|
|
||||||
void TriggerPage::setFilter(const std::optional<PgClass> &cls)
|
void TriggerPage::setFilter(const std::optional<PgClass> &cls)
|
||||||
{
|
{
|
||||||
m_sortFilterProxy->setOidFilterTable(cls ? cls->oid : InvalidOid, FirstHiddenValue);
|
m_sortFilterProxy->setOidFilterTable(cls ? cls->oid() : InvalidOid, FirstHiddenValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ QVariant TriggerTableModel::getData(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
auto&& t = m_triggers->getByIdx(index.row());
|
auto&& t = m_triggers->getByIdx(index.row());
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case NameCol: return t.name;
|
case NameCol: return t.objectName();
|
||||||
case EventsCol: return t.eventAbbr();
|
case EventsCol: return t.eventAbbr();
|
||||||
case WhenCol: return t.typeFireWhen();
|
case WhenCol: return t.typeFireWhen();
|
||||||
case DeferrableCol: return t.deferrable;
|
case DeferrableCol: return t.deferrable;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "PgClass.h"
|
#include "PgClass.h"
|
||||||
|
|
||||||
|
|
||||||
void operator<<(RelPersistence &s, const Pgsql::Value &v)
|
void operator<<(RelPersistence &s, const Pgsql::Value &v)
|
||||||
{
|
{
|
||||||
//s = static_cast<T>(v);
|
//s = static_cast<T>(v);
|
||||||
|
|
@ -48,3 +49,8 @@ void operator<<(RelKind &s, const Pgsql::Value &v)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//QString PgClass::objectName() const
|
||||||
|
//{
|
||||||
|
// return name;
|
||||||
|
//}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#define PGCLASS_H
|
#define PGCLASS_H
|
||||||
|
|
||||||
#include "Pgsql_Value.h"
|
#include "Pgsql_Value.h"
|
||||||
|
#include "PgNamespaceObject.h"
|
||||||
|
#include "PgOwnedObject.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
|
|
@ -27,17 +29,17 @@ enum class RelKind {
|
||||||
void operator<<(RelKind &s, const Pgsql::Value &v);
|
void operator<<(RelKind &s, const Pgsql::Value &v);
|
||||||
|
|
||||||
|
|
||||||
class PgClass {
|
class PgClass: public PgNamespaceObject, public PgOwnedObject {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Oid oid = InvalidOid;
|
// Oid oid = InvalidOid;
|
||||||
QString name;
|
// QString name;
|
||||||
Oid relnamespace = InvalidOid;
|
// Oid relnamespace = InvalidOid;
|
||||||
QString relnamespace_name; // Transient, cached value from relnamespace
|
// QString relnamespace_name; // Transient, cached value from relnamespace
|
||||||
bool system_namespace = false; // Transient, cached value from relnamespace
|
// bool system_namespace = false; // Transient, cached value from relnamespace
|
||||||
Oid type = InvalidOid;
|
Oid type = InvalidOid;
|
||||||
Oid oftype = InvalidOid;
|
Oid oftype = InvalidOid;
|
||||||
Oid owner = InvalidOid;
|
//Oid owner = InvalidOid;
|
||||||
Oid am = InvalidOid;
|
Oid am = InvalidOid;
|
||||||
Oid filenode = InvalidOid;
|
Oid filenode = InvalidOid;
|
||||||
Oid tablespace = InvalidOid;
|
Oid tablespace = InvalidOid;
|
||||||
|
|
@ -54,10 +56,14 @@ public:
|
||||||
QString acl;
|
QString acl;
|
||||||
std::vector<QString> options;
|
std::vector<QString> options;
|
||||||
|
|
||||||
bool operator==(Oid _oid) const { return oid == _oid; }
|
using PgNamespaceObject::PgNamespaceObject;
|
||||||
bool operator==(const QString &n) const { return name == n; }
|
|
||||||
bool operator<(Oid _oid) const { return oid < _oid; }
|
// virtual QString objectName() const override;
|
||||||
bool operator<(const PgClass &rhs) const { return oid < rhs.oid; }
|
|
||||||
|
// bool operator==(Oid _oid) const { return oid == _oid; }
|
||||||
|
// bool operator==(const QString &n) const { return objectName() == n; }
|
||||||
|
// bool operator<(Oid _oid) const { return oid < _oid; }
|
||||||
|
// bool operator<(const PgClass &rhs) const { return oid < rhs.oid; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,22 @@ std::string PgClassContainer::getLoadQuery() const
|
||||||
PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
||||||
{
|
{
|
||||||
Pgsql::Col col(row);
|
Pgsql::Col col(row);
|
||||||
PgClass v;
|
Oid class_oid = col.nextValue();
|
||||||
col >> v.oid >> v.name >> v.relnamespace >> v.type >> v.oftype
|
QString name = col.nextValue();
|
||||||
>> v.owner >> v.am >> v.filenode >> v.tablespace >> v.pages_est
|
Oid schema_oid = col.nextValue();
|
||||||
|
|
||||||
|
PgClass v(m_catalog, class_oid, name, schema_oid);
|
||||||
|
Oid owner ;
|
||||||
|
col >> v.type >> v.oftype
|
||||||
|
>> owner >> v.am >> v.filenode >> v.tablespace >> v.pages_est
|
||||||
>> v.tuples_est >> v.toastrelid >> v.isshared >> v.persistence
|
>> v.tuples_est >> v.toastrelid >> v.isshared >> v.persistence
|
||||||
>> v.kind >> v.hasoids >> v.ispopulated >> v.frozenxid >> v.minmxid
|
>> v.kind >> v.hasoids >> v.ispopulated >> v.frozenxid >> v.minmxid
|
||||||
>> v.acl >> v.options;
|
>> v.acl >> v.options;
|
||||||
|
v.setOwnerOid(m_catalog, owner);
|
||||||
auto&& ns = m_catalog.namespaces()->getByKey(v.relnamespace);
|
// auto&& ns = m_catalog.namespaces()->getByKey(v.relnamespace);
|
||||||
if (ns) {
|
// if (ns) {
|
||||||
v.relnamespace_name = ns->name;
|
// v.relnamespace_name = ns->objectName();
|
||||||
v.system_namespace = ns->isSystemCatalog();
|
// v.system_namespace = ns->isSystemCatalog();
|
||||||
}
|
// }
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,2 @@
|
||||||
#include "PgDatabase.h"
|
#include "PgDatabase.h"
|
||||||
|
|
||||||
PgDatabase::PgDatabase()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
#ifndef PGDATABASE_H
|
#ifndef PGDATABASE_H
|
||||||
#define PGDATABASE_H
|
#define PGDATABASE_H
|
||||||
|
|
||||||
|
#include "PgServerObject.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
class PgDatabase {
|
class PgDatabase: public PgServerObject {
|
||||||
public:
|
public:
|
||||||
PgDatabase();
|
|
||||||
|
|
||||||
Oid oid = InvalidOid;
|
// Oid oid = InvalidOid;
|
||||||
QString name;
|
// QString name;
|
||||||
Oid dba; // owner?
|
Oid dba; // owner?
|
||||||
int encoding;
|
int encoding;
|
||||||
QString collate;
|
QString collate;
|
||||||
|
|
@ -20,12 +20,14 @@ public:
|
||||||
Oid tablespace;
|
Oid tablespace;
|
||||||
QString acl;//"ARRAY";"YES"
|
QString acl;//"ARRAY";"YES"
|
||||||
|
|
||||||
bool isValid() const { return oid != InvalidOid; }
|
using PgServerObject::PgServerObject;
|
||||||
|
|
||||||
bool operator==(Oid _oid) const { return oid == _oid; }
|
bool isValid() const { return oid() != InvalidOid; }
|
||||||
bool operator==(const QString &n) const { return name == n; }
|
|
||||||
bool operator<(Oid _oid) const { return oid < _oid; }
|
// bool operator==(Oid _oid) const { return oid() == _oid; }
|
||||||
bool operator<(const PgDatabase &rhs) const { return oid < rhs.oid; }
|
// bool operator==(const QString &n) const { return objectName() == n; }
|
||||||
|
// bool operator<(Oid _oid) const { return oid() < _oid; }
|
||||||
|
// bool operator<(const PgDatabase &rhs) const { return oid() < rhs.oid(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGDATABASE_H
|
#endif // PGDATABASE_H
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ QString getNamespaceDisplayString(const PgDatabaseCatalog &cat, Oid oid)
|
||||||
auto nss = cat.namespaces();
|
auto nss = cat.namespaces();
|
||||||
auto ns = nss->getByKey(oid);
|
auto ns = nss->getByKey(oid);
|
||||||
if (ns)
|
if (ns)
|
||||||
result = ns->name; //QString("ns %1").arg(oid);
|
result = ns->objectName(); //QString("ns %1").arg(oid);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ QString getClassDisplayString(const PgDatabaseCatalog &cat, Oid oid)
|
||||||
auto l = cat.classes();
|
auto l = cat.classes();
|
||||||
auto e = l->getByKey(oid);
|
auto e = l->getByKey(oid);
|
||||||
if (e)
|
if (e)
|
||||||
result = e->name;
|
result = e->objectName();
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -146,25 +146,29 @@ void PgDatabaseCatalog::loadAll(Pgsql::Connection &conn,
|
||||||
int n = 0;
|
int n = 0;
|
||||||
if (progress_callback && !progress_callback(++n, count))
|
if (progress_callback && !progress_callback(++n, count))
|
||||||
return;
|
return;
|
||||||
load2(m_namespaces, conn);
|
|
||||||
|
// First load server objects
|
||||||
|
load2(m_authIds, conn);
|
||||||
if (progress_callback && !progress_callback(++n, count))
|
if (progress_callback && !progress_callback(++n, count))
|
||||||
return;
|
return;
|
||||||
load2(m_tablespaces, conn);
|
load2(m_tablespaces, conn);
|
||||||
|
if (progress_callback && !progress_callback(++n, count))
|
||||||
|
return;
|
||||||
|
load2(m_databases, conn);
|
||||||
|
if (progress_callback && !progress_callback(++n, count))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Load database objects
|
||||||
|
load2(m_namespaces, conn);
|
||||||
if (progress_callback && !progress_callback(++n, count))
|
if (progress_callback && !progress_callback(++n, count))
|
||||||
return;
|
return;
|
||||||
load2(m_classes, conn); // needs namespaces
|
load2(m_classes, conn); // needs namespaces
|
||||||
if (progress_callback && !progress_callback(++n, count))
|
if (progress_callback && !progress_callback(++n, count))
|
||||||
return;
|
return;
|
||||||
load2(m_attributes, conn);
|
load2(m_attributes, conn);
|
||||||
if (progress_callback && !progress_callback(++n, count))
|
|
||||||
return;
|
|
||||||
load2(m_authIds, conn);
|
|
||||||
if (progress_callback && !progress_callback(++n, count))
|
if (progress_callback && !progress_callback(++n, count))
|
||||||
return;
|
return;
|
||||||
load2(m_constraints, conn);
|
load2(m_constraints, conn);
|
||||||
if (progress_callback && !progress_callback(++n, count))
|
|
||||||
return;
|
|
||||||
load2(m_databases, conn);
|
|
||||||
if (progress_callback && !progress_callback(++n, count))
|
if (progress_callback && !progress_callback(++n, count))
|
||||||
return;
|
return;
|
||||||
load2(m_indexes, conn);
|
load2(m_indexes, conn);
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,11 @@ std::string PgDatabaseContainer::getLoadQuery() const
|
||||||
PgDatabase PgDatabaseContainer::loadElem(const Pgsql::Row &row)
|
PgDatabase PgDatabaseContainer::loadElem(const Pgsql::Row &row)
|
||||||
{
|
{
|
||||||
Pgsql::Col col(row);
|
Pgsql::Col col(row);
|
||||||
PgDatabase v;
|
|
||||||
col >> v.oid >> v.name >> v.dba >> v.encoding >> v.collate >> v.ctype >> v.isTemplate
|
Oid oid = col.nextValue();
|
||||||
|
QString name = col.nextValue();
|
||||||
|
PgDatabase v(m_catalog, oid, name);
|
||||||
|
col >> v.dba >> v.encoding >> v.collate >> v.ctype >> v.isTemplate
|
||||||
>> v.allowConn >> v.connLimit >> v.tablespace >> v.acl;
|
>> v.allowConn >> v.connLimit >> v.tablespace >> v.acl;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,11 @@ QString PgIndex::getAm() const
|
||||||
{
|
{
|
||||||
auto&& cat = catalog();
|
auto&& cat = catalog();
|
||||||
QString result;
|
QString result;
|
||||||
auto idxcls = cat.classes()->getByKey(indexrelid);
|
auto idxcls = cat.classes()->getByKey(oid());
|
||||||
if (idxcls) {
|
if (idxcls) {
|
||||||
auto am = cat.ams()->getByKey(idxcls->am);
|
auto am = cat.ams()->getByKey(idxcls->am);
|
||||||
if (am)
|
if (am)
|
||||||
result = am->name;
|
result = am->name; // objectName();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PgIndex::objectName() const
|
|
||||||
{
|
|
||||||
return getAm();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
#ifndef PGINDEX_H
|
#ifndef PGINDEX_H
|
||||||
#define PGINDEX_H
|
#define PGINDEX_H
|
||||||
|
|
||||||
#include "PgSchemaObject.h"
|
#include "PgNamespaceObject.h"
|
||||||
#include "Pgsql_declare.h"
|
#include "Pgsql_declare.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class PgIndex : public PgSchemaObject {
|
class PgIndex : public PgNamespaceObject {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Oid indexrelid = InvalidOid; // oid of pg_class for this index
|
// Oid indexrelid = InvalidOid; // oid of pg_class for this index
|
||||||
Oid relid = InvalidOid; // oid of table (pg_class) where this is an index on
|
Oid relid = InvalidOid; // oid of table (pg_class) where this is an index on
|
||||||
int16_t natts = 0;
|
int16_t natts = 0;
|
||||||
bool isunique = false;
|
bool isunique = false;
|
||||||
|
|
@ -30,14 +30,13 @@ public:
|
||||||
QString pred;
|
QString pred;
|
||||||
QString definition;
|
QString definition;
|
||||||
|
|
||||||
using PgSchemaObject::PgSchemaObject;
|
using PgNamespaceObject::PgNamespaceObject;
|
||||||
QString getAm() const;
|
QString getAm() const;
|
||||||
virtual QString objectName() const override;
|
|
||||||
|
|
||||||
bool operator==(Oid _oid) const { return indexrelid == _oid; }
|
// bool operator==(Oid _oid) const { return indexrelid == _oid; }
|
||||||
//bool operator==(const QString &n) const { return name == n; }
|
// //bool operator==(const QString &n) const { return name == n; }
|
||||||
bool operator<(Oid _oid) const { return indexrelid < _oid; }
|
// bool operator<(Oid _oid) const { return indexrelid < _oid; }
|
||||||
bool operator<(const PgIndex &rhs) const { return indexrelid < rhs.indexrelid; }
|
// bool operator<(const PgIndex &rhs) const { return indexrelid < rhs.indexrelid; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGINDEX_H
|
#endif // PGINDEX_H
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "PgIndexContainer.h"
|
#include "PgIndexContainer.h"
|
||||||
|
#include "PgClassContainer.h"
|
||||||
#include "PgDatabaseCatalog.h"
|
#include "PgDatabaseCatalog.h"
|
||||||
#include "Pgsql_Col.h"
|
#include "Pgsql_Col.h"
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
@ -21,8 +22,13 @@ SELECT indexrelid, indrelid, indnatts, indisunique, indisprimary,
|
||||||
PgIndex PgIndexContainer::loadElem(const Pgsql::Row &row)
|
PgIndex PgIndexContainer::loadElem(const Pgsql::Row &row)
|
||||||
{
|
{
|
||||||
Pgsql::Col col(row);
|
Pgsql::Col col(row);
|
||||||
PgIndex v(m_catalog);
|
Oid indexrelid = col.nextValue();
|
||||||
col >> v.indexrelid >> v.relid >> v.natts >> v.isunique
|
auto&& cls = m_catalog.classes()->getByKey(indexrelid);
|
||||||
|
auto&& name = cls->objectName();
|
||||||
|
auto&& nsoid = cls->nsOid();
|
||||||
|
|
||||||
|
PgIndex v(m_catalog, indexrelid, name, nsoid);
|
||||||
|
col >> v.relid >> v.natts >> v.isunique
|
||||||
>> v.isprimary >> v.isexclusion >> v.immediate >> v.isclustered
|
>> v.isprimary >> v.isexclusion >> v.immediate >> v.isclustered
|
||||||
>> v.isvalid >> v.checkxmin >> v.isready >> v.islive;
|
>> v.isvalid >> v.checkxmin >> v.isready >> v.islive;
|
||||||
col.getAsVector<int16_t>(std::back_inserter(v.key));
|
col.getAsVector<int16_t>(std::back_inserter(v.key));
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#include "PgNamespace.h"
|
#include "PgNamespace.h"
|
||||||
|
|
||||||
PgNamespace::PgNamespace() = default;
|
|
||||||
|
|
||||||
bool PgNamespace::isSystemCatalog() const
|
bool PgNamespace::isSystemCatalog() const
|
||||||
{
|
{
|
||||||
return name.startsWith("pg_")
|
auto&& n = objectName();
|
||||||
|| name == "information_schema";
|
return n.startsWith("pg_")
|
||||||
|
|| n == "information_schema";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,26 @@
|
||||||
#ifndef PGNAMESPACE_H
|
#ifndef PGNAMESPACE_H
|
||||||
#define PGNAMESPACE_H
|
#define PGNAMESPACE_H
|
||||||
|
|
||||||
|
#include "PgDatabaseObject.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
class PgNamespace {
|
|
||||||
public:
|
|
||||||
PgNamespace();
|
|
||||||
|
|
||||||
Oid oid = InvalidOid;
|
/// Object representing a namespace within a database
|
||||||
QString name;
|
class PgNamespace: public PgDatabaseObject {
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Oid oid = InvalidOid;
|
||||||
|
// QString name;
|
||||||
Oid owner = InvalidOid;
|
Oid owner = InvalidOid;
|
||||||
QString acl;
|
QString acl;
|
||||||
|
|
||||||
bool operator==(Oid _oid) const { return oid == _oid; }
|
using PgDatabaseObject::PgDatabaseObject;
|
||||||
bool operator==(const QString &n) const { return name == n; }
|
|
||||||
bool operator<(Oid _oid) const { return oid < _oid; }
|
// bool operator==(Oid _oid) const { return oid == _oid; }
|
||||||
bool operator<(const PgNamespace &rhs) const { return oid < rhs.oid; }
|
// bool operator==(const QString &n) const { return objectName() == n; }
|
||||||
|
// bool operator<(Oid _oid) const { return oid < _oid; }
|
||||||
|
// bool operator<(const PgNamespace &rhs) const { return oid < rhs.oid; }
|
||||||
|
|
||||||
bool isSystemCatalog() const;
|
bool isSystemCatalog() const;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,11 @@ std::string PgNamespaceContainer::getLoadQuery() const
|
||||||
PgNamespace PgNamespaceContainer::loadElem(const Pgsql::Row &row)
|
PgNamespace PgNamespaceContainer::loadElem(const Pgsql::Row &row)
|
||||||
{
|
{
|
||||||
Pgsql::Col col(row);
|
Pgsql::Col col(row);
|
||||||
PgNamespace v;
|
|
||||||
col >> v.oid >> v.name >> v.owner >> v.acl;
|
Oid oid = col.nextValue();
|
||||||
|
QString name = col.nextValue();
|
||||||
|
PgNamespace v(m_catalog, oid, name);
|
||||||
|
col >> v.owner >> v.acl;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
40
pglablib/PgNamespaceObject.cpp
Normal file
40
pglablib/PgNamespaceObject.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#include "PgNamespaceObject.h"
|
||||||
|
#include "PgDatabaseCatalog.h"
|
||||||
|
#include "PgNamespace.h"
|
||||||
|
#include "PgNamespaceContainer.h"
|
||||||
|
#include "SqlFormattingUtils.h"
|
||||||
|
|
||||||
|
PgNamespaceObject::PgNamespaceObject(PgDatabaseCatalog& cat, Oid oid, const QString &name, Oid schema_oid)
|
||||||
|
: PgDatabaseObject(cat, oid, name)
|
||||||
|
, m_schemaOid(schema_oid)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Oid PgNamespaceObject::nsOid() const
|
||||||
|
{
|
||||||
|
return m_schemaOid;
|
||||||
|
}
|
||||||
|
|
||||||
|
//void PgSchemaObject::setSchemaOid(Oid oid)
|
||||||
|
//{
|
||||||
|
// m_schemaOid = oid;
|
||||||
|
//}
|
||||||
|
|
||||||
|
QString PgNamespaceObject::nsName() const
|
||||||
|
{
|
||||||
|
return ns().objectName();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PgNamespaceObject::quotedNsName() const
|
||||||
|
{
|
||||||
|
return quoteIdent(nsName());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PgNamespaceObject::fullyQualifiedQuotedObjectName() const
|
||||||
|
{
|
||||||
|
return quotedNsName() + "." + quotedObjectName();
|
||||||
|
}
|
||||||
|
|
||||||
|
const PgNamespace& PgNamespaceObject::ns() const
|
||||||
|
{
|
||||||
|
return *catalog().namespaces()->getByKey(m_schemaOid);
|
||||||
|
}
|
||||||
|
|
@ -8,13 +8,15 @@
|
||||||
class PgNamespace;
|
class PgNamespace;
|
||||||
|
|
||||||
/// Base class for database objects that are part of a specific schema
|
/// Base class for database objects that are part of a specific schema
|
||||||
class PgSchemaObject: public PgDatabaseObject {
|
class PgNamespaceObject: public PgDatabaseObject {
|
||||||
public:
|
public:
|
||||||
using PgDatabaseObject::PgDatabaseObject;
|
|
||||||
|
|
||||||
Oid schemaOid() const;
|
PgNamespaceObject(PgDatabaseCatalog& cat, Oid oid, const QString &name, Oid schema_oid);
|
||||||
void setSchemaOid(Oid oid);
|
|
||||||
QString quotedSchemaName() const;
|
Oid nsOid() const;
|
||||||
|
// void setSchemaOid(Oid oid);
|
||||||
|
QString nsName() const;
|
||||||
|
QString quotedNsName() const;
|
||||||
/// Returns the schema name and object name with proper quotes
|
/// Returns the schema name and object name with proper quotes
|
||||||
QString fullyQualifiedQuotedObjectName() const;
|
QString fullyQualifiedQuotedObjectName() const;
|
||||||
|
|
||||||
|
|
@ -1,13 +1,25 @@
|
||||||
#include "PgObject.h"
|
#include "PgObject.h"
|
||||||
#include "SqlFormattingUtils.h"
|
#include "SqlFormattingUtils.h"
|
||||||
|
|
||||||
PgObject::PgObject(PgDatabaseCatalog& cat)
|
PgObject::PgObject(PgDatabaseCatalog& cat, Oid oid, const QString &name)
|
||||||
: m_catalog(&cat)
|
: m_catalog(&cat)
|
||||||
|
, m_oid(oid)
|
||||||
|
, m_name(name)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
PgObject::~PgObject()
|
PgObject::~PgObject()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
Oid PgObject::oid() const
|
||||||
|
{
|
||||||
|
return m_oid;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& PgObject::objectName() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
QString PgObject::quotedObjectName() const
|
QString PgObject::quotedObjectName() const
|
||||||
{
|
{
|
||||||
return quoteIdent(objectName());
|
return quoteIdent(objectName());
|
||||||
|
|
@ -17,3 +29,8 @@ const PgDatabaseCatalog& PgObject::catalog() const
|
||||||
{
|
{
|
||||||
return *m_catalog;
|
return *m_catalog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test(PgObject a, PgObject b)
|
||||||
|
{
|
||||||
|
a = b;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,32 @@
|
||||||
#ifndef PGOBJECT_H
|
#ifndef PGOBJECT_H
|
||||||
#define PGOBJECT_H
|
#define PGOBJECT_H
|
||||||
|
|
||||||
|
#include <libpq-fe.h>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
|
|
||||||
class PgObject {
|
class PgObject {
|
||||||
public:
|
public:
|
||||||
explicit PgObject(PgDatabaseCatalog& cat);
|
explicit PgObject(PgDatabaseCatalog& cat, Oid oid, const QString &name);
|
||||||
virtual ~PgObject();
|
virtual ~PgObject();
|
||||||
|
|
||||||
virtual QString objectName() const = 0;
|
Oid oid() const;
|
||||||
|
const QString& objectName() const;
|
||||||
/// 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;
|
||||||
|
|
||||||
|
bool operator==(Oid _oid) const { return m_oid == _oid; }
|
||||||
|
bool operator==(const QString &n) const { return m_name == n; }
|
||||||
|
bool operator<(Oid _oid) const { return m_oid < _oid; }
|
||||||
|
bool operator<(const PgObject &rhs) const { return m_oid < rhs.m_oid; }
|
||||||
protected:
|
protected:
|
||||||
const PgDatabaseCatalog& catalog() const;
|
const PgDatabaseCatalog& catalog() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PgDatabaseCatalog* m_catalog;
|
PgDatabaseCatalog* m_catalog;
|
||||||
|
Oid m_oid;
|
||||||
|
QString m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGOBJECT_H
|
#endif // PGOBJECT_H
|
||||||
|
|
|
||||||
25
pglablib/PgOwnedObject.cpp
Normal file
25
pglablib/PgOwnedObject.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include "PgOwnedObject.h"
|
||||||
|
#include "PgAuthId.h"
|
||||||
|
#include "PgAuthIdContainer.h"
|
||||||
|
#include "PgDatabaseCatalog.h"
|
||||||
|
|
||||||
|
void PgOwnedObject::setOwnerOid(PgDatabaseCatalog& cat, Oid oid)
|
||||||
|
{
|
||||||
|
m_ownerOid = oid;
|
||||||
|
m_owner = cat.authIds()->getByKey(oid);
|
||||||
|
}
|
||||||
|
|
||||||
|
Oid PgOwnedObject::ownerOid() const
|
||||||
|
{
|
||||||
|
return m_ownerOid;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PgOwnedObject::ownerName() const
|
||||||
|
{
|
||||||
|
return m_owner->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PgAuthId* PgOwnedObject::owner() const
|
||||||
|
{
|
||||||
|
return m_owner;
|
||||||
|
}
|
||||||
22
pglablib/PgOwnedObject.h
Normal file
22
pglablib/PgOwnedObject.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef PGOWNEDOBJECT_H
|
||||||
|
#define PGOWNEDOBJECT_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <libpq-fe.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class PgDatabaseCatalog;
|
||||||
|
class PgAuthId;
|
||||||
|
class PgOwnedObject {
|
||||||
|
public:
|
||||||
|
void setOwnerOid(PgDatabaseCatalog& cat, Oid oid);
|
||||||
|
|
||||||
|
Oid ownerOid() const;
|
||||||
|
QString ownerName() const;
|
||||||
|
const PgAuthId* owner() const;
|
||||||
|
private:
|
||||||
|
Oid m_ownerOid = InvalidOid;
|
||||||
|
const PgAuthId * m_owner;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PGOWNEDOBJECT_H
|
||||||
|
|
@ -74,11 +74,6 @@ namespace {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PgProc::objectName() const
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PgProc::setArgs(
|
void PgProc::setArgs(
|
||||||
std::vector<Oid> argtypes,
|
std::vector<Oid> argtypes,
|
||||||
std::vector<Oid> allargtypes,
|
std::vector<Oid> allargtypes,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef PGPROC_H
|
#ifndef PGPROC_H
|
||||||
#define PGPROC_H
|
#define PGPROC_H
|
||||||
|
|
||||||
#include "PgSchemaObject.h"
|
#include "PgNamespaceObject.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
#include "Pgsql_Value.h"
|
#include "Pgsql_Value.h"
|
||||||
|
|
@ -24,12 +24,12 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PgProc: public PgSchemaObject {
|
class PgProc: public PgNamespaceObject {
|
||||||
public:
|
public:
|
||||||
using PgSchemaObject::PgSchemaObject;
|
using PgNamespaceObject::PgNamespaceObject;
|
||||||
|
|
||||||
Oid oid = InvalidOid; // oid
|
// Oid oid = InvalidOid; // oid
|
||||||
QString name; // name
|
// QString name; // name
|
||||||
// Oid pronamespace = InvalidOid; // oid, namespace
|
// Oid pronamespace = InvalidOid; // oid, namespace
|
||||||
Oid owner = InvalidOid; // oid
|
Oid owner = InvalidOid; // oid
|
||||||
Oid lang = InvalidOid; // oid
|
Oid lang = InvalidOid; // oid
|
||||||
|
|
@ -65,12 +65,10 @@ public:
|
||||||
);
|
);
|
||||||
const std::vector<Arg>& args() const;
|
const std::vector<Arg>& args() const;
|
||||||
|
|
||||||
bool operator==(Oid _oid) const { return oid == _oid; }
|
// bool operator==(Oid _oid) const { return oid == _oid; }
|
||||||
bool operator==(const QString &n) const { return name == n; }
|
// bool operator==(const QString &n) const { return name == n; }
|
||||||
bool operator<(Oid _oid) const { return oid < _oid; }
|
// bool operator<(Oid _oid) const { return oid < _oid; }
|
||||||
bool operator<(const PgProc &rhs) const { return oid < rhs.oid; }
|
// bool operator<(const PgProc &rhs) const { return oid < rhs.oid; }
|
||||||
|
|
||||||
virtual QString objectName() const override;
|
|
||||||
|
|
||||||
QString createSql() const;
|
QString createSql() const;
|
||||||
QString argListWithNames(bool multiline = false) const;
|
QString argListWithNames(bool multiline = false) const;
|
||||||
|
|
|
||||||
|
|
@ -26,23 +26,26 @@ std::string PgProcContainer::getLoadQuery() const
|
||||||
PgProc PgProcContainer::loadElem(const Pgsql::Row &row)
|
PgProc PgProcContainer::loadElem(const Pgsql::Row &row)
|
||||||
{
|
{
|
||||||
Pgsql::Col col(row);
|
Pgsql::Col col(row);
|
||||||
PgProc v(m_catalog);
|
Oid oid = col.nextValue();
|
||||||
Oid namespace_oid;
|
QString name = col.nextValue();
|
||||||
|
Oid namespace_oid = col.nextValue();
|
||||||
|
|
||||||
|
PgProc v(m_catalog, oid, name, namespace_oid);
|
||||||
|
|
||||||
|
col >> v.owner >> v.lang >> v.cost >> v.rows
|
||||||
|
>> v.variadic >> v.transform >> v.isagg >> v.iswindow >> v.secdef >> v.leakproof
|
||||||
|
>> v.isstrict >> v.retset >> v.provolatile >> v.nargs >> v.nargdefaults
|
||||||
|
>> v.rettype;
|
||||||
|
|
||||||
std::vector<Oid> argtypes; // oid[]
|
std::vector<Oid> argtypes; // oid[]
|
||||||
std::vector<Oid> allargtypes; // oid[]
|
std::vector<Oid> allargtypes; // oid[]
|
||||||
std::vector<char> argmodes; // char[]
|
std::vector<char> argmodes; // char[]
|
||||||
std::vector<QString> argnames; // text[]
|
std::vector<QString> argnames; // text[]
|
||||||
std::optional<QString> argdefaults; // pg_node_tree
|
std::optional<QString> argdefaults; // pg_node_tree
|
||||||
|
|
||||||
col >> v.oid >> v.name >> namespace_oid >> v.owner >> v.lang >> v.cost >> v.rows
|
|
||||||
>> v.variadic >> v.transform >> v.isagg >> v.iswindow >> v.secdef >> v.leakproof
|
|
||||||
>> v.isstrict >> v.retset >> v.provolatile >> v.nargs >> v.nargdefaults
|
|
||||||
>> v.rettype;
|
|
||||||
col.getAsVector<Oid>(std::back_inserter(argtypes));
|
col.getAsVector<Oid>(std::back_inserter(argtypes));
|
||||||
col >> allargtypes >> argmodes >> argnames >> argdefaults
|
col >> allargtypes >> argmodes >> argnames >> argdefaults
|
||||||
>> v.src >> v.bin >> v.config >> v.acl;
|
>> v.src >> v.bin >> v.config >> v.acl;
|
||||||
|
|
||||||
v.setSchemaOid(namespace_oid);
|
|
||||||
v.setArgs(argtypes, allargtypes, argmodes, argnames, argdefaults);
|
v.setArgs(argtypes, allargtypes, argmodes, argnames, argdefaults);
|
||||||
|
|
||||||
if (minimumVersion(90500)) {
|
if (minimumVersion(90500)) {
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
#include "PgSchemaObject.h"
|
|
||||||
#include "PgDatabaseCatalog.h"
|
|
||||||
#include "PgNamespace.h"
|
|
||||||
#include "PgNamespaceContainer.h"
|
|
||||||
#include "SqlFormattingUtils.h"
|
|
||||||
|
|
||||||
Oid PgSchemaObject::schemaOid() const
|
|
||||||
{
|
|
||||||
return m_schemaOid;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PgSchemaObject::setSchemaOid(Oid oid)
|
|
||||||
{
|
|
||||||
m_schemaOid = oid;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PgSchemaObject::quotedSchemaName() const
|
|
||||||
{
|
|
||||||
return quoteIdent(ns().name);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PgSchemaObject::fullyQualifiedQuotedObjectName() const
|
|
||||||
{
|
|
||||||
return quotedSchemaName() + "." + quotedObjectName();
|
|
||||||
}
|
|
||||||
|
|
||||||
const PgNamespace& PgSchemaObject::ns() const
|
|
||||||
{
|
|
||||||
return *catalog().namespaces()->getByKey(m_schemaOid);
|
|
||||||
}
|
|
||||||
|
|
@ -5,16 +5,11 @@
|
||||||
#include "SqlFormattingUtils.h"
|
#include "SqlFormattingUtils.h"
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
|
||||||
QString PgTrigger::objectName() const
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PgTrigger::dropSql()
|
QString PgTrigger::dropSql()
|
||||||
{
|
{
|
||||||
if (m_dropSql.isEmpty()) {
|
if (m_dropSql.isEmpty()) {
|
||||||
auto&& fqtablename = genFQTableName(catalog(), *catalog().classes()->getByKey(relid));
|
auto&& fqtablename = catalog().classes()->getByKey(relid)->fullyQualifiedQuotedObjectName(); // genFQTableName(catalog(), *catalog().classes()->getByKey(relid));
|
||||||
m_dropSql = "DROP TRIGGER " % quoteIdent(name)
|
m_dropSql = "DROP TRIGGER " % quotedObjectName()
|
||||||
% " ON " % fqtablename % ";";
|
% " ON " % fqtablename % ";";
|
||||||
}
|
}
|
||||||
return m_dropSql;
|
return m_dropSql;
|
||||||
|
|
@ -23,8 +18,8 @@ QString PgTrigger::dropSql()
|
||||||
QString PgTrigger::createSql()
|
QString PgTrigger::createSql()
|
||||||
{
|
{
|
||||||
if (m_createSql.isEmpty()) {
|
if (m_createSql.isEmpty()) {
|
||||||
auto&& fqtablename = genFQTableName(catalog(), *catalog().classes()->getByKey(relid));
|
auto&& fqtablename = catalog().classes()->getByKey(relid)->fullyQualifiedQuotedObjectName(); //genFQTableName(catalog(), *catalog().classes()->getByKey(relid));
|
||||||
auto&& triggername = quoteIdent(name);
|
auto&& triggername = quotedObjectName();
|
||||||
|
|
||||||
if (constraint != InvalidOid)
|
if (constraint != InvalidOid)
|
||||||
m_createSql += "CREATE CONSTRAINT TRIGGER ";
|
m_createSql += "CREATE CONSTRAINT TRIGGER ";
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
#ifndef PGTRIGGER_H
|
#ifndef PGTRIGGER_H
|
||||||
#define PGTRIGGER_H
|
#define PGTRIGGER_H
|
||||||
|
|
||||||
#include "PgSchemaObject.h"
|
#include "PgNamespaceObject.h"
|
||||||
#include "Pgsql_Value.h"
|
#include "Pgsql_Value.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
|
|
||||||
class PgTrigger: public PgSchemaObject {
|
class PgTrigger: public PgNamespaceObject {
|
||||||
public:
|
public:
|
||||||
Oid oid = InvalidOid;
|
// Oid oid = InvalidOid;
|
||||||
Oid relid;
|
Oid relid;
|
||||||
QString name;
|
// QString name;
|
||||||
Oid foid;
|
Oid foid;
|
||||||
int16_t type;
|
int16_t type;
|
||||||
char enabled;
|
char enabled;
|
||||||
|
|
@ -29,15 +29,15 @@ public:
|
||||||
QString oldtable; // >= 10.0
|
QString oldtable; // >= 10.0
|
||||||
QString newtable; // >= 10.0
|
QString newtable; // >= 10.0
|
||||||
|
|
||||||
using PgSchemaObject::PgSchemaObject;
|
using PgNamespaceObject::PgNamespaceObject;
|
||||||
|
|
||||||
virtual QString objectName() const override;
|
// virtual QString objectName() const override;
|
||||||
|
|
||||||
|
|
||||||
bool operator==(Oid _oid) const { return oid == _oid; }
|
// bool operator==(Oid _oid) const { return oid == _oid; }
|
||||||
bool operator==(const QString &n) const { return name == n; }
|
// bool operator==(const QString &n) const { return name == n; }
|
||||||
bool operator<(Oid _oid) const { return oid < _oid; }
|
// bool operator<(Oid _oid) const { return oid < _oid; }
|
||||||
bool operator<(const PgTrigger &rhs) const { return oid < rhs.oid; }
|
// bool operator<(const PgTrigger &rhs) const { return oid < rhs.oid; }
|
||||||
|
|
||||||
static constexpr int TriggerTypeRow = (1 << 0);
|
static constexpr int TriggerTypeRow = (1 << 0);
|
||||||
static constexpr int TriggerTypeBefore = (1 << 1);
|
static constexpr int TriggerTypeBefore = (1 << 1);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
std::string PgTriggerContainer::getLoadQuery() const
|
std::string PgTriggerContainer::getLoadQuery() const
|
||||||
{
|
{
|
||||||
std::string q =
|
std::string q =
|
||||||
"SELECT oid, tgrelid, tgname, tgfoid, tgtype, tgenabled, tgisinternal, tgconstrrelid, \n"
|
"SELECT oid, tgname, tgrelid, tgfoid, tgtype, tgenabled, tgisinternal, tgconstrrelid, \n"
|
||||||
" tgconstrindid, tgconstraint, tgdeferrable, tginitdeferred, tgnargs, tgattr, \n"
|
" tgconstrindid, tgconstraint, tgdeferrable, tginitdeferred, tgnargs, tgattr, \n"
|
||||||
" tgargs, COALESCE(substring(pg_get_triggerdef(oid), 'WHEN (.*) EXECUTE PROCEDURE'), substring(pg_get_triggerdef(oid), 'WHEN (.*) \\$trigger')) AS whenclause";
|
" tgargs, COALESCE(substring(pg_get_triggerdef(oid), 'WHEN (.*) EXECUTE PROCEDURE'), substring(pg_get_triggerdef(oid), 'WHEN (.*) \\$trigger')) AS whenclause";
|
||||||
if (minimumVersion(90600)) {
|
if (minimumVersion(90600)) {
|
||||||
|
|
@ -23,8 +23,10 @@ PgTrigger PgTriggerContainer::loadElem(const Pgsql::Row &row)
|
||||||
{
|
{
|
||||||
|
|
||||||
Pgsql::Col col(row);
|
Pgsql::Col col(row);
|
||||||
PgTrigger v(m_catalog);
|
Oid oid = col.nextValue();
|
||||||
col >> v.oid >> v.relid >> v.name >> v.foid >> v.type >> v.enabled >> v.isinternal >> v.constrrelid
|
QString name = col.nextValue();
|
||||||
|
PgTrigger v(m_catalog, oid, name, InvalidOid);
|
||||||
|
col >> v.relid >> v.foid >> v.type >> v.enabled >> v.isinternal >> v.constrrelid
|
||||||
>> v.constrindid >> v.constraint >> v.deferrable >> v.initdeferred >> v.nargs >> v.attr;
|
>> v.constrindid >> v.constraint >> v.deferrable >> v.initdeferred >> v.nargs >> v.attr;
|
||||||
const unsigned char * args_bytea = reinterpret_cast<const unsigned char *>(col.nextValue().c_str());
|
const unsigned char * args_bytea = reinterpret_cast<const unsigned char *>(col.nextValue().c_str());
|
||||||
if (args_bytea) {
|
if (args_bytea) {
|
||||||
|
|
|
||||||
|
|
@ -18,5 +18,5 @@ UpdatePtr QueryGeneratorFactory::update(QString ns, QString table_name, QString
|
||||||
UpdatePtr QueryGeneratorFactory::update(const PgClass &table_class, QString alias)
|
UpdatePtr QueryGeneratorFactory::update(const PgClass &table_class, QString alias)
|
||||||
{
|
{
|
||||||
//QString nsname = m_catalog->namespaces()->getByKey(table_class.relnamespace_name)
|
//QString nsname = m_catalog->namespaces()->getByKey(table_class.relnamespace_name)
|
||||||
return update(table_class.relnamespace_name, table_class.name, alias);
|
return update(table_class.nsName(), table_class.objectName(), alias);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -244,26 +244,26 @@ QString dollarQuoteString(const QString &value)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString genSchemaPrefix(const PgNamespace &ns)
|
//QString genSchemaPrefix(const PgNamespace &ns)
|
||||||
{
|
//{
|
||||||
QString str;
|
// QString str;
|
||||||
if (!ns.name.isEmpty()) {
|
// if (!ns.name.isEmpty()) {
|
||||||
str = quoteIdent(ns.name) % QString::fromUtf16(u".");
|
// str = quoteIdent(ns.name) % QString::fromUtf16(u".");
|
||||||
}
|
// }
|
||||||
return str;
|
// return str;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
QString genFQTableName(const PgDatabaseCatalog &catalog, const PgClass &cls)
|
//QString genFQTableName(const PgDatabaseCatalog &catalog, const PgClass &cls)
|
||||||
{
|
//{
|
||||||
auto ns = catalog.namespaces()->getByKey(cls.relnamespace);
|
// auto ns = catalog.namespaces()->getByKey(cls.relnamespace);
|
||||||
|
////cls.fullyQualifiedQuotedObjectName()
|
||||||
return genSchemaPrefix(*ns) % quoteIdent(cls.name);
|
// return ns->quotedObjectName() % "." % cls.quotedObjectName();
|
||||||
}
|
//}
|
||||||
|
|
||||||
QString genAlterTable(const PgDatabaseCatalog &catalog, const PgClass &cls)
|
QString genAlterTable(const PgDatabaseCatalog &catalog, const PgClass &cls)
|
||||||
{
|
{
|
||||||
return "ALTER TABLE " % genFQTableName(catalog, cls);
|
return "ALTER TABLE " % cls.fullyQualifiedQuotedObjectName(); // genFQTableName(catalog, cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getDropConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint)
|
QString getDropConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint)
|
||||||
|
|
@ -312,7 +312,7 @@ QString getForeignKeyConstraintDefinition(const PgDatabaseCatalog &catalog, cons
|
||||||
|
|
||||||
return "\n FOREIGN KEY ("
|
return "\n FOREIGN KEY ("
|
||||||
% getColumnNameList(catalog, constraint.relid, constraint.key) % ")\n REFERENCES "
|
% getColumnNameList(catalog, constraint.relid, constraint.key) % ")\n REFERENCES "
|
||||||
% genFQTableName(catalog, *fcls) % " ("
|
% fcls->fullyQualifiedQuotedObjectName() % " ("
|
||||||
% getColumnNameList(catalog, constraint.frelid, constraint.fkey) % ")\n MATCH "
|
% getColumnNameList(catalog, constraint.frelid, constraint.fkey) % ")\n MATCH "
|
||||||
% ForeignKeyMatchToString(constraint.fmatchtype)
|
% ForeignKeyMatchToString(constraint.fmatchtype)
|
||||||
% " ON UPDATE " % ForeignKeyActionToString(constraint.fupdtype)
|
% " ON UPDATE " % ForeignKeyActionToString(constraint.fupdtype)
|
||||||
|
|
@ -332,7 +332,7 @@ QString getForeignKeyConstraintReferences(const PgDatabaseCatalog &catalog, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
return "REFERENCES "
|
return "REFERENCES "
|
||||||
% genFQTableName(catalog, *fcls) % " ("
|
% fcls->fullyQualifiedQuotedObjectName() % " ("
|
||||||
% getColumnNameList(catalog, constraint.frelid, constraint.fkey) % ") MATCH "
|
% getColumnNameList(catalog, constraint.frelid, constraint.fkey) % ") MATCH "
|
||||||
% ForeignKeyMatchToString(constraint.fmatchtype)
|
% ForeignKeyMatchToString(constraint.fmatchtype)
|
||||||
% " ON UPDATE " % ForeignKeyActionToString(constraint.fupdtype)
|
% " ON UPDATE " % ForeignKeyActionToString(constraint.fupdtype)
|
||||||
|
|
@ -356,7 +356,7 @@ QString getForeignKeyConstraintReferencesShort(const PgDatabaseCatalog &catalog,
|
||||||
QString on_delete = constraint.fdeltype == ForeignKeyAction::NoAction ? QString() : " ON DELETE " % ForeignKeyActionToString(constraint.fdeltype);
|
QString on_delete = constraint.fdeltype == ForeignKeyAction::NoAction ? QString() : " ON DELETE " % ForeignKeyActionToString(constraint.fdeltype);
|
||||||
QString match_type = constraint.fmatchtype == ForeignKeyMatch::Simple ? QString() : " MATCH " % ForeignKeyMatchToString(constraint.fmatchtype);
|
QString match_type = constraint.fmatchtype == ForeignKeyMatch::Simple ? QString() : " MATCH " % ForeignKeyMatchToString(constraint.fmatchtype);
|
||||||
|
|
||||||
return genFQTableName(catalog, *fcls) % " ("
|
return fcls->fullyQualifiedQuotedObjectName() % " ("
|
||||||
% getColumnNameList(catalog, constraint.frelid, constraint.fkey) % ")"
|
% getColumnNameList(catalog, constraint.frelid, constraint.fkey) % ")"
|
||||||
% match_type
|
% match_type
|
||||||
% on_update
|
% on_update
|
||||||
|
|
@ -406,7 +406,7 @@ QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstr
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &index)
|
QString getIndexDefinition(const PgDatabaseCatalog &, const PgIndex &index)
|
||||||
{
|
{
|
||||||
// const PgClass *table_class = catalog.classes()->getByKey(index.relid);
|
// const PgClass *table_class = catalog.classes()->getByKey(index.relid);
|
||||||
// const PgClass *index_class = catalog.classes()->getByKey(index.indexrelid);
|
// const PgClass *index_class = catalog.classes()->getByKey(index.indexrelid);
|
||||||
|
|
@ -464,40 +464,8 @@ QString getDropIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &
|
||||||
|
|
||||||
QString result;
|
QString result;
|
||||||
result = "DROP INDEX "
|
result = "DROP INDEX "
|
||||||
% quoteIdent(getIndexDisplayString(catalog, index.indexrelid))
|
% index.fullyQualifiedQuotedObjectName() // quoteIdent(getIndexDisplayString(catalog, index.indexrelid))
|
||||||
% ";";
|
% ";";
|
||||||
// % quoteIdent(index_class.name)
|
|
||||||
// % "\n ON " % genFQTableName(catalog, table_class);
|
|
||||||
//// % "\n USING " % index_class.am lookup in pg_am table
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
wxString sql;
|
|
||||||
|
|
||||||
sql = wxT("(") + GetQuotedFkColumns()
|
|
||||||
+ wxT(")\n REFERENCES ") + GetQuotedSchemaPrefix(GetRefSchema()) + qtIdent(GetReferences())
|
|
||||||
+ wxT(" (") + GetQuotedRefColumns()
|
|
||||||
+ wxT(")");
|
|
||||||
|
|
||||||
if (GetDatabase()->BackendMinimumVersion(7, 4) || GetMatch() == wxT("FULL"))
|
|
||||||
sql += wxT(" MATCH ") + GetMatch();
|
|
||||||
|
|
||||||
sql += wxT("\n ON UPDATE ") + GetOnUpdate()
|
|
||||||
+ wxT(" ON DELETE ") + GetOnDelete();
|
|
||||||
if (GetDeferrable())
|
|
||||||
{
|
|
||||||
sql += wxT(" DEFERRABLE INITIALLY ");
|
|
||||||
if (GetDeferred())
|
|
||||||
sql += wxT("DEFERRED");
|
|
||||||
else
|
|
||||||
sql += wxT("IMMEDIATE");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GetDatabase()->BackendMinimumVersion(9, 1) && !GetValid())
|
|
||||||
sql += wxT("\n NOT VALID");
|
|
||||||
|
|
||||||
return sql;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ QString quoteIdent(QString ident);
|
||||||
QString dollarQuoteString(const QString &value);
|
QString dollarQuoteString(const QString &value);
|
||||||
|
|
||||||
|
|
||||||
QString genFQTableName(const PgDatabaseCatalog &catalog, const PgClass &cls);
|
//QString genFQTableName(const PgDatabaseCatalog &catalog, const PgClass &cls);
|
||||||
QString getDropConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
QString getDropConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
||||||
QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
||||||
QString getIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &index);
|
QString getIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &index);
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,10 @@ codebuilder/StructureTemplate.cpp \
|
||||||
PgTriggerContainer.cpp \
|
PgTriggerContainer.cpp \
|
||||||
PgProc.cpp \
|
PgProc.cpp \
|
||||||
PgProcContainer.cpp \
|
PgProcContainer.cpp \
|
||||||
PgSchemaObject.cpp \
|
|
||||||
PgDatabaseObject.cpp \
|
PgDatabaseObject.cpp \
|
||||||
PgServerObject.cpp
|
PgServerObject.cpp \
|
||||||
|
PgOwnedObject.cpp \
|
||||||
|
PgNamespaceObject.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
Pglablib.h \
|
Pglablib.h \
|
||||||
|
|
@ -121,9 +122,10 @@ codebuilder/StructureTemplate.h \
|
||||||
PgTriggerContainer.h \
|
PgTriggerContainer.h \
|
||||||
PgProc.h \
|
PgProc.h \
|
||||||
PgProcContainer.h \
|
PgProcContainer.h \
|
||||||
PgSchemaObject.h \
|
|
||||||
PgDatabaseObject.h \
|
PgDatabaseObject.h \
|
||||||
PgServerObject.h
|
PgServerObject.h \
|
||||||
|
PgOwnedObject.h \
|
||||||
|
PgNamespaceObject.h
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
target.path = /usr/lib
|
target.path = /usr/lib
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue