""" Module: CDdatabase Purpose: Read and write CD Database. """ __author__ = 'distatica' __version__ = '0.0.1' import sqlite3 class CDdatabase: def __init__(self, dbFile='default.db', dbType='sqlite'): """ sqlite is the only current dbType, this value is optional dbFile is the database file to write to. """ if dbType == 'sqlite': self.conn = sqlite3.connect(dbFile) self.c = self.conn.cursor() # here we should definitely create the table if it does not exist def add_cd(self, cdid, title, notes, tags): """ Adds a new CD to the database. cdid is the index matching the files contained in 'files' table to each CD. """ q = (cdid, title, notes, tags,) self.c.execute('insert into disks values (?,?,?,?)', q) def add_file(self, cdid, afile, ext, afilter): """ Writes a file to the 'files' table, using cdid as the index. """ q = (cdid, afile, ext, afilter) self.c.execute('insert into files values (?,?,?,?)', q) def setup_db(self): """ Setup tables in database """ self.c.execute('''create table disks (cdid real, notes text, tags text, title text)''') self.c.execute('''create table files (cdid real, file text, ext text, filter text)''') new = CDdatabase() # new.setup_db() new.add_cd(1, 'SOME_DISK', 'Scratched', 'dvd,video')