~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/db.py

  • Committer: William Grant
  • Date: 2009-01-20 00:12:35 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: grantw@unimelb.edu.au-20090120001235-6m2qebmtpylpzsvn
ivle.db.{get_all,delete}: Kill. Unused.

Show diffs side-by-side

added added

removed removed

Lines of Context:
259
259
        if dry: return query
260
260
        self.db.query(query)
261
261
 
262
 
    def delete(self, primarydict, tablename, primary_keys, dry=False):
263
 
        """Deletes a row in the table, matching against primarydict to find
264
 
        the row.
265
 
        primarydict, tablename, primary_keys: See update.
266
 
        """
267
 
        if not DB.check_dict(primarydict, primary_keys, must=True):
268
 
            raise DBException("Supplied dictionary contains invalid or missing fields (2).")
269
 
        wherelist = []
270
 
        for k,v in primarydict.items():
271
 
            wherelist.append("%s = %s" % (k, _escape(v)))
272
 
        if len(wherelist) == 0:
273
 
            return
274
 
        wherestring = ' AND '.join(wherelist)
275
 
        query = ("DELETE FROM %s WHERE %s;" % (tablename, wherestring))
276
 
        if dry: return query
277
 
        self.db.query(query)
278
 
 
279
262
    def get_single(self, primarydict, tablename, getfields, primary_keys,
280
263
        error_notfound="No rows found", dry=False):
281
264
        """Retrieves a single row from a table, returning it as a dictionary
312
295
        # Return as a dictionary
313
296
        return result.dictresult()[0]
314
297
 
315
 
    def get_all(self, tablename, getfields, dry=False):
316
 
        """Retrieves all rows from a table, returning it as a list of
317
 
        dictionaries mapping field names to values.
318
 
        tablename, getfields: See get_single.
319
 
        """
320
 
        if len(getfields) == 0:
321
 
            return
322
 
        getstring = ', '.join(getfields)
323
 
        query = ("SELECT %s FROM %s;" % (getstring, tablename))
324
 
        if dry: return query
325
 
        return self.db.query(query).dictresult()
326
 
 
327
298
    def start_transaction(self, dry=False):
328
299
        """Starts a DB transaction.
329
300
        Will not commit any changes until self.commit() is called.