Hi, I've been experimenting with locking tables in oracle 8 using queries
like "lock table x in exclusive mode nowait".  In my stand-alone script,
using PEAR::DB objects, I am trying to lock a table for the duration of a
transaction, and using a second connection, attempt to take out the same

I would expect that a 2nd db connection would not be able to take out the
lock after the 1st one has acquired it, but it seems to work.  If I run the
same script twice (simultaneously), the 2nd script fails when it tries to
get the lock, as expected.

ie. I thought the following would output:

    got first lock
    can't get second lock

but instead i get:

    got first lock
    got second lock

and if run a second time while the first instance is sleeping:

    can't get first lock

Why does this behaviour occur?

require_once ('DB.php');
$conn1 = DB::connect("oci8://***");
$conn2 = DB::connect("oci8://***");


// Lock the table in session 1
if (DB::isError($conn1->query("lock table x in exclusive mode nowait")))
    echo "can't get first lock\n";
    echo $conn1->error;
    echo "got first lock\n";
    // Attempt to take out lock in another session - this succeeds as well
    if (DB::isError($conn2->query("lock table x in exclusive mode nowait")))
         echo "can't get second lock\n";
         echo $conn2->error;
         echo "got second lock\n";

// wait a bit so we can run the script again

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

Reply via email to