예제 #1
0
        protected virtual IActiveOperation <TInternal> PrepareNonQueryOperationWithParameter <TContext, TMySqlOperation, TOperation, TResult, TInternal>(TMySqlOperation operation, IReadOnlyCollection <IColumnValuePair <byte[]> > dataEntryList, Func <TOperation, IAsyncResult, TInternal> createResultHandler, Func <MySqlCommand, TInternal, string> finalizer)
            where TContext : IModifyContext, IDataContext
            where TMySqlOperation : IMySqlModifyOperation <TContext, TInternal>, TOperation
            where TOperation : IModifyOperation, IOperation <TContext, TResult>
            where TResult : IModifyResult, IDataResult
            where TInternal : IModifyResultInternal, IDataResultInternal, TResult
        {
            TInternal OperationResult;
            MySqlActiveOperation <TInternal> ActiveOperation;

            try
            {
                string CommandText = operation.GetCommandText();

                MySqlCommand Command = new MySqlCommand(CommandText, Connection);

                int i = 0;
                foreach (IColumnValuePair <byte[]> DataEntry in dataEntryList)
                {
                    MySqlParameter DataParameter = Command.CreateParameter();
                    DataParameter.ParameterName = $"data{i}";
                    DataParameter.Value         = DataEntry.Value;
                    Command.Parameters.Add(DataParameter);

                    i++;
                }

                TraceCommand(Command);
                IAsyncResult Result = Command.BeginExecuteNonQuery();

                OperationResult = createResultHandler(operation, Result);
                ActiveOperation = new MySqlActiveOperation <TInternal>(OperationResult, finalizer);
                ActiveOperationTable.Add(ActiveOperation, Command);
            }
#if TRACE
            catch (ApplicationException)
            {
                throw;
            }
#endif
            catch (MySqlException e)
            {
                TraceMySqlException(e);
                OperationResult = createResultHandler(operation, null);
                ActiveOperation = new MySqlActiveOperation <TInternal>(OperationResult);
            }
            catch (Exception e)
            {
                TraceException(e);
                OperationResult = createResultHandler(operation, null);
                ActiveOperation = new MySqlActiveOperation <TInternal>(OperationResult);
            }

            return(ActiveOperation);
        }
예제 #2
0
        protected virtual IActiveOperation <TInternal> PrepareNonQueryOperation <TContext, TMySqlOperation, TOperation, TResult, TInternal>(TMySqlOperation operation, Func <TOperation, IAsyncResult, TInternal> createResultHandler, Func <MySqlCommand, TInternal, string> finalizer)
            where TContext : IModifyContext
            where TMySqlOperation : IMySqlModifyOperation <TContext, TInternal>, TOperation
            where TOperation : IModifyOperation, IOperation <TContext, TResult>
            where TResult : IModifyResult
            where TInternal : IModifyResultInternal, TResult
        {
            TInternal OperationResult;
            MySqlActiveOperation <TInternal> ActiveOperation;

            try
            {
                string CommandText = operation.GetCommandText();

                MySqlCommand Command = new MySqlCommand(CommandText, Connection);

                TraceCommand(Command);
                IAsyncResult Result = Command.BeginExecuteNonQuery();

                OperationResult = createResultHandler(operation, Result);
                ActiveOperation = new MySqlActiveOperation <TInternal>(OperationResult, finalizer);
                ActiveOperationTable.Add(ActiveOperation, Command);
            }
#if TRACE
            catch (ApplicationException)
            {
                throw;
            }
#endif
            catch (MySqlException e)
            {
                TraceMySqlException(e);
                OperationResult = createResultHandler(operation, null);
                ActiveOperation = new MySqlActiveOperation <TInternal>(OperationResult);
            }
            catch (Exception e)
            {
                TraceException(e);
                OperationResult = createResultHandler(operation, null);
                ActiveOperation = new MySqlActiveOperation <TInternal>(OperationResult);
            }

            return(ActiveOperation);
        }