public void Resolve(Session session) { this.SetLanguage(this.Language); if (this.Language == 2) { if (this.DataImpact == 1) { throw Error.GetError(0x15e4); } if (this.ParameterStyle == 1) { throw Error.GetError(0x15e4); } } if (((this.Language == 2) && (this.ParameterStyle != 0)) && (this.ParameterStyle != 2)) { throw Error.GetError(0x15e4); } this.ParameterTypes = new SqlType[this.ParameterList.Size()]; this.TypeGroups = 0; for (int i = 0; i < this.ParameterTypes.Length; i++) { ColumnSchema schema = this.ParameterList.Get(i); this.ParameterTypes[i] = schema.DataType; if (i < 4) { BitMap.SetByte(this.TypeGroups, (byte)schema.DataType.TypeComparisonGroup, i * 8); } } if (this.statement != null) { this.statement.Resolve(session, this.Ranges); if (this.DataImpact == 2) { CheckNoSqlData(session.database, this.statement.GetReferences()); } } if ((this._methodName != null) && (this._cSharpMethod == null)) { bool[] hasConnection = new bool[1]; this._cSharpMethod = this.GetMethod(this._methodName, this, hasConnection, this._returnsTable); if (this._cSharpMethod == null) { throw Error.GetError(0x177d); } if (!this._cSharpMethod.IsStatic) { this.CSharpClassInstance = Activator.CreateInstance(this._cSharpMethod.DeclaringType); if (this.CSharpClassInstance == null) { throw Error.GetError(0x177d); } } this.CSharpMethodWithConnection = hasConnection[0]; if (this._cSharpMethod.DeclaringType.FullName.Equals("System.Math")) { this._isLibraryRoutine = true; } } if (this.isAggregate) { if (this.ParameterTypes.Length < 4) { throw Error.GetError(0x15ea); } bool flag = this.ParameterTypes[this.ParameterList.Size() - 3].TypeCode == 0x10; ColumnSchema schema2 = this.ParameterList.Get(0); flag &= schema2.GetParameterMode() == 1; int index = 1; while (index < (this.ParameterList.Size() - 3)) { schema2 = this.ParameterList.Get(index); flag &= schema2.GetParameterMode() == 1; index++; } schema2 = this.ParameterList.Get(index); flag &= schema2.GetParameterMode() == 1; schema2 = this.ParameterList.Get(index + 1); flag &= schema2.GetParameterMode() == 2; schema2 = this.ParameterList.Get(index + 2); if (!(flag & (schema2.GetParameterMode() == 2))) { throw Error.GetError(0x15ea); } } else if ((this._methodName != null) && this.ReturnsTable()) { object[] customAttributes = this._cSharpMethod.GetCustomAttributes(typeof(SqlFunction), false); if ((customAttributes == null) || (customAttributes.Length == 0)) { throw Error.GetError(0x177d); } string fillRowMethodName = ((SqlFunction)customAttributes[0]).FillRowMethodName; this._fillRowMethod = this.GetFillRowMethod(fillRowMethodName); if (this._fillRowMethod == null) { throw Error.GetError(0x177d); } } this.SetReferences(); }
private MethodInfo GetMethod(string name, Routine routine, bool[] hasConnection, bool returnsTable) { MethodInfo[] methods = this.GetMethods(name); int i = -1; for (int j = 0; j < methods.Length; j++) { int num4; int num3 = 0; hasConnection[0] = false; MethodInfo info = methods[j]; ParameterInfo[] parameters = info.GetParameters(); if ((parameters.Length != 0) && parameters[0].ParameterType.Equals(typeof(DbConnection))) { num3 = 1; hasConnection[0] = true; } if ((parameters.Length - num3) != routine.ParameterTypes.Length) { continue; } if (returnsTable) { if (typeof(IEnumerable).IsAssignableFrom(info.ReturnType)) { goto Label_00AB; } continue; } SqlType parameterSqlType = Types.GetParameterSqlType(methods[j].ReturnType); if ((parameterSqlType == null) || (parameterSqlType.TypeCode != routine.ReturnType.TypeCode)) { continue; } Label_00AB: num4 = 0; while (num4 < routine.ParameterTypes.Length) { bool flag = false; ParameterInfo info2 = parameters[num4 + num3]; Type parameterType = info2.ParameterType; if (parameterType.IsArray && !typeof(byte[]).Equals(parameterType)) { parameterType = parameterType.GetElementType(); if (parameterType.IsPrimitive) { info = null; break; } flag = true; } SqlType type3 = Types.GetParameterSqlType(parameterType); if (type3 == null) { info = null; break; } ColumnSchema parameter = routine.GetParameter(num4); if (parameter.GetParameterMode() == 1) { if (!info2.IsOut && !parameterType.IsByRef) { goto Label_0183; } info = null; break; } if (parameter.GetParameterMode() == 4) { if (info2.IsOut && parameterType.IsByRef) { goto Label_0183; } info = null; break; } if ((parameter.GetParameterMode() == 2) && !parameterType.IsByRef) { info = null; break; } Label_0183: parameter.SetNullable(!parameters[j].ParameterType.IsPrimitive); bool flag2 = routine.ParameterTypes[num4].TypeComparisonGroup == type3.TypeComparisonGroup; if (flag2 && routine.ParameterTypes[num4].IsNumberType()) { flag2 = routine.ParameterTypes[num4].TypeCode == type3.TypeCode; } if (flag && (routine.GetParameter(num4).ParameterMode == 1)) { flag2 = false; } if (!flag2) { info = null; if ((num4 + num3) > i) { i = num4 + num3; } break; } num4++; } if (info != null) { for (int k = 0; k < routine.ParameterTypes.Length; k++) { routine.GetParameter(k).SetNullable(!parameters[k + num3].ParameterType.IsPrimitive); } return(info); } } if (i >= 0) { ColumnSchema parameter = routine.GetParameter(i); throw Error.GetError(0x1785, parameter.GetNameString()); } return(null); }