Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / wxWindows odbc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. wxWindows odbc
#4468
Posted by: 2004-06-15 22:43:16
Hello,

I'd like to use wxWidgets for consulting a MySQL ODBC but I don't know how to start. I don't find an example with all included libraries.
Can someone give me an example wich compile in order to start ?

Thanks in advance
Message2. Re: wxWindows odbc
#4491
Posted by: 2004-06-16 21:25:01
Please !
Message3. Re: wxWindows odbc
#4495
Posted by: upCASE 2004-06-17 00:09:06
Hi!
Other people have work to do :)
Please be patient, I'll see what I can when I get home.
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message4. Re: wxWindows odbc
#4497
Posted by: 2004-06-17 00:53:21
Thanks upCASE ;-)
Message5. Re: wxWindows odbc
#4498
Posted by: upCASE 2004-06-17 01:56:12
Hi!
Finally I'm home. Sorry that it took a bit longer, but we're in the end phase of out project so I didn't have to time to answer earlier this day....

Basically it's not that complicated to get the ODBC stuff working with wxWidgets. The first important question is: Is your lib compiled with ODBC support (iODBC if you're on Linux/Mac)?
If not -> Recompile the lib and set the corresponding defines to 1 in setup.h or download my devpack for version 2.5.1 :)
The second part is to link libodbc32.a in, so add -lodbc32 to your linker options for this project.

I suppose you allready have MySQL downloaded/installed/running locally and do have some knowledge of DBMS and SQL in general. Download and install the MySQL Connector/ODBC driver. Version 3.52 is said to be a development release, but it works just fine. Install it and configure it (remember the DSN name, user and password for later use).

To connect to a DBMS do the following:

wxDbConnectInf *ConnectInf = new wxDbConnectInf(NULL,"MyDSN", "MyLOGIN","MyPASS", "");
wxDb* db = new wxDb(ConnectInf->GetHenv());
db->Open(ConnectInf);
if(!db->IsOpen())
{
//Errorhandling code
}

This should be enough to establish a connection to the Database using the MyDSN DSN with user=MyLOGIN/pass=MyPASS.

Now, for queries you'll have two choices. Either query the DB directly or use wxDbTable to set up a table you can work on. The last possibility is very nice when you want to work with a wxDbGrid.

For a basic query try:

db->ExecSql( "SELECT * FROM myTable" );
while( db->GetNext() )
{
  //Use db->GetData() to get the data in a row
}
To set up a basic wxTable:

wxDbTable* table = new wxDbTable (db, "TestTable", 2,"");

table->SetColDefs (0, "Firstname", DB_DATA_TYPE_VARCHAR, &first,
			SQL_C_CHAR, sizeof(first), false);
table->SetColDefs (1, "Name", DB_DATA_TYPE_VARCHAR, &Name,
			SQL_C_CHAR, sizeof(Name), false);
table->Open();

Check the wxDbTable reference for more info.

I hope that this info helps a little to get things going. It's not very complete, but currently I don't have the time to hack up a proper example with SQL definitions...
Maybe someone else in the forum can comment a bit more in depth.
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message6. Re: wxWindows odbc
#4499
Posted by: 2004-06-17 02:32:34
Thanks a lot upCASE !!!!!!!!! That's very sympathetic to help me. That's better than I hoped.
In fact, I use dev-cpp 4.9.8.10 (the last). I have installed wxWindows pack. I have already the library libodbc32.a and I linked it.

It seems to be good. I have just one or two problems with first and Name but when I declare them void*, that's seems good.

I find some errors again like these but I will search more before disturbing you again. If I really don't find, I'll rewrite again in this post.

C:\Dev-Cpp\main.o(.text+0x12e)
[Warning] In function `main':
[Linker error] undefined reference to `wxDbConnectInf::wxDbConnectInf(void*, wxString const&, wxString const&, wxString const&, wxString const&, wxString const&, wxString const&)'
 
