Sha256: 3ccdb7c6a77d0b5ce893845678ab8d58ede4ecd826e215bc248d538f0ac61f91

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

# Main class for exceptions relating to Vertica.
class Vertica::Error < StandardError
  
  class ConnectionError < Vertica::Error; end
  class SSLNotSupported < ConnectionError; end
  class InterruptImpossible < Vertica::Error; end
  class MessageError < Vertica::Error; end
  class EmptyQueryError < Vertica::Error; end
    
  class SynchronizeError < Vertica::Error
    attr_reader :running_job, :requested_job

    def initialize(running_job, requested_job)
      @running_job, @requested_job = running_job, requested_job
      super("Cannot execute #{running_job}, connection is in use for #{requested_job}!")
    end
  end

  class QueryError < Vertica::Error
    
    attr_reader :error_response, :sql
    
    def initialize(error_response, sql)
      @error_response, @sql = error_response, sql
      super("#{error_response.error_message}, SQL: #{one_line_sql.inspect}" )
    end
    
    def one_line_sql
      @sql.gsub(/[\r\n]+/, ' ')
    end
    
    def self.from_error_response(error_response, sql)
      klass = QUERY_ERROR_CLASSES[error_response.sqlstate] || self
      klass.new(error_response, sql)
    end
  end
  
  QUERY_ERROR_CLASSES = {
    '55V03' => (LockFailure           = Class.new(Vertica::Error::QueryError)),
    '53000' => (InsufficientResources = Class.new(Vertica::Error::QueryError)),
    '53200' => (OutOfMemory           = Class.new(Vertica::Error::QueryError)),
    '42601' => (SyntaxError           = Class.new(Vertica::Error::QueryError)),
    '42V01' => (MissingRelation       = Class.new(Vertica::Error::QueryError)),
    '42703' => (MissingColumn         = Class.new(Vertica::Error::QueryError)),
    '22V04' => (CopyRejected          = Class.new(Vertica::Error::QueryError)),
    '42501' => (PermissionDenied      = Class.new(Vertica::Error::QueryError))
  }
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vertica-0.9.5 lib/vertica/error.rb