Beispiel #1
0
 public CaseExpression(TableAlias alias, IDbExpression test, IDbExpression defaultResult, params CaseTestExpression[] caseTests)
     : base(alias)
 {
     Test = test;
     DefaultResult = defaultResult;
     CaseTests = caseTests;
 }
Beispiel #2
0
            public IDbCommand Parse( IDbExpression expression )
            {
                var templateExpression = expression as TemplateExpression;
                if ( templateExpression != null )
                  return ParseTemplate( templateExpression );

                throw new NotSupportedException();
            }
Beispiel #3
0
 public virtual string Render(IDbExpression expression)
 {
     tables.Clear();
     alias.Clear();
     using (writer = new System.IO.StringWriter())
     {
         Visit(expression);
         return writer.GetStringBuilder().ToString();
     }
 }
Beispiel #4
0
        public virtual BangoCommand GetSearchCommand(SearchScenario scenario, DbConnect con, BangoCommand cmd, DynamicDictionary data_param, string selectClause, string orderByClause, int page = -1, int pageSize = 20, bool count = false, string tableAlias = null, string scenarioOthers = null)
        {
            TableDetailAttribute tableDetail = _model.GetTableDetail();
            //clear the params whic are empty or null
            List <string> keys = new List <string>(data_param.KeyList.Cast <String>());

            foreach (string key in keys)
            {
                object value = data_param.GetValue(key);
                if (value == null || data_param.GetValueAsString(key).Length == 0)
                {
                    data_param.Remove(key);
                }
            }

            //BangoCommand cmd = GetSearchCommandTemplate(selectClause, count, tableAlias);
            //cmd.Sql.AppendLine("FROM " + model.GetTableName());
            IDbExpression dbExp = App.Container.GetInstance <IDbExpression>();

            if (data_param.GetCount() == 0)
            {
                return(cmd);
            }

            string append = DbServiceUtility.GetTableAliasForColumn(tableAlias);

            if (!(scenario == SearchScenario.TreeNode && count == false))
            {
                //check & adding delete flag check sql
                DbServiceUtility.BindDeleteParameter(cmd, _model, tableAlias);

                if (CheckClientID)
                {
                    DbServiceUtility.BindClientIdParameter(cmd, _model, tableAlias, DisplayMasterDataFromSystem);
                }

                //add remaining default search criteria

                cmd = BeforeBindingParameter(scenario, con, cmd, data_param, count, tableAlias);
                cmd = DbServiceUtility.BindParameters(cmd, _model, data_param, tableAlias);
                cmd = AfterBindingParameter(scenario, con, cmd, data_param, count, tableAlias);

                //check & adding order by clause
                if (count == false)
                {
                    cmd = BeforeBindingOrderBy(scenario, con, cmd, data_param, count, tableAlias);
                    cmd = DbServiceUtility.BindOrderBy(cmd, orderByClause);
                    cmd = AfterBindingOrderBy(scenario, con, cmd, data_param, count, tableAlias);
                    cmd = DbServiceUtility.BindPagination(cmd, page, pageSize);
                }
            }
            return(cmd);
        }
Beispiel #5
0
 public virtual InsertStatement Update(InsertStatement item, TableExpression table, KeyValuePair<ColumnExpression, NLinq.Expressions.Expression>[] original_values, KeyValuePair<ColumnExpression, NLinq.Expressions.Expression>[] values, IDbExpression select)
 {
     if (item.Select != select)
         return new InsertStatement(table, (SelectStatement)select);
     if (original_values != values)
     {
         IDictionary<ColumnExpression, NLinq.Expressions.Expression> dictValues = new Dictionary<ColumnExpression, NLinq.Expressions.Expression>();
         foreach (KeyValuePair<ColumnExpression, NLinq.Expressions.Expression> kvp in values)
             dictValues.Add(kvp);
         return new InsertStatement(table, dictValues);
     }
     return item;
 }
        /// <summary>
        /// 解析查询表达式
        /// </summary>
        /// <param name="expression">查询表达式</param>
        /// <returns>解析后创建的命令对象</returns>
        public IDbCommand Parse( IDbExpression expression )
        {
            var template = expression as TemplateExpression;
              if ( template != null )
            return ParseTemplate( template );

              var table = expression as TableExpression;
              if ( table != null )
            return ParseTable( table );

              var storedProcedure = expression as StoredProcedureExpression;

              if ( storedProcedure != null )
            return ParseStoredProcedure( storedProcedure );

              throw new NotSupportedException();
        }
