예제 #1
0
    /// <summary>
    /// Test CUBRIDSchemaProvider GetForeignKeys() method
    /// </summary>
    private static void Test_GetForeignKeys()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
        DataTable dt = schema.GetForeignKeys(new string[] { "game" });

        Debug.Assert(dt.Columns.Count == 9);
        Debug.Assert(dt.Rows.Count == 2);

        Debug.Assert(dt.Rows[0][0].ToString() == "event");
        Debug.Assert(dt.Rows[0][1].ToString() == "code");
        Debug.Assert(dt.Rows[0][2].ToString() == "game");
        Debug.Assert(dt.Rows[0][3].ToString() == "event_code");
        Debug.Assert(dt.Rows[0][4].ToString() == "1");
        Debug.Assert(dt.Rows[0][5].ToString() == "1");
        Debug.Assert(dt.Rows[0][6].ToString() == "1");
        Debug.Assert(dt.Rows[0][7].ToString() == "fk_game_event_code");
        Debug.Assert(dt.Rows[0][8].ToString() == "pk_event_code");

        Debug.Assert(dt.Rows[1][0].ToString() == "athlete");
        Debug.Assert(dt.Rows[1][1].ToString() == "code");
        Debug.Assert(dt.Rows[1][2].ToString() == "game");
        Debug.Assert(dt.Rows[1][3].ToString() == "athlete_code");
        Debug.Assert(dt.Rows[1][4].ToString() == "1");
        Debug.Assert(dt.Rows[1][5].ToString() == "1");
        Debug.Assert(dt.Rows[1][6].ToString() == "1");
        Debug.Assert(dt.Rows[1][7].ToString() == "fk_game_athlete_code");
        Debug.Assert(dt.Rows[1][8].ToString() == "pk_athlete_code");
      }
    }
예제 #2
0
    private static void Test_Encoding()
    {
        CUBRIDConnection conn = new CUBRIDConnection();

        conn.SetEncoding("cp1252");
        Debug.Assert(Encoding.GetEncoding("Windows-1252") == conn.GetEncoding());

        conn.SetEncoding("iso-8859-1");
        Debug.Assert(Encoding.GetEncoding("iso-8859-1") == conn.GetEncoding());

        conn.SetEncoding("euc-kr");
        Debug.Assert(Encoding.GetEncoding("euc-kr") == conn.GetEncoding());

        conn.SetEncoding("euc-jp");
        Debug.Assert(Encoding.GetEncoding("euc-jp") == conn.GetEncoding());

        conn.SetEncoding("gb2312");
        Debug.Assert(Encoding.GetEncoding("gb2312") == conn.GetEncoding());

        conn.SetEncoding("gbk");
        Debug.Assert(Encoding.GetEncoding("gbk") == conn.GetEncoding());

        conn.SetEncoding("xxxx");
        Debug.Assert(Encoding.Default == conn.GetEncoding());
    }
예제 #3
0
        public void conn_setIsolationLevel()
        {
            string conn_string = "server=test-db-server;database=demodb;port=33000;user=dba;password="******"drop table if exists test_isolation";
            cmd.ExecuteNonQuery();

            // open another session
            CUBRIDConnection conn2 = new CUBRIDConnection();
            conn2.ConnectionString = conn_string;
            conn2.Open();

            CUBRIDCommand cmd2 = new CUBRIDCommand();
            cmd2.Connection = conn2;


            // set up the isolation level to 
            conn.SetAutoCommit(false);
            conn.SetIsolationLevel(CUBRIDIsolationLevel.TRAN_REP_CLASS_COMMIT_INSTANCE);
            cmd.CommandText = "create table test_isolation(a int)";
            cmd.ExecuteNonQuery();

            conn.Commit();

            conn.Close();
        }
