Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: 'Use' in console doesn't close previous table

  1. #1
    Senior Member
    Join Date
    Apr 2014
    Posts
    201

    'Use' in console doesn't close previous table

    Hi,

    After typing several commands in the console I have ende up in this situation several times:

    Code:
    use purchase_order
    Code:
    list dictionary
    output lists purchase_order.dbf info. Then:

    Code:
    use supplier
    Gives Error:
    Code:
    Thu Jan 28 14:28:40 2016
    **** Lianja error ****
    use supplier
                ^
    ALIAS name 'SUPPLIER' already in use
    list dictionary then gives the purchase_order table info, so it seems that purchase_order is stuck open even though 'use' hitnk that suppliers is active. The only way I have been able to get out of this situation is by closing the database and re-opening & then it all works as expected.

  2. #2
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,831
    Hi Alia,

    The "ALIAS name 'SUPPLIER' already in use" error is saying that 'supplier' is already open in another workarea. If you

    Code:
    select supplier
    this will select the correct workarea.

    Regards,

    Yvonne

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Posts
    201
    pls excuse my ignorance but what is a workarea?

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658
    Hi alia,

    There is a better explanation for this although a workarea tracks which table is currently open and selected.
    Here is some code I've used so that it avoids this error.

    Code:
    if inuse("supplier") = .T.
       SELECT supplier
    else
      select 0
      use supplier
    endif
    Cory

  5. #5
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,831
    Hi Alia,

    I probably should have said 'cursor' instead of 'workarea' (old habits die hard).

    http://www.lianja.com/doc/index.php/SELECT

    Thanks,

    Yvonne

  6. #6
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    2,184
    Hi Alia,

    A workarea is a numbered item in set of available slots for opening cursors. The size of that set varies with development platform. We don't usually see the numbers (something that dates back to the dBase days, at least). But when we issue the following:

    use suppliers in 0 current
    we are really telling the system: "Hey Joe, find an empty workarea for me to open a cursor, and then make it the current one I'm using."

    If after that command you issue:

    ? select()
    you will see printed the number of the workarea.

    If you issue:

    ? alias()
    you will see the alias assigned to that cursor, which defaults to the table/vt name.

    In the old days, IIRC, there were only 10 workareas in dBase III. I was using dBMan back then where I think we had 25, and even had windows of a sort (printed on the CRT), so considered myself quite advanced.

    hth,

    Hank

    PS: select() can be used to store the current workarea so it can be returned to after code has gone somewhere else and done something else:

    lnSelect = select(0) && without the 0 works the same way -- that's a habit from the early version Fox days when it made a difference)
    ... go do your work
    select (lnSelect)

  7. #7
    Senior Member
    Join Date
    Apr 2014
    Posts
    201
    Thanks for the all the replies, this is a little confusing for me so please confirm that IUC:
    Code:
    use table1
    use table2
    then I would have two cursors open, with the active one being on table2. If I then issue

    Code:
    use table1
    I'll get the error that table1 is in use and I should actually be using 'select table1'?

    If this is true then what actually releases the cursors? is it possible to/should I close a cursor manually?


    Also, fyi the help for the 'use' command in the app builder says:

    Code:
    Opens a table in the currently selected workarea. Use on its own will close the current table.
    That is why I assumed that 'using' one table would automatically close the previous one.

  8. #8
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Hi,

    USE is for initial opening (one-time for every table).

    SELECT is for moving among workareas (to set only one of them as 'current' or active).
    Some commands work on 'current' workarea, without mentioning name or number of it.

    USE without parameters closes currently selected one.

    Here is a screenshot of VFP:

    Name:  Screenshot - 29.1.2016. , 9_19_38.png
Views: 116
Size:  9.6 KB

    As you see at the bottom: for selected YKRI there is WORKAREA: 5
    Everyone of these in list has own number. They are not sorted here and number is visible only for selected one.
    You get it in code with ?SELECT('ykri') if you need to know the number (not likely).
    I talk about these numbers only because it explains and visualizes this stack.
    And better clarify USE 'xxx' as adding new one into the stack, and SELECT as pointing to 'current' one
    In Fox for DOS all unused numbers (to 254) are shown too, so it is more obvious to understand it.

    Everyone was once initially open with:
    Code:
    USE 'somename'
    To move to IFAISS workarea (its number is 2), I must
    Code:
    SELECT 'IFAISS'
    //or
    SELECT 2
    If I now say
    Code:
    USE
    (with nothing), it will close my (currently selected) table YKRI.
    Now, every command which operates on current workarea by default, will fail because I did not select any.
    Last edited by josipradnik; 2016-01-29 at 03:07.

  9. #9
    Senior Member
    Join Date
    Apr 2014
    Posts
    201
    That's cleared it up, thank you Josip

  10. #10
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Hi,

    You are not the first who was confused here.
    For next developers to clarify this in code, lets copy/paste and save this code in a PRG in console with ED USEXAMPLE.
    Execute it in console with DO USEXAMPLE.

    Code:
    clear
    close databases
    open database southwind
    ? '#1 case: BEFORE USEs'
    ? [used('orders')=]+transform(used('orders'))
    
    
    use orders
    use shippers
    ? 'AFTER USE orders and shippers without specify numbers or 0=next available'
    ? [used('orders')=]+transform(used('orders'))
    ? [used('shippers')=]+transform(used('shippers'))
    ? 'all USEs were made on the same workarea number and only last wins'
    
    
    close databases
    open database southwind
    ?
    ? '#2 case: BEFORE USEs'
    ? [used('orders')=]+transform(used('orders'))
    
    
    use orders in 0
    use shippers in 0
    ? 'AFTER USE orders and shippers with 0=next available'
    ? [used('orders')=]+transform(used('orders'))
    ? [used('shippers')=]+transform(used('shippers'))
    ? 'Every USE was made in NEXT AVAILABLE workarea number and all are live'
    ?
    ? '#3 case: How to close one of them'
    select orders
    use
    ? 'AFTER SELECT and USE '
    ? [used('orders')=]+transform(used('orders'))
    The result will be:
    Code:
    #1 case: BEFORE USEs
    used('orders')=.F.
    AFTER USE orders and shippers without specify numbers or 0=next available
    used('orders')=.F.
    used('shippers')=.T.
    all USEs were made on the same workarea number and only last wins
    
    
    #2 case: BEFORE USEs
    used('orders')=.F.
    AFTER USE orders and shippers with 0=next available
    used('orders')=.T.
    used('shippers')=.T.
    Every USE was made in NEXT AVAILABLE workarea number and all are live
    
    
    #3 case: How to close one of them
    AFTER SELECT and USE 
    used('orders')=.F.
    The trick is:
    Code:
    USE 'somename' IN 0
    In VFP you can close it in 1 step: (use in 'orders')
    Lianja needs 2 steps (select + use).
    Maybe this is for ER ticket?
    Last edited by josipradnik; 2016-01-29 at 04:03.

Bookmarks

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
  •  
Journey into the Cloud
Join us