/// <exception cref="System.SqlSyntaxErrorException" /> private void CreateTableDefs(DdlCreateTableStatement stmt) { if (lexer.Token() != MySqlToken.PuncLeftParen) { return; } Match(MySqlToken.PuncLeftParen); IndexDefinition indexDef; Identifier id; for (var i = 0; lexer.Token() != MySqlToken.PuncRightParen; ++i) { if (i > 0) { Match(MySqlToken.PuncComma); } switch (lexer.Token()) { case MySqlToken.KwPrimary: { lexer.NextToken(); Match(MySqlToken.KwKey); indexDef = IndexDefinition(); stmt.SetPrimaryKey(indexDef); break; } case MySqlToken.KwIndex: case MySqlToken.KwKey: { lexer.NextToken(); if (lexer.Token() == MySqlToken.Identifier) { id = Identifier(); } else { id = null; } indexDef = IndexDefinition(); stmt.AddIndex(id, indexDef); break; } case MySqlToken.KwUnique: { switch (lexer.NextToken()) { case MySqlToken.KwIndex: case MySqlToken.KwKey: { lexer.NextToken(); break; } } if (lexer.Token() == MySqlToken.Identifier) { id = Identifier(); } else { id = null; } indexDef = IndexDefinition(); stmt.AddUniqueIndex(id, indexDef); break; } case MySqlToken.KwFulltext: { switch (lexer.NextToken()) { case MySqlToken.KwIndex: case MySqlToken.KwKey: { lexer.NextToken(); break; } } if (lexer.Token() == MySqlToken.Identifier) { id = Identifier(); } else { id = null; } indexDef = IndexDefinition(); if (indexDef.IndexType != IndexType.None) { throw new SqlSyntaxErrorException("FULLTEXT INDEX can specify no index_type"); } stmt.AddFullTextIndex(id, indexDef); break; } case MySqlToken.KwSpatial: { switch (lexer.NextToken()) { case MySqlToken.KwIndex: case MySqlToken.KwKey: { lexer.NextToken(); break; } } if (lexer.Token() == MySqlToken.Identifier) { id = Identifier(); } else { id = null; } indexDef = IndexDefinition(); if (indexDef.IndexType != IndexType.None) { throw new SqlSyntaxErrorException("SPATIAL INDEX can specify no index_type"); } stmt.AddSpatialIndex(id, indexDef); break; } case MySqlToken.KwCheck: { lexer.NextToken(); Match(MySqlToken.PuncLeftParen); var expr = exprParser.Expression(); Match(MySqlToken.PuncRightParen); stmt.AddCheck(expr); break; } case MySqlToken.Identifier: { var columnName = Identifier(); var columnDef = ColumnDefinition(); stmt.AddColumnDefinition(columnName, columnDef); break; } default: { throw new SqlSyntaxErrorException("unsupportted column definition"); } } } Match(MySqlToken.PuncRightParen); }
public virtual void Visit(DdlCreateTableStatement node) { VisitInternal(node.Table); }
/// <summary><code>TABLE</code> has been consumed</summary> /// <exception cref="System.SqlSyntaxErrorException" /> private DdlCreateTableStatement CreateTable(bool temp) { var ifNotExists = false; if (lexer.Token() == MySqlToken.KwIf) { lexer.NextToken(); Match(MySqlToken.KwNot); Match(MySqlToken.KwExists); ifNotExists = true; } var table = Identifier(); var stmt = new DdlCreateTableStatement(temp, ifNotExists, table); CreateTableDefs(stmt); var options = new DdlTableOptions(); stmt.SetTableOptions(options); TableOptions(options); var selectOpt = CreateTableSelectOption.None; switch (lexer.Token()) { case MySqlToken.KwIgnore: { selectOpt = CreateTableSelectOption.Ignored; if (lexer.NextToken() == MySqlToken.KwAs) { lexer.NextToken(); } break; } case MySqlToken.KwReplace: { selectOpt = CreateTableSelectOption.Replace; if (lexer.NextToken() == MySqlToken.KwAs) { lexer.NextToken(); } break; } case MySqlToken.KwAs: { lexer.NextToken(); goto case MySqlToken.KwSelect; } case MySqlToken.KwSelect: { break; } case MySqlToken.Eof: { return stmt; } default: { throw new SqlSyntaxErrorException("Ddl CREATE TABLE statement not end properly"); } } var select = new MySqlDmlSelectParser(lexer, exprParser).Select(); stmt.SetSelect(selectOpt, select); Match(MySqlToken.Eof); return stmt; }