Commit f4437acb authored by Jonathan Vollebregt's avatar Jonathan Vollebregt

Connection: insert/update/delete variable naming cleanup

parent cab04d0e
...@@ -603,33 +603,33 @@ class Connection implements DriverConnection ...@@ -603,33 +603,33 @@ class Connection implements DriverConnection
} }
/** /**
* Gathers criteria for an update or delete call. * Gathers conditions for an update or delete call.
* *
* @param array $identifiers Input array of columns to values * @param array $identifiers Input array of columns to values
* *
* @return string[][] a triplet with: * @return string[][] a triplet with:
* - the first key being the column names * - the first key being the columns
* - the second key being the values * - the second key being the values
* - the third key being the criteria strings * - the third key being the conditions
*/ */
private function gatherCriteria(array $identifiers) private function gatherConditions(array $identifiers)
{ {
$columns = []; $columns = [];
$values = []; $values = [];
$criteria = []; $conditions = [];
foreach ($identifiers as $columnName => $value) { foreach ($identifiers as $columnName => $value) {
if (null === $value) { if (null === $value) {
$criteria[] = $this->getDatabasePlatform()->getIsNullExpression($columnName); $conditions[] = $this->getDatabasePlatform()->getIsNullExpression($columnName);
continue; continue;
} }
$columns[] = $columnName; $columns[] = $columnName;
$values[] = $value; $values[] = $value;
$criteria[] = $columnName . ' = ?'; $conditions[] = $columnName . ' = ?';
} }
return [$columns, $values, $criteria]; return [$columns, $values, $conditions];
} }
/** /**
...@@ -651,12 +651,12 @@ class Connection implements DriverConnection ...@@ -651,12 +651,12 @@ class Connection implements DriverConnection
throw InvalidArgumentException::fromEmptyCriteria(); throw InvalidArgumentException::fromEmptyCriteria();
} }
list($columnList, $paramValues, $criteria) = $this->gatherCriteria($identifier); list($columns, $values, $conditions) = $this->gatherConditions($identifier);
return $this->executeUpdate( return $this->executeUpdate(
'DELETE FROM ' . $tableExpression . ' WHERE ' . implode(' AND ', $criteria), 'DELETE FROM ' . $tableExpression . ' WHERE ' . implode(' AND ', $conditions),
$paramValues, $values,
is_string(key($types)) ? $this->extractTypeValues($columnList, $types) : $types is_string(key($types)) ? $this->extractTypeValues($columns, $types) : $types
); );
} }
...@@ -714,28 +714,28 @@ class Connection implements DriverConnection ...@@ -714,28 +714,28 @@ class Connection implements DriverConnection
*/ */
public function update($tableExpression, array $data, array $identifier, array $types = array()) public function update($tableExpression, array $data, array $identifier, array $types = array())
{ {
$columnList = array(); $setColumns = array();
$setValues = array();
$set = array(); $set = array();
$paramValues = array();
foreach ($data as $columnName => $value) { foreach ($data as $columnName => $value) {
$columnList[] = $columnName; $setColumns[] = $columnName;
$setValues[] = $value;
$set[] = $columnName . ' = ?'; $set[] = $columnName . ' = ?';
$paramValues[] = $value;
} }
list($whereColumns, $whereValues, $criteria) = $this->gatherCriteria($identifier); list($conditionColumns, $conditionValues, $conditions) = $this->gatherConditions($identifier);
$columnList = array_merge($columnList, $whereColumns); $columns = array_merge($setColumns, $conditionColumns);
$paramValues = array_merge($paramValues, $whereValues); $values = array_merge($setValues, $conditionValues);
if (is_string(key($types))) { if (is_string(key($types))) {
$types = $this->extractTypeValues($columnList, $types); $types = $this->extractTypeValues($columns, $types);
} }
$sql = 'UPDATE ' . $tableExpression . ' SET ' . implode(', ', $set) $sql = 'UPDATE ' . $tableExpression . ' SET ' . implode(', ', $set)
. ' WHERE ' . implode(' AND ', $criteria); . ' WHERE ' . implode(' AND ', $conditions);
return $this->executeUpdate($sql, $paramValues, $types); return $this->executeUpdate($sql, $values, $types);
} }
/** /**
...@@ -755,21 +755,21 @@ class Connection implements DriverConnection ...@@ -755,21 +755,21 @@ class Connection implements DriverConnection
return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' ()' . ' VALUES ()'); return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' ()' . ' VALUES ()');
} }
$columnList = array(); $columns = array();
$paramPlaceholders = array(); $values = array();
$paramValues = array(); $set = array();
foreach ($data as $columnName => $value) { foreach ($data as $columnName => $value) {
$columnList[] = $columnName; $columns[] = $columnName;
$paramPlaceholders[] = '?'; $values[] = $value;
$paramValues[] = $value; $set[] = '?';
} }
return $this->executeUpdate( return $this->executeUpdate(
'INSERT INTO ' . $tableExpression . ' (' . implode(', ', $columnList) . ')' . 'INSERT INTO ' . $tableExpression . ' (' . implode(', ', $columns) . ')' .
' VALUES (' . implode(', ', $paramPlaceholders) . ')', ' VALUES (' . implode(', ', $set) . ')',
$paramValues, $values,
is_string(key($types)) ? $this->extractTypeValues($columnList, $types) : $types is_string(key($types)) ? $this->extractTypeValues($columns, $types) : $types
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment