wxString pgType::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Type: ") + GetQuotedFullIdentifier() + wxT("\n\n") + wxT("-- DROP TYPE ") + GetQuotedFullIdentifier() + wxT(";") + wxT("\n\nCREATE TYPE ") + GetQuotedFullIdentifier(); if (GetTypeClass() == TYPE_COMPOSITE) { sql += wxT(" AS\n ("); sql += GetQuotedTypesList(); } else if (GetTypeClass() == TYPE_ENUM) { sql += wxT(" AS ENUM\n ("); sql += GetQuotedLabelList(); } else { sql += wxT("\n (INPUT=") + qtIdent(GetInputFunction()) + wxT(", OUTPUT=") + qtIdent(GetOutputFunction()); AppendIfFilled(sql, wxT(", DEFAULT="), qtDbString(GetDefault())); if (!GetElement().IsNull()) { sql += wxT(",\n ELEMENT=") + GetElement() + wxT(", DELIMITER='") + GetDelimiter() + wxT("'"); } sql += wxT(",\n INTERNALLENGTH=") + NumToStr(GetInternalLength()) + wxT(", ALIGNMENT=" + GetAlignment() + wxT(", STORAGE=") + GetStorage()); if (GetConnection()->BackendMinimumVersion(8, 3)) { if (GetTypmodinFunction() != wxEmptyString && GetTypmodoutFunction() != wxEmptyString) { sql += wxT(",\n TYPMOD_IN=") + GetTypmodinFunction() + wxT(", TYPMOD_OUT=") + GetTypmodoutFunction(); } else if (GetTypmodinFunction() != wxEmptyString) sql += wxT(",\n TYPMOD_IN=") + GetTypmodinFunction(); else if (GetTypmodoutFunction() != wxEmptyString) sql += wxT(",\n TYPMOD_OUT=") + GetTypmodoutFunction(); } if (GetConnection()->BackendMinimumVersion(9, 1) && GetCollatable()) { sql += wxT(",\n COLLATABLE=true"); } } sql += wxT(");\n") + GetOwnerSql(8, 0) + GetCommentSql(); if (GetConnection()->BackendMinimumVersion(9, 1)) sql += GetSeqLabelsSql(); } return sql; }
wxString pgForeignTable::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Foreign Table: ") + GetQuotedFullIdentifier() + wxT("\n\n") + wxT("-- DROP FOREIGN TABLE ") + GetQuotedFullIdentifier() + wxT(";") + wxT("\n\nCREATE FOREIGN TABLE ") + GetQuotedFullIdentifier() + wxT("\n (") + GetQuotedTypesList() + wxT(")\n SERVER ") + GetForeignServer(); if (!GetOptionsList().IsEmpty()) sql += wxT("\n OPTIONS (") + GetOptionsList() + wxT(")"); sql += wxT(";\n") + GetOwnerSql(9, 1) + GetCommentSql(); if (GetConnection()->BackendMinimumVersion(9, 1)) sql += GetSeqLabelsSql(); } return sql; }
wxString pgType::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Type: ") + GetQuotedFullIdentifier() + wxT("\n\n") + wxT("-- DROP TYPE ") + GetQuotedFullIdentifier() + wxT(";") + wxT("\n\nCREATE TYPE ") + GetQuotedFullIdentifier(); if (GetTypeClass() == TYPE_COMPOSITE) { sql += wxT(" AS\n ("); sql += GetQuotedTypesList(); } else if (GetTypeClass() == TYPE_ENUM) { sql += wxT(" AS ENUM\n ("); sql += GetQuotedLabelList(); } else if (GetTypeClass() == TYPE_RANGE) { sql += wxT(" AS RANGE\n (") wxT("SUBTYPE=") + rngsubtypestr; if (!rngsubopcstr.IsEmpty()) sql += wxT(",\n SUBTYPE_OPCLASS=") + rngsubopcstr; if (!rngcollationstr.IsEmpty()) sql += wxT(",\n COLLATION=") + rngcollationstr; if (!rngcanonical.IsEmpty()) sql += wxT(",\n CANONICAL=") + rngcanonical; if (!rngsubdiff.IsEmpty()) sql += wxT(",\n SUBTYPE_DIFF=") + rngsubdiff; } else { sql += wxT("\n (INPUT=") + qtIdent(GetInputFunction()) + wxT(",\n OUTPUT=") + qtIdent(GetOutputFunction()); if (GetConnection()->BackendMinimumVersion(7, 4)) { if (!GetReceiveFunction().IsEmpty()) { sql += wxT(",\n RECEIVE=") + GetReceiveFunction(); } if (!GetSendFunction().IsEmpty()) { sql += wxT(",\n SEND=") + GetSendFunction(); } } if (GetConnection()->BackendMinimumVersion(8, 3)) { if (!GetTypmodinFunction().IsEmpty()) sql += wxT(",\n TYPMOD_IN=") + GetTypmodinFunction(); if (!GetTypmodoutFunction().IsEmpty()) sql += wxT(",\n TYPMOD_OUT=") + GetTypmodoutFunction(); if (GetAnalyzeFunction() != wxEmptyString) sql += wxT(",\n ANALYZE=") + GetAnalyzeFunction(); } if (GetConnection()->BackendMinimumVersion(8, 4)) { sql += wxT(",\n CATEGORY=") + qtDbString(GetCategory()); if (GetPrefered()) sql += wxT(",\n PREFERRED=true"); } if (GetPassedByValue()) sql += wxT(",\n PASSEDBYVALUE"); AppendIfFilled(sql, wxT(", DEFAULT="), qtDbString(GetDefault())); if (!GetElement().IsNull()) { sql += wxT(",\n ELEMENT=") + GetElement() + wxT(", DELIMITER='") + GetDelimiter() + wxT("'"); } sql += wxT(",\n INTERNALLENGTH=") + NumToStr(GetInternalLength()) + wxT(", ALIGNMENT=" + GetAlignment() + wxT(", STORAGE=") + GetStorage()); if (GetConnection()->BackendMinimumVersion(9, 1) && GetCollatable()) { sql += wxT(",\n COLLATABLE=true"); } if (GetConnection()->BackendMinimumVersion(9, 1) && GetCollatable()) { sql += wxT(",\n COLLATABLE=true"); } } sql += wxT(");\n") + GetOwnerSql(8, 0) + GetCommentSql(); if (GetConnection()->BackendMinimumVersion(9, 1)) sql += GetSeqLabelsSql(); } return sql; }
void pgForeignTable::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane) { wxString constraint; if (!expandedKids) { expandedKids = true; pgSet *set = ExecuteSet( wxT("SELECT attname, format_type(t.oid,NULL) AS typname, attndims, atttypmod, nspname, attnotnull,\n") wxT(" (SELECT COUNT(1) from pg_type t2 WHERE t2.typname=t.typname) > 1 AS isdup\n") wxT(" FROM pg_attribute att\n") wxT(" JOIN pg_type t ON t.oid=atttypid\n") wxT(" JOIN pg_namespace nsp ON t.typnamespace=nsp.oid\n") wxT(" LEFT OUTER JOIN pg_type b ON t.typelem=b.oid\n") wxT(" WHERE att.attrelid=") + GetOidStr() + wxT("\n") wxT(" AND attnum>0\n") wxT(" ORDER by attnum")); if (set) { int anzvar = 0; while (!set->Eof()) { pgDatatype dt(set->GetVal(wxT("nspname")), set->GetVal(wxT("typname")), set->GetBool(wxT("isdup")), set->GetLong(wxT("attndims")) > 0, set->GetLong(wxT("atttypmod"))); constraint = set->GetBool(wxT("attnotnull")) ? wxT("NOT NULL") : wxT(""); if (anzvar++) { typesList += wxT(", "); quotedTypesList += wxT(",\n "); } typesList += set->GetVal(wxT("attname")) + wxT(" ") + dt.GetSchemaPrefix(GetDatabase()) + dt.FullName() + wxT(" ") + constraint; quotedTypesList += qtIdent(set->GetVal(wxT("attname"))) + wxT(" ") + dt.GetQuotedSchemaPrefix(GetDatabase()) + dt.QuotedFullName() + wxT(" ") + constraint; typesArray.Add(set->GetVal(wxT("attname"))); typesArray.Add(dt.GetSchemaPrefix(GetDatabase()) + dt.FullName()); typesArray.Add(constraint); set->MoveNext(); } delete set; } } if (properties) { CreateListColumns(properties); properties->AppendItem(_("Name"), GetName()); properties->AppendItem(_("OID"), GetOid()); properties->AppendItem(_("Owner"), GetOwner()); properties->AppendItem(_("Server"), GetForeignServer()); properties->AppendItem(_("Columns"), GetQuotedTypesList()); properties->AppendItem(_("Options"), GetOptionsList()); properties->AppendItem(_("Comment"), firstLineOnly(GetComment())); if (!GetLabels().IsEmpty()) { wxArrayString seclabels = GetProviderLabelArray(); if (seclabels.GetCount() > 0) { for (unsigned int index = 0 ; index < seclabels.GetCount() - 1 ; index += 2) { properties->AppendItem(seclabels.Item(index), seclabels.Item(index + 1)); } } } } }