Mercurial > cgi-bin > hgweb.cgi > PassMan
diff src/main/kotlin/name/blackcap/passman/RenameSubcommand.kt @ 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 | c69665ff37d0 |
children | 0fc90892a3ae |
line wrap: on
line diff
--- 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) + } + } +}