public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { //TODO: add default capacity SqlStringBuilder sqlBuilder = new SqlStringBuilder(); var columnNames = CriterionUtil.GetColumnNamesAsSqlStringParts(_propertyName, _projection, criteriaQuery, criteria); bool opNeeded = false; for (int i = 0; i < columnNames.Length; i++) { if (opNeeded) { sqlBuilder.Add(" or "); } opNeeded = true; sqlBuilder.AddObject(columnNames[i]) .Add(" is not null"); } if (columnNames.Length > 1) { sqlBuilder.Insert(0, "("); sqlBuilder.Add(")"); } return(sqlBuilder.ToSqlString()); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { //TODO: add default capacity SqlStringBuilder sqlBuilder = new SqlStringBuilder(); var columnNames = CriterionUtil.GetColumnNamesAsSqlStringParts(propertyName, projection, criteriaQuery, criteria); if (columnNames.Length != 1) { throw new HibernateException("insensitive like may only be used with single-column properties"); } if (criteriaQuery.Factory.Dialect is PostgreSQLDialect) { sqlBuilder.AddObject(columnNames[0]); sqlBuilder.Add(" ilike "); } else { sqlBuilder.Add(criteriaQuery.Factory.Dialect.LowercaseFunction) .Add("(") .AddObject(columnNames[0]) .Add(")") .Add(" like "); } sqlBuilder.Add(criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).Single()); return(sqlBuilder.ToSqlString()); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { var columnNames = CriterionUtil.GetColumnNamesAsSqlStringParts(_lhsPropertyName, _lhsProjection, criteriaQuery, criteria); var otherColumnNames = CriterionUtil.GetColumnNamesAsSqlStringParts(_rhsPropertyName, _rhsProjection, criteriaQuery, criteria); switch (columnNames.Length) { case 1: return(new SqlString(columnNames[0], Op, otherColumnNames[0])); case 0: return(SqlString.Empty); } var sb = new SqlStringBuilder(); sb.Add(StringHelper.OpenParen); sb.AddObject(columnNames[0]).Add(Op).AddObject(otherColumnNames[0]); for (var i = 1; i < columnNames.Length; i++) { sb.Add(" and "); sb.AddObject(columnNames[i]).Add(Op).AddObject(otherColumnNames[i]); } sb.Add(StringHelper.ClosedParen); return(sb.ToSqlString()); }
private object[] GetColumnsOrAliases(ICriteria criteria, ICriteriaQuery criteriaQuery) { var propName = propertyName ?? (projection as IPropertyProjection)?.PropertyName; return(propName != null ? criteriaQuery.GetColumnAliasesUsingProjection(criteria, propName) : CriterionUtil.GetColumnNamesAsSqlStringParts(projection, criteriaQuery, criteria)); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { //TODO: add a default capacity SqlStringBuilder sqlBuilder = new SqlStringBuilder(); var parametersTypes = GetTypedValues(criteria, criteriaQuery).ToArray(); var lowType = parametersTypes[0]; var highType = parametersTypes[1]; var columnNames = CriterionUtil.GetColumnNamesAsSqlStringParts(_propertyName, _projection, criteriaQuery, criteria); if (columnNames.Length == 1) { sqlBuilder .AddObject(columnNames[0]) .Add(" between ") .Add(criteriaQuery.NewQueryParameter(lowType).Single()) .Add(" and ") .Add(criteriaQuery.NewQueryParameter(highType).Single()); } else { bool andNeeded = false; var lowParameters = criteriaQuery.NewQueryParameter(lowType).ToArray(); for (int i = 0; i < columnNames.Length; i++) { if (andNeeded) { sqlBuilder.Add(" AND "); } andNeeded = true; sqlBuilder.AddObject(columnNames[i]) .Add(" >= ") .Add(lowParameters[i]); } var highParameters = criteriaQuery.NewQueryParameter(highType).ToArray(); for (int i = 0; i < columnNames.Length; i++) { sqlBuilder.Add(" AND ") .AddObject(columnNames[i]) .Add(" <= ") .Add(highParameters[i]); } } return(sqlBuilder.ToSqlString()); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { var columns = CriterionUtil.GetColumnNamesAsSqlStringParts(projection, criteriaQuery, criteria); var value = criteriaQuery.NewQueryParameter(typedValue).Single(); var arguments = new[] { columns[0], value }; var dialect = criteriaQuery.Factory.Dialect; var functionName = dialect.FullTextSearchFunction; var dialectFunction = criteriaQuery.Factory.SQLFunctionRegistry.FindSQLFunction(functionName); if (dialectFunction == null) { throw new HibernateException(string.Format("The current dialect '{0}' doesn't support the function: '{1}'", criteriaQuery.Factory.Dialect, functionName)); } return(dialectFunction.Render(arguments, criteriaQuery.Factory)); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { var columns = CriterionUtil.GetColumnNamesAsSqlStringParts(projection, criteriaQuery, criteria); if (columns.Length != 1) { throw new HibernateException("Like may only be used with single-column properties / projections."); } SqlStringBuilder lhs = new SqlStringBuilder(6); if (ignoreCase) { Dialect.Dialect dialect = criteriaQuery.Factory.Dialect; lhs.Add(dialect.LowercaseFunction) .Add(StringHelper.OpenParen) .AddObject(columns[0]) .Add(StringHelper.ClosedParen); } else { lhs.AddObject(columns[0]); } if (ignoreCase) { Dialect.Dialect dialect = criteriaQuery.Factory.Dialect; lhs.Add(" like ") .Add(dialect.LowercaseFunction) .Add(StringHelper.OpenParen) .Add(criteriaQuery.NewQueryParameter(typedValue).Single()) .Add(StringHelper.ClosedParen); } else { lhs.Add(" like ").Add(criteriaQuery.NewQueryParameter(typedValue).Single()); } if (escapeChar.HasValue) { lhs.Add(" escape '" + escapeChar + "'"); } return(lhs.ToSqlString()); }
private static object[] GetProjectionArguments(ICriteriaQuery criteriaQuery, ICriteria criteria, IProjection projection) { return(CriterionUtil.GetColumnNamesAsSqlStringParts(projection, criteriaQuery, criteria)); }