Class: DB::MySQL::Native::Result
- Inherits:
-
FFI::Pointer
- Object
- FFI::Pointer
- DB::MySQL::Native::Result
- Defined in:
- lib/db/mysql/native/result.rb
Instance Method Summary collapse
- #each ⇒ Object
- #field_count ⇒ Object
- #field_names ⇒ Object (also: #keys)
- #fields ⇒ Object
-
#initialize(connection, address) ⇒ Result
constructor
A new instance of Result.
- #row_count ⇒ Object (also: #count)
- #to_a ⇒ Object
Constructor Details
#initialize(connection, address) ⇒ Result
Returns a new instance of Result.
98 99 100 101 102 103 |
# File 'lib/db/mysql/native/result.rb', line 98 def initialize(connection, address) super(address) @connection = connection @fields = nil end |
Instance Method Details
#each ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/db/mysql/native/result.rb', line 132 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 pointer.get_array_of_string(0, field_count) end end @connection.check_error!("Reading recordset") end |
#field_count ⇒ Object
105 106 107 |
# File 'lib/db/mysql/native/result.rb', line 105 def field_count Native.mysql_num_fields(self) end |
#field_names ⇒ Object Also known as: keys
121 122 123 |
# File 'lib/db/mysql/native/result.rb', line 121 def field_names fields.map(&:name) end |
#fields ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/db/mysql/native/result.rb', line 109 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 |
#row_count ⇒ Object Also known as: count
125 126 127 |
# File 'lib/db/mysql/native/result.rb', line 125 def row_count Native.mysql_num_rows(self) end |
#to_a ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/db/mysql/native/result.rb', line 157 def to_a rows = [] self.each do |row| rows << row end return rows end |