public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
        {
            var sqlBuilder = new SqlStringBuilder();
            SqlString[] columnNames = null;

            if (_propertyName != "*")
            {
                columnNames = CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);

                if (columnNames.Length != 1)
                {
                    throw new HibernateException("Contains may only be used with single-column properties");
                }
            } else
            {
                columnNames = new SqlString[]
                                  {
                                      new SqlString("*")
                                  };
            }

            sqlBuilder.Add("contains(")
              .Add(columnNames[0])
              .Add(",");

            sqlBuilder.Add(criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).Single());
            sqlBuilder.Add(")");

            return sqlBuilder.ToSqlString();
        }
 public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
 {
     return new SqlStringBuilder()
         .Add(string.Format(" CASE WHEN {0} LIKE ", PropertyName))
         .Add(criteriaQuery.NewQueryParameter(new TypedValue(NHibernateUtil.String, string.Format("{0}%", SearchValue), EntityMode.Poco)).Single())
         .Add(string.Format(" THEN 0 WHEN {0} LIKE ", PropertyName))
         .Add(criteriaQuery.NewQueryParameter(new TypedValue(NHibernateUtil.String, string.Format("% %{0}% %", SearchValue), EntityMode.Poco)).Single())
         .Add(string.Format(" THEN 1 WHEN {0} LIKE ", PropertyName))
         .Add(criteriaQuery.NewQueryParameter(new TypedValue(NHibernateUtil.String, string.Format("%{0}", SearchValue), EntityMode.Poco)).Single())
         .Add(" THEN 2 ELSE 3 END ")
         .Add(" as ")
         .Add(GetColumnAliases(position)[0])
         .ToSqlString();
 }
Пример #3
0
		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			//TODO: add a default capacity
			SqlStringBuilder sqlBuilder = new SqlStringBuilder();

			var parametersTypes = GetTypedValues(criteria, criteriaQuery).ToArray();
			var lowType = parametersTypes[0];
			var highType = parametersTypes[1];
			SqlString[] columnNames =
				CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);

			if (columnNames.Length == 1)
			{
				sqlBuilder
					.Add(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.Add(columnNames[i])
						.Add(" >= ")
						.Add(lowParameters[i]);
				}

				var highParameters = criteriaQuery.NewQueryParameter(highType).ToArray();
				for (int i = 0; i < columnNames.Length; i++)
				{
					sqlBuilder.Add(" AND ")
						.Add(columnNames[i])
						.Add(" <= ")
						.Add(highParameters[i]);
				}
			}

			return sqlBuilder.ToSqlString();
		}
		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			//Implementation changed from H3.2 to use SqlString
			string[] columns = criteriaQuery.GetIdentifierColumns(criteria);
			Parameter[] parameters = GetTypedValues(criteria, criteriaQuery).SelectMany(t => criteriaQuery.NewQueryParameter(t)).ToArray();

			SqlStringBuilder result = new SqlStringBuilder(4 * columns.Length + 2);
			if (columns.Length > 1)
			{
				result.Add(StringHelper.OpenParen);
			}

			for (int i = 0; i < columns.Length; i++)
			{
				if (i > 0)
				{
					result.Add(" and ");
				}

				result.Add(columns[i])
					.Add(" = ");

				AddValueOrProjection(parameters, i, criteria, criteriaQuery, enabledFilters, result);
			}

			if (columns.Length > 1)
			{
				result.Add(StringHelper.ClosedParen);
			}
			return result.ToSqlString();
		}
Пример #5
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            if (_projection == null)
            {
                AssertPropertyIsNotCollection(criteriaQuery, criteria);
            }

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

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

            var list = new List <Parameter>(columns.Length * Values.Length);

            foreach (var typedValue in GetParameterTypedValues(criteria, criteriaQuery))
            {
                //Must be executed after CriterionUtil.GetColumnNames (as it might add _projection parameters to criteria)
                list.AddRange(criteriaQuery.NewQueryParameter(typedValue));
            }

            var bogusParam = Parameter.Placeholder;

            var sqlString = GetSqlString(criteriaQuery, columns, bogusParam);

            sqlString.SubstituteBogusParameters(list, bogusParam);
            return(sqlString);
        }
		public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			return new SqlString(
				criteriaQuery.NewQueryParameter(typedValue).Single(),
				" as ",
				GetColumnAliases(position, criteria, criteriaQuery)[0]);
		}
