Suggested patches for libpq++/pgdatabase.* - Mailing list pgsql-interfaces

From J. T. Vermeulen
Subject Suggested patches for libpq++/pgdatabase.*
Date
Msg-id 20010226143446.B17746@cistron.nl
Whole thread Raw
Responses Re: Suggested patches for libpq++/pgdatabase.*
List pgsql-interfaces
Suggest the following fixes for a future version.  These include some minor
changes of interface (ints changed to bools) that should be compatible at the
source level but incompatible at the linking level, so those may have to be
skipped or deferred to some more convenient time.

Other changes: fixed possible portability problem for weird platforms (using 
memset() to clear pointers); fixed minor memory leak in PrintTuples(), and
marked PrintTuples() / DisplayTuples() as obsolescent; changed dubious 
parameter names "string" to "str".


--- postgresql-7.0.3/src/interfaces/libpq++/pgdatabase.cc    Sat Jan 29 17:58:52 2000
+++ postgresql-7.0.3-jtv/src/interfaces/libpq++/pgdatabase.cc    Mon Feb 26 14:17:32 2001
@@ -18,37 +18,41 @@#include "pgdatabase.h"
-void PgDatabase::DisplayTuples(FILE *out, int fillAlign, 
-                               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 */) {    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){    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);}
@@ -126,13 +130,13 @@}
-int PgDatabase::GetIsNull(int tup_num, int field_num)
+bool PgDatabase::GetIsNull(int tup_num, int 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){ return PQgetisnull(pgResult, tup_num,
FieldNum(field_name));}
 
@@ -150,15 +154,15 @@}
-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); }


--- postgresql-7.0.3/src/interfaces/libpq++/pgdatabase.h    Sun Apr 23 00:39:15 2000
+++ postgresql-7.0.3-jtv/src/interfaces/libpq++/pgdatabase.h    Mon Feb 26 14:17:44 2001
@@ -37,7 +37,7 @@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
connectionand clean up  
 
@@ -53,18 +53,20 @@  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);
+  bool GetIsNull(int tup_num, int field_num);
+  bool 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) ;
+
+  // OBSOLESCENT (use PQprint()):
+  void DisplayTuples(FILE *out=0, bool fillAlign=true, 
+    const char* fieldSep="|", bool printHeader=true, bool quiet=false) ;
+  void PrintTuples(FILE *out=0, bool printAttName=true, 
+    bool terseOutput=false, bool fillAlign=false) ;  // copy command related access
-  int GetLine(char* string, int length);
-  void PutLine(const char* string);
+  int GetLine(char str[], int length);
+  void PutLine(const char str[]);  const char* OidStatus();  int EndCopy();




pgsql-interfaces by date:

Previous
From: Katsuyuki Tanaka
Date:
Subject: IPC Shared Memory (fwd)
Next
From: "J. T. Vermeulen"
Date:
Subject: Re: Suggested patches for libpq++/pgdatabase.*