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. DB search results are normal, but Qt displays an error. I'd like to know the solution.
Forum Updated to NodeBB v4.3 + New Features

DB search results are normal, but Qt displays an error. I'd like to know the solution.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 255 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.
  • M Offline
    M Offline
    meria0503
    wrote on last edited by
    #1

    Hello, I'm a beginner who just learned qt and c++. We are experiencing many difficulties while developing the program, but we are solving it through search. But there's another problem.

    Oracle DB runs sql normally

    The qt causes an error whether it is out of format. Help me.

        QString sqlQuery = QString("select year,month,day,hour,minute,sv FROM hmidata WHERE time BETWEEN TO_DATE('2022-06-17 00:00:00', 'YYYY-MM-DD HH24:MI:SS ') AND TO_DATE('2022-06-17 23:59:59', 'YYYY-MM-DD HH24:MI:SS ') ORDER BY time ASC");
        if(query.exec(sqlQuery)){
            while(query.next()) {
                 xValue.setDate(QDate(query.value(0).toInt(),query.value(1).toInt(),query.value(2).toInt()));
                 xValue.setTime(QTime(query.value(3).toInt(),query.value(4).toInt()));
    
                qreal yValue = query.value(5).toDouble();
    
                series->append(xValue.toMSecsSinceEpoch(),yValue);
    
                qDebug() << xValue << yValue<<QDateTime::currentDateTime().toString("yyyy년 MM월 dd일 hh시:mm분:ss초:zzz");;
            }
        }
    
        else {
            qDebug() << query.lastError();
    
        }
    

    QDateTimeAxis *xAxis = new QDateTimeAxis;
    xAxis->setTickCount(5);
    m_chart->addAxis(xAxis, Qt::AlignBottom);
    xAxis->setFormat("yyyy-MM-dd hh:mm:ss");
    This is the code content in qt.

    This is an error in the debug.

    QSqlQuery::value: not positioned on a valid record
    QSqlError("1861", "Unable to execute statement", "ORA-01861: literal does not match format string\n")

    화면 캡처 2022-06-17 175934.png

    화면 캡처 2022-06-17 175922.png You can see that sql statements are executed well.

    I'm sorry that the sentence is not smooth using a translator.

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

      @meria0503 said in DB search results are normal, but Qt displays an error. I'd like to know the solution.:

      'YYYY-MM-DD HH24:MI:SS '

      I would try to remove the last space.

      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
      • M meria0503

        Hello, I'm a beginner who just learned qt and c++. We are experiencing many difficulties while developing the program, but we are solving it through search. But there's another problem.

        Oracle DB runs sql normally

        The qt causes an error whether it is out of format. Help me.

            QString sqlQuery = QString("select year,month,day,hour,minute,sv FROM hmidata WHERE time BETWEEN TO_DATE('2022-06-17 00:00:00', 'YYYY-MM-DD HH24:MI:SS ') AND TO_DATE('2022-06-17 23:59:59', 'YYYY-MM-DD HH24:MI:SS ') ORDER BY time ASC");
            if(query.exec(sqlQuery)){
                while(query.next()) {
                     xValue.setDate(QDate(query.value(0).toInt(),query.value(1).toInt(),query.value(2).toInt()));
                     xValue.setTime(QTime(query.value(3).toInt(),query.value(4).toInt()));
        
                    qreal yValue = query.value(5).toDouble();
        
                    series->append(xValue.toMSecsSinceEpoch(),yValue);
        
                    qDebug() << xValue << yValue<<QDateTime::currentDateTime().toString("yyyy년 MM월 dd일 hh시:mm분:ss초:zzz");;
                }
            }
        
            else {
                qDebug() << query.lastError();
        
            }
        

        QDateTimeAxis *xAxis = new QDateTimeAxis;
        xAxis->setTickCount(5);
        m_chart->addAxis(xAxis, Qt::AlignBottom);
        xAxis->setFormat("yyyy-MM-dd hh:mm:ss");
        This is the code content in qt.

        This is an error in the debug.

        QSqlQuery::value: not positioned on a valid record
        QSqlError("1861", "Unable to execute statement", "ORA-01861: literal does not match format string\n")

        화면 캡처 2022-06-17 175934.png

        화면 캡처 2022-06-17 175922.png You can see that sql statements are executed well.

        I'm sorry that the sentence is not smooth using a translator.

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

        @meria0503 said in DB search results are normal, but Qt displays an error. I'd like to know the solution.:

        QSqlQuery::value: not positioned on a valid record

        I admit I am not sure where this is coming from, and how come if(query.exec(sqlQuery)) is returning true.

        However

        QSqlError("1861", "Unable to execute statement", "ORA-01861: literal does not match format string\n")

        TO_DATE('2022-06-17 00:00:00', 'YYYY-MM-DD HH24:MI:SS ') AND TO_DATE('2022-06-17 23:59:59', 'YYYY-MM-DD HH24:MI:SS ')

        I can only guess this is what it is not happy about.

        • Try removing the WHERE clause. Does the query run OK?
        • Is hmidata.time indeed a datetime not just a time?
        • Is time on its own like you have any kind of reserved word in Oracle? E.g. does it need to read hmidata.time?
        • Try using bool QSqlQuery::prepare(const QString &query). Does that return false? If so that rules actually issuing the query being the issue.
        • Just in case, remove the trailing space at the end of each of your format strings. [ @Christian-Ehrlicher's post has crossed with mine, I see he suggests this too.]
        1 Reply Last reply
        1
        • M Offline
          M Offline
          meria0503
          wrote on last edited by meria0503
          #4

          @Christian-Ehrlicher @JonB

          Thank you both for your kind reply.

          But there was a part that I made a mistake.

          DB data type is a varchar type, but there was a problem when I tried to get it as a date type.

          Qt also has to write qreal to express the chart, but qreal has to write float or double. only

          I get the X-axis as a date, and if you look at it, it's divided into year, month, day, hour, minute, and so on. I got it as an int and I was expressing the date.

          There was a problem when I tried to get this part in date format and I wanted to solve it

          I thought it'd be better to get it in a text format, so I tried it, and it was successful. Here's the solution.

          SELECT year,month,day,hour,minute,%3 FROM hmidata WHERE time BETWEEN '%1 00:00:00' AND '%2 23:59:59' order by time

          Using this sql statement, I was able to recognize it as a string and check that the chart was loaded normally. string.

          thank u :)

          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