Parent

DBI::DBD::SQLite::Statement

See DBI::BaseStatement.

Constants

DBI_TYPE_MAP

Public Class Methods

new(stmt, dbh) click to toggle source
# File lib/dbd/sqlite/statement.rb, line 20
def initialize(stmt, dbh)
    @dbh       = dbh
    @statement = DBI::SQL::PreparedStatement.new(@dbh, stmt)
    @attr      = { }
    @params    = [ ]
    @rows      = [ ]
    @result_set = nil
    @dbh.open_handles += 1
end

Public Instance Methods

bind_param(param, value, attributes=nil) click to toggle source

See DBI::BaseStatement#bind_param. This method will also raise DBI::InterfaceError if param is not a Fixnum, to prevent incorrect binding.

# File lib/dbd/sqlite/statement.rb, line 35
def bind_param(param, value, attributes=nil)
    unless param.kind_of? Fixnum
        raise DBI::InterfaceError, "Only numeric parameters are supported"
    end

    @params[param-1] = value

    # FIXME what to do with attributes? are they important in SQLite?
end
column_info() click to toggle source
# File lib/dbd/sqlite/statement.rb, line 89
def column_info
    columns = [ ]

    # FIXME this shit should *really* be abstracted into DBI
    # FIXME this still doesn't handle nullable/unique/default stuff.
    @result_set.columns.each_with_index do |name, i|
        columns[i] = { } unless columns[i]
        columns[i]["name"] = name
        type_name = @result_set.types[i]

        if type_name
            m = DBI::DBD::SQLite.parse_type(type_name)

            columns[i]["type_name"] = m[1]
            columns[i]["precision"] = m[3].to_i if m[3]
            columns[i]["scale"]     = m[5].to_i if m[5]
            DBI_TYPE_MAP.each do |map|
                if columns[i]["type_name"] =~ map[0]
                    columns[i]["sql_type"] = map[1]
                    break
                end
            end

            case columns[i]["type_name"]
            when 'double'
                columns[i]["dbi_type"] = DBI::Type::Float
            end
        end
    end

    return columns
end
execute() click to toggle source

See DBI::BaseStatement#execute.

In the event AutoCommit is off and no transaction is currently executing, one will be opened at this point. It is your responsibility to finish, cancel, rollback, or commit.

# File lib/dbd/sqlite/statement.rb, line 52
def execute
    sql = @statement.bind(@params)
    # XXX sqlite re-escapes this for us automatically, it's causing trouble with everything else.
    #     this will probably break in a horrible manner and I will be forced to "fix" it again.
    sql.gsub!(/\\\\/) { '\' } 
    DBI::DBD::SQLite.check_sql(sql)

    begin
        unless @dbh.db.transaction_active?
            @dbh.db.transaction 
        end
        @result_set = @dbh.db.query(sql)
        @dbh.commit if @dbh["AutoCommit"]
    rescue Exception => e
        raise DBI::DatabaseError, e.message
    end
end
fetch() click to toggle source
# File lib/dbd/sqlite/statement.rb, line 80
def fetch
    return nil if @result_set.eof?

    row = @result_set.next
    return nil unless row

    return row
end
finish() click to toggle source
# File lib/dbd/sqlite/statement.rb, line 72
def finish
    # nil out the result set
    @result_set.close if @result_set
    @result_set = nil
    @rows = nil
    @dbh.open_handles -= 1
end
rows() click to toggle source
# File lib/dbd/sqlite/statement.rb, line 122
def rows
    return @dbh.db.changes
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.