1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-12-25 22:35:35 +00:00

DatabaseUpdate now converts all existing messages with the correct api level to json.

This commit is contained in:
Fabian Schlenz 2017-02-23 06:31:18 +01:00
parent 54a3fad349
commit f5d8b0c2e1

View File

@ -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);
}
}