Re: No me funciona Trigger de Auditoria

From: "Mario Soto" <msotocl(at)gmail(dot)com>
To: "WILLIAM PARRA" <wilparra(at)yahoo(dot)com>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: No me funciona Trigger de Auditoria
Date: 2006-12-14 17:06:30
Message-ID: e9b17cde0612140906t11c6a59cj736ae3c5142b929d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Hola, la funcion a la cual haces mencion es generica, pero para que
funcione, debes crear dicha funcion para cada tabla que quieras
auditar., de igual modo los disparadores que lanzan la funcion deben
estar asociados a cada tabla que quieras auditar.

Con pl/pgsql, no se puede hacer lo que quieres, debes colocar en la
funcion explicitamente el campo que quieres auditar.

Cualquier cosa me avisas

El 13/12/06, WILLIAM PARRA<wilparra(at)yahoo(dot)com> escribió:
> Compañeros de lista:
>
> No he logrado conseguir que funcione el siguiente trigger que tomé de la
> lista... Creo que lo Hizo Mario Soto.
>
> CREATE OR REPLACE FUNCTION AUDITOR_TABLAS () RETURNS TRIGGER
> AS '
> DECLARE
> CONSULTA varchar;
> fecha timestamp;
> tipo varchar;
> cols record;
> usuario varchar;
> id integer;
> pid integer;
> columna varchar;
> BEGIN
> select into fecha current_timestamp(0);
> -- INSERTA LA IP DEL EQUIPO DEL USUARIO
> select into usuario inet_client_addr();
> --select into usuario user;
> select into pid pg_backend_pid();
> IF TG_OP = ''INSERT'' THEN
> tipo:=''I'';
> select into id new.oid;
> END IF;
> IF TG_OP = ''UPDATE'' THEN
> tipo:=''U'';
> select into id old.oid;
> END IF;
>
> FOR cols IN
> select attname as nombre,
> attnum as numero
> from pg_attribute
> where attrelid = TG_RELID
> and attnum > 0
> and NOT attisdropped
> LOOP
> IF NEW. || cols.nombre || <> OLD. || cols.nombre || THEN
> INSERT INTO auditoria
> (TIPO,FECHA,USUARIO,TABLA,CAMPO,NOMBRE1,NOMBRE2,NOMBRE3,PID)
> values
> (tipo,fecha,usuario,TG_RELNAME,id,cols.nombre,cols.nombre,cols.nombre,pid);
> END IF;
> END LOOP;
> RETURN NEW;
> END;
> '
> LANGUAGE plpgsql;
>
> Este es el script de la tabla de audoitoria
>
> CREATE TABLE AUDITORIA
> (
> CODIGO_AUDITA serial NOT NULL,
> TIPO CHAR(1),
> FECHA TIMESTAMP,
> USUARIO VARCHAR(20),
> TABLA VARCHAR(30),
> CAMPO VARCHAR(30),
> PID VARCHAR(30)
> )
> /
> Y el siguiente es el Trigger que cree sobre una tabla parentesco
>
> CREATE TRIGGER AUDITOR_PARENTESCO
> AFTER INSERT OR UPDATE OR DELETE ON PARENTESCO
> FOR EACH ROW EXECUTE PROCEDURE AUDITOR_TABLAS();
> Al tratar de efectuar un Insert en parentesco, este es el error que me
> saca...
> Y realmente no sé de que se trate el error.
>
> ERROR: record "old" is not assigned yet
> Detail: The tuple structure of a not-yet-assigned record is indeterminate.
> Line: 1 
>
> Y este el error cuando trato de efectuar un Delete
>
> record "new" is not assigned yet
> Detail: The tuple structure of a not-yet-assigned record is indeterminate.
> Line: 1 
>
> Y este cuando trato de efectuar un Update
>
> ERROR: syntax error at or near "||"
> Line: 1
>
> Gracias compañeros por sus aportes
>
> Saludos,
>
>
>
>
> Lo creo En Windows, y no saca error, pero cuando
>
>
> William Enrique Parra Alba
> Ingeniero De Sistemas
> Universidad Pedagógica y Tecnológica de Colombia
> /\ /\
> / //\\ \
> \ \\// /
> / / \ \
> \/ \/
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> Regístrate ya - http://correo.espanol.yahoo.com/

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Juan Carlos Azogue 2006-12-14 20:59:15 Ayuda con fechas
Previous Message Patricio Cifuentes Ithal 2006-12-14 16:45:11 RE: Autovacuum