query string analyzer c # – Exchange stack code revision

I have written this class to create RapportColumn objects for each column that is written in the query. And I would like to receive your comments.

The query that is provided in the GetRapportColumnsList () method is always a valid query. That check has been made in a previous class.

I'm specifically asking about the CreateColumns class, but any other comments are very much appreciated. Can I optimize this code further?

RapportService class
{
static main vacuum (chain[] args)
{
var service = new RapportService ();
var consultation =
"SELECT column, column, column b, column, DATE_FORMAT (columnd,% Y-% m-% d & # 39;), DATE_FORMAT (columnd, & # 39;% T & # 39;), IF (columne = (count SELECT (*) FROM table WHERE column = m.columnb AND columnc = 0 AND columnd = 1), & # 39 ;, & # 39; Fout & # 39;) as for example FROM the tablab m WHERE column = 64 AND columnb> = & # 39; 2018-09-04 00: 00: 00 & # 39; AND columnd <= & # 39; 2018-09-08 00: 00: 00 & # 39; ORDER BY columnb ASC " ;
var x = service.GetRapportColumnsList (query, 5);
Console.Read ();
}

private queue columnQueue = new queue();
Private list columns = new list();

// param -> part of the query of everything between select and from
// split into & # 39;, & # 39; and add it in a queue
private void AddColumnStringsToQueue (string query)
{
var columns = query.Split (& # 39;, & # 39;);
foreach (var column in columns)
{
columnQueue.Enqueue (column);
}
}

// param query and rapport_id
// get the part of the query between SELECT and FROM
// call the method to put everything in the queue
// call the method to create the column objects
Public list GetRapportColumnsList (string query, int rapport_id)
{
var i = query.LastIndexOf (SqlClauseEnum.FROM, StringComparison.CurrentCultureIgnoreCase);
var res = query.Substring (SqlClauseEnum.SELECT.Length, i - SqlClauseEnum.SELECT.Length);
AddColumnStringsToQueue (res);

CreateColumns (rapport_id);

return columns;
}

// traverses the queue and creates RapportColumn objects
empty empty CreateColumns (int rapport_id)
{
pile var = new battery();
count var = 0;

while (columnQueue.Count> 0)
{
var builder = new StringBuilder ();
account ++;
var rapportColumn = new RapportColumn ();
var item = columnQueue.Dequeue ();

constructor.Append (item);
var bracket = GetOpeningBracket (item);
if (bracket == BracketsEnum.ParenthesisOpen)
{
if (! IsSrounded (item))
{
pile.Pulgar (support);
while (columnQueue.Count> 0)
{
var newItem = columnQueue.Peek ();
var newBracket = GetOpeningBracket (newItem);
if (newBracket == BracketsEnum.ParenthesisOpen)
{
if (! IsSrounded (item))
{
stack.Push (newBracket);
}
}

constructor.Append (",");
constructor.Append (newItem);
columnQueue.Dequeue ();

if (GetClosingBracket (newItem) == BracketsEnum.ParenthesisClose)
{
if (! IsSrounded (item))
{
stack.pop ();
yes (stack.Count == 0)
{
break;
}
}
}

}
}
}

var query = builder.ToString ();
if (query.IndexOf ("AS", StringComparison.CurrentCultureIgnoreCase)> 0)
{
var parts = Regex.Split (query, "AS", RegexOptions.IgnoreCase);
rapportColumn.RC_ColumnQuery = parts[0];
rapportColumn.RC_ColumnLabel = parts[1];
}
plus
{
rapportColumn.RC_ColumnQuery = query;
}
rapportColumn.Rapport_Id = rapport_id;
rapportColumn.RC_Order = count;
Columns.Add (rapportColumn);
}
}

// check if there is an opening parenthesis in the string
Private char GetOpeningBracket (string element)
{
var arr = item.ToCharArray ();
foreach (var charr in arr)
{
switch (charr)
{
case BracketsEnum.ParenthesisOpen:
back charr;
default:
continue;
}
}

returns & # 39;  0 & # 39 ;;
}

// check if there is a closing parenthesis in the string
private char GetClosingBracket (string element)
{
var arr = item.ToCharArray ();
foreach (var charr in arr)
{
switch (charr)
{
case BracketsEnum.ParenthesisClose:
back charr;
default:
continue;
}
}

returns & # 39;  0 & # 39 ;;
}

// check if there is as much closure as opening parenthesis in the string
Private bool IsSurrounded (string element)
{
pile var = new battery();
var isSurrounded = false;
for (var i = 0; i <item.Length; i ++)
{
switch (element[i])
{
case BracketsEnum.ParenthesisOpen:
pile.Pulse (i);
break;
case BracketsEnum.ParenthesisClose:
var index = stack.Any ()? stack.pop (): -1;
break;
default:
break;
}
}
return pile. Account <= 0;
}

}
RapportColumn class
{
public int RC_Id {get; set; }
public int Rapport_Id {get; set; }
public string RC_ColumnName {get; set; }
public string RC_ColumnLabel {get; set; }
public string RC_ColumnQuery {get; set; }
public int RC_Order {get; set; }
public bool RC_checked {get; set; }
}
SqlClauseEnum class
{
public const string FROM = "FROM";
public const string WHERE = "WHERE";
public const string GROUP_BY = "GROUP BY";
public const string HAVING = "HAVING";
public const string SELECT = "SELECT";
public const string ORDER_BY = "ORDER BY";
public const string LIMIT = "LIMIT";
}

Class BracketsEnum
{
public const char ParenthesisOpen = & # 39; (& # 39 ;;
public const char ParenthesisClose = & # 39;) & # 39 ;;
}