コード例 #1
0
ファイル: MySqlCommand.cs プロジェクト: ejball/MySqlConnector
        protected override async Task <DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
        {
            VerifyValid();
            Connection.HasActiveReader = true;

            MySqlDataReader reader = null;

            try
            {
                LastInsertedId = -1;
                var connection = (MySqlConnection)DbConnection;
                var preparer   = new MySqlStatementPreparer(CommandText, m_parameterCollection, connection.AllowUserVariables ? StatementPreparerOptions.AllowUserVariables : StatementPreparerOptions.None);
                preparer.BindParameters();
                var payload = new PayloadData(new ArraySegment <byte>(Payload.CreateEofStringPayload(CommandKind.Query, preparer.PreparedSql)));
                await Session.SendAsync(payload, cancellationToken).ConfigureAwait(false);

                reader = await MySqlDataReader.CreateAsync(this, behavior, cancellationToken).ConfigureAwait(false);

                return(reader);
            }
            finally
            {
                if (reader == null)
                {
                    // received an error from MySQL and never created an active reader
                    Connection.HasActiveReader = false;
                }
            }
        }
コード例 #2
0
        internal async Task <DbDataReader> ExecuteReaderAsync(CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken)
        {
            VerifyValid();
            Connection.HasActiveReader = true;

            MySqlDataReader reader = null;

            try
            {
                LastInsertedId = -1;
                var connection = (MySqlConnection)DbConnection;
                var statementPreparerOptions = StatementPreparerOptions.None;
                if (connection.AllowUserVariables)
                {
                    statementPreparerOptions |= StatementPreparerOptions.AllowUserVariables;
                }
                if (connection.OldGuids)
                {
                    statementPreparerOptions |= StatementPreparerOptions.OldGuids;
                }
                var preparer = new MySqlStatementPreparer(CommandText, m_parameterCollection, statementPreparerOptions);
                var payload  = new PayloadData(preparer.ParseAndBindParameters());
                await Session.SendAsync(payload, ioBehavior, cancellationToken).ConfigureAwait(false);

                reader = await MySqlDataReader.CreateAsync(this, behavior, ioBehavior, cancellationToken).ConfigureAwait(false);

                return(reader);
            }
            finally
            {
                if (reader == null)
                {
                    // received an error from MySQL and never created an active reader
                    Connection.HasActiveReader = false;
                }
            }
        }