public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery) { SqlString condition = criterion.ToSqlString(criteria, criteriaQuery); var ifTrue = CriterionUtil.GetColumnNameAsSqlStringPart(whenTrue, criteriaQuery, criteria); var ifFalse = CriterionUtil.GetColumnNameAsSqlStringPart(whenFalse, criteriaQuery, criteria); return(new SqlString("(case when ", condition, " then ", ifTrue, " else ", ifFalse, " end) as ", GetColumnAlias(position))); }
private void AddValueOrProjection(Parameter[] parameters, int paramIndex, ICriteria criteria, ICriteriaQuery criteriaQuery, SqlStringBuilder result) { if (_projection == null) { result.Add(parameters[paramIndex]); } else { result.AddObject(CriterionUtil.GetColumnNameAsSqlStringPart(_projection, criteriaQuery, criteria)); } }
public override SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery) { var column = CriterionUtil.GetColumnNameAsSqlStringPart(propertyName, projection, criteriaQuery, criteria); return(new SqlString( aggregate, "(", column, ") as y", loc.ToString(), "_")); }
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery) { ISessionFactoryImplementor factory = criteriaQuery.Factory; SqlType[] sqlTypeCodes = type.SqlTypes(factory); if (sqlTypeCodes.Length != 1) { throw new QueryException("invalid Hibernate type for CastProjection"); } string sqlType = factory.Dialect.GetCastTypeName(sqlTypeCodes[0]); var val = CriterionUtil.GetColumnNameAsSqlStringPart(projection, criteriaQuery, criteria); return(new SqlString("cast( ", val, " as ", sqlType, ") as ", GetColumnAlias(position))); }
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery) { var buf = new SqlStringBuilder().Add("count("); if (distinct) { buf.Add("distinct "); } if (projection != null) { buf.AddObject(CriterionUtil.GetColumnNameAsSqlStringPart(projection, criteriaQuery, criteria)); } else { buf.Add(criteriaQuery.GetColumn(criteria, propertyName)); } buf.Add(") as y").Add(position.ToString()).Add("_"); return(buf.ToSqlString()); }
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery) { var sqlBuilder = new SqlStringBuilder(5 + (_cases.Length * 4)); sqlBuilder.Add("(case"); foreach (var projectionCase in _cases) { sqlBuilder.Add(" when "); sqlBuilder.Add(projectionCase.Criterion.ToSqlString(criteria, criteriaQuery)); sqlBuilder.Add(" then "); sqlBuilder.AddObject(CriterionUtil.GetColumnNameAsSqlStringPart(projectionCase.Projection, criteriaQuery, criteria)); } sqlBuilder.Add(" else "); sqlBuilder.AddObject(CriterionUtil.GetColumnNameAsSqlStringPart(_elseProjection, criteriaQuery, criteria)); sqlBuilder.Add(" end) as "); sqlBuilder.Add(GetColumnAlias(position)); return(sqlBuilder.ToSqlString()); }
public override SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery) { ISessionFactoryImplementor factory = criteriaQuery.Factory; SqlType[] sqlTypeCodes = NHibernateUtil.Double.SqlTypes(factory); string sqlType = factory.Dialect.GetCastTypeName(sqlTypeCodes[0]); var sql = new SqlStringBuilder().Add(aggregate).Add("("); sql.Add("cast("); if (projection != null) { sql.AddObject(CriterionUtil.GetColumnNameAsSqlStringPart(projection, criteriaQuery, criteria)); } else { sql.Add(criteriaQuery.GetColumn(criteria, propertyName)); } sql.Add(" as ").Add(sqlType).Add(")"); sql.Add(") as ").Add(GetColumnAliases(loc, criteria, criteriaQuery)[0]); return(sql.ToSqlString()); }