public override void Accept(ICommandContext ctx) { Object value = ctx.GetArg(_names[0]); Type type = (value != null ? value.GetType() : null); InternalValueAndType valueAndType = new InternalValueAndType(); valueAndType.TargetValue = value; valueAndType.TargetType = type; SetupValueAndType(valueAndType); if (_blockNullParameter && valueAndType.TargetValue == null) { ThrowBindOrEmbeddedParameterNullValueException(valueAndType); } if (!IsInScope()) { // Main Root // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // [UnderReview]: Should I make an original exception instead of this exception? // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // if (valueAndType.TargetValue != null && valueAndType.TargetValue.ToString().IndexOf("?") > -1) { // throw new org.seasar.framework.exception.SRuntimeException("EDAO0023"); // } ctx.AddSql(valueAndType.TargetValue.ToString()); } else { if (IsInScope() && typeof(System.Collections.IList).IsAssignableFrom(valueAndType.TargetType)) { System.Collections.IList list = valueAndType.TargetValue as System.Collections.IList; Array array = new Object[list.Count]; list.CopyTo(array, 0); EmbedArray(ctx, array); } else if (IsInScope() && valueAndType.TargetType.IsArray) { EmbedArray(ctx, valueAndType.TargetValue); } else { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // [UnderReview]: Should I make an original exception instead of this exception? // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // if (valueAndType.TargetValue != null && valueAndType.TargetValue.ToString().IndexOf("?") > -1) { // throw new org.seasar.framework.exception.SRuntimeException("EDAO0023"); // } ctx.AddSql(valueAndType.TargetValue.ToString()); } } if (valueAndType.IsValidRearOption()) { ctx.AddSql(valueAndType.BuildRearOptionOnSql()); } }
protected void EmbedArray(ICommandContext ctx, object arrayArg) { if (arrayArg == null) { return; } object[] array = arrayArg as object[]; int length = array.Length; if (length == 0) { ThrowBindOrEmbeddedParameterEmptyListException(); } String quote = null; for (int i = 0; i < length; ++i) { Object currentElement = array[i]; if (currentElement != null) { quote = !IsNumeric(currentElement) ? "'" : ""; break; } } if (quote == null) { ThrowBindOrEmbeddedParameterNullOnlyListException(); } bool existsValidElements = false; ctx.AddSql("("); for (int i = 0; i < length; ++i) { Object currentElement = array[i]; if (currentElement != null) { if (!existsValidElements) { ctx.AddSql(quote + currentElement + quote); existsValidElements = true; } else { ctx.AddSql(", " + quote + currentElement + quote); } } } ctx.AddSql(")"); }
protected void BindArray(ICommandContext ctx, object arrayArg) { if (arrayArg == null) { return; } object[] array = arrayArg as object[]; int length = array.Length; if (length == 0) { ThrowBindOrEmbeddedParameterEmptyListException(); } Type type = null; for (int i = 0; i < length; ++i) { Object currentElement = array[i]; if (currentElement != null) { type = currentElement.GetType(); break; } } if (type == null) { ThrowBindOrEmbeddedParameterNullOnlyListException(); } ctx.AddSql("("); int bindCount = 0; for (int i = 0; i < length; ++i) { Object currentElement = array[i]; if (currentElement != null) { ++bindCount; if (bindCount == 1) // FirstElement! { ctx.AddSql(currentElement, type, _expression + bindCount); } else { ctx.AppendSql(currentElement, type, _expression + bindCount); } } } ctx.AddSql(")"); }
public override void Accept(ICommandContext ctx) { object value = ctx.GetArg(_names[0]); Type type = (value != null ? value.GetType() : null); InternalValueAndType valueAndType = new InternalValueAndType(); valueAndType.TargetValue = value; valueAndType.TargetType = type; SetupValueAndType(valueAndType); if (_blockNullParameter && valueAndType.TargetValue == null) { ThrowBindOrEmbeddedParameterNullValueException(valueAndType); } if (!IsInScope()) { // Main Root ctx.AddSql(valueAndType.TargetValue, valueAndType.TargetType, _expression.Replace('.', '_')); } else { if (typeof(System.Collections.IList).IsAssignableFrom(valueAndType.TargetType)) { System.Collections.IList list = valueAndType.TargetValue as System.Collections.IList; Array array = new Object[list.Count]; list.CopyTo(array, 0); BindArray(ctx, array); } else if (valueAndType.TargetType.IsArray) { BindArray(ctx, valueAndType.TargetValue); } else { ctx.AddSql(valueAndType.TargetValue, valueAndType.TargetType, _expression.Replace('.', '_')); } } if (valueAndType.IsValidRearOption()) { ctx.AddSql(valueAndType.BuildRearOptionOnSql()); } }