コード例 #1
0
        public override string ToString()
        {
            var query = base.ToString();

            if (StatementCount <= 1)
            {
                query = query.Trim();                 // only trim for small queries as memory may be wasted otherwise
                if (query.EndsWith(StatementTerminator))
                {
                    query = query.Substring(0, query.Length - StatementTerminator.Length);
                }
            }
            else
            {
                var stringBuilder = new FastStringBuilder();
                stringBuilder.AppendFormat("SET TERM {0};{1}", StatementTerminator, Environment.NewLine);
                if (_variableDeclarations.Count > 0)
                {
                    stringBuilder.AppendLine("EXECUTE BLOCK AS");
                    stringBuilder.AppendLine("BEGIN");
                    foreach (var variable in _variableDeclarations.Keys)
                    {
                        stringBuilder.AppendFormat("DECLARE VARIABLE {0} {1}{2}{3}", variable, ConvertTypeToSQLType(_variableDeclarations[variable]), StatementTerminator, Environment.NewLine);
                    }
                }

                stringBuilder.Append(query);
                if (_variableDeclarations.Count > 0)
                {
                    stringBuilder.Append("END");
                }
                query = stringBuilder.ToString();
            }

            return(query);
        }