Hi All,
Please find the patch for "CREATE DATABASE" with COLLATE, CTYPE &
CONNECTION LIMIT.
Changed the following files:
* include/schema/pgDatabase.h
- Declarations of variables & functions for collate, ctype & connection
limit
* include/dlg/dlgDatabase.h
- Declaration of the event handlers to take care the auto-completion of
ctlComboBox for collate & ctype
* schema/pgDatabase.cpp
- Made modifications in GetSql function for reverse engineering of the query
- Made modifications in CreateObjects for fetching ctype, collate and
connection limit details from pg_database catalog for existing
databases, saved as datctype, datcollate, datconnlimit respectively.
* dlg/dlgDatabase.cpp
- Defined the following variables:
+ cbCollate as ctlComboBox
+ cbCType as ctlComboBox
+ spConnLimit as wxSpinCtrl
- Defined event-handlers for auto-completion operation for cbCollate &
cbCType
- COLLATE & CTYPE takes locale as input value.
Currently, we don't have any way to get the supported server-locale on
client side. :(
Hence, I have kept the values fetched from the already used locale
values earlier along with C & POSIX.
- Made modification for Create a new database & editing existing
database (properties).
* ui/dlgDatabase.xrc
- Increased the height of the property dialog by 10
- Added controls for collate, ctype & connection limit
You may need to run embed-xrc.
I have followed this link to implement this.
http://developer.postgresql.org/pgdocs/postgres/sql-createdatabase.html
Range for the Connection limit is set to -1 to 1000.
Regards,
Ashesh
Index: include/schema/pgDatabase.h
===================================================================
--- include/schema/pgDatabase.h (revision 7498)
+++ 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; }
+ int GetConnectionLimit() { return connectionLimit; }
+ void iSetConnectionLimit(int 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;
+ int connectionLimit;
wxArrayString variables;
wxString schemaChanges;
Index: include/dlg/dlgDatabase.h
===================================================================
--- include/dlg/dlgDatabase.h (revision 7498)
+++ include/dlg/dlgDatabase.h (working copy)
@@ -46,6 +46,8 @@
void OnVarAdd(wxCommandEvent &ev);
void OnVarRemove(wxCommandEvent &ev);
void OnVarSelChange(wxListEvent &ev);
+ void OnCollateSelChange(wxCommandEvent &ev);
+ void OnCTypeSelChange(wxCommandEvent &ev);
void OnVarnameSelChange(wxCommandEvent &ev);
void OnOK(wxCommandEvent &ev);
Index: schema/pgDatabase.cpp
===================================================================
--- schema/pgDatabase.cpp (revision 7498)
+++ 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))
@@ -474,6 +483,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 +512,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 +562,16 @@
else
database->iSetPath(databases->GetVal(wxT("datpath")));
+ if (collection->GetConnection()->BackendMinimumVersion(8, 1))
+ {
+ database->iSetConnectionLimit((int)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 7498)
+++ 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,13 @@
#define chkValue CTRL_CHECKBOX("chkValue")
#define btnAdd CTRL_BUTTON("wxID_ADD")
#define btnRemove CTRL_BUTTON("wxID_REMOVE")
+#define stCollate CTRL_TEXT("stCollate")
+#define cbCollate CTRL_COMBOBOX2("cbCollate")
+#define stCType CTRL_TEXT("stCType")
+#define cbCType CTRL_COMBOBOX2("cbCType")
+#define stConnLimit CTRL_TEXT("stConnLimit")
+#define spConnLimit CTRL_SPIN("spConnLimit")
-
dlgProperty *pgDatabaseFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
dlgDatabase *dlg=new dlgDatabase(this, frame, (pgDatabase*)node);
@@ -61,6 +68,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("spConnLimit"), dlgProperty::OnChange)
#ifdef __WXMAC__
EVT_SIZE( dlgDatabase::OnChangeSize)
#endif
@@ -114,6 +124,22 @@
cbTablespace->Hide();
}
+ if (!connection->BackendMinimumVersion(8,1))
+ {
+ stConnLimit->Hide();
+ spConnLimit->Hide();
+ }
+ else
+ spConnLimit->SetRange(-1, 1000);
+
+ if (!connection->BackendMinimumVersion(8,4))
+ {
+ stCollate->Hide();
+ cbCollate->Hide();
+ stCType->Hide();
+ cbCType->Hide();
+ }
+
pgSet *set;
if (connection->BackendMinimumVersion(7, 4))
set=connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
@@ -173,8 +199,25 @@
cbEncoding->Append(database->GetEncoding());
cbEncoding->SetSelection(0);
+ if (connection->BackendMinimumVersion(8,1))
+ {
+ wxString strConnLimit;
+ strConnLimit.Printf(wxT("%ld"), database->GetConnectionLimit());
+ spConnLimit->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 +237,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))
+ {
+ spConnLimit->SetValue(wxT("-1"));
+ }
+
+
long encNo=0;
wxString encStr;
do
@@ -232,6 +295,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__
@@ -313,6 +380,7 @@
|| txtName->GetValue() != database->GetName()
|| cbOwner->GetValue() != database->GetOwner()
|| cbTablespace->GetValue() != database->GetTablespace()
+ || spConnLimit->GetValue() != database->GetConnectionLimit()
|| dirtyVars;
}
@@ -330,6 +398,16 @@
SetupVarEditor(sel);
}
+void dlgDatabase::OnCollateSelChange(wxCommandEvent &ev)
+{
+ cbCollate->GuessSelection(ev);
+}
+
+void dlgDatabase::OnCTypeSelChange(wxCommandEvent &ev)
+{
+ cbCType->GuessSelection(ev);
+}
+
void dlgDatabase::SetupVarEditor(int var)
{
if (var >= 0 && varInfo.Count() > 0)
@@ -437,6 +515,15 @@
sql += wxT("ALTER DATABASE ") + qtIdent(name)
+ wxT(" SET TABLESPACE ") + qtIdent(cbTablespace->GetValue())
+ wxT(";\n");
+ if (spConnLimit->GetValue() != database->GetConnectionLimit())
+ {
+ wxString strConnLimit;
+ strConnLimit << spConnLimit->GetValue();
+ sql += wxT("ALTER DATABASE ") + qtIdent(name)
+ + wxT(" WITH CONNECTION LIMIT = ")
+ + qtDbString(strConnLimit)
+ + wxT(";\n");
+ }
}
if (!connection->BackendMinimumVersion(8, 2))
@@ -498,6 +585,17 @@
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))
+ {
+ wxString strConnLimit;
+ strConnLimit.Printf(wxT("%d"), spConnLimit->GetValue());
+ AppendIfFilled(sql, wxT("\n CONNECTION LIMIT="), strConnLimit);
+ }
if (cbTablespace->GetCurrentSelection() > 0 && cbTablespace->GetOIDKey() > 0)
sql += wxT("\n TABLESPACE=") + qtIdent(cbTablespace->GetValue());
Index: ui/dlgDatabase.xrc
===================================================================
--- ui/dlgDatabase.xrc (revision 7498)
+++ ui/dlgDatabase.xrc (working copy)
@@ -2,7 +2,7 @@
<resource>
<object class="wxDialog" name="dlgDatabase">
<title></title>
- <size>218,260d</size>
+ <size>218,270d</size>
<style>wxDEFAULT_DIALOG_STYLE|wxCAPTION|wxSYSTEM_MENU|wxRESIZE_BORDER|wxRESIZE_BOX|wxTHICK_FRAME</style>
<object class="wxFlexGridSizer">
<cols>1</cols>
@@ -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="wxSpinCtrl" name="spConnLimit">
+ <content/>
+ <style>wxSP_WRAP</style><!--wxSP_ARROW_KEYS|-->
+ </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>
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers