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 // pgOperatorFamily.cpp - OperatorFamily class
9 //
10 //////////////////////////////////////////////////////////////////////////
11
12 // wxWindows headers
13 #include <wx/wx.h>
14
15 // App headers
16 #include "pgAdmin3.h"
17 #include "utils/misc.h"
18 #include "schema/pgOperatorFamily.h"
19 #include "schema/pgFunction.h"
20
21
pgOperatorFamily(pgSchema * newSchema,const wxString & newName)22 pgOperatorFamily::pgOperatorFamily(pgSchema *newSchema, const wxString &newName)
23 : pgSchemaObject(newSchema, operatorFamilyFactory, newName)
24 {
25 }
26
~pgOperatorFamily()27 pgOperatorFamily::~pgOperatorFamily()
28 {
29 }
30
GetTranslatedMessage(int kindOfMessage) const31 wxString pgOperatorFamily::GetTranslatedMessage(int kindOfMessage) const
32 {
33 wxString message = wxEmptyString;
34
35 switch (kindOfMessage)
36 {
37 case RETRIEVINGDETAILS:
38 message = _("Retrieving details on operator family");
39 message += wxT(" ") + GetName();
40 break;
41 case REFRESHINGDETAILS:
42 message = _("Refreshing operator family");
43 message += wxT(" ") + GetName();
44 break;
45 case DROPINCLUDINGDEPS:
46 message = wxString::Format(_("Are you sure you wish to drop operator family \"%s\" including all objects that depend on it?"),
47 GetFullIdentifier().c_str());
48 break;
49 case DROPEXCLUDINGDEPS:
50 message = wxString::Format(_("Are you sure you wish to drop operator family \"%s\"?"),
51 GetFullIdentifier().c_str());
52 break;
53 case DROPCASCADETITLE:
54 message = _("Drop operator family cascaded?");
55 break;
56 case DROPTITLE:
57 message = _("Drop operator family?");
58 break;
59 case PROPERTIESREPORT:
60 message = _("Operator family properties report");
61 message += wxT(" - ") + GetName();
62 break;
63 case PROPERTIES:
64 message = _("Operator family properties");
65 break;
66 case DDLREPORT:
67 message = _("Operator family DDL report");
68 message += wxT(" - ") + GetName();
69 break;
70 case DDL:
71 message = _("Operator family DDL");
72 break;
73 case DEPENDENCIESREPORT:
74 message = _("Operator family dependencies report");
75 message += wxT(" - ") + GetName();
76 break;
77 case DEPENDENCIES:
78 message = _("Operator family dependencies");
79 break;
80 case DEPENDENTSREPORT:
81 message = _("Operator family dependents report");
82 message += wxT(" - ") + GetName();
83 break;
84 case DEPENDENTS:
85 message = _("Operator family dependents");
86 break;
87 }
88
89 return message;
90 }
91
DropObject(wxFrame * frame,ctlTree * browser,bool cascaded)92 bool pgOperatorFamily::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
93 {
94 wxString sql = wxT("DROP OPERATOR FAMILY ") + this->GetSchema()->GetQuotedIdentifier() + wxT(".") + this->GetQuotedIdentifier() + wxT(" USING ") + GetAccessMethod();
95 if (cascaded)
96 sql += wxT(" CASCADE");
97 return GetDatabase()->ExecuteVoid(sql);
98 }
99
GetSql(ctlTree * browser)100 wxString pgOperatorFamily::GetSql(ctlTree *browser)
101 {
102 if (sql.IsNull())
103 {
104 sql = wxT("-- Operator Family: ") + GetName() + wxT("\n\n")
105 + wxT("-- DROP OPERATOR FAMILY ") + GetQuotedFullIdentifier() + wxT(" USING ") + GetAccessMethod() + wxT(";")
106 + wxT("\n\nCREATE OPERATOR FAMILY ") + GetQuotedFullIdentifier()
107 + wxT(" USING ") + GetAccessMethod()
108 + wxT(";");
109 }
110
111 return sql;
112 }
113
114
ShowTreeDetail(ctlTree * browser,frmMain * form,ctlListView * properties,ctlSQLBox * sqlPane)115 void pgOperatorFamily::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
116 {
117 if (properties)
118 {
119 CreateListColumns(properties);
120
121 properties->AppendItem(_("Name"), GetName());
122 properties->AppendItem(_("OID"), GetOid());
123 properties->AppendItem(_("Owner"), GetOwner());
124 properties->AppendItem(_("Access method"), GetAccessMethod());
125 properties->AppendYesNoItem(_("System operator family?"), GetSystemObject());
126 properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
127 }
128 }
129
130
131
Refresh(ctlTree * browser,const wxTreeItemId item)132 pgObject *pgOperatorFamily::Refresh(ctlTree *browser, const wxTreeItemId item)
133 {
134 pgObject *operatorFamily = 0;
135 pgCollection *coll = browser->GetParentCollection(item);
136 if (coll)
137 operatorFamily = operatorFamilyFactory.CreateObjects(coll, 0, wxT("\n AND opf.oid=") + GetOidStr());
138
139 return operatorFamily;
140 }
141
142
143 ///////////////////////////////////////////////////
144
145
pgOperatorFamilyCollection(pgaFactory * factory,pgSchema * sch)146 pgOperatorFamilyCollection::pgOperatorFamilyCollection(pgaFactory *factory, pgSchema *sch)
147 : pgSchemaObjCollection(factory, sch)
148 {
149 }
150
151
GetTranslatedMessage(int kindOfMessage) const152 wxString pgOperatorFamilyCollection::GetTranslatedMessage(int kindOfMessage) const
153 {
154 wxString message = wxEmptyString;
155
156 switch (kindOfMessage)
157 {
158 case RETRIEVINGDETAILS:
159 message = _("Retrieving details on operator families");
160 break;
161 case REFRESHINGDETAILS:
162 message = _("Refreshing operator families");
163 break;
164 case OBJECTSLISTREPORT:
165 message = _("Operator families list report");
166 break;
167 }
168
169 return message;
170 }
171
172
173 ///////////////////////////////////////////////////
174
175
CreateObjects(pgCollection * collection,ctlTree * browser,const wxString & restriction)176 pgObject *pgOperatorFamilyFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
177 {
178 pgOperatorFamily *operatorFamily = 0;
179
180 pgSet *operatorFamilies;
181
182 operatorFamilies = collection->GetDatabase()->ExecuteSet(
183 wxT("SELECT opf.oid, opf.*, pg_get_userbyid(opf.opfowner) as opowner, amname\n")
184 wxT(" FROM pg_opfamily opf\n")
185 wxT(" JOIN pg_am am ON am.oid=opf.opfmethod\n")
186 wxT(" WHERE opfnamespace = ") + collection->GetSchema()->GetOidStr()
187 + restriction + wxT("\n")
188 wxT(" ORDER BY opfname"));
189
190
191 if (operatorFamilies)
192 {
193 while (!operatorFamilies->Eof())
194 {
195 operatorFamily = new pgOperatorFamily(
196 collection->GetSchema(), operatorFamilies->GetVal(wxT("opfname")));
197
198 operatorFamily->iSetOid(operatorFamilies->GetOid(wxT("oid")));
199 operatorFamily->iSetOwner(operatorFamilies->GetVal(wxT("opowner")));
200 operatorFamily->iSetAccessMethod(operatorFamilies->GetVal(wxT("amname")));
201
202 if (browser)
203 {
204 browser->AppendObject(collection, operatorFamily);
205 operatorFamilies->MoveNext();
206 }
207 else
208 break;
209 }
210
211 delete operatorFamilies;
212 }
213 return operatorFamily;
214 }
215
216
217 #include "images/operatorfamily.pngc"
218 #include "images/operatorfamilies.pngc"
219
pgOperatorFamilyFactory()220 pgOperatorFamilyFactory::pgOperatorFamilyFactory()
221 : pgSchemaObjFactory(__("Operator Family"), __("New Operator Family..."), __("Create a new Operator Family."), operatorfamily_png_img)
222 {
223 metaType = PGM_OPFAMILY;
224 }
225
CreateDialog(frmMain * frame,pgObject * node,pgObject * parent)226 dlgProperty *pgOperatorFamilyFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
227 {
228 return 0; // not implemented
229 }
230
CreateCollection(pgObject * obj)231 pgCollection *pgOperatorFamilyFactory::CreateCollection(pgObject *obj)
232 {
233 return new pgOperatorFamilyCollection(GetCollectionFactory(), (pgSchema *)obj);
234 }
235
236 pgOperatorFamilyFactory operatorFamilyFactory;
237 static pgaCollectionFactory cf(&operatorFamilyFactory, __("Operator Families"), operatorfamilies_png_img);
238