Exception: Mysql2::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/mysql2/error.rb

Constant Summary

ENCODE_OPTS =
{
  :undef => :replace,
  :invalid => :replace,
  :replace => '?'.freeze,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg) ⇒ Error

Returns a new instance of Error



17
18
19
20
21
# File 'lib/mysql2/error.rb', line 17

def initialize(msg)
  @server_version ||= nil

  super(clean_message(msg))
end

Instance Attribute Details

#error_numberObject (readonly) Also known as: errno

Returns the value of attribute error_number



11
12
13
# File 'lib/mysql2/error.rb', line 11

def error_number
  @error_number
end

#sql_stateObject (readonly)

Returns the value of attribute sql_state



11
12
13
# File 'lib/mysql2/error.rb', line 11

def sql_state
  @sql_state
end

Class Method Details

.new_with_args(msg, server_version, error_number, sql_state) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/mysql2/error.rb', line 23

def self.new_with_args(msg, server_version, error_number, sql_state)
  err = allocate
  err.instance_variable_set('@server_version', server_version)
  err.instance_variable_set('@error_number', error_number)
  err.instance_variable_set('@sql_state', sql_state.respond_to?(:encode) ? sql_state.encode(ENCODE_OPTS) : sql_state)
  err.send(:initialize, msg)
  err
end