Can not get the result of query in pymssql module of python...

Rod Person rodperson at rodperson.com
Thu Feb 9 07:31:56 EST 2012


On Thu, 9 Feb 2012 12:34:25 +0530
amarjeet yadav <amarjeet.java at gmail.com> wrote:

> Hi All,
>            This is my first post to any mailing group. I am QA engg
> and using python for testing automation. I need to connect with Mysql
> (2008) and mssql databases for executing some queries.
> 
> I have installed following modules & softwares in python 2.7 :
> 
> python 2.7.2
> setuptools
> MySQLdb Module
> pymssql module
> yum install mysql msql-devel freetdf
> 
> I have installed freetds 0.9version. After installation of all the
> above components, I have done following things
> 
> Python 2.6 (r26:66714, Apr  8 2010, 08:46:35)
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import pymssql
> >>> conn = pymssql.connect(host='mssql_server', user='_username',
> password='_password', database='_db',as_dict=True)
> >>> cur = conn.cursor()
> >>> cur.execute('select count(*) from D2.dbo.abc (nolock)')
> >>> print cur.fetchall()

What if you change this to 

	print cur.fetchone()

About 95% of my python database work is with MS SQL. I use fetchone when
as_dict is True and it seems to work better for me.

> []
> >>> cur.rowcount
> -1
> >>> exit()
> 
> I am expecting that the result of the query will be 16. But it is not
> retuning any data from query with no error at any place. On execting
> the same query in tsql, I got result as 16.
> 



-- 

Rod Person  http://www.rodperson.com  rodperson at rodperson.com

'Silence is a fence around wisdom'



More information about the Python-list mailing list