通过unixODBC和FreeTDS从MSSQL返回西里尔字符的问题 [英] Issue with returning Cyrillic symbols from MSSQL via unixODBC and FreeTDS

查看:181
本文介绍了通过unixODBC和FreeTDS从MSSQL返回西里尔字符的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在远程主机上使用django-pyodbc作为Ubuntu 12.04 LTS和MSSQL 2008上的数据库后端。除了返回西里尔字符之外,它的效果很好。而不是他们,我看到问号 - '?'。我开始调查可能会导致这个问题。

I'm using django-pyodbc as database backend on Ubuntu 12.04 LTS and MSSQL 2008 on remote host. It works good except of returning Cyrillic symbols. Instead of them I see question marks - '?'. I have begin investigation what could cause this problem.

据我所知MSSQL-django链看起来如此:

As far as I understand MSSQL-django chain looks so:

MSSQL< - > FreeTDS< - > unixODBC< - > pyodbc< - > django-pyodbc

MSSQL <-> FreeTDS <-> unixODBC <-> pyodbc <-> django-pyodbc

所以我从FreeTDS开始。当我在tsql中运行查询时,它工作得很好,我可以看到所有符号,包括西里尔文。

So I have started from FreeTDS. When I run query in tsql - it works good I can see all symbols including Cyrillic.

下一个是isql - 据我所知,我可以测试FreeTDS< ; - > unixODBC对。
那里我没有得到正确的数据。实际上,当我在包含西里尔字符串的isql列中运行查询是空的或由不可见的符号组成时。我猜这个FreeTDS之间的沟通问题unixODBC。什么可能导致这个问题? Btw,我也尝试过iusql - 没有任何改变。

The next one was isql - as far as I understand there I can test FreeTDS <-> unixODBC pair. And there I didn't get proper data. In fact when I run query in isql columns that contain Cyrillic symbols are empty or consist of not visible symbols. I guess that problem in communication between FreeTDS <-> unixODBC. What could cause this problem? Btw, I have also tried iusql - nothing have changed.

MSSQL排序规则是Cyrillic_General_CI_AS。

MSSQL collation is Cyrillic_General_CI_AS.

freetds.conf的内容:

[global]
tds version = 4.2
dump file = /tmp/freetds.log
debug flags = 0xffff
timeout = 10
connect timeout = 10
client charset = UTF-8
text size = 64512

[egServer50]
host = symachine.domain.com
port = 5000
tds version = 5.0

[egServer70]
host = ntmachine.domain.com
port = 1433
tds version = 7.0

[rfxdigest]
host = mssql-iis-1
port = 1433
tds version = 8.0
client charset = UTF-8

odbc.ini的内容:

[RFX]
Description = Rfx digest server
Driver = FreeTDS
Database = RFXDB
Servername = rfxdigest
TDS_Version = 8.0 

Edit1 15.08.12

在python使用pyodbc我得到'?'而不是西里尔字符 - 我已经尝试了两个python版本:UCS2和UCS4。

In python using pyodbc I get '?' instead of Cyrillic symbols - I have tried both python versions: UCS2 and UCS4.

推荐答案

好的,我已经使所有的这个模块链工作:

Ok, I have made all this modules chain work:

MSSQL <-> FreeTDS <-> unixODBC <-> pyodbc <-> django-pyodbc

我刚添加了'unicode_results':在django设置中的DATABASES选项中为True: p>

I just have added 'unicode_results':True in DATABASES options in django settings:

DATABASES = {
'default': {
    'ENGINE': 'sql_server.pyodbc', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'name',                      # Or path to database file if using sqlite3.
    'USER': 'user',                      # Not used with sqlite3.
    'PASSWORD': 'pwd',                  # Not used with sqlite3.
    'HOST': 'server-name',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': 'port',                      # Set to empty string for default. Not used with sqlite3.
    'OPTIONS': {
            'unicode_results':True,
            'driver': 'FreeTDS',
            'host_is_server': True,
            'extra_params': 'TDS_VERSION=8.0'
    }

但是pyodbc和isql仍然无法正常工作 - 也许我错过了其他unicode特定的参数。要检查odbc和pyodbc如何使用这个unicode_results参数。无论如何,网站现在可以显示西里尔字符。

But pyodbc and isql still doesn't work correctly - maybe I have missed other unicode-specific parameters. Going to check how odbc and pyodbc use this unicode_results parameter later. Anyway site now able to show Cyrillic symbols.

这篇关于通过unixODBC和FreeTDS从MSSQL返回西里尔字符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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