View Issue Details

IDProjectCategoryView StatusLast Update
0004201SymmetricDSBugpublic2022-07-27 18:59
Reportermkurz Assigned Topmarzullo  
Prioritynormal 
Status closedResolutionfixed 
Product Version3.11.0 
Target Version3.13.7Fixed in Version3.13.7 
Summary0004201: Failed to create update trigger for triggers that use and external_select with $(curTriggerValue)
DescriptionWe observe several
"Failed to create trigger x ... Reason The multi-part identifier "inserted.customerid" could not be bound"
for all update triggers that use and external_select with $(curTriggerValue) on a MsSql Server. See central_3.11_log_snippet.log.

First analyze shows that happens after
https://www.symmetricds.org/issues/view.php?id=3901
MsSqlTriggerTemplate.java -> updateTriggerTemplate. I guess it affects updateReloadTriggerTemplate, too

I formatted the sql and made it work. Diff the enclosed failing_sql.txt with fixed_sql.txt, please.
Tagsdialect: sql-server, dialect: sybase, trigger

Activities

mkurz

2019-12-12 10:31

reporter  

failing_sql.txt (15,591 bytes)   
CREATE TRIGGER sym_on_u_for_gr_cstmrpctr_c2m_cntrl ON "dbo"."gr_CustomerPicture" WITH 
execute AS 
  caller after 
UPDATE AS BEGIN 
DECLARE @NCT int 
SET @NCT = @@OPTIONS & 512 
SET nocount ON 
DECLARE @TransactionId varchar(1000) 
IF (@@TRANCOUNT > 0) 
BEGIN 
  SELECT @TransactionId = CONVERT(varchar(1000),transaction_id) 
  FROM   sys.dm_exec_requests 
  WHERE  session_id=@@SPID 
  AND    open_transaction_count > 0 