Пример #7
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);

            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.Add(criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).Single());

            return(sqlBuilder.ToSqlString());
        }
Пример #8
0
        /// <summary>
        /// Render the SQL Fragment.
        /// </summary>
        /// <param name="criteria"></param>
        /// <param name="position"></param>
        /// <param name="criteriaQuery"></param>
        /// <returns></returns>
        public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery)
        {
            var       spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect;
            string    column1        = criteriaQuery.GetColumn(criteria, this.propertyName);
            SqlString sqlString;

            if (IsBinaryOperation())
            {
                if (geometry != null)
                {
                    Parameter[] parameters = criteriaQuery.NewQueryParameter(this.GetTypedValues(criteria, criteriaQuery)[0]).ToArray();
                    sqlString = spatialDialect.GetSpatialAnalysisString(column1, this.analysis, parameters.Single());
                }
                else
                {
                    string column2 = criteriaQuery.GetColumn(criteria, this.anotherPropertyName);
                    sqlString = spatialDialect.GetSpatialAnalysisString(column1, this.analysis, column2);
                }
            }
            else
            {
                sqlString = spatialDialect.GetSpatialAnalysisString(column1, this.analysis, null);
            }

            return(new SqlStringBuilder()
                   .Add(sqlString)
                   .Add(" as y")
                   .Add(position.ToString())
                   .Add("_")
                   .ToSqlString());
        }
Пример #9
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            var sqlBuilder = new SqlStringBuilder();

            SqlString[] columnNames = null;

            if (!_propertyName.Contains("*"))
            {
                columnNames = CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);

                if (columnNames.Length != 1)
                {
                    throw new HibernateException("Contains may only be used with single-column properties");
                }
            }
            else
            {
                columnNames = new SqlString[]
                {
                    new SqlString("*")
                };
            }

            sqlBuilder.Add("freetext(")
            .Add(columnNames[0])
            .Add(",");

            sqlBuilder.Add(criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).Single());
            sqlBuilder.Add(")");

            return(sqlBuilder.ToSqlString());
        }
Пример #10
0
 public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery)
 {
     return(new SqlString(
                criteriaQuery.NewQueryParameter(TypedValue).Single(),
                " as ",
                GetColumnAliases(position, criteria, criteriaQuery)[0]));
 }
Пример #11
0
 public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
 {
     return(new SqlStringBuilder()
            .Add(criteriaQuery.NewQueryParameter(typedValue).Single())
            .Add(" as ")
            .Add(GetColumnAliases(position)[0])
            .ToSqlString());
 }
Пример #12
0
		public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			return new SqlStringBuilder()
				.Add(criteriaQuery.NewQueryParameter(typedValue).Single())
				.Add(" as ")
				.Add(GetColumnAliases(position)[0])
				.ToSqlString();
		}
Пример #13
0
        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());
        }
        public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
        {
            var loc = position * GetHashCode();
            var val = _projection.ToSqlString(criteria, loc, criteriaQuery, enabledFilters);
            val = HierarchyIdStringHelper.RemoveAsAliasesFromSql(val);

            var lhs = new SqlStringBuilder();

            lhs.Add(val);
            lhs.Add(".GetReparentedValue(");
            lhs.Add(criteriaQuery.NewQueryParameter(new TypedValue(NHibernateUtil.String, _oldRoot, EntityMode.Poco)).Single());
            lhs.Add(" , ");
            lhs.Add(criteriaQuery.NewQueryParameter(new TypedValue(NHibernateUtil.String, _newRoot, EntityMode.Poco)).Single());
            lhs.Add(") as ");
            lhs.Add(GetColumnAliases(position)[0]);

            var ret =  lhs.ToSqlString();

            return ret;
        }
Пример #15
0
 public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
 {
     if (_parameter == null)
     {
         _parameter = criteriaQuery.NewQueryParameter(_typedValue).Single();
     }
     return(new SqlString(
                _parameter,
                " as ",
                GetColumnAliases(position, criteria, criteriaQuery)[0]));
 }
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
        {
            var columnName = Projection.GetColumnName(criteria, criteriaQuery, enabledFilters);
            var parameter = criteriaQuery.NewQueryParameter(GetParameterTypedValue()).Single();

            return new SqlStringBuilder(3)
                .Add(columnName)
                .Add(Operation)
                .Add(parameter)
                .ToSqlString();
        }
Пример #17
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            var columnName = Projection.GetColumnName(criteria, criteriaQuery, enabledFilters);
            var parameter  = criteriaQuery.NewQueryParameter(GetParameterTypedValue()).Single();

            return(new SqlStringBuilder(3)
                   .Add(columnName)
                   .Add(Operation)
                   .Add(parameter)
                   .ToSqlString());
        }
Пример #18
0
        public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery)
        {
            var loc = position * GetHashCode();
            var val = _projection.ToSqlString(criteria, loc, criteriaQuery);

            val = GetAncestorProjection.RemoveAsAliasesFromSql(val);

            var lhs = new SqlStringBuilder();

            lhs.Add(val);
            lhs.Add(".GetReparentedValue(");
            lhs.Add(criteriaQuery.NewQueryParameter(new TypedValue(NHibernateUtil.String, _oldRoot, false)).Single());
            lhs.Add(" , ");
            lhs.Add(criteriaQuery.NewQueryParameter(new TypedValue(NHibernateUtil.String, _newRoot, false)).Single());
            lhs.Add(") as ");
            lhs.Add(GetColumnAliases(position)[0]);

            var ret = lhs.ToSqlString();

            return(ret);
        }
Пример #19
0
        public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            var loc = position * GetHashCode();
            var val = _projection.ToSqlString(criteria, loc, criteriaQuery, enabledFilters);

            val = HierarchyIdStringHelper.RemoveAsAliasesFromSql(val);

            var lhs = new SqlStringBuilder();

            lhs.Add(val);
            lhs.Add(".GetDescendant(");
            lhs.Add(criteriaQuery.NewQueryParameter(new TypedValue(NHibernateUtil.String, _child1, EntityMode.Poco)).Single());
            lhs.Add(" , ");
            lhs.Add(criteriaQuery.NewQueryParameter(new TypedValue(NHibernateUtil.String, _child2, EntityMode.Poco)).Single());
            lhs.Add(") as ");
            lhs.Add(GetColumnAliases(position)[0]);

            var ret = lhs.ToSqlString();

            return(ret);
        }
Пример #20
0
        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(" + ")
                   .Add(criteriaQuery.NewQueryParameter(typedValue).Single())
                   .Add(") as ")
                   .Add(GetColumnAliases(0)[0])
                   .ToSqlString());
        }
Пример #21
0
		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(" + ")
				.Add(criteriaQuery.NewQueryParameter(typedValue).Single())
				.Add(") as ")
				.Add(GetColumnAliases(0, criteria, criteriaQuery)[0])
				.ToSqlString();
		}
Пример #22
0
        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());
        }
Пример #23
0
		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			var parameters = _sql.GetParameters().ToList();
			var paramPos = 0;
			for (int i = 0; i < _typedValues.Length; i++)
			{
				var controlledParameters = criteriaQuery.NewQueryParameter(_typedValues[i]);
				foreach (Parameter parameter in controlledParameters)
				{
					parameters[paramPos++].BackTrack = parameter.BackTrack;
				}
			}
			return _sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria));
		}
Пример #24
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);

            Parameter[] parameters = criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).ToArray();

            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)
                       .Add(parameters.Single())
                       .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)
                    .Add(parameters[i]);
                }
                return(sqlBuilder.ToSqlString());
            }
        }
Пример #25
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 ...
			Parameter[] parameters = GetTypedValues(criteria, criteriaQuery).SelectMany(t => criteriaQuery.NewQueryParameter(t)).ToArray();

			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.Add(parameters[i]);
				}

				result.Add(")");
			}

			return result.ToSqlString();
		}
Пример #26
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            var parameters = _sql.GetParameters().ToList();
            var paramPos   = 0;

            for (int i = 0; i < _typedValues.Length; i++)
            {
                var controlledParameters = criteriaQuery.NewQueryParameter(_typedValues[i]);
                foreach (Parameter parameter in controlledParameters)
                {
                    parameters[paramPos++].BackTrack = parameter.BackTrack;
                }
            }
            return(criteriaQuery.RenderSQLAliases(_sql).Replace("{alias}", criteriaQuery.GetSQLAlias(criteria)));
        }
Пример #27
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)
        {
            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());
        }
Пример #28
0
        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,
                                              IDictionary<string, IFilter> enabledFilters)
        {
            var columns = CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria,
                                                       enabledFilters);
            if (columns.Length != 1)
                throw new HibernateException(
                    "IsDescendantOf may only be used with single-column properties / projections.");

            var lhs = new SqlStringBuilder(6);

            lhs.Add(columns[0]);
            lhs.Add(".IsDescendantOf(");
            lhs.Add(criteriaQuery.NewQueryParameter(_typedValue).Single());
            lhs.Add(") = 1");

            return lhs.ToSqlString();
        }
Пример #30
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            var columns = CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria);

            if (columns.Length != 1)
            {
                throw new HibernateException(
                          "IsDescendantOf may only be used with single-column properties / projections.");
            }

            var lhs = new SqlStringBuilder(6);

            lhs.Add(columns[0]);
            lhs.Add(".IsDescendantOf(");
            lhs.Add(criteriaQuery.NewQueryParameter(_typedValue).Single());
            lhs.Add(") = 1");

            return(lhs.ToSqlString());
        }
Пример #31
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            var columnNames = GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, this, _value);

            var typedValue = GetParameterTypedValue(criteria, criteriaQuery);
            var parameters = criteriaQuery.NewQueryParameter(typedValue).ToArray();

            var sqlBuilder     = new SqlStringBuilder(4 * columnNames.Length);
            var columnNullness = typedValue.Type.ToColumnNullness(typedValue.Value, criteriaQuery.Factory);

            if (columnNullness.Length != columnNames.Length)
            {
                throw new AssertionFailure("Column nullness length doesn't match number of columns.");
            }

            for (int i = 0; i < columnNames.Length; i++)
            {
                if (i > 0)
                {
                    sqlBuilder.Add(" and ");
                }

                if (columnNullness[i])
                {
                    if (_inverse)
                    {
                        sqlBuilder.Add(parameters[i]).Add(Op).Add(columnNames[i]);
                    }
                    else
                    {
                        sqlBuilder.Add(columnNames[i]).Add(Op).Add(parameters[i]);
                    }
                }
                else
                {
                    sqlBuilder.Add(columnNames[i]).Add(" is null ");
                }
            }

            return(sqlBuilder.ToSqlString());
        }
