From 72021324551a3e961e8effda857f2e46a6ac9859 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Wed, 21 Aug 2024 08:22:00 +0300 Subject: [PATCH] [history] Support of kotlin unsigned integer types --- .../db/jdbc_kotlin_extensions/extensions.kt | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/jvmMain/kotlin/ru/landgrafhomyak/db/jdbc_kotlin_extensions/extensions.kt b/src/jvmMain/kotlin/ru/landgrafhomyak/db/jdbc_kotlin_extensions/extensions.kt index adf9129..de2d39a 100644 --- a/src/jvmMain/kotlin/ru/landgrafhomyak/db/jdbc_kotlin_extensions/extensions.kt +++ b/src/jvmMain/kotlin/ru/landgrafhomyak/db/jdbc_kotlin_extensions/extensions.kt @@ -52,11 +52,16 @@ public inline fun Connection.transaction(t: (Connection) -> R): R { } +public fun Connection.executeStatement(@Language("SQL") sql: String) { + this.prepareStatement(sql) { ps -> ps.execute() } +} + + public inline fun Connection.prepareStatement(@Language("SQL") sql: String, action: (PreparedStatement) -> R): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } - this.prepareStatement(sql/*.trim(' ', '\n', '\t')*/).use { ps -> return action(ps) } + this.prepareStatement(sql).use { ps -> return action(ps) } } public inline fun > ResultSet.mapTo(to: C, transform: (rs: ResultSet) -> R): C { @@ -80,4 +85,29 @@ public inline fun PreparedStatement.executeQuery(action: (ResultSet) -> R): callsInPlace(action, InvocationKind.EXACTLY_ONCE) } return this.executeQuery().use(action) -} \ No newline at end of file +} + + +public fun PreparedStatement.setUByte(parameterIndex: Int, value: UByte): Unit = + this.setByte(parameterIndex, value.toByte()) + +public fun PreparedStatement.setUShort(parameterIndex: Int, value: UShort): Unit = + this.setShort(parameterIndex, value.toShort()) + +public fun PreparedStatement.setUInt(parameterIndex: Int, value: UInt): Unit = + this.setInt(parameterIndex, value.toInt()) + +public fun PreparedStatement.setULong(parameterIndex: Int, value: ULong): Unit = + this.setLong(parameterIndex, value.toLong()) + +public fun ResultSet.getUByte(columnIndex: Int): UByte = + this.getByte(columnIndex).toUByte() + +public fun ResultSet.getUShort(columnIndex: Int): UShort = + this.getShort(columnIndex).toUShort() + +public fun ResultSet.getUInt(columnIndex: Int): UInt = + this.getInt(columnIndex).toUInt() + +public fun ResultSet.getULong(columnIndex: Int): ULong = + this.getLong(columnIndex).toULong() \ No newline at end of file