Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将sql文本文件加载到变量中并通过pymysql提交insert/update查询会产生警告-是否可以安全忽略?_Python_Mysql_Warnings_Pymysql - Fatal编程技术网

Python 将sql文本文件加载到变量中并通过pymysql提交insert/update查询会产生警告-是否可以安全忽略?

Python 将sql文本文件加载到变量中并通过pymysql提交insert/update查询会产生警告-是否可以安全忽略?,python,mysql,warnings,pymysql,Python,Mysql,Warnings,Pymysql,我有一些存储过程存储在.sql文件中。我想使用pymysql将它们添加到数据库中。因此,我将文件加载到一个变量中,如下所示: with open(filepath, 'r') as file: sql = file.read() connection = pymysql.connect(...) with connection.cursor() as cursor: cursor.execute(sql) connection

我有一些存储过程存储在.sql文件中。我想使用pymysql将它们添加到数据库中。因此,我将文件加载到一个变量中,如下所示:

    with open(filepath, 'r') as file:
        sql = file.read()
    connection = pymysql.connect(...)

    with connection.cursor() as cursor:
        cursor.execute(sql)

    connection.close()
/usr/lib/python3/dist-packages/pymysql/cursors.py:322: Warning: (139, 'Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.')
self._do_get_result()
/usr/lib/python3/dist-packages/pymysql/cursors.py:322: Warning: (1246, "Converting column '' from VARCHAR to TEXT")
self._do_get_result()
然后我使用pymysql提交,如下所示:

    with open(filepath, 'r') as file:
        sql = file.read()
    connection = pymysql.connect(...)

    with connection.cursor() as cursor:
        cursor.execute(sql)

    connection.close()
/usr/lib/python3/dist-packages/pymysql/cursors.py:322: Warning: (139, 'Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.')
self._do_get_result()
/usr/lib/python3/dist-packages/pymysql/cursors.py:322: Warning: (1246, "Converting column '' from VARCHAR to TEXT")
self._do_get_result()
这似乎很有效,但我收到了一些与我有关的警告。它们看起来像这样:

    with open(filepath, 'r') as file:
        sql = file.read()
    connection = pymysql.connect(...)

    with connection.cursor() as cursor:
        cursor.execute(sql)

    connection.close()
/usr/lib/python3/dist-packages/pymysql/cursors.py:322: Warning: (139, 'Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.')
self._do_get_result()
/usr/lib/python3/dist-packages/pymysql/cursors.py:322: Warning: (1246, "Converting column '' from VARCHAR to TEXT")
self._do_get_result()
我的问题是:忽略这些是安全的吗

更新:

我发现了第一个警告(关于行大小过大的警告):生成该警告的sql文本文件是一个视图创建,而不是SP创建,并且视图中的字段数量确实超过了行大小,因此在这里解决了这个问题。我仍在努力找出第二次警告的确切原因

更新2:


我发现了第二个警告。生成该文件的sql文本文件是一个SP创建,其中有一个变量声明为DECLARE v_sql VARCHAR(32000)。我将其改为VARCHAR(2000),警告消失了。因此,看起来变量大于某个大小将生成该警告。

对于我发布的第一个警告,问题是:生成该警告的sql文本文件是视图创建的,而不是SP创建的,并且视图中的字段数量确实超过了行大小


对于我发布的第二个警告,问题是:生成该警告的sql文本文件是一个SP创建,其中有一个变量声明为DECLARE v_sql VARCHAR(32000)。我将其改为VARCHAR(2000),警告消失了。因此,看起来变量大于某个大小将生成该警告。

您应该发布您的表structure@Hack5-没有表结构。这些.sql文件只是创建存储过程。因此,它们只是创建过程语句。我对SQL没有太多的经验,但由于其中一个警告涉及到一个列,我假设您必须有一个表(否则该列从何而来?@Hack5-确切地说)。我猜pymysql在内部使用某种表结构来执行游标之类的东西?没有线索。这就是为什么我要发布这个。哦,如果这不是一个noob错误,我什么都不知道,对不起。