/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> public virtual void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { if (tag.IsPrependAvailable) { if (bodyContent.ToString().Trim().Length > 0) { if (ctx.IsOverridePrepend && tag == ctx.FirstNonDynamicTagWithPrepend) { ctx.IsOverridePrepend = false; } else { bodyContent.Insert(0, tag.Prepend); } } else { if (ctx.FirstNonDynamicTagWithPrepend != null) { ctx.FirstNonDynamicTagWithPrepend = null; ctx.IsOverridePrepend = true; } } } }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (parameterObject == null) { return(true); } var baseTag = ((BaseTag)tag); object value; if (!string.IsNullOrEmpty(baseTag.BindName)) { if (!string.IsNullOrEmpty(baseTag.Property)) { throw new DataMapperException("Error comparing in conditional fragment. Please specify a \"bindName\" or \"property\", not both."); } value = GetBindValue(ctx, baseTag.BindName, parameterObject); } else if (!string.IsNullOrEmpty(baseTag.Property)) { // changed to enable references to current iterate items to also be catered for. value = GetMemberPropertyValue(ctx, baseTag, parameterObject); } else { value = parameterObject; } return(value == null); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate == null) { string propertyName = ((BaseTag)tag).Property; object collection; if (propertyName != null && propertyName.Length > 0) { collection = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory); } else { collection = parameterObject; } iterate = new IterateContext(collection); ctx.AddAttribute(tag, iterate); } if (iterate != null && iterate.HasNext) { return(BaseTagHandler.INCLUDE_BODY); } else { return(BaseTagHandler.SKIP_BODY); } }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (parameterObject == null) { return(true); } string propertyName = ((BaseTag)tag).Property; object value = null; if (!string.IsNullOrEmpty(propertyName)) { value = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory); } else { value = parameterObject; } if (value is ICollection) { return((value == null) || (((ICollection)value).Count < 1)); } if (value != null && typeof(Array).IsAssignableFrom(value.GetType())) //value.GetType().IsArray { return(((Array)value).GetLength(0) == 0); } return((value == null) || (Convert.ToString(value).Equals(""))); }
/// <summary> /// /// </summary> /// <typeparam name="Result"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="tag"></param> /// <param name="parameter"></param> /// <returns></returns> public virtual IEnumerable <Result> QueryForEnumerable <Result, T>(SqlTag tag, EasySqlParameter <T> parameter) { var format = tag.Format(parameter); var temp = this.SqlExecuter.QueryForEnumerable <Result>(format.ToString(), CommandType.Text, format.Parameters.ToArray()); return(temp == null ? new Result[0] : temp); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate == null) { string propertyName = ((BaseTag)tag).Property; object collection; if (!string.IsNullOrEmpty(propertyName)) { collection = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory); } else { collection = parameterObject; } iterate = new IterateContext(collection); ctx.AddAttribute(tag, iterate); } if (iterate.HasNext) { return(INCLUDE_BODY); } return(SKIP_BODY); }
public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (parameterObject != null) { string property = ((BaseTag)tag).Property; object obj2 = null; if ((property != null) && (property.Length > 0)) { obj2 = ObjectProbe.GetMemberValue(parameterObject, property, base.AccessorFactory); } else { obj2 = parameterObject; } if (obj2 is ICollection) { if (obj2 != null) { return(((ICollection)obj2).Count < 1); } return(true); } if ((obj2 != null) && typeof(Array).IsAssignableFrom(obj2.GetType())) { return(((Array)obj2).GetLength(0) == 0); } if (obj2 != null) { return(Convert.ToString(obj2).Equals("")); } } return(true); }
public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) { IterateContext attribute = (IterateContext)ctx.GetAttribute(tag); if (attribute == null) { object obj2; string property = ((BaseTag)tag).Property; if ((property != null) && (property.Length > 0)) { obj2 = ObjectProbe.GetMemberValue(parameterObject, property, base.AccessorFactory); } else { obj2 = parameterObject; } attribute = new IterateContext(obj2); ctx.AddAttribute(tag, attribute); } if ((attribute != null) && attribute.HasNext) { return(1); } return(0); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject) { if (IsCondition(ctx, tag, parameterObject)) { return(INCLUDE_BODY); } return(SKIP_BODY); }
public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (parameterObject == null) { return(false); } return(ObjectProbe.HasReadableProperty(parameterObject, ((BaseTag)tag).Property)); }
public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (this.IsCondition(ctx, tag, parameterObject)) { return(1); } return(0); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject) { ctx.FirstNonDynamicTagWithPrepend = null; if (tag.IsPrependAvailable) { ctx.IsOverridePrepend = true; } return(BaseTagHandler.INCLUDE_BODY); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> public override void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate.IsFirst) { base.DoPrepend(ctx, tag, parameterObject, bodyContent); } }
public void CheckAssignFirstDynamicTagWithPrepend(SqlTag tag) { if (IsOverridePrepend && FirstNonDynamicTagWithPrepend == null && tag.IsPrependAvailable && !(tag.Handler is DynamicTagHandler)) { FirstNonDynamicTagWithPrepend = tag; } }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> /// <remarks> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Changed the index to check for. /// The "iterate" tag handler has been re-worked to ensure we read the next iterate context item /// before the child tag elements are processed. We need to do this to ensure that we can parse /// property expressions within tag elements nested within the iterate element. /// </remarks> public override void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { var iterate = (IterateContext)ctx.GetAttribute(tag); // because we move to the first item before we iterate, we need to check to see if this is the first item, by checking the Index = 1 and not 0. if (iterate.IsFirst) { base.DoPrepend(ctx, tag, parameterObject, bodyContent); } }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject) { if (IsCondition(ctx, tag, parameterObject)) { return(BaseTagHandler.INCLUDE_BODY); } else { return(BaseTagHandler.SKIP_BODY); } }
private static void InsertCode(ICodeBuilder codeBuilder, LoggingRelatedItemInfo info, string sqlResource, SqlTag<EntityLoggingInfo> tag) { string codeSnippet = Sql.Format(sqlResource, GetTempColumnNameOld(info), GetTempColumnNameNew(info), info.Table, SqlUtility.Identifier(info.Column), SqlUtility.QuoteText(info.Relation)); codeBuilder.InsertCode(codeSnippet, tag, info.Logging); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Enables one to be able to have sql text within an iterate element that references the current item as "[]." /// This is then parsed, along with any reflection path suffix to get the object instance the used is interested in. /// and add it to an attributes collection for later use. public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) { var iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate == null) { var baseTag = (BaseTag)tag; object collection; if (!string.IsNullOrEmpty(baseTag.Property)) { // this will either leave the property name as it is, or if it starts with "[].", the // current iterate context item value will be used, with the rest of the property name // walked to determine the field/property to get the value from. collection = _tagPropertyProbe.GetMemberPropertyValue(ctx, baseTag, parameterObject); } else { collection = parameterObject; } iterate = new IterateContext(collection); ctx.AddAttribute(tag, iterate); // if there is another item in the iterate array, then we need to include the body. if (iterate.MoveNext()) { return(INCLUDE_BODY); } iterate.IsCompleted = true; return(SKIP_BODY); } if (iterate.IsCompleted) { // reset the context to cater for nested iterations. ctx.RemoveAttibute(tag); // now re-process the tag which will re-add the now modified tag element back to the attributes collection. return(DoStartFragment(ctx, tag, parameterObject)); } else if (iterate.HasNext || iterate.IsLast) { if (iterate.MoveNext()) { return(INCLUDE_BODY); } } return(SKIP_BODY); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="sqlTag"></param> /// <param name="parameterObject"></param> /// <returns></returns> protected long Compare(SqlTagContext ctx, SqlTag sqlTag, object parameterObject) { var tag = (Conditional)sqlTag; string propertyName = tag.Property; string literal = tag.Literal; string comparePropertyName = tag.CompareProperty; string compareValue = tag.CompareValue; object value1 = null; Type type = null; if (propertyName != null && propertyName.Length > 0) { // check to see if we are a list //if (fpropertyName.StartsWith("[")) //{ //} value1 = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory); type = value1.GetType(); } else if (!String.IsNullOrEmpty(literal)) { value1 = literal; type = value1.GetType(); } else { value1 = parameterObject; if (value1 != null) { type = parameterObject.GetType(); } else { type = typeof(object); } } if (comparePropertyName != null && comparePropertyName.Length > 0) { object value2 = ObjectProbe.GetMemberValue(parameterObject, comparePropertyName, AccessorFactory); return(CompareValues(type, value1, value2)); } else if (!String.IsNullOrEmpty(compareValue)) { return(CompareValues(type, value1, compareValue)); } else { throw new DataMapperException("Error comparing in conditional fragment. Uknown 'compare to' values."); } }
/// <summary> /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> /// <remarks> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Builds full property name and checks to see if the property is readable. /// Not sure why it doesn't also cater for class Fields? /// </remarks> public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (parameterObject == null) { return(false); } var baseTag = (BaseTag)tag; // build property full name from property name - specifically handles references to current iterate item, i.e. "[]." var propertyFullName = ctx.ReplaceIterateCurrentProperty(baseTag); return(ObjectProbe.HasReadableProperty(parameterObject, propertyFullName)); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> /// <returns></returns> public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate.MoveNext()) { string propertyName = ((BaseTag)tag).Property; if (propertyName == null) { propertyName = ""; } string find = propertyName + "[]"; string replace = propertyName + "[" + iterate.Index + "]"; //Parameter-index-Dynamic Replace(bodyContent, find, replace); if (iterate.IsFirst) { string open = ((Iterate)tag).Open; if (open != null) { bodyContent.Insert(0, open); bodyContent.Insert(0, ' '); } } if (!iterate.IsLast) { string conjunction = ((Iterate)tag).Conjunction; if (conjunction != null) { bodyContent.Append(conjunction); bodyContent.Append(' '); } } if (iterate.IsLast) { string close = ((Iterate)tag).Close; if (close != null) { bodyContent.Append(close); } } return(BaseTagHandler.REPEAT_BODY); } else { return(BaseTagHandler.INCLUDE_BODY); } }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="sqlTag"></param> /// <param name="parameterObject"></param> /// <returns></returns> protected long Compare(SqlTagContext ctx, SqlTag sqlTag, object parameterObject) { Conditional tag = (Conditional)sqlTag; string bindName = tag.BindName; string propertyName = tag.Property; string comparePropertyName = tag.CompareProperty; string compareValue = tag.CompareValue; object value1 = null; Type type = null; if (!string.IsNullOrEmpty(bindName)) { if (!string.IsNullOrEmpty(propertyName)) { throw new DataMapperException("Error comparing in conditional fragment. Please specify a \"bindName\" or \"property\", not both."); } value1 = GetBindValue(ctx, bindName, parameterObject); type = value1.GetType(); } else if (!string.IsNullOrEmpty(propertyName)) { value1 = GetMemberPropertyValue(ctx, tag, parameterObject); type = value1.GetType(); } else { value1 = parameterObject; if (value1 != null) { type = parameterObject.GetType(); } else { type = typeof(object); } } if (!string.IsNullOrEmpty(comparePropertyName)) { object value2 = GetMemberComparePropertyValue(ctx, tag, parameterObject); return(CompareValues(type, value1, value2)); } if (!string.IsNullOrEmpty(compareValue)) { return(CompareValues(type, value1, compareValue)); } throw new DataMapperException("Error comparing in conditional fragment. Unknown 'compare to' values."); }
public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext attribute = (IterateContext)ctx.GetAttribute(tag); if (!attribute.MoveNext()) { return(1); } string property = ((BaseTag)tag).Property; if (property == null) { property = ""; } string find = property + "[]"; string replace = string.Concat(new object[] { property, "[", attribute.Index, "]" }); Replace(bodyContent, find, replace); if (attribute.IsFirst) { string open = ((Iterate)tag).Open; if (open != null) { bodyContent.Insert(0, open); bodyContent.Insert(0, ' '); } } if (!attribute.IsLast) { string conjunction = ((Iterate)tag).Conjunction; if (conjunction != null) { bodyContent.Append(conjunction); bodyContent.Append(' '); } } if (attribute.IsLast) { string close = ((Iterate)tag).Close; if (close != null) { bodyContent.Append(close); } } return(2); }
internal static SqlTag SelectSqlTag(string sql, IDao dao) { var sqltag = new SqlTag() { CommandType = null, Id = NewId.GenerateString(NewId.StringLength.L24), IndentedOnNameSpace = false, IndentedOnSqlTag = false, NameSpace = null, Labels = new List <ILabel>(1), }; var label = sqltag.ReadTextNode(sql, new Serialization.Json.ThunderWriter(sql.Length), new Serialization.Json.SequenceStringReader("1"), dao.SqlExecuter.GetParameterPrefix()); sqltag.Labels.Add(new DecoratedTextLabel(label)); return(sqltag); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tag"></param> /// <param name="parameter"></param> /// <param name="callmode"></param> /// <returns></returns> public virtual object Call <T>(SqlTag tag, EasySqlParameter <T> parameter, CallMode callmode) { var format = tag.Format(parameter); if ((callmode & CallMode.ExecuteScalar) == CallMode.ExecuteScalar) { if ((callmode & CallMode.CommandText) == CallMode.CommandText) { return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.Text, format.Parameters.ToArray())); } if ((callmode & CallMode.CommandStoredProcedure) == CallMode.CommandStoredProcedure) { return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.StoredProcedure, format.Parameters.ToArray())); } if ((callmode & CallMode.CommandTableDirect) == CallMode.CommandTableDirect) { return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.TableDirect, format.Parameters.ToArray())); } return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.Text, format.Parameters.ToArray())); } if ((callmode & CallMode.ExecuteNonQuery) == CallMode.ExecuteNonQuery) { if ((callmode & CallMode.CommandText) == CallMode.CommandText) { return(this.SqlExecuter.ExecuteNonQuery(format.ToString(), CommandType.Text, format.Parameters.ToArray())); } if ((callmode & CallMode.CommandStoredProcedure) == CallMode.CommandStoredProcedure) { return(this.SqlExecuter.ExecuteNonQuery(format.ToString(), CommandType.StoredProcedure, format.Parameters.ToArray())); } if ((callmode & CallMode.CommandTableDirect) == CallMode.CommandTableDirect) { return(this.SqlExecuter.ExecuteNonQuery(format.ToString(), CommandType.TableDirect, format.Parameters.ToArray())); } return(this.SqlExecuter.ExecuteNonQuery(format.ToString(), CommandType.Text, format.Parameters.ToArray())); } return(this.SqlExecuter.ExecuteScalar(format.ToString(), CommandType.Text, format.Parameters.ToArray())); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (parameterObject == null) { return(true); } string propertyName = ((BaseTag)tag).Property; object value; if (!string.IsNullOrEmpty(propertyName)) { value = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory); } else { value = parameterObject; } return(value == null); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (parameterObject == null) { return(true); } var baseTag = ((BaseTag)tag); string bindName = baseTag.BindName; string propertyName = baseTag.Property; object value = null; if (!string.IsNullOrEmpty(bindName)) { if (!string.IsNullOrEmpty(propertyName)) { throw new DataMapperException("Error comparing in conditional fragment. Please specify a \"bindName\" or \"property\", not both."); } value = GetBindValue(ctx, bindName, parameterObject); } else if (!string.IsNullOrEmpty(propertyName)) { value = GetMemberPropertyValue(ctx, baseTag, parameterObject); //value = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory); } else { value = parameterObject; } if (value is ICollection) { return((value == null) || (((ICollection)value).Count < 1)); } if (value != null && typeof(Array).IsAssignableFrom(value.GetType())) //value.GetType().IsArray { return(((Array)value).GetLength(0) == 0); } return((value == null) || (Convert.ToString(value).Equals(""))); }
public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { object obj2; if (parameterObject == null) { return(true); } string property = ((BaseTag)tag).Property; if ((property != null) && (property.Length > 0)) { obj2 = ObjectProbe.GetMemberValue(parameterObject, property, base.AccessorFactory); } else { obj2 = parameterObject; } return(obj2 == null); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="sqlTag"></param> /// <param name="parameterObject"></param> /// <returns></returns> protected long Compare(SqlTagContext ctx, SqlTag sqlTag, object parameterObject) { Conditional tag = (Conditional)sqlTag; string propertyName = tag.Property; string comparePropertyName = tag.CompareProperty; string compareValue = tag.CompareValue; object value1 = null; Type type = null; if (propertyName != null && propertyName.Length > 0) { value1 = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory); type = value1.GetType(); } else { value1 = parameterObject; if (value1 != null) { type = parameterObject.GetType(); } else { type = typeof(object); } } if (comparePropertyName != null && comparePropertyName.Length > 0) { object value2 = ObjectProbe.GetMemberValue(parameterObject, comparePropertyName, this.AccessorFactory); return(CompareValues(type, value1, value2)); } else if (compareValue != null && compareValue != "") { return(CompareValues(type, value1, compareValue)); } else { throw new DataMapperException("Error comparing in conditional fragment. Uknown 'compare to' values."); } }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <returns></returns> public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (parameterObject == null) { return(true); } else { string propertyName = ((BaseTag)tag).Property; object value; if (propertyName != null && propertyName.Length > 0) { value = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory); } else { value = parameterObject; } return(value == null); } }
protected long Compare(SqlTagContext ctx, SqlTag sqlTag, object parameterObject) { Conditional conditional = (Conditional)sqlTag; string property = conditional.Property; string compareProperty = conditional.CompareProperty; string compareValue = conditional.CompareValue; object obj2 = null; Type type = null; if ((property != null) && (property.Length > 0)) { obj2 = ObjectProbe.GetMemberValue(parameterObject, property, base.AccessorFactory); type = obj2.GetType(); } else { obj2 = parameterObject; if (obj2 != null) { type = parameterObject.GetType(); } else { type = typeof(object); } } if ((compareProperty != null) && (compareProperty.Length > 0)) { object obj3 = ObjectProbe.GetMemberValue(parameterObject, compareProperty, base.AccessorFactory); return(this.CompareValues(type, obj2, obj3)); } switch (compareValue) { case null: case "": throw new DataMapperException("Error comparing in conditional fragment. Uknown 'compare to' values."); } return(this.CompareValues(type, obj2, compareValue)); }