Skip to content

Instantly share code, notes, and snippets.

@michaeljs1990
Last active August 29, 2015 14:05
Show Gist options
  • Save michaeljs1990/934496ef95c11609cc42 to your computer and use it in GitHub Desktop.
Save michaeljs1990/934496ef95c11609cc42 to your computer and use it in GitHub Desktop.
Python Sqlite3
import sqlite3
#python 3.4
# This fails with key of site_title
db.execute("SELECT * FROM options WHERE key=?;", (key.encode('utf-8'),))
# This works...
db.execute("SELECT * FROM options WHERE key='site_title';")
# This says I have supplied to many arguments...
db.execute("SELECT * FROM options WHERE key='?';", (key.encode('utf-8'),))
@michaeljs1990
Copy link
Author

Error from first output when i try and access it using fetchone()[0]

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/cherrypy/_cprequest.py", line 670, in respond
    response.body = self.handler()
  File "/usr/local/lib/python3.4/dist-packages/cherrypy/lib/encoding.py", line 217, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/cherrypy/_cpdispatch.py", line 61, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/home/mschuett/python/CherryBlog/CherryBlog/admin.py", line 49, in settings
    title = admin.AdminModel.getKey("site_title")
  File "/home/mschuett/python/CherryBlog/CherryBlog/models/admin.py", line 63, in getKey
    return cursor.fetchone()[1]
TypeError: 'NoneType' object is not subscriptable

repr output of key 'site_title'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment