File: test071.cxx

package info (click to toggle)
libpqxx 4.0.1%2Bdfsg3-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,012 kB
  • ctags: 9,469
  • sloc: sh: 11,289; cpp: 10,801; xml: 1,256; makefile: 287; ansic: 195; python: 159
file content (71 lines) | stat: -rw-r--r-- 1,958 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <map>

#include "test_helpers.hxx"

using namespace PGSTD;
using namespace pqxx;


// Test program for libpqxx.  Issue queries through a pipeline, and retrieve
// results both in-order and out-of-order.
namespace
{
typedef map<pipeline::query_id, int> Exp;

template<typename MAPIT>
void checkresult(pipeline &P, MAPIT c)
{
  const result r = P.retrieve(c->first);
  const int val = r.at(0).at(0).as(int(0));
  PQXX_CHECK_EQUAL(val, c->second, "Wrong result from pipeline.");
}


void test_071(transaction_base &W)
{
  pipeline P(W);

  // Keep expected result for every query we issue
  Exp values;

  // Insert queries returning various numbers
  for (int i=1; i<10; ++i) values[P.insert("SELECT " + to_string(i))] = i;

  // Retrieve results in query_id order, and compare to expected values
  for (Exp::const_iterator c=values.begin(); c!=values.end(); ++c)
    checkresult(P, c);

  PQXX_CHECK(P.empty(), "Pipeline was not empty retrieving all results.");

  values.clear();

  // Insert more queries returning various numbers
  P.retain(20);
  for (int i=100; i>90; --i) values[P.insert("SELECT " + to_string(i))] = i;

  P.resume();

#ifdef PQXX_HAVE_REVERSE_ITERATOR
  // Retrieve results in reverse order
  for (Exp::reverse_iterator c=values.rbegin(); c!=values.rend(); ++c)
    checkresult(P, c);
#endif	// PQXX_HAVE_REVERSE_ITERATOR

  values.clear();
  P.retain(10);
  for (int i=1010; i>1000; --i) values[P.insert("SELECT "+to_string(i))] = i;
  for (Exp::const_iterator c=values.begin(); c!=values.end(); ++c)
  {
    if (P.is_finished(c->first))
      cout << "Query #" << c->first << " completed despite retain()" << endl;
  }

  // See that all results are retrieved by complete()
  P.complete();
  for (Exp::const_iterator c=values.begin(); c!=values.end(); ++c)
    PQXX_CHECK(P.is_finished(c->first), "Query not finished after complete().");
}
} // namespace

PQXX_REGISTER_TEST_C(test_071, asyncconnection)