/// <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();
		}
        /// <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[] columns1 = GetColumnNames(criteria, criteriaQuery, this.propertyName);
            string[] columns2 = null;
            if (!(this.anotherGeometry is IGeometry))
            {
                columns2 = GetColumnNames(criteria, criteriaQuery, (string)this.anotherGeometry);
            }

            SqlStringBuilder builder = new SqlStringBuilder(10 * columns1.Length);

            for (int i = 0; i < columns1.Length; i++)
            {
                if (i > 0)
                {
                    builder.Add(" AND ");
                }
                if (this.anotherGeometry is IGeometry)
                {
                    builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, Parameter.Placeholder, true));
                }
                else
                {
                    builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, columns2[i], true));
                }
            }
            return(builder.ToSqlString());
        }
		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
		                                      IDictionary<string, IFilter> enabledFilters)
		{
			//TODO: add default capacity
			SqlStringBuilder sqlBuilder = new SqlStringBuilder();
			SqlString[] columnNames =
				CriterionUtil.GetColumnNames(propertyName, projection, criteriaQuery, criteria, enabledFilters);

			criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria,criteriaQuery));
			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();
		}
Пример #4
0
        /// <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());
        }
Пример #5
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
                                              IDictionary <string, IFilter> enabledFilters)
        {
            //TODO: add default capacity
            SqlStringBuilder sqlBuilder = new SqlStringBuilder();

            SqlString[] columnNames =
                CriterionUtil.GetColumnNames(propertyName, projection, criteriaQuery, criteria, enabledFilters);

            criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
            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());
        }
		/// <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[] columns1 = GetColumnNames(criteria, criteriaQuery, this.propertyName);
			string[] columns2 = null;
			if (!(this.anotherGeometry is IGeometry))
			{
				columns2 = GetColumnNames(criteria, criteriaQuery, (string)this.anotherGeometry);
			}

			SqlStringBuilder builder = new SqlStringBuilder(10 * columns1.Length);
			for (int i = 0; i < columns1.Length; i++)
			{
				if (i > 0)
				{
					builder.Add(" AND ");
				}
				if (this.anotherGeometry is IGeometry)
				{
					builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, Parameter.Placeholder, true));
				}
				else
				{
					builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, columns2[i], true));
				}
			}
			return builder.ToSqlString();
		}
		public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			criteriaQuery.AddUsedTypedValues(new TypedValue[] { new TypedValue(type, value, EntityMode.Poco) });
			return new SqlStringBuilder()
				.AddParameter()
				.Add(" as ")
				.Add(GetColumnAliases(position)[0])
				.ToSqlString();
		}
Пример #8
0
 public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
 {
     criteriaQuery.AddUsedTypedValues(new TypedValue[] { new TypedValue(type, value, EntityMode.Poco) });
     return(new SqlStringBuilder()
            .AddParameter()
            .Add(" as ")
            .Add(GetColumnAliases(position)[0])
            .ToSqlString());
 }
Пример #9
0
 public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
 {
     string[] projection = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName);
     criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
     return(new SqlStringBuilder()
            .Add("(")
            .Add(projection[0])
            .Add(" + ")
            .AddParameter()
            .Add(") as ")
            .Add(GetColumnAliases(0)[0])
            .ToSqlString());
 }
Пример #10
0
		public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			string[] projection = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName);
			criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
			return new SqlStringBuilder()
				.Add("(")
				.Add(projection[0])
				.Add(" + ")
				.AddParameter()
				.Add(") as ")
				.Add(GetColumnAliases(0)[0])
				.ToSqlString();
		}
Пример #11
0
 private void AddValueOrProjection(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters, SqlStringBuilder result)
 {
     if (_projection == null)
     {
         criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
         result.AddParameter();
     }
     else
     {
         SqlString sql = _projection.ToSqlString(criteria, GetHashCode(), criteriaQuery, enabledFilters);
         result.Add(StringHelper.RemoveAsAliasesFromSql(sql));
     }
 }
		private void AddValueOrProjection(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters, SqlStringBuilder result)
		{
			if (_projection == null)
			{
				criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria,criteriaQuery));
				result.AddParameter();
			}
			else
			{
				SqlString sql = _projection.ToSqlString(criteria, GetHashCode(),criteriaQuery, enabledFilters);
				result.Add(StringHelper.RemoveAsAliasesFromSql(sql));
			}
		}
Пример #13
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
                                              IDictionary <string, IFilter> enabledFilters)
        {
            if (_projection == null)
            {
                AssertPropertyIsNotCollection(criteriaQuery, criteria);
            }

            if (_values.Length == 0)
            {
                // "something in ()" is always false
                return(new SqlString("1=0"));
            }

            //TODO: add default capacity
            SqlStringBuilder result = new SqlStringBuilder();

            SqlString[] columnNames =
                CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);

            // Generate SqlString of the form:
            // columnName1 in (values) and columnName2 in (values) and ...

            criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
            for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++)
            {
                SqlString 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());
        }
Пример #14
0
 public void AddUsedTypedValues(TypedValue[] values)
 {
     if (values != null)
     {
         if (outerQueryTranslator != null)
         {
             outerQueryTranslator.AddUsedTypedValues(values);
         }
         else
         {
             usedTypedValues.AddRange(values);
         }
     }
 }
Пример #15
0
        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());
        }
