Adds a sql projection to the criteria

@param sql SQL projecting a single value
@param columnAlias column alias for the projected value
@param type the type of the projected value
492078
protected void sqlProjection(String sql, String columnAlias, Type type) {
        sqlProjection(sql, Collections.singletonList(columnAlias), Collections.singletonList(type));
    }
665739
public void setSql(String sql) {
		if (StringUtils.isNotEmpty(sql)) {
			this.sql = sql.trim();
			this.comment = parseComment(sql);
			this.digest = MessageDigestUtils.MD5(sql);
			
			String sqlStatement = this.sql.toLowerCase();
			if (sqlStatement != null) {
				this.select = sqlStatement.startsWith("select");
				this.procedure = sqlStatement.startsWith("call");
			}
		}
	}
135427
protected void validateOrderList(SqlSelect select) {
		// ORDER BY is validated in a scope where aliases in the SELECT clause
		// are visible. For example, "SELECT empno AS x FROM emp ORDER BY x"
		// is valid.
		SqlNodeList orderList = select.getOrderList();
		if (orderList == null) {
			return;
		}
		if (!shouldAllowIntermediateOrderBy()) {
			if (!cursorSet.contains(select)) {
				throw newValidationError(select, RESOURCE.invalidOrderByPos());
			}
		}
		final SqlValidatorScope orderScope = getOrderScope(select);
		Objects.requireNonNull(orderScope);

		List<SqlNode> expandList = new ArrayList<>();
		for (SqlNode orderItem : orderList) {
			SqlNode expandedOrderItem = expand(orderItem, orderScope);
			expandList.add(expandedOrderItem);
		}

		SqlNodeList expandedOrderList = new SqlNodeList(
			expandList,
			orderList.getParserPosition());
		select.setOrderBy(expandedOrderList);

		for (SqlNode orderItem : expandedOrderList) {
			validateOrderItem(select, orderItem);
		}
	}
499023
public static String toSingleColumnSql(String sql) {
		String tempSql = sql.trim();
		String regex = "(?i)^select(.*?)from";
		Matcher m = Pattern.compile(regex).matcher(tempSql);
		String columnAlias = SqlTemplate.SINGLE_COLUMN_ALIAS;
		if (m.find()) {
			columnAlias = m.group(1).trim().replaceAll("\\(\\s+", "(").replaceAll("\\s+\\)", ")").split("\\s+")[0]+ " AS " + columnAlias;
		}
		return tempSql.replaceFirst(regex, "select " + columnAlias + " from ");
	}
479787
public <T> List<T> selectList(String sql, Class<T> resultType) {
        String msId;
        if (resultType == null) {
            msId = msUtils.select(sql);
        } else {
            msId = msUtils.select(sql, resultType);
        }
        return sqlSession.selectList(msId);
    }
1008012
public function addOrderBy(string $sql, ?string $type, array $params = [])
    {
        $this->orderBy[] = [
            'sql'    => $sql,
            'type'   => $type,
            'params' => $params,
        ];

        return $this;
    }
1328908
public void addAlias(CmsDbContext dbc, CmsProject project, CmsAlias alias) throws CmsException {

        I_CmsVfsDriver vfsDriver = getVfsDriver(dbc);
        vfsDriver.insertAlias(dbc, project, alias);
    }
608310
public void addAlias(Object alias) {
	  if (lock == SET) {
		 throw new IllegalStateException("EntryInfo is locked");
	  }
	  if (alias != null && !alias.equals("")) {
		  aliasList.add(alias);
	  }
   }
928231
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) {
        record(parameterIndex, getDeclaredMethod(CallableStatement.class, "registerOutParameter", int.class, int.class, int.class), parameterIndex, sqlType, typeName);
    }
1124077
function (type) {
            var sql = [("" + type).toUpperCase()];
            try {
                this._static[sql + "_CLAUSE_METHODS"].forEach(function (m) {
                    if (m.match("With")) {
                        this[m](sql);
                    } else {
                        var sqlRet = this[m]();
                        if (sqlRet) {
                            sql.push(sqlRet);
                        }
                    }
                }, this);
            } catch (e) {
                throw e;
            }
            return sql.join("");
        }
1036305
public Object querySingleResult(String sql, String[] args, int column,
			GeoPackageDataType dataType) {
		return db.querySingleResult(sql, args, column, dataType);
	}
