【问题标题】:python mariadb connector error when fetching results from a DATETIME with value NULL从值为 NULL 的 DATETIME 获取结果时出现 python mariadb 连接器错误
【发布时间】:2021-07-01 22:31:47
【问题描述】:

好吧,我猜 mariadb 连接器有问题...

我有一个如下所示的表格行:

id title category date_posted date_due content file user_id
6 test 7 10 2021-04-01 21:50:21 content 7 strawsf9cdaf.txt 16

问题是我有一个为 NULL 的 DATETIME 字段(我的应用程序中的 date_due 日期不是强制性的)

似乎在将值传递给execute()方法之后,fetchall()方法对返回的数据进行了不同的解析。

第一个案例效果很好 第二个返回“ValueError: year 0 is out of range”

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)

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

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

我虽然是版本问题,所以我更新到最新的 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

任何帮助将不胜感激

【问题讨论】:

  • 这对我来说确实像是一个连接器错误。
  • 我该如何报告?切换到 mysql 连接器会更好吗:D 我已经为此挠头了 0.o
  • mariadb.com 页面上有一个“联系我们”页面。

标签: python mysql mariadb


【解决方案1】:

这是 MariaDB Connector/Python 中的一个错误,最近由我自己修复。修复将在下一版本 (1.0.7) 中提供。

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

感谢您的报告。

【讨论】:

    猜你喜欢
    • 2022-11-24
    • 1970-01-01
    • 2019-07-25
    • 2022-11-05
    • 1970-01-01
    • 2019-06-05
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多