DB search results are normal, but Qt displays an error. I'd like to know the solution.
-
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")
You can see that sql statements are executed well.I'm sorry that the sentence is not smooth using a translator.
-
@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.
-
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")
You can see that sql statements are executed well.I'm sorry that the sentence is not smooth using a translator.
@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
WHEREclause. Does the query run OK? - Is
hmidata.timeindeed a datetime not just a time? - Is
timeon its own like you have any kind of reserved word in Oracle? E.g. does it need to readhmidata.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.]
- Try removing the
-
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 :)