~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/schema/pgSequence.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2011-06-07 23:03:54 UTC
  • mfrom: (1.3.1 upstream) (13 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110607230354-3td4j9y71u4ahcvj
Tags: 1.14.0~beta1-1
* New upstream development release, adding Build-Depends on
  postgresql-server-dev-all >= 117~.
* Add Build-Depends on quilt, (un)patch to debian/rules and patch for fixing
  the include for kwlist.h in pgadmin/db/keywords.c.
* Add pg_config --includedir-server output to CPPFLAGS.
* Remove unrecognized configure options: --with-wx-config,
  --with-pgsql-include, --enable-gtk2, --enable-unicode.
* Clean up manually the files that are left behind after the broken
  distclean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// 
5
 
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
 
4
//
 
5
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
6
6
// This software is released under the PostgreSQL Licence
7
7
//
8
8
// pgSequence.cpp - Sequence class
18
18
#include "schema/pgSequence.h"
19
19
 
20
20
 
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)
23
23
{
24
 
    isReplicated=false;
 
24
        isReplicated = false;
25
25
}
26
26
 
27
27
pgSequence::~pgSequence()
28
28
{
29
29
}
30
30
 
 
31
wxString pgSequence::GetTranslatedMessage(int kindOfMessage) const
 
32
{
 
33
        wxString message = wxEmptyString;
 
34
 
 
35
        switch (kindOfMessage)
 
36
        {
 
37
                case RETRIEVINGDETAILS:
 
38
                        message = _("Retrieving details on sequence");
 
39
                        message += wxT(" ") + GetName();
 
40
                        break;
 
41
                case REFRESHINGDETAILS:
 
42
                        message = _("Refreshing sequence");
 
43
                        message += wxT(" ") + GetName();
 
44
                        break;
 
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());
 
48
                        break;
 
49
                case DROPEXCLUDINGDEPS:
 
50
                        message = wxString::Format(_("Are you sure you wish to drop sequence \"%s\"?"),
 
51
                                                   GetFullIdentifier().c_str());
 
52
                        break;
 
53
                case DROPCASCADETITLE:
 
54
                        message = _("Drop sequence cascaded?");
 
55
                        break;
 
56
                case DROPTITLE:
 
57
                        message = _("Drop sequence?");
 
58
                        break;
 
59
                case PROPERTIESREPORT:
 
60
                        message = _("Sequence properties report");
 
61
                        message += wxT(" - ") + GetName();
 
62
                        break;
 
63
                case PROPERTIES:
 
64
                        message = _("Sequence properties");
 
65
                        break;
 
66
                case DDLREPORT:
 
67
                        message = _("Sequence DDL report");
 
68
                        message += wxT(" - ") + GetName();
 
69
                        break;
 
70
                case DDL:
 
71
                        message = _("Sequence DDL");
 
72
                        break;
 
73
                case STATISTICSREPORT:
 
74
                        message = _("Sequence statistics report");
 
75
                        message += wxT(" - ") + GetName();
 
76
                        break;
 
77
                case OBJSTATISTICS:
 
78
                        message = _("Sequence statistics");
 
79
                        break;
 
80
                case DEPENDENCIESREPORT:
 
81
                        message = _("Sequence dependencies report");
 
82
                        message += wxT(" - ") + GetName();
 
83
                        break;
 
84
                case DEPENDENCIES:
 
85
                        message = _("Sequence dependencies");
 
86
                        break;
 
87
                case DEPENDENTSREPORT:
 
88
                        message = _("Sequence dependents report");
 
89
                        message += wxT(" - ") + GetName();
 
90
                        break;
 
91
                case DEPENDENTS:
 
92
                        message = _("Sequence dependents");
 
93
                        break;
 
94
        }
 
95
 
 
96
        return message;
 
97
}
 
98
 
 
99
 
31
100
int pgSequence::GetIconId()
32
101
{
33
 
    if (isReplicated)
34
 
        return sequenceFactory.GetReplicatedIconId();
35
 
    else
36
 
        return sequenceFactory.GetIconId();
 
102
        if (isReplicated)
 
103
                return sequenceFactory.GetReplicatedIconId();
 
104
        else
 
105
                return sequenceFactory.GetIconId();
37
106
}
38
107
 
