ON CONFLICT(id) DO UPDATE SET does not work for FireDAC in DELPHI 10.3.1

。_饼干妹妹 提交于 2019-12-24 01:04:23

问题


After attaching the second database I tried to insert and update data in the table of the first database using ON CONFLICT(id) DO UPDATE. Field id is the primary key for the first table.

  FDQuery1.EXECSQL('ATTACH ''D:\Update2019.DB'' AS DBUpdate');

  FDQuery1.SQL.Text:=
    'INSERT INTO acts (id,title) SELECT id,title FROM DBUpdate.acts'+
    '   WHERE (DBUpdate.acts.id >100)'+
    '   ON CONFLICT(id) DO UPDATE SET'+
    '   title=excluded.title;'
  FDQuery1.ExecSQL;

I get error message: "ERROR near "ON":syntax error" When I removed WHERE (DBUpdate.acts.id >100 condition the error message AS: "ERROR near "DO":syntax error".

The same query works fine in SQLITESTUDIO.


回答1:


As correctly indicated in comments, SQLite that your application uses does not support this syntax. You will need to use newer version of SQLite. To do this, follow the Dynamic linking paragraph of FireDAC SQLite connection topic, otherwise Delphi builds your FireDAC application with statically linked SQLite objects of the version distributed with it (which makes your application dependent on such SQLite version no matter what SQLite DLLs are all around).

Just don't forget the most important part of this task; modifying the FireDAC.inc include file to use dynamic linking. If you don't want to break your Delphi setup source folder, copy for example all the FireDAC modules somewhere else, add them into the build search path of your project, and modify the FireDAC.inc include file there.



来源:https://stackoverflow.com/questions/58982771/on-conflictid-do-update-set-does-not-work-for-firedac-in-delphi-10-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!