private static void Test_Encoding()
    {
        CUBRIDConnection conn = new CUBRIDConnection();

        conn.SetEncoding("cp1252");
        Debug.Assert(Encoding.GetEncoding("Windows-1252") == conn.GetEncoding());

        conn.SetEncoding("iso-8859-1");
        Debug.Assert(Encoding.GetEncoding("iso-8859-1") == conn.GetEncoding());

        conn.SetEncoding("euc-kr");
        Debug.Assert(Encoding.GetEncoding("euc-kr") == conn.GetEncoding());

        conn.SetEncoding("euc-jp");
        Debug.Assert(Encoding.GetEncoding("euc-jp") == conn.GetEncoding());

        conn.SetEncoding("gb2312");
        Debug.Assert(Encoding.GetEncoding("gb2312") == conn.GetEncoding());

        conn.SetEncoding("gbk");
        Debug.Assert(Encoding.GetEncoding("gbk") == conn.GetEncoding());

        conn.SetEncoding("xxxx");
        Debug.Assert(Encoding.Default == conn.GetEncoding());
    }
Exemple #2
0
        public void i18n_issue()
        {
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.ConnectionString = "server=test-db-server;database=demodb;port=33000;user=dba;password="******"utf-8");

            cmd.CommandText = "drop table if exists 测试表;";
            cmd.ExecuteNonQuery();

            cmd.CommandText = "create table 测试表 (名称 varchar);";
            cmd.ExecuteNonQuery();

            cmd.CommandText = "insert into 测试表 value('小明');";
            cmd.ExecuteNonQuery();

            cmd.CommandText = "select 名称 from 测试表;";
            CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(reader.GetString(0));
            };

            conn.Close();
        }
        public void GetEncoding_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;

                LogTestStep("set encoding and execute a sql in this encoding, then verify the encoding value");
                conn.SetEncoding("utf-8");
                conn.Open();

                DBHelper.ExecuteSQL("drop table if exists t", conn);
                DBHelper.ExecuteSQL("create table t(a int, b varchar(100))", conn);
                DBHelper.ExecuteSQL("insert into t values(1 ,'中文')", conn);

                String sql = "select * from t where b = '中文'";
                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read(); //retrieve just one row

                        Assert.AreEqual(1, reader.GetInt32(0));
                        Assert.AreEqual("中文", reader.GetString(1));
                    }
                }
                Assert.AreEqual(Encoding.GetEncoding("gbk"), conn.GetEncoding());
                LogStepPass();

                LogTestStep("test the other encodings");
                conn.SetEncoding("utf-8");
                Assert.AreEqual(conn.GetEncoding(), Encoding.UTF8);

                conn.SetEncoding("iso-8859-1");
                Assert.AreEqual(conn.GetEncoding(), Encoding.GetEncoding("iso-8859-1"));

                conn.SetEncoding("euc-kr");
                Assert.AreEqual(conn.GetEncoding(), Encoding.GetEncoding("euc-kr"));

                conn.SetEncoding("euc-jp");
                Assert.AreEqual(conn.GetEncoding(), Encoding.GetEncoding("euc-jp"));

                conn.SetEncoding("gb2312");
                Assert.AreEqual(conn.GetEncoding(), Encoding.GetEncoding("gb2312"));

                conn.SetEncoding("gbk");
                Assert.AreEqual(conn.GetEncoding(), Encoding.GetEncoding("gbk"));

                LogStepPass();

                //revert the test db
                DBHelper.ExecuteSQL("drop table t", conn);
                LogTestResult();
            }
        }
        public void SetEncoding_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;

                LogTestStep("set correct encoding for sql string");
                conn.SetEncoding("cp1252");
                conn.Open();

                DBHelper.ExecuteSQL("drop table if exists t", conn);
                DBHelper.ExecuteSQL("create table t(a int, b varchar(100))", conn);
                DBHelper.ExecuteSQL("insert into t values(1 ,'中文Goodこんにちは')", conn);

                String sql = "select * from t where b = '中文Goodこんにちは'";
                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read(); //retrieve just one row

                        Assert.AreEqual(1, reader.GetInt32(0));
                        Assert.AreEqual("中文Goodこんにちは", reader.GetString(1));
                    }
                }

                sql = "update t set b='中文Goodこんにちは'";
                DBHelper.ExecuteSQL(sql, conn);
                sql = "select * from t where b = '中文Goodこんにちは'";
                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read(); //retrieve just one row

                        Assert.IsTrue(reader.GetInt32(0) == 1);
                        Assert.IsTrue(reader.GetString(1) == "中文Goodこんにちは");
                    }
                }
                LogStepPass();

                LogTestStep("set wrong encoding for sql string");
                conn.SetEncoding("gbk");

                DBHelper.ExecuteSQL("drop table if exists t", conn);
                DBHelper.ExecuteSQL("create table t(a int, b varchar(100))", conn);
                DBHelper.ExecuteSQL("insert into t values(1 ,'中文Goodこんにちは')", conn);

                sql = "select * from t where b = '中文Goodこんにちは'";
                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {

                        reader.Read(); //retrieve just one row

                        Assert.AreEqual(1, reader.GetInt32(0));
                        Assert.AreEqual("中文Goodこんにちは", reader.GetString(1));
                    }
                }
                LogStepPass();

                //revert the test db
                DBHelper.ExecuteSQL("drop table t", conn);
                LogTestResult();
            }
        }