Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the schema.
        /// </summary>
        /// <returns></returns>
        // mbr - 02-10-2007 - added optional specification.
        public virtual SqlSchema GetSchema(GetSchemaArgs args)
        {
            // create...
            SqlSchema schema = new SqlSchema();

            // gets a datatable of information_schema...
            if (Connection == null)
            {
                throw new InvalidOperationException("Connection is null.");
            }

            // sql...
            SqlStatement sql = new SqlStatement(this.Dialect);

            // mbr - 02-10-2007 - build the sql, now including the search specification...
            StringBuilder builder = new StringBuilder();

            builder.Append("SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'");
            if (args.ConstrainTableNames.Count > 0)
            {
                builder.Append(" AND (");
                this.AppendTableNameConstraint(sql, builder, args.ConstrainTableNames);
                builder.Append(")");
            }
            if (args.ConstrainSchemaNames.Count > 0)
            {
                builder.Append(" AND (");
                this.AppendSchemaNameConstraint(sql, builder, args.ConstrainSchemaNames);
                builder.Append(")");
            }
            builder.Append(" ORDER BY TABLE_NAME");

            // get...
            sql.CommandText = builder.ToString();
            DataTable table = this.Connection.ExecuteDataTable(sql);

            // walk...
            foreach (DataRow row in table.Rows)
            {
                // create a new schema table...
                SqlTable schemaTable = this.GetSchemaTable(row, schema);
                schema.Tables.Add(schemaTable);

                // mbr - 04-10-2007 - set owner...
                schemaTable.SetSchema(schema);
            }

            // return...
            return(schema);
        }