Ejemplo n.º 1
0
        /// <summary>
        /// Parses the SQL code and loads the SQL statements into the StringCollection <see cref="Results"/>.
        /// </summary>
        /// <returns>The number of statements found.</returns>
        public int Parse()
        {
            _results.Clear();
            foreach (var statement in _parser.Parse())
            {
                string newParserToken;
                if (IsSetTermStatement(statement.CleanText, out newParserToken))
                {
                    _parser.Tokens = new[] { newParserToken };
                    continue;
                }

                if (statement.CleanText != string.Empty)
                {
                    var type = GetStatementType(statement.CleanText);
                    if (type != null)
                    {
                        statement.SetStatementType((SqlStatementType)type);
                        _results.Add(statement);
                        continue;
                    }
                }

                if (statement.Text.Trim() != string.Empty)
                {
                    var unknownStatementEventArgs = new UnknownStatementEventArgs(statement);
                    UnknownStatement?.Invoke(this, unknownStatementEventArgs);
                    if (unknownStatementEventArgs.Handled && !unknownStatementEventArgs.Ignore)
                    {
                        statement.SetStatementType(unknownStatementEventArgs.NewStatementType);
                        _results.Add(statement);
                        continue;
                    }
                    else if (!unknownStatementEventArgs.Handled && unknownStatementEventArgs.Ignore)
                    {
                        continue;
                    }
                    else if (unknownStatementEventArgs.Handled && unknownStatementEventArgs.Ignore)
                    {
                        throw new InvalidOperationException($"Both {nameof(UnknownStatementEventArgs.Handled)} and {nameof(UnknownStatementEventArgs.Ignore)} should not be set.");
                    }
                    else
                    {
                        throw new ArgumentException($"The type of the SQL statement could not be determined. See also {nameof(UnknownStatement)} event.{Environment.NewLine}Statement: {statement.Text}.");
                    }
                }
            }
            return(_results.Count);
        }
		/// <summary>
		/// Parses the SQL code and loads the SQL statements into the StringCollection <see cref="Results"/>.
		/// </summary>
		/// <returns>The number of statements found.</returns>
		public int Parse()
		{
			_results.Clear();
			foreach (var statement in _parser.ParseNext())
			{
				string newParserToken;
				if (IsSetTermStatement(statement.CleanText, out newParserToken))
				{
					_parser.Tokens = new[] { newParserToken };
					continue;
				}

				if (statement.CleanText != string.Empty)
				{
					var type = GetStatementType(statement.CleanText);
					if (type != null)
					{
						statement.SetStatementType((SqlStatementType)type);
						_results.Add(statement);
						continue;
					}
				}

				if (statement.Text.Trim() != string.Empty)
				{
					var unknownStatementEventArgs = new UnknownStatementEventArgs(statement);
					UnknownStatement?.Invoke(this, unknownStatementEventArgs);
					if (unknownStatementEventArgs.Handled && !unknownStatementEventArgs.Ignore)
					{
						statement.SetStatementType(unknownStatementEventArgs.NewStatementType);
						_results.Add(statement);
						continue;
					}
					else if (!unknownStatementEventArgs.Handled && unknownStatementEventArgs.Ignore)
					{
						continue;
					}
					else if (unknownStatementEventArgs.Handled && unknownStatementEventArgs.Ignore)
					{
						throw new InvalidOperationException($"Both {nameof(UnknownStatementEventArgs.Handled)} and {nameof(UnknownStatementEventArgs.Ignore)} should not be set.");
					}
					else
					{
						throw new ArgumentException(string.Format("The type of the SQL statement could not be determined.{0}Statement: {1}.",
							Environment.NewLine,
							statement.Text));
					}
				}
			}
			return _results.Count;
		}