Exception: OCIError

Inherits:
OCIException show all
Defined in:
ext/oci8/error.c,
lib/oci8/oci8.rb,
ext/oci8/error.c

Overview

Subclass of OCIException

The following exceptions are defined as subclasses of OCIError.

  • OCISuccessWithInfo

  • OCINoData (It had been a subclass of OCIException, not OCIError, until ruby-oci8 2.0)

Raised when underlying Oracle Call Interface failed with an Oracle error code such as ORA-00001.

Direct Known Subclasses

OCINoData, OCISuccessWithInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, error_code = nil, sql_stmt = nil, parse_error_offset = nil) ⇒ OCIError #initialize(error_code, *params) ⇒ OCIError

Returns a new instance of OCIError.

Overloads:

  • #initialize(message, error_code = nil, sql_stmt = nil, parse_error_offset = nil) ⇒ OCIError

    Creates a new OCIError object with specified parameters.

    Examples:

    OCIError.new("ORA-00001: unique constraint (%s.%s) violated", 1, 'insert into table_name values (1)', )
    # => #<OCIError: ORA-00001: unique constraint (%s.%s) violated>
    #<OCIError: ORA-00923: FROM keyword not found where expected>
    "select sysdate"
    923
    14

    Parameters:

    • message (String)

      error message

    • error_code (Integer) (defaults to: nil)

      Oracle error code

    • sql_stmt (String) (defaults to: nil)

      SQL statement

    • parse_error_offset (Integer) (defaults to: nil)
  • #initialize(error_code, *params) ⇒ OCIError

    Creates a new OCIError object with the error message which corresponds to the specified Oracle error code.

    Examples:

    # without parameters
    OCIError.new(4043)
    # When NLS_LANG=american_america.AL32UTF8
    # => #<OCIError: ORA-04043: object %s does not exist>
    # When NLS_LANG=german_germany.AL32UTF8
    # => #<OCIError: ORA-04043: Objekt %s ist nicht vorhanden>
    
    # with one parameter
    OCIError.new(4043, 'table_name')
    # When NLS_LANG=american_america.AL32UTF8
    # => #<OCIError: ORA-04043: object table_name does not exist>
    # When NLS_LANG=german_germany.AL32UTF8
    # => #<OCIError: ORA-04043: Objekt table_name ist nicht vorhanden>

    Parameters:

    • error_code (Integer)

      Oracle error code

    • params (String, ...)

      parameters which replace ā€˜%sā€™



623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/oci8/oci8.rb', line 623

def initialize(*args)
  if args.length > 0
    if args[0].is_a? Integer
      @code = args.shift
      super(OCI8.error_message(@code).gsub('%s') {|s| args.empty? ? '%s' : args.shift})
      @sql = nil
      @parse_error_offset = nil
    else
      msg, @code, @sql, @parse_error_offset = args
      super(msg)
    end
  else
    super()
  end
end

Instance Attribute Details

#codeObject (readonly)

#parse_error_offsetObject (readonly) Also known as: parseErrorOffset

#sqlObject (readonly)