コード例 #1
0
        protected virtual TableDefinition ParseCreateTableStatement(SqliteSyntaxReader reader)
        {
            var table = new TableDefinition();

            while (reader.Read() != SqliteSyntaxReader.TokenType.StringToken || reader.ValueToUpper != "TABLE")
            {
                ;
            }

            if (reader.Read() == SqliteSyntaxReader.TokenType.StringToken && reader.ValueToUpper == "IF")
            {
                reader.Read(); // NOT
                reader.Read(); // EXISTS
            }
            else
            {
                reader.Rollback();
            }

            table.Name = ParseIdentifier(reader);

            // Find Column List
            reader.SkipTillToken(SqliteSyntaxReader.TokenType.ListStart);

            // Split the list.
            var list = reader.ReadList();

            foreach (var columnReader in list)
            {
                columnReader.SkipWhitespace();

                if (columnReader.Read() == SqliteSyntaxReader.TokenType.StringToken)
                {
                    if (columnReader.ValueToUpper == "CONSTRAINT" ||
                        columnReader.ValueToUpper == "PRIMARY" || columnReader.ValueToUpper == "UNIQUE" ||
                        columnReader.ValueToUpper == "CHECK" || columnReader.ValueToUpper == "FOREIGN")
                    {
                        continue;
                    }
                }

                columnReader.Rollback();

                var column = ParseColumnDefinition(columnReader);
                column.TableName = table.Name;
                table.Columns.Add(column);
            }

            return(table);
        }
コード例 #2
0
ファイル: SqliteSchemaDumper.cs プロジェクト: Djohnnie/Sonarr
        protected virtual TableDefinition ParseCreateTableStatement(SqliteSyntaxReader reader)
        {
            var table = new TableDefinition();

            while (reader.Read() != SqliteSyntaxReader.TokenType.StringToken || reader.ValueToUpper != "TABLE") ;

            if (reader.Read() == SqliteSyntaxReader.TokenType.StringToken && reader.ValueToUpper == "IF")
            {
                reader.Read(); // NOT
                reader.Read(); // EXISTS
            }
            else
            {
                reader.Rollback();
            }

            table.Name = ParseIdentifier(reader);

            // Find Column List
            reader.SkipTillToken(SqliteSyntaxReader.TokenType.ListStart);

            // Split the list.
            var list = reader.ReadList();

            foreach (var columnReader in list)
            {
                columnReader.SkipWhitespace();

                if (columnReader.Read() == SqliteSyntaxReader.TokenType.StringToken)
                {
                    if (columnReader.ValueToUpper == "CONSTRAINT" ||
                        columnReader.ValueToUpper == "PRIMARY" || columnReader.ValueToUpper == "UNIQUE" ||
                        columnReader.ValueToUpper == "CHECK" || columnReader.ValueToUpper == "FOREIGN")
                    {
                        continue;
                    }
                }

                columnReader.Rollback();

                var column = ParseColumnDefinition(columnReader);
                column.TableName = table.Name;
                table.Columns.Add(column);
            }

            return table;
        }
コード例 #3
0
        protected virtual IndexDefinition ParseCreateIndexStatement(SqliteSyntaxReader reader)
        {
            var index = new IndexDefinition();

            reader.Read();

            reader.Read();
            index.IsUnique = reader.ValueToUpper == "UNIQUE";

            while (reader.ValueToUpper != "INDEX")
            {
                reader.Read();
            }

            if (reader.Read() == SqliteSyntaxReader.TokenType.StringToken && reader.ValueToUpper == "IF")
            {
                reader.Read(); // NOT
                reader.Read(); // EXISTS
            }
            else
            {
                reader.Rollback();
            }

            index.Name = ParseIdentifier(reader);

            reader.Read(); // ON

            index.TableName = ParseIdentifier(reader);

            // Find Column List
            reader.SkipTillToken(SqliteSyntaxReader.TokenType.ListStart);

            // Split the list.
            var list = reader.ReadList();

            foreach (var columnReader in list)
            {
                var column = new IndexColumnDefinition();
                column.Name = ParseIdentifier(columnReader);

                while (columnReader.Read() == SqliteSyntaxReader.TokenType.StringToken)
                {
                    if (columnReader.ValueToUpper == "COLLATE")
                    {
                        columnReader.Read(); // Skip Collation name
                    }
                    else if (columnReader.ValueToUpper == "DESC")
                    {
                        column.Direction = Direction.Descending;
                    }
                }

                index.Columns.Add(column);
            }

            return(index);
        }
コード例 #4
0
ファイル: SqliteSchemaDumper.cs プロジェクト: jtolar/NzbDrone
        protected virtual String ParseIdentifier(SqliteSyntaxReader reader)
        {
            reader.Read();

            if (reader.Type != SqliteSyntaxReader.TokenType.Identifier &&
                reader.Type != SqliteSyntaxReader.TokenType.StringToken)
            {
                throw reader.CreateSyntaxException("Expected Identifier but found {0}", reader.Type);
            }

            return(reader.Value);
        }
コード例 #5
0
        protected virtual ColumnDefinition ParseColumnDefinition(SqliteSyntaxReader reader)
        {
            var column = new ColumnDefinition();

            column.Name = ParseIdentifier(reader);

            reader.TrimBuffer();

            reader.Read();
            if (reader.Type != SqliteSyntaxReader.TokenType.End)
            {
                column.Type = GetDbType(reader.Value);

                var upper = reader.Buffer.ToUpperInvariant();
                column.IsPrimaryKey = upper.Contains("PRIMARY KEY");
                column.IsIdentity   = upper.Contains("AUTOINCREMENT");
                column.IsNullable   = !upper.Contains("NOT NULL") && !upper.Contains("PRIMARY KEY");
                column.IsUnique     = upper.Contains("UNIQUE") || upper.Contains("PRIMARY KEY");
            }

            return(column);
        }
