国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

pymssql ntext字段調(diào)用問(wèn)題解決方法

2019-11-25 18:45:29
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

下面是調(diào)用方式:

Example script - pymssql module (DB API 2.0)

Example script - _mssql module (lower level DB access)

不過(guò),在我使用過(guò)程中,發(fā)現(xiàn),如果表中包含了ntext字段,就會(huì)出錯(cuò),提示

不能用 DB-Library(如 ISQL)或 ODBC 3.7 或更早版本將 ntext 數(shù)據(jù)或僅使用

Unicode排序規(guī)則的 Unicode 數(shù)據(jù)發(fā)送到客戶端。

查了一下,發(fā)現(xiàn)官方網(wǎng)站有解釋:

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.

大概意思是,這是因?yàn)槲覀兊膒ymssql使用早期的ODBC函數(shù)集來(lái)獲取數(shù)據(jù)。后來(lái)微軟才引入了ntext和nvarchar類型,但Microsoft并沒(méi)有更新他們的 C-library,所以就沒(méi)辦法支持了。建議:將ntext修改為nvarchar或text.

顯然,這不是個(gè)好的解決方法,那么是否就沒(méi)有其他辦法了呢?

還好,不用絕望,既然不支持ntext但支持text,那么我們只需要在輸出時(shí)將ntext轉(zhuǎn)換為text就好了,方法很簡(jiǎn)單:

SELECT cast ( field_name AS TEXT ) AS field_name

唯一的問(wèn)題,可能是ntext和text字段所支持的長(zhǎng)度不一樣,所以也許你還需要設(shè)置一下TEXTSIZE

SET TEXTSIZE 65536

當(dāng)然,你還可以將字段設(shè)置的大一點(diǎn),這個(gè)就看你的需要了。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 潞西市| 公主岭市| 梅河口市| 鄯善县| 神池县| 西贡区| 瓮安县| 黄陵县| 大方县| 宁都县| 晋中市| 罗山县| 长白| 株洲县| 互助| 洞头县| 内黄县| 彭州市| 定边县| 中宁县| 电白县| 沂水县| 来安县| 宣恩县| 衢州市| 锡林浩特市| 察隅县| 兴仁县| 体育| 开化县| 青神县| 新民市| 苍南县| 保山市| 思茅市| 安图县| 衡水市| 花莲县| 泾源县| 施甸县| 双鸭山市|