QSqlQuery::next () returns false on OSX..
-
Hello!!
This is my code to get data from my database:
bool consultas::ec_bd_a_cuentas_parcial(){ QSqlDatabase& bd = sdata::get_instancia()->bd; const QString txt_ = QString("select * from tcuentas;"); QSqlQuery consulta(bd); qDebug() << consulta.exec(txt_); //true //this returns false, while loop never executes while (consulta.next()){ //... } }
The code works on Linux and Windows but not in OSX, I'm not sure if there is an incorrect ODBC Mysql on my Mac, but DB connection is success...
Any idea?
Thanks..! -
@U7Development
Are you 100,000% sure the database you're using on Mac really does have any rows in that table? :) Can you runselect count(*) from tcuentas;
? -
@U7Development You did not answer @JonB 's question. Please open your db with a sql browser and see if there is data in it.
-
@Christian-Ehrlicher I really 101% sure there is data ... here is a screenshot
I forgot something important, the database I'm using is MariaDB on a remote server, is accessed by all three operating systems... there is no local db..
-
Did you do what @JonB suggests with select count(*)? Did you try to insert data into the table just to see if it works?
-
@U7Development
We're not saying there isn't a problem/bug here, just that you need to try a few things. Does it depend on table? Does simply every query fail to return any rows? Does an INSERT work at all? Did you build for yourself or install the Qt or the MySQL ODBC? -
Hi,
To add to my fellows, since it's a remote database, are you sure your Mac machine is allowed to access that specific database ?
On an unrelated not, keeping local copies of QSqlDatabase object is highly not recommended as explained in the class documentation.
-
Thanks all for answering..
I'll do some queries to check if I can insert/remove or update cells from my Mac machine...
I don't know how to check if my Mac is being blocked by my DB, I just installed ODBC Mysql connector as documented...Will return later for updates.
Thanks again.
-
@U7Development Out of curiosity - if you use MariaDB why bother with ODBC if you can use MysqlConnector directly?
-
Tests done:
-
Pushing a row into tcuentas:
db is valid outputs true
db is open outputs trueif consulta.exec(). outputs true..
finally checked into tcuentas and the row exists, so the test succeeds. -
Executed select count(*) from tcuentas
db is valid outputs true
db is open outputs truewhile consulta.next() outputs false...
Seems to be something with the query itself...
It is not mandatory to use Mac OSX by the way... for now I will use VirtualBox Windows 10 and continue developing there, this post was created just by curiosity.., if I find a solution in the meanwhile I will post here..
Thanks!
-