Column 1 out of range although datas aren't missing and data are showing properly
-
Hey guys,
I am having some problem while using query to fetch data.
This is the exact same codeQString command = "select name from details;"; { QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setDatabaseName("name"); db.setPort(3306); db.setHostName("localhost"); db.setUserName("don"); db.setPassword("nothing"); if(db.open()){ QSqlQuery query(db); if(query.exec(command)){ while (query.next()) { QString name= query.value(0).toString(); qDebug()<<query.value(0); } }else{ // keep err here } }else{ // keep err here } } QSqlDatabase::removeDatabase("qt_sql_default_connection"); // removing database
This is output of qDebug()
QVariant(QString, "First name") QMYSQLResult::data: column 1 out of range QVariant(QString, "second name") QVariant(QString, "third name") QVariant(QString, "fourth") QVariant(QString, "fifth") QVariant(QString, "sixth") QVariant(QString, "seventh") QVariant(QString, "eighth") QVariant(QString, "ninth") QMYSQLResult::data: column 1 out of range
And mysql table is same as the output and the data are in the same format.
There is nothing between the data. There are 3 columns in table and it is the first column.
What may be the problem with it. I have read some articles about it.
I tried usingisValid()
and I got the same thing. What could have caused it??@Thank-You How does it compare then you run the query directly on the db server? How many rows do you get back?
-
@Thank-You How does it compare then you run the query directly on the db server? How many rows do you get back?
-
@artwaw
It gives me the exact data present in output. They have same data and same no. of rows.Thank You
@Thank-You Can you include in qDebug() query.size()? Also examining result() comes to mind.
It is absolutely odd. -
@Thank-You Can you include in qDebug() query.size()? Also examining result() comes to mind.
It is absolutely odd. -
Can you include in qDebug() query.size()?
It gives me
9
Also examining result() comes to mind.
Sorry I am not aware of this thing. I tried reading docs but I am not getting this thing. 😂😂 LOL
@Thank-You Which Qt version do you use and what sort of MySql db runs as your db server? I'll try to reproduce this behaviour.
-
@Thank-You Which Qt version do you use and what sort of MySql db runs as your db server? I'll try to reproduce this behaviour.
-
@artwaw
I should have included it at first
QT 5.12.8 and mysql
Server version: 10.4.18-MariaDB - binary distribution
Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.0.3
Database client version: libmysql - mysqlnd 8.0.3
Are these sufficient ?@Thank-You As long as you use MinGW I should be fine;) I'll get back to you once I download and install this ancient version of Qt (you should update it to 5.15.2 and see if that helps by the way).
-
@artwaw
I should have included it at first
QT 5.12.8 and mysql
Server version: 10.4.18-MariaDB - binary distribution
Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.0.3
Database client version: libmysql - mysqlnd 8.0.3
Are these sufficient ?@Thank-You
There is clearly a problem in this area out there, i.e. you are not alone. (There is nothing wrong with your code.) See Qt, MySQL: QMYSQLResult::data: column 1 out of range that only happens sometimesTry different version of Qt and/or mysql driver?
-
@Thank-You
There is clearly a problem in this area out there, i.e. you are not alone. (There is nothing wrong with your code.) See Qt, MySQL: QMYSQLResult::data: column 1 out of range that only happens sometimesTry different version of Qt and/or mysql driver?
-
@Thank-You Mostly yes. A few minor changes in QString (parameters for split() moved from QString:: to Qt::) that I noticed.
I also tested this with current stable MariaDB on Debian, no issued for over a 100 selects in the row. -
@Thank-You
There is clearly a problem in this area out there, i.e. you are not alone. (There is nothing wrong with your code.) See Qt, MySQL: QMYSQLResult::data: column 1 out of range that only happens sometimesTry different version of Qt and/or mysql driver?