use of net.sf.jsqlparser.schema.Column in project spanner-jdbc by olavloite.
the class CloudSpannerResultSetMetaData method initColumns.
private void initColumns(Select select) {
columns = new ArrayList<>();
aliases = new ArrayList<>();
select.getSelectBody().accept(new SelectVisitorAdapter() {
@Override
public void visit(PlainSelect plainSelect) {
for (SelectItem selectItem : plainSelect.getSelectItems()) {
selectItem.accept(new SelectItemVisitor() {
private boolean foundColumn = false;
@Override
public void visit(SelectExpressionItem selectExpressionItem) {
selectExpressionItem.getExpression().accept(new ExpressionVisitorAdapter() {
@Override
public void visit(Column column) {
registerColumn(column, selectExpressionItem.getAlias());
foundColumn = true;
}
});
if (!foundColumn) {
registerColumn(null, selectExpressionItem.getAlias());
}
}
@Override
public void visit(AllTableColumns allTableColumns) {
registerAllTableColumns(allTableColumns.getTable());
}
@Override
public void visit(AllColumns allColumns) {
for (Table table : tables) {
registerAllTableColumns(table);
}
}
});
}
}
});
}
use of net.sf.jsqlparser.schema.Column in project dbeaver by dbeaver.
the class SQLSemanticProcessor method getOrderConstraintExpression.
private static Expression getOrderConstraintExpression(DBRProgressMonitor monitor, DBPDataSource dataSource, PlainSelect select, DBDAttributeConstraint co, boolean forceNumeric) throws JSQLParserException, DBException {
Expression orderExpr;
String attrName = DBUtils.getQuotedIdentifier(dataSource, co.getAttributeName());
if (forceNumeric || attrName.isEmpty()) {
orderExpr = new LongValue(co.getOrderPosition());
} else if (CommonUtils.isJavaIdentifier(attrName)) {
// Use column table only if there are multiple source tables (joins)
Table orderTable = CommonUtils.isEmpty(select.getJoins()) ? null : getConstraintTable(select, co);
if (!isValidTableColumn(monitor, dataSource, orderTable, co)) {
orderTable = null;
}
orderExpr = new Column(orderTable, attrName);
} else {
// TODO: set tableAlias for all column references in expression
orderExpr = CCJSqlParserUtil.parseExpression(attrName);
// orderExpr = new CustomExpression(attrName);
// orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
}
return orderExpr;
}
use of net.sf.jsqlparser.schema.Column in project dbeaver by serge-rider.
the class SQLSemanticProcessor method getConstraintExpression.
private static Expression getConstraintExpression(PlainSelect select, DBDAttributeConstraint co) throws JSQLParserException {
Expression orderExpr;
String attrName = co.getAttribute().getName();
if (attrName.isEmpty()) {
orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
} else if (CommonUtils.isJavaIdentifier(attrName)) {
// Use column table only if there are multiple source tables (joins)
Table orderTable = CommonUtils.isEmpty(select.getJoins()) ? null : getConstraintTable(select, co);
orderExpr = new Column(orderTable, attrName);
} else {
// TODO: set tableAlias for all column references in expression
orderExpr = CCJSqlParserUtil.parseExpression(attrName);
//orderExpr = new CustomExpression(attrName);
//orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
}
return orderExpr;
}
use of net.sf.jsqlparser.schema.Column in project dbeaver by dbeaver.
the class SQLSemanticProcessor method getConstraintExpression.
private static Expression getConstraintExpression(DBPDataSource dataSource, PlainSelect select, DBDAttributeConstraint co) throws JSQLParserException {
Expression orderExpr;
String attrName = DBUtils.getQuotedIdentifier(dataSource, co.getAttribute().getName());
if (attrName.isEmpty()) {
orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
} else if (CommonUtils.isJavaIdentifier(attrName)) {
// Use column table only if there are multiple source tables (joins)
Table orderTable = CommonUtils.isEmpty(select.getJoins()) ? null : getConstraintTable(select, co);
orderExpr = new Column(orderTable, attrName);
} else {
// TODO: set tableAlias for all column references in expression
orderExpr = CCJSqlParserUtil.parseExpression(attrName);
// orderExpr = new CustomExpression(attrName);
// orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
}
return orderExpr;
}
use of net.sf.jsqlparser.schema.Column in project JSqlParser by JSQLParser.
the class CreateViewDeParserTest method testUseExtrnalExpressionDeparser.
/**
* Test of deParse method, of class CreateViewDeParser.
*/
@Test
public void testUseExtrnalExpressionDeparser() throws JSQLParserException {
StringBuilder b = new StringBuilder();
SelectDeParser selectDeParser = new SelectDeParser();
selectDeParser.setBuffer(b);
ExpressionDeParser expressionDeParser = new ExpressionDeParser(selectDeParser, b) {
@Override
public void visit(Column tableColumn) {
final Table table = tableColumn.getTable();
String tableName = null;
if (table != null) {
if (table.getAlias() != null) {
tableName = table.getAlias().getName();
} else {
tableName = table.getFullyQualifiedName();
}
}
if (tableName != null && !tableName.isEmpty()) {
getBuffer().append("\"").append(tableName).append("\"").append(".");
}
getBuffer().append("\"").append(tableColumn.getColumnName()).append("\"");
}
};
selectDeParser.setExpressionVisitor(expressionDeParser);
CreateViewDeParser instance = new CreateViewDeParser(b, selectDeParser);
CreateView vc = (CreateView) CCJSqlParserUtil.parse("CREATE VIEW test AS SELECT a, b FROM mytable");
instance.deParse(vc);
assertEquals("CREATE VIEW test AS SELECT a, b FROM mytable", vc.toString());
assertEquals("CREATE VIEW test AS SELECT \"a\", \"b\" FROM mytable", instance.getBuffer().toString());
}
Aggregations