Skip to content

Commit

Permalink
0001785: Hard coded EXECUTE AS OWNER in Sql Server triggers causes is…
Browse files Browse the repository at this point in the history
…sues if the tables are created under another account
  • Loading branch information
chenson42 committed Jul 2, 2014
1 parent a020ece commit 4dfe82e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Expand Up @@ -40,6 +40,8 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {

boolean castToNVARCHAR = symmetricDialect.getParameterService().is(ParameterConstants.MSSQL_USE_NTYPES_FOR_SYNC);

String triggerExecuteAs = symmetricDialect.getParameterService().getString(ParameterConstants.MSSQL_TRIGGER_EXECUTE_AS, "self");

// @formatter:off
emptyColumnTemplate = "''" ;
stringColumnTemplate = "case when $(tableAlias).\"$(columnName)\" is null then '' else '\"' + replace(replace(convert("+
Expand All @@ -60,7 +62,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
sqlTemplates = new HashMap<String,String>();

sqlTemplates.put("insertTriggerTemplate" ,
"create trigger $(triggerName) on $(schemaName)$(tableName) with execute as owner after insert as \n" +
"create trigger $(triggerName) on $(schemaName)$(tableName) with execute as "+triggerExecuteAs+" after insert as \n" +
" begin \n" +
" declare @NCT int \n" +
" set @NCT = @@OPTIONS & 512 \n" +
Expand Down Expand Up @@ -94,7 +96,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" end " );

sqlTemplates.put("updateTriggerTemplate" ,
"create trigger $(triggerName) on $(schemaName)$(tableName) with execute as owner after update as \n" +
"create trigger $(triggerName) on $(schemaName)$(tableName) with execute as "+triggerExecuteAs+" after update as \n" +
" begin \n" +
" declare @NCT int \n" +
" set @NCT = @@OPTIONS & 512 \n" +
Expand Down Expand Up @@ -133,7 +135,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" end " );

sqlTemplates.put("updateHandleKeyUpdatesTriggerTemplate" ,
"create trigger $(triggerName) on $(schemaName)$(tableName) with execute as owner after update as \n" +
"create trigger $(triggerName) on $(schemaName)$(tableName) with execute as "+triggerExecuteAs+" after update as \n" +
" begin \n" +
" declare @NCT int \n" +
" set @NCT = @@OPTIONS & 512 \n" +
Expand Down Expand Up @@ -180,7 +182,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" end " );

sqlTemplates.put("deleteTriggerTemplate" ,
"create trigger $(triggerName) on $(schemaName)$(tableName) with execute as owner after delete as \n" +
"create trigger $(triggerName) on $(schemaName)$(tableName) with execute as "+triggerExecuteAs+" after delete as \n" +
" begin \n" +
" declare @NCT int \n" +
" set @NCT = @@OPTIONS & 512 \n" +
Expand Down
Expand Up @@ -258,6 +258,8 @@ private ParameterConstants() {
public final static String MSSQL_ROW_LEVEL_LOCKS_ONLY = "mssql.allow.only.row.level.locks.on.runtime.tables";

public final static String MSSQL_USE_NTYPES_FOR_SYNC = "mssql.use.ntypes.for.sync";

public final static String MSSQL_TRIGGER_EXECUTE_AS = "mssql.trigger.execute.as";

public static Map<String, ParameterMetaData> getParameterMetaData() {
return parameterMetaData;
Expand Down
18 changes: 12 additions & 6 deletions symmetric-core/src/main/resources/symmetric-default.properties
Expand Up @@ -1260,28 +1260,28 @@ mysql.bulk.load.replace=true
# Maximum number of rows to write to file before running with "BULK INSERT" to SQL-Server
#
# DatabaseOverridable: true
# Tags: other
# Tags: other, mssql
mssql.bulk.load.max.rows.before.flush=100000

# Whether or not triggers should be allowed to fire when bulk loading data.
#
# DatabaseOverridable: true
# Tags: other
# Tags: other, mssql
# Type: boolean
mssql.bulk.load.fire.triggers=false

# Specify a UNC network path to the tmp\bulkloaddir directory for SQL Server to access bulk load files.
# Use this property with bulk loader when SymmetricDS is on a separate server from SQL Server.
#
# DatabaseOverridable: true
# Tags: other
# Tags: other, mssql
mssql.bulk.load.unc.path=

# Automatically update data, data_event and outgoing_batch tables to allow only
# row level locking.
#
# DatabaseOverridable: true
# Tags: other
# Tags: other, mssql
# Type: boolean
mssql.allow.only.row.level.locks.on.runtime.tables=true

Expand All @@ -1290,6 +1290,12 @@ mssql.allow.only.row.level.locks.on.runtime.tables=true
# when the database collation for char types isn't compatible with n char types.
#
# DatabaseOverridable: true
# Tags: other
# Tags: other, mssql
# Type: boolean
mssql.use.ntypes.for.sync=false
mssql.use.ntypes.for.sync=false

# Specify the user the SymmetricDS triggers should execute as. Possible values are
# { CALLER | SELF | OWNER | 'user_name' }
# DatabaseOverridable: true
# Tags: other, mssql
mssql.trigger.execute.as=self

0 comments on commit 4dfe82e

Please sign in to comment.