Ruby/OpenBase Reference

Using Ruby/OpenBase

Typically using Ruby/OpenBase is connecting to database and executing SQL statement with OpenBase object. If you execute SQL statement with OpenBase#execute(), you can get OpenBaseResult object to access query result table as return value. Next, call fetch() or each() to fetching result rows. A simple example is the following.

require 'openbase'

# connects to database
ob = OpenBase.new('WOMovies', 'localhost', 'admin', '')

# executes SQL statement
result = ob.execute 'select * from MOVIE'

# shows result rows
result.each do |row|
  p row
end

Class OpenBase

This class services connecting and communicating to database.

Class Methods

new( database='', host='localhost', login_name='', password='' )
Creates an object and connects to the database.

Instance Methods

(Getting information of the database)

database
Returns the database name.
host
Returns the host name.
login
Returns the login name.
password
Returns the password.
encoding
Returns the encoding.

(Scheme Information)

tables
Returns an array of all table names.
columns( table )
Returns an array of column names of specified table.
relationships( table )
Returns an array of relationships of specified table.

(Connecting to the database)

connect( database='', host='localhost', login_name='', password='' )
Connects to the database.
invalidate
Invalidates connection of the database.
connect?
Returns true if the receiver is connected to the database, or false.

(Executing SQL statements)

execute( statement )
Executes the SQL statement and returns an OpenBaseResult object.

(Using Transaction)

transaction { |connection| ... }
Executes the block with the receiver after starting a new transaction. If the block don't raise exception, the receiver commits the transaction, or rollbacks. If the receiver already has a transaction, executes the block after commiting the transaction.
begin
Starts a new transaction.
commit
Commits the transaction.
rollback
Rollbacks the transaction.
transaction?
Returns true if the receiver has a transcation in progress, or false.

(Generating unique row IDs)

unique_row_id( table, column = '' )
Generates a unique _rowid for the table and column. The _rowid must be inserted with a new record. You need not use the method to insert a new record because of _rowid is used by OpenBase.

Class OpenBaseResult

This class services accessing query result table.

Instance Methods

(Accessing query result table)

column_count
Returns count of the columns.
rows_affected
Returns the number of database rows affected by the most recent SQL statement.
column_infos
Returns an array of OpenBaseColumnInfo objects.

(Fetching)

fetch
Returns a row as array fetched from the database. If there are no more result rows in the database, returns nil.
each { |row| ... }
Fetches each result row.
free
Frees memory used for result row.

Class OpenBaseColumnInfo

This class services accessing information of column.

Instance Methods

name
Returns name of the column..
type
Returns data type of the column.
table
Returns table name of the column.

Copyright (C) SUZUKI Tetsuya. All rights reserved.