Module: DBI

### Home Classes Methods

### In Files

- lib/dbi.rb
- lib/dbi/base_classes/database.rb
- lib/dbi/base_classes/driver.rb
- lib/dbi/base_classes/statement.rb
- lib/dbi/base_classes.rb
- lib/dbi/binary.rb
- lib/dbi/columninfo.rb
- lib/dbi/exceptions.rb
- lib/dbi/handles/database.rb
- lib/dbi/handles/driver.rb
- lib/dbi/handles/statement.rb
- lib/dbi/handles.rb
- lib/dbi/row.rb
- lib/dbi/sql/preparedstatement.rb
- lib/dbi/sql.rb
- lib/dbi/sql_type_constants.rb
- lib/dbi/trace.rb
- lib/dbi/types.rb
- lib/dbi/typeutil.rb
- lib/dbi/utils/date.rb
- lib/dbi/utils/tableformatter.rb
- lib/dbi/utils/time.rb
- lib/dbi/utils/timestamp.rb
- lib/dbi/utils/xmlformatter.rb
- lib/dbi/utils.rb

### Namespace

- MODULE DBI::SQL
- MODULE DBI::Type
- MODULE DBI::Utils
- CLASS DBI::BaseDatabase
- CLASS DBI::BaseDriver
- CLASS DBI::BaseStatement
- CLASS DBI::Binary
- CLASS DBI::ColumnInfo
- CLASS DBI::DataError
- CLASS DBI::DatabaseError
- CLASS DBI::DatabaseHandle
- CLASS DBI::Date
- CLASS DBI::DriverHandle
- CLASS DBI::Error
- CLASS DBI::Handle
- CLASS DBI::HandleTracer
- CLASS DBI::IntegrityError
- CLASS DBI::InterfaceError
- CLASS DBI::InternalError
- CLASS DBI::NotImplementedError
- CLASS DBI::NotSupportedError
- CLASS DBI::OperationalError
- CLASS DBI::ProgrammingError
- CLASS DBI::Row
- CLASS DBI::StatementHandle
- CLASS DBI::Time
- CLASS DBI::Timestamp
- CLASS DBI::TypeUtil
- CLASS DBI::Warning

### Methods

- ::available_drivers
- ::collect_drivers
- ::connect
- ::convert_types
- ::convert_types=
- ::data_sources
- ::disconnect_all
- ::last_connection
- ::trace

### Files

- ChangeLog
- LICENSE
- README

### Class/Module Index

Quicksearch

- DBI
- DBI::BaseDatabase
- DBI::BaseDriver
- DBI::BaseStatement
- DBI::Binary
- DBI::ColumnInfo
- DBI::DataError
- DBI::DatabaseError
- DBI::DatabaseHandle
- DBI::Date
- DBI::DriverHandle
- DBI::Error
- DBI::Handle
- DBI::HandleTracer
- DBI::IntegrityError
- DBI::InterfaceError
- DBI::InternalError
- DBI::NotImplementedError
- DBI::NotSupportedError
- DBI::OperationalError
- DBI::ProgrammingError
- DBI::Row
- DBI::SQL
- DBI::SQL::PreparedStatement
- DBI::StatementHandle
- DBI::Time
- DBI::Timestamp
- DBI::Type
- DBI::Type::Boolean
- DBI::Type::Decimal
- DBI::Type::Float
- DBI::Type::Integer
- DBI::Type::Null
- DBI::Type::Timestamp
- DBI::Type::Varchar
- DBI::TypeUtil
- DBI::Utils
- DBI::Utils::ConvParam
- DBI::Utils::TableFormatter
- DBI::Utils::XMLFormatter
- DBI::Warning
- Class

No matching classes.

# DBI

DBI - Database Interface for Ruby. Please see the files README, DBI_SPEC, DBD_SPEC for more information.

++

Dispatch classes (Handle, DriverHandle, DatabaseHandle and StatementHandle)

$Id: utils.rb,v 1.5 2006/01/29 06:14:19 djberg96 Exp $

### Constants

DEFAULT_TRACE_MODE

  Module functions (of DBI)

DEFAULT_TRACE_OUTPUT
SQL_BIGINT
SQL_BINARY
SQL_BIT
SQL_BLOB

      TODO
      Find types for these (XOPEN?)

  SQL_ARRAY =

SQL_BOOLEAN
SQL_CHAR

  SQL type constants

SQL_CLOB
SQL_DATE
SQL_DECIMAL
SQL_DOUBLE
SQL_FETCH_ABSOLUTE
SQL_FETCH_FIRST
SQL_FETCH_LAST
SQL_FETCH_NEXT

  Constants for fetch_scroll

