# HG changeset patch # User David Barts # Date 1675220866 28800 # Node ID 4dae7a15ee48dbf1db73ba816b756b3295e47492 # Parent 302d224bbd576c422a32193d8a5fe4268d988420 Fix bugs found in additional round of testing. diff -r 302d224bbd57 -r 4dae7a15ee48 src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt --- 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()) { diff -r 302d224bbd57 -r 4dae7a15ee48 src/main/kotlin/name/blackcap/passman/RenameSubcommand.kt --- 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) + } + } +}