Exemplo n.º 1
0
 public DatasetSqlCompiler(
     ISqlCompiler compiler,
     IOptions <CompilerOptions> compOpts)
 {
     this.compiler        = compiler;
     this.compilerOptions = compOpts.Value;
 }
Exemplo n.º 2
0
 public DemographicSqlCompiler(
     ISqlCompiler compiler,
     IOptions <CompilerOptions> compOpts)
 {
     this.compiler        = compiler;
     this.compilerOptions = compOpts.Value;
 }
Exemplo n.º 3
0
 public ParallelPatientCohortService(
     ISqlCompiler compiler,
     PatientCountAggregator patientCountAggregator,
     IOptions <ClinDbOptions> clinOpts,
     ILogger <PatientCohortService> logger) : base(compiler, clinOpts, logger)
 {
     this.patientCountAggregator = patientCountAggregator;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new instance of <see cref="BatchPlanner"/>.
        /// </summary>
        /// <param name="compiler">The <see cref="ISqlCompiler"/>.</param>
        /// <param name="hydrator">The <see cref="Hydrator"/>.</param>
        public BatchPlanner(ISqlCompiler compiler, Hydrator hydrator)
        {
            _compiler = compiler ?? throw new ArgumentNullException(nameof(compiler));
            _hydrator = hydrator ?? throw new ArgumentNullException(nameof(hydrator));

            _objectShaper = new ObjectShaper(new SqlAstValidator());
            _arrayToConnectionConverter = new ArrayToConnectionConverter();
        }
Exemplo n.º 5
0
        public static IEnumerable <SqlStatement> Parse(IContext context, SqlQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            ISqlCompiler compiler = null;

            if (context != null)
            {
                compiler = context.ResolveService <ISqlCompiler>();
            }

            if (compiler == null)
            {
                compiler = new PlSqlCompiler();
            }

            try {
                var compileContext = new SqlCompileContext(context, query.Text);
                var result         = compiler.Compile(compileContext);
                if (result.HasErrors)
                {
                    var messages = new StringBuilder();
                    messages.AppendFormat("SqlParseException for '{0}'" + Environment.NewLine, query.Text);
                    foreach (var m in result.Messages)
                    {
                        messages.AppendFormat("Level: {0}", m.Level);
                        if (null != m.Location)
                        {
                            messages.AppendFormat(", Line: {0}, Column: {1}", m.Location.Line, m.Location.Column);
                        }
                        messages.AppendFormat(", Message: {0}", m.Text);
                        messages.AppendLine();
                    }

                    throw new FormatException(messages.ToString());
                }

                var statements = result.Statements;

                foreach (var statement in statements)
                {
                    if (statement != null)
                    {
                        statement.SetSource(query);
                    }
                }

                return(statements);
            } catch (Exception ex) {
                var messages = new StringBuilder();
                messages.AppendFormat("The input string '{0}'" + Environment.NewLine, query.Text);
                messages.AppendFormat(" cannot be parsed into SQL Statements, because of {0}" + Environment.NewLine, ex.ToString());
                throw new FormatException(messages.ToString(), ex);
            }
        }
Exemplo n.º 6
0
 protected PatientCohortService(
     ISqlCompiler compiler,
     IOptions <ClinDbOptions> clinOpts,
     ILogger <PatientCohortService> logger)
 {
     this.compiler = compiler;
     clinDbOptions = clinOpts.Value;
     log           = logger;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a new instance of <see cref="JoinMonsterExecuter"/>.
        /// </summary>
        /// <param name="converter">The <see cref="QueryToSqlConverter"/>.</param>
        /// <param name="compiler">The <see cref="ISqlCompiler"/>.</param>
        /// <param name="batchPlanner">The <see cref="IBatchPlanner"/>.</param>
        /// <param name="hydrator">The <see cref="Hydrator"/>.</param>
        public JoinMonsterExecuter(QueryToSqlConverter converter, ISqlCompiler compiler, IBatchPlanner batchPlanner, Hydrator hydrator)
        {
            _converter    = converter ?? throw new ArgumentNullException(nameof(converter));
            _compiler     = compiler ?? throw new ArgumentNullException(nameof(compiler));
            _batchPlanner = batchPlanner ?? throw new ArgumentNullException(nameof(batchPlanner));
            _hydrator     = hydrator ?? throw new ArgumentNullException(nameof(hydrator));

            _objectShaper = new ObjectShaper(new SqlAstValidator());
            _arrayToConnectionConverter = new ArrayToConnectionConverter();
        }
Exemplo n.º 8
0
        private static XSqlCommand GetCommand(ISqlCompiler Compiler, BaseSql Sql, string Bracket, string ParamPrefix)
        {
            var Params = new List <XSqlCommandParam>();
            var ret    = new XSqlCommand
            {
                CommandText = Sql.ToSQLString(Bracket, ParamPrefix, Params, Compiler)
            };

            ret.Params = Params;
            var selectFields = new List <string>();


            return(ret);
        }
Exemplo n.º 9
0
 public string ToSQLString(string Quotes, string paramPrefix, List <XSqlCommandParam> Params, ISqlCompiler compiler)
 {
     if (Params == null)
     {
         return(Name + "(" + string.Join(",", Arguments.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler))) + ")");
     }
     else
     {
         return(compiler.Compile(this.Clone(), Params));
     }
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 public PiecesCompiler(IEnumerable<IExpressionPiece> pieces, ISqlCompiler next)
 {
     _Next = next;
     _Pieces = pieces;
 }
Exemplo n.º 11
0
        void IServiceResolveContext.OnResolved(Type type, string name, object obj)
        {
            if (obj is ISqlCompiler) {
                sqlCompiler = (ISqlCompiler) obj;
            } else if (obj is IQueryPlanner) {
                queryPlanner = (IQueryPlanner) obj;
            }

            if (obj != null && obj is IConfigurable)
                ((IConfigurable)obj).Configure(Configuration);
        }
Exemplo n.º 12
0
 public static XSqlCommand GetCommand <T>(ISqlCompiler provider, IQueryable <T> sql)
 {
     return(GetCommand(provider, (BaseSql)sql, provider.GetBrackets(), provider.GetParamPrefix()));
 }
Exemplo n.º 13
0
 private static XSqlCommand GetCommand <T>(ISqlCompiler Compiler, IQueryable <T> Sql, string Bracket, string ParamPrefix)
 {
     return(GetCommand(Compiler, (BaseSql)Sql, Bracket, ParamPrefix));
 }
Exemplo n.º 14
0
 public InTableCompiler(ITable table, IExpressionPiece piece, ISqlCompiler compiler)
 {
     _Table = table;
     _Piece = piece;
     _Compiler = compiler;
 }
Exemplo n.º 15
0
 public BetweenCompiler(ISqlCompiler parameterCompiler, ISqlCompiler secondParameter)
 {
     _SecondParameter = secondParameter;
     _FirstParameter = parameterCompiler;
 }
Exemplo n.º 16
0
        //[System.Diagnostics.DebuggerStepThrough]
        public string ToSQLString(string Quotes, string paramPrefix, List <XSqlCommandParam> Params, ISqlCompiler compiler)
        {
            var ret = "";

            if (this.source == null)
            {
                if (SelectedFields == null || this.SelectedFields.Count == 0)
                {
                    if (this.filter == null)
                    {
                        ret = "select * From " + this.GetFromClause(Quotes, paramPrefix, Params, compiler);
                    }
                    else
                    {
                        ret = "select * From " + this.GetFromClause(Quotes, paramPrefix, Params, compiler) + " where " + this.filter.ToSQLString(Quotes, paramPrefix, Params, compiler);
                    }
                }
                else
                {
                    if (this.filter == null)
                    {
                        ret = "select " + string.Join(",", SelectedFields.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler))) + " From " + this.GetFromClause(Quotes, paramPrefix, Params, compiler);
                    }
                    else
                    {
                        ret = "select " + string.Join(",", SelectedFields.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler))) + " From " + this.GetFromClause(Quotes, paramPrefix, Params, compiler) + " where " + this.filter.ToSQLString(Quotes, paramPrefix, Params, compiler);
                    }
                }
            }
            else
            {
                if (SelectedFields == null || this.SelectedFields.Count == 0)
                {
                    if (this.filter == null)
                    {
                        ret = "select * From " + this.source.ToSQLString(Quotes, paramPrefix, Params, compiler);
                    }
                    else
                    {
                        ret = "select * From " + this.source.ToSQLString(Quotes, paramPrefix, Params, compiler) + " where " + this.filter.ToSQLString(Quotes, paramPrefix, Params, compiler);
                    }
                }
                else
                {
                    if (this.filter == null)
                    {
                        ret = "select " + string.Join(",", SelectedFields.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler))) + " From " + this.source.ToSQLString(Quotes, paramPrefix, Params, compiler);
                    }
                    else
                    {
                        ret = "select " + string.Join(",", SelectedFields.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler))) + " From " + this.source.ToSQLString(Quotes, paramPrefix, Params, compiler) + " where " + this.filter.ToSQLString(Quotes, paramPrefix, Params, compiler);
                    }
                }
            }
            if (this.GroupByFields != null)
            {
                ret += " Group By " + string.Join(",", this.GroupByFields.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler)));
            }
            if (ret != "")
            {
                return(ret);
            }
            throw new NotImplementedException();
        }
