|
@@ -3,7 +3,6 @@ from collections import namedtuple
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
from re import escape
|
|
from re import escape
|
|
from numpy import select
|
|
from numpy import select
|
|
-
|
|
|
|
import pandas as pd
|
|
import pandas as pd
|
|
import plac
|
|
import plac
|
|
import pyodbc
|
|
import pyodbc
|
|
@@ -158,19 +157,14 @@ def create(config_file='dbtools/OPTIMA.json'):
|
|
select_columns = ''
|
|
select_columns = ''
|
|
for col in target_columns_list:
|
|
for col in target_columns_list:
|
|
if col in intersect:
|
|
if col in intersect:
|
|
- select_columns += f"T1.\"{col}\", "
|
|
|
|
|
|
+ select_columns += f"T1.[{col}], "
|
|
elif col == 'Client_DB':
|
|
elif col == 'Client_DB':
|
|
- select_columns += "'" + client_db + "' as \"Client_DB\", "
|
|
|
|
|
|
+ select_columns += "'" + client_db + "' as \\\"Client_DB\\\", "
|
|
else:
|
|
else:
|
|
- select_columns += "'' as \"" + col + "\", "
|
|
|
|
|
|
+ select_columns += "'' as \\\"" + col + "\\\", "
|
|
|
|
|
|
select_query = select_query.replace("T1.*", select_columns[:-2])
|
|
select_query = select_query.replace("T1.*", select_columns[:-2])
|
|
- select_query_file = f"{cfg.batch_dir}/query/{current_table['target']}.sql"
|
|
|
|
- with open(select_query_file, 'w', encoding='cp65001') as fwh:
|
|
|
|
- fwh.write(select_query)
|
|
|
|
-
|
|
|
|
select_query = select_query.replace("%", "%%") # batch-Problem
|
|
select_query = select_query.replace("%", "%%") # batch-Problem
|
|
- select_query = escape(select_query)
|
|
|
|
|
|
|
|
stage_csv = f"{cfg.stage_dir}\\{current_table['target']}_{client_db}.csv"
|
|
stage_csv = f"{cfg.stage_dir}\\{current_table['target']}_{client_db}.csv"
|
|
# insert_query = f"LOAD DATA INFILE '{stage_csv}' INTO TABLE {current_table['target']} FIELDS TERMINATED BY ','
|
|
# insert_query = f"LOAD DATA INFILE '{stage_csv}' INTO TABLE {current_table['target']} FIELDS TERMINATED BY ','
|
|
@@ -185,6 +179,8 @@ def create(config_file='dbtools/OPTIMA.json'):
|
|
f"-c -C 65001 -m 1000 -e \"{stage_csv[:-4]}.in.log\" > \"{stage_csv[:-4]}.bcp2.log\" \n")
|
|
f"-c -C 65001 -m 1000 -e \"{stage_csv[:-4]}.in.log\" > \"{stage_csv[:-4]}.bcp2.log\" \n")
|
|
f.write(f"type \"{stage_csv[:-4]}.bcp2.log\" | findstr -v \"1000\" \n")
|
|
f.write(f"type \"{stage_csv[:-4]}.bcp2.log\" | findstr -v \"1000\" \n")
|
|
|
|
|
|
|
|
+ f.write(f"del \"{stage_csv}\" /F >nul 2>nul \n")
|
|
|
|
+
|
|
with open(f"{cfg.batch_dir}/_{cfg.name}.bat", 'w', encoding='cp850') as f:
|
|
with open(f"{cfg.batch_dir}/_{cfg.name}.bat", 'w', encoding='cp850') as f:
|
|
f.write("@echo off & cd /d %~dp0 \n")
|
|
f.write("@echo off & cd /d %~dp0 \n")
|
|
f.write(f"del {cfg.stage_dir}\\*.* /Q /F >nul 2>nul \n\n")
|
|
f.write(f"del {cfg.stage_dir}\\*.* /Q /F >nul 2>nul \n\n")
|