作者alansyue (alansyue)
看板Python
標題[問題] 撈取SQLite資料筆數問題
時間Mon Oct 1 14:51:49 2018
各位大大們好,小弟目前在自學 Python ,近期想使用 Python 取出每天爬到並匯入到
SQLite 的資料筆數
資料存入的格式如下圖:
https://i.imgur.com/WJap8QB.png
程式碼如下:
import sqlite3
conn = sqlite3.connect('sqlite01.db')
c = conn.cursor()
print ("Opened database successfully")
time = " 2018-09-30T%"
cur = c.execute("select count(*) from my_data where update_time like
'?'",time)
data = cur.fetchone()
print(data)
conn.commit()
print("Records created successfully")
conn.close()
但都會出現此行的錯誤訊息
--- > cur = c.execute("select count(*) from my_data where update_time like
'?'",time)
=錯誤訊息=
ProgrammingError: Incorrect number of bindings supplied. The current
statement uses 0, and there are 8 supplied.
不知道這部分該如何處理比較適合,想請大大們幫忙解惑,感謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.146.117.88
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1538376718.A.19C.html
推 cutekid: time 變成 [time] 10/01 16:29
→ alansyue: cutekid大大,還是一樣的錯誤訊息>< 10/01 18:18
推 cutekid: (time,) 試試 10/01 19:24
→ stucode: 問號旁邊不用加單引號。加了 SQLite 會認為你表達的是 10/02 00:40
→ stucode: 字面上的問號,而不是 placeholder。 10/02 00:40
推 cutekid: 推 stucode, 原來是這樣! 10/02 09:19
→ alansyue: 感謝!已解決 10/02 13:33