Permalink
Browse files

[APIS-774] column name and table name should also support Encoding wi…

…th given charset (#9)

* [APIS-774] column name and table name should also support Encoding with given charset

* [APIS-774] define constant 254 as the max length of column and table name

* [APIS-774] define constant 254 as the max length of column and table name
  • Loading branch information...
byungwook-kim committed Aug 21, 2018
1 parent 378dcf1 commit b683b7a084c81a03a527c159885609de8db2071b
Showing with 61 additions and 20 deletions.
  1. +28 −8 Code/Src/CUBRIDCciInterface.cs
  2. +4 −3 Code/Src/CUBRIDCommand.cs
  3. +1 −1 Code/Src/CUBRIDDataReader.cs
  4. +28 −8 Code/Src/CUBRIDSchemaProvider.cs
@@ -156,10 +156,10 @@ internal struct T_CCI_COL_INFO
public char is_non_null;
public short scale;
public int precision;
public string col_name;
public string real_attr;
public string class_name;
public string default_value;
public IntPtr col_name;
public IntPtr real_attr;
public IntPtr class_name;
public IntPtr default_value;
public char is_auto_increment;
public char is_unique_key;
public char is_primary_key;
@@ -197,6 +197,7 @@ internal struct T_CCI_QUERY_RESULT

internal static class CciInterface
{
const int MAX_TBALE_COLUMN_NAME_LENGTH = 254;
const string dll_name = @"cascci.dll";
[DllImport(dll_name, EntryPoint = "cci_get_db_version", CharSet = CharSet.Ansi)]
public static extern int cci_get_db_version(int con_handle, StringBuilder out_buf, int capacity);
@@ -261,10 +262,12 @@ public static string cci_get_db_version(CUBRIDConnection conn_handle, int capaci
[DllImport(dll_name, EntryPoint = "cci_get_result_info", CharSet = CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
public static extern IntPtr cci_get_result_info_internal(int req_handle, ref int stmt_type, ref int col_num);

public static ColumnMetaData[] cci_get_result_info(int req_handle)
public static ColumnMetaData[] cci_get_result_info(CUBRIDConnection conn, int req_handle)
{
int stmt_type = 0;
int col_num = 0;
int n;
byte[] name = new byte[MAX_TBALE_COLUMN_NAME_LENGTH];

IntPtr pt = cci_get_result_info_internal(req_handle, ref stmt_type, ref col_num);
ColumnMetaData[] item = new ColumnMetaData[col_num];
@@ -288,11 +291,28 @@ public static ColumnMetaData[] cci_get_result_info(int req_handle)
data.IsShared = int_to_bool(tmp.is_shared - 0);
data.IsUniqueKey = int_to_bool(tmp.is_unique_key - 0);
data.Precision = tmp.precision;
data.RealName = tmp.class_name;
data.Name = tmp.col_name;
data.Scale = tmp.scale;
data.Table = tmp.class_name;
data.Type = (CUBRIDDataType)tmp.ext_type;

Marshal.Copy(tmp.col_name, name, 0, MAX_TBALE_COLUMN_NAME_LENGTH);
for (n = 0; n < MAX_TBALE_COLUMN_NAME_LENGTH; n++) if (name[n] == 0) break;
if (conn.GetEncoding().Equals(Encoding.UTF8))
data.Name = Encoding.UTF8.GetString(name, 0, n);
else
data.Name = Encoding.Unicode.GetString(name, 0, n);

Marshal.Copy(tmp.class_name, name, 0, MAX_TBALE_COLUMN_NAME_LENGTH);
for (n = 0; n < MAX_TBALE_COLUMN_NAME_LENGTH; n++) if (name[n] == 0) break;
if (conn.GetEncoding().Equals(Encoding.UTF8))
{
data.RealName = Encoding.UTF8.GetString(name, 0, n);
data.Table = Encoding.UTF8.GetString(name, 0, n);
}
else
{
data.RealName = Encoding.Unicode.GetString(name, 0, n);
data.Table = Encoding.Unicode.GetString(name, 0, n);
}
}
catch
{
@@ -469,8 +469,9 @@ internal CUBRIDDataReader ExecuteInternal()
}

//T_CCI_COL_INFO res;
columnInfos = CciInterface.cci_get_result_info (handle);
dataReader = new CUBRIDDataReader (this, handle, ret, columnInfos, ret);
columnInfos = CciInterface.cci_get_result_info (conn, handle);

dataReader = new CUBRIDDataReader (this, handle, ret, columnInfos, ret);

return dataReader;
}
@@ -536,7 +537,7 @@ public override int ExecuteNonQuery()
throw new CUBRIDException (err.err_msg);
}

columnInfos = CciInterface.cci_get_result_info(handle);
columnInfos = CciInterface.cci_get_result_info(conn, handle);

if (this.Parameters.Count > 0)
{
@@ -804,7 +804,7 @@ public override bool NextResult()
resultCount = CciInterface.cci_next_result(handle, ref err);
if (resultCount >= 0)
{
columnMetaData = CciInterface.cci_get_result_info(handle);
columnMetaData = CciInterface.cci_get_result_info(conn, handle);
currentRow = 0;
resultTuple = new ResultTuple(columnMetaData.Length);
commandBehavior = CommandBehavior.Default;
@@ -246,8 +246,9 @@ private void LoadTableColumns(DataTable dt, string tableName, string columnRestr
{
string sql =
String.Format(
"select attr_name, default_value, is_nullable, `data_type`, prec, scale, charset from db_attribute where class_name like '{0}' and attr_name like '{1}' order by def_order asc",
"select * from db_attribute where class_name like '{0}' and attr_name like '{1}' order by def_order asc",
tableName, columnRestriction);

using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
{
int pos = 1;
@@ -264,12 +265,31 @@ private void LoadTableColumns(DataTable dt, string tableName, string columnRestr
row["COLUMN_NAME"] = colName;
row["ORDINAL_POSITION"] = pos++;

row["COLUMN_DEFAULT"] = reader.GetString(1);
row["IS_NULLABLE"] = reader.GetString(2).Equals("YES");
row["DATA_TYPE"] = reader.GetString(3);
row["NUMERIC_PRECISION"] = reader.GetInt(4);
row["NUMERIC_SCALE"] = reader.GetInt(5);
row["CHARACTER_SET"] = reader.GetString(6);
for (int i = 0; i < reader.GetColumnCount(); i++) {
switch (reader.GetColumnName(i)) {
case "defalut_value":
row["COLUMN_DEFAULT"] = reader.GetString(i);
break;
case "is_nullable":
row["IS_NULLABLE"] = reader.GetString(i).Equals("YES");
break;
case "data_type":
row["DATA_TYPE"] = reader.GetString(i);
break;
case "prec":
row["NUMERIC_PRECISION"] = reader.GetInt(i);
break;
case "scale":
row["NUMERIC_SCALE"] = reader.GetInt(i);
break;
case "code_set":
case "charset":
row["CHARACTER_SET"] = reader.GetString(i);
break;
default:
break;
}
}

dt.Rows.Add(row);
}
@@ -455,7 +475,7 @@ public DataTable GetForeignKeys(string[] filters)
throw new CUBRIDException(err.err_msg);
}

ColumnMetaData[] columnInfos = CciInterface.cci_get_result_info(handle);
ColumnMetaData[] columnInfos = CciInterface.cci_get_result_info(conn, handle);
CUBRIDCommand command = new CUBRIDCommand(null,conn);
CUBRIDDataReader reader = new CUBRIDDataReader(command, handle, columnInfos.Length, columnInfos, columnInfos.Length);

0 comments on commit b683b7a

Please sign in to comment.