class DBI::DBD::SQLRelay::Database

Public Instance Methods

[]=(attr, value) click to toggle source

Stores “value” associated with key “attr”. sqlrelay_debug=true or false will toggle debugging and AutoCommit=true or false will toggle autocommit.

# File SQLRelay.rb, line 142
def []=(attr, value)

  # AutoCommit and sqlrelay_debug are supported by this driver
  case attr
  when 'AutoCommit'
    if value == true
      @handle.autoCommitOn
    else
      @handle.autoCommitOff
    end
  when 'sqlrelay_debug' 
    if value == true
      @handle.debugOn
    else
      @handle.debugOff
    end
  else
    if attr =~ /^sqlrelay_/ or attr != /_/
      # raise and exception for unsupported or improperly formatted options
      raise DBI::NotSupportedError, "Option '#{attr}' not supported"
    else 
      # option for some other driver - quietly ignore
      return  
    end     
  end
  @attr[attr] = value
end
commit() click to toggle source

Issues a commit. Raises a DBI::ProgrammingError if it failed.

# File SQLRelay.rb, line 112
def commit
  $stderr.puts "Warning: Commit ineffective while AutoCommit is on" if @attr['AutoCommit']

  case @handle.commit
  when 0
    # failed
    raise DBI::OperationalError.new("Commit failed")
  when -1
    raise DBI::OperationalError.new("Error occured during commit")
 end
end
disconnect() click to toggle source

Ends the current session.

# File SQLRelay.rb, line 94
def disconnect
  @handle.endSession
end
ping() click to toggle source

Returns true if the database is up and false if it's down.

# File SQLRelay.rb, line 100
def ping
  @handle.ping == 1 ? true : false
end
prepare(statement) click to toggle source

Prepare to execute query. Returns a Statement.

# File SQLRelay.rb, line 106
def prepare(statement)
  Statement.new(@handle, statement)
end
rollback() click to toggle source

Issues a rollback. Raises a DBI::ProgrammingError if it failed.

# File SQLRelay.rb, line 126
def rollback
  $stderr.puts "Warning: Rollback ineffective while AutoCommit is on" if @attr['AutoCommit']

  case @handle.rollback
  when 0
    # failed
    raise DBI::OperationalError.new("Rollback failed")
  when -1
    raise DBI::OperationalError.new("Error occured during rollback")
  end
end