freetds的:如何设置参数的字符集运行存储过程 [英] FreeTDS: How to set charset of parameters running stored procedure

查看:1299
本文介绍了freetds的:如何设置参数的字符集运行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要通过 freetds的

C程序连接到MSSQL数据库

我试图用设置为类似赛达Liberada一个varchar参数来执行存储过程,但它被存储在MS SQL奇怪的字符,如上面的截图:

赛达Liberada与错误的字符

下面是我的freetds.conf:

 #$编号:freetds.conf,V 1.12 2007年12月25日6时02分36秒jklowden精通$

#此文件由freetds的安装,如果由同一个没有文件
#名称在安装目录中找到。

#有关此文件及其设置的布局信息,
#看到freetds.conf联机帮助的人freetds.conf。#全局设置是由那些在数据库覆盖
#服务器的特定部分
[全球]
        #TDS协议版本
        TDS版本= 8.0        #是否写诊断目的的TDSDUMP文件
        #(此设置到/ tmp是不安全的多用户系统上)
        转储文件= /tmp/freetds.log
;调试标志= 0xFFFF的        #指挥和连接超时
;超时= 10
;连接超时= 10        #如果你得到了内存不足的错误,这可能意味着你的客户
        #试图分配巨大的缓冲区的文本字段。
        #尝试设置'文字大小到一个更合理的限度
        文字大小= 64512        客户端字符集= UTF-8

下面是TDS转储文件的部分:

  log.c:196:启动日志文件freetds的0.91
        在2016年5月17日19时19分41秒与调试标志0x4fff。
iconv.c:330:tds_iconv_open(0xaed19130,ISO-8859-1)
iconv.c:353:利用琐碎的iconv
iconv.c:187:为ISO-8859-1本地名称是ISO-8859-1
iconv.c:187:UTF-8的本地名称是UTF-8
iconv.c:187:为UCS-2LE本地名称为UCS-2LE
iconv.c:187:为UCS-2BE本地名称为UCS-2BE
iconv.c:349:客户端字符集设置转换ISO-8859-1
iconv.c:351:preparing的iconv为ISO-8859-1< - > UCS-2LE转换
iconv.c:391:preparing的iconv为ISO-8859-1< - > ISO-8859-1转换
iconv.c:394:tds_iconv_open:完成...net.c:741:发送数据包
0000 01 01 00 84 00 00 00 00-20 45 58 45 43 20 55 50 | ........ EXEC UP |
0010 5F 49 4E 53 45 52 54 4D-4F 56 49 45 4D 4E 54 4F | _INSERTM OVIMENTO |
0020 20 27 32 30 31 36 30-35 2D 2D 31 37 20 31 39 3A | 2016-0 5-17 19:|
0030 31 39 33 3A 2E 31 30 30-30 27 27 2C 30 30 30 30 | 19:31.00 0','0000 |
0040 30 30 30 30 30 30 36 34-38 33 30 35 37 30 33 30 | 00000064 83057030 |
0050 27 2C 27 53 27 2C 30 2C-32 2C 27 50 43 56 43 30 |','S',0,2,'PCVC0 |
0060 34 20 20 3D 53 61 C3广告64 61 20 69 4C 65 62 72 | 4 =萨..达莱博|
0070 61 64 61 27 34 2C 2C 27-50 43 56 43 41 4D 4E 41 | ADA',4'PCVCMANA |
0080 47 45 52 27 - | GER'|

根据该freetds的日志,它发送的字符I(我急)为C3的广告,这意味着它在发送为UTF-8(拉丁文小写的i急性)。

我如何设置客户端或服务器,因此字符串可以妥善保存?

更新1:

 #TSQL -C
编译时设置(与configure脚本建立)
                            版本:freetds的v0.91
             freetds.conf目录:/等等
     MS DB-LIB源代码兼容性:无
        SYBASE二进制兼容性:是
                      线程安全:是
                      的iconv库:无
                        TDS版本:4.2
                              iODBC的:无
                           的unixODBC:是
              SSPI值得信赖的登录:无
                           Kerberos的:无

更新2

code连接:

  = RET的SQLDriverConnect(db_msserver_dbc_handle,
    空值, \"Driver={FreeTDS};Server=FooBar;Port=1433;Database=Foo;UID=sa;PWD=pwd@123;APP=XPTO;TDS_Version=8.0;\",
    SQL_NTS,outstr,sizeof的(outstr),放大器; outstrlen,
    SQL_DRIVER_COMPLETE);


解决方案

了很多的尝试后,我无法弄清楚,为什么freetds.conf设置(客户端字符集和TDS版本)不被尊重。至少,当我追加的 TDS_Version = 8.0; ClientCharset = UTF-8 连接​​字符串,它的作品!

记录是正确更改连接字符串当存储

<$p$p><$c$c>\"Driver={FreeTDS};Server=%s;Port=%s;Database=%s;UID=%s;PWD=%s;APP=%s;TDS_Version=8.0;ClientCharset=UTF-8\"

此外,freetds的标头日志文件被更改,提UTF-8的转换:

  log.c:196:启动日志文件freetds的0.91
        在2016年5月18日十五时58分49秒与调试标志0x4fff。
iconv.c:330:tds_iconv_open(0xaeb19118,UTF-8)
iconv.c:353:利用琐碎的iconv
iconv.c:187:为ISO-8859-1本地名称是ISO-8859-1
iconv.c:187:UTF-8的本地名称是UTF-8
iconv.c:187:为UCS-2LE本地名称为UCS-2LE
iconv.c:187:为UCS-2BE本地名称为UCS-2BE
iconv.c:349:客户端字符集设置转换UTF-8
iconv.c:351:preparing的iconv为UTF-8&下 - →; UCS-2LE转换
iconv.c:391:preparing的iconv为ISO-8859-1&LT; - &GT; UCS-2LE转换
iconv.c:394:tds_iconv_open:完成

I have a C program connecting to a MSSQL database through FreeTDS.

I'm trying to execute a stored procedure with a varchar parameter set to something like "Saída Liberada", but it's being stored with strange characters in MS SQL, as the screenshot above:

Here is my freetds.conf:

#   $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database
# server specific section
[global]
        # TDS protocol version
        tds version = 8.0

        # 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
        text size = 64512

        client charset = UTF-8

Here is parts of the tds dump file:

log.c:196:Starting log file for FreeTDS 0.91
        on 2016-05-17 19:19:41 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0xaed19130, ISO-8859-1)
iconv.c:353:Using trivial iconv
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "ISO-8859-1"
iconv.c:351:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion
iconv.c:394:tds_iconv_open: done

...

net.c:741:Sending packet
0000 01 01 00 84 00 00 00 00-20 45 58 45 43 20 55 50 |........  EXEC UP|
0010 5f 49 4e 53 45 52 54 4d-4f 56 49 4d 45 4e 54 4f |_INSERTM OVIMENTO|
0020 20 27 32 30 31 36 2d 30-35 2d 31 37 20 31 39 3a | '2016-0 5-17 19:|
0030 31 39 3a 33 31 2e 30 30-30 27 2c 27 30 30 30 30 |19:31.00 0','0000|
0040 30 30 30 30 30 30 36 34-38 33 30 35 37 30 33 30 |00000064 83057030|
0050 27 2c 27 53 27 2c 30 2c-32 2c 27 50 43 56 43 30 |','S',0, 2,'PCVC0|
0060 34 20 3d 20 53 61 c3 ad-64 61 20 4c 69 62 65 72 |4 = Sa.. da Liber|
0070 61 64 61 27 2c 34 2c 27-50 43 56 43 4d 41 4e 41 |ada',4,' PCVCMANA|
0080 47 45 52 27            -                        |GER'|

According to the freetds log, it's sending the character 'í' (i acute) as c3 ad, which means it's sending it as UTF-8 (LATIN SMALL LETTER I WITH ACUTE).

How can I setup the client or the server, so the string can be properly stored?

Update 1:

# tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v0.91
             freetds.conf directory: /etc
     MS db-lib source compatibility: no
        Sybase binary compatibility: yes
                      Thread safety: yes
                      iconv library: no
                        TDS version: 4.2
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: no
#

Update 2

Code to connect:

ret = SQLDriverConnect(db_msserver_dbc_handle,
    NULL,  "Driver={FreeTDS};Server=FooBar;Port=1433;Database=Foo;UID=sa;PWD=pwd@123;APP=XPTO;TDS_Version=8.0;",
    SQL_NTS, outstr, sizeof(outstr), &outstrlen,
    SQL_DRIVER_COMPLETE);

解决方案

After a lot of attempts, I couldn't figure out why freetds.conf settings (client charset and tds version) are not being respected. At least, when I append TDS_Version=8.0;ClientCharset=UTF-8 into the connection string, it works!

"Driver={FreeTDS};Server=%s;Port=%s;Database=%s;UID=%s;PWD=%s;APP=%s;TDS_Version=8.0;ClientCharset=UTF-8"

Also, the header of freetds log file is changed, mentioning UTF-8 conversion:

log.c:196:Starting log file for FreeTDS 0.91
        on 2016-05-18 15:58:49 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0xaeb19118, UTF-8)
iconv.c:353:Using trivial iconv
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "UTF-8"
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
iconv.c:394:tds_iconv_open: done

这篇关于freetds的:如何设置参数的字符集运行存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