)")
c.execute("CREATE TABLE IF NOT EXISTS registrations (\
- id INTEGER PRIMARY KEY \
+ dvrid INTEGER PRIMARY KEY \
REFERENCES dvrtable(id) ON DELETE CASCADE, \
name TEXT NOT NULL, \
address TEXT NOT NULL \
)")
c.execute("CREATE TABLE IF NOT EXISTS purposes (\
- id INTEGER REFERENCES dvrtable(id) ON DELETE CASCADE, \
- num INTEGER, \
+ id INTEGER PRIMARY KEY AUTOINCREMENT, \
+ dvrid INTEGER REFERENCES dvrtable(id) ON DELETE CASCADE, \
+ num INTEGER NOT NULL, \
purpose TEXT NOT NULL, \
date TEXT NOT NULL, \
- status TEXT NOT NULL, \
- PRIMARY KEY(id, num) \
+ status TEXT NOT NULL \
)")
+
+ c.execute("CREATE INDEX IF NOT EXISTS purposes_dvrid ON purposes (dvrid)")
+
c.close()
conn.commit()
c.close()
self.conn.commit()
- def get_registration(self, id):
- """Return the registration of given ID, if any."""
+ def get_registration(self, dvrid):
+ """Return the registration of given DVR-ID, if any."""
c = self.conn.cursor()
- c.execute("SELECT * FROM registrations WHERE id=?", (id,))
+ c.execute("SELECT * FROM registrations WHERE dvrid=?", (dvrid,))
return c.fetchone()
- def add_registration(self, id, name, address):
- """Add a registration for the given ID."""
+ def add_registration(self, dvrid, name, address):
+ """Add a registration for the given DVR-ID."""
c = self.conn.cursor()
c.execute("INSERT INTO registrations VALUES (?, ?, ?)",
- (id, name, address))
+ (dvrid, name, address))
c.close()
self.conn.commit()
- def get_purposes(self, id):
- """Return all known purposes of given ID, if any."""
+ def get_purposes(self, dvrid):
+ """Return all known purposes of given DVR-ID, if any."""
c = self.conn.cursor()
- c.execute("SELECT * FROM purposes WHERE id=?", (id,))
+ c.execute("SELECT * FROM purposes WHERE dvrid=?", (dvrid,))
return c.fetchall()
- def add_purpose(self, id, num, purpose, date, status):
- """Add a purpose for a given ID."""
+ def add_purpose(self, dvrid, num, purpose, date, status):
+ """Add a purpose for a given DVR-ID."""
c = self.conn.cursor()
- c.execute("INSERT INTO purposes VALUES (?, ?, ?, ?, ?)",
- (id, num, purpose, date, status))
+ c.execute("INSERT INTO purposes (dvrid, num, purpose, date, status) \
+ VALUES (?, ?, ?, ?, ?)",
+ (dvrid, num, purpose, date, status))
c.close()
self.conn.commit()
print(" No purposes known.")
else:
for purp in purposes:
- print(" Purpose %d:" % purp[1])
- print(" Text: ", purp[2])
- print(" Date: ", purp[3])
- print(" Status:", purp[4])
+ print(" Purpose %d:" % purp[2])
+ print(" Text: ", purp[3])
+ print(" Date: ", purp[4])
+ print(" Status:", purp[5])
return True