prabushitha
prabushitha

Reputation: 1483

How to bind datetime function in sqlite3 c++

My sqlite insert statement is as

char *testSQL;
testSQL = "INSERT INTO Test (id, tx_time) VALUES ("+id+ ", datetime("+timestamp+",'unixepoch', 'localtime'));";

I'm trying to convert above into prepared statement using sqlite3_bind.

testSQL = "INSERT INTO Test (id, tx_time) VALUES (?, ?);";

I can bind id simply using sqlite3_bind_int(stmt, 1, id) but how can I bind datetime function?

Upvotes: 0

Views: 636

Answers (1)

varro
varro

Reputation: 2482

Put the datetime in the SQL instead:

char *testSQL;
testSQL = "INSERT INTO Test (id, tx_time) "
          "VALUES (?, datetime(?,'unixepoch', 'localtime'));"

And use sqlite3_bind_int to bind timestamp instead.

Upvotes: 1

Related Questions