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. Column 1 out of range although datas aren't missing and data are showing properly

Column 1 out of range although datas aren't missing and data are showing properly

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 1.0k Views
  • 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.
  • Thank YouT Offline
    Thank YouT Offline
    Thank You
    wrote on last edited by Thank You
    #1

    Hey guys,
    I am having some problem while using query to fetch data.
    This is the exact same code

       QString 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 using isValid() and I got the same thing. What could have caused it??

    Let's make QT free or It will go forever

    TRUE AND FALSE <3

    artwawA 1 Reply Last reply
    0
    • Thank YouT Thank You

      Hey guys,
      I am having some problem while using query to fetch data.
      This is the exact same code

         QString 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 using isValid() and I got the same thing. What could have caused it??

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

      @Thank-You How does it compare then you run the query directly on the db server? How many rows do you get back?

      For more information please re-read.

      Kind Regards,
      Artur

      Thank YouT 1 Reply Last reply
      0
      • artwawA artwaw

        @Thank-You How does it compare then you run the query directly on the db server? How many rows do you get back?

        Thank YouT Offline
        Thank YouT Offline
        Thank You
        wrote on last edited by
        #3

        @artwaw
        It gives me the exact data present in output. They have same data and same no. of rows.

        Thank You

        Let's make QT free or It will go forever

        TRUE AND FALSE <3

        artwawA 1 Reply Last reply
        0
        • Thank YouT Thank You

          @artwaw
          It gives me the exact data present in output. They have same data and same no. of rows.

          Thank You

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

          @Thank-You Can you include in qDebug() query.size()? Also examining result() comes to mind.
          It is absolutely odd.

          For more information please re-read.

          Kind Regards,
          Artur

          Thank YouT 1 Reply Last reply
          0
          • artwawA artwaw

            @Thank-You Can you include in qDebug() query.size()? Also examining result() comes to mind.
            It is absolutely odd.

            Thank YouT Offline
            Thank YouT Offline
            Thank You
            wrote on last edited by
            #5

            @artwaw

            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

            Let's make QT free or It will go forever

            TRUE AND FALSE <3

            artwawA 1 Reply Last reply
            0
            • Thank YouT Thank You

              @artwaw

              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

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

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

              For more information please re-read.

              Kind Regards,
              Artur

              Thank YouT 1 Reply Last reply
              1
              • artwawA artwaw

                @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 YouT Offline
                Thank YouT Offline
                Thank You
                wrote on last edited by
                #7

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

                Let's make QT free or It will go forever

                TRUE AND FALSE <3

                artwawA JonBJ 2 Replies Last reply
                0
                • Thank YouT Thank You

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

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

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

                  For more information please re-read.

                  Kind Regards,
                  Artur

                  1 Reply Last reply
                  1
                  • Thank YouT Thank You

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

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

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

                    Try different version of Qt and/or mysql driver?

                    Thank YouT 2 Replies Last reply
                    1
                    • JonBJ JonB

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

                      Try different version of Qt and/or mysql driver?

                      Thank YouT Offline
                      Thank YouT Offline
                      Thank You
                      wrote on last edited by
                      #10

                      @JonB
                      Then I think I shouldn't take much stress in this. If codes become compatible with newer version of QT I will go with it. For now I will go with this. I have not tried QT 5.15.2 @artwaw Are the codes of QT 5.12.8 compatible with that version ?

                      Let's make QT free or It will go forever

                      TRUE AND FALSE <3

                      artwawA 1 Reply Last reply
                      0
                      • Thank YouT Thank You

                        @JonB
                        Then I think I shouldn't take much stress in this. If codes become compatible with newer version of QT I will go with it. For now I will go with this. I have not tried QT 5.15.2 @artwaw Are the codes of QT 5.12.8 compatible with that version ?

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

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

                        For more information please re-read.

                        Kind Regards,
                        Artur

                        1 Reply Last reply
                        0
                        • JonBJ JonB

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

                          Try different version of Qt and/or mysql driver?

                          Thank YouT Offline
                          Thank YouT Offline
                          Thank You
                          wrote on last edited by
                          #12

                          @JonB Although it is kinda late but l am currently using QT 5.15.2. But also getting same result. I used the drivers from https://github.com/thecodemonkey86/qt_mysql_driver/releases
                          I don't know any other drivers for this

                          Let's make QT free or It will go forever

                          TRUE AND FALSE <3

                          1 Reply Last reply
                          0

                          • Login

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