PG18 support, enfoced, virtual cols

This commit is contained in:
lsv 2025-10-03 14:56:27 +05:00
parent f0475130ed
commit 51ec580dce
8 changed files with 36 additions and 15 deletions

View file

@ -403,10 +403,10 @@ int dlgTable::Go(bool modal)
case PGM_FOREIGNKEY:
{
pgForeignKey *obj = (pgForeignKey *)data;
wxString def = obj->GetDefinition();
wxString def = obj->GetDefinition(PGM_TABLE);
lstConstraints->AppendItem(data->GetIconId(), obj->GetName(), def);
constraintsDefinition.Add(obj->GetDefinition());
constraintsDefinition.Add(obj->GetDefinition(PGM_TABLE));
previousConstraints.Add(obj->GetQuotedIdentifier()
+ wxT(" ") + obj->GetTypeName().Upper() + wxT(" ") + def);
break;

View file

@ -2382,7 +2382,7 @@ void reportObjectDataDictionaryFactory::GenerateReport(frmReport *report, pgObje
break;
case PGM_FOREIGNKEY:
type = _("Foreign key");
definition = ((pgForeignKey *)constraint)->GetDefinition();
definition = ((pgForeignKey *)constraint)->GetDefinition(PGM_FOREIGNKEY);
break;
case PGM_EXCLUDE:
type = _("Exclude");

View file

@ -95,6 +95,14 @@ public:
{
valid = b;
}
bool GetEnforced() const
{
return enfoced;
}
void iSetEnforced(const bool b)
{
enfoced = b;
}
bool DropObject(wxFrame *frame, ctlTree *browser, bool cascaded);
wxString GetConstraint();
@ -121,7 +129,7 @@ public:
private:
wxString definition, objectKind, objectName, objectSchema;
bool noinherit, valid;
bool noinherit, valid,enfoced;
};
class pgCheckCollection : public pgSchemaObjCollection

View file

@ -39,7 +39,7 @@ public:
int GetIconId();
wxString GetDefinition();
wxString GetDefinition(int metatype);
wxString GetFullName();
wxString GetTranslatedMessage(int kindOfMessage) const;
@ -156,6 +156,14 @@ public:
{
valid = b;
}
bool GetEnforced() const
{
return enforced;
}
void iSetEnforced(const bool b)
{
enforced = b;
}
wxString GetRelTableOidStr() const
{
return NumToStr(relTableOid) + wxT("::oid");
@ -218,7 +226,7 @@ private:
fkTable, fkSchema, references, refSchema;
wxString fkColumns, refColumns, quotedFkColumns, quotedRefColumns, coveringIndex, match;
wxString fkDelColumns, quotedFkDelColumns;
bool deferrable, deferred, valid;
bool deferrable, deferred, valid, enforced;
OID relTableOid;
};

View file

@ -125,7 +125,7 @@ wxString pgCheck::GetConstraint()
if (GetDatabase()->BackendMinimumVersion(9, 2) && !GetValid())
sql += wxT(" NOT VALID");
if (!GetEnforced()) sql += wxT(" NOT ENFORCED");
return sql;
}
@ -205,11 +205,12 @@ pgObject *pgCheckFactory::CreateObjects(pgCollection *coll, ctlTree *browser, co
wxString connoinherit = collection->GetDatabase()->BackendMinimumVersion(9, 2) ? wxT(", connoinherit") : wxEmptyString;
wxString convalidated = collection->GetDatabase()->BackendMinimumVersion(9, 2) ? wxT(", convalidated") : wxEmptyString;
wxString enforced =collection->GetDatabase()->BackendMinimumVersion(18, 0) ? ",c.conenforced enforced" :" ,true enforced";
wxString sql =
wxT("SELECT 'TABLE' AS objectkind, c.oid, conname, relname, nspname, description,\n")
wxT(" pg_get_expr(conbin, conrelid") + collection->GetDatabase()->GetPrettyOption() + wxT(") as consrc\n")
+ connoinherit + convalidated +
+ connoinherit + convalidated + enforced +
wxT(" FROM pg_constraint c\n")
wxT(" JOIN pg_class cl ON cl.oid=conrelid\n")
wxT(" JOIN pg_namespace nl ON nl.oid=relnamespace\n")
@ -219,7 +220,7 @@ pgObject *pgCheckFactory::CreateObjects(pgCollection *coll, ctlTree *browser, co
wxT("UNION\n")
wxT("SELECT 'DOMAIN' AS objectkind, c.oid, conname, typname as relname, nspname, description,\n")
wxT(" regexp_replace(pg_get_constraintdef(c.oid, true), E'CHECK \\\\((.*)\\\\).*', E'\\\\1') as consrc\n")
+ connoinherit + convalidated +
+ connoinherit + convalidated + enforced +
wxT(" FROM pg_constraint c\n")
wxT(" JOIN pg_type t ON t.oid=contypid\n")
wxT(" JOIN pg_namespace nl ON nl.oid=typnamespace\n")
@ -246,6 +247,7 @@ pgObject *pgCheckFactory::CreateObjects(pgCollection *coll, ctlTree *browser, co
check->iSetNoInherit(checks->GetBool(wxT("connoinherit")));
check->iSetValid(checks->GetBool(wxT("convalidated")));
}
check->iSetEnforced(checks->GetBool(wxT("enforced")));
check->iSetComment(checks->GetVal(wxT("description")));
if (browser)

View file

@ -424,6 +424,7 @@ wxString pgColumn::GetDefinition()
sql += wxT(" NOT NULL");
if (!GetGenerated().IsEmpty()) {
if (GetGenerated()=="s") sql+= " GENERATED ALWAYS AS " + GetDefault() + " STORED";
if (GetGenerated()=="v") sql+= " GENERATED ALWAYS AS " + GetDefault() + " VIRTUAL";
} else if (!GetIdentity().IsEmpty()) {
if (GetIdentity()=="a") sql+= " GENERATED ALWAYS AS IDENTITY";
if (GetIdentity()=="d") sql+= " GENERATED BY DEFAULT AS IDENTITY" ;

View file

@ -114,7 +114,7 @@ bool pgForeignKey::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
}
wxString pgForeignKey::GetDefinition()
wxString pgForeignKey::GetDefinition(int metatype)
{
wxString sql;
@ -139,8 +139,8 @@ wxString pgForeignKey::GetDefinition()
else
sql += wxT("IMMEDIATE");
}
if (GetDatabase()->BackendMinimumVersion(9, 1) && !GetValid())
if (!GetEnforced()) sql += wxT(" NOT ENFORCED");
if (GetDatabase()->BackendMinimumVersion(9, 1) && !GetValid() && metatype!=PGM_TABLE )
sql += wxT("\n NOT VALID");
return sql;
@ -151,7 +151,7 @@ wxString pgForeignKey::GetConstraint()
{
wxString sql;
sql = GetQuotedIdentifier()
+ wxT(" FOREIGN KEY ") + GetDefinition();
+ wxT(" FOREIGN KEY ") + GetDefinition(PGM_FOREIGNKEY);
return sql;
}
@ -307,10 +307,11 @@ pgObject *pgForeignKeyFactory::CreateObjects(pgCollection *coll, ctlTree *browse
wxString sql;
pgTableObjCollection *collection = (pgTableObjCollection *)coll;
pgForeignKey *foreignKey = 0;
wxString enforced =collection->GetDatabase()->BackendMinimumVersion(18, 0) ? ",ct.conenforced enforced" :" ,true enforced";
sql = wxT("SELECT ct.oid, conname, condeferrable, condeferred, confupdtype, confdeltype, confmatchtype, ")
wxT("conkey, confkey, confrelid, nl.nspname as fknsp, cl.relname as fktab, ")
wxT("nr.nspname as refnsp, cr.relname as reftab, description");
wxT("nr.nspname as refnsp, cr.relname as reftab, description") + enforced;
if (collection->GetDatabase()->BackendMinimumVersion(15, 0))
sql += wxT(", confdelsetcols");
if (collection->GetDatabase()->BackendMinimumVersion(9, 1))
@ -342,6 +343,7 @@ pgObject *pgForeignKeyFactory::CreateObjects(pgCollection *coll, ctlTree *browse
foreignKey->iSetReferences(foreignKeys->GetVal(wxT("reftab")));
if (collection->GetDatabase()->BackendMinimumVersion(9, 1))
foreignKey->iSetValid(foreignKeys->GetBool(wxT("convalidated")));
foreignKey->iSetEnforced(foreignKeys->GetBool(wxT("enforced")));
wxString onUpd = foreignKeys->GetVal(wxT("confupdtype"));
wxString onDel = foreignKeys->GetVal(wxT("confdeltype"));
wxString match = foreignKeys->GetVal(wxT("confmatchtype"));

View file

@ -478,7 +478,7 @@ wxString pgTable::GetSql(ctlTree *browser)
if (data->GetMetaType()== PGM_PRIMARYKEY) defpkcluster= ((pgIndexConstraint*)data)->GetDefinitionCluster();
break;
case PGM_FOREIGNKEY:
cols_sql += ((pgForeignKey *)data)->GetDefinition();
cols_sql += ((pgForeignKey *)data)->GetDefinition(PGM_TABLE);
break;
case PGM_CHECK:
cols_sql += wxT("(") + ((pgCheck *)data)->GetDefinition() + wxT(")");