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
How manually mapping a field to TDatabase
How manually mapping a field to TDatabase
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
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
- 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
Hihua 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
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
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
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: How manually mapping a field to TDatabase
TDatabase has this feature for many years. To be exact, from FWH 10.02 onwards.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
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
.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: How manually mapping a field to TDatabase
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
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC