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

Delete users who have expired and related records

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

    Delete users who have expired and related records

    Delete users who have expired

    I’m trying to create script to automatically delete all records in all tables belonging to expired users.

    I know I can:
    1. Query for all expired records in the main user’s table
    2. Take the expired user results and pass userid only to a delete database
    3. Take userids from delete database and make session.userid to search each database and if userid exists, delete those records.
    4. Do this until all expired user’s and their records in all tables are deleted
    5. Empty delete database

    There must be a better way of doing this. Can anyone give me suggestions”\?

    Thanks for your time.
    Eric

    Alpha Five Websites
    longlivepuppies.com
    socialservicenetwork.com
    -------------------------------------------------
    socialservicenetwork.org

    #2
    Re: Delete users who have expired and related records

    You could eliminate steps 2, 3 and 5, and do most of it in memory.

    In your script, create a list of tables you want to review for expired users:

    tbls=<<%lst%
    mytbl1
    mytbl2
    mytbl3
    %lst%

    Then use table.external_record_content_get() to make a list of expired userids:

    uids = table.external_record_content_get("myusertable", "userid","","my filter criteria here")
    Then loop through each table, and for each table, loop through each userid:

    for each x in tbls
    for each y in uids
    record_delete(x, "id="+y)
    next
    next

    Finally, use <TBL>.DELETE_RANGE() to delete the records in the users table still in the query.

    --- I am positive the above syntax will need tweaking and I left out some detail. Also, since record_delete() opens and closes the table each time it fires, if you had a lot of userids to purge it would be more effecient if you used table.open() to open each table and then step through each record with fetch functions and use tbl.delete() to delete each record.
    Steve Wood
    See my profile on IADN

    Comment


      #3
      Re: Delete users who have expired and related records

      As always, thank you for helping me.

      Does this look like I'm on the right track?

      ' Has user expired?
      ' Checks users table. Locates expired records and begins deletion process in other tables
      ' Main table: users
      ' Other tables: sites, posts, posthistory
      ' After deletion complete in all tables:
      ' 1) Delete expired users in security table
      ' 2) Delete records in users table
      ' 3) Pack databases (not shown in this thread)
      ' 4) Send me confirmation email (not shown in this thread)

      tbls=<<%lst%
      "[pathalias.adb_path]\posts"
      "[pathalias.adb_path]\posthistory"
      "[pathalias.adb_path]\sites"
      %lst%
      uids = table.external_record_content_get("[pathalias.adb_path]\users", "userid","",Dateexpires >= ctod("Date()"))
      for each x in tbls
      for each y in uids
      record_delete(x, "userid=" + y)
      next
      next
      ' ===== Delete expired users from security table =====
      for each z in uids
      dim userid as c = useridsecurity
      a5ws_Delete_User(useridsecurity)
      next
      ' ===== Users table Delete Records =====
      dim tbl as P
      dim qry as P
      tbl = table.open("[pathalias.adb_path]\users")
      'Perform a query to find user records for deletion.
      query.filter = Dateexpires >= ctod("Date()")
      query.order = "Recno()"
      qry = tbl.query_create()
      tbl.delete_range()
      tbl.close()
      ' **************************************************

      Thanks again.
      Last edited by EricN; 03-06-2008, 04:30 PM.
      Eric

      Alpha Five Websites
      longlivepuppies.com
      socialservicenetwork.com
      -------------------------------------------------
      socialservicenetwork.org

      Comment


        #4
        Re: Delete users who have expired and related records

        I have this
        tbls=<<%lst%
        "[pathalias.adb_path]\posts"
        "[pathalias.adb_path]\posthistory"
        "[pathalias.adb_path]\sites"
        %lst%

        uids = table.external_record_content_get("[pathalias.adb_path]\users","userid","userid","Acctstatus='Delete'")
        for x = tbls
        for y = uids
        record_delete(x, "userid=" + y)
        next y
        next x

        I'm finding the correct userids that should be deleted but I'm getting this error
        "Script Error
        Error:line:80 Missing or invalid keyword"

        line 80 is --> %lst%
        Last edited by EricN; 03-07-2008, 06:19 PM.
        Eric

        Alpha Five Websites
        longlivepuppies.com
        socialservicenetwork.com
        -------------------------------------------------
        socialservicenetwork.org

        Comment


          #5
          Simple loop expression

          Can someone please give me a simple loop expression?
          I have the following

          While lookup("[pathalias.adb_path]\users", "Acctstatus='Delete'", "userid") <> " "
          session.userid = lookup("[pathalias.adb_path]\users", "Acctstatus='Delete'", "userid")

          ' ===== Posts jobs table Delete Records =====
          dim tbl as P
          dim qry as P
          tbl = table.open("[pathalias.adb_path]\posts")
          query.filter = "Userid =" + quote(session.userid)
          query.order = "Recno()"
          qry = tbl.query_create()
          tbl.delete_range()
          tbl.close()

          a5ws_Delete_User(session.userid)

          ' ===== Main users table Delete Expired User's Record =====
          ' ===== This is where we get session.userid from ======
          dim tbl as P
          dim qry as P
          tbl = table.open("[pathalias.adb_path]\users")
          query.filter = "Userid =" + quote(session.userid)
          query.order = "Recno()"
          qry = tbl.query_create()
          tbl.delete_range()
          tbl.close()
          end while

          The lookup checks to see if any records are expired in the main database "users." If there are, then it will convert the first one to session.userid and use that to delete any related records in the "posts" table. It then deletes the record set for deletion in the "users" table and begins the process again starting with the lookup expression.

          This works great when I do it manually (even with multiple records set for deletion in users table) but hangs when I use the while, end while method.

          Don't know what I'm doing wrong.
          Last edited by EricN; 03-09-2008, 02:59 PM.
          Eric

          Alpha Five Websites
          longlivepuppies.com
          socialservicenetwork.com
          -------------------------------------------------
          socialservicenetwork.org

          Comment


            #6
            Re: Delete users who have expired and related records

            Bump...starting parts from scratch

            Basic fetch question

            I need to fetch users who have expired. I have a character field called Acctstatus in my users table. When user expires, Acctstatus automatically changes to “Delete”

            My problem is:
            1) I need to locate those users in my users table who have Delete in the Acctstatus field.
            2) Create a session var (I think) to be used to delete users related records in other tables.
            3) Delete related records in other tables
            4) Delete the expired from my users table
            5) Loop this until all expired (Acctstatus=Delete) no longer exist.
            6) Update indexes in all tables and pack them?

            #2-3 I can do easily. My problem is creating the correct fetch and the looping. I also probably should update indexes in these tables once deletions are complete.
            #4 use record_delete as Steve suggests above. Currently I'm getting errors there.

            I have read so much in the help (fetch, while, end while, next) that I’m seeing double…

            This is my last major script for my project!

            Any help?

            Thanks
            yy
            Last edited by EricN; 03-10-2008, 12:19 AM.
            Eric

            Alpha Five Websites
            longlivepuppies.com
            socialservicenetwork.com
            -------------------------------------------------
            socialservicenetwork.org

            Comment


              #7
              Re: Delete users who have expired and related records

              Solution found

              Doubled up. Please see below.
              Eric

              Alpha Five Websites
              longlivepuppies.com
              socialservicenetwork.com
              -------------------------------------------------
              socialservicenetwork.org

              Comment


                #8
                Re: Delete users who have expired and related records

                Solution found

                Looking at this now it seems very simple. But for a “seasoned newbie” going through all the functions, learning the functions can be a very daunting task!

                Thanks to Steve Wood who gave me the record_delete("[pathalias.adb_path]\users", "Userid=" + quote(y)) and uids = table.external_record_content_get("[pathalias.adb_path]\users", "userid","userid","Acctstatus='Delete'") functions to start with.

                Here is my solution:
                This deletes ALL users who have expired AND all of their related records in my other tables including the security table.

                I actually have many tables but am only using two in my example here.

                uids = table.external_record_content_get("[pathalias.adb_path]\users", "userid","userid","Acctstatus='Delete'")
                For each y in uids
                dim tbl as P
                dim qry as P
                tbl = table.open("[pathalias.adb_path]\posts")
                query.filter = "Userid =" + quote(y)
                query.order = "Recno()"
                qry = tbl.query_create()
                tbl.delete_range()
                tbl.close()

                ' ===== Jobsposted history table Delete Expired User's Records =====
                dim tbl as P
                dim qry as P
                tbl = table.open("[pathalias.adb_path]\jobsposted")
                query.filter = "Userid =" + quote(y)
                query.order = "Recno()"
                qry = tbl.query_create()
                tbl.delete_range()
                tbl.close()

                a5ws_Delete_User(y)

                record_delete("[pathalias.adb_path]\users", "Userid=" + quote(y))
                next
                ========================================
                The details...
                The table.external_record_content_get finds all the userids who have expired and places them in a array list.

                "For each y in uids" pulls each (variable) userid and uses this variable to filter my individual tables allowing me to delete related records. At the very end, there is the “next” which looks for the next y or uid and starts the process over again.

                a5ws_Delete_User(y) goes into my security table and deletes the users out of security..

                record_delete("[pathalias.adb_path]\users", "Userid=" + quote(y)) deletes the current user’s record “y” from the table.

                This "For...Next" loop continues until ALL of the "Acctstatus='Delete'" are deleted from my Users table.

                BTW: Would be nice to see the help improved...
                Last edited by EricN; 03-10-2008, 01:16 PM.
                Eric

                Alpha Five Websites
                longlivepuppies.com
                socialservicenetwork.com
                -------------------------------------------------
                socialservicenetwork.org

                Comment

                Working...
                X