Exemple #1
0
        /// <summary>
        /// Test CUBRIDConnection BatchExecuteNoQuery() method
        /// </summary>
        private static void Test_BatchExecuteNoQuery()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

                string[] sqls = new string[3];
                sqls[0] = "create table t(id int)";
                sqls[1] = "insert into t values(1)";
                sqls[2] = "insert into t values(2)";

                conn.BatchExecuteNoQuery(sqls);

                string sql = "select count(*) from t";
                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        Debug.Assert(reader.GetInt32(0) == 2);
                    }
                }

                TestCases.ExecuteSQL("drop table t", conn);
            }
        }
Exemple #2
0
        public void CUBRIDCommand_Constructor_SQLAndConnAndTran_Test()
        {
            CUBRIDConnection conn = new CUBRIDConnection();

            conn.ConnectionString = DBHelper.connString;
            conn.Open();
            conn.SetAutoCommit(false);

            string            sql         = "drop table if exists t";
            CUBRIDTransaction transaction = new CUBRIDTransaction(conn, CUBRIDIsolationLevel.TRAN_DEFAULT_ISOLATION);
            CUBRIDCommand     cmd         = new CUBRIDCommand(sql, conn, transaction);

            conn.BeginTransaction();
            cmd.ExecuteNonQuery();
            cmd.CommandText = "create table t (id int, name varchar(50))";
            cmd.ExecuteNonQuery();
            cmd.CommandText = "insert into t values(1, 'Nancy')";
            cmd.ExecuteNonQuery();
            conn.Commit();

            cmd.CommandText = "select * from t";
            CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();

            reader.Read();
            Assert.AreEqual(2, reader.FieldCount);
            Assert.AreEqual("1", reader.GetString(0));
            Assert.AreEqual("Nancy", reader.GetString(1));

            cmd.Close();
            reader.Close();
            conn.Close();
        }
Exemple #3
0
        public void CUBRIDCommand_ExecuteReader_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;
                conn.Open();

                string sql = "select * from nation order by code asc";
                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
                    {
                        //verify the first two results
                        reader.Read();
                        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));

                        reader.Read();
                        Assert.AreEqual(4, reader.FieldCount);
                        Assert.AreEqual("AHO", reader.GetString(0));
                        Assert.AreEqual("Netherlands Antilles", reader.GetString(1));
                        Assert.AreEqual("Americas", reader.GetString(2));
                        Assert.AreEqual("Willemstad", reader.GetString(3));
                    }
                }
            }
        }
Exemple #4
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();
        }
Exemple #5
0
            public void CUBRIDSchemaProviderConstructorTest()
            {
                CUBRIDConnection connection = new CUBRIDConnection();;  // TODO: Initialize to an appropriate value

                connection.ConnectionString = DBHelper.connString;
                connection.Open();
                CUBRIDSchemaProvider target = new CUBRIDSchemaProvider(connection);


                CUBRIDCommand cmd = new CUBRIDCommand();

                cmd.Connection  = connection;
                cmd.CommandText = "select * from nation order by code asc";


                CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();

                reader.Read();
                Assert.AreEqual(4, reader.FieldCount);


                cmd.Close();
                reader.Close();
                connection.Close();
            }
Exemple #6
0
        private static List <object> GetTableValues(string tableName, int indexPosition, string[] columnNames)
        {
            List <object> columnValues = new List <object>();

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

                using (CUBRIDCommand cmd = new CUBRIDCommand("select * from " + tableName, conn))
                {
                    DbDataReader reader = cmd.ExecuteReader();
                    for (int i = 0; i < indexPosition; i++)
                    {
                        reader.Read();
                    }

                    for (int i = 0; i < columnNames.Length; i++)
                    {
                        columnValues.Add(reader[columnNames[i]]);
                    }
                }
            }

            return(columnValues);
        }
