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

236 lines
4.9 KiB
PHP
Raw Normal View History

2008-07-17 03:51:29 +00:00
<?php
/**
2010-09-14 18:40:41 +02:00
* This file is part of the "dibi" - smart database abstraction layer.
2008-07-17 03:51:29 +00:00
*
2012-01-02 20:24:16 +01:00
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
2010-09-14 18:40:41 +02:00
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
2008-07-17 03:51:29 +00:00
*/
/**
* Provides an interface between a dataset and data-aware components.
2012-01-03 04:50:11 +01:00
* @package dibi
*/
interface IDataSource extends Countable, IteratorAggregate
{
2009-02-05 23:13:29 +00:00
//function IteratorAggregate::getIterator();
//function Countable::count();
}
2008-07-17 03:51:29 +00:00
/**
* dibi driver interface.
2012-01-03 04:50:11 +01:00
* @package dibi
2008-07-17 03:51:29 +00:00
*/
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 IDibiResultDriver|NULL
2008-07-17 03:51:29 +00:00
* @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();
2010-08-05 21:03:08 +02:00
/**
* Returns the connection reflector.
* @return IDibiReflector
*/
function getReflector();
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);
/**
* Encodes string for use in a LIKE statement.
* @param string
* @param int
* @return string
*/
function escapeLike($value, $pos);
2008-07-17 03:51:29 +00:00
/**
* 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);
}
2008-07-17 03:51:29 +00:00
/**
* dibi result set driver interface.
2012-01-03 04:50:11 +01:00
* @package dibi
*/
interface IDibiResultDriver
{
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.
2010-08-03 22:48:44 +02:00
* @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
2008-07-17 03:51:29 +00:00
*/
function getResultColumns();
2008-07-17 03:51:29 +00:00
/**
* Returns the result set resource.
2008-07-17 03:51:29 +00:00
* @return mixed
*/
function getResultResource();
/**
* Decodes data from result set.
* @param string value
* @param string type (dibi::BINARY)
* @return string decoded value
* @throws InvalidArgumentException
*/
function unescape($value, $type);
}
2008-07-17 03:51:29 +00:00
/**
* dibi driver reflection.
*
2010-09-14 18:40:41 +02:00
* @author David Grudl
2012-01-03 04:50:11 +01:00
* @package dibi
*/
interface IDibiReflector
{
2008-07-17 03:51:29 +00:00
/**
* Returns list of tables.
2010-08-03 22:48:44 +02:00
* @return array of {name [, (bool) view ]}
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
2010-08-03 22:48:44 +02:00
* @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
*/
function getColumns($table);
/**
* Returns metadata for all indexes in a table.
* @param string
2010-08-03 22:48:44 +02:00
* @return array of {name, (array of names) columns [, (bool) unique, (bool) primary ]}
*/
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
}