activerecord-oracle_enhanced-adapter 7.2.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/History.md +1977 -0
  3. data/License.txt +20 -0
  4. data/README.md +863 -0
  5. data/VERSION +1 -0
  6. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +7 -0
  7. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +24 -0
  8. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +137 -0
  9. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +344 -0
  10. data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +47 -0
  11. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +295 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +63 -0
  13. data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +71 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +561 -0
  15. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +38 -0
  16. data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +45 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +457 -0
  18. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +44 -0
  19. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +195 -0
  20. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +186 -0
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +94 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +99 -0
  23. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +197 -0
  24. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +738 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +366 -0
  26. data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +34 -0
  27. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +3 -0
  28. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +865 -0
  29. data/lib/active_record/type/oracle_enhanced/boolean.rb +19 -0
  30. data/lib/active_record/type/oracle_enhanced/character_string.rb +36 -0
  31. data/lib/active_record/type/oracle_enhanced/integer.rb +14 -0
  32. data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
  33. data/lib/active_record/type/oracle_enhanced/national_character_string.rb +26 -0
  34. data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
  35. data/lib/active_record/type/oracle_enhanced/raw.rb +25 -0
  36. data/lib/active_record/type/oracle_enhanced/string.rb +29 -0
  37. data/lib/active_record/type/oracle_enhanced/text.rb +32 -0
  38. data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
  39. data/lib/active_record/type/oracle_enhanced/timestamptz.rb +25 -0
  40. data/lib/activerecord-oracle_enhanced-adapter.rb +25 -0
  41. data/lib/arel/visitors/oracle.rb +216 -0
  42. data/lib/arel/visitors/oracle12.rb +121 -0
  43. data/lib/arel/visitors/oracle_common.rb +51 -0
  44. data/spec/active_record/connection_adapters/emulation/oracle_adapter_spec.rb +24 -0
  45. data/spec/active_record/connection_adapters/oracle_enhanced/compatibility_spec.rb +36 -0
  46. data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +574 -0
  47. data/spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb +431 -0
  48. data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +122 -0
  49. data/spec/active_record/connection_adapters/oracle_enhanced/dbms_output_spec.rb +69 -0
  50. data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +362 -0
  51. data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +181 -0
  52. data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +492 -0
  53. data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +1289 -0
  54. data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +474 -0
  55. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +815 -0
  56. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +230 -0
  57. data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
  58. data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +206 -0
  59. data/spec/active_record/oracle_enhanced/type/character_string_spec.rb +67 -0
  60. data/spec/active_record/oracle_enhanced/type/custom_spec.rb +90 -0
  61. data/spec/active_record/oracle_enhanced/type/decimal_spec.rb +56 -0
  62. data/spec/active_record/oracle_enhanced/type/dirty_spec.rb +141 -0
  63. data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
  64. data/spec/active_record/oracle_enhanced/type/integer_spec.rb +99 -0
  65. data/spec/active_record/oracle_enhanced/type/json_spec.rb +56 -0
  66. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +56 -0
  67. data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
  68. data/spec/active_record/oracle_enhanced/type/raw_spec.rb +137 -0
  69. data/spec/active_record/oracle_enhanced/type/text_spec.rb +244 -0
  70. data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +77 -0
  71. data/spec/spec_config.yaml.template +11 -0
  72. data/spec/spec_helper.rb +214 -0
  73. data/spec/support/alter_system_set_open_cursors.sql +1 -0
  74. data/spec/support/alter_system_user_password.sql +2 -0
  75. data/spec/support/create_oracle_enhanced_users.sql +31 -0
  76. metadata +177 -0
