Skip to content

Commit

Permalink
fix: escape SQL column names in MSSQL's event trigger
Browse files Browse the repository at this point in the history
GITHUB_PR_NUMBER: 9926
GITHUB_PR_URL: #9926

PR-URL: hasura/graphql-engine-mono#10378
Co-authored-by: Nakano as a Service <20109935+nakanoasaservice@users.noreply.github.com>
GitOrigin-RevId: 644e8fa2cf8c86f85c72c7a075e375a071cb5814
  • Loading branch information
hasura-bot and nakanoasaservice committed Oct 30, 2023
1 parent 82fa13d commit 17e1516
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/src-lib/Hasura/Backends/MSSQL/DDL/EventTrigger.hs
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

0 comments on commit 17e1516

Please sign in to comment.