From de2955a24feb0a3c7204f9a07a224c2ad7828fa3 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Mon, 23 Oct 2023 15:50:48 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=AB=EF=BC=92?= =?UTF-8?q?=E3=82=AD=E3=83=BC=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=A2=E3=83=89=E3=83=97=E3=83=AD=E3=82=B7?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=83=A3=E3=81=AE=E6=9C=80=E5=88=9D=E3=83=97?= =?UTF-8?q?=E3=83=83=E3=82=B7=E3=83=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._distribution_Call2_Key_Message_vod__c.sql | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql diff --git a/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql b/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql new file mode 100644 index 00000000..bde36950 --- /dev/null +++ b/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql @@ -0,0 +1,105 @@ +CREATE PROCEDURE `internal02`.`crm_distribution_Call2_Key_Message_vod__c`() +SQL SECURITY INVOKER +BEGIN + +-- 振り分けスキーマ +DECLARE distribution_schema VARCHAR(64); +-- 振り分けカラム +DECLARE target_column_value VARCHAR(64); +-- 振り分け先テーブルID +DECLARE temp_table_id VARCHAR(18); +-- カーソルフェッチステータス +DECLARE fetch_done BOOLEAN DEFAULT FALSE; + +-- カーソル設定 +DECLARE table_cursor CURSOR FOR SELECT Id, medaca_parent_record_type_id FROM internal02.crm_Call2_Key_Message_vod__c; +DECLARE CONTINUE HANDLER FOR NOT FOUND SET fetch_done = TRUE; + +-- エラー処理 +DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + GET DIAGNOSTICS CONDITION 1 + @error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT; + ROLLBACK; + SET @error_msg = ( + CASE + WHEN LENGTH(@error_msg) > 128 THEN CONCAT(SUBSTRING(@error_msg, 1, 125), '...') + ELSE @error_msg + END + ); + SIGNAL SQLSTATE '45000' + SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg; + END; + +START TRANSACTION; + +-- UPSERT STATEMENT設定 +SET @upsert_statement_base = + 'INSERT INTO $$distribution_schema$$.crm_Call2_Key_Message_vod__c + (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, + MayEdit, IsLocked, Account_vod__c, Call2_vod__c, Reaction_vod__c, Product_vod__c, Key_Message_vod__c, + Mobile_ID_vod__c, Contact_vod__c, Call_Date_vod__c, User_vod__c, Category_vod__c, Vehicle_vod__c, + Is_Parent_Call_vod__c, Override_Lock_vod__c, CLM_ID_vod__c, Slide_Version_vod__c, Duration_vod__c, + Presentation_ID_vod__c, Start_Time_vod__c, Attendee_Type_vod__c, Entity_Reference_Id_vod__c, Segment_vod__c, + Display_Order_vod__c, Clm_Presentation_Name_vod__c, Clm_Presentation_Version_vod__c, Clm_Presentation_vod__c, + file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) + SELECT + Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, + MayEdit, IsLocked, Account_vod__c, Call2_vod__c, Reaction_vod__c, Product_vod__c, Key_Message_vod__c, + Mobile_ID_vod__c, Contact_vod__c, Call_Date_vod__c, User_vod__c, Category_vod__c, Vehicle_vod__c, + Is_Parent_Call_vod__c, Override_Lock_vod__c, CLM_ID_vod__c, Slide_Version_vod__c, Duration_vod__c, + Presentation_ID_vod__c, Start_Time_vod__c, Attendee_Type_vod__c, Entity_Reference_Id_vod__c, Segment_vod__c, + Display_Order_vod__c, Clm_Presentation_Name_vod__c, Clm_Presentation_Version_vod__c, Clm_Presentation_vod__c, + file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date + FROM + internal02.crm_Call2_Key_Message_vod__c AS internaltb + WHERE + internaltb.Id = ? + ON DUPLICATE KEY UPDATE + IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate, + CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate, + LastModifiedById = internaltb.LastModifiedById, SystemModstamp = internaltb.SystemModstamp, + MayEdit = internaltb.MayEdit, IsLocked = internaltb.IsLocked, Account_vod__c = internaltb.Account_vod__c, + Call2_vod__c = internaltb.Call2_vod__c, Reaction_vod__c = internaltb.Reaction_vod__c, + Product_vod__c = internaltb.Product_vod__c, Key_Message_vod__c = internaltb.Key_Message_vod__c, + Mobile_ID_vod__c = internaltb.Mobile_ID_vod__c, Contact_vod__c = internaltb.Contact_vod__c, + Call_Date_vod__c = internaltb.Call_Date_vod__c, User_vod__c = internaltb.User_vod__c, + Category_vod__c = internaltb.Category_vod__c, Vehicle_vod__c = internaltb.Vehicle_vod__c, + Is_Parent_Call_vod__c = internaltb.Is_Parent_Call_vod__c, Override_Lock_vod__c = internaltb.Override_Lock_vod__c, + CLM_ID_vod__c = internaltb.CLM_ID_vod__c, Slide_Version_vod__c = internaltb.Slide_Version_vod__c, + Duration_vod__c = internaltb.Duration_vod__c, Presentation_ID_vod__c = internaltb.Presentation_ID_vod__c, + Start_Time_vod__c = internaltb.Start_Time_vod__c, Attendee_Type_vod__c = internaltb.Attendee_Type_vod__c, + Entity_Reference_Id_vod__c = internaltb.Entity_Reference_Id_vod__c, Segment_vod__c = internaltb.Segment_vod__c, + Display_Order_vod__c = internaltb.Display_Order_vod__c, Clm_Presentation_Name_vod__c = internaltb.Clm_Presentation_Name_vod__c, + Clm_Presentation_Version_vod__c = internaltb.Clm_Presentation_Version_vod__c, + Clm_Presentation_vod__c = internaltb.Clm_Presentation_vod__c, file_name = internaltb.file_name, + file_row_cnt = internaltb.file_row_cnt, delete_flg = internaltb.delete_flg, ins_user = internaltb.ins_user, + ins_date = internaltb.ins_date, upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP();'; + +OPEN table_cursor; + +-- ループ +TableCursorLoop: LOOP + -- スキーマ取得 + FETCH table_cursor INTO temp_table_id, target_column_value; + + -- 終了条件ループ抜き + IF fetch_done THEN + LEAVE TableCursorLoop; + END IF; + + SET @distribution_schema = get_distribution_to_schema('crm_Call2_Key_Message_vod__c', 'medaca_parent_record_type_id', target_column_value); + SET @temp_table_id = temp_table_id; + + SET @upsert_statement = REPLACE(@upsert_statement_base, "$$distribution_schema$$", @distribution_schema); + + -- UPSERT実行 + PREPARE stmt FROM @upsert_statement; + EXECUTE stmt USING @temp_table_id; + DEALLOCATE PREPARE stmt; + +END LOOP; +CLOSE table_cursor; +COMMIT; + +END \ No newline at end of file From 36617a657fb73e43f90af08609017311e4426fe3 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Mon, 23 Oct 2023 16:19:42 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E5=89=8A=E9=99=A4=E3=83=95=E3=83=A9?= =?UTF-8?q?=E3=82=B0(delete=5Fflg)=E3=80=81=E7=99=BB=E9=8C=B2=E8=80=85(ins?= =?UTF-8?q?=5Fuser)=E3=80=81=E7=99=BB=E9=8C=B2=E6=97=A5=E6=99=82(ins=5Fdat?= =?UTF-8?q?e)UPDATE=E3=81=8B=E3=82=89=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal02/crm_distribution_Call2_Key_Message_vod__c.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql b/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql index bde36950..31792948 100644 --- a/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql +++ b/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql @@ -73,8 +73,7 @@ SET @upsert_statement_base = Display_Order_vod__c = internaltb.Display_Order_vod__c, Clm_Presentation_Name_vod__c = internaltb.Clm_Presentation_Name_vod__c, Clm_Presentation_Version_vod__c = internaltb.Clm_Presentation_Version_vod__c, Clm_Presentation_vod__c = internaltb.Clm_Presentation_vod__c, file_name = internaltb.file_name, - file_row_cnt = internaltb.file_row_cnt, delete_flg = internaltb.delete_flg, ins_user = internaltb.ins_user, - ins_date = internaltb.ins_date, upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP();'; + file_row_cnt = internaltb.file_row_cnt, upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP();'; OPEN table_cursor; From 7fa147ff8a8ecf227c994f90b44fba39da1e82e6 Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Thu, 26 Oct 2023 13:57:45 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E3=83=AC=E3=83=93=E3=83=A5?= =?UTF-8?q?=E3=83=BC=E6=8C=87=E6=91=98=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._distribution_Call2_Key_Message_vod__c.sql | 86 ++++++++++--------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql b/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql index 31792948..3fcaae7f 100644 --- a/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql +++ b/rds_mysql/stored_procedure/internal02/crm_distribution_Call2_Key_Message_vod__c.sql @@ -1,11 +1,15 @@ +-- A5M2で実行時に[SQL] - [スラッシュ(/)のみの行でSQLを区切る]に変えてから実行する +-- $$から始まる文字は後からREPLACEする文字を示す独自ルール +-- 当プロシージャは、同一セッション内での並列処理を実行することができない +-- 実行者の権限でストアドプロシージャを実行するために、「SQL SECURITY INVOKER」を付与している CREATE PROCEDURE `internal02`.`crm_distribution_Call2_Key_Message_vod__c`() SQL SECURITY INVOKER BEGIN -- 振り分けスキーマ -DECLARE distribution_schema VARCHAR(64); +DECLARE distribution_schema VARCHAR(20); -- 振り分けカラム -DECLARE target_column_value VARCHAR(64); +DECLARE target_column_value VARCHAR(100); -- 振り分け先テーブルID DECLARE temp_table_id VARCHAR(18); -- カーソルフェッチステータス @@ -16,7 +20,7 @@ DECLARE table_cursor CURSOR FOR SELECT Id, medaca_parent_record_type_id FROM int DECLARE CONTINUE HANDLER FOR NOT FOUND SET fetch_done = TRUE; -- エラー処理 -DECLARE EXIT HANDLER FOR SQLEXCEPTION +DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN GET DIAGNOSTICS CONDITION 1 @error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT; @@ -34,45 +38,45 @@ DECLARE EXIT HANDLER FOR SQLEXCEPTION START TRANSACTION; -- UPSERT STATEMENT設定 -SET @upsert_statement_base = - 'INSERT INTO $$distribution_schema$$.crm_Call2_Key_Message_vod__c - (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, - MayEdit, IsLocked, Account_vod__c, Call2_vod__c, Reaction_vod__c, Product_vod__c, Key_Message_vod__c, - Mobile_ID_vod__c, Contact_vod__c, Call_Date_vod__c, User_vod__c, Category_vod__c, Vehicle_vod__c, - Is_Parent_Call_vod__c, Override_Lock_vod__c, CLM_ID_vod__c, Slide_Version_vod__c, Duration_vod__c, - Presentation_ID_vod__c, Start_Time_vod__c, Attendee_Type_vod__c, Entity_Reference_Id_vod__c, Segment_vod__c, - Display_Order_vod__c, Clm_Presentation_Name_vod__c, Clm_Presentation_Version_vod__c, Clm_Presentation_vod__c, +SET @upsert_statement_base = + 'INSERT INTO $$distribution_schema$$.crm_Call2_Key_Message_vod__c + (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, + MayEdit, IsLocked, Account_vod__c, Call2_vod__c, Reaction_vod__c, Product_vod__c, Key_Message_vod__c, + Mobile_ID_vod__c, Contact_vod__c, Call_Date_vod__c, User_vod__c, Category_vod__c, Vehicle_vod__c, + Is_Parent_Call_vod__c, Override_Lock_vod__c, CLM_ID_vod__c, Slide_Version_vod__c, Duration_vod__c, + Presentation_ID_vod__c, Start_Time_vod__c, Attendee_Type_vod__c, Entity_Reference_Id_vod__c, Segment_vod__c, + Display_Order_vod__c, Clm_Presentation_Name_vod__c, Clm_Presentation_Version_vod__c, Clm_Presentation_vod__c, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) - SELECT - Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, - MayEdit, IsLocked, Account_vod__c, Call2_vod__c, Reaction_vod__c, Product_vod__c, Key_Message_vod__c, - Mobile_ID_vod__c, Contact_vod__c, Call_Date_vod__c, User_vod__c, Category_vod__c, Vehicle_vod__c, - Is_Parent_Call_vod__c, Override_Lock_vod__c, CLM_ID_vod__c, Slide_Version_vod__c, Duration_vod__c, - Presentation_ID_vod__c, Start_Time_vod__c, Attendee_Type_vod__c, Entity_Reference_Id_vod__c, Segment_vod__c, - Display_Order_vod__c, Clm_Presentation_Name_vod__c, Clm_Presentation_Version_vod__c, Clm_Presentation_vod__c, + SELECT + Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, + MayEdit, IsLocked, Account_vod__c, Call2_vod__c, Reaction_vod__c, Product_vod__c, Key_Message_vod__c, + Mobile_ID_vod__c, Contact_vod__c, Call_Date_vod__c, User_vod__c, Category_vod__c, Vehicle_vod__c, + Is_Parent_Call_vod__c, Override_Lock_vod__c, CLM_ID_vod__c, Slide_Version_vod__c, Duration_vod__c, + Presentation_ID_vod__c, Start_Time_vod__c, Attendee_Type_vod__c, Entity_Reference_Id_vod__c, Segment_vod__c, + Display_Order_vod__c, Clm_Presentation_Name_vod__c, Clm_Presentation_Version_vod__c, Clm_Presentation_vod__c, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date - FROM - internal02.crm_Call2_Key_Message_vod__c AS internaltb - WHERE + FROM + internal02.crm_Call2_Key_Message_vod__c AS internaltb + WHERE internaltb.Id = ? - ON DUPLICATE KEY UPDATE - IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate, - CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate, - LastModifiedById = internaltb.LastModifiedById, SystemModstamp = internaltb.SystemModstamp, - MayEdit = internaltb.MayEdit, IsLocked = internaltb.IsLocked, Account_vod__c = internaltb.Account_vod__c, - Call2_vod__c = internaltb.Call2_vod__c, Reaction_vod__c = internaltb.Reaction_vod__c, - Product_vod__c = internaltb.Product_vod__c, Key_Message_vod__c = internaltb.Key_Message_vod__c, - Mobile_ID_vod__c = internaltb.Mobile_ID_vod__c, Contact_vod__c = internaltb.Contact_vod__c, - Call_Date_vod__c = internaltb.Call_Date_vod__c, User_vod__c = internaltb.User_vod__c, - Category_vod__c = internaltb.Category_vod__c, Vehicle_vod__c = internaltb.Vehicle_vod__c, - Is_Parent_Call_vod__c = internaltb.Is_Parent_Call_vod__c, Override_Lock_vod__c = internaltb.Override_Lock_vod__c, - CLM_ID_vod__c = internaltb.CLM_ID_vod__c, Slide_Version_vod__c = internaltb.Slide_Version_vod__c, - Duration_vod__c = internaltb.Duration_vod__c, Presentation_ID_vod__c = internaltb.Presentation_ID_vod__c, - Start_Time_vod__c = internaltb.Start_Time_vod__c, Attendee_Type_vod__c = internaltb.Attendee_Type_vod__c, - Entity_Reference_Id_vod__c = internaltb.Entity_Reference_Id_vod__c, Segment_vod__c = internaltb.Segment_vod__c, - Display_Order_vod__c = internaltb.Display_Order_vod__c, Clm_Presentation_Name_vod__c = internaltb.Clm_Presentation_Name_vod__c, - Clm_Presentation_Version_vod__c = internaltb.Clm_Presentation_Version_vod__c, - Clm_Presentation_vod__c = internaltb.Clm_Presentation_vod__c, file_name = internaltb.file_name, + ON DUPLICATE KEY UPDATE + IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate, + CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate, + LastModifiedById = internaltb.LastModifiedById, SystemModstamp = internaltb.SystemModstamp, + MayEdit = internaltb.MayEdit, IsLocked = internaltb.IsLocked, Account_vod__c = internaltb.Account_vod__c, + Call2_vod__c = internaltb.Call2_vod__c, Reaction_vod__c = internaltb.Reaction_vod__c, + Product_vod__c = internaltb.Product_vod__c, Key_Message_vod__c = internaltb.Key_Message_vod__c, + Mobile_ID_vod__c = internaltb.Mobile_ID_vod__c, Contact_vod__c = internaltb.Contact_vod__c, + Call_Date_vod__c = internaltb.Call_Date_vod__c, User_vod__c = internaltb.User_vod__c, + Category_vod__c = internaltb.Category_vod__c, Vehicle_vod__c = internaltb.Vehicle_vod__c, + Is_Parent_Call_vod__c = internaltb.Is_Parent_Call_vod__c, Override_Lock_vod__c = internaltb.Override_Lock_vod__c, + CLM_ID_vod__c = internaltb.CLM_ID_vod__c, Slide_Version_vod__c = internaltb.Slide_Version_vod__c, + Duration_vod__c = internaltb.Duration_vod__c, Presentation_ID_vod__c = internaltb.Presentation_ID_vod__c, + Start_Time_vod__c = internaltb.Start_Time_vod__c, Attendee_Type_vod__c = internaltb.Attendee_Type_vod__c, + Entity_Reference_Id_vod__c = internaltb.Entity_Reference_Id_vod__c, Segment_vod__c = internaltb.Segment_vod__c, + Display_Order_vod__c = internaltb.Display_Order_vod__c, Clm_Presentation_Name_vod__c = internaltb.Clm_Presentation_Name_vod__c, + Clm_Presentation_Version_vod__c = internaltb.Clm_Presentation_Version_vod__c, + Clm_Presentation_vod__c = internaltb.Clm_Presentation_vod__c, file_name = internaltb.file_name, file_row_cnt = internaltb.file_row_cnt, upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP();'; OPEN table_cursor; @@ -87,9 +91,9 @@ TableCursorLoop: LOOP LEAVE TableCursorLoop; END IF; - SET @distribution_schema = get_distribution_to_schema('crm_Call2_Key_Message_vod__c', 'medaca_parent_record_type_id', target_column_value); + SET @distribution_schema = internal02.get_distribution_to_schema('crm_Call2_Key_Message_vod__c', 'medaca_parent_record_type_id', target_column_value); SET @temp_table_id = temp_table_id; - + SET @upsert_statement = REPLACE(@upsert_statement_base, "$$distribution_schema$$", @distribution_schema); -- UPSERT実行