Skip to content

Commit

Permalink
Fix for issue 48 (Exception thrown in outer join with subquery member)
Browse files Browse the repository at this point in the history
the problem was that the ordering of the table expression was not strict, so the from expression
would get mixed with a join expression.
  • Loading branch information
max-l committed Sep 28, 2010
1 parent d1c2301 commit 2057df7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/main/scala/org/squeryl/dsl/ast/ExpressionNode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ trait QueryableExpressionNode extends ExpressionNode with UniqueIdInAliaseRequir

def inhibited_=(b: Boolean) = _inhibited = b

/**
* When the join syntax is used, isMemberOfJoinList is true if this instance is not in the from clause
* but a 'join element'.
*/
def isMemberOfJoinList = joinKind != None

// new join syntax
var joinKind: Option[(String,String)] = None

Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/org/squeryl/internals/DatabaseAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ trait DatabaseAdapter {
}
}
else {
val texp = qen.tableExpressions.splitAt(1)
val firstJoinExpr = texp._1.head
val restOfJoinExpr = texp._2
val singleNonJoinTableExpression = qen.tableExpressions.filter(! _.isMemberOfJoinList)
assert(singleNonJoinTableExpression.size == 1, "join query must have exactly one FROM argument, got : " + qen.tableExpressions)
val firstJoinExpr = singleNonJoinTableExpression.head
val restOfJoinExpr = qen.tableExpressions.filter(_.isMemberOfJoinList)
firstJoinExpr.write(sw)
sw.write(" ")
sw.write(firstJoinExpr.alias)
Expand Down
32 changes: 30 additions & 2 deletions src/test/scala/org/squeryl/tests/musicdb/MusicDb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,43 @@ class MusicDbTestRun extends QueryTester {

val r = q.map(q0 => (q0.key._1, q0.measures)).toSet

println("!:" + r)

assertEquals(
Set((herbyHancock.id, 1),
(ponchoSanchez.id,1),
(mongoSantaMaria.id,1),
(alainCaron.id, 0),
(hossamRamzy.id, 0)),
r, 'testJoinWithCompute)

passed('testJoinWithCompute)
}

def testOuterJoinWithSubQuery = {
import testInstance._

val artistsQ = artists.where(_.firstName <> "zozo")

val q =
join(artistsQ,songs.leftOuter)((a,s)=>
select((a,s))
on(a.id === s.map(_.authorId))
).toList


val artistIdsWithoutSongs = q.filter(_._2 == None).map(_._1.id).toSet

assertEquals(
Set(alainCaron.id,hossamRamzy.id),
artistIdsWithoutSongs, 'testOuterJoinWithSubQuery)

val artistIdsWithSongs = q.filter(_._2 != None).map(_._1.id).toSet

assertEquals(
Set(herbyHancock.id,ponchoSanchez.id,mongoSantaMaria.id),
artistIdsWithSongs, 'testOuterJoinWithSubQuery)

passed('testOuterJoinWithSubQuery)
}

def selfJoinNested3Level =
from(
Expand Down Expand Up @@ -284,6 +310,8 @@ class MusicDbTestRun extends QueryTester {
def working = {
import testInstance._

testOuterJoinWithSubQuery

testJoinWithCompute

testInTautology
Expand Down

0 comments on commit 2057df7

Please sign in to comment.