private void FindViews(DataTable schemaTable, string[] filters)
        {
            StringBuilder sql = new StringBuilder();

            StringBuilder where = new StringBuilder();
            const string selectTables = "select class_name from db_class where is_system_class='NO' and class_type='VCLASS'";

            sql.AppendFormat(CultureInfo.InvariantCulture, selectTables);
            if (filters != null)
            {
                string view_name_pattern = filters[0];
                where.AppendFormat(CultureInfo.InvariantCulture, " and class_name LIKE '{0}'", view_name_pattern);
                sql.Append(@where);
            }

            using (CUBRIDCommand cmd = new CUBRIDCommand(sql.ToString(), conn))
            {
                using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        DataRow row = schemaTable.NewRow();

                        row["VIEW_CATALOG"] = conn.Database;
                        row["VIEW_SCHEMA"]  = conn.Database;
                        row["VIEW_NAME"]    = reader.GetString(0);

                        schemaTable.Rows.Add(row);
                    }
                }
            }
        }
        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();

        }
    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");
            }
        }
    }
示例#4
0
    /// <summary>
    /// Test BLOB INSERT
    /// </summary>
    private static void Test_Blob_Insert()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CreateTestTableLOB(conn);

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

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

        Blob.SetBytes(1, bytes);

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

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

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

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

        cmd2.Close();

        CleanupTestTableLOB(conn);
      }
    }
示例#5
0
        private static void Test_apis_514()
        {
            string sql = "select * from nation order by code asc";
            CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);
            CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader(CommandBehavior.CloseConnection);

            Console.WriteLine(reader.IsClosed);
            Console.WriteLine(conn.State);

            reader.Close();

            Console.WriteLine(reader.IsClosed);
            Console.WriteLine(conn.State);
        }
示例#6
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);
      }
    }
示例#7
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);
      }
    }
    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);
      }
    }
        /// <summary>
        ///   Gets the procedures matching the procedure name filter.
        /// </summary>
        /// <param name="filters"> The procedure name filter, value is {"procedure name pattern"}. It should be a string array with Length==1.<para/>
        /// If filters == null or Length == 0, the default filters {"%"} is used. If the Length > 1, the first procedure name is used. <para/></param>
        /// <returns>A <see cref="DataTable" /> that contains procedure schema information and contains <para/>
        /// columns={"PROCEDURE_NAME", "PROCEDURE_TYPE", "RETURN_TYPE", "ARGUMENTS_COUNT", "LANGUAGE", "TARGET", "OWNER"}
        /// </returns>
        public DataTable GetProcedures(string[] filters)
        {
            using (DataTable dt = new DataTable("Procedures"))
            {
                dt.Columns.Add(new DataColumn("PROCEDURE_NAME", typeof(string)));
                dt.Columns.Add(new DataColumn("PROCEDURE_TYPE", typeof(string)));
                dt.Columns.Add(new DataColumn("RETURN_TYPE", typeof(string)));
                dt.Columns.Add(new DataColumn("ARGUMENTS_COUNT", typeof(int)));
                dt.Columns.Add(new DataColumn("LANGUAGE", typeof(string)));
                dt.Columns.Add(new DataColumn("TARGET", typeof(string)));
                dt.Columns.Add(new DataColumn("OWNER", typeof(string)));

                string procedureName = "%";
                if (filters != null && filters.Length > 0 && filters[0] != null)
                {
                    procedureName = filters[0];
                }

                string sql = String.Format("select * from db_stored_procedure where sp_name like '{0}'", procedureName);

                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            DataRow row = dt.NewRow();

                            row["PROCEDURE_NAME"]  = reader.GetString(0);
                            row["PROCEDURE_TYPE"]  = reader.GetString(1);
                            row["RETURN_TYPE"]     = reader.GetString(2);
                            row["ARGUMENTS_COUNT"] = reader.GetInt(3);
                            row["LANGUAGE"]        = reader.GetString(4);
                            row["TARGET"]          = reader.GetString(5);
                            row["OWNER"]           = reader.GetString(6);

                            dt.Rows.Add(row);
                        }
                    }
                }

                return(dt);
            }
        }
