mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 05:37:39 +02:00
bug fixed
This commit is contained in:
@@ -227,7 +227,6 @@ class DibiMsSqlDriver extends NObject implements IDibiDriver
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of rows in a result set
|
* Returns the number of rows in a result set
|
||||||
*
|
*
|
||||||
|
@@ -277,7 +277,6 @@ class DibiMySqlDriver extends NObject implements IDibiDriver
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of rows in a result set
|
* Returns the number of rows in a result set
|
||||||
*
|
*
|
||||||
|
@@ -125,6 +125,7 @@ class DibiMySqliDriver extends NObject implements IDibiDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from a database
|
* Disconnects from a database
|
||||||
*
|
*
|
||||||
@@ -256,8 +257,6 @@ class DibiMySqliDriver extends NObject implements IDibiDriver
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of rows in a result set
|
* Returns the number of rows in a result set
|
||||||
*
|
*
|
||||||
|
@@ -239,7 +239,6 @@ class DibiOdbcDriver extends NObject implements IDibiDriver
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of rows in a result set
|
* Returns the number of rows in a result set
|
||||||
*
|
*
|
||||||
|
@@ -232,7 +232,6 @@ class DibiOracleDriver extends NObject implements IDibiDriver
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of rows in a result set
|
* Returns the number of rows in a result set
|
||||||
*
|
*
|
||||||
|
@@ -95,6 +95,7 @@ class DibiPdoDriver extends NObject implements IDibiDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from a database
|
* Disconnects from a database
|
||||||
*
|
*
|
||||||
|
@@ -69,6 +69,7 @@ class DibiPostgreDriver extends NObject implements IDibiDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to a database
|
* Connects to a database
|
||||||
*
|
*
|
||||||
@@ -262,8 +263,6 @@ class DibiPostgreDriver extends NObject implements IDibiDriver
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of rows in a result set
|
* Returns the number of rows in a result set
|
||||||
*
|
*
|
||||||
|
@@ -105,6 +105,7 @@ class DibiSqliteDriver extends NObject implements IDibiDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from a database
|
* Disconnects from a database
|
||||||
*
|
*
|
||||||
@@ -235,7 +236,6 @@ class DibiSqliteDriver extends NObject implements IDibiDriver
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of rows in a result set
|
* Returns the number of rows in a result set
|
||||||
*
|
*
|
||||||
|
@@ -49,6 +49,9 @@ abstract class DibiTable extends NObject
|
|||||||
/** @var string primary key type */
|
/** @var string primary key type */
|
||||||
protected $primaryModifier = '%i';
|
protected $primaryModifier = '%i';
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
protected $blankRow = array();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table constructor
|
* Table constructor
|
||||||
@@ -202,10 +205,10 @@ abstract class DibiTable extends NObject
|
|||||||
if (!is_array($what)) {
|
if (!is_array($what)) {
|
||||||
$what = func_get_args();
|
$what = func_get_args();
|
||||||
}
|
}
|
||||||
return $this->connection->query(
|
return $this->complete($this->connection->query(
|
||||||
'SELECT * FROM %n', $this->name,
|
'SELECT * FROM %n', $this->name,
|
||||||
'WHERE %n', $this->primary, 'IN (' . $this->primaryModifier, $what, ')'
|
'WHERE %n', $this->primary, 'IN (' . $this->primaryModifier, $what, ')'
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -218,15 +221,15 @@ abstract class DibiTable extends NObject
|
|||||||
public function findAll($order = NULL)
|
public function findAll($order = NULL)
|
||||||
{
|
{
|
||||||
if ($order === NULL) {
|
if ($order === NULL) {
|
||||||
return $this->connection->query(
|
return $this->complete($this->connection->query(
|
||||||
'SELECT * FROM %n', $this->name
|
'SELECT * FROM %n', $this->name
|
||||||
);
|
));
|
||||||
} else {
|
} else {
|
||||||
$order = func_get_args();
|
$order = func_get_args();
|
||||||
return $this->connection->query(
|
return $this->complete($this->connection->query(
|
||||||
'SELECT * FROM %n', $this->name,
|
'SELECT * FROM %n', $this->name,
|
||||||
'ORDER BY %n', $order
|
'ORDER BY %n', $order
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,14 +238,42 @@ abstract class DibiTable extends NObject
|
|||||||
/**
|
/**
|
||||||
* Fetches single row
|
* Fetches single row
|
||||||
* @param scalar primary key value
|
* @param scalar primary key value
|
||||||
* @return array row
|
* @return array|object row
|
||||||
*/
|
*/
|
||||||
public function fetch($what)
|
public function fetch($what)
|
||||||
{
|
{
|
||||||
$this->connection->query(
|
return $this->complete($this->connection->query(
|
||||||
'SELECT * FROM %n', $this->name,
|
'SELECT * FROM %n', $this->name,
|
||||||
'WHERE %n', $this->primary, '=' . $this->primaryModifier, $what
|
'WHERE %n', $this->primary, '=' . $this->primaryModifier, $what
|
||||||
)->fetch();
|
))->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a blank row (not fetched from database)
|
||||||
|
* @return array|object
|
||||||
|
*/
|
||||||
|
public function createBlank()
|
||||||
|
{
|
||||||
|
$row = $this->blankRow;
|
||||||
|
$row[$this->primary] = NULL;
|
||||||
|
if ($this->connection->getConfig('result:objects')) {
|
||||||
|
$row = (object) $row;
|
||||||
|
}
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User DibiResult post-processing
|
||||||
|
* @param DibiResult
|
||||||
|
* @return DibiResult
|
||||||
|
*/
|
||||||
|
protected function complete($res)
|
||||||
|
{
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,7 @@ class DibiVariable extends NObject implements IDibiVariable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function toSql(IDibiDriver $driver, $modifier)
|
public function toSql(IDibiDriver $driver, $modifier)
|
||||||
{
|
{
|
||||||
return $driver->format($this->value, $this->type);
|
return $driver->format($this->value, $this->type);
|
||||||
|
@@ -114,6 +114,7 @@ class NException extends Exception
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal error handler
|
* Internal error handler
|
||||||
*/
|
*/
|
||||||
|
@@ -5,15 +5,17 @@
|
|||||||
require_once '../dibi/dibi.php';
|
require_once '../dibi/dibi.php';
|
||||||
|
|
||||||
|
|
||||||
copy('sample.sdb', 'sample_tmp.sdb');
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect(array(
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
'database' => 'sample_tmp.sdb',
|
'database' => 'sample.sdb',
|
||||||
));
|
));
|
||||||
|
|
||||||
|
dibi::begin();
|
||||||
|
|
||||||
|
|
||||||
|
// autodetection: primary keys are customer_id, order_id, ...
|
||||||
|
DibiTable::$primaryMask = '%s_id';
|
||||||
|
|
||||||
|
|
||||||
// table products
|
// table products
|
||||||
class Products extends DibiTable
|
class Products extends DibiTable
|
||||||
@@ -24,8 +26,7 @@ class Products extends DibiTable
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// autodetection: primary keys are customer_id, order_id, ...
|
|
||||||
DibiTable::$primaryMask = '%s_id';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ echo "Primary key: $products->primary\n";
|
|||||||
|
|
||||||
// Finds rows by primary key
|
// Finds rows by primary key
|
||||||
foreach ($products->find(1, 3) as $row) {
|
foreach ($products->find(1, 3) as $row) {
|
||||||
...
|
print_r($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user