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


C# CUBRIDConnection.BatchExecute方法代码示例

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


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

示例1: BatchExecute_Test

        public void BatchExecute_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                LogTestStep("Test BatchExecute with serveral non-query sql statements");
                conn.ConnectionString = DBHelper.connString;
                conn.Open();

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

                string[] sql_arr = new string[3];
                sql_arr[0] = "create table t(id integer)";
                sql_arr[1] = "insert into t values(11)";
                sql_arr[2] = "insert into t values(22)";

                CUBRIDBatchResult result = conn.BatchExecute(sql_arr);

                Log("Check the CUBRIDBatchResult returned by BatchExecute()");
                int[] statementType = result.getStatementTypes();
                int[] errorCodes = result.getErrorCodes();
                string[] errorMessage = result.getErrorMessages();
                int[] executeResults = result.getResults();

                Assert.AreEqual(3, result.Count());
                Assert.AreEqual(false, result.getErrorFlag());

                Assert.AreEqual(4, statementType[0]);
                Assert.AreEqual(20, statementType[1]);
                Assert.AreEqual(20, statementType[2]);

                Assert.AreEqual(0, executeResults[0]);
                Assert.AreEqual(1, executeResults[1]);
                Assert.AreEqual(1, executeResults[2]);

                for (int i = 0; i < 3; i++)
                {
                    Assert.AreEqual(0, errorCodes[i]);
                    Assert.AreEqual(null, errorMessage[i]);
                }

                string sql = "select * from t";
                using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        for (int i = 1; i < 3; i++)
                        {
                            reader.Read();
                            Assert.AreEqual(i * 11, reader.GetInt32(0));
                        }
                    }
                }

                LogStepPass();

                LogTestStep("Test BatchExecute with null");
                result = conn.BatchExecute(null);
                Assert.AreEqual(null, result);
                LogStepPass();

                //revert the test db
                DBHelper.ExecuteSQL("drop table t;", conn);
                LogTestResult();
            }
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:65,代码来源:CUBRIDConnectionTest.cs

示例2: Test_BatchExecute

    /// <summary>
    /// Test BatchExecute()
    /// </summary>
    private static void Test_BatchExecute()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

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

        string[] sql_arr = new string[3];
        sql_arr[0] = "insert into t values(1)";
        sql_arr[1] = "insert into t values(2)";
        sql_arr[2] = "insert into t values(3)";
        conn.BatchExecute(sql_arr);

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

        sql = "drop table t;";
        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
        {
          cmd.ExecuteNonQuery();
        }
      }
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:39,代码来源:TestVarious.cs


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