Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'insert': 0.05; 'schema': 0.05; 'subject:Python': 0.06; 'intermediate': 0.07; 'table.': 0.07; 'cursor': 0.09; 'executed': 0.09; 'method,': 0.09; 'null,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'creates': 0.14; '...,': 0.16; 'adapter': 0.16; 'comma,': 0.16; 'expecting': 0.16; 'message):': 0.16; 'message-id:@4ax.com': 0.16; 'parameters,': 0.16; 'portable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'shortcut': 0.16; 'skip:> 20': 0.16; 'tuple': 0.16; 'tuple.': 0.16; 'topics': 0.16; 'exists': 0.24; 'url:home': 0.24; 'mon,': 0.24; "haven't": 0.24; 'second': 0.26; 'primary': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'statement': 0.30; 'code': 0.31; 'author,': 0.31; 'file': 0.32; '(most': 0.33; 'call.': 0.33; 'actual': 0.34; 'table': 0.34; 'created': 0.35; '14,': 0.36; 'skip:> 10': 0.36; "didn't": 0.36; 'method': 0.36; 'christian': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'new': 0.61; 'more': 0.64; 'here': 0.66; 'subject:there': 0.68; 'given.': 0.84; 'id,': 0.84; 'message)': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Is there an easy way to control indents in Python Date: Mon, 20 Oct 2014 21:13:00 -0400 Organization: IISS Elusive Unicorn References: <54424691$0$12978$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: adsl-108-73-117-157.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES 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: 86 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413853991 news.xs4all.nl 2878 [2001:888:2000:d::a6]:54871 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79360 On Mon, 20 Oct 2014 17:04:09 -0200, Juan Christian declaimed the following: >Ok, new code using ?: > >import sqlite3 > >db = sqlite3.connect('db.sqlite') > > >def create_db(): Misnamed function... the "database" was created (if it didn't exist) when you did the .connect() call. Here you are defining the schema of a table. > db.execute(''' > CREATE TABLE TOPICS( > ID INT PRIMARY KEY NOT NULL, > URL VARCHAR NOT NULL, > AUTHOR VARCHAR NOT NULL, > MESSAGE VARCHAR NOT NULL > ); > ''') > Stylistic point -- I never use the connection.execute() form; as documented: execute(sql[, parameters]) This is a nonstandard shortcut that creates an intermediate cursor object by calling the cursor method, then calls the cursor’s execute method with the parameters given. More portable to create an actual cursor cur = db.cursor() and then cur.execute(...) > >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)) Presuming the adapter is expecting a tuple of parameters, you haven't provided one. Try with ..., (_id,) ) It is the comma, not the () that make a tuple. > cursor = db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE >ID = ?", (_id)) >ValueError: parameters are of unsupported type > {see prior comment} >------------- > >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 Well, sure... If it failed on the "select" statement you had already executed (and commited) the table create and the insert of one row. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/