activerecord-oracle_enhanced-adapter 1.8.2 → 5.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.md +190 -5
- data/README.md +10 -10
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +9 -71
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +84 -73
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +12 -12
- data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +52 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +35 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +59 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +379 -402
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +7 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +46 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +242 -247
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +9 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +3 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +25 -9
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +9 -6
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +10 -5
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +48 -51
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +261 -59
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +2 -34
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +267 -222
- data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +33 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +136 -547
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/boolean.rb +4 -2
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/integer.rb +4 -2
- data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/national_character_string.rb +5 -3
- data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/raw.rb +4 -2
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/string.rb +4 -2
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/text.rb +4 -2
- data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
- data/lib/active_record/{oracle_enhanced/type → type/oracle_enhanced}/timestamptz.rb +4 -2
- data/lib/activerecord-oracle_enhanced-adapter.rb +2 -6
- data/spec/active_record/connection_adapters/{oracle_enhanced_emulate_oracle_adapter_spec.rb → emulation/oracle_adapter_spec.rb} +2 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_connection_spec.rb → oracle_enhanced/connection_spec.rb} +82 -38
- data/spec/active_record/connection_adapters/{oracle_enhanced_context_index_spec.rb → oracle_enhanced/context_index_spec.rb} +20 -16
- data/spec/active_record/connection_adapters/{oracle_enhanced_database_tasks_spec.rb → oracle_enhanced/database_tasks_spec.rb} +17 -5
- data/spec/active_record/connection_adapters/{oracle_enhanced_dbms_output_spec.rb → oracle_enhanced/dbms_output_spec.rb} +2 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_procedures_spec.rb → oracle_enhanced/procedures_spec.rb} +26 -33
- data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +196 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_schema_dump_spec.rb → oracle_enhanced/schema_dumper_spec.rb} +61 -90
- data/spec/active_record/connection_adapters/{oracle_enhanced_schema_statements_spec.rb → oracle_enhanced/schema_statements_spec.rb} +95 -28
- data/spec/active_record/connection_adapters/{oracle_enhanced_structure_dump_spec.rb → oracle_enhanced/structure_dump_spec.rb} +48 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +202 -331
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +15 -1106
- data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
- data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +207 -0
- data/spec/active_record/{connection_adapters/oracle_enhanced_dirty_spec.rb → oracle_enhanced/type/dirty_spec.rb} +3 -1
- data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
- data/spec/active_record/oracle_enhanced/type/integer_spec.rb +91 -0
- data/spec/active_record/oracle_enhanced/type/json_spec.rb +57 -0
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +55 -0
- data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
- data/spec/active_record/oracle_enhanced/type/raw_spec.rb +122 -0
- data/spec/active_record/oracle_enhanced/type/text_spec.rb +229 -0
- data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +75 -0
- data/spec/spec_helper.rb +15 -1
- data/spec/support/alter_system_set_open_cursors.sql +1 -0
- metadata +63 -48
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +0 -28
- data/lib/active_record/oracle_enhanced/type/json.rb +0 -8
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module OracleEnhanced
|
@@ -8,10 +10,14 @@ module ActiveRecord
|
|
8
10
|
blob = Java::OracleSql::BLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::BLOB::DURATION_SESSION)
|
9
11
|
blob.setBytes(1, value.to_s.to_java_bytes)
|
10
12
|
blob
|
11
|
-
when
|
13
|
+
when Type::OracleEnhanced::Text::Data
|
12
14
|
clob = Java::OracleSql::CLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::CLOB::DURATION_SESSION)
|
13
15
|
clob.setString(1, value.to_s)
|
14
16
|
clob
|
17
|
+
when Type::OracleEnhanced::NationalCharacterText::Data
|
18
|
+
clob = Java::OracleSql::NCLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::NCLOB::DURATION_SESSION)
|
19
|
+
clob.setString(1, value.to_s)
|
20
|
+
clob
|
15
21
|
else
|
16
22
|
super
|
17
23
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord #:nodoc:
|
4
|
+
module ConnectionAdapters #:nodoc:
|
5
|
+
module OracleEnhanced #:nodoc:
|
6
|
+
module Lob #:nodoc:
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
class_attribute :custom_create_method, :custom_update_method, :custom_delete_method
|
11
|
+
|
12
|
+
# After setting large objects to empty, select the OCI8::LOB
|
13
|
+
# and write back the data.
|
14
|
+
before_update :record_changed_lobs
|
15
|
+
after_update :enhanced_write_lobs
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def lob_columns
|
20
|
+
columns.select do |column|
|
21
|
+
column.sql_type_metadata.sql_type =~ /LOB$/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def enhanced_write_lobs
|
29
|
+
if self.class.connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) &&
|
30
|
+
!(self.class.custom_create_method || self.class.custom_update_method)
|
31
|
+
self.class.connection.write_lobs(self.class.table_name, self.class, attributes, @changed_lob_columns)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def record_changed_lobs
|
35
|
+
@changed_lob_columns = self.class.lob_columns.select do |col|
|
36
|
+
self.will_save_change_to_attribute?(col.name) && !self.class.readonly_attributes.to_a.include?(col.name)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
ActiveSupport.on_load(:active_record) do
|
45
|
+
ActiveRecord::Base.send(:include, ActiveRecord::ConnectionAdapters::OracleEnhanced::Lob)
|
46
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "delegate"
|
2
4
|
|
3
5
|
begin
|
@@ -10,258 +12,245 @@ rescue LoadError => e
|
|
10
12
|
end
|
11
13
|
|
12
14
|
# check ruby-oci8 version
|
13
|
-
required_oci8_version = [2, 2,
|
15
|
+
required_oci8_version = [2, 2, 4]
|
14
16
|
oci8_version_ints = OCI8::VERSION.scan(/\d+/).map { |s| s.to_i }
|
15
17
|
if (oci8_version_ints <=> required_oci8_version) < 0
|
16
|
-
|
18
|
+
$stderr.puts <<-EOS.strip_heredoc
|
19
|
+
"ERROR: ruby-oci8 version #{OCI8::VERSION} is too old. Please install ruby-oci8 version #{required_oci8_version.join('.')} or later."
|
20
|
+
EOS
|
21
|
+
|
22
|
+
exit!
|
17
23
|
end
|
18
24
|
|
19
25
|
module ActiveRecord
|
20
26
|
module ConnectionAdapters
|
21
27
|
# OCI database interface for MRI
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def raw_oci_connection
|
32
|
-
if @raw_connection.is_a? OCI8
|
33
|
-
@raw_connection
|
34
|
-
# ActiveRecord Oracle enhanced adapter puts OCI8EnhancedAutoRecover wrapper around OCI8
|
35
|
-
# in this case we need to pass original OCI8 connection
|
36
|
-
else
|
37
|
-
@raw_connection.instance_variable_get(:@connection)
|
28
|
+
module OracleEnhanced
|
29
|
+
class OCIConnection < OracleEnhanced::Connection #:nodoc:
|
30
|
+
def initialize(config)
|
31
|
+
@raw_connection = OCI8EnhancedAutoRecover.new(config, OracleEnhancedOCIFactory)
|
32
|
+
# default schema owner
|
33
|
+
@owner = config[:schema]
|
34
|
+
@owner ||= config[:username]
|
35
|
+
@owner = @owner.to_s.upcase
|
38
36
|
end
|
39
|
-
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
def raw_oci_connection
|
39
|
+
if @raw_connection.is_a? OCI8
|
40
|
+
@raw_connection
|
41
|
+
# ActiveRecord Oracle enhanced adapter puts OCI8EnhancedAutoRecover wrapper around OCI8
|
42
|
+
# in this case we need to pass original OCI8 connection
|
43
|
+
else
|
44
|
+
@raw_connection.instance_variable_get(:@connection)
|
45
|
+
end
|
46
|
+
end
|
44
47
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
def auto_retry
|
49
|
+
@raw_connection.auto_retry if @raw_connection
|
50
|
+
end
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
52
|
+
def auto_retry=(value)
|
53
|
+
@raw_connection.auto_retry = value if @raw_connection
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
def logoff
|
57
|
+
@raw_connection.logoff
|
58
|
+
@raw_connection.active = false
|
59
|
+
end
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
+
def commit
|
62
|
+
@raw_connection.commit
|
63
|
+
end
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
def rollback
|
66
|
+
@raw_connection.rollback
|
67
|
+
end
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
def autocommit?
|
70
|
+
@raw_connection.autocommit?
|
71
|
+
end
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def ping
|
74
|
-
@raw_connection.ping
|
75
|
-
rescue OCIException => e
|
76
|
-
raise OracleEnhancedConnectionException, e.message
|
77
|
-
end
|
73
|
+
def autocommit=(value)
|
74
|
+
@raw_connection.autocommit = value
|
75
|
+
end
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
# Checks connection, returns true if active. Note that ping actively
|
78
|
+
# checks the connection, while #active? simply returns the last
|
79
|
+
# known state.
|
80
|
+
def ping
|
81
|
+
@raw_connection.ping
|
82
|
+
rescue OCIException => e
|
83
|
+
raise OracleEnhanced::ConnectionException, e.message
|
84
|
+
end
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
raise OracleEnhancedConnectionException, e.message
|
87
|
-
end
|
86
|
+
def active?
|
87
|
+
@raw_connection.active?
|
88
|
+
end
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
def reset!
|
91
|
+
@raw_connection.reset!
|
92
|
+
rescue OCIException => e
|
93
|
+
raise OracleEnhanced::ConnectionException, e.message
|
94
|
+
end
|
92
95
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
+
def exec(sql, *bindvars, &block)
|
97
|
+
@raw_connection.exec(sql, *bindvars, &block)
|
98
|
+
end
|
96
99
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
cursor = @raw_connection.parse(sql)
|
101
|
-
cursor.bind_param(":insert_id", nil, Integer)
|
102
|
-
cursor.exec
|
103
|
-
cursor[":insert_id"]
|
104
|
-
ensure
|
105
|
-
cursor.close rescue nil
|
106
|
-
end
|
100
|
+
def prepare(sql)
|
101
|
+
Cursor.new(self, @raw_connection.parse(sql))
|
102
|
+
end
|
107
103
|
|
108
|
-
|
109
|
-
|
110
|
-
|
104
|
+
class Cursor
|
105
|
+
def initialize(connection, raw_cursor)
|
106
|
+
@connection = connection
|
107
|
+
@raw_cursor = raw_cursor
|
108
|
+
end
|
111
109
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
110
|
+
def bind_params(*bind_vars)
|
111
|
+
index = 1
|
112
|
+
bind_vars.flatten.each do |var|
|
113
|
+
if Hash === var
|
114
|
+
var.each { |key, val| bind_param key, val }
|
115
|
+
else
|
116
|
+
bind_param index, var
|
117
|
+
index += 1
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
117
121
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
122
|
+
def bind_param(position, value)
|
123
|
+
case value
|
124
|
+
when Type::OracleEnhanced::Raw
|
125
|
+
@raw_cursor.bind_param(position, OracleEnhanced::Quoting.encode_raw(value))
|
126
|
+
when ActiveModel::Type::Decimal
|
127
|
+
@raw_cursor.bind_param(position, BigDecimal.new(value.to_s))
|
128
|
+
when NilClass
|
129
|
+
@raw_cursor.bind_param(position, nil, String)
|
123
130
|
else
|
124
|
-
bind_param
|
125
|
-
index += 1
|
131
|
+
@raw_cursor.bind_param(position, value)
|
126
132
|
end
|
127
133
|
end
|
128
|
-
end
|
129
134
|
|
130
|
-
|
131
|
-
|
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)
|
138
|
-
else
|
139
|
-
@raw_cursor.bind_param(position, value)
|
135
|
+
def bind_returning_param(position, bind_type)
|
136
|
+
@raw_cursor.bind_param(position, nil, bind_type)
|
140
137
|
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def bind_returning_param(position, bind_type)
|
144
|
-
@raw_cursor.bind_param(position, nil, bind_type)
|
145
|
-
end
|
146
138
|
|
147
|
-
|
148
|
-
|
149
|
-
|
139
|
+
def exec
|
140
|
+
@raw_cursor.exec
|
141
|
+
end
|
150
142
|
|
151
|
-
|
152
|
-
|
153
|
-
|
143
|
+
def exec_update
|
144
|
+
@raw_cursor.exec
|
145
|
+
end
|
154
146
|
|
155
|
-
|
156
|
-
|
157
|
-
|
147
|
+
def get_col_names
|
148
|
+
@raw_cursor.get_col_names
|
149
|
+
end
|
158
150
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
151
|
+
def fetch(options = {})
|
152
|
+
if row = @raw_cursor.fetch
|
153
|
+
get_lob_value = options[:get_lob_value]
|
154
|
+
row.map do |col|
|
155
|
+
@connection.typecast_result_value(col, get_lob_value)
|
156
|
+
end
|
164
157
|
end
|
165
158
|
end
|
166
|
-
end
|
167
159
|
|
168
|
-
|
169
|
-
|
170
|
-
|
160
|
+
def get_returning_param(position, type)
|
161
|
+
@raw_cursor[position]
|
162
|
+
end
|
171
163
|
|
172
|
-
|
173
|
-
|
164
|
+
def close
|
165
|
+
@raw_cursor.close
|
166
|
+
end
|
174
167
|
end
|
175
|
-
end
|
176
168
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
169
|
+
def select(sql, name = nil, return_column_names = false)
|
170
|
+
cursor = @raw_connection.exec(sql)
|
171
|
+
cols = []
|
172
|
+
# Ignore raw_rnum_ which is used to simulate LIMIT and OFFSET
|
173
|
+
cursor.get_col_names.each do |col_name|
|
174
|
+
col_name = _oracle_downcase(col_name)
|
175
|
+
cols << col_name unless col_name == "raw_rnum_"
|
176
|
+
end
|
177
|
+
# Reuse the same hash for all rows
|
178
|
+
column_hash = {}
|
179
|
+
cols.each { |c| column_hash[c] = nil }
|
180
|
+
rows = []
|
181
|
+
get_lob_value = !(name == "Writable Large Object")
|
182
|
+
|
183
|
+
while row = cursor.fetch
|
184
|
+
hash = column_hash.dup
|
190
185
|
|
191
|
-
|
192
|
-
|
186
|
+
cols.each_with_index do |col, i|
|
187
|
+
hash[col] = typecast_result_value(row[i], get_lob_value)
|
188
|
+
end
|
193
189
|
|
194
|
-
|
195
|
-
hash[col] = typecast_result_value(row[i], get_lob_value)
|
190
|
+
rows << hash
|
196
191
|
end
|
197
192
|
|
198
|
-
rows
|
193
|
+
return_column_names ? [rows, cols] : rows
|
194
|
+
ensure
|
195
|
+
cursor.close if cursor
|
199
196
|
end
|
200
197
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
end
|
205
|
-
|
206
|
-
def write_lob(lob, value, is_binary = false)
|
207
|
-
lob.write value
|
208
|
-
end
|
198
|
+
def write_lob(lob, value, is_binary = false)
|
199
|
+
lob.write value
|
200
|
+
end
|
209
201
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
202
|
+
def describe(name)
|
203
|
+
# fall back to SELECT based describe if using database link
|
204
|
+
return super if name.to_s.include?("@")
|
205
|
+
quoted_name = OracleEnhanced::Quoting.valid_table_name?(name) ? name : "\"#{name}\""
|
206
|
+
@raw_connection.describe(quoted_name)
|
207
|
+
rescue OCIException => e
|
208
|
+
if e.code == 4043
|
209
|
+
raise OracleEnhanced::ConnectionException, %Q{"DESC #{name}" failed; does it exist?}
|
210
|
+
else
|
211
|
+
# fall back to SELECT which can handle synonyms to database links
|
212
|
+
super
|
213
|
+
end
|
221
214
|
end
|
222
|
-
end
|
223
215
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
216
|
+
# Return OCIError error code
|
217
|
+
def error_code(exception)
|
218
|
+
case exception
|
219
|
+
when OCIError
|
220
|
+
exception.code
|
221
|
+
else
|
222
|
+
nil
|
223
|
+
end
|
231
224
|
end
|
232
|
-
end
|
233
225
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
226
|
+
def typecast_result_value(value, get_lob_value)
|
227
|
+
case value
|
228
|
+
when Integer
|
229
|
+
value
|
230
|
+
when String
|
231
|
+
value
|
232
|
+
when Float, BigDecimal
|
233
|
+
# return Integer if value is integer (to avoid issues with _before_type_cast values for id attributes)
|
234
|
+
value == (v_to_i = value.to_i) ? v_to_i : value
|
235
|
+
when OCI8::LOB
|
236
|
+
if get_lob_value
|
237
|
+
data = value.read || "" # if value.read returns nil, then we have an empty_clob() i.e. an empty string
|
238
|
+
# In Ruby 1.9.1 always change encoding to ASCII-8BIT for binaries
|
239
|
+
data.force_encoding("ASCII-8BIT") if data.respond_to?(:force_encoding) && value.is_a?(OCI8::BLOB)
|
240
|
+
data
|
241
|
+
else
|
242
|
+
value
|
243
|
+
end
|
244
|
+
when Time, DateTime
|
245
|
+
create_time_with_default_timezone(value)
|
252
246
|
else
|
253
247
|
value
|
254
248
|
end
|
255
|
-
when Time, DateTime
|
256
|
-
create_time_with_default_timezone(value)
|
257
|
-
else
|
258
|
-
value
|
259
249
|
end
|
260
|
-
end
|
261
250
|
|
262
|
-
|
263
|
-
|
264
|
-
|
251
|
+
def database_version
|
252
|
+
@database_version ||= (version = raw_connection.oracle_server_version) && [version.major, version.minor]
|
253
|
+
end
|
265
254
|
|
266
255
|
private
|
267
256
|
|
@@ -291,60 +280,66 @@ module ActiveRecord
|
|
291
280
|
::DateTime.civil(year, month, day, hour, min, sec, offset)
|
292
281
|
end
|
293
282
|
end
|
294
|
-
|
283
|
+
end
|
295
284
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
conn.
|
335
|
-
|
336
|
-
conn.
|
337
|
-
|
338
|
-
|
285
|
+
# The OracleEnhancedOCIFactory factors out the code necessary to connect and
|
286
|
+
# configure an Oracle/OCI connection.
|
287
|
+
class OracleEnhancedOCIFactory #:nodoc:
|
288
|
+
def self.new_connection(config)
|
289
|
+
# to_s needed if username, password or database is specified as number in database.yml file
|
290
|
+
username = config[:username] && config[:username].to_s
|
291
|
+
password = config[:password] && config[:password].to_s
|
292
|
+
database = config[:database] && config[:database].to_s
|
293
|
+
schema = config[:schema] && config[:schema].to_s
|
294
|
+
host, port = config[:host], config[:port]
|
295
|
+
privilege = config[:privilege] && config[:privilege].to_sym
|
296
|
+
async = config[:allow_concurrency]
|
297
|
+
prefetch_rows = config[:prefetch_rows] || 100
|
298
|
+
cursor_sharing = config[:cursor_sharing]
|
299
|
+
# get session time_zone from configuration or from TZ environment variable
|
300
|
+
time_zone = config[:time_zone] || ENV["TZ"]
|
301
|
+
|
302
|
+
# using a connection string via DATABASE_URL
|
303
|
+
connection_string = if host == "connection-string"
|
304
|
+
database
|
305
|
+
# connection using host, port and database name
|
306
|
+
elsif host || port
|
307
|
+
host ||= "localhost"
|
308
|
+
host = "[#{host}]" if host =~ /^[^\[].*:/ # IPv6
|
309
|
+
port ||= 1521
|
310
|
+
database = "/#{database}" unless database.match(/^\//)
|
311
|
+
"//#{host}:#{port}#{database}"
|
312
|
+
# if no host is specified then assume that
|
313
|
+
# database parameter is TNS alias or TNS connection string
|
314
|
+
else
|
315
|
+
database
|
316
|
+
end
|
317
|
+
OCI8.properties[:tcp_keepalive] = true
|
318
|
+
begin
|
319
|
+
OCI8.properties[:tcp_keepalive_time] = 600
|
320
|
+
rescue NotImplementedError
|
321
|
+
end
|
322
|
+
conn = OCI8.new username, password, connection_string, privilege
|
323
|
+
conn.autocommit = true
|
324
|
+
conn.non_blocking = true if async
|
325
|
+
conn.prefetch_rows = prefetch_rows
|
326
|
+
conn.exec "alter session set cursor_sharing = #{cursor_sharing}" rescue nil if cursor_sharing
|
327
|
+
if ActiveRecord::Base.default_timezone == :local
|
328
|
+
conn.exec "alter session set time_zone = '#{time_zone}'" unless time_zone.blank?
|
329
|
+
elsif ActiveRecord::Base.default_timezone == :utc
|
330
|
+
conn.exec "alter session set time_zone = '+00:00'"
|
331
|
+
end
|
332
|
+
conn.exec "alter session set current_schema = #{schema}" unless schema.blank?
|
339
333
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
334
|
+
# Initialize NLS parameters
|
335
|
+
OracleEnhancedAdapter::DEFAULT_NLS_PARAMETERS.each do |key, default_value|
|
336
|
+
value = config[key] || ENV[key.to_s.upcase] || default_value
|
337
|
+
if value
|
338
|
+
conn.exec "alter session set #{key} = '#{value}'"
|
339
|
+
end
|
345
340
|
end
|
341
|
+
conn
|
346
342
|
end
|
347
|
-
conn
|
348
343
|
end
|
349
344
|
end
|
350
345
|
end
|