# HG changeset patch # User Paul Boddie # Date 1461273455 -7200 # Node ID e7e62c2e1598040e09b30c6e91becc97d470ab9a # Parent 64303953c839f8e98b3ee40c757b61032b399ff1 Fixed string encoding when inserting/removing periods in database collections. diff -r 64303953c839 -r e7e62c2e1598 imiptools/period.py --- a/imiptools/period.py Thu Apr 21 16:34:27 2016 +0200 +++ b/imiptools/period.py Thu Apr 21 23:17:35 2016 +0200 @@ -34,6 +34,12 @@ if x is None: return y else: return x +def to_string(s, encoding): + if s: + return s.encode(encoding) + else: + return s + class Comparable: "A date/datetime wrapper that allows comparisons with other types." @@ -896,7 +902,7 @@ "insert into %(table)s (:columns) values (:values)" % { "table" : self.table_name }, - columns, values) + columns, [to_string(v, "utf-8") for v in values]) self.cursor.execute(query, values) @@ -907,11 +913,14 @@ self._check_mutable() for period in periods: + values = period.as_tuple(string_datetimes=True) + query, values = self.get_query( "delete from %(table)s :condition" % { "table" : self.table_name }, - self.period_columns, period.as_tuple(string_datetimes=True)) + self.period_columns, [to_string(v, "utf-8") for v in values]) + self.cursor.execute(query, values) def remove_event_periods(self, uid, recurrenceid=None):