简体   繁体   English

python sqlite fetchall没有返回正确的数据类型

[英]python sqlite fetchall not returning correct data type

I am having an issue with having fetchall return being the correct data type. 我在让fetchall返回正确的数据类型时遇到问题。 fetchone does work?!?! fetchone有效吗?!?!

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

with con: 与骗局:

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

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

Returns 退货

================= 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)

with con: 与骗局:

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

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

Returns: 返回值:

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

cur.fetchall() returns a tuple of tuples. cur.fetchall()返回一个元组的元组。 According to https://docs.python.org/2/library/sqlite3.html it seems to be returning the correct type. 根据https://docs.python.org/2/library/sqlite3.html,它似乎正在返回正确的类型。 You might want to iterate through individual tuple to get a single element. 您可能要遍历单个元组以获得单个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM