GithubHelp home page GithubHelp logo

Comments (6)

max-l avatar max-l commented on June 24, 2024

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 ...

from squeryl.

dflemstr avatar dflemstr commented on June 24, 2024

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

from squeryl.

max-l avatar max-l commented on June 24, 2024

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

from squeryl.

dflemstr avatar dflemstr commented on June 24, 2024

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?

from squeryl.

max-l avatar max-l commented on June 24, 2024

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)

from squeryl.

samhendley avatar samhendley commented on June 24, 2024

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.

from squeryl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.