Skip to content

Commit

Permalink
fix issue with SQLite and chunking of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed May 2, 2015
1 parent 70a7095 commit f043906
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/Jackalope/Transport/DoctrineDBAL/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,25 @@ public function getNamespaces()
return $this->namespaces;
}

/**
* Executes an UPDATE on DBAL while ensuring that we never try to send more than 999 parameters to SQLite
*
* @param $query
* @param array $params
* @param array $types
* @throws DBALException
*/
private function executeUpdate($query, array $params = array(), array $types = array())
{
if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) {
foreach (array_chunk($params, 999) as $chunk) {
$this->conn->executeUpdate($query, array($chunk), $types);
}
} else {
$this->conn->executeUpdate($query, array($params), $types);
}
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -729,7 +748,7 @@ private function syncReferences()
try {
foreach ($this->referenceTables as $table) {
$query = "DELETE FROM $table WHERE source_id IN (?)";
$this->conn->executeUpdate($query, array(array_keys($toUpdate)), array(Connection::PARAM_INT_ARRAY));
$this->executeUpdate($query, array(array_keys($toUpdate)), array(Connection::PARAM_INT_ARRAY));
}
} catch (DBALException $e) {
throw new RepositoryException('Unexpected exception while cleaning up after saving', $e->getCode(), $e);
Expand Down Expand Up @@ -765,13 +784,7 @@ private function syncReferences()
// remove all PropertyType::REFERENCE with a source_id on a deleted node
try {
$query = "DELETE FROM phpcr_nodes_references WHERE source_id IN (?)";
if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) {
foreach (array_chunk($params, 999) as $chunk) {
$this->conn->executeUpdate($query, array($chunk), array(Connection::PARAM_INT_ARRAY));
}
} else {
$this->conn->executeUpdate($query, array($params), array(Connection::PARAM_INT_ARRAY));
}
$this->executeUpdate($query, array($params), array(Connection::PARAM_INT_ARRAY));
} catch (DBALException $e) {
throw new RepositoryException('Unexpected exception while cleaning up deleted nodes', $e->getCode(), $e);
}
Expand Down Expand Up @@ -810,13 +823,7 @@ private function syncReferences()
try {
foreach ($this->referenceTables as $table) {
$query = "DELETE FROM $table WHERE target_id IN (?)";
if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) {
foreach (array_chunk($params, 999) as $chunk) {
$this->conn->executeUpdate($query, array($chunk), array(Connection::PARAM_INT_ARRAY));
}
} else {
$this->conn->executeUpdate($query, array($params), array(Connection::PARAM_INT_ARRAY));
}
$this->executeUpdate($query, array($params), array(Connection::PARAM_INT_ARRAY));
}
} catch (DBALException $e) {
throw new RepositoryException('Unexpected exception while cleaning up deleted nodes', $e->getCode(), $e);
Expand Down

0 comments on commit f043906

Please sign in to comment.