1 //////////////////////////////////////////////////////////////////////////
2 //
3 // pgAdmin III - PostgreSQL Tools
4 //
5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team
6 // This software is released under the PostgreSQL Licence
7 //
8 // edbPackageVariable.cpp - EnterpriseDB Package variable
9 //
10 //////////////////////////////////////////////////////////////////////////
11
12 // wxWindows headers
13 #include <wx/wx.h>
14
15 // App headers
16 #include "pgAdmin3.h"
17 #include "schema/edbPackageVariable.h"
18
19
edbPackageVariable(edbPackage * newPackage,const wxString & newName)20 edbPackageVariable::edbPackageVariable(edbPackage *newPackage, const wxString &newName)
21 : edbPackageObject(newPackage, packageVariableFactory, newName)
22 {
23 }
24
GetTranslatedMessage(int kindOfMessage) const25 wxString edbPackageVariable::GetTranslatedMessage(int kindOfMessage) const
26 {
27 wxString message = wxEmptyString;
28
29 switch (kindOfMessage)
30 {
31 case RETRIEVINGDETAILS:
32 message = _("Retrieving details on package variable");
33 message += wxT(" ") + GetName();
34 break;
35 case REFRESHINGDETAILS:
36 message = _("Refreshing package variable");
37 message += wxT(" ") + GetName();
38 break;
39 case DROPINCLUDINGDEPS:
40 message = wxString::Format(_("Are you sure you wish to drop package variable \"%s\" including all objects that depend on it?"),
41 GetFullIdentifier().c_str());
42 break;
43 case DROPEXCLUDINGDEPS:
44 message = wxString::Format(_("Are you sure you wish to drop package variable \"%s\"?"),
45 GetFullIdentifier().c_str());
46 break;
47 case DROPCASCADETITLE:
48 message = _("Drop package variable cascaded?");
49 break;
50 case DROPTITLE:
51 message = _("Drop package variable?");
52 break;
53 case PROPERTIESREPORT:
54 message = _("Package variable properties report");
55 message += wxT(" - ") + GetName();
56 break;
57 case PROPERTIES:
58 message = _("Package variable properties");
59 break;
60 case DDLREPORT:
61 message = _("Package variable DDL report");
62 message += wxT(" - ") + GetName();
63 break;
64 case DDL:
65 message = _("Package variable DDL");
66 break;
67 }
68
69 return message;
70 }
71
72
GetSql(ctlTree * browser)73 wxString edbPackageVariable::GetSql(ctlTree *browser)
74 {
75 if (sql.IsNull())
76 {
77 sql = wxT("-- Package Variable: ") + GetName() + wxT("\n\n");
78 sql += GetName() + wxT(" ") + GetDataType() + wxT(";\n\n");
79 }
80
81 return sql;
82 }
83
ShowTreeDetail(ctlTree * browser,frmMain * form,ctlListView * properties,ctlSQLBox * sqlPane)84 void edbPackageVariable::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
85 {
86 if (properties)
87 {
88 CreateListColumns(properties);
89
90 properties->AppendItem(_("Name"), GetName());
91 properties->AppendItem(_("OID"), GetOid());
92 properties->AppendItem(_("Data type"), GetDataType());
93 properties->AppendItem(_("Visibility"), GetVisibility());
94 }
95 }
96
97
98
Refresh(ctlTree * browser,const wxTreeItemId item)99 pgObject *edbPackageVariable::Refresh(ctlTree *browser, const wxTreeItemId item)
100 {
101 pgObject *packageVariable = 0;
102 pgCollection *coll = browser->GetParentCollection(item);
103 if (coll)
104 {
105 if (coll->GetConnection()->EdbMinimumVersion(8, 2))
106 packageVariable = packageVariableFactory.CreateObjects(coll, 0, wxT("\n AND varname='") + GetName() + wxT("'"));
107 else
108 packageVariable = packageVariableFactory.CreateObjects(coll, 0, wxT("\n AND eltname='") + GetName() + wxT("'"));
109 }
110
111 return packageVariable;
112 }
113
114
115 ///////////////////////////////////////////////////
116
CreateObjects(pgCollection * collection,ctlTree * browser,const wxString & restriction)117 pgObject *edbPackageVariableFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
118 {
119
120 edbPackageVariable *packageVariable = 0;
121
122 pgSet *packageVariables;
123
124 wxString sql;
125
126 if (collection->GetConnection()->EdbMinimumVersion(8, 2))
127 {
128 sql = wxT("SELECT oid, varname AS eltname, varaccess AS visibility, format_type(vartype, NULL) as datatype FROM edb_variable\n")
129 wxT(" WHERE varpackage = ") + ((edbPackageObjCollection *)collection)->GetPackage()->GetOidStr() + wxT("\n")
130 + restriction + wxT("\n")
131 wxT(" ORDER BY varname");
132 }
133 else
134 {
135 sql = wxT("SELECT oid, eltname, visibility, format_type(eltdatatype, NULL) as datatype FROM edb_pkgelements\n")
136 wxT(" WHERE eltclass = 'V'\n")
137 wxT(" AND packageoid = ") + ((edbPackageObjCollection *)collection)->GetPackage()->GetOidStr() + wxT("\n")
138 + restriction + wxT("\n")
139 wxT(" ORDER BY eltname");
140 }
141
142 packageVariables = collection->GetDatabase()->ExecuteSet(sql);
143
144 if (packageVariables)
145 {
146 edbPackage *package = ((edbPackageObjCollection *)collection)->GetPackage();
147
148 while (!packageVariables->Eof())
149 {
150 // Do not create edbPackageVariable, if package is wrapped
151 if (package->GetBody().Trim(false).StartsWith(wxT("$__EDBwrapped__$")))
152 {
153 packageVariables->MoveNext();
154 continue;
155 }
156 packageVariable = new edbPackageVariable(package, packageVariables->GetVal(wxT("eltname")));
157 packageVariable->iSetOid(packageVariables->GetOid(wxT("oid")));
158 packageVariable->iSetDataType(packageVariables->GetVal(wxT("datatype")));
159 if (packageVariables->GetVal(wxT("visibility")) == wxT("+"))
160 packageVariable->iSetVisibility(_("Public"));
161 else if (packageVariables->GetVal(wxT("visibility")) == wxT("-"))
162 packageVariable->iSetVisibility(_("Private"));
163 else
164 packageVariable->iSetVisibility(_("Unknown"));
165
166 if (browser)
167 {
168 browser->AppendObject(collection, packageVariable);
169 packageVariables->MoveNext();
170 }
171 else
172 break;
173 }
174
175 delete packageVariables;
176 }
177 return packageVariable;
178 }
179
180 /////////////////////////////
181
edbPackageVariableCollection(pgaFactory * factory,edbPackage * pkg)182 edbPackageVariableCollection::edbPackageVariableCollection(pgaFactory *factory, edbPackage *pkg)
183 : edbPackageObjCollection(factory, pkg)
184 {
185 }
186
GetTranslatedMessage(int kindOfMessage) const187 wxString edbPackageVariableCollection::GetTranslatedMessage(int kindOfMessage) const
188 {
189 wxString message = wxEmptyString;
190
191 switch (kindOfMessage)
192 {
193 case RETRIEVINGDETAILS:
194 message = _("Retrieving details on package variables");
195 break;
196 case REFRESHINGDETAILS:
197 message = _("Refreshing package variables");
198 break;
199 case GRANTWIZARDTITLE:
200 message = _("Privileges for package variables");
201 break;
202 case OBJECTSLISTREPORT:
203 message = _("Package variables list report");
204 break;
205 }
206
207 return message;
208 }
209
210 /////////////////////////////
211
212 #include "images/variable.pngc"
213 #include "images/variables.pngc"
214
edbPackageVariableFactory()215 edbPackageVariableFactory::edbPackageVariableFactory()
216 : edbPackageObjFactory(__("Variable"), __("New Variable..."), __("Create a new Variable."), variable_png_img)
217 {
218 metaType = EDB_PACKAGEVARIABLE;
219 }
220
CreateCollection(pgObject * obj)221 pgCollection *edbPackageVariableFactory::CreateCollection(pgObject *obj)
222 {
223 return new edbPackageVariableCollection(GetCollectionFactory(), (edbPackage *)obj);
224 }
225
226 edbPackageVariableFactory packageVariableFactory;
227 static pgaCollectionFactory cf(&packageVariableFactory, __("Variables"), variables_png_img);
228