Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: test/simple.rb
- ===================================================================
- --- test/simple.rb (revision 318)
- +++ test/simple.rb (working copy)
- @@ -91,6 +91,7 @@
- assert_equal ["updated_on"], indexes.first.columns
- end
- end
- +
- def test_dumping_schema
- require 'active_record/schema_dumper'
- @connection.add_index :entries, :title
- @@ -106,5 +107,10 @@
- test = AutoId.create('value' => '')
- assert_nil AutoId.find(test.id).value
- end
- +
- + def test_invalid
- + e = Entry.new(:title => @title, :content => @content, :rating => ' ')
- + p e.valid?
- + end
- end
- Index: lib/active_record/connection_adapters/jdbc_adapter.rb
- ===================================================================
- --- lib/active_record/connection_adapters/jdbc_adapter.rb (revision 318)
- +++ lib/active_record/connection_adapters/jdbc_adapter.rb (working copy)
- @@ -94,7 +94,7 @@
- lambda {|r| r['type_name'] =~ /^time$/i},
- lambda {|r| r['type_name'] =~ /^datetime$/i}],
- :date => [ lambda {|r| Jdbc::Types::DATE == r['data_type']},
- - lambda {|r| r['type_name'] =~ /^datetime$/i}],
- + lambda {|r| r['type_name'] =~ /^date$/i}],
- :binary => [ lambda {|r| [Jdbc::Types::LONGVARBINARY,Jdbc::Types::BINARY,Jdbc::Types::BLOB].include?(r['data_type'])},
- lambda {|r| r['type_name'] =~ /^blob/i},
- lambda {|r| r['type_name'] =~ /sub_type 0$/i}, # For FireBird
- @@ -104,8 +104,6 @@
- lambda {|r| r['type_name'] =~ /^bool/i},
- lambda {|r| r['type_name'] =~ /^tinyint$/i},
- lambda {|r| r['type_name'] =~ /^decimal$/i}],
- - :decimal => [ lambda {|r| Jdbc::Types::DECIMAL == r['data_type']},
- - lambda {|r| r['type_name'] =~ /^decimal$/i}]
- }
- def initialize(types)
- @@ -220,7 +218,7 @@
- results = metadata.getColumns(nil, nil, table_name, nil)
- columns = []
- unmarshal_result(results).each do |col|
- - columns << ActiveRecord::ConnectionAdapters::JdbcColumn.new(@config,col['column_name'].downcase, col['column_def'],
- + columns << ActiveRecord::ConnectionAdapters::JdbcColumn.new(@config,col['column_name'], col['column_def'],
- "#{col['type_name']}(#{col['column_size']})", col['is_nullable'] != 'NO')
- end
- columns
- @@ -377,7 +375,7 @@
- column_types << metadata.getColumnType(i)
- column_scale << metadata.getScale(i)
- end
- -
- +
- results = []
- # take all rows if block not supplied
- @@ -389,7 +387,11 @@
- if row_filter.call(resultset)
- row = {}
- 1.upto(column_count) do |i|
- + begin
- row[column_names[i].downcase] = convert_jdbc_type_to_ruby(i, column_types[i], column_scale[i], resultset)
- + rescue
- + puts $!, column_types[i]
- + end
- end
- results << row
- end
- @@ -422,13 +424,20 @@
- results
- end
- - def to_ruby_time(java_date)
- - if java_date
- - tm = java_date.getTime
- + def to_ruby_time(java_time)
- + if java_time
- + tm = java_time.getTime
- Time.at(tm / 1000, (tm % 1000) * 1000)
- end
- end
- + def to_ruby_date(java_date)
- + if java_date
- + # FIXME: This should use Calendar
- + Date.new(java_date.year+1900, java_date.month, java_date.day)
- + end
- + end
- +
- def convert_jdbc_type_to_ruby(row, type, scale, resultset)
- if scale != 0 && type != Jdbc::Types::TIMESTAMP
- decimal = resultset.getString(row)
- @@ -438,9 +447,12 @@
- when Jdbc::Types::CHAR, Jdbc::Types::VARCHAR, Jdbc::Types::LONGVARCHAR, Jdbc::Types::CLOB
- value = resultset.getString(row)
- resultset.wasNull ? nil : value
- - when Jdbc::Types::NUMERIC, Jdbc::Types::BIGINT, Jdbc::Types::DECIMAL
- - value = resultset.getLong(row)
- + when Jdbc::Types::NUMERIC, Jdbc::Types::BIGINT
- + value = resultset.getLong(row)
- resultset.wasNull ? nil : value
- + when Jdbc::Types::DECIMAL
- + value = BigDecimal.new(resultset.getBigDecimal(row))
- + resultset.wasNull ? nil : value
- when Jdbc::Types::SMALLINT, Jdbc::Types::INTEGER
- value = resultset.getInt(row)
- resultset.wasNull ? nil : value
- @@ -451,13 +463,19 @@
- value = resultset.getDouble(row)
- resultset.wasNull ? nil : value
- when Jdbc::Types::TIMESTAMP
- - value = to_ruby_time(resultset.getTimestamp(row))
- - resultset.wasNull ? nil : value
- + # FIXME: This should not be a catchall and it should move this to mysql since it
- + # is catching non-existent date 0000-00:00:00
- + begin
- + value = to_ruby_time(resultset.getTimestamp(row))
- + resultset.wasNull ? nil : value
- + rescue java.sql.SQLException
- + nil
- + end
- when Jdbc::Types::TIME
- value = to_ruby_time(resultset.getTime(row))
- resultset.wasNull ? nil : value
- when Jdbc::Types::DATE
- - value = to_ruby_time(resultset.getDate(row))
- + value = to_ruby_date(resultset.getDate(row))
- resultset.wasNull ? nil : value
- when Jdbc::Types::LONGVARBINARY, Jdbc::Types::BLOB, Jdbc::Types::BINARY, Jdbc::Types::VARBINARY
- value = resultset.getString(row)
- @@ -590,7 +608,7 @@
- end
- def columns(table_name, name = nil)
- - @connection.columns(table_name)
- + @connection.columns(table_name.to_s)
- end
- def tables
Add Comment
Please, Sign In to add comment