]> uap-core.de Git - rssreader.git/commitdiff
fix Database.newFeeds
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 16 Aug 2025 19:42:16 +0000 (21:42 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 16 Aug 2025 19:42:16 +0000 (21:42 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt

index 5d7603af458d2c7ac4c85aaea08fad0835c72b08..0899d03bf068fd2d8fb7348eba4f481a1d08e209 100644 (file)
@@ -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)