Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit12cf0fd

Browse files
committed
Back out plperl OUT hash/array parameter patch, again.
1 parente0d6630 commit12cf0fd

File tree

3 files changed

+21
-286
lines changed

3 files changed

+21
-286
lines changed

‎src/pl/plperl/expected/plperl.out

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -468,112 +468,3 @@ SELECT * from perl_spi_prepared_set(1,2);
468468
4
469469
(2 rows)
470470

471-
---
472-
--- Some OUT and OUT array tests
473-
---
474-
CREATE OR REPLACE FUNCTION test_out_params(OUT a varchar, OUT b varchar) AS $$
475-
return { a=> 'ahoj', b=>'svete'};
476-
$$ LANGUAGE plperl;
477-
SELECT '01' AS i, * FROM test_out_params();
478-
i | a | b
479-
----+------+-------
480-
01 | ahoj | svete
481-
(1 row)
482-
483-
CREATE OR REPLACE FUNCTION test_out_params_array(OUT a varchar[], OUT b varchar[]) AS $$
484-
return { a=> ['ahoj'], b=>['svete']};
485-
$$ LANGUAGE plperl;
486-
SELECT '02' AS i, * FROM test_out_params_array();
487-
ERROR: array value must start with "{" or dimension information
488-
CREATE OR REPLACE FUNCTION test_out_params_set(OUT a varchar, out b varchar) RETURNS SETOF RECORD AS $$
489-
return_next { a=> 'ahoj', b=>'svete'};
490-
return_next { a=> 'ahoj', b=>'svete'};
491-
return_next { a=> 'ahoj', b=>'svete'};
492-
$$ LANGUAGE plperl;
493-
SELECT '03' AS I,* FROM test_out_params_set();
494-
i | a | b
495-
----+------+-------
496-
03 | ahoj | svete
497-
03 | ahoj | svete
498-
03 | ahoj | svete
499-
(3 rows)
500-
501-
CREATE OR REPLACE FUNCTION test_out_params_set_array(OUT a varchar[], out b varchar[]) RETURNS SETOF RECORD AS $$
502-
return_next { a=> ['ahoj'], b=>['velky','svete']};
503-
return_next { a=> ['ahoj'], b=>['velky','svete']};
504-
return_next { a=> ['ahoj'], b=>['velky','svete']};
505-
$$ LANGUAGE plperl;
506-
SELECT '04' AS I,* FROM test_out_params_set_array();
507-
ERROR: error from Perl function: array value must start with "{" or dimension information at line 2.
508-
DROP FUNCTION test_out_params();
509-
DROP FUNCTION test_out_params_set();
510-
DROP FUNCTION test_out_params_array();
511-
DROP FUNCTION test_out_params_set_array();
512-
-- one out argument can be returned as scalar or hash
513-
CREATE OR REPLACE FUNCTION test01(OUT a varchar) AS $$
514-
return 'ahoj';
515-
$$ LANGUAGE plperl ;
516-
SELECT '01' AS i,* FROM test01();
517-
i | a
518-
----+------
519-
01 | ahoj
520-
(1 row)
521-
522-
CREATE OR REPLACE FUNCTION test02(OUT a varchar[]) AS $$
523-
return {a=>['ahoj']};
524-
$$ LANGUAGE plperl;
525-
SELECT '02' AS i,a[1] FROM test02();
526-
ERROR: array value must start with "{" or dimension information
527-
CREATE OR REPLACE FUNCTION test03(OUT a varchar[]) RETURNS SETOF varchar[] AS $$
528-
return_next { a=> ['ahoj']};
529-
return_next { a=> ['ahoj']};
530-
return_next { a=> ['ahoj']};
531-
$$ LANGUAGE plperl;
532-
SELECT '03' AS i,* FROM test03();
533-
ERROR: error from Perl function: array value must start with "{" or dimension information at line 2.
534-
CREATE OR REPLACE FUNCTION test04() RETURNS SETOF VARCHAR[] AS $$
535-
return_next ['ahoj'];
536-
return_next ['ahoj'];
537-
$$ LANGUAGE plperl;
538-
SELECT '04' AS i,* FROM test04();
539-
ERROR: error from Perl function: array value must start with "{" or dimension information at line 2.
540-
CREATE OR REPLACE FUNCTION test05(OUT a varchar) AS $$
541-
return {a=>'ahoj'};
542-
$$ LANGUAGE plperl;
543-
SELECT '05' AS i,a FROM test05();
544-
i | a
545-
----+-----------------
546-
05 | HASH(0x8558f9c)
547-
(1 row)
548-
549-
CREATE OR REPLACE FUNCTION test06(OUT a varchar) RETURNS SETOF varchar AS $$
550-
return_next { a=> 'ahoj'};
551-
return_next { a=> 'ahoj'};
552-
return_next { a=> 'ahoj'};
553-
$$ LANGUAGE plperl;
554-
SELECT '06' AS i,* FROM test06();
555-
i | a
556-
----+-----------------
557-
06 | HASH(0x8559230)
558-
06 | HASH(0x8559230)
559-
06 | HASH(0x8559230)
560-
(3 rows)
561-
562-
CREATE OR REPLACE FUNCTION test07() RETURNS SETOF VARCHAR AS $$
563-
return_next 'ahoj';
564-
return_next 'ahoj';
565-
$$ LANGUAGE plperl;
566-
SELECT '07' AS i,* FROM test07();
567-
i | test07
568-
----+--------
569-
07 | ahoj
570-
07 | ahoj
571-
(2 rows)
572-
573-
DROP FUNCTION test01();
574-
DROP FUNCTION test02();
575-
DROP FUNCTION test03();
576-
DROP FUNCTION test04();
577-
DROP FUNCTION test05();
578-
DROP FUNCTION test06();
579-
DROP FUNCTION test07();