示例#10
0
        private static void Test_Sequence_Default()
        {
            ExecuteSQL("DROP TABLE IF EXISTS t", conn);

            //Create a new table with a collection
            ExecuteSQL("CREATE TABLE t(s SET(string))", conn);
            //Insert some data in the sequence column
            string[] sArray = new string[8]{"P", 
                                    "Types of fragmentation", 
                                    "File fragmentation",
                                    "Free space fragmentation",
                                    "File scattering", 
                                    "File system fragmentation", 
                                    "Preventing fragmentation",null};
            string sql = "INSERT INTO t(s) VALUES( ?);";
            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                CUBRIDParameter param = new CUBRIDParameter();
                param.ParameterName = "?p";
                param.Value = sArray;
                param.InnerCUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_LAST + 1;
                cmd.Parameters.Add(param);
                cmd.Parameters[0].CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_SET;
                cmd.ExecuteNonQuery();
            }

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

                    object objValue = reader.GetValue(0);
                    Array oArray = objValue as Array;
                    if (oArray != null)
                        Console.WriteLine(oArray.Length);
                    cmd.ColumnInfos[0].ToString();
                }
            }
        }
示例#11
0
    /// <summary>
    /// Test CUBRIDCommand ExecuteNonQuery() method
    /// </summary>
    private static void Test_ExecuteNonQuery()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CreateTestTable(conn);

        string sql = "insert into t values(1, 'a', 'abc', 1.2, 2.1, '10/31/2008')";
        CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);
        cmd.ExecuteNonQuery();
        cmd.Close();
      }

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

        string sql = "select * from t";
        CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);
        DbDataReader reader = cmd.ExecuteReader();

        while (reader.Read()) //only one row will be available
        {
          Debug.Assert(reader.GetInt32(0) == 1);
          Debug.Assert(reader.GetString(1) == "a         ");
          Debug.Assert(reader.GetString(2) == "abc");
          Debug.Assert(reader.GetFloat(3) == 1.2f);
          Debug.Assert(reader.GetFloat(4) == (float)Convert.ToDouble(2.1));
          Debug.Assert(reader.GetDateTime(5) == new DateTime(2008, 10, 31));
        }

        cmd.Close();

        CleanupTestTable(conn);
      }
    }
示例#12
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();
        }
示例#13
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));
                };
            }
        } 
示例#14
0
    /// <summary>
    /// Test Enum data type
    /// </summary>
    public static void Test_DataType_Enum()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

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

        /* create new table */
        string sql = "create table table11(city enum('BeiJing', 'ChengDu', 'QingDao', 'DaLian'), nationality enum('China', 'Korea', 'Japan'));";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          cmd.ExecuteNonQuery();
        }

        /* insert multi rows values */
        sql = "insert into table11 (city, nationality) values ('BeiJing', 'Japan'),('ChengDu','China'),('QingDao', 'Korea');";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          cmd.ExecuteNonQuery();
        }

        /* verify count */
        sql = "select count(*) from table11";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            reader.Read();
            Debug.Assert(reader.GetInt32(0) == 3);
          }
        }

        sql = "select * from table11";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            reader.Read();
            Debug.Assert(reader.GetString(0) == "BeiJing");
          }
        }

        try
        {
          /* 
           Only thrown exception is the correct result
           */
          sql = "insert into table11 (city, nationality) values ('Peking', 'China');";
          using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
          {
            cmd.ExecuteNonQuery();
          }
        }
        catch (Exception exp)
        {
          Debug.Assert(exp.Message == "Semantic: before ' , 'China');'\nCannot coerce 'Peking' to type enum. insert into table11 table11 (table11.city, table11.nationali...");
        }

        TestCases.ExecuteSQL("drop table11;", conn);
      }
    }
示例#15
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);
      }
    }
