|
@@ -1,7 +1,9 @@
|
|
|
+import codecs
|
|
|
import json
|
|
|
from pathlib import Path
|
|
|
|
|
|
import pandas as pd
|
|
|
+import pyodbc
|
|
|
|
|
|
from database.db_create import get_import_config
|
|
|
from database.model import DatabaseInspect, create_db_ini, load_config
|
|
@@ -35,7 +37,9 @@ def compare(config_file: str = "database/CARLO.json"):
|
|
|
f"SELECT [Client_DB], max(timestamp) as [TS] FROM {full_table_name} GROUP BY [Client_DB]"
|
|
|
)
|
|
|
q = dest_db.cursor.execute(query_timestamp_dest)
|
|
|
- dest_timestamp = dict([(col[0], col[1]) for col in q.fetchall()])
|
|
|
+ dest_timestamp = dict(
|
|
|
+ [(col[0], "0x" + codecs.encode(col[1], "hex_codec").decode()) for col in q.fetchall()]
|
|
|
+ )
|
|
|
|
|
|
source_row_count = {}
|
|
|
source_row_count_ts = {}
|
|
@@ -43,7 +47,9 @@ def compare(config_file: str = "database/CARLO.json"):
|
|
|
for client_db, prefix in cfg.clients.items():
|
|
|
# table_client = f'{current_table["dest"]}_{client_db}'
|
|
|
source_table = current_table["source"].format(prefix)
|
|
|
- if source_table in source_tables:
|
|
|
+ source_table2 = source_table.split(".")[-1][1:-1]
|
|
|
+
|
|
|
+ if source_table in source_tables or source_table2 in source_tables:
|
|
|
if not pd.isnull(current_table["query"]):
|
|
|
select_query = current_table["query"].format(prefix, cfg.filter[0], cfg.filter[1])
|
|
|
elif "." in source_table or cfg.source_dsn.schema == "":
|
|
@@ -56,6 +62,7 @@ def compare(config_file: str = "database/CARLO.json"):
|
|
|
if not pd.isnull(current_table["filter"]):
|
|
|
select_query += " WHERE " + current_table["filter"].format("", cfg.filter[0], cfg.filter[1])
|
|
|
query_count_source = select_query.replace("T1.*", "COUNT(*) as [Rows]")
|
|
|
+ # print(query_count_source)
|
|
|
|
|
|
q = source_db.cursor.execute(query_count_source)
|
|
|
source_row_count[client_db] = q.fetchone()[0]
|
|
@@ -63,11 +70,15 @@ def compare(config_file: str = "database/CARLO.json"):
|
|
|
query_ts = query_count_source
|
|
|
ts = dest_timestamp.get(client_db, "0x0000000000000000")
|
|
|
if "WHERE" in query_ts:
|
|
|
- query_ts = query_ts.replace("WHERE", "WHERE [timestamp] <= convert(binary(8), '{ts}', 1) AND")
|
|
|
+ query_ts = query_ts.replace("WHERE", f"WHERE T1.[timestamp] <= convert(binary(8), '{ts}', 1) AND")
|
|
|
else:
|
|
|
- query_ts += f" WHERE [timestamp] <= convert(binary(8), '{ts}', 1)"
|
|
|
- q = source_db.cursor.execute(query_count_source)
|
|
|
- source_row_count_ts[client_db] = q.fetchone()[0]
|
|
|
+ query_ts += f" WHERE T1.[timestamp] <= convert(binary(8), '{ts}', 1)"
|
|
|
+ # print(query_ts)
|
|
|
+ try:
|
|
|
+ q = source_db.cursor.execute(query_ts)
|
|
|
+ source_row_count_ts[client_db] = q.fetchone()[0]
|
|
|
+ except pyodbc.ProgrammingError:
|
|
|
+ pass
|
|
|
|
|
|
if dest_row_count.get(client_db, 0) != source_row_count.get(client_db, 0):
|
|
|
print(f"Tabelle {current_table['dest']} mit Client {client_db} stimmt nicht ueberein.")
|