Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72688

Re: How to use SQLite (sqlite3) more efficiently

From Peter Otten <__peter__@web.de>
Subject Re: How to use SQLite (sqlite3) more efficiently
Date 2014-06-05 09:48 +0200
Organization None
References <6e18a509-9471-4fe8-8664-3c58fc17536f@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.10728.1401954515.18130.python-list@python.org> (permalink)

Show all headers | View raw


ps16thypresenceisfullnessofjoy@gmail.com wrote:

> I'm completely new to SQL, and recently started using SQLite in one of my
> Python programs. I've gotten what I wanted to work, but I'm not sure if
> I'm doing it in the best/most efficient way. I have attached some sample
> code and would appreciate any (polite) comments about how the SQL (or
> Python) in it could be improved. The code is written in Python 2, but I
> think it should work in Python 3 if the 4 print statements are changed to
> function calls. Am I correct that the function 'set_description2' should
> work the same way as 'set_description'?

> def set_description2(conn, name, description):
>     with conn:
>         if description:
>             conn.execute("INSERT OR REPLACE INTO ProgrammingLanguages " \
>                 "VALUES(?,?)", (name, description))
>         else:
>             conn.execute("DELETE FROM ProgrammingLanguages WHERE Name=?",
>                 (name,))
>     conn.commit()

Have a look at these to see how this can be wrapped into a dict-like object:

http://svn.python.org/view/sandbox/trunk/dbm_sqlite/alt/dbsqlite.py?view=markup
https://github.com/shish/sqliteshelf/blob/master/sqliteshelf.py

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

How to use SQLite (sqlite3) more efficiently ps16thypresenceisfullnessofjoy@gmail.com - 2014-06-04 13:27 -0700
  Re: How to use SQLite (sqlite3) more efficiently Chris Angelico <rosuav@gmail.com> - 2014-06-05 07:23 +1000
    Re: How to use SQLite (sqlite3) more efficiently Rustom Mody <rustompmody@gmail.com> - 2014-06-04 19:15 -0700
      Re: How to use SQLite (sqlite3) more efficiently Demian Brecht <demianbrecht@gmail.com> - 2014-06-04 20:35 -0700
      Re: How to use SQLite (sqlite3) more efficiently Chris Angelico <rosuav@gmail.com> - 2014-06-05 17:08 +1000
  Re: How to use SQLite (sqlite3) more efficiently Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-06-04 22:40 -0400
  Re: How to use SQLite (sqlite3) more efficiently Peter Otten <__peter__@web.de> - 2014-06-05 09:48 +0200

csiph-web