1 /*-------------------------------------------------------------------------
7 * implementation of the PgCursor class.
8 * PgCursor encapsulates a cursor interface to the backend
10 * Copyright (c) 1994, Regents of the University of California
13 * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.5 2001/05/09 17:29:10 momjian Exp $
15 *-------------------------------------------------------------------------
18 #include "pgcursordb.h"
24 // ****************************************************************
26 // PgCursor Implementation
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)
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)
42 // Destructor: End the transaction block
49 // ****************************************************************
51 // PgCursor: Cursor Interface Implementation
53 // ****************************************************************
54 // Declare a cursor: name has already been supplied in the constructor
55 int PgCursor::Declare(string query, bool binary)
57 string cmd = "DECLARE " + pgCursor;
60 cmd += " CURSOR FOR " + query;
61 return ExecCommandOk( cmd.c_str() );
64 // Fetch ALL tuples in given direction
65 int PgCursor::Fetch(const char* dir)
67 return Fetch("ALL", dir);
70 // Fetch specified amount of tuples in given direction
71 int PgCursor::Fetch(unsigned num, const char* dir)
73 return Fetch( IntToString(num), dir );
76 // Create and execute the actual fetch command with the given arguments
77 int PgCursor::Fetch(string num, string dir)
79 string cmd = "FETCH " + dir + " " + num + " IN " + pgCursor;
80 return ExecTuplesOk( cmd.c_str() );
83 // Close the cursor: no more queries using the cursor should be allowed
84 // Actually, the backend should take care of it.
87 string cmd = "CLOSE " + pgCursor;
88 return ExecCommandOk( cmd.c_str() );
89 } // End CloseCursor()