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. How to use QSqlQuery with "to_timestamp"?
QtWS25 Last Chance

How to use QSqlQuery with "to_timestamp"?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 539 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.
  • R Offline
    R Offline
    RolBri
    wrote on last edited by RolBri
    #1

    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 :-)

    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