Exception: Mysql2::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Mysql2::Error
- Defined in:
- lib/mysql2/error.rb
Constant Summary collapse
- ENCODE_OPTS =
{ undef: :replace, invalid: :replace, replace: '?'.freeze, }.freeze
- ConnectionError =
Class.new(Error)
- TimeoutError =
Class.new(Error)
- CODES =
{ 1205 => TimeoutError, # ER_LOCK_WAIT_TIMEOUT 1044 => ConnectionError, # ER_DBACCESS_DENIED_ERROR 1045 => ConnectionError, # ER_ACCESS_DENIED_ERROR 1152 => ConnectionError, # ER_ABORTING_CONNECTION 1153 => ConnectionError, # ER_NET_PACKET_TOO_LARGE 1154 => ConnectionError, # ER_NET_READ_ERROR_FROM_PIPE 1155 => ConnectionError, # ER_NET_FCNTL_ERROR 1156 => ConnectionError, # ER_NET_PACKETS_OUT_OF_ORDER 1157 => ConnectionError, # ER_NET_UNCOMPRESS_ERROR 1158 => ConnectionError, # ER_NET_READ_ERROR 1159 => ConnectionError, # ER_NET_READ_INTERRUPTED 1160 => ConnectionError, # ER_NET_ERROR_ON_WRITE 1161 => ConnectionError, # ER_NET_WRITE_INTERRUPTED 1927 => ConnectionError, # ER_CONNECTION_KILLED 2001 => ConnectionError, # CR_SOCKET_CREATE_ERROR 2002 => ConnectionError, # CR_CONNECTION_ERROR 2003 => ConnectionError, # CR_CONN_HOST_ERROR 2004 => ConnectionError, # CR_IPSOCK_ERROR 2005 => ConnectionError, # CR_UNKNOWN_HOST 2006 => ConnectionError, # CR_SERVER_GONE_ERROR 2007 => ConnectionError, # CR_VERSION_ERROR 2009 => ConnectionError, # CR_WRONG_HOST_INFO 2012 => ConnectionError, # CR_SERVER_HANDSHAKE_ERR 2013 => ConnectionError, # CR_SERVER_LOST 2020 => ConnectionError, # CR_NET_PACKET_TOO_LARGE 2026 => ConnectionError, # CR_SSL_CONNECTION_ERROR 2027 => ConnectionError, # CR_MALFORMED_PACKET 2047 => ConnectionError, # CR_CONN_UNKNOW_PROTOCOL 2048 => ConnectionError, # CR_INVALID_CONN_HANDLE 2049 => ConnectionError, # CR_UNUSED_1 }.freeze
Instance Attribute Summary collapse
-
#error_number ⇒ Object
(also: #errno)
readonly
Returns the value of attribute error_number.
-
#sql_state ⇒ Object
readonly
Returns the value of attribute sql_state.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(msg, server_version = nil, error_number = nil, sql_state = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(msg, server_version = nil, error_number = nil, sql_state = nil) ⇒ Error
Returns a new instance of Error.
53 54 55 56 57 58 59 |
# File 'lib/mysql2/error.rb', line 53 def initialize(msg, server_version = nil, error_number = nil, sql_state = nil) @server_version = server_version @error_number = error_number @sql_state = sql_state ? sql_state.encode('ascii', **ENCODE_OPTS) : nil super((msg)) end |
Instance Attribute Details
#error_number ⇒ Object (readonly) Also known as: errno
Returns the value of attribute error_number.
47 48 49 |
# File 'lib/mysql2/error.rb', line 47 def error_number @error_number end |
#sql_state ⇒ Object (readonly)
Returns the value of attribute sql_state.
47 48 49 |
# File 'lib/mysql2/error.rb', line 47 def sql_state @sql_state end |
Class Method Details
.new_with_args(msg, server_version, error_number, sql_state) ⇒ Object
61 62 63 64 |
# File 'lib/mysql2/error.rb', line 61 def self.new_with_args(msg, server_version, error_number, sql_state) error_class = CODES.fetch(error_number, self) error_class.new(msg, server_version, error_number, sql_state) end |