Esempio n. 1
0
        public static void Test_CUBRIDClob_Update()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDClobType).Assembly);

            //Create the database schema
            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);

                TestCUBRIDClobType test = new TestCUBRIDClobType
                {
                    c_clob = new CUBRIDClob(conn)
                };

                StreamReader originalFileReader = new StreamReader("../../BSD License.txt");
                string       clobStringToInsert = originalFileReader.ReadToEnd();
                originalFileReader.Close();
                test.c_clob.SetString(1, clobStringToInsert);
                //Insert
                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                using (var session = sessionFactory.OpenSession())
                {
                    using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Save(test);
                        trans.Commit();
                    }

                    TestCUBRIDClobType pGet = session.Get <TestCUBRIDClobType>(test.c_integer);
                    pGet.c_clob = new CUBRIDClob(conn);

                    StreamReader updateFileReader   = new StreamReader("../../BSD License Updated.txt");
                    string       clobStringToUpdate = updateFileReader.ReadToEnd();
                    updateFileReader.Close();
                    test.c_clob.SetString(1, clobStringToUpdate);
                    using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Update(pGet);
                        trans.Commit();
                    }

                    //Retrieve the inserted information
                    IQuery query = session.CreateQuery("FROM TestCUBRIDClobType");
                    IList <TestCUBRIDClobType> testQuery = query.List <TestCUBRIDClobType>();
                    Debug.Assert(testQuery[0].c_integer == 1);

                    string clobStringUpdated = testQuery[0].c_clob.GetString(1, (int)testQuery[0].c_clob.ClobLength);
                    Debug.Assert(clobStringToUpdate.Length == clobStringUpdated.Length);
                    Debug.Assert(clobStringToUpdate == clobStringUpdated);
                }

                //Clean the database schema
                TestCases.ExecuteSQL("drop table if exists TestCUBRIDBlob", conn);
            }
        }
Esempio n. 2
0
        public static void Test_CUBRIDClob_Insert()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

            //Create the database schema
            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);


                TestCUBRIDClobType test = new TestCUBRIDClobType
                {
                    c_clob = new CUBRIDClob(conn)
                };

                StreamReader originalFileReader = new StreamReader("../../BSD License.txt");
                string       clobStringToInsert = originalFileReader.ReadToEnd();
                originalFileReader.Close();
                test.c_clob.SetString(1, clobStringToInsert);
                //Insert
                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                using (var session = sessionFactory.OpenSession())
                {
                    using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Save(test);
                        trans.Commit();
                    }
                }

                const string  sql2   = "SELECT c_clob from TestCUBRIDClob";
                CUBRIDCommand cmd2   = new CUBRIDCommand(sql2, conn);
                DbDataReader  reader = cmd2.ExecuteReader();
                while (reader.Read())
                {
                    CUBRIDClob cString            = (CUBRIDClob)reader[0];
                    string     clobStringInserted = cString.GetString(1, (int)cString.ClobLength);

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

                //Clean the database schema
                TestCases.ExecuteSQL("drop table if exists TestCUBRIDClob", conn);
            }
        }
    public static void Test_CUBRIDClob_Delete()
    {
      Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDClobType).Assembly);
      //Create the database schema
      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);

        TestCUBRIDClobType test = new TestCUBRIDClobType
        {
          c_clob = new CUBRIDClob(conn)
        };

        StreamReader updateFileReader = new StreamReader("../../BSD License.txt");
        string clobStringToInsert = updateFileReader.ReadToEnd();
        updateFileReader.Close();
        test.c_clob.SetString(1, clobStringToInsert);
        //Insert
        ISessionFactory sessionFactory = cfg.BuildSessionFactory();
        using (var session = sessionFactory.OpenSession())
        {
          using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
          {
            session.Save(test);
            trans.Commit();
          }

          //Retrieve the inserted information
          IQuery query = session.CreateQuery("FROM TestCUBRIDClobType");
          IList<TestCUBRIDClobType> testQuery = query.List<TestCUBRIDClobType>();
          Debug.Assert(testQuery.Count == 1);

          //Delete the inserted information
          using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
          {
            session.Delete(test);
            trans.Commit();
          }

          IQuery queryAfterDelete = session.CreateQuery("FROM TestCUBRIDClobType");
          IList<TestCUBRIDClobType> testQueryAfterDelete = queryAfterDelete.List<TestCUBRIDClobType>();
          Debug.Assert(testQueryAfterDelete.Count == 0);
        }

        //Clean the database schema
        TestCases.ExecuteSQL("drop table if exists TestCUBRIDClob", conn);
      }
    }
    public static void Test_CUBRIDClob_Insert()
    {
      Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);
      //Create the database schema
      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);


        TestCUBRIDClobType test = new TestCUBRIDClobType
        {
          c_clob = new CUBRIDClob(conn)
        };

        StreamReader originalFileReader = new StreamReader("../../BSD License.txt");
        string clobStringToInsert = originalFileReader.ReadToEnd();
        originalFileReader.Close();
        test.c_clob.SetString(1, clobStringToInsert);
        //Insert
        ISessionFactory sessionFactory = cfg.BuildSessionFactory();
        using (var session = sessionFactory.OpenSession())
        {
          using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
          {
            session.Save(test);
            trans.Commit();
          }
        }

        const string sql2 = "SELECT c_clob from TestCUBRIDClob";
        CUBRIDCommand cmd2 = new CUBRIDCommand(sql2, conn);
        DbDataReader reader = cmd2.ExecuteReader();
        while (reader.Read())
        {
          CUBRIDClob cString = (CUBRIDClob)reader[0];
          string clobStringInserted = cString.GetString(1, (int)cString.ClobLength);

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

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