Пример #1
0
        private IEnumerator<string> Compile(SQLContext LanguageContext)
        {
            yield return "UPDATE ";

            var From = Table.SourceDefinion.Compile(LanguageContext);
            while (From.MoveNext()) yield return From.Current;

            yield return " SET ";
            bool first = true;
            foreach (var setter in SetClause)
            {
                if (!first) yield return ", ";
                else first = false;

                var field = setter.Item1.ColumnDefinion.Compile(LanguageContext);
                while (field.MoveNext()) yield return field.Current;

                yield return " = ";

                var value = setter.Item2;
                foreach (var s in value) yield return s;
            }

            yield return " WHERE ";
            yield return where;
        }
Пример #2
0
 /// <summary>
 /// Gets a text representation of the identifier for a given SQL flavor
 /// </summary>
 public string Escape(SQLContext LanguageContext)
 {
     string cached = null;
     if (!CachedNames.TryGetValue(LanguageContext, out cached))
         CachedNames[LanguageContext] = cached = string.Concat(LanguageContext.LeftEscapingSymbol, Identifier, LanguageContext.RightEscapingSymbol);
     return cached;
 }
Пример #3
0
        private IEnumerator<string> Compile(SQLContext LanguageContext)
        {
            yield return "VALUES ";
            bool firstrow = true;
            foreach (var row in data)
            {
#if DEBUG
                yield return "\r\n   ";
#endif
                if (!firstrow) yield return ", ";
                else firstrow = false;
                
                yield return "(";

                bool firstcell = true;
                foreach (var cell in row)
                {
                    if (!firstcell) yield return ", ";
                    else firstcell = false;

                    var cellbuilder = cell.ColumnDefinion.Compile(LanguageContext);
                    while (cellbuilder.MoveNext()) yield return cellbuilder.Current;
                }

                yield return ")";
            }
        }
Пример #4
0
        private IEnumerator<string> Compile(SQLContext LanguageContext)
        {
            yield return "INSERT INTO ";

            var into = Into.SourceDefinion.Compile(LanguageContext);
            while (into.MoveNext()) yield return into.Current;

            yield return " (";
            for (int i = 0; i < fields.Length; i++)
            {
                var field = fields[i].NamedColumnDefinion.Compile(LanguageContext);
                while (field.MoveNext()) yield return field.Current;
                if (i < fields.Length - 1) yield return ", ";
            }
            yield return ") ";
#if DEBUG
            yield return "\r\n";
#endif
            if (Output != null)
            {
                var clause = LanguageContext.InsertReturningClause_at_Values(Output);
                while (clause.MoveNext()) yield return clause.Current;
            }

            var what = SourceData.InsertSourceDefinion.Compile(LanguageContext);
            while (what.MoveNext()) yield return what.Current;

            if (Output != null)
            {
                var clause = LanguageContext.InsertReturningClause_at_End(Output);
                while (clause.MoveNext()) yield return clause.Current;
            }
        }
Пример #5
0
 private IEnumerator<string> Compile(SQLContext LanguageContext)
 {
     yield return "CAST (";
     var arg = Argument.ColumnDefinion.Compile(LanguageContext);
     while (arg.MoveNext()) yield return arg.Current;            
     yield return " AS ";
     yield return LanguageContext.GetTypeName(TargetType);
     yield return ")";
 }
Пример #6
0
        /// <summary> Builds SQL text in the given context </summary>
        /// <param name="LanguageContext"> TSQL, PostgreSQL or other available options </param>
        public string Build(SQLContext LanguageContext)
        {
            var builder = new StringBuilder();

            var enumerator = getter(LanguageContext);
            while (enumerator.MoveNext())
                builder.Append(enumerator.Current);

            return builder.ToString();
        }
Пример #7
0
        private IEnumerator<string> Compile(SQLContext LanguageContext)
        {
            yield return "DELETE FROM ";

            var From = Table.SourceDefinion.Compile(LanguageContext);
            while (From.MoveNext()) yield return From.Current;

            yield return " WHERE ";
            yield return where;
        }
