18
18
#include "schema/pgSequence.h"
21
pgSequence::pgSequence(pgSchema *newSchema, const wxString& newName)
22
: pgSchemaObject(newSchema, sequenceFactory, newName)
21
pgSequence::pgSequence(pgSchema *newSchema, const wxString &newName)
22
: pgSchemaObject(newSchema, sequenceFactory, newName)
27
27
pgSequence::~pgSequence()
31
wxString pgSequence::GetTranslatedMessage(int kindOfMessage) const
33
wxString message = wxEmptyString;
35
switch (kindOfMessage)
37
case RETRIEVINGDETAILS:
38
message = _("Retrieving details on sequence");
39
message += wxT(" ") + GetName();
41
case REFRESHINGDETAILS:
42
message = _("Refreshing sequence");
43
message += wxT(" ") + GetName();
45
case DROPINCLUDINGDEPS:
46
message = wxString::Format(_("Are you sure you wish to drop sequence \"%s\" including all objects that depend on it?"),
47
GetFullIdentifier().c_str());
49
case DROPEXCLUDINGDEPS:
50
message = wxString::Format(_("Are you sure you wish to drop sequence \"%s\"?"),
51
GetFullIdentifier().c_str());
53
case DROPCASCADETITLE:
54
message = _("Drop sequence cascaded?");
57
message = _("Drop sequence?");
59
case PROPERTIESREPORT:
60
message = _("Sequence properties report");
61
message += wxT(" - ") + GetName();
64
message = _("Sequence properties");
67
message = _("Sequence DDL report");
68
message += wxT(" - ") + GetName();
71
message = _("Sequence DDL");
73
case STATISTICSREPORT:
74
message = _("Sequence statistics report");
75
message += wxT(" - ") + GetName();
78
message = _("Sequence statistics");
80
case DEPENDENCIESREPORT:
81
message = _("Sequence dependencies report");
82
message += wxT(" - ") + GetName();
85
message = _("Sequence dependencies");
87
case DEPENDENTSREPORT:
88
message = _("Sequence dependents report");
89
message += wxT(" - ") + GetName();
92
message = _("Sequence dependents");
31
100
int pgSequence::GetIconId()
34
return sequenceFactory.GetReplicatedIconId();
36
return sequenceFactory.GetIconId();
103
return sequenceFactory.GetReplicatedIconId();
105
return sequenceFactory.GetIconId();
39
108
bool pgSequence::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
41
wxString sql = wxT("DROP SEQUENCE ") + this->GetSchema()->GetQuotedIdentifier() + wxT(".") + this->GetQuotedIdentifier();
43
sql += wxT(" CASCADE");
44
return GetDatabase()->ExecuteVoid(sql);
110
wxString sql = wxT("DROP SEQUENCE ") + this->GetSchema()->GetQuotedIdentifier() + wxT(".") + this->GetQuotedIdentifier();
112
sql += wxT(" CASCADE");
113
return GetDatabase()->ExecuteVoid(sql);
48
117
void pgSequence::UpdateValues()
50
pgSet *sequence=ExecuteSet(
51
wxT("SELECT last_value, min_value, max_value, cache_value, is_cycled, increment_by, is_called\n")
52
wxT(" FROM ") + GetQuotedFullIdentifier());
55
lastValue = sequence->GetLongLong(wxT("last_value"));
56
minValue = sequence->GetLongLong(wxT("min_value"));
57
maxValue = sequence->GetLongLong(wxT("max_value"));
58
cacheValue = sequence->GetLongLong(wxT("cache_value"));
59
increment = sequence->GetLongLong(wxT("increment_by"));
60
cycled = sequence->GetBool(wxT("is_cycled"));
61
called = sequence->GetBool(wxT("is_called"));
119
pgSet *sequence = ExecuteSet(
120
wxT("SELECT last_value, min_value, max_value, cache_value, is_cycled, increment_by, is_called\n")
121
wxT(" FROM ") + GetQuotedFullIdentifier());
124
lastValue = sequence->GetLongLong(wxT("last_value"));
125
minValue = sequence->GetLongLong(wxT("min_value"));
126
maxValue = sequence->GetLongLong(wxT("max_value"));
127
cacheValue = sequence->GetLongLong(wxT("cache_value"));
128
increment = sequence->GetLongLong(wxT("increment_by"));
129
cycled = sequence->GetBool(wxT("is_cycled"));
130
called = sequence->GetBool(wxT("is_called"));
68
137
wxString pgSequence::GetSql(ctlTree *browser)
73
sql = wxT("-- Sequence: ") + GetQuotedFullIdentifier() + wxT("\n\n")
74
+ wxT("-- DROP SEQUENCE ") + GetQuotedFullIdentifier() + wxT(";")
75
+ wxT("\n\nCREATE SEQUENCE ") + GetQuotedFullIdentifier()
76
+ wxT("\n INCREMENT ") + GetIncrement().ToString()
77
+ wxT("\n MINVALUE ") + GetMinValue().ToString()
78
+ wxT("\n MAXVALUE ") + GetMaxValue().ToString()
79
+ wxT("\n START ") + GetLastValue().ToString()
80
+ wxT("\n CACHE ") + GetCacheValue().ToString();
82
sql += wxT("\n CYCLE");
84
+ GetOwnerSql(7, 3, wxT("TABLE ") + GetQuotedFullIdentifier());
86
if (!GetConnection()->BackendMinimumVersion(8, 2))
87
sql += GetGrant(wxT("arwdRxt"), wxT("TABLE ") + GetQuotedFullIdentifier());
89
sql += GetGrant(wxT("rwU"), wxT("TABLE ") + GetQuotedFullIdentifier());
91
sql += GetCommentSql();
142
sql = wxT("-- Sequence: ") + GetQuotedFullIdentifier() + wxT("\n\n")
143
+ wxT("-- DROP SEQUENCE ") + GetQuotedFullIdentifier() + wxT(";")
144
+ wxT("\n\nCREATE SEQUENCE ") + GetQuotedFullIdentifier()
145
+ wxT("\n INCREMENT ") + GetIncrement().ToString()
146
+ wxT("\n MINVALUE ") + GetMinValue().ToString()
147
+ wxT("\n MAXVALUE ") + GetMaxValue().ToString()
148
+ wxT("\n START ") + GetLastValue().ToString()
149
+ wxT("\n CACHE ") + GetCacheValue().ToString();
151
sql += wxT("\n CYCLE");
153
+ GetOwnerSql(7, 3, wxT("TABLE ") + GetQuotedFullIdentifier());
155
if (!GetConnection()->BackendMinimumVersion(8, 2))
156
sql += GetGrant(wxT("arwdRxt"), wxT("TABLE ") + GetQuotedFullIdentifier());
158
sql += GetGrant(wxT("rwU"), wxT("TABLE ") + GetQuotedFullIdentifier());
160
sql += GetCommentSql();
97
166
void pgSequence::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
102
CreateListColumns(properties);
171
CreateListColumns(properties);
104
properties->AppendItem(_("Name"), GetName());
105
properties->AppendItem(_("OID"), GetOid());
106
properties->AppendItem(_("Owner"), GetOwner());
107
properties->AppendItem(_("ACL"), GetAcl());
108
properties->AppendItem(_("Current value"), GetLastValue());
109
properties->AppendItem(_("Minimum"), GetMinValue());
110
properties->AppendItem(_("Maximum"), GetMaxValue());
111
properties->AppendItem(_("Increment"), GetIncrement());
112
properties->AppendItem(_("Cache"), GetCacheValue());
113
properties->AppendItem(_("Cycled?"), GetCycled());
114
properties->AppendItem(_("Called?"), GetCalled());
115
properties->AppendItem(_("System sequence?"), GetSystemObject());
116
properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
173
properties->AppendItem(_("Name"), GetName());
174
properties->AppendItem(_("OID"), GetOid());
175
properties->AppendItem(_("Owner"), GetOwner());
176
properties->AppendItem(_("ACL"), GetAcl());
177
properties->AppendItem(_("Current value"), GetLastValue());
178
properties->AppendItem(_("Minimum"), GetMinValue());
179
properties->AppendItem(_("Maximum"), GetMaxValue());
180
properties->AppendItem(_("Increment"), GetIncrement());
181
properties->AppendItem(_("Cache"), GetCacheValue());
182
properties->AppendYesNoItem(_("Cycled?"), GetCycled());
183
properties->AppendYesNoItem(_("Called?"), GetCalled());
184
properties->AppendYesNoItem(_("System sequence?"), GetSystemObject());
185
properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
122
191
void pgSequence::ShowStatistics(frmMain *form, ctlListView *statistics)
124
wxLogInfo(wxT("Displaying statistics for sequence on ") +GetSchema()->GetIdentifier());
126
// Add the statistics view columns
127
CreateListColumns(statistics, _("Statistic"), _("Value"));
129
pgSet *stats = GetSchema()->GetDatabase()->ExecuteSet(wxT(
130
"SELECT blks_read, blks_hit FROM pg_statio_all_sequences WHERE relid = ") + GetOidStr());
134
statistics->InsertItem(0, _("Blocks Read"), PGICON_STATISTICS);
135
statistics->SetItem(0l, 1, stats->GetVal(wxT("blks_read")));
136
statistics->InsertItem(1, _("Blocks Hit"), PGICON_STATISTICS);
137
statistics->SetItem(1, 1, stats->GetVal(wxT("blks_hit")));
193
wxLogInfo(wxT("Displaying statistics for sequence on ") + GetSchema()->GetIdentifier());
195
// Add the statistics view columns
196
CreateListColumns(statistics, _("Statistic"), _("Value"));
198
pgSet *stats = GetSchema()->GetDatabase()->ExecuteSet(wxT(
199
"SELECT blks_read, blks_hit FROM pg_statio_all_sequences WHERE relid = ") + GetOidStr());
203
statistics->InsertItem(0, _("Blocks Read"), PGICON_STATISTICS);
204
statistics->SetItem(0l, 1, stats->GetVal(wxT("blks_read")));
205
statistics->InsertItem(1, _("Blocks Hit"), PGICON_STATISTICS);
206
statistics->SetItem(1, 1, stats->GetVal(wxT("blks_hit")));
144
213
pgObject *pgSequence::Refresh(ctlTree *browser, const wxTreeItemId item)
146
pgObject *sequence=0;
147
pgCollection *coll=browser->GetParentCollection(item);
149
sequence = sequenceFactory.CreateObjects(coll, 0, wxT("\n AND cl.oid=") + GetOidStr());
215
pgObject *sequence = 0;
216
pgCollection *coll = browser->GetParentCollection(item);
218
sequence = sequenceFactory.CreateObjects(coll, 0, wxT("\n AND cl.oid=") + GetOidStr());
224
wxString pgSequenceCollection::GetTranslatedMessage(int kindOfMessage) const
226
wxString message = wxEmptyString;
228
switch (kindOfMessage)
230
case RETRIEVINGDETAILS:
231
message = _("Retrieving details on sequences");
233
case REFRESHINGDETAILS:
234
message = _("Refreshing sequences");
236
case GRANTWIZARDTITLE:
237
message = _("Privileges for sequences");
239
case OBJECTSLISTREPORT:
240
message = _("Sequences list report");
158
251
pgObject *pgSequenceFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
160
pgSequence *sequence=0;
163
sequences = collection->GetDatabase()->ExecuteSet(
164
wxT("SELECT cl.oid, relname, pg_get_userbyid(relowner) AS seqowner, relacl, description\n")
165
wxT(" FROM pg_class cl\n")
166
wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=cl.oid\n")
167
wxT(" WHERE relkind = 'S' AND relnamespace = ") + collection->GetSchema()->GetOidStr()
168
+ restriction + wxT("\n")
169
wxT(" ORDER BY relname"));
173
while (!sequences->Eof())
175
sequence = new pgSequence(collection->GetSchema(),
176
sequences->GetVal(wxT("relname")));
178
sequence->iSetOid(sequences->GetOid(wxT("oid")));
179
sequence->iSetComment(sequences->GetVal(wxT("description")));
180
sequence->iSetOwner(sequences->GetVal(wxT("seqowner")));
181
sequence->iSetAcl(sequences->GetVal(wxT("relacl")));
185
browser->AppendObject(collection, sequence);
186
sequences->MoveNext();
253
pgSequence *sequence = 0;
256
sequences = collection->GetDatabase()->ExecuteSet(
257
wxT("SELECT cl.oid, relname, pg_get_userbyid(relowner) AS seqowner, relacl, description\n")
258
wxT(" FROM pg_class cl\n")
259
wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=cl.oid\n")
260
wxT(" WHERE relkind = 'S' AND relnamespace = ") + collection->GetSchema()->GetOidStr()
261
+ restriction + wxT("\n")
262
wxT(" ORDER BY relname"));
266
while (!sequences->Eof())
268
sequence = new pgSequence(collection->GetSchema(),
269
sequences->GetVal(wxT("relname")));
271
sequence->iSetOid(sequences->GetOid(wxT("oid")));
272
sequence->iSetComment(sequences->GetVal(wxT("description")));
273
sequence->iSetOwner(sequences->GetVal(wxT("seqowner")));
274
sequence->iSetAcl(sequences->GetVal(wxT("relacl")));
278
browser->AppendObject(collection, sequence);
279
sequences->MoveNext();
191
284
delete sequences;
197
#include "images/sequence.xpm"
198
#include "images/sequences.xpm"
290
#include "images/sequence.pngc"
291
#include "images/sequences.pngc"
200
pgSequenceFactory::pgSequenceFactory()
201
: pgSchemaObjFactory(__("Sequence"), __("New Sequence..."), __("Create a new Sequence."), sequence_xpm)
293
pgSequenceFactory::pgSequenceFactory()
294
: pgSchemaObjFactory(__("Sequence"), __("New Sequence..."), __("Create a new Sequence."), sequence_png_img)
203
metaType = PGM_SEQUENCE;
296
metaType = PGM_SEQUENCE;
207
300
pgSequenceFactory sequenceFactory;
208
static pgaCollectionFactory cf(&sequenceFactory, __("Sequences"), sequences_xpm);
301
static pgaCollectionFactory cf(&sequenceFactory, __("Sequences"), sequences_png_img);