Sqlite using Python3 error?
Question: I am trying to insert some data into a sqlite database by following : -

    
    
    param = '("593863695396044801","Ivan F. Siahaan","307783731","None","65","83","Thu Apr 30 19:45:13 +0000 2015","xyz")'
    
    >>> conn.execute("INSERT INTO data "+param) Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    sqlite3.OperationalError: near ")": syntax error
    

I initialized connection to database as follows :-

    
    
    from sqlite3 import dbapi2 as sqlite
    
    conn = sqlite.connect('dataStore')
    

What wrong I am doing here ?


Answer: You are getting your SQL syntax wrong; both the quoting and the `INSERT`
statement syntax are incorrect.

SQLite doesn't support double quotes around string values, only single quotes.
From the [SQLite keywords
documenation](https://www.sqlite.org/lang_keywords.html):

> `'keyword'` A keyword in single quotes is a string literal.  
>  `"keyword"` A keyword in double-quotes is an identifier.

You are using double quotes, but for string literals you need to use single
quotes instead.

You are also missing the `VALUES` keyword; see the [`INSERT` statement
documentation](https://www.sqlite.org/lang_insert.html); the pattern is
`INSERT INTO <table> VALUES (<value list>)`.

You really want to leave quoting to the database itself, however. Use SQL
parameters here:

    
    
    statement = "INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
    params = (593863695396044801, "Ivan F. Siahaan", 307783731, None, 65, 83, "Thu Apr 30 19:45:13 +0000 2015", "xyz")
    conn.execute(statement, params)
    

Note that this would also let you use the Python `None` singleton to insert a
`NULL` in the database.

