From f3e226e43f144c378768f544486c308ea2c64911 Mon Sep 17 00:00:00 2001 From: Vest Date: Wed, 14 Mar 2018 11:14:27 +0100 Subject: [PATCH] Fixed issue #94 by closing open statements added out/ (IntelliJ) to .gitignore Signed-off-by: Vest --- .gitignore | 1 + .../kotlin/de/fabianonline/telegram_backup/Database.kt | 7 +++++-- .../de/fabianonline/telegram_backup/DatabaseUpdates.kt | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 953f7e4..5fe20b7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ dev/ todo deploy.secret.sh release_notes.txt +out/ diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/Database.kt b/src/main/kotlin/de/fabianonline/telegram_backup/Database.kt index 8c35302..0e120b8 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/Database.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/Database.kt @@ -278,11 +278,14 @@ class Database private constructor(var client: TelegramClient) { try { val rs = stmt!!.executeQuery(query) rs.next() - return rs.getInt(1) + + val result = rs.getInt(1) + + rs.close() + return result } catch (e: SQLException) { throw RuntimeException("Could not get count of messages.") } - } @Synchronized diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/DatabaseUpdates.kt b/src/main/kotlin/de/fabianonline/telegram_backup/DatabaseUpdates.kt index 0f8d12c..009090d 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/DatabaseUpdates.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/DatabaseUpdates.kt @@ -111,10 +111,10 @@ class DatabaseUpdates(protected var conn: Connection, protected var db: Database logger.debug("No update necessary.") } + stmt.close() } catch (e: SQLException) { throw RuntimeException(e) } - } private fun getUpdateToVersion(i: Int): DatabaseUpdate { @@ -145,7 +145,6 @@ internal abstract class DatabaseUpdate(protected var conn: Connection, protected } catch (e: SQLException) { throw RuntimeException(e) } - } @Throws(SQLException::class) @@ -155,6 +154,8 @@ internal abstract class DatabaseUpdate(protected var conn: Connection, protected _doUpdate() logger.debug("Saving current database version to the db") stmt.executeUpdate("INSERT INTO database_versions (version) VALUES ($version)") + + stmt.close() } @Throws(SQLException::class)