Multibyte (non-ascii string) supported in Snowflake ODBC Driver?

233 Views Asked by At

In snowflake portal, I created one table, DDL as below

create table test_multibytes(id int, varchar(16));

then inserted some rows, like

insert into myt_string2 values('1','中国我爱');
insert into myt_string2 values('2','こんにちは');
insert into myt_string2 values('2','你好');
insert into myt_string2 values('3','Tabelle enthält');
insert into myt_string2 values('4','안녕하세요');

It is fine when I view the data from the portal. but when I retrieve the data from the table through the Snowflake ODBC Drvier, It does not work, every non-ascii character shows as '0x3f' which is a '?'.

Then I changed my machine OS locale to Chinese, I can only get non-ascii(Chinese) correctly, but not for German and Korean rows.

Get Data All:
"NAME", "COUNTRY"
"1", "中国我爱"
"2", "こんにちは"
"2", "你好"
"3", "Tabelle enth?lt"
"4", "?????"
5 rows fetched from 2 columns.

Is there any other setting that I can do to get it work around? or is it a limitation for the current odbc driver? Looking forward to good news to me.

Thanks a lot.

2

There are 2 best solutions below

0
Greg Pavlik On

It's most likely a limitation of the control displaying the data.

I have an ODBC test project in C# and tested it with your table in a WPF Windows desktop DataGrid. It displays all your data correctly.

enter image description here

I have a WPF form with a DataGrid named dataGrid1. Here is the section of code that fills it with the results of a query to Snowflake through ODBC:

   try
    {

        OdbcConnection DbConnection = new OdbcConnection("DSN=" + dsnBox.Text + 
                                                         ";uid=" + userNameBox.Text +
                                                         ";pwd=" + passwordBox.Password);

        OdbcCommand DbCommandSetup = DbConnection.CreateCommand();
        DbConnection.Open();
        DbCommandSetup.CommandText = "use warehouse " + warehouseName.Text + ";";
        DbCommandSetup.ExecuteNonQuery();

        OdbcCommand DbCommand = DbConnection.CreateCommand();
        DbCommand.CommandText = sqlStatement;

        OdbcDataReader DbReader = DbCommand.ExecuteReader();

        int fCount = DbReader.FieldCount;

        DataTable dt = new DataTable();
        DataRow dr = null;
        String fName = null;

        for (int i = 0; i < fCount; i++)
        {
            fName = DbReader.GetName(i);
            dt.Columns.Add(fName, System.Type.GetType("System.String"));
        }

        while (DbReader.Read())
        {
            dr = dt.NewRow();
            for (int i = 0; i < fCount; i++)
            {
                if (!DbReader.IsDBNull(i))
                {
                    dr[i] = DbReader.GetValue(i).ToString();
                }
                else
                {
                    dr[i] = "{NULL}";
                }

            }
            dt.Rows.Add(dr);
        }
        dt.AcceptChanges();
        dataGrid1.DataContext = dt.DefaultView;
0
Dave Welden On

It may also be a font issue. You would need a font that has both Chinese, Korean, and German character support.