1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// pgLanguage.cpp - Language class
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "schema/pgLanguage.h"
pgLanguage::pgLanguage(const wxString &newName)
: pgDatabaseObject(languageFactory, newName)
{
}
wxString pgLanguage::GetTranslatedMessage(int kindOfMessage) const
{
wxString message = wxEmptyString;
switch (kindOfMessage)
{
case RETRIEVINGDETAILS:
message = _("Retrieving details on language");
message += wxT(" ") + GetName();
break;
case REFRESHINGDETAILS:
message = _("Refreshing language");
message += wxT(" ") + GetName();
break;
case DROPINCLUDINGDEPS:
message = wxString::Format(_("Are you sure you wish to drop language \"%s\" including all objects that depend on it?"),
GetFullIdentifier().c_str());
break;
case DROPEXCLUDINGDEPS:
message = wxString::Format(_("Are you sure you wish to drop language \"%s\"?"),
GetFullIdentifier().c_str());
break;
case DROPCASCADETITLE:
message = _("Drop language cascaded?");
break;
case DROPTITLE:
message = _("Drop language?");
break;
case PROPERTIESREPORT:
message = _("Language properties report");
message += wxT(" - ") + GetName();
break;
case PROPERTIES:
message = _("Language properties");
break;
case DDLREPORT:
message = _("Language DDL report");
message += wxT(" - ") + GetName();
break;
case DDL:
message = _("Language DDL");
break;
case DEPENDENCIESREPORT:
message = _("Language dependencies report");
message += wxT(" - ") + GetName();
break;
case DEPENDENCIES:
message = _("Language dependencies");
break;
case DEPENDENTSREPORT:
message = _("Language dependents report");
message += wxT(" - ") + GetName();
break;
case DEPENDENTS:
message = _("Language dependents");
break;
}
return message;
}
bool pgLanguage::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
{
wxString sql = wxT("DROP LANGUAGE ") + GetQuotedFullIdentifier();
if (cascaded)
sql += wxT(" CASCADE");
return GetDatabase()->ExecuteVoid(sql);
}
wxString pgLanguage::GetSql(ctlTree *browser)
{
if (sql.IsNull())
{
sql = wxT("-- Language: ") + GetQuotedFullIdentifier() + wxT("\n\n")
+ wxT("-- DROP LANGUAGE ") + GetQuotedFullIdentifier() + wxT(";")
+ wxT("\n\nCREATE ");
if (GetTrusted())
sql += wxT("TRUSTED ");
sql += wxT("PROCEDURAL LANGUAGE '") + GetName()
+ wxT("'\n HANDLER ") + qtIdent(GetHandlerProc());
if (!GetInlineProc().IsEmpty())
sql += wxT("\n INLINE ") + qtIdent(GetInlineProc());
if (!GetValidatorProc().IsEmpty())
sql += wxT("\n VALIDATOR ") + qtIdent(GetValidatorProc());
sql += wxT(";\n")
+ GetOwnerSql(8, 3, wxT("LANGUAGE ") + GetName())
+ GetGrant(wxT("U"), wxT("LANGUAGE ") + GetQuotedFullIdentifier());
if (GetConnection()->BackendMinimumVersion(9, 1))
sql += GetSeqLabelsSql();
}
return sql;
}
void pgLanguage::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
if (properties)
{
CreateListColumns(properties);
properties->AppendItem(_("Name"), GetName());
properties->AppendItem(_("OID"), GetOid());
if (GetConnection()->BackendMinimumVersion(8, 3))
properties->AppendItem(_("Owner"), GetOwner());
properties->AppendItem(_("ACL"), GetAcl());
properties->AppendYesNoItem(_("Trusted?"), GetTrusted());
properties->AppendItem(_("Handler function"), GetHandlerProc());
if (GetConnection()->BackendMinimumVersion(9, 0))
properties->AppendItem(_("Inline function"), GetInlineProc());
properties->AppendItem(_("Validator function"), GetValidatorProc());
properties->AppendYesNoItem(_("System language?"), GetSystemObject());
if (GetConnection()->BackendMinimumVersion(7, 5))
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));
}
}
}
}
}
pgObject *pgLanguage::Refresh(ctlTree *browser, const wxTreeItemId item)
{
pgObject *language = 0;
pgCollection *coll = browser->GetParentCollection(item);
if (coll)
language = languageFactory.CreateObjects(coll, 0, wxT("\n AND lan.oid=") + GetOidStr());
return language;
}
pgObject *pgLanguageFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
{
wxString sql;
pgLanguage *language = 0;
sql = wxT("SELECT lan.oid, lanname, lanpltrusted, lanacl, hp.proname as lanproc, vp.proname as lanval, description");
if (collection->GetConnection()->BackendMinimumVersion(8, 3))
sql += wxT(", pg_get_userbyid(lan.lanowner) as languageowner");
if (collection->GetConnection()->BackendMinimumVersion(9, 0))
sql += wxT(", ip.proname as laninl");
if (collection->GetDatabase()->BackendMinimumVersion(9, 1))
{
sql += wxT(",\n(SELECT array_agg(label) FROM pg_seclabels sl1 WHERE sl1.objoid=lan.oid) AS labels");
sql += wxT(",\n(SELECT array_agg(provider) FROM pg_seclabels sl2 WHERE sl2.objoid=lan.oid) AS providers");
}
sql += wxT("\n FROM pg_language lan\n")
wxT(" JOIN pg_proc hp on hp.oid=lanplcallfoid\n");
if (collection->GetConnection()->BackendMinimumVersion(9, 0))
sql += wxT(" LEFT OUTER JOIN pg_proc ip on ip.oid=laninline\n");
sql += wxT(" LEFT OUTER JOIN pg_proc vp on vp.oid=lanvalidator\n")
wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=lan.oid AND des.objsubid=0 AND des.classoid='pg_language'::regclass)\n")
wxT(" WHERE lanispl IS TRUE")
+ restriction + wxT("\n")
wxT(" ORDER BY lanname");
pgSet *languages = collection->GetDatabase()->ExecuteSet(sql);
if (languages)
{
while (!languages->Eof())
{
language = new pgLanguage(languages->GetVal(wxT("lanname")));
language->iSetDatabase(collection->GetDatabase());
language->iSetOid(languages->GetOid(wxT("oid")));
if (collection->GetConnection()->BackendMinimumVersion(8, 3))
{
language->iSetOwner(languages->GetVal(wxT("languageowner")));
}
language->iSetAcl(languages->GetVal(wxT("lanacl")));
language->iSetComment(languages->GetVal(wxT("description")));
language->iSetHandlerProc(languages->GetVal(wxT("lanproc")));
if (collection->GetConnection()->BackendMinimumVersion(9, 0))
{
language->iSetInlineProc(languages->GetVal(wxT("laninl")));
}
language->iSetValidatorProc(languages->GetVal(wxT("lanval")));
language->iSetTrusted(languages->GetBool(wxT("lanpltrusted")));
if (collection->GetDatabase()->BackendMinimumVersion(9, 1))
{
language->iSetProviders(languages->GetVal(wxT("providers")));
language->iSetLabels(languages->GetVal(wxT("labels")));
}
if (browser)
{
browser->AppendObject(collection, language);
languages->MoveNext();
}
else
break;
}
delete languages;
}
return language;
}
/////////////////////////////
pgLanguageCollection::pgLanguageCollection(pgaFactory *factory, pgDatabase *db)
: pgDatabaseObjCollection(factory, db)
{
}
wxString pgLanguageCollection::GetTranslatedMessage(int kindOfMessage) const
{
wxString message = wxEmptyString;
switch (kindOfMessage)
{
case RETRIEVINGDETAILS:
message = _("Retrieving details on languages");
break;
case REFRESHINGDETAILS:
message = _("Refreshing languages");
break;
case OBJECTSLISTREPORT:
message = _("Languages list report");
break;
}
return message;
}
///////////////////////////////////////////////////
#include "images/language.pngc"
#include "images/language-sm.pngc"
#include "images/languages.pngc"
pgLanguageFactory::pgLanguageFactory()
: pgDatabaseObjFactory(__("Language"), __("New Language..."), __("Create a new Language."), language_png_img, language_sm_png_img)
{
metaType = PGM_LANGUAGE;
}
pgCollection *pgLanguageFactory::CreateCollection(pgObject *obj)
{
return new pgLanguageCollection(GetCollectionFactory(), (pgDatabase *)obj);
}
pgLanguageFactory languageFactory;
static pgaCollectionFactory cf(&languageFactory, __("Languages"), languages_png_img);
|