Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Event Trigger creation for MSSQL tables with reserved word columns (close #9929) #9926

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions server/src-lib/Hasura/Backends/MSSQL/DDL/EventTrigger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,9 @@ generateColumnTriggerAlias op colPrefixMaybe colInfo =
case colPrefixMaybe of
-- prefix with the joining table's name
-- `id` -> `inserted.id` (prefix = 'inserted')
Just colPrefix -> colPrefix <> "." <> dbColNameText
Just colPrefix -> "[" <> colPrefix <> "].[" <> dbColNameText <> "]"
-- do not prefix anthing to the column name
Nothing -> dbColNameText
Nothing -> "[" <> dbColNameText <> "]"
-- create the alias for the column
-- `payload.data.old.id` (opText = old) (dbColNameText = id)
dbColAlias = "payload.data" <> "." <> opText <> "." <> dbColNameText
Expand Down Expand Up @@ -802,7 +802,7 @@ mkPrimaryKeyJoinExp lhsPrefix rhsPrefix columns =
where
singleColExp colInfo =
let dbColNameText = columnNameText $ ciColumn colInfo
in LT.toStrict $ [ST.stext| #{lhsPrefix}.#{dbColNameText} = #{rhsPrefix}.#{dbColNameText} |]
in LT.toStrict $ [ST.stext| [#{lhsPrefix}].[#{dbColNameText}] = [#{rhsPrefix}].[#{dbColNameText}] |]

-- Creates the WHERE clause for UPDATE SQL Trigger
-- eg: If no listenColumns are defined then the where clause is an empty text
Expand All @@ -814,7 +814,7 @@ mkListenColumnsExp lhsPrefix rhsPrefix columns =
where
singleColExp colInfo =
let dbColNameText = columnNameText $ ciColumn colInfo
in LT.toStrict $ [ST.stext| #{lhsPrefix}.#{dbColNameText} != #{rhsPrefix}.#{dbColNameText} |]
in LT.toStrict $ [ST.stext| [#{lhsPrefix}].[#{dbColNameText}] != [#{rhsPrefix}].[#{dbColNameText}] |]

-- | Check if primary key is present in listen columns
-- We use this in update event trigger, to check if the primary key has been updated
Expand Down