-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_test.py
70 lines (52 loc) · 2.25 KB
/
db_test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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=8.0;'.format(details['server'],details['db'],details['user'],details['password'])
pyconn = pyodbc.connect(pyodbc_uri)
c = pyconn.cursor()
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://{}:{}@{}/{}?DRIVER=FreeTDS".format(details['user'], details['password'], details['server'], details['db'])
uri = "mssql+pyodbc:///?odbc_connect=" + quote('DRIVER=FreeTDS;SERVER={};PORT=1433;DATABASE={};UID={};PWD={};TDS_Version=8.0;'.format(details['server'], details['db'], details['user'], details['password']))
engine = sqlalchemy.create_engine(uri)
for row in engine.execute('select * from STUPOSN'):
print("SQLALCHEMY:",row)
break
###########################
# Test SQL Alchemy with app configuration
###########################
from flask_sqlalchemy import SQLAlchemy
from app import load_config, app
from app.logic.tracy import Tracy
cfg = load_config('app/config/secret_config.yaml')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
uri = "mssql+pyodbc:///?odbc_connect=" + quote('DRIVER=FreeTDS;SERVER={};PORT=1433;DATABASE={};UID={};PWD={};TDS_Version=8.0;'.format(details['server'], details['db'], details['user'], details['password']))
app.config['SQLALCHEMY_DATABASE_URI'] = uri
db = SQLAlchemy(app)
print("FLASK:",Tracy().getPositionFromCode("S01015"))
###########################
# Test Banner connection
###########################
from app.logic.banner import Banner
from app.models.formHistory import FormHistory
b = Banner()
cursor = b.conn.cursor()
print(cursor)
# NOT FOR PROD
# b.insert(FormHistory.get_by_id(39061))