Overview

Packages

  • Db
    • Adapter
    • Migration

Classes

  • Horde_Db_Adapter_Base
  • Horde_Db_Adapter_Base_Column
  • Horde_Db_Adapter_Base_ColumnDefinition
  • Horde_Db_Adapter_Base_Index
  • Horde_Db_Adapter_Base_Schema
  • Horde_Db_Adapter_Base_Table
  • Horde_Db_Adapter_Base_TableDefinition
  • Horde_Db_Adapter_Mysql
  • Horde_Db_Adapter_Mysql_Column
  • Horde_Db_Adapter_Mysql_Result
  • Horde_Db_Adapter_Mysql_Schema
  • Horde_Db_Adapter_Mysqli
  • Horde_Db_Adapter_Mysqli_Result
  • Horde_Db_Adapter_Pdo_Base
  • Horde_Db_Adapter_Pdo_Mysql
  • Horde_Db_Adapter_Pdo_Pgsql
  • Horde_Db_Adapter_Pdo_Sqlite
  • Horde_Db_Adapter_Postgresql_Column
  • Horde_Db_Adapter_Postgresql_Schema
  • Horde_Db_Adapter_SplitRead
  • Horde_Db_Adapter_Sqlite_Column
  • Horde_Db_Adapter_Sqlite_Schema

