Beispiel #1
0
        public MySmo.Database GetDatabase(Smo.Database smo_db, MySmo.Server parent = null)
        {
            #region implement

            var mysmo_db = new MySmo.Database();

            mysmo_db.ParentServer          = parent;
            mysmo_db.Name                  = smo_db.Name;
            mysmo_db.Owner                 = smo_db.Owner;
            mysmo_db.CreateTime            = smo_db.CreateDate;
            mysmo_db.ExtendedProperties    = GetExtendProperties(mysmo_db, smo_db.ExtendedProperties);
            mysmo_db.Schemas               = GetSchemas(smo_db, mysmo_db);
            mysmo_db.Tables                = GetTables(smo_db, mysmo_db);
            mysmo_db.Views                 = GetViews(smo_db, mysmo_db);
            mysmo_db.UserDefinedFunctions  = GetUserDefinedFunctions(smo_db, mysmo_db);
            mysmo_db.UserDefinedTableTypes = GetUserDefinedTableTypes(smo_db, mysmo_db);
            mysmo_db.StoredProcedures      = GetStoredProcedures(smo_db, mysmo_db);
            mysmo_db.CompatibilityLevel    = (MySmo.CompatibilityLevel)(int) smo_db.CompatibilityLevel;

            CombineExtendProperties(mysmo_db);

            return(mysmo_db);

            #endregion
        }
Beispiel #2
0
        public List <MySmo.StoredProcedure> GetStoredProcedures(Smo.Database smo_db, MySmo.Database parent = null)
        {
            #region implement

            return(new List <MySmo.StoredProcedure>(
                       from Smo.StoredProcedure o in smo_db.StoredProcedures
                       where o.IsSystemObject == false
                       select GetStoredProcedure(o, parent)
                       ));

            #endregion
        }
Beispiel #3
0
        public List <MySmo.View> GetViews(Smo.Database smo_db, MySmo.Database parent = null)
        {
            #region implement

            return(new List <MySmo.View>(
                       from Smo.View o in smo_db.Views
                       where o.IsSystemObject == false
                       select GetView(o, parent)
                       ));

            #endregion
        }
Beispiel #4
0
        public List <MySmo.Schema> GetSchemas(Smo.Database smo_db, MySmo.Database parent = null)
        {
            #region implement

            return(new List <MySmo.Schema>(
                       from Smo.Schema o in smo_db.Schemas
                       where o.IsSystemObject == false || o.Name == "dbo"
                       select GetSchema(o, parent)
                       ));

            #endregion
        }
Beispiel #5
0
        public MySmo.StoredProcedure GetStoredProcedure(Smo.StoredProcedure smo_sp, MySmo.Database parent = null)
        {
            #region implement

            SetDataLimit();

            var mysmo_sp = new MySmo.StoredProcedure();

            mysmo_sp.ParentDatabase     = parent;
            mysmo_sp.Name               = smo_sp.Name;
            mysmo_sp.Schema             = smo_sp.Schema;
            mysmo_sp.CreateTime         = smo_sp.CreateDate;
            mysmo_sp.Owner              = smo_sp.Owner;
            mysmo_sp.ExtendedProperties = GetExtendProperties(mysmo_sp, smo_sp.ExtendedProperties);
            var s = "";
            if (mysmo_sp.ExtendedProperties.TryGetValue(K_MS_Description, out s))
            {
                mysmo_sp.Description = s;
                mysmo_sp.ExtendedProperties.Remove(K_MS_Description);
            }
            mysmo_sp.Parameters = new List <MySmo.Parameter>();
            foreach (Smo.StoredProcedureParameter smo_p in smo_sp.Parameters)
            {
                var mysmo_p = new MySmo.Parameter
                {
                    ParentDatabase      = parent,
                    ParentParameterBase = mysmo_sp,
                    Name              = smo_p.Name.Substring(1),
                    DefaultValue      = smo_p.DefaultValue,
                    IsOutputParameter = smo_p.IsOutputParameter,
                    IsReadOnly        = smo_p.IsReadOnly,
                    DataType          = new MySmo.DataType
                    {
                        Name             = smo_p.DataType.Name,
                        Schema           = smo_p.DataType.Schema,
                        MaximumLength    = smo_p.DataType.MaximumLength,
                        NumericPrecision = smo_p.DataType.NumericPrecision,
                        NumericScale     = smo_p.DataType.NumericScale,
                        SqlDataType      = (MySmo.SqlDataType)(int) smo_p.DataType.SqlDataType
                    }
                };
                mysmo_sp.Parameters.Add(mysmo_p);
            }

            FormatExtendProperties(mysmo_sp);

            return(mysmo_sp);

            #endregion
        }
