wxSqlite3 help please

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
mct1949
In need of some credit
In need of some credit
Posts: 1
Joined: Tue Jul 09, 2013 3:53 pm

wxSqlite3 help please

Post by mct1949 »

Hi All,

I have been searching the forums for a simple guide to using wxSqlite3 with Code::Blocks and wxWidgets 2.8.12 on Windows7. I have previously been using RealBasic to create a database front end :oops: but I need more control over the program and so am trying to move to C++ through wxWidgets under Code::Blocks.

So far the GUI is fine and I am learning the basics reasonably quickly. However, I can't work out how to get the program to interact with my Sqlite3 database.

Some forum entries complain about the problems compiling the wxSqlite3 DLL (which is something I always struggle with). However, I have seen suggestions that this is not necessary and all I have to do is to include the wxSqlite3 source files in my Code:Blocks project. This seems simple enough but I am not sure how to achieve this.

A simple step-by-step guide would be very welcome ... either to compile the DLL or to include the source files in my project.

Talking of DLL's, is it possible to rename the DLL's used by my program? For example; MyProg1.dll and MyProg2.dll.

Thanks in advance for your help,

Alan ...

Edit: Well! I managed to include the wxSqlite3 files into a test project - simple really :D - but I haven't yet tried to connect with a database. I'm sure it's quite straightforward (Why do we always try to make these things so difficult?) but ... I'm having great difficulty compiling the Dataview sample and I think the makefile is wrong. Is there a tutorial to show me how to correct this or, better still, an updated makefile that I can copy or download?

Again, any help will be greatly appreciated.

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

Re: wxSqlite3 help please

Post by utelle »

mct1949 wrote:So far the GUI is fine and I am learning the basics reasonably quickly. However, I can't work out how to get the program to interact with my Sqlite3 database.
This is really straight forward: you need a wxSQLite3Database object for each separate database connection. This object is then used to insert, modify, delete or select data to/from the database.
mct1949 wrote:Some forum entries complain about the problems compiling the wxSqlite3 DLL (which is something I always struggle with). However, I have seen suggestions that this is not necessary and all I have to do is to include the wxSqlite3 source files in my Code:Blocks project. This seems simple enough but I am not sure how to achieve this.
I don't use Code::Blocks myself, so I can't give detailed instructions. However, wxSQLite3 consists of only a single C++ source file and a few header files. It should be easy to set up a C::B project to compile wxSQLite3. The somewhat difficult part might be to set up the necessary include and link paths to the SQLite3 library and to set compiler defines to get the compile time options right. (You may use one of the precomiled SQLite3 DLLs coming with wxSQLite3; link libraries for GCC are included. Or you may compile SQLite3 yourself, i.e. if you want to use it as a static library. You'll find detailed instructions how to do that on this forum.)

Then there is a premake4 build file coming with wxSQLite3. Premake4 is able to generate C::B project files. It might be required to adjust the premake4 build file, though, because I haven't tested it with C::B.

In my own projects I usually include wxSQLite3 directly by adding the source files to the project.
mct1949 wrote:Talking of DLL's, is it possible to rename the DLL's used by my program? For example; MyProg1.dll and MyProg2.dll.
Usually this will not work, if you use so called link libraries to build your application, since a link library refers to the DLL by its file name. However, you could load a DLL dynamically by using for example the class wxDynamicLibrary. In that case you are free to rename your DLL.
mct1949 wrote:Edit: Well! I managed to include the wxSqlite3 files into a test project - simple really :D - but I haven't yet tried to connect with a database. I'm sure it's quite straightforward (Why do we always try to make these things so difficult?)
Take a look at the minimal sample coming with wxSQLite3. Although it's a command line application it shows you almost all operations you need to connect to a SQLite3 database, enter data into it and retrieve data from it.

In my own application I usually have a common wxSQLite3Database instance through which all database activities are executed. Beware, if you use multi-threading in your application: a separate wxSQLite3Database instance should be used for each concurrent thread.

Within a wxWidgets GUI application you usually have a method to initialize controls. In this method you could read values from a database connection to fill your controls with values. Of course this depends on the type of controls. For a wxGrid control you would derive a class from wxGridTableBase.
mct1949 wrote:but ... I'm having great difficulty compiling the Dataview sample and I think the makefile is wrong. Is there a tutorial to show me how to correct this or, better still, an updated makefile that I can copy or download?
Of which sample are you talking? The dataview sample in the wxWidgets distribution? Maybe you'll find some hints on the Code::Blocks forums about how to compile wxWidgets samples.

Regards,

Ulrich
Post Reply