Permalink
Browse files

Merge pull request #126 from slick/tmp/parenthesize-subqueries

Always add parentheses around subqueries in a SELECT clause.
  • Loading branch information...
szeiger committed Mar 27, 2013
2 parents 55011d7 + 592d5c2 commit e9d48e9f623e7a9d299aea245a2eb0d53d34d58c
@@ -433,4 +433,23 @@ class NewQuerySemanticsTest(val tdb: TestDB) extends TestkitTest {
(TableA.ddl ++ TableB.ddl ++ TableC.ddl).create
queryErr2.run
}
def testSubquery {
object A extends Table[Int]("A_subquery") {
def id = column[Int]("id")
def * = id
}
A.ddl.create
A.insert(42)
val q0 = Query(A).filter(_.id === 42.bind).length
val r0 = q0.run
assertEquals(1, r0)
val q1 = Parameters[Int].flatMap { n =>
Query(A).filter(_.id is n).map(a => Query(a).length)
}
val r1 = q1(42).list
assertEquals(List(1), r1)
}
}
@@ -151,6 +151,10 @@ trait BasicStatementBuilderComponent { driver: BasicDriver =>
protected def buildSelectPart(n: Node): Unit = n match {
case Typed(t: TypeMapper[_]) if useIntForBoolean && (t(profile) == driver.typeMapperDelegates.booleanTypeMapperDelegate) =>
b"case when $n then 1 else 0 end"
case c: Comprehension =>
b"("
buildComprehension(c)
b")"
case n =>
expr(n, true)
}

0 comments on commit e9d48e9

Please sign in to comment.