Beispiel #1
0
        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();
        }
Beispiel #2
0
        private static void Test_Sequence_String()
        {
            ExecuteSQL("DROP TABLE IF EXISTS t", conn);

            //Create a new table with a collection
            ExecuteSQL("CREATE TABLE t(s SET(string))", conn);
            //Insert some data in the sequence column
            string[] sArray = new string[8] {
                "P",
                "Types of fragmentation",
                "File fragmentation",
                "Free space fragmentation",
                "File scattering",
                "File system fragmentation",
                "Preventing fragmentation", null
            };
            string sql = "INSERT INTO t(s) VALUES( ?);";

            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                CUBRIDParameter param = new CUBRIDParameter();
                param.ParameterName       = "?p";
                param.Value               = sArray;
                param.InnerCUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_STRING;
                cmd.Parameters.Add(param);
                cmd.Parameters[0].CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_SET;
                cmd.ExecuteNonQuery();
            }

            using (CUBRIDCommand cmd = new CUBRIDCommand("select * from t", conn))
            {
                using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
                {
                    reader.Read();

                    object objValue = reader.GetValue(0);
                    Array  oArray   = objValue as Array;
                    if (oArray != null)
                    {
                        Console.WriteLine(oArray.Length);
                    }
                    cmd.ColumnInfos[0].ToString();
                }
            }
        }
Beispiel #3
0
        private static void Test_Sequence_Object()
        {
            ExecuteSQL("DROP TABLE IF EXISTS t", conn);

            //Create a new table with a collection
            ExecuteSQL("CREATE TABLE t(s SET(object))", conn);
            //Insert some data in the sequence column
            object[] sArray = new object[1] {
                null
            };
            string sql = "INSERT INTO t(s) VALUES( ?);";

            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                CUBRIDParameter param = new CUBRIDParameter();
                param.ParameterName       = "?p";
                param.Value               = sArray;
                param.InnerCUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_OBJECT;
                cmd.Parameters.Add(param);
                cmd.Parameters[0].CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_SET;
                cmd.ExecuteNonQuery();
            }

            using (CUBRIDCommand cmd = new CUBRIDCommand("select * from t", conn))
            {
                using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
                {
                    reader.Read();

                    object objValue = reader.GetValue(0);
                    Array  oArray   = objValue as Array;
                    if (oArray != null)
                    {
                        Console.WriteLine(oArray.Length);
                    }
                }
            }
        }