Ejemplo n.º 1
0
        /// <summary>
        /// 写入<see cref="ScalarFragment"/>方法。
        /// </summary>
        /// <param name="writer">语句写入器。</param>
        /// <param name="fragment">当前语句。</param>
        private void WriteFragmentForScalar(SqlWriter writer, ISqlFragment fragment)
        {
            var content = (ScalarFragment)fragment;

            if (_WriteScalarMethods.TryGetValue(content.Function, out WriteFragmentDelegate action))
            {
                action(writer, content);
                return;
            }
            var attribute = content.Function.GetCustomAttribute <DbFunctionAttribute>();

            if (attribute != null)
            {
                if (attribute.IsSystemFunction)
                {
                    writer.Write(attribute.Name);
                }
                else
                {
                    WriteDbObject(writer, attribute.Name, attribute.Schema);
                }
                writer.Write('(');
                content.Arguments.ForEach(() => writer.Write(','), a => a.WriteSql(writer));
                writer.Write(')');
                return;
            }
            throw new NotSupportedException(string.Format(Res.NotSupportedWriteFragmentForScalar, content.Function));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 写入分组语句。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="groups">分组语句集合。</param>
 protected virtual void WriteFragmentForGroupBy(SqlWriter writer, IEnumerable <ISqlFragment> groups)
 {
     if (groups.Any())
     {
         writer.WriteLine();
         writer.Write("GROUP BY ");
         groups.ForEach(() => writer.Write(", "), item => item.WriteSql(writer));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 写入排序语句。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="sorts">排序语句集合。</param>
 protected virtual void WriteFragmentForOrderBy(SqlWriter writer, IEnumerable <IExpressionFragment> sorts)
 {
     if (sorts.Any())
     {
         writer.WriteLine();
         writer.Write("ORDER BY ");
         sorts.ForEach(() => writer.Write(", "), sort => sort.WriteSql(writer));
     }
 }
Ejemplo n.º 4
0
        private void WriteBinaryForAssign(SqlWriter writer, ISqlFragment fragment)
        {
            var binary = (BinaryFragment)fragment;

            writer.Write("SET ");
            binary.Left.WriteSql(writer);
            writer.Write(" = ");
            binary.Right.WriteSql(writer);
        }
Ejemplo n.º 5
0
        private void WriteBinaryForPower(SqlWriter writer, ISqlFragment fragment)
        {
            var binary = (BinaryFragment)fragment;

            writer.Write("POWER(");
            binary.Left.WriteSql(writer);
            writer.Write(", ");
            binary.Right.WriteSql(writer);
            writer.Write(')');
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 写入SELECT输出成员。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="members">写入的成员列表。</param>
 protected virtual void WriteFragmentForSelectMembers(SqlWriter writer, IEnumerable <IMemberFragment> members)
 {
     members.ForEach(() => writer.Write(", "), column =>
     {
         column.WriteSql(writer);
         if (!string.IsNullOrEmpty(column.AliasName))
         {
             writer.Write(" AS ");
             WriteDbName(writer, column.AliasName);
         }
     });
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 写入数据源连接子句
        /// </summary>
        /// <param name="writer">语句写入器。</param>
        /// <param name="source">目标写入的数据源。</param>
        protected virtual void WriteFragmentForSourceJoin(SqlWriter writer, ISourceFragment source)
        {
            switch (source.Join.Value)
            {
            case EJoinType.CrossJoin: writer.Write("CROSS JOIN "); break;

            case EJoinType.InnerJoin: writer.Write("INNER JOIN "); break;

            case EJoinType.LeftJoin: writer.Write("LEFT JOIN "); break;

            case EJoinType.RightJoin: writer.Write("RIGHT JOIN "); break;
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 写入数据源连接条件。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="source">数据源语句。</param>
 protected virtual void WriteFragmentForSourceCondition(SqlWriter writer, ISourceFragment source)
 {
     if (source.Condition != null)
     {
         writer.Write(" ON ");
         source.Condition.WriteSql(writer);
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 写入数据源内容。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="source">数据源语句。</param>
 protected virtual void WriteFragmentForSourceContent(SqlWriter writer, ISourceFragment source)
 {
     if (source is SelectFragment || source is SetFragment)
     {
         writer.Write('(');
         source.WriteSql(writer);
         writer.Write(')');
     }
     else
     {
         source.WriteSql(writer);
     }
     if (!(source is InheritFragment))
     {
         writer.Write(" AS ");
         writer.Write(source.AliasName);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 写入过滤条件。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="where">过滤条件。</param>
 protected virtual void WriteFragmentForWhere(SqlWriter writer, ILogicFragment where)
 {
     if (where != null)
     {
         writer.WriteLine();
         writer.Write("WHERE ");
         where.WriteSql(writer);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 写入查询数据源子句。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="sources">数据源集合。</param>
 protected virtual void WriteFragmentForFrom(SqlWriter writer, IEnumerable <ISourceFragment> sources)
 {
     if (sources.Any())
     {
         writer.WriteLine();
         writer.Write("FROM ");
         sources.ForEach(() => writer.WriteLine(),
                         source => WriteFragmentForSource(writer, source));
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 写入数据库对象名称。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="name">名称。</param>
 /// <param name="schema">架构名。</param>
 public virtual void WriteDbObject(SqlWriter writer, string name, string schema)
 {
     if (string.IsNullOrEmpty(schema))
     {
         schema = writer.Context.Feature.DefaultSchema;
     }
     if (!string.IsNullOrEmpty(schema))
     {
         WriteDbName(writer, schema);
         writer.Write('.');
     }
     WriteDbName(writer, name);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 写入参数名称。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="name">名称。</param>
 public virtual void WriteParameterName(SqlWriter writer, string name)
 {
     writer.Write('@');
     writer.Write(name);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 写入别名。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="name">名称。</param>
 public virtual void WriteAliasName(SqlWriter writer, string name)
 {
     writer.Write(" AS ");
     writer.Write(name);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 写入语句终止符。
 /// </summary>
 /// <param name="writer">语句写入器。</param>
 /// <param name="fragment">当前语句。</param>
 public virtual void WriteTerminator(SqlWriter writer, ISqlFragment fragment) => writer.Write(';');
Ejemplo n.º 16
0
        private void WriteBinaryForSimple(SqlWriter writer, ISqlFragment fragment)
        {
            var binary = (BinaryFragment)fragment;

            binary.Left.WriteSql(writer);
            switch (binary.Kind)
            {
            case EBinaryKind.AndAlso: break;

            case EBinaryKind.OrElse: break;

            case EBinaryKind.Add: writer.Write(" + "); break;

            case EBinaryKind.Subtract: writer.Write(" - "); break;

            case EBinaryKind.Multiply: writer.Write(" * "); break;

            case EBinaryKind.Divide: writer.Write(" / "); break;

            case EBinaryKind.Modulo: writer.Write(" % "); break;

            case EBinaryKind.And: writer.Write(" & "); break;

            case EBinaryKind.Or: writer.Write(" | "); break;

            case EBinaryKind.ExclusiveOr: writer.Write(" ^ "); break;

            case EBinaryKind.Equal: writer.Write(" = "); break;

            case EBinaryKind.NotEqual: writer.Write(" != "); break;

            case EBinaryKind.GreaterThanOrEqual: writer.Write(" >= "); break;

            case EBinaryKind.GreaterThan: writer.Write(" > "); break;

            case EBinaryKind.LessThan: writer.Write(" < "); break;

            case EBinaryKind.LessThanOrEqual: writer.Write(" <= "); break;
            }
            binary.Right.WriteSql(writer);
        }