2. Errors

Both the database and query class have a common error method: error(). The database class returns a string whereas the query class returns a QSqlError object. Though it is a C++ object, it has the following Ruby form:


class SqlError

  def text()
    # Error text
  end

  def number()
    # Error number
  end

  def type()
    # One of:
    #   NoError
    #   ConnectionError
    #   StatementError
    #   TransactionError
    #   UnknownError
  end

  def isValid?()
    # Whether the error object is a valid one
  end

  def driverText()
    # Error text from DB driver
  end

  def databaseText()
    # Error text from database
  end

end

Here is a typical example of usage:


# Count the number of records in foods table
assert @query.exec('select * from no_table') == nil

error = @query.error()

assert error.valid? == true
assert error.number == 1
assert error.type == SqlError::StatementError
assert error.text() == 'no such table: no_table Unable to execute statement'
assert error.databaseText() == 'no such table: no_table'
assert error.driverText() == 'Unable to execute statement'