-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconnect.py
More file actions
53 lines (43 loc) · 1.18 KB
/
connect.py
File metadata and controls
53 lines (43 loc) · 1.18 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
#auto call horses
import psycopg2
import psycopg2.extras
#ensures unicode output
import psycopg2.extensions
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
import re
import settings
import pprint
from datetime import datetime
from re import sub
from sqlalchemy.engine.url import URL
def _sanitycheck(val):
if type(val) == 'list':
return val[0] is not None
else:
return val is not None
#to expand
def makewhere(s):
return str(s)
def makeselect(*args):
assert _sanitycheck(args)
s = " ".join(args)
return s
def _getbasiccolnames():
return "ra.racenumber, ru.horsenumber, h.code, h.name "
def _getextendedcolnames():
return "ra.racenumber,ru.horsenumber "
########CONNECTION
def connect():
conn_string = "host='localhost' dbname='hkraces100' user='vmac' password=''"
conn = psycopg2.connect(conn_string)
# c1= conn.cursor()
c1= conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
# print conn.dsn
return conn,c1
def connectnocursor():
conn_string = "host='localhost' dbname='hkraces100' user='vmac' password=''"
conn = psycopg2.connect(conn_string)
return conn
def teardown(conn):
conn.close()