1.1 --- a/imiptools/stores/database/common.py Tue May 23 16:31:27 2017 +0200
1.2 +++ b/imiptools/stores/database/common.py Tue May 23 16:34:09 2017 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 A database store of calendar data.
1.6
1.7 -Copyright (C) 2014, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -24,11 +24,13 @@
1.13 from datetime import datetime
1.14 from imiptools.data import parse_string, to_string
1.15 from imiptools.dates import format_datetime, get_datetime, to_timezone
1.16 -from imiptools.period import FreeBusyDatabaseCollection, \
1.17 - FreeBusyGroupDatabaseCollection, \
1.18 - FreeBusyOffersDatabaseCollection
1.19 +from imiptools.freebusy import FreeBusyDatabaseCollection, \
1.20 + FreeBusyGroupDatabaseCollection, \
1.21 + FreeBusyOffersDatabaseCollection
1.22 from imiptools.sql import DatabaseOperations
1.23
1.24 +def first(l): return l[0]
1.25 +
1.26 class DatabaseStoreBase(DatabaseOperations):
1.27
1.28 "A database store supporting user-specific locking."
1.29 @@ -56,6 +58,15 @@
1.30 "freebusy_provider_datetimes" : self.freebusy_provider_datetimes_table,
1.31 }
1.32
1.33 + def get_single_values(self):
1.34 +
1.35 + """
1.36 + Return the cursor results as a list of single values from each of the
1.37 + result tuples.
1.38 + """
1.39 +
1.40 + return map(first, self.cursor.fetchall())
1.41 +
1.42 class DatabaseStore(DatabaseStoreBase, StoreBase):
1.43
1.44 "A database store of tabular free/busy data and objects."
1.45 @@ -79,7 +90,7 @@
1.46 "union all select store_user from %(recurrences)s" \
1.47 ") as users")
1.48 self.cursor.execute(query)
1.49 - return [r[0] for r in self.cursor.fetchall()]
1.50 + return self.get_single_values()
1.51
1.52 # Event and event metadata access.
1.53
1.54 @@ -119,7 +130,7 @@
1.55 columns, values)
1.56
1.57 self.cursor.execute(query, values)
1.58 - return [r[0] for r in self.cursor.fetchall()]
1.59 + return self.get_single_values()
1.60
1.61 def get_cancelled_events(self, user):
1.62
1.63 @@ -505,7 +516,7 @@
1.64 columns, values)
1.65
1.66 self.cursor.execute(query, values)
1.67 - return [r[0] for r in self.cursor.fetchall()]
1.68 + return self.get_single_values()
1.69
1.70 # Tentative free/busy periods related to countering.
1.71
1.72 @@ -641,7 +652,7 @@
1.73 columns, values)
1.74
1.75 self.cursor.execute(query, values)
1.76 - return [r[0] for r in self.cursor.fetchall()]
1.77 + return self.get_single_values()
1.78
1.79 def get_counter(self, user, other, uid, recurrenceid=None):
1.80
1.81 @@ -852,7 +863,7 @@
1.82 "union all select quota from quota_limits" \
1.83 ") as quotas")
1.84 self.cursor.execute(query)
1.85 - return [r[0] for r in self.cursor.fetchall()]
1.86 + return self.get_single_values()
1.87
1.88 def get_quota_users(self, quota):
1.89
1.90 @@ -869,7 +880,7 @@
1.91 columns, values)
1.92
1.93 self.cursor.execute(query, values)
1.94 - return [r[0] for r in self.cursor.fetchall()]
1.95 + return self.get_single_values()
1.96
1.97 # Delegate information for the quota.
1.98
1.99 @@ -885,7 +896,7 @@
1.100 columns, values)
1.101
1.102 self.cursor.execute(query, values)
1.103 - return [r[0] for r in self.cursor.fetchall()]
1.104 + return self.get_single_values()
1.105
1.106 def set_delegates(self, quota, delegates):
1.107