Наследование: SchemaProvider
Пример #1
0
        private static ProcedureCacheEntry GetProcData(MySqlConnection connection, string spName)
        {
            string text  = string.Empty;
            string text2 = spName;
            int    num   = spName.IndexOf(".");

            if (num != -1)
            {
                text  = spName.Substring(0, num);
                text2 = spName.Substring(num + 1, spName.Length - num - 1);
            }
            string[] array = new string[4];
            array[1] = ((text.Length > 0) ? text : connection.CurrentDatabase());
            array[2] = text2;
            MySqlSchemaCollection schemaCollection = connection.GetSchemaCollection("procedures", array);

            if (schemaCollection.Rows.Count > 1)
            {
                throw new MySqlException(Resources.ProcAndFuncSameName);
            }
            if (schemaCollection.Rows.Count == 0)
            {
                throw new MySqlException(string.Format(Resources.InvalidProcName, text2, text));
            }
            ProcedureCacheEntry procedureCacheEntry = new ProcedureCacheEntry();

            procedureCacheEntry.procedure = schemaCollection;
            ISSchemaProvider iSSchemaProvider = new ISSchemaProvider(connection);

            string[] restrictions = iSSchemaProvider.CleanRestrictions(array);
            MySqlSchemaCollection procedureParameters = iSSchemaProvider.GetProcedureParameters(restrictions, schemaCollection);

            procedureCacheEntry.parameters = procedureParameters;
            return(procedureCacheEntry);
        }
Пример #2
0
        private MySqlSchemaCollection GetParametersForRoutineFromIS(string[] restrictions)
        {
            string[] keys = new string[]
            {
                "SPECIFIC_CATALOG",
                "SPECIFIC_SCHEMA",
                "SPECIFIC_NAME",
                "ROUTINE_TYPE",
                "PARAMETER_NAME"
            };
            StringBuilder stringBuilder = new StringBuilder("SELECT * FROM INFORMATION_SCHEMA.PARAMETERS");
            string        whereClause   = ISSchemaProvider.GetWhereClause(null, keys, restrictions);

            if (!string.IsNullOrEmpty(whereClause))
            {
                stringBuilder.AppendFormat(CultureInfo.InvariantCulture, " WHERE {0}", new object[]
                {
                    whereClause
                });
            }
            MySqlSchemaCollection mySqlSchemaCollection = base.QueryCollection("parameters", stringBuilder.ToString());

            if (mySqlSchemaCollection.Rows.Count != 0 && (string)mySqlSchemaCollection.Rows[0]["routine_type"] == "FUNCTION")
            {
                mySqlSchemaCollection.Rows[0]["parameter_mode"] = "IN";
                mySqlSchemaCollection.Rows[0]["parameter_name"] = "return_value";
            }
            return(mySqlSchemaCollection);
        }
Пример #3
0
        private DataSet GetProcData(MySqlConnection connection, string spName)
        {
            int    dotIndex = spName.IndexOf(".");
            string schema   = spName.Substring(0, dotIndex);
            string name     = spName.Substring(dotIndex + 1, spName.Length - dotIndex - 1);

            string[] restrictions = new string[4];
            restrictions[1] = schema;
            restrictions[2] = name;
            DataTable procTable = connection.GetSchema("procedures", restrictions);

            if (procTable.Rows.Count > 1)
            {
                throw new MySqlException(Resources.ProcAndFuncSameName);
            }
            if (procTable.Rows.Count == 0)
            {
                throw new MySqlException(String.Format(Resources.InvalidProcName, name, schema));
            }

            // we don't use GetSchema here because that would cause another
            // query of procedures and we don't need that since we already
            // know the procedure we care about.
            ISSchemaProvider isp             = new ISSchemaProvider(connection);
            DataTable        parametersTable = isp.GetProcedureParameters(
                restrictions, procTable);

            DataSet ds = new DataSet();

            ds.Tables.Add(procTable);
            ds.Tables.Add(parametersTable);
            return(ds);
        }
