FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour ERROR CON TDATABASE Y CODGRUP.DBF
Posts: 182
Joined: Wed Nov 08, 2006 11:44 PM
ERROR CON TDATABASE Y CODGRUP.DBF
Posted: Mon Dec 30, 2019 12:31 AM
Hola a todos
Estoy corriendo una funcion para modificar estructuras de bases de datos .DBF y me he encontrado con lo siguiente
Tengo una base de datos CODGRUP.DBF
si hago esto Dbusearea(.t.,,cPath+'CODGRUP',,.t.) la base se abre perfectanmente
si intento abrirla con oDbf := TDatabase():Open( , cPath+'CODGRUP' ,'DBFCDX' , .T. ) me da un error y el programa se cuelga !!!
Necesito el oDbf para poder usar oDbf:Dbstruct() en un xbrowse.
si le cambio el nombre a la DBF ej: CODIGOS.DBF lo anterior anda perfectamente ?????
No se me ocurre que pueda estar pasando , CODGRUP será una palabra RESERVADA y por eso se cuelga ? o algun error en la TDatabase ?
Estuve mirando la Clase pero no encuentro nada!
Ayuda please...
Saludos a todos y Feliz año nuevo.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: ERROR CON TDATABASE Y CODGRUP.DBF
Posted: Mon Dec 30, 2019 01:03 AM
Si pones esto
Code (fw): Select all Collapse
Dbusearea(.t.,"DBFCDX",cPath+'CODGRUP',,.t.)


También se abre bien?
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 182
Joined: Wed Nov 08, 2006 11:44 PM
Re: ERROR CON TDATABASE Y CODGRUP.DBF - SOLUCIONADO
Posted: Mon Dec 30, 2019 12:03 PM
Hola
Despues de mucho probar encontre esto:

La base de datos tiene un indice .CDX construido de esta manera
Ordcreate(".\data\codgrup","ID","codgrup->id")
Ordcreate(".\data\codgrup","DESCR","codgrup->descgrup")
Ordcreate(".\data\codgrup","CODIGO","STR(codgrup->codigo,4)")

Dbusearea(.t.,,'.\data\CODGRUP',,.t.) FUNCIONA PERFECTAMENTE
oDbf := TDatabase():Open( , '.\data\CODGRUP , 'DBFCDX' , .T. ) NO FUNCIONA

Regenero el indice de esta manera:

Ordcreate(".\data\codgrup","ID","_FIELD->id")
Ordcreate(".\data\codgrup","DESCR","_FIELD->descgrup")
Ordcreate(".\data\codgrup","CODIGO","STR(_FIELD->codigo,4)")

Dbusearea(.t.,,'.\data\CODGRUP',,.t.) FUNCIONA PERFECTAMENTE
oDbf := TDatabase():Open( , '.\data\CODGRUP , 'DBFCDX' , .T. ) FUNCIONA PERFECTAMENTE

No se por que pasa esto, teoricamente el indice debería ser igual ?????
De todas manera creo que esto le podria servir a otros a los que les pase algo similar
abrazo
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: ERROR CON TDATABASE Y CODGRUP.DBF
Posted: Wed Jan 01, 2020 03:10 PM
The real problem is to use fieldname with dbfname as alias.
Code (fw): Select all Collapse
Ordcreate (".\ Data \codgrup","DESCR", "codgrup->descgrup" )


Problem is to use "codgrup->descgrup". We should never use the dbfname as alias name while creating indexes.

If index is created in this way, the CODGRUP.DBF can never be opened with a different Alias.

For examples
USE CODGRUP SHARED VIA "DBFCDX" // works
USE CODGRUP SHARED VIA "DBFCDX" ALIAS COD // FAILS.

TDatabase always opens with a different alias and so a dbf with this kind of indexes always fails to open.

Next if you want to read the structure of a DBF, without opening the DBF, we can use the FWH function:
Code (fw): Select all Collapse
aStruct := FW_DBFSTRUCT( cDbf )

This function reads the structure from the raw dbf file without USEing it.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: ERROR CON TDATABASE Y CODGRUP.DBF
Posted: Wed Jan 01, 2020 03:31 PM
Best way to create indexes, when the DBF is used in exclusive mode:
Code (fw): Select all Collapse
function mycreateindexes()

   field ID,FIRST,AGE,DATE

   INDEX ON ID           TAG ID
   INDEX ON UPPER(FIRST) TAG FIRST
   INDEX ON AGE          TAG AGE
   INDEX ON DATE         TAG DATE

return nil


FWH function FW_CdxCreate() makes the process on indexing easy.

Code (fw): Select all Collapse
FERASE( "CUSTOMER.CDX" )
USE CUSTOMER NEW EXCLUSIVE VIA "DBFCDX"
FW_CdxCreate()
CLOSE CUSTOMER

FW_CdxCreate() without any parameters creates indexe tags on all fields. In case of character fields, the index is built on UPPER(fldname)
In addition, it creates an index
Code (fw): Select all Collapse
INDEX ON DELETED() TAG DELETED

This index is used to optimize filters.

Full Syntax:
Code (fw): Select all Collapse
FW_CdxCreate( [acTagList], [lMemory] )


Examples:
Code (fw): Select all Collapse
FW_CdxCreate( "ID,FIRST,CITY,SALARY" )
Regards



G. N. Rao.

Hyderabad, India
Posts: 182
Joined: Wed Nov 08, 2006 11:44 PM
Re: ERROR CON TDATABASE Y CODGRUP.DBF
Posted: Thu Jan 02, 2020 02:00 PM

Apreciado Mr. Rao, como siempre Ud. tan atento...
Le agradezco infinitamente su respuesta a mi problema!
Fue muy clara y didáctica, parece mentira que despues de tantos años de trabajar con DBF's me haya enterado de este importante detalle con respecto a la construccion de los CDX.
Por suerte habitualmente uso _FIELD-> los del alias fue solo en algunos pocos lugares y fueron seguramente resabios del viejo Clipper :D
Ya los modifique en todos los sitios donde encontre el 'bug'
Mi afectuoso saludo y que tenga Ud. un muy buen 2020

Continue the discussion