Beispiel #1
0
  public boolean visit(SQLColumnDefinition x) {
    MySqlSQLColumnDefinition mysqlColumn = null;

    if (x instanceof MySqlSQLColumnDefinition) {
      mysqlColumn = (MySqlSQLColumnDefinition) x;
    }

    x.getName().accept(this);
    print(' ');
    x.getDataType().accept(this);

    if (x.getDefaultExpr() != null) {
      print(" DEFAULT ");
      x.getDefaultExpr().accept(this);
    }

    if (mysqlColumn != null && mysqlColumn.isAutoIncrement()) {
      print(" AUTO_INCREMENT");
    }

    for (SQLColumnConstraint item : x.getConstaints()) {
      print(' ');
      item.accept(this);
    }

    return false;
  }
Beispiel #2
0
  public SQLColumnDefinition parseColumnRest(SQLColumnDefinition column) {
    if (lexer.token() == Token.ON) {
      lexer.nextToken();
      accept(Token.UPDATE);
      SQLExpr expr = this.expr();
      ((MySqlSQLColumnDefinition) column).setOnUpdate(expr);
    }

    if (identifierEquals("AUTO_INCREMENT")) {
      lexer.nextToken();
      if (column instanceof MySqlSQLColumnDefinition) {
        ((MySqlSQLColumnDefinition) column).setAutoIncrement(true);
      }
      return parseColumnRest(column);
    }

    if (identifierEquals("precision")
        && column.getDataType().getName().equalsIgnoreCase("double")) {
      lexer.nextToken();
    }

    if (identifierEquals("PARTITION")) {
      throw new ParserException("syntax error " + lexer.token() + " " + lexer.stringVal());
    }

    if (identifierEquals("COMMENT")) {
      lexer.nextToken();
      column.setComment(lexer.stringVal());
      accept(Token.LITERAL_CHARS);
    }

    super.parseColumnRest(column);

    return column;
  }
  @Override
  public boolean visit(SQLAlterTableAddColumn x) {
    SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
    String table = stmt.getName().toString();

    for (SQLColumnDefinition column : x.getColumns()) {
      String columnName = column.getName().toString();
      addColumn(table, columnName);
    }
    return false;
  }
  public boolean visit(SQLColumnDefinition x) {
    String tableName = null;
    {
      SQLObject parent = x.getParent();
      if (parent instanceof SQLCreateTableStatement) {
        tableName = ((SQLCreateTableStatement) parent).getName().toString();
      }
    }

    if (tableName == null) {
      return true;
    }

    String columnName = x.getName().toString();
    addColumn(tableName, columnName);

    return false;
  }
  public SQLColumnDefinition parseColumnRest(SQLColumnDefinition column) {
    column = super.parseColumnRest(column);

    if (lexer.token() == Token.ENABLE) {
      lexer.nextToken();
      column.setEnable(Boolean.TRUE);
    }

    return column;
  }