-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_test.py
More file actions
74 lines (57 loc) · 2.23 KB
/
db_test.py
File metadata and controls
74 lines (57 loc) · 2.23 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import pyodbc
details = {
"user": "ute_limited",
"password": "REPLACE",
"server": "timemachine1sql.berea.edu",
"db": "UTE"
}
###########################
# Test pyodbc connection
###########################
pyodbc_uri = 'DRIVER=FreeTDS;SERVER={};PORT=1433;DATABASE={};UID={};PWD={};TDS_Version=7.4;'.format(details['server'],details['db'],details['user'],details['password'])
pyconn = pyodbc.connect(pyodbc_uri)
c = pyconn.cursor()
#for row in c.execute("select * from STUDATA where ID like '%B00815333%'"):
for row in c.execute("select * from STUPOSN"):
print("PYODBC:",row)
break
###########################
# Test SQL Alchemy with pyodbc
###########################
from urllib.parse import quote
import sqlalchemy
# SAWarning: No driver name specified; this is expected by PyODBC when using DSN-less connections
#uri = "mssql+pyodbc://{}:{}@{}/{}".format(details['user'], details['password'], details['server'], details['db'])
# No driver name specified
uri = "mssql+pyodbc:///?odbc_connect=" + quote('DRIVER=FreeTDS;SERVER={};PORT=1433;DATABASE={};UID={};PWD={};TDS_Version=7.4;'.format(details['server'], details['db'], details['user'], details['password']))
engine = sqlalchemy.create_engine(uri)
with engine.connect() as connection:
for row in connection.execute(sqlalchemy.text('select * from STUPOSN')):
print("SQLALCHEMY:",row)
break
###########################
# Test SQL Alchemy with app configuration
###########################
from app import app
from app.logic.tracy import Tracy
with app.test_request_context("/") as ctx:
if app.config['use_tracy']:
print("FLASK:",Tracy().getPositionFromCode("S01015"))
else:
print("FLASK: Config says not to use Tracy. Check your environment")
###########################
# Test Banner connection
###########################
from app.logic.banner import Banner
from app.models.formHistory import FormHistory
b = Banner()
if app.config['use_banner']:
if b.database_exists:
cursor = b.conn.cursor()
print("BANNER",cursor)
else:
print("BANNER: Error with database connection")
else:
print("BANNER: Config says not to use banner. Check your secret_config")
# NOT FOR PROD
#b.insert(FormHistory.get_by_id(39061))