We are switching to SVN and the commit to mailing list script failed.
I have fixed it (I hope) but in the meantime here is the change I
made.  The log message is:

Fix money quoting.  Amount of $0.00 should certainly be allowed.
Add unit tests.


Index: pg.py
===================================================================
--- pg.py       (revision 411)
+++ pg.py       (working copy)
@@ -190,7 +190,7 @@

     def _quote_money(self, d):
         """Quote money value."""
-        if not d:
+        if d is None or d == '':
             return 'NULL'
         return "'%.2f'" % float(d)

Index: TEST_PyGreSQL_classic.py
===================================================================
--- TEST_PyGreSQL_classic.py    (revision 411)
+++ TEST_PyGreSQL_classic.py    (working copy)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python

 import sys, unittest
+from decimal import Decimal
 from pg import *

 # We need a database to test against.  If LOCAL_PyGreSQL.py exists we
will @@ -154,6 +155,11 @@
         self.assertEqual(_quote('1', 'money'), "'1.00'")
         self.assertEqual(_quote(1.234, 'money'), "'1.23'")
         self.assertEqual(_quote('1.234', 'money'), "'1.23'")
+        self.assertEqual(_quote(0, 'money'), "'0.00'")
+        self.assertEqual(_quote(0.00, 'money'), "'0.00'")
+        self.assertEqual(_quote(Decimal('0.00'), 'money'), "'0.00'")
+        self.assertEqual(_quote(None, 'money'), "NULL")
+        self.assertEqual(_quote('', 'money'), "NULL")
         self.assertEqual(_quote(0, 'bool'), "'f'")
         self.assertEqual(_quote('', 'bool'), "NULL")
         self.assertEqual(_quote('f', 'bool'), "'f'")
PyGreSQL.org

-- 
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org
_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to