コード例 #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();
        }