Jump to content

DBF-UDF - dBase database read and write with DLL


funkey
 Share

Recommended Posts

Hello,
I needed to read and write dBase files. so I searched the internet and found the shapelib library (http://shapelib.maptools.org/). I compiled the DBF part of it to make a small DLL and build some wrapper functions around it. Function description is here: http://shapelib.maptools.org/dbf_api.html.

I know this can be done with COM, but I hope DLL version is faster than it and faster than SQLite. But I haven't done testing yet.

Maybe someone needs this UDF.

Download: http://autoit.de/index.php/Attachment/16455-DBF-rar/

BR
funkey



Edit: Added examples

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

I'm glad you like it.

Another example:

#include <Array.au3>
#include <Date.au3>
#include "DBF.au3"
Global $hDBF = _DBF_Create("Test.dbf")
If $hDBF = 0 Then
 ConsoleWrite("Error creating dbf file ..." & @CRLF)
 Exit
EndIf
_DBF_AddField($hDBF, "ID", $DBF_FTInteger, 10, 0)
_DBF_AddField($hDBF, "Time", $DBF_FTString, 24, 0)
_DBF_AddField($hDBF, "Value1", $DBF_FTDouble, 10, 3)
_DBF_AddField($hDBF, "Value2", $DBF_FTDouble, 10, 3)
_DBF_AddField($hDBF, "Value3", $DBF_FTDouble, 10, 3)
_DBF_AddField($hDBF, "Value4", $DBF_FTDouble, 10, 3)
For $i = 1 To 100
 _WriteValues($hDBF)
Next
Global $aDBF = _DBF_DBFToArray($hDBF)
_DBF_Close($hDBF)
_ArrayDisplay($aDBF)

Func _WriteValues($hDBF)
 $iRecords = _DBF_GetRecordCount($hDBF)
 _DBF_WriteIntegerAttribute($hDBF, $iRecords, 0, $iRecords + 1)
 _DBF_WriteStringAttribute($hDBF, $iRecords, 1, _Now() & "." & @MSEC)
 _DBF_WriteDoubleAttribute($hDBF, $iRecords, 2, Random(1, 100))
 _DBF_WriteDoubleAttribute($hDBF, $iRecords, 3, Random(1, 100))
 _DBF_WriteDoubleAttribute($hDBF, $iRecords, 4, Random(1, 100))
 _DBF_WriteDoubleAttribute($hDBF, $iRecords, 5, Random(1, 100))
EndFunc

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

I unfortunately do not know much about SQL, I am of the age of CA-Clipper + DBF

Your UDF made ​​me very happy, thank you!

5*

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Thank you JScript!

I added a few functions to the UDF and some more examples. Download link in post #1.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Hi,

Congrats for the Autoit port.

There is my port also http://www.emesn.com/autoitforum/viewtopic.php?t=4 using no dll but dbase.exe (DBase III, IV,5) as a wrapper, so in a higher logical level.

You would not realize if it is a DLL-BASED, or a wrapper-based one. Very quick, and this app makes dbase.exe modifying dbf files. It has also the BIG advantage that you can embebe several lines of "DBASE CODE SOURCE" directly and it works:

I mean you can PORT and use nice commands like thin in AUTOIT, so mixing both languages ;).

USE MYDB

LIST FIELDS, etc....

In two lines you make a lot of things. That is outdated but it works perfectly.

I got an error in your dll-app opening a dbf. I send it here.

I used your sample number 3 with a select file dialog, it is supossed to open an ArrayDisp(),

If you please, take a look at the file

it is a file with a couple of records,

Thanks for the TOPIC

Salu

PD: If somebody uses DB4 files. Pls send me in an attached file in a PM, as I wanted to test my library with this newer version.

Edited by BasicOs
Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http
Link to comment
Share on other sites

  • 2 weeks later...

@ldub: Sorry, Shapelib does not support Memo fields. And I never used them too. But I think I reading memo fields could be easily implemented by someone better than me in C language.

@BasicOS: Thanks for your comment. I cannot download your files from that link and nothing is attached to your post, sorry.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

as far i can see,

the functions DBFAddField() and DBFGetFieldInfo() are not correct.

the manual says;

pszFieldName: The name of the new field. At most 11 character will be used.

In order to use the xBase file in some packages it may be

necessary to avoid some special characters in the field names

such as spaces, or arithmetic operators.

pszFieldName: If this pointer is not NULL the name of the requested field

will be written to this location. The pszFieldName buffer

should be at least 12 character is size in order to hold

the longest possible field name of 11 characters plus a

terminating zero character.

it should be 10 characters zero terminated

so if you write a fieldname bigger then 10 characters your offset is wrong for the next item (Field type)

who start at byte 11 in the fieldtable

i hope its only wrong in the manual and not the dll

jpam

Link to comment
Share on other sites

  • 2 weeks later...

@BasicOS: Thanks for your comment. I cannot download your files from that link and nothing is attached to your post, sorry.

HERE is serie.dbf to check it.. Does somebody still use dbase IV?

https://www.dropbox.com/sh/i95ks7jrrw9lix9/X85R44_-wv

Salu2

PD: SEE ATTACHED FILE

please say if dropbox link worked, thanks

serie.zip

Edited by BasicOs
Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http
Link to comment
Share on other sites

Your dropbox link works.

serie.dbf works fine with my DBF-UDF. It has one record with only 1234 in the first column.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

@funkey thanks for checking I will review it other way...

Hi. Tried your link, but it's coming back 404.

Sorry, server was down under maintenance now is working. Remember that this port uses DBASE files, you have to copy in same directory of your autoit APP, dbaseIII or dbaseIV files. I cannot provide with port as they are propietary software.

It reuses dbase.exe to work all at as a kind of command "wrapper". That has cons and pros, one pro is that can reuse old dbase language inserting macros-like LINES OF dbase CODE, it will reuse dbase.exe for this execution. E.G.for output to printer, to file, etc...

Salu22:)

Edited by BasicOs
Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http
Link to comment
Share on other sites

  • 1 year later...

Sorry to reopen an old post, but it's still relevant!

BasicOS: Your link takes me to a spanish language page which, unfortunately is one of the few languages I don't work with!

Funkey: I got a job "fixing" an old Clipper program that I wrote in 1997 that now won't run on Windows 8! Your routine checks out on Win8 so I'm excited to see if I can do the conversion using this. Thanks a million!

Link to comment
Share on other sites

.DBF may be ancient, but MS bought FoxPro not too long ago and you would be surprised at how many dBase/DBF installations are out there.  Thank you very much for this. Is it possible to bump the two downloads (the one from VelvetElvis's link) to the top of this page? Just to make access and download easier?  As time goes by access to tools like these will become more and more important.

Thank you for sharing!

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

  • 4 months later...

Hello,

I needed to read and write dBase files. so I searched the internet and found the shapelib library (http://shapelib.maptools.org/). I compiled the DBF part of it to make a small DLL and build some wrapper functions around it. Function description is here: http://shapelib.maptools.org/dbf_api.html.

I know this can be done with COM, but I hope DLL version is faster than it and faster than SQLite. But I haven't done testing yet.

Maybe someone needs this UDF.

Download: http://www.autoit.de/index.php?page=Attachment&attachmentID=16455&h=ef6c61696ff0d78b2a904e988e53c570ac275855

BR

funkey

Edit: Added examples

new link please

Link to comment
Share on other sites

new link please

Done. German forum software version changed and so the links to there changed too.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...