Class: TeradataCli::MetaData

Inherits:
Object
  • Object
show all
Defined in:
lib/teradata-cli/connection.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ MetaData

Returns a new instance of MetaData.



753
754
755
# File 'lib/teradata-cli/connection.rb', line 753

def initialize(types)
  @types = types
end

Class Method Details

.parse_datainfo(binary) ⇒ Object



745
746
747
748
749
750
751
# File 'lib/teradata-cli/connection.rb', line 745

def .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



729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
# File 'lib/teradata-cli/connection.rb', line 729

def .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



761
762
763
# File 'lib/teradata-cli/connection.rb', line 761

def column(nth)
  @types[nth]
end

#each_column(&block) ⇒ Object



765
766
767
# File 'lib/teradata-cli/connection.rb', line 765

def each_column(&block)
  @types.each(&block)
end

#field_namesObject



769
770
771
# File 'lib/teradata-cli/connection.rb', line 769

def field_names
  @types.map {|t| t.name }
end

#inspectObject



773
774
775
# File 'lib/teradata-cli/connection.rb', line 773

def inspect
  "\#<#{self.class} [#{@types.map {|t| t.to_s }.join(', ')}]>"
end

#num_columnsObject



757
758
759
# File 'lib/teradata-cli/connection.rb', line 757

def num_columns
  @types.size
end

#unmarshal(data) ⇒ Object



777
778
779
780
781
782
783
784
785
# File 'lib/teradata-cli/connection.rb', line 777

def unmarshal(data)
  f = StringIO.new(data)
  cols = @types.zip(read_indicator(f)).map {|type, is_null|
    # debugger #FIXME
    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