Close tables opened by query ? 
Author Message
 Close tables opened by query ?

If in the middle of a program I have an SQL statement that uses 2 or more
tables, FoxPro opens the tables in any Workarea it wants to. After the SQL
statement has been executed, how do I close the tables used by the SQL
statement ? How do I know which Workareas the tables were opened in ?

e.g.,

SELECT DISTINCT F1 FROM TABLE1.DBF  ;
 WHERE F1 NOT IN (SELECT DISTINCT F2 FROM TABLE2.DBF) INTO ARRAY a
.....

USE TABLE2.DBF     &&  "THIS ERRORS AS TABLE2 IS ALREADY OPEN"

NOTE: I do not want to use "CLOSE ALL" or "USE  TABLE2.DBF AGAIN"

Thanks,

Kaushik



Sat, 18 Jan 2003 03:00:00 GMT  
 Close tables opened by query ?

You will probably have to loop through an array created from AUSED() and
check each alias' DBF()
e.g.
** note: DBF() function returns full path - this is just an example.
lnUsed = AUSED(laUsed)
FOR ji = 1 TO lnUsed
   IF DBF(laUsed[ji,1])="C:\TABLE1.DBF"
      USE IN (laUsed[ji,1])
   ENDIF
ENDFOR

** vfp6
lnUsed = AUSED(laUsed)
FOR ji = 1 TO lnUsed
   IF JUSTFNAME(laUsed[ji,1]) = "TABLE1.DBF"
      USE IN (laUsed[ji,1])
   ENDIF
ENDFOR


Quote:
> If in the middle of a program I have an SQL statement that uses 2 or more
> tables, FoxPro opens the tables in any Workarea it wants to. After the SQL
> statement has been executed, how do I close the tables used by the SQL
> statement ? How do I know which Workareas the tables were opened in ?

> e.g.,

> SELECT DISTINCT F1 FROM TABLE1.DBF  ;
>  WHERE F1 NOT IN (SELECT DISTINCT F2 FROM TABLE2.DBF) INTO ARRAY a
> .....

> USE TABLE2.DBF     &&  "THIS ERRORS AS TABLE2 IS ALREADY OPEN"

> NOTE: I do not want to use "CLOSE ALL" or "USE  TABLE2.DBF AGAIN"

> Thanks,

> Kaushik



Sat, 18 Jan 2003 03:00:00 GMT  
 Close tables opened by query ?
Kaushik,

You know which tables might be open because you used them in your SQL.

You should never worry about the work areas.  It is always better to refer
to open tables by their alias since the program code is easier to follow
that way.  Let FoxPro take care of exactly which work area number goes with
which Alias.

Like this:

USE MyTable IN 0    && Opens in next available work area

*!* Test to see if it's already open before opening
IF !USED("MyTable")
    USE MyTable IN 0
ENDIF

*!* Make it the current work area
SELECT MyTable

*!* Test to see if it's open before issuing close
IF USED("MyTable")
    USE IN MyTable
ENDIF

--

Cindy Winegarden
Microsoft Certified Professional, Visual FoxPro

Duke Children's Information Systems
Duke University Medical Center


| If in the middle of a program I have an SQL statement that uses 2 or more
| tables, FoxPro opens the tables in any Workarea it wants to. After the SQL
| statement has been executed, how do I close the tables used by the SQL
| statement ? How do I know which Workareas the tables were opened in ?
|
| e.g.,
|
| SELECT DISTINCT F1 FROM TABLE1.DBF  ;
|  WHERE F1 NOT IN (SELECT DISTINCT F2 FROM TABLE2.DBF) INTO ARRAY a
| .....
|
| USE TABLE2.DBF     &&  "THIS ERRORS AS TABLE2 IS ALREADY OPEN"
|
|
| NOTE: I do not want to use "CLOSE ALL" or "USE  TABLE2.DBF AGAIN"
|
|
| Thanks,
|
| Kaushik
|
|
|



Sat, 18 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Closing project manager closes open tables -why?

2. closing tables opened by select-sql

3. Closing tables after running queries

4. close a database and leave open a free table

5. VFP50 problems opening and closing free tables

6. Opening and closing tables

7. Automatic open and close tables

8. VFP60 DataEnvironment - Open/Close Tables

9. open table dialog even though table is open?

10. How to open a table without opening the CDX

11. Closing an Open Low-level file

12. Q: FPW and closing a cursor leaves dbf open

 

 
Powered by phpBB® Forum Software