Class: PG::Result
- Inherits:
-
Object
- Object
- PG::Result
- Defined in:
- lib/tep/pg.rb
Instance Attribute Summary collapse
-
#rh ⇒ Object
Returns the value of attribute rh.
Instance Method Summary collapse
- #clear ⇒ Object
- #cmd_status ⇒ Object
- #cmd_tuples ⇒ Object
- #column_values(col) ⇒ Object
-
#each ⇒ Object
Hash-yielding iteration -- matches ruby-pg's #each.
-
#each_row ⇒ Object
Array-yielding iteration.
- #error_field(code) ⇒ Object
- #error_message ⇒ Object
- #fformat(col) ⇒ Object
- #fields ⇒ Object
- #fmod(col) ⇒ Object
- #fname(col) ⇒ Object
- #fnumber(name) ⇒ Object
- #ftype(col) ⇒ Object
- #getisnull(row, col) ⇒ Object
- #getlength(row, col) ⇒ Object
- #getvalue(row, col) ⇒ Object
-
#initialize(rh) ⇒ Result
constructor
A new instance of Result.
- #nfields ⇒ Object
- #ntuples ⇒ Object
- #num_fields ⇒ Object
-
#num_tuples ⇒ Object
ruby-pg aliases for ntuples / nfields.
-
#ok? ⇒ Boolean
True when the query reached the server and produced a non-error result (rows, command success, or empty query).
-
#sql_state ⇒ Object
ruby-pg's PG::Result#error_field shortcut: 5-char SQLSTATE string.
- #status ⇒ Object
-
#value(row, col) ⇒ Object
ruby-pg's #value is an alias for #getvalue.
- #values ⇒ Object
Constructor Details
#initialize(rh) ⇒ Result
Returns a new instance of Result.
613 614 615 |
# File 'lib/tep/pg.rb', line 613 def initialize(rh) @rh = rh end |
Instance Attribute Details
#rh ⇒ Object
Returns the value of attribute rh.
611 612 613 |
# File 'lib/tep/pg.rb', line 611 def rh @rh end |
Instance Method Details
#clear ⇒ Object
787 788 789 790 791 792 793 |
# File 'lib/tep/pg.rb', line 787 def clear if @rh >= 0 Pg.tep_pg_clear(@rh) @rh = -1 end 0 end |
#cmd_status ⇒ Object
637 638 639 |
# File 'lib/tep/pg.rb', line 637 def cmd_status @rh < 0 ? "" : Pg.tep_pg_cmd_status(@rh) end |
#cmd_tuples ⇒ Object
647 648 649 |
# File 'lib/tep/pg.rb', line 647 def cmd_tuples @rh < 0 ? 0 : Pg.tep_pg_cmd_tuples(@rh) end |
#column_values(col) ⇒ Object
732 733 734 735 736 737 738 739 740 741 742 |
# File 'lib/tep/pg.rb', line 732 def column_values(col) out = [""] out.delete_at(0) n = ntuples i = 0 while i < n out.push(getvalue(i, col)) i += 1 end out end |
#each ⇒ Object
Hash-yielding iteration -- matches ruby-pg's #each. Pre-builds the field-name array to skip a per-row fname call. The Hash shape is pinned to str_str_hash via a seed in lib/tep.rb; without that seed spinel widens to poly_poly_hash on first use.
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'lib/tep/pg.rb', line 769 def each flds = fields n = ntuples w = flds.length i = 0 while i < n row = Tep.str_hash j = 0 while j < w row[flds[j]] = getvalue(i, j) j += 1 end yield row i += 1 end self end |
#each_row ⇒ Object
Array-yielding iteration. Cleaner shape than #each for hot paths -- no Hash allocation per row.
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
# File 'lib/tep/pg.rb', line 746 def each_row n = ntuples w = nfields i = 0 while i < n row = [""] row.delete_at(0) j = 0 while j < w row.push(getvalue(i, j)) j += 1 end yield row i += 1 end self end |
#error_field(code) ⇒ Object
633 634 635 |
# File 'lib/tep/pg.rb', line 633 def error_field(code) @rh < 0 ? "" : Pg.tep_pg_result_error_field(@rh, code) end |
#error_message ⇒ Object
629 630 631 |
# File 'lib/tep/pg.rb', line 629 def @rh < 0 ? "" : Pg.(@rh) end |
#fformat(col) ⇒ Object
675 676 677 |
# File 'lib/tep/pg.rb', line 675 def fformat(col) @rh < 0 ? 0 : Pg.tep_pg_fformat(@rh, col) end |
#fields ⇒ Object
700 701 702 703 704 705 706 707 708 709 710 |
# File 'lib/tep/pg.rb', line 700 def fields out = [""] out.delete_at(0) w = nfields j = 0 while j < w out.push(fname(j)) j += 1 end out end |
#fmod(col) ⇒ Object
679 680 681 |
# File 'lib/tep/pg.rb', line 679 def fmod(col) @rh < 0 ? -1 : Pg.tep_pg_fmod(@rh, col) end |
#fname(col) ⇒ Object
663 664 665 |
# File 'lib/tep/pg.rb', line 663 def fname(col) @rh < 0 ? "" : Pg.tep_pg_fname(@rh, col) end |
#fnumber(name) ⇒ Object
667 668 669 |
# File 'lib/tep/pg.rb', line 667 def fnumber(name) @rh < 0 ? -1 : Pg.tep_pg_fnumber(@rh, name) end |
#ftype(col) ⇒ Object
671 672 673 |
# File 'lib/tep/pg.rb', line 671 def ftype(col) @rh < 0 ? 0 : Pg.tep_pg_ftype(@rh, col) end |
#getisnull(row, col) ⇒ Object
687 688 689 |
# File 'lib/tep/pg.rb', line 687 def getisnull(row, col) @rh < 0 ? true : Pg.tep_pg_getisnull(@rh, row, col) == 1 end |
#getlength(row, col) ⇒ Object
691 692 693 |
# File 'lib/tep/pg.rb', line 691 def getlength(row, col) @rh < 0 ? 0 : Pg.tep_pg_getlength(@rh, row, col) end |
#getvalue(row, col) ⇒ Object
683 684 685 |
# File 'lib/tep/pg.rb', line 683 def getvalue(row, col) @rh < 0 ? "" : Pg.tep_pg_getvalue(@rh, row, col) end |
#nfields ⇒ Object
655 656 657 |
# File 'lib/tep/pg.rb', line 655 def nfields @rh < 0 ? 0 : Pg.tep_pg_nfields(@rh) end |
#ntuples ⇒ Object
651 652 653 |
# File 'lib/tep/pg.rb', line 651 def ntuples @rh < 0 ? 0 : Pg.tep_pg_ntuples(@rh) end |
#num_fields ⇒ Object
661 |
# File 'lib/tep/pg.rb', line 661 def num_fields; nfields; end |
#num_tuples ⇒ Object
ruby-pg aliases for ntuples / nfields.
660 |
# File 'lib/tep/pg.rb', line 660 def num_tuples; ntuples; end |
#ok? ⇒ Boolean
True when the query reached the server and produced a
non-error result (rows, command success, or empty query).
Inspect error_message / error_field(5) on a non-ok result.
624 625 626 627 |
# File 'lib/tep/pg.rb', line 624 def ok? st = status st == Pg::RES_TUPLES || st == Pg::RES_COMMAND || st == Pg::RES_EMPTY end |
#sql_state ⇒ Object
ruby-pg's PG::Result#error_field shortcut: 5-char SQLSTATE string. Empty when the result isn't an error.
643 644 645 |
# File 'lib/tep/pg.rb', line 643 def sql_state error_field(PG::DIAG_SQLSTATE) end |
#status ⇒ Object
617 618 619 |
# File 'lib/tep/pg.rb', line 617 def status @rh < 0 ? Pg::RES_ERROR : Pg.tep_pg_result_status(@rh) end |
#value(row, col) ⇒ Object
ruby-pg's #value is an alias for #getvalue.
696 697 698 |
# File 'lib/tep/pg.rb', line 696 def value(row, col) getvalue(row, col) end |
#values ⇒ Object
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
# File 'lib/tep/pg.rb', line 712 def values rows = [[""]] rows.delete_at(0) n = ntuples w = nfields i = 0 while i < n row = [""] row.delete_at(0) j = 0 while j < w row.push(getvalue(i, j)) j += 1 end rows.push(row) i += 1 end rows end |