Alpha Video Training
Results 1 to 8 of 8

Thread: Delete users who have expired and related records

  1. #1
    Member EricN's Avatar
    Real Name
    Eric
    Join Date
    May 2007
    Location
    Minnesota
    Posts
    553

    Default 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. #2
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Thumbs up 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
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  3. #3
    Member EricN's Avatar
    Real Name
    Eric
    Join Date
    May 2007
    Location
    Minnesota
    Posts
    553

    Default 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 at 04:30 PM.
    Eric

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

  4. #4
    Member EricN's Avatar
    Real Name
    Eric
    Join Date
    May 2007
    Location
    Minnesota
    Posts
    553

    Default 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 at 06:19 PM.
    Eric

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

  5. #5
    Member EricN's Avatar
    Real Name
    Eric
    Join Date
    May 2007
    Location
    Minnesota
    Posts
    553

    Default 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 at 03:59 PM.
    Eric

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

  6. #6
    Member EricN's Avatar
    Real Name
    Eric
    Join Date
    May 2007
    Location
    Minnesota
    Posts
    553

    Default 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 at 01:19 AM.
    Eric

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

  7. #7
    Member EricN's Avatar
    Real Name
    Eric
    Join Date
    May 2007
    Location
    Minnesota
    Posts
    553

    Default 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

  8. #8
    Member EricN's Avatar
    Real Name
    Eric
    Join Date
    May 2007
    Location
    Minnesota
    Posts
    553

    Default 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 at 02:16 PM.
    Eric

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

Similar Threads

  1. Processing related records
    By Lawrence Fox in forum Alpha Five Version 7
    Replies: 7
    Last Post: 02-23-2006, 07:13 PM
  2. Means to read, add, delete users
    By metadyne in forum Alpha Five Version 7
    Replies: 2
    Last Post: 02-09-2006, 08:27 AM
  3. Reporting on Expired Members
    By CubDriver in forum Alpha Five Version 7
    Replies: 8
    Last Post: 12-05-2005, 04:08 PM
  4. Beta Period has expired
    By Dennis Mathias in forum Alpha Five Version 5
    Replies: 2
    Last Post: 01-22-2004, 07:57 AM
  5. Grace period expired
    By John Webster in forum Alpha Five Version 5
    Replies: 3
    Last Post: 07-25-2002, 12:10 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
  •