QBFunctions

Overview

The QBFunctions class provides a comprehensive set of SQL functions designed to enhance query building in QBSelect. It enables the creation of mathematical, string, and date-based expressions, along with conditional and custom logic.

This class allows users to perform operations like calculating absolute values, rounding, and extracting substrings. It also includes advanced capabilities such as casting data types, concatenating strings, trimming whitespace, and formatting dates. With access to aggregation methods and support for custom function definitions, the class is versatile in handling diverse SQL requirements.

For additional guidance on query construction and execution, refer to the QBSelect section of the documentation.

Properties Summarized

Type
Name
Summary

Get query builder parent table clause, this may be a query or a join clause.

Get query builder parent.

Methods Summarized

Type
Name
Summary

Create abs(column) expression

Create bit_length(column) expression

Create cardinality(column) expression

Create cast(column, type) expression

Create ceil(column) expression

Create coalesce(arg) expression

Concatenate with value

Call a custom defined function.

Extract day from date

Create floor(column) expression

Extract hour from date

Create length(column) expression

Create locate(arg) expression

Create locate(arg, start) expression

Create lower(column) expression

Extract minute from date

Create mod(arg) expression

Extract month from date

Multiply with value

Create nullif(arg) expression

Create round(column) expression

Create round(column) expression

Extract second from date

Create sqrt(column) expression

Create substring(pos) expression

Create substring(pos, len) expression

Create trim(column) expression

Create upper(column) expression

Extract year from date

Properties Detailed

parent

Get query builder parent table clause, this may be a query or a join clause.

Type QBSelect

Sample

root

Get query builder parent.

Type QBSelect

Sample

Methods Detailed

abs(value)

Create abs(column) expression

Parameters

Returns: QBColumn A query builder column representing the absolute value of the input.

Sample

bit_length(value)

Create bit_length(column) expression

Parameters

Returns: QBColumn A query builder column representing the bit length of the value.

Sample

cardinality(arg)

Create cardinality(column) expression

Parameters

Returns: QBColumn A query builder column representing the year component of a date/time value.

Sample

cast(value, type)

Create cast(column, type) expression

Parameters

  • Object value object to cast

  • String type type see QUERY_COLUMN_TYPES

Returns: QBColumn A query builder column representing the value cast to the specified type.

Sample

ceil(arg)

Create ceil(column) expression

Parameters

Returns: QBColumn A query builder column representing the smallest integer greater than or equal to the input.

Sample

coalesce(args)

Create coalesce(arg) expression

Parameters

  • Array args arguments to coalesce

Returns: QBColumn A query builder column that returns the first non-null argument.

Sample

concat(arg1, arg2)

Concatenate with value

Parameters

Returns: QBColumn A query builder column representing the concatenation of two arguments.

Sample

custom(name, args)

Call a custom defined function.

Parameters

  • String name custom function name

  • Array args function arguments

Returns: QBColumn A query builder column representing a custom function with the given name and arguments.

Sample

day(arg)

Extract day from date

Parameters

Returns: QBColumn A query builder column representing the day component of a date/time value.

Sample

divide(arg1, arg2)

Divide by value

Parameters

Returns: QBColumn A query builder column representing the division of two arguments.

Sample

floor(arg)

Create floor(column) expression

Parameters

Returns: QBColumn A query builder column representing the largest integer less than or equal to the input.

Sample

hour(arg)

Extract hour from date

Parameters

Returns: QBColumn A query builder column representing the hour component of a date/time value.

Sample

len(value)

Create length(column) expression

Parameters

Returns: QBColumn A query builder column representing the length of the value.

Sample

locate(string1, string2)

Create locate(arg) expression

Parameters

  • Object string1 string to locate

  • Object string2 string to search in

Returns: QBColumn A query builder column representing the position of the first occurrence of one string in another.

Sample

locate(string1, string2, start)

Create locate(arg, start) expression

Parameters

Returns: QBColumn A query builder column representing the position of the first occurrence of one string in another, starting from a given position.

Sample

lower(value)

Create lower(column) expression

Parameters

Returns: QBColumn A query builder column representing the value converted to lowercase.

Sample

minus(arg1, arg2)

Subtract value

Parameters

Returns: QBColumn A query builder column representing the difference between two arguments.

Sample

minute(arg)

Extract minute from date

Parameters

Returns: QBColumn A query builder column representing the minute component of a date/time value.

Sample

mod(dividend, divisor)

Create mod(arg) expression

Parameters

Returns: QBColumn A query builder column representing the remainder of the division of two numbers.

Sample

month(arg)

Extract month from date

Parameters

Returns: QBColumn A query builder column representing the month component of a date/time value.

Sample

multiply(arg1, arg2)

Multiply with value

Parameters

Returns: QBColumn A query builder column representing the product of two arguments.

Sample

nullif(arg1, arg2)

Create nullif(arg) expression

Parameters

Returns: QBColumn A query builder column that returns null if the two arguments are equal.

Sample

plus(arg1, arg2)

Add up value

Parameters

Returns: QBColumn A query builder column representing the sum of two arguments.

Sample

round(arg)

Create round(column) expression

Parameters

Returns: QBColumn A query builder column representing the input rounded to the nearest integer.

Sample

round(arg, decimals)

Create round(column) expression

Parameters

  • Object arg number object

  • Number decimals The number of decimal places to round number to, default 0

Returns: QBColumn A query builder column representing the input rounded to the specified number of decimal places.

Sample

second(arg)

Extract second from date

Parameters

Returns: QBColumn A query builder column representing the second component of a date/time value.

Sample

sqrt(value)

Create sqrt(column) expression

Parameters

Returns: QBColumn A query builder column representing the square root of the input.

Sample

substring(arg, pos)

Create substring(pos) expression

Parameters

Returns: QBColumn A query builder column representing a substring starting at the specified position.

Sample

substring(arg, pos, len)

Create substring(pos, len) expression

Parameters

Returns: QBColumn A query builder column representing a substring of specified length starting at the specified position.

Sample

trim(value)

Create trim(column) expression

Parameters

Returns: QBColumn A query builder column representing the value with leading and trailing spaces removed.

Sample

trim(leading_trailing_both, characters, fromKeyword, value)

Create trim(column) expression

Parameters

  • String leading_trailing_both 'leading', 'trailing' or 'both'

  • String characters characters to remove

  • String fromKeyword 'from'

  • Object value value to trim

Returns: QBColumn A query builder column representing the value with specified characters trimmed from a specified position.

Sample

upper(value)

Create upper(column) expression

Parameters

Returns: QBColumn A query builder column representing the value converted to uppercase.

Sample

year(arg)

Extract year from date

Parameters

Returns: QBColumn A query builder column representing the year component of a date/time value.

Sample


Last updated

Was this helpful?