Class: Mysql::Result
- Inherits:
-
Object
- Object
- Mysql::Result
- Defined in:
- lib/ventouse/mysql_compat.rb
Instance Attribute Summary collapse
-
#eof ⇒ Object
Returns the value of attribute eof.
Instance Method Summary collapse
- #data_seek(n) ⇒ Object
- #each ⇒ Object
- #each_hash(with_table = nil) ⇒ Object
- #fetch_field ⇒ Object
- #fetch_field_direct(n) ⇒ Object
- #fetch_fields ⇒ Object
- #fetch_hash(with_table = nil) ⇒ Object
- #fetch_lengths ⇒ Object
- #fetch_row ⇒ Object
- #field_seek(n) ⇒ Object
- #field_tell ⇒ Object
- #free ⇒ Object
-
#initialize(mysql, fields, field_count, data = nil) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
- #num_fields ⇒ Object
- #num_rows ⇒ Object
- #row_seek(n) ⇒ Object
- #row_tell ⇒ Object
Constructor Details
#initialize(mysql, fields, field_count, data = nil) ⇒ Result
Returns a new instance of Result.
580 581 582 583 584 585 586 587 588 589 |
# File 'lib/ventouse/mysql_compat.rb', line 580 def initialize(mysql, fields, field_count, data=nil) @handle = mysql @fields = fields @field_count = field_count @data = data @current_field = 0 @current_row = 0 @eof = false @row_count = 0 end |
Instance Attribute Details
#eof ⇒ Object
Returns the value of attribute eof.
590 591 592 |
# File 'lib/ventouse/mysql_compat.rb', line 590 def eof @eof end |
Instance Method Details
#data_seek(n) ⇒ Object
592 593 594 |
# File 'lib/ventouse/mysql_compat.rb', line 592 def data_seek(n) @current_row = n end |
#each ⇒ Object
676 677 678 679 680 |
# File 'lib/ventouse/mysql_compat.rb', line 676 def each() while row = fetch_row do yield row end end |
#each_hash(with_table = nil) ⇒ Object
682 683 684 685 686 |
# File 'lib/ventouse/mysql_compat.rb', line 682 def each_hash(with_table=nil) while hash = fetch_hash(with_table) do yield hash end end |
#fetch_field ⇒ Object
596 597 598 599 600 601 |
# File 'lib/ventouse/mysql_compat.rb', line 596 def fetch_field() return if @current_field >= @field_count f = @fields[@current_field] @current_field += 1 f end |
#fetch_field_direct(n) ⇒ Object
607 608 609 |
# File 'lib/ventouse/mysql_compat.rb', line 607 def fetch_field_direct(n) @fields[n] end |
#fetch_fields ⇒ Object
603 604 605 |
# File 'lib/ventouse/mysql_compat.rb', line 603 def fetch_fields() @fields end |
#fetch_hash(with_table = nil) ⇒ Object
636 637 638 639 640 641 642 643 644 645 |
# File 'lib/ventouse/mysql_compat.rb', line 636 def fetch_hash(with_table=nil) row = fetch_row return if row == nil hash = {} @fields.each_index do |i| f = with_table ? @fields[i].table+"."+@fields[i].name : @fields[i].name hash[f] = row[i] end hash end |
#fetch_lengths ⇒ Object
611 612 613 |
# File 'lib/ventouse/mysql_compat.rb', line 611 def fetch_lengths() @data ? @data[@current_row].map{|i| i ? i.length : 0} : @lengths end |
#fetch_row ⇒ Object
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/ventouse/mysql_compat.rb', line 615 def fetch_row() if @data then if @current_row >= @data.length then @handle.status = :STATUS_READY return end ret = @data[@current_row] @current_row += 1 else return if @eof ret = @handle.read_one_row @field_count if ret == nil then @eof = true return end @lengths = ret.map{|i| i ? i.length : 0} @row_count += 1 end ret end |
#field_seek(n) ⇒ Object
647 648 649 |
# File 'lib/ventouse/mysql_compat.rb', line 647 def field_seek(n) @current_field = n end |
#field_tell ⇒ Object
651 652 653 |
# File 'lib/ventouse/mysql_compat.rb', line 651 def field_tell() @current_field end |
#free ⇒ Object
655 656 657 658 |
# File 'lib/ventouse/mysql_compat.rb', line 655 def free() @handle.skip_result @handle = @fields = @data = nil end |
#inspect ⇒ Object
688 689 690 |
# File 'lib/ventouse/mysql_compat.rb', line 688 def inspect() "#<#{self.class}>" end |
#num_fields ⇒ Object
660 661 662 |
# File 'lib/ventouse/mysql_compat.rb', line 660 def num_fields() @field_count end |
#num_rows ⇒ Object
664 665 666 |
# File 'lib/ventouse/mysql_compat.rb', line 664 def num_rows() @data ? @data.length : @row_count end |
#row_seek(n) ⇒ Object
668 669 670 |
# File 'lib/ventouse/mysql_compat.rb', line 668 def row_seek(n) @current_row = n end |
#row_tell ⇒ Object
672 673 674 |
# File 'lib/ventouse/mysql_compat.rb', line 672 def row_tell() @current_row end |