Re: [SQLObject] problem: implementing BoolCol
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2003-04-16 21:14:43
|
On Mon, 2003-04-14 at 10:53, Bud P.Bruegger wrote: > I tried to implement BoolCol and have the following problem: > > The function sqlRepr in SQLBuilder.py should cast boolean values to > either 't' or 'f' (or some alternative reps). Problem is that (in > Python 2.2 that I use), there is no Boolean type and sqlRepr has only > the python type of the (value) object and knows nothing about the > related ColType (SQL type). So I can't figure out how to recognize > that I deal with a boolean in sqlRepr... > > Would it be worth while to refactor sqlRepr to get a second argument > that specifies the desired SQL type? Yes, that is a problem. In the meantime you can override the accessor directly. Ultimately the Constraints system will handle this, as I'm going to expand it to also do some sort of conversion. You'll have something like: class AsBool(Validator): def convertSQL(self, value): return ["'f'", "'t'"][not not value] def unconvertSQL(self, value): return value == 'f' (Assuming you also get 't'/'f' back, but maybe I'm wrong) Ian |