|
@@ -3,7 +3,7 @@ import os
|
|
|
from itertools import count
|
|
|
from pathlib import Path
|
|
|
|
|
|
-from csv_column_types import get_column_types
|
|
|
+from cognos7.csv_column_types import get_column_types
|
|
|
|
|
|
col_type_convert = {
|
|
|
"varchar(20)": "to_varchar20",
|
|
@@ -64,7 +64,13 @@ def create_format_xml_files(base_dir: str, tables_with_columns: dict[str, list[s
|
|
|
record.append(
|
|
|
f' <FIELD ID="{i}" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>'
|
|
|
)
|
|
|
- col_name_escape = col_name.encode("ascii", "xmlcharrefreplace").decode()
|
|
|
+ col_name_escape = (
|
|
|
+ col_name.replace("&", "&")
|
|
|
+ .encode("ascii", "xmlcharrefreplace")
|
|
|
+ .decode()
|
|
|
+ .replace("<", "<")
|
|
|
+ .replace(">", ">")
|
|
|
+ )
|
|
|
row.append(f' <COLUMN SOURCE="{i}" NAME="{col_name_escape}" xsi:type="SQLVARYCHAR"/>')
|
|
|
record[-1] = record[-1].replace(";", "\\r\\n")
|
|
|
|
|
@@ -80,6 +86,7 @@ def create_format_xml_files(base_dir: str, tables_with_columns: dict[str, list[s
|
|
|
|
|
|
|
|
|
def create_format_xml_from_folder(base_dir: str) -> None:
|
|
|
+ system = Path(base_dir).parent.name
|
|
|
format_folder = f"{base_dir}\\Format"
|
|
|
os.makedirs(format_folder, exist_ok=True)
|
|
|
sql_folder = f"{base_dir}\\SQL"
|
|
@@ -93,8 +100,9 @@ def create_format_xml_from_folder(base_dir: str) -> None:
|
|
|
create_format_xml_files(format_folder, tables_with_columns)
|
|
|
create_openrowset_sql_files(base_dir, format_folder, sql_folder, tables_with_columns)
|
|
|
create_load_sql_files(sql_folder, tables_with_columns)
|
|
|
- create_drop_create_sql_files(sql_folder, tables_with_columns)
|
|
|
- create_update_sql_files(sql_folder, tables_with_columns)
|
|
|
+ create_drop_create_sql_files(sql_folder, tables_with_columns, system)
|
|
|
+ create_update_sql_files(sql_folder, tables_with_columns, system)
|
|
|
+ create_sql_bat_files(sql_folder)
|
|
|
|
|
|
|
|
|
def create_openrowset_sql_files(
|
|
@@ -179,20 +187,45 @@ def get_tables_with_columns_from_folder(base_dir: str) -> dict[str, list[str]]:
|
|
|
with open(csv_file, "r", encoding="latin-1") as frh:
|
|
|
cols = frh.readline().strip("\n").split(";")
|
|
|
cols_unique = []
|
|
|
+ cols_unique_lower = []
|
|
|
for c in cols:
|
|
|
c1 = c.strip('"')
|
|
|
- if c1 not in cols_unique:
|
|
|
+ if c1.lower() not in cols_unique_lower:
|
|
|
cols_unique.append(c1)
|
|
|
+ cols_unique_lower.append(c1.lower())
|
|
|
continue
|
|
|
for i in count(1):
|
|
|
c2 = f"{c1}_{i}"
|
|
|
- if c2 not in cols and c2 not in cols_unique:
|
|
|
+ if c2 not in cols and c2.lower() not in cols_unique_lower:
|
|
|
cols_unique.append(c2)
|
|
|
+ cols_unique_lower.append(c2.lower())
|
|
|
break
|
|
|
tables_with_columns[table_name] = cols_unique
|
|
|
return tables_with_columns
|
|
|
|
|
|
|
|
|
+def create_sql_bat_files(sql_folder: str) -> None:
|
|
|
+ tasks_dir = Path(sql_folder).parent.parent.parent.parent / "Tasks" / "scripts"
|
|
|
+ header = f'@call "{tasks_dir}\\config.bat" 0 > nul'
|
|
|
+
|
|
|
+ folder_list = [
|
|
|
+ "views_export",
|
|
|
+ "views_load",
|
|
|
+ "exec_drop_create",
|
|
|
+ "exec_update",
|
|
|
+ ]
|
|
|
+ for f in folder_list:
|
|
|
+ folder = f"{sql_folder}\\{f}"
|
|
|
+ bat_file = f"{folder}\\{f}.bat"
|
|
|
+
|
|
|
+ with open(bat_file, "w", encoding="cp850") as fwh:
|
|
|
+ fwh.write(header + "\n\n")
|
|
|
+ fwh.write(f"echo {folder}\n")
|
|
|
+
|
|
|
+ for sql_file in Path(folder).glob("*.sql"):
|
|
|
+ fwh.write(f" call sqlexec2.bat {sql_file}\n")
|
|
|
+
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
# schema_convert("C:\\GlobalCube_LOCOSOFT\\GCStruct_SKR51\\Kontenrahmen")
|
|
|
create_format_xml_from_folder("C:\\GlobalCube_LOCOSOFT\\System\\LOCOSOFT\\Export")
|