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); }
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; }
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); }
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); }
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); }
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; }
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; }
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; }
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); }