PgType now inherits from PgNamespaceObject and PgOwnedObject
This commit is contained in:
parent
742fd0a4d3
commit
44358d198a
10 changed files with 37 additions and 54 deletions
|
|
@ -24,7 +24,10 @@ Pgsql::Params QueryParamListController::params() const
|
||||||
Pgsql::Params params;
|
Pgsql::Params params;
|
||||||
auto types = m_openDatabase->catalog()->types();
|
auto types = m_openDatabase->catalog()->types();
|
||||||
for (auto e : m_paramList.GetParams()) {
|
for (auto e : m_paramList.GetParams()) {
|
||||||
Oid oid = types->getByName(e.type)->oid;
|
// some types have two names that are in seperate fields
|
||||||
|
// this function only checks one field currently :(
|
||||||
|
// for example integer vs int4, bigint vs int8
|
||||||
|
Oid oid = types->getByName(e.type)->oid();
|
||||||
params.add(e.value, oid);
|
params.add(e.value, oid);
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ void SqlSyntaxHighlighter::setTypes(const PgTypeContainer& types)
|
||||||
{
|
{
|
||||||
m_typeNames.clear();
|
m_typeNames.clear();
|
||||||
for (auto&& e : types) {
|
for (auto&& e : types) {
|
||||||
m_typeNames.insert(e.name);
|
m_typeNames.insert(e.objectName());
|
||||||
}
|
}
|
||||||
rehighlight();
|
rehighlight();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ QString PgAttribute::columnDefinition(const PgDatabaseCatalog &cat) const
|
||||||
// constraints NULL/NOT NULL, DEFAULT, GENERATED other constraints will be ignored here a
|
// constraints NULL/NOT NULL, DEFAULT, GENERATED other constraints will be ignored here a
|
||||||
auto&& type = cat.types()->getByKey(typid);
|
auto&& type = cat.types()->getByKey(typid);
|
||||||
|
|
||||||
QString sql = quoteIdent(name) % " " % type->name;
|
QString sql = quoteIdent(name) % " " % type->objectName();
|
||||||
if (collation != InvalidOid) {
|
if (collation != InvalidOid) {
|
||||||
auto&& col = cat.collations()->getByKey(collation);
|
auto&& col = cat.collations()->getByKey(collation);
|
||||||
QString oname = col->objectName();
|
QString oname = col->objectName();
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ QString getTypeDisplayString(const PgDatabaseCatalog &cat, Oid oid, int32_t typm
|
||||||
s += "[]";
|
s += "[]";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
s = t->name;
|
s = t->objectName();
|
||||||
switch (oid) {
|
switch (oid) {
|
||||||
case varchar_oid:
|
case varchar_oid:
|
||||||
case char_oid:
|
case char_oid:
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ QString PgProc::argListWithNames(bool multiline) const
|
||||||
|
|
||||||
if (!arg.isEmpty())
|
if (!arg.isEmpty())
|
||||||
arg += " ";
|
arg += " ";
|
||||||
arg += types->getByKey(arg_elem.type)->name;
|
arg += types->getByKey(arg_elem.type)->objectName();
|
||||||
|
|
||||||
if (!arg_elem.def.isEmpty())
|
if (!arg_elem.def.isEmpty())
|
||||||
arg += " DEFAULT " + arg_elem.def;
|
arg += " DEFAULT " + arg_elem.def;
|
||||||
|
|
@ -179,7 +179,7 @@ QString PgProc::argSigList(const bool forScript) const
|
||||||
args += ", ";
|
args += ", ";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString typname = types->getByKey(arg_elem.type)->name;
|
QString typname = types->getByKey(arg_elem.type)->objectName();
|
||||||
if (forScript)
|
if (forScript)
|
||||||
args += " <" + typname + ">";
|
args += " <" + typname + ">";
|
||||||
else
|
else
|
||||||
|
|
@ -201,7 +201,7 @@ QString PgProc::createSql() const
|
||||||
QString quoted_sig = QString("%1(%2)").arg(fullyQualifiedQuotedObjectName(), argSigList());
|
QString quoted_sig = QString("%1(%2)").arg(fullyQualifiedQuotedObjectName(), argSigList());
|
||||||
|
|
||||||
auto&& types = catalog().types();
|
auto&& types = catalog().types();
|
||||||
QString return_type = types->getByKey(rettype)->name;
|
QString return_type = types->getByKey(rettype)->objectName();
|
||||||
|
|
||||||
|
|
||||||
sql = QString("-- Function: %1\n\n"
|
sql = QString("-- Function: %1\n\n"
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,3 @@ void operator<<(TypCategory &s, const Pgsql::Value &v)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PgType::PgType() = default;
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef PGTYPE_H
|
#ifndef PGTYPE_H
|
||||||
#define PGTYPE_H
|
#define PGTYPE_H
|
||||||
|
|
||||||
|
#include "PgNamespaceObject.h"
|
||||||
|
#include "PgOwnedObject.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
#include "Pgsql_Value.h"
|
#include "Pgsql_Value.h"
|
||||||
|
|
@ -26,15 +28,13 @@ enum class TypCategory {
|
||||||
void operator<<(TypCategory &s, const Pgsql::Value &v);
|
void operator<<(TypCategory &s, const Pgsql::Value &v);
|
||||||
|
|
||||||
|
|
||||||
class PgType {
|
class PgType: public PgNamespaceObject, public PgOwnedObject {
|
||||||
public:
|
public:
|
||||||
PgType();
|
// Oid oid = InvalidOid;
|
||||||
|
// QString name; // formatted name as per database, arrays
|
||||||
Oid oid = InvalidOid;
|
|
||||||
QString name; // formatted name as per database, arrays
|
|
||||||
QString typname; //"name";"NO"
|
QString typname; //"name";"NO"
|
||||||
Oid typnamespace = InvalidOid;//"oid";"NO"
|
// Oid typnamespace = InvalidOid;//"oid";"NO"
|
||||||
Oid owner = InvalidOid;//"oid";"NO"
|
// Oid owner = InvalidOid;//"oid";"NO"
|
||||||
short len = -1;//"smallint";"NO"
|
short len = -1;//"smallint";"NO"
|
||||||
bool byval = false;//"boolean";"NO"
|
bool byval = false;//"boolean";"NO"
|
||||||
QString type;//""char"";"NO"
|
QString type;//""char"";"NO"
|
||||||
|
|
@ -63,10 +63,12 @@ public:
|
||||||
QString typdefault;//"text";"YES"
|
QString typdefault;//"text";"YES"
|
||||||
QString acl;//"ARRAY";"YES"
|
QString acl;//"ARRAY";"YES"
|
||||||
|
|
||||||
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; }
|
// bool operator==(Oid _oid) const { return oid == _oid; }
|
||||||
bool operator<(const PgType &rhs) const { return oid < rhs.oid; }
|
// bool operator==(const QString &n) const { return name == n; }
|
||||||
|
// bool operator<(Oid _oid) const { return oid < _oid; }
|
||||||
|
// bool operator<(const PgType &rhs) const { return oid < rhs.oid; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGTYPE_H
|
#endif // PGTYPE_H
|
||||||
|
|
|
||||||
|
|
@ -3,34 +3,11 @@
|
||||||
#include "Pgsql_Col.h"
|
#include "Pgsql_Col.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
//const PgType& PgTypeContainer::getTypeByOid(Oid oid) const
|
|
||||||
//{
|
|
||||||
// auto lb_result = std::lower_bound(m_types.begin(), m_types.end(), oid);
|
|
||||||
// if (lb_result != m_types.end() && lb_result->oid == oid)
|
|
||||||
// return *lb_result;
|
|
||||||
|
|
||||||
// return m_invalidType;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//const PgType& PgTypeContainer::getTypeByName(const QString &name) const
|
|
||||||
//{
|
|
||||||
// auto find_res = std::find(m_types.begin(), m_types.end(), name);
|
|
||||||
|
|
||||||
// if (find_res != m_types.end())
|
|
||||||
// return *find_res;
|
|
||||||
|
|
||||||
// return m_invalidType;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//const PgType& PgTypeContainer::getTypeByIdx(int idx) const
|
|
||||||
//{
|
|
||||||
// return m_types.at(idx);
|
|
||||||
//}
|
|
||||||
|
|
||||||
std::string PgTypeContainer::getLoadQuery() const
|
std::string PgTypeContainer::getLoadQuery() const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"SELECT oid, format_type(oid, NULL) AS name, typname, typnamespace, typowner, typlen, typbyval, typtype, typcategory, \n"
|
"SELECT oid, format_type(oid, NULL) AS name, typnamespace, typowner, typname, typlen, typbyval, typtype, typcategory, \n"
|
||||||
" typispreferred, typisdefined, typdelim, typrelid, typelem, typarray, typinput, typoutput, \n"
|
" typispreferred, typisdefined, typdelim, typrelid, typelem, typarray, typinput, typoutput, \n"
|
||||||
" typreceive, typsend, typmodin, typmodout, typanalyze, typalign, typstorage, typnotnull, \n"
|
" typreceive, typsend, typmodin, typmodout, typanalyze, typalign, typstorage, typnotnull, \n"
|
||||||
" typbasetype, typtypmod, typndims, typcollation, typdefaultbin, typdefault, typacl \n"
|
" typbasetype, typtypmod, typndims, typcollation, typdefaultbin, typdefault, typacl \n"
|
||||||
|
|
@ -40,10 +17,15 @@ std::string PgTypeContainer::getLoadQuery() const
|
||||||
PgType PgTypeContainer::loadElem(const Pgsql::Row &row)
|
PgType PgTypeContainer::loadElem(const Pgsql::Row &row)
|
||||||
{
|
{
|
||||||
Pgsql::Col col(row);
|
Pgsql::Col col(row);
|
||||||
PgType v;
|
Oid type_oid = col.nextValue();
|
||||||
col >> v.oid >> v.name >> v.typname >> v.typnamespace >> v.owner >> v.len >> v.byval >> v.type >> v.category
|
QString name = col.nextValue();
|
||||||
|
Oid ns_oid = col.nextValue();
|
||||||
|
Oid owner = col.nextValue();
|
||||||
|
PgType v(m_catalog, type_oid, name, ns_oid);
|
||||||
|
col >> v.typname >> v.len >> v.byval >> v.type >> v.category
|
||||||
>> v.ispreferred >> v.isdefined >> v.delim >> v.relid >> v.elem >> v.array >> v.input >> v.output
|
>> v.ispreferred >> v.isdefined >> v.delim >> v.relid >> v.elem >> v.array >> v.input >> v.output
|
||||||
>> v.receive >> v.send >> v.modin >> v.modout >> v.analyze >> v.align >> v.storage >> v.notnull
|
>> v.receive >> v.send >> v.modin >> v.modout >> v.analyze >> v.align >> v.storage >> v.notnull
|
||||||
>> v.basetype >> v.typmod >> v.ndims >> v.collation >> v.defaultbin >> v.typdefault >> v.acl;
|
>> v.basetype >> v.typmod >> v.ndims >> v.collation >> v.defaultbin >> v.typdefault >> v.acl;
|
||||||
|
v.setOwnerOid(m_catalog, owner);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ void TypeSelectionItemModel::setTypeList(std::shared_ptr<const PgTypeContainer>
|
||||||
m_types.clear();
|
m_types.clear();
|
||||||
for (const auto &e : *types) {
|
for (const auto &e : *types) {
|
||||||
if (e.category != TypCategory::Array && e.type != "c") {
|
if (e.category != TypCategory::Array && e.type != "c") {
|
||||||
m_types.push_back(e.name);
|
m_types.push_back(e.objectName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::sort(m_types.begin(), m_types.end());
|
std::sort(m_types.begin(), m_types.end());
|
||||||
|
|
@ -87,8 +87,8 @@ QVariant TypeModel::data(const QModelIndex &index, int role) const
|
||||||
//const PgType &tp = m_types->getByIdx(row);
|
//const PgType &tp = m_types->getByIdx(row);
|
||||||
auto elem = m_types->getByIdx(row);
|
auto elem = m_types->getByIdx(row);
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case OidCol: return elem.oid;
|
case OidCol: return elem.oid();
|
||||||
case NameCol: return elem.name;
|
case NameCol: return elem.objectName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ TypeMappingResult TypeMappings::getTypeForOid(Oid oid) const
|
||||||
if (m_types) {
|
if (m_types) {
|
||||||
const PgType* type = m_types->getByKey(oid);
|
const PgType* type = m_types->getByKey(oid);
|
||||||
if (type)
|
if (type)
|
||||||
dbtypename = type->name;
|
dbtypename = type->objectName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return { res->second, dbtypename };
|
return { res->second, dbtypename };
|
||||||
|
|
@ -52,11 +52,11 @@ TypeMappingResult TypeMappings::getTypeForOid(Oid oid) const
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
QString(m_defaultContainerType).arg(type_string),
|
QString(m_defaultContainerType).arg(type_string),
|
||||||
elem_type->name + "[]"
|
elem_type->objectName() + "[]"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return { m_defaultStringType, type->name };
|
return { m_defaultStringType, type->objectName() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We shouldn't get here unless m_types is empty
|
// We shouldn't get here unless m_types is empty
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue