DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: Lock rows as readonly

  1. #1
    Join Date
    May 2001
    Posts
    8
    Hi.

    I have a question about locks.
    How can I prevent updates, if another users has a readonly cursor on the row ?

    Example
    I have two transactions which holds a cursor (read) on one row.
    How can I prevent that a third transaction updates this row ?

    Thanks in advance
    Olaf Oelsner



  2. #2
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    The one who wants to lock his rows must open a cursor with FOR UPDATE option, eg

    SELECT ..... FROM .... WHERE ... FOR UPDATE;

    This will lock all rows that meet the WHERE conditions.
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  3. #3
    Join Date
    Jun 2001
    Location
    Helsinki. Finland
    Posts
    3,938
    Start the 3rd transaction wih SET TRANSACTION READ ONLY;
    Thus it will not be able to update the rows.

  4. #4
    Join Date
    May 2001
    Posts
    8
    Thanks for your answers.

    The first and second transaction do only read operations.

    The third transaction should to check if the rows are in use by another transaction, before it tries to update.

    In other words:
    How can the a transaction check whether rows are currently red by another transactions.


  5. #5
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Originally posted by OOelsner
    In other words:
    How can the a transaction check whether rows are currently red by another transactions.
    No way to find this that I'm aware of, unless the rows are locked by the reading transaction.
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  6. #6
    Join Date
    Jun 2001
    Location
    Helsinki. Finland
    Posts
    3,938
    No way to find this that I'm aware of, unless the rows are locked by the reading transaction.
    I also think so. And moreover, if Jurij doesn't know a way, few are the people that might know!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width