activerecord-jdbc-alt-adapter 52.5.1-java → 60.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.nvimlog +0 -0
  4. data/.travis.yml +61 -37
  5. data/Gemfile +10 -3
  6. data/README.md +44 -28
  7. data/Rakefile +1 -1
  8. data/Rakefile.jdbc +8 -1
  9. data/activerecord-jdbc-adapter.gemspec +5 -8
  10. data/activerecord-jdbc-alt-adapter.gemspec +5 -8
  11. data/lib/arel/visitors/sqlserver.rb +33 -23
  12. data/lib/arjdbc/abstract/connection_management.rb +7 -0
  13. data/lib/arjdbc/abstract/core.rb +16 -23
  14. data/lib/arjdbc/abstract/database_statements.rb +24 -0
  15. data/lib/arjdbc/abstract/statement_cache.rb +2 -5
  16. data/lib/arjdbc/abstract/transaction_support.rb +5 -3
  17. data/lib/arjdbc/db2/column.rb +0 -39
  18. data/lib/arjdbc/derby/adapter.rb +1 -20
  19. data/lib/arjdbc/firebird/adapter.rb +0 -21
  20. data/lib/arjdbc/h2/adapter.rb +0 -15
  21. data/lib/arjdbc/hsqldb/adapter.rb +0 -14
  22. data/lib/arjdbc/informix/adapter.rb +0 -23
  23. data/lib/arjdbc/jdbc/adapter.rb +3 -1
  24. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  25. data/lib/arjdbc/jdbc/adapter_require.rb +3 -1
  26. data/lib/arjdbc/jdbc/base_ext.rb +3 -1
  27. data/lib/arjdbc/jdbc/callbacks.rb +2 -0
  28. data/lib/arjdbc/jdbc/column.rb +2 -0
  29. data/lib/arjdbc/jdbc/connection.rb +2 -0
  30. data/lib/arjdbc/jdbc/connection_methods.rb +2 -0
  31. data/lib/arjdbc/jdbc/error.rb +2 -0
  32. data/lib/arjdbc/jdbc/extension.rb +2 -0
  33. data/lib/arjdbc/jdbc/java.rb +3 -1
  34. data/lib/arjdbc/jdbc/railtie.rb +3 -1
  35. data/lib/arjdbc/jdbc/rake_tasks.rb +3 -1
  36. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -1
  37. data/lib/arjdbc/jdbc/type_cast.rb +2 -0
  38. data/lib/arjdbc/jdbc/type_converter.rb +2 -0
  39. data/lib/arjdbc/mssql/adapter.rb +105 -36
  40. data/lib/arjdbc/mssql/column.rb +5 -1
  41. data/lib/arjdbc/mssql/connection_methods.rb +8 -2
  42. data/lib/arjdbc/mssql/database_limits.rb +2 -0
  43. data/lib/arjdbc/mssql/database_statements.rb +43 -5
  44. data/lib/arjdbc/mssql/errors.rb +2 -0
  45. data/lib/arjdbc/mssql/explain_support.rb +3 -1
  46. data/lib/arjdbc/mssql/extensions/attribute_methods.rb +5 -1
  47. data/lib/arjdbc/mssql/extensions/calculations.rb +2 -0
  48. data/lib/arjdbc/mssql/quoting.rb +38 -0
  49. data/lib/arjdbc/mssql/schema_creation.rb +24 -2
  50. data/lib/arjdbc/mssql/schema_definitions.rb +10 -0
  51. data/lib/arjdbc/mssql/schema_dumper.rb +2 -0
  52. data/lib/arjdbc/mssql/schema_statements.rb +63 -21
  53. data/lib/arjdbc/mssql/transaction.rb +2 -0
  54. data/lib/arjdbc/mssql/types/binary_types.rb +2 -0
  55. data/lib/arjdbc/mssql/types/date_and_time_types.rb +2 -0
  56. data/lib/arjdbc/mssql/types/deprecated_types.rb +2 -0
  57. data/lib/arjdbc/mssql/types/numeric_types.rb +2 -0
  58. data/lib/arjdbc/mssql/types/string_types.rb +2 -0
  59. data/lib/arjdbc/mssql/types.rb +2 -0
  60. data/lib/arjdbc/mssql/utils.rb +2 -0
  61. data/lib/arjdbc/mssql.rb +3 -1
  62. data/lib/arjdbc/mysql/adapter.rb +47 -18
  63. data/lib/arjdbc/postgresql/adapter.rb +240 -214
  64. data/lib/arjdbc/postgresql/base/array_decoder.rb +2 -0
  65. data/lib/arjdbc/postgresql/base/array_encoder.rb +4 -2
  66. data/lib/arjdbc/postgresql/base/array_parser.rb +4 -2
  67. data/lib/arjdbc/postgresql/base/pgconn.rb +2 -0
  68. data/lib/arjdbc/postgresql/column.rb +6 -4
  69. data/lib/arjdbc/postgresql/name.rb +2 -0
  70. data/lib/arjdbc/postgresql/oid_types.rb +3 -1
  71. data/lib/arjdbc/sqlite3/adapter.rb +188 -180
  72. data/lib/arjdbc/sqlite3/connection_methods.rb +15 -4
  73. data/lib/arjdbc/tasks/databases.rake +13 -10
  74. data/lib/arjdbc/tasks/mssql_database_tasks.rb +49 -5
  75. data/lib/arjdbc/util/quoted_cache.rb +3 -1
  76. data/lib/arjdbc/util/serialized_attributes.rb +3 -1
  77. data/lib/arjdbc/util/table_copier.rb +3 -1
  78. data/lib/arjdbc/version.rb +1 -1
  79. data/pom.xml +4 -4
  80. data/rakelib/01-tomcat.rake +2 -2
  81. data/src/java/arjdbc/ArJdbcModule.java +5 -5
  82. data/src/java/arjdbc/jdbc/DriverWrapper.java +1 -9
  83. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +406 -629
  84. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +88 -0
  85. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +13 -23
  86. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +56 -30
  87. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +94 -99
  88. data/src/java/arjdbc/util/DateTimeUtils.java +12 -4
  89. metadata +7 -16
