Print Thread
Trouble with Locking, Checking and Refreshing in OnApplyRecord
#59349 01/10/19 01:53 PM
Joined: Feb 2018
Posts: 16
M
Member
OP Offline
Member
M
Joined: Feb 2018
Posts: 16
Hello

All tables in my database have a column called ID with primary key on it and I need to use that column instead of ROWID.
Some views with joined tables include that column and I'd like to be able to their refresh records without ROWID.

Most of my DataSet queries look like this:

SELECT * FROM TABLE/VIEW;

I successfully overruled Insert, Update and Delete actions in OnApplyRecord, but I cannot figure out how to properly handle the rest.

Here is what I'm doing:
Code
  case Action of
    'L':
    begin
      S := 'SELECT * FROM ' + Sender.GetUpdatingTable + ' WHERE ID = :OLD_ID FOR UPDATE NOWAIT';
      DMLQuery.SQL.Text := S;
      Sender.DeclareQueryVariables(DMLQuery);
      Sender.SetQueryVariables(DMLQuery);
      DMLQuery.Execute;
      Applied := True;
    end;
    'C':
    begin
      S := 'SELECT * FROM ' + Sender.GetUpdatingTable + ' WHERE ID = :OLD_ID';
      DMLQuery.SQL.Text := S;
      Sender.DeclareQueryVariables(DMLQuery);
      Sender.SetQueryVariables(DMLQuery);
      DMLQuery.Execute;
      if not Sender.CompareQueryVariables(DMLQuery) then
        raise Exception.Create('Record has been modified by another user');
      Applied := True;
    end;
    'R':
    begin
      S := 'SELECT * FROM ' + Sender.GetUpdatingTable + ' WHERE ID = :ID';
      DMLQuery.SQL.Text := S;
      Sender.DeclareQueryVariables(DMLQuery);
      Sender.SetQueryVariables(DMLQuery);
      DMLQuery.Execute;
      Sender.GetQueryVariables(DMLQuery);
      Applied := True;
    end;
Refresh doesn't work because the code declares and sets only the 'ID' variable. After query execution GetQueryVariables will apply only the value of 'ID' variable.
Check doesn't work either, because it compares variables - not common fields.

If I want to refresh and check common fields then should I iterate over FieldNames and set(or compare) the values manually? Or is this a wrong approach to the solution? (disregarding the fact that life would be easier if I simply used RowId but it's not possible for me at the moment..)

Last edited by Matt Ors; 01/10/19 04:58 PM.
Re: Trouble with Locking, Checking and Refreshing in OnApplyRecord
Matt Ors #59350 01/11/19 10:29 AM
Joined: Aug 1999
Posts: 22,201
Member
Offline
Member
Joined: Aug 1999
Posts: 22,201
For the "Refresh" action you will need to copy the field values of the query to the dataset fields. The GetQueryVariables procedure cannot be used, because it only copies the variable values as you noted.


Marco Kalter
Allround Automations
Re: Trouble with Locking, Checking and Refreshing in OnApplyRecord
Marco Kalter #59377 01/15/19 02:20 PM
Joined: Feb 2018
Posts: 16
M
Member
OP Offline
Member
M
Joined: Feb 2018
Posts: 16
I wrote a procedure based on GetQueryVariables that works on fields instead and it works! Thank you.


Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.032s Queries: 15 (0.007s) Memory: 2.5043 MB (Peak: 3.0380 MB) Data Comp: Off Server Time: 2024-04-23 13:20:45 UTC
Valid HTML 5 and Valid CSS