예제 #1
0
        public override SqlSchema GetSchema(GetSchemaArgs args)
        {
            SqlSchema schema = base.GetSchema(args);

            if (schema == null)
            {
                throw new InvalidOperationException("schema is null.");
            }

            // mbr - 02-10-2007 - for c7 - if we have a search spec, don't do sprocs...
            if (args.ConstrainTableNames.Count == 0)
            {
                // mbr - 15-06-2006 - now do procedures...
                DataTable table = this.Connection.ExecuteDataTable(new SqlStatement("select specific_name, routine_definition from information_schema.routines where routine_type='PROCEDURE' order by specific_name",
                                                                                    this.Dialect));
                foreach (DataRow row in table.Rows)
                {
                    try
                    {
                        // create...
                        SqlProcedure proc = this.GetSchemaProcedure(schema, row);
                        schema.Procedures.Add(proc);
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException(string.Format("Failed to handle stored procedure '{0}'.\r\nBody: {1}", row["specific_name"], row["routine_definition"]), ex);
                    }
                }
            }

            // return...
            return(schema);
        }
예제 #2
0
 /// <summary>
 /// Removes a SqlProcedure item to the collection.
 /// </summary>
 /// <param name="item">The item to remove.</param>
 public void Remove(SqlProcedure item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     List.Remove(item);
 }
예제 #3
0
 /// <summary>
 /// Inserts a SqlProcedure instance into the collection.
 /// </summary>
 /// <param name="item">The item to add.</param>
 public void Insert(int index, SqlProcedure item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     List.Insert(index, item);
 }
예제 #4
0
 /// <summary>
 /// Adds a SqlProcedure instance to the collection.
 /// </summary>
 /// <param name="item">The item to add.</param>
 public int Add(SqlProcedure item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     return(List.Add(item));
 }
예제 #5
0
 /// <summary>
 /// Discovers if the given item is in the collection.
 /// </summary>
 /// <param name="item">The item to find.</param>
 /// <returns>Returns true if the given item is in the collection.</returns>
 public bool Contains(SqlProcedure item)
 {
     if (IndexOf(item) == -1)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
예제 #6
0
        private SqlProcedure GetSchemaProcedure(SqlSchema schema, DataRow row)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            // create...
            SqlProcedure proc = new SqlProcedure((string)row["specific_name"]);

            proc.Body = ConversionHelper.ToString(row["routine_definition"], Cultures.System);

            // handle...
            this.ParseProcedureBody(schema, proc);

            // return...
            return(proc);
        }
예제 #7
0
 /// <summary>
 /// Returns the index of the item in the collection.
 /// </summary>
 /// <param name="item">The item to find.</param>
 /// <returns>The index of the item, or -1 if it is not found.</returns>
 public int IndexOf(SqlProcedure item)
 {
     return(List.IndexOf(item));
 }
예제 #8
0
        private void ParseProcedureBody(SqlSchema schema, SqlProcedure proc)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (proc == null)
            {
                throw new ArgumentNullException("proc");
            }

            // reset...
            proc.Parameters.Clear();
            if (proc.Body == null || proc.Body.Length == 0)
            {
                return;
            }

            // add the params...
            Match asMatch = AsRegex.Match(proc.Body);

            if (asMatch.Success)
            {
                // header...
                string header = proc.Body.Substring(0, asMatch.Index);

                // get...
                foreach (Match paramMatch in ParamsRegex.Matches(header))
                {
                    string name = paramMatch.Groups["name"].Value;
                    if (name == null)
                    {
                        throw new InvalidOperationException("'name' is null.");
                    }
                    if (name.Length == 0)
                    {
                        throw new InvalidOperationException("'name' is zero-length.");
                    }

                    try
                    {
                        // type...
                        string typeName = paramMatch.Groups["type"].Value;
                        if (typeName == null)
                        {
                            throw new InvalidOperationException("'typeName' is null.");
                        }
                        if (typeName.Length == 0)
                        {
                            throw new InvalidOperationException("'typeName' is zero-length.");
                        }

                        // mbr - 26-02-2007 - is the type name parameterized?
                        typeName = typeName.ToLower();

                        // are we output?
                        const string outputDirective = " output";
                        if (typeName.EndsWith(outputDirective))
                        {
                            typeName = typeName.Substring(typeName.Length - outputDirective.Length).TrimEnd();
                        }

                        // field...
                        FieldSpecification spec = this.Connection.GetFieldSpecificationForNativeTypeName(typeName, false);
                        if (spec != null)
                        {
                            DbType dbType = spec.DbType;

                            // dimension et al...
                            string dimensionAsString    = paramMatch.Groups["dimension"].Value;
                            string defaultValueAsString = paramMatch.Groups["default"].Value;

                            // direction...
                            string             directionAsString = paramMatch.Groups["direction"].Value;
                            ParameterDirection direction         = ParameterDirection.Input;
                            if (directionAsString != null && directionAsString.Length > 0)
                            {
                                directionAsString = directionAsString.ToLower();
                                if (directionAsString.StartsWith("out"))
                                {
                                    direction = ParameterDirection.Output;
                                }
                            }

                            // value...
                            object defaultValue = DBNull.Value;

                            // create...
                            proc.Parameters.Add(new SqlStatementParameter(name, dbType, defaultValue, direction));
                        }
                        else
                        {
                            proc.Parameters.Add(new SqlStatementParameter(name, DbType.Object, DBNull.Value));
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException(string.Format("Failed when processing parameter '{0}'\r\nText: {1}", name, paramMatch.Value), ex);
                    }
                }
            }
        }