Date Dev Ver Change details
---------- --- ------ --------------
+2009-10-08 DP 1.12.0 Add 'SELECT Script' for functions and 'EXEC Script' for
+ procedures.
2009-10-08 DP 1.10.1 Fix Greenplum support for column oriented partitions
[Chuck McDevitt]
2009-10-05 DP 1.10.1 Ensure function variables get reset if the function is
toolsMenu->Append(scriptingMenuFactory->GetId(), _("Scripts"), scriptingMenu, _("Start Query Tool with scripted query."));
new queryToolSqlFactory(menuFactories, scriptingMenu, 0);
new queryToolSelectFactory(menuFactories, scriptingMenu, 0);
+ new queryToolExecFactory(menuFactories, scriptingMenu, 0);
new queryToolInsertFactory(menuFactories, scriptingMenu, 0);
new queryToolUpdateFactory(menuFactories, scriptingMenu, 0);
new queryToolDeleteFactory(menuFactories, scriptingMenu, 0);
#include "gqb/gqbViewPanels.h"
#include "gqb/gqbEvents.h"
#include "schema/pgDatabase.h"
+#include "schema/pgFunction.h"
#include "schema/pgTable.h"
#include "schema/pgView.h"
#include "schema/gpExtTable.h"
mnu->Append(id, _("SELECT script"), _("Start query tool with SELECT script."));
}
+bool queryToolSelectFactory::CheckEnable(pgObject *obj)
+{
+ return queryToolBaseFactory::CheckEnable(obj) && !obj->IsCollection() &&
+ (obj->IsCreatedBy(tableFactory) || obj->IsCreatedBy(viewFactory) || obj->IsCreatedBy(functionFactory));
+}
wxWindow *queryToolSelectFactory::StartDialog(frmMain *form, pgObject *obj)
{
gpExtTable *exttable = (gpExtTable*)obj;
return StartDialogSql(form, obj, exttable->GetSelectSql(form->GetBrowser()));
}
+ else if (obj->IsCreatedBy(functionFactory))
+ {
+ pgFunction *function = (pgFunction*)obj;
+ return StartDialogSql(form, obj, function->GetSelectSql(form->GetBrowser()));
+ }
return 0;
}
+queryToolExecFactory::queryToolExecFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : queryToolDataFactory(list)
+{
+ mnu->Append(id, _("EXEC script"), _("Start query tool with EXEC script."));
+}
+
+bool queryToolExecFactory::CheckEnable(pgObject *obj)
+{
+ return queryToolBaseFactory::CheckEnable(obj) && !obj->IsCollection() && obj->IsCreatedBy(procedureFactory);
+}
+
+wxWindow *queryToolExecFactory::StartDialog(frmMain *form, pgObject *obj)
+{
+ if (obj->IsCreatedBy(procedureFactory))
+ {
+ pgProcedure *procedure = (pgProcedure*)obj;
+ return StartDialogSql(form, obj, procedure->GetExecSql(form->GetBrowser()));
+ }
+ return 0;
+}
queryToolDeleteFactory::queryToolDeleteFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : queryToolDataFactory(list)
{
public:
queryToolSelectFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
wxWindow *StartDialog(frmMain *form, pgObject *obj);
+ bool CheckEnable(pgObject *obj);
+};
+
+class queryToolExecFactory : public queryToolDataFactory
+{
+public:
+ queryToolExecFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
+ wxWindow *StartDialog(frmMain *form, pgObject *obj);
+ bool CheckEnable(pgObject *obj);
};
class queryToolDeleteFactory : public queryToolDataFactory
wxString GetFullName();
wxString GetArgListWithNames();
- wxString GetArgSigList();
+ wxString GetArgSigList(const bool forScript = false);
wxArrayString &GetArgNamesArray() { return argNamesArray; }
void iAddArgName(const wxString &s) { argNamesArray.Add(s); }
wxString GetSql(ctlTree *browser);
wxString GetHelpPage(bool forCreate) const { return wxT("pg/sql-createfunction"); }
pgObject *Refresh(ctlTree *browser, const wxTreeItemId item);
+ wxString GetSelectSql(ctlTree *browser);
void ShowHint(frmMain *form, bool force);
bool GetCanHint() { return true; };
wxString GetSql(ctlTree *browser);
bool DropObject(wxFrame *frame, ctlTree *browser, bool cascaded);
+ wxString GetExecSql(ctlTree *browser);
wxString GetHelpPage(bool forCreate) const { return wxT("pg/sql-createprocedure"); }
};
return args;
}
-wxString pgFunction::GetArgSigList()
+// Return the signature arguments list. If forScript = true, we format the list
+// appropriately for use in a SELECT script.
+wxString pgFunction::GetArgSigList(const bool forScript)
{
wxString args;
if (argModesArray.Item(i) != wxT("OUT") && argModesArray.Item(i) != wxT("TABLE"))
{
if (args.Length() > 0)
- args += wxT(", ");
+ {
+ if (forScript)
+ args += wxT(",\n");
+ else
+ args += wxT(", ");
+ }
- args += argTypesArray.Item(i);
+ if (forScript)
+ args += wxT(" <") + argTypesArray.Item(i) + wxT(">");
+ else
+ args += argTypesArray.Item(i);
}
else
{
if (GetLanguage() == wxT("edbspl") && argModesArray.Item(i) != wxT("TABLE"))
{
if (args.Length() > 0)
- args += wxT(", ");
+ {
+ if (forScript)
+ args += wxT(",\n");
+ else
+ args += wxT(", ");
+ }
- args += argTypesArray.Item(i);
+ if (forScript)
+ args += wxT(" <") + argTypesArray.Item(i) + wxT(">");
+ else
+ args += argTypesArray.Item(i);
}
}
}
return function;
}
+// Generate the SELECT Script SQL
+wxString pgFunction::GetSelectSql(ctlTree *browser)
+{
+ wxString args = GetArgSigList(true);
+
+ wxString sql = wxT("SELECT ") + GetQuotedFullIdentifier();
+
+ if (args.Length())
+ sql += wxT("(\n") + args + wxT("\n);\n");
+ else
+ sql += wxT(");\n");
+
+ return sql;
+}
+
+// Generate the EXEC Script SQL
+wxString pgProcedure::GetExecSql(ctlTree *browser)
+{
+ wxString args = GetArgSigList(true);
+
+ wxString sql = wxT("EXEC ") + GetQuotedFullIdentifier();
+
+ if (args.Length())
+ sql += wxT("(\n") + args + wxT("\n);\n");
+ else
+ sql += wxT(";\n");
+ return sql;
+}
pgObject *pgFunctionFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restr)
{