This topic is locked

Logging who's updating the records and time

8/4/2007 1:58:32 PM
PHPRunner General questions
D
darkstorm author

Hello,

I am working at a project and i'm trying to log the date-time (mm.dd.yyyy hh:mm) when the update was taken and who did it. I am not trying only to view the last update, but to be able to view all the updates that had taken place on a record.
If anyone can pin point where to look at and maybe give some advices, i would highly appreciate it.
Regards

H
hugolesme 8/4/2007

I think you have to do a trigger with update event and insert the data in another (audit) table with the same colums
Hugo. PostgreSQL

H
hugolesme 8/6/2007

CREATE OR REPLACE FUNCTION auditoria_update_articulo()

RETURNS "trigger" AS

$BODY$
BEGIN

IF TG_OP = 'UPDATE' THEN
INSERT INTO

articulo_auditoria

(idarticulo, articulodescripcion, idtipoarticulo, stockminimo, stockmaximo, idsucursal,

idmarca, idlinea, iddeposito, idgondola, idimpuesto, idunidadmedida, idunidadpeso, idtamano, idpublicadora, idtipoobraartistica,

creacion, modificacion, ano, peso, paginas, idmaterial, observacion, idusuario, "login", remote_host, remote_addr, motor, chassis,

especificaciones, estado, max_porc_desc_vta, cant_min_pedido, idcolor, alfanumerico, tasa_entrega_porc,

flete_gratis_local, flete_gratis_externo, min_exigido_prov, idpais, comis_adic, cod_proveedor, se_vende_en_internet,

secuencia, path_image, contenido, empaque, serie, desc_global, idmodelo, idfamilia, idsubseccion, idseccion, idarea, art_local_import,

modeloarticulo, precioventa, codbarra1, codbarra2, codbarra3, codbarra4, codbarra5, permitir_fraccionar_venta)
VALUES

(NEW.idarticulo, NEW.articulodescripcion, NEW.idtipoarticulo, NEW.stockminimo, NEW.stockmaximo, NEW.idsucursal, NEW.

idmarca, NEW.idlinea, NEW.iddeposito, NEW.idgondola, NEW.idimpuesto, NEW.idunidadmedida, NEW.idunidadpeso, NEW.idtamano, NEW.idpublicadora, NEW.idtipoobraartistica, NEW.

creacion, NEW.modificacion, NEW.ano, NEW.peso, NEW.paginas, NEW.idmaterial, NEW.observacion, NEW.idusuario, NEW."login", NEW.remote_host, NEW.remote_addr, NEW.motor, NEW.chassis, NEW.

especificaciones, NEW.estado, NEW. max_porc_desc_vta, NEW.cant_min_pedido, NEW.idcolor, NEW.alfanumerico, NEW.tasa_entrega_porc, NEW.

flete_gratis_local, NEW.flete_gratis_externo, NEW.min_exigido_prov, NEW.idpais, NEW.comis_adic, NEW.cod_proveedor, NEW.se_vende_en_internet, NEW.

secuencia, NEW.path_image, NEW.contenido, NEW.empaque, NEW.serie, NEW.desc_global, NEW.idmodelo, NEW.idfamilia, NEW.idsubseccion, NEW.idseccion, NEW.idarea, NEW.art_local_import, NEW.

modeloarticulo, NEW.precioventa, NEW.codbarra1, NEW.codbarra2, NEW.codbarra3, NEW.codbarra4, NEW.codbarra5, NEW.permitir_fraccionar_venta);
END IF;

RETURN NEW;
END;

$BODY$

LANGUAGE 'plpgsql' VOLATILE;

ALTER FUNCTION auditoria_update_articulo() OWNER TO postgres;

COMMENT ON FUNCTION auditoria_update_articulo() IS 'Auditoria que copia los datos de la Tabla Articulo hacia la Tabla Articulo Auditoria en caso de Update';

D
darkstorm author 8/6/2007

Hello Hugo, thanks for your input.
I have thought of using 2 tables, and to accomplish this, i am trying to work with some 2 small test tables.
I am using MySql as database support.
So i have 2 tables right
first table: customers

ID (INT, Primary Key)

Name( Varchar)

Id_RDSDB(varchar)

Operator(Varchar)

Date (datetime)

Called_Date(varchar)
2nd table : Session

crt(int, primary key)

Id_RDSDB(varchar)

Called_Date(varchar)

Operator(varchar)
What i am trying to do is when i edit and update the first table i want to record data to second table like this...

When someone updates the data on table customers the script must take ID_RDSDB and copy the modified value of it to the Session table to the appropiate field. then Called_date field from must take the value of Current_Timestamp or time(now) so i can store when the update was done, and in the last field the Operator who updated the record.
Now with this data that i have in Session table, i must update like this....
All the records in the Customer table with that unique ID_RDSDB field found in second must store in Called_Date the values:

Operator, Called_date(from session table).

Do you think that i can somehow accomplish this using phprunner functions, or with some custom code?
Thank you

H
hugolesme 8/6/2007

I think PHPRunner Suport can help you because I do everything with PostgreSQL Triggers and Functions with the Event UPDATE of the table
Hugo - From Paraguay
PHPRunner + PostgreSQL 8.2.4 + Apache 2.2 + VB.NET 2005

J
Jane 8/7/2007

Hi,
to update fields in another table use Before record updated event.

All entered values are stored in the $values array.

Also you can use Save new data in another table action as a sample.

D
darkstorm author 8/8/2007

Hello,

and thanks for the reply.
So far i have managed to create another table where i save the name of the operator who modifies the data, the timespamp when that occurs and the ID of the customer data beying edited..
i've done so by using after record update event and using the following code
global $conn;

$strSQLInsert = "insert into _sesiune (id_rdsdb, operator, data) select id_client, operator, now() from _clienti where" .$where;

db_exec($strSQLInsert,$conn);
_sesiune is the audit table.
Here is an output of the table
mysql> select * from _sesiune;

+-----+----------+-----------+---------------------+--------------------+

| reg | id_rdsdb | operator | data | CreatedByPHPRunner |

+-----+----------+-----------+---------------------+--------------------+

| 16 | 10034 | balan | 2007-08-08 20:18:23 | NULL |

| 15 | 10034 | balan | 2007-08-08 19:46:11 | NULL |

| 14 | 10034 | balan | 2007-08-08 19:29:15 | NULL |

| 17 | 10034 | balan | 2007-08-08 20:19:34 | NULL |

| 19 | 402311 | balan | 2007-08-08 21:06:13 | NULL |

| 20 | 402311 | balan | 2007-08-08 21:06:39 | NULL |

| 21 | 10034 | balan | 2007-08-08 21:10:35 | NULL |

| 22 | 10034 | balan | 2007-08-08 21:33:17 | NULL |

| 23 | 10034 | balan | 2007-08-08 21:33:22 | NULL |

+-----+----------+-----------+---------------------+--------------------+
My trouble now is to get the "data" entries into data_sunat column from _clienti table based on the id_rdsdb , which as you can see will have multiple records, and then i need to display the results on the appropriate field on the edit/list/view pages.
Kindest Regards,