Skip to content

Commit

Permalink
DbRepository: Allow to pass parameter $types to methods insert() and …
Browse files Browse the repository at this point in the history
…update()

DbConnection does already support this but it got somehow forgotten in this
class.
  • Loading branch information
nilmerg committed Jun 6, 2017
1 parent 29f9ff5 commit 91b0e98
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions library/Icinga/Repository/DbRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,37 +348,56 @@ protected function clearTableAlias($table)
/**
* Insert a table row with the given data
*
* Note that the base implementation does not perform any quoting on the $table argument.
* Pass an array with a column name (the same as in $bind) and a PDO::PARAM_* constant as value
* as third parameter $types to define a different type than string for a particular column.
*
* @param string $table
* @param array $bind
* @param array $types
*
* @return int The number of affected rows
*/
public function insert($table, array $bind)
public function insert($table, array $bind, array $types = array())
{
return $this->ds->insert(
$this->clearTableAlias($this->requireTable($table)),
$this->requireStatementColumns($table, $bind)
);
$realTable = $this->clearTableAlias($this->requireTable($table));

foreach ($types as $alias => $type) {
unset($types[$alias]);
$types[$this->requireStatementColumn($table, $alias)] = $type;
}

return $this->ds->insert($realTable, $this->requireStatementColumns($table, $bind), $types);
}

/**
* Update table rows with the given data, optionally limited by using a filter
*
* Note that the base implementation does not perform any quoting on the $table argument.
* Pass an array with a column name (the same as in $bind) and a PDO::PARAM_* constant as value
* as fourth parameter $types to define a different type than string for a particular column.
*
* @param string $table
* @param array $bind
* @param Filter $filter
* @param array $types
*
* @return int The number of affected rows
*/
public function update($table, array $bind, Filter $filter = null)
public function update($table, array $bind, Filter $filter = null, array $types = array())
{
$realTable = $this->clearTableAlias($this->requireTable($table));

if ($filter) {
$filter = $this->requireFilter($table, $filter);
}

return $this->ds->update($realTable, $this->requireStatementColumns($table, $bind), $filter);
foreach ($types as $alias => $type) {
unset($types[$alias]);
$types[$this->requireStatementColumn($table, $alias)] = $type;
}

return $this->ds->update($realTable, $this->requireStatementColumns($table, $bind), $filter, $types);
}

/**
Expand Down

0 comments on commit 91b0e98

Please sign in to comment.