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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there command that whould Save current table status?

Status
Not open for further replies.

1421

Technical User
Feb 24, 2004
69
Hi All!

Is there any command that whould save the current status of the open tables, indexes and record pointers, similar to the 'save to' command used for memory?

Thank You
 
Is there any command that whould save the current status of the open tables, indexes and record pointers

You mean like this function from my Error Handler that save the status of all open tables?

Code:
  ********************************************************************
  *** [P] GETDATADETS(): Get the state of the data tables that are open
  ********************************************************************
  PROTECTED FUNCTION GetDataDets()
  LOCAL ARRAY laUsed[1]
  LOCAL lnSelect, lnCnt, lcStr, lcStat, lnFld, lcFVal, lnBMode, lcBMode
    lnSelect = SELECT()
    lcStr  = CRLF + DIVLINE ;
           + CRLF + "*** Open Table Information ***" ;
           + CRLF + DIVLINE + CRLF
    FOR lnCnt = 1 TO AUSED(laUsed)
      *** Select the work area
      SELECT ( laUsed[ lnCnt, 2 ] )
      lnBMode = CURSORGETPROP( "BUFFERING" )
      lcBMode = IIF( lnBMode = 1, "NONE", ;
                  IIF( lnBMode = 2, "Pessimistic Row", ;
                  IIF( lnBMode = 3, "Optimistic Row", ;
                  IIF( lnBMode = 4, "Pessimistic Table", "Optimistic Table"))))
      *** Get the Alias name and Record Number
      lcStr = lcStr + 'TABLE: ' + ALIAS() ;
            + ' (Buffering: ' + lcBMode + ')' + CRLF
      lcStr = lcStr + SPACE( 5 ) + 'Record #' + TRANSFORM( RECNO() )
      *** Check the record status
      IF CURSORGETPROP( 'Buffering' ) > 1 
        lcStat = NVL( GETFLDSTATE( -1 ), '0' )
        IF '3' $ lcStat OR '4' $ lcStat
          lcStr = lcStr + SPACE(5) + '  ** APPENDED **'
        ENDIF
        *** And Deletion Status
        IF GETFLDSTATE(0)%2 = 0
          IF DELETED()
            lcStr = lcStr + SPACE(5) + '  ** DELETED **'
          ELSE
            lcStr = lcStr + SPACE(5) + '  ** UNDELETED **'
          ENDIF
        ENDIF
      ENDIF
      lcStr = lcStr + CRLF
      *** Get the Details of the current record too
      FOR lnFld = 1 TO FCOUNT()
        lcFVal = ALLTRIM( TRANSFORM( EVAL( FIELD( lnFld ))))
        IF CURSORGETPROP('Buffering')>1
          *** Flag if Edited
          lcStr = lcStr + SPACE(5) ;
            + IIF( INLIST( GETFLDSTATE( lnFld ), 2, 4), ' *', '  ') + ' ' ;
            + TYPE( FIELD( lnFld )) + ' ' ;
            + PADR( FIELD( lnFld ) + ' ', 25, '.' ) + ' ' ;
            + lcFVal + CRLF
        ELSE
          *** Can't tell if it is edited or not
          lcStr = lcStr + SPACE(5) ;
            + '   ' + TYPE( FIELD( lnFld )) + ' ' ;
            + PADR( FIELD( lnFld ) + ' ', 25, '.' ) + ' ' ;
            + lcFVal + CRLF
        ENDIF
      NEXT
      lcStr = lcStr + CRLF
    NEXT
    RETURN lcStr
  ENDFUNC

Marcia G. Akins
 
Hi 1421,

It's easy to save this information -- but not so easy to restore it.

Code:
DISPLAY STATUS TO Status.Txt

* And if you want to get it into a memory variable
lcVar = FILETOSTR(Status.Txt)

You'll also get a lot of other information that you might not want.

Mike

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

I think you meant LIST STATUS TO status.txt since DISPLAY STATUS will show the 'Press any Key to continue..' if the result is more than one screen.


 
I also have such a method and even a restoring one (savesession/restoresession). But they disregard BUFFERING.

