public static string ToSqlText(this DbActionInfo info)
        {
            if (info.SqlText == DbActionInfo.OpenConnectionFlag)
            {
                return(string.Empty);
            }


            string        commandText = RepairLFchar(info.SqlText);
            StringBuilder sb          = new StringBuilder(2048);

            if (info.Parameters != null && info.Parameters.Count > 0)
            {
                foreach (CommandParameter p in info.Parameters)
                {
                    sb.AppendLine(p.ToDeclareString());
                }
            }


            sb.AppendLine(commandText);
            sb.AppendLine("\r\n");

            return(sb.ToString());
        }
        private List <DbActionInfo> TryGetDbActionListFromResponseHeader(Session oSession)
        {
            List <DbActionInfo> list = null;

            int index = 1;

            for ( ;;)
            {
                string headerName = "X-SQL-Action-" + (index++).ToString();
                string value      = oSession.GetResponseHeader <string>(headerName);
                if (string.IsNullOrEmpty(value))
                {
                    break;
                }

                DbActionInfo info = DbActionInfo.Deserialize(value);

                if (list == null)
                {
                    list = new List <DbActionInfo>();
                }
                list.Add(info);
            }

            return(list);
        }
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count < 1)
            {
                return;
            }

            ListViewItem item = listView1.SelectedItems[0];
            DbActionInfo info = (DbActionInfo)item.Tag;

            if (info.SqlText == DbActionInfo.OpenConnectionFlag)
            {
                textBox1.Text = string.Empty;
                return;
            }

            // 在XmlCommand中 \r\n 读取后会变成 \n ,这是XML规范问题,所以只能在这里强制添加 \r,
            // http://stackoverflow.com/questions/2004386/how-to-save-newlines-in-xml-attribute
            // 如果是用CPQuery拼接出来的SQL,即使包含\r\n,替换后也能正常显示。

            // 如果希望精确处理XmlCommand,
            // 可以在DataLayerEventSubscriber的Instance_AfterExecute,Instance_OnException
            // 中判断是不是XmlCommand,继而可以针对地处理。
            // 这里简单地处理算了!

            string        commandText = info.SqlText.Replace("\n", "\r\n");
            StringBuilder sb          = new StringBuilder(commandText);

            sb.AppendLine("\r\n");


            if (info.ErrorMsg != null)
            {
                sb.AppendLine()
                .AppendLine("---------------------------------------------------------------------------------")
                .AppendLine("Error:")
                .AppendLine(info.ErrorMsg)
                .AppendLine();
            }

            if (info.Parameters != null && info.Parameters.Count > 0)
            {
                sb.AppendLine()
                .AppendLine("---------------------------------------------------------------------------------")
                .AppendLine("Parameters:");

                foreach (CommandParameter p in info.Parameters)
                {
                    sb.AppendFormat("  {0} = ({1}) {2}\r\n", p.Name, p.DbType, p.Value);
                }

                sb.AppendLine();
            }

            textBox1.Text = sb.ToString();
        }
Ejemplo n.º 4
0
        public static string Serialize(DbActionInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(info);

            return(CompressHelper.GzipCompress(json));
        }
Ejemplo n.º 5
0
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count < 1)
            {
                return;
            }

            ListViewItem item = listView1.SelectedItems[0];
            DbActionInfo info = (DbActionInfo)item.Tag;

            if (info.SqlShowText == null)
            {
                info.SqlShowText = info.ToShowText();
            }

            textBox1.Text = info.SqlShowText;
        }
