#!/usr/bin/env python #coding: utf-8 import os import platform import sys from pysqlite2 import dbapi2 as sqlite from PyQt4.QtCore import * from PyQt4.QtGui import * #from PyQt4.QtSql import * from main import * from assignment import * from reading import * from schedule import * from calendar import * from book import * from course import * def initDB(): conn = sqlite.connect('egon.db') curs = conn.cursor() return curs, conn def initNewDB(): cursor, conn = initDB() initAssignmentDB(cursor) initReadingDB(cursor) initScheduleDB(cursor) initBookDB(cursor) initCourseDB(cursor) exitDB(conn) def initAssignmentDB(cursor): cursor.execute(''' CREATE TABLE Assignment ( aid INTEGER PRIMARY KEY, date TEXT, description TEXT, available BOOLEAN, begun BOOLEAN, finished BOOLEAN, delivered BOOLEAN ) ''') def initReadingDB(cursor): cursor.execute(''' CREATE TABLE Reading ( rid INTEGER PRIMARY KEY, week TEXT, chapter TEXT, pages TEXT ) ''') def initScheduleDB(cursor): cursor.execute(''' CREATE TABLE Lesson ( lid INTEGER PRIMARY KEY, day TEXT, fromtime TEXT, totime TEXT, type TEXT, room TEXT ) ''') def initBookDB(cursor): cursor.execute(''' CREATE TABLE Book ( isbn TEXT PRIMARY KEY, title TEXT, author TEXT, edition INTEGER ) ''') def initCourseDB(cursor): cursor.execute(''' CREATE TABLE Course ( code TEXT PRIMARY KEY, title TEXT, short TEXT ) ''') def initAssignmentInCourse(cursor): cursor.execute(''' CREATE TABLE assignmentInCourse ( assignment INTEGER, course INTEGER ) ''') def initReadingInCourse(cursor): cursor.execute(''' CREATE TABLE readingInCourse ( reading INTEGER, course INTEGER ) ''') def initLessonInCourse(cursor): cursor.execute(''' CREATE TABLE lessonInCourse ( lesson INTEGER, course INTEGER ) ''') def initCourseUsesBook(cursor): cursor.execute(''' CREATE TABLE courseUsesBook ( course INTEGER, book TEXT ) ''') def addNewBook(isbn, title, author, edition, course): cursor, conn = initDB() bookQuery = ''' INSERT INTO Book VALUES (%s, %s, %s, %i) ''' % (isbn, title, author, edition) courseUsesBookQuery = ''' INSERT INTO courseUsesBook VALUES (%i, %s) ''' % (course, isbn) cursor.execute(bookQuery) cursor.execute(courseUsesBookQuery) exitDB(conn) def addNewCourse(code, title, short): cursor, conn = initDB() courseQuery = ''' INSERT INTO Course VALUES (%s, %s, %s) ''' % (code, title, short) cursor.execute(courseQuery) exitDB(conn) def exitDB(conn): conn.commit() conn.close() initNewDB()