From: Date: February 14 2008 5:55pm Subject: Connector/NET commit: r1177 - in branches/5.1: . Driver/Source Driver/Source/common VisualStudio/Descriptors List-Archive: http://lists.mysql.com/commits/42294 X-Bug: 34359 Message-Id: <200802141655.m1EGtVMG005571@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/5.1/CHANGES branches/5.1/Driver/Source/ISSchemaProvider.cs branches/5.1/Driver/Source/common/SqlTokenizer.cs branches/5.1/VisualStudio/Descriptors/StoredProcDescriptor.cs Log: - Fixed problem where parameters lists were not showing when you tried to alter a routine in server explorer. (bug #34359). the problem was that since we moved away from using mysql.proc we didn't replace the code that pulled out the parameter list. We have now. Modified: branches/5.1/CHANGES =================================================================== --- branches/5.1/CHANGES 2008-02-13 19:17:22 UTC (rev 1176) +++ branches/5.1/CHANGES 2008-02-14 16:55:31 UTC (rev 1177) @@ -1,3 +1,7 @@ +Version 5.1.6 + - Fixed problem where parameters lists were not showing when you tried to alter a routine + in server explorer. (bug #34359) + Version 5.1.5 - - Fixed problem with membership provider where FindUserByEmail would fail trying to add a second parameter with the same name as the first (bug #33347) Modified: branches/5.1/Driver/Source/ISSchemaProvider.cs =================================================================== --- branches/5.1/Driver/Source/ISSchemaProvider.cs 2008-02-13 19:17:22 UTC (rev 1176) +++ branches/5.1/Driver/Source/ISSchemaProvider.cs 2008-02-14 16:55:31 UTC (rev 1177) @@ -195,6 +195,60 @@ return dt; } + private DataTable GetProceduresWithParameters(string[] restrictions) + { + DataTable dt = GetProcedures(restrictions); + dt.Columns.Add("ParameterList", typeof(string)); + + foreach (DataRow row in dt.Rows) + { + row["ParameterList"] = GetProcedureParameterLine(row); + } + return dt; + } + + private string GetProcedureParameterLine(DataRow isRow) + { + string sql = "SHOW CREATE {0} {1}.{2}"; + sql = String.Format(sql, isRow["ROUTINE_TYPE"], isRow["ROUTINE_SCHEMA"], + isRow["ROUTINE_NAME"]); + MySqlCommand cmd = new MySqlCommand(sql, connection); + using (MySqlDataReader reader = cmd.ExecuteReader()) + { + reader.Read(); + + // if we are not the owner of this proc or have permissions + // then we will get null for the body + if (reader.IsDBNull(2)) return null; + + string sql_mode = reader.GetString(1); + + string body = reader.GetString(2); + SqlTokenizer tokenizer = new SqlTokenizer(body); + tokenizer.AnsiQuotes = sql_mode.IndexOf("ANSI_QUOTES") != -1; + tokenizer.BackslashEscapes = sql_mode.IndexOf("NO_BACKSLASH_ESCAPES") == -1; + + string token = tokenizer.NextToken(); + while (token != "(") + token = tokenizer.NextToken(); + int start = tokenizer.Index + 1; + token = tokenizer.NextToken(); + while (token != ")" || tokenizer.Quoted) + { + token = tokenizer.NextToken(); + // if we see another ( and we are not quoted then we + // are in a size element and we need to look for the closing paren + if (token == "(" && !tokenizer.Quoted) + { + while (token != ")" || tokenizer.Quoted) + token = tokenizer.NextToken(); + token = tokenizer.NextToken(); + } + } + return body.Substring(start, tokenizer.Index - start); + } + } + /// /// Return schema information about parameters for procedures and functions /// Restrictions supported are: @@ -237,6 +291,8 @@ return GetViews(restrictions); case "procedures": return GetProcedures(restrictions); + case "procedures with parameters": + return GetProceduresWithParameters(restrictions); case "procedure parameters": return GetProcedureParameters(restrictions, null); case "triggers": @@ -290,7 +346,6 @@ routines = GetSchema("procedures", restrictions); MySqlCommand cmd = connection.CreateCommand(); - MySqlDataReader reader = null; foreach (DataRow routine in routines.Rows) { @@ -304,20 +359,17 @@ if (restrictions != null && restrictions.Length == 5 && restrictions[4] != null) nameToRestrict = restrictions[4]; - reader = cmd.ExecuteReader(); - reader.Read(); - ParseProcedureBody(parametersTable, reader.GetString(2), - routine, nameToRestrict); + using (MySqlDataReader reader = cmd.ExecuteReader()) + { + reader.Read(); + ParseProcedureBody(parametersTable, reader.GetString(2), + routine, nameToRestrict); + } } catch (SqlNullValueException snex) { throw new InvalidOperationException(Resources.UnableToRetrieveSProcData, snex); } - finally - { - if (reader != null) - reader.Close(); - } } } Modified: branches/5.1/Driver/Source/common/SqlTokenizer.cs =================================================================== --- branches/5.1/Driver/Source/common/SqlTokenizer.cs 2008-02-13 19:17:22 UTC (rev 1176) +++ branches/5.1/Driver/Source/common/SqlTokenizer.cs 2008-02-14 16:55:31 UTC (rev 1177) @@ -47,6 +47,11 @@ get { return quoted; } } + public int Index + { + get { return index; } + } + #endregion public string NextToken() Modified: branches/5.1/VisualStudio/Descriptors/StoredProcDescriptor.cs =================================================================== --- branches/5.1/VisualStudio/Descriptors/StoredProcDescriptor.cs 2008-02-13 19:17:22 UTC (rev 1176) +++ branches/5.1/VisualStudio/Descriptors/StoredProcDescriptor.cs 2008-02-14 16:55:31 UTC (rev 1177) @@ -133,7 +133,7 @@ [Field(FieldType = TypeCode.String)] public const string Definer = "DEFINER"; [Field(FieldType = TypeCode.String)] - public const string ParameterList = "PARAM_LIST"; + public const string ParameterList = "PARAMETERLIST"; } #endregion @@ -219,7 +219,7 @@ for (int x = 0; x < rest.Length; x++) if (restrictions[x] != null) rest[x] = restrictions[x].ToString(); - DataTable dt = conn.GetSchema("Procedures", rest); + DataTable dt = conn.GetSchema("Procedures With Parameters", rest); connection.Connection.UnlockProviderObject(); return dt; }