Пример #16
0
		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
		                                      IDictionary<string, IFilter> enabledFilters)
		{
			if (_projection == null)
			{
				AssertPropertyIsNotCollection(criteriaQuery, criteria);
			}

			if (_values.Length == 0)
			{
				// "something in ()" is always false
				return new SqlString("1=0");
			}

			//TODO: add default capacity
			SqlStringBuilder result = new SqlStringBuilder();
			SqlString[] columnNames =
				CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);
			
			// Generate SqlString of the form:
			// columnName1 in (values) and columnName2 in (values) and ...

			criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
			for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++)
			{
				SqlString 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();
		}
Пример #17
0
		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
		                                      IDictionary<string, IFilter> enabledFilters)
		{
			//TODO: add a default capacity
			SqlStringBuilder sqlBuilder = new SqlStringBuilder();

			//IType propertyType = criteriaQuery.GetTypeUsingProjection( criteria, _propertyName );
			SqlString[] columnNames =
				CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);

			criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
			if (columnNames.Length == 1)
			{
				sqlBuilder
					.Add(columnNames[0])
					.Add(" between ")
					.AddParameter()
					.Add(" and ")
					.AddParameter();
			}
			else
			{
				bool andNeeded = false;

				for (int i = 0; i < columnNames.Length; i++)
				{
					if (andNeeded)
					{
						sqlBuilder.Add(" AND ");
					}
					andNeeded = true;

					sqlBuilder.Add(columnNames[i])
						.Add(" >= ")
						.AddParameter();
				}

				for (int i = 0; i < columnNames.Length; i++)
				{
					sqlBuilder.Add(" AND ")
						.Add(columnNames[i])
						.Add(" <= ")
						.AddParameter();
				}
			}

			return sqlBuilder.ToSqlString();
		}
Пример #18
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
                                              IDictionary <string, IFilter> enabledFilters)
        {
            //TODO: add a default capacity
            SqlStringBuilder sqlBuilder = new SqlStringBuilder();

            //IType propertyType = criteriaQuery.GetTypeUsingProjection( criteria, _propertyName );
            SqlString[] columnNames =
                CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);

            criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
            if (columnNames.Length == 1)
            {
                sqlBuilder
                .Add(columnNames[0])
                .Add(" between ")
                .AddParameter()
                .Add(" and ")
                .AddParameter();
            }
            else
            {
                bool andNeeded = false;

                for (int i = 0; i < columnNames.Length; i++)
                {
                    if (andNeeded)
                    {
                        sqlBuilder.Add(" AND ");
                    }
                    andNeeded = true;

                    sqlBuilder.Add(columnNames[i])
                    .Add(" >= ")
                    .AddParameter();
                }

                for (int i = 0; i < columnNames.Length; i++)
                {
                    sqlBuilder.Add(" AND ")
                    .Add(columnNames[i])
                    .Add(" <= ")
                    .AddParameter();
                }
            }

            return(sqlBuilder.ToSqlString());
        }
Пример #19
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            SqlString[] columns = CriterionUtil.GetColumnNamesUsingProjection(projection, criteriaQuery, criteria, enabledFilters);
            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)
                .Add(columns[0])
                .Add(StringHelper.ClosedParen);
            }
            else
            {
                lhs.Add(columns[0]);
            }

            criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));

            if (ignoreCase)
            {
                Dialect.Dialect dialect = criteriaQuery.Factory.Dialect;
                lhs.Add(" like ")
                .Add(dialect.LowercaseFunction)
                .Add(StringHelper.OpenParen)
                .AddParameter()
                .Add(StringHelper.ClosedParen);
            }
            else
            {
                lhs.Add(" like ").AddParameter();
            }

            if (escapeChar.HasValue)
            {
                lhs.Add(" escape '" + escapeChar + "'");
            }
            return(lhs.ToSqlString());
        }
		/// <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<string, IFilter> enabledFilters)
		{
			SqlString[] columnNames =
				CriterionUtil.GetColumnNamesForSimpleExpression(propertyName, _projection, criteriaQuery, criteria, enabledFilters,
				                                                 this, value);

			criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
			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
			{
				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();
			}
		}
Пример #21
0
        /// <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 <string, IFilter> enabledFilters)
        {
            SqlString[] columnNames =
                CriterionUtil.GetColumnNamesForSimpleExpression(propertyName, _projection, criteriaQuery, criteria, enabledFilters,
                                                                this, value);

            criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
            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
            {
                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());
            }
        }
Пример #22
0
        /// <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());
        }
Пример #23
0
		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			SqlString[] columns = CriterionUtil.GetColumnNamesUsingProjection(projection, criteriaQuery, criteria, enabledFilters);
			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)
					.Add(columns[0])
					.Add(StringHelper.ClosedParen);
			}
			else
				lhs.Add(columns[0]);

			criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));

			if (ignoreCase)
			{
				Dialect.Dialect dialect = criteriaQuery.Factory.Dialect;
				lhs.Add(" like ")
					.Add(dialect.LowercaseFunction)
					.Add(StringHelper.OpenParen)
					.AddParameter()
					.Add(StringHelper.ClosedParen);
			}
			else
				lhs.Add(" like ").AddParameter();

			if (escapeChar.HasValue)
				lhs.Add(" escape '" + escapeChar + "'");
			return lhs.ToSqlString();
		}
Пример #24
0
 protected override SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
 {
     criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
     return(SqlString.Parameter);
 }
Пример #25
0
		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
			return _sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria));
		}
Пример #26
0
 public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
 {
     criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
     return(_sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria)));
 }
Пример #27
0
		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();
		}
		protected override SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
		{
			criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
			return SqlString.Parameter;
		}
Пример #29
0
		/// <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();
		}