Page 1 of 1
How manually mapping a field to TDatabase
Posted: Fri Feb 22, 2019 8:00 am
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
Re: How manually mapping a field to TDatabase
Posted: Sat Feb 23, 2019 9:40 am
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() )
Re: How manually mapping a field to TDatabase
Posted: Sat Feb 23, 2019 11:50 am
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
.
Re: How manually mapping a field to TDatabase
Posted: Mon Feb 25, 2019 2:38 am
by hua
Thank you very much Rao! I didn't notice the existence of :MapCol()