Diff
Modified: trunk/activerecord-jdbc/lib/active_record/connection_adapters/jdbc_adapter.rb (636 => 637)
--- trunk/activerecord-jdbc/lib/active_record/connection_adapters/jdbc_adapter.rb 2007-06-18 13:29:57 UTC (rev 636)
+++ trunk/activerecord-jdbc/lib/active_record/connection_adapters/jdbc_adapter.rb 2007-06-19 07:57:41 UTC (rev 637)
@@ -5,6 +5,37 @@
require 'bigdecimal'
module ActiveRecord
+ module ConnectionAdapters # :nodoc:
+ module SchemaStatements
+ # The original implementation of this had a bug, which modifies native_database_types.
+ # This version allows us to cache that value.
+ def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
+ native = native_database_types[type]
+ column_type_sql = native.is_a?(Hash) ? native[:name] : native
+ if type == :decimal # ignore limit, use precison and scale
+ precision ||= native[:precision]
+ scale ||= native[:scale]
+ if precision
+ if scale
+ column_type_sql += "(#{precision},#{scale})"
+ else
+ column_type_sql += "(#{precision})"
+ end
+ else
+ raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" if scale
+ end
+ column_type_sql
+ else
+ limit ||= native[:limit]
+ column_type_sql += "(#{limit})" if limit
+ column_type_sql
+ end
+ end
+ end
+ end
+end
+
+module ActiveRecord
class Base
def self.jdbc_connection(config)
connection = ConnectionAdapters::JdbcConnection.new(config)
Modified: trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb (636 => 637)
--- trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb 2007-06-18 13:29:57 UTC (rev 636)
+++ trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_derby.rb 2007-06-19 07:57:41 UTC (rev 637)
@@ -33,7 +33,7 @@
module Column
def type_cast(value)
- return nil if value.nil? || value =~ /^\s*null\s*$/i
+ return nil if value.nil? || value.to_s.strip.downcase == 'null'
case type
when :string then value
when :text then value
@@ -372,25 +372,8 @@
drop_table t
end
end
-
- def native_database_types #:nodoc:
- {
- :primary_key=>"int generated by default as identity NOT NULL PRIMARY KEY",
- :float=>{:name=>"real"},
- :date=>{:name=>"date"},
- :integer=>{:limit=>nil, :name=>"integer"},
- :datetime=>{:name=>"timestamp"},
- :timestamp=>{:name=>"timestamp"},
- :text=>{:name=>"clob"},
- :boolean=>{:name=>"smallint"},
- :time=>{:name=>"time"},
- :decimal=>{:limit=>31, :name=>"decimal"},
- :string=>{:limit=>256, :name=>"varchar"},
- :binary=>{:name=>"blob"}
- }
- end
-
-# For DDL it appears you can quote "" column names, but in queries (like insert it errors out?)
+
+ # For DDL it appears you can quote "" column names, but in queries (like insert it errors out?)
def quote_column_name(name) #:nodoc:
if /^references$/i =~ name
%Q{"#{name.upcase}"}
@@ -398,10 +381,8 @@
%Q{"#{name}"}
elsif name =~ /\s/
%Q{"#{name.upcase}"}
- elsif name =~ /^_/
+ elsif name =~ /^[_\d]/
%Q{"#{name.upcase}"}
- elsif name =~ /^\d/
- %Q{"#{name.upcase}"}
else
name
end
Modified: trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_mysql.rb (636 => 637)
--- trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_mysql.rb 2007-06-18 13:29:57 UTC (rev 636)
+++ trunk/activerecord-jdbc/lib/jdbc_adapter/jdbc_mysql.rb 2007-06-19 07:57:41 UTC (rev 637)
@@ -138,23 +138,6 @@
end
end
- def native_database_types #:nodoc:
- {
- :primary_key => "int(11) DEFAULT NULL auto_increment PRIMARY KEY",
- :string => { :name => "varchar", :limit => 255 },
- :text => { :name => "text" },
- :integer => { :name => "int", :limit => 11 },
- :float => { :name => "float" },
- :decimal => { :name => "decimal" },
- :datetime => { :name => "datetime" },
- :timestamp => { :name => "datetime" },
- :time => { :name => "time" },
- :date => { :name => "date" },
- :binary => { :name => "blob" },
- :boolean => { :name => "tinyint", :limit => 1 }
- }
- end
-
private
def supports_views?
false
Modified: trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java (636 => 637)
--- trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java 2007-06-18 13:29:57 UTC (rev 636)
+++ trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java 2007-06-19 07:57:41 UTC (rev 637)
@@ -171,27 +171,8 @@
}
}
- /*
- # The hacks in this method is needed because of a bug in Rails. Check
- # out type_to_sql in schema_statements.rb and see if you can see it... =)
- */
public static IRubyObject native_database_types(IRubyObject recv) {
- RubyHash tps = (RubyHash)recv.getInstanceVariable("@tps");
- Map val = new HashMap();
- Ruby runtime = recv.getRuntime();
- IRubyObject nameSym = runtime.newSymbol("name");
- for(Iterator iter = tps.directEntrySet().iterator();iter.hasNext();) {
- Map.Entry me = (Map.Entry)iter.next();
- IRubyObject v = (IRubyObject)me.getValue();
- if(v instanceof RubyHash) {
- RubyHash v2 = (RubyHash)(v.dup());
- v2.put(nameSym, ((IRubyObject)(v2.fastARef(nameSym))).dup());
- val.put(me.getKey(), v2);
- } else {
- val.put(me.getKey(), ((IRubyObject)v).dup());
- }
- }
- return RubyHash.newHash(runtime, val, runtime.getNil());
+ return recv.getInstanceVariable("@tps");
}
public static IRubyObject set_native_database_types(IRubyObject recv) throws SQLException, IOException {
Modified: trunk/activerecord-jdbc/test/activerecord/connection_adapters/type_conversion_test.rb (636 => 637)
--- trunk/activerecord-jdbc/test/activerecord/connection_adapters/type_conversion_test.rb 2007-06-18 13:29:57 UTC (rev 636)
+++ trunk/activerecord-jdbc/test/activerecord/connection_adapters/type_conversion_test.rb 2007-06-19 07:57:41 UTC (rev 637)
@@ -1,5 +1,6 @@
require 'java'
require 'models/data_types'
+require 'active_record/connection_adapters/jdbc_adapter'
require 'db/derby'
require 'test/unit'