$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'); // Write the result set to a CSV. fputcsv($fp, Pql::GetColumnLabels($combinedResultSet)); foreach ($combinedResultSet->rows as $row) { fputcsv($fp, Pql::GetRowStringValues($row)); } fclose($fp); printf("Browsers saved to %s\n", $filePath); } 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) { $resultSet = null; $combinedResultSet = null; do { $resultSet = $pqlService->select($statementBuilder->ToStatement()); // Combine result sets with previous ones. $combinedResultSet = !isset($combinedResultSet) ? $resultSet : Pql::CombineResultSets($combinedResultSet, $resultSet); $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(), $fileName, uniqid()); $fp = fopen($filePath, 'w'); // Write the result set to a CSV. fputcsv($fp, Pql::GetColumnLabels($combinedResultSet)); foreach ($combinedResultSet->rows as $row) { fputcsv($fp, Pql::GetRowStringValues($row)); } fclose($fp); return $filePath; }
/** * Adds a value to the statement in the form of a {@code Value}. * * @param string $key the value key * @param mixed $value the value either as a primitive, which will be * converted to a PQL Value object, or a PQL Value object * @return StatementBuilder a reference to this object */ public function WithBindVariableValue($key, $value) { $this->valueMap[$key] = Pql::CreateValue($value); return $this; }
/** * @covers Pql::CombineResultSets * @expectedException InvalidArgumentException */ public function testCombineResultSetWithBadColumnsThrowsException() { $row1 = new Row(array($this->textValue1, $this->booleanValue1, $this->numberValue1)); $row2 = new Row(array($this->textValue2, $this->booleanValue2, $this->numberValue2)); $row3 = new Row(array($this->textValue3, $this->booleanValue3)); $resultSet1 = new ResultSet(array($this->column1, $this->column2, $this->column3), array($row1, $row2)); $resultSet2 = new ResultSet(array($this->column1, $this->column2), array($row3)); Pql::CombineResultSets($resultSet1, $resultSet2); }