bool ParticleChannelInt::Append(IObject* channel) { IParticleChannelAmountR* iAmount = GetParticleChannelAmountRInterface(channel); DbgAssert(iAmount); if (iAmount == NULL) return false; int num = iAmount->Count(); if (num <= 0) return true; IParticleChannelIntR* iInt = (IParticleChannelIntR*)(channel->GetInterface(GetReadID())); DbgAssert(iInt); if (iInt == NULL) return false; int oldCount = Count(); if (!AppendNum(num)) return false; for(int i=0; i<num; i++) SetValue(oldCount + i, iInt->GetValue(i)); return true; }
wxString dlgView::GetSql() { wxString sql; wxString name; wxString withoptions = wxEmptyString; bool editQuery = false; if (view) { // edit mode name = GetName(); if (name != view->GetName()) { if (connection->BackendMinimumVersion(8, 3)) { if (connection->BackendMinimumVersion(9, 3)) { if (view->GetMaterializedView()) { AppendNameChange(sql, wxT("MATERIALIZED VIEW ") + view->GetQuotedFullIdentifier()); editQuery = true; } else AppendNameChange(sql, wxT("VIEW ") + view->GetQuotedFullIdentifier()); } else AppendNameChange(sql, wxT("VIEW ") + view->GetQuotedFullIdentifier()); } else AppendNameChange(sql, wxT("TABLE ") + view->GetQuotedFullIdentifier()); } if (connection->BackendMinimumVersion(8, 4) && cbSchema->GetName() != view->GetSchema()->GetName()) { if (connection->BackendMinimumVersion(9, 3)) { if (view->GetMaterializedView()) { AppendSchemaChange(sql, wxT("MATERIALIZED VIEW " + qtIdent(view->GetSchema()->GetName()) + wxT(".") + qtIdent(name))); editQuery = true; } else AppendSchemaChange(sql, wxT("VIEW " + qtIdent(view->GetSchema()->GetName()) + wxT(".") + qtIdent(name))); } else AppendSchemaChange(sql, wxT("VIEW " + qtIdent(view->GetSchema()->GetName()) + wxT(".") + qtIdent(name))); } else AppendSchemaChange(sql, wxT("TABLE " + qtIdent(view->GetSchema()->GetName()) + wxT(".") + qtIdent(name))); } name = qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName()); if (!view || txtSqlBox->GetText().Trim(true).Trim(false) != oldDefinition.Trim(true).Trim(false)) { if (editQuery) { // Delete the materialized view query sql += wxT("DROP MATERIALIZED VIEW ") + name + wxT(";"); } // Check if user creates the materialized view if (!chkMaterializedView->GetValue()) { sql += wxT("CREATE OR REPLACE VIEW ") + name; if (connection->BackendMinimumVersion(9, 2) && chkSecurityBarrier->GetValue()) withoptions += wxT("security_barrier=true"); if (connection->BackendMinimumVersion(9, 4) && cbCheckOption->GetSelection() > 0) { if (withoptions.Length() > 0) withoptions += wxT(", "); withoptions += wxT("check_option=") + cbCheckOption->GetValue().Lower(); } if (withoptions.Length() > 0) sql += wxT(" WITH (") + withoptions + wxT(")"); sql += wxT(" AS\n") + txtSqlBox->GetText().Trim(true).Trim(false) + wxT(";\n"); } else if (connection->BackendMinimumVersion(9, 3) && chkMaterializedView->GetValue()) { sql += wxT("CREATE MATERIALIZED VIEW ") + name; // Add the parameter of tablespace and storage parameter to create the materilized view if (txtFillFactor->GetValue().Trim().Length() > 0 || chkVacEnabled->GetValue() == true || chkToastVacEnabled->GetValue() == true) { bool fillFactorFlag, toastTableFlag; fillFactorFlag = false; toastTableFlag = false; sql += wxT("\nWITH ("); if (txtFillFactor->GetValue().Trim().Length() > 0) { sql += wxT("\n FILLFACTOR = ") + txtFillFactor->GetValue(); fillFactorFlag = true; } bool valChanged = false; wxString newVal; wxString resetStr; if (connection->BackendMinimumVersion(9, 3) && chkCustomVac->GetValue()) { FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_enabled"), BoolToStr(chkVacEnabled->GetValue())); if (!fillFactorFlag) { int position = sql.Find(',', true); if (position != wxNOT_FOUND) sql.Remove(position, 1); toastTableFlag = true; } newVal = AppendNum(valChanged, txtBaseVac, tableVacBaseThr); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_vacuum_threshold"), newVal); } newVal = AppendNum(valChanged, txtBaseAn, tableAnlBaseThr); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_analyze_threshold"), newVal); } newVal = AppendNum(valChanged, txtFactorVac, tableVacFactor); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_vacuum_scale_factor"), newVal); } newVal = AppendNum(valChanged, txtFactorAn, tableAnlFactor); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_analyze_scale_factor"), newVal); } newVal = AppendNum(valChanged, txtVacDelay, tableCostDelay); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_vacuum_cost_delay"), newVal); } newVal = AppendNum(valChanged, txtVacLimit, tableCostLimit); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_vacuum_cost_limit"), newVal); } newVal = AppendNum(valChanged, txtFreezeMinAge, tableFreezeMinAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_freeze_min_age"), newVal); } newVal = AppendNum(valChanged, txtFreezeMaxAge, tableFreezeMaxAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_freeze_max_age"), newVal); } newVal = AppendNum(valChanged, txtFreezeTableAge, tableFreezeTableAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("autovacuum_freeze_table_age"), newVal); } } if (connection->BackendMinimumVersion(9, 3) && chkCustomToastVac->GetValue()) { FillAutoVacuumParameters(sql, resetStr, wxT("toast.autovacuum_enabled"), BoolToStr(chkToastVacEnabled->GetValue())); if (!fillFactorFlag && !toastTableFlag) { int position = sql.Find(',', true); if (position != wxNOT_FOUND) sql.Remove(position, 1); } newVal = AppendNum(valChanged, txtBaseToastVac, toastTableVacBaseThr); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("toast.autovacuum_vacuum_threshold"), newVal); } newVal = AppendNum(valChanged, txtFactorToastVac, toastTableVacFactor); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("toast.autovacuum_vacuum_scale_factor"), newVal); } newVal = AppendNum(valChanged, txtToastVacDelay, toastTableCostDelay); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("toast.autovacuum_vacuum_cost_delay"), newVal); } newVal = AppendNum(valChanged, txtToastVacLimit, toastTableCostLimit); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("toast.autovacuum_vacuum_cost_limit"), newVal); } newVal = AppendNum(valChanged, txtToastFreezeMinAge, toastTableFreezeMinAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("toast.autovacuum_freeze_min_age"), newVal); } newVal = AppendNum(valChanged, txtToastFreezeMaxAge, toastTableFreezeMaxAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("toast.autovacuum_freeze_max_age"), newVal); } newVal = AppendNum(valChanged, txtToastFreezeTableAge, toastTableFreezeTableAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(sql, resetStr, wxT("toast.autovacuum_freeze_table_age"), newVal); } } sql += wxT("\n)\n"); } if (cboTablespace->GetCurrentSelection() > 0 && cboTablespace->GetOIDKey() > 0) sql += wxT("\nTABLESPACE ") + qtIdent(cboTablespace->GetValue()); wxString sqlDefinition; bool tmpLoopFlag = true; sqlDefinition = txtSqlBox->GetText().Trim(true).Trim(false); // Remove semicolon from the end of the string while(tmpLoopFlag) { int length = sqlDefinition.Len(); int position = sqlDefinition.Find(';', true); if ((position != wxNOT_FOUND) && (position = (length - 1))) sqlDefinition.Remove(position, 1); else tmpLoopFlag = false; } sql += wxT(" AS\n") + sqlDefinition; if (chkMatViewWithData->GetValue()) sql += wxT("\n WITH DATA;\n"); else sql += wxT("\n WITH NO DATA;\n"); } } else if (view) { if (!chkMaterializedView->GetValue()) { if (connection->BackendMinimumVersion(9, 2)) { if (chkSecurityBarrier->GetValue() && view->GetSecurityBarrier() != wxT("true")) sql += wxT("ALTER VIEW ") + name + wxT("\n SET (security_barrier=true);\n"); else if (!chkSecurityBarrier->GetValue() && view->GetSecurityBarrier() == wxT("true")) sql += wxT("ALTER VIEW ") + name + wxT("\n SET (security_barrier=false);\n"); } if (connection->BackendMinimumVersion(9, 4) && cbCheckOption->GetValue().Lower().Cmp(view->GetCheckOption()) != 0) { if (cbCheckOption->GetValue().Cmp(wxT("No")) == 0) sql += wxT("ALTER VIEW ") + name + wxT(" RESET (check_option);\n"); else sql += wxT("ALTER VIEW ") + name + wxT("\n SET (check_option=") + cbCheckOption->GetValue().Lower() + wxT(");\n"); } if (withoptions.Length() > 0) sql += wxT(" WITH (") + withoptions + wxT(")"); } else if (connection->BackendMinimumVersion(9, 3) && chkMaterializedView->GetValue()) { if (txtFillFactor->GetValue() != view->GetFillFactor()) { // If fill factor value get changed then set the new value if (txtFillFactor->GetValue().Trim().Length() > 0) { sql += wxT("ALTER MATERIALIZED VIEW ") + name + wxT("\n SET (FILLFACTOR=") + txtFillFactor->GetValue() + wxT(");\n"); } else { // If fill factor value get changed and value is not blank then do the reset sql += wxT("ALTER MATERIALIZED VIEW ") + name + wxT(" RESET(\n") wxT(" FILLFACTOR\n") wxT(");\n"); } } bool isPopulatedFlag = false; if (view->GetIsPopulated().Cmp(wxT("t")) == 0) isPopulatedFlag = true; if (chkMatViewWithData->GetValue() != isPopulatedFlag) { // If checkbox is checked then set WITH NO DATA if (isPopulatedFlag) { sql += wxT("REFRESH MATERIALIZED VIEW ") + name + wxT(" WITH NO DATA;\n"); } else { sql += wxT("REFRESH MATERIALIZED VIEW ") + name + wxT(" WITH DATA;\n"); } } // Altered the storage parameters for the materialized view? if (!chkCustomVac->GetValue()) { if (hasVacuum) { sql += wxT("ALTER MATERIALIZED VIEW ") + name + wxT(" RESET(\n") wxT(" autovacuum_enabled,\n") wxT(" autovacuum_vacuum_threshold,\n") wxT(" autovacuum_analyze_threshold,\n") wxT(" autovacuum_vacuum_scale_factor,\n") wxT(" autovacuum_analyze_scale_factor,\n") wxT(" autovacuum_vacuum_cost_delay,\n") wxT(" autovacuum_vacuum_cost_limit,\n") wxT(" autovacuum_freeze_min_age,\n") wxT(" autovacuum_freeze_max_age,\n") wxT(" autovacuum_freeze_table_age\n") wxT(");\n"); } } else { wxString vacStr; bool changed = (chkVacEnabled->GetValue() != tableVacEnabled); bool valChanged = false; wxString newVal; wxString setStr; wxString resetStr; if (changed) { FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_enabled"), BoolToStr(chkVacEnabled->GetValue())); } newVal = AppendNum(valChanged, txtBaseVac, tableVacBaseThr); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_vacuum_threshold"), newVal); } newVal = AppendNum(valChanged, txtBaseAn, tableAnlBaseThr); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_analyze_threshold"), newVal); } newVal = AppendNum(valChanged, txtFactorVac, tableVacFactor); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_vacuum_scale_factor"), newVal); } newVal = AppendNum(valChanged, txtFactorAn, tableAnlFactor); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_analyze_scale_factor"), newVal); } newVal = AppendNum(valChanged, txtVacDelay, tableCostDelay); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_vacuum_cost_delay"), newVal); } newVal = AppendNum(valChanged, txtVacLimit, tableCostLimit); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_vacuum_cost_limit"), newVal); } newVal = AppendNum(valChanged, txtFreezeMinAge, tableFreezeMinAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_freeze_min_age"), newVal); } newVal = AppendNum(valChanged, txtFreezeMaxAge, tableFreezeMaxAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_freeze_max_age"), newVal); } newVal = AppendNum(valChanged, txtFreezeTableAge, tableFreezeTableAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("autovacuum_freeze_table_age"), newVal); } if (!setStr.IsEmpty()) { vacStr = wxT("ALTER MATERIALIZED VIEW ") + name + setStr + wxT("\n);\n");; changed = true; } if (!resetStr.IsEmpty()) { vacStr += wxT("ALTER MATERIALIZED VIEW ") + name + resetStr + wxT("\n);\n");; changed = true; } if (changed) sql += vacStr; } if (!chkCustomToastVac->GetValue()) { if (toastTableHasVacuum) { sql += wxT("ALTER MATERIALIZED VIEW ") + name + wxT(" RESET(\n") wxT(" toast.autovacuum_enabled,\n") wxT(" toast.autovacuum_vacuum_threshold,\n") wxT(" toast.autovacuum_analyze_threshold,\n") wxT(" toast.autovacuum_vacuum_scale_factor,\n") wxT(" toast.autovacuum_analyze_scale_factor,\n") wxT(" toast.autovacuum_vacuum_cost_delay,\n") wxT(" toast.autovacuum_vacuum_cost_limit,\n") wxT(" toast.autovacuum_freeze_min_age,\n") wxT(" toast.autovacuum_freeze_max_age,\n") wxT(" toast.autovacuum_freeze_table_age\n") wxT(");\n"); } } else { wxString vacStr; bool changed = (chkToastVacEnabled->GetValue() != toastTableVacEnabled); bool valChanged = false; wxString newVal; wxString setStr; wxString resetStr; if (changed) { FillAutoVacuumParameters(setStr, resetStr, wxT("toast.autovacuum_enabled"), BoolToStr(chkToastVacEnabled->GetValue())); } newVal = AppendNum(valChanged, txtBaseToastVac, toastTableVacBaseThr); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("toast.autovacuum_vacuum_threshold"), newVal); } newVal = AppendNum(valChanged, txtFactorToastVac, toastTableVacFactor); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("toast.autovacuum_vacuum_scale_factor"), newVal); } newVal = AppendNum(valChanged, txtToastVacDelay, toastTableCostDelay); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("toast.autovacuum_vacuum_cost_delay"), newVal); } newVal = AppendNum(valChanged, txtToastVacLimit, toastTableCostLimit); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("toast.autovacuum_vacuum_cost_limit"), newVal); } newVal = AppendNum(valChanged, txtToastFreezeMinAge, toastTableFreezeMinAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("toast.autovacuum_freeze_min_age"), newVal); } newVal = AppendNum(valChanged, txtToastFreezeMaxAge, toastTableFreezeMaxAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("toast.autovacuum_freeze_max_age"), newVal); } newVal = AppendNum(valChanged, txtToastFreezeTableAge, toastTableFreezeTableAge); if (valChanged) { valChanged = false; FillAutoVacuumParameters(setStr, resetStr, wxT("toast.autovacuum_freeze_table_age"), newVal); } if (!setStr.IsEmpty()) { vacStr = wxT("ALTER MATERIALIZED VIEW ") + name + setStr + wxT("\n);\n"); changed = true; } if (!resetStr.IsEmpty()) { vacStr += wxT("ALTER MATERIALIZED VIEW ") + name + resetStr + wxT("\n);\n"); changed = true; } if (changed) sql += vacStr; } if (cboTablespace->GetOIDKey() != view->GetTablespaceOid()) { sql += wxT("ALTER MATERIALIZED VIEW ") + name + wxT("\n SET TABLESPACE ") + qtIdent(cboTablespace->GetValue()) + wxT(";\n"); } } } if (view) AppendOwnerChange(sql, wxT("TABLE ") + qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName())); else AppendOwnerNew(sql, wxT("TABLE ") + qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName())); sql += GetGrant(wxT("arwdRxt"), wxT("TABLE ") + qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName())); if (connection->BackendMinimumVersion(9, 3) && chkMaterializedView->GetValue()) AppendComment(sql, wxT("MATERIALIZED VIEW ") + qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName()), view); else AppendComment(sql, wxT("VIEW ") + qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName()), view); if (seclabelPage && connection->BackendMinimumVersion(9, 1)) sql += seclabelPage->GetSqlForSecLabels(wxT("VIEW"), qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName())); return sql; }