2008-10-02 17:13:43 +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-10-02 17:13:43 +00:00
|
|
|
* @license http://dibiphp.com/license dibi license
|
|
|
|
* @link http://dibiphp.com
|
|
|
|
* @package dibi
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reflection metadata class for a database.
|
2008-10-28 15:24:47 +00:00
|
|
|
*
|
2010-01-03 15:15:37 +01:00
|
|
|
* @copyright Copyright (c) 2005, 2010 David Grudl
|
2008-10-28 15:24:47 +00:00
|
|
|
* @package dibi
|
2010-04-22 12:12:11 +02:00
|
|
|
*
|
|
|
|
* @property-read string $name
|
|
|
|
* @property-read array $tables
|
|
|
|
* @property-read array $tableNames
|
2008-10-02 17:13:43 +00:00
|
|
|
*/
|
|
|
|
class DibiDatabaseInfo extends DibiObject
|
|
|
|
{
|
2010-05-26 16:26:21 +02:00
|
|
|
/** @var IDibiReflector */
|
2008-10-02 17:13:43 +00:00
|
|
|
private $driver;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $tables;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-26 16:26:21 +02:00
|
|
|
public function __construct(IDibiReflector $driver, $name)
|
2008-10-02 17:13:43 +00:00
|
|
|
{
|
|
|
|
$this->driver = $driver;
|
|
|
|
$this->name = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array of DibiTableInfo
|
|
|
|
*/
|
|
|
|
public function getTables()
|
|
|
|
{
|
|
|
|
$this->init();
|
|
|
|
return array_values($this->tables);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array of string
|
|
|
|
*/
|
|
|
|
public function getTableNames()
|
|
|
|
{
|
|
|
|
$this->init();
|
|
|
|
$res = array();
|
|
|
|
foreach ($this->tables as $table) {
|
|
|
|
$res[] = $table->getName();
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-05 23:13:29 +00:00
|
|
|
* @param string
|
2008-10-02 17:13:43 +00:00
|
|
|
* @return DibiTableInfo
|
|
|
|
*/
|
|
|
|
public function getTable($name)
|
|
|
|
{
|
2010-05-19 15:03:48 +02:00
|
|
|
$name = DibiTranslator::substitute($name);
|
2008-10-02 17:13:43 +00:00
|
|
|
$this->init();
|
|
|
|
$l = strtolower($name);
|
|
|
|
if (isset($this->tables[$l])) {
|
|
|
|
return $this->tables[$l];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
throw new DibiException("Database '$this->name' has no table '$name'.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-05 23:13:29 +00:00
|
|
|
* @param string
|
2008-10-02 17:13:43 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasTable($name)
|
|
|
|
{
|
2010-05-19 15:03:48 +02:00
|
|
|
$name = DibiTranslator::substitute($name);
|
2008-10-02 17:13:43 +00:00
|
|
|
$this->init();
|
|
|
|
return isset($this->tables[strtolower($name)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function init()
|
|
|
|
{
|
|
|
|
if ($this->tables === NULL) {
|
|
|
|
$this->tables = array();
|
|
|
|
foreach ($this->driver->getTables() as $info) {
|
|
|
|
$this->tables[strtolower($info['name'])] = new DibiTableInfo($this->driver, $info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reflection metadata class for a database table.
|
2008-10-28 15:24:47 +00:00
|
|
|
*
|
2010-01-03 15:15:37 +01:00
|
|
|
* @copyright Copyright (c) 2005, 2010 David Grudl
|
2008-10-28 15:24:47 +00:00
|
|
|
* @package dibi
|
2010-04-22 12:12:11 +02:00
|
|
|
*
|
|
|
|
* @property-read string $name
|
|
|
|
* @property-read bool $view
|
|
|
|
* @property-read array $columns
|
|
|
|
* @property-read array $columnNames
|
|
|
|
* @property-read array $foreignKeys
|
|
|
|
* @property-read array $indexes
|
|
|
|
* @property-read DibiIndexInfo $primaryKey
|
2008-10-02 17:13:43 +00:00
|
|
|
*/
|
|
|
|
class DibiTableInfo extends DibiObject
|
|
|
|
{
|
2010-05-26 16:26:21 +02:00
|
|
|
/** @var IDibiReflector */
|
2008-10-02 17:13:43 +00:00
|
|
|
private $driver;
|
|
|
|
|
2008-10-28 14:37:40 +00:00
|
|
|
/** @var string */
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
/** @var bool */
|
|
|
|
private $view;
|
2008-10-02 17:13:43 +00:00
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $columns;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $foreignKeys;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $indexes;
|
|
|
|
|
|
|
|
/** @var DibiIndexInfo */
|
|
|
|
private $primaryKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-26 16:26:21 +02:00
|
|
|
public function __construct(IDibiReflector $driver, array $info)
|
2008-10-02 17:13:43 +00:00
|
|
|
{
|
|
|
|
$this->driver = $driver;
|
2008-10-28 14:37:40 +00:00
|
|
|
$this->name = $info['name'];
|
|
|
|
$this->view = !empty($info['view']);
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
2008-10-28 14:37:40 +00:00
|
|
|
return $this->name;
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isView()
|
|
|
|
{
|
2008-10-28 14:37:40 +00:00
|
|
|
return $this->view;
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array of DibiColumnInfo
|
|
|
|
*/
|
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
$this->initColumns();
|
|
|
|
return array_values($this->columns);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array of string
|
|
|
|
*/
|
|
|
|
public function getColumnNames()
|
|
|
|
{
|
|
|
|
$this->initColumns();
|
|
|
|
$res = array();
|
|
|
|
foreach ($this->columns as $column) {
|
|
|
|
$res[] = $column->getName();
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-05 23:13:29 +00:00
|
|
|
* @param string
|
2008-10-02 17:13:43 +00:00
|
|
|
* @return DibiColumnInfo
|
|
|
|
*/
|
|
|
|
public function getColumn($name)
|
|
|
|
{
|
2010-05-19 15:03:48 +02:00
|
|
|
$name = DibiTranslator::substitute($name);
|
2008-10-02 17:13:43 +00:00
|
|
|
$this->initColumns();
|
|
|
|
$l = strtolower($name);
|
|
|
|
if (isset($this->columns[$l])) {
|
|
|
|
return $this->columns[$l];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
throw new DibiException("Table '$this->name' has no column '$name'.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-05 23:13:29 +00:00
|
|
|
* @param string
|
2008-10-02 17:13:43 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasColumn($name)
|
|
|
|
{
|
2010-05-19 15:03:48 +02:00
|
|
|
$name = DibiTranslator::substitute($name);
|
2008-10-02 17:13:43 +00:00
|
|
|
$this->initColumns();
|
|
|
|
return isset($this->columns[strtolower($name)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array of DibiForeignKeyInfo
|
|
|
|
*/
|
|
|
|
public function getForeignKeys()
|
|
|
|
{
|
|
|
|
$this->initForeignKeys();
|
|
|
|
return $this->foreignKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array of DibiIndexInfo
|
|
|
|
*/
|
|
|
|
public function getIndexes()
|
|
|
|
{
|
|
|
|
$this->initIndexes();
|
|
|
|
return $this->indexes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DibiIndexInfo
|
|
|
|
*/
|
|
|
|
public function getPrimaryKey()
|
|
|
|
{
|
|
|
|
$this->initIndexes();
|
|
|
|
return $this->primaryKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function initColumns()
|
|
|
|
{
|
|
|
|
if ($this->columns === NULL) {
|
|
|
|
$this->columns = array();
|
2008-10-28 14:37:40 +00:00
|
|
|
foreach ($this->driver->getColumns($this->name) as $info) {
|
2008-10-02 17:13:43 +00:00
|
|
|
$this->columns[strtolower($info['name'])] = new DibiColumnInfo($this->driver, $info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function initIndexes()
|
|
|
|
{
|
|
|
|
if ($this->indexes === NULL) {
|
|
|
|
$this->initColumns();
|
|
|
|
$this->indexes = array();
|
2008-10-28 14:37:40 +00:00
|
|
|
foreach ($this->driver->getIndexes($this->name) as $info) {
|
2008-10-28 01:03:50 +00:00
|
|
|
foreach ($info['columns'] as $key => $name) {
|
|
|
|
$info['columns'][$key] = $this->columns[strtolower($name)];
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
2008-10-28 01:03:50 +00:00
|
|
|
$this->indexes[strtolower($info['name'])] = new DibiIndexInfo($info);
|
2008-10-02 17:13:43 +00:00
|
|
|
if (!empty($info['primary'])) {
|
2008-10-28 01:03:50 +00:00
|
|
|
$this->primaryKey = $this->indexes[strtolower($info['name'])];
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function initForeignKeys()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-09-09 17:02:46 +02:00
|
|
|
* Reflection metadata class for a result set.
|
|
|
|
*
|
2010-01-03 15:15:37 +01:00
|
|
|
* @copyright Copyright (c) 2005, 2010 David Grudl
|
2009-09-09 17:02:46 +02:00
|
|
|
* @package dibi
|
2010-04-22 12:12:11 +02:00
|
|
|
*
|
|
|
|
* @property-read array $columns
|
|
|
|
* @property-read array $columnNames
|
2009-09-09 17:02:46 +02:00
|
|
|
*/
|
|
|
|
class DibiResultInfo extends DibiObject
|
|
|
|
{
|
2010-05-26 16:26:21 +02:00
|
|
|
/** @var IDibiReflector */
|
2009-09-09 17:02:46 +02:00
|
|
|
private $driver;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $columns;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $names;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-26 16:26:21 +02:00
|
|
|
public function __construct(IDibiReflector $driver)
|
2009-09-09 17:02:46 +02:00
|
|
|
{
|
|
|
|
$this->driver = $driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array of DibiColumnInfo
|
|
|
|
*/
|
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
$this->initColumns();
|
|
|
|
return array_values($this->columns);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool
|
|
|
|
* @return array of string
|
|
|
|
*/
|
|
|
|
public function getColumnNames($fullNames = FALSE)
|
|
|
|
{
|
|
|
|
$this->initColumns();
|
|
|
|
$res = array();
|
|
|
|
foreach ($this->columns as $column) {
|
|
|
|
$res[] = $fullNames ? $column->getFullName() : $column->getName();
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string
|
|
|
|
* @return DibiColumnInfo
|
|
|
|
*/
|
|
|
|
public function getColumn($name)
|
|
|
|
{
|
2010-05-19 15:03:48 +02:00
|
|
|
$name = DibiTranslator::substitute($name);
|
2009-09-09 17:02:46 +02:00
|
|
|
$this->initColumns();
|
|
|
|
$l = strtolower($name);
|
|
|
|
if (isset($this->names[$l])) {
|
|
|
|
return $this->names[$l];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
throw new DibiException("Result set has no column '$name'.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasColumn($name)
|
|
|
|
{
|
2010-05-19 15:03:48 +02:00
|
|
|
$name = DibiTranslator::substitute($name);
|
2009-09-09 17:02:46 +02:00
|
|
|
$this->initColumns();
|
|
|
|
return isset($this->names[strtolower($name)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function initColumns()
|
|
|
|
{
|
|
|
|
if ($this->columns === NULL) {
|
|
|
|
$this->columns = array();
|
|
|
|
foreach ($this->driver->getColumnsMeta() as $info) {
|
|
|
|
$this->columns[] = $this->names[$info['name']] = new DibiColumnInfo($this->driver, $info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reflection metadata class for a table or result set column.
|
2008-10-28 15:24:47 +00:00
|
|
|
*
|
2010-01-03 15:15:37 +01:00
|
|
|
* @copyright Copyright (c) 2005, 2010 David Grudl
|
2008-10-28 15:24:47 +00:00
|
|
|
* @package dibi
|
2010-04-22 12:12:11 +02:00
|
|
|
*
|
|
|
|
* @property-read string $name
|
|
|
|
* @property-read string $fullName
|
|
|
|
* @property-read DibiTableInfo $table
|
|
|
|
* @property-read string $type
|
|
|
|
* @property-read mixed $nativeType
|
|
|
|
* @property-read int $size
|
|
|
|
* @property-read bool $unsigned
|
|
|
|
* @property-read bool $nullable
|
|
|
|
* @property-read bool $autoIncrement
|
|
|
|
* @property-read mixed $default
|
2008-10-02 17:13:43 +00:00
|
|
|
*/
|
|
|
|
class DibiColumnInfo extends DibiObject
|
|
|
|
{
|
2008-10-28 14:37:40 +00:00
|
|
|
/** @var array */
|
|
|
|
private static $types;
|
|
|
|
|
2010-05-26 16:26:21 +02:00
|
|
|
/** @var IDibiReflector */
|
2008-10-02 17:13:43 +00:00
|
|
|
private $driver;
|
|
|
|
|
2008-10-28 14:37:40 +00:00
|
|
|
/** @var array (name, nativetype, [table], [fullname], [size], [nullable], [default], [autoincrement], [vendor]) */
|
2008-10-02 17:13:43 +00:00
|
|
|
private $info;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-26 16:26:21 +02:00
|
|
|
public function __construct(IDibiReflector $driver, array $info)
|
2008-10-02 17:13:43 +00:00
|
|
|
{
|
|
|
|
$this->driver = $driver;
|
|
|
|
$this->info = $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->info['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-09 17:02:46 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFullName()
|
|
|
|
{
|
2010-08-03 22:48:44 +02:00
|
|
|
return isset($this->info['fullname']) ? $this->info['fullname'] : NULL;
|
2009-09-09 17:02:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-28 01:03:50 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasTable()
|
|
|
|
{
|
|
|
|
return !empty($this->info['table']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-02 17:13:43 +00:00
|
|
|
/**
|
|
|
|
* @return DibiTableInfo
|
|
|
|
*/
|
|
|
|
public function getTable()
|
|
|
|
{
|
|
|
|
if (empty($this->info['table'])) {
|
|
|
|
throw new DibiException("Table name is unknown.");
|
|
|
|
}
|
|
|
|
return new DibiTableInfo($this->driver, array('name' => $this->info['table']));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getType()
|
|
|
|
{
|
2010-08-03 07:35:18 +02:00
|
|
|
if (self::$types === NULL) {
|
|
|
|
self::$types = new DibiLazyStorage(array(__CLASS__, 'detectType'));
|
2009-09-09 17:03:40 +02:00
|
|
|
}
|
2010-08-03 13:40:47 +02:00
|
|
|
return $this->info['nativetype'] ? self::$types->{$this->info['nativetype']} : dibi::TEXT;
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getNativeType()
|
|
|
|
{
|
2008-10-28 14:37:40 +00:00
|
|
|
return $this->info['nativetype'];
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getSize()
|
|
|
|
{
|
|
|
|
return isset($this->info['size']) ? (int) $this->info['size'] : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-10-28 01:03:50 +00:00
|
|
|
* @return bool
|
2008-10-02 17:13:43 +00:00
|
|
|
*/
|
2009-11-04 05:41:07 +08:00
|
|
|
public function isUnsigned()
|
|
|
|
{
|
|
|
|
return isset($this->info['unsigned']) ? (bool) $this->info['unsigned'] : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-22 12:12:11 +02:00
|
|
|
/**
|
2009-11-04 05:41:07 +08:00
|
|
|
* @return bool
|
|
|
|
*/
|
2008-10-28 01:03:50 +00:00
|
|
|
public function isNullable()
|
2008-10-02 17:13:43 +00:00
|
|
|
{
|
2008-10-28 14:37:40 +00:00
|
|
|
return isset($this->info['nullable']) ? (bool) $this->info['nullable'] : NULL;
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2008-10-28 01:03:50 +00:00
|
|
|
public function isAutoIncrement()
|
2008-10-02 17:13:43 +00:00
|
|
|
{
|
2008-10-28 14:37:40 +00:00
|
|
|
return isset($this->info['autoincrement']) ? (bool) $this->info['autoincrement'] : NULL;
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-10-28 01:03:50 +00:00
|
|
|
* @return mixed
|
2008-10-02 17:13:43 +00:00
|
|
|
*/
|
2008-10-28 01:03:50 +00:00
|
|
|
public function getDefault()
|
2008-10-02 17:13:43 +00:00
|
|
|
{
|
2008-10-28 01:03:50 +00:00
|
|
|
return isset($this->info['default']) ? $this->info['default'] : NULL;
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-10-28 01:03:50 +00:00
|
|
|
* @param string
|
2008-10-02 17:13:43 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2008-10-28 14:37:40 +00:00
|
|
|
public function getVendorInfo($key)
|
2008-10-02 17:13:43 +00:00
|
|
|
{
|
2008-10-28 14:37:40 +00:00
|
|
|
return isset($this->info['vendor'][$key]) ? $this->info['vendor'][$key] : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Heuristic type detection.
|
|
|
|
* @param string
|
|
|
|
* @return string
|
2010-08-03 22:48:44 +02:00
|
|
|
* @internal
|
2008-10-28 14:37:40 +00:00
|
|
|
*/
|
2010-08-03 07:35:18 +02:00
|
|
|
public static function detectType($type)
|
2008-10-28 14:37:40 +00:00
|
|
|
{
|
|
|
|
static $patterns = array(
|
2009-03-17 07:26:09 +00:00
|
|
|
'BYTEA|BLOB|BIN' => dibi::BINARY,
|
2010-08-03 03:06:52 +02:00
|
|
|
'TEXT|CHAR|BIGINT|LONGLONG' => dibi::TEXT,
|
2009-03-16 06:48:27 +00:00
|
|
|
'BYTE|COUNTER|SERIAL|INT|LONG' => dibi::INTEGER,
|
|
|
|
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => dibi::FLOAT,
|
|
|
|
'^TIME$' => dibi::TIME,
|
|
|
|
'TIME' => dibi::DATETIME, // DATETIME, TIMESTAMP
|
|
|
|
'YEAR|DATE' => dibi::DATE,
|
|
|
|
'BOOL|BIT' => dibi::BOOL,
|
2008-10-28 14:37:40 +00:00
|
|
|
);
|
|
|
|
|
2010-08-03 07:35:18 +02:00
|
|
|
foreach ($patterns as $s => $val) {
|
|
|
|
if (preg_match("#$s#i", $type)) {
|
|
|
|
return $val;
|
2008-10-28 14:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-03 07:35:18 +02:00
|
|
|
return dibi::TEXT;
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reflection metadata class for a foreign key.
|
2008-10-28 15:24:47 +00:00
|
|
|
*
|
2010-01-03 15:15:37 +01:00
|
|
|
* @copyright Copyright (c) 2005, 2010 David Grudl
|
2008-10-28 15:24:47 +00:00
|
|
|
* @package dibi
|
2008-10-28 14:37:40 +00:00
|
|
|
* @todo
|
2010-04-22 12:12:11 +02:00
|
|
|
*
|
|
|
|
* @property-read string $name
|
|
|
|
* @property-read array $references
|
2008-10-02 17:13:43 +00:00
|
|
|
*/
|
|
|
|
class DibiForeignKeyInfo extends DibiObject
|
|
|
|
{
|
|
|
|
/** @var string */
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
/** @var array of array(local, foreign, onDelete, onUpdate) */
|
|
|
|
private $references;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($name, array $references)
|
|
|
|
{
|
|
|
|
$this->name = $name;
|
|
|
|
$this->references = $references;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getReferences()
|
|
|
|
{
|
|
|
|
return $this->references;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-05 23:13:29 +00:00
|
|
|
* Reflection metadata class for a index or primary key.
|
2008-10-28 15:24:47 +00:00
|
|
|
*
|
2010-01-03 15:15:37 +01:00
|
|
|
* @copyright Copyright (c) 2005, 2010 David Grudl
|
2008-10-28 15:24:47 +00:00
|
|
|
* @package dibi
|
2010-04-22 12:12:11 +02:00
|
|
|
*
|
|
|
|
* @property-read string $name
|
|
|
|
* @property-read array $columns
|
|
|
|
* @property-read bool $unique
|
|
|
|
* @property-read bool $primary
|
2008-10-02 17:13:43 +00:00
|
|
|
*/
|
|
|
|
class DibiIndexInfo extends DibiObject
|
|
|
|
{
|
2008-10-28 14:37:40 +00:00
|
|
|
/** @var array (name, columns, [unique], [primary]) */
|
2008-10-28 01:03:50 +00:00
|
|
|
private $info;
|
2008-10-02 17:13:43 +00:00
|
|
|
|
|
|
|
|
2008-10-28 01:03:50 +00:00
|
|
|
public function __construct(array $info)
|
2008-10-02 17:13:43 +00:00
|
|
|
{
|
2008-10-28 01:03:50 +00:00
|
|
|
$this->info = $info;
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
2008-10-28 01:03:50 +00:00
|
|
|
return $this->info['name'];
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getColumns()
|
|
|
|
{
|
2008-10-28 01:03:50 +00:00
|
|
|
return $this->info['columns'];
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isUnique()
|
|
|
|
{
|
2008-10-28 01:03:50 +00:00
|
|
|
return !empty($this->info['unique']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isPrimary()
|
|
|
|
{
|
|
|
|
return !empty($this->info['primary']);
|
2008-10-02 17:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|