1.1 --- a/imiptools/period.py Sun Mar 06 19:22:43 2016 +0100
1.2 +++ b/imiptools/period.py Sun Mar 06 19:23:39 2016 +0100
1.3 @@ -866,10 +866,7 @@
1.4 # List emulation methods.
1.5
1.6 def __nonzero__(self):
1.7 - query = "select count(*) from %(table)s" % {"table" : self.table_name}
1.8 - self.cursor.execute(query)
1.9 - result = self.cursor.fetchone()
1.10 - return result[0]
1.11 + return len(self) and True or False
1.12
1.13 def __iter__(self):
1.14 query = "select * from %(table)s" % {"table" : self.table_name}
1.15 @@ -877,7 +874,10 @@
1.16 return iter(map(lambda t: FreeBusyPeriod(*t), self.cursor.fetchall()))
1.17
1.18 def __len__(self):
1.19 - return len(list(iter(self)))
1.20 + query = "select count(*) from %(table)s" % {"table" : self.table_name}
1.21 + self.cursor.execute(query)
1.22 + result = self.cursor.fetchone()
1.23 + return result and result[0] or 0
1.24
1.25 def __getitem__(self, i):
1.26 return list(iter(self))[i]
1.27 @@ -907,7 +907,8 @@
1.28 values = period.as_tuple(strings_only=True)
1.29 query = """\
1.30 delete from %(table)s
1.31 -where start = ? and end = ? and uid = ? and transp = ? and recurrenceid = ? and summary = ? and organiser = ? and expires = ?
1.32 +where start = ? and end = ? and uid = ? and transp = ? and recurrenceid = ?
1.33 +and summary = ? and organiser = ? and expires = ?
1.34 """ % {"table" : self.table_name}
1.35 self.cursor.execute(query, values)
1.36