当前位置: 首页>>代码示例>>C#>>正文


C# CUBRIDClient.CUBRIDConnection类代码示例

本文整理汇总了C#中CUBRID.Data.CUBRIDClient.CUBRIDConnection的典型用法代码示例。如果您正苦于以下问题:C# CUBRIDConnection类的具体用法?C# CUBRIDConnection怎么用?C# CUBRIDConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CUBRIDConnection类属于CUBRID.Data.CUBRIDClient命名空间,在下文中一共展示了CUBRIDConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_GetForeignKeys

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

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

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

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

        Debug.Assert(dt.Rows[1][0].ToString() == "athlete");
        Debug.Assert(dt.Rows[1][1].ToString() == "code");
        Debug.Assert(dt.Rows[1][2].ToString() == "game");
        Debug.Assert(dt.Rows[1][3].ToString() == "athlete_code");
        Debug.Assert(dt.Rows[1][4].ToString() == "1");
        Debug.Assert(dt.Rows[1][5].ToString() == "1");
        Debug.Assert(dt.Rows[1][6].ToString() == "1");
        Debug.Assert(dt.Rows[1][7].ToString() == "fk_game_athlete_code");
        Debug.Assert(dt.Rows[1][8].ToString() == "pk_athlete_code");
      }
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:37,代码来源:TestSchema.cs

示例2: Test_Encoding

    private static void Test_Encoding()
    {
        CUBRIDConnection conn = new CUBRIDConnection();

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

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

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

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

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

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

        conn.SetEncoding("xxxx");
        Debug.Assert(Encoding.Default == conn.GetEncoding());
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:25,代码来源:TestCUBRIDConnection.cs

示例3: conn_setIsolationLevel

        public void conn_setIsolationLevel()
        {
            string conn_string = "server=test-db-server;database=demodb;port=33000;user=dba;password=";
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.ConnectionString = conn_string;
            conn.Open();

            CUBRIDCommand cmd = new CUBRIDCommand();
            cmd.Connection = conn;
            cmd.CommandText = "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();
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:31,代码来源:BTSIssue.cs

示例4: ExecuteSQL

        //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();
            }
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:15,代码来源:DBHelper.cs

示例5: CUBRIDDataAdapter_ConstructorWithCUBRIDCommand_Test

        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);
                }
            }
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:35,代码来源:CUBRIDDataAdapterTest.cs

示例6: Test_DataSet_Basic

    /// <summary>
    /// Test basic SQL statements execution, using DataSet
    /// </summary>
    private static void Test_DataSet_Basic()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

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

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

        dt0 = ds.Tables[0];

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

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

        Debug.Assert(dataRow.Length == 54);
      }
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:33,代码来源:TestDataSet.cs

示例7: GetOwners

        public IList<string> GetOwners()
        {
            var owners = new List<string>();
            var conn = new CUBRIDConnection(connectionStr);
            conn.Open();

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

            return owners;
        }
开发者ID:HongJunRen,项目名称:NMG,代码行数:25,代码来源:CUBRIDMetadataReader.cs

示例8: Test_DataSet_ExportXML

    /// <summary>
    /// Test exporting XML from DataSet
    /// </summary>
    private static void Test_DataSet_ExportXML()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

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

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

        if (!System.IO.File.Exists(filename))
        {
          throw new Exception("XML output file not found!");
        }
        else
        {
          System.IO.File.Delete(filename);
        }
      }
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:29,代码来源:TestDataSet.cs

示例9: DataReader_Basic_Test

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

        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:30,代码来源:CUBRIDDataReaderTest.cs

示例10: Test_CreateFunction

    /// <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);
      }
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:30,代码来源:TestVarious.cs

示例11: CUBRIDTransaction

    /// <summary>
    ///   Initializes a new instance of the <see cref="CUBRIDTransaction" /> class.
    /// </summary>
    /// <param name="conn"> The connection. </param>
    /// <param name="isolationLevel"> The isolation level. </param>
    public CUBRIDTransaction(CUBRIDConnection conn, CUBRIDIsolationLevel isolationLevel)
    {
      if (isolationLevel == CUBRIDIsolationLevel.TRAN_UNKNOWN_ISOLATION)
        throw new ArgumentException(Utils.GetStr(MsgId.UnknownIsolationLevelNotSupported));

      this.conn = conn;
      conn.IsolationLevel = isolationLevel;
      conn.SetIsolationLevel(isolationLevel);
      open = true;
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:15,代码来源:CUBRIDTransaction.cs

示例12: Test_Blob_Select

    ///<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);
      }
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:58,代码来源:TestLOB.cs

示例13: conn_Database

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

            conn.Close();
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:11,代码来源:BTSIssue.cs

示例14: GetSingleValue

        public static object GetSingleValue(string sql, CUBRIDConnection conn)
        {
            object ret = null;

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

            return ret;
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:11,代码来源:DBHelper.cs

示例15: GetTablesCount

        public static int GetTablesCount(string tableName, CUBRIDConnection conn)
        {
            int count = 0;
            string sql = "select count(*) from db_class where class_name = '" + tableName + "'";

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

            return count;
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:12,代码来源:DBHelper.cs


注:本文中的CUBRID.Data.CUBRIDClient.CUBRIDConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。