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
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgSchema.cpp - PostgreSQL Schema Property
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "dlg/dlgSchema.h"
#include "schema/pgSchema.h"
#include "ctl/ctlSeclabelPanel.h"
// pointer to controls
BEGIN_EVENT_TABLE(dlgSchema, dlgDefaultSecurityProperty)
END_EVENT_TABLE();
dlgProperty *pgSchemaBaseFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
return new dlgSchema(this, frame, (pgSchema *)node, parent);
}
dlgSchema::dlgSchema(pgaFactory *f, frmMain *frame, pgSchema *node, pgObject *parent)
: dlgDefaultSecurityProperty(f, frame, node, wxT("dlgSchema"), wxT("USAGE,CREATE"), "UC", node != NULL ? true : false)
{
schema = node;
seclabelPage = new ctlSeclabelPanel(nbNotebook);
}
pgObject *dlgSchema::GetObject()
{
return schema;
}
int dlgSchema::Go(bool modal)
{
wxString strDefPrivsOnTables, strDefPrivsOnSeqs, strDefPrivsOnFuncs, strDefPrivsOnTypes;
if (connection->BackendMinimumVersion(9, 1))
{
seclabelPage->SetConnection(connection);
seclabelPage->SetObject(schema);
this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgSchema::OnChange));
}
else
seclabelPage->Disable();
if (schema)
{
if (connection->BackendMinimumVersion(9, 0))
{
strDefPrivsOnTables = schema->GetDefPrivsOnTables();
strDefPrivsOnSeqs = schema->GetDefPrivsOnSequences();
strDefPrivsOnFuncs = schema->GetDefPrivsOnFunctions();
}
if (connection->BackendMinimumVersion(9, 2))
strDefPrivsOnTypes = schema->GetDefPrivsOnTypes();
// edit mode
if (!connection->BackendMinimumVersion(7, 5))
cbOwner->Disable();
if (schema->GetMetaType() == PGM_CATALOG)
{
cbOwner->Disable();
txtName->Disable();
}
}
else
{
// create mode
}
return dlgDefaultSecurityProperty::Go(modal, true, strDefPrivsOnTables, strDefPrivsOnSeqs, strDefPrivsOnFuncs, strDefPrivsOnTypes);
}
pgObject *dlgSchema::CreateObject(pgCollection *collection)
{
wxString name = GetName();
pgObject *obj = schemaFactory.CreateObjects(collection, 0, wxT(" WHERE nspname=") + qtDbString(name) + wxT("\n"));
return obj;
}
#ifdef __WXMAC__
void dlgSchema::OnChangeSize(wxSizeEvent &ev)
{
SetPrivilegesLayout();
if (GetAutoLayout())
{
Layout();
}
}
#endif
void dlgSchema::CheckChange()
{
bool enable = true;
wxString name = GetName();
if (schema)
{
enable = name != schema->GetName()
|| txtComment->GetValue() != schema->GetComment()
|| cbOwner->GetValue() != schema->GetOwner();
if (seclabelPage && connection->BackendMinimumVersion(9, 1))
enable = enable || !(seclabelPage->GetSqlForSecLabels().IsEmpty());
}
else
{
CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
}
EnableOK(enable);
}
wxString dlgSchema::GetSql()
{
wxString sql, name;
name = qtIdent(GetName());
if (schema)
{
// edit mode
AppendNameChange(sql);
AppendOwnerChange(sql, wxT("SCHEMA ") + name);
}
else
{
// create mode
sql = wxT("CREATE SCHEMA ") + name;
AppendIfFilled(sql, wxT("\n AUTHORIZATION "), qtIdent(cbOwner->GetValue()));
sql += wxT(";\n");
}
AppendComment(sql, wxT("SCHEMA"), 0, schema);
sql += GetGrant(wxT("UC"), wxT("SCHEMA ") + name);
if (connection->BackendMinimumVersion(9, 0) && defaultSecurityChanged)
sql += GetDefaultPrivileges(name);
if (seclabelPage && connection->BackendMinimumVersion(9, 1))
sql += seclabelPage->GetSqlForSecLabels(wxT("SCHEMA"), name);
return sql;
}
void dlgSchema::OnChange(wxCommandEvent &event)
{
CheckChange();
}
|