Пример #4
0
        private DataSet GetParameters(string procName)
        {
            // if we can use mysql.proc, then do so
            //if (Connection.Settings.UseProcedureBodies)
            DataSet ds = Connection.ProcedureCache.GetProcedure(Connection, procName);

            // if we got both proc and parameter data then just return
            if (ds.Tables.Count == 2)
            {
                return(ds);
            }

            // we were not able to retrieve parameter data so we have to make do by
            // adding the parameters from the command object to our table
            // we use an internal method to create our procedure parameters table.
            ISSchemaProvider sp     = new ISSchemaProvider(Connection);
            DataTable        pTable = sp.CreateParametersTable();

            ds.Tables.Add(pTable);

            // now we run through the parameters that were set and fill in the parameters table
            // the best we can
            int pos = 1;

            foreach (MySqlParameter p in command.Parameters)
            {
                // in this mode, all parameters must have their type set
                if (!p.TypeHasBeenSet)
                {
                    throw new InvalidOperationException(Resources.NoBodiesAndTypeNotSet);
                }

                DataRow row = pTable.NewRow();
                row["PARAMETER_NAME"] = p.ParameterName;
                row["PARAMETER_MODE"] = "IN";
                if (p.Direction == ParameterDirection.InputOutput)
                {
                    row["PARAMETER_MODE"] = "INOUT";
                }
                else if (p.Direction == ParameterDirection.Output)
                {
                    row["PARAMETER_MODE"] = "OUT";
                }
                else if (p.Direction == ParameterDirection.ReturnValue)
                {
                    row["PARAMETER_MODE"]   = "OUT";
                    row["ORDINAL_POSITION"] = 0;
                }
                else
                {
                    row["ORDINAL_POSITION"] = pos++;
                }
                pTable.Rows.Add(row);
            }
            return(ds);
        }
Пример #5
0
        private DataSet GetParameters(string procName)
        {
            // if we can use mysql.proc, then do so
            if (Connection.Settings.UseProcedureBodies)
                return Connection.ProcedureCache.GetProcedure(Connection, procName);

            // we can't use mysql.proc so we attempt to "make do"
            DataSet ds = new DataSet();
            string[] restrictions = new string[4];
            int dotIndex = procName.IndexOf('.');
            restrictions[1] = procName.Substring(0, dotIndex++);
            restrictions[2] = procName.Substring(dotIndex, procName.Length - dotIndex);
            ds.Tables.Add(Connection.GetSchema("procedures", restrictions));

            // we use an internal method to create our procedure parameters table.  We pass
            // in a non-null routines table and this will prevent the code from attempting
            // a show create. It will process zero routine records but will return an empty
            // parameters table we can then fill.
            DataTable zeroRoutines = new DataTable();
            ISSchemaProvider sp = new ISSchemaProvider(Connection);
            DataTable pTable = sp.GetProcedureParameters(null, zeroRoutines);
            pTable.TableName = "procedure parameters";
            ds.Tables.Add(pTable);

            // now we run through the parameters that were set and fill in the parameters table
            // the best we can
            int pos = 1;
            foreach (MySqlParameter p in command.Parameters)
            {
                // in this mode, all parameters must have their type set
                if (!p.TypeHasBeenSet)
                    throw new InvalidOperationException(Resources.NoBodiesAndTypeNotSet);

                DataRow row = pTable.NewRow();
                row["PARAMETER_NAME"] = p.ParameterName;
                row["PARAMETER_MODE"] = "IN";
                if (p.Direction == ParameterDirection.InputOutput)
                    row["PARAMETER_MODE"] = "INOUT";
                else if (p.Direction == ParameterDirection.Output)
                    row["PARAMETER_MODE"] = "OUT";
                else if (p.Direction == ParameterDirection.ReturnValue)
                {
                    row["PARAMETER_MODE"] = "OUT";
                    row["ORDINAL_POSITION"] = 0;
                }
                else
                    row["ORDINAL_POSITION"] = pos++;
                pTable.Rows.Add(row);
            }
            return ds;
        }