END 
IF (dbo.sym_triggers_disabled() = 0) 
BEGIN 
  IF (1=1 
  AND 
  ( 
         UPDATE(sym_row_id) ) ) 
  BEGIN 
    INSERT INTO "grips"."dbo".sym_data 
                ( 
                            table_name, 
                            event_type, 
                            trigger_hist_id, 
                            pk_data, 
                            channel_id, 
                            transaction_id, 
                            source_node_id, 
                            external_data, 
                            create_time 
                ) 
    SELECT 'GR_CUSTOMERPICTURE', 
           'D', 
           34, 
           CASE 
                  WHEN deleted."sym_row_id" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(36),deleted."sym_row_id") ,'\','\\'),'"','\"') + '"'
           END, 
           'content', 
           @TransactionId, 
           "grips".dbo.sym_node_disabled(), 
           (inserted.customerid), 
           CURRENT_TIMESTAMP 
    FROM   deleted 
    WHERE  EXISTS 
           ( 
                  SELECT 1 
                  FROM   sym_customer2node_active_only s 
                  WHERE  s.customer_id = (inserted.customerid)) 
    AND    1=1 
    INSERT INTO "grips"."dbo".sym_data 
                ( 
                            table_name, 
                            event_type, 
                            trigger_hist_id, 
                            row_data, 
                            channel_id, 
                            transaction_id, 
                            source_node_id, 
                            external_data, 
                            create_time 
                ) 
    SELECT 'GR_CUSTOMERPICTURE', 
           'I', 
           34, 
           CASE 
                  WHEN inserted."sym_row_id" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."sym_row_id") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."Id" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."Id") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."PictureId" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."PictureId") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."CustomerId" IS NULL THEN '' 
                  ELSE ('"' + CONVERT(varchar(40), inserted."CustomerId",2) + '"') 
           END+','+ 
           CASE 
                  WHEN inserted."CreatedDate" IS NULL THEN '' 
                  ELSE ('"' + CONVERT(varchar,inserted."CreatedDate",121) + '"') 
           END+','+ 
           CASE 
                  WHEN inserted."CreatedBy" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."CreatedBy") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."ModifiedDate" IS NULL THEN '' 
                  ELSE ('"' + CONVERT(varchar,inserted."ModifiedDate",121) + '"') 
           END+','+ 
           CASE 
                  WHEN inserted."ModifiedBy" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."ModifiedBy") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."DeletedDate" IS NULL THEN '' 
                  ELSE ('"' + CONVERT(varchar,inserted."DeletedDate",121) + '"') 
           END+','+ 
           CASE 
                  WHEN inserted."DeletedBy" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."DeletedBy") ,'\','\\'),'"','\"') + '"'
           END, 
           'content', 
           @TransactionId, 
           "grips".dbo.sym_node_disabled(), 
           (inserted.customerid), 
           CURRENT_TIMESTAMP 
    FROM   inserted 
    WHERE  EXISTS 
           ( 
                  SELECT 1 
                  FROM   sym_customer2node_active_only s 
                  WHERE  s.customer_id = (inserted.customerid)) 
    AND    1=1 
  END 
  ELSE 
  BEGIN 
    INSERT INTO "grips"."dbo".sym_data 
                ( 
                            table_name, 
                            event_type, 
                            trigger_hist_id, 
                            row_data, 
                            pk_data, 
                            old_data, 
                            channel_id, 
                            transaction_id, 
                            source_node_id, 
                            external_data, 
                            create_time 
                ) 
    SELECT     'GR_CUSTOMERPICTURE', 
               'U', 
               34, 
               CASE 
                          WHEN inserted."sym_row_id" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."sym_row_id") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."Id" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."Id") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."PictureId" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."PictureId") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."CustomerId" IS NULL THEN '' 
                          ELSE ('"' + CONVERT(varchar(40), inserted."CustomerId",2) + '"') 
               END+','+ 
               CASE 
                          WHEN inserted."CreatedDate" IS NULL THEN '' 
                          ELSE ('"' + CONVERT(varchar,inserted."CreatedDate",121) + '"') 
               END+','+ 
               CASE 
                          WHEN inserted."CreatedBy" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."CreatedBy") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."ModifiedDate" IS NULL THEN '' 
                          ELSE ('"' + CONVERT(varchar,inserted."ModifiedDate",121) + '"') 
               END+','+ 
               CASE 
                          WHEN inserted."ModifiedBy" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."ModifiedBy") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."DeletedDate" IS NULL THEN '' 
                          ELSE ('"' + CONVERT(varchar,inserted."DeletedDate",121) + '"') 
               END+','+ 
               CASE 
                          WHEN inserted."DeletedBy" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."DeletedBy") ,'\','\\'),'"','\"') + '"'
               END, 
               CASE 
                          WHEN deleted."sym_row_id" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(36),deleted."sym_row_id") ,'\','\\'),'"','\"') + '"'
               END, 
               NULL, 
               'content', 
               @TransactionId, 
               "grips".dbo.sym_node_disabled(), 
               (inserted.customerid), 
               CURRENT_TIMESTAMP 
    FROM       inserted 
    INNER JOIN deleted 
    ON         deleted."sym_row_id"=inserted."sym_row_id" 
    WHERE      EXISTS 
               ( 
                      SELECT 1 
                      FROM   sym_customer2node_active_only s 
                      WHERE  s.customer_id = (inserted.customerid)) 
    AND        1=1 
    AND        ((( 
                                                inserted."sym_row_id" IS NOT NULL 
                                     AND        deleted."sym_row_id" IS NOT NULL 
                                     AND        inserted."sym_row_id"<>deleted."sym_row_id") 
                          OR         ( 
                                                inserted."sym_row_id" IS NULL 
                                     AND        deleted."sym_row_id" IS NOT NULL) 
                          OR         ( 
                                                inserted."sym_row_id" IS NOT NULL 
                                     AND        deleted."sym_row_id" IS NULL)) 
               OR         (( 
                                                inserted."Id" IS NOT NULL 
                                     AND        deleted."Id" IS NOT NULL 
                                     AND        inserted."Id"<>deleted."Id") 
                          OR         ( 
                                                inserted."Id" IS NULL 
                                     AND        deleted."Id" IS NOT NULL) 
                          OR         ( 
                                                inserted."Id" IS NOT NULL 
                                     AND        deleted."Id" IS NULL)) 
               OR         (( 
                                                inserted."PictureId" IS NOT NULL 
                                     AND        deleted."PictureId" IS NOT NULL 
                                     AND        inserted."PictureId"<>deleted."PictureId") 
                          OR         ( 
                                                inserted."PictureId" IS NULL 
                                     AND        deleted."PictureId" IS NOT NULL) 
                          OR         ( 
                                                inserted."PictureId" IS NOT NULL 
                                     AND        deleted."PictureId" IS NULL)) 
               OR         (( 
                                                inserted."CustomerId" IS NOT NULL 
                                     AND        deleted."CustomerId" IS NOT NULL 
                                     AND        inserted."CustomerId"<>deleted."CustomerId") 
                          OR         ( 
                                                inserted."CustomerId" IS NULL 
                                     AND        deleted."CustomerId" IS NOT NULL) 
                          OR         ( 
                                                inserted."CustomerId" IS NOT NULL 
                                     AND        deleted."CustomerId" IS NULL)) 
               OR         (( 
                                                inserted."CreatedDate" IS NOT NULL 
                                     AND        deleted."CreatedDate" IS NOT NULL 
                                     AND        inserted."CreatedDate"<>deleted."CreatedDate") 
                          OR         ( 
                                                inserted."CreatedDate" IS NULL 
                                     AND        deleted."CreatedDate" IS NOT NULL) 
                          OR         ( 
                                                inserted."CreatedDate" IS NOT NULL 
                                     AND        deleted."CreatedDate" IS NULL)) 
               OR         (( 
                                                inserted."CreatedBy" IS NOT NULL 
                                     AND        deleted."CreatedBy" IS NOT NULL 
                                     AND        inserted."CreatedBy"<>deleted."CreatedBy") 
                          OR         ( 
                                                inserted."CreatedBy" IS NULL 
                                     AND        deleted."CreatedBy" IS NOT NULL) 
                          OR         ( 
                                                inserted."CreatedBy" IS NOT NULL 
                                     AND        deleted."CreatedBy" IS NULL)) 
               OR         (( 
                                                inserted."ModifiedDate" IS NOT NULL 
                                     AND        deleted."ModifiedDate" IS NOT NULL 
                                     AND        inserted."ModifiedDate"<>deleted."ModifiedDate")
                          OR         ( 
                                                inserted."ModifiedDate" IS NULL 
                                     AND        deleted."ModifiedDate" IS NOT NULL) 
                          OR         ( 
                                                inserted."ModifiedDate" IS NOT NULL 
                                     AND        deleted."ModifiedDate" IS NULL)) 
               OR         (( 
                                                inserted."ModifiedBy" IS NOT NULL 
                                     AND        deleted."ModifiedBy" IS NOT NULL 
                                     AND        inserted."ModifiedBy"<>deleted."ModifiedBy") 
                          OR         ( 
                                                inserted."ModifiedBy" IS NULL 
                                     AND        deleted."ModifiedBy" IS NOT NULL) 
                          OR         ( 
                                                inserted."ModifiedBy" IS NOT NULL 
                                     AND        deleted."ModifiedBy" IS NULL)) 
               OR         (( 
                                                inserted."DeletedDate" IS NOT NULL 
                                     AND        deleted."DeletedDate" IS NOT NULL 
                                     AND        inserted."DeletedDate"<>deleted."DeletedDate") 
                          OR         ( 
                                                inserted."DeletedDate" IS NULL 
                                     AND        deleted."DeletedDate" IS NOT NULL) 
                          OR         ( 
                                                inserted."DeletedDate" IS NOT NULL 
                                     AND        deleted."DeletedDate" IS NULL)) 
               OR         (( 
                                                inserted."DeletedBy" IS NOT NULL 
                                     AND        deleted."DeletedBy" IS NOT NULL 
                                     AND        inserted."DeletedBy"<>deleted."DeletedBy") 
                          OR         ( 
                                                inserted."DeletedBy" IS NULL 
                                     AND        deleted."DeletedBy" IS NOT NULL) 
                          OR         ( 
                                                inserted."DeletedBy" IS NOT NULL 
                                     AND        deleted."DeletedBy" IS NULL))) 
  END 
END 
IF (@NCT = 0) 
SET nocount OFF 
END
failing_sql.txt (15,591 bytes)   
fixed_sql.txt (15,641 bytes)   
--drop trigger sym_on_u_for_gr_cstmrpctr_c2m_cntrl
CREATE TRIGGER sym_on_u_for_gr_cstmrpctr_c2m_cntrl ON "dbo"."gr_CustomerPicture" WITH 
execute AS 
  caller after 
UPDATE AS BEGIN 
DECLARE @NCT int 
SET @NCT = @@OPTIONS & 512 
SET nocount ON 
DECLARE @TransactionId varchar(1000) 
IF (@@TRANCOUNT > 0) 
BEGIN 
  SELECT @TransactionId = CONVERT(varchar(1000),transaction_id) 
  FROM   sys.dm_exec_requests 
  WHERE  session_id=@@SPID 
  AND    open_transaction_count > 0 
END 
IF (dbo.sym_triggers_disabled() = 0) 
BEGIN 
  IF (1=1 
  AND 
  ( 
         UPDATE(sym_row_id) ) ) 
  BEGIN 
    INSERT INTO "grips"."dbo".sym_data 
                ( 
                            table_name, 
                            event_type, 
                            trigger_hist_id, 
                            pk_data, 
                            channel_id, 
                            transaction_id, 
                            source_node_id, 
                            external_data, 
                            create_time 
                ) 
    SELECT 'GR_CUSTOMERPICTURE', 
           'D', 
           34, 
           CASE 
                  WHEN deleted."sym_row_id" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(36),deleted."sym_row_id") ,'\','\\'),'"','\"') + '"'
           END, 
           'content', 
           @TransactionId, 
           "grips".dbo.sym_node_disabled(), 
           (deleted.customerid), 
           CURRENT_TIMESTAMP 
    FROM   deleted 
    WHERE  EXISTS 
           ( 
                  SELECT 1 
                  FROM   sym_customer2node_active_only s 
                  WHERE  s.customer_id = (deleted.customerid)) 
    AND    1=1 
    INSERT INTO "grips"."dbo".sym_data 
                ( 
                            table_name, 
                            event_type, 
                            trigger_hist_id, 
                            row_data, 
                            channel_id, 
                            transaction_id, 
                            source_node_id, 
                            external_data, 
                            create_time 
                ) 
    SELECT 'GR_CUSTOMERPICTURE', 
           'I', 
           34, 
           CASE 
                  WHEN inserted."sym_row_id" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."sym_row_id") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."Id" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."Id") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."PictureId" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."PictureId") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."CustomerId" IS NULL THEN '' 
                  ELSE ('"' + CONVERT(varchar(40), inserted."CustomerId",2) + '"') 
           END+','+ 
           CASE 
                  WHEN inserted."CreatedDate" IS NULL THEN '' 
                  ELSE ('"' + CONVERT(varchar,inserted."CreatedDate",121) + '"') 
           END+','+ 
           CASE 
                  WHEN inserted."CreatedBy" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."CreatedBy") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."ModifiedDate" IS NULL THEN '' 
                  ELSE ('"' + CONVERT(varchar,inserted."ModifiedDate",121) + '"') 
           END+','+ 
           CASE 
                  WHEN inserted."ModifiedBy" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."ModifiedBy") ,'\','\\'),'"','\"') + '"'
           END             +','+ 
           CASE 
                  WHEN inserted."DeletedDate" IS NULL THEN '' 
                  ELSE ('"' + CONVERT(varchar,inserted."DeletedDate",121) + '"') 
           END+','+ 
           CASE 
                  WHEN inserted."DeletedBy" IS NULL THEN '' 
                  ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."DeletedBy") ,'\','\\'),'"','\"') + '"'
           END, 
           'content', 
           @TransactionId, 
           "grips".dbo.sym_node_disabled(), 
           (inserted.customerid), 
           CURRENT_TIMESTAMP 
    FROM   inserted 
    WHERE  EXISTS 
           ( 
                  SELECT 1 
                  FROM   sym_customer2node_active_only s 
                  WHERE  s.customer_id = (inserted.customerid)) 
    AND    1=1 
  END 
  ELSE 
  BEGIN 
    INSERT INTO "grips"."dbo".sym_data 
                ( 
                            table_name, 
                            event_type, 
                            trigger_hist_id, 
                            row_data, 
                            pk_data, 
                            old_data, 
                            channel_id, 
                            transaction_id, 
                            source_node_id, 
                            external_data, 
                            create_time 
                ) 
    SELECT     'GR_CUSTOMERPICTURE', 
               'U', 
               34, 
               CASE 
                          WHEN inserted."sym_row_id" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."sym_row_id") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."Id" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."Id") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."PictureId" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(36),inserted."PictureId") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."CustomerId" IS NULL THEN '' 
                          ELSE ('"' + CONVERT(varchar(40), inserted."CustomerId",2) + '"') 
               END+','+ 
               CASE 
                          WHEN inserted."CreatedDate" IS NULL THEN '' 
                          ELSE ('"' + CONVERT(varchar,inserted."CreatedDate",121) + '"') 
               END+','+ 
               CASE 
                          WHEN inserted."CreatedBy" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."CreatedBy") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."ModifiedDate" IS NULL THEN '' 
                          ELSE ('"' + CONVERT(varchar,inserted."ModifiedDate",121) + '"') 
               END+','+ 
               CASE 
                          WHEN inserted."ModifiedBy" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."ModifiedBy") ,'\','\\'),'"','\"') + '"'
               END                 +','+ 
               CASE 
                          WHEN inserted."DeletedDate" IS NULL THEN '' 
                          ELSE ('"' + CONVERT(varchar,inserted."DeletedDate",121) + '"') 
               END+','+ 
               CASE 
                          WHEN inserted."DeletedBy" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(255),inserted."DeletedBy") ,'\','\\'),'"','\"') + '"'
               END, 
               CASE 
                          WHEN deleted."sym_row_id" IS NULL THEN '' 
                          ELSE '"' + replace(replace(CONVERT(varchar(36),deleted."sym_row_id") ,'\','\\'),'"','\"') + '"'
               END, 
               NULL, 
               'content', 
               @TransactionId, 
               "grips".dbo.sym_node_disabled(), 
               (inserted.customerid), 
               CURRENT_TIMESTAMP 
    FROM       inserted 
    INNER JOIN deleted 
    ON         deleted."sym_row_id"=inserted."sym_row_id" 
    WHERE      EXISTS 
               ( 
                      SELECT 1 
                      FROM   sym_customer2node_active_only s 
                      WHERE  s.customer_id = (inserted.customerid)) 
    AND        1=1 
    AND        ((( 
                                                inserted."sym_row_id" IS NOT NULL 
                                     AND        deleted."sym_row_id" IS NOT NULL 
                                     AND        inserted."sym_row_id"<>deleted."sym_row_id") 
                          OR         ( 
                                                inserted."sym_row_id" IS NULL 
                                     AND        deleted."sym_row_id" IS NOT NULL) 
                          OR         ( 
                                                inserted."sym_row_id" IS NOT NULL 
                                     AND        deleted."sym_row_id" IS NULL)) 
               OR         (( 
                                                inserted."Id" IS NOT NULL 
                                     AND        deleted."Id" IS NOT NULL 
                                     AND        inserted."Id"<>deleted."Id") 
                          OR         ( 
                                                inserted."Id" IS NULL 
                                     AND        deleted."Id" IS NOT NULL) 
                          OR         ( 
                                                inserted."Id" IS NOT NULL 
                                     AND        deleted."Id" IS NULL)) 
               OR         (( 
                                                inserted."PictureId" IS NOT NULL 
                                     AND        deleted."PictureId" IS NOT NULL 
                                     AND        inserted."PictureId"<>deleted."PictureId") 
                          OR         ( 
                                                inserted."PictureId" IS NULL 
                                     AND        deleted."PictureId" IS NOT NULL) 
                          OR         ( 
                                                inserted."PictureId" IS NOT NULL 
                                     AND        deleted."PictureId" IS NULL)) 
               OR         (( 
                                                inserted."CustomerId" IS NOT NULL 
                                     AND        deleted."CustomerId" IS NOT NULL 
                                     AND        inserted."CustomerId"<>deleted."CustomerId") 
                          OR         ( 
                                                inserted."CustomerId" IS NULL 
                                     AND        deleted."CustomerId" IS NOT NULL) 
                          OR         ( 
                                                inserted."CustomerId" IS NOT NULL 
                                     AND        deleted."CustomerId" IS NULL)) 
               OR         (( 
                                                inserted."CreatedDate" IS NOT NULL 
                                     AND        deleted."CreatedDate" IS NOT NULL 
                                     AND        inserted."CreatedDate"<>deleted."CreatedDate") 
                          OR         ( 
                                                inserted."CreatedDate" IS NULL 
                                     AND        deleted."CreatedDate" IS NOT NULL) 
                          OR         ( 
                                                inserted."CreatedDate" IS NOT NULL 
                                     AND        deleted."CreatedDate" IS NULL)) 
               OR         (( 
                                                inserted."CreatedBy" IS NOT NULL 
                                     AND        deleted."CreatedBy" IS NOT NULL 
                                     AND        inserted."CreatedBy"<>deleted."CreatedBy") 
                          OR         ( 
                                                inserted."CreatedBy" IS NULL 
                                     AND        deleted."CreatedBy" IS NOT NULL) 
                          OR         ( 
                                                inserted."CreatedBy" IS NOT NULL 
                                     AND        deleted."CreatedBy" IS NULL)) 
               OR         (( 
                                                inserted."ModifiedDate" IS NOT NULL 
                                     AND        deleted."ModifiedDate" IS NOT NULL 
                                     AND        inserted."ModifiedDate"<>deleted."ModifiedDate")
                          OR         ( 
                                                inserted."ModifiedDate" IS NULL 
                                     AND        deleted."ModifiedDate" IS NOT NULL) 
                          OR         ( 
                                                inserted."ModifiedDate" IS NOT NULL 
                                     AND        deleted."ModifiedDate" IS NULL)) 
               OR         (( 
                                                inserted."ModifiedBy" IS NOT NULL 
                                     AND        deleted."ModifiedBy" IS NOT NULL 
                                     AND        inserted."ModifiedBy"<>deleted."ModifiedBy") 
                          OR         ( 
                                                inserted."ModifiedBy" IS NULL 
                                     AND        deleted."ModifiedBy" IS NOT NULL) 
                          OR         ( 
                                                inserted."ModifiedBy" IS NOT NULL 
                                     AND        deleted."ModifiedBy" IS NULL)) 
               OR         (( 
                                                inserted."DeletedDate" IS NOT NULL 
                                     AND        deleted."DeletedDate" IS NOT NULL 
                                     AND        inserted."DeletedDate"<>deleted."DeletedDate") 
                          OR         ( 
                                                inserted."DeletedDate" IS NULL 
                                     AND        deleted."DeletedDate" IS NOT NULL) 
                          OR         ( 
                                                inserted."DeletedDate" IS NOT NULL 
                                     AND        deleted."DeletedDate" IS NULL)) 
               OR         (( 
                                                inserted."DeletedBy" IS NOT NULL 
                                     AND        deleted."DeletedBy" IS NOT NULL 
                                     AND        inserted."DeletedBy"<>deleted."DeletedBy") 
                          OR         ( 
                                                inserted."DeletedBy" IS NULL 
                                     AND        deleted."DeletedBy" IS NOT NULL) 
                          OR         ( 
                                                inserted."DeletedBy" IS NOT NULL 
                                     AND        deleted."DeletedBy" IS NULL))) 
  END 
END 
IF (@NCT = 0) 
SET nocount OFF 
END
fixed_sql.txt (15,641 bytes)   

mkurz

2020-01-06 06:33

reporter   ~0001672

This prevents us from using 3.11.
One idea I had was to use something like:
"select .. from deleted as inserted, deleted as deleted " (sql allows multiple aliases)
But that decreases the performance, because it leads to a join. And if it's
correct in content has to be evaluated.

josh-a-hicks

2021-08-11 17:56

developer   ~0001982

Instead of $(curTriggerValue) can you use $(oldTriggerValue)? This should reference the deleted.customerid instead of the inserted.customerid

mkurz

2022-03-30 06:12

reporter   ~0002065

@josh-a-hicks
With usage of $(oldTriggerValue) the creation of the insert triggers fails. Reason The multi-part identifier "deleted.customerid" could not be bound.

With usage of $(newTriggerValue) the creation of the delete triggers fails. Reason The multi-part identifier "inserted.sym_row_id" could not be bound.

So when the creation of insert triggers works, delete fails and the opposite. Id did some research how to determine in a trigger if it's and insert, update or delete to set the oldTriggerValue or newTriggerValue depending the case, but first impressions do not look like a responsible solution.

elong

2022-04-12 13:08

developer   ~0002077

This a bug caused by code changes to handle updates to the primary key by converting the update into a combination of a delete and a insert. (Issues 0003901 and 0004611.) Variables like $(curTriggerValue) are processed for the DML type of the trigger, which is an update in this case. But since it is internally recording a delete and an insert, the variables need to be processed for those DML types instead.

pmarzullo

2022-07-13 16:53

developer   ~0002109

This has also been fixed for 3.11, 3.12 and 3.14.
Patches have been created for 3.11 3.12 and 3.13
https://www.jumpmind.com/downloads/symmetricds/patches/3.13/patch-0004201.jar
https://www.jumpmind.com/downloads/symmetricds/patches/3.12/patch-0004201.jar
https://www.jumpmind.com/downloads/symmetricds/patches/3.11/patch-0004201.jar

Related Changesets

SymmetricDS: 3.11 708f3ff9

2022-07-13 15:58:03

pmarzullo

Details Diff
0004201: Failed to create update trigger for triggers that use and
external_select with $(curTriggerValue)
Affected Issues
0004201
mod - symmetric-client/src/main/java/org/jumpmind/symmetric/db/ase/AseTriggerTemplate.java Diff File
mod - symmetric-client/src/main/java/org/jumpmind/symmetric/db/mssql/MsSqlTriggerTemplate.java Diff File
mod - symmetric-core/src/main/java/org/jumpmind/symmetric/db/AbstractTriggerTemplate.java Diff File

SymmetricDS: 3.12 9f635e88

2022-07-13 16:05:05

pmarzullo

Details Diff
0004201: Failed to create update trigger for triggers that use and
external_select with $(curTriggerValue)
Affected Issues
0004201
mod - symmetric-client/src/main/java/org/jumpmind/symmetric/db/ase/AseTriggerTemplate.java Diff File
mod - symmetric-client/src/main/java/org/jumpmind/symmetric/db/mssql/MsSqlTriggerTemplate.java Diff File
mod - symmetric-core/src/main/java/org/jumpmind/symmetric/db/AbstractTriggerTemplate.java Diff File

SymmetricDS: 3.13 e37808e6

2022-07-13 16:05:05

pmarzullo

Details Diff
0004201: Failed to create update trigger for triggers that use and
external_select with $(curTriggerValue)
# Conflicts:
# symmetric-client/src/main/java/org/jumpmind/symmetric/db/ase/AseTriggerTemplate.java
# symmetric-core/src/main/java/org/jumpmind/symmetric/db/AbstractTriggerTemplate.java
Affected Issues
0004201
mod - symmetric-client/src/main/java/org/jumpmind/symmetric/db/ase/AseTriggerTemplate.java Diff File
mod - symmetric-client/src/main/java/org/jumpmind/symmetric/db/mssql/MsSqlTriggerTemplate.java Diff File
mod - symmetric-core/src/main/java/org/jumpmind/symmetric/db/AbstractTriggerTemplate.java Diff File

SymmetricDS: 3.14 535090fd

2022-07-13 16:15:34

pmarzullo

Details Diff
0004201: Failed to create update trigger for triggers that use and
external_select with $(curTriggerValue)
Affected Issues
0004201
mod - symmetric-client/src/main/java/org/jumpmind/symmetric/db/ase/AseTriggerTemplate.java Diff File
mod - symmetric-client/src/main/java/org/jumpmind/symmetric/db/mssql/MsSqlTriggerTemplate.java Diff File
mod - symmetric-core/src/main/java/org/jumpmind/symmetric/db/AbstractTriggerTemplate.java Diff File

Issue History

Date Modified Username Field Change
2019-12-12 10:31 mkurz New Issue
2019-12-12 10:31 mkurz File Added: central_3.11_log_snippet.log
2019-12-12 10:31 mkurz File Added: failing_sql.txt
2019-12-12 10:31 mkurz File Added: fixed_sql.txt
2020-01-06 06:33 mkurz Note Added: 0001672
2020-05-22 18:13 elong Target Version => 3.11.10
2020-05-22 18:13 elong Description Updated View Revisions
2020-06-24 20:14 elong Target Version 3.11.10 => 3.12.2
2020-07-20 13:06 elong Target Version 3.12.2 => 3.12.3
2020-07-22 16:41 elong Tag Attached: dialect: sql-server
2020-07-22 16:41 elong Tag Attached: trigger
2020-07-22 17:34 elong Status new => acknowledged
2020-07-22 17:34 elong Product Version 3.11.2 => 3.11.0
2020-08-31 19:47 elong Target Version 3.12.3 => 3.12.4
2020-09-23 15:32 admin Target Version 3.12.4 => 3.12.5
2020-11-09 13:45 admin Target Version 3.12.5 => 3.12.6
2021-01-08 20:42 admin Target Version 3.12.6 => 3.12.7
2021-02-25 13:01 admin Target Version 3.12.7 => 3.12.8
2021-03-30 19:13 admin Target Version 3.12.8 => 3.12.9
2021-04-28 14:41 admin Target Version 3.12.9 => 3.12.10
2021-05-28 11:54 admin Target Version 3.12.10 => 3.12.11
2021-07-13 12:43 admin Target Version 3.12.11 => 3.12.12
2021-08-11 17:56 josh-a-hicks Note Added: 0001982
2021-11-03 12:11 elong Target Version 3.12.12 => 3.12.13
2021-12-11 17:11 admin Target Version 3.12.13 => 3.12.14
2021-12-20 13:55 admin Target Version 3.12.14 => 3.12.15
2022-01-13 13:32 elong Target Version 3.12.15 => 3.14.0
2022-03-30 06:12 mkurz Note Added: 0002065
2022-04-12 13:08 elong Note Added: 0002077
2022-07-13 16:00 pmarzullo Changeset attached => SymmetricDS 3.11 708f3ff9
2022-07-13 16:51 pmarzullo Tag Attached: dialect: sybase
2022-07-13 16:51 pmarzullo Assigned To => pmarzullo
2022-07-13 16:51 pmarzullo Status acknowledged => assigned
2022-07-13 16:53 pmarzullo Status assigned => resolved
2022-07-13 16:53 pmarzullo Resolution open => fixed
2022-07-13 16:53 pmarzullo Fixed in Version => 3.13.7
2022-07-13 16:53 pmarzullo Note Added: 0002109
2022-07-13 17:00 pmarzullo Changeset attached => SymmetricDS 3.12 9f635e88
2022-07-13 17:00 pmarzullo Changeset attached => SymmetricDS 3.13 e37808e6
2022-07-13 17:00 pmarzullo Changeset attached => SymmetricDS 3.14 535090fd
2022-07-27 18:59 admin Status resolved => closed