diff --git a/plparrot.c b/plparrot.c index e116e35..c013689 100644 --- a/plparrot.c +++ b/plparrot.c @@ -193,15 +193,20 @@ plparrot_func_handler(PG_FUNCTION_ARGS) result = create_pmc("ResizablePMCArray"); Parrot_ext_call(interp, func_pmc, "Pf->Pf", func_args, &result); + + /* Where is the correct place to put this? */ + if ((rc = SPI_finish()) != SPI_OK_FINISH) + elog(ERROR, "SPI_finish failed: %s", SPI_result_code_string(rc)); + if (Parrot_PMC_get_bool(interp,result)) { tmp_pmc = Parrot_PMC_pop_pmc(interp, result); /* TODO: We need to convert Parrot datatypes into PG Datum's */ /* dump_pmc(interp,tmp_pmc); */ + } else { + /* We got an empty array of return values, so we should return void */ + PG_RETURN_VOID(); } - if ((rc = SPI_finish()) != SPI_OK_FINISH) - elog(ERROR, "SPI_finish failed: %s", SPI_result_code_string(rc)); - return retval; } void @@ -253,13 +258,11 @@ plparrot_call_handler(PG_FUNCTION_ARGS) TriggerData *tdata; plparrot_call_data *save_call_data = current_call_data; - //elog(NOTICE,"enter plparrot_call_handler"); - //elog(NOTICE,"entering PG_TRY"); PG_TRY(); { if (CALLED_AS_TRIGGER(fcinfo)) { tdata = (TriggerData *) fcinfo->context; - /* we need a trigger handler */ + /* TODO: we need a trigger handler */ } else { retval = plparrot_func_handler(fcinfo); } @@ -280,6 +283,7 @@ Parrot_PMC create_pmc(const char *name) { return Parrot_PMC_new(interp,Parrot_PMC_typenum(interp,name)); } + Parrot_String create_string(const char *name) { return Parrot_new_string(interp, name, strlen(name), (const char *) NULL, 0); @@ -293,4 +297,3 @@ dump_pmc(Parrot_Interp interp, Parrot_PMC pmc) string = Parrot_PMC_get_cstring(interp,tmp_pmc); elog(NOTICE, "PMC = %s", string); } - diff --git a/t/sql/test.sql b/t/sql/test.sql index 0d82719..7edfe31 100644 --- a/t/sql/test.sql +++ b/t/sql/test.sql @@ -65,30 +65,30 @@ CREATE FUNCTION test_float() RETURNS float AS $$ .end $$ LANGUAGE plparrot; -CREATE FUNCTION test_varchar_in(text) RETURNS varchar AS $$ +CREATE FUNCTION test_varchar_in(varchar) RETURNS varchar AS $$ .sub foo_varchar_in .param string s .return(s) .end $$ LANGUAGE plparrot; -CREATE FUNCTION test_varchar_out(text) RETURNS varchar AS $$ +CREATE FUNCTION test_varchar_out(varchar) RETURNS varchar AS $$ .sub foo_varchar_out $S1 = 'blue' .return($S1) .end $$ LANGUAGE plparrot; -CREATE FUNCTION test_char_in(text) RETURNS char AS $$ +CREATE FUNCTION test_char_in(char) RETURNS char AS $$ .sub foo_char_in .param string s .return(s) .end $$ LANGUAGE plparrot; -CREATE FUNCTION test_char_out(text) RETURNS char AS $$ +CREATE FUNCTION test_char_out(char) RETURNS char AS $$ .sub foo_char_out - $S1 = 'blue' + $S1 = 'b' .return($S1) .end $$ LANGUAGE plparrot; @@ -106,8 +106,8 @@ select is(test_varchar_in('cheese'::text), 'cheese', 'We can pass a varchar in') select is(test_varchar_out('cheese'::text), 'blue', 'We can return a varchar'); select is(test_int_float(42,6.9), 1, 'We can pass an int and float as arguments'); -select is(test_char_in('cheese'::text), 'cheese', 'We can pass a char in'); -select is(test_char_out('cheese'::text), 'blue', 'We can return a char'); +select is(test_char_in('c'), 'c', 'We can pass a char in'); +select is(test_char_out('c'), 'b', 'We can return a char'); select is(test_int_in(42),1,'We can pass in an int'); select is(test_int_out(1),42,'We can return an int');