示例#16
0
    /// <summary>
    /// Test SEQUENCE operations
    /// </summary>
    private static void Test_SequenceOperations()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        TestCases.ExecuteSQL("DROP TABLE IF EXISTS t", conn);

        //Create a new table with a sequence

        TestCases.ExecuteSQL("CREATE TABLE t(seq SEQUENCE(int))", conn);
        //Insert some data in the sequence column
        TestCases.ExecuteSQL("INSERT INTO t(seq) VALUES({0,1,2,3,4,5,6})", conn);
        CUBRIDOid oid = new CUBRIDOid("@0|0|0");
        using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT t FROM t", conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            while (reader.Read())
            {
              oid = (CUBRIDOid)reader[0];
            }
          }
        }

        String attributeName = "seq";
        int value = 7;

        int SeqSize = conn.GetCollectionSize(oid, attributeName);
        Debug.Assert(SeqSize == 7);

        conn.UpdateElementInSequence(oid, attributeName, 1, value);
        SeqSize = conn.GetCollectionSize(oid, attributeName);
        Debug.Assert(SeqSize == 7);

        using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            while (reader.Read())
            {
              int[] expected = { 7, 1, 2, 3, 4, 5, 6 };
              object[] o = (object[])reader[0];
              for (int i = 0; i < SeqSize; i++)
              {
                Debug.Assert(Convert.ToInt32(o[i]) == expected[i]);
              }
            }
          }
        }

        conn.InsertElementInSequence(oid, attributeName, 5, value);
        SeqSize = conn.GetCollectionSize(oid, attributeName);
        Debug.Assert(SeqSize == 8);

        using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            while (reader.Read())
            {
              int[] expected = { 7, 1, 2, 3, 7, 4, 5, 6 };
              object[] o = (object[])reader[0];
              for (int i = 0; i < SeqSize; i++)
              {
                Debug.Assert(Convert.ToInt32(o[i]) == expected[i]);
              }
            }
          }
        }

        conn.DropElementInSequence(oid, attributeName, 5);
        SeqSize = conn.GetCollectionSize(oid, attributeName);
        Debug.Assert(SeqSize == 7);

        using (CUBRIDCommand cmd = new CUBRIDCommand("SELECT * FROM t", conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            while (reader.Read())
            {
              int[] expected = { 7, 1, 2, 3, 4, 5, 6 };
              object[] o = (object[])reader[0];
              for (int i = 0; i < SeqSize; i++)
              {
                Debug.Assert(Convert.ToInt32(o[i]) == expected[i]);
              }
            }
          }
        }

        TestCases.ExecuteSQL("DROP t", conn);
      }
    }
示例#17
0
    /// <summary>
    /// Test CUBRID data types Get...()
    /// </summary>
    private static void Test_Various_DataTypes()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

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

        string sql = "create table t(";
        sql += "c_integer_ai integer AUTO_INCREMENT, ";
        sql += "c_smallint smallint, ";
        sql += "c_integer integer, ";
        sql += "c_bigint bigint, ";
        sql += "c_numeric numeric(15,1), ";
        sql += "c_float float, ";
        sql += "c_decimal decimal(15,3), ";
        sql += "c_double double, ";
        sql += "c_char char(1), ";
        sql += "c_varchar character varying(4096), ";
        sql += "c_time time, ";
        sql += "c_date date, ";
        sql += "c_timestamp timestamp, ";
        sql += "c_datetime datetime, ";
        sql += "c_bit bit(1), ";
        sql += "c_varbit bit varying(4096), ";
        sql += "c_monetary monetary, ";
        sql += "c_string string";
        sql += ")";
        TestCases.ExecuteSQL(sql, conn);

        sql = "insert into t values(";
        sql += "1, ";
        sql += "11, ";
        sql += "111, ";
        sql += "1111, ";
        sql += "1.1, ";
        sql += "1.11, ";
        sql += "1.111, ";
        sql += "1.1111, ";
        sql += "'a', ";
        sql += "'abcdfghijk', ";
        sql += "TIME '13:15:45 pm', ";
        sql += "DATE '00-10-31', ";
        sql += "TIMESTAMP '13:15:45 10/31/2008', ";
        sql += "DATETIME '13:15:45 10/31/2008', ";
        sql += "B'0', ";
        sql += "B'0', ";
        sql += "123456789, ";
        sql += "'qwerty'";
        sql += ")";
        TestCases.ExecuteSQL(sql, conn);

        sql = "select * from t";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          DbDataReader reader = cmd.ExecuteReader();
          while (reader.Read()) //only one row will be available
          {
            Debug.Assert(reader.GetInt32(0) == 1);
            Debug.Assert(reader.GetInt16(1) == 11);
            Debug.Assert(reader.GetInt32(2) == 111);
            Debug.Assert(reader.GetInt64(3) == 1111);
            Debug.Assert(reader.GetDecimal(4) == (decimal)1.1);
            Debug.Assert(reader.GetFloat(5) == (float)1.11);
            Debug.Assert(reader.GetDecimal(6) == (decimal)1.111);
            Debug.Assert(reader.GetDouble(7) == (double)1.1111);
            Debug.Assert(reader.GetChar(8) == 'a');
            Debug.Assert(reader.GetString(9) == "abcdfghijk");
            Debug.Assert(reader.GetDateTime(10).Second == 45);
            Debug.Assert(reader.GetDateTime(11) == new DateTime(2000, 10, 31));
            Debug.Assert(reader.GetDateTime(12) == new DateTime(2008, 10, 31, 13, 15, 45));
            Debug.Assert(reader.GetDateTime(13) == new DateTime(2008, 10, 31, 13, 15, 45));
            Debug.Assert(reader.GetByte(14) == (byte)0);
            Debug.Assert(reader.GetByte(15) == (byte)0);
            Debug.Assert(reader.GetString(16) == "123456789");
            Debug.Assert(reader.GetString(17) == "qwerty");
          }
        }

        TestCases.ExecuteSQL("drop table t", conn);
      }
    }
