Пример #1
0
        /// <summary>
        /// Outputs the SQL script as a string
        /// </summary>
        /// <param name="outputParameterDeclarations">
        /// If set to true will place the parameter DECLARE statements on top of the script
        /// and try to escape values where needed.
        /// </param>
        /// <returns>
        /// SQL script as a string
        /// </returns>
        public string ToSqlString(bool outputParameterDeclarations) {
            if (outputParameterDeclarations && this.HasParameters) {
                var tsb = new StringBuilder();

                foreach (SqlParameter sqlParameter in this.Parameters) {
                    ParameterFormat paramInfo = ParameterFormatter.Format(sqlParameter);
                    tsb.AppendFormat(
                        "DECLARE {0} AS {1} = {2};",
                        sqlParameter.ParameterName,
                        paramInfo.SqlServerDbEngineTypeString,
                        paramInfo.PrintableParameterValue);
                    tsb.AppendLine();
                }

                tsb.AppendLine(this.sb.ToString());
                return tsb.ToString();
            }

            return this.sb.ToString();
        }