@@ -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'.freeze, nil) { @connection.begin }
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'.freeze, nil) { @connection.commit }
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'.freeze, nil) { @connection.rollback }
46
+ log('ROLLBACK TRANSACTION', nil) { @connection.rollback }
45
47
  end
46
48
 
47
49
  ########################## Savepoint Interface ############################
@@ -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
@@ -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
@@ -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
@@ -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'.freeze
99
+ ADAPTER_NAME = 'JDBC'
98
100
 
99
101
  # @return [String] the 'JDBC' adapter name.
100
102
  def adapter_name
Binary file
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
 
3
5
  if defined? ConnectionAdapters::ConnectionSpecification::Resolver # 4.0
@@ -43,4 +45,4 @@ module ActiveRecord
43
45
 
44
46
  end
45
47
 
46
- end
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  class << Base
3
5
  m = Module.new do
@@ -12,4 +14,4 @@ module ActiveRecord
12
14
 
13
15
  self.prepend(m)
14
16
  end
15
- end
17
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord::ConnectionAdapters
2
4
  module Jdbc
3
5
  # ActiveRecord connection pool callbacks for JDBC.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  module Jdbc
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  # JDBC (connection) base class, custom adapters we support likely extend
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  ConnectionMethods = ::ActiveRecord::ConnectionHandling
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  # Represents exceptions that have propagated up through the JDBC API.
3
5
  class JDBCError < WrappedDatabaseException
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
 
3
5
  # Defines an AR-JDBC extension. An extension consists of a declaration using
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'java'
2
4
  require 'arjdbc/jdbc/adapter_java'
3
5
 
@@ -10,4 +12,4 @@ module ActiveRecord
10
12
  Types = ::Java::JavaSql::Types
11
13
  end
12
14
  end
13
- end
15
+ end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'arjdbc/railtie'
2
- ArJdbc.deprecate "require 'arjdbc/railtie' instead of 'arjdbc/jdbc/railtie'"
4
+ ArJdbc.deprecate "require 'arjdbc/railtie' instead of 'arjdbc/jdbc/railtie'"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  load 'arjdbc/tasks.rb'
2
4
 
