Method: WIKK::SQL#query_array
- Defined in:
-
lib/wikk_mysql2.rb,
lib/wikk_ruby_mysql.rb
@result and @affected_rows are also set via call to query().
Yields query query results row by row, as Array
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/wikk_mysql2.rb', line 173 def each_row(the_query, &block) begin query(the_query, { as: :array, cache_rows: false }) unless @result.nil? if block_given? @affected_rows = @result.count # This is non-zero is we do a select, and get results. @result.each(&block) else result = [] @result.each { |row| result << row } return result end end rescue Mysql2::Error => e # puts "#{e.errno}: #{e.error}" raise e ensure if block_given? && @result != nil @result.free end end end |