public static bool ParseExplicitFieldName(string f, string sepStart, string sepEnd, ref string name, ref string text) { int i = FieldsParser.FindStringIndex(f, " AS ", 0, sepStart, sepEnd); if (i > 0) { text = f.Substring(0, i); text = text.Trim(); name = f.Substring(i + 4); name = name.Trim(); int sepLeng = 0; if (!string.IsNullOrEmpty(sepStart) && !string.IsNullOrEmpty(sepEnd)) { sepLeng = sepStart.Length + sepEnd.Length; } if (sepLeng > 0 && name.Length > sepLeng) { if (name.StartsWith(sepStart, StringComparison.OrdinalIgnoreCase) && name.EndsWith(sepEnd, StringComparison.OrdinalIgnoreCase)) { name = name.Substring(sepStart.Length, name.Length - sepEnd.Length); } } return(true); } return(false); }
public void LoadData(QueryParser q) { int i; //qParser = q; qry = (EasyQuery)q.query.Clone(); //parse group by groupFields = new FieldsParser(); //============================================= string s; string sGroupBy = qry.GroupBy; if (!string.IsNullOrEmpty(sGroupBy)) { sGroupBy = sGroupBy.Trim(); if (sGroupBy.StartsWith("GROUP BY ", StringComparison.OrdinalIgnoreCase)) { sGroupBy = sGroupBy.Substring(9); sGroupBy = sGroupBy.Trim(); } i = FieldsParser.FindStringIndex(sGroupBy, ",", 0, q.Sep1, q.Sep2); while (sGroupBy.Length > 0) { if (i < 0) { s = sGroupBy; sGroupBy = ""; } else { s = sGroupBy.Substring(0, i); sGroupBy = sGroupBy.Substring(i + 1); sGroupBy = sGroupBy.Trim(); } s = s.Trim(); groupFields.AddField(new QryField(s, q.Sep1, q.Sep2)); i = FieldsParser.FindStringIndex(sGroupBy, ",", 0, q.Sep1, q.Sep2); } } //============================================= ListViewItem item; listView1.Items.Clear(); FieldList fl = qry.Fields; for (i = 0; i < fl.Count; i++) { item = new ListViewItem(fl[i].FieldText); if (groupFields.FindFieldByText(fl[i].FieldText) != null) { item.SubItems.Add("Group by"); } else { item.SubItems.Add(""); } listView1.Items.Add(item); } }
public bool IsCommand(string sep1, string sep2) { if (!string.IsNullOrEmpty(_sql)) { return(FieldsParser.FindStringIndex(_sql, QueryParser.SQL_Select(), 0, sep1, sep2) < 0); } return(false); }
public QryField(string f, string sepStart, string sepEnd) { //find table name/alias int n = -1; string t = ""; int sepLeng = 0; FieldText = f; if (!string.IsNullOrEmpty(sepStart) && !string.IsNullOrEmpty(sepEnd)) { sepLeng = sepStart.Length + sepEnd.Length; } f = f.Trim(); if (sepLeng > 0 && f.Length > sepLeng) { if (f.StartsWith(sepStart, StringComparison.OrdinalIgnoreCase)) { n = f.IndexOf(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}.{1}", sepEnd, sepStart), StringComparison.OrdinalIgnoreCase); if (n > 1) { t = f.Substring(sepStart.Length, n - sepEnd.Length); f = f.Substring(n + 1 + sepEnd.Length); } } } if (n < 2) { int i = FieldsParser.FindStringIndex(f, ".", 0, sepStart, sepEnd); if (i > 0) { t = f.Substring(0, i); } } Table = t; string fn = ""; //find field name by looking for " AS " backward if (ParseExplicitFieldName(f, sepStart, sepEnd, ref fn, ref t)) { FieldName = fn; FieldText = t; } else { if (sepLeng > 0) { if (f.StartsWith(sepStart) && f.EndsWith(sepEnd)) { f = f.Substring(sepStart.Length, f.Length - sepLeng); } } FieldName = f; } Field = f; }
public static string[] ParseFieldList(string fieldList, string sepStart, string sepEnd) { if (string.IsNullOrEmpty(fieldList)) { return(new string[] { }); } else { List <string> ss = new List <string>(); while (fieldList.Length > 0) { string s = FieldsParser.PopValue(ref fieldList, ",", sepStart, sepEnd); ss.Add(s.Trim()); } return(ss.ToArray()); } }
private void loadWebDataFields() { WebDataEditorLookupDB wd = WebLookup; cbx2.Items.Clear(); int i; FieldsParser fp = new FieldsParser(); string[] fields = null; string msg = string.Empty; if (!string.IsNullOrEmpty(wd.SqlString)) { if (fp.ParseQuery(wd.SqlString, _webQuery.NameDelimiterBegin, _webQuery.NameDelimiterEnd, ref msg)) { fields = new string[fp.Count]; for (i = 0; i < fields.Length; i++) { fields[i] = fp.Fields[i].FieldName; } } else { MessageBox.Show(string.Format(CultureInfo.InstalledUICulture, "{0}. Error parsing SQL Statement [{1}].", msg, wd.SqlString), "Parse SQL Statement"); } } int n = wd.Hold.FieldCount; cbx2.Items.Add(""); if (fields != null) { for (i = 0; i < fields.Length; i++) { cbx2.Items.Add(fields[i]); } } if (n == 0) { MessageBox.Show("Linked data source not found (DestinationFieldCount is 0)"); return; } else { ds.Tables[0].Rows.Clear(); object[] vs; for (i = 0; i < n; i++) { string nm = wd.Hold.GetFieldNameByIndex(i); vs = new object[2]; vs[0] = nm; //field to be updated vs[1] = string.Empty; if (wd.FieldsMap != null) { for (int j = 0; j < wd.FieldsMap.Count; j++) { if (string.Compare(wd.FieldsMap[j].Target, nm, StringComparison.OrdinalIgnoreCase) == 0) { bool ok = false; if (fields != null) { for (int k = 0; k < fields.Length; k++) { if (string.Compare(fields[k], wd.FieldsMap[j].Source, StringComparison.OrdinalIgnoreCase) == 0) { ok = true; break; } } } if (ok) { vs[1] = wd.FieldsMap[j].Source; } break; } } } ds.Tables[0].Rows.Add(vs); } } }
public void LoadData(QueryParser q) { qParser = q; lstFields.Items.Clear(); EPField fld; int i; FieldList fl = q.query.Fields; for (i = 0; i < fl.Count; i++) { fld = fl[i]; if (!EPField.IsBinary(fld.OleDbType)) { lstFields.Items.Add(new OrderByField(fld, qParser.Sep1, qParser.Sep2)); //lstFields.Items.Add(fld); } } clsOrder.Items.Clear(); int nType; string s, s2; string sOrder = q.query.OrderBy; if (sOrder == null) { sOrder = ""; } sOrder = sOrder.Trim(); if (sOrder.StartsWith("ORDER BY ", StringComparison.OrdinalIgnoreCase)) { sOrder = sOrder.Substring(9); sOrder = sOrder.Trim(); } i = FieldsParser.FindStringIndex(sOrder, ",", 0, q.Sep1, q.Sep2); while (sOrder.Length > 0) { if (i < 0) { s = sOrder; sOrder = ""; } else { s = sOrder.Substring(0, i); sOrder = sOrder.Substring(i + 1); sOrder = sOrder.Trim(); } s = s.Trim(); nType = -1; if (s.Length > 4) { s2 = s.Substring(s.Length - 4, 4); if (string.Compare(s2, " ASC", StringComparison.OrdinalIgnoreCase) == 0) { s = s.Substring(0, s.Length - 4); s = s.Trim(); nType = 0; } } if (nType < 0) { if (s.Length > 5) { s2 = s.Substring(s.Length - 5, 5); if (string.Compare(s2, " DESC", StringComparison.OrdinalIgnoreCase) == 0) { s = s.Substring(0, s.Length - 5); s = s.Trim(); nType = 1; } } } clsOrder.Items.Add(s, (nType == 1)); i = FieldsParser.FindStringIndex(sOrder, ",", 0, q.Sep1, q.Sep2); } }