trapping a MySql warning

前端 未结 7 1045
逝去的感伤
逝去的感伤 2020-11-29 23:59

In my python script I would like to trap a \"Data truncated for column \'xxx\'\" warning durnig my query using MySql.

I saw some posts suggesting the code below, but

7条回答
  •  暖寄归人
    2020-11-30 00:29

    I would try first to set the sql_mode. You can do this at the session level. If you execute a:

    SET @@sql_mode:=TRADITIONAL;
    

    (you could also set it at the server level, but you need access to the server to do that. and, that setting an still be overridden at the session level, so the bottom line is, always set it at the session level, immediately after establishing the connection)

    then many things that are normally warnings become errors. I don't know how those manifest themselves at the python level, but the clear advantage is that the changes are not stored in the database. See: http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html#sqlmode_traditional

提交回复
热议问题