From f5d8b0c2e1a23b0e35f0f0e0a5c5801dd0b8785d Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Thu, 23 Feb 2017 06:31:18 +0100 Subject: [PATCH] DatabaseUpdate now converts all existing messages with the correct api level to json. --- .../telegram_backup/DatabaseUpdates.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/de/fabianonline/telegram_backup/DatabaseUpdates.java b/src/main/java/de/fabianonline/telegram_backup/DatabaseUpdates.java index aae9d6d..824c4a4 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DatabaseUpdates.java +++ b/src/main/java/de/fabianonline/telegram_backup/DatabaseUpdates.java @@ -12,8 +12,10 @@ import java.sql.PreparedStatement; import com.github.badoualy.telegram.tl.api.*; import org.slf4j.LoggerFactory; import org.slf4j.Logger; +import com.google.gson.Gson; import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory; import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager; +import com.github.badoualy.telegram.api.Kotlogram; public class DatabaseUpdates { protected Connection conn; @@ -311,5 +313,20 @@ class DB_Update_8 extends DatabaseUpdate { stmt.executeUpdate("ALTER TABLE messages ADD COLUMN json TEXT"); stmt.executeUpdate("ALTER TABLE chats ADD COLUMN json TEXT"); stmt.executeUpdate("ALTER TABLE users ADD COLUMN json TEXT"); + + ResultSet rs = stmt.executeQuery("SELECT id, data FROM messages WHERE api_layer=" + Kotlogram.API_LAYER); + PreparedStatement ps = conn.prepareStatement("UPDATE messages SET json=? WHERE id=?"); + Gson gson = Utils.getGson(); + while(rs.next()) { + TLMessage msg = db.bytesToTLMessage(rs.getBytes(2)); + ps.setInt(2, rs.getInt(1)); + ps.setString(1, gson.toJson(msg)); + ps.addBatch(); + } + rs.close(); + conn.setAutoCommit(false); + ps.executeBatch(); + conn.commit(); + conn.setAutoCommit(true); } }