-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
53 lines (41 loc) · 1.8 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import iris
import pyodbc
# Get connection details from config file
def get_connection_info(file_name: str) -> dict:
# Initial empty dictionary to store connection details
connections = {}
# Open config file to get connection info
with open(file_name) as f:
lines = f.readlines()
for line in lines:
# remove all white space (space, tab, new line)
line = ''.join(line.split())
# get connection info
connection_param, connection_value = line.split(":")
connections[connection_param] = connection_value
return connections
def run() -> None:
# Retrieve connection information from configuration file
connection_detail = get_connection_info("connection.config")
ip = connection_detail["ip"]
port = int(connection_detail["port"])
namespace = connection_detail["namespace"]
username = connection_detail["username"]
password = connection_detail["password"]
driver = "{InterSystems IRIS ODBC35}"
# Create connection to InterSystems IRIS using native API
connection = iris.connect(ip, port, namespace, username, password)
print("Connected to InterSystems IRIS using Native API")
# Create connection to InterSystems IRIS using pyodbc
connection_string = 'DRIVER={};SERVER={};PORT={};DATABASE={};UID={};PWD={}' \
.format(driver, ip, port, namespace, username, password)
connection_pyodbc = pyodbc.connect(connection_string)
connection_pyodbc.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
connection_pyodbc.setencoding(encoding='utf-8')
print("Connected to InterSystems IRIS using pyodbc")
# Create an iris object
iris_obj = iris.createIRIS(connection)
if __name__ == '__main__':
run()
with open("./SQL.py") as SQLFile:
exec(SQLFile.read())