#!/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 actions import * def initDB(self): conn = sqlite.connect('scheduler.db') curs = conn.cursor() return curs, conn def initNewDB(self): cursor, conn = initDB() initAssignmentDB(cursor) initReadingDB(cursor) initScheduleDB(cursor) initBookDB(cursor) initCourseDB(cursor) exitDB(conn) def initAssignmentDB(self, cursor): cursor.execute(''' CREATE TABLE Assignment ( aid INTEGER PRIMARY KEY, date TEXT, description TEXT, available BOOLEAN, begun BOOLEAN, finished BOOLEAN, delivered BOOLEAN ) ''') def initReadingDB(self, cursor): cursor.execute(''' CREATE TABLE Reading ( rid INTEGER PRIMARY KEY, week TEXT, chapter TEXT, pages TEXT ) ''') def initScheduleDB(self, cursor): cursor.execute(''' CREATE TABLE Lesson ( lid INTEGER PRIMARY KEY, day TEXT, fromtime TEXT, totime TEXT, type TEXT, room TEXT ) ''') def initBookDB(self, cursor): cursor.execute(''' CREATE TABLE Book ( isbn TEXT PRIMARY KEY, title TEXT, author TEXT, edition INTEGER ) ''') def initCourseDB(self, cursor): cursor.execute(''' CREATE TABLE Course ( code TEXT PRIMARY KEY, title TEXT, short TEXT ) ''') def initAssignmentInCourse(self, cursor): cursor.execute(''' CREATE TABLE assignmentInCourse ( assignment INTEGER, course INTEGER ) ''') def initReadingInCourse(self, cursor): cursor.execute(''' CREATE TABLE readingInCourse ( reading INTEGER, course INTEGER ) ''') def initLessonInCourse(self, cursor): cursor.execute(''' CREATE TABLE lessonInCourse ( lesson INTEGER, course INTEGER ) ''') def initCourseUsesBook(self, cursor): cursor.execute(''' CREATE TABLE courseUsesBook ( course INTEGER, book TEXT ) ''') def addNewBook(self, 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(self, code, title, short): cursor, conn = initDB() courseQuery = ''' INSERT INTO Course VALUES (%s, %s, %s) ''' % (code, title, short) cursor.execute(courseQuery) exitDB(conn) def exitDB(self, conn): conn.commit() conn.close() initNewDB()