datetime insertion in SQLite database using QT and parameters

I am trying to perform an insertion into a SQLite database from a c++/QT application. One of the columns of the table where I want to insert the data is a datetime (yyyy-mm-dd hh:mm:ss).

I have try to use this code:

...
query.prepare("INSERT INTO table (table_date_time, ...) "
        " VALUES (?, ...);");
query.bindValue(0, "datetime('2004-12-11 13:00:00', '+1 day')");
...

but it inserts the text "datetime('2004-12-11 13:00:00', '+1 day')" instead the value 2004-12-12 13:00:00. If I try

...
query.prepare("INSERT INTO table (table_date_time, ...) "
        " VALUES (datetime(?), ...);");
query.bindValue(0, "2004-12-11 13:00:00, +1 day");
...

or

...
query.prepare("INSERT INTO table (table_date_time, ...) "
        " VALUES (datetime(?), ...);");
query.bindValue(0, "'2004-12-11 13:00:00',' +1 day'");
...

the datetime field does not get filled. What is the correct way to use datetime functions allong parameters?

Thanks in advance.

Answers


A bound value only replaces one parameter, the 2 parameters to the datetime function have to be sent separately:

query.prepare("INSERT INTO table (table_date_time, ...) "
        " VALUES (datetime(?, ?), ...)");
query.bindValue(0, "2004-12-11 13:00:00");
query.bindValue(1, "+1 day");

Need Your Help

How to do variadic macros with $(call …) in GNU Make

macros gnu-make variadic-macro

I created a macro for use in makefiles along the lines of:

How do I change my gdb path in Unix?

unix command-line path gdb alias

My professor posted this online for a lab this week, but I missed the tutorial and didn't find how to do this. Does anyone know? It is just a simple command line thing, but I have been hunting arou...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.