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
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgExtension.cpp - PostgreSQL Extension Property
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "utils/pgDefs.h"
#include "dlg/dlgExtension.h"
#include "schema/pgExtension.h"
// pointer to controls
#define cbName CTRL_COMBOBOX("cbName")
#define cbObjectsSchema CTRL_COMBOBOX("cbObjectsSchema")
#define cbVersion CTRL_COMBOBOX("cbVersion")
dlgProperty *pgExtensionFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
return new dlgExtension(this, frame, (pgExtension *)node);
}
BEGIN_EVENT_TABLE(dlgExtension, dlgProperty)
EVT_TEXT(XRCID("cbName"), dlgExtension::OnChangeName)
EVT_COMBOBOX(XRCID("cbName"), dlgExtension::OnChangeName)
EVT_TEXT(XRCID("cbObjectsSchema"), dlgProperty::OnChange)
EVT_COMBOBOX(XRCID("cbObjectsSchema"), dlgProperty::OnChange)
EVT_TEXT(XRCID("cbVersion"), dlgProperty::OnChange)
EVT_COMBOBOX(XRCID("cbVersion"), dlgProperty::OnChange)
END_EVENT_TABLE();
dlgExtension::dlgExtension(pgaFactory *f, frmMain *frame, pgExtension *node)
: dlgProperty(f, frame, wxT("dlgExtension"))
{
extension = node;
}
pgObject *dlgExtension::GetObject()
{
return extension;
}
int dlgExtension::Go(bool modal)
{
txtComment->Disable();
// add all schemas
cbObjectsSchema->Append(wxEmptyString);
pgSetIterator schemas(connection,
wxT("SELECT nspname FROM pg_namespace\n")
wxT(" ORDER BY nspname"));
while (schemas.RowsLeft())
cbObjectsSchema->Append(schemas.GetVal(wxT("nspname")));
cbObjectsSchema->SetSelection(0);
if (extension)
{
// edit mode
cbName->Append(extension->GetName());
cbName->SetSelection(0);
cbName->Disable();
cbObjectsSchema->SetValue(extension->GetSchemaStr());
cbObjectsSchema->Enable(extension->GetIsRelocatable());
// add all versions
cbVersion->Clear();
cbVersion->Append(wxEmptyString);
pgSetIterator versions(connection,
wxT("SELECT version, relocatable FROM pg_available_extension_versions\n")
wxT(" WHERE name=") + qtDbString(cbName->GetValue()) + wxT(" ")
wxT(" ORDER BY version"));
while (versions.RowsLeft())
cbVersion->Append(versions.GetVal(wxT("version")));
cbVersion->SetValue(extension->GetVersion());
}
else
{
// create mode
// add available extensions (but not the installed ones)
cbName->Append(wxEmptyString);
pgSetIterator extensions(connection,
wxT("SELECT name FROM pg_available_extensions\n")
wxT(" WHERE installed_version IS NULL\n")
wxT(" ORDER BY name"));
while (extensions.RowsLeft())
cbName->Append(extensions.GetVal(wxT("name")));
cbName->SetSelection(0);
}
return dlgProperty::Go(modal);
}
pgObject *dlgExtension::CreateObject(pgCollection *collection)
{
wxString name = cbName->wxComboBox::GetValue();
pgObject *obj = extensionFactory.CreateObjects(collection, 0, wxT("\n AND extname ILIKE ") + qtDbString(name));
return obj;
}
void dlgExtension::OnChangeName(wxCommandEvent &ev)
{
bool relocatable;
// add all versions
cbVersion->Clear();
cbVersion->Append(wxEmptyString);
pgSetIterator versions(connection,
wxT("SELECT version, relocatable FROM pg_available_extension_versions\n")
wxT(" WHERE name=") + qtDbString(cbName->GetValue()) + wxT(" ")
wxT(" ORDER BY version"));
while (versions.RowsLeft())
{
relocatable = versions.GetBool(wxT("relocatable"));
cbVersion->Append(versions.GetVal(wxT("version")));
}
cbVersion->SetSelection(0);
if (relocatable)
{
cbObjectsSchema->Enable();
}
else
{
cbObjectsSchema->SetSelection(0);
cbObjectsSchema->Disable();
}
OnChange(ev);
}
void dlgExtension::CheckChange()
{
bool didChange = true;
if (extension)
{
didChange = cbObjectsSchema->GetValue() != extension->GetSchemaStr()
|| cbVersion->GetValue() != extension->GetVersion();
EnableOK(didChange);
}
else
{
bool enable = true;
CheckValid(enable, !cbName->GetValue().IsEmpty(), _("Please specify name."));
EnableOK(enable);
}
}
wxString dlgExtension::GetSql()
{
wxString sql;
if (extension)
{
// edit mode
if (cbObjectsSchema->GetValue() != extension->GetSchemaStr())
sql += wxT("ALTER EXTENSION ") + qtIdent(extension->GetName())
+ wxT("\n SET SCHEMA ") + qtIdent(cbObjectsSchema->GetValue()) + wxT(";\n");
if (cbVersion->GetValue() != extension->GetVersion())
sql += wxT("ALTER EXTENSION ") + qtIdent(extension->GetName())
+ wxT("\n UPDATE TO ") + qtIdent(cbVersion->GetValue()) + wxT(";\n");
}
else
{
sql = wxT("CREATE EXTENSION ") + qtIdent(cbName->GetValue());
AppendIfFilled(sql, wxT("\n SCHEMA "), qtIdent(cbObjectsSchema->GetValue()));
AppendIfFilled(sql, wxT("\n VERSION "), qtIdent(cbVersion->GetValue()));
}
return sql;
}
|