Skip to content

Commit

Permalink
CAST with CAST('field' AS CHAR(n))
Browse files Browse the repository at this point in the history
CAST with CAST('field' AS CHAR(n))
  • Loading branch information
alikon committed Oct 15, 2016
1 parent 5a85d02 commit 08e6c48
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions libraries/joomla/database/query/pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,32 @@
*/
class JDatabaseQueryPdo extends JDatabaseQuery
{
/**
* Casts a value to a char.
*
* Ensure that the value is properly quoted before passing to the method.
*
* Usage:
* $query->select($query->castAsChar('a'));
* $query->select($query->castAsChar('a', 40));
*
* @param string $value The value to cast as a char.
*
* @param string $len The lenght of the char.
*
* @return string Returns the cast value.
*
* @since 11.1
*/
public function castAsChar($value, $len = null)
{
if (!$len)
{
return $value;
}
else
{
return ' CAST(' . $value . ' AS CHAR(' . $len . '))';
}
}
}

0 comments on commit 08e6c48

Please sign in to comment.