字节字符串太长PyPyOdbc [英] Byte string too long PyPyOdbc
问题描述
使用FreeTDS和Python3.5库PyPyodbc尝试在SQL Server数据库(位于Windows中)中插入一行时,出现了'Byte string too long'
的错误.
在FreeTDS conf文件下,有一个我已更改为的'text size'
副版本:
Using FreeTDS and Python3.5 library PyPyodbc I am getting a 'Byte string too long'
when trying to insert a row in the SQL Server database (residing on Windows).
Under FreeTDS conf file there is a vairable 'text size'
that I changed to:
[global]
text size = 4294967295
这是配置文件
/etc/freetds/freetds.conf
[global]
tds version = 4.2
text size = 4294967295
[sqlserver]
host = 192.168.0.3
port = 1433
tds version = 8.0
/etc/odbc.ini
[sqlserverdatasource]
Driver = freetds
Description = SQL Server
Servername = sqlserver
Database = MyDB
TDS_Version = 8.0
/etc/odbcinst.ini
[freetds]
Description = MS SQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
Trace = Yes
TraceFile = /tmp/freetds.log
FileUsage = 1
UsageCount = 1
执行'tsql -C'
:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
执行'/usr/bin/tsql -S 192.168.0.3 -U user'
:
Password:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
执行'odbcinst -j'
:
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/metheUser/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
Python PyPyodbc连接字符串:
Python PyPyodbc connection string:
connStr = 'DSN=sqlserverdatasource;Database=MyDB;uid=user;pwd=password'
但是错误不断出现,我所缺少的是什么?
But the error keeps appearing, what I am missing?
推荐答案
我终于发现了问题,除了在TDS_Version = 8.0中设置之外,在PyPyodbc中分配字符缓冲区还不够.我的查询至少有3100个字符.现在,直接将PyPyodbc更新为两倍即可.不确定是否需要四倍.
I finally found the problem, other than set in TDS_Version = 8.0, the allocation for a character buffer in PyPyodbc is not enough. My query has more than 3100 characters (at a minimum). Updating the PyPyodbc directly to double the amount was sufficient for now. Not sure if quadrupling it will be necessary.
为什么没有将此内容添加到库中?有关更多信息: https://github.com/jiangwen365/pypyodbc/issues/27
Why this not had been added to the library? For more info: https://github.com/jiangwen365/pypyodbc/issues/27
感谢 @GordThompson 帮助我发现各种可能性,并在他自己的环境中进行测试.
Thanks to @GordThompson to help me out with the possibilities and test it on his own environment.
这篇关于字节字符串太长PyPyOdbc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!