Skip to content

Commit

Permalink
Merge pull request #67 from sonots/support_multiple_statements
Browse files Browse the repository at this point in the history
Support a query with multiple statments (unofficially)
  • Loading branch information
wvanbergen authored Apr 10, 2017
2 parents c082f0a + 5303216 commit 200d317
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/vertica/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def handle_data_row(message)
def handle_command_complete(message)
if buffer_rows?
@result = Vertica::Result.new(row_description: @row_description, rows: @buffer, tag: message.tag)
@row_description, @buffer = nil, nil
@row_description = nil
@buffer = []
else
@result = message.tag
end
Expand Down
14 changes: 14 additions & 0 deletions test/functional/functional_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ def test_select_query_with_multibyte_column_names_results
assert_equal 'ニ', r.row_description[1].name
end

# Query with multiple statements is not officailly supported
def test_query_with_multiple_statements
# Results of only the last statement are obtained
r = @connection.query("SET SEARCH_PATH TO default; SELECT 1 as one; SELECT 2 as two")
assert_equal 1, r.size
assert_equal 1, r.row_description.length
assert_equal 'two', r.row_description[0].name

# Error of the former statement is raised
assert_raises(Vertica::Error::MissingColumn) do
@connection.query("SELECT missing FROM test_ruby_vertica_table; SELECT 1 FROM missing")
end
end

def test_insert
r = @connection.query("INSERT INTO test_ruby_vertica_table VALUES (2, 'stefanie')")
assert_equal "INSERT", r.tag
Expand Down

0 comments on commit 200d317

Please sign in to comment.