从值为NULL的DATETIME获取结果时出现python mariadb连接器错误

2024-05-23 22:38:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我猜mariadb连接器有点不对劲

我有一个表行,如下所示:

^{tb1}$

问题是我的DATETIME字段为空(date_due date在我的应用程序中不是强制性的)

似乎在将值传递给execute()方法之后,fetchall()方法会以不同的方式解析返回的数据

第一个案例效果很好 第二个返回“ValueError:第0年超出范围”

id=("6",)
statement1 = "select * from posts where id = 6"
statement2 = "select * from posts where id = ?"

db.cursor.execute(statement1)
result = db.cursor.fetchall()
for x in result:
     print(x)

db.cursor.execute(statement2, id)
result = db.cursor.fetchall()
for x in result:
     print(x)

我尝试列出()连接器-结果相同

我尝试更改值和表列属性-结果相同

我认为这是版本的问题,所以我更新了最新的python、mariadb服务器和python连接器(在ubuntu 20.04上)——同样的结果

结果是:

6, 'test 7', 10, datetime.datetime(2021, 4, 1, 21, 50, 21), None, 'content 7', 'strawsf9cdaf.txt', 16)
ValueError: year 0 is out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/project dir/main_test3.py", line 38, in <module>
    result = db.cursor.fetchall()
SystemError: <method 'fetchall' of 'mariadb.connection.cursor' objects> returned a result with an error set

Process finished with exit code 1

任何帮助都将不胜感激


Tags: of方法infromidexecutedbdate
1条回答
网友
1楼 · 发布于 2024-05-23 22:38:48

这是MariaDB Connector/Python中的一个bug,最近我自己修复了它。下一版本(1.0.7)中将提供此修复程序

日期“0000-00-00”在Python中无效,因此必须转换为无

谢谢你的报告

相关问题 更多 >