gcxh
gcxh

Reputation: 21

SQLITE create statement error

I am using sqlite3 in python3.

Is there anything wrong in my CREATE statement shown below? c.execute("CREATE TABLE IF NOT EXISTS transaction(no INTEGER PRIMARY KEY AUTOINCREMENT, ic NONE, borrow INTEGER, timeIn NONE, timeOut NONE")

Error message: sqlite3.OperationalError: near "transaction" : syntax error

Upvotes: 1

Views: 110

Answers (2)

Kenly
Kenly

Reputation: 26768

As Ignacio said, transaction should be quoted and there is a missing right parenthesis.
The query should looks like:

c.execute("CREATE TABLE IF NOT EXISTS 'transaction'(no INTEGER PRIMARY KEY AUTOINCREMENT,  
                                                    ic NONE, borrow INTEGER, 
                                                    timeIn NONE, 
                                                    timeOut NONE)")

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799520

"transaction" is a reserved word in SQL. You need to quote it if you want to use it.

... `transaction` (...

Upvotes: 1

Related Questions