最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

pymssqlntext字段调用问题解决方法

来源:动视网 责编:小采 时间:2020-11-27 14:39:15
文档

pymssqlntext字段调用问题解决方法

pymssqlntext字段调用问题解决方法:下面是调用方式: Example script - pymssql module (DB API 2.0) Example script - _mssql module (lower level DB access) 不过,在我使用过程中,发现,如果表中包含了ntext字段,就会出错,提示 不能用 DB-Library(如 ISQL)或
推荐度:
导读pymssqlntext字段调用问题解决方法:下面是调用方式: Example script - pymssql module (DB API 2.0) Example script - _mssql module (lower level DB access) 不过,在我使用过程中,发现,如果表中包含了ntext字段,就会出错,提示 不能用 DB-Library(如 ISQL)或


下面是调用方式:

Example script - pymssql module (DB API 2.0)

Example script - _mssql module (lower level DB access)

不过,在我使用过程中,发现,如果表中包含了ntext字段,就会出错,提示

不能用 DB-Library(如 ISQL)或 ODBC 3.7 或更早版本将 ntext 数据或仅使用

Unicode排序规则的 Unicode 数据发送到客户端。

查了一下,发现官方网站有解释:

Q: What means "Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library"?

A: If you connect to a SQL Server 2000 SP4 or SQL Server 2005, and if you make a SELECT query on a table that contains a column of type NTEXT, you may encounter the following error:
_mssql.error: SQL Server message 4004, severity 16, state 1, line 1:
Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier.

It's the SQL Server complaining that it doesn't support pure Unicode via TDS or older versions of ODBC. There's no fix for this error. Microsoft has deprecated DB-Library a long ago, in favor of ODBC, OLE DB, or SQL Native Client. Many new features of SQL 2005 aren't accessible via DB-Library so if you need them, you have to switch away from pymssql or other tools based on TDS and DB-Library.

A workaround is to change the column type to NVARCHAR (it doesn't exhibit this behaviour), or TEXT.

大概意思是,这是因为我们的pymssql使用早期的ODBC函数集来获取数据。后来微软才引入了ntext和nvarchar类型,但Microsoft并没有更新他们的 C-library,所以就没办法支持了。建议:将ntext修改为nvarchar或text.

显然,这不是个好的解决方法,那么是否就没有其他办法了呢?

还好,不用绝望,既然不支持ntext但支持text,那么我们只需要在输出时将ntext转换为text就好了,方法很简单:

SELECT cast ( field_name AS TEXT ) AS field_name

唯一的问题,可能是ntext和text字段所支持的长度不一样,所以也许你还需要设置一下TEXTSIZE

SET TEXTSIZE 65536

当然,你还可以将字段设置的大一点,这个就看你的需要了。

文档

pymssqlntext字段调用问题解决方法

pymssqlntext字段调用问题解决方法:下面是调用方式: Example script - pymssql module (DB API 2.0) Example script - _mssql module (lower level DB access) 不过,在我使用过程中,发现,如果表中包含了ntext字段,就会出错,提示 不能用 DB-Library(如 ISQL)或
推荐度:
标签: 调用 ntext pymssql
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top