Interfaces

  • Horde_Db_Adapter
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Copyright 2007 Maintainable Software, LLC
  4:  * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
  5:  *
  6:  * @author     Mike Naberezny <mike@maintainable.com>
  7:  * @author     Derek DeVries <derek@maintainable.com>
  8:  * @author     Chuck Hagenbuch <chuck@horde.org>
  9:  * @license    http://www.horde.org/licenses/bsd
 10:  * @category   Horde
 11:  * @package    Db
 12:  * @subpackage Adapter
 13:  */
 14: 
 15: /**
 16:  * @author     Mike Naberezny <mike@maintainable.com>
 17:  * @author     Derek DeVries <derek@maintainable.com>
 18:  * @author     Chuck Hagenbuch <chuck@horde.org>
 19:  * @license    http://www.horde.org/licenses/bsd
 20:  * @category   Horde
 21:  * @package    Db
 22:  * @subpackage Adapter
 23:  */
 24: class Horde_Db_Adapter_Base_ColumnDefinition
 25: {
 26:     protected $_base;
 27:     protected $_name;
 28:     protected $_type;
 29:     protected $_limit;
 30:     protected $_precision;
 31:     protected $_scale;
 32:     protected $_unsigned;
 33:     protected $_default;
 34:     protected $_null;
 35:     protected $_autoincrement;
 36: 
 37:     /**
 38:      * Constructor.
 39:      */
 40:     public function __construct($base, $name, $type, $limit = null,
 41:                                 $precision = null, $scale = null,
 42:                                 $unsigned = null, $default = null,
 43:                                 $null = null, $autoincrement = null)
 44:     {
 45:         // Protected
 46:         $this->_base      = $base;
 47: 
 48:         // Public
 49:         $this->_name          = $name;
 50:         $this->_type          = $type;
 51:         $this->_limit         = $limit;
 52:         $this->_precision     = $precision;
 53:         $this->_scale         = $scale;
 54:         $this->_unsigned      = $unsigned;
 55:         $this->_default       = $default;
 56:         $this->_null          = $null;
 57:         $this->_autoincrement = $autoincrement;
 58:     }
 59: 
 60: 
 61:     /*##########################################################################
 62:     # Public
 63:     ##########################################################################*/
 64: 
 65:     /**
 66:      * @return  string
 67:      */
 68:     public function toSql()
 69:     {
 70:         $sql = $this->_base->quoteColumnName($this->_name) . ' ' . $this->getSqlType();
 71:         return $this->_addColumnOptions($sql, array('null'     => $this->_null,
 72:                                                     'default'  => $this->_default));
 73:     }
 74: 
 75:     /**
 76:      * @return  string
 77:      */
 78:     public function __toString()
 79:     {
 80:         return $this->toSql();
 81:     }
 82: 
 83: 
 84:     /*##########################################################################
 85:     # Accessor
 86:     ##########################################################################*/
 87: 
 88:     /**
 89:      * @return  string
 90:      */
 91:     public function getName()
 92:     {
 93:         return $this->_name;
 94:     }
 95: 
 96:     /**
 97:      * @return  string
 98:      */
 99:     public function getDefault()
100:     {
101:         return $this->_default;
102:     }
103: 
104:     /**
105:      * @return  string
106:      */
107:     public function getType()
108:     {
109:         return $this->_type;
110:     }
111: 
112:     /**
113:      * @return  string
114:      */
115:     public function getSqlType()
116:     {
117:         try {
118:             return $this->_base->typeToSql($this->_type, $this->_limit, $this->_precision, $this->_scale, $this->_unsigned);
119:         } catch (Exception $e) {
120:             return $this->_type;
121:         }
122:     }
123: 
124:     /**
125:      * @return  int
126:      */
127:     public function getLimit()
128:     {
129:         return $this->_limit;
130:     }
131: 
132:     /**
133:      * @return  int
134:      */
135:     public function precision()
136:     {
137:         return $this->_precision;
138:     }
139: 
140:     /**
141:      * @return  int
142:      */
143:     public function scale()
144:     {
145:         return $this->_scale;
146:     }
147: 
148:     /**
149:      * @return  boolean
150:      */
151:     public function isUnsigned()
152:     {
153:         return $this->_unsigned;
154:     }
155: 
156:     /**
157:      * @return  boolean
158:      */
159:     public function isNull()
160:     {
161:         return $this->_null;
162:     }
163: 
164:     /**
165:      * @return  boolean
166:      */
167:     public function isAutoIncrement()
168:     {
169:         return $this->_autoincrement;
170:     }
171: 
172:     /**
173:      * @param   string
174:      */
175:     public function setName($name)
176:     {
177:         $this->_name = $name;
178:     }
179: 
180:     /**
181:      * @param  string
182:      */
183:     public function setDefault($default)
184:     {
185:         $this->_default = $default;
186:     }
187: 
188:     /**
189:      * @param  string
190:      */
191:     public function setType($type)
192:     {
193:         $this->_type = $type;
194:     }
195: 
196:     /**
197:      * @param  int
198:      */
199:     public function setLimit($limit)
200:     {
201:         $this->_limit = $limit;
202:     }
203: 
204:     /**
205:      * @param  int
206:      */
207:     public function setPrecision($precision)
208:     {
209:         $this->_precision = $precision;
210:     }
211: 
212:     /**
213:      * @param  int
214:      */
215:     public function setScale($scale)
216:     {
217:         $this->_scale = $scale;
218:     }
219: 
220:     /**
221:      * @param  boolean
222:      */
223:     public function setUnsigned($unsigned)
224:     {
225:         $this->_unsigned = $unsigned;
226:     }
227: 
228:     /**
229:      * @param  boolean
230:      */
231:     public function setNull($null)
232:     {
233:         $this->_null = $null;
234:     }
235: 
236:     /**
237:      * @param  boolean
238:      */
239:     public function setAutoIncrement($autoincrement)
240:     {
241:         $this->_autoincrement = $autoincrement;
242:     }
243: 
244: 
245:     /*##########################################################################
246:     # Schema Statements
247:     ##########################################################################*/
248: 
249:     /**
250:      * @param   string  $sql
251:      * @param   array   $options
252:      */
253:     protected function _addColumnOptions($sql, $options)
254:     {
255:         return $this->_base->addColumnOptions($sql,
256:             array_merge($options, array('column' => $this))
257:         );
258:     }
259: }
260: 
API documentation generated by ApiGen