From 0d84d59ca2f3646d32aa31c8fe24beab3de911da Mon Sep 17 00:00:00 2001 From: tirilane Date: Thu, 19 Jun 2008 14:25:51 +0000 Subject: [PATCH] Now the database is made if necessary, not manually. Should be done a long time ago. --- egon.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/egon.py b/egon.py index f9f0ad5..b16eb85 100755 --- a/egon.py +++ b/egon.py @@ -18,7 +18,7 @@ from pysqlite2 import dbapi2 as sqlite from qrc_resources import * -__version__ = "1.0.0" +__version__ = "1.0.1" main = None @@ -1520,19 +1520,25 @@ class BookModel(): ## Connect to the database and return the cursor and connection def initDB(): conn = sqlite.connect('egon.db') - curs = conn.cursor() - return curs, conn + cursor = conn.cursor() + + cursor.execute(''' + SELECT name FROM sqlite_master + WHERE type='table' + ORDER BY name + ''') + + if cursor.fetchall() == []: + initSemesterDB(cursor) + initAssignmentDB(cursor) + initReadingDB(cursor) + initScheduleDB(cursor) + initBookDB(cursor) + initCourseDB(cursor) + initCourseUsesBook(cursor) + + return cursor, conn -## Initialize the tables -def initNewDB(): - cursor, conn = initDB() - initSemesterDB(cursor) - initAssignmentDB(cursor) - initReadingDB(cursor) - initScheduleDB(cursor) - initBookDB(cursor) - initCourseDB(cursor) - initCourseUsesBook(cursor) exitDB(conn) # Create the database