1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Database
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * PDO Query Building Class.
14 *
15 * @since 12.1
16 */
17 class JDatabaseQueryPdo extends JDatabaseQuery
18 {
19 /**
20 * Casts a value to a char.
21 *
22 * Ensure that the value is properly quoted before passing to the method.
23 *
24 * Usage:
25 * $query->select($query->castAsChar('a'));
26 * $query->select($query->castAsChar('a', 40));
27 *
28 * @param string $value The value to cast as a char.
29 *
30 * @param string $len The lenght of the char.
31 *
32 * @return string Returns the cast value.
33 *
34 * @since 11.1
35 */
36 public function castAsChar($value, $len = null)
37 {
38 if (!$len)
39 {
40 return $value;
41 }
42 else
43 {
44 return ' CAST(' . $value . ' AS CHAR(' . $len . '))';
45 }
46 }
47 }
48