How to use QSqlQuery with "to_timestamp"?



  • Hi,

    I would like to use "to_timestamp" to write a timestamp into my database.

    If I execute this line everything works really fine:

    QSqlQuery insert;
     insert.exec("INSERT INTO t_measured_data (number, angle, time)" "VALUES (10,3.4,to_timestamp('2015-09-01 13:36:38:999', 'yyyy-mm-dd hh24:mi:ss:ms'))")  
    

    Of course I would like to insert values from a function and therefore I would like to use the "bind"-syntax.

    If I write it like the following it gives me an error:

    QString test="to_timestamp('2015-09-01 13:36:38:999', 'yyyy-mm-dd hh24:mi:ss:ms')" ;
            insert.prepare("INSERT INTO t_measured_data  (number, angle, time)" "VALUES (:number, :angle, :time)");
            insert.bindValue(":number",QString::number(Number) );
            insert.bindValue(":angle", QString::number(Angle,'f', 2) );
            insert.bindValue(":time", test  );
            if (!insert.exec()) qDebug() << "Error!" << insert.lastError().text() ;
    

    Where is the error?
    What it the correct way to use "to_timestamp"?

    Thank you very much :-)


Log in to reply
 

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