本文整理汇总了C#中CUBRID.Data.CUBRIDClient.CUBRIDConnection.SetEncoding方法的典型用法代码示例。如果您正苦于以下问题:C# CUBRIDConnection.SetEncoding方法的具体用法?C# CUBRIDConnection.SetEncoding怎么用?C# CUBRIDConnection.SetEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUBRID.Data.CUBRIDClient.CUBRIDConnection
的用法示例。
在下文中一共展示了CUBRIDConnection.SetEncoding方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Encoding
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());
}
示例2: i18n_issue
public void i18n_issue()
{
CUBRIDConnection conn = new CUBRIDConnection();
conn.ConnectionString = "server=test-db-server;database=demodb;port=33000;user=dba;password=";
conn.Open();
CUBRIDCommand cmd = new CUBRIDCommand();
cmd.Connection = conn;
conn.SetEncoding("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();
}
示例3: GetEncoding_Test
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();
}
}
示例4: SetEncoding_Test
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();
}
}