Exemple #7
0
        public List <string> GetSequences(string tablename, string column)
        {
            var sequences = new List <string>();
            var conn      = new CUBRIDConnection(connectionStr);

            conn.Open();

            try
            {
                using (conn)
                {
                    CUBRIDCommand seqCommand = conn.CreateCommand();
                    string        sqlCmd     = String.Format(@"select [name] from db_serial where class_name='{0}' and att_name='{1}'",
                                                             tablename,
                                                             column);
                    seqCommand.CommandText = sqlCmd;
                    var seqReader = (CUBRIDDataReader)seqCommand.ExecuteReader(CommandBehavior.CloseConnection);
                    while (seqReader.Read())
                    {
                        sequences.Add(seqReader.GetString(0));
                    }
                }
            }
            finally
            {
                conn.Close();
            }

            return(sequences);
        }
Exemple #8
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);
                }
            }
        }
        public void DataReader_GetDate_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 (timeTest time,datetimeTest datetime)", conn);
                DBHelper.ExecuteSQL("insert into t values('12:07:39', '2013-03-18 12:07:12')", conn);

                using (CUBRIDCommand cmd = new CUBRIDCommand("select * from t", conn))
                {
                    using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
                    {
                        reader.Read();
                        Assert.AreEqual(2, reader.FieldCount);
                        Assert.AreEqual("12:07:39", reader.GetTime(0));
                        Assert.AreEqual("2013-03-18", reader.GetDate(1));

                        DateTime dt = reader.GetDateTime(1);
                        Assert.AreEqual("2013-03-18 12:07:12", dt.ToString("yyyy-MM-dd HH:mm:ss"));
                    }
                }

                //revert test db
                DBHelper.ExecuteSQL("drop table if exists t", conn);
            }
        }
Exemple #10
0
        /// <summary>
        /// Test DateTime types
        /// </summary>
        private static void Test_DateTime_Types()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

                CleanupTestTable(conn);
                TestCases.ExecuteSQL("create table t(dt datetime)", conn);

                TestCases.ExecuteSQL("insert into t values('10/31/2008 10:20:30.040')", conn);

                using (CUBRIDCommand cmd = new CUBRIDCommand("select * from t", conn))
                {
                    CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();

                    reader.Read();
                    Debug.Assert(reader.GetDateTime(0) == new DateTime(2008, 10, 31, 10, 20, 30, 040));
                    Debug.Assert(reader.GetDate(0) == "2008-10-31");
                    Debug.Assert(reader.GetDate(0, "yy/MM/dd") == "08/10/31");
                    Debug.Assert(reader.GetTime(0) == "10:20:30");
                    Debug.Assert(reader.GetTime(0, "HH") == "10");
                    Debug.Assert(reader.GetTimestamp(0) == "2008-10-31 10:20:30.040");
                    Debug.Assert(reader.GetTimestamp(0, "yyyy HH") == "2008 10");
                }

                CleanupTestTable(conn);
            }
        }
Exemple #11
0
        /// <summary>
        /// Test SQL statements execution, using DataReader and parameters
        /// </summary>
        private static void Test_DataReader_Parameters()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

                CUBRIDCommand cmd = new CUBRIDCommand("select `code` from nation where capital = ?", conn);

                CUBRIDParameter param = new CUBRIDParameter();
                param.ParameterName  = "?";
                param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_STRING;
                param.Value          = "Kabul";

                cmd.Parameters.Add(param);

                DbDataReader reader = cmd.ExecuteReader();

                Debug.Assert(reader.FieldCount == 1);

                while (reader.Read()) //only one row is available
                {
                    Debug.Assert(reader.GetString(0) == "AFG");
                }

                cmd.Close();
            }
        }
Exemple #12
0
        /// <summary>
        /// Test CREATE Stored Procedures calls
        /// </summary>
        private static void Test_CreateProcedure()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

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

                string sql = "CREATE PROCEDURE \"sp2\"() AS LANGUAGE JAVA NAME 'SpTest.test2()'";
                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 procedure sp2", conn);
            }
        }
Exemple #13
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);
            }
        }
Exemple #14
0
        /// <summary>
        /// Test basic SQL statements execution, using parameters
        /// </summary>
        private static void Test_Command_Multiple_CommandText()
        {
            string sqlTablesCount = "select count(*) from db_class";
            int    tablesCount, newTableCount;

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();
                using (CUBRIDCommand cmd = conn.CreateCommand())
                {
                    tablesCount     = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                    cmd.CommandText = "create table test(id int)";
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                    newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                    Debug.Assert(newTableCount == tablesCount + 1);
                    cmd.CommandText = "drop table test";
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                    newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                    Debug.Assert(newTableCount == tablesCount);
                }
            }
        }
