Module: DBI

Defined in:
lib/dbi/row.rb,
lib/dbi.rb,
lib/dbd/ADO.rb,
lib/dbi/sql.rb,
lib/dbi/trace.rb,
lib/dbi/utils.rb,
lib/dbi/version.rb

Overview

$Id: version.rb,v 1.1 2006/01/04 02:03:22 francis Exp $

Defined Under Namespace

Modules: DBD, SQL, Utils Classes: Base, BaseDatabase, BaseDriver, BaseStatement, Binary, DataError, DatabaseError, DatabaseHandle, Date, DriverHandle, Error, Handle, HandleTracer, IntegrityError, InterfaceError, InternalError, NotImplementedError, NotSupportedError, OperationalError, ProgrammingError, Row, StatementHandle, Time, Timestamp, Warning

Constant Summary collapse

VERSION =
"0.0.23"
SQL_FETCH_NEXT =

Constants for fetch_scroll

1
SQL_FETCH_PRIOR =
2
SQL_FETCH_FIRST =
3
SQL_FETCH_LAST =
4
SQL_FETCH_ABSOLUTE =
5
SQL_FETCH_RELATIVE =
6
SQL_CHAR =

SQL type constants

1
SQL_NUMERIC =
2
SQL_DECIMAL =
3
SQL_INTEGER =
4
SQL_SMALLINT =
5
SQL_FLOAT =
6
SQL_REAL =
7
SQL_DOUBLE =
8
SQL_DATE =

91

9
SQL_TIME =

92

10
SQL_TIMESTAMP =

93

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 =

TODO Find types for these (XOPEN?) SQL_ARRAY =

-10   # TODO
SQL_CLOB =

TODO

-11   # TODO
#SQL_DISTINCT = 
#SQL_OBJECT = 
#SQL_NULL =
SQL_OTHER =

SQL_DISTINCT = SQL_OBJECT = SQL_NULL =

100
SQL_TYPE_NAMES =

SQL_REF = SQL_STRUCT =

{
   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',

}
DEFAULT_TRACE_MODE =

Module functions (of DBI)

2
DEFAULT_TRACE_OUTPUT =
STDERR
@@driver_map =

TODO: Is using class variables within a module such a wise idea? - Dan B.

Hash.new
@@driver_monitor =
::Monitor.new()
@@trace_mode =
DEFAULT_TRACE_MODE
@@trace_output =
DEFAULT_TRACE_OUTPUT
@@tracer_driver =
HandleTracer.new(DBI::DriverHandle)
@@tracer_database =
HandleTracer.new(DBI::DatabaseHandle)
@@tracer_statement =
HandleTracer.new(DBI::StatementHandle)

Class Method Summary collapse

Class Method Details

._get_full_driver(driver_url) ⇒ Object

Extracts the db_args from driver_url and returns the correspondeing entry of the @@driver_map.



231
232
233
234
235
236
# File 'lib/dbi.rb', line 231

def _get_full_driver(driver_url)
   db_driver, db_args = parse_url(driver_url)
   db_driver = load_driver(db_driver)
   dr = @@driver_map[db_driver]
   [dr, db_args]
end

.available_driversObject

Returns a list of the currently available drivers on your system in ‘dbi:driver:’ format.



245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/dbi.rb', line 245

def available_drivers
   drivers = []
   #path = File.dirname(File.dirname(__FILE__)) + "/" + DBD::DIR
   path = File.dirname(__FILE__) + "/" + DBD::DIR
   Find.find(path){ |f|
      if File.file?(f)
         driver = File.basename(f, ".rb")
         drivers.push("dbi:#{driver}:")
      end
   }
   drivers
end

.connect(driver_url, user = nil, auth = nil, params = nil, &p) ⇒ Object

Establish a database connection. This is mostly a facade for the DBD’s connect method.



218
219
220
221
222
# File 'lib/dbi.rb', line 218

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.connect(db_args, user, auth, params, &p)
end

.data_sources(driver) ⇒ Object



258
259
260
261
262
263
# File 'lib/dbi.rb', line 258

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) ⇒ Object



265
266
267
268
269
270
271
272
# File 'lib/dbi.rb', line 265

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

.get_driver(driver_url) ⇒ Object

Load a DBD and returns the DriverHandle object



225
226
227
# File 'lib/dbi.rb', line 225

def get_driver(driver_url)
   _get_full_driver(driver_url)[0][0]  # return DriverHandle
end

.trace(mode = nil, output = nil) ⇒ Object



238
239
240
241
# File 'lib/dbi.rb', line 238

def trace(mode=nil, output=nil)
   @@trace_mode   = mode   || @@trace_mode   || DBI::DEFAULT_TRACE_MODE
   @@trace_output = output || @@trace_output || DBI::DEFAULT_TRACE_OUTPUT
end