-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQLconnector.py
39 lines (31 loc) · 1.03 KB
/
SQLconnector.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
#import pyodbc
import psycopg2
counter = 0
conn = None
def connectToSource():
global conn
global counter
if counter <= 0:
conn = psycopg2.connect(host='127.0.0.1',port=5432 ,user='LaserScraper', password='LaserScraper', database = 'LaserScraper')
conn.set_session(autocommit = True)
else:
try:
cursor = conn.cursor()
except:
print("It's closed but the Counter is %s" % (counter,))
counter = 0
return connectToSource()
#conn = psycopg2.connect(host='localhost',port=5432 ,user='LaserScraper', password='LaserScraper', database = 'LaserScraper')
#conn = pyodbc.connect('Driver={SQL Server}; Server=CTRI-DESKTOP\SQLEXPRESS; Database=LaserScraper; Trusted_Connection=yes;')
counter = counter + 1
return conn
def closeConnection():
global conn
global counter
counter = counter - 1
if counter <= 0:
conn.close()
def execute():
result = {}
return result
#SQL = databaseSetup.read()