patrick wrote:
> Hey,
> I'm trying to create dynamic defaults for columns ala "http://
> www.sqlalchemy.org/docs/metadata.html#context-sensitive-default-functions".
> MySQL has COMPRESS and UNCOMPRESS functions that I'm trying to
> leverage. I don't want to compress with python's zlib because I have
> legacy tables that were compressed using MySQL (which has a weird non-
> standard zip header and body), and I need to interface with them.
> Anyway, during an insert or update, I want to grab the 'text' variable
> from the instance object and insert it into the database like:
> COMPRESS("the text value"). Obviously context.current_parameters is
> not the appropriate object, but I can't figure out if it's possible to
> access the instance being inserted/updated.
are you trying to create a *default* value for an INSERT/UPDATE when NULL
would otherwise be passed, or are you trying to run all incoming/outgoing
data through a SQL function ? those are two completely separate topics.
>
> def compress_text(context):
> return "COMPRESS('%s')" % context.current_parameters['text']
>
> class Tree(BaseStruct, Base):
> __tablename__ = 'tree'
> __table_args__ = (
> {'autoload':True}
> )
>
> compressed =
> deferred(Column(Binary(),default=compress_text,default=compress_text,onupdate=compress_text))
> text =
> column_property(select(["UNCOMPRESS(compressed)"]),deferred=True)
>
> Is this possible with 0.5.7?
>
> --
> 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.
>
>
--
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.