clueboy / pymssql_issues

0 stars 0 forks source link

Text field ouptut is truncated to 500 chr #99

Open clueboy opened 11 years ago

clueboy commented 11 years ago

From einarum on August 07, 2012 08:41:17

using pymssql 2.0.0 with python 2.7, Ubuntu 11.04: pymssql-2.0.0b1_dev_20111018-py2.7-linux-x86_64.egg

import pymssql print pymssql.version $ 2.0.0

Output of long text fields truncated to maximum 500 characters. What steps will reproduce the problem? 1. Connect to MS SQL

  1. Select query

Example code:

doc_id = 1775286 conn = pymssql.connect(host='remote_server_IP', user='user', password='pass', database='current', as_dict=True) cur = conn.cursor() cur.execute(''' SELECT Req.ID, ShReq.Summary AS [Short Name], ShReq.ALM_SharedText AS TEXT, Req.ContainedBy, Req.DocumentID FROM CurMKS..ALM_Requirement Req JOIN CurMKS..ALM_SharedRequirement ShReq ON Req.[References] = ShReq.ID WHERE DocumentID = %s''' % str(doc_id)) for i in cur: print i, len(i[2]) conn.close()

When output is not full, we can see len = 500. The problem is with ShReq.ALM_SharedText field. Used "AS TEXT" - doesn't help. Originally it was "AS [Text]". Any solution or workaround? Thanks in advance!

Original issue: http://code.google.com/p/pymssql/issues/detail?id=99

clueboy commented 11 years ago

From csmith32 on June 16, 2013 17:35:26

Could this be related to "SET TEXTSIZE"? One of the MSSQL session options limits the number of characters returned from BLOB fields. Try adding a "SET TEXTSIZE=16536;" statement or some other reasonable size before your query execution.

Note that "AS TEXT" or variants thereof just changes the name of the column to text: it does not affect the type of the column in any way. Try using "CAST(ShReq.ALM_SharedText AS TEXT) AS SharedText" or "CAST(ShReq.ALM_SharedText AS VARCHAR(MAX)) AS SharedText" to actually convert the type.

I take it that CurMKS..ALM_SharedRequirement.ShReq is some kind of SQLCLR type with properties? What type is CurMKS..ALM_SharedRequirement.ShReq.ALM_SharedText defined as?

What version of MSSQL are you connecting to?

See also: http://msdn.microsoft.com/en-us/library/ms186238.aspx http://freetds.schemamania.org/userguide/troubleshooting.htm