mirror of
https://github.com/dg/dibi.git
synced 2025-08-09 15:47:23 +02:00
typos & whitespace
This commit is contained in:
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi connection.
|
||||
*
|
||||
@@ -45,7 +40,6 @@ class DibiConnection extends DibiObject
|
||||
private $substitutes;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Connection options: (see driver-specific options too)
|
||||
* - lazy (bool) => if TRUE, connection will be established only when required
|
||||
@@ -139,7 +133,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
@@ -151,7 +144,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
@@ -171,7 +163,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
@@ -183,7 +174,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns TRUE when connection was established.
|
||||
* @return bool
|
||||
@@ -194,7 +184,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns configuration variable. If no $key is passed, returns the entire array.
|
||||
* @see self::__construct
|
||||
@@ -216,7 +205,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Apply configuration alias or default values.
|
||||
* @param array connect configuration
|
||||
@@ -224,10 +212,12 @@ class DibiConnection extends DibiObject
|
||||
* @param string alias key
|
||||
* @return void
|
||||
*/
|
||||
public static function alias(&$config, $key, $alias)
|
||||
public static function alias(& $config, $key, $alias)
|
||||
{
|
||||
$foo = & $config;
|
||||
foreach (explode('|', $key) as $key) $foo = & $foo[$key];
|
||||
foreach (explode('|', $key) as $key) {
|
||||
$foo = & $foo[$key];
|
||||
}
|
||||
|
||||
if (!isset($foo) && isset($config[$alias])) {
|
||||
$foo = $config[$alias];
|
||||
@@ -236,7 +226,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the driver and connects to a database in lazy mode.
|
||||
* @return IDibiDriver
|
||||
@@ -248,7 +237,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates (translates) and executes SQL query.
|
||||
* @param array|mixed one or more arguments
|
||||
@@ -262,7 +250,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates SQL query.
|
||||
* @param array|mixed one or more arguments
|
||||
@@ -276,7 +263,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates and prints SQL query.
|
||||
* @param array|mixed one or more arguments
|
||||
@@ -300,7 +286,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates (translates) and returns SQL query as DibiDataSource.
|
||||
* @param array|mixed one or more arguments
|
||||
@@ -314,7 +299,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates SQL query.
|
||||
* @param array
|
||||
@@ -327,7 +311,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
@@ -359,7 +342,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int number of rows
|
||||
@@ -369,12 +351,13 @@ class DibiConnection extends DibiObject
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
$rows = $this->driver->getAffectedRows();
|
||||
if (!is_int($rows) || $rows < 0) throw new DibiException('Cannot retrieve number of affected rows.');
|
||||
if (!is_int($rows) || $rows < 0) {
|
||||
throw new DibiException('Cannot retrieve number of affected rows.');
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows. Alias for getAffectedRows().
|
||||
* @return int number of rows
|
||||
@@ -386,7 +369,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @param string optional sequence name
|
||||
@@ -397,12 +379,13 @@ class DibiConnection extends DibiObject
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
$id = $this->driver->getInsertId($sequence);
|
||||
if ($id < 1) throw new DibiException('Cannot retrieve last generated ID.');
|
||||
if ($id < 1) {
|
||||
throw new DibiException('Cannot retrieve last generated ID.');
|
||||
}
|
||||
return (int) $id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().
|
||||
* @param string optional sequence name
|
||||
@@ -415,7 +398,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
@@ -436,7 +418,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
@@ -457,7 +438,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
@@ -478,7 +458,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Result set factory.
|
||||
* @param IDibiResultDriver
|
||||
@@ -492,11 +471,9 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* fluent SQL builders ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return DibiFluent
|
||||
*/
|
||||
@@ -506,7 +483,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string column name
|
||||
* @return DibiFluent
|
||||
@@ -518,7 +494,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string table
|
||||
* @param array
|
||||
@@ -533,7 +508,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string table
|
||||
* @param array
|
||||
@@ -551,7 +525,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string table
|
||||
* @return DibiFluent
|
||||
@@ -562,11 +535,9 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* substitutions ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns substitution hashmap.
|
||||
* @return DibiHashMap
|
||||
@@ -577,7 +548,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provides substitution.
|
||||
* @return string
|
||||
@@ -588,7 +558,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Substitution callback.
|
||||
*/
|
||||
@@ -598,11 +567,9 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* shortcuts ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Executes SQL query and fetch result - shortcut for query() & fetch().
|
||||
* @param array|mixed one or more arguments
|
||||
@@ -616,11 +583,10 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Executes SQL query and fetch results - shortcut for query() & fetchAll().
|
||||
* @param array|mixed one or more arguments
|
||||
* @return array of DibiRow
|
||||
* @return DibiRow[]
|
||||
* @throws DibiException
|
||||
*/
|
||||
public function fetchAll($args)
|
||||
@@ -630,7 +596,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Executes SQL query and fetch first column - shortcut for query() & fetchSingle().
|
||||
* @param array|mixed one or more arguments
|
||||
@@ -644,7 +609,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().
|
||||
* @param array|mixed one or more arguments
|
||||
@@ -658,11 +622,9 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* misc ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Import SQL dump from file - extreme fast!
|
||||
* @param string filename
|
||||
@@ -698,7 +660,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets a information about the current database.
|
||||
* @return DibiDatabaseInfo
|
||||
@@ -710,7 +671,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prevents unserialization.
|
||||
*/
|
||||
@@ -720,7 +680,6 @@ class DibiConnection extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prevents serialization.
|
||||
*/
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of IDataSource for dibi.
|
||||
*
|
||||
@@ -55,7 +50,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
private $limit;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string SQL command or table or view name, as data source
|
||||
* @param DibiConnection connection
|
||||
@@ -71,12 +65,11 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Selects columns to query.
|
||||
* @param string|array column name or array of column names
|
||||
* @param string column alias
|
||||
* @return DibiDataSource provides a fluent interface
|
||||
* @param string column alias
|
||||
* @return self
|
||||
*/
|
||||
public function select($col, $as = NULL)
|
||||
{
|
||||
@@ -90,11 +83,10 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds conditions to query.
|
||||
* @param mixed conditions
|
||||
* @return DibiDataSource provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
public function where($cond)
|
||||
{
|
||||
@@ -109,12 +101,11 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Selects columns to order by.
|
||||
* @param string|array column name or array of column names
|
||||
* @param string sorting direction
|
||||
* @return DibiDataSource provides a fluent interface
|
||||
* @param string sorting direction
|
||||
* @return self
|
||||
*/
|
||||
public function orderBy($row, $sorting = 'ASC')
|
||||
{
|
||||
@@ -128,12 +119,11 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Limits number of rows.
|
||||
* @param int limit
|
||||
* @param int offset
|
||||
* @return DibiDataSource provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
public function applyLimit($limit, $offset = NULL)
|
||||
{
|
||||
@@ -144,7 +134,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the dibi connection.
|
||||
* @return DibiConnection
|
||||
@@ -155,11 +144,9 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* executing ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns (and queries) DibiResult.
|
||||
* @return DibiResult
|
||||
@@ -173,7 +160,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return DibiResultIterator
|
||||
*/
|
||||
@@ -183,7 +169,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates, executes SQL query and fetches the single row.
|
||||
* @return DibiRow|FALSE array on success, FALSE if no next record
|
||||
@@ -194,7 +179,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Like fetch(), but returns only first field.
|
||||
* @return mixed value on success, FALSE if no next record
|
||||
@@ -205,7 +189,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all records from table.
|
||||
* @return array
|
||||
@@ -216,7 +199,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all records from table and returns associative tree.
|
||||
* @param string associative descriptor
|
||||
@@ -228,7 +210,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all records from table like $key => $value pairs.
|
||||
* @param string associative key
|
||||
@@ -241,7 +222,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Discards the internal cache.
|
||||
* @return void
|
||||
@@ -252,11 +232,9 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* exporting ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns this data source wrapped in DibiFluent object.
|
||||
* @return DibiFluent
|
||||
@@ -267,7 +245,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns this data source wrapped in DibiDataSource object.
|
||||
* @return DibiDataSource
|
||||
@@ -278,7 +255,6 @@ class DibiDataSource extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns SQL query.
|
||||
* @return string
|
||||
@@ -299,11 +275,9 @@ FROM %SQL', $this->sql, '
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* counting ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a given data source.
|
||||
* @return int
|
||||
@@ -321,7 +295,6 @@ FROM %SQL', $this->sql, '
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a given data source.
|
||||
* @return int
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reflection metadata class for a database.
|
||||
*
|
||||
@@ -33,7 +28,6 @@ class DibiDatabaseInfo extends DibiObject
|
||||
private $tables;
|
||||
|
||||
|
||||
|
||||
public function __construct(IDibiReflector $reflector, $name)
|
||||
{
|
||||
$this->reflector = $reflector;
|
||||
@@ -41,7 +35,6 @@ class DibiDatabaseInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -51,9 +44,8 @@ class DibiDatabaseInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array of DibiTableInfo
|
||||
* @return DibiTableInfo[]
|
||||
*/
|
||||
public function getTables()
|
||||
{
|
||||
@@ -62,9 +54,8 @@ class DibiDatabaseInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array of string
|
||||
* @return string[]
|
||||
*/
|
||||
public function getTableNames()
|
||||
{
|
||||
@@ -77,7 +68,6 @@ class DibiDatabaseInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return DibiTableInfo
|
||||
@@ -95,7 +85,6 @@ class DibiDatabaseInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return bool
|
||||
@@ -107,7 +96,6 @@ class DibiDatabaseInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -124,8 +112,6 @@ class DibiDatabaseInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reflection metadata class for a database table.
|
||||
*
|
||||
@@ -164,7 +150,6 @@ class DibiTableInfo extends DibiObject
|
||||
private $primaryKey;
|
||||
|
||||
|
||||
|
||||
public function __construct(IDibiReflector $reflector, array $info)
|
||||
{
|
||||
$this->reflector = $reflector;
|
||||
@@ -173,7 +158,6 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -183,7 +167,6 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -193,9 +176,8 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array of DibiColumnInfo
|
||||
* @return DibiColumnInfo[]
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
@@ -204,9 +186,8 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array of string
|
||||
* @return string[]
|
||||
*/
|
||||
public function getColumnNames()
|
||||
{
|
||||
@@ -219,7 +200,6 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return DibiColumnInfo
|
||||
@@ -237,7 +217,6 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return bool
|
||||
@@ -249,9 +228,8 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array of DibiForeignKeyInfo
|
||||
* @return DibiForeignKeyInfo[]
|
||||
*/
|
||||
public function getForeignKeys()
|
||||
{
|
||||
@@ -260,9 +238,8 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array of DibiIndexInfo
|
||||
* @return DibiIndexInfo[]
|
||||
*/
|
||||
public function getIndexes()
|
||||
{
|
||||
@@ -271,7 +248,6 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return DibiIndexInfo
|
||||
*/
|
||||
@@ -282,7 +258,6 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -297,7 +272,6 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -319,7 +293,6 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -331,8 +304,6 @@ class DibiTableInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reflection metadata class for a result set.
|
||||
*
|
||||
@@ -354,16 +325,14 @@ class DibiResultInfo extends DibiObject
|
||||
private $names;
|
||||
|
||||
|
||||
|
||||
public function __construct(IDibiResultDriver $driver)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array of DibiColumnInfo
|
||||
* @return DibiColumnInfo[]
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
@@ -372,10 +341,9 @@ class DibiResultInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return array of string
|
||||
* @return string[]
|
||||
*/
|
||||
public function getColumnNames($fullNames = FALSE)
|
||||
{
|
||||
@@ -388,7 +356,6 @@ class DibiResultInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return DibiColumnInfo
|
||||
@@ -406,7 +373,6 @@ class DibiResultInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return bool
|
||||
@@ -418,7 +384,6 @@ class DibiResultInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -436,8 +401,6 @@ class DibiResultInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reflection metadata class for a table or result set column.
|
||||
*
|
||||
@@ -467,7 +430,6 @@ class DibiColumnInfo extends DibiObject
|
||||
private $info;
|
||||
|
||||
|
||||
|
||||
public function __construct(IDibiReflector $reflector = NULL, array $info)
|
||||
{
|
||||
$this->reflector = $reflector;
|
||||
@@ -475,7 +437,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -485,7 +446,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -495,7 +455,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -505,7 +464,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return DibiTableInfo
|
||||
*/
|
||||
@@ -518,7 +476,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -528,7 +485,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -538,7 +494,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -548,7 +503,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@@ -558,7 +512,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -568,7 +521,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -578,7 +530,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -588,7 +539,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -598,7 +548,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return mixed
|
||||
@@ -609,7 +558,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Heuristic type detection.
|
||||
* @param string
|
||||
@@ -639,7 +587,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@@ -654,8 +601,6 @@ class DibiColumnInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reflection metadata class for a foreign key.
|
||||
*
|
||||
@@ -675,7 +620,6 @@ class DibiForeignKeyInfo extends DibiObject
|
||||
private $references;
|
||||
|
||||
|
||||
|
||||
public function __construct($name, array $references)
|
||||
{
|
||||
$this->name = $name;
|
||||
@@ -683,7 +627,6 @@ class DibiForeignKeyInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -693,7 +636,6 @@ class DibiForeignKeyInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -705,8 +647,6 @@ class DibiForeignKeyInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reflection metadata class for a index or primary key.
|
||||
*
|
||||
@@ -730,7 +670,6 @@ class DibiIndexInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -740,7 +679,6 @@ class DibiIndexInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -750,7 +688,6 @@ class DibiIndexInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -760,7 +697,6 @@ class DibiIndexInfo extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* DateTime with serialization and timestamp support for PHP 5.2.
|
||||
*
|
||||
@@ -33,7 +28,6 @@ class DibiDateTime extends DateTime
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function modifyClone($modify = '')
|
||||
{
|
||||
$dolly = clone($this);
|
||||
@@ -41,7 +35,6 @@ class DibiDateTime extends DateTime
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function modify($modify)
|
||||
{
|
||||
parent::modify($modify);
|
||||
@@ -49,7 +42,6 @@ class DibiDateTime extends DateTime
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function __sleep()
|
||||
{
|
||||
$this->fix = array($this->format('Y-m-d H:i:s'), $this->getTimezone()->getName());
|
||||
@@ -57,7 +49,6 @@ class DibiDateTime extends DateTime
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->__construct($this->fix[0], new DateTimeZone($this->fix[1]));
|
||||
@@ -65,21 +56,18 @@ class DibiDateTime extends DateTime
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getTimestamp()
|
||||
{
|
||||
return (int) $this->format('U');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function setTimestamp($timestamp)
|
||||
{
|
||||
return $this->__construct(date('Y-m-d H:i:s', $timestamp), new DateTimeZone($this->getTimezone()->getName())); // getTimeZone() crashes in PHP 5.2.6
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->format('Y-m-d H:i:s');
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Profiler & logger event.
|
||||
*
|
||||
@@ -54,7 +49,6 @@ class DibiEvent
|
||||
public $source;
|
||||
|
||||
|
||||
|
||||
public function __construct(DibiConnection $connection, $type, $sql = NULL)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
@@ -85,7 +79,6 @@ class DibiEvent
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function done($result = NULL)
|
||||
{
|
||||
$this->result = $result;
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi common exception.
|
||||
*
|
||||
@@ -36,7 +31,6 @@ class DibiException extends Exception
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string The SQL passed to the constructor
|
||||
*/
|
||||
@@ -46,7 +40,6 @@ class DibiException extends Exception
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string string represenation of exception with SQL command
|
||||
*/
|
||||
@@ -58,8 +51,6 @@ class DibiException extends Exception
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* database server exception.
|
||||
*
|
||||
@@ -72,12 +63,10 @@ class DibiDriverException extends DibiException
|
||||
/********************* error catching ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/** @var string */
|
||||
private static $errorMsg;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Starts catching potential errors/warnings.
|
||||
* @return void
|
||||
@@ -89,7 +78,6 @@ class DibiDriverException extends DibiException
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns catched error/warning message.
|
||||
* @param string catched message
|
||||
@@ -104,7 +92,6 @@ class DibiDriverException extends DibiException
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Internal error handler. Do not call directly.
|
||||
* @internal
|
||||
@@ -124,8 +111,6 @@ class DibiDriverException extends DibiException
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* PCRE exception.
|
||||
*
|
||||
@@ -149,7 +134,6 @@ class DibiPcreException extends Exception {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @package dibi
|
||||
*/
|
||||
@@ -157,7 +141,6 @@ class DibiNotImplementedException extends DibiException
|
||||
{}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @package dibi
|
||||
*/
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi file logger.
|
||||
*
|
||||
@@ -26,7 +21,6 @@ class DibiFileLogger extends DibiObject
|
||||
public $filter;
|
||||
|
||||
|
||||
|
||||
public function __construct($file, $filter = NULL)
|
||||
{
|
||||
$this->file = $file;
|
||||
@@ -34,7 +28,6 @@ class DibiFileLogger extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* After event notification.
|
||||
* @return void
|
||||
@@ -46,7 +39,9 @@ class DibiFileLogger extends DibiObject
|
||||
}
|
||||
|
||||
$handle = fopen($this->file, 'a');
|
||||
if (!$handle) return; // or throw exception?
|
||||
if (!$handle) {
|
||||
return; // or throw exception?
|
||||
}
|
||||
flock($handle, LOCK_EX);
|
||||
|
||||
if ($event->result instanceof Exception) {
|
||||
@@ -65,7 +60,7 @@ class DibiFileLogger extends DibiObject
|
||||
fwrite($handle,
|
||||
"OK: " . $event->sql
|
||||
. ($event->count ? ";\n-- rows: " . $event->count : '')
|
||||
. "\n-- takes: " . sprintf('%0.3f', $event->time * 1000) . ' ms'
|
||||
. "\n-- takes: " . sprintf('%0.3f ms', $event->time * 1000)
|
||||
. "\n-- source: " . implode(':', $event->source)
|
||||
. "\n-- driver: " . $event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name')
|
||||
. "\n-- " . date('Y-m-d H:i:s')
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi FirePHP logger.
|
||||
*
|
||||
@@ -38,7 +33,6 @@ class DibiFirePhpLogger extends DibiObject
|
||||
private static $fireTable = array(array('Time', 'SQL Statement', 'Rows', 'Connection'));
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -48,14 +42,12 @@ class DibiFirePhpLogger extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function __construct($filter = NULL)
|
||||
{
|
||||
$this->filter = $filter ? (int) $filter : DibiEvent::QUERY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* After event notification.
|
||||
* @return void
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi SQL builder via fluent interfaces. EXPERIMENTAL!
|
||||
*
|
||||
@@ -101,7 +96,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
private static $normalizer;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param DibiConnection
|
||||
*/
|
||||
@@ -115,12 +109,11 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Appends new argument to the clause.
|
||||
* @param string clause name
|
||||
* @param array arguments
|
||||
* @return DibiFluent provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
public function __call($clause, $args)
|
||||
{
|
||||
@@ -205,11 +198,10 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Switch to a clause.
|
||||
* @param string clause name
|
||||
* @return DibiFluent provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
public function clause($clause, $remove = FALSE)
|
||||
{
|
||||
@@ -227,11 +219,10 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes a clause.
|
||||
* @param string clause name
|
||||
* @return DibiFluent provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
public function removeClause($clause)
|
||||
{
|
||||
@@ -240,12 +231,11 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Change a SQL flag.
|
||||
* @param string flag name
|
||||
* @param bool value
|
||||
* @return DibiFluent provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
public function setFlag($flag, $value = TRUE)
|
||||
{
|
||||
@@ -259,7 +249,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Is a flag set?
|
||||
* @param string flag name
|
||||
@@ -271,7 +260,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns SQL command.
|
||||
* @return string
|
||||
@@ -282,7 +270,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the dibi connection.
|
||||
* @return DibiConnection
|
||||
@@ -293,12 +280,11 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds DibiResult setup.
|
||||
* @param string method
|
||||
* @param mixed args
|
||||
* @return DibiFluent provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
public function setupResult($method)
|
||||
{
|
||||
@@ -307,11 +293,9 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* executing ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates and executes SQL query.
|
||||
* @param mixed what to return?
|
||||
@@ -325,7 +309,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates, executes SQL query and fetches the single row.
|
||||
* @return DibiRow|FALSE array on success, FALSE if no next record
|
||||
@@ -340,7 +323,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Like fetch(), but returns only first field.
|
||||
* @return mixed value on success, FALSE if no next record
|
||||
@@ -355,7 +337,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all records from table.
|
||||
* @param int offset
|
||||
@@ -368,7 +349,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all records from table and returns associative tree.
|
||||
* @param string associative descriptor
|
||||
@@ -380,7 +360,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all records from table like $key => $value pairs.
|
||||
* @param string associative key
|
||||
@@ -393,7 +372,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Required by the IteratorAggregate interface.
|
||||
* @param int offset
|
||||
@@ -406,7 +384,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates and prints SQL query or it's part.
|
||||
* @param string clause name
|
||||
@@ -418,7 +395,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@@ -430,7 +406,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return DibiResult
|
||||
*/
|
||||
@@ -444,11 +419,9 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* exporting ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return DibiDataSource
|
||||
*/
|
||||
@@ -458,7 +431,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns SQL query.
|
||||
* @return string
|
||||
@@ -473,7 +445,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates parameters for DibiTranslator.
|
||||
* @param string clause name
|
||||
@@ -499,7 +470,9 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
if ($clause === $this->command && $this->flags) {
|
||||
$args[] = implode(' ', array_keys($this->flags));
|
||||
}
|
||||
foreach ($statement as $arg) $args[] = $arg;
|
||||
foreach ($statement as $arg) {
|
||||
$args[] = $arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +480,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Format camelCase clause name to UPPER CASE.
|
||||
* @param string
|
||||
@@ -524,7 +496,6 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
// remove references
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Lazy cached storage.
|
||||
*
|
||||
@@ -29,7 +24,6 @@ abstract class DibiHashMapBase
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function setCallback($callback)
|
||||
{
|
||||
if (!is_callable($callback)) {
|
||||
@@ -40,7 +34,6 @@ abstract class DibiHashMapBase
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
@@ -49,7 +42,6 @@ abstract class DibiHashMapBase
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Lazy cached storage.
|
||||
*
|
||||
@@ -68,7 +60,6 @@ final class DibiHashMap extends DibiHashMapBase
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function __get($nm)
|
||||
{
|
||||
if ($nm == '') {
|
||||
|
@@ -2,19 +2,15 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* SQL literal value.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiLiteral extends DibiObject
|
||||
{
|
||||
@@ -28,7 +24,6 @@ class DibiLiteral extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* DibiObject is the ultimate ancestor of all instantiable classes.
|
||||
*
|
||||
@@ -58,7 +53,6 @@ abstract class DibiObject
|
||||
private static $extMethods;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the class of this object.
|
||||
* @return string
|
||||
@@ -69,7 +63,6 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Access to reflection.
|
||||
* @return \ReflectionObject
|
||||
@@ -80,7 +73,6 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Call to undefined method.
|
||||
* @param string method name
|
||||
@@ -125,7 +117,6 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Call to undefined static method.
|
||||
* @param string method name (in lower case!)
|
||||
@@ -140,7 +131,6 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adding method to class.
|
||||
* @param string method name
|
||||
@@ -158,7 +148,9 @@ abstract class DibiObject
|
||||
self::$extMethods[$pair[1]][''] = NULL;
|
||||
}
|
||||
}
|
||||
if ($name === NULL) return NULL;
|
||||
if ($name === NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$name = strtolower($name);
|
||||
@@ -202,14 +194,13 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns property value. Do not call directly.
|
||||
* @param string property name
|
||||
* @return mixed property value
|
||||
* @throws \LogicException if the property is not defined.
|
||||
*/
|
||||
public function &__get($name)
|
||||
public function & __get($name)
|
||||
{
|
||||
$class = get_class($this);
|
||||
|
||||
@@ -222,8 +213,8 @@ abstract class DibiObject
|
||||
$m = 'get' . $name;
|
||||
if (self::hasAccessor($class, $m)) {
|
||||
// ampersands:
|
||||
// - uses &__get() because declaration should be forward compatible (e.g. with Nette\Web\Html)
|
||||
// - doesn't call &$this->$m because user could bypass property setter by: $x = & $obj->property; $x = 'new value';
|
||||
// - uses & __get() because declaration should be forward compatible (e.g. with Nette\Web\Html)
|
||||
// - doesn't call & $this->$m because user could bypass property setter by: $x = & $obj->property; $x = 'new value';
|
||||
$val = $this->$m();
|
||||
return $val;
|
||||
}
|
||||
@@ -239,7 +230,6 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets value of a property. Do not call directly.
|
||||
* @param string property name
|
||||
@@ -274,7 +264,6 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Is property defined?
|
||||
* @param string property name
|
||||
@@ -287,7 +276,6 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Access to undeclared property.
|
||||
* @param string property name
|
||||
@@ -301,7 +289,6 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Has property an accessor?
|
||||
* @param string class name
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi result set.
|
||||
*
|
||||
@@ -58,7 +53,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
private $formats = array();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param IDibiResultDriver
|
||||
*/
|
||||
@@ -69,7 +63,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@@ -79,7 +72,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
@@ -93,7 +85,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Safe access to property $driver.
|
||||
* @return IDibiResultDriver
|
||||
@@ -109,11 +100,9 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* rows ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
@@ -126,7 +115,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Required by the Countable interface.
|
||||
* @return int
|
||||
@@ -137,7 +125,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
@@ -148,7 +135,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set. Alias for getRowCount().
|
||||
* @deprecated
|
||||
@@ -160,7 +146,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Required by the IteratorAggregate interface.
|
||||
* @return DibiResultIterator
|
||||
@@ -174,15 +159,13 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* fetching rows ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set fetched object class. This class should extend the DibiRow class.
|
||||
* @param string
|
||||
* @return DibiResult provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
public function setRowClass($class)
|
||||
{
|
||||
@@ -191,7 +174,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns fetched object class name.
|
||||
* @return string
|
||||
@@ -202,7 +184,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the row at current position, process optional type conversion.
|
||||
* and moves the internal cursor to the next position
|
||||
@@ -223,7 +204,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Like fetch(), but returns only first field.
|
||||
* @return mixed value on success, FALSE if no next record
|
||||
@@ -240,23 +220,26 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all records from table.
|
||||
* @param int offset
|
||||
* @param int limit
|
||||
* @return array of DibiRow
|
||||
* @return DibiRow[]
|
||||
*/
|
||||
final public function fetchAll($offset = NULL, $limit = NULL)
|
||||
{
|
||||
$limit = $limit === NULL ? -1 : (int) $limit;
|
||||
$this->seek((int) $offset);
|
||||
$row = $this->fetch();
|
||||
if (!$row) return array(); // empty result set
|
||||
if (!$row) {
|
||||
return array(); // empty result set
|
||||
}
|
||||
|
||||
$data = array();
|
||||
do {
|
||||
if ($limit === 0) break;
|
||||
if ($limit === 0) {
|
||||
break;
|
||||
}
|
||||
$limit--;
|
||||
$data[] = $row;
|
||||
} while ($row = $this->fetch());
|
||||
@@ -265,7 +248,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all records from table and returns associative tree.
|
||||
* Examples:
|
||||
@@ -285,7 +267,9 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
|
||||
$this->seek(0);
|
||||
$row = $this->fetch();
|
||||
if (!$row) return array(); // empty result set
|
||||
if (!$row) {
|
||||
return array(); // empty result set
|
||||
}
|
||||
|
||||
$data = NULL;
|
||||
$assoc = preg_split('#(\[\]|->|=|\|)#', $assoc, NULL, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
@@ -344,7 +328,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@@ -352,7 +335,9 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
{
|
||||
$this->seek(0);
|
||||
$row = $this->fetch();
|
||||
if (!$row) return array(); // empty result set
|
||||
if (!$row) {
|
||||
return array(); // empty result set
|
||||
}
|
||||
|
||||
$data = NULL;
|
||||
$assoc = explode(',', $assoc);
|
||||
@@ -417,7 +402,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches all records from table like $key => $value pairs.
|
||||
* @param string associative key
|
||||
@@ -429,7 +413,9 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
{
|
||||
$this->seek(0);
|
||||
$row = $this->fetch();
|
||||
if (!$row) return array(); // empty result set
|
||||
if (!$row) {
|
||||
return array(); // empty result set
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
@@ -475,11 +461,9 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* column types ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Autodetect column types.
|
||||
* @return void
|
||||
@@ -495,7 +479,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts values to specified type and format.
|
||||
* @param array
|
||||
@@ -543,12 +526,11 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Define column type.
|
||||
* @param string column
|
||||
* @param string type (use constant Dibi::*)
|
||||
* @return DibiResult provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
final public function setType($col, $type)
|
||||
{
|
||||
@@ -557,7 +539,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns column type.
|
||||
* @return string
|
||||
@@ -568,12 +549,11 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets data format.
|
||||
* @param string type (use constant Dibi::*)
|
||||
* @param string format
|
||||
* @return DibiResult provides a fluent interface
|
||||
* @return self
|
||||
*/
|
||||
final public function setFormat($type, $format)
|
||||
{
|
||||
@@ -582,7 +562,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns data format.
|
||||
* @return string
|
||||
@@ -593,11 +572,9 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* meta info ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a meta information about the current result set.
|
||||
* @return DibiResultInfo
|
||||
@@ -611,7 +588,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@@ -621,7 +597,6 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @deprecated */
|
||||
public function getColumnNames($fullNames = FALSE)
|
||||
{
|
||||
@@ -630,11 +605,9 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* misc tools ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Displays complete result set as HTML table for debug purposes.
|
||||
* @return void
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* External result set iterator.
|
||||
*
|
||||
@@ -47,7 +42,6 @@ class DibiResultIterator implements Iterator, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Rewinds the iterator to the first element.
|
||||
* @return void
|
||||
@@ -60,7 +54,6 @@ class DibiResultIterator implements Iterator, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the key of the current element.
|
||||
* @return mixed
|
||||
@@ -71,7 +64,6 @@ class DibiResultIterator implements Iterator, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current element.
|
||||
* @return mixed
|
||||
@@ -82,7 +74,6 @@ class DibiResultIterator implements Iterator, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Moves forward to next element.
|
||||
* @return void
|
||||
@@ -94,7 +85,6 @@ class DibiResultIterator implements Iterator, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if there is a current element after calls to rewind() or next().
|
||||
* @return bool
|
||||
@@ -105,7 +95,6 @@ class DibiResultIterator implements Iterator, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Required by the Countable interface.
|
||||
* @return int
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Result set single row.
|
||||
*
|
||||
@@ -22,18 +17,18 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
|
||||
|
||||
public function __construct($arr)
|
||||
{
|
||||
foreach ($arr as $k => $v) $this->$k = $v;
|
||||
foreach ($arr as $k => $v) {
|
||||
$this->$k = $v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return (array) $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts value to DateTime object.
|
||||
* @param string key
|
||||
@@ -53,7 +48,6 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts value to UNIX timestamp.
|
||||
* @param string key
|
||||
@@ -69,7 +63,6 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts value to boolean.
|
||||
* @param string key
|
||||
@@ -82,7 +75,6 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @deprecated */
|
||||
public function asDate($key, $format = NULL)
|
||||
{
|
||||
@@ -95,46 +87,39 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* interfaces ArrayAccess, Countable & IteratorAggregate ****************d*g**/
|
||||
|
||||
|
||||
|
||||
final public function count()
|
||||
{
|
||||
return count((array) $this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
final public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
final public function offsetSet($nm, $val)
|
||||
{
|
||||
$this->$nm = $val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
final public function offsetGet($nm)
|
||||
{
|
||||
return $this->$nm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
final public function offsetExists($nm)
|
||||
{
|
||||
return isset($this->$nm);
|
||||
}
|
||||
|
||||
|
||||
|
||||
final public function offsetUnset($nm)
|
||||
{
|
||||
unset($this->$nm);
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi SQL translator.
|
||||
*
|
||||
@@ -53,14 +48,12 @@ final class DibiTranslator extends DibiObject
|
||||
private $identifiers;
|
||||
|
||||
|
||||
|
||||
public function __construct(DibiConnection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates SQL.
|
||||
* @param array
|
||||
@@ -94,8 +87,7 @@ final class DibiTranslator extends DibiObject
|
||||
|
||||
// iterate
|
||||
$sql = array();
|
||||
while ($cursor < count($this->args))
|
||||
{
|
||||
while ($cursor < count($this->args)) {
|
||||
$arg = $this->args[$cursor];
|
||||
$cursor++;
|
||||
|
||||
@@ -126,7 +118,9 @@ final class DibiTranslator extends DibiObject
|
||||
array($this, 'cb'),
|
||||
substr($arg, $toSkip)
|
||||
);
|
||||
if (preg_last_error()) throw new DibiPcreException;
|
||||
if (preg_last_error()) {
|
||||
throw new DibiPcreException;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -148,7 +142,9 @@ final class DibiTranslator extends DibiObject
|
||||
$commandIns = $commandIns === 'INSERT' || $commandIns === 'REPLAC';
|
||||
$sql[] = $this->formatValue($arg, $commandIns ? 'v' : 'a');
|
||||
} else {
|
||||
if ($lastArr === $cursor - 1) $sql[] = ',';
|
||||
if ($lastArr === $cursor - 1) {
|
||||
$sql[] = ',';
|
||||
}
|
||||
$sql[] = $this->formatValue($arg, $commandIns ? 'l' : 'a');
|
||||
}
|
||||
$lastArr = $cursor;
|
||||
@@ -161,7 +157,9 @@ final class DibiTranslator extends DibiObject
|
||||
} // while
|
||||
|
||||
|
||||
if ($comment) $sql[] = "*/";
|
||||
if ($comment) {
|
||||
$sql[] = "*/";
|
||||
}
|
||||
|
||||
$sql = implode(' ', $sql);
|
||||
|
||||
@@ -178,7 +176,6 @@ final class DibiTranslator extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Apply modifier to single value.
|
||||
* @param mixed
|
||||
@@ -199,131 +196,131 @@ final class DibiTranslator extends DibiObject
|
||||
if (is_array($value)) {
|
||||
$vx = $kx = array();
|
||||
switch ($modifier) {
|
||||
case 'and':
|
||||
case 'or': // key=val AND key IS NULL AND ...
|
||||
if (empty($value)) {
|
||||
return '1=1';
|
||||
}
|
||||
case 'and':
|
||||
case 'or': // key=val AND key IS NULL AND ...
|
||||
if (empty($value)) {
|
||||
return '1=1';
|
||||
}
|
||||
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$k = $this->identifiers->{$pair[0]} . ' ';
|
||||
if (!isset($pair[1])) {
|
||||
$v = $this->formatValue($v, FALSE);
|
||||
$vx[] = $k . ($v === 'NULL' ? 'IS ' : '= ') . $v;
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$k = $this->identifiers->{$pair[0]} . ' ';
|
||||
if (!isset($pair[1])) {
|
||||
$v = $this->formatValue($v, FALSE);
|
||||
$vx[] = $k . ($v === 'NULL' ? 'IS ' : '= ') . $v;
|
||||
|
||||
} elseif ($pair[1] === 'ex') { // TODO: this will be removed
|
||||
$vx[] = $k . $this->formatValue($v, 'ex');
|
||||
} elseif ($pair[1] === 'ex') { // TODO: this will be removed
|
||||
$vx[] = $k . $this->formatValue($v, 'ex');
|
||||
|
||||
} else {
|
||||
$v = $this->formatValue($v, $pair[1]);
|
||||
if ($pair[1] === 'l' || $pair[1] === 'in') {
|
||||
$op = 'IN ';
|
||||
} elseif (strpos($pair[1], 'like') !== FALSE) {
|
||||
$op = 'LIKE ';
|
||||
} elseif ($v === 'NULL') {
|
||||
$op = 'IS ';
|
||||
} else {
|
||||
$op = '= ';
|
||||
$v = $this->formatValue($v, $pair[1]);
|
||||
if ($pair[1] === 'l' || $pair[1] === 'in') {
|
||||
$op = 'IN ';
|
||||
} elseif (strpos($pair[1], 'like') !== FALSE) {
|
||||
$op = 'LIKE ';
|
||||
} elseif ($v === 'NULL') {
|
||||
$op = 'IS ';
|
||||
} else {
|
||||
$op = '= ';
|
||||
}
|
||||
$vx[] = $k . $op . $v;
|
||||
}
|
||||
$vx[] = $k . $op . $v;
|
||||
|
||||
} else {
|
||||
$vx[] = $this->formatValue($v, 'ex');
|
||||
}
|
||||
|
||||
} else {
|
||||
$vx[] = $this->formatValue($v, 'ex');
|
||||
}
|
||||
}
|
||||
return '(' . implode(') ' . strtoupper($modifier) . ' (', $vx) . ')';
|
||||
return '(' . implode(') ' . strtoupper($modifier) . ' (', $vx) . ')';
|
||||
|
||||
case 'n': // key, key, ... identifier names
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$vx[] = $this->identifiers->$k . (empty($v) ? '' : ' AS ' . $this->identifiers->$v);
|
||||
} else {
|
||||
$pair = explode('%', $v, 2); // split into identifier & modifier
|
||||
$vx[] = $this->identifiers->{$pair[0]};
|
||||
case 'n': // key, key, ... identifier names
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$vx[] = $this->identifiers->$k . (empty($v) ? '' : ' AS ' . $this->identifiers->$v);
|
||||
} else {
|
||||
$pair = explode('%', $v, 2); // split into identifier & modifier
|
||||
$vx[] = $this->identifiers->{$pair[0]};
|
||||
}
|
||||
}
|
||||
}
|
||||
return implode(', ', $vx);
|
||||
return implode(', ', $vx);
|
||||
|
||||
|
||||
case 'a': // key=val, key=val, ...
|
||||
foreach ($value as $k => $v) {
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$vx[] = $this->identifiers->{$pair[0]} . '='
|
||||
. $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
|
||||
}
|
||||
return implode(', ', $vx);
|
||||
case 'a': // key=val, key=val, ...
|
||||
foreach ($value as $k => $v) {
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$vx[] = $this->identifiers->{$pair[0]} . '='
|
||||
. $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
|
||||
}
|
||||
return implode(', ', $vx);
|
||||
|
||||
|
||||
case 'in':// replaces scalar %in modifier!
|
||||
case 'l': // (val, val, ...)
|
||||
foreach ($value as $k => $v) {
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
|
||||
}
|
||||
return '(' . (($vx || $modifier === 'l') ? implode(', ', $vx) : 'NULL') . ')';
|
||||
case 'in':// replaces scalar %in modifier!
|
||||
case 'l': // (val, val, ...)
|
||||
foreach ($value as $k => $v) {
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
|
||||
}
|
||||
return '(' . (($vx || $modifier === 'l') ? implode(', ', $vx) : 'NULL') . ')';
|
||||
|
||||
|
||||
case 'v': // (key, key, ...) VALUES (val, val, ...)
|
||||
foreach ($value as $k => $v) {
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$kx[] = $this->identifiers->{$pair[0]};
|
||||
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
|
||||
}
|
||||
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
|
||||
case 'v': // (key, key, ...) VALUES (val, val, ...)
|
||||
foreach ($value as $k => $v) {
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$kx[] = $this->identifiers->{$pair[0]};
|
||||
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
|
||||
}
|
||||
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
|
||||
|
||||
case 'm': // (key, key, ...) VALUES (val, val, ...), (val, val, ...), ...
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
if (isset($proto)) {
|
||||
if ($proto !== array_keys($v)) {
|
||||
$this->hasError = TRUE;
|
||||
return '**Multi-insert array "' . $k . '" is different.**';
|
||||
case 'm': // (key, key, ...) VALUES (val, val, ...), (val, val, ...), ...
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
if (isset($proto)) {
|
||||
if ($proto !== array_keys($v)) {
|
||||
$this->hasError = TRUE;
|
||||
return '**Multi-insert array "' . $k . '" is different.**';
|
||||
}
|
||||
} else {
|
||||
$proto = array_keys($v);
|
||||
}
|
||||
} else {
|
||||
$proto = array_keys($v);
|
||||
$this->hasError = TRUE;
|
||||
return '**Unexpected type ' . gettype($v) . '**';
|
||||
}
|
||||
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$kx[] = $this->identifiers->{$pair[0]};
|
||||
foreach ($v as $k2 => $v2) {
|
||||
$vx[$k2][] = $this->formatValue($v2, isset($pair[1]) ? $pair[1] : (is_array($v2) ? 'ex' : FALSE));
|
||||
}
|
||||
} else {
|
||||
$this->hasError = TRUE;
|
||||
return '**Unexpected type ' . gettype($v) . '**';
|
||||
}
|
||||
|
||||
$pair = explode('%', $k, 2); // split into identifier & modifier
|
||||
$kx[] = $this->identifiers->{$pair[0]};
|
||||
foreach ($v as $k2 => $v2) {
|
||||
$vx[$k2][] = $this->formatValue($v2, isset($pair[1]) ? $pair[1] : (is_array($v2) ? 'ex' : FALSE));
|
||||
foreach ($vx as $k => $v) {
|
||||
$vx[$k] = '(' . implode(', ', $v) . ')';
|
||||
}
|
||||
}
|
||||
foreach ($vx as $k => $v) {
|
||||
$vx[$k] = '(' . implode(', ', $v) . ')';
|
||||
}
|
||||
return '(' . implode(', ', $kx) . ') VALUES ' . implode(', ', $vx);
|
||||
return '(' . implode(', ', $kx) . ') VALUES ' . implode(', ', $vx);
|
||||
|
||||
case 'by': // key ASC, key DESC
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$vx[] = $this->formatValue($v, 'ex');
|
||||
} elseif (is_string($k)) {
|
||||
$v = (is_string($v) && strncasecmp($v, 'd', 1)) || $v > 0 ? 'ASC' : 'DESC';
|
||||
$vx[] = $this->identifiers->$k . ' ' . $v;
|
||||
} else {
|
||||
$vx[] = $this->identifiers->$v;
|
||||
case 'by': // key ASC, key DESC
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$vx[] = $this->formatValue($v, 'ex');
|
||||
} elseif (is_string($k)) {
|
||||
$v = (is_string($v) && strncasecmp($v, 'd', 1)) || $v > 0 ? 'ASC' : 'DESC';
|
||||
$vx[] = $this->identifiers->$k . ' ' . $v;
|
||||
} else {
|
||||
$vx[] = $this->identifiers->$v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return implode(', ', $vx);
|
||||
return implode(', ', $vx);
|
||||
|
||||
case 'ex':
|
||||
case 'sql':
|
||||
$translator = new self($this->connection);
|
||||
return $translator->translate($value);
|
||||
case 'ex':
|
||||
case 'sql':
|
||||
$translator = new self($this->connection);
|
||||
return $translator->translate($value);
|
||||
|
||||
default: // value, value, value - all with the same modifier
|
||||
foreach ($value as $v) {
|
||||
$vx[] = $this->formatValue($v, $modifier);
|
||||
}
|
||||
return implode(', ', $vx);
|
||||
default: // value, value, value - all with the same modifier
|
||||
foreach ($value as $v) {
|
||||
$vx[] = $this->formatValue($v, $modifier);
|
||||
}
|
||||
return implode(', ', $vx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,94 +333,98 @@ final class DibiTranslator extends DibiObject
|
||||
}
|
||||
|
||||
switch ($modifier) {
|
||||
case 's': // string
|
||||
case 'bin':// binary
|
||||
case 'b': // boolean
|
||||
return $value === NULL ? 'NULL' : $this->driver->escape($value, $modifier);
|
||||
case 's': // string
|
||||
case 'bin':// binary
|
||||
case 'b': // boolean
|
||||
return $value === NULL ? 'NULL' : $this->driver->escape($value, $modifier);
|
||||
|
||||
case 'sN': // string or NULL
|
||||
case 'sn':
|
||||
return $value == '' ? 'NULL' : $this->driver->escape($value, dibi::TEXT); // notice two equal signs
|
||||
case 'sN': // string or NULL
|
||||
case 'sn':
|
||||
return $value == '' ? 'NULL' : $this->driver->escape($value, dibi::TEXT); // notice two equal signs
|
||||
|
||||
case 'iN': // signed int or NULL
|
||||
case 'in': // deprecated
|
||||
if ($value == '') $value = NULL;
|
||||
// intentionally break omitted
|
||||
|
||||
case 'i': // signed int
|
||||
case 'u': // unsigned int, ignored
|
||||
// support for long numbers - keep them unchanged
|
||||
if (is_string($value) && preg_match('#[+-]?\d++(e\d+)?\z#A', $value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return $value === NULL ? 'NULL' : (string) (int) ($value + 0);
|
||||
}
|
||||
|
||||
case 'f': // float
|
||||
// support for extreme numbers - keep them unchanged
|
||||
if (is_string($value) && is_numeric($value) && strpos($value, 'x') === FALSE) {
|
||||
return $value; // something like -9E-005 is accepted by SQL, HEX values are not
|
||||
} else {
|
||||
return $value === NULL ? 'NULL' : rtrim(rtrim(number_format($value + 0, 10, '.', ''), '0'), '.');
|
||||
}
|
||||
|
||||
case 'd': // date
|
||||
case 't': // datetime
|
||||
if ($value === NULL) {
|
||||
return 'NULL';
|
||||
} else {
|
||||
if (is_numeric($value)) {
|
||||
$value = (int) $value; // timestamp
|
||||
|
||||
} elseif (is_string($value)) {
|
||||
$value = new DateTime($value);
|
||||
case 'iN': // signed int or NULL
|
||||
case 'in': // deprecated
|
||||
if ($value == '') {
|
||||
$value = NULL;
|
||||
}
|
||||
return $this->driver->escape($value, $modifier);
|
||||
}
|
||||
// intentionally break omitted
|
||||
|
||||
case 'by':
|
||||
case 'n': // identifier name
|
||||
return $this->identifiers->$value;
|
||||
case 'i': // signed int
|
||||
case 'u': // unsigned int, ignored
|
||||
// support for long numbers - keep them unchanged
|
||||
if (is_string($value) && preg_match('#[+-]?\d++(e\d+)?\z#A', $value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return $value === NULL ? 'NULL' : (string) (int) ($value + 0);
|
||||
}
|
||||
|
||||
case 'ex':
|
||||
case 'sql': // preserve as dibi-SQL (TODO: leave only %ex)
|
||||
$value = (string) $value;
|
||||
// speed-up - is regexp required?
|
||||
$toSkip = strcspn($value, '`[\'":');
|
||||
if (strlen($value) !== $toSkip) {
|
||||
$value = substr($value, 0, $toSkip)
|
||||
. preg_replace_callback(
|
||||
'/(?=[`[\'":])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?))/s',
|
||||
array($this, 'cb'),
|
||||
substr($value, $toSkip)
|
||||
);
|
||||
if (preg_last_error()) throw new DibiPcreException;
|
||||
}
|
||||
return $value;
|
||||
case 'f': // float
|
||||
// support for extreme numbers - keep them unchanged
|
||||
if (is_string($value) && is_numeric($value) && strpos($value, 'x') === FALSE) {
|
||||
return $value; // something like -9E-005 is accepted by SQL, HEX values are not
|
||||
} else {
|
||||
return $value === NULL ? 'NULL' : rtrim(rtrim(number_format($value + 0, 10, '.', ''), '0'), '.');
|
||||
}
|
||||
|
||||
case 'SQL': // preserve as real SQL (TODO: rename to %sql)
|
||||
return (string) $value;
|
||||
case 'd': // date
|
||||
case 't': // datetime
|
||||
if ($value === NULL) {
|
||||
return 'NULL';
|
||||
} else {
|
||||
if (is_numeric($value)) {
|
||||
$value = (int) $value; // timestamp
|
||||
|
||||
case 'like~': // LIKE string%
|
||||
return $this->driver->escapeLike($value, 1);
|
||||
} elseif (is_string($value)) {
|
||||
$value = new DateTime($value);
|
||||
}
|
||||
return $this->driver->escape($value, $modifier);
|
||||
}
|
||||
|
||||
case '~like': // LIKE %string
|
||||
return $this->driver->escapeLike($value, -1);
|
||||
case 'by':
|
||||
case 'n': // identifier name
|
||||
return $this->identifiers->$value;
|
||||
|
||||
case '~like~': // LIKE %string%
|
||||
return $this->driver->escapeLike($value, 0);
|
||||
case 'ex':
|
||||
case 'sql': // preserve as dibi-SQL (TODO: leave only %ex)
|
||||
$value = (string) $value;
|
||||
// speed-up - is regexp required?
|
||||
$toSkip = strcspn($value, '`[\'":');
|
||||
if (strlen($value) !== $toSkip) {
|
||||
$value = substr($value, 0, $toSkip)
|
||||
. preg_replace_callback(
|
||||
'/(?=[`[\'":])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?))/s',
|
||||
array($this, 'cb'),
|
||||
substr($value, $toSkip)
|
||||
);
|
||||
if (preg_last_error()) {
|
||||
throw new DibiPcreException;
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
|
||||
case 'and':
|
||||
case 'or':
|
||||
case 'a':
|
||||
case 'l':
|
||||
case 'v':
|
||||
$this->hasError = TRUE;
|
||||
return '**Unexpected type ' . gettype($value) . '**';
|
||||
case 'SQL': // preserve as real SQL (TODO: rename to %sql)
|
||||
return (string) $value;
|
||||
|
||||
default:
|
||||
$this->hasError = TRUE;
|
||||
return "**Unknown or invalid modifier %$modifier**";
|
||||
case 'like~': // LIKE string%
|
||||
return $this->driver->escapeLike($value, 1);
|
||||
|
||||
case '~like': // LIKE %string
|
||||
return $this->driver->escapeLike($value, -1);
|
||||
|
||||
case '~like~': // LIKE %string%
|
||||
return $this->driver->escapeLike($value, 0);
|
||||
|
||||
case 'and':
|
||||
case 'or':
|
||||
case 'a':
|
||||
case 'l':
|
||||
case 'v':
|
||||
$this->hasError = TRUE;
|
||||
return '**Unexpected type ' . gettype($value) . '**';
|
||||
|
||||
default:
|
||||
$this->hasError = TRUE;
|
||||
return "**Unknown or invalid modifier %$modifier**";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,7 +458,6 @@ final class DibiTranslator extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* PREG callback from translate() or formatValue().
|
||||
* @param array
|
||||
@@ -536,12 +536,16 @@ final class DibiTranslator extends DibiObject
|
||||
return '';
|
||||
|
||||
} elseif ($mod === 'lmt') { // apply limit
|
||||
if ($this->args[$cursor] !== NULL) $this->limit = (int) $this->args[$cursor];
|
||||
if ($this->args[$cursor] !== NULL) {
|
||||
$this->limit = (int) $this->args[$cursor];
|
||||
}
|
||||
$cursor++;
|
||||
return '';
|
||||
|
||||
} elseif ($mod === 'ofs') { // apply offset
|
||||
if ($this->args[$cursor] !== NULL) $this->offset = (int) $this->args[$cursor];
|
||||
if ($this->args[$cursor] !== NULL) {
|
||||
$this->offset = (int) $this->args[$cursor];
|
||||
}
|
||||
$cursor++;
|
||||
return '';
|
||||
|
||||
@@ -551,21 +555,23 @@ final class DibiTranslator extends DibiObject
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->comment) return '...';
|
||||
if ($this->comment) {
|
||||
return '...';
|
||||
}
|
||||
|
||||
if ($matches[1]) // SQL identifiers: `ident`
|
||||
if ($matches[1]) { // SQL identifiers: `ident`
|
||||
return $this->identifiers->{$matches[1]};
|
||||
|
||||
if ($matches[2]) // SQL identifiers: [ident]
|
||||
} elseif ($matches[2]) { // SQL identifiers: [ident]
|
||||
return $this->identifiers->{$matches[2]};
|
||||
|
||||
if ($matches[3]) // SQL strings: '...'
|
||||
} elseif ($matches[3]) { // SQL strings: '...'
|
||||
return $this->driver->escape( str_replace("''", "'", $matches[4]), dibi::TEXT);
|
||||
|
||||
if ($matches[5]) // SQL strings: "..."
|
||||
} elseif ($matches[5]) { // SQL strings: "..."
|
||||
return $this->driver->escape( str_replace('""', '"', $matches[6]), dibi::TEXT);
|
||||
|
||||
if ($matches[7]) { // string quote
|
||||
} elseif ($matches[7]) { // string quote
|
||||
$this->hasError = TRUE;
|
||||
return '**Alone quote**';
|
||||
}
|
||||
@@ -580,7 +586,6 @@ final class DibiTranslator extends DibiObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Apply substitutions to indentifier and delimites it.
|
||||
* @param string indentifier
|
||||
@@ -592,7 +597,9 @@ final class DibiTranslator extends DibiObject
|
||||
$value = $this->connection->substitute($value);
|
||||
$parts = explode('.', $value);
|
||||
foreach ($parts as & $v) {
|
||||
if ($v !== '*') $v = $this->driver->escape($v, dibi::IDENTIFIER);
|
||||
if ($v !== '*') {
|
||||
$v = $this->driver->escape($v, dibi::IDENTIFIER);
|
||||
}
|
||||
}
|
||||
return implode('.', $parts);
|
||||
}
|
||||
|
@@ -2,15 +2,10 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provides an interface between a dataset and data-aware components.
|
||||
* @package dibi
|
||||
@@ -22,7 +17,6 @@ interface IDataSource extends Countable, IteratorAggregate
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi driver interface.
|
||||
* @package dibi
|
||||
@@ -36,7 +30,7 @@ interface IDibiDriver
|
||||
* @return void
|
||||
* @throws DibiException
|
||||
*/
|
||||
function connect(array &$config);
|
||||
function connect(array & $config);
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
@@ -120,19 +114,13 @@ interface IDibiDriver
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string &$sql The SQL query that will be modified.
|
||||
* @param int $limit
|
||||
* @param int $offset
|
||||
* @return void
|
||||
*/
|
||||
function applyLimit(&$sql, $limit, $offset);
|
||||
function applyLimit(& $sql, $limit, $offset);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi result set driver interface.
|
||||
* @package dibi
|
||||
@@ -193,9 +181,6 @@ interface IDibiResultDriver
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dibi driver reflection.
|
||||
*
|
||||
|
Reference in New Issue
Block a user