Exemple #1
0
        void InlineDbCommandCondition.AddToCommand(IDbCommand command, DatabaseInfo databaseInfo, string parameterName)
        {
            var tokens = new List <string>();

            if (behavior == Behavior.SingleTerm)
            {
                tokens.Add(searchTerm.Trim());
            }
            else
            {
                // NOTE: We want to improve the separation logic here to deal with odd characters in a good way, and to escape certain characters (per-database). See Task 1913.
                tokens.AddRange(searchTerm.Separate());
            }

            // NOTE: We may have to do some casing stuff for Oracle because existing queries seem to do UPPER on everything.
            var concatCharacter = databaseInfo is SqlServerInfo ? "+" : "||";
            var parameterNumber = 0;
            var newCommandText  = "";

            // NOTE: Is it important to tell the user they've been capped? How would we do that?
            foreach (var token in tokens.Take(20 /*Google allows many more tokens than this.*/))
            {
                var parameter = new DbCommandParameter(
                    parameterName + "L" + parameterNumber++,
                    new DbParameterValue(token.Truncate(128 /*This is Google's cap on word length.*/)));
                newCommandText = StringTools.ConcatenateWithDelimiter(
                    " AND ",
                    newCommandText,
                    (columnName + " LIKE '%' {0} " + parameter.GetNameForCommandText(databaseInfo) + " {0} '%'").FormatWith(concatCharacter));
                command.Parameters.Add(parameter.GetAdoDotNetParameter(databaseInfo));
            }
            command.CommandText += newCommandText;
        }
Exemple #2
0
        void InlineDbCommandCondition.AddToCommand(IDbCommand command, StringBuilder commandText, DatabaseInfo databaseInfo, string parameterName)
        {
            var tokens = new List <string>();

            if (behavior == Behavior.SingleTerm)
            {
                tokens.Add(searchTerm.Trim());
            }
            else
            {
                tokens.AddRange(searchTerm.Separate());
            }

            // NOTE: We may have to do some casing stuff for Oracle because existing queries seem to do UPPER on everything.
            var concatCharacter = databaseInfo is SqlServerInfo ? "+" : "||";
            var parameterNumber = 0;

            // NOTE: Is it important to tell the user they've been capped? How would we do that?

            StringTools.ConcatenateWithDelimiter(
                commandText,
                " AND ",
                tokens.Take(20 /*Google allows many more tokens than this.*/).Select(
                    t => {
                var parameter = new DbCommandParameter(
                    parameterName + "L" + parameterNumber++,
                    new DbParameterValue(t.Truncate(128 /*This is Google's cap on word length.*/)));
                command.Parameters.Add(parameter.GetAdoDotNetParameter(databaseInfo));
                return($@"{columnName} LIKE '%' {concatCharacter} {parameter.GetNameForCommandText( databaseInfo )} {concatCharacter} '%'");
            }));
        }
        void InlineDbCommandCondition.AddToCommand( IDbCommand command, DatabaseInfo databaseInfo, string parameterName )
        {
            var tokens = new List<string>();
            if( behavior == Behavior.SingleTerm )
                tokens.Add( searchTerm.Trim() );
            else {
                // NOTE: We want to improve the separation logic here to deal with odd characters in a good way, and to escape certain characters (per-database). See Task 1913.
                tokens.AddRange( searchTerm.Separate() );
            }

            // NOTE: We may have to do some casing stuff for Oracle because existing queries seem to do UPPER on everything.
            var concatCharacter = databaseInfo is SqlServerInfo ? "+" : "||";
            var parameterNumber = 0;
            var newCommandText = "";
            // NOTE: Is it important to tell the user they've been capped? How would we do that?
            foreach( var token in tokens.Take( 20 /*Google allows many more tokens than this.*/ ) ) {
                var parameter = new DbCommandParameter(
                    parameterName + "L" + parameterNumber++,
                    new DbParameterValue( token.Truncate( 128 /*This is Google's cap on word length.*/ ) ) );
                newCommandText = StringTools.ConcatenateWithDelimiter(
                    " AND ",
                    newCommandText,
                    ( columnName + " LIKE '%' {0} " + parameter.GetNameForCommandText( databaseInfo ) + " {0} '%'" ).FormatWith( concatCharacter ) );
                command.Parameters.Add( parameter.GetAdoDotNetParameter( databaseInfo ) );
            }
            command.CommandText += newCommandText;
        }