public override void ExplicitVisit(NamedTableReference node) { base.ExplicitVisit(node); if (node.Alias != null && String.IsNullOrEmpty(_search.DatabaseIdentifier?.Value) && node.Alias.Value.Equals(_search.BaseIdentifier.Value, StringComparison.OrdinalIgnoreCase)) { _ambiguous = _foundAlias; TargetDataSource = node.SchemaObject.DatabaseIdentifier?.Value ?? PrimaryDataSource; TargetEntityName = node.SchemaObject.BaseIdentifier.Value; TargetAliasName = node.Alias.Value; Target = node; _foundAlias = true; } if (!_foundAlias && (node.SchemaObject.DatabaseIdentifier?.Value ?? PrimaryDataSource).Equals(_search.DatabaseIdentifier?.Value ?? PrimaryDataSource, StringComparison.OrdinalIgnoreCase) && node.SchemaObject.BaseIdentifier.Value.Equals(_search.BaseIdentifier.Value, StringComparison.OrdinalIgnoreCase)) { if (!_foundAlias && !String.IsNullOrEmpty(TargetEntityName)) { _ambiguous = true; } TargetDataSource = node.SchemaObject.DatabaseIdentifier?.Value ?? PrimaryDataSource; TargetEntityName = node.SchemaObject.BaseIdentifier.Value; TargetAliasName = node.Alias?.Value ?? _search.BaseIdentifier.Value; Target = node; } }
public override void ExplicitVisit(NamedTableReference node) { if (node.SchemaObject.SchemaIdentifier == null && node.Alias != null && node.Alias.Value.ToList().TrueForAll(char.IsUpper)) { this.NamedTableReferences.Add(node); } }
public NamedTableReference[] GetTableReferencesOfQuery(SourceLocation sourceLocation) { List <NamedTableReference> namedTableReferences = new List <NamedTableReference>(); TableReferenceScope[] scopes = GetTableReferenceScopes(sourceLocation); foreach (TableReferenceScope scope in scopes) { int upperBound = namedTableReferences.Count - 1; foreach (NamedTableReference tableReference in scope.TableReferences) { bool referenceIsHidden = false; for (int i = 0; i <= upperBound; i++) { NamedTableReference processedTableReference = namedTableReferences[i]; if (tableReference.CorrelationName.Matches(processedTableReference.CorrelationName)) { referenceIsHidden = true; break; } } if (!referenceIsHidden) { namedTableReferences.Add(tableReference); } } } return(namedTableReferences.ToArray()); }
private void PrintTableReferenceRecurse(TableReference aTableReference) { if (aTableReference.GetType() == typeof(NamedTableReference)) { NamedTableReference aNamedTableReference = (NamedTableReference)aTableReference; Identifier aAliasIdentifier = aNamedTableReference.Alias; SchemaObjectName aSchemaObjectName = aNamedTableReference.SchemaObject; AddLogText(string.Format("Table Reference Server.Database.Schema.Base={0}.{1}.{2}.{3}", (aSchemaObjectName.ServerIdentifier != null) ? aSchemaObjectName.ServerIdentifier.Value : "", (aSchemaObjectName.DatabaseIdentifier != null) ? aSchemaObjectName.DatabaseIdentifier.Value : "", (aSchemaObjectName.SchemaIdentifier != null) ? aSchemaObjectName.SchemaIdentifier.Value : "", (aSchemaObjectName.BaseIdentifier != null) ? aSchemaObjectName.BaseIdentifier.Value : "") ); if (aAliasIdentifier != null) { AddLogText(string.Format("Table Reference Alias:{0}", aAliasIdentifier.Value)); } AddTableReference(aSchemaObjectName, aAliasIdentifier); } if (aTableReference.GetType() == typeof(QualifiedJoin)) { QualifiedJoin aQualifiedJoin = (QualifiedJoin)aTableReference; AddLogText(string.Format("Table Reference QualifiedJoinType ={0}", aQualifiedJoin.QualifiedJoinType.ToString())); PrintTableReferenceRecurse(aQualifiedJoin.FirstTableReference); PrintTableReferenceRecurse(aQualifiedJoin.SecondTableReference); } if (aTableReference.GetType() == typeof(JoinTableReference)) { JoinTableReference aJoinTableReference = (JoinTableReference)aTableReference; PrintTableReferenceRecurse(aJoinTableReference.FirstTableReference); PrintTableReferenceRecurse(aJoinTableReference.SecondTableReference); } }
public override void ExplicitVisit(NamedTableReference node) { if (node.Alias != null && !string.IsNullOrEmpty(node.Alias.Value)) { this.NamedTableReferences.Add(node); } }
private void Process(NamedTableReference namedTableReference) { if (IsInViolationOfRule(namedTableReference)) { this.NamedTableReferences.Add(namedTableReference); } }
public override void ExplicitVisit(SelectStatement node) { QuerySpecification querySpecification = node.QueryExpression as QuerySpecification; FromClause fromClause = querySpecification.FromClause; // There could be more than one TableReference! // TableReference is not sure to be a NamedTableReference, could be as example a QueryDerivedTable NamedTableReference namedTableReference = fromClause.TableReferences[0] as NamedTableReference; TableReferenceWithAlias tableReferenceWithAlias = fromClause.TableReferences[0] as TableReferenceWithAlias; string baseIdentifier = namedTableReference?.SchemaObject.BaseIdentifier?.Value; string schemaIdentifier = namedTableReference?.SchemaObject.SchemaIdentifier?.Value; string databaseIdentifier = namedTableReference?.SchemaObject.DatabaseIdentifier?.Value; string serverIdentifier = namedTableReference?.SchemaObject.ServerIdentifier?.Value; string alias = tableReferenceWithAlias.Alias?.Value; Console.WriteLine("From:"); Console.WriteLine($" {"Server:",-10} {serverIdentifier}"); Console.WriteLine($" {"Database:",-10} {databaseIdentifier}"); Console.WriteLine($" {"Schema:",-10} {schemaIdentifier}"); Console.WriteLine($" {"Table:",-10} {baseIdentifier}"); Console.WriteLine($" {"Alias:",-10} {alias}"); // Example of changing the alias: //(fromClause.TableReferences[0] as NamedTableReference).Alias = new Identifier() { Value = baseIdentifier[0].ToString() }; Console.WriteLine("Statement:"); Console.WriteLine(node.ToSqlString().Indent(2)); Console.WriteLine("¯".Multiply(40)); base.ExplicitVisit(node); }
private bool IsTempNode(DataModificationStatement node) { bool ret = false; NamedTableReference target = null; if (node is InsertStatement nodeInsert) { target = nodeInsert.InsertSpecification.Target as NamedTableReference; } else if (node is DeleteStatement nodeDelete) { target = nodeDelete.DeleteSpecification.Target as NamedTableReference; } else if (node is UpdateStatement nodeUpdate) { target = nodeUpdate.UpdateSpecification.Target as NamedTableReference; } if (target != null && target.SchemaObject.Identifiers.Any(x => x.Value.Contains("#") || x.Value.Contains("@"))) { ret = true; } return(ret); }
internal gsFromTerm GetTable(NamedTableReference namedTableReference) { gsFromTerm table; string tableName = namedTableReference.SchemaObject.BaseIdentifier.Value; if (namedTableReference.Alias != null) { string alias = namedTableReference.Alias.Value; table = new gsFromTerm() { TableName = tableName, TableAlias = alias }; } else { table = table = new gsFromTerm() { TableName = tableName }; } return(table); }
public override void Visit(NamedTableReference node) { if (node.SchemaObject.DatabaseIdentifier != null) { DatabasesUpdated.Add(node.SchemaObject.DatabaseIdentifier.Value); } }
private void PrintTableReferenceRecurse(TableReference aTableReference) { if (aTableReference.GetType() == typeof(NamedTableReference)) { NamedTableReference aNamedTableReference = (NamedTableReference)aTableReference; Identifier aAliasIdentifier = aNamedTableReference.Alias; SchemaObjectName aSchemaObjectName = aNamedTableReference.SchemaObject; AddLogText(string.Format("Table Reference Schema.Base={0}.{1}", (aSchemaObjectName.SchemaIdentifier != null) ? aSchemaObjectName.SchemaIdentifier.Value : "", (aSchemaObjectName.BaseIdentifier != null) ? aSchemaObjectName.BaseIdentifier.Value : "") ); //foreach (Identifier aSchemaObjectNameIdentifier in aSchemaObjectName.Identifiers) //{ // AddText(string.Format("Table Reference Identifier={0}", aSchemaObjectNameIdentifier.Value)); //} if (aAliasIdentifier != null) { AddLogText(string.Format("Table Reference Alias:{0}", aAliasIdentifier.Value)); } aColumnInfoList.AddTableReference(aSchemaObjectName, aAliasIdentifier); } if (aTableReference.GetType() == typeof(QualifiedJoin)) { QualifiedJoin aQualifiedJoin = (QualifiedJoin)aTableReference; AddLogText(string.Format("Table Reference QualifiedJoinType ={0}", aQualifiedJoin.QualifiedJoinType)); PrintTableReferenceRecurse(aQualifiedJoin.FirstTableReference); PrintTableReferenceRecurse(aQualifiedJoin.SecondTableReference); } if (aTableReference.GetType() == typeof(JoinTableReference)) { JoinTableReference aJoinTableReference = (JoinTableReference)aTableReference; PrintTableReferenceRecurse(aJoinTableReference.FirstTableReference); PrintTableReferenceRecurse(aJoinTableReference.SecondTableReference); } }
public NamedTableView(NamedTableReference namedTable) { this.Name = namedTable.GetName("dbo"); if (namedTable.Alias != null && !HasAlias(namedTable.Alias.Value)) { Aliases.Add(namedTable.Alias.Value); } }
public override void ExplicitVisit(NamedTableReference table) { var schemaName = table.SchemaObject.SchemaIdentifier != null ? table.SchemaObject.SchemaIdentifier.Value : "dbo"; Console.WriteLine(string.Concat(schemaName, ".", table.SchemaObject.BaseIdentifier.Value)); base.ExplicitVisit(table); }
public override void Visit(NamedTableReference namedTableReference) { var alias = namedTableReference.Alias; if (alias != null) { var baseObjectName = namedTableReference.SchemaObject.AsObjectName(); Aliases.Add(alias.Value, baseObjectName); } }
public override void Visit(NamedTableReference node) { if (node.SchemaObject.ServerIdentifier == null) { return; } errorCallback(RULE_NAME, RULE_TEXT, node.StartLine, node.StartColumn); }
public override void ExplicitVisit(NamedTableReference node) { if (node.Alias != null) { Aliases[node.Alias.Value] = node.SchemaObject.BaseIdentifier.Value; } base.ExplicitVisit(node); }
public override void ExplicitVisit(NamedTableReference node) { node.SchemaObject.Accept(this); if (node.Alias != null) { _buffer.Append(" as "); node.Alias.Accept(this); } }
private static bool IsInViolationOfRule(NamedTableReference namedTableReference) { if (namedTableReference.SchemaObject.SchemaIdentifier == null) { return(true); } return(false); }
public override void Visit(NamedTableReference namedTableReference) { var alias = namedTableReference.Alias; if (alias != null) { var baseObjectName = string.Join(".", namedTableReference.SchemaObject.Identifiers.Select(x => x.Value)); aliases.Add(alias.Value, baseObjectName); } }
public static string GetTableReferenceIdentifier(this NamedTableReference tableReference) { var qualifiers = new List <string>() { tableReference.Alias?.Value, tableReference.SchemaObject.BaseIdentifier?.Value, }; return(qualifiers.GetQualifiedIdentfier()); }
public static ObjectIdentifier GetObjectIdentifier(this NamedTableReference table, string assumedSchema = "dbo") { var identifiers = table.SchemaObject.Identifiers; if (identifiers.Count == 1 && !string.IsNullOrWhiteSpace(assumedSchema)) { return(new ObjectIdentifier(new[] { assumedSchema, identifiers.First().Value })); } return(new ObjectIdentifier(identifiers.Skip(Math.Max(0, identifiers.Count - 2)).Select(x => x.Value))); }
public override void Visit(QuerySpecification node) { foreach (TableReference tableReference in node.FromClause.TableReferences) { NamedTableReference namedTableReference = tableReference as NamedTableReference; if (namedTableReference != null) { //Console.WriteLine(namedTableReference.SchemaObject.ToString); } } }
public QueryColumnSourceNT(int id, NamedTableReference ntRef) : base(id, BuildKey(ntRef.SchemaObject, ntRef.Alias)) { NtRef = ntRef; SchemaName = NtRef.SchemaObject.SchemaIdentifier != null ? NtRef.SchemaObject.SchemaIdentifier.Dequote() : null; TableName = NtRef.SchemaObject.BaseIdentifier.Dequote(); //SetAlias(ntRef.Alias); }
public override void Visit(NamedTableReference node) { if (CteNames.Contains(node.SchemaObject.BaseIdentifier.Value)) { return; } if (node.Alias == null) { ChildCallback(node); } }
public override void Visit(NamedTableReference node) { if (node.Alias != null) { node.Alias.Value = node.Alias.Value.ToSnakeCase(); } node.SchemaObject.BaseIdentifier.Value = node.SchemaObject.BaseIdentifier.Value.ToSnakeCase(); base.Visit(node); }
public override void ExplicitVisit(NamedTableReference node) { base.ExplicitVisit(node); if (node.Alias == null) { node.Alias = new Identifier { Value = node.SchemaObject.BaseIdentifier.Value } } ; } }
private static bool CheckName(NamedTableReference tbl, ColumnReferenceExpression col) { if (tbl == null) { return(false); } var colNameParts = col.MultiPartIdentifier.Identifiers; var colTableName = new ObjectIdentifier(colNameParts.Take(colNameParts.Count - 1).Select(x => x.Value)); var alias = tbl.Alias?.Value; var tblName = GetTableOrAliasName(tbl.SchemaObject.Identifiers); return(alias.StringEquals(colTableName.Parts.First()) || colTableName.CompareTo(tblName) >= 5); }
protected override object InternalVisit(NamedTableReference node) { var tableName = Visit <string>(node.SchemaObject); //TODO: this is actually a kind of hack, if i am in presence of an var realTable = Database.GetTable(tableName); if (node.Alias != null) { return(new RecordTable(node.Alias.Value, realTable.Columns, realTable.Rows)); } //TODO: make this a result?. //If i make this a result, the insert, delete, or update wont work. they need the real table here. return(realTable); }
public Table GetTableFromReference(NamedTableReference namedTableReference) { var schema = namedTableReference.SchemaObject; var table = new Table { Database = schema.DatabaseIdentifier?.Value, Schema = schema.SchemaIdentifier?.Value, Server = schema.ServerIdentifier?.Value, Name = schema.BaseIdentifier?.Value, Alias = namedTableReference.Alias?.Value }; Dump($"{_pad}FOUND TABLE: {table.Alias ?? "_"} {table.FullyQualifiedName}"); return(table); }
private static void ProcessObjectReferenceProperty(dynamic property, dynamic obj, string propertyTypeNamespace, ref List <NamedTableReference> listObjects, string propertyHierarchy = "", short index = -1) { var propertyValue = index == -1 ? property.GetValue(obj) : property.GetValue(obj, new object[] { index }); if (propertyValue == null) { return; } bool isCollection = false; if (property.PropertyType.GetInterface("System.Collections.IEnumerable") != null) { isCollection = true; } string currentPropertyName = property.Name; string currentPropertyType = property.PropertyType.Name; string currentPropertyTypeNamespace = property.PropertyType.Namespace; if (currentPropertyTypeNamespace == propertyTypeNamespace || currentPropertyType == "String" || isCollection) { if (isCollection && !(propertyValue is string) && propertyValue != null) { foreach (var item in propertyValue) { RecurseObjectReference(item, propertyTypeNamespace, ref listObjects, propertyHierarchy + "." + currentPropertyName); } } else { if (obj is NamedTableReference) { NamedTableReference table = (NamedTableReference)obj; listObjects.Add(table); } else if (currentPropertyTypeNamespace == propertyTypeNamespace) { RecurseObjectReference(propertyValue, propertyTypeNamespace, ref listObjects, propertyHierarchy + "." + currentPropertyName); } } } }
public override void ExplicitVisit(NamedTableReference fragment) { _fragments.Add(fragment); }
public override void Visit(NamedTableReference node) { this.action(node); }