Class: DBI::DriverHandle

Inherits:
Handle
  • Object
show all
Defined in:
lib/dbi/handles/driver.rb

Overview

DriverHandles, while not directly exposed, are essentially the backend for the facade that many DBI root-level methods communicate with.

Instance Attribute Summary (collapse)

Attributes inherited from Handle

#convert_types, #handle, #trace_mode, #trace_output

Instance Method Summary (collapse)

Methods inherited from Handle

#func, #initialize, #trace

Constructor Details

This class inherits a constructor from DBI::Handle

Instance Attribute Details

- (Object) driver_name=(value) (writeonly)

Sets the attribute driver_name



6
7
8
# File 'lib/dbi/handles/driver.rb', line 6

def driver_name=(value)
  @driver_name = value
end

Instance Method Details

- (Object) connect(db_args, user, auth, params)

Connect to the database. The DSN will have been parsed at this point and the named parameters should need no explanation.

If a block is provided to DBI.connect, the connected DatabaseHandle will be provided as the first argument to the block, and the DatabaseHandle will be disconnected upon block exit.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dbi/handles/driver.rb', line 15

def connect(db_args, user, auth, params)

    user = @handle.default_user[0] if user.nil?
    auth = @handle.default_user[1] if auth.nil?

    # TODO: what if only one of them is nil?
    #if user.nil? and auth.nil? then
    #  user, auth = @handle.default_user
    #end

    params ||= {}
    new_params = @handle.default_attributes
    params.each {|k,v| new_params[k] = v} 

    if params.has_key?(:_convert_types)
        @convert_types = params[:_convert_types]
    end

    db = @handle.connect(db_args, user, auth, new_params)
    dbh = DatabaseHandle.new(db, @convert_types)
    # FIXME trace
    # dbh.trace(@trace_mode, @trace_output)
    dbh.driver_name = @driver_name

    if block_given?
        begin
            yield dbh
        ensure  
            dbh.disconnect if dbh.connected?
        end  
    else
        return dbh
    end
end

- (Object) data_sources

See BaseDriver#data_sources.



51
52
53
# File 'lib/dbi/handles/driver.rb', line 51

def data_sources
    @handle.data_sources
end

- (Object) disconnect_all

See BaseDriver#disconnect_all.



56
57
58
# File 'lib/dbi/handles/driver.rb', line 56

def disconnect_all
    @handle.disconnect_all
end