Пример #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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        public static void Test_CUBRIDBlob_Select()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

            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);

                const string  sql  = "insert into TestCUBRIDBlob values(1, ?)";
                CUBRIDCommand cmd  = new CUBRIDCommand(sql, conn);
                CUBRIDBlob    Blob = new CUBRIDBlob(conn);

                BinaryReader originalFileReader = new BinaryReader(File.Open("../../CUBRID.ico", FileMode.Open));
                byte[]       bytesOriginalData  = originalFileReader.ReadBytes((int)originalFileReader.BaseStream.Length);
                originalFileReader.Close();
                Blob.SetBytes(1, bytesOriginalData);

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

                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                using (var session = sessionFactory.OpenSession())
                {
                    //Retrieve the inserted information
                    IQuery query = session.CreateQuery("FROM TestCUBRIDBlobType");
                    IList <TestCUBRIDBlobType> testQuery = query.List <TestCUBRIDBlobType>();
                    Debug.Assert(testQuery[0].c_integer == 1);
                    CUBRIDBlob bImage             = testQuery[0].c_blob;
                    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);
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        public static void Test_ManyToManySelect()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

            using (CUBRIDConnection con = TestCases.GetDemodbConnection())
            {
                TestCases.ExecuteSQL("drop table if exists AthleteEvent", con);
                TestCases.ExecuteSQL("create table AthleteEvent (event_code int, athlete_code int, primary key(event_code,athlete_code))", con);
                TestCases.ExecuteSQL("insert into AthleteEvent values(20038, 10011)", con);
                TestCases.ExecuteSQL("insert into AthleteEvent values(20038, 14313)", con);

                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                using (ISession session = sessionFactory.OpenSession())
                {
                    IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator();
                    while (athletes.MoveNext())
                    {
                        if (athletes.Current.Events.Count != 0)
                        {
                            List <object> eventValues   = GetTableValues("event", 37, new string[] { "code", "name", "sports", "gender", "players" });
                            List <object> athleteValues = GetTableValues("athlete", 989, new string[] { "code", "name", "gender", "nation_code", "event" });
                            Debug.Assert(athletes.Current.code == (int)athleteValues[0]);
                            Debug.Assert(athletes.Current.name == (string)athleteValues[1]);
                            Debug.Assert(athletes.Current.gender == (string)athleteValues[2]);
                            Debug.Assert(athletes.Current.nation_code == (string)athleteValues[3]);
                            Debug.Assert(athletes.Current.athlete_event == (string)athleteValues[4]);
                            Debug.Assert(athletes.Current.Events.Count == 1);
                            Debug.Assert(athletes.Current.Events[0].code == (int)eventValues[0]);
                            Debug.Assert(athletes.Current.Events[0].name == (string)eventValues[1]);
                            Debug.Assert(athletes.Current.Events[0].sports == (string)eventValues[2]);
                            Debug.Assert(athletes.Current.Events[0].gender == (string)eventValues[3]);
                            Debug.Assert(athletes.Current.Events[0].players == (int)eventValues[4]);
                            Debug.Assert(athletes.Current.Events[0].Athletes.Count == 2);
                            Debug.Assert(athletes.Current.Events[0].Athletes[0].code == (int)athleteValues[0]);
                            Debug.Assert(athletes.Current.Events[0].Athletes[0].name == (string)athleteValues[1]);
                            Debug.Assert(athletes.Current.Events[0].Athletes[0].gender == (string)athleteValues[2]);
                            Debug.Assert(athletes.Current.Events[0].Athletes[0].nation_code == (string)athleteValues[3]);
                            Debug.Assert(athletes.Current.Events[0].Athletes[0].athlete_event == (string)athleteValues[4]);
                            break;
                        }
                    }
                }
                //Clean database schema
                TestCases.ExecuteSQL("drop table AthleteEvent", con);
            }
        }