[Linker error] undefined reference to `wxDb::wxDb(void* const&, bool)'


Thanks again and have a nice day !
Message7. Re: wxWindows odbc
#4515
Posted by: 2004-06-17 18:28:18
Hello,

That's me again. I really don't find the problem. I have linked my project with libodbc32.a but I allready have "undefined reference to functions(...)". I think it comes from the libodbc32...
If I don't put -lodbc32, I have the same errors. My libodbc32.a was allready in the library directory of dev-cpp 4.9.8.10.

I give you the log compilation :
-------------------------------------------------

Compilateur: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Exécution de  make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -D__DEBUG__ main.o Projet1_private.res -o "Projet1.exe" -L"C:/Dev-Cpp/lib" -mwindows -Wl,--subsystem,windows -mwindows -lwxmsw -lstdc++ -lgcc -lodbc32 -lwsock32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32 -ladvapi32 -lopengl32 -lglu32 -lole32 -loleaut32 -luuid -lodbc32 -g3

main.o(.text+0x12e): In function `main':
C:/Dev-Cpp/include/wx/string.h:311: undefined reference to `wxDbConnectInf::wxDbConnectInf(void*, wxString const&, wxString const&, wxString const&, wxString const&, wxString const&, wxString const&)'
main.o(.text+0x1f3): In function `main':
C:/Dev-Cpp/include/wx/db.h:309: undefined reference to `wxDb::wxDb(void* const&, bool)'
main.o(.text+0x1ff): In function `main':
C:/Dev-Cpp/main.cpp:14: undefined reference to `wxDb::Open(wxDbConnectInf*)'
main.o(.text+0x222): In function `main':
C:/Dev-Cpp/include/wx/string.h:311: undefined reference to `wxDb::ExecSql(wxString const&)'
main.o(.text+0x244): In function `main':

C:/Dev-Cpp/main.cpp:21: undefined reference to `wxDb::GetNext()'
main.o(.text+0x2b6): In function `main':
C:/Dev-Cpp/include/wx/string.h:311: undefined reference to `wxDbTable::wxDbTable(wxDb*, wxString const&, unsigned short, char const*, bool, wxString const&)'
main.o(.text+0x333):C:/Dev-Cpp/include/wx/string.h:311: undefined reference to `wxDbTable::SetColDefs(unsigned short, wxString const&, int, void*, short, int, bool, bool, bool, bool)'
main.o(.text+0x393):C:/Dev-Cpp/include/wx/string.h:311: undefined reference to `wxDbTable::SetColDefs(unsigned short, wxString const&, int, void*, short, int, bool, bool, bool, bool)'
main.o(.text+0x3be): In function `main':
C:/Dev-Cpp/main.cpp:32: undefined reference to `wxDbTable::Open(bool, bool)'

make.exe: *** [Projet1.exe] Error 1

Exécution terminée

------------------------------------------------------

Could you help me again please ?
Message8. Re: wxWindows odbc
#4517
Posted by: upCASE 2004-06-17 20:51:07
Hi!
"I have installed wxWindows pack"
Which one? The 2.5.1 devpack from my site or the 2.4.2 one by Michel Weihnachter?
For Michels one: I'm pretty sure he left out ODBC support, so you can't use his devpack to compile ODBC enabled apps.

For the errors you gave: They don't come from libodbc32.a, nor do they have anything to do with ODBC in general. This is a problem of wxWidgets, meaning the library you use to compile your stuff doesn't know about the wxODBC classes like wxDb, wxDbTable etc., because these classes never got compiled and added to the lib. To confirm that open up WXDIR\include\setup.h and check line 912 (in 2.5.1) for wxUSE_ODBC. If it is defined as 0 you don't have ODBC support, if it is 1 there's a problem with the linker not finding the correct lib including the wxDB classes.
Check and post if you've got further questions.
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message9. Re: wxWindows odbc
#4518
Posted by: 2004-06-17 22:22:12
Thanks upCASE ! You're great !!!
It works now. I had the 2.4.2 version and the field wxUSE_ODBC was defined as 0.

But now, when I try to compile the "reference program" (when I create a new project) in order to display a box, I have multiple definitions .....

frame.cpp C:\Dev-Cpp\lib\libwxmsw25.a(monolib_frame.o)(.rdata$_ZTV7wxFrame+0x0)
multiple definition of `vtable for wxFrame'
...


