How manually mapping a field to TDatabase

Post Reply
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

How manually mapping a field to TDatabase

Post by hua »

Hi guys,
Sometimes when maintaining legacy modules, I come across dbfs which have cryptic field names.

If I have a dbf with field name cod, otr1, otp1 is it possible to create a TDatabase object where the field name is more user friendly and mapped to the physical dbf?

I mean creating oDbf:EmployeeCode to map to field cod, oDbf:OTRate1 mapped to field otr1, oDbf:OTAmount1 mapped to field otp1, etc?

Thank you for any tip
FWH 11.08/FWH 19.03
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
User avatar
richard-service
Posts: 583
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan
Contact:

Re: How manually mapping a field to TDatabase

Post by richard-service »

hua wrote:Hi guys,
Sometimes when maintaining legacy modules, I come across dbfs which have cryptic field names.

If I have a dbf with field name cod, otr1, otp1 is it possible to create a TDatabase object where the field name is more user friendly and mapped to the physical dbf?

I mean creating oDbf:EmployeeCode to map to field cod, oDbf:OTRate1 mapped to field otr1, oDbf:OTAmount1 mapped to field otp1, etc?

Thank you for any tip
Hi
These code from my old and use 3rd party LIB.
I hope TDatabase can use these easy code.

Code: Select all

::cDB := TaxBillSetMsfOpen( "TBS" )
::oDB := TDataBase():New()

....

REDEFINE GET ::oDB:oTB_HDNO      VAR ::oDB:TB_HDNO      ID 103 OF ::oDlg UPDATE        
REDEFINE GET ::oDB:oTB_STRNO     VAR ::oDB:TB_STRNO     ID 104 OF ::oDlg UPDATE            
REDEFINE GET ::oDB:oTB_TRMNO     VAR ::oDB:TB_TRMNO    ID 105 OF ::oDlg UPDATE          
REDEFINE GET ::oDB:oTB_PRSNO     VAR ::oDB:TB_PRSNO      ID 106 OF ::oDlg UPDATE READONLY   
REDEFINE GET ::oDB:oTB_REMARK    VAR ::oDB:TB_REMARK   ID 107 OF ::oDlg UPDATE         

….

IF lNew
   ::oDB:Blank()
ELSE
   ::oDB:Load()
ENDIF

IF lNew .OR. !lNew
   ::oDB:oTB_PRSMNYR:Disable()                    
   ::oDB:oTB_PRSNO:Disable()                      
   ::oDB:oTB_MONA:Disable()                       
ENDIF

IF lNew
   ::oDB:TB_BNO   := nBNO + 1
   ::oDB:TB_FULL  := "N"                               
   ::oDB:TB_PRNNO := SubStr(AllTrim(cPCNAME),1,20)   
   ::oDB:MAKER_NO := AllTrim(GetUserE_NO())            
   ::oDB:MAKER_NM := AllTrim(_USER_NAME)               
ENDIF

(::cDB)->( DbRLock()  )
::oDB:Save()
(::cDB)->( DbCommit() )
(::cDB)->( DbUnLock() )
 
Regards,

Richard

Harbour 3.2.0dev (r1904111533)/xHarbour 1.2.3 Intl. (SimpLex) (Build 20180818) => Borland C++ v7.4
xHarbour 0.99.71 (SimpLex) => Borland C++ v5.5
MySQL v5.7 /ADS v12
Harbour 3.2.0dev (r1603181642) => Borland C++ v7.4 64bit
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How manually mapping a field to TDatabase

Post by nageswaragunupudi »

hua wrote:Hi guys,
Sometimes when maintaining legacy modules, I come across dbfs which have cryptic field names.

If I have a dbf with field name cod, otr1, otp1 is it possible to create a TDatabase object where the field name is more user friendly and mapped to the physical dbf?

I mean creating oDbf:EmployeeCode to map to field cod, oDbf:OTRate1 mapped to field otr1, oDbf:OTAmount1 mapped to field otp1, etc?

Thank you for any tip
TDatabase has this feature for many years. To be exact, from FWH 10.02 onwards.

oDbf:MapCol( cFieldName, cUserFriendlyName )

or

oDbf:MapCol( { { "fld1", "name1" }, .... { "fldN","nameN" } } )

Small Sample:

Code: Select all

   local oDbf

   oDbf  := TDatabase():Open( nil, "STATES", "DBFCDX", .T. )

   oDbf:MapCol( "CODE", "StateCode" )
   oDbf:MapCol( "NAME", "StateName" )

/*
   // Alternatively, we can assign several fields together

   oDbf:MapCol( { { "CODE", "StateCode" }, ;
                  { "NAME", "StateCode" } } )

*/

   ? odbf:name, odbf:statename

   oDbf:Edit()

   XBROWSER oDbf

 
Image

Image

.
Regards

G. N. Rao.
Hyderabad, India
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Re: How manually mapping a field to TDatabase

Post by hua »

Thank you very much Rao! I didn't notice the existence of :MapCol()
FWH 11.08/FWH 19.03
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
Post Reply