ERROR: can't read "tgname": no such variable

From: Cesar A <cesar(dot)carbonara(at)gmail(dot)com>
To: pgsql-es-ayuda(at)postgresql(dot)org
Subject: ERROR: can't read "tgname": no such variable
Date: 2011-04-08 14:37:42
Message-ID: BANLkTikP5VSVXnadDpzP_ArONZhN3iTBxg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Saludos

Tengo una función de auditoría similar a [0], hasta ahora, la estoy
"personalizando" y va funcionando.
Estoy agregando otra función que chequee X intentos fallidos para bloquear
el usuario:

CREATE OR REPLACE FUNCTION check_login(uname TEXT, pass TEXT)
RETURNS SETOF usuarios AS $$
DECLARE
passed BOOLEAN;
inten INTEGER;
BEGIN
SELECT (clave = $2) INTO passed
FROM usuarios
WHERE usuario = $1;

IF (passed = false) THEN
UPDATE usuarios SET intento = (intento + 1) WHERE usuario = $1;

SELECT intento INTO inten FROM usuarios WHERE usuario = $1;

IF (inten = 3) THEN
UPDATE usuarios SET activo = false WHERE usuario = $1;
END IF;
RETURN;
ELSE
UPDATE usuarios SET intento = 0 WHERE usuario = $1;
RETURN QUERY SELECT * FROM usuarios WHERE usuario = $1;
END IF;

RETURN;
END;
$$ LANGUAGE plpgsql
SECURITY DEFINER;

La tabla usuarios también tiene el disparador de la auditoría.

Al agregarle la función check_login al sistema, y hacer login, me devuelve:

ERROR: can't read "tgname": no such variable
CONTEXT: can't read "tgname": no such variable
while executing
"spi_exec "SELECT nspname AS scname FROM pg_namespace AS n JOIN pg_class AS
c ON c.relnamespace = n.oid WHERE c.relname = '$tgname'""
(procedure "__PLTcl_proc_909190_trigger_908521" line 15)
invoked from within
"__PLTcl_proc_909190_trigger_908521 trg_audit_log 908521 usuarios cc1 {{} id
tabla20_campo2 usuario clave default_mask nivel_acceso fregistro activo
us..."
in PL/Tcl function "log_to_audit_table"
sentencia SQL: «UPDATE cc1.usuarios SET intento = 0 WHERE usuario = $1 »
PL/pgSQL function "check_login" line 19 at SQL statement

Entiendo por el mensaje que como estoy haciendo un UPDATE dentro de la
función y no se dispara el trigger? cómo debería hacerse?

[0]http://www.alberton.info/postgresql_table_audit.html

--
--
Sí no eres parte de la solución... eres parte del problema.
--
... y no dejes de leer:
Netiqueta: Conjunto de reglas que regulan la conducta del usuario en
internet
http://es.wikibooks.org/wiki/Netiquette
--
Cesar A. Carbonara R.
C.I. Nº V.11.952.572
--
Usuario Linux 377997
www.gulmer.org.ve

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Cesar A 2011-04-08 14:52:49 Re: ERROR: can't read "tgname": no such variable
Previous Message Alvaro Herrera 2011-04-08 14:33:25 RE: Error createlang plperlu