Class: DBI::DBD::Pg::Statement

### Home Classes Methods

### In Files

- lib/dbd/pg/statement.rb

### Parent

DBI::BaseStatement

### Namespace

- CLASS DBI::DBD::Pg::Statement::DummyQuoter

### Methods

- ::new
- #[]
- #bind_param
- #column_info
- #execute
- #fetch
- #fetch_scroll
- #finish
- #rows

### Files

- ChangeLog
- LICENSE
- README

### Class/Module Index

Quicksearch

- DBI
- DBI::DBD
- DBI::DBD::Pg
- DBI::DBD::Pg::Database
- DBI::DBD::Pg::Driver
- DBI::DBD::Pg::PgExecutor
- DBI::DBD::Pg::PgExecutorAsync
- DBI::DBD::Pg::Statement
- DBI::DBD::Pg::Statement::DummyQuoter
- DBI::DBD::Pg::Tuples
- DBI::DBD::Pg::Type
- DBI::DBD::Pg::Type::Array
- DBI::DBD::Pg::Type::ByteA

No matching classes.

# DBI::DBD::Pg::Statement

See DBI::BaseStatement, and DBI::DBD::Pg::Tuples.

### Constants

PG_STMT_NAME_PREFIX

### Public Class Methods

new(db, sql) click to toggle source

    # File lib/dbd/pg/statement.rb, line 13
    def initialize(db, sql)
        super(db)
        @db  = db
        @sql = sql
        @stmt_name = PG_STMT_NAME_PREFIX + self.object_id.to_s + Time.now.to_f.to_s
        @result = nil
        @bindvars = []
        @prepared = false
    rescue PGError => err
        raise DBI::ProgrammingError.new(err.message)
    end

### Public Instance Methods

[](attr) click to toggle source

Attributes:

If `pg_row_count` is requested and the statement has already executed, postgres will return what it believes is the row count.

    # File lib/dbd/pg/statement.rb, line 100
    def [](attr)
        case attr
        when 'pg_row_count'
            if @result
                @result.row_count
            else
                nil
            end
        else
            @attr[attr]
        end
    end

bind_param(index, value, options) click to toggle source

    # File lib/dbd/pg/statement.rb, line 25
    def bind_param(index, value, options)
        @bindvars[index-1] = value
    end

column_info() click to toggle source

See DBI::DBD::Pg::Tuples#column_info.

    # File lib/dbd/pg/statement.rb, line 82
    def column_info
        @result.column_info
    end

execute() click to toggle source

See DBI::BaseDatabase#execute.

This method will make use of PostgreSQL's native BLOB support if DBI::Binary objects are passed in.

    # File lib/dbd/pg/statement.rb, line 35
    def execute
        # replace DBI::Binary object by oid returned by lo_import
        @bindvars.collect! do |var|
            if var.is_a? DBI::Binary then
                oid = @db.__blob_create(PGconn::INV_WRITE)
                @db.__blob_write(oid, var.to_s)
                oid
            else
                var
            end
        end

        internal_prepare

        if not @db['AutoCommit'] then
            #          if not SQL.query?(boundsql) and not @db['AutoCommit'] then
            @db.start_transaction unless @db.in_transaction?
        end

        if @db["pg_native_binding"]
            pg_result = @db._exec_prepared(@stmt_name, *@bindvars)
        else
            pg_result = @db._exec_prepared(@stmt_name)
        end

        @result = DBI::DBD::Pg::Tuples.new(@db, pg_result)
    rescue PGError, RuntimeError => err
        raise DBI::ProgrammingError.new(err.message)
    end

fetch() click to toggle source

    # File lib/dbd/pg/statement.rb, line 65
    def fetch
        @result.fetchrow
    end

fetch_scroll(direction, offset) click to toggle source

    # File lib/dbd/pg/statement.rb, line 69
    def fetch_scroll(direction, offset)
        @result.fetch_scroll(direction, offset)
    end

finish() click to toggle source

    # File lib/dbd/pg/statement.rb, line 73
    def finish
        internal_finish
        @result = nil
        @db = nil
    end

rows() click to toggle source

    # File lib/dbd/pg/statement.rb, line 86
    def rows
        if @result
            @result.rows_affected
        else
            nil
        end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.