Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to know if someone changed one or more fields
Message
 
 
To
26/03/2024 14:23:47
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01687771
Message ID:
01687789
Views:
36
Likes (1)
>>>>>>>Is there a way for user "A" to know if any other user modified the same record (the same or other fields), and for the application to know and notify the user of those changes? Then, user "A" decides whether or not to overwrite those previous changes.
>>>>>>
>>>>>>Check out these functions: GetNextModified(), GetFldState(), CURVAL(), and OLDVAL()
>>>>>
>>>>>Not sure oldval() would be enough, these functions compare the edited values against the last read values. The problem in this case is the value at the server, which is unknown at save time. One possible solution would be to have the wheretype=1 (if I remember correctly*), the one which compares not only the key against the serverside record, but also the oldval() values against it. So if the old value of the field is not the same as the value on server, the update will fail... and that's where it gets complicated, what to do then. One way would be to retrieve the record in its current state from the server into a separate cursor, then show the differences between it and the values we tried to save (ouch, lots of code to write), show them onscreen (more code...) and let the user decide what to do. If it's a text field, try to merge perhaps (ouch squared).
>>>>>
>>>>>* nope, it's 3
>>>>>3 or DB_KEYANDMODIFIED (from FOXPRO.H) - Includes the primary fields specified by the KeyFieldList property and other modified fields.
>>>>
>>>>Thanks Dragan, I'll give it a try.
>>>
>>>Hi Dragan, I tried your advice, but it didn't help me, then I changed the remote view's "SQL WHERE clause includes" criteria to 2 or DB_KEYANDUPDATABLE (from FOXPRO.H) and when I tried to save my changes it threw me an error message "Update conflict in cursor 'MyRemoteView'".
>>>
>>>Now, I still don't know how to know the field(s) changed by the other user. I tried with AERROR(myArray), it has 1 row, first column just gives an error number which is 1585, the second column says "Update conflict in cursor 'myRemoteView'.", third column has the name of my remote view, rest of columns are filled with 0 and nulls.
>>
>>You've just got to the point where it got complicated, see above. You now have just a way to detect that the serverside record has changed meanwhile, nothing else. The server will not tell you which fields are different. I'd like to have a db server which would, but AFAIK they don't.
>>To know what changed, you'd need to retrieve the current version of the record (into a separate cursor), then compare field by field with your current record etc etc, as described in that long paragraph with ouches and parentheses above. Life is tough.
>
>The last thing you explained is what I thought of, I mean, the separate cursor and so on. That would led me to ask if there are events in CursorAdapters, not views, that could do that job done, just before saving my changes.
>
>On the other hand I don't have a guide that let me develop using CursorAdapters instead of remote views. If anyone could help me with this last topic, that would be a big, big help.
>
>Thanks.

Here is my brief overview of how I use CA:
1. Like Dragan, I do not use the VFP builder.
2. There are 4-5 meta tables. For example:
my_tables.dbf which lists all tables the application uses
mycadict.dbf which - for each table - defines each column/field, the size, etc.
myidxdict.dbf which is a dictionary of all index tags for each table.
and maybe a couple of more meta tables.
3. I have a class library - dl_biz_base.vcx which has one class dl_biz_data_base. This class has all the Major methods that create a table class based on the top meta tables.
4. I have a class dl_dal_classes.vcx which has two classes:
dl_cursor_adapter
dl_dal_base
The class (above) dl_biz_data_base uses these classes when instantiating a class
5. The I have an application library - my_lib_biz_classes.vcx
In this library there is a class for each table of the application. For example, if I have a table customers, I will have a class customer_biz in the my_lib_biz_classes.vcx
The class customer_biz is based on the dl_biz_data_base where some properties have values (at design time) for this table.
6. I drop the class customer_biz on a form. That is all. The class gets all the data from the either VFP or SQL Server. And the form uses the cursor.
7. On save, the class my_biz_data_base method is called and the changes are stored in a table (e.g. myaudittable)
8. I can use the table myaudittable to create a report of all the changes done to each field.

HTH
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform