for customer trial purpose, i used SQLite for Database
I have problem with INSERT ON CONFLICT DO UPDATE with SQLite, when there is no conflict ,then the query works normally, but when conflict happen because of unique constraint, the ON CONFLICT does'nt work and throw an error..
import java.lang.Exception
txId = system.db.beginTransaction(timeout=5000)
try:
excelFile = event.file.getBytes()
res = system.dataset.fromExcel(excelFile, headerRow=0, sheetNumber=0)
data = Convert.toJson(res)
query = """INSERT INTO myTable(orders, earl_start_date)
VALUES(?, ?)
ON CONFLICT (orders)
DO UPDATE SET
orders=?, earl_start_date=?"""
for item in data:
args = [item["Order"], system.date.toMillis(item["Earl.start date"])]*2
system.db.runPrepUpdate(query, args, tx=txId)
system.db.commitTransaction(txId)
except java.lang.Exception, err:
system.perspective.sendMessage(
'toastMessage',
payload={"text": "There is problem with database query \n\n" + str(err), "level": "error"},
scope='session'
)
system.db.rollbackTransaction(txId)
else:
self.getSibling("Table").props.data = data
finally:
system.db.closeTransaction(txId)
Why not try your insert, catch the error if there is one since you have a unique constraint and do your update in there? You can follow this logic of this post
What error message do you get from trying to insert a duplicate?
I would tend to agree with @pturmel here - setting up a real database doesn't take more than 15 minutes of time and you will get a lot more for it. If you continue with SQLLite syntax like INSERT ... ON CONFLICT UPDATE which SQL Server does not have, you will end up needing to rewrite your queries too - probably more work than just making an instance of SQL Server Express.