Esempio n. 1
0
 public ProcedureSchema(ProcedureSchema proc)
     : base(proc)
 {
     this.parameters        = new ParameterSchemaCollection(parameters);
     this.language          = proc.language;
     this.isSystemProcedure = proc.isSystemProcedure;
 }
        public virtual ParameterSchemaCollection GetProcedureParameters(ProcedureSchema procedure)
        {
            ParameterSchemaCollection collection = new ParameterSchemaCollection();

            IPooledDbConnection conn = connectionPool.Request();

            try {
                //restrictions: database, schema, name, type, parameter
                DataTable dt = conn.GetSchema(procedureParametersCollectionString, null, procedure.SchemaName, procedure.Name);
                for (int r = 0; r < dt.Rows.Count; r++)
                {
                    DataRow row = dt.Rows[r];
                    collection.Add(GetProcedureParameter(row, procedure));
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(collection);
        }
        public override ParameterSchemaCollection GetProcedureParameters(ProcedureSchema procedure)
        {
            ParameterSchemaCollection parameters = new ParameterSchemaCollection();

            // FIXME: Won't work properly with overload functions.
            // Maybe check the number of columns in the parameters for
            // proper match.
            IPooledDbConnection conn    = connectionPool.Request();
            IDbCommand          command = conn.CreateCommand(String.Format(
                                                                 "SELECT format_type (prorettype, NULL) "
                                                                 + "FROM pg_proc pc, pg_language pl "
                                                                 + "WHERE pc.prolang = pl.oid "
                                                                 + "AND pc.proname = '{0}';", procedure.Name
                                                                 ));

            try {
                using (command) {
                    using (IDataReader r = command.ExecuteReader()) {
                        while (r.Read())
                        {
                            ParameterSchema param = new ParameterSchema(this);

                            param.DataTypeName = r.GetString(0);
                            param.Name         = r.GetString(0);
                            parameters.Add(param);
                        }
                        r.Close();
                    }
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(parameters);
        }
 public ParameterSchemaCollection(ParameterSchemaCollection collection)
     : base(collection, false)
 {
 }
        public override ParameterSchemaCollection GetProcedureParameters(ProcedureSchema procedure)
        {
            ParameterSchemaCollection parameters = new ParameterSchemaCollection();

            IPooledDbConnection conn    = connectionPool.Request();
            IDbCommand          command = conn.CreateCommand(
                "SELECT param_list FROM mysql.proc where name = '" + procedure.Name + "'"
                );

            try {
                using (command) {
                    if (GetMainVersion(command) >= 5)
                    {
                        using (IDataReader r = command.ExecuteReader()) {
                            while (r.Read())
                            {
                                if (r.IsDBNull(0))
                                {
                                    continue;
                                }

                                string[] field = Encoding.ASCII.GetString((byte[])r.GetValue(0)).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string chunk in field)
                                {
                                    ParameterSchema param = new ParameterSchema(this);
                                    param.Definition = chunk;

                                    string[] tmp       = chunk.TrimStart(new char[] { ' ' }).Split(new char[] { ' ' });
                                    int      nameIndex = 0;
                                    if (String.Compare(tmp[0], "OUT", true) == 0)
                                    {
                                        nameIndex           = 1;
                                        param.ParameterType = ParameterType.Out;
                                    }
                                    else if (String.Compare(tmp[0], "INOUT", true) == 0)
                                    {
                                        nameIndex           = 1;
                                        param.ParameterType = ParameterType.InOut;
                                    }
                                    else
                                    {
                                        param.ParameterType = ParameterType.In;
                                    }

                                    param.Name         = tmp[nameIndex];
                                    param.OwnerName    = procedure.Name;
                                    param.DataTypeName = tmp[nameIndex + 1];

                                    parameters.Add(param);
                                }
                            }
                            r.Close();
                        }
                    }                     //else: do nothing, since procedures are only supported since mysql 5.x
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(parameters);
        }