Skip to content

Commit

Permalink
Complete Exercise 6-15: Supporting Different RDBMSs
Browse files Browse the repository at this point in the history
  • Loading branch information
schedutron committed Nov 7, 2017
1 parent 1bd68c2 commit 35c4331
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Binary file modified Chap6/sqlite_test/test
Binary file not shown.
2 changes: 1 addition & 1 deletion Chap6/ushuffle_dbU.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

COLSIZ = 10
FIELDS = ('login', 'userid', 'projid')
RDBMSs = {'s': 'sqlite', 'm': 'mysql', 'g': 'gadfly'}
RDBMSs = {'s': 'sqlite', 'm': 'mysql', 'g': 'gadfly', 'p': 'postgresql'}
DBNAME = 'test'
DBUSER = 'root'
DB_EXC = None
Expand Down
18 changes: 17 additions & 1 deletion Chap6/ushuffle_sad.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from sqlalchemy.ext.declarative import declarative_base

from password import PASSWORD
from ushuffle_dbU import DBNAME, NAMELEN, randName, FIELDS, tformat, cformat, setup
from ushuffle_dbU import DBNAME, NAMELEN, randName, FIELDS, tformat, cformat,\
RDBMSs, scanf

DSNs = {
'mysql': 'mysql://root@localhost/%s/%s' % (DBNAME, PASSWORD),
'sqlite': 'sqlite:///:memory:',
'postgresql': 'postgresql+psycopg2://binaryBoy:%s@localhost/%s' % (PASSWORD, DBNAME)
}

Base = declarative_base()
Expand Down Expand Up @@ -84,6 +86,20 @@ def __getattr__(self, attr):
def finish(self):
self.ses.connection().close()


def setup():
return RDBMSs[scanf(
'''
Choose a database system:
(M)ySQL
(G)adfly
(S)QLite
(P)ostgreSQL
Enter choice: ''').strip().lower()[0]]


def main():
printf("*** Connect to %r database" % DBNAME)
db = setup()
Expand Down

0 comments on commit 35c4331

Please sign in to comment.