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

How I Pack Table in multiuser (buffermode override 5 mode) 1

Status
Not open for further replies.

ERRY

Programmer
Jan 14, 2000
3
0
0
FR
When I in multiuser platform (buffermode override 5), I want to pack the table. But I always have a problem
 
I am not sure what 'buffermode override 5' is, & what your problem is, but before you pack the table you have to use it exclusively (use xyz excl) and it shouldnt be open by any other user.
 
Like Martin Said You can not pack a multiuser database when it is opened by oher people. My favorite trick is to run the application with SET DELETED ON then at night run a reindex routine that removes deleted records. I have a tables of tables to be reindexed at night and a routine that goes into a endless loop until the reindex is complete.<br>
<br>
Following is the code and the table structure.<br>
<br>
<br>
<br>
*/***************************************************************************<br>
*/Program : Sysindex<br>
*/System : Fox Library<br>
*/Purpose : Rebuild cdx files<br>
*/Syntax : do sysindex<br>
*/Returns : nothing<br>
*/Parameter : nothing<br>
*/Defaults : none<br>
*/Requires : nothing<br>
*/Changes : nothing<br>
*/Calls : nothing<br>
*/Version : 1.0<br>
*/Dated : 28 July 1997<br>
*/Written By: David W. Grewe<br>
*/***************************************************************************<br>
*& File Handling-Index<br>
*/***************************************************************************<br>
*/<br>
*/***************************************************************************<br>
*<br>
* Set enviroment<br>
*<br>
close data<br>
set exclusive on<br>
set deleted off<br>
set safety off<br>
set deleted off<br>
set talk off<br>
*set step on<br>
*<br>
* open the sysindex in directory you started up in BEFORE going to C: drive<br>
*<br>
? &quot;Reseting Sysindex File&quot;<br>
L_ERROR=0<br>
on error do TRAPERR<br>
use SYSINDEX alias SYSINDEX exclu<br>
if L_ERROR=0<br>
pack<br>
replace all completed with {}<br>
replace all avail with .t.<br>
endif<br>
use SYSINDEX alias SYSINDEX shared<br>
set filter to empty(completed)<br>
*<br>
* set default to c: drive there is a reason for this see diskspace() command<br>
*<br>
L_DEFAULTDIR = sys(5) + sys(2003)<br>
set default to c:\<br>
*<br>
* program memvars<br>
*<br>
C_CDXPRG = &quot;C:\CDXPRG.PRG&quot;<br>
C_CDXFXP = &quot;C:\CDXPRG.FXP&quot;<br>
L_ERROR = 0<br>
*<br>
* do forever until all records have a date in sysindex.completed field<br>
*<br>
do while .t.<br>
select SYSINDEX<br>
goto top<br>
do while !eof()<br>
*<br>
* tell user what is up and loop<br>
*<br>
L_PERCENT = str(((recno() / reccount()) * 100) , 6 , 2)<br>
L_MSG = &quot;Percent Complete=&quot; + alltrim(L_PERCENT)<br>
wait L_MSG window nowait<br>
clear<br>
*<br>
if SYSINDEX.NAME = &quot;SYSINDEX&quot;<br>
replace SYSINDEX.AVAIL with .T.<br>
replace SYSINDEX.COMPLETED with date()<br>
skip<br>
loop<br>
endif<br>
*<br>
if SYSINDEX.AVAIL = .f.<br>
skip<br>
loop<br>
endif<br>
*<br>
if !empty(SYSINDEX.COMPLETED)<br>
skip<br>
loop<br>
endif<br>
*<br>
* define loop memvars<br>
*<br>
replace SYSINDEX.AVAIL with .F.<br>
? &quot;Working On &quot; + alltrim(SYSINDEX.name)<br>
L_ERROR = 0<br>
L_TGTDBF = alltrim(SYSINDEX.WORKAREA) + alltrim(SYSINDEX.NAME) + &quot;.DBF&quot;<br>
L_TGTCDX = alltrim(SYSINDEX.WORKAREA) + alltrim(SYSINDEX.name) + &quot;.CDX&quot;<br>
L_TGTFPT = alltrim(SYSINDEX.WORKAREA) + alltrim(SYSINDEX.name) + &quot;.FPT&quot;<br>
L_SRCDBF = alltrim(SYSINDEX.DRIVE) + alltrim(SYSINDEX.directory) + alltrim(SYSINDEX.name) + &quot;.DBF&quot;<br>
L_SRCCDX = alltrim(SYSINDEX.DRIVE) + alltrim(SYSINDEX.directory) + alltrim(SYSINDEX.name) + &quot;.CDX&quot;<br>
L_SRCFPT = alltrim(SYSINDEX.DRIVE) + alltrim(SYSINDEX.directory) + alltrim(SYSINDEX.name) + &quot;.FPT&quot;<br>
*<br>
* set up the error trap<br>
*<br>
select 2<br>
on error do TRAPERR<br>
*<br>
* Will the file fit on the hard drive<br>
*<br>
L_handle = fopen(L_SRCDBF)<br>
L_Size = fseek(L_handle,0,2)<br>
= fclose(L_handle)<br>
*<br>
if file(L_SRCCDX)<br>
L_handle = fopen(L_SRCCDX)<br>
L_Size = L_Size + fseek(L_handle,0,2)<br>
= fclose(L_handle)<br>
endif<br>
if file(L_SRCFPT)<br>
L_handle = fopen(L_SRCFPT)<br>
L_Size = L_Size + fseek(L_handle,0,2)<br>
= fclose(L_handle)<br>
endif<br>
*<br>
if L_Size &gt; diskspace()<br>
*<br>
* file will not fit<br>
*<br>
? &quot;File Will Not File On Drive C:, Start the program on a computer With More Drive Space&quot;<br>
use<br>
select SYSINDEX<br>
replace SYSINDEX.avail with .T.<br>
skip<br>
= inkey(2)<br>
loop<br>
endif<br>
*<br>
* file fits<br>
*<br>
use (L_SRCDBF) exclu<br>
on error<br>
*<br>
* if file is in use skip and got to next database<br>
*<br>
if L_ERROR = 1<br>
? &quot;Can't Open File, Either It's: 1. Open, 2. Location Problem, 3. Corrupt&quot;<br>
select SYSINDEX<br>
replace SYSINDEX.AVAIL with .t.<br>
skip<br>
= inkey(2)<br>
loop<br>
endif<br>
*<br>
* change enviroment<br>
*<br>
if SYSINDEX.pack = .T.<br>
set deleted on<br>
else<br>
set deleted off<br>
endif<br>
*<br>
* if there are no indexes on the file<br>
*<br>
if empty(SYSINDEX.CDXPRG)<br>
if SYSINDEX.pack<br>
? &quot;No Index on File, Removing Deleted Records&quot;<br>
pack<br>
else<br>
? &quot;No Index on File, Pack Not Requested.&quot;<br>
endif<br>
use<br>
select SYSINDEX<br>
replace SYSINDEX.completed with date()<br>
skip<br>
? &quot;Action Completed&quot;<br>
? &quot;&quot;<br>
loop<br>
endif<br>
*<br>
if !empty(tag(1))<br>
set order to (tag(1))<br>
endif <br>
*<br>
* No one has the file open, copy to C drive to work on<br>
*<br>
? &quot;Making A Backup Copy In Case Something Goes Wrong&quot;<br>
set talk on<br>
copy to (L_TGTDBF)<br>
*<br>
select 3<br>
use (L_TGTDBF) exclu<br>
*<br>
* create a index file and reindex to file<br>
*<br>
? &quot;Starting Reindex On Backup Copy&quot;<br>
copy memo SYSINDEX.CDXPRG to (C_CDXPRG)<br>
set talk off<br>
comp (C_CDXPRG)<br>
wait clear<br>
set talk on<br>
do &C_CDXPRG<br>
set talk off<br>
select 3<br>
use<br>
*<br>
* move files back to their orginal location<br>
*<br>
? &quot;Replacing Orginal File With Reindexed Backup Copy&quot;<br>
select 2<br>
use<br>
delete file (L_SRCDBF)<br>
delete file (L_SRCCDX)<br>
delete file (L_SRCFPT)<br>
*<br>
set talk on<br>
if file(L_TGTFPT)<br>
copy file (L_TGTFPT) to (L_SRCFPT)<br>
endif<br>
if file(L_TGTCDX) <br>
copy file (L_TGTCDX) to (L_SRCCDX)<br>
endif<br>
copy file (L_TGTDBF) to (L_SRCDBF)<br>
set talk off<br>
if SYSINDEX.CLEANUP = .T.<br>
delete file (L_TGTDBF)<br>
delete file (L_TGTCDX)<br>
delete file (L_TGTFPT)<br>
endif<br>
delete file (C_CDXPRG)<br>
delete file (C_CDXFXP)<br>
*<br>
* update database<br>
*<br>
select SYSINDEX<br>
replace completed with date()<br>
skip<br>
<br>
enddo && (! eof sysindex)<br>
* && Reset enviroment<br>
wait clear<br>
set deleted on<br>
goto top<br>
if eof()<br>
exit<br>
endif<br>
wait window &quot;Waiting 5 seconds for next loop&quot;+chr(13) + &quot;Ctrl+End to stop Loop&quot; timeout 5<br>
if lastkey() = 23<br>
exit<br>
endif<br>
*<br>
enddo<br>
*<br>
set default to (L_DEFAULTDIR)<br>
clear<br>
return<br>
*<br>
*<br>
*<br>
procedure TRAPERR<br>
******************<br>
L_ERROR = 1<br>
= inkey(1.0)<br>
return<br>
<br>
<br>
<br>
<br>
Structure for table: D:\BIDSYS\DBF\SYSINDEX.DBF<br>
Number of data records: 96 <br>
Date of last update: 02/11/00<br>
Memo file block size: 64<br>
Code Page: 1252 <br>
Field Field Name Type Width Dec<br>
1 DRIVE Character 2<br>
2 DIRECTORY Character 25<br>
3 NAME Character 10 <br>
4 WORKAREA Character 25<br>
5 PACK Logical 1<br>
6 CLEANUP Logical 1<br>
7 AVAIL Logical 1<br>
8 COMPLETED Date 8<br>
9 CDXPRG Memo 4<br>
10 MAINTPRG Memo 4<br>
<br>
<br>
<br>

 
Sometimes it is necessary to do a little system maintenance. Sometimes the middle of the night just doesnt cut it. If you want to do and index and pack in your code, you should verify that you can use the tables exclusivly. <br>
Here is an example of such code.<br>
<br>
* Create an array of all tables in the database and scan them<br>
FOR i = 1 TO 3<br>
IF !EMPTY(latables<i>)<br>
ls_retry = &quot;RETRY&quot;<br>
ls_table = latables<i><br>
IF !lb_quit_program<br>
DO WHILE ls_retry = &quot;RETRY&quot;<br>
* If the file exists, check it by opening it<br>
IF FILE(&quot;data\&quot;+ls_table+&quot;.dbf&quot;)<br>
* Open the next table<br>
IF used(ls_table)<br>
USE IN (ls_table)<br>
ENDIF<br>
USE (ls_table) IN 0 EXCL && set_buf_optimistic takes care of this<br>
IF !CURSORSETPROP(&quot;BUFFERING&quot;,1,ls_table)<br>
lb_quit_program = .T.<br>
EXIT<br>
ENDIF<br>
IF USED(ls_table)<br>
* If the table is used, it is ok. Close it and try the next table.<br>
USE IN (ls_table) && new ah 9/23<br>
USE<br>
ls_retry = &quot;OK&quot;<br>
ELSE<br>
* If the table is not used, it had a problem. If retry is false, do not continue.<br>
IF ls_retry = &quot;QUIT&quot;<br>
lb_quit_program = .T.<br>
ENDIF<br>
ENDIF<br>
ELSE<br>
* If the file does not exist, an update is needed<br>
WAIT window &quot;no file found&quot;<br>
gb_update_needed = .T.<br>
ls_retry = &quot;OK&quot;<br>
ENDIF<br>
ENDDO<br>
ON ERROR<br>
IF lb_quit_program<br>
EXIT<br>
ENDIF<br>
ENDIF<br>
ENDIF<br>
ENDFOR<br>
<br>
SET EXCLUSIVE OFF<br>
IF lb_quit_program<br>
=messagebox(&quot;Unable to gain sole access to tables, process aborted.&quot;,48+0,&quot;exclusive access denied&quot;)<br>
ENDIF<br>
RETURN !lb_quit_program<br>
ENDFUNC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top