This file is indexed.

/usr/share/php/Horde/Db/Adapter/Base/Column.php is in php-horde-db 2.3.1-1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<?php
/**
 * Copyright 2007 Maintainable Software, LLC
 * Copyright 2008-2016 Horde LLC (http://www.horde.org/)
 *
 * @author     Mike Naberezny <mike@maintainable.com>
 * @author     Derek DeVries <derek@maintainable.com>
 * @author     Chuck Hagenbuch <chuck@horde.org>
 * @license    http://www.horde.org/licenses/bsd
 * @category   Horde
 * @package    Db
 * @subpackage Adapter
 */

/**
 * @author     Mike Naberezny <mike@maintainable.com>
 * @author     Derek DeVries <derek@maintainable.com>
 * @author     Chuck Hagenbuch <chuck@horde.org>
 * @license    http://www.horde.org/licenses/bsd
 * @category   Horde
 * @package    Db
 * @subpackage Adapter
 */
class Horde_Db_Adapter_Base_Column
{
    protected $_name;
    protected $_type;
    protected $_null;
    protected $_limit;
    protected $_precision;
    protected $_scale;
    protected $_unsigned;
    protected $_default;
    protected $_sqlType;
    protected $_isText;
    protected $_isNumber;


    /*##########################################################################
    # Construct/Destruct
    ##########################################################################*/

    /**
     * Constructor.
     *
     * @param string $name     The column's name, such as "supplier_id" in
     *                         "supplier_id int(11)".
     * @param string $default  The type-casted default value, such as "new" in
     *                         "sales_stage varchar(20) default 'new'".
     * @param string $sqlType  Used to extract the column's type, length and
     *                         signed status, if necessary. For example
     *                         "varchar" and "60" in "company_name varchar(60)"
     *                         or "unsigned => true" in "int(10) UNSIGNED".
     * @param boolean $null    Whether this column allows NULL values.
     */
    public function __construct($name, $default, $sqlType = null, $null = true)
    {
        $this->_name      = $name;
        $this->_sqlType   = $sqlType;
        $this->_null      = $null;

        $this->_limit     = $this->_extractLimit($sqlType);
        $this->_precision = $this->_extractPrecision($sqlType);
        $this->_scale     = $this->_extractScale($sqlType);
        $this->_unsigned  = $this->_extractUnsigned($sqlType);

        $this->_setSimplifiedType();
        $this->_isText    = $this->_type == 'text'  || $this->_type == 'string';
        $this->_isNumber  = $this->_type == 'float' || $this->_type == 'integer' || $this->_type == 'decimal';

        $this->_default   = $this->extractDefault($default);
    }

    /**
     * @return  boolean
     */
    public function isText()
    {
        return $this->_isText;
    }

    /**
     * @return  boolean
     */
    public function isNumber()
    {
        return $this->_isNumber;
    }

    /**
     * Casts value (which is a String) to an appropriate instance.
     */
    public function typeCast($value)
    {
        if ($value === null) return null;

        switch ($this->_type) {
        case 'string':
        case 'text':
            return $value;
        case 'integer':
            return strlen($value) ? (int)$value : null;
        case 'float':
            return strlen($value) ? (float)$value : null;
        case 'decimal':
            return $this->valueToDecimal($value);
        case 'datetime':
        case 'timestamp':
            return $this->stringToTime($value);
        case 'time':
            return $this->stringToDummyTime($value);
        case 'date':
            return $this->stringToDate($value);
        case 'binary':
            return $this->binaryToString($value);
        case 'boolean':
            return $this->valueToBoolean($value);
        default:
            return $value;
        }
    }

    public function extractDefault($default)
    {
        return $this->typeCast($default);
    }


    /*##########################################################################
    # Accessor
    ##########################################################################*/

    /**
     * @return  string
     */
    public function getName()
    {
        return $this->_name;
    }

    /**
     * @return  string
     */
    public function getDefault()
    {
        return $this->_default;
    }

    /**
     * @return  string
     */
    public function getType()
    {
        return $this->_type;
    }

    /**
     * @return  int
     */
    public function getLimit()
    {
        return $this->_limit;
    }

    /**
     * @return  int
     */
    public function precision()
    {
        return $this->_precision;
    }

    /**
     * @return  int
     */
    public function scale()
    {
        return $this->_scale;
    }

    /**
     * @return  boolean
     */
    public function isUnsigned()
    {
        return $this->_unsigned;
    }

