本文整理汇总了C#中CUBRID.Data.CUBRIDClient.CUBRIDConnection.GetEncoding方法的典型用法代码示例。如果您正苦于以下问题:C# CUBRIDConnection.GetEncoding方法的具体用法?C# CUBRIDConnection.GetEncoding怎么用?C# CUBRIDConnection.GetEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUBRID.Data.CUBRIDClient.CUBRIDConnection
的用法示例。
在下文中一共展示了CUBRIDConnection.GetEncoding方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: cci_bind_param
public static int cci_bind_param(CUBRIDConnection conn, int handle, int index, T_CCI_A_TYPE a_type, CUBRIDParameter param, CUBRIDDataType u_type, char flag)
{
int ret = 0;
IntPtr p = IntPtr.Zero;
switch (param.CUBRIDDataType)
{
case CUBRIDDataType.CCI_U_TYPE_DATE:
case CUBRIDDataType.CCI_U_TYPE_TIME:
case CUBRIDDataType.CCI_U_TYPE_DATETIME:
case CUBRIDDataType.CCI_U_TYPE_TIMESTAMP:
string date = param.Value.ToString();
if (param.Value.GetType()== typeof(DateTime))
{
DateTime d = Convert.ToDateTime(param.Value);
date = string.Format("{0:u}", d);
date = date.Remove(date.Length - 1);
}
p = Marshal.StringToCoTaskMemAnsi(date);
ret = bind_param(handle, index, a_type, p, u_type, flag);
break;
case CUBRIDDataType.CCI_U_TYPE_SET:
case CUBRIDDataType.CCI_U_TYPE_MULTISET:
case CUBRIDDataType.CCI_U_TYPE_SEQUENCE:
IntPtr set = IntPtr.Zero;
string[] value = data_format((object[])param.Value, param.InnerCUBRIDDataType);
int[] indicator = new int[value.Length];
for (int i = 0; i < value.Length; i++)
{
if (value[i] != null)
{
indicator[i] = 0;
}
else
{
indicator[i] = 1;
}
}
//CUBRIDDataType.CCI_U_TYPE_STRING or param.InnerCUBRIDDataType
ret = cci_set_make(ref set, CUBRIDDataType.CCI_U_TYPE_STRING, value.Length, value, indicator);
if (ret < 0)
{
return ret;
}
ret = bind_param(handle, index, T_CCI_A_TYPE.CCI_A_TYPE_SET, set, param.CUBRIDDataType, flag);
cci_set_free(set);
break;
case CUBRIDDataType.CCI_U_TYPE_BLOB:
CUBRIDBlob blob = (CUBRIDBlob)param.Value;
bind_param(handle, index, T_CCI_A_TYPE.CCI_A_TYPE_BLOB, blob.GetPackedLobHandle(), param.CUBRIDDataType, flag);
break;
case CUBRIDDataType.CCI_U_TYPE_CLOB:
CUBRIDClob clob = (CUBRIDClob)param.Value;
bind_param(handle, index, T_CCI_A_TYPE.CCI_A_TYPE_CLOB, clob.GetPackedLobHandle(), param.CUBRIDDataType, flag);
break;
case CUBRIDDataType.CCI_U_TYPE_BIT:
case CUBRIDDataType.CCI_U_TYPE_VARBIT:
T_CCI_BIT bit = new T_CCI_BIT();
bit.size = ((byte[])param.Value).Length;
bit.buf = Marshal.AllocHGlobal(bit.size);
Marshal.Copy((byte[])param.Value, 0, bit.buf, bit.size);
p = Marshal.AllocHGlobal(Marshal.SizeOf(bit));
Marshal.StructureToPtr(bit, p, false);
ret = bind_param(handle, index, T_CCI_A_TYPE.CCI_A_TYPE_BIT, p, param.CUBRIDDataType, flag);
Marshal.FreeHGlobal(p);
break;
case CUBRIDDataType.CCI_U_TYPE_NULL:
ret = bind_param(handle, index, a_type, IntPtr.Zero, u_type, flag);
break;
default:
string bind_value = param.Value.ToString();
if (param.GetParameterEncoding().Equals(conn.GetEncoding()))
{
bind_value = Encoding.Default.GetString(conn.GetEncoding().GetBytes(param.Value.ToString()));
}
else
{
bind_value = Encoding.Default.GetString(param.GetParameterEncoding().GetBytes(param.Value.ToString()));
}
p = Marshal.StringToCoTaskMemAnsi(bind_value);
ret = bind_param(handle, index, a_type, p, u_type, flag);
break;
}
return ret;
}
示例3: cci_get_data
public static int cci_get_data(ResultTuple rt, int req_handle, int col_no, int type,CUBRIDConnection conn)
{
IntPtr value = IntPtr.Zero;
int indicator = 0, res=0;
switch ((CUBRIDDataType)type)
{
case CUBRIDDataType.CCI_U_TYPE_BLOB:
res = cci_get_data(req_handle, col_no, (int)T_CCI_A_TYPE.CCI_A_TYPE_BLOB, ref value, ref indicator);
CUBRIDBlob blob = new CUBRIDBlob(value,conn);
rt[col_no - 1] = blob;
break;
case CUBRIDDataType.CCI_U_TYPE_CLOB:
res = cci_get_data(req_handle, col_no, (int)T_CCI_A_TYPE.CCI_A_TYPE_CLOB, ref value, ref indicator);
CUBRIDClob clob = new CUBRIDClob(value,conn);
rt[col_no - 1] = clob;
break;
case CUBRIDDataType.CCI_U_TYPE_INT:
res = cci_get_data(req_handle, col_no, (int)T_CCI_A_TYPE.CCI_A_TYPE_STR, ref value, ref indicator);
if (Marshal.PtrToStringAnsi(value) == null)
{
rt[col_no - 1] = null;
}
else
{
rt[col_no - 1] = Convert.ToInt32(Marshal.PtrToStringAnsi(value));
}
if (is_collection_type((CUBRIDDataType)type))
{
rt.toArray(col_no - 1);
}
break;
case CUBRIDDataType.CCI_U_TYPE_BIGINT:
res = cci_get_data(req_handle, col_no, (int)T_CCI_A_TYPE.CCI_A_TYPE_STR, ref value, ref indicator);
rt[col_no - 1] = Convert.ToInt64(Marshal.PtrToStringAnsi(value));
if (is_collection_type((CUBRIDDataType)type))
{
rt.toArray(col_no - 1);
}
break;
case CUBRIDDataType.CCI_U_TYPE_OBJECT:
res = cci_get_data(req_handle, col_no, (int)T_CCI_A_TYPE.CCI_A_TYPE_STR, ref value, ref indicator);
string oid = Marshal.PtrToStringAnsi(value);
rt[col_no - 1] = new CUBRIDOid(oid);
break;
case CUBRIDDataType.CCI_U_TYPE_BIT:
T_CCI_BIT bit = new T_CCI_BIT();
res = cci_get_data(req_handle, col_no, (int)T_CCI_A_TYPE.CCI_A_TYPE_BIT, ref bit, ref indicator);
byte[] data = conn.GetEncoding().GetBytes(Marshal.PtrToStringAnsi(bit.buf));
rt[col_no - 1] = new byte[bit.size];
Array.Copy(data,(byte[])rt[col_no - 1] ,bit.size);
break;
default:
res = cci_get_data(req_handle, col_no, (int)T_CCI_A_TYPE.CCI_A_TYPE_STR, ref value, ref indicator);
if (value != IntPtr.Zero)
{
if (conn.GetEncoding().Equals(Encoding.UTF8))
{
Byte[] v = Encoding.Unicode.GetBytes(Marshal.PtrToStringUni(value));
int count = 0;
while (count < v.Length && v[count] != 0)
{
count++;
}
rt[col_no - 1] = Encoding.Unicode.GetString(Encoding.Convert(Encoding.UTF8, Encoding.Unicode, v, 0, count));
}
else
{
rt[col_no - 1] = Marshal.PtrToStringAnsi(value);
}
}
else {
rt[col_no - 1] = String.Empty;
}
if (is_collection_type((CUBRIDDataType)type))
{
rt.toArray(col_no - 1);
}
break;
}
return res;
}
示例4: cci_prepare
public static int cci_prepare(CUBRIDConnection conn_handle, string sql_stmt, ref T_CCI_ERROR err_buf)
{
int ret = cci_set_holdability(conn_handle.Conection,0);
if (ret < 0)
{
return ret;
}
sql_stmt = Encoding.Default.GetString(conn_handle.GetEncoding().GetBytes(sql_stmt));
return cci_prepare(
conn_handle.Conection, sql_stmt,
(char)(T_CCI_PREPARE_FLAG.CCI_PREPARE_INCLUDE_OID|
T_CCI_PREPARE_FLAG.CCI_PREPARE_UPDATABLE),
ref err_buf);
}
示例5: CUBRIDCommand
/// <summary>
/// Initializes a new instance of the <see cref="CUBRIDCommand" /> class.
/// </summary>
/// <param name="sql"> The SQL statement. </param>
/// <param name="conn"> The connection. </param>
public CUBRIDCommand(string sql, CUBRIDConnection conn)
: this(sql)
{
this.conn = conn;
paramCollection.SetParametersEncoding(conn.GetEncoding());
paramCollection.sql = sql;
}
示例6: 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();
}
}
示例7: CUBRIDCommand_CreateParameter_Test
public void CUBRIDCommand_CreateParameter_Test()
{
CUBRIDConnection conn = new CUBRIDConnection();
conn.ConnectionString = DBHelper.connString;
conn.Open();
DBHelper.ExecuteSQL("drop table if exists t", conn);
DBHelper.ExecuteSQL("create table t (clsid bit(288))", conn);
byte[] bytes = new byte[36]{55, 56, 50, 69, 55, 57, 67, 69,
45, 50, 70, 68, 68, 45, 52, 68,
50, 55, 45, 65, 51, 48, 48, 45,
69, 48, 56, 56, 70, 56, 68, 68,
55, 54, 66, 69};
string sql = "INSERT INTO t VALUES (?);";
CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);
CUBRIDParameter param = (CUBRIDParameter)cmd.CreateParameter();
param.ParameterName = "?p";
param.Value = bytes;
cmd.Parameters.Add(param);
cmd.Parameters[0].CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_BIT;
cmd.ExecuteNonQuery();
cmd.Close();
sql = "select * from t";
cmd = new CUBRIDCommand(sql, conn);
CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();
reader.Read();
byte[] buffer = (byte[])reader.GetValue(0);
string clsid = conn.GetEncoding().GetString(buffer);
Assert.AreEqual(clsid, "782E79CE-2FDD-4D27-A300-E088F8DD76BE");
reader.Close();
cmd.Close();
//Revert the test db
DBHelper.ExecuteSQL("drop table if exists t", conn);
conn.Close();
}