コード例 #6
0
ファイル: SqliteSchemaDumper.cs プロジェクト: Djohnnie/Sonarr
        protected virtual ColumnDefinition ParseColumnDefinition(SqliteSyntaxReader reader)
        {
            var column = new ColumnDefinition();

            column.Name = ParseIdentifier(reader);
            
            reader.TrimBuffer();

            reader.Read();
            if (reader.Type != SqliteSyntaxReader.TokenType.End)
            {
                column.Type = GetDbType(reader.Value);

                var upper = reader.Buffer.ToUpperInvariant();
                column.IsPrimaryKey = upper.Contains("PRIMARY KEY");
                column.IsIdentity = upper.Contains("AUTOINCREMENT");
                column.IsNullable = !upper.Contains("NOT NULL") && !upper.Contains("PRIMARY KEY");
                column.IsUnique = upper.Contains("UNIQUE") || upper.Contains("PRIMARY KEY");
            }

            return column;
        }
コード例 #7
0
ファイル: SqliteSchemaDumper.cs プロジェクト: Djohnnie/Sonarr
        protected virtual string ParseIdentifier(SqliteSyntaxReader reader)
        {
            reader.Read();

            if (reader.Type != SqliteSyntaxReader.TokenType.Identifier &&
                reader.Type != SqliteSyntaxReader.TokenType.StringToken &&
                reader.Type != SqliteSyntaxReader.TokenType.StringLiteral)
            {
                throw reader.CreateSyntaxException("Expected Identifier but found {0}", reader.Type);
            }

            return reader.Value;
        }
コード例 #8
0
ファイル: SqliteSchemaDumper.cs プロジェクト: Djohnnie/Sonarr
        protected virtual IndexDefinition ParseCreateIndexStatement(SqliteSyntaxReader reader)
        {
            var index = new IndexDefinition();

            reader.Read();

            reader.Read();
            index.IsUnique = reader.ValueToUpper == "UNIQUE";

            while (reader.ValueToUpper != "INDEX") reader.Read();

            if (reader.Read() == SqliteSyntaxReader.TokenType.StringToken && reader.ValueToUpper == "IF")
            {
                reader.Read(); // NOT
                reader.Read(); // EXISTS
            }
            else
            {
                reader.Rollback();
            }

            index.Name = ParseIdentifier(reader);

            reader.Read(); // ON

            index.TableName = ParseIdentifier(reader);
            
            // Find Column List
            reader.SkipTillToken(SqliteSyntaxReader.TokenType.ListStart);

            // Split the list.
            var list = reader.ReadList();

            foreach (var columnReader in list)
            {
                var column = new IndexColumnDefinition();
                column.Name = ParseIdentifier(columnReader);

                while (columnReader.Read() == SqliteSyntaxReader.TokenType.StringToken)
                {
                    if (columnReader.ValueToUpper == "COLLATE")
                    {
                        columnReader.Read(); // Skip Collation name
                    }
                    else if (columnReader.ValueToUpper == "DESC")
                    {
                        column.Direction = Direction.Descending;
                    }
                }

                index.Columns.Add(column);
            }

            return index;
        }
コード例 #9
0
ファイル: SqliteSchemaDumper.cs プロジェクト: whoshoe/Readarr
        protected virtual TableDefinition ParseCreateTableStatement(SqliteSyntaxReader reader)
        {
            var table = new TableDefinition();

            while (reader.Read() != SqliteSyntaxReader.TokenType.StringToken || reader.ValueToUpper != "TABLE")
            {
            }

            if (reader.Read() == SqliteSyntaxReader.TokenType.StringToken && reader.ValueToUpper == "IF")
            {
                reader.Read(); // NOT
                reader.Read(); // EXISTS
            }
            else
            {
                reader.Rollback();
            }

            table.Name = ParseIdentifier(reader);

            // Find Column List
            reader.SkipTillToken(SqliteSyntaxReader.TokenType.ListStart);

            // Split the list.
            var list = reader.ReadList();

            foreach (var columnReader in list)
            {
                columnReader.SkipWhitespace();

                if (columnReader.Read() == SqliteSyntaxReader.TokenType.StringToken)
                {
                    if (columnReader.ValueToUpper == "PRIMARY")
                    {
                        columnReader.SkipTillToken(SqliteSyntaxReader.TokenType.ListStart);
                        if (columnReader.Read() == SqliteSyntaxReader.TokenType.Identifier)
                        {
                            var pk = table.Columns.First(v => v.Name == columnReader.Value);
                            pk.IsPrimaryKey = true;
                            pk.IsNullable   = true;
                            pk.IsUnique     = true;
                            if (columnReader.Buffer.ToUpperInvariant().Contains("AUTOINCREMENT"))
                            {
                                pk.IsIdentity = true;
                            }

                            continue;
                        }
                    }

                    if (columnReader.ValueToUpper == "CONSTRAINT" ||
                        columnReader.ValueToUpper == "PRIMARY" || columnReader.ValueToUpper == "UNIQUE" ||
                        columnReader.ValueToUpper == "CHECK" || columnReader.ValueToUpper == "FOREIGN")
                    {
                        continue;
                    }
                }

                columnReader.Rollback();

                var column = ParseColumnDefinition(columnReader);
                column.TableName = table.Name;
                table.Columns.Add(column);
            }

            return(table);
        }