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
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgCollation.cpp - PostgreSQL Collation Property
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "utils/pgDefs.h"
#include "dlg/dlgCollation.h"
#include "schema/pgSchema.h"
#include "schema/pgCollation.h"
#include "schema/pgDatatype.h"
// pointer to controls
#define txtLocale CTRL_TEXT("txtLocale")
#define txtLcCollate CTRL_TEXT("txtLcCollate")
#define txtLcCtype CTRL_TEXT("txtLcCtype")
#define cbCollation CTRL_COMBOBOX2("cbCollation")
BEGIN_EVENT_TABLE(dlgCollation, dlgTypeProperty)
EVT_TEXT(XRCID("txtLocale"), dlgProperty::OnChange)
EVT_TEXT(XRCID("txtLcCollate"), dlgProperty::OnChange)
EVT_TEXT(XRCID("txtLcCtype"), dlgProperty::OnChange)
EVT_TEXT(XRCID("cbCollation"), dlgProperty::OnChange)
EVT_COMBOBOX(XRCID("cbCollation"), dlgProperty::OnChange)
END_EVENT_TABLE();
dlgProperty *pgCollationFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
return new dlgCollation(this, frame, (pgCollation *)node, (pgSchema *)parent);
}
dlgCollation::dlgCollation(pgaFactory *f, frmMain *frame, pgCollation *node, pgSchema *sch)
: dlgTypeProperty(f, frame, wxT("dlgCollation"))
{
schema = sch;
collation = node;
}
pgObject *dlgCollation::GetObject()
{
return collation;
}
int dlgCollation::Go(bool modal)
{
if (collation)
{
// edit mode
txtLcCollate->SetValue(collation->GetLcCollate());
txtLcCtype->SetValue(collation->GetLcCtype());
txtLocale->Disable();
txtLcCollate->Disable();
txtLcCtype->Disable();
cbCollation->Disable();
}
else
{
// create mode
// fill collation combobox
cbCollation->Append(wxEmptyString);
pgSet *set = connection->ExecuteSet(
wxT("SELECT nspname, collname\n")
wxT(" FROM pg_collation c, pg_namespace n\n")
wxT(" WHERE c.collnamespace=n.oid\n")
wxT(" ORDER BY nspname, collname"));
if (set)
{
while (!set->Eof())
{
wxString name = qtIdent(set->GetVal(wxT("nspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname")));
cbCollation->Append(name);
set->MoveNext();
}
delete set;
}
cbCollation->SetSelection(0);
}
return dlgProperty::Go(modal);
}
pgObject *dlgCollation::CreateObject(pgCollection *collection)
{
wxString name = GetName();
pgObject *obj = collationFactory.CreateObjects(collection, 0,
wxT(" AND c.collname=") + qtDbString(name) +
wxT("\n AND c.collnamespace=") + schema->GetOidStr() +
wxT("\n"));
return obj;
}
void dlgCollation::CheckChange()
{
if (collation)
{
EnableOK(txtName->GetValue() != collation->GetName()
|| cbSchema->GetValue() != collation->GetSchema()->GetName()
|| cbOwner->GetValue() != collation->GetOwner()
|| txtComment->GetValue() != collation->GetComment());
}
else
{
bool enable = true;
CheckValid(enable, !GetName().IsEmpty(), _("Please specify name."));
CheckValid(enable,
!txtLocale->GetValue().IsEmpty() ||
!(txtLcCollate->GetValue().IsEmpty() && txtLcCtype->GetValue().IsEmpty()) ||
!cbCollation->GetValue().IsEmpty(),
_("Please specify a locale, or LC_COLLATE and LC_CTYPE, or a collation"));
txtLocale->Enable(cbCollation->GetValue().IsEmpty() && txtLcCollate->GetValue().IsEmpty() && txtLcCtype->GetValue().IsEmpty());
txtLcCollate->Enable(cbCollation->GetValue().IsEmpty() && txtLocale->GetValue().IsEmpty());
txtLcCtype->Enable(cbCollation->GetValue().IsEmpty() && txtLocale->GetValue().IsEmpty());
cbCollation->Enable(txtLocale->GetValue().IsEmpty() && txtLcCollate->GetValue().IsEmpty() && txtLcCtype->GetValue().IsEmpty());
EnableOK(enable);
}
}
wxString dlgCollation::GetSql()
{
wxString sql;
wxString name;
if (collation)
{
// edit mode
name = schema->GetQuotedPrefix() + qtIdent(GetName());;
AppendNameChange(sql, wxT("COLLATION ") + collation->GetQuotedFullIdentifier());
AppendOwnerChange(sql, wxT("COLLATION ") + name);
AppendSchemaChange(sql, wxT("COLLATION ") + name);
}
else
{
// create mode
name = qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName());
sql = wxT("CREATE COLLATION ") + name;
if (cbCollation->GetValue().IsEmpty())
{
if (txtLocale->GetValue().IsEmpty())
{
sql += wxT("(LC_COLLATE=") + qtDbString(txtLcCollate->GetValue())
+ wxT(", LC_CTYPE=") + qtDbString(txtLcCtype->GetValue())
+ wxT(")");
}
else
{
sql += wxT("(LOCALE=") + qtDbString(txtLocale->GetValue()) + wxT(")");
}
}
else
{
sql += wxT(" FROM ") + cbCollation->GetValue();
}
sql += wxT(";\n");
AppendOwnerNew(sql, wxT("COLLATION ") + schema->GetQuotedPrefix() + qtIdent(name));
}
AppendComment(sql, wxT("COLLATION ") + qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName()), collation);
return sql;
}
|