Page 1 of 1

Field name length

PostPosted: Wed Oct 07, 2009 8:14 am
by MarcoBoschi
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

Re: Field name length

PostPosted: Wed Oct 07, 2009 11:55 pm
by Antonio Linares
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: Select all  Expand view

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

function Main()

   local hValue := {=>}

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

   MsgInfo( hValue[ "LONGFIELDNAME1" ] )
   MsgInfo( hValue[ "LONGFIELDNAME2" ] )
   
return nil
 

Re: Field name length

PostPosted: Thu Oct 08, 2009 6:50 am
by MarcoBoschi
Antonio,
many thanks now do a test and then you'll know if it works.

Marco

Re: Field name length

PostPosted: Thu Oct 08, 2009 7:16 am
by MarcoBoschi
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.

Re: Field name length

PostPosted: Thu Oct 08, 2009 7:38 am
by MarcoBoschi
Antonio,
I improve my function that shrink long field names
For every field I verify if a name already exist.
Thanks again

Re: Field name length

PostPosted: Sat Oct 10, 2009 6:32 am
by Antonio Linares
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 :-)

Re: Field name length

PostPosted: Sat Oct 10, 2009 1:49 pm
by MarcoBoschi
Ok Thanks
marco