Beispiel #6
0
        public MySmo.View GetView(Smo.View smo_v, MySmo.Database parent = null)
        {
            #region implement

            SetDataLimit();

            var mysmo_v = new MySmo.View();
            mysmo_v.ParentDatabase     = parent;
            mysmo_v.Name               = smo_v.Name;
            mysmo_v.Schema             = smo_v.Schema;
            mysmo_v.CreateTime         = smo_v.CreateDate;
            mysmo_v.Owner              = smo_v.Owner;
            mysmo_v.TriggersCount      = smo_v.Triggers.Count;
            mysmo_v.ExtendedProperties = GetExtendProperties(mysmo_v, smo_v.ExtendedProperties);
            var s = "";
            if (mysmo_v.ExtendedProperties.TryGetValue(K_MS_Description, out s))
            {
                mysmo_v.Description = s;
                mysmo_v.ExtendedProperties.Remove(K_MS_Description);
            }
            mysmo_v.Columns = new List <MySmo.Column>();
            foreach (Smo.Column smo_c in smo_v.Columns)
            {
                var mysmo_c = new MySmo.Column
                {
                    ParentDatabase    = parent,
                    ParentTableBase   = mysmo_v,
                    Name              = smo_c.Name,
                    DataType          = GetDataType(smo_c),
                    Computed          = smo_c.Computed,
                    ComputedText      = smo_c.ComputedText,
                    Default           = smo_c.Default,
                    Identity          = smo_c.Identity,
                    IdentityIncrement = smo_c.IdentityIncrement,
                    IdentitySeed      = smo_c.IdentitySeed,
                    InPrimaryKey      = smo_c.InPrimaryKey,
                    IsForeignKey      = smo_c.IsForeignKey,
                    Nullable          = smo_c.Nullable,
                    RowGuidCol        = smo_c.RowGuidCol
                };
                mysmo_v.Columns.Add(mysmo_c);
            }
            FormatExtendProperties(mysmo_v);

            return(mysmo_v);

            #endregion
        }
Beispiel #7
0
        public MySmo.Schema GetSchema(Smo.Schema smo_s, MySmo.Database parent = null)
        {
            #region implement

            SetDataLimit();

            var mysmo_s = new MySmo.Schema();

            mysmo_s.ParentDatabase     = parent;
            mysmo_s.Name               = smo_s.Name;
            mysmo_s.Owner              = smo_s.Owner;
            mysmo_s.ExtendedProperties = GetExtendProperties(mysmo_s, smo_s.ExtendedProperties);

            FormatExtendProperties(mysmo_s);

            return(mysmo_s);

            #endregion
        }
Beispiel #8
0
        public List <MySmo.UserDefinedTableType> GetUserDefinedTableTypes(Smo.Database smo_db, MySmo.Database parent = null)
        {
            #region implement

            return(new List <MySmo.UserDefinedTableType>(
                       from Smo.UserDefinedTableType o in smo_db.UserDefinedTableTypes
                       select GetUserDefinedTableType(o, parent)
                       ));

            #endregion
        }
Beispiel #9
0
        public List <MySmo.UserDefinedFunction> GetUserDefinedFunctions(Smo.Database smo_db, MySmo.Database parent = null)
        {
            #region implement

            return(new List <MySmo.UserDefinedFunction>(
                       from Smo.UserDefinedFunction o in smo_db.UserDefinedFunctions
                       where o.IsSystemObject == false
                       select GetUserDefinedFunction(o, parent)
                       ));

            #endregion
        }
