ruby-plsql 0.5.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.github/stale.yml +37 -0
  3. data/.github/workflows/rubocop.yml +37 -0
  4. data/.github/workflows/test.yml +69 -0
  5. data/.rubocop.yml +147 -0
  6. data/.travis.yml +88 -0
  7. data/.travis/oracle/download.sh +15 -0
  8. data/.travis/oracle/install.sh +32 -0
  9. data/.travis/setup_accounts.sh +9 -0
  10. data/Gemfile +17 -9
  11. data/History.txt +76 -0
  12. data/README.md +29 -6
  13. data/Rakefile +31 -26
  14. data/VERSION +1 -1
  15. data/Vagrantfile +4 -4
  16. data/ci/network/admin/tnsnames.ora +7 -0
  17. data/ci/setup_accounts.sh +9 -0
  18. data/gemfiles/Gemfile.activerecord-5.0 +21 -0
  19. data/gemfiles/Gemfile.activerecord-5.1 +21 -0
  20. data/gemfiles/Gemfile.activerecord-5.2 +21 -0
  21. data/gemfiles/Gemfile.activerecord-6.0 +21 -0
  22. data/gemfiles/Gemfile.activerecord-6.1 +21 -0
  23. data/gemfiles/Gemfile.activerecord-main +21 -0
  24. data/lib/plsql/connection.rb +19 -22
  25. data/lib/plsql/helpers.rb +1 -3
  26. data/lib/plsql/jdbc_connection.rb +70 -68
  27. data/lib/plsql/oci8_patches.rb +2 -2
  28. data/lib/plsql/oci_connection.rb +62 -77
  29. data/lib/plsql/package.rb +61 -46
  30. data/lib/plsql/procedure.rb +358 -78
  31. data/lib/plsql/procedure_call.rb +508 -463
  32. data/lib/plsql/schema.rb +96 -101
  33. data/lib/plsql/sequence.rb +10 -13
  34. data/lib/plsql/sql_statements.rb +9 -11
  35. data/lib/plsql/table.rb +60 -63
  36. data/lib/plsql/type.rb +71 -76
  37. data/lib/plsql/variable.rb +90 -94
  38. data/lib/plsql/version.rb +1 -1
  39. data/lib/plsql/view.rb +16 -19
  40. data/ruby-plsql.gemspec +55 -35
  41. data/spec/plsql/connection_spec.rb +72 -66
  42. data/spec/plsql/package_spec.rb +63 -14
  43. data/spec/plsql/procedure_spec.rb +603 -261
  44. data/spec/plsql/schema_spec.rb +47 -23
  45. data/spec/plsql/sequence_spec.rb +2 -2
  46. data/spec/plsql/sql_statements_spec.rb +6 -6
  47. data/spec/plsql/table_spec.rb +84 -79
  48. data/spec/plsql/type_spec.rb +24 -30
  49. data/spec/plsql/variable_spec.rb +80 -88
  50. data/spec/plsql/version_spec.rb +4 -4
  51. data/spec/plsql/view_spec.rb +42 -42
  52. data/spec/spec_helper.rb +38 -35
  53. data/spec/support/create_arunit_user.sql +2 -0
  54. data/spec/support/custom_config.rb.sample +14 -0
  55. data/spec/support/test_db.rb +12 -13
  56. data/spec/support/unlock_and_setup_hr_user.sql +2 -0
  57. metadata +111 -34
@@ -25,20 +25,20 @@ module PLSQL
25
25
 
26
26
  def self.create_new(params) #:nodoc:
27
27
  conn = case driver_type
28
- when :oci
29
- OCIConnection.create_raw(params)
30
- when :jdbc
31
- JDBCConnection.create_raw(params)
32
- else
33
- raise ArgumentError, "Unknown raw driver"
28
+ when :oci
29
+ OCIConnection.create_raw(params)
30
+ when :jdbc
31
+ JDBCConnection.create_raw(params)
32
+ else
33
+ raise ArgumentError, "Unknown raw driver"
34
34
  end
