Пример #1
0
 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;
 }
Пример #2
0
    /// <summary>
    /// Test SEQUENCE operations
    /// </summary>
    private static void Test_SequenceOperations()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        TestCases.ExecuteSQL("DROP TABLE IF EXISTS t", conn);

        //Create a new table with a sequence

        TestCases.ExecuteSQL("CREATE TABLE t(seq SEQUENCE(int))", conn);
        //Insert some data in the sequence column
        TestCases.ExecuteSQL("INSERT INTO t(seq) VALUES({0,1,2,3,4,5,6})", conn);
        CUBRIDOid oid = new CUBRIDOid("@0|0|0");
        using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT t FROM t", conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            while (reader.Read())
            {
              oid = (CUBRIDOid)reader[0];
            }
          }
        }

        String attributeName = "seq";
        int value = 7;

        int SeqSize = conn.GetCollectionSize(oid, attributeName);
        Debug.Assert(SeqSize == 7);

        conn.UpdateElementInSequence(oid, attributeName, 1, value);
        SeqSize = conn.GetCollectionSize(oid, attributeName);
        Debug.Assert(SeqSize == 7);

        using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            while (reader.Read())
            {
              int[] expected = { 7, 1, 2, 3, 4, 5, 6 };
              object[] o = (object[])reader[0];
              for (int i = 0; i < SeqSize; i++)
              {
                Debug.Assert(Convert.ToInt32(o[i]) == expected[i]);
              }
            }
          }
        }

        conn.InsertElementInSequence(oid, attributeName, 5, value);
        SeqSize = conn.GetCollectionSize(oid, attributeName);
        Debug.Assert(SeqSize == 8);

        using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            while (reader.Read())
            {
              int[] expected = { 7, 1, 2, 3, 7, 4, 5, 6 };
              object[] o = (object[])reader[0];
              for (int i = 0; i < SeqSize; i++)
              {
                Debug.Assert(Convert.ToInt32(o[i]) == expected[i]);
              }
            }
          }
        }

        conn.DropElementInSequence(oid, attributeName, 5);
        SeqSize = conn.GetCollectionSize(oid, attributeName);
        Debug.Assert(SeqSize == 7);

        using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            while (reader.Read())
            {
              int[] expected = { 7, 1, 2, 3, 4, 5, 6 };
              object[] o = (object[])reader[0];
              for (int i = 0; i < SeqSize; i++)
              {
                Debug.Assert(Convert.ToInt32(o[i]) == expected[i]);
              }
            }
          }
        }

        TestCases.ExecuteSQL("DROP t", conn);
      }
    }
Пример #3
0
        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);
        }
Пример #4
0
        public void CollectionSequence_Test()
        {
            Log("Test GetCollectionSize, UpdateElementInSequence, InsertElementInSequence, DropElementInSequence");

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;
                conn.Open();

                DBHelper.ExecuteSQL("DROP TABLE IF EXISTS t", conn);

                //Create a new table with a sequence
                DBHelper.ExecuteSQL("CREATE TABLE t(seq SEQUENCE(int))", conn);
                //Insert some data in the sequence column
                DBHelper.ExecuteSQL("INSERT INTO t(seq) VALUES({0,1,2,3,4,5,6})", conn);
                CUBRIDOid oid = new CUBRIDOid("@0|0|0");

                LogTestStep("Test UpdateElementInSequence");
                using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT t FROM t", conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            oid = (CUBRIDOid)reader[0];
                        }
                    }
                }

                String attributeName = "seq";
                int SeqSize = conn.GetCollectionSize(oid, attributeName);
                Assert.AreEqual(7, SeqSize);

                conn.UpdateElementInSequence(oid, attributeName, 1, 11);
                SeqSize = conn.GetCollectionSize(oid, attributeName);
                Assert.AreEqual(7, SeqSize);

                using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int[] expected = { 11, 1, 2, 3, 4, 5, 6 };
                            object[] o = (object[])reader[0];
                            for (int i = 0; i < SeqSize; i++)
                            {
                                Assert.AreEqual(expected[i], Convert.ToInt32(o[i]));
                            }
                        }
                    }
                }
                LogStepPass();

                LogTestStep("Test InsertElementInSequence");
                conn.InsertElementInSequence(oid, attributeName, 5, 12);
                SeqSize = conn.GetCollectionSize(oid, attributeName);
                Assert.AreEqual(8, SeqSize);

                using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int[] expected = { 11, 1, 2, 3, 12, 4, 5, 6 };
                            object[] o = (object[])reader[0];
                            for (int i = 0; i < SeqSize; i++)
                            {
                                Assert.AreEqual(expected[i], Convert.ToInt32(o[i]));
                            }
                        }
                    }
                }

                LogStepPass();

                LogTestStep("Test DropElementInSequence");
                conn.DropElementInSequence(oid, attributeName, 6);
                SeqSize = conn.GetCollectionSize(oid, attributeName);
                Assert.AreEqual(7, SeqSize);

                using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int[] expected = { 11, 1, 2, 3, 12, 5, 6 };
                            object[] o = (object[])reader[0];
                            for (int i = 0; i < SeqSize; i++)
                            {
                                Assert.AreEqual(expected[i], Convert.ToInt32(o[i]));
                            }
                        }
                    }
                }
                LogStepPass();

                //revert test db
                DBHelper.ExecuteSQL("drop table t", conn);
                LogTestResult();
            }
        }
