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::value: not positioned on a valid record
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery::value: not positioned on a valid record

Scheduled Pinned Locked Moved Solved General and Desktop
32 Posts 6 Posters 3.6k Views 1 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.
  • gfxxG gfxx

    on my Sqlite db can write:

    SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data)
    FROM getdata
    WHERE timeDayData BETWEEN date('now','-605 day') and date('now','-598 day')
    

    with valid result ... so in my mainwindovs void I try to call:

    QString dbTable = "getdata";
    QString data2 = "-605";
    QString data1 = "-598 ";
    
    QSqlQuery qryUser(QSqlDatabase::database("db"));
                            qryUser.exec("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM '"+dbTable+"' WHERE timeDayData BETWEEN date('now', ' '"+data2+"' day') and date('now', ' '"+data1+"' day')");
    while (qryUser.next()){
                               /* grab data code */
                            }
                            qryUser.finish();
                            qryUser.clear();
                            qDebug() << qryUser.lastError() ;
    

    but obtain only these error and no data:

    QSqlError("", "", "")    /* for => qDebug() << qryUser.lastError() ;*/
    QSqlQuery::value: not positioned on a valid record /* because some error */
    

    i write the query in wrong way? someone can suggest the right one?

    regards

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

    @gfxx
    Is your database open? QSqlQuery::exec() returns a value, test it. Or maybe there is no error, I cannot tell from what you have shown.

    gfxxG 3 Replies Last reply
    2
    • JonBJ JonB

      @gfxx
      Is your database open? QSqlQuery::exec() returns a value, test it. Or maybe there is no error, I cannot tell from what you have shown.

      gfxxG Offline
      gfxxG Offline
      gfxx
      wrote on last edited by
      #3

      @JonB for sure is open because i try other query reply is perfect ... problem was related to variable .... if write inside query a direct value in these way:

      qryUser.exec("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM  getdata WHERE timeDayData BETWEEN date('now', ' -620 day') and date('now', ' -590 day')");
      while (qryUser.next()){
      

      query work ...

      bkt

      B piervalliP 2 Replies Last reply
      0
      • JonBJ JonB

        @gfxx
        Is your database open? QSqlQuery::exec() returns a value, test it. Or maybe there is no error, I cannot tell from what you have shown.

        gfxxG Offline
        gfxxG Offline
        gfxx
        wrote on last edited by gfxx
        #4

        @JonB said in QSqlQuery::value: not positioned on a valid record:

        @gfxx
        Is your database open? QSqlQuery::exec() returns a value, test it. Or maybe there is no error, I cannot tell from what you have shown.

        update ... previous code not work ..... these one yes .... note no spaces before - (minus) ...

        qryUser.exec("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM  getdata WHERE timeDayData BETWEEN date('now', '-620 day') and date('now', '-590 day')");
        while (qryUser.next()){
        

        bkt

        Christian EhrlicherC 1 Reply Last reply
        0
        • gfxxG gfxx

          @JonB said in QSqlQuery::value: not positioned on a valid record:

          @gfxx
          Is your database open? QSqlQuery::exec() returns a value, test it. Or maybe there is no error, I cannot tell from what you have shown.

          update ... previous code not work ..... these one yes .... note no spaces before - (minus) ...

          qryUser.exec("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM  getdata WHERE timeDayData BETWEEN date('now', '-620 day') and date('now', '-590 day')");
          while (qryUser.next()){
          
          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @gfxx As @JonB already told you - QSqlQuery::exec() returns a bool which you should check...

          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
          • JonBJ JonB

            @gfxx
            Is your database open? QSqlQuery::exec() returns a value, test it. Or maybe there is no error, I cannot tell from what you have shown.

            gfxxG Offline
            gfxxG Offline
            gfxx
            wrote on last edited by
            #6

            @JonB any original code without spaces give me the same result ....no error but

            QSqlQuery::value: not positioned on a valid record 
            

            not undestand ...

            bkt

            jsulmJ 1 Reply Last reply
            0
            • gfxxG gfxx

              @JonB any original code without spaces give me the same result ....no error but

              QSqlQuery::value: not positioned on a valid record 
              

              not undestand ...

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @gfxx How about following what others suggested?
              For the third time: check what QSqlQuery::exec() returns and if it fails check what https://doc.qt.io/qt-6/qsqlquery.html#lastError and https://doc.qt.io/qt-6/qsqlquery.html#executedQuery return...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • gfxxG gfxx

                @JonB for sure is open because i try other query reply is perfect ... problem was related to variable .... if write inside query a direct value in these way:

                qryUser.exec("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM  getdata WHERE timeDayData BETWEEN date('now', ' -620 day') and date('now', ' -590 day')");
                while (qryUser.next()){
                

                query work ...

                B Offline
                B Offline
                Bonnie
                wrote on last edited by
                #8

                @gfxx
                date('now', ' '"+data2+"' day') -> date('now', ' '-605' day')
                date('now', ' '"+data1+"' day') -> date('now', ' '-598' day')
                I don't think the above is right because you have extra single quotes in the string.
                As others already have told you, your exec() probably fails, so there's no "valid record".

                1 Reply Last reply
                0
                • gfxxG gfxx

                  @JonB for sure is open because i try other query reply is perfect ... problem was related to variable .... if write inside query a direct value in these way:

                  qryUser.exec("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM  getdata WHERE timeDayData BETWEEN date('now', ' -620 day') and date('now', ' -590 day')");
                  while (qryUser.next()){
                  

                  query work ...

                  piervalliP Offline
                  piervalliP Offline
                  piervalli
                  wrote on last edited by
                  #9

                  @gfxx
                  I usually for best practice print in console every error with query, so you can check quickly.

                  try this :
                  if(!qryUser.exec("SELECT SUM(1Data) ...") qDebug() << qryUser.lastQuery() << qryUser.lastError()
                  
                  gfxxG 2 Replies Last reply
                  0
                  • piervalliP piervalli

                    @gfxx
                    I usually for best practice print in console every error with query, so you can check quickly.

                    try this :
                    if(!qryUser.exec("SELECT SUM(1Data) ...") qDebug() << qryUser.lastQuery() << qryUser.lastError()
                    
                    gfxxG Offline
                    gfxxG Offline
                    gfxx
                    wrote on last edited by
                    #10

                    @piervalli said in QSqlQuery::value: not positioned on a valid record:

                    qDebug() << qryUser.lastQuery() << qryUser.lastError()

                    I try but I have no debug messages .. think because query is working .... think these messages ...

                    QSqlError("", "", "")    /* for => qDebug() << qryUser.lastError() ;*/
                    QSqlQuery::value: not positioned on a valid record /* because some error */
                    

                    related to debug of my query show a right query but some "invalid record" .... so think sqlite driver not working in right manner the query ... most probabily because variable is not write in right manner ....

                    bkt

                    1 Reply Last reply
                    0
                    • piervalliP piervalli

                      @gfxx
                      I usually for best practice print in console every error with query, so you can check quickly.

                      try this :
                      if(!qryUser.exec("SELECT SUM(1Data) ...") qDebug() << qryUser.lastQuery() << qryUser.lastError()
                      
                      gfxxG Offline
                      gfxxG Offline
                      gfxx
                      wrote on last edited by
                      #11

                      @piervalli finally with your suggest I see what happens .... but not try solution ... for now try to compose a string for a statement like:

                      data2 = "date('now', '" + QString::number(dtNow1) + " day')";
                      data1 = "date('now', '" + QString::number(dy1) + " day')";
                      

                      so final part of query become: ...WHERE timeDayData BETWEEN '"+data2+"' and '"+data1+"'");

                      At these point I obtain the resulted request .. that is not right because extra " ' " characters .....

                      /* lastQuery result*/  "SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM 'getdata' WHERE timeDayData BETWEEN 'date('now', '-11 day')' and 'date('now', '-12 day')'" QSqlError("1", "Unable to execute statement", "near \"now\": syntax error")
                      

                      how can leave extra " ' " out? because if write '"+date2+"' obtain a reply ... if write "+date2" obtain nothing nor desired result not lastquery macro result ...

                      bkt

                      piervalliP 1 Reply Last reply
                      0
                      • gfxxG gfxx

                        @piervalli finally with your suggest I see what happens .... but not try solution ... for now try to compose a string for a statement like:

                        data2 = "date('now', '" + QString::number(dtNow1) + " day')";
                        data1 = "date('now', '" + QString::number(dy1) + " day')";
                        

                        so final part of query become: ...WHERE timeDayData BETWEEN '"+data2+"' and '"+data1+"'");

                        At these point I obtain the resulted request .. that is not right because extra " ' " characters .....

                        /* lastQuery result*/  "SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM 'getdata' WHERE timeDayData BETWEEN 'date('now', '-11 day')' and 'date('now', '-12 day')'" QSqlError("1", "Unable to execute statement", "near \"now\": syntax error")
                        

                        how can leave extra " ' " out? because if write '"+date2+"' obtain a reply ... if write "+date2" obtain nothing nor desired result not lastquery macro result ...

                        piervalliP Offline
                        piervalliP Offline
                        piervalli
                        wrote on last edited by piervalli
                        #12

                        @gfxx said in QSqlQuery::value: not positioned on a valid record:

                        SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM 'getdata' WHERE timeDayData BETWEEN 'date('now', '-11 day')' and 'date('now', '-12 day')

                        const auto q = QStringLiteral("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM getdata WHERE timeDayData BETWEEN date('now','-%1 day') and date('now','-%2 day')").arg(dtNow1).arg(dy1);

                        So, You can use placeholder, you have extra ' i the query

                        gfxxG 2 Replies Last reply
                        0
                        • piervalliP piervalli

                          @gfxx said in QSqlQuery::value: not positioned on a valid record:

                          SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM 'getdata' WHERE timeDayData BETWEEN 'date('now', '-11 day')' and 'date('now', '-12 day')

                          const auto q = QStringLiteral("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM getdata WHERE timeDayData BETWEEN date('now','-%1 day') and date('now','-%2 day')").arg(dtNow1).arg(dy1);

                          So, You can use placeholder, you have extra ' i the query

                          gfxxG Offline
                          gfxxG Offline
                          gfxx
                          wrote on last edited by
                          #13

                          @piervalli said in QSqlQuery::value: not positioned on a valid record:

                          const auto q = QStringLiteral("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM getdata WHERE timeDayData BETWEEN date('now','-%1 day') and date('now','-%2 day')").arg(dtNow1).arg(dy1);

                          const auto q1 = QStringLiteral("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM %1 WHERE timeDayData BETWEEN date('now','-%2 day') and date('now','-%3 day')").arg(myQStringTableName).arg(dtNow1).arg(dy1);

                          is right in your opinion?

                          bkt

                          1 Reply Last reply
                          0
                          • piervalliP piervalli

                            @gfxx said in QSqlQuery::value: not positioned on a valid record:

                            SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM 'getdata' WHERE timeDayData BETWEEN 'date('now', '-11 day')' and 'date('now', '-12 day')

                            const auto q = QStringLiteral("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM getdata WHERE timeDayData BETWEEN date('now','-%1 day') and date('now','-%2 day')").arg(dtNow1).arg(dy1);

                            So, You can use placeholder, you have extra ' i the query

                            gfxxG Offline
                            gfxxG Offline
                            gfxx
                            wrote on last edited by
                            #14

                            @piervalli said in QSqlQuery::value: not positioned on a valid record:

                            const auto q = QStringLiteral("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM getdata WHERE timeDayData BETWEEN date('now','-%1 day') and date('now','-%2 day')").arg(dtNow1).arg(dy1);

                            unfortunately these not show result ....

                            bkt

                            jsulmJ 1 Reply Last reply
                            0
                            • gfxxG gfxx

                              @piervalli said in QSqlQuery::value: not positioned on a valid record:

                              const auto q = QStringLiteral("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM getdata WHERE timeDayData BETWEEN date('now','-%1 day') and date('now','-%2 day')").arg(dtNow1).arg(dy1);

                              unfortunately these not show result ....

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              @gfxx Unfortunatelly you do not show the output qryUser.lastQuery() and qryUser.lastError() after executing the query.
                              And you should use https://doc.qt.io/qt-6/qsqlquery.html#prepare instead of doing string substitution.

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              gfxxG 1 Reply Last reply
                              2
                              • jsulmJ jsulm

                                @gfxx Unfortunatelly you do not show the output qryUser.lastQuery() and qryUser.lastError() after executing the query.
                                And you should use https://doc.qt.io/qt-6/qsqlquery.html#prepare instead of doing string substitution.

                                gfxxG Offline
                                gfxxG Offline
                                gfxx
                                wrote on last edited by
                                #16

                                @jsulm these is not right ....

                                SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM 'getdata' WHERE timeDayData BETWEEN 'date('now', '-11 day')' and 'date('now', '-12 day')
                                

                                these is one of lastquery .... as I write problem is extra " ' " in every manner I write the query exec .... so think these is completely qt side problem .... and for these query using query prepare ... not try .... but have some doubt about ....

                                bkt

                                Christian EhrlicherC gfxxG 2 Replies Last reply
                                0
                                • gfxxG gfxx

                                  @jsulm these is not right ....

                                  SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM 'getdata' WHERE timeDayData BETWEEN 'date('now', '-11 day')' and 'date('now', '-12 day')
                                  

                                  these is one of lastquery .... as I write problem is extra " ' " in every manner I write the query exec .... so think these is completely qt side problem .... and for these query using query prepare ... not try .... but have some doubt about ....

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

                                  @gfxx said in QSqlQuery::value: not positioned on a valid record:

                                  so think these is completely qt side problem ..

                                  Since the query is passed to sqlite the way you write it - no.

                                  Please provide a minimal, compilable example of your problem, including the table creation etc if you want to prove me wrong.

                                  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
                                  0
                                  • gfxxG gfxx

                                    @jsulm these is not right ....

                                    SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM 'getdata' WHERE timeDayData BETWEEN 'date('now', '-11 day')' and 'date('now', '-12 day')
                                    

                                    these is one of lastquery .... as I write problem is extra " ' " in every manner I write the query exec .... so think these is completely qt side problem .... and for these query using query prepare ... not try .... but have some doubt about ....

                                    gfxxG Offline
                                    gfxxG Offline
                                    gfxx
                                    wrote on last edited by
                                    #18

                                    @gfxx so try in qt way .... but not sure these query can write in that manner ....

                                    QSqlQuery qryUser(QSqlDatabase::database("db"));
                                                            qryUser.prepare("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM :dbTable WHERE timeDayData BETWEEN date('now', ':date2 day') and date('now', ':date1 day')");
                                                            qryUser.bindValue(":dbTable", dbTable);
                                                            qryUser.bindValue(":data2", data2);
                                                            qryUser.bindValue(":data1", data1);
                                                            qryUser.exec();
                                    

                                    last query return these ....

                                    try to not work.... "SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM :dbTable WHERE timeDayData BETWEEN date('now', ':date2 day') and date('now', ':date1 day')" QSqlError("", "Parameter count mismatch", "")
                                    

                                    is simple if possible write query in these manner ...

                                    qryPausa.prepare("INSERT INTO getdata (timeDayData, 1Data, 2Data, pausaData,3Data, 4Data, 5data) VALUES (:timeDayData, :aData, :bData, :pausaData, :cData, :dData, :eData)");
                                            qryPausa.bindValue(":timeDayData", timestamp);
                                    

                                    in these way work .... but not sure is possible insert VALUES request in my SELECT query ...... because need " ' " ..... if somone can suggest a way to write that query using queryprepare ..... is perfect fo me .....

                                    bkt

                                    Christian EhrlicherC 1 Reply Last reply
                                    0
                                    • gfxxG gfxx

                                      @gfxx so try in qt way .... but not sure these query can write in that manner ....

                                      QSqlQuery qryUser(QSqlDatabase::database("db"));
                                                              qryUser.prepare("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM :dbTable WHERE timeDayData BETWEEN date('now', ':date2 day') and date('now', ':date1 day')");
                                                              qryUser.bindValue(":dbTable", dbTable);
                                                              qryUser.bindValue(":data2", data2);
                                                              qryUser.bindValue(":data1", data1);
                                                              qryUser.exec();
                                      

                                      last query return these ....

                                      try to not work.... "SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM :dbTable WHERE timeDayData BETWEEN date('now', ':date2 day') and date('now', ':date1 day')" QSqlError("", "Parameter count mismatch", "")
                                      

                                      is simple if possible write query in these manner ...

                                      qryPausa.prepare("INSERT INTO getdata (timeDayData, 1Data, 2Data, pausaData,3Data, 4Data, 5data) VALUES (:timeDayData, :aData, :bData, :pausaData, :cData, :dData, :eData)");
                                              qryPausa.bindValue(":timeDayData", timestamp);
                                      

                                      in these way work .... but not sure is possible insert VALUES request in my SELECT query ...... because need " ' " ..... if somone can suggest a way to write that query using queryprepare ..... is perfect fo me .....

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

                                      @gfxx said in QSqlQuery::value: not positioned on a valid record:

                                      qryUser.prepare("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM :dbTable WHERE timeDayData BETWEEN date('now', ':date2 day') and date('now', ':date1 day')");
                                      qryUser.bindValue(":dbTable", dbTable);
                                      qryUser.bindValue(":data2", data2);
                                      qryUser.bindValue(":data1", data1);

                                      You should at least try to post correct snippets when you're not able to create a minimal, compilable example... date != data, no checking of QSqlQuery::prepare() return value, ...

                                      No more comments from me in this post here.

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

                                      gfxxG 1 Reply Last reply
                                      2
                                      • Christian EhrlicherC Christian Ehrlicher

                                        @gfxx said in QSqlQuery::value: not positioned on a valid record:

                                        qryUser.prepare("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM :dbTable WHERE timeDayData BETWEEN date('now', ':date2 day') and date('now', ':date1 day')");
                                        qryUser.bindValue(":dbTable", dbTable);
                                        qryUser.bindValue(":data2", data2);
                                        qryUser.bindValue(":data1", data1);

                                        You should at least try to post correct snippets when you're not able to create a minimal, compilable example... date != data, no checking of QSqlQuery::prepare() return value, ...

                                        No more comments from me in this post here.

                                        gfxxG Offline
                                        gfxxG Offline
                                        gfxx
                                        wrote on last edited by
                                        #20

                                        @Christian-Ehrlicher i understand your point of view ... but really is only trascription error not real error .... now try in other manner .... wit same result .. about simple example ..... need to create a simple table with 50 item with these sqlstatement ....

                                        CREATE TABLE "getdata" (
                                        	"Field1"	INTEGER PRIMARY KEY AUTOINCREMENT,
                                        	"1Data"	TEXT,
                                        	"2Data"	TEXT,
                                                "date"            TEXT
                                        );
                                        

                                        than tray select on sqlite3

                                        SELECT SUM(1Data), SUM(2Data),
                                        FROM getdata
                                        WHERE timeDayData BETWEEN date('now','-50 day') and date('now','-60 day')
                                        

                                        than try the same on qt mainwindows .... result is mine .... data2 and data1 need to be integer value ..... request is sort "date" from NOW to xxxx value AND from NOW to xxxxMoreLittle ..... xxx and xxxMoreLittle is the var with problem because inside 'xxx day' and 'xxxMoreLittle day' macro .....

                                        Any how write again in other way .....

                                        QSqlQuery qryUser1(QSqlDatabase::database("db"));
                                                            qryUser1.prepare("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM dbTable= :dbTable1 WHERE timeDayData BETWEEN date('now', 'data2= :data21 day') and date('now', 'data1= :data11 day')");
                                                            qryUser1.bindValue(":dbTable1", dbTable);
                                                            qryUser1.bindValue(":data21", data2);
                                                            qryUser1.bindValue(":data11", data1);
                                                            if(!qryUser1.exec()){
                                                                qDebug() << "try to not work...." << qryUser1.lastQuery() << qryUser1.lastError();
                                                                qryUser1.finish();
                                                                qryUser1.clear();
                                                            }
                                        

                                        ... see lastquery result ...

                                        try to not work.... "SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM dbTable= :dbTable1 WHERE timeDayData BETWEEN date('now', 'data2= :data21 day') and date('now', 'data1= :data11 day')" QSqlError("", "Parameter count mismatch", "")
                                        

                                        bkt

                                        jsulmJ JonBJ 2 Replies Last reply
                                        0
                                        • gfxxG gfxx

                                          @Christian-Ehrlicher i understand your point of view ... but really is only trascription error not real error .... now try in other manner .... wit same result .. about simple example ..... need to create a simple table with 50 item with these sqlstatement ....

                                          CREATE TABLE "getdata" (
                                          	"Field1"	INTEGER PRIMARY KEY AUTOINCREMENT,
                                          	"1Data"	TEXT,
                                          	"2Data"	TEXT,
                                                  "date"            TEXT
                                          );
                                          

                                          than tray select on sqlite3

                                          SELECT SUM(1Data), SUM(2Data),
                                          FROM getdata
                                          WHERE timeDayData BETWEEN date('now','-50 day') and date('now','-60 day')
                                          

                                          than try the same on qt mainwindows .... result is mine .... data2 and data1 need to be integer value ..... request is sort "date" from NOW to xxxx value AND from NOW to xxxxMoreLittle ..... xxx and xxxMoreLittle is the var with problem because inside 'xxx day' and 'xxxMoreLittle day' macro .....

                                          Any how write again in other way .....

                                          QSqlQuery qryUser1(QSqlDatabase::database("db"));
                                                              qryUser1.prepare("SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM dbTable= :dbTable1 WHERE timeDayData BETWEEN date('now', 'data2= :data21 day') and date('now', 'data1= :data11 day')");
                                                              qryUser1.bindValue(":dbTable1", dbTable);
                                                              qryUser1.bindValue(":data21", data2);
                                                              qryUser1.bindValue(":data11", data1);
                                                              if(!qryUser1.exec()){
                                                                  qDebug() << "try to not work...." << qryUser1.lastQuery() << qryUser1.lastError();
                                                                  qryUser1.finish();
                                                                  qryUser1.clear();
                                                              }
                                          

                                          ... see lastquery result ...

                                          try to not work.... "SELECT SUM(1Data), SUM(2Data), SUM(3Data), SUM(4Data), SUM(5Data) FROM dbTable= :dbTable1 WHERE timeDayData BETWEEN date('now', 'data2= :data21 day') and date('now', 'data1= :data11 day')" QSqlError("", "Parameter count mismatch", "")
                                          
                                          jsulmJ Offline
                                          jsulmJ Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #21

                                          @gfxx said in QSqlQuery::value: not positioned on a valid record:

                                          FROM dbTable= :dbTable1

                                          What is this?
                                          It should be

                                          FROM :dbTable1
                                          

                                          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