*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.1.1.1 1996/07/09 06:22:17 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.2 1996/07/12 04:53:57 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
char *tmp;
conn = (PGconn*)malloc(sizeof(PGconn));
-
+
+ if (!conn) {
+ fprintf(stderr,"FATAL: pqsetdb() -- unable to allocate memory for a PGconn");
+ return (PGconn*)NULL;
+ }
+
conn->Pfout = NULL;
conn->Pfin = NULL;
conn->Pfdebug = NULL;
void
PQfinish(PGconn *conn)
{
- if (conn->status == CONNECTION_OK)
- closePGconn(conn);
- freePGconn(conn);
+ if (!conn) {
+ fprintf(stderr,"PQfinish() -- pointer to PGconn is null");
+ } else {
+ if (conn->status == CONNECTION_OK)
+ closePGconn(conn);
+ freePGconn(conn);
+ }
}
/* PQreset :
void
PQreset(PGconn *conn)
{
+ if (!conn) {
+ fprintf(stderr,"PQreset() -- pointer to PGconn is null");
+ } else {
closePGconn(conn);
conn->status = connectDB(conn);
+ }
}
/*
char*
PQdb(PGconn* conn)
{
+ if (!conn) {
+ fprintf(stderr,"PQdb() -- pointer to PGconn is null");
+ return (char *)NULL;
+ }
+
return conn->dbName;
}
char*
PQhost(PGconn* conn)
{
+ if (!conn) {
+ fprintf(stderr,"PQhost() -- pointer to PGconn is null");
+ return (char *)NULL;
+ }
+
return conn->pghost;
}
char*
PQoptions(PGconn* conn)
{
+ if (!conn) {
+ fprintf(stderr,"PQoptions() -- pointer to PGconn is null");
+ return (char *)NULL;
+ }
+
return conn->pgoptions;
}
char*
PQtty(PGconn* conn)
{
+ if (!conn) {
+ fprintf(stderr,"PQtty() -- pointer to PGconn is null");
+ return (char *)NULL;
+ }
+
return conn->pgtty;
}
char*
PQport(PGconn* conn)
{
+ if (!conn) {
+ fprintf(stderr,"PQport() -- pointer to PGconn is null");
+ return (char *)NULL;
+ }
+
return conn->pgport;
}
ConnStatusType
PQstatus(PGconn* conn)
{
+ if (!conn) {
+ fprintf(stderr,"PQstatus() -- pointer to PGconn is null");
+ return CONNECTION_BAD;
+ }
+
return conn->status;
}
char*
PQerrorMessage(PGconn* conn)
{
+ if (!conn) {
+ fprintf(stderr,"PQerrorMessage() -- pointer to PGconn is null");
+ return (char *)NULL;
+ }
+
return conn->errorMessage;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.1.1.1 1996/07/09 06:22:17 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.2 1996/07/12 04:53:59 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
char cmdStatus[MAX_MESSAGE_LEN];
char pname[MAX_MESSAGE_LEN]; /* portal name */
PGnotify *newNotify;
- FILE *Pfin = conn->Pfin;
- FILE *Pfout = conn->Pfout;
- FILE* Pfdebug = conn->Pfdebug;
+ FILE *Pfin, *Pfout, *Pfdebug;
pname[0]='\0';
+ if (!conn) return NULL;
+ if (!query) {
+ sprintf(conn->errorMessage, "PQexec() -- query pointer is null.");
+ return NULL;
+ }
+
+ Pfin = conn->Pfin;
+ Pfout = conn->Pfout;
+ Pfdebug = conn->Pfdebug;
+
/*clear the error string */
conn->errorMessage[0] = '\0';
PQnotifies(PGconn *conn)
{
Dlelem *e;
+
+ if (!conn) return NULL;
+
if (conn->status != CONNECTION_OK)
return NULL;
/* RemHead returns NULL if list is empy */
PQgetline(PGconn *conn, char *s, int maxlen)
{
int c = '\0';
+
+ if (!conn) return EOF;
if (!conn->Pfin || !s || maxlen <= 1)
return(EOF);
void
PQputline(PGconn *conn, char *s)
{
- if (conn->Pfout) {
+ if (conn && (conn->Pfout)) {
(void) fputs(s, conn->Pfout);
fflush(conn->Pfout);
}
PQendcopy(PGconn *conn)
{
char id;
- FILE *Pfin = conn->Pfin;
- FILE* Pfdebug = conn->Pfdebug;
+ FILE *Pfin, *Pfdebug;
+
+ if (!conn) return (int)NULL;
+
+ Pfin = conn->Pfin;
+ Pfdebug = conn->Pfdebug;
if ( (id = pqGetc(Pfin,Pfdebug)) > 0)
return(0);
PQArgBlock *args,
int nargs)
{
- FILE *Pfin = conn->Pfin;
- FILE *Pfout = conn->Pfout;
- FILE* Pfdebug = conn->Pfdebug;
+ FILE *Pfin, *Pfout, *Pfdebug;
int id;
int i;
+ if (!conn) return NULL;
+
+ Pfin = conn->Pfin;
+ Pfout = conn->Pfout;
+ Pfdebug = conn->Pfdebug;
+
/* clear the error string */
conn->errorMessage[0] = '\0';
ExecStatusType
PQresultStatus(PGresult* res)
{
+ if (!res) {
+ fprintf(stderr, "PQresultStatus() -- pointer to PQresult is null");
+ return PGRES_NONFATAL_ERROR;
+ }
+
return res->resultStatus;
}
int
PQntuples(PGresult *res)
{
+ if (!res) {
+ fprintf(stderr, "PQntuples() -- pointer to PQresult is null");
+ return (int)NULL;
+ }
+
return res->ntups;
}
int
PQnfields(PGresult *res)
{
+ if (!res) {
+ fprintf(stderr, "PQnfields() -- pointer to PQresult is null");
+ return (int)NULL;
+ }
+
return res->numAttributes;
}
char*
PQfname(PGresult *res, int field_num)
{
+
+ if (!res) {
+ fprintf(stderr, "PQfname() -- pointer to PQresult is null");
+ return NULL;
+ }
+
if (field_num > (res->numAttributes - 1)) {
fprintf(stderr,
"PQfname: ERROR! name of field %d(of %d) is not available",
{
int i;
+ if (!res) {
+ fprintf(stderr, "PQfnumber() -- pointer to PQresult is null");
+ return -1;
+ }
+
if (field_name == NULL ||
field_name[0] == '\0' ||
res->attDescs == NULL)
Oid
PQftype(PGresult *res, int field_num)
{
+ if (!res) {
+ fprintf(stderr, "PQftype() -- pointer to PQresult is null");
+ return InvalidOid;
+ }
+
if (field_num > (res->numAttributes - 1)) {
fprintf(stderr,
"PQftype: ERROR! type of field %d(of %d) is not available",
int2
PQfsize(PGresult *res, int field_num)
{
+ if (!res) {
+ fprintf(stderr, "PQfsize() -- pointer to PQresult is null");
+ return (int2)NULL;
+ }
+
if (field_num > (res->numAttributes - 1)) {
fprintf(stderr,
"PQfsize: ERROR! size of field %d(of %d) is not available",
}
char* PQcmdStatus(PGresult *res) {
+ if (!res) {
+ fprintf(stderr, "PQcmdStatus() -- pointer to PQresult is null");
+ return NULL;
+ }
+
return res->cmdStatus;
}
if not, return ""
*/
char* PQoidStatus(PGresult *res) {
+ if (!res) {
+ fprintf(stderr, "PQoidStatus() -- pointer to PQresult is null");
+ return NULL;
+ }
+
if (!res->cmdStatus)
return "";
char*
PQgetvalue(PGresult *res, int tup_num, int field_num)
{
+ if (!res) {
+ fprintf(stderr, "PQgetvalue() -- pointer to PQresult is null");
+ return NULL;
+ }
+
if (tup_num > (res->ntups - 1) ||
field_num > (res->numAttributes - 1)) {
fprintf(stderr,
int
PQgetlength(PGresult *res, int tup_num, int field_num)
{
+ if (!res) {
+ fprintf(stderr, "PQgetlength() -- pointer to PQresult is null");
+ return (int)NULL;
+ }
+
if (tup_num > (res->ntups - 1 )||
field_num > (res->numAttributes - 1)) {
fprintf(stderr,