activerecord-jdbc-alt-adapter 70.1.0-java → 71.0.0.alpha1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +135 -21
- data/.github/workflows/ruby.yml +10 -10
- data/.gitignore +1 -0
- data/.solargraph.yml +15 -0
- data/Gemfile +17 -4
- data/README.md +7 -3
- data/RUNNING_TESTS.md +36 -0
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/activerecord-jdbc-alt-adapter.gemspec +1 -1
- data/lib/arel/visitors/sqlserver.rb +10 -0
- data/lib/arjdbc/abstract/connection_management.rb +23 -10
- data/lib/arjdbc/abstract/core.rb +5 -6
- data/lib/arjdbc/abstract/database_statements.rb +35 -25
- data/lib/arjdbc/abstract/statement_cache.rb +1 -6
- data/lib/arjdbc/abstract/transaction_support.rb +37 -9
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/column.rb +0 -34
- data/lib/arjdbc/jdbc/connection_methods.rb +1 -1
- data/lib/arjdbc/mssql/adapter.rb +93 -80
- data/lib/arjdbc/mssql/column.rb +1 -0
- data/lib/arjdbc/mssql/connection_methods.rb +7 -55
- data/lib/arjdbc/mssql/database_statements.rb +182 -71
- data/lib/arjdbc/mssql/explain_support.rb +8 -5
- data/lib/arjdbc/mssql/schema_creation.rb +1 -1
- data/lib/arjdbc/mssql/schema_definitions.rb +10 -0
- data/lib/arjdbc/mssql/schema_statements.rb +19 -11
- data/lib/arjdbc/mssql/server_version.rb +56 -0
- data/lib/arjdbc/mssql/utils.rb +23 -9
- data/lib/arjdbc/mysql/adapter.rb +64 -22
- data/lib/arjdbc/mysql/connection_methods.rb +43 -42
- data/lib/arjdbc/sqlite3/adapter.rb +218 -135
- data/lib/arjdbc/sqlite3/column.rb +103 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +7 -2
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +9 -5
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/02-test.rake +1 -1
- data/rakelib/rails.rake +2 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4 -2
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +2 -1
- metadata +11 -14
- data/lib/arel/visitors/sql_server/ng42.rb +0 -294
- data/lib/arel/visitors/sql_server.rb +0 -124
- data/lib/arjdbc/mssql/limit_helpers.rb +0 -231
- data/lib/arjdbc/mssql/lock_methods.rb +0 -77
- data/lib/arjdbc/mssql/old_adapter.rb +0 -804
- data/lib/arjdbc/mssql/old_column.rb +0 -200
@@ -1,200 +0,0 @@
|
|
1
|
-
module ArJdbc
|
2
|
-
module MSSQL
|
3
|
-
|
4
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
|
5
|
-
def self.column_selector
|
6
|
-
[ /sqlserver|tds|Microsoft SQL/i, lambda { |config, column| column.extend(Column) } ]
|
7
|
-
end
|
8
|
-
|
9
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcColumn
|
10
|
-
module Column
|
11
|
-
|
12
|
-
def self.included(base)
|
13
|
-
# NOTE: assumes a standalone MSSQLColumn class
|
14
|
-
class << base; include Cast; end
|
15
|
-
end
|
16
|
-
|
17
|
-
include LockMethods unless AR42
|
18
|
-
|
19
|
-
# @override
|
20
|
-
def simplified_type(field_type)
|
21
|
-
case field_type
|
22
|
-
when /int|bigint|smallint|tinyint/i then :integer
|
23
|
-
when /numeric/i then (@scale.nil? || @scale == 0) ? :integer : :decimal
|
24
|
-
when /float|double|money|real|smallmoney/i then :decimal
|
25
|
-
when /datetime|smalldatetime/i then :datetime
|
26
|
-
when /timestamp/i then :timestamp
|
27
|
-
when /time/i then :time
|
28
|
-
when /date/i then :date
|
29
|
-
when /text|ntext|xml/i then :text
|
30
|
-
when /binary|image|varbinary/i then :binary
|
31
|
-
when /char|nchar|nvarchar|string|varchar/i then (@limit == 1073741823 ? (@limit = nil; :text) : :string)
|
32
|
-
when /bit/i then :boolean
|
33
|
-
when /uniqueidentifier/i then :string
|
34
|
-
else
|
35
|
-
super
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# @override
|
40
|
-
def default_value(value)
|
41
|
-
return $1 if value =~ /^\(N?'(.*)'\)$/ || value =~ /^\(\(?(.*?)\)?\)$/
|
42
|
-
value
|
43
|
-
end
|
44
|
-
|
45
|
-
# @override
|
46
|
-
def type_cast(value)
|
47
|
-
return nil if value.nil?
|
48
|
-
case type
|
49
|
-
when :integer then ( value.is_a?(String) ? unquote(value) : (value || 0) ).to_i
|
50
|
-
when :primary_key then value.respond_to?(:to_i) ? value.to_i : ((value && 1) || 0)
|
51
|
-
when :decimal then self.class.value_to_decimal(unquote(value))
|
52
|
-
when :date then self.class.string_to_date(value)
|
53
|
-
when :datetime then self.class.string_to_time(value)
|
54
|
-
when :timestamp then self.class.string_to_time(value)
|
55
|
-
when :time then self.class.string_to_dummy_time(value)
|
56
|
-
when :boolean then value == true || (value =~ /^t(rue)?$/i) == 0 || unquote(value) == '1'
|
57
|
-
when :binary then unquote(value)
|
58
|
-
else value
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# @override
|
63
|
-
def extract_limit(sql_type)
|
64
|
-
case sql_type
|
65
|
-
when /^smallint/i
|
66
|
-
2
|
67
|
-
when /^int/i
|
68
|
-
4
|
69
|
-
when /^bigint/i
|
70
|
-
8
|
71
|
-
when /\(max\)/, /decimal/, /numeric/
|
72
|
-
nil
|
73
|
-
when /text|ntext|xml|binary|image|varbinary|bit/
|
74
|
-
nil
|
75
|
-
else
|
76
|
-
super
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# #primary replacement that works on 4.2 as well
|
81
|
-
# #columns will set @primary even when on AR 4.2
|
82
|
-
def primary?; @primary end
|
83
|
-
alias_method :is_primary, :primary?
|
84
|
-
|
85
|
-
def identity?
|
86
|
-
!! sql_type.downcase.index('identity')
|
87
|
-
end
|
88
|
-
# @deprecated
|
89
|
-
alias_method :identity, :identity?
|
90
|
-
alias_method :is_identity, :identity?
|
91
|
-
|
92
|
-
# NOTE: these do not handle = equality as expected
|
93
|
-
# see {#repair_special_columns}
|
94
|
-
# (TEXT, NTEXT, and IMAGE data types are deprecated)
|
95
|
-
# @private
|
96
|
-
def special?
|
97
|
-
unless defined? @special # /text|ntext|image|xml/i
|
98
|
-
sql_type = @sql_type.downcase
|
99
|
-
@special = !! ( sql_type.index('text') || sql_type.index('image') || sql_type.index('xml') )
|
100
|
-
end
|
101
|
-
@special
|
102
|
-
end
|
103
|
-
# @deprecated
|
104
|
-
alias_method :special, :special?
|
105
|
-
alias_method :is_special, :special?
|
106
|
-
|
107
|
-
def is_utf8?
|
108
|
-
!!( sql_type =~ /nvarchar|ntext|nchar/i )
|
109
|
-
end
|
110
|
-
|
111
|
-
private
|
112
|
-
|
113
|
-
def unquote(value)
|
114
|
-
value.to_s.sub(/\A\([\(\']?/, "").sub(/[\'\)]?\)\Z/, "")
|
115
|
-
end
|
116
|
-
|
117
|
-
# @deprecated no longer used
|
118
|
-
def cast_to_time(value)
|
119
|
-
return value if value.is_a?(Time)
|
120
|
-
DateTime.parse(value).to_time rescue nil
|
121
|
-
end
|
122
|
-
|
123
|
-
# @deprecated no longer used
|
124
|
-
def cast_to_date(value)
|
125
|
-
return value if value.is_a?(Date)
|
126
|
-
return Date.parse(value) rescue nil
|
127
|
-
end
|
128
|
-
|
129
|
-
# @deprecated no longer used
|
130
|
-
def cast_to_datetime(value)
|
131
|
-
if value.is_a?(Time)
|
132
|
-
if value.year != 0 and value.month != 0 and value.day != 0
|
133
|
-
return value
|
134
|
-
else
|
135
|
-
return Time.mktime(2000, 1, 1, value.hour, value.min, value.sec) rescue nil
|
136
|
-
end
|
137
|
-
end
|
138
|
-
if value.is_a?(DateTime)
|
139
|
-
begin
|
140
|
-
# Attempt to convert back to a Time, but it could fail for dates significantly in the past/future.
|
141
|
-
return Time.mktime(value.year, value.mon, value.day, value.hour, value.min, value.sec)
|
142
|
-
rescue ArgumentError
|
143
|
-
return value
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
return cast_to_time(value) if value.is_a?(Date) or value.is_a?(String) rescue nil
|
148
|
-
|
149
|
-
return value.is_a?(Date) ? value : nil
|
150
|
-
end
|
151
|
-
|
152
|
-
module Cast
|
153
|
-
|
154
|
-
def string_to_date(value)
|
155
|
-
return value unless value.is_a?(String)
|
156
|
-
return nil if value.empty?
|
157
|
-
|
158
|
-
date = fast_string_to_date(value)
|
159
|
-
date ? date : Date.parse(value) rescue nil
|
160
|
-
end
|
161
|
-
|
162
|
-
def string_to_time(value)
|
163
|
-
return value unless value.is_a?(String)
|
164
|
-
return nil if value.empty?
|
165
|
-
|
166
|
-
fast_string_to_time(value) || DateTime.parse(value).to_time rescue nil
|
167
|
-
end
|
168
|
-
|
169
|
-
ISO_TIME = /\A(\d\d)\:(\d\d)\:(\d\d)(\.\d+)?\z/
|
170
|
-
|
171
|
-
def string_to_dummy_time(value)
|
172
|
-
return value unless value.is_a?(String)
|
173
|
-
return nil if value.empty?
|
174
|
-
|
175
|
-
if value =~ ISO_TIME # "12:34:56.1234560"
|
176
|
-
microsec = ($4.to_f * 1_000_000).round.to_i
|
177
|
-
new_time 2000, 1, 1, $1.to_i, $2.to_i, $3.to_i, microsec
|
178
|
-
else
|
179
|
-
super(value)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def string_to_binary(value)
|
184
|
-
# this will only allow the adapter to insert binary data with a length
|
185
|
-
# of 7K or less because of a SQL Server statement length policy ...
|
186
|
-
"0x#{value.unpack("H*")}" # "0x#{value.unpack("H*")[0]}"
|
187
|
-
end
|
188
|
-
|
189
|
-
def binary_to_string(value)
|
190
|
-
if value.respond_to?(:force_encoding) && value.encoding != Encoding::ASCII_8BIT
|
191
|
-
value = value.force_encoding(Encoding::ASCII_8BIT)
|
192
|
-
end
|
193
|
-
value =~ /[^[:xdigit:]]/ ? value : [value].pack('H*')
|
194
|
-
end
|
195
|
-
|
196
|
-
end
|
197
|
-
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|