PlainSql() protected method

protected PlainSql ( StringBuilder sb ) : void
sb StringBuilder
return void
コード例 #1
0
        public Exception HandleException(Exception ex, SqlPreCommandSimple command)
        {
            var nex = ReplaceException(ex, command);

            nex.Data["Sql"] = command.PlainSql();
            return(nex);
        }
コード例 #2
0
        protected internal override object ExecuteScalar(SqlPreCommandSimple preCommand, CommandType commandType)
        {
            using (SqlConnection con = EnsureConnection())
                using (SqlCommand cmd = NewCommand(preCommand, con, commandType))
                    using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql()))
                    {
                        try
                        {
                            object result = cmd.ExecuteScalar();

                            if (result == null || result == DBNull.Value)
                            {
                                return(null);
                            }

                            return(result);
                        }
                        catch (Exception ex)
                        {
                            var nex = HandleException(ex, preCommand);
                            if (nex == ex)
                            {
                                throw;
                            }

                            throw nex;
                        }
                    }
        }
コード例 #3
0
        protected internal override DataSet ExecuteDataSet(SqlPreCommandSimple preCommand, CommandType commandType)
        {
            using (SqlConnection con = EnsureConnection())
                using (SqlCommand cmd = NewCommand(preCommand, con, commandType))
                    using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql()))
                    {
                        try
                        {
                            SqlDataAdapter da     = new SqlDataAdapter(cmd);
                            DataSet        result = new DataSet();
                            da.Fill(result);
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            var nex = HandleException(ex, preCommand);
                            if (nex == ex)
                            {
                                throw;
                            }

                            throw nex;
                        }
                    }
        }
コード例 #4
0
        protected internal override int ExecuteNonQuery(SqlPreCommandSimple preCommand, CommandType commandType)
        {
            using (SqlConnection con = EnsureConnection())
                using (SqlCommand cmd = NewCommand(preCommand, con, commandType))
                    using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql()))
                    {
                        try
                        {
                            int result = cmd.ExecuteNonQuery();
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            var nex = HandleException(ex, preCommand);
                            if (nex == ex)
                            {
                                throw;
                            }

                            throw nex;
                        }
                    }
        }
コード例 #5
0
        public void ExecuteDataReaderDependency(SqlPreCommandSimple preCommand, OnChangeEventHandler change, Action reconect, Action <FieldReader> forEach, CommandType commandType)
        {
            bool reconected = false;

retry:
            try
            {
                using (SqlConnection con = EnsureConnection())
                    using (SqlCommand cmd = NewCommand(preCommand, con, commandType))
                        using (HeavyProfiler.Log("SQL-Dependency"))
                            using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql()))
                            {
                                try
                                {
                                    if (change != null)
                                    {
                                        SqlDependency dep = new SqlDependency(cmd);
                                        dep.OnChange += change;
                                    }

                                    using (SqlDataReader reader = cmd.ExecuteReader())
                                    {
                                        FieldReader fr  = new FieldReader(reader);
                                        int         row = -1;
                                        try
                                        {
                                            while (reader.Read())
                                            {
                                                row++;
                                                forEach(fr);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            FieldReaderException fieldEx = fr.CreateFieldReaderException(ex);
                                            fieldEx.Command = preCommand;
                                            fieldEx.Row     = row;
                                            throw fieldEx;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    var nex = HandleException(ex, preCommand);
                                    if (nex == ex)
                                    {
                                        throw;
                                    }

                                    throw nex;
                                }
                            }
            }
            catch (InvalidOperationException ioe)
            {
                if (ioe.Message.Contains("SqlDependency.Start()") && !reconected)
                {
                    reconect();

                    reconected = true;

                    goto retry;
                }

                throw;
            }
        }
コード例 #6
0
 public Exception HandleException(Exception ex, SqlPreCommandSimple command)
 {
     var nex = ReplaceException(ex, command);
     nex.Data["Sql"] = command.PlainSql();
     return nex;
 }
コード例 #7
0
        protected internal override DataSet ExecuteDataSet(SqlPreCommandSimple preCommand, CommandType commandType)
        {
            using (SqlConnection con = EnsureConnection())
            using (SqlCommand cmd = NewCommand(preCommand, con, commandType))
            using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql()))
            {
                try
                {
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataSet result = new DataSet();
                    da.Fill(result);
                    return result;
                }
                catch (Exception ex)
                {
                    var nex = HandleException(ex, preCommand);
                    if (nex == ex)
                        throw;

                    throw nex;
                }
            }
        }
コード例 #8
0
        public void ExecuteDataReaderDependency(SqlPreCommandSimple preCommand, OnChangeEventHandler change, Action reconect, Action<FieldReader> forEach, CommandType commandType)
        {
            bool reconected = false; 
            retry:
            try
            {
                using (SqlConnection con = EnsureConnection())
                using (SqlCommand cmd = NewCommand(preCommand, con, commandType))
                using (HeavyProfiler.Log("SQL-Dependency"))
                using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql()))
                {
                    try
                    {
                        if (change != null)
                        {
                            SqlDependency dep = new SqlDependency(cmd);
                            dep.OnChange += change;
                        }

                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            FieldReader fr = new FieldReader(reader);
                            int row = -1;
                            try
                            {
                                while (reader.Read())
                                {
                                    row++;
                                    forEach(fr);
                                }
                            }
                            catch (Exception ex)
                            {
                                FieldReaderException fieldEx = fr.CreateFieldReaderException(ex);
                                fieldEx.Command = preCommand;
                                fieldEx.Row = row;
                                throw fieldEx;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var nex = HandleException(ex, preCommand);
                        if (nex == ex)
                            throw;

                        throw nex;
                    }
                }
            }
            catch (InvalidOperationException ioe)
            {
                if (ioe.Message.Contains("SqlDependency.Start()") && !reconected)
                {
                    reconect();

                    reconected = true;

                    goto retry;
                }

                throw;
            }
        }
コード例 #9
0
        protected internal override int ExecuteNonQuery(SqlPreCommandSimple preCommand, CommandType commandType)
        {
            using (SqlConnection con = EnsureConnection())
            using (SqlCommand cmd = NewCommand(preCommand, con, commandType))
            using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql()))
            {
                try
                {
                    int result = cmd.ExecuteNonQuery();
                    return result;
                }
                catch (Exception ex)
                {
                    var nex = HandleException(ex, preCommand);
                    if (nex == ex)
                        throw;

                    throw nex;
                }
            }
        }
コード例 #10
0
        protected internal override object ExecuteScalar(SqlPreCommandSimple preCommand, CommandType commandType)
        {
            using (SqlConnection con = EnsureConnection())
            using (SqlCommand cmd = NewCommand(preCommand, con, commandType))
            using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql()))
            {
                try
                {
                    object result = cmd.ExecuteScalar();

                    if (result == null || result == DBNull.Value)
                        return null;

                    return result;
                }
                catch (Exception ex)
                {
                    var nex = HandleException(ex, preCommand);
                    if (nex == ex)
                        throw;

                    throw nex;
                }
            }
        }