private void CreateResult(ResultType resultType, DatabaseFunction function, string script)
 {
     var result = new CompareResult
         {
             SchemaObjectType = SchemaObjectType.Function,
             ResultType = resultType,
             Name = function.Name,
             SchemaOwner = function.SchemaOwner,
             Script = script
         };
     _results.Add(result);
 }
        public override string AddFunction(DatabaseFunction databaseFunction)
        {
            if (string.IsNullOrEmpty(databaseFunction.Sql))
            {
                //the function.Sql contains the BEGIN to END statements, not the CREATE FUNCTION and arguments.
                //for now, just comment
                return "-- add function " + databaseFunction.Name;
            }

            var name = databaseFunction.Name;
            var procWriter = new ProcedureWriter(name, true);
            procWriter.AddReturns(databaseFunction.ReturnType);
            WriteProcedure(databaseFunction, procWriter);

            return procWriter.End();

        }
        public static List<DatabaseFunction> Functions(DataTable dt)
        {
            List<DatabaseFunction> list = new List<DatabaseFunction>();

            var functionKeyMap = new FunctionKeyMap(dt);
            foreach (DataRow row in dt.Rows)
            {
                DatabaseFunction fun = new DatabaseFunction();
                fun.Name = row[functionKeyMap.Key].ToString();
                if (!string.IsNullOrEmpty(functionKeyMap.OwnerKey))
                    fun.SchemaOwner = row[functionKeyMap.OwnerKey].ToString();
                if (functionKeyMap.SqlKey != null) fun.Sql = row[functionKeyMap.SqlKey].ToString();
                if (functionKeyMap.LangKey != null) fun.Language = row[functionKeyMap.LangKey].ToString();
                if (functionKeyMap.ReturnKey != null) fun.ReturnType = row[functionKeyMap.ReturnKey].ToString();
                list.Add(fun);
            }
            return list;
        }
 private static DatabaseStoredProcedure CreateProcedureOrFunction(DatabaseSchema databaseSchema, List<DatabaseArgument> args)
 {
     //if it's ordinal 0 and no name, it's a function not a sproc
     DatabaseStoredProcedure sproc;
     if (args.Find(delegate(DatabaseArgument arg) { return arg.Ordinal == 0 && string.IsNullOrEmpty(arg.Name); }) != null)
     {
         //functions are just a type of stored procedure
         DatabaseFunction fun = new DatabaseFunction();
         databaseSchema.Functions.Add(fun);
         sproc = fun;
     }
     else
     {
         sproc = new DatabaseStoredProcedure();
         databaseSchema.StoredProcedures.Add(sproc);
     }
     return sproc;
 }
 private static DatabaseStoredProcedure CreateProcedureOrFunction(DatabaseSchema databaseSchema, bool isFunction)
 {
     DatabaseStoredProcedure sproc;
     if (isFunction)
     {
         //functions are just a type of stored procedure
         DatabaseFunction fun = new DatabaseFunction();
         databaseSchema.Functions.Add(fun);
         sproc = fun;
     }
     else
     {
         sproc = new DatabaseStoredProcedure();
         databaseSchema.StoredProcedures.Add(sproc);
     }
     return sproc;
 }
 public virtual string AddFunction(DatabaseFunction databaseFunction)
 {
     var sql = databaseFunction.Sql;
     if (string.IsNullOrEmpty(sql))
     {
         //without the sql, we can't do anything
         return "-- add function " + databaseFunction.Name;
     }
     if (sql.TrimStart().StartsWith("FUNCTION ", StringComparison.OrdinalIgnoreCase))
     {
         return "CREATE " + sql + _sqlFormatProvider.RunStatements();
     }
     //helpfully, SqlServer includes the create statement
     //MySQL doesn't, so this will need to be overridden
     return sql + _sqlFormatProvider.RunStatements();
 }
 public virtual string DropFunction(DatabaseFunction databaseFunction)
 {
     return "DROP FUNCTION " + SchemaPrefix(databaseFunction.SchemaOwner) + Escape(databaseFunction.Name) + ";"
         + _sqlFormatProvider.RunStatements();
 }
 public string AddFunction(DatabaseFunction function)
 {
     return _migration.AddFunction(function);
 }
 public string DropFunction(DatabaseFunction function)
 {
     return _migration.DropFunction(function);
 }
 public override string DropFunction(DatabaseFunction databaseFunction)
 {
     return null; //doesn't support it
 }
示例#11
0
 public void BuildFunction(DatabaseFunction databaseFunction)
 {
     try
     {
         var txt = _migrationGenerator.AddFunction(databaseFunction);
         Clipboard.SetText(txt, TextDataFormat.UnicodeText);
     }
     catch (Exception exception)
     {
         Debug.WriteLine(exception.Message);
     }
 }