Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/commandprompt/PL-php
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Klyukin committed May 21, 2011
2 parents 8d63079 + 74bab22 commit 8381096
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions expected/trigger.out
Expand Up @@ -61,6 +61,16 @@ NOTICE: plphp: trigger: trigtest8 table: trigfunc_table, level: ROW event: AFTE
NOTICE: plphp: trigger: trigtest8 table: trigfunc_table, level: ROW event: AFTER DELETE old val: 2
NOTICE: plphp: trigger: trigtest8 table: trigfunc_table, level: ROW event: AFTER DELETE old val: 2
NOTICE: plphp: trigger: trigtest11 table: trigfunc_table, level: STATEMENT event: AFTER DELETE
-- Do we get the schema?
CREATE FUNCTION trigfunc2() RETURNS trigger LANGUAGE plphp AS $$
$extra = "";

pg_raise('notice', "schema: ${_TD['schemaname']} table: ${_TD['relname']}");
$$;
create schema "the schema" create table "the table" (a int);
create trigger trig2test after insert on "the schema"."the table" for each row execute procedure trigfunc2();
insert into "the schema"."the table" values (4);
NOTICE: plphp: schema: the schema table: the table
-- Add an additional attribute to NEW
CREATE FUNCTION trigfunc_test1() RETURNS trigger LANGUAGE plphp AS $$
$_TD['new']['a'] = 'foo';
Expand Down
7 changes: 7 additions & 0 deletions plphp.c
Expand Up @@ -760,6 +760,7 @@ plphp_trig_build_args(FunctionCallInfo fcinfo)
add_assoc_string(retval, "name", tdata->tg_trigger->tgname, 1);
add_assoc_long(retval, "relid", tdata->tg_relation->rd_id);
add_assoc_string(retval, "relname", SPI_getrelname(tdata->tg_relation), 1);
add_assoc_string(retval, "schemaname", SPI_getnspname(tdata->tg_relation), 1);

/* EVENT */
if (TRIGGER_FIRED_BY_INSERT(tdata->tg_event))
Expand Down Expand Up @@ -1552,6 +1553,12 @@ plphp_func_build_args(plphp_proc_desc *desc, FunctionCallInfo fcinfo TSRMLS_DC)
{
char *tmp;

/*
* TODO room for improvement here: instead of going through the
* output function, figure out if we can just use the native
* representation to pass to PHP.
*/

tmp =
DatumGetCString(FunctionCall3
(&(desc->arg_out_func[i]),
Expand Down
11 changes: 11 additions & 0 deletions sql/trigger.sql
Expand Up @@ -44,6 +44,17 @@ update trigfunc_table set a = 2 where a = 1;

delete from trigfunc_table where a = 2;

-- Do we get the schema?
CREATE FUNCTION trigfunc2() RETURNS trigger LANGUAGE plphp AS $$
$extra = "";

pg_raise('notice', "schema: ${_TD['schemaname']} table: ${_TD['relname']}");
$$;

create schema "the schema" create table "the table" (a int);
create trigger trig2test after insert on "the schema"."the table" for each row execute procedure trigfunc2();
insert into "the schema"."the table" values (4);

-- Add an additional attribute to NEW
CREATE FUNCTION trigfunc_test1() RETURNS trigger LANGUAGE plphp AS $$
$_TD['new']['a'] = 'foo';
Expand Down

0 comments on commit 8381096

Please sign in to comment.