Пример #5
0
    /// <summary>
    /// Test CUBRIDOid class (which implements OID support)
    /// </summary>
    private static void Test_Oid_Basic()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CUBRIDOid oid = new CUBRIDOid("@620|1|0");

        Debug.Assert(oid.Page() == 620);
        Debug.Assert(oid.Slot() == 1);
        Debug.Assert(oid.Volume() == 0);
      }
    }
Пример #6
0
 /// <summary>
 ///   Gets the size of the collection.
 /// </summary>
 /// <param name="oid"> The oid. </param>
 /// <param name="attributeName"> Name of the attribute. </param>
 /// <returns> </returns>
 public int GetCollectionSize(CUBRIDOid oid, String attributeName)
 {
     if (State == ConnectionState.Closed)
     {
         throw new CUBRIDException(Utils.GetStr(MsgId.TheConnectionIsNotOpen));
     }
     int size = 0;
     T_CCI_ERROR err_buf = new T_CCI_ERROR();
     int req = CciInterface.cci_col_size(Conection, oid.Get_OidStr(), attributeName, ref size, ref err_buf);
     if (req < 0)
     {
         throw new CUBRIDException(err_buf.err_code, err_buf.err_msg);
     }
     return size;
 }
Пример #7
0
    /// <summary>
    ///   Drops the element in sequence.
    /// </summary>
    /// <param name="oid"> The oid. </param>
    /// <param name="attributeName"> Name of the attribute. </param>
    /// <param name="index"> The index. </param>
    public void DropElementInSequence(CUBRIDOid oid, String attributeName, int index)
    {
        if (State == ConnectionState.Closed)
        {
            throw new CUBRIDException(Utils.GetStr(MsgId.TheConnectionIsNotOpen));
        }

        T_CCI_ERROR err_buf = new T_CCI_ERROR();
        int req = CciInterface.cci_col_seq_drop(Conection, oid.Get_OidStr(), attributeName, index, ref err_buf);
        if (req < 0)
        {
            throw new CUBRIDException(err_buf.err_code, err_buf.err_msg);
        }
    }
Пример #8
0
    /// <summary>
    ///   Adds the element to set.
    /// </summary>
    /// <param name="oid"> The oid. </param>
    /// <param name="attributeName"> Name of the attribute. </param>
    /// <param name="value"> The value. </param>
    public void AddElementToSet(CUBRIDOid oid, String attributeName, Object value)
    {
        if (State == ConnectionState.Closed)
        {
            throw new CUBRIDException(Utils.GetStr(MsgId.TheConnectionIsNotOpen));
        }

        T_CCI_ERROR err_buf = new T_CCI_ERROR();
        int req = CciInterface.cci_col_set_add(Conection, oid.Get_OidStr(), attributeName, value.ToString(), ref err_buf);
        if (req < 0)
        {
            throw new CUBRIDException(err_buf.err_code, err_buf.err_msg);
        }
    }