activerecord-oracle_enhanced-adapter 1.5.6 → 1.6.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/History.md +87 -0
  4. data/README.md +271 -174
  5. data/VERSION +1 -1
  6. data/activerecord-oracle_enhanced-adapter.gemspec +26 -22
  7. data/lib/active_record/connection_adapters/{oracle_enhanced_column.rb → oracle_enhanced/column.rb} +14 -63
  8. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +65 -0
  9. data/lib/active_record/connection_adapters/{oracle_enhanced_connection.rb → oracle_enhanced/connection.rb} +2 -2
  10. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +347 -0
  11. data/lib/active_record/connection_adapters/{oracle_enhanced_cpk.rb → oracle_enhanced/cpk.rb} +0 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +257 -0
  13. data/lib/active_record/connection_adapters/{oracle_enhanced_database_tasks.rb → oracle_enhanced/database_tasks.rb} +0 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +40 -0
  15. data/lib/active_record/connection_adapters/{oracle_enhanced_jdbc_connection.rb → oracle_enhanced/jdbc_connection.rb} +0 -0
  16. data/lib/active_record/connection_adapters/{oracle_enhanced_oci_connection.rb → oracle_enhanced/oci_connection.rb} +0 -0
  17. data/lib/active_record/connection_adapters/{oracle_enhanced_procedures.rb → oracle_enhanced/procedures.rb} +0 -0
  18. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_creation.rb → oracle_enhanced/schema_creation.rb} +17 -16
  19. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +92 -0
  20. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_dumper.rb → oracle_enhanced/schema_dumper.rb} +4 -32
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +543 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +65 -0
  23. data/lib/active_record/connection_adapters/{oracle_enhanced_structure_dump.rb → oracle_enhanced/structure_dump.rb} +26 -4
  24. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +159 -66
  26. data/lib/active_record/oracle_enhanced/type/integer.rb +13 -0
  27. data/lib/active_record/oracle_enhanced/type/raw.rb +13 -0
  28. data/lib/active_record/oracle_enhanced/type/timestamp.rb +11 -0
  29. data/lib/activerecord-oracle_enhanced-adapter.rb +1 -1
  30. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +6 -31
  31. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +1 -1
  32. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +2 -2
  33. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +2 -2
  34. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +63 -63
  35. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +1 -1
  36. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +7 -13
  37. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +21 -175
  38. data/spec/spec_config.yaml.template +10 -0
  39. data/spec/spec_helper.rb +21 -10
  40. metadata +29 -25
  41. data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +0 -77
  42. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -350
  43. data/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb +0 -262
  44. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -45
  45. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -197
  46. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -450
  47. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
  48. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
@@ -0,0 +1,65 @@
1
+ require 'digest/sha1'
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module OracleEnhancedSchemaStatementsExt
6
+ # Create primary key trigger (so that you can skip primary key value in INSERT statement).
7
+ # By default trigger name will be "table_name_pkt", you can override the name with
8
+ # :trigger_name option (but it is not recommended to override it as then this trigger will
9
+ # not be detected by ActiveRecord model and it will still do prefetching of sequence value).
10
+ #
11
+ # add_primary_key_trigger :users
12
+ #
13
+ # You can also create primary key trigger using +create_table+ with :primary_key_trigger
14
+ # option:
15
+ #
16
+ # create_table :users, :primary_key_trigger => true do |t|
17
+ # # ...
18
+ # end
19
+ #
20
+ def add_primary_key_trigger(table_name, options={})
21
+ # call the same private method that is used for create_table :primary_key_trigger => true
22
+ create_primary_key_trigger(table_name, options)
23
+ end
24
+
25
+ # Add synonym to existing table or view or sequence. Can be used to create local synonym to
26
+ # remote table in other schema or in other database
27
+ # Examples:
28
+ #
29
+ # add_synonym :posts, "blog.posts"
30
+ # add_synonym :posts_seq, "blog.posts_seq"
31
+ # add_synonym :employees, "hr.employees@dblink", :force => true
32
+ #
33
+ def add_synonym(name, table_name, options = {})
34
+ sql = "CREATE"
35
+ if options[:force] == true
36
+ sql << " OR REPLACE"
37
+ end
38
+ sql << " SYNONYM #{quote_table_name(name)} FOR #{quote_table_name(table_name)}"
39
+ execute sql
40
+ end
41
+
42
+ # Remove existing synonym to table or view or sequence
43
+ # Example:
44
+ #
45
+ # remove_synonym :posts, "blog.posts"
46
+ #
47
+ def remove_synonym(name)
48
+ execute "DROP SYNONYM #{quote_table_name(name)}"
49
+ end
50
+
51
+ # get synonyms for schema dump
52
+ def synonyms #:nodoc:
53
+ select_all("SELECT synonym_name, table_owner, table_name, db_link FROM user_synonyms").collect do |row|
54
+ OracleEnhanced::SynonymDefinition.new(oracle_downcase(row['synonym_name']),
55
+ oracle_downcase(row['table_owner']), oracle_downcase(row['table_name']), oracle_downcase(row['db_link']))
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+
63
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
64
+ include ActiveRecord::ConnectionAdapters::OracleEnhancedSchemaStatementsExt
65
+ end
@@ -134,12 +134,34 @@ module ActiveRecord #:nodoc:
134
134
  join_with_statement_token(fks)
135
135
  end
136
136
 
137
- def dump_schema_information #:nodoc:
138
- sm_table = ActiveRecord::Migrator.schema_migrations_table_name
139
- migrated = select_values("SELECT version FROM #{sm_table} ORDER BY version")
140
- join_with_statement_token(migrated.map{|v| "INSERT INTO #{sm_table} (version) VALUES ('#{v}')" })
137
+ def foreign_key_definition(to_table, options = {}) #:nodoc:
138
+ columns = Array(options[:column] || options[:columns])
139
+
140
+ if columns.size > 1
141
+ # composite foreign key
142
+ columns_sql = columns.map {|c| quote_column_name(c)}.join(',')
143
+ references = options[:references] || columns
144
+ references_sql = references.map {|c| quote_column_name(c)}.join(',')
145
+ else
146
+ columns_sql = quote_column_name(columns.first || "#{to_table.to_s.singularize}_id")
147
+ references = options[:references] ? options[:references].first : nil
148
+ references_sql = quote_column_name(options[:primary_key] || references || "id")
149
+ end
150
+
151
+ table_name = to_table
152
+
153
+ sql = "FOREIGN KEY (#{columns_sql}) REFERENCES #{quote_table_name(table_name)}(#{references_sql})"
154
+
155
+ case options[:dependent]
156
+ when :nullify
157
+ sql << " ON DELETE SET NULL"
158
+ when :delete
159
+ sql << " ON DELETE CASCADE"
160
+ end
161
+ sql
141
162
  end
142
163
 
164
+
143
165
  # Extract all stored procedures, packages, synonyms and views.
144
166
  def structure_dump_db_stored_code #:nodoc:
145
167
  structure = []
@@ -0,0 +1 @@
1
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::VERSION = File.read(File.expand_path('../../../../../VERSION', __FILE__)).chomp
@@ -30,9 +30,13 @@
30
30
  # portions Copyright 2005 Graham Jenkins
31
31
 
32
32
  require 'active_record/connection_adapters/abstract_adapter'
33
- require 'active_record/connection_adapters/oracle_enhanced_connection'
33
+ require 'active_record/connection_adapters/oracle_enhanced/connection'
34
+ require 'active_record/connection_adapters/oracle_enhanced/database_statements'
35
+ require 'active_record/connection_adapters/oracle_enhanced/schema_statements'
36
+ require 'active_record/connection_adapters/oracle_enhanced/column_dumper'
37
+ require 'active_record/connection_adapters/oracle_enhanced/context_index'
34
38
 