35
- conn.set_time_zone(params[:time_zone])
35
+ conn.set_time_zone(params[:time_zone] || ENV["ORA_SDTZ"])
36
36
  conn
37
37
  end
38
38
 
39
39
  def self.driver_type #:nodoc:
40
- # MRI 1.8.6 or YARV 1.9.1
41
- @driver_type ||= if (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby") && defined?(OCI8)
40
+ # MRI 1.8.6 or YARV 1.9.1 or TruffleRuby
41
+ @driver_type ||= if (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "truffleruby") && defined?(OCI8)
42
42
  :oci
43
43
  # JRuby
44
44
  elsif (defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby")
@@ -66,7 +66,7 @@ module PLSQL
66
66
  def jdbc?
67
67
  @raw_driver == :jdbc
68
68
  end
69
-
69
+
70
70
  def logoff #:nodoc:
71
71
  # Rollback any uncommited transactions
72
72
  rollback
@@ -99,14 +99,14 @@ module PLSQL
99
99
  end
100
100
 
101
101
  def select_first(sql, *bindvars) #:nodoc:
102
- cursor = cursor_from_query(sql, bindvars, :prefetch_rows => 1)
102
+ cursor = cursor_from_query(sql, bindvars, prefetch_rows: 1)
103
103
  cursor.fetch
104
104
  ensure
105
105
  cursor.close rescue nil
106
106
  end
107
107
 
108
108
  def select_hash_first(sql, *bindvars) #:nodoc:
109
- cursor = cursor_from_query(sql, bindvars, :prefetch_rows => 1)
109
+ cursor = cursor_from_query(sql, bindvars, prefetch_rows: 1)
110
110
  cursor.fetch_hash
111
111
  ensure
112
112
  cursor.close rescue nil
@@ -183,7 +183,7 @@ module PLSQL
183
183
  # this implementation is overriden in OCI connection with faster native OCI method
184
184
  def describe_synonym(schema_name, synonym_name) #:nodoc:
185
185
  select_first(
186
- "SELECT table_owner, table_name FROM all_synonyms WHERE owner = :owner AND synonym_name = :synonym_name",
186
+ "SELECT table_owner, table_name FROM all_synonyms WHERE owner = :owner AND synonym_name = :synonym_name",
187
187
  schema_name.to_s.upcase, synonym_name.to_s.upcase)
188
188
  end
189
189
 
@@ -197,9 +197,8 @@ module PLSQL
197
197
  @session_id ||= select_first("SELECT TO_NUMBER(USERENV('SESSIONID')) FROM dual")[0]
198
198
  end
199
199
 
200
- # Set time zone (default taken from TZ environment variable)
201
- def set_time_zone(time_zone=nil)
202
- time_zone ||= ENV['TZ']
200
+ # Set time zone
201
+ def set_time_zone(time_zone = nil)
203
202
  exec("alter session set time_zone = '#{time_zone}'") if time_zone
204
203
  end
205
204
 
@@ -208,12 +207,12 @@ module PLSQL
208
207
  select_first("SELECT SESSIONTIMEZONE FROM dual")[0]
209
208
  end
210
209
 
211
- RUBY_TEMP_TABLE_PREFIX = 'ruby_'
210
+ RUBY_TEMP_TABLE_PREFIX = "ruby_"
212
211
 
213
212
  # Drop all ruby temporary tables that are used for calling packages with table parameter types defined in packages
214
213
  def drop_all_ruby_temporary_tables
215
214
  select_all("SELECT table_name FROM user_tables WHERE temporary='Y' AND table_name LIKE :table_name",
216
- RUBY_TEMP_TABLE_PREFIX.upcase+'%').each do |row|
215
+ RUBY_TEMP_TABLE_PREFIX.upcase + "%").each do |row|
217
216
  exec "TRUNCATE TABLE #{row[0]}"
218
217
  exec "DROP TABLE #{row[0]}"
219
218
  end
@@ -222,12 +221,10 @@ module PLSQL
222
221
  # Drop ruby temporary tables created in current session that are used for calling packages with table parameter types defined in packages
223
222
  def drop_session_ruby_temporary_tables
224
223
  select_all("SELECT table_name FROM user_tables WHERE temporary='Y' AND table_name LIKE :table_name",
225
- RUBY_TEMP_TABLE_PREFIX.upcase+"#{session_id}_%").each do |row|
224
+ RUBY_TEMP_TABLE_PREFIX.upcase + "#{session_id}_%").each do |row|
226
225
  exec "TRUNCATE TABLE #{row[0]}"
