Hi,
It took me one more day than I previously thought. Anyways, here it is.
I checked every I could (apart from checking on Windows and Mac OS X
because I don't have those in my hotel room...).
There is not much to say on this patch. It changes the Role and Database
dialogsbut not that much. Should work on 9.0 (obviously), and previous
releases.
Comments?
(for sure, my last patch with BackendMinimumVersion(8, 5)... forgot to
fix those :) )
--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com
diff --git a/pgadmin/ctl/ctlListView.cpp b/pgadmin/ctl/ctlListView.cpp
index 84e17e6..ac46f06 100644
--- a/pgadmin/ctl/ctlListView.cpp
+++ b/pgadmin/ctl/ctlListView.cpp
@@ -105,3 +105,41 @@ void ctlListView::CreateColumns(wxImageList *images, const wxString &left, const
if (images)
SetImageList(images, wxIMAGE_LIST_SMALL);
}
+
+
+void ctlListView::CreateColumns(wxImageList *images, const wxString &str1, const wxString &str2, const wxString &str3, int leftSize)
+{
+ int rightSize;
+ if (leftSize < 0)
+ {
+#ifdef __WXMAC__
+ leftSize = rightSize = (GetParent()->GetSize().GetWidth() - 20)/2;
+#else
+ leftSize = rightSize = GetSize().GetWidth()/2;
+#endif
+ }
+ else
+ {
+ if (leftSize)
+ leftSize = ConvertDialogToPixels(wxPoint(leftSize, 0)).x;
+
+#ifdef __WXMAC__
+ rightSize = (GetParent()->GetSize().GetWidth() - 20) - leftSize;
+#else
+ rightSize = GetClientSize().GetWidth()-leftSize;
+#endif
+ }
+ if (!leftSize)
+ {
+ InsertColumn(0, str1, wxLIST_FORMAT_LEFT, GetClientSize().GetWidth());
+ }
+ else
+ {
+ InsertColumn(0, str1, wxLIST_FORMAT_LEFT, leftSize);
+ InsertColumn(1, str2, wxLIST_FORMAT_LEFT, rightSize/2);
+ InsertColumn(2, str3, wxLIST_FORMAT_LEFT, rightSize/2);
+ }
+
+ if (images)
+ SetImageList(images, wxIMAGE_LIST_SMALL);
+}
diff --git a/pgadmin/dlg/dlgDatabase.cpp b/pgadmin/dlg/dlgDatabase.cpp
index b5a6041..39fa1d5 100644
--- a/pgadmin/dlg/dlgDatabase.cpp
+++ b/pgadmin/dlg/dlgDatabase.cpp
@@ -32,6 +32,7 @@
#define lstVariables CTRL_LISTVIEW("lstVariables")
#define cbVarname CTRL_COMBOBOX2("cbVarname")
+#define cbVarUsername CTRL_COMBOBOX2("cbVarUsername")
#define txtValue CTRL_TEXT("txtValue")
#define chkValue CTRL_CHECKBOX("chkValue")
#define btnAdd CTRL_BUTTON("wxID_ADD")
@@ -63,6 +64,7 @@ BEGIN_EVENT_TABLE(dlgDatabase, dlgSecurityProperty)
EVT_BUTTON(wxID_ADD, dlgDatabase::OnVarAdd)
EVT_BUTTON(wxID_REMOVE, dlgDatabase::OnVarRemove)
EVT_TEXT(XRCID("cbVarname"), dlgDatabase::OnVarnameSelChange)
+ EVT_TEXT(XRCID("cbVarUsername"), dlgDatabase::OnVarnameSelChange)
EVT_COMBOBOX(XRCID("cbVarname"), dlgDatabase::OnVarnameSelChange)
EVT_BUTTON(wxID_OK, dlgDatabase::OnOK)
EVT_TEXT(XRCID("cbCollate"), dlgDatabase::OnCollateSelChange)
@@ -79,7 +81,7 @@ dlgDatabase::dlgDatabase(pgaFactory *f, frmMain *frame, pgDatabase *node)
{
database=node;
schemaRestrictionOk=true;
- lstVariables->CreateColumns(0, _("Variable"), _("Value"));
+ lstVariables->CreateColumns(0, _("Username"), _("Variable"), _("Value"));
chkValue->Hide();
@@ -108,6 +110,14 @@ int dlgDatabase::Go(bool modal)
AddGroups();
AddUsers(cbOwner);
+ if (connection->BackendMinimumVersion(8,5))
+ {
+ cbVarUsername->Append(wxT(""));
+ AddUsers(cbVarUsername);
+ }
+ else
+ cbVarUsername->Enable(false);
+
if (connection->BackendMinimumVersion(8, 0))
{
stPath->Hide();
@@ -151,6 +161,11 @@ int dlgDatabase::Go(bool modal)
delete set;
cbVarname->SetSelection(0);
+
+ if (connection->BackendMinimumVersion(8,5))
+ {
+ cbVarUsername->SetSelection(0);
+ }
}
if (database)
@@ -168,16 +183,27 @@ int dlgDatabase::Go(bool modal)
if (readOnly)
{
cbVarname->Disable();
+ cbVarUsername->Disable();
txtValue->Disable();
btnAdd->Disable();
btnRemove->Disable();
}
size_t i;
+ wxString username;
+ wxString varname;
+ wxString varvalue;
for (i=0 ; i < database->GetVariables().GetCount() ; i++)
{
- wxString item=database->GetVariables().Item(i);
- lstVariables->AppendItem(0, item.BeforeFirst('='), item.AfterFirst('='));
+ wxStringTokenizer tkz(database->GetVariables().Item(i), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ username = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
+ lstVariables->AppendItem(0, username, varname, varvalue);
}
PrepareTablespace(cbTablespace, database->GetTablespaceOid());
@@ -459,12 +485,13 @@ void dlgDatabase::OnVarSelChange(wxListEvent &ev)
long pos=lstVariables->GetSelection();
if (pos >= 0)
{
- wxString value=lstVariables->GetText(pos, 1);
- cbVarname->SetValue(lstVariables->GetText(pos));
+ cbVarUsername->SetValue(lstVariables->GetText(pos));
+ cbVarname->SetValue(lstVariables->GetText(pos, 1));
// We used to raise an OnVarnameSelChange() event here, but
// at this point the combo box hasn't necessarily updated.
- int sel = cbVarname->FindString(lstVariables->GetText(pos));
+ wxString value=lstVariables->GetText(pos, 2);
+ int sel = cbVarname->FindString(lstVariables->GetText(pos, 1));
SetupVarEditor(sel);
txtValue->SetValue(value);
@@ -475,6 +502,7 @@ void dlgDatabase::OnVarSelChange(wxListEvent &ev)
void dlgDatabase::OnVarAdd(wxCommandEvent &ev)
{
+ wxString username=cbVarUsername->GetValue();
wxString name=cbVarname->GetValue();
wxString value;
if (chkValue->IsShown())
@@ -487,13 +515,39 @@ void dlgDatabase::OnVarAdd(wxCommandEvent &ev)
if (!name.IsEmpty())
{
- long pos=lstVariables->FindItem(-1, name);
- if (pos < 0)
+ bool found = false;
+ long prevpos = -1;
+ for (long item=0; item<lstVariables->GetItemCount(); item++)
{
- pos = lstVariables->GetItemCount();
- lstVariables->InsertItem(pos, name, 0);
+ if (name == lstVariables->GetText(item, 1))
+ {
+ if (username == lstVariables->GetText(item))
+ {
+ found = true;
+ lstVariables->SetItem(item, 2, value);
+ }
+ else
+ {
+ prevpos = item;
+ }
+ }
+ }
+ if (!found)
+ {
+ if (prevpos != -1)
+ {
+ lstVariables->InsertItem(prevpos, username, 1);
+ lstVariables->SetItem(prevpos, 1, name);
+ lstVariables->SetItem(prevpos, 2, value);
+ }
+ else
+ {
+ long pos = lstVariables->GetItemCount();
+ lstVariables->InsertItem(pos, username, 1);
+ lstVariables->SetItem(pos, 1, name);
+ lstVariables->SetItem(pos, 2, value);
+ }
}
- lstVariables->SetItem(pos, 1, value);
}
dirtyVars = true;
CheckChange();
@@ -560,6 +614,9 @@ wxString dlgDatabase::GetSql()
sql += GetGrant(wxT("CTc"), wxT("DATABASE ") + qtIdent(name));
wxArrayString vars;
+ wxString username;
+ wxString varname;
+ wxString varvalue;
size_t index;
@@ -572,36 +629,71 @@ wxString dlgDatabase::GetSql()
// check for changed or added vars
for (pos=0 ; pos < cnt ; pos++)
{
- wxString newVar=lstVariables->GetText(pos);
- wxString newVal=lstVariables->GetText(pos, 1);
+ wxString newUsr=lstVariables->GetText(pos);
+ wxString newVar=lstVariables->GetText(pos, 1);
+ wxString newVal=lstVariables->GetText(pos, 2);
wxString oldVal;
for (index=0 ; index < vars.GetCount() ; index++)
{
+ wxStringTokenizer tkz(vars.Item(index), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ username = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
wxString var=vars.Item(index);
- if (var.BeforeFirst('=').IsSameAs(newVar, false))
+ if (newUsr == username && newVar == varname)
{
- oldVal = var.Mid(newVar.Length()+1);
+ oldVal = varvalue;
vars.RemoveAt(index);
break;
}
}
if (oldVal != newVal)
{
- sql += wxT("ALTER DATABASE ") + qtIdent(name)
- + wxT(" SET ") + newVar
- + wxT("='") + newVal
- + wxT("';\n");
+ if (newUsr.Length() == 0)
+ {
+ sql += wxT("ALTER DATABASE ") + qtIdent(name)
+ + wxT(" SET ") + newVar
+ + wxT("='") + newVal
+ + wxT("';\n");
+ }
+ else
+ {
+ sql += wxT("ALTER ROLE ") + newUsr + wxT(" IN DATABASE ") + qtIdent(name)
+ + wxT(" SET ") + newVar
+ + wxT("='") + newVal
+ + wxT("';\n");
+ }
}
}
// check for removed vars
for (pos=0 ; pos < (int)vars.GetCount() ; pos++)
{
- sql += wxT("ALTER DATABASE ") + qtIdent(name)
- + wxT(" RESET ") + vars.Item(pos).BeforeFirst('=')
- + wxT(";\n");
+ wxStringTokenizer tkz(vars.Item(pos), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ username = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
+ if (username.Length() == 0)
+ {
+ sql += wxT("ALTER DATABASE ") + qtIdent(name)
+ + wxT(" RESET ") + varname
+ + wxT(";\n");
+ }
+ else
+ {
+ sql += wxT("ALTER ROLE ") + username + wxT(" IN DATABASE ") + qtIdent(name)
+ + wxT(" RESET ") + varname + wxT(";\n");
+ }
}
}
else
diff --git a/pgadmin/dlg/dlgRole.cpp b/pgadmin/dlg/dlgRole.cpp
index 1a41384..8b35b77 100644
--- a/pgadmin/dlg/dlgRole.cpp
+++ b/pgadmin/dlg/dlgRole.cpp
@@ -45,6 +45,7 @@
#define cbVarname CTRL_COMBOBOX2("cbVarname")
#define txtValue CTRL_TEXT("txtValue")
#define chkValue CTRL_CHECKBOX("chkValue")
+#define cbVarDatabase CTRL_COMBOBOX2("cbVarDatabase")
@@ -83,6 +84,8 @@ BEGIN_EVENT_TABLE(dlgRole, dlgProperty)
EVT_BUTTON(wxID_REMOVE, dlgRole::OnVarRemove)
EVT_TEXT(XRCID("cbVarname"), dlgRole::OnVarnameSelChange)
EVT_COMBOBOX(XRCID("cbVarname"), dlgRole::OnVarnameSelChange)
+ EVT_TEXT(XRCID("cbVarDatabase"), dlgRole::OnVarnameSelChange)
+ EVT_COMBOBOX(XRCID("cbVarDatabase"), dlgRole::OnVarnameSelChange)
EVT_BUTTON(wxID_OK, dlgRole::OnOK)
@@ -97,7 +100,7 @@ dlgRole::dlgRole(pgaFactory *f, frmMain *frame, pgRole *node, bool chkLogin)
: dlgProperty(f, frame, wxT("dlgRole"))
{
role=node;
- lstVariables->CreateColumns(0, _("Variable"), _("Value"), -1);
+ lstVariables->CreateColumns(0, _("Database"), _("Variable"), _("Value"), -1);
btnOK->Disable();
chkValue->Hide();
if (chkLogin)
@@ -152,6 +155,27 @@ int dlgRole::Go(bool modal)
cbVarname->SetSelection(0);
}
+ if (connection->BackendMinimumVersion(8,5))
+ {
+ cbVarDatabase->Append(wxT(""));
+ set=connection->ExecuteSet(wxT("SELECT datname FROM pg_database ")
+ wxT("ORDER BY datname"));
+
+ if (set)
+ {
+ while (!set->Eof())
+ {
+ cbVarDatabase->Append(set->GetVal(0));
+ set->MoveNext();
+ }
+ delete set;
+
+ cbVarDatabase->SetSelection(0);
+ }
+ }
+ else
+ cbVarDatabase->Enable(false);
+
if (role)
{
wxArrayString roles=role->GetRolesIn();
@@ -181,11 +205,20 @@ int dlgRole::Go(bool modal)
txtConnectionLimit->SetValue(NumToStr(role->GetConnectionLimit()));
txtComment->SetValue(role->GetComment());
- size_t index;
- for (index = 0 ; index < role->GetConfigList().GetCount() ; index++)
+ wxString database;
+ wxString varname;
+ wxString varvalue;
+ for (i=0 ; i < role->GetConfigList().GetCount() ; i++)
{
- wxString item=role->GetConfigList().Item(index);
- lstVariables->AppendItem(0, item.BeforeFirst('='), item.AfterFirst('='));
+ wxStringTokenizer tkz(role->GetConfigList().Item(i), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ database = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
+ lstVariables->AppendItem(0, database, varname, varvalue);
}
timValidUntil->Enable(!readOnly && role->GetAccountExpires().IsValid());
@@ -203,6 +236,7 @@ int dlgRole::Go(bool modal)
btnAddRole->Disable();
btnDelRole->Disable();
cbVarname->Disable();
+ cbVarDatabase->Disable();
txtValue->Disable();
txtConnectionLimit->Disable();
btnRemove->Disable();
@@ -434,12 +468,13 @@ void dlgRole::OnVarSelChange(wxListEvent &ev)
long pos=lstVariables->GetSelection();
if (pos >= 0)
{
- wxString value=lstVariables->GetText(pos, 1);
- cbVarname->SetValue(lstVariables->GetText(pos));
+ cbVarDatabase->SetValue(lstVariables->GetText(pos));
+ cbVarname->SetValue(lstVariables->GetText(pos, 1));
// We used to raise an OnVarnameSelChange() event here, but
// at this point the combo box hasn't necessarily updated.
- int sel = cbVarname->FindString(lstVariables->GetText(pos));
+ wxString value=lstVariables->GetText(pos, 2);
+ int sel = cbVarname->FindString(lstVariables->GetText(pos, 1));
SetupVarEditor(sel);
txtValue->SetValue(value);
@@ -450,8 +485,11 @@ void dlgRole::OnVarSelChange(wxListEvent &ev)
void dlgRole::OnVarAdd(wxCommandEvent &ev)
{
+ wxString database=cbVarDatabase->GetValue();
wxString name=cbVarname->GetValue();
wxString value;
+ long pos;
+
if (chkValue->IsShown())
value = chkValue->GetValue() ? wxT("on") : wxT("off");
else
@@ -462,13 +500,39 @@ void dlgRole::OnVarAdd(wxCommandEvent &ev)
if (!name.IsEmpty())
{
- long pos=lstVariables->FindItem(-1, name);
- if (pos < 0)
+ bool found = false;
+ long prevpos = -1;
+ for (long item=0; item<lstVariables->GetItemCount(); item++)
{
- pos = lstVariables->GetItemCount();
- lstVariables->InsertItem(pos, name, 0);
+ if (name == lstVariables->GetText(item, 1))
+ {
+ if (database == lstVariables->GetText(item))
+ {
+ found = true;
+ lstVariables->SetItem(item, 2, value);
+ }
+ else
+ {
+ prevpos = item;
+ }
+ }
+ }
+ if (!found)
+ {
+ if (prevpos != -1)
+ {
+ lstVariables->InsertItem(prevpos, database, 1);
+ lstVariables->SetItem(prevpos, 1, name);
+ lstVariables->SetItem(prevpos, 2, value);
+ }
+ else
+ {
+ long pos = lstVariables->GetItemCount();
+ lstVariables->InsertItem(pos, database, 1);
+ lstVariables->SetItem(pos, 1, name);
+ lstVariables->SetItem(pos, 2, value);
+ }
}
- lstVariables->SetItem(pos, 1, value);
}
CheckChange();
}
@@ -716,6 +780,9 @@ wxString dlgRole::GetSql()
wxArrayString vars;
size_t index;
+ wxString database;
+ wxString varname;
+ wxString varvalue;
if (role)
{
@@ -728,36 +795,71 @@ wxString dlgRole::GetSql()
// check for changed or added vars
for (pos=0 ; pos < cnt ; pos++)
{
- wxString newVar=lstVariables->GetText(pos);
- wxString newVal=lstVariables->GetText(pos, 1);
+ wxString newDb=lstVariables->GetText(pos);
+ wxString newVar=lstVariables->GetText(pos, 1);
+ wxString newVal=lstVariables->GetText(pos, 2);
wxString oldVal;
for (index=0 ; index < vars.GetCount() ; index++)
{
+ wxStringTokenizer tkz(vars.Item(index), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ database = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
wxString var=vars.Item(index);
- if (var.BeforeFirst('=').IsSameAs(newVar, false))
+ if (newDb == database && newVar == varname)
{
- oldVal = var.Mid(newVar.Length()+1);
+ oldVal = varvalue;
vars.RemoveAt(index);
break;
}
}
if (oldVal != newVal)
{
- sql += wxT("ALTER ROLE ") + qtIdent(name)
- + wxT(" SET ") + newVar
- + wxT("='") + newVal
- + wxT("';\n");
+ if (newDb.Length() == 0)
+ {
+ sql += wxT("ALTER ROLE ") + qtIdent(name)
+ + wxT(" SET ") + newVar
+ + wxT("='") + newVal
+ + wxT("';\n");
+ }
+ else
+ {
+ sql += wxT("ALTER ROLE ") + qtIdent(name) + wxT(" IN DATABASE ") + database
+ + wxT(" SET ") + newVar
+ + wxT("='") + newVal
+ + wxT("';\n");
+ }
}
}
// check for removed vars
for (pos=0 ; pos < (int)vars.GetCount() ; pos++)
{
- sql += wxT("ALTER ROLE ") + qtIdent(name)
- + wxT(" RESET ") + vars.Item(pos).BeforeFirst('=')
- + wxT(";\n");
+ wxStringTokenizer tkz(vars.Item(pos), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ database = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
+ if (database.Length() == 0)
+ {
+ sql += wxT("ALTER ROLE ") + qtIdent(name)
+ + wxT(" RESET ") + varname
+ + wxT(";\n");
+ }
+ else
+ {
+ sql += wxT("ALTER ROLE ") + qtIdent(name) + wxT(" IN DATABASE ") + database
+ + wxT(" RESET ") + varname + wxT(";\n");
+ }
}
AppendComment(sql, wxT("ROLE"), 0, role);
diff --git a/pgadmin/include/ctl/ctlListView.h b/pgadmin/include/ctl/ctlListView.h
index 01c2a5a..4928eaa 100644
--- a/pgadmin/include/ctl/ctlListView.h
+++ b/pgadmin/include/ctl/ctlListView.h
@@ -27,6 +27,7 @@ public:
wxString GetText(long row, long col=0);
void CreateColumns(wxImageList *images, const wxString &left, const wxString &right, int leftSize=60);
+ void CreateColumns(wxImageList *images, const wxString &str1, const wxString &str2, const wxString &str3, int leftSize=60);
void AddColumn(const wxChar *text, int size=wxLIST_AUTOSIZE_USEHEADER, int format=wxLIST_FORMAT_LEFT);
diff --git a/pgadmin/schema/pgDatabase.cpp b/pgadmin/schema/pgDatabase.cpp
index c46bae8..4b153e2 100644
--- a/pgadmin/schema/pgDatabase.cpp
+++ b/pgadmin/schema/pgDatabase.cpp
@@ -406,9 +406,30 @@ wxString pgDatabase::GetSql(ctlTree *browser)
sql += wxT(";\n");
size_t i;
+ wxString username;
+ wxString varname;
+ wxString varvalue;
for (i=0 ; i < variables.GetCount() ; i++)
- sql += wxT("ALTER DATABASE ") + GetQuotedFullIdentifier()
- + wxT(" SET ") + variables.Item(i).BeforeFirst('=') + wxT("='") + variables.Item(i).AfterFirst('=') + wxT("';\n");
+ {
+ wxStringTokenizer tkz(variables.Item(i), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ username = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
+ if (username.Length() == 0)
+ {
+ sql += wxT("ALTER DATABASE ") + GetQuotedFullIdentifier()
+ + wxT(" SET ") + varname + wxT("='") + varvalue + wxT("';\n");
+ }
+ else
+ {
+ sql += wxT("ALTER ROLE ") + username + wxT(" IN DATABASE ") + GetQuotedFullIdentifier()
+ + wxT(" SET ") + varname + wxT("='") + varvalue + wxT("';\n");
+ }
+ }
if (myConn)
{
@@ -498,10 +519,29 @@ void pgDatabase::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *pr
properties->AppendItem(_("Default schema"), defaultSchema);
size_t i;
+ wxString username;
+ wxString varname;
+ wxString varvalue;
for (i=0 ; i < variables.GetCount() ; i++)
{
- wxString item=variables.Item(i);
- properties->AppendItem(item.BeforeFirst('='), item.AfterFirst('='));
+ wxStringTokenizer tkz(variables.Item(i), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ username = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
+ if (username.Length() == 0)
+ {
+ properties->AppendItem(varname, varvalue);
+ }
+ else
+ {
+ // should we add the parameters for the username?
+ // I don't think so
+ // but if we want this, how will we display that?
+ }
}
properties->AppendItem(_("Allow connections?"), GetAllowConnections());
properties->AppendItem(_("Connected?"), GetConnected());
@@ -568,8 +608,12 @@ pgObject *pgDatabaseFactory::CreateObjects(pgCollection *collection, ctlTree *br
// In 8.5+, database config options are in pg_db_role_setting
if (collection->GetConnection()->BackendMinimumVersion(8, 5))
+ {
+ wxString setconfig = wxT("SELECT array(select coalesce('''' || rolname || '''', '') || '=' || unnest(setconfig) ")
+ wxT("FROM pg_db_role_setting setting LEFT JOIN pg_roles role ON setting.setrole=role.oid ")
+ wxT("WHERE setdatabase = db.oid)");
databases = collection->GetServer()->ExecuteSet(
- wxT("SELECT db.oid, datname, db.dattablespace AS spcoid, spcname, datallowconn, setconfig AS datconfig, datacl, ")
+ wxT("SELECT db.oid, datname, db.dattablespace AS spcoid, spcname, datallowconn, (") + setconfig + wxT(") AS datconfig, datacl, ")
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")
@@ -578,9 +622,9 @@ pgObject *pgDatabaseFactory::CreateObjects(pgCollection *collection, ctlTree *br
wxT(" FROM pg_database db\n")
wxT(" LEFT OUTER JOIN pg_tablespace ta ON db.dattablespace=ta.OID\n")
wxT(" LEFT OUTER JOIN pg_shdescription descr ON db.oid=descr.objoid\n")
- wxT(" LEFT OUTER JOIN pg_db_role_setting setting ON (db.oid=setting.setdatabase AND setting.setrole=0)\n")
+ restr +
wxT(" ORDER BY datname"));
+ }
else if (collection->GetConnection()->BackendMinimumVersion(8, 0))
databases = collection->GetServer()->ExecuteSet(
wxT("SELECT db.oid, datname, db.dattablespace AS spcoid, spcname, datallowconn, datconfig, datacl, ")
@@ -621,6 +665,18 @@ pgObject *pgDatabaseFactory::CreateObjects(pgCollection *collection, ctlTree *br
database->iSetCreatePrivilege(databases->GetBool(wxT("cancreate")));
database->iSetComment(databases->GetVal(wxT("description")));
wxString str=databases->GetVal(wxT("datconfig"));
+ if (!collection->GetConnection()->BackendMinimumVersion(8, 5))
+ {
+ wxString tmp = wxEmptyString;
+ wxStringTokenizer tkz(str.Mid(1, str.Length()-2), wxT(","));
+ while (tkz.HasMoreTokens())
+ {
+ if (tmp.Length() > 0)
+ tmp += wxT(",");
+ tmp += wxT("=") + tkz.GetNextToken();
+ }
+ str = wxT("{") + tmp + wxT("}");
+ }
if (!str.IsEmpty())
FillArray(database->GetVariables(), str.Mid(1, str.Length()-2));
database->iSetAllowConnections(databases->GetBool(wxT("datallowconn")));
diff --git a/pgadmin/schema/pgRole.cpp b/pgadmin/schema/pgRole.cpp
index 1098a11..462ac04 100644
--- a/pgadmin/schema/pgRole.cpp
+++ b/pgadmin/schema/pgRole.cpp
@@ -102,10 +102,29 @@ wxString pgRole::GetSql(ctlTree *browser)
sql += wxT("UPDATE pg_authid SET rolcatupdate=false WHERE rolname=") + qtDbString(GetIdentifier()) + wxT(";\n");
size_t index;
+ wxString database;
+ wxString varname;
+ wxString varvalue;
for (index=0 ; index < configList.GetCount() ; index++)
{
- sql += wxT("ALTER ROLE ") + GetQuotedIdentifier()
- + wxT(" SET ") + configList.Item(index).BeforeFirst('=') + wxT("='") + configList.Item(index).AfterFirst('=') + wxT("';\n");
+ wxStringTokenizer tkz(configList.Item(index), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ database = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
+ if (database.Length() == 0)
+ {
+ sql += wxT("ALTER ROLE ") + GetQuotedIdentifier()
+ + wxT(" SET ") + varname + wxT("='") + varvalue + wxT("';\n");
+ }
+ else
+ {
+ sql += wxT("ALTER ROLE ") + GetQuotedIdentifier() + wxT(" IN DATABASE ") + database
+ + wxT(" SET ") + varname + wxT("='") + varvalue + wxT("';\n");
+ }
}
for (index=0 ; index < rolesIn.GetCount() ; index++)
{
@@ -280,10 +299,29 @@ void pgRole::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *proper
}
properties->AppendItem(_("Member of"), roleList);
+ wxString database;
+ wxString varname;
+ wxString varvalue;
for (index=0; index < configList.GetCount() ; index++)
{
- wxString item=configList.Item(index);
- properties->AppendItem(item.BeforeFirst('='), item.AfterFirst('='));
+ wxStringTokenizer tkz(configList.Item(index), wxT("="));
+ while (tkz.HasMoreTokens())
+ {
+ database = tkz.GetNextToken();
+ varname = tkz.GetNextToken();
+ varvalue = tkz.GetNextToken();
+ }
+
+ if (database.Length() == 0)
+ {
+ properties->AppendItem(varname, varvalue);
+ }
+ else
+ {
+ // should we add the parameters for the user/database?
+ // I don't think so
+ // but if we want this, how will we display that?
+ }
}
}
}
@@ -362,10 +400,14 @@ pgObject *pgRoleBaseFactory::CreateObjects(pgCollection *collection, ctlTree *br
// In 8.5+, role config options are in pg_db_role_setting
if (collection->GetServer()->GetConnection()->BackendMinimumVersion(8, 5))
- roles = collection->GetServer()->ExecuteSet(wxT("SELECT tab.oid, tab.*, pg_catalog.shobj_description(tab.oid, 'pg_authid') AS description, setting.setconfig AS rolconfig FROM ") +
+ {
+ wxString setconfig = wxT("SELECT array(select coalesce('''' || datname || '''', '') || '=' || unnest(setconfig) ")
+ wxT("FROM pg_db_role_setting setting LEFT JOIN pg_database db ON setting.setdatabase=db.oid ")
+ wxT("WHERE setrole = tab.oid)");
+ roles = collection->GetServer()->ExecuteSet(wxT("SELECT tab.oid, tab.*, pg_catalog.shobj_description(tab.oid, 'pg_authid') AS description, (") + setconfig + wxT(") AS rolconfig FROM ") +
tabname + wxT(" tab") +
- wxT(" LEFT OUTER JOIN pg_db_role_setting setting ON (tab.oid=setting.setrole AND setting.setdatabase=0)\n") +
restriction + wxT(" ORDER BY rolname"));
+ }
else if (collection->GetServer()->GetConnection()->BackendMinimumVersion(8, 2))
roles = collection->GetServer()->ExecuteSet(wxT("SELECT oid, *, pg_catalog.shobj_description(oid, 'pg_authid') AS description FROM ")
+ tabname + restriction + wxT(" ORDER BY rolname"));
@@ -405,6 +447,19 @@ pgObject *pgRoleBaseFactory::CreateObjects(pgCollection *collection, ctlTree *br
wxString cfg=roles->GetVal(wxT("rolconfig"));
+ if (!collection->GetConnection()->BackendMinimumVersion(8, 5))
+ {
+ wxString tmp = wxEmptyString;
+ wxStringTokenizer tkz(cfg.Mid(1, cfg.Length()-2), wxT(","));
+ while (tkz.HasMoreTokens())
+ {
+ if (tmp.Length() > 0)
+ tmp += wxT(",");
+ tmp += wxT("=") + tkz.GetNextToken();
+ }
+ cfg = wxT("{") + tmp + wxT("}");
+ }
+
if (!cfg.IsEmpty())
FillArray(role->GetConfigList(), cfg.Mid(1, cfg.Length()-2));
diff --git a/pgadmin/ui/dlgDatabase.xrc b/pgadmin/ui/dlgDatabase.xrc
index cec97bc..2d5129d 100644
--- a/pgadmin/ui/dlgDatabase.xrc
+++ b/pgadmin/ui/dlgDatabase.xrc
@@ -290,6 +290,21 @@
<flag>wxALL|wxGROW|wxALIGN_CENTRE</flag>
<border>4</border>
</object>
+ <object class="sizeritem">
+ <object class="wxStaticText" name="stVarUsername">
+ <label>User Name</label>
+ </object>
+ <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="ctlComboBox" name="cbVarUsername">
+ <content/>
+ <style>wxCB_DROPDOWN</style>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
</object>
<flag>wxGROW</flag>
</object>
diff --git a/pgadmin/ui/dlgRole.xrc b/pgadmin/ui/dlgRole.xrc
index 9509b3e..4dcd131 100644
--- a/pgadmin/ui/dlgRole.xrc
+++ b/pgadmin/ui/dlgRole.xrc
@@ -403,6 +403,21 @@
<flag>wxALL|wxGROW|wxALIGN_CENTRE</flag>
<border>4</border>
</object>
+ <object class="sizeritem">
+ <object class="wxStaticText" name="stVarDatabase">
+ <label>Database</label>
+ </object>
+ <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="ctlComboBox" name="cbVarDatabase">
+ <content/>
+ <style>wxCB_DROPDOWN</style>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
</object>
<flag>wxGROW</flag>
</object>
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers