[問題] 撈取SQLite資料筆數問題

看板Python作者 (alansyue)時間6年前 (2018/10/01 14:51), 編輯推噓3(304)
留言7則, 3人參與, 6年前最新討論串1/1
各位大大們好,小弟目前在自學 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

10/01 16:29, 6年前 , 1F
time 變成 [time]
10/01 16:29, 1F

10/01 18:18, 6年前 , 2F
cutekid大大,還是一樣的錯誤訊息><
10/01 18:18, 2F

10/01 19:24, 6年前 , 3F
(time,) 試試
10/01 19:24, 3F

10/02 00:40, 6年前 , 4F
問號旁邊不用加單引號。加了 SQLite 會認為你表達的是
10/02 00:40, 4F

10/02 00:40, 6年前 , 5F
字面上的問號,而不是 placeholder。
10/02 00:40, 5F

10/02 09:19, 6年前 , 6F
推 stucode, 原來是這樣!
10/02 09:19, 6F

10/02 13:33, 6年前 , 7F
感謝!已解決
10/02 13:33, 7F
文章代碼(AID): #1RiSGE6S (Python)
文章代碼(AID): #1RiSGE6S (Python)