Exemple #1
0
        public static StringExpression RTrim(this StringExpression expr)
        {
            var newExpr = (StringExpression)expr.Clone();

            newExpr._sql = "RTRIM(" + expr._sql + ")";

            return(newExpr);
        }
Exemple #2
0
        /// <summary>
        /// Left of current string expression.
        /// </summary>
        /// <param name="expr">The expr.</param>
        /// <param name="length">The length.</param>
        /// <returns></returns>
        public static StringExpression Left(this StringExpression expr, int length)
        {
            var newExpr = (StringExpression)expr.Clone();

            newExpr.Sql = "LEFT(" + newExpr.Sql + ", ?)";
            newExpr.ChildExpressions.Add(new Int32ParameterExpression(length));

            return(newExpr);
        }
Exemple #3
0
        public static StringExpression Right(this StringExpression expr, int length)
        {
            var newExpr = (StringExpression)expr.Clone();

            newExpr._sql = "RIGHT(" + newExpr._sql + ", ?)";
            newExpr._childExpressions.Add(new Int32ParameterExpression(length));

            return(newExpr);
        }
Exemple #4
0
        public static StringExpression Substring(this StringExpression expr, int begin, int length)
        {
            var newExpr = (StringExpression)expr.Clone();

            newExpr._sql = "SUBSTRING(" + newExpr._sql + ", ? + 1, ?)";
            newExpr._childExpressions.Add(new Int32ParameterExpression(begin));
            newExpr._childExpressions.Add(new Int32ParameterExpression(length));

            return(newExpr);
        }
Exemple #5
0
        public static Condition StartsWith(this StringExpression expr, StringExpression value)
        {
            if (ReferenceEquals(value, null))
            {
                throw new ArgumentNullException("value");
            }

            var escapedLikeValue = (StringExpression)value.Clone();

            escapedLikeValue._sql = escapedLikeValue._sql + " + '%'";

            return(new Condition(expr, ExpressionOperator.Like, escapedLikeValue));
        }
Exemple #6
0
        public static StringExpression Right(this StringExpression expr, Int32Expression length)
        {
            if (ReferenceEquals(length, null))
            {
                throw new ArgumentNullException("length");
            }

            var newExpr = (StringExpression)expr.Clone();

            newExpr._sql = "RIGHT(" + newExpr._sql + ", ?)";
            newExpr._childExpressions.Add(length);

            return(newExpr);
        }
Exemple #7
0
        public static StringExpression Substring(this StringExpression expr, int begin, Int32Expression length)
        {
            if (ReferenceEquals(length, null))
            {
                throw new ArgumentNullException("length");
            }

            var newExpr = (StringExpression)expr.Clone();

            newExpr._sql = "SUBSTRING(" + newExpr._sql + ", ? + 1, ?)";
            newExpr._childExpressions.Add(new Int32ParameterExpression(begin));
            newExpr._childExpressions.Add(length);

            return(newExpr);
        }
Exemple #8
0
        /// <summary>
        /// Substring of specified expr.
        /// </summary>
        /// <param name="expr">The expr.</param>
        /// <param name="begin">The begin.</param>
        /// <param name="length">The length.</param>
        /// <returns></returns>
        public static StringExpression Substring(this StringExpression expr, Int32Expression begin, int length)
        {
            if (ReferenceEquals(begin, null))
            {
                throw new ArgumentNullException("begin");
            }

            var newExpr = (StringExpression)expr.Clone();

            newExpr.Sql = "SUBSTR(" + newExpr.Sql + ", ? + 1, ?)";
            newExpr.ChildExpressions.Add(begin);
            newExpr.ChildExpressions.Add(new Int32ParameterExpression(length));

            return(newExpr);
        }
Exemple #9
0
        public static StringExpression Replace(this StringExpression expr, StringExpression find, StringExpression replace)
        {
            if (ReferenceEquals(find, null))
            {
                throw new ArgumentNullException("find");
            }
            if (ReferenceEquals(replace, null))
            {
                throw new ArgumentNullException("replace");
            }

            var newExpr = (StringExpression)expr.Clone();

            newExpr._sql = "REPLACE(" + newExpr._sql + ", ?, ?)";
            newExpr._childExpressions.Add(find);
            newExpr._childExpressions.Add(replace);

            return(newExpr);
        }
Exemple #10
0
        public static StringExpression Replace(this StringExpression expr, string find, StringExpression replace)
        {
            if (string.IsNullOrEmpty(find))
            {
                throw new ArgumentNullException("find");
            }
            if (ReferenceEquals(replace, null))
            {
                throw new ArgumentNullException("replace");
            }

            var newExpr = (StringExpression)expr.Clone();

            newExpr._sql = "REPLACE(" + newExpr._sql + ", ?, ?)";
            newExpr._childExpressions.Add(new StringParameterExpression(find, expr.IsUnicode));
            newExpr._childExpressions.Add(replace);

            return(newExpr);
        }
Exemple #11
0
 public static Int32Expression GetLength(this StringExpression expr)
 {
     return(new Int32Expression("LEN(" + expr._sql + ")", ((StringExpression)expr.Clone())._childExpressions));
 }
Exemple #12
0
 public static Int32Expression ToUnicode(this StringExpression expr)
 {
     return(new Int32Expression("UNICODE(" + expr._sql + ")", ((StringExpression)expr.Clone())._childExpressions));
 }
Exemple #13
0
 public static Int32Expression ToAscii(this StringExpression expr)
 {
     return(new Int32Expression("ASCII(" + expr._sql + ")", ((StringExpression)expr.Clone())._childExpressions));
 }
Exemple #14
0
        public static Int32Expression IndexOf(this StringExpression expr, StringExpression value)
        {
            var newExpr = new Int32Expression("CHARINDEX(?, " + expr._sql + ") - 1", ((StringExpression)expr.Clone())._childExpressions);

            newExpr.ChildExpressions.Insert(0, value);

            return(newExpr);
        }
Exemple #15
0
        public static Int32Expression IndexOf(this StringExpression expr, string value)
        {
            var newExpr = new Int32Expression("CHARINDEX(?, " + expr._sql + ") - 1", ((StringExpression)expr.Clone())._childExpressions);

            newExpr.ChildExpressions.Insert(0, new StringParameterExpression(value, expr.IsUnicode));

            return(newExpr);
        }
Exemple #16
0
        /// <summary>
        /// Index of specified substring in current string expression.
        /// </summary>
        /// <param name="expr">The expr.</param>
        /// <param name="value">The substring value.</param>
        /// <returns></returns>
        public static Int32Expression IndexOf(this StringExpression expr, StringExpression value)
        {
            var newExpr = new Int32Expression("INSTR(" + expr.Sql + ", ?) - 1", ((StringExpression)expr.Clone()).ChildExpressions);

            newExpr.ChildExpressions.Insert(0, value);

            return(newExpr);
        }