aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq++/examples/testlibpq0.cc
blob: 43f8e93d15ed031f9cf8167bbaa8af7732c0ba05 (plain)
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
/*-------------------------------------------------------------------------
 *
 * testlibpq0.c--
 *    small test program for libpq++, 
 * small interactive loop where queries can be entered interactively
 * and sent to the backend
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *    $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.3 1997/02/13 10:00:42 scrappy Exp $
 *
 *-------------------------------------------------------------------------
 */

#include <iostream.h>
#include <libpq++.h>

int main()
{
  // Open the connection to the database and make sure it's OK
  PgDatabase data("template1");
  if ( data.ConnectionBad() ) {
      cout << "Connection was unsuccessful..." << endl
           << "Error message returned: " << data.ErrorMessage() << endl;
      return 1;
  }
  else
      cout << "Connection successful...  Enter queries below:" << endl;
    
  // Interactively obtain and execute queries
  ExecStatusType status;
  string buf;
  int done = 0;
  while (!done)
    {
      cout << "> ";
      cout.flush();
      getline(cin, buf);
      if ( buf != "" )
	       if ( (status = data.Exec( buf.c_str() )) == PGRES_TUPLES_OK ) 
	          data.DisplayTuples();
	       else
	          cout << "No tuples returned..." << endl
	               << "status = " << status << endl
	               << "Error returned: " << data.ErrorMessage() << endl;
      else
	       done = 1;
      }
  return 0;
} // End main()