Code Monkey home page Code Monkey logo

Comments (17)

pmjones avatar pmjones commented on August 23, 2024

I think that's the correct behavior; there's nothing to quote, after all. What do you suggest?

from aura.sql.

stof avatar stof commented on August 23, 2024

@pmjones The issue is that you are making it transparent to use an array, except for 1 case (which might happen but stay unnoticed when the array is dynamic). For a condition WHERE name IN(?) with an empty array, I would except an empty result set, not a PDOException.
Doctrine DBAL is preparing the statement as IN (NULL), which will produce the expected behavior in case of a positive IN() (being always falsy so rejecting everything). there is still one drawback with this code, when using WHERE a NOT IN(NULL), as NOT IN(NULL) will also be falsy (IN(NULL) will return NULL like for all other SQL operators, and negating NULL is still NULL)

from aura.sql.

pmjones avatar pmjones commented on August 23, 2024

So what are you advocating for here?

from aura.sql.

pmjones avatar pmjones commented on August 23, 2024

(closed by accident sorry)

from aura.sql.

stof avatar stof commented on August 23, 2024

@pmjones well, the best solution could be to figure a way to have a false condition instead of a NULL one. It may be a bit difficult.

In the meantime, the exception would be really confusing as it would be caused by some modification done by Aura while preparing the query (the user would never find IN() in his code).
The other solution would be to throw the exception earlier when binding the value, where you can give a better exception message explaining that binding an empty array is not supported by Aura.Sql. This way, the user would understand the error.

from aura.sql.

pmjones avatar pmjones commented on August 23, 2024

It sounds like the solution easiest to implement would be an exception thrown when quoting an empty array for a bound value. Do you agree with that, or would you prefer something else? (As always, if you have a patch or pull request, I'm happy to review.)

from aura.sql.

pmjones avatar pmjones commented on August 23, 2024

(As a side note, it is not the job of the quoting mechanism to build syntactically correct statements; that's up to the developer.)

from aura.sql.

harikt avatar harikt commented on August 23, 2024

Thank you @stof for the bug report.

Reading all the comments first I thought it will be good to document and add an exception. Looking at how adminer ( by @vrana ) was working when I don't pass any values it worked as @stof mentioning #60 (comment) .

This is a serious case for it is not working as expected though we pass NULL .
We are passing an entirely wrong values and getting wrong values for things like IS NULL should apply . Eg : a field with something can have NULL and may be having values of 1, 2, 3 . In this case IN NULL results should return some values. ( ie also someone will expect )

from aura.sql.

stof avatar stof commented on August 23, 2024

@harikt IN(NULL) always returns NULL (and so is falsy), at least in MySQL. the only operator allowing to check NULL fields is IS, not IN

from aura.sql.

harikt avatar harikt commented on August 23, 2024

yes that is what I also mean. So doesn't that mean we are altering the query.

from aura.sql.

pmjones avatar pmjones commented on August 23, 2024

@stof To reiterate an earlier question: It sounds like the solution easiest to implement would be an exception thrown when quoting an empty array for a bound value. Do you agree with that, or would you prefer something else? (As always, if you have a patch or pull request, I'm happy to review.)

from aura.sql.

stof avatar stof commented on August 23, 2024

@pmjones I think it is fine. It gives a clear error to the user at least. Note that I don't care much about the solution you choose as I don't use Aura.SQL in my projects anyway. I reported the issue because I looked at the package when you announced its v2 and I saw this issue which was faced by Doctrine a few months ago.

from aura.sql.

pmjones avatar pmjones commented on August 23, 2024

I appreciate you taking the time to report it, even as a non-user. Thanks!

from aura.sql.

harikt avatar harikt commented on August 23, 2024

Thank you @stof for reporting it. Your attitude is highly appreciated.

from aura.sql.

Koc avatar Koc commented on August 23, 2024

-1. We shouldn't even make query for an empty set.

from aura.sql.

stof avatar stof commented on August 23, 2024

@Koc -1 on what ? The latest agreement here is to throw a meaningful exception instead of letting PDO failing with a SQL syntax error, so that users understand their mistake

from aura.sql.

Koc avatar Koc commented on August 23, 2024

-1 on adding IN(NULL) by default.

from aura.sql.

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.