Alpha Video Training
Results 1 to 8 of 8

Thread: How do you close table/set sessions with Xbasic?

  1. #1
    Member
    Real Name
    Trevor Sayers
    Join Date
    Jan 2004
    Posts
    118

    Default How do you close table/set sessions with Xbasic?

    Hi folks,

    I was testing some standalone Xbasic which included...
    t = table.open_session(tblname)
    ...but in which I hadn't got as far as putting in a t.close(). I now have a rather unhealthy number of table sessions open.

    Obviously I could close them by closing A5, but that seems to be a hammer to crack a nut. Given how extensive A5's capabilities are, I'd be surprised if there isn't a way to close them with Xbasic but I've searched and searched and can't find anything. Anyone have any thoughts/tips?

    Thanks.

    Regards,
    Trevor

  2. #2
    "Certified" Alphaholic
    Real Name
    Louis Nickerson
    Join Date
    Aug 2002
    Posts
    1,039

    Default RE: How do you close table/set sessions with Xbasi

    Trevor,

    The following X-Basic opens the "tbl_Customer_Contacts" table, creates a new record, writes the value held in vc_new_title to the "Title" field, saves the record and closes the table.

    Is this what you were looking for?


    dim tbl as p
    tbl = table.open("tbl_customer_contacts",FILE_RW_SHARED)
    tbl.enter_begin()
    tbl.TITLE = convert_type(vc_new_title,"Character")
    tbl.enter_end(.t.)
    tbl.close()


    Louis Nickerson
    ASMIAP! Software

  3. #3
    Former Alpha Employee Edward Larrabee's Avatar
    Real Name
    Edward Larrabee
    Join Date
    Nov 2002
    Location
    New Hampshire
    Posts
    1,385

    Default RE: How do you close table/set sessions with Xbasi

    If you are thinking of a clean-up function that closes all open tables, you could create one, starting with Ta ble.Enum_Open().

  4. #4
    Former Alpha Employee Edward Larrabee's Avatar
    Real Name
    Edward Larrabee
    Join Date
    Nov 2002
    Location
    New Hampshire
    Posts
    1,385

    Default RE: How do you close table/set sessions with Xbasi

    Or use A5_FORCECLOSETABLES().

  5. #5
    "Certified" Alphaholic
    Real Name
    jim chapman
    Join Date
    Apr 2000
    Posts
    1,779

    Default RE: How do you close table/set sessions with Xbasi

    Hello Trevor,

    ""t = table.open_session(tblname)""

    Louis gave you the solution, t.close(), but I'm curious why you are using the table.open_session() method instead of table.open()?

    Alpha does a good job of cleaning up after itself. When a session is closed, Alpha attempts to close all table pointers opened in the session. I'm not sure how that would work when using the table.open_session() method. I've never used it myself.

    Jim

  6. #6
    Member
    Real Name
    Trevor Sayers
    Join Date
    Jan 2004
    Posts
    118

    Default RE: How do you close table/set sessions with Xbasi

    Hi folks,

    thanks for your responses. The code I have looks like this. Note that the line t.close() is missing...

    t = table.open_session("contacts")
    redim global ar[5] as P
    i=1
    For i = 1 to n
    ar[i].Firstname = t.firstname
    ar[i].Lastname = t.lastname
    t.fetch_next()
    next i


    I was testing it and ran it a number of times. I realised that there must be a load of table sessions open somewhere and, sure enough, when I looked in the Xbasic Explorer, there they were. The problem was, I was unable to see any way to determine what session I was currently "in," or any way to switch sessions or close the excess ones. I realised that even if you have the t.close() line, if your code fails to reach it for some reason, then you could end up opening more and more sessions until eventually A5 falls over.

    I tried running...
    ? table.enum_session_open("F"+crlf())
    and
    ? table.enum_open("F"+crlf())
    ...but all these told me was that the only database open was null.dbf so I'm not sure A5_FORCECLOSETABLES() would help (it's also not listed in the Feb 2 .chm).


    Ed, a few points:
    1. it is unfortunate that the word "session" applies to both the whole A5 session and to individual instances of a table being open, as this does create a little confusion. Would it be possible change the terminology so you have session and tablesession, or session and instance?
    2. I do not see the difference between what table.enum_session_open("F"+crlf()) and table.enum_open("F"+crlf()) do. Could the manual have an example highlighting the difference?
    3. As for solving the main problem above, I guess what I need are some functions along the lines of...
    session.tableinstances_enum()
    session.tableinstances_activate()
    session.tableinstances_close()

    Regards,
    Trevor

  7. #7
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

    Default RE: How do you close table/set sessions with Xbasi

    Trevor,

    I hope somebody comes up with an answer. My solution has always been to (1) swear at myself for screwing up again, (2) close alpha, (3) swear at myself for screwing up again, (4) restart alpha, (5) swear at myself for screwing up again, (6) try to get back to whatever I was doing before, and finally, (7) swear at myself for screwing up again.

    Computer - the great leveler.

    Cal Locklin
    www.aimsdc.net

  8. #8
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,687

    Default Re: How do you close table/set sessions with Xbasic?

    Was looking for this same solution so I bumped it.

    If I define a table pointer as
    tmp = table.open_session("mytemp")

    and I want to test if that table closed properly I can use

    if tmp.enum_session_open() = "mytemp" then
    tmp.close()
    end if

    Because if the table is not open in its session, then the return value for this function is 'NUL' otherwise it returns the table name. And I do not have to concern myself with any of the other tables that may be open in other sessions.

    Nor can you use:
    table.isopen("mytemp") or table.isopen(tmp.name_get()) because both will return .F. as they are not looking to the correct session
    and table.in_use("mytemp") with not help either if the table is opened more than once because you will get a false positive for the session you are concerned with.

    BTW in the Wiki is says to get a list of tables by using the table.enum_open() method and then set a pointer using table.get() to close a table. This will only return 'no such table'. You need to have your pointer already defined else you cannot close the table any other way.

    Opening a table (again) in its own session allows you to use ptr.enum_session_open() when all else may fail - especially in a multiuser environment.

    Edit: There may be more than one table in the list if the pointer is to a table in a set so I tried this in my script and it seems to work better

    Code:
    CLOSETBLS:
    	lst1 = crlf_to_comma(tmp.Enum_Session_Open())
    	if inlist2(tmp.name_get(),lst1) then
    		tmp.close()
    	end if
    	lst2 = crlf_to_comma(thf.Enum_Session_Open())
    	if inlist2(thf.name_get(),lst2) then
    		thf.close()
    	end if
    Last edited by MoGrace; 02-15-2018 at 02:36 PM. Reason: correction
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

Similar Threads

  1. Close Table
    By Bill@TrackerSystems.com in forum Alpha Five Version 6
    Replies: 0
    Last Post: 02-28-2005, 07:26 AM
  2. Close Open Table
    By John Fringer in forum Alpha Five Version 6
    Replies: 4
    Last Post: 01-12-2005, 09:02 PM
  3. How to close open table
    By Mantford in forum Alpha Five Version 5
    Replies: 5
    Last Post: 10-13-2004, 02:58 PM
  4. Force table close??
    By Scott Emerick in forum Alpha Five Version 5
    Replies: 3
    Last Post: 03-02-2004, 02:44 PM
  5. close form and table
    By Edward F. Schulz in forum Alpha Five Version 4
    Replies: 1
    Last Post: 11-23-2002, 08:22 AM

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
  •