Method: DBI::DatabaseHandle#prepare

Defined in:
lib/dbi/handles/database.rb

#prepare(stmt) ⇒ Object

Prepare a StatementHandle and return it. If given a block, it will supply that StatementHandle as the first argument to the block, and BaseStatement#finish it when the block is done executing.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dbi/handles/database.rb', line 51

def prepare(stmt)
    sanity_check(stmt)
    @last_statement = stmt
    sth = StatementHandle.new(@handle.prepare(stmt), false, true, @convert_types)
    # FIXME trace sth.trace(@trace_mode, @trace_output)
    sth.dbh = self
    sth.raise_error = raise_error

    if block_given?
        begin
            yield sth
        ensure
            sth.finish unless sth.finished?
        end
    else
        return sth
    end 
end