39
108
bool pgSequence::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
40
109
{
41
 
    wxString sql = wxT("DROP SEQUENCE ") + this->GetSchema()->GetQuotedIdentifier() + wxT(".") + this->GetQuotedIdentifier();
42
 
    if (cascaded)
43
 
        sql += wxT(" CASCADE");
44
 
    return GetDatabase()->ExecuteVoid(sql);
 
110
        wxString sql = wxT("DROP SEQUENCE ") + this->GetSchema()->GetQuotedIdentifier() + wxT(".") + this->GetQuotedIdentifier();
 
111
        if (cascaded)
 
112
                sql += wxT(" CASCADE");
 
113
        return GetDatabase()->ExecuteVoid(sql);
45
114
}
46
115
 
47
116
 
48
117
void pgSequence::UpdateValues()
49
118
{
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());
53
 
    if (sequence)
54
 
    {
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());
 
122
        if (sequence)
 
123
        {
 
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"));
62
131
 
63
 
        delete sequence;
64
 
    }
 
132
                delete sequence;
 
133
        }
65
134
}
66
135
 
67
136
 
68
137
wxString pgSequence::GetSql(ctlTree *browser)
69
138
{
70
 
    if (sql.IsNull())
71
 
    {
72
 
        UpdateValues();
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();
81
 
        if (GetCycled())
82
 
            sql += wxT("\n  CYCLE");
83
 
        sql += wxT(";\n")
84
 
            + GetOwnerSql(7, 3, wxT("TABLE ") + GetQuotedFullIdentifier());
85
 
 
86
 
        if (!GetConnection()->BackendMinimumVersion(8, 2))
87
 
            sql += GetGrant(wxT("arwdRxt"), wxT("TABLE ") + GetQuotedFullIdentifier());
88
 
        else
89
 
            sql += GetGrant(wxT("rwU"), wxT("TABLE ") + GetQuotedFullIdentifier());
90
 
 
91
 
        sql += GetCommentSql();
92
 
    }
93
 
 
94
 
    return sql;
 
139
        if (sql.IsNull())
 
140
        {
 
141
                UpdateValues();
 
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();
 
150
                if (GetCycled())
 
151
                        sql += wxT("\n  CYCLE");
 
152
                sql += wxT(";\n")
 
153
                       + GetOwnerSql(7, 3, wxT("TABLE ") + GetQuotedFullIdentifier());
 
154
 
 
155
                if (!GetConnection()->BackendMinimumVersion(8, 2))
 
156
                        sql += GetGrant(wxT("arwdRxt"), wxT("TABLE ") + GetQuotedFullIdentifier());
 
157
                else
 
158
                        sql += GetGrant(wxT("rwU"), wxT("TABLE ") + GetQuotedFullIdentifier());
 
159
 
 
160
                sql += GetCommentSql();
 
161
        }
 
162
 
 
163
        return sql;
95
164
}
96
165
 
97
166
void pgSequence::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
98
167
{
99
 
    UpdateValues();
100
 
    if (properties)
101
 
    {
102
 
        CreateListColumns(properties);
 
168
        UpdateValues();
 
169
        if (properties)
 
170
        {
 
171
                CreateListColumns(properties);
103
172
 
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()));
117
 
    }
 
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()));
 
186
        }
118
187
}
119
188
 
120
189
 
121
190
 
122
191
void pgSequence::ShowStatistics(frmMain *form, ctlListView *statistics)
123
192
{
124
 
    wxLogInfo(wxT("Displaying statistics for sequence on ") +GetSchema()->GetIdentifier());
125
 
 
126
 
    // Add the statistics view columns
127
 
    CreateListColumns(statistics, _("Statistic"), _("Value"));
128
 
 
129
 
    pgSet *stats = GetSchema()->GetDatabase()->ExecuteSet(wxT(
130
 
        "SELECT blks_read, blks_hit FROM pg_statio_all_sequences WHERE relid = ") + GetOidStr());
131
 
 
132
 
    if (stats)
133
 
    {
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")));
138
 
 
139
 
        delete stats;
140
 
    }
 
193
        wxLogInfo(wxT("Displaying statistics for sequence on ") + GetSchema()->GetIdentifier());
 
194
 
 
195
        // Add the statistics view columns
 
196
        CreateListColumns(statistics, _("Statistic"), _("Value"));
 
197
 
 
198
        pgSet *stats = GetSchema()->GetDatabase()->ExecuteSet(wxT(
 
199
                           "SELECT blks_read, blks_hit FROM pg_statio_all_sequences WHERE relid = ") + GetOidStr());
 
200
 
 
201
        if (stats)
 
202
        {
 
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")));
 
207
 
 
208
                delete stats;
 
209
        }
141
210
}
142
211
 
