From: SourceForge.net <no...@so...> - 2003-10-25 15:31:14
|
Bugs item #829727, was opened at 2003-10-24 13:23 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116528&aid=829727&group_id=16528 Category: PgBoolean Group: None Status: Open Resolution: None Priority: 5 Submitted By: Mike C. Fletcher (mcfletch) Assigned to: Nobody/Anonymous (nobody) Summary: 0 or 1 not accepted for booleans... Initial Comment: Not sure whether this is really fixable in PyPgSQL, but I spent quite some time fixing it in my apps. Basically, to declare a boolean for PostgreSQL you need to have SQL syntax something like: True, '1','t','True' and not: 1 Given that the DB-API advocates, wherever possible, using the driver's escaping mechanism, new users (myself included) will often pass in common old-style python boolean values (i.e. 1,0) (particularly in Python 2.2.x) to queries as parameters for escaping. To fix it, you'd need to know the context of the query (i.e. that the value needs to be a boolean, not a number), so I'm not at all confident that PyPgSQL can do the escaping properly (or even if it would be desirable to do so). It can be worked around by rewriting applications to use a back-ported Python 2.3 bool class (with __str__ giving True/False) whereever booleans come in contact with SQL escaping. (Or I would assume by using PgBoolean in the same way). If it's not fixable, a FAQ entry describing the problem, and pointing to http://www.python.org/peps/pep-0285.html (which has the code to back-port true booleans to Python 2.2.x). sqlquery.SQLQuery( sql="""INSERT INTO person( login, person_active, upass) VALUES ('jed',%(active)s, 'blah')""" )( connection, #active = booleanfix.bool(0), active = 0, ) gives V:\cinemon>boolean_problem.py Traceback (most recent call last): File "V:\cinemon\boolean_problem.py", line 17, in ? active = 0, File "p:\table\pytable\sqlquery.py", line 87, in __call__ self.do( cursor=cursor, query=query, **namedarguments) File "p:\table\pytable\sqlquery.py", line 109, in do raise err.__class__( """(SQLQuery) %s\nQuery: %s\nArguments: %s"""%( libpq.OperationalError: (SQLQuery) ERROR: column "person_active" is of type boolean but expression is of type integer You will need to rewrite or cast the expression Query: INSERT INTO person( login, person_active, upass) VALUES ('jed',0, 'blah') Arguments: {'active': 0} ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116528&aid=829727&group_id=16528 |