Пример #6
0
        private MySqlSchemaCollection Query(string table_name, string initial_where, string[] keys, string[] values)
        {
            StringBuilder stringBuilder = new StringBuilder("SELECT * FROM INFORMATION_SCHEMA.");

            stringBuilder.Append(table_name);
            string whereClause = ISSchemaProvider.GetWhereClause(initial_where, keys, values);

            if (whereClause.Length > 0)
            {
                stringBuilder.AppendFormat(CultureInfo.InvariantCulture, " WHERE {0}", new object[]
                {
                    whereClause
                });
            }
            return(this.GetTable(stringBuilder.ToString()));
        }
Пример #7
0
        private static ProcedureCacheEntry GetProcData(MySqlConnection connection, string spName)
        {
            string schema = string.Empty;
            string name   = spName;

            int dotIndex = spName.IndexOf("`.`");

            if (dotIndex != -1)
            {
                schema = spName.Substring(1, dotIndex - 1);
                name   = spName.Substring(dotIndex + 3, spName.Length - dotIndex - 4);
            }

            string[] restrictions = new string[4];
            restrictions[1] = schema.Length > 0 ? schema : connection.CurrentDatabase();
            restrictions[2] = name;
            MySqlSchemaCollection proc = connection.GetSchemaCollection("procedures", restrictions);

            if (proc.Rows.Count > 1)
            {
                throw new MySqlException(Resources.ProcAndFuncSameName);
            }
            if (proc.Rows.Count == 0)
            {
                string msg = string.Format(Resources.InvalidProcName, name, schema) + " " +
                             string.Format(Resources.ExecuteProcedureUnauthorized, connection.Settings.UserID, connection.Settings.Server);
                throw new MySqlException(msg);
            }

            ProcedureCacheEntry entry = new ProcedureCacheEntry();

            entry.procedure = proc;

            // we don't use GetSchema here because that would cause another
            // query of procedures and we don't need that since we already
            // know the procedure we care about.
            ISSchemaProvider isp = new ISSchemaProvider(connection);

            string[] rest = isp.CleanRestrictions(restrictions);
            MySqlSchemaCollection parameters = isp.GetProcedureParameters(rest, proc);

            entry.parameters = parameters;

            return(entry);
        }
Пример #8
0
        private static DataSet GetProcData(MySqlConnection connection, string spName)
        {
            var schema = String.Empty;
            var name   = spName;

            var dotIndex = spName.IndexOf(".");

            if (dotIndex != -1)
            {
                schema = spName.Substring(0, dotIndex);
                name   = spName.Substring(dotIndex + 1, spName.Length - dotIndex - 1);
            }

            var restrictions = new string[4];

            restrictions[1] = schema.Length > 0 ? schema : connection.CurrentDatabase();
            restrictions[2] = name;
            var procTable = connection.GetSchema("procedures", restrictions);

            if (procTable.Rows.Count > 1)
            {
                throw new MySqlException(Resources.ProcAndFuncSameName);
            }
            if (procTable.Rows.Count == 0)
            {
                throw new MySqlException(String.Format(Resources.InvalidProcName, name, schema));
            }

            var ds = new DataSet();

            ds.Tables.Add(procTable);

            // we don't use GetSchema here because that would cause another
            // query of procedures and we don't need that since we already
            // know the procedure we care about.
            var isp             = new ISSchemaProvider(connection);
            var rest            = isp.CleanRestrictions(restrictions);
            var parametersTable = isp.GetProcedureParameters(rest, procTable);

            ds.Tables.Add(parametersTable);

            return(ds);
        }
