Alpha Video Training
Results 1 to 9 of 9

Thread: <TBL>.IS_RECORD_LOCKED() filtered group of records

  1. #1
    Member
    Real Name
    Bob Arbuthnot
    Join Date
    Apr 2005
    Location
    Belleville, KS
    Posts
    598

    Default <TBL>.IS_RECORD_LOCKED() filtered group of records

    I need to check a group of records selected by a filter expression to see if any of the group are locked. If none are locked I'll run an operation. If even one of the group is locked I'll throw up a message that the process can't be run at this time because one of the affected records is being changed.

    I think I could use <TBL>.IS_RECORD_LOCKED() but am having trouble getting my head around how to apply this to the filtered out group of records.

    As always, any help would be greatly appreciated.

    Bob Arbuthnot

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: <TBL>.IS_RECORD_LOCKED() filtered group of records

    table.current().IS_RECORD_LOCKED()

    maybe?

    Worked here.
    Last edited by Stan Mathews; 04-24-2009 at 03:06 PM. Reason: verification
    There can be only one.

  3. #3
    Member
    Real Name
    Bob Arbuthnot
    Join Date
    Apr 2005
    Location
    Belleville, KS
    Posts
    598

    Default Re: <TBL>.IS_RECORD_LOCKED() filtered group of records

    Hi Stan,

    Thanks for replying. I need to be clearer. I can make it work for a single record, but how do I make it work on the results of the filter?

    ba

  4. #4
    "Certified" Alphaholic
    Real Name
    Peter Wayne
    Join Date
    Apr 2000
    Posts
    1,728

    Default Re: <TBL>.IS_RECORD_LOCKED() filtered group of records

    Bob,
    I don't think there's any way to do what you want to do with table.is_record_locked(). However, I can think of two ways to do what you want:

    1) open the table in exclusive mode before running your operation.
    e.g.

    on error goto no_open
    t=table.open("mytable",file_rw_exclusive)
    ' run operation here
    ....
    ....
    t.close()
    end

    no_open:
    on error goto 0
    ui_msg_box("Unable to run operation","Another user accessing table. Try later, please!")
    end

    This might require a redesign of your application--it won't work if you have a main form that is based on this table that users are sitting on all the time.

    2) If that's the case (users on a main form with the table open), then you could redesign your table to add a field, "in_use". When you want to run your operation you can change the "in_use" field to .T. for all the records in the filter, and change it back to .F. after the operation runs. Then in the CanSaveRecord event for the table you can write
    t=table.get("mytable")
    if t.in_use then
    cancel()
    ui_msg_box("Changes not saved","Another user running monthly updates. Please try again.")
    end if

    which will prevent interactive users from saving any changes they make.

  5. #5
    Member
    Real Name
    Bob Arbuthnot
    Join Date
    Apr 2005
    Location
    Belleville, KS
    Posts
    598

    Default Re: <TBL>.IS_RECORD_LOCKED() filtered group of records

    Hi Peter,

    Going the table route won't work because the table is open 90% of the time. Route #2 will work, I've done that elsewhere in other apps. But...please consider the following:

    Have just tested this a couple times and it appears to work. It dawned on me that I could possibly use A5_GET_RECORDS_IN_QUERY() and make table.current().IS_RECORD_LOCKED() a part of the filter used by A5_GET_RECORDS_IN_QUERY() (along with my other criteria). I took the filter expression for my operation and added table.current().IS_RECORD_LOCKED()=.t. to it and put this in A5_GET_RECORDS_IN_QUERY() ahead of the operation. If it returns a number > 0 I put up the error message and abort.

    I've tested this a half dozen times under different circumstances and it appears to work flawlessly.

    Do you see any problem with this?

    ba

  6. #6
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: <TBL>.IS_RECORD_LOCKED() filtered group of records

    Quote Originally Posted by Bob Arbuthnot View Post
    I need to check a group of records selected by a filter expression to see if any of the group are locked. If none are locked I'll run an operation. If even one of the group is locked I'll throw up a message that the process can't be run at this time because one of the
    Bob:
    I am trying to understand the logic behind the question. Yes, it is clear you do not want to run "the operation" if any of the records in the group is locked. But the real question is, what does the operation do?

    You might succeed in your quest, but that simply means the user will have to keep on trying until such time when none of the records are locked which might not be practical.

    That said, try this script:
    Code:
    t=table.current()
    t.query_create("t","your filter")
    x=t.mode_get()
    if x=1
    msgbox("locked")
    end
    else
    t.fetch_first()
    while .not. t.fetch_eof()
    if x=1
    msgbox("locked")
    end
    end if
    t.fetch_next()
    end while
    end if
    msgbox("none locked")
    Incidentally, if ANY record is locked, not just one in the group and you run a script that says:
    t=table.open("mytable",file_rw_exclusive)
    alpha will give you an error message as you are attempting to access an open table.

  7. #7
    "Certified" Alphaholic
    Real Name
    Peter Wayne
    Join Date
    Apr 2000
    Posts
    1,728

    Default Re: <TBL>.IS_RECORD_LOCKED() filtered group of records

    Bob,
    If you add <tbl>.is_record_locked() to your query, you'll have two problems:

    1) If a record that you would otherwise want to include in your query is locked by another user, then it won't show up in your query. Your query will never fail to execute but you won't be performing the operation you want on the records that were locked -- so you're not ahead of the game.
    2) Query lists are static, not dynamic. You can run your query and then start your operation. In between running the query and starting the operation, a user can lock or unlock a record, and your query list remains the same and it's out of date.

    - Peter

  8. #8
    Member
    Real Name
    Bob Arbuthnot
    Join Date
    Apr 2005
    Location
    Belleville, KS
    Posts
    598

    Default Re: <TBL>.IS_RECORD_LOCKED() filtered group of records

    Gabe,

    Thanks for the thoughts and the code. I'll try it out. As a software user I'm not a big fan of hour glasses and progress boxes. In this instance, as the developer, I'm trying to check up front to see if the process is going to run and if it won't (a locked record is encountered) let the user know so they can go on to something else and try again in a few minutes.


    Peter,

    If a record that you would otherwise want to include in your query is locked by another user, then it won't show up in your query. Your query will never fail to execute but you won't be performing the operation you want on the records that were locked -- so you're not ahead of the game.
    If I'm reading you correctly, this is not what I'm seeing in my testing. What I'm seeing is that the A5_get_records_in_query() described above is picking up if one of the records in the filter is locked allowing me to put up a message to alert the user and abort the script before the operation starts to run (which is what I was trying to accomplish in the first place).

    I guess it is possible that in the micro-second between the query and the operation another user could put a record in change mode. In that case, the worst that could happen is that eventually the built in A5 error will come up that the operation couldn't run because a portion of the file is locked. I can live with that.

    Thanks to all for your thoughtful insights.

    Bob Arbuthnot

  9. #9
    "Certified" Alphaholic
    Real Name
    Peter Wayne
    Join Date
    Apr 2000
    Posts
    1,728

    Default Re: <TBL>.IS_RECORD_LOCKED() filtered group of records

    Thanks, Bob, you're absolutely right. I was looking at it backwards -- I didn't read your post carefully enough. Your way of doing it should work just fine, with the exception, as you point out, of someone beginning to change a record before the operation begins or while it is in progress.

Similar Threads

  1. <tbl>.Append() and Sorting records
    By turbojack in forum Alpha Five Version 8
    Replies: 2
    Last Post: 02-15-2008, 09:11 AM
  2. can tbl.summarize() be filtered?
    By mariusm in forum Alpha Five Version 8
    Replies: 1
    Last Post: 11-30-2007, 06:09 PM
  3. Counting the no ok filtered records
    By Cyrus in forum Alpha Five Version 5
    Replies: 9
    Last Post: 10-21-2005, 08:27 PM
  4. Display filtered records only
    By Paul Main in forum Alpha Five Version 6
    Replies: 3
    Last Post: 02-13-2005, 11:11 AM
  5. Report with filtered child records
    By David Boomer in forum Alpha Five Version 5
    Replies: 2
    Last Post: 04-07-2004, 03:43 PM

Bookmarks

Posting Permissions

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