I would like to create a little auditing mechanism for my tables in sqlite where any time a change is made to a table, i update 2 fields that show who changed the data and when.
We use a similar concept in our MS SQL Server databases.
But I’m wondering how I could implement this in sqlite. I’ve added 2 fields to the end of my table called updatedusername, and a updateddatetime field.
When end users sign into my web application and make changes, i can “insert” the user credentials along with any other data for the specific table…
But i’m wondering how i could accomplish the same thing with triggers.
Can anyone shed some light on this?
For example, if i were to set up a trigger, when a new record is inserted or existing data is updated, how would I supply the username of the person that logged into the app to make the change, instead of some generic web id that’s being used by my server….
Thanks.
SQLite doesn’t have the notion of users you’ll find in other databases, which means there’s no way to ask what user initiated an operation.
If the client has a user name on hand, you would have to make sure that every
INSERTandUPDATEprovided it:The time can be filled in automatically by a trigger since SQLite has functions that can provide that information.