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

amarjeet yadav amarjeet.java at gmail.com
Thu Feb 9 08:04:25 CET 2012


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()
[]
>>> 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.

freetds.log file  :
############################################################################
mem.c:615:tds_free_all_results()
util.c:156:Changed query state from IDLE to QUERYING
write.c:140:tds_put_string converting 50 bytes of "select count(*) from
D2.dbo.abc (nolock)"
write.c:168:tds_put_string wrote 100 bytes
util.c:156:Changed query state from QUERYING to PENDING
net.c:741:Sending packet
0000 01 01 00 6c 00 00 01 00-73 00 65 00 6c 00 65 00 |...l.... s.e.l.e.|
0010 63 00 74 00 20 00 63 00-6f 00 75 00 6e 00 74 00 |c.t. .c. o.u.n.t.|
0020 28 00 2a 00 29 00 20 00-66 00 72 00 6f 00 6d 00 |(.*.). . f.r.o.m.|
0030 20 00 44 00 32 00 2e 00-64 00 62 00 6f 00 2e 00 | .D.2... d.b.o...|
0040 61 00 63 00 74 00 69 00-76 00 65 00 5f 00 61 00 |a.c.t.i. v.e._.a.|
0050 67 00 65 00 6e 00 74 00-73 00 20 00 28 00 6e 00 |g.e.n.t. s. .(.n.|
0060 6f 00 6c 00 6f 00 63 00-6b 00 29 00             |o.l.o.c. k.).|
dblib.c:4639:dbsqlok(0x99d1148)
dblib.c:4669:dbsqlok() not done, calling tds_process_tokens()
token.c:540:tds_process_tokens(0x998ff70, 0xbff42098, 0xbff42094, 0x6914)
util.c:156:Changed query state from PENDING to READING
net.c:555:Received header
0000 04 01 00 21 00 46 01 00-                        |...!.F..|
net.c:609:Received packet
0000 04 01 00 21 00 46 01 00-81 01 00 00 00 01 00 26 |...!.F.. .......&|
0010 04 00 d1 04 10 00 00 00-fd 10 00 c1 00 01 00 00 |........ ........|
0020 00                     -                        |.|
token.c:555:processing result tokens.  marker is  81(TDS7_RESULT)
token.c:1515:processing TDS7 result metadata.
mem.c:615:tds_free_all_results()
token.c:1540:set current_results (1 column) to tds->res_info
token.c:1547:setting up 1 columns
token.c:1486:tds7_get_data_info:
        colname =  (0 bytes)
        type = 38 (integer-null)
        server's type = 38 (integer-null)
        column_varint_size = 1
        column_size = 4 (4 on server)
token.c:1556: name                 size/wsize      type/wtype      utype
token.c:1557: -------------------- --------------- --------------- -------
token.c:1567:                            4/4            38/38            0
util.c:156:Changed query state from READING to PENDING
dblib.c:4700:dbsqlok() found result token
dblib.c:1813:dbnumcols(0x99d1148)
dblib.c:2761:dbcount(0x99d1148)
dblib.c:1813:dbnumcols(0x99d1148)
dblib.c:1839:dbcolname(0x99d1148, 1)
dblib.c:2831:dbcoltype(0x99d1148, 1)
dblib.c:2018:dbnextrow(0x99d1148)
dblib.c:2031:dbnextrow() dbresults_state = 1 (_DB_RES_RESULTSET_EMPTY)
dblib.c:2036:leaving dbnextrow() returning -2 (NO_MORE_ROWS)
dblib.c:2761:dbcount(0x99d1148)
dblib.c:1443:dbclose(0x99d1148)
dblib.c:258:dblib_del_connection(0xeff460, 0x998ff70)
mem.c:615:tds_free_all_results()
util.c:156:Changed query state from PENDING to DEAD
dblib.c:305:dblib_release_tds_ctx(1)
dblib.c:5882:dbfreebuf(0x99d1148)

####################################################################################


Please let me know what could be the issue? Am I forgettting to set any
variable ot conf file change. Is anyone has faced the same problem.


Thanks in Advance for your help....
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120209/2e633783/attachment.html>


More information about the Python-list mailing list