fix:SQLシンタックスエラー対応

This commit is contained in:
野間 2023-08-24 10:45:12 +09:00
parent 2f23f0b9c9
commit c90d3e0fec
4 changed files with 28 additions and 34 deletions

View File

@ -101,6 +101,9 @@ class BioSalesLotRepository(BaseRepository):
def __build_condition(self, parameter: BioModel):
where_clauses: list[SQLCondition] = []
# 無条件対応(常に真)
where_clauses.append(SQLCondition('', '', '1 = 1', literal=True))
# 卸(コード/サブコード)
if is_not_empty(parameter.rec_whs_cd) and is_not_empty(parameter.rec_whs_sub_cd):
where_clauses.append(SQLCondition('rec_whs_cd', condition.EQ, 'rec_whs_cd'))
@ -141,5 +144,6 @@ class BioSalesLotRepository(BaseRepository):
where_clauses.append(SQLCondition('LENGTH(TRIM(rec_lot_num))', condition.GT, '0', literal=True))
where_clauses_str = ' AND '.join([condition.apply() for condition in where_clauses])
logger.debug(f'条件設定終了:{where_clauses_str}')
return where_clauses_str

View File

@ -13,7 +13,7 @@ class EmpChgInstRepository(BaseRepository):
def connect(self):
self._database.connect()
def to_jst(self):
self._database.to_jst()
@ -179,11 +179,11 @@ class EmpChgInstRepository(BaseRepository):
FROM
{table_name} AS eci
LEFT JOIN mst_inst AS mi
ON eci.inst_cd = mi.inst_cd
ON eci.inst_cd = mi.inst_cd
LEFT JOIN emp
ON eci.emp_cd = emp.emp_cd
ON eci.emp_cd = emp.emp_cd
LEFT JOIN bu
ON eci.bu_cd = bu.bu_cd
ON eci.bu_cd = bu.bu_cd
WHERE
{where_clause}
"""
@ -206,6 +206,9 @@ class EmpChgInstRepository(BaseRepository):
def __build_condition(self, parameter: MasterMainteCsvDlModel):
where_clauses: list[SQLCondition] = []
# 無条件対応(常に真)
where_clauses.append(SQLCondition('', '', '1 = 1', literal=True))
# 領域コードが入力されていた場合
if is_not_empty(parameter.ta_cd):
parameter.adapt_ta_cd = f'%{parameter.ta_cd}%'
@ -223,62 +226,43 @@ class EmpChgInstRepository(BaseRepository):
# 適用期間内が入力されていた場合
if is_not_empty(parameter.adapt_apply_date_from):
where_clauses.append(SQLCondition('eci.start_date',
condition.LE,
'adapt_apply_date_from'))
where_clauses.append(SQLCondition('eci.end_date',
condition.GE,
'adapt_apply_date_from'))
where_clauses.append(SQLCondition('eci.start_date', condition.LE, 'adapt_apply_date_from'))
where_clauses.append(SQLCondition('eci.end_date', condition.GE, 'adapt_apply_date_from'))
# 適用開始日FROMが入力されていた場合
if is_not_empty(parameter.adapt_start_date_from):
where_clauses.append(SQLCondition('eci.start_date',
condition.GE,
'adapt_start_date_from'))
where_clauses.append(SQLCondition('eci.start_date', condition.GE, 'adapt_start_date_from'))
# 適用開始日TOが入力されていた場合
if is_not_empty(parameter.adapt_start_date_to):
where_clauses.append(SQLCondition('eci.start_date',
condition.LE,
'adapt_start_date_to'))
where_clauses.append(SQLCondition('eci.start_date', condition.LE, 'adapt_start_date_to'))
# 適用終了日FROMが入力されていた場合
if is_not_empty(parameter.adapt_end_date_from):
where_clauses.append(SQLCondition('eci.end_date',
condition.GE,
'adapt_end_date_from'))
where_clauses.append(SQLCondition('eci.end_date', condition.GE, 'adapt_end_date_from'))
# 適用終了日TOが入力されていた場合
if is_not_empty(parameter.adapt_end_date_to):
where_clauses.append(SQLCondition('eci.end_date',
condition.LE,
'adapt_end_date_to'))
where_clauses.append(SQLCondition('eci.end_date', condition.LE, 'adapt_end_date_to'))
# データ作成日FROMが入力されていた場合
if is_not_empty(parameter.adapt_create_date_from):
where_clauses.append(SQLCondition('eci.create_date',
condition.GE,
'adapt_create_date_from'))
where_clauses.append(SQLCondition('eci.create_date', condition.GE, 'adapt_create_date_from'))
# データ作成日TOが入力されていた場合
if is_not_empty(parameter.adapt_create_date_to):
where_clauses.append(SQLCondition('eci.create_date',
condition.LE,
'adapt_create_date_to'))
where_clauses.append(SQLCondition('eci.create_date', condition.LE, 'adapt_create_date_to'))
# データ更新日FROMが入力されていた場合
if is_not_empty(parameter.adapt_update_date_from):
where_clauses.append(SQLCondition('eci.update_date',
condition.GE,
'adapt_update_date_from'))
where_clauses.append(SQLCondition('eci.update_date', condition.GE, 'adapt_update_date_from'))
# データ更新日TOが入力されていた場合
if is_not_empty(parameter.adapt_update_date_to):
where_clauses.append(SQLCondition('eci.update_date',
condition.LE,
'adapt_update_date_to'))
where_clauses.append(SQLCondition('eci.update_date', condition.LE, 'adapt_update_date_to'))
where_clauses_str = ' AND '.join([condition.apply() for condition in where_clauses])
logger.debug(f'条件設定終了:{where_clauses_str}')
return where_clauses_str

View File

@ -72,6 +72,9 @@ class UltmarcDoctorRepository(BaseRepository):
def __build_condition(self, parameter: UltmarcDoctorSearchModel):
where_clauses: list[SQLCondition] = []
# 無条件対応(常に真)
where_clauses.append(SQLCondition('', '', '1 = 1', literal=True))
# 医師コード
if is_not_empty(parameter.dcf_pcf_dr_cd):
# 必ず部分一致で検索

View File

@ -58,6 +58,9 @@ class UltmarcInstRepository(BaseRepository):
def __build_condition(self, parameter: UltmarcInstSearchModel):
where_clauses: list[SQLCondition] = []
# 無条件対応(常に真)
where_clauses.append(SQLCondition('', '', '1 = 1', literal=True))
# ULT施設コード
if is_not_empty(parameter.dcf_dsf_inst_cd):
# 部分一致検索