Method: WIKK::SQL.each_param

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

.each_param(db_config, query) {|for| ... } ⇒ Object

Note:

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

Create WIKK::SQL instance and set up the mySQL connection, and Run a query on the DB server. 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:

  • db_config (Configuration)

    Configuration class, Hash, or any class with appropriate attr_readers.

  • the_query (String)

    Sql query to send to DB server.

Yield Parameters:

  • for (**Hash)

    each result row, which can be passed to named args in a block

Raises:

  • (Mysql)

    passes on Mysql errors, freeing the result.



373
374
375
376
377
378
379
380
381
382
# File 'lib/wikk_mysql2.rb', line 373

def self.each_param(db_config, query, &block)
  self.connect( db_config ) do |sql|
    if block_given?
      sql.each_param(query, &block)
      return sql  # May be useful to access the affected rows
    else
      return sql.each_sym(query)
    end
  end
end