Пример #9
0
        private void GetParameters(string procName, out DataTable proceduresTable,
                                   out DataTable parametersTable)
        {
            string  procCacheKey = GetCacheKey(procName);
            DataSet ds           = Connection.ProcedureCache.GetProcedure(Connection, procName, procCacheKey);

            if (ds.Tables.Count == 2)
            {
                // if we got our parameters and our user says it is ok to use proc bodies
                // then just return them
                if (Connection.Settings.UseProcedureBodies)
                {
                    lock (ds)
                    {
                        proceduresTable = ds.Tables["procedures"];
                        parametersTable = ds.Tables["procedure parameters"];
                        return;
                    }
                }
            }

            lock (ds)
            {
                proceduresTable = ds.Tables["procedures"];
            }
            // we were not able to retrieve parameter data so we have to make do by
            // adding the parameters from the command object to our table
            // we use an internal method to create our procedure parameters table.
            ISSchemaProvider sp = new ISSchemaProvider(Connection);

            parametersTable = sp.CreateParametersTable();

            // now we run through the parameters that were set and fill in the parameters table
            // the best we can
            int pos = 1;

            foreach (MySqlParameter p in command.Parameters)
            {
                // in this mode, all parameters must have their type set
                if (!p.TypeHasBeenSet)
                {
                    throw new InvalidOperationException(Resources.NoBodiesAndTypeNotSet);
                }

                DataRow row = parametersTable.NewRow();
                row["PARAMETER_NAME"] = p.ParameterName;
                row["PARAMETER_MODE"] = "IN";
                if (p.Direction == ParameterDirection.InputOutput)
                {
                    row["PARAMETER_MODE"] = "INOUT";
                }
                else if (p.Direction == ParameterDirection.Output)
                {
                    row["PARAMETER_MODE"] = "OUT";
                }
                else if (p.Direction == ParameterDirection.ReturnValue)
                {
                    row["PARAMETER_MODE"]   = "OUT";
                    row["ORDINAL_POSITION"] = 0;
                }
                else
                {
                    row["ORDINAL_POSITION"] = pos++;
                }
                parametersTable.Rows.Add(row);
            }
            if (Connection.Settings.UseProcedureBodies)
            {
                lock (ds)
                {
                    // we got the parameters, but ignore them.
                    if (ds.Tables.Contains("Procedure Parameters"))
                    {
                        ds.Tables.Remove("Procedure Parameters");
                    }

                    ds.Tables.Add(parametersTable);
                }
            }
        }
Пример #10
0
        private DataSet GetParameters(string procName)
        {
            // if we can use mysql.proc, then do so
            if (Connection.Settings.UseProcedureBodies)
            {
                return(Connection.ProcedureCache.GetProcedure(Connection, procName));
            }

            // we can't use mysql.proc so we attempt to "make do"
            DataSet ds = new DataSet();

            string[] restrictions = new string[4];
            int      dotIndex     = procName.IndexOf('.');

            restrictions[1] = procName.Substring(0, dotIndex++);
            restrictions[2] = procName.Substring(dotIndex, procName.Length - dotIndex);
            ds.Tables.Add(Connection.GetSchema("procedures", restrictions));

            // we use an internal method to create our procedure parameters table.  We pass
            // in a non-null routines table and this will prevent the code from attempting
            // a show create. It will process zero routine records but will return an empty
            // parameters table we can then fill.
            DataTable        zeroRoutines = new DataTable();
            ISSchemaProvider sp           = new ISSchemaProvider(Connection);
            DataTable        pTable       = sp.GetProcedureParameters(null, zeroRoutines);

            pTable.TableName = "procedure parameters";
            ds.Tables.Add(pTable);

            // now we run through the parameters that were set and fill in the parameters table
            // the best we can
            int pos = 1;

            foreach (MySqlParameter p in command.Parameters)
            {
                // in this mode, all parameters must have their type set
                if (!p.TypeHasBeenSet)
                {
                    throw new InvalidOperationException(Resources.NoBodiesAndTypeNotSet);
                }

                DataRow row = pTable.NewRow();
                row["PARAMETER_NAME"] = p.ParameterName;
                row["PARAMETER_MODE"] = "IN";
                if (p.Direction == ParameterDirection.InputOutput)
                {
                    row["PARAMETER_MODE"] = "INOUT";
                }
                else if (p.Direction == ParameterDirection.Output)
                {
                    row["PARAMETER_MODE"] = "OUT";
                }
                else if (p.Direction == ParameterDirection.ReturnValue)
                {
                    row["PARAMETER_MODE"]   = "OUT";
                    row["ORDINAL_POSITION"] = 0;
                }
                else
                {
                    row["ORDINAL_POSITION"] = pos++;
                }
                pTable.Rows.Add(row);
            }
            return(ds);
        }