Exemple #15
0
        public void CUBRIDCommand_Constructor_SQL_Test()
        {
            CUBRIDConnection conn = new CUBRIDConnection();

            conn.ConnectionString = DBHelper.connString;

            string        sql = "select * from nation order by code asc";
            CUBRIDCommand cmd = new CUBRIDCommand(sql);

            cmd.Connection = conn;

            conn.Open();
            CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();

            reader.Read();
            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));

            cmd.Close();
            reader.Close();
            conn.Close();
        }
        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();
        }
Exemple #17
0
        public void CUBRIDCommand_Close_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;

                string        sql = "select * from nation order by code asc";
                CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);

                conn.Open();
                CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();
                reader.Read();
                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));

                cmd.Close();

                try
                {
                    cmd.CommandText = "drop table if exists t";
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Assert.AreEqual("Some message about the cmd cannot be used", ex.Message);
                }
            }
        }
Exemple #18
0
        public void DataReader_MultiQuery_Test2()
        {
            string           conn_string = "server=test-db-server;database=demodb;port=33000;user=dba;password="******"select s_name from code where s_name='X'; select name from nation where name='Algeria';";
            CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);

            CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(reader.GetString(0));
            }
            ;

            while (reader.NextResult())
            {
                Console.WriteLine("=============================");

                while (reader.Read())
                {
                    Console.WriteLine(reader.GetString(0));
                }
                ;
            }

            conn.Close();
        }
Exemple #19
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();
            }
        }
Exemple #20
0
        public void i18n_issue()
        {
            CUBRIDConnection conn = new CUBRIDConnection();

            conn.ConnectionString = "server=test-db-server;database=demodb;port=33000;user=dba;password="******"utf-8");

            cmd.CommandText = "drop table if exists 测试表;";
            cmd.ExecuteNonQuery();

            cmd.CommandText = "create table 测试表 (名称 varchar);";
            cmd.ExecuteNonQuery();

            cmd.CommandText = "insert into 测试表 value('小明');";
            cmd.ExecuteNonQuery();

            cmd.CommandText = "select 名称 from 测试表;";
            CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(reader.GetString(0));
            }
            ;

            conn.Close();
        }
Exemple #21
0
        private static void Test_apis_669()
        {
            String sql = "select s_name from code where f_name = 'Woman';select * from code;";

            CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);

            CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(reader.GetString(0));
            }
            ;

            while (reader.NextResult())
            {
                Console.WriteLine("=============================");

                while (reader.Read())
                {
                    Console.WriteLine(reader.GetString(0));
                    //    Console.WriteLine(reader.GetString(1));
                }
                ;
            }
        }
Exemple #22
0
        public void CUBRIDCommand_ExecuteScalar_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;
                conn.Open();

                string        sql = "select * from nation order by code asc";
                CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);

                LogTestStep("Test ExecuteScalar - return a value");
                object obj = cmd.ExecuteScalar();

                Assert.AreEqual("AFG", obj.ToString());
                LogStepPass();

                LogTestStep("Test ExecuteScalar - return null");
                cmd.CommandText = "drop table if exists test_scalar;";
                cmd.ExecuteNonQuery();
                cmd.CommandText = "create table test_scalar(a int);";
                cmd.ExecuteNonQuery();
                cmd.CommandText = "insert into test_scalar values(NULL);";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "select * from test_scalar";
                obj             = cmd.ExecuteScalar();
                Assert.AreEqual(DBNull.Value, obj);
                LogStepPass();

                cmd.Close();
                LogTestResult();
            }
        }
Exemple #23
0
        public List <string> GetSequences(List <Table> tables)
        {
            var sequences = new List <string>();
            var conn      = new CUBRIDConnection(connectionStr);

            conn.Open();

            try
            {
                using (conn)
                {
                    CUBRIDCommand seqCommand = conn.CreateCommand();
                    seqCommand.CommandText = "select [name], class_name from db_serial";
                    var seqReader = (CUBRIDDataReader)seqCommand.ExecuteReader(CommandBehavior.CloseConnection);
                    while (seqReader.Read())
                    {
                        sequences.AddRange(from table in tables where table.Name.ToUpper() == seqReader.GetString(1).ToUpper() select seqReader.GetString(0));
                    }
                }
            }
            finally
            {
                conn.Close();
            }

            return(sequences);
        }
