/// <summary> /// Render a SqlString for the expression. /// </summary> /// <param name="criteria"></param> /// <param name="criteriaQuery"></param> /// <param name="enabledFilters"></param> /// <returns> /// A SqlString that contains a valid Sql fragment. /// </returns> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); ISpatialDialect spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect; string[] columnsUsingProjection = criteriaQuery.GetColumnsUsingProjection(criteria, this.propertyName); IType typeUsingProjection = criteriaQuery.GetTypeUsingProjection(criteria, this.propertyName); if (typeUsingProjection.ReturnedClass != typeof(IGeometry)) { throw new QueryException(string.Format("Type mismatch in {0}: {1} expected type {2}, actual type {3}", GetType(), this.propertyName, typeof(IGeometry), typeUsingProjection.ReturnedClass)); } if (typeUsingProjection.IsCollectionType) { throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), this.propertyName)); } SqlStringBuilder builder = new SqlStringBuilder(2 * columnsUsingProjection.Length); for (int i = 0; i < columnsUsingProjection.Length; i++) { if (i > 0) { builder.Add(" AND "); } builder.Add(spatialDialect.GetSpatialValidationString(columnsUsingProjection[i], this.validation, true)); } return(builder.ToSqlString()); }
private static SqlString[] GetColumnNamesUsingPropertyName( ICriteriaQuery criteriaQuery, ICriteria criteria, string propertyName, object value, ICriterion critertion) { var columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); var propertyType = criteriaQuery.GetTypeUsingProjection(criteria, propertyName); var type = propertyType.ReturnedClass; var elementTypes = type.GetGenericArguments(); var elementType = (elementTypes.Length > 0) ? elementTypes[0] : null; if (value != null) { if (!type.IsInstanceOfType(value) && elementType == null) { throw new QueryException(string.Format( "Type mismatch in {0}: {1} expected type {2}, actual type {3}", critertion.GetType(), propertyName, type, value.GetType())); } else if (!type.IsInstanceOfType(value) && !elementType.IsInstanceOfType(value)) { throw new QueryException(string.Format( "Type mismatch in {0}: {1} expected types {2} or {3}, actual type {4}", critertion.GetType(), propertyName, type, elementType, value.GetType())); } } return(Array.ConvertAll(columnNames, (col) => new SqlString(col))); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters) { //TODO: add default capacity SqlStringBuilder sqlBuilder = new SqlStringBuilder(); string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName); bool opNeeded = false; for (int i = 0; i < columnNames.Length; i++) { if (opNeeded) { sqlBuilder.Add(" or "); } opNeeded = true; sqlBuilder.Add(columnNames[i]) .Add(" is not null"); } if (columnNames.Length > 1) { sqlBuilder.Insert(0, "("); sqlBuilder.Add(")"); } return sqlBuilder.ToSqlString(); }
/// <summary> /// Render a SqlString for the expression. /// </summary> /// <param name="criteria"></param> /// <param name="criteriaQuery"></param> /// <param name="enabledFilters"></param> /// <returns> /// A SqlString that contains a valid Sql fragment. /// </returns> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); ISpatialDialect spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect; string[] columnsUsingProjection = criteriaQuery.GetColumnsUsingProjection(criteria, this.propertyName); IType typeUsingProjection = criteriaQuery.GetTypeUsingProjection(criteria, this.propertyName); if (typeUsingProjection.ReturnedClass != typeof(IGeometry)) { throw new QueryException(string.Format("Type mismatch in {0}: {1} expected type {2}, actual type {3}", GetType(), this.propertyName, typeof(IGeometry), typeUsingProjection.ReturnedClass)); } if (typeUsingProjection.IsCollectionType) { throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), this.propertyName)); } SqlStringBuilder builder = new SqlStringBuilder(2 * columnsUsingProjection.Length); for (int i = 0; i < columnsUsingProjection.Length; i++) { if (i > 0) { builder.Add(" AND "); } builder.Add(spatialDialect.GetSpatialValidationString(columnsUsingProjection[i], this.validation, true)); } return builder.ToSqlString(); }
private static SqlString[] GetColumnNamesUsingPropertyName( ICriteriaQuery criteriaQuery, ICriteria criteria, string propertyName, object value, ICriterion critertion) { string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); IType propertyType = criteriaQuery.GetTypeUsingProjection(criteria, propertyName); if (value != null && !(value is System.Type) && !propertyType.ReturnedClass.IsInstanceOfType(value)) { throw new QueryException(string.Format( "Type mismatch in {0}: {1} expected type {2}, actual type {3}", critertion.GetType(), propertyName, propertyType.ReturnedClass, value.GetType())); } if (propertyType.IsCollectionType) { throw new QueryException(string.Format( "cannot use collection property ({0}.{1}) directly in a criterion," + " use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), propertyName)); } return(Array.ConvertAll <string, SqlString>(columnNames, delegate(string col) { return new SqlString(col); })); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters) { //TODO: add default capacity SqlStringBuilder sqlBuilder = new SqlStringBuilder(); string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName); if (columnNames.Length != 1) { throw new HibernateException("insensitive like may only be used with single-column properties"); } if (criteriaQuery.Factory.Dialect is PostgreSQLDialect) { sqlBuilder.Add(columnNames[0]); sqlBuilder.Add(" ilike "); } else { sqlBuilder.Add(criteriaQuery.Factory.Dialect.LowercaseFunction) .Add("(") .Add(columnNames[0]) .Add(")") .Add(" like "); } sqlBuilder.AddParameter(); return sqlBuilder.ToSqlString(); }
private static SqlString[] GetColumnNamesUsingPropertyName( ICriteriaQuery criteriaQuery, ICriteria criteria, string propertyName, object value, ICriterion critertion) { string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); IType propertyType = criteriaQuery.GetTypeUsingProjection(criteria, propertyName); if (value != null && !(value is System.Type) && !propertyType.ReturnedClass.IsInstanceOfType(value)) { throw new QueryException(string.Format( "Type mismatch in {0}: {1} expected type {2}, actual type {3}", critertion.GetType(), propertyName, propertyType.ReturnedClass, value.GetType())); } if (propertyType.IsCollectionType) { throw new QueryException(string.Format( "cannot use collection property ({0}.{1}) directly in a criterion," + " use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), propertyName)); } return Array.ConvertAll<string, SqlString>(columnNames, delegate(string col) { return new SqlString(col); }); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters) { string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _lhsPropertyName); string[] otherColumnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _rhsPropertyName); string result = string.Join( " and ", StringHelper.Add(columnNames, Op, otherColumnNames) ); if (columnNames.Length > 1) { result = StringHelper.OpenParen + result + StringHelper.ClosedParen; } return new SqlString(result); //TODO: get SQL rendering out of this package! }
internal static object[] GetColumnNamesAsSqlStringParts(IProjection projection, ICriteriaQuery criteriaQuery, ICriteria criteria) { if (projection is IPropertyProjection propertyProjection) { return(criteriaQuery.GetColumnsUsingProjection(criteria, propertyProjection.PropertyName)); } return(GetProjectionColumns(projection, criteriaQuery, criteria)); }
internal static object[] GetColumnNamesAsSqlStringParts(string propertyName, IProjection projection, ICriteriaQuery criteriaQuery, ICriteria criteria) { if (propertyName != null) { return(criteriaQuery.GetColumnsUsingProjection(criteria, propertyName)); } return(GetColumnNamesAsSqlStringParts(projection, criteriaQuery, criteria)); }
/// <summary> /// Converts the SimpleExpression to a <see cref="SqlString"/>. /// </summary> /// <returns>A SqlString that contains a valid Sql fragment.</returns> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters) { string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName); IType propertyType = criteriaQuery.GetTypeUsingProjection(criteria, _propertyName); if (_value != null && !(_value is System.Type) && !propertyType.ReturnedClass.IsInstanceOfType(_value)) { throw new QueryException(string.Format( "Type mismatch in {0}: {1} expected type {2}, actual type {3}", GetType(), _propertyName, propertyType.ReturnedClass, _value.GetType())); } if (propertyType.IsCollectionType) { throw new QueryException(string.Format( "cannot use collection property ({0}.{1}) directly in a criterion," + " use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), _propertyName)); } if (_ignoreCase) { if (columnNames.Length != 1) { throw new HibernateException( "case insensitive expression may only be applied to single-column properties: " + _propertyName); } return new SqlStringBuilder(6) .Add(criteriaQuery.Factory.Dialect.LowercaseFunction) .Add(StringHelper.OpenParen) .Add(columnNames[0]) .Add(StringHelper.ClosedParen) .Add(Op) .AddParameter() .ToSqlString(); } else { //TODO: add default capacity SqlStringBuilder sqlBuilder = new SqlStringBuilder(4 * columnNames.Length); for (int i = 0; i < columnNames.Length; i++) { if (i > 0) { sqlBuilder.Add(" and "); } sqlBuilder.Add(columnNames[i]) .Add(Op) .AddParameter(); } return sqlBuilder.ToSqlString(); } }
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { string[] projection = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); return(new SqlStringBuilder() .Add("(") .Add(projection[0]) .Add(" + ") .AddParameter() .Add(") as ") .Add(GetColumnAliases(0)[0]) .ToSqlString()); }
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery) { string[] projection = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); return(new SqlStringBuilder() .Add("(") .Add(projection[0]) .Add(" + ") .Add(criteriaQuery.NewQueryParameter(typedValue).Single()) .Add(") as ") .Add(GetColumnAliases(0, criteria, criteriaQuery)[0]) .ToSqlString()); }
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { string[] projection = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); return new SqlStringBuilder() .Add("(") .Add(projection[0]) .Add(" + ") .AddParameter() .Add(") as ") .Add(GetColumnAliases(0)[0]) .ToSqlString(); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { //we only need this for SQL Server, and or large amount of values if ((criteriaQuery.Factory.Dialect is MsSql2005Dialect) == false || values.Length < maximumNumberOfParametersToNotUseXml) { return(expr.ToSqlString(criteria, criteriaQuery)); } //TODO: NON FUNZIONA DOPO IL REFACTOR NHIBERNATE 5 IType type = criteriaQuery.GetTypeUsingProjection(criteria, propertyName); if (type.IsCollectionType) { throw new QueryException("Cannot use collections with InExpression"); } if (values.Length == 0) { // "something in ()" is always false return(new SqlString("1=0")); } SqlStringBuilder result = new SqlStringBuilder(); string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); // Generate SqlString of the form: // columnName1 in (xml query) and columnName2 in (xml query) and ... IEnumerable <Parameter> parameters = criteriaQuery.NewQueryParameter(this.GetTypedValues(criteria, criteriaQuery).First <TypedValue>()); for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++) { string columnName = columnNames[columnIndex]; if (columnIndex > 0) { result.Add(" and "); } SqlType sqlType = type.SqlTypes(criteriaQuery.Factory)[columnIndex]; result .Add(columnName) .Add(" in (") .Add("SELECT ParamValues.Val.value('.','") .Add(criteriaQuery.Factory.Dialect.GetTypeName(sqlType)) .Add("') FROM ") .Add(parameters.ElementAt(columnIndex)) .Add(".nodes('/items/val') as ParamValues(Val)") .Add(")"); } return(result.ToSqlString()); }
/// <summary> /// Gets the column names. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="criteriaQuery">The criteria query.</param> /// <param name="propertyName">Name of the property.</param> /// <returns></returns> private string[] GetColumnNames(ICriteria criteria, ICriteriaQuery criteriaQuery, string propertyName) { string[] columns = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); IType type = criteriaQuery.GetTypeUsingProjection(criteria, propertyName); if (!typeof(IGeometry).IsAssignableFrom(type.ReturnedClass)) { throw new QueryException(string.Format("Type mismatch in {0}: {1} expected type {2}, actual type {3}", base.GetType(), propertyName, typeof(IGeometry), type.ReturnedClass)); } if (type.IsCollectionType) { throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), propertyName)); } return(columns); }
public override SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { SqlStringBuilder s = new SqlStringBuilder(); string[] cols = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); for (int i = 0; i < cols.Length; i++) { s.Add(cols[i]); s.Add(" as y"); s.Add((loc + i).ToString()); s.Add("_"); if (i < cols.Length - 1) s.Add(", "); } return s.ToSqlString(); }
/// <summary> /// Return sql string /// </summary> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { // we only need this for SQL Server, and or large amount of values if ((criteriaQuery.Factory.Dialect is MsSql2005Dialect) == false || _values.Length < _maxParametersToNotUseXml) { return(_expr.ToSqlString(criteria, criteriaQuery, enabledFilters)); } var type = criteriaQuery.GetTypeUsingProjection(criteria, _propertyName); if (type.IsCollectionType) { throw new QueryException("Cannot use collections with InExpression"); } if (_values.Length == 0) { return(new SqlString("1=0")); // " somthing in ()" is always false } var result = new SqlStringBuilder(); var columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName); // Generate SqlString of the form: // columnName1 in (xml query) and columnName2 in (xml query) and ... for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++) { string columnName = columnNames[columnIndex]; if (columnIndex > 0) { result.Add(" and "); } var sqlType = type.SqlTypes(criteriaQuery.Factory)[columnIndex]; result .Add(columnName) .Add(" in (") .Add("SELECT ParamValues.Val.value('.','") .Add(criteriaQuery.Factory.Dialect.GetTypeName(sqlType)) .Add("') FROM ") .AddParameter() .Add(".nodes('/items/val') as ParamValues(Val)") .Add(")"); } return(result.ToSqlString()); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters) { IType type = criteriaQuery.GetTypeUsingProjection(criteria, _propertyName); if (type.IsCollectionType) { throw new QueryException("Cannot use collections with InExpression"); } if (_values.Length == 0) { // "something in ()" is always false return new SqlString("1=0"); } //TODO: add default capacity SqlStringBuilder result = new SqlStringBuilder(); string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName); // Generate SqlString of the form: // columnName1 in (values) and columnName2 in (values) and ... for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++) { string columnName = columnNames[columnIndex]; if (columnIndex > 0) { result.Add(" and "); } result .Add(columnName) .Add(" in ("); for (int i = 0; i < _values.Length; i++) { if (i > 0) { result.Add(StringHelper.CommaSpace); } result.AddParameter(); } result.Add(")"); } return result.ToSqlString(); }
/// <summary> /// Get the names of the columns constrained by this criterion. /// </summary> public string[] GetColumnsUsingProjection(ICriteria subcriteria, string propertyName) { // NH Different behavior: we don't use the projection alias for NH-1023 if (TryGetColumns(subcriteria, propertyName, outerQueryTranslator != null, out var columns)) { return(columns); } //not found in inner query , try the outer query if (outerQueryTranslator != null) { return(outerQueryTranslator.GetColumnsUsingProjection(subcriteria, propertyName)); } throw new QueryException("Could not find property " + propertyName); }
/// <summary> /// Render a SqlString for the expression. /// </summary> /// <param name="criteria"></param> /// <param name="criteriaQuery"></param> /// <param name="enabledFilters"></param> /// <returns> /// A SqlString that contains a valid Sql fragment. /// </returns> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { IEnumerable <Parameter> parameters = criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)); Parameter p = null; foreach (Parameter p_ in parameters) { p = p_; } //Parameter[] p = criteriaQuery.NewQueryParameter(GetTypedValues(criteria, criteriaQuery)[0]).ToArray(); ISpatialDialect spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect; string[] columnsUsingProjection = criteriaQuery.GetColumnsUsingProjection(criteria, this.propertyName); IType typeUsingProjection = criteriaQuery.GetTypeUsingProjection(criteria, this.propertyName); if (typeUsingProjection.IsCollectionType) { throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), this.propertyName)); } string[] keyColumns = criteriaQuery.GetIdentifierColumns(criteria); string entityType = criteriaQuery.GetEntityName(criteria, this.propertyName); AbstractEntityPersister entityPersister = (AbstractEntityPersister)criteriaQuery.Factory.GetEntityPersister(entityType); // Only one key column is assumed string keyColumn = keyColumns[0]; string alias = criteriaQuery.GetSQLAlias(criteria, this.propertyName); string tableName = entityPersister.TableName; int aliasLength = alias.Length + 1; SqlStringBuilder builder = new SqlStringBuilder(10 * columnsUsingProjection.Length); for (int i = 0; i < columnsUsingProjection.Length; i++) { if (i > 0) { builder.Add(" AND "); } string geometryColumn = columnsUsingProjection[i].Remove(0, aliasLength); builder.Add(spatialDialect.GetSpatialFilterString(alias, geometryColumn, keyColumn, tableName, p)); } return(builder.ToSqlString()); }
public override SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery) { SqlStringBuilder s = new SqlStringBuilder(); string[] cols = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); for (int i = 0; i < cols.Length; i++) { s.Add(cols[i]); s.Add(" as y"); s.Add((loc + i).ToString()); s.Add("_"); if (i < cols.Length - 1) { s.Add(", "); } } return(s.ToSqlString()); }
/// <summary> /// Get the names of the columns constrained by this criterion. /// </summary> public string[] GetColumnsUsingProjection(ICriteria subcriteria, string propertyName) { // NH Different behavior: we don't use the projection alias for NH-1023 try { return(GetColumns(subcriteria, propertyName)); } catch (HibernateException) { //not found in inner query , try the outer query if (outerQueryTranslator != null) { return(outerQueryTranslator.GetColumnsUsingProjection(subcriteria, propertyName)); } else { throw; } } }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { string[] columns = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); if (columns.Length != 1) throw new HibernateException("Like may only be used with single-column properties"); SqlStringBuilder lhs = new SqlStringBuilder(6); if(ignoreCase) { Dialect.Dialect dialect = criteriaQuery.Factory.Dialect; lhs.Add(dialect.LowercaseFunction).Add(StringHelper.OpenParen).Add(columns[0]).Add( StringHelper.ClosedParen); } else lhs.Add(columns[0]); lhs.Add(" like ").AddParameter(); if (escapeChar.HasValue) lhs.Add(" escape '" + escapeChar + "'"); return lhs.ToSqlString(); }
/// <summary> /// Gets the column names. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="criteriaQuery">The criteria query.</param> /// <param name="propertyName">Name of the property.</param> /// <returns></returns> private string[] GetColumnNames(ICriteria criteria, ICriteriaQuery criteriaQuery, string propertyName) { string[] columns = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); IType type = criteriaQuery.GetTypeUsingProjection(criteria, propertyName); if (type.ReturnedClass != typeof(IGeometry)) { throw new QueryException(string.Format("Type mismatch in {0}: {1} expected type {2}, actual type {3}", base.GetType(), propertyName, typeof(IGeometry), type.ReturnedClass)); } if (type.IsCollectionType) { throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), propertyName)); } return columns; }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string,IFilter> enabledFilters) { //we only need this for SQL Server, and or large amount of values if ((criteriaQuery.Factory.Dialect is MsSql2005Dialect) == false || values.Length < maximumNumberOfParametersToNotUseXml) { return expr.ToSqlString(criteria, criteriaQuery, enabledFilters); } IType type = criteriaQuery.GetTypeUsingProjection(criteria, propertyName); if (type.IsCollectionType) { throw new QueryException("Cannot use collections with InExpression"); } if (values.Length == 0) { // "something in ()" is always false return new SqlString("1=0"); } SqlStringBuilder result = new SqlStringBuilder(); string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); // Generate SqlString of the form: // columnName1 in (xml query) and columnName2 in (xml query) and ... criteriaQuery.AddUsedTypedValues(this.GetTypedValues(criteria, criteriaQuery)); for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++) { string columnName = columnNames[columnIndex]; if (columnIndex > 0) { result.Add(" and "); } SqlType sqlType = type.SqlTypes(criteriaQuery.Factory)[columnIndex]; result .Add(columnName) .Add(" in (") .Add("SELECT ParamValues.Val.value('.','") .Add(criteriaQuery.Factory.Dialect.GetTypeName(sqlType)) .Add("') FROM ") .AddParameter() .Add(".nodes('/items/val') as ParamValues(Val)") .Add(")"); } return result.ToSqlString(); }
private static SqlString[] GetColumnNamesUsingPropertyName(ICriteriaQuery criteriaQuery, ICriteria criteria, string propertyName) { string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); return(Array.ConvertAll <string, SqlString>(columnNames, delegate(string input) { return new SqlString(input); })); }
/// <summary> /// Render a SqlString for the expression. /// </summary> /// <param name="criteria"></param> /// <param name="criteriaQuery"></param> /// <param name="enabledFilters"></param> /// <returns> /// A SqlString that contains a valid Sql fragment. /// </returns> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { //criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); ISpatialDialect spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect; string[] columnsUsingProjection = criteriaQuery.GetColumnsUsingProjection(criteria, this.propertyName); IType typeUsingProjection = criteriaQuery.GetTypeUsingProjection(criteria, this.propertyName); if (typeUsingProjection.IsCollectionType) { throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), this.propertyName)); } string[] keyColumns = criteriaQuery.GetIdentifierColumns(criteria); string entityType = criteriaQuery.GetEntityName(criteria, this.propertyName); AbstractEntityPersister entityPersister = (AbstractEntityPersister)criteriaQuery.Factory.GetEntityPersister(entityType); // Only one key column is assumed string keyColumn = keyColumns[0]; string alias = criteriaQuery.GetSQLAlias(criteria, this.propertyName); string tableName = entityPersister.TableName; int aliasLength = alias.Length + 1; SqlStringBuilder builder = new SqlStringBuilder(10 * columnsUsingProjection.Length); for (int i = 0; i < columnsUsingProjection.Length; i++) { if (i > 0) { builder.Add(" AND "); } string geometryColumn = columnsUsingProjection[i].Remove(0, aliasLength); builder.Add(spatialDialect.GetSpatialFilterString(alias, geometryColumn, keyColumn, tableName)); } return builder.ToSqlString(); }
private static SqlString[] GetColumnNamesUsingPropertyName(ICriteriaQuery criteriaQuery, ICriteria criteria, string propertyName) { string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); return Array.ConvertAll<string, SqlString>(columnNames, delegate(string input) { return new SqlString(input); }); }