Last update: Tue, 19 June 2001
The module to encapsulate the Ruby ODBC binding.
module functions:
datasources
- Returns an array of ODBC::DSNs, ie all
known data source names.
drivers
- Returns an array of ODBC::Drivers,
ie all known ODBC drivers.
error
- Returns the last error message (String) or nil.
newenv
- Returns a new ODBC::Environment.
-
connection_pooling[=value]
- Gets or sets the process-wide connection pooling attribute.
-
to_time(timestamp)
to_time(date,
[time])
to_time(time,
[date])
- Creates a
Time
object from the specified arguments,
which must be ODBC::Date,
ODBC::Time, or
ODBC::TimeStamp objects.
-
to_date(timestamp)
to_date(date)
- Creates a
Date
object from the specified arguments,
which must be ODBC::Date, or
ODBC::TimeStamp objects.
connect(dsn,
[user, passwd])
[{|dbc| block}]
- If no block is specified, a connection to the given data source
is established and a ODBC::Database
object is returned, identifying that connection. Otherwise,
the block is executed with the database object. When the block
is finished, the connection is automatically released.
Options are:
- dsn: Data source name (String or
ODBC::DSN)
- user: Login user name (String)
- passwd: Login password (String)
constants:
Some constants of the ODBC API are defined in order to set connection
options and to
deal with SQL data types:
- Cursor behaviour:
- SQL_CURSOR_FORWARD_ONLY,
SQL_CURSOR_KEYSET_DRIVEN,
SQL_CURSOR_DYNAMIC,
SQL_CURSOR_STATIC
- Concurrency (transactions):
- SQL_CONCUR_READ_ONLY,
SQL_CONCUR_LOCK,
SQL_CONCUR_ROWVER,
SQL_CONCUR_VALUES
- Fetch direction:
- SQL_FETCH_NEXT,
SQL_FETCH_FIRST,
SQL_FETCH_LAST,
SQL_FETCH_PRIOR,
SQL_FETCH_ABSOLUTE,
SQL_FETCH_RELATIVE
- Data types:
- SQL_UNKNOWN_TYPE,
SQL_CHAR,
SQL_NUMERIC,
SQL_DECIMAL,
SQL_INTEGER,
SQL_SMALLINT,
SQL_FLOAT,
SQL_REAL,
SQL_DOUBLE,
SQL_VARCHAR,
SQL_DATETIME,
SQL_DATE,
SQL_TYPE_DATE,
SQL_TIME,
SQL_TYPE_TIME,
SQL_TIMESTAMP,
SQL_TYPE_TIMESTAMP,
SQL_LONGVARCHAR,
SQL_BINARY,
SQL_VARBINARY,
SQL_LONGVARBINARY,
SQL_BIGINT,
SQL_TINYINT,
SQL_BIT,
SQL_GUID
- Environment attributes:
- SQL_CP_OFF,
SQL_CP_ONE_PER_DRIVER,
SQL_CP_ONE_PER_HENV,
SQL_CP_DEFAULT,
SQL_CP_STRICT_MATCH,
SQL_CP_RELAXED_MATCH,
SQL_CP_MATCH_DEFAULT,
SQL_OV_ODBC2,
SQL_OV_ODBC3
The class to represent the root of all other ODBC related objects.
super class:
Object
methods:
error
- Returns the last error message (String) or nil.
raise(value)
- Raises an ODBC::Error exception.
singleton methods:
error
Returns the last error message (String) or nil.
The class to represent a connection to an ODBC data source.
When underlying ODBC SQL functions report an error,
an ODBC::Error
exception with a corresponding error message from the ODBC
driver manager and/or driver is raised.
super class:
ODBC::Environment
methods:
connected?
- Returns
true
when the object is in connected
state, false otherwise.
drvconnect(drv)
- Connect to a data source specified by drv
(ODBC::Driver).
disconnect
- Disconnects from the data source.
tables([pattern])
- Returns an ODBC::Statement with
information of all or some (pattern String given)
tables of the data source.
columns([table])
- Returns an ODBC::Statement
with column information
of the given table (String).
indexes([table])
- Returns an ODBC::Statement
with index information
of the given table (String).
types([tcode])
- Returns an ODBC::Statement
with type information
of the numeric SQL type tcode or all types if
tcode is omitted.
-
primary_keys([table])
- Returns an ODBC::Statement
with primary key information of the given table (String).
-
foreign_keys([table])
- Returns an ODBC::Statement
with foreign key information of the given table (String).
-
table_privileges([table])
- Returns an ODBC::Statement
with owner/right information of the given table (String).
procedures([p])
- Returns an ODBC::Statement
with information about stored procedures.
-
procedure_columns([p])
- Returns an ODBC::Statement
with information about stored procedures.
run(sql,
[args ...])
- Prepares and executes the query specified by sql
with parameters bound
from args and returns an
ODBC::Statement.
do(sql,
[args ...])
- Prepares and executes the query as in run,
but returns the number of result rows and automatically drops
the statement. Useful for SQL insert, delete, or update statements.
prepare(sql)
- Prepares the query specified by sql and returns
an ODBC::Statement.
proc(sql)
{|stmt| block}
- Prepares the query specified by sql within a
ODBCProc and returns that procedure.
When the procedure is called, the statement is executed with
the procedure's arguments bound to the statement's parameters
and the statement is bound as parameter in the block, eg
# add customer given name and id
addcust = dbc.proc("insert into customer values(?, ?)") { |stmt|
stmt.nrows
}
addcust.call("J.R. User", 9999)
# alternative form: addcust["J.R. User", 9999]
autocommit([bool])
- Sets or queries the autocommit option of the connection.
-
concurrency([intval])
- Sets or queries the concurrency mode of the connection.
maxrows([intval])
- Sets or queries the maximum rows for the connection.
timeout([intval])
- Sets or queries the timeout value of the connection.
maxlength([intval])
- Sets or queries the maximum length for the connection.
-
rowsetsize([intval])
- Sets or queries the row set size option of the connection.
-
cursortype([intval])
- Sets or queries the cursor behaviour of the connection.
noscan([bool])
- Sets or queries the noscan option of the connection.
drop_all
- Releases the resources of all open
ODBC::Statements in this
database connection.
singleton methods:
new
- Creates an unconnected ODBC object, eg for a later
drvconnect
method call.
new(dsn,
[user, passwd])
- Connect to an ODBC data source. Options are:
- dsn: Data source name (String or
ODBC::DSN)
- user: Login user name (String)
- passwd: Login password (String)
Remarks:
The
run,
prepare,
do, and info methods (eg
tables)
can be invoked with a block. In this case the block is executed with
the
ODBC::Statement as parameter.
The class to represent the query result. The object of this
class is created as the result of every query. You may need to invoke the
close or drop methods for the finished object for better memory performance.
When underlying ODBC SQL functions report an error,
an ODBC::Error
exception with a corresponding error message from the ODBC driver manager
and/or driver is raised.
ODBC to Ruby type mapping:
ODBC | Ruby |
SQL_SMALLINT, SQL_INTEGER, SQL_TINYINT, SQL_BIT |
T_FIXNUM, T_BIGNUM |
SQL_FLOAT, SQL_DOUBLE, SQL_REAL | T_FLOAT |
SQL_DATE, SQL_TYPE_DATE |
ODBC::Date |
SQL_TIME, SQL_TYPE_TIME |
ODBC::Time |
SQL_TIMESTAMP, SQL_TYPE_TIMESTAMP |
ODBC::TimeStamp |
all others | T_STRING |
super class:
ODBC::Database
mixins:
Enumerable
methods:
cancel
- Cancel and close the
ODBC::Statement.
close
- Close the ODBC::Statement.
drop
- Close and free the ODBC::Statement.
column(n)
- Returns information of the n-th column of the query result
as ODBC::Column.
columns
- Returns a hash of column information keyed by column names
(Strings) of the query result. The hash elements are
ODBC::Columns.
ncols
- Returns the number of columns of the query result.
nrows
- Returns the number of rows of the query result.
fetch
- Returns the next row of the query result as an array.
fetch_first
- Returns the first row of the query result as an array.
fetch_scroll(direction,
offset=1)
- Returns the row addressed by direction, eg
SQL_FETCH_LAST
as an array. offset is
used for SQL_FETCH_RELATIVE
and
SQL_FETCH_ABSOLUTE
.
fetch_many(count)
- Returns an array of the next count rows of the query
result, where each row is an array.
fetch_all
- Same as
fetch_many
except that all remaining rows
are returned.
-
fetch_hash(with_table_names)
- Returns the next row of the query result as a hash keyed by
column names. If with_table_names is true,
the keys are combined table/column names.
each {|row|
block}
- Iterates over the query result, performing a
fetch
for each row.
each_hash(with_table_names)
{|row| block}
- Iterates over the query result, performing a
fetch_hash
for each row.
execute([args ...])
- Binds args to current query and executes it.
Remarks:
The
fetch
,
fetch_hash
,
and
execute
methods can be invoked with a block. In this case the block is
executed with one row of the result set (
fetch
and
fetch_hash
) or with the
ODBC::Statement (
execute
)
as parameter.
The class to represent information of a column of a query.
Objects of this class are created as result of the column
and columns
methods of
ODBC::Statement.
super class:
ODBC::Object
methods:
name
- Returns the column name (String).
table
- Returns the table name (String).
length
- Returns the length of the column (Integer).
nullable
- Returns the nullable state of the column (Boolean).
searchable
- Returns the searchable state of the column (Boolean).
unsigned
- Returns the unsigned flag of the column (Boolean).
precision
- Returns the precision of the column (Integer).
scale
- Returns the scale of the column (Integer).
type
- Returns the SQL type of the column (Integer).
The class to represent a SQL_DATE
column in a table.
super class:
ODBC::Object
mixins:
Comparable
methods:
<=>(adate)
- Comparison, compares date with adate and returns
0, 1, or -1.
day[=num]
- Returns or sets the day component of the date object.
month[=num]
- Returns or sets the month component of the date object.
year[=num]
- Returns or sets the year component of the date object.
to_s
- Returns a string representation of the object with format
YYYY-MM-DD
.
singleton methods:
new([year, month,
day])
new(date)
new(time)
- Creates a new date object from numeric values or from
a
Date
or Time
object.
The class to represent a SQL_TIME
column in a table.
super class:
ODBC::Object
mixins:
Comparable
methods:
<=>(atime)
- Comparison, compares time with atime and returns
0, 1, or -1.
second[=num]
- Returns or sets the second component of the time object.
minute[=num]
- Returns or sets the minute component of the time object.
hour[=num]
- Returns or sets the hour component of the time object.
to_s
- Returns a string representation of the object with format
hh:mm:ss
.
singleton methods:
new([hour, minute,
second])
new(time)
- Creates a new time object from numeric values or from
a
Time
object.
The class to represent a SQL_TIMESTAMP
column in a table.
super class:
ODBC::Object
mixins:
Comparable
methods:
<=>(atimestamp)
- Comparison, compares time stamp with atimestamp
and returns 0, 1, or -1.
fraction[=num]
- Returns or sets the fraction component of the time stamp object.
Note that this is expressed in nanoseconds.
second[=num]
- Returns or sets the second component of the time stamp object.
minute[=num]
- Returns or sets the minute component of the time stamp object.
hour[=num]
- Returns or sets the hour component of the time stamp object.
day[=num]
- Returns or sets the day component of the time stamp object.
month[=num]
- Returns or sets the month component of the time stamp object.
year[=num]
- Returns or sets the year component of the time stamp object.
to_s
- Returns a string representation of the object with format
YYYY-MM-DD hh:mm:ss fraction
.
singleton methods:
new([year, month,
day, hour, minute,
second, fraction])
new(time)
- Creates a new time stamp object from numeric values or from
a
Time
object.
The class to represent a data source name. Objects of this class are
created as result of a
ODBC::datasources
module function call.
super class:
ODBC::Object
methods:
name[=name]
- Queries or sets the name (String) of the data source.
descr[=descr]
- Queries or sets the descr (description, String)
of the data source.
singleton methods:
new
- Returns an empty ODBC::DSN object.
The class to represent an ODBC driver with name and attributes.
Objects of this class are
created as result of a ODBC::drivers
module function call.
super class:
ODBC::Object
methods:
name[=name]
- Queries or sets the name (String) of the ODBC driver.
attrs[[key][=value]]
- Queries or sets attributes in the attrs Hash of the
ODBC driver object. The keys and values
should be Strings.
singleton methods:
new
- Returns an empty ODBC::Driver object.
The class to represent a procedure with ODBC database/statement
context.
Objects of this class are created as result of a
ODBC::Database.proc method call.
super class:
Proc
methods:
call([args*])
- Executes the SQL statement with parameters set from args
and then invokes the procedure's block, setting the block's
parameter to the ODBC::Statement.
[[args*]]
- Synonym for
call
.
The class to represent ODBC related exceptions.
super class:
StandardError
mailto:Christian Werner