Anybody know a good C++ wrapper for sqlite?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Wridmuld
Experienced Solver
Experienced Solver
Posts: 58
Joined: Mon Nov 13, 2006 1:03 pm

Anybody know a good C++ wrapper for sqlite?

Post by Wridmuld » Thu Nov 23, 2006 8:17 pm

I am currently working on a database program for my movies.
I have decided to at least try to use the sqlite db.
However, I want to use a c++ wrapper for it.
Do you guys know of a good one, that's fairly easy to use?

Thanks

/Wridmuld

Sof_T
Can't get richer than this
Can't get richer than this
Posts: 864
Joined: Thu Jul 28, 2005 9:48 pm
Location: New Forest, United Kingdom
Contact:

Post by Sof_T » Thu Nov 23, 2006 8:45 pm

wxsqlite
The home of Sof.T http://www.sof-t.site88.net/
Author of Programming with wxDevC++
http://sourceforge.net/projects/wxdevcpp-book/

jb_coder
Super wx Problem Solver
Super wx Problem Solver
Posts: 267
Joined: Mon Oct 18, 2004 10:55 am

Post by jb_coder » Fri Nov 24, 2006 2:16 am

The SQLite Wiki has a page on C++ wrappers at http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers

Supporting the latest SQLite3 library, wxSQLite3 is available at http://wxcode.sourceforge.net/components/wxsqlite3/ and provides access to all of the functionality available in SQLite.

Another wxWidgets inferface to SQLite3 is DatabaseLayer at http://wxcode.sourceforge.net/components/databaselayer/ which provides a subset of the functionality to support queries, transactions, and prepared statements.

There are many other C++ wrappers listed on the Wiki page mentioned above that are not wxWidgets specific but may work well for you.

bigpilot
I live to help wx-kind
I live to help wx-kind
Posts: 167
Joined: Tue Sep 19, 2006 8:33 am

Post by bigpilot » Fri Nov 24, 2006 7:49 am

I'm using SQLite without a wrapper and that works just fine. I recommend it.
Soon to be world famous ;)

emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Post by emarti » Sat Nov 25, 2006 5:25 pm

bigpilot wrote:I'm using SQLite without a wrapper and that works just fine. I recommend it.
You are right.
- T U R K E Y ?
- I love this country!

WebSites:
http://mebt.sourceforge.net/
http://wxquran.sourceforge.net/

JSThePatriot
Earned some good credits
Earned some good credits
Posts: 146
Joined: Sun Nov 26, 2006 7:37 am
Location: Tennessee, USA
Contact:

Post by JSThePatriot » Sun Nov 26, 2006 7:40 am

bigpilot wrote:I'm using SQLite without a wrapper and that works just fine. I recommend it.
Out of curiosity, if you are using a C++ to create your wxWidgets program how do you just use the SQLite without a wrapper? (SQLite is written in C)

I am not very good with the C vs C++ issues. I can use them each by themselves, and at a novice level on both.

I have created a plugin using SQLite for a scripting language that I use a lot on MS Windows, I just used C as it was already written in C.

I do apologize for hijacking the thread as it may seem, but I think this information would be useful to know for those of us that dont know very well how to go about it.

JS

metalogic
Super wx Problem Solver
Super wx Problem Solver
Posts: 307
Joined: Fri Oct 08, 2004 8:21 am
Location: Area 51
Contact:

Post by metalogic » Sun Nov 26, 2006 9:07 am

JSThePatriot wrote:if you are using a C++ to create your wxWidgets program how do you just use the SQLite without a wrapper? (SQLite is written in C)
There's nothing to it. Just link to your C library and call the functions. To get around the few incompatibilities you can use the following when including the header

Code: Select all

extern "C"
{
    #include "MyCHeader.h"
}
That's my understanding anyway. I must admit I haven't done much of this since I haven't had a need for it yet.

Also, here's an article on this:
http://www.parashift.com/c++-faq-lite/m ... d-cpp.html

vdell
Moderator
Moderator
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell » Sun Nov 26, 2006 12:54 pm

I would also give my voice for wxSqlite3. I don't see any reasons for using the raw C Api in a C++ app.
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere

bigpilot
I live to help wx-kind
I live to help wx-kind
Posts: 167
Joined: Tue Sep 19, 2006 8:33 am

Post by bigpilot » Sun Nov 26, 2006 2:26 pm

vdell wrote:I would also give my voice for wxSqlite3. I don't see any reasons for using the raw C Api in a C++ app.
I see many reasons.

The first is: using the SQLite API directly isn't harder than with a wrapper. In fact, I would say it's downright easy.

The only trick you need to know is how handle the callbacks in C++ (hint: pass the 'this' pointer to the callback routine parameter and in the callback function cast the pointer to the C++ class).
Soon to be world famous ;)

User avatar
T-Rex
Moderator
Moderator
Posts: 1195
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex » Sun Nov 26, 2006 3:25 pm

Wll, here are my 2 cents:

