Class: Teradata::MetaData
- Inherits:
-
Object
- Object
- Teradata::MetaData
- Defined in:
- lib/teradata/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
750 751 752 |
# File 'lib/teradata/connection.rb', line 750 def initialize(types) @types = types end |
Class Method Details
.parse_datainfo(binary) ⇒ Object
742 743 744 745 746 747 748 |
# File 'lib/teradata/connection.rb', line 742 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
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
# File 'lib/teradata/connection.rb', line 726 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
758 759 760 |
# File 'lib/teradata/connection.rb', line 758 def column(nth) @types[nth] end |
#each_column(&block) ⇒ Object
762 763 764 |
# File 'lib/teradata/connection.rb', line 762 def each_column(&block) @types.each(&block) end |
#field_names ⇒ Object
766 767 768 |
# File 'lib/teradata/connection.rb', line 766 def field_names @types.map {|t| t.name } end |
#inspect ⇒ Object
770 771 772 |
# File 'lib/teradata/connection.rb', line 770 def inspect "\#<#{self.class} [#{@types.map {|t| t.to_s }.join(', ')}]>" end |
#num_columns ⇒ Object
754 755 756 |
# File 'lib/teradata/connection.rb', line 754 def num_columns @types.size end |
#unmarshal(data) ⇒ Object
774 775 776 777 778 779 780 781 |
# File 'lib/teradata/connection.rb', line 774 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 |