コード例 #1
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);
            }
        }
コード例 #2
0
    public static void Test_DataTypesStandard_Select()
    {
      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);
          Debug.Assert(testQuery[0].c_integer == 14);
          Debug.Assert(testQuery[0].c_bigint == 1);
          Debug.Assert(testQuery[0].c_char == "a");
          Debug.Assert(testQuery[0].c_date == new DateTime(2012, 06, 19));
          Debug.Assert(testQuery[0].c_datetime == new DateTime(2012, 06, 19, 12, 05, 14));
          Debug.Assert(testQuery[0].c_decimal == (decimal)0.5);
          Debug.Assert(testQuery[0].c_double.Equals(1.5));
          Debug.Assert(testQuery[0].c_float.Equals(1.5f));
          Debug.Assert(testQuery[0].c_monetary == 50);
          Debug.Assert(testQuery[0].c_numeric == (decimal)20.12);
          Debug.Assert(testQuery[0].c_smallint == 1);
          Debug.Assert(testQuery[0].c_string == "qwerty");
          Debug.Assert(testQuery[0].c_time == new DateTime(2012, 06, 19, 12, 05, 14));
          Debug.Assert(testQuery[0].c_timestamp == new DateTime(2012, 06, 19, 12, 05, 14));
          Debug.Assert(testQuery[0].c_varchar == "qwerty");
          Debug.Assert(testQuery[0].c_bit == (byte)1);
          Debug.Assert(testQuery[0].c_varbit == (byte)1);
        }

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