studio.raptor.sqlparser.fast.expression.Wildcard Maven / Gradle / Ivy
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package studio.raptor.sqlparser.fast.expression;
import studio.raptor.sqlparser.fast.api.ErrorCode;
import studio.raptor.sqlparser.fast.message.ParseException;
import studio.raptor.sqlparser.fast.util.StringUtils;
import studio.raptor.sqlparser.fast.value.Value;
import studio.raptor.sqlparser.fast.table.ColumnResolver;
/**
* A wildcard expression as in SELECT * FROM TEST.
* This object is only used temporarily during the parsing phase, and later
* replaced by column expressions.
*/
public class Wildcard extends Expression {
private final String table;
public Wildcard(String table) {
this.table = table;
}
@Override
public boolean isWildcard() {
return true;
}
@Override
public void mapColumns(ColumnResolver resolver, int level) {
throw ParseException.get(ErrorCode.SYNTAX_ERROR_1, table);
}
@Override
public Expression optimize() {
throw ParseException.get(ErrorCode.SYNTAX_ERROR_1, table);
}
@Override
public String getTableAlias() {
return table;
}
@Override
public String getSQL() {
if (table == null) {
return "*";
}
return StringUtils.quoteIdentifier(table) + ".*";
}
@Override
public boolean isEverything(ExpressionVisitor visitor) {
if (visitor.getType() == ExpressionVisitor.QUERY_COMPARABLE) {
return true;
}
throw ParseException.throwInternalError("" + visitor.getType());
}
@Override
public Value getValue() {
return null;
}
@Override
public int getType() {
return 0;
}
}