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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*-------------------------------------------------------------------------
*
* FILE
* pglobject.cc
*
* DESCRIPTION
* implementation of the PgLargeObject class.
* PgLargeObject encapsulates a frontend to backend connection
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.3 1997/02/13 10:00:34 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
extern "C" {
#include "libpq/libpq-fs.h"
}
#include "pglobject.h"
// ****************************************************************
//
// PgLargeObject Implementation
//
// ****************************************************************
// default constructor
// creates a large object in the default database
PgLargeObject::PgLargeObject(const char* dbName)
: PgConnection(dbName)
{
Init();
Create();
Open();
}
// constructor
// open an existing large object in the default database
PgLargeObject::PgLargeObject(Oid lobjId, const char* dbName)
: PgConnection(dbName)
{
Init(lobjId);
if ( !pgObject )
Create();
Open();
}
// constructor
// create a large object in the given database
PgLargeObject::PgLargeObject(const PgEnv& env, const char* dbName)
: PgConnection(env, dbName)
{
Init();
Create();
Open();
}
// constructor
// open an existing large object in the given database
PgLargeObject::PgLargeObject(const PgEnv& env, const char* dbName, Oid lobjId)
: PgConnection(env, dbName)
{
Init(lobjId);
if ( !pgObject )
Create();
Open();
}
// destructor -- closes large object
PgLargeObject::~PgLargeObject()
{
Close();
}
// PgLargeObject::Init
// Initialize the variables
void PgLargeObject::Init(Oid lobjId)
{
pgFd = -1;
pgObject = lobjId;
}
// PgLargeObject::create
// create large object and check for errors
void PgLargeObject::Create()
{
// Create the object
pgObject = lo_creat(pgConn, INV_READ|INV_WRITE);
// Check for possible errors
if (!pgObject)
SetErrorMessage( "PgLargeObject: can't create large object" );
}
// PgLargeObject::open
// open large object and check for errors
void PgLargeObject::Open()
{
// Open the object
pgFd = lo_open(pgConn, pgObject, INV_READ|INV_WRITE);
// Check for possible errors
string objStr( IntToString(pgObject) );
if (pgFd < 0)
SetErrorMessage( "PgLargeObject: can't open large object " + objStr );
else
SetErrorMessage( "PgLargeObject: created and opened large object " + objStr );
}
// PgLargeObject::unlink
// destruct large object and delete from it from the database
int PgLargeObject::Unlink()
{
// Unlink the object
int temp = lo_unlink(pgConn, pgObject);
// Initialize the large object upon success
if (!temp) {
Close();
Init();
}
// Return the status
return temp;
}
|