Hi All,
Please find the attached updated patch.
Patch contains following changes:
* Added "ctype" in keyword list as RESERVED
* Added support for COLLATE, CTYPE & CONNECTION LIMIT in pgDatabase
* Added reverse engineering support for SQL generation from existing schema
* Added these variable in properties list.
(Made them disabled for the not-supported versions of PostgreSQL)
* Added them in property list (forgot to add it in the previous patch)
* Used wxTextCtrl instead of wxSpinCtrl for connection limit control in
properties dialog, as we don't want to put any restriction on the maximum
limit for it.
Regards,
Ashesh
Index: include/parser/keywords.h
===================================================================
--- include/parser/keywords.h (revision 7499)
+++ include/parser/keywords.h (working copy)
@@ -437,6 +437,7 @@
POSTFIXOP = 643,
UMINUS = 644,
TYPECAST = 645,
+ CTYPE=646,
/* The following additions are keywords in EnterpriseDB */
CONNECT_EDB = 800,
Index: include/schema/pgDatabase.h
===================================================================
--- include/schema/pgDatabase.h (revision 7499)
+++ include/schema/pgDatabase.h (working copy)
@@ -67,6 +67,12 @@
void iSetEncoding(const wxString& newVal) { encoding = newVal; }
wxString GetSchemaRestriction() { return schemaRestriction; }
void iSetSchemaRestriction(const wxString &s) { schemaRestriction = s; }
+ wxString GetCollate() const { return collate; }
+ void iSetCollate( const wxString& newVal) { collate = newVal; }
+ wxString GetCType() const { return ctype; }
+ void iSetCType( const wxString& newVal) { ctype = newVal; }
+ long GetConnectionLimit() { return connectionLimit; }
+ void iSetConnectionLimit(long newVal) { connectionLimit = newVal; }
wxArrayString& GetVariables() { return variables; }
bool GetAllowConnections() const { return allowConnections; }
@@ -111,10 +117,11 @@
pgConn *conn;
bool connected;
bool useServerConnection;
- wxString searchPath, path, tablespace, defaultTablespace, encoding;
+ wxString searchPath, path, tablespace, defaultTablespace, encoding, collate, ctype;
wxString prettyOption, defaultSchema;
bool allowConnections, createPrivilege;
long missingFKs;
+ long connectionLimit;
wxArrayString variables;
wxString schemaChanges;
Index: include/dlg/dlgDatabase.h
===================================================================
--- include/dlg/dlgDatabase.h (revision 7499)
+++ include/dlg/dlgDatabase.h (working copy)
@@ -46,6 +46,9 @@
void OnVarAdd(wxCommandEvent &ev);
void OnVarRemove(wxCommandEvent &ev);
void OnVarSelChange(wxListEvent &ev);
+ void OnCollateSelChange(wxCommandEvent &ev);
+ void OnCTypeSelChange(wxCommandEvent &ev);
+ void OnConnLimitChange(wxCommandEvent &ev);
void OnVarnameSelChange(wxCommandEvent &ev);
void OnOK(wxCommandEvent &ev);
Index: db/keywords.c
===================================================================
--- db/keywords.c (revision 7499)
+++ db/keywords.c (working copy)
@@ -107,6 +107,7 @@
{"createuser", CREATEUSER, UNRESERVED_KEYWORD},
{"cross", CROSS, TYPE_FUNC_NAME_KEYWORD},
{"csv", CSV, UNRESERVED_KEYWORD},
+ {"ctype", CTYPE, RESERVED_KEYWORD},
{"current", CURRENT_P, UNRESERVED_KEYWORD},
{"current_date", CURRENT_DATE, RESERVED_KEYWORD},
{"current_role", CURRENT_ROLE, RESERVED_KEYWORD},
Index: schema/pgDatabase.cpp
===================================================================
--- schema/pgDatabase.cpp (revision 7499)
+++ schema/pgDatabase.cpp (working copy)
@@ -338,6 +338,11 @@
{
if (sql.IsEmpty())
{
+ // If we can't connect to this database, use the maintenance DB
+ pgConn *myConn = GetConnection();
+ if (!myConn)
+ myConn = GetServer()->GetConnection();
+
sql = wxT("-- Database: ") + GetQuotedFullIdentifier() + wxT("\n\n")
+ wxT("-- DROP DATABASE ") + GetQuotedIdentifier() + wxT(";")
+ wxT("\n\nCREATE DATABASE ") + GetQuotedIdentifier()
@@ -345,7 +350,16 @@
+ wxT("\n ENCODING = ") + qtDbString(GetEncoding());
if (tablespace != defaultTablespace)
sql += wxT("\n TABLESPACE = ") + qtIdent(GetTablespace());
-
+ if (myConn && myConn->BackendMinimumVersion(8, 4))
+ {
+ sql += wxT("\n COLLATE = ") + qtDbString(GetCollate());
+ sql += wxT("\n CTYPE = ") + qtDbString(GetCType());
+ }
+ if (myConn && myConn->BackendMinimumVersion(8, 1))
+ {
+ sql += wxT("\n CONNECTION LIMIT = ");
+ sql << GetConnectionLimit();
+ }
sql += wxT(";\n");
size_t i;
@@ -353,11 +367,6 @@
sql += wxT("ALTER DATABASE ") + GetQuotedFullIdentifier()
+ wxT(" SET ") + variables.Item(i) + wxT(";\n");
- // If we can't connect to this database, use the maintenance DB
- pgConn *myConn = GetConnection();
- if (!myConn)
- myConn = GetServer()->GetConnection();
-
if (myConn)
{
if (!myConn->BackendMinimumVersion(8, 2))
@@ -431,6 +440,12 @@
}
properties->AppendItem(_("Encoding"), GetEncoding());
+ if (GetConnection() && GetConnection()->BackendMinimumVersion(8, 4))
+ {
+ properties->AppendItem(_("COLLATE"), GetCollate());
+ properties->AppendItem(_("CTYPE"), GetCType());
+ }
+
if (!defaultSchema.IsEmpty())
properties->AppendItem(_("Default schema"), defaultSchema);
@@ -442,6 +457,12 @@
}
properties->AppendItem(_("Allow connections?"), GetAllowConnections());
properties->AppendItem(_("Connected?"), GetConnected());
+ if (GetConnection() && GetConnection()->BackendMinimumVersion(8, 1))
+ {
+ wxString strConnLimit;
+ strConnLimit.Printf(wxT("%ld"), GetConnectionLimit());
+ properties->AppendItem(_("Connection Limit"), strConnLimit);
+ }
properties->AppendItem(_("System database?"), GetSystemObject());
if (GetMissingFKs())
properties->AppendItem(_("Old style FKs"), GetMissingFKs());
@@ -474,6 +495,18 @@
pgSet *databases;
+ wxString datcollate, datctype, datconnlimit;
+
+ if (collection->GetConnection()->BackendMinimumVersion(8, 1))
+ {
+ datconnlimit = wxT(", db.datconnlimit as connectionlimit");
+ }
+ if (collection->GetConnection()->BackendMinimumVersion(8, 4))
+ {
+ datctype = wxT(", db.datctype as ctype");
+ datcollate = wxT(", db.datcollate as collate");
+ }
+
wxString restr=restriction;
if (!collection->GetServer()->GetDbRestriction().IsEmpty())
{
@@ -491,7 +524,8 @@
wxT("pg_encoding_to_char(encoding) AS serverencoding, pg_get_userbyid(datdba) AS datowner,")
wxT("has_database_privilege(db.oid, 'CREATE') as cancreate, \n")
wxT("current_setting('default_tablespace') AS default_tablespace, \n")
- wxT("descr.description\n")
+ wxT("descr.description\n") +
+ datconnlimit + datcollate + datctype +
wxT(" FROM pg_database db\n")
wxT(" LEFT OUTER JOIN pg_tablespace ta ON db.dattablespace=ta.OID\n")
wxT(" LEFT OUTER JOIN ")
@@ -540,6 +574,16 @@
else
database->iSetPath(databases->GetVal(wxT("datpath")));
+ if (collection->GetConnection()->BackendMinimumVersion(8, 1))
+ {
+ database->iSetConnectionLimit(databases->GetLong(wxT("connectionlimit")));
+ }
+ if (collection->GetConnection()->BackendMinimumVersion(8, 4))
+ {
+ database->iSetCollate(databases->GetVal(wxT("collate")));
+ database->iSetCType(databases->GetVal(wxT("ctype")));
+ }
+
if (collection->GetServer()->GetServerIndex())
{
wxString value;
Index: dlg/dlgDatabase.cpp
===================================================================
--- dlg/dlgDatabase.cpp (revision 7499)
+++ dlg/dlgDatabase.cpp (working copy)
@@ -11,6 +11,8 @@
// wxWindows headers
#include <wx/wx.h>
+#include <wx/generic/spinctlg.h>
+#include <wx/spinbutt.h>
// App headers
#include "pgAdmin3.h"
@@ -34,8 +36,10 @@
#define chkValue CTRL_CHECKBOX("chkValue")
#define btnAdd CTRL_BUTTON("wxID_ADD")
#define btnRemove CTRL_BUTTON("wxID_REMOVE")
+#define cbCollate CTRL_COMBOBOX2("cbCollate")
+#define cbCType CTRL_COMBOBOX2("cbCType")
+#define txtConnLimit CTRL_TEXT("txtConnLimit")
-
dlgProperty *pgDatabaseFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
dlgDatabase *dlg=new dlgDatabase(this, frame, (pgDatabase*)node);
@@ -61,6 +65,9 @@
EVT_TEXT(XRCID("cbVarname"), dlgDatabase::OnVarnameSelChange)
EVT_COMBOBOX(XRCID("cbVarname"), dlgDatabase::OnVarnameSelChange)
EVT_BUTTON(wxID_OK, dlgDatabase::OnOK)
+ EVT_TEXT(XRCID("cbCollate"), dlgDatabase::OnCollateSelChange)
+ EVT_TEXT(XRCID("cbCType"), dlgDatabase::OnCTypeSelChange)
+ EVT_TEXT(XRCID("txtConnLimit"), dlgDatabase::OnConnLimitChange)
#ifdef __WXMAC__
EVT_SIZE( dlgDatabase::OnChangeSize)
#endif
@@ -114,6 +121,19 @@
cbTablespace->Hide();
}
+ if (!connection->BackendMinimumVersion(8,1))
+ {
+ txtConnLimit->Disable();
+ }
+ else
+ txtConnLimit->SetValidator(numericValidator);
+
+ if (!connection->BackendMinimumVersion(8,4))
+ {
+ cbCollate->Disable();
+ cbCType->Disable();
+ }
+
pgSet *set;
if (connection->BackendMinimumVersion(7, 4))
set=connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
@@ -173,8 +193,25 @@
cbEncoding->Append(database->GetEncoding());
cbEncoding->SetSelection(0);
+ if (connection->BackendMinimumVersion(8,1))
+ {
+ wxString strConnLimit;
+ strConnLimit.Printf(wxT("%ld"), database->GetConnectionLimit());
+ txtConnLimit->SetValue(strConnLimit);
+ }
+
+ if (connection->BackendMinimumVersion(8, 4))
+ {
+ cbCollate->Append(database->GetCollate());
+ cbCollate->SetSelection(0);
+ cbCType->Append(database->GetCType());
+ cbCType->SetSelection(0);
+ }
+
cbTemplate->Disable();
cbEncoding->Disable();
+ cbCollate->Disable();
+ cbCType->Disable();
txtSchemaRestr->SetValue(database->GetSchemaRestriction());
}
@@ -194,6 +231,26 @@
FillCombobox(wxT("SELECT datname FROM pg_database ORDER BY datname"), cbTemplate);
cbTemplate->SetSelection(0);
+ if (connection->BackendMinimumVersion(8,4))
+ {
+ FillCombobox(wxT("select DISTINCT(datctype) from pg_database UNION SELECT DISTINCT(datcollate) from pg_database"), cbCollate, cbCType);
+ if (cbCollate->FindString(wxT("C")) < 0)
+ {
+ cbCollate->AppendString(wxT("C"));
+ cbCType->AppendString(wxT("C"));
+ }
+ if (cbCollate->FindString(wxT("POSIX")) < 0)
+ {
+ cbCollate->AppendString(wxT("POSIX"));
+ cbCType->AppendString(wxT("POSIX"));
+ }
+ }
+ if (connection->BackendMinimumVersion(8,1))
+ {
+ txtConnLimit->SetValue(wxT("-1"));
+ }
+
+
long encNo=0;
wxString encStr;
do
@@ -232,6 +289,10 @@
SetupVarEditor(1);
+ // As some of the controls has been made hidden,
+ // Update() will help to rearrange all the other controls properly.
+ this->Update();
+
returncode = dlgSecurityProperty::Go(modal);
#ifdef __WXMAC__
@@ -308,11 +369,15 @@
if (database)
{
+ long connLimit;
+ if (!txtConnLimit->GetValue().ToLong(&connLimit))
+ connLimit = database->GetConnectionLimit();
enable = txtSchemaRestr->GetValue() != database->GetSchemaRestriction()
|| txtComment->GetValue() != database->GetComment()
|| txtName->GetValue() != database->GetName()
|| cbOwner->GetValue() != database->GetOwner()
|| cbTablespace->GetValue() != database->GetTablespace()
+ || connLimit != database->GetConnectionLimit()
|| dirtyVars;
}
@@ -330,6 +395,50 @@
SetupVarEditor(sel);
}
+void dlgDatabase::OnCollateSelChange(wxCommandEvent &ev)
+{
+ cbCollate->GuessSelection(ev);
+}
+
+void dlgDatabase::OnCTypeSelChange(wxCommandEvent &ev)
+{
+ cbCType->GuessSelection(ev);
+}
+
+void dlgDatabase::OnConnLimitChange(wxCommandEvent &ev)
+{
+ if (ev.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED)
+ {
+ wxString strConnLimit = txtConnLimit->GetValue();
+ long val = 0;
+ if (strConnLimit.ToLong(&val))
+ {
+ if (val < -1)
+ {
+ ev.StopPropagation();
+ txtConnLimit->SetValue(wxT("-1"));
+ txtConnLimit->SetInsertionPointEnd();
+ return;
+ }
+ CheckChange();
+ }
+ else if (strConnLimit.Contains(wxT(".")))
+ {
+ double val;
+
+ // Stop Propagation of the event to the parents
+ ev.StopPropagation();
+ if (strConnLimit.ToDouble(&val))
+ {
+ strConnLimit.Printf(wxT("%ld"), (long)val);
+ txtConnLimit->SetValue(strConnLimit);
+ txtConnLimit->SetInsertionPointEnd();
+ return;
+ }
+ }
+ }
+}
+
void dlgDatabase::SetupVarEditor(int var)
{
if (var >= 0 && varInfo.Count() > 0)
@@ -438,6 +547,23 @@
+ wxT(" SET TABLESPACE ") + qtIdent(cbTablespace->GetValue())
+ wxT(";\n");
}
+ if (connection->BackendMinimumVersion(8, 1))
+ {
+ long connLimit;
+ if (!txtConnLimit->GetValue().ToLong(&connLimit))
+ {
+ connLimit = database->GetConnectionLimit();
+ }
+ if (connLimit != database->GetConnectionLimit())
+ {
+ wxString strConnLimit;
+ strConnLimit << txtConnLimit->GetValue();
+ sql += wxT("ALTER DATABASE ") + qtIdent(name)
+ + wxT(" WITH CONNECTION LIMIT = ")
+ + strConnLimit
+ + wxT(";\n");
+ }
+ }
if (!connection->BackendMinimumVersion(8, 2))
sql += GetGrant(wxT("CT"), wxT("DATABASE ") + qtIdent(name));
@@ -498,6 +624,15 @@
AppendIfFilled(sql, wxT("\n OWNER="), qtIdent(cbOwner->GetValue()));
AppendIfFilled(sql, wxT("\n TEMPLATE="), qtIdent(cbTemplate->GetValue()));
AppendIfFilled(sql, wxT("\n LOCATION="), txtPath->GetValue());
+ if (connection->BackendMinimumVersion(8,4))
+ {
+ AppendIfFilled(sql, wxT("\n COLLATE="), qtDbString(cbCollate->GetValue()));
+ AppendIfFilled(sql, wxT("\n CTYPE="), qtDbString(cbCType->GetValue()));
+ }
+ if (connection->BackendMinimumVersion(8,1))
+ {
+ AppendIfFilled(sql, wxT("\n CONNECTION LIMIT="), (txtConnLimit->GetValue() == wxT("-") ? wxT("-1") : txtConnLimit->GetValue()));
+ }
if (cbTablespace->GetCurrentSelection() > 0 && cbTablespace->GetOIDKey() > 0)
sql += wxT("\n TABLESPACE=") + qtIdent(cbTablespace->GetValue());
Index: ui/dlgDatabase.xrc
===================================================================
--- ui/dlgDatabase.xrc (revision 7499)
+++ ui/dlgDatabase.xrc (working copy)
@@ -2,7 +2,7 @@
<resource>
<object class="wxDialog" name="dlgDatabase">
<title></title>
- <size>218,260d</size>
+ <size>218,280d</size>
<style>wxDEFAULT_DIALOG_STYLE|wxCAPTION|wxSYSTEM_MENU|wxRESIZE_BORDER|wxRESIZE_BOX|wxTHICK_FRAME</style>
<object class="wxFlexGridSizer">
<cols>1</cols>
@@ -17,10 +17,10 @@
<object class="wxPanel" name="pnlProperties">
<object class="wxFlexGridSizer">
<cols>2</cols>
- <rows>9</rows>
+ <rows>11</rows>
<vgap>5</vgap>
<hgap>5</hgap>
- <growablerows>8</growablerows>
+ <growablerows>9</growablerows>
<growablecols>1</growablecols>
<object class="sizeritem">
<object class="wxStaticText" name="stName">
@@ -135,6 +135,51 @@
<border>4</border>
</object>
<object class="sizeritem">
+ <object class="wxStaticText" name="stCollate">
+ <label>Collate</label>
+ </object>
+ <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="ctlComboBox" name="cbCollate">
+ <content/>
+ <style>wxCB_DROPDOWN|wxCB_SORT</style>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxStaticText" name="stCType">
+ <label>CTYPE</label>
+ </object>
+ <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="ctlComboBox" name="cbCType">
+ <content/>
+ <style>wxCB_DROPDOWN|wxCB_SORT</style>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxStaticText" name="stConnLimit">
+ <label>Connection Limit</label>
+ </object>
+ <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxTextCtrl" name="txtConnLimit">
+ <content/>
+ <min>-1</min>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
<object class="wxStaticText" name="stComment">
<label>Comment</label>
</object>
@@ -144,6 +189,7 @@
<object class="sizeritem">
<object class="wxTextCtrl" name="txtComment">
<style>wxTE_MULTILINE</style>
+ <size>60,60d</size>
</object>
<flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>4</border>
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers