与freetds的查询MS SqlServer时,蟒截断在255个字符(Python truncat

2019-07-03 20:25发布

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.

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,

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).

here is a sample query :

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

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

the others conf files are:

> 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=

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.

thank u for any help,

best regards

Answer 1:

是什么的意思; @行首?

它注释的开始。 男人freetds.conf是你的朋友。 :-)

我不能设法比前255个字符。

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

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



文章来源: Python truncate at 255 chars when querying MS SqlServer with FreeTDS