Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPSQL: unable to create query
Forum Updated to NodeBB v4.3 + New Features

QPSQL: unable to create query

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • houssQtH Offline
    houssQtH Offline
    houssQt
    wrote on last edited by
    #1

    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 as

    SELECT * 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.

    1 Reply Last reply
    0
    • houssQtH Offline
      houssQtH Offline
      houssQt
      wrote on last edited by
      #2

      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 ??.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved