python - What is wrong with my sqlite3 script? -
c = conn.cursor() c.executescript(""" create table if not exists dvdlist ( title text, barcode, added_date text, out numeric, borrower text, price real ); create table if not exists userdb ( username text, password text, address text, phone text, email text, borrowed integer ); create table if not exists staffdb ( username text, password text, address text, phone text, email text, group integer ); """)
traceback says:
traceback (most recent call last): file "<stdin>", line 1, in <module> file "shopdatabase.py", line 52, in __init__ self.__db_init() file "shopdatabase.py", line 108, in __db_init """) sqlite3.operationalerror: near "group": syntax error
i have looked data types in sqlite @ http://www.sqlite.org/datatype3.html, not quite sure going on. please help.
group
reserved keyword (it part of sql language). you'll need quote if want use column name:
create table if not exists staffdb ( username text, password text, address text, phone text, email text, 'group' integer );
you can use single quotes ('group'
), double quotes ("group"
) or square brackets or backticks ([group]
, `group`
), latter 2 forms supported compatibility non-compliant database engines.
you'll have quote name anywhere use in sql statement:
select 'group' staffdb username=?
for example.
Comments
Post a Comment