private void PopulateParameters(string databaseName, string moduleName, Dictionary <string, ProcedureDef> globalProcedureDefMap) { using (SqlCommand command = new SqlCommand() { CommandText = $"SELECT * FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_CATALOG='{databaseName}' AND SPECIFIC_NAME like '{moduleName}\\_%\\_%' ESCAPE '\\' ORDER BY ORDINAL_POSITION ASC", CommandType = CommandType.Text, Connection = this.SqlConnection }) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { var parameterRow = reader; string procedureName = (string)parameterRow["SPECIFIC_NAME"]; ProcedureDef procedureDef = globalProcedureDefMap[procedureName]; string parameterName = (string)parameterRow["PARAMETER_NAME"]; int?charLength; if (parameterRow["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value) { charLength = null; } else { charLength = (int)parameterRow["CHARACTER_MAXIMUM_LENGTH"]; } int?scale; if (parameterRow["NUMERIC_SCALE"] == DBNull.Value) { scale = null; } else { scale = (int)parameterRow["NUMERIC_SCALE"]; } byte?precision; if (parameterRow["NUMERIC_PRECISION"] == DBNull.Value) { precision = null; } else { precision = (byte)parameterRow["NUMERIC_PRECISION"]; } /* TODO: if you have an interface, and a referring class uses the interface * and not the implementing object, but you put the object name + Key in the * database table, TIDAL is making procedures/functions using the interface * name + Key, and this doesn't map back to the table to get the columndef */ /* try to find the best guess as to the field it may be */ ColumnDef columnDef; procedureDef.TableDef.ColumnDefMap.TryGetValue(parameterName.Substring(1), out columnDef); // if (columnDef == null) Console.WriteLine("Could not get ColumnDef for " + parameterName.Substring(1) + " of " + procedureDef.ProcedureName); ParameterDef parameterDef = new ParameterDef { ProcedureDef = procedureDef, ParameterName = parameterName, ParameterMode = (string)parameterRow["PARAMETER_MODE"], ParameterDataTypeCode = (string)parameterRow["DATA_TYPE"], ColumnDef = columnDef, CharLength = charLength, Precision = (ulong?)precision, Scale = scale, OrdinalPosition = (int)parameterRow["ORDINAL_POSITION"], IsOutParameter = parameterRow["PARAMETER_MODE"].ToString() == "INOUT" }; procedureDef.ParameterDefMap[parameterName] = parameterDef; /* isNullable, isOut, length */ } } } }
private void PopulateParameters(string databaseName, string moduleName, Dictionary <string, ProcedureDef> globalProcedureDefMap) { using (MySqlCommand command = new MySqlCommand() { CommandText = "SELECT * FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_CATALOG='def' AND SPECIFIC_SCHEMA='" + databaseName + "' AND SPECIFIC_NAME like '" + moduleName + "_%_%' ORDER BY ORDINAL_POSITION ASC", CommandType = CommandType.Text, Connection = this.mySqlConnection }) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { var parameterRow = reader; string procedureName = (string)parameterRow["SPECIFIC_NAME"]; ProcedureDef procedureDef = globalProcedureDefMap[procedureName]; string parameterName = (string)parameterRow["PARAMETER_NAME"]; int?charLength; if (parameterRow["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value) { charLength = null; } else { charLength = (int)parameterRow["CHARACTER_MAXIMUM_LENGTH"]; } int?scale; if (parameterRow["NUMERIC_SCALE"] == DBNull.Value) { scale = null; } else { scale = (int)parameterRow["NUMERIC_SCALE"]; } ulong?precision; if (parameterRow["NUMERIC_PRECISION"] == DBNull.Value) { precision = null; } else { precision = (ulong)parameterRow["NUMERIC_PRECISION"]; } /* try to find the best guess as to the field it may be */ ColumnDef columnDef; procedureDef.TableDef.ColumnDefMap.TryGetValue(parameterName.Substring(1), out columnDef); ParameterDef parameterDef = new ParameterDef { ProcedureDef = procedureDef, ParameterName = parameterName, ParameterMode = (string)parameterRow["PARAMETER_MODE"], ParameterDataTypeCode = (string)parameterRow["DATA_TYPE"], ColumnDef = columnDef, CharLength = charLength, Precision = precision, Scale = scale, OrdinalPosition = (int)parameterRow["ORDINAL_POSITION"], IsOutParameter = parameterRow["PARAMETER_MODE"].ToString() == "OUT" }; procedureDef.ParameterDefMap[parameterName] = parameterDef; /* isNullable, isOut, length */ } } } }