mtangoo / wxDatabase

wxWidgets library for connecting to major relational database
http://mtangoo.github.io/database/index.html
37 stars 17 forks source link

Working with ODBC with a graphical interface. #28

Closed Melandr closed 2 years ago

Melandr commented 3 years ago

Good evening, could you add an example of working with ODBC in a graphical interface to the library? As it is not clear, you need to create a wxDatabase object or a wxOdbcDatabase object. Also, there is still a question about building the library in the Cmake gui, why is it that when specifying the use of odbc, the library is built with the preprocessor directive wxUSE_DATABASE_ODBC off. How should CMakeLists.txt be changed for correct assembly to work through ODBC? 2021-11-22_215010 The application from the samples folder builds and runs, but it uses the parent of all database classes. And on the forum https://forums.wxwidgets.org/viewtopic.php?f=34&t=48736&p=209286#p209286 it is advised to use the odbc constructor, not an abstract class.

mtangoo commented 2 years ago

Hi @Melandr There is already and example of how to use wxDatabase with various databases. However the code is commented and might be convoluted for the beginner. I will see what I can do to make it easier to get started. I will also update documentation to add get started.

For that reason I will leave this ticket open until that is fixed.

As of enabling ODBC, checking ENABLE_ODBC (which is not checked in your CMake GUI) should be enough. If ODBC libraries and headers are found it should build wxDatabase with ODBC enabled.

As said in forum connection should be of type wxDatabase. Then when instantiating it, use specific database class, all of them defined by wxDatabase and well documented

here is an example for ODBC

wxDatabase *db = new wxOdbcDatabase();
wxString dsn = "Driver={PostgreSQL};Server=127.0.0.1;Port=5432;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";
if(db->open(dsn))
{
    int affected = db->RunQuery("UPDATE users SET is_active = false");
    wxString message = wxString::Format("Affected rows: %d", affected);
    wxPuts(message);
} else {
    wxPuts(db->GetErrorMessage());
}

That, in combination with forum comments, should give you idea how to do it.

mtangoo commented 2 years ago

Hi @Melandr I have pushed an easy implementation of the sample app. Can you check and offer your comments? I would like to hear how easy it is before I incorporate all other connection. For that reason, for now only SQLite3 is supported and hence a need to enable it on CMake

Melandr commented 2 years ago

Good night! Sorry for not responding for a long time, there were problems with the computer. I had to completely reinstall the operating system, now I tried to rebuild the library again, it gives an error when compiling the example. My experience is not enough to figure out what the problem is. How to add SQLite3 to Cmake correctly? It would be nice to keep the old example.

mtangoo commented 2 years ago

Good night! Sorry for not responding for a long time, there were problems with the computer. I had to completely reinstall the operating system, now I tried to rebuild the library again, it gives an error when compiling the example.

Sorry for the problems you went through. I hope you got your OS working.

My experience is not enough to figure out what the problem is. How to add SQLite3 to Cmake correctly? Just make the option in this line as ON and you are set : https://github.com/mtangoo/wxDatabase/blob/8152e805f2fda92805e487ad0a85deaf6f2968bd/CMakeLists.txt#L23

Make sure all other databases you are not using are OFF

It would be nice to keep the old example. This is one step to rewriting the same example in more understandable way. If you look at it, all am doing it separate connections into functions so that one who only need SQLite3 does not need to bother with ODBC stuffs. So I want feedback with SQLite3 only before I add back everything.

Let me know if you are facing any other issue

mtangoo commented 2 years ago

One more thing (As I have been saying) do not reply from Email if you have an attachment. If you can attach to Github issue editor here it will be better. I cannot open screenshot here so difficult to help with errors you are getting!

mtangoo commented 2 years ago

I will assume all is well and close this issue