Skip to content

Commit

Permalink
0005557: SQL-Server capture rows that exceed 4000 characters
Browse files Browse the repository at this point in the history
# Conflicts:
#	symmetric-core/src/main/java/org/jumpmind/symmetric/db/AbstractTriggerTemplate.java

# Conflicts:
#	symmetric-client/src/main/java/org/jumpmind/symmetric/db/mssql/MsSqlTriggerTemplate.java
  • Loading branch information
Philip Marzullo committed Oct 26, 2022
1 parent 4f04064 commit df14dcc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
Expand Up @@ -55,7 +55,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
emptyColumnTemplate = "''" ;
stringColumnTemplate = "case when $(tableAlias).\"$(columnName)\" is null then '' else '\"' + replace(replace(convert("+
(castToNVARCHAR ? "n" : "")
+"varchar($(columnSize)),$(tableAlias).\"$(columnName)\") $(masterCollation),'\\','\\\\'),'\"','\\\"') + '\"' end" ;
+"varchar($(columnSizeOrMax)),$(tableAlias).\"$(columnName)\") $(masterCollation),'\\','\\\\'),'\"','\\\"') + '\"' end" ;
geometryColumnTemplate = "case when $(tableAlias).\"$(columnName)\" is null then '' else '\"' + replace(replace(convert("+(castToNVARCHAR ? "n" : "")+"varchar(max),$(tableAlias).\"$(columnName)\".STAsText()) $(masterCollation),'\\','\\\\'),'\"','\\\"') + '\"' end" ;
geographyColumnTemplate = "case when $(tableAlias).\"$(columnName)\" is null then '' else '\"' + replace(replace(convert("+(castToNVARCHAR ? "n" : "")+"varchar(max),$(tableAlias).\"$(columnName)\".STAsText()) $(masterCollation),'\\','\\\\'),'\"','\\\"') + '\"' end" ;
numberColumnTemplate = "case when $(tableAlias).\"$(columnName)\" is null then '' else ('\"' + convert(varchar(40), $(tableAlias).\"$(columnName)\",2) + '\"') end" ;
Expand Down Expand Up @@ -92,7 +92,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" if ($(syncOnIncomingBatchCondition)) begin \n" +
" insert into " + defaultCatalog + "$(defaultSchema)$(prefixName)_data \n" +
" (table_name, event_type, trigger_hist_id, row_data, channel_id, transaction_id, source_node_id, external_data, create_time) \n" +
" select '$(targetTableName)','I', $(triggerHistoryId), $(columns), \n" +
" select '$(targetTableName)','I', $(triggerHistoryId), $(oracleToClob)$(columns), \n" +
" $(channelExpression), $(txIdExpression), " + defaultCatalog + "dbo.$(prefixName)_node_disabled(), $(externalSelect), " + getCreateTimeExpression() + " \n" +
" $(if:containsBlobClobColumns) \n" +
" from inserted inner join $(schemaName)$(tableName) $(origTableAlias) on $(tableNewPrimaryKeyJoin) \n" +
Expand Down Expand Up @@ -120,7 +120,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" if ($(syncOnIncomingBatchCondition)) begin \n" +
" insert into " + defaultCatalog + "$(defaultSchema)$(prefixName)_data \n" +
" (table_name, event_type, trigger_hist_id, pk_data, channel_id, transaction_id, source_node_id, external_data, create_time) \n" +
" select '$(targetTableName)','R', $(triggerHistoryId), $(newKeys), \n" +
" select '$(targetTableName)','R', $(triggerHistoryId), $(oracleToClob)$(newKeys), \n" +
" $(channelExpression), $(txIdExpression), " + defaultCatalog + "dbo.$(prefixName)_node_disabled(), $(externalSelect), " + getCreateTimeExpression() + " \n" +
" $(if:containsBlobClobColumns) \n" +
" from inserted inner join $(schemaName)$(tableName) $(origTableAlias) on $(tableNewPrimaryKeyJoin) \n" +
Expand Down Expand Up @@ -175,7 +175,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" (table_name, event_type, trigger_hist_id, row_data, pk_data, old_data, channel_id, \n" +
" transaction_id, source_node_id, \n" +
" external_data, create_time) \n" +
" select '$(targetTableName)','U', $(triggerHistoryId), $(columns), $(oldKeys), $(oldColumns), \n" +
" select '$(targetTableName)','U', $(triggerHistoryId), $(oracleToClob)$(columns), $(oracleToClob)$(oldKeys), $(oracleToClob)$(oldColumns), \n" +
" $(channelExpression), \n" +
" $(txIdExpression), " + defaultCatalog + "dbo.$(prefixName)_node_disabled(), $(externalSelect), \n" +
" " + getCreateTimeExpression() + " \n" +
Expand All @@ -194,7 +194,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" insert into " + defaultCatalog + "$(defaultSchema)$(prefixName)_data \n" +
" (table_name, event_type, trigger_hist_id, pk_data, channel_id, transaction_id, \n" +
" source_node_id, external_data, create_time) \n" +
" select '$(targetTableName)','D', $(triggerHistoryId), $(oldKeys), \n" +
" select '$(targetTableName)','D', $(triggerHistoryId), $(oracleToClob)$(oldKeys), \n" +
" $(specialSqlServerSybaseChannelExpression), $(txIdExpression), \n" +
defaultCatalog + "dbo.$(prefixName)_node_disabled(), \n" +
" $(externalSelectForDelete), " + getCreateTimeExpression() + " \n" +
Expand All @@ -203,7 +203,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" insert into " + defaultCatalog + "$(defaultSchema)$(prefixName)_data \n" +
" (table_name, event_type, trigger_hist_id, row_data, channel_id, transaction_id, \n" +
" source_node_id, external_data, create_time) \n" +
" select '$(targetTableName)','I', $(triggerHistoryId), $(columns), \n" +
" select '$(targetTableName)','I', $(triggerHistoryId), $(oracleToClob)$(columns), \n" +
" $(channelExpression), $(txIdExpression), \n" +
defaultCatalog + "dbo.$(prefixName)_node_disabled(), \n" +
" $(externalSelectForInsert), " + getCreateTimeExpression() + " \n" +
Expand All @@ -222,7 +222,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" (table_name, event_type, trigger_hist_id, row_data, pk_data, old_data, channel_id, \n" +
" transaction_id, source_node_id, \n" +
" external_data, create_time) \n" +
" select '$(targetTableName)','U', $(triggerHistoryId), $(columns), $(oldKeys), $(oldColumns), \n" +
" select '$(targetTableName)','U', $(triggerHistoryId), $(oracleToClob)$(columns), $(oracleToClob)$(oldKeys), $(oracleToClob)$(oldColumns), \n" +
" $(channelExpression), \n" +
" $(txIdExpression), " + defaultCatalog + "dbo.$(prefixName)_node_disabled(), $(externalSelect), \n" +
" " + getCreateTimeExpression() + " \n" +
Expand Down Expand Up @@ -275,7 +275,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" (table_name, event_type, trigger_hist_id, row_data, pk_data, old_data, channel_id, \n" +
" transaction_id, source_node_id, \n" +
" external_data, create_time) \n" +
" select '$(targetTableName)','U', $(triggerHistoryId), $(columns), $(oldKeys), $(oldColumns), \n" +
" select '$(targetTableName)','U', $(triggerHistoryId), $(oracleToClob)$(columns), $(oracleToClob)$(oldKeys), $(oracleToClob)$(oldColumns), \n" +
" $(channelExpression), \n" +
" $(txIdExpression), " + defaultCatalog + "dbo.$(prefixName)_node_disabled(), $(externalSelect), \n" +
" " + getCreateTimeExpression() + " \n" +
Expand All @@ -294,7 +294,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" insert into " + defaultCatalog + "$(defaultSchema)$(prefixName)_data \n" +
" (table_name, event_type, trigger_hist_id, pk_data, channel_id, transaction_id, \n" +
" source_node_id, external_data, create_time) \n" +
" select '$(targetTableName)','D', $(triggerHistoryId), $(oldKeys), \n" +
" select '$(targetTableName)','D', $(triggerHistoryId), $(oracleToClob)$(oldKeys), \n" +
" $(specialSqlServerSybaseChannelExpression), \n" +
" $(txIdExpression), " + defaultCatalog + "dbo.$(prefixName)_node_disabled(), \n" +
" $(externalSelectForDelete), " + getCreateTimeExpression() + " \n" +
Expand All @@ -303,7 +303,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" insert into " + defaultCatalog + "$(defaultSchema)$(prefixName)_data \n" +
" (table_name, event_type, trigger_hist_id, pk_data, channel_id, transaction_id, \n" +
" source_node_id, external_data, create_time) \n" +
" select '$(targetTableName)','R', $(triggerHistoryId), $(newKeys), \n" +
" select '$(targetTableName)','R', $(triggerHistoryId), $(oracleToClob)$(newKeys), \n" +
" $(channelExpression), $(txIdExpression), \n" +
defaultCatalog + "dbo.$(prefixName)_node_disabled(), \n" +
" $(externalSelectForInsert), " + getCreateTimeExpression() + " \n" +
Expand All @@ -321,7 +321,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" insert into " + defaultCatalog + "$(defaultSchema)$(prefixName)_data \n" +
" (table_name, event_type, trigger_hist_id, pk_data, channel_id, transaction_id, \n" +
" source_node_id, external_data, create_time) \n" +
" select '$(targetTableName)','R', $(triggerHistoryId), $(oldKeys), $(channelExpression), \n" +
" select '$(targetTableName)','R', $(triggerHistoryId), $(oracleToClob)$(oldKeys), $(channelExpression), \n" +
" $(txIdExpression), " + defaultCatalog + "dbo.$(prefixName)_node_disabled(), \n" +
" $(externalSelect), " + getCreateTimeExpression() + " \n" +
" $(if:containsBlobClobColumns) \n" +
Expand Down Expand Up @@ -409,7 +409,7 @@ public MsSqlTriggerTemplate(ISymmetricDialect symmetricDialect) {
" $(custom_before_delete_text) \n" +
" if ($(syncOnIncomingBatchCondition)) begin \n" +
" insert into " + defaultCatalog + "$(defaultSchema)$(prefixName)_data (table_name, event_type, trigger_hist_id, pk_data, old_data, channel_id, transaction_id, source_node_id, external_data, create_time) \n" +
" select '$(targetTableName)','D', $(triggerHistoryId), $(oldKeys), $(oldColumns), $(channelExpression), \n" +
" select '$(targetTableName)','D', $(triggerHistoryId), $(oracleToClob)$(oldKeys), $(oracleToClob)$(oldColumns), $(channelExpression), \n" +
" $(txIdExpression), " + defaultCatalog + "dbo.$(prefixName)_node_disabled(), $(externalSelect), " + getCreateTimeExpression() + "\n" +
" from deleted where $(syncOnDeleteCondition) \n" +
" end \n" +
Expand Down Expand Up @@ -566,4 +566,13 @@ protected boolean useTriggerTemplateForColumnTemplatesDuringInitialLoad(Column c
protected boolean requiresEmptyLobTemplateForDeletes() {
return true;
}

@Override
protected String toClobExpression(Table table) {
if (castToNVARCHAR) {
return "cast(N'' as nvarchar(max)) +";
} else {
return "cast('' as varchar(max)) +";
}
}
}
Expand Up @@ -898,8 +898,10 @@ protected ColumnString fillOutColumnTemplate(String origTableAlias, String table
} else {
throw new NotImplementedException("Table " + table + " column " + column);
}
String formattedColumnText = FormatUtils.replace("columnName",
String.format("%s%s", columnPrefix, column.getName()), templateToUse);
String formattedColumnText = FormatUtils.replace("columnSizeOrMax",
trigger.isUseCaptureLobs() ? "max" : "$(columnSize)", templateToUse);
formattedColumnText = FormatUtils.replace("columnName",
String.format("%s%s", columnPrefix, column.getName()), formattedColumnText);
formattedColumnText = FormatUtils.replace("columnSize",
getColumnSize(table, column), formattedColumnText);
formattedColumnText = FormatUtils.replace("masterCollation",
Expand Down

0 comments on commit df14dcc

Please sign in to comment.