coldbox-modules / qb

Fluent Query Builder for CFML
https://qb.ortusbooks.com/
MIT License
40 stars 35 forks source link

update with returning does not work on MSSQL. Wrong placement for OUTPUT. #287

Open Vintic opened 1 month ago

Vintic commented 1 month ago

Error: Incorrect syntax near 'OUTPUT'. This code: ``` <cfset LOCAL.result = common.model.BaseModel::qb() .from("zzz") .returning("xxx") .join("aaa", function(j){ j.on("aaa.ddd", "zzz.ddd") }) .whereIn("aaa.id", [1,2,3]) .update({ "zzz.user_id": 1, "zzz.created": NOW() }) />

returns this: ```
UPDATE [zzz]
SET [created] = {ts '2024-08-13 15:56:05'},
    [user_id] = 1
FROM [zzz]
         INNER JOIN [aaa] ON [aaa].[ddd] = [zzz].[ddd] OUTPUT INSERTED.[xxx]
WHERE [aaa].[id] IN (1, 2, 3)

Problem is that QB, place OUTPUT clause after WHERE, but it should be placed after SET clause. In docs https://qb.ortusbooks.com/query-builder/executing-queries/inserts-updates-deletes#update is placed correctly.