예제 #1
0
        private static IEnumerable <SelectColumn> _Parse(Benumerator <char> en)
        {
            // Next value MUST be "SELECT "
            if (en.Current != 'S' || !en.MoveNext() ||
                en.Current != 'E' || !en.MoveNext() ||
                en.Current != 'L' || !en.MoveNext() ||
                en.Current != 'E' || !en.MoveNext() ||
                en.Current != 'C' || !en.MoveNext() ||
                en.Current != 'T' || !en.MoveNext() ||
                en.Current != ' ' || !en.MoveNext()
                )
            {
                throw new Exception("failed to parse SELECT. Expecting SELECT keyword");
            }


            // I am very lazily forcing the use of * for now
            foreach (var col in SelectColumn.Parse(en, true))
            {
                yield return(col);
            }
        }
예제 #2
0
파일: Insert.cs 프로젝트: hearnderek/SDB
        public static new Insert Parse(Benumerator <char> en)
        {
            if (!en.MoveNext() || en.Current == ' ' && !en.MoveNext())
            {
                throw new Exception("failed to parse. No Input");
            }


            if (!Parser.HasValue(en, "INSERT INTO "))
            {
                throw new Exception("failed to parse INSERT. Expecting 'INSERT INTO '");
            }


            var tableName = Parser.ParseWord(en);

            Parser.SkipWhitespace(en);

            if (!Parser.HasValue(en, "("))
            {
                throw new Exception("failed to parse INSERT. Expecting '('");
            }

            var columns = SelectColumn.Parse(en).ToArray();

            Parser.SkipWhitespace(en);

            if (!Parser.HasValue(en, ")"))
            {
                throw new Exception("failed to parse INSERT. Expecting ')'");
            }
            Parser.SkipWhitespace(en);

            if (!Parser.HasValue(en, "VALUES"))
            {
                throw new Exception("failed to parse INSERT. Expecting ')'");
            }

            List <SelectColumn[]> rows = new List <SelectColumn[]>();

            do
            {
                Parser.SkipWhitespace(en);

                if (!Parser.HasValue(en, "("))
                {
                    throw new Exception("failed to parse INSERT. Expecting ')'");
                }

                Parser.SkipWhitespace(en);

                var values = SelectColumn.Parse(en).ToArray();
                if (values.Length != columns.Length)
                {
                    throw new Exception("failed to parse INSERT. Number of values do not match number of columns");
                }
                rows.Add(values);

                Parser.SkipWhitespace(en);

                if (!Parser.HasValue(en, ")"))
                {
                    throw new Exception("failed to parse INSERT. Expecting ')'");
                }

                Parser.SkipWhitespace(en);
            } while (Parser.HasValue(en, ","));

            return(new Insert
            {
                tableName = tableName,
                columns = columns,
                rows = rows
            });
        }