diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt index 82293d8899..feca48b108 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt @@ -779,6 +779,7 @@ class BlobColumnType( is ExposedBlob -> value is InputStream -> ExposedBlob(value) is ByteArray -> ExposedBlob(value) + is Blob -> ExposedBlob(value.binaryStream) else -> error("Unexpected value of type Blob: $value of ${value::class.qualifiedName}") } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/types/BlobColumnTypeTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/types/BlobColumnTypeTests.kt new file mode 100644 index 0000000000..198da458dc --- /dev/null +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/types/BlobColumnTypeTests.kt @@ -0,0 +1,30 @@ +package org.jetbrains.exposed.sql.tests.shared.types + +import junit.framework.TestCase.assertEquals +import org.jetbrains.exposed.dao.id.IntIdTable +import org.jetbrains.exposed.sql.alias +import org.jetbrains.exposed.sql.insert +import org.jetbrains.exposed.sql.statements.api.ExposedBlob +import org.jetbrains.exposed.sql.tests.DatabaseTestsBase +import org.junit.Test +import java.nio.charset.Charset + +class BlobColumnTypeTests : DatabaseTestsBase() { + object BlobTable : IntIdTable("test-blob") { + val content = blob("content") + } + + @Test + fun testWriteAndReadBlobValueViaAlias() { + withTables(BlobTable) { + val sampleData = "test-sample-data" + BlobTable.insert { + it[content] = ExposedBlob(sampleData.toByteArray()) + } + + val alias = BlobTable.content.alias("content_column") + val content = BlobTable.select(alias).single()[alias].bytes.toString(Charset.defaultCharset()) + assertEquals(content, sampleData) + } + } +}