Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open cursors in memory

Status
Not open for further replies.

INFORMAT

Programmer
Jan 3, 2001
121
BE
How can I determine the amount of open cursors in the VFP memory and which alias they have?

Thus, ALL the open cursors!
 
I think AUSED() would be what you'd want.

Hope that helps,

Stewart
 
Stewart's idea works good as long as your definition of "cursor" includes Tables, Views and Cursors. If you only want true Cursors, then you'll probably need to use the DBF() function to verify the table name. Note also that AUSED() allows an optional datasession parameter, so if you have multiple data sessions, you'll need to check them all.

Rick
 
OK, Thx

Who can explain why I have the following aliases in my VFP memory?

e.g.
viewEmployee
viewEmployee1

Am I doing something wrong? Perhaps too many retrievals of data? Who can solve this problem please...
 
Sounds like you've created views of your data.

If you don't think they are supposed to be there,
then something is wrong. But the names seem appropriate.

Darrell

BTW

Here's a basis to get all open table/cursor/views open
in all datasessions in VFP.

Obviously it would exhaust VFP's array limits if
there are too many tables open.

[tt]
CLEAR MEMO

* Open a lot of tables in mulitple
* datasessions
LOCAL ARRAY aDS[1]
DIME aDS[100]
FOR i = 1 TO 100
aDS[ i ] = CREATEOBJECT("clsDS")
NEXT

* This array will contain all
* of the open table names with
* the datasessions they are open in
* aOpenTables[x,1]<-TableName
* aOpenTables[x,1]<-DataSession
LOCAL ARRAY aOpenTables[1,2]

LOCAL nOpenTables

nOpenTables = GetOpenTables(@aOpenTables)

SUSP

FUNCTION GetOpenTables(aArrayIn)
LOCAL nOpenTables && Return value
LOCAL cErrHand && Current error handler
LOCAL nError && Used by local error trap
LOCAL ARRAY aTables[1] && Holds tables open in datasessions
LOCAL nTables && Table count in datasessions
LOCAL i, j

LOCAL nNextTable
DIME aArrayIn[1]

nOpenTables = 0 && Set return value
nNextTable = 0

cErrHand = ON(&quot;error&quot;) && Save error handler
ON ERROR nError = ERROR() && And set a new one
nError = 0 && Set initial error value

FOR i = 1 TO 32000
nTables = AUSED(aTables,i)
IF nTables > 0
IF nError<>0
EXIT
ENDIF
nNextTable = IIF(nOpenTables>0,nOpenTables,0)
nOpenTables = nOpenTables + nTables
DIME aArrayIn[nOpenTables,2]
FOR j = 1 TO nTables
aArrayIn[nNextTable+j,1] = aTables[j,1]
aArrayIn[nNextTable+j,2] = aTables[j,2] && or i
NEXT
ENDIF
NEXT
ON ERROR &cErrHand && Reset error handler
RETURN nOpenTables
ENDFUNC

DEFINE CLASS clsDS AS SESSION
DATASESSION = 2
PROCEDURE INIT
LOCAL ARRAY aTbls2Open[1], aTblNames[1]
LOCAL nTable2Open, i

nTable2Open = THIS.DATASESSIONID/7 - INT(THIS.DATASESSIONID/7)

ALINES(aTblNames, ;
STRTRAN(&quot;country,customer,employee,orders,orditems,products,queries&quot;,&quot;,&quot;,CHR(13)))

ALINES(aTbls2Open, ;
STRTRAN(&quot;0.0000,0.1429,0.2857,0.4286,0.5714,0.7143,0.8571&quot;,&quot;,&quot;,CHR(13)))

nTable2Open = ASCAN(aTbls2Open,STR(nTable2Open,6,4))

FOR i = 1 TO nTable2Open
USE (_samples+&quot;\data\&quot;+aTblNames[ i ]) IN 0 SHARED
NEXT

ENDPROC
ENDDEFINE

[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top