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
  • Loading branch information
nakanoasaservice committed Oct 11, 2023
1 parent 59f83e2 commit e4ed4c7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/src-lib/Hasura/Backends/MSSQL/DDL/EventTrigger.hs
Expand Up @@ -766,7 +766,7 @@ generateColumnTriggerAlias op colPrefixMaybe colInfo =
in -- create the SQL alias using the `as` keyword
-- If colPrefixMaybe existed then alias will be `inserted.id as payload.data.old.id`
-- If no colPrefixMaybe was Nothing then alias will be 'id as payload.data.old.id`
SQLFragment $ LT.toStrict $ [ST.stext| #{joinPrefixedDbColNameText} as [#{dbColAlias}]|]
SQLFragment $ LT.toStrict $ [ST.stext| [#{joinPrefixedDbColNameText}] as [#{dbColAlias}]|]

-- Converts tables name to the format [SCHEMA].[TABLENAME]
-- eg: [dbo].[author], [hge].[books]
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 e4ed4c7

Please sign in to comment.