{"action":"created","issue":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/655","repository_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4","labels_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/655/labels{/name}","comments_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/655/comments","events_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/655/events","html_url":"https://github.com/bcit-ci/CodeIgniter4/issues/655","id":248099799,"number":655,"title":"PREG_QUOTE and SQL String Binding","user":{"login":"JakeAi","id":20408447,"avatar_url":"https://avatars1.githubusercontent.com/u/20408447?v=4","gravatar_id":"","url":"https://api.github.com/users/JakeAi","html_url":"https://github.com/JakeAi","followers_url":"https://api.github.com/users/JakeAi/followers","following_url":"https://api.github.com/users/JakeAi/following{/other_user}","gists_url":"https://api.github.com/users/JakeAi/gists{/gist_id}","starred_url":"https://api.github.com/users/JakeAi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JakeAi/subscriptions","organizations_url":"https://api.github.com/users/JakeAi/orgs","repos_url":"https://api.github.com/users/JakeAi/repos","events_url":"https://api.github.com/users/JakeAi/events{/privacy}","received_events_url":"https://api.github.com/users/JakeAi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-08-04T19:43:15Z","updated_at":"2017-08-07T03:21:39Z","closed_at":null,"body":"The function[ \\CodeIgniter\\Database\\Query matchNamedBinds()](https://github.com/bcit-ci/CodeIgniter4/blob/develop/system/Database/Query.php#L403) uses preg_quote to escape some characters. This is a hindrance with SQLSRV as the backslashes are taken literally. Is there a way to override this function in the driver since it's being loaded as a new query in many base functions?\r\n\r\nAdding the line (below) fixes the issue.\r\n```php\r\n$escapedValue = str_replace('\\\\-', '-', $escapedValue);\r\n```\r\n```php\r\nprotected function matchNamedBinds(string $sql, array $binds)\r\n\t{\r\n\t\tforeach ($binds as $placeholder => $value)\r\n\t\t{\r\n\t\t\t$escapedValue = $this->db->escape($value);\r\n\t\t\t// In order to correctly handle backlashes in saved strings\r\n\t\t\t// we will need to preg_quote, so remove the wrapping escape characters\r\n\t\t\t// otherwise it will get escaped.\r\n\t\t\tif (is_array($value))\r\n\t\t\t{\r\n\t\t\t\tforeach ($value as &$item)\r\n\t\t\t\t{\r\n\t\t\t\t\t$item = preg_quote($item, '|');\r\n\t\t\t\t}\r\n\t\t\t\t$escapedValue = '(' . implode(',', $escapedValue) . ')';\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t$escapedValue = preg_quote(trim($escapedValue, $this->db->escapeChar), '|');\r\n\t\t\t}\r\n\t\t\t// preg_quoting can cause issues with some characters in the final query,\r\n\t\t\t// but NOT preg_quoting causes other characters to be intepreted, like $.\r\n\t\t\t$escapedValue = str_replace('\\\\.', '.', $escapedValue);\r\n\r\n\t\t\t//THIS LINE FIXES IT\r\n\t\t\t$escapedValue = str_replace('\\\\-', '-', $escapedValue);\r\n\t\t\t//THIS LINE FIXES IT\r\n\r\n\t\t\t$sql = preg_replace('|:' . $placeholder . '(?!\\w)|', $escapedValue, $sql);\r\n\t\t}\r\n\t\treturn $sql;\r\n\t}\r\n```"},"comment":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/comments/320559566","html_url":"https://github.com/bcit-ci/CodeIgniter4/issues/655#issuecomment-320559566","issue_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/655","id":320559566,"user":{"login":"lonnieezell","id":51931,"avatar_url":"https://avatars2.githubusercontent.com/u/51931?v=4","gravatar_id":"","url":"https://api.github.com/users/lonnieezell","html_url":"https://github.com/lonnieezell","followers_url":"https://api.github.com/users/lonnieezell/followers","following_url":"https://api.github.com/users/lonnieezell/following{/other_user}","gists_url":"https://api.github.com/users/lonnieezell/gists{/gist_id}","starred_url":"https://api.github.com/users/lonnieezell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lonnieezell/subscriptions","organizations_url":"https://api.github.com/users/lonnieezell/orgs","repos_url":"https://api.github.com/users/lonnieezell/repos","events_url":"https://api.github.com/users/lonnieezell/events{/privacy}","received_events_url":"https://api.github.com/users/lonnieezell/received_events","type":"User","site_admin":false},"created_at":"2017-08-07T03:21:39Z","updated_at":"2017-08-07T03:21:39Z","body":"I have no problem with the second solution. If you wanted to make a PR for it that would be great. What issues were you running into, exactly, with the SQLSRV syntax? I'm not familiar enough with that variant."}}
{"actor":{"display_login":"lonnieezell"}}