mirror of
https://github.com/dg/dibi.git
synced 2025-10-21 01:36:26 +02:00
- added DibiDataSource as default implementation of IDataSource
- new modifiers %lmt %ofs - removed old modifier %p (alias for %sql)
This commit is contained in:
@@ -141,14 +141,8 @@ abstract class DibiTable extends NObject
|
||||
*/
|
||||
public function insert($data)
|
||||
{
|
||||
if (is_object($data)) {
|
||||
$data = (array) $data;
|
||||
} elseif (!is_array($data)) {
|
||||
throw new DibiException('Dataset must be array or anonymous object');
|
||||
}
|
||||
|
||||
$this->connection->query(
|
||||
'INSERT INTO %n', $this->name, '%v', $data
|
||||
'INSERT INTO %n', $this->name, '%v', $this->prepare($data)
|
||||
);
|
||||
return $this->connection->insertId();
|
||||
}
|
||||
@@ -163,15 +157,9 @@ abstract class DibiTable extends NObject
|
||||
*/
|
||||
public function update($where, $data)
|
||||
{
|
||||
if (is_object($data)) {
|
||||
$data = (array) $data;
|
||||
} elseif (!is_array($data)) {
|
||||
throw new DibiException('Dataset must be array or anonymous object');
|
||||
}
|
||||
|
||||
$this->connection->query(
|
||||
'UPDATE %n', $this->name,
|
||||
'SET %a', $data,
|
||||
'SET %a', $this->prepare($data),
|
||||
'WHERE %n', $this->primary, 'IN (' . $this->primaryModifier, $where, ')'
|
||||
);
|
||||
return $this->connection->affectedRows();
|
||||
@@ -266,6 +254,24 @@ abstract class DibiTable extends NObject
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* User data pre-processing
|
||||
* @param array|object
|
||||
* @return array
|
||||
*/
|
||||
protected function prepare($data)
|
||||
{
|
||||
if (is_object($data)) {
|
||||
return (array) $data;
|
||||
} elseif (is_array($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
throw new DibiException('Dataset must be array or anonymous object');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* User DibiResult post-processing
|
||||
* @param DibiResult
|
||||
|
Reference in New Issue
Block a user