Oracle Database Lock Issue

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Oracle Database Lock Issue

    Hi,

    I have a SQL statement that I execute obn Oracle 9i Database:

    select lnum from parolee
    Where lNUM='#trim(UCase(Form.fnum))#'
    FOR UPDATE NOWAIT

    The Oracle is supposed to lock and throw an error if another user tries to get
    the same record. I am not sure whether the Oracle is not processing the
    statement or CF App. Server is not passing to the DB server. However the same
    statement works when we use TOAD.

    Thanks


    CFRAM Guest

  2. Similar Questions and Discussions

    1. Database Access: Lock? Readonly? What to do...
      I have a CF site that uses MS Access databases for many different things, from creating the actual site, to doing Admin-related stuff like adding,...
    2. Record Lock in Oracle
      We wanted to lock the record for update and wanted to consider which lock to be used <CFLOCK> Or Oracle Select lock for update? Experts please...
    3. break access database lock in mx?
      all, I'm trying to remotely compact an access database that holds all client variables. problem is, the ldb lock is there and i don't know how to...
    4. Dump Database / Porting Database to Oracle
      Hi, I do not know much about informix. I have no running instance here, but its my job to transfer data from informix to oracle. - Is there a...
    5. Oracle 8i and AIX 5 compatibility issue
      Hello Just installed Oracle 8.1.7 on AIX 5. Oracle version downloaded from Oracle> Oracle8i Enterprise Edition (64-bit) Release 3 (8.1.7) for...
  3. #2

    Default Re: Oracle Database Lock Issue

    How do you know it's not working? Some more code might help. I ask because I'm having a hard time trying to come up with a reason for locking a record in this manner in a web environment.

    JR

    jonwrob Guest

  4. #3

    Default Re: Oracle Database Lock Issue

    This how I found its not working properly. As USER1 I login into the
    application and I go to the search page where I give the parameter for the SQL
    and submit. The SQL statement all the values from the table and assue that It
    locks the row. Login as USER2 and repeat the same steps. As USER2 I get the
    same row for the same parameter. Now this is not good since USER1 has already
    aquired the lock the DB should give an error.

    If I use TOAD then I get the desired result. I get into TOAD and I give the
    SQL statement with the parameter and lock the record. When USER1 logs into the
    application he gets the error message as desired.

    Why there are two different behaviour ?

    Thanks

    CFRAM Guest

  5. #4

    Default Re: Oracle Database Lock Issue

    OK, this is easy. Have you ever noticed that you don't need to explicitly
    commit a DML statement in a CFQUERY tag, even if you haven't included the
    CFQUERY in a CFTRANSACTION tag? This must mean that CF is issuing a commit
    upon successful completion of the query. I would therfore guess that CF is
    issuing a commit upon successful complete of your select for update query, thus
    releasing the lock immediately after obtaining it.

    The way to prevent CF from issuing the commit after the CFQUERY is to put it
    in a CFTRANSACTION tag, but this doesn't do what you want. You want to lock
    the record until after an entirely different request is run. Not only do I not
    think it's possible to lock a database resource like this, I would STRONGLY
    recommend against it. You will constantly have to do things like kill sessions
    in order to release locks that your application failed to release.

    A better solution would be to implement the locking features on the CF side,
    perhaps by storing the primary key values of the records you wish to lock in an
    application variable (or structure).

    JR


    jonwrob Guest

  6. #5

    Default Re: Oracle Database Lock Issue

    So we can use <CFLOCK> ?
    CFRAM Guest

  7. #6

    Default Re: Oracle Database Lock Issue

    I think that you may be misunderstanding the use of FOR UPDATE and NOWAIT. if
    you include the FOR UPDATE clause in your select, then you place a row level
    lock on on all rows selected until you issue a COMMIT or ROLLBACK. Any other
    attempt to update those rows by other users will wait until you COMMIT or
    ROLLBACK, or until you get a DEADLOCK. By including the NOWAIT keyword, all
    that you are doing is to tell Oracle not to wait if the tables that you are
    selecting are already locked by another user, in which case it will raise an
    exception and give you an Oracle error.. It is not intended to tell you if
    another user is attempting to update your locked rows. If you use FOR UPDATE
    NOWAIT within a stored PL/SQL procedure, then you could handle your exception,
    and return an error message, for example, that says that your transaction could
    not be completed, etc.

    Phil

    paross1 Guest

  8. #7

    Default Re: Oracle Database Lock Issue

    CFLOCK prevents other users from running the same code.

    You want to allow different users to run the same code for different records. CFLOCK can't help you.

    JR

    jonwrob Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139