【问题标题】:Python truncate at 255 chars when querying MS SqlServer with FreeTDS使用 FreeTDS 查询 MS SqlServer 时,Python 在 255 个字符处截断
【发布时间】:2012-11-03 03:04:23
【问题描述】:

我想我在 Debian 机器上的 FreeTDS 上使用 pyodbc 的 python 查询中遗漏了一些东西。我不能超过前 255 个字符。

如果我尝试按此处描述的 CAST SQL 数据:ODBC query on MS SQL Server returning first 255 characters only in PHP PDO (FreeTDS) 使用: SELECT CAST(myText as TEXT) FROM mytable 我得到空/零长度字符串,

我也进行了测试,但没有成功:使用下面的配置更改大小,我只得到前 255 个字符(例如,在我的 Win 框中 pyodbc 可以得到 279 个字符)。

这是一个示例查询:

SET TEXTSIZE 2147483647;
SELECT [id], myText , LEN(myText)
FROM    mytable

这是我的/etc/freetds/freetds/conf: (;@行首是什么意思?)

[global]
    # TDS protocol version
;   tds version = 4.2


#!!!added by me
client charset = UTF-8
text size = 4294967295 
#!!!/added by me

    # Whether to write a TDSDUMP file for diagnostic purposes
    # (setting this to /tmp is insecure on a multi-user system)
;   dump file = /tmp/freetds.log
;   debug flags = 0xffff

    # Command and connection timeouts
;   timeout = 10
;   connect timeout = 10

    # If you get out-of-memory errors, it may mean that your client
    # is trying to allocate a huge buffer for a TEXT field.  
    # Try setting 'text size' to a more reasonable limit 
    #!!!changed by me
    #text size = 64512

其他的配置文件是:

> cat /etc/odbc.ini #/etc/odbc.ini is empty! is it ok?
> cat /etc/odbcinst.ini
[FreeTDS]
Description=TDS driver (Sybase/MS SQL)
Driver=/usr/lib/odbc/libtdsodbc.so
Setup=/usr/lib/odbc/libtdsS.so
CPTimeout=
CPReuse=

我的 SQL 服务器在 192.168.1.2,我使用连接:

cnstr = 'DRIVER={FreeTDS};SERVER=192.168.1.2;DATABASE=MyDBName;UID=MyUID;PWD=MYPASSWD'
cursor = cnxn.cursor()
cursor.execute(SQL)
# etc.

感谢您的帮助,

最好的问候

【问题讨论】:

    标签: python pyodbc freetds


    【解决方案1】:

    ; 是什么意思@行首?

    它开始一个评论。 ma​​n freetds.conf 是你的朋友。 :-)

    我不能超过前 255 个字符。

    我怀疑您使用的是协议版本 4.2,因为您使用的是无 DSN 连接并且没有提及设置默认值。还因为 TDS 4.2 将 VARCHAR 列限制为 255 个字符。

    您可以将协议版本添加到您的连接字符串,参见。 http://www.freetds.org/userguide/odbcconnattr.htm

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多