Ejemplo n.º 1
0
 /// <summary>
 /// Parses the given command text to build a command builder.
 /// </summary>
 /// <param name="commandText">The command text to parse.</param>
 /// <param name="options">Configures the behavior of the command builder.</param>
 /// <returns>The command that was parsed.</returns>
 public ICommand GetCommand(string commandText, CommandBuilderOptions options = null)
 {
     this.scope = new SourceScope();
     this.options = options ?? new CommandBuilderOptions();
     ITokenSource tokenSource = Grammar.TokenRegistry.CreateTokenSource(commandText);
     MatchResult result = GetResult(tokenSource);
     return buildStart(result);
 }
Ejemplo n.º 2
0
 public ICommand Parse(string sqlCommandText, string placeholderToken)
 {
     var commandText = sqlCommandText;
     var commandBuilder = new CommandBuilder();
     var options = new CommandBuilderOptions();
     options.PlaceholderPrefix = placeholderToken;
     var builder = commandBuilder.GetCommand(commandText, options);
     return builder;
 }
        private ICrmOperation GetOperationFromTextCommand(CrmDbCommand command, CommandBehavior behavior)
        {
            // We actually need to parse the SQL, and then build the appropriate organisation request.

            var commandText = command.CommandText;

            // Use SQLGeneration to parse the SQL command into a Visitable Builder.
            var commandBuilder = new CommandBuilder();
            var options = new CommandBuilderOptions();
            options.PlaceholderPrefix = ParameterToken;
            var sqlCommandBuilder = commandBuilder.GetCommand(commandText, options);

            // Visit the builder with out custom visiter that will build the appropriate org request whilst visiting.
            var visitor = GetVisitor(command);
            if (visitor == null)
            {
                throw new InvalidOperationException("visitor was null");
            }
            sqlCommandBuilder.Accept(visitor);

            // The visitor should now have vuild the OrgCommand that we need.
            var orgCommand = visitor.CrmOperation;
            if (orgCommand == null || orgCommand.Request == null)
            {
                throw new NotSupportedException("Could not translate the command into the appropriate Organization Service Request Message");
            }

            // Before returning the command, ensure some additional properties are set.
            orgCommand.DbCommand = command;
            orgCommand.CommandBehavior = behavior;
            return orgCommand;
        }
Ejemplo n.º 4
0
 public void TestSelect_LikeFilter_CompareToParameter()
 {
     string commandText = "SELECT Column FROM Table WHERE Column1 LIKE @Parameter";
     CommandBuilderOptions options = new CommandBuilderOptions()
     {
         PlaceholderPrefix = "@"
     };
     assertCanReproduce(commandText, options);
 }
Ejemplo n.º 5
0
 private void assertCanReproduce(string commandText, CommandBuilderOptions options = null)
 {
     CommandBuilder builder = new CommandBuilder();
     ICommand command = builder.GetCommand(commandText, options);
     Formatter formatter = new Formatter();
     string actual = formatter.GetCommandText(command);
     Assert.AreEqual(commandText, actual, "The command builder did not generate the original command text.");
 }