ODBC Select

Stephen Prinster prinster at mail.com
Wed Nov 17 21:21:02 EST 2004


Larry wrote:
> I am trying to connect to my MySQL database using python and ODBC.
> 
> Here is what I am doing.
> 
>  >>> import dbi,odbc
>  >>> conn=odbc.odbc("dsn=facs")
>  >>> cursor=conn.cursor()
>  >>> cursor.execute("select * from data")
> 0
>  >>>
> 
> Notice I get the "0" after the select statement.
> Problem is, there are 20 records in the database.  In fact I can do this
> 
>  >>> cursor.execute("insert into data (facility) values ('AAA')")
> 1
>  >>>
> 
> and then I can do this
> 
>  >>> cursor.execute("delete from data where id > 20")
> 1
>  >>>
> 
> but when I do
> 
>  >>> cursor.execute("select * from data")
> 0
>  >>>
> 
> Anyone seen this and can maybe tell me why this is occuring.  I have 
> full privileges as I can log on and query with the DSN from other programs.
> 
> Thanks,
> Larry
> 
> 
> 
According to PEP 249, the return value for cursor.execute() is undefined 
and there seems to be little documentation for the ODBC module, so my 
guess (and I can't confirm it from home where I have no Windows) is that 
   0 indicates "success" and has nothing to do with the number of 
records.  Have you tried a "print cursor.fetchone()" to see if anything 
is there?



More information about the Python-list mailing list