Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite dict cursors #588

Closed
ivan-kleshnin opened this issue Sep 3, 2012 · 2 comments
Closed

sqlite dict cursors #588

ivan-kleshnin opened this issue Sep 3, 2012 · 2 comments

Comments

@ivan-kleshnin
Copy link

There are whole sections based on assumption that sqlite has no built-in DictCursor behavior
http://flask.pocoo.org/docs/tutorial/views/#tutorial-views
http://flask.pocoo.org/docs/patterns/sqlite3/#easy-querying

Besides verbosity, by wrapping result in dict() we block transparent data passing to INSERT which waits for "tupled" format

Here is solution:
db = sqlite3.connect(app.config['DATABASE_NAME'])
db.row_factory = sqlite3.Row # trick!

While "print cur.fetchall()" still looks like tuples are here... don't worry, it supports key access:

for item in cur.fetchall():
print item['title'] # works!

So you can easily remove those custom wrappers which i saw copied here and there...

@mitsuhiko
Copy link
Contributor

Sounds like a good idea. Do you want to update the docs and send me a pull request?

soulseekah added a commit to soulseekah/flask that referenced this issue Nov 5, 2012
As pointed out in issue pallets#588 sqlite3.Row should be used instead of
using casting to dict(). Also altered the "Easy Querying" Patterns
example to include the more correct way to return rows as dicts.
Did not touch Tutorial examples ("Views"), as these are not up to
date with the current Flaskr code, and the "Show Entries" section
points out the "Easy Querying" section on how to convert to a
dict().
kennethreitz pushed a commit that referenced this issue Jan 25, 2013
 Use sqlite3.Row factory in Flaskr (#588)
@DasIch
Copy link
Contributor

DasIch commented Jun 19, 2013

Fixed with #625

@DasIch DasIch closed this as completed Jun 19, 2013
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants