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

Methods

Classes and Modules

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

Constants

VERSION = "0.4.3"
DEFAULT_TRACE_MODE = 2   Module functions (of DBI)
DEFAULT_TRACE_OUTPUT = STDERR
SQL_FETCH_NEXT = 1   Constants for fetch_scroll
SQL_FETCH_PRIOR = 2
SQL_FETCH_FIRST = 3
SQL_FETCH_LAST = 4
SQL_FETCH_ABSOLUTE = 5
SQL_FETCH_RELATIVE = 6
SQL_CHAR = 1   SQL type constants
SQL_NUMERIC = 2
SQL_DECIMAL = 3
SQL_INTEGER = 4
SQL_SMALLINT = 5
SQL_FLOAT = 6
SQL_REAL = 7
SQL_DOUBLE = 8
SQL_DATE = 9
SQL_TIME = 10
SQL_TIMESTAMP = 11
SQL_VARCHAR = 12
SQL_BOOLEAN = 13
SQL_LONGVARCHAR = -1
SQL_BINARY = -2
SQL_VARBINARY = -3
SQL_LONGVARBINARY = -4
SQL_BIGINT = -5
SQL_TINYINT = -6
SQL_BIT = -7
SQL_BLOB = -10  
 TODO
 Find types for these (XOPEN?)
SQL_ARRAY =
SQL_CLOB = -11
SQL_OTHER = 100   SQL_DISTINCT = SQL_OBJECT = SQL_NULL =
SQL_TYPE_NAMES = { SQL_BIT => 'BIT', SQL_TINYINT => 'TINYINT', SQL_SMALLINT => 'SMALLINT', SQL_INTEGER => 'INTEGER', SQL_BIGINT => 'BIGINT', SQL_FLOAT => 'FLOAT', SQL_REAL => 'REAL', SQL_DOUBLE => 'DOUBLE', SQL_NUMERIC => 'NUMERIC', SQL_DECIMAL => 'DECIMAL', SQL_CHAR => 'CHAR', SQL_VARCHAR => 'VARCHAR', SQL_LONGVARCHAR => 'LONG VARCHAR', SQL_DATE => 'DATE', SQL_TIME => 'TIME', SQL_TIMESTAMP => 'TIMESTAMP', SQL_BINARY => 'BINARY', SQL_VARBINARY => 'VARBINARY', SQL_LONGVARBINARY => 'LONG VARBINARY', SQL_BLOB => 'BLOB', SQL_CLOB => 'CLOB', SQL_OTHER => nil, SQL_BOOLEAN => 'BOOLEAN', }   SQL_REF = SQL_STRUCT =

Public Class methods

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.

[Source]

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

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.

[Source]

     # File lib/dbi.rb, line 178
178:         def collect_drivers
179:             drivers = { }
180:             # FIXME rewrite this to leverage require and be more intelligent
181:             path = File.join(File.dirname(__FILE__), "dbd", "*.rb")
182:             Dir[path].each do |f|
183:                 if File.file?(f)
184:                     driver = File.basename(f, ".rb")
185:                     drivers[driver] = f
186:                 end
187:             end
188: 
189:             return drivers
190:         end

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.

[Source]

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

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

[Source]

     # File lib/dbi.rb, line 113
113:     def self.convert_types
114:         @@convert_types
115:     end

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

[Source]

     # File lib/dbi.rb, line 119
119:     def self.convert_types=(bool)
120:         @@convert_types = bool
121:     end

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.

[Source]

     # File lib/dbi.rb, line 210
210:         def data_sources(driver)
211:             db_driver, = parse_url(driver)
212:             db_driver = load_driver(db_driver)
213:             dh = @@driver_map[db_driver][0]
214:             dh.data_sources
215:         end

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.

[Source]

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

Return the last connection attempted.

[Source]

     # File lib/dbi.rb, line 107
107:     def self.last_connection
108:         @@last_connection
109:     end

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.

[Source]

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

[Validate]