-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_test.py
51 lines (38 loc) · 1.85 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
import pyodbc
details = {
"user": "ute_limited",
"password": "REPLACE",
"server": "timemachine1sql.berea.edu",
"db": "UTE"
}
# works
pyodbc_uri = 'DRIVER=FreeTDS;SERVER={};PORT=1433;DATABASE={};UID={};PWD={};TDS_Version=8.0;'.format(details['server'],details['db'],details['user'],details['password'])
# works
#pyodbc_uri = 'DRIVER=FreeTDS;DSN=tracyDSN;UID={};PWD={};'.format(details['user'], details['password'])
pyconn = pyodbc.connect(pyodbc_uri)
c = pyconn.cursor()
for row in c.execute('select * from STUPOSN'):
print("PYODBC:",row)
break
##########
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
##########
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"))