Hi, With PostgreSQL 8.1 and new ROLE object remplacing traditional USER/GROUP, I was a bit confuse using the dlgProperty and dlgSecurityProperty dialog because I can only select USER (ROLE with LOGIN privilege) for owner and GROUP (ROLE without LOGIN privilege) for privileges . And I not sure this comportment can match all PostgreSQL 8.1 usages scenarios (like one of my case).
This proposed patch : - change owner and privilege list to get the full ROLE list. - select by default currently connected ROLE in the owner list (replacing the blank filed) for new object creation - remove pg_global in the available tablespace list - select current user default tablespace in tablespace list (replacing the blank filed, yes I don't like blank field) for new object creation It's not fully finish yet, I have one or two bug in mind, but it's usable if you want to test it, I post it to know your opinion about it, know if go to the wrong way. Does it make sense to replace user and group tree by a role tree if your are connected to a PostgreSQL server version 8.1 ? Comments are welcomes. Thomas
diff -Nru pgadmin3/src/dlg/dlgDatabase.cpp pgadmin3_1.4.svn20060522/src/dlg/dlgDatabase.cpp --- pgadmin3/src/dlg/dlgDatabase.cpp 2006-01-06 17:33:27.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/dlg/dlgDatabase.cpp 2006-05-24 15:04:58.000000000 +0000 @@ -85,12 +85,18 @@ int dlgDatabase::Go(bool modal) { - if (!database) - cbOwner->Append(wxT("")); - - AddGroups(); - AddUsers(cbOwner); + if (connection->BackendMinimumVersion(8, 1)) + { + AddRoles(cbOwner); + } + else + { + if (!database) + cbOwner->Append(wxT("")); + AddGroups(); + AddUsers(cbOwner); + } if (connection->BackendMinimumVersion(7, 5)) { diff -Nru pgadmin3/src/dlg/dlgFunction.cpp pgadmin3_1.4.svn20060522/src/dlg/dlgFunction.cpp --- pgadmin3/src/dlg/dlgFunction.cpp 2006-01-06 17:33:27.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/dlg/dlgFunction.cpp 2006-05-24 14:52:21.000000000 +0000 @@ -130,11 +130,18 @@ rdbDirection->Disable(); isProcedure = function->GetIsProcedure(); } + + if (connection->BackendMinimumVersion(8, 1)) + { + AddRoles(cbOwner); + } else - cbOwner->Append(wxEmptyString); - - AddGroups(); - AddUsers(cbOwner); + { + if (!function) + cbOwner->Append(wxT("")); + AddGroups(); + AddUsers(cbOwner); + } if (!connection->BackendMinimumVersion(8, 0)) cbOwner->Disable(); diff -Nru pgadmin3/src/dlg/dlgLanguage.cpp pgadmin3_1.4.svn20060522/src/dlg/dlgLanguage.cpp --- pgadmin3/src/dlg/dlgLanguage.cpp 2006-01-06 17:33:27.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/dlg/dlgLanguage.cpp 2006-05-24 14:23:10.000000000 +0000 @@ -56,9 +56,17 @@ { if (!connection->BackendMinimumVersion(7, 5)) txtComment->Disable(); + + if (connection->BackendMinimumVersion(8, 1)) + { + AddRoles(); + } + else + { + AddGroups(); + AddUsers(); + } - AddGroups(); - AddUsers(); if (language) { // edit mode diff -Nru pgadmin3/src/dlg/dlgProperty.cpp pgadmin3_1.4.svn20060522/src/dlg/dlgProperty.cpp --- pgadmin3/src/dlg/dlgProperty.cpp 2006-01-06 17:33:27.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/dlg/dlgProperty.cpp 2006-05-24 15:33:25.000000000 +0000 @@ -237,9 +237,17 @@ if (cbowner && !cbowner->GetCount()) { - if (!GetObject()) - cbOwner->Append(wxEmptyString); - AddUsers(cbowner); + if (connection && connection->BackendMinimumVersion(8, 1)) + { + AddRoles(cbOwner); + } + else + { + if (!GetObject()) + cbOwner->Append(wxEmptyString); + AddUsers(cbowner); + } + } if (txtOid) txtOid->Disable(); @@ -406,6 +414,13 @@ FillCombobox(wxT("SELECT usename FROM pg_user ORDER BY usename"), cb1, cb2); } +void dlgProperty::AddRoles(ctlComboBoxFix *cb1, ctlComboBoxFix *cb2) +{ + FillCombobox(wxT("SELECT rolname from pg_roles ORDER BY rolname"), cb1, cb2); + if (database) { + cb1->SetValue(database->GetServer()->GetUsername()); + } +} void dlgProperty::PrepareTablespace(ctlComboBoxFix *cb, const wxChar *current) { @@ -421,9 +436,9 @@ } else { - cb->Append(wxEmptyString); - FillCombobox(wxT("SELECT spcname FROM pg_tablespace WHERE spcname <> 'global' ORDER BY spcname"), cb); - cb->SetSelection(0); + FillCombobox(wxT("SELECT spcname FROM pg_tablespace WHERE spcname NOT IN ('global', 'pg_global') ORDER BY spcname"), cb); + if(database) + cb->SetValue(database->GetServer()->GetDefaultTablespace()); } } else @@ -1133,6 +1148,31 @@ } +void dlgSecurityProperty::AddRoles(ctlComboBox *comboBox) +{ + if (connection) + { + pgSet *set=connection->ExecuteSet(wxT("SELECT rolname from pg_roles ORDER BY rolname")); + + if (set) + { + while (!set->Eof()) + { + if (securityPage && securityPage->cbGroups) + securityPage->cbGroups->Append(set->GetVal(0)); + if (comboBox) + comboBox->Append(set->GetVal(0)); + set->MoveNext(); + } + delete set; + if (database) { + cbOwner->SetValue(database->GetServer()->GetUsername()); + } + } + } + +} + void dlgSecurityProperty::OnAddPriv(wxCommandEvent &ev) { securityChanged=true; diff -Nru pgadmin3/src/dlg/dlgSchema.cpp pgadmin3_1.4.svn20060522/src/dlg/dlgSchema.cpp --- pgadmin3/src/dlg/dlgSchema.cpp 2006-01-06 17:33:27.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/dlg/dlgSchema.cpp 2006-05-24 14:52:34.000000000 +0000 @@ -44,11 +44,19 @@ int dlgSchema::Go(bool modal) { - if (!schema) - cbOwner->Append(wxT("")); + if (connection->BackendMinimumVersion(8, 1)) + { + AddRoles(cbOwner); + } + else + { + if (!schema) + cbOwner->Append(wxT("")); + + AddGroups(); + AddUsers(cbOwner); + } - AddGroups(); - AddUsers(cbOwner); if (schema) { // edit mode diff -Nru pgadmin3/src/dlg/dlgSequence.cpp pgadmin3_1.4.svn20060522/src/dlg/dlgSequence.cpp --- pgadmin3/src/dlg/dlgSequence.cpp 2006-01-06 17:33:27.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/dlg/dlgSequence.cpp 2006-05-24 14:52:37.000000000 +0000 @@ -64,10 +64,19 @@ int dlgSequence::Go(bool modal) { - if (!sequence) - cbOwner->Append(wxEmptyString); - AddGroups(); - AddUsers(cbOwner); + + if (connection->BackendMinimumVersion(8, 1)) + { + AddRoles(cbOwner); + } + else + { + if (!sequence) + cbOwner->Append(wxT("")); + AddGroups(); + AddUsers(cbOwner); + } + if (sequence) { diff -Nru pgadmin3/src/dlg/dlgTable.cpp pgadmin3_1.4.svn20060522/src/dlg/dlgTable.cpp --- pgadmin3/src/dlg/dlgTable.cpp 2006-01-31 12:28:45.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/dlg/dlgTable.cpp 2006-05-24 14:52:40.000000000 +0000 @@ -130,10 +130,18 @@ int dlgTable::Go(bool modal) { - if (!table) - cbOwner->Append(wxT("")); - AddGroups(); - AddUsers(cbOwner); + if (connection->BackendMinimumVersion(8, 1)) + { + AddRoles(cbOwner); + } + else + { + if (!table) + cbOwner->Append(wxT("")); + AddGroups(); + AddUsers(cbOwner); + } + PrepareTablespace(cbTablespace); hasPK=false; diff -Nru pgadmin3/src/dlg/dlgTablespace.cpp pgadmin3_1.4.svn20060522/src/dlg/dlgTablespace.cpp --- pgadmin3/src/dlg/dlgTablespace.cpp 2006-01-06 17:33:27.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/dlg/dlgTablespace.cpp 2006-05-24 14:52:43.000000000 +0000 @@ -54,10 +54,18 @@ int dlgTablespace::Go(bool modal) { - if (!tablespace) - cbOwner->Append(wxEmptyString); - AddGroups(); - AddUsers(cbOwner); + if (connection->BackendMinimumVersion(8, 1)) + { + AddRoles(cbOwner); + } + else + { + if (!tablespace) + cbOwner->Append(wxT("")); + AddGroups(); + AddUsers(cbOwner); + } + txtComment->Disable(); if (tablespace) diff -Nru pgadmin3/src/dlg/dlgView.cpp pgadmin3_1.4.svn20060522/src/dlg/dlgView.cpp --- pgadmin3/src/dlg/dlgView.cpp 2006-01-06 17:33:27.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/dlg/dlgView.cpp 2006-05-24 14:31:44.000000000 +0000 @@ -56,9 +56,16 @@ int dlgView::Go(bool modal) { - AddGroups(); - AddUsers(); + if (connection->BackendMinimumVersion(8, 1)) + { + AddRoles(); + } + else + { + AddGroups(); + AddUsers(); + } if (view) { // edit mode diff -Nru pgadmin3/src/include/dlgProperty.h pgadmin3_1.4.svn20060522/src/include/dlgProperty.h --- pgadmin3/src/include/dlgProperty.h 2006-01-06 17:33:27.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/include/dlgProperty.h 2006-05-24 15:11:48.000000000 +0000 @@ -83,6 +83,7 @@ protected: void AddUsers(ctlComboBoxFix *cb1, ctlComboBoxFix *cb2=0); + void AddRoles(ctlComboBoxFix *cb1, ctlComboBoxFix *cb2=0); void FillCombobox(const wxString &query, ctlComboBoxFix *cb1, ctlComboBoxFix *cb2=0); void PrepareTablespace(ctlComboBoxFix *cb, const wxChar *current=0); @@ -163,6 +164,7 @@ ~dlgSecurityProperty(); void AddGroups(ctlComboBox *comboBox=0); void AddUsers(ctlComboBox *comboBox=0); + void AddRoles(ctlComboBox *comboBox=0); wxString GetGrant(const wxString &allPattern, const wxString &grantObject); void EnableOK(bool enable); diff -Nru pgadmin3/src/include/pgServer.h pgadmin3_1.4.svn20060522/src/include/pgServer.h --- pgadmin3/src/include/pgServer.h 2006-05-17 15:35:59.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/include/pgServer.h 2006-05-23 13:24:25.000000000 +0000 @@ -76,6 +76,8 @@ void iSetSuperUser(const bool b) { superUser=b; } bool GetCreateRole() const { return createRole; } void iSetCreateRole(const bool b) { createRole=b; } + wxString GetDefaultTablespace() const { return defaultTablespace; } + void iSetdefaultTablespace(const wxString& newVal) { defaultTablespace = newVal; } pgConn *CreateConn(wxString dbName=wxEmptyString, OID oid=0); @@ -122,7 +124,7 @@ pgConn *conn; bool connected, passwordValid, autovacuumRunning; - wxString database, username, password, ver, error; + wxString database, username, password, ver, error, defaultTablespace; wxString lastDatabase, lastSchema, description, serviceId; wxDateTime upSince; int port, ssl; diff -Nru pgadmin3/src/schema/pgServer.cpp pgadmin3_1.4.svn20060522/src/schema/pgServer.cpp --- pgadmin3/src/schema/pgServer.cpp 2006-05-17 15:35:59.000000000 +0000 +++ pgadmin3_1.4.svn20060522/src/schema/pgServer.cpp 2006-05-23 13:52:30.000000000 +0000 @@ -651,6 +651,17 @@ delete set; } } + if (conn->BackendMinimumVersion(7, 5)) { + set=ExecuteSet(wxT("SHOW default_tablespace;")); + if (set && set->GetVal(wxT("default_tablespace")) != wxT("unset")) + { + iSetdefaultTablespace(set->GetVal(wxT("default_tablespace"))); + delete set; + } else { + iSetdefaultTablespace(wxT("pg_default")); + } + } + else iSetCreateRole(false);
---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org