Exemplo n.º 17
0
 public SubQueryCompiler(ITable table, IEnumerable<IExpressionPiece> pieces, ISqlCompiler next)
 {
     var expressionPieces = pieces as List<IExpressionPiece> ?? pieces.ToList();
     _Compiler = new PiecesCompiler(expressionPieces,
         new InTableCompiler(table, expressionPieces.Last(), next));
 }
Exemplo n.º 18
0
 public LikeCompiler(ISqlCompiler firstParameter, WildCard token = WildCard.Both)
 {
     _Token = token;
     _FirstParameter = firstParameter;
 }
Exemplo n.º 19
0
 //[System.Diagnostics.DebuggerStepThrough]
 public string ToSQLString(string Quotes, string paramPrefix, List <XSqlCommandParam> Params, ISqlCompiler compiler)
 {
     if (this.Value != null)
     {
         return(this.Value.ToSQLString(Quotes, paramPrefix, Params));
     }
     else if (this.Field != null)
     {
         return(this.Field.ToSQLString(Quotes, paramPrefix));
     }
     else if (Op != null)
     {
         return("(" + Left.ToSQLString(Quotes, paramPrefix, Params, compiler) + ")" + Op + "(" + Right.ToSQLString(Quotes, paramPrefix, Params, compiler) + ") " + ((this.AliasName != null) ? string.Format(string.Format("{0}{{0}}{1}", Quotes[0], Quotes[1]), this.AliasName):""));
     }
     else if (Callee != null)
     {
         if (Callee.AliasName == null)
         {
             return(Callee.ToSQLString(Quotes, paramPrefix, Params, compiler));
         }
         else
         {
             return(Callee.ToSQLString(Quotes, paramPrefix, Params, compiler) + " " + string.Format(string.Format("{0}{{0}}{1}", Quotes[0], Quotes[1]), this.AliasName));
         }
     }
     return("Unknown");
 }
 public static ISystemBuilder UseSqlCompiler(this ISystemBuilder builder, ISqlCompiler compiler)
 {
     return(builder.Use <ISqlCompiler>(options => options.With(compiler).InSystemScope()));
 }