I have read the post in this forum about this problem and I think the solution is here :
I found the solution recently. Actually, IMPLEMENT_APP() must be called out of the namespace Application { }; block.
So I finally wrote that :

IMPLEMENT_APP(Application::Core)

namespace Application {

Core::Core() { ... }

...

};

Now it works!

Thank you all,
vovor


But I don't know what is exactly Core and I don't understand what I must put instead of "..."
I'm confused to have always problems :-\ Could you help me again ? I hope it will be the last one ...
Message10. Re: wxWindows odbc
#4519
Posted by: upCASE 2004-06-17 23:11:11
Hi!
I don't think that the solution will be namespaces...
Have you tried recompiling the whole project (deleting the object .o files that where already created using the old version)?
If that doesn't do the job: I'm sorry but you ran into the same problem as mah123. Your version of mingw is (too) old. Although I'm not sure why this happens (I think it should work with older versions too), you'll either have to update mingw, or compile the whole wxWidgets lib yourself... :(
Sorry for causing this trouble, but I didn't see that coming when I compiled/released the devpack...

To update mingw: http://g.yi.org/forum/read.php?13,4080 -> Keep an eye on mah123 and achims postings. They should lead you the right way. A good advice: Use Dev-C++ with a seperate MinGW instalation (download the latest mingw, install it and point Dev-C++ to it). This will be easier to update and use...
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message11. Re: wxWindows odbc
#4525
Posted by: 2004-06-18 04:28:53
Ad: "multiple definition of `vtable for wxXxxx'"
I had the same problem after downloading <http://www.upcase.de/stuff/wxWidgets251.DevPak> and having MinGW/GCC 3.2. I downloaded MinGW/GCC 3.3 (not difficult, only overwrite some files in your Dev-C++ directory) and it worked. New GCC comes in these files (the links are pasted from another thread):
<http://prdownloads.sf.net/mingw/gcc-core-3.3.1-20030804-1.tar.gz?download>
<http://prdownloads.sf.net/mingw/gcc-g++-3.3.1-20030804-1.tar.gz?download>

Ad: "[Linker error] undefined reference to `wxDbConnectInf::wxDbConnectInf(...)"
This problem I had with wxWidgets compiled without the ODBC classes. Compile it with them ("#define wxUSE_ODBC 1" in setup.h) or use <http://www.upcase.de/stuff/wxWidgets251.DevPak> (I think it is compiled with the wxDb classes).

Ladis
http://zimtech.ceskehry.cz
Message12. Re: wxWindows odbc
#4529
Posted by: upCASE 2004-06-18 15:18:17
Hi!
Ad: "I think it is compiled with the wxDb classes" -> It is :)
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message13. Re: wxWindows odbc
#4555
Posted by: 2004-06-20 23:11:59
Hello and thanks,

Sorry to answer so late but I have downloaded from the two links and I replace / add programs and files in the respective directory and I still have the same errors.
I have add to bin, include and lib directories.
I allready hace errors like these :

C:/Dev-Cpp/lib/libwxmsw25.a(monolib_frame.o)(.rdata$_ZTV7wxFrame+0x0):frame.cpp: multiple definition of `vtable for wxFrame'
base11.o(.data$_ZTV7wxFrame+0x0):base11.cpp: first defined here
C:/Dev-Cpp/lib/libwxmsw25.a(monolib_menu.o)(.rdata$_ZTV14wxMenuItemList+0x0):menu.cpp: multiple definition of `vtable for wxMenuItemList'
base11.o(.data$_ZTV14wxMenuItemList+0x0):base11.cpp: first defined here
C:/Dev-Cpp/lib/libwxmsw25.a(monolib_menu.o)(.rdata$_ZTV6wxMenu+0x0):menu.cpp: multiple definition of `vtable for wxMenu'
base11.o(.data$_ZTV6wxMenu+0x0):base11.cpp: first defined here


Must I do something else in order to work ?
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥738.00 ·
 
 
¥1,480.00 ·
 
 
¥397.00 ·
 
 
¥950.00 ·
 
 
¥264.00 ·
 
 
¥1,005.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0