227
226
  exec "DROP TABLE #{row[0]}"
228
227
  end
229
228
  end
230
-
231
229
  end
232
-
233
- end
230
+ end
data/lib/plsql/helpers.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  module PLSQL #:nodoc:
2
2
  module ArrayHelpers #:nodoc:
3
-
4
3
  def self.to_hash(keys, values) #:nodoc:
5
4
  (0...keys.size).inject({}) { |hash, i| hash[keys[i]] = values[i]; hash }
6
5
  end
7
-
8
6
  end
9
- end
7
+ end
@@ -5,21 +5,31 @@ begin
5
5
  # ojdbc6.jar or ojdbc5.jar file should be in JRUBY_HOME/lib or should be in ENV['PATH'] or load path
6
6
 
7
7
  java_version = java.lang.System.getProperty("java.version")
8
- ojdbc_jar = if java_version =~ /^1.5/
9
- "ojdbc5.jar"
10
- elsif java_version >= '1.6'
11
- "ojdbc6.jar"
8
+ ojdbc_jars = if java_version =~ /^1.5/
9
+ %w(ojdbc5.jar)
10
+ elsif java_version =~ /^1.6/
11
+ %w(ojdbc6.jar)
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)
12
16
  else
13
- nil
17
+ []
14
18
  end
15
19
 
16
- unless ENV_JAVA['java.class.path'] =~ Regexp.new(ojdbc_jar)
20
+ if ENV_JAVA["java.class.path"] !~ Regexp.new(ojdbc_jars.join("|"))
17
21
  # On Unix environment variable should be PATH, on Windows it is sometimes Path
18
- env_path = (ENV["PATH"] || ENV["Path"] || '').split(/[:;]/)
22
+ env_path = (ENV["PATH"] || ENV["Path"] || "").split(File::PATH_SEPARATOR)
19
23
  # Look for JDBC driver at first in lib subdirectory (application specific JDBC file version)
20
24
  # then in Ruby load path and finally in environment PATH
21
- if ojdbc_jar_path = ['./lib'].concat($LOAD_PATH).concat(env_path).find{|d| File.exists?(File.join(d,ojdbc_jar))}
22
- require File.join(ojdbc_jar_path,ojdbc_jar)
25
+ ["./lib"].concat($LOAD_PATH).concat(env_path).detect do |dir|
26
+ # check any compatible JDBC driver in the priority order
27
+ ojdbc_jars.any? do |ojdbc_jar|
28
+ if File.exists?(file_path = File.join(dir, ojdbc_jar))
29
+ require file_path
30
+ true
31
+ end
32
+ end
23
33
  end
24
34
  end
25
35
 
@@ -32,15 +42,14 @@ begin
32
42
 
33
43
  rescue LoadError, NameError
34
44
  # JDBC driver is unavailable.
35
- raise LoadError, "ERROR: ruby-plsql could not load Oracle JDBC driver. Please install #{ojdbc_jar || "Oracle JDBC"} library."
45
+ raise LoadError, "ERROR: ruby-plsql could not load Oracle JDBC driver. Please install #{ojdbc_jars.empty? ? "Oracle JDBC" : ojdbc_jars.join(' or ') } library."
36
46
  end
37
47
 
38
48
  module PLSQL
39
49
  class JDBCConnection < Connection #:nodoc:
40
-
41
50
  def self.create_raw(params)
42
51
  database = params[:database]
43
- url = if ENV['TNS_ADMIN'] && database && !params[:host] && !params[:url]
52
+ url = if ENV["TNS_ADMIN"] && database && !params[:host] && !params[:url]
44
53
  "jdbc:oracle:thin:@#{database}"
