From a68ba272bc176ca811468d3013a16d9977132f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liam=2EM=28=EC=97=84=EC=9D=B5=ED=9B=88=29?= Date: Wed, 30 Mar 2016 16:32:50 +0900 Subject: [PATCH] Update codec for resolve decoding error between `mysql bit(1)` and `scala Bealean` cause by `java.lang.IllegalStateException: Value 'RawValue(16,63,true,[B@64697949)' can't be decoded to 'boolean'` --- .../finagle/mysql/FinagleMysqlDecoders.scala | 1 + .../mysql/FinagleMysqlEncodingSpec.scala | 27 +++++++++++++++++++ quill-sql/src/test/sql/mysql-schema.sql | 5 ++++ quill-sql/src/test/sql/postgres-schema.sql | 4 +-- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/quill-finagle-mysql/src/main/scala/io/getquill/sources/finagle/mysql/FinagleMysqlDecoders.scala b/quill-finagle-mysql/src/main/scala/io/getquill/sources/finagle/mysql/FinagleMysqlDecoders.scala index 07e238e83f..60ac6417fa 100644 --- a/quill-finagle-mysql/src/main/scala/io/getquill/sources/finagle/mysql/FinagleMysqlDecoders.scala +++ b/quill-finagle-mysql/src/main/scala/io/getquill/sources/finagle/mysql/FinagleMysqlDecoders.scala @@ -56,6 +56,7 @@ trait FinagleMysqlDecoders { implicit val booleanDecoder: Decoder[Boolean] = decoder[Boolean] { case ByteValue(byte) => byte == (1: Byte) + case v: RawValue => v.bytes.head == (1: Byte) } implicit val byteDecoder: Decoder[Byte] = decoder[Byte] { diff --git a/quill-finagle-mysql/src/test/scala/io/getquill/sources/finagle/mysql/FinagleMysqlEncodingSpec.scala b/quill-finagle-mysql/src/test/scala/io/getquill/sources/finagle/mysql/FinagleMysqlEncodingSpec.scala index d40efa31f6..c549ba2b48 100644 --- a/quill-finagle-mysql/src/test/scala/io/getquill/sources/finagle/mysql/FinagleMysqlEncodingSpec.scala +++ b/quill-finagle-mysql/src/test/scala/io/getquill/sources/finagle/mysql/FinagleMysqlEncodingSpec.scala @@ -41,4 +41,31 @@ class FinagleMysqlEncodingSpec extends EncodingSpec { } } } + + "decode boolean types" - { + case class BooleanEncodingTestEntity(v1: Boolean, v2: Boolean) + val decodeBoolean = (entity: BooleanEncodingTestEntity) => { + val delete = quote(query[BooleanEncodingTestEntity].delete) + val insert = quote(query[BooleanEncodingTestEntity].insert) + val r = for { + _ <- testDB.run(delete) + _ <- testDB.run(insert)(List(entity)) + result <- testDB.run(query[BooleanEncodingTestEntity]) + } yield result + Await.result(r).head + } + "true" in { + val entity = BooleanEncodingTestEntity(true, true) + val r = decodeBoolean(entity) + r.v1 mustEqual true + r.v2 mustEqual true + } + + "false" in { + val entity = BooleanEncodingTestEntity(false, false) + val r = decodeBoolean(entity) + r.v1 mustEqual false + r.v2 mustEqual false + } + } } diff --git a/quill-sql/src/test/sql/mysql-schema.sql b/quill-sql/src/test/sql/mysql-schema.sql index a2858168e2..075b7f7487 100644 --- a/quill-sql/src/test/sql/mysql-schema.sql +++ b/quill-sql/src/test/sql/mysql-schema.sql @@ -54,6 +54,11 @@ Create TABLE DateEncodingTestEntity( v3 timestamp ); +Create TABLE BooleanEncodingTestEntity( + v1 BOOLEAN, + v2 BIT(1) +); + CREATE TABLE TestEntity( s VARCHAR(255), i INTEGER, diff --git a/quill-sql/src/test/sql/postgres-schema.sql b/quill-sql/src/test/sql/postgres-schema.sql index b313c4ec34..fa077737d9 100644 --- a/quill-sql/src/test/sql/postgres-schema.sql +++ b/quill-sql/src/test/sql/postgres-schema.sql @@ -32,7 +32,7 @@ CREATE TABLE EncodingTestEntity( v6 INTEGER, v7 BIGINT, v8 FLOAT, - v9 DOUBLE PRECISIOn, + v9 DOUBLE PRECISION, v10 BYTEA, v11 TIMESTAMP, o1 VARCHAR(255), @@ -43,7 +43,7 @@ CREATE TABLE EncodingTestEntity( o6 INTEGER, o7 BIGINT, o8 FLOAT, - o9 DOUBLE PRECISIOn, + o9 DOUBLE PRECISION, o10 BYTEA, o11 TIMESTAMP );