Class: DbQueryHelper::Connection::Connector

Inherits:
Object
  • Object
show all
Defined in:
lib/classes/connector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Connector

Returns a new instance of Connector.



6
7
8
9
# File 'lib/classes/connector.rb', line 6

def initialize(params = {})
  @query = nil
  connect_to(params)  
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/classes/connector.rb', line 4

def client
  @client
end

#queryObject (readonly)

Returns the value of attribute query.



4
5
6
# File 'lib/classes/connector.rb', line 4

def query
  @query
end

Instance Method Details

#connect_to(params) ⇒ Object



15
16
17
18
# File 'lib/classes/connector.rb', line 15

def connect_to(params)
  @client = TinyTds::Client.new(params)
  raise "Connection::TinyTds::UnableToConnect" unless @client.active?
end

#disconnectObject



25
26
27
# File 'lib/classes/connector.rb', line 25

def disconnect
  @client.close
end

#execute_queryObject



20
21
22
23
# File 'lib/classes/connector.rb', line 20

def execute_query
  raise "Connection::TinyTds::CannotExecuteNilQuery" if @query.nil?
  @client.execute(query)
end

#set_new_query(new_query) ⇒ Object



11
12
13
# File 'lib/classes/connector.rb', line 11

def set_new_query(new_query)
  @query = new_query
end