Ejemplo n.º 6
0
        private void listView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (listView1.SelectedItems.Count < 1)
            {
                return;
            }

            ListViewItem item = listView1.SelectedItems[0];
            DbActionInfo info = (DbActionInfo)item.Tag;

            string sql = info.ToSqlText();

            try {
                Clipboard.SetText(sql);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "ClownFish.FiddlerPulgin", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        public static string ToShowText(this DbActionInfo info)
        {
            if (info.SqlText == DbActionInfo.OpenConnectionFlag)
            {
                return(string.Empty);
            }


            string        commandText = RepairLFchar(info.SqlText);
            StringBuilder sb          = new StringBuilder(2048);

            sb.AppendLine(commandText);
            sb.AppendLine();


            if (info.ErrorMsg != null)
            {
                sb.AppendLine()
                .AppendLine("---------------------------------------------------------------------------------")
                .AppendLine("Error:")
                .AppendLine(info.ErrorMsg)
                .AppendLine();
            }

            if (info.Parameters != null && info.Parameters.Count > 0)
            {
                sb.AppendLine()
                .AppendLine("---------------------------------------------------------------------------------")
                .AppendLine("Parameters:");

                foreach (CommandParameter p in info.Parameters)
                {
                    sb.AppendFormat("  {0} = ({1}) {2}\r\n", p.Name, p.DbType, p.Value);
                }

                sb.AppendLine("\r\n");
            }

            return(sb.ToString());
        }
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count < 1)
            {
                return;
            }

            ListViewItem item = listView1.SelectedItems[0];
            DbActionInfo info = (DbActionInfo)item.Tag;

            if (info.SqlText == DbActionInfo.OpenConnectionFlag)
            {
                textBox1.Text = string.Empty;
                return;
            }

            // 在XmlCommand中 \r\n 读取后会变成 \n ,这是XML规范问题,所以只能在这里强制添加 \r,
            // http://stackoverflow.com/questions/2004386/how-to-save-newlines-in-xml-attribute
            // 如果是用CPQuery拼接出来的SQL,即使包含\r\n,替换后也能正常显示。

            // 如果希望精确处理XmlCommand,
            // 可以在DataLayerEventSubscriber的Instance_AfterExecute,Instance_OnException
            // 中判断是不是XmlCommand,继而可以针对地处理。
            // 这里简单地处理算了!

            List <string> nonQuotes = new List <string> {
                "Int", "DECIMAL(18, 4)"
            };

            StringBuilder sb = new StringBuilder();

            if (info.Parameters != null && info.Parameters.Count > 0)
            {
                sb.AppendLine()
                .AppendLine("---------------------------------------------------------------------------------")
                .AppendLine("--Parameters:");

                sb.Append("DECLARE ");

                for (int i = 0; i < info.Parameters.Count; i++)
                {
                    CommandParameter p      = info.Parameters[i];
                    string           dbType = CSharpType2DbType(p.DbType);

                    // 如果不是最后一个则补","号
                    string quotes = string.Empty;
                    if (i != info.Parameters.Count - 1)
                    {
                        quotes = ",";
                    }
                    // 判断值是否需要加"''"号
                    if (nonQuotes.Contains(dbType))
                    {
                        sb.AppendFormat("{0} {1} = {2}{3}\r\n", p.Name, dbType, p.Value, quotes);
                    }
                    else
                    {
                        sb.AppendFormat("{0} {1} = '{2}'{3}\r\n", p.Name, dbType, p.Value, quotes);
                    }
                }

                //foreach (CommandParameter p in info.Parameters)
                //    sb.AppendFormat("  {0} = ({1}) {2}\r\n", p.Name, p.DbType, p.Value);

                sb.AppendLine();
            }

            sb.AppendLine()
            .AppendLine("---------------------------------------------------------------------------------")
            .AppendLine("--Sql Content:")
            .AppendLine();

            string commandText = info.SqlText.Replace("\n", "\r\n");

            sb.Append(commandText);
            //StringBuilder sb = new StringBuilder(commandText);

            sb.AppendLine("\r\n");


            if (info.ErrorMsg != null)
            {
                sb.AppendLine()
                .AppendLine("---------------------------------------------------------------------------------")
                .AppendLine("--Error:")
                .AppendLine(info.ErrorMsg)
                .AppendLine();
            }

            //if( info.Parameters != null && info.Parameters.Count > 0 ) {
            //	sb.AppendLine()
            //		.AppendLine("---------------------------------------------------------------------------------")
            //		.AppendLine("Parameters:");

            //	foreach( CommandParameter p in info.Parameters )
            //		sb.AppendFormat("  {0} = ({1}) {2}\r\n", p.Name, p.DbType, p.Value);

            //	sb.AppendLine();
            //}

            textBox1.Text = sb.ToString();
        }