data/README.md ADDED
@@ -0,0 +1,863 @@
1
+ activerecord-oracle_enhanced-adapter
2
+ ====================================
3
+
4
+ Oracle enhanced adapter for ActiveRecord
5
+
6
+ DESCRIPTION
7
+ -----------
8
+
9
+ Oracle enhanced ActiveRecord adapter provides Oracle database access from Ruby on Rails applications. Oracle enhanced adapter can be used from Ruby on Rails versions between 2.3.x and 7.2 and it is working with Oracle database versions 10g and higher
10
+
11
+ INSTALLATION
12
+ ------------
13
+ ### Rails 7.2
14
+
15
+ Oracle enhanced adapter version 7.2 supports Rails 7.2
16
+ When using Ruby on Rails version 7.2 then in Gemfile include
17
+
18
+ ```ruby
19
+ # Use oracle as the database for Active Record
20
+ gem 'activerecord-oracle_enhanced-adapter', '~> 7.2.0'
21
+ ```
22
+
23
+ ### Rails 7.1
24
+
25
+ Oracle enhanced adapter version 7.1 supports Rails 7.1
26
+ When using Ruby on Rails version 7.1 then in Gemfile include
27
+
28
+ ```ruby
29
+ # Use oracle as the database for Active Record
30
+ gem 'activerecord-oracle_enhanced-adapter', '~> 7.1.0'
31
+ ```
32
+
33
+ ### Rails 7.0
34
+
35
+ Oracle enhanced adapter version 7.0 supports Rails 7.0
36
+ When using Ruby on Rails version 7.0 then in Gemfile include
37
+
38
+ ```ruby
39
+ # Use oracle as the database for Active Record
40
+ gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0'
41
+ ```
42
+
43
+ ### Rails 6.1
44
+
45
+ Oracle enhanced adapter version 6.1 supports Rails 6.1.
46
+ When using Ruby on Rails version 6.1 then in Gemfile include
47
+
48
+ ```ruby
49
+ # Use oracle as the database for Active Record
50
+ gem 'activerecord-oracle_enhanced-adapter', '~> 6.1.0'
51
+ gem 'ruby-oci8' # only for CRuby users
52
+ ```
53
+
54
+ ### Rails 6.0
55
+
56
+ Oracle enhanced adapter version 6.0 supports Rails 6.0.
57
+ When using Ruby on Rails version 6.0 then in Gemfile include
58
+
59
+ ```ruby
60
+ # Use oracle as the database for Active Record
61
+ gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0'
62
+ gem 'ruby-oci8' # only for CRuby users
63
+ ```
64
+
65
+ ### Rails 5.2
66
+
67
+ Oracle enhanced adapter version 5.2 supports Rails 5.2.
68
+ When using Ruby on Rails version 5.2 then in Gemfile include
69
+
70
+ ```ruby
71
+ # Use oracle as the database for Active Record
72
+ gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0'
73
+ gem 'ruby-oci8' # only for CRuby users
74
+ ```
75
+
76
+ ### Rails 5.1
77
+
78
+ Oracle enhanced adapter version 1.8 just supports Rails 5.1 and does not support Rails 5.0 or lower version of Rails.
79
+ When using Ruby on Rails version 5.1 then in Gemfile include
80
+
81
+ ```ruby
82
+ # Use oracle as the database for Active Record
83
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.8.0'
84
+ gem 'ruby-oci8' # only for CRuby users
85
+ ```
86
+
87
+ ### Rails 5.0
88
+
89
+ Oracle enhanced adapter version 1.7 just supports Rails 5.0 and does not support Rails 4.2 or lower version of Rails.
90
+ When using Ruby on Rails version 5.0 then in Gemfile include
91
+
92
+ ```ruby
93
+ # Use oracle as the database for Active Record
94
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.7.0'
95
+ gem 'ruby-oci8' # only for CRuby users
96
+ ```
97
+
98
+ ### Rails 4.2
99
+
100
+ Oracle enhanced adapter version 1.6 just supports Rails 4.2 and does not support Rails 4.1 or lower version of Rails.
101
+ When using Ruby on Rails version 4.2 then in Gemfile include
102
+
103
+ ```ruby
104
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
105
+ ```
106
+
107
+ where instead of 1.6.0 you can specify any other desired version. It is recommended to specify version with `~>` which means that use specified version or later patch versions (in this example any later 1.6.x version but not 1.7.x version). Oracle enhanced adapter maintains API backwards compatibility during patch version upgrades and therefore it is safe to always upgrade to latest patch version.
108
+
109
+ ### Rails 4.0 and 4.1
110
+
111
+ Oracle enhanced adapter version 1.5 supports Rails 4.0 and 4.1 and does not support Rails 3.2 or lower version of Rails.
112
+
113
+ When using Ruby on Rails version 4.0 and 4.1 then in Gemfile include
114
+
115
+ ```ruby
116
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.5.0'
117
+ ```
118
+
119
+ where instead of 1.5.0 you can specify any other desired version. It is recommended to specify version with `~>` which means that use specified version or later patch versions (in this example any later 1.5.x version but not 1.6.x version). Oracle enhanced adapter maintains API backwards compatibility during patch version upgrades and therefore it is safe to always upgrade to latest patch version.
120
+
121
+ If you would like to use latest adapter version from github then specify
122
+
123
+ ```ruby
124
+ gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
125
+ ```
126
+
127
+ If you are using CRuby >= 1.9.3 then you need to install ruby-oci8 gem as well as Oracle client, e.g. [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html). Include in Gemfile also ruby-oci8:
128
+
129
+ ```ruby
130
+ gem 'ruby-oci8', '~> 2.1.0'
131
+ ```
132
+
133
+ If you are using JRuby then you need to download latest [Oracle JDBC driver](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html) - either ojdbc7.jar or ojdbc6.jar for Java 7, ojdbc6.jar for Java 6 or ojdbc5.jar for Java 5. And copy this file to one of these locations:
134
+
135
+ * in `./lib` directory of Rails application
136
+ * in some directory which is in `PATH`
137
+ * in `JRUBY_HOME/lib` directory
138
+ * or include path to JDBC driver jar file in Java `CLASSPATH`
139
+
140
+ After specifying necessary gems in Gemfile run
141
+
142
+ ```bash
143
+ bundle install
144
+ ```
145
+
146
+ to install the adapter (or later run `bundle update` to force updating to latest version).
147
+
148
+ ### Rails 3
149
+
150
+ When using Ruby on Rails version 3 then in Gemfile include
151
+
152
+ ```ruby
153
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.0'
154
+ ```
155
+
156
+ where instead of 1.4.0 you can specify any other desired version. It is recommended to specify version with `~>` which means that use specified version or later patch versions (in this example any later 1.4.x version but not 1.5.x version). Oracle enhanced adapter maintains API backwards compatibility during patch version upgrades and therefore it is safe to always upgrade to latest patch version.
157
+
158
+ If you would like to use latest adapter version from github then specify
159
+
160
+ ```ruby
161
+ gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
162
+ ```
163
+
164
+ If you are using MRI 1.8 or 1.9 Ruby implementation then you need to install ruby-oci8 gem as well as Oracle client, e.g. [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html). Include in Gemfile also ruby-oci8:
165
+
166
+ ```ruby
167
+ gem 'ruby-oci8', '~> 2.1.0'
168
+ ```
169
+
170
+ If you are using JRuby then you need to download latest [Oracle JDBC driver](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html) - either ojdbc6.jar for Java 6 or ojdbc5.jar for Java 5. And copy this file to one of these locations:
171
+
172
+ * in `./lib` directory of Rails application
173
+ * in some directory which is in `PATH`
174
+ * in `JRUBY_HOME/lib` directory
175
+ * or include path to JDBC driver jar file in Java `CLASSPATH`
176
+
177
+ After specifying necessary gems in Gemfile run
178
+
179
+ ```bash
180
+ bundle install
181
+ ```
182
+
183
+ to install the adapter (or later run `bundle update` to force updating to latest version).
184
+
185
+ ### Rails 2.3
186
+
187
+ If you don't use Bundler in Rails 2 application then you need to specify gems in `config/environment.rb`, e.g.
188
+
189
+ ```ruby
190
+ Rails::Initializer.run do |config|
191
+ # ...
192
+ config.gem 'activerecord-oracle_enhanced-adapter', :lib => 'active_record/connection_adapters/oracle_enhanced_adapter'
193
+ config.gem 'ruby-oci8'
194
+ # ...
195
+ end
196
+ ```
197
+
198
+ But it is recommended to use Bundler for gem version management also for Rails 2.3 applications (search for instructions in Google).
199
+
200
+ ### Without Rails and Bundler
201
+
202
+ If you want to use ActiveRecord and Oracle enhanced adapter without Rails and Bundler then install it just as a gem:
203
+
204
+ ```bash
205
+ gem install activerecord-oracle_enhanced-adapter
206
+ ```
207
+
208
+ USAGE
209
+ -----
210
+
211
+ ### Database connection
212
+
213
+ In Rails application `config/database.yml` use oracle_enhanced as adapter name, e.g.
214
+
215
+ ```yml
216
+ development:
217
+ adapter: oracle_enhanced
218
+ database: xe
219
+ username: user
220
+ password: secret
221
+ ```
222
+
223
+ If you're connecting to a service name, indicate the service with a
224
+ leading slash on the database parameter:
225
+
226
+ ```yml
227
+ development:
228
+ adapter: oracle_enhanced
229
+ database: /xe
230
+ username: user
231
+ password: secret
232
+ ```
233
+
234
+ If `TNS_ADMIN` environment variable is pointing to directory where `tnsnames.ora` file is located then you can use TNS connection name in `database` parameter. Otherwise you can directly specify database host, port (defaults to 1521) and database name in the following way:
235
+
236
+ ```yml
237
+ development:
238
+ adapter: oracle_enhanced
239
+ host: localhost
240
+ port: 1521
241
+ database: xe
242
+ username: user
243
+ password: secret
244
+ ```
245
+
246
+ or you can use Oracle specific format in `database` parameter:
247
+
248
+ ```yml
249
+ development:
250
+ adapter: oracle_enhanced
251
+ database: //localhost:1521/xe
252
+ username: user
253
+ password: secret
254
+ ```
255
+
256
+ or you can even use Oracle specific TNS connection description:
257
+
258
+ ```yml
259
+ development:
260
+ adapter: oracle_enhanced
261
+ database: "(DESCRIPTION=
262
+ (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
263
+ (CONNECT_DATA=(SERVICE_NAME=xe))
264
+ )"
265
+ username: user
266
+ password: secret
267
+ ```
268
+
269
+
270
+ If you choose to specify your database connection via the `DATABASE_URL`
271
+ environment variable, note that the adapter name uses a dash instead of an underscore:
272
+
273
+ ```bash
274
+ DATABASE_URL=oracle-enhanced://localhost/XE
275
+ ```
276
+
277
+ You can also specify a connection string via the `DATABASE_URL`, as long as it doesn't have any whitespace:
278
+
279
+ ```bash
280
+ DATABASE_URL=oracle-enhanced://user:secret@connection-string/(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=xe)))
281
+ ```
282
+
283
+ If you deploy JRuby on Rails application in Java application server that supports JNDI connections then you can specify JNDI connection as well:
284
+
285
+ ```yml
286
+ development:
287
+ adapter: oracle_enhanced
288
+ jndi: "jdbc/jndi_connection_name"
289
+ ```
290
+
291
+ To use jndi with Tomcat you need to set the accessToUnderlyingConnectionAllowed to true property on the pool. See the [Tomcat Documentation](http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html) for reference.
292
+
293
+ You can find other available database.yml connection parameters in [oracle_enhanced_adapter.rb](http://github.com/rsim/oracle-enhanced/blob/master/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb). There are many NLS settings as well as some other Oracle session settings.
294
+
295
+ ### Adapter settings
296
+
297
+ If you want to change Oracle enhanced adapter default settings then create initializer file e.g. `config/initializers/oracle.rb` specify there necessary defaults, e.g.:
298
+
299
+ ```ruby
300
+ # It is recommended to set time zone in TZ environment variable so that the same timezone will be used by Ruby and by Oracle session
301
+ ENV['TZ'] = 'UTC'
302
+
303
+ ActiveSupport.on_load(:active_record) do
304
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
305
+ # true and false will be stored as 'Y' and 'N'
306
+ self.emulate_booleans_from_strings = true
307
+
308
+ # start primary key sequences from 1 (and not 10000) and take just one next value in each session
309
+ self.default_sequence_start_value = "1 NOCACHE INCREMENT BY 1"
310
+
311
+ # Use old visitor for Oracle 12c database
312
+ self.use_old_oracle_visitor = true
313
+
314
+ # other settings ...
315
+ end
316
+ end
317
+ ```
318
+
319
+ In case of Rails 2 application you do not need to use `ActiveSupport.on_load(:active_record) do ... end` around settings code block.
320
+
321
+ See other adapter settings in [oracle_enhanced_adapter.rb](http://github.com/rsim/oracle-enhanced/blob/master/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb).
322
+
323
+ ### Legacy schema support
324
+
325
+ If you want to put Oracle enhanced adapter on top of existing schema tables then there are several methods how to override ActiveRecord defaults, see example:
326
+
327
+ ```ruby
328
+ class Employee < ActiveRecord::Base
329
+ # specify schema and table name
330
+ self.table_name = "hr.hr_employees"
331
+
332
+ # specify primary key name
333
+ self.primary_key = "employee_id"
334
+
335
+ # specify sequence name
336
+ self.sequence_name = "hr.hr_employee_s"
337
+
338
+ # set which DATE columns should be converted to Ruby Date using ActiveRecord Attribute API
339
+ # Starting from Oracle enhanced adapter 1.7 Oracle `DATE` columns are mapped to Ruby `Date` by default.
340
+ attribute :hired_on, :date
341
+ attribute :birth_date_on, :date
342
+
343
+ # set which DATE columns should be converted to Ruby Time using ActiveRecord Attribute API
344
+ attribute :last_login_time, :datetime
345
+
346
+ # set which VARCHAR2 columns should be converted to true and false using ActiveRecord Attribute API
347
+ attribute :manager, :boolean
348
+ attribute :active, :boolean
349
+
350
+ # set which columns should be ignored in ActiveRecord
351
+ ignore_table_columns :attribute1, :attribute2
352
+ end
353
+ ```
354
+
355
+ You can also access remote tables over database link using
356
+
357
+ ```ruby
358
+ self.table_name "hr_employees@db_link"
359
+ ```
360
+
361
+ Examples for Rails 4.x
362
+
363
+ ```ruby
364
+ class Employee < ActiveRecord::Base
365
+ # specify schema and table name
366
+ self.table_name = "hr.hr_employees"
367
+
368
+ # specify primary key name
369
+ self.primary_key = "employee_id"
370
+
371
+ # specify sequence name
372
+ self.sequence_name = "hr.hr_employee_s"
373
+
374
+ # If you're using Rails 4.2 or earlier you can do this
375
+
376
+ # set which DATE columns should be converted to Ruby Date
377
+ set_date_columns :hired_on, :birth_date_on
378
+
379
+ # set which DATE columns should be converted to Ruby Time
380
+ set_datetime_columns :last_login_time
381
+
382
+ # set which VARCHAR2 columns should be converted to true and false
383
+ set_boolean_columns :manager, :active
384
+
385
+ # set which columns should be ignored in ActiveRecord
386
+ ignore_table_columns :attribute1, :attribute2
387
+ end
388
+ ```
389
+
390
+ Examples for Rails 3.2 and lower version of Rails
391
+
392
+ ```ruby
393
+ class Employee < ActiveRecord::Base
394
+ # specify schema and table name
395
+ set_table_name "hr.hr_employees"
396
+
397
+ # specify primary key name
398
+ set_primary_key "employee_id"
399
+
400
+ # specify sequence name
401
+ set_sequence_name "hr.hr_employee_s"
402
+
403
+ # set which DATE columns should be converted to Ruby Date
404
+ set_date_columns :hired_on, :birth_date_on
405
+
406
+ # set which DATE columns should be converted to Ruby Time
407
+ set_datetime_columns :last_login_time
408
+
409
+ # set which VARCHAR2 columns should be converted to true and false
410
+ set_boolean_columns :manager, :active
411
+
412
+ # set which columns should be ignored in ActiveRecord
413
+ ignore_table_columns :attribute1, :attribute2
414
+ end
415
+ ```
416
+
417
+ You can also access remote tables over database link using
418
+
419
+ ```ruby
420
+ set_table_name "hr_employees@db_link"
421
+ ```
422
+
423
+ ### Custom create, update and delete methods
424
+
425
+ If you have legacy schema and you are not allowed to do direct INSERTs, UPDATEs and DELETEs in legacy schema tables and need to use existing PL/SQL procedures for create, updated, delete operations then you should add `ruby-plsql` gem to your application, include `ActiveRecord::OracleEnhancedProcedures` in your model and then define custom create, update and delete methods, see example:
426
+
427
+ ```ruby
428
+ class Employee < ActiveRecord::Base
429
+ include ActiveRecord::OracleEnhancedProcedures
430
+
431
+ # when defining create method then return ID of new record that will be assigned to id attribute of new object
432
+ set_create_method do
433
+ plsql.employees_pkg.create_employee(
434
+ :p_first_name => first_name,
435
+ :p_last_name => last_name,
436
+ :p_employee_id => nil
437
+ )[:p_employee_id]
438
+ end
439
+
440
+ set_update_method do
441
+ plsql.employees_pkg.update_employee(
442
+ :p_employee_id => id,
443
+ :p_first_name => first_name,
444
+ :p_last_name => last_name
445
+ )
446
+ end
447
+
448
+ set_delete_method do
449
+ plsql.employees_pkg.delete_employee(
450
+ :p_employee_id => id
451
+ )
452
+ end
453
+ end
454
+ ```
455
+
456
+ In addition in `config/initializers/oracle.rb` initializer specify that ruby-plsql should use ActiveRecord database connection:
457
+
458
+ ```ruby
459
+ plsql.activerecord_class = ActiveRecord::Base
460
+ ```
461
+
462
+ ### Oracle CONTEXT index support
463
+
464
+ Every edition of Oracle database includes [Oracle Text](http://www.oracle.com/technology/products/text/index.html) option for free which provides several full text indexing capabilities. Therefore in Oracle database case you don’t need external full text indexing and searching engines which can simplify your application deployment architecture.
465
+
466
+ To create simple single column index create migration with, e.g.
467
+
468
+ ```ruby
469
+ add_context_index :posts, :title
470
+ ```
471
+
472
+ and you can remove context index with
473
+
474
+ ```ruby
475
+ remove_context_index :posts, :title
476
+ ```
477
+
478
+ Include in class definition
479
+
480
+ ```ruby
481
+ has_context_index
482
+ ```
483
+
484
+ and then you can do full text search with
485
+
486
+ ```ruby
487
+ Post.contains(:title, 'word')
488
+ ```
489
+
490
+ You can create index on several columns (which will generate additional stored procedure for providing XML document with specified columns to indexer):
491
+
492
+ ```ruby
493
+ add_context_index :posts, [:title, :body]
494
+ ```
495
+
496
+ And you can search either in all columns or specify in which column you want to search (as first argument you need to specify first column name as this is the column which is referenced during index creation):
497
+
498
+ ```ruby
499
+ Post.contains(:title, 'word')
500
+ Post.contains(:title, 'word within title')
501
+ Post.contains(:title, 'word within body')
502
+ ```
503
+
504
+ See Oracle Text documentation for syntax that you can use in CONTAINS function in SELECT WHERE clause.
505
+
506
+ You can also specify some dummy main column name when creating multiple column index as well as specify to update index automatically after each commit (as otherwise you need to synchronize index manually or schedule periodic update):
507
+
508
+ ```ruby
509
+ add_context_index :posts, [:title, :body], :index_column => :all_text, :sync => 'ON COMMIT'
510
+
511
+ Post.contains(:all_text, 'word')
512
+ ```
513
+
514
+ Or you can specify that index should be updated when specified columns are updated (e.g. in ActiveRecord you can specify to trigger index update when created_at or updated_at columns are updated). Otherwise index is updated only when main index column is updated.
515
+
516
+ ```ruby
517
+ add_context_index :posts, [:title, :body], :index_column => :all_text,
518
+ :sync => 'ON COMMIT', :index_column_trigger_on => [:created_at, :updated_at]
519
+ ```
520
+
521
+ And you can even create index on multiple tables by providing SELECT statements which should be used to fetch necessary columns from related tables:
522
+
523
+ ```ruby
524
+ add_context_index :posts,
525
+ [:title, :body,
526
+ # specify aliases always with AS keyword
527
+ "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
528
+ ],
529
+ :name => 'post_and_comments_index',
530
+ :index_column => :all_text,
531
+ :index_column_trigger_on => [:updated_at, :comments_count],
532
+ :sync => 'ON COMMIT'
533
+
534
+ # search in any table columns
535
+ Post.contains(:all_text, 'word')
536
+ # search in specified column
537
+ Post.contains(:all_text, "aaa within title")
538
+ Post.contains(:all_text, "bbb within comment_author")
539
+ ```
540
+
541
+ Please note that `index_column` must be a real column in your database and it's value will be overridden every time your `index_column_trigger_on` columns are changed. So, _do not use columns with real data as `index_column`_.
542
+
543
+ Index column can be created as:
544
+
545
+ ```ruby
546
+ add_column :posts, :all_text, :string, limit: 2, comment: 'Service column for context search index'
547
+ ```
548
+
549
+ ### Oracle virtual columns support
550
+
551
+ Since version R11G1 Oracle database allows adding computed [Virtual Columns](http://www.oracle-base.com/articles/11g/virtual-columns-11gr1.php) to the table.
552
+ They can be used as normal fields in the queries, in the foreign key contstraints and to partitioning data.
553
+
554
+ To define virtual column you can use `virtual` method in the `create_table` block, providing column expression in the `:as` option:
555
+
556
+ ```ruby
557
+ create_table :mytable do |t|
558
+ t.decimal :price, :precision => 15, :scale => 2
559
+ t.decimal :quantity, :precision => 15, :scale => 2
560
+ t.virtual :amount, :as => 'price * quantity'
561
+ end
562
+ ```
563
+
564
+ Oracle tries to predict type of the virtual column, based on its expression but sometimes it is necessary to state type explicitly.
565
+ This can be done by providing `:type` option to the `virtual` method:
566
+
567
+ ```ruby
568
+ # ...
569
+ t.virtual :amount_2, :as => 'ROUND(price * quantity,2)', :type => :decimal, :precision => 15, :scale => 2
570
+ t.virtual :amount_str, :as => "TO_CHAR(quantity) || ' x ' || TO_CHAR(price) || ' USD = ' || TO_CHAR(quantity*price) || ' USD'",
571
+ :type => :string, :limit => 100
572
+ # ...
573
+ ```
574
+
575
+ It is possible to add virtual column to existing table:
576
+
577
+ ```ruby
578
+ add_column :mytable, :amount_4, :virtual, :as => 'ROUND(price * quantity,4)', :precision => 38, :scale => 4
579
+ ```
580
+
581
+ You can use the same options here as in the `create_table` `virtual` method.
582
+
583
+ Changing virtual columns is also possible:
584
+
585
+ ```ruby
586
+ change_column :mytable, :amount, :virtual, :as => 'ROUND(price * quantity,0)', :type => :integer
587
+ ```
588
+
589
+ Virtual columns allowed in the foreign key constraints.
590
+ For example it can be used to force foreign key constraint on polymorphic association:
591
+
592
+ ```ruby
593
+ create_table :comments do |t|
594
+ t.string :subject_type
595
+ t.integer :subject_id
596
+ t.virtual :subject_photo_id, :as => "CASE subject_type WHEN 'Photo' THEN subject_id END"
597
+ t.virtual :subject_event_id, :as => "CASE subject_type WHEN 'Event' THEN subject_id END"
598
+ end
599
+
600
+ add_foreign_key :comments, :photos, :column => :subject_photo_id
601
+ add_foreign_key :comments, :events, :column => :subject_event_id
602
+ ```
603
+
604
+ For backward compatibility reasons it is possible to use `:default` option in the `create_table` instead of `:as` option.
605
+ But this is deprecated and may be removed in the future version.
606
+
607
+ ### Oracle specific schema statements and data types
608
+
609
+ There are several additional schema statements and data types available that you can use in database migrations:
610
+
611
+ * `add_foreign_key` and `remove_foreign_key` for foreign key definition (and they are also dumped in `db/schema.rb`)
612
+ * `add_synonym` and `remove_synonym` for synonym definition (and they are also dumped in `db/schema.rb`)
613
+ * You can create table with primary key trigger using `:primary_key_trigger => true` option for `create_table`
614
+ * You can define columns with `raw` type which maps to Oracle's `RAW` type
615
+ * You can add table and column comments with `:comment` option
616
+ * Default tablespaces can be specified for tables, indexes, clobs and blobs, for example:
617
+
618
+ ```ruby
619
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces =
620
+ {:clob => 'TS_LOB', :blob => 'TS_LOB', :index => 'TS_INDEX', :table => 'TS_DATA'}
621
+ ```
622
+
623
+ ### Switching to another schema
624
+
625
+ There are some requirements to connect to Oracle database first and switch to another user.
626
+ Oracle enhanced adapter supports schema: option.
627
+
628
+ Note: Oracle enhanced adapter does not take care if the database user specified in username: parameter
629
+ has appropriate privilege to select, insert, update and delete database objects owned by the schema specified in schema: parameter.
630
+
631
+ ```yml
632
+ development:
633
+ adapter: oracle_enhanced
634
+ database: xe
635
+ username: user
636
+ password: secret
637
+ schema: tableowner
638
+ ```
639
+
640
+ ### Timeouts
641
+
642
+ By default, OCI libraries set a connect timeout of 60 seconds (as of v12.0), and do not set a data receive timeout.
643
+
644
+ While this may desirable if you process queries that take several minutes to complete, it may also lead to resource exhaustion if
645
+ connections are teared down improperly during a query, e.g. by misbehaving networking equipment that does not inform both peers of
646
+ connection reset. In this scenario, the OCI libraries will wait indefinitely for data to arrive, thus blocking indefinitely the application
647
+ that initiated the query.
648
+
649
+ You can set a connect timeout, in seconds, using the following TNSNAMES parameters:
650
+
651
+ * `CONNECT_TIMEOUT`
652
+ * `TCP_CONNECT_TIMEOUT`
653
+
654
+ Example setting a 5 seconds connect timeout:
655
+
656
+ ```yml
657
+ development:
658
+ database: "(DESCRIPTION=
659
+ (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
660
+ (CONNECT_TIMEOUT=5)(TCP_CONNECT_TIMEOUT=5)
661
+ (CONNECT_DATA=(SERVICE_NAME=xe))
662
+ )"
663
+ ```
664
+ You should set a timeout value dependant on your network topology, and the time needed to establish a TCP connection with your ORACLE
665
+ server. In real-world scenarios, a value larger than 5 should be avoided.
666
+
667
+ You can set receive and send timeouts, in seconds, using the following TNSNAMES parameters:
668
+
669
+ * `RECV_TIMEOUT` - the maximum time the OCI libraries should wait for data to arrive on the TCP socket. Internally, it is implemented
670
+ through a `setsockopt(s, SOL_SOCKET, SO_RCVTIMEO)`. You should set this value to an integer larger than the server-side execution time
671
+ of your longest-running query.
672
+ * `SEND_TIMEOUT` the maximum time the OCI libraries should wait for write operations to complete on the TCP socket. Internally, it is
673
+ implemented through a `setsockopt(s, SOL_SOCKET, SO_SNDTIMEO)`. Values larger than 5 are a sign of poorly performing network, and as
674
+ such it should be avoided.
675
+
676
+ Example setting a 60 seconds receive timeout and 5 seconds send timeout:
677
+
678
+ ```yml
679
+ development:
680
+ database: "(DESCRIPTION=
681
+ (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
682
+ (RECV_TIMEOUT=60)(SEND_TIMEOUT=5)
683
+ (CONNECT_DATA=(SERVICE_NAME=xe))
684
+ )"
685
+ ```
686
+
687
+ Example setting the above send/recv timeout plus a 5 seconds connect timeout:
688
+
689
+ ```yml
690
+ development:
691
+ database: "(DESCRIPTION=
692
+ (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
693
+ (CONNECT_TIMEOUT=5)(TCP_CONNECT_TIMEOUT=5)
694
+ (RECV_TIMEOUT=60)(SEND_TIMEOUT=5)
695
+ (CONNECT_DATA=(SERVICE_NAME=xe))
696
+ )"
697
+ ```
698
+
699
+ ### Schema cache
700
+
701
+ `rails db:schema:cache:dump` generates `db/schema_cache.yml` to avoid queries for Oracle database dictionary, which could help your application response time if it takes time to look up database structure.
702
+
703
+ if any database structure changed by migrations, execute `rails db:schema:cache:dump` again and restart Rails server to reflect changes.
704
+
705
+ UPGRADE
706
+ ---------------
707
+ ### Upgrade Rails 5.1 or older version to Rails 5.2
708
+
709
+ * `emulate_booleans_from_strings = true` change
710
+
711
+ `VARCHAR2(1)` sql type is not registered as `Type:Boolean` even if `emulate_booleans_from_strings = true`
712
+
713
+ Configure each model attribute as follows:
714
+
715
+ ```ruby
716
+ class Post < ActiveRecord::Base
717
+ attribute :is_default, :boolean
718
+ end
719
+ ```
720
+
721
+ * Remove `OracleEnhancedAdapter.cache_columns` to use Rails `db:schema:cache:dump`
722
+
723
+ Refer https://github.com/rsim/oracle-enhanced#schema-cache
724
+
725
+ ### Upgrade Rails 5.0 or older version to Rails 5.1
726
+
727
+ If your application gets `ORA-01000: maximum open cursors exceeded`
728
+ after upgrading to Rails 5.1,
729
+ check these two values and configure `open_cursors` parameter value
730
+ at Oracle database instance is larger than `:statement_limit` value at database.yml.
731
+
732
+ * `open_cursors` value at Oracle database instance
733
+
734
+ ```sql
735
+ SQL> select name,value from v$parameter where name = 'open_cursors';
736
+
737
+ NAME
738
+ --------------------------------------------------------------------------------
739
+ VALUE
740
+ --------------------------------------------------------------------------------
741
+ open_cursors
742
+ 1200
743
+
744
+ ```
745
+
746
+ * `:statement_limit` value at database.yml
747
+
748
+ Since Oracle enhanced adapter 1.8.0 this default value changed from 250 to 1000.
749
+
750
+ ### Upgrade Rails 4.2 or older version to Rails 5
751
+
752
+ If your Oracle table columns have been created for Rails `:datetime` attributes in Rails 4.2 or earlier,
753
+ they need to migrate to `:datetime` in Rails 5 using one of two following ways:
754
+
755
+ * Rails migration code example:
756
+ ```ruby
757
+ change_column :posts, :created_at, :datetime
758
+ change_column :posts, :updated_at, :datetime
759
+ ```
760
+
761
+ or
762
+
763
+ * SQL statement example
764
+ ```sql
765
+ ALTER TABLE "POSTS" MODIFY "CREATED_AT" TIMESTAMP
766
+ ALTER TABLE "POSTS" MODIFY "UPDATED_AT" TIMESTAMP
767
+ ```
768
+
769
+ In Rails 5 without running this migration or sql statement,
770
+ these attributes will be handled as Rails `:date` type.
771
+
772
+ TROUBLESHOOTING
773
+ ---------------
774
+
775
+ ### What to do if Oracle enhanced adapter is not working?
776
+
777
+ Please verify that
778
+
779
+ 1. Oracle Instant Client is installed correctly
780
+ Can you connect to database using sqlnet?
781
+
782
+ 2. ruby-oci8 is installed correctly
783
+ Try something like:
784
+
785
+ ruby -rubygems -e "require 'oci8'; OCI8.new('username','password','database').exec('select * from dual') do |r| puts r.join(','); end"
786
+
787
+ to verify that ruby-oci8 is working
788
+
789
+ 3. Verify that activerecord-oracle_enhanced-adapter is working from irb
790
+
791
+ ```ruby
792
+ require 'rubygems'
793
+ gem 'activerecord'
794
+ gem 'activerecord-oracle_enhanced-adapter'
795
+ require 'active_record'
796
+ ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "database",:username => "user",:password => "password")
797
+ ```
798
+
799
+ and see if it is successful (use your correct database, username and password)
800
+
801
+ ### What to do if Oracle enhanced adapter is not working with Phusion Passenger?
802
+
803
+ Oracle Instant Client and ruby-oci8 requires that several environment variables are set:
804
+
805
+ * `LD_LIBRARY_PATH` (on Linux) or `DYLD_LIBRARY_PATH` (on Mac) should point to Oracle Instant Client directory (where Oracle client shared libraries are located)
806
+ * `TNS_ADMIN` should point to directory where `tnsnames.ora` file is located
807
+ * `NLS_LANG` should specify which territory and language NLS settings to use and which character set to use (e.g. `"AMERICAN_AMERICA.UTF8"`)
808
+
809
+ If this continues to throw "OCI Library Initialization Error (OCIError)", you might also need
810
+
811
+ * `ORACLE_HOME` set to full Oracle client installation directory
812
+
813
+ When Apache with Phusion Passenger (mod_passenger or previously mod_rails) is used for Rails application deployment then by default Ruby is launched without environment variables that you have set in shell profile scripts (e.g. .profile). Therefore it is necessary to set environment variables in one of the following ways:
814
+
815
+ * Create wrapper script as described in [Phusion blog](http://blog.phusion.nl/2008/12/16/passing-environment-variables-to-ruby-from-phusion-passenger) or [RayApps::Blog](http://blog.rayapps.com/2008/05/21/using-mod_rails-with-rails-applications-on-oracle)
816
+ * Set environment variables in the file which is used by Apache before launching Apache worker processes - on Linux it typically is envvars file (look in apachectl or apache2ctl script where it is looking for envvars file) or /System/Library/LaunchDaemons/org.apache.httpd.plist on Mac OS X. See the following [discussion thread](http://groups.google.com/group/oracle-enhanced/browse_thread/thread/c5f64106569fadd0) for more hints.
817
+
818
+ ### What to do if my application is stuck?
819
+
820
+ If you see established TCP connections that do not exchange data, and you are unable to terminate your application using a TERM or an INT
821
+ signal, and you are forced to use the KILL signal, then the OCI libraries may be waiting indefinitely for a network read operation to
822
+ complete.
823
+
824
+ See the **Timeouts** section above.
825
+
826
+ RUNNING TESTS
827
+ -------------
828
+
829
+ See [RUNNING_TESTS.md](https://github.com/rsim/oracle-enhanced/blob/master/RUNNING_TESTS.md) for information how to set up environment and run Oracle enhanced adapter unit tests.
830
+
831
+ LINKS
832
+ -----
833
+
834
+ * Source code: http://github.com/rsim/oracle-enhanced
835
+ * Bug reports / Feature requests / Pull requests: http://github.com/rsim/oracle-enhanced/issues
836
+ * Discuss at Oracle enhanced adapter group: http://groups.google.com/group/oracle-enhanced
837
+ * Blog posts about Oracle enhanced adapter can be found at http://blog.rayapps.com/category/oracle_enhanced
838
+
839
+ LICENSE
840
+ -------
841
+
842
+ (The MIT License)
843
+
844
+ Copyright (c) 2008-2011 Graham Jenkins, Michael Schoen, Raimonds Simanovskis
845
+
846
+ Permission is hereby granted, free of charge, to any person obtaining
847
+ a copy of this software and associated documentation files (the
848
+ 'Software'), to deal in the Software without restriction, including
849
+ without limitation the rights to use, copy, modify, merge, publish,
850
+ distribute, sublicense, and/or sell copies of the Software, and to
851
+ permit persons to whom the Software is furnished to do so, subject to
852
+ the following conditions:
853
+
854
+ The above copyright notice and this permission notice shall be
855
+ included in all copies or substantial portions of the Software.
856
+
857
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
858
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
859
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
860
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
861
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
862
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
863
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.