Prezados Colegas,
Existe alguma maneira de checar se um determinado arquivo de Ãndices está corrompido? Se sim, como devo proceder?
Estou utilizando DBF/CDX.
MuitÃssimo obrigado e aguardo qualquer orientação.

Moderador: Moderadores
rochinha escreveu:Amiguinhos,
aprendiz_ceMinha dica?
Simplemente apague o indices e recrie.
Indices são arquivos acessórios do seu .DBF portanto descartáveis. Só servem para organizar os dados. Poderiamos dizer que são ordenações temporárias fixas. Fixas porque criamos uma vez e usamos sempre. Ficaria demorado ter de recriar toda vez que o .DBF fosse acessado.
sele carq
seek chave
if .not. eof()
if campo-chave-de-carq#chave
Msg("Indice invalido, reindexe")
close all
quit
endif
endif
Olá rochinha,
Eu não tenho nenhuma duvida com relação o que são indexes, e muito menos para que servem. A questão é que estou fazendo uma rotina
de intercâmbio de dados e isso seria muito útil para mim.
Grato pelo seu comentário.
...
dbGotop()
dbSeek( m->procurar )
if found()
...
endif
...
* Program: VALIDNTX.PRG
* Authors: Joseph D. Booth and Greg Lief
*
* EXT Key Size
*
STATIC aOffset := { {".IDX", 17, 13},;
{".NDX", 25, 13},;
{".NTX", 23, 15},;
{".CDX",513, 13} }
#translate OrgBagExt() => ".NTX"
* Function: ValidNtx()
* Purpose: Validate an index appears ok and optionally recreate it
* Syntax: <numeric> := VALIDNTX( cFile,cExpr,lCreate )
* Arguments: cFile - Index file name, with no extension
* cExpr - Expression file is indexed on
* lCreate - Can index be created if needed?
*
* Returns: 0 - Everything ok
* -1 - File is corrupt
* -2 - File does not exist and can't be created
* -3 - Index file is set to read only
* >0 - A DOS error
* 2 - File not found
* 3 - Path not found
* 4 - Too many files open
* 5 - Access denied
* 6 - Invalid handle
* 8 - Insufficient memory
* 15 - Invalid drive specified
* 19 - Attempted to write to a write-protected
* 21 - Drive not ready
* 23 - Data CRC error
* 29 - Write fault
* 30 - Read fault
* 32 - Sharing violation
* 33 - Lock Violation
*
*
* Notes: This function examines an index file using the low
* level file functions and makes a guess as to whether
* or not the file is a valid NTX. The expression stored
* is stored with the passed expression to see if they
* matched.
*
* Example: if ValidNTX("CUST1","upper(CUST_CODE)",.T.) <> 0
* Alert("CUST1 is unavailable...")
* endif
*
***********************************************************************
function ValidNTX(cFile,cExpr,lCreate)
LOCAL nReturn := 0
LOCAL cFullName := cFile +OrgBagExt()
LOCAL x
LOCAL nHandle
LOCAL nSize
LOCAL cFileExpr
LOCAL buf
LOCAL cExt := OrgBagExt()
lcreate := if(lCreate==NIL,.F.,lCreate)
if !file( cFullname )
if lCreate
dbclearind()
index on &cExpr. to (cFIle)
dbclearind()
nreturn := 0
else
nReturn := -2
endif
elseif "R" $ GetFattr( cFullname )
nReturn := -3
else
if !IndexCorrupt( cFile,OrgBagExt() )
//
nHandle := fopen( cFullname,64 )
if nHandle = -1
nReturn := Ferror()
else
x := ascan( aOffSet, { |zz| zz[1]=upper(cExt) } )
if x > 0
buf := space(1024)
fread(nHandle,@buf,1024)
fclose(nHandle)
nSize := bin2w(substr(buf,aOffset[x,3],2))
cFileExpr := upper(cleanstr(substr(buf,aOffset[x,2],nSize)))
if cFileExpr = cExpr
nReturn := 0
else
nReturn := -1
if lCreate
dbclearind()
index on &cExpr. to (cFIle)
dbclearind()
nreturn := 0
endif
endif
else
nReturn := -1
endif
endif
//
else
nReturn := -1
endif
endif
return nReturn
dbclearind()
GetFattr( )
IndexCorrupt()
function corrupto(indice,chave)
private isbad
isbad = .f.
if isbad = .f.
return isbad
endif
v_chave = ''
set order to 0
go bott
/*if eof() .and. bof()
return .f.
endif*/
v_chave = &chave
set index to &indice
seek v_chave
if !found() .and. valtype(&chave) # 'U'
return .t.
endif
if v_chave # &chave
isbad := .t.
endif
if isbad
alerta5()
ok_ind=confirma("Arquivo de indice danificado. Deseja Corrigir? ")
if ok_ind = 2
isbad := .f.
endif
endif
return isbad
Reference Item| Description
|
DBCLEARIND() | Close indexes
DBCREATEIND() | Create an index file
DBREINDEX() | Recreate all active indexes
DBSEEK() | Search for a key value
DBSETINDEX() | Open an index
DBSETORDER() | Set the controlling order
DESCEND() | Create a descending index key value
FOUND() | Determine if the previous search operation succeeded
INDEX | Create an index file
INDEXEXT() | Return the default index extension
INDEXKEY() | Return the key expression of a specified index
INDEXORD() | Return the order position of the controlling index
REINDEX | Rebuild open indexes in the current workarea
SET INDEX | Open index file(s) in the current work area
SET ORDER | Set a new controlling index
SET UNIQUE | Toggle the inclusion of nonunique keys into an index
STATIC aOffset := { {".IDX", 17, 13},;
{".NDX", 25, 13},;
{".NTX", 23, 15},;
{".CDX",513, 13} }
SELECT...
GO TOP
IF ORDKEYCOUNT() # RECCOUNT()
VERIFY_CDX( "CADNFE" )
ENDIF
FUNCTION VERIFY_CDX( XNOMEARQ )
? "Problemas nos indices... Verifique!"
RETURN NIL
Jairo Maia escreveu:Não há em Harbour nem em Clipper nenhum recurso para isso.
Kapiaba escreveu:Tente assim:SELECT...
GO TOP
IF ORDKEYCOUNT() # RECCOUNT()
VERIFY_CDX( "CADNFE" )
ENDIF
FUNCTION VERIFY_CDX( XNOMEARQ )
? "Problemas nos indices... Verifique!"
RETURN NIL
Nascimento escreveu:no meio das minhas tranqueiras achei algo interessante possa ser que lhe ajude
Usuários vendo este fórum: Nenhum usuário registrado online e 3 visitantes