Move helpers.select_generator to PDB.sql_select.

master
voussoir 2018-03-25 16:32:17 -07:00
parent cfa5d269d1
commit cca8837863
3 changed files with 17 additions and 18 deletions

View File

@ -343,19 +343,6 @@ def seconds_to_hms(seconds):
hms = ':'.join('%02d' % part for part in parts)
return hms
def select_generator(sql, query, bindings=None):
'''
Perform the query, and yield the results.
'''
bindings = bindings or []
cursor = sql.cursor()
cursor.execute(query, bindings)
while True:
fetch = cursor.fetchone()
if fetch is None:
break
yield fetch
def sql_listify(items):
'''
Given a list of strings, return a string in the form of an SQL list.

View File

@ -448,8 +448,7 @@ class Album(ObjectBase, GroupableMixin):
def get_photos(self):
photos = []
generator = helpers.select_generator(
self.photodb.sql,
generator = self.photodb.sql_select(
'SELECT photoid FROM album_photo_rel WHERE albumid == ?',
[self.id]
)
@ -874,8 +873,7 @@ class Photo(ObjectBase):
'''
Return the tags assigned to this Photo.
'''
generator = helpers.select_generator(
self.photodb.sql,
generator = self.photodb.sql_select(
'SELECT tagid FROM photo_tag_rel WHERE photoid == ?',
[self.id]
)

View File

@ -632,7 +632,7 @@ class PDBPhotoMixin:
#cur = self.sql.cursor()
#cur.execute('EXPLAIN QUERY PLAN ' + query, bindings)
#print('\n'.join(str(x) for x in cur.fetchall()))
generator = helpers.select_generator(self.sql, query, bindings)
generator = self.sql_select(query, bindings)
photos_received = 0
for row in generator:
photo = objects.Photo(self, row)
@ -758,6 +758,20 @@ class PDBSQLMixin:
if commit:
self.commit()
def sql_select(self, query, bindings=None):
cur = self.sql.cursor()
cur.execute(query, bindings)
while True:
fetch = cur.fetchone()
if fetch is None:
break
yield fetch
def sql_select_one(self, query, bindings=None):
cur = self.sql.cursor()
cur.execute(query, bindings)
return cur.fetchone()
def sql_update(self, table, pairs, where_key, *, commit=False):
cur = self.sql.cursor()