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


Groups > comp.lang.python > #33197

Re: Is there a way to creat a func that returns a cursor that can be used?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Is there a way to creat a func that returns a cursor that can be used?
Date 2012-11-12 15:41 -0500
References <05f7724a-1e41-43ea-b837-88e476917f9a@googlegroups.com> <CAPTjJmrPb0f7Oe8yR_oS4VOpfidWQKF-fRb2j_B1WqD3Z6EQzg@mail.gmail.com> <CAPM-O+z=N-zjk0xVvb-reP_xRfY02YYapFW_ftAFakwECkLNPQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3592.1352752925.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 11/12/2012 7:25 AM, Joel Goldstick wrote:

> Chris gave you the same help that you got yesterday.
...
> go to ://python.org> and read the tutorials,
> specifically about functions.

It is hard to see what is working and not with an empty database. But to 
drive the point home, running

import sqlite3

def connect():
     conn = sqlite3.connect(':memory:')#use sch3.db or sch4.db  .... etc.
     cur = conn.cursor()
     cur.execute("create table schedule (teams integer, sn integer, 
badge integer ,name text, grp integer,\
     major text, track text, stage text,  tc text, subject text, course 
text, ws text, date text, \
     time text, proctor text, code text, no integer,fl_time text, flag2 
text, flag3 text,\
     flag4 text, clash1 integer, clash2 integer)")
     return cur

cur = connect()
print(cur.fetchone())
cur.execute("select * from schedule")
print(cur.fetchall())

# prints
None
[]

So the change suggested by multiple people *does* work ;-).

On a different note: use triple quote for multi-line strings and 
backslashes are not needed.

     cur.execute('''create table schedule (teams integer, sn integer,
             badge integer ,name text, grp integer, major text,
             track text, stage text,  tc text, subject text, course text,
             ws text, date text, time text, proctor text, code text,
             no integer,fl_time text, flag2 text, flag3 text, flag4 text,
             clash1 integer, clash2 integer)''')

works fine. SQL treats newlines in statements as whitespace.

-- 
Terry Jan Reedy

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


Thread

Is there a way to creat a func that returns a cursor that can be used? Khalid Al-Ghamdi <emailkgnow@gmail.com> - 2012-11-12 02:45 -0800
  Re: Is there a way to creat a func that returns a cursor that can be used? Peter Otten <__peter__@web.de> - 2012-11-12 11:57 +0100
  Re: Is there a way to creat a func that returns a cursor that can be used? Chris Angelico <rosuav@gmail.com> - 2012-11-12 22:01 +1100
  Re: Is there a way to creat a func that returns a cursor that can be used? Terry Reedy <tjreedy@udel.edu> - 2012-11-12 15:41 -0500

csiph-web