Example #1
0
        internal static TableAndColumn FindTable(string tableName, Dictionary <string, Table> tables)
        {
            tableName = CleanName(tableName);

            var result = new TableAndColumn(  );

            if (string.IsNullOrWhiteSpace(tableName) == false)
            {
                if (tables.ContainsKey(tableName))
                {
                    result.TableName = tableName;
                    result.Table     = tables[tableName];
                    return(result);
                }
                else
                {
                    var foundTables = tables.Where(t => t.Value.Name == tableName).ToList( );
                    if (foundTables.Count( ) != 1)
                    {
                        throw new SqlInvalidTableNameException(tableName);
                    }

                    result.TableName = foundTables[0].Key;
                    result.Table     = foundTables[0].Value;
                    return(result);
                }
            }

            return(result);
        }
Example #2
0
        public static Column FindColumn(TableAndColumn tableAndColumn, string columnName, Dictionary <string, Table> tables)
        {
            columnName = CleanName(columnName);

            if (tableAndColumn.Table == null)
            {
                var foundTables = tables.Where(t => t.Value.Columns.Any(c => c.Name == columnName)).ToList( );
                if (foundTables.Count != 1)
                {
                    throw new SqlUnqualifiedColumnNameException(columnName);
                }

                tableAndColumn.TableName = foundTables[0].Key;
                tableAndColumn.Table     = foundTables[0].Value;
            }

            if (tableAndColumn.Table.Columns.Any(c => c.Name == columnName) == false)
            {
                throw new SqlInvalidColumnNameException(columnName);
            }

            return(tableAndColumn.Table.Columns.Single(c => c.Name == columnName));
        }