Deveel.Data.Sql.Query.FromTableDirectSource.ResolveColumn C# (CSharp) Method

ResolveColumn() public method

public ResolveColumn ( string catalog, string schema, string table, string column ) : ObjectName
catalog string
schema string
table string
column string
return ObjectName
        public ObjectName ResolveColumn(string catalog, string schema, string table, string column)
        {
            var schemaName = GivenTableName.Parent;
            var catalogName = schemaName == null ? null : schemaName.Parent;

            var givenCatalog = catalogName != null ? catalogName.Name : null;
            if (catalog != null && !StringCompare(catalog, givenCatalog))
                throw new InvalidOperationException("Incorrect catalog.");

            // Does this table name represent the correct schema?
            var givenSchema = GivenTableName.Parent != null ? GivenTableName.Parent.Name : null;
            if (schema != null && !StringCompare(schema, givenSchema))
                // If schema is present and we can't resolve to this schema
                throw new InvalidOperationException("Incorrect schema.");

            if (table != null && !StringCompare(table, GivenTableName.Name))
                // If table name is present and we can't resolve to this table name
                throw new InvalidOperationException("Incorrect table.");

            if (column != null) {
                if (!IgnoreCase) {
                    // Can we resolve the column in this table?
                    int i = tableInfo.IndexOfColumn(column);
                    if (i == -1)
                        throw new InvalidOperationException("Could not resolve '" + column + "'");

                    return new ObjectName(GivenTableName, column);
                }

                // Case insensitive search (this is slower than case sensitive).
                var columnName =
                    tableInfo.Where(x => StringCompare(x.ColumnName, column))
                        .Select(x => x.ColumnName)
                        .FirstOrDefault();

                if (String.IsNullOrEmpty(columnName))
                    throw new InvalidOperationException(String.Format("Could not resolve column '{0}' within the table '{1}'.", column,
                        GivenTableName));

                return new ObjectName(GivenTableName, columnName);
            }

            // Return the first column in the table
            return new ObjectName(GivenTableName, tableInfo[0].ColumnName);
        }