Exemplo n.º 1
0
 public TableKeySchema(DatabaseSchema database, string name, string[] foreignKeyMemberColumns, string foreignKeyTableOwner, string foreignKeyTable, string[] primaryKeyMemberColumns, string primaryKeyTableOwner, string primaryKeyTable)
 {
     this.database = database;
     this.name = name;
     if (foreignKeyTableOwner.Length > 0)
     {
         this.foreignKeyTable = this.Database.Tables.Where(p => p.Owner == foreignKeyTableOwner && p.Name == foreignKeyTable).FirstOrDefault();
     }
     else
     {
         this.foreignKeyTable = this.Database.Tables.Where(p => p.Name == foreignKeyTable).FirstOrDefault();
     }
     this.foreignKeyMemberColumns = new List<MemberColumnSchema>();
     for (int i = 0; i < foreignKeyMemberColumns.Length; i++)
     {
         string name2 = foreignKeyMemberColumns[i];
         this.foreignKeyMemberColumns.Add(new MemberColumnSchema(this.foreignKeyTable.Columns.Where(p => p.Name == name2).FirstOrDefault()));
     }
     if (primaryKeyTableOwner.Length > 0)
     {
         this.primaryKeyTable = this.Database.Tables.Where(p => p.Owner == foreignKeyTableOwner && p.Name == foreignKeyTable).FirstOrDefault();
     }
     else
     {
         this.primaryKeyTable = this.Database.Tables.Where(p => p.Name == foreignKeyTable).FirstOrDefault();
     }
     this.frimaryKeyMemberColumns = new List<MemberColumnSchema>();
     for (int j = 0; j < primaryKeyMemberColumns.Length; j++)
     {
         string name3 = primaryKeyMemberColumns[j];
         this.frimaryKeyMemberColumns.Add(new MemberColumnSchema(this.primaryKeyTable.Columns.Where(p => p.Name == name3).FirstOrDefault()));
     }
     this.extendedProperties = new List<ExtendedProperty>();
 }
Exemplo n.º 2
0
 public ViewSchema(DatabaseSchema database, string name, string owner, DateTime dateCreated)
 {
     this.database = database;
     this.name = name;
     this.owner = owner;
     this.dateCreated = dateCreated;
 }
Exemplo n.º 3
0
 public ViewSchema(DatabaseSchema database, string name, string owner, DateTime dateCreated, ExtendedProperty[] extendedProperties)
     : this(database, name, owner, dateCreated)
 {
     this.extendedProperties = new List<ExtendedProperty>();
     this.extendedProperties.AddRange(extendedProperties);
 }
Exemplo n.º 4
0
 public TableKeySchema(DatabaseSchema database, string name, string[] foreignKeyMemberColumns, string foreignKeyTableOwner, string foreignKeyTable, string[] primaryKeyMemberColumns, string primaryKeyTableOwner, string primaryKeyTable, ExtendedProperty[] extendedProperties)
     : this(database, name, foreignKeyMemberColumns, foreignKeyTableOwner, foreignKeyTable, primaryKeyMemberColumns, primaryKeyTableOwner, primaryKeyTable)
 {
     this.extendedProperties = new List<ExtendedProperty>();
     this.extendedProperties.AddRange(extendedProperties);
 }
Exemplo n.º 5
0
 public TableKeySchema(DatabaseSchema database, string name, string[] foreignKeyMemberColumns, string foreignKeyTable, string[] primaryKeyMemberColumns, string primaryKeyTable)
     : this(database, name, foreignKeyMemberColumns, string.Empty, foreignKeyTable, primaryKeyMemberColumns, string.Empty, primaryKeyTable)
 {
 }
Exemplo n.º 6
0
		public CommandSchema[] GetCommands(string connectionString, DatabaseSchema database)
		{
			string commandText = string.Format("SELECT ROUTINE_NAME, '' OWNER, CREATED FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_CATALOG = '{0}' AND ROUTINE_TYPE = 'PROCEDURE' ORDER BY 1", database.Name);
			List<CommandSchema> list = new List<CommandSchema>();
			using (DbConnection dbConnection = MsSqlSchemaProvider.CreateConnection(connectionString))
			{
				dbConnection.Open();
				DbCommand dbCommand = dbConnection.CreateCommand();
				dbCommand.CommandText = commandText;
				dbCommand.Connection = dbConnection;
				using (IDataReader dataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection))
				{
					while (dataReader.Read())
					{
						list.Add(new CommandSchema(database, dataReader.GetString(0), dataReader.GetString(1), dataReader.GetDateTime(2)));
					}
					if (!dataReader.IsClosed)
					{
						dataReader.Close();
					}
				}
				if (dbConnection.State != ConnectionState.Closed)
				{
					dbConnection.Close();
				}
			}
			return list.ToArray();
		}
Exemplo n.º 7
0
		public ViewSchema[] GetViews(string connectionString, DatabaseSchema database)
		{
			string commandText = string.Format("SELECT  TABLE_NAME, '' OWNER, NULL as CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG = '{0}' AND TABLE_TYPE = 'VIEW' ORDER BY 1", database.Name);
			List<ViewSchema> list = new List<ViewSchema>();
			using (DbConnection dbConnection = MsSqlSchemaProvider.CreateConnection(connectionString))
			{
				dbConnection.Open();
				DbCommand dbCommand = dbConnection.CreateCommand();
				dbCommand.CommandText = commandText;
				dbCommand.Connection = dbConnection;
				using (IDataReader dataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection))
				{
					while (dataReader.Read())
					{
						DateTime dateCreated = (!dataReader.IsDBNull(2)) ? dataReader.GetDateTime(2) : DateTime.Parse("2011-01-01");
						list.Add(new ViewSchema(database, dataReader.GetString(0), dataReader.GetString(1), dateCreated));
					}
					if (!dataReader.IsClosed)
					{
						dataReader.Close();
					}
				}
				if (dbConnection.State != ConnectionState.Closed)
				{
					dbConnection.Close();
				}
			}
			return list.ToArray();
		}
Exemplo n.º 8
0
        /// <summary>
        /// 获取当前数据库架构信息
        /// </summary>
        /// <returns></returns>
        protected virtual DatabaseSchema GetDatabase()
        {
            DatabaseSchema db = null;
            switch (DMContext.ProviderType)
            {
                case EnumProviderType.Access:
                    break;

                case EnumProviderType.MsSql:
                    db = new DatabaseSchema(new MsSqlSchemaProvider(), DMContext.DefaultConnectionString);
                    break;

                case EnumProviderType.MySql:
                    db = new DatabaseSchema(new MySqlSchemaProvider(), DMContext.DefaultConnectionString);
                    break;

                default:
                    break;
            }

            if (db == null)
            {
                throw new NotSupportedException("不支持的数据库类型!");
            }

            return db;
        }