45
54
  else
46
55
  database = ":#{database}" unless database.match(/^(\:|\/)/)
@@ -49,9 +58,8 @@ module PLSQL
49
58
  new(java.sql.DriverManager.getConnection(url, params[:username], params[:password]))
50
59
  end
51
60
 
52
- def set_time_zone(time_zone=nil)
53
- time_zone ||= ENV['TZ']
54
- raw_connection.setSessionTimeZone(time_zone)
61
+ def set_time_zone(time_zone = nil)
62
+ raw_connection.setSessionTimeZone(time_zone) if time_zone
55
63
  end
56
64
 
57
65
  def logoff
@@ -91,7 +99,6 @@ module PLSQL
91
99
  end
92
100
 
93
101
  class CallableStatement #:nodoc:
94
-
95
102
  def initialize(conn, sql)
96
103
  @sql = sql
97
104
  @connection = conn
@@ -108,11 +115,11 @@ module PLSQL
108
115
  if metadata[:in_out] =~ /OUT/
109
116
  @out_types[arg] = type || ora_value.class
110
117
  @out_index[arg] = bind_param_index(arg)
111
- if ['TABLE','VARRAY','OBJECT'].include?(metadata[:data_type])
112
- @statement.registerOutParameter(@out_index[arg], @connection.get_java_sql_type(ora_value,type),
118
+ if ["TABLE", "VARRAY", "OBJECT", "XMLTYPE"].include?(metadata[:data_type])
119
+ @statement.registerOutParameter(@out_index[arg], @connection.get_java_sql_type(ora_value, type),
113
120
  metadata[:sql_type_name])
114
121
  else
115
- @statement.registerOutParameter(@out_index[arg],@connection.get_java_sql_type(ora_value,type))
122
+ @statement.registerOutParameter(@out_index[arg], @connection.get_java_sql_type(ora_value, type))
116
123
  end
117
124
  end
118
125
  end
@@ -131,11 +138,11 @@ module PLSQL
131
138
 
132
139
  private
133
140
 
134
- def bind_param_index(key)
135
- return key if key.kind_of? Integer
136
- key = ":#{key.to_s}" unless key.to_s =~ /^:/
137
- @params.index(key)+1
138
- end
141
+ def bind_param_index(key)
142
+ return key if key.kind_of? Integer
143
+ key = ":#{key.to_s}" unless key.to_s =~ /^:/
144
+ @params.index(key) + 1
145
+ end
139
146
  end
140
147
 
141
148
  class Cursor #:nodoc:
@@ -151,11 +158,11 @@ module PLSQL
151
158
  @column_count = @metadata.getColumnCount
152
159
  @column_type_names = [nil] # column numbering starts at 1
153
160
  (1..@column_count).each do |i|
154
- @column_type_names << {:type_name => @metadata.getColumnTypeName(i), :sql_type => @metadata.getColumnType(i)}
161
+ @column_type_names << { type_name: @metadata.getColumnTypeName(i), sql_type: @metadata.getColumnType(i) }
155
162
  end
156
163
  end
157
164
 
158
- def self.new_from_query(conn, sql, bindvars=[], options={})
165
+ def self.new_from_query(conn, sql, bindvars = [], options = {})
159
166
  stmt = conn.prepare_statement(sql, *bindvars)
160
167
  if prefetch_rows = options[:prefetch_rows]
161
168
  stmt.setRowPrefetch(prefetch_rows)
@@ -195,14 +202,14 @@ module PLSQL
195
202
  CallableStatement.new(self, sql)
196
203
  end
197
204
 
198
- def cursor_from_query(sql, bindvars=[], options={})
205
+ def cursor_from_query(sql, bindvars = [], options = {})
199
206
  Cursor.new_from_query(self, sql, bindvars, options)
200
207
  end
201
208
 
202
209
  def prepare_statement(sql, *bindvars)
203
210
  stmt = raw_connection.prepareStatement(sql)
204
211
  bindvars.each_with_index do |bv, i|
205
- set_bind_variable(stmt, i+1, ruby_value_to_ora_value(bv))
212
+ set_bind_variable(stmt, i + 1, ruby_value_to_ora_value(bv))
206
213
  end
207
214
  stmt
208
215
  end
@@ -210,14 +217,12 @@ module PLSQL
210
217
  def prepare_call(sql, *bindvars)
211
218
  stmt = raw_connection.prepareCall(sql)
212
219
  bindvars.each_with_index do |bv, i|
213
- set_bind_variable(stmt, i+1, bv)
220
+ set_bind_variable(stmt, i + 1, bv)
214
221
  end
215
222
  stmt
216
223
  end
217
224
 
218
225
  RUBY_CLASS_TO_SQL_TYPE = {
219
- Fixnum => java.sql.Types::INTEGER,
220
- Bignum => java.sql.Types::INTEGER,
221
226
  Integer => java.sql.Types::INTEGER,
222
227
  Float => java.sql.Types::FLOAT,
223
228
  BigDecimal => java.sql.Types::NUMERIC,
@@ -241,7 +246,7 @@ module PLSQL
241
246
  java.sql.Types::NVARCHAR => String,
242
247
  java.sql.Types::LONGVARCHAR => String,
243
248
  java.sql.Types::NUMERIC => BigDecimal,
244
- java.sql.Types::INTEGER => Fixnum,
249
+ java.sql.Types::INTEGER => Integer,
245
250
  java.sql.Types::DATE => Time,
246
251
  java.sql.Types::TIMESTAMP => Time,
247
252
  Java::oracle.jdbc.OracleTypes::TIMESTAMPTZ => Time,
@@ -257,8 +262,8 @@ module PLSQL
257
262
  RUBY_CLASS_TO_SQL_TYPE[type || value.class] || java.sql.Types::VARCHAR
258
263
  end
259
264
 
260
- def set_bind_variable(stmt, i, value, type=nil, length=nil, metadata={})
261
- key = i.kind_of?(Integer) ? nil : i.to_s.gsub(':','')
265
+ def set_bind_variable(stmt, i, value, type = nil, length = nil, metadata = {})
266
+ key = i.kind_of?(Integer) ? nil : i.to_s.gsub(":", "")
262
267
  type_symbol = (!value.nil? && type ? type : value.class).to_s.to_sym
263
268
  case type_symbol
264
269
  when :Fixnum, :Bignum, :Integer
@@ -278,10 +283,10 @@ module PLSQL
278
283
  when :Time, :'Java::JavaSql::Timestamp'
279
284
  stmt.send("setTimestamp#{key && "AtName"}", key || i, value)
280
285
  when :NilClass
281
- if ['TABLE', 'VARRAY', 'OBJECT'].include?(metadata[:data_type])
286
+ if ["TABLE", "VARRAY", "OBJECT", "XMLTYPE"].include?(metadata[:data_type])
282
287
  stmt.send("setNull#{key && "AtName"}", key || i, get_java_sql_type(value, type),
283
288
  metadata[:sql_type_name])
284
- elsif metadata[:data_type] == 'REF CURSOR'
289
+ elsif metadata[:data_type] == "REF CURSOR"
285
290
  # TODO: cannot bind NULL value to cursor parameter, getting error
286
291
  # java.sql.SQLException: Unsupported feature: sqlType=-10
287
292
  # Currently do nothing and assume that NULL values will not be passed to IN parameters
@@ -305,12 +310,12 @@ module PLSQL
305
310
  def get_bind_variable(stmt, i, type)
306
311
  case type.to_s.to_sym
307
312
  when :Fixnum, :Bignum, :Integer
308
- stmt.getInt(i)
313
+ stmt.getObject(i)
309
314
  when :Float
310
315
  stmt.getFloat(i)
311
316
  when :BigDecimal
312
317
  bd = stmt.getBigDecimal(i)
313
- bd && BigDecimal.new(bd.to_s)
318
+ bd && BigDecimal(bd.to_s)
314
319
  when :String
315
320
  stmt.getString(i)
316
321
  when :'Java::OracleSql::CLOB'
@@ -337,13 +342,12 @@ module PLSQL
337
342
  end
338
343
 
339
344
  def result_set_to_ruby_data_type(column_type, column_type_name)
340
-
341
345
  end
342
346
 
343
347
  def plsql_to_ruby_data_type(metadata)
344
348
  data_type, data_length = metadata[:data_type], metadata[:data_length]
345
349
  case data_type
346
- when "VARCHAR2", "CHAR", "NVARCHAR2", "NCHAR"
350
+ when "VARCHAR", "VARCHAR2", "CHAR", "NVARCHAR2", "NCHAR"
347
351
  [String, data_length || 32767]
348
352
  when "CLOB", "NCLOB"
349
353
  [Java::OracleSql::CLOB, nil]
@@ -351,8 +355,8 @@ module PLSQL
351
355
  [Java::OracleSql::BLOB, nil]
352
356
  when "NUMBER"
353
357
  [BigDecimal, nil]
354
- when "PLS_INTEGER", "BINARY_INTEGER"
355
- [Fixnum, nil]
358
+ when "NATURAL", "NATURALN", "POSITIVE", "POSITIVEN", "SIGNTYPE", "SIMPLE_INTEGER", "PLS_INTEGER", "BINARY_INTEGER"
359
+ [Integer, nil]
356
360
  when "DATE"
357
361
  [DateTime, nil]
358
362
  when "TIMESTAMP", "TIMESTAMP WITH TIME ZONE", "TIMESTAMP WITH LOCAL TIME ZONE"
@@ -368,10 +372,10 @@ module PLSQL
368
372
  end
369
373
  end
370
374
 
371
- def ruby_value_to_ora_value(value, type=nil, metadata={})
375
+ def ruby_value_to_ora_value(value, type = nil, metadata = {})
372
376
  type ||= value.class
373
377
  case type.to_s.to_sym
374
- when :Fixnum
378
+ when :Integer
375
379
  value
376
380
  when :String
377
381
  value.to_s
@@ -420,9 +424,9 @@ module PLSQL
420
424
  elem_list = value.map do |elem|
421
425
  case elem_type
422
426
  when Java::oracle.jdbc.OracleTypes::ARRAY
423
- ruby_value_to_ora_value(elem, Java::OracleSql::ARRAY, :sql_type_name => elem_type_name)
427
+ ruby_value_to_ora_value(elem, Java::OracleSql::ARRAY, sql_type_name: elem_type_name)
424
428
  when Java::oracle.jdbc.OracleTypes::STRUCT
425
- ruby_value_to_ora_value(elem, Java::OracleSql::STRUCT, :sql_type_name => elem_type_name)
429
+ ruby_value_to_ora_value(elem, Java::OracleSql::STRUCT, sql_type_name: elem_type_name)
426
430
  else
427
431
  ruby_value_to_ora_value(elem)
428
432
  end
@@ -436,7 +440,7 @@ module PLSQL
436
440
  struct_metadata = descriptor.getMetaData
437
441
  struct_fields = (1..descriptor.getLength).inject({}) do |hash, i|
438
442
  hash[struct_metadata.getColumnName(i).downcase.to_sym] =
439
- {:type => struct_metadata.getColumnType(i), :type_name => struct_metadata.getColumnTypeName(i)}
443
+ { type: struct_metadata.getColumnType(i), type_name: struct_metadata.getColumnTypeName(i) }
440
444
  hash
441
445
  end
442
446
  object_attrs = java.util.HashMap.new
@@ -445,10 +449,10 @@ module PLSQL
445
449
  case field[:type]
446
450
  when Java::oracle.jdbc.OracleTypes::ARRAY
447
451
  # nested collection
448
- object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value, Java::OracleSql::ARRAY, :sql_type_name => field[:type_name]))
452
+ object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value, Java::OracleSql::ARRAY, sql_type_name: field[:type_name]))
449
453
  when Java::oracle.jdbc.OracleTypes::STRUCT
