Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Auditoria - Arquivo de LOG
Message
From
24/02/2003 10:09:08
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00756606
Message ID:
00756972
Views:
10
This message has been marked as the solution to the initial question of the thread.
>Thanks Hilmar for your replay...
>
>I'm so close that all I want... I make some tests here and I already can store the old values of all fields (Update and Delete) using a log table.
>
>But I can't get the values when I'm adding a new record...
>
>Take a look at this sample:
>
>* STEP 1 - Creating Database and Store Procedure
>Create Database MyDataBase
>Create Table Audit (Log M)
>Create Table Customer (Id I, Name C (20))
>Create Trigger On 'Customer' For Insert As MyAudit("I")
>Create Trigger On 'Customer' For Update As MyAudit("U")
>Create Trigger On 'Customer' For Delete As MyAudit("D")
Exactly the way I do it. Three different parameters for a single audit function.
>Function MyAudit
>   LParameter m.Mode
>   Set Textmerge On NoShow
>   Set Textmerge To Memvar m.Log
>   \<<Alias()>> <<Datetime()>> <<m.Mode>>
>   For m.NoField = 1 To Fcount()
>       \<<Field(m.NoField)>>:<<Transform(Evaluate(Field(m.NoField)))>>
>   EndFor
>   Set Textmerge To
>   Set Textmerge Off
>   Insert Into Audit (LogBDD) Values (m.LogBDD)
>EndFunc
>* STEP 2 - Inserting Data Into Table Customer
>A) Insert Into Customer (Id, Name) Values (1, "RODOLFO")
>B) Update Customer Where Id = 1 Where Name = "RODOLFO DUARTE"
>C) Delete From Customer Where Id = 1
>
>
>Now, my questions:
>
>Notice in example A, Evaluate(Field(m.NoCampo)) always returns .NULL. - I tried OLDVAL and CURVAL functions, but it just works when you are using views or buffered tables... And this is not my case.

When inserting a new record, there is no old value; therefore, it is quite logical that oldval(...) returns NULL. You should make your audit function a little more sophisticated: when adding a value, you should show the new value, but not the old value.

>Notice in example B, Evaluate(Field(m.NoCampo)) always returns the OLD VALUE (in this case 1 and "RODOLFO")... I can't get the NEW VALUE (1 and "RODOLFO DUARTE")

The new value should be accessed directly through the fieldname, the old value, through oldval("FieldName"). I don't see oldval() in your UDF.

The VFP documentation for this function is confusing. It states - or seems to state - that oldval() only works on buffered tables. This is not the case. Oldval() works quite well with unbuffered tables - the only problem you would have is that if you have multiple REPLACE commands, you would get multiple entries into the audit table.

>And, finally, in example C, all works fine, because I have the values when the record has been deleted.

For the deleted case, you should also use oldval(), in case the user has changed the value and THEN deleted the record.

>Important: I can't change my app to use buffered tables or views... I must use just this kind of commands: INSERT, UPDATE and DELETE (SQL) ...

You don't need to do so. See above.

>Other question... I don't like MEMO fields because they broken down easily... Do you know other type of file that I could store this information?
>Could you help me.... ;-)

I use memo fields whenever it makes sense to do so. There is simply no practical alternative for variable-sized text. In some cases, you could keep the information in separate files (one text file, etc., instead of each memo field), but that is too much trouble, IMO.

>I just write in English to make the things easier for you! ;-)

Thanks, but Michel asks us not to change the language of the thread (he must have though specifically about me when he wrote this...). The alternative, in this case, would have been to start a new thread directed at me. OTOH, I can read Portuguese quite well, but I have some difficulty writing it, as you are surely aware. If I know the other person knows English well enough, I might insert words I don't know in English, in parentheses or something...

Regards,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform