diff -r 81fd6e40a6a8 -r 52f5831400b2 dataimport.py --- a/dataimport.py Fri Apr 08 09:02:55 2011 +0200 +++ b/dataimport.py Mon Apr 11 13:28:59 2011 +0200 @@ -147,13 +147,16 @@ for row in reader: yield dict(zip(header, row)) -def lazydbtable(cu, table, headers): +def lazydbtable(cu, table, headers, orderby=None): """return an iterator on rows of a sql table. On each row, fetch columns defined in headers and return values as a dictionary. >>> data = lazydbtable(cu, 'experimentation', ('id', 'nickname', 'gps')) """ - cu.execute('SELECT %s FROM %s' % (','.join(headers), table,)) + sql = 'SELECT %s FROM %s' % (','.join(headers), table,) + if orderby: + sql += ' ORDER BY %s' % ','.join(orderby) + cu.execute(sql) while True: row = cu.fetchone() if row is None: