QPSQL: Unable to create query
-
wrote on 10 May 2020, 12:26 last edited by
Hi!
I I get error: QPSQL: "42601", "QPSQL: Unable to create query".
How do I fix this?void DataBase::openDB() { dataBase = QSqlDatabase::addDatabase("QPSQL"); dataBase.setDatabaseName("db_taxi_vik_park"); //ResumeDB.setDatabaseName("1"); dataBase.setUserName("postgres"); dataBase.setPassword("1qaz"); //ResumeDB.setHostName("127.0.0.1"); dataBase.setPort(5433);//*/ if (dataBase.open()) { qDebug()<<"db is opened \r\n";} else { qDebug()<<"db not opened \r\n";} } QVector<QMap<QString, QString> > DataBase::getAllAccauntWithoutPhoto() { QVector<QMap<QString, QString> > resultVector; QMap<QString, QString> valueMap; QSqlQuery query; query.prepare("SELECT " "id, " "name, " "email, " "login, " "password, " "date_create, " "date_block, " "id_key_device, " "number_of_downloaded_games, " "blocked_bool, " "comment " " FROM public.account " " ;"); if (!query.exec()) {qDebug()<<"not get data from db \r\n"<<query.lastError()<<"\r\n";} else { qDebug()<<"get data from db \r\n"; query.first(); valueMap["id"] = query.value(0).toString(); valueMap["name"] = query.value(1).toString(); valueMap["email"] = query.value(2).toString(); valueMap["login"] = query.value(3).toString(); valueMap["password"] = query.value(4).toString(); valueMap["date_create"] = query.value(5).toString(); valueMap["date_block"] = query.value(6).toString(); valueMap["id_key_device"] = query.value(7).toString(); valueMap["number_of_downloaded_games"] = query.value(8).toString(); valueMap["blocked_bool"] = query.value(9).toString(); valueMap["comment"] = query.value(10).toString(); resultVector.append(valueMap); while (query.next()) { valueMap["id"] = query.value(0).toString(); valueMap["name"] = query.value(1).toString(); valueMap["email"] = query.value(2).toString(); valueMap["login"] = query.value(3).toString(); valueMap["password"] = query.value(4).toString(); valueMap["date_create"] = query.value(5).toString(); valueMap["date_block"] = query.value(6).toString(); valueMap["id_key_device"] = query.value(7).toString(); valueMap["number_of_downloaded_games"] = query.value(8).toString(); valueMap["blocked_bool"] = query.value(9).toString(); valueMap["comment"] = query.value(10).toString(); resultVector.append(valueMap); } } return resultVector; }
-
Lifetime Qt Championwrote on 10 May 2020, 12:33 last edited by Christian Ehrlicher 5 Oct 2020, 12:33
By looking what this error means: https://www.postgresql.org/docs/10/errcodes-appendix.html
Try to run your query directly with psql to see where exactly the error is.
Also there is no need to use prepare() here since you don't bind any values. -
By looking what this error means: https://www.postgresql.org/docs/10/errcodes-appendix.html
Try to run your query directly with psql to see where exactly the error is.
Also there is no need to use prepare() here since you don't bind any values.wrote on 10 May 2020, 12:44 last edited by@Christian-Ehrlicher I tried making a query in psql and the query works.
I also tried to make this requestQSqlQuery query("select * from public.account"); QSqlError error = query.lastError(); if (error.type() == QSqlError::NoError) { while(query.next()) { qDebug() << query.value(0).toString(); } } else { qDebug() << error.text(); }
But I got the error of not having a table, whereas the table is exactly there.
-
The table is 'account', the schema public - try without schema
-
By looking what this error means: https://www.postgresql.org/docs/10/errcodes-appendix.html
Try to run your query directly with psql to see where exactly the error is.
Also there is no need to use prepare() here since you don't bind any values.wrote on 10 May 2020, 14:19 last edited by@Christian-Ehrlicher Can there be a problem with a bad driver?
-
The table is 'account', the schema public - try without schema
wrote on 10 May 2020, 15:01 last edited by@Christian-Ehrlicher it is too not work:
QSqlQuery query("SELECT * FROM account ", dataBase); if (!query.exec()) { qDebug()<<"not get data from db \r\n"<<query.lastError()<<"\r\n"; qDebug()<<query.lastQuery(); } else { qDebug()<<"get data from db \r\n"; query.first(); } return resultVector;
-
wrote on 10 May 2020, 15:04 last edited by
I use psql 12 in the windows 7 64
-
So where do you get the error? during query.exec()? And what error? The same as in the first post?
-
wrote on 10 May 2020, 16:57 last edited by
@Christian-Ehrlicher said in QPSQL: Unable to create query:
query.exec()
Yes, in query.exec(). The same error. Looks like it's the driver. How do I find out which version of the driver is designed for?
-
wrote on 10 May 2020, 17:19 last edited by
Do you connect PSQL to the project and it works normally?
-
@Mikeeeeee I'm using psql since ages with Qt. Imo it's a problem with your psql installation. Simply test it with a sqlite database. Also you should take a look what others did to solve the psql 42601 error but that's not Qt related
-
wrote on 10 May 2020, 17:35 last edited by
Before the update, I had PSQL working, after the update, new drivers were added and it stopped working.
-
Thenswitch back to the old PostgreSQL - or do you really need some new features in PostgreSQL 12 (btw: psql 12 is supported since Qt5.14 and works fine here)
-
wrote on 10 May 2020, 19:00 last edited by
Sorry, I'm in a connection indicated is not the base, my stupid mistake.
1/14