*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.70 1997/06/03 06:17:34 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.71 1997/06/06 01:41:24 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
static PGresult *
PSQLexec(PsqlSettings * ps, char *query)
{
- PGresult *res = PQexec(ps->db, query);
+ PGresult *res;
+ res = PQexec(ps->db, query);
if (!res)
fputs(PQerrorMessage(ps->db), stderr);
else {
strcat(listbuf, " ORDER BY relname ");
if (!(res = PSQLexec(ps, listbuf)))
return -1;
-
/* first, print out the attribute names */
nColumns = PQntuples(res);
if (nColumns > 0) {
strcpy(table[i], PQgetvalue(res, i, 1));
}
- PQclear(res);
+ PQclear(res); /* PURIFY */
for (i = 0; i < nColumns; i++) {
tableDesc(ps, table[i]);
}
return (0);
} else {
+ PQclear(res); /* PURIFY */
switch (table_index_both) {
case 't': fprintf(stderr, "Couldn't find any tables!\n");
break;
/* read up to MAX_QUERY_BUFFER characters */
if (fgets(line, MAX_QUERY_BUFFER, source) == NULL)
+ {
+ free(line);
return NULL;
+ }
line[MAX_QUERY_BUFFER - 1] = '\0';
len = strlen(line);
&(settings->opt));
fflush(settings->queryFout);
}
- PQclear(results);
break;
case PGRES_EMPTY_QUERY:
*success_p = true;
- PQclear(results);
break;
case PGRES_COMMAND_OK:
*success_p = true;
if (!settings->quiet)
fprintf(stdout, "%s\n", PQcmdStatus(results));
- PQclear(results);
break;
case PGRES_COPY_OUT:
*success_p = true;
handleCopyOut(results, settings->quiet, stdout);
}
- PQclear(results);
break;
case PGRES_COPY_IN:
*success_p = true;
handleCopyIn(results, false, copystream);
else
handleCopyIn(results, !settings->quiet, stdin);
- PQclear(results);
break;
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
notify->relname, notify->be_pid);
free(notify);
}
+ if(results) PQclear(results);
}
}
}
query_start = line;
-
if (line == NULL) { /* No more input. Time to quit */
if (!settings->quiet)
printf("EOF\n"); /* Goes on prompt line */
fprintf(stderr, "query buffer max length of %d exceeded\n",
MAX_QUERY_BUFFER);
fprintf(stderr, "query line ignored\n");
+ free (line);
} else {
if (query_start[0] != '\0') {
+
querySent = false;
if (query[0] != '\0') {
strcat(query, "\n");
} else
strcpy(query, query_start);
}
+ free(line); /* PURIFY */
}
if (slashCmdStatus == 0) {
successResult &= success;
querySent = true;
}
- free(line); /* free storage malloc'd by GetNextLine */
}
} /* while */
return successResult;
if (PQstatus(settings.db) == CONNECTION_BAD) {
fprintf(stderr, "Connection to database '%s' failed.\n", dbname);
fprintf(stderr, "%s", PQerrorMessage(settings.db));
+ PQfinish(settings.db);
exit(1);
}
if (listDatabases) {
sprintf(line, "\\i %s", qfilename);
}
HandleSlashCmds(&settings, line, "");
+ if (!singleSlashCmd) free (line); /* PURIFY */
+
} else {
if (singleQuery) {
bool success; /* The query succeeded at the backend */
}
PQfinish(settings.db);
+ free(settings.opt.fieldSep); /* PURIFY */
+ if(settings.prompt) free(settings.prompt); /* PURIFY */
return !successResult;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.36 1997/06/01 15:38:52 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.37 1997/06/06 01:42:02 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
return CONNECTION_OK;
connect_errReturn:
+
+ /* Igor/6/3/97 - We need to free it here...otherwise the function
+ returns without setting conn->port to port. Because of that
+ any way of referencing this variable will be lost and it's allocated
+ memory will not be freed. */
+ free(port); /* PURIFY */
return CONNECTION_BAD;
}
static void
freePGconn(PGconn *conn)
{
+ if (!conn) return;
if (conn->pghost) free(conn->pghost);
if (conn->pgtty) free(conn->pgtty);
if (conn->pgoptions) free(conn->pgoptions);
PQfinish(PGconn *conn)
{
if (!conn) {
- fprintf(stderr,"PQfinish() -- pointer to PGconn is null");
+ fprintf(stderr,"PQfinish() -- pointer to PGconn is null\n");
} else {
if (conn->status == CONNECTION_OK)
closePGconn(conn);
PQreset(PGconn *conn)
{
if (!conn) {
- fprintf(stderr,"PQreset() -- pointer to PGconn is null");
+ fprintf(stderr,"PQreset() -- pointer to PGconn is null\n");
} else {
closePGconn(conn);
conn->status = connectDB(conn);
PQdb(PGconn* conn)
{
if (!conn) {
- fprintf(stderr,"PQdb() -- pointer to PGconn is null");
+ fprintf(stderr,"PQdb() -- pointer to PGconn is null\n");
return (char *)NULL;
}
return conn->dbName;
PQuser(PGconn* conn)
{
if (!conn) {
- fprintf(stderr,"PQuser() -- pointer to PGconn is null");
+ fprintf(stderr,"PQuser() -- pointer to PGconn is null\n");
return (char *)NULL;
}
return conn->pguser;
PQhost(PGconn* conn)
{
if (!conn) {
- fprintf(stderr,"PQhost() -- pointer to PGconn is null");
+ fprintf(stderr,"PQhost() -- pointer to PGconn is null\n");
return (char *)NULL;
}
PQoptions(PGconn* conn)
{
if (!conn) {
- fprintf(stderr,"PQoptions() -- pointer to PGconn is null");
+ fprintf(stderr,"PQoptions() -- pointer to PGconn is null\n");
return (char *)NULL;
}
return conn->pgoptions;
PQtty(PGconn* conn)
{
if (!conn) {
- fprintf(stderr,"PQtty() -- pointer to PGconn is null");
+ fprintf(stderr,"PQtty() -- pointer to PGconn is null\n");
return (char *)NULL;
}
return conn->pgtty;
PQport(PGconn* conn)
{
if (!conn) {
- fprintf(stderr,"PQport() -- pointer to PGconn is null");
+ fprintf(stderr,"PQport() -- pointer to PGconn is null\n");
return (char *)NULL;
}
return conn->pgport;
PQstatus(PGconn* conn)
{
if (!conn) {
- fprintf(stderr,"PQstatus() -- pointer to PGconn is null");
+ fprintf(stderr,"PQstatus() -- pointer to PGconn is null\n");
return CONNECTION_BAD;
}
return conn->status;
PQerrorMessage(PGconn* conn)
{
if (!conn) {
- fprintf(stderr,"PQerrorMessage() -- pointer to PGconn is null");
+ fprintf(stderr,"PQerrorMessage() -- pointer to PGconn is null\n");
return (char *)NULL;
}
return conn->errorMessage;