Skip to content

Commit 1a1deb2

Browse files
committed
[postgres] handle null values in array columns with AR < 4.0 (fixes #548)
1 parent b6bbb4b commit 1a1deb2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.sql.Statement;
3636
import java.sql.Timestamp;
3737
import java.sql.Types;
38-
import java.util.List;
3938
import java.util.Map;
4039
import java.util.UUID;
4140

@@ -463,7 +462,7 @@ protected IRubyObject arrayToRuby(final ThreadContext context,
463462
final Ruby runtime, final ResultSet resultSet, final int column)
464463
throws SQLException {
465464
if ( rawArrayType == Boolean.TRUE ) { // pre AR 4.0 compatibility
466-
return runtime.newString( resultSet.getString(column) );
465+
return stringToRuby(context, runtime, resultSet, column);
467466
}
468467
// NOTE: avoid `finally { array.free(); }` on PostgreSQL due :
469468
// java.sql.SQLFeatureNotSupportedException:

test/db/postgresql/array_compat_test.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def setup
1515
@connection.execute 'ALTER TABLE "pg_arrays" ADD COLUMN "bool_1d" boolean[]'
1616

1717
@connection.execute "INSERT INTO \"pg_arrays\"(bool_1d, str_2d, int_1d) " <<
18-
" VALUES ('{f, t, t}', '{{\"a\",\"b\"}, {\"c\",\"d\"}}', '{1, 2, 3}')"
18+
" VALUES ('{f, t, t}', '{{\"a\",\"b\"}, {\"c\",\"d\"}}', '{1, 2, 3}')"
1919
end
2020

2121
def teardown
@@ -39,4 +39,11 @@ def test_column_values
3939
assert_equal "{f,t,t}", arr.bool_1d
4040
end
4141

42+
def test_null_column_values
43+
arr = PgArray.create; arr.reload
44+
assert_nil arr.str_2d
45+
assert_equal '{}', arr.int_1d # default {}
46+
assert_nil arr.bool_1d
47+
end
48+
4249
end if ActiveRecord::VERSION::MAJOR < 4

0 commit comments

Comments
 (0)