我尝试从 Linux 框(Python 2.7、Ubuntu 11.04)使用 python 连接到 MSSQL DB 。我收到的输出被截断为 500 个字符。请参阅下面的脚本和配置。怎么可能解决?我想在 ODBC 驱动程序中或附近的问题。
代码(pyodbc、pymssql):
conn = pymssql.connect(host='my_remote_host', user='ro_user',
password='password', database='current', as_dict=True)
cur = conn.cursor()
cur.execute(sql)
for i in cur:
print i
conn.close()
cnxn = pyodbc.connect(driver='FreeTDS', server='my_remote_host', database='current', uid='ro_user', pwd='password')
cursor = cnxn.cursor()
cursor.execute(sql)
rows = cursor.fetchall()
...
cnxn.close()
我对 MS SQL DB 没有写入权限,它实际上是不属于我们系统的远程服务器。
SQL:
sql = '''
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 = 1111111'''
问题出在ShReq.ALM_SharedText
场上。它被截断为 255 个字符,但使用像convert(text,ShReq.ALM_SharedText) AS TEXT
和CAST(ShReq.ALM_SharedText AS TEXT)
我这样的转换将截断增加到 500 个字符。但是,有些字段的文本长度超过 500 个字符,它们会被截断。
ODBC 设置:
/etc/odbc.ini
:
[MKS]
#Driver=FreeTDS
Driver=/usr/lib/odbc/libtdsodbc.so
Description=Database
Trace=No
Server=my_remote_host
Port=1433
Database=current
UID=ro_user
PWD=password
TDS Version=8.0
/etc/odbcinst.ini
:
[FreeTDS]
Description=FreeTDS
Driver=/usr/lib/odbc/libtdsodbc.so
UsageCount=1
/etc/freetds/freetds.conf
:
[global]
tds version = 8.0
; dump file = /tmp/freetds.log
; debug flags = 0xffff
; timeout = 10
; connect timeout = 10
; text size = 2097152
[mksserver]
host = my_remote_host
port = 1433
tds version = 8.0
client charset = UTF-8
任何想法如何解决?