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 // pgTextSearchTemplate.cpp - Text Search Template 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/pgTextSearchTemplate.h"
19
20
pgTextSearchTemplate(pgSchema * newSchema,const wxString & newName)21 pgTextSearchTemplate::pgTextSearchTemplate(pgSchema *newSchema, const wxString &newName)
22 : pgSchemaObject(newSchema, textSearchTemplateFactory, newName)
23 {
24 }
25
~pgTextSearchTemplate()26 pgTextSearchTemplate::~pgTextSearchTemplate()
27 {
28 }
29
GetTranslatedMessage(int kindOfMessage) const30 wxString pgTextSearchTemplate::GetTranslatedMessage(int kindOfMessage) const
31 {
32 wxString message = wxEmptyString;
33
34 switch (kindOfMessage)
35 {
36 case RETRIEVINGDETAILS:
37 message = _("Retrieving details on FTS template");
38 message += wxT(" ") + GetName();
39 break;
40 case REFRESHINGDETAILS:
41 message = _("Refreshing FTS template");
42 message += wxT(" ") + GetName();
43 break;
44 case DROPINCLUDINGDEPS:
45 message = wxString::Format(_("Are you sure you wish to drop FTS template \"%s\" including all objects that depend on it?"),
46 GetFullIdentifier().c_str());
47 break;
48 case DROPEXCLUDINGDEPS:
49 message = wxString::Format(_("Are you sure you wish to drop FTS template \"%s\"?"),
50 GetFullIdentifier().c_str());
51 break;
52 case DROPCASCADETITLE:
53 message = _("Drop FTS template cascaded?");
54 break;
55 case DROPTITLE:
56 message = _("Drop FTS template?");
57 break;
58 case PROPERTIESREPORT:
59 message = _("FTS template properties report");
60 message += wxT(" - ") + GetName();
61 break;
62 case PROPERTIES:
63 message = _("FTS template properties");
64 break;
65 case DDLREPORT:
66 message = _("FTS template DDL report");
67 message += wxT(" - ") + GetName();
68 break;
69 case DDL:
70 message = _("FTS template DDL");
71 break;
72 case DEPENDENCIESREPORT:
73 message = _("FTS template dependencies report");
74 message += wxT(" - ") + GetName();
75 break;
76 case DEPENDENCIES:
77 message = _("FTS template dependencies");
78 break;
79 case DEPENDENTSREPORT:
80 message = _("FTS template dependents report");
81 message += wxT(" - ") + GetName();
82 break;
83 case DEPENDENTS:
84 message = _("FTS template dependents");
85 break;
86 }
87
88 return message;
89 }
90
DropObject(wxFrame * frame,ctlTree * browser,bool cascaded)91 bool pgTextSearchTemplate::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
92 {
93 wxString sql = wxT("DROP TEXT SEARCH TEMPLATE ") + this->GetSchema()->GetQuotedIdentifier() + wxT(".") + qtIdent(this->GetIdentifier());
94
95 if (cascaded)
96 sql += wxT(" CASCADE");
97
98 return GetDatabase()->ExecuteVoid(sql);
99 }
100
101
GetSql(ctlTree * browser)102 wxString pgTextSearchTemplate::GetSql(ctlTree *browser)
103 {
104 if (sql.IsNull())
105 {
106 sql = wxT("-- Text Search Template: ") + GetFullIdentifier() + wxT("\n\n")
107 + wxT("-- DROP TEXT SEARCH TEMPLATE ") + GetFullIdentifier() + wxT("\n\n")
108 wxT("CREATE TEXT SEARCH TEMPLATE ") + GetFullIdentifier() + wxT(" (");
109 AppendIfFilled(sql, wxT("\n INIT = "), GetInit());
110 AppendIfFilled(sql, wxT(",\n LEXIZE = "), GetLexize());
111 sql += wxT("\n);\n");
112
113 if (!GetComment().IsNull())
114 sql += wxT("COMMENT ON TEXT SEARCH TEMPLATE ") + GetFullIdentifier()
115 + wxT(" IS ") + qtDbString(GetComment()) + wxT(";\n");
116 }
117
118 return sql;
119 }
120
121
ShowTreeDetail(ctlTree * browser,frmMain * form,ctlListView * properties,ctlSQLBox * sqlPane)122 void pgTextSearchTemplate::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
123 {
124 if (properties)
125 {
126 CreateListColumns(properties);
127
128 properties->AppendItem(_("Name"), GetName());
129 properties->AppendItem(_("OID"), GetOid());
130 properties->AppendItem(_("Init"), GetInit());
131 properties->AppendItem(_("Lexize"), GetLexize());
132 properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
133 }
134 }
135
136
137
Refresh(ctlTree * browser,const wxTreeItemId item)138 pgObject *pgTextSearchTemplate::Refresh(ctlTree *browser, const wxTreeItemId item)
139 {
140 pgObject *tstemplate = 0;
141 pgCollection *coll = browser->GetParentCollection(item);
142 if (coll)
143 tstemplate = textSearchTemplateFactory.CreateObjects(coll, 0, wxT("\n AND tmpl.oid=") + GetOidStr());
144
145 return tstemplate;
146 }
147
148
149 ///////////////////////////////////////////////////
150
151
pgTextSearchTemplateCollection(pgaFactory * factory,pgSchema * sch)152 pgTextSearchTemplateCollection::pgTextSearchTemplateCollection(pgaFactory *factory, pgSchema *sch)
153 : pgSchemaObjCollection(factory, sch)
154 {
155 }
156
157
GetTranslatedMessage(int kindOfMessage) const158 wxString pgTextSearchTemplateCollection::GetTranslatedMessage(int kindOfMessage) const
159 {
160 wxString message = wxEmptyString;
161
162 switch (kindOfMessage)
163 {
164 case RETRIEVINGDETAILS:
165 message = _("Retrieving details on FTS templates");
166 break;
167 case REFRESHINGDETAILS:
168 message = _("Refreshing FTS templates");
169 break;
170 case OBJECTSLISTREPORT:
171 message = _("FTS templates list report");
172 break;
173 }
174
175 return message;
176 }
177
178
179 //////////////////////////////////////////////////////
180
181
CreateObjects(pgCollection * collection,ctlTree * browser,const wxString & restriction)182 pgObject *pgTextSearchTemplateFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
183 {
184 pgTextSearchTemplate *tmpl = 0;
185
186 pgSet *templates;
187 templates = collection->GetDatabase()->ExecuteSet(
188 wxT("SELECT tmpl.oid, tmpl.tmplname, tmpl.tmplinit, tmpl.tmpllexize, description\n")
189 wxT(" FROM pg_ts_template tmpl\n")
190 wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=tmpl.oid AND des.classoid='pg_ts_template'::regclass)\n")
191 wxT(" WHERE tmpl.tmplnamespace = ") + collection->GetSchema()->GetOidStr()
192 + restriction + wxT("\n")
193 wxT(" ORDER BY tmpl.tmplname"));
194
195 if (templates)
196 {
197 while (!templates->Eof())
198 {
199 tmpl = new pgTextSearchTemplate(collection->GetSchema(), templates->GetVal(wxT("tmplname")));
200 tmpl->iSetOid(templates->GetOid(wxT("oid")));
201 tmpl->iSetComment(templates->GetVal(wxT("description")));
202 if (templates->GetVal(wxT("tmplinit")).Cmp(wxT("-")) != 0)
203 {
204 tmpl->iSetInit(templates->GetVal(wxT("tmplinit")));
205 }
206 else
207 {
208 tmpl->iSetInit(wxT(""));
209 }
210 tmpl->iSetLexize(templates->GetVal(wxT("tmpllexize")));
211
212 if (browser)
213 {
214 browser->AppendObject(collection, tmpl);
215 templates->MoveNext();
216 }
217 else
218 break;
219 }
220
221 delete templates;
222 }
223 return tmpl;
224 }
225
226
227 #include "images/template.pngc"
228 #include "images/templates.pngc"
229
pgTextSearchTemplateFactory()230 pgTextSearchTemplateFactory::pgTextSearchTemplateFactory()
231 : pgSchemaObjFactory(__("FTS Template"), __("New FTS Template..."), __("Create a new FTS Template."), template_png_img)
232 {
233 }
234
235
CreateCollection(pgObject * obj)236 pgCollection *pgTextSearchTemplateFactory::CreateCollection(pgObject *obj)
237 {
238 return new pgTextSearchTemplateCollection(GetCollectionFactory(), (pgSchema *)obj);
239 }
240
241 pgTextSearchTemplateFactory textSearchTemplateFactory;
242 static pgaCollectionFactory cf(&textSearchTemplateFactory, __("FTS Templates"), templates_png_img);
243