Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to close all tables opened in a routine?
Message
From
14/04/2008 09:36:09
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01310216
Message ID:
01310372
Views:
21
>Thank you, Mike. But the key also, as Jim said, if you don't need any other tables and cursors. In my case, even though I have a private data session, I have a bunch of cursors open and they need to remain open.

I may not be understanding you.

Use table1 in 0
use table2 in 0

loQuery = CreateObject('myquery')

The myquery object opens whatever tables it wants in its private datasession without affecting your existing open tables. It runs a query and closes those tables. When you get back, the table1 and table2 should still be open. It can re-open table1 and table2 because since they were already open, VFP has no problem opening them with the AGAIN clause. They reopen faster since they're already open.




>
>>You might want to consider an object with a private data session. Once released the opened tables would be closed. You could make that object a reusable class.
>>
>>
LOCAL m.loQuery, m.lnBefore, m.lnAfter, m.lcResult
>>m.loQuery = CREATEOBJECT('sesCustomQuery')
>>*m.lnBefore and m.lnAfter are just here to show zero
>>*effects from running the query.
>>m.lnBefore = AUSED(laBefore)
>>m.lcResult = m.loQuery.ReturnValueFromQuery()
>>m.lnAfter = AUSED(laAfter)
>>?m.lnBefore,m.lnAfter,m.lcResult
>>RETURN
>>
>>DEFINE CLASS sesCustomQuery as Session
>>DataSession = 2
>>
>>PROCEDURE ReturnValueFromQuery
>>SELECT TOP 1 cust_id FROM (HOME()+"SAMPLES\DATA\CUSTOMER.DBF") CUSTOMERS ORDER BY cust_id INTO CURSOR temp
>>RETURN temp.cust_id
>>ENDPROC
>>ENDDEFINE
>>
>>
>>
>>>Yes, this method will work better as the first one was closing all open tables. Thank you very much.
>>>
>>>>OR
>>>>
>>>>AUSED(laCurrAliases)
>>>>
>>>>*-- Execute a Sql Select that opens one or more tables
>>>>*** select * from mytable1 join mytable2 .. join mytable3.. etc.
>>>>
>>>>lnallAliases = AUSED(laArr)
>>>>
>>>>FOR lnLoop = 1 TO m.lnallAliases
>>>>    IF ASCAN(laCurrAliases,m.laArr[m.lnLoop,1])# 0
>>>>       LOOP
>>>>    ENDIF
>>>>    USE IN (m.laArr(m.lnLoop,1))
>>>>NEXT
>>>>
>>>>
>>>>>Thank you, Vladimir.
>>>>>
>>>>>>Try this:
>>>>>>
*-- bookmark selected area
>>>>>>lcSelect = ALIAS()
>>>>>>
>>>>>>*-- Execute a Sql Select that opens one or more tables
>>>>>>*** select * from mytable1 join mytable2 .. join mytable3.. etc.
>>>>>>
>>>>>>lnOpenDbfs = AUSED(laArr)
>>>>>>
>>>>>>FOR lnLoop = 1 TO m.lnOpenDbfs
>>>>>>
>>>>>>    IF m.laArr[m.lnLoop,1] = m.lcSelect
>>>>>>       LOOP
>>>>>>    ENDIF
>>>>>>
>>>>>>    USE IN (m.laArr(m.lnLoop,1))
>>>>>>NEXT
>>>>>>
>>>>>>
>>>>>>>Good morning,
>>>>>>>
>>>>>>>I would like to find a way to close all tables that are opened in a routine.
>>>>>>>
>>>>>>>Here is an example.
>>>>>>>
>>>>>>>
>>>>>>>*-- bookmark selected area
>>>>>>>nSelect = select()
>>>>>>>
>>>>>>>*-- Execute a Sql Select that opens one or more tables
>>>>>>>select * from mytable1 join mytable2 .. join mytable3.. etc.
>>>>>>>
>>>>>>>*-- Close all tables opened in the above SQL Select.
>>>>>>>
>>>>>>>*-- I believe I need to know the highest SELECT() at this
>>>>>>>point and scan it backwards until coming to nSelect.
>>>>>>>But how to determine currently highest SELECT()?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>Or if you think or can suggest a better method to accomplish it, I would appreciate it.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform