예제 #1
0
        public DataSet ExecuteDataSet(QueryCommand qry)
        {
            WriteToLog(() => string.Format("ExecuteDataSet(QueryCommand): {0}.", qry.CommandSql));

            DbCommand cmd = Factory.CreateCommand();

            cmd.CommandText = qry.CommandSql;
            cmd.CommandType = qry.CommandType;
            DataSet ds = new DataSet();

            using (AutomaticConnectionScope scope = new AutomaticConnectionScope(this))
            {
                cmd.Connection = scope.Connection;
                AddParams(cmd, qry);
                DbDataAdapter da = Factory.CreateDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(ds);

                return(ds);
            }
        }
예제 #2
0
        public DbDataReader ExecuteReader(QueryCommand qry)
        {
            AutomaticConnectionScope scope = new AutomaticConnectionScope(this);

            if (Log != null)
            {
                Log.WriteLine(qry.CommandSql);
            }

#if DEBUG
            //Console.Error.WriteLine("ExecuteReader(QueryCommand):\r\n{0}", qry.CommandSql);
#endif
            DbCommand cmd = scope.Connection.CreateCommand();
            cmd.Connection = scope.Connection; //CreateConnection();

            cmd.CommandText = qry.CommandSql;
            cmd.CommandType = qry.CommandType;

            AddParams(cmd, qry);

            //this may look completely lame
            //but there is a bug in here...

            DbDataReader rdr;
            //Thanks jcoenen!
            try
            {
                // if it is a shared connection, we shouldn't be telling the reader to close it when it is done
                rdr = scope.IsUsingSharedConnection ? cmd.ExecuteReader() : cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (Exception)
            {
                // AutoConnectionScope will figure out what to do with the connection
                scope.Dispose();
                //rethrow retaining stack trace.
                throw;
            }

            return(rdr);
        }
예제 #3
0
        public DbDataReader ExecuteReader(QueryCommand qry, out string connectionString)
        {
            AutomaticConnectionScope scope = new AutomaticConnectionScope(this);

            WriteToLog(() => string.Format("ExecuteReader(QueryCommand):\r\n{0}", qry.CommandSql));

            // Added for supporting PetaPoco integration for optimized object hydration
            connectionString = scope.Connection.ConnectionString;

            DbCommand cmd = scope.Connection.CreateCommand();

            cmd.Connection = scope.Connection; //CreateConnection();

            cmd.CommandText = qry.CommandSql;
            cmd.CommandType = qry.CommandType;

            AddParams(cmd, qry);

            //this may look completely lame
            //but there is a bug in here...

            DbDataReader rdr;

            //Thanks jcoenen!
            try
            {
                // if it is a shared connection, we shouldn't be telling the reader to close it when it is done
                rdr = scope.IsUsingSharedConnection ? cmd.ExecuteReader() : cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (Exception)
            {
                // AutoConnectionScope will figure out what to do with the connection
                scope.Dispose();
                //rethrow retaining stack trace.
                throw;
            }

            return(rdr);
        }
예제 #4
0
        public object ExecuteScalar(QueryCommand qry)
        {
            WriteToLog(() => string.Format("ExecuteScalar(QueryCommand): {0}.", qry.CommandSql));

            object result;

            using (AutomaticConnectionScope automaticConnectionScope = new AutomaticConnectionScope(this))
            {
                DbCommand cmd = Factory.CreateCommand();
                cmd.Connection = automaticConnectionScope.Connection;
                if (automaticConnectionScope.IsUsingSharedConnection && CurrentSharedTransaction != null)
                {
                    cmd.Transaction = CurrentSharedTransaction;
                }
                cmd.CommandType = qry.CommandType;
                cmd.CommandText = qry.CommandSql;
                AddParams(cmd, qry);
                result = cmd.ExecuteScalar();
            }

            return(result);
        }
예제 #5
0
        public int ExecuteQuery(QueryCommand qry)
        {
            WriteToLog(() => string.Format("ExecuteQuery(QueryCommand): {0}.", qry.CommandSql));

            int result;

            using (AutomaticConnectionScope automaticConnectionScope = new AutomaticConnectionScope(this))
            {
                DbCommand cmd = automaticConnectionScope.Connection.CreateCommand();
                if (automaticConnectionScope.IsUsingSharedConnection && CurrentSharedTransaction != null)
                {
                    cmd.Transaction = CurrentSharedTransaction;
                }
                cmd.CommandText = qry.CommandSql;
                cmd.CommandType = qry.CommandType;
                AddParams(cmd, qry);
                result = cmd.ExecuteNonQuery();
                // Issue 11 fix introduced by [email protected]
                qry.GetOutputParameters(cmd);
            }

            return(result);
        }
예제 #6
0
        public int ExecuteQuery(QueryCommand qry)
        {
            if (Log != null)
            {
                Log.WriteLine(qry.CommandSql);
            }

#if DEBUG
            //Console.Error.WriteLine("ExecuteQuery(QueryCommand): {0}.", qry.CommandSql);
#endif
            int result;
            using (AutomaticConnectionScope automaticConnectionScope = new AutomaticConnectionScope(this))
            {
                DbCommand cmd = automaticConnectionScope.Connection.CreateCommand();
                cmd.CommandText = qry.CommandSql;
                cmd.CommandType = qry.CommandType;
                AddParams(cmd, qry);
                result = cmd.ExecuteNonQuery();
                // Issue 11 fix introduced by [email protected]
                qry.GetOutputParameters(cmd);
            }

            return(result);
        }