示例#1
0
        public static string PrettyDBDeets(DbTaskSummary pDBDeets)
        {
            StringBuilder sbDeets = new StringBuilder();

            sbDeets.AppendLine(pDBDeets.TimingPretty);
            sbDeets.AppendLine(pDBDeets.QueryAsExecutableText);
            sbDeets.AppendLine(pDBDeets.ExceptionPretty);
            sbDeets.AppendLine(pDBDeets.ExtendedInfo);
            sbDeets.AppendLine(pDBDeets.BlackBoxAsText);
            return(sbDeets.ToString());
        }
示例#2
0
        public static void DebugSql(DbTask pDbt)
        {
            //if (ConnectionNotOpenHappened(ref pDbt,MethodBase.GetCurrentMethod())) return;

            var DBDeets = new DbTaskSummary {
                QueryRaw = pDbt.Sql
            };

            //if (pDbt.Sql.ToLower().IndexOf("insert into [activitylog]") > -1) return;

            if (pDbt.Sql != null & DbUtility.IsAdHocSql(pDbt.Sql))
            {
                DBDeets.QueryType = TypeOfQuery.AdHocSQL;
            }

            if (DBDeets.QueryType == TypeOfQuery.AdHocSQL)
            {
                DBDeets.QueryRaw              = pDbt.Sql;
                DBDeets.QueryPrettyFormatted  = DBMaria.PrettySQL(pDbt.Sql);
                DBDeets.QueryAsExecutableText = DBDeets.QueryPrettyFormatted;
            }
            else
            {
                DBDeets.QueryType = TypeOfQuery.SProc;

                // TODO function in Utility
                StringBuilder sbSprocCall = new StringBuilder();
                sbSprocCall.Append("EXEC " + pDbt.SqlCmd.CommandText + " ");
                foreach (SqlParameter parm in pDbt.SqlCmd.Parameters)
                {
                    sbSprocCall.AppendFormat(" {0}={1}, ", parm.ParameterName,
                                             DbUtility.DelimitObject(parm.Value));
                }
                string sprocCallExpanded = sbSprocCall.ToString();
                // remove the trailing comma
                if (sprocCallExpanded.EndsWith(", "))
                {
                    sprocCallExpanded = sprocCallExpanded.Substring(0, sprocCallExpanded.Length - 2);
                }
                DBDeets.QueryPrettyFormatted  = sprocCallExpanded;
                DBDeets.QueryAsExecutableText = DBDeets.QueryPrettyFormatted;
            }

            if (pDbt.IsSqlCommand)
            {
                DBDeets.QueryType             = TypeOfQuery.CommandObject;
                DBDeets.QueryAsExecutableText = pDbt.SqlCmd.TSqlFromFromCommand();
            }
            DBDeets.MthdBsPretty = DBMaria.PrettyMethodBase(pDbt.MethodBase);


            // timing transfer
            DBDeets.MilliSecondsElapsed = pDbt.SW.ElapsedMilliseconds;
            DBDeets.TimingPretty        = DBMaria.PrettyDBtTiming(pDbt);

            if (pDbt.DbQueryType == DbQueryType.DataReader || pDbt.DbQueryType == DbQueryType.DataTable)
            {
                // TODO: may need tweaking with multiple result sets
                DBDeets.BlackBoxAsText = DBMaria.PrettyDataTable(pDbt.LogCaptureDataset.Tables[0], Schema: pDbt.Schema);
                DBDeets.BlackBox       = pDbt.LogCaptureDataset;
            }

            DBDeets.RawExceptionQuery    = pDbt.ExceptionQuery;
            DBDeets.RawExceptionDelegate = pDbt.ExceptionDelegate;
            DBDeets.ExceptionPretty      = string.Empty;
            if (DBDeets.RawExceptionQuery != null)
            {
                DBDeets.ExceptionPretty = "QueryException=" + DBMaria.PrettyException(pDbt.ExceptionQuery);
            }
            if (DBDeets.RawExceptionDelegate != null)
            {
                DBDeets.ExceptionPretty += System.Environment.NewLine + "DelegateException=" + DBMaria.PrettyException(pDbt.ExceptionDelegate);
            }
            Debug.WriteLine(DBMaria.PrettyDBDeets(DBDeets));
        }