[DB-SIG] None Value??
chris at cogdon.org
Mon Oct 6 18:48:57 EDT 2003
On Monday, Oct 6, 2003, at 15:45 US/Pacific, Guido van Rossum wrote:
>> 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
>>> below, what if conrad does not exist in the table users, what would
>>> result equal?
>>> db = MySQL.connect(host='localhost, user='conrad', passwd='python',
>>> 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'.)
I was working on the assumption that Conrad meant 'there is no row
containing data "conrad"'. Of course, the SQL statement is a bit
botched, so this IS going to raise an exception :)
Conrad: I think you meant "SELECT * FROM users WHERE
username='conrad'", or something like that.
("`-/")_.-'"``-._ Chris Cogdon <chris at cogdon.org>
. . `; -._ )-;-,_`)
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.'
((,.-' ((,/ fL
More information about the DB-SIG