Browse Source

INSERT mit TABLOCK

gc-server3 9 tháng trước cách đây
mục cha
commit
75b9e1b17b
3 tập tin đã thay đổi với 9 bổ sung4 xóa
  1. 8 3
      database/db_compare.py
  2. 1 1
      database/model.py
  3. BIN
      dist/gctools.exe

+ 8 - 3
database/db_compare.py

@@ -5,7 +5,7 @@ import sys
 from datetime import datetime
 
 import pandas as pd
-from pyodbc import ProgrammingError
+from pyodbc import Error, ProgrammingError
 
 sys.path.insert(0, "C:\\Projekte\\tools")
 from database.db_create import get_table_config  # noqa:E402
@@ -166,6 +166,10 @@ def resolve_mismatch(source_table: SourceTable2, dest_table: DestTable, cfg: DbC
         print(res.rowcount)
         res.commit()
 
+    if len(ts_lists[1]) > 100_000:
+        print(f"Tabellen-Import fuer {source_table.table_client} abgebrochen: zu viele Zeilen!")
+        return
+
     res = cfg.dest_inspect.cursor.execute(f"TRUNCATE TABLE {dest_table.temp_table_name}")
     res.commit()
     print(res.rowcount)
@@ -183,16 +187,17 @@ def resolve_mismatch(source_table: SourceTable2, dest_table: DestTable, cfg: DbC
         print(len(insert_rows))
         if len(insert_rows) == 0:
             break
-        insert_query = f"INSERT INTO {dest_table.temp_table_name} VALUES \n" + ", \n".join(insert_rows)
+        insert_query = f"INSERT INTO {dest_table.temp_table_name} with (TABLOCK) VALUES \n" + ", \n".join(insert_rows)
 
         try:
             res2 = cfg.dest_inspect.cursor.execute(insert_query)
             print(res2.rowcount)
             res2.commit()
-        except Exception:
+        except Error as e:
             with open(f"{cfg.stage_dir}\\diff\\{source_table.table_client}_insert_{i}.sql", "w") as fwh:
                 fwh.write(insert_query)
             print(f"Tabellen-Import fuer {source_table.table_client} abgebrochen")
+            print(e)
 
     res = cfg.dest_inspect.cursor.execute(dest_table.delete_query)
     print(res.rowcount)

+ 1 - 1
database/model.py

@@ -303,7 +303,7 @@ class DestTable:
 
     @property
     def insert_query(self) -> str:
-        return f"INSERT INTO {self.full_table_name} SELECT * FROM {self.temp_table_name} T1"
+        return f"INSERT INTO {self.full_table_name} with (TABLOCK) SELECT * FROM {self.temp_table_name} T1"
 
     @property
     def delete_query(self) -> str:

BIN
dist/gctools.exe