Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.1.4
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:Fedora Linux 9, Sun Java 1.6.0_07, JRuby 1.1.4, ActiveRecord-jdbc-adapter 0.8.2, activerecord 2.1.1
-
Testcase included:yes
-
Patch Submitted:Yes
-
Number of attachments :
Description
When using conditions with parameters like
Entry.find(:all, :conditions => ['title = ?', my_expression])
the resulting SQL statement fails on DerbyDB (JavaDB) if the given parameter computes til nil since DerbyDB does not allow comparison with NULL using the equals operator. DerbyDB demands using "IS NULL" when comparing to NULL.
I have attached a patch with test that allows most uses to succeed.
Please review and comment.
SQL has three valued logic, where boolean expressions can be "true", "false" or "NULL" where NULL means "I don't know." It's unfortunate that they chose NULL to denote this, since every where else in computerland it means "no value."
When you say "title = NULL", you're saying "is title equal to some value I don't know?" Of course, if you don't know what you're comparing to, you can't know whether the comparison is true or false. So the result of the expression is not "true" or "false" but NULL. If you want to test whether a value is NULL or not, you use "title is NULL," which always returns true or false.
http://en.wikipedia.org/wiki/Null_(SQL)
Unless I'm misunderstanding the issue...