问题描述
我想我错过了在 Debian 机器上通过 FreeTDS 使用 pyodbc 进行的 Python 查询中的某些内容.我不能超过前 255 个字符.
i think i have miss something in a query from python using pyodbc over a FreeTDS on a Debian machine. I can not manage to have more than the first 255 characters.
如果我尝试 CAST SQL 数据,如下所述:MS SQL Server 上的 ODBC 查询仅在 PHP PDO (FreeTDS) 中返回前 255 个字符 使用:SELECT CAST(myText as TEXT) FROM mytable
我得到空/零长度字符串,
if i try to CAST SQL data as describe here: ODBC query on MS SQL Server returning first 255 characters only in PHP PDO (FreeTDS) with :SELECT CAST(myText as TEXT) FROM mytable
i get empty/zero length string,
我也进行了测试,但没有成功:按照下面的配置描述更改大小,我只能得到前 255 个字符(例如,在我的 Win 框中 pyodbc 可以得到 279 个字符).
i have also test with no more success to : change size as describe with the config below, i only get first 255 characters (while on my Win box pyodbc can get 279 characters, for example).
这是一个示例查询:
SET TEXTSIZE 2147483647;
SELECT [id], myText , LEN(myText)
FROM mytable
这是我的/etc/freetds/freetds/conf
:(;@行首是什么意思?)
here is my /etc/freetds/freetds/conf
:(what is the meaning of the ; @ beginning of line ?)
[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
上,我使用以下方式连接:
my SQL server is on 192.168.1.2
, and i connect by using :
cnstr = 'DRIVER={FreeTDS};SERVER=192.168.1.2;DATABASE=MyDBName;UID=MyUID;PWD=MYPASSWD'
cursor = cnxn.cursor()
cursor.execute(SQL)
# etc.
感谢您的帮助,
最好的问候
推荐答案
它开始评论.man freetds.conf 是您的朋友.:-)
It starts a comment. man freetds.conf is your friend. :-)
我不能超过前 255 个字符.
我怀疑您使用的是协议版本 4.2,因为您使用的是无 DSN 连接并且没有提到设置默认值.还因为 TDS 4.2 将 VARCHAR 列限制为 255 个字符.
I suspect you are using protocol version 4.2, because you're using a DSN-less connection and did not mention setting the default. Also because TDS 4.2 limits VARCHAR columns to 255 characters.
您可以将协议版本添加到您的连接字符串中,参见.http://www.freetds.org/userguide/odbcconnattr.htm.
You can add the protocol version to your connection string, cf. http://www.freetds.org/userguide/odbcconnattr.htm.
这篇关于使用 FreeTDS 查询 MS SqlServer 时,Python 在 255 个字符处截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!