Exclusive access to a table in firebird Has How?

2

Would you like to open a table in Exclusive mode in Firebird by Delphi preventing other users from opening the Table?

I use Delphi 10.1 and FireDac to connect to the database.

    
asked by anonymous 08.11.2017 / 12:52

2 answers

1

I was able to do this:

// Eu desativei o "AutoCommit" pois sem desativar não Funciona.
DM.TFDConnection.TxOptions.AutoCommit := False;
DM.TFDQuery.Close;
DM.TFDQuery.SQL.Clear;
// Trava a Linha da tabela com essa SQL
vSql := 'SELECT * FROM TABELA '+
        'WHERE FIELD1 = FIELD1 WITH LOCK';
DM.TFDQuery.SQL.Add(vSql);
DM.TFDQuery.Open;
{ Aqui você faz o que tem que fazer antes de Desbloquear}
  Depois destarva Com "COMMIT" ou "ROLLBACK"
DM.TFDConnection.TxOptions.AutoCommit := True;

I hope I have helped.

    
28.11.2017 / 18:24
5

You need to have good transactional control to succeed with this type of treatment.

Use with lock and a lock on table data is prevented, preventing changes or deletions of selected data!

Ex:

Lock a record: SELECT * FROM CLIENTES WHERE CODIGO = 255 WITH LOCK so the Code 255 client will be locked for changes / deletions.

For the entire table do not use filters.

Source: Firebird.Org

    
08.11.2017 / 17:17