activerecord-oracle_enhanced-adapter 1.7.11 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +206 -4
- data/README.md +37 -1
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +7 -59
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -50
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +11 -11
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -117
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +37 -27
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +10 -10
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +56 -71
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +0 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +51 -69
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +76 -76
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +14 -43
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -64
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -47
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +150 -160
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +95 -133
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +66 -101
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +290 -533
- data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -10
- data/lib/active_record/oracle_enhanced/type/integer.rb +3 -4
- data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
- data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -1
- data/lib/active_record/oracle_enhanced/type/raw.rb +2 -3
- data/lib/active_record/oracle_enhanced/type/string.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/text.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/timestamptz.rb +23 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +55 -162
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +32 -34
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +44 -42
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +250 -357
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -6
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -5
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +115 -124
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +68 -72
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +64 -80
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +223 -329
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +18 -20
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +59 -59
- data/spec/support/alter_system_user_password.sql +2 -0
- data/spec/support/create_oracle_enhanced_users.sql +31 -0
- metadata +25 -25
- data/.rspec +0 -2
- data/Gemfile +0 -22
- data/RUNNING_TESTS.md +0 -83
- data/Rakefile +0 -45
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -94
- data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -19
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
@@ -2,27 +2,26 @@ begin
|
|
2
2
|
require "java"
|
3
3
|
require "jruby"
|
4
4
|
|
5
|
-
# ojdbc7.jar
|
5
|
+
# ojdbc7.jar or ojdbc6.jar file should be in application ./lib directory or in load path or in ENV['PATH']
|
6
6
|
|
7
7
|
java_version = java.lang.System.getProperty("java.version")
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
elsif java_version >= '1.7'
|
13
|
-
# Oracle 11g client ojdbc6.jar is also compatible with Java 1.7
|
14
|
-
# Oracle 12c client provides new ojdbc7.jar
|
15
|
-
%w(ojdbc7.jar ojdbc6.jar)
|
16
|
-
else
|
17
|
-
nil
|
8
|
+
# Dropping Java SE 6(1.6) or older version without deprecation cycle.
|
9
|
+
# Rails 5.0 already requires CRuby 2.2.2 or higher and JRuby 9.0 supporging CRuby 2.2 requires Java SE 7.
|
10
|
+
if java_version < "1.7"
|
11
|
+
raise "ERROR: Java SE 6 or older version is not supported. Upgrade Java version to Java SE 7 or higher"
|
18
12
|
end
|
19
13
|
|
20
|
-
|
14
|
+
# Oracle 11g client ojdbc6.jar is also compatible with Java 1.7
|
15
|
+
# Oracle 12c Release 1 client provides ojdbc7.jar
|
16
|
+
# Oracle 12c Release 2 client provides ojdbc8.jar
|
17
|
+
ojdbc_jars = %w(ojdbc8.jar ojdbc7.jar ojdbc6.jar)
|
18
|
+
|
19
|
+
if ENV_JAVA["java.class.path"] !~ Regexp.new(ojdbc_jars.join("|"))
|
21
20
|
# On Unix environment variable should be PATH, on Windows it is sometimes Path
|
22
|
-
env_path = (ENV["PATH"] || ENV["Path"] ||
|
21
|
+
env_path = (ENV["PATH"] || ENV["Path"] || "").split(File::PATH_SEPARATOR)
|
23
22
|
# Look for JDBC driver at first in lib subdirectory (application specific JDBC file version)
|
24
23
|
# then in Ruby load path and finally in environment PATH
|
25
|
-
[
|
24
|
+
["./lib"].concat($LOAD_PATH).concat(env_path).detect do |dir|
|
26
25
|
# check any compatible JDBC driver in the priority order
|
27
26
|
ojdbc_jars.any? do |ojdbc_jar|
|
28
27
|
if File.exists?(file_path = File.join(dir, ojdbc_jar))
|
@@ -43,7 +42,7 @@ begin
|
|
43
42
|
|
44
43
|
rescue LoadError, NameError
|
45
44
|
# JDBC driver is unavailable.
|
46
|
-
raise LoadError, "ERROR: ActiveRecord oracle_enhanced adapter could not load Oracle JDBC driver. Please install #{ojdbc_jars
|
45
|
+
raise LoadError, "ERROR: ActiveRecord oracle_enhanced adapter could not load Oracle JDBC driver. Please install #{ojdbc_jars.join(' or ') } library."
|
47
46
|
end
|
48
47
|
|
49
48
|
module ActiveRecord
|
@@ -74,7 +73,7 @@ module ActiveRecord
|
|
74
73
|
|
75
74
|
# tomcat needs first lookup method, oc4j (and maybe other application servers) need second method
|
76
75
|
begin
|
77
|
-
env = ctx.lookup(
|
76
|
+
env = ctx.lookup("java:/comp/env")
|
78
77
|
ds = env.lookup(jndi)
|
79
78
|
rescue
|
80
79
|
ds = ctx.lookup(jndi)
|
@@ -102,13 +101,13 @@ module ActiveRecord
|
|
102
101
|
# to_s needed if username, password or database is specified as number in database.yml file
|
103
102
|
username = config[:username] && config[:username].to_s
|
104
103
|
password = config[:password] && config[:password].to_s
|
105
|
-
database = config[:database] && config[:database].to_s ||
|
104
|
+
database = config[:database] && config[:database].to_s || "XE"
|
106
105
|
host, port = config[:host], config[:port]
|
107
106
|
privilege = config[:privilege] && config[:privilege].to_s
|
108
107
|
|
109
108
|
# connection using TNS alias, or connection-string from DATABASE_URL
|
110
|
-
using_tns_alias = !host && !config[:url] && ENV[
|
111
|
-
if database && (using_tns_alias || host ==
|
109
|
+
using_tns_alias = !host && !config[:url] && ENV["TNS_ADMIN"]
|
110
|
+
if database && (using_tns_alias || host == "connection-string")
|
112
111
|
url = "jdbc:oracle:thin:@#{database}"
|
113
112
|
else
|
114
113
|
unless database.match(/^(\:|\/)/)
|
@@ -120,7 +119,7 @@ module ActiveRecord
|
|
120
119
|
|
121
120
|
prefetch_rows = config[:prefetch_rows] || 100
|
122
121
|
# get session time_zone from configuration or from TZ environment variable
|
123
|
-
time_zone = config[:time_zone] || ENV[
|
122
|
+
time_zone = config[:time_zone] || ENV["TZ"] || java.util.TimeZone.default.getID
|
124
123
|
|
125
124
|
properties = java.util.Properties.new
|
126
125
|
properties.put("user", username)
|
@@ -138,13 +137,17 @@ module ActiveRecord
|
|
138
137
|
end
|
139
138
|
|
140
139
|
# Set session time zone to current time zone
|
141
|
-
|
140
|
+
if ActiveRecord::Base.default_timezone == :local
|
141
|
+
@raw_connection.setSessionTimeZone(time_zone)
|
142
|
+
elsif ActiveRecord::Base.default_timezone == :utc
|
143
|
+
@raw_connection.setSessionTimeZone("UTC")
|
144
|
+
end
|
142
145
|
|
143
146
|
# Set default number of rows to prefetch
|
144
147
|
# @raw_connection.setDefaultRowPrefetch(prefetch_rows) if prefetch_rows
|
145
148
|
end
|
146
149
|
|
147
|
-
cursor_sharing = config[:cursor_sharing] ||
|
150
|
+
cursor_sharing = config[:cursor_sharing] || "force"
|
148
151
|
exec "alter session set cursor_sharing = #{cursor_sharing}"
|
149
152
|
|
150
153
|
# Initialize NLS parameters
|
@@ -327,7 +330,7 @@ module ActiveRecord
|
|
327
330
|
@raw_statement = raw_statement
|
328
331
|
end
|
329
332
|
|
330
|
-
def bind_params(
|
333
|
+
def bind_params(*bind_vars)
|
331
334
|
index = 1
|
332
335
|
bind_vars.flatten.each do |var|
|
333
336
|
if Hash === var
|
@@ -339,17 +342,7 @@ module ActiveRecord
|
|
339
342
|
end
|
340
343
|
end
|
341
344
|
|
342
|
-
def bind_param(position, value
|
343
|
-
if column
|
344
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
345
|
-
*******************************************************
|
346
|
-
Passing a column to `bind_param` will be deprecated.
|
347
|
-
`type_casted_binds` should be already type casted
|
348
|
-
so that `bind_param` should not need to know column.
|
349
|
-
*******************************************************
|
350
|
-
MSG
|
351
|
-
end
|
352
|
-
|
345
|
+
def bind_param(position, value)
|
353
346
|
case value
|
354
347
|
when Integer
|
355
348
|
@raw_statement.setLong(position, value)
|
@@ -373,17 +366,13 @@ module ActiveRecord
|
|
373
366
|
when Java::JavaSql::Timestamp
|
374
367
|
@raw_statement.setTimestamp(position, value)
|
375
368
|
when Time
|
376
|
-
|
377
|
-
@raw_statement.setTimestamp(position,
|
369
|
+
new_value = Java::java.sql.Timestamp.new(value.year - 1900, value.month - 1, value.day, value.hour, value.min, value.sec, value.usec * 1000)
|
370
|
+
@raw_statement.setTimestamp(position, new_value)
|
378
371
|
when NilClass
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
# When nils will actually be used by ActiveRecord as bound parameters
|
384
|
-
# then need to pass actual column type.
|
385
|
-
@raw_statement.setNull(position, java.sql.Types::VARCHAR)
|
386
|
-
end
|
372
|
+
# TODO: currently nil is always bound as NULL with VARCHAR type.
|
373
|
+
# When nils will actually be used by ActiveRecord as bound parameters
|
374
|
+
# then need to pass actual column type.
|
375
|
+
@raw_statement.setNull(position, java.sql.Types::VARCHAR)
|
387
376
|
else
|
388
377
|
raise ArgumentError, "Don't know how to bind variable with type #{value.class}"
|
389
378
|
end
|
@@ -411,21 +400,21 @@ module ActiveRecord
|
|
411
400
|
end
|
412
401
|
|
413
402
|
def column_types
|
414
|
-
@column_types ||= (1..metadata.getColumnCount).map{|i| metadata.getColumnTypeName(i).to_sym}
|
403
|
+
@column_types ||= (1..metadata.getColumnCount).map { |i| metadata.getColumnTypeName(i).to_sym }
|
415
404
|
end
|
416
405
|
|
417
406
|
def column_names
|
418
|
-
@column_names ||= (1..metadata.getColumnCount).map{|i| metadata.getColumnName(i)}
|
407
|
+
@column_names ||= (1..metadata.getColumnCount).map { |i| metadata.getColumnName(i) }
|
419
408
|
end
|
420
409
|
alias :get_col_names :column_names
|
421
410
|
|
422
|
-
def fetch(options={})
|
411
|
+
def fetch(options = {})
|
423
412
|
if @raw_result_set.next
|
424
413
|
get_lob_value = options[:get_lob_value]
|
425
414
|
row_values = []
|
426
415
|
column_types.each_with_index do |column_type, i|
|
427
416
|
row_values <<
|
428
|
-
@connection.get_ruby_value_from_result_set(@raw_result_set, i+1, column_type, get_lob_value)
|
417
|
+
@connection.get_ruby_value_from_result_set(@raw_result_set, i + 1, column_type, get_lob_value)
|
429
418
|
end
|
430
419
|
row_values
|
431
420
|
else
|
@@ -469,14 +458,14 @@ module ActiveRecord
|
|
469
458
|
|
470
459
|
cols_types_index = (1..column_count).map do |i|
|
471
460
|
col_name = oracle_downcase(metadata.getColumnName(i))
|
472
|
-
next if col_name ==
|
461
|
+
next if col_name == "raw_rnum_"
|
473
462
|
column_hash[col_name] = nil
|
474
463
|
[col_name, metadata.getColumnTypeName(i).to_sym, i]
|
475
464
|
end
|
476
465
|
cols_types_index.delete(nil)
|
477
466
|
|
478
467
|
rows = []
|
479
|
-
get_lob_value = !(name ==
|
468
|
+
get_lob_value = !(name == "Writable Large Object")
|
480
469
|
|
481
470
|
while rset.next
|
482
471
|
hash = column_hash.dup
|
@@ -496,7 +485,7 @@ module ActiveRecord
|
|
496
485
|
if is_binary
|
497
486
|
lob.setBytes(1, value.to_java_bytes)
|
498
487
|
else
|
499
|
-
lob.setString(1,value)
|
488
|
+
lob.setString(1, value)
|
500
489
|
end
|
501
490
|
end
|
502
491
|
|
@@ -529,11 +518,7 @@ module ActiveRecord
|
|
529
518
|
if dt = rset.getDATE(i)
|
530
519
|
d = dt.dateValue
|
531
520
|
t = dt.timeValue
|
532
|
-
|
533
|
-
Date.new(d.year + 1900, d.month + 1, d.date)
|
534
|
-
else
|
535
|
-
Time.send(Base.default_timezone, d.year + 1900, d.month + 1, d.date, t.hours, t.minutes, t.seconds)
|
536
|
-
end
|
521
|
+
Time.send(Base.default_timezone, d.year + 1900, d.month + 1, d.date, t.hours, t.minutes, t.seconds)
|
537
522
|
else
|
538
523
|
nil
|
539
524
|
end
|
@@ -547,7 +532,7 @@ module ActiveRecord
|
|
547
532
|
get_lob_value ? lob_to_ruby_value(rset.getBlob(i)) : rset.getBlob(i)
|
548
533
|
when :RAW
|
549
534
|
raw_value = rset.getRAW(i)
|
550
|
-
raw_value && raw_value.getBytes.to_a.pack(
|
535
|
+
raw_value && raw_value.getBytes.to_a.pack("C*")
|
551
536
|
else
|
552
537
|
nil
|
553
538
|
end
|
@@ -555,22 +540,22 @@ module ActiveRecord
|
|
555
540
|
|
556
541
|
private
|
557
542
|
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
543
|
+
def lob_to_ruby_value(val)
|
544
|
+
case val
|
545
|
+
when ::Java::OracleSql::CLOB
|
546
|
+
if val.isEmptyLob
|
547
|
+
nil
|
548
|
+
else
|
549
|
+
val.getSubString(1, val.length)
|
550
|
+
end
|
551
|
+
when ::Java::OracleSql::BLOB
|
552
|
+
if val.isEmptyLob
|
553
|
+
nil
|
554
|
+
else
|
555
|
+
String.from_java_bytes(val.getBytes(1, val.length))
|
556
|
+
end
|
571
557
|
end
|
572
558
|
end
|
573
|
-
end
|
574
559
|
end
|
575
560
|
end
|
576
561
|
end
|
@@ -12,13 +12,6 @@ module ActiveRecord
|
|
12
12
|
clob = Java::OracleSql::CLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::CLOB::DURATION_SESSION)
|
13
13
|
clob.setString(1, value.to_s)
|
14
14
|
clob
|
15
|
-
when Date, DateTime
|
16
|
-
Java::oracle.sql.DATE.new(value.strftime("%Y-%m-%d %H:%M:%S"))
|
17
|
-
when Time
|
18
|
-
Java::java.sql.Timestamp.new(value.year-1900, value.month-1, value.day, value.hour, value.min, value.sec, value.usec * 1000)
|
19
|
-
when Java::JavaSql::Timestamp
|
20
|
-
# Returning value as it is likely this value was already type casted from Time to Java::JavaSql::Timestamp
|
21
|
-
value
|
22
15
|
else
|
23
16
|
super
|
24
17
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "delegate"
|
2
2
|
|
3
3
|
begin
|
4
4
|
require "oci8"
|
@@ -11,7 +11,7 @@ end
|
|
11
11
|
|
12
12
|
# check ruby-oci8 version
|
13
13
|
required_oci8_version = [2, 2, 0]
|
14
|
-
oci8_version_ints = OCI8::VERSION.scan(/\d+/).map{|s| s.to_i}
|
14
|
+
oci8_version_ints = OCI8::VERSION.scan(/\d+/).map { |s| s.to_i }
|
15
15
|
if (oci8_version_ints <=> required_oci8_version) < 0
|
16
16
|
raise LoadError, "ERROR: ruby-oci8 version #{OCI8::VERSION} is too old. Please install ruby-oci8 version #{required_oci8_version.join('.')} or later."
|
17
17
|
end
|
@@ -98,9 +98,9 @@ module ActiveRecord
|
|
98
98
|
# and return :insert_id value
|
99
99
|
def exec_with_returning(sql)
|
100
100
|
cursor = @raw_connection.parse(sql)
|
101
|
-
cursor.bind_param(
|
101
|
+
cursor.bind_param(":insert_id", nil, Integer)
|
102
102
|
cursor.exec
|
103
|
-
cursor[
|
103
|
+
cursor[":insert_id"]
|
104
104
|
ensure
|
105
105
|
cursor.close rescue nil
|
106
106
|
end
|
@@ -115,7 +115,7 @@ module ActiveRecord
|
|
115
115
|
@raw_cursor = raw_cursor
|
116
116
|
end
|
117
117
|
|
118
|
-
def bind_params(
|
118
|
+
def bind_params(*bind_vars)
|
119
119
|
index = 1
|
120
120
|
bind_vars.flatten.each do |var|
|
121
121
|
if Hash === var
|
@@ -127,30 +127,16 @@ module ActiveRecord
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
def bind_param(position, value
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
MSG
|
139
|
-
end
|
140
|
-
|
141
|
-
if column && column.object_type?
|
142
|
-
@raw_cursor.bind_param(position, value, :named_type, column.sql_type)
|
130
|
+
def bind_param(position, value)
|
131
|
+
case value
|
132
|
+
when ActiveRecord::OracleEnhanced::Type::Raw
|
133
|
+
@raw_cursor.bind_param(position, ActiveRecord::ConnectionAdapters::OracleEnhanced::Quoting.encode_raw(value))
|
134
|
+
when ActiveModel::Type::Decimal
|
135
|
+
@raw_cursor.bind_param(position, BigDecimal.new(value.to_s))
|
136
|
+
when NilClass
|
137
|
+
@raw_cursor.bind_param(position, nil, String)
|
143
138
|
else
|
144
|
-
|
145
|
-
when ActiveRecord::OracleEnhanced::Type::Raw
|
146
|
-
@raw_cursor.bind_param(position, ActiveRecord::ConnectionAdapters::OracleEnhanced::Quoting.encode_raw(value))
|
147
|
-
when ActiveModel::Type::Decimal
|
148
|
-
@raw_cursor.bind_param(position, BigDecimal.new(value.to_s))
|
149
|
-
when NilClass
|
150
|
-
@raw_cursor.bind_param(position, nil, String)
|
151
|
-
else
|
152
|
-
@raw_cursor.bind_param(position, value)
|
153
|
-
end
|
139
|
+
@raw_cursor.bind_param(position, value)
|
154
140
|
end
|
155
141
|
end
|
156
142
|
|
@@ -170,7 +156,7 @@ module ActiveRecord
|
|
170
156
|
@raw_cursor.get_col_names
|
171
157
|
end
|
172
158
|
|
173
|
-
def fetch(options={})
|
159
|
+
def fetch(options = {})
|
174
160
|
if row = @raw_cursor.fetch
|
175
161
|
get_lob_value = options[:get_lob_value]
|
176
162
|
row.map do |col|
|
@@ -194,13 +180,13 @@ module ActiveRecord
|
|
194
180
|
# Ignore raw_rnum_ which is used to simulate LIMIT and OFFSET
|
195
181
|
cursor.get_col_names.each do |col_name|
|
196
182
|
col_name = oracle_downcase(col_name)
|
197
|
-
cols << col_name unless col_name ==
|
183
|
+
cols << col_name unless col_name == "raw_rnum_"
|
198
184
|
end
|
199
185
|
# Reuse the same hash for all rows
|
200
186
|
column_hash = {}
|
201
|
-
cols.each {|c| column_hash[c] = nil}
|
187
|
+
cols.each { |c| column_hash[c] = nil }
|
202
188
|
rows = []
|
203
|
-
get_lob_value = !(name ==
|
189
|
+
get_lob_value = !(name == "Writable Large Object")
|
204
190
|
|
205
191
|
while row = cursor.fetch
|
206
192
|
hash = column_hash.dup
|
@@ -223,7 +209,7 @@ module ActiveRecord
|
|
223
209
|
|
224
210
|
def describe(name)
|
225
211
|
# fall back to SELECT based describe if using database link
|
226
|
-
return super if name.to_s.include?(
|
212
|
+
return super if name.to_s.include?("@")
|
227
213
|
quoted_name = ActiveRecord::ConnectionAdapters::OracleEnhanced::Quoting.valid_table_name?(name) ? name : "\"#{name}\""
|
228
214
|
@raw_connection.describe(quoted_name)
|
229
215
|
rescue OCIException => e
|
@@ -261,17 +247,13 @@ module ActiveRecord
|
|
261
247
|
if get_lob_value
|
262
248
|
data = value.read || "" # if value.read returns nil, then we have an empty_clob() i.e. an empty string
|
263
249
|
# In Ruby 1.9.1 always change encoding to ASCII-8BIT for binaries
|
264
|
-
data.force_encoding(
|
250
|
+
data.force_encoding("ASCII-8BIT") if data.respond_to?(:force_encoding) && value.is_a?(OCI8::BLOB)
|
265
251
|
data
|
266
252
|
else
|
267
253
|
value
|
268
254
|
end
|
269
255
|
when Time, DateTime
|
270
|
-
|
271
|
-
value.to_date
|
272
|
-
else
|
273
|
-
create_time_with_default_timezone(value)
|
274
|
-
end
|
256
|
+
create_time_with_default_timezone(value)
|
275
257
|
else
|
276
258
|
value
|
277
259
|
end
|
@@ -283,32 +265,32 @@ module ActiveRecord
|
|
283
265
|
|
284
266
|
private
|
285
267
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
268
|
+
def date_without_time?(value)
|
269
|
+
case value
|
270
|
+
when OraDate
|
271
|
+
value.hour == 0 && value.minute == 0 && value.second == 0
|
272
|
+
else
|
273
|
+
value.hour == 0 && value.min == 0 && value.sec == 0
|
274
|
+
end
|
292
275
|
end
|
293
|
-
end
|
294
276
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
277
|
+
def create_time_with_default_timezone(value)
|
278
|
+
year, month, day, hour, min, sec, usec = case value
|
279
|
+
when Time
|
280
|
+
[value.year, value.month, value.day, value.hour, value.min, value.sec, value.usec]
|
281
|
+
when OraDate
|
282
|
+
[value.year, value.month, value.day, value.hour, value.minute, value.second, 0]
|
283
|
+
else
|
284
|
+
[value.year, value.month, value.day, value.hour, value.min, value.sec, 0]
|
285
|
+
end
|
286
|
+
# code from Time.time_with_datetime_fallback
|
287
|
+
begin
|
288
|
+
Time.send(Base.default_timezone, year, month, day, hour, min, sec, usec)
|
289
|
+
rescue
|
290
|
+
offset = Base.default_timezone.to_sym == :local ? ::DateTime.local_offset : 0
|
291
|
+
::DateTime.civil(year, month, day, hour, min, sec, offset)
|
292
|
+
end
|
310
293
|
end
|
311
|
-
end
|
312
294
|
end
|
313
295
|
|
314
296
|
# The OracleEnhancedOCIFactory factors out the code necessary to connect and
|
@@ -324,16 +306,16 @@ module ActiveRecord
|
|
324
306
|
privilege = config[:privilege] && config[:privilege].to_sym
|
325
307
|
async = config[:allow_concurrency]
|
326
308
|
prefetch_rows = config[:prefetch_rows] || 100
|
327
|
-
cursor_sharing = config[:cursor_sharing] ||
|
309
|
+
cursor_sharing = config[:cursor_sharing] || "force"
|
328
310
|
# get session time_zone from configuration or from TZ environment variable
|
329
|
-
time_zone = config[:time_zone] || ENV[
|
311
|
+
time_zone = config[:time_zone] || ENV["TZ"]
|
330
312
|
|
331
313
|
# using a connection string via DATABASE_URL
|
332
|
-
connection_string = if host ==
|
314
|
+
connection_string = if host == "connection-string"
|
333
315
|
database
|
334
316
|
# connection using host, port and database name
|
335
317
|
elsif host || port
|
336
|
-
host ||=
|
318
|
+
host ||= "localhost"
|
337
319
|
host = "[#{host}]" if host =~ /^[^\[].*:/ # IPv6
|
338
320
|
port ||= 1521
|
339
321
|
database = "/#{database}" unless database.match(/^\//)
|
@@ -372,8 +354,8 @@ class OCI8 #:nodoc:
|
|
372
354
|
def describe(name)
|
373
355
|
info = describe_table(name.to_s)
|
374
356
|
raise %Q{"DESC #{name}" failed} if info.nil?
|
375
|
-
if info.respond_to?
|
376
|
-
[info.obj_schema, info.obj_name,
|
357
|
+
if info.respond_to?(:obj_link) && info.obj_link
|
358
|
+
[info.obj_schema, info.obj_name, "@" + info.obj_link]
|
377
359
|
else
|
378
360
|
[info.obj_schema, info.obj_name]
|
379
361
|
end
|
@@ -402,7 +384,7 @@ class OCI8EnhancedAutoRecover < DelegateClass(OCI8) #:nodoc:
|
|
402
384
|
@active = true
|
403
385
|
@config = config
|
404
386
|
@factory = factory
|
405
|
-
@connection
|
387
|
+
@connection = @factory.new_connection @config
|
406
388
|
super @connection
|
407
389
|
end
|
408
390
|
|
@@ -5,16 +5,16 @@ module ActiveRecord
|
|
5
5
|
def _type_cast(value)
|
6
6
|
case value
|
7
7
|
when ActiveModel::Type::Binary::Data
|
8
|
-
lob_value = value ==
|
8
|
+
lob_value = value == "" ? " " : value
|
9
9
|
bind_type = OCI8::BLOB
|
10
10
|
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
|
11
|
-
ora_value.size = 0 if value ==
|
11
|
+
ora_value.size = 0 if value == ""
|
12
12
|
ora_value
|
13
13
|
when ActiveRecord::OracleEnhanced::Type::Text::Data
|
14
|
-
lob_value = value.to_s ==
|
14
|
+
lob_value = value.to_s == "" ? " " : value.to_s
|
15
15
|
bind_type = OCI8::CLOB
|
16
16
|
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
|
17
|
-
ora_value.size = 0 if value.to_s ==
|
17
|
+
ora_value.size = 0 if value.to_s == ""
|
18
18
|
ora_value
|
19
19
|
else
|
20
20
|
super
|