Пример #8
0
        public static void Test_CUBRIDCollections_Select()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDCollectionType).Assembly);

            //Create the database schema
            using (CUBRIDConnection conn = new CUBRIDConnection(cfg.GetProperty(NHibernate.Cfg.Environment.ConnectionString)))
            {
                conn.Open();
                TestCases.ExecuteSQL("drop table if exists TestCUBRIDCollectionType", conn);
                TestCases.ExecuteSQL("create table TestCUBRIDCollectionType(id int not null auto_increment," +
                                     "sequence_column sequence(int), " +
                                     "set_column set(int), " +
                                     "multiset_column multiset(string)," +
                                     "primary key (id))", conn);
                //Insert some data in the sequence column
                TestCases.ExecuteSQL("INSERT INTO TestCUBRIDCollectionType(sequence_column, set_column, multiset_column)" +
                                     "VALUES({0, 1, 2, 3}, { 4, 5, 6, 7}, { 'CUBRID', 'qwerty' })", conn);

                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                using (var session = sessionFactory.OpenSession())
                {
                    //Retrieve the inserted information
                    IQuery query = session.CreateQuery(" from TestCUBRIDCollectionType");
                    IList <TestCUBRIDCollectionType> testQuery = query.List <TestCUBRIDCollectionType>();

                    int[]    expectedSequence = { 0, 1, 2, 3 };
                    int[]    expectedSet      = { 4, 5, 6, 7 };
                    string[] expectedMultiset = { "CUBRID", "qwerty" };
                    Debug.Assert((int)testQuery[0].id == 1);
                    Debug.Assert((int)testQuery[0].seq[0] == expectedSequence[0]);
                    Debug.Assert((int)testQuery[0].seq[1] == expectedSequence[1]);
                    Debug.Assert((int)testQuery[0].seq[2] == expectedSequence[2]);
                    Debug.Assert((int)testQuery[0].seq[3] == expectedSequence[3]);
                    Debug.Assert((int)testQuery[0].set[0] == expectedSet[0]);
                    Debug.Assert((int)testQuery[0].set[1] == expectedSet[1]);
                    Debug.Assert((int)testQuery[0].set[2] == expectedSet[2]);
                    Debug.Assert((int)testQuery[0].set[3] == expectedSet[3]);
                    Debug.Assert((string)testQuery[0].multiset[0] == expectedMultiset[0]);
                    Debug.Assert((string)testQuery[0].multiset[1] == expectedMultiset[1]);
                }

                //Clean the database schema
                TestCases.ExecuteSQL("drop table if exists TestCUBRIDCollectionType", conn);
            }
        }
Пример #9
0
        public static void Test_ManyToManyDelete()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

            using (CUBRIDConnection con = TestCases.GetDemodbConnection())
            {
                TestCases.ExecuteSQL("drop table if exists AthleteEvent", con);
                TestCases.ExecuteSQL(
                    "create table AthleteEvent (event_code int, athlete_code int, primary key(event_code,athlete_code))", con);
                TestCases.ExecuteSQL("insert into Event(code) values(20422)", con);

                AthleteManyToMany athleteManyToMany = new AthleteManyToMany()
                {
                    name          = "Lucian Bute",
                    gender        = "M",
                    nation_code   = "ROM",
                    athlete_event = "Boxing",
                    Events        = new List <Event>()
                };
                athleteManyToMany.Events.Add(new Event()
                {
                    code = 20422, sports = "Boxing", name = "70 Kg", gender = "M", players = 2
                });

                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                using (ISession session = sessionFactory.OpenSession())
                {
                    IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator();
                    int count = 0;
                    while (athletes.MoveNext())
                    {
                        count++;
                    }
                    Debug.Assert(count == 6677);
                }

                using (ISession session = sessionFactory.OpenSession())
                {
                    using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Save(athleteManyToMany);
                        tx.Commit();
                    }
                }

                using (ISession session = sessionFactory.OpenSession())
                {
                    IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator();
                    int count = 0;
                    while (athletes.MoveNext())
                    {
                        count++;
                    }
                    Debug.Assert(count == 6678);
                }

                using (ISession session = sessionFactory.OpenSession())
                {
                    using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Delete(athleteManyToMany);
                        tx.Commit();
                    }
                }

                using (ISession session = sessionFactory.OpenSession())
                {
                    IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator();
                    int count = 0;
                    while (athletes.MoveNext())
                    {
                        count++;
                    }
                    Debug.Assert(count == 6677);
                }

                TestCases.ExecuteSQL("drop table AthleteEvent", con);
            }
        }
