예제 #1
0
        public async Task <int> ExecuteNonQueryAsync(ISqlCompileUnit statement, CancellationToken token = default)
        {
            await EnsureConnectionIsOpenAsync(token).ConfigureAwait(false);

            var command = connection.CreateCommand(Compile(statement));

            await using (command.ConfigureAwait(false)) {
                return(await driver.ExecuteNonQueryAsync(session, command, token).ConfigureAwait(false));
            }
        }
예제 #2
0
        private async Task PrepareAsync(CancellationToken cancellationToken)
        {
            Session.EnsureNotDisposed();
            await driver.OpenConnectionAsync(Session, connection, cancellationToken).ConfigureAwait(false);

            try {
                foreach (var initializationSqlScript in initializationSqlScripts)
                {
                    using (var command = connection.CreateCommand(initializationSqlScript))
                        await driver.ExecuteNonQueryAsync(Session, command, cancellationToken).ConfigureAwait(false);
                }
            }
            catch (OperationCanceledException) {
                connection.Close();
                throw;
            }

            if (pendingTransaction == null)
            {
                return;
            }
            var transaction = pendingTransaction;

            pendingTransaction = null;
            if (connection.ActiveTransaction == null) // Handle external transactions
            {
                driver.BeginTransaction(Session, connection, IsolationLevelConverter.Convert(transaction.IsolationLevel));
            }
        }