Exemple #24
0
        /// <summary>
        /// Test BLOB SELECT, using CUBRIDDataAdapter and DataTable
        /// </summary>
        private static void Test_Blob_SelectDataAdapter()
        {
            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    Blob1 = new CUBRIDBlob(conn);
                CUBRIDBlob    Blob2 = new CUBRIDBlob(conn);

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

                Blob1.SetBytes(1, bytes1);

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

                string            sql = "SELECT b from t";
                DataTable         dt  = new DataTable("t");
                CUBRIDDataAdapter da  = new CUBRIDDataAdapter();
                da.SelectCommand = new CUBRIDCommand(sql, conn);
                da.Fill(dt);

                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    CUBRIDBlob bImage = (CUBRIDBlob)dt.Rows[j]["b"];
                    byte[]     bytes  = new byte[(int)bImage.BlobLength];
                    bytes = bImage.GetBytes(1, (int)bImage.BlobLength);

                    Debug.Assert(bytes1.Length == bytes.Length, "The selected 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!");
                }

                CleanupTestTableLOB(conn);
            }
        }
Exemple #25
0
        /// <summary>
        /// Test CLOB UPDATE
        /// </summary>
        private static void Test_Clob_Update()
        {
            String str;

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

                CreateTestTableLOB(conn);

                string sql1 = "insert into t (c) values(?)";
                using (CUBRIDCommand cmd1 = new CUBRIDCommand(sql1, conn))
                {
                    CUBRIDClob Clob1 = new CUBRIDClob(conn);

                    Clob1.SetString(1, "test string to be inserted");

                    CUBRIDParameter param1 = new CUBRIDParameter();
                    param1.ParameterName  = "?";
                    param1.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;
                    param1.Value          = Clob1;
                    cmd1.Parameters.Add(param1);
                    cmd1.ExecuteNonQuery();
                    cmd1.Close();

                    string        sql = "UPDATE t SET c = ?";
                    CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);

                    CUBRIDClob Clob = new CUBRIDClob(conn);
                    str = conn.ConnectionString; //Use the ConnectionString for testing

                    Clob.SetString(1, str);
                    CUBRIDParameter param = new CUBRIDParameter();
                    param.ParameterName  = "?";
                    param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;
                    param.Value          = Clob;
                    cmd.Parameters.Add(param);
                    cmd.ExecuteNonQuery();
                }

                string sql2 = "SELECT c from t";
                using (CUBRIDCommand cmd2 = new CUBRIDCommand(sql2, conn))
                {
                    DbDataReader reader = cmd2.ExecuteReader();
                    while (reader.Read())
                    {
                        CUBRIDClob cImage = (CUBRIDClob)reader[0];
                        string     str2   = cImage.GetString(1, (int)cImage.ClobLength);

                        Debug.Assert(str.Length == str2.Length, "The selected CLOB length is not valid!");
                        Debug.Assert(str.Equals(str2), "The CLOB was not selected correctly!");
                    }
                }

                CleanupTestTableLOB(conn);
            }
        }
        private static void TestParameterCollection()
        {
            string sql = "drop table if exists TestTable;";

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

            sql = "CREATE TABLE TestTable (clsid BLOB);";
            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                cmd.ExecuteNonQuery();
            }
            byte[] bytes = new byte[36] {
                55, 56, 50, 69, 55, 57, 67, 69, 45, 50, 70, 68, 68, 45, 52, 68, 50, 55, 45, 65, 51, 48, 48, 45, 69, 48, 56, 56, 70, 56, 68, 68, 55, 54, 66, 69
            };
            sql = "INSERT INTO TestTable VALUES(?);";
            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                CUBRIDBlob Blob = new CUBRIDBlob(conn);
                Blob.SetBytes(1, bytes);
                CUBRIDParameter param = new CUBRIDParameter();
                param.ParameterName      = "?p";
                param.Value              = Blob; cmd.Parameters.Add(param);
                cmd.Parameters[0].DbType = DbType.Binary;

                try
                {
                    cmd.Parameters.Insert(0, param);
                }
                catch (Exception e)
                {
                    Debug.Assert(e.Message == "Parameter already added to the collection!");
                }
                try
                {
                    cmd.Parameters.Insert(0, null);
                }
                catch (Exception e)
                {
                    string es = e.ToString();
                    Debug.Assert(e.Message == "Only CUBRIDParameter objects are valid!");
                }
                cmd.ExecuteNonQuery();
            }
            using (CUBRIDCommand cmd = new CUBRIDCommand("Select * from TestTable", conn))
            {
                using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
                {
                    reader.Read(); byte[] buffer = new byte[36];
                    long          len            = reader.GetBytes(0, 0, buffer, 0, 36);
                    ASCIIEncoding encoding       = new ASCIIEncoding();
                    string        clsid          = encoding.GetString(buffer);
                    Debug.Assert(clsid == "782E79CE-2FDD-4D27-A300-E088F8DD76BE");
                }
            }
        }
