From 611acb6a3722499a874476bc52e29e67636f5e15 Mon Sep 17 00:00:00 2001 From: y-ono-r <95060536+y-ono-r@users.noreply.github.com> Date: Thu, 21 Jul 2022 09:31:40 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=E4=B8=80=E6=99=82=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=83=96=E3=83=AB=E5=90=8D=E3=81=AE=E5=A4=89=E6=9B=B4=E3=80=81?= =?UTF-8?q?=E7=B4=B0=E3=81=8B=E3=81=84=E3=83=9F=E3=82=B9=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rds_mysql/stored_procedure/crm_history.sql | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rds_mysql/stored_procedure/crm_history.sql b/rds_mysql/stored_procedure/crm_history.sql index a83cc581..f361a850 100644 --- a/rds_mysql/stored_procedure/crm_history.sql +++ b/rds_mysql/stored_procedure/crm_history.sql @@ -8,19 +8,19 @@ BEGIN BEGIN GET DIAGNOSTICS CONDITION 1 @error_state = RETURNED_SQLSTATE, @error_msg = MESSAGE_TEXT; - EXECUTE drop_tmp_table; - DEALLOCATE PREPARE drop_tmp_table; + EXECUTE drop_tmp_table_stmt; + DEALLOCATE PREPARE drop_tmp_table_stmt; SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = @error_msg, MYSQL_ERRNO = @error_state; + SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg; END; -- ②-3で利用する一時テーブル削除のSQLを準備 -- 例外処理でも利用するため先に記述 SET @drop_tmp_table = ' - DROP TEMPORARY TABLE IF EXISTS make_history_tmp_$$target_table + DROP TEMPORARY TABLE IF EXISTS $$target_table_make_history_tmp '; SET @drop_tmp_table = REPLACE(@drop_tmp_table, "$$target_table", target_table); - PREPARE new_history_save_stmt from @drop_tmp_table; + PREPARE drop_tmp_table_stmt from @drop_tmp_table; -- ①-1 Salesforce側で更新されたデータの適用開始日時と適用終了日時を設定する SET @new_history_save = ' @@ -38,11 +38,11 @@ BEGIN SET @new_history_save = REPLACE(@new_history_save, "$$target_column", target_column); PREPARE new_history_save_stmt from @new_history_save; EXECUTE new_history_save_stmt; - DEALLOCATE PREPARE ew_history_save_stmt; + DEALLOCATE PREPARE new_history_save_stmt; -- ②-1 Salesforce側で更新されたデータを検出用一時テーブルの作成 SET @make_history_tmp_create = ' - CREATE TEMPORARY TABLE make_history_tmp_$$target_table + CREATE TEMPORARY TABLE $$target_table_make_history_tmp SELECT id , MIN($$target_column) AS min_start_datetime @@ -65,7 +65,7 @@ BEGIN -- ②-2 「②-1」で取得した全件に更新処理を行う SET @update_end_datetime = ' UPDATE $$target_table tt - LEFT JOIN make_history_tmp_$$target_table mht + LEFT JOIN $$target_table_make_history_tmp mht ON tt.id = mht.id AND tt.start_datetime = mht.min_start_datetime SET @@ -82,7 +82,7 @@ BEGIN DEALLOCATE PREPARE update_end_datetime_stmt; -- ②-3 「②-1」で作成した一時テーブルを削除する - EXECUTE drop_tmp_table; - DEALLOCATE PREPARE drop_tmp_table; + EXECUTE drop_tmp_table_stmt; + DEALLOCATE PREPARE drop_tmp_table_stmt; END \ No newline at end of file