コード例 #1
0
ファイル: FbCommandTests.cs プロジェクト: zabulus/NETProvider
        public void CommandCancellationTest()
        {
            if (GetServerVersion() < new Version("2.5.0.0"))
            {
                Assert.Inconclusive("Not supported on this version.");
                return;
            }

            bool cancelled = false;

            using (FbCommand cmd = Connection.CreateCommand())
            {
                cmd.CommandText =
                    @"execute block as
declare variable start_time timestamp;
begin
  start_time = cast('now' as timestamp);
  while (datediff(second from start_time to cast('now' as timestamp)) <= 10) do
  begin
  end
end";
                cmd.BeginExecuteNonQuery(o =>
                {
                    try
                    {
                        cmd.EndExecuteNonQuery(o as IAsyncResult);
                    }
                    catch (FbException ex)
                    {
                        cancelled = "HY008" == ex.SQLSTATE;
                    }
                }, null);
                System.Threading.Thread.Sleep(2000);
                cmd.Cancel();
                System.Threading.Thread.Sleep(2000);
                Assert.IsTrue(cancelled);
            }
        }