Wrapper for cheetah (database access)

Developed or developing a new product in PureBasic? Tell the world about it.
infratec
Always Here
Always Here
Posts: 7619
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Wrapper for cheetah (database access)

Post by infratec »

Hi,

a coding question was the trigger to write a wrapper for PureBASIC.
Cheetah is a dll which makes it possible to access directly DBF files.
Also FoxPro databases are supported.

Look here:
http://cheetahdatabase.sourceforge.net/

I applied my wrapper as a patch:
http://sourceforge.net/tracker/?func=de ... tid=824432

If you download and unpack the file, you can directly run the examples.

Have fun :D
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Wrapper for cheetah (database access)

Post by luis »

Hi, thanks for the wrapper :)

I gave it a quick run and noticed two things.

The QueryRecords.pb example is empty (?).

In the AddRecords.pb example, in DisplayRecords(), you have defined

Protected st1.s = ""
Protected st2.s = ""
Protected st3.s = ""

but then xdbGetField() it's poking the returned fields values inside them, so you are writing to unallocated space.

Bye!
"Have you tried turning it off and on again ?"
infratec
Always Here
Always Here
Posts: 7619
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Wrapper for cheetah (database access)

Post by infratec »

luis wrote:The QueryRecords.pb example is empty (?).
That's true and right.
The original examples of QueryRecords are also empty :cry:
luis wrote: In the AddRecords.pb example, in DisplayRecords(), you have defined

Protected st1.s = ""
Protected st2.s = ""
Protected st3.s = ""

but then xdbGetField() it's poking the returned fields values inside them, so you are writing to unallocated space.
Hm...
Without = "" I got an 0 pointer address. So I added this.
In general I would agree.
But what's about this:

Code: Select all

Protected String1.s
Protected String2.s = "Test"

String1 = String2
Isn't that the same ?
During compilation it's unknown how big String1 will be.
So it is extended during runtime.
Does PokeS() the same or not?

I also never got an error message that I'm writing to an illegal address.
I expect an 'illegal memory access' or something similar.

Maybe one of our gurus can give me an ultimate explanation.

And thanks for testing :D
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Wrapper for cheetah (database access)

Post by luis »

When you assign one string to another PB know what to do, they are both strings and so the empty one is resized to make space for the copy.

With PokeS() (all the Poke*), you are simply stuffing a memory region with some data, it's up to you to make space for the data.

infratec wrote: I also never got an error message that I'm writing to an illegal address.
I expect an 'illegal memory access' or something similar.
In time you will get one, rarely the OS pops one immediately. More often you simply overwrite some other data. If you are in a hurry to get an error message just use the purifier. :)

PS: why I'm doing so much advertising for the purifier lately :mrgreen: ?
"Have you tried turning it off and on again ?"
infratec
Always Here
Always Here
Posts: 7619
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Wrapper for cheetah (database access)

Post by infratec »

Hi Luis,

I just tested AddRecords.pb with activated purifier.

It points out 3 errors.
But not at the expected positions. :cry:

One for example in the line:

Code: Select all

dbf\nData       = nDataAddress
[ERROR] Overflow in a string memory block.

But \nData is defined as long and nDataAddress is also defined as long.
So how could this happen ?

Since I have no experience with the purifier, can you give me a hint ?

Thanks in advance.

Bernd
infratec
Always Here
Always Here
Posts: 7619
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Wrapper for cheetah (database access)

Post by infratec »

Ahh...

I see :!:

I replaced = "" with Space(256) and the 3 errors gone.

But without your hint, the errors from the purifier makes absolut no sense.

Because I can only see that something is not ok, but I can not see where or what it is. :cry:
Or is there an other trick to come closer to the fault?
infratec
Always Here
Always Here
Posts: 7619
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Wrapper for cheetah (database access)

Post by infratec »

I updated the files on sourceforge.

Thanks again for checking :!:
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Wrapper for cheetah (database access)

Post by luis »

infratec wrote:
But \nData is defined as long and nDataAddress is also defined as long.
So how could this happen ?

Since I have no experience with the purifier, can you give me a hint ?

Sure. Start the program with the debugger and purifier enabled, then select from the ide menu Debugger - > Purifier. You will see a window with four sliders.

Move the "String variables" slider to the left and let the program run. This should catch the error in the right place.

These four sliders set how often the purifier must do its checks for every particular class of memory. You can set all of them to "Every line" but this will slow down the debugged program more. Depending on your hardware and the type of program you can set them to "every line".

In your case the purifier reported the problem on another line because it has checked for an error only then. The error happened before but it had not a chance to check for it until then.
"Have you tried turning it off and on again ?"
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: Wrapper for cheetah (database access)

Post by electrochrisso »

Thanks, I will try it out. :)
PureBasic! Purely the best 8)
jpotting
User
User
Posts: 12
Joined: Sat Jun 11, 2005 10:28 pm
Location: Texas, USA

Re: Wrapper for cheetah (database access)

Post by jpotting »

All the Cheetah Query functions (xdbCreateQuery, xdbQueryCondition, xdbQuerySort, xdbQueryExecute, xdbDestroyQuery, xdbQueryDistinct) are missing from the wrapper.
infratec
Always Here
Always Here
Posts: 7619
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Wrapper for cheetah (database access)

Post by infratec »

jpotting wrote:All the Cheetah Query functions (xdbCreateQuery, xdbQueryCondition, xdbQuerySort, xdbQueryExecute, xdbDestroyQuery, xdbQueryDistinct) are missing from the wrapper.
Hi,

I downloaded the file cheetahdatabase-0.02.zip and I also checked the CVS:

I didn't found one of your functions.

So please, tell me where I can find them.
Than I'll try to extend the wrapper.
jpotting
User
User
Posts: 12
Joined: Sat Jun 11, 2005 10:28 pm
Location: Texas, USA

Re: Wrapper for cheetah (database access)

Post by jpotting »

I'm not sure what is included in Cheetah4. I've been using Cheetah2 for a long time. See this Discussion http://www.purebasic.fr/english/viewtopic.php?t=30032. The PureBasic wrapper for Cheetah2 is shown there. I just assumed the Query functions would be in Cheetah4.
jpotting
User
User
Posts: 12
Joined: Sat Jun 11, 2005 10:28 pm
Location: Texas, USA

Re: Wrapper for cheetah (database access)

Post by jpotting »

Well this post got me looking for a Cheetah update. Someone already wrote a wrapper for Cheetah4. It's in the Purebasic Wrappers Repository http://code.google.com/p/rwrappers/sour ... spec=svn82.

It also looks like Cheetah4 does not include any of the query functions that were in Cheetah2.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Wrapper for cheetah (database access)

Post by netmaestro »

jpotting, could you fix your link please?
BERESHEIT
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Wrapper for cheetah (database access)

Post by Kuron »

netmaestro wrote:jpotting, could you fix your link please?
Just curious, what is wrong with it?
Post Reply