這個問題在這里已經有了答案: sqlite3.ProgrammingError:提供的系結數量不正確。當前陳述句使用 1,提供了 74 個(2 個答案) 昨天關門。
我正在進入 SQL,試圖將一個值插入到特定的表列中,但與我試圖提供的整個字串相比,它似乎只想取一個字符。
import sqlite3
import random
conn = sqlite3.connect(r"test.db")
cursor = conn.cursor()
profile_ID = str(random.randint(100,999))
'''
insert into one column
'''
cursor.execute("INSERT INTO Webstore(Running) VALUES(?)", (profile_ID))
這是出現的錯誤:
sqlite3.ProgrammingError:提供的系結數量不正確。當前陳述句使用 1,并且提供了 3。
似乎帶有上述查詢的插入只希望接受一個字符而不是 profile_ID 中的三個,我嘗試發送一個字串,例如“字串 6”,它會傳遞給我同樣的錯誤,但在這種情況下是“提供 8”(8 “字串 6”中的字符)。
uj5u.com熱心網友回復:
我不是使用專家sqlite,但我堅信您所堅持的問題與該模塊無關;相反,這是一個tuple問題。我相信你需要改變這一行:
cursor.execute("INSERT INTO Webstore(Running) VALUES(?)", (profile_ID))
到這一行:
cursor.execute("INSERT INTO Webstore(Running) VALUES(?)", (profile_ID,))
這兩行之間有細微的差別。(profile_ID)已更改為(profile_ID,). 前者可以是基于以下值的任何內容profile_ID:字串、整數,甚至是浮點數。但后者絕對是一個元組,我相信您將需要cursor.execute.
uj5u.com熱心網友回復:
插入一個值:
cursor.execute("insert into Webstore (Running) values (%s)" % profile_ID)
插入多個值(?在這里作業沒有錯誤):
cursor.execute("insert into Webstore (Running, Status) values (?, ?)", (profile_ID, status))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/430514.html
