示例#1
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            //TODO: add default capacity
            SqlStringBuilder sqlBuilder = new SqlStringBuilder();

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

            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());
        }
示例#2
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
                                              IDictionary <string, IFilter> enabledFilters)
        {
            SqlString[] columnNames =
                CriterionUtil.GetColumnNames(_lhsPropertyName, _lhsProjection, criteriaQuery, criteria, enabledFilters);
            SqlString[] otherColumnNames =
                CriterionUtil.GetColumnNames(_rhsPropertyName, _rhsProjection, criteriaQuery, criteria, enabledFilters);

            SqlStringBuilder sb = new SqlStringBuilder();

            if (columnNames.Length > 1)
            {
                sb.Add(StringHelper.OpenParen);
            }
            bool first = true;

            foreach (SqlString sqlString in SqlStringHelper.Add(columnNames, Op, otherColumnNames))
            {
                if (first == false)
                {
                    sb.Add(" and ");
                }
                first = false;
                sb.Add(sqlString);
            }

            if (columnNames.Length > 1)
            {
                sb.Add(StringHelper.ClosedParen);
            }

            return(sb.ToSqlString());
        }
示例#3
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);

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

                sqlBuilder.Add(columnNames[i])
                .Add(" is null");
            }

            if (columnNames.Length > 1)
            {
                sqlBuilder.Insert(0, "(");
                sqlBuilder.Add(")");
            }

            return(sqlBuilder.ToSqlString());
        }
示例#4
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.AddParameter();

            return(sqlBuilder.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);
        }
示例#6
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());
        }
示例#7
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());
        }
示例#8
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());
        }
示例#9
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());
        }