예제 #4
0
        //public static void ExecuteSQL(string sql)
        //{
        //    using (CUBRIDCommand cmd = new CUBRIDCommand(sql, connectionStr))
        //    {
        //        cmd.ExecuteNonQuery();
        //    }
        //}

        public static void ExecuteSQL(string sql, CUBRIDConnection conn)
        {
            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                cmd.ExecuteNonQuery();
            }
        }
예제 #5
0
        public void CUBRIDDataAdapter_ConstructorWithCUBRIDCommand_Test()
        {
           
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;
                conn.Open();

                DBHelper.ExecuteSQL("drop table if exists t", conn);
                DBHelper.ExecuteSQL("create table t (id int, name varchar(100))", conn);
                DBHelper.ExecuteSQL("insert into t values (1, 'Nancy')", conn);
                DBHelper.ExecuteSQL("insert into t values (2, 'Peter')", conn);

                string selectCommandText = "select * from t";

                using (CUBRIDCommand cmd = new CUBRIDCommand(selectCommandText, conn))
                {
                    CUBRIDDataAdapter adapter = new CUBRIDDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    adapter.Fill(ds);

                    //Update data
                    DataTable dt = ds.Tables[0];

                    Assert.AreEqual(1, (int)dt.Rows[0]["id"]);
                    Assert.AreEqual("Nancy", dt.Rows[0]["name"].ToString());

                    Assert.AreEqual(2, (int)dt.Rows[1]["id"]);
                    Assert.AreEqual("Peter", dt.Rows[1]["name"].ToString());

                    //revert test db
                    DBHelper.ExecuteSQL("drop table if exists t", conn);
                }
            }
        }
예제 #6
0
    /// <summary>
    /// Test basic SQL statements execution, using DataSet
    /// </summary>
    private static void Test_DataSet_Basic()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        String sql = "select * from nation order by `code` asc";
        CUBRIDDataAdapter da = new CUBRIDDataAdapter();
        da.SelectCommand = new CUBRIDCommand(sql, conn);
        DataSet ds = new DataSet("nation");
        da.Fill(ds);

        DataTable dt0 = ds.Tables["Table"];
        Debug.Assert(dt0 != null);

        dt0 = ds.Tables[0];

        Debug.Assert(dt0.Columns.Count == 4);
        Debug.Assert(dt0.DefaultView.Count == 215);
        Debug.Assert(dt0.DefaultView.AllowEdit == true);
        Debug.Assert(dt0.DefaultView.AllowDelete == true);
        Debug.Assert(dt0.DefaultView.AllowNew == true);
        Debug.Assert(dt0.DataSet.DataSetName == "nation");

        DataRow[] dataRow = dt0.Select("continent = 'Africa'");

        Debug.Assert(dataRow.Length == 54);
      }
    }
예제 #7
0
        public IList<string> GetOwners()
        {
            var owners = new List<string>();
            var conn = new CUBRIDConnection(connectionStr);
            conn.Open();

            try
            {
                using (conn)
                {
                    var schema = new CUBRIDSchemaProvider(conn);
                    DataTable dt = schema.GetUsers(new[] { "%" });
                    for (var i = 0; i < dt.Rows.Count; i++)
                    {
                        owners.Add(dt.Rows[i][0].ToString().ToLower());
                    }
                }
            }
            finally
            {
                conn.Close();
            }

            return owners;
        }
예제 #8
0
    /// <summary>
    /// Test exporting XML from DataSet
    /// </summary>
    private static void Test_DataSet_ExportXML()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        String sql = "select * from nation order by `code` asc";
        CUBRIDDataAdapter da = new CUBRIDDataAdapter();
        da.SelectCommand = new CUBRIDCommand(sql, conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "nation");

        string filename = @".\Test_DataSet_ExportXML.xml";
        ds.WriteXml(filename);

        if (!System.IO.File.Exists(filename))
        {
          throw new Exception("XML output file not found!");
        }
        else
        {
          System.IO.File.Delete(filename);
        }
      }
    }
예제 #9
0
        public void DataReader_Basic_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;
                conn.Open();

                String sql = "select * from nation order by `code` asc";

                LogTestStep("retrieve just one row");
                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
                    {
                        reader.Read(); //retrieve just one row

                        Assert.AreEqual(4, reader.FieldCount);
                        Assert.AreEqual("AFG", reader.GetString(0));
                        Assert.AreEqual("Afghanistan", reader.GetString(1));
                        Assert.AreEqual("Asia",reader.GetString(2));
                        Assert.AreEqual("Kabul", reader.GetString(3));

                        LogStepPass();
                    }
                }
            }

            LogTestResult();

        }
예제 #10
0
    /// <summary>
    /// Test CREATE Database Stored Functions calls
    /// </summary>
    private static void Test_CreateFunction()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        try
        {
          TestCases.ExecuteSQL("drop function sp1", conn);
        }
        catch { }

        string sql = "CREATE FUNCTION sp1(a int) RETURN string AS LANGUAGE JAVA NAME 'SpTest.test1(int) return java.lang.String'";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          cmd.ExecuteNonQuery();
        }

        CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
        DataTable dt = schema.GetProcedures(null);

        Debug.Assert(dt.Rows.Count == 1);

        TestCases.ExecuteSQL("drop function sp1", conn);
      }
    }
예제 #11
0
    /// <summary>
    ///   Initializes a new instance of the <see cref="CUBRIDTransaction" /> class.
    /// </summary>
    /// <param name="conn"> The connection. </param>
    /// <param name="isolationLevel"> The isolation level. </param>
    public CUBRIDTransaction(CUBRIDConnection conn, CUBRIDIsolationLevel isolationLevel)
    {
      if (isolationLevel == CUBRIDIsolationLevel.TRAN_UNKNOWN_ISOLATION)
        throw new ArgumentException(Utils.GetStr(MsgId.UnknownIsolationLevelNotSupported));

      this.conn = conn;
      conn.IsolationLevel = isolationLevel;
      conn.SetIsolationLevel(isolationLevel);
      open = true;
    }
예제 #12
0
    ///<summary>
    /// Test BLOB SELECT
    /// </summary>
    private static void Test_Blob_Select()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CreateTestTableLOB(conn);

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

        byte[] bytes1 = new byte[256];
        bytes1[0] = 69;
        bytes1[1] = 98;
        bytes1[2] = 99;
        bytes1[255] = 122;

        Blob.SetBytes(1, bytes1);

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

        string sql = "SELECT b from t";
        CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);
        DbDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
          CUBRIDBlob bImage = (CUBRIDBlob)reader[0];
          byte[] bytes = new byte[(int)bImage.BlobLength];
          bytes = bImage.GetBytes(1, (int)bImage.BlobLength);

          Debug.Assert(bytes1.Length == bytes.Length, "The selected BLOB length is not valid!");
          bool ok = true;
          for (int i = 0; i < bytes.Length; i++)
          {
            if (bytes1[i] != bytes[i])
              ok = false;
          }

          Debug.Assert(ok == true, "The BLOB was not selected correctly!");
        }

        cmd.Close();

        CleanupTestTableLOB(conn);
      }
    }
예제 #13
0
        public void conn_Database()
        {
            string conn_string = "server=test-db-server;database=demodb;port=33000;user=dba;password=";
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.ConnectionString = conn_string;
            Console.WriteLine(conn.Database);
            conn.Open();
            Console.WriteLine(conn.Database);

            conn.Close();
        }
예제 #14
0
        public static object GetSingleValue(string sql, CUBRIDConnection conn)
        {
            object ret = null;

            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                ret = cmd.ExecuteScalar();
            }

            return ret;
        }
예제 #15
0
        public static int GetTablesCount(string tableName, CUBRIDConnection conn)
        {
            int count = 0;
            string sql = "select count(*) from db_class where class_name = '" + tableName + "'";

            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                count = (int)cmd.ExecuteScalar();
            }

            return count;
        }
