Skip to content

Commit 23fae6e

Browse files
committed
fix: added bytes read und write from and to mongodb
1 parent 0e64c07 commit 23fae6e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/scala/dev/mongocamp/driver/mongodb/jdbc/resultSet/MongoDbResultSet.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dev.mongocamp.driver.mongodb.jdbc.resultSet
22

33
import dev.mongocamp.driver.mongodb.MongoDAO
44
import dev.mongocamp.driver.mongodb.bson.BsonConverter
5-
import org.mongodb.scala.bson.{ BsonArray, BsonBoolean, BsonDateTime, BsonInt32, BsonInt64, BsonNull, BsonNumber, BsonObjectId, BsonString }
5+
import org.mongodb.scala.bson.{ BsonArray, BsonBoolean, BsonDateTime, BsonDouble, BsonInt32, BsonInt64, BsonNull, BsonNumber, BsonObjectId, BsonString }
66
import org.mongodb.scala.bson.collection.immutable.Document
77

88
import java.io.{ InputStream, Reader }
@@ -14,6 +14,7 @@ import dev.mongocamp.driver.mongodb._
1414
import dev.mongocamp.driver.mongodb.jdbc.MongoJdbcCloseable
1515

1616
import java.nio.charset.StandardCharsets
17+
import javax.sql.rowset.serial.SerialBlob
1718
import scala.util.Try
1819

1920
class MongoDbResultSet(collectionDao: MongoDAO[Document], data: List[Document], queryTimeOut: Int) extends ResultSet with MongoJdbcCloseable {
@@ -197,7 +198,7 @@ class MongoDbResultSet(collectionDao: MongoDAO[Document], data: List[Document],
197198

198199
override def getBytes(columnLabel: String): Array[Byte] = {
199200
checkClosed()
200-
null
201+
getString(columnLabel).replace("[", "").replace("]", "").split(",").filterNot(s => s.trim.isEmpty).map(_.trim.toByte)
201202
}
202203

203204
override def getDate(columnLabel: String): Date = {
@@ -824,9 +825,13 @@ class MongoDbResultSet(collectionDao: MongoDAO[Document], data: List[Document],
824825
updateString(columnLabel, text)
825826
}
826827

827-
override def getBlob(columnIndex: Int): Blob = sqlFeatureNotSupported()
828+
override def getBlob(columnIndex: Int): Blob = {
829+
new SerialBlob(getBytes(columnIndex))
830+
}
828831

829-
override def getBlob(columnLabel: String): Blob = sqlFeatureNotSupported()
832+
override def getBlob(columnLabel: String): Blob = {
833+
new SerialBlob(getBytes(columnLabel))
834+
}
830835

831836
override def updateBlob(columnIndex: Int, x: Blob): Unit = {
832837
checkClosed()

0 commit comments

Comments
 (0)