diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-13 07:24:50 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-13 07:24:50 +0000 |
commit | 068d9ef0effb8bfbcaf23f990335c0c867e5a1d7 (patch) | |
tree | f7e117b4b323aa177af2c3a610e1f838a81783bc /activerecord/lib | |
parent | 077ae340e8c3013dd43ebcc8023d183dfdd52d4a (diff) | |
download | rails-068d9ef0effb8bfbcaf23f990335c0c867e5a1d7.tar.gz rails-068d9ef0effb8bfbcaf23f990335c0c867e5a1d7.tar.bz2 rails-068d9ef0effb8bfbcaf23f990335c0c867e5a1d7.zip |
Much faster Oracle column reflection. References #2848.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2996 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/oci_adapter.rb | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/oci_adapter.rb b/activerecord/lib/active_record/connection_adapters/oci_adapter.rb index bdbf6b2e5d..2c6aa83817 100644 --- a/activerecord/lib/active_record/connection_adapters/oci_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/oci_adapter.rb @@ -316,23 +316,29 @@ begin table_name = table_name.to_s.upcase owner = table_name.include?('.') ? "'#{table_name.split('.').first}'" : "user" table = "'#{table_name.split('.').last}'" + scope = (owner == "user" ? "user" : "all") + + table_cols = %Q{ + select column_name, data_type, data_default, nullable, + case when data_type = 'NUMBER' then data_precision + when data_type = 'VARCHAR2' then data_length + else null end as length, + case when data_type = 'NUMBER' then data_scale + else null end as scale + from #{scope}_catalog cat, #{scope}_synonyms syn, all_tab_columns col + where cat.table_name = #{table} + and syn.synonym_name (+)= cat.table_name + and col.table_name = nvl(syn.table_name, cat.table_name) + and col.owner = nvl(syn.table_owner, #{(scope == "all" ? "cat.owner" : "user")}) } + + if scope == "all" + table_cols << %Q{ + and cat.owner = #{owner} + and syn.owner (+)= cat.owner } + end - select_all(%Q{ - select column_name, data_type, data_default, nullable, - case when data_type = 'NUMBER' then data_precision - when data_type = 'VARCHAR2' then data_length - else null end as length, - case when data_type = 'NUMBER' then data_scale - else null end as scale - from all_catalog cat, all_synonyms syn, all_tab_columns col - where cat.owner = #{owner} - and cat.table_name = #{table} - and syn.owner (+)= cat.owner - and syn.synonym_name (+)= cat.table_name - and col.owner = nvl(syn.table_owner, cat.owner) - and col.table_name = nvl(syn.table_name, cat.table_name) - }).map do |row| - row['data_default'].gsub!(/^'(.*)'\s*$/, '\1') if row['data_default'] + select_all(table_cols).map do |row| + row['data_default'].gsub!(/^'(.*)'$/, '\1') if row['data_default'] OCIColumn.new( oci_downcase(row['column_name']), row['data_default'], |