예제 #16
0
        public static int GetTableRowsCount(string tableName, CUBRIDConnection conn)
        {
            int count = -1;
            string sql = "select count(*) from `" + tableName + "`";

            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                count = (int)cmd.ExecuteScalar();
            }

            return count;
        }
예제 #17
0
    /// <summary>
    /// Test CUBRIDTransaction class
    /// </summary>
    private static void Test_Transaction()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        TestCases.ExecuteSQL("drop table if exists t", conn);

        conn.BeginTransaction();

        string sql = "create table t(idx integer)";
        using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
        {
          command.ExecuteNonQuery();
        }

        int tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 1);

        conn.Rollback();

        //Verify the table does not exist
        tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 0);

        conn.BeginTransaction();

        sql = "create table t(idx integer)";
        using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
        {
          command.ExecuteNonQuery();
        }

        tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 1);

        conn.Commit();

        tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 1);

        conn.BeginTransaction();

        TestCases.ExecuteSQL("drop table t", conn);

        conn.Commit();

        tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 0);
      }
    }
예제 #18
0
    /// <summary>
    /// Test CUBRIDTransaction class, using parameters
    /// </summary>
    private static void Test_Transaction_Parameters()
    {
      DbTransaction tran = null;

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

        CreateTestTable(conn);

        tran = conn.BeginTransaction();

        string sql = "insert into t values(?, ?, ?, ?, ?, ?)";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          CUBRIDParameter p1 = new CUBRIDParameter("?p1", CUBRIDDataType.CCI_U_TYPE_INT);
          p1.Value = 1;
          cmd.Parameters.Add(p1);

          CUBRIDParameter p2 = new CUBRIDParameter("?p2", CUBRIDDataType.CCI_U_TYPE_CHAR);
          p2.Value = 'A';
          cmd.Parameters.Add(p2);

          CUBRIDParameter p3 = new CUBRIDParameter("?p3", CUBRIDDataType.CCI_U_TYPE_STRING);
          p3.Value = "cubrid";
          cmd.Parameters.Add(p3);

          CUBRIDParameter p4 = new CUBRIDParameter("?p4", CUBRIDDataType.CCI_U_TYPE_FLOAT);
          p4.Value = 1.1f;
          cmd.Parameters.Add(p4);

          CUBRIDParameter p5 = new CUBRIDParameter("?p5", CUBRIDDataType.CCI_U_TYPE_DOUBLE);
          p5.Value = 2.2d;
          cmd.Parameters.Add(p5);

          CUBRIDParameter p6 = new CUBRIDParameter("?p6", CUBRIDDataType.CCI_U_TYPE_DATE);
          p6.Value = DateTime.Now;
          cmd.Parameters.Add(p6);

          cmd.ExecuteNonQuery();

          tran.Commit();
        }

        Debug.Assert(GetTableRowsCount("t", conn) == 1);

        CleanupTestTable(conn);
      }
    }
예제 #19
0
    /// <summary>
    /// Test multiple connections
    /// </summary>
    private static void Test_MultipleConnections()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        TestCases.ExecuteSQL("drop table if exists t", conn);
        TestCases.ExecuteSQL("create table t(idx integer)", conn);

        string sql = "select * from nation";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            int count = 0;
            while (reader.Read() && count++ < 3)
            {
              using (CUBRIDConnection conn2 = new CUBRIDConnection())
              {
                conn2.ConnectionString = conn.ConnectionString;
                conn2.Open();
                string sqlInsert = "insert into t values(" + count + ")";
                using (CUBRIDCommand cmdInsert = new CUBRIDCommand(sqlInsert, conn2))
                {
                  cmdInsert.ExecuteNonQuery();
                }
              }
            }
          }
        }

        using (CUBRIDConnection conn2 = new CUBRIDConnection())
        {
          conn2.ConnectionString = conn.ConnectionString;
          conn2.Open();
          string sqlSelect = "select count(*) from t";
          using (CUBRIDCommand cmd = new CUBRIDCommand(sqlSelect, conn2))
          {
            using (DbDataReader reader = cmd.ExecuteReader())
            {
              reader.Read();
              Debug.Assert(reader.GetInt32(0) == 3);
            }
          }
        }

        TestCases.ExecuteSQL("drop table if exists t", conn);
      }
    }
