diff --git a/Chap6/sqlite_test/test b/Chap6/sqlite_test/test index 13b667a..0b6a402 100644 Binary files a/Chap6/sqlite_test/test and b/Chap6/sqlite_test/test differ diff --git a/Chap6/ushuffle_dbU.py b/Chap6/ushuffle_dbU.py index ddb5534..43fcfdc 100644 --- a/Chap6/ushuffle_dbU.py +++ b/Chap6/ushuffle_dbU.py @@ -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 diff --git a/Chap6/ushuffle_sad.py b/Chap6/ushuffle_sad.py index 328fe46..f3e49ac 100644 --- a/Chap6/ushuffle_sad.py +++ b/Chap6/ushuffle_sad.py @@ -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() @@ -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()