public DataManipulation Resolve(ReadOnlySpan <TSQLToken> tokens, ref int fileIndex, CompilerContext context) { manipulation = new DataManipulation(); fileIndex++; //skip 'insert' //TODO Resolve TOP Expression if (tokens[fileIndex].Text.ToLower().Equals("into")) { fileIndex++; //skip 'into' } targetObject = StatementResolveHelper.ResolveDatabaseObject(tokens, ref fileIndex, context, true); DetermineTargetColumns(tokens, ref fileIndex, context); //TODO Resolve Table Hint if (tokens[fileIndex].Text.Equals("values", StringComparison.InvariantCultureIgnoreCase)) { fileIndex += 2; //skip 'values (' DetermineSourceObjects(tokens, ref fileIndex, context); } else if (tokens[fileIndex].Text.Equals("select", StringComparison.InvariantCultureIgnoreCase)) { var selectStatement = new SelectStatementResolver().Resolve(tokens, ref fileIndex, context); sources = selectStatement.ChildExpressions; } if (targets.Count == 0) { for (int index = 0; index < sources.Count; index++) { Expression resolvedSource; if (sources[index].Type.Equals(ExpressionType.COMPLEX) || sources[index].Type.Equals(ExpressionType.CONSTANT)) { continue; } else if (sources[index].Type.Equals(ExpressionType.ALIAS)) { resolvedSource = sources[index].ChildExpressions[0]; } else { resolvedSource = sources[index]; } var singleManipulation = new Expression(ExpressionType.COLUMN) { Name = Beautifier.EnhanceNotation(targetObject, InternalConstants.UNRELATED_COLUMN_NAME) }; singleManipulation.ChildExpressions.Add(resolvedSource); manipulation.Expressions.Add(singleManipulation); } } else if (StatementResolveHelper.HaveEqualAmountOfRealExpression(sources, targets)) { for (int index = 0; index < targets.Count; index++) { if (!sources[index].Type.Equals(ExpressionType.COLUMN) && !sources[index].Type.Equals(ExpressionType.SCALAR_FUNCTION)) { continue; } var singleManipulation = new Expression(ExpressionType.COLUMN) { Name = targets[index].Name }; singleManipulation.ChildExpressions.Add(sources[index]); manipulation.Expressions.Add(singleManipulation); } } else { throw new InvalidSqlException("Amount of targets does not match the number of sources"); } if (fileIndex < tokens.Length && tokens[fileIndex].Text.Equals(";")) { fileIndex++; } var beautified = new List <Expression>(); foreach (var exp in manipulation.Expressions) { beautified.Add(Beautifier.BeautifyColumns(exp, context)); } manipulation.Expressions = beautified; return(manipulation); }