aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq++/pgcursordb.cc
blob: 182911817a130ae3ad0b236f49940802e0df694a (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
/*-------------------------------------------------------------------------
*
*	FILE
*	pgcursordb.cpp
*
*	DESCRIPTION
*	   implementation of the PgCursor class.
*	PgCursor encapsulates a cursor interface to the backend
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
*	  $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.8 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/

#include "pgcursordb.h"

#ifdef HAVE_NAMESPACE_STD
using namespace std;
#endif


// ****************************************************************
//
// PgCursor Implementation
//
// ****************************************************************
// Make a connection to the specified database with default environment
// See PQconnectdb() for conninfo usage
PgCursor::PgCursor(const char* conninfo, const char* cursor)
		: PgTransaction(conninfo), pgCursor(cursor)
{}

// Do not make a connection to the backend -- just query
// Connection should not be closed after the object destructs since some
// other object is using the connection
//PgCursor::PgCursor(const PgConnection& conn, const char* cursor)
//	 : PgTransaction(conn), pgCursor(cursor)
//{}

// Destructor: End the transaction block

PgCursor::~PgCursor()
{
	Close();
}


// ****************************************************************
//
// PgCursor: Cursor Interface Implementation
//
// ****************************************************************
// Declare a cursor: name has already been supplied in the constructor
int PgCursor::Declare(string query, bool binary)
{
	string cmd = "DECLARE " + pgCursor;
	if ( binary )
		cmd += " BINARY";
	cmd += " CURSOR FOR " + query;
	return ExecCommandOk( cmd.c_str() );
}

// Fetch ALL tuples in given direction
int PgCursor::Fetch(const char* dir)
{
	return Fetch("ALL", dir);
}

// Fetch specified amount of tuples in given direction
int PgCursor::Fetch(unsigned num, const char* dir)
{
	return Fetch( IntToString(num), dir );
}

// Create and execute the actual fetch command with the given arguments
int PgCursor::Fetch(string num, string dir)
{
	string cmd = "FETCH " + dir + " " + num + " IN " + pgCursor;
	return ExecTuplesOk( cmd.c_str() );
}

// Close the cursor: no more queries using the cursor should be allowed
// Actually, the backend should take care of it.
int PgCursor::Close()
{
	string cmd = "CLOSE " + pgCursor;
	return ExecCommandOk( cmd.c_str() );
}