PDA

View Full Version : connecting to MySQL through it's API



Philip_Anselmo
23rd May 2006, 16:37
I'm now trying to connect to my app to MySQL using mysql.h from MySQL 4.1.... as I just can't make the damn plugin... somewhere theres a post explaining the plugin stuff.. :rolleyes:

The thing now is that after I made the connection I retrieve the table list as this:



.......
#include <mysql.h>
....
..
MYSQL_RES *res;
...
..

QStringList tablas()
{
if (!res=mysql_list_tables( &mysql, NULL ))
{
QMessageBox::warning(0,"No se pudo obtener la lista de tablas", mysql_error( &mysql ));
}
QStringList listaTablas = res->toStringList;
//convert MYSQL_RES to QSTRINGLIST ???
for ( QStringList::Iterator it = listaTablas.begin(); it != listaTablas.end(); ++it ) {
qWarning(*it + "\n");
}
//muestra en consola la lista de tablas de la base de datos a la que se conecto

return listaTablas;
}


so the question is..... tararraaarrataaan.
how do i get res to fill a QStringList? :confused:

I've tryed casting:

QStringList listaTablas = (QStringList)res;

Dumbass way:

QStringList listaTablas = res;

and DumbAss2 xD as there is no member... etc
error: 'struct st_mysql_res' has no member named 'toStringList

QStringList listaTablas = res->toStringList;


Any ideas?
the final idea is to fill a qcombobox with the QStringList with the table list



CB_Tablas->insertStringList(tablas());


as you can see the function named tablas returns a QStringList that contains or should contain the table list from the database

