Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"table.column in Nil" causes MySQLSyntaxErrorException with MySQL #16

Closed
dflemstr opened this issue Jun 5, 2010 · 6 comments
Closed

Comments

@dflemstr
Copy link
Contributor

dflemstr commented Jun 5, 2010

The "in" operator assumes that it will not receive an empty list as its argument, and fails when it does.

@max-l
Copy link
Member

max-l commented Jun 5, 2010

Dave, what behavior would you suggest for an in () ? Should the "in ()" be replace with an expression that evaluates to false ?, ex.: 1=2 ?
notIn(Nil) should then return a tautology : 1=1 ...

@dflemstr
Copy link
Contributor Author

dflemstr commented Jun 7, 2010

Why not just omit the expression node? (The inhibition mechanism might be reusable)

@max-l
Copy link
Member

max-l commented Jun 7, 2010

"in(Nil)" always evaluates to false (it is logically false), omitting the node would evaluate to true, woudln't that be problematic ?

@dflemstr
Copy link
Contributor Author

dflemstr commented Jun 8, 2010

Well, there could be typed inhibitions, so that when "inhibit = Omissive" (bad naming, I know), the node is simply treated as if it would't change the query, and when "inhibit = Destructive", it is treated as if it would make the query not match. ("bar = 1 or foo in ()" should result in "bar = 1" using such transformations, since "or" can have one destructive operand)

Using Kiama (http://code.google.com/p/kiama/) would also be an alternative, especially for query optimizations and clean-ups in general, but maybe a little overkill?

@max-l
Copy link
Member

max-l commented Sep 19, 2010

Fixed as of :
http://github.com/max-l/Squeryl/commit/4cd99be940a3b7e7315290b32c8df7fbea126162

in () ---> always false (results in this condition being written : "(1 = 0)")

notIn () ---> always true (inhibits the condition)

@samhendley
Copy link
Contributor

This only works if its actually a list, if its an Iterable it appears to bypass this check and blows up. An example with Map.keys follows but it seems to happen with any iterable. Workaround is to call .toList on iterable before passing it to squeryl but I dont think it should compile with an iterable if its going to have a runtime fault like this.

test("Empty list inhibition with iterable"){
  transaction {
    FooSchema.reset
    val foo1 = FooSchema.foos.insert(new Foo("test1"))

    val map1 = Map("test1" -> "test1")
    val result1 = FooSchema.foos.where(f => f.value in map1.keys).toList
    result1 should equal(List(foo1))

    //Select
    //  Foo1.data as Foo1_data,
    //  Foo1.id as Foo1_id,
    //  Foo1.value as Foo1_value
    //From
    //  Foo Foo1
    //Where
    //  (Foo1.value in ())   <-- EMPTY!
    intercept[Exception]{
      val map2 = Map.empty[String, String]
      val result2 = FooSchema.foos.where(f => f.value in map2.keys).toList
      result2 should equal(Nil)
    }
  }
}

Full Test Code at https://gist.github.com/795508

Tested against 0.9.4-RC2 and RC3 with mysql adapter.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants