Solved QPSQL: unable to create query
-
Hi everyone,
I am trying to develop a desktop application that uses a postgresql database. i successfully connect to the server (postgresql 9.5) as the root "postgres", but when i try to execute a simple query asSELECT * FROM information_schema.tables;
I get an error that say
QPSQL: unable to create query ERROR: syntax error at the end of input LINE1: EXECUTE
I stay ready to give any information that you will need.
-
Hi again i guess i found the error in my code, first i had this
if(m_db.isOpen()) { QSqlQuery q(query,m_db); if(q.exec){ // do somthing } else { executionError(q.lastError().driverText()+"\n"+ q.lastError().databaseText()+"\n"+ q.lastError().nativeErrorCode()); }
the code above gave me the error, but when i use the QSqlDatabase object to directly exec the query it works just fine;
if(m_db.isOpen()) { auto q = m_db.exec(query); if(q.isActive()){ // do something } else { executionError(q.lastError().driverText()+"\n"+ q.lastError().databaseText()+"\n"+ q.lastError().nativeErrorCode()); }
i can't explain why, can anyone please explain why this behaviour ??.
-
Hi and welcome to devnet,
It's all explained in the QSqlQuery constructor documentation.
If you pass a valid string, the query will be executed directly. So what is happening is that you are trying to run the query twice.