Method: WIKK::SQL.each_hash

Defined in:
lib/wikk_sql.rb

.each_hash(db_config, query, with_table_names = false) {|each| ... } ⇒ 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 String keys

Parameters:

  • db_config (Configuration)

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

  • the_query (String)

    Sql query to send to DB server.

  • with_table_names (Boolean) (defaults to: false)

    if TrueClass, then table names are included in the hash keys.

Yield Parameters:

  • each (Hash)

    result row

Raises:

  • (Mysql)

    passes on Mysql errors, freeing the result.



227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/wikk_sql.rb', line 227

def self.each_hash(db_config, query, with_table_names=false)
  sql = self.new
  sql.open db_config
  begin
    if block_given?
      sql.each_hash(query, with_table_names) do |res|
        yield res
      end
    end
  ensure
    sql.close
  end
  return sql
end