Field name length

Field name length

Postby MarcoBoschi » Wed Oct 07, 2009 8: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
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Field name length

Postby Antonio Linares » 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: 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
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Field name length

Postby MarcoBoschi » Thu Oct 08, 2009 6:50 am

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

Marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Field name length

Postby MarcoBoschi » Thu Oct 08, 2009 7: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.
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Field name length

Postby MarcoBoschi » Thu Oct 08, 2009 7:38 am

Antonio,
I improve my function that shrink long field names
For every field I verify if a name already exist.
Thanks again
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Field name length

Postby Antonio Linares » Sat Oct 10, 2009 6: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Field name length

Postby MarcoBoschi » Sat Oct 10, 2009 1:49 pm

Ok Thanks
marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Willi Quintana and 92 guests