class DB::MariaDB::Native::Result
Public Class Methods
new(connection, types = {}, address)
click to toggle source
Calls superclass method
# File lib/db/mariadb/native/result.rb, line 35 def initialize(connection, types = {}, address) super(address) @connection = connection @fields = nil @types = types @casts = nil end
Public Instance Methods
cast!(row)
click to toggle source
# File lib/db/mariadb/native/result.rb, line 75 def cast!(row) @casts ||= self.field_types row.size.times do |index| if cast = @casts[index] row[index] = cast.parse(row[index]) end end return row end
each() { |cast!(get_array_of_string)| ... }
click to toggle source
# File lib/db/mariadb/native/result.rb, line 87 def each row = FFI::MemoryPointer.new(:pointer) field_count = self.field_count while true status = Native.mysql_fetch_row_start(row, self) while status != 0 @connection.wait_for(status) status = Native.mysql_fetch_row_cont(row, self, status) end pointer = row.read_pointer if pointer.null? break else yield cast!(pointer.get_array_of_string(0, field_count)) end end @connection.check_error!("Reading recordset") end
field_count()
click to toggle source
# File lib/db/mariadb/native/result.rb, line 44 def field_count Native.mysql_num_fields(self) end
field_names()
click to toggle source
# File lib/db/mariadb/native/result.rb, line 60 def field_names fields.map(&:name) end
Also aliased as: keys
field_types()
click to toggle source
# File lib/db/mariadb/native/result.rb, line 64 def field_types fields.map{|field| @types[field.type]} end
fields()
click to toggle source
# File lib/db/mariadb/native/result.rb, line 48 def fields unless @fields pointer = Native.mysql_fetch_fields(self) @fields = field_count.times.map do |index| Field.new(pointer + index * Field.size) end end return @fields end
map() { |row| ... }
click to toggle source
# File lib/db/mariadb/native/result.rb, line 112 def map(&block) results = [] self.each do |row| results << yield(row) end return results end
row_count()
click to toggle source
# File lib/db/mariadb/native/result.rb, line 68 def row_count Native.mysql_num_rows(self) end
Also aliased as: count
to_a()
click to toggle source
# File lib/db/mariadb/native/result.rb, line 122 def to_a rows = [] self.each do |row| rows << row end return rows end