    /**
     * @return  boolean
     */
    public function isNull()
    {
        return $this->_null;
    }

    /**
     * @return  string
     */
    public function getSqlType()
    {
        return $this->_sqlType;
    }


    /*##########################################################################
    # Type Juggling
    ##########################################################################*/

    /**
     * Used to convert from BLOBs to Strings
     *
     * @return  string
     */
    public function binaryToString($value)
    {
        return (string)$value;
    }

    /**
     * @param   string  $string
     * @return  Horde_Date
     */
    public function stringToDate($string)
    {
        if (empty($string) ||
            // preserve '0000-00-00' (http://bugs.php.net/bug.php?id=45647)
            preg_replace('/[^\d]/', '', $string) == 0) {
            return null;
        }

        $d = new Horde_Date($string);
        $d->setDefaultFormat('Y-m-d');

        return $d;
    }

    /**
     * @param   string  $string
     * @return  Horde_Date
     */
    public function stringToTime($string)
    {
        if (empty($string) ||
            // preserve '0000-00-00 00:00:00' (http://bugs.php.net/bug.php?id=45647)
            preg_replace('/[^\d]/', '', $string) == 0) {
            return null;
        }

        return new Horde_Date($string);
    }

    /**
     * @param   string  $string
     * @return  Horde_Date
     */
    public function stringToDummyTime($value)
    {
        if (empty($string)) {
            return null;
        }
        return $this->stringToTime('2000-01-01 ' . $string);
    }

    /**
     * @param   mixed  $value
     * @return  boolean
     */
    public function valueToBoolean($value)
    {
        if ($value === true || $value === false) {
            return $value;
        }

        $value = Horde_String::lower($value);
        return $value == 'true' || $value == 't' || $value == '1';
    }

    /**
     * @param   mixed  $value
     * @return  decimal
     */
    public function valueToDecimal($value)
    {
        return (float)$value;
    }


    /*##########################################################################
    # Protected
    ##########################################################################*/

    /**
     * @param   string  $sqlType
     * @return  int
     */
    protected function _extractLimit($sqlType)
    {
        if (preg_match("/\((.*)\)/", $sqlType, $matches)) {
            return (int)$matches[1];
        }
        return null;
    }

    /**
     * @param   string  $sqlType
     * @return  int
     */
    protected function _extractPrecision($sqlType)
    {
        if (preg_match("/^(numeric|decimal|number)\((\d+)(,\d+)?\)/i", $sqlType, $matches)) {
            return (int)$matches[2];
        }
        return null;
    }

    /**
     * @param   string  $sqlType
     * @return  int
     */
    protected function _extractScale($sqlType)
    {
        switch (true) {
            case preg_match("/^(numeric|decimal|number)\((\d+)\)/i", $sqlType):
                return 0;
            case preg_match("/^(numeric|decimal|number)\((\d+)(,(\d+))\)/i",
                            $sqlType, $match):
                return (int)$match[4];
        }
    }

    /**
     * @param   string  $sqlType
     * @return  int
     */
    protected function _extractUnsigned($sqlType)
    {
        return (boolean)preg_match('/^int.*unsigned/i', $sqlType);
    }

    /**
     */
    protected function _setSimplifiedType()
    {
        switch (true) {
        case preg_match('/int/i', $this->_sqlType):
            $this->_type = 'integer';
            return;
        case preg_match('/float|double/i', $this->_sqlType):
            $this->_type = 'float';
            return;
        case preg_match('/decimal|numeric|number/i', $this->_sqlType):
            $this->_type = $this->_scale == 0 ? 'integer' : 'decimal';
            return;
        case preg_match('/datetime/i', $this->_sqlType):
            $this->_type = 'datetime';
            return;
        case preg_match('/timestamp/i', $this->_sqlType):
            $this->_type = 'timestamp';
            return;
        case preg_match('/time/i', $this->_sqlType):
            $this->_type = 'time';
            return;
        case preg_match('/date/i', $this->_sqlType):
            $this->_type = 'date';
            return;
        case preg_match('/clob|text/i', $this->_sqlType):
            $this->_type = 'text';
            return;
        case preg_match('/blob|binary/i', $this->_sqlType):
            $this->_type = 'binary';
            return;
        case preg_match('/char|string/i', $this->_sqlType):
            $this->_type = 'string';
            return;
        case preg_match('/boolean/i', $this->_sqlType):
            $this->_type = 'boolean';
            return;
        }
    }
}