Class: TeradataCli::MetaData
- Inherits:
-
Object
- Object
- TeradataCli::MetaData
- Defined in:
- lib/teradata-cli/connection.rb
Class Method Summary collapse
Instance Method Summary collapse
- #column(nth) ⇒ Object
- #each_column(&block) ⇒ Object
- #field_names ⇒ Object
-
#initialize(types) ⇒ MetaData
constructor
A new instance of MetaData.
- #inspect ⇒ Object
- #num_columns ⇒ Object
- #unmarshal(data) ⇒ Object
Constructor Details
#initialize(types) ⇒ MetaData
Returns a new instance of MetaData.
751 752 753 |
# File 'lib/teradata-cli/connection.rb', line 751 def initialize(types) @types = types end |
Class Method Details
.parse_datainfo(binary) ⇒ Object
743 744 745 746 747 748 749 |
# File 'lib/teradata-cli/connection.rb', line 743 def MetaData.parse_datainfo(binary) n_entries, *entries = binary.unpack('S*') unless entries.size % 2 == 0 and entries.size / 2 == n_entries raise MetaDataFormatError, "could not get correct size of metadata (expected=#{n_entries * 2}, really=#{entries.size})" end new(entries.each_slice(2).map {|type, len| FieldType.create(type, len) }) end |
.parse_prepinfo(binary, extractor) ⇒ Object
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 |
# File 'lib/teradata-cli/connection.rb', line 727 def MetaData.parse_prepinfo(binary, extractor) f = StringIO.new(binary) cost_estimate, summary_count = f.read(10).unpack('dS') return new([]) if f.eof? # does not have column count count, = f.read(2).unpack('S') new(count.times.map { type, data_len, name_len = f.read(6).unpack('SSS') column_name = f.read(name_len) format_len, = f.read(2).unpack('S') format = f.read(format_len) title_len, = f.read(2).unpack('S') title = f.read(title_len) FieldType.create(type, data_len, column_name, format, title, extractor) }) end |
Instance Method Details
#column(nth) ⇒ Object
759 760 761 |
# File 'lib/teradata-cli/connection.rb', line 759 def column(nth) @types[nth] end |
#each_column(&block) ⇒ Object
763 764 765 |
# File 'lib/teradata-cli/connection.rb', line 763 def each_column(&block) @types.each(&block) end |
#field_names ⇒ Object
767 768 769 |
# File 'lib/teradata-cli/connection.rb', line 767 def field_names @types.map {|t| t.name } end |
#inspect ⇒ Object
771 772 773 |
# File 'lib/teradata-cli/connection.rb', line 771 def inspect "\#<#{self.class} [#{@types.map {|t| t.to_s }.join(', ')}]>" end |
#num_columns ⇒ Object
755 756 757 |
# File 'lib/teradata-cli/connection.rb', line 755 def num_columns @types.size end |
#unmarshal(data) ⇒ Object
775 776 777 778 779 780 781 782 |
# File 'lib/teradata-cli/connection.rb', line 775 def unmarshal(data) f = StringIO.new(data) cols = @types.zip(read_indicator(f)).map {|type, is_null| val = type.unmarshal(f) # We must read value regardless of NULL. is_null ? nil : val } Record.new(self, @types.zip(cols).map {|type, col| Field.new(type, col) }) end |