In the onupdate function, how to get the value of the row of records to be updated

20 views
Skip to first unread message

peizhi qin

unread,
Jun 20, 2021, 12:37:30 PM6/20/21
to sqlalchemy
I have a table ,the definition is as follows:
class TEnterprise(Base):
__tablename__ = 't_enterprise'
__table_args__ = (
{'mysql_engine': 'InnoDB', 'mysql_charset': 'latin1'}
)

Fent_id = Column(String(32), primary_key=True)
Fent_type = Column(INTEGER(11), nullable=False)
Fcomb_cert_state = Column(INTEGER(11), nullable=False)
Fstate = Column(INTEGER(11), nullable=False)
Fbusiness_license_copy = Column(String(256), nullable=False)
Fbusiness_license_number = Column(String(32), nullable=False)
Fmerchant_name = Column(String(128), nullable=False)
Fsign = Column(String(64), nullable=False, server_default=text("''"))

the Fsign=md5(Fcomb_cert_state=${Fcomb_cert_state}&Fent_id=${Fent_id})

i can use  context.current_parameters get the value of the field to be updated, but how to get the value of the field that has not been updated, thanks for help!

Simon King

unread,
Jun 21, 2021, 5:34:02 AM6/21/21
to sqlal...@googlegroups.com
I don't think you'll be able to get what you want in an onupdate
function. You'd probably be better off with the before_insert and
before_update mapper events:

https://docs.sqlalchemy.org/en/14/orm/events.html#sqlalchemy.orm.MapperEvents.before_insert

https://docs.sqlalchemy.org/en/14/orm/events.html#sqlalchemy.orm.MapperEvents.before_update

Hope that helps,

Simon
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
> ---
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/bc9a6c71-90dd-4c7a-a5a8-9712f43d24f6n%40googlegroups.com.

peizhi qin

unread,
Jun 23, 2021, 1:02:19 AM6/23/21
to sqlalchemy
before_ insert before_ update can solve my problem. Thank you very much
Reply all
Reply to author
Forward
0 new messages