Пример #32
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            var columnNames = CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria);
            var dialect     = criteriaQuery.Factory.Dialect;

            if (columnNames.Length != 1)
            {
                throw new HibernateException("accent insensitive like may only be used with single-column properties");
            }

            var parameter = criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).Single();

            if (dialect is Oracle8iDialect)
            {
                return(GenerateOracleExpression(columnNames[0], dialect, parameter).ToSqlString());
            }

            if (dialect is MsSql2000Dialect)
            {
                return(GenerateMsSqlExpression(columnNames[0], parameter).ToSqlString());
            }

            throw new NotSupportedException();
        }
		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);

			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.Add(criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).Single());

			return sqlBuilder.ToSqlString();
		}
		protected override SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
		{
			return new SqlString(criteriaQuery.NewQueryParameter(FirstTypedValue()).First());
		}
        /// <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);

            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)
                {
                    Parameter[] parameters = criteriaQuery.NewQueryParameter(this.GetTypedValues(criteria, criteriaQuery)[0]).ToArray();
                    builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, parameters.Single(), true));
                }
                else
                {
                    string[] columns2 = GetColumnNames(criteria, criteriaQuery, (string)this.anotherGeometry);
                    builder.Add(spatialDialect.GetSpatialRelationString(columns1[i], this.relation, columns2[i], true));
                }
            }
            return builder.ToSqlString();
        }
Пример #36
0
 protected override SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
 {
     return(new SqlString(criteriaQuery.NewQueryParameter(FirstTypedValue()).First()));
 }
Пример #37
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            //Implementation changed from H3.2 to use SqlString
            string[]    columns    = criteriaQuery.GetIdentifierColumns(criteria);
            Parameter[] parameters = GetTypedValues(criteria, criteriaQuery).SelectMany(t => criteriaQuery.NewQueryParameter(t)).ToArray();

            SqlStringBuilder result = new SqlStringBuilder(4 * columns.Length + 2);

            if (columns.Length > 1)
            {
                result.Add(StringHelper.OpenParen);
            }

            for (int i = 0; i < columns.Length; i++)
            {
                if (i > 0)
                {
                    result.Add(" and ");
                }

                result.Add(columns[i])
                .Add(" = ");

                AddValueOrProjection(parameters, i, criteria, criteriaQuery, result);
            }

            if (columns.Length > 1)
            {
                result.Add(StringHelper.ClosedParen);
            }
            return(result.ToSqlString());
        }
Пример #38
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);

            TypedValue typedValue = GetParameterTypedValue(criteria, criteriaQuery);

            Parameter[] parameters = criteriaQuery.NewQueryParameter(typedValue).ToArray();

            if (ignoreCase)
            {
                if (columnNames.Length != 1)
                {
                    throw new HibernateException(
                              "case insensitive expression may only be applied to single-column properties: " +
                              propertyName);
                }

                return(new SqlString(
                           criteriaQuery.Factory.Dialect.LowercaseFunction,
                           StringHelper.OpenParen,
                           columnNames[0],
                           StringHelper.ClosedParen,
                           Op,
                           parameters.Single()));
            }
            else
            {
                SqlStringBuilder sqlBuilder = new SqlStringBuilder(4 * columnNames.Length);
                var columnNullness          = typedValue.Type.ToColumnNullness(typedValue.Value, criteriaQuery.Factory);

                if (columnNullness.Length != columnNames.Length)
                {
                    throw new AssertionFailure("Column nullness length doesn't match number of columns.");
                }

                for (int i = 0; i < columnNames.Length; i++)
                {
                    if (i > 0)
                    {
                        sqlBuilder.Add(" and ");
                    }

                    if (columnNullness[i])
                    {
                        sqlBuilder.Add(columnNames[i])
                        .Add(Op)
                        .Add(parameters[i]);
                    }
                    else
                    {
                        sqlBuilder.Add(columnNames[i])
                        .Add(" is null ");
                    }
                }
                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)
        {
            string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, this.propertyName);

            ISpatialDialect spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect;

            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);

            Parameter[] parameters = criteriaQuery.NewQueryParameter(this.GetTypedValues(criteria, criteriaQuery)[0]).ToArray();

            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 sqlBuilder = new SqlStringBuilder(10 * columnNames.Length);
            for (int i = 0; i < columnNames.Length; i++)
            {
                if (i > 0)
                {
                    sqlBuilder.Add(" AND ");
                }
                string geometryColumn = columnNames[i].Remove(0, aliasLength);
                sqlBuilder.Add(spatialDialect.GetSpatialFilterString(alias, geometryColumn, keyColumn, tableName, parameters.Single()));
            }
            return sqlBuilder.ToSqlString();
        }
        /// <summary>
        /// Render the SQL Fragment.
        /// </summary>
        /// <param name="criteria"></param>
        /// <param name="position"></param>
        /// <param name="criteriaQuery"></param>
        /// <param name="enabledFilters"></param>
        /// <returns></returns>
        public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
        {
            var spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect;
            string column1 = criteriaQuery.GetColumn(criteria, this.propertyName);
            SqlString sqlString;

            if (IsBinaryOperation())
            {
                if (geometry != null)
                {
                    Parameter[] parameters = criteriaQuery.NewQueryParameter(this.GetTypedValues(criteria, criteriaQuery)[0]).ToArray();
                    sqlString = spatialDialect.GetSpatialAnalysisString(column1, this.analysis, parameters.Single());
                }
                else
                {
                    string column2 = criteriaQuery.GetColumn(criteria, this.anotherPropertyName);
                    sqlString = spatialDialect.GetSpatialAnalysisString(column1, this.analysis, column2);
                }
            }
            else
            {
                sqlString = spatialDialect.GetSpatialAnalysisString(column1, this.analysis, null);
            }

            return new SqlStringBuilder()
                .Add(sqlString)
                .Add(" as y")
                .Add(position.ToString())
                .Add("_")
                .ToSqlString();
        }
