Fixing minor bugs for insert, such as accessibility and query building in loops.

This commit is contained in:
Dennis Eichhorn 2015-12-20 22:28:40 +01:00
parent fdef759d37
commit e247c6a627
3 changed files with 44 additions and 18 deletions

View File

@ -249,7 +249,9 @@ abstract class DataMapperAbstract implements DataMapperInterface
foreach ($properties as $property) { foreach ($properties as $property) {
foreach (static::$columns as $key => $column) { foreach (static::$columns as $key => $column) {
if ($column['internal'] === $property) { if ($column['internal'] === $property->getName()) {
$property->setAccessible(true);
$value = $property->getValue($obj); $value = $property->getValue($obj);
if ($column['type'] === 'DateTime') { if ($column['type'] === 'DateTime') {
@ -257,7 +259,9 @@ abstract class DataMapperAbstract implements DataMapperInterface
} }
$query->insert($column['name']) $query->insert($column['name'])
->values($value); ->value($value);
// todo: do i have to reverse the accessibility or is there no risk involved here?
break; break;
} }

View File

@ -17,6 +17,7 @@
namespace phpOMS\DataStorage\Database\Query; namespace phpOMS\DataStorage\Database\Query;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\Query;
/** /**
* Database query builder. * Database query builder.
@ -174,7 +175,7 @@ class Builder
* @var QueryType * @var QueryType
* @since 1.0.0 * @since 1.0.0
*/ */
protected $type = null; protected $type = QueryType::INSERT;
protected $unionLimit = null; protected $unionLimit = null;
@ -792,6 +793,26 @@ class Builder
return $this; return $this;
} }
/**
* Values to insert.
*
* @param mixed $value Values
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function value($value) : Builder
{
end($this->values);
$key = key($this->values);
$this->values[$key][] = $value;
reset($this->values);
return $this;
}
public function update() : Builder public function update() : Builder
{ {
$this->type = QueryType::UPDATE; $this->type = QueryType::UPDATE;
@ -877,7 +898,8 @@ class Builder
return $this->type; return $this->type;
} }
public function merge($query) : Builder { public function merge($query) : Builder
{
return clone($this); return clone($this);
} }
} }

View File

@ -169,10 +169,10 @@ class Grammar extends \phpOMS\DataStorage\Database\Grammar
$components = $this->insertComponents; $components = $this->insertComponents;
break; break;
case QueryType::UPDATE: case QueryType::UPDATE:
$components = null; $components = [];
break; break;
case QueryType::DELETE: case QueryType::DELETE:
$components = null; $components = [];
break; break;
default: default:
throw new \InvalidArgumentException('Unknown query type.'); throw new \InvalidArgumentException('Unknown query type.');