pmacs-activerecord-oracle_enhanced-adapter 1.5.6.1 → 1.6.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -7
  3. data/History.md +126 -0
  4. data/README.md +285 -178
  5. data/Rakefile +1 -1
  6. data/VERSION +1 -1
  7. data/lib/active_record/connection_adapters/{oracle_enhanced_column.rb → oracle_enhanced/column.rb} +14 -63
  8. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +65 -0
  9. data/lib/active_record/connection_adapters/{oracle_enhanced_connection.rb → oracle_enhanced/connection.rb} +2 -2
  10. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +347 -0
  11. data/lib/active_record/connection_adapters/{oracle_enhanced_cpk.rb → oracle_enhanced/cpk.rb} +0 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +257 -0
  13. data/lib/active_record/connection_adapters/{oracle_enhanced_database_tasks.rb → oracle_enhanced/database_tasks.rb} +0 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +40 -0
  15. data/lib/active_record/connection_adapters/{oracle_enhanced_jdbc_connection.rb → oracle_enhanced/jdbc_connection.rb} +0 -0
  16. data/lib/active_record/connection_adapters/{oracle_enhanced_oci_connection.rb → oracle_enhanced/oci_connection.rb} +0 -0
  17. data/lib/active_record/connection_adapters/{oracle_enhanced_procedures.rb → oracle_enhanced/procedures.rb} +1 -3
  18. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_creation.rb → oracle_enhanced/schema_creation.rb} +34 -35
  19. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +95 -0
  20. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_dumper.rb → oracle_enhanced/schema_dumper.rb} +4 -32
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +548 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +74 -0
  23. data/lib/active_record/connection_adapters/{oracle_enhanced_structure_dump.rb → oracle_enhanced/structure_dump.rb} +28 -6
  24. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +161 -68
  26. data/lib/active_record/oracle_enhanced/type/integer.rb +13 -0
  27. data/lib/active_record/oracle_enhanced/type/raw.rb +13 -0
  28. data/lib/active_record/oracle_enhanced/type/timestamp.rb +11 -0
  29. data/lib/pmacs-activerecord-oracle_enhanced-adapter.rb +1 -1
  30. data/pmacs-activerecord-oracle_enhanced-adapter.gemspec +35 -31
  31. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +6 -31
  32. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +1 -1
  33. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +2 -2
  34. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +2 -2
  35. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +75 -63
  36. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +1 -1
  37. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +7 -13
  38. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +2 -1
  39. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +25 -178
  40. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +60 -5
  41. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +1 -0
  42. data/spec/spec_helper.rb +21 -10
  43. metadata +32 -28
  44. data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +0 -77
  45. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -350
  46. data/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb +0 -262
  47. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -45
  48. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -223
  49. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -450
  50. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -267
  51. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfd9dfc216e8abfe2b49a29ca26b706c96c25b4c
4
- data.tar.gz: ae40965f3d27b5bcd55759c008eedb1de94c6734
3
+ metadata.gz: 01c14e8e159cf76f8d90d3830b8fabe19b323ae6
4
+ data.tar.gz: 2b6b32a79a1201ad303d04d2d17c061da174b67b
5
5
  SHA512:
6
- metadata.gz: bc8d709b07ced146b51b9ece9f2b0207403c4f3dd5159c063c87bac3ff572a08e0e893450a8742108aaffa63ff69d2850b325f753ea3628a9b198da63f63494c
7
- data.tar.gz: 6d047603b5a70ae34e37ecc414746c2a083dc63688499fea2428f67be854b544baaeac096283bdc836cdd8857db60d8d0666d078fe779a8f0384898d92952cc5
6
+ metadata.gz: a77984b9feac67daabb128df9b4b1e61bebdd7571e5a8452937ad578afa33ad75e901009fc41921f4ac1c1cd805db10de9af82c8785f6473825d80b655293a9d
7
+ data.tar.gz: 58ac4a4d386b0423e925f9447d72b3f28013ff1a09ac0eedd3ca59c42dc013cac95e5515837c9b863e092781ad53cad4d31e66f2c5c4d517125bd360ba8cb4cb
data/Gemfile CHANGED
@@ -1,17 +1,17 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  group :development do
4
- gem 'jeweler', '~> 1.8'
4
+ gem 'jeweler', '~> 2.0'
5
5
  gem 'rspec', '~> 2.4'
6
6
  gem 'rdoc'
7
7
 
8
- gem 'activerecord', github: 'rails/rails'
9
- gem 'activemodel', github: 'rails/rails'
10
- gem 'activesupport', github: 'rails/rails'
11
- gem 'actionpack', github: 'rails/rails'
12
- gem 'railties', github: 'rails/rails'
8
+ gem 'activerecord', github: 'rails/rails', branch: '4-2-stable'
9
+ gem 'activemodel', github: 'rails/rails', branch: '4-2-stable'
10
+ gem 'activesupport', github: 'rails/rails', branch: '4-2-stable'
11
+ gem 'actionpack', github: 'rails/rails', branch: '4-2-stable'
12
+ gem 'railties', github: 'rails/rails', branch: '4-2-stable'
13
13
 
