|
2 | 2 |
|
3 | 3 | class Vertica::Connection
|
4 | 4 |
|
5 |
| - attr_reader :options, :notices, :transaction_status, :backend_pid, :backend_key, :parameters, :notice_handler |
| 5 | + attr_reader :options, :notices, :transaction_status, :backend_pid, :backend_key, :parameters, :notice_handler, :session_id |
6 | 6 |
|
7 | 7 | attr_accessor :row_style, :debug
|
8 | 8 |
|
9 | 9 | def self.cancel(existing_conn)
|
10 |
| - conn = self.new(existing_conn.options.merge(:skip_startup => true)) |
11 |
| - conn.write Vertica::Messages::CancelRequest.new(existing_conn.backend_pid, existing_conn.backend_key) |
12 |
| - conn.write Vertica::Messages::Flush.new |
13 |
| - conn.socket.close |
| 10 | + existing_conn.cancel |
14 | 11 | end
|
15 | 12 |
|
16 | 13 | # Opens a connectio the a Vertica server
|
@@ -92,6 +89,25 @@ def reset
|
92 | 89 | reset_values
|
93 | 90 | end
|
94 | 91 |
|
| 92 | + def cancel |
| 93 | + conn = self.class.new(options.merge(:skip_startup => true)) |
| 94 | + conn.write Vertica::Messages::CancelRequest.new(backend_pid, backend_key) |
| 95 | + conn.write Vertica::Messages::Flush.new |
| 96 | + conn.socket.close |
| 97 | + end |
| 98 | + |
| 99 | + def interrupt |
| 100 | + raise Vertica::Error::ConnectionError, "Session cannopt be interrupted because the session ID is not known!" if session_id.nil? |
| 101 | + conn = self.class.new(options.merge(:interruptable => false, :role => nil, :search_path => nil)) |
| 102 | + response = conn.query("SELECT CLOSE_SESSION(#{Vertica.quote(session_id)})").the_value |
| 103 | + conn.close |
| 104 | + return response |
| 105 | + end |
| 106 | + |
| 107 | + def interruptable? |
| 108 | + !session_id.nil? |
| 109 | + end |
| 110 | + |
95 | 111 | def read_message
|
96 | 112 | type = read_bytes(1)
|
97 | 113 | size = read_bytes(4).unpack('N').first
|
@@ -193,10 +209,12 @@ def startup_connection
|
193 | 209 | def initialize_connection
|
194 | 210 | query("SET SEARCH_PATH TO #{options[:search_path]}") if options[:search_path]
|
195 | 211 | query("SET ROLE #{options[:role]}") if options[:role]
|
| 212 | + @session_id = query("SELECT session_id FROM v_monitor.current_session").the_value if options[:interruptable] |
196 | 213 | end
|
197 | 214 |
|
198 | 215 | def reset_values
|
199 | 216 | @parameters = {}
|
| 217 | + @session_id = nil |
200 | 218 | @backend_pid = nil
|
201 | 219 | @backend_key = nil
|
202 | 220 | @transaction_status = nil
|
|
0 commit comments