activerecord-oracle_enhanced-adapter-monky_patch_755 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/activerecord/monkey_patch.rb +6 -2
- data/lib/activerecord/monkey_patch/rails5.rb +187 -0
- data/lib/oracle_enhanced/monkey_patch_755/version.rb +1 -1
- metadata +43 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 126a4ca05008abafa013f727d12b1e63d8cc93a1
|
4
|
+
data.tar.gz: 356e802ba546bf6aa21d9d9d26d5464a6010757d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a203db760816d586498789b00a35a94dda46c007073266ee726b239413377c8514cccd2bfa87bc1a838f45707d432505b5f4a6c7a8055d9e6b6661c0f05e62
|
7
|
+
data.tar.gz: 8e143df1032a05f846c2fbbadfa0e93298e71f5d697acd5eab5789ece32f96f0ec93c9042d97ab51b75313961bc71749d4b7e149388db50e8cc9f5ee03c5acc8
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
A monkey patch for oracle-enhanced ISSUE [#755](https://github.com/rsim/oracle-enhanced/issues/755).
|
4
4
|
|
5
|
+
**ISSUE #755 has been resolved at activerecord-oracle_enhanced-adapter 1.7.3.**
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add these lines to your application's Gemfile:
|
@@ -24,7 +26,7 @@ $ gem install activerecord-oracle_enhanced-adapter-monky_patch_755
|
|
24
26
|
|
25
27
|
## Target
|
26
28
|
|
27
|
-
* 'activerecord', '
|
29
|
+
* 'activerecord', '=> 4.2.1'
|
28
30
|
* 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
|
29
31
|
|
30
32
|
## Motivation
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
case Rails::VERSION::MAJOR
|
2
|
+
when 4; require 'activerecord/monkey_patch/rails4'
|
3
|
+
when 5; require 'activerecord/monkey_patch/rails5'
|
4
|
+
end
|
2
5
|
|
3
6
|
#
|
4
7
|
# This code is a monkey patch for oracle-enhanced ISSUE #755.
|
@@ -10,7 +13,8 @@ module ActiveRecord
|
|
10
13
|
def adjust_timezone_offset(opts)
|
11
14
|
if ActiveRecord::Base.connection_config[:adapter] != 'oracle_enhanced' ||
|
12
15
|
ActiveRecord::VERSION::MAJOR != SUPPORTED_MAJOR_VERSION ||
|
13
|
-
ActiveRecord.version < Gem::Version.create(MINIMUM_SUPPORTED_VERSION)
|
16
|
+
ActiveRecord.version < Gem::Version.create(MINIMUM_SUPPORTED_VERSION) ||
|
17
|
+
Gem::Version.create(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::VERSION ) > Gem::Version.create('1.7.3')
|
14
18
|
return opts
|
15
19
|
end
|
16
20
|
|
@@ -0,0 +1,187 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module MonkeyPatch
|
3
|
+
SUPPORTED_MAJOR_VERSION = 5
|
4
|
+
MINIMUM_SUPPORTED_VERSION = '5.0.0'.freeze
|
5
|
+
end
|
6
|
+
|
7
|
+
#
|
8
|
+
# Original code is the following URL.
|
9
|
+
#
|
10
|
+
# https://github.com/rails/rails/blob/v5.0.0.1/activerecord/lib/active_record/internal_metadata.rb#L18
|
11
|
+
#
|
12
|
+
class InternalMetadata < ActiveRecord::Base
|
13
|
+
class << self
|
14
|
+
def []=(key, value)
|
15
|
+
find_or_initialize_by(key: key).update_attributes!(value: value.to_s)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ConnectionAdapters
|
21
|
+
#
|
22
|
+
# Original code is the following URL.
|
23
|
+
#
|
24
|
+
# https://github.com/rsim/oracle-enhanced/blob/rails5/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb#L938
|
25
|
+
#
|
26
|
+
class OracleEnhancedAdapter
|
27
|
+
def columns_without_cache(table_name, name = nil) #:nodoc:
|
28
|
+
table_name = table_name.to_s
|
29
|
+
# get ignored_columns by original table name
|
30
|
+
ignored_columns = ignored_table_columns(table_name)
|
31
|
+
|
32
|
+
(owner, desc_table_name, db_link) = @connection.describe(table_name)
|
33
|
+
|
34
|
+
# reset do_not_prefetch_primary_key cache for this table
|
35
|
+
@@do_not_prefetch_primary_key[table_name] = nil
|
36
|
+
|
37
|
+
table_cols = <<-SQL.strip.gsub(/\s+/, ' ')
|
38
|
+
SELECT cols.column_name AS name, cols.data_type AS sql_type,
|
39
|
+
cols.data_default, cols.nullable, cols.virtual_column, cols.hidden_column,
|
40
|
+
cols.data_type_owner AS sql_type_owner,
|
41
|
+
DECODE(cols.data_type, 'NUMBER', data_precision,
|
42
|
+
'FLOAT', data_precision,
|
43
|
+
'VARCHAR2', DECODE(char_used, 'C', char_length, data_length),
|
44
|
+
'RAW', DECODE(char_used, 'C', char_length, data_length),
|
45
|
+
'CHAR', DECODE(char_used, 'C', char_length, data_length),
|
46
|
+
NULL) AS limit,
|
47
|
+
DECODE(data_type, 'NUMBER', data_scale, NULL) AS scale,
|
48
|
+
comments.comments as column_comment
|
49
|
+
FROM all_tab_cols#{db_link} cols, all_col_comments#{db_link} comments
|
50
|
+
WHERE cols.owner = '#{owner}'
|
51
|
+
AND cols.table_name = '#{desc_table_name}'
|
52
|
+
AND cols.hidden_column = 'NO'
|
53
|
+
AND cols.owner = comments.owner
|
54
|
+
AND cols.table_name = comments.table_name
|
55
|
+
AND cols.column_name = comments.column_name
|
56
|
+
ORDER BY cols.column_id
|
57
|
+
SQL
|
58
|
+
|
59
|
+
# added deletion of ignored columns
|
60
|
+
select_all(table_cols, name).to_a.delete_if do |row|
|
61
|
+
ignored_columns && ignored_columns.include?(row['name'].downcase)
|
62
|
+
end.map do |row|
|
63
|
+
limit, scale = row['limit'], row['scale']
|
64
|
+
if limit || scale
|
65
|
+
row['sql_type'] += "(#{(limit || 38).to_i}" + ((scale = scale.to_i) > 0 ? ",#{scale})" : ")")
|
66
|
+
end
|
67
|
+
|
68
|
+
if row['sql_type_owner']
|
69
|
+
row['sql_type'] = row['sql_type_owner'] + '.' + row['sql_type']
|
70
|
+
end
|
71
|
+
|
72
|
+
is_virtual = row['virtual_column']=='YES'
|
73
|
+
|
74
|
+
# clean up odd default spacing from Oracle
|
75
|
+
if row['data_default'] && !is_virtual
|
76
|
+
row['data_default'].sub!(/^(.*?)\s*$/, '\1')
|
77
|
+
|
78
|
+
# If a default contains a newline these cleanup regexes need to
|
79
|
+
# match newlines.
|
80
|
+
row['data_default'].sub!(/^'(.*)'$/m, '\1')
|
81
|
+
row['data_default'] = nil if row['data_default'] =~ /^(null|empty_[bc]lob\(\))$/i
|
82
|
+
# TODO: Needs better fix to fallback "N" to false
|
83
|
+
row['data_default'] = false if (row['data_default'] == "N" && OracleEnhancedAdapter.emulate_booleans_from_strings)
|
84
|
+
end
|
85
|
+
|
86
|
+
type_metadata = fetch_type_metadata(row['sql_type'])
|
87
|
+
|
88
|
+
# *** Its a monkey patch paragraph. ***
|
89
|
+
if /date/i === type_metadata.sql_type
|
90
|
+
if type_metadata.type == :date
|
91
|
+
type_metadata.instance_eval('@sql_type = "DATETIME"')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
new_column(oracle_downcase(row['name']),
|
96
|
+
row['data_default'],
|
97
|
+
type_metadata,
|
98
|
+
row['nullable'] == 'Y',
|
99
|
+
table_name,
|
100
|
+
is_virtual,
|
101
|
+
false,
|
102
|
+
row['column_comment']
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
module OracleEnhanced
|
109
|
+
#
|
110
|
+
# Original code is the following URL.
|
111
|
+
#
|
112
|
+
# https://github.com/rsim/oracle-enhanced/blob/rails5/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb#L87
|
113
|
+
#
|
114
|
+
module Quoting
|
115
|
+
def quote(value, column = nil) #:nodoc:
|
116
|
+
case value
|
117
|
+
when ::Date, ::Time, ::DateTime # *** Its a monky patch condition. ***
|
118
|
+
if value.acts_like?(:time)
|
119
|
+
zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
|
120
|
+
|
121
|
+
if value.respond_to?(zone_conversion_method)
|
122
|
+
value = value.send(zone_conversion_method)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
"'#{value.to_s(:db)}'"
|
127
|
+
else
|
128
|
+
super
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# Original code is the following URL.
|
137
|
+
#
|
138
|
+
# https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/relation/where_clause_factory.rb#L9
|
139
|
+
#
|
140
|
+
class Relation
|
141
|
+
class WhereClauseFactory
|
142
|
+
|
143
|
+
def build(opts, other)
|
144
|
+
binds = []
|
145
|
+
|
146
|
+
case opts
|
147
|
+
when String, Array
|
148
|
+
parts = [klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
|
149
|
+
when Hash
|
150
|
+
opts = ActiveRecord::MonkeyPatch.adjust_timezone_offset(opts)
|
151
|
+
|
152
|
+
attributes = predicate_builder.resolve_column_aliases(opts)
|
153
|
+
attributes = klass.send(:expand_hash_conditions_for_aggregates, attributes)
|
154
|
+
attributes.stringify_keys!
|
155
|
+
|
156
|
+
attributes, binds = predicate_builder.create_binds(attributes)
|
157
|
+
|
158
|
+
parts = predicate_builder.build_from_hash(attributes)
|
159
|
+
when Arel::Nodes::Node
|
160
|
+
parts = [opts]
|
161
|
+
binds = other
|
162
|
+
else
|
163
|
+
raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
|
164
|
+
end
|
165
|
+
|
166
|
+
WhereClause.new(parts, binds)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# Original code is the following URL.
|
173
|
+
#
|
174
|
+
# https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/statement_cache.rb#L83
|
175
|
+
#
|
176
|
+
class StatementCache # :nodoc:
|
177
|
+
class BindMap # :nodoc:
|
178
|
+
def bind(values)
|
179
|
+
values = ActiveRecord::MonkeyPatch.adjust_timezone_offset(values)
|
180
|
+
|
181
|
+
bas = @bound_attributes.dup
|
182
|
+
@indexes.each_with_index { |offset,i| bas[offset] = bas[offset].with_cast_value(values[i]) }
|
183
|
+
bas
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-oracle_enhanced-adapter-monky_patch_755
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koichi ITO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.2.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.2.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord-oracle_enhanced-adapter
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.6.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.6.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby-oci8
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: railties
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
61
|
version: 4.2.1
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 4.2.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.0
|
55
83
|
description: 'A monkey patch for oracle-enhanced ISSUE #755.'
|
56
84
|
email: koic.ito@gmail.com
|
57
85
|
executables: []
|
@@ -63,6 +91,7 @@ files:
|
|
63
91
|
- lib/activerecord-oracle_enhanced-adapter-monky_patch_755.rb
|
64
92
|
- lib/activerecord/monkey_patch.rb
|
65
93
|
- lib/activerecord/monkey_patch/rails4.rb
|
94
|
+
- lib/activerecord/monkey_patch/rails5.rb
|
66
95
|
- lib/oracle_enhanced/monkey_patch_755/hooks.rb
|
67
96
|
- lib/oracle_enhanced/monkey_patch_755/railtie.rb
|
68
97
|
- lib/oracle_enhanced/monkey_patch_755/version.rb
|
@@ -70,7 +99,10 @@ homepage: http://github.com/koic/oracle-enhanced-monky_patch_755
|
|
70
99
|
licenses:
|
71
100
|
- MIT
|
72
101
|
metadata: {}
|
73
|
-
post_install_message:
|
102
|
+
post_install_message: |
|
103
|
+
[activerecord-oracle_enhanced-adapter-monky_patch_755]
|
104
|
+
oracle-enhanced ISSUE #755 has been fixed at oracle-enhanced 1.7.3.
|
105
|
+
The best way is to use oracle-enhanced 1.7.3 or later. Thanks.
|
74
106
|
rdoc_options: []
|
75
107
|
require_paths:
|
76
108
|
- lib
|
@@ -86,8 +118,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
118
|
version: '0'
|
87
119
|
requirements: []
|
88
120
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.6.8
|
90
122
|
signing_key:
|
91
123
|
specification_version: 4
|
92
124
|
summary: 'A monkey patch for oracle-enhanced ISSUE #755.'
|
93
125
|
test_files: []
|
126
|
+
has_rdoc:
|