コード例 #1
0
ファイル: Column.cs プロジェクト: bencoveney/DatabaseObjects
 /// <summary>
 /// Initializes a new instance of the <see cref="Column" /> class.
 /// </summary>
 /// <param name="name">Name of the column.</param>
 /// <param name="type">The type.</param>
 /// <param name="ordinalPosition">The ordinal position.</param>
 /// <param name="columnDefault">The column default.</param>
 /// <param name="isNullable">if set to <c>true</c> the column can be set to null.</param>
 public Column(string name, SqlType type, int ordinalPosition, string columnDefault, bool isNullable)
 {
     // Populate member variables
     // A lot of the varibales here are duplicated from the tables class. maybe these columns should just be properties of the tables?
     this.Name = name;
     this.DataType = type;
     this.OrdinalPosition = ordinalPosition;
     this.ColumnDefault = columnDefault;
     this.IsNullable = isNullable;
 }
コード例 #2
0
ファイル: Routine.cs プロジェクト: bencoveney/DatabaseObjects
        /// <summary>
        /// Initializes a new instance of the <see cref="Routine"/> class.
        /// </summary>
        /// <param name="catalog">The catalog.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="name">The name.</param>
        /// <param name="routineType">Type of the routine.</param>
        /// <param name="returnType">Type of the return.</param>
        /// <param name="definition">The definition.</param>
        /// <param name="created">The created.</param>
        /// <param name="lastAltered">The last altered.</param>
        public Routine(string catalog, string schema, string name, RoutineType routineType, SqlType returnType, string definition, DateTime created, DateTime lastAltered)
        {
            this.Catalog = catalog;
            this.Schema = schema;
            this.Name = name;
            this.RoutineType = routineType;
            this.ReturnType = returnType;
            this.Definition = definition;
            this.Created = created;
            this.LastAltered = lastAltered;

            this.parameters = new Collection<RoutineParameter>();
        }
コード例 #3
0
ファイル: Column.cs プロジェクト: bencoveney/DatabaseObjects
        /// <summary>
        /// Loads the columns from the database for a specific table.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="dataProvider">The data provider.</param>
        /// <exception cref="System.ArgumentNullException">
        /// table;table cannot be null
        /// or
        /// dataProvider;dataProvider cannot be null
        /// </exception>
        public static void PopulateColumns(Table table, IObjectDataProvider dataProvider)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table", "table cannot be null");
            }

            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider", "dataProvider cannot be null");
            }

            using (IDataReader result = dataProvider.LoadColumnDataForTable(table))
            {
                while (result.Read())
                {
                    // Read the result data
                    string name = (string)result["COLUMN_NAME"];
                    int ordinalPosition = (int)result["ORDINAL_POSITION"];
                    string columnDefault = result.GetNullableString("COLUMN_DEFAULT");
                    bool isNullable = ((string)result["IS_NULLABLE"]).Equals("NO") ? false : true;

                    // Read the result data for the routine's return type
                    string dataType = (string)result["DATA_TYPE"];
                    int? characterMaximumLength = result.GetNullable<int>("CHARACTER_MAXIMUM_LENGTH");
                    int? numericPrecision = result.GetNullable<int>("NUMERIC_PRECISION");
                    int? numericPrecisionRadix = result.GetNullable<int>("NUMERIC_PRECISION_RADIX");
                    int? numericScale = result.GetNullable<int>("NUMERIC_SCALE");
                    int? dateTimePrecision = result.GetNullable<int>("DATETIME_PRECISION");
                    string characterSetName = result.GetNullableString("CHARACTER_SET_NAME");
                    string collationName = result.GetNullableString("COLLATION_NAME");

                    // Build the proper data structure for return type
                    SqlType type = new SqlType(dataType, characterMaximumLength, characterSetName, collationName, numericPrecision, numericPrecisionRadix, numericScale, dateTimePrecision);

                    // Build the new column
                    table.Columns.Add(new Column(name, type, ordinalPosition, columnDefault, isNullable));
                }
            }
        }
コード例 #4
0
ファイル: Routine.cs プロジェクト: bencoveney/DatabaseObjects
        /// <summary>
        /// Loads the routines from the database.
        /// </summary>
        /// <param name="dataProvider">The data provider.</param>
        /// <returns>
        /// The loaded routines.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">dataProvider;dataProvider cannot be null</exception>
        public static Collection<Routine> LoadFromDatabase(IObjectDataProvider dataProvider)
        {
            Collection<Routine> result = new Collection<Routine>();

            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider", "dataProvider cannot be null");
            }

            using (IDataReader reader = dataProvider.LoadRoutineData())
            {
                while (reader.Read())
                {
                    // Read the result data for the routine
                    string catalog = (string)reader["SPECIFIC_CATALOG"];
                    string schema = (string)reader["SPECIFIC_SCHEMA"];
                    string name = (string)reader["SPECIFIC_NAME"];
                    string routineTypeAsText = (string)reader["ROUTINE_TYPE"];
                    string definition = (string)reader["ROUTINE_DEFINITION"];
                    DateTime created = (DateTime)reader["CREATED"];
                    DateTime lastAltered = (DateTime)reader["LAST_ALTERED"];

                    // Build the proper data structure for routine type
                    RoutineType routineType = (RoutineType)Enum.Parse(typeof(RoutineType), routineTypeAsText, true);

                    // Build the proper data structure for return type
                    SqlType returnType = null;
                    if (!reader.IsDBNull("DATA_TYPE"))
                    {
                        // Read the result data for the routine's return type
                        string dataType = (string)reader["DATA_TYPE"];
                        int? characterMaximumLength = reader.GetNullable<int>("CHARACTER_MAXIMUM_LENGTH");
                        int? numericPrecision = reader.GetNullable<int>("NUMERIC_PRECISION");
                        int? numericPrecisionRadix = reader.GetNullable<int>("NUMERIC_PRECISION_RADIX");
                        int? numericScale = reader.GetNullable<int>("NUMERIC_SCALE");
                        int? dateTimePrecision = reader.GetNullable<int>("DATETIME_PRECISION");
                        string characterSetName = reader.GetNullableString("CHARACTER_SET_NAME");
                        string collationName = reader.GetNullableString("COLLATION_NAME");

                        returnType = new SqlType(dataType, characterMaximumLength, characterSetName, collationName, numericPrecision, numericPrecisionRadix, numericScale, dateTimePrecision);
                    }

                    // Build the new routine
                    Routine routine = new Routine(catalog, schema, name, routineType, returnType, definition, created, lastAltered);

                    result.Add(routine);
                }
            }

            // Populate parameters
            foreach (Routine routine in result)
            {
                RoutineParameter.PopulateParameters(routine, dataProvider);
            }

            return result;
        }