Skip to content

Loading…

[DB2] fix db2 = null issue #506

Merged
merged 2 commits into from

2 participants

@pierrickrouxel

Hi,

DB2 doesn't support instructions like

WHERE field = NULL

the correct syntax is

WHERE field IS NULL

Thanks.

@kares
JRuby Team member

Thanks Pierrick, did you test with DB2 as well or "only" AS4k/i ? Cause on "regular" DB2 this should not be needed ...

@pierrickrouxel

I hadn't test but you can get information in this IBM doc :

https://www.ibm.com/developerworks/community/blogs/SQLTips4DB2LUW/entry/null43?lang=en

A colleague who is experimented with DB2 for luw has confirmed the information.

@kares
JRuby Team member

OK ... could we have a test for it than ? THX

@pierrickrouxel

Done... Copied from informix.

@kares kares merged commit 8fcb726 into jruby:master

1 check failed

Details default The Travis CI build failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 28, 2013
  1. @pierrickrouxel

    fix db2 = null issue

    pierrickrouxel committed
Commits on Dec 10, 2013
  1. @pierrickrouxel

    test db2 is null fix

    pierrickrouxel committed
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 0 deletions.
  1. +5 −0 lib/arjdbc/db2/adapter.rb
  2. +16 −0 test/db/db2/simple_test.rb
View
5 lib/arjdbc/db2/adapter.rb
@@ -428,6 +428,11 @@ def runstats_for_table(tablename, priority = 10)
@connection.execute_update "call sysproc.admin_cmd('RUNSTATS ON TABLE #{tablename} WITH DISTRIBUTION AND DETAILED INDEXES ALL UTIL_IMPACT_PRIORITY #{priority}')"
end
+ def select(sql, name, binds)
+ # DB2 does not like "= NULL", "!= NULL", or "<> NULL".
+ exec_query(to_sql(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), binds), name, binds)
+ end
+
def add_index(table_name, column_name, options = {})
if ! zos? || ( table_name.to_s == ActiveRecord::Migrator.schema_migrations_table_name.to_s )
column_name = column_name.to_s if column_name.is_a?(Symbol)
View
16 test/db/db2/simple_test.rb
@@ -114,5 +114,21 @@ def test_find_by_sql_WITH_statement
assert_equal db.id, connection.last_insert_id
#assert_equal e.id, connection.last_insert_id('entries')
end
+
+ # DB2 does not like "= NULL".
+ def test_equals_null
+ Entry.create!(:title => "Foo")
+ entry = Entry.find(:first, :conditions => ["content = NULL"])
+ assert_equal "Foo", entry.title
+ end
+
+ # DB2 does not like "!= NULL" or "<> NULL".
+ def test_not_equals_null
+ Entry.create!(:title => "Foo", :content => "Bar")
+ entry = Entry.find_by_title("Foo", :conditions => ["content != NULL"])
+ assert_equal "Foo", entry.title
+ entry = Entry.find_by_title("Foo", :conditions => ["content <> NULL"])
+ assert_equal "Foo", entry.title
+ end
end
Something went wrong with that request. Please try again.