Exemple #27
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);
            }
        }
Exemple #28
0
        private static void test()
        {
            String ip = "192.168.0.1";
            String ConnectionString = "server=" + ip + ";database=demodb;port=33000;user=public;password="******"SELECT * FROM record;";
                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Object[] values     = new Object[reader.FieldCount];
                            int      fieldCount = reader.GetValues(values);
                            foreach (Object obj in values)
                            {
                                Console.Out.Write(obj.ToString() + "," + obj.GetType() + "|");
                            }
                            Console.Out.WriteLine();

                            /*
                             *  EXPLAIN athlete;                    //same as Describe, basic information of table
                             *  SHOW TABLES;                        //get all table names
                             *  SHOW FULL COLUMNS FROM athlete;     //same as Describe but with comments
                             *  SHOW INDEXES FROM athlete;          //get table information like fk
                             *  SHOW CREATE TABLE athlete;          //get query string of creating the table
                             */
                        }
                        //(read the values using: reader.Get...() methods)
                    }
                }

                Console.Out.WriteLine("CUBRID SQL Connection");
                conn.Close();
            }

            /*using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString()))
             * {
             *  conn.Open();
             *  String sql = "SELECT * FROM athlete;";
             *  using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
             *  {
             *      using (DbDataReader reader = cmd.ExecuteReader())
             *      {
             *          reader.Read();
             *          Console.Out.WriteLine(reader.GetString(3));
             *          //(read the values using: reader.Get...() methods)
             *      }
             *  }
             * }*/
        }
Exemple #29
0
        public static object GetSingleValue(string sql, CUBRIDConnection conn)
        {
            object ret = null;

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

            return(ret);
        }
Exemple #30
0
        /// <summary>
        /// Test CLOB INSERT, using a txt input file
        /// </summary>
        private static void Test_Clob_FromFile()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

                CreateTestTableLOB(conn);

                string        sql = "insert into t (c) values(?)";
                CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);

                CUBRIDClob Clob = new CUBRIDClob(conn);

                StreamReader r           = new StreamReader("../../../BSD License.txt");
                string       writestring = r.ReadToEnd();
                r.Close();

                Clob.SetString(1, writestring);

                CUBRIDParameter param = new CUBRIDParameter();
                param.ParameterName  = "?";
                param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;
                param.Value          = Clob;
                cmd.Parameters.Add(param);
                cmd.ExecuteNonQuery();
                cmd.Close();

                string sql2 = "SELECT c from t";
                using (CUBRIDCommand cmd2 = new CUBRIDCommand(sql2, conn))
                {
                    DbDataReader reader = cmd2.ExecuteReader();

                    while (reader.Read())
                    {
                        CUBRIDClob cImage = (CUBRIDClob)reader[0];
                        string     str2   = cImage.GetString(1, (int)cImage.ClobLength);

                        StreamWriter w = new StreamWriter("testout.txt");
                        w.Write(str2);
                        w.Close();

                        StreamReader r2         = new StreamReader("testout.txt");
                        string       readstring = r2.ReadToEnd();
                        r2.Close();

                        Debug.Assert(writestring.Length == readstring.Length, "The inserted CLOB length is not valid!");
                        Debug.Assert(writestring.Equals(readstring), "The CLOB was not inserted correctly!");
                    }
                }

                CleanupTestTableLOB(conn);
            }
        }