]> granicus.if.org Git - postgresql/blob - src/interfaces/libpq++/pgcursordb.cc
Here's a version of my suggested diffs transplanted to 7.1 beta 5. I'm
[postgresql] / src / interfaces / libpq++ / pgcursordb.cc
1 /*-------------------------------------------------------------------------
2  *
3  *   FILE
4  *      pgcursordb.cpp
5  *
6  *   DESCRIPTION
7  *      implementation of the PgCursor class.
8  *   PgCursor encapsulates a cursor interface to the backend
9  *
10  * Copyright (c) 1994, Regents of the University of California
11  *
12  * IDENTIFICATION
13  *        $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.5 2001/05/09 17:29:10 momjian Exp $
14  *
15  *-------------------------------------------------------------------------
16  */
17  
18 #include "pgcursordb.h"
19  
20
21 using namespace std;
22
23
24 // ****************************************************************
25 //
26 // PgCursor Implementation
27 //
28 // ****************************************************************
29 // Make a connection to the specified database with default environment
30 // See PQconnectdb() for conninfo usage
31 PgCursor::PgCursor(const char* conninfo, const char* cursor)
32    : PgTransaction(conninfo), pgCursor(cursor)
33 {}
34
35 // Do not make a connection to the backend -- just query
36 // Connection should not be closed after the object destructs since some
37 // other object is using the connection
38 //PgCursor::PgCursor(const PgConnection& conn, const char* cursor)
39 //   : PgTransaction(conn), pgCursor(cursor)
40 //{}
41
42 // Destructor: End the transaction block
43 PgCursor::~PgCursor()
44 {
45         Close();
46 }
47
48
49 // ****************************************************************
50 //
51 // PgCursor: Cursor Interface Implementation
52 //
53 // ****************************************************************
54 // Declare a cursor: name has already been supplied in the constructor
55 int PgCursor::Declare(string query, bool binary)
56 {
57         string cmd = "DECLARE " + pgCursor;
58         if ( binary )
59              cmd += " BINARY";
60         cmd += " CURSOR FOR " + query;
61         return ExecCommandOk( cmd.c_str() );
62 } // End Declare()
63
64 // Fetch ALL tuples in given direction
65 int PgCursor::Fetch(const char* dir)
66 {
67         return Fetch("ALL", dir);
68 } // End Fetch()
69
70 // Fetch specified amount of tuples in given direction
71 int PgCursor::Fetch(unsigned num, const char* dir)
72 {
73         return Fetch( IntToString(num), dir );
74 } // End Fetch()
75
76 // Create and execute the actual fetch command with the given arguments
77 int PgCursor::Fetch(string num, string dir)
78 {
79         string cmd = "FETCH " + dir + " " + num + " IN " + pgCursor;
80         return ExecTuplesOk( cmd.c_str() );
81 } // End Fetch()
82
83 // Close the cursor: no more queries using the cursor should be allowed
84 // Actually, the backend should take care of it.
85 int PgCursor::Close()
86 {
87         string cmd = "CLOSE " + pgCursor;
88         return ExecCommandOk( cmd.c_str() );
89 } // End CloseCursor()