LOADの実行結果のワーニングをキャッチして例外で落とす処理を実装

This commit is contained in:
x.azuma.m@nds-tyo.co.jp 2023-06-23 20:03:37 +09:00
parent 7a9293187f
commit d285a28c96
2 changed files with 10 additions and 8 deletions

View File

@ -35,17 +35,18 @@ class VjskDataLoadManager:
ENCLOSED BY '\"'
IGNORE 1 LINES;
"""
db.begin()
result = db.execute(sql, {"src_file_name": src_file_name})
logger.debug(sql)
# MEMO : sqlalchemy(engine=pymysql)としたときの result.context.cursor は、engineに依存してクラスが異なる
# https://nds-tyo.backlog.com/view/NEWDWH2021-1006#comment-266127218
if result.context.cursor._result.warning_count > 0:
result_w = db.execute("SHOW WARNINGS;")
for row in result_w.fetchall():
logger.info(f"SHOW WARNINGS : {row}")
result_w = db.execute("SHOW WARNINGS;")
has_mysql_warnings = False
for row in result_w.fetchall():
has_mysql_warnings = True
logger.info(f"SHOW WARNINGS : {row}")
if has_mysql_warnings:
raise Exception("LOAD文実行時にWARNINGが発生しました。")
logger.debug(sql)
logger.info(f'{data_name}tsvファイルを{table_name_org}にLOAD : 件数({result.rowcount})')
db.commit()
# org→srcにinsert select
db.begin()

View File

@ -35,6 +35,7 @@ class TestImportFileToDb:
self.db = database
self.db.connect()
self.db.execute("set sql_mode = 'TRADITIONAL';")
# self.db.begin()
# testing