Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

<TBL>.IS_RECORD_LOCKED() filtered group of records

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    <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
    Re: &lt;TBL&gt;.IS_RECORD_LOCKED() filtered group of records

    table.current().IS_RECORD_LOCKED()

    maybe?

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

    Comment


      #3
      Re: &lt;TBL&gt;.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

      Comment


        #4
        Re: &lt;TBL&gt;.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.

        Comment


          #5
          Re: &lt;TBL&gt;.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

          Comment


            #6
            Re: &lt;TBL&gt;.IS_RECORD_LOCKED() filtered group of records

            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.

            Comment


              #7
              Re: &lt;TBL&gt;.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

              Comment


                #8
                Re: &lt;TBL&gt;.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

                Comment


                  #9
                  Re: &lt;TBL&gt;.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.

                  Comment

                  Working...
                  X