Exemple #1
0
        public SqlTableInfo ByName(string name)
        {
            var processed = SqlName.ProcessName(name);

            return(_tables.FirstOrDefault(t => string.Equals(t.Alias, processed, StringComparison.OrdinalIgnoreCase) ||
                                          (t.Name != null && string.Equals(t.Name.Name, processed, StringComparison.OrdinalIgnoreCase)) ||
                                          (t.Name != null && string.Equals(t.Name.FullName, processed, StringComparison.OrdinalIgnoreCase))));
        }
Exemple #2
0
        public IEnumerator <SqlNode> GetEnumerator()
        {
            SqlLiteral prevLiteral = null;
            SqlName    prevName    = null;

            var en = MarkKeywords().GetEnumerator();

            if (!en.MoveNext())
            {
                yield break;
            }
            prevLiteral = en.Current;

            while (en.MoveNext())
            {
                if (prevLiteral != null && (KeywordPrecedesTable(prevLiteral) ||
                                            prevLiteral.Text.StartsWith("create ", StringComparison.OrdinalIgnoreCase)))
                {
                    prevName         = new SqlName();
                    prevName.IsTable = true;
                    yield return(prevLiteral);

                    if (prevName.TryAdd(en.Current))
                    {
                        prevLiteral = null;
                    }
                    else
                    {
                        prevLiteral = en.Current;
                        prevName    = null;
                    }
                }
                else if (prevLiteral != null && prevLiteral.Type == SqlType.Identifier && en.Current.Text == ".")
                {
                    prevName = new SqlName();
                    if (prevName.TryAdd(prevLiteral) && prevName.TryAdd(en.Current))
                    {
                        prevLiteral = null;
                    }
                    else
                    {
                        yield return(prevLiteral);

                        prevLiteral = en.Current;
                        prevName    = null;
                    }
                }
                else if (prevName != null)
                {
                    if (!prevName.TryAdd(en.Current))
                    {
                        yield return(prevName);

                        prevName    = null;
                        prevLiteral = en.Current;
                    }
                }
                else
                {
                    yield return(prevLiteral);

                    prevLiteral = en.Current;
                }
            }

            if (prevLiteral != null)
            {
                yield return(prevLiteral);
            }
            if (prevName != null)
            {
                yield return(prevName);
            }
        }