EndExecuteNonQuery() public method

Finishes asynchronous execution of a SQL statement.
public EndExecuteNonQuery ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult The returned by the call /// to .
return int
コード例 #1
0
ファイル: ManejoDB.cs プロジェクト: jj-gallardo/CRat
 public static void EjecutarQuery(string querySQL, MySqlConnection connection)
 {
     try
         {
             MySqlCommand command = new MySqlCommand(querySQL, connection);
             connection.Open();
             IAsyncResult result = command.BeginExecuteNonQuery();
             while (!result.IsCompleted)
             {
                 Thread.Sleep(50);
             }
             command.EndExecuteNonQuery(result);
             connection.Close();
         }
         catch (SqlException ex)
         {
             throw ex;
         }
         catch (InvalidOperationException ex)
         {
             throw ex;
         }
         catch (MySqlException ex)
         {
             //Se captura en el caso de intentar guardar un cliente que ya esta en
             //la base de datos. Como no me interesa guardarlo, no hago nada.
             if (ex.Message.IndexOf("PRIMARY", StringComparison.Ordinal) <= 0)
                 throw ex;
         }
 }
コード例 #2
0
ファイル: AsyncTests.cs プロジェクト: tdhieu/openvss
		public void ExecuteNonQuery()
		{
			if (version < new Version(5, 0)) return;

			execSQL("CREATE TABLE test (id int)");
			execSQL("CREATE PROCEDURE spTest() BEGIN SET @x=0; REPEAT INSERT INTO test VALUES(@x); " +
				"SET @x=@x+1; UNTIL @x = 300 END REPEAT; END");

			try
			{
				MySqlCommand proc = new MySqlCommand("spTest", conn);
				proc.CommandType = CommandType.StoredProcedure;
				IAsyncResult iar = proc.BeginExecuteNonQuery();
				int count = 0;
				while (!iar.IsCompleted)
				{
					count++;
					System.Threading.Thread.Sleep(20);
				}
				proc.EndExecuteNonQuery(iar);
				Assert.IsTrue(count > 0);

				proc.CommandType = CommandType.Text;
				proc.CommandText = "SELECT COUNT(*) FROM test";
				object cnt = proc.ExecuteScalar();
				Assert.AreEqual(300, cnt);
			}
			catch (Exception ex)
			{
				Assert.Fail(ex.Message);
			}
			finally
			{
			}
		}
コード例 #3
0
ファイル: Database.cs プロジェクト: CarlosX/DarkEmu
        public static void ExecuteQueryAsnyc(string MySqlCommand)
        {
            if (MySqlCommand != null)
            {
                Console.WriteLine(MySqlCommand);
                MySqlCommand Command = new MySqlCommand(MySqlCommand, connection);

                IAsyncResult result = Command.BeginExecuteNonQuery();
                while (!result.IsCompleted)
                {
                    System.Threading.Thread.Sleep(10);
                }
                Command.EndExecuteNonQuery(result);
            }
        }
コード例 #4
0
ファイル: MySql.cs プロジェクト: 906507516/Oxide
 public bool Handle()
 {
     List<Dictionary<string, object>> list = null;
     var nonQueryResult = 0;
     var lastInsertRowId = 0L;
     try
     {
         if (Connection == null) throw new Exception("Connection is null");
         //if (_result == null)
         //{
             _connection = Connection.Con;
             if (_connection.State == ConnectionState.Closed)
                 _connection.Open();
             _cmd = _connection.CreateCommand();
             _cmd.CommandText = Sql.SQL;
             Sql.AddParams(_cmd, Sql.Arguments, "@");
             _result = NonQuery ? _cmd.BeginExecuteNonQuery() : _cmd.BeginExecuteReader();
         //}
         _result.AsyncWaitHandle.WaitOne();
         //if (!_result.IsCompleted) return false;
         if (NonQuery)
             nonQueryResult = _cmd.EndExecuteNonQuery(_result);
         else
         {
             using (var reader = _cmd.EndExecuteReader(_result))
             {
                 list = new List<Dictionary<string, object>>();
                 while (reader.Read())
                 {
                     var dict = new Dictionary<string, object>();
                     for (var i = 0; i < reader.FieldCount; i++)
                     {
                         dict.Add(reader.GetName(i), reader.GetValue(i));
                     }
                     list.Add(dict);
                 }
             }
         }
         lastInsertRowId = _cmd.LastInsertedId;
         Cleanup();
     }
     catch (Exception ex)
     {
         var message = "MySql handle raised an exception";
         if (Connection?.Plugin != null) message += $" in '{Connection.Plugin.Name} v{Connection.Plugin.Version}' plugin";
         Interface.Oxide.LogException(message, ex);
         Cleanup();
     }
     Interface.Oxide.NextTick(() =>
     {
         Connection?.Plugin?.TrackStart();
         try
         {
             if (Connection != null) Connection.LastInsertRowId = lastInsertRowId;
             if (!NonQuery)
                 Callback(list);
             else
                 CallbackNonQuery?.Invoke(nonQueryResult);
         }
         catch (Exception ex)
         {
             var message = "MySql command callback raised an exception";
             if (Connection?.Plugin != null) message += $" in '{Connection.Plugin.Name} v{Connection.Plugin.Version}' plugin";
             Interface.Oxide.LogException(message, ex);
         }
         Connection?.Plugin?.TrackEnd();
     });
     return true;
 }