- wxSQLite3 has problems with ANSI build of wxWidgets. It works perfectly with UNICODE build but I got linker errors with ANSI build. And that was one of several main reasons why I decided to use wxDatabaseLayer in my projects.
- wxDatabaseLayer seems to be good replacement for wxSQLite3 because it provides common API for several SQL servers (e.g. I'm planning to upgrade my project to Firebird 2.0 from SQLite3 and it seems that I will be able to do this with minimum efforts)
- Certainly wxSQLite3 is also god enough but it is suitable for very small projects. (IMHO)

(the same situation I had with wxMySQL library which I developed some time ago. Now I'm using wxDatabaseLayer in most of my projects)

- Also I found one more SQLite3 wrapper in mailing lists of russian shareware developers ( http://softvoile.com/development/CppSQLite3U/ ). You can try it, maybe it will fit your needs.

Regards,
T-Rex

utelle
Moderator
Moderator
Posts: 949
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Sun Nov 26, 2006 5:43 pm

T-Rex wrote:- wxSQLite3 has problems with ANSI build of wxWidgets. It works perfectly with UNICODE build but I got linker errors with ANSI build.
Let me know which problems you experience in ANSI build and I'll take a look into them. If no one is giving feedback to me as the author of wxSQLite3, how would you expect wxSQLite3 to get better?

Most problems in ANSI builds arouse from the fact that many ANSI mode users and external SQLite tools don't care about converting strings to be stored in the database to UTF-8, but doing that is the only guarantee that the resulting database file is really portable between different platforms and applications. Unfortunately SQLite itself does not enforce Unicode encoding. But wxSQLite3 does.
T-Rex wrote:- Certainly wxSQLite3 is also god enough but it is suitable for very small projects. (IMHO)
Well, wxSQLite3 is suitable for projects which are stand alone and for which SQLite3 itself offers enough features and which are not meant or planned to be ported to client/server databases. Such projects aren't neccessarily "very small".
T-Rex wrote:(the same situation I had with wxMySQL library which I developed some time ago. Now I'm using wxDatabaseLayer in most of my projects)
wxDatabaseLayer is a very good option if there is a significant chance that a project needs to support different database back ends. In respect to SQLite it has the draw back that it supports only a subset of SQLite's features.
T-Rex wrote:- Also I found one more SQLite3 wrapper in mailing lists of russian shareware developers (http://softvoile.com/development/CppSQLite3U/ ). You can try it, maybe it will fit your needs.
I really don't see why that wrapper should be a better choice than wxSQLite3 since it is not well integrated into the wxWidgets world, in contrast to wxSQLite3. But as a matter of course everybody is free to use whichever wrapper he or she likes. As stated in prior posts there are quite a few C++ wrappers for SQLite, and every wrapper has its advantages and disadvantages. wxSQLite3 is certainly no exception.

Regards,

Ulrich

JSThePatriot
Earned some good credits
Earned some good credits
Posts: 146
Joined: Sun Nov 26, 2006 7:37 am
Location: Tennessee, USA
Contact:

Post by JSThePatriot » Sun Nov 26, 2006 6:43 pm

My reason for wanting to use the SQLite API directly is for a couple of reasons.

1. I am already familiar with the API as I am creating a SQLite Plugin for AutoIt.
2. I feel that if there is no need to add extra code to get the same thing done, then not only is your executable going to be smaller, but in time probably faster on larger functions.

I do appreciate the reasons and arguments on both sides. I had forgotten about extern "C" { } thanks.

JS

User avatar
T-Rex
Moderator
Moderator
Posts: 1195
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex » Sun Nov 26, 2006 7:18 pm

I really don't see why that wrapper should be a better choice than wxSQLite3 since it is not well integrated into the wxWidgets world, in contrast to wxSQLite3. But as a matter of course everybody is free to use whichever wrapper he or she likes. As stated in prior posts there are quite a few C++ wrappers for SQLite, and every wrapper has its advantages and disadvantages. wxSQLite3 is certainly no exception.
:) I didn't say that it should be better. I just said that it may be suitable. I don't suggest to refuse use of wxSQLite3, just show another option.
Certainly it is better to use wxWidgets-based wrapper if the whole GUI and core of the project is written with wxWidgets.
Let me know which problems you experience in ANSI build and I'll take a look into them. If no one is giving feedback to me as the author of wxSQLite3, how would you expect wxSQLite3 to get better?
OK, I'll try to reproduce those errors which I had when using wxSQLite3 and then will let you know.

utelle
Moderator
Moderator
Posts: 949
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Sun Nov 26, 2006 8:01 pm

T-Rex wrote::) I didn't say that it should be better. I just said that it may be suitable. I don't suggest to refuse use of wxSQLite3, just show another option.
Certainly it is better to use wxWidgets-based wrapper if the whole GUI and core of the project is written with wxWidgets.
Isn't most of this forum about wxWidgets-based programming? :)

For my own programs I use the database component best suited for the purpose of the application, sometimes wxSQLite3, sometimes wxDatabaselayer, sometimes native database interfaces. So I totally agree that everybody else should make his decision based on his own needs.

But if wxSQLite3 is used I certainly would like to know whether there are problems or missing features.
T-Rex wrote:OK, I'll try to reproduce those errors which I had when using wxSQLite3 and then will let you know.
Thanks.

Regards,

Ulrich

vdell
Moderator
Moderator
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell » Mon Nov 27, 2006 8:10 am

bigpilot wrote:
vdell wrote:I would also give my voice for wxSqlite3. I don't see any reasons for using the raw C Api in a C++ app.
I see many reasons.

The first is: using the SQLite API directly isn't harder than with a wrapper. In fact, I would say it's downright easy.
Maybe, but I find it more easier to use C++ code in a C++ application since after all, C and C++ are completely different languages and I only know the second one. Of course the API could be easier to use for some (like for a person with a C background) but when using C directly the user is responsible for many things (like memory de/allocation) which the wrapper could take care of "under the hood".

It's also usually the case that class wrappers only create a very thin wrapper around the C code so if I really need to use the C Api then I can do so and still benefit from the features of the wrapper class. I would also say that the learning curve for such thin wrappers is very low (assuming that the class is well documented).
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere

Post Reply