def quantity():
i = 0
x = 1
file = open("john.txt", "r")
while i < 5000:
for line in file:
c.execute("INSERT INTO test (playerNAME, playerID) VALUES ("+line+", "+str(x)+")")
conn.commit()
x = random.randint(100,10000000000000000)
i += 1
我嘗試遍歷John.txt文件並將每個值插入到表中。 txt文件中的第一個單詞是「abc123」。當我運行此代碼有一個錯誤:sqlite3.OperationalError:沒有這樣的列:abc123嘗試從python的sqlite中插入txt文件的值
我可以得到的代碼輸入到playerID的隨機數,但我不能讓txt文件查詢工作...
你錯過了附近的引號:'VALUES('「+ line +」',「+ str(x)+」)「)' – trans1st0r
不要連接sql查詢和字符串,使用參數化版本的'execute'。 – DeepSpace