3
- ArJdbc.deprecate "load 'arjdbc/tasks.rb' instead of 'arjdbc/jdbc/rake_tasks.rb'"
5
+ ArJdbc.deprecate "load 'arjdbc/tasks.rb' instead of 'arjdbc/jdbc/rake_tasks.rb'"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'arjdbc/util/serialized_attributes'
2
4
 
3
- ArJdbc.deprecate "require 'arjdbc/util/serialized_attributes' instead of 'arjdbc/jdbc/serialized_attributes_helper'"
5
+ ArJdbc.deprecate "require 'arjdbc/util/serialized_attributes' instead of 'arjdbc/jdbc/serialized_attributes_helper'"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record/connection_adapters/column'
2
4
 
3
5
  module ActiveRecord::ConnectionAdapters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  # I want to use JDBC's DatabaseMetaData#getTypeInfo to choose the best native types to
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  ArJdbc.load_java_part :MSSQL
4
4
 
@@ -68,8 +68,19 @@ module ActiveRecord
68
68
  # configure_connection happens in super
69
69
  super(connection, logger, config)
70
70
 
71
- unless mssql_major_version >= 11
72
- raise "Your MSSQL #{mssql_version_year} is too old. This adapter supports MSSQL >= 2012."
71
+ if database_version < '11'
72
+ raise "Your #{mssql_product_name} #{mssql_version_year} is too old. This adapter supports #{mssql_product_name} >= 2012."
73
+ end
74
+ end
75
+
76
+ def self.database_exists?(config)
77
+ !!ActiveRecord::Base.sqlserver_connection(config)
78
+ rescue ActiveRecord::JDBCError => e
79
+ case e.message
80
+ when /Cannot open database .* requested by the login/
81
+ false
82
+ else
83
+ raise
73
84
  end
74
85
  end
75
86
 
@@ -101,6 +112,14 @@ module ActiveRecord
101
112
  true
102
113
  end
103
114
 
115
+ def supports_savepoints?
116
+ true
117
+ end
118
+
119
+ def supports_lazy_transactions?
120
+ true
121
+ end
122
+
104
123
  # The MSSQL datetime type doe have precision.
105
124
  def supports_datetime_with_precision?
106
125
  true
@@ -121,12 +140,23 @@ module ActiveRecord
121
140
  true
122
141
  end
123
142
 
143
+ def supports_insert_on_conflict?
144
+ false
145
+ end
146
+ alias supports_insert_on_duplicate_skip? supports_insert_on_conflict?
147
+ alias supports_insert_on_duplicate_update? supports_insert_on_conflict?
148
+ alias supports_insert_conflict_target? supports_insert_on_conflict?
149
+
150
+ def build_insert_sql(insert) # :nodoc:
151
+ # TODO: hope we can implement an upsert like feature
152
+ "INSERT #{insert.into} #{insert.values_list}"
153
+ end
154
+
124
155
  # Overrides abstract method which always returns false
125
156
  def valid_type?(type)
126
157
  !native_database_types[type].nil?
127
158
  end
128
159
 
129
- # FIXME: to be reviewed.
130
160
  def clear_cache!
131
161
  reload_type_map
132
162
  super
@@ -170,22 +200,6 @@ module ActiveRecord
170
200
  result
171
201
  end
172
202
 
173
- def arel_visitor # :nodoc:
174
- ::Arel::Visitors::SQLServer.new(self)
175
- end
176
-
177
- def schema_creation # :nodoc:
178
- MSSQL::SchemaCreation.new(self)
179
- end
180
-
181
- def create_table_definition(*args) # :nodoc:
182
- MSSQL::TableDefinition.new(*args)
183
- end
184
-
185
- def update_table_definition(table_name, base) #:nodoc:
186
- MSSQL::Table.new(table_name, base)
187
- end
188
-
189
203
  # Returns the name of the current security context
190
204
  def current_user
191
205
  @current_user ||= select_value('SELECT CURRENT_USER')
