【问题标题】:python sqlite fetchall not returning correct data typepython sqlite fetchall没有返回正确的数据类型
【发布时间】:2017-11-18 15:53:46
【问题描述】:

我在将 fetchall 返回为正确的数据类型时遇到问题。 fetchone 确实有效?!?!

con = sqlite3.connect('test.db', detect_types=sqlite3.PARSE_DECLTYPES)

与缺点:

cur = con.cursor()    
cur.execute("SELECT df1 FROM PLCValues")

rows = cur.fetchall()
#print(rows)
for row in rows:
    print (row)
print(row)

返回

================= RESTART: C:/Users/zippo/Desktop/Graphit.py =================
(44.64769744873047,)
(44.691650390625,)
(44.691650390625,)
(44.471900939941406,)
(44.64769744873047,)

FETCHONE

con = sqlite3.connect('test.db', detect_types=sqlite3.PARSE_DECLTYPES)

与缺点:

cur = con.cursor()    
cur.execute("SELECT df1 FROM PLCValues")

rows = cur.fetchone()
#print(rows)
for row in rows:
    print (row)
print(row)

返回:

================= RESTART: C:/Users/zippo/Desktop/Graphit.py =================
44.64769744873047
44.64769744873047

【问题讨论】:

  • PLCValues 表中df1 列的类型是什么?

标签: python sqlite fetchall


【解决方案1】:

cur.fetchall() 返回一个元组的元组。根据https://docs.python.org/2/library/sqlite3.html,它似乎返回了正确的类型。您可能希望遍历单个元组以获取单个元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 2011-07-10
    • 2021-05-20
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多