コード例 #1
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the PublisherQueryLanguageService.
      PublisherQueryLanguageService pqlService =
          (PublisherQueryLanguageService) user.GetService(
              DfpService.v201308.PublisherQueryLanguageService);

      int pageSize = 500;

      // Create statement to select all line items.
      String selectStatement = "SELECT Id, Name, Status FROM Line_Item where Name LIKE " +
            "'line item%' order by Id ASC LIMIT " + pageSize;
      int offset = 0;
      int resultSetSize = 0;
      List<Row> allRows = new List<Row>();
      ResultSet resultSet;

      try {
        do {
          StatementBuilder statementBuilder =
              new StatementBuilder(selectStatement + " OFFSET " + offset);

          // Get line items like 'line item%'.
          resultSet = pqlService.select(statementBuilder.ToStatement());

          // Collect all line items from each page.
          allRows.AddRange(resultSet.rows);

          // Display results.
          Console.WriteLine(PqlUtilities.ResultSetToString(resultSet));

          offset += pageSize;
          resultSetSize = resultSet.rows == null ? 0 : resultSet.rows.Length;
        } while (resultSetSize == pageSize);

        Console.WriteLine("Number of results found: " + allRows.Count);

        // Optionally, save all rows to a CSV.
        // Get a string array representation of the data rows.
        resultSet.rows = allRows.ToArray();
        List<String[]> rows = PqlUtilities.ResultSetToStringArrayList(resultSet);

        // Write the contents to a csv file.
        CsvFile file = new CsvFile();
        file.Headers.AddRange(rows[0]);
        file.Records.AddRange(rows.GetRange(1, rows.Count - 1).ToArray());
        file.Write("line_items_named_like_" + GetTimeStamp() + ".csv");
      } catch (Exception ex) {
        Console.WriteLine("Failed to get line items. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #2
0
    public void TestAllStatementBuilderPartialFunctions() {
      StatementBuilder statementBuilder = new StatementBuilder()
          .Select("Name, Id")
          .From("Geo_Target")
          .Where("Targetable = :targetable")
          .OrderBy("Id DESC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .Offset(0)
          .AddValue("targetable", true)
          .IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .RemoveLimitAndOffset();
      Assert.AreEqual(null, statementBuilder.GetOffset());

      Statement expectedStatement = new Statement();
      expectedStatement.query = "SELECT Name, Id FROM Geo_Target"
          + " WHERE Targetable = :targetable ORDER BY Id DESC";
      String_ValueMapEntry targetableEntry = new String_ValueMapEntry();
      targetableEntry.key = "targetable";
      BooleanValue targetableValue = new BooleanValue();
      targetableValue.value = true;
      targetableEntry.value = targetableValue;
      expectedStatement.values = new String_ValueMapEntry[] {targetableEntry};
      Assert.True(StatementsAreEqual(expectedStatement, statementBuilder.ToStatement()));
    }
コード例 #3
0
    public void TestStatementBuilderBasicStatement() {
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("ID = 1");

      Statement expectedStatement = new Statement();
      expectedStatement.query = "WHERE ID = 1";
      expectedStatement.values = new String_ValueMapEntry[0];

      Assert.True(StatementsAreEqual(expectedStatement,
                                     statementBuilder.ToStatement()));
    }
コード例 #4
0
    public void TestStatementBuilderIncludesKeywordPrefix() {
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("WHEREWITHALL = 1");

      Statement expectedStatement = new Statement();
      expectedStatement.query = "WHERE WHEREWITHALL = 1";
      expectedStatement.values = new String_ValueMapEntry[0];

      Assert.True(StatementsAreEqual(expectedStatement,
        statementBuilder.ToStatement()));
    }
コード例 #5
0
    public void TestStatementBuilderBlankStatement() {
      StatementBuilder statementBuilder = new StatementBuilder();

      Statement expectedStatement = new Statement();
      expectedStatement.query = "";
      expectedStatement.values = new String_ValueMapEntry[0];

      Assert.True(StatementsAreEqual(expectedStatement,
                                     statementBuilder.ToStatement()));
    }