0
이것은 내 프로그램입니다. 하여 구문 오류가 정확히 어디에 그것은 나에게 말한다, 그러나 나는 말 그대로 문제가 무엇인지 아무 생각이 없다 :구문 오류 알아낼 수 없습니까? python3
import sqlite3
def create_table(dbName, table_name, sql):
with sqlite3.connect("ATM.db") as db:
cursor = db.cursor()
cursor.execute("select name from sqlite_master where name=?",(table_name,))
result = cursor.fetchall()
keep_table = True
if len(result) == 1:
response = input("The table{0} already exists, do you wish to recreate? (y/n) \n".format(table_name))
if response.lower() == "y":
keep_table = False
print("the {0} table will be recreated".format(table_name))
cursor.execute("drop table if exists {0}".format(table_name))
db.commit()
insert_data()
else:
print("The existing table was kept")
insert_data()
else:
keep_table = False
if not keep_table:
>>>>>> cursor.execute(sql) #Problem is supposedly here?
db.commit()
insert_data()
def insert_data():
with sqlite3.connect("ATM.db") as db:
cursor = db.cursor()
sql = """insert into ATM(Title, First Name, Surname, Balance) values (Mr., Jeremy, Clarkson, 172.16),
(Miss, Suzanne, Perry, 15.62)"""
cursor.execute(sql, values)
db.commit()
dbName = "ATM.db"
sql = """ create table ATM
(CustomerID integer,
Title text
First Name text,
Surname text,
Balance real,
CustomerID(CustomerID))"""
create_table(dbName, "ATM", sql)
이것은 내가 무엇입니까 구문 오류 메시지입니다. 코드를 강조하는 부분에 화살표를 추가했습니다.
line 23, in create_table
cursor.execute(sql)
sqlite3.OperationalError: near "(": syntax error
나는 여전히 같은 구문 오류를 얻고 있습니다. 나는 그 쿼리에서 내 실수를 깨닫고 이미 변경했습니다! 심지어 전체 삽입 데이터 함수를 제거하여 그것을 테스트하고 cursor.execute (SQL)가리키는 동일한 구문 오류가 있습니다. sqlite3.OperationalError : 근처에 "(": 구문 오류 –
수정 한 고정 된. –
도와 주셔서 감사합니다. 좋은 하루 되세요! –