1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18: 19: 20: 21: 22: 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: 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:
46: $this->_base = $base;
47:
48:
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: 63:
64:
65: 66: 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: 77:
78: public function __toString()
79: {
80: return $this->toSql();
81: }
82:
83:
84: 85: 86:
87:
88: 89: 90:
91: public function getName()
92: {
93: return $this->_name;
94: }
95:
96: 97: 98:
99: public function getDefault()
100: {
101: return $this->_default;
102: }
103:
104: 105: 106:
107: public function getType()
108: {
109: return $this->_type;
110: }
111:
112: 113: 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: 126:
127: public function getLimit()
128: {
129: return $this->_limit;
130: }
131:
132: 133: 134:
135: public function precision()
136: {
137: return $this->_precision;
138: }
139:
140: 141: 142:
143: public function scale()
144: {
145: return $this->_scale;
146: }
147:
148: 149: 150:
151: public function isUnsigned()
152: {
153: return $this->_unsigned;
154: }
155:
156: 157: 158:
159: public function isNull()
160: {
161: return $this->_null;
162: }
163:
164: 165: 166:
167: public function isAutoIncrement()
168: {
169: return $this->_autoincrement;
170: }
171:
172: 173: 174:
175: public function setName($name)
176: {
177: $this->_name = $name;
178: }
179:
180: 181: 182:
183: public function setDefault($default)
184: {
185: $this->_default = $default;
186: }
187:
188: 189: 190:
191: public function setType($type)
192: {
193: $this->_type = $type;
194: }
195:
196: 197: 198:
199: public function setLimit($limit)
200: {
201: $this->_limit = $limit;
202: }
203:
204: 205: 206:
207: public function setPrecision($precision)
208: {
209: $this->_precision = $precision;
210: }
211:
212: 213: 214:
215: public function setScale($scale)
216: {
217: $this->_scale = $scale;
218: }
219:
220: 221: 222:
223: public function setUnsigned($unsigned)
224: {
225: $this->_unsigned = $unsigned;
226: }
227:
228: 229: 230:
231: public function setNull($null)
232: {
233: $this->_null = $null;
234: }
235:
236: 237: 238:
239: public function setAutoIncrement($autoincrement)
240: {
241: $this->_autoincrement = $autoincrement;
242: }
243:
244:
245: 246: 247:
248:
249: 250: 251: 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: