1
//////////////////////////////////////////////////////////////////////////
3
// pgAdmin III - PostgreSQL Tools
4
// RCS-ID: $Id: dlgView.cpp 4874 2006-01-06 17:33:27Z dpage $
5
// Copyright (C) 2002 - 2006, The pgAdmin Development Team
6
// This software is released under the Artistic Licence
8
// dlgView.cpp - PostgreSQL View Property
10
//////////////////////////////////////////////////////////////////////////
20
#include "ctl/ctlSQLBox.h"
27
// pointer to controls
28
#define pnlDefinition CTRL_PANEL("pnlDefinition")
29
#define txtSqlBox CTRL_SQLBOX("txtSqlBox")
33
BEGIN_EVENT_TABLE(dlgView, dlgSecurityProperty)
34
EVT_STC_MODIFIED(XRCID("txtSqlBox"), dlgProperty::OnChangeStc)
38
dlgProperty *pgViewFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
40
return new dlgView(this, frame, (pgView*)node, (pgSchema*)parent);
43
dlgView::dlgView(pgaFactory *f, frmMain *frame, pgView *node, pgSchema *sch)
44
: dlgSecurityProperty(f, frame, node, wxT("dlgView"), wxT("INSERT,SELECT,UPDATE,DELETE,RULE,REFERENCE,TRIGGER"), "arwdRxt")
51
pgObject *dlgView::GetObject()
57
int dlgView::Go(bool modal)
66
oldDefinition=view->GetFormattedDefinition();
67
txtSqlBox->SetText(oldDefinition);
74
return dlgSecurityProperty::Go(modal);
78
pgObject *dlgView::CreateObject(pgCollection *collection)
80
pgObject *obj=viewFactory.CreateObjects(collection, 0,
81
wxT("\n AND c.relname=") + qtString(txtName->GetValue()) +
82
wxT("\n AND c.relnamespace=") + schema->GetOidStr());
87
void dlgView::CheckChange()
89
wxString name=GetName();
92
EnableOK(txtComment->GetValue() != view->GetComment()
93
|| txtSqlBox->GetText() != oldDefinition
94
|| cbOwner->GetValue() != view->GetOwner()
95
|| name != view->GetName());
101
CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
102
CheckValid(enable, txtSqlBox->GetText().Length() > 14 , _("Please enter function definition."));
109
wxString dlgView::GetSql()
111
wxString sql, name=GetName();
118
if (name != view->GetName())
120
sql += wxT("ALTER TABLE ") + view->GetQuotedFullIdentifier()
121
+ wxT(" RENAME TO ") + qtIdent(name) + wxT(";\n");
125
if (!view || txtSqlBox->GetText() != oldDefinition)
127
sql += wxT("CREATE OR REPLACE VIEW ") + schema->GetQuotedPrefix() + qtIdent(name) + wxT(" AS\n")
128
+ txtSqlBox->GetText()
133
AppendOwnerChange(sql, wxT("TABLE ") + schema->GetQuotedPrefix() + qtIdent(name));
135
AppendOwnerNew(sql, wxT("TABLE ") + schema->GetQuotedPrefix() + qtIdent(name));
138
sql += GetGrant(wxT("arwdRxt"), wxT("TABLE ") + schema->GetQuotedPrefix() + qtIdent(name));
140
AppendComment(sql, wxT("VIEW"), schema, view);