Skip to content

Commit

Permalink
Updated charLength to 12.1 platform's version to address CMS' CASE WHEN
Browse files Browse the repository at this point in the history
queries.
  • Loading branch information
gpongelli committed Mar 25, 2012
1 parent 5aef5fb commit ac0d24a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 6 deletions.
8 changes: 5 additions & 3 deletions libraries/joomla/database/database/sqlsrvquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ public function castAsChar($value)
/**
* Gets the function to determine the length of a character string.
*
* @param string $field A value.
* @param string $field A value.
* @param string $operator Comparison operator between charLength integer value and $condition
* @param string $condition Integer value to compare charLength with.
*
* @return string The required char length call.
*
* @since 11.1
*/
public function charLength($field)
public function charLength($field, $operator = null, $condition = null)
{
return 'DATALENGTH(' . $field . ') IS NOT NULL';
return 'DATALENGTH(' . $field . ')' . (isset($operator) && isset($condition) ? ' ' . $operator . ' ' . $condition : '');
}

/**
Expand Down
110 changes: 107 additions & 3 deletions libraries/joomla/database/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,17 @@ public function castAsChar($value)
* Usage:
* $query->select($query->charLength('a'));
*
* @param string $field A value.
* @param string $field A value.
* @param string $operator Comparison operator between charLength integer value and $condition
* @param string $condition Integer value to compare charLength with.
*
* @return string The required char length call.
*
* @since 11.1
*/
public function charLength($field)
public function charLength($field, $operator = null, $condition = null)
{
return 'CHAR_LENGTH(' . $field . ')';
return 'CHAR_LENGTH(' . $field . ')' . (isset($operator) && isset($condition) ? ' ' . $operator . ' ' . $condition : '');
}

/**
Expand Down Expand Up @@ -721,6 +723,108 @@ public function from($tables)
}

return $this;
}

/**
* Used to get a string to extract year from date column.
*
* Usage:
* $query->select($query->year($query->quoteName('dateColumn')));
*
* @param string $date Date column containing year to be extracted.
*
* @return string Returns string to extract year from a date.
*
* @since 12.1
*/
public function year($date)
{
return 'YEAR(' . $date . ')';
}

/**
* Used to get a string to extract month from date column.
*
* Usage:
* $query->select($query->month($query->quoteName('dateColumn')));
*
* @param string $date Date column containing month to be extracted.
*
* @return string Returns string to extract month from a date.
*
* @since 12.1
*/
public function month($date)
{
return 'MONTH(' . $date . ')';
}

/**
* Used to get a string to extract day from date column.
*
* Usage:
* $query->select($query->day($query->quoteName('dateColumn')));
*
* @param string $date Date column containing day to be extracted.
*
* @return string Returns string to extract day from a date.
*
* @since 12.1
*/
public function day($date)
{
return 'DAY(' . $date . ')';
}

/**
* Used to get a string to extract hour from date column.
*
* Usage:
* $query->select($query->hour($query->quoteName('dateColumn')));
*
* @param string $date Date column containing hour to be extracted.
*
* @return string Returns string to extract hour from a date.
*
* @since 12.1
*/
public function hour($date)
{
return 'HOUR(' . $date . ')';
}

/**
* Used to get a string to extract minute from date column.
*
* Usage:
* $query->select($query->minute($query->quoteName('dateColumn')));
*
* @param string $date Date column containing minute to be extracted.
*
* @return string Returns string to extract minute from a date.
*
* @since 12.1
*/
public function minute($date)
{
return 'MINUTE(' . $date . ')';
}

/**
* Used to get a string to extract seconds from date column.
*
* Usage:
* $query->select($query->second($query->quoteName('dateColumn')));
*
* @param string $date Date column containing second to be extracted.
*
* @return string Returns string to extract second from a date.
*
* @since 12.1
*/
public function second($date)
{
return 'SECOND(' . $date . ')';
}

/**
Expand Down

0 comments on commit ac0d24a

Please sign in to comment.