450
454
  # nested object type
451
- object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value, Java::OracleSql::STRUCT, :sql_type_name => field[:type_name]))
455
+ object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value, Java::OracleSql::STRUCT, sql_type_name: field[:type_name]))
452
456
  else
453
457
  object_attrs.put(key.to_s.upcase, ruby_value_to_ora_value(attr_value))
454
458
  end
@@ -469,7 +473,7 @@ module PLSQL
469
473
  when Float, BigDecimal
470
474
  ora_number_to_ruby_number(value)
471
475
  when Java::JavaMath::BigDecimal
472
- value && ora_number_to_ruby_number(BigDecimal.new(value.to_s))
476
+ value && ora_number_to_ruby_number(BigDecimal(value.to_s))
473
477
  when Java::OracleSql::DATE
474
478
  if value
475
479
  d = value.dateValue
@@ -494,12 +498,12 @@ module PLSQL
494
498
  String.from_java_bytes(value.getBytes(1, value.length))
495
499
  end
496
500
  when Java::OracleSql::ARRAY
497
- value.getArray.map{|e| ora_value_to_ruby_value(e)}
501
+ value.getArray.map { |e| ora_value_to_ruby_value(e) }
498
502
  when Java::OracleSql::STRUCT
499
503
  descriptor = value.getDescriptor
