int dlgView::Go(bool modal) { if (connection->BackendMinimumVersion(9, 1)) { seclabelPage->SetConnection(connection); seclabelPage->SetObject(view); this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgView::OnChange)); } else seclabelPage->Disable(); chkSecurityBarrier->Enable(connection->BackendMinimumVersion(9, 2)); if (view) { // edit mode cbSchema->Enable(connection->BackendMinimumVersion(8, 1)); oldDefinition = view->GetFormattedDefinition(); txtSqlBox->SetText(oldDefinition); chkSecurityBarrier->SetValue(view->GetSecurityBarrier() == wxT("true")); } else { // create mode } // Find, and disable the RULE ACL option if we're 8.2 if (connection->BackendMinimumVersion(8, 2)) { // Disable the checkbox if (!DisablePrivilege(wxT("RULE"))) { wxLogError(_("Failed to disable the RULE privilege checkbox!")); } } return dlgSecurityProperty::Go(modal); }
int dlgDatabase::Go(bool modal) { bool createDefPriv = false; wxString strDefPrivsOnTables, strDefPrivsOnSeqs, strDefPrivsOnFuncs, strDefPrivsOnTypes; if (connection->BackendMinimumVersion(9, 2)) { seclabelPage->SetConnection(connection); seclabelPage->SetObject(database); this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgDatabase::OnChange)); } else seclabelPage->Disable(); if (connection->BackendMinimumVersion(9, 0)) { cbVarUsername->Append(wxT("")); // AddUsers function of dlgDefaultSecurity has already been called. // Hence, calling dlgProperty::AddUsers instead of that. dlgProperty::AddUsers(cbVarUsername); } else cbVarUsername->Enable(false); if (connection->BackendMinimumVersion(8, 0)) { stPath->Hide(); txtPath->Hide(); } else { stTablespace->Hide(); 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") wxT(" FROM pg_settings WHERE context in ('user', 'superuser')")); else set = connection->ExecuteSet(wxT("SELECT name, 'string' as vartype, '' as min_val, '' as max_val FROM pg_settings")); if (set) { while (!set->Eof()) { cbVarname->Append(set->GetVal(0)); varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") + set->GetVal(wxT("min_val")) + wxT(" ") + set->GetVal(wxT("max_val"))); set->MoveNext(); } delete set; cbVarname->SetSelection(0); if (connection->BackendMinimumVersion(9, 0)) { cbVarUsername->SetSelection(0); } SetupVarEditor(0); } if (database) { // edit mode if (!connection->BackendMinimumVersion(7, 4)) txtName->Disable(); if (!connection->BackendMinimumVersion(8, 0)) cbOwner->Disable(); readOnly = !database->GetServer()->GetCreatePrivilege(); if (connection->BackendMinimumVersion(9, 0)) { createDefPriv = true; strDefPrivsOnTables = database->GetDefPrivsOnTables(); strDefPrivsOnSeqs = database->GetDefPrivsOnSequences(); strDefPrivsOnFuncs = database->GetDefPrivsOnFunctions(); } if (connection->BackendMinimumVersion(9, 2)) strDefPrivsOnTypes = database->GetDefPrivsOnTypes(); 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 += 3) { username = database->GetVariables().Item(i); varname = database->GetVariables().Item(i + 1); varvalue = database->GetVariables().Item(i + 2); lstVariables->AppendItem(0, username, varname, varvalue); } PrepareTablespace(cbTablespace, database->GetTablespaceOid()); if (connection->BackendMinimumVersion(8, 4)) cbTablespace->Enable(); else cbTablespace->Disable(); txtPath->SetValue(database->GetPath()); txtPath->Disable(); 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()); } else { // create mode if (!connection->BackendMinimumVersion(8, 2)) txtComment->Disable(); PrepareTablespace(cbTablespace); // Add the default tablespace cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0); cbTablespace->SetSelection(0); cbTemplate->Append(wxEmptyString); 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 { encStr = connection->ExecuteScalar( wxT("SELECT pg_encoding_to_char(") + NumToStr(encNo) + wxT(")")); if (pgConn::IsValidServerEncoding(encNo) && !encStr.IsEmpty()) cbEncoding->Append(encStr); encNo++; } while (!encStr.IsEmpty()); encStr = connection->ExecuteScalar(wxT("SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = 'template0'")); encNo = cbEncoding->FindString(encStr); if (encNo < 0) { encNo = cbEncoding->FindString(wxT("UNICODE")); if (encNo < 0) encNo = cbEncoding->FindString(wxT("UTF8")); } if (encNo >= 0) cbEncoding->SetSelection(encNo); } // Find, and disable the CONNECT ACL option if we're on pre 8.2 if (!connection->BackendMinimumVersion(8, 2)) { // Disable the checkbox if (!DisablePrivilege(wxT("CONNECT"))) { wxLogError(_("Failed to disable the CONNECT privilege checkbox!")); } } return dlgDefaultSecurityProperty::Go(modal, createDefPriv, strDefPrivsOnTables, strDefPrivsOnSeqs, strDefPrivsOnFuncs, strDefPrivsOnTypes); }
int dlgView::Go(bool modal) { if (connection->BackendMinimumVersion(9, 1)) { seclabelPage->SetConnection(connection); seclabelPage->SetObject(view); this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgView::OnChange)); } else seclabelPage->Disable(); chkSecurityBarrier->Enable(connection->BackendMinimumVersion(9, 2)); cbCheckOption->Enable(connection->BackendMinimumVersion(9, 4)); if (connection->BackendMinimumVersion(9, 3)) { PrepareTablespace(cboTablespace); } if (view) { // edit mode cbSchema->Enable(connection->BackendMinimumVersion(8, 1)); oldDefinition = view->GetFormattedDefinition(); txtSqlBox->SetText(oldDefinition); chkSecurityBarrier->SetValue(view->GetSecurityBarrier() == wxT("true")); if ((connection->BackendMinimumVersion(9, 3) && view)) { // If it is materialized view than edit it if (view->GetMaterializedView()) { // Checked the view as user is in edit materialized view mode chkMaterializedView->SetValue(true); // Disable the security barrier as user is editing the materailized view chkSecurityBarrier->Disable(); // Disable the check-option as user is editing the materailized view cbCheckOption->Disable(); // Disable the materialized view as user is editing it and not allowed to switch to other view chkMaterializedView->Disable(); if (view->GetTablespaceOid() != 0) cboTablespace->SetKey(view->GetTablespaceOid()); txtFillFactor->SetValue(view->GetFillFactor()); if (view->GetIsPopulated().Cmp(wxT("t")) == 0) chkMatViewWithData->SetValue(true); else chkMatViewWithData->SetValue(false); settingAutoVacuum = false; pgSetIterator avSet(connection, wxT("SELECT name, setting FROM pg_settings WHERE name like '%vacuum%' ORDER BY name")); while (avSet.RowsLeft()) { wxString name = avSet.GetVal(wxT("name")); wxString setting = avSet.GetVal(wxT("setting")); if (name == wxT("autovacuum_vacuum_cost_delay")) settingCostDelay = setting; else if (name == wxT("vacuum_cost_delay")) { if (StrToLong(settingCostDelay) < 0) settingCostDelay = setting; } else if (name == wxT("autovacuum_vacuum_cost_limit")) settingCostLimit = setting; else if (name == wxT("vacuum_cost_limit")) { if (StrToLong(settingCostLimit) < 0) settingCostLimit = setting; } else if (name == wxT("autovacuum_vacuum_scale_factor")) settingVacFactor = setting; else if (name == wxT("autovacuum_analyze_scale_factor")) settingAnlFactor = setting; else if (name == wxT("autovacuum_vacuum_threshold")) settingVacBaseThr = setting; else if (name == wxT("autovacuum_analyze_threshold")) settingAnlBaseThr = setting; else if (name == wxT("vacuum_freeze_min_age")) settingFreezeMinAge = setting; else if (name == wxT("autovacuum_freeze_max_age")) settingFreezeMaxAge = setting; else if (name == wxT("vacuum_freeze_table_age")) settingFreezeTableAge = setting; else settingAutoVacuum = avSet.GetBool(wxT("setting")); } tableVacBaseThr = wxT("-1"); tableAnlBaseThr = wxT("-1"); tableCostDelay = wxT("-1"); tableCostLimit = wxT("-1"); tableFreezeMinAge = wxT("-1"); tableFreezeMaxAge = wxT("-1"); tableVacFactor = wxT("-1"); tableAnlFactor = wxT("-1"); tableFreezeTableAge = wxT("-1"); toastTableVacBaseThr = wxT("-1"); toastTableCostDelay = wxT("-1"); toastTableCostLimit = wxT("-1"); toastTableFreezeMinAge = wxT("-1"); toastTableFreezeMaxAge = wxT("-1"); toastTableVacFactor = wxT("-1"); toastTableFreezeTableAge = wxT("-1"); toastTableHasVacuum = false; toastTableVacEnabled = false; if (view) { if (view->GetAutoVacuumEnabled() == 2) tableVacEnabled = settingAutoVacuum; else tableVacEnabled = view->GetAutoVacuumEnabled() == 1; if (!view->GetAutoVacuumVacuumThreshold().IsEmpty()) tableVacBaseThr = view->GetAutoVacuumVacuumThreshold(); if (!view->GetAutoVacuumAnalyzeThreshold().IsEmpty()) tableAnlBaseThr = view->GetAutoVacuumAnalyzeThreshold(); if (!view->GetAutoVacuumVacuumScaleFactor().IsEmpty()) tableVacFactor = view->GetAutoVacuumVacuumScaleFactor(); if (!view->GetAutoVacuumAnalyzeScaleFactor().IsEmpty()) tableAnlFactor = view->GetAutoVacuumAnalyzeScaleFactor(); if (!view->GetAutoVacuumVacuumCostDelay().IsEmpty()) tableCostDelay = view->GetAutoVacuumVacuumCostDelay(); if (!view->GetAutoVacuumVacuumCostLimit().IsEmpty()) tableCostLimit = view->GetAutoVacuumVacuumCostLimit(); if (!view->GetAutoVacuumFreezeMinAge().IsEmpty()) tableFreezeMinAge = view->GetAutoVacuumFreezeMinAge(); if (!view->GetAutoVacuumFreezeMaxAge().IsEmpty()) tableFreezeMaxAge = view->GetAutoVacuumFreezeMaxAge(); if (!view->GetAutoVacuumFreezeTableAge().IsEmpty()) tableFreezeTableAge = view->GetAutoVacuumFreezeTableAge(); hasVacuum = view->GetCustomAutoVacuumEnabled(); chkVacEnabled->SetValue(hasVacuum ? tableVacEnabled : settingAutoVacuum); toastTableVacEnabled = false; if (!view->GetHasToastTable()) { nbVaccum->GetPage(2)->Enable(false); } else { toastTableHasVacuum = view->GetToastCustomAutoVacuumEnabled(); if (toastTableHasVacuum) { if (view->GetToastAutoVacuumEnabled() == 2) toastTableVacEnabled = settingAutoVacuum; else toastTableVacEnabled = view->GetToastAutoVacuumEnabled() == 1; if (!view->GetToastAutoVacuumVacuumThreshold().IsEmpty()) toastTableVacBaseThr = view->GetToastAutoVacuumVacuumThreshold(); if (!view->GetToastAutoVacuumVacuumScaleFactor().IsEmpty()) toastTableVacFactor = view->GetToastAutoVacuumVacuumScaleFactor(); if (!view->GetToastAutoVacuumVacuumCostDelay().IsEmpty()) toastTableCostDelay = view->GetToastAutoVacuumVacuumCostDelay(); if (!view->GetToastAutoVacuumVacuumCostLimit().IsEmpty()) toastTableCostLimit = view->GetToastAutoVacuumVacuumCostLimit(); if (!view->GetToastAutoVacuumFreezeMinAge().IsEmpty()) toastTableFreezeMinAge = view->GetToastAutoVacuumFreezeMinAge(); if (!view->GetToastAutoVacuumFreezeMaxAge().IsEmpty()) toastTableFreezeMaxAge = view->GetToastAutoVacuumFreezeMaxAge(); if (!view->GetToastAutoVacuumFreezeTableAge().IsEmpty()) toastTableFreezeTableAge = view->GetToastAutoVacuumFreezeTableAge(); } chkToastVacEnabled->SetValue(toastTableHasVacuum ? toastTableVacEnabled : settingAutoVacuum); } } else { hasVacuum = false; chkVacEnabled->SetValue(settingAutoVacuum); } txtBaseVac->SetValue(tableVacBaseThr); txtBaseAn->SetValue(tableAnlBaseThr); txtFactorVac->SetValue(tableVacFactor); txtFactorAn->SetValue(tableAnlFactor); txtVacDelay->SetValue(tableCostDelay); txtVacLimit->SetValue(tableCostLimit); txtFreezeMinAge->SetValue(tableFreezeMinAge); txtFreezeMaxAge->SetValue(tableFreezeMaxAge); txtFreezeTableAge->SetValue(tableFreezeTableAge); txtBaseToastVac->SetValue(toastTableVacBaseThr); txtFactorToastVac->SetValue(toastTableVacFactor); txtToastVacDelay->SetValue(toastTableCostDelay); txtToastVacLimit->SetValue(toastTableCostLimit); txtToastFreezeMinAge->SetValue(toastTableFreezeMinAge); txtToastFreezeMaxAge->SetValue(toastTableFreezeMaxAge); txtToastFreezeTableAge->SetValue(toastTableFreezeTableAge); chkCustomToastVac->SetValue(toastTableHasVacuum); chkToastVacEnabled->SetValue(toastTableHasVacuum ? toastTableVacEnabled : settingAutoVacuum); chkCustomVac->SetValue(hasVacuum); wxCommandEvent ev; OnChangeVacuum(ev); } else { // It is not materialized view so disabling all the controls DisableMaterializedView(); } if (view->GetCheckOption().Cmp(wxT("cascaded")) == 0) cbCheckOption->SetSelection(2); else if (view->GetCheckOption().Cmp(wxT("local")) == 0) cbCheckOption->SetSelection(1); else cbCheckOption->SetSelection(0); } } else { // create mode cboTablespace->Insert(_("<default tablespace>"), 0, (void *)0); cboTablespace->SetSelection(0); cbCheckOption->SetSelection(0); wxCommandEvent ev; OnChangeVacuum(ev); } // Find, and disable the RULE ACL option if we're 8.2 if (connection->BackendMinimumVersion(8, 2)) { // Disable the checkbox if (!DisablePrivilege(wxT("RULE"))) { wxLogError(_("Failed to disable the RULE privilege checkbox!")); } } return dlgSecurityProperty::Go(modal); }
int dlgSequence::Go(bool modal) { if (connection->BackendMinimumVersion(9, 1)) { seclabelPage->SetConnection(connection); seclabelPage->SetObject(sequence); this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgSequence::OnChange)); } else seclabelPage->Disable(); if (sequence) { // edit mode txtIncrement->SetValue(sequence->GetIncrement().ToString()); txtStart->SetValue(sequence->GetLastValue().ToString()); txtMin->SetValue(sequence->GetMinValue().ToString()); txtMax->SetValue(sequence->GetMaxValue().ToString()); txtCache->SetValue(sequence->GetCacheValue().ToString()); chkCycled->SetValue(sequence->GetCycled()); stStart->SetLabel(_("Current value")); cbSchema->Enable(connection->BackendMinimumVersion(8, 1)); if (!connection->BackendMinimumVersion(7, 4)) { txtIncrement->Disable(); txtMin->Disable(); txtMax->Disable(); txtCache->Disable(); chkCycled->Disable(); } } else { // create mode txtIncrement->SetValidator(numericValidator); txtMin->SetValidator(numericValidator); txtMax->SetValidator(numericValidator); txtCache->SetValidator(numericValidator); } txtStart->SetValidator(numericValidator); // Find, and disable the USAGE ACL option if we're on pre 8.2 // 8.2+ only supports SELECT, UPDATE and USAGE if (!connection->BackendMinimumVersion(8, 2)) { // Disable the checkbox if (!DisablePrivilege(wxT("USAGE"))) { wxLogError(_("Failed to disable the USAGE privilege checkbox!")); } } else { if (!DisablePrivilege(wxT("INSERT"))) { wxLogError(_("Failed to disable the INSERT privilege checkbox!")); } if (!DisablePrivilege(wxT("DELETE"))) { wxLogError(_("Failed to disable the DELETE privilege checkbox!")); } if (!DisablePrivilege(wxT("RULE"))) { wxLogError(_("Failed to disable the RULE privilege checkbox!")); } if (!DisablePrivilege(wxT("REFERENCES"))) { wxLogError(_("Failed to disable the REFERENCES privilege checkbox!")); } if (!DisablePrivilege(wxT("TRIGGER"))) { wxLogError(_("Failed to disable the TRIGGER privilege checkbox!")); } } return dlgSecurityProperty::Go(modal); }