示例#18
0
    /// <summary>
    /// Test CUBRID data types, using parameters
    /// </summary>
    private static void Test_Various_DataTypes_Parameters()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

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

        string sql = "create table t(";
        sql += "c_integer_ai integer AUTO_INCREMENT, ";
        sql += "c_smallint smallint, ";
        sql += "c_integer integer, ";
        sql += "c_bigint bigint, ";
        sql += "c_numeric numeric(15,1), ";
        sql += "c_float float, ";
        sql += "c_decimal decimal(15,3), ";
        sql += "c_double double, ";
        sql += "c_char char(1), ";
        sql += "c_varchar character varying(4096), ";
        sql += "c_time time, ";
        sql += "c_date date, ";
        sql += "c_timestamp timestamp, ";
        sql += "c_datetime datetime, ";
        sql += "c_bit bit(8), ";
        sql += "c_varbit bit varying(4096), ";
        sql += "c_monetary monetary, ";
        sql += "c_string string, ";
        sql += "c_null string ";
        sql += ")";
        TestCases.ExecuteSQL(sql, conn);

        sql = "insert into t values(";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "?, ";
        sql += "? ";
        sql += ")";

        CUBRIDCommand cmd_i = new CUBRIDCommand(sql, conn);

        //sql += "c_integer_ai integer AUTO_INCREMENT, ";
        //sql += "1, ";
        CUBRIDParameter p1 = new CUBRIDParameter("?p1", CUBRIDDataType.CCI_U_TYPE_INT);
        p1.Value = 1;
        cmd_i.Parameters.Add(p1);
        //sql += "c_smallint smallint, ";
        //sql += "11, ";
        CUBRIDParameter p2 = new CUBRIDParameter("?p2", CUBRIDDataType.CCI_U_TYPE_SHORT);
        p2.Value = 11;
        cmd_i.Parameters.Add(p2);
        //sql += "c_integer integer, ";
        //sql += "111, ";
        CUBRIDParameter p3 = new CUBRIDParameter("?p3", CUBRIDDataType.CCI_U_TYPE_INT);
        p3.Value = 111;
        cmd_i.Parameters.Add(p3);
        //sql += "c_bigint bigint, ";
        //sql += "1111, ";
        CUBRIDParameter p4 = new CUBRIDParameter("?p4", CUBRIDDataType.CCI_U_TYPE_BIGINT);
        p4.Value = 1111;
        cmd_i.Parameters.Add(p4);
        //sql += "c_numeric numeric(15,0), ";
        //sql += "1.1, ";
        CUBRIDParameter p5 = new CUBRIDParameter("?p5", CUBRIDDataType.CCI_U_TYPE_NUMERIC);
        p5.Value = 1.1;
        cmd_i.Parameters.Add(p5);
        //sql += "c_float float, ";
        //sql += "1.11, ";
        CUBRIDParameter p6 = new CUBRIDParameter("?p6", CUBRIDDataType.CCI_U_TYPE_FLOAT);
        p6.Value = 1.11;
        cmd_i.Parameters.Add(p6);
        //sql += "c_decimal decimal, ";
        //sql += "1.111, ";
        CUBRIDParameter p7 = new CUBRIDParameter("?p7", CUBRIDDataType.CCI_U_TYPE_NUMERIC);
        p7.Value = 1.111;
        cmd_i.Parameters.Add(p7);
        //sql += "c_double double, ";
        //sql += "1.1111, ";
        CUBRIDParameter p8 = new CUBRIDParameter("?p8", CUBRIDDataType.CCI_U_TYPE_DOUBLE);
        p8.Value = 1.1111;
        cmd_i.Parameters.Add(p8);
        //sql += "c_char char(1), ";
        //sql += "'a', ";
        CUBRIDParameter p9 = new CUBRIDParameter("?p9", CUBRIDDataType.CCI_U_TYPE_CHAR);
        p9.Size = 1;
        p9.Value = 'a';
        cmd_i.Parameters.Add(p9);
        //sql += "c_varchar varchar(4096), ";
        //sql += "'abcdfghijk', ";
        CUBRIDParameter p10 = new CUBRIDParameter("?p10", CUBRIDDataType.CCI_U_TYPE_STRING);
        p10.Value = "abcdfghijk";//trebuie luat cap coada si vazut dc plm nu se trimite ok. S-ar putea sa fie de la n
        cmd_i.Parameters.Add(p10);
        //sql += "c_time time, ";
        //sql += "TIME '13:15:45 pm', ";
        CUBRIDParameter p11 = new CUBRIDParameter("?p11", CUBRIDDataType.CCI_U_TYPE_TIME);
        p11.Value = new DateTime(2010, 1, 1, 13, 15, 45); //year/month/date is not relevant, only the time part is used
        cmd_i.Parameters.Add(p11);
        //sql += "c_date date, ";
        //sql += "DATE '00-10-31', ";
        CUBRIDParameter p12 = new CUBRIDParameter("?p12", CUBRIDDataType.CCI_U_TYPE_DATE);
        p12.Value = new DateTime(2000, 10, 31);
        cmd_i.Parameters.Add(p12);
        //sql += "c_timestamp timestamp, ";
        //sql += "TIMESTAMP '13:15:45 10/31/2008', ";
        CUBRIDParameter p13 = new CUBRIDParameter("?p13", CUBRIDDataType.CCI_U_TYPE_TIMESTAMP);
        p13.Value = new DateTime(2008, 10, 31, 13, 15, 45);
        cmd_i.Parameters.Add(p13);
        //sql += "c_datetime datetime, ";
        //sql += "DATETIME '13:15:45 10/31/2008', ";
        CUBRIDParameter p14 = new CUBRIDParameter("?p14", CUBRIDDataType.CCI_U_TYPE_DATETIME);
        p14.Value = new DateTime(2008, 10, 31, 13, 15, 45);
        cmd_i.Parameters.Add(p14);
        //sql += "c_bit bit(1), ";
        //sql += "B'1', ";
        CUBRIDParameter p15 = new CUBRIDParameter("?p15", CUBRIDDataType.CCI_U_TYPE_BIT);
        p15.Value = (byte)1;
        cmd_i.Parameters.Add(p15);
        //sql += "c_varbit bit varying(4096), ";
        //sql += "B'1', ";
        CUBRIDParameter p16 = new CUBRIDParameter("?p16", CUBRIDDataType.CCI_U_TYPE_VARBIT);
        p16.Value = (byte)1;
        cmd_i.Parameters.Add(p16);
        //sql += "c_monetary monetary, ";
        //sql += "123456789, ";
        CUBRIDParameter p17 = new CUBRIDParameter("?p17", CUBRIDDataType.CCI_U_TYPE_MONETARY);
        p17.Value = 123456789;
        cmd_i.Parameters.Add(p17);
        //sql += "c_string string ";
        //sql += "'qwerty'";
        CUBRIDParameter p18 = new CUBRIDParameter("?p18", CUBRIDDataType.CCI_U_TYPE_STRING);
        p18.Value = "qwerty";
        cmd_i.Parameters.Add(p18);
        //sql += "c_null string ";
        //sql += "null";
        CUBRIDParameter p19 = new CUBRIDParameter("?p19", CUBRIDDataType.CCI_U_TYPE_NULL);
        p19.Value = null;
        cmd_i.Parameters.Add(p19);

        cmd_i.ExecuteNonQuery();

        cmd_i.Close();

        sql = "select * from t ";
        sql += "where 1 = 1 ";
        sql += "and c_integer_ai = ? ";
        sql += "and c_smallint = ? ";
        sql += "and c_integer = ? ";
        sql += "and c_bigint = ? ";
        sql += "and c_numeric = ? ";
        sql += "and c_float = ? ";
        sql += "and c_decimal = ? ";
        sql += "and c_double = ? ";
        sql += "and c_char = ? ";
        sql += "and c_varchar = ? ";
        sql += "and c_time = ? ";
        sql += "and c_date = ? ";
        sql += "and c_timestamp = ? ";
        sql += "and c_datetime = ? ";
        sql += "and c_bit = ? ";
        sql += "and c_varbit = ? ";
        sql += "and c_monetary = ? ";
        sql += "and c_string = ? ";
        sql += "and c_null IS NULL ";

        CUBRIDCommand cmd_s = new CUBRIDCommand(sql, conn);
        cmd_s.Parameters.Add(p1);
        cmd_s.Parameters.Add(p2);
        cmd_s.Parameters.Add(p3);
        cmd_s.Parameters.Add(p4);
        cmd_s.Parameters.Add(p5);
        cmd_s.Parameters.Add(p6);
        cmd_s.Parameters.Add(p7);
        cmd_s.Parameters.Add(p8);
        cmd_s.Parameters.Add(p9);
        cmd_s.Parameters.Add(p10);
        cmd_s.Parameters.Add(p11);
        cmd_s.Parameters.Add(p12);
        cmd_s.Parameters.Add(p13);
        cmd_s.Parameters.Add(p14);
        cmd_s.Parameters.Add(p15);
        cmd_s.Parameters.Add(p16);
        cmd_s.Parameters.Add(p17);
        cmd_s.Parameters.Add(p18);
        //cmd_s.Parameters.Add(p19);

        DbDataReader reader = cmd_s.ExecuteReader();
        while (reader.Read()) //only one row will be available
        {
          Debug.Assert(reader.GetInt32(0) == 1);
          Debug.Assert(reader.GetInt16(1) == 11);
          Debug.Assert(reader.GetInt32(2) == 111);
          Debug.Assert(reader.GetInt64(3) == 1111);
          Debug.Assert(reader.GetDecimal(4) == (decimal)1.1);
          Debug.Assert(reader.GetFloat(5) == (float)1.11);
          Debug.Assert(reader.GetDouble(6) == 1.111);
          Debug.Assert(reader.GetDouble(7) == 1.1111);
          Debug.Assert(reader.GetChar(8) == 'a');
          Debug.Assert(reader.GetString(9) == "abcdfghijk");
          Debug.Assert(reader.GetDateTime(10) == new DateTime(1, 1, 1, 13, 15, 45));
          Debug.Assert(reader.GetDateTime(11) == new DateTime(2000, 10, 31));
          Debug.Assert(reader.GetDateTime(12) == new DateTime(2008, 10, 31, 13, 15, 45));
          Debug.Assert(reader.GetDateTime(13) == new DateTime(2008, 10, 31, 13, 15, 45, 00));
          Debug.Assert(reader.GetByte(14) == 1);
          Debug.Assert(reader.GetByte(15) == 1);
          Debug.Assert(reader.GetString(16) == "123456789");
          Debug.Assert(reader.GetString(17) == "qwerty");
          Debug.Assert(reader.GetValue(18) == null);
        }

        cmd_s.Close();

        TestCases.ExecuteSQL("drop table t", conn);
      }
    }
