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.
|
2012-01-02 20:24:16 +01:00
|
|
|
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-02-05 21:08:00 +00:00
|
|
|
/**
|
|
|
|
* Provides an interface between a dataset and data-aware components.
|
2012-01-03 04:50:11 +01:00
|
|
|
* @package dibi
|
2009-02-05 21:08:00 +00:00
|
|
|
*/
|
|
|
|
interface IDataSource extends Countable, IteratorAggregate
|
|
|
|
{
|
2009-02-05 23:13:29 +00:00
|
|
|
//function IteratorAggregate::getIterator();
|
2009-02-05 21:08:00 +00:00
|
|
|
//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
|
|
|
|
*/
|
2013-07-02 18:42:55 +02:00
|
|
|
function connect(array & $config);
|
2008-07-17 03:51:29 +00:00
|
|
|
|
|
|
|
/**
|
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.
|
2010-08-04 15:27:41 +02:00
|
|
|
* @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
|
|
|
|
*/
|
2009-02-26 20:02:14 +00:00
|
|
|
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
|
|
|
|
*/
|
2009-02-26 20:02:14 +00:00
|
|
|
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
|
|
|
|
2008-10-02 17:13:43 +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
|
2009-03-16 06:48:27 +00:00
|
|
|
* @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);
|
|
|
|
|
2010-08-25 18:45:48 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-07-02 18:42:55 +02:00
|
|
|
function applyLimit(& $sql, $limit, $offset);
|
2008-07-17 03:51:29 +00:00
|
|
|
|
2010-08-04 15:27:41 +02:00
|
|
|
}
|
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
|
2010-08-04 15:27:41 +02:00
|
|
|
/**
|
|
|
|
* dibi result set driver interface.
|
2012-01-03 04:50:11 +01:00
|
|
|
* @package dibi
|
2010-08-04 15:27:41 +02:00
|
|
|
*/
|
|
|
|
interface IDibiResultDriver
|
|
|
|
{
|
2008-10-02 17:13:43 +00:00
|
|
|
|
2008-07-17 03:51:29 +00:00
|
|
|
/**
|
|
|
|
* Returns the number of rows in a result set.
|
|
|
|
* @return int
|
|
|
|
*/
|
2009-02-26 20:02:14 +00:00
|
|
|
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
|
|
|
*/
|
2010-08-03 23:33:12 +02:00
|
|
|
function getResultColumns();
|
2008-07-17 03:51:29 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-02 17:13:43 +00:00
|
|
|
* Returns the result set resource.
|
2008-07-17 03:51:29 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2008-10-02 17:13:43 +00:00
|
|
|
function getResultResource();
|
2010-08-04 15:27:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decodes data from result set.
|
|
|
|
* @param string value
|
|
|
|
* @param string type (dibi::BINARY)
|
|
|
|
* @return string decoded value
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function unescape($value, $type);
|
|
|
|
|
2010-05-26 16:26:21 +02:00
|
|
|
}
|
2008-10-02 17:13:43 +00:00
|
|
|
|
|
|
|
|
2010-05-26 16:26:21 +02: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
|
2010-05-26 16:26:21 +02:00
|
|
|
*/
|
|
|
|
interface IDibiReflector
|
|
|
|
{
|
2008-07-17 03:51:29 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-02 17:13:43 +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
|
|
|
*/
|
2008-10-02 17:13:43 +00:00
|
|
|
function getTables();
|
2008-07-17 03:51:29 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-02 17:13:43 +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 ]}
|
2008-10-02 17:13:43 +00:00
|
|
|
*/
|
|
|
|
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 ]}
|
2008-10-02 17:13:43 +00:00
|
|
|
*/
|
|
|
|
function getIndexes($table);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns metadata for all foreign keys in a table.
|
|
|
|
* @param string
|
|
|
|
* @return array
|
2008-07-17 03:51:29 +00:00
|
|
|
*/
|
2008-10-02 17:13:43 +00:00
|
|
|
function getForeignKeys($table);
|
2008-07-17 03:51:29 +00:00
|
|
|
|
|
|
|
}
|