forked from levinsv/pgadmin3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslTable.cpp
277 lines (233 loc) · 7.46 KB
/
slTable.cpp
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
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2016, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// slTable.cpp PostgreSQL Slony-I table
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "slony/slTable.h"
#include "frm/frmMain.h"
slTable::slTable(slSet *s, const wxString &newName)
: slSetObject(s, slTableFactory, newName)
{
}
bool slTable::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
{
return GetDatabase()->ExecuteVoid(
wxT("SELECT ") + GetCluster()->GetSchemaPrefix()
+ wxT("setdroptable(") + NumToStr(GetSlId()) + wxT(");\n"));
}
wxString slTable::GetTranslatedMessage(int kindOfMessage) const
{
wxString message = wxEmptyString;
switch (kindOfMessage)
{
case RETRIEVINGDETAILS:
message = _("Retrieving details on Slony table");
message += wxT(" ") + GetName();
break;
case REFRESHINGDETAILS:
message = _("Refreshing Slony table");
message += wxT(" ") + GetName();
break;
case DROPINCLUDINGDEPS:
message = wxString::Format(_("Are you sure you wish to drop Slony table \"%s\" including all objects that depend on it?"),
GetFullIdentifier().c_str());
break;
case DROPEXCLUDINGDEPS:
message = wxString::Format(_("Are you sure you wish to drop Slony table \"%s\"?"),
GetFullIdentifier().c_str());
break;
case DROPCASCADETITLE:
message = _("Drop Slony table cascaded?");
break;
case DROPTITLE:
message = _("Drop Slony table?");
break;
case PROPERTIESREPORT:
message = _("Slony table properties report");
message += wxT(" - ") + GetName();
break;
case PROPERTIES:
message = _("Slony table properties");
break;
case DDLREPORT:
message = _("Slony table DDL report");
message += wxT(" - ") + GetName();
break;
case DDL:
message = _("Slony table DDL");
break;
case DEPENDENCIESREPORT:
message = _("Slony table dependencies report");
message += wxT(" - ") + GetName();
break;
case DEPENDENCIES:
message = _("Slony table dependencies");
break;
case DEPENDENTSREPORT:
message = _("Slony table dependents report");
message += wxT(" - ") + GetName();
break;
case DEPENDENTS:
message = _("Slony table dependents");
break;
}
return message;
}
wxString slTable::GetSql(ctlTree *browser)
{
if (sql.IsNull())
{
sql = wxT("-- Register table ") + GetName() + wxT(" for replication.\n\n")
wxT("SELECT ") + GetCluster()->GetSchemaPrefix() + wxT("setaddtable(")
+ NumToStr(GetSet()->GetSlId()) + wxT(", ")
+ NumToStr(GetSlId()) + wxT(", ")
+ qtDbString(GetName()) + wxT(", ")
+ qtDbString(GetIndexName()) + wxT(", ")
+ qtDbString(GetComment()) + wxT(");\n");
size_t i;
for (i = 0 ; i < triggers.GetCount() ; i++)
{
sql += wxT("SELECT ") + GetCluster()->GetSchemaPrefix() + wxT("storetrigger(")
+ NumToStr(GetSlId()) + wxT(", ")
+ qtDbString(triggers[i]) + wxT(");\n");
}
}
return sql;
}
void slTable::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
if (!expandedKids)
{
expandedKids = true;
pgSet *set;
if (GetConnection()->BackendMinimumVersion(9, 0))
{
set = GetConnection()->ExecuteSet(
wxT("SELECT tgname AS trig_tgname FROM pg_trigger t, pg_proc p, pg_namespace n ")
wxT("WHERE t.tgfoid = p.oid AND p.pronamespace = n.oid ")
wxT("AND n.nspname = ") + qtDbString(wxT("_") + GetCluster()->GetName()));
}
else
{
set = GetConnection()->ExecuteSet(
wxT("SELECT trig_tgname\n")
wxT(" FROM ") + GetCluster()->GetSchemaPrefix() + wxT("sl_trigger\n")
wxT(" WHERE trig_tabid = ") + NumToStr(GetSlId()));
}
if (set)
{
while (!set->Eof())
{
triggers.Add(set->GetVal(wxT("trig_tgname")));
set->MoveNext();
}
delete set;
}
}
if (properties)
{
CreateListColumns(properties);
properties->AppendItem(_("Name"), GetName());
properties->AppendItem(_("ID"), GetSlId());
properties->AppendItem(_("Index Name"), GetIndexName());
properties->AppendYesNoItem(_("Altered"), GetAltered());
if (triggers.GetCount() > 0)
{
size_t i;
wxString triglist;
for (i = 0; i < triggers.GetCount() ; i++)
triglist += triggers[i] + wxT(", ");
properties->AppendItem(_("Triggers"), triglist.BeforeLast(','));
}
properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
}
}
pgObject *slTable::Refresh(ctlTree *browser, const wxTreeItemId item)
{
pgObject *table = 0;
pgCollection *coll = browser->GetParentCollection(item);
if (coll)
table = slTableFactory.CreateObjects(coll, 0, wxT(" WHERE tab_id=") + NumToStr(GetSlId()) + wxT("\n"));
return table;
}
pgObject *slSlTableFactory::CreateObjects(pgCollection *coll, ctlTree *browser, const wxString &restr)
{
slSetObjCollection *collection = (slSetObjCollection *)coll;
slTable *table = 0;
wxString restriction;
if (restr.IsEmpty())
restriction = wxT(" WHERE tab_set = ") + NumToStr(collection->GetSlId());
else
restriction = restr;
pgSet *tables = collection->GetDatabase()->ExecuteSet(
wxT("SELECT tab_id, tab_reloid, tab_set, nspname, relname, tab_idxname, tab_altered, tab_comment")
wxT(" FROM ") + collection->GetCluster()->GetSchemaPrefix() + wxT("sl_table\n")
wxT(" JOIN ") + collection->GetCluster()->GetSchemaPrefix() + wxT("sl_set ON set_id=tab_set\n")
wxT(" JOIN pg_class cl ON cl.oid=tab_reloid\n")
wxT(" JOIN pg_namespace nsp ON nsp.oid=relnamespace\n")
+ restriction +
wxT(" ORDER BY tab_id"));
if (tables)
{
while (!tables->Eof())
{
table = new slTable(collection->GetSet(), tables->GetVal(wxT("nspname")) + wxT(".") + tables->GetVal(wxT("relname")));
table->iSetSlId(tables->GetLong(wxT("tab_id")));
table->iSetIndexName(tables->GetVal(wxT("tab_idxname")));
table->iSetComment(tables->GetVal(wxT("tab_comment")));
table->iSetAltered(tables->GetBool(wxT("tab_altered")));
table->iSetOid(tables->GetOid(wxT("tab_reloid")));
if (browser)
{
browser->AppendObject(collection, table);
tables->MoveNext();
}
else
break;
}
delete tables;
}
return table;
}
wxString slSlTableCollection::GetTranslatedMessage(int kindOfMessage) const
{
wxString message = wxEmptyString;
switch (kindOfMessage)
{
case RETRIEVINGDETAILS:
message = _("Retrieving details on Slony tables");
break;
case REFRESHINGDETAILS:
message = _("Refreshing Slony tables");
break;
case OBJECTSLISTREPORT:
message = _("Slony tables list report");
break;
}
return message;
}
///////////////////////////////////////////////////
#include "images/table-repl.pngc"
#include "images/table-repl-sm.pngc"
#include "images/tables.pngc"
slSlTableFactory::slSlTableFactory()
: slSetObjFactory(__("Table"), __("New Table"), __("Create a new Table."), table_repl_png_img, table_repl_sm_png_img)
{
metaType = SLM_TABLE;
}
pgCollection *slSlTableFactory::CreateCollection(pgObject *obj)
{
return new slSlTableCollection(GetCollectionFactory(), (slSet *)obj);
}
slSlTableFactory slTableFactory;
static pgaCollectionFactory cf(&slTableFactory, __("Tables"), tables_png_img);