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
}
/**
* 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
*
* @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 third key being the criteria strings
* - the third key being the conditions
*/
private function gatherCriteria(array $identifiers)
private function gatherConditions(array $identifiers)
{
$columns = [];
$values = [];
$criteria = [];
$conditions = [];
foreach ($identifiers as $columnName => $value) {
if (null === $value) {
$criteria[] = $this->getDatabasePlatform()->getIsNullExpression($columnName);
$conditions[] = $this->getDatabasePlatform()->getIsNullExpression($columnName);
continue;
}
$columns[] = $columnName;
$values[] = $value;
$criteria[] = $columnName . ' = ?';
$conditions[] = $columnName . ' = ?';
}
return [$columns, $values, $criteria];
return [$columns, $values, $conditions];
}
/**
......@@ -651,12 +651,12 @@ class Connection implements DriverConnection
throw InvalidArgumentException::fromEmptyCriteria();
}
list($columnList, $paramValues, $criteria) = $this->gatherCriteria($identifier);
list($columns, $values, $conditions) = $this->gatherConditions($identifier);
return $this->executeUpdate(
'DELETE FROM ' . $tableExpression . ' WHERE ' . implode(' AND ', $criteria),
$paramValues,
is_string(key($types)) ? $this->extractTypeValues($columnList, $types) : $types
'DELETE FROM ' . $tableExpression . ' WHERE ' . implode(' AND ', $conditions),
$values,
is_string(key($types)) ? $this->extractTypeValues($columns, $types) : $types
);
}
......@@ -714,28 +714,28 @@ class Connection implements DriverConnection
*/
public function update($tableExpression, array $data, array $identifier, array $types = array())
{
$columnList = array();
$setColumns = array();
$setValues = array();
$set = array();
$paramValues = array();
foreach ($data as $columnName => $value) {
$columnList[] = $columnName;
$setColumns[] = $columnName;
$setValues[] = $value;
$set[] = $columnName . ' = ?';
$paramValues[] = $value;
}
list($whereColumns, $whereValues, $criteria) = $this->gatherCriteria($identifier);
$columnList = array_merge($columnList, $whereColumns);
$paramValues = array_merge($paramValues, $whereValues);
list($conditionColumns, $conditionValues, $conditions) = $this->gatherConditions($identifier);
$columns = array_merge($setColumns, $conditionColumns);
$values = array_merge($setValues, $conditionValues);
if (is_string(key($types))) {
$types = $this->extractTypeValues($columnList, $types);
$types = $this->extractTypeValues($columns, $types);
}
$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
return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' ()' . ' VALUES ()');
}
$columnList = array();
$paramPlaceholders = array();
$paramValues = array();
$columns = array();
$values = array();
$set = array();
foreach ($data as $columnName => $value) {
$columnList[] = $columnName;
$paramPlaceholders[] = '?';
$paramValues[] = $value;
$columns[] = $columnName;
$values[] = $value;
$set[] = '?';
}
return $this->executeUpdate(
'INSERT INTO ' . $tableExpression . ' (' . implode(', ', $columnList) . ')' .
' VALUES (' . implode(', ', $paramPlaceholders) . ')',
$paramValues,
is_string(key($types)) ? $this->extractTypeValues($columnList, $types) : $types
'INSERT INTO ' . $tableExpression . ' (' . implode(', ', $columns) . ')' .
' VALUES (' . implode(', ', $set) . ')',
$values,
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