Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'parameters': 0.04; 'subject:Python': 0.06; '__name__': 0.09; 'cursor': 0.09; 'null,': 0.09; 'valueerror:': 0.09; 'def': 0.12; "'__main__':": 0.16; "'a',": 0.16; '23,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message):': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'topics': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'exists': 0.24; 'second': 0.26; 'primary': 0.26; 'values': 0.27; 'header:In-Reply- To:1': 0.27; "i'm": 0.30; 'code': 0.31; 'author,': 0.31; 'file': 0.32; '(most': 0.33; 'table': 0.34; 'created': 0.35; 'but': 0.35; '14,': 0.36; 'christian': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'new': 0.61; '30,': 0.65; 'subject:there': 0.68; 'certain,': 0.84; 'id,': 0.84; 'message)': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=V9zz0IXi c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=aoAcgTy3oA8A:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=wzhEKzvcAAAA:8 a=ITHzPFklFXkON854XvcA:9 a=QEXdDO2ut3YA:10 a=k2AMaFkwvfwA:10 X-AUTH: mrabarnett:2500 Date: Mon, 20 Oct 2014 20:43:36 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Is there an easy way to control indents in Python References: <9a0c67be-de3a-4770-bf06-e158783bfff0@googlegroups.com> <54424691$0$12978$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413834220 news.xs4all.nl 2836 [2001:888:2000:d::a6]:48547 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79327 On 2014-10-20 20:04, Juan Christian wrote: > Ok, new code using ?: > > import sqlite3 > > db = sqlite3.connect('db.sqlite') > > > def create_db(): > db.execute(''' > CREATE TABLE TOPICS( > ID INT PRIMARY KEY NOT NULL, > URL VARCHAR NOT NULL, > AUTHOR VARCHAR NOT NULL, > MESSAGE VARCHAR NOT NULL > ); > ''') > > > def insert_db(_id, url, author, message): > db.execute("INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES > (?, ?, ?, ?)", (_id, url, author, message)) > db.commit() > > > def get_db(_id): > cursor = db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE > ID = ?", (_id)) > return cursor.fetchone() > > > if __name__ == '__main__': > create_db() > insert_db(12, 'abc.com ', 'a', 'b') > print(get_db(12)) > db.close() > > ------------- > > But now when I execute I get > > Traceback (most recent call last): > File ".\sql.py", line 30, in > print(get_db(12)) > File ".\sql.py", line 23, in get_db > cursor = db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS > WHERE ID = ?", (_id)) > ValueError: parameters are of unsupported type > > ------------- > I'm not certain, but I think that the SQL type is called "INTEGER", not "INT". > And the second time, again, I get > > Traceback (most recent call last): > File ".\sql.py", line 28, in > create_db() > File ".\sql.py", line 14, in create_db > ''') > sqlite3.OperationalError: table TOPICS already exists > That's because you created the table the last time you ran it.