Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have problem while fetching data from sqlitedb.I need to fetch data between two dates.But I am not getting data.

query.prepare("SELECT PassID,STARTDATE,ENDDATE,INTIME,OUTTIME FROM ISSUEPASS WHERE STARTDATE BETWEEN ? AND ?");
query.addBindValue(date2);
query.addBindValue(date3);

Here date2 , date3 and STARTDATE are QDate objects

while(query.next)
{
qDebug() << query.value(0).toString().toAscii().data();
qDebug() << query.value(1).toString().toAscii().data();
qDebug() << query.value(2).toString().toAscii().data();
qDebug() << query.value(3).toString().toAscii().data();
qDebug() << query.value(4).toString().toAscii().data();
}

Here nothing is printed,Can you please provide the solution.

What I have tried:

query.prepare("SELECT PassID,STARTDATE,ENDDATE,INTIME,OUTTIME FROM ISSUEPASS WHERE STARTDATE BETWEEN ? AND ?");
query.addBindValue(date2);
query.addBindValue(date3);

while(query.next)
{
qDebug() << query.value(0).toString().toAscii().data();
qDebug() << query.value(1).toString().toAscii().data();
qDebug() << query.value(2).toString().toAscii().data();
qDebug() << query.value(3).toString().toAscii().data();
qDebug() << query.value(4).toString().toAscii().data();
}
Posted
Updated 3-Apr-18 22:11pm

1 solution

SQLite handles datetimes in a different way than other databases. It does not have specific storage classes but stores them as TEXT, REAL, or INTEGER (see Datatypes In SQLite Version 3[^]).

You have to pass the data acording to the used storage class and/or use one of the SQLite Query Language: Date And Time Functions[^].

Untested example:
C++
query.prepare("SELECT PassID,STARTDATE,ENDDATE,INTIME,OUTTIME FROM ISSUEPASS WHERE date(STARTDATE) BETWEEN ? AND ?");
query.addBindValue(date2.toString(Qt::ISODate));
query.addBindValue(date3.toString(Qt::ISODate));
 
Share this answer
 
Comments
Member 13740197 4-Apr-18 7:11am    
This is not working.In query executing it is entering but not entering into
while(query.next).Can you please tell me the solution.
Jochen Arndt 4-Apr-18 7:26am    
So you have called query.exec() (because it is not shown in your code snippet)?

If so and query.next() is false, then there is no matching recordset.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900