diff --git a/dibi/dibi.php b/dibi/dibi.php
index 7907b58b..bea673b5 100644
--- a/dibi/dibi.php
+++ b/dibi/dibi.php
@@ -33,11 +33,12 @@ if (version_compare(PHP_VERSION , '5.1.0', '<')) {
// libraries
require_once __FILE__ . '/../libs/NObject.php';
-require_once __FILE__ . '/../libs/driver.php';
-require_once __FILE__ . '/../libs/resultset.php';
-require_once __FILE__ . '/../libs/translator.php';
-require_once __FILE__ . '/../libs/exception.php';
-require_once __FILE__ . '/../libs/logger.php';
+require_once __FILE__ . '/../libs/DibiException.php';
+require_once __FILE__ . '/../libs/DibiDriver.php';
+require_once __FILE__ . '/../libs/DibiResult.php';
+require_once __FILE__ . '/../libs/DibiResultIterator.php';
+require_once __FILE__ . '/../libs/DibiTranslator.php';
+require_once __FILE__ . '/../libs/DibiLogger.php';
diff --git a/dibi/drivers/mssql.php b/dibi/drivers/mssql.php
index 1fc1cd1d..6600ee74 100644
--- a/dibi/drivers/mssql.php
+++ b/dibi/drivers/mssql.php
@@ -27,6 +27,10 @@
*/
class DibiMsSqlDriver extends DibiDriver
{
+ /**
+ * Describes how convert some datatypes to SQL command
+ * @var array
+ */
public $formats = array(
'TRUE' => "-1",
'FALSE' => "0",
@@ -36,18 +40,27 @@ class DibiMsSqlDriver extends DibiDriver
/**
+ * Creates object and (optionally) connects to a database
+ *
* @param array connect configuration
+ * @throws DibiException
*/
- public function __construct($config)
+ public function __construct(array $config)
{
- self::prepare($config, 'username', 'user');
- self::prepare($config, 'password', 'pass');
- self::prepare($config, 'host');
+ self::config($config, 'username', 'user');
+ self::config($config, 'password', 'pass');
+ self::config($config, 'host');
parent::__construct($config);
}
+ /**
+ * Connects to a database
+ *
+ * @throws DibiException
+ * @return resource
+ */
protected function connect()
{
if (!extension_loaded('mssql')) {
@@ -76,6 +89,13 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Internal: Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiDatabaseException
+ */
protected function doQuery($sql)
{
$res = @mssql_query($sql, $this->getConnection());
@@ -89,6 +109,11 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
+ *
+ * @return int number of rows or FALSE on error
+ */
public function affectedRows()
{
$rows = mssql_rows_affected($this->getConnection());
@@ -97,6 +122,11 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
+ *
+ * @return int|FALSE int on success or FALSE on failure
+ */
public function insertId()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -104,6 +134,10 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Begins a transaction (if supported).
+ * @return void
+ */
public function begin()
{
$this->doQuery('BEGIN TRANSACTION');
@@ -112,6 +146,10 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Commits statements in a transaction.
+ * @return void
+ */
public function commit()
{
$this->doQuery('COMMIT');
@@ -120,6 +158,10 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Rollback changes in a transaction.
+ * @return void
+ */
public function rollback()
{
$this->doQuery('ROLLBACK');
@@ -128,6 +170,11 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Returns last error
+ *
+ * @return array with items 'message' and 'code'
+ */
public function errorInfo()
{
return array(
@@ -138,6 +185,13 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Escapes the string
+ *
+ * @param string unescaped string
+ * @param bool quote string?
+ * @return string escaped and optionally quoted string
+ */
public function escape($value, $appendQuotes = TRUE)
{
$value = str_replace("'", "''", $value);
@@ -148,6 +202,12 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Delimites identifier (table's or column's name, etc.)
+ *
+ * @param string identifier
+ * @return string delimited identifier
+ */
public function delimite($value)
{
return '[' . str_replace('.', '].[', $value) . ']';
@@ -155,6 +215,11 @@ class DibiMsSqlDriver extends DibiDriver
+ /**
+ * Gets a information of the current database.
+ *
+ * @return DibiMetaData
+ */
public function getMetaData()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -163,7 +228,12 @@ class DibiMsSqlDriver extends DibiDriver
/**
- * @see DibiDriver::applyLimit()
+ * 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
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
@@ -191,6 +261,11 @@ class DibiMsSqlDriver extends DibiDriver
class DibiMSSqlResult extends DibiResult
{
+ /**
+ * Returns the number of rows in a result set
+ *
+ * @return int
+ */
public function rowCount()
{
return mssql_num_rows($this->resource);
@@ -198,6 +273,12 @@ class DibiMSSqlResult extends DibiResult
+ /**
+ * Fetches the row at current position and moves the internal cursor to the next position
+ * internal usage only
+ *
+ * @return array|FALSE array on success, FALSE if no next record
+ */
protected function doFetch()
{
return mssql_fetch_assoc($this->resource);
@@ -205,6 +286,12 @@ class DibiMSSqlResult extends DibiResult
+ /**
+ * Moves cursor position without fetching row
+ *
+ * @param int the 0-based cursor pos to seek to
+ * @return boolean TRUE on success, FALSE if unable to seek to specified record
+ */
public function seek($row)
{
return mssql_data_seek($this->resource, $row);
@@ -212,6 +299,11 @@ class DibiMSSqlResult extends DibiResult
+ /**
+ * Frees the resources allocated for this result set
+ *
+ * @return void
+ */
protected function free()
{
mssql_free_result($this->resource);
diff --git a/dibi/drivers/mysql.php b/dibi/drivers/mysql.php
index a1ae88be..2e419982 100644
--- a/dibi/drivers/mysql.php
+++ b/dibi/drivers/mysql.php
@@ -27,6 +27,10 @@
*/
class DibiMySqlDriver extends DibiDriver
{
+ /**
+ * Describes how convert some datatypes to SQL command
+ * @var array
+ */
public $formats = array(
'TRUE' => "1",
'FALSE' => "0",
@@ -36,13 +40,15 @@ class DibiMySqlDriver extends DibiDriver
/**
+ * Creates object and (optionally) connects to a database
+ *
* @param array connect configuration
* @throws DibiException
*/
- public function __construct($config)
+ public function __construct(array $config)
{
- self::prepare($config, 'username', 'user');
- self::prepare($config, 'password', 'pass');
+ self::config($config, 'username', 'user');
+ self::config($config, 'password', 'pass');
// default values
if ($config['username'] === NULL) $config['username'] = ini_get('mysql.default_user');
@@ -58,6 +64,12 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Connects to a database
+ *
+ * @throws DibiException
+ * @return resource
+ */
protected function connect()
{
if (!extension_loaded('mysql')) {
@@ -110,6 +122,13 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Internal: Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiDatabaseException
+ */
protected function doQuery($sql)
{
$connection = $this->getConnection();
@@ -124,6 +143,11 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
+ *
+ * @return int number of rows or FALSE on error
+ */
public function affectedRows()
{
$rows = mysql_affected_rows($this->getConnection());
@@ -132,6 +156,11 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
+ *
+ * @return int|FALSE int on success or FALSE on failure
+ */
public function insertId()
{
$id = mysql_insert_id($this->getConnection());
@@ -140,6 +169,10 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Begins a transaction (if supported).
+ * @return void
+ */
public function begin()
{
$this->doQuery('BEGIN');
@@ -148,6 +181,10 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Commits statements in a transaction.
+ * @return void
+ */
public function commit()
{
$this->doQuery('COMMIT');
@@ -156,6 +193,10 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Rollback changes in a transaction.
+ * @return void
+ */
public function rollback()
{
$this->doQuery('ROLLBACK');
@@ -164,6 +205,11 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Returns last error
+ *
+ * @return array with items 'message' and 'code'
+ */
public function errorInfo()
{
$connection = $this->getConnection();
@@ -175,6 +221,13 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Escapes the string
+ *
+ * @param string unescaped string
+ * @param bool quote string?
+ * @return string escaped and optionally quoted string
+ */
public function escape($value, $appendQuotes = TRUE)
{
$connection = $this->getConnection();
@@ -185,6 +238,12 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Delimites identifier (table's or column's name, etc.)
+ *
+ * @param string identifier
+ * @return string delimited identifier
+ */
public function delimite($value)
{
return '`' . str_replace('.', '`.`', $value) . '`';
@@ -192,6 +251,11 @@ class DibiMySqlDriver extends DibiDriver
+ /**
+ * Gets a information of the current database.
+ *
+ * @return DibiMetaData
+ */
public function getMetaData()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -200,7 +264,12 @@ class DibiMySqlDriver extends DibiDriver
/**
- * @see DibiDriver::applyLimit()
+ * 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
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
@@ -225,6 +294,11 @@ class DibiMySqlDriver extends DibiDriver
class DibiMySqlResult extends DibiResult
{
+ /**
+ * Returns the number of rows in a result set
+ *
+ * @return int
+ */
public function rowCount()
{
return mysql_num_rows($this->resource);
@@ -232,6 +306,12 @@ class DibiMySqlResult extends DibiResult
+ /**
+ * Fetches the row at current position and moves the internal cursor to the next position
+ * internal usage only
+ *
+ * @return array|FALSE array on success, FALSE if no next record
+ */
protected function doFetch()
{
return mysql_fetch_assoc($this->resource);
@@ -239,6 +319,12 @@ class DibiMySqlResult extends DibiResult
+ /**
+ * Moves cursor position without fetching row
+ *
+ * @param int the 0-based cursor pos to seek to
+ * @return boolean TRUE on success, FALSE if unable to seek to specified record
+ */
public function seek($row)
{
return mysql_data_seek($this->resource, $row);
@@ -246,6 +332,11 @@ class DibiMySqlResult extends DibiResult
+ /**
+ * Frees the resources allocated for this result set
+ *
+ * @return void
+ */
protected function free()
{
mysql_free_result($this->resource);
diff --git a/dibi/drivers/mysqli.php b/dibi/drivers/mysqli.php
index 67446593..92cf9386 100644
--- a/dibi/drivers/mysqli.php
+++ b/dibi/drivers/mysqli.php
@@ -27,6 +27,10 @@
*/
class DibiMySqliDriver extends DibiDriver
{
+ /**
+ * Describes how convert some datatypes to SQL command
+ * @var array
+ */
public $formats = array(
'TRUE' => "1",
'FALSE' => "0",
@@ -35,16 +39,17 @@ class DibiMySqliDriver extends DibiDriver
);
-
/**
+ * Creates object and (optionally) connects to a database
+ *
* @param array connect configuration
* @throws DibiException
*/
- public function __construct($config)
+ public function __construct(array $config)
{
- self::prepare($config, 'username', 'user');
- self::prepare($config, 'password', 'pass');
- self::prepare($config, 'database');
+ self::config($config, 'username', 'user');
+ self::config($config, 'password', 'pass');
+ self::config($config, 'database');
// default values
if ($config['username'] === NULL) $config['username'] = ini_get('mysqli.default_user');
@@ -60,6 +65,12 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Connects to a database
+ *
+ * @throws DibiException
+ * @return resource
+ */
protected function connect()
{
if (!extension_loaded('mysqli')) {
@@ -84,6 +95,13 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Internal: Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiDatabaseException
+ */
protected function doQuery($sql)
{
$connection = $this->getConnection();
@@ -98,6 +116,11 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
+ *
+ * @return int number of rows or FALSE on error
+ */
public function affectedRows()
{
$rows = mysqli_affected_rows($this->getConnection());
@@ -106,6 +129,11 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
+ *
+ * @return int|FALSE int on success or FALSE on failure
+ */
public function insertId()
{
$id = mysqli_insert_id($this->getConnection());
@@ -114,6 +142,10 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Begins a transaction (if supported).
+ * @return void
+ */
public function begin()
{
$connection = $this->getConnection();
@@ -125,6 +157,10 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Commits statements in a transaction.
+ * @return void
+ */
public function commit()
{
$connection = $this->getConnection();
@@ -137,6 +173,10 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Rollback changes in a transaction.
+ * @return void
+ */
public function rollback()
{
$connection = $this->getConnection();
@@ -149,6 +189,11 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Returns last error
+ *
+ * @return array with items 'message' and 'code'
+ */
public function errorInfo()
{
$connection = $this->getConnection();
@@ -160,6 +205,13 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Escapes the string
+ *
+ * @param string unescaped string
+ * @param bool quote string?
+ * @return string escaped and optionally quoted string
+ */
public function escape($value, $appendQuotes = TRUE)
{
$connection = $this->getConnection();
@@ -170,6 +222,12 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Delimites identifier (table's or column's name, etc.)
+ *
+ * @param string identifier
+ * @return string delimited identifier
+ */
public function delimite($value)
{
return '`' . str_replace('.', '`.`', $value) . '`';
@@ -177,6 +235,11 @@ class DibiMySqliDriver extends DibiDriver
+ /**
+ * Gets a information of the current database.
+ *
+ * @return DibiMetaData
+ */
public function getMetaData()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -185,7 +248,12 @@ class DibiMySqliDriver extends DibiDriver
/**
- * @see DibiDriver::applyLimit()
+ * 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
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
@@ -210,6 +278,11 @@ class DibiMySqliDriver extends DibiDriver
class DibiMySqliResult extends DibiResult
{
+ /**
+ * Returns the number of rows in a result set
+ *
+ * @return int
+ */
public function rowCount()
{
return mysqli_num_rows($this->resource);
@@ -217,6 +290,12 @@ class DibiMySqliResult extends DibiResult
+ /**
+ * Fetches the row at current position and moves the internal cursor to the next position
+ * internal usage only
+ *
+ * @return array|FALSE array on success, FALSE if no next record
+ */
protected function doFetch()
{
return mysqli_fetch_assoc($this->resource);
@@ -224,6 +303,12 @@ class DibiMySqliResult extends DibiResult
+ /**
+ * Moves cursor position without fetching row
+ *
+ * @param int the 0-based cursor pos to seek to
+ * @return boolean TRUE on success, FALSE if unable to seek to specified record
+ */
public function seek($row)
{
return mysqli_data_seek($this->resource, $row);
@@ -231,6 +316,11 @@ class DibiMySqliResult extends DibiResult
+ /**
+ * Frees the resources allocated for this result set
+ *
+ * @return void
+ */
protected function free()
{
mysqli_free_result($this->resource);
diff --git a/dibi/drivers/odbc.php b/dibi/drivers/odbc.php
index 1cd4be84..ce629f04 100644
--- a/dibi/drivers/odbc.php
+++ b/dibi/drivers/odbc.php
@@ -27,6 +27,10 @@
*/
class DibiOdbcDriver extends DibiDriver
{
+ /**
+ * Describes how convert some datatypes to SQL command
+ * @var array
+ */
public $formats = array(
'TRUE' => "-1",
'FALSE' => "0",
@@ -43,14 +47,16 @@ class DibiOdbcDriver extends DibiDriver
/**
+ * Creates object and (optionally) connects to a database
+ *
* @param array connect configuration
* @throws DibiException
*/
- public function __construct($config)
+ public function __construct(array $config)
{
- self::prepare($config, 'username', 'user');
- self::prepare($config, 'password', 'pass');
- self::prepare($config, 'database');
+ self::config($config, 'username', 'user');
+ self::config($config, 'password', 'pass');
+ self::config($config, 'database');
// default values
if ($config['username'] === NULL) $config['username'] = ini_get('odbc.default_user');
@@ -62,6 +68,12 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Connects to a database
+ *
+ * @throws DibiException
+ * @return resource
+ */
protected function connect()
{
if (!extension_loaded('odbc')) {
@@ -86,6 +98,13 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiException
+ */
public function nativeQuery($sql)
{
$this->affectedRows = FALSE;
@@ -99,6 +118,13 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Internal: Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiDatabaseException
+ */
protected function doQuery($sql)
{
$connection = $this->getConnection();
@@ -113,6 +139,11 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
+ *
+ * @return int number of rows or FALSE on error
+ */
public function affectedRows()
{
return $this->affectedRows;
@@ -120,6 +151,11 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
+ *
+ * @return int|FALSE int on success or FALSE on failure
+ */
public function insertId()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -127,6 +163,10 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Begins a transaction (if supported).
+ * @return void
+ */
public function begin()
{
$connection = $this->getConnection();
@@ -138,6 +178,10 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Commits statements in a transaction.
+ * @return void
+ */
public function commit()
{
$connection = $this->getConnection();
@@ -150,6 +194,10 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Rollback changes in a transaction.
+ * @return void
+ */
public function rollback()
{
$connection = $this->getConnection();
@@ -162,6 +210,11 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Returns last error
+ *
+ * @return array with items 'message' and 'code'
+ */
public function errorInfo()
{
$connection = $this->getConnection();
@@ -173,6 +226,13 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Escapes the string
+ *
+ * @param string unescaped string
+ * @param bool quote string?
+ * @return string escaped and optionally quoted string
+ */
public function escape($value, $appendQuotes = TRUE)
{
$value = str_replace("'", "''", $value);
@@ -183,6 +243,12 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Delimites identifier (table's or column's name, etc.)
+ *
+ * @param string identifier
+ * @return string delimited identifier
+ */
public function delimite($value)
{
return '[' . str_replace('.', '].[', $value) . ']';
@@ -190,6 +256,11 @@ class DibiOdbcDriver extends DibiDriver
+ /**
+ * Gets a information of the current database.
+ *
+ * @return DibiMetaData
+ */
public function getMetaData()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -198,7 +269,12 @@ class DibiOdbcDriver extends DibiDriver
/**
- * @see DibiDriver::applyLimit()
+ * 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
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
@@ -225,6 +301,11 @@ class DibiOdbcResult extends DibiResult
+ /**
+ * Returns the number of rows in a result set
+ *
+ * @return int
+ */
public function rowCount()
{
// will return -1 with many drivers :-(
@@ -233,6 +314,12 @@ class DibiOdbcResult extends DibiResult
+ /**
+ * Fetches the row at current position and moves the internal cursor to the next position
+ * internal usage only
+ *
+ * @return array|FALSE array on success, FALSE if no next record
+ */
protected function doFetch()
{
return odbc_fetch_array($this->resource, $this->row++);
@@ -240,6 +327,12 @@ class DibiOdbcResult extends DibiResult
+ /**
+ * Moves cursor position without fetching row
+ *
+ * @param int the 0-based cursor pos to seek to
+ * @return boolean TRUE on success, FALSE if unable to seek to specified record
+ */
public function seek($row)
{
$this->row = $row;
@@ -247,6 +340,11 @@ class DibiOdbcResult extends DibiResult
+ /**
+ * Frees the resources allocated for this result set
+ *
+ * @return void
+ */
protected function free()
{
odbc_free_result($this->resource);
diff --git a/dibi/drivers/oracle.php b/dibi/drivers/oracle.php
index 127fdfd4..6d21a6fe 100644
--- a/dibi/drivers/oracle.php
+++ b/dibi/drivers/oracle.php
@@ -27,6 +27,10 @@
*/
class DibiOracleDriver extends DibiDriver
{
+ /**
+ * Describes how convert some datatypes to SQL command
+ * @var array
+ */
public $formats = array(
'TRUE' => "1",
'FALSE' => "0",
@@ -39,20 +43,28 @@ class DibiOracleDriver extends DibiDriver
/**
+ * Creates object and (optionally) connects to a database
+ *
* @param array connect configuration
* @throws DibiException
*/
- public function __construct($config)
+ public function __construct(array $config)
{
- self::prepare($config, 'username', 'user');
- self::prepare($config, 'password', 'pass');
- self::prepare($config, 'database', 'db');
- self::prepare($config, 'charset');
+ self::config($config, 'username', 'user');
+ self::config($config, 'password', 'pass');
+ self::config($config, 'database', 'db');
+ self::config($config, 'charset');
parent::__construct($config);
}
+ /**
+ * Connects to a database
+ *
+ * @throws DibiException
+ * @return resource
+ */
protected function connect()
{
if (!extension_loaded('oci8')) {
@@ -73,6 +85,13 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Internal: Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiDatabaseException
+ */
protected function doQuery($sql)
{
$connection = $this->getConnection();
@@ -95,6 +114,11 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
+ *
+ * @return int number of rows or FALSE on error
+ */
public function affectedRows()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -102,6 +126,11 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
+ *
+ * @return int|FALSE int on success or FALSE on failure
+ */
public function insertId()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -109,6 +138,10 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Begins a transaction (if supported).
+ * @return void
+ */
public function begin()
{
$this->autocommit = FALSE;
@@ -116,6 +149,10 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Commits statements in a transaction.
+ * @return void
+ */
public function commit()
{
$connection = $this->getConnection();
@@ -129,6 +166,10 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Rollback changes in a transaction.
+ * @return void
+ */
public function rollback()
{
$connection = $this->getConnection();
@@ -142,6 +183,11 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Returns last error
+ *
+ * @return array with items 'message' and 'code'
+ */
public function errorInfo()
{
return oci_error($this->getConnection());
@@ -149,6 +195,13 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Escapes the string
+ *
+ * @param string unescaped string
+ * @param bool quote string?
+ * @return string escaped and optionally quoted string
+ */
public function escape($value, $appendQuotes = TRUE)
{
return $appendQuotes
@@ -158,6 +211,12 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Delimites identifier (table's or column's name, etc.)
+ *
+ * @param string identifier
+ * @return string delimited identifier
+ */
public function delimite($value)
{
return '[' . str_replace('.', '].[', $value) . ']';
@@ -165,6 +224,11 @@ class DibiOracleDriver extends DibiDriver
+ /**
+ * Gets a information of the current database.
+ *
+ * @return DibiMetaData
+ */
public function getMetaData()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -173,7 +237,12 @@ class DibiOracleDriver extends DibiDriver
/**
- * @see DibiDriver::applyLimit()
+ * 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
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
@@ -194,6 +263,11 @@ class DibiOracleDriver extends DibiDriver
class DibiOracleResult extends DibiResult
{
+ /**
+ * Returns the number of rows in a result set
+ *
+ * @return int
+ */
public function rowCount()
{
return oci_num_rows($this->resource);
@@ -201,6 +275,12 @@ class DibiOracleResult extends DibiResult
+ /**
+ * Fetches the row at current position and moves the internal cursor to the next position
+ * internal usage only
+ *
+ * @return array|FALSE array on success, FALSE if no next record
+ */
protected function doFetch()
{
return oci_fetch_assoc($this->resource);
@@ -208,6 +288,12 @@ class DibiOracleResult extends DibiResult
+ /**
+ * Moves cursor position without fetching row
+ *
+ * @param int the 0-based cursor pos to seek to
+ * @return boolean TRUE on success, FALSE if unable to seek to specified record
+ */
public function seek($row)
{
//throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -215,6 +301,11 @@ class DibiOracleResult extends DibiResult
+ /**
+ * Frees the resources allocated for this result set
+ *
+ * @return void
+ */
protected function free()
{
oci_free_statement($this->resource);
diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php
index 2a1b9f33..59cb5fd5 100644
--- a/dibi/drivers/pdo.php
+++ b/dibi/drivers/pdo.php
@@ -27,6 +27,10 @@
*/
class DibiPdoDriver extends DibiDriver
{
+ /**
+ * Describes how convert some datatypes to SQL command
+ * @var array
+ */
public $formats = array(
'TRUE' => "1",
'FALSE' => "0",
@@ -35,21 +39,28 @@ class DibiPdoDriver extends DibiDriver
);
-
/**
+ * Creates object and (optionally) connects to a database
+ *
* @param array connect configuration
* @throws DibiException
*/
- public function __construct($config)
+ public function __construct(array $config)
{
- self::prepare($config, 'username', 'user');
- self::prepare($config, 'password', 'pass');
- self::prepare($config, 'dsn');
+ self::config($config, 'username', 'user');
+ self::config($config, 'password', 'pass');
+ self::config($config, 'dsn');
parent::__construct($config);
}
+ /**
+ * Connects to a database
+ *
+ * @throws DibiException
+ * @return resource
+ */
protected function connect()
{
if (!extension_loaded('pdo')) {
@@ -66,6 +77,13 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Internal: Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiDatabaseException
+ */
protected function doQuery($sql)
{
$res = $this->getConnection()->query($sql);
@@ -74,6 +92,11 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
+ *
+ * @return int number of rows or FALSE on error
+ */
public function affectedRows()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -81,6 +104,11 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
+ *
+ * @return int|FALSE int on success or FALSE on failure
+ */
public function insertId()
{
return $this->getConnection()->lastInsertId();
@@ -88,6 +116,10 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Begins a transaction (if supported).
+ * @return void
+ */
public function begin()
{
$this->getConnection()->beginTransaction();
@@ -96,6 +128,10 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Commits statements in a transaction.
+ * @return void
+ */
public function commit()
{
$this->getConnection()->commit();
@@ -104,6 +140,10 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Rollback changes in a transaction.
+ * @return void
+ */
public function rollback()
{
$this->getConnection()->rollBack();
@@ -112,6 +152,11 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Returns last error
+ *
+ * @return array with items 'message' and 'code'
+ */
public function errorInfo()
{
$error = $this->getConnection()->errorInfo();
@@ -124,6 +169,13 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Escapes the string
+ *
+ * @param string unescaped string
+ * @param bool quote string?
+ * @return string escaped and optionally quoted string
+ */
public function escape($value, $appendQuotes = TRUE)
{
if (!$appendQuotes) {
@@ -134,6 +186,12 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Delimites identifier (table's or column's name, etc.)
+ *
+ * @param string identifier
+ * @return string delimited identifier
+ */
public function delimite($value)
{
// quoting is not supported by PDO
@@ -142,6 +200,11 @@ class DibiPdoDriver extends DibiDriver
+ /**
+ * Gets a information of the current database.
+ *
+ * @return DibiMetaData
+ */
public function getMetaData()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -150,7 +213,12 @@ class DibiPdoDriver extends DibiDriver
/**
- * @see DibiDriver::applyLimit()
+ * 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
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
@@ -172,6 +240,11 @@ class DibiPdoResult extends DibiResult
private $row = 0;
+ /**
+ * Returns the number of rows in a result set
+ *
+ * @return int
+ */
public function rowCount()
{
return $this->resource->rowCount();
@@ -179,6 +252,12 @@ class DibiPdoResult extends DibiResult
+ /**
+ * Fetches the row at current position and moves the internal cursor to the next position
+ * internal usage only
+ *
+ * @return array|FALSE array on success, FALSE if no next record
+ */
protected function doFetch()
{
return $this->resource->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT, $this->row++);
@@ -186,6 +265,12 @@ class DibiPdoResult extends DibiResult
+ /**
+ * Moves cursor position without fetching row
+ *
+ * @param int the 0-based cursor pos to seek to
+ * @return boolean TRUE on success, FALSE if unable to seek to specified record
+ */
public function seek($row)
{
$this->row = $row;
@@ -193,6 +278,11 @@ class DibiPdoResult extends DibiResult
+ /**
+ * Frees the resources allocated for this result set
+ *
+ * @return void
+ */
protected function free()
{
}
diff --git a/dibi/drivers/postgre.php b/dibi/drivers/postgre.php
index b6463111..6d4c7702 100644
--- a/dibi/drivers/postgre.php
+++ b/dibi/drivers/postgre.php
@@ -27,6 +27,10 @@
*/
class DibiPostgreDriver extends DibiDriver
{
+ /**
+ * Describes how convert some datatypes to SQL command
+ * @var array
+ */
public $formats = array(
'TRUE' => "TRUE",
'FALSE' => "FALSE",
@@ -43,18 +47,26 @@ class DibiPostgreDriver extends DibiDriver
/**
+ * Creates object and (optionally) connects to a database
+ *
* @param array connect configuration
* @throws DibiException
*/
- public function __construct($config)
+ public function __construct(array $config)
{
- self::prepare($config, 'database', 'string');
- self::prepare($config, 'type');
+ self::config($config, 'database', 'string');
+ self::config($config, 'type');
parent::__construct($config);
}
+ /**
+ * Connects to a database
+ *
+ * @throws DibiException
+ * @return resource
+ */
protected function connect()
{
if (!extension_loaded('pgsql')) {
@@ -63,14 +75,25 @@ class DibiPostgreDriver extends DibiDriver
$config = $this->getConfig();
+ // some errors aren't handled. Must use $php_errormsg
+ if (function_exists('ini_set')) {
+ $save = ini_set('track_errors', TRUE);
+ }
+
+ $php_errormsg = '';
+
if (isset($config['persistent'])) {
$connection = @pg_connect($config['database'], $config['type']);
} else {
$connection = @pg_pconnect($config['database'], $config['type']);
}
+ if (function_exists('ini_set')) {
+ ini_set('track_errors', $save);
+ }
+
if (!is_resource($connection)) {
- throw new DibiDatabaseException(pg_last_error());
+ throw new DibiDatabaseException($php_errormsg);
}
if (isset($config['charset'])) {
@@ -84,6 +107,13 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiException
+ */
public function nativeQuery($sql)
{
$this->affectedRows = FALSE;
@@ -97,6 +127,13 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Internal: Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiDatabaseException
+ */
protected function doQuery($sql)
{
$connection = $this->getConnection();
@@ -111,6 +148,11 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
+ *
+ * @return int number of rows or FALSE on error
+ */
public function affectedRows()
{
return $this->affectedRows;
@@ -118,6 +160,11 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
+ *
+ * @return int|FALSE int on success or FALSE on failure
+ */
public function insertId($sequence = NULL)
{
if ($sequence === NULL) {
@@ -138,6 +185,10 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Begins a transaction (if supported).
+ * @return void
+ */
public function begin()
{
$this->doQuery('BEGIN');
@@ -146,6 +197,10 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Commits statements in a transaction.
+ * @return void
+ */
public function commit()
{
$this->doQuery('COMMIT');
@@ -154,6 +209,10 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Rollback changes in a transaction.
+ * @return void
+ */
public function rollback()
{
$this->doQuery('ROLLBACK');
@@ -162,6 +221,11 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Returns last error
+ *
+ * @return array with items 'message' and 'code'
+ */
public function errorInfo()
{
return array(
@@ -172,6 +236,13 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Escapes the string
+ *
+ * @param string unescaped string
+ * @param bool quote string?
+ * @return string escaped and optionally quoted string
+ */
public function escape($value, $appendQuotes = TRUE)
{
return $appendQuotes
@@ -181,6 +252,12 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Delimites identifier (table's or column's name, etc.)
+ *
+ * @param string identifier
+ * @return string delimited identifier
+ */
public function delimite($value)
{
$value = str_replace('"', '""', $value);
@@ -189,6 +266,11 @@ class DibiPostgreDriver extends DibiDriver
+ /**
+ * Gets a information of the current database.
+ *
+ * @return DibiMetaData
+ */
public function getMetaData()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -197,7 +279,12 @@ class DibiPostgreDriver extends DibiDriver
/**
- * @see DibiDriver::applyLimit()
+ * 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
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
@@ -222,6 +309,11 @@ class DibiPostgreDriver extends DibiDriver
class DibiPostgreResult extends DibiResult
{
+ /**
+ * Returns the number of rows in a result set
+ *
+ * @return int
+ */
public function rowCount()
{
return pg_num_rows($this->resource);
@@ -229,6 +321,12 @@ class DibiPostgreResult extends DibiResult
+ /**
+ * Fetches the row at current position and moves the internal cursor to the next position
+ * internal usage only
+ *
+ * @return array|FALSE array on success, FALSE if no next record
+ */
protected function doFetch()
{
return pg_fetch_array($this->resource, NULL, PGSQL_ASSOC);
@@ -236,6 +334,12 @@ class DibiPostgreResult extends DibiResult
+ /**
+ * Moves cursor position without fetching row
+ *
+ * @param int the 0-based cursor pos to seek to
+ * @return boolean TRUE on success, FALSE if unable to seek to specified record
+ */
public function seek($row)
{
return pg_result_seek($this->resource, $row);
@@ -243,6 +347,11 @@ class DibiPostgreResult extends DibiResult
+ /**
+ * Frees the resources allocated for this result set
+ *
+ * @return void
+ */
protected function free()
{
pg_free_result($this->resource);
diff --git a/dibi/drivers/sqlite.php b/dibi/drivers/sqlite.php
index 37646b22..c092ebd1 100644
--- a/dibi/drivers/sqlite.php
+++ b/dibi/drivers/sqlite.php
@@ -27,6 +27,10 @@
*/
class DibiSqliteDriver extends DibiDriver
{
+ /**
+ * Describes how convert some datatypes to SQL command
+ * @var array
+ */
public $formats = array(
'TRUE' => "1",
'FALSE' => "0",
@@ -35,20 +39,27 @@ class DibiSqliteDriver extends DibiDriver
);
-
/**
+ * Creates object and (optionally) connects to a database
+ *
* @param array connect configuration
* @throws DibiException
*/
public function __construct($config)
{
- self::prepare($config, 'database', 'file');
+ self::config($config, 'database', 'file');
if (!isset($config['mode'])) $config['mode'] = 0666;
parent::__construct($config);
}
+ /**
+ * Connects to a database
+ *
+ * @throws DibiException
+ * @return resource
+ */
protected function connect()
{
if (!extension_loaded('sqlite')) {
@@ -74,6 +85,13 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Internal: Executes the SQL query
+ *
+ * @param string SQL statement.
+ * @return DibiResult|TRUE Result set object
+ * @throws DibiDatabaseException
+ */
protected function doQuery($sql)
{
$connection = $this->getConnection();
@@ -88,6 +106,11 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query
+ *
+ * @return int number of rows or FALSE on error
+ */
public function affectedRows()
{
$rows = sqlite_changes($this->getConnection());
@@ -96,6 +119,11 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query
+ *
+ * @return int|FALSE int on success or FALSE on failure
+ */
public function insertId()
{
$id = sqlite_last_insert_rowid($this->getConnection());
@@ -104,6 +132,10 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Begins a transaction (if supported).
+ * @return void
+ */
public function begin()
{
$this->doQuery('BEGIN');
@@ -112,6 +144,10 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Commits statements in a transaction.
+ * @return void
+ */
public function commit()
{
$this->doQuery('COMMIT');
@@ -120,6 +156,10 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Rollback changes in a transaction.
+ * @return void
+ */
public function rollback()
{
$this->doQuery('ROLLBACK');
@@ -128,6 +168,11 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Returns last error
+ *
+ * @return array with items 'message' and 'code'
+ */
public function errorInfo()
{
$code = sqlite_last_error($this->getConnection());
@@ -139,6 +184,13 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Escapes the string
+ *
+ * @param string unescaped string
+ * @param bool quote string?
+ * @return string escaped and optionally quoted string
+ */
public function escape($value, $appendQuotes = TRUE)
{
return $appendQuotes
@@ -148,6 +200,12 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Delimites identifier (table's or column's name, etc.)
+ *
+ * @param string identifier
+ * @return string delimited identifier
+ */
public function delimite($value)
{
return '[' . str_replace('.', '].[', $value) . ']';
@@ -155,6 +213,11 @@ class DibiSqliteDriver extends DibiDriver
+ /**
+ * Gets a information of the current database.
+ *
+ * @return DibiMetaData
+ */
public function getMetaData()
{
throw new BadMethodCallException(__METHOD__ . ' is not implemented');
@@ -163,7 +226,12 @@ class DibiSqliteDriver extends DibiDriver
/**
- * @see DibiDriver::applyLimit()
+ * 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
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
@@ -184,6 +252,11 @@ class DibiSqliteDriver extends DibiDriver
class DibiSqliteResult extends DibiResult
{
+ /**
+ * Returns the number of rows in a result set
+ *
+ * @return int
+ */
public function rowCount()
{
return sqlite_num_rows($this->resource);
@@ -191,6 +264,12 @@ class DibiSqliteResult extends DibiResult
+ /**
+ * Fetches the row at current position and moves the internal cursor to the next position
+ * internal usage only
+ *
+ * @return array|FALSE array on success, FALSE if no next record
+ */
protected function doFetch()
{
return sqlite_fetch_array($this->resource, SQLITE_ASSOC);
@@ -198,6 +277,12 @@ class DibiSqliteResult extends DibiResult
+ /**
+ * Moves cursor position without fetching row
+ *
+ * @param int the 0-based cursor pos to seek to
+ * @return boolean TRUE on success, FALSE if unable to seek to specified record
+ */
public function seek($row)
{
return sqlite_seek($this->resource, $row);
@@ -205,6 +290,11 @@ class DibiSqliteResult extends DibiResult
+ /**
+ * Frees the resources allocated for this result set
+ *
+ * @return void
+ */
protected function free()
{
}
diff --git a/dibi/libs/driver.php b/dibi/libs/DibiDriver.php
similarity index 93%
rename from dibi/libs/driver.php
rename to dibi/libs/DibiDriver.php
index 2cfd8d20..8e08004e 100644
--- a/dibi/libs/driver.php
+++ b/dibi/libs/DibiDriver.php
@@ -59,7 +59,7 @@ abstract class DibiDriver extends NObject
* @param array connect configuration
* @throws DibiException
*/
- public function __construct($config)
+ public function __construct(array $config)
{
$this->config = $config;
@@ -183,7 +183,7 @@ abstract class DibiDriver extends NObject
* @param string alias key
* @return void
*/
- protected static function prepare(&$config, $key, $alias=NULL)
+ protected static function config(&$config, $key, $alias=NULL)
{
if (isset($config[$key])) return;
@@ -290,7 +290,7 @@ abstract class DibiDriver extends NObject
/**
- * Experimental - injects LIMIT/OFFSET to the SQL query
+ * Injects LIMIT/OFFSET to the SQL query
*
* @param string &$sql The SQL query that will be modified.
* @param int $limit
diff --git a/dibi/libs/exception.php b/dibi/libs/DibiException.php
similarity index 100%
rename from dibi/libs/exception.php
rename to dibi/libs/DibiException.php
diff --git a/dibi/libs/logger.php b/dibi/libs/DibiLogger.php
similarity index 94%
rename from dibi/libs/logger.php
rename to dibi/libs/DibiLogger.php
index 26abfb8b..d77914e9 100644
--- a/dibi/libs/logger.php
+++ b/dibi/libs/DibiLogger.php
@@ -22,7 +22,7 @@
/**
- * dibi basic logger & profiler
+ * dibi basic logger & profiler (experimental)
*
* @version $Revision$ $Date$
*/
diff --git a/dibi/libs/resultset.php b/dibi/libs/DibiResult.php
similarity index 81%
rename from dibi/libs/resultset.php
rename to dibi/libs/DibiResult.php
index 1654d701..110b13f5 100644
--- a/dibi/libs/resultset.php
+++ b/dibi/libs/DibiResult.php
@@ -26,10 +26,14 @@
*
*
* $result = dibi::query('SELECT * FROM [table]');
+ *
+ * $row = $result->fetch();
* $value = $result->fetchSingle();
- * $all = $result->fetchAll();
+ * $table = $result->fetchAll();
+ * $pairs = $result->fetchPairs();
* $assoc = $result->fetchAssoc('id');
* $assoc = $result->fetchAssoc('active', 'id');
+ *
* unset($result);
*
*
@@ -443,7 +447,7 @@ abstract class DibiResult extends NObject implements IteratorAggregate, Countabl
/**
- * Displays complete result-set as HTML table
+ * Displays complete result-set as HTML table for debug purposes
*
* @return void
*/
@@ -475,108 +479,27 @@ abstract class DibiResult extends NObject implements IteratorAggregate, Countabl
- /** these are the required IteratorAggregate functions */
- final public function getIterator($offset = NULL, $count = NULL)
+ /**
+ * Required by the IteratorAggregate interface
+ * @param int offset
+ * @param int limit
+ * @return ArrayIterator
+ */
+ final public function getIterator($offset = NULL, $limit = NULL)
{
- return new DibiResultIterator($this, $offset, $count);
+ return new DibiResultIterator($this, $offset, $limit);
}
- /** end required IteratorAggregate functions */
- /** these are the required Countable functions */
+ /**
+ * Required by the Countable interface
+ * @return int
+ */
final public function count()
{
return $this->rowCount();
}
- /** end required Countable functions */
} // class DibiResult
-
-
-
-
-
-
-
-
-/**
- * Basic Result set iterator.
- *
- * This can be returned by DibiResult::getIterator() method or directly using foreach:
- *
- * $result = dibi::query('SELECT * FROM table');
- * foreach ($result as $fields) {
- * print_r($fields);
- * }
- * unset($result);
- *
- *
- * Optionally you can specify offset and limit:
- *
- * foreach ($result->getIterator(2, 3) as $fields) {
- * print_r($fields);
- * }
- *
- */
-final class DibiResultIterator implements Iterator
-{
- private
- $result,
- $offset,
- $count,
- $row,
- $pointer;
-
-
- public function __construct(DibiResult $result, $offset = NULL, $count = NULL)
- {
- $this->result = $result;
- $this->offset = (int) $offset;
- $this->count = $count === NULL ? 2147483647 /*PHP_INT_MAX till 5.0.5 */ : (int) $count;
- }
-
-
-
- /** these are the required Iterator functions */
- public function rewind()
- {
- $this->pointer = 0;
- @$this->result->seek($this->offset);
- $this->row = $this->result->fetch();
- }
-
-
-
- public function key()
- {
- return $this->pointer;
- }
-
-
-
- public function current()
- {
- return $this->row;
- }
-
-
-
- public function next()
- {
- $this->row = $this->result->fetch();
- $this->pointer++;
- }
-
-
-
- public function valid()
- {
- return is_array($this->row) && ($this->pointer < $this->count);
- }
- /** end required Iterator functions */
-
-
-
-} // class DibiResultIterator
diff --git a/dibi/libs/DibiResultIterator.php b/dibi/libs/DibiResultIterator.php
new file mode 100644
index 00000000..598bd5d9
--- /dev/null
+++ b/dibi/libs/DibiResultIterator.php
@@ -0,0 +1,125 @@
+
+ * $result = dibi::query('SELECT * FROM table');
+ * foreach ($result as $row) {
+ * print_r($row);
+ * }
+ * unset($result);
+ *
+ *
+ * Optionally you can specify offset and limit:
+ *
+ * foreach ($result->getIterator(2, 3) as $row) {
+ * print_r($row);
+ * }
+ *
+ */
+final class DibiResultIterator implements Iterator
+{
+ private
+ $result,
+ $offset,
+ $limit,
+ $row,
+ $pointer;
+
+
+ /**
+ * Required by the Iterator interface
+ * @param int offset
+ * @param int limit
+ */
+ public function __construct(DibiResult $result, $offset, $limit)
+ {
+ $this->result = $result;
+ $this->offset = (int) $offset;
+ $this->limit = $limit === NULL ? -1 : (int) $limit;
+ }
+
+
+
+ /**
+ * Rewinds the Iterator to the first element
+ * @return void
+ */
+ public function rewind()
+ {
+ $this->pointer = 0;
+ @$this->result->seek($this->offset);
+ $this->row = $this->result->fetch();
+ }
+
+
+
+ /**
+ * Returns the key of the current element.
+ * @return mixed
+ */
+ public function key()
+ {
+ return $this->pointer;
+ }
+
+
+
+ /**
+ * Returns the current element.
+ * @return mixed
+ */
+ public function current()
+ {
+ return $this->row;
+ }
+
+
+
+ /**
+ * Moves forward to next element.
+ * @return void
+ */
+ public function next()
+ {
+ $this->row = $this->result->fetch();
+ $this->pointer++;
+ }
+
+
+
+ /**
+ * Checks if there is a current element after calls to rewind() or next().
+ * @return bool
+ */
+ public function valid()
+ {
+ return is_array($this->row) && ($this->limit < 0 || $this->pointer < $this->limit);
+ }
+
+
+
+} // class DibiResultIterator
diff --git a/dibi/libs/translator.php b/dibi/libs/DibiTranslator.php
similarity index 94%
rename from dibi/libs/translator.php
rename to dibi/libs/DibiTranslator.php
index 158ecf63..5415ac72 100644
--- a/dibi/libs/translator.php
+++ b/dibi/libs/DibiTranslator.php
@@ -22,7 +22,7 @@
/**
- * dibi translator
+ * dibi SQL translator
*
* @version $Revision$ $Date$
*/
@@ -54,7 +54,7 @@ final class DibiTranslator extends NObject
- public function __construct($driver)
+ public function __construct(DibiDriver $driver)
{
$this->driver = $driver;
}
@@ -67,7 +67,7 @@ final class DibiTranslator extends NObject
* @param array
* @return bool
*/
- public function translate($args)
+ public function translate(array $args)
{
$this->hasError = FALSE;
$commandIns = NULL;
@@ -144,6 +144,12 @@ final class DibiTranslator extends NObject
+ /**
+ * Apply modifier to single value
+ * @param mixed
+ * @param string
+ * @return string
+ */
private function formatValue($value, $modifier)
{
// array processing (with or without modifier)
@@ -412,4 +418,4 @@ final class DibiTranslator extends NObject
}
-} // class DibiParser
+} // class DibiTranslator
diff --git a/dibi/libs/NObject.php b/dibi/libs/NObject.php
index a4e14d6b..61d0cfe8 100644
--- a/dibi/libs/NObject.php
+++ b/dibi/libs/NObject.php
@@ -21,6 +21,12 @@
+/**
+ * compatiblity
+ */
+if (!class_exists('NObject', FALSE)) {
+
+
/**
* NObject is the ultimate ancestor of all instantiable classes.
*
@@ -227,3 +233,6 @@ abstract class NObject
class NPropertyException extends Exception
{
}
+
+
+}
\ No newline at end of file
diff --git a/examples/date.type.demo.php b/examples/date.type.demo.php
index cebbeeb3..2a54f8ee 100644
--- a/examples/date.type.demo.php
+++ b/examples/date.type.demo.php
@@ -60,12 +60,8 @@ class MyDateTime implements DibiVariableInterface
// CHANGE TO REAL PARAMETERS!
dibi::connect(array(
- 'driver' => 'mysql',
- 'host' => 'localhost',
- 'username' => 'root',
- 'password' => 'xxx',
- 'database' => 'dibi',
- 'charset' => 'utf8',
+ 'driver' => 'sqlite',
+ 'database' => 'sample.sdb',
));
diff --git a/examples/fetch.php b/examples/fetch.php
index 02beb202..23c99a7f 100644
--- a/examples/fetch.php
+++ b/examples/fetch.php
@@ -58,6 +58,11 @@ foreach ($res as $row => $fields) {
echo '