Skip to content

Commit 8a30a50

Browse files
author
Richard Jones
committed
fixed Boolean values in postgresql (bugs [SF#972546] and [SF#972600])
1 parent 0f64ab7 commit 8a30a50

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Fixed:
2121
- allow list of values for id, Number and Boolean filtering in anydbm
2222
backend
2323
- fixed some more mysql 0.6->0.7 upgrade bugs (sf bug 950410)
24+
- fixed Boolean values in postgresql (sf bugs 972546 and 972600)
2425

2526

2627
2004-06-10 0.7.4

roundup/backends/rdbms_common.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.109 2004-06-14 03:36:11 richard Exp $
1+
# $Id: rdbms_common.py,v 1.110 2004-06-16 03:54:00 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -53,6 +53,12 @@ def _num_cvt(num):
5353
except:
5454
return float(num)
5555

56+
def _bool_cvt(value):
57+
if value in ('TRUE', 'FALSE'):
58+
return {'TRUE': 1, 'FALSE': 0}[value]
59+
# assume it's a number returned from the db API
60+
return int(value)
61+
5662
class Database(FileStorage, hyperdb.Database, roundupdb.Database):
5763
''' Wrapper around an SQL database that presents a hyperdb interface.
5864
@@ -740,7 +746,7 @@ def addnode(self, classname, nodeid, node):
740746

741747
prop = props[col[1:]]
742748
value = values[col[1:]]
743-
if value:
749+
if value is not None:
744750
value = self.hyperdb_to_sql_value[prop.__class__](value)
745751
vals.append(value)
746752
vals.append(nodeid)
@@ -880,7 +886,7 @@ def setnode(self, classname, nodeid, values, multilink_changes={}):
880886
hyperdb.Link : str,
881887
hyperdb.Interval : date.Interval,
882888
hyperdb.Password : lambda x: password.Password(encrypted=x),
883-
hyperdb.Boolean : int,
889+
hyperdb.Boolean : _bool_cvt,
884890
hyperdb.Number : _num_cvt,
885891
hyperdb.Multilink : lambda x: x, # used in journal marshalling
886892
}

test/db_test_base.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.31 2004-06-13 01:05:46 richard Exp $
18+
# $Id: db_test_base.py,v 1.32 2004-06-16 03:54:00 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint
2121

@@ -263,11 +263,19 @@ def testIntervalUnset(self):
263263
self.assertEqual(self.db.issue.get(nid, "foo"), None)
264264

265265
# Boolean
266+
def testBooleanSet(self):
267+
nid = self.db.user.create(username='one', assignable=1)
268+
self.assertEqual(self.db.user.get(nid, "assignable"), 1)
269+
nid = self.db.user.create(username='two', assignable=0)
270+
self.assertEqual(self.db.user.get(nid, "assignable"), 0)
271+
266272
def testBooleanChange(self):
267273
userid = self.db.user.create(username='foo', assignable=1)
268274
self.assertEqual(1, self.db.user.get(userid, 'assignable'))
269275
self.db.user.set(userid, assignable=0)
270276
self.assertEqual(self.db.user.get(userid, 'assignable'), 0)
277+
self.db.user.set(userid, assignable=1)
278+
self.assertEqual(self.db.user.get(userid, 'assignable'), 1)
271279

272280
def testBooleanUnset(self):
273281
nid = self.db.user.create(username='foo', assignable=1)

0 commit comments

Comments
 (0)