Class: ActiveRecord::ConnectionAdapters::TrilogyAdapter
Constant Summary
collapse
- ER_BAD_DB_ERROR =
1049
- ER_DBACCESS_DENIED_ERROR =
1044
- ER_ACCESS_DENIED_ERROR =
1045
- ER_SERVER_SHUTDOWN =
1053
- ADAPTER_NAME =
"Trilogy"
- SSL_MODES =
{
SSL_MODE_DISABLED: ::Trilogy::SSL_DISABLED,
SSL_MODE_PREFERRED: ::Trilogy::SSL_PREFERRED_NOVERIFY,
SSL_MODE_REQUIRED: ::Trilogy::SSL_REQUIRED_NOVERIFY,
SSL_MODE_VERIFY_CA: ::Trilogy::SSL_VERIFY_CA,
SSL_MODE_VERIFY_IDENTITY: ::Trilogy::SSL_VERIFY_IDENTITY
}.freeze
- TYPE_MAP =
Type::TypeMap.new.tap { |m| initialize_type_map(m) }
Class Method Summary
collapse
Instance Method Summary
collapse
#build_explain_clause, #exec_delete, #exec_insert, #exec_query, #execute, #explain, #high_precision_current_timestamp, #internal_exec_query, #select_all, #write_query?
Constructor Details
#initialize(connection, logger, connection_options, config) ⇒ TrilogyAdapter
Returns a new instance of TrilogyAdapter.
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 157
def initialize(connection, logger, connection_options, config)
config = config.dup
config.delete(:host) if config[:socket]
super
@prepared_statements = self.class.type_cast_config_to_boolean(
@config.fetch(:prepared_statements) { default_prepared_statements }
)
end
|
Class Method Details
.dbconsole(config, options = {}) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 111
def dbconsole(config, options = {})
mysql_config = if ActiveRecord.version < ::Gem::Version.new('6.1.a')
config.config
else
config.configuration_hash
end
args = {
host: "--host",
port: "--port",
socket: "--socket",
username: "--user",
encoding: "--default-character-set",
sslca: "--ssl-ca",
sslcert: "--ssl-cert",
sslcapath: "--ssl-capath",
sslcipher: "--ssl-cipher",
sslkey: "--ssl-key",
ssl_mode: "--ssl-mode"
}.filter_map { |opt, arg| "#{arg}=#{mysql_config[opt]}" if mysql_config[opt] }
if mysql_config[:password] && options[:include_password]
args << "--password=#{mysql_config[:password]}"
elsif mysql_config[:password] && !mysql_config[:password].to_s.empty?
args << "-p"
end
args << mysql_config[:database]
find_cmd_and_exec(["mysql", "mysql5"], *args)
end
|
.find_cmd_and_exec(commands, *args) ⇒ Object
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 257
def self.find_cmd_and_exec(commands, *args) commands = Array(commands)
dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR)
unless (ext = RbConfig::CONFIG["EXEEXT"]).empty?
commands = commands.map { |cmd| "#{cmd}#{ext}" }
end
full_path_command = nil
found = commands.detect do |cmd|
dirs_on_path.detect do |path|
full_path_command = File.join(path, cmd)
begin
stat = File.stat(full_path_command)
rescue SystemCallError
else
stat.file? && stat.executable?
end
end
end
if found
exec full_path_command, *args
else
abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
end
end
|
.new_client(config) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 80
def new_client(config)
config[:ssl_mode] = parse_ssl_mode(config[:ssl_mode]) if config[:ssl_mode]
::Trilogy.new(config)
rescue ::Trilogy::Error => error
raise translate_connect_error(config, error)
end
|
.parse_ssl_mode(mode) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 87
def parse_ssl_mode(mode)
return mode if mode.is_a? Integer
m = mode.to_s.upcase
m = "SSL_MODE_#{m}" unless m.start_with? "SSL_MODE_"
SSL_MODES.fetch(m.to_sym, mode)
end
|
.translate_connect_error(config, error) ⇒ Object
Instance Method Details
#active? ⇒ Boolean
227
228
229
230
231
232
233
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 227
def active?
return false if connection&.closed?
connection&.ping || false
rescue ::Trilogy::Error
false
end
|
#connect! ⇒ Object
203
204
205
206
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 203
def connect!
verify!
self
end
|
#connected? ⇒ Boolean
223
224
225
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 223
def connected?
!connection.nil?
end
|
#discard! ⇒ Object
245
246
247
248
249
250
251
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 245
def discard!
super
unless connection.nil?
connection.discard!
self.connection = nil
end
end
|
#disconnect! ⇒ Object
237
238
239
240
241
242
243
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 237
def disconnect!
super
unless connection.nil?
connection.close
self.connection = nil
end
end
|
#error_number(exception) ⇒ Object
253
254
255
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 253
def error_number(exception)
exception.error_code if exception.respond_to?(:error_code)
end
|
#quote_string(string) ⇒ Object
197
198
199
200
201
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 197
def quote_string(string)
with_trilogy_connection(allow_retry: true, materialize_transactions: false) do |conn|
conn.escape(string)
end
end
|
#reconnect! ⇒ Object
Also known as:
reset!
208
209
210
211
212
213
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 208
def reconnect!
@lock.synchronize do
disconnect!
connect
end
end
|
#savepoint_errors_invalidate_transactions? ⇒ Boolean
189
190
191
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 189
def savepoint_errors_invalidate_transactions?
true
end
|
177
178
179
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 177
def
true
end
|
181
182
183
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 181
def
true
end
|
#supports_json? ⇒ Boolean
173
174
175
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 173
def supports_json?
!mariadb? && database_version >= "5.7.8"
end
|
#supports_lazy_transactions? ⇒ Boolean
193
194
195
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 193
def supports_lazy_transactions?
true
end
|
#supports_savepoints? ⇒ Boolean
185
186
187
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 185
def supports_savepoints?
true
end
|
#with_trilogy_connection(materialize_transactions: true, **_kwargs) ⇒ Object
215
216
217
218
219
220
221
|
# File 'lib/active_record/connection_adapters/trilogy_adapter.rb', line 215
def with_trilogy_connection(materialize_transactions: true, **_kwargs)
@lock.synchronize do
verify!
self.materialize_transactions if materialize_transactions
yield connection
end
end
|