activerecord-oracle_enhanced-adapter 1.5.6 → 1.6.0.beta1

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