@@ -208,15 +222,25 @@ module ActiveRecord
208
222
 
209
223
  alias_method :current_schema=, :default_schema=
210
224
 
211
- # Overrides method in abstract adapter
212
- # FIXME: This needs to be fixed the we find a way how to
213
- # get the collation per column basis. At the moment we only use
214
- # the global database collation
215
- def case_sensitive_comparison(table, attribute, column, value)
216
- if [:string, :text].include?(column.type) && collation && !collation.match(/_CS/)
217
- table[attribute].eq(Arel::Nodes::Bin.new(value))
218
- # elsif value.acts_like?(:string)
219
- # table[attribute].eq(Arel::Nodes::Bin.new(Arel::Nodes::BindParam.new))
225
+ # FIXME: This needs to be fixed when we implement the collation per
226
+ # column basis. At the moment we only use the global database collation
227
+ def default_uniqueness_comparison(attribute, value, klass) # :nodoc:
228
+ column = column_for_attribute(attribute)
229
+
230
+ if [:string, :text].include?(column.type) && collation && !collation.match(/_CS/) && !value.nil?
231
+ # NOTE: there is a deprecation warning here in the mysql adapter
232
+ # no sure if it's required.
233
+ attribute.eq(Arel::Nodes::Bin.new(value))
234
+ else
235
+ super
236
+ end
237
+ end
238
+
239
+ def case_sensitive_comparison(attribute, value)
240
+ column = column_for_attribute(attribute)
241
+
242
+ if [:string, :text].include?(column.type) && collation && !collation.match(/_CS/) && !value.nil?
243
+ attribute.eq(Arel::Nodes::Bin.new(value))
220
244
  else
221
245
  super
222
246
  end
@@ -248,6 +272,27 @@ module ActiveRecord
248
272
  MSSQL_VERSION_YEAR[mssql_major_version.to_i]
249
273
  end
250
274
 
275
+ def mssql_product_version
276
+ return @mssql_product_version if defined? @mssql_product_version
277
+
278
+ @mssql_product_version = @connection.database_product_version
279
+ end
280
+
281
+ def mssql_product_name
282
+ return @mssql_product_name if defined? @mssql_product_name
283
+
284
+ @mssql_product_name = @connection.database_product_name
285
+ end
286
+
287
+ def get_database_version # :nodoc:
288
+ MSSQLAdapter::Version.new(mssql_product_version)
289
+ end
290
+
291
+ def check_version # :nodoc:
292
+ # NOTE: hitting the database from here causes trouble when adapter
293
+ # uses JNDI or Data Source setup.
294
+ end
295
+
251
296
  def tables_with_referential_integrity
