changeset 14:4dae7a15ee48

Fix bugs found in additional round of testing.
author David Barts <n5jrn@me.com>
date Tue, 31 Jan 2023 19:07:46 -0800
parents 302d224bbd57
children 0fc90892a3ae
files src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt src/main/kotlin/name/blackcap/passman/RenameSubcommand.kt
diffstat 2 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt	Tue Jan 24 20:13:13 2023 -0800
+++ b/src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt	Tue Jan 31 19:07:46 2023 -0800
@@ -65,7 +65,7 @@
             die(e.message ?: "syntax error", 2)
         }
         if (commandLine.hasOption(ImportSubcommand.HELP)) {
-            HelpFormatter().printHelp("$SHORTNAME merge [options] csv_file", options)
+            HelpFormatter().printHelp("$SHORTNAME import [options] csv_file", options)
             exitProcess(0)
         }
         if (commandLine.args.isEmpty()) {
--- a/src/main/kotlin/name/blackcap/passman/RenameSubcommand.kt	Tue Jan 24 20:13:13 2023 -0800
+++ b/src/main/kotlin/name/blackcap/passman/RenameSubcommand.kt	Tue Jan 31 19:07:46 2023 -0800
@@ -1,6 +1,8 @@
 package name.blackcap.passman
 
 import org.apache.commons.cli.*
+import java.sql.PreparedStatement
+import java.sql.Types
 import kotlin.system.exitProcess
 
 class RenameSubcommand(): Subcommand() {
@@ -59,19 +61,19 @@
         }
 
         db.connection.prepareStatement("select username, password, notes, created, modified, accessed from passwords where id = ?").use { sourceStmt ->
-            sourceStmt.setLong(1, did)
+            sourceStmt.setLong(1, sid)
             val result = sourceStmt.executeQuery()
             result.next()
-            db.connection.prepareStatement("insert into passwords (id, name, username, password, notes, created, modified, accessed) values (?, ?, ?, ?, ?, ?, ?, ?)").run {
-                setLong(1, did)
-                setEncryptedString(2, destination, db.encryption)
-                setBytes(3, result.getBytes(1))
-                setBytes(4, result.getBytes(2))
-                setBytesOrNull(5, result.getBytes(3))
-                setLong(6, result.getLong(4))
-                setLong(7, System.currentTimeMillis())
-                setLongOrNull(8, result.getLong(6))
-                executeUpdate()
+            db.connection.prepareStatement("insert into passwords (id, name, username, password, notes, created, modified, accessed) values (?, ?, ?, ?, ?, ?, ?, ?)").use {
+                it.setLong(1, did)
+                it.setEncryptedString(2, destination, db.encryption)
+                it.setBytes(3, result.getBytes(1))
+                it.setBytes(4, result.getBytes(2))
+                it.setBytesOrNull(5, result.getBytes(3))
+                it.setLong(6, result.getLong(4))
+                it.setLong(7, System.currentTimeMillis())
+                it.setDateOrNull(8, result.getLong(6))
+                it.executeUpdate()
             }
         }
 
@@ -93,4 +95,12 @@
             it.executeUpdate()
         }
     }
-}
\ No newline at end of file
+
+    private fun PreparedStatement.setDateOrNull(parameterIndex: Int, value: Long?) {
+        if (value == null || value == 0L) {
+            setNull(parameterIndex, Types.INTEGER)
+        } else {
+            setLong(parameterIndex, value)
+        }
+    }
+}