Пример #10
0
        public static void Test_ManyToManyUpdate()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

            using (CUBRIDConnection con = TestCases.GetDemodbConnection())
            {
                TestCases.ExecuteSQL("drop table if exists AthleteEvent", con);
                TestCases.ExecuteSQL("create table AthleteEvent (event_code int, athlete_code int, primary key(event_code,athlete_code))", con);
                TestCases.ExecuteSQL("insert into Event(code) values(20422)", con);

                AthleteManyToMany athleteManyToMany = new AthleteManyToMany
                {
                    name          = "Lucian Bute",
                    gender        = "M",
                    nation_code   = "ROM",
                    athlete_event = "Boxing",
                    Events        = new List <Event>()
                };
                athleteManyToMany.Events.Add(new Event {
                    code = 20422, sports = "Boxing", name = "70 Kg", gender = "M", players = 2
                });

                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                using (ISession session = sessionFactory.OpenSession())
                {
                    using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Save(athleteManyToMany);
                        tx.Commit();
                    }
                }

                athleteManyToMany.name           = "Leonard Doroftei";
                athleteManyToMany.Events[0].name = "65 Kg";
                using (ISession session = sessionFactory.OpenSession())
                {
                    using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Update(athleteManyToMany);
                        tx.Commit();
                    }
                }

                using (ISession session = sessionFactory.OpenSession())
                {
                    IEnumerator <AthleteManyToMany> athletes = session.Query <AthleteManyToMany>().Fetch(b => b.Events).GetEnumerator();
                    while (athletes.MoveNext())
                    {
                        if (athletes.Current.name == "Leonard Doroftei")
                        {
                            List <object> eventValues   = GetTableValues("event", 423, new string[] { "code", "name", "sports", "gender", "players" });
                            List <object> athleteValues = GetTableValues("athlete", 6678, new string[] { "code", "name", "gender", "nation_code", "event" });
                            Debug.Assert(athletes.Current.code == (int)athleteValues[0]);
                            Debug.Assert(athletes.Current.name == (string)athleteValues[1]);
                            Debug.Assert(athletes.Current.gender == (string)athleteValues[2]);
                            Debug.Assert(athletes.Current.nation_code == (string)athleteValues[3]);
                            Debug.Assert(athletes.Current.athlete_event == (string)athleteValues[4]);
                            Debug.Assert(athletes.Current.Events.Count == 1);
                            Debug.Assert(athletes.Current.Events[0].code == (int)eventValues[0]);
                            Debug.Assert(athletes.Current.Events[0].name == (string)eventValues[1]);
                            Debug.Assert(athletes.Current.Events[0].sports == (string)eventValues[2]);
                            Debug.Assert(athletes.Current.Events[0].gender == (string)eventValues[3]);
                            Debug.Assert(athletes.Current.Events[0].players == (int)eventValues[4]);
                            Debug.Assert(athletes.Current.Events[0].Athletes.Count == 1);
                            Debug.Assert(athletes.Current.Events[0].Athletes[0].name == (string)athleteValues[1]);
                            Debug.Assert(athletes.Current.Events[0].Athletes[0].gender == (string)athleteValues[2]);
                            Debug.Assert(athletes.Current.Events[0].Athletes[0].nation_code == (string)athleteValues[3]);
                            Debug.Assert(athletes.Current.Events[0].Athletes[0].athlete_event == (string)athleteValues[4]);
                            break;
                        }
                    }
                }

                using (ISession session = sessionFactory.OpenSession())
                {
                    using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Delete(athleteManyToMany);
                        tx.Commit();
                    }
                }

                TestCases.ExecuteSQL("drop table AthleteEvent", con);
            }
        }
