File: dlgPackage.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 (183 lines) | stat: -rw-r--r-- 4,439 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
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgPackage.cpp - EnterpriseDB package Property
//
//////////////////////////////////////////////////////////////////////////

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

// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"

#include "dlg/dlgPackage.h"
#include "schema/edbPackage.h"

// pointer to controls
#define txtName             CTRL_TEXT("txtName")
#define txtComment          CTRL_TEXT("txtComment")
#define txtHeader           CTRL_SQLBOX("txtHeader")
#define txtBody             CTRL_SQLBOX("txtBody")

dlgProperty *edbPackageFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
	return new dlgPackage(this, frame, (edbPackage *)node, (pgSchema *)parent);
}


BEGIN_EVENT_TABLE(dlgPackage, dlgSecurityProperty)
	EVT_STC_MODIFIED(XRCID("txtHeader"),            dlgProperty::OnChangeStc)
	EVT_STC_MODIFIED(XRCID("txtBody"),              dlgProperty::OnChangeStc)
END_EVENT_TABLE();


dlgPackage::dlgPackage(pgaFactory *f, frmMain *frame, edbPackage *node, pgSchema *sch)
	: dlgSecurityProperty(f, frame, node, wxT("dlgPackage"), wxT("EXECUTE"), "X")
{
	schema = sch;
	package = node;

	bool bVal;
	settings->Read(wxT("frmQuery/ShowLineNumber"), &bVal, false);
	if (!bVal)
	{
		txtHeader->SetMarginType(1, wxSTC_MARGIN_NUMBER);
		txtHeader->SetMarginWidth(1, ConvertDialogToPixels(wxPoint(16, 0)).x);

		txtBody->SetMarginType(1, wxSTC_MARGIN_NUMBER);
		txtBody->SetMarginWidth(1, ConvertDialogToPixels(wxPoint(16, 0)).x);
	}
}



pgObject *dlgPackage::GetObject()
{
	return package;
}


int dlgPackage::Go(bool modal)
{
	if (!connection->EdbMinimumVersion(8, 2))
		txtComment->Disable();

	cbOwner->Disable();

	if (package)
	{
		// edit mode
		txtName->Disable();

		txtHeader->SetText(package->GetHeaderInner());
		txtBody->SetText(package->GetBodyInner());
	}
	else
	{
		// create mode

	}

	return dlgSecurityProperty::Go(modal);
}


pgObject *dlgPackage::CreateObject(pgCollection *collection)
{
	pgObject *obj;

	if (collection->GetConnection()->EdbMinimumVersion(8, 2))
		obj = packageFactory.CreateObjects(collection, 0,
		                                   wxT("   AND nspname = ") + qtDbString(GetName()));
	else
		obj = packageFactory.CreateObjects(collection, 0,
		                                   wxT("   AND pkgname = ") + qtDbString(GetName()));

	return obj;
}


#ifdef __WXMAC__
void dlgPackage::OnChangeSize(wxSizeEvent &ev)
{
	SetPrivilegesLayout();
	if (GetAutoLayout())
	{
		Layout();
	}
}
#endif


void dlgPackage::CheckChange()
{
	bool enable = true;

	CheckValid(enable, !txtName->GetValue().IsEmpty(), _("Please specify name."));
	CheckValid(enable, !txtHeader->GetText().IsEmpty(), _("Please specify package header."));

	if (package)
	{
		if (!(txtBody->GetText() != package->GetBodyInner() ||
		        txtHeader->GetText() != package->GetHeaderInner()))
			enable = false;

		if (txtComment->GetValue() != package->GetComment())
			enable = true;
	}

	EnableOK(enable);
}

bool dlgPackage::IsUpToDate()
{
	if (package && !package->IsUpToDate())
		return false;
	else
		return true;
}


wxString dlgPackage::GetSql()
{
	wxString sql;
	wxString qtName = schema->GetQuotedSchemaPrefix(schema->GetName()) + qtIdent(txtName->GetValue());

	if (!package || (package && txtHeader->GetText() != package->GetHeaderInner()))
	{
		if (package)
			sql = wxT("DROP PACKAGE BODY ") + qtName + wxT(";\n\n");

		sql += wxT("CREATE OR REPLACE PACKAGE ") + qtName + wxT("\nIS\n");
		sql += txtHeader->GetText();
		sql += wxT("\nEND ") + qtIdent(txtName->GetValue()) + wxT(";\n\n");
	}

	if (!package || (package && txtBody->GetText() != package->GetBodyInner())
	        || (package && txtHeader->GetText() != package->GetHeaderInner()))
	{
		if (!txtBody->GetText().Trim().IsEmpty())
		{
			sql += wxT("CREATE OR REPLACE PACKAGE BODY ") + qtName + wxT("\nIS\n");
			sql += txtBody->GetText().Trim().Trim(false);
			sql += wxT("\nEND ") + qtIdent(txtName->GetValue()) + wxT(";\n\n");
		}
		else
		{
			if (package && !package->GetBodyInner().Trim().IsEmpty())
				sql = wxT("DROP PACKAGE BODY ") + qtName + wxT(";\n\n");
		}
	}

	sql += GetGrant(wxT("X"), wxT("PACKAGE ") + qtName);

	AppendComment(sql, wxT("PACKAGE"), schema, package);

	return sql;
}