From bbb2f0983e1a3d07bcee728c0a43dfa633ec6be6 Mon Sep 17 00:00:00 2001 From: bwkim Date: Wed, 20 Feb 2019 17:19:28 +0900 Subject: [PATCH] [APIS-784] raised System.AccessViolationException --- Code/Src/CUBRIDCciInterface.cs | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Code/Src/CUBRIDCciInterface.cs b/Code/Src/CUBRIDCciInterface.cs index b69a788..77d1782 100644 --- a/Code/Src/CUBRIDCciInterface.cs +++ b/Code/Src/CUBRIDCciInterface.cs @@ -156,10 +156,10 @@ internal struct T_CCI_COL_INFO public char is_non_null; public short scale; public int precision; - public IntPtr col_name; - public IntPtr real_attr; - public IntPtr class_name; - public IntPtr default_value; + public String col_name; + public String real_attr; + public String class_name; + public String default_value; public char is_auto_increment; public char is_unique_key; public char is_primary_key; @@ -266,8 +266,7 @@ public static ColumnMetaData[] cci_get_result_info(CUBRIDConnection conn, int re { int stmt_type = 0; int col_num = 0; - int n; - byte[] name = new byte[MAX_TBALE_COLUMN_NAME_LENGTH]; + byte[] name; IntPtr pt = cci_get_result_info_internal(req_handle, ref stmt_type, ref col_num); ColumnMetaData[] item = new ColumnMetaData[col_num]; @@ -277,9 +276,11 @@ public static ColumnMetaData[] cci_get_result_info(CUBRIDConnection conn, int re ColumnMetaData data = new ColumnMetaData(); try { + T_CCI_COL_INFO tmp = (T_CCI_COL_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pt + i * Marshal.SizeOf(typeof(T_CCI_COL_INFO))), typeof(T_CCI_COL_INFO)); + data.Type = (CUBRIDDataType)tmp.ext_type; data.IsAutoIncrement = int_to_bool(tmp.is_auto_increment - 0); @@ -294,24 +295,23 @@ public static ColumnMetaData[] cci_get_result_info(CUBRIDConnection conn, int re data.Scale = tmp.scale; 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); + name = Encoding.UTF8.GetBytes(tmp.col_name); + data.Name = Encoding.UTF8.GetString(name); + + name = Encoding.UTF8.GetBytes(tmp.class_name); + data.RealName = Encoding.UTF8.GetString(name); + data.Table = Encoding.UTF8.GetString(name); } else { - data.RealName = Encoding.Unicode.GetString(name, 0, n); - data.Table = Encoding.Unicode.GetString(name, 0, n); + name = Encoding.Unicode.GetBytes(tmp.col_name); + data.Name = Encoding.Unicode.GetString(name); + + name = Encoding.Unicode.GetBytes(tmp.class_name); + data.RealName = Encoding.Unicode.GetString(name); + data.Table = Encoding.Unicode.GetString(name); } } catch