143
212
 
144
213
pgObject *pgSequence::Refresh(ctlTree *browser, const wxTreeItemId item)
145
214
{
146
 
    pgObject *sequence=0;
147
 
    pgCollection *coll=browser->GetParentCollection(item);
148
 
    if (coll)
149
 
        sequence = sequenceFactory.CreateObjects(coll, 0, wxT("\n   AND cl.oid=") + GetOidStr());
150
 
 
151
 
    return sequence;
 
215
        pgObject *sequence = 0;
 
216
        pgCollection *coll = browser->GetParentCollection(item);
 
217
        if (coll)
 
218
                sequence = sequenceFactory.CreateObjects(coll, 0, wxT("\n   AND cl.oid=") + GetOidStr());
 
219
 
 
220
        return sequence;
 
221
}
 
222
 
 
223
 
 
224
wxString pgSequenceCollection::GetTranslatedMessage(int kindOfMessage) const
 
225
{
 
226
        wxString message = wxEmptyString;
 
227
 
 
228
        switch (kindOfMessage)
 
229
        {
 
230
                case RETRIEVINGDETAILS:
 
231
                        message = _("Retrieving details on sequences");
 
232
                        break;
 
233
                case REFRESHINGDETAILS:
 
234
                        message = _("Refreshing sequences");
 
235
                        break;
 
236
                case GRANTWIZARDTITLE:
 
237
                        message = _("Privileges for sequences");
 
238
                        break;
 
239
                case OBJECTSLISTREPORT:
 
240
                        message = _("Sequences list report");
 
241
                        break;
 
242
        }
 
243
 
 
244
        return message;
152
245
}
153
246
 
154
247
 
157
250
 
158
251
pgObject *pgSequenceFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
159
252
{
160
 
    pgSequence *sequence=0;
161
 
 
162
 
    pgSet *sequences;
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"));
170
 
 
171
 
    if (sequences)
172
 
    {
173
 
        while (!sequences->Eof())
174
 
        {
175
 
            sequence = new pgSequence(collection->GetSchema(), 
176
 
                                            sequences->GetVal(wxT("relname")));
177
 
 
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")));
182
 
 
183
 
            if (browser)
184
 
            {
185
 
                browser->AppendObject(collection, sequence);
186
 
                                sequences->MoveNext();
187
 
            }
188
 
            else
189
 
                break;
190
 
        }
 
253
        pgSequence *sequence = 0;
 
254
 
 
255
        pgSet *sequences;
 
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"));
 
263
 
 
264
        if (sequences)
 
265
        {
 
266
                while (!sequences->Eof())
 
267
                {
 
268
                        sequence = new pgSequence(collection->GetSchema(),
 
269
                                                  sequences->GetVal(wxT("relname")));
 
270
 
 
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")));
 
275
 
 
276
                        if (browser)
 
277
                        {
 
278
                                browser->AppendObject(collection, sequence);
 
279
                                sequences->MoveNext();
 
280
                        }
 
281
                        else
 
282
                                break;
 
283
                }
191
284
                delete sequences;
192
 
    }
193
 
    return sequence;
 
285
        }
 
286
        return sequence;
194
287
}
195
288
 
196
289
 
197
 
#include "images/sequence.xpm"
198
 
#include "images/sequences.xpm"
 
290
#include "images/sequence.pngc"
 
291
#include "images/sequences.pngc"
199
292
 
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)
202
295
{
203
 
    metaType = PGM_SEQUENCE;
 
296
        metaType = PGM_SEQUENCE;
204
297
}
205
298
 
206
299
 
207
300
pgSequenceFactory sequenceFactory;
208
 
static pgaCollectionFactory cf(&sequenceFactory, __("Sequences"), sequences_xpm);
 
301
static pgaCollectionFactory cf(&sequenceFactory, __("Sequences"), sequences_png_img);