please don't tellme to use qdatabase.h as that's now not an option :(

wysota
23rd May 2006, 17:11
You have to process the result row by row and extract the data yourself... You can take a look at QMYSQL plugin to see how it does it. Oh, and don't give up compiling that plugin :D To be honest I have never had problems with that... Maybe you should try one more time? You can take a look ath the FAQ (http://www.qtcentre.org/forum/faq.php?faq=qt_faq_section#faq_qt_compiling_mysql_ plugin_category), maybe it'll help you.

Philip_Anselmo
23rd May 2006, 21:30
jajja I finally made de damn plugin but I'm still geting ths Driver not Loaded shh..
I'm now running:

configure -plugin-sql-mysql -I d:\mysql\include -L d:\mysql\lib\opt

if that doesn't work... I finnished with the damn plugin... :mad:

And I'm looking to the code on the main.cpp from the mysql plugin and nothing so I'm looking on the qsql_mysql.cpp and well no ideas yet :(

... jejejej wait a second I think I got the idea xD... :$ as you can tell i'm working on real time XD

I realy hope the plugin work.... I would like to keep it qt and not doing a mixed ..... thing..

jacek
23rd May 2006, 21:32
Do you use Qt3 or Qt4?

Philip_Anselmo
23rd May 2006, 21:48
on this case. I'm working on Qt 4.1.2 as I need to make the plugin for an app which needs to run on windows... so everything I made on linux and works with the Qt 3.1.2 on linux has to run on wnidows compiled and ported to Qt 4.1.2 the ap and the porting works perfectly.. I just have to modify de conection... change the pointer for a variable.. changing the '->' for '.' etc.. and I have to add the #include <qsqlerror.h> but it works without problems excepet for the "Driver not Loaded"...

jacek
23rd May 2006, 22:03
it works without problems excepet for the "Driver not Loaded"...
Check with Dependency Walker (http://www.dependencywalker.com) if your application and the plugin can find all DLLs they need. If there is a missing DLL, find it and place in the same directory as the executable.

Philip_Anselmo
24th May 2006, 15:49
I ran DependencyWalker on my app's exe and it tells me that couldn't find MSJAVA.DLL
:confused:
java?
I don't remember have used java so... ?

but well..
on the other side.. I'm now worried about how to populate a qdatatable using the MySQL API ... mysql.h etc etc
I made a conection and populated a qcombobox with the tables from the database..
so now I'm trying to populate a qdatatable with the qsqlcursor... but I guess I'm not able to use it as the connection is made through the MySQL API not by qt.

jacek
24th May 2006, 16:27
I ran DependencyWalker on my app's exe and it tells me that couldn't find MSJAVA.DLL
You can safely ignore msjava.dll. Are there any other missing DLLs (especially for the plugin)?

Philip_Anselmo
24th May 2006, 18:09
it tells me that the libmysql.dll is missing so I putted it on the same folder as the exe and the qsqlmysql.dll and there's still Driver not Loaded message :(

and the other way using a MySQL API connection works on linux but on windows at compilling time... it just tells me errors on mysql_com.h and that a SOCKET is created without a type :confused:

¬¬ Qt hates me...

jacek
24th May 2006, 18:13
it tells me that the libmysql.dll is missing so I putted it on the same folder as the exe and the qsqlmysql.dll and there's still Driver not Loaded message
Do I understand you correctly that you have placed the plugin and the executable in the same directory?

wysota
24th May 2006, 20:16
qsqlmysql.dll should be in "sqldrivers/" subdirectory.

Philip_Anselmo
24th May 2006, 21:13
yeap there it is...
and also in the release folder and in the source code dierctory... you know the one where main.cpp conexion.cpp and all cpps and hs files are


but.. well so the driver it's giving trouble so... another aproach is connecting directly with the MySQL API ... any ideas there? like.. why is not working in windows?

(I added LIS -Ld:\mysql... -lmysql.. and INCPATH -I d:\m....\niclude.. to the Makefiles)

I retrieve the table list to a combobox but how to fill a qdatatable with the table selected from MySQL? :confused: as it uses a qsqlcursor to get filled... how do I fill the cursor or the table directly?

Help PleasEEEE

jacek
24th May 2006, 21:54
but.. well so the driver it's giving trouble so... another aproach is connecting directly with the MySQL API ...
If you can't make the plugin work, then try compiling it into the Qt (use -qt-sql-mysql instead -plugin-sql-mysql).

Philip_Anselmo
24th May 2006, 22:45
In the case that the configure -qt-sql-mysql works
what would be the diference?.. I'm now compilling with make after the configure...
after comnpilling my app in the case it works.. how should I pack my app to work on other windows whithout the Qt 4.1.2 installed?

jacek
24th May 2006, 22:49
In the case that the configure -qt-sql-mysql works
what would be the diference?..
You won't have a separate DLL with the plugin. If it won't work, at least you will know why.


how should I pack my app to work on other windows whithout the Qt 4.1.2 installed?
The same way, only without the qsqlmysql.dll file.

Philip_Anselmo
25th May 2006, 22:52
I just get errors... :( the same that i got with the plugin :(

jacek
25th May 2006, 23:08
I just get errors... :( the same that i got with the plugin :(
What commands did you issue? Could you post the exact error message?

Philip_Anselmo
30th May 2006, 18:08
I just did exactly this:



configure -qt-sql-mysql -I d:\mysql\include -L d:\mysql\lib\opt -l libmysql


and there were some errors that now I can't remember.. so I guess isn't of too much help unless I type the command on a wrong way

but the includes from mysql and the libs are there where i told the configure to look for...
the libmysql.lib libmysql.a and libmysql.dll
the libmysql.a was made acording to the manual on other posts..
I posted the lines I used to make it on qtforum and them has been referenced to a lot of people who used them and get the plugins to work and once I used them too and it worked but not now :crying:

wysota
30th May 2006, 18:10
Unfortunately we can't help without knowing what the errors are :(

jacek
30th May 2006, 19:15
I just did exactly this:[...]
IMO it should be:
configure -qt-sql-mysql -Id:\mysql\include -Ld:\mysql\lib\opt

wysota
31st May 2006, 00:22
IMO it should be:
configure -qt-sql-mysql -Id:\mysql\include -Ld:\mysql\lib\opt

AFAIK both are ok.