Пример #11
0
        private static DataSet GetProcData(MySqlConnection connection, string spName)
        {
            string schema = String.Empty;
            string name = spName;

            int dotIndex = spName.IndexOf(".");
            if (dotIndex != -1)
            {
                schema = spName.Substring(0, dotIndex);
                name = spName.Substring(dotIndex + 1, spName.Length - dotIndex - 1);
            }

            string[] restrictions = new string[4];
            restrictions[1] = schema.Length > 0 ? schema : connection.CurrentDatabase();
            restrictions[2] = name;
            DataTable procTable = connection.GetSchema("procedures", restrictions);
            if (procTable.Rows.Count > 1)
                throw new MySqlException(Resources.ProcAndFuncSameName);
            if (procTable.Rows.Count == 0)
                throw new MySqlException(String.Format(Resources.InvalidProcName, name, schema));

            DataSet ds = new DataSet();
            ds.Tables.Add(procTable);

            // we don't use GetSchema here because that would cause another
            // query of procedures and we don't need that since we already
            // know the procedure we care about.
            ISSchemaProvider isp = new ISSchemaProvider(connection);
            string[] rest = isp.CleanRestrictions(restrictions);
            try
            {
                DataTable parametersTable = isp.GetProcedureParameters(rest, procTable);
                ds.Tables.Add(parametersTable);
            }
            catch (Exception) { }

            return ds;
        }
