How manually mapping a field to TDatabase

How manually mapping a field to TDatabase

Postby hua » Fri Feb 22, 2019 8:00 am

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.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: How manually mapping a field to TDatabase

Postby richard-service » Sat Feb 23, 2019 9:40 am

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  Expand view

::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() )
 
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 803
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: How manually mapping a field to TDatabase

Postby nageswaragunupudi » Sat Feb 23, 2019 11:50 am

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  Expand view
  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
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How manually mapping a field to TDatabase

Postby hua » Mon Feb 25, 2019 2:38 am

Thank you very much Rao! I didn't notice the existence of :MapCol()
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 96 guests