Menu

Query gets strangely truncated

prantaaho
2009-04-08
2013-04-29
  • prantaaho

    prantaaho - 2009-04-08

    I have a strange problem with pymssql 1.0.1. My query gets truncated and SQL Server complains about syntax errors. The same code (shown at the end of the message) works fine with pymssql 0.8.0.

    Furthermore the code works if I add some imports before and after 'import pymssql' line, i.e.
      import sys
      import pymssql
      import os
    And it works!? What's happening here? However adding any class definition to the same file breaks the code again...

    Some debugging information: debug_queries prints OK query, no missing or additional characters there. But in freetds log there is:

    dblib.c:1243:dbcmd(0x81edcc0,  SELECT ...OK Here ...1-4101-BC9C-E50A542A5CA7'); ¨^A)

    Where did those characters after semicolon came from? And then it continues:

    write.c:136:tds_put_string converting 385 bytes of " SELECT ...OK...1-4101-BC9C-E50A^Q"

    Which, of course, is wrong and invalid SQL since closing quatation mark and parenthesis are missing.

    Both versions of pymssql are compiled  in this machine (x86, ubuntu 8.04) and freetds (0.82) is compiled from source .deb.

    I think this might be related to character encoding, my code is utf-8, in freetds.conf I have: tds version=8.0, client charset=UTF-8 and locale is "en_US.UTF-8"

    Any ideas what's going on?

    And finally the code:
    <code>
    import pymssql

    con = pymssql.connect(host='1.2.3.4:1433\SOFT', user='X', password='Y',
                          database='db1')
    cur=con.cursor()
    lastSeenGuid="6ACEB2A2-D461-4101-BC9C-E50A542A5CA7"
    query = r"""SELECT Headers.ID, Headers.Comment,
                      Headers.CashierCode,                                                
                      Headers.TranTimeStamp AS
                         TimeStamp,                                                              
                      Rows.RowItemCode AS
                         ItemCode                                                                     
                      FROM dbo.tblTillHeaders AS Headers INNER JOIN
                         dbo.tblTillRows AS Rows ON
                         Headers.ID=Rows.HeaderGUID
                      WHERE Rows.RowItemCode > %d AND Headers.TranTimeStamp >
                      ( SELECT TranTimeStamp FROM
                         dbo.tblTillHeaders                                                     
                       WHERE dbo.tblTillHeaders.ID = %s)"""
    cur._source.debug_queries=True                                                                                     
    cur.execute(query,(0,str(lastSeenGuid)))
    print cur.fetchall()
    </code>

     
    • A

      A - 2009-04-08

      This is a bug in pymssql. I am already aware of it. It'll be fixed in 1.0.2. Sorry for the inconvenience.

       
    • prantaaho

      prantaaho - 2009-04-08

      Thanks for the quick response.

      Is there already a patch for that somewhere, in CVS? Or is the best workaround to use version 0.8?

       
    • Fry

      Fry - 2009-04-20

      Hi

      Has there been any movement on this bug or a date for 1.0.2? I'm running into this as well and it's very annoying.

      Cheers

       
      • A

        A - 2009-04-21

        I'll try to do my best to release pymssql 1.0.2 by the end of next week.

         
    • Bjorn Pettersen

      Bjorn Pettersen - 2009-04-21

      Thanks.  (I'm running into the same issue...)

       
    • Markus Hubig

      Markus Hubig - 2009-04-23

      I also went into this issue and looking forward to v1.0.2 ...

       
      • A

        A - 2009-04-23

        This issue is already fixed in CVS. If you can pull it and compile yourself, you don't have to wait for 1.0.2 release. I have applied almost all patches and bugfixes and done limited testing, so it should be in pretty good shape. Any feedback is welcome.

         
      • Markus Hubig

        Markus Hubig - 2009-05-03

        Im using v 1.0.2 now and it works like a charm! Thanks!

         
        • A

          A - 2009-05-03

          Good to know. Have fun!

           
    • Markus Hubig

      Markus Hubig - 2009-04-23

      addition to my post:

      Screenshot of query within the M$SQL-Profiler

      http://twitpic.com/3tlll

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.