DBServer replacement

This forum is meant for questions and discussions about the X# language and tools
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

DBServer replacement

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

DBServer replacement

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

DBServer replacement

Post by FFF »

cFieldname AS STRING
I suppose?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

DBServer replacement

Post 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.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

DBServer replacement

Post 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...
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

DBServer replacement

Post by wriedmann »

Hi Karl,
do you have a better idea?
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

DBServer replacement

Post by FFF »

No idea, wether "better" ;)...
CoreDBServer
XDBServer
X#DBServer
xDBF
CoreDBF
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

DBServer replacement

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

DBServer replacement

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

DBServer replacement

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply