public static void Test_CUBRIDBlob_Delete() { 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 TestCUBRIDBlob", conn); TestCases.ExecuteSQL("create table TestCUBRIDBlob(c_integer int not null auto_increment," + "c_blob BLOB," + "primary key (c_integer))", conn); TestCUBRIDBlobType test = new TestCUBRIDBlobType { c_blob = new CUBRIDBlob(conn) }; BinaryReader originalFileReader = new BinaryReader(File.Open("../../CUBRID.ico", FileMode.Open)); byte[] bytesOriginalData = originalFileReader.ReadBytes((int)originalFileReader.BaseStream.Length); originalFileReader.Close(); test.c_blob.SetBytes(1, bytesOriginalData); //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 TestCUBRIDBlobType"); IList <TestCUBRIDBlobType> testQuery = query.List <TestCUBRIDBlobType>(); 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 TestCUBRIDBlobType"); IList <TestCUBRIDBlobType> testQueryAfterDelete = queryAfterDelete.List <TestCUBRIDBlobType>(); Debug.Assert(testQueryAfterDelete.Count == 0); } //Clean the database schema TestCases.ExecuteSQL("drop table if exists TestCUBRIDBlob", conn); } }
public static void Test_CUBRIDBlob_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 TestCUBRIDBlob", conn); TestCases.ExecuteSQL("create table TestCUBRIDBlob(c_integer int not null auto_increment," + "c_blob BLOB," + "primary key (c_integer))", conn); TestCUBRIDBlobType test = new TestCUBRIDBlobType { c_blob = new CUBRIDBlob(conn) }; BinaryReader origianlFileReader = new BinaryReader(File.Open("../../CUBRID.ico", FileMode.Open)); byte[] bytesOriginalData = origianlFileReader.ReadBytes((int)origianlFileReader.BaseStream.Length); origianlFileReader.Close(); test.c_blob.SetBytes(1, bytesOriginalData); //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_blob from TestCUBRIDBlob"; CUBRIDCommand cmd2 = new CUBRIDCommand(sql2, conn); DbDataReader reader = cmd2.ExecuteReader(); while (reader.Read()) { CUBRIDBlob bImage = (CUBRIDBlob)reader[0]; byte[] bytesRetrievedData = bImage.GetBytes(1, (int)bImage.BlobLength); Debug.Assert(bytesOriginalData.Length == bytesRetrievedData.Length); Debug.Assert(bytesOriginalData[0] == bytesRetrievedData[0]); Debug.Assert(bytesOriginalData[bytesOriginalData.Length - 1] == bytesRetrievedData[bytesRetrievedData.Length - 1]); } //Clean the database schema TestCases.ExecuteSQL("drop table if exists TestCUBRIDBlob", conn); } }
public static void Test_CUBRIDBlob_Delete() { 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 TestCUBRIDBlob", conn); TestCases.ExecuteSQL("create table TestCUBRIDBlob(c_integer int not null auto_increment," + "c_blob BLOB," + "primary key (c_integer))", conn); TestCUBRIDBlobType test = new TestCUBRIDBlobType { c_blob = new CUBRIDBlob(conn) }; BinaryReader originalFileReader = new BinaryReader(File.Open("../../CUBRID.ico", FileMode.Open)); byte[] bytesOriginalData = originalFileReader.ReadBytes((int)originalFileReader.BaseStream.Length); originalFileReader.Close(); test.c_blob.SetBytes(1, bytesOriginalData); //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 TestCUBRIDBlobType"); IList<TestCUBRIDBlobType> testQuery = query.List<TestCUBRIDBlobType>(); 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 TestCUBRIDBlobType"); IList<TestCUBRIDBlobType> testQueryAfterDelete = queryAfterDelete.List<TestCUBRIDBlobType>(); Debug.Assert(testQueryAfterDelete.Count == 0); } //Clean the database schema TestCases.ExecuteSQL("drop table if exists TestCUBRIDBlob", conn); } }