[DB-SIG] None Value??

Guido van Rossum guido at python.org
Mon Oct 6 18:45:04 EDT 2003

> On Monday, Oct 6, 2003, at 15:24 US/Pacific, Conrad Koziol wrote:
> > Hey what does MySQLdb return if it cant find the value. Like in the 
> > code
> > below, what if conrad does not exist in the table users, what would
> > result equal?
> >
> > db = MySQL.connect(host='localhost, user='conrad', passwd='python',
> > db='general')
> > cursor = db.cursor()
> > cursor.execute('SELECT conrad FROM users')
> > result = cursor.fetchall()

[Chris Cogdon]
> fetchall, in this instance, will return an empty list.
> if you run 'fetchone' when there are no, or no more, results, it 
> returns None.

Hm.  I'd think that if the table 'users' has no column 'conrad', this
would raise an exception saying approximately "ERROR 1054: Unknown
column 'foo' in 'field list'".  Certainly that's what the mysql test
client (no Python involved) does when I try this (on a random table
I've got lying around).

Or was the question about the connect() call?  I thought it was about
the SELECT statement.  (They both have a 'conrad'.)

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the DB-SIG mailing list