ctreatma-activerecord-oracle_enhanced-adapter 1.4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.rspec +2 -0
  2. data/Gemfile +51 -0
  3. data/History.md +269 -0
  4. data/License.txt +20 -0
  5. data/README.md +378 -0
  6. data/RUNNING_TESTS.md +45 -0
  7. data/Rakefile +46 -0
  8. data/VERSION +1 -0
  9. data/activerecord-oracle_enhanced-adapter.gemspec +130 -0
  10. data/ctreatma-activerecord-oracle_enhanced-adapter.gemspec +129 -0
  11. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +5 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced.rake +105 -0
  13. data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +41 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +1390 -0
  15. data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +106 -0
  16. data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +136 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +119 -0
  18. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +328 -0
  19. data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +25 -0
  20. data/lib/active_record/connection_adapters/oracle_enhanced_cpk.rb +21 -0
  21. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +39 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +553 -0
  23. data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +492 -0
  24. data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +260 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +213 -0
  26. data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +252 -0
  27. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +373 -0
  28. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +265 -0
  29. data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +290 -0
  30. data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +17 -0
  31. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -0
  32. data/lib/activerecord-oracle_enhanced-adapter.rb +25 -0
  33. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +749 -0
  34. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +310 -0
  35. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +426 -0
  36. data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +19 -0
  37. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +113 -0
  38. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +1330 -0
  39. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +69 -0
  40. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +121 -0
  41. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +25 -0
  42. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +374 -0
  43. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +380 -0
  44. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +1112 -0
  45. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +323 -0
  46. data/spec/spec_helper.rb +185 -0
  47. metadata +287 -0
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --backtrace
data/Gemfile ADDED
@@ -0,0 +1,51 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'jeweler', '~> 1.5.1'
5
+ gem 'rspec', '~> 2.4'
6
+
7
+ if ENV['RAILS_GEM_VERSION']
8
+ gem 'activerecord', "=#{ENV['RAILS_GEM_VERSION']}"
9
+ gem 'actionpack', "=#{ENV['RAILS_GEM_VERSION']}"
10
+ gem 'activesupport', "=#{ENV['RAILS_GEM_VERSION']}"
11
+ case ENV['RAILS_GEM_VERSION']
12
+ when /^2.0/
13
+ gem 'composite_primary_keys', '=0.9.93'
14
+ when /^2.1/
15
+ gem 'composite_primary_keys', '=1.0.8'
16
+ when /^2.2/
17
+ gem 'composite_primary_keys', '=2.2.2'
18
+ when /^2.3.3/
19
+ gem 'composite_primary_keys', '=2.3.2'
20
+ when /^3/
21
+ gem 'railties', "=#{ENV['RAILS_GEM_VERSION']}"
22
+ end
23
+ else
24
+ %w(activerecord activemodel activesupport actionpack railties).each do |gem_name|
25
+ if ENV['RAILS_GEM_PATH']
26
+ gem gem_name, :path => File.join(ENV['RAILS_GEM_PATH'], gem_name)
27
+ else
28
+ gem gem_name, :git => "git://github.com/rails/rails"
29
+ end
30
+ end
31
+
32
+ if ENV['AREL_GEM_PATH']
33
+ gem 'arel', :path => ENV['AREL_GEM_PATH']
34
+ else
35
+ gem 'arel', :git => "git://github.com/rails/arel"
36
+ end
37
+
38
+ if ENV['JOURNEY_GEM_PATH']
39
+ gem 'journey', :path => ENV['JOURNEY_GEM_PATH']
40
+ else
41
+ gem "journey", :git => "git://github.com/rails/journey"
42
+ end
43
+ end
44
+
45
+ gem 'ruby-plsql', '>=0.4.4'
46
+
47
+ platforms :ruby do
48
+ gem 'ruby-oci8', '>=2.0.4'
49
+ end
50
+
51
+ end
data/History.md ADDED
@@ -0,0 +1,269 @@
1
+ ### 1.4.1 / 2011-01-27
2
+
3
+ * Enhancements:
4
+ * Support for Rails 3.2
5
+ * Support for ActiveRecord 3.2 explain plans [#116]
6
+ * Support for ActiveRecord 3.1 statement pool, to avoid `ORA-01000` maximum open cursors exceeded (default `statement_limit` is 250 and can be changed in `database.yml`) [#100]
7
+ * Added error handling for `rename_table` method in migrations [#137]
8
+ * Bug fixes:
9
+ * Store primary key as `nil` in cache at first time for table without primary key [#84]
10
+ * Fixed inserting records with decimal type columns (`ORA-01722` invalid number exceptions) [#130]
11
+ * Check virtual columns only in models that are using `oracle-enhanced` adapter, to avoid problems when using multiple database adapters [#85]
12
+ * Don't drop the user in rake `db:create` and `db:drop` tasks [#103]
13
+ * Don't add `db:create` and `db:drop` when ActiveRecord is not used as the primary datastore [#128]
14
+ * Quote column names in LOB statements to avoid `ORA-00936` errors [#91]
15
+ * Don't add the `RETURNING` clause if using `composite_primary_keys` gem [#132]
16
+ * Added `join_to_update` method that is necessary for ActiveRecord 3.1 to ensure that correct UPDATE statement is generated using `WHERE ... IN` subquery with offset condition
17
+
18
+ ### 1.4.0 / 2011-08-09
19
+
20
+ * Enhancements:
21
+ * Support for Rails 3.1
22
+ * Bind parameter support for exec_insert, exec_update and exec_delete (in ActiveRecord 3.1)
23
+ * Purge recyclebin on rake db:test:purge
24
+ * Support transactional context index
25
+ * Require ojdbc6.jar (on Java 6) or ojdbc5.jar (on Java 5) JDBC drivers
26
+ * Support for RAW data type
27
+ * rake db:create and db:drop tasks
28
+ * Support virtual columns (in Oracle 11g) in schema dump
29
+ * It is possible to specify default tablespaces for tables, indexes, CLOBs and BLOBs
30
+ * rename_index migrations method
31
+ * Search for JDBC driver in ./lib directory of Rails application
32
+ * Bug fixes:
33
+ * Fixed context index dump when definition is larger than 4000 bytes
34
+ * Fixed schema dump not to conflict with other database adapters that are used in the same application
35
+ * Allow $ in table name prefix or suffix
36
+
37
+ ### 1.3.2 / 2011-01-05
38
+
39
+ * Enhancements:
40
+ * If no :host or :port is provided then connect with :database name (do not default :host to localhost)
41
+ * Database connection pool support for JRuby on Tomcat and JBoss application servers
42
+ * NLS connection parameters support via environment variables or database.yml
43
+ * Support for Arel 2.0 and latest Rails master branch
44
+ * Support for Rails 3.1 prepared statements (implemented in not yet released Rails master branch version)
45
+ * Eager loading of included association with more than 1000 records (implemented in not yet released Rails master branch version)
46
+ * Bug fixes:
47
+ * Foreign keys are added after table definitions in schema dump to ensure correct order of schema statements
48
+ * Quote NCHAR and NVARCHAR2 type values with N'...'
49
+ * Numeric username and/or password in database.yml will be automatically converted to string
50
+
51
+ ### 1.3.1 / 2010-09-09
52
+
53
+ * Enhancements:
54
+ * Tested with Rails 3.0.0 release
55
+ * Lexer options for context index creation
56
+ * Added Bundler for running adapter specs, added RUNNING_TESTS.rdoc with description how to run specs
57
+ * Connection to database using :host, :port and :database options
58
+ * Improved loading of adapter in Rails 3 using railtie
59
+ * Bug fixes:
60
+ * Fix for custom context index procedure when indexing records with null values
61
+ * Quote table and column names in write_lobs callback
62
+ * Fix for incorrect column SQL types when two models use the same table and AR query cache is enabled
63
+ * Fixes for schema and scructure dump tasks
64
+ * Fix for handling of zero-length strings in BLOB and CLOB columns
65
+ * removed String.mb_chars upcase and downcase methods for Ruby 1.9 as Rails 3.0.0 already includes Unicode aware upcase and downcase methods for Ruby 1.9
66
+ * Fixes for latest ActiveRecord unit tests
67
+
68
+ ### 1.3.0 / 2010-06-21
69
+
70
+ * Enhancements:
71
+ * Rails 3.0.0.beta4 and Rails 2.3.x compatible
72
+ * When used with Rails 3 then works together with Oracle SQL compiler included in Arel gem (http://github.com/rails/arel)
73
+ * Rails 3: Better support for limit and offset (when possible adds just ROWNUM condition in WHERE clause without using subqueries)
74
+ * Table and column names are always quoted and in uppercase to avoid the need for checking Oracle reserved words
75
+ * Full text search index creation (add_context_index and remove_context_index methods in migrations and #contains method in ActiveRecord models)
76
+ * add_index and remove_index give just warnings on wrong index names (new expected behavior in Rails 2.3.8 and 3.0.0)
77
+ * :tablespace and :options options for create_table and add_index
78
+ * Workarounds:
79
+ * Rails 3: set ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = true in initializer file for all environments
80
+ (to avoid too many data dictionary queries from Arel)
81
+ * Rails 2.3: patch several ActiveRecord methods to work correctly with quoted table names in uppercase (see oracle_enhanced_activerecord_patches.rb).
82
+ These patches are already included in Rails 3.0.0.beta4.
83
+ * Bug fixes:
84
+ * Fixes for schema purge (drop correctly materialized views)
85
+ * Fixes for schema dump and structure dump (use correct statement separator)
86
+ * Only use Oracle specific schema dump for Oracle connections
87
+
88
+ ### 1.2.4 / 2010-02-23
89
+
90
+ * Enhancements:
91
+ * rake db:test:purge will drop all schema objects from test schema (including views, synonyms, packages, functions, procedures) -
92
+ they should be always reloaded before tests run if necessary
93
+ * added views, synonyms, packages, functions, procedures, indexes, triggers, types, primary, unique and foreign key constraints to structure dump
94
+ * added :temporary option for create_table to create temporary tables
95
+ * added :tablespace option for add_index
96
+ * support function based indexes in schema dump
97
+ * support JNDI database connections in JRuby
98
+ * check ruby-oci8 minimum version 2.0.3
99
+ * added savepoints support (nested ActiveRecord transactions)
100
+ * Bug fixes:
101
+ * typecast returned BigDecimal integer values to Fixnum or Bignum
102
+ (to avoid issues with _before_type_cast values for id attributes because _before_type_cast is used in form helpers)
103
+ * clear table columns cache after columns definition change in migrations
104
+
105
+ ### 1.2.3 / 2009-12-09
106
+
107
+ * Enhancements
108
+ * support fractional seconds in TIMESTAMP values
109
+ * support for ActiveRecord 2.3.5
110
+ * use ENV['TZ'] to set database session time zone
111
+ (as a result DATE and TIMESTAMP values are retrieved with correct time zone)
112
+ * added cache_columns adapter option
113
+ * added current_user adapter method
114
+ * added set_integer_columns and set_string_columns ActiveRecord model class methods
115
+ * Bug fixes:
116
+ * do not raise exception if ENV['PATH'] is nil
117
+ * do not add change_table behavior for ActiveRecord 2.0 (to avoid exception during loading)
118
+ * move foreign key definitions after definition of all tables in schema.rb
119
+ (to avoid definition of foreign keys before all tables are created)
120
+ * changed timestamp format mask to use ':' before fractional seconds
121
+ (workaround to avoid table detection in tables_in_string method in ActiveRecord associations.rb file)
122
+ * fixed custom create/update/delete methods with ActiveRecord 2.3+ and timestamps
123
+ * do not call oracle_enhanced specific schema dump methods when using other database adapters
124
+
125
+ ### 1.2.2 / 2009-09-28
126
+
127
+ * Enhancements
128
+ * improved RDoc documentation of public methods
129
+ * structure dump optionally (database.yml environment has db_stored_code: yes) extracts
130
+ packages, procedures, functions, views, triggers and synonyms
131
+ * automatically generated too long index names are shortened down to 30 characters
132
+ * create tables with primary key triggers
133
+ * use 'set_sequence_name :autogenerated' for inserting into legacy tables with trigger populated primary keys
134
+ * access to tables over database link (need to define local synonym to remote table and use local synonym in set_table_name)
135
+ * [JRuby] support JDBC connection using TNS_ADMIN environment variable and TNS database alias
136
+ * changed cursor_sharing option default from 'similar' to 'force'
137
+ * optional dbms_output logging to ActiveRecord log file (requires ruby-plsql gem)
138
+ * use add_foreign_key and remove_foreign_key to define foreign key constraints
139
+ (the same syntax as in http://github.com/matthuhiggins/foreigner and similar
140
+ to http://github.com/eyestreet/active_record_oracle_extensions)
141
+ * raise RecordNotUnique and InvalidForeignKey exceptions if caused by corresponding ORA errors
142
+ (these new exceptions are supported just by current ActiveRecord master branch)
143
+ * implemented disable_referential_integrity
144
+ (enables safe loading of fixtures in schema with foreign key constraints)
145
+ * use add_synonym and remove_synonym to define database synonyms
146
+ * add_foreign_key and add_synonym are also exported to schema.rb
147
+ * Bug fixes:
148
+ * [JRuby] do not raise LoadError if ojdbc14.jar cannot be required (rely on application server to add it to class path)
149
+ * [JRuby] 'execute' can be used to create triggers with :NEW reference
150
+ * support create_table without a block
151
+ * support create_table with Symbol table name
152
+ * use ActiveRecord functionality to do time zone conversion
153
+ * rake tasks such as db:test:clone are redefined only if oracle_enhanced is current adapter in use
154
+ * VARCHAR2 and CHAR column sizes are defined in characters and not in bytes (expected behavior from ActiveRecord)
155
+ * set_date_columns, set_datetime_columns, ignore_table_columns will work after reestablishing connection
156
+ * ignore :limit option for :text and :binary columns in migrations
157
+ * patches for ActiveRecord schema dumper to remove table prefixes and suffixes from schema.rb
158
+
159
+ ### 1.2.1 / 2009-06-07
160
+
161
+ * Enhancements
162
+ * caching of table indexes query which makes schema dump much faster
163
+ * Bug fixes:
164
+ * return Date (and not DateTime) values for :date column value before year 1970
165
+ * fixed after_create/update/destroy callbacks with plsql custom methods
166
+ * fixed creation of large integers in JRuby
167
+ * Made test tasks respect RAILS_ENV
168
+ * fixed support for composite primary keys for tables with LOBs
169
+
170
+ ### 1.2.0 / 2009-03-22
171
+
172
+ * Enhancements
173
+ * support for JRuby and JDBC
174
+ * support for Ruby 1.9.1 and ruby-oci8 2.0
175
+ * support for Rails 2.3
176
+ * quoting of Oracle reserved words in table names and column names
177
+ * emulation of OracleAdapter (for ActiveRecord unit tests)
178
+ * Bug fixes:
179
+ * several bug fixes that were identified during running of ActiveRecord unit tests
180
+
181
+ ### 1.1.9 / 2009-01-02
182
+
183
+ * Enhancements
184
+ * Added support for table and column comments in migrations
185
+ * Added support for specifying sequence start values
186
+ * Added :privilege option (e.g. :SYSDBA) to ActiveRecord::Base.establish_connection
187
+ * Bug fixes:
188
+ * Do not mark empty decimals, strings and texts (stored as NULL in database) as changed when reassigning them (starting from Rails 2.1)
189
+ * Create booleans as VARCHAR2(1) columns if emulate_booleans_from_strings is true
190
+
191
+ ### 1.1.8 / 2008-10-10
192
+
193
+ * Bug fixes:
194
+ * Fixed storing of serialized LOB columns
195
+ * Prevent from SQL injection in :limit and :offset
196
+ * Order by LOB columns (by replacing column with function which returns first 100 characters of LOB)
197
+ * Sequence creation for tables with non-default primary key in create_table block
198
+ * Do count distinct workaround only when composite_primary_keys gem is used
199
+ (otherwise count distinct did not work with ActiveRecord 2.1.1)
200
+ * Fixed rake db:test:clone_structure task
201
+ (see http://rsim.lighthouseapp.com/projects/11468/tickets/11-rake-dbtestclone_structure-fails-in-117)
202
+ * Fixed bug when ActiveRecord::Base.allow_concurrency = true
203
+ (see http://dev.rubyonrails.org/ticket/11134)
204
+
205
+ ### 1.1.7 / 2008-08-20
206
+
207
+ * Bug fixes:
208
+ * Fixed that adapter works without ruby-plsql gem (in this case just custom create/update/delete methods are not available)
209
+
210
+ ### 1.1.6 / 2008-08-19
211
+
212
+ * Enhancements:
213
+ * Added support for set_date_columns and set_datetime_columns
214
+ * Added support for set_boolean_columns
215
+ * Added support for schema prefix in set_table_name (removed table name quoting)
216
+ * Added support for NVARCHAR2 column type
217
+ * Bug fixes:
218
+ * Do not call write_lobs callback when custom create or update methods are defined
219
+
220
+ ### 1.1.5 / 2008-07-27
221
+
222
+ * Bug fixes:
223
+ * Fixed that write_lobs callback works with partial_updates enabled (added additional record lock before writing BLOB data to database)
224
+ * Enhancements:
225
+ * Changed SQL SELECT in indexes method so that it will execute faster on some large data dictionaries
226
+ * Support for other date and time formats when assigning string to :date or :datetime column
227
+
228
+ ### 1.1.4 / 2008-07-14
229
+
230
+ * Enhancements:
231
+ * Date/Time quoting changes to support composite_primary_keys
232
+ * Added additional methods that are used by composite_primary_keys
233
+
234
+ ### 1.1.3 / 2008-07-10
235
+
236
+ * Enhancements:
237
+ * Added support for custom create, update and delete methods when working with legacy databases where
238
+ PL/SQL API should be used for create, update and delete operations
239
+
240
+ ### 1.1.2 / 2008-07-08
241
+
242
+ * Bug fixes:
243
+ * Fixed after_save callback addition for session store in ActiveRecord version 2.0.2
244
+ * Changed date column name recognition - now should match regex /(^|_)date(_|$)/i
245
+ (previously "updated_at" was recognized as :date column and not as :datetime)
246
+
247
+ ### 1.1.1 / 2008-06-28
248
+
249
+ * Enhancements:
250
+ * Added ignore_table_columns option
251
+ * Added support for TIMESTAMP columns (without fractional seconds)
252
+ * NLS_DATE_FORMAT and NLS_TIMESTAMP_FORMAT independent DATE and TIMESTAMP columns support
253
+ * Bug fixes:
254
+ * Checks if CGI::Session::ActiveRecordStore::Session does not have enhanced_write_lobs callback before adding it
255
+ (Rails 2.0 does not add this callback, Rails 2.1 does)
256
+
257
+ ### 1.1.0 / 2008-05-05
258
+
259
+ * Forked from original activerecord-oracle-adapter-1.0.0.9216
260
+ * Renamed oracle adapter to oracle_enhanced adapter
261
+ * Added "enhanced" to method and class definitions so that oracle_enhanced and original oracle adapter
262
+ could be used simultaniously
263
+ * Added Rails rake tasks as a copy from original oracle tasks
264
+ * Enhancements:
265
+ * Improved perfomance of schema dump methods when used on large data dictionaries
266
+ * Added LOB writing callback for sessions stored in database
267
+ * Added emulate_dates_by_column_name option
268
+ * Added emulate_integers_by_column_name option
269
+ * Added emulate_booleans_from_strings option
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2011 Graham Jenkins, Michael Schoen, Raimonds Simanovskis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,378 @@
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 2.3.x and 3.x and it is working with Oracle database versions 10g and 11g.
10
+
11
+ INSTALLATION
12
+ ------------
13
+
14
+ ### Rails 3
15
+
16
+ When using Ruby on Rails version 3 then in Gemfile include
17
+
18
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.0'
19
+
20
+ 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.
21
+
22
+ If you would like to use latest adapter version from github then specify
23
+
24
+ gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
25
+
26
+ 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:
27
+
28
+ gem 'ruby-oci8', '~> 2.0.6'
29
+
30
+ 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:
31
+
32
+ * in `./lib` directory of Rails application
33
+ * in some directory which is in `PATH`
34
+ * in `JRUBY_HOME/lib` directory
35
+ * or include path to JDBC driver jar file in Java `CLASSPATH`
36
+
37
+ After specifying necessary gems in Gemfile run
38
+
39
+ bundle install
40
+
41
+ to install the adapter (or later run `bundle update` to force updating to latest version).
42
+
43
+ ### Rails 2.3
44
+
45
+ If you don't use Bundler in Rails 2 application then you need to specify gems in `config/environment.rb`, e.g.
46
+
47
+ Rails::Initializer.run do |config|
48
+ #...
49
+ config.gem 'activerecord-oracle_enhanced-adapter', :lib => "active_record/connection_adapters/oracle_enhanced_adapter"
50
+ config.gem 'ruby-oci8'
51
+ #...
52
+ end
53
+
54
+ But it is recommended to use Bundler for gem version management also for Rails 2.3 applications (search for instructions in Google).
55
+
56
+ ### Without Rails and Bundler
57
+
58
+ If you want to use ActiveRecord and Oracle enhanced adapter without Rails and Bundler then install it just as a gem:
59
+
60
+ gem install activerecord-oracle_enhanced-adapter
61
+
62
+ USAGE
63
+ -----
64
+
65
+ ### Database connection
66
+
67
+ In Rails application `config/database.yml` use oracle_enhanced as adapter name, e.g.
68
+
69
+ development:
70
+ adapter: oracle_enhanced
71
+ database: xe
72
+ username: user
73
+ password: secret
74
+
75
+ 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:
76
+
77
+ development:
78
+ adapter: oracle_enhanced
79
+ host: localhost
80
+ port: 1521
81
+ database: xe
82
+ username: user
83
+ password: secret
84
+
85
+ or you can use Oracle specific format in `database` parameter:
86
+
87
+ development:
88
+ adapter: oracle_enhanced
89
+ database: //localhost:1521/xe
90
+ username: user
91
+ password: secret
92
+
93
+ or you can even use Oracle specific TNS connection description:
94
+
95
+ development:
96
+ adapter: oracle_enhanced
97
+ database: "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=xe)))"
98
+ username: user
99
+ password: secret
100
+
101
+ If you deploy JRuby on Rails application in Java application server that supports JNDI connections then you can specify JNDI connection as well:
102
+
103
+ development:
104
+ adapter: oracle_enhanced
105
+ jndi: "jdbc/jndi_connection_name"
106
+
107
+ You can find other available database.yml connection parameters in [oracle_enhanced_adapter.rb](/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.
108
+
109
+ ### Adapter settings
110
+
111
+ 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.:
112
+
113
+ # 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
114
+ ENV['TZ'] = 'UTC'
115
+
116
+ ActiveSupport.on_load(:active_record) do
117
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
118
+ # id columns and columns which end with _id will always be converted to integers
119
+ self.emulate_integers_by_column_name = true
120
+ # DATE columns which include "date" in name will be converted to Date, otherwise to Time
121
+ self.emulate_dates_by_column_name = true
122
+ # true and false will be stored as 'Y' and 'N'
123
+ self.emulate_booleans_from_strings = true
124
+ # start primary key sequences from 1 (and not 10000) and take just one next value in each session
125
+ self.default_sequence_start_value = "1 NOCACHE INCREMENT BY 1"
126
+ # other settings ...
127
+ end
128
+ end
129
+
130
+ In case of Rails 2 application you do not need to use `ActiveSupport.on_load(:active_record) do ... end` around settings code block.
131
+
132
+ See other adapter settings in [oracle_enhanced_adapter.rb](/rsim/oracle-enhanced/blob/master/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb).
133
+
134
+ ### Legacy schema support
135
+
136
+ 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:
137
+
138
+ class Employee < ActiveRecord::Base
139
+ # specify schema and table name
140
+ set_table_name "hr.hr_employees"
141
+ # specify primary key name
142
+ set_primary_key "employee_id"
143
+ # specify sequence name
144
+ set_sequence_name "hr.hr_employee_s"
145
+ # set which DATE columns should be converted to Ruby Date
146
+ set_date_columns :hired_on, :birth_date_on
147
+ # set which DATE columns should be converted to Ruby Time
148
+ set_datetime_columns :last_login_time
149
+ # set which VARCHAR2 columns should be converted to true and false
150
+ set_boolean_columns :manager, :active
151
+ # set which columns should be ignored in ActiveRecord
152
+ ignore_table_columns :attribute1, :attribute2
153
+ end
154
+
155
+ You can also access remote tables over database link using
156
+
157
+ set_table_name "hr_employees@db_link"
158
+
159
+ ### Custom create, update and delete methods
160
+
161
+ 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 and then define custom create, update and delete methods, see example:
162
+
163
+ class Employee < ActiveRecord::Base
164
+ # when defining create method then return ID of new record that will be assigned to id attribute of new object
165
+ set_create_method do
166
+ plsql.employees_pkg.create_employee(
167
+ :p_first_name => first_name,
168
+ :p_last_name => last_name,
169
+ :p_employee_id => nil
170
+ )[:p_employee_id]
171
+ end
172
+ set_update_method do
173
+ plsql.employees_pkg.update_employee(
174
+ :p_employee_id => id,
175
+ :p_first_name => first_name,
176
+ :p_last_name => last_name
177
+ )
178
+ end
179
+ set_delete_method do
180
+ plsql.employees_pkg.delete_employee(
181
+ :p_employee_id => id
182
+ )
183
+ end
184
+ end
185
+
186
+ In addition in `config/initializers/oracle.rb` initializer specify that ruby-plsql should use ActiveRecord database connection:
187
+
188
+ plsql.activerecord_class = ActiveRecord::Base
189
+
190
+ ### Oracle CONTEXT index support
191
+
192
+ 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.
193
+
194
+ To create simple single column index create migration with, e.g.
195
+
196
+ add_context_index :posts, :title
197
+
198
+ and you can remove context index with
199
+
200
+ remove_context_index :posts, :title
201
+
202
+ Include in class definition
203
+
204
+ has_context_index
205
+
206
+ and then you can do full text search with
207
+
208
+ Post.contains(:title, 'word')
209
+
210
+ You can create index on several columns (which will generate additional stored procedure for providing XML document with specified columns to indexer):
211
+
212
+ add_context_index :posts, [:title, :body]
213
+
214
+ 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):
215
+
216
+ Post.contains(:title, 'word')
217
+ Post.contains(:title, 'word within title')
218
+ Post.contains(:title, 'word within body')
219
+
220
+ See Oracle Text documentation for syntax that you can use in CONTAINS function in SELECT WHERE clause.
221
+
222
+ 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):
223
+
224
+ add_context_index :posts, [:title, :body], :index_column => :all_text, :sync => 'ON COMMIT'
225
+
226
+ Post.contains(:all_text, 'word')
227
+
228
+ 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.
229
+
230
+ add_context_index :posts, [:title, :body], :index_column => :all_text,
231
+ :sync => 'ON COMMIT', :index_column_trigger_on => [:created_at, :updated_at]
232
+
233
+ And you can even create index on multiple tables by providing SELECT statements which should be used to fetch necessary columns from related tables:
234
+
235
+ add_context_index :posts,
236
+ [:title, :body,
237
+ # specify aliases always with AS keyword
238
+ "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
239
+ ],
240
+ :name => 'post_and_comments_index',
241
+ :index_column => :all_text,
242
+ :index_column_trigger_on => [:updated_at, :comments_count],
243
+ :sync => 'ON COMMIT'
244
+
245
+ # search in any table columns
246
+ Post.contains(:all_text, 'word')
247
+ # search in specified column
248
+ Post.contains(:all_text, "aaa within title")
249
+ Post.contains(:all_text, "bbb within comment_author")
250
+
251
+ ### Oracle specific schema statements and data types
252
+
253
+ There are several additional schema statements and data types available that you can use in database migrations:
254
+
255
+ * `add_foreign_key` and `remove_foreign_key` for foreign key definition (and they are also dumped in `db/schema.rb`)
256
+ * `add_synonym` and `remove_synonym` for synonym definition (and they are also dumped in `db/schema.rb`)
257
+ * You can create table with primary key trigger using `:primary_key_trigger => true` option for `create_table`
258
+ * You can define columns with `raw` type which maps to Oracle's `RAW` type
259
+ * You can add table and column comments with `:comment` option
260
+ * On Oracle 11g you can define `virtual` columns with calculation formula in `:default` option
261
+ * Default tablespaces can be specified for tables, indexes, clobs and blobs, for example:
262
+
263
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces =
264
+ {:clob => 'TS_LOB', :blob => 'TS_LOB', :index => 'TS_INDEX', :table => 'TS_DATA'}
265
+
266
+ TROUBLESHOOTING
267
+ ---------------
268
+
269
+ ### What to do if Oracle enhanced adapter is not working?
270
+
271
+ Please verify that
272
+
273
+ 1. Oracle Instant Client is installed correctly
274
+ Can you connect to database using sqlnet?
275
+
276
+ 2. ruby-oci8 is installed correctly
277
+ Try something like:
278
+
279
+ ruby -rubygems -e "require 'oci8'; OCI8.new('username','password','database').exec('select * from dual') do |r| puts r.join(','); end"
280
+
281
+ to verify that ruby-oci8 is working
282
+
283
+ 3. Verify that activerecord-oracle_enhanced-adapter is working from irb
284
+
285
+ require 'rubygems'
286
+ gem 'activerecord'
287
+ gem 'activerecord-oracle_enhanced-adapter'
288
+ require 'activerecord'
289
+ ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "database",:username => "user",:password => "password")
290
+
291
+ and see if it is successful (use your correct database, username and password)
292
+
293
+ ### What to do if Oracle enhanced adapter is not working with Phusion Passenger?
294
+
295
+ Oracle Instant Client and ruby-oci8 requires that several environment variables are set:
296
+
297
+ * `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)
298
+ * `TNS_ADMIN` should point to directory where `tnsnames.ora` file is located
299
+ * `NLS_LANG` should specify which territory and language NLS settings to use and which character set to use (e.g. `"AMERICAN_AMERICA.UTF8"`)
300
+
301
+ If this continues to throw "OCI Library Initialization Error (OCIError)", you might also need
302
+
303
+ * `ORACLE_HOME` set to full Oracle client installation directory
304
+
305
+ 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:
306
+
307
+ * 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)
308
+ * 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.
309
+
310
+ RUNNING TESTS
311
+ -------------
312
+
313
+ See [RUNNING_TESTS.md](/rsim/oracle-enhanced/blob/master/RUNNING_TESTS.md) for information how to set up environment and run Oracle enhanced adapter unit tests.
314
+
315
+ LINKS
316
+ -----
317
+
318
+ * Source code: http://github.com/rsim/oracle-enhanced
319
+ * Bug reports / Feature requests / Pull requests: http://github.com/rsim/oracle-enhanced/issues
320
+ * Discuss at Oracle enhanced adapter group: http://groups.google.com/group/oracle-enhanced
321
+ * Blog posts about Oracle enhanced adapter can be found at http://blog.rayapps.com/category/oracle_enhanced
322
+
323
+ CONTRIBUTORS
324
+ ------------
325
+
326
+ * Raimonds Simanovskis
327
+ * Jorge Dias
328
+ * James Wylder
329
+ * Rob Christie
330
+ * Nate Wieger
331
+ * Edgars Beigarts
332
+ * Lachlan Laycock
333
+ * toddwf
334
+ * Anton Jenkins
335
+ * Dave Smylie
336
+ * Alex Rothenberg
337
+ * Billy Reisinger
338
+ * David Blain
339
+ * Joe Khoobyar
340
+ * Edvard Majakari
341
+ * Beau Fabry
342
+ * Simon Chiang
343
+ * Peter Nyberg
344
+ * Dwayne Litzenberger
345
+ * Aaron Patterson
346
+ * Darcy Schultz
347
+ * Alexi Rahman
348
+ * Joeri Samson
349
+ * Luca Bernardo Ciddio
350
+ * Sam Baskinger
351
+ * Benjamin Ortega
352
+ * Yasuo Honda
353
+
354
+ LICENSE
355
+ -------
356
+
357
+ (The MIT License)
358
+
359
+ Copyright (c) 2008-2011 Graham Jenkins, Michael Schoen, Raimonds Simanovskis
360
+
361
+ Permission is hereby granted, free of charge, to any person obtaining
362
+ a copy of this software and associated documentation files (the
363
+ 'Software'), to deal in the Software without restriction, including
364
+ without limitation the rights to use, copy, modify, merge, publish,
365
+ distribute, sublicense, and/or sell copies of the Software, and to
366
+ permit persons to whom the Software is furnished to do so, subject to
367
+ the following conditions:
368
+
369
+ The above copyright notice and this permission notice shall be
370
+ included in all copies or substantial portions of the Software.
371
+
372
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
373
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
374
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
375
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
376
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
377
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
378
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.