/** * Get the alias name of a column or SQL expression * if it is not an aliased expression. * * @return the alias name */ public String getAlias() { return StringUtils.unEnclose(getSQL()); }
buff.append(StringUtils.unEnclose(joinCondition.getSQL())); buff.append(StringUtils.unEnclose(joinCondition.getSQL())); String condition = StringUtils.unEnclose(filterCondition.getSQL()); condition = "/* WHERE " + StringUtils.quoteRemarkSQL(condition) + "\n*/"; buff.append(StringUtils.indent(condition, 4, false));
buff.append("\nWHERE ").append(StringUtils.unEnclose(condition.getSQL())); g = g.getNonAliasExpression(); buff.appendExceptFirst(", "); buff.append(StringUtils.unEnclose(g.getSQL())); for (Expression g : group) { buff.appendExceptFirst(", "); buff.append(StringUtils.unEnclose(g.getSQL())); buff.append("\nHAVING ").append(StringUtils.unEnclose(h.getSQL())); } else if (havingIndex >= 0) { Expression h = exprList[havingIndex]; buff.append("\nHAVING ").append(StringUtils.unEnclose(h.getSQL())); for (SelectOrderBy o : orderList) { buff.appendExceptFirst(", "); buff.append(StringUtils.unEnclose(o.getSQL())); buff.append("\nLIMIT ").append(StringUtils.unEnclose(limitExpr.getSQL())); if (offsetExpr != null) { buff.append(" OFFSET ").append(StringUtils.unEnclose(offsetExpr.getSQL())); buff.append("\nSAMPLE_SIZE ").append(StringUtils.unEnclose(sampleSizeExpr.getSQL()));
/** * @see http://dev.mysql.com/doc/refman/5.7/en/delete.html */ @Override public SQLTranslated translate(Delete prepared, ObjectNode node) { ArrayList<Value> params = New.arrayList(); String forTable = node.getCompositeObjectName(); Expression condition = prepared.getCondition(); Expression limitExpr = prepared.getLimitExpr(); StatementBuilder sql = new StatementBuilder(); sql.append("DELETE FROM "); sql.append(identifier(forTable)); if (condition != null) { condition.getPreparedSQL(prepared.getSession(), params); sql.append(" WHERE ").append(StringUtils.unEnclose(condition.getSQL())); } if (limitExpr != null) { limitExpr.getPreparedSQL(prepared.getSession(), params); sql.append(" LIMIT ").append(StringUtils.unEnclose(limitExpr.getSQL())); } return SQLTranslated.build().sql(sql.toString()).sqlParams(params); }
/** * Create the SQL snippet that describes this sort order. * This is the SQL snippet that usually appears after the ORDER BY clause. * * @param list the expression list * @param visible the number of columns in the select list * @return the SQL snippet */ public String getSQL(Expression[] list, int visible) { StatementBuilder buff = new StatementBuilder(); int i = 0; for (int idx : queryColumnIndexes) { buff.appendExceptFirst(", "); if (idx < visible) { buff.append(idx + 1); } else { buff.append('=').append(StringUtils.unEnclose(list[idx].getSQL())); } int type = sortTypes[i++]; if ((type & DESCENDING) != 0) { buff.append(" DESC"); } if ((type & NULLS_FIRST) != 0) { buff.append(" NULLS FIRST"); } else if ((type & NULLS_LAST) != 0) { buff.append(" NULLS LAST"); } } return buff.toString(); }
if (condition != null) { buff.append(" WHERE ").append( StringUtils.unEnclose(condition.getPreparedSQL(select.getSession(), params))); g = g.getNonAliasExpression(); buff.appendExceptFirst(", "); buff.append(StringUtils.unEnclose(g.getPreparedSQL(select.getSession(), params))); for (Expression g : group) { buff.appendExceptFirst(", "); buff.append(StringUtils.unEnclose(g.getPreparedSQL(select.getSession(), params)));
@Override public SQLTranslated translate(Column[] searchColumns, TableFilter filter, ObjectNode node) { // can not use the field sqlStatement because the parameter // indexes may be incorrect: ? may be in fact ?2 for a subquery // but indexes may be set manually as well if (node instanceof GroupObjectNode) { return translate(searchColumns, filter, (GroupObjectNode) node); } List<Value> params = New.arrayList(10); StatementBuilder buff = new StatementBuilder("SELECT"); int visibleColumnCount = searchColumns.length; for (int i = 0; i < visibleColumnCount; i++) { buff.appendExceptFirst(","); buff.append(' '); buff.append(identifier(searchColumns[i].getName())); } buff.append(" FROM "); buff.append(identifier(node.getCompositeObjectName())); buff.append(" AS "); buff.append(filter.getTableAlias()); Expression condition = filter.getFilterCondition(); if (condition != null) { buff.append(" WHERE ").append(StringUtils.unEnclose(condition.getPreparedSQL(filter.getSession(), params))); } return SQLTranslated.build().sql(buff.toString()).sqlParams(params); }