CoreDBF class

This forum is meant for examples of X# code.

User avatar
wriedmann
Posts: 3783
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

CoreDBF class

Post by wriedmann »

Hi all,
if someone is interested: the attached application contains a class to permit an object oriented access to DBF files without using any VO compatible class.
There is also some code showing how to use this class.
Wolfgang
DBFServerApp.zip
(6.27 KiB) Downloaded 150 times
P.S. of course I'm open to suggestions, bug fixes, enhancements
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Juraj
Posts: 162
Joined: Mon Jan 09, 2017 7:00 am

CoreDBF class

Post by Juraj »

Hi Wolfgang,

After import DBServerApp.viaef into Xide 1.17 and compile I have tihis error message (in attachments.

Juraj
Attachments
DBFServerAppError.png
DBFServerAppError.png (13.01 KiB) Viewed 1987 times
User avatar
wriedmann
Posts: 3783
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

CoreDBF class

Post by wriedmann »

Hi Juraj,

strange.... you can remove this class from the application, it is not more needed. Or you can simply change the build type to "Text".

Wolfgang
P.S. I have XIDE 1.23 and X# 2.2a and there it compiles
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Juraj
Posts: 162
Joined: Mon Jan 09, 2017 7:00 am

CoreDBF class

Post by Juraj »

Hi Wolfgang,

after remove this class I have next error message (in atachments) in Form1:CreateDBFile..

oFieldList := List<RDDFieldInfo>{}
oFieldList:Add( RDDFieldInfo{ "FIELDC", "C", 10, 0, 0 } )
oFieldList:Add( RDDFieldInfo{ "FIELDD", "D", 8, 0, 0 } )
oFieldList:Add( RDDFieldInfo{ "FIELDN", "N", 10, 2, 0 } )
oFieldList:Add( RDDFieldInfo{ "FIELDL", "L", 1, 0, 0 } )
oFieldList:Add( RDDFieldInfo{ "FIELDM", "M", 10, 0, 0 } )

when I delete last "0" , copilation is OK.

Juraj
Attachments
DBFServerAppError01.png
DBFServerAppError01.png (72.43 KiB) Viewed 1987 times
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

CoreDBF class

Post by robert »

Juraj,
The last X# build has added an extra parameter in the constructor: this is the Flags field for VFP which is used to indicate that a field is autonumber or binary.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

CoreDBF class

Post by Karl-Heinz »

Hi Wolfgang,

the Append() is incredible slow. Even when i change in your CreateDBFile() the loop to

FOR nI := 1 UPTO 100

it still takes 5,5 seconds to create and fill both dbfs. I couldn´t believe that, and created a test. When i run the TestAppend() with X# it takes indeed seconds ! to append 100 records. When i increase the loop upto 1000, VO appends 1000 records in less than 0,1 seconds. ...

can you confirm this behaviour ?

Code: Select all

FUNCTION TestAppend() AS  VOID
LOCAL i AS DWORD 
LOCAL aFields AS ARRAY
LOCAL cDbf AS STRING  
LOCAL f AS FLOAT 
                     
    RddSetDefault( "dbfcdx" )
    
	cDBF := "D:testXDbfTest.dbf"

	aFields := { { "LAST" , "C" , 10 , 0 } } 
    
	SetExclusive ( true )  //  X#  2,36 secs   !
	// SetExclusive ( false )  // X#  4,64 secs   !
	
	? "-------------------"
	? "Create and fill DBF"
	? "-------------------"
	? DbCreate( cDBF , AFields) 
	? DbUseArea( ,,cDBF )	

	f := Seconds()
		
	FOR i := 1 UPTO 100  
		DbAppend() 
		FieldPut ( 1 , PadL ( i , 10 , "0" ) )
						
	NEXT 
	
	
	? "Elapsed:" , Seconds() - f
	
	DbCloseArea()
	
RETURN 

regards
Karl-Heinz
User avatar
wriedmann
Posts: 3783
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

CoreDBF class

Post by wriedmann »

Hi Karl-Heinz,

this is really strange!
I have to check it out later today.
Basically the Append() method does the following:

Code: Select all

public virtual method Append( lReleaseLocks as logic ) as logic
	local lReturn		as logic
	local nSaveArea		as dword

	nSaveArea			:= RuntimeState.CurrentWorkArea
	lReturn				:= false
	try
	RuntimeState.CurrentWorkArea	:= _oRDD:Area

   	lReturn				:= CoreDB.Append( lReleaseLocks )

   	catch oEx as Exception

	self:ProcessException( oEx )
	lReturn				:= false

	finally
	RuntimeState.CurrentWorkArea	:= nSaveArea

	end try

    return lReturn
So I don't see any cause why it could be so slow....

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1590
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

CoreDBF class

Post by FFF »

Wolfgang,
yes, strange.
Took your code, imported Aef into Xide1.23, compiles, runs.
Click "Create DBF" - Bang, "konnte nicht auf eine Objectinstanz festgelegt werden".
looked in Code, find defaultpath for DBF is c: temp, change to zu "D:" (as i have no c:temp)
recompile, run, create dbf
swap to explorer, to look, if true -> yes, - dbf and fpt written
come back to app -> apphang.
?
EDIT: coming back after writing this, i find a "DBF written" messagebox. Hit ok. Looking NOW into explorer, i see also a cdx file written. I'm rather sure, it wasn't there, when i first looked ;)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

CoreDBF class

Post by Karl-Heinz »

Hi Karl,

the app doesn´t hang, but you have to wait ... or decrease the for loop as i did ;-)

The problem is not Wolfgang´s class, the problem is IMO the way a append currently works.

regards
Karl-Heinz
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

CoreDBF class

Post by Karl-Heinz »

Hi Karl,

am i correct that you´re using win8.1 64bit, and you´re still facing the mentioned append speed issues ?

regards
Karl-Heinz
Post Reply