File: edbPackageVariable.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 (227 lines) | stat: -rw-r--r-- 6,584 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// edbPackageVariable.cpp - EnterpriseDB Package variable
//
//////////////////////////////////////////////////////////////////////////

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

// App headers
#include "pgAdmin3.h"
#include "schema/edbPackageVariable.h"


edbPackageVariable::edbPackageVariable(edbPackage *newPackage, const wxString &newName)
	: edbPackageObject(newPackage, packageVariableFactory, newName)
{
}

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

	switch (kindOfMessage)
	{
		case RETRIEVINGDETAILS:
			message = _("Retrieving details on package variable");
			message += wxT(" ") + GetName();
			break;
		case REFRESHINGDETAILS:
			message = _("Refreshing package variable");
			message += wxT(" ") + GetName();
			break;
		case DROPINCLUDINGDEPS:
			message = wxString::Format(_("Are you sure you wish to drop package variable \"%s\" including all objects that depend on it?"),
			                           GetFullIdentifier().c_str());
			break;
		case DROPEXCLUDINGDEPS:
			message = wxString::Format(_("Are you sure you wish to drop package variable \"%s\"?"),
			                           GetFullIdentifier().c_str());
			break;
		case DROPCASCADETITLE:
			message = _("Drop package variable cascaded?");
			break;
		case DROPTITLE:
			message = _("Drop package variable?");
			break;
		case PROPERTIESREPORT:
			message = _("Package variable properties report");
			message += wxT(" - ") + GetName();
			break;
		case PROPERTIES:
			message = _("Package variable properties");
			break;
		case DDLREPORT:
			message = _("Package variable DDL report");
			message += wxT(" - ") + GetName();
			break;
		case DDL:
			message = _("Package variable DDL");
			break;
	}

	return message;
}


wxString edbPackageVariable::GetSql(ctlTree *browser)
{
	if (sql.IsNull())
	{
		sql = wxT("-- Package Variable: ") + GetName() + wxT("\n\n");
		sql += GetName() + wxT(" ") + GetDataType() + wxT(";\n\n");
	}

	return sql;
}

void edbPackageVariable::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), GetOid());
		properties->AppendItem(_("Data type"), GetDataType());
		properties->AppendItem(_("Visibility"), GetVisibility());
	}
}



pgObject *edbPackageVariable::Refresh(ctlTree *browser, const wxTreeItemId item)
{
	pgObject *packageVariable = 0;
	pgCollection *coll = browser->GetParentCollection(item);
	if (coll)
	{
		if (coll->GetConnection()->EdbMinimumVersion(8, 2))
			packageVariable = packageVariableFactory.CreateObjects(coll, 0, wxT("\n   AND varname='") + GetName() + wxT("'"));
		else
			packageVariable = packageVariableFactory.CreateObjects(coll, 0, wxT("\n   AND eltname='") + GetName() + wxT("'"));
	}

	return packageVariable;
}


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

pgObject *edbPackageVariableFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
{

	edbPackageVariable *packageVariable = 0;

	pgSet *packageVariables;

	wxString sql;

	if (collection->GetConnection()->EdbMinimumVersion(8, 2))
	{
		sql = wxT("SELECT oid, varname AS eltname, varaccess AS visibility, format_type(vartype, NULL) as datatype FROM edb_variable\n")
		      wxT(" WHERE varpackage = ") + ((edbPackageObjCollection *)collection)->GetPackage()->GetOidStr() + wxT("\n")
		      + restriction + wxT("\n")
		      wxT(" ORDER BY varname");
	}
	else
	{
		sql = wxT("SELECT oid, eltname, visibility, format_type(eltdatatype, NULL) as datatype FROM edb_pkgelements\n")
		      wxT(" WHERE eltclass = 'V'\n")
		      wxT(" AND packageoid = ") + ((edbPackageObjCollection *)collection)->GetPackage()->GetOidStr() + wxT("\n")
		      + restriction + wxT("\n")
		      wxT(" ORDER BY eltname");
	}

	packageVariables = collection->GetDatabase()->ExecuteSet(sql);

	if (packageVariables)
	{
		edbPackage *package = ((edbPackageObjCollection *)collection)->GetPackage();

		while (!packageVariables->Eof())
		{
			// Do not create edbPackageVariable, if package is wrapped
			if (package->GetBody().Trim(false).StartsWith(wxT("$__EDBwrapped__$")))
			{
				packageVariables->MoveNext();
				continue;
			}
			packageVariable = new edbPackageVariable(package, packageVariables->GetVal(wxT("eltname")));
			packageVariable->iSetOid(packageVariables->GetOid(wxT("oid")));
			packageVariable->iSetDataType(packageVariables->GetVal(wxT("datatype")));
			if (packageVariables->GetVal(wxT("visibility")) == wxT("+"))
				packageVariable->iSetVisibility(_("Public"));
			else if (packageVariables->GetVal(wxT("visibility")) == wxT("-"))
				packageVariable->iSetVisibility(_("Private"));
			else
				packageVariable->iSetVisibility(_("Unknown"));

			if (browser)
			{
				browser->AppendObject(collection, packageVariable);
				packageVariables->MoveNext();
			}
			else
				break;
		}

		delete packageVariables;
	}
	return packageVariable;
}

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

edbPackageVariableCollection::edbPackageVariableCollection(pgaFactory *factory, edbPackage *pkg)
	: edbPackageObjCollection(factory, pkg)
{
}

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

	switch (kindOfMessage)
	{
		case RETRIEVINGDETAILS:
			message = _("Retrieving details on package variables");
			break;
		case REFRESHINGDETAILS:
			message = _("Refreshing package variables");
			break;
		case GRANTWIZARDTITLE:
			message = _("Privileges for package variables");
			break;
		case OBJECTSLISTREPORT:
			message = _("Package variables list report");
			break;
	}

	return message;
}

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

#include "images/variable.pngc"
#include "images/variables.pngc"

edbPackageVariableFactory::edbPackageVariableFactory()
	: edbPackageObjFactory(__("Variable"), __("New Variable..."), __("Create a new Variable."), variable_png_img)
{
	metaType = EDB_PACKAGEVARIABLE;
}

pgCollection *edbPackageVariableFactory::CreateCollection(pgObject *obj)
{
	return new edbPackageVariableCollection(GetCollectionFactory(), (edbPackage *)obj);
}

edbPackageVariableFactory packageVariableFactory;
static pgaCollectionFactory cf(&packageVariableFactory, __("Variables"), variables_png_img);