예제 #20
0
    /// <summary>
    /// Test Encodings support
    /// </summary>
    private static void Test_Encodings()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = "server="+ip+";database=demodb;port=33000;user=public;password=;charset=utf-8";
        conn.Open();

        TestCases.ExecuteSQL("drop table if exists t", conn);
        TestCases.ExecuteSQL("create table t(a int, b varchar(100))", conn);

        String sql = "insert into t values(1 ,'¾Æ¹«°³')";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          cmd.ExecuteNonQuery();
        }

        sql = "select * from t where b = '¾Æ¹«°³'";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            reader.Read(); //retrieve just one row

            Debug.Assert(reader.GetInt32(0) == 1);
            Debug.Assert(reader.GetString(1) == "¾Æ¹«°³");
          }
        }

        sql = "update t set b='¾Æ¹°³'";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          cmd.ExecuteNonQuery();
        }

        sql = "select * from t where b = '¾Æ¹°³'";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            reader.Read(); //retrieve just one row

            Debug.Assert(reader.GetInt32(0) == 1);
            Debug.Assert(reader.GetString(1) == "¾Æ¹°³");
          }
        }

        TestCases.ExecuteSQL("drop table if exists t", conn);
      }
    }
예제 #21
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);
      }
    }
예제 #22
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);
      }
    }
예제 #23
0
    /// <summary>
    /// Test CUBRIDSchemaProvider GetColumns() method
    /// </summary>
    private static void Test_GetColumns()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
        DataTable dt = schema.GetColumns(new string[] { "game" });

        Debug.Assert(dt.Columns.Count == 11);
        Debug.Assert(dt.Rows.Count == 7);

        Debug.Assert(dt.Rows[0][3].ToString() == "host_year");
        Debug.Assert(dt.Rows[1][3].ToString() == "event_code");
      }
    }
예제 #24
0
    /// <summary>
    /// Test CUBRIDSchemaProvider GetTables() method
    /// </summary>
    private static void Test_GetTables()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
        DataTable dt = schema.GetTables(new string[] { "%" });

        Debug.Assert(dt.Columns.Count == 3);
        Debug.Assert(dt.Rows.Count == 10);

        Debug.Assert(dt.Rows[0][0].ToString() == "demodb");
        Debug.Assert(dt.Rows[0][1].ToString() == "demodb");
        Debug.Assert(dt.Rows[0][2].ToString() == "stadium");
      }
    }
예제 #25
0
    //http://msdn.microsoft.com/en-us/library/tf579hcz%28v=vs.80%29.aspx
    /// <summary>
    /// Test CUBRIDCommandBuilder class, and methods used to automatically get SQL commands
    /// </summary>
    private static void Test_CommandBuilder_GetCommands()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        String sql = "select * from nation order by `code` asc";
        CUBRIDDataAdapter da = new CUBRIDDataAdapter(sql, conn);

        CUBRIDCommandBuilder cmdBuilder = new CUBRIDCommandBuilder(da);
        da.UpdateCommand = cmdBuilder.GetUpdateCommand();
        Debug.Assert(da.UpdateCommand.CommandText == "UPDATE `nation` SET `code` = ?, `name` = ?, `continent` = ?, `capital` = ? WHERE ((`code` = ?) AND (`name` = ?) AND ((? = 1 AND `continent` IS NULL) OR (`continent` = ?)) AND ((? = 1 AND `capital` IS NULL) OR (`capital` = ?)))");
        da.InsertCommand = cmdBuilder.GetInsertCommand();
        Debug.Assert(da.InsertCommand.CommandText == "INSERT INTO `nation` (`code`, `name`, `continent`, `capital`) VALUES (?, ?, ?, ?)");
        da.DeleteCommand = cmdBuilder.GetDeleteCommand();
        Debug.Assert(da.DeleteCommand.CommandText == "DELETE FROM `nation` WHERE ((`code` = ?) AND (`name` = ?) AND ((? = 1 AND `continent` IS NULL) OR (`continent` = ?)) AND ((? = 1 AND `capital` IS NULL) OR (`capital` = ?)))");
      }
    }
