Automagically log changes in table

aspineux aspineux at gmail.com
Sun Mar 18 13:40:40 CET 2007


On 18 mar, 04:20, "George Sakkis" <george.sak... at gmail.com> wrote:
> On Mar 17, 7:59 pm, "aspineux" <aspin... at gmail.com> wrote:
>
> > Hi
>
> > You can get this using "triggers" and "stored procedures".
> > These are SQL engine dependent! This is available for long time with
> > postgress and only from version 5 with mysql.
> > This let you write SQL code (Procedure) that will be called when
> > "trigged" by an event like inserting new row, updating rows,
> > deleting ....
>
> I'd rather avoid triggers since I may have to deal with Mysql 4. Apart
> from that, how can a trigger know the current user ?

Because each user opening an web session will login to the SQL
database using it's own
login. That way you will be able to manage security at DB too. And the
trigger
will use the userid of the SQL session.

> This information
> is part of the context (e.g. an http request), not stored persistently
> somewhere. It should be doable at the framework/orm level but I'm
> rather green on Turbogears/SQLAlchemy.
>
> George

Maybe it will be easier to manage this in your web application.

it's not too dificulte to replace any

UPDATE persone
SET name = %{new_name}s
WHERE persone_id=%{personeid}

by something like

UPDATE persone
SET name = %{new_name}s, modified_by=%{user_id}s, modified_time=%
{now}s
WHERE persone_id=%{personeid}

BR




More information about the Python-list mailing list