Exception: Mysql2::Error
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
StandardError
|
|
Instance Chain:
self,
StandardError
|
|
Inherits: |
StandardError
|
Defined in: | lib/mysql2/error.rb |
Constant Summary
-
CODES =
# File 'lib/mysql2/error.rb', line 12{ 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
-
ConnectionError =
# File 'lib/mysql2/error.rb', line 9Class.new(Error)
-
ENCODE_OPTS =
# File 'lib/mysql2/error.rb', line 3{ undef: :replace, invalid: :replace, replace: '?'.freeze, }.freeze
-
TimeoutError =
# File 'lib/mysql2/error.rb', line 10Class.new(Error)
Class Method Summary
Instance Attribute Summary
-
#errno
readonly
Alias for #error_number.
- #error_number (also: #errno) readonly
- #sql_state readonly
Instance Method Summary
- #error
-
#clean_message(message)
private
In MySQL 5.5+ error messages are always constructed server-side as UTF-8 then returned in the encoding set by the
character_set_results
system variable.
Constructor Details
.new(msg, server_version = nil, error_number = nil, sql_state = nil) ⇒ Error
# 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(**ENCODE_OPTS) : nil super( (msg)) end
Class Method Details
.new_with_args(msg, server_version, error_number, sql_state)
[ GitHub ]# 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
Instance Attribute Details
#errno (readonly)
Alias for #error_number.
# File 'lib/mysql2/error.rb', line 50
alias errno error_number
#error_number (readonly) Also known as: #errno
[ GitHub ]# File 'lib/mysql2/error.rb', line 47
attr_reader :error_number, :sql_state
#sql_state (readonly)
[ GitHub ]# File 'lib/mysql2/error.rb', line 47
attr_reader :error_number, :sql_state
Instance Method Details
#clean_message(message) (private)
In MySQL 5.5+ error messages are always constructed server-side as UTF-8 then returned in the encoding set by the character_set_results
system variable.
See dev.mysql.com/doc/refman/5.5/en/charset-errors.html for more context.
Before MySQL 5.5 error message template strings are in whatever encoding is associated with the error message language. See dev.mysql.com/doc/refman/5.1/en/error-message-language.html for more information.
The issue is that the user-data inserted in the message could potentially be in any encoding MySQL supports and is insert into the latin1, euckr or koi8r string raw. Meaning there’s a high probability the string will be corrupt encoding-wise.
See dev.mysql.com/doc/refman/5.1/en/charset-errors.html for more information.
So in an attempt to make sure the error message string is always in a valid encoding, we’ll assume UTF-8 and clean the string of anything that’s not a valid UTF-8 character.
Returns a valid UTF-8 string.
# File 'lib/mysql2/error.rb', line 93
def ( ) if @server_version && @server_version > 50500 .encode(**ENCODE_OPTS) else .encode(Encoding::UTF_8, **ENCODE_OPTS) end end
#error
[ GitHub ]# File 'lib/mysql2/error.rb', line 51
alias error