SQL_FETCH_PRIOR
SQL_FETCH_RELATIVE
SQL_FLOAT
SQL_INTEGER
SQL_LONGVARBINARY
SQL_LONGVARCHAR
SQL_NUMERIC
SQL_OTHER

  SQL_DISTINCT = SQL_OBJECT = SQL_NULL =

SQL_REAL
SQL_SMALLINT
SQL_TIME
SQL_TIMESTAMP
SQL_TINYINT
SQL_TYPE_NAMES

  SQL_REF = SQL_STRUCT =

SQL_VARBINARY
SQL_VARCHAR
VERSION

### Public Class Methods

available_drivers() click to toggle source

Returns a list (of String) of the currently available drivers on your system in 'dbi:driver:' format.

This currently does not work for rubygems installations, please see DBI.collect_drivers for reasons.

    # File lib/dbi.rb, line 203
    def available_drivers
        drivers = []
        collect_drivers.each do |key, value|
            drivers.push("dbi:#{key}:")
        end
        return drivers
    end

collect_drivers() click to toggle source

Return a list (of String) of the available drivers.

NOTE | This is non-functional for gem installations, due to the nature of how it currently works. A better solution for this will be provided in DBI 0.6.0.

    # File lib/dbi.rb, line 184
    def collect_drivers
        drivers = { }
        # FIXME rewrite this to leverage require and be more intelligent
        path = File.join(File.dirname(__FILE__), "dbd", "*.rb")
        Dir[path].each do |f|
            if File.file?(f)
                driver = File.basename(f, ".rb")
                drivers[driver] = f
            end
        end

        return drivers
    end

connect(driver_url, user=nil, auth=nil, params=nil, &p) click to toggle source

Establish a database connection.

Format goes as such: "dbi:Driver:database_conn_args"

- "dbi" is the literal string "dbi". Case is unimportant.

- "Driver" is the case-dependent name of your database driver class. The file "dbd/#{Driver}" will be required. If you are using rubygems to control your DBDs and DBI, you must make the gem's file path available via the "gem" command before this will work.

- database_conn_args can be:

  - The database name.

  - A more complex key/value association (to indicate host, etc). This is driver dependent; you should consult your DBD documentation.

    # File lib/dbi.rb, line 144
    def connect(driver_url, user=nil, auth=nil, params=nil, &p)
        dr, db_args = _get_full_driver(driver_url)
        dh = dr[0] # driver-handle
        dh.convert_types = @@convert_types
        @@last_connection = dh.connect(db_args, user, auth, params, &p)
    end

convert_types() click to toggle source

Return the current status of type conversion at this level. This status will be propogated to any new DatabaseHandles created.

    # File lib/dbi.rb, line 119
    def self.convert_types
        @@convert_types
    end

convert_types=(bool) click to toggle source

Set the current status of type conversion at this level. This status will be propogated to any new DatabaseHandles created.

    # File lib/dbi.rb, line 125
    def self.convert_types=(bool)
        @@convert_types = bool
    end

data_sources(driver) click to toggle source

Attempt to collect the available data sources to the driver, specified in DBI.connect format.

The result is heavily dependent on the driver's ability to enumerate these sources, and results will vary.

    # File lib/dbi.rb, line 216
    def data_sources(driver)
        db_driver, = parse_url(driver)
        db_driver = load_driver(db_driver)
        dh = @@driver_map[db_driver][0]
        dh.data_sources
    end

disconnect_all( driver = nil ) click to toggle source

Attempt to disconnect all database handles. If a driver is provided, disconnections will happen under that scope. Otherwise, all loaded drivers (and their handles) will be attempted.

    # File lib/dbi.rb, line 228
    def disconnect_all( driver = nil )
        if driver.nil?
            @@driver_map.each {|k,v| v[0].disconnect_all}
        else
            db_driver, = parse_url(driver)
            @@driver_map[db_driver][0].disconnect_all
        end
    end

last_connection() click to toggle source

Return the last connection attempted.

    # File lib/dbi.rb, line 113
    def self.last_connection
        @@last_connection
    end

trace(mode=nil, output=nil) click to toggle source

Enable tracing mode. Requires that 'dbi/trace' be required before it does anything.

As of 0.4.0, this mode does not do anything either way, so this currently just throws an InterfaceError. This issue is expected to be resolved in the next release.

    # File lib/dbi.rb, line 171
    def trace(mode=nil, output=nil)
        # FIXME trace
        raise InterfaceError, "the trace module has been removed until it actually works."
        @@trace_mode   = mode   || @@trace_mode   || DBI::DEFAULT_TRACE_MODE
        @@trace_output = output || @@trace_output || DBI::DEFAULT_TRACE_OUTPUT
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.