Add support for RETURNS TABLE() on functions [Ashesh Vashi].
authordpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Fri, 17 Apr 2009 11:54:37 +0000 (11:54 +0000)
committerdpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Fri, 17 Apr 2009 11:54:37 +0000 (11:54 +0000)
git-svn-id: svn://svn.pgadmin.org/trunk/pgadmin3@7815 a7884b65-44f6-0310-8a51-81a127f17b15

CHANGELOG
pgadmin/dlg/dlgFunction.cpp
pgadmin/schema/pgFunction.cpp

index bbb04047becf3de0decab4bcf47b825450086fa4..80009fc47ee899421f8530bf8216fd29213ac5c4 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -36,6 +36,8 @@ Changes
 \r
 Date       Dev Ver     Change details\r
 ---------- --- ------  --------------\r
+2009-04-01 DP  1.10.0  Add support for RETURNS TABLE() on functions [Ashesh\r
+                       Vashi].\r
 2009-04-01 DP  1.10.0  Fix the validation of database and schema restriction\r
                        strings.\r
 2009-03-31 DP  1.10.0  Support ldap, gss, sspi & cert authentication methods in\r
index 91a70349375426242020b92a0df8e95c1e1ed34b..bbb5a5c7e18830d94fbc5554415f00f2f5738069 100644 (file)
@@ -513,7 +513,7 @@ void dlgFunction::CheckChange()
 
     CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
     if (!isProcedure)
-        CheckValid(enable, cbReturntype->GetGuessedSelection() >= 0, _("Please select return type."));
+        CheckValid(enable, cbReturntype->GetValue().Trim() != wxEmptyString, _("Please select return type."));
 
     if (!(isProcedure && connection->GetIsEdb()))
         CheckValid(enable, cbLanguage->GetGuessedSelection() >= 0, _("Please select language."));
index 2fdf4e24d81ce82f823e16096499359a4e9364b9..066cc991f068a02289bf4df18bfdfe21f72ef8a9 100644 (file)
@@ -99,7 +99,7 @@ wxString pgFunction::GetSql(ctlTree *browser)
         else
         {
             sql += wxT("\n  RETURNS ");
-            if (GetReturnAsSet())
+            if (GetReturnAsSet() && !GetReturnType().StartsWith(wxT("TABLE")))
                 sql += wxT("SETOF ");
             sql += GetReturnType();
 
@@ -266,6 +266,13 @@ wxString pgFunction::GetArgListWithNames()
 
     for (unsigned int i=0; i < argTypesArray.Count(); i++)
     {
+        /*
+        * All Table arguments lies at the end of the list
+        * Do not include them as the part of the argument list
+        */
+        if (argModesArray.Item(i) == wxT("TABLE"))
+            break;
+
         if (args.Length() > 0)
             args += wxT(", ");
 
@@ -273,8 +280,16 @@ wxString pgFunction::GetArgListWithNames()
 
         if (GetIsProcedure())
         {
-            if (!argNamesArray.Item(i).IsEmpty())
+            if (!argModesArray.Item(i).IsEmpty())
+            {
                 arg += qtIdent(argNamesArray.Item(i));
+            }
+            else
+            {
+                if (!argNamesArray.Item(i).IsEmpty())
+                    arg += qtIdent(argNamesArray.Item(i));
+                arg += wxT(" ") + argModesArray.Item(i);
+            }
 
             if (!argModesArray.Item(i).IsEmpty())
             {
@@ -322,7 +337,7 @@ wxString pgFunction::GetArgSigList()
     for (unsigned int i=0; i < argTypesArray.Count(); i++)
     {
         // OUT parameters are not considered part of the signature, except for EDB-SPL
-        if (argModesArray.Item(i) != wxT("OUT"))
+        if (argModesArray.Item(i) != wxT("OUT") && argModesArray.Item(i) != wxT("TABLE"))
         {
             if (args.Length() > 0)
                 args += wxT(", ");
@@ -331,7 +346,7 @@ wxString pgFunction::GetArgSigList()
         }
         else
         {
-            if (GetLanguage() == wxT("edbspl"))
+            if (GetLanguage() == wxT("edbspl") && argModesArray.Item(i) != wxT("TABLE"))
             {
                 if (args.Length() > 0)
                     args += wxT(", ");
@@ -506,6 +521,8 @@ pgFunction *pgFunctionFactory::AppendFunctions(pgObject *obj, pgSchema *schema,
                         mode = wxT("IN OUT");
                     else if (mode == wxT("v"))
                         mode = wxT("VARIADIC");
+                    else if (mode == wxT("t"))
+                        mode = wxT("TABLE");
                     else
                     {
                         mode = wxT("IN");
@@ -548,6 +565,7 @@ pgFunction *pgFunctionFactory::AppendFunctions(pgObject *obj, pgSchema *schema,
             
             function->iSetArgCount(functions->GetLong(wxT("pronargs")));
 
+            wxString strReturnTableArgs;
             // Process default values
             if (obj->GetConnection()->BackendMinimumVersion(8, 4) &&
                 function->GetArgCount() != 0)
@@ -566,6 +584,15 @@ pgFunction *pgFunctionFactory::AppendFunctions(pgObject *obj, pgSchema *schema,
                                 function->iAddArgDef(argDefValArray[currINindex-1]);
                         }
                     }
+                    else if(function->GetArgModesArray()[index] == wxT("TABLE"))
+                    {
+                        if (strReturnTableArgs.Length() > 0)
+                            strReturnTableArgs += wxT(", ");
+                        wxString strName = function->GetArgNamesArray()[index];
+                        if (!strName.IsEmpty())
+                            strReturnTableArgs += strName + wxT(" ");
+                        strReturnTableArgs += function->GetArgTypesArray()[index];
+                    }
                     function->iAddArgDef(wxEmptyString);
                 }
             }
@@ -575,7 +602,12 @@ pgFunction *pgFunctionFactory::AppendFunctions(pgObject *obj, pgSchema *schema,
             function->UpdateSchema(browser, functions->GetOid(wxT("pronamespace")));
             function->iSetOwner(functions->GetVal(wxT("funcowner")));
             function->iSetAcl(functions->GetVal(wxT("proacl")));
-            function->iSetReturnType(functions->GetVal(wxT("typname")));
+            wxString strType = functions->GetVal(wxT("typname"));
+            if (strType.Lower() == wxT("record") && !strReturnTableArgs.IsEmpty())
+            {
+                strType = wxT("TABLE(") + strReturnTableArgs + wxT(")");
+            }
+            function->iSetReturnType(strType);
             function->iSetComment(functions->GetVal(wxT("description")));
 
             function->iSetLanguage(lanname);