Exemplo n.º 1
0
 public override void Visit(DbConstantExpression expression)
 {
     if (_createParameters)
     {
         IngresParameter parameter =
             CreateParameter(expression.Value, expression.ResultType);
         _commandText.Append(parameter.ParameterName);
     }
     else
     {
         _commandText.Append(
             _sqlGenerator.WriteSql(expression.Accept(_sqlGenerator)));
     }
 }
Exemplo n.º 2
0
        public override void Visit(DbConstantExpression expression)
        {
            Check.NotNull(expression, "expression");

            if (_createParameters)
            {
                var parameter = CreateParameter(expression.Value, expression.ResultType);
                _commandText.Append(parameter.ParameterName);
            }
            else
            {
                _sqlGenerator.WriteSql(_commandText, expression.Accept(_sqlGenerator));
            }
        }
            public override void Visit(DbConstantExpression expression)
            {
                Check.NotNull <DbConstantExpression>(expression, nameof(expression));
                SqlParameter parameter = this.CreateParameter(expression.Value, expression.ResultType, (string)null);

                if (this._createParameters)
                {
                    this._commandText.Append(parameter.ParameterName);
                }
                else
                {
                    using (SqlWriter writer = new SqlWriter(this._commandText.InnerBuilder))
                        this._sqlGenerator.WriteSql(writer, expression.Accept <ISqlFragment>((DbExpressionVisitor <ISqlFragment>) this._sqlGenerator));
                }
            }
Exemplo n.º 4
0
 public override void Visit(DbConstantExpression expression)
 {
     if (generateParameters)
     {
         var parameter = CreateParameter(expression.Value, expression.ResultType);
         commandText.Append(parameter.ParameterName);
     }
     else
     {
         using (var writer = new SqlWriter(commandText))
         {
             var sqlGenerator = new SqlGenerator();
             sqlGenerator.WriteSql(writer, expression.Accept(sqlGenerator));
         }
     }
 }
Exemplo n.º 5
0
            public override void Visit(DbConstantExpression expression)
            {
                Check.NotNull(expression, "expression");

                var parameter = CreateParameter(expression.Value, expression.ResultType);

                if (_createParameters)
                {
                    _commandText.Append(parameter.ParameterName);
                }
                else
                {
                    using (var writer = new SqlWriter(_commandText.InnerBuilder))
                    {
                        _sqlGenerator.WriteSql(writer, expression.Accept(_sqlGenerator));
                    }
                }
            }
Exemplo n.º 6
0
            public override void Visit(DbConstantExpression expression)
            {
                Check.NotNull(expression, "expression");

                var parameter = CreateParameter(expression.Value, expression.ResultType);

                if (_createParameters)
                {
                    if (_sqlGenerator.CharBoolModes[_sqlGenerator.CurrentColumn] && expression.ResultType.EdmType.Name == "Boolean")
                    {
                        Facet nullable;
                        bool  isNullable = expression.ResultType.Facets.TryGetValue("Nullable", false, out nullable) && (bool)nullable.Value;
                        if (isNullable)
                        {
                            _commandText.Append("(CASE WHEN ");
                            _commandText.Append(parameter.ParameterName);
                            _commandText.Append(" IS NULL THEN NULL ELSE ");
                        }
                        _commandText.Append("(CASE WHEN ");
                        _commandText.Append(parameter.ParameterName);
                        _commandText.Append(" = 1 ");
                        _commandText.Append(string.Format(CultureInfo.InvariantCulture, "THEN '{0}' ELSE '{1}' END) ", SqlProviderServices.CharBoolTrueChar, SqlProviderServices.CharBoolFalseChar));
                        if (isNullable)
                        {
                            _commandText.Append("END) ");
                        }
                    }
                    else
                    {
                        _commandText.Append(parameter.ParameterName);
                    }
                }
                else
                {
                    using (var writer = new SqlWriter(_commandText.InnerBuilder))
                    {
                        _sqlGenerator.WriteSql(writer, expression.Accept(_sqlGenerator));
                    }
                }
            }
            public override void Visit(DbConstantExpression expression)
            {
                Check.NotNull(expression, "expression");

                if (!_commandTree.Parameters.Any())
                {
                    var parameter = CreateParameter(expression.Value, expression.ResultType);

                    _commandText.Append(parameter.ParameterName);
                }
                else
                {
                    _commandText.Append(_sqlGenerator.WriteSql(expression.Accept(_sqlGenerator)));
                }
            }
Exemplo n.º 8
0
 public override DbExpression Visit(DbConstantExpression exp)
 {
     return(exp.Accept(this._generator));
 }
Exemplo n.º 9
0
            public override void Visit(DbConstantExpression expression)
            {
                Check.NotNull(expression, "expression");

                var parameter = CreateParameter(expression.Value, expression.ResultType);

                if (_createParameters)
                {
                    _commandText.Append(parameter.ParameterName);
                }
                else
                {
                    using (var writer = new SqlWriter(_commandText.InnerBuilder))
                    {
                        _sqlGenerator.WriteSql(writer, expression.Accept(_sqlGenerator));
                    }
                }
            }
        /// <summary>
        /// Function to translate the StartsWith, EndsWith and Contains canonical functions to LIKE expression in T-SQL
        /// and also add the trailing ESCAPE '~' when escaping of the search string for the LIKE expression has occurred
        /// </summary>
        /// <param name="sqlgen"></param>
        /// <param name="targetExpression"></param>
        /// <param name="constSearchParamExpression"></param>
        /// <param name="result"></param>
        /// <param name="insertPercentStart"></param>
        /// <param name="insertPercentEnd"></param>
        private static void TranslateConstantParameterForLike(SqlGenerator sqlgen, DbExpression targetExpression, DbConstantExpression constSearchParamExpression, SqlBuilder result, bool insertPercentStart, bool insertPercentEnd)
        {
            result.Append(targetExpression.Accept(sqlgen));
            result.Append(" LIKE ");

            // If it's a DbConstantExpression then escape the search parameter if necessary.
            bool escapingOccurred;

            StringBuilder searchParamBuilder = new StringBuilder();
            if (insertPercentStart == true)
                searchParamBuilder.Append("%");
            searchParamBuilder.Append(SqlProviderManifest.EscapeLikeText(constSearchParamExpression.Value as string, false,  out escapingOccurred));
            if (insertPercentEnd == true)
                searchParamBuilder.Append("%");

            DbConstantExpression escapedSearchParamExpression = new DbConstantExpression(constSearchParamExpression.ResultType, searchParamBuilder.ToString());
            result.Append(escapedSearchParamExpression.Accept(sqlgen));

            // If escaping did occur (special characters were found), then append the escape character used.
            if (escapingOccurred)
                result.Append(" ESCAPE '" + SqlProviderManifest.LikeEscapeChar + "'");
        }
 public override void Visit(DbConstantExpression expression)
 {
     if (generateParameters)
     {
         var parameter = CreateParameter(expression.Value, expression.ResultType);
         commandText.Append(parameter.ParameterName);
     }
     else
     {
         using (var writer = new SqlWriter(commandText))
         {
             var sqlGenerator = new SqlGenerator();
             sqlGenerator.WriteSql(writer, expression.Accept(sqlGenerator));
         }
     }
 }