<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:57 petere Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.29 2001/05/09 17:29:09 momjian Exp $
-->
<chapter id="libpqplusplus">
returns whether or not the connection to the backend server succeeded or
failed.
<synopsis>
- int PgConnection::ConnectionBad()
+ bool PgConnection::ConnectionBad() const
</synopsis>
- Returns TRUE if the connection failed.
+ Returns true if the connection failed.
</para>
</listitem>
<listitem>
<function>Tuples</function>
Returns the number of tuples (rows) in the query result.
<synopsis>
- int PgDatabase::Tuples()
+ int PgDatabase::Tuples() const
</synopsis>
</para>
</listitem>
Returns the field (attribute) name associated with the given field index.
Field indices start at 0.
<synopsis>
- const char *PgDatabase::FieldName(int field_num)
+ const char *PgDatabase::FieldName(int field_num) const
</synopsis>
</para>
</listitem>
PQfnumber Returns the field (attribute) index associated with
the given field name.
<synopsis>
- int PgDatabase::FieldNum(const char* field_name)
+ int PgDatabase::FieldNum(const char* field_name) const
</synopsis>
-1 is returned if the given name does not match any field.
</para>
integer returned is an internal coding of the type. Field indices
start at 0.
<synopsis>
- Oid PgDatabase::FieldType(int field_num)
+ Oid PgDatabase::FieldType(int field_num) const
</synopsis>
</para>
</listitem>
integer returned is an internal coding of the type. Field indices
start at 0.
<synopsis>
- Oid PgDatabase::FieldType(const char* field_name)
+ Oid PgDatabase::FieldType(const char* field_name) const
</synopsis>
</para>
</listitem>
Returns the size in bytes of the field associated with the given
field index. Field indices start at 0.
<synopsis>
- short PgDatabase::FieldSize(int field_num)
+ short PgDatabase::FieldSize(int field_num) const
</synopsis>
Returns the space allocated for this field in a database tuple given
the field number. In other words the size of the server's binary
Returns the size in bytes of the field associated with the given
field index. Field indices start at 0.
<synopsis>
- short PgDatabase::FieldSize(const char *field_name)
+ short PgDatabase::FieldSize(const char *field_name) const
</synopsis>
Returns the space allocated for this field in a database tuple given
the field name. In other words the size of the server's binary
Returns a single field (attribute) value of one tuple of a PGresult.
Tuple and field indices start at 0.
<synopsis>
- const char *PgDatabase::GetValue(int tup_num, int field_num)
+ const char *PgDatabase::GetValue(int tup_num, int field_num) const
</synopsis>
For most queries, the value returned by GetValue is a null-terminated
ASCII string representation of the attribute value. But if BinaryTuples()
Returns a single field (attribute) value of one tuple of a PGresult.
Tuple and field indices start at 0.
<synopsis>
- const char *PgDatabase::GetValue(int tup_num, const char *field_name)
+ const char *PgDatabase::GetValue(int tup_num, const char *field_name) const
</synopsis>
For most queries, the value returned by GetValue is a null-terminated
ASCII string representation of the attribute value. But if BinaryTuples()
Returns the length of a field (attribute) in bytes. Tuple and field
indices start at 0.
<synopsis>
- int PgDatabase::GetLength(int tup_num, int field_num)
+ int PgDatabase::GetLength(int tup_num, int field_num) const
</synopsis>
This is the actual data length for the particular data value, that
is the size of the object pointed to by GetValue. Note that for
Returns the length of a field (attribute) in bytes. Tuple and field
indices start at 0.
<synopsis>
- int PgDatabase::GetLength(int tup_num, const char* field_name)
+ int PgDatabase::GetLength(int tup_num, const char* field_name) const
</synopsis>
This is the actual data length for the particular data value, that
is the size of the object pointed to by GetValue. Note that for
size reported by PQfsize.
</para>
</listitem>
+ <listitem>
+ <para>
+ <function>GetIsNull</function>
+ Returns whether a field has the null value.
+ <synopsis>
+ bool GetIsNull(int tup_num, int field_num) const
+ </synopsis>
+ Note that GetValue will return the empty string for null fields, not
+ the NULL pointer.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <function>GetIsNull</function>
+ Returns whether a field has the null value.
+ <synopsis>
+ bool GetIsNull(int tup_num, const char *field_name) const
+ </synopsis>
+ Note that GetValue will return the empty string for null fields, not
+ the NULL pointer.
+ </para>
+ </listitem>
<listitem>
<para>
<function>DisplayTuples</function>
- Prints out all the tuples and, optionally, the attribute names to the
+ OBSOLESCENT: Prints out all the tuples and, optionally, the attribute names to the
specified output stream.
<synopsis>
- void PgDatabase::DisplayTuples(FILE *out = 0, int fillAlign = 1,
- const char* fieldSep = "|",int printHeader = 1, int quiet = 0)
+ void PgDatabase::DisplayTuples(FILE *out = 0, bool fillAlign = true,
+ const char* fieldSep = "|",bool printHeader = true, bool quiet = false) const
</synopsis>
</para>
</listitem>
<listitem>
<para>
<function>PrintTuples</function>
- Prints out all the tuples and, optionally, the attribute names to the
+ OBSOLESCENT: Prints out all the tuples and, optionally, the attribute names to the
specified output stream.
<synopsis>
- void PgDatabase::PrintTuples(FILE *out = 0, int printAttName = 1,
- int terseOutput = 0, int width = 0)
+ void PgDatabase::PrintTuples(FILE *out = 0, bool printAttName = true,
+ bool terseOutput = false, bool fillAlign = false) const
</synopsis>
</para>
</listitem>
Returns the number of rows affected after an INSERT, UPDATE or DELETE.
If the command was anything else, it returns -1.
<synopsis>
- int PgDatabase::CmdTuples()
+ int PgDatabase::CmdTuples() const
</synopsis>
</para>
</listitem>
<para>
<function>OidStatus</function>
<synopsis>
- const char *PgDatabase::OidStatus()
+ const char *PgDatabase::OidStatus() const
</synopsis>
</para>
</listitem>
to see if any notification data is currently available from the backend.
<function>PgDatabase::Notifies</function>
returns the notification from a list of unhandled notifications from the
- backend. The function eturns NULL if there is no pending notifications from the
- backend.
+ backend. The function returns NULL if there are no pending notifications
+ from the backend.
<function>PgDatabase::Notifies</function>
behaves like the popping of a stack. Once a notification is returned
from <function>PgDatabase::Notifies</function>,
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.50 2001/05/07 19:31:33 petere Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.51 2001/05/09 17:29:10 momjian Exp $
Postgres documentation
-->
</varlistentry>
+ <varlistentry>
+ <term><literal>\du [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
+ <listitem>
+ <para>
+ Lists all configured users or only those that match <replaceable class="parameter">pattern</replaceable>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+
<varlistentry>
<term><literal>\edit</literal> (or <literal>\e</literal>) [ <replaceable class="parameter">filename</replaceable> ]</term>
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.51 2001/05/07 19:31:33 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.52 2001/05/09 17:29:10 momjian Exp $
*/
#include "postgres_fe.h"
#include "command.h"
case 'S':
success = listTables(&cmd[1], name, show_verbose);
break;
+ case 'u':
+ success = describeUsers(name);
+ break;
default:
status = CMD_UNKNOWN;
}
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.28 2001/03/22 04:00:19 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.29 2001/05/09 17:29:10 momjian Exp $
*/
#include "postgres_fe.h"
#include "describe.h"
}
+/*
+ * describeUsers()
+ *
+ * \du [user]
+ *
+ * Describes users, possibly based on a simplistic prefix search on the
+ * argument.
+ */
+
+bool
+describeUsers (const char *name)
+{
+ char buf[384 + REGEXP_CUTOFF];
+ PGresult *res;
+ printTableOpt myopt = pset.popt.topt;
+ int i;
+ char *title;
+ const char *headers[4];
+ char **cells = NULL;
+ unsigned int cols;
+
+ /*
+ * All we want to know is the user names and permissions
+ * for the system.
+ */
+
+ title = "List of Users";
+
+ cols = 0;
+ headers[cols++] = "User Name";
+ headers[cols++] = "User ID";
+ headers[cols++] = "Attributes";
+ headers[cols] = NULL;
+
+ strcpy(buf,
+ "SELECT u.usename AS \"User Name\"\n
+ , u.usesysid AS \"User ID\"\n
+ , u.usesuper AS \"Super User\"\n
+ , u.usecreatedb AS \"Create DB\"\n
+ FROM pg_user u\n");
+ if (name)
+ {
+ strcat(buf, " WHERE u.usename ~ '^");
+ strncat(buf, name, REGEXP_CUTOFF);
+ strcat(buf, "'\n");
+ }
+ strcat(buf, "ORDER BY \"User Name\"\n");
+
+ res = PSQLexec(buf);
+ if (!res)
+ return false;
+
+ cells = xmalloc((PQntuples(res) * cols + 1) * sizeof(*cells));
+ cells[PQntuples(res) * cols] = NULL;
+
+ for (i = 0; i < PQntuples(res); i++)
+ {
+ char createuser[2] = "";
+ char createdb[2] = "";
+
+ /* Name */
+ cells[i * cols + 0] = PQgetvalue(res, i, 0);
+
+ /* ID */
+ cells[i * cols + 1] = PQgetvalue(res, i, 1);
+
+ /* Super */
+ strcpy(createuser, PQgetvalue(res, i, 2));
+
+ /* Create DB */
+ strcpy(createdb, PQgetvalue(res, i, 3));
+
+ cells[i * cols + 2] = xmalloc((strlen("create user, create DB") * sizeof(char)) + 1);
+ strcpy(cells[i * cols + 2], "");
+
+ if (strcmp(createuser, "t") == 0)
+ strcat(cells[i * cols + 2], "create user");
+
+ if (strcmp(createdb, "t") == 0) {
+ if (strcmp(createuser, "t") == 0)
+ strcat(cells[i * cols + 2], ", ");
+ strcat(cells[i * cols + 2], "create DB");
+ }
+ }
+
+ printTable(title, headers,
+ (const char **) cells,
+ NULL,
+ "lll", &myopt, pset.queryFout);
+
+ /* clean up */
+ free(cells);
+
+ PQclear(res);
+ return true;
+}
+
/*
* listTables()
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.9 2000/04/12 17:16:22 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.10 2001/05/09 17:29:10 momjian Exp $
*/
#ifndef DESCRIBE_H
#define DESCRIBE_H
/* \do */
bool describeOperators(const char *name);
+/* \du */
+bool describeUsers(const char *name);
+
/* \z (or \dp) */
bool permissionsList(const char *name);
#include "libpq++.h"
#include <stdlib.h>
-main()
+int main()
{
// Begin, by connecting to the backend using hardwired constants
// and a test database created by the user prior to the invokation
// of this test program.
- char* dbName = "dbname=template1";
+ const char* dbName = "dbname=template1";
PgDatabase data(dbName);
// Check to see that the backend connection was successfully made
#include "utils/geo_decls.h" // for the POLYGON type
}
-main()
+int main()
{
// Begin, by connecting to the backend using hardwired constants
// and a test database created by the user prior to the invokation
// of this test program. Connect using cursor interface.
- char* dbName = "dbname=template1"; // change this to the name of your test database
+ const char* dbName = "dbname=template1"; // change this to the name of your test database
PgCursor data(dbName, "mycursor");
// check to see that the backend connection was successfully made
#include "libpq++.h"
#include <stdlib.h>
-main()
+int main()
{
// Begin, by connecting to the backend using hardwired constants
// and a test database created by the user prior to the invokation
// of this test program. Connect using transaction interface.
- char* dbName = "dbname=template1";
+ const char* dbName = "dbname=template1";
PgTransaction data(dbName);
// check to see that the backend connection was successfully made
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.10 2000/07/27 19:44:01 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.11 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgconnection.h"
+using namespace std;
+
// ****************************************************************
//
// ****************************************************************
// default constructor -- initialize everything
PgConnection::PgConnection()
- : pgConn(NULL), pgResult(NULL), pgCloseConnection(0)
+ : pgConn(NULL), pgResult(NULL), pgCloseConnection(false)
{}
// constructor -- checks environment variable for database name
// Now uses PQconnectdb
PgConnection::PgConnection(const char* conninfo)
- : pgConn(NULL), pgResult(NULL), pgCloseConnection(1)
+ : pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
{
// Connect to the database
pgResult=NULL;
if(pgConn) PQfinish(pgConn);
pgConn=NULL;
- pgCloseConnection=0;
+ pgCloseConnection=false;
}
}
// PgConnection::connect
// establish a connection to a backend
-ConnStatusType PgConnection::Connect(const char* conninfo)
+ConnStatusType PgConnection::Connect(const char conninfo[])
{
// if the connection is open, close it first
CloseConnection();
pgConn = PQconnectdb(conninfo);
// Now we have a connection we must close (even if it's bad!)
- pgCloseConnection = 1;
+ pgCloseConnection = true;
// Status will return either CONNECTION_OK or CONNECTION_BAD
return Status();
}
// PgConnection::status -- return connection or result status
-ConnStatusType PgConnection::Status()
+ConnStatusType PgConnection::Status() const
{
return PQstatus(pgConn);
}
// From Integer To String Conversion Function
string PgConnection::IntToString(int n)
{
- char buffer [32];
- memset(buffer, 0, sizeof(buffer));
+ char buffer [4*sizeof(n) + 2];
sprintf(buffer, "%d", n);
return buffer;
}
-int PgConnection::ConnectionBad()
+bool PgConnection::ConnectionBad() const
{
return Status() == CONNECTION_BAD;
}
-const char* PgConnection::ErrorMessage()
+const char* PgConnection::ErrorMessage() const
{
return (const char *)PQerrorMessage(pgConn);
}
-const char* PgConnection::DBName()
+const char* PgConnection::DBName() const
{
return (const char *)PQdb(pgConn);
}
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pgconnection.h,v 1.10 2001/02/10 02:31:30 tgl Exp $
+ * $Id: pgconnection.h,v 1.11 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
}
#ifdef HAVE_NAMESPACE_STD
-using namespace std;
+#define PGSTD std::
+#else
+#define PGSTD
#endif
// derived from this class to obtain the connection interface.
class PgConnection {
protected:
- PGconn* pgConn; // Connection Structure
+ PGconn* pgConn; // Connection Structure
PGresult* pgResult; // Current Query Result
- int pgCloseConnection; // TRUE if connection should be closed by destructor
+ bool pgCloseConnection; // true if connection should be closed by destructor
public:
- PgConnection(const char* conninfo); // use reasonable & environment defaults
+ explicit PgConnection(const char* conninfo); // use reasonable & environment defaults
virtual ~PgConnection(); // close connection and clean up
// Connection status and error messages
- ConnStatusType Status();
- int ConnectionBad();
- const char* ErrorMessage();
+ ConnStatusType Status() const;
+ bool ConnectionBad() const;
+ const char* ErrorMessage() const;
// returns the database name of the connection
- const char* DBName();
+ const char* DBName() const;
// Query Execution interface
ExecStatusType Exec(const char* query); // send a query to the backend
protected:
ConnStatusType Connect(const char* conninfo);
void CloseConnection();
- string IntToString(int);
+ static PGSTD string IntToString(int);
// Default constructor is only available to subclasses
PgConnection();
PgConnection& operator= (const PgConnection&);
};
+
+#ifdef HAVE_NAMESPACE_STD
+#undef PGSTD
+#endif
+
+
#endif // PGCONNECTION_H
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.4 1999/06/01 02:43:37 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.5 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgcursordb.h"
+
+using namespace std;
+
+
// ****************************************************************
//
// PgCursor Implementation
//
// ****************************************************************
// Declare a cursor: name has already been supplied in the constructor
-int PgCursor::Declare(const string& query, int binary)
+int PgCursor::Declare(string query, bool binary)
{
string cmd = "DECLARE " + pgCursor;
if ( binary )
} // End Fetch()
// Create and execute the actual fetch command with the given arguments
-int PgCursor::Fetch(const string& num, const string& dir)
+int PgCursor::Fetch(string num, string dir)
{
string cmd = "FETCH " + dir + " " + num + " IN " + pgCursor;
return ExecTuplesOk( cmd.c_str() );
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $Id: pgcursordb.h,v 1.6 2001/01/24 19:43:32 momjian Exp $
+ * $Id: pgcursordb.h,v 1.7 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgtransdb.h"
#endif
+#ifdef HAVE_NAMESPACE_STD
+#define PGSTD std::
+#else
+#define PGSTD
+#endif
+
// ****************************************************************
//
~PgCursor(); // close connection and clean up
// Commands associated with cursor interface
- int Declare(const string& query, int binary = 0); // Declare a cursor with given name
+ int Declare(PGSTD string query, bool binary=false); // Declare a cursor with given name
int Fetch(const char* dir = "FORWARD"); // Fetch ALL tuples in given direction
int Fetch(unsigned num, const char* dir = "FORWARD"); // Fetch specified amount of tuples
int Close(); // Close the cursor
// Accessors to the cursor name
const char* Cursor() const { return pgCursor.c_str(); }
- void Cursor(const string& cursor) { pgCursor = cursor; }
+ // TODO: Setter has same name as getter--ouch!
+ // OBSOLESCENT
+ void Cursor(PGSTD string cursor) { pgCursor = cursor; }
protected:
- int Fetch(const string& num, const string& dir);
+ int Fetch(PGSTD string num, PGSTD string dir);
protected:
- string pgCursor;
+ PGSTD string pgCursor;
protected:
PgCursor() : PgTransaction() {} // Do not connect
PgCursor& operator= (const PgCursor&);
}; // End PgCursor Class Declaration
+
+#ifdef HAVE_NAMESPACE_STD
+#undef PGSTD
+#endif
+
#endif // PGCURSORDB_H
+
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgdatabase.cc,v 1.9 2000/01/29 16:58:52 petere Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgdatabase.cc,v 1.10 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgdatabase.h"
-void PgDatabase::DisplayTuples(FILE *out, int fillAlign,
- const char* fieldSep, int printHeader,
- int /* quiet */)
+using namespace std;
+
+
+// OBSOLESCENT (uses PQprint(), which is no longer being maintained)
+void PgDatabase::DisplayTuples(FILE *out,
+ bool fillAlign,
+ const char* fieldSep,
+ bool printHeader,
+ bool /* quiet */) const
{
PQprintOpt po;
- memset(&po,0,sizeof(po));
-
- po.align = fillAlign;
- po.fieldSep = (char *)fieldSep;
po.header = printHeader;
+ po.align = fillAlign;
+ po.standard = po.html3 = po.expanded = po.pager = 0;
+ po.fieldSep = const_cast<char *>(fieldSep);
+ po.tableOpt = po.caption = 0;
+ po.fieldName = 0;
PQprint(out,pgResult,&po);
}
-
-void PgDatabase::PrintTuples(FILE *out, int printAttName, int terseOutput,
- int width)
+// OBSOLESCENT (uses PQprint(), which is no longer being maintained)
+void PgDatabase::PrintTuples(FILE *out,
+ bool printAttName,
+ bool terseOutput,
+ bool fillAlign) const
{
PQprintOpt po;
- memset(&po,0,sizeof(po));
-
- po.align = width;
-
- if(terseOutput) po.fieldSep = strdup("|");
- else po.fieldSep = "";
-
po.header = printAttName;
+ po.align = fillAlign;
+ po.standard = po.html3 = po.expanded = po.pager = 0;
+ po.tableOpt = po.caption = 0;
+ po.fieldSep = const_cast<char *>(terseOutput ? "" : "|");
+ po.fieldName = 0;
PQprint(out,pgResult,&po);
}
-int PgDatabase::Tuples()
+int PgDatabase::Tuples() const
{
return PQntuples(pgResult);
}
-int PgDatabase::CmdTuples()
+int PgDatabase::CmdTuples() const
{
-char *a;
-
- a = (char *)PQcmdTuples(pgResult);
- if(!a[0]) return -1;
-
-return atoi(a);
+const char *a = PQcmdTuples(pgResult);
+return a[0] ? atoi(a) : -1;
}
+// TODO: Make const?
int PgDatabase::Fields()
{
return PQnfields(pgResult);
}
-const char* PgDatabase::FieldName(int field_num)
+const char* PgDatabase::FieldName(int field_num) const
{
return PQfname(pgResult, field_num);
}
-int PgDatabase::FieldNum(const char* field_name)
+int PgDatabase::FieldNum(const char* field_name) const
{
return PQfnumber(pgResult, field_name);
}
-Oid PgDatabase::FieldType(int field_num)
+Oid PgDatabase::FieldType(int field_num) const
{
return PQftype(pgResult, field_num);
}
-Oid PgDatabase::FieldType(const char* field_name)
+Oid PgDatabase::FieldType(const char* field_name) const
{
return PQftype(pgResult, FieldNum(field_name));
}
-short PgDatabase::FieldSize(int field_num)
+short PgDatabase::FieldSize(int field_num) const
{
return PQfsize(pgResult, field_num);
}
-short PgDatabase::FieldSize(const char* field_name)
+short PgDatabase::FieldSize(const char* field_name) const
{
return PQfsize(pgResult, FieldNum(field_name));
}
-const char* PgDatabase::GetValue(int tup_num, int field_num)
+const char* PgDatabase::GetValue(int tup_num, int field_num) const
{
return PQgetvalue(pgResult, tup_num, field_num);
}
-const char* PgDatabase::GetValue(int tup_num, const char* field_name)
+const char* PgDatabase::GetValue(int tup_num, const char* field_name) const
{
return PQgetvalue(pgResult, tup_num, FieldNum(field_name));
}
-int PgDatabase::GetIsNull(int tup_num, int field_num)
+bool PgDatabase::GetIsNull(int tup_num, int field_num) const
{
return PQgetisnull(pgResult, tup_num, field_num);
}
-int PgDatabase::GetIsNull(int tup_num, const char* field_name)
+bool PgDatabase::GetIsNull(int tup_num, const char* field_name) const
{
return PQgetisnull(pgResult, tup_num, FieldNum(field_name));
}
-int PgDatabase::GetLength(int tup_num, int field_num)
+int PgDatabase::GetLength(int tup_num, int field_num) const
{
return PQgetlength(pgResult, tup_num, field_num);
}
-int PgDatabase::GetLength(int tup_num, const char* field_name)
+int PgDatabase::GetLength(int tup_num, const char* field_name) const
{
return PQgetlength(pgResult, tup_num, FieldNum(field_name));
}
-int PgDatabase::GetLine(char* string, int length)
+int PgDatabase::GetLine(char str[], int length)
{
-return PQgetline(pgConn, string, length);
+return PQgetline(pgConn, str, length);
}
-void PgDatabase::PutLine(const char* string)
+void PgDatabase::PutLine(const char str[])
{
-PQputline(pgConn, string);
+PQputline(pgConn, str);
}
-const char* PgDatabase::OidStatus()
+const char* PgDatabase::OidStatus() const
{
return PQoidStatus(pgResult);
}
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $Id: pgdatabase.h,v 1.9 2001/01/24 19:43:32 momjian Exp $
+ * $Id: pgdatabase.h,v 1.10 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
class PgDatabase : public PgConnection {
public:
// connect to the database with conninfo
- PgDatabase(const char* conninfo) : PgConnection(conninfo) {}
+ explicit PgDatabase(const char* conninfo) : PgConnection(conninfo) {}
~PgDatabase() {} // close connection and clean up
+
+ typedef int size_type;
// query result access
- int Tuples();
- int CmdTuples();
+ size_type Tuples() const;
+ size_type CmdTuples() const;
int Fields();
- const char* FieldName(int field_num);
- int FieldNum(const char* field_name);
- Oid FieldType(int field_num);
- Oid FieldType(const char* field_name);
- short FieldSize(int field_num);
- short FieldSize(const char* field_name);
- const char* GetValue(int tup_num, int field_num);
- const char* GetValue(int tup_num, const char* field_name);
- int GetIsNull(int tup_num, int field_num);
- int GetIsNull(int tup_num, const char* field_name);
- int GetLength(int tup_num, int field_num);
- int GetLength(int tup_num, const char* field_name);
- void DisplayTuples(FILE *out = 0, int fillAlign = 1,
- const char* fieldSep = "|",int printHeader = 1, int quiet = 0) ;
- void PrintTuples(FILE *out = 0, int printAttName = 1,
- int terseOutput = 0, int width = 0) ;
+ const char* FieldName(int field_num) const;
+ int FieldNum(const char* field_name) const;
+ Oid FieldType(int field_num) const;
+ Oid FieldType(const char* field_name) const;
+ short FieldSize(int field_num) const;
+ short FieldSize(const char* field_name) const;
+ const char* GetValue(size_type tup_num, int field_num) const;
+ const char* GetValue(size_type tup_num, const char* field_name) const;
+ bool GetIsNull(size_type tup_num, int field_num) const;
+ bool GetIsNull(size_type tup_num, const char* field_name) const;
+ int GetLength(size_type tup_num, int field_num) const;
+ int GetLength(size_type tup_num, const char* field_name) const;
+
+ // OBSOLESCENT (use PQprint()):
+ void DisplayTuples(FILE *out=0, bool fillAlign=true,
+ const char* fieldSep="|", bool printHeader=true, bool quiet=false) const;
+ void PrintTuples(FILE *out=0, bool printAttName=true,
+ bool terseOutput=false, bool fillAlign=false) const;
// copy command related access
- int GetLine(char* string, int length);
- void PutLine(const char* string);
- const char* OidStatus();
+ int GetLine(char str[], int length);
+ void PutLine(const char str[]);
+ const char* OidStatus() const;
int EndCopy();
protected:
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.6 2000/04/22 22:39:15 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.7 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "libpq/libpq-fs.h"
}
+
+using namespace std;
+
+
// ****************************************************************
//
// PgLargeObject Implementation
}
-int PgLargeObject::Tell()
+int PgLargeObject::Tell() const
{
return lo_tell(pgConn, pgFd);
}
}
-string PgLargeObject::Status()
+string PgLargeObject::Status() const
{
return loStatus;
}
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $Id: pglobject.h,v 1.6 2001/01/24 19:43:32 momjian Exp $
+ * $Id: pglobject.h,v 1.7 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgconnection.h"
#endif
+#ifdef HAVE_NAMESPACE_STD
+#define PGSTD std::
+#else
+#define PGSTD
+#endif
+
// ****************************************************************
//
private:
int pgFd;
Oid pgObject;
- string loStatus;
+ PGSTD string loStatus;
void Init(Oid lobjId = 0);
public:
- PgLargeObject(const char* conninfo = 0); // use reasonable defaults and create large object
- PgLargeObject(Oid lobjId, const char* conninfo = 0); // use reasonable defaults and open large object
+ explicit PgLargeObject(const char* conninfo = 0); // use reasonable defaults and create large object
+ explicit PgLargeObject(Oid lobjId, const char* conninfo = 0); // use reasonable defaults and open large object
~PgLargeObject(); // close connection and clean up
void Create();
int Read(char* buf, int len);
int Write(const char* buf, int len);
int LSeek(int offset, int whence);
- int Tell();
+ int Tell() const;
int Unlink();
Oid LOid();
Oid Import(const char* filename);
int Export(const char* filename);
- string Status();
+ PGSTD string Status() const;
private:
// We don't support copying of PgLargeObject objects,
PgLargeObject& operator= (const PgLargeObject&);
};
+
+#ifdef HAVE_NAMESPACE_STD
+#undef PGSTD
+#endif
+
+
#endif // PGLOBJECT_H
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgtransdb.cc,v 1.3 1999/05/30 15:17:58 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgtransdb.cc,v 1.4 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
// Make a connection to the specified database with default environment
// See PQconnectdb() for conninfo usage.
PgTransaction::PgTransaction(const char* conninfo)
- : PgDatabase(conninfo)
+ : PgDatabase(conninfo),
+ pgCommitted(true)
{
BeginTransaction();
}
// Destructor: End the transaction block
PgTransaction::~PgTransaction()
{
- EndTransaction();
+ if (!pgCommitted) Exec("ABORT");
}
// Begin the transaction block
ExecStatusType PgTransaction::BeginTransaction()
{
+ pgCommitted = false;
return Exec("BEGIN");
} // End BeginTransaction()
// Begin the transaction block
ExecStatusType PgTransaction::EndTransaction()
{
+ pgCommitted = true;
return Exec("END");
} // End EndTransaction()
+
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $Id: pgtransdb.h,v 1.6 2001/01/24 19:43:32 momjian Exp $
+ * $Id: pgtransdb.h,v 1.7 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
// the object is destroyed.
class PgTransaction : public PgDatabase {
public:
- PgTransaction(const char* conninfo); // use reasonable & environment defaults
+ explicit PgTransaction(const char* conninfo); // use reasonable & environment defaults
// connect to the database with given environment and database name
- // PgTransaction(const PgConnection&);
+ // explicit PgTransaction(const PgConnection&);
~PgTransaction(); // close connection and clean up
protected:
ExecStatusType EndTransaction();
protected:
- PgTransaction() : PgDatabase() {} // Do not connect
+ PgTransaction() : PgDatabase(), pgCommitted(true) {} // Do not connect
private:
+ bool pgCommitted;
+
// We don't support copying of PgTransaction objects,
// so make copy constructor and assignment op private.
PgTransaction(const PgTransaction&);