Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C#

SQL Parser

Rate me:
Please Sign up or sign in to vote.
4.86/5 (47 votes)
3 Feb 2009CDDL4 min read 307.3K   15.2K   165  
This article describes an implementation of a simple SQL parser which can be used to add or modify "where" and "order by" parts of SQL queries (PL/SQL).
using System;
using System.Collections.Generic;
using System.Text;

namespace Parser
{
	#region StartWith

	[TagType(StartWith.cTagName)]
	[MatchStartWithTag]
	internal class StartWith : SimpleTwoWordTag
	{
		#region Consts

		/// <summary>
		/// The name of the tag (its identifier).
		/// </summary>
		public const string cTagName = "START_WITH";

		/// <summary>
		/// The first part of tag.
		/// </summary>
		public const string cTagFirstPart = "START";

		/// <summary>
		/// The second part of tag.
		/// </summary>
		public const string cTagSecondPart = "WITH";

		#endregion

		#region Properties

		/// <summary>
		/// Gets the name of the tag.
		/// </summary>
		protected override string Name 
		{
			get
			{
				return cTagName;
			}
		}

		/// <summary>
		/// Gets the first word of the tag.
		/// </summary>
		protected override string FirstWord
		{
			get
			{
				return cTagFirstPart;
			}
		}

		/// <summary>
		/// Gets the second word of the tag.
		/// </summary>
		protected override string SecondWord
		{
			get
			{
				return cTagSecondPart;
			}
		}

		#endregion
	}

	#endregion

	#region MatchOrderByTagAttribute

	internal class MatchStartWithTagAttribute : MatchSimpleTwoWordTagAttribute
	{
		#region Properties

		/// <summary>
		/// Gets the name of the tag (its identifier and sql text)
		/// </summary>
		protected override string Name
		{
			get
			{
				return StartWith.cTagName;
			}
		}

		/// <summary>
		/// Gets the first word of the tag.
		/// </summary>
		protected override string FirstWord 
		{
			get
			{
				return StartWith.cTagFirstPart;
			}
		}

		/// <summary>
		/// Gets the second word of the tag.
		/// </summary>
		protected override string SecondWord
		{
			get
			{
				return StartWith.cTagSecondPart;
			}
		}

		#endregion
	}

	#endregion
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior)
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions