Skip to content

Commit

Permalink
0004168: SQL-Server capture rows that exceed 4000 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Marzullo committed Oct 26, 2022
1 parent e4d9fc9 commit 8a32ecf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
Expand Up @@ -58,7 +58,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 @@ -95,7 +95,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), current_timestamp \n" +
" $(if:containsBlobClobColumns) \n" +
" from inserted inner join $(schemaName)$(tableName) $(origTableAlias) on $(tableNewPrimaryKeyJoin) \n" +
Expand Down Expand Up @@ -123,7 +123,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), current_timestamp \n" +
" $(if:containsBlobClobColumns) \n" +
" from inserted inner join $(schemaName)$(tableName) $(origTableAlias) on $(tableNewPrimaryKeyJoin) \n" +
Expand Down Expand Up @@ -170,7 +170,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" +
" current_timestamp \n" +
Expand All @@ -189,7 +189,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), current_timestamp \n" +
Expand All @@ -198,7 +198,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), current_timestamp \n" +
Expand All @@ -217,7 +217,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" +
" current_timestamp \n" +
Expand Down Expand Up @@ -264,7 +264,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" +
" current_timestamp \n" +
Expand All @@ -283,7 +283,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), current_timestamp \n" +
Expand All @@ -292,7 +292,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), current_timestamp \n" +
Expand All @@ -310,7 +310,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), current_timestamp \n" +
" $(if:containsBlobClobColumns) \n" +
Expand Down Expand Up @@ -342,7 +342,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), current_timestamp\n" +
" from deleted where $(syncOnDeleteCondition) \n" +
" end \n" +
Expand Down Expand Up @@ -495,4 +495,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 @@ -1036,9 +1036,14 @@ else if (column.getJdbcTypeName() != null
} 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);
Expand Down

0 comments on commit 8a32ecf

Please sign in to comment.