Beispiel #10
0
        public MySmo.UserDefinedFunction GetUserDefinedFunction(Smo.UserDefinedFunction smo_f, MySmo.Database parent = null)
        {
            #region implement

            SetDataLimit();

            var mysmo_f = new MySmo.UserDefinedFunction();

            mysmo_f.ParentDatabase     = parent;
            mysmo_f.Name               = smo_f.Name;
            mysmo_f.Schema             = smo_f.Schema;
            mysmo_f.CreateTime         = smo_f.CreateDate;
            mysmo_f.Owner              = smo_f.Owner;
            mysmo_f.ExtendedProperties = GetExtendProperties(mysmo_f, smo_f.ExtendedProperties);
            var s = "";
            if (mysmo_f.ExtendedProperties.TryGetValue(K_MS_Description, out s))
            {
                mysmo_f.Description = s;
                mysmo_f.ExtendedProperties.Remove(K_MS_Description);
            }
            mysmo_f.Parameters = new List <MySmo.Parameter>();
            foreach (Smo.UserDefinedFunctionParameter smo_p in smo_f.Parameters)
            {
                var mysmo_p = new MySmo.Parameter
                {
                    ParentDatabase      = parent,
                    ParentParameterBase = mysmo_f,
                    Name              = smo_p.Name.Substring(1),
                    DefaultValue      = smo_p.DefaultValue,
                    IsOutputParameter = false,
                    IsReadOnly        = smo_p.IsReadOnly,
                    DataType          = new MySmo.DataType
                    {
                        Name             = smo_p.DataType.Name,
                        Schema           = smo_p.DataType.Schema,
                        MaximumLength    = smo_p.DataType.MaximumLength,
                        NumericPrecision = smo_p.DataType.NumericPrecision,
                        NumericScale     = smo_p.DataType.NumericScale,
                        SqlDataType      = (MySmo.SqlDataType)(int) smo_p.DataType.SqlDataType
                    }
                };
                mysmo_f.Parameters.Add(mysmo_p);
            }
            if (smo_f.FunctionType == Smo.UserDefinedFunctionType.Table)
            {
                mysmo_f.Columns = new List <MySmo.Column>();
                foreach (Smo.Column smo_c in smo_f.Columns)
                {
                    var mysmo_c = new MySmo.Column
                    {
                        ParentDatabase    = parent,
                        ParentTableBase   = mysmo_f,
                        Name              = smo_c.Name,
                        DataType          = GetDataType(smo_c),
                        Computed          = smo_c.Computed,
                        ComputedText      = smo_c.ComputedText,
                        Default           = smo_c.Default,
                        Identity          = smo_c.Identity,
                        IdentityIncrement = smo_c.IdentityIncrement,
                        IdentitySeed      = smo_c.IdentitySeed,
                        InPrimaryKey      = smo_c.InPrimaryKey,
                        IsForeignKey      = smo_c.IsForeignKey,
                        Nullable          = smo_c.Nullable,
                        RowGuidCol        = smo_c.RowGuidCol
                    };
                    mysmo_f.Columns.Add(mysmo_c);
                }
            }
            FormatExtendProperties(mysmo_f);

            return(mysmo_f);

            #endregion
        }
