123456789_123456789_123456789_123456789_123456789_

Exception: SQLite3::Exception

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, StandardError
Instance Chain:
self, StandardError
Inherits: StandardError
  • ::Object
Defined in: lib/sqlite3/errors.rb

Instance Attribute Summary

  • #code readonly

    A convenience for accessing the error code for this exception.

  • #sql readonly

    If the error is associated with a SQL query, this is the query.

  • #sql_offset readonly

    If the error is associated with a particular offset in a SQL query, this is the non-negative offset.

Instance Method Summary

Instance Attribute Details

#code (readonly)

A convenience for accessing the error code for this exception.

[ GitHub ]

  
# File 'lib/sqlite3/errors.rb', line 6

attr_reader :code

#sql (readonly)

If the error is associated with a SQL query, this is the query

[ GitHub ]

  
# File 'lib/sqlite3/errors.rb', line 9

attr_reader :sql

#sql_offset (readonly)

If the error is associated with a particular offset in a SQL query, this is the non-negative offset. If the offset is not available, this will be -1.

[ GitHub ]

  
# File 'lib/sqlite3/errors.rb', line 13

attr_reader :sql_offset

Instance Method Details

#message

[ GitHub ]

  
# File 'lib/sqlite3/errors.rb', line 15

def message
  [super, sql_error].compact.join(":\n")
end

#sql_error (private)

[ GitHub ]

  
# File 'lib/sqlite3/errors.rb', line 19

private def sql_error
  return nil unless @sql
  return @sql.chomp unless @sql_offset >= 0

  offset = @sql_offset
  sql.lines.flat_map do |line|
    if offset >= 0 && line.length > offset
      blanks = " " * offset
      offset = -1
      [line.chomp, blanks + "^"]
    else
      offset -= line.length if offset
      line.chomp
    end
  end.join("\n")
end