protected List <ColumnClause> GetColumns() { List <ColumnClause> res = new List <ColumnClause>(); var sExpr1 = CommonUtils.FindParentSelect(this); if (sExpr1 == null) { throw new Exception("Select expression is not found"); } var tables = sExpr1.GetTables(); for (int j = 0; j < tables.Length; j++) { var st = tables[j]; var t = tables[j].Table; if (!string.IsNullOrEmpty(Prefix)) { string tableAlias = Prefix; if (!st.CompareWithColumn(new string[1] { tableAlias })) { continue; } } var tlist = t.TableColumns; for (int k = 0; k < tlist.Count; k++) { ColumnClause cc = new ColumnClause(); FieldExpr fe = new FieldExpr(); fe.Bind(tables[j], tlist[k].Name); cc.ColumnExpression = fe; res.Add(cc); } } return(res); }
private void FindAndMakeField() { FieldExpr f = this; string tableAlias = f.TableAlias; string fieldAlias = f.FieldName; string schema = f.Schema; bool ok = false; ITableSource tsource = CommonUtils.FindParentTableSource(this); while (tsource != null) { var tables = tsource.GetTables(); foreach (var st in tables) { bool okTable = false; if (!string.IsNullOrEmpty(tableAlias)) { if (st.CompareWithColumn(new string[2] { schema, tableAlias })) { okTable = true; } } else { okTable = true; } if (okTable) { var c = st.Table.ByName(fieldAlias); if (c != null) { if (ok) { throw new Exception("Невозможно определить однозначно колонку"); } f.Bind(st, fieldAlias); ok = true; } } } if (ok) { break; } if (string.IsNullOrEmpty(tableAlias) && tsource is SelectExpresion) { SelectExpresion select = tsource as SelectExpresion; foreach (var c in select.TableColumns) { if (StringComparer.InvariantCultureIgnoreCase.Compare(c.Name, fieldAlias) == 0) { if (ok) { throw new Exception("Невозможно определить однозначно колонку"); } ok = true; f.Bind(select, fieldAlias); } } } if (ok) { break; } tsource = CommonUtils.FindParentTableSource(tsource); } if (!ok) { throw new Exception("Column \"" + fieldAlias + "\" is not found"); } }