Пример #41
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 ...
            Parameter[] parameters = GetParameterTypedValues(criteria, criteriaQuery).SelectMany(t => criteriaQuery.NewQueryParameter(t)).ToArray();

            for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++)
            {
                SqlString columnName = columnNames[columnIndex];

                if (columnIndex > 0)
                {
                    result.Add(" and ");
                }

                result
                .Add(columnName)
                //эノfnSplitStringsち澄把计
                .Add(" in ( select Item from fnSplitStrings(");

                for (int i = 0; i < _values.Length; i++)
                {
                    if (i > 0)
                    {
                        result.Add(StringHelper.CommaSpace);
                    }
                    result.Add(parameters[i]);
                }

                result.Add(",',')");
                result.Add(")");
            }

            return(result.ToSqlString());
        }
Пример #42
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]);

			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();
		}
		/// <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);

			Parameter[] parameters = criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).ToArray();

			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)
					.Add(parameters.Single())
					.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)
						.Add(parameters[i]);
				}
				return sqlBuilder.ToSqlString();
			}
		}
Пример #44
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);

			TypedValue typedValue = GetParameterTypedValue(criteria, criteriaQuery);
			Parameter[] parameters = criteriaQuery.NewQueryParameter(typedValue).ToArray();
   
			if (ignoreCase)
			{
				if (columnNames.Length != 1)
				{
					throw new HibernateException(
						"case insensitive expression may only be applied to single-column properties: " +
						propertyName);
				}
   
				return new SqlString(
					criteriaQuery.Factory.Dialect.LowercaseFunction,
					StringHelper.OpenParen,
					columnNames[0],
					StringHelper.ClosedParen,
					Op,
					parameters.Single());
			}
			else
			{
				SqlStringBuilder sqlBuilder = new SqlStringBuilder(4 * columnNames.Length);
				var columnNullness = typedValue.Type.ToColumnNullness(typedValue.Value, criteriaQuery.Factory);

				if (columnNullness.Length != columnNames.Length)
				{
					throw new AssertionFailure("Column nullness length doesn't match number of columns.");
				}
   
				for (int i = 0; i < columnNames.Length; i++)
				{
					if (i > 0)
					{
						sqlBuilder.Add(" and ");
					}
   
					if (columnNullness[i])
					{
						sqlBuilder.Add(columnNames[i])
								  .Add(Op)
								  .Add(parameters[i]);
					}
					else
					{
						sqlBuilder.Add(columnNames[i])
								  .Add(" is null ");
					}
				}
				return sqlBuilder.ToSqlString();
			}
		}