예제 #26
0
    /// <summary>
    /// Test CUBRIDCommand column properties
    /// </summary>
    private static void Test_Command_ColumnProperties()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        String sql = "select * from nation";
        CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);
        CUBRIDCommand cmd2 = cmd.Clone();

        try
        {
            cmd.Cancel();
        }
        catch (Exception e)
        {
            string r = "System.NotSupportedException: Specified method is not supported";
            Debug.Assert(e.Message.Substring(0,r.Length) == r);
        }

        Debug.Assert(cmd.CommandType == cmd2.CommandType);
        CUBRIDDataAdapter da = new CUBRIDDataAdapter();
        da.SelectCommand = cmd;
        DataTable dt = new DataTable("");
        da.FillSchema(dt, SchemaType.Source);//To retrieve all the column properties you have to use the FillSchema() method

        Debug.Assert(cmd.ColumnInfos[0].Name == "code");
        Debug.Assert(cmd.ColumnInfos[0].IsPrimaryKey == true);
        Debug.Assert(cmd.ColumnInfos[0].IsForeignKey == false);
        Debug.Assert(cmd.ColumnInfos[0].IsNullable == false);
        Debug.Assert(cmd.ColumnInfos[0].RealName == "");
        Debug.Assert(cmd.ColumnInfos[0].Precision == 3);
        Debug.Assert(cmd.ColumnInfos[0].Scale == 0);
        Debug.Assert(cmd.ColumnInfos[0].IsAutoIncrement == false);
        Debug.Assert(cmd.ColumnInfos[0].IsReverseIndex == false);
        Debug.Assert(cmd.ColumnInfos[0].IsReverseUnique == false);
        Debug.Assert(cmd.ColumnInfos[0].IsShared == false);
        Debug.Assert(cmd.ColumnInfos[0].Type == CUBRIDDataType.CCI_U_TYPE_CHAR);
        Debug.Assert(cmd.ColumnInfos[0].Table == "nation");
      }
    }
예제 #27
0
        public void conn_dataAdapter_update()
        {
            string conn_string = "server=test-db-server;database=demodb;port=33000;user=dba;password="******"drop table if exists tbl";
            cmd.ExecuteNonQuery();
            cmd.CommandText = "create table tbl (id int, name varchar(100))";
            cmd.ExecuteNonQuery();
            cmd.CommandText = "insert into tbl values (1, 'Nancy')";
            cmd.ExecuteNonQuery();
            cmd.CommandText = "insert into tbl values (2, 'Peter')";
            cmd.ExecuteNonQuery();

            CUBRIDDataAdapter adapter = new CUBRIDDataAdapter();

            //SelectCommand
            string sql = "select * from tbl";
            CUBRIDCommand cmd2 = new CUBRIDCommand(sql, conn);
            adapter.SelectCommand = cmd2;

            sql = "insert into tbl values (3, 'Kitty')";
            cmd2 = new CUBRIDCommand(sql, conn);
            adapter.InsertCommand = cmd2;
            adapter.InsertCommand.ExecuteNonQuery();

            sql = "update tbl set name='Mandy' where id=1";
            cmd2 = new CUBRIDCommand(sql, conn);
            adapter.UpdateCommand = cmd2;
            adapter.UpdateCommand.ExecuteNonQuery();

            sql = "delete from tbl where name='Mandy'";
            cmd2 = new CUBRIDCommand(sql, conn);
            adapter.DeleteCommand = cmd2;
            adapter.DeleteCommand.ExecuteNonQuery();

            conn.Close();
        }
