Select() public method

Only necessary for statements being sent to the {@code PublisherQueryLanguageService}. The "SELECT " keyword will be ignored.
public Select ( string $columns ) : StatementBuilder
$columns string the statement select clause without "SELECT"
return StatementBuilder a reference to this object
 /**
  * @covers StatementBuilder::ToStatement
  */
 public function testToStatementForPqlTableWithKeywords()
 {
     $expectedQuery = 'SELECT Id FROM table WHERE a = b AND b = c ORDER BY a ' . 'ASC, b DESC LIMIT 200 OFFSET 0';
     $statementBuilder = new StatementBuilder();
     $query = $statementBuilder->Select('Id')->From('FrOM table')->Where('WHERE a = b AND b = c')->OrderBy('order BY a ASC, b DESC')->Limit(200)->Offset(0)->ToStatement()->query;
     $this->assertEquals($expectedQuery, $query);
 }
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php';
require_once 'Google/Api/Ads/Dfp/Util/v201508/Pql.php';
require_once 'Google/Api/Ads/Dfp/Util/v201508/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
try {
    // Get DfpUser from credentials in "../auth.ini"
    // relative to the DfpUser.php file's directory.
    $user = new DfpUser();
    // Log SOAP XML request and response.
    $user->LogDefaults();
    // Get the PublisherQueryLanguageService.
    $pqlService = $user->GetService('PublisherQueryLanguageService', 'v201508');
    // Create statement to select all line items.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Select('Id, BrowserName, MajorVersion, MinorVersion')->From('Browser')->OrderBy('BrowserName ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Default for result sets.
    $resultSet = null;
    $combinedResultSet = null;
    $i = 0;
    do {
        // Get all browsers.
        $resultSet = $pqlService->select($statementBuilder->ToStatement());
        // Combine result sets with previous ones.
        $combinedResultSet = !isset($combinedResultSet) ? $resultSet : Pql::CombineResultSets($combinedResultSet, $resultSet);
        printf("%d) %d browsers beginning at offset %d were found.\n", $i++, isset($resultSet->rows) ? count($resultSet->rows) : 0, $statementBuilder->GetOffset());
        $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    } while (isset($resultSet->rows) && count($resultSet->rows) > 0);
    // Change to your file location.
    $filePath = sprintf("%s/Browsers-%s.csv", sys_get_temp_dir(), uniqid());
    $fp = fopen($filePath, 'w');
require_once 'Google/Api/Ads/Dfp/Util/v201508/Pql.php';
require_once 'Google/Api/Ads/Dfp/Util/v201508/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
try {
    // Get DfpUser from credentials in "../auth.ini"
    // relative to the DfpUser.php file's directory.
    $user = new DfpUser();
    // Log SOAP XML request and response.
    $user->LogDefaults();
    // Get the PublisherQueryLanguageService.
    $pqlService = $user->GetService('PublisherQueryLanguageService', 'v201508');
    // Set the type of geo target.
    $geoTargetType = 'City';
    // Create statement to select all line items.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Select('Id, Name, CanonicalParentId, ParentIds, CountryCode, Type, Targetable')->From('Geo_Target')->Where('Type = :Type AND Targetable = true')->OrderBy('CountryCode ASC, Name ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT)->WithBindVariableValue('Type', $geoTargetType);
    // Default for result sets.
    $resultSet = null;
    $combinedResultSet = null;
    $i = 0;
    do {
        // Get all cities.
        $resultSet = $pqlService->select($statementBuilder->ToStatement());
        // Combine result sets with previous ones.
        $combinedResultSet = !isset($combinedResultSet) ? $resultSet : Pql::CombineResultSets($combinedResultSet, $resultSet);
        printf("%d) %d geo targets beginning at offset %d were found.\n", $i++, isset($resultSet->rows) ? count($resultSet->rows) : 0, $statementBuilder->GetOffset());
        $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    } while (isset($resultSet->rows) && count($resultSet->rows) > 0);
    // Change to your file location.
    $filePath = sprintf("%s/%s-%s.csv", sys_get_temp_dir(), $geoTargetType, uniqid());
    $fp = fopen($filePath, 'w');
$path = dirname(__FILE__) . '/../../../../src';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php';
require_once 'Google/Api/Ads/Dfp/Util/v201608/Pql.php';
require_once 'Google/Api/Ads/Dfp/Util/v201608/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
try {
    // Get DfpUser from credentials in "../auth.ini"
    // relative to the DfpUser.php file's directory.
    $user = new DfpUser();
    // Log SOAP XML request and response.
    $user->LogDefaults();
    $pqlService = $user->GetService('PublisherQueryLanguageService', 'v201608');
    // Create statement to select all programmatic buyers.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Select('BuyerAccountId, Name')->From('Programmatic_Buyer')->OrderBy('BuyerAccountId ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Retrieve a small amount of rows at a time, paging through until all rows
    // have been retrieved.
    $resultSet = null;
    $combinedResultSet = null;
    $i = 0;
    do {
        $resultSet = $pqlService->select($statementBuilder->ToStatement());
        // Combine result sets with previous ones.
        $combinedResultSet = $combinedResultSet !== null ? $resultSet : Pql::CombineResultSets($combinedResultSet, $resultSet);
        printf("%d) %d programmatic buyers beginning at offset %d were found.\n", $i++, $resultSet->rows !== null ? count($resultSet->rows) : 0, $statementBuilder->GetOffset());
        $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    } while ($resultSet->rows !== null && count($resultSet->rows) > 0);
    // Change to another file location if desired.
    $filePath = sprintf("%s/programmatic-buyers-%s.csv", sys_get_temp_dir(), uniqid());
    $fp = fopen($filePath, 'w');
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php';
require_once 'Google/Api/Ads/Dfp/Util/v201602/Pql.php';
require_once 'Google/Api/Ads/Dfp/Util/v201602/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
try {
    // Get DfpUser from credentials in "../auth.ini"
    // relative to the DfpUser.php file's directory.
    $user = new DfpUser();
    // Log SOAP XML request and response.
    $user->LogDefaults();
    // Get the PublisherQueryLanguageService.
    $pqlService = $user->GetService('PublisherQueryLanguageService', 'v201602');
    // Create statement to select line items whose names begin with "line item".
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Select('Id, Name, Status')->From('Line_Item')->Where('Name LIKE \'line item%\'')->OrderBy('Id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Default for result sets.
    $combinedResultSet = null;
    $resultSet = null;
    $i = 0;
    do {
        // Get line items like 'line item%'.
        $resultSet = $pqlService->select($statementBuilder->ToStatement());
        // Combine result sets with previous ones.
        $combinedResultSet = !isset($combinedResultSet) ? $resultSet : Pql::CombineResultSets($combinedResultSet, $resultSet);
        printf("%d) %d line items beginning at offset %d were found.\n", $i++, isset($resultSet->rows) ? count($resultSet->rows) : 0, $statementBuilder->GetOffset());
        $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    } while (isset($resultSet->rows) && count($resultSet->rows) > 0);
    // Change to your file location.
    $filePath = sprintf("%s/Line-Items-Named-Like-%s.csv", sys_get_temp_dir(), uniqid());
    ob_start();
Example #6
0
require_once 'Google/Api/Ads/Dfp/Util/v201411/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
try {
    // Get DfpUser from credentials in "../auth.ini"
    // relative to the DfpUser.php file's directory.
    $user = new DfpUser();
    // Log SOAP XML request and response.
    $user->LogDefaults();
    // Get the PublisherQueryLanguageService.
    $pqlService = $user->GetService('PublisherQueryLanguageService', 'v201411');
    // Create statement to select all line items.
    $lineItemStatementBuilder = new StatementBuilder();
    $lineItemStatementBuilder->Select('Id, Name, Status')->From('Line_Item')->OrderBy('Id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Create statement to select all ad units.
    $adUnitStatementBuilder = new StatementBuilder();
    $adUnitStatementBuilder->Select('Id, Name')->From('Ad_Unit')->OrderBy('Id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    $lineItemFilePath = fetchMatchTable($lineItemStatementBuilder, $pqlService, "Line-Item-Matchtable");
    $adUnitFilePath = fetchMatchTable($adUnitStatementBuilder, $pqlService, "Ad-Unit-Matchtable");
    printf("Line items saved to %s\n", $lineItemFilePath);
    printf("Ad units saved to %s\n", $adUnitFilePath);
} catch (OAuth2Exception $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (ValidationException $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (Exception $e) {
    printf("%s\n", $e->getMessage());
}
/**
 * Fetches a match table from a PQL statement and writes it to a file.
 */
function fetchMatchTable($statementBuilder, $pqlService, $fileName)