GenerateSQL() public method

public GenerateSQL ( System.Data.Common.CommandTrees.DbCommandTree commandTree ) : string
commandTree System.Data.Common.CommandTrees.DbCommandTree
return string
Esempio n. 1
0
        protected virtual MigrationStatement Generate(HistoryOperation op)
        {
            if (op == null)
            {
                return(null);
            }

            MigrationStatement stmt = new MigrationStatement();

            var          cmdStr    = "";
            SqlGenerator generator = new SelectGenerator();

            foreach (var commandTree in op.CommandTrees)
            {
                switch (commandTree.CommandTreeKind)
                {
                case DbCommandTreeKind.Insert:
                    generator = new InsertGenerator();
                    break;

                case DbCommandTreeKind.Delete:
                    generator = new DeleteGenerator();
                    break;

                case DbCommandTreeKind.Update:
                    generator = new UpdateGenerator();
                    break;

                case DbCommandTreeKind.Query:
                    generator = new SelectGenerator();
                    break;

                case DbCommandTreeKind.Function:
                    generator = new FunctionGenerator();
                    break;

                default:
                    throw new NotImplementedException(commandTree.CommandTreeKind.ToString());
                }
                cmdStr = generator.GenerateSQL(commandTree);

                ReplaceParemeters(ref cmdStr, generator.Parameters);
                stmt.Sql += cmdStr.Replace("dbo", "") + ";";
            }
            return(stmt);
        }
Esempio n. 2
0
        public override string GenerateProcedureBody(ICollection <DbModificationCommandTree> commandTrees, string rowsAffectedParameter, string providerManifestToken)
        {
            MySqlConnection    con  = new MySqlConnection();
            MigrationStatement stmt = new MigrationStatement();

            _providerManifest = DbProviderServices.GetProviderServices(con).GetProviderManifest(providerManifestToken);

            var          cmdStr    = "";
            SqlGenerator generator = new SelectGenerator();

            foreach (var commandTree in commandTrees)
            {
                switch (commandTree.CommandTreeKind)
                {
                case DbCommandTreeKind.Insert:
                    generator = new InsertGenerator();
                    cmdStr    = generator.GenerateSQL(commandTree);
                    break;

                case DbCommandTreeKind.Delete:
                    generator = new DeleteGenerator();
                    cmdStr    = generator.GenerateSQL(commandTree);
                    break;

                case DbCommandTreeKind.Update:
                    generator = new UpdateGenerator();
                    cmdStr    = generator.GenerateSQL(commandTree);
                    break;

                case DbCommandTreeKind.Query:
                    generator = new SelectGenerator();
                    cmdStr    = generator.GenerateSQL(commandTree);
                    break;

                case DbCommandTreeKind.Function:
                    generator = new FunctionGenerator();
                    cmdStr    = generator.GenerateSQL(commandTree);
                    break;
                }
                stmt.Sql += cmdStr.Replace("dbo.", "") + ";";
            }
            return(stmt.Sql);
        }
    public override string GenerateProcedureBody(ICollection<DbModificationCommandTree> commandTrees, string rowsAffectedParameter, string providerManifestToken)
    {
      MySqlConnection con = new MySqlConnection();
      MigrationStatement stmt = new MigrationStatement();
      _providerManifest = DbProviderServices.GetProviderServices(con).GetProviderManifest(providerManifestToken);

      var cmdStr = "";
      SqlGenerator generator = new SelectGenerator();
      foreach (var commandTree in commandTrees)
      {
        switch (commandTree.CommandTreeKind)
        {
          case DbCommandTreeKind.Insert:
            generator = new InsertGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
          case DbCommandTreeKind.Delete:
            generator = new DeleteGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
          case DbCommandTreeKind.Update:
            generator = new UpdateGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
          case DbCommandTreeKind.Query:
            generator = new SelectGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
          case DbCommandTreeKind.Function:
            generator = new FunctionGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
        }
        stmt.Sql += cmdStr.Replace("dbo.", "") + ";";
      }
      return stmt.Sql;
    }
    protected virtual MigrationStatement Generate(HistoryOperation op)
    {
      if (op == null) return null;

      MigrationStatement stmt = new MigrationStatement();

      var cmdStr = "";
      SqlGenerator generator = new SelectGenerator();
      foreach (var commandTree in op.CommandTrees)
      {
        switch (commandTree.CommandTreeKind)
        {
          case DbCommandTreeKind.Insert:
            generator = new InsertGenerator();
            break;
          case DbCommandTreeKind.Delete:
            generator = new DeleteGenerator();
            break;
          case DbCommandTreeKind.Update:
            generator = new UpdateGenerator();
            break;
          case DbCommandTreeKind.Query:
            generator = new SelectGenerator();
            break;
          case DbCommandTreeKind.Function:
            generator = new FunctionGenerator();
            break;
          default:
            throw new NotImplementedException(commandTree.CommandTreeKind.ToString());
        }
        cmdStr = generator.GenerateSQL(commandTree);

        ReplaceParemeters(ref cmdStr, generator.Parameters);
        stmt.Sql += cmdStr.Replace("dbo", "") + ";";
      }
      return stmt;
    }