Skip to content

Commit

Permalink
chore: Add blobParam function. (JetBrains#1672)
Browse files Browse the repository at this point in the history
* Add blobParam function.

* Review changes.
  • Loading branch information
spand authored and saral committed Oct 3, 2023
1 parent e94514a commit 6916391
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.exposed.sql

import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.sql.SqlExpressionBuilder.wrap
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
import org.jetbrains.exposed.sql.vendors.*
import java.math.BigDecimal

Expand Down Expand Up @@ -762,6 +763,9 @@ fun stringParam(value: String): Expression<String> = QueryParameter(value, TextC
/** Returns the specified [value] as a decimal query parameter. */
fun decimalParam(value: BigDecimal): Expression<BigDecimal> = QueryParameter(value, DecimalColumnType(value.precision(), value.scale()))

/** Returns the specified [value] as a blob query parameter. */
fun blobParam(value: ExposedBlob): Expression<ExposedBlob> = QueryParameter(value, BlobColumnType())

// Misc.

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ class DDLTests : DatabaseTestsBase() {
it[t.b] = longBlob
} get (t.id)

val id3 = t.insert {
it[t.b] = blobParam(ExposedBlob(shortBytes))
} get (t.id)

val readOn1 = t.select { t.id eq id1 }.first()[t.b]
val text1 = String(readOn1.bytes)
val text2 = readOn1.inputStream.bufferedReader().readText()
Expand All @@ -482,6 +486,9 @@ class DDLTests : DatabaseTestsBase() {

assertTrue(longBytes.contentEquals(bytes1))
assertTrue(longBytes.contentEquals(bytes2))

val bytes3 = t.select { t.id eq id3 }.first()[t.b].inputStream.readBytes()
assertTrue(shortBytes.contentEquals(bytes3))
}
}

Expand Down

0 comments on commit 6916391

Please sign in to comment.