‎src/pl/plperl/plperl.c

Lines changed: 21 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plperl.c - perl as a procedural language for PostgreSQL
33
*
4-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.116 2006/08/1302:37:11 momjian Exp $
4+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.117 2006/08/1317:31:10 momjian Exp $
55
*
66
**********************************************************************/
77

@@ -52,7 +52,6 @@ typedef struct plperl_proc_desc
5252
FmgrInforesult_in_func;/* I/O function and arg for result type */
5353
Oidresult_typioparam;
5454
intnargs;
55-
intnum_out_args;/* number of out arguments */
5655
FmgrInfoarg_out_func[FUNC_MAX_ARGS];
5756
boolarg_is_rowtype[FUNC_MAX_ARGS];
5857
SV*reference;
@@ -116,9 +115,6 @@ static SV *plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc);
116115
staticvoidplperl_init_shared_libs(pTHX);
117116
staticHV*plperl_spi_execute_fetch_result(SPITupleTable*,int,int);
118117

119-
staticSV*plperl_convert_to_pg_array(SV*src);
120-
staticSV*plperl_transform_result(plperl_proc_desc*prodesc,SV*result);
121-
122118
/*
123119
* This routine is a crock, and so is everyplace that calls it. The problem
124120
* is that the cached form of plperl functions/queries is allocated permanently
@@ -408,12 +404,7 @@ plperl_build_tuple_result(HV *perlhash, AttInMetadata *attinmeta)
408404
(errcode(ERRCODE_UNDEFINED_COLUMN),
409405
errmsg("Perl hash contains nonexistent column \"%s\"",
410406
key)));
411-
412-
/* if value is ref on array do to pg string array conversion */
413-
if (SvTYPE(val)==SVt_RV&&
414-
SvTYPE(SvRV(val))==SVt_PVAV)
415-
values[attn-1]=SvPV(plperl_convert_to_pg_array(val),PL_na);
416-
elseif (SvOK(val)&&SvTYPE(val)!=SVt_NULL)
407+
if (SvOK(val)&&SvTYPE(val)!=SVt_NULL)
417408
values[attn-1]=SvPV(val,PL_na);
418409
}
419410
hv_iterinit(perlhash);
@@ -690,7 +681,12 @@ plperl_validator(PG_FUNCTION_ARGS)
690681
HeapTupletuple;
691682
Form_pg_procproc;
692683
charfunctyptype;
684+
intnumargs;
685+
Oid*argtypes;
686+
char**argnames;
687+
char*argmodes;
693688
boolistrigger= false;
689+
inti;
694690

695691
/* Get the new function's pg_proc entry */
696692
tuple=SearchSysCache(PROCOID,
@@ -718,6 +714,18 @@ plperl_validator(PG_FUNCTION_ARGS)
718714
format_type_be(proc->prorettype))));
719715
}
720716

717+
/* Disallow pseudotypes in arguments (either IN or OUT) */
718+
numargs=get_func_arg_info(tuple,
719+
&argtypes,&argnames,&argmodes);
720+
for (i=0;i<numargs;i++)
721+
{
722+
if (get_typtype(argtypes[i])=='p')
723+
ereport(ERROR,
724+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
725+
errmsg("plperl functions cannot take type %s",
726+
format_type_be(argtypes[i]))));
727+
}
728+
721729
ReleaseSysCache(tuple);
722730

723731
/* Postpone body checks if !check_function_bodies */
@@ -1120,8 +1128,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
11201128
/* Return a perl string converted to a Datum */
11211129
char*val;
11221130