예제 #28
0
    //http://msdn.microsoft.com/en-us/library/bbw6zyha%28v=vs.80%29.aspx
    /// <summary>
    /// Test DataTable implicit UPDATE
    /// </summary>
    private static void Test_DataTable_UpdateImplicit()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        String sql = "select * from nation order by `code` asc";
        using (CUBRIDDataAdapter da = new CUBRIDDataAdapter(sql, conn))
        {

          using (CUBRIDDataAdapter daCmd = new CUBRIDDataAdapter(sql, conn))
          {
            CUBRIDCommandBuilder cmdBuilder = new CUBRIDCommandBuilder(daCmd);
            da.UpdateCommand = cmdBuilder.GetUpdateCommand();
          }

          DataTable dt = new DataTable("nation");
          da.Fill(dt);

          //Update data
          DataRow workRow = dt.Rows[0];

          Debug.Assert(workRow["code"].ToString() == "AFG");
          Debug.Assert(workRow["capital"].ToString() == "Kabul");

          workRow.BeginEdit();
          workRow["capital"] = "MyKabul";
          workRow.EndEdit();
          da.Update(dt);

          Debug.Assert(workRow["capital"].ToString() == "MyKabul");
          Debug.Assert(workRow.RowState.ToString() != "New");
        }

        Debug.Assert((string)GetSingleValue("select capital from nation where `code` = 'AFG'", conn) == "MyKabul");
        //Revert changes
        ExecuteSQL("update nation set capital = 'Kabul' where capital = 'MyKabul'", conn);
        Debug.Assert((string)GetSingleValue("select capital from nation where `code` = 'AFG'", conn) == "Kabul");
      }
    }
예제 #29
0
        public void Clone_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                LogTestStep("Clone a connection");
                conn.ConnectionString = DBHelper.connString;
                Log("change a property value of the original connection");
                conn.SetConnectionTimeout(45);
                conn.Open();

                Log("call the Clone method");
                CUBRIDConnection clonedConn = conn.Clone();
                Assert.IsTrue(clonedConn != null);

                Log("The property values are different between the original connection and the cloned connection");
                Assert.AreEqual(45, conn.ConnectionTimeout);
                Assert.AreEqual(30, clonedConn.ConnectionTimeout);

                try
                {
                    clonedConn.Open();

                    Log("Close the original connection, check the cloned connection works well");
                    conn.Close();
                    Assert.IsTrue(DBHelper.GetTableRowsCount("db_class", clonedConn) > 0);
                    clonedConn.Close();
                    LogStepPass();
                }
                catch (Exception ex)
                {
                    Log(ex.Message);
                    LogStepFail();
                }
                finally
                {
                    LogTestResult();
                    conn.Close();
                    clonedConn.Close();
                }
            }
        }
예제 #30
0
    /// <summary>
    /// Test ConnectionStringBuilder class
    /// </summary>
    private static void Test_ConnectionStringBuilder()
    {
        CUBRIDConnectionStringBuilder sb = new CUBRIDConnectionStringBuilder(ip, 33000, "demodb", "public", "",
                                                                           "utf-8", false);
      //Note: Do not use sb.ConnectionString with empty password

      using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString()))
      {
        conn.Open();
      }

      sb = new CUBRIDConnectionStringBuilder(ip, 33000, "demodb", "public", "wrong password", "utf-8", false);
      using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString()))
      {
        try
        {
          conn.Open();
        }
        catch (Exception ex)
        {
          string r = "Incorrect or missing password.";
          Debug.Assert(ex.Message.Substring(0,r.Length)== r);
        }
      }

      sb = new CUBRIDConnectionStringBuilder(TestCases.connString);
      using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString()))
      {
        conn.Open();
      }

      sb = new CUBRIDConnectionStringBuilder();
      sb.User = "******";
      sb.Database = "demodb";
      sb.Port = "33000";
      sb.Server = ip;
      using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString()))
      {
        conn.Open();
      }
    }