Mike,

Michael Bayer wrote:
> On Nov 7, 2007, at 10:23 AM, Werner F. Bruhin wrote:
>
>   
>> How can I define a column in the table as read-only?
>>
>> I have some "computed by" columns, e.g.:
>> consumedvalue  computed by (quantity*unitprice)
>>
>> These columns can not be updated, otherwise I get the following  
>> exception:
>> ProgrammingError: (ProgrammingError) (-151, 'isc_dsql_prepare: \n
>> attempted update of read-only column')
>>
>>     
>
> read-only behavior is a class-level thing, so something like this:
>
> class MyClass(object):
>      def mycol(self):
>          return self._mycol
>      mycol = property(mycol)
>
> mapper(MyClass, mytable, properties={
>     '_mycol':mytable.c.mycol,
>     'mycol':synonym('_mycol')
> })
>
>
> Theres a ticket in trac which will make the above configuration  
> slightly less verbose in a future release.
>   
I don't have many of these, so no big deal that it is verbose.

However I must not do something wrong in transposing the above as I 
still get the error.

I must be a bit dense on this, here is what I have done:

consumption_table = sa.Table(u'consumption', metadata,
    sa.Column(u'consumptionid', sa.Integer(), 
sa.Sequence('gen_consumption_consumptionid'), primary_key=True, 
nullable=False),
    sa.Column(u'quantity', sa.Integer()),
    sa.Column(u'unitprice', 
sa.Numeric(precision=18,length=2,asdecimal=True)),
    sa.Column(u'consumedvalue', 
sa.Numeric(precision=18,length=2,asdecimal=True)),
....
)

class Consumption(object):
    def consumedvalue(self):
        return self._consumedvalue
    consumedvalue = property(consumedvalue)
    pass

consumption = sao.mapper(Consumption, consumption_table,
    properties={
...
        'cellar': sao.relation(Cellar, backref='consumption'),
        '_consumedvalue': consumption_table.c.consumedvalue,
        'consumedvalue': sao.synonym('_consumedvalue'),
})

Can you point out what I did wrong, please.

Werner

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to