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


C# MySqlCommand.Cancel方法代码示例

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


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

示例1: CancelSelect

        public void CancelSelect()
        {
            if (version < new Version(5, 0)) return;

            execSQL("CREATE TABLE Test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20))");
            for (int i=0; i < 10000; i++)
                execSQL("INSERT INTO Test VALUES (NULL, 'my string')");

            MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
            cmd.CommandTimeout = 0;
            int rows = 0;
            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                reader.Read();

                cmd.Cancel();

                try
                {
                    while (reader.Read())
                    {
                        rows++;
                    }
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.Message);
                }
            }
            Assert.IsTrue(rows < 10000);
        }
开发者ID:rykr,项目名称:connector-net,代码行数:31,代码来源:TimeoutAndCancel.cs

示例2: CancelSingleQuery

    public void CancelSingleQuery()
    {
      if (st.Version < new Version(5, 0)) return;

      // first we need a routine that will run for a bit
      st.execSQL(@"CREATE PROCEDURE spTest(duration INT) 
        BEGIN 
          SELECT SLEEP(duration);
        END");

      MySqlCommand cmd = new MySqlCommand("spTest", st.conn);
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Parameters.AddWithValue("duration", 10);

      // now we start execution of the command
      CommandInvokerDelegate d = new CommandInvokerDelegate(CommandRunner);
      d.BeginInvoke(cmd, null, null);

      // sleep 1 seconds
      Thread.Sleep(1000);

      // now cancel the command
      cmd.Cancel();

      resetEvent.WaitOne();
    }
开发者ID:Nicholi,项目名称:mysql-connector-net,代码行数:26,代码来源:TimeoutAndCancel.cs

示例3: CancelSelect

        public void CancelSelect()
        {
            if (Version < new Version(5, 0)) return;

              execSQL("CREATE TABLE Test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20))");
              for (int i = 0; i < 1000; i++)
            execSQL("INSERT INTO Test VALUES (NULL, 'my string')");

              MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
              cmd.CommandTimeout = 0;
              int rows = 0;
              using (MySqlDataReader reader = cmd.ExecuteReader())
              {
            reader.Read();

            cmd.Cancel();

            while (true)
            {

              try
              {
            if (!reader.Read())
              break;
            rows++;
              }
              catch (MySqlException ex)
              {
            Assert.IsTrue(ex.Number == (int)MySqlErrorCode.QueryInterrupted);
            if (rows < 1000)
            {
              bool readOK = reader.Read();
              Assert.IsFalse(readOK);
            }
              }

            }
              }
              Assert.IsTrue(rows < 1000);
        }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:40,代码来源:TimeoutAndCancel.cs

示例4: ExecuteReaderReturnsReaderAfterCancel

    public void ExecuteReaderReturnsReaderAfterCancel()
    {
      st.execSQL("DROP TABLE IF EXISTS TableWithDateAsPrimaryKey");
      st.execSQL("DROP TABLE IF EXISTS TableWithStringAsPrimaryKey");
      st.createTable("CREATE TABLE TableWithDateAsPrimaryKey(PrimaryKey date NOT NULL, PRIMARY KEY  (PrimaryKey))", "InnoDB");
      st.createTable("CREATE TABLE TableWithStringAsPrimaryKey(PrimaryKey nvarchar(50) NOT NULL, PRIMARY KEY  (PrimaryKey))", "InnoDB");

      string connStr = st.GetConnectionString(true);
      using (MySqlConnection connection = new MySqlConnection(connStr))
      {
        connection.Open();
        MySqlCommand command = new MySqlCommand("SELECT PrimaryKey FROM TableWithDateAsPrimaryKey", connection);
#if RT
        MySqlDataReader reader = command.ExecuteReader(CommandBehavior.KeyInfo);
        while (reader.Read()) ;
#else
        IDataReader reader = command.ExecuteReader(CommandBehavior.KeyInfo);
        DataTable dataTableSchema = reader.GetSchemaTable();
#endif
        command.Cancel();
        reader.Close();

        command = new MySqlCommand("SELECT PrimaryKey FROM TableWithStringAsPrimaryKey", connection);
        reader = command.ExecuteReader(CommandBehavior.KeyInfo);
        Assert.NotNull(reader);

#if RT
        while (reader.Read()) ;
        Assert.Equal("PrimaryKey", reader.GetName(0));
#else
        dataTableSchema = reader.GetSchemaTable();
        Assert.True("PrimaryKey" == (string)dataTableSchema.Rows[0][dataTableSchema.Columns[0]]);
#endif
        reader.Close();
      }
    }
开发者ID:betabot7,项目名称:mysql-connector-net,代码行数:36,代码来源:MySqlCommandTests.cs

示例5: ExecuteReaderReturnsReaderAfterCancel

        public void ExecuteReaderReturnsReaderAfterCancel()
        {
            execSQL("DROP TABLE IF EXISTS TableWithDateAsPrimaryKey");
            execSQL("DROP TABLE IF EXISTS TableWithStringAsPrimaryKey");
            createTable("CREATE TABLE TableWithDateAsPrimaryKey(PrimaryKey date NOT NULL, PRIMARY KEY  (PrimaryKey))", "InnoDB");
            createTable("CREATE TABLE TableWithStringAsPrimaryKey(PrimaryKey nvarchar(50) NOT NULL, PRIMARY KEY  (PrimaryKey))", "InnoDB");

            string connStr = GetConnectionString(true);
            using (MySqlConnection connection = new MySqlConnection(connStr))
            {
                connection.Open();
                MySqlCommand command = new MySqlCommand("SELECT PrimaryKey FROM TableWithDateAsPrimaryKey", connection);
                var reader = command.ExecuteReader(CommandBehavior.KeyInfo);
                //DataTable dataTableSchema = reader.GetSchemaTable();
                command.Cancel();
                reader.Close();

                command = new MySqlCommand("SELECT PrimaryKey FROM TableWithStringAsPrimaryKey", connection);
                reader = command.ExecuteReader(CommandBehavior.KeyInfo);
                Assert.IsNotNull(reader);

                //dataTableSchema = reader.GetSchemaTable();
                //Assert.AreEqual("PrimaryKey", dataTableSchema.Rows[0][dataTableSchema.Columns[0]]);

                reader.Close();
            }
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:27,代码来源:CommandTests.cs


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