From a4d79c3892d15b609233c5b4d33bf5fd2bd14fb8 Mon Sep 17 00:00:00 2001 From: KnugiHK <24708955+KnugiHK@users.noreply.github.com> Date: Sat, 21 Mar 2026 15:46:00 +0800 Subject: [PATCH] Add backward compatibility to contact database processing Because ZLID does not exist in the old schema --- Whatsapp_Chat_Exporter/ios_handler.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Whatsapp_Chat_Exporter/ios_handler.py b/Whatsapp_Chat_Exporter/ios_handler.py index 98077a6..2ee1091 100644 --- a/Whatsapp_Chat_Exporter/ios_handler.py +++ b/Whatsapp_Chat_Exporter/ios_handler.py @@ -24,7 +24,14 @@ def contacts(db, data): total_row_number = c.fetchone()[0] logging.info(f"Pre-processing contacts...({total_row_number})", extra={"clear": True}) - c.execute("""SELECT ZWHATSAPPID, ZLID, ZFULLNAME, ZABOUTTEXT FROM ZWAADDRESSBOOKCONTACT""") + # Check if expected columns exist before querying, + # to handle different WhatsApp versions (mainly ZLID). + c.execute("PRAGMA table_info(ZWAADDRESSBOOKCONTACT)") + column_names = [info[1] for info in c.fetchall()] + all_cols = ["ZWHATSAPPID", "ZLID", "ZFULLNAME", "ZABOUTTEXT"] + columns = [col for col in all_cols if col in column_names] + + c.execute(f"""SELECT {', '.join(columns)} FROM ZWAADDRESSBOOKCONTACT""") with tqdm(total=total_row_number, desc="Processing contacts", unit="contact", leave=False) as pbar: while (content := c.fetchone()) is not None: zwhatsapp_id = content["ZWHATSAPPID"] @@ -40,7 +47,11 @@ def contacts(db, data): if content["ZABOUTTEXT"]: current_chat.status = content["ZABOUTTEXT"] # Index by WhatsApp ID, with LID as alias if available - data.add_chat(zwhatsapp_id, current_chat, content["ZLID"] if content["ZLID"] else None) + data.add_chat( + zwhatsapp_id, + current_chat, + content["ZLID"] if "ZLID" in columns and content["ZLID"] else None + ) pbar.update(1) total_time = pbar.format_dict['elapsed']