class RDBI::Driver::PostgreSQL::Cursor

Public Class Methods

new(handle, schema) click to toggle source
Calls superclass method
# File lib/rdbi/driver/postgresql.rb, line 163
def initialize(handle, schema)
  super(handle)
  @index = 0
  @stub_datetime = DateTime.now.strftime( " %z" )
  @schema = schema
end

Public Instance Methods

[](index) click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 208
def [](index)
  fix_dates(@handle[index].values)
end
affected_count() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 187
def affected_count
  @handle.cmd_tuples
end
all() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 204
def all
  fix_dates(fetch_range(0, result_count-1))
end
empty?() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 220
def empty?
  result_count == 0
end
fetch(count=1) click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 170
def fetch(count=1)
  return [] if last_row?
  a = []
  count.times { a.push(next_row) }
  return a
end
finish() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 224
def finish
  @handle.clear
end
first() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 191
def first
  fix_dates(@handle[0].values)
end
last() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 195
def last
  fix_dates(@handle[-1].values)
end
last_row?() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 212
def last_row?
  @index == result_count
end
next_row() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 177
def next_row
  val = @handle[@index].values
  @index += 1
  fix_dates(val)
end
rest() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 199
def rest
  oindex, @index = @index, result_count-1
  fix_dates(fetch_range(oindex, @index))
end
result_count() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 183
def result_count
  @handle.num_tuples
end
rewind() click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 216
def rewind
  @index = 0
end

Protected Instance Methods

fetch_range(start, stop) click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 230
def fetch_range(start, stop)
  # XXX when did PG::Result get so stupid?
  ary = []
  (start..stop).each do |i|
    row = []
    @handle.num_fields.times do |j|
      row[ j ] = @handle.getvalue( i, j )
    end

    ary << row
  end
  # XXX end stupid rectifier.

  return ary
end
fix_dates(values) click to toggle source
# File lib/rdbi/driver/postgresql.rb, line 246
def fix_dates(values)
  index = 0

  columns = @schema.columns

  values.collect! do |val|
    if val.kind_of?(Array)
      index2 = 0
      val.collect! do |col|
        ctype = columns[index2].type
        if !col.nil? && ctype.start_with?('timestamp') && ctype =~ /timestamp(?:\(\d\d?\))? without time zone/
          col << @stub_datetime
        end

        index2 += 1
        col
      end
    else
      ctype = columns[index].type
      if !val.nil? && ctype.start_with?('timestamp') && ctype =~ /timestamp(?:\(\d\d?\))? without time zone/
        val << @stub_datetime
      end
    end

    index += 1
    val
  end

  return values
end