简体   繁体   English

pymssql问题与255个字符后切断

[英]pymssql issue with cutting off after 255 characters

I have installed pymssql (using _mssql) version 1.0.2 and I noticed that when I start looking at the fields in the result set it appears to be cutting off large text fields at 255 characters max. 我已经安装了pymssql(使用_mssql)1.0.2版,并且注意到当我开始查看结果集中的字段时,它似乎切断了最多255个字符的大文本字段。 I scoured the internet for any mention of this but found nothing - I have no idea why it is cutting the string off at this point, but the database is definitely returning a longer string than that. 我在互联网上搜寻有关此内容的任何内容,但一无所获-我不知道为什么此时会切断字符串,但是数据库肯定会返回比该字符串更长的字符串。 Any help is appreciated - could it just be as easy as a version upgrade, or is this something I need to work around? 感谢您提供任何帮助-就像升级版本一样简单,还是我需要解决此问题?

Thanks! 谢谢!

As per your request, I am inserting an obscured code snippet detailing what I am talking about - this is a Python script on an Ubuntu system: 根据您的要求,我正在插入一个模糊的代码片段,详细说明我在说什么-这是Ubuntu系统上的Python脚本:

import sys
import shutil
import fileinput
import os
import _mssql

myServer = 'hostIP'
myUID = 'userID'
myPW = 'mypass'
myDB = 'theDBName'
theID  = 'ABC123'

myConn = _mssql.connect(server=myServer, user=myUID, password=myPW, database=myDB)
myConn.execute_query("SELECT method FROM myTable WHERE id = '" + theID + "'")

for myRow in myConn:
  method = myRow["method"]
  len(method) # This prints out 255
  len(myRow["method")) # This prints out 255

myConn.close()

FYI : the string returned from the database is over 900 characters in length, but I only see the first 255 of it. 仅供参考:从数据库返回的字符串长度超过900个字符,但我只看到它的前255个。

This appears to be a known issue with pymssql (or rather, the underlying protocol). 这似乎是pymssql(或更确切地说是底层协议)的已知问题

varchar and nvarchar data is limited to 255 characters, and longer strings are silently trimmed. varchar和nvarchar数据限制为255个字符,并且较长的字符串会被静默修剪。 This is known limitation of TDS protocol. 这是TDS协议的已知限制。 A workaround is to CAST or CONVERT that row or expression to text data type, which is capable of returning 4000 characters. 解决方法是将该行或表达式CAST或转换为文本数据类型,该数据类型可以返回4000个字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM