67
67
#define TXTOBJ_LIB wxT("$libdir/")
69
69
BEGIN_EVENT_TABLE(dlgFunction, dlgSecurityProperty)
70
EVT_TEXT(XRCID("cbVolatility"), dlgProperty::OnChange)
71
EVT_CHECKBOX(XRCID("chkStrict"), dlgProperty::OnChange)
72
EVT_CHECKBOX(XRCID("chkSecureDefiner"), dlgProperty::OnChange)
73
EVT_TEXT(XRCID("txtObjectFile"), dlgProperty::OnChange)
74
EVT_TEXT(XRCID("txtLinkSymbol"), dlgProperty::OnChange)
75
EVT_TEXT(XRCID("txtCost"), dlgProperty::OnChange)
76
EVT_TEXT(XRCID("txtRows"), dlgProperty::OnChange)
77
EVT_STC_MODIFIED(XRCID("txtSqlBox"), dlgProperty::OnChangeStc)
79
EVT_CHECKBOX(XRCID("chkSetof"), dlgFunction::OnChangeSetof)
80
EVT_TEXT(XRCID("cbReturntype"), dlgFunction::OnChangeReturn)
81
EVT_COMBOBOX(XRCID("cbReturntype"), dlgFunction::OnChangeReturn)
82
EVT_TEXT(XRCID("cbDatatype"), dlgFunction::OnSelChangeType)
83
EVT_COMBOBOX(XRCID("cbDatatype"), dlgFunction::OnSelChangeType)
84
EVT_TEXT(XRCID("cbLanguage"), dlgFunction::OnSelChangeLanguage)
85
EVT_COMBOBOX(XRCID("cbLanguage"), dlgFunction::OnSelChangeLanguage)
87
EVT_LIST_ITEM_SELECTED(XRCID("lstArguments"), dlgFunction::OnSelChangeArg)
88
EVT_TEXT(XRCID("txtArgName"), dlgFunction::OnChangeArgName)
89
EVT_BUTTON(wxID_ADD, dlgFunction::OnAddArg)
90
EVT_BUTTON(XRCID("wxID_CHANGE"), dlgFunction::OnChangeArg)
91
EVT_BUTTON(wxID_REMOVE, dlgFunction::OnRemoveArg)
93
EVT_LIST_ITEM_SELECTED(XRCID("lstVariables"), dlgFunction::OnVarSelChange)
94
EVT_BUTTON(XRCID("btnAddVar"), dlgFunction::OnVarAdd)
95
EVT_BUTTON(XRCID("btnRemoveVar"), dlgFunction::OnVarRemove)
96
EVT_TEXT(XRCID("cbVarname"), dlgFunction::OnVarnameSelChange)
97
EVT_COMBOBOX(XRCID("cbVarname"), dlgFunction::OnVarnameSelChange)
98
EVT_RADIOBUTTON(XRCID("rdbIn"), dlgFunction::OnChangeArgMode)
99
EVT_RADIOBUTTON(XRCID("rdbOut"), dlgFunction::OnChangeArgMode)
100
EVT_RADIOBUTTON(XRCID("rdbInOut"), dlgFunction::OnChangeArgMode)
101
EVT_RADIOBUTTON(XRCID("rdbVariadic"), dlgFunction::OnChangeArgMode)
102
EVT_CHECKBOX(XRCID("chkWindow"), dlgFunction::OnChangeWindow)
70
EVT_TEXT(XRCID("cbVolatility"), dlgProperty::OnChange)
71
EVT_CHECKBOX(XRCID("chkStrict"), dlgProperty::OnChange)
72
EVT_CHECKBOX(XRCID("chkSecureDefiner"), dlgProperty::OnChange)
73
EVT_TEXT(XRCID("txtObjectFile"), dlgProperty::OnChange)
74
EVT_TEXT(XRCID("txtLinkSymbol"), dlgProperty::OnChange)
75
EVT_TEXT(XRCID("txtCost"), dlgProperty::OnChange)
76
EVT_TEXT(XRCID("txtRows"), dlgProperty::OnChange)
77
EVT_STC_MODIFIED(XRCID("txtSqlBox"), dlgProperty::OnChangeStc)
79
EVT_CHECKBOX(XRCID("chkSetof"), dlgFunction::OnChangeSetof)
80
EVT_TEXT(XRCID("cbReturntype"), dlgFunction::OnChangeReturn)
81
EVT_COMBOBOX(XRCID("cbReturntype"), dlgFunction::OnChangeReturn)
82
EVT_TEXT(XRCID("cbDatatype"), dlgFunction::OnSelChangeType)
83
EVT_COMBOBOX(XRCID("cbDatatype"), dlgFunction::OnSelChangeType)
84
EVT_TEXT(XRCID("cbLanguage"), dlgFunction::OnSelChangeLanguage)
85
EVT_COMBOBOX(XRCID("cbLanguage"), dlgFunction::OnSelChangeLanguage)
87
EVT_LIST_ITEM_SELECTED(XRCID("lstArguments"), dlgFunction::OnSelChangeArg)
88
EVT_TEXT(XRCID("txtArgName"), dlgFunction::OnChangeArgName)
89
EVT_BUTTON(wxID_ADD, dlgFunction::OnAddArg)
90
EVT_BUTTON(XRCID("wxID_CHANGE"), dlgFunction::OnChangeArg)
91
EVT_BUTTON(wxID_REMOVE, dlgFunction::OnRemoveArg)
93
EVT_LIST_ITEM_SELECTED(XRCID("lstVariables"), dlgFunction::OnVarSelChange)
94
EVT_BUTTON(XRCID("btnAddVar"), dlgFunction::OnVarAdd)
95
EVT_BUTTON(XRCID("btnRemoveVar"), dlgFunction::OnVarRemove)
96
EVT_TEXT(XRCID("cbVarname"), dlgFunction::OnVarnameSelChange)
97
EVT_COMBOBOX(XRCID("cbVarname"), dlgFunction::OnVarnameSelChange)
98
EVT_RADIOBUTTON(XRCID("rdbIn"), dlgFunction::OnChangeArgMode)
99
EVT_RADIOBUTTON(XRCID("rdbOut"), dlgFunction::OnChangeArgMode)
100
EVT_RADIOBUTTON(XRCID("rdbInOut"), dlgFunction::OnChangeArgMode)
101
EVT_RADIOBUTTON(XRCID("rdbVariadic"), dlgFunction::OnChangeArgMode)
102
EVT_CHECKBOX(XRCID("chkWindow"), dlgFunction::OnChangeWindow)
104
EVT_SIZE( dlgFunction::OnChangeSize)
104
EVT_SIZE( dlgFunction::OnChangeSize)
106
EVT_BUTTON(wxID_APPLY, dlgFunction::OnApply)
106
EVT_BUTTON(wxID_APPLY, dlgFunction::OnApply)
107
107
END_EVENT_TABLE();
110
110
dlgProperty *pgFunctionFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
114
if (parent->GetMetaType() == PGM_TRIGGER)
115
sch = parent->GetSchema();
117
sch = (pgSchema*)parent;
119
return new dlgFunction(this, frame, (pgFunction*)node, sch);
114
if (parent->GetMetaType() == PGM_TRIGGER)
115
sch = parent->GetSchema();
117
sch = (pgSchema *)parent;
119
return new dlgFunction(this, frame, (pgFunction *)node, sch);
123
123
dlgFunction::dlgFunction(pgaFactory *f, frmMain *frame, pgFunction *node, pgSchema *sch)
124
: dlgSecurityProperty(f, frame, node, wxT("dlgFunction"), wxT("EXECUTE"), "X"),
125
isEdbWrapped( false )
124
: dlgSecurityProperty(f, frame, node, wxT("dlgFunction"), wxT("EXECUTE"), "X"),
125
isEdbWrapped( false )
131
txtArguments->Disable();
134
settings->Read(wxT("frmQuery/ShowLineNumber"), &bVal, false);
137
txtSqlBox->SetMarginType(1, wxSTC_MARGIN_NUMBER);
138
txtSqlBox->SetMarginWidth(1, ConvertDialogToPixels(wxPoint(16, 0)).x);
142
btnRemove->Disable();
143
btnChange->Disable();
145
lstVariables->CreateColumns(0, _("Variable"), _("Value"), -1);
131
txtArguments->Disable();
134
settings->Read(wxT("frmQuery/ShowLineNumber"), &bVal, false);
137
txtSqlBox->SetMarginType(1, wxSTC_MARGIN_NUMBER);
138
txtSqlBox->SetMarginWidth(1, ConvertDialogToPixels(wxPoint(16, 0)).x);
142
btnRemove->Disable();
143
btnChange->Disable();
145
lstVariables->CreateColumns(0, _("Variable"), _("Value"), -1);
151
151
dlgProperty *pgProcedureFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
153
return new dlgProcedure(this, frame, (pgFunction*)node, (pgSchema*)parent);
153
return new dlgProcedure(this, frame, (pgFunction *)node, (pgSchema *)parent);
156
156
dlgProcedure::dlgProcedure(pgaFactory *f, frmMain *frame, pgFunction *node, pgSchema *sch)
157
: dlgFunction(f, frame, node, sch)
157
: dlgFunction(f, frame, node, sch)
162
162
pgObject *dlgFunction::GetObject()
168
168
int dlgFunction::Go(bool modal)
170
isBackendMinVer84 = connection->BackendMinimumVersion(8, 4);
177
rdbVariadic->Disable();
178
isProcedure = function->GetIsProcedure();
181
cbOwner->Append(wxEmptyString);
183
if (!isBackendMinVer84)
184
txtArgDefVal->Disable();
189
lstArguments->AddColumn(_("Type"), 60);
190
lstArguments->AddColumn(_("Mode"), 40);
191
lstArguments->AddColumn(_("Name"), 60);
192
lstArguments->AddColumn(_("Default Value"), 60);
194
if (!connection->BackendMinimumVersion(8, 0))
197
if (!connection->BackendMinimumVersion(8, 3))
202
if (!connection->BackendMinimumVersion(8, 0))
203
txtArgName->Disable();
205
// Window function can not be modified
206
// Disable it for editing
207
if (function || !isBackendMinVer84)
208
chkWindow->Disable();
212
if (function && !connection->EdbMinimumVersion(8, 2))
215
cbLanguage->Disable();
216
chkStrict->Disable();
217
chkWindow->Disable();
218
chkSecureDefiner->Disable();
220
cbVolatility->Disable();
221
cbReturntype->Disable();
227
if (!connection->BackendMinimumVersion(8, 1))
229
rdbIn->SetValue(true);
235
if (!isBackendMinVer84)
237
rdbVariadic->Disable();
241
pgSet *lang=connection->ExecuteSet(wxT("SELECT lanname FROM pg_language"));
246
wxString language=lang->GetVal(0);
247
if (factory == &triggerFunctionFactory)
249
if (language.IsSameAs(wxT("SQL"), false) ||
250
language.IsSameAs(wxT("edbspl"), false))
256
cbLanguage->Append(language);
262
if (connection->BackendMinimumVersion(8, 3))
265
set=connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
266
wxT(" FROM pg_settings WHERE context in ('user', 'superuser')"));
271
cbVarname->Append(set->GetVal(0));
272
varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") +
273
set->GetVal(wxT("min_val")) + wxT(" ") +
274
set->GetVal(wxT("max_val")));
279
cbVarname->SetSelection(0);
286
btnAddVar->Disable();
287
btnRemoveVar->Disable();
288
cbVarname->Disable();
297
if (factory != &triggerFunctionFactory)
299
wxArrayString argTypes = function->GetArgTypesArray();
300
wxArrayString argNames = function->GetArgNamesArray();
301
wxArrayString argModes = function->GetArgModesArray();
302
wxArrayString argDefs = function->GetArgDefsArray();
304
for (unsigned int i=0; i<argTypes.Count(); i++)
306
if (argModes[i] != wxT("TABLE"))
308
if (isBackendMinVer84)
309
lstArguments->AppendItem(-1, argTypes.Item(i), argModes[i], argNames[i], (argDefs.Count() > i ? argDefs[i] : wxString(wxEmptyString)));
311
lstArguments->AppendItem(-1, argTypes.Item(i), argModes[i], argNames[i]);
316
txtArguments->SetValue(function->GetArgListWithNames());
317
cbReturntype->Append(function->GetReturnType());
318
cbReturntype->SetValue(function->GetReturnType());
320
cbLanguage->SetValue(function->GetLanguage());
321
cbVolatility->SetValue(function->GetVolatility());
323
chkSetof->SetValue(function->GetReturnAsSet());
324
chkStrict->SetValue(function->GetIsStrict());
170
isBackendMinVer84 = connection->BackendMinimumVersion(8, 4);
177
rdbVariadic->Disable();
178
isProcedure = function->GetIsProcedure();
181
cbOwner->Append(wxEmptyString);
183
if (!isBackendMinVer84)
184
txtArgDefVal->Disable();
189
lstArguments->AddColumn(_("Type"), 60);
190
lstArguments->AddColumn(_("Mode"), 40);
191
lstArguments->AddColumn(_("Name"), 60);
192
lstArguments->AddColumn(_("Default Value"), 60);
194
if (!connection->BackendMinimumVersion(8, 0))
197
if (!connection->BackendMinimumVersion(8, 3))
202
if (!connection->BackendMinimumVersion(8, 0))
203
txtArgName->Disable();
205
// Window function can not be modified
206
// Disable it for editing
207
if (function || !isBackendMinVer84)
208
chkWindow->Disable();
212
if (function && !connection->EdbMinimumVersion(8, 2))
215
cbLanguage->Disable();
216
chkStrict->Disable();
217
chkWindow->Disable();
218
chkSecureDefiner->Disable();
220
cbVolatility->Disable();
221
cbReturntype->Disable();
227
if (!connection->BackendMinimumVersion(8, 1))
229
rdbIn->SetValue(true);
235
if (!isBackendMinVer84)
237
rdbVariadic->Disable();
241
pgSet *lang = connection->ExecuteSet(wxT("SELECT lanname FROM pg_language"));
246
wxString language = lang->GetVal(0);
247
if (factory == &triggerFunctionFactory)
249
if (language.IsSameAs(wxT("SQL"), false) ||
250
language.IsSameAs(wxT("edbspl"), false))
256
cbLanguage->Append(language);
262
if (connection->BackendMinimumVersion(8, 3))
265
set = connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
266
wxT(" FROM pg_settings WHERE context in ('user', 'superuser')"));
271
cbVarname->Append(set->GetVal(0));
272
varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") +
273
set->GetVal(wxT("min_val")) + wxT(" ") +
274
set->GetVal(wxT("max_val")));
279
cbVarname->SetSelection(0);
286
btnAddVar->Disable();
287
btnRemoveVar->Disable();
288
cbVarname->Disable();
297
if (factory != &triggerFunctionFactory)
299
wxArrayString argTypes = function->GetArgTypesArray();
300
wxArrayString argNames = function->GetArgNamesArray();
301
wxArrayString argModes = function->GetArgModesArray();
302
wxArrayString argDefs = function->GetArgDefsArray();
304
for (unsigned int i = 0; i < argTypes.Count(); i++)
306
if (argModes[i] != wxT("TABLE"))
308
if (isBackendMinVer84)
309
lstArguments->AppendItem(-1, argTypes.Item(i), argModes[i], argNames[i], (argDefs.Count() > i ? argDefs[i] : wxString(wxEmptyString)));
311
lstArguments->AppendItem(-1, argTypes.Item(i), argModes[i], argNames[i]);
316
txtArguments->SetValue(function->GetArgListWithNames());
317
cbReturntype->Append(function->GetReturnType());
318
cbReturntype->SetValue(function->GetReturnType());
320
cbLanguage->SetValue(function->GetLanguage());
321
cbVolatility->SetValue(function->GetVolatility());
323
chkSetof->SetValue(function->GetReturnAsSet());
324
chkStrict->SetValue(function->GetIsStrict());
325
325
if (connection->BackendMinimumVersion(8, 4))
326
chkWindow->SetValue(function->GetIsWindow());
327
chkSecureDefiner->SetValue(function->GetSecureDefiner());
329
if (function->GetLanguage().IsSameAs(wxT("C"), false))
331
txtObjectFile->SetValue(function->GetBin());
332
txtLinkSymbol->SetValue(function->GetSource());
335
txtSqlBox->SetText(function->GetSource());
337
if (!connection->BackendMinimumVersion(7, 4))
340
if (connection->BackendMinimumVersion(8, 3))
342
txtCost->SetValue(NumToStr(function->GetCost()));
343
if (function->GetReturnAsSet())
345
txtRows->SetValue(NumToStr(function->GetRows()));
353
for (index = 0 ; index < function->GetConfigList().GetCount() ; index++)
355
wxString item=function->GetConfigList().Item(index);
356
lstVariables->AppendItem(0, item.BeforeFirst('='), item.AfterFirst('='));
359
cbReturntype->Disable();
361
cbDatatype->Disable();
362
// Editing paramter for wrapped functions is not allowed
363
// It will anyway throw an error, if we try to edit the paramter list
364
if ( connection->GetIsEdb() &&
365
function->GetSource().Trim(false).StartsWith( wxT( "$__EDBwrapped__$" )))
368
cbDatatype->Disable();
372
rdbVariadic->Disable();
373
txtArgName->Disable();
374
txtArgDefVal->Disable();
376
btnChange->Disable();
377
btnRemove->Disable();
384
restrict = wxT("(typtype IN ('b', 'c', 'd', 'p') AND typname NOT IN ('any', 'trigger', 'language_handler'))");
385
if (!settings->GetShowSystemObjects())
386
restrict += wxT(" AND nspname NOT LIKE 'pg_toast%' AND nspname NOT LIKE 'pg_temp%'");
388
DatatypeReader tr(database, restrict);
391
pgDatatype dt=tr.GetDatatype();
393
typOids.Add(tr.GetOidStr());
394
types.Add(dt.QuotedFullName());
396
cbDatatype->Append(dt.FullName());
397
if (factory != &triggerFunctionFactory)
398
cbReturntype->Append(dt.FullName());
403
if (factory == &triggerFunctionFactory)
405
cbReturntype->Append(wxT("trigger"));
406
cbReturntype->SetSelection(0);
407
cbReturntype->Disable();
408
lstArguments->Disable();
409
cbDatatype->Disable();
410
txtArgName->Disable();
411
sel=cbLanguage->FindString(wxT("c"));
413
else if (isProcedure)
414
sel=cbLanguage->FindString(wxT("edbspl"));
416
sel=cbLanguage->FindString(wxT("sql"));
419
cbLanguage->SetSelection(sel);
420
txtObjectFile->SetValue(TXTOBJ_LIB);
424
OnSelChangeLanguage(event);
426
return dlgSecurityProperty::Go(modal);
326
chkWindow->SetValue(function->GetIsWindow());
327
chkSecureDefiner->SetValue(function->GetSecureDefiner());
329
if (function->GetLanguage().IsSameAs(wxT("C"), false))
331
txtObjectFile->SetValue(function->GetBin());
332
txtLinkSymbol->SetValue(function->GetSource());
335
txtSqlBox->SetText(function->GetSource());
337
if (!connection->BackendMinimumVersion(7, 4))
340
if (connection->BackendMinimumVersion(8, 3))
342
txtCost->SetValue(NumToStr(function->GetCost()));
343
if (function->GetReturnAsSet())
345
txtRows->SetValue(NumToStr(function->GetRows()));
353
for (index = 0 ; index < function->GetConfigList().GetCount() ; index++)
355
wxString item = function->GetConfigList().Item(index);
356
lstVariables->AppendItem(0, item.BeforeFirst('='), item.AfterFirst('='));
359
cbReturntype->Disable();
361
cbDatatype->Disable();
362
// Editing paramter for wrapped functions is not allowed
363
// It will anyway throw an error, if we try to edit the paramter list
364
if ( connection->GetIsEdb() &&
365
function->GetSource().Trim(false).StartsWith( wxT( "$__EDBwrapped__$" )))
368
cbDatatype->Disable();
372
rdbVariadic->Disable();
373
txtArgName->Disable();
374
txtArgDefVal->Disable();
376
btnChange->Disable();
377
btnRemove->Disable();
384
restrict = wxT("(typtype IN ('b', 'c', 'd', 'p') AND typname NOT IN ('any', 'trigger', 'language_handler'))");
385
if (!settings->GetShowSystemObjects())
386
restrict += wxT(" AND nspname NOT LIKE 'pg_toast%' AND nspname NOT LIKE 'pg_temp%'");
388
DatatypeReader tr(database, restrict);
391
pgDatatype dt = tr.GetDatatype();
393
typOids.Add(tr.GetOidStr());
394
types.Add(dt.QuotedFullName());
396
cbDatatype->Append(dt.FullName());
397
if (factory != &triggerFunctionFactory)
398
cbReturntype->Append(dt.FullName());
403
if (factory == &triggerFunctionFactory)
405
cbReturntype->Append(wxT("trigger"));
406
cbReturntype->SetSelection(0);
407
cbReturntype->Disable();
408
lstArguments->Disable();
409
cbDatatype->Disable();
410
txtArgName->Disable();
411
sel = cbLanguage->FindString(wxT("c"));
413
else if (isProcedure)
414
sel = cbLanguage->FindString(wxT("edbspl"));
416
sel = cbLanguage->FindString(wxT("sql"));
419
cbLanguage->SetSelection(sel);
420
txtObjectFile->SetValue(TXTOBJ_LIB);
424
OnSelChangeLanguage(event);
426
return dlgSecurityProperty::Go(modal);
430
430
void dlgFunction::OnChangeSize(wxSizeEvent &ev)
432
lstArguments->SetSize(wxDefaultCoord, wxDefaultCoord,
433
ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 350);
434
lstVariables->SetSize(wxDefaultCoord, wxDefaultCoord,
435
ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 350);
436
dlgSecurityProperty::OnChangeSize(ev);
432
lstArguments->SetSize(wxDefaultCoord, wxDefaultCoord,
433
ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 350);
434
lstVariables->SetSize(wxDefaultCoord, wxDefaultCoord,
435
ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 350);
436
dlgSecurityProperty::OnChangeSize(ev);
441
441
void dlgFunction::OnVarnameSelChange(wxCommandEvent &ev)
443
int sel=cbVarname->GuessSelection(ev);
443
int sel = cbVarname->GuessSelection(ev);
448
448
void dlgFunction::SetupVarEditor(int var)
450
if (var >= 0 && varInfo.Count() > 0)
452
wxStringTokenizer vals(varInfo.Item(var));
453
wxString typ=vals.GetNextToken();
450
if (var >= 0 && varInfo.Count() > 0)
452
wxStringTokenizer vals(varInfo.Item(var));
453
wxString typ = vals.GetNextToken();
455
if (typ == wxT("bool"))
459
chkValue->GetParent()->Layout();
465
txtValue->GetParent()->Layout();
466
if (typ == wxT("string") || typ == wxT("enum"))
467
txtValue->SetValidator(wxTextValidator());
469
txtValue->SetValidator(numericValidator);
455
if (typ == wxT("bool"))
459
chkValue->GetParent()->Layout();
465
txtValue->GetParent()->Layout();
466
if (typ == wxT("string") || typ == wxT("enum"))
467
txtValue->SetValidator(wxTextValidator());
469
txtValue->SetValidator(numericValidator);
474
474
void dlgFunction::OnVarSelChange(wxListEvent &ev)
476
long pos=lstVariables->GetSelection();
479
wxString value=lstVariables->GetText(pos, 1);
480
cbVarname->SetValue(lstVariables->GetText(pos));
483
// We used to raise an OnVarnameSelChange() event here, but
484
// at this point the combo box hasn't necessarily updated.
485
int sel = cbVarname->FindString(lstVariables->GetText(pos));
488
txtValue->SetValue(value);
489
chkValue->SetValue(value == wxT("on"));
476
long pos = lstVariables->GetSelection();
479
wxString value = lstVariables->GetText(pos, 1);
480
cbVarname->SetValue(lstVariables->GetText(pos));
483
// We used to raise an OnVarnameSelChange() event here, but
484
// at this point the combo box hasn't necessarily updated.
485
int sel = cbVarname->FindString(lstVariables->GetText(pos));
488
txtValue->SetValue(value);
489
chkValue->SetValue(value == wxT("on"));
495
495
void dlgFunction::OnVarAdd(wxCommandEvent &ev)
497
wxString name=cbVarname->GetValue();
499
if (chkValue->IsShown())
500
value = chkValue->GetValue() ? wxT("on") : wxT("off");
502
value = txtValue->GetValue().Strip(wxString::both);
505
value = wxT("DEFAULT");
509
long pos=lstVariables->FindItem(-1, name);
512
pos = lstVariables->GetItemCount();
513
lstVariables->InsertItem(pos, name, 0);
515
lstVariables->SetItem(pos, 1, value);
497
wxString name = cbVarname->GetValue();
499
if (chkValue->IsShown())
500
value = chkValue->GetValue() ? wxT("on") : wxT("off");
502
value = txtValue->GetValue().Strip(wxString::both);
505
value = wxT("DEFAULT");
509
long pos = lstVariables->FindItem(-1, name);
512
pos = lstVariables->GetItemCount();
513
lstVariables->InsertItem(pos, name, 0);
515
lstVariables->SetItem(pos, 1, value);
521
521
void dlgFunction::OnVarRemove(wxCommandEvent &ev)
523
if (lstVariables->GetSelection() == wxNOT_FOUND)
525
lstVariables->DeleteCurrentItem();
523
if (lstVariables->GetSelection() == wxNOT_FOUND)
525
lstVariables->DeleteCurrentItem();
530
530
pgObject *dlgFunction::CreateObject(pgCollection *collection)
532
wxString sql=wxT(" WHERE proname=") + qtDbString(GetName()) +
533
wxT("\n AND pronamespace=") + schema->GetOidStr();
536
for (argCount=0 ; argCount < (int)argOids.GetCount() ; argCount++)
537
sql += wxT("\n AND proargtypes[") + NumToStr(argCount) + wxT("] = ") + argOids.Item(argCount);
539
sql += wxT("\n AND proargtypes[") + NumToStr(argCount) + wxT("] = 0\n");
541
pgObject *obj=functionFactory.AppendFunctions(collection, collection->GetSchema(), 0, sql);
532
wxString sql = wxT(" WHERE proname=") + qtDbString(GetName()) +
533
wxT("\n AND pronamespace=") + schema->GetOidStr();
536
for (argCount = 0 ; argCount < (int)argOids.GetCount() ; argCount++)
537
sql += wxT("\n AND proargtypes[") + NumToStr(argCount) + wxT("] = ") + argOids.Item(argCount);
539
sql += wxT("\n AND proargtypes[") + NumToStr(argCount) + wxT("] = 0\n");
541
pgObject *obj = functionFactory.AppendFunctions(collection, collection->GetSchema(), 0, sql);
546
546
void dlgFunction::CheckChange()
548
wxString name=GetName();
549
bool isC=cbLanguage->GetValue().IsSameAs(wxT("C"), false);
550
bool enable=true, didChange=true;
552
CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
554
CheckValid(enable, cbReturntype->GetValue().Trim() != wxEmptyString, _("Please select return type."));
556
if (!(isProcedure && connection->GetIsEdb()))
557
CheckValid(enable, cbLanguage->GetGuessedSelection() >= 0, _("Please select language."));
561
wxString objfile=txtObjectFile->GetValue();
562
CheckValid(enable, !objfile.IsEmpty() && objfile != TXTOBJ_LIB, _("Please specify object library."));
566
CheckValid(enable, !txtSqlBox->GetText().IsEmpty(), _("Please enter function source code."));
569
if (function && enable)
571
EnableOK(!GetSql().IsEmpty());
575
EnableOK(enable && didChange);
548
wxString name = GetName();
549
bool isC = cbLanguage->GetValue().IsSameAs(wxT("C"), false);
550
bool enable = true, didChange = true;
552
CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
554
CheckValid(enable, cbReturntype->GetValue().Trim() != wxEmptyString, _("Please select return type."));
556
if (!(isProcedure && connection->GetIsEdb()))
557
CheckValid(enable, cbLanguage->GetGuessedSelection() >= 0, _("Please select language."));
561
wxString objfile = txtObjectFile->GetValue();
562
CheckValid(enable, !objfile.IsEmpty() && objfile != TXTOBJ_LIB, _("Please specify object library."));
566
CheckValid(enable, !txtSqlBox->GetText().IsEmpty(), _("Please enter function source code."));
569
if (function && enable)
571
EnableOK(!GetSql().IsEmpty());
575
EnableOK(enable && didChange);
579
579
bool dlgFunction::IsUpToDate()
587
587
void dlgFunction::OnApply(wxCommandEvent &ev)
589
dlgProperty::OnApply(ev);
589
dlgProperty::OnApply(ev);
591
wxString sql = wxT("SELECT xmin FROM pg_proc WHERE oid = ") + function->GetOidStr();
591
wxString sql = wxT("SELECT xmin FROM pg_proc WHERE oid = ") + function->GetOidStr();
592
592
function->iSetXid(StrToOid(connection->ExecuteScalar(sql)));
595
595
void dlgFunction::OnSelChangeLanguage(wxCommandEvent &ev)
597
bool isC=(cbLanguage->GetValue().IsSameAs(wxT("C"), false));
599
stObjectFile->Show(isC);
600
txtObjectFile->Show(isC);
601
stLinkSymbol->Show(isC);
602
txtLinkSymbol->Show(isC);
603
txtSqlBox->Show(!isC);
605
txtSqlBox->GetContainingSizer()->Layout();
597
bool isC = (cbLanguage->GetValue().IsSameAs(wxT("C"), false));
599
stObjectFile->Show(isC);
600
txtObjectFile->Show(isC);
601
stLinkSymbol->Show(isC);
602
txtLinkSymbol->Show(isC);
603
txtSqlBox->Show(!isC);
605
txtSqlBox->GetContainingSizer()->Layout();
611
611
void dlgFunction::OnSelChangeArg(wxListEvent &ev)
613
int row=lstArguments->GetSelection();
616
cbDatatype->SetValue(lstArguments->GetText(row, 0));
617
wxString mode = lstArguments->GetText(row, 1);
618
if (mode == wxT("IN"))
619
rdbIn->SetValue(true);
620
else if (mode == wxT("OUT"))
621
rdbOut->SetValue(true);
622
else if (mode == wxT("IN OUT") || mode == wxT("INOUT"))
623
rdbInOut->SetValue(true);
624
else if (mode == wxT("VARIADIC"))
625
rdbVariadic->SetValue(true);
626
txtArgName->SetValue(lstArguments->GetText(row, 2));
627
if (isBackendMinVer84)
629
txtArgDefVal->SetValue(lstArguments->GetText(row, 3));
630
txtArgDefVal->Enable(mode == wxT("IN") || mode.IsEmpty());
613
int row = lstArguments->GetSelection();
616
cbDatatype->SetValue(lstArguments->GetText(row, 0));
617
wxString mode = lstArguments->GetText(row, 1);
618
if (mode == wxT("IN"))
619
rdbIn->SetValue(true);
620
else if (mode == wxT("OUT"))
621
rdbOut->SetValue(true);
622
else if (mode == wxT("IN OUT") || mode == wxT("INOUT"))
623
rdbInOut->SetValue(true);
624
else if (mode == wxT("VARIADIC"))
625
rdbVariadic->SetValue(true);
626
txtArgName->SetValue(lstArguments->GetText(row, 2));
627
if (isBackendMinVer84)
629
txtArgDefVal->SetValue(lstArguments->GetText(row, 3));
630
txtArgDefVal->Enable(mode == wxT("IN") || mode.IsEmpty());
639
639
void dlgFunction::OnChangeReturn(wxCommandEvent &ev)
641
cbReturntype->GuessSelection(ev);
641
cbReturntype->GuessSelection(ev);
646
646
void dlgFunction::OnChangeSetof(wxCommandEvent &ev)
648
if (chkSetof->GetValue() && connection->BackendMinimumVersion(8, 3) && !isProcedure)
648
if (chkSetof->GetValue() && connection->BackendMinimumVersion(8, 3) && !isProcedure)
657
657
void dlgFunction::OnSelChangeType(wxCommandEvent &ev)
659
cbDatatype->GuessSelection(ev);
659
cbDatatype->GuessSelection(ev);
664
664
void dlgFunction::OnChangeArgName(wxCommandEvent &ev)
667
if (!txtArgName->GetValue().IsEmpty())
668
argNameRow = lstArguments->FindItem(-1, txtArgName->GetValue());
670
int pos=lstArguments->GetSelection();
672
bool typeValid = (function != 0 || cbDatatype->GetGuessedSelection() >= 0);
674
// EDBWrapped function does not allow modification in parameter list
675
btnChange->Enable(pos >= 0 && typeValid && !isEdbWrapped);
678
// EDBWrapped function does not allow modification in parameter list
679
btnAdd->Enable(argNameRow < 0 && typeValid && !isEdbWrapped);
680
btnRemove->Enable(pos >= 0 && !isEdbWrapped);
667
if (!txtArgName->GetValue().IsEmpty())
668
argNameRow = lstArguments->FindItem(-1, txtArgName->GetValue());
670
int pos = lstArguments->GetSelection();
672
bool typeValid = (function != 0 || cbDatatype->GetGuessedSelection() >= 0);
674
// EDBWrapped function does not allow modification in parameter list
675
btnChange->Enable(pos >= 0 && typeValid && !isEdbWrapped);
678
// EDBWrapped function does not allow modification in parameter list
679
btnAdd->Enable(argNameRow < 0 && typeValid && !isEdbWrapped);
680
btnRemove->Enable(pos >= 0 && !isEdbWrapped);
684
684
void dlgFunction::OnChangeArgMode(wxCommandEvent &ev)
686
// Do nothing, if Default value for function parameter not supported
687
if (!isBackendMinVer84)
686
// Do nothing, if Default value for function parameter not supported
687
if (!isBackendMinVer84)
690
// Only IN parameter supports default value
691
if (!rdbIn->GetValue())
693
txtArgDefVal->SetValue(wxEmptyString);
694
txtArgDefVal->Enable(false);
698
// EDBWrapped function does not allow modification in parameter list
699
txtArgDefVal->Enable(true && !isEdbWrapped);
690
// Only IN parameter supports default value
691
if (!rdbIn->GetValue())
693
txtArgDefVal->SetValue(wxEmptyString);
694
txtArgDefVal->Enable(false);
698
// EDBWrapped function does not allow modification in parameter list
699
txtArgDefVal->Enable(true && !isEdbWrapped);
703
703
void dlgFunction::OnChangeArg(wxCommandEvent &ev)
705
if (GetSelectedDirection() == wxT("VARIADIC") &&
706
!cbDatatype->GetValue().EndsWith(wxT("[]")))
708
wxLogError(_("Only array types can be VARIADIC."));
712
int row=lstArguments->GetSelection();
716
lstArguments->SetItem(row, 0, cbDatatype->GetValue());
717
lstArguments->SetItem(row, 1, GetSelectedDirection());
718
lstArguments->SetItem(row, 2, txtArgName->GetValue());
719
if (isBackendMinVer84)
720
lstArguments->SetItem(row, 3, txtArgDefVal->GetValue());
723
argOids.Item(row) = typOids.Item(cbDatatype->GetGuessedSelection());
724
txtArguments->SetValue(GetArgs());
705
if (GetSelectedDirection() == wxT("VARIADIC") &&
706
!cbDatatype->GetValue().EndsWith(wxT("[]")))
708
wxLogError(_("Only array types can be VARIADIC."));
712
int row = lstArguments->GetSelection();
716
lstArguments->SetItem(row, 0, cbDatatype->GetValue());
717
lstArguments->SetItem(row, 1, GetSelectedDirection());
718
lstArguments->SetItem(row, 2, txtArgName->GetValue());
719
if (isBackendMinVer84)
720
lstArguments->SetItem(row, 3, txtArgDefVal->GetValue());
723
argOids.Item(row) = typOids.Item(cbDatatype->GetGuessedSelection());
724
txtArguments->SetValue(GetArgs());
731
731
void dlgFunction::OnAddArg(wxCommandEvent &ev)
733
if (GetSelectedDirection() == wxT("VARIADIC") &&
734
!cbDatatype->GetValue().EndsWith(wxT("[]")))
736
wxLogError(_("Only array types can be VARIADIC."));
740
lstArguments->AppendItem(-1, cbDatatype->GetValue(), GetSelectedDirection(), txtArgName->GetValue(), txtArgDefVal->GetValue().Trim());
743
argOids.Add(typOids.Item(cbDatatype->GetGuessedSelection()));
745
txtArguments->SetValue(GetArgs());
733
if (GetSelectedDirection() == wxT("VARIADIC") &&
734
!cbDatatype->GetValue().EndsWith(wxT("[]")))
736
wxLogError(_("Only array types can be VARIADIC."));
740
lstArguments->AppendItem(-1, cbDatatype->GetValue(), GetSelectedDirection(), txtArgName->GetValue(), txtArgDefVal->GetValue().Trim());
743
argOids.Add(typOids.Item(cbDatatype->GetGuessedSelection()));
745
txtArguments->SetValue(GetArgs());
750
750
void dlgFunction::OnRemoveArg(wxCommandEvent &ev)
752
unsigned int sel=lstArguments->GetSelection();
753
argOids.RemoveAt(sel);
754
lstArguments->DeleteItem(sel);
755
btnRemove->Disable();
756
txtArguments->SetValue(GetArgs());
752
unsigned int sel = lstArguments->GetSelection();
753
argOids.RemoveAt(sel);
754
lstArguments->DeleteItem(sel);
755
btnRemove->Disable();
756
txtArguments->SetValue(GetArgs());
760
760
wxString dlgFunction::GetSelectedDirection()
762
if (rdbIn->GetValue())
764
else if (rdbOut->GetValue())
766
else if (rdbInOut->GetValue())
769
return wxT("IN OUT");
773
else if (rdbVariadic->GetValue())
774
return wxT("VARIADIC");
776
return wxEmptyString;
762
if (rdbIn->GetValue())
764
else if (rdbOut->GetValue())
766
else if (rdbInOut->GetValue())
769
return wxT("IN OUT");
773
else if (rdbVariadic->GetValue())
774
return wxT("VARIADIC");
776
return wxEmptyString;
780
780
wxString dlgFunction::GetArgs(const bool withNames, const bool inOnly)
783
bool isEdbspl = cbLanguage->GetValue() == wxT("edbspl");
785
for (int i=0; i < lstArguments->GetItemCount(); i++)
787
if (!isEdbspl && inOnly && lstArguments->GetText(i, 1) == wxT("OUT"))
790
if (i && !args.IsEmpty() && !args.EndsWith(wxT(", ")))
795
if (withNames && lstArguments->GetText(i, 2) != wxEmptyString)
796
args += qtIdent(lstArguments->GetText(i, 2)) + wxT(" ");
798
// edbspl functions should list OUT params, but only by type.
799
if (!inOnly || !isEdbspl || lstArguments->GetText(i, 1) != wxT("OUT"))
801
if (lstArguments->GetText(i, 1) != wxEmptyString)
802
args += lstArguments->GetText(i, 1) + wxT(" ");
805
args += lstArguments->GetText(i, 0);
809
// edbspl functions should list OUT params, but only by type.
810
if (!inOnly || !isEdbspl || lstArguments->GetText(i, 1) != wxT("OUT"))
812
if (connection->BackendMinimumVersion(8, 1) && lstArguments->GetText(i, 1) != wxEmptyString)
813
args += lstArguments->GetText(i, 1) + wxT(" ");
816
if (connection->BackendMinimumVersion(8, 0) && withNames && lstArguments->GetText(i, 2) != wxEmptyString)
817
args += qtIdent(lstArguments->GetText(i, 2)) + wxT(" ");
819
args += lstArguments->GetText(i, 0);
821
if (isBackendMinVer84 && !lstArguments->GetText(i, 3).IsEmpty())
822
args += wxT(" DEFAULT ") + lstArguments->GetText(i, 3);
783
bool isEdbspl = cbLanguage->GetValue() == wxT("edbspl");
785
for (int i = 0; i < lstArguments->GetItemCount(); i++)
787
if (!isEdbspl && inOnly && lstArguments->GetText(i, 1) == wxT("OUT"))
790
if (i && !args.IsEmpty() && !args.EndsWith(wxT(", ")))
795
if (withNames && lstArguments->GetText(i, 2) != wxEmptyString)
796
args += qtIdent(lstArguments->GetText(i, 2)) + wxT(" ");
798
// edbspl functions should list OUT params, but only by type.
799
// although this is not true for EDB AS90 onwards..
800
if (!inOnly || !isEdbspl || lstArguments->GetText(i, 1) != wxT("OUT") ||
801
connection->EdbMinimumVersion(9, 0))
803
if (lstArguments->GetText(i, 1) != wxEmptyString)
804
args += lstArguments->GetText(i, 1) + wxT(" ");
807
args += lstArguments->GetText(i, 0);
811
// edbspl functions should list OUT params, but only by type.
812
// although this is not true for EDB AS90 onwards..
813
if (!inOnly || !isEdbspl || lstArguments->GetText(i, 1) != wxT("OUT") ||
814
connection->EdbMinimumVersion(9, 0))
816
if (connection->BackendMinimumVersion(8, 1) && lstArguments->GetText(i, 1) != wxEmptyString)
817
args += lstArguments->GetText(i, 1) + wxT(" ");
820
if (connection->BackendMinimumVersion(8, 0) && withNames && lstArguments->GetText(i, 2) != wxEmptyString)
821
args += qtIdent(lstArguments->GetText(i, 2)) + wxT(" ");
823
args += lstArguments->GetText(i, 0);
825
if (isBackendMinVer84 && !lstArguments->GetText(i, 3).IsEmpty())
826
args += wxT(" DEFAULT ") + lstArguments->GetText(i, 3);
829
833
wxString dlgFunction::GetSql()
832
wxString name=GetName();
835
objType = wxT("PROCEDURE ");
837
objType = wxT("FUNCTION ");
839
bool isC=cbLanguage->GetValue().IsSameAs(wxT("C"), false);
840
bool didChange = !function
841
|| cbLanguage->GetValue() != function->GetLanguage()
842
|| cbVolatility->GetValue() != function->GetVolatility()
843
|| chkSecureDefiner->GetValue() != function->GetSecureDefiner()
844
|| chkStrict->GetValue() != function->GetIsStrict()
845
|| cbOwner->GetValue() != function->GetOwner()
846
|| GetArgs() != function->GetArgListWithNames()
847
|| (isC && (txtObjectFile->GetValue() != function->GetBin() || txtLinkSymbol->GetValue() != function->GetSource()))
848
|| (!isC && txtSqlBox->GetText() != function->GetSource());
850
if (connection->BackendMinimumVersion(8, 3))
852
didChange = (didChange ||
853
txtCost->GetValue() != NumToStr(function->GetCost()) ||
854
(chkSetof->GetValue() && txtRows->GetValue() != NumToStr(function->GetRows())));
860
if (name != function->GetName())
863
sql = wxT("ALTER FUNCTION ") + function->GetQuotedFullIdentifier()
864
+ wxT("(") + function->GetArgSigList() + wxT(")")
865
+ wxT(" RENAME TO ") + qtIdent(name) + wxT(";\n");
867
sql = wxT("ALTER PROCEDURE ") + function->GetQuotedFullIdentifier()
868
+ wxT(" RENAME TO ") + qtIdent(name) + wxT(";\n");
872
sql += wxT("CREATE OR REPLACE ") + objType;
877
sql = wxT("CREATE " ) + objType;
882
if (isProcedure && GetArgs().IsEmpty())
884
sql += schema->GetQuotedPrefix() + qtIdent(GetName());
888
sql += schema->GetQuotedPrefix() + qtIdent(GetName())
889
+ wxT("(") + GetArgs() + wxT(")");
894
sql += wxT(" RETURNS ");
895
if (chkSetof->GetValue() && !cbReturntype->GetValue().StartsWith(wxT("TABLE")))
896
sql += wxT("SETOF ");
898
sql += cbReturntype->GetValue();
905
sql += txtSqlBox->GetText();
906
sql = sql.Trim(true);
907
if (!sql.EndsWith(wxT(";")))
914
if (cbLanguage->GetValue().IsSameAs(wxT("C"), false))
916
sql += qtDbString(txtObjectFile->GetValue());
917
if (!txtLinkSymbol->GetValue().IsEmpty())
918
sql += wxT(", ") + qtDbString(txtLinkSymbol->GetValue());
922
if (connection->BackendMinimumVersion(7, 5))
923
sql += qtDbStringDollar(txtSqlBox->GetText());
925
sql += qtDbString(txtSqlBox->GetText());
928
sql += wxT("\nLANGUAGE ") + cbLanguage->GetValue();
929
if (chkWindow->GetValue())
930
sql += wxT(" WINDOW ");
933
sql += cbVolatility->GetValue();
934
if (chkStrict->GetValue())
935
sql += wxT(" STRICT");
936
if (chkSecureDefiner->GetValue())
937
sql += wxT(" SECURITY DEFINER");
939
// PostgreSQL 8.3+ cost/row estimations
940
if (connection->BackendMinimumVersion(8, 3))
942
if (txtCost->GetValue().Length() > 0)
943
sql += wxT("\nCOST ") + txtCost->GetValue();
945
if (chkSetof->GetValue() && txtRows->GetValue().Length() > 0)
946
sql += wxT("\nROWS ") + txtRows->GetValue();
953
name = schema->GetQuotedPrefix() + qtIdent(name)
954
+ wxT("(") + GetArgs(false, true) + wxT(")");
958
if (cbOwner->GetValue() != function->GetOwner())
959
sql += wxT("ALTER FUNCTION ") + name
960
+ wxT(" OWNER TO ") + qtIdent(cbOwner->GetValue())
965
if (cbOwner->GetCurrentSelection() > 0)
966
AppendOwnerNew(sql,wxT("FUNCTION ") + name);
970
sql += GetGrant(wxT("X"), wxT("PROCEDURE ") + name);
978
for (index = 0 ; index < function->GetConfigList().GetCount() ; index++)
979
vars.Add(function->GetConfigList().Item(index));
982
int cnt=lstVariables->GetItemCount();
985
// check for changed or added vars
986
for (pos=0 ; pos < cnt ; pos++)
988
wxString newVar=lstVariables->GetText(pos);
989
wxString newVal=lstVariables->GetText(pos, 1);
993
for (index=0 ; index < vars.GetCount() ; index++)
995
wxString var=vars.Item(index);
996
if (var.BeforeFirst('=').IsSameAs(newVar, false))
998
oldVal = var.Mid(newVar.Length()+1);
999
vars.RemoveAt(index);
1004
// Reset the vars if they've changed, or the function definition has
1005
// changed, which will remove them all :-(
1006
if ((oldVal != newVal) || didChange)
1008
if (newVar != wxT("search_path") && newVar != wxT("temp_tablespaces"))
1009
sql += wxT("ALTER FUNCTION ") + name
1010
+ wxT(" SET ") + newVar
1011
+ wxT("='") + newVal
1014
sql += wxT("ALTER FUNCTION ") + name
1015
+ wxT(" SET ") + newVar
1021
// check for removed vars
1022
for (pos=0 ; pos < (int)vars.GetCount() ; pos++)
1024
sql += wxT("ALTER FUNCTION ") + name
1025
+ wxT(" RESET ") + vars.Item(pos).BeforeFirst('=')
1029
sql += GetGrant(wxT("X"), wxT("FUNCTION ") + name);
1033
AppendComment(sql, wxT("PROCEDURE ") + schema->GetQuotedPrefix() + qtIdent(GetName()), function);
1035
AppendComment(sql, wxT("FUNCTION ") + name, function);
836
wxString name = GetName();
839
objType = wxT("PROCEDURE ");
841
objType = wxT("FUNCTION ");
843
bool isC = cbLanguage->GetValue().IsSameAs(wxT("C"), false);
844
bool didChange = !function
845
|| cbLanguage->GetValue() != function->GetLanguage()
846
|| cbVolatility->GetValue() != function->GetVolatility()
847
|| chkSecureDefiner->GetValue() != function->GetSecureDefiner()
848
|| chkStrict->GetValue() != function->GetIsStrict()
849
|| cbOwner->GetValue() != function->GetOwner()
850
|| GetArgs() != function->GetArgListWithNames()
851
|| (isC && (txtObjectFile->GetValue() != function->GetBin() || txtLinkSymbol->GetValue() != function->GetSource()))
852
|| (!isC && txtSqlBox->GetText() != function->GetSource());
854
if (connection->BackendMinimumVersion(8, 3))
856
didChange = (didChange ||
857
txtCost->GetValue() != NumToStr(function->GetCost()) ||
858
(chkSetof->GetValue() && txtRows->GetValue() != NumToStr(function->GetRows())));
864
if (name != function->GetName())
867
sql = wxT("ALTER FUNCTION ") + function->GetQuotedFullIdentifier()
868
+ wxT("(") + function->GetArgSigList() + wxT(")")
869
+ wxT(" RENAME TO ") + qtIdent(name) + wxT(";\n");
871
sql = wxT("ALTER PROCEDURE ") + function->GetQuotedFullIdentifier()
872
+ wxT(" RENAME TO ") + qtIdent(name) + wxT(";\n");
876
sql += wxT("CREATE OR REPLACE ") + objType;
881
sql = wxT("CREATE " ) + objType;
886
if (isProcedure && GetArgs().IsEmpty())
888
sql += schema->GetQuotedPrefix() + qtIdent(GetName());
892
sql += schema->GetQuotedPrefix() + qtIdent(GetName())
893
+ wxT("(") + GetArgs() + wxT(")");
898
sql += wxT(" RETURNS ");
899
if (chkSetof->GetValue() && !cbReturntype->GetValue().StartsWith(wxT("TABLE")))
900
sql += wxT("SETOF ");
902
sql += cbReturntype->GetValue();
909
sql += txtSqlBox->GetText();
910
sql = sql.Trim(true);
911
if (!sql.EndsWith(wxT(";")))
918
if (cbLanguage->GetValue().IsSameAs(wxT("C"), false))
920
sql += qtDbString(txtObjectFile->GetValue());
921
if (!txtLinkSymbol->GetValue().IsEmpty())
922
sql += wxT(", ") + qtDbString(txtLinkSymbol->GetValue());
926
if (connection->BackendMinimumVersion(7, 5))
927
sql += qtDbStringDollar(txtSqlBox->GetText());
929
sql += qtDbString(txtSqlBox->GetText());
932
sql += wxT("\nLANGUAGE ") + cbLanguage->GetValue();
933
if (chkWindow->GetValue())
934
sql += wxT(" WINDOW ");
937
sql += cbVolatility->GetValue();
938
if (chkStrict->GetValue())
939
sql += wxT(" STRICT");
940
if (chkSecureDefiner->GetValue())
941
sql += wxT(" SECURITY DEFINER");
943
// PostgreSQL 8.3+ cost/row estimations
944
if (connection->BackendMinimumVersion(8, 3))
946
if (txtCost->GetValue().Length() > 0)
947
sql += wxT("\nCOST ") + txtCost->GetValue();
949
if (chkSetof->GetValue() && txtRows->GetValue().Length() > 0)
950
sql += wxT("\nROWS ") + txtRows->GetValue();
957
name = schema->GetQuotedPrefix() + qtIdent(name)
958
+ wxT("(") + GetArgs(false, true) + wxT(")");
962
if (cbOwner->GetValue() != function->GetOwner())
963
sql += wxT("ALTER FUNCTION ") + name
964
+ wxT(" OWNER TO ") + qtIdent(cbOwner->GetValue())
969
if (cbOwner->GetCurrentSelection() > 0)
970
AppendOwnerNew(sql, wxT("FUNCTION ") + name);
974
sql += GetGrant(wxT("X"), wxT("PROCEDURE ") + name);
982
for (index = 0 ; index < function->GetConfigList().GetCount() ; index++)
983
vars.Add(function->GetConfigList().Item(index));
986
int cnt = lstVariables->GetItemCount();
989
// check for changed or added vars
990
for (pos = 0 ; pos < cnt ; pos++)
992
wxString newVar = lstVariables->GetText(pos);
993
wxString newVal = lstVariables->GetText(pos, 1);
997
for (index = 0 ; index < vars.GetCount() ; index++)
999
wxString var = vars.Item(index);
1000
if (var.BeforeFirst('=').IsSameAs(newVar, false))
1002
oldVal = var.Mid(newVar.Length() + 1);
1003
vars.RemoveAt(index);
1008
// Reset the vars if they've changed, or the function definition has
1009
// changed, which will remove them all :-(
1010
if ((oldVal != newVal) || didChange)
1012
if (newVar != wxT("search_path") && newVar != wxT("temp_tablespaces"))
1013
sql += wxT("ALTER FUNCTION ") + name
1014
+ wxT(" SET ") + newVar
1015
+ wxT("='") + newVal
1018
sql += wxT("ALTER FUNCTION ") + name
1019
+ wxT(" SET ") + newVar
1025
// check for removed vars
1026
for (pos = 0 ; pos < (int)vars.GetCount() ; pos++)
1028
sql += wxT("ALTER FUNCTION ") + name
1029
+ wxT(" RESET ") + vars.Item(pos).BeforeFirst('=')
1033
sql += GetGrant(wxT("X"), wxT("FUNCTION ") + name);
1037
AppendComment(sql, wxT("PROCEDURE ") + schema->GetQuotedPrefix() + qtIdent(GetName()), function);
1039
AppendComment(sql, wxT("FUNCTION ") + name, function);
1041
1045
void dlgFunction::OnChangeWindow(wxCommandEvent &ev)