sqlite3 question

Rob Wolfe rw at smsnet.pl
Thu Apr 12 10:06:52 CEST 2007


Jorgen Bodde wrote:

> All I can think of is a 'crappy' construction where I use the iterator
> to see if there was something in there, but surely, there must be a
> better way to know?
>
> >>> r = c.execute('select * from song where id = 2')
> >>> notfound = True
> >>> for s in r:
> ... 	notfound = False
> ... 	print s
> >>> if notfound:
> ... 	print 'No rows'
>
> I am pretty new with Python, maybe there are some properties of an
> iterator / sqlite3 I am not aware of that can tell me how many rows
> are there?

What about this:

if not c.fetchone():
  print "No rows"

or

print "rowcount=", len(cur.fetchall())

--
HTH,
Rob




More information about the Python-list mailing list