14
- gem 'arel', github: 'rails/arel'
14
+ gem 'arel', github: 'rails/arel', branch: '6-0-stable'
15
15
  gem 'journey', github: 'rails/journey'
16
16
 
17
17
  gem 'activerecord-deprecated_finders'
data/History.md CHANGED
@@ -1,3 +1,129 @@
1
+ ## 1.6.2 / 2015-07-20
2
+
3
+ * Changes and bug fixes since 1.6.1
4
+
5
+ * Oracle enhanced adapter v1.6 requires ActiveRecord 4.2.1 or higher,
6
+ ActiveRecord 4.2.0 is not supported.[#672]
7
+ * Unique constraints not created when function unique index created [#662, #663]
8
+ * create_table should use default tablespace values for lobs [#668]
9
+
10
+ ## 1.6.1 / 2015-07-01
11
+
12
+ * Changes and bug fixes since 1.6.0
13
+
14
+ * Oracle enhanced adapter v1.6 requires ActiveRecord 4.2.1 or higher,
15
+ ActiveRecord 4.2.0 is not supported.[#651, #652]
16
+ * Fix serialized value becomes from yaml to string once saved [#655, #657]
17
+ * Update Ruby version in readme [#654]
18
+ * Update unit test matcher to skip sql statements to get `table` metadata [#653]
19
+
20
+ ## 1.6.0 / 2015-06-25
21
+
22
+ * Changes and bug fixes since 1.6.0.beta1
23
+
24
+ * Add deprecation warnings for Oracle enhanced specific foreign key methods [#631]
25
+ * Skip composite foreign key tests not supported in this version [#632]
26
+ * Do not dump default foreign key name [#633]
27
+ * Schema dump uses `:on_delete` option instead of `:dependent` [#634]
28
+ * Use Rails foreign key name in rspec unit tests [#635]
29
+ * Add deprecate warning if foreign key name length is longer than 30 byte [#636]
30
+ * Foreign key name longer than 30 byte will be shortened using Digest::SHA1.hexdigest [#637]
31
+ * Schema dumper for :integer will not dump :precision 0 [#638]
32
+ * Update foreign key names for add_foreign_key with table_name_prefix [#643]
33
+
34
+ * Known Issues since 1.6.0.beta1
35
+ * table_name_prefix and table_name_suffix changes column names which cause ORA-00904 [#639]
36
+ * custom methods should rollback record when exception is raised in after_create callback fails [#640]
37
+ * custom methods for create, update and destroy should log create record fails [#641]
38
+
39
+ ## 1.6.0.beta 1 / 2015-06-19
40
+
41
+ * Enhancements
42
+ * Support Rails 4.2
43
+ * Support Rails native foreign key syntax [#488, #618]
44
+
45
+ * Other changes and bug fixes
46
+ * Column#primary method removed from Rails [#483]
47
+ * ActiveRecord::Migrator.proper_table_name has been removed from Rails [#481]
48
+ * New db/schema.rb files will be created with force: :cascade [#593]
49
+ * Rails42 add unique index creates unique constraint [#617]
50
+ * Modify remove_column to add cascade constraint to avoid ORA-12991 [#617]
51
+ * Add `null: true` to avoid DEPRECATION WARNING [#489, #499]
52
+ * Rails 4.2 Add `connection.supports_views?` [#496]
53
+ * text? has been removed from Column class [#487]
54
+ * Remove call to deprecated `serialized_attributes` [#550, #552]
55
+ * Support :cascade option for drop_table [#579]
56
+ * Raise a better exception for renaming long indexes [#577]
57
+ * Override aliased_types [#575]
58
+ * Revert "Add options_include_default!" [#586]
59
+ * Remove substitute_at method from Oracle enhanced adapter [#520]
60
+ * Require 'active_record/base' in rake task #526
61
+ * Make it easier to spot which version of active record is actually used [#550]
62
+ * Rails4.2 Add Type::Raw type [#503]
63
+ * Support :bigint datatype [#580]
64
+ * Map :bigint as NUMBER(19) sql_type not NUMBER(8) [#608]
65
+ * Use Oracle BINARY_FLOAT datatype for Rails :float type [#610]
66
+ * Revert "Implement possibility of handling of NUMBER columns as :float" [#576]
67
+ * Rails 4.2 Support NCHAR correctly [#490]
68
+ * Support :timestamp datatype in Rails 4.2 [#575]
69
+ * Rails 4.2 Handle NUMBER sql_type as `Type::Integer` cast type [#509]
70
+ * ActiveRecord::OracleEnhanced::Type::Integer for max_value to take 38 digits [#605]
71
+ * Rails 4.2 add `module OracleEnhanced` and migrate classes/modules under this [#584]
72
+ * Migrate to ActiveRecord::ConnectionAdapters::OracleEnhanced::ColumnDumper [#597]
73
+ * Migrated from OracleEnhancedContextIndex to OracleEnhanced::ContextIndex [#599]
74
+ * Make OracleEnhancedIndexDefinition as subclass of IndexDefinition [#600]
75
+ * Refactor add_index and add_index_options [#601]
76
+ * Types namespace moved to `ActiveRecord::Type::Value` [#484]
77
+ * Add new_column method [#482]
78
+ * Rename type_cast to type_cast_from_database [#485]
79
+ * Removed `forced_column_type` by using `cast_type` [#595]
80
+ * Move dump_schema_information to SchemaStatements [#611]
81
+ * Move OracleEnhancedIndexDefinition to OracleEnhanced::IndexDefinition [#614]
82
+ * Move OracleEnhancedSynonymDefinition to OracleEnhanced::SynonymDefinition [#615]
83
+ * Move types under OracleEnhanced module [#603]
84
+ * Make OracleEnhancedForeignKeyDefinition as subclass of ForeignKeyDefinition [#581]
85
+ * Support _field_changed argument changes [#479]
86
+ * Rails 4.2 Don't type cast the default on the column [#504]
87
+ * Rename variable names in create_table to follow Rails implementation [#616]
88
+ * Rails 4.2: Fix create_savepoint and rollback_to_savepoint name [#497]
89
+ * Shorten foreign key name if it is longer than 30 byte [#621]
90
+ * Restore foreign_key_definition [#624]
91
+ * Rails 4.2 Support OracleEnhancedAdapter.emulate_integers_by_column_name [#491]
92
+ * Rails 4.2 Support OracleEnhancedAdapter.emulate_dates_by_column_name [#492]
93
+ * Rails 4.2 Support emulate_booleans_from_strings and is_boolean_column? [#506]
94
+ * Rails 4.2 Support OracleEnhancedAdapter.number_datatype_coercion [#512]
95
+ * Rails 4.2 Use register_class_with_limit [#502]
96
+ * Rails 4.2 Remove redundant substitute index when constructing bind values [#517]
97
+ * Rails 4.2 Unit test updated to support `substitute_at` in Arel [#522]
98
+ * Change log method signiture to support Rails 4.2 [#539]
99
+ * Enable loading spec configuration from config file instead of env [#550]
100
+ * Rails42: Issue with non-existent columns [#545, #551]
101
+ * Squelch warning "#column_for_attribute` will return a null object
102
+ for non-existent columns in Rails 5. Use `#has_attribute?`" [#551]
103
+ * Use arel 6-0-stable [#565]
104
+ * Support 'Y' as true and 'N' as false in Rails 4.2 [#574, #573]
105
+ * Remove alias_method_chain :references, :foreign_keys [#582]
106
+ * Use quote_value method to avoid undefined method `type_cast_for_database' for nil:NilClass [#486]
107
+ * Rails 4.2: Set @nchar and @object_type only when sql_type is true [#493]
108
+ * Rails 4.2: Handle forced_column_type temporary [#498]
109
+ * Rails 4.2 Address ArgumentError: wrong number of arguments (1 for 2) at `quote_value` [#511]
110
+ * Address ORA-00932: inconsistent datatypes: expected NUMBER got DATE [#538]
111
+ * Remove duplicate alias_method_chain for indexes [#560]
112
+ * Address RangeError: 6000000000 is out of range for ActiveRecord::Type::Integer
113
+ with limit 4 [#578]
114
+ * Return foreign_keys_without_oracle_enhanced when non Oracle database used [#583]
115
+ * Add missing database_tasks.rb to gemspec [#585]
116
+ * Fixed typo in the rake tasks load statement [#587]
117
+ * Call super when column typs is serialized [#563, #591]
118
+ * Clear query cache on rollback [#592]
119
+ * Modify default to `false` if database default value is "N" [#596]
120
+ * refer correct location if filess in gemspec [#606]
121
+ * Add integer.rb to gemspec [#607]
122
+
123
+ * Known Issues
124
+ * Override aliased_types [#575]
125
+ * Multi column foreign key is not supported
126
+
1
127
  ## 1.5.6 / 2015-03-30
2
128
 
3
129
  * Enhancements
data/README.md CHANGED
@@ -10,24 +10,40 @@ Oracle enhanced ActiveRecord adapter provides Oracle database access from Ruby o
10
10
 
11
11
  INSTALLATION
12
12
  ------------
13
+ ### Rails 4.2
13
14
 
14
- ### Rails 4
15
+ Oracle enhanced adapter version 1.6 just supports Rails 4.2 and does not support Rails 4.1 or lower version of Rails.
16
+ When using Ruby on Rails version 4.2 then in Gemfile include
15
17
 
16
- Oracle enhanced adapter version 1.5 just supports Rails 4 and does not support Rails 3.2 or lower version of Rails.
18
+ ```ruby
19
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
20
+ ```
17
21
 
18
- When using Ruby on Rails version 4 then in Gemfile include
22
+ 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.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.
19
23
 
20
- gem "activerecord-oracle_enhanced-adapter", "~> 1.5.0"
24
+ ### Rails 4.0 and 4.1
25
+
26
+ 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.
27
+
28
+ When using Ruby on Rails version 4.0 and 4.1 then in Gemfile include
29
+
30
+ ```ruby
31
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.5.0'
32
+ ```
21
33
 
22
34
  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.
23
35
 
24
36
  If you would like to use latest adapter version from github then specify
25
37
 
26
- gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
38
+ ```ruby
39
+ gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
40
+ ```
27
41
 
28
- If you are using CRuby 1.9.3 or 2.0 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:
42
+ 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:
29
43
 
30
- gem 'ruby-oci8', '~> 2.1.0'
44
+ ```ruby
45
+ gem 'ruby-oci8', '~> 2.1.0'
46
+ ```
31
47
 
32
48
  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:
33
49
 
@@ -38,7 +54,9 @@ If you are using JRuby then you need to download latest [Oracle JDBC driver](htt
38
54
 
39
55
  After specifying necessary gems in Gemfile run
40
56
 
41
- bundle install
57
+ ```bash
58
+ bundle install
59
+ ```
42
60
 
43
61
  to install the adapter (or later run `bundle update` to force updating to latest version).
44
62
 
@@ -46,17 +64,23 @@ to install the adapter (or later run `bundle update` to force updating to latest
46
64
 
47
65
  When using Ruby on Rails version 3 then in Gemfile include
48
66
 
49
- gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.0'
67
+ ```ruby
68
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.0'
69
+ ```
50
70
 
51
71
  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.
52
72
 
53
73
  If you would like to use latest adapter version from github then specify
54
74
 
55
- gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
75
+ ```ruby
76
+ gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
77
+ ```
56
78
 
57
79
  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:
58
80
 
59
- gem 'ruby-oci8', '~> 2.1.0'
81
+ ```ruby
82
+ gem 'ruby-oci8', '~> 2.1.0'
83
+ ```
60
84
 
61
85
  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:
62
86
 
@@ -67,7 +91,9 @@ If you are using JRuby then you need to download latest [Oracle JDBC driver](htt
67
91
 
68
92
  After specifying necessary gems in Gemfile run
69
93
 
70
- bundle install
94
+ ```bash
95
+ bundle install
96
+ ```
71
97
 
72
98
  to install the adapter (or later run `bundle update` to force updating to latest version).
73
99
 
@@ -75,12 +101,14 @@ to install the adapter (or later run `bundle update` to force updating to latest
75
101
 
76
102
  If you don't use Bundler in Rails 2 application then you need to specify gems in `config/environment.rb`, e.g.
77
103
 
78
- Rails::Initializer.run do |config|
79
- #...
80
- config.gem 'activerecord-oracle_enhanced-adapter', :lib => "active_record/connection_adapters/oracle_enhanced_adapter"
81
- config.gem 'ruby-oci8'
82
- #...
83
- end
104
+ ```ruby
105
+ Rails::Initializer.run do |config|
106
+ # ...
107
+ config.gem 'activerecord-oracle_enhanced-adapter', :lib => 'active_record/connection_adapters/oracle_enhanced_adapter'
108
+ config.gem 'ruby-oci8'
109
+ # ...
110
+ end
111
+ ```
84
112
 
85
113
  But it is recommended to use Bundler for gem version management also for Rails 2.3 applications (search for instructions in Google).
86
114
 
@@ -88,7 +116,9 @@ But it is recommended to use Bundler for gem version management also for Rails 2
88
116
 
89
117
  If you want to use ActiveRecord and Oracle enhanced adapter without Rails and Bundler then install it just as a gem:
90
118
 
91
- gem install activerecord-oracle_enhanced-adapter
119
+ ```bash
120
+ gem install activerecord-oracle_enhanced-adapter
121
+ ```
92
122
 
93
123
  USAGE
94
124
  -----
@@ -97,52 +127,64 @@ USAGE
97
127
 
98
128
  In Rails application `config/database.yml` use oracle_enhanced as adapter name, e.g.
99
129
 
100
- development:
101
- adapter: oracle_enhanced
102
- database: xe
103
- username: user
104
- password: secret
130
+ ```yml
131
+ development:
132
+ adapter: oracle_enhanced
133
+ database: xe
134
+ username: user
135
+ password: secret
136
+ ```
105
137
 
106
138
  If you're connecting to a service name, indicate the service with a
107
139
  leading slash on the database parameter:
108
140
 
109
- development:
110
- adapter: oracle_enhanced
111
- database: /xe
112
- username: user
113
- password: secret
141
+ ```yml
142
+ development:
143
+ adapter: oracle_enhanced
144
+ database: /xe
145
+ username: user
146
+ password: secret
147
+ ```
114
148
 
115
149
  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:
116
150
 
117
- development:
118
- adapter: oracle_enhanced
119
- host: localhost
120
- port: 1521
121
- database: xe
122
- username: user
123
- password: secret
151
+ ```yml
152
+ development:
153
+ adapter: oracle_enhanced
154
+ host: localhost
155
+ port: 1521
156
+ database: xe
157
+ username: user
158
+ password: secret
159
+ ```
124
160
 
125
161
  or you can use Oracle specific format in `database` parameter:
126
162
 
127
- development:
128
- adapter: oracle_enhanced
129
- database: //localhost:1521/xe
130
- username: user
131
- password: secret
163
+ ```yml
164
+ development:
165
+ adapter: oracle_enhanced
166
+ database: //localhost:1521/xe
167
+ username: user
168
+ password: secret
169
+ ```
132
170
 
133
171
  or you can even use Oracle specific TNS connection description:
134
172
 
135
- development:
136
- adapter: oracle_enhanced
137
- database: "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=xe)))"
138
- username: user
139
- password: secret
173
+ ```yml
174
+ development:
175
+ adapter: oracle_enhanced
176
+ database: "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=xe)))"
177
+ username: user
178
+ password: secret
179
+ ```
140
180
 
141
181
  If you deploy JRuby on Rails application in Java application server that supports JNDI connections then you can specify JNDI connection as well:
142
182
 
143
- development:
144
- adapter: oracle_enhanced
145
- jndi: "jdbc/jndi_connection_name"
183
+ ```yml
184
+ development:
185
+ adapter: oracle_enhanced
186
+ jndi: "jdbc/jndi_connection_name"
187
+ ```
146
188
 
147
189
  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.
148
190
 
@@ -152,22 +194,28 @@ You can find other available database.yml connection parameters in [oracle_enhan
152
194
 
153
195
  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.:
154
196
 
155
- # 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
156
- ENV['TZ'] = 'UTC'
157
-
158
- ActiveSupport.on_load(:active_record) do
159
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
160
- # id columns and columns which end with _id will always be converted to integers
161
- self.emulate_integers_by_column_name = true
162
- # DATE columns which include "date" in name will be converted to Date, otherwise to Time
163
- self.emulate_dates_by_column_name = true
164
- # true and false will be stored as 'Y' and 'N'
165
- self.emulate_booleans_from_strings = true
166
- # start primary key sequences from 1 (and not 10000) and take just one next value in each session
167
- self.default_sequence_start_value = "1 NOCACHE INCREMENT BY 1"
168
- # other settings ...
169
- end
170
- end
197
+ ```ruby
198
+ # 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
199
+ ENV['TZ'] = 'UTC'
200
+
201
+ ActiveSupport.on_load(:active_record) do
202
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
203
+ # id columns and columns which end with _id will always be converted to integers
204
+ self.emulate_integers_by_column_name = true
205
+
206
+ # DATE columns which include "date" in name will be converted to Date, otherwise to Time
207
+ self.emulate_dates_by_column_name = true
208
+
209
+ # true and false will be stored as 'Y' and 'N'
210
+ self.emulate_booleans_from_strings = true
211
+
212
+ # start primary key sequences from 1 (and not 10000) and take just one next value in each session
213
+ self.default_sequence_start_value = "1 NOCACHE INCREMENT BY 1"
214
+
215
+ # other settings ...
216
+ end
217
+ end
218
+ ```
171
219
 
172
220
  In case of Rails 2 application you do not need to use `ActiveSupport.on_load(:active_record) do ... end` around settings code block.
173
221
 
@@ -177,81 +225,108 @@ See other adapter settings in [oracle_enhanced_adapter.rb](http://github.com/rsi
177
225
 
178
226
  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:
179
227
 
180
- class Employee < ActiveRecord::Base
181
- # specify schema and table name
182
- self.table_name = "hr.hr_employees"
183
- # specify primary key name
184
- self.primary_key = "employee_id"
185
- # specify sequence name
186
- self.sequence_name = "hr.hr_employee_s"
187
- # set which DATE columns should be converted to Ruby Date
188
- set_date_columns :hired_on, :birth_date_on
189
- # set which DATE columns should be converted to Ruby Time
190
- set_datetime_columns :last_login_time
191
- # set which VARCHAR2 columns should be converted to true and false
192
- set_boolean_columns :manager, :active
193
- # set which columns should be ignored in ActiveRecord
194
- ignore_table_columns :attribute1, :attribute2
195
- end
228
+ ```ruby
229
+ class Employee < ActiveRecord::Base
230
+ # specify schema and table name
231
+ self.table_name = "hr.hr_employees"
232
+
233
+ # specify primary key name
234
+ self.primary_key = "employee_id"
235
+
236
+ # specify sequence name
237
+ self.sequence_name = "hr.hr_employee_s"
238
+
239
+ # set which DATE columns should be converted to Ruby Date
240
+ set_date_columns :hired_on, :birth_date_on
241
+
242
+ # set which DATE columns should be converted to Ruby Time
243
+ set_datetime_columns :last_login_time
244
+
245
+ # set which VARCHAR2 columns should be converted to true and false
246
+ set_boolean_columns :manager, :active
247
+
248
+ # set which columns should be ignored in ActiveRecord
249
+ ignore_table_columns :attribute1, :attribute2
250
+ end
251
+ ```
196
252
 
197
253
  You can also access remote tables over database link using
198
254
 
199
- self.table_name "hr_employees@db_link"
255
+ ```ruby
256
+ self.table_name "hr_employees@db_link"
257
+ ```
200
258
 
201
259
  Examples for Rails 3.2 and lower version of Rails
202
260
 
203
- class Employee < ActiveRecord::Base
204
- # specify schema and table name
205
- set_table_name "hr.hr_employees"
206
- # specify primary key name
207
- set_primary_key "employee_id"
208
- # specify sequence name
209
- set_sequence_name "hr.hr_employee_s"
210
- # set which DATE columns should be converted to Ruby Date
211
- set_date_columns :hired_on, :birth_date_on
212
- # set which DATE columns should be converted to Ruby Time
213
- set_datetime_columns :last_login_time
214
- # set which VARCHAR2 columns should be converted to true and false
215
- set_boolean_columns :manager, :active
216
- # set which columns should be ignored in ActiveRecord
217
- ignore_table_columns :attribute1, :attribute2
218
- end
261
+ ```ruby
262
+ class Employee < ActiveRecord::Base
263
+ # specify schema and table name
264
+ set_table_name "hr.hr_employees"
265
+
266
+ # specify primary key name
267
+ set_primary_key "employee_id"
268
+
269
+ # specify sequence name
270
+ set_sequence_name "hr.hr_employee_s"
271
+
272
+ # set which DATE columns should be converted to Ruby Date
273
+ set_date_columns :hired_on, :birth_date_on
274
+
275
+ # set which DATE columns should be converted to Ruby Time
276
+ set_datetime_columns :last_login_time
277
+
278
+ # set which VARCHAR2 columns should be converted to true and false
279
+ set_boolean_columns :manager, :active
280
+
281
+ # set which columns should be ignored in ActiveRecord
282
+ ignore_table_columns :attribute1, :attribute2
283
+ end
284
+ ```
219
285
 
220
286
  You can also access remote tables over database link using
221
287
 
222
- set_table_name "hr_employees@db_link"
288
+ ```ruby
289
+ set_table_name "hr_employees@db_link"
290
+ ```
223
291
 
224
292
  ### Custom create, update and delete methods
225
293
 
226
294
  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:
227
295
 
228
- class Employee < ActiveRecord::Base
229
- include ActiveRecord::OracleEnhancedProcedures
230
- # when defining create method then return ID of new record that will be assigned to id attribute of new object
231
- set_create_method do
232
- plsql.employees_pkg.create_employee(
233
- :p_first_name => first_name,
234
- :p_last_name => last_name,
235
- :p_employee_id => nil
236
- )[:p_employee_id]
237
- end
238
- set_update_method do
239
- plsql.employees_pkg.update_employee(
240
- :p_employee_id => id,
241
- :p_first_name => first_name,
242
- :p_last_name => last_name
243
- )
244
- end
245
- set_delete_method do
246
- plsql.employees_pkg.delete_employee(
247
- :p_employee_id => id
248
- )
249
- end
250
- end
296
+ ```ruby
297
+ class Employee < ActiveRecord::Base
298
+ include ActiveRecord::OracleEnhancedProcedures
299
+
300
+ # when defining create method then return ID of new record that will be assigned to id attribute of new object
301
+ set_create_method do
302
+ plsql.employees_pkg.create_employee(
303
+ :p_first_name => first_name,
304
+ :p_last_name => last_name,
305
+ :p_employee_id => nil
306
+ )[:p_employee_id]
307
+ end
308
+
309
+ set_update_method do
310
+ plsql.employees_pkg.update_employee(
311
+ :p_employee_id => id,
312
+ :p_first_name => first_name,
313
+ :p_last_name => last_name
314
+ )
315
+ end
316
+
317
+ set_delete_method do
318
+ plsql.employees_pkg.delete_employee(
319
+ :p_employee_id => id
320
+ )
321
+ end
322
+ end
323
+ ```
251
324
 
252
325
  In addition in `config/initializers/oracle.rb` initializer specify that ruby-plsql should use ActiveRecord database connection:
253
326
 
254
- plsql.activerecord_class = ActiveRecord::Base
327
+ ```ruby
328
+ plsql.activerecord_class = ActiveRecord::Base
329
+ ```
255
330
 
256
331
  ### Oracle CONTEXT index support
257
332
 
@@ -259,60 +334,78 @@ Every edition of Oracle database includes [Oracle Text](http://www.oracle.com/te
259
334
 
260
335
  To create simple single column index create migration with, e.g.
261
336
 
262
- add_context_index :posts, :title
337
+ ```ruby
338
+ add_context_index :posts, :title
339
+ ```
263
340
 
264
341
  and you can remove context index with
265
342
 
266
- remove_context_index :posts, :title
343
+ ```ruby
344
+ remove_context_index :posts, :title
345
+ ```
267
346
 
268
347
  Include in class definition
269
348
 
270
- has_context_index
349
+ ```ruby
350
+ has_context_index
351
+ ```
271
352
 
272
353
  and then you can do full text search with
273
354
 
274
- Post.contains(:title, 'word')
355
+ ```ruby
356
+ Post.contains(:title, 'word')
357
+ ```
275
358
 
276
359
  You can create index on several columns (which will generate additional stored procedure for providing XML document with specified columns to indexer):
277
360
 
278
- add_context_index :posts, [:title, :body]
361
+ ```ruby
362
+ add_context_index :posts, [:title, :body]
363
+ ```
279
364
 
280
365
  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):
281
366
 
282
- Post.contains(:title, 'word')
283
- Post.contains(:title, 'word within title')
284
- Post.contains(:title, 'word within body')
367
+ ```ruby
368
+ Post.contains(:title, 'word')
369
+ Post.contains(:title, 'word within title')
370
+ Post.contains(:title, 'word within body')
371
+ ```
285
372
 
286
373
  See Oracle Text documentation for syntax that you can use in CONTAINS function in SELECT WHERE clause.
287
374
 
288
375
  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):
289
376
 
290
- add_context_index :posts, [:title, :body], :index_column => :all_text, :sync => 'ON COMMIT'
377
+ ```ruby
378
+ add_context_index :posts, [:title, :body], :index_column => :all_text, :sync => 'ON COMMIT'
291
379
 
292
- Post.contains(:all_text, 'word')
380
+ Post.contains(:all_text, 'word')
381
+ ```
293
382
 
294
383
  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.
295
384
 
296
- add_context_index :posts, [:title, :body], :index_column => :all_text,
297
- :sync => 'ON COMMIT', :index_column_trigger_on => [:created_at, :updated_at]
385
+ ```ruby
386
+ add_context_index :posts, [:title, :body], :index_column => :all_text,
387
+ :sync => 'ON COMMIT', :index_column_trigger_on => [:created_at, :updated_at]
388
+ ```
298
389
 
299
390
  And you can even create index on multiple tables by providing SELECT statements which should be used to fetch necessary columns from related tables:
300
391
 
301
- add_context_index :posts,
302
- [:title, :body,
303
- # specify aliases always with AS keyword
304
- "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
305
- ],
306
- :name => 'post_and_comments_index',
307
- :index_column => :all_text,
308
- :index_column_trigger_on => [:updated_at, :comments_count],
309
- :sync => 'ON COMMIT'
310
-
311
- # search in any table columns
312
- Post.contains(:all_text, 'word')
313
- # search in specified column
314
- Post.contains(:all_text, "aaa within title")
315
- Post.contains(:all_text, "bbb within comment_author")
392
+ ```ruby
393
+ add_context_index :posts,
394
+ [:title, :body,
395
+ # specify aliases always with AS keyword
396
+ "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
397
+ ],
398
+ :name => 'post_and_comments_index',
399
+ :index_column => :all_text,
400
+ :index_column_trigger_on => [:updated_at, :comments_count],
401
+ :sync => 'ON COMMIT'
402
+
403
+ # search in any table columns
404
+ Post.contains(:all_text, 'word')
405
+ # search in specified column
406
+ Post.contains(:all_text, "aaa within title")
407
+ Post.contains(:all_text, "bbb within comment_author")
408
+ ```
316
409
 
317
410
  ### Oracle virtual columns support
318
411
 
@@ -321,43 +414,53 @@ They can be used as normal fields in the queries, in the foreign key contstraint
321
414
 
322
415
  To define virtual column you can use `virtual` method in the `create_table` block, providing column expression in the `:as` option:
323
416
 
324
- create_table :mytable do |t|
325
- t.decimal :price, :precision => 15, :scale => 2
326
- t.decimal :quantity, :precision => 15, :scale => 2
327
- t.virtual :amount, :as => 'price * quantity'
328
- end
417
+ ```ruby
418
+ create_table :mytable do |t|
419
+ t.decimal :price, :precision => 15, :scale => 2
420
+ t.decimal :quantity, :precision => 15, :scale => 2
421
+ t.virtual :amount, :as => 'price * quantity'
422
+ end
423
+ ```
329
424
 
330
425
  Oracle tries to predict type of the virtual column, based on its expression but sometimes it is necessary to state type explicitly.
331
426
  This can be done by providing `:type` option to the `virtual` method:
332
427
 
333
- ...
334
- t.virtual :amount_2, :as => 'ROUND(price * quantity,2)', :type => :decimal, :precision => 15, :scale => 2
335
- t.virtual :amount_str, :as => "TO_CHAR(quantity) || ' x ' || TO_CHAR(price) || ' USD = ' || TO_CHAR(quantity*price) || ' USD'",
336
- :type => :string, :limit => 100
337
- ...
428
+ ```ruby
429
+ # ...
430
+ t.virtual :amount_2, :as => 'ROUND(price * quantity,2)', :type => :decimal, :precision => 15, :scale => 2
431
+ t.virtual :amount_str, :as => "TO_CHAR(quantity) || ' x ' || TO_CHAR(price) || ' USD = ' || TO_CHAR(quantity*price) || ' USD'",
432
+ :type => :string, :limit => 100
433
+ # ...
434
+ ```
338
435
 
339
436
  It is possible to add virtual column to existing table:
340
437
 
341
- add_column :mytable, :amount_4, :virtual, :as => 'ROUND(price * quantity,4)', :precision => 38, :scale => 4
438
+ ```ruby
439
+ add_column :mytable, :amount_4, :virtual, :as => 'ROUND(price * quantity,4)', :precision => 38, :scale => 4
440
+ ```
342
441
 
343
442
  You can use the same options here as in the `create_table` `virtual` method.
344
443
 
345
444
  Changing virtual columns is also possible:
346
445
 
347
- change_column :mytable, :amount, :virtual, :as => 'ROUND(price * quantity,0)', :type => :integer
446
+ ```ruby
447
+ change_column :mytable, :amount, :virtual, :as => 'ROUND(price * quantity,0)', :type => :integer
448
+ ```
348
449
 
349
450
  Virtual columns allowed in the foreign key constraints.
350
451
  For example it can be used to force foreign key constraint on polymorphic association:
351
452
 
352
- create_table :comments do |t|
353
- t.string :subject_type
354
- t.integer :subject_id
355
- t.virtual :subject_photo_id, :as => "CASE subject_type WHEN 'Photo' THEN subject_id END"
356
- t.virtual :subject_event_id, :as => "CASE subject_type WHEN 'Event' THEN subject_id END"
357
- end
453
+ ```ruby
454
+ create_table :comments do |t|
455
+ t.string :subject_type
456
+ t.integer :subject_id
457
+ t.virtual :subject_photo_id, :as => "CASE subject_type WHEN 'Photo' THEN subject_id END"
458
+ t.virtual :subject_event_id, :as => "CASE subject_type WHEN 'Event' THEN subject_id END"
459
+ end
358
460
 
359
- add_foreign_key :comments, :photos, :column => :subject_photo_id
360
- add_foreign_key :comments, :events, :column => :subject_event_id
461
+ add_foreign_key :comments, :photos, :column => :subject_photo_id
462
+ add_foreign_key :comments, :events, :column => :subject_event_id
463
+ ```
361
464
 
362
465
  For backward compatibility reasons it is possible to use `:default` option in the `create_table` instead of `:as` option.
363
466
  But this is deprecated and may be removed in the future version.
@@ -373,8 +476,10 @@ There are several additional schema statements and data types available that you
373
476
  * You can add table and column comments with `:comment` option
374
477
  * Default tablespaces can be specified for tables, indexes, clobs and blobs, for example:
375
478
 
376
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces =
377
- {:clob => 'TS_LOB', :blob => 'TS_LOB', :index => 'TS_INDEX', :table => 'TS_DATA'}
479
+ ```ruby
480
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces =
481
+ {:clob => 'TS_LOB', :blob => 'TS_LOB', :index => 'TS_INDEX', :table => 'TS_DATA'}
482
+ ```
378
483
 
379
484
  TROUBLESHOOTING
380
485
  ---------------
@@ -395,13 +500,15 @@ Please verify that
395
500
 
396
501
  3. Verify that activerecord-oracle_enhanced-adapter is working from irb
397
502
 
398
- require 'rubygems'
399
- gem 'activerecord'
400
- gem 'activerecord-oracle_enhanced-adapter'
401
- require 'active_record'
402
- ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "database",:username => "user",:password => "password")
503
+ ```ruby
504
+ require 'rubygems'
505
+ gem 'activerecord'
506
+ gem 'activerecord-oracle_enhanced-adapter'
507
+ require 'active_record'
508
+ ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "database",:username => "user",:password => "password")
509
+ ```
403
510
 
404
- and see if it is successful (use your correct database, username and password)
511
+ and see if it is successful (use your correct database, username and password)
405
512
 
406
513
  ### What to do if Oracle enhanced adapter is not working with Phusion Passenger?
407
514