PgsqlSqlHelper extends SqlHelper
Table of Contents
Methods
- __construct() : mixed
- addDaysToDateTime() : string
- Returns function for adding days time interval to $from.
- addSecondsToDateTime() : string
- Returns function for adding seconds time interval to $from.
- castToChar() : string
- Returns CAST expression for converting field or expression into string
- convertDateField() : null|Date
- convertDatetimeField() : null|DateTime
- convertFromDb() : mixed
- Returns $value converted to a type according to $field type.
- convertFromDbDate() : Date
- convertFromDbDateTime() : DateTime
- convertFromDbFloat() : float
- convertFromDbInteger() : int
- convertFromDbString() : string
- convertFromDbText() : string
- convertToDb() : string
- Converts values to the string according to the column type to use it in a SQL query.
- convertToDbBinary() : string
- Returns binary safe data representation.
- convertToDbDate() : string
- Converts value to the string according to the data type to use it in a SQL query.
- convertToDbDateTime() : string
- Converts value to the string according to the data type to use it in a SQL query.
- convertToDbFloat() : string
- Converts value to the string according to the data type to use it in a SQL query.
- convertToDbInteger() : int
- Converts value to the string according to the data type to use it in a SQL query.
- convertToDbString() : string
- Converts value to the string according to the data type to use it in a SQL query.
- convertToDbText() : string
- Converts value to the string according to the data type to use it in a SQL query.
- formatDate() : string
- Returns database expression for converting $field value according the $format.
- forSql() : string
- Escapes special characters in a string for use in an SQL statement.
- getAliasLength() : int
- Returns maximum length of an alias in a select statement
- getAscendingOrder() : string
- Returns ascending order specifier for ORDER BY clause.
- getCharToDateFunction() : string
- Returns function for converting string value into datetime.
- getColumnTypeByField() : string
- Returns a column type according to ScalarField object.
- getConcatFunction() : string
- Returns function for concatenating database fields or expressions.
- getConditionalAssignment() : string
- getConverter() : false|callable
- Returns callback to be called for a field value on fetch.
- getCurrentDateFunction() : string
- Returns function for getting current date without time part.
- getCurrentDateTimeFunction() : string
- Returns function for getting current time.
- getDatetimeToDateFunction() : string
- Returns function cast $value to datetime database type.
- getDateToCharFunction() : string
- Returns function for converting database field or expression into string.
- getDescendingOrder() : string
- Returns descending order specifier for ORDER BY clause.
- getFieldByColumnType() : ScalarField
- Returns instance of a descendant from Entity\ScalarField that matches database type.
- getIlikeOperator() : string
- Returns case insensitive like expression.
- getInsertIgnore() : string
- Makes an insert statement which will ignore duplicate keys errors.
- getIsNullFunction() : string
- Returns function for testing database field or expressions against NULL value. When it is NULL then $result will be returned.
- getLeftQuote() : string
- Returns an identificator escaping left character.
- getLengthFunction() : string
- Returns function for getting length of database field or expression.
- getMatchAndExpression() : mixed
- getMatchFunction() : mixed
- getMatchOrExpression() : mixed
- getOrderByIntField() : string
- getOrderByStringField() : string
- getQueryDelimiter() : string
- Returns database specific query delimiter for batch processing.
- getQueryTables() : array<string|int, mixed>
- getRandomFunction() : string
- Returns function for getting random number.
- getRegexpOperator() : string
- Returns regexp expression.
- getRightQuote() : string
- Returns an identificator escaping right character.
- getRowNumber() : mixed
- getSha1Function() : string
- Returns function to generate sha1 hash.
- getSubstrFunction() : string
- Returns function for getting part of string.
- getTopSql() : string
- Transforms Sql according to $limit and $offset limitations.
- initRowNumber() : mixed
- isBigType() : bool
- Checks is the field type is BIG
- prepareAssignment() : string
- Builds the string for the SQL assignment operation of the given column.
- prepareCorrelatedUpdate() : string
- Builds correlated update DML.
- prepareDeleteLimit() : string
- Builds the DML string for the SQL DELETE command for the given table with limited rows number.
- prepareInsert() : array<string|int, mixed>
- Builds the strings for the SQL INSERT command for the given table.
- prepareMerge() : array<string|int, mixed>
- Builds the strings for the SQL MERGE command for the given table.
- prepareMergeMultiple() : array<string|int, mixed>
- Builds the DML strings for the SQL REPLACE INTO command for the given table.
- prepareMergeSelect() : string
- Builds the DML strings for the SQL INSERT INTO ON CONFLICT UPDATE command for the given table.
- prepareMergeValues() : string
- Returns prepared sql string for upsert multiple rows
- prepareUpdate() : array<string|int, mixed>
- Builds the strings for the SQL UPDATE command for the given table.
- quote() : string
- Returns quoted identifier.
- softCastTextToChar() : string
- Returns expression for text field being used in group or order
- values() : string
- Returns identifier for usage in VALUES.
Methods
__construct()
public
__construct(Connection $connection) : mixed
Parameters
- $connection : Connection
-
Database connection.
addDaysToDateTime()
Returns function for adding days time interval to $from.
public
addDaysToDateTime(mixed $days[, mixed $from = null ]) : string
Parameters
- $days : mixed
-
How many days to add.
- $from : mixed = null
-
Datetime database field of expression.
Tags
Return values
stringaddSecondsToDateTime()
Returns function for adding seconds time interval to $from.
public
addSecondsToDateTime(mixed $seconds[, mixed $from = null ]) : string
Parameters
- $seconds : mixed
-
How many seconds to add.
- $from : mixed = null
-
Datetime database field of expression.
Tags
Return values
stringcastToChar()
Returns CAST expression for converting field or expression into string
public
castToChar(mixed $fieldName) : string
Parameters
- $fieldName : mixed
Tags
Return values
stringconvertDateField()
public
convertDateField(string $value) : null|Date
Converts string into \Bitrix\Main\Type\Date object.
Helper function.
Parameters
- $value : string
-
Value fetched.
Tags
Return values
null|DateconvertDatetimeField()
public
convertDatetimeField(string $value) : null|DateTime
Converts string into \Bitrix\Main\Type\DateTime object.
Helper function.
Parameters
- $value : string
-
Value fetched.
Tags
Return values
null|DateTimeconvertFromDb()
Returns $value converted to a type according to $field type.
public
convertFromDb(mixed $value, IReadable $field) : mixed
For example if $field is Entity\DatetimeField then returned value will be the instance of Type\DateTime.
Parameters
- $value : mixed
-
Value to be converted.
- $field : IReadable
-
Type "source".
convertFromDbDate()
public
convertFromDbDate(mixed $value) : Date
Parameters
- $value : mixed
Tags
Return values
DateconvertFromDbDateTime()
public
convertFromDbDateTime(mixed $value) : DateTime
Parameters
- $value : mixed
Tags
Return values
DateTimeconvertFromDbFloat()
public
convertFromDbFloat(mixed $value[, int $scale = null ]) : float
Parameters
- $value : mixed
- $scale : int = null
Return values
floatconvertFromDbInteger()
public
convertFromDbInteger(mixed $value) : int
Parameters
- $value : mixed
Return values
intconvertFromDbString()
public
convertFromDbString(string $value[, int $length = null ]) : string
Parameters
- $value : string
- $length : int = null
Return values
stringconvertFromDbText()
public
convertFromDbText(mixed $value) : string
Parameters
- $value : mixed
Return values
stringconvertToDb()
Converts values to the string according to the column type to use it in a SQL query.
public
convertToDb(mixed $value[, IReadable|null $field = null ]) : string
Parameters
- $value : mixed
-
Value to be converted.
- $field : IReadable|null = null
-
Type "source".
Return values
string —Value to write to column.
convertToDbBinary()
Returns binary safe data representation.
public
convertToDbBinary(mixed $value) : string
Parameters
- $value : mixed
-
Value to be encoded.
Tags
Return values
stringconvertToDbDate()
Converts value to the string according to the data type to use it in a SQL query.
public
convertToDbDate(mixed $value) : string
Parameters
- $value : mixed
-
Value to be converted.
Tags
Return values
string —Value to write to column.
convertToDbDateTime()
Converts value to the string according to the data type to use it in a SQL query.
public
convertToDbDateTime(mixed $value) : string
Parameters
- $value : mixed
-
Value to be converted.
Tags
Return values
string —Value to write to column.
convertToDbFloat()
Converts value to the string according to the data type to use it in a SQL query.
public
convertToDbFloat(mixed $value[, int|null $scale = null ]) : string
Parameters
- $value : mixed
-
Value to be converted.
- $scale : int|null = null
-
Precise to round float value.
Return values
string —Value to write to column.
convertToDbInteger()
Converts value to the string according to the data type to use it in a SQL query.
public
convertToDbInteger(mixed $value[, int $size = 8 ]) : int
Parameters
- $value : mixed
-
Value to be converted.
- $size : int = 8
-
Size in bytes.
Return values
int —Value to write to column.
convertToDbString()
Converts value to the string according to the data type to use it in a SQL query.
public
convertToDbString(mixed $value[, int|null $length = null ]) : string
Parameters
- $value : mixed
-
Value to be converted.
- $length : int|null = null
-
Maximum acceptable length of the value
Return values
string —Value to write to column.
convertToDbText()
Converts value to the string according to the data type to use it in a SQL query.
public
convertToDbText(mixed $value) : string
Parameters
- $value : mixed
-
Value to be converted.
Return values
string —Value to write to column.
formatDate()
Returns database expression for converting $field value according the $format.
public
formatDate(mixed $format[, mixed $field = null ]) : string
Parameters
- $format : mixed
-
Format string.
- $field : mixed = null
-
Database field or expression.
Tags
Return values
stringforSql()
Escapes special characters in a string for use in an SQL statement.
public
forSql(mixed $value[, mixed $maxLength = 0 ]) : string
Parameters
- $value : mixed
-
Value to be escaped.
- $maxLength : mixed = 0
-
Limits string length if set.
Tags
Return values
stringgetAliasLength()
Returns maximum length of an alias in a select statement
public
getAliasLength() : int
Tags
Return values
intgetAscendingOrder()
Returns ascending order specifier for ORDER BY clause.
public
getAscendingOrder() : string
Tags
Return values
stringgetCharToDateFunction()
Returns function for converting string value into datetime.
public
getCharToDateFunction(mixed $value) : string
Parameters
- $value : mixed
-
String in YYYY-MM-DD HH:MI:SS format.
Tags
Return values
stringgetColumnTypeByField()
Returns a column type according to ScalarField object.
public
getColumnTypeByField(ScalarField $field) : string
Parameters
- $field : ScalarField
-
Type "source".
Tags
Return values
stringgetConcatFunction()
Returns function for concatenating database fields or expressions.
public
getConcatFunction() : string
Tags
Return values
stringgetConditionalAssignment()
public
getConditionalAssignment(string|SqlExpression $field, string $value) : string
Parameters
- $field : string|SqlExpression
- $value : string
Return values
stringgetConverter()
Returns callback to be called for a field value on fetch.
public
getConverter(ScalarField $field) : false|callable
Parameters
- $field : ScalarField
-
Type "source".
Tags
Return values
false|callablegetCurrentDateFunction()
Returns function for getting current date without time part.
public
getCurrentDateFunction() : string
Tags
Return values
stringgetCurrentDateTimeFunction()
Returns function for getting current time.
public
getCurrentDateTimeFunction() : string
Tags
Return values
stringgetDatetimeToDateFunction()
Returns function cast $value to datetime database type.
public
getDatetimeToDateFunction(mixed $value) : string
Parameters
- $value : mixed
-
Database field or expression to cast.
Tags
Return values
stringgetDateToCharFunction()
Returns function for converting database field or expression into string.
public
getDateToCharFunction(mixed $fieldName) : string
Parameters
- $fieldName : mixed
-
Database field or expression.
Tags
Return values
stringgetDescendingOrder()
Returns descending order specifier for ORDER BY clause.
public
getDescendingOrder() : string
Tags
Return values
stringgetFieldByColumnType()
Returns instance of a descendant from Entity\ScalarField that matches database type.
public
getFieldByColumnType(mixed $name, mixed $type[, array<string|int, mixed> $parameters = null ]) : ScalarField
Parameters
- $name : mixed
-
Database column name.
- $type : mixed
-
Database specific type.
- $parameters : array<string|int, mixed> = null
-
Additional information.
Tags
Return values
ScalarFieldgetIlikeOperator()
Returns case insensitive like expression.
public
getIlikeOperator(mixed $field, mixed $value) : string
Parameters
- $field : mixed
-
Database field or expression.
- $value : mixed
-
String to match.
Tags
Return values
stringgetInsertIgnore()
Makes an insert statement which will ignore duplicate keys errors.
public
getInsertIgnore(mixed $tableName, mixed $fields, mixed $sql) : string
Parameters
- $tableName : mixed
-
Table to insert.
- $fields : mixed
-
Fields list in braces.
- $sql : mixed
-
Select or values sql.
Tags
Return values
stringgetIsNullFunction()
Returns function for testing database field or expressions against NULL value. When it is NULL then $result will be returned.
public
getIsNullFunction(mixed $expression, mixed $result) : string
Parameters
- $expression : mixed
-
Database field or expression for NULL test.
- $result : mixed
-
Database field or expression to return when $expression is NULL.
Tags
Return values
stringgetLeftQuote()
Returns an identificator escaping left character.
public
getLeftQuote() : string
Tags
Return values
stringgetLengthFunction()
Returns function for getting length of database field or expression.
public
getLengthFunction(mixed $field) : string
Parameters
- $field : mixed
-
Database field or expression.
Tags
Return values
stringgetMatchAndExpression()
public
getMatchAndExpression(mixed $values[, mixed $prefixSearch = false ]) : mixed
Parameters
- $values : mixed
- $prefixSearch : mixed = false
getMatchFunction()
public
getMatchFunction(mixed $field, mixed $value) : mixed
Parameters
- $field : mixed
- $value : mixed
getMatchOrExpression()
public
getMatchOrExpression(mixed $values[, mixed $prefixSearch = false ]) : mixed
Parameters
- $values : mixed
- $prefixSearch : mixed = false
getOrderByIntField()
public
getOrderByIntField(string $field, array<string|int, mixed> $values[, bool $quote = true ]) : string
Parameters
- $field : string
- $values : array<string|int, mixed>
- $quote : bool = true
Return values
stringgetOrderByStringField()
public
getOrderByStringField(string $field, array<string|int, mixed> $values[, bool $quote = true ]) : string
Parameters
- $field : string
- $values : array<string|int, mixed>
- $quote : bool = true
Return values
stringgetQueryDelimiter()
Returns database specific query delimiter for batch processing.
public
getQueryDelimiter() : string
Tags
Return values
stringgetQueryTables()
public
getQueryTables(string $sql[, int $maxLevel = -1 ]) : array<string|int, mixed>
Parameters
- $sql : string
- $maxLevel : int = -1
Return values
array<string|int, mixed>getRandomFunction()
Returns function for getting random number.
public
getRandomFunction() : string
Tags
Return values
stringgetRegexpOperator()
Returns regexp expression.
public
getRegexpOperator(mixed $field, mixed $regexp) : string
Parameters
- $field : mixed
-
Database field or expression.
- $regexp : mixed
-
Regexp to match.
Tags
Return values
stringgetRightQuote()
Returns an identificator escaping right character.
public
getRightQuote() : string
Tags
Return values
stringgetRowNumber()
public
getRowNumber(mixed $variableName) : mixed
Parameters
- $variableName : mixed
getSha1Function()
Returns function to generate sha1 hash.
public
getSha1Function(mixed $field) : string
Parameters
- $field : mixed
-
Database field or expression.
Tags
Return values
stringgetSubstrFunction()
Returns function for getting part of string.
public
getSubstrFunction(string $str, int $from[, int $length = null ]) : string
If length is null or omitted, the substring starting from start until the end of the string will be returned.
$str and $from parameters are SQL unsafe.
Parameters
- $str : string
-
Database field or expression.
- $from : int
-
Start position.
- $length : int = null
-
Maximum length.
Return values
stringgetTopSql()
Transforms Sql according to $limit and $offset limitations.
public
getTopSql(mixed $sql, mixed $limit[, mixed $offset = 0 ]) : string
Parameters
- $sql : mixed
-
Sql text.
- $limit : mixed
-
Maximum number of rows to return.
- $offset : mixed = 0
-
Offset of the first row to return, starting from 0.
Tags
Return values
stringinitRowNumber()
public
initRowNumber(mixed $variableName) : mixed
Parameters
- $variableName : mixed
isBigType()
Checks is the field type is BIG
public
isBigType(mixed $type) : bool
Parameters
- $type : mixed
Return values
boolprepareAssignment()
Builds the string for the SQL assignment operation of the given column.
public
prepareAssignment(string $tableName, string $columnName, string $value) : string
Parameters
- $tableName : string
-
A table name.
- $columnName : string
-
A column name.
- $value : string
-
A value to assign.
Return values
stringprepareCorrelatedUpdate()
Builds correlated update DML.
public
prepareCorrelatedUpdate(mixed $tableName, mixed $tableAlias, mixed $fields, mixed $from, mixed $where) : string
Parameters
- $tableName : mixed
-
A table name.
- $tableAlias : mixed
-
A table alias.
- $fields : mixed
-
Array("column" => "expression")[] Update columns list.
- $from : mixed
-
Correlated tables.
- $where : mixed
-
Where clause.
Tags
Return values
stringprepareDeleteLimit()
Builds the DML string for the SQL DELETE command for the given table with limited rows number.
public
prepareDeleteLimit(mixed $tableName, array<string|int, mixed> $primaryFields, mixed $where, array<string|int, mixed> $order, mixed $limit) : string
Parameters
- $tableName : mixed
-
A table name.
- $primaryFields : array<string|int, mixed>
-
Array("column")[] Primary key columns list.
- $where : mixed
-
Sql where clause.
- $order : array<string|int, mixed>
-
Array("column" => asc|desc)[] Sort order.
- $limit : mixed
-
Rows to delete count.
Tags
Return values
string —(replace)
prepareInsert()
Builds the strings for the SQL INSERT command for the given table.
public
prepareInsert(string $tableName, array<string|int, mixed> $fields[, bool $returnAsArray = false ]) : array<string|int, mixed>
Parameters
- $tableName : string
-
A table name.
- $fields : array<string|int, mixed>
-
Array("column" => $value)[].
- $returnAsArray : bool = false
Return values
array<string|int, mixed> —(columnList, valueList, binds)
prepareMerge()
Builds the strings for the SQL MERGE command for the given table.
public
prepareMerge(mixed $tableName, array<string|int, mixed> $primaryFields, array<string|int, mixed> $insertFields, array<string|int, mixed> $updateFields) : array<string|int, mixed>
Parameters
- $tableName : mixed
-
A table name.
- $primaryFields : array<string|int, mixed>
-
Array("column")[] Primary key columns list.
- $insertFields : array<string|int, mixed>
-
Array("column" => $value)[] What to insert.
- $updateFields : array<string|int, mixed>
-
Array("column" => $value)[] How to update.
Tags
Return values
array<string|int, mixed> —(merge)
prepareMergeMultiple()
Builds the DML strings for the SQL REPLACE INTO command for the given table.
public
prepareMergeMultiple(mixed $tableName, array<string|int, mixed> $primaryFields, array<string|int, mixed> $insertRows) : array<string|int, mixed>
Parameters
- $tableName : mixed
-
A table name.
- $primaryFields : array<string|int, mixed>
-
Array("column")[] Primary key columns list.
- $insertRows : array<string|int, mixed>
-
Array(Array("column" => $value)[])[] Rows to insert.
Tags
Return values
array<string|int, mixed> —(replace)
prepareMergeSelect()
Builds the DML strings for the SQL INSERT INTO ON CONFLICT UPDATE command for the given table.
public
prepareMergeSelect(mixed $tableName, array<string|int, mixed> $primaryFields, array<string|int, mixed> $selectFields, mixed $select, mixed $updateFields) : string
Parameters
- $tableName : mixed
-
A table name.
- $primaryFields : array<string|int, mixed>
-
Array("column")[] Primary key columns list.
- $selectFields : array<string|int, mixed>
- $select : mixed
- $updateFields : mixed
Tags
Return values
string —(replace)
prepareMergeValues()
Returns prepared sql string for upsert multiple rows
public
prepareMergeValues(string $tableName, array<string|int, mixed> $primaryFields, array<string|int, mixed> $insertRows[, array<string|int, mixed> $updateFields = [] ]) : string
Parameters
- $tableName : string
-
Table name
- $primaryFields : array<string|int, mixed>
-
Fields that can be conflicting keys (primary, unique keys)
- $insertRows : array<string|int, mixed>
-
Rows to insert [['FIELD_NAME' =>'value',...],...], Attention! use same columns in each row
- $updateFields : array<string|int, mixed> = []
-
Fields to update, if empty - update all fields, can be only field names, or fieldname => expression or fieldname => value
Tags
Return values
stringprepareUpdate()
Builds the strings for the SQL UPDATE command for the given table.
public
prepareUpdate(string $tableName, array<string|int, mixed> $fields) : array<string|int, mixed>
Parameters
- $tableName : string
-
A table name.
- $fields : array<string|int, mixed>
-
Array("column" => $value)[].
Return values
array<string|int, mixed> —(update, binds)
quote()
Returns quoted identifier.
public
quote(mixed $identifier) : string
Parameters
- $identifier : mixed
-
Table or Column name.
Tags
Return values
stringsoftCastTextToChar()
Returns expression for text field being used in group or order
public
softCastTextToChar(mixed $fieldName) : string
Parameters
- $fieldName : mixed
Tags
Return values
stringvalues()
Returns identifier for usage in VALUES.
public
values(mixed $identifier) : string
Parameters
- $identifier : mixed
-
Column name.