public TableContext(SourceLocation sourceLocation, Identifier remainingPart, Scope scope, TableBinding tableBinding, string correlationName) : base(sourceLocation, remainingPart) { _scope = scope; _tableBinding = tableBinding; _correlationName = correlationName; }
public TableRelation Add(string parentTable, IList<string> parentColumns, string childTable, IList<string> childColumns) { if (parentTable == null) throw ExceptionBuilder.ArgumentNull("parentTable"); if (parentColumns == null) throw ExceptionBuilder.ArgumentNull("parentColumns"); if (parentColumns.Count == 0) throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("parentColumns"); if (childTable == null) throw ExceptionBuilder.ArgumentNull("childTable"); if (childColumns == null) throw ExceptionBuilder.ArgumentNull("childColumns"); if (childColumns.Count == 0) throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("childColumns"); TableBinding parentTableBinding = _dataContext.Tables[parentTable]; TableBinding childTableBinding = _dataContext.Tables[childTable]; if (parentTableBinding == null) throw ExceptionBuilder.ParentTableMustExistInDataContext("parentTable"); if (childTableBinding == null) throw ExceptionBuilder.ChildTableMustExistInDataContext("childTable"); return Add(parentTableBinding, parentColumns, childTableBinding, childColumns); }
public void Deserialize(GamePlatform p, string data, TableBinding b) { IntRef linesCount = new IntRef(); string[] lines = p.ReadAllLines(data, linesCount); string[] header = null; IntRef headerLength = new IntRef(); string current = ""; int currentI = 0; for (int i = 0; i < linesCount.value; i++) { string s = p.StringTrim(lines[i]); if (s == "") { continue; } if (p.StringStartsWithIgnoreCase(s, "//") || p.StringStartsWithIgnoreCase(s, "#")) { continue; } if (p.StringStartsWithIgnoreCase(s, "section=")) { current = p.StringReplace(s, "section=", ""); string sHeader = p.StringTrim(lines[i + 1]); header = p.StringSplit(sHeader, "\t", headerLength); i++; // header currentI = 0; continue; } { if (header == null) { continue; } IntRef ssLength = new IntRef(); string[] ss = p.StringSplit(s, "\t", ssLength); for (int k = 0; k < ssLength.value; k++) { if (k >= headerLength.value) { // discard all data longer than header fields continue; } b.Set(current, currentI, header[k], ss[k]); } currentI++; } } }
private void DeclareTableRefs(IEnumerable <NamedTableReference> namedTableReferences) { foreach (NamedTableReference namedTableReference in namedTableReferences) { TableBinding[] tables = _scope.DataContext.Tables.Find(namedTableReference.TableName); if (tables != null && tables.Length == 1) { TableBinding tableBinding = tables[0]; _resolver.CurrentScope.DeclareTableRef(tableBinding, namedTableReference.CorrelationName); } } }
public IList<TableRelation> GetRelations(TableBinding table) { if (table == null) throw ExceptionBuilder.ArgumentNull("table"); List<TableRelation> result = new List<TableRelation>(); foreach (TableRelation tableRelation in this) { if (tableRelation.ParentTable == table || tableRelation.ChildTable == table) result.Add(tableRelation); } return result; }
public IViewComponentResult Invoke(string markdown) { var tableBinding = new TableBinding(); var rows = markdown.Split("|"); var columns = rows[0].Split("#"); var bindingColumns = columns.ToList(); bindingColumns.RemoveAt(0); var bindingRows = rows.ToList(); bindingRows.RemoveAt(0); tableBinding.Columns = bindingColumns; tableBinding.Rows = bindingRows; ViewData["BindingTable"] = tableBinding; return(View("/Views/Shared/Components/Widgets/TableBuilder/Default.cshtml")); }
public override void Enumerate(IMemberCompletionAcceptor acceptor) { List <TableBinding> joinTargetList = new List <TableBinding>(); TableRefBinding[] tableRefBindings = _queryScope.GetAllTableRefBindings(); foreach (TableRefBinding tableRefBinding in tableRefBindings) { TableBinding joinSource = tableRefBinding.TableBinding; IList <TableRelation> tableRelations = _scope.DataContext.TableRelations.GetRelations(joinSource); foreach (TableRelation tableRelation in tableRelations) { TableBinding joinTarget; if (tableRelation.ParentTable == joinSource) { joinTarget = tableRelation.ChildTable; } else { joinTarget = tableRelation.ParentTable; } if (!joinTargetList.Contains(joinTarget)) { joinTargetList.Add(joinTarget); } } } if (joinTargetList.Count > 0) { foreach (TableBinding joinTarget in joinTargetList) { acceptor.AcceptTable(joinTarget); } } else { foreach (TableBinding joinTarget in _scope.DataContext.Tables) { acceptor.AcceptTable(joinTarget); } } }
public override void Enumerate(IMemberCompletionAcceptor acceptor) { List <TableRelationData> tableRelationDataList = new List <TableRelationData>(); TableRefBinding[] tableRefBindings = _queryScope.GetAllTableRefBindings(); Array.Reverse(tableRefBindings); foreach (TableRefBinding joinSourceTableRef in tableRefBindings) { TableBinding joinSource = joinSourceTableRef.TableBinding; IList <TableRelation> tableRelations = _scope.DataContext.TableRelations.GetRelations(joinSource); foreach (TableRelation tableRelation in tableRelations) { TableBinding joinTarget; if (tableRelation.ParentTable == joinSource) { joinTarget = tableRelation.ChildTable; } else { joinTarget = tableRelation.ParentTable; } foreach (TableRefBinding joinTargetTableRef in tableRefBindings) { if (joinTargetTableRef.TableBinding == joinTarget) { TableRelationData tableRelationData = new TableRelationData(); tableRelationData.Relation = tableRelation; tableRelationData.Child = joinTargetTableRef; tableRelationData.Parent = joinSourceTableRef; tableRelationDataList.Add(tableRelationData); } } } } foreach (TableRelationData tableRelationData in tableRelationDataList) { acceptor.AcceptRelation(tableRelationData.Parent, tableRelationData.Child, tableRelationData.Relation); } }
public TableRelation(IList <ColumnBinding> parentColumns, IList <ColumnBinding> childColumns) { if (parentColumns == null) { throw ExceptionBuilder.ArgumentNull("parentColumns"); } if (childColumns == null) { throw ExceptionBuilder.ArgumentNull("childColumns"); } if (parentColumns.Count == 0) { throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("parentColumns"); } if (childColumns.Count != parentColumns.Count) { throw ExceptionBuilder.ArgumentArrayMustHaveSameSize("childColumns", "parentColumns"); } TableBinding parentTable = parentColumns[0].Table; TableBinding childTable = childColumns[0].Table; for (int i = 1; i < parentColumns.Count; i++) { if (parentColumns[i].Table != parentTable) { throw ExceptionBuilder.AllColumnsMustBelongToSameTable("parentColumns"); } } for (int i = 1; i < childColumns.Count; i++) { if (childColumns[i].Table != childTable) { throw ExceptionBuilder.AllColumnsMustBelongToSameTable("childColumns"); } } _parentColumns = new ColumnBindingCollection(parentColumns); _childColumns = new ColumnBindingCollection(childColumns); }
public TableRelation Add(TableBinding parentTable, IList<string> parentColumns, TableBinding childTable, IList<string> childColumns) { if (parentTable == null) throw ExceptionBuilder.ArgumentNull("parentTable"); if (parentColumns == null) throw ExceptionBuilder.ArgumentNull("parentColumns"); if (parentColumns.Count == 0) throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("parentColumns"); if (childTable == null) throw ExceptionBuilder.ArgumentNull("childTable"); if (childColumns == null) throw ExceptionBuilder.ArgumentNull("childColumns"); if (childColumns.Count == 0) throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("childColumns"); ColumnBinding[] parentColumnBindings = new ColumnBinding[parentColumns.Count]; for (int i = 0; i < parentColumnBindings.Length; i++) { parentColumnBindings[i] = parentTable.GetColumn(parentColumns[i]); if (parentColumnBindings[i] == null) throw ExceptionBuilder.ParentColumnNotFound("parentColumns", parentTable, parentColumns[i]); } ColumnBinding[] childColumnBindings = new ColumnBinding[childColumns.Count]; for (int i = 0; i < childColumnBindings.Length; i++) { childColumnBindings[i] = childTable.GetColumn(childColumns[i]); if (childColumnBindings[i] == null) throw ExceptionBuilder.ChildColumnNotFound("childColumns", childTable, childColumns[i]); } return Add(parentColumnBindings, childColumnBindings); }
public TableRefBinding DeclareTableRef(TableBinding tableBinding, Identifier identifier) { TableRefBinding tableRefBinding = new TableRefBinding(this, tableBinding, identifier.Text); _tableRefs.Add(tableRefBinding); foreach (ColumnRefBinding columnRefBinding in tableRefBinding.ColumnRefs) { if (columnRefBinding.ColumnBinding is RowColumnBinding) { _rowColumnRefs.Add(columnRefBinding); } else { _columnRefs.Add(columnRefBinding); } } return(tableRefBinding); }
public static ArgumentException ChildColumnNotFound(string paramName, TableBinding childTable, string childColumn) { if (paramName == null) { throw new ArgumentNullException("paramName"); } if (childTable == null) { throw new ArgumentNullException("childTable"); } if (childColumn == null) { throw new ArgumentNullException("childColumn"); } string message = String.Format(CultureInfo.CurrentCulture, Resources.ChildColumnNotFound, childColumn, childTable); return(new ArgumentException(message, paramName)); }
public override void Enumerate(IMemberCompletionAcceptor acceptor) { if (acceptor == null) { throw ExceptionBuilder.ArgumentNull("acceptor"); } // Enumerate the complete global scope // // 1. Enumerate all table refs and column refs as they are part // of the query scope. foreach (TableRefBinding tableRefBinding in _queryScope.GetAllTableRefBindings()) { acceptor.AcceptTableRef(tableRefBinding); } foreach (ColumnRefBinding columnRefBinding in _queryScope.GetAllColumnRefBindings()) { acceptor.AcceptColumnRef(columnRefBinding); } // 2. Enumerate all tables, constants, aggregates and functions foreach (TableBinding table in _scope.DataContext.Tables) { acceptor.AcceptTable(table); } foreach (ConstantBinding constant in _scope.DataContext.Constants) { acceptor.AcceptConstant(constant); } foreach (AggregateBinding aggregateBinding in _scope.DataContext.Aggregates) { acceptor.AcceptAggregate(aggregateBinding); } foreach (FunctionBinding functionBinding in _scope.DataContext.Functions) { acceptor.AcceptFunction(functionBinding); } // 3. Enumerate parameters foreach (ParameterBinding parameter in _scope.Parameters) { acceptor.AcceptParameter(parameter); } // 4. Enumerate keywords TokenId[] tokenIDs = (TokenId[])Enum.GetValues(typeof(TokenId)); foreach (TokenId tokenID in tokenIDs) { TokenInfo info = TokenInfo.FromTokenId(tokenID); if (info.IsKeyword) { acceptor.AcceptKeyword(info.Text); } } // 5. Enumerate relations TableRefBinding[] tableRefBindings = _queryScope.GetAllTableRefBindings(); foreach (TableRefBinding parentTableRef in tableRefBindings) { IList <TableRelation> relations = _scope.DataContext.TableRelations.GetChildRelations(parentTableRef.TableBinding); foreach (TableRelation relation in relations) { TableBinding childTable = (relation.ParentTable == parentTableRef.TableBinding) ? relation.ChildTable : relation.ParentTable; TableRefBinding childTableRef = null; foreach (TableRefBinding tableRefBinding in tableRefBindings) { if (tableRefBinding.TableBinding == childTable) { childTableRef = tableRefBinding; break; } } if (childTableRef != null) { acceptor.AcceptRelation(parentTableRef, childTableRef, relation); } } } }
public DerivedColumnBinding(TableBinding derivedTable, string name, Type dataType) : base(derivedTable) { _name = name; _dataType = dataType; }
public void AcceptTable(TableBinding table) { }
public void AcceptTable(TableBinding table) { AddWithoutDuplicationCheck(table.Name, table.GetFullName(), "TABLE", TABLE_IMG_INDEX); }
public void Deserialize(GamePlatform p, string data, TableBinding b) { IntRef linesCount = new IntRef(); string[] lines = p.ReadAllLines(data, linesCount); string[] header = null; IntRef headerLength = new IntRef(); string current = ""; int currentI = 0; for (int i = 0; i < linesCount.value; i++) { string s = p.StringTrim(lines[i]); if (s == "") { continue; } if (p.StringStartsWithIgnoreCase(s, "//") || p.StringStartsWithIgnoreCase(s, "#")) { continue; } if (p.StringStartsWithIgnoreCase(s, "section=")) { current = p.StringReplace(s, "section=", ""); string sHeader = p.StringTrim(lines[i + 1]); header = p.StringSplit(sHeader, "\t", headerLength); i++; // header currentI = 0; continue; } { if (header == null) { continue; } IntRef ssLength = new IntRef(); string[] ss = p.StringSplit(s, "\t", ssLength); for (int k = 0; k < ssLength.value; k++) { b.Set(current, currentI, header[k], ss[k]); } currentI++; } } }
/// <summary> /// returns information about the binding for table/dsvTable or ColumnBinding, we return the table ID /// for query binding, the returned value is -1, but the query out parameter is set to the query definition /// </summary> /// <param name="connectionID"></param> /// <param name="dsvTableNameToIdMap"></param> /// <param name="binding"></param> /// <param name="?"></param> /// <returns></returns> private int GetSourceIDForBinding(int connectionID, Dictionary <string, int> dsvTableNameToIdMap, Binding binding, out string query) { int sourceID = -1; query = null; if (binding != null) { if (binding is ColumnBinding) { ColumnBinding colBinding = (ColumnBinding)binding; // get the id of the dsv table colBinding.TableID if (dsvTableNameToIdMap.ContainsKey(colBinding.TableID)) { sourceID = dsvTableNameToIdMap[colBinding.TableID]; } } else { if (binding is DsvTableBinding) { DsvTableBinding dsvTableBinding = (DsvTableBinding)binding; if (dsvTableNameToIdMap.ContainsKey(dsvTableBinding.TableID)) { sourceID = dsvTableNameToIdMap[dsvTableBinding.TableID]; } } else { if (binding is TableBinding) { TableBinding tableBinding = (TableBinding)binding; string tableName = GetFullyQualifiedTableName(tableBinding.DbSchemaName, tableBinding.DbTableName); if (threePartNames) { tableName = String.Format("[{0}].{1}", repository.RetrieveDatabaseNameFromConnectionID(connectionID), tableName); } // get the table name from the repository itself sourceID = repository.GetTable(connectionID, tableName); if (sourceID == -1) { sourceID = repository.AddObject(tableName, string.Empty, RelationalEnumerator.ObjectTypes.Table, connectionID); } } else { if (binding is MeasureGroupDimensionBinding) { // the caller will handle this since we need the list of cb dimensions } else { if (binding is QueryBinding) { QueryBinding queryBinding = (QueryBinding)binding; query = queryBinding.QueryDefinition; } } } } } } return(sourceID); }
public IMemberCompletionContext ProvideMemberCompletionContext(SourceLocation sourceLocation) { if (_scope.DataContext == null || _scope.Parameters == null) { return(new NullMemberCompletionContext(sourceLocation)); } _errorReporter.Reset(); Token token = _completionParser.GetTokenBeforeSourcePos(sourceLocation); Identifier remainingPart; if (token.Id != TokenId.Identifier) { remainingPart = null; } else { remainingPart = Identifier.InternalFromSource(token.Text); SourceLocation oneBefore = token.Range.StartLocation; oneBefore--; token = _completionParser.GetTokenBeforeSourcePos(oneBefore); } if (token.Id == TokenId.ON) { NamedTableReference[] joinedTables = _completionParser.GetTableReferencesOfJoin(sourceLocation); DeclareTableRefs(joinedTables); return(new TableRelationMemberContext(sourceLocation, remainingPart, _scope, _resolver.CurrentScope)); } else if (token.Id == TokenId.JOIN) { NamedTableReference[] joinedTables = _completionParser.GetTableReferencesOfJoin(sourceLocation); DeclareTableRefs(joinedTables); return(new JoinTableMemberContext(sourceLocation, remainingPart, _scope, _resolver.CurrentScope)); } else { ExpressionNode expressionBeforeDot = _completionParser.ParseExpressionBeforeDot(sourceLocation, out remainingPart); ThrowErrors(); DeclareTableRefs(sourceLocation); if (expressionBeforeDot == null) { return(new GlobalScopeMemberContext(sourceLocation, remainingPart, _scope, _resolver.CurrentScope)); } else { NameExpression expressionAsName = expressionBeforeDot as NameExpression; if (expressionAsName != null) { // Try to resolve a table name. foreach (NamedTableReference namedTableReference in _completionParser.GetTableReferencesOfQuery(sourceLocation)) { if (expressionAsName.Name.Matches(namedTableReference.CorrelationName)) { TableBinding[] tables = _scope.DataContext.Tables.Find(namedTableReference.TableName); if (tables != null && tables.Length == 1) { TableBinding tableBinding = tables[0]; return(new TableContext(sourceLocation, remainingPart, _scope, tableBinding, namedTableReference.CorrelationName.Text)); } break; } } } expressionBeforeDot = ResolveExpression(expressionBeforeDot); if (expressionBeforeDot != null && expressionBeforeDot.ExpressionType != null) { return(new MemberContext(sourceLocation, remainingPart, _scope, expressionBeforeDot)); } } } ThrowErrors(); return(new NullMemberCompletionContext(sourceLocation)); }
private static void ReadAllTables(DataContext dataContext, string pathToMsiFile) { IntPtr databaseHandle; int openFlags = Msi.MsiDbPersistMode_ReadOnly; if (Path.GetExtension(pathToMsiFile).Equals(".msp", StringComparison.InvariantCultureIgnoreCase)) { openFlags += Msi.MsiDbPersistMode_PatchFile; } Msi.OpenDatabase(pathToMsiFile, openFlags, out databaseHandle); try { // Read table metadata table. DataTable tableDataTable = ReadTable(databaseHandle, "_Tables"); // NOTE: The metadata table itself is not listed in _Tables. dataContext.Tables.Add(tableDataTable); foreach (DataRow row in tableDataTable.Rows) { string tableName = (string)row["Name"]; DataTable table = ReadTable(databaseHandle, tableName); dataContext.Tables.Add(table); } // Add relations as described in the _Validation metadata table. DataTableBinding validationTableBinding = (DataTableBinding)dataContext.Tables["_Validation"]; if (validationTableBinding != null) { foreach (DataRow dataRow in validationTableBinding.DataTable.Rows) { if (dataRow.IsNull("KeyTable")) { continue; } string tableName = (string)dataRow["Table"]; string columnName = (string)dataRow["Column"]; string[] keyTablesNames = ((string)dataRow["KeyTable"]).Split(';'); int keyColumnNumber = (int)dataRow["KeyColumn"]; foreach (string keyTableName in keyTablesNames) { if (dataContext.Tables[tableName] != null) { TableBinding keyTable = dataContext.Tables[keyTableName]; if (keyTable != null && keyColumnNumber >= 1 && keyColumnNumber <= keyTable.Columns.Count) { string keyColumnName = keyTable.Columns[keyColumnNumber - 1].Name; dataContext.TableRelations.Add(tableName, new string[] { columnName }, keyTableName, new string[] { keyColumnName }); } } } } } } finally { Msi.CloseHandle(databaseHandle); } }