Exemple #1
0
        /// <summary>
        /// Prepares to import the given table valued function <paramref name="tableValuedFunction"/> as <see cref="TableInfo"/> / <see cref="ColumnInfo"/> references in the
        /// <paramref name="repository"/>.
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="tableValuedFunction"></param>
        /// <param name="usageContext"></param>
        public TableValuedFunctionImporter(ICatalogueRepository repository, DiscoveredTableValuedFunction tableValuedFunction, DataAccessContext usageContext = DataAccessContext.Any)
        {
            _repository          = repository;
            _tableValuedFunction = tableValuedFunction;
            _server   = _tableValuedFunction.Database.Server.Name;
            _database = _tableValuedFunction.Database.GetRuntimeName();
            _schema   = tableValuedFunction.Schema;

            _usageContext = usageContext;

            if (!_tableValuedFunction.Exists())
            {
                throw new Exception("Could not find tableValuedFunction with name '" + _tableValuedFunction.GetRuntimeName() + "' (.Exists() returned false)");
            }

            _tableValuedFunctionName = _tableValuedFunction.GetRuntimeName();

            _parameters = _tableValuedFunction.DiscoverParameters();

            ParametersCreated = new List <AnyTableSqlParameter>();
        }
 public override DiscoveredParameter[] DiscoverTableValuedFunctionParameters(DbConnection connection,
                                                                             DiscoveredTableValuedFunction discoveredTableValuedFunction, DbTransaction transaction)
 {
     throw new NotImplementedException();
 }
 public override void DropFunction(DbConnection connection, DiscoveredTableValuedFunction functionToDrop)
 {
     throw new NotImplementedException();
 }
        public override DiscoveredParameter[] DiscoverTableValuedFunctionParameters(DbConnection connection, DiscoveredTableValuedFunction discoveredTableValuedFunction, DbTransaction transaction)
        {
            List <DiscoveredParameter> toReturn = new List <DiscoveredParameter>();

            string query =
                @"select 
sys.parameters.name AS name,
sys.types.name AS TYPE_NAME,
sys.parameters.max_length AS LENGTH,
sys.types.collation_name AS COLLATION_NAME,
sys.parameters.scale AS SCALE,
sys.parameters.precision AS PRECISION
 from 
sys.parameters 
join
sys.types on sys.parameters.user_type_id = sys.types.user_type_id
where object_id = OBJECT_ID('" + GetObjectName(discoveredTableValuedFunction) + "')";

            using (DbCommand cmd = discoveredTableValuedFunction.GetCommand(query, connection))
            {
                cmd.Transaction = transaction;

                using (var r = cmd.ExecuteReader())
                {
                    while (r.Read())
                    {
                        DiscoveredParameter toAdd = new DiscoveredParameter(r["name"].ToString());
                        toAdd.DataType = new DiscoveredDataType(r, GetSQLType_FromSpColumnsResult(r), null);
                        toReturn.Add(toAdd);
                    }
                }
            }

            return(toReturn.ToArray());
        }
 public override void DropFunction(DbConnection connection, DiscoveredTableValuedFunction functionToDrop)
 {
     using (SqlCommand cmd = new SqlCommand($"DROP FUNCTION {functionToDrop.Schema??"dbo"}.{functionToDrop.GetRuntimeName()}", (SqlConnection)connection))
         cmd.ExecuteNonQuery();
 }
        public override void DropFunction(DbConnection connection, DiscoveredTableValuedFunction functionToDrop)
        {
            SqlCommand cmd = new SqlCommand("DROP FUNCTION " + functionToDrop.GetRuntimeName(), (SqlConnection)connection);

            cmd.ExecuteNonQuery();
        }