252
297
  schema_and_tables_sql = %(
253
298
  SELECT s.name, o.name
@@ -266,20 +311,22 @@ module ActiveRecord
266
311
 
267
312
  private
268
313
 
269
- def translate_exception(exception, message)
314
+ def translate_exception(exception, message:, sql:, binds:)
270
315
  case message
271
316
  when /(cannot insert duplicate key .* with unique index) | (violation of unique key constraint)/i
272
- RecordNotUnique.new(message)
317
+ RecordNotUnique.new(message, sql: sql, binds: binds)
273
318
  when /Lock request time out period exceeded/i
274
- LockTimeout.new(message)
319
+ LockTimeout.new(message, sql: sql, binds: binds)
275
320
  when /The .* statement conflicted with the FOREIGN KEY constraint/
276
- ActiveRecord::InvalidForeignKey.new(message)
321
+ InvalidForeignKey.new(message, sql: sql, binds: binds)
322
+ when /The .* statement conflicted with the REFERENCE constraint/
323
+ InvalidForeignKey.new(message, sql: sql, binds: binds)
277
324
  when /(String or binary data would be truncated)/i
278
- ActiveRecord::ValueTooLong.new(message)
325
+ ValueTooLong.new(message, sql: sql, binds: binds)
279
326
  when /Cannot insert the value NULL into column .* does not allow nulls/
280
- ActiveRecord::NotNullViolation.new(message)
327
+ NotNullViolation.new(message, sql: sql, binds: binds)
281
328
  when /Arithmetic overflow error converting expression/
282
- ActiveRecord::RangeError.new(message)
329
+ RangeError.new(message, sql: sql, binds: binds)
283
330
  else
284
331
  super
285
332
  end
@@ -387,6 +434,28 @@ module ActiveRecord
387
434
  map.register_type 'ntext', MSSQL::Type::Ntext.new
388
435
  map.register_type 'image', MSSQL::Type::Image.new
389
436
  end
437
+
438
+ # Returns an array of Column objects for the table specified by +table_name+.
439
+ # See the concrete implementation for details on the expected parameter values.
440
+ # NOTE: This is ready, all implemented in the java part of adapter,
441
+ # it uses MSSQLColumn, SqlTypeMetadata, etc.
442
+ def column_definitions(table_name)
443
+ log('JDBC: GETCOLUMNS', 'SCHEMA') { @connection.columns(table_name) }
444
+ rescue => e
445
+ # raise translate_exception_class(e, nil)
446
+ # FIXME: this breaks one arjdbc test but fixes activerecord tests
447
+ # (table name alias). Also it behaves similarly to the CRuby adapter
448
+ # which returns an empty array too. (postgres throws a exception)
449
+ []
450
+ end
451
+
452
+ def arel_visitor # :nodoc:
453
+ ::Arel::Visitors::SQLServer.new(self)
454
+ end
455
+
456
+ def build_statement_pool
457
+ # NOTE: @statements is set in StatementCache module
458
+ end
390
459
  end
391
460
  end
392
461
  end
@@ -1,11 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  # MSSQL specific extensions to column definitions in a table.
4
6
  class MSSQLColumn < Column
7
+ attr_reader :table_name
5
8
  def initialize(name, raw_default, sql_type_metadata = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment: nil)
9
+ @table_name = table_name
6
10
  default = extract_default(raw_default)
7
11
 
8
- super(name, default, sql_type_metadata, null, table_name, default_function, collation, comment: comment)
12
+ super(name, default, sql_type_metadata, null, default_function, collation: collation, comment: comment)
9
13
  end
10
14
 
11
15
  def extract_default(value)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ArJdbc::ConnectionMethods.module_eval do
2
4
 
3
5
  # Default connection method for MS-SQL adapter (`adapter: mssql`),
@@ -11,6 +13,8 @@ ArJdbc::ConnectionMethods.module_eval do
11
13
  return sqlserver_connection(config)
12
14
  end
13
15
 
16
+ config = config.deep_dup
17
+
14
18
  config[:adapter_spec] ||= ::ArJdbc::MSSQL
15
19
  config[:adapter_class] = ActiveRecord::ConnectionAdapters::MSSQLAdapter unless config.key?(:adapter_class)
16
20
 
@@ -31,7 +35,8 @@ ArJdbc::ConnectionMethods.module_eval do
31
35
  config[:connection_alive_sql] ||= 'SELECT 1'
32
36
 
33
37
  config[:url] ||= begin
34
- url = "jdbc:jtds:sqlserver://#{config[:host]}:#{config[:port]}/#{config[:database]}"
38
+ url = ''.dup
39
+ url << "jdbc:jtds:sqlserver://#{config[:host]}:#{config[:port]}/#{config[:database]}"
35
40
  # Instance is often a preferrable alternative to port when dynamic ports are used.
36
41
  # If instance is specified then port is essentially ignored.
37
42
  url << ";instance=#{config[:instance]}" if config[:instance]
@@ -65,7 +70,8 @@ ArJdbc::ConnectionMethods.module_eval do
65
70
  config[:lock_timeout] ||= 5000
66
71
 
67
72
  config[:url] ||= begin
68
- url = "jdbc:sqlserver://#{config[:host]}"
73
+ url = ''.dup
74
+ url << "jdbc:sqlserver://#{config[:host]}"
69
75
  url << ( config[:port] ? ":#{config[:port]};" : ';' )
70
76
  url << "databaseName=#{config[:database]};" if config[:database]
71
77
  url << "instanceName=#{config[:instance]};" if config[:instance]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  module MSSQL