Skip to content

Commit

Permalink
Fix #80.
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Jan 15, 2015
1 parent 528c480 commit 7d7ec7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions nfldb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,14 @@ def _sql_where(self, cursor, aliases=None, aggregate=False):
field = self.entity._sql_field(self.column, aliases=aliases)
if aggregate:
field = 'SUM(%s)' % field
paramed = '%s %s %s' % (field, self.operator, '%s')
if isinstance(self.value, tuple) or isinstance(self.value, list):
paramed = paramed % 'ANY (%s)'
self.value = list(self.value) # Coerce tuples to pg ARRAYs...
return cursor.mogrify(paramed, (self.value,))
assert self.operator == '=', \
'Disjunctions must use "=" for column "%s"' % field
vals = [cursor.mogrify('%s', (v,)) for v in self.value]
return '%s IN (%s)' % (field, ', '.join(vals))
else:
paramed = '%s %s %s' % (field, self.operator, '%s')
return cursor.mogrify(paramed, (self.value,))


def QueryOR(db):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def test_drives_from_player(qgame):
assert len(qgame.as_drives()) == 15


def test_player_position_disjunction(q):
players = q.player(position=['QB', 'RB', 'WR']).limit(1).as_players()
assert len(players) == 1


def test_longest_pass_player(q):
q.sort('passing_yds').limit(1)
assert q.as_play_players()[0].player.full_name == 'Brandon Weeden'
Expand Down

0 comments on commit 7d7ec7d

Please sign in to comment.