I may post it later, as a FAQ, it can be useful, if you need to create new alias(es) in the current datasession, while you want to leave anything else intact. I made this for an interface class, that would care about data access, so it opens daabase, several tables, does some SQL/xbase etc to create a result cursor and then cleans up anything as it was plus result cursor, but closes aliases not open before, resetting recnos, if they were changed.

It's much easier, if you don't need a new alias within the current datasession: You simply leave the current datasession untouched and create a new one. Make a class (PRG only) based on SESSION, and put any code for data access/manipulation in it.

Bye, Olaf.
 
mm0000,

I think you meant LIST STATUS TO status.txt since DISPLAY STATUS will show the 'Press any Key to continue..' if the result is more than one screen.

Quite right (although DISPLAY STATUS will also work if you add NOCONSOLE).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanx Everyone for your response.

I wrote the below listed code now i tested it & it works. It's being used by the below-listed xyz.prg.

Thank's again




=========================
xyz.prg
SELECT 1
USE file_a
SELECT 2
USE billing ORDER account
SELECT 3
USE B_DETAIL ORDER ACCOUNT
SELECT 4
USE insure ORDER account
SELECT 5
USE client ORDER client
open_db=SELECT() && determine # open tables
DECLARE FTBL(open_db,3) && declare table
sr_stat(open_db,'c' && saves current file status's
.......
.......
sr_stat(open_db,'o') && restores them after
return
=========================
sr_stat.prg
PARAMETERS open_db,process_sw
ALPHA='abcdefghijklmnopqrstuvwxyz'
if process_sw='c'
FOR CTR = 1 TO open_db
msel=SUBSTR(alpha,CTR,1)
SELECT &msel
FTBL [CTR,1]=DBF()
FTBL [CTR,2]=TAG()
FTBL [CTR,3]=RECNO()
ENDFOR
CLOSE DATA
else
CLOSE data
FOR CTR = 1 TO open_db
msel=SUBSTR(alpha,CTR,1)
SELECT &msel
m_use=FTBL [CTR,1]
m_order=IIF(FTBL [CTR,2]<>'','order '+FTBL [CTR,2],'')
m_goto=FTBL [CTR,3]
USE &m_use &m_order
GOTO m_goto
ENDFOR
endif
RETURN
 
Geoff,

I don't know how much of the new dbc info it stores.

None of it, if the Help is to be believed.

Did you have any particular DBC info in mind? The fact that it re-opens tables suggests that, if any of those tables belong to a DBC, it will also re-open the DBC.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
if any of those tables belong to a DBC, it will also re-open the DBC

I've just discovered that it does reopen the dbc but, to go back to the original request, CREATE VIEW doesn't restore the position of the record pointers. It does everything else that was requested - but parks you back on record #1.

Geoff Franklin
 
Hi Geoff,

that one is new to me. Has certsinly slipped through, because it looks so close to CREATE SQL VIEW.

Maybe the fact, that it reopens tables and database isn't too bad for 1421.

You could CREATE VIEW and store recno additionally by
Code:
for i=1 to aused(laAliases)
   laAliases[i,2]=recno(laAliases[i,1])
endfor
and then restore record pointer after SET VIEW.

At least, 1421, I suggest you don't take Select() for granted as the number of aliases open. It's the number of the active workarea, no more, no less. As you open up your tables with USE... IN 1,2,3... you determine in which wokarea what table is open and already know there are 5 aliases open. Still, if you want to make sure you don't close something already open in workarea you should USE ... IN 0, that's recommended. I always work with the alias names of workareas, not with workarea numbers. And therefore the more general approach is with AUSED(), which gives you all open aliases.

Bye, Olaf.
 
that one is new to me.

Glad I could add a small nugget to your vast mountain of experience<g>.

I could have sworn that it restored the record pointer but it appears that it never has:

[TT]
Format: CREATE VIEW [<viewfile>] FROM ENVIRONMENT [ALL]

This variant of CREATE builds a new FoxBASE+ view file containing information about the FoxBASE+ environment. The information saved in the view file includes all database, index, and format files currently open in all ten workareas, all fields contained in the SET FIELDS list, all established relations between open database files, all filters in effect for open databases.
[/TT]

Geoff Franklin
 
Thanx all, you are correct, Olaf I need to use aused(). I generaly either close all tables or none. The problem i have with select() is that it returns a 1 if no tables or open or if only 1 table is open...thankx.
i
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top