Exception: Mysql::Error

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

Overview

Mysql::Error

Direct Known Subclasses

ClientError, ServerError

Constant Summary collapse

ERRNO =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, sqlstate = 'HY000', errno = nil) ⇒ Error

Returns a new instance of Error.



28
29
30
31
32
33
# File 'lib/mysql/error.rb', line 28

def initialize(message, sqlstate='HY000', errno=nil)
  @sqlstate = sqlstate
  @error = message
  @errno = errno || self.class::ERRNO
  super message
end

Instance Attribute Details

#errnoObject (readonly)

Returns the value of attribute errno.



26
27
28
# File 'lib/mysql/error.rb', line 26

def errno
  @errno
end

#errorObject (readonly)

Returns the value of attribute error.



26
27
28
# File 'lib/mysql/error.rb', line 26

def error
  @error
end

#sqlstateObject (readonly)

Returns the value of attribute sqlstate.



26
27
28
# File 'lib/mysql/error.rb', line 26

def sqlstate
  @sqlstate
end

Class Method Details

.define_error_class(prefix_re) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mysql/error.rb', line 12

def self.define_error_class(prefix_re)
  self.constants.each do |errname|
    errname = errname.to_s
    next unless errname =~ prefix_re
    errno = self.const_get errname
    excname = errname.sub(prefix_re, '').gsub(/(\A.|_.)([A-Z]+)/){$1+$2.downcase}.gsub(/_/, '')
    klass = Class.new self
    klass.const_set 'ERRNO', errno
    self.const_set excname, klass
    self::ERROR_MAP[errno] = klass
    Mysql::Error.const_set errname, errno
  end
end