mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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:
@ -10,7 +10,7 @@
|
||||
* 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 $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -18,151 +18,155 @@
|
||||
#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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user