{"record":{"id":"ce4dc6b2a711a9e6","repo":"laravel/framework","slug":"this-database-engine-does-not-support-case-sensiti","errorCode":null,"errorMessage":"This database engine does not support case sensitive like operations.","messagePattern":"This database engine does not support case sensitive like operations\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Grammars/Grammar.php","lineNumber":338,"sourceCode":"     */\n    protected function whereBitwise(Builder $query, $where)\n    {\n        return $this->whereBasic($query, $where);\n    }\n\n    /**\n     * Compile a \"where like\" clause.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @param  array  $where\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    protected function whereLike(Builder $query, $where)\n    {\n        if ($where['caseSensitive']) {\n            throw new RuntimeException('This database engine does not support case sensitive like operations.');\n        }\n\n        $where['operator'] = $where['not'] ? 'not like' : 'like';\n\n        return $this->whereBasic($query, $where);\n    }\n\n    /**\n     * Compile a \"where null safe equals\" clause.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @param  array  $where\n     * @return string\n     */\n    protected function whereNullSafeEquals(Builder $query, $where)\n    {\n        return $this->wrap($where['column']).' is not distinct from '.$this->parameter($where['value']);\n    }","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Grammars/Grammar.php#L320-L356","documentation":"The base Grammar's whereLike throws when $where['caseSensitive'] is true and the grammar does not override the method. MySQL, PostgreSQL, and SQLite all override whereLike to handle case sensitivity (e.g., MySQL uses BINARY, PostgreSQL switches between LIKE and ILIKE). SqlServerGrammar does not override it, so case-sensitive LIKE on SQL Server triggers the throw.","triggerScenarios":"Calling ->whereLike('column', 'value', caseSensitive: true) or ->orWhereLike with caseSensitive: true on a SQL Server (sqlsrv) connection.","commonSituations":"Application originally developed on MySQL or PostgreSQL using case-sensitive LIKE, then migrated to SQL Server. Developer unaware that SQL Server's grammar lacks a case-sensitive LIKE override in Laravel.","solutions":["Switch to a connection whose grammar supports case-sensitive LIKE (mysql, pgsql, or sqlite)","On SQL Server, use a raw where clause with COLLATE: ->whereRaw(\"[column] COLLATE Latin1_General_CS_AS LIKE ?\", ['value'])","Use where() with DB::raw() to apply an explicit case-sensitive collation per query"],"exampleFix":"// before — throws on SQL Server\nUser::whereLike('email', 'Admin@Example.com', caseSensitive: true)->get();\n\n// after — raw COLLATE clause works on SQL Server\nUser::whereRaw(\"email COLLATE Latin1_General_CS_AS LIKE ?\", ['Admin@Example.com'])->get();","handlingStrategy":"type-guard","validationCode":"$driver = DB::connection()->getDriverName();\n\nif ($driver !== 'sqlsrv') {\n    $query->whereLike('email', $value, caseSensitive: true);\n} else {\n    $query->whereRaw(\"email COLLATE Latin1_General_CS_AS LIKE ?\", [$value]);\n}","typeGuard":"function supportsCaseSensitiveLike(): bool {\n    return DB::connection()->getDriverName() !== 'sqlsrv';\n}","tryCatchPattern":"try {\n    $query->whereLike('email', $value, caseSensitive: true);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'case sensitive like')) {\n        $query->whereRaw(\"email COLLATE Latin1_General_CS_AS LIKE ?\", [$value]);\n    } else {\n        throw $e;\n    }\n}","preventionTips":["If targeting SQL Server, avoid caseSensitive: true in whereLike calls","Test case-sensitive LIKE queries against all target DB engines","Keep a COLLATE clause ready as a SQL Server fallback"],"tags":["like","case-sensitive","sqlserver","database","where"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}