Exemple #1
0
    /// <summary>
    /// Test CLOB INSERT, using a txt input file
    /// </summary>
    private static void Test_Clob_FromFile()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CreateTestTableLOB(conn);

        string sql = "insert into t (c) values(?)";
        CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);

        CUBRIDClob Clob = new CUBRIDClob(conn);

        StreamReader r = new StreamReader("../../../BSD License.txt");
        string writestring = r.ReadToEnd();
        r.Close();

        Clob.SetString(1, writestring);

        CUBRIDParameter param = new CUBRIDParameter();
        param.ParameterName = "?";
        param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;
        param.Value = Clob;
        cmd.Parameters.Add(param);
        cmd.ExecuteNonQuery();
        cmd.Close();

        string sql2 = "SELECT c from t";
        using (CUBRIDCommand cmd2 = new CUBRIDCommand(sql2, conn))
        {
          DbDataReader reader = cmd2.ExecuteReader();

          while (reader.Read())
          {
            CUBRIDClob cImage = (CUBRIDClob)reader[0];
            string str2 = cImage.GetString(1, (int)cImage.ClobLength);

            StreamWriter w = new StreamWriter("testout.txt");
            w.Write(str2);
            w.Close();

            StreamReader r2 = new StreamReader("testout.txt");
            string readstring = r2.ReadToEnd();
            r2.Close();

            Debug.Assert(writestring.Length == readstring.Length, "The inserted CLOB length is not valid!");
            Debug.Assert(writestring.Equals(readstring), "The CLOB was not inserted correctly!");
          }
        }

        CleanupTestTableLOB(conn);
      }
    }
Exemple #2
0
    /// <summary>
    /// Test CLOB SELECT, using CUBRIDDataAdapter and DataSet
    /// </summary>
    private static void Test_Clob_SelectDataAdapter2()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CreateTestTableLOB(conn);

        string sql1 = "insert into t (c) values(?)";
        CUBRIDCommand cmd1 = new CUBRIDCommand(sql1, conn);

        CUBRIDClob Clob1 = new CUBRIDClob(conn);

        String str1 = conn.ConnectionString; //Use ConnectionString content for testing
        Clob1.SetString(1, str1);

        CUBRIDParameter param = new CUBRIDParameter();
        param.ParameterName = "?";
        param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;
        param.Value = Clob1;
        cmd1.Parameters.Add(param);
        cmd1.ExecuteNonQuery();
        cmd1.Close();

        string sql = "SELECT c from t";

        DataSet ds = new DataSet();
        CUBRIDDataAdapter da = new CUBRIDDataAdapter();
        da.SelectCommand = new CUBRIDCommand(sql, conn);
        da.Fill(ds);

        DataTable dt = ds.Tables[0];
        for (int j = 0; j < dt.Rows.Count; j++)
        {
          CUBRIDClob cImage = (CUBRIDClob)dt.Rows[j]["c"];
          string str = cImage.GetString(1, (int)cImage.ClobLength);

          Debug.Assert(str.Length == str1.Length, "The selected CLOB length is not valid!");
          Debug.Assert(str.Equals(str1), "The CLOB was not selected correctly!");
        }

        CleanupTestTableLOB(conn);
      }
    }
Exemple #3
0
    /// <summary>
    /// Test CLOB UPDATE
    /// </summary>
    private static void Test_Clob_Update()
    {
      String str;

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

        CreateTestTableLOB(conn);

        string sql1 = "insert into t (c) values(?)";
        using (CUBRIDCommand cmd1 = new CUBRIDCommand(sql1, conn))
        {
          CUBRIDClob Clob1 = new CUBRIDClob(conn);

          Clob1.SetString(1, "test string to be inserted");

          CUBRIDParameter param1 = new CUBRIDParameter();
          param1.ParameterName = "?";
          param1.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;
          param1.Value = Clob1;
          cmd1.Parameters.Add(param1);
          cmd1.ExecuteNonQuery();
          cmd1.Close();

          string sql = "UPDATE t SET c = ?";
          CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);

          CUBRIDClob Clob = new CUBRIDClob(conn);
          str = conn.ConnectionString; //Use the ConnectionString for testing

          Clob.SetString(1, str);
          CUBRIDParameter param = new CUBRIDParameter();
          param.ParameterName = "?";
          param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;
          param.Value = Clob;
          cmd.Parameters.Add(param);
          cmd.ExecuteNonQuery();
        }

        string sql2 = "SELECT c from t";
        using (CUBRIDCommand cmd2 = new CUBRIDCommand(sql2, conn))
        {
          DbDataReader reader = cmd2.ExecuteReader();
          while (reader.Read())
          {
            CUBRIDClob cImage = (CUBRIDClob)reader[0];
            string str2 = cImage.GetString(1, (int)cImage.ClobLength);

            Debug.Assert(str.Length == str2.Length, "The selected CLOB length is not valid!");
            Debug.Assert(str.Equals(str2), "The CLOB was not selected correctly!");
          }
        }

        CleanupTestTableLOB(conn);
      }
    }
    public static void Test_CUBRIDClob_Select()
    {
      Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDClobType).Assembly);
      using (CUBRIDConnection conn = new CUBRIDConnection(cfg.GetProperty(NHibernate.Cfg.Environment.ConnectionString)))
      {
        conn.Open();
        TestCases.ExecuteSQL("drop table if exists TestCUBRIDClob", conn);
        TestCases.ExecuteSQL("create table TestCUBRIDClob(c_integer int not null auto_increment," +
                             "c_clob CLOB," +
                              "primary key (c_integer))", conn);

        const string sql = "insert into TestCUBRIDClob values(1, ?)";
        CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);
        CUBRIDClob Clob = new CUBRIDClob(conn);

        StreamReader originalFileReader = new StreamReader("../../BSD License.txt");
        string clobStringToInsert = originalFileReader.ReadToEnd();
        originalFileReader.Close();
        Clob.SetString(1, clobStringToInsert);

        CUBRIDParameter param = new CUBRIDParameter();
        param.ParameterName = "?p";
        param.Value = Clob;
        cmd.Parameters.Add(param);
        cmd.Parameters[0].DbType = DbType.AnsiString;
        cmd.ExecuteNonQuery();
        cmd.Close();

        ISessionFactory sessionFactory = cfg.BuildSessionFactory();
        using (var session = sessionFactory.OpenSession())
        {
          //Retrieve the inserted information
          IQuery query = session.CreateQuery("FROM TestCUBRIDClobType");
          IList<TestCUBRIDClobType> testQuery = query.List<TestCUBRIDClobType>();
          Debug.Assert(testQuery[0].c_integer == 1);
          CUBRIDClob bImage = testQuery[0].c_clob;
          string clobInserted = bImage.GetString(1, (int)testQuery[0].c_clob.ClobLength);

          Debug.Assert(clobStringToInsert.Length == clobInserted.Length);
          Debug.Assert(clobStringToInsert == clobInserted);
        }

        //Clean the database schema
        TestCases.ExecuteSQL("drop table if exists TestCUBRIDClob", conn);
      }
    }