Skip to content

Commit

Permalink
Run OptionBooleanTest.testFilterWithOption test against all databases.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexFrankfurt authored and hvesalai committed Feb 13, 2020
1 parent c456cda commit eecc74f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Expand Up @@ -36,7 +36,7 @@ object Dependencies {
} else "8"
"com.microsoft.sqlserver" % "mssql-jdbc" % s"7.2.2.jre$jreVersionToUse"
}

val testDBs = Seq(
h2,
sqlServer,
Expand Down
1 change: 1 addition & 0 deletions slick-testkit/src/main/resources/testkit-reference.conf
Expand Up @@ -49,6 +49,7 @@ testkit {
${testPackage}.ForUpdateTest
${testPackage}.ForceInsertQueryTest
${testPackage}.RewriteBooleanTest
${testPackage}.OptionBooleanTest
]
}

Expand Down
@@ -1,16 +1,14 @@
package com.typesafe.slick.testkit.tests

import com.typesafe.slick.testkit.util.{AsyncTest, JdbcTestDB}
import slick.jdbc.OracleProfile

class OptionBooleanTest extends AsyncTest[JdbcTestDB] {
lazy val oracleProfile = tdb.profile.asInstanceOf[OracleProfile]
import oracleProfile.api._
import tdb.profile.api._

def testFilterWithOption = {
class A(tag: Tag) extends Table[(Int, Option[Boolean], Option[Int])](tag, "a") {
def id = column[Int]("id")
def b = column[Option[Boolean]]("a")
def b = column[Option[Boolean]]("b")
def oi = column[Option[Int]]("oi")
def * = (id, b, oi)
}
Expand All @@ -21,8 +19,8 @@ class OptionBooleanTest extends AsyncTest[JdbcTestDB] {
as += (1, Some(true), None),
as += (2, Some(false), Some(1)),
as += (3, None, Some(2)),
as.filter(_.b.getOrElse(false) === false).result.map(_ shouldBe Seq(2, 3)),
as.filter(_.oi.map(_ === 2).getOrElse(false)).result.map(_ shouldBe Seq(3)),
as.filter(_.b.getOrElse(false) === false).map(_.id).result.map(_ shouldBe Seq(2, 3)),
as.filter(_.oi.map(_ === 2).getOrElse(false)).map(_.id).result.map(_ shouldBe Seq(3)),
as.schema.drop
)
}
Expand Down
6 changes: 5 additions & 1 deletion slick/src/main/scala/slick/jdbc/DB2Profile.scala
Expand Up @@ -94,6 +94,10 @@ trait DB2Profile extends JdbcProfile {
case Library.CountAll(LiteralNode(1)) => b"count(*)"
case RewriteBooleans.ToFakeBoolean(a @ Apply(Library.SilentCast, _)) =>
expr(RewriteBooleans.rewriteFakeBooleanWithEquals(a), skipParens)
case RewriteBooleans.ToFakeBoolean(a @ Apply(Library.IfNull, _)) =>
expr(RewriteBooleans.rewriteFakeBooleanWithEquals(a), skipParens)
case c@Comprehension(_, _, _, Some(n @ Apply(Library.IfNull, _)), _, _, _, _, _, _, _) =>
super.expr(c.copy(where = Some(RewriteBooleans.rewriteFakeBooleanEqOne(n))), skipParens)
case _ => super.expr(c, skipParens)
}

Expand Down Expand Up @@ -136,7 +140,7 @@ trait DB2Profile extends JdbcProfile {
} else super.createIndex(idx)
}

//For compatibility with all versions of DB2
//For compatibility with all versions of DB2
//http://stackoverflow.com/questions/3006999/sql-query-to-truncate-table-in-ibm-db2
override def truncateTable = s"DELETE FROM ${quoteTableName(tableNode)}"

Expand Down
4 changes: 4 additions & 0 deletions slick/src/main/scala/slick/jdbc/DerbyProfile.scala
Expand Up @@ -211,6 +211,10 @@ trait DerbyProfile extends JdbcProfile {
b"\}"
case RewriteBooleans.ToFakeBoolean(a @ Apply(Library.SilentCast, _)) =>
expr(RewriteBooleans.rewriteFakeBooleanWithEquals(a), skipParens)
case RewriteBooleans.ToFakeBoolean(a @ Apply(Library.IfNull, _)) =>
expr(RewriteBooleans.rewriteFakeBooleanWithEquals(a), skipParens)
case c@Comprehension(_, _, _, Some(n @ Apply(Library.IfNull, _)), _, _, _, _, _, _, _) =>
super.expr(c.copy(where = Some(RewriteBooleans.rewriteFakeBooleanEqOne(n))), skipParens)
case _ => super.expr(c, skipParens)
}
}
Expand Down
4 changes: 4 additions & 0 deletions slick/src/main/scala/slick/jdbc/SQLServerProfile.scala
Expand Up @@ -194,6 +194,10 @@ trait SQLServerProfile extends JdbcProfile {
b"replicate($str, $count)"
case RewriteBooleans.ToFakeBoolean(a @ Apply(Library.SilentCast, _)) =>
expr(RewriteBooleans.rewriteFakeBooleanWithEquals(a), skipParens)
case RewriteBooleans.ToFakeBoolean(a @ Apply(Library.IfNull, _)) =>
expr(RewriteBooleans.rewriteFakeBooleanWithEquals(a), skipParens)
case c@Comprehension(_, _, _, Some(n @ Apply(Library.IfNull, _)), _, _, _, _, _, _, _) =>
super.expr(c.copy(where = Some(RewriteBooleans.rewriteFakeBooleanEqOne(n))), skipParens)
case n => super.expr(n, skipParens)
}
}
Expand Down

0 comments on commit eecc74f

Please sign in to comment.