c.execute("SELECT dvr FROM dvrtable WHERE id=?", (id,))
return c.fetchone()[0]
+ def query(self, wherestmt):
+ """Query database with given where statement. Return a list od IDs."""
+ stmt = "SELECT DISTINCT dvrtable.id FROM dvrtable, registrations, purposes"
+ stmt += " WHERE dvrtable.id=registrations.dvrid AND dvrtable.id=purposes.dvrid"
+ stmt += " AND " + wherestmt
+
+ c = self.conn.cursor()
+ c.execute(stmt)
+ rows = c.fetchall()
+ return [r[0] for r in rows]
+
def add_dvr(self, id, dvr=None):
""""Add a DVR with given ID to the dataset"""
c = self.conn.cursor()
a directory, read all files ending with ".html" or ".html.gz".
-d FILE Use given sqlite3 database.
-h Print this help text.
- -q ID Query dataset for dataset of given ID. Exit status is 1 in case
- that no such dataset exists and 0 on success.
+ -q COND Query for datasets where the given WHERE SQL-condition holds.
-g Query geographical location for address field of registration.
""")
print(e, file=sys.stderr)
return None
-def processQuery(db, id, showLocation=False):
- """Process query for given ID."""
+
+def printDataset(db, id):
+ """Print info for a dataset of given ID."""
if not db.contains_id(id):
- print("No such ID in the database.")
+ print("No ID %d in the database." % id)
return False
print("ID %d found in the database." % id)
return True
+def processQuery(db, query, showLocation=False):
+ """Process query for given ID."""
+
+ ids = db.query(query)
+ print("Found %d results." % len(ids))
+
+ for id in ids:
+ printDataset(db, id)
+
+
def processAdd(db, source):
"""Read data from source, parse data, and add to database."""
elif opt == "-g":
showLocation = True
elif opt == "-q":
- query = int(arg)
+ query = arg
else:
print("Unknown option '", opt, "'.", file=sys.stderr)
assert(False)