0

I've been unsuccessfully trying to implement the following:

var queryResult: OpaquePointer? 
var query = "INSERT INTO myTable (id, remarks, status) VALUES (?,?,?) ON CONFLICT(id) DO UPDATE SET remarks=?, status=?"            

if sqlite3_prepare_v2(dbase, query, -1, &queryResult, nil) == SQLITE_OK {
    sqlite3_bind_int(queryResult, 1, 7)                      // insert id
    sqlite3_bind_text(queryResult, 2, "my remarks, -1, nil)  // insert remarks      
    sqlite3_bind_int(queryResult, 3, 1)                      // insert status 
    sqlite3_bind_text(queryResult, 4, "my remarks, -1, nil)  // update remarks      
    sqlite3_bind_int(queryResult, 5, 1)                      // update status 
}

But I keep getting this error on sqlite3_prepare_v2:

sqlite3 error (near "ON": syntax error)

Is there some issue with my execution or does Swift 4.1 sqlite3 simply not support ON CONFLICT?

TIA

iSofia
  • 1,412
  • 2
  • 19
  • 36
  • That's sqlite code not swift??? What version of sqlite are you using? – trojanfoe Oct 16 '19 at 10:48
  • Wouldn't that be dependent on the device? – iSofia Oct 16 '19 at 11:08
  • 1
    That UPSERT syntax requires sqlite 3.24 or newer. The version of Swift doesn't matter (unless it comes with a particular fixed version of sqlite instead of using some system-wide shared library version) – Shawn Oct 16 '19 at 11:10
  • Just checked with **sqlite3_libversion()**. It's v.3.16. Thank you, Shawn. – iSofia Oct 16 '19 at 11:12

0 Answers0