1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-24 10:53:17 +01:00
php-dibi/dibi/libs/interfaces.php

277 lines
5.3 KiB
PHP
Raw Normal View History

2008-07-17 03:51:29 +00:00
<?php
/**
* dibi - tiny'n'smart database abstraction layer
* ----------------------------------------------
*
2010-01-03 15:15:37 +01:00
* @copyright Copyright (c) 2005, 2010 David Grudl
2008-07-17 03:51:29 +00:00
* @license http://dibiphp.com/license dibi license
* @link http://dibiphp.com
* @package dibi
*/
/**
* Provides an interface between a dataset and data-aware components.
* @package dibi
*/
interface IDataSource extends Countable, IteratorAggregate
{
2009-02-05 23:13:29 +00:00
//function IteratorAggregate::getIterator();
//function Countable::count();
}
/**
* Defines method that must profiler implement.
* @package dibi
*/
interface IDibiProfiler
{
/**#@+ event type */
const CONNECT = 1;
const SELECT = 4;
const INSERT = 8;
const DELETE = 16;
const UPDATE = 32;
2010-08-03 02:43:37 +02:00
const QUERY = 60; // SELECT | INSERT | DELETE | UPDATE
const BEGIN = 64;
const COMMIT = 128;
const ROLLBACK = 256;
2010-08-03 02:43:37 +02:00
const TRANSACTION = 448; // BEGIN | COMMIT | ROLLBACK
const EXCEPTION = 512;
const ALL = 1023;
/**#@-*/
/**
* Before event notification.
* @param DibiConnection
* @param int event name
* @param string sql
* @return int
*/
function before(DibiConnection $connection, $event, $sql = NULL);
/**
* After event notification.
* @param int
* @param DibiResult
* @return void
*/
function after($ticket, $result = NULL);
/**
* After exception notification.
* @param DibiDriverException
* @return void
*/
function exception(DibiDriverException $exception);
}
2008-07-17 03:51:29 +00:00
/**
* dibi driver interface.
*
2010-01-03 15:15:37 +01:00
* @copyright Copyright (c) 2005, 2010 David Grudl
2008-07-17 03:51:29 +00:00
* @package dibi
*/
interface IDibiDriver
{
/**
2008-10-28 15:24:47 +00:00
* Connects to a database.
2008-07-17 03:51:29 +00:00
* @param array
* @return void
* @throws DibiException
*/
function connect(array &$config);
/**
2008-10-28 15:24:47 +00:00
* Disconnects from a database.
2008-07-17 03:51:29 +00:00
* @return void
* @throws DibiException
*/
function disconnect();
/**
* Internal: Executes the SQL query.
* @param string SQL statement.
* @return IDibiDriver|NULL
* @throws DibiDriverException
*/
function query($sql);
/**
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
* @return int|FALSE number of rows or FALSE on error
*/
function getAffectedRows();
2008-07-17 03:51:29 +00:00
/**
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
* @return int|FALSE int on success or FALSE on failure
*/
function getInsertId($sequence);
2008-07-17 03:51:29 +00:00
/**
* Begins a transaction (if supported).
2009-06-30 14:08:49 +00:00
* @param string optional savepoint name
2008-07-17 03:51:29 +00:00
* @return void
* @throws DibiDriverException
*/
2008-11-17 16:17:16 +00:00
function begin($savepoint = NULL);
2008-07-17 03:51:29 +00:00
/**
* Commits statements in a transaction.
2009-06-30 14:08:49 +00:00
* @param string optional savepoint name
2008-07-17 03:51:29 +00:00
* @return void
* @throws DibiDriverException
*/
2008-11-17 16:17:16 +00:00
function commit($savepoint = NULL);
2008-07-17 03:51:29 +00:00
/**
* Rollback changes in a transaction.
2009-06-30 14:08:49 +00:00
* @param string optional savepoint name
2008-07-17 03:51:29 +00:00
* @return void
* @throws DibiDriverException
*/
2008-11-17 16:17:16 +00:00
function rollback($savepoint = NULL);
2008-07-17 03:51:29 +00:00
/**
* Returns the connection resource.
* @return mixed
*/
function getResource();
/********************* SQL ****************d*g**/
2008-07-17 03:51:29 +00:00
/**
2009-03-19 12:18:16 +00:00
* Encodes data for use in a SQL statement.
2008-07-17 03:51:29 +00:00
* @param string value
* @param string type (dibi::TEXT, dibi::BOOL, ...)
2008-07-17 03:51:29 +00:00
* @return string encoded value
* @throws InvalidArgumentException
*/
function escape($value, $type);
/**
* Decodes data from result set.
* @param string value
* @param string type (dibi::BINARY)
2008-07-17 03:51:29 +00:00
* @return string decoded value
* @throws InvalidArgumentException
*/
function unescape($value, $type);
/**
* 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);
/********************* result set ****************d*g**/
2008-07-17 03:51:29 +00:00
/**
* Returns the number of rows in a result set.
* @return int
*/
function getRowCount();
2008-07-17 03:51:29 +00:00
/**
* 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
* @throws DibiException
*/
function seek($row);
/**
* Fetches the row at current position and moves the internal cursor to the next position.
* @param bool TRUE for associative array, FALSE for numeric
* @return array array on success, nonarray if no next record
2008-10-28 15:24:47 +00:00
* @internal
2008-07-17 03:51:29 +00:00
*/
function fetch($type);
/**
* Frees the resources allocated for this result set.
* @param resource result set resource
* @return void
*/
function free();
/**
* Returns metadata for all columns in a result set.
* @return array
* @throws DibiException
*/
function getColumnsMeta();
/**
* Returns the result set resource.
2008-07-17 03:51:29 +00:00
* @return mixed
*/
function getResultResource();
}
2008-07-17 03:51:29 +00:00
/**
* dibi driver reflection.
*
* @copyright Copyright (c) 2005, 2010 David Grudl
* @package dibi
*/
interface IDibiReflector
{
2008-07-17 03:51:29 +00:00
/**
* Returns list of tables.
* @return array
2008-07-17 03:51:29 +00:00
*/
function getTables();
2008-07-17 03:51:29 +00:00
/**
* Returns metadata for all columns in a table.
* @param string
* @return array
*/
function getColumns($table);
/**
* Returns metadata for all indexes in a table.
* @param string
* @return array
*/
function getIndexes($table);
/**
* Returns metadata for all foreign keys in a table.
* @param string
* @return array
2008-07-17 03:51:29 +00:00
*/
function getForeignKeys($table);
2008-07-17 03:51:29 +00:00
}