I know how to do this in MySQL, but I have no clue what I'm doing wrong with UniDAC. Please help me what I have to change.
My code (shortened):
Code: Select all
procedure [...]
var
Query: TUniQuery;
begin
[...]
Query := TUniQuery.Create(Self);
Query.Connection := AppData.DatabaseConnection; // TUniConnection object
Query.SQL.Text := 'LOCK TABLES c_balance WRITE, c_change WRITE';
Query.Execute;
Query.SQL.Text := 'SELECT value FROM c_balance WHERE id = ' +
'(SELECT max(id) FROM c_balance)';
Query.Open;
Query.First;
if not Query.Eof then
[...]
Query.Close;
[...]
Query.SQL.Text := 'INSERT INTO c_balance (value, time) VALUES (:val, :time)';
Query.ParamByName('val').AsFloat := NewVal;
Query.ParamByName('time').AsString :=
FormatDateTime('yyyy-mm-dd HH:NN:SS', CurrentTimestamp);
Query.Execute;
Query.SQL.Text := 'INSERT INTO c_change (value, time, reason) '
+ 'VALUES (:value, :time, :reason)';
[...]
Query.Execute;
[...]
Query.SQL.Text := 'UNLOCK TABLES';
Query.Execute;
Query.Destroy;
[...]
end;
The code is working without the table locking ^^Table 'c_balance' was not locked with LOCK TABLES