public async Task <ISet <DatabaseObject> > GetExistingObjectsAsync()
        {
            var cmd = _connection.CreateCommand();

            cmd.Transaction = _transaction;
            cmd.CommandText = @"
Select
o.name as objectName,
s.name as schemaName,
o.[type] as objectType
From sys.objects o
inner join sys.schemas s
	on o.[schema_id] = s.[schema_id]
Where o.[type] in ('V', 'FN', 'IF', 'TF', 'P')

Union all

Select
t.name as objectName,
s.name as schemaName,
'TT' as objectType
From sys.types t
inner join sys.schemas s
	on t.[schema_id] = s.[schema_id]
Where t.is_user_defined = 1
";
            ISet <DatabaseObject> result = new HashSet <DatabaseObject>(new DatabaseObjectComparer());
            await _logger.LogMessageAsync("Executing query to find pre-existing objects.", SeverityLevel.Verbose);

            using (var reader = await cmd.ExecuteReaderAsync())
            {
                while (await reader.ReadAsync())
                {
                    result.Add(new TypedDatabaseObject(
                                   _serverName,
                                   _databaseName,
                                   await reader.GetFieldValueAsync <string>("schemaName"),
                                   await reader.GetFieldValueAsync <string>("objectName"),
                                   DatabaseIdentifierUtility.GetObjectTypeFromString(await reader.GetFieldValueAsync <string>("objectType"))));
                }
            }
            await _logger.LogMessageAsync("Found " + result.Count + " existing objects in the database's current state.", SeverityLevel.Verbose);

            return(result);
        }
Ejemplo n.º 2
0
 public TypedDatabaseObject GetDependency(string serverName, string databaseName)
 {
     return(new TypedDatabaseObject(serverName, databaseName, DependencySchemaName, DependencyName, DatabaseIdentifierUtility.GetObjectTypeFromString(DependencyType)));
 }