Class: Vertica::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/vertica/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, sql, options = {}) ⇒ Query

Returns a new instance of Query.



6
7
8
9
10
11
12
13
14
15
# File 'lib/vertica/query.rb', line 6

def initialize(connection, sql, options = {})
  @connection, @sql = connection, sql
  
  @row_style    = options[:row_style] || @connection.row_style || :hash
  @row_handler  = options[:row_handler] 
  @copy_handler = options[:copy_handler]

  @error  = nil
  @result = Vertica::Result.new(row_style)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/vertica/query.rb', line 3

def connection
  @connection
end

#copy_handlerObject

Returns the value of attribute copy_handler.



4
5
6
# File 'lib/vertica/query.rb', line 4

def copy_handler
  @copy_handler
end

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'lib/vertica/query.rb', line 3

def error
  @error
end

#resultObject (readonly)

Returns the value of attribute result.



3
4
5
# File 'lib/vertica/query.rb', line 3

def result
  @result
end

#row_handlerObject

Returns the value of attribute row_handler.



4
5
6
# File 'lib/vertica/query.rb', line 4

def row_handler
  @row_handler
end

#row_styleObject

Returns the value of attribute row_style.



4
5
6
# File 'lib/vertica/query.rb', line 4

def row_style
  @row_style
end

#sqlObject (readonly)

Returns the value of attribute sql.



3
4
5
# File 'lib/vertica/query.rb', line 3

def sql
  @sql
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/vertica/query.rb', line 17

def run
  @connection.write Vertica::Messages::Query.new(sql)
  
  begin
    process_message(message = @connection.read_message)
  end until message.kind_of?(Vertica::Messages::ReadyForQuery)

  raise error unless error.nil?
  return result
end

#to_sObject



35
36
37
# File 'lib/vertica/query.rb', line 35

def to_s
  @sql
end

#write(data) ⇒ Object Also known as: <<



28
29
30
31
# File 'lib/vertica/query.rb', line 28

def write(data)
  @connection.write Vertica::Messages::CopyData.new(data)
  return self
end