blob: 125c9427a5ce1f135504eefdd2720dcf165b2dcf (
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
|
/*-------------------------------------------------------------------------
*
* pgconnection.h
*
*
* DESCRIPTION
* Postgres Connection Class:
* Manage Postgres backend connection
*
* NOTES
* Currently under construction.
*
* Copyright (c) 1994, Regents of the University of California
*
*-------------------------------------------------------------------------
*/
#ifndef PGCONN_H
#define PGCONN_H
#include <stdio.h>
#include "pgenv.h"
extern "C" {
#include "libpq-fe.h"
}
// ****************************************************************
//
// 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:
PgEnv pgEnv; // Current connection environment
PGconn* pgConn; // Connection Structures
PGresult* pgResult; // Query Result
string pgErrorMessage; // Error messages container
int pgCloseConnection; // Flag indicating whether the connection should be closed or not
public:
PgConnection(const char* dbName); // use reasonable defaults
PgConnection(const PgEnv& env, const char* dbName); // connect to the database with
// given environment and database name
virtual ~PgConnection(); // close connection and clean up
// Connection status and error messages
ConnStatusType Status();
int ConnectionBad() { return Status() == CONNECTION_BAD; }
const char* ErrorMessage() const { return pgErrorMessage.c_str(); }
// returns the database name of the connection
const char* DBName() const { return PQdb(pgConn); }
// 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* dbName);
void SetErrorMessage(const string&, int append = 0);
string IntToString(int);
protected:
PgConnection();
PgConnection(const PgConnection&);
};
#endif // PGCONN_H
|