예제 #1
0
        private static T Execute <T>(WrappedConnection wrappedConnection, string sql, Func <IDbCommand, T> query)
        {
            Check.NotNull(wrappedConnection, nameof(wrappedConnection));
            Check.NotNullOrEmpty(sql, nameof(sql));
            Check.NotNull(query, nameof(query));

            bool wasClosed = wrappedConnection.DbConnection.State == ConnectionState.Closed;

            try
            {
                if (wasClosed)
                {
                    wrappedConnection.Open();
                }

                using (IDbCommand cmd = wrappedConnection.DbConnection.CreateCommand())
                {
                    cmd.CommandText = sql;
                    cmd.Transaction = wrappedConnection.CurrentTx;

                    return(query(cmd));
                }
            }
            catch (Exception ex)
            {
                throw new EvolveSqlException(sql, ex);
            }
            finally
            {
                if (wasClosed)
                {
                    wrappedConnection.Close();
                }
            }
        }
예제 #2
0
 public override void Close()
 {
     if ((Transaction != null) && !Transaction.GetWrappedProperty <bool>("HasAlreadyBeenCommittedOrRolledBack") && (Transaction.Connection == null))
     {
         Transaction.SetWrappedField("_connection", WrappedConnection);
     }
     _catalogHelpers = null;
     WrappedConnection.Close();
 }
예제 #3
0
        /// <inheritdoc cref="DbConnection.Close()" />
        public override void Close()
        {
            if (Profiler == null || !Profiler.IsEnabled)
            {
                WrappedConnection.Close();

                return;
            }

            Profiler.OnClosing(this);

            WrappedConnection.Close();

            Profiler.OnClosed(this);
        }
예제 #4
0
        public void When_opened_multiple_times_a_single_call_to_close_is_not_enought()
        {
            var cnn = new SqliteConnection("Data Source=:memory:");

            using (var wrappedConnection = new WrappedConnection(cnn))
            {
                wrappedConnection.Open();
                wrappedConnection.Open();
                wrappedConnection.Open();

                wrappedConnection.Close();

                Assert.True(wrappedConnection.DbConnection.State == ConnectionState.Open);
            }

            Assert.True(cnn.State == ConnectionState.Closed);
        }
예제 #5
0
        public void When_opened_multiple_times_a_single_call_to_close_is_not_enought()
        {
            var cnn = _pgContainer.CreateDbConnection();

            using (var wrappedConnection = new WrappedConnection(cnn))
            {
                wrappedConnection.Open();
                wrappedConnection.Open();
                wrappedConnection.Open();

                wrappedConnection.Close();

                Assert.True(wrappedConnection.DbConnection.State == ConnectionState.Open);
            }

            Assert.True(cnn.State == ConnectionState.Closed);
        }