Interbase and PHP locking (was: Interbase locking)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello everybody,

Some days ago I've posted a question about interbase locking. I've solved
the problem after searching at interbase developers network and php manuals.
Let me drop some line about my experiences...

Deadlock is when two (or more) transactions want update or delete a field
in the same table at the same time.
For cause a deadlock in Interbase do the following:

   $tr_id1 = ibase_trans();
   $tr_id2 = ibase_trans();

   $result = ibase_query($tr_id1, "UPDATE TEST SET FIELD_A=FIELD_C");
   echo "First result: $result<br>";
   ibase_commit($tr_id1);

   $result = ibase_query($tr_id2, "UPDATE TEST SET FIELD_A=FIELD_C");
   echo "Second result: $result<br>";

If you run this you can see that the second result will be false and you'll
get
an error about interbase deadlock. Thats all right about interbase his do
its best when doing this. This error must be handled by the application.

So simple complete the code above with some check and rollback, like this:

   $tr_id1 = ibase_trans();
   $tr_id2 = ibase_trans();

   $result = ibase_query($tr_id1, "UPDATE TEST SET FIELD_A=FIELD_C");
   echo "First result: $result<br>";
   ibase_commit($tr_id1);

   $result = 0;

   while (!$result) {
     $result = @ibase_query($tr_id2, "UPDATE TEST SET FIELD_A=FIELD_C");
     echo "Second result: $result<br>";
     if (!$result) {
       ibase_rollback($tr_id2);
       $tr_id2 = ibase_trans();
     }
   }


   ibase_commit($tr_id2);

This will works nicely, and you will see that the first query will fail but
the second
query (in another one transaction!) will be correct. The complete solution
is when you
write a function for the queries to runs in a transaction and its check.

Regards,


Tibor


--
Integranet Internet Service Provider Co. - www.integranet.hu
GnuPG fingerprint: 189C B343 71A8 C25F 7456  F46F D522 C34C ED7F A574
Koleszár Tibor, Director and Senior System Engineer, Debian Developer
koleszar@integranet.hu, oldw@debian.org, http://www.oldw.net



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux