本文整理汇总了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);
}
示例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();
}
示例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);
}
示例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();
}
}
示例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();
}
}