How to use Firebird WITH LOCK with Delphi FireDac

2

I am trying to block a table on my system in order to prevent other users from entering the system when the procedure is running, how can I do this using the "WITH LOCK" / strong> with "FireDac" ?

  • Does this eating lock the table for writing or also blocks for preview ?
  • If you block for preview and write , how to use it correctly?
  • How to identify via Delphi that the table or registry is locked?
asked by anonymous 16.11.2017 / 19:15

2 answers

1

After So Trying I solved the question. In order to work in FireDac you will have to disable AutoCommit ex: FDConnection1.TxOptions.AutoCommit := False; .

  • P - This eating locks the table for recording or also locks to view?

  • R - The WITH LOCK command blocks the lines that will be fetched in a SQL statement as @Lucas de Souza Cruz said. ex: SELECT * FROM TABELA WHERE FIELD1=VALUE WITH LOCK and unlocks when a command COMMIT or ROLLBACK the command WITH LOCK does not lock for visualization.

    P - If I block for viewing and recording, how do I use it correctly?

    R - The WITH LOCK command only blocks for Recording as above and does not block for viewing.

    P - How to identify via Delphi that the table or registry is locked?

  • R - To test just try to insert or edit the table if it displays a message like this:
  

run caused by system error that does not preclude successful   execution of subsequent statements. Lock conflict on no wait   transaction.

The table row is locked. You can do exception handling to avoid message in English ... It goes from the imagination of each.

    
23.11.2017 / 15:02
2

I found in this FireBird documentation , the correct way to use this command. The documentation talks about some caution when using this command. From what I read in the documentation, it returns a compromised line if it uses WITH LOCK .

I have read in some non-official Firebird forums that the lines are automatically "released" when performing commit or rollback in the transaction. That is, it does not lock tables, but rather lines that have been SQL of WITH LOCK executed.

Unfortunately, I do not have much experience with Firebird, so in a way, it's very complicated to say all the impacts of using this command in your application. Perhaps as a contour solution and less impact on your system and database, using a flag within the database (in a parameter table, for example) would make the process simpler.

For example, if this column is as TRUE , the system would return a message stating that it is not ready to connect because it is undergoing an update process.

I hope I have helped.

    
20.11.2017 / 12:09