Class: KnjDB_mysql_result
- Defined in:
- lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb
Overview
This class controls the results for the normal MySQL-driver.
Instance Method Summary collapse
-
#each ⇒ Object
Loops over every result yielding it.
-
#fetch ⇒ Object
Returns a single result.
-
#fetch_hash_strings ⇒ Object
Returns a single result as a hash with strings as keys.
-
#fetch_hash_symbols ⇒ Object
Returns a single result as a hash with symbols as keys.
-
#initialize(driver, result) ⇒ KnjDB_mysql_result
constructor
Constructor.
Constructor Details
#initialize(driver, result) ⇒ KnjDB_mysql_result
Constructor. This should not be called manually.
388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb', line 388 def initialize(driver, result) @driver = driver @result = result @mutex = Mutex.new if @result @keys = [] keys = @result.fetch_fields keys.each do |key| @keys << key.name.to_sym end end end |
Instance Method Details
#each ⇒ Object
Loops over every result yielding it.
435 436 437 438 439 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb', line 435 def each while data = self.fetch_hash_symbols yield(data) end end |
#fetch ⇒ Object
Returns a single result.
403 404 405 406 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb', line 403 def fetch return self.fetch_hash_symbols if @driver.knjdb.opts[:return_keys] == "symbols" return self.fetch_hash_strings end |
#fetch_hash_strings ⇒ Object
Returns a single result as a hash with strings as keys.
409 410 411 412 413 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb', line 409 def fetch_hash_strings @mutex.synchronize do return @result.fetch_hash end end |
#fetch_hash_symbols ⇒ Object
Returns a single result as a hash with symbols as keys.
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb', line 416 def fetch_hash_symbols fetched = nil @mutex.synchronize do fetched = @result.fetch_row end return false if !fetched ret = {} count = 0 @keys.each do |key| ret[key] = fetched[count] count += 1 end return ret end |