Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '-----------': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; "'from": 0.16; '23,': 0.16; 'collections': 0.16; 'dict': 0.16; 'iterable,': 0.16; 'pairs': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'sequence.': 0.16; 'subclass': 0.16; 'subject:sqlite3': 0.16; 'there!': 0.16; 'tuple': 0.16; 'userdict': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'replacing': 0.19; 'work,': 0.20; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'subject:problem': 0.24; 'fairly': 0.24; 'fine': 0.24; 'looks': 0.24; 'skip:" 30': 0.26; 'pass': 0.26; 'values': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'url:bugs': 0.29; 'am,': 0.29; 'raise': 0.29; 'keyerror:': 0.31; 'file': 0.32; 'class': 0.32; 'url:python': 0.33; '(most': 0.33; 'table': 0.34; 'could': 0.34; 'subject: (': 0.35; 'subject:with': 0.35; 'equal': 0.35; 'but': 0.35; 'skip:" 50': 0.36; 'url:org': 0.36; 'january': 0.37; 'list': 0.37; 'clear': 0.37; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'called': 0.40; 'received:173': 0.61; 'skip:n 10': 0.64; 'yes': 0.68; 'age': 0.80; 'age)': 0.84; 'dict.': 0.84; 'received:fios.verizon.net': 0.84; 'works!': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: sqlite3 docbug (was problem with sqlite3) Date: Thu, 23 Jan 2014 05:43:26 -0500 References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390473818 news.xs4all.nl 2883 [2001:888:2000:d::a6]:47450 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64594 On 1/23/2014 12:35 AM, Rustom Mody wrote: > On Thursday, January 23, 2014 10:11:42 AM UTC+5:30, Chris Angelico wrote: >> I think it's fairly clear from the example that it has to be either a >> tuple or a dict. Looks fine to me. > > yes 'from the example' and only from there! 'parameters' is a single parameter, which could be called 'seq_dict'. Let(seq_dict) must equal the number of replacements. A dict with extra pairs raises. A list instead of a tuple does work, but not an iterable, so 'sequence'. A dict subclass works, but a UserDict is treated as a sequence. ----------- import sqlite3 con = sqlite3.connect(":memory:") cur = con.cursor() cur.execute("create table people (name_last, age)") who = "Yeltsin" age = 72 s = (who, age) d = {'who':who, 'age':age} class D(dict): pass dD = D(d) from collections import UserDict dU = UserDict(d) # This is the qmark style: cur.execute("insert into people values (?, ?)", s) # And this is the named style: cur.execute("select * from people where name_last=:who and age=:age", dU) print(cur.fetchone()) -------------- >>> Traceback (most recent call last): File "C:\Programs\Python34\tem.py", line 23, in cur.execute("select * from people where name_last=:who and age=:age", dU) File "C:\Programs\Python34\lib\collections\__init__.py", line 883, in __getitem__ raise KeyError(key) KeyError: 0 Replacing dU in the last call with s works! http://bugs.python.org/issue20364 -- Terry Jan Reedy