diff --git a/dlg/dlgTable.cpp b/dlg/dlgTable.cpp index 7a482ea..8a306d8 100644 --- a/dlg/dlgTable.cpp +++ b/dlg/dlgTable.cpp @@ -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; diff --git a/frm/frmReport.cpp b/frm/frmReport.cpp index 4476434..ec57d1b 100644 --- a/frm/frmReport.cpp +++ b/frm/frmReport.cpp @@ -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"); diff --git a/include/schema/pgCheck.h b/include/schema/pgCheck.h index 57b0f6a..0abd082 100644 --- a/include/schema/pgCheck.h +++ b/include/schema/pgCheck.h @@ -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 diff --git a/include/schema/pgForeignKey.h b/include/schema/pgForeignKey.h index e553f77..7c060e6 100644 --- a/include/schema/pgForeignKey.h +++ b/include/schema/pgForeignKey.h @@ -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; }; diff --git a/schema/pgCheck.cpp b/schema/pgCheck.cpp index 1002e5e..0dd4887 100644 --- a/schema/pgCheck.cpp +++ b/schema/pgCheck.cpp @@ -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) diff --git a/schema/pgColumn.cpp b/schema/pgColumn.cpp index 5d54439..65f3831 100644 --- a/schema/pgColumn.cpp +++ b/schema/pgColumn.cpp @@ -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" ; diff --git a/schema/pgForeignKey.cpp b/schema/pgForeignKey.cpp index c1abb01..4b03d8b 100644 --- a/schema/pgForeignKey.cpp +++ b/schema/pgForeignKey.cpp @@ -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")); diff --git a/schema/pgTable.cpp b/schema/pgTable.cpp index c05f616..5ea2077 100644 --- a/schema/pgTable.cpp +++ b/schema/pgTable.cpp @@ -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(")");