Пример #12
0
        private string ParseDataType(MySqlSchemaRow row, MySqlTokenizer tokenizer)
        {
            StringBuilder stringBuilder = new StringBuilder(StringUtility.ToUpperInvariant(tokenizer.NextToken()));

            row["DATA_TYPE"] = stringBuilder.ToString();
            string text  = row["DATA_TYPE"].ToString();
            string text2 = tokenizer.NextToken();

            if (text2 == "(")
            {
                text2 = tokenizer.ReadParenthesis();
                stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", new object[]
                {
                    text2
                });
                if (text != "ENUM" && text != "SET")
                {
                    ISSchemaProvider.ParseDataTypeSize(row, text2);
                }
                text2 = tokenizer.NextToken();
            }
            else
            {
                stringBuilder.Append(ISSchemaProvider.GetDataTypeDefaults(text, row));
            }
            while (text2 != ")" && text2 != "," && string.Compare(text2, "begin", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(text2, "return", StringComparison.OrdinalIgnoreCase) != 0)
            {
                if (string.Compare(text2, "CHARACTER", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(text2, "BINARY", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    if (string.Compare(text2, "SET", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(text2, "CHARSET", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        row["CHARACTER_SET_NAME"] = tokenizer.NextToken();
                    }
                    else if (string.Compare(text2, "ASCII", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        row["CHARACTER_SET_NAME"] = "latin1";
                    }
                    else if (string.Compare(text2, "UNICODE", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        row["CHARACTER_SET_NAME"] = "ucs2";
                    }
                    else if (string.Compare(text2, "COLLATE", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        row["COLLATION_NAME"] = tokenizer.NextToken();
                    }
                    else
                    {
                        stringBuilder.AppendFormat(CultureInfo.InvariantCulture, " {0}", new object[]
                        {
                            text2
                        });
                    }
                }
                text2 = tokenizer.NextToken();
            }
            if (stringBuilder.Length > 0)
            {
                row["DTD_IDENTIFIER"] = stringBuilder.ToString();
            }
            if (string.IsNullOrEmpty((string)row["COLLATION_NAME"]) && !string.IsNullOrEmpty((string)row["CHARACTER_SET_NAME"]))
            {
                row["COLLATION_NAME"] = CharSetMap.GetDefaultCollation(row["CHARACTER_SET_NAME"].ToString(), this.connection);
            }
            if (row["CHARACTER_MAXIMUM_LENGTH"] != null)
            {
                if (row["CHARACTER_SET_NAME"] == null)
                {
                    row["CHARACTER_SET_NAME"] = "";
                }
                row["CHARACTER_OCTET_LENGTH"] = CharSetMap.GetMaxLength((string)row["CHARACTER_SET_NAME"], this.connection) * (int)row["CHARACTER_MAXIMUM_LENGTH"];
            }
            return(text2);
        }
Пример #13
0
        private void ParseProcedureBody(MySqlSchemaCollection parametersTable, string body, MySqlSchemaRow row, string nameToRestrict)
        {
            List <string> list = new List <string>(new string[]
            {
                "IN",
                "OUT",
                "INOUT"
            });
            string         text           = row["SQL_MODE"].ToString();
            int            num            = 1;
            MySqlTokenizer mySqlTokenizer = new MySqlTokenizer(body);

            mySqlTokenizer.AnsiQuotes       = (text.IndexOf("ANSI_QUOTES") != -1);
            mySqlTokenizer.BackslashEscapes = (text.IndexOf("NO_BACKSLASH_ESCAPES") == -1);
            mySqlTokenizer.ReturnComments   = false;
            string text2 = mySqlTokenizer.NextToken();

            while (text2 != "(")
            {
                if (string.Compare(text2, "FUNCTION", StringComparison.OrdinalIgnoreCase) == 0 && nameToRestrict == null)
                {
                    parametersTable.AddRow();
                    ISSchemaProvider.InitParameterRow(row, parametersTable.Rows[0]);
                }
                text2 = mySqlTokenizer.NextToken();
            }
            text2 = mySqlTokenizer.NextToken();
            while (text2 != ")")
            {
                MySqlSchemaRow mySqlSchemaRow = parametersTable.NewRow();
                ISSchemaProvider.InitParameterRow(row, mySqlSchemaRow);
                mySqlSchemaRow["ORDINAL_POSITION"] = num++;
                string text3 = StringUtility.ToUpperInvariant(text2);
                if (!mySqlTokenizer.Quoted && list.Contains(text3))
                {
                    mySqlSchemaRow["PARAMETER_MODE"] = text3;
                    text2 = mySqlTokenizer.NextToken();
                }
                if (mySqlTokenizer.Quoted)
                {
                    text2 = text2.Substring(1, text2.Length - 2);
                }
                mySqlSchemaRow["PARAMETER_NAME"] = text2;
                text2 = this.ParseDataType(mySqlSchemaRow, mySqlTokenizer);
                if (text2 == ",")
                {
                    text2 = mySqlTokenizer.NextToken();
                }
                if (nameToRestrict == null || string.Compare(mySqlSchemaRow["PARAMETER_NAME"].ToString(), nameToRestrict, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    parametersTable.Rows.Add(mySqlSchemaRow);
                }
            }
            text2 = StringUtility.ToUpperInvariant(mySqlTokenizer.NextToken());
            if (string.Compare(text2, "RETURNS", StringComparison.OrdinalIgnoreCase) == 0)
            {
                MySqlSchemaRow mySqlSchemaRow2 = parametersTable.Rows[0];
                mySqlSchemaRow2["PARAMETER_NAME"] = "RETURN_VALUE";
                this.ParseDataType(mySqlSchemaRow2, mySqlTokenizer);
            }
        }
        private DataSet GetParameters(string procName)
        {
            // if we can use mysql.proc, then do so
            //if (Connection.Settings.UseProcedureBodies)
            DataSet ds = Connection.ProcedureCache.GetProcedure(Connection, procName);

            if(ds.Tables.Count == 2)
            {
                // if we got our parameters and our user says it is ok to use proc bodies
                // then just return them
                if (Connection.Settings.UseProcedureBodies) return ds;

                // we got the parameters, but ignore them.
                if(ds.Tables.Contains("Procedure Parameters"))
                    ds.Tables.Remove("Procedure Parameters");
            }

            // we were not able to retrieve parameter data so we have to make do by
            // adding the parameters from the command object to our table
            // we use an internal method to create our procedure parameters table.
            ISSchemaProvider sp = new ISSchemaProvider(Connection);
            DataTable pTable = sp.CreateParametersTable();
            ds.Tables.Add(pTable);

            // now we run through the parameters that were set and fill in the parameters table
            // the best we can
            int pos = 1;
            foreach (MySqlParameter p in command.Parameters)
            {
                // in this mode, all parameters must have their type set
                if (!p.TypeHasBeenSet)
                    throw new InvalidOperationException(Resources.NoBodiesAndTypeNotSet);

                DataRow row = pTable.NewRow();
                row["PARAMETER_NAME"] = p.ParameterName;
                row["PARAMETER_MODE"] = "IN";
                if (p.Direction == ParameterDirection.InputOutput)
                    row["PARAMETER_MODE"] = "INOUT";
                else if (p.Direction == ParameterDirection.Output)
                    row["PARAMETER_MODE"] = "OUT";
                else if (p.Direction == ParameterDirection.ReturnValue)
                {
                    row["PARAMETER_MODE"] = "OUT";
                    row["ORDINAL_POSITION"] = 0;
                }
                else
                    row["ORDINAL_POSITION"] = pos++;
                pTable.Rows.Add(row);
            }
            return ds;
        }
Пример #15
0
        public void GetProcedureParametersDoesNotRequireSelectFromMySqlProceduresTable()
        {
            if (Version < new Version(5, 5, 3)) return;

              suExecSQL(String.Format("GRANT ALL ON `{0}`.* to 'simpleuser' identified by 'simpleuser'", database0));
              execSQL("DROP PROCEDURE IF EXISTS spTest");
              execSQL(@"CREATE  PROCEDURE spTest(id INT, name VARCHAR(20))
                    BEGIN SELECT name; END");

              string connStr = GetConnectionString("simpleuser", "simpleuser", true) + ";use procedure bodies=false";

              using (MySqlConnection c = new MySqlConnection(connStr))
              {
            c.Open();

            string[] restrictions = new string[4];
            restrictions[1] = c.Database;
            restrictions[2] = "spTest";
            DataTable procTable = c.GetSchema("procedures", restrictions);
            ISSchemaProvider isp = new ISSchemaProvider(c);
            string[] rest = isp.CleanRestrictions(restrictions);

            MySqlSchemaCollection parametersTable = isp.GetProcedureParameters(rest, new MySqlSchemaCollection( procTable ));

            Assert.IsNotNull(parametersTable);
              }
        }
Пример #16
0
    private static ProcedureCacheEntry GetProcData(MySqlConnection connection, string spName)
    {
      string schema = String.Empty;
      string name = spName;

      int dotIndex = spName.IndexOf(".");
      if (dotIndex != -1)
      {
        schema = spName.Substring(0, dotIndex);
        name = spName.Substring(dotIndex + 1, spName.Length - dotIndex - 1);
      }

      string[] restrictions = new string[4];
      restrictions[1] = schema.Length > 0 ? schema : connection.CurrentDatabase();
      restrictions[2] = name;
      MySqlSchemaCollection proc = connection.GetSchemaCollection("procedures", restrictions);
      if (proc.Rows.Count > 1)
        throw new MySqlException(Resources.ProcAndFuncSameName);
      if (proc.Rows.Count == 0)
        throw new MySqlException(String.Format(Resources.InvalidProcName, name, schema));

      ProcedureCacheEntry entry = new ProcedureCacheEntry();
      entry.procedure = proc;

      // we don't use GetSchema here because that would cause another
      // query of procedures and we don't need that since we already
      // know the procedure we care about.
      ISSchemaProvider isp = new ISSchemaProvider(connection);
      string[] rest = isp.CleanRestrictions(restrictions);
      MySqlSchemaCollection parameters = isp.GetProcedureParameters(rest, proc);
      entry.parameters = parameters;

      return entry;
    }