示例#19
0
    /// <summary>
    /// Test BLOB DELETE in a transaction
    /// </summary>
    private static void Test_Blob_DeleteTransaction()
    {
      DbTransaction tran = null;
      byte[] bytes1 = new byte[256];

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

        CreateTestTableLOB(conn);

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

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

          tran = conn.BeginTransaction(IsolationLevel.ReadUncommitted);
          string sql2 = "DELETE from t";
          CUBRIDCommand cmd2 = new CUBRIDCommand(sql2, conn);
          cmd2.ExecuteNonQuery();
        }

        tran.Rollback();
      }

      //We have to close and reopen connection. Otherwise we get an invalid buffer position.
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        string sql = "SELECT b from t";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          DbDataReader reader = cmd.ExecuteReader();
          while (reader.Read())
          {
            Debug.Assert(reader.HasRows == true);

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

            bool ok = true;
            for (int i = 0; i < bytes.Length; i++)
            {
              if (bytes1[i] != bytes[i])
                ok = false;
            }

            Debug.Assert(ok == true, "The BLOB DELETE command was not rolled-back correctly!");
          }
        }

        CleanupTestTableLOB(conn);
      }
    }
示例#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();
        }
示例#21
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);
      }
    }
示例#22
0
    /// <summary>
    /// Test BLOB INSERT in a transaction
    /// </summary>
    private static void Test_Blob_InsertTransaction()
    {
      DbTransaction tran = null;
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        CreateTestTableLOB(conn);

        tran = conn.BeginTransaction(IsolationLevel.ReadUncommitted);
        string sql = "insert into t (b) values(?)";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          CUBRIDBlob Blob = new CUBRIDBlob(conn);

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

          Blob.SetBytes(1, bytes);

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

        tran.Rollback();
      }

      //We have to close and reopen connection. Otherwise we get an invalid buffer position.
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();
        string sql2 = "SELECT b from t";
        using (CUBRIDCommand cmd2 = new CUBRIDCommand(sql2, conn))
        {
          DbDataReader reader = cmd2.ExecuteReader();
          Debug.Assert(reader.HasRows == false, "Transaction did not rollback!");
        }

        CleanupTestTableLOB(conn);
      }
    }
        private void LoadTableColumns(DataTable dt, string tableName, string columnRestriction)
        {
            string sql =
                String.Format(
                    "select * from db_attribute where class_name like '{0}' and attr_name like '{1}' order by def_order asc",
                    tableName, columnRestriction);

            using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
            {
                int pos = 1;
                using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string  colName = reader.GetString(0);
                        DataRow row     = dt.NewRow();

                        row["TABLE_CATALOG"]    = conn.Database;
                        row["TABLE_SCHEMA"]     = conn.Database;
                        row["TABLE_NAME"]       = tableName;
                        row["COLUMN_NAME"]      = colName;
                        row["ORDINAL_POSITION"] = pos++;

                        for (int i = 0; i < reader.GetColumnCount(); i++)
                        {
                            switch (reader.GetColumnName(i))
                            {
                            case "defalut_value":
                                row["COLUMN_DEFAULT"] = reader.GetString(i);
                                break;

                            case "is_nullable":
                                row["IS_NULLABLE"] = reader.GetString(i).Equals("YES");
                                break;

                            case "data_type":
                                row["DATA_TYPE"] = reader.GetString(i);
                                break;

                            case "prec":
                                row["NUMERIC_PRECISION"] = reader.GetInt(i);
                                break;

                            case "scale":
                                row["NUMERIC_SCALE"] = reader.GetInt(i);
                                break;

                            case "code_set":
                            case "charset":
                                row["CHARACTER_SET"] = reader.GetString(i);
                                break;

                            default:
                                break;
                            }
                        }

                        dt.Rows.Add(row);
                    }
                }
            }
        }
示例#24
0
    /// <summary>
    /// Test SQL statements execution, using DataReader
    /// </summary>
    private static void Test_DataReader_Basic()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

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

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

            Debug.Assert(reader.FieldCount == 4);
            Debug.Assert(reader.GetString(0) == "AFG");
            Debug.Assert(reader.GetString(1) == "Afghanistan");
            Debug.Assert(reader.GetString(2) == "Asia");
            Debug.Assert(reader.GetString(3) == "Kabul");
          }
        }
      }
    }
示例#25
0
    /// <summary>
    /// Test CUBRIDDataReader getter methods
    /// </summary>
    private static void Test_DataReader_Getxxx()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        string sql = "select * from nation;";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          using (CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader())
          {
            reader.Read();

            Debug.Assert(reader.GetOrdinal("code") == 0);
            Debug.Assert(reader.GetName(0) == "code");
            Debug.Assert(reader.GetColumnName(0) == "code");
            Debug.Assert(reader.GetColumnType(0) == typeof(System.String));
            Debug.Assert(reader.GetDataTypeName(0) == "CHAR");
          }
        }
      }
    }
示例#26
0
    /// <summary>
    /// Test Encodings support with parameters
    /// </summary>
    private static void Test_EncodingsWithParameters()
    {
      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))
        {
          CUBRIDParameter param = new CUBRIDParameter();
          param.ParameterName = "?";
          param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_STRING;
          param.Value = "¾Æ¹«°³";

          cmd.Parameters.Add(param);
          cmd.ExecuteNonQuery();
        }

        sql = "select * from t where b = ?";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          CUBRIDParameter param = new CUBRIDParameter();
          param.ParameterName = "?";
          param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_STRING;
          param.Value = "¾Æ¹«°³";

          cmd.Parameters.Add(param);
          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))
        {
          CUBRIDParameter param = new CUBRIDParameter();
          param.ParameterName = "?";
          param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_STRING;
          param.Value = "¾Æ¹°³";

          cmd.Parameters.Add(param);
          cmd.ExecuteNonQuery();
        }

        sql = "select * from t where b = ?";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          CUBRIDParameter param = new CUBRIDParameter();
          param.ParameterName = "?";
          param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_STRING;
          param.Value = "¾Æ¹°³";

          cmd.Parameters.Add(param);
          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);
      }
    }
示例#27
0
    /// <summary>
    /// Test the CUBRIDDataType.CCI_U_TYPE_NULL data type
    /// </summary>
    private static void Test_Null_WithParameters()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        using (CUBRIDCommand cmd = new CUBRIDCommand("drop table if exists t", conn))
        {
          cmd.ExecuteNonQuery();
        }

        using (CUBRIDCommand cmd = new CUBRIDCommand("create table t(id int, str string)", conn))
        {
          cmd.ExecuteNonQuery();
        }

        using (CUBRIDCommand cmd = new CUBRIDCommand("insert into t values(?, ?)", 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_NULL);
          p2.Value = null;
          cmd.Parameters.Add(p2);

          cmd.ExecuteNonQuery();
        }

        using (CUBRIDCommand cmd = new CUBRIDCommand("select * from t where id = 1", conn))
        {
          using (DbDataReader reader = cmd.ExecuteReader())
          {
            reader.Read();
            Debug.Assert(reader.GetValue(1) == null);
          }
        }

        using (CUBRIDCommand cmd = new CUBRIDCommand("drop table t", conn))
        {
          cmd.ExecuteNonQuery();
        }
      }
    }
示例#28
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();
      }
    }
示例#29
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();
        }
示例#30
0
    /// <summary>
    /// Test read many rows in one SQL statement execution
    /// </summary>
    private static void Test_Read_ManyRows()
    {
      int curr_row = 0;

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

        string sql = "select * from athlete";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {

          DbDataReader reader = cmd.ExecuteReader();
          while (reader.Read())
          {
            curr_row++;
          }
          cmd.Close();
        }
      }

      Debug.Assert(curr_row == 6677);
    }
示例#31
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);
      }
    }
示例#32
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;
    }
示例#33
0
    /// <summary>
    /// Test BLOB INSERT, using a jpg image input file
    /// </summary>
    private static void Test_Blob_FromFile()
    {
      BinaryReader b;

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

        CreateTestTableLOB(conn);

        string sql = "insert into t (b) values(?)";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          CUBRIDBlob Blob = new CUBRIDBlob(conn);
          byte[] bytes;
          b = new BinaryReader(File.Open("../../../CUBRID.ico", FileMode.Open));
          int length = (int)b.BaseStream.Length;
          bytes = b.ReadBytes(length);

          Blob.SetBytes(1, bytes);
          CUBRIDParameter param = new CUBRIDParameter();
          param.ParameterName = "?";
          param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_BLOB;
          param.Value = Blob;
          cmd.Parameters.Add(param);
          cmd.Parameters[0].DbType = DbType.Binary;
          cmd.ExecuteNonQuery();
        }

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

            FileStream stream = new FileStream("1out.jpg", FileMode.Create);
            BinaryWriter writer = new BinaryWriter(stream);
            writer.Write(bytes2);
            writer.Close();

            BinaryReader b2 = new BinaryReader(File.Open("1out.jpg", FileMode.Open));
            Debug.Assert(b2.BaseStream.Length == b.BaseStream.Length, "The inserted BLOB length is not valid!");
            bool ok = true;
            int file1byte, file2byte;
            b.BaseStream.Position = 0;

            do
            {
              file1byte = b.BaseStream.ReadByte();
              file2byte = b2.BaseStream.ReadByte();
              if (file1byte != file2byte)
                ok = false;
            }
            while (file1byte != -1);

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

            b.Close();
            b2.Close();
          }
        }

        CleanupTestTableLOB(conn);
      }
    }