]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Data/Common/Mysql/TMysqlTableColumn.php
dd62f0f667743a559370177c7726ec67c122db41
[bacula/bacula] / gui / baculum / framework / Data / Common / Mysql / TMysqlTableColumn.php
1 <?php
2 /**
3  * TMysqlTableColumn class file.
4  *
5  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6  * @link http://www.pradosoft.com/
7  * @copyright Copyright &copy; 2005-2014 PradoSoft
8  * @license http://www.pradosoft.com/license/
9  * @package System.Data.Common.Mysql
10  */
11
12 /**
13  * Load common TDbTableCommon class.
14  */
15 Prado::using('System.Data.Common.TDbTableColumn');
16
17 /**
18  * Describes the column metadata of the schema for a Mysql database table.
19  *
20  * @author Wei Zhuo <weizho[at]gmail[dot]com>
21  * @package System.Data.Common.Mysql
22  * @since 3.1
23  */
24 class TMysqlTableColumn extends TDbTableColumn
25 {
26         private static $types = array(
27                 'integer' => array('bit', 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint'),
28                 'boolean' => array('boolean', 'bool'),
29                 'float' => array('float', 'double', 'double precision', 'decimal', 'dec', 'numeric', 'fixed')
30                 );
31
32         /**
33          * Overrides parent implementation, returns PHP type from the db type.
34          * @return boolean derived PHP primitive type from the column db type.
35          */
36         public function getPHPType()
37         {
38                 $dbtype = trim(str_replace(array('unsigned', 'zerofill'),array('','',),strtolower($this->getDbType())));
39                 if($dbtype==='tinyint' && $this->getColumnSize()===1)
40                         return 'boolean';
41                 foreach(self::$types as $type => $dbtypes)
42                 {
43                         if(in_array($dbtype, $dbtypes))
44                                 return $type;
45                 }
46                 return 'string';
47         }
48
49         /**
50          * @return boolean true if column will auto-increment when the column value is inserted as null.
51          */
52         public function getAutoIncrement()
53         {
54                 return $this->getInfo('AutoIncrement', false);
55         }
56
57         /**
58          * @return boolean true if auto increment is true.
59          */
60         public function hasSequence()
61         {
62                 return $this->getAutoIncrement();
63         }
64
65         public function getDbTypeValues()
66         {
67                 return $this->getInfo('DbTypeValues');
68         }
69 }
70