I've search trought a lot a internet site and I cannot find the answer. I try to create 4 tables in my SQLite database with this code:
try:
conn = sqlite3.connect(os.path.join(current_directory, 'fidouda.db'))
c = conn.cursor()
c.execute('''CREATE TABLE Clients (ID INTEGER PRIMARY KEY AUTOINCREMENT, Prenom, Nom, Adresse, Email, Telephone, Genre, Factures, Fidelite);''')
c.execute('''CREATE TABLE Factures (ID, Client, Items, Date, Prix, Promotion, Sous-total, Total, Payer, Rpayer);''')
c.execute('''CREATE TABLE Inventaire (Stock, Nom, Prix);''')
c.execute('''CREATE TABLE Rabais (Nom, Pourcentage);''')
except Error as e:
print(e)
finally:
if conn:
conn.close()
return os.path.join(current_directory, fname)
The problem is that only the first table are created. How can I create all my table ?
-
Are you getting an error message? Except for the first column in the first table, none of these columns have data types, which I thought was required.John Gordon– John Gordon2019年09月20日 15:25:08 +00:00Commented Sep 20, 2019 at 15:25
1 Answer 1
If you run this code, it will output this error:
sqlite3.OperationalError: near "-": syntax error
Specifically, the hyphen in the column Sous-total, you can either surround the column name in quotes, like this:
c.execute('''CREATE TABLE Factures (ID, Client, Items, Date, Prix, Promotion, 'Sous-total', Total, Payer, Rpayer);''')
Or pick another column name that won't cause problems.
answered Sep 20, 2019 at 15:26
Anon Coward
10.9k3 gold badges31 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Mamquam
That work ... I dont know why but when I run this, I dont get error ... Maybe "hidden" by other thing in my script. I feel a little bit dumb .... Thanks a lot
default