Пример #8
0
        private IEnumerator<string> Compile(SQLContext LanguageContext)
        {
            yield return "(";

            var subquery = baseColumn.ColumnDefinion.Compile(LanguageContext);
            while (subquery.MoveNext()) yield return subquery.Current;

            yield return ") AS ";

            var name = AS.ColumnDefinion.Compile(LanguageContext);
            while (name.MoveNext()) yield return name.Current;
        }
Пример #9
0
 private IEnumerator<string> Compile(SQLContext LanguageContext)
 {
     yield return LanguageContext.GetFunctionName(Function);
     yield return "( ";
     for (int i = 0; i < Arguments.Length; i++)
     {
         var arg = Arguments[i].ColumnDefinion.Compile(LanguageContext);
         while (arg.MoveNext()) yield return arg.Current;
         if (i < Arguments.Length - 1) yield return ", ";
     }
     yield return " )";
 }
Пример #10
0
        /// <summary>
        /// Gets a text representation of the identifier for a given SQL flavor
        /// </summary>
        public string Escape(SQLContext LanguageContext)
        {
            string cached = null;
            if (!CachedNames.TryGetValue(LanguageContext, out cached))
            {
                var builder = new StringBuilder();

                if (!string.IsNullOrEmpty(Schema))
                {
                    builder.Append(LanguageContext.LeftEscapingSymbol);
                    builder.Append(Schema);
                    builder.Append(LanguageContext.RightEscapingSymbol);
                    builder.Append(".");
                }
                builder.Append(LanguageContext.LeftEscapingSymbol);
                builder.Append(Identifier);
                builder.Append(LanguageContext.RightEscapingSymbol);

                CachedNames[LanguageContext] = cached = builder.ToString();
            }
            return cached;
        }
Пример #11
0
 internal IEnumerator<string> Compile(SQLContext LanguageContext) => getter(LanguageContext);
Пример #12
0
 private IEnumerator<string> Compile(SQLContext LanguageContext)
 {
     yield return Escape(LanguageContext);
 }
Пример #13
0
 /// <summary>
 /// Gets a text representation of the identifier for a given SQL flavor
 /// </summary>
 public string Escape(SQLContext LanguageContext) => "*";
Пример #14
0
 private IEnumerator<string> Compile(SQLContext LanguageContext)
 {
     var literal = LanguageContext.EscapeLiteral(Value);
     while (literal.MoveNext()) yield return literal.Current;
 }
Пример #15
0
        private IEnumerator<string> Compile(SQLContext LanguageContext)
        {
            yield return "SELECT ";
            if (top.HasValue)
            {
                yield return "TOP ";
                yield return top.ToString();
                yield return " ";
            }
#if DEBUG
            if (fields.Length > 1) yield return "\r\n   ";
#endif
            for (int i = 0; i < fields.Length; i++)
            {
                var field = fields[i].NamedColumnDefinion.Compile(LanguageContext);
                while (field.MoveNext()) yield return field.Current;                  
                if (i < fields.Length - 1) yield return ", ";
            }
#if DEBUG
            yield return "\r\n";
#endif
            yield return " FROM ";
#if DEBUG
            yield return "\r\n   ";
#endif
            var From = source.SourceDefinion.Compile(LanguageContext);
            while (From.MoveNext())
            {
                var current = From.Current;
#if DEBUG
                current = current.Replace("\r\n", "\r\n   ");
#endif
                yield return current;
            }

            if (where?.Length > 0)
            {
#if DEBUG
                yield return "\r\n";
#endif
                yield return " WHERE ";
#if DEBUG
                yield return "\r\n   ";
#endif
                bool brackets = where.Length > 1;

                for (int i = 0; i < where.Length; i++)
                {
                    if (brackets) yield return "(";
                    yield return where[i];
                    if (brackets) yield return ")";

                    if (i < where.Length - 1) yield return " AND ";
                }
            }
        }