xsharp.eu • binary DBF access in the X# runtime
Page 1 of 2

binary DBF access in the X# runtime

Posted: Mon Jun 17, 2019 1:58 pm
by wriedmann
Hi,
is there any possibilty to get binary data from a DBF field using the X# runtime?
Thank you very much!
Wolfgang
P.S. another thing: when I call a X# VO dialect library from a X# Core application: is there any need to initialize the runtime like it was needed with the Vulcan runtime?

binary DBF access in the X# runtime

Posted: Mon Jun 17, 2019 3:53 pm
by robert
Wofgang,
Thanks for reminding me.
I will add a FieldGetBytes() function that reads the bytes directly from the buffer in the DBF
and a FieldPutBytes()
What you can do in the mean time:

Code: Select all

LOCAL oRDD as IRDD
oRdd := (IRDD) DbInfo(DBI_RDD_OBJECT)
// get the bytes from the current record
local aBytes as Byte[]
aBytes := oRDD:GetRec()
// manipulate the bytes

// and to write the bytes
oRDD:PutRec(aBytes)
// (not tested but this should work)
And there is no need to initialize the runtime afaik.
But please remember: even if you use X# Core, the Macro compiler will "silently" load XSharp.RT because it needs the USUAL type and CODEBLOCK type that are defined in XSharp.RT. So XSharp.RT should be available at runtime.

Robert

binary DBF access in the X# runtime

Posted: Mon Jun 17, 2019 4:08 pm
by wriedmann
Hi Robert,

thank you very much!
Your code will also work for memo fields? I'm mostly using memo fields to store bitmaps or compressed content (or both at the same time as bitmaps have a good compression ratio), and sometimes also for crypted content.

Of course I will make sure the RT and Macro compiler DLL are available at runtime, as they are needed by the VO dialect library.

Wolfgang

binary DBF access in the X# runtime

Posted: Mon Jun 17, 2019 5:17 pm
by robert
Wolfgang,
No this does not work for memo fields.
In the case of memo fields, the buffer contains the location of the memo in the file. To read the memo you have move the file to the right location.
You can use DbInfo(DBI_MEMOFIELD, nFieldPos) to retrieve the location of the memo in the DBT/FPT file and then retrieve the memo file handle with DBI_MEMOHANDLE, and read the data yourself.
But I will take care of this in a next build.

Robert

binary DBF access in the X# runtime

Posted: Mon Jun 17, 2019 5:59 pm
by wriedmann
Hi Robert,
I suspected that as I have some experience accessing DBF files in a binary mode.
It is not urgent, but it would be a good thing to have it in the next build.
Currently I will start to migrate my Dictionary Editor to the X# runtime and use it myself - but many other applications, including my most important ones, need the binary data.
Maybe in the meantime the trick (by Chris <g>) will help:
https://www.xsharp.eu/forum/public-vo-v ... o-a-sql-db
Wolfgang

binary DBF access in the X# runtime

Posted: Mon Jun 17, 2019 7:34 pm
by Chris
Hi Wolfgang,

I had completely forgotten about that! But, yeah this trick should work also with the X# RDD for storing/reading binary data, as it makes an extra conversion which negates the binary<->text conversion .that the RDD makes. Remember to use the simpler version of the code in post 2686: https://www.xsharp.eu/forum/public-vo-v ... ql-db#2686

Of course Robert's solution will be a lot faster, as it will return/store the raw bytes, with no conversions at all.

binary DBF access in the X# runtime

Posted: Tue Jun 18, 2019 5:48 am
by wriedmann
Hi Robert,
And there is no need to initialize the runtime afaik.
But please remember: even if you use X# Core, the Macro compiler will "silently" load XSharp.RT because it needs the USUAL type and CODEBLOCK type that are defined in XSharp.RT. So XSharp.RT should be available at runtime.
I can confirm that - my production planning application (that I have currently in development) works perfectly also with the X# runtime (and DBFCDX) without any special initialization.
The (Core dialect) WPF application is reading data from DBFs and PostgreSQL sources and writing to PostgreSQL databases (from where my VO application accesses it using a X# COM module).

Wolfgang

binary DBF access in the X# runtime

Posted: Tue Jun 18, 2019 5:51 am
by FFF
Why do you need COM? Doesn't npgsql work for you?
Only curious...

binary DBF access in the X# runtime

Posted: Tue Jun 18, 2019 6:06 am
by wriedmann
Hi Karl,

using the .NET data access I don't need anything to install on the machines. This approach works very well with MySQL, SQLite and PostgreSQL.

Wolfgang

binary DBF access in the X# runtime

Posted: Tue Jun 18, 2019 5:25 pm
by Juraj
Hi Wolfgang,

If I want to use an existing MySQL database using COM, do not need to install a MySQL server on the machines ?

Juraj