35
- require 'active_record/connection_adapters/oracle_enhanced_column'
39
+ require 'active_record/connection_adapters/oracle_enhanced/column'
36
40
 
37
41
  require 'digest/sha1'
38
42
 
@@ -131,7 +135,7 @@ module ActiveRecord
131
135
 
132
136
  def record_changed_lobs
133
137
  @changed_lob_columns = self.class.lob_columns.select do |col|
134
- (self.class.serialized_attributes.keys.include?(col.name) || self.send(:"#{col.name}_changed?")) && !self.class.readonly_attributes.to_a.include?(col.name)
138
+ self.attribute_changed?(col.name) && !self.class.readonly_attributes.to_a.include?(col.name)
135
139
  end
136
140
  end
137
141
  end
@@ -218,6 +222,15 @@ module ActiveRecord
218
222
  # * <tt>:nls_time_tz_format</tt>
219
223
  #
220
224
  class OracleEnhancedAdapter < AbstractAdapter
225
+ # TODO: Use relative
226
+ include ActiveRecord::ConnectionAdapters::OracleEnhanced::DatabaseStatements
227
+ include ActiveRecord::ConnectionAdapters::OracleEnhanced::SchemaStatements
228
+ include ActiveRecord::ConnectionAdapters::OracleEnhanced::ColumnDumper
229
+ include ActiveRecord::ConnectionAdapters::OracleEnhanced::ContextIndex
230
+
231
+ def schema_creation
232
+ OracleEnhanced::SchemaCreation.new self
233
+ end
221
234
 
222
235
  ##
223
236
  # :singleton-method:
@@ -270,13 +283,6 @@ module ActiveRecord
270
283
  cattr_accessor :emulate_dates_by_column_name
271
284
  self.emulate_dates_by_column_name = false
272
285
 
273
- ##
274
- # :singleton-method:
275
- # Specify how `NUMBER` datatype columns, without precision and scale, are handled in Rails world.
276
- # Default is :decimal and other valid option is :float. Be wary of setting it to other values.
277
- cattr_accessor :number_datatype_coercion
278
- self.number_datatype_coercion = :decimal
279
-
280
286
  # Check column name to identify if it is Date (and not Time) column.
281
287
  # Is used if +emulate_dates_by_column_name+ option is set to +true+.
282
288
  # Override this method definition in initializer file if different Date column recognition is needed.
@@ -311,7 +317,7 @@ module ActiveRecord
311
317
  # Is used if +emulate_integers_by_column_name+ option is set to +true+.
312
318
  # Override this method definition in initializer file if different Integer column recognition is needed.
313
319
  def self.is_integer_column?(name, table_name = nil)
314
- !!(name =~ /(^|_)id$/i)
320
+ name =~ /(^|_)id$/i
315
321
  end
316
322
 
317
323
  ##
@@ -326,9 +332,9 @@ module ActiveRecord
326
332
  # Check column name to identify if it is boolean (and not String) column.
327
333
  # Is used if +emulate_booleans_from_strings+ option is set to +true+.
328
334
  # Override this method definition in initializer file if different boolean column recognition is needed.
329
- def self.is_boolean_column?(name, field_type, table_name = nil)
330
- return true if ["CHAR(1)","VARCHAR2(1)"].include?(field_type)
331
- field_type =~ /^VARCHAR2/ && (name =~ /_flag$/i || name =~ /_yn$/i)
335
+ def self.is_boolean_column?(name, sql_type, table_name = nil)
336
+ return true if ["CHAR(1)","VARCHAR2(1)"].include?(sql_type)
337
+ sql_type =~ /^VARCHAR2/ && (name =~ /_flag$/i || name =~ /_yn$/i)
332
338
  end
333
339
 
334
340
  # How boolean value should be quoted to String.
@@ -383,21 +389,18 @@ module ActiveRecord
383
389
  end
384
390
  end
385
391
 
386
- class BindSubstitution < Arel::Visitors::Oracle #:nodoc:
387
- include Arel::Visitors::BindVisitor
388
- end
389
-
390
392
  def initialize(connection, logger, config) #:nodoc:
