Page 2 of 3
DBServer replacement
Posted: Sun Jan 26, 2020 2:03 pm
by wriedmann
Hi Robert,
I'm now a step further, I think.
Code: Select all
protected method Initialize( cFileName as string, lShared as logic, lReadOnly as logic, cDriver as string ) as logic
local lReturn as logic
local cAlias as string
lReturn := true
try
cAlias := DBFHelper.ConstructUniqueAlias( cFileName )
lReturn := CoreDB.UseArea( true, cDriver, cFileName, cAlias, lShared, lReadOnly )
if lReturn
_nWorkArea := CoreDB.SymSelect( cAlias )
_oRDD := RuntimeState.Workareas:GetRDD( dword( _nWorkArea ) )
else
_nWorkArea := -1
endif
catch oEx as Exception
lReturn := false
self:ProcessException( oEx )
end try
_lInitialized := lReturn
return lReturn
Currently I'm trying to implement the SetOrder() method.
Wolfgang
DBServer replacement
Posted: Sun Jan 26, 2020 6:45 pm
by wriedmann
Hi Robert,
I have now tried to implement the FieldPut() method:
Code: Select all
public virtual method FieldPut( cFieldName, oValue as object ) as logic
local lReturn as logic
local nFieldPos as int
local nSaveArea as dword
nSaveArea := RuntimeState.CurrentWorkArea
if ( lReturn := self:Used ) .and. ( nFieldPos := self:FieldPos( cFieldName ) ) > 0
try
if RuntimeState.CurrentWorkArea != _nWorkArea
RuntimeState.CurrentWorkArea := _nWorkArea
endif
lReturn := _oRDD:PutValue( nFieldPos, oValue )
catch oEx as Exception
self:ProcessException( oEx )
end try
else
lReturn := false
endif
if RuntimeState.CurrentWorkArea != nSaveArea
RuntimeState.CurrentWorkArea := nSaveArea
endif
return lReturn
I'm doing that correctly?
Currently I don't have tested that code - have to do it.
Wolfgang
DBServer replacement
Posted: Sun Jan 26, 2020 7:56 pm
by FFF
cFieldname AS STRING
I suppose?
DBServer replacement
Posted: Mon Jan 27, 2020 5:01 am
by wriedmann
Hi Karl,
yes, of course! Thanks!
Unfortunately I had copied the function header from my AppDbServer class that inherited from DBServer, and there it was not possible to do it. Now I have changed it.
Wolfgang
P.S. I have named the class DBFAccess, so everywhere can use it, even people without VO background.
DBServer replacement
Posted: Mon Jan 27, 2020 8:42 am
by FFF
wriedmann wrote:Hi Wolfgang,
P.S. I have named the class DBFAccess, so everywhere can use it, even people without VO background.
Hm, i would probably re-think that, as it might imply, "Access" to be envolved...
DBServer replacement
Posted: Mon Jan 27, 2020 8:45 am
by wriedmann
Hi Karl,
do you have a better idea?
Wolfgang
DBServer replacement
Posted: Mon Jan 27, 2020 9:45 am
by FFF
No idea, wether "better"
...
CoreDBServer
XDBServer
X#DBServer
xDBF
CoreDBF
DBServer replacement
Posted: Mon Jan 27, 2020 9:52 am
by wriedmann
Hi Karl,
I would discard "Server" because it may sound for non VO people like a "database server" - and it is not that.
The internally used class is CoreDB, and maybe CoreDBF would be the best option.
Wolfgang
DBServer replacement
Posted: Tue Jan 28, 2020 12:34 pm
by wriedmann
Hi Robert,
my code seems to work, including creating DBF files and the relative orders.
If I understand you correctly, I have to switch the current workarea every time I do some write into the table, including order creation.
It may be important to include the code switching the workarea in a try - catch statement, and restore it afterwards.
Please let me know if this code has any drawbacks or errors (I have to add some more error checking and exception handling):
Code: Select all
public virtual method FieldPut( cFieldName as string, oValue as object ) as logic
local lReturn as logic
local nFieldPos as int
local nSaveArea as dword
nSaveArea := RuntimeState.CurrentWorkArea
if ( lReturn := self:Used ) .and. ( nFieldPos := self:FieldPos( cFieldName ) ) > 0
try
if RuntimeState.CurrentWorkArea != _nWorkArea
RuntimeState.CurrentWorkArea := dword( _nWorkArea )
endif
lReturn := _oRDD:PutValue( nFieldPos, oValue )
catch oEx as Exception
self:ProcessException( oEx )
end try
else
lReturn := false
endif
if RuntimeState.CurrentWorkArea != nSaveArea
RuntimeState.CurrentWorkArea := nSaveArea
endif
return lReturn
Thank you very much!
Wolfgang
DBServer replacement
Posted: Tue Jan 28, 2020 2:32 pm
by robert
Wolfgang,
If you want to be sure that the code to restore the workarea always runs, I would add it to a FINALLY clause.
And I am not sure why you are testing for the workarea number. Assigning should not have any negative effects.
And if you already have the RDD object then you don't need a variable for the area number as well. The number is a property of the RDD object:
Something like
Code: Select all
nSaveArea := RuntimeState.CurrentWorkArea
try
RuntimeState.CurrentWorkArea := _oRDD:Area
lReturn := _oRDD:PutValue( nFieldPos, oValue )
catch oEx as Exception
self:ProcessException( oEx )
finally
RuntimeState.CurrentWorkArea := nSaveArea
end try