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


Groups > comp.lang.python > #72804

Re: How to use SQLite (sqlite3) more efficiently

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ps16thypresenceisfullnessofjoy@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'insert': 0.05; 'continuation': 0.07; '%s"': 0.09; 'attachment.': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; 'thread': 0.14; 'changes': 0.15; '"making': 0.16; '"python",': 0.16; '"re:"': 0.16; '(now': 0.16; '(without': 0.16; '__future__': 0.16; 'backslash': 0.16; "chris'": 0.16; 'did.': 0.16; 'end).': 0.16; 'fyi,': 0.16; 'name):': 0.16; 'posters': 0.16; 'subject:sqlite3': 0.16; 'url:py': 0.16; 'attach': 0.16; 'followed': 0.16; 'language': 0.16; 'code.': 0.18; 'not,': 0.20; 'url:view': 0.20; 'help.': 0.21; 'import': 0.22; 'issue.': 0.22; 'header:User- Agent:1': 0.23; 'exists': 0.24; 'replace': 0.24; 'post': 0.26; 'primary': 0.26; 'subject:) ': 0.29; 'skip:( 20': 0.30; "i'm": 0.30; 'code': 0.31; 'easier': 0.31; 'posting': 0.31; 'that.': 0.31; 'fine,': 0.31; 'minor': 0.31; 'probably': 0.32; 'front': 0.32; 'languages': 0.32; 'text': 0.33; 'url:python': 0.33; 'guess': 0.33; 'table': 0.34; 'at:': 0.34; 'skip:d 20': 0.34; 'message.': 0.35; 'subject: (': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'version': 0.36; 'c++': 0.36; 'doing': 0.36; "i'll": 0.36; 'should': 0.36; 'too': 0.37; 'message- id:@gmail.com': 0.38; 'thank': 0.38; 'lists.': 0.38; 'to:addr :python-list': 0.38; 'explain': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'mailing': 0.39; 'how': 0.40; 'easy': 0.60; 'above,': 0.60; 'mentioned': 0.61; 'new': 0.61; 'course': 0.61; "you're": 0.61; "you'll": 0.62; 'group,': 0.63; 'url:group': 0.63; 'subject:more': 0.64; 'relatively': 0.65; 'reply': 0.66; 'latest': 0.67; 'sample': 0.67; 'url:0': 0.67; 'improvements': 0.68; 'subject': 0.69; 'e-mail,': 0.69; ':).': 0.84; 'characters,': 0.84; 'paradox': 0.84; 'timothy': 0.84; 'url:lang': 0.84; 'absolutely': 0.87; '***': 0.95; 'instructed': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=Bqx/XSO3UrtoVQT5UoKMaxhpgM4TZnj5PYOCsxCfXBA=; b=sFpHtg4/mVVnzaELY68s8ZzduC5kd7+DbfwFP6DCJWvKW58h13Q2M+VfOXe5jDH7hf ne+Oi63a/B5Yz6RIGEmfeDjS08hiwstFw3aC7IiL7+LEJb7qddvKsiPxY8qLtqD/jPhe nirvHiJAJuOkhVuOjoMTvgtOIUxZ8C3Pl9g3nHGitINJE/HemlZOpKgHq4Cw1LyN/yMn 1CYx63KaeT9mSkNCgNq2h6dyKX8eCYlyE+x0nBXxNhKVojRn9kLTCvFYaXQiotLOKd2D 2kNRbTDlUmJ4B7IfNgPzdLi/j3l5ozTWj8POEGkLvAqZCu+NDzLvP3j4mdOY2gcyh3AG 3zqg==
X-Received by 10.224.147.80 with SMTP id k16mr1378386qav.40.1402009061926; Thu, 05 Jun 2014 15:57:41 -0700 (PDT)
Date Thu, 05 Jun 2014 18:57:39 -0400
From R Johnson <ps16thypresenceisfullnessofjoy@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: How to use SQLite (sqlite3) more efficiently
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Antivirus avast! (VPS 140605-3, 06/05/2014), Outbound message
X-Antivirus-Status Clean
X-Mailman-Approved-At Fri, 06 Jun 2014 03:08:27 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10796.1402016908.18130.python-list@python.org> (permalink)
Lines 83
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402016908 news.xs4all.nl 2882 [2001:888:2000:d::a6]:44463
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72804

Show key headers only | View raw


Sorry for the attachment issue. I'm used to the wxPython-users Google 
group, where posters are instructed to attach code to their post instead 
of including it in the body of the message.
I placed the latest version of my sample code below, since I made a few 
minor changes to it after posting it as that attachment. (I changed 
REPLACE to INSERT OR REPLACE as I mentioned above, followed Chris' 
suggestion to not use backslash continuation characters, and changed the 
description of C++ as mentioned below.)
FYI, you can also view the version (now outdated) that I had attached on 
the Google Groups website at:
https://groups.google.com/group/comp.lang.python/attach/bd64353c8dfd43ad/sqlite_test.py?part=0.1&view=1

 > > OK, I'll admit that I don't know Assembly :). How about the paradox
 > "Making
 > > Easy Things Hard & Hard Things Easy"? Although that might make my
 > > description of C++ too unfair; suggestions for improvements to my
 > language
 > > descriptions are welcome :).
 >
 > Hehe. As I'm sure you're aware, this has absolutely nothing to do with
 > your SQL or Python code.

Of course :). It's just for fun. I changed the description for C++ to 
"Making Easy Things Hard & Hard Things Hard" (without the -er on the end).

 > (Suggestion: Always reply to an existing post if it's part of the same
 > thread. Replying to your own post is fine, and it links the thread
 > together nicely.)

Sorry about that. As you can probably tell, I'm relatively new to using 
mailing lists. I'm not exactly sure why that occurred like it did. I'll 
try adding "Re:" in front of the subject when I send this e-mail, and 
see if it works right this time. If not, I guess you'll have to please 
explain to me what I'm doing wrong.

Thank you again for your help.

-- Timothy

*** sqlite_test.py ***
from __future__ import print_function
import sqlite3


def get_description(conn, description):
     row = conn.execute("SELECT description FROM languages WHERE name=?",
         (description,)).fetchone()
     if row:
         return row[0]


def set_description(conn, name, description):
     conn.execute("INSERT OR REPLACE INTO languages VALUES(?,?)",
         (name, description))
     conn.commit()


def delete_language(conn, name):
     conn.execute("DELETE FROM languages WHERE name=?", (name,))
     conn.commit()


conn = sqlite3.connect(":memory:")
conn.execute("CREATE TABLE IF NOT EXISTS languages(name TEXT PRIMARY KEY, "
     "description TEXT NOT NULL)")
set_description(conn, "Perl", "Making Easy Things Easy & Hard Things 
Possible")
set_description(conn, "Python", "Making Easy Things Easier & Hard Things 
Easy")
set_description(conn, "C++", "Making Easy Things Hard & Hard Things Hard")
for language in ("Perl", "Python", "C++"):
     print("%s: %s" % (language, get_description(conn, language)))
set_description(conn, "Assembly", "Making Easy Things Very Hard & "
     "Hard Things Impossible (Hey, that's not fair!)")
print("Assembly: %s" % get_description(conn, "Assembly"))
set_description(conn, "Assembly",
     "Making Easy Things Hard & Hard Things Easy")
print("Assembly: %s" % get_description(conn, "Assembly"))  # Should be 
changed
delete_language(conn, "Assembly")
print("Assembly: %s" % get_description(conn, "Assembly"))  # Should be None
conn.close()

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


Thread

Re: How to use SQLite (sqlite3) more efficiently R Johnson <ps16thypresenceisfullnessofjoy@gmail.com> - 2014-06-05 18:57 -0400

csiph-web