Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle nil values when parsing composite types in the pg_row extensio…

…n (Fixes #548)

Conversion procs are not expected to handle nil values, so they
should not be called if the value is nil.
  • Loading branch information...
commit ed3b8a5fb5ff17f86373086f5f638d43c908799d 1 parent f9baeb5
@jeremyevans authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Handle nil values when parsing composite types in the pg_row extension (jeremyevans) (#548)
+
* Add :disconnect=>:retry option to Database#transaction, for automatically retrying the transaction on disconnect (jeremyevans)
* Greatly improved support on Microsoft Access (jeremyevans)
View
2  lib/sequel/extensions/pg_row.rb
@@ -321,7 +321,7 @@ def _typecast(obj)
# ruby objects, one for each converter.
def convert_columns(arr)
if ccs = @column_converters
- arr.zip(ccs).map{|v, pr| pr ? pr.call(v) : v}
+ arr.zip(ccs).map{|v, pr| (v && pr) ? pr.call(v) : v}
else
arr
end
View
10 spec/extensions/pg_row_spec.rb
@@ -247,6 +247,16 @@
@db.conversion_procs[1].call('(1,b)').should == [{:bar=>1, :baz=>'bb'}]
end
+ it "should handle nil values when converting columns" do
+ @db.conversion_procs[5] = p5 = proc{|s| s * 2}
+ @db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}]]
+ called = false
+ @db.conversion_procs[4] = proc{|s| called = true; s}
+ @db.register_row_type(:foo)
+ @db.conversion_procs[1].call('()').should == {:bar=>nil}
+ called.should be_false
+ end
+
it "should registering array type for row type if type has an array oid" do
@db.conversion_procs[4] = p4 = proc{|s| s.to_i}
@db.conversion_procs[5] = p5 = proc{|s| s * 2}
Please sign in to comment.
Something went wrong with that request. Please try again.