391
393
  super(connection, logger)
392
394
  @quoted_column_names, @quoted_table_names = {}, {}
393
395
  @config = config
394
396
  @statements = StatementPool.new(connection, config.fetch(:statement_limit) { 250 })
395
397
  @enable_dbms_output = false
396
- if config.fetch(:prepared_statements) { true }
397
- @visitor = Arel::Visitors::Oracle.new self
398
+ @visitor = Arel::Visitors::Oracle.new self
399
+
400
+ if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
398
401
  @prepared_statements = true
399
402
  else
400
- @visitor = unprepared_visitor
403
+ @prepared_statements = false
401
404
  end
402
405
  end
403
406
 
@@ -423,7 +426,13 @@ module ActiveRecord
423
426
  true
424
427
  end
425
428
 
426
- NUMBER_MAX_PRECISION = 38
429
+ def supports_foreign_keys?
430
+ true
431
+ end
432
+
433
+ def supports_views?
434
+ true
435
+ end
427
436
 
428
437
  #:stopdoc:
429
438
  DEFAULT_NLS_PARAMETERS = {
@@ -448,11 +457,11 @@ module ActiveRecord
448
457
 
449
458
  #:stopdoc:
450
459
  NATIVE_DATABASE_TYPES = {
451
- :primary_key => "NUMBER(#{NUMBER_MAX_PRECISION}) NOT NULL PRIMARY KEY",
460
+ :primary_key => "NUMBER(38) NOT NULL PRIMARY KEY",
452
461
  :string => { :name => "VARCHAR2", :limit => 255 },
453
462
  :text => { :name => "CLOB" },
454
- :integer => { :name => "NUMBER", :limit => NUMBER_MAX_PRECISION },
455
- :float => { :name => "NUMBER" },
463
+ :integer => { :name => "NUMBER", :limit => 38 },
464
+ :float => { :name => "BINARY_FLOAT" },
456
465
  :decimal => { :name => "DECIMAL" },
457
466
  :datetime => { :name => "DATE" },
458
467
  # changed to native TIMESTAMP type
@@ -462,7 +471,8 @@ module ActiveRecord
462
471
  :date => { :name => "DATE" },
463
472
  :binary => { :name => "BLOB" },
464
473
  :boolean => { :name => "NUMBER", :limit => 1 },
465
- :raw => { :name => "RAW", :limit => 2000 }
474
+ :raw => { :name => "RAW", :limit => 2000 },
475
+ :bigint => { :name => "NUMBER", :limit => 19 }
466
476
  }
467
477
  # if emulate_booleans_from_strings then store booleans in VARCHAR2
468
478
  NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS = NATIVE_DATABASE_TYPES.dup.merge(
@@ -667,22 +677,26 @@ module ActiveRecord
667
677
 
668
678
  # Cast a +value+ to a type that the database understands.
669
679
  def type_cast(value, column)
670
- case value
671
- when true, false
672
- if emulate_booleans_from_strings || column && column.type == :string
673
- self.class.boolean_to_string(value)
674
- else
675
- value ? 1 : 0
676
- end
677
- when Date, Time
678
- if value.acts_like?(:time)
679
- zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
680
- value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
680
+ if column && column.cast_type.is_a?(Type::Serialized)
681
+ super
682
+ else
683
+ case value
684
+ when true, false
685
+ if emulate_booleans_from_strings || column && column.type == :string
686
+ self.class.boolean_to_string(value)
687
+ else
688
+ value ? 1 : 0
689
+ end
690
+ when Date, Time
691
+ if value.acts_like?(:time)
692
+ zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
693
+ value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
694
+ else
695
+ value
696
+ end
681
697
  else
682
- value
698
+ super
683
699
  end
684
- else
685
- super
686
700
  end
687
701
  end
688
702
 
@@ -812,7 +826,7 @@ module ActiveRecord
812
826
  value = attributes[col.name]
813
827
  # changed sequence of next two lines - should check if value is nil before converting to yaml
814
828
  next if value.nil? || (value == '')
815
- value = value.to_yaml if col.text? && klass.serialized_attributes[col.name]
829
+ value = value.to_yaml if value.is_a?(String) && klass.serialized_attributes[col.name]
816
830
  uncached do
817
831
  sql = is_with_cpk ? "SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)} WHERE #{klass.composite_where_clause(id)} FOR UPDATE" :
818
832
  "SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)} WHERE #{quote_column_name(klass.primary_key)} = #{id} FOR UPDATE"
@@ -906,7 +920,7 @@ module ActiveRecord
906
920
  statement_parameters = $1
907
921
  end
908
922
  end
909
- all_schema_indexes << OracleEnhancedIndexDefinition.new(row['table_name'], row['index_name'],
923
+ all_schema_indexes << OracleEnhanced::IndexDefinition.new(row['table_name'], row['index_name'],
910
924
  row['uniqueness'] == "UNIQUE", row['index_type'] == 'DOMAIN' ? "#{row['ityp_owner']}.#{row['ityp_name']}" : nil,
911
925
  row['parameters'], statement_parameters,
912
926
  row['tablespace_name'] == default_tablespace_name ? nil : row['tablespace_name'], [])
@@ -1038,7 +1052,7 @@ module ActiveRecord
1038
1052
  end.map do |row|
1039
1053
  limit, scale = row['limit'], row['scale']
1040
1054
  if limit || scale
1041
- row['sql_type'] += "(#{(limit || NUMBER_MAX_PRECISION).to_i}" + ((scale = scale.to_i) > 0 ? ",#{scale})" : ")")
1055
+ row['sql_type'] += "(#{(limit || 38).to_i}" + ((scale = scale.to_i) > 0 ? ",#{scale})" : ")")
1042
1056
  end
1043
1057
 
1044
1058
  if row['sql_type_owner']
@@ -1055,19 +1069,61 @@ module ActiveRecord
1055
1069
  # match newlines.
1056
1070
  row['data_default'].sub!(/^'(.*)'$/m, '\1')
1057
1071
  row['data_default'] = nil if row['data_default'] =~ /^(null|empty_[bc]lob\(\))$/i
1072
+ # TODO: Needs better fix to fallback "N" to false
1073
+ row['data_default'] = false if row['data_default'] == "N"
1074
+ end
1075
+
1076
+ # TODO: Consider to extract another method such as `get_cast_type`
1077
+ case row['sql_type']
1078
+ when /decimal|numeric|number/i
1079
+ if get_type_for_column(table_name, oracle_downcase(row['name'])) == :integer
1080
+ cast_type = ActiveRecord::OracleEnhanced::Type::Integer.new
1081
+ elsif OracleEnhancedAdapter.emulate_booleans && row['sql_type'].upcase == "NUMBER(1)"
1082
+ cast_type = Type::Boolean.new
1083
+ elsif OracleEnhancedAdapter.emulate_integers_by_column_name && OracleEnhancedAdapter.is_integer_column?(row['name'], table_name)
1084
+ cast_type = ActiveRecord::OracleEnhanced::Type::Integer.new
1085
+ else
1086
+ cast_type = lookup_cast_type(row['sql_type'])
1087
+ end
1088
+ when /char/i
1089
+ if get_type_for_column(table_name, oracle_downcase(row['name'])) == :string
1090
+ cast_type = Type::String.new
1091
+ elsif get_type_for_column(table_name, oracle_downcase(row['name'])) == :boolean
1092
+ cast_type = Type::Boolean.new
1093
+ elsif OracleEnhancedAdapter.emulate_booleans_from_strings && OracleEnhancedAdapter.is_boolean_column?(row['name'], row['sql_type'], table_name)
1094
+ cast_type = Type::Boolean.new
1095
+ else
1096
+ cast_type = lookup_cast_type(row['sql_type'])
1097
+ end
1098
+ when /date/i
1099
+ if get_type_for_column(table_name, oracle_downcase(row['name'])) == :date
1100
+ cast_type = Type::Date.new
1101
+ elsif get_type_for_column(table_name, oracle_downcase(row['name'])) == :datetime
1102
+ cast_type = Type::DateTime.new
1103
+ elsif OracleEnhancedAdapter.emulate_dates_by_column_name && OracleEnhancedAdapter.is_date_column?(row['name'], table_name)
1104
+ cast_type = Type::Date.new
1105
+ else
1106
+ cast_type = lookup_cast_type(row['sql_type'])
1107
+ end
1108
+ else
1109
+ cast_type = lookup_cast_type(row['sql_type'])
1058
1110
  end
1059
1111
 
1060
- OracleEnhancedColumn.new(oracle_downcase(row['name']),
1112
+ new_column(oracle_downcase(row['name']),
1061
1113
  row['data_default'],
1114
+ cast_type,
1062
1115
  row['sql_type'],
1063
1116
  row['nullable'] == 'Y',
1064
- # pass table name for table specific column definitions
1065
1117
  table_name,
1066
- # pass column type if specified in class definition
1067
- get_type_for_column(table_name, oracle_downcase(row['name'])), is_virtual)
1118
+ is_virtual,
1119
+ false )
1068
1120
  end
1069
1121
  end
1070
1122
 
1123
+ def new_column(name, default, cast_type, sql_type = nil, null = true, table_name = nil, virtual=false, returning_id=false)
1124
+ OracleEnhancedColumn.new(name, default, cast_type, sql_type, null, table_name, virtual, returning_id)
1125
+ end
1126
+
1071
1127
  # used just in tests to clear column cache
1072
1128
  def clear_columns_cache #:nodoc:
1073
1129
  @@columns_cache = nil
@@ -1207,6 +1263,34 @@ module ActiveRecord
1207
1263
 
1208
1264
  protected
1209
1265
 
1266
+ def initialize_type_map(m)
1267
+ super
1268
+ # oracle
1269
+ register_class_with_limit m, %r(date)i, Type::DateTime
1270
+ register_class_with_limit m, %r(raw)i, ActiveRecord::OracleEnhanced::Type::Raw
1271
+ register_class_with_limit m, %r(timestamp)i, ActiveRecord::OracleEnhanced::Type::Timestamp
1272
+
1273
+ m.register_type(%r(NUMBER)i) do |sql_type|
1274
+ scale = extract_scale(sql_type)
1275
+ precision = extract_precision(sql_type)
1276
+ limit = extract_limit(sql_type)
1277
+ if scale == 0
1278
+ ActiveRecord::OracleEnhanced::Type::Integer.new(precision: precision, limit: limit)
1279
+ else
1280
+ Type::Decimal.new(precision: precision, scale: scale)
1281
+ end
1282
+ end
1283
+ end
1284
+
1285
+ def extract_limit(sql_type) #:nodoc:
1286
+ case sql_type
1287
+ when /^bigint/i
1288
+ 19
1289
+ when /\((.*)\)/
1290
+ $1.to_i
1291
+ end
1292
+ end
1293
+
1210
1294
  def translate_exception(exception, message) #:nodoc:
1211
1295
  case @connection.error_code(exception)
1212
1296
  when 1
@@ -1220,6 +1304,10 @@ module ActiveRecord
1220
1304
 
1221
1305
  private
1222
1306
 
1307
+ def select(sql, name = nil, binds = [])
1308
+ exec_query(sql, name, binds)
1309
+ end
1310
+
1223
1311
  def oracle_downcase(column_name)
1224
1312
  @connection.oracle_downcase(column_name)
1225
1313
  end
@@ -1256,12 +1344,8 @@ module ActiveRecord
1256
1344
  end
1257
1345
 
1258
1346
  protected
1259
- def log(sql, name, binds = nil) #:nodoc:
1260
- if binds
1261
- super sql, name, binds
1262
- else
1263
- super sql, name
1264
- end
1347
+ def log(sql, name = "SQL", binds = [], statement_name = nil) #:nodoc:
1348
+ super
1265
1349
  ensure
1266
1350
  log_dbms_output if dbms_output_enabled?
1267
1351
  end
@@ -1289,38 +1373,47 @@ module ActiveRecord
1289
1373
  end
1290
1374
 
1291
1375
  # Implementation of standard schema definition statements and extensions for schema definition
1292
- require 'active_record/connection_adapters/oracle_enhanced_schema_statements'
1293
- require 'active_record/connection_adapters/oracle_enhanced_schema_statements_ext'
1376
+ require 'active_record/connection_adapters/oracle_enhanced/schema_statements'
1377
+ require 'active_record/connection_adapters/oracle_enhanced/schema_statements_ext'
1294
1378
 
1295
1379
  # Extensions for schema definition
1296
- require 'active_record/connection_adapters/oracle_enhanced_schema_definitions'
1380
+ require 'active_record/connection_adapters/oracle_enhanced/schema_definitions'
1297
1381
 
1298
1382
  # Extensions for context index definition
1299
- require 'active_record/connection_adapters/oracle_enhanced_context_index'
1383
+ require 'active_record/connection_adapters/oracle_enhanced/context_index'
1300
1384
 
1301
1385
  # Load additional methods for composite_primary_keys support
1302
- require 'active_record/connection_adapters/oracle_enhanced_cpk'
1386
+ require 'active_record/connection_adapters/oracle_enhanced/cpk'
1303
1387
 
1304
1388
  # Load patch for dirty tracking methods
1305
- require 'active_record/connection_adapters/oracle_enhanced_dirty'
1389
+ require 'active_record/connection_adapters/oracle_enhanced/dirty'
1306
1390
 
1307
1391
  # Patches and enhancements for schema dumper
1308
- require 'active_record/connection_adapters/oracle_enhanced_schema_dumper'
1392
+ require 'active_record/connection_adapters/oracle_enhanced/schema_dumper'
1309
1393
 
1310
1394
  # Implementation of structure dump
1311
- require 'active_record/connection_adapters/oracle_enhanced_structure_dump'
1395
+ require 'active_record/connection_adapters/oracle_enhanced/structure_dump'
1312
1396
 
1313
- require 'active_record/connection_adapters/oracle_enhanced_version'
1397
+ require 'active_record/connection_adapters/oracle_enhanced/version'
1314
1398
 
1315
1399
  module ActiveRecord
1316
- autoload :OracleEnhancedProcedures, 'active_record/connection_adapters/oracle_enhanced_procedures'
1400
+ autoload :OracleEnhancedProcedures, 'active_record/connection_adapters/oracle_enhanced/procedures'
1317
1401
  end
1318
1402
 
1319
1403
  # Patches and enhancements for column dumper
1320
- require 'active_record/connection_adapters/oracle_enhanced_column_dumper'
1404
+ require 'active_record/connection_adapters/oracle_enhanced/column_dumper'
1321
1405
 
1322
1406
  # Moved SchemaCreation class
1323
- require 'active_record/connection_adapters/oracle_enhanced_schema_creation'
1407
+ require 'active_record/connection_adapters/oracle_enhanced/schema_creation'
1324
1408
 
1325
1409
  # Moved DatabaseStetements
1326
- require 'active_record/connection_adapters/oracle_enhanced_database_statements'
1410
+ require 'active_record/connection_adapters/oracle_enhanced/database_statements'
1411
+
1412
+ # Add Type:Raw
1413
+ require 'active_record/oracle_enhanced/type/raw'
1414
+
1415
+ # Add Type:Timestamp
1416
+ require 'active_record/oracle_enhanced/type/timestamp'
1417
+
1418
+ # Add OracleEnhanced::Type::Integer
1419
+ require 'active_record/oracle_enhanced/type/integer'