From 14d80a70fe3bee36e94eab471fdf3fa357336c13 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Sun, 26 Feb 2017 13:20:36 +0100 Subject: [PATCH] '--stats' now also counts chats and users in the DB. --- .../telegram_backup/CommandLineController.java | 2 ++ .../java/de/fabianonline/telegram_backup/Database.java | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java index 6f88259..732eb66 100644 --- a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java +++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java @@ -223,6 +223,8 @@ public class CommandLineController { String format = "%40s: %d%n"; System.out.format(format, "Number of accounts", Utils.getAccounts().size()); System.out.format(format, "Number of messages", Database.getInstance().getMessageCount()); + System.out.format(format, "Number of chats", Database.getInstance().getChatCount()); + System.out.format(format, "Number of users", Database.getInstance().getUserCount()); System.out.format(format, "Top message ID", Database.getInstance().getTopMessageID()); System.out.println(); diff --git a/src/main/java/de/fabianonline/telegram_backup/Database.java b/src/main/java/de/fabianonline/telegram_backup/Database.java index 0855feb..b715e97 100644 --- a/src/main/java/de/fabianonline/telegram_backup/Database.java +++ b/src/main/java/de/fabianonline/telegram_backup/Database.java @@ -133,9 +133,9 @@ public class Database { } catch (SQLException e) {} } - public int getMessageCount() { + public int queryInt(String query) { try { - ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM messages"); + ResultSet rs = stmt.executeQuery(query); rs.next(); return rs.getInt(1); } catch (SQLException e) { @@ -143,6 +143,10 @@ public class Database { } } + public int getMessageCount() { return queryInt("SELECT COUNT(*) FROM messages"); } + public int getChatCount() { return queryInt("SELECT COUNT(*) FROM chats"); } + public int getUserCount() { return queryInt("SELECT COUNT(*) FROM users"); } + public LinkedList getMissingIDs() { try { LinkedList missing = new LinkedList();