activerecord-jdbc-alt-adapter 52.5.1-java → 60.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +58 -37
- data/Gemfile +9 -2
- data/README.md +25 -9
- data/Rakefile +1 -1
- data/Rakefile.jdbc +8 -1
- data/activerecord-jdbc-adapter.gemspec +5 -8
- data/activerecord-jdbc-alt-adapter.gemspec +5 -8
- data/lib/arel/visitors/sqlserver.rb +33 -23
- data/lib/arjdbc/abstract/connection_management.rb +7 -0
- data/lib/arjdbc/abstract/core.rb +16 -23
- data/lib/arjdbc/abstract/database_statements.rb +24 -0
- data/lib/arjdbc/abstract/statement_cache.rb +2 -5
- data/lib/arjdbc/abstract/transaction_support.rb +5 -3
- data/lib/arjdbc/db2/column.rb +0 -39
- data/lib/arjdbc/derby/adapter.rb +1 -20
- data/lib/arjdbc/firebird/adapter.rb +0 -21
- data/lib/arjdbc/h2/adapter.rb +0 -15
- data/lib/arjdbc/hsqldb/adapter.rb +0 -14
- data/lib/arjdbc/informix/adapter.rb +0 -23
- data/lib/arjdbc/jdbc/adapter.rb +3 -1
- data/lib/arjdbc/jdbc/adapter_require.rb +3 -1
- data/lib/arjdbc/jdbc/base_ext.rb +3 -1
- data/lib/arjdbc/jdbc/callbacks.rb +2 -0
- data/lib/arjdbc/jdbc/column.rb +2 -0
- data/lib/arjdbc/jdbc/connection.rb +2 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +2 -0
- data/lib/arjdbc/jdbc/error.rb +2 -0
- data/lib/arjdbc/jdbc/extension.rb +2 -0
- data/lib/arjdbc/jdbc/java.rb +3 -1
- data/lib/arjdbc/jdbc/railtie.rb +3 -1
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -1
- data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -1
- data/lib/arjdbc/jdbc/type_cast.rb +2 -0
- data/lib/arjdbc/jdbc/type_converter.rb +2 -0
- data/lib/arjdbc/mssql.rb +3 -1
- data/lib/arjdbc/mssql/adapter.rb +105 -36
- data/lib/arjdbc/mssql/column.rb +5 -1
- data/lib/arjdbc/mssql/connection_methods.rb +8 -2
- data/lib/arjdbc/mssql/database_limits.rb +2 -0
- data/lib/arjdbc/mssql/database_statements.rb +43 -5
- data/lib/arjdbc/mssql/errors.rb +2 -0
- data/lib/arjdbc/mssql/explain_support.rb +3 -1
- data/lib/arjdbc/mssql/extensions/attribute_methods.rb +5 -1
- data/lib/arjdbc/mssql/extensions/calculations.rb +2 -0
- data/lib/arjdbc/mssql/quoting.rb +38 -0
- data/lib/arjdbc/mssql/schema_creation.rb +24 -2
- data/lib/arjdbc/mssql/schema_definitions.rb +10 -0
- data/lib/arjdbc/mssql/schema_dumper.rb +2 -0
- data/lib/arjdbc/mssql/schema_statements.rb +63 -21
- data/lib/arjdbc/mssql/transaction.rb +2 -0
- data/lib/arjdbc/mssql/types.rb +2 -0
- data/lib/arjdbc/mssql/types/binary_types.rb +2 -0
- data/lib/arjdbc/mssql/types/date_and_time_types.rb +2 -0
- data/lib/arjdbc/mssql/types/deprecated_types.rb +2 -0
- data/lib/arjdbc/mssql/types/numeric_types.rb +2 -0
- data/lib/arjdbc/mssql/types/string_types.rb +2 -0
- data/lib/arjdbc/mssql/utils.rb +2 -0
- data/lib/arjdbc/mysql/adapter.rb +47 -18
- data/lib/arjdbc/postgresql/adapter.rb +220 -213
- data/lib/arjdbc/postgresql/base/array_decoder.rb +2 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +4 -2
- data/lib/arjdbc/postgresql/base/array_parser.rb +4 -2
- data/lib/arjdbc/postgresql/base/pgconn.rb +2 -0
- data/lib/arjdbc/postgresql/column.rb +6 -4
- data/lib/arjdbc/postgresql/name.rb +2 -0
- data/lib/arjdbc/postgresql/oid_types.rb +2 -0
- data/lib/arjdbc/sqlite3/adapter.rb +175 -180
- data/lib/arjdbc/sqlite3/connection_methods.rb +15 -4
- data/lib/arjdbc/tasks/databases.rake +13 -10
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +49 -5
- data/lib/arjdbc/util/quoted_cache.rb +3 -1
- data/lib/arjdbc/util/serialized_attributes.rb +3 -1
- data/lib/arjdbc/util/table_copier.rb +3 -1
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +4 -4
- data/src/java/arjdbc/ArJdbcModule.java +5 -5
- data/src/java/arjdbc/jdbc/DriverWrapper.java +1 -9
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +405 -628
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +37 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +13 -23
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +31 -24
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +94 -99
- data/src/java/arjdbc/util/DateTimeUtils.java +12 -4
- metadata +5 -14
data/lib/arjdbc/abstract/core.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ArJdbc
|
2
4
|
module Abstract
|
3
5
|
|
@@ -34,28 +36,26 @@ module ArJdbc
|
|
34
36
|
|
35
37
|
protected
|
36
38
|
|
37
|
-
def translate_exception_class(e, sql)
|
38
|
-
|
39
|
-
message = "#{e.class.name}: #{e.message}: #{sql}"
|
40
|
-
rescue Encoding::CompatibilityError
|
41
|
-
message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql}"
|
42
|
-
end
|
39
|
+
def translate_exception_class(e, sql, binds)
|
40
|
+
message = "#{e.class.name}: #{e.message}"
|
43
41
|
|
44
|
-
exception = translate_exception(
|
45
|
-
|
42
|
+
exception = translate_exception(
|
43
|
+
e, message: message, sql: sql, binds: binds
|
44
|
+
)
|
45
|
+
exception.set_backtrace e.backtrace
|
46
46
|
exception
|
47
47
|
end
|
48
48
|
|
49
|
-
def translate_exception(
|
49
|
+
def translate_exception(exception, message:, sql:, binds:)
|
50
50
|
# override in derived class
|
51
51
|
|
52
52
|
# we shall not translate native "Java" exceptions as they might
|
53
53
|
# swallow an ArJdbc / driver bug into an AR::StatementInvalid !
|
54
|
-
return
|
54
|
+
return exception if exception.is_a?(Java::JavaLang::Throwable)
|
55
55
|
|
56
|
-
case
|
57
|
-
when SystemExit, SignalException, NoMemoryError then
|
58
|
-
when ActiveModel::RangeError, TypeError, RuntimeError then
|
56
|
+
case exception
|
57
|
+
when SystemExit, SignalException, NoMemoryError then exception
|
58
|
+
when ActiveModel::RangeError, TypeError, RuntimeError then exception
|
59
59
|
else super
|
60
60
|
end
|
61
61
|
end
|
@@ -74,13 +74,6 @@ module ArJdbc
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
# Remove this gem from log trace so that query shows where it was called in application
|
81
|
-
def ignored_callstack(path)
|
82
|
-
super || path.start_with?(JDBC_GEM_ROOT)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
ActiveRecord::LogSubscriber.prepend(ArJdbc::LogSubscriber)
|
86
|
-
end
|
77
|
+
JDBC_GEM_ROOT = File.expand_path("../../../..", __FILE__) + "/"
|
78
|
+
ActiveRecord::LogSubscriber.backtrace_cleaner.add_silencer { |line| line.start_with?(JDBC_GEM_ROOT) }
|
79
|
+
end
|
@@ -10,6 +10,12 @@ module ArJdbc
|
|
10
10
|
NO_BINDS = [].freeze
|
11
11
|
|
12
12
|
def exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil)
|
13
|
+
if preventing_writes?
|
14
|
+
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
|
15
|
+
end
|
16
|
+
|
17
|
+
materialize_transactions
|
18
|
+
|
13
19
|
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
14
20
|
|
15
21
|
if without_prepared_statement?(binds)
|
@@ -24,6 +30,12 @@ module ArJdbc
|
|
24
30
|
# It appears that at this point (AR 5.0) "prepare" should only ever be true
|
25
31
|
# if prepared statements are enabled
|
26
32
|
def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false)
|
33
|
+
if preventing_writes? && write_query?(sql)
|
34
|
+
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
|
35
|
+
end
|
36
|
+
|
37
|
+
materialize_transactions
|
38
|
+
|
27
39
|
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
28
40
|
|
29
41
|
if without_prepared_statement?(binds)
|
@@ -38,6 +50,12 @@ module ArJdbc
|
|
38
50
|
end
|
39
51
|
|
40
52
|
def exec_update(sql, name = nil, binds = NO_BINDS)
|
53
|
+
if preventing_writes?
|
54
|
+
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
|
55
|
+
end
|
56
|
+
|
57
|
+
materialize_transactions
|
58
|
+
|
41
59
|
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
42
60
|
|
43
61
|
if without_prepared_statement?(binds)
|
@@ -49,6 +67,12 @@ module ArJdbc
|
|
49
67
|
alias :exec_delete :exec_update
|
50
68
|
|
51
69
|
def execute(sql, name = nil)
|
70
|
+
if preventing_writes? && write_query?(sql)
|
71
|
+
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
|
72
|
+
end
|
73
|
+
|
74
|
+
materialize_transactions
|
75
|
+
|
52
76
|
log(sql, name) { @connection.execute(sql) }
|
53
77
|
end
|
54
78
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_record/connection_adapters/statement_pool'
|
2
4
|
|
3
5
|
module ArJdbc
|
@@ -41,11 +43,6 @@ module ArJdbc
|
|
41
43
|
@statements[sql_key(sql)] ||= @connection.prepare_statement(sql)
|
42
44
|
end
|
43
45
|
|
44
|
-
def supports_statement_cache?
|
45
|
-
ActiveSupport::Deprecation.deprecation_warning(__method__)
|
46
|
-
@jdbc_statement_cache_enabled
|
47
|
-
end
|
48
|
-
|
49
46
|
private
|
50
47
|
|
51
48
|
# This should be overridden by the adapter if the sql itself
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ArJdbc
|
2
4
|
module Abstract
|
3
5
|
|
@@ -22,7 +24,7 @@ module ArJdbc
|
|
22
24
|
# Starts a database transaction.
|
23
25
|
# @override
|
24
26
|
def begin_db_transaction
|
25
|
-
log('BEGIN TRANSACTION'
|
27
|
+
log('BEGIN TRANSACTION', nil) { @connection.begin }
|
26
28
|
end
|
27
29
|
|
28
30
|
# Starts a database transaction.
|
@@ -34,14 +36,14 @@ module ArJdbc
|
|
34
36
|
# Commits the current database transaction.
|
35
37
|
# @override
|
36
38
|
def commit_db_transaction
|
37
|
-
log('COMMIT TRANSACTION'
|
39
|
+
log('COMMIT TRANSACTION', nil) { @connection.commit }
|
38
40
|
end
|
39
41
|
|
40
42
|
# Rolls back the current database transaction.
|
41
43
|
# Called from 'rollback_db_transaction' in the AbstractAdapter
|
42
44
|
# @override
|
43
45
|
def exec_rollback_db_transaction
|
44
|
-
log('ROLLBACK TRANSACTION'
|
46
|
+
log('ROLLBACK TRANSACTION', nil) { @connection.rollback }
|
45
47
|
end
|
46
48
|
|
47
49
|
########################## Savepoint Interface ############################
|
data/lib/arjdbc/db2/column.rb
CHANGED
@@ -80,45 +80,6 @@ module ArJdbc
|
|
80
80
|
|
81
81
|
private
|
82
82
|
|
83
|
-
def simplified_type(field_type)
|
84
|
-
case field_type
|
85
|
-
when /^decimal\(1\)$/i then DB2.emulate_booleans? ? :boolean : :integer
|
86
|
-
when /smallint/i then DB2.emulate_booleans? ? :boolean : :integer
|
87
|
-
when /boolean/i then :boolean
|
88
|
-
when /^real|double/i then :float
|
89
|
-
when /int|serial/i then :integer
|
90
|
-
# if a numeric column has no scale, lets treat it as an integer.
|
91
|
-
# The AS400 rpg guys do this ALOT since they have no integer datatype ...
|
92
|
-
when /decimal|numeric|decfloat/i
|
93
|
-
extract_scale(field_type) == 0 ? :integer : :decimal
|
94
|
-
when /timestamp/i then :timestamp
|
95
|
-
when /datetime/i then :datetime
|
96
|
-
when /time/i then :time
|
97
|
-
when /date/i then :date
|
98
|
-
# DB2 provides three data types to store these data objects as strings of up to 2 GB in size:
|
99
|
-
# Character large objects (CLOBs)
|
100
|
-
# Use the CLOB data type to store SBCS or mixed data, such as documents that contain
|
101
|
-
# single character set. Use this data type if your data is larger (or might grow larger)
|
102
|
-
# than the VARCHAR data type permits.
|
103
|
-
# Double-byte character large objects (DBCLOBs)
|
104
|
-
# Use the DBCLOB data type to store large amounts of DBCS data, such as documents that
|
105
|
-
# use a DBCS character set.
|
106
|
-
# Binary large objects (BLOBs)
|
107
|
-
# Use the BLOB data type to store large amounts of noncharacter data, such as pictures,
|
108
|
-
# voice, and mixed media.
|
109
|
-
when /clob|text/i then :text # handles DBCLOB
|
110
|
-
when /^long varchar/i then :text # :limit => 32700
|
111
|
-
when /blob|binary/i then :binary
|
112
|
-
# varchar () for bit data, char () for bit data, long varchar for bit data
|
113
|
-
when /for bit data/i then :binary
|
114
|
-
when /xml/i then :xml
|
115
|
-
when /graphic/i then :graphic # vargraphic, long vargraphic
|
116
|
-
when /rowid/i then :rowid # rowid is a supported datatype on z/OS and i/5
|
117
|
-
else
|
118
|
-
super
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
83
|
# Post process default value from JDBC into a Rails-friendly format (columns{-internal})
|
123
84
|
def default_value(value)
|
124
85
|
# IBM i (AS400) will return an empty string instead of null for no default
|
data/lib/arjdbc/derby/adapter.rb
CHANGED
@@ -65,25 +65,6 @@ module ArJdbc
|
|
65
65
|
limit
|
66
66
|
end
|
67
67
|
|
68
|
-
def simplified_type(field_type)
|
69
|
-
case field_type
|
70
|
-
when /^smallint/i then Derby.emulate_booleans? ? :boolean : :integer
|
71
|
-
when /^bigint|int/i then :integer
|
72
|
-
when /^real|double/i then :float
|
73
|
-
when /^dec/i then # DEC is a DECIMAL alias
|
74
|
-
extract_scale(field_type) == 0 ? :integer : :decimal
|
75
|
-
when /^timestamp/i then :datetime
|
76
|
-
when /^xml/i then :xml
|
77
|
-
when 'long varchar' then :text
|
78
|
-
when /for bit data/i then :binary
|
79
|
-
# :name=>"long varchar for bit data", :limit=>32700
|
80
|
-
# :name=>"varchar() for bit data", :limit=>32672
|
81
|
-
# :name=>"char() for bit data", :limit=>254}
|
82
|
-
else
|
83
|
-
super
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
68
|
# Post process default value from JDBC into a Rails-friendly format (columns{-internal})
|
88
69
|
def default_value(value)
|
89
70
|
# JDBC returns column default strings with actual single quotes around the value.
|
@@ -420,7 +401,7 @@ module ArJdbc
|
|
420
401
|
|
421
402
|
# @override
|
422
403
|
def supports_ddl_transactions?; true end
|
423
|
-
|
404
|
+
|
424
405
|
# @override
|
425
406
|
def supports_foreign_keys?; true end
|
426
407
|
|
@@ -38,27 +38,6 @@ module ArJdbc
|
|
38
38
|
return $1 unless $1.upcase == 'NULL'
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def simplified_type(field_type)
|
45
|
-
case field_type
|
46
|
-
when /timestamp/i then :datetime
|
47
|
-
when /^smallint/i then :integer
|
48
|
-
when /^bigint|int/i then :integer
|
49
|
-
when /^double/i then :float # double precision
|
50
|
-
when /^decimal/i then
|
51
|
-
extract_scale(field_type) == 0 ? :integer : :decimal
|
52
|
-
when /^char\(1\)$/i then Firebird.emulate_booleans? ? :boolean : :string
|
53
|
-
when /^char/i then :string
|
54
|
-
when /^blob\ssub_type\s(\d)/i
|
55
|
-
return :binary if $1 == '0'
|
56
|
-
return :text if $1 == '1'
|
57
|
-
else
|
58
|
-
super
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
41
|
end
|
63
42
|
|
64
43
|
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
|
data/lib/arjdbc/h2/adapter.rb
CHANGED
@@ -47,21 +47,6 @@ module ArJdbc
|
|
47
47
|
limit
|
48
48
|
end
|
49
49
|
|
50
|
-
def simplified_type(field_type)
|
51
|
-
case field_type
|
52
|
-
when /^bit|bool/i then :boolean
|
53
|
-
when /^signed|year/i then :integer
|
54
|
-
when /^real|double/i then :float
|
55
|
-
when /^varchar/i then :string
|
56
|
-
when /^longvarchar/i then :text
|
57
|
-
when /^binary|raw|bytea/i then :binary
|
58
|
-
when /varbinary/i then :binary # longvarbinary, varbinary
|
59
|
-
when /^blob|image|oid/i then :binary
|
60
|
-
else
|
61
|
-
super
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
50
|
# Post process default value from JDBC into a Rails-friendly format (columns{-internal})
|
66
51
|
def default_value(value)
|
67
52
|
# H2 auto-generated key default value
|
@@ -42,20 +42,6 @@ module ArJdbc
|
|
42
42
|
limit
|
43
43
|
end
|
44
44
|
|
45
|
-
def simplified_type(field_type)
|
46
|
-
case field_type
|
47
|
-
when /^nvarchar/i then :string
|
48
|
-
when /^character/i then :string
|
49
|
-
when /^longvarchar/i then :text
|
50
|
-
when /int/i then :integer # TINYINT, SMALLINT, BIGINT, INT
|
51
|
-
when /real|double/i then :float
|
52
|
-
when /^bit/i then :boolean
|
53
|
-
when /binary/i then :binary # VARBINARY, LONGVARBINARY
|
54
|
-
else
|
55
|
-
super
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
45
|
# Post process default value from JDBC into a Rails-friendly format (columns{-internal})
|
60
46
|
def default_value(value)
|
61
47
|
# JDBC returns column default strings with actual single quotes around the value.
|
@@ -28,11 +28,6 @@ module ArJdbc
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
|
32
|
-
def self.column_selector
|
33
|
-
[ /informix/i, lambda { |cfg, column| column.extend(ColumnMethods) } ]
|
34
|
-
end
|
35
|
-
|
36
31
|
JdbcConnection = ::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
|
37
32
|
|
38
33
|
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
|
@@ -45,20 +40,6 @@ module ArJdbc
|
|
45
40
|
::ActiveRecord::ConnectionAdapters::InformixColumn
|
46
41
|
end
|
47
42
|
|
48
|
-
module ColumnMethods
|
49
|
-
|
50
|
-
private
|
51
|
-
# TODO: Test all Informix column types.
|
52
|
-
def simplified_type(field_type)
|
53
|
-
if field_type =~ /serial/i
|
54
|
-
:primary_key
|
55
|
-
else
|
56
|
-
super
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
43
|
def modify_types(types)
|
63
44
|
super(types)
|
64
45
|
types[:primary_key] = "SERIAL PRIMARY KEY"
|
@@ -152,10 +133,6 @@ module ArJdbc
|
|
152
133
|
end # module ::ArJdbc
|
153
134
|
|
154
135
|
module ActiveRecord::ConnectionAdapters
|
155
|
-
class InformixColumn < JdbcColumn
|
156
|
-
include ::ArJdbc::Informix::ColumnMethods
|
157
|
-
end
|
158
|
-
|
159
136
|
class InformixAdapter < JdbcAdapter
|
160
137
|
include ::ArJdbc::Informix
|
161
138
|
end
|
data/lib/arjdbc/jdbc/adapter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_record/version'
|
2
4
|
require 'active_record/connection_adapters/abstract_adapter'
|
3
5
|
|
@@ -94,7 +96,7 @@ module ActiveRecord
|
|
94
96
|
nil
|
95
97
|
end
|
96
98
|
|
97
|
-
ADAPTER_NAME = 'JDBC'
|
99
|
+
ADAPTER_NAME = 'JDBC'
|
98
100
|
|
99
101
|
# @return [String] the 'JDBC' adapter name.
|
100
102
|
def adapter_name
|
data/lib/arjdbc/jdbc/base_ext.rb
CHANGED
data/lib/arjdbc/jdbc/column.rb
CHANGED
data/lib/arjdbc/jdbc/error.rb
CHANGED