Permalink
Browse files

Support single INOUT or OUT parameter.

  • Loading branch information...
ItGacky committed Sep 3, 2010
1 parent 3464155 commit 24820a35c1d0a2143da9543d5093f8706bf7df30
Showing with 50 additions and 6 deletions.
  1. +23 −0 expected/plv8.out
  2. +11 −5 plv8.cc
  3. +1 −1 plv8_type.cc
  4. +15 −0 sql/plv8.sql
View
@@ -229,6 +229,29 @@ $$
LANGUAGE plv8;
SELECT * FROM set_of_integers();
ERROR: SETOF a scalar type is not implemented yet
+-- INOUT and OUT parameters
+CREATE FUNCTION one_inout(a integer, INOUT b text) AS
+$$
+return a + b;
+$$
+LANGUAGE plv8;
+SELECT one_inout(5, 'ABC');
+ one_inout
+-----------
+ 5ABC
+(1 row)
+
+CREATE FUNCTION one_out(OUT o text, i integer) AS
+$$
+return 'ABC' + i;
+$$
+LANGUAGE plv8;
+SELECT one_out(123);
+ one_out
+---------
+ ABC123
+(1 row)
+
-- print()
CREATE FUNCTION test_print(arg text) RETURNS void AS
$$
View
16 plv8.cc
@@ -500,12 +500,12 @@ plv8_get_proc_cache(Oid fn_oid, bool validate, char ***argnames) throw()
strlcpy(proc->proname, NameStr(procStruct->proname), NAMEDATALEN);
proc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data);
proc->fn_tid = procTup->t_self;
- proc->nargs = get_func_arg_info(procTup, &argtypes, argnames, &argmodes);
+ int nargs = get_func_arg_info(procTup, &argtypes, argnames, &argmodes);
if (validate)
{
/* Disallow pseudotypes in arguments (either IN or OUT) */
- for (int i = 0; i < proc->nargs; i++)
+ for (int i = 0; i < nargs; i++)
{
if (get_typtype(argtypes[i]) == TYPTYPE_PSEUDO)
ereport(ERROR,
@@ -521,22 +521,28 @@ plv8_get_proc_cache(Oid fn_oid, bool validate, char ***argnames) throw()
ReleaseSysCache(procTup);
- for (int i = 0; i < proc->nargs; i++)
+ int inargs = 0;
+ for (int i = 0; i < nargs; i++)
{
Oid argtype = argtypes[i];
char argmode = argmodes ? argmodes[i] : PROARGMODE_IN;
switch (argmode)
{
case PROARGMODE_IN:
+ case PROARGMODE_INOUT:
case PROARGMODE_VARIADIC:
break;
default:
- elog(ERROR, "OUT parameters are not supported");
+ continue;
}
- plv8_fill_type(&proc->argtypes[i], argtype);
+ if (*argnames)
+ (*argnames)[inargs] = (*argnames)[i];
+ plv8_fill_type(&proc->argtypes[inargs], argtype);
+ inargs++;
}
+ proc->nargs = inargs;
plv8_fill_type(&proc->rettype, rettype);
View
2 plv8_type.cc 100644 → 100755
@@ -1,5 +1,5 @@
/*
- * plv8.cc : Postgres from/to v8 data converters.
+ * plv8_type.cc : Postgres from/to v8 data converters.
*/
#include "plv8.h"
View
@@ -122,6 +122,21 @@ $$
LANGUAGE plv8;
SELECT * FROM set_of_integers();
+-- INOUT and OUT parameters
+CREATE FUNCTION one_inout(a integer, INOUT b text) AS
+$$
+return a + b;
+$$
+LANGUAGE plv8;
+SELECT one_inout(5, 'ABC');
+
+CREATE FUNCTION one_out(OUT o text, i integer) AS
+$$
+return 'ABC' + i;
+$$
+LANGUAGE plv8;
+SELECT one_out(123);
+
-- print()
CREATE FUNCTION test_print(arg text) RETURNS void AS
$$

0 comments on commit 24820a3

Please sign in to comment.