diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2014-10-01 09:42:24 -0400 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2014-10-01 09:42:24 -0400 |
commit | 12be3e0468a6dab819738d4bd863ea98867589fe (patch) | |
tree | c4237b43abfbd65599a2e7c9f0ee9f49655ec47c | |
parent | d1197d085df8318010797039ead3df86c4b1849f (diff) |
simplify design point fetch queries
-rwxr-xr-x | rtss14/database.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/rtss14/database.py b/rtss14/database.py index 6028e3a..0f9a917 100755 --- a/rtss14/database.py +++ b/rtss14/database.py | |||
@@ -351,22 +351,20 @@ def __get_design_points(conn, ndp): | |||
351 | #################### | 351 | #################### |
352 | try: | 352 | try: |
353 | begin_sync(conn, c) | 353 | begin_sync(conn, c) |
354 | c.execute('SELECT id FROM dp_pending WHERE taken=0 LIMIT %s FOR UPDATE', (ndp,)) | 354 | c.execute('SELECT id,%s FROM dp_pending WHERE taken=0 LIMIT %%s FOR UPDATE' % ','.join(dp_col_names), (ndp,)) |
355 | dp_ids = [d['id'] for d in c.fetchall()] | 355 | rows = c.fetchall() |
356 | nfetched = len(dp_ids) if dp_ids else 0 | 356 | nfetched = c.rowcount |
357 | if nfetched > 0: | 357 | if nfetched > 0: |
358 | dp_ids = [r['id'] for r in rows] | ||
358 | c.execute('UPDATE dp_pending SET taken=1 WHERE id IN (%s)' % ','.join(['%s']*len(dp_ids)), tuple(dp_ids)) | 359 | c.execute('UPDATE dp_pending SET taken=1 WHERE id IN (%s)' % ','.join(['%s']*len(dp_ids)), tuple(dp_ids)) |
359 | end_sync(conn) | 360 | end_sync(conn) |
361 | fetched = [dp_to_dp(r) for r in rows] | ||
360 | except db.OperationalError, e: | 362 | except db.OperationalError, e: |
361 | print e | 363 | print e |
362 | print 'Last Query: %s' % c._last_executed | 364 | print 'Last Query: %s' % c._last_executed |
363 | rollback(conn) | 365 | rollback(conn) |
364 | c.close() | 366 | c.close() |
365 | raise e | 367 | raise e |
366 | #################### | ||
367 | if nfetched > 0: | ||
368 | c.execute('SELECT %s FROM dp_pending WHERE id IN (%s)' % (','.join(dp_col_names), ','.join(['%s']*len(dp_ids))), tuple(dp_ids)) | ||
369 | fetched = [db_to_dp(d) for d in c.fetchall()] | ||
370 | c.close() | 368 | c.close() |
371 | return fetched | 369 | return fetched |
372 | 370 | ||