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. QSqlQuery::next () returns false on OSX..
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery::next () returns false on OSX..

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 6 Posters 743 Views 3 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.
  • U Offline
    U Offline
    U7Development
    wrote on last edited by
    #1

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

    JonBJ 1 Reply Last reply
    0
    • U U7Development

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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @U7Development
      Are you 100,000% sure the database you're using on Mac really does have any rows in that table? :) Can you run select count(*) from tcuentas;?

      U 1 Reply Last reply
      3
      • JonBJ JonB

        @U7Development
        Are you 100,000% sure the database you're using on Mac really does have any rows in that table? :) Can you run select count(*) from tcuentas;?

        U Offline
        U Offline
        U7Development
        wrote on last edited by
        #3

        @JonB Thanks for answering...

        Yes!.. 101% sure, on Windows & Linux all tables are downloaded into vectors.. on OSX detects no rows... but DB is connected successfully... that's weird..

        Christian EhrlicherC 1 Reply Last reply
        0
        • U U7Development

          @JonB Thanks for answering...

          Yes!.. 101% sure, on Windows & Linux all tables are downloaded into vectors.. on OSX detects no rows... but DB is connected successfully... that's weird..

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @U7Development You did not answer @JonB 's question. Please open your db with a sql browser and see if there is data in it.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          U 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @U7Development You did not answer @JonB 's question. Please open your db with a sql browser and see if there is data in it.

            U Offline
            U Offline
            U7Development
            wrote on last edited by U7Development
            #5

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

            alt text

            JonBJ 1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Did you do what @JonB suggests with select count(*)? Did you try to insert data into the table just to see if it works?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • U U7Development

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

                alt text

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

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

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

                  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.

                  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
                  2
                  • U Offline
                    U Offline
                    U7Development
                    wrote on last edited by
                    #9

                    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.

                    artwawA 1 Reply Last reply
                    0
                    • U U7Development

                      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.

                      artwawA Offline
                      artwawA Offline
                      artwaw
                      wrote on last edited by
                      #10

                      @U7Development Out of curiosity - if you use MariaDB why bother with ODBC if you can use MysqlConnector directly?

                      For more information please re-read.

                      Kind Regards,
                      Artur

                      JonBJ U 2 Replies Last reply
                      2
                      • artwawA artwaw

                        @U7Development Out of curiosity - if you use MariaDB why bother with ODBC if you can use MysqlConnector directly?

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #11

                        @artwaw
                        Can one use the Qt MYSQL connector thingie with MariaDB?

                        artwawA 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @artwaw
                          Can one use the Qt MYSQL connector thingie with MariaDB?

                          artwawA Offline
                          artwawA Offline
                          artwaw
                          wrote on last edited by
                          #12

                          @JonB I think so. I did so under Windows some 2 years ago, db was vanilla MariaDB running on Debian over local network. All I needed was to provide proper dll from Mysql client connector (oracle client connector package).

                          For more information please re-read.

                          Kind Regards,
                          Artur

                          1 Reply Last reply
                          1
                          • artwawA artwaw

                            @U7Development Out of curiosity - if you use MariaDB why bother with ODBC if you can use MysqlConnector directly?

                            U Offline
                            U Offline
                            U7Development
                            wrote on last edited by
                            #13

                            @artwaw I got compiling problems ... and could not find binary package ... :(

                            1 Reply Last reply
                            0
                            • U Offline
                              U Offline
                              U7Development
                              wrote on last edited by U7Development
                              #14

                              Tests done:

                              1. Pushing a row into tcuentas:

                                db is valid outputs true
                                db is open outputs true

                                if consulta.exec(). outputs true..
                                finally checked into tcuentas and the row exists, so the test succeeds.

                              2. Executed select count(*) from tcuentas

                                db is valid outputs true
                                db is open outputs true

                                while 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!

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mchinand
                                wrote on last edited by mchinand
                                #15

                                What is the result if you run that query on your Mac using another MariaDB client?

                                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