Skip to content

Commit

Permalink
1825800 - MS SQL SERVER DIALECT DEVELOPMENT. Passes IntegrationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Nov 29, 2007
1 parent 74e98f8 commit 87de309
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
Expand Up @@ -95,7 +95,7 @@ protected AbstractDbDialect() {
_defaultSizes.put(new Integer(3), "15,15");
_defaultSizes.put(new Integer(2), "15,15");
}

protected boolean allowsNullForIdentityColumn() {
return true;
}
Expand Down Expand Up @@ -516,13 +516,17 @@ public Object doInConnection(Connection conn) throws SQLException, DataAccessExc
ps = conn.prepareStatement(sql, new int[] { 1 });
} else {
String replaceSql = sql.replaceFirst("\\(\\w*,", "(").replaceFirst("\\(null,", "(");
ps = conn.prepareStatement(replaceSql);
if (supportsGetGeneratedKeys) {
ps = conn.prepareStatement(replaceSql, Statement.RETURN_GENERATED_KEYS);
} else {
ps = conn.prepareStatement(replaceSql);
}
}
ps.setQueryTimeout(jdbcTemplate.getQueryTimeout());
if (callback != null) {
callback.doInPreparedStatement(ps);
}
ps.execute();
ps.executeUpdate();

if (supportsGetGeneratedKeys) {
ResultSet rs = ps.getGeneratedKeys();
Expand Down
32 changes: 19 additions & 13 deletions symmetric/src/main/resources/dialects/mssql.xml
Expand Up @@ -9,7 +9,7 @@
<bean id="msSqlStringTemplate" class="java.lang.String">
<constructor-arg>
<value>
<![CDATA[ case $(tableAlias).$(columnName) when null then '' else '"' + replace(replace($(tableAlias).$(columnName),'\','\\'),'"','\"') + '"' end +','+]]>
<![CDATA[ case when $(tableAlias).$(columnName) is null then '' else '"' + replace(replace($(tableAlias).$(columnName),'\','\\'),'"','\"') + '"' end +','+]]>
</value>
</constructor-arg>
</bean>
Expand All @@ -36,7 +36,7 @@
<!-- TODO -->
<property name="datetimeColumnTemplate">
<value>
<![CDATA[case $(tableAlias).$(columnName) when null then '' else ('"' + cast($(tableAlias).$(columnName) as char) + '"') end +','+]]>
<![CDATA[case when $(tableAlias).$(columnName) is null then '' else ('"' + convert(varchar,$(tableAlias).$(columnName),121) + '"') end +','+]]>
</value>
</property>
<property name="triggerConcatCharacter" value="+"/>
Expand All @@ -58,8 +58,10 @@
if (@SyncEnabled <> 0x1) begin
insert into $(defaultSchema)$(prefixName)_data (table_name, channel_id, event_type, trigger_hist_id, transaction_id, row_data, create_time)
(select '$(targetTableName)','$(channelName)','I', $(triggerHistoryId), $(txIdExpression), $(columns), current_timestamp from inserted where $(syncOnInsertCondition));
insert into $(defaultSchema)$(prefixName)_data_event (node_id, data_id) (select node_id, @@IDENTITY from $(defaultSchema)$(prefixName)_node c where
c.node_group_id='$(targetGroupId)' and c.sync_enabled=1 $(nodeSelectWhere));
if (@@ROWCOUNT > 0) begin
insert into $(defaultSchema)$(prefixName)_data_event (node_id, data_id) (select node_id, @@IDENTITY from $(defaultSchema)$(prefixName)_node c where
c.node_group_id='$(targetGroupId)' and c.sync_enabled=1 $(nodeSelectWhere));
end
end
end
]]>
Expand All @@ -79,13 +81,15 @@
if (@SyncEnabled <> 0x1) begin
insert into $(defaultSchema)$(prefixName)_data (table_name, channel_id, event_type, trigger_hist_id, transaction_id, row_data, pk_data, create_time)
(select '$(targetTableName)','$(channelName)','U', $(triggerHistoryId), $(txIdExpression), $(columns), $(oldKeys), current_timestamp from inserted left outer join deleted on $(oldNewPrimaryKeyJoin) where $(syncOnUpdateCondition));
if (@@ROWCOUNT = 1) begin
declare @OldKeys varchar(1000)
select @OldKeys=$(oldKeys) from deleted;
update $(defaultSchema)$(prefixName)_data set pk_data=@OldKeys where data_id=@@IDENTITY;
end
insert into $(defaultSchema)$(prefixName)_data_event (node_id, data_id) (select node_id, @@IDENTITY from $(defaultSchema)$(prefixName)_node c where
c.node_group_id='$(targetGroupId)' and c.sync_enabled=1 $(nodeSelectWhere));
if (@@ROWCOUNT > 0) begin
if (@@ROWCOUNT = 1) begin
declare @OldKeys varchar(1000)
select @OldKeys=$(oldKeys) from deleted;
update $(defaultSchema)$(prefixName)_data set pk_data=@OldKeys where data_id=@@IDENTITY;
end
insert into $(defaultSchema)$(prefixName)_data_event (node_id, data_id) (select node_id, @@IDENTITY from $(defaultSchema)$(prefixName)_node c where
c.node_group_id='$(targetGroupId)' and c.sync_enabled=1 $(nodeSelectWhere));
end
end
end
]]>
Expand All @@ -105,8 +109,10 @@
if (@SyncEnabled <> 0x1) begin
insert into $(defaultSchema)$(prefixName)_data (table_name, channel_id, event_type, trigger_hist_id, transaction_id, pk_data, create_time)
(select '$(targetTableName)','$(channelName)','D', $(triggerHistoryId), $(txIdExpression), $(oldKeys), current_timestamp from deleted where $(syncOnDeleteCondition));
insert into $(defaultSchema)$(prefixName)_data_event (node_id, data_id) (select node_id, @@IDENTITY from $(defaultSchema)$(prefixName)_node c where
c.node_group_id='$(targetGroupId)' and c.sync_enabled=1 $(nodeSelectWhere));
if (@@ROWCOUNT > 0) begin
insert into $(defaultSchema)$(prefixName)_data_event (node_id, data_id) (select node_id, @@IDENTITY from $(defaultSchema)$(prefixName)_node c where
c.node_group_id='$(targetGroupId)' and c.sync_enabled=1 $(nodeSelectWhere));
end
end
end
]]>
Expand Down
6 changes: 6 additions & 0 deletions symmetric/src/test/resources/log4j.xml
Expand Up @@ -20,6 +20,12 @@
<category name="org.springframework">
<priority value="ERROR" />
</category>

<!-- Enable this to see extract output
<category name="org.jumpmind.symmetric.extract.csv">
<priority value="DEBUG" />
</category>
-->

<root>
<priority value="INFO" />
Expand Down

0 comments on commit 87de309

Please sign in to comment.