un-tuple (newbie)

Dang Griffith noemail at noemail4u.com
Tue Dec 2 13:54:45 CET 2003

On Mon, 01 Dec 2003 11:30:20 +0100, Martin Doering <doeringm at gmx.de>

>I want to use Jython to fetch exactly one value from a database query,
>like here:
># execute a query
>def query(db, sql):
>    c = db.cursor()
>    c.execute(sql)
>    for line in c.fetchall():
>        val = line
>        print val
>    c.close()
>    return val
>I could find out, how to create a tuple with just one member, but I
>can not find out how to get a value from a tuple with just one member.

You might check your database manual.  You might be able to have the
query return only one row.  E.g., in Oracle, you can add 
"and rownum=1" to the query and you'll only get back one row. Since it
looks like you're opening, fetching and closing the cursor all in one
function, and you said you only want one row, you should save some
disk and cpu and bandwidth cycles and make your query more precise.

More information about the Python-list mailing list