浏览代码

IQD verfeinert

Global Cube 2 年之前
父节点
当前提交
0110cefcaa
共有 1 个文件被更改,包括 12 次插入5 次删除
  1. 12 5
      cognos7/iqd_convert.py

+ 12 - 5
cognos7/iqd_convert.py

@@ -16,7 +16,7 @@ class IqdConverter:
         query = self.cleanup_query(query)
 
         output_file = iqd_file[:-4] + '.sql'
-        with open(output_file, 'w') as fwh:
+        with open(output_file, 'w', encoding='latin-1') as fwh:
             fwh.write(query)
 
         table = Path(iqd_file).stem
@@ -27,7 +27,7 @@ class IqdConverter:
             "GO\nSET QUOTED_IDENTIFIER OFF \nGO\nSET ANSI_NULLS OFF \nGO\n\nGO"
 
         view_file = f"{self.output_dir}\\{schema}.{table}.sql"
-        with open(view_file, 'w') as fwh:
+        with open(view_file, 'w', encoding='latin-1') as fwh:
             fwh.write(create_view)
 
     def get_query_from_iqdfile(self, iqd_file):
@@ -45,6 +45,11 @@ class IqdConverter:
 
         for col_key, col_name in zip(col_keys, col_names):
             query = re.sub(col_key + r'([^\d])', col_name + r'\1', query)
+
+        columns2 = re.findall(r'\s+(c\d+) as (".*")', query)
+        for col in columns2:
+            query = re.sub(col[0] + r' as ' + col[1], col[1], query)
+            query = re.sub(col[0] + r'([^\d])', col[1] + r'\1', query)
         return query
 
     def cleanup_query(self, query):
@@ -85,11 +90,13 @@ class IqdConverter:
         query = re.sub(r'(order by .*)', r'-- \1', query)
         return query
 
-    def run_folder(base_dir: str):
+    def run_folder(self, base_dir: str):
         files = sorted([(f.stat().st_mtime, f) for f in Path(base_dir).rglob('*.iqd')])
-        print(files)
+        for timestamp, iqd in files:
+            self.convert(str(iqd))
 
 
 if __name__ == '__main__':
-    IqdConverter().convert('C:\\GlobalCube_LOCOSOFT\\System\\LOCOSOFT\\IQD\\NW\\LOC_Belege_NW_GW_VK_Stk_FIBU.iqd')
+    IqdConverter().convert('C:\\GlobalCube_LOCOSOFT\\System\\LOCOSOFT\\IQD\\Serv_Teile\\offene_Auftraege_Ums_ben_AW.iqd')
+    IqdConverter().run_folder('C:\\Projekte\\DWH\\CARLO\\IQD')
     # plac.Interpreter.call(IqdConverter)