Exemplo n.º 21
0
 public CtePatientCohortService(
     ISqlCompiler compiler,
     IOptions <ClinDbOptions> clinOpts,
     ILogger <PatientCohortService> logger) : base(compiler, clinOpts, logger)
 {
 }
Exemplo n.º 22
0
 private string GetFromClause(string quotes, string paramPrefix, List <XSqlCommandParam> Params, ISqlCompiler compiler)
 {
     if (this.schema != null)
     {
         return(string.Format(string.Format("{0}{{0}}{1}.{0}{{1}}{1}", quotes[0], quotes[1]), this.schema, this.table));
     }
     else
     {
         return(string.Format(string.Format("{0}{{0}}{1}", quotes[0], quotes[1]), this.table));
     }
 }
Exemplo n.º 23
0
        public string ToSQLString(string Quotes, string paramPrefix, List <XSqlCommandParam> Params, ISqlCompiler compiler)
        {
            var ret = "";

            if (this.LeftSource != null && this.RightSource != null)
            {
                if (this.JoinExpr == null)
                {
                    ret = string.Join(",", new string[] { this.LeftSource.ToSQLString(Quotes, paramPrefix, Params, compiler), this.RightSource.ToSQLString(Quotes, paramPrefix, Params, compiler) });
                }
                else
                {
                    ret = this.LeftSource.ToSQLString(Quotes, paramPrefix, Params, compiler) + " " + this.JoinType + " join " + this.RightSource.ToSQLString(Quotes, paramPrefix, Params, compiler) + " on " + this.JoinExpr.ToSQLString(Quotes, paramPrefix, Params, compiler);
                }
            }
            if (Source != null)
            {
                if (Fields != null)
                {
                    ret = string.Join(",", Fields.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler))) + " from " + Source.ToSQLString(Quotes, paramPrefix, Params, compiler);
                    ;
                }
                else
                {
                    ret = Source.ToSQLString(Quotes, paramPrefix, Params, compiler);
                }
            }
            else if (Schema != null)
            {
                if (Fields != null)
                {
                    ret = string.Join(",", Fields.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler))) + " from " +
                          string.Format(string.Format("{0}{{0}}{1}.{0}{{1}}{1}", Quotes[0], Quotes[1]), Schema, Table);
                    ;
                }
                else
                {
                    ret = string.Format(string.Format("{0}{{0}}{1}.{0}{{1}}{1}", Quotes[0], Quotes[1]), Schema, Table);
                    ret = ret + " " + string.Format(string.Format("{0}{{0}}{1}", Quotes[0], Quotes[1]), Alias);
                    return(ret);
                }
            }
            else if (Table != null)
            {
                if (Fields != null)
                {
                    ret = string.Join(",", Fields.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler))) + " from " +
                          string.Format(string.Format("{0}{{0}}{1}", Quotes[0], Quotes[1]), Table);
                }
                else
                {
                    ret = string.Format(string.Format("{0}{{0}}{1}", Quotes[0], Quotes[1]), Table);
                }
            }
            if (this.filter != null)
            {
                ret += " where " + this.filter.ToSQLString(Quotes, paramPrefix, Params, compiler);
            }
            ret = ret + string.Format(string.Format("{0}{{0}}{1}", Quotes[0], Quotes[1]), Alias);
            if (this.Fields != null)
            {
                ret = "Select " + string.Join(",", this.Fields.Select(p => p.ToSQLString(Quotes, paramPrefix, Params, compiler))) + " " +
                      ret;
            }
            return("(" + ret + ")");
        }