500
504
  struct_metadata = descriptor.getMetaData
501
- field_names = (1..descriptor.getLength).map {|i| struct_metadata.getColumnName(i).downcase.to_sym}
502
- field_values = value.getAttributes.map{|e| ora_value_to_ruby_value(e)}
505
+ field_names = (1..descriptor.getLength).map { |i| struct_metadata.getColumnName(i).downcase.to_sym }
506
+ field_values = value.getAttributes.map { |e| ora_value_to_ruby_value(e) }
503
507
  ArrayHelpers::to_hash(field_names, field_values)
504
508
  when Java::java.sql.ResultSet
505
509
  Cursor.new(self, value)
@@ -524,23 +528,21 @@ module PLSQL
524
528
 
525
529
  private
526
530
 
527
- def java_date(value)
528
- value && Java::oracle.sql.DATE.new(value.strftime("%Y-%m-%d %H:%M:%S"))
529
- end
530
-
531
- def java_timestamp(value)
532
- value && Java::java.sql.Timestamp.new(value.year-1900, value.month-1, value.day, value.hour, value.min, value.sec, value.usec * 1000)
533
- end
531
+ def java_date(value)
532
+ value && Java::oracle.sql.DATE.new(value.strftime("%Y-%m-%d %H:%M:%S"))
533
+ end
534
534
 
