aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq++/pgconnection.h
blob: 4310dac61db3b823ab951a82c01359e28093b5ee (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*-------------------------------------------------------------------------
 *
 * pgconnection.h
 *    
 *
 *   DESCRIPTION
 *		Postgres Connection Class: 
 *		   Manage Postgres backend connection
 *
 *   NOTES
 *      Currently under construction.
 *
 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 * 
 * $Id: pgconnection.h,v 1.10 2001/02/10 02:31:30 tgl Exp $
 *
 *-------------------------------------------------------------------------
 */
 
#ifndef PGCONNECTION_H
#define PGCONNECTION_H

extern "C" {
#include "config.h"
}

/* We assume that the C++ compiler will have these keywords, even though
 * config.h may have #define'd them to empty because C compiler doesn't.
 */
#undef const
#undef inline
#undef signed
#undef volatile

#ifdef HAVE_CXX_STRING_HEADER
#include <string>
#endif

extern "C" {
#include "postgres_fe.h"
#include "libpq-fe.h"
}

#ifdef HAVE_NAMESPACE_STD
using namespace std;
#endif


// ****************************************************************
//
// PgConnection - a connection made to a postgres backend
//
// ****************************************************************
// This class contains all the information about the connection
// to the backend process.  All the database classes should be
// derived from this class to obtain the connection interface.
class PgConnection {
protected:
  PGconn* pgConn;				// Connection Structure
  PGresult* pgResult;			// Current Query Result
  int pgCloseConnection; // TRUE if connection should be closed by destructor
  
public:
   PgConnection(const char* conninfo); 	// use reasonable & environment defaults
   virtual ~PgConnection(); 			// close connection and clean up
   
   // Connection status and error messages
   ConnStatusType Status();
   int ConnectionBad();
   const char* ErrorMessage();
  
   // returns the database name of the connection
   const char* DBName();

   // Query Execution interface
   ExecStatusType Exec(const char* query);  // send a query to the backend
   int ExecCommandOk(const char* query);    // send a command and check if it's OK
   int ExecTuplesOk(const char* query);     // send a command and check if tuples are returned
   PGnotify* Notifies();
    
protected:
   ConnStatusType Connect(const char* conninfo);
   void CloseConnection();
   string IntToString(int);
   // Default constructor is only available to subclasses
   PgConnection();

private:
// We don't support copying of PgConnection objects,
// so make copy constructor and assignment op private.
   PgConnection(const PgConnection&);
   PgConnection& operator= (const PgConnection&);
};

#endif	// PGCONNECTION_H