Class: MSSQLImporterCommon

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

Class Method Summary collapse

Class Method Details

.connectObject


24
25
26
27
28
29
30
31
32
33
# File 'lib/mssql_importer_common.rb', line 24

def self.connect
  conn = {
    username: Settings.ns('mssql_connector').username,
    password: Settings.ns('mssql_connector').password,
    host: Settings.ns('mssql_connector').host,
    port: Settings.ns('mssql_connector').port,
    database: Settings.ns('mssql_connector').database,
  }
  @client = TinyTds::Client.new conn
end

.get_all_recordsObject

“Retrieves all records from the reading table.”


15
16
17
18
19
20
21
22
# File 'lib/mssql_importer_common.rb', line 15

def self.get_all_records
  connect
  # Read all employees
  puts "Reading data from table"
  @client.execute("SELECT * FROM #{Settings.ns('mssql_connector').table_read}").each do |row|
    puts row
  end
end

.ping_mssql_serverObject

“Just tests connection to the DB configured in Settings.”


5
6
7
8
9
10
11
12
# File 'lib/mssql_importer_common.rb', line 5

def self.ping_mssql_server
  connect
  puts 'Connecting to SQL Server'

  if @client.active? == true then puts 'Done' end

  @client.close
end