1171983
protected void appendCriteria(TableAlias alias, PathInfo pathInfo, SelectionCriteria c, StringBuffer buf)
    {
        if (c instanceof FieldCriteria)
        {
            appendFieldCriteria(alias, pathInfo, (FieldCriteria) c, buf);
        }
        else if (c instanceof NullCriteria)
        {
            appendNullCriteria(alias, pathInfo, (NullCriteria) c, buf);
        }
        else if (c instanceof BetweenCriteria)
        {
            appendBetweenCriteria(alias, pathInfo, (BetweenCriteria) c, buf);
        }
        else if (c instanceof InCriteria)
        {
            appendInCriteria(alias, pathInfo, (InCriteria) c, buf);
        }
        else if (c instanceof SqlCriteria)
        {
            appendSQLCriteria((SqlCriteria) c, buf);
        }
        else if (c instanceof ExistsCriteria)
        {
            appendExistsCriteria((ExistsCriteria) c, buf);
        }
        else if (c instanceof LikeCriteria)
        {
            appendLikeCriteria(alias, pathInfo, (LikeCriteria) c, buf);
        }
        else
        {
            appendSelectionCriteria(alias, pathInfo, c, buf);
        }
    }
715945
private function _join($type, $mixed, $criteria, $alias='')
    {
        if (is_object($mixed)) {
            $this->_joins []= sprintf('%s (%s) %s %s', $type, $mixed, $alias ?: 'derived', $criteria);
        } elseif ($alias) {
            $this->_joins []= sprintf('%s `%s` AS `%s` %s', $type, $mixed, $alias, $criteria);
        } else {
            $this->_joins []= sprintf('%s `%s` %s', $type, $mixed, $criteria);
        }

        return $this;
    }
324319
def add_order_by_for_association_limiting!(sql, options)
      return sql if options[:order].blank?

      order_columns = extract_order_columns(options[:order]) do |columns|
        columns.map! { |s| $1 if s =~ / (.*)/ }; columns
      end
      order = order_columns.map { |s, i| "alias_#{i}__ #{s}" } # @see {#distinct}

      sql << "ORDER BY #{order.join(', ')}"
    end
1069032
@SuppressWarnings("rawtypes")
    public org.grails.datastore.mapping.query.api.ProjectionList distinct(Collection propertyNames, String alias) {
        ProjectionList list = Projections.projectionList();
        for (Object o : propertyNames) {
            list.add(Projections.property(calculatePropertyName(o.toString())));
        }
        final Projection proj = Projections.distinct(list);
        addProjectionToList(proj, alias);
        return this;
    }
123271
public function addSelectQuery(Criteria $subQueryCriteria, $alias = null)
    {
        if (null === $alias) {
            $alias = 'alias_' . ($subQueryCriteria->forgeSelectQueryAlias() + count($this->selectQueries));
        }
        $this->selectQueries[$alias] = $subQueryCriteria;

        return $this;
    }
959936
def _alias_columns(self, sql):
        """"""
        qn = self.connection.ops.quote_name

        outer = list()
        inner = list()
        names_seen = list()

        # replace all parens with placeholders
        paren_depth, paren_buf = 0, ['']
        parens, i = {}, 0
        for ch in sql:
            if ch == '(':
                i += 1
                paren_depth += 1
                paren_buf.append('')
            elif ch == ')':
                paren_depth -= 1
                key = '_placeholder_{0}'.format(i)
                buf = paren_buf.pop()

                # store the expanded paren string
                buf = re.sub(r'%([^\(])', r'$$$\1', buf)
                parens[key] = buf% parens
                parens[key] = re.sub(r'\$\$\$([^\(])', r'%\1', parens[key])
                #cannot use {} because IBM's DB2 uses {} as quotes
                paren_buf[paren_depth] += '(%(' + key + ')s)'
            else:
                paren_buf[paren_depth] += ch

        def _replace_sub(col):
            """Replace all placeholders with expanded values"""
            while _re_col_placeholder.search(col):
                col = col.format(**parens)
            return col

        temp_sql = ''.join(paren_buf)

        # replace any bare %s with placeholders.  Needed when the WHERE
        # clause only contains one condition, and isn't wrapped in parens.
        # the placeholder_data is used to prevent the variable "i" from
        # being interpreted as a local variable in the replacement function
        placeholder_data = { "i": i }
        def _alias_placeholders(val):
            i = placeholder_data["i"]
            i += 1
            placeholder_data["i"] = i
            key = "_placeholder_{0}".format(i)
            parens[key] = "%s"
            return "%(" + key + ")s"

        temp_sql = re.sub("%s", _alias_placeholders, temp_sql)

        select_list, from_clause = _break(temp_sql, ' FROM ' + self.connection.ops.left_sql_quote)

        for col in [x.strip() for x in select_list.split(',')]:
            match = self._re_pat_col.search(col)
            if match:
                col_name = match.group(1)
                col_key = col_name.lower()

                if col_key in names_seen:
                    alias = qn('{0}___{1}'.format(col_name, names_seen.count(col_key)))
                    outer.append(alias)
                    inner.append('{0} as {1}'.format(_replace_sub(col), alias))
                else:
                    outer.append(qn(col_name))
                    inner.append(_replace_sub(col))

                names_seen.append(col_key)
            else:
                raise Exception('Unable to find a column name when parsing SQL: {0}'.format(col))

        return ', '.join(outer), ', '.join(inner) + (from_clause % parens)