\Google\AdsApi\AdManager\Util\v202105StatementBuilder

Builds statements that can be used in PQL queries.

Typical usage:

$statementBuilder = (new StatementBuilder())
    ->where('lastModifiedDateTime > :yesterday AND status = :status')
    ->orderBy('id ASC')
    ->limit(200)
    ->withBindVariableValue(
        'yesterday',
        AdManagerDateTimes::fromDateTime(new DateTime(
            '-1 day',
            new DateTimeZone('America/New_York')
        )))
    ->withBindVariableValue('status', SomeStatus::STATUS);

$statement = $statementBuilder->toStatement();
//...
$statementBuilder->increaseOffsetBy(200);
$statement = $statementBuilder->toStatement();

Summary

Methods
Properties
Constants
__construct()
withBindVariableValue()
toStatement()
select()
from()
where()
limit()
offset()
increaseOffsetBy()
getOffset()
removeLimitAndOffset()
orderBy()
getBindVariableMap()
No public properties found
SUGGESTED_PAGE_LIMIT
SELECT
FROM
WHERE
LIMIT
OFFSET
ORDER_BY
No protected methods found
No protected properties found
N/A
removeKeyword()
validateQuery()
buildQuery()
$select
$from
$where
$limit
$offset
$orderBy
$valueMap
N/A

Constants

SUGGESTED_PAGE_LIMIT

SUGGESTED_PAGE_LIMIT

SELECT

SELECT

FROM

FROM

WHERE

WHERE

LIMIT

LIMIT

OFFSET

OFFSET

ORDER_BY

ORDER_BY

Properties

$select

$select :

Type

$from

$from :

Type

$where

$where :

Type

$limit

$limit :

Type

$offset

$offset :

Type

$orderBy

$orderBy :

Type

$valueMap

$valueMap :

Type

Methods

__construct()

__construct()

Creates an empty statement builder ready to have statement parts added to it.

withBindVariableValue()

withBindVariableValue(string  $key,mixed  $value): \Google\AdsApi\AdManager\Util\v202105\StatementBuilder

Adds a bind variable value to the statement.

Parameters

string $key

the value key

mixed $value

the value either as a primitive, which will be converted to a PQL Value object, or a PQL Value object

Returns

\Google\AdsApi\AdManager\Util\v202105\StatementBuilder

this builder

toStatement()

toStatement(): \Google\AdsApi\AdManager\v202105\Statement

Gets the statement representing the state of this statement builder.

Returns

\Google\AdsApi\AdManager\v202105\Statement

select()

select(string  $columns): \Google\AdsApi\AdManager\Util\v202105\StatementBuilder

Sets the statement `SELECT` clause in the form of 'a, b, .

..'.

Only necessary for statements being sent to the PublisherQueryLanguageService. The 'SELECT ' keyword will be ignored.

Parameters

string $columns

the statement select clause without SELECT

Returns

\Google\AdsApi\AdManager\Util\v202105\StatementBuilder

this builder

from()

from(string  $table): \Google\AdsApi\AdManager\Util\v202105\StatementBuilder

Sets the statement `FROM` clause in the form of 'table'.

Only necessary for statements being sent to the PublisherQueryLanguageService. The 'FROM ' keyword will be ignored.

Parameters

string $table

the statement from clause without FROM

Returns

\Google\AdsApi\AdManager\Util\v202105\StatementBuilder

this builder

where()

where(string  $conditions): \Google\AdsApi\AdManager\Util\v202105\StatementBuilder

Sets the statement `WHERE` clause in the form of `'WHERE <condition> {[AND | OR] <condition> .

..}'`. E.g., 'a = b OR b = c'. The 'WHERE ' keyword will be ignored.

Parameters

string $conditions

the statement query without WHERE

Returns

\Google\AdsApi\AdManager\Util\v202105\StatementBuilder

this builder

limit()

limit(integer  $count): \Google\AdsApi\AdManager\Util\v202105\StatementBuilder

Sets the statement `LIMIT` clause in the form of `'LIMIT <count>'`. E.g., 1000.

Parameters

integer $count

the statement limit

Returns

\Google\AdsApi\AdManager\Util\v202105\StatementBuilder

this builder

offset()

offset(integer  $count): \Google\AdsApi\AdManager\Util\v202105\StatementBuilder

Sets the statement `OFFSET` clause in the form of `'OFFSET <count>'`. E.g., 200.

Parameters

integer $count

the statement offset

Returns

\Google\AdsApi\AdManager\Util\v202105\StatementBuilder

this builder

getOffset()

getOffset(): integer

Gets the current offset.

Returns

integer

orderBy()

orderBy(string  $orderBy): \Google\AdsApi\AdManager\Util\v202105\StatementBuilder

Sets the statement `ORDER BY` clause in the form of `'ORDER BY <property> [ASC | DESC]'`. E.g., 'type ASC, lastModifiedDateTime DESC'. The 'ORDER BY' keyword will be ignored.

Parameters

string $orderBy

the statement order by without ORDER BY

Returns

\Google\AdsApi\AdManager\Util\v202105\StatementBuilder

this builder

getBindVariableMap()

getBindVariableMap(): array

Returns the key to value bind variable map.

Returns

array

removeKeyword()

removeKeyword(string  $clause,string  $keyword): string

Removes the specified keyword from the clause, if present. Will remove `keyword + ' '`.

Parameters

string $clause
string $keyword

Returns

string —

a new string with the keyword + ' ' removed

validateQuery()

validateQuery()

Checks that the query is valid.

Throws

\InvalidArgumentException

if the query is invalid

buildQuery()

buildQuery(): string

Builds the query from the clauses.

Returns

string —

the query