Michael Bayer wrote:
> Werner F. Bruhin wrote:
>
>> Figured out how to run the called procedure.
>>
>> sql = db.sa.text("select trans_value from t(:totrans, :username)",
>> bindparams=[db.sa.bindparam('totrans', 'some text
>> orig'),
>> db.sa.bindparam('username', me.name)])
>> result = session.execute(sql).fetchone()
>> print result
>> (u'some text orig auf Deutsch',)
>>
>>
>> But still stuck on how to make this an additional column using
>> declarative base and obtaining "some text orig" from another column in
>> the same table.
>>
>> Is this at all possible?
>>
>
> easiest would be a plain python method that calls the appropriate SQL.
>
Michael thanks for these tips, I think I am there.
However I am still getting the feeling that you think this is not a good
way to go and I wonder if there is something which will bite me down the
road.
Some additional explanations:
On the tables which are multi language I would like to be able to do
queries and just get the translation returned from the stored procedure,
that is why I like to do the mapped column.
> alternatively, if you really want to use a mapped column, the only
> advantage is the inline SQL aspect of it, i.e. performance. you'd
> construct a select() from the above and pass the dependent columns in -
> using the third example in
> http://www.sqlalchemy.org/docs/05/sqlexpression.html#functions , something
> like
>
> select([column('x1')]).select_from(func.t(mytable.c.totrans,
> mytable.c.username))
>
> then map it using column_property().
>
Now I have this in my model:
def getCurrentUser():
return cUser
class Sample(Base):
__table__ = sa.Table(u'sample', metadata,
sa.Column(u'id', sa.Integer(), sa.Sequence('gen_sample_id'),
primary_key=True, nullable=False),
sa.Column(u'name', sa.String(length=256, convert_unicode=False)),
)
name_trans =
sao.column_property(sa.select([sasql.column('trans_value')]).
select_from(sa.func.t(__table__.c.name,
getCurrentUser)))
And doing a query, e.g. like this:
sample = session.query(db.Sample).one()
print sample
Gives me:
Sample(id=1, name=u'some text orig', name_trans=u'some text orig auf
Deutsch')
Perfect!
Will do some more testing on this, but I think I am pretty close, if not
already there.
Thanks again!
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
-~----------~----~----~----~------~----~------~--~---