Koka / odbc-rs

Rust ODBC FFI binding
MIT License
98 stars 31 forks source link

get_data returns Chinese string error under windows #94

Closed gmg137 closed 5 years ago

gmg137 commented 5 years ago

The database returns a Chinese string. Running normally under linux, but compiling and running under windows will report the following error:

thread 'main' panicked at 'called Result::unwrap()on anErr value: Utf8Error { valid_up_to: 1, error_len: Some(1) }'
yuana1 commented 5 years ago

@gmg137 Have you solved it ?

yuana1 commented 5 years ago

@Koka When i open win10 utf-8 beta support, it works. image

I viewed source and find something. image can we send a user encoded bytes (like gbk bytes) to sqlserver?
as following

fn prepare_bytes(&mut self, sql_bytes: &[u8]) -> Return<()> {
        match unsafe {
            ffi::SQLPrepare(
                self.handle(),
                sql_bytes.as_ptr(),
                sql_bytes.len() as ffi::SQLINTEGER,
            )
        } {
            ffi::SQL_SUCCESS => Return::Success(()),
            ffi::SQL_SUCCESS_WITH_INFO => Return::SuccessWithInfo(()),
            ffi::SQL_ERROR => Return::Error,
            r => panic!("SQLPrepare returned unexpected result: {:?}", r),
        }
    }
gmg137 commented 5 years ago

@yuana1 没解决,我最后是直接把数据库返回数据换成英文了。。。推测是 odbc 的问题,因为我是相同的window sql server 数据库,在linux客户端下没问题,到windows客户端下就有问题了。。。。可能真是你说的那样,需要修改windows客户端的系统编码。

Koka commented 5 years ago

can we send a user encoded bytes (like gbk bytes) to sqlserver?

@yuana1 Thanks for your investigation! I have very little experience related to national encoding problems in Rust and have no ability to properly test such cases. It would be great if you could find places where non-utf8 support can be improved and prepare pull request with proposed fixes.

yuana1 commented 5 years ago

@Koka I will try it!

Koka commented 5 years ago

Fix published as 0.10.1