Thread overview | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 18, 2010 SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Hello there. I've converted the .h file of the latest SQLite version to .d and I thought I'd let the world know (as suggested on IRC ;). Maybe it will save someone some work. I've also written a nice connector class that wraps all the C functions for convenient use in your application. It's very basic, but I will probably add more features (like automatic preparation of statements and automatic caching of several prepared statements) later. For the time being both files are included in the download: http://nexunity.com/sqlite4d.rar I'm pretty new to this kind of stuff, so what I did to get it to work was compiling the latest SQLite dll from source with dmc and then link the .obj file into my app ( http://nexunity.com/sqlite3.obj ). I'm sure there is a better way like compiling it as static lib (dmc complained about no entry point) or having some kind of other file to link into your app in order for it to compile and then use the dll. I however couldn't figure it out and it works for me. Don't hesitate to teach me nonetheless. Any kind of feedback is always appreciated. Greetings, Max. |
July 18, 2010 Re: SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Posted in reply to awishformore | == Quote from awishformore (awishformore@gmail.com)'s article
> Hello there.
> I've converted the .h file of the latest SQLite version to .d and I
> thought I'd let the world know (as suggested on IRC ;). Maybe it will
> save someone some work.
> I've also written a nice connector class that wraps all the C functions
> for convenient use in your application. It's very basic, but I will
> probably add more features (like automatic preparation of statements and
> automatic caching of several prepared statements) later.
> For the time being both files are included in the download:
> http://nexunity.com/sqlite4d.rar
> I'm pretty new to this kind of stuff, so what I did to get it to work
> was compiling the latest SQLite dll from source with dmc and then link
> the .obj file into my app ( http://nexunity.com/sqlite3.obj ).
> I'm sure there is a better way like compiling it as static lib (dmc
> complained about no entry point) or having some kind of other file to
> link into your app in order for it to compile and then use the dll. I
> however couldn't figure it out and it works for me. Don't hesitate to
> teach me nonetheless.
> Any kind of feedback is always appreciated.
> Greetings, Max.
Awesome. D1, D2 or both? I've wanted a simple database for some time now, but been too lazy to write bindings or find one one myself, which encourages me to roll my own ad-hoc formats instead. Given that sqlite is in the public domain, maybe Phobos should eventually include SQLite + a nice D-ish wrapper for it, so that people can use it w/o creating dependency hell in their projects.
|
July 18, 2010 Re: SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha | On 19/07/2010 00:57, dsimcha wrote:
> Given that sqlite is in the public domain,
> maybe Phobos should eventually include SQLite + a nice D-ish wrapper for it, so
> that people can use it w/o creating dependency hell in their projects.
Agreed, even a very popular and commercial multi OS RAD Tool called "Real Basic" comes bundled with SQLite. Let's use this excellent tool instead of the thick openrj stuff, we had before.
-bjoern
|
July 18, 2010 Re: SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha | On 19/07/2010 00:57, dsimcha wrote:
> == Quote from awishformore (awishformore@gmail.com)'s article
>> Hello there.
>> I've converted the .h file of the latest SQLite version to .d and I
>> thought I'd let the world know (as suggested on IRC ;). Maybe it will
>> save someone some work.
>> I've also written a nice connector class that wraps all the C functions
>> for convenient use in your application. It's very basic, but I will
>> probably add more features (like automatic preparation of statements and
>> automatic caching of several prepared statements) later.
>> For the time being both files are included in the download:
>> http://nexunity.com/sqlite4d.rar
>> I'm pretty new to this kind of stuff, so what I did to get it to work
>> was compiling the latest SQLite dll from source with dmc and then link
>> the .obj file into my app ( http://nexunity.com/sqlite3.obj ).
>> I'm sure there is a better way like compiling it as static lib (dmc
>> complained about no entry point) or having some kind of other file to
>> link into your app in order for it to compile and then use the dll. I
>> however couldn't figure it out and it works for me. Don't hesitate to
>> teach me nonetheless.
>> Any kind of feedback is always appreciated.
>> Greetings, Max.
>
> Awesome. D1, D2 or both? I've wanted a simple database for some time now, but
> been too lazy to write bindings or find one one myself, which encourages me to
> roll my own ad-hoc formats instead. Given that sqlite is in the public domain,
> maybe Phobos should eventually include SQLite + a nice D-ish wrapper for it, so
> that people can use it w/o creating dependency hell in their projects.
Hello.
Ah yeah, I guess I should have mentioned. I'm only working with D2 at the moment, so it is D2 right now (because of the use of string). However, it should be straight forward to replace all string occurrences with char[] to get it to work on D1. I'm pretty sure that's the only issue stopping it from working on D1.
Also, when using my wrapper, please note a few specifics with the bind method:
- to bind a zeroblob to a prepared statement, pass an int array with a single element with the size of the blob as value. Couldn't come up with a better way to make that function available through the same method.
- to bind NULL just pass null ;)
- currently, it lets you pass anything and will try to treat it as sqlite3_value struct reference, so be careful
Greetings, Max.
|
July 19, 2010 Re: SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Posted in reply to BLS | On 07/18/2010 06:22 PM, BLS wrote:
> On 19/07/2010 00:57, dsimcha wrote:
>> Given that sqlite is in the public domain,
>> maybe Phobos should eventually include SQLite + a nice D-ish wrapper
>> for it, so
>> that people can use it w/o creating dependency hell in their projects.
>
> Agreed, even a very popular and commercial multi OS RAD Tool called
> "Real Basic" comes bundled with SQLite. Let's use this excellent tool
> instead of the thick openrj stuff, we had before.
> -bjoern
I thought Qt does, too.
Python definitely does, and I've actually been using it a lot lately. One thing I noticed when switching my code from postgresql to sqlite is that their respective python libraries use different parameter styles. Otherwise, it was completely painless.
I'd love to see sqlite distributed with D, but not before a good DB API specification (not to disparage awishformore's work, of course).
|
July 19, 2010 Re: SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Posted in reply to awishformore | On 07/18/2010 05:44 PM, awishformore wrote:
> Hello there.
>
> I've converted the .h file of the latest SQLite version to .d and I
> thought I'd let the world know (as suggested on IRC ;). Maybe it will
> save someone some work.
>
> I've also written a nice connector class that wraps all the C functions
> for convenient use in your application. It's very basic, but I will
> probably add more features (like automatic preparation of statements and
> automatic caching of several prepared statements) later.
>
> For the time being both files are included in the download:
> http://nexunity.com/sqlite4d.rar
>
btw, would it be possible to distribute as something other than a rar? I wanted to have a peek at what you've done, but apparently nothing on my [linux] system can read that file.
|
July 19, 2010 Re: SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ellery Newcomer | On Sunday 18 July 2010 19:10:35 Ellery Newcomer wrote:
> On 07/18/2010 05:44 PM, awishformore wrote:
> > Hello there.
> >
> > I've converted the .h file of the latest SQLite version to .d and I thought I'd let the world know (as suggested on IRC ;). Maybe it will save someone some work.
> >
> > I've also written a nice connector class that wraps all the C functions for convenient use in your application. It's very basic, but I will probably add more features (like automatic preparation of statements and automatic caching of several prepared statements) later.
> >
> > For the time being both files are included in the download: http://nexunity.com/sqlite4d.rar
>
> btw, would it be possible to distribute as something other than a rar? I wanted to have a peek at what you've done, but apparently nothing on my [linux] system can read that file.
While I hate rar, every distribution than I have used has had unrar. There's a decent chance that it isn't installed by default though.
- Jonathan M Davis
|
July 19, 2010 Re: SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 07/18/2010 09:20 PM, Jonathan M Davis wrote:
> On Sunday 18 July 2010 19:10:35 Ellery Newcomer wrote:
>> btw, would it be possible to distribute as something other than a rar? I
>> wanted to have a peek at what you've done, but apparently nothing on my
>> [linux] system can read that file.
>
> While I hate rar, every distribution than I have used has had unrar. There's a
> decent chance that it isn't installed by default though.
>
> - Jonathan M Davis
Hmm. I suppose I could have spent more than 2 seconds trying to open it. You're right on both counts.
As for the code, I'm looking at SQLiteConnector.ptrtostr. Does reserve really work that way? Just curious - I wouldn't know one way or the other, although I would probably use something more like
string ptrtostr(char* ptr, int size = 0){
return ptr ? ptr[0 .. size].idup : null;
}
|
July 19, 2010 Re: SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ellery Newcomer | On 19/07/2010 04:59, Ellery Newcomer wrote:
> On 07/18/2010 09:20 PM, Jonathan M Davis wrote:
>> On Sunday 18 July 2010 19:10:35 Ellery Newcomer wrote:
>>> btw, would it be possible to distribute as something other than a rar? I
>>> wanted to have a peek at what you've done, but apparently nothing on my
>>> [linux] system can read that file.
>>
>> While I hate rar, every distribution than I have used has had unrar.
>> There's a
>> decent chance that it isn't installed by default though.
>>
>> - Jonathan M Davis
>
> Hmm. I suppose I could have spent more than 2 seconds trying to open it.
> You're right on both counts.
>
> As for the code, I'm looking at SQLiteConnector.ptrtostr. Does reserve
> really work that way? Just curious - I wouldn't know one way or the
> other, although I would probably use something more like
>
> string ptrtostr(char* ptr, int size = 0){
> return ptr ? ptr[0 .. size].idup : null;
> }
I think an empty array/string is safer to return than null. And yes, reserve works that way, it will reserve the space needed for the (character) array to expand.
The strings are null terminated in SQLite and you won't always know the size; I had previously used the same method in another place of my app. I however also wasn't aware that you could still access pointers like arrays in D, so that would indeed be a better way to do it when you always know the size.
You could then even go as far as not iduping, but instead casting it to a string to avoid unnecessary allocations.
Greetings, Max.
|
July 19, 2010 Re: SQLite 3.6.23.1 wrapper + connector | ||||
---|---|---|---|---|
| ||||
Posted in reply to awishformore | On 07/18/2010 11:20 PM, awishformore wrote:
>
> I think an empty array/string is safer to return than null.
It doesn't matter. D treats 'null' arrays exactly the same as empty arrays. Just think of a 'null' array as {length=0, ptr=null}
|
Copyright © 1999-2021 by the D Language Foundation