2

I'm trying to do a simple query with squeryl. however it doesn't work! the code compiles but the query returns no results, but it should! the same query in blank SQL works perfectly. SELECT * FROM tablename WHERE position <= 83172924

val qryResult = from(DBName.tablename)(t => where(t.position === 83172924) select (t)) //works! but not what i want
val qryResult = from(DBName.tablename)(t => where(t.position <= 83172924) select (t)) //compile OK, no results
val qryResult = from(DBName.tablename)(t => where(t.position lte 83172924) select (t)) //compile ERROR

object DBName extends Schema {
  val tablename = table[FOO]("tablename")
}

class FOO(var position: Int) {
  def this() = this (0)
}

according to http://max-l.github.com/Squeryl/functions.html it should work?!

any help is appreciated.

dforce
  • 2,136
  • 3
  • 20
  • 36
  • 1
    qryResult.statement is quite helpfull: `... From tablename tablename1 Where (tablename1.position = true)`. don 't – dforce Jun 14 '11 at 12:52

1 Answers1

2

This should have given you a deprecation warning :

qryResult = from(DBName.tablename)(t => where(t.position <= 83172924) select (t))

There's a deprecated implicit conversion that is causing trouble, see this

https://groups.google.com/forum/#!searchin/squeryl/implicit$20boolean/squeryl/pSUzNDA4Bq4/oHmqS16yD_0J

I just removed it from master branch.

This one should work :

qryResult = from(DBName.tablename)(t => where(t.position lte 83172924) select (t))

I just tried it and it compiles and runs correctly.

Max L.
  • 9,774
  • 15
  • 56
  • 86
  • indeed, the `lte` version works. however i'm still struggling to define the query in squeryl. in sql it's quite simple: `SELECT * FROM tablename WHERE x = "a" and ((startPos between 83172924 and 83336614 or endPos between 83172924 and 83336614) or (startPos < 83172924 and endPos > 83336614))`. but in squeryl it doesn't work the same way: `val qryResult = from(DBName.tablename)(t => where(t.x === "a" and ((t.startPos between(83172924, 83336614) or t.endPos between(83172924, 83336614)) or (t.startPos lt 83172924 and t.endPos gt 83336614)) select (t)))` – dforce Jun 15 '11 at 11:35
  • You have an umbalanced parenthesis in the above code ! The select(t) is inside the where() clause... – Max L. Jun 15 '11 at 12:53
  • thx, but that doesn't fix the problem :(. i get an `error: type mismatch found: Int required: org.squeryl.dsl.ast.LogicalBoolean` and `error: value x is not a memeber of Nothing`. – dforce Jun 15 '11 at 15:23
  • Beware of the parenthesis, the order or evaluation is not always like you would think, from the error message, I'm guessing that you should have more parenthesis to force the proper order of evaluation – Max L. Jun 16 '11 at 00:02
  • are there some examples around anywhere? i can't find any than trivial examples using google and on the squeryl website! the parenthesis should clearly define the logic. at least it works for SQL... why not for squeryl? – dforce Jun 16 '11 at 07:42
  • finally i got it: `t.x === "a" and (((t.startPos between(83172924, 83336614)) or (t.endPos between(83172924, 83336614))) or ((t.startPos lt 83172924) and ((t.endPos gt 83336614))))`. you need parenthesis around each clause! – dforce Jun 16 '11 at 07:58