FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Field name length
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Field name length
Posted: Wed Oct 07, 2009 08:14 AM

Hi everybody,
does exist a function that convert long field name (for instance helpful in a import program from Sql to Dbf).
into a dbf compatibile field_name (max 10 char)?

Any hints?

Does exist a kind of dbf file type that permits FIELD_NAME lenght > 10 char?

It would be nice to create a new DBF format which allows to go beyond this limit.

Thanks in advance
marco

Marco Boschi
info@marcoboschi.it
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Field name length
Posted: Wed Oct 07, 2009 11:55 PM
Marco,

If you use FWH Class TDataBase then you could easily "translate" long fieldnames into shortfield names in a similar way as Windows generates short filenames from long filenames.

This is an example to review the way Windows does it:
Code (fw): Select all Collapse
function Main()

   lMkDir( "This is a long fieldname 1" )
   lMkDir( "This is a long fieldname 2" )

   MsgInfo( LFN2SFN( "This is a long fieldname 1" ) )
   MsgInfo( LFN2SFN( "This is a long fieldname 2" ) )
   
return nil

You could create a function to make a similar conversion. Once you have it, then you could inherit from FWH Class TDataBase or modify it, so when a long fieldname is used, the TDataBase object translates it into its equivalent short fieldname:

MsgInfo( oDbf:ALongFieldName ) // the object class will translate it into a search for "ALONG~1", etc

To improve the search speed you could use hashes:
Code (fw): Select all Collapse
function Main()

   local hValue := {=>}

   hValue[ "LONGFIELDNAME1" ] := "LONGF~1"
   hValue[ "LONGFIELDNAME2" ] := "LONGF~2"

   MsgInfo( hValue[ "LONGFIELDNAME1" ] )
   MsgInfo( hValue[ "LONGFIELDNAME2" ] )
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Field name length
Posted: Thu Oct 08, 2009 06:50 AM

Antonio,
many thanks now do a test and then you'll know if it works.

Marco

Marco Boschi
info@marcoboschi.it
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Field name length
Posted: Thu Oct 08, 2009 07:16 AM

Antonio,
I tried this

include "fivewin.ch"

function Main()

LOCAL cLongName1 := "LONGFIELDNAME1"
LOCAL cLongName2 := "LONGFIELDNAME2"

MsgInfo( lfn2sfn( cLongName1 ) )
MsgInfo( lfn2sfn( cLongName2 ) )

return nil

Does not appear anything.

Marco Boschi
info@marcoboschi.it
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Field name length
Posted: Thu Oct 08, 2009 07:38 AM

Antonio,
I improve my function that shrink long field names
For every field I verify if a name already exist.
Thanks again

Marco Boschi
info@marcoboschi.it
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Field name length
Posted: Sat Oct 10, 2009 06:32 AM

Marco,

The fieldname (or a folder name) must exists in order to get LFN2SFN() working

Anyhow, thats just an example for how to create a short name from a long name. You could easily create a function that mimics LFN2SFN() behavior :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Field name length
Posted: Sat Oct 10, 2009 01:49 PM

Ok Thanks
marco

Marco Boschi
info@marcoboschi.it

Continue the discussion