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;                  
        }
 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;
 }
 public static extern int cci_get_data(int req_handle, int col_no, int type, ref T_CCI_BIT value, ref int indicator);
        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:
                byte[] bind_value;     // = param.Value.ToString();
                if (conn.GetEncoding() != null)
                {
                    bind_value = conn.GetEncoding().GetBytes(param.Value.ToString());
                }
                else
                {
                    bind_value = param.GetParameterEncoding().GetBytes(param.Value.ToString());
                }
                ret = bind_param(handle, index, a_type, bind_value, u_type, flag);
                break;
            }
            return(ret);
        }
        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 = new byte[bit.size];
                for (int i = 0; i < bit.size; i++)
                {
                    data[i] = Marshal.ReadByte(bit.buf, i);
                }
                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++;
                        }

                        if ((CUBRIDDataType)type == CUBRIDDataType.CCI_U_TYPE_VARBIT)
                        {
                            rt[col_no - 1] = Enumerable.Range(0, count)
                                             .Where(x => x % 2 == 0)
                                             .Select(x => Convert.ToByte(Marshal.PtrToStringAnsi(value).Substring(x, 2), 16))
                                             .ToArray();
                        }
                        else
                        {
                            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] = null;     // String.Empty;
                }
                if (is_collection_type((CUBRIDDataType)type))
                {
                    rt.toArray(col_no - 1);
                }
                break;
            }
            return(res);
        }
 public static extern int cci_get_data(int req_handle, int col_no, int type, ref T_CCI_BIT value, ref int indicator);