public CaseExpression(TableAlias alias, IDbExpression test, IDbExpression defaultResult, params CaseTestExpression[] caseTests) : base(alias) { Test = test; DefaultResult = defaultResult; CaseTests = caseTests; }
public IDbCommand Parse( IDbExpression expression ) { var templateExpression = expression as TemplateExpression; if ( templateExpression != null ) return ParseTemplate( templateExpression ); throw new NotSupportedException(); }
public virtual string Render(IDbExpression expression) { tables.Clear(); alias.Clear(); using (writer = new System.IO.StringWriter()) { Visit(expression); return writer.GetStringBuilder().ToString(); } }
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); }
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(); }
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; }
public Not(TableAlias alias, IDbExpression expression) : base(UnaryExpressionType.Not, (Expression)expression) { Alias = alias; }
/// <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; } }
/// <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; } }
public static IfStatement If(IDbExpression condition, IDbStatement then, IDbStatement @else) { return new IfStatement(condition, then, @else); }
public static IfStatement If(IDbExpression condition, IDbStatement then) { return If(condition, then); }
public IfStatement(IDbExpression condition, IDbStatement then, IDbStatement @else) { this.Condition = condition; this.Then = then; this.Else = @else; }
public IDbCommand Parse( IDbExpression expression ) { throw new NotImplementedException(); }
/// <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 ); }
/// <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; } }
public static Not Not(IDbExpression booleanToBeInversed) { return new Not(booleanToBeInversed); }
/// <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; } }
internal IAliasedExpression Update(Not item, IDbExpression expression) { if (item.Expression != expression) return new Not(expression); return item; }
/// <summary> /// 创建 DbCommand 对象 /// </summary> /// <param name="expression">查询表达式</param> /// <returns>DbCommand 对象</returns> protected virtual IDbCommand CreateCommand( IDbExpression expression ) { var parser = GetExpressionParser(); return parser.Parse( expression ); }
public Not(IDbExpression expression) : this(null, expression) { }