File: pgCatalogObject.cpp

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (208 lines) | stat: -rw-r--r-- 5,557 bytes parent folder | download
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
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// pgCatalogObject.cpp - EnterpriseDB catalog class
//
//////////////////////////////////////////////////////////////////////////

// wxWindows headers
#include <wx/wx.h>

// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "schema/pgCatalogObject.h"
#include "schema/pgColumn.h"


pgCatalogObject::pgCatalogObject(pgSchema *newSchema, const wxString &newName)
	: pgSchemaObject(newSchema, catalogObjectFactory, newName)
{
}

wxString pgCatalogObject::GetTranslatedMessage(int kindOfMessage) const
{
	wxString message = wxEmptyString;

	switch (kindOfMessage)
	{
		case RETRIEVINGDETAILS:
			message = _("Retrieving details on catalog object");
			message += wxT(" ") + GetName();
			break;
		case REFRESHINGDETAILS:
			message = _("Refreshing catalog object");
			message += wxT(" ") + GetName();
			break;
		case PROPERTIESREPORT:
			message = _("Catalog object properties report");
			message += wxT(" - ") + GetName();
			break;
		case PROPERTIES:
			message = _("Catalog object properties");
			break;
		case DEPENDENCIESREPORT:
			message = _("Catalog object dependencies report");
			message += wxT(" - ") + GetName();
			break;
		case DEPENDENCIES:
			message = _("Catalog object dependencies");
			break;
		case DEPENDENTSREPORT:
			message = _("Catalog object dependents report");
			message += wxT(" - ") + GetName();
			break;
		case DEPENDENTS:
			message = _("Catalog object dependents");
			break;
	}

	return message;
}


wxString pgCatalogObject::GetSql(ctlTree *browser)
{
	if (sql.IsNull())
	{
		sql = wxT("-- Catalog Object: ") + GetQuotedIdentifier() + wxT("\n");
	}
	return sql;
}


void pgCatalogObject::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (!expandedKids)
	{
		expandedKids = true;

		browser->AppendCollection(this, columnFactory);
	}

	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), GetOid());
		properties->AppendItem(_("Owner"), GetOwner());
		properties->AppendItem(_("Comment"), GetComment());
	}
}



pgObject *pgCatalogObject::Refresh(ctlTree *browser, const wxTreeItemId item)
{
	pgObject *catalog = 0;
	pgCollection *parent = (pgCollection *)browser->GetItemData(browser->GetItemParent(item));
	if (parent)
		catalog = catalogObjectFactory.CreateObjects(parent, 0, wxT("\n AND c.oid=") + GetOidStr());

	return catalog;
}



pgObject *pgCatalogObjectFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
{
	pgCatalogObject *catalog = 0;

	wxString qry = wxT("SELECT c.oid, c.relname, pg_get_userbyid(relowner) AS owner, description\n")
	               wxT("  FROM pg_class c\n")
	               wxT("  LEFT OUTER JOIN pg_description d ON (d.objoid=c.oid AND d.classoid='pg_class'::regclass)\n")
	               wxT("  WHERE relnamespace = ") + NumToStr(collection->GetSchema()->GetOid()) + wxT("::oid\n");

	qry += restriction +
	       wxT(" ORDER BY relname");

	pgSet *catalogs = collection->GetServer()->ExecuteSet(qry);

	if (catalogs)
	{
		while (!catalogs->Eof())
		{
			// On EnterpriseDB we need to ignore some objects in the sys
			// catalog, namely, _*, dual and type_object_source.
			if (!settings->GetShowSystemObjects() &&
			        collection->GetSchema()->GetName() == wxT("sys") &&
			        (catalogs->GetVal(wxT("relname")).StartsWith(wxT("_")) ||
			         catalogs->GetVal(wxT("relname")) == wxT("dual") ||
			         catalogs->GetVal(wxT("relname")) == wxT("type_object_source")))
			{
				catalogs->MoveNext();
				continue;
			}

			catalog = new pgCatalogObject(collection->GetSchema(), catalogs->GetVal(wxT("relname")));
			catalog->iSetOid(catalogs->GetOid(wxT("oid")));
			catalog->iSetOwner(catalogs->GetVal(wxT("owner")));
			catalog->iSetComment(catalogs->GetVal(wxT("description")));

			if (browser)
			{
				browser->AppendObject(collection, catalog);
				catalogs->MoveNext();
			}
			else
				break;
		}

		delete catalogs;
	}
	return catalog;
}

/////////////////////////////

pgCatalogObjectCollection::pgCatalogObjectCollection(pgaFactory *factory, pgSchema *sch)
	: pgSchemaObjCollection(factory, sch)
{
}


wxString pgCatalogObjectCollection::GetTranslatedMessage(int kindOfMessage) const
{
	wxString message = wxEmptyString;

	switch (kindOfMessage)
	{
		case RETRIEVINGDETAILS:
			message = _("Retrieving details on catalog objects");
			break;
		case REFRESHINGDETAILS:
			message = _("Refreshing catalog objects");
			break;
		case OBJECTSLISTREPORT:
			message = _("Catalog objects list report");
			break;
	}

	return message;
}

/////////////////////////////

#include "images/catalogobject.pngc"
#include "images/catalogobject-sm.pngc"
#include "images/catalogobjects.pngc"

pgCatalogObjectFactory::pgCatalogObjectFactory()
	: pgSchemaObjFactory(__("Catalog Object"), __("New Catalog Object..."), __("Create a new Catalog Object."), catalogobject_png_img, catalogobject_sm_png_img)
{
	metaType = PGM_CATALOGOBJECT;
}


pgCollection *pgCatalogObjectFactory::CreateCollection(pgObject *obj)
{
	return new pgCatalogObjectCollection(GetCollectionFactory(), (pgSchema *)obj);
}

pgCatalogObjectFactory catalogObjectFactory;
static pgaCollectionFactory cf(&catalogObjectFactory, __("Catalog Objects"), catalogobjects_png_img);