Skip to content

Commit

Permalink
Code cleanup and fix signatures of test_char_* and test_varchar_* tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Apr 9, 2010
1 parent ad7dd1c commit dca15e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 10 additions & 7 deletions plparrot.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
}

14 changes: 7 additions & 7 deletions t/sql/test.sql
Expand Up @@ -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;
Expand All @@ -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');
Expand Down

0 comments on commit dca15e4

Please sign in to comment.