Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change collation in query to adapt to charset #337

Merged
merged 1 commit into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

1.3.0
-----

* Added auto-detection of binary collation for MySQL, so that not always utf8_bin is used.
A new `setCaseSensitiveEncoding` method has been introduced, which can be used to override
the auto detected value.

1.2
---

Expand Down
35 changes: 34 additions & 1 deletion src/Jackalope/Transport/DoctrineDBAL/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
*/
private $nodeProcessor;

/**
* @var string
*/
private $caseSensitiveEncoding;

/**
* @param FactoryInterface $factory
* @param Connection $conn
Expand Down Expand Up @@ -439,6 +444,34 @@ public function setCheckLoginOnServer($bool)
$this->checkLoginOnServer = $bool;
}

/**
* This will control the collate which is being used on MySQL when querying nodes. It will be autodetected by just
* appending _bin to the current charset, which is good enough in most cases.
*
* @param string $encoding
*/
public function setCaseSensitiveEncoding($encoding)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a docblock explaining that this is to control what collate should be used when querying for nodes. and mention that its only relevant for mysql and usually the autodetection of appending _bin to the charset is good enough.

{
$this->caseSensitiveEncoding = $encoding;
}

/**
* Returns the collate which is being used on MySQL when querying nodes.
*
* @return string
*/
private function getCaseSensitiveEncoding()
{
if (!$this->caseSensitiveEncoding) {
$params = $this->conn->getParams();
$charset = isset($params['charset']) ? $params['charset'] : 'utf8';

return $this->caseSensitiveEncoding = $charset === 'binary' ? $charset : $charset . '_bin';
}

return $this->caseSensitiveEncoding;
}

protected function workspaceExists($workspaceName)
{
try {
Expand Down Expand Up @@ -1540,7 +1573,7 @@ private function getSystemIdForNode($identifier, $workspaceName = null)
$query = 'SELECT id FROM phpcr_nodes WHERE identifier = ? AND workspace_name = ?';
} else {
if ($this->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOMySql\Driver) {
$query = 'SELECT id FROM phpcr_nodes WHERE path COLLATE utf8_bin = ? AND workspace_name = ?';
$query = 'SELECT id FROM phpcr_nodes WHERE path COLLATE ' . $this->getCaseSensitiveEncoding() .' = ? AND workspace_name = ?';
} else {
$query = 'SELECT id FROM phpcr_nodes WHERE path = ? AND workspace_name = ?';
}
Expand Down