Skip to content

Commit

Permalink
0005966: SQLAnywhere support for stream row
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Marzullo committed Aug 31, 2023
1 parent ef0ebc0 commit 332c84c
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ public SqlAnywhere12TriggerTemplate(ISymmetricDialect symmetricDialect) {
" end if; "
+
" end; ");
sqlTemplates.put("insertReloadTriggerTemplate",
"create or replace trigger $(triggerName) after insert order 10000 "
+ "on $(schemaName)$(tableName) referencing new as inserted "
+ " begin "
+ " declare @NewPk varchar(2000); "
+ " declare @ChannelId varchar(128); "
+ " declare @err_notfound EXCEPTION FOR SQLSTATE VALUE '02000'; "
+ " $(custom_before_insert_text) \n"
+ " if ($(syncOnIncomingBatchCondition)) then begin "
+ " declare DataCursor cursor for "
+ " select $(newKeys), $(channelExpression) from inserted where $(syncOnInsertCondition); "
+ " open DataCursor; "
+ " LoopGetRow: "
+ " loop "
+ " fetch next DataCursor into @NewPK, @ChannelId; "
+ " if SQLSTATE = @err_notfound then "
+ " leave LoopGetRow "
+ " end if; "
+ " insert into $(defaultCatalog)$(defaultSchema)$(prefixName)_data (table_name, event_type, trigger_hist_id, pk_data, channel_id, transaction_id, source_node_id, external_data, create_time) "
+ " values('$(targetTableName)','R', $(triggerHistoryId), @NewPK, @ChannelId, $(txIdExpression), $(defaultCatalog)$(defaultSchema)$(prefixName)_node_disabled(0), $(externalSelect), getdate()); "
+ " end loop LoopGetRow; "
+ " close DataCursor; "
+ " end; "
+ " $(custom_on_insert_text) "
+ " end if; "
+ " end; ");
sqlTemplates.put("updateTriggerTemplate",
"create or replace trigger $(triggerName) after update order 10000 on $(schemaName)$(tableName) "
+
Expand Down Expand Up @@ -128,6 +154,32 @@ public SqlAnywhere12TriggerTemplate(ISymmetricDialect symmetricDialect) {
" end if;"
+
"end; ");
sqlTemplates.put("updateReloadTriggerTemplate",
"create or replace trigger $(triggerName) after update order 10000 on $(schemaName)$(tableName) "
+ "referencing old as deleted new as inserted "
+ "begin "
+ " declare @OldPk varchar(2000); "
+ " declare @ChannelId varchar(128); "
+ " declare @err_notfound EXCEPTION FOR SQLSTATE VALUE '02000'; "
+ " $(custom_before_update_text) \n "
+ " if ($(syncOnIncomingBatchCondition)) then begin "
+ " declare DataCursor cursor for "
+ " select $(oldKeys), $(channelExpression) from deleted where $(syncOnUpdateCondition); "
+ " open DataCursor; "
+ " LoopGetRow: "
+ " loop "
+ " fetch next DataCursor into @OldPK, @ChannelId; "
+ " if SQLSTATE = @err_notfound then "
+ " leave LoopGetRow "
+ " end if; "
+ " insert into $(defaultCatalog)$(defaultSchema)$(prefixName)_data (table_name, event_type, trigger_hist_id, pk_data, channel_id, transaction_id, source_node_id, external_data, create_time) "
+ " values('$(targetTableName)','R', $(triggerHistoryId), @OldPK, @ChannelId, $(txIdExpression), $(defaultCatalog)$(defaultSchema)$(prefixName)_node_disabled(0), $(externalSelect), getdate()); "
+ " end loop LoopGetRow; "
+ " close DataCursor; "
+ " end; "
+ " $(custom_on_update_text) "
+ " end if; "
+ "end; ");
sqlTemplates.put("deleteTriggerTemplate",
"create or replace trigger $(triggerName) after delete order 10000 on $(schemaName)$(tableName) referencing old as deleted "
+
Expand Down

0 comments on commit 332c84c

Please sign in to comment.