protected virtual string BuildGroup(QueryGroupNode node) { // do not render empty group if (node.Nodes == null || node.Nodes.Count == 0) { return(null); } // if group contains only one node ignore group rendering logic if (node.Nodes.Count == 1) { return(BuildExpression(node.Nodes[0])); } var subNodes = new List <string>(); foreach (QueryNode childNode in node.Nodes) { string childNodeExpression = BuildExpression(childNode); if (childNodeExpression != null) { subNodes.Add("(" + childNodeExpression + ")"); } } return(String.Join( " " + node.GroupType.ToString() + " ", subNodes.ToArray())); }
/// <summary> /// Compose OR group node with specified child nodes /// </summary> /// <param name="nodes">child nodes</param> /// <returns>QueryGroupNode of OR type</returns> public static QueryGroupNode Or(params QueryNode[] nodes) { var orGrp = new QueryGroupNode(QueryGroupNodeType.Or); orGrp._Nodes.AddRange(nodes); return(orGrp); }
/// <summary> /// Compose AND group node with specified child nodes /// </summary> /// <param name="nodes">child nodes</param> /// <returns>QueryGroupNode of AND type</returns> public static QueryGroupNode And(params QueryNode[] nodes) { var andGrp = new QueryGroupNode(QueryGroupNodeType.And); andGrp._Nodes.AddRange(nodes); return(andGrp); }
public static QueryNode MapQValue(QueryNode qNode, Func <IQueryValue, IQueryValue> mapFunc) { if (qNode is QueryGroupNode) { var group = new QueryGroupNode((QueryGroupNode)qNode); for (int i = 0; i < group.Nodes.Count; i++) { group.Nodes[i] = MapQValue(group.Nodes[i], mapFunc); } return(group); } if (qNode is QueryConditionNode) { var origCndNode = (QueryConditionNode)qNode; var cndNode = new QueryConditionNode(origCndNode.Name, mapFunc(origCndNode.LValue), origCndNode.Condition, mapFunc(origCndNode.RValue)); return(cndNode); } if (qNode is QueryNegationNode) { var negNode = new QueryNegationNode((QueryNegationNode)qNode); for (int i = 0; i < negNode.Nodes.Count; i++) { negNode.Nodes[i] = MapQValue(negNode.Nodes[i], mapFunc); } return(negNode); } return(qNode); }
/// <summary> /// AND operator /// </summary> public static QueryGroupNode operator &(QueryNode node1, QueryNode node2) { QueryGroupNode res = new QueryGroupNode(QueryGroupNodeType.And); res.Nodes.Add(node1); res.Nodes.Add(node2); return(res); }
protected QueryNode ComposePkCondition(DataTable table, IDbSqlBuilder dbSqlBuilder, DataRowVersion rowValueVersion) { var pkCondition = new QueryGroupNode(QueryGroupNodeType.And); foreach (DataColumn col in table.PrimaryKey) { pkCondition.Nodes.Add( (QField)col.ColumnName == new QRawSql(dbSqlBuilder.BuildCommandParameter(col, rowValueVersion))); } return(pkCondition); }
protected QueryNode ComposePkCondition(T t) { var qcnd = new QueryGroupNode(QueryGroupNodeType.And); var ds = DbManager.CreateDataSet(TableName); foreach (DataColumn c in ds.Tables[TableName].PrimaryKey) { var pVal = ObjectMapper.GetFieldValue(t, c); qcnd.Nodes.Add(new QueryConditionNode((QField)c.ColumnName, Conditions.Equal, new QConst(pVal))); } return(qcnd); }
/// <summary> /// OR operator /// </summary> public static QueryGroupNode operator |(QueryGroupNode node1, QueryNode node2) { if (node1.GroupType == QueryGroupNodeType.Or) { node1.Nodes.Add(node2); return(node1); } QueryGroupNode res = new QueryGroupNode(QueryGroupNodeType.Or); res.Nodes.Add(node1); res.Nodes.Add(node2); return(res); }
protected QueryNode ComposePkCondition(DataTable tbl, params object[] pk) { QueryGroupNode grp = new QueryGroupNode(QueryGroupNodeType.And); if (tbl.PrimaryKey.Length != pk.Length) { throw new Exception("Invalid primary key"); } for (int i = 0; i < tbl.PrimaryKey.Length; i++) { grp.Nodes.Add(new QueryConditionNode((QField)tbl.PrimaryKey[i].ColumnName, Conditions.Equal, new QConst(pk[i]))); } return(grp); }
/// <summary> /// Initializes a new instance of the QueryGroupNode that copies specified QueryGroupNode /// </summary> /// <param name="likeGroup">QueryGroupNode to copy from</param> public QueryGroupNode(QueryGroupNode likeGroup) : this(likeGroup.GroupType) { Name = likeGroup.Name; _Nodes.AddRange(likeGroup.Nodes); }