Beispiel #7
0
 public virtual IAliasedExpression Update(CaseExpression item, Evaluant.NLinq.Expressions.Expression test, IDbExpression result, CaseTestExpression[] tests, TableAlias alias)
 {
     if (item.Test != test || item.DefaultResult != result || item.CaseTests != tests || item.Alias != alias)
         return new CaseExpression(alias, (IDbExpression)test, (IDbExpression)result, tests);
     return item;
 }
Beispiel #8
0
 public Not(TableAlias alias, IDbExpression expression)
     : base(UnaryExpressionType.Not, (Expression)expression)
 {
     Alias = alias;
 }
Beispiel #9
0
        /// <summary>
        /// 执行查询,并返回首行首列
        /// </summary>
        /// <param name="expression">查询表达式</param>
        /// <returns>查询结果的首行首列</returns>
        public virtual object ExecuteScalar( IDbExpression expression )
        {
            IDbCommand command = CreateCommand( expression );
              try
              {
            OnCommandExecuting( this, command );
            var result = ExecuteScalar( command );
            OnCommandExecuted( this, command );

            return result;
              }
              catch ( DbException e )
              {
            OnError( this, e, command );
            throw;
              }
        }
Beispiel #10
0
        /// <summary>
        /// 执行查询,并返回首行
        /// </summary>
        /// <param name="expression">查询表达式</param>
        /// <returns>查询结果的首行</returns>
        public virtual DataRow ExecuteFirstRow( IDbExpression expression )
        {
            IDbCommand command = CreateCommand( expression );

              try
              {
            OnCommandExecuting( this, command );
            var result = ExecuteFirstRow( command );
            OnCommandExecuted( this, command );

            return result;
              }
              catch ( DbException e )
              {
            OnError( this, e, command );
            throw;
              }
        }
Beispiel #11
0
 public static IfStatement If(IDbExpression condition, IDbStatement then, IDbStatement @else)
 {
     return new IfStatement(condition, then, @else);
 }
Beispiel #12
0
 public static IfStatement If(IDbExpression condition, IDbStatement then)
 {
     return If(condition, then);
 }
Beispiel #13
0
 public IfStatement(IDbExpression condition, IDbStatement then, IDbStatement @else)
 {
     this.Condition = condition;
     this.Then = then;
     this.Else = @else;
 }
Beispiel #14
0
 public IDbCommand Parse( IDbExpression expression )
 {
     throw new NotImplementedException();
 }
Beispiel #15
0
 /// <summary>
 /// 查询数据库并将最后一个结果集填充动态对象列表
 /// </summary>
 /// <param name="dbUtility">DbUtility 实例</param>
 /// <param name="expression">查询表达式</param>
 /// <returns>实体集</returns>
 public static dynamic[] Dynamics( this DbUtility dbUtility, IDbExpression expression )
 {
     var data = dbUtility.ExecuteData( expression );
       return ToDynamics( data );
 }
Beispiel #16
0
        /// <summary>
        /// 执行查询,并返回第一个结果集
        /// </summary>
        /// <param name="expression">查询表达式</param>
        /// <returns>第一个结果集</returns>
        public virtual DataTable ExecuteData( IDbExpression expression )
        {
            var command = CreateCommand( expression );
              try
              {
            OnCommandExecuting( this, command );
            var result = ExecuteData( command );
            OnCommandExecuted( this, command );

            return result;
              }
              catch ( DbException e )
              {
            OnError( this, e, command );
            throw;
              }
        }
Beispiel #17
0
 public static Not Not(IDbExpression booleanToBeInversed)
 {
     return new Not(booleanToBeInversed);
 }
Beispiel #18
0
        /// <summary>
        /// 执行命令,并返回DataReader对象,请注意数据库连接将在DataReader关闭的同时关闭。
        /// </summary>
        /// <param name="expression">查询表达式</param>
        /// <returns></returns>
        public IDataReader ExecuteReader( IDbExpression expression )
        {
            IDbCommand command = CreateCommand( expression );

              try
              {
            return ExecuteReader( command );
              }
              catch ( DbException e )
              {
            OnError( this, e, command );
            throw;
              }
        }
Beispiel #19
0
 internal IAliasedExpression Update(Not item, IDbExpression expression)
 {
     if (item.Expression != expression)
         return new Not(expression);
     return item;
 }
Beispiel #20
0
 /// <summary>
 /// 创建 DbCommand 对象
 /// </summary>
 /// <param name="expression">查询表达式</param>
 /// <returns>DbCommand 对象</returns>
 protected virtual IDbCommand CreateCommand( IDbExpression expression )
 {
     var parser = GetExpressionParser();
       return parser.Parse( expression );
 }
Beispiel #21
0
 public Not(IDbExpression expression) : this(null, expression) { }