Beispiel #11
0
        public MySmo.Table GetTable(Smo.Table smo_t, MySmo.Database parent = null)
        {
            #region implement
            SetDataLimit();

            var mysmo_t = new MySmo.Table();
            mysmo_t.ParentDatabase     = parent;
            mysmo_t.Name               = smo_t.Name;
            mysmo_t.Schema             = smo_t.Schema;
            mysmo_t.CreateTime         = smo_t.CreateDate;
            mysmo_t.Owner              = smo_t.Owner;
            mysmo_t.TriggersCount      = smo_t.Triggers.Count;
            mysmo_t.ExtendedProperties = GetExtendProperties(mysmo_t, smo_t.ExtendedProperties);
            var s = "";
            if (mysmo_t.ExtendedProperties.TryGetValue(K_MS_Description, out s))
            {
                mysmo_t.Description = s;
                mysmo_t.ExtendedProperties.Remove(K_MS_Description);
            }
            mysmo_t.Columns = new List <MySmo.Column>();
            foreach (Smo.Column smo_c in smo_t.Columns)
            {
                var mysmo_c = new MySmo.Column
                {
                    ParentDatabase    = parent,
                    ParentTableBase   = mysmo_t,
                    Name              = smo_c.Name,
                    DataType          = GetDataType(smo_c),
                    Computed          = smo_c.Computed,
                    ComputedText      = smo_c.ComputedText,
                    Default           = smo_c.Default,
                    Identity          = smo_c.Identity,
                    IdentityIncrement = smo_c.IdentityIncrement,
                    IdentitySeed      = smo_c.IdentitySeed,
                    InPrimaryKey      = smo_c.InPrimaryKey,
                    IsForeignKey      = smo_c.IsForeignKey,
                    Nullable          = smo_c.Nullable,
                    RowGuidCol        = smo_c.RowGuidCol
                };
                mysmo_c.DefaultConstraint  = GetDefaultConstraint(smo_c, mysmo_c, parent);
                mysmo_c.ExtendedProperties = GetExtendProperties(mysmo_c, smo_c.ExtendedProperties);
                s = "";
                if (mysmo_c.ExtendedProperties.TryGetValue(K_MS_Description, out s))
                {
                    mysmo_c.Description = s;
                    mysmo_c.ExtendedProperties.Remove(K_MS_Description);
                }
                mysmo_t.Columns.Add(mysmo_c);
            }
            mysmo_t.ForeignKeys = new List <MySmo.ForeignKey>();
            foreach (Smo.ForeignKey smo_fk in smo_t.ForeignKeys)
            {
                var mysmo_fk = new MySmo.ForeignKey
                {
                    ParentDatabase              = parent,
                    Columns                     = new List <MySmo.ForeignKeyColumn>(),
                    CreateTime                  = smo_fk.CreateDate,
                    DeleteAction                = (MySmo.ForeignKeyAction)(int) smo_fk.DeleteAction,
                    IsChecked                   = smo_fk.IsChecked,
                    IsEnabled                   = smo_fk.IsEnabled,
                    IsSystemNamed               = smo_fk.IsSystemNamed,
                    Name                        = smo_fk.Name,
                    NotForReplication           = smo_fk.NotForReplication,
                    ParentTable                 = mysmo_t,
                    ReferencedKey               = smo_fk.ReferencedKey,
                    ReferencedTable             = smo_fk.ReferencedTable,
                    ReferencedTableSchema       = smo_fk.ReferencedTableSchema,
                    ScriptReferencedTable       = smo_fk.ScriptReferencedTable,
                    ScriptReferencedTableSchema = smo_fk.ScriptReferencedTableSchema,
                    UpdateAction                = (MySmo.ForeignKeyAction)(int) smo_fk.UpdateAction
                };
                foreach (Smo.ForeignKeyColumn smo_fkc in smo_fk.Columns)
                {
                    var mysmo_fkc = new MySmo.ForeignKeyColumn
                    {
                        ParentDatabase   = parent,
                        Name             = smo_fkc.Name,
                        ParentForeignKey = mysmo_fk,
                        ReferencedColumn = smo_fkc.ReferencedColumn
                    };
                    mysmo_fk.Columns.Add(mysmo_fkc);
                }
                mysmo_fk.ExtendedProperties = GetExtendProperties(mysmo_fk, smo_fk.ExtendedProperties);
                mysmo_t.ForeignKeys.Add(mysmo_fk);
            }
            FormatExtendProperties(mysmo_t);

            return(mysmo_t);

            #endregion
        }
Beispiel #12
0
        public MySmo.DefaultConstraint GetDefaultConstraint(Smo.Column smo_c, MySmo.Column parentColumn, MySmo.Database parentDatabase = null)
        {
            var dc = smo_c.DefaultConstraint;

            if (dc == null)
            {
                return(null);
            }
            var result = new MySmo.DefaultConstraint
            {
                CreateTime     = dc.CreateDate,
                IsSystemNamed  = dc.IsSystemNamed,
                Name           = dc.Name,
                Text           = dc.Text,
                ParentColumn   = parentColumn,
                ParentDatabase = parentDatabase
            };

            result.ExtendedProperties = GetExtendProperties(result, dc.ExtendedProperties);
            return(result);
        }