Deveel.Data.Sql.Statements.InsertStatement.ResolveColumn C# (CSharp) Method

ResolveColumn() private method

private ResolveColumn ( IFromTableSource fromTable, ObjectName v ) : ObjectName
fromTable IFromTableSource
v ObjectName
return ObjectName
        private ObjectName ResolveColumn(IFromTableSource fromTable, ObjectName v)
        {
            // Try and resolve against alias names first,
            var list = new List<ObjectName>();

            var tname = v.Parent;
            string schemaName = null;
            string tableName = null;
            string columnName = v.Name;
            if (tname != null) {
                schemaName = tname.ParentName;
                tableName = tname.Name;
            }

            int rcc = fromTable.ResolveColumnCount(null, schemaName, tableName, columnName);
            if (rcc == 1) {
                var matched = fromTable.ResolveColumn(null, schemaName, tableName, columnName);
                list.Add(matched);
            } else if (rcc > 1) {
                throw new StatementException("Ambiguous column name (" + v + ")");
            }

            int totalMatches = list.Count;
            if (totalMatches == 0)
                throw new StatementException("Can't find column: " + v);

            if (totalMatches == 1)
                return list[0];

            if (totalMatches > 1)
                // if there more than one match, check if they all match the identical
                // resource,
                throw new StatementException("Ambiguous column name (" + v + ")");

            // Should never reach here but we include this exception to keep the
            // compiler happy.
            throw new InvalidOperationException("Negative total matches");
        }