Class: KnjDB_java_mysql_result
- Defined in:
- lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb
Instance Method Summary collapse
- #each ⇒ Object
- #fetch ⇒ Object
-
#initialize(knjdb, opts, result) ⇒ KnjDB_java_mysql_result
constructor
A new instance of KnjDB_java_mysql_result.
-
#read_meta ⇒ Object
Reads meta-data about the query like keys and count.
Constructor Details
#initialize(knjdb, opts, result) ⇒ KnjDB_java_mysql_result
Returns a new instance of KnjDB_java_mysql_result.
462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb', line 462 def initialize(knjdb, opts, result) @knjdb = knjdb @result = result if !opts.key?(:result) or opts[:result] == "hash" @as_hash = true elsif opts[:result] == "array" @as_hash = false else raise "Unknown type of result: '#{opts[:result]}'." end end |
Instance Method Details
#each ⇒ Object
510 511 512 513 514 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb', line 510 def each while data = self.fetch yield(data) end end |
#fetch ⇒ Object
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb', line 487 def fetch return false if !@result self. if !@keys status = @result.next return false if !status if @as_hash ret = {} 1.upto(@keys.length) do |count| ret[@keys[count - 1]] = @result.string(count).to_s.encode("utf-8") end else ret = [] 1.upto(@count) do |count| ret << @result.string(count).to_s.encode("utf-8") end end return ret end |
#read_meta ⇒ Object
Reads meta-data about the query like keys and count.
476 477 478 479 480 481 482 483 484 485 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb', line 476 def @result.before_first = @result. @count = .column_count @keys = [] 1.upto(@count) do |count| @keys << .column_label(count).to_sym end end |