ERROR CON TDATABASE Y CODGRUP.DBF

ERROR CON TDATABASE Y CODGRUP.DBF

Postby rterraz » 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.
User avatar
rterraz
 
Posts: 182
Joined: Wed Nov 08, 2006 11:44 pm
Location: Argentina

Re: ERROR CON TDATABASE Y CODGRUP.DBF

Postby cnavarro » Mon Dec 30, 2019 1:03 am

Si pones esto
Code: Select all  Expand view

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
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: ERROR CON TDATABASE Y CODGRUP.DBF - SOLUCIONADO

Postby rterraz » 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
User avatar
rterraz
 
Posts: 182
Joined: Wed Nov 08, 2006 11:44 pm
Location: Argentina

Re: ERROR CON TDATABASE Y CODGRUP.DBF

Postby nageswaragunupudi » Wed Jan 01, 2020 3:10 pm

The real problem is to use fieldname with dbfname as alias.
Code: Select all  Expand view

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: Select all  Expand view

aStruct := FW_DBFSTRUCT( cDbf )
 

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10247
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: ERROR CON TDATABASE Y CODGRUP.DBF

Postby nageswaragunupudi » Wed Jan 01, 2020 3:31 pm

Best way to create indexes, when the DBF is used in exclusive mode:
Code: Select all  Expand view

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: Select all  Expand view

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: Select all  Expand view

INDEX ON DELETED() TAG DELETED
 

This index is used to optimize filters.

Full Syntax:
Code: Select all  Expand view

FW_CdxCreate( [acTagList], [lMemory] )
 


Examples:
Code: Select all  Expand view

FW_CdxCreate( "ID,FIRST,CITY,SALARY" )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10247
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: ERROR CON TDATABASE Y CODGRUP.DBF

Postby rterraz » Thu Jan 02, 2020 2: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
User avatar
rterraz
 
Posts: 182
Joined: Wed Nov 08, 2006 11:44 pm
Location: Argentina


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 59 guests