535
- def java_bigdecimal(value)
536
- value && java.math.BigDecimal.new(value.to_s)
537
- end
535
+ def java_timestamp(value)
536
+ value && Java::java.sql.Timestamp.new(value.year - 1900, value.month - 1, value.day, value.hour, value.min, value.sec, value.usec * 1000)
537
+ end
538
538
 
539
- def ora_number_to_ruby_number(num)
540
- # return BigDecimal instead of Float to avoid rounding errors
541
- num == (num_to_i = num.to_i) ? num_to_i : (num.is_a?(BigDecimal) ? num : BigDecimal.new(num.to_s))
542
- end
539
+ def java_bigdecimal(value)
540
+ value && java.math.BigDecimal.new(value.to_s)
541
+ end
543
542
 
543
+ def ora_number_to_ruby_number(num)
544
+ # return BigDecimal instead of Float to avoid rounding errors
545
+ num == (num_to_i = num.to_i) ? num_to_i : (num.is_a?(BigDecimal) ? num : BigDecimal(num.to_s))
546
+ end
544
547
  end
545
-
546
548
  end
@@ -21,5 +21,5 @@ if OCI8::VERSION == "2.0.3" &&
21
21
  end
22
22
  private :datetime_to_array_without_timestamp_patch, :datetime_to_array
23
23
  end
24
-
25
- end
24
+
25
+ end