Exemple #1
0
        /// <summary>
        /// Write the query to the <paramref name="writer"/> as SQL
        /// </summary>
        /// <param name="writer">The writer</param>
        /// <param name="settings">The settings.</param>
        public void ToArasSql(TextWriter writer, IAmlSqlWriterSettings settings)
        {
            var visitor = new ArasSqlServerVisitor(writer, settings);
            var clone   = new CloneVisitor().WithPropertyMapper(p =>
            {
                var table = p.Table;
                table.TryFillName(settings);
                if (string.IsNullOrEmpty(table.Type))
                {
                    return(IgnoreNode.Instance);
                }
                var props = settings.GetProperties(table.Type);
                if (props.Count < 1)
                {
                    return(p);
                }
                if (!props.TryGetValue(p.Name, out var propDefn))
                {
                    return(IgnoreNode.Instance);
                }
                if (propDefn.DataType().Value == "foreign")
                {
                    return(table.GetProperty(propDefn));
                }
                return(p);
            }).Clone(this);

            visitor.Visit(clone);
        }
Exemple #2
0
        private string ToBaseSql(QueryItem query, IAmlSqlWriterSettings settings)
        {
            using (var writer = new StringWriter())
            {
                var visitor = new SqlServerVisitor(writer, settings);
                var clone   = new CloneVisitor().WithPropertyMapper(p =>
                {
                    var table = p.Table;
                    table.TryFillName(settings);
                    if (string.IsNullOrEmpty(table.Type))
                    {
                        return(IgnoreNode.Instance);
                    }
                    var props = settings.GetProperties(table.Type);
                    if (props.Count < 1)
                    {
                        return(p);
                    }
                    if (!props.TryGetValue(p.Name, out var propDefn))
                    {
                        return(IgnoreNode.Instance);
                    }
                    if (propDefn.DataType().Value == "foreign")
                    {
                        return(table.GetProperty(propDefn));
                    }
                    return(p);
                }).Clone(query);
                visitor.Visit(clone);

                writer.Flush();
                return(writer.ToString());
            }
        }