2017-11-18 8 views
0

fetchall returnが正しいデータ型であることに問題があります。 fetchoneは動作しますか?!?!python sqlite fetchallが正しいデータ型を返さない

詐欺と
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 
+0

'PLCValues'テーブルの' df1'カラムのタイプは? –

答えて

1

cur.fetchall()はタプルのタプルを返します。 https://docs.python.org/2/library/sqlite3.htmlによると、正しいタイプが返されているようです。単一の要素を得るためには、個々のタプルを繰り返し処理したいと思うかもしれません。

関連する問題