print simple Sqlite statement....



  • Hello, I need your help for stupid thing...

    I'm using Sqlite for my qt application and it's easy to print value from table with:

    QSqlQuery query;
            query.prepare("SELECT rowid, data,  FROM table ");
            query.exec();
            while (query.next()) {
    
                QString data= query.value(1).toString();
    }
    

    that fine and easy...
    But I need to make date diff and the statement is:

    QSqlQuery datediff;
                datediff.prepare("SELECT julianday('now') - julianday('2007-02-02')");
                datediff.exec();
    

    using db browser the query is working fine..

    but how can I print the result?....
    I try :

    double dateresult = datediff.value(1).toDouble();
    qDebug() << dateresult
    

    but it's not working... nothing is printed...

    Could you help me?...



  • solved with add datediff.next(); :

    datediff.prepare("SELECT date FROM (SELECT(julianday('now') - julianday(?)) AS date)");
                datediff.addBindValue(dateinsteng2);
                datediff.exec();
                datediff.next();
                int tsn = datediff.value(0).toInt();
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.