From 5b37bf7c76278c68b7651bde144f7f66a3bd58f3 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 16 Aug 2025 21:42:16 +0200 Subject: [PATCH] fix Database.newFeeds --- .../kotlin/de/unixwork/rssreader/Database.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt index 5d7603a..0899d03 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -51,8 +51,8 @@ object Database { feed_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, feedcollection_id INT NOT NULL REFERENCES feedcollections(feedcollection_id) ON DELETE CASCADE, url VARCHAR NOT NULL, - user VARCHAR, - password VARCHAR, + auth_user VARCHAR, + auth_password VARCHAR, certpath VARCHAR, last_update TIMESTAMP ) @@ -120,7 +120,7 @@ object Database { public fun newFeedGroup(name: String) : FeedGroup { var groupId = 0 connection.prepareStatement(""" - insert into groups (pos, name) select max(pos)+1, ? from groups + insert into groups (pos, name) select coalesce(max(pos), 0)+1, ? from groups """.trimIndent(), Statement.RETURN_GENERATED_KEYS).use { stmt -> stmt.setString(1, name) stmt.execute() @@ -145,8 +145,8 @@ object Database { { var feedcollectionId = -1 connection.prepareStatement(""" - insert into feedcollections (group_id, pos, name) select ?, max(pos)+1, ? from groups - """.trimIndent()).use { stmt -> + insert into feedcollections (group_id, pos, name) select ?, coalesce(max(pos), 0)+1, ? from groups + """.trimIndent(), Statement.RETURN_GENERATED_KEYS).use { stmt -> stmt.setInt(1, parent.id) stmt.setString(2, name) stmt.execute() @@ -161,10 +161,8 @@ object Database { uris.forEach { uri -> connection.prepareStatement(""" - insert into feeds (feedcollection_id, url, user, password, certpath) - select ?, ?, ?, ?, ? - from dual - where not exists (select 1 from feeds where url = ?) + insert into feeds (feedcollection_id, url, auth_user, auth_password, certpath) values + (?, ?, ?, ?, ?) """.trimIndent()).use { stmt -> stmt.setInt(1, feedcollectionId) stmt.setString(2, uri) -- 2.47.3