1123-
perlret=plperl_transform_result(prodesc,perlret);
1124-
11251131
if (prodesc->fn_retisarray&&SvROK(perlret)&&
11261132
SvTYPE(SvRV(perlret))==SVt_PVAV)
11271133
{
@@ -1250,6 +1256,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
12501256
charinternal_proname[64];
12511257
intproname_len;
12521258
plperl_proc_desc*prodesc=NULL;
1259+
inti;
12531260
SV**svp;
12541261

12551262
/* We'll need the pg_proc tuple in any case... */
@@ -1312,12 +1319,6 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
13121319
Datumprosrcdatum;
13131320
boolisnull;
13141321
char*proc_source;
1315-
inti;
1316-
intnumargs;
1317-
Oid*argtypes;
1318-
char**argnames;
1319-
char*argmodes;
1320-
13211322

13221323
/************************************************************
13231324
* Allocate a new procedure description block
@@ -1336,25 +1337,6 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
13361337
prodesc->fn_readonly=
13371338
(procStruct->provolatile!=PROVOLATILE_VOLATILE);
13381339

1339-
1340-
/* Disallow pseudotypes in arguments (either IN or OUT) */
1341-
/* Count number of out arguments */
1342-
numargs=get_func_arg_info(procTup,
1343-
&argtypes,&argnames,&argmodes);
1344-
for (i=0;i<numargs;i++)
1345-
{
1346-
if (get_typtype(argtypes[i])=='p')
1347-
ereport(ERROR,
1348-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1349-
errmsg("plperl functions cannot take type %s",
1350-
format_type_be(argtypes[i]))));
1351-
1352-
if (argmodes&&argmodes[i]==PROARGMODE_OUT)
1353-
prodesc->num_out_args++;
1354-
1355-
}
1356-
1357-
13581340
/************************************************************
13591341
* Lookup the pg_language tuple by Oid
13601342
************************************************************/
@@ -1694,8 +1676,6 @@ plperl_return_next(SV *sv)
16941676
fcinfo=current_call_data->fcinfo;
16951677
rsi= (ReturnSetInfo*)fcinfo->resultinfo;
16961678

1697-
sv=plperl_transform_result(prodesc,sv);
1698-
16991679
if (!prodesc->fn_retisset)
17001680
ereport(ERROR,
17011681
(errcode(ERRCODE_SYNTAX_ERROR),
@@ -1773,16 +1753,7 @@ plperl_return_next(SV *sv)
17731753

17741754
if (SvOK(sv)&&SvTYPE(sv)!=SVt_NULL)
17751755
{
1776-
char*val;
1777-
SV*array_ret;
1778-
1779-
if (SvROK(sv)&&SvTYPE(SvRV(sv))==SVt_PVAV )
1780-
{
1781-
array_ret=plperl_convert_to_pg_array(sv);
1782-
sv=array_ret;
1783-
}
1784-
1785-
val=SvPV(sv,PL_na);
1756+
char*val=SvPV(sv,PL_na);
17861757

17871758
ret=InputFunctionCall(&prodesc->result_in_func,val,
17881759
prodesc->result_typioparam,-1);
@@ -2397,46 +2368,3 @@ plperl_spi_freeplan(char *query)
23972368

23982369
SPI_freeplan(plan);
23992370
}
2400-
2401-
/*
2402-
* If plerl result is hash and fce result is scalar, it's hash form of
2403-
* out argument. Then, transform it to scalar
2404-
*/
2405-
2406-
staticSV*
2407-
plperl_transform_result(plperl_proc_desc*prodesc,SV*result)
2408-
{
2409-
boolexactly_one_field= false;
2410-
HV*hvr;
2411-
SV*val;
2412-
char*key;
2413-
I32klen;
2414-
2415-
2416-
if (prodesc->num_out_args==1&&SvOK(result)
2417-
&&SvTYPE(result)==SVt_RV&&SvTYPE(SvRV(result))==SVt_PVHV)
2418-
{
2419-
hvr= (HV*)SvRV(result);
2420-
hv_iterinit(hvr);
2421-
2422-
while ((val=hv_iternextsv(hvr,&key,&klen)))
2423-
{
2424-
if (exactly_one_field)
2425-
ereport(ERROR,
2426-
(errcode(ERRCODE_UNDEFINED_COLUMN),
2427-
errmsg("Perl hash contains nonexistent column \"%s\"",
2428-
key)));
2429-
exactly_one_field= true;
2430-
result=val;
2431-
}
2432-
2433-
if (!exactly_one_field)
2434-
ereport(ERROR,
2435-
(errcode(ERRCODE_UNDEFINED_COLUMN),
2436-
errmsg("Perl hash is empty")));
2437-
2438-
hv_iterinit(hvr);
2439-
}
2440-
2441-
returnresult;
2442-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp