1. <legend id='s0LWX'><style id='s0LWX'><dir id='s0LWX'><q id='s0LWX'></q></dir></style></legend>

  2. <i id='s0LWX'><tr id='s0LWX'><dt id='s0LWX'><q id='s0LWX'><span id='s0LWX'><b id='s0LWX'><form id='s0LWX'><ins id='s0LWX'></ins><ul id='s0LWX'></ul><sub id='s0LWX'></sub></form><legend id='s0LWX'></legend><bdo id='s0LWX'><pre id='s0LWX'><center id='s0LWX'></center></pre></bdo></b><th id='s0LWX'></th></span></q></dt></tr></i><div id='s0LWX'><tfoot id='s0LWX'></tfoot><dl id='s0LWX'><fieldset id='s0LWX'></fieldset></dl></div>

      <bdo id='s0LWX'></bdo><ul id='s0LWX'></ul>

    <small id='s0LWX'></small><noframes id='s0LWX'>

  3. <tfoot id='s0LWX'></tfoot>
    1. 捕获一个 MySql 警告

      trapping a MySql warning(捕获一个 MySql 警告)
        <tbody id='6Mnzi'></tbody>

      1. <legend id='6Mnzi'><style id='6Mnzi'><dir id='6Mnzi'><q id='6Mnzi'></q></dir></style></legend>

        <small id='6Mnzi'></small><noframes id='6Mnzi'>

          <bdo id='6Mnzi'></bdo><ul id='6Mnzi'></ul>
              • <i id='6Mnzi'><tr id='6Mnzi'><dt id='6Mnzi'><q id='6Mnzi'><span id='6Mnzi'><b id='6Mnzi'><form id='6Mnzi'><ins id='6Mnzi'></ins><ul id='6Mnzi'></ul><sub id='6Mnzi'></sub></form><legend id='6Mnzi'></legend><bdo id='6Mnzi'><pre id='6Mnzi'><center id='6Mnzi'></center></pre></bdo></b><th id='6Mnzi'></th></span></q></dt></tr></i><div id='6Mnzi'><tfoot id='6Mnzi'></tfoot><dl id='6Mnzi'><fieldset id='6Mnzi'></fieldset></dl></div>
                <tfoot id='6Mnzi'></tfoot>

                本文介绍了捕获一个 MySql 警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在我的 python 脚本中,我想在使用 MySql 的查询期间捕获为列 'xxx' 截断的数据"警告.

                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 it doesn' work.

                您是否知道在使用此代码之前是否必须导入某些特定模块或者是否应该调用某些选项/标志?

                Do you know if some specific module must be imported or if some option/flag should be called before using this code?

                谢谢大家

                阿夫格

                import MySQLdb
                try:
                    cursor.execute(some_statement)
                    # code steps always here: No Warning is trapped
                    # by the code below
                except MySQLdb.Warning, e:
                    # handle warnings, if the cursor you're using raises them
                except Warning, e:
                    # handle warnings, if the cursor you're using raises them
                

                推荐答案

                警告就是:警告.他们被报告给(通常)stderr,但没有做任何其他事情.你不能像异常一样捕捉它们,因为它们没有被引发.

                Warnings are just that: warnings. They get reported to (usually) stderr, but nothing else is done. You can't catch them like exceptions because they aren't being raised.

                但是,您可以使用 warnings 模块配置警告时要做什么,并关闭它们或将它们变成异常.例如, warnings.filterwarnings('error', category=MySQLdb.Warning)MySQLdb.Warning 警告 转换为异常(在这种情况下,它们将被使用您的 try/except) 或 'ignore' 根本不显示它们.您可以(并且可能应该)拥有比类别更细粒度的过滤器.

                You can, however, configure what to do with warnings, and turn them off or turn them into exceptions, using the warnings module. For instance, warnings.filterwarnings('error', category=MySQLdb.Warning) to turn MySQLdb.Warning warnings into exceptions (in which case they would be caught using your try/except) or 'ignore' to not show them at all. You can (and probably should) have more fine-grained filters than just the category.

                这篇关于捕获一个 MySql 警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to delete duplicate records in mysql database?(如何删除mysql数据库中的重复记录?)
                Python Pandas write to sql with NaN values(Python Pandas 使用 NaN 值写入 sql)
                MySQL Insert amp; Joins(MySQL 插入 amp;加入)
                MySQL concat() to create column names to be used in a query?(MySQL concat() 创建要在查询中使用的列名?)
                NodeJS responded MySQL timezone is different when I fetch directly from MySQL(当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同)
                WHERE datetime older than some time (eg. 15 minutes)(WHERE 日期时间早于某个时间(例如 15 分钟))

                  <i id='9HK1K'><tr id='9HK1K'><dt id='9HK1K'><q id='9HK1K'><span id='9HK1K'><b id='9HK1K'><form id='9HK1K'><ins id='9HK1K'></ins><ul id='9HK1K'></ul><sub id='9HK1K'></sub></form><legend id='9HK1K'></legend><bdo id='9HK1K'><pre id='9HK1K'><center id='9HK1K'></center></pre></bdo></b><th id='9HK1K'></th></span></q></dt></tr></i><div id='9HK1K'><tfoot id='9HK1K'></tfoot><dl id='9HK1K'><fieldset id='9HK1K'></fieldset></dl></div>
                    • <bdo id='9HK1K'></bdo><ul id='9HK1K'></ul>

                          <tbody id='9HK1K'></tbody>
                        • <tfoot id='9HK1K'></tfoot>

                          <small id='9HK1K'></small><noframes id='9HK1K'>

                          <legend id='9HK1K'><style id='9HK1K'><dir id='9HK1K'><q id='9HK1K'></q></dir></style></legend>