Here's a version of my suggested diffs transplanted to 7.1 beta 5. I'm
still looking at the best way to integrate Tom Vijlbrief's fixes (insofar as they're still needed); would 7.2 be a suitable time for incompatible API changes? Jeroen Changes: (*) Introduced bool, true, false (replacing some int, 1, 0) (*) Made some member functions const (*) Documented GetIsNull() (*) Marked DisplayTuples() and PrintTuples() as obsolescent; fixed possible portability problem (assumed that NULL pointer equals all-zero bit pattern) (*) PrintTuples(): renamed width parameter to fillAlign to conform with other usage; fixed memory leak and compile issue w.r.t. field separator (should also slightly improve performance) (*) Fixed some minor compilation issues (*) Moved "using namespace std;" out of headers, where they didn't belong; used new (temporary) preprocessor macro PGSTD to do this (*) Made ToString() static, removed unneeded memset(), made buffer size adapt to sizeof(int) (*) Made some constructors explicit (*) Changed some const std::string & parameters to plain std::string (*) Marked PgCursor::Cursor(std::string) as obsolescent (setter with same name as getter--bad style) (*) Renamed some paramaters previously named "string" (*) Introduced size_type typedef for number of tuples in result set (*) PgTransaction now supports re-opening after closing, and aborts if not explicitly committed prior to destruction J. T. Vermeulen
This commit is contained in:
parent
c8db55f78a
commit
a79b698adb
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$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">
|
<chapter id="libpqplusplus">
|
||||||
@ -227,9 +227,9 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
returns whether or not the connection to the backend server succeeded or
|
returns whether or not the connection to the backend server succeeded or
|
||||||
failed.
|
failed.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
int PgConnection::ConnectionBad()
|
bool PgConnection::ConnectionBad() const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
Returns TRUE if the connection failed.
|
Returns true if the connection failed.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
@ -368,7 +368,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
<function>Tuples</function>
|
<function>Tuples</function>
|
||||||
Returns the number of tuples (rows) in the query result.
|
Returns the number of tuples (rows) in the query result.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
int PgDatabase::Tuples()
|
int PgDatabase::Tuples() const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -387,7 +387,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
Returns the field (attribute) name associated with the given field index.
|
Returns the field (attribute) name associated with the given field index.
|
||||||
Field indices start at 0.
|
Field indices start at 0.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
const char *PgDatabase::FieldName(int field_num)
|
const char *PgDatabase::FieldName(int field_num) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -397,7 +397,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
PQfnumber Returns the field (attribute) index associated with
|
PQfnumber Returns the field (attribute) index associated with
|
||||||
the given field name.
|
the given field name.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
int PgDatabase::FieldNum(const char* field_name)
|
int PgDatabase::FieldNum(const char* field_name) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
-1 is returned if the given name does not match any field.
|
-1 is returned if the given name does not match any field.
|
||||||
</para>
|
</para>
|
||||||
@ -409,7 +409,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
integer returned is an internal coding of the type. Field indices
|
integer returned is an internal coding of the type. Field indices
|
||||||
start at 0.
|
start at 0.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
Oid PgDatabase::FieldType(int field_num)
|
Oid PgDatabase::FieldType(int field_num) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -420,7 +420,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
integer returned is an internal coding of the type. Field indices
|
integer returned is an internal coding of the type. Field indices
|
||||||
start at 0.
|
start at 0.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
Oid PgDatabase::FieldType(const char* field_name)
|
Oid PgDatabase::FieldType(const char* field_name) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -430,7 +430,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
Returns the size in bytes of the field associated with the given
|
Returns the size in bytes of the field associated with the given
|
||||||
field index. Field indices start at 0.
|
field index. Field indices start at 0.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
short PgDatabase::FieldSize(int field_num)
|
short PgDatabase::FieldSize(int field_num) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
Returns the space allocated for this field in a database tuple given
|
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
|
the field number. In other words the size of the server's binary
|
||||||
@ -444,7 +444,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
Returns the size in bytes of the field associated with the given
|
Returns the size in bytes of the field associated with the given
|
||||||
field index. Field indices start at 0.
|
field index. Field indices start at 0.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
short PgDatabase::FieldSize(const char *field_name)
|
short PgDatabase::FieldSize(const char *field_name) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
Returns the space allocated for this field in a database tuple given
|
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
|
the field name. In other words the size of the server's binary
|
||||||
@ -466,7 +466,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
Returns a single field (attribute) value of one tuple of a PGresult.
|
Returns a single field (attribute) value of one tuple of a PGresult.
|
||||||
Tuple and field indices start at 0.
|
Tuple and field indices start at 0.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
const char *PgDatabase::GetValue(int tup_num, int field_num)
|
const char *PgDatabase::GetValue(int tup_num, int field_num) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
For most queries, the value returned by GetValue is a null-terminated
|
For most queries, the value returned by GetValue is a null-terminated
|
||||||
ASCII string representation of the attribute value. But if BinaryTuples()
|
ASCII string representation of the attribute value. But if BinaryTuples()
|
||||||
@ -486,7 +486,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
Returns a single field (attribute) value of one tuple of a PGresult.
|
Returns a single field (attribute) value of one tuple of a PGresult.
|
||||||
Tuple and field indices start at 0.
|
Tuple and field indices start at 0.
|
||||||
<synopsis>
|
<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>
|
</synopsis>
|
||||||
For most queries, the value returned by GetValue is a null-terminated
|
For most queries, the value returned by GetValue is a null-terminated
|
||||||
ASCII string representation of the attribute value. But if BinaryTuples()
|
ASCII string representation of the attribute value. But if BinaryTuples()
|
||||||
@ -506,7 +506,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
Returns the length of a field (attribute) in bytes. Tuple and field
|
Returns the length of a field (attribute) in bytes. Tuple and field
|
||||||
indices start at 0.
|
indices start at 0.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
int PgDatabase::GetLength(int tup_num, int field_num)
|
int PgDatabase::GetLength(int tup_num, int field_num) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
This is the actual data length for the particular data value, that
|
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
|
is the size of the object pointed to by GetValue. Note that for
|
||||||
@ -520,7 +520,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
Returns the length of a field (attribute) in bytes. Tuple and field
|
Returns the length of a field (attribute) in bytes. Tuple and field
|
||||||
indices start at 0.
|
indices start at 0.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
int PgDatabase::GetLength(int tup_num, const char* field_name)
|
int PgDatabase::GetLength(int tup_num, const char* field_name) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
This is the actual data length for the particular data value, that
|
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
|
is the size of the object pointed to by GetValue. Note that for
|
||||||
@ -528,25 +528,47 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
size reported by PQfsize.
|
size reported by PQfsize.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</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>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<function>DisplayTuples</function>
|
<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.
|
specified output stream.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
void PgDatabase::DisplayTuples(FILE *out = 0, int fillAlign = 1,
|
void PgDatabase::DisplayTuples(FILE *out = 0, bool fillAlign = true,
|
||||||
const char* fieldSep = "|",int printHeader = 1, int quiet = 0)
|
const char* fieldSep = "|",bool printHeader = true, bool quiet = false) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<function>PrintTuples</function>
|
<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.
|
specified output stream.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
void PgDatabase::PrintTuples(FILE *out = 0, int printAttName = 1,
|
void PgDatabase::PrintTuples(FILE *out = 0, bool printAttName = true,
|
||||||
int terseOutput = 0, int width = 0)
|
bool terseOutput = false, bool fillAlign = false) const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -563,7 +585,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
Returns the number of rows affected after an INSERT, UPDATE or DELETE.
|
Returns the number of rows affected after an INSERT, UPDATE or DELETE.
|
||||||
If the command was anything else, it returns -1.
|
If the command was anything else, it returns -1.
|
||||||
<synopsis>
|
<synopsis>
|
||||||
int PgDatabase::CmdTuples()
|
int PgDatabase::CmdTuples() const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -572,7 +594,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
<para>
|
<para>
|
||||||
<function>OidStatus</function>
|
<function>OidStatus</function>
|
||||||
<synopsis>
|
<synopsis>
|
||||||
const char *PgDatabase::OidStatus()
|
const char *PgDatabase::OidStatus() const
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -650,8 +672,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpq++.sgml,v 1.28 2001/05/01 10:48:
|
|||||||
to see if any notification data is currently available from the backend.
|
to see if any notification data is currently available from the backend.
|
||||||
<function>PgDatabase::Notifies</function>
|
<function>PgDatabase::Notifies</function>
|
||||||
returns the notification from a list of unhandled notifications from the
|
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. The function returns NULL if there are no pending notifications
|
||||||
backend.
|
from the backend.
|
||||||
<function>PgDatabase::Notifies</function>
|
<function>PgDatabase::Notifies</function>
|
||||||
behaves like the popping of a stack. Once a notification is returned
|
behaves like the popping of a stack. Once a notification is returned
|
||||||
from <function>PgDatabase::Notifies</function>,
|
from <function>PgDatabase::Notifies</function>,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$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
|
Postgres documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -494,6 +494,16 @@ testdb=>
|
|||||||
</varlistentry>
|
</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>
|
<varlistentry>
|
||||||
<term><literal>\edit</literal> (or <literal>\e</literal>) [ <replaceable class="parameter">filename</replaceable> ]</term>
|
<term><literal>\edit</literal> (or <literal>\e</literal>) [ <replaceable class="parameter">filename</replaceable> ]</term>
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* 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 "postgres_fe.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
@ -357,6 +357,9 @@ exec_command(const char *cmd,
|
|||||||
case 'S':
|
case 'S':
|
||||||
success = listTables(&cmd[1], name, show_verbose);
|
success = listTables(&cmd[1], name, show_verbose);
|
||||||
break;
|
break;
|
||||||
|
case 'u':
|
||||||
|
success = describeUsers(name);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
status = CMD_UNKNOWN;
|
status = CMD_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* 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 "postgres_fe.h"
|
||||||
#include "describe.h"
|
#include "describe.h"
|
||||||
@ -890,6 +890,103 @@ describeTableDetails(const char *name, bool desc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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()
|
* listTables()
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* 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
|
#ifndef DESCRIBE_H
|
||||||
#define DESCRIBE_H
|
#define DESCRIBE_H
|
||||||
@ -22,6 +22,9 @@ bool describeTypes(const char *name, bool verbose);
|
|||||||
/* \do */
|
/* \do */
|
||||||
bool describeOperators(const char *name);
|
bool describeOperators(const char *name);
|
||||||
|
|
||||||
|
/* \du */
|
||||||
|
bool describeUsers(const char *name);
|
||||||
|
|
||||||
/* \z (or \dp) */
|
/* \z (or \dp) */
|
||||||
bool permissionsList(const char *name);
|
bool permissionsList(const char *name);
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@ INSERT INTO TBL1 values (10);
|
|||||||
#include "libpq++.h"
|
#include "libpq++.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
main()
|
int main()
|
||||||
{
|
{
|
||||||
// Begin, by connecting to the backend using hardwired constants
|
// Begin, by connecting to the backend using hardwired constants
|
||||||
// and a test database created by the user prior to the invokation
|
// and a test database created by the user prior to the invokation
|
||||||
// of this test program.
|
// of this test program.
|
||||||
char* dbName = "dbname=template1";
|
const char* dbName = "dbname=template1";
|
||||||
PgDatabase data(dbName);
|
PgDatabase data(dbName);
|
||||||
|
|
||||||
// Check to see that the backend connection was successfully made
|
// Check to see that the backend connection was successfully made
|
||||||
|
@ -34,12 +34,12 @@ extern "C" {
|
|||||||
#include "utils/geo_decls.h" // for the POLYGON type
|
#include "utils/geo_decls.h" // for the POLYGON type
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
int main()
|
||||||
{
|
{
|
||||||
// Begin, by connecting to the backend using hardwired constants
|
// Begin, by connecting to the backend using hardwired constants
|
||||||
// and a test database created by the user prior to the invokation
|
// and a test database created by the user prior to the invokation
|
||||||
// of this test program. Connect using cursor interface.
|
// 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");
|
PgCursor data(dbName, "mycursor");
|
||||||
|
|
||||||
// check to see that the backend connection was successfully made
|
// check to see that the backend connection was successfully made
|
||||||
|
@ -8,12 +8,12 @@
|
|||||||
#include "libpq++.h"
|
#include "libpq++.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
main()
|
int main()
|
||||||
{
|
{
|
||||||
// Begin, by connecting to the backend using hardwired constants
|
// Begin, by connecting to the backend using hardwired constants
|
||||||
// and a test database created by the user prior to the invokation
|
// and a test database created by the user prior to the invokation
|
||||||
// of this test program. Connect using transaction interface.
|
// of this test program. Connect using transaction interface.
|
||||||
char* dbName = "dbname=template1";
|
const char* dbName = "dbname=template1";
|
||||||
PgTransaction data(dbName);
|
PgTransaction data(dbName);
|
||||||
|
|
||||||
// check to see that the backend connection was successfully made
|
// check to see that the backend connection was successfully made
|
||||||
|
@ -10,13 +10,15 @@
|
|||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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"
|
#include "pgconnection.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
@ -25,14 +27,14 @@
|
|||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
// default constructor -- initialize everything
|
// default constructor -- initialize everything
|
||||||
PgConnection::PgConnection()
|
PgConnection::PgConnection()
|
||||||
: pgConn(NULL), pgResult(NULL), pgCloseConnection(0)
|
: pgConn(NULL), pgResult(NULL), pgCloseConnection(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// constructor -- checks environment variable for database name
|
// constructor -- checks environment variable for database name
|
||||||
// Now uses PQconnectdb
|
// Now uses PQconnectdb
|
||||||
PgConnection::PgConnection(const char* conninfo)
|
PgConnection::PgConnection(const char* conninfo)
|
||||||
: pgConn(NULL), pgResult(NULL), pgCloseConnection(1)
|
: pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Connect to the database
|
// Connect to the database
|
||||||
@ -60,14 +62,14 @@ void PgConnection::CloseConnection()
|
|||||||
pgResult=NULL;
|
pgResult=NULL;
|
||||||
if(pgConn) PQfinish(pgConn);
|
if(pgConn) PQfinish(pgConn);
|
||||||
pgConn=NULL;
|
pgConn=NULL;
|
||||||
pgCloseConnection=0;
|
pgCloseConnection=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// PgConnection::connect
|
// PgConnection::connect
|
||||||
// establish a connection to a backend
|
// 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
|
// if the connection is open, close it first
|
||||||
CloseConnection();
|
CloseConnection();
|
||||||
@ -76,14 +78,14 @@ ConnStatusType PgConnection::Connect(const char* conninfo)
|
|||||||
pgConn = PQconnectdb(conninfo);
|
pgConn = PQconnectdb(conninfo);
|
||||||
|
|
||||||
// Now we have a connection we must close (even if it's bad!)
|
// 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
|
// Status will return either CONNECTION_OK or CONNECTION_BAD
|
||||||
return Status();
|
return Status();
|
||||||
}
|
}
|
||||||
|
|
||||||
// PgConnection::status -- return connection or result status
|
// PgConnection::status -- return connection or result status
|
||||||
ConnStatusType PgConnection::Status()
|
ConnStatusType PgConnection::Status() const
|
||||||
{
|
{
|
||||||
return PQstatus(pgConn);
|
return PQstatus(pgConn);
|
||||||
}
|
}
|
||||||
@ -131,27 +133,26 @@ PGnotify* PgConnection::Notifies()
|
|||||||
// From Integer To String Conversion Function
|
// From Integer To String Conversion Function
|
||||||
string PgConnection::IntToString(int n)
|
string PgConnection::IntToString(int n)
|
||||||
{
|
{
|
||||||
char buffer [32];
|
char buffer [4*sizeof(n) + 2];
|
||||||
memset(buffer, 0, sizeof(buffer));
|
|
||||||
sprintf(buffer, "%d", n);
|
sprintf(buffer, "%d", n);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int PgConnection::ConnectionBad()
|
bool PgConnection::ConnectionBad() const
|
||||||
{
|
{
|
||||||
return Status() == CONNECTION_BAD;
|
return Status() == CONNECTION_BAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* PgConnection::ErrorMessage()
|
const char* PgConnection::ErrorMessage() const
|
||||||
{
|
{
|
||||||
return (const char *)PQerrorMessage(pgConn);
|
return (const char *)PQerrorMessage(pgConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* PgConnection::DBName()
|
const char* PgConnection::DBName() const
|
||||||
{
|
{
|
||||||
return (const char *)PQdb(pgConn);
|
return (const char *)PQdb(pgConn);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -43,7 +43,9 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_NAMESPACE_STD
|
#ifdef HAVE_NAMESPACE_STD
|
||||||
using namespace std;
|
#define PGSTD std::
|
||||||
|
#else
|
||||||
|
#define PGSTD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -57,21 +59,21 @@ using namespace std;
|
|||||||
// derived from this class to obtain the connection interface.
|
// derived from this class to obtain the connection interface.
|
||||||
class PgConnection {
|
class PgConnection {
|
||||||
protected:
|
protected:
|
||||||
PGconn* pgConn; // Connection Structure
|
PGconn* pgConn; // Connection Structure
|
||||||
PGresult* pgResult; // Current Query Result
|
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:
|
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
|
virtual ~PgConnection(); // close connection and clean up
|
||||||
|
|
||||||
// Connection status and error messages
|
// Connection status and error messages
|
||||||
ConnStatusType Status();
|
ConnStatusType Status() const;
|
||||||
int ConnectionBad();
|
bool ConnectionBad() const;
|
||||||
const char* ErrorMessage();
|
const char* ErrorMessage() const;
|
||||||
|
|
||||||
// returns the database name of the connection
|
// returns the database name of the connection
|
||||||
const char* DBName();
|
const char* DBName() const;
|
||||||
|
|
||||||
// Query Execution interface
|
// Query Execution interface
|
||||||
ExecStatusType Exec(const char* query); // send a query to the backend
|
ExecStatusType Exec(const char* query); // send a query to the backend
|
||||||
@ -82,7 +84,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
ConnStatusType Connect(const char* conninfo);
|
ConnStatusType Connect(const char* conninfo);
|
||||||
void CloseConnection();
|
void CloseConnection();
|
||||||
string IntToString(int);
|
static PGSTD string IntToString(int);
|
||||||
// Default constructor is only available to subclasses
|
// Default constructor is only available to subclasses
|
||||||
PgConnection();
|
PgConnection();
|
||||||
|
|
||||||
@ -93,4 +95,10 @@ private:
|
|||||||
PgConnection& operator= (const PgConnection&);
|
PgConnection& operator= (const PgConnection&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_NAMESPACE_STD
|
||||||
|
#undef PGSTD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // PGCONNECTION_H
|
#endif // PGCONNECTION_H
|
||||||
|
@ -10,13 +10,17 @@
|
|||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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"
|
#include "pgcursordb.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
// PgCursor Implementation
|
// PgCursor Implementation
|
||||||
@ -48,7 +52,7 @@ PgCursor::~PgCursor()
|
|||||||
//
|
//
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
// Declare a cursor: name has already been supplied in the constructor
|
// 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;
|
string cmd = "DECLARE " + pgCursor;
|
||||||
if ( binary )
|
if ( binary )
|
||||||
@ -70,7 +74,7 @@ int PgCursor::Fetch(unsigned num, const char* dir)
|
|||||||
} // End Fetch()
|
} // End Fetch()
|
||||||
|
|
||||||
// Create and execute the actual fetch command with the given arguments
|
// 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;
|
string cmd = "FETCH " + dir + " " + num + " IN " + pgCursor;
|
||||||
return ExecTuplesOk( cmd.c_str() );
|
return ExecTuplesOk( cmd.c_str() );
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -26,6 +26,12 @@
|
|||||||
#include "pgtransdb.h"
|
#include "pgtransdb.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_NAMESPACE_STD
|
||||||
|
#define PGSTD std::
|
||||||
|
#else
|
||||||
|
#define PGSTD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
@ -44,20 +50,22 @@ public:
|
|||||||
~PgCursor(); // close connection and clean up
|
~PgCursor(); // close connection and clean up
|
||||||
|
|
||||||
// Commands associated with cursor interface
|
// 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(const char* dir = "FORWARD"); // Fetch ALL tuples in given direction
|
||||||
int Fetch(unsigned num, const char* dir = "FORWARD"); // Fetch specified amount of tuples
|
int Fetch(unsigned num, const char* dir = "FORWARD"); // Fetch specified amount of tuples
|
||||||
int Close(); // Close the cursor
|
int Close(); // Close the cursor
|
||||||
|
|
||||||
// Accessors to the cursor name
|
// Accessors to the cursor name
|
||||||
const char* Cursor() const { return pgCursor.c_str(); }
|
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:
|
protected:
|
||||||
int Fetch(const string& num, const string& dir);
|
int Fetch(PGSTD string num, PGSTD string dir);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
string pgCursor;
|
PGSTD string pgCursor;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PgCursor() : PgTransaction() {} // Do not connect
|
PgCursor() : PgTransaction() {} // Do not connect
|
||||||
@ -69,4 +77,10 @@ private:
|
|||||||
PgCursor& operator= (const PgCursor&);
|
PgCursor& operator= (const PgCursor&);
|
||||||
}; // End PgCursor Class Declaration
|
}; // End PgCursor Class Declaration
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_NAMESPACE_STD
|
||||||
|
#undef PGSTD
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // PGCURSORDB_H
|
#endif // PGCURSORDB_H
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -18,151 +18,155 @@
|
|||||||
#include "pgdatabase.h"
|
#include "pgdatabase.h"
|
||||||
|
|
||||||
|
|
||||||
void PgDatabase::DisplayTuples(FILE *out, int fillAlign,
|
using namespace std;
|
||||||
const char* fieldSep, int printHeader,
|
|
||||||
int /* quiet */)
|
|
||||||
|
// 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;
|
PQprintOpt po;
|
||||||
|
|
||||||
memset(&po,0,sizeof(po));
|
|
||||||
|
|
||||||
po.align = fillAlign;
|
|
||||||
po.fieldSep = (char *)fieldSep;
|
|
||||||
po.header = printHeader;
|
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);
|
PQprint(out,pgResult,&po);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// OBSOLESCENT (uses PQprint(), which is no longer being maintained)
|
||||||
void PgDatabase::PrintTuples(FILE *out, int printAttName, int terseOutput,
|
void PgDatabase::PrintTuples(FILE *out,
|
||||||
int width)
|
bool printAttName,
|
||||||
|
bool terseOutput,
|
||||||
|
bool fillAlign) const
|
||||||
{
|
{
|
||||||
PQprintOpt po;
|
PQprintOpt po;
|
||||||
|
|
||||||
memset(&po,0,sizeof(po));
|
|
||||||
|
|
||||||
po.align = width;
|
|
||||||
|
|
||||||
if(terseOutput) po.fieldSep = strdup("|");
|
|
||||||
else po.fieldSep = "";
|
|
||||||
|
|
||||||
po.header = printAttName;
|
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);
|
PQprint(out,pgResult,&po);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int PgDatabase::Tuples()
|
int PgDatabase::Tuples() const
|
||||||
{
|
{
|
||||||
return PQntuples(pgResult);
|
return PQntuples(pgResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int PgDatabase::CmdTuples()
|
int PgDatabase::CmdTuples() const
|
||||||
{
|
{
|
||||||
char *a;
|
const char *a = PQcmdTuples(pgResult);
|
||||||
|
return a[0] ? atoi(a) : -1;
|
||||||
a = (char *)PQcmdTuples(pgResult);
|
|
||||||
if(!a[0]) return -1;
|
|
||||||
|
|
||||||
return atoi(a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Make const?
|
||||||
int PgDatabase::Fields()
|
int PgDatabase::Fields()
|
||||||
{
|
{
|
||||||
return PQnfields(pgResult);
|
return PQnfields(pgResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* PgDatabase::FieldName(int field_num)
|
const char* PgDatabase::FieldName(int field_num) const
|
||||||
{
|
{
|
||||||
return PQfname(pgResult, field_num);
|
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);
|
return PQfnumber(pgResult, field_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Oid PgDatabase::FieldType(int field_num)
|
Oid PgDatabase::FieldType(int field_num) const
|
||||||
{
|
{
|
||||||
return PQftype(pgResult, field_num);
|
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));
|
return PQftype(pgResult, FieldNum(field_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
short PgDatabase::FieldSize(int field_num)
|
short PgDatabase::FieldSize(int field_num) const
|
||||||
{
|
{
|
||||||
return PQfsize(pgResult, field_num);
|
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));
|
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);
|
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));
|
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);
|
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));
|
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);
|
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));
|
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);
|
return PQoidStatus(pgResult);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -37,35 +37,39 @@
|
|||||||
class PgDatabase : public PgConnection {
|
class PgDatabase : public PgConnection {
|
||||||
public:
|
public:
|
||||||
// connect to the database with conninfo
|
// 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
|
~PgDatabase() {} // close connection and clean up
|
||||||
|
|
||||||
|
typedef int size_type;
|
||||||
|
|
||||||
// query result access
|
// query result access
|
||||||
int Tuples();
|
size_type Tuples() const;
|
||||||
int CmdTuples();
|
size_type CmdTuples() const;
|
||||||
int Fields();
|
int Fields();
|
||||||
const char* FieldName(int field_num);
|
const char* FieldName(int field_num) const;
|
||||||
int FieldNum(const char* field_name);
|
int FieldNum(const char* field_name) const;
|
||||||
Oid FieldType(int field_num);
|
Oid FieldType(int field_num) const;
|
||||||
Oid FieldType(const char* field_name);
|
Oid FieldType(const char* field_name) const;
|
||||||
short FieldSize(int field_num);
|
short FieldSize(int field_num) const;
|
||||||
short FieldSize(const char* field_name);
|
short FieldSize(const char* field_name) const;
|
||||||
const char* GetValue(int tup_num, int field_num);
|
const char* GetValue(size_type tup_num, int field_num) const;
|
||||||
const char* GetValue(int tup_num, const char* field_name);
|
const char* GetValue(size_type tup_num, const char* field_name) const;
|
||||||
int GetIsNull(int tup_num, int field_num);
|
bool GetIsNull(size_type tup_num, int field_num) const;
|
||||||
int GetIsNull(int tup_num, const char* field_name);
|
bool GetIsNull(size_type tup_num, const char* field_name) const;
|
||||||
int GetLength(int tup_num, int field_num);
|
int GetLength(size_type tup_num, int field_num) const;
|
||||||
int GetLength(int tup_num, const char* field_name);
|
int GetLength(size_type tup_num, const char* field_name) const;
|
||||||
void DisplayTuples(FILE *out = 0, int fillAlign = 1,
|
|
||||||
const char* fieldSep = "|",int printHeader = 1, int quiet = 0) ;
|
// OBSOLESCENT (use PQprint()):
|
||||||
void PrintTuples(FILE *out = 0, int printAttName = 1,
|
void DisplayTuples(FILE *out=0, bool fillAlign=true,
|
||||||
int terseOutput = 0, int width = 0) ;
|
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
|
// copy command related access
|
||||||
int GetLine(char* string, int length);
|
int GetLine(char str[], int length);
|
||||||
void PutLine(const char* string);
|
void PutLine(const char str[]);
|
||||||
const char* OidStatus();
|
const char* OidStatus() const;
|
||||||
int EndCopy();
|
int EndCopy();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -21,6 +21,10 @@ extern "C" {
|
|||||||
#include "libpq/libpq-fs.h"
|
#include "libpq/libpq-fs.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
// PgLargeObject Implementation
|
// PgLargeObject Implementation
|
||||||
@ -142,7 +146,7 @@ int PgLargeObject::LSeek(int offset, int whence)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int PgLargeObject::Tell()
|
int PgLargeObject::Tell() const
|
||||||
{
|
{
|
||||||
return lo_tell(pgConn, pgFd);
|
return lo_tell(pgConn, pgFd);
|
||||||
}
|
}
|
||||||
@ -160,7 +164,7 @@ int PgLargeObject::Export(const char* filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string PgLargeObject::Status()
|
string PgLargeObject::Status() const
|
||||||
{
|
{
|
||||||
return loStatus;
|
return loStatus;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -23,6 +23,12 @@
|
|||||||
#include "pgconnection.h"
|
#include "pgconnection.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_NAMESPACE_STD
|
||||||
|
#define PGSTD std::
|
||||||
|
#else
|
||||||
|
#define PGSTD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
@ -33,12 +39,12 @@ class PgLargeObject : public PgConnection {
|
|||||||
private:
|
private:
|
||||||
int pgFd;
|
int pgFd;
|
||||||
Oid pgObject;
|
Oid pgObject;
|
||||||
string loStatus;
|
PGSTD string loStatus;
|
||||||
void Init(Oid lobjId = 0);
|
void Init(Oid lobjId = 0);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PgLargeObject(const char* conninfo = 0); // use reasonable defaults and create large object
|
explicit 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(Oid lobjId, const char* conninfo = 0); // use reasonable defaults and open large object
|
||||||
~PgLargeObject(); // close connection and clean up
|
~PgLargeObject(); // close connection and clean up
|
||||||
|
|
||||||
void Create();
|
void Create();
|
||||||
@ -47,12 +53,12 @@ public:
|
|||||||
int Read(char* buf, int len);
|
int Read(char* buf, int len);
|
||||||
int Write(const char* buf, int len);
|
int Write(const char* buf, int len);
|
||||||
int LSeek(int offset, int whence);
|
int LSeek(int offset, int whence);
|
||||||
int Tell();
|
int Tell() const;
|
||||||
int Unlink();
|
int Unlink();
|
||||||
Oid LOid();
|
Oid LOid();
|
||||||
Oid Import(const char* filename);
|
Oid Import(const char* filename);
|
||||||
int Export(const char* filename);
|
int Export(const char* filename);
|
||||||
string Status();
|
PGSTD string Status() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// We don't support copying of PgLargeObject objects,
|
// We don't support copying of PgLargeObject objects,
|
||||||
@ -61,4 +67,10 @@ private:
|
|||||||
PgLargeObject& operator= (const PgLargeObject&);
|
PgLargeObject& operator= (const PgLargeObject&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_NAMESPACE_STD
|
||||||
|
#undef PGSTD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // PGLOBJECT_H
|
#endif // PGLOBJECT_H
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -25,7 +25,8 @@
|
|||||||
// Make a connection to the specified database with default environment
|
// Make a connection to the specified database with default environment
|
||||||
// See PQconnectdb() for conninfo usage.
|
// See PQconnectdb() for conninfo usage.
|
||||||
PgTransaction::PgTransaction(const char* conninfo)
|
PgTransaction::PgTransaction(const char* conninfo)
|
||||||
: PgDatabase(conninfo)
|
: PgDatabase(conninfo),
|
||||||
|
pgCommitted(true)
|
||||||
{
|
{
|
||||||
BeginTransaction();
|
BeginTransaction();
|
||||||
}
|
}
|
||||||
@ -33,17 +34,20 @@ PgTransaction::PgTransaction(const char* conninfo)
|
|||||||
// Destructor: End the transaction block
|
// Destructor: End the transaction block
|
||||||
PgTransaction::~PgTransaction()
|
PgTransaction::~PgTransaction()
|
||||||
{
|
{
|
||||||
EndTransaction();
|
if (!pgCommitted) Exec("ABORT");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin the transaction block
|
// Begin the transaction block
|
||||||
ExecStatusType PgTransaction::BeginTransaction()
|
ExecStatusType PgTransaction::BeginTransaction()
|
||||||
{
|
{
|
||||||
|
pgCommitted = false;
|
||||||
return Exec("BEGIN");
|
return Exec("BEGIN");
|
||||||
} // End BeginTransaction()
|
} // End BeginTransaction()
|
||||||
|
|
||||||
// Begin the transaction block
|
// Begin the transaction block
|
||||||
ExecStatusType PgTransaction::EndTransaction()
|
ExecStatusType PgTransaction::EndTransaction()
|
||||||
{
|
{
|
||||||
|
pgCommitted = true;
|
||||||
return Exec("END");
|
return Exec("END");
|
||||||
} // End EndTransaction()
|
} // End EndTransaction()
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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 $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -36,9 +36,9 @@
|
|||||||
// the object is destroyed.
|
// the object is destroyed.
|
||||||
class PgTransaction : public PgDatabase {
|
class PgTransaction : public PgDatabase {
|
||||||
public:
|
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
|
// connect to the database with given environment and database name
|
||||||
// PgTransaction(const PgConnection&);
|
// explicit PgTransaction(const PgConnection&);
|
||||||
~PgTransaction(); // close connection and clean up
|
~PgTransaction(); // close connection and clean up
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -46,9 +46,11 @@ protected:
|
|||||||
ExecStatusType EndTransaction();
|
ExecStatusType EndTransaction();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PgTransaction() : PgDatabase() {} // Do not connect
|
PgTransaction() : PgDatabase(), pgCommitted(true) {} // Do not connect
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool pgCommitted;
|
||||||
|
|
||||||
// We don't support copying of PgTransaction objects,
|
// We don't support copying of PgTransaction objects,
|
||||||
// so make copy constructor and assignment op private.
|
// so make copy constructor and assignment op private.
|
||||||
PgTransaction(const PgTransaction&);
|
PgTransaction(const PgTransaction&);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user