Пример #11
0
        public static void Test_DataTypesStandard_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 TestDataTypesStandard", conn);
                TestCases.ExecuteSQL("create table TestDataTypesStandard (" +
                                     "c_integer integer," +
                                     "c_smallint smallint," +
                                     "c_bigint bigint," +
                                     "c_numeric numeric(10,2)," +
                                     "c_float float," +
                                     "c_decimal decimal(19,5)," +
                                     "c_double double," +
                                     "c_char char(1)," +
                                     "c_varchar varchar(30)," +
                                     "c_time time," +
                                     "c_date date," +
                                     "c_timestamp timestamp," +
                                     "c_datetime datetime," +
                                     "c_monetary monetary," +
                                     "c_string string," +
                                     "c_bit BIT(8)," +
                                     "c_varbit bit varying(8)," +
                                     "primary key (c_integer))", conn);

                TestDataTypesStandard test = new TestDataTypesStandard
                {
                    c_bigint    = 1,
                    c_char      = "a",
                    c_date      = new DateTime(2012, 06, 19),
                    c_datetime  = new DateTime(2012, 06, 19, 12, 05, 14),
                    c_decimal   = (decimal)0.5,
                    c_double    = 1.5,
                    c_float     = 1.5f,
                    c_integer   = 14,
                    c_monetary  = 50,
                    c_numeric   = (decimal)20.12,
                    c_smallint  = 1,
                    c_string    = "qwerty",
                    c_time      = new DateTime(2012, 06, 19, 12, 05, 14),
                    c_timestamp = new DateTime(2012, 06, 19, 12, 05, 14),
                    c_varchar   = "qwerty",
                    c_bit       = 1,
                    c_varbit    = 1,
                };

                //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 TestDataTypesStandard");
                    IList <TestDataTypesStandard> testQuery = query.List <TestDataTypesStandard>();
                    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 TestDataTypesStandard");
                    IList <TestDataTypesStandard> testQueryAfterDelete = queryAfterDelete.List <TestDataTypesStandard>();
                    Debug.Assert(testQueryAfterDelete.Count == 0);
                }

                //Clean the database schema
                TestCases.ExecuteSQL("drop table if exists TestDataTypesStandard", conn);
            }
        }
Пример #12
0
        public static void Test_CUBRIDCollections_Delete()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDCollectionType).Assembly);

            //Create the database schema
            using (CUBRIDConnection conn = new CUBRIDConnection(cfg.GetProperty(NHibernate.Cfg.Environment.ConnectionString)))
            {
                conn.Open();
                TestCases.ExecuteSQL("drop table if exists TestCUBRIDCollectionType", conn);
                TestCases.ExecuteSQL("create table TestCUBRIDCollectionType(id int not null auto_increment," +
                                     "sequence_column sequence(int), " +
                                     "set_column set(int), " +
                                     "multiset_column multiset(string)," +
                                     "primary key (id))", conn);

                object[] insertSequence = { 0, 1, 2, 3 };
                object[] insertSet      = { 4, 5, 6, 7 };
                object[] insertMultiset = { "CUBRID", "qwerty" };
                TestCUBRIDCollectionType testCollections = new TestCUBRIDCollectionType()
                {
                    seq      = insertSequence,
                    set      = insertSet,
                    multiset = insertMultiset
                };

                //Insert
                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                using (var session = sessionFactory.OpenSession())
                {
                    using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Save(testCollections);
                        trans.Commit();
                    }
                }

                //Check the the insert performed correctly
                using (var session = sessionFactory.OpenSession())
                {
                    //Retrieve the inserted information
                    IQuery queryAfterInsert = session.CreateQuery(" from TestCUBRIDCollectionType");
                    IList <TestCUBRIDCollectionType> testQueryAfterInsert = queryAfterInsert.List <TestCUBRIDCollectionType>();

                    Debug.Assert(testQueryAfterInsert.Count == 1);
                }

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

                using (var session = sessionFactory.OpenSession())
                {
                    IQuery queryAfterDelete = session.CreateQuery("FROM TestCUBRIDCollectionType");
                    IList <TestCUBRIDClobType> testQueryAfterDelete = queryAfterDelete.List <TestCUBRIDClobType>();
                    Debug.Assert(testQueryAfterDelete.Count == 0);
                }

                //Clean the database schema
                TestCases.ExecuteSQL("drop table if exists TestCUBRIDCollectionType", conn);
            }
        }
Пример #13
0
        public static void Test_CUBRIDCollections_Update()
        {
            Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDCollectionType).Assembly);

            //Create the database schema
            using (CUBRIDConnection conn = new CUBRIDConnection(cfg.GetProperty(NHibernate.Cfg.Environment.ConnectionString)))
            {
                conn.Open();
                TestCases.ExecuteSQL("drop table if exists TestCUBRIDCollectionType", conn);
                TestCases.ExecuteSQL("create table TestCUBRIDCollectionType(id int not null auto_increment," +
                                     "sequence_column sequence(int), " +
                                     "set_column set(int), " +
                                     "multiset_column multiset(string)," +
                                     "primary key (id))", conn);

                object[] insertSequence = { 0, 1, 2, 3 };
                object[] insertSet      = { 4, 5, 6, 7 };
                object[] insertMultiset = { "CUBRID", "qwerty" };
                TestCUBRIDCollectionType testCollections = new TestCUBRIDCollectionType()
                {
                    seq      = insertSequence,
                    set      = insertSet,
                    multiset = insertMultiset
                };

                //Insert
                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                using (var session = sessionFactory.OpenSession())
                {
                    using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Save(testCollections);
                        trans.Commit();
                    }
                }

                object[] updateSequence = { 10, 11, 12, 13 };
                object[] updateSet      = { 14, 15, 16, 17 };
                object[] updateMultiset = { "ADO.NET", "NHibernate" };
                testCollections.seq      = updateSequence;
                testCollections.set      = updateSet;
                testCollections.multiset = updateMultiset;

                //Update
                using (var session = sessionFactory.OpenSession())
                {
                    using (var trans = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        session.Update(testCollections);
                        trans.Commit();
                    }
                }

                //Check the the insert performed correctly
                using (var session = sessionFactory.OpenSession())
                {
                    //Retrieve the inserted information
                    IQuery query = session.CreateQuery(" from TestCUBRIDCollectionType");
                    IList <TestCUBRIDCollectionType> testQuery = query.List <TestCUBRIDCollectionType>();

                    int[]    expectedSequence = { 10, 11, 12, 13 };
                    int[]    expectedSet      = { 14, 15, 16, 17 };
                    string[] expectedMultiset = { "ADO.NET", "NHibernate" };
                    Debug.Assert((int)testQuery[0].id == 1);
                    Debug.Assert((int)testQuery[0].seq[0] == expectedSequence[0]);
                    Debug.Assert((int)testQuery[0].seq[1] == expectedSequence[1]);
                    Debug.Assert((int)testQuery[0].seq[2] == expectedSequence[2]);
                    Debug.Assert((int)testQuery[0].seq[3] == expectedSequence[3]);
                    Debug.Assert((int)testQuery[0].set[0] == expectedSet[0]);
                    Debug.Assert((int)testQuery[0].set[1] == expectedSet[1]);
                    Debug.Assert((int)testQuery[0].set[2] == expectedSet[2]);
                    Debug.Assert((int)testQuery[0].set[3] == expectedSet[3]);
                    Debug.Assert((string)testQuery[0].multiset[0] == expectedMultiset[0]);
                    Debug.Assert((string)testQuery[0].multiset[1] == expectedMultiset[1]);
                }

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