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 dlgIndex::Go(bool modal) { if (!connection->BackendMinimumVersion(7, 4)) chkClustered->Disable(); if (index) { // edit mode: view only // We only display the column options (ASC/DESC, NULLS FIRST/LAST) // on PostgreSQL 8.3+, for btree indexes. wxArrayString colsArr = index->GetColumnList(); wxString colDef, colRest, colName, descDef, nullsDef, opclassDef; const wxString firstOrder = wxT(" NULLS FIRST"), lastOrder = wxT(" NULLS LAST"), descOrder = wxT(" DESC"); if (this->database->BackendMinimumVersion(8, 3) && index->GetIndexType() == wxT("btree")) { for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++) { colDef = colsArr.Item(colIdx); if (colDef.EndsWith(firstOrder.GetData(), &colRest)) { colDef = colRest; nullsDef = wxT("FIRST"); } else if (colDef.EndsWith(lastOrder.GetData(), &colRest)) { colDef = colRest; nullsDef = wxT("LAST"); } else nullsDef = wxT(""); if (colDef.EndsWith(descOrder.GetData(), &colRest)) { colDef = colRest; descDef = wxT("DESC"); if (nullsDef.IsEmpty()) nullsDef = wxT("FIRST"); } else { descDef = wxT("ASC"); if (nullsDef.IsEmpty()) nullsDef = wxT("LAST"); } int pos = colDef.First(wxT(" ")); if (pos > 0) { opclassDef = colDef.Mid(pos + 1); colDef = colDef.Mid(0, pos - 1); } else opclassDef = wxEmptyString; lstColumns->InsertItem(colIdx, colDef, columnFactory.GetIconId()); lstColumns->SetItem(colIdx, 1, descDef); lstColumns->SetItem(colIdx, 2, nullsDef); lstColumns->SetItem(colIdx, 3, opclassDef); } } else { for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++) { int pos = colDef.First(wxT(" ")); if (pos > 0) { colDef = colRest; opclassDef = colDef.Mid(pos + 1); colDef = colDef.Mid(0, pos - 1); } else opclassDef = wxEmptyString; lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId()); lstColumns->SetItem(colIdx, 3, cbOpClass->GetValue()); } } cbType->Append(index->GetIndexType()); chkUnique->SetValue(index->GetIsUnique()); chkClustered->SetValue(index->GetIsClustered()); txtWhere->SetValue(index->GetConstraint()); cbType->SetSelection(0); cbType->Disable(); txtWhere->Disable(); chkUnique->Disable(); chkConcurrent->Disable(); PrepareTablespace(cbTablespace, index->GetTablespaceOid()); cbOpClass->Disable(); chkDesc->Disable(); rdbNullsFirst->Disable(); rdbNullsLast->Disable(); } else { // create mode PrepareTablespace(cbTablespace); cbType->Append(wxT("")); pgSet *set=connection->ExecuteSet(wxT( "SELECT oid, amname FROM pg_am")); if (set) { while (!set->Eof()) { cbType->Append(set->GetVal(1), set->GetVal(0)); set->MoveNext(); } delete set; } if (!this->database->BackendMinimumVersion(8, 2)) chkConcurrent->Disable(); if (!this->database->BackendMinimumVersion(8, 3)) { chkDesc->Disable(); rdbNullsFirst->Disable(); rdbNullsLast->Disable(); } // Add the default tablespace cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0); cbTablespace->SetSelection(0); } int returnCode = dlgIndexBase::Go(modal); if (index && connection->BackendMinimumVersion(8, 0)) txtName->Enable(true); // This fixes a UI glitch on MacOS X // Because of the new layout code, the Columns pane doesn't size itself properly SetSize(GetSize().GetWidth()+1, GetSize().GetHeight()); SetSize(GetSize().GetWidth()-1, GetSize().GetHeight()); return returnCode; }
int dlgIndex::Go(bool modal) { if (!connection->BackendMinimumVersion(7, 4)) chkClustered->Disable(); if (index) { // edit mode: view only // We only display the column options (ASC/DESC, NULLS FIRST/LAST) // on PostgreSQL 8.3+, for btree indexes. wxArrayString colsArr = index->GetColumnList(); wxArrayString collationsArray = index->GetCollationsArray(); wxString colDef, descDef, nullsDef, opclassDef; if (this->database->BackendMinimumVersion(8, 3) && index->GetIndexType() == wxT("btree")) { for (unsigned int colIdx = 0, colsCount = colsArr.Count(); colIdx < colsCount; colIdx++) { colDef = colsArr.Item(colIdx); descDef = index->GetOrdersArray().Item(colIdx); nullsDef = index->GetNullsArray().Item(colIdx); opclassDef = index->GetOpClassesArray().Item(colIdx); lstColumns->InsertItem(colIdx, colDef, columnFactory.GetIconId()); lstColumns->SetItem(colIdx, 1, descDef); lstColumns->SetItem(colIdx, 2, nullsDef); lstColumns->SetItem(colIdx, 3, opclassDef); if (colIdx < collationsArray.Count()) lstColumns->SetItem(colIdx, 4, collationsArray.Item(colIdx)); } } else { for (unsigned int colIdx = 0, colsCount = colsArr.Count(); colIdx < colsCount; colIdx++) { int pos = colDef.First(wxT(" ")); if (pos > 0) { opclassDef = colDef.Mid(pos + 1); colDef = colDef.Mid(0, pos); } else opclassDef = wxEmptyString; lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId()); lstColumns->SetItem(colIdx, 3, cbOpClass->GetValue()); if (colIdx < collationsArray.Count()) lstColumns->SetItem(colIdx, 4, collationsArray.Item(colIdx)); } } cbType->Append(index->GetIndexType()); chkUnique->SetValue(index->GetIsUnique()); chkClustered->SetValue(index->GetIsClustered()); txtWhere->SetValue(index->GetConstraint()); cbType->SetSelection(0); cbType->Disable(); txtWhere->Disable(); chkUnique->Disable(); chkConcurrent->Disable(); PrepareTablespace(cbTablespace, index->GetTablespaceOid()); cbOpClass->Disable(); chkDesc->Disable(); rdbNullsFirst->Disable(); rdbNullsLast->Disable(); cbCollation->Disable(); lstColumns->Disable(); } else { // create mode PrepareTablespace(cbTablespace); cbType->Append(wxT("")); pgSet *set = connection->ExecuteSet(wxT( "SELECT oid, amname FROM pg_am")); if (set) { while (!set->Eof()) { cbType->Append(set->GetVal(1), set->GetVal(0)); set->MoveNext(); } delete set; } if (connection->BackendMinimumVersion(9, 1)) { // fill collation combobox cbCollation->Append(wxEmptyString); set = connection->ExecuteSet( wxT("SELECT nspname, collname\n") wxT(" FROM pg_collation c, pg_namespace n\n") wxT(" WHERE c.collnamespace=n.oid\n") wxT(" ORDER BY nspname, collname")); if (set) { while (!set->Eof()) { wxString name = qtIdent(set->GetVal(wxT("nspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname"))); cbCollation->Append(name); set->MoveNext(); } delete set; } cbCollation->SetSelection(0); } else cbCollation->Disable(); if (!this->database->BackendMinimumVersion(8, 2)) chkConcurrent->Disable(); if (!this->database->BackendMinimumVersion(8, 3)) { chkDesc->Disable(); rdbNullsFirst->Disable(); rdbNullsLast->Disable(); } // Add the default tablespace cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0); cbTablespace->SetSelection(0); } // Reset the labels as the XRC defined values will have been localised :-( rdbNullsFirst->SetLabel(wxT("FIRST")); rdbNullsLast->SetLabel(wxT("LAST")); int returnCode = dlgIndexBase::Go(modal); if (index && connection->BackendMinimumVersion(8, 0)) txtName->Enable(true); // This fixes a UI glitch on MacOS X // Because of the new layout code, the Columns pane doesn't size itself properly SetSize(GetSize().GetWidth() + 1, GetSize().GetHeight()); SetSize(GetSize().GetWidth() - 1, GetSize().GetHeight()); return returnCode; }
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 dlgIndexConstraint::Go(bool modal) { pgSet *set; PrepareTablespace(cbTablespace); if (wxString(factory->GetTypeName()).Upper() == wxT("EXCLUDE")) { cbIndex->Disable(); } else { cbIndex->Enable(connection->BackendMinimumVersion(9, 1)); cbType->Disable(); txtWhere->Disable(); cbOpClass->Disable(); chkDesc->Disable(); rdbNullsFirst->Disable(); rdbNullsLast->Disable(); cbOperator->Disable(); } if (index) { pgIndexConstraint *idc = (pgIndexConstraint *)index; // We only display the column options (ASC/DESC, NULLS FIRST/LAST) // on exclude constraints with btree wxArrayString colsArr = index->GetColumnList(); wxString colDef, colRest, colName, descDef, nullsDef, opclassDef, withDef; const wxString firstOrder = wxT(" NULLS FIRST"), lastOrder = wxT(" NULLS LAST"); const wxString descOrder = wxT(" DESC"); if (wxString(factory->GetTypeName()).Upper() == wxT("EXCLUDE") && index->GetIndexType() == wxT("btree")) { for (int colIdx = 0, colsCount = colsArr.Count(); colIdx < colsCount; colIdx++) { colDef = colsArr.Item(colIdx); int withStartPoint = colDef.Find(wxT(" WITH ")); if (withStartPoint > 0) { withDef = colDef.Mid(withStartPoint + 6, colDef.Length() - withStartPoint - 6); colDef = colDef.Mid(0, withStartPoint); } else withDef = wxT(""); if (colDef.EndsWith(firstOrder.GetData(), &colRest)) { colDef = colRest; nullsDef = wxT("FIRST"); } else if (colDef.EndsWith(lastOrder.GetData(), &colRest)) { colDef = colRest; nullsDef = wxT("LAST"); } else nullsDef = wxT(""); if (colDef.EndsWith(descOrder.GetData(), &colRest)) { colDef = colRest; descDef = wxT("DESC"); if (nullsDef.IsEmpty()) nullsDef = wxT("FIRST"); } else { descDef = wxT("ASC"); if (nullsDef.IsEmpty()) nullsDef = wxT("LAST"); } int pos = colDef.First(wxT(" ")); if (pos > 0) { opclassDef = colDef.Mid(pos + 1); colDef = colDef.Mid(0, pos - 1); } else opclassDef = wxEmptyString; lstColumns->InsertItem(colIdx, colDef, columnFactory.GetIconId()); lstColumns->SetItem(colIdx, 1, descDef); lstColumns->SetItem(colIdx, 2, nullsDef); lstColumns->SetItem(colIdx, 3, opclassDef); lstColumns->SetItem(colIdx, 4, withDef); } } else { for (int colIdx = 0, colsCount = colsArr.Count(); colIdx < colsCount; colIdx++) { colDef = colsArr.Item(colIdx); int withStartPoint = colDef.Find(wxT(" WITH ")); if (withStartPoint > 0) { withDef = colDef.Mid(withStartPoint + 6, colDef.Length() - withStartPoint - 6); colDef = colDef.Mid(0, withStartPoint); } else withDef = wxT(""); int pos = colDef.First(wxT(" ")); if (pos > 0) { colDef = colRest; opclassDef = colDef.Mid(pos + 1); colDef = colDef.Mid(0, pos - 1); } else opclassDef = wxEmptyString; lstColumns->InsertItem(colIdx, colDef, columnFactory.GetIconId()); lstColumns->SetItem(colIdx, 3, cbOpClass->GetValue()); lstColumns->SetItem(colIdx, 4, withDef); } } if (idc->GetTablespaceOid() != 0) cbTablespace->SetKey(idc->GetTablespaceOid()); cbTablespace->Enable(connection->BackendMinimumVersion(8, 0)); if (txtFillFactor) { txtFillFactor->SetValue(idc->GetFillFactor()); } if (index->GetIndexType().Length() > 0) { cbType->Append(index->GetIndexType()); cbType->SetSelection(0); cbType->Disable(); } chkDeferrable->SetValue(index->GetDeferrable()); chkDeferred->SetValue(index->GetDeferred()); chkDeferrable->Enable(false); chkDeferred->Enable(false); } else { txtComment->Disable(); if (!table) { cbClusterSet->Disable(); cbClusterSet = 0; } // Add the indexes if (table) { cbIndex->Append(wxT("")); set = connection->ExecuteSet( wxT("SELECT relname FROM pg_class, pg_index WHERE pg_class.oid=indexrelid AND indrelid=") + table->GetOidStr()); if (set) { while (!set->Eof()) { cbIndex->Append(set->GetVal(0)); set->MoveNext(); } delete set; } } else { cbIndex->Disable(); } // Add the default tablespace cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0); cbTablespace->SetSelection(0); cbType->Append(wxT("")); set = connection->ExecuteSet( wxT("SELECT oid, amname FROM pg_am ") wxT("WHERE EXISTS (SELECT 1 FROM pg_proc WHERE oid=amgettuple) ") wxT("ORDER BY amname")); if (set) { while (!set->Eof()) { cbType->Append(set->GetVal(1), set->GetVal(0)); set->MoveNext(); } delete set; } chkDeferrable->Enable(connection->BackendMinimumVersion(9, 0)); chkDeferred->Enable(connection->BackendMinimumVersion(9, 0)); } txtFillFactor->SetValidator(numericValidator); if (connection->BackendMinimumVersion(8, 2)) txtFillFactor->Enable(); else txtFillFactor->Disable(); return dlgIndexBase::Go(modal); }