This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
dlgExtTable.cpp
169 lines (128 loc) · 4.24 KB
/
dlgExtTable.cpp
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
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
// RCS-ID: $Id: $
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgExtTable.cpp - Greenplum Externtal Table Property
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "utils/pgDefs.h"
#include "ctl/ctlSQLBox.h"
#include "dlg/dlgExtTable.h"
#include "schema/gpExtTable.h"
#include "schema/pgSchema.h"
// pointer to controls
#define pnlDefinition CTRL_PANEL("pnlDefinition")
#define txtSqlBox CTRL_SQLBOX("txtSqlBox")
BEGIN_EVENT_TABLE(dlgExtTable, dlgSecurityProperty)
EVT_STC_MODIFIED(XRCID("txtSqlBox"), dlgProperty::OnChangeStc)
END_EVENT_TABLE();
dlgProperty *gpExtTableFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
return new dlgExtTable(this, frame, (gpExtTable*)node, (pgSchema*)parent);
}
dlgExtTable::dlgExtTable(pgaFactory *f, frmMain *frame, gpExtTable *node, pgSchema *sch)
: dlgSecurityProperty(f, frame, node, wxT("dlgExtTable"), wxT("SELECT"), "r")
{
schema=sch;
extTable=node;
}
pgObject *dlgExtTable::GetObject()
{
return extTable;
}
int dlgExtTable::Go(bool modal)
{
int returncode;
AddGroups();
AddUsers(cbOwner);
if (extTable)
{
// edit mode
// TODO: Make this more like dlgTable, so that it is easier to use.
// Right now, this is just dummy code until that code is written.
txtSqlBox->SetText(wxT("(") + extTable->GetSql(NULL).AfterFirst('('));
oldDefinition = txtSqlBox->GetText();
txtSqlBox->Enable(false);
}
else
{
// create mode
}
returncode = dlgSecurityProperty::Go(modal);
// This fixes a UI glitch on MacOS X and Windows
// Because of the new layout code, the Privileges pane don't size itself properly
SetSize(GetSize().GetWidth()+1, GetSize().GetHeight());
SetSize(GetSize().GetWidth()-1, GetSize().GetHeight());
return returncode;
}
pgObject *dlgExtTable::CreateObject(pgCollection *collection)
{
pgObject *obj=extTableFactory.CreateObjects(collection, 0,
wxT("\n AND c.relname=") + qtDbString(txtName->GetValue()) +
wxT("\n AND c.relnamespace=") + schema->GetOidStr());
return obj;
}
void dlgExtTable::CheckChange()
{
wxString name=GetName();
if (name)
{
if (extTable)
EnableOK(txtComment->GetValue() != extTable->GetComment()
|| txtSqlBox->GetText() != oldDefinition
|| cbOwner->GetValue() != extTable->GetOwner()
|| name != extTable->GetName());
else
EnableOK(!txtComment->GetValue().IsEmpty()
|| !txtSqlBox->GetText().IsEmpty()
|| !cbOwner->GetValue().IsEmpty());
}
else
{
bool enable=true;
CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
CheckValid(enable, txtSqlBox->GetText().Length() > 0 , _("Please enter external table definition."));
EnableOK(enable);
}
}
wxString dlgExtTable::GetSql()
{
wxString sql, name=GetName();
if (extTable)
{
// edit mode
if (name != extTable->GetName())
{
sql += wxT("ALTER TABLE ") + extTable->GetQuotedFullIdentifier()
+ wxT(" RENAME TO ") + qtIdent(name) + wxT(";\n");
}
}
if (!extTable || txtSqlBox->GetText() != oldDefinition)
{
sql += wxT("CREATE EXTERNAL TABLE ") + schema->GetQuotedPrefix() + qtIdent(name) + wxT("\n")
+ txtSqlBox->GetText()
+ wxT(";\n");
}
if (extTable)
AppendOwnerChange(sql, wxT("TABLE ") + schema->GetQuotedPrefix() + qtIdent(name));
else
AppendOwnerNew(sql, wxT("TABLE ") + schema->GetQuotedPrefix() + qtIdent(name));
sql += GetGrant(wxT("r"), wxT("TABLE ") + schema->GetQuotedPrefix() + qtIdent(name));
AppendComment(sql, wxT("TABLE"), schema, extTable);
return sql;
}
bool dlgExtTable::IsUpToDate()
{
if (extTable && !extTable->IsUpToDate())
return false;
else
return true;
}