简体   繁体   中英

sqlite-problem-sqlite3-operationalerror-near-where-syntax-error

I am trying to insert data into database, but here is error:

sqlite-problem-sqlite3-operationalerror-near-where-syntax-error

This is my code:

c.execute(f"INSERT INTO math(qula) WHERE name = '{member.name}' VALUES({saboloo})")

I suspect that you want to update the column qula of an existing row of the table math and not insert a new row.
Also, it's a good practice to use ? placeholders:

c.execute("UPDATE math SET qula = ? WHERE name = ?", (saboloo, member.name)) 

To insert data into sqlite3, first you have to import sqlite3 module in the Python standard library. You then connect to the file by passing a file path to the connect (xxxx) method in the sqlite3 module, if the database you passed in the connect method does not exist one will be created at that path and if the database exist it will connect to it.

import sqlite3
con = sqlite3.connect('/path/xxx.sqlite3')

You than have to create a cursor object using the cursor() method

c = con.cursor()

You than Prepare, SQL queries to INSERT a record into the database.

c.execute(f"INSERT INTO math(qula) VALUES({saboloo})").

I hope this one helps. You can also read more from here Python SQLite insert data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM