public static NameWithSchema Parse(string value) { if (value == null) { return(null); } var sident = StructuredIdentifier.Parse(value); if (sident == null) { return(null); } var res = sident.ToNameWithSchema(); if (res != null) { return(res); } int dotPos = value.IndexOf('.'); if (dotPos >= 0) { return(new NameWithSchema(value.Substring(0, dotPos), value.Substring(dotPos + 1))); } else { return(new NameWithSchema(value)); } }
private DmlfSource DoAddOrFindRelation(DmlfSource baseSource, NameWithSchema baseTable, StructuredIdentifier relationJoined, StructuredIdentifier relationToJoin, DatabaseInfo db, DmlfJoinType joinType) { if (relationToJoin.IsEmpty) return baseSource; string relName = relationToJoin.First; string alias = String.Format("_REF{0}_{1}", relationJoined.NameItems.Select(x => "_" + x).CreateDelimitedText(""), relName); var source = FindSourceByAlias(alias); if (source == null) { var baseTableInfo = db.FindTable(baseTable); var fk = baseTableInfo.ForeignKeys.FirstOrDefault(x => System.String.Compare(x.ConstraintName, relName, StringComparison.OrdinalIgnoreCase) == 0); if (fk == null) { var column = baseTableInfo.FindColumn(relName); if (column != null) fk = column.GetForeignKeys().FirstOrDefault(x => x.Columns.Count == 1); } if (fk == null) return null; source = new DmlfSource { TableOrView = fk.RefTableFullName, Alias = alias, }; var relation = new DmlfRelation { Reference = source, JoinType = joinType, }; for (int i = 0; i < fk.Columns.Count; i++) { relation.Conditions.Add(new DmlfEqualCondition { LeftExpr = new DmlfColumnRefExpression { Column = new DmlfColumnRef { ColumnName = fk.Columns[0].RefColumnName, Source = baseSource, } }, RightExpr = new DmlfColumnRefExpression { Column = new DmlfColumnRef { ColumnName = fk.RefColumns[0].RefColumnName, Source = source, } }, }); Relations.Add(relation); } } if (relationToJoin.IsEmpty) return source; return DoAddOrFindRelation(source, source.TableOrView, relationJoined/relationToJoin.First, relationToJoin.WithoutFirst, db, joinType); }
public static StructuredIdentifier Parse(string s) { if (s == null) { return(null); } var res = new StructuredIdentifier(); int pos = 0; var currentSb = new StringBuilder(); bool isQuoted = false; while (pos < s.Length) { char ch = s[pos]; if (ch == '[' && !isQuoted) { isQuoted = true; pos++; continue; } if (ch == ']' && isQuoted) { isQuoted = false; pos++; continue; } if (isQuoted) { currentSb.Append(ch); pos++; continue; } if (ch == '.') { res._nameItems.Add(currentSb.ToString()); currentSb.Clear(); pos++; continue; } currentSb.Append(ch); pos++; } if (currentSb.Length > 0) { res._nameItems.Add(currentSb.ToString()); } return(res); }
public void ReplaceTargetSchemaByTemplate(string template) { var identSrc = StructuredIdentifier.Parse(Source); if (identSrc.Count == 1 || identSrc.Count == 2) { Source = new StructuredIdentifier(new string[] { template, identSrc.Last }).ToString(); } var identDst = StructuredIdentifier.Parse(Target); if (identDst.Count == 1 || identDst.Count == 2) { Target = new StructuredIdentifier(new string[] { template, identDst.Last }).ToString(); } }
public static StructuredIdentifier Parse(string s) { if (s == null) return null; var res = new StructuredIdentifier(); int pos = 0; var currentSb = new StringBuilder(); bool isQuoted = false; while (pos < s.Length) { char ch = s[pos]; if (ch == '[' && !isQuoted) { isQuoted = true; pos++; continue; } if (ch == ']' && isQuoted) { isQuoted = false; pos++; continue; } if (isQuoted) { currentSb.Append(ch); pos++; continue; } if (ch == '.') { res._nameItems.Add(currentSb.ToString()); currentSb.Clear(); pos++; continue; } currentSb.Append(ch); pos++; } if (currentSb.Length > 0) { res._nameItems.Add(currentSb.ToString()); } return res; }
public StructuredIdentifier(StructuredIdentifier a, StructuredIdentifier b) { _nameItems.AddRange(a._nameItems); _nameItems.AddRange(b._nameItems); }
public StructuredIdentifier(string a, StructuredIdentifier b) { _nameItems.Add(a); _nameItems.AddRange(b._nameItems); }
public StructuredIdentifier(StructuredIdentifier a, string b) { _nameItems.AddRange(a._nameItems); _nameItems.Add(b); }
public DmlfColumnRef GetColumnRef(DmlfSource baseSource, NameWithSchema baseTable, StructuredIdentifier columnId, DatabaseInfo db, DmlfJoinType joinType) { var relationId = columnId.WithoutLast; string column = columnId.Last; var source = AddOrFindRelation(baseSource, baseTable, relationId, db, joinType); if (source == null) return null; return new DmlfColumnRef { ColumnName = column, Source = source, }; }
public DmlfSource AddOrFindRelation(DmlfSource baseSource, NameWithSchema baseTable, StructuredIdentifier relationId, DatabaseInfo db, DmlfJoinType joinType) { return DoAddOrFindRelation(baseSource, baseTable, new StructuredIdentifier(), relationId, db, joinType); }