Method: WIKK::SQL#each_sym

Defined in:
lib/wikk_mysql2.rb,
lib/wikk_ruby_mysql.rb

#each_sym(the_query) {|each| ... } ⇒ Array

Note:

@result and @affected_rows are also set via call to query().

Yields query result row by row, as Hash using Symbol keys, so can’t have table names included. This can be used with keyword arguments. eg. each_sym { |key1:, key2:, …, **rest_of_args| do something }

Parameters:

  • the_query (String)

    Sql query to send to DB server.

Yield Parameters:

  • each (Hash)

    result row

Returns:

  • (Array)

    if no block is given, returns an Array of Hash’d rows, with symbol as the key

Raises:

  • (Mysql)

    passes on Mysql errors, freeing the result.



234
235
236
237
238
239
240
241
242
243
# File 'lib/wikk_mysql2.rb', line 234

def each_sym(the_query, &block)
  query(the_query, { symbolize_keys: true, as: :hash